find-simplifications

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Finding simplifications

寻找简化机会

Turn a broad "find things to simplify" request into evidence-backed Agent Notes that remove or collapse existing surface across code, docs, and skills. It is guidance, not a checklist: follow the code, keep judgment active, and prefer a few well-proven candidates over a pile of thin guesses.
将宽泛的“寻找可简化内容”请求转化为有证据支持的Agent Notes,以移除或合并代码、文档和Skill中现有的冗余内容。这是指导方针而非检查清单:跟随代码逻辑,保持判断力,优先选择少数经充分验证的候选对象,而非大量缺乏依据的猜测。

Start with repo context

从仓库上下文入手

  • Read the root
    AGENTS.md
    — the pre-release stance when present, and conventions such as tests-are-not-golden-truth and Agent Notes-are-not-golden-truth doctrines — plus the repository's defensive-patterns and testing docs when they exist.
  • Skim the architecture doc before judging core code; simplifications that fight the service map or event taxonomy need extra evidence.
  • Use the Agent Note tree and its rules to understand intentional architecture; a recorded decision needs new evidence to overturn, not a "looks complex" flag. Start with high-signal implemented examples — capability seams, twin adapters, and persistence notes — when the tree has them.
  • Treat recorded architectural twins — dual LLM adapters and dual persistence backends — as intentional by default. Do not propose deleting either side as "low effort" unless the user explicitly overrides that constraint. Removing an unused method or hook inside a protected seam can still be valid if it does not collapse the protected design.
  • 阅读根目录下的
    AGENTS.md
    ——若存在预发布立场,以及诸如“测试并非绝对真理”和“Agent Notes并非绝对真理”的原则——此外,若仓库有防御模式和测试文档,也需一并阅读。
  • 在评判核心代码前,先浏览架构文档;与服务映射或事件分类相悖的简化方案需要额外的证据支持。
  • 利用Agent Notes树及其规则理解既定架构;已记录的决策需要新的证据才能推翻,而非仅凭“看起来复杂”的标记。当树中存在高信号的已实现示例(如能力接缝、双适配器和持久化说明)时,从这些示例入手。
  • 默认将已记录的架构双实现(如双LLM适配器和双持久化后端)视为有意设计。除非用户明确推翻该约束,否则不要提议删除任意一方作为“低工作量”的简化。若不破坏受保护的设计,移除受保护接缝内未使用的方法或钩子仍是有效的简化。

What counts as a strong candidate

什么是优质候选对象

A strong simplification removes, folds, or demotes something real and has clear evidence that the current design costs more than it buys:
  • A public method, event, config knob, registry notification, helper, package, durable event, or test artifact has no production consumer.
  • Tests or docs are the only consumers, and the behavior they pin is not load-bearing.
  • Two representations mirror the same fact, especially across durable events and transient in-memory events.
  • A seam has methods every implementation must support but no consumer uses.
  • A separate package exists only for test/demo/support code and adds publish or dependency overhead.
  • A feature implements speculative product generality: multi-session/session-load, background job rosters, live registry invalidation, mid-turn steering, tool-owned UI rendering, and similar designs with no product owner.
  • An invariant, rollback path, set of expected outputs, or special-case test exists only to protect an unused API.
  • Hand-rolled code reimplements what a well-maintained external package or a builtin at the repository's engine floor already provides, and the swap would delete the implementation plus its dedicated tests.
  • The simplified behavior may differ slightly, but the new behavior is still reasonable and easier to explain.
Thin candidates are usually not enough for an Agent Note: deleting one typo, running a dead-code tool once, removing an intentionally documented backend or adapter, or flagging "this looks complex" without call-site proof.
优质的简化会移除、合并或降级实际存在的内容,且有明确证据表明当前设计的成本大于其价值:
  • 公共方法、事件、配置项、注册表通知、辅助工具、包、持久化事件或测试工件没有生产环境消费者。
  • 只有测试或文档是其消费者,且它们锁定的行为并非核心必要。
  • 两种表示形式反映同一事实,尤其是在持久化事件和临时内存事件之间。
  • 某个接缝包含所有实现必须支持但无消费者使用的方法。
  • 某个独立包仅用于测试/演示/支持代码,却增加了发布或依赖开销。
  • 某个功能实现了投机性的产品通用性:多会话/会话加载、后台作业清单、实时注册表失效、中途转向、工具自有UI渲染等无产品负责人的类似设计。
  • 某个不变量、回滚路径、预期输出集或特殊用例测试仅用于保护未使用的API。
  • 自行实现的代码重复了维护良好的外部包或仓库引擎层内置功能的逻辑,替换后可删除该实现及其专用测试。
  • 简化后的行为可能略有不同,但新行为仍合理且更易解释。
