# 编写 Agent Briefs Agent brief 是 GitHub issue 或 PR 移动到 `ready-for-agent` 时发布在其上的结构化 comment。它是 AFK agent 后续工作的权威 spec。原始 body 和讨论是 context;agent brief 是 contract。 Brief 说明 **agent 应该做什么**,这延伸到两种 surface:对 issue,是从零构建 change;对 PR,是*在现有 diff 上*还剩什么要做:完成它、补齐缺口、处理 review 意见。两种情况原则相同;下面的 PR 示例展示了差异。 ## 原则 ### 持久优于精确 Issue 可能会在 `ready-for-agent` 中停留数天或数周。期间 codebase 会变化。写 brief 时要让它在文件被重命名、移动或 refactor 后仍然有用。 - **Do** 描述 interfaces、types 和 behavioral contracts - **Do** 命名 agent 应该查找或修改的具体 types、function signatures 或 config shapes - **Don't** 引用 file paths;它们会过期 - **Don't** 引用 line numbers - **Don't** 假设当前 implementation structure 会保持不变 ### 行为而非过程 描述系统应该做**什么**,而不是**如何**实现。Agent 会重新探索 codebase,并做出自己的 implementation decisions。 - **Good:** "The `SkillConfig` type should accept an optional `schedule` field of type `CronExpression`" - **Bad:** "Open src/types/skill.ts and add a schedule field on line 42" - **Good:** "When a user runs `/triage` with no arguments, they should see a summary of issues needing attention" - **Bad:** "Add a switch statement in the main handler function" ### 完整的 acceptance criteria Agent 需要知道什么时候算完成。每个 agent brief 都必须有具体、可测试的 acceptance criteria。每条 criterion 都应该能独立验证。 - **Good:** "Running `gh issue list --label needs-triage` returns issues that have been through initial classification" - **Bad:** "Triage should work correctly" ### 明确的 scope 边界 说明什么不在范围内。这可以防止 agent gold-plating 或对相邻功能做假设。 ## 模板 ```markdown ## Agent Brief **Category:** bug / enhancement **Summary:** one-line description of what needs to happen **Current behavior:** Describe what happens now. For bugs, this is the broken behavior. For enhancements, this is the status quo the feature builds on. **Desired behavior:** Describe what should happen after the agent's work is complete. Be specific about edge cases and error conditions. **Key interfaces:** - `TypeName`: what needs to change and why - `functionName()` return type: what it currently returns vs what it should return - Config shape: any new configuration options needed **Acceptance criteria:** - [ ] Specific, testable criterion 1 - [ ] Specific, testable criterion 2 - [ ] Specific, testable criterion 3 **Out of scope:** - Thing that should NOT be changed or addressed in this issue - Adjacent feature that might seem related but is separate ``` ## 示例 ### 好的 agent brief(bug) ```markdown ## Agent Brief **Category:** bug **Summary:** Skill description truncation drops mid-word, producing broken output **Current behavior:** When a skill description exceeds 1024 characters, it is truncated at exactly 1024 characters regardless of word boundaries. This produces descriptions that end mid-word (e.g. "Use when the user wants to confi"). **Desired behavior:** Truncation should break at the last word boundary before 1024 characters and append "..." to indicate truncation. **Key interfaces:** - The `SkillMetadata` type's `description` field: no type change needed, but the validation/processing logic that populates it needs to respect word boundaries - Any function that reads SKILL.md frontmatter and extracts the description **Acceptance criteria:** - [ ] Descriptions under 1024 chars are unchanged - [ ] Descriptions over 1024 chars are truncated at the last word boundary before 1024 chars - [ ] Truncated descriptions end with "..." - [ ] The total length including "..." does not exceed 1024 chars **Out of scope:** - Changing the 1024 char limit itself - Multi-line description support ``` ### 好的 agent brief(enhancement) ```markdown ## Agent Brief **Category:** enhancement **Summary:** Add `.out-of-scope/` directory support for tracking rejected feature requests **Current behavior:** When a feature request is rejected, the issue is closed with a `wontfix` label and a comment. There is no persistent record of the decision or reasoning. Future similar requests require the maintainer to recall or search for the prior discussion. **Desired behavior:** Rejected feature requests should be documented in `.out-of-scope/.md` files that capture the decision, reasoning, and links to all issues that requested the feature. When triaging new issues, these files should be checked for matches. **Key interfaces:** - Markdown file format in `.out-of-scope/`: each file should have a `# Concept Name` heading, a `**Decision:**` line, a `**Reason:**` line, and a `**Prior requests:**` list with issue links - The triage workflow should read all `.out-of-scope/*.md` files early and match incoming issues against them by concept similarity **Acceptance criteria:** - [ ] Closing a feature as wontfix creates/updates a file in `.out-of-scope/` - [ ] The file includes the decision, reasoning, and link to the closed issue - [ ] If a matching `.out-of-scope/` file already exists, the new issue is appended to its "Prior requests" list rather than creating a duplicate - [ ] During triage, existing `.out-of-scope/` files are checked and surfaced when a new issue matches a prior rejection **Out of scope:** - Automated matching (human confirms the match) - Reopening previously rejected features - Bug reports (only enhancement rejections go to `.out-of-scope/`) ``` ### 好的 agent brief(PR) 对 PR 而言,“Current behavior” 描述的是 diff 的状态,brief 要求 agent 完成或修复它,而不是从零构建。 ```markdown ## Agent Brief **Category:** enhancement **Summary:** Finish the contributor's `--json` output flag for `triage list` **Current behavior:** The PR adds a `--json` flag that serializes the issue list to JSON. The happy path works and the diff matches the project's command structure. Two gaps remain: errors are still printed as human text (not JSON), and the new flag has no test coverage. **Desired behavior:** With `--json`, all output (including errors) is well-formed JSON on stdout, and the command's exit codes are unchanged. The existing human-readable output is untouched when the flag is absent. **Key interfaces:** - The command's error path should emit `{ "error": string }` under `--json` instead of the plain-text error - Reuse the existing serializer the PR already added; don't introduce a second **Acceptance criteria:** - [ ] `triage list --json` emits valid JSON for both success and error cases - [ ] Exit codes match the non-JSON command - [ ] A test covers the `--json` success output and one error case - [ ] Default (non-JSON) output is byte-for-byte unchanged **Out of scope:** - Adding `--json` to any other command - Changing the JSON shape of the success payload the PR already defined ``` ### 坏的 agent brief ```markdown ## Agent Brief **Summary:** Fix the triage bug **What to do:** The triage thing is broken. Look at the main file and fix it. The function around line 150 has the issue. **Files to change:** - src/triage/handler.ts (line 150) - src/types.ts (line 42) ``` 它不好,因为: - 没有 category - 描述含糊(“the triage thing is broken”) - 引用了会过期的 file paths 和 line numbers - 没有 acceptance criteria - 没有 scope boundaries - 没有说明 current vs desired behavior