tandy
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesetandy
tandy
A note from Andy
Andy 的一点说明
I like simple systems and code that feels obvious. Don't preserve complexity just because it already exists, and don't add machinery because it looks impressive. Understand the real constraint, then build the smallest thing that makes the correct behavior unsurprising. Measure twice, cut once, and YAGNI. Finish everything the task needs, and nothing it doesn't.
These are strong defaults. The repo's own / and my explicit instructions override them. If a rule here fights the task, say so clearly and wait for my sign-off before breaking it. Never break one silently.
AGENTS.mdCLAUDE.md我喜欢简单的系统,以及看起来一目了然的代码。不要仅仅因为复杂逻辑已经存在就保留它,也不要因为某种机制看起来很厉害就添加它。理解真正的约束,然后构建能让正确行为显得自然而然的最小实现。反复衡量,果断取舍,遵循 YAGNI。完成任务所需的一切,不做任务之外的事。
这些是优先采用的默认原则。仓库自身的 / 以及我的明确指令会覆盖这些原则。如果这里的规则与任务冲突,请明确指出,并在违反规则前等待我确认。绝不能默默违反规则。
AGENTS.mdCLAUDE.mdScope
范围
- Simplify or delete existing code only when it is in the path of the task, and say so in the plan or PR.
- Anything worth fixing outside that path becomes a one-line follow-up note. Don't touch it.
- No "while I was here" changes: no unrelated formatting, renames or refactors.
- No backwards compatibility nobody asked for: no old code paths kept alive, no deprecation shims, no copies. Change the code.
v2
- 只有当现有代码处于任务路径中时,才对其进行简化或删除,并且要在 plan 或 PR 中说明。
- 路径之外任何值得修复的问题,都只写一行后续处理说明。不要动它。
- 不做“顺便”修改:不改无关格式、不重命名、不重构。
- 不维护没人要求的向后兼容性:不保留旧代码路径,不添加弃用 shim,也不创建 副本。直接修改代码。
v2
Before writing code
写代码之前
Take the first option that fully works:
- Does it need to exist? If not, skip it and name what you skipped in one line.
- Already in this codebase? Reuse the helper, component or pattern the way the surrounding code does.
- An installed dependency or the platform/stdlib? Use it.
- Can you extend something existing (a variant, an option, a case) instead of creating a parallel copy? Extend it.
- Otherwise, write new code: the least that works, in the structure the codebase already has.
Never add a dependency for a few lines. Any new dependency must be called out in the plan for approval.
优先选择第一个能够完整工作的方案:
- 真的需要它吗? 如果不需要,跳过,并用一行说明跳过了什么。
- 代码库中已经有了? 按照周边代码的用法复用 helper、component 或 pattern。
- 已有 dependency 或 platform/stdlib? 直接使用。
- 能扩展现有实现吗? 通过增加 variant、option 或 case 来扩展现有实现,而不是创建一套并行副本。请扩展它。
- 否则,编写新代码: 按照代码库已有的结构,写能够工作的最少代码。
绝不为几行代码新增 dependency。任何新 dependency 都必须在 plan 中明确提出以供批准。
Errors
错误
- Validate at trust boundaries: user input, API requests and responses, webhooks, third-party data. Inside the app, trust your own types.
- Never swallow an error. Handle it in a way that has meaning (retry, fallback, a message the user sees) or let it propagate. A catch that only logs and continues is a bug.
- Errors the user sees are actionable ("Couldn't save, try again"), never raw stack traces or internal messages.
- No defensive code for impossible states. If it truly matters, assert and fail loudly.
- 在信任边界进行校验:用户输入、API 请求与响应、webhook、第三方数据。在应用内部,信任自己的类型。
- 绝不吞掉错误。以有意义的方式处理(重试、fallback、向用户显示的消息),或者让错误向上传播。只记录日志后继续执行的 catch 就是一个 bug。
- 用户看到的错误应当可操作(“无法保存,请重试”),绝不能是原始 stack trace 或内部消息。
- 不要为不可能发生的状态编写防御性代码。如果确实需要处理,就 assert 并显式失败。
Types
类型
-
Let types be inferred. Annotate only at public boundaries: exported functions, API contracts, component props.
-
No. Use
anyand narrow it at the trust boundary.unknown -
No casts () to silence the compiler. Fix the type model, or explain in one line why the cast is safe.
as Foo -
Make impossible states unrepresentable: discriminated unions instead of several optional fields or booleans.
-
One source of truth for each type. Derive types from the schema, DB or validator instead of redefining a shape by hand.
-
Branch on a union or enum with+
switch, never anassertNeverchain. Every value gets its ownif. A value that should do nothing gets an explicit case, so adding a new value fails the build until someone decides what it does:casetsswitch (status) { case "active": activate(); break; case "paused": pause(); break; case "archived": // no-op: archived items are read-only break; default: assertNever(status); }Use the repo's existing. If the repo has none, add one to the shared utils. For plain value lookups, useassertNever, which gives the same build-time check.Record<MyEnum, T>
-
让类型自动推断。只在公共边界添加类型标注:导出的函数、API contract、component props。
-
不使用。使用
any,并在信任边界对其进行缩窄。unknown -
不要用强制类型转换()来消掉 compiler 报错。修复类型模型,或者用一行说明 cast 为什么是安全的。
as Foo -
让不可能的状态无法表示:使用 discriminated union,而不是多个可选字段或 boolean。
-
每种类型只保留一个事实来源。通过 schema、DB 或 validator 派生类型,不要手动重复定义结构。
-
使用+
switch对 union 或 enum 进行分支处理,绝不使用assertNever链。 每个值都要有独立的if。不应执行任何操作的值也要有明确的 case,这样新增一个值时,构建会失败,直到有人决定它应该如何处理:casetsswitch (status) { case "active": activate(); break; case "paused": pause(); break; case "archived": // no-op: archived items are read-only break; default: assertNever(status); }使用仓库现有的。如果仓库没有,则在共享 utils 中添加一个。对于普通的值查找,使用assertNever,它能提供相同的构建期检查。Record<MyEnum, T>
State (React)
状态(React)
- Derive, don't sync. If a value can be computed from props or state, compute it in render.
- is only for syncing with something outside React (subscriptions, the DOM, timers). Logic triggered by a user action goes in the event handler.
useEffect - Server data lives in the repo's data-fetching layer, not copied into or a global store.
useState - Keep state as local as possible. Lift it only when two components really share it. Global stores are for truly app-wide state only.
- Every async view handles loading, empty and error states explicitly.
- 派生状态,不要同步状态。如果某个值可以由 props 或 state 计算出来,就在 render 中计算。
- 只用于与 React 外部的东西同步(订阅、DOM、定时器)。由用户操作触发的逻辑放进事件处理器。
useEffect - 服务端数据放在仓库的数据获取层,不要复制到 或 global store 中。
useState - 让 state 尽可能保持局部。只有两个组件确实共享时才向上提升。global store 只用于真正贯穿整个应用的状态。
- 每个异步视图都要显式处理加载、空和错误状态。
Data and performance
数据与性能
- No N+1 queries, at all costs. Never query inside a loop. Load related data in batches: joins, , a dataloader, or the ORM's include/preload.
IN (...) - No unbounded queries or lists. Always paginate or limit.
- Migrations must be safe on existing data. No destructive change without a plan for the rows already there.
- 绝不允许 N+1 查询,无论如何都不行。 绝不要在循环中查询。批量加载关联数据:使用 join、、dataloader,或 ORM 的 include/preload。
IN (...) - 查询和列表都不能无限制。始终分页或设置 limit。
- migration 必须对现有数据安全。如果没有针对已有行的处理方案,就不能做破坏性变更。
Tests
测试
- Default to integration tests against a real database. Don't mock DB interactions.
- Use unit tests with mocked infrastructure only for edge cases that are hard to reproduce for real, like rare error paths.
- Test behavior through public interfaces, not internals. Never mock code from the same repo.
- Must have a test: every bug fix (a test that fails before the fix), and new non-trivial logic (branches, parsers, money, permissions, data writes). Trivial wiring and pure layout need none.
- One good test beats coverage padding. No snapshot tests by default, and no tests that only check that a mock was called.
- Follow the repo's existing test framework, style and location.
- 默认采用针对真实数据库的 integration test。不要 mock DB 交互。
- 只有在难以真实复现的边缘场景中,才使用带 mocked infrastructure 的 unit test,例如罕见错误路径。
- 通过 public interface 测试行为,而不是内部实现。绝不 mock 同一仓库中的代码。
- 以下情况必须有测试:每个 bug 修复(修复前会失败的测试),以及新的非平凡逻辑(分支、parser、金额、权限、数据写入)。简单接线和纯布局无需测试。
- 一个好的测试胜过为了凑覆盖率而增加的测试。默认不使用 snapshot test,也不写只检查 mock 是否被调用的测试。
- 遵循仓库现有的 test framework、风格和测试位置。
Comments
注释
- No comment by default. Write one only for what the code can't show: a constraint, a quirk of an external system, an invariant, a non-obvious why. One line where possible, four at most.
- Never restate the code, narrate steps, record history, or explain the fix you just made. That belongs in the PR.
- No TODOs unless they link to an issue in the tracker: .
// TODO(<issue-id>): ... - Docstrings only on exported APIs whose signature doesn't explain itself.
- 默认不写注释。只为代码本身无法表达的内容写注释:约束、外部系统的异常特性、不变量、不明显的原因。尽量一行,最多四行。
- 绝不复述代码、叙述执行步骤、记录历史,或解释刚刚完成的修复。这些内容应写在 PR 中。
- 除非 TODO 链接到 tracker 中的 issue,否则不要写 TODO:。
// TODO(<issue-id>): ... - 只有当导出 API 的签名本身无法说明其含义时,才写 docstring。
Files and naming
文件与命名
- Follow the repo's conventions for folders, file names and casing. Copy the closest sibling feature. Never introduce a new convention in passing.
- Put code next to where it's used. Move a helper to shared code only when a second feature needs it. No catch-all .
helpers.ts - One concept per file. Split by responsibility, never by line count.
- Name things after what they mean in the domain (), not their type (
invoiceDueDate,dateObj). No abbreviations beyond well-known ones (dataList,id).url - No barrel files (re-exports) unless the repo already uses them.
index.ts
- 遵循仓库关于目录、文件名和大小写的约定。参照最接近的同类 feature。不要顺手引入新约定。
- 把代码放在使用位置附近。只有第二个 feature 需要时,才把 helper 移到共享代码中。不要创建包揽一切的 。
helpers.ts - 每个文件只承载一个概念。按职责拆分,绝不按行数拆分。
- 按其代表的领域含义命名(),而不是按类型命名(
invoiceDueDate、dateObj)。除通用缩写(dataList、id)外,不使用缩写。url - 不要使用 barrel file(通过 重新导出),除非仓库已经在使用。
index.ts
Never cut
绝不删减
Even under YAGNI and minimal diffs, always keep:
- Validation at trust boundaries.
- Error handling that prevents data loss or silent failure.
- Security and permission checks. Never weaken one to make something work.
- Loading, empty and error states for async UI.
- Accessibility basics: semantic elements, labels, keyboard access.
- Safe migrations.
- No N+1 queries, and no unbounded queries or lists.
- Anything Andy explicitly asked for. You may say it seems unnecessary, but build it.
即使遵循 YAGNI 和最小 diff,也始终保留:
- 信任边界处的校验。
- 防止数据丢失或静默失败的错误处理。
- 安全与权限检查。绝不能为了让功能可用而削弱检查。
- 异步 UI 的加载、空和错误状态。
- accessibility 基础能力:语义化元素、label、键盘访问。
- 安全的 migration。
- 不使用 N+1 查询,也不使用无限制的查询或列表。
- Andy 明确要求的任何内容。你可以认为它没有必要,但仍然要实现。
Never do
绝不做
- Change unrelated files: formatting, renames, "while I was here" refactors.
- Over-abstract: a factory, interface or generic for a single use.
- Add backwards compatibility nobody asked for: old paths, shims, copies.
v2 - Say it's done without running tests, lint and typecheck, or claim they pass when they don't.
- Weaken a test, or add ,
skip,anyor@ts-ignoreto get to green.eslint-disable - Leave , debug code or commented-out code behind.
console.log - Hardcode magic values that belong in a constant, config or the DB.
- Write long final reports or PR descriptions. Say what changed, how it was verified, and what's left. Nothing more.
- 修改无关文件:格式调整、重命名、“顺手”重构。
- 过度抽象:为单次使用创建 factory、interface 或 generic。
- 添加没人要求的向后兼容性:旧路径、shim、副本。
v2 - 未运行 test、lint 和 typecheck 就声称完成,或在它们未通过时声称通过。
- 削弱测试,或为了让检查通过而添加 、
skip、any或@ts-ignore。eslint-disable - 留下 、调试代码或被注释掉的代码。
console.log - 硬编码本应放在常量、配置或 DB 中的 magic value。
- 写冗长的最终报告或 PR 描述。只说明改了什么、如何验证、还剩什么。不要多说。
Using tandy while planning
在规划时使用 tandy
When gathering context, grilling or planning, use tandy to decide what to change and what to leave alone:
- Mark what can be reused, what must stay untouched, and what in the path of the task can be simplified or deleted.
- Don't ask questions tandy already answers. Ask only where tandy says nothing, or where a rule conflicts with the task.
- Put deliberate omissions and out-of-path cleanups in the plan's "Out of scope" section.
收集上下文、追问或规划时,使用 tandy 来决定哪些内容要改,哪些内容应保持不动:
- 标明哪些内容可以复用、哪些必须保持不动,以及任务路径中的哪些内容可以简化或删除。
- 不要询问 tandy 已经回答的问题。只在 tandy 没有说明,或某条规则与任务冲突时提问。
- 将刻意省略的内容和路径之外的清理项放入 plan 的“Out of scope”部分。