薄弱候选对象通常不足以生成Agent Note:删除一个拼写错误、运行一次死代码工具、移除有意记录的后端或适配器,或是仅标记“这看起来复杂”却无调用站点证据。

Survey broadly

全面调查

Use parallel subagents when the user asks for breadth or many candidates. Give each agent a domain and require evidence, not guesses. Useful domains:
  • Agent loop and session log: turn/step boundaries, steering, abort/cancel, durable events, replay, load/resume.
  • Automation and human UI APIs: prompt settlement and teardown on the protocol side; transcript rendering and interaction state on the UI side.
  • LLM/tools/system prompt: stream/generate APIs, assemblers, registries, tool schema defaults, presentation hooks.
  • Bash and tool execution: foreground/background split, job ownership, output spill files, executor methods.
  • Packages/examples/scripts/tests: package splits, static inventories, redundant snapshot expected outputs, support packages.
If subagents are unavailable, simulate the same breadth yourself. Do not let the first good candidate stop the survey.
Start with the largest production-code deltas. A broad audit that stops after obvious unused symbols can miss the files where duplicated lifecycle or defensive machinery carries most of the cost.
当用户要求广度或大量候选对象时,使用并行子Agent。为每个Agent分配一个领域,并要求提供证据而非猜测。有用的领域包括:
  • Agent循环和会话日志:回合/步骤边界、转向、中止/取消、持久化事件、重放、加载/恢复。
  • 自动化和人工UI API:协议端的提示确认和清理;UI端的转录渲染和交互状态。
  • LLM/工具/系统提示:流/生成API、组装器、注册表、工具模式默认值、展示钩子。
  • Bash和工具执行:前台/后台拆分、作业所有权、输出溢出文件、执行器方法。
  • 包/示例/脚本/测试:包拆分、静态清单、冗余快照预期输出、支持包。
若无法使用子Agent,则自行模拟同样的广度调查。不要因找到第一个优质候选对象就停止调查。
从最大的生产代码差异入手。仅在发现明显未使用符号后就停止的全面审计,可能会错过那些重复生命周期或防御机制占据大部分成本的文件。

Audit trust and lifecycle boundaries

审核信任与生命周期边界

For every defensive copy, freeze, validator, and callback capture, name where the value came from and who owns it next. Same-process typed service/plugin calls ordinarily borrow readonly values; parsers, config loaders, queues, model/tool JSON, durable files, workers, processes, and wire decoders own or validate their data. Tests built around hostile getters, fake typed objects, callback replacement, or mutation after a same-process handoff are evidence of a potentially speculative contract, not automatic justification for keeping it.
For complex asynchronous code, draw the ownership graph and map each sentinel, readiness promise, cancellation path, disposer, and state flag to a distinct owner or transition. When several mechanisms mirror the same liveness or settlement fact, propose one transaction or lifecycle controller instead. Preserve separate machinery where it protects synchronous publication and rollback, callback containment, first-terminal-outcome arbitration, worker/process ownership, or dispose-to-quiescence.
对于每个防御性复制、冻结、验证器和回调捕获,明确其值的来源及后续所有者。同进程类型化服务/插件调用通常借用只读值;解析器、配置加载器、队列、模型/工具JSON、持久化文件、工作进程、进程和 wire 解码器拥有或验证其数据。围绕恶意 getter、伪造类型化对象、回调替换或同进程传递后突变构建的测试,是潜在投机性契约的证据,而非保留相关代码的自动理由。
对于复杂的异步代码,绘制所有权图,并将每个标记、就绪Promise、取消路径、处置器和状态标志映射到明确的所有者或转换。当多个机制反映相同的活跃性或结算事实时,提议使用单个事务或生命周期控制器替代。在保护同步发布和回滚、回调包含、首个终端结果仲裁、工作进程/进程所有权或处置至静默状态的场景下,保留独立机制。

Hand-rolled code versus a dependency

自行实现代码与依赖的对比

Introducing a dependency is a valid simplification move, not a policy exception; the repository's dependency policy, when recorded, owns the bar. When surveying, ask of protocol parsers, framers, retry/backoff loops, glob matchers, diff engines, and similar infrastructure: does a well-maintained package or a builtin at the repository's engine floor already do this?
Prove a dependency-swap candidate like any other, plus:
  • Read the hand-rolled implementation and name the exact surface the package covers; residual semantics the package does not cover count against the swap and stay in the Agent Note.
  • Check the package's health honestly (maintenance, adoption, transitive footprint) and prefer builtins when the engine floor has them.
  • Check the Agent Note tree first: recorded seams are settled — a swap that collapses one needs to beat the recorded rationale, not just cite the policy.
  • Weigh net deletion: implementation plus dedicated tests plus docs, minus the glue that remains. A wrapper that relocates the same complexity is not a win.
