stage-chapters
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesestage-chapters
stage-chapters
Generates a Stage chapter run for the current local git branch and opens it in a browser. Uses to compute the diff, then generates chapters and a prologue, and hands the result to to launch the SPA.
stagereview prepstagereview show为当前本地Git分支生成Stage章节运行实例,并在浏览器中打开。使用计算差异,然后生成章节和序言,再将结果交给以启动SPA。
stagereview prepstagereview showPrerequisites
前置条件
Run these checks before any other work. If either fails, stop with the error message — do not continue.
-
is installed. Run
stagereview. If it exits non-zero, instruct the user:which stagereviewstagereview is not installed. Run: npm install -g stagereview Then retry /stage-chapters.Stop. -
The current directory is a git repo. Run. If it does not print
git rev-parse --is-inside-work-tree, stop with:true/stage-chapters must be run inside a git repository.
在开展任何工作前先进行以下检查。如果任一检查失败,输出错误信息后停止操作——不要继续执行。
-
已安装。运行
stagereview。如果返回非零退出码,请告知用户:which stagereviewstagereview is not installed. Run: npm install -g stagereview Then retry /stage-chapters.停止操作。 -
当前目录是Git仓库。运行。如果未输出
git rev-parse --is-inside-work-tree,输出以下信息后停止:true/stage-chapters must be run inside a git repository.
Step 1 — Run prep
步骤1 — 运行prep
bash
PREP_FILE=$(stagereview prep)stagereview prepIf the user specifies a base branch (e.g., "generate chapters against "), pass to both and :
feature-a--base <ref>prepshowbash
PREP_FILE=$(stagereview prep --base feature-a)bash
PREP_FILE=$(stagereview prep)stagereview prep如果用户指定了基准分支(例如“基于生成章节”),请在和命令中都传入参数:
feature-aprepshow--base <ref>bash
PREP_FILE=$(stagereview prep --base feature-a)... later ...
... later ...
stagereview show --base feature-a "$AGENT_OUTPUT"
If `prep` exits non-zero, relay its stderr to the user and stop.
**Do not modify files in the working tree between running `prep` and running `show`.** Both commands independently snapshot the git state. If the diff changes between them, `show` will reject the chapters with a hunk coverage error because the hunks no longer match.stagereview show --base feature-a "$AGENT_OUTPUT"
如果`prep`返回非零退出码,将其标准错误信息转发给用户并停止操作。
**在运行`prep`和`show`之间不要修改工作区中的文件**。两个命令会独立快照Git状态。如果期间差异发生变化,`show`会因代码块覆盖错误而拒绝章节,因为代码块不再匹配。Step 2 — Read prep output
步骤2 — 读取prep输出
Read via the Read tool (or equivalent). For large diffs, use the Read tool's and parameters to read in chunks.
$PREP_FILEoffsetlimitThe file has two sections separated by headers:
- —
=== COMMIT MESSAGES ===output for prologue context.git log --oneline - — formatted diff hunks with line numbers. Each hunk looks like:
=== HUNKS ===
=== File: src/app.ts (modified) | filePath: "src/app.ts", oldStart: 1 ===
=== Hunk @1: @@ -1,5 +1,6 @@ ===
1 1 | const a = 1;
2 |-const b = 2;
2 |+const b = 3;
3 |+const c = 4;
3 4 | const d = 5;The two number columns are the old line number (left) and new line number (right). A blank column means the line doesn't exist on that side — additions have no old line number, deletions have no new line number. These numbers are used directly for in key changes (see Step 3d).
lineRefscommits.txtgit log --oneline通过Read工具(或等效工具)读取。对于大型差异,使用Read工具的和参数分块读取。
$PREP_FILEoffsetlimit该文件包含两个由标题分隔的部分:
- — 用于序言上下文的
=== COMMIT MESSAGES ===输出。git log --oneline - — 带行号的格式化差异代码块。每个代码块格式如下:
=== HUNKS ===
=== File: src/app.ts (modified) | filePath: "src/app.ts", oldStart: 1 ===
=== Hunk @1: @@ -1,5 +1,6 @@ ===
1 1 | const a = 1;
2 |-const b = 2;
2 |+const b = 3;
3 |+const c = 4;
3 4 | const d = 5;两列数字分别是旧行号(左侧)和新行号(右侧)。空白列表示该行在对应版本中不存在——新增行没有旧行号,删除行没有新行号。这些数字直接用于关键变更中的(见步骤3d)。
lineRefscommits.txtgit log --onelineStep 3 — Cluster + narrate
步骤3 — 聚类 + 叙述
Using the hunks from , produce a array. Each chapter groups related hunks into a coherent story beat, narrates them for a reviewer unfamiliar with this part of the codebase, and flags judgment calls that need human input.
hunks.txtchapters使用中的代码块,生成一个数组。每个章节将相关代码块分组为连贯的故事片段,为不熟悉该代码库的评审者进行叙述,并标记需要人工介入的判断点。
hunks.txtchapters3a — Clustering rules
3a — 聚类规则
Group hunks by causal relationship — changes that set up or enable later changes belong together.
- Spanning multiple files is expected and correct (e.g., schema + API + UI for one feature = one chapter).
- Moves and refactors are a single chapter — when code is removed from one file and added to another (or a file is deleted and a similar one created), group the deletion and addition hunks together as one "Move/Refactor" chapter, not separate "Remove" and "Add" chapters.
- Split only when changes are truly independent — a reviewer could understand one without knowing about the other.
- Tests belong with their implementation chapter.
- Config/dependency changes can be their own chapter if unrelated to a feature chapter.
Chapter ordering:
- Foundation first: types, interfaces, schemas, utilities that others depend on
- Core logic next: main implementation
- Integration last: wiring, configuration, tests
Consider symbol dependencies between chapters — a chapter that introduces a type another chapter uses must come first.
Hunk ordering within a chapter:
- Group all hunks from the same file together — do not interleave hunks from different files.
- Within the same file, list hunks in ascending order (matching file layout).
oldStart
按因果关系分组代码块——为后续变更做铺垫或提供支持的变更应归为一组。
- 跨多个文件是正常且正确的(例如,一个功能的Schema + API + UI = 一个章节)。
- 移动和重构属于单个章节——当代码从一个文件移除并添加到另一个文件(或删除一个文件并创建类似文件)时,将删除和添加的代码块归为一个“移动/重构”章节,而非分开的“移除”和“添加”章节。
- 仅当变更完全独立时才拆分——评审者无需了解另一部分即可理解当前部分。
- 测试应与其实现章节放在一起。
- 如果配置/依赖变更与功能章节无关,可以单独作为一个章节。
章节排序:
- 基础优先:类型、接口、Schema、其他模块依赖的工具类
- 核心逻辑次之:主要实现代码
- 集成最后:连接逻辑、配置、测试
考虑章节之间的符号依赖——引入其他章节使用的类型的章节必须放在前面。
章节内代码块排序:
- 将同一文件的所有代码块放在一起——不要交错不同文件的代码块。
- 在同一文件内,按升序排列代码块(与文件布局匹配)。
oldStart
3b — Self-validation rules
3b — 自验证规则
Every hunk in the formatted diff must appear in exactly one chapter. No hunk may be omitted and no hunk may appear in more than one chapter.
Each hunk header in the prep output has the format:
=== File: <path> (<status>) | filePath: "<path>", oldStart: <N> ===Use the and values from these headers to build .
filePatholdStarthunkRefsstagereview show格式化差异中的每个代码块必须恰好出现在一个章节中。不得遗漏任何代码块,也不得让代码块出现在多个章节中。
prep输出中的每个代码块标题格式如下:
=== File: <path> (<status>) | filePath: "<path>", oldStart: <N> ===使用这些标题中的和值构建。
filePatholdStarthunkRefsstagereview show3c — Narration rules
3c — 叙述规则
Write each chapter as a story beat — a meaningful step that moves the branch forward, not a summary of files changed.
- Title: action-oriented verb phrase, max 8 words (e.g., "Wire org ID through the API layer"). No filler like "Add support for".
- Summary: 2–3 sentences covering what this chapter enables and why. Lead with impact, then connect to the broader purpose. When a chapter builds on a previous one, open with that causal link explicitly (e.g., "Now that X is in place…").
- Keep paragraphs short. Prefer splitting distinct points into separate short paragraphs (separated by a blank line) rather than writing one long dense paragraph. Each paragraph should convey a single idea.
- Markdown allowed: for emphasis,
**bold**for nuance,*italics*for inline code references, and fenced code blocks when a short snippet (≤ 6 lines) helps illustrate the change.`backticks`
将每个章节写成一个故事片段——推动分支前进的有意义步骤,而非变更文件的摘要。
- 标题: 面向动作的动词短语,最多8个单词(例如“将组织ID接入API层”)。不要使用“添加对...的支持”之类的冗余表述。
- 摘要: 2-3句话,说明本章实现的功能及其原因。先讲影响,再关联更广泛的目标。当本章基于前一章构建时,明确以因果关系开头(例如“既然X已就绪...”)。
- 段落要简短。将不同观点拆分为单独的短段落(用空白行分隔),而非写一个冗长的密集段落。每个段落应传达一个单一观点。
- 允许使用Markdown:用于强调,
**粗体**用于细微差别,*斜体*用于内联代码引用,当短代码片段(≤6行)有助于说明变更时使用围栏代码块。`反引号`
3d — Key change rules
3d — 关键变更规则
Key changes are judgment calls only a human reviewer can make — things that require product context, team conventions, or knowledge of the author's intent. Linters, type checkers, and code-review bots already cover correctness and style; skip anything they can catch. Ignore auto-generated files.
Return an empty array when nothing needs human input — do not invent items to fill the list. When a chapter is a straightforward rename, type fix, or mechanical refactor with no judgment calls, should be .
keyChanges[]Frame each item as a question.
Each key change includes : one line range per distinct spot the question depends on. Most questions touch a single location, so use one range; only add more when the judgment genuinely spans related code in different places.
lineRefsReading line numbers from : Each diff line shows two number columns — old (left) and new (right). Use these numbers directly:
hunks.txt- For — use the old (left) column number as
side: "deletions"/startLine.endLine - For — use the new (right) column number as
side: "additions"/startLine.endLine - Do not count lines yourself — read the numbers from the formatted output.
Keep ranges tight — point to the specific lines the question is about, not the entire hunk. and must both be positive integers with .
startLineendLineendLine >= startLineGood examples:
- "Should reset when the user switches orgs?"
retryCount - "Is a 60-minute session timeout appropriate for this user base, or would 30 minutes be safer?"
- "Does this new index cover the query patterns the team actually uses in production?"
Bad examples:
- "Check that the auth logic is correct." — vague, verifiable by reading the code
- "The function now handles errors." — changelog item, not a question
- "Make sure the tests pass." — CI catches this, not a human judgment call
关键变更是只有人工评审者才能做出的判断——需要产品上下文、团队约定或了解作者意图的内容。代码检查器、类型检查器和代码评审机器人已经覆盖了正确性和风格;跳过它们可以捕获的内容。忽略自动生成的文件。
当没有需要人工介入的内容时返回空数组——不要为了填充列表而编造条目。当章节是简单的重命名、类型修复或无判断点的机械重构时,应为。
keyChanges[]将每个条目表述为问题。
每个关键变更包含:每个问题对应的一个或多个行范围。大多数问题只涉及一个位置,因此使用一个范围;只有当判断真正涉及不同位置的相关代码时才添加更多范围。
lineRefs从读取行号: 每个差异行显示两列数字——旧行号(左侧)和新行号(右侧)。直接使用这些数字:
hunks.txt- 对于——使用旧(左侧)列号作为
side: "deletions"/startLine。endLine - 对于——使用新(右侧)列号作为
side: "additions"/startLine。endLine - 不要自行计数行号——从格式化输出中读取数字。
范围要精确——指向问题涉及的具体行,而非整个代码块。和必须都是正整数,且。
startLineendLineendLine >= startLine好例子:
- “当用户切换组织时,是否应该重置?”
retryCount - “60分钟会话超时对该用户群体是否合适,还是30分钟更安全?”
- “这个新索引是否覆盖了团队在生产环境中实际使用的查询模式?”
坏例子:
- “检查认证逻辑是否正确。”——模糊,可通过阅读代码验证
- “函数现在可以处理错误。”——变更日志条目,而非问题
- “确保测试通过。”——CI会捕获此问题,无需人工判断
3e — Output format
3e — 输出格式
Produce an array of chapter objects. Each chapter:
jsonc
{
"id": "chapter-1", // unique within the run, e.g. "chapter-1", "chapter-2", …
"order": 1, // positive integer, 1-indexed
"title": "Short imperative title",
"summary": "Why this chapter matters to the reviewer.",
"hunkRefs": [
// one entry per hunk in the chapter
{ "filePath": "path/to/file.ts", "oldStart": 42 }
],
"keyChanges": [
// zero or more judgment-call questions
{
"content": "A judgment-call question for the reviewer.",
"lineRefs": [
{
"filePath": "path/to/file.ts",
"side": "additions",
"startLine": 50,
"endLine": 55
}
]
}
]
}- Do not invent — only use
hunkRefstuples that actually appear in the formatted hunks.(filePath, oldStart) - must have at least one entry per key change.
keyChanges[].lineRefs
生成章节对象数组。每个章节:
jsonc
{
"id": "chapter-1", // 本次运行内唯一,例如 "chapter-1", "chapter-2", …
"order": 1, // 正整数,从1开始索引
"title": "简短的祈使句标题",
"summary": "本章对评审者的重要性。",
"hunkRefs": [
// 本章中的每个代码块对应一个条目
{ "filePath": "path/to/file.ts", "oldStart": 42 }
],
"keyChanges": [
// 零个或多个判断性问题
{
"content": "给评审者的判断性问题。",
"lineRefs": [
{
"filePath": "path/to/file.ts",
"side": "additions",
"startLine": 50,
"endLine": 55
}
]
}
]
}- 不要编造——仅使用格式化代码块中实际存在的
hunkRefs元组。(filePath, oldStart) - 每个关键变更至少包含一个条目。
keyChanges[].lineRefs
Step 4 — Generate prologue
步骤4 — 生成序言
After building the chapters, generate a prologue — a high-level overview of the entire change. The prologue helps reviewers orient themselves before diving into individual chapters.
Use from the prep output for context.
commits.txtUsing the diff, chapters, and commit messages, produce a object with the following fields:
prologue构建章节后,生成序言——整个变更的高层概述。序言帮助评审者在深入单个章节前了解整体情况。
使用prep输出中的获取上下文。
commits.txt利用差异、章节和提交信息,生成包含以下字段的对象:
prologuemotivation (string or null)
motivation(字符串或null)
One sentence a non-engineer would understand. What was broken, annoying, or missing — from a person's perspective. If the commit messages are generic and the diff doesn't make the motivation obvious, use .
nullGood: "Dashboards would break during deploys, so people had to keep refreshing until things came back."
Bad: "The API client had no retry logic for 503 errors." (too technical — no one outside the team knows what that means)
一句非技术人员能理解的话。从用户角度看,什么是破损的、令人烦恼的或缺失的。如果提交信息通用且差异无法明确动机,使用。
null好例子: “部署期间仪表板会崩溃,因此人们必须不断刷新直到恢复正常。”
坏例子: “API客户端没有针对503错误的重试逻辑。”——过于技术化,团队外的人不知道这意味着什么
outcome (string or null)
outcome(字符串或null)
One sentence a non-engineer would understand. What's better now. Same null rule as motivation.
Good: "Dashboards stay up during deploys now."
Bad: "Added exponential backoff with a base delay of 100ms." (implementation detail)
一句非技术人员能理解的话。现在有什么改善。与motivation的null规则相同。
好例子: “现在部署期间仪表板保持可用。”
坏例子: “添加了基础延迟为100ms的指数退避机制。”——实现细节
keyChanges (array of 2–5 objects)
keyChanges(2-5个对象的数组)
Each object has:
- : 6–10 words describing what's different now. Outcome-focused, not action-focused.
summary - : Capitalized sentence, 10–15 words of additional context.
description
Good: ,
Bad: (action-focused — describe what changed, not what you did)
summary: "Audit runs are now tracked in a database"description: "Uses new Drizzle ORM schema with full history retention"summary: "Adds Drizzle ORM layer"每个对象包含:
- : 6-10个单词,描述现在的不同之处。以结果为导向,而非动作导向。
summary - : 首字母大写的句子,10-15个单词的额外上下文。
description
好例子: ,
坏例子: ——动作导向,描述变更内容而非你做了什么
summary: "审计运行现在在数据库中跟踪"description: "使用具有完整历史保留功能的新Drizzle ORM Schema"summary: "添加Drizzle ORM层"focusAreas (array of 1–5 objects)
focusAreas(1-5个对象的数组)
Always provide at least 1 focus area. Even clean changes have spots worth a reviewer's attention.
Each object has:
- : one of
type,security,breaking-change,high-complexity,data-integrity,new-pattern,architecture,performancetesting-gap - : one of
severity,critical,high(for problems) ormedium(for points of interest)info - : 3–5 word noun phrase (e.g., "Unvalidated user input")
title - : WHY this was flagged + a declarative action for the reviewer. Use "confirm", "verify", or "check" to give the reviewer a specific task.
description - : array of file paths where this applies
locations
Good:
Bad: (no action, vague)
type: "security", severity: "high", title: "Unvalidated user input", description: "User-provided ID passed directly to database query — confirm input is validated and parameterized"description: "Worth understanding"始终至少提供1个重点领域。即使是清晰的变更也有值得评审者关注的地方。
每个对象包含:
- : 以下之一:
type,security,breaking-change,high-complexity,data-integrity,new-pattern,architecture,performancetesting-gap - : 以下之一:
severity,critical,high(针对问题)或medium(针对关注点)info - : 3-5个单词的名词短语(例如“未验证的用户输入”)
title - : 标记此内容的原因 + 给评审者的明确操作。使用“确认”、“验证”或“检查”给评审者具体任务。
description - : 适用此内容的文件路径数组
locations
好例子:
坏例子: ——无操作,模糊
type: "security", severity: "high", title: "未验证的用户输入", description: "用户提供的ID直接传递给数据库查询——确认输入已验证且参数化"description: "值得理解"complexity
complexity
Object with:
- : one of
level,low,medium,highvery-high - : brief explanation (e.g., "New DB schema plus multiple service changes")
reasoning
包含以下字段的对象:
- : 以下之一:
level,low,medium,highvery-high - : 简短解释(例如“新数据库Schema加上多个服务变更”)
reasoning
Style
风格
Talk like a coworker, not a changelog. No jargon, no filler phrases, no "this change introduces/implements/adds". Just say what happened and why it matters.
像同事一样交流,而非变更日志。不要使用行话、冗余短语,不要说“此变更引入/实现/添加了”。只需说明发生了什么以及为什么重要。
Step 5 — Write agent output
步骤5 — 写入Agent输出
Compute a unique temp path and write the JSON via a bash heredoc:
bash
AGENT_OUTPUT=$(mktemp "${TMPDIR:-/tmp}/stage-agent-output.XXXXXX")
cat > "$AGENT_OUTPUT" << 'AGENT_EOF'
{
"chapters": [ ... ],
"prologue": { ... }
}
AGENT_EOFThe trailing (with no suffix after) is required by macOS BSD . Using with a heredoc avoids tool-specific file-writing issues.
XXXXXXmktempcatField rules:
| Field | Constraint |
|---|---|
| Non-empty, unique within the run |
| Positive integer (1-indexed) |
| Non-negative integer — the pre-image start line from the |
| Array with at least one entry |
| |
| Positive integers; |
| Optional object; omit entirely if not desired |
| String or |
| String or |
| Array of 2–5 objects with |
| Array of 1–5 objects |
| One of: |
| One of: |
| One of: |
计算唯一的临时路径,并通过bash heredoc写入JSON:
bash
AGENT_OUTPUT=$(mktemp "${TMPDIR:-/tmp}/stage-agent-output.XXXXXX")
cat > "$AGENT_OUTPUT" << 'AGENT_EOF'
{
"chapters": [ ... ],
"prologue": { ... }
}
AGENT_EOF末尾的(无后缀)是macOS BSD 要求的。使用和heredoc避免工具特定的文件写入问题。
XXXXXXmktempcat字段规则:
| 字段 | 约束 |
|---|---|
| 非空,本次运行内唯一 |
| 正整数(从1开始索引) |
| 非负整数——格式化代码块标题中 |
| 至少包含一个条目的数组 |
| |
| 正整数; |
| 可选对象;如果不需要可完全省略 |
| 字符串或 |
| 字符串或 |
| 包含2-5个带 |
| 包含1-5个对象的数组 |
| 以下之一: |
| 以下之一: |
| 以下之一: |
Step 6 — Display generated chapters
步骤6 — 显示生成的章节
Hand the file to :
stagereviewbash
stagereview show "$AGENT_OUTPUT"stagereview showThe command blocks until the user presses Ctrl+C. If your harness requires non-blocking execution, run it in the background (e.g., in Claude Code). Invoke it as the final command in the workflow.
run_in_background将文件交给:
stagereviewbash
stagereview show "$AGENT_OUTPUT"stagereview show该命令会阻塞直到用户按下Ctrl+C。如果你的执行环境需要非阻塞运行,请在后台执行(例如Claude Code中的)。将其作为工作流中的最后一个命令调用。
run_in_background