@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.md CHANGED
@@ -6,38 +6,66 @@ English | [简体中文](README.zh-CN.md)
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
- > Turn a raw requirement into an approved, executor-neutral implementation PLAN — the same staged workflow across Claude Code, Codex, and Gemini.
9
+ > Turn a raw requirement into an approved, executor-neutral implementation PLAN across Claude Code, Codex, Gemini, and opencode.
10
10
 
11
- `req-2-plan` installs and manages the `r2p` requirement-to-PLAN workflow for AI
12
- agent platforms. The workflow is a staged, gated pipeline: a requirement moves
13
- through **requirement brief risk discovery DESIGN SPEC PLAN**, and each
14
- stage must clear a quality gate and a human/main checkpoint before it hands off.
15
- The result is a plan another agent or engineer can execute without re-deciding
16
- scope.
11
+ `req-2-plan` installs the `r2p` workflow for AI coding agents. It takes a rough
12
+ requirement through a staged, gated process - **requirement brief**, **risk
13
+ discovery**, **DESIGN**, **SPEC**, and **PLAN** - so the final plan is grounded,
14
+ reviewed, and ready for another agent or engineer to execute.
17
15
 
18
- The npm package is an installer. From one shared source it generates per-platform
19
- agent skills and commands and installs them into Claude Code, Codex, and Gemini,
20
- so the workflow behaves identically on all three.
16
+ The npm package is the lifecycle installer. It currently supports four agent
17
+ platforms - **Claude Code**, **Codex**, **Gemini**, and **opencode**. From one
18
+ shared source it generates platform-specific agent surfaces, installs the shared
19
+ `r2p-*` wrappers, and keeps an owned manifest so uninstall only removes files
20
+ managed by `r2p`.
21
+
22
+ **Contents:** [Why r2p](#why-r2p) · [Features](#features) · [Installation](#installation) · [Quick start](#quick-start) · [Workflow commands](#workflow-commands) · [Development](#development)
23
+
24
+ ## Why r2p
25
+
26
+ AI agents are fast at implementation, but weak requirements tend to leak into
27
+ ambiguous plans, hidden scope choices, and repeated rework. `r2p` makes the
28
+ planning phase explicit:
29
+
30
+ - the requirement is preserved as the source of truth;
31
+ - risks and unknowns are surfaced before implementation planning;
32
+ - DESIGN, SPEC, and PLAN each pass structural quality gates;
33
+ - human decisions are recorded instead of guessed;
34
+ - execution can start from a PLAN without re-deciding scope.
35
+
36
+ Use it when the requirement is more than a one-line edit, when a change touches
37
+ important behavior, or when you want a durable handoff between agents.
21
38
 
22
39
  ## Features
23
40
 
24
- - **Staged, gated pipeline** every stage clears a quality gate and a checkpoint before handoff; nothing advances on a guess.
25
- - **One lifecycle CLI** `r2p install`, `r2p uninstall`, `r2p status`, `r2p version`, `r2p help`, using only the Python standard library.
26
- - **Multi-platform from one source** generates skills for `claude`, `codex`, and `gemini`.
27
- - **Owned-only, manifest-backed install** uninstall removes only files `r2p` created; pre-existing user files are backed up and preserved.
28
- - **Compact agent skills** eight `r2p-*` wrappers drive the daily loop.
41
+ - **Staged requirement-to-PLAN workflow**: requirement brief, risk discovery, DESIGN, SPEC, and PLAN.
42
+ - **Quality gates and checkpoints**: each stage must clear validation before handoff.
43
+ - **Four supported platforms**: installs matching surfaces for Claude Code (`claude`), Codex (`codex`), Gemini (`gemini`), and opencode (`opencode`).
44
+ - **One lifecycle CLI**: `r2p install`, `r2p uninstall`, `r2p status`, `r2p version`, and `r2p help`.
45
+ - **Manifest-backed install safety**: pre-existing files are backed up, and uninstall removes only managed paths.
46
+ - **Project Context Pack**: `--repo-path` captures real repository facts for tiering and PLAN checks.
47
+ - **Repair paths**: reopen closed runs, route upstream gaps, and resolve repaired decisions.
48
+ - **Execution handoff**: `r2p-execute` can drive an approved PLAN through an in-place implementation loop.
29
49
 
30
50
  ## Supported platforms
31
51
 
32
- | Platform | Skill format |
33
- |---|---|
34
- | `claude` | Command files (`commands/r2p-*.md`) |
35
- | `codex` | Skill directories (`skills/r2p-*/SKILL.md`) |
36
- | `gemini` | Command TOML (`commands/r2p-*.toml`) |
52
+ `r2p` currently supports 4 platforms. Use the platform ID with `--platform`.
53
+
54
+ | Agent platform | Platform ID | Installed surface |
55
+ |---|---|---|
56
+ | Claude Code | `claude` | `skills/r2p/SKILL.md` plus `commands/r2p-*.md` |
57
+ | Codex | `codex` | `skills/r2p-*/SKILL.md` |
58
+ | Gemini | `gemini` | `commands/r2p-*.toml` |
59
+ | opencode | `opencode` | `commands/r2p-*.md` |
37
60
 
38
61
  ## Installation
39
62
 
40
- Requirements: **Node.js 18+** and **Python 3** (available as `python3` or `python`).
63
+ Requirements:
64
+
65
+ - Node.js 18+
66
+ - Python 3 as `python3` or `python`
67
+
68
+ Install the package globally:
41
69
 
42
70
  ```bash
43
71
  npm install -g @xenonbyte/req-2-plan
@@ -52,152 +80,169 @@ r2p help
52
80
  ```
53
81
 
54
82
  > [!NOTE]
55
- > The lifecycle commands need only the Python standard library, but the daily
56
- > `r2p-*` skills depend on `pyyaml`. Install it from a checkout with
83
+ > Lifecycle commands use only the Python standard library. Daily workflow
84
+ > wrappers use `pyyaml`; from a checkout, install it with
57
85
  > `python3 -m pip install --user -r requirements.txt`, or directly with
58
86
  > `python3 -m pip install --user "pyyaml>=6.0"`.
59
87
 
60
- `r2p install` writes platform templates into each agent's home directory, shared
61
- command wrappers under `~/.req-to-plan/bin/`, and a manifest at
62
- `~/.req-to-plan/install/<platform>.yaml`. The manifest records every managed path
63
- so uninstall removes only files `r2p` created and restores backups for files that
64
- existed beforehand.
88
+ Install all supported agent integrations. This is the default when `--platform`
89
+ is omitted:
65
90
 
66
- ## Usage
67
-
68
- ### Quick start
91
+ ```bash
92
+ r2p install
93
+ ```
69
94
 
70
- Install the platform skills, then check what landed (terminal, lifecycle CLI):
95
+ Install only selected platforms with `--platform`:
71
96
 
72
97
  ```bash
73
- r2p install # install all platforms (default)
74
- r2p status # see what is installed
98
+ r2p install --platform claude
99
+ r2p install --platform claude,codex,gemini,opencode
75
100
  ```
76
101
 
77
- Then drive the workflow from your agent — the installed skills call the `r2p-*`
78
- wrappers (to run them in a terminal instead, add `~/.req-to-plan/bin` to `PATH`,
79
- see the tip below):
102
+ > [!WARNING]
103
+ > `r2p install` overwrites an existing `r2p` install for the selected platform(s).
104
+ > Existing user files are backed up first, and `r2p uninstall` removes only paths
105
+ > recorded in the install manifest.
106
+
107
+ ## Quick start
108
+
109
+ Install the platform skills, then start a workflow from your agent:
80
110
 
81
111
  ```text
82
- /r2p-start --repo-path . "Add rate limiting" # requirement as inline text
83
- /r2p-start --repo-path . --file change-req.md # requirement as a document
84
- /r2p-continue # advance it stage by stage
112
+ /r2p-start --repo-path . "Add rate limiting"
113
+ /r2p-continue
85
114
  ```
86
115
 
87
- A requirement can be inline text or a document passed with `--file <path>`
88
- (the two are mutually exclusive). **Whenever a code repository is the
89
- requirement's context, pass `--repo-path`** — `.` for the current project,
90
- the target repo's path for cross-repo work; it generates the Project Context
91
- Pack that grounds tier estimation and PLAN file-reference checks. Keep options
92
- before the requirement text (as above) so a quoting slip in free-form text can
93
- never swallow an option. If a standard-tier PLAN gate later reports a missing
94
- or unusable Context Pack, build it mid-run with
95
- the `PYTHONPATH=... <python> -m tools.workflow_cli context-build ...` command printed
96
- by the gate (there is no standalone `context-build` executable).
116
+ Start from a requirement file instead of inline text:
97
117
 
98
- ### Lifecycle commands
118
+ ```text
119
+ /r2p-start --repo-path . --file change-req.md
120
+ ```
99
121
 
100
- Install all platforms, one platform, or a comma-separated list:
122
+ For repositories used as requirement context, pass `--repo-path`. Use `.` for the
123
+ current repository or a path to the target repository for cross-project work.
124
+ This builds the Project Context Pack used by tier estimation and PLAN reference
125
+ checks.
101
126
 
102
- ```bash
103
- r2p install
104
- r2p install --platform claude
105
- r2p install --platform claude,codex,gemini
106
- ```
127
+ The workflow stops whenever it needs a human or agent action: tier lock,
128
+ artifact content, quality-gate repair, checkpoint approval, subagent review, or
129
+ gap resolution. Run the printed `next:` command exactly, then resume with
130
+ `r2p-continue`.
131
+
132
+ > [!TIP]
133
+ > Add `~/.req-to-plan/bin` to your `PATH` to run the wrappers directly:
134
+ >
135
+ > ```bash
136
+ > export PATH="$HOME/.req-to-plan/bin:$PATH"
137
+ > ```
138
+
139
+ ## Workflow commands
140
+
141
+ After installation, the agent-facing commands call shared wrappers under
142
+ `~/.req-to-plan/bin`.
143
+
144
+ | Command | Purpose |
145
+ |---|---|
146
+ | `r2p-start` | Start a new run from inline requirement text or `--file <path>`. |
147
+ | `r2p-continue` | Advance the active run to the next stop or completed state. |
148
+ | `r2p-status` | Inspect the active run, or all runs with `--all`, without changing state. |
149
+ | `r2p-switch` | Select a different active `--work-id`. |
150
+ | `r2p-tier-lock` | Lock the tier with `--base light\|standard` and optional modifiers. |
151
+ | `r2p-reopen` | Reopen a closed or executing run from a specific stage and select the reopened run. |
152
+ | `r2p-gap-open` | Route an upstream gap on an open run back to the owner stage. |
153
+ | `r2p-gap-resolve` | Close a repaired upstream-gap route. |
154
+ | `r2p-archive` | Move a closed run under `.req-to-plan/archive/` and untrack its active path. |
155
+ | `r2p-execute` | Execute a closed PLAN in place on the current branch, then archive the run. |
156
+
157
+ Most runs only need `r2p-start` and repeated `r2p-continue`. Use the specialized
158
+ commands when the workflow prints them or when you intentionally need to switch,
159
+ repair, reopen, execute, or archive a run.
160
+
161
+ > [!IMPORTANT]
162
+ > `r2p-execute` assumes the host agent can dispatch subagents. It works on the
163
+ > current branch and does not push or open pull requests.
164
+
165
+ > [!NOTE]
166
+ > Closing a run at the PLAN checkpoint and archiving a run perform best-effort,
167
+ > path-limited commits for that run's `.req-to-plan/<work-id>` state. They never
168
+ > run `git add -A`, never force-add ignored paths, and never push.
107
169
 
108
- Report install status per platform — installed version, drift (missing files or
109
- version mismatch), or an invalid manifest. `status` is read-only; add `--json`
110
- for machine-readable output:
170
+ ## Lifecycle commands
171
+
172
+ Use lifecycle commands from a terminal to manage installed integrations:
111
173
 
112
174
  ```bash
175
+ r2p install
176
+ r2p install --platform codex
177
+
113
178
  r2p status
114
179
  r2p status --json
115
- ```
116
180
 
117
- Uninstall one platform, a list, or all (omit `--platform`):
118
-
119
- ```bash
120
181
  r2p uninstall --platform claude
121
- r2p uninstall --platform claude,codex,gemini
182
+ r2p uninstall
183
+
184
+ r2p version
185
+ r2p help
122
186
  ```
123
187
 
124
- > [!WARNING]
125
- > `r2p install` overwrites an existing install — no confirmation flag is needed.
126
- > Pre-existing user files are backed up before any overwrite, and uninstall never
127
- > deletes a file `r2p` did not create.
188
+ Omitting `--platform` targets all supported platforms for both `r2p install` and
189
+ `r2p uninstall`.
128
190
 
129
- ### Workflow skills
191
+ `r2p status` is read-only. With `--json`, it reports machine-readable platform
192
+ state, installed version, and manifest issues.
130
193
 
131
- After install, the platform skills call these shared `r2p-*` wrappers — one per
132
- step of running a workflow:
194
+ ## How the workflow works
133
195
 
134
- | Skill | What it does |
135
- |---|---|
136
- | `r2p-start` | Start a new run from a requirement (text, or `--file <path>` to read a document's contents). |
137
- | `r2p-continue` | Continue the active run — advance it to its next stop (gate, checkpoint, or repair). |
138
- | `r2p-status` | Inspect the current run, or all runs, read-only. |
139
- | `r2p-switch` | Point the active run at a different `--work-id`. |
140
- | `r2p-tier-lock` | Lock the active run's complexity tier (`--base light\|standard`). |
141
- | `r2p-reopen` | Reopen a closed run from a specific `--stage`. |
142
- | `r2p-gap-open` | Route an upstream gap on an open run back to its `--owner-stage`; downstream artifacts become stale and must be re-derived. |
143
- | `r2p-gap-resolve` | Close a gap `--route-id` after the owner stage is re-worked and passes `gate-quality`. |
196
+ Every run lives in `.req-to-plan/<work-id>/` inside the target workspace. The
197
+ agent writes semantic content; the CLI owns state, files, gates, and structured
198
+ validation.
144
199
 
145
- > [!TIP]
146
- > Add `~/.req-to-plan/bin` to your `PATH` to run the `r2p-*` wrappers directly:
147
- >
148
- > ```bash
149
- > export PATH="$HOME/.req-to-plan/bin:$PATH"
150
- > ```
200
+ | Stage | Output |
201
+ |---|---|
202
+ | Raw requirement | Original user requirement |
203
+ | Requirement brief | Scope, goals, non-goals, and acceptance direction |
204
+ | Risk discovery | Unknowns, constraints, dependencies, and risk areas |
205
+ | DESIGN | Technical approach and decision requests |
206
+ | SPEC | Detailed behavior and interfaces |
207
+ | PLAN | Ordered implementation tasks with verification criteria |
151
208
 
152
- ### When to use which skill
209
+ Standard-tier DESIGN/SPEC/PLAN stages can require subagent review, especially
210
+ when tier modifiers such as `migration`, `safety`, or `cross_project` are
211
+ present. If a later stage discovers an upstream decision gap, use
212
+ `r2p-gap-open`, repair the owner stage, then close the route with
213
+ `r2p-gap-resolve`.
153
214
 
154
- Most runs only need `r2p-start`, then repeated `r2p-continue`. The other skills
155
- cover specific situations.
215
+ ## Development
156
216
 
157
- **Lock the tier** — once per run, when `r2p-continue` stops with `tier_not_locked`:
217
+ Install development dependencies:
158
218
 
159
219
  ```bash
160
- r2p-tier-lock --work-id <id> --base standard --modifiers migration,safety --confirm
220
+ python3 -m pip install -r requirements-dev.txt
161
221
  ```
162
222
 
163
- `--base standard` raises the rigor floor; the `migration`, `safety`, and
164
- `cross_project` modifiers force a subagent review at the DESIGN / SPEC / PLAN
165
- checkpoints.
166
-
167
- **Reopen a closed run** — revisit a run that was closed at the PLAN checkpoint,
168
- restarting from an earlier stage (this seeds a new linked run):
223
+ Run the test suite:
169
224
 
170
225
  ```bash
171
- r2p-reopen --from <closed-id> --stage spec --reason "spec gap found"
226
+ npm test
227
+ # or, when using the checked-in virtual environment:
228
+ npm run test:local
172
229
  ```
173
230
 
174
- **Route an upstream gap** — on an *open* run, when a later stage finds that an
175
- earlier stage owns a wrong or missing decision. `gap-open` sends the run back to
176
- the owner stage and marks everything downstream stale; after you re-work the
177
- owner past `gate-quality`, `gap-resolve` closes the route so the owner can be
178
- re-approved and the downstream re-derived:
231
+ Useful local checks:
179
232
 
180
233
  ```bash
181
- r2p-gap-open --work-id <id> --owner-stage design --required-action "fixed-window burst flaw"
182
- # then re-work the owner stage until it passes gate-quality (r2p-continue guides this)
183
- r2p-gap-resolve --work-id <id> --route-id R-1
234
+ node bin/r2p.js version
235
+ node bin/r2p.js help
236
+ .venv/bin/python -m tools.workflow_cli --help
237
+ .venv/bin/python -m tools.workflow_cli.agent_shortcuts --help
184
238
  ```
185
239
 
186
- > [!NOTE]
187
- > Reopen is for a *closed* run; gap routing is for an *open* one. `r2p-continue`
188
- > walks you through both repair flows with `needs_repair` and `needs_gap_resolve`
189
- > stops.
240
+ Project layout:
190
241
 
191
- > [!NOTE]
192
- > **Human decision points (standard DESIGN).** When a standard-tier DESIGN
193
- > involves a choice a human must make (new dependency, migration strategy,
194
- > API compatibility), the agent records it in the `## Decision Requests`
195
- > section as a `### DECISION-NNN` block with `Question:`, `Options:`,
196
- > `Recommended:`, and `Status: pending` and a pending decision fails
197
- > `gate-quality` until a human chooses and the block becomes
198
- > `Status: selected` with `Selected:` and `Rationale:` lines.
199
- > Write exactly `none` in that section when no human decision is needed.
200
-
201
- ## License
202
-
203
- [MIT](./LICENSE) © xenonbyte
242
+ | Path | Purpose |
243
+ |---|---|
244
+ | `bin/r2p.js` | npm binary that invokes the Python lifecycle CLI |
245
+ | `tools/r2p-*` | installed workflow wrapper scripts |
246
+ | `tools/workflow_cli/` | state machine, gates, templates, installer, and command routing |
247
+ | `tools/workflow_cli/agent_templates/` | generated surfaces for Claude Code, Codex, and Gemini |
248
+ | `tests/` | regression tests for CLI behavior, state, gates, install safety, packaging, and README consistency |