@xenonbyte/req-2-plan 0.4.4 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/README.md +170 -125
  2. package/README.zh-CN.md +154 -108
  3. package/package.json +1 -1
  4. package/tools/r2p-archive +10 -0
  5. package/tools/r2p-execute +10 -0
  6. package/tools/workflow_cli/agent_shortcuts.py +310 -26
  7. package/tools/workflow_cli/agent_templates/claude/SKILL.md +2 -1
  8. package/tools/workflow_cli/agent_templates/claude/commands/r2p-archive.md +10 -0
  9. package/tools/workflow_cli/agent_templates/claude/commands/r2p-continue.md +1 -0
  10. package/tools/workflow_cli/agent_templates/claude/commands/r2p-execute.md +122 -0
  11. package/tools/workflow_cli/agent_templates/claude/commands/r2p-reopen.md +2 -2
  12. package/tools/workflow_cli/agent_templates/codex/skills/r2p-archive/SKILL.md +14 -0
  13. package/tools/workflow_cli/agent_templates/codex/skills/r2p-continue/SKILL.md +2 -0
  14. package/tools/workflow_cli/agent_templates/codex/skills/r2p-execute/SKILL.md +123 -0
  15. package/tools/workflow_cli/agent_templates/codex/skills/r2p-reopen/SKILL.md +2 -2
  16. package/tools/workflow_cli/agent_templates/gemini/commands/r2p-archive.toml +4 -0
  17. package/tools/workflow_cli/agent_templates/gemini/commands/r2p-continue.toml +1 -1
  18. package/tools/workflow_cli/agent_templates/gemini/commands/r2p-execute.toml +4 -0
  19. package/tools/workflow_cli/agent_templates/gemini/commands/r2p-reopen.toml +1 -1
  20. package/tools/workflow_cli/artifact.py +5 -2
  21. package/tools/workflow_cli/atomic.py +50 -0
  22. package/tools/workflow_cli/cli.py +229 -31
  23. package/tools/workflow_cli/gates.py +149 -2
  24. package/tools/workflow_cli/install.py +56 -3
  25. package/tools/workflow_cli/link_expander.py +9 -25
  26. package/tools/workflow_cli/markdown.py +18 -0
  27. package/tools/workflow_cli/models.py +19 -1
  28. package/tools/workflow_cli/stage_templates.py +2 -1
  29. package/tools/workflow_cli/state.py +5 -6
  30. package/tools/workflow_cli/tier.py +1 -1
  31. package/tools/workflow_cli/version.py +1 -1
  32. package/tools/workflow_cli/workspace.py +112 -0