引入依赖是有效的简化手段,而非政策例外;仓库的依赖政策(若已记录)决定了准入门槛。调查时,针对协议解析器、成帧器、重试/退避循环、glob匹配器、差异引擎等基础设施,询问:维护良好的包或仓库引擎层的内置功能是否已实现此功能?
像对待其他候选对象一样验证依赖替换候选,此外还需:
  • 阅读自行实现的代码,明确包覆盖的确切内容;包未覆盖的剩余语义会对替换造成负面影响,需写入Agent Note。
  • 如实检查包的健康状况(维护情况、采用率、传递依赖规模),优先选择引擎层的内置功能。
  • 先查看Agent Notes树:已记录的接缝是既定方案——替换会破坏接缝的,需推翻已记录的理由,而非仅引用政策。
  • 权衡净删除量:实现代码加专用测试加文档,减去剩余的粘合代码。仅将复杂性转移到包装器的替换并非成功。

Prove or reject each candidate

验证或否决每个候选对象

For every symbol or behavior, classify consumers before writing:
  • Production corpus: production source (e.g.
    packages/*/src
    ,
    examples/*/src
    ,
    examples/**/*.yml
    ), runtime scripts, and loader/config paths.
  • Non-production corpus: tests, README/docs, Agent Notes, snapshots, generated expected outputs, and comments.
  • Ambiguous corpus: examples and scripts that may be product smoke paths. Inspect usage before classifying.
