docs: split language by audience, add Codex / AGENTS.md spec
Language policy: Chinese for human-facing files (README, docs/, human-fillable templates), English for AI-facing files (CLAUDE.md, AGENTS.md, AI templates). Commits / PRs / branches / tags stay English. - Translate docs/01-06 to Chinese - Translate README.md, PR / handoff / project README templates to Chinese - Drop README.en.md (redundant once language policy is explicit) - Rewrite CLAUDE.md and CLAUDE.md.template under the new policy - Add AGENTS.md (root) and templates/AGENTS.md.template for Codex - Add docs/07-codex.md covering Codex usage and AGENTS.md / CLAUDE.md sync rules Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
1 parent
411f0b8182
commit
154f592f3c
16 files changed
+901
-690
No files matched your search
+70
-85
@@ -1,111 +1,96 @@
|
||||
# 05 — Code & deliverable style
|
||||
# 05 — 代码与产出风格
|
||||
|
||||
Naming, comments, structure. Same rules apply whether a human or Claude
|
||||
typed the code.
|
||||
命名、注释、结构。不论是人写的还是 AI 写的代码,都按这套来。
|
||||
|
||||
## Naming
|
||||
## 命名
|
||||
|
||||
- **Files** — lowercase, hyphens for docs (`git-workflow.md`),
|
||||
underscores for Python (`task_runner.py`), kebab for JS/TS where the
|
||||
ecosystem prefers it. Match the surrounding project.
|
||||
- **Functions** — verb phrases. `loadConfig`, not `config`. `runTask`,
|
||||
not `taskRunner`.
|
||||
- **Variables** — say what they are, not their type. `users`, not
|
||||
`userArray`. `retryCount`, not `n`.
|
||||
- **Booleans** — `is*`, `has*`, `should*`. `isReady`, not `ready`.
|
||||
- **Constants** — `UPPER_SNAKE_CASE` only when truly module-level
|
||||
constants. Inside functions, just use a normal `const`.
|
||||
- **No abbreviations** unless they're a domain term. `database`, not
|
||||
`db`. `request`, not `req`. (`req`/`res` in Express handlers is fine —
|
||||
domain convention.)
|
||||
- **文件** —— 小写。文档用连字符(`git-workflow.md`),Python 用
|
||||
下划线(`task_runner.py`),JS/TS 跟生态走 kebab。匹配周围项目。
|
||||
- **函数** —— 动词短语。`loadConfig` 不是 `config`;`runTask`
|
||||
不是 `taskRunner`。
|
||||
- **变量** —— 写它**是什么**,不写它的类型。`users` 不是
|
||||
`userArray`;`retryCount` 不是 `n`。
|
||||
- **布尔** —— `is*`、`has*`、`should*`。`isReady` 不是 `ready`。
|
||||
- **常量** —— `UPPER_SNAKE_CASE` 仅用于真正的模块级常量。函数内用
|
||||
普通 `const`。
|
||||
- **不要缩写**——除非是领域术语。`database` 不是 `db`,`request`
|
||||
不是 `req`。(Express handler 里的 `req`/`res` 是领域约定,可以。)
|
||||
|
||||
## Comments
|
||||
## 注释
|
||||
|
||||
Default to none. A comment is justified when **all** are true:
|
||||
默认不写。要写注释,**全部**条件成立:
|
||||
|
||||
- The *why* is non-obvious from the code.
|
||||
- A future reader would otherwise misread the code.
|
||||
- The code itself can't be made clearer (rename, extract, restructure).
|
||||
- "为什么"从代码里看不出来。
|
||||
- 未来读代码的人不写注释会读错。
|
||||
- 代码本身改不清晰(重命名、抽函数、重组都试过)。
|
||||
|
||||
Don't write:
|
||||
不要写:
|
||||
|
||||
- `// increment counter` next to `counter++`
|
||||
- `// added for the auth refactor` — belongs in the commit message
|
||||
- Block comments restating function signatures
|
||||
- TODOs without an owner or a date — they rot. Either fix it now, file
|
||||
an issue, or delete the comment.
|
||||
- `// increment counter` 紧挨着 `counter++`
|
||||
- `// added for the auth refactor` —— 这话该在 commit message 里
|
||||
- 一大段 docstring 只是把签名复述一遍
|
||||
- 没有 owner 没有日期的 TODO —— 它们会烂掉。要么现在修,要么开
|
||||
issue,要么删了。
|
||||
|
||||
Do write:
|
||||
可以写:
|
||||
|
||||
- One-liners explaining a non-obvious workaround, with the *why*.
|
||||
- A `# NOTE:` when behavior would surprise a reader.
|
||||
- Module headers only when a file does something the directory layout
|
||||
doesn't already explain.
|
||||
- 一行解释一个非显而易见的 workaround,带上**为什么**。
|
||||
- `# NOTE:` 标注会让读者意外的行为。
|
||||
- 文件头注释,仅限于这个文件做的事目录结构没说清楚。
|
||||
|
||||
## File structure
|
||||
## 文件结构
|
||||
|
||||
- One concept per file. If you can't summarize the file in one sentence,
|
||||
split it.
|
||||
- Keep tests next to the code, not in a parallel tree, unless the
|
||||
project already does the parallel tree.
|
||||
- Generated files go in `dist/`, `build/`, or similar — and into
|
||||
`.gitignore`. Never edit a generated file.
|
||||
- Lockfiles are checked in. Always.
|
||||
- 一个文件一个概念。一句话说不清这个文件干啥——拆。
|
||||
- 测试文件挨着代码放,除非项目本来就是平行测试树。
|
||||
- 生成文件进 `dist/` / `build/` 这类目录,进 `.gitignore`。永远
|
||||
不改生成文件。
|
||||
- Lockfile 必须 commit,永远。
|
||||
|
||||
## Errors
|
||||
## 错误
|
||||
|
||||
- Fail loudly at boundaries (user input, external APIs, file I/O).
|
||||
- Don't `try/except` to silence errors. If you catch, you handle.
|
||||
- Internal functions trust their callers. Don't validate the same input
|
||||
three layers deep.
|
||||
- Logged errors include enough context to debug from logs alone — what
|
||||
was being attempted, which inputs, which path.
|
||||
- 在边界处(用户输入、外部 API、文件 I/O)大声失败。
|
||||
- 不要 `try/except` 吞错。捕了就处理。
|
||||
- 内部函数信任调用方,不要在三层深度上重复校验同一个输入。
|
||||
- 日志里的错要带够上下文,光看日志能调试——做的什么操作、输入是
|
||||
什么、走的哪条路径。
|
||||
|
||||
## Tests
|
||||
## 测试
|
||||
|
||||
- Test the behavior, not the implementation. If a refactor that
|
||||
preserves behavior breaks a test, the test was wrong.
|
||||
- One assertion per test, ideally. "Tests that test many things at once
|
||||
fail unhelpfully."
|
||||
- Fixtures live next to the tests that use them.
|
||||
- Slow / flaky tests get marked or quarantined, not silently retried.
|
||||
- New code without a test is incomplete unless the project genuinely
|
||||
has no test infrastructure (rare, and a bug in itself).
|
||||
- 测行为,不测实现。一个保留行为的重构把测试搞挂了——是测试错。
|
||||
- 一个测试一个断言为佳。"啥都测的测试,挂了你不知道是哪一个挂了。"
|
||||
- Fixture 和用它的测试放一起。
|
||||
- 慢 / flaky 的测试加标记或隔离,不要默默重试。
|
||||
- 没测试的新代码就是没写完——除非项目真的没有测试基础设施
|
||||
(罕见,而且这本身是个 bug)。
|
||||
|
||||
## READMEs
|
||||
## README
|
||||
|
||||
Every repo has a `README.md`. It answers, in order:
|
||||
每个仓库都要有 `README.md`。按这个顺序回答:
|
||||
|
||||
1. **What is this?** One paragraph.
|
||||
2. **How do I run it?** Bash blocks for setup, run, test.
|
||||
3. **How do I develop on it?** Where the code lives, what the conventions
|
||||
are.
|
||||
4. **Where does the data come from / go to?** Only if non-obvious.
|
||||
5. **Pointers.** Related repos, dashboards, docs.
|
||||
1. **这是什么?** 一段话。
|
||||
2. **怎么跑?** Setup / run / test 的 bash 块。
|
||||
3. **怎么开发?** 代码在哪,约定是什么。
|
||||
4. **数据从哪来 / 去哪?** 仅当不显然才写。
|
||||
5. **指针。** 关联仓库、dashboard、文档。
|
||||
|
||||
Use `templates/README.md.template`. If the README is shorter than the
|
||||
template, that's fine — delete the unused sections.
|
||||
用 `templates/README.md.template`。如果你的 README 比模板短,没问题
|
||||
——把没用的 section 删掉。
|
||||
|
||||
## Deliverables (task packages, datasets, exports)
|
||||
## 交付物(任务包、数据集、导出)
|
||||
|
||||
When we ship a deliverable to a partner or downstream consumer:
|
||||
给伙伴或下游交付时:
|
||||
|
||||
1. Versioned filename: `<name>-v<n>.<ext>` or `<name>-<YYYYMMDD>.<ext>`.
|
||||
Pick one convention per project and stick to it.
|
||||
2. Ships with a `README` describing schema, generation date, known
|
||||
limitations.
|
||||
3. Ships with a verification report (counts, checksums, sanity checks)
|
||||
in the same archive.
|
||||
4. Exact commit hash that produced it goes in the README.
|
||||
1. 文件名带版本:`<name>-v<n>.<ext>` 或 `<name>-<YYYYMMDD>.<ext>`。
|
||||
一个项目一种约定,定了别变。
|
||||
2. 配 `README` 写明 schema、生成日期、已知限制。
|
||||
3. 配验证报告(计数、checksum、合理性检查),跟交付物一起打包。
|
||||
4. 生成它的 commit hash 写进 README。
|
||||
|
||||
See `docs/06-handoff.md` for the full checklist.
|
||||
完整 checklist 见 [docs/06-handoff.md](06-handoff.md)。
|
||||
|
||||
## What NOT to do
|
||||
## 不要做的事
|
||||
|
||||
- Don't introduce a third way to do something we already do two ways.
|
||||
Pick one and migrate.
|
||||
- Don't add config options "for flexibility" without a real use case.
|
||||
YAGNI.
|
||||
- Don't refactor unrelated code in a feature PR. Open a separate PR.
|
||||
- Don't optimize before measuring. "It might be slow" is not a
|
||||
measurement.
|
||||
- 不要引入第三种做某件事的方式——已经有两种了。挑一种统一。
|
||||
- 不要"为了灵活性"加配置开关,没有真实用例就别加。YAGNI。
|
||||
- 不要在功能 PR 里顺手重构无关代码。开新 PR。
|
||||
- 不要没量就先优化。"可能慢"不是测量结果。
|
||||
Reference in new issue
Block a user