tidy
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAgent 变笨,多半是它每次读到的东西太多、太旧、太乱。这一次只做减法:合并、删除、拦住,不加新功能。
每一步先把要改的列给用户看,用户点头再动手。删掉的东西 git 里都还在,确认没人引用就可以删。
An Agent becomes less effective, usually because it has too much to read, too much of it is outdated, and the material is too disorganized. This pass is about subtraction only: consolidate, delete, and enforce limits—no new features.
Before making changes in each step, show the user a list of the proposed changes and wait for approval before proceeding. Deleted content is still available in Git, so confirm that nothing references it before removing it.
1. 同一条规矩只放一处
1. Keep Each Rule in One Place Only
找出业务规则(算不算迟到、价格怎么算、谁能看什么)分别写在了哪几处。同一条规则出现在两处以上,就收到一个地方,其他地方改成调用它。代码长得像、管的却是不同的事,就各留各的。
做完的标准:每条业务规则只剩一个出处,测试照样通过。
Find every place where business rules—such as whether someone counts as late, how prices are calculated, and who can view what—are written. If the same rule appears in more than one place, consolidate it into one location and point the other locations to it. Code may look similar but govern different concerns, so keep those separate.
Definition of done: every business rule has exactly one source, and the tests still pass.
2. 清废料
2. Remove the Clutter
- 死代码:没有任何地方引用的文件、函数、导出,搜索确认后删掉。
- 注释:复述代码的删掉,讲「为什么这么做」的留下;和代码对不上的,照代码改过来。
- 过时的文档:已经做完或作废的草稿、计划、旧版说明,删掉。
- Dead code: files, functions, and exports that nothing references. Search to confirm this, then delete them.
- Comments: delete comments that merely restate the code; keep those that explain “why”; if a comment no longer matches the code, update it to match.
- Outdated documentation: drafts, plans, and older documentation for work that has been completed or made obsolete.
3. 装文件大小钩子
3. Install a File-Size Hook
用 Git 的提交前钩子:提交的文件超过 5,000 token(字节数 ÷ 4,约 20 KB)就拒绝提交,报错写明这个文件多大,请按功能拆成几个文件。lockfile、自动生成的代码、构建产物这类 agent 不会去读的文件,跳过不查。项目已经在用 husky、lefthook、pre-commit 这类工具的,加在它里面。
装好后拿一个超标的文件试:提交必须被拦下,拆完再提交必须通过。已经超标的文件列出来交给用户,这一步不顺手去拆。
再在 AGENTS.md 里写两行:提交被钩子拒了,照报错拆文件再提交;写新函数、新规则前,先搜项目里有没有现成的。
Use a Git pre-commit hook: reject the commit if a file being committed exceeds 5,000 tokens (bytes ÷ 4, roughly 20 KB). The error should state the file's size and instruct the user to split it into several files based on functionality. Skip files the Agent will not read, such as lockfiles, generated code, and build artifacts. If the project already uses a tool such as husky, lefthook, or pre-commit, add the check to that existing setup.
After installation, test it with an oversized file: the commit must be blocked, and after the file is split, the commit must pass. List files that are already over the limit for the user; do not split them as part of this step.
Then add two lines to AGENTS.md: If a commit is rejected by the hook, split the file as directed by the error and try again; before writing a new function or rule, search the project for an existing one.
4. AGENTS.md 和工具瘦身
4. Slim Down AGENTS.md and Tooling
- AGENTS.md 压到 100 行左右:留下项目是做什么的、这个项目特有的坑、指向 的路标。看一眼目录、
docs/或package.json就知道的删掉;长篇细节挪进--help,在 AGENTS.md 里用一行指过去。docs/ - 工具:列出全局装着、但这个项目用不上的 MCP、skill 和插件,建议用户改成只在需要的项目里开。全局配置交给用户自己改。
- 老犯的错:同一个错 agent 犯了两次以上,加一条 lint 规则或测试拦住,不往 AGENTS.md 里写提醒。
- 记忆插件:写代码时建议用户关掉,最新的代码和 git 记录就是记忆。
- Reduce AGENTS.md to around 100 lines: Keep what the project does, project-specific gotchas, and pointers to . Delete information that can be learned at a glance from the directory listing,
docs/, orpackage.json; move lengthy details into--helpand leave a one-line pointer in AGENTS.md.docs/ - Tooling: List globally installed MCP servers, skills, and plugins that this project does not need, and recommend enabling them only in projects that need them. Leave global configuration changes for the user to make.
- Recurring mistakes: If the Agent makes the same mistake at least twice, add a lint rule or test to prevent it instead of adding a reminder to AGENTS.md.
- Memory plugin: Recommend turning it off while writing code; the latest code and Git history are the memory.
5. 交差
5. Report the Results
规矩收拢:<规则> → <路径>(原来 N 处)
删掉:N 个文件,N 行
钩子:<装在哪>;超标文件被拦下、拆完通过
AGENTS.md:N 行 → N 行
建议关掉的工具:…;没有就写「无」
还超标、没拆的文件:…;没有就写「无」最后告诉用户以后的三个习惯:读代码、搜资料交给 sub-agent,只带回结论;聊长了就 ;换任务就清空,开一个新对话。
/compactRules consolidated: <rule> → <path> (previously N locations)
Deleted: N files, N lines
Hook: <installed in>; oversized file blocked; passes after splitting
AGENTS.md: N lines → N lines
Tools recommended for disabling: …; "None" if there are none
Files still over the limit and unsplit: …; "None" if there are noneFinally, tell the user to adopt three habits from now on: delegate code reading and research to a sub-agent and bring back only the conclusions; use /compact when the conversation gets long; clear the conversation when switching tasks and start a new one.