Use
rg
first. Good searches include the exact symbol, event name, package name, config key, method name with both
.name(
and
name(
, and any wire strings. Then read the call sites. A dead-code tool such as
knip
can help, but it is not a substitute for understanding public interfaces, dynamic event names, tests, docs, and loader paths.
Reject or downgrade a candidate when:
  • A production caller exists and the simplification would be a feature decision rather than a cleanup.
  • The API is explicitly justified by an implemented Agent Note or a hard-won defensive pattern, and the new evidence does not beat that reason.
  • The removal would force unrelated churn without actually reducing the public API or required behavior.
  • The idea is correct but tiny. Add a targeted TODO/FIXME/XXX instead, using the urgency semantics in the repository's conventions doc.
在编写内容前,对每个符号或行为的消费者进行分类:
  • 生产语料库:生产源码(如
    packages/*/src
    examples/*/src
    examples/**/*.yml
    )、运行时脚本和加载器/配置路径。
  • 非生产语料库:测试、README/文档、Agent Notes、快照、生成的预期输出和注释。
  • 模糊语料库:可能是产品冒烟测试路径的示例和脚本。分类前需检查其使用情况。
首先使用
rg
工具。有效的搜索包括精确符号、事件名称、包名称、配置键、包含
.name(
name(
的方法名称,以及任何wire字符串。然后查看调用站点。
knip
等死代码工具可能有帮助,但不能替代对公共接口、动态事件名称、测试、文档和加载器路径的理解。
出现以下情况时,否决或降级候选对象:
  • 存在生产环境调用者,简化将是功能决策而非清理操作。
  • API已通过已实现的Agent Note或来之不易的防御模式明确证明其合理性,且新证据无法推翻该理由。
  • 移除操作会导致无关代码变更,却未实际减少公共API或必要行为。
  • 想法正确但影响极小。改用仓库约定文档中的紧急语义,添加针对性的TODO/FIXME/XXX标记。

Coalesce superseded Agent Notes

合并已过时的Agent Notes

When the user asks to reduce or coalesce the note tree, or a simplification makes an owning note obsolete, follow the coalescing workflow: classify each old note fully or partially, consolidate through the note-archiving skill, and repair every inbound link before deleting a superseded triplet.
当用户要求精简或合并Notes树,或某个简化使所属Note过时,遵循合并工作流:对每个旧Note进行完全或部分分类,通过Note归档Skill合并,并在删除过时的三元组前修复所有入站链接。

Write the Agent Note

编写Agent Note

Create one file per durable proposal under the repository's note tree — typically
.agents/notes/<lifecycle>/<class>/yyyy-mm-dd-topic.md
— following its lifecycle and classification rules. Keep prose paragraphs on one physical line and use relative Markdown links.
Prefer this structure, adjusting when the idea needs it:
  • # Agent Note: <action-oriented title>
  • Status: proposed
  • ## Problem
    : name the current API, cite the relevant files, and state the consumer evidence. Separate production callers from tests/docs.
  • ## Proposal
    : say exactly what to remove, fold, demote, or rehome. Include tests, docs, READMEs, JSDoc, event-taxonomy, snapshot, and generated-file cleanup when relevant.
  • ## Why not keep it?
    or
    ## What we give up
    : make the strongest counterargument legible.
  • ## Acceptance criteria
    : observable end state and gates.
  • ## Risks
    : public API changes, behavior changes, future product wants, and why the tradeoff is still reasonable.
Be concrete enough that an implementing PR can follow the trail. Avoid vague "simplify this package" Agent Notes. When a proposal overlaps an existing Agent Note, consolidate the useful details into the existing one rather than creating a duplicate.
在仓库的Notes树下为每个持久化提案创建一个文件——通常为
.agents/notes/<lifecycle>/<class>/yyyy-mm-dd-topic.md
——遵循其生命周期和分类规则。将散文段落保持在一行,并使用相对Markdown链接。
优先采用以下结构,可根据想法调整:
  • # Agent Note: <面向操作的标题>
  • Status: proposed
  • ## 问题
    : 说明当前API,引用相关文件,并陈述消费者证据。区分生产环境调用者与测试/文档调用者。
  • ## 提案
    : 明确说明要移除、合并、降级或迁移的内容。涉及测试、文档、README、JSDoc、事件分类、快照和生成文件的清理时也需包含在内。
  • ## 为何不保留?
    ## 我们将放弃什么
    : 清晰列出最有力的反对论据。
  • ## 验收标准
    : 可观察的最终状态和准入条件。
  • ## 风险
    : 公共API变更、行为变更、未来产品需求,以及为何权衡仍合理。
内容需足够具体,以便实现PR可依照执行。避免模糊的“简化此包”类Agent Note。当提案与现有Agent Note重叠时,将有用细节整合到现有Note中,而非创建重复内容。

Inline TODO notes

内联TODO标记

Use inline TODO/FIXME/XXX only for small, local cleanups that are clearly useful but not durable design decisions. Keep them short and actionable:
  • Name the smell with a stable tag, e.g.
    TODO(double-default)
    or
    XXX(unused-default)
    .
  • Explain why it is safe to revisit and what action would simplify it.
  • Do not add TODOs for speculative complaints or for behavior that needs an Agent Note-level decision.
仅将内联TODO/FIXME/XXX用于小型、局部的明确有用但非持久化设计决策的清理。保持简短且可操作:
  • 使用稳定标记命名问题,例如
    TODO(double-default)
    XXX(unused-default)
  • 说明为何可以重新审视以及什么操作可简化它。
  • 不要为投机性抱怨或需要Agent Note级决策的行为添加TODO。

When folding another PR or branch

整合其他PR或分支的内容

When folding simplification ideas from a sibling PR or branch, follow the folding workflow: diff against the base branch, port only the non-overlapping candidates that meet the bar, and update the PR body.
当整合来自同级PR或分支的简化想法时,遵循整合工作流:与基准分支对比差异,仅移植符合标准的非重叠候选对象,并更新PR正文。

Validation and PR hygiene

验证与PR规范

For docs-only Agent Note work, run at least the repository's documentation gates, lint, and
git diff --check
— for example
pnpm run doc-sync
plus
pnpm run lint
in a pnpm repo. For code or skill changes, also run the relevant validator when one exists. Select any other evidence from the outgoing diff; the pre-push hook contributes typecheck only.
When opening or updating a PR, summarize:
  • How many Agent Notes and inline notes were added, consolidated, retained as partial supersessions, or deleted.
  • The main areas surveyed.
  • What was intentionally excluded.
  • Which checks passed.
For each consolidation group, name the old and current owners, state the evidence for full supersession, and explain why deletion is safe. If an added-then-removed scan finds no qualifying note, report that result and the representative partial cases retained.
Use a draft PR while the survey is still expanding; mark ready only when the candidate set, review responses, and validation are settled.
对于仅涉及文档的Agent Note工作,至少运行仓库的文档检查、lint和
git diff --check
——例如在pnpm仓库中运行
pnpm run doc-sync
pnpm run lint
。对于代码或Skill变更,若存在相关验证器,也需运行。从输出差异中选择其他证据;预推送钩子仅提供类型检查。
打开或更新PR时,总结:
  • 添加、合并、保留为部分过时或删除的Agent Notes和内联标记的数量。
  • 调查的主要领域。
  • 有意排除的内容。
  • 通过的检查项。
对于每个组合组,说明旧所有者和当前所有者,陈述完全过时的证据,并解释删除的安全性。若添加后又移除的扫描未找到符合条件的Note,需报告结果以及保留的代表性部分案例。
调查仍在扩展时使用草稿PR;仅当候选对象集、评审反馈和验证均确定后,再标记为就绪。