文档规范按工程、介绍、参考三类分列,要求用标识符而非行号定位代码,并逐维度核对边界;提交规范采用 Conventional Commits,一次提交只做一件事;注释规范区分调用方契约与实现说明。项目概览不再重复,改为指向 README.md。
9.7 KiB
AGENTS.md
This file holds the working standards for this repository. Project overview, commands, architecture, and configuration live in README.md — read that first, and do not duplicate it here.
Documentation Standards
Docs fall into three categories with different standards. Pick the category before writing and state it at the top of the file (for example, > Doc type: implementation). The categories are engineering docs (plan, implementation, bug fix), introductory docs, and reference docs (APIs, configuration, error codes).
Common rules (all docs)
- Never locate code by line number. Use
pathplus an identifier (function, type, constant, config key), for exampleAdapter.Executeininternal/infrastructure/adk/adapter.go. Line numbers drift when code changes; identifiers do not. - One concept, one term. Use the same word for the same thing throughout a doc, with no synonyms. Define each term at its first use, for example: Armory — the chain of responsibility that turns YAML configuration into runnable agents.
- Do not document what you cannot verify. Mark unverified behavior
TBDand say how to confirm it (whom to ask, which command to run). Never present a guess as fact. - Generate reference docs from code or schema. Build API lists, config keys, and error-code tables from
go doc, route registration code, the YAML schema, or the constants inpkg/types, then proofread the result. Hand-written parts must be checked against the source entry by entry. - Examples must run. Commands, configuration, and snippets should be copy-paste runnable. Mark anything that does not run as
illustrative, untested. - Do not repeat onboarding content that already exists in the README; link to it. Keep each fact in one place.
Engineering docs (plan / implementation / bug fix)
Goal: someone else can execute, verify, and debug from the doc alone. Be as detailed and specific as possible.
Each entry is self-contained and states at least:
- Preconditions: required configuration, services, permissions, existing changes, version assumptions.
- Parameters and defaults: name, type, unit, value range, and behavior when omitted.
- Returns and side effects: what it returns, what it writes, what events it emits, whether it is idempotent and reentrant.
- Failure modes and error codes: when it fails, the error or HTTP code, the message text, retry semantics.
- Observability: log fields, metrics, traces, how to confirm success or failure, where to start debugging.
Organize by the question the reader asks (for example "add an agent", "switch to Redis storage", "debug error 0002"), not by source-file order. Each section is readable on its own; no reading order is required.
Walk all nine boundary dimensions. Write "undefined" explicitly where behavior is undefined; never leave a gap.
| Dimension | Questions to answer |
|---|---|
| Input | empty values, oversized input, invalid characters, encoding, duplicate keys, unknown fields |
| Numeric | zero, negative, upper bounds, precision, overflow, unit mismatch |
| Resource | concurrency limits, memory and file handles, connection-pool exhaustion, large objects |
| Time | timeouts, clock skew, retry backoff, TTL, time zones |
| State | repeated execution, concurrent modification, recovery after restart, partial success |
| Permission | who may call, privilege escalation, missing or expired credentials, tenant isolation |
| Failure | downstream outage, partial failure, degradation, rollback |
| Version | protocol and configuration compatibility, upgrade and rollback paths |
| Environment | dev versus prod differences, platform differences, missing env vars, origin of default values |
Per-category additions:
- Plan: phases, deliverables and acceptance criteria per phase, dependency order, rollback points, deferred or out-of-scope items with reasons.
- Implementation: change list at file and identifier level (not line numbers), migration and compatibility strategy, verification steps (command plus expected output), rollout and rollback steps.
- Bug fix: close the loop — phenomenon → reproduction (minimal steps plus environment) → root cause → blast radius → fix → verification → regression risk. Reproduction steps must run standalone; the root cause names the exact code path and trigger, not "some logic is wrong".
Introductory docs
Goal: the reader gains a complete, clear picture and can run the thing.
Include one runnable main path, in four steps, with no gaps:
- What it is: one sentence of positioning plus 3–5 key characteristics.
- What problem it solves: the pain without it, grounded in a concrete scenario.
- How it solves it: the overall approach and key trade-offs, saying why this way and not another.
- How it is implemented: the implementation path — entry point, key modules, data flow, output.
Also provide a directory map (one line of responsibility per module or directory, using identifiers rather than line numbers) and the implementation path (the components and functions a request passes from entry to persistence or response). Mention detail without going to engineering-doc depth; link to engineering docs for the rest.
Use precise, plain words in the spirit of ASD-STE100: one idea per sentence, active voice, few nested clauses, one verb per action, sparing pronouns, no adjective stacking, no marketing language. Prefer short sentences and short paragraphs. Stop once the main path is covered; do not chase full coverage.
Commit Standards
- Language: write commit messages in Chinese; keep
typeandscopein English. - Format: Conventional Commits,
type(scope): subject.- type is
feat/fix/docs/refactor/test/chore; useperf/build/ci/style/revertwhen warranted. - scope is the affected module — a first-level directory or subsystem under
internal/orfrontend/, such asagent,armory,chat,adk,config,http,frontend. Omit it, or userepo, for changes that span modules. - subject is imperative, states what changed and why it matters, takes no trailing period, and stays around 50 characters.
- Add a body when needed for motivation and impact, wrapped at 72 characters. Flag breaking changes with
!after the type or aBREAKING CHANGE:footer.
- type is
- Examples (subjects in Chinese, matching the language rule):
feat(armory): 支持用环境变量覆盖模型温度fix(chat): 会话不存在时返回 0002 而不是 0001docs(agents): 补充文档、提交与注释规范
- No single-shot commits. Do not stuff a batch of changes into one commit, and do not hoard work until the end of a task.
- Granularity: one logical change per commit, independently buildable (
go build ./...,cd frontend && npm run build) and independently revertable (git revertleaves the repository usable). Split the commit if either fails. - Titles carry information. Ban
update,fix bug,修改,优化,提交and similar zero-information titles; the title alone must tell what changed without opening the diff. - Do not mix categories. Formatting, renames, and import sorting go in their own
styleorrefactorcommit, separate from behavior changes. Pure file moves userefactorwith "no behavior change" in the body. - Unrelated problems noticed along the way get their own commit or a tracked note; do not smuggle them into the current commit.
Comment Standards
Comments come in two kinds with different jobs. Do not let them bleed into each other.
Doc comments (for callers)
State what it is and how to use it: what the exported identifier does, what its parameters mean and constrain, what it returns, when it fails, and the side effects a caller must know about (concurrency safety, lock holding, blocking, idempotency).
Describe the contract and usage only — not internal choices such as "implemented with a skip list". Implementations change; contracts do not. Go doc comments start with the identifier name. Exported frontend functions and components carry JSDoc/TSDoc for parameters and return values. Package comments state the package boundary and its invariants.
Implementation comments (for maintainers)
Write only what the code cannot express:
- Why this way: the reason for this approach over another.
- Non-obvious ordering and locking: what must precede what, which lock guards which state, why a lock cannot be taken at that point.
- Magic numbers: where 4 tool-call iterations, timeouts, and retry counts come from (protocol limit, measurement, upstream docs).
- Workarounds: the concrete bug being bypassed and the condition under which the code can be deleted.
Never write:
- Restatements of the code (
i++ // increment i). - Commented-out code: version control keeps it, so delete it.
- Author, date, or change history: git already has that.
- Language truisms: what an error is, what a goroutine is.
- Internal detail in doc comments: which data structure or private function is used.
- Line numbers or copies of variable names that go stale on rename.
- What a rename or a smaller function should say instead: a comment explaining "this variable holds pending items" is a request to rename the variable.
- ASCII banners and separator lines.
- Ownerless TODOs (
// TODO: optimize). If one is needed, write// TODO(module): condition and action, with an issue number when possible.
Length and where knowledge lands
- One point per comment; if one line carries it, do not write three.
- Design notes that belong in introductory or engineering docs stay short in code: link to the doc or leave a pointer. Code comments keep only what the reader needs on the spot.
- Change comments together with the code. Any behavior change requires re-reading the affected comments; a stale comment is worse than none.