package/README.zh-CN.md CHANGED
@@ -6,35 +6,61 @@
6
6
  [![node](https://img.shields.io/node/v/%40xenonbyte%2Freq-2-plan.svg)](https://nodejs.org)
7
7
  [![license: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
8
8
 
9
- > 把原始需求变成一份获批、执行器中立的实现 PLAN——同一套分阶段工作流,在 Claude Code、Codex、Gemini 上一致运行。
9
+ > 把原始需求变成一份获批、执行器中立的实现 PLAN,并在 Claude Code、Codex、Gemini、opencode 上一致运行。
10
10
 
11
- `req-2-plan` 为 AI agent 平台安装并管理 `r2p` 需求到 PLAN 的工作流。该工作流是一条
12
- 分阶段、门控的流水线:需求依次经过 **requirement briefrisk discoveryDESIGN
13
- SPEC → PLAN**,每个阶段都要先过一道 quality gate 和一个人工/主控 checkpoint 才能交给
14
- 下游。产出是一份另一个 agent 或工程师无需重新决策范围就能执行的计划。
11
+ `req-2-plan` 为 AI coding agent 安装 `r2p` 工作流。它把粗略需求推进到一条分阶段、
12
+ 门控的流程中:**requirement brief**、**risk discovery**、**DESIGN**、**SPEC**、
13
+ **PLAN**。最终得到的计划有上下文、有审查记录,也能直接交给另一个 agent 或工程师执行。
15
14
 
16
- 这个 npm 包是安装器:它从一份共享源生成各平台的 agent skill 与命令,并安装进
17
- Claude Code、Codex、Gemini,让工作流在三个平台上表现一致。
15
+ 这个 npm 包是生命周期安装器。目前它支持 4 个 agent 平台:**Claude Code**、**Codex**、
16
+ **Gemini**、**opencode**。它从一份共享源生成各平台的 agent 入口,安装共享的
17
+ `r2p-*` wrapper,并维护 owned manifest,确保卸载时只移除 `r2p` 自己管理的文件。
18
+
19
+ **Contents:** [Why r2p](#why-r2p) · [Features](#features) · [Installation](#installation) · [Quick start](#quick-start) · [Workflow commands](#workflow-commands) · [Development](#development)
20
+
21
+ ## Why r2p
22
+
23
+ AI agent 执行很快,但模糊需求容易变成含糊计划、隐藏范围决策和反复返工。`r2p`
24
+ 把规划阶段显式化:
25
+
26
+ - 原始需求会作为真值来源被保留;
27
+ - 风险和未知点会在实现计划前暴露;
28
+ - DESIGN、SPEC、PLAN 都要通过结构化 quality gate;
29
+ - 必须由人选择的决定会被记录,而不是由 agent 猜;
30
+ - 执行可以从 PLAN 开始,不需要重新决定范围。
31
+
32
+ 当需求不只是单行修改、会影响重要行为,或需要在多个 agent 之间做稳定交接时,适合使用它。
18
33
 
19
34
  ## Features
20
35
 
21
- - **分阶段、门控流水线**——每个阶段交接前都通过一道 quality gate 和一个 checkpoint;不靠猜推进。
22
- - **单一生命周期 CLI**——`r2p install`、`r2p uninstall`、`r2p status`、`r2p version`、`r2p help`,只依赖 Python 标准库。
23
- - **一份源、多平台**——为 `claude`、`codex`、`gemini` 生成 skill。
24
- - **owned-only、manifest 背书的安装**——卸载只删 `r2p` 创建的文件;已存在的用户文件会被备份并保留。
25
- - **紧凑的 agent 技能**——八个 `r2p-*` wrapper 驱动日常循环。
36
+ - **分阶段 requirement-to-PLAN 工作流**:requirement brief、risk discovery、DESIGN、SPEC、PLAN。
37
+ - **Quality gate checkpoint**:每个阶段交接前都要先通过校验。
38
+ - **支持 4 个平台**:为 Claude Code(`claude`)、Codex(`codex`)、Gemini(`gemini`)、opencode(`opencode`)安装匹配入口。
39
+ - **单一生命周期 CLI**:`r2p install`、`r2p uninstall`、`r2p status`、`r2p version`、`r2p help`。
40
+ - **Manifest-backed 安装安全**:覆盖前备份已存在文件,卸载只删除受管路径。
41
+ - **Project Context Pack**:`--repo-path` 捕获真实仓库事实,用于 tier 估算和 PLAN 校验。
42
+ - **修复路径**:可重开 closed run、路由上游缺口,并关闭已修复的决策路线。
43
+ - **执行交接**:`r2p-execute` 可以把获批 PLAN 接入当前分支上的实现循环。
26
44
 
27
45
  ## Supported platforms
28
46
 
29
- | 平台 | 技能格式 |
30
- |---|---|
31
- | `claude` | 命令文件(`commands/r2p-*.md`) |
32
- | `codex` | 技能目录(`skills/r2p-*/SKILL.md`) |
33
- | `gemini` | 命令 TOML(`commands/r2p-*.toml`) |
47
+ `r2p` 当前支持 4 个平台。`--platform` 使用下表里的 platform ID。
48
+
49
+ | Agent platform | Platform ID | Installed surface |
50
+ |---|---|---|
51
+ | Claude Code | `claude` | `skills/r2p/SKILL.md` plus `commands/r2p-*.md` |
52
+ | Codex | `codex` | `skills/r2p-*/SKILL.md` |
53
+ | Gemini | `gemini` | `commands/r2p-*.toml` |
54
+ | opencode | `opencode` | `commands/r2p-*.md` |
34
55
 
35
56
  ## Installation
36
57
 
37
- 环境要求:**Node.js 18+** 与 **Python 3**(以 `python3` 或 `python` 提供)。
58
+ 环境要求:
59
+
60
+ - Node.js 18+
61
+ - Python 3,以 `python3` 或 `python` 提供
62
+
63
+ 全局安装:
38
64
 
39
65
  ```bash
40
66
  npm install -g @xenonbyte/req-2-plan
@@ -49,137 +75,157 @@ r2p help
49
75
  ```
50
76
 
51
77
  > [!NOTE]
52
- > 生命周期命令只需 Python 标准库,但日常 `r2p-*` 技能依赖 `pyyaml`。在仓库 checkout
53
- > 内用 `python3 -m pip install --user -r requirements.txt` 安装,或直接
78
+ > 生命周期命令只使用 Python 标准库。日常 workflow wrapper 使用 `pyyaml`;在 checkout
79
+ > 内可运行 `python3 -m pip install --user -r requirements.txt`,或直接运行
54
80
  > `python3 -m pip install --user "pyyaml>=6.0"`。
55
81
 
56
- `r2p install` 把各平台模板写入对应 agent home 目录、在 `~/.req-to-plan/bin/` 下写入
57
- 共享命令 wrapper,并生成 `~/.req-to-plan/install/<platform>.yaml` 清单。清单记录每个
58
- 受管路径,因此卸载只移除 `r2p` 创建的文件,并为安装前已存在的文件还原备份。
59
-
60
- ## Usage
61
-
62
- ### Quick start
63
-
64
- 先在终端用生命周期 CLI 安装平台技能并确认安装结果:
82
+ 安装全部支持的 agent 集成。不传 `--platform` 时,这就是默认行为:
65
83
 
66
84
  ```bash
67
- r2p install # 安装全部平台(默认)
68
- r2p status # 查看已安装情况
69
- ```
70
-
71
- 然后在 agent 里驱动工作流——已安装的平台技能会调用 `r2p-*` 包装器
72
- (如需在终端手动执行,先把 `~/.req-to-plan/bin` 加入 `PATH`,见下方 tip):
73
-
74
- ```text
75
- /r2p-start --repo-path . "Add rate limiting" # 需求为内联文本
76
- /r2p-start --repo-path . --file change-req.md # 需求为文档文件
77
- /r2p-continue # 逐阶段推进
85
+ r2p install
78
86
  ```
79
87
 
80
- 需求可以是内联文本,也可以用 `--file <path>` 传入文档(两者互斥)。
81
- **只要需求以某个代码仓库为上下文,就必须传 `--repo-path`**——当前项目传 `.`,
82
- 跨仓库需求传目标仓库路径;它生成的 Project Context Pack 是 tier 估算与 PLAN
83
- 文件引用校验的真值锚点。选项写在需求文本之前(如上例),这样即使自由文本
84
- 引号写错也不会吞掉选项。若 standard tier 的 PLAN gate 提示 Context Pack
85
- 缺失/不可用,直接执行 gate 打印的
86
- `PYTHONPATH=... <python> -m tools.workflow_cli context-build ...` 命令中途补建
87
- (不存在独立的 `context-build` 可执行文件)。
88
-
89
- ### Lifecycle commands
90
-
91
- 安装全部平台、单个平台,或逗号分隔的列表:
88
+ `--platform` 只安装指定平台:
92
89
 
93
90
  ```bash
94
- r2p install
95
91
  r2p install --platform claude
96
- r2p install --platform claude,codex,gemini
92
+ r2p install --platform claude,codex,gemini,opencode
97
93
  ```
98
94
 
99
- 按平台报告安装状态——已装版本、漂移(缺文件或版本不匹配)、或 manifest 无效。`status`
100
- 只读;加 `--json` 得到机器可读输出:
95
+ > [!WARNING]
96
+ > `r2p install` 会覆盖所选平台的既有 `r2p` 安装。已存在的用户文件会先备份,
97
+ > `r2p uninstall` 也只会移除 install manifest 里记录的路径。
101
98
 
102
- ```bash
103
- r2p status
104
- r2p status --json
105
- ```
99
+ ## Quick start
106
100
 
107
- 卸载单个平台、列表,或全部(省略 `--platform`):
101
+ 安装平台 skill 后,在 agent 里启动一次工作流:
108
102
 
109
- ```bash
110
- r2p uninstall --platform claude
111
- r2p uninstall --platform claude,codex,gemini
103
+ ```text
104
+ /r2p-start --repo-path . "Add rate limiting"
105
+ /r2p-continue
112
106
  ```
113
107
 
114
- > [!WARNING]
115
- > `r2p install` 直接覆盖已有安装——无需确认参数。覆盖前会先备份已存在的用户文件,
116
- > 而卸载绝不删除非 `r2p` 创建的文件。
108
+ 也可以从需求文件启动,而不是传内联文本:
117
109
 
118
- ### Workflow skills
110
+ ```text
111
+ /r2p-start --repo-path . --file change-req.md
112
+ ```
119
113
 
120
- 安装后,平台 skill 调用这些共享的 `r2p-*` wrapper——运行一次工作流的每一步各一个:
114
+ 只要需求以代码仓库为上下文,就传 `--repo-path`。当前仓库传 `.`,跨项目需求传目标仓库路径。
115
+ 这会构建 Project Context Pack,供 tier 估算和 PLAN 引用校验使用。
121
116
 
122
- | Skill | 作用 |
123
- |---|---|
124
- | `r2p-start` | 从需求启动一次新运行(文本,或用 `--file <path>` 读取文档内容)。 |
125
- | `r2p-continue` | 继续当前运行——推进到下一个停点(gate、checkpoint 或修复)。 |
126
- | `r2p-status` | 查看当前运行或全部运行,只读。 |
127
- | `r2p-switch` | 把活动运行指向另一个 `--work-id`。 |
128
- | `r2p-tier-lock` | 锁定活动运行的复杂度 tier(`--base light\|standard`)。 |
129
- | `r2p-reopen` | 从指定 `--stage` 重开一个已关闭的运行。 |
130
- | `r2p-gap-open` | 把 open run 的上游缺口路由回其 `--owner-stage`;下游 artifact 失效、需重新派生。 |
131
- | `r2p-gap-resolve` | owner 阶段重做并通过 `gate-quality` 后,关闭一个 `--route-id` 缺口路由。 |
117
+ 工作流会在需要人或 agent 动作时停下:锁定 tier、填写 artifact、修复 quality gate、
118
+ 批准 checkpoint、执行 subagent review,或解决 gap。按输出里的 `next:` 命令执行,
119
+ 然后继续运行 `r2p-continue`。
132
120
 
133
121
  > [!TIP]
134
- > 把 `~/.req-to-plan/bin` 加入 `PATH`,即可直接运行 `r2p-*` wrapper:
122
+ > 把 `~/.req-to-plan/bin` 加入 `PATH`,即可直接运行 wrapper:
135
123
  >
136
124
  > ```bash
137
125
  > export PATH="$HOME/.req-to-plan/bin:$PATH"
138
126
  > ```
139
127
 
140
- ### When to use which skill
128
+ ## Workflow commands
129
+
130
+ 安装后,面向 agent 的命令会调用 `~/.req-to-plan/bin` 下的共享 wrapper。
131
+
132
+ | Command | Purpose |
133
+ |---|---|
134
+ | `r2p-start` | 从内联需求文本或 `--file <path>` 启动新 run。 |
135
+ | `r2p-continue` | 把活动 run 推进到下一个停点或完成状态。 |
136
+ | `r2p-status` | 只读查看活动 run;加 `--all` 可查看全部 run。 |
137
+ | `r2p-switch` | 切换活动的 `--work-id`。 |
138
+ | `r2p-tier-lock` | 用 `--base light\|standard` 和可选 modifier 锁定 tier。 |
139
+ | `r2p-reopen` | 从指定阶段重开一个 closed 或 executing run,并选择新重开的 run。 |
140
+ | `r2p-gap-open` | 把 open run 的上游缺口路由回 owner stage。 |
141
+ | `r2p-gap-resolve` | 关闭一个已修复的上游缺口 route。 |
142
+ | `r2p-archive` | 把 closed run 移到 `.req-to-plan/archive/`,并取消活动路径跟踪。 |
143
+ | `r2p-execute` | 在当前分支原地执行 closed PLAN,然后归档该 run。 |
144
+
145
+ 大多数 run 只需要 `r2p-start`,然后反复 `r2p-continue`。当工作流输出这些命令,
146
+ 或你明确需要切换、修复、重开、执行、归档时,再使用对应的专用命令。
147
+
148
+ > [!IMPORTANT]
149
+ > `r2p-execute` 假设宿主 agent 能派发 subagent。它直接在当前分支工作,不会 push,
150
+ > 也不会打开 pull request。
151
+
152
+ > [!NOTE]
153
+ > 在 PLAN checkpoint 关闭 run,以及归档 run 时,`r2p` 会对该 run 的
154
+ > `.req-to-plan/<work-id>` 状态做 best-effort、path-limited commit。它不会运行
155
+ > `git add -A`,不会强制添加 ignored path,也不会 push。
141
156
 
142
- 大多数运行只需 `r2p-start`,然后反复 `r2p-continue`。其余技能针对特定情形。
157
+ ## Lifecycle commands
143
158
 
144
- **锁定 tier**——每个 run 一次,当 `r2p-continue` 停在 `tier_not_locked` 时:
159
+ 在终端里使用生命周期命令管理已安装的集成:
145
160
 
146
161
  ```bash
147
- r2p-tier-lock --work-id <id> --base standard --modifiers migration,safety --confirm
162
+ r2p install
163
+ r2p install --platform codex
164
+
165
+ r2p status
166
+ r2p status --json
167
+
168
+ r2p uninstall --platform claude
169
+ r2p uninstall
170
+
171
+ r2p version
172
+ r2p help
148
173
  ```
149
174
 
150
- `--base standard` 抬高刚性下限;`migration`、`safety`、`cross_project` 这几个 modifier
151
- 会在 DESIGN / SPEC / PLAN 检查点强制子 agent 审查。
175
+ `r2p install` `r2p uninstall` 省略 `--platform` 时,都会作用于全部支持平台。
176
+
177
+ `r2p status` 是只读命令。加 `--json` 后会输出机器可读的平台状态、已安装版本和 manifest
178
+ 问题。
179
+
180
+ ## How the workflow works
181
+
182
+ 每个 run 都保存在目标 workspace 的 `.req-to-plan/<work-id>/` 下。agent 负责语义内容;
183
+ CLI 负责状态、文件、gate 和结构化校验。
184
+
185
+ | Stage | Output |
186
+ |---|---|
187
+ | Raw requirement | 原始用户需求 |
188
+ | Requirement brief | 范围、目标、非目标和验收方向 |
189
+ | Risk discovery | 未知点、约束、依赖和风险区域 |
190
+ | DESIGN | 技术方案和 decision requests |
191
+ | SPEC | 详细行为和接口 |
192
+ | PLAN | 带 verification criteria 的有序实现任务 |
193
+
194
+ Standard tier 的 DESIGN/SPEC/PLAN 阶段可能要求 subagent review,尤其当存在
195
+ `migration`、`safety`、`cross_project` 等 tier modifier 时。如果后续阶段发现上游决策缺口,
196
+ 用 `r2p-gap-open` 路由回 owner stage,修复后再用 `r2p-gap-resolve` 关闭 route。
197
+
198
+ ## Development
152
199
 
153
- **重开已关闭的 run**——回到一个已在 PLAN 检查点关闭的运行,从更早的阶段重新开始
154
- (会派生一个带血缘的新 run):
200
+ 安装开发依赖:
155
201
 
156
202
  ```bash
157
- r2p-reopen --from <closed-id> --stage spec --reason "spec gap found"
203
+ python3 -m pip install -r requirements-dev.txt
158
204
  ```
159
205
 
160
- **回路上游缺口**——在一个**开着的** run 上,当后面的阶段发现更早的阶段拥有一个错误或
161
- 缺失的决策时。`gap-open` 把 run 退回 owner 阶段并把所有下游标记 stale;待你把 owner
162
- 重做到通过 `gate-quality`,`gap-resolve` 关闭路由,让 owner 可被重新批准、下游重新派生:
206
+ 运行测试套件:
163
207
 
164
208
  ```bash
165
- r2p-gap-open --work-id <id> --owner-stage design --required-action "fixed-window burst flaw"
166
- # 然后把 owner 阶段重做到通过 gate-quality(r2p-continue 会引导这步)
167
- r2p-gap-resolve --work-id <id> --route-id R-1
209
+ npm test
210
+ # or, when using the checked-in virtual environment:
211
+ npm run test:local
168
212
  ```
169
213
 
170
- > [!NOTE]
171
- > reopen 针对**已关闭**的 run;gap 路由针对**开着**的 run。`r2p-continue` 会用
172
- > `needs_repair` 和 `needs_gap_resolve` 停点带你走完这两种修复流程。
214
+ 常用本地检查:
173
215
 
174
- > [!NOTE]
175
- > **人工决策点(standard DESIGN)。** 当 standard tier 的 DESIGN 涉及必须由人
176
- > 决定的选择(引入新依赖、迁移策略、API 兼容性)时,agent 会在 `## Decision
177
- > Requests` 章节写入 `### DECISION-NNN` block(含 `Question:`/`Options:`/
178
- > `Recommended:`)并标记 `Status: pending` ——存在 pending 决策时
179
- > `gate-quality` 会失败,直到人选定方案、block 改为 `Status: selected`
180
- > 并补上 `Selected:` 与 `Rationale:` 行。
181
- > 无需人工决策时,该章节须恰好写 `none`。
216
+ ```bash
217
+ node bin/r2p.js version
218
+ node bin/r2p.js help
219
+ .venv/bin/python -m tools.workflow_cli --help
220
+ .venv/bin/python -m tools.workflow_cli.agent_shortcuts --help
221
+ ```
182
222
 
183
- ## License
223
+ 项目结构:
184
224
 
185
- [MIT](./LICENSE) © xenonbyte
225
+ | Path | Purpose |
226
+ |---|---|
227
+ | `bin/r2p.js` | 调用 Python 生命周期 CLI 的 npm binary |
228
+ | `tools/r2p-*` | 已安装 workflow wrapper 的源脚本 |
229
+ | `tools/workflow_cli/` | 状态机、gate、template、installer 和命令路由 |
230
+ | `tools/workflow_cli/agent_templates/` | 面向 Claude Code、Codex、Gemini 的生成入口 |
231
+ | `tests/` | 覆盖 CLI 行为、状态、gate、安装安全、打包和 README 一致性的回归测试 |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xenonbyte/req-2-plan",
3
- "version": "0.4.4",
3
+ "version": "0.5.0",
4
4
  "description": "Requirement-to-PLAN workflow CLI and agent integration installer.",
5
5
  "bin": {
6
6
  "r2p": "bin/r2p.js"
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4
+ REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
5
+ export PYTHONPATH="$REPO_ROOT${PYTHONPATH:+:$PYTHONPATH}"
6
+ if command -v python3 >/dev/null 2>&1; then
7
+ exec python3 -m tools.workflow_cli.agent_shortcuts archive "$@"
8
+ else
9
+ exec python -m tools.workflow_cli.agent_shortcuts archive "$@"
10
+ fi
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4
+ REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
5
+ export PYTHONPATH="$REPO_ROOT${PYTHONPATH:+:$PYTHONPATH}"
6
+ if command -v python3 >/dev/null 2>&1; then
7
+ exec python3 -m tools.workflow_cli.agent_shortcuts execute "$@"
8
+ else
9
+ exec python -m tools.workflow_cli.agent_shortcuts execute "$@"
10
+ fi