Files
tsl-devkit/README.md
T
csh 3d83740f88 Squashed 'docs/standards/playbook/' changes from c3f8137..25d895d
25d895d 🐛 fix(gitea_workflow): clean up temp repos after job steps
2bc3b11 🐛 fix(gitea_workflow): clean up temporary repo dirs in workflows
98c3f30 📝 docs(agent_rules): allow plan execution on current branch
16c7230 📝 docs(prompts): define custom verify layering
8efc4dd 🐛 fix(skills): quote commit-message description
bc8498f 🐛 fix(ci): install tomli for gitea tests
55cda3b 🐛 fix(tests): report missing toml parser clearly
c0729c7 🐛 fix(playbook): import Optional for cli compatibility
63e24bf 📦 deps(skills): sync thirdparty skills
d2f9356 🐛 fix(ci): isolate gitea workflow repos
588b81d 🐛 fix(ci): inline gitea workflow bootstrap
e0b1c3a ♻️ refactor(skills): standardize first-party skill contracts
2c5050d ♻️ refactor(skills): rename repo skills source dir
f049dfb 📦 deps(skills): drop duplicate first-party superpowers skills
234b335  feat(workflow): add superpowers planning and execution state tracking
c1702a6 📝 docs(markdown): format tracked markdown and drop stale templates
2325409 📝 docs(markdown): clarify optional markdownlint usage
214c44e 🔧 chore(markdown): add markdownlint baseline and lint fixes
a22b324 📝 docs(templates): add execution and memory-bank prompt templates
223a797 📝 docs(templates): update README for Claude Code and current features
4ac8672 📝 docs: simplify README + platform-agnostic tools + auto-create local rules
2431c9d 📝 docs: add claude_md config and use cross-platform paths
d64b248 📝 docs: fix README.md inaccuracies and add Claude Code info
c8d6bf2 🐛 fix(playbook): use relative paths in CLAUDE.md when not at project root
6518f0f  feat(playbook): auto-create CLAUDE.md with path discovery
6ec9a45  feat(skills): add skill_link symlink support + platform-agnostic prompt
9f8b6b5 📝 docs: update README and config example for Claude Code support
79cff6c 📝 docs(skills): add Claude Code platform support
452c6f5  feat(playbook): auto-inject AGENTS.md into CLAUDE.md
e1dbf3c 🐛 fix(skills): remove dual-path from commit-message skill
f3a7259 🔧 chore(ci): use prepare_repo.sh in both workflows
da08212 🔧 chore(ci): extract prepare_repo.sh and clean up workflows
7ade85e 🗑️ remove(tsl): drop syntax_book/, data/ source and build script
f94dba0 ♻️ refactor(skills): update playbook.py and tests for thirdparty/ layout
b3df412 ♻️ refactor(skills): separate thirdparty skills into thirdparty/ subdirectory
64950e7 📦 deps(skills): sync thirdparty skills
a2e3cb0  feat(playbook): add no_backup deploy controls
8609d59 🐛 fix(docs): repair reference catalog source links
956da11 🐛 fix(playbook): publish hidden ci test fixes
3f67754 📦 deps(skills): sync thirdparty skills
08ca87b 📦 deps(skills): add karpathy thirdparty sync
96b705b 📝 docs(tsl): rebuild canonical syntax and routing manual
3ed5052 📦 deps(skills): sync thirdparty skills
60108dd 📦 deps(skills): sync thirdparty skills
da85d4e 🐛 fix(thirdparty): prune nested project snapshots
a2a697e 📦 deps(skills): sync thirdparty skills
9df610a 🐛 fix(thirdparty): exclude duplicated superpowers skills
33dd5bb 🐛 fix(thirdparty): preserve optional manifest fields
91b0ea7 🐛 fix(thirdparty): preserve manifest during snapshot update
2e26f98 🔧 chore(thirdparty): generalize skills sync pipeline
5b9c1e3 📦 deps(skills): sync superpowers
2f2d34a 📝 docs(readme): normalize subtree command spacing
62db7db 🐛 fix(ci): serialize superpowers update and sync
3463223 🐛 fix(ci): use literal superpowers sync paths
48f6de8 📦 deps(skills): sync superpowers
4b23529 🔧 chore(ci): merge superpowers update and sync workflow
a56d75b 📦 deps(skills): sync superpowers
84bcefa 🔧 chore(ci): use ci[bot] commit author name
00a07e5 📦 deps(skills): sync superpowers
7b84daf 🐛 fix(templates): enforce main loop progress tracking
51373d7 🔧 chore(ci): automate superpowers sync workflow
eaaa39c 🐛 fix(ci): prevent stale superpowers sync from restoring skills block
79755c6 📦 deps(skills): sync superpowers
836d878 📦 deps(skills): sync superpowers
8216c9f 📦 deps(skills): sync superpowers
9439505 🐛 fix(playbook): address reported repo issues

git-subtree-dir: docs/standards/playbook
git-subtree-split: 25d895d8b3f56624ccfe99ad7289e9eb49e0f316
2026-05-24 13:04:14 +08:00

357 lines
14 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# playbook
Playbook:工程规范与代理规则合集,当前覆盖:
- TSL`.tsl`/`.tsf`
- C++
- Python
- TypeScript`.ts`/`.tsx`
- JavaScript`.js`/`.mjs`/`.cjs`
- Markdown(代码格式化)
## 原则
1. **可读性优先**:读代码的时间远大于写代码
2. **一致性优先**:同一仓库内保持一致比追求"最优风格"更重要
3. **遵从既有代码**:修改/扩展现有代码时优先沿用其局部风格
## 适用范围
- 本指南适用于所有 TSL/C++/Python/TypeScript/JavaScript/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.md`:执行流程模板
### 快速部署
统一入口(配置驱动,示例见 `playbook.toml.example`):
```bash
python scripts/playbook.py -config playbook.toml
```
示例配置(部署项目架构模板):
```toml
[playbook]
project_root = "/path/to/project"
[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 时强制覆盖(会先备份)
### 工作流留痕 helper
如果项目已经部署了这套模板,并使用 `superpowers` 工作流:
```bash
# spec 写完后
python <deploy_root>/scripts/playbook.py \
-record-spec docs/superpowers/specs/<topic>-design.md \
-progress memory-bank/progress.md
# plan 写完后
python <deploy_root>/scripts/playbook.py \
-record-plan docs/superpowers/plans/<topic>.md \
-progress memory-bank/progress.md
```
这两个 helper 只负责把 `workflow-state` 写入
`memory-bank/progress.md`
真正执行 Plan 仍然走 `main_loop.py claim/finish`
详见:`templates/README.md`
## rulesets/(规则集模板库 - 三层架构)
> **重要说明**playbook 仓库中的 `rulesets/` 是**规则集模板库**,不是 playbook 项目自身的代理规则。
>
> Playbook 本身不包含源代码,因此不需要 AI 代理遵循规则。`rulesets/` 存在的目的是:
>
> 1. 作为**模板源**,供其他项目复制
> 2. 通过 playbook.py 的 `[sync_standards]` 部署到目标项目的 `.agents/`
> 3. 目标项目的 AI 代理读取**项目根目录的 `.agents/`**(从模板生成)
`rulesets/` 是 AI 代理规则集模板(三层架构设计):
### 三层架构设计
```txt
Layer 1: rulesets/ (≤50 行/语言,模板源)
├─ 核心约束与安全红线
└─ 指向 Skills 和 docs
Layer 2: skills/ (按需加载,$skill-name 触发)
├─ commit-message: 提交信息规范
├─ style-cleanup: 代码风格整理
├─ bulk-refactor-workflow: 批量重构流程
└─ thirdparty/: 第三方同步 skills
Layer 3: docs/ (权威静态文档)
└─ 完整语法手册/代码风格/工具链配置
```
**各层职责**
| 层级 | 加载方式 | 内容 | 作用 |
| ------- | ------------------------------ | ------------------------------ | -------------------------- |
| Layer 1 | 自动,始终在上下文 | 硬约束与安全红线 | 快速判断能做/不能做 |
| Layer 2 | `$<skill-name>` 触发或代理判定 | 操作指南、最佳实践、工作流 | 指导具体怎么做 |
| Layer 3 | 按需读取特定章节 | 完整语言手册、代码风格、工具链 | 最终权威(冲突时以此为准) |
**目录结构**
- `rulesets/index.md`:规则集索引(跨语言)
- `rulesets/tsl/index.md`TSL 核心约定(45 行)
- `rulesets/cpp/index.md`C++ 核心约定(46 行)
- `rulesets/python/index.md`Python 核心约定(44 行)
- `rulesets/typescript/index.md`TypeScript 核心约定(47 行)
- `rulesets/markdown/index.md`Markdown 核心约定(31 行,仅代码格式化)
更多说明:`rulesets/index.md`
### 维护原则
**.agents/Layer 1)修改规则**
- 可做:增加安全漏洞类型、更新核心约定、添加硬性约束
- 不可做:添加推荐型最佳实践(→ skill)、详细语法解释(→ skill/docs)、超过 50 行(→ 拆分)
**SkillsLayer 2)创建规则**
- 可做:增加新流程、从零教授新语言、添加跨语言通用知识
## SKILLSCodex CLI / Claude Code
本仓库内置一组 AI agent skills(见 `skills/`),支持 Codex CLI 和 Claude Code,用于按需加载的工作流与知识库。
TSL 相关问题直接查阅 `rulesets/tsl/index.md``docs/tsl/`
**通用 Skills**
- `$commit-message`:提交信息规范
- `$style-cleanup`:整理代码风格
- `$bulk-refactor-workflow`:批量重构流程
- 更多见 `SKILLS.md`
**安装与使用**:详见 `SKILLS.md`
如果你通过 `[install_skills]` 更新已经安装过的 skill,默认会先把旧目录备份为 `*.bak.<timestamp>`;如果你明确希望“删除旧版本后直接重装”,可在 `playbook.toml``[install_skills]` 下设置 `no_backup = true`
## 在其他项目中使用本 Playbook
由于本仓库需要内部权限访问,其他项目**不能仅用外链引用**;推荐把 Playbook 规范部署到项目内,并用统一入口执行。
### 快速决策:我应该用哪种方式?
| 你的情况 | 推荐方式 | 优势 |
| ------------------------------------------------------------- | --------------------------------- | --------------------------------------------- |
| 新项目,需要持续同步更新 | 方式一:`git subtree` | 标准留在项目内,后续可拉取更新 |
| 不想把 Playbook 以 subtree 嵌进仓库,但仍要把标准部署到项目内 | 方式二:外部 clone 后执行部署 | Playbook 仓库与业务仓库解耦,部署根目录可配置 |
| **不确定?** | **方式一:`git subtree`(推荐)** | 项目内可见、版本可追溯、使用路径最稳定 |
---
### TL;DR - 30 秒快速开始
先区分三个路径概念:
- `project_root`:目标项目根目录。
- `deploy_root`:相对于 `project_root` 的项目内目标目录。
- 外部 clone 出来的 Playbook 路径(如 `/opt/playbook`):只是执行部署脚本的位置,不是部署目标。
以 TSL 为例,Playbook 在项目内的默认部署根是 `docs/standards/playbook`;如果你把 `deploy_root` 改成 `custom/playbook`,则部署结果会落到 `<project_root>/custom/playbook`,文档和脚本入口也会跟着变成 `custom/playbook/docs/...``custom/playbook/scripts/...`
#### 方式一:`git subtree`
```bash
# 1. 引入标准快照
git subtree add --prefix docs/standards/playbook https://git.mytsl.cn/csh/playbook.git main --squash
# 2. 在项目根创建配置(示例见 docs/standards/playbook/playbook.toml.example
cat <<'EOF' > playbook.toml
[playbook]
project_root = "."
[sync_standards]
langs = ["tsl"]
EOF
# 3. 执行统一入口
python docs/standards/playbook/scripts/playbook.py -config playbook.toml
# 4. 提交
git add .
git commit -m ":package: deps(playbook): add tsl standards"
```
---
### 方式一:git subtree 同步(推荐)
1. 在目标项目中首次引入:
```bash
git subtree add --prefix docs/standards/playbook https://git.mytsl.cn/csh/playbook.git main --squash
```
2. 后续同步更新:
```bash
git subtree pull --prefix docs/standards/playbook https://git.mytsl.cn/csh/playbook.git main --squash
```
3. 在项目根配置并执行:
```toml
# playbook.toml
[playbook]
project_root = "."
[sync_standards]
langs = ["tsl", "cpp"]
[sync_rules]
[sync_memory_bank]
project_name = "MyProject"
```
```bash
python docs/standards/playbook/scripts/playbook.py -config playbook.toml
```
配置参数说明见 `docs/standards/playbook/playbook.toml.example`。
---
### 方式二:外部 clone 后执行部署
如果你不想把 Playbook 以 `git subtree` 嵌进目标项目,可以把 Playbook clone 到项目外部,再由该 clone 直接把标准部署进目标项目。
1. 先在任意位置 clone Playbook
```bash
git clone https://git.mytsl.cn/csh/playbook.git /opt/playbook
```
2. 在目标项目根创建 `playbook.toml`,并用 `deploy_root` 指定项目内的部署根。例如:
- `project_root` 写目标项目根目录。
- `deploy_root` 写目标项目内的相对路径。
- 不要把外部 clone 的路径(如 `/opt/playbook`)写进 `deploy_root`;那只是你执行脚本的位置。
```toml
[playbook]
project_root = "."
deploy_root = "custom/playbook"
[vendor]
langs = ["tsl"]
[sync_standards]
langs = ["tsl"]
[sync_rules]
[sync_memory_bank]
project_name = "MyProject"
```
3. 在目标项目根执行外部 clone 里的统一入口:
```bash
python /opt/playbook/scripts/playbook.py -config playbook.toml
```
说明:
- 这里的 `[vendor]` 是“把 Playbook 快照部署进目标项目”的执行步骤,不是第三种正式部署路线。
- `deploy_root` 永远表示目标项目内的部署目录;它不是外部 clone 出来的 Playbook 仓库路径。
- 外部 clone 场景下必须显式填写 `deploy_root`;脚本不会替你补默认部署目录。
- 如果 `deploy_root = "custom/playbook"`,部署后的项目内入口会是 `custom/playbook/scripts/playbook.py`、`custom/playbook/docs/index.md`。
---
### 多语言项目落地(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):
```txt
.
├── .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
├── <deploy_root>/ # 本 Playbook 在项目内的部署根(默认 docs/standards/playbook
│ ├── docs/
│ ├── rulesets/
│ ├── scripts/
│ └── templates/
├── docs/project/ # 项目自有文档(架构、ADR、运行方式等)
├── playbook.toml # 统一入口配置
└── src/ # 源码目录(按项目实际情况)
```
**规则优先级建议**
- 同一项目内多个规则集并行放在 `.agents/<lang>/`,不要互相覆盖
- 若某个子目录需要更具体规则(模块/子系统差异),在更靠近代码的目录放置更具体规则(例如
`src/foo/.agents/`),并以"离代码更近者优先"为准