investigate-codebase
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseInvestigate Codebase
调查代码库
Objective
目标
Build the minimum sufficient, falsifiable model needed to answer the user's
question. Prefer a thin vertical slice over an exhaustive repository summary.
Optimize for human understanding and verification, not the amount of code read.
构建回答用户问题所需的最低充分且可证伪的模型。优先采用精简的垂直切片,而非详尽的代码仓库总结。以促进人类理解和验证为目标,而不是以读取代码量为目标。
Operating contract
操作契约
- Read all applicable repository and agent instruction files before inspecting
implementation, including nested per-directory files under whichever convention
the repository uses (for example ,
AGENTS.md, orCLAUDE.md).CONTRIBUTING.md - Default to read-only investigation. Do not edit files, install dependencies, switch branches, reset state, or alter durable resources unless the user requested that action.
- Preserve unrelated and dirty worktree changes. Separate committed changes from local modifications before drawing conclusions.
- Record the repository revision. For change analysis, resolve and record the exact base and head revisions rather than silently guessing.
- Treat README files, architecture documents, comments, and PR descriptions as intent evidence that must be reconciled with implementation and behavior.
- Start narrow. Expand scope only when a dependency, contract, contradiction, or unresolved hypothesis requires it.
- Prefer version-control history, manifests, exact symbol references, fast
repository-wide text search (,
rg, or the equivalent available in the environment), language-native tooling, tests, and runtime observation. Use semantic or embedding search only to locate candidate code, never as behavioral proof.grep - Use whatever file-reading, search, and command-execution capabilities the host
environment provides. If a capability required by a check is unavailable, record
the check as with the reason rather than substituting a weaker claim.
UNKNOWN - Ask before checks that may use production credentials, access external systems, mutate durable state, incur meaningful cost, or take substantial time.
- Never equate passing tests, high coverage, or clean static analysis with proof of complete correctness.
- 在检查实现之前,读取所有适用的代码仓库和 Agent 指令文件,包括代码仓库按照自身约定设置在各子目录中的嵌套文件,例如 、
AGENTS.md或CLAUDE.md。CONTRIBUTING.md - 默认采用只读调查。除非用户明确要求,否则不要编辑文件、安装依赖、切换分支、重置状态或更改持久性资源。
- 保留无关变更和未提交的工作区变更(dirty worktree changes)。得出结论前,将已提交的变更与本地修改区分开来。
- 记录代码仓库版本。对于变更分析,应解析并记录准确的 base 和 head 版本,而不是在未说明的情况下猜测。
- 将 README 文件、架构文档、注释和 PR 描述视为意图证据,并将其与实现和行为进行核对。
- 从狭窄范围开始。仅当依赖、契约、矛盾或尚未解决的假设要求扩大范围时才扩展调查。
- 优先使用版本控制历史、manifest、精确的符号引用、快速的全仓库文本搜索(、
rg或环境中可用的等效工具)、语言原生工具、测试和运行时观察。语义搜索或 embedding 搜索只能用于定位候选代码,绝不能作为行为证据。grep - 使用宿主环境提供的任何文件读取、搜索和命令执行能力。如果某项检查所需的能力不可用,应将该检查记录为 并说明原因,而不是以较弱的结论替代。
UNKNOWN - 在执行可能使用生产凭据、访问外部系统、改变持久性状态、产生显著成本或耗费大量时间的检查前,先征求用户同意。
- 绝不能将测试通过、较高覆盖率或静态分析无问题等同于完整正确性的证明。
Select the investigation
选择调查方式
Choose one primary mode and read its guide completely:
- : Map a large or unfamiliar repository. Read orient-large-codebase.md.
ORIENT - : Explain a concrete runtime, control, or data flow. Read trace-runtime-flow.md.
TRACE - : Analyze a PR, branch, commit, or diff. Read analyze-pr-impact.md.
IMPACT - : Assess generated or changed code. Read verify-generated-code.md.
VERIFY
Combine modes only when necessary, such as . Read only the
guides required for the selected modes.
IMPACT + VERIFYChoose a depth:
- : Find landmarks and a likely path; keep uncertainty explicit.
scan - : Produce an evidence-backed explanation and focused checks. Use by default.
working - : Broaden risk and verification coverage when explicitly requested or warranted by the change's consequences.
audit
State the selected mode, depth, scope, revision, assumptions, and important
environment limits in the result.
选择一个主要模式,并完整阅读对应的指南:
- :梳理大型或陌生的代码库。阅读 orient-large-codebase.md。
ORIENT - :解释具体的运行时、控制流或数据流。阅读 trace-runtime-flow.md。
TRACE - :分析 PR、branch、commit 或 diff。阅读 analyze-pr-impact.md。
IMPACT - :评估生成或已变更的代码。阅读 verify-generated-code.md。
VERIFY
仅在必要时组合模式,例如 。只阅读所选模式所需的指南。
IMPACT + VERIFY选择调查深度:
- :查找关键地标和可能的路径,并明确保留不确定性。
scan - :给出有证据支撑的解释并执行聚焦检查。默认使用此深度。
working - :在用户明确要求或变更后果确有需要时,扩大风险和验证覆盖面。
audit
在结果中说明所选模式、深度、范围、版本、假设和重要的环境限制。
Investigation loop
调查循环
1. Anchor the target
1. 锚定目标
- Identify the repository root, applicable instructions, working-tree state, revision, build system, and relevant runtime configuration.
- For a PR or branch, resolve the actual comparison base from PR metadata or the merge base. Keep unrelated local changes out of the comparison.
- Exclude generated, vendored, fixture, snapshot, lockfile, and formatting noise from semantic analysis unless one of them changes behavior or contracts.
- 确定代码仓库根目录、适用指令、工作区状态、版本、构建系统和相关的运行时配置。
- 对于 PR 或 branch,从 PR 元数据或 merge base 解析出实际比较基线。不得将无关的本地变更纳入比较。
- 除非生成内容、vendored 依赖、fixture、snapshot、lockfile 或格式化噪声会影响行为或契约,否则应将其排除在语义分析之外。
2. Frame falsifiable questions
2. 界定可证伪的问题
- Rewrite the request as observable questions: given which input and preconditions, what output, state change, side effect, or failure should occur?
- Identify available correctness oracles: explicit requirements, acceptance criteria, public contracts, schemas, stable prior behavior, domain invariants, reference implementations, or production observations.
- If no independent oracle exists, state which consistency claims can be assessed and which intent claims cannot be established.
- 将请求改写为可观察的问题:给定哪些输入和前置条件,应产生什么输出、状态变化、副作用或失败?
- 识别可用的正确性 oracle:明确需求、验收标准、公共契约、schema、稳定的既有行为、领域不变量、参考实现或生产观察结果。
- 如果不存在独立的 oracle,应说明哪些一致性结论可以评估,以及哪些意图性结论无法确立。
3. Build the minimum map
3. 构建最小映射
- Locate only the relevant manifests, boundaries, entry points, public contracts, configuration, persistence, external effects, and tests.
- Describe components by runtime or domain responsibility rather than by directory.
- Mark dynamic dispatch, dependency injection, reflection, generated code, plugins, queues, and callbacks as unresolved edges until supported by evidence.
- 仅定位相关的 manifest、边界、入口、公共契约、配置、持久化、外部影响和测试。
- 根据运行时职责或领域职责描述组件,而不是根据目录结构描述。
- 在获得证据之前,将动态分派、依赖注入、反射、生成代码、插件、队列和 callback 标记为未解析的边。
4. Trace a thin vertical slice
4. 追踪精简的垂直切片
Follow the smallest path that can answer the question:
input boundary -> parsing/auth -> orchestration -> domain decisions -> state or external effect -> output/error/telemetryTrack control flow, data-shape changes, state ownership, feature flags, async
boundaries, retries, serialization, errors, and observable side effects when relevant.
沿能够回答问题的最小路径继续追踪:
输入边界 -> 解析/认证 -> 编排 -> 领域决策 -> 状态或外部副作用 -> 输出/错误/遥测根据相关性追踪控制流、数据形状变化、状态所有权、feature flag、异步边界、重试、序列化、错误和可观察副作用。
5. Maintain an evidence ledger
5. 维护证据账本
For each material claim, record:
| Claim | Evidence status | Revision + path/symbol or command | Result or limitation |
|---|
Use these labels:
- : Directly supported by implementation, configuration, schema, or diff.
SOURCE - : Observed through an executed command, test, log, trace, or reproducer.
RUNTIME - : Reasoned from evidence but not directly observed.
INFERRED - : Missing code, environment, specification, oracle, or access.
UNKNOWN - : A counterexample or conflicting source disproves the claim.
CONTRADICTED
Prefer ; use line numbers as secondary anchors because
they drift. Include exact commands and outcomes for runtime evidence. Never label a
statically inferred call path as an observed runtime trace.
revision + file + symbol对于每项实质性论断,记录:
| 论断 | 证据状态 | 版本 + 路径/符号或命令 | 结果或限制 |
|---|
使用以下标签:
- :直接得到实现、配置、schema 或 diff 的支持。
SOURCE - :通过执行命令、测试、日志、trace 或 reproducer 观察到。
RUNTIME - :根据证据推理得出,但未直接观察到。
INFERRED - :缺少代码、环境、规范、oracle 或访问权限。
UNKNOWN - :反例或冲突来源推翻了该论断。
CONTRADICTED
优先使用 ;行号仅作为辅助定位依据,因为行号会发生变化。对于运行时证据,应包含准确命令及其结果。绝不能将通过静态分析推断出的调用路径标记为已观察到的 runtime trace。
版本 + 文件 + 符号6. Challenge the model
6. 质疑模型
- Turn the model into predictions that could be false.
- Search for contradictory call sites, tests, schemas, configuration, history, and runtime behavior.
- Consider empty and boundary inputs, permissions, ordering, retries, idempotency, concurrency, partial failure, compatibility, migration, rollback, and external boundary behavior according to risk.
- Ask which unchanged behavior must remain invariant, not only what changed.
- 将模型转化为可能被证伪的预测。
- 搜索相互矛盾的调用点、测试、schema、配置、历史记录和运行时行为。
- 根据风险考虑空输入和边界输入、权限、顺序、重试、幂等性、并发、部分失败、兼容性、迁移、回滚和外部边界行为。
- 询问哪些未改变的行为必须保持不变量,而不只是关注发生变化的行为。
7. Verify economically
7. 以合理成本进行验证
Choose the cheapest check capable of falsifying each important claim:
- Source, type, schema, and configuration inspection
- Typecheck, lint, compile, or static analysis
- Focused unit or component test
- Integration or end-to-end path
- Base/head differential, property, metamorphic, adversarial, or mutation check
- Runtime trace or production-like observation
Prefer focused checks tied to a hypothesis over an untargeted full suite. Distinguish
pre-existing failures, regressions, flaky outcomes, skipped checks, timeouts, and
environment mismatches. Do not hide checks that could not run.
为每项重要论断选择能够将其证伪的最低成本检查:
- 源代码、类型、schema 和配置检查
- 类型检查、lint、编译或静态分析
- 聚焦的单元测试或组件测试
- 集成路径或端到端路径
- base/head 差异检查、property 检查、metamorphic 检查、adversarial 检查或 mutation 检查
- runtime trace 或类生产环境观察
优先执行与具体假设相关的聚焦检查,而不是无目标地运行完整测试套件。应区分既有失败、回归、不稳定结果、被跳过的检查、超时和环境不匹配。不得隐藏无法运行的检查。
8. Synthesize for human use
8. 面向人类综合结果
Answer the question before presenting supporting detail. Use progressive disclosure:
- : Direct answer, primary path, and largest uncertainty.
30 seconds - : Minimal model, contracts or invariants, behavior delta, and risks.
5 minutes - : Evidence ledger, commands, results, contradictions, and unknowns.
Audit
Limit the first map to roughly five to seven meaningful components and one to three
representative flows. Provide a five-to-twelve-file reading route in causal or
dependency order, with one reason per file. If the user is learning, finish with
two or three prediction questions that test whether the model transfers.
先回答问题,再呈现支撑细节。采用渐进式披露方式:
- :直接答案、主要路径和最大的不确定性。
30 seconds - :最小模型、契约或不变量、行为差异和风险。
5 minutes - :证据账本、命令、结果、矛盾和未知项。
Audit
第一张映射应限制在大约五到七个有意义的组件,以及一到三条代表性流程。提供一条包含五到十二个文件的阅读路径,按因果关系或依赖关系排序,并为每个文件说明一个选择理由。如果用户是在学习,应以两到三个预测问题结束,以检验该模型能否迁移到新场景。
Report contract
报告契约
Return the sections relevant to the selected mode:
- Direct answer
- Scope, mode, depth, revision, and base/head when applicable
- Minimal architecture or execution-flow model
- Contracts and invariants
- Evidence ledger
- Behavioral impact or correctness matrix
- Risks, contradictions, assumptions, and unknowns
- Recommended reading route
- Smallest next verification steps
- Prediction questions when learning is part of the goal
Use a diagram only when it materially clarifies at least three boundaries, branches,
or state transitions. Do not produce a full repository tree as a substitute for a model.
Phrase correctness conclusions conditionally, for example:
At revision X in environment Y, evidence supports behavior Z for scenarios A and B. Scenario C and external dependency D remain unverified.
Do not output an uncalibrated correctness percentage.
返回与所选模式相关的章节:
- 直接答案
- 范围、模式、深度、版本,以及适用时的 base/head
- 最小架构或执行流模型
- 契约与不变量
- 证据账本
- 行为影响或正确性矩阵
- 风险、矛盾、假设和未知项
- 推荐阅读路径
- 最小的后续验证步骤
- 当目标包含学习时的预测问题
仅当图示能够实质性澄清至少三个边界、分支或状态转换时才使用图示。不得用完整的代码仓库目录树代替模型。
正确性结论应采用有条件的表述,例如:
在版本 X 和环境 Y 下,现有证据支持场景 A 和 B 中的行为 Z。场景 C 和外部依赖 D 仍未验证。
不要输出未经校准的正确性百分比。
Completion criteria
完成标准
Stop when:
- the target question has a supported answer;
- the relevant entry, decisions, state ownership, side effects, and failure path are accounted for to the requested depth;
- every material claim has evidence or is explicitly marked unknown;
- verification results and limitations are reproducible; and
- further exploration is unlikely to change the answer materially.
Do not continue exploring merely to appear exhaustive.
满足以下条件时停止:
- 目标问题已有证据支持的答案;
- 相关入口、决策、状态所有权、副作用和失败路径在 requested depth 下均已得到说明;
- 每项实质性论断都有证据支持,或已明确标为 ;
UNKNOWN - 验证结果和限制均可复现;
- 继续探索不太可能对答案造成实质性改变。
不要仅为显得详尽而继续探索。