36计 - 擒贼先擒ai
Go to file
ci[bot] 1d4a92f874 📦 deps(skills): sync thirdparty skills 2026-06-21 16:02:42 +00:00
.gitea 🔧 chore(test): fix test directory path references 2026-06-21 18:14:16 +08:00
docs 🎨 style(md): lint and format all Markdown files 2026-06-21 17:37:29 +08:00
rulesets 📝 docs(tsl): clarify syntax constraints and enhance test infrastructure 2026-06-21 17:04:50 +08:00
scripts 📝 docs(tsl): clarify syntax constraints and enhance test infrastructure 2026-06-21 17:04:50 +08:00
skills 📦 deps(skills): sync thirdparty skills 2026-06-21 16:02:42 +00:00
templates 📝 docs(tsl): clarify syntax constraints and enhance test infrastructure 2026-06-21 17:04:50 +08:00
test 🔧 chore(test): fix test directory path references 2026-06-21 18:14:16 +08:00
.gitattributes 🐛 fix(playbook): support toml without tomllib 2026-01-23 16:54:53 +08:00
.gitignore 🗑️ remove(test): remove fragile documentation consistency tests 2026-06-21 18:07:47 +08:00
.markdownlint.json 🎨 style(md): lint and format all Markdown files 2026-06-21 17:37:29 +08:00
.markdownlintignore ♻️ refactor(skills): rename repo skills source dir 2026-05-19 09:09:54 +08:00
.prettierignore ♻️ refactor(skills): rename repo skills source dir 2026-05-19 09:09:54 +08:00
.prettierrc.json 🔧 chore(markdown): add prettier config and usage 2026-01-21 10:20:19 +08:00
CONTRIBUTING.md 🔧 chore(test): fix test directory path references 2026-06-21 18:14:16 +08:00
README.md 📝 docs(tsl): clarify syntax constraints and enhance test infrastructure 2026-06-21 17:04:50 +08:00
SKILLS.md 📝 docs(tsl): clarify syntax constraints and enhance test infrastructure 2026-06-21 17:04:50 +08:00
package.json 🔧 chore(markdown): add markdownlint baseline and lint fixes 2026-05-18 15:43:48 +08:00
playbook.toml.example 📝 docs(tsl): clarify syntax constraints and enhance test infrastructure 2026-06-21 17:04:50 +08:00
pyproject.toml feat(playbook): add plan progress tracking and rules updates 2026-01-26 16:51:23 +08:00

README.md

playbook

Playbook工程规范与代理规则合集当前覆盖

  • TSL.tsl/.tsf
  • C++
  • Python
  • TypeScript.ts/.tsx
  • JavaScript.js/.mjs/.cjs
  • Markdown代码格式化

docs/(开发规范)

docs/ 目录是给开发者阅读的工程规范,约束代码写法、命名与提交信息。

  • docs/index.md:文档导航入口
  • docs/common/:跨语言规范(提交信息、版本号)
  • docs/tsl/TSL 规范(语法手册、金融业务、模块、函数检索、代码风格、命名、工具链)
  • docs/cpp/C++ 规范C++23/Modules、Google 基线、Conan、clangd
  • docs/python/Python 规范Google 基线、black/isort/flake8/pylint/mypy/pytest
  • docs/typescript/TypeScript 规范Google 基线、prettier/eslint/vitest
  • docs/markdown/Markdown 规范(仅代码格式化)

落地模板:templates/cpp/templates/python/templates/ci/

详见 docs/index.md

templates/(项目架构模板)

templates/ 目录除了语言配置模板外,还包含 AI 代理工作环境的项目架构模板:

  • templates/memory-bank/项目上下文文档模板project-brief、tech-context、system-patterns、active-context、progress、decisions
  • templates/prompts/任务入口模板agent-behavior、clarify、verify-change、close-task、update-memory、code-review不是流程权威
  • templates/AGENTS.template.md:入口导航模板(项目主入口)
  • templates/AGENT_RULES.template.mdsuperpowers-first 执行规则模板

快速部署

统一入口(配置驱动,示例见 playbook.toml.example

python scripts/playbook.py -config playbook.toml

示例配置(部署项目架构模板):

[playbook]
project_root = "/path/to/project"
playbook_root = "docs/standards/playbook"
install_mode = "snapshot"

[sync_rules]
# force = true # 可选

[sync_memory_bank]
project_name = "MyProject"

[sync_prompts]

部署行为

  • 配置节存在即启用:只写需要同步的配置节
  • AGENTS.md:始终按区块更新(<!-- playbook:xxx:start/end -->
  • CLAUDE.md:自动检测(根目录 → .claude/),不存在则创建;注入 @AGENTS.md / @AGENT_RULES.md
  • force:默认 false已存在则跳过设为 true 时强制覆盖(会先备份)

更多说明详见 templates/README.md

rulesets/(规则集模板库 - 三层架构)

重要说明playbook 仓库中的 rulesets/规则集模板库,不是 playbook 项目自身的代理规则。

Playbook 本身不包含源代码,因此不需要 AI 代理遵循规则。rulesets/ 存在的目的是:

  1. 作为模板源,供其他项目复制
  2. 通过 playbook.py 的 [sync_standards] 部署到目标项目的 .agents/
  3. 目标项目的 AI 代理读取项目根目录的 .agents/(从模板生成)

rulesets/ 是 AI 代理规则集模板(三层架构设计):

三层架构设计

Layer 1: rulesets/          (≤50 行/语言,模板源)
  ├─ 语言特有的核心约束
  └─ 指向 Skills 和 docs

Layer 2: skills/           (按需加载,$skill-name 触发)
  ├─ commit-message: 提交信息规范
  ├─ style-cleanup: 代码风格整理
  └─ thirdparty/: 第三方同步 skills

Layer 3: docs/             (权威静态文档)
  └─ 完整语法手册/代码风格/工具链配置

各层职责

层级 加载方式 内容 作用
Layer 1 自动,始终在上下文 语言特有的核心约束 快速判断能做/不能做
Layer 2 $<skill-name> 触发或代理判定 操作指南、最佳实践、工作流 指导具体怎么做
Layer 3 按需读取特定章节 完整语言手册、代码风格、工具链 最终权威(冲突时以此为准)

目录结构

  • rulesets/index.md:规则集索引(跨语言)
  • rulesets/tsl/index.mdTSL 核心约定45 行)
  • rulesets/cpp/index.mdC++ 核心约定46 行)
  • rulesets/python/index.mdPython 核心约定44 行)
  • rulesets/typescript/index.mdTypeScript 核心约定47 行)
  • rulesets/markdown/index.mdMarkdown 核心约定31 行,仅代码格式化)

更多说明:rulesets/index.md

维护原则

.agents/Layer 1修改规则

  • 可做:更新核心约定、添加语言特有的硬性约束(命名/语法/工具链)
  • 不可做:添加推荐型最佳实践(→ skill、详细语法解释→ skill/docs、超过 50 行(→ 拆分)

SkillsLayer 2创建规则

  • 可做:增加新流程、从零教授新语言、添加跨语言通用知识

SKILLSCodex CLI / Claude Code

本仓库内置 AI agent skills支持 Codex CLI 和 Claude Code用于按需加载的工作流与知识库。

安装与使用详见 SKILLS.md

在其他项目中使用本 Playbook

由于本仓库需要内部权限访问,其他项目不能仅用外链引用;推荐把 Playbook 规范部署到项目内,并用统一入口执行。

快速决策:我应该用哪种方式?

你的情况 推荐方式 优势
新项目,需要持续同步更新 方式一:git subtree 标准留在项目内,后续可拉取更新
不想把 Playbook 以 subtree 嵌进仓库,但仍要把标准部署到项目内 方式二:外部 clone 后执行部署 Playbook 仓库与业务仓库解耦,部署根目录可配置
不确定? 方式一:git subtree(推荐) 项目内可见、版本可追溯、使用路径最稳定

方式一git subtree 同步(推荐)

  1. 在目标项目中首次引入:

    git subtree add --prefix docs/standards/playbook https://git.mytsl.cn/csh/playbook.git main --squash
    
  2. 后续同步更新:

    git subtree pull --prefix docs/standards/playbook https://git.mytsl.cn/csh/playbook.git main --squash
    
  3. 在项目根配置并执行:

    # playbook.toml
    [playbook]
    project_root = "."
    playbook_root = "docs/standards/playbook"
    install_mode = "subtree"
    
    [sync_standards]
    langs = ["tsl", "cpp"]
    
    [sync_rules]
    
    [sync_memory_bank]
    project_name = "MyProject"
    
    python docs/standards/playbook/scripts/playbook.py -config playbook.toml
    

配置参数说明见 playbook.toml.example


方式二:外部 clone 后执行部署

如果你不想把 Playbook 以 git subtree 嵌进目标项目,可以把 Playbook clone 到项目外部,再由该 clone 直接把标准部署进目标项目。

  1. 先在任意位置 clone Playbook

    git clone https://git.mytsl.cn/csh/playbook.git /opt/playbook
    
  2. 在目标项目根创建 playbook.toml

    [playbook]
    project_root = "."
    playbook_root = "custom/playbook"
    install_mode = "snapshot"
    
    [sync_standards]
    langs = ["tsl"]
    
    [sync_rules]
    
    [sync_memory_bank]
    project_name = "MyProject"
    
  3. 在目标项目根执行外部 clone 里的统一入口:

    python /opt/playbook/scripts/playbook.py -config playbook.toml
    

说明playbook_root 表示项目内的部署目录,不是外部 clone 的路径。


多语言项目落地TSL + C++/其他语言)

多语言项目建议把规范拆成两类:

  1. 仓库级(跨语言)共识:对所有语言都成立的规则与流程。
    • 提交信息:docs/common/commit_message.md
    • 行尾与文本规范:.gitattributes
    • 代理最低要求:.agents/*(工作原则、质量底线、安全边界)
  2. 语言级Language-specific规范:只对某个语言成立的风格与工具。
    • 例如 TSL 的命名/文件顶层声明限制、C++ 的 .clang-format/.clang-tidy、Python 的 ruff、TypeScript 的 ESLint/类型约束等。

建议:仓库级规则尽量少且稳定;语言级规则各自独立,避免互相"污染"。

本仓库提供多套代理规则集(同步后位于目标项目的 .agents/tsl/ / .agents/cpp/ / .agents/python/ / .agents/typescript/ / .agents/markdown/

  • 各规则集都包含语言特有的核心约定
  • 并在 index.md 中叠加语言级"硬约束"TSL/TSF 语法限制、C++23/Modules、Python 风格、TypeScript 类型约束、Markdown 代码格式化等)

多语言项目推荐结构示例TSL + C++ + Python + TypeScript + Markdown

.
├── .agents/
│   ├── index.md                      # 多语言索引(缺省时由 playbook 生成)
│   ├── tsl/                          # 由本 Playbook 同步(适用于 .tsl/.tsf
│   ├── cpp/                          # 由本 Playbook 同步(适用于 C++23/Modules
│   ├── python/                       # Python 规则集(同上)
│   ├── typescript/                   # TypeScript/JavaScript 规则集(同上)
│   └── markdown/                     # Markdown 规则集(仅代码格式化)
├── .gitattributes                    # 行尾/文本规范
├── AGENTS.md                         # Codex 入口(由 playbook 自动生成/更新)
├── CLAUDE.md                         # Claude Code 入口(自动注入 @AGENTS.md
├── <playbook_root>/                  # 本 Playbook 在项目内的根(默认 docs/standards/playbook
│   ├── docs/
│   ├── rulesets/
│   ├── scripts/
│   └── templates/
├── docs/project/                     # 项目自有文档架构、ADR、运行方式等
├── playbook.toml                     # 统一入口配置
└── src/                              # 源码目录(按项目实际情况)

规则优先级建议

  • 同一项目内多个规则集并行放在 .agents/<lang>/,不要互相覆盖
  • 若某个子目录需要更具体规则(模块/子系统差异),在更靠近代码的目录放置更具体规则(例如 src/foo/.agents/),并以"离代码更近者优先"为准