@curdx/flow 1.1.11 → 2.0.0-beta.10

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 (96) hide show
  1. package/.claude-plugin/marketplace.json +3 -3
  2. package/.claude-plugin/plugin.json +4 -11
  3. package/CHANGELOG.md +99 -0
  4. package/README.md +74 -102
  5. package/README.zh.md +2 -2
  6. package/agent-preamble/preamble.md +81 -11
  7. package/agents/flow-adversary.md +41 -56
  8. package/agents/flow-architect.md +24 -11
  9. package/agents/flow-debugger.md +2 -2
  10. package/agents/flow-edge-hunter.md +20 -6
  11. package/agents/flow-executor.md +3 -3
  12. package/agents/flow-planner.md +51 -48
  13. package/agents/flow-product-designer.md +15 -2
  14. package/agents/flow-qa-engineer.md +4 -4
  15. package/agents/flow-researcher.md +18 -3
  16. package/agents/flow-reviewer.md +5 -1
  17. package/agents/flow-security-auditor.md +2 -2
  18. package/agents/flow-triage-analyst.md +4 -4
  19. package/agents/flow-ui-researcher.md +7 -7
  20. package/agents/flow-ux-designer.md +3 -3
  21. package/agents/flow-verifier.md +47 -14
  22. package/bin/curdx-flow.js +13 -1
  23. package/cli/doctor.js +28 -13
  24. package/cli/install.js +62 -36
  25. package/cli/protocols.js +63 -10
  26. package/cli/registry.js +73 -0
  27. package/cli/uninstall.js +9 -11
  28. package/cli/upgrade.js +6 -10
  29. package/cli/utils.js +104 -56
  30. package/commands/debug.md +10 -10
  31. package/commands/fast.md +1 -1
  32. package/commands/help.md +109 -87
  33. package/commands/implement.md +7 -7
  34. package/commands/init.md +18 -7
  35. package/commands/review.md +114 -130
  36. package/commands/spec.md +131 -89
  37. package/commands/start.md +130 -153
  38. package/commands/verify.md +110 -92
  39. package/gates/adversarial-review-gate.md +20 -20
  40. package/gates/coverage-audit-gate.md +1 -1
  41. package/gates/devex-gate.md +5 -6
  42. package/gates/edge-case-gate.md +2 -2
  43. package/gates/security-gate.md +3 -3
  44. package/hooks/hooks.json +0 -11
  45. package/hooks/scripts/quick-mode-guard.sh +12 -9
  46. package/hooks/scripts/session-start.sh +2 -2
  47. package/hooks/scripts/stop-watcher.sh +25 -15
  48. package/knowledge/epic-decomposition.md +2 -2
  49. package/knowledge/execution-strategies.md +10 -9
  50. package/knowledge/planning-reviews.md +6 -6
  51. package/knowledge/spec-driven-development.md +11 -10
  52. package/knowledge/two-stage-review.md +6 -5
  53. package/knowledge/wave-execution.md +5 -5
  54. package/package.json +4 -2
  55. package/skills/brownfield-index/SKILL.md +62 -0
  56. package/skills/browser-qa/SKILL.md +50 -0
  57. package/skills/epic/SKILL.md +68 -0
  58. package/skills/security-audit/SKILL.md +50 -0
  59. package/skills/ui-sketch/SKILL.md +49 -0
  60. package/templates/config.json.tmpl +1 -1
  61. package/templates/design.md.tmpl +32 -112
  62. package/templates/requirements.md.tmpl +25 -43
  63. package/templates/research.md.tmpl +37 -68
  64. package/templates/tasks.md.tmpl +27 -84
  65. package/agents/persona-amelia.md +0 -128
  66. package/agents/persona-david.md +0 -141
  67. package/agents/persona-emma.md +0 -179
  68. package/agents/persona-john.md +0 -105
  69. package/agents/persona-mary.md +0 -95
  70. package/agents/persona-oliver.md +0 -136
  71. package/agents/persona-rachel.md +0 -126
  72. package/agents/persona-serena.md +0 -175
  73. package/agents/persona-winston.md +0 -117
  74. package/commands/audit.md +0 -170
  75. package/commands/autoplan.md +0 -184
  76. package/commands/design.md +0 -155
  77. package/commands/discuss.md +0 -162
  78. package/commands/doctor.md +0 -124
  79. package/commands/index.md +0 -261
  80. package/commands/install-deps.md +0 -128
  81. package/commands/party.md +0 -241
  82. package/commands/plan-ceo.md +0 -117
  83. package/commands/plan-design.md +0 -107
  84. package/commands/plan-dx.md +0 -104
  85. package/commands/plan-eng.md +0 -108
  86. package/commands/qa.md +0 -118
  87. package/commands/requirements.md +0 -146
  88. package/commands/research.md +0 -141
  89. package/commands/security.md +0 -109
  90. package/commands/sketch.md +0 -118
  91. package/commands/spike.md +0 -181
  92. package/commands/status.md +0 -139
  93. package/commands/switch.md +0 -95
  94. package/commands/tasks.md +0 -189
  95. package/commands/triage.md +0 -160
  96. package/hooks/scripts/fail-tracker.sh +0 -31
package/commands/init.md CHANGED
@@ -22,7 +22,7 @@ ls -la
22
22
  - If the current directory is a dangerous location such as the home directory or a system directory, stop and ask the user to switch
23
23
  - If `.flow/` already exists:
24
24
  - With `--force` → continue but warn about overwriting
25
- - Without `--force` → stop and prompt the user to run `/curdx-flow:status` to inspect the existing state
25
+ - Without `--force` → stop and prompt the user to inspect `.flow/` directly, or run `/curdx-flow:start --list` to see existing specs
26
26
 
27
27
  ### Step 2: Create Directory Skeleton
28
28
 
@@ -71,9 +71,20 @@ Append (if not already present):
71
71
 
72
72
  ### Step 5: Health Check
73
73
 
74
- Run `/curdx-flow:doctor` (or inline its checks) to verify:
75
- - 3 MCPs started (context7 / sequential-thinking / chrome-devtools)
76
- - Recommended plugins status (pua / claude-mem / frontend-design)
74
+ Do NOT shell out to a new terminal for this step — you are already inside
75
+ Claude Code. Verify inline via the information the plugin already has:
76
+
77
+ - Read `~/.claude/plugins/data/curdx-flow/.deps-checked` (optional — the
78
+ SessionStart hook already refreshes this once per day).
79
+ - If the user asks for the full report, suggest they run
80
+ `npx @curdx/flow doctor` in a separate terminal — don't try to spawn
81
+ it from inside the Claude Code session (output won't render cleanly
82
+ and the user has to alt-tab to see it).
83
+
84
+ Items the CLI doctor covers (for user reference):
85
+ - 2 bundled MCPs (context7 / sequential-thinking) — visible in `claude mcp list`
86
+ - 4 recommended plugins (pua / claude-mem / frontend-design / chrome-devtools-mcp)
87
+ - Runtime PATH guards for `bun` / `uv` (relevant only when claude-mem is installed)
77
88
 
78
89
  ### Step 6: Prompt Next Steps
79
90
 
@@ -90,9 +101,9 @@ Output:
90
101
 
91
102
  Next steps (in order):
92
103
  1. Edit .flow/PROJECT.md to add the project goal
93
- 2. /curdx-flow:install-deps install recommended plugins (if not installed)
94
- 3. /curdx-flow:doctor — verify health
95
- 4. /curdx-flow:status view project status
104
+ 2. (already handled) — recommended plugins installed via `npx @curdx/flow install --all`
105
+ 3. npx @curdx/flow doctor — verify health
106
+ 4. /curdx-flow:start <name> "<goal>" begin your first feature spec
96
107
 
97
108
  Start development (after Phase 1 ships):
98
109
  5. /curdx-flow:start <name> "<goal>" — kick off the first spec
@@ -1,168 +1,152 @@
1
1
  ---
2
2
  name: review
3
- description: Two-Stage Review — Stage 1 spec compliance + Stage 2 code quality. Applies enabled Gates. Dispatches flow-reviewer.
4
- argument-hint: "[spec-name] [--adversarial | --edge-case | --both]"
3
+ description: Two-stage code review — Stage 1 spec compliance, Stage 2 code quality. Optional flags add adversarial review or edge-case hunting.
4
+ argument-hint: "[--stage=<1|2|both>] [--adversarial] [--edge-case]"
5
5
  allowed-tools: [Read, Bash, Task, Grep, Glob]
6
6
  ---
7
7
 
8
- # Flow Review — Two-Stage Code Review
8
+ # Two-Stage Code Review
9
9
 
10
- @${CLAUDE_PLUGIN_ROOT}/knowledge/two-stage-review.md
10
+ Distinct from `/curdx-flow:verify`:
11
+ - **verify** checks that the spec's stated goals actually work (goal-backward).
12
+ - **review** checks that the code is good (spec compliance + craftsmanship).
11
13
 
12
- Dispatches the `flow-reviewer` agent to perform a Two-Stage Review: Stage 1 compliance + Stage 2 quality.
13
- Optionally layer on deep reviews from `flow-adversary` and `flow-edge-hunter`.
14
+ ## Flags
14
15
 
15
- ## When to use
16
+ | Flag | Default | Purpose |
17
+ |------|---------|---------|
18
+ | `--stage=<1\|2\|both>` | `both` | Stage 1 = spec compliance only. Stage 2 = code quality only. `both` = sequential. |
19
+ | `--adversarial` | off | Add an adversarial review pass across applicable categories (zero findings requires proof-of-checking, not fabrication). |
20
+ | `--edge-case` | off | Add edge-case hunting across applicable categories. Produces a test-gap checklist. |
16
21
 
17
- - After `/curdx-flow:verify` passes
18
- - Before PR
19
- - When the user explicitly requests a deep review (add --adversarial / --edge-case / --both)
20
-
21
- ## Step 1: Parse arguments
22
+ ## Preflight
22
23
 
23
24
  ```bash
24
- ARGS="$ARGUMENTS"
25
- ADV=0; EDGE=0
26
- case "$ARGS" in
27
- *--both*) ADV=1; EDGE=1 ;;
28
- *--adversarial*) ADV=1 ;;
29
- *--edge-case*) EDGE=1 ;;
30
- esac
31
-
32
- SPEC_NAME=$(echo "$ARGS" | sed 's/--[a-z-]*//g' | xargs)
33
- [ -z "$SPEC_NAME" ] && SPEC_NAME=$(cat .flow/.active-spec 2>/dev/null)
34
- [ -z "$SPEC_NAME" ] && { echo "❌ No active spec"; exit 1; }
25
+ [ ! -d ".flow" ] && { echo "✗ Not a CurDX-Flow project."; exit 1; }
26
+
27
+ SPEC_NAME=$(cat .flow/.active-spec 2>/dev/null)
28
+ [ -z "$SPEC_NAME" ] && { echo "✗ No active spec."; exit 1; }
29
+
30
+ # Review needs a design.md + implementation to compare against
31
+ for f in design.md; do
32
+ [ ! -f ".flow/specs/$SPEC_NAME/$f" ] && {
33
+ echo "✗ Missing $f. Run /curdx-flow:spec first.";
34
+ exit 1;
35
+ }
36
+ done
37
+
38
+ FLAG_STAGE=$(echo "$ARGUMENTS" | grep -oP -- '--stage=\K[^\s]+' || echo "both")
39
+ FLAG_ADV=$(echo "$ARGUMENTS" | grep -q -- '--adversarial' && echo 1 || echo 0)
40
+ FLAG_EDGE=$(echo "$ARGUMENTS" | grep -q -- '--edge-case' && echo 1 || echo 0)
35
41
  ```
36
42
 
37
- ## Step 2: Preflight checks
43
+ ## Stage 1 Spec compliance
38
44
 
39
- ```bash
40
- DIR=".flow/specs/$SPEC_NAME"
45
+ Dispatch `flow-reviewer` in Stage 1 mode. It checks:
46
+ - Implementation actually addresses every US / AC / FR / NFR in `requirements.md`
47
+ - Code structure reflects AD-NN decisions from `design.md`
48
+ - Task checklist in `tasks.md` is genuinely complete (all tasks marked `[x]` have real code)
49
+ - Conventional-commit log (`git log`) matches the tasks declared completed
41
50
 
42
- # If /curdx-flow:verify hasn't been run, prompt to run it first
43
- if [ ! -f "$DIR/verification-report.md" ]; then
44
- echo "⚠ /curdx-flow:verify not run. Recommend running goal-reverse verification first."
45
- echo "Continue? (y/N)"
46
- # AskUserQuestion
47
- fi
48
- ```
51
+ Output: Stage-1 section of the report with any compliance gaps.
49
52
 
50
- ## Step 3: Dispatch flow-reviewer (core)
53
+ ## Stage 2 Code quality
51
54
 
52
- ```
53
- Task:
54
- subagent_type: general-purpose
55
- description: "Review $SPEC_NAME"
56
- prompt: |
57
- You are the flow-reviewer agent. Full definition:
58
- ${CLAUDE_PLUGIN_ROOT}/agents/flow-reviewer.md
59
-
60
- Spec files to read:
61
- - .flow/specs/$SPEC_NAME/requirements.md
62
- - .flow/specs/$SPEC_NAME/design.md
63
- - .flow/specs/$SPEC_NAME/tasks.md
64
- - .flow/specs/$SPEC_NAME/.state.json
65
- - .flow/specs/$SPEC_NAME/verification-report.md (if exists)
66
-
67
- Enabled Gates (from .flow/config.json):
68
- - karpathy-gate (always)
69
- - verification-gate (always)
70
- - tdd-gate (standard+)
71
- - coverage-audit-gate (standard+)
72
-
73
- Tasks:
74
- Stage 1: Spec compliance review
75
- - Judge each FR / AC / AD / error path as ✓/⚠/✗
76
- - Check Out of Scope adherence
77
-
78
- Stage 2: Code quality review
79
- - Apply all enabled Gates
80
- - Emit per-Gate check results
81
-
82
- Combined verdict:
83
- - APPROVED / APPROVED_WITH_WARNINGS / NEEDS_FIXES / BLOCKED
84
-
85
- Output:
86
- .flow/specs/$SPEC_NAME/review-report.md
87
-
88
- Return a brief to me: Stage 1/2 verdicts, blocking/warning counts, and the top 3 fix suggestions
89
- ```
55
+ Dispatch `flow-reviewer` in Stage 2 mode. It checks:
56
+ - Naming, comments, structure
57
+ - Error handling completeness
58
+ - Test coverage and test quality
59
+ - Performance / resource usage concerns
60
+ - Security smells (not a full security audit — that's `security-audit` skill)
61
+ - Karpathy 4 principles applied
90
62
 
91
- ## Step 4 (optional): Dispatch flow-adversary
63
+ Output: Stage-2 section of the report.
64
+
65
+ ## Optional: adversarial review
92
66
 
93
67
  If `--adversarial`:
68
+ Dispatch `flow-adversary`. It scans the applicable categories (Architecture / Implementation / Testing / Security / Maintainability / UX — skip N/A with reason) using `sequential-thinking` proportional to the residual uncertainty, probing:
69
+ 1. What's missing?
70
+ 2. What's overengineered?
71
+ 3. What would break first in production?
72
+ 4. What's undocumented that a new maintainer would misunderstand?
73
+ 5. What decision locks us out of a future option?
74
+ 6. What would a skeptical reviewer reject?
94
75
 
95
- ```
96
- Task:
97
- subagent_type: general-purpose
98
- description: "Adversarial review $SPEC_NAME"
99
- prompt: |
100
- You are the flow-adversary agent. Full definition:
101
- ${CLAUDE_PLUGIN_ROOT}/agents/flow-adversary.md
102
-
103
- Core rule: zero findings are forbidden — must find ≥ 3 categories of issues
104
-
105
- Scan:
106
- - .flow/specs/$SPEC_NAME/*.md
107
- - Related code (git diff)
108
- - Recent commits
109
-
110
- Use sequential-thinking ≥ 12 rounds (2 rounds × 6 dimensions)
111
-
112
- Output: .flow/specs/$SPEC_NAME/adversarial-review.md
113
- ```
76
+ **Zero findings requires proof-of-checking, not fabrication** — honest "clean" verdicts are fine if the agent lists what it examined. Per `@${CLAUDE_PLUGIN_ROOT}/gates/adversarial-review-gate.md`.
114
77
 
115
- ## Step 5 (optional): Dispatch flow-edge-hunter
78
+ ## Optional: edge-case hunting
116
79
 
117
80
  If `--edge-case`:
81
+ Dispatch `flow-edge-hunter` across the applicable categories (skip N/A with one-line reason):
82
+ 1. Boundary values (0, MAX, empty, one-over-limit)
83
+ 2. Concurrency / race conditions
84
+ 3. Network failure / partial failure
85
+ 4. Malformed input
86
+ 5. Permission / auth failure
87
+ 6. Resource exhaustion
88
+ 7. Time / locale / timezone
118
89
 
119
- ```
120
- Task:
121
- subagent_type: general-purpose
122
- description: "Edge-case scan $SPEC_NAME"
123
- prompt: |
124
- You are the flow-edge-hunter agent. Full definition:
125
- ${CLAUDE_PLUGIN_ROOT}/agents/flow-edge-hunter.md
126
-
127
- Scan the subject's coverage across 7 categories:
128
- - Boundary values / nulls / concurrency / error recovery / security / i18n / performance
129
-
130
- Use sequential-thinking ≥ 3 rounds per category
131
-
132
- Output: .flow/specs/$SPEC_NAME/edge-cases.md
133
- ```
90
+ Output: test-gap checklist with suggested test cases.
134
91
 
135
- ## Step 6: Read reports + aggregate verdict
92
+ ## Report
136
93
 
137
- ```bash
138
- MAIN_REPORT="$DIR/review-report.md"
139
- ADV_REPORT="$DIR/adversarial-review.md"
140
- EDGE_REPORT="$DIR/edge-cases.md"
94
+ **Landing check**: sub-agent responses can be truncated. After dispatching review agents, verify the report actually landed on disk:
141
95
 
142
- # Parse the verdict from review-report.md
143
- VERDICT=$(grep -E "^## Verdict:" "$MAIN_REPORT" | head -1 | sed 's/## Verdict: //')
96
+ ```bash
97
+ REPORT=".flow/specs/$SPEC_NAME/review-report.md"
98
+ if [ ! -f "$REPORT" ] || [ "$(wc -c < "$REPORT" 2>/dev/null | tr -d ' ')" -lt 300 ]; then
99
+ echo "⚠ Report missing or truncated. Re-dispatching flow-reviewer with a terse 'Write the report now, no narration' prompt."
100
+ fi
144
101
  ```
145
102
 
146
- ## Step 7: Output to user
103
+ Consolidated output: `.flow/specs/$SPEC_NAME/review-report.md`:
104
+
105
+ ```markdown
106
+ # Review Report — <spec-name>
107
+
108
+ ## Stage 1 — Spec Compliance
109
+ - ✓ FR-01: implemented in src/auth.ts
110
+ - ✗ FR-04: missing — add handler for token refresh
111
+ - ⚠ AC-2.1: no integration test asserting 403 on expired token
147
112
 
113
+ ## Stage 2 — Code Quality
114
+ - Blocker: duplicated error-handling pattern in 3 files — extract helper
115
+ - Warning: function foo() in src/a.ts: 90 lines, split
116
+ - Nit: inconsistent naming (getUserId vs fetchUser)
117
+
118
+ ## Adversarial (if run)
119
+ ...
120
+
121
+ ## Edge Cases (if run)
122
+ ...
123
+
124
+ ## Verdict
125
+ - [ ] APPROVED
126
+ - [X] CHANGES REQUIRED — <n> blockers
127
+ - [ ] REJECTED
148
128
  ```
149
- ✓ Review complete: $SPEC_NAME
150
129
 
151
- Main report: .flow/specs/$SPEC_NAME/review-report.md
152
- Verdict: $VERDICT
130
+ ## Reporting
131
+
132
+ ```
133
+ ✓ Review complete
134
+ Stage 1 findings: <n>
135
+ Stage 2 findings: <n>
136
+ Adversarial findings: <n> (if --adversarial)
137
+ Edge-case gaps: <n> (if --edge-case)
138
+ Verdict: CHANGES REQUIRED
153
139
 
154
- $([ "$ADV" = "1" ] && echo "Adversarial review: $ADV_REPORT")
155
- $([ "$EDGE" = "1" ] && echo "Edge-case scan: $EDGE_REPORT")
140
+ Report: .flow/specs/<name>/review-report.md
156
141
 
157
- Next steps:
158
- $([ "$VERDICT" = "APPROVED" ] && echo " ✓ Proceed to /curdx-flow:ship (Phase 6+)")
159
- $([ "$VERDICT" = "APPROVED_WITH_WARNINGS" ] && echo " ⚠ Recommend fixing warnings first, then /curdx-flow:ship")
160
- $([ "$VERDICT" = "NEEDS_FIXES" ] && echo " ❌ Fix blockers → /curdx-flow:implement --task=... → /curdx-flow:review re-review")
161
- $([ "$VERDICT" = "BLOCKED_BY_SPEC" ] && echo " ❌ Back to /curdx-flow:implement to fill missing FR/AD")
142
+ Next: address blockers, then re-run /curdx-flow:review.
162
143
  ```
163
144
 
164
- ## Error recovery
145
+ ## References
165
146
 
166
- - review-report.md generation fails → check agent turn limit, reduce spec scope
167
- - Agent returns no findings (violates adversarial zero-tolerance) agent auto-triggers Round 2
168
- - Multiple concurrent agents produce conflicting files → run sequentially, not in parallel
147
+ - `flow-reviewer` agent: `@${CLAUDE_PLUGIN_ROOT}/agents/flow-reviewer.md`
148
+ - `flow-adversary` agent: `@${CLAUDE_PLUGIN_ROOT}/agents/flow-adversary.md`
149
+ - `flow-edge-hunter` agent: `@${CLAUDE_PLUGIN_ROOT}/agents/flow-edge-hunter.md`
150
+ - `adversarial-review-gate`: `@${CLAUDE_PLUGIN_ROOT}/gates/adversarial-review-gate.md`
151
+ - `edge-case-gate`: `@${CLAUDE_PLUGIN_ROOT}/gates/edge-case-gate.md`
152
+ - Knowledge: `@${CLAUDE_PLUGIN_ROOT}/knowledge/two-stage-review.md`
package/commands/spec.md CHANGED
@@ -1,135 +1,177 @@
1
1
  ---
2
2
  name: spec
3
- description: One-shot sequential run of research → requirements → design → tasks across all four stages
4
- argument-hint: "[spec-name] [--skip-research | --skip-requirements]"
3
+ description: Generate or refresh a feature specification. By default runs research → requirements → design → tasks in sequence. Flags let you target a single phase, stop early, regenerate, or tack on a multi-dimensional planning review.
4
+ argument-hint: "[--phase=<X[,Y,...]>] [--until=<X>] [--review[=<dim[,dim]>]] [--regenerate] [--resume]"
5
5
  allowed-tools: [Read, Write, Bash, Task, AskUserQuestion]
6
6
  ---
7
7
 
8
- # One-Shot Full Spec Generation
8
+ # Generate or Refresh the Active Spec
9
9
 
10
- Runs the 4 spec stages sequentially, prompting the user between stages to decide whether to continue. Suitable for generating a full spec in one go.
10
+ This command writes the four spec documents (`research.md`, `requirements.md`, `design.md`, `tasks.md`) inside `.flow/specs/<active-spec>/`. It replaces the v1 commands `/research`, `/requirements`, `/design`, `/tasks`, `/plan-ceo`, `/plan-eng`, `/plan-design`, `/plan-dx`, and `/autoplan` all expressed here as flags.
11
11
 
12
- ## Step 1: Preflight + confirmation
12
+ ## Flags
13
13
 
14
- ```bash
15
- [ ! -d ".flow" ] && { echo "❌ Not a CurDX-Flow project"; exit 1; }
14
+ | Flag | Default | Purpose |
15
+ |------|---------|---------|
16
+ | `--phase=<X[,Y]>` | (inferred from `.state.json`) | Run only the listed phase(s). `X ∈ {research, requirements, design, tasks}`. Accepts comma-separated list. |
17
+ | `--until=<X>` | (none) | Run from the current phase forward, stopping after `X`. Mutually exclusive with `--phase`. |
18
+ | `--review[=<dim[,dim]>]` | (not run) | After phases complete, run a planning review. `dim ∈ {ceo, eng, design, dx, all}`. Bare `--review` = `--review=all`. |
19
+ | `--regenerate` | (resume) | Wipe existing phase output for the targeted phases and rebuild from scratch. |
20
+ | `--resume` | (default) | Continue from `.state.json.phase`. This is the default when no flag is given. |
16
21
 
17
- SPEC_NAME="$(echo "$ARGUMENTS" | awk '{print $1}')"
18
- [ -z "$SPEC_NAME" ] && SPEC_NAME=$(cat .flow/.active-spec 2>/dev/null)
22
+ ## Preflight
19
23
 
24
+ ```bash
25
+ # 1. A .flow project must exist
26
+ [ ! -d ".flow" ] && {
27
+ echo "✗ Not a CurDX-Flow project. Run /curdx-flow:init first.";
28
+ exit 1;
29
+ }
30
+
31
+ # 2. An active spec must be set
32
+ SPEC_NAME=$(cat .flow/.active-spec 2>/dev/null)
20
33
  if [ -z "$SPEC_NAME" ]; then
21
- echo " No active spec. Run /curdx-flow:start <name> \"<goal>\" first"
22
- exit 1
34
+ echo " No active spec. Run /curdx-flow:start <name> \"<goal>\" first.";
35
+ exit 1;
23
36
  fi
37
+ SPEC_DIR=".flow/specs/$SPEC_NAME"
38
+ STATE_FILE="$SPEC_DIR/.state.json"
39
+ [ ! -f "$STATE_FILE" ] && { echo "✗ Missing $STATE_FILE"; exit 1; }
24
40
  ```
25
41
 
26
- ## Step 2: Parse skip options
42
+ ## Flag parsing
27
43
 
28
44
  ```bash
29
- SKIP_RESEARCH=0
30
- SKIP_REQUIREMENTS=0
31
- case "$ARGUMENTS" in
32
- *--skip-research*) SKIP_RESEARCH=1 ;;
33
- esac
34
- case "$ARGUMENTS" in
35
- *--skip-requirements*) SKIP_REQUIREMENTS=1 ;;
36
- esac
45
+ # $ARGUMENTS is the raw argument string
46
+ FLAG_PHASE=$(echo "$ARGUMENTS" | grep -oP -- '--phase=\K[^\s]+' || true)
47
+ FLAG_UNTIL=$(echo "$ARGUMENTS" | grep -oP -- '--until=\K[^\s]+' || true)
48
+ FLAG_REVIEW=$(echo "$ARGUMENTS" | grep -oP -- '--review(?:=[^\s]+)?' || true)
49
+ FLAG_REGENERATE=$(echo "$ARGUMENTS" | grep -q -- '--regenerate' && echo "1" || echo "0")
50
+
51
+ # Rule: --phase and --until are mutually exclusive
52
+ if [ -n "$FLAG_PHASE" ] && [ -n "$FLAG_UNTIL" ]; then
53
+ echo "✗ --phase and --until cannot be combined. Pick one.";
54
+ exit 1;
55
+ fi
37
56
  ```
38
57
 
39
- ## Step 3: Execute the 4 stages in sequence
58
+ ## Phase resolution
40
59
 
41
- ### Phase 1: Research
60
+ The ordered pipeline is `research → requirements → design → tasks`. Resolve which phases to run:
42
61
 
43
- ```bash
44
- if [ "$SKIP_RESEARCH" = "1" ]; then
45
- echo "⊘ Skipping research"
46
- elif [ -f ".flow/specs/$SPEC_NAME/research.md" ]; then
47
- echo "ℹ research.md already exists; asking the user..."
48
- # AskUserQuestion: re-run research? (skip / rerun / abort)
49
- else
50
- echo "▶ Running research stage..."
51
- # Via SlashCommand or directly dispatch the agent
52
- # Recommended: directly invoke the /curdx-flow:research logic (inline or via the SlashCommand tool)
53
- fi
54
- ```
62
+ - No flags → start at `state.json.phase`, run forward to `tasks`.
63
+ - `--phase=design` run only `design`.
64
+ - `--phase=design,tasks` run `design` then `tasks`.
65
+ - `--until=design` start at `state.json.phase`, stop after `design`.
66
+ - `--regenerate` (no other phase flag) same as default but clear existing output for each phase before running.
67
+ - `--regenerate --phase=X` clear `X`'s output, re-run only `X`.
55
68
 
56
- **Implementation 1** (recommended): Dispatch the agent directly, skipping SlashCommand:
69
+ Read and update `.state.json.phase` after each phase succeeds.
57
70
 
58
- Call the Task tool with the same content as the Task call in `/curdx-flow:research` (reading flow-researcher.md).
71
+ ## Phase execution
59
72
 
60
- **Implementation 2**: If Claude Code supports the SlashCommand tool chain:
61
- ```
62
- SlashCommand: /curdx-flow:research $SPEC_NAME
63
- ```
73
+ For each phase in the resolved list, dispatch a sub-agent via the `Task` tool:
64
74
 
65
- ### Intermediate confirmation after each stage
75
+ ### research `flow-researcher`
76
+ Inputs: spec goal + one-line description from `.state.json`.
77
+ Output: `research.md` covering problem space, prior art (library candidates via `context7`), constraints, technical recommendation.
66
78
 
67
- ```
68
- research stage complete
79
+ ### requirements → `flow-product-designer`
80
+ Inputs: `research.md`.
81
+ Output: `requirements.md` with user stories (US-NN), acceptance criteria (AC-N.N), functional requirements (FR-NN), non-functional requirements (NFR-*).
82
+
83
+ ### design → `flow-architect`
84
+ Inputs: `research.md` + `requirements.md`.
85
+ Output: `design.md` with architecture decisions (AD-NN), component boundaries, data models, error-path design, mermaid diagrams (when they clarify). Uses `sequential-thinking` MCP proportional to the genuine tradeoff surface.
69
86
 
70
- Key findings:
71
- - ...
72
- - ...
87
+ ### tasks → `flow-planner`
88
+ Inputs: all three prior files + `.flow/PROJECT.md` tech stack.
89
+ Output: `tasks.md` — POC-First 5-phase decomposition with per-task Verify commands, multi-source coverage audit against FR/AC/AD/Research/Decisions.
73
90
 
74
- The following open questions were found; recommend answering first:
75
- Q1: ...
91
+ After each phase completes successfully, update `.state.json`:
76
92
 
77
- Choose:
78
- [continue] Continue to requirements (agent will answer open questions with reasonable assumptions)
79
- [pause] Pause — I'll review research.md myself, then manually run /curdx-flow:requirements
80
- [abort] Abort the entire /curdx-flow:spec
93
+ ```json
94
+ {
95
+ "phase": "<just-completed-phase>",
96
+ "phase_status": { "<phase>": "completed" },
97
+ "updated": "<ISO8601 timestamp>"
98
+ }
81
99
  ```
82
100
 
83
- Use AskUserQuestion for the choice.
101
+ ### Artifact landing check (mandatory after every phase)
84
102
 
85
- ### Phase 2: Requirements
103
+ Sub-agent responses can be truncated by the model's output-length limit, which means the `Write` tool call for the phase's Markdown artifact may never fire. Do NOT trust the agent's return value alone — always verify the file actually landed.
86
104
 
87
- If continue, dispatch flow-product-designer (mirroring the Task call in `/curdx-flow:requirements`).
105
+ For each phase just dispatched, run:
88
106
 
89
- Confirm again after completion.
107
+ ```bash
108
+ ARTIFACT=".flow/specs/$SPEC_NAME/<phase>.md"
109
+ if [ ! -f "$ARTIFACT" ]; then
110
+ echo "⚠ $ARTIFACT did not land. Re-dispatching <phase> agent with an explicit 'write the file' prompt."
111
+ # Re-dispatch the same agent, but in the prompt, front-load:
112
+ # "Your ONLY job is to call the Write tool with the full <phase>.md content now.
113
+ # Do not explain. Do not narrate. Write the file and stop."
114
+ # This pattern produces an artifact even when prior verbosity caused truncation.
115
+ fi
116
+
117
+ # Minimum-size sanity check — if the file is <500 bytes, the write likely truncated
118
+ if [ -f "$ARTIFACT" ] && [ "$(wc -c < "$ARTIFACT" | tr -d ' ')" -lt 500 ]; then
119
+ echo "⚠ $ARTIFACT looks truncated (<500 bytes). Re-dispatching to complete it."
120
+ fi
121
+ ```
90
122
 
91
- ### Phase 3: Design
123
+ Only advance `.state.json.phase` after both the file exists AND passes the size sanity check. If a re-dispatch also fails to produce the artifact, stop and surface the issue to the user instead of silently advancing — that prevents later phases from consuming an empty upstream file.
92
124
 
93
- If continue, dispatch flow-architect (mirroring the Task call in `/curdx-flow:design`).
125
+ ## Optional planning review
94
126
 
95
- Confirm again after completion. **This step is especially important** because design freezes the technology choices — recommend that the user review the AD-NN entries before entering tasks.
127
+ If `--review` (or `--review=<dims>`) is present:
96
128
 
97
- ### Phase 4: Tasks
129
+ 1. **Precondition**: `design.md` must exist. If missing, error: "Design missing. Run `/curdx-flow:spec --phase=design` first."
130
+ 2. Parse the dims: `all` expands to `ceo,eng,design,dx`.
131
+ 3. Dispatch review agents in parallel via `Task` (one per dim):
98
132
 
99
- If continue, dispatch flow-planner (mirroring the Task call in `/curdx-flow:tasks`).
133
+ | Dim | Agent | Focus |
134
+ |-----|-------|-------|
135
+ | `ceo` | `flow-architect` (review mode) | Strategic: scope fit, ROI, opportunity cost |
136
+ | `eng` | `flow-architect` (review mode) | Engineering: architecture lock-in, risk, technical debt |
137
+ | `design` | `flow-ux-designer` | UX / UI / accessibility / design system |
138
+ | `dx` | `flow-architect` (review mode) | Developer experience: naming, comments, structure, error handling, setup, types, tests, dev loop |
100
139
 
101
- ## Step 4: Final summary
140
+ 4. Aggregate findings into `.flow/specs/<active>/spec-review.md` with one section per dim and a consolidated verdict (GO / GO-WITH-CHANGES / HOLD).
141
+
142
+ ## Reporting
143
+
144
+ Final console output:
102
145
 
103
146
  ```
104
- ═══════════════════════════════════════════════
105
- Full spec generated: $SPEC_NAME
106
-
107
- Output files:
108
- .flow/specs/$SPEC_NAME/research.md (N lines)
109
- .flow/specs/$SPEC_NAME/requirements.md (M lines)
110
- .flow/specs/$SPEC_NAME/design.md (K lines)
111
- .flow/specs/$SPEC_NAME/tasks.md (L lines)
112
-
113
- Stats:
114
- Research: 2-3 technical options, context7 queried X libraries
115
- Requirements: P US, Q FR, R AC
116
- Design: S AD, T components
117
- Tasks: U tasks (fine / coarse)
118
-
119
- Next steps:
120
- - Review all 4 files
121
- - To modify, run /curdx-flow:research / /curdx-flow:requirements / ... individually
122
- - After Phase 2 ships: /curdx-flow:implement
147
+ ✓ Spec <name> refreshed
148
+ Phases run: research, requirements, design, tasks
149
+ Review dims: ceo, eng, design, dx (if --review was used)
150
+ Files:
151
+ .flow/specs/<name>/research.md
152
+ .flow/specs/<name>/requirements.md
153
+ .flow/specs/<name>/design.md
154
+ .flow/specs/<name>/tasks.md
155
+ .flow/specs/<name>/spec-review.md (if --review was used)
156
+
157
+ Next: /curdx-flow:implement
123
158
  ```
124
159
 
125
- ## Auto mode (/curdx-flow:spec --yolo)
126
-
127
- If the user passes `--yolo`, all intermediate confirmations default to `continue`, running through in one pass.
160
+ ## Common invocations
128
161
 
129
- **Warning**: yolo mode may run to completion but not necessarily match the user's intent. Recommend using it only on sketch / fast projects.
162
+ ```
163
+ /curdx-flow:spec # full spec from current state
164
+ /curdx-flow:spec --phase=design # re-run only design (e.g., after requirements changed)
165
+ /curdx-flow:spec --phase=design,tasks # re-run design and tasks
166
+ /curdx-flow:spec --until=design # run up through design, stop (human review checkpoint)
167
+ /curdx-flow:spec --review # full spec + all 4 planning dimensions
168
+ /curdx-flow:spec --review=eng,dx # full spec + engineering + DX review only
169
+ /curdx-flow:spec --regenerate # clear all four phases and rebuild
170
+ /curdx-flow:spec --regenerate --phase=tasks # only rebuild tasks (keep research/requirements/design)
171
+ ```
130
172
 
131
- ## Error recovery
173
+ ## References
132
174
 
133
- - A stage fails stop without advancing; after manual fixes the user can re-run /curdx-flow:<phase>
134
- - User chooses abort → preserve generated files, but do not advance phase_status
135
- - sequential-thinking / context7 requirements at every stage match the per-command definitions
175
+ - Agents: `@${CLAUDE_PLUGIN_ROOT}/agents/flow-researcher.md`, `flow-product-designer.md`, `flow-architect.md`, `flow-planner.md`, `flow-ux-designer.md`
176
+ - Knowledge: `@${CLAUDE_PLUGIN_ROOT}/knowledge/spec-driven-development.md`, `poc-first-workflow.md`
177
+ - Preamble: `@${CLAUDE_PLUGIN_ROOT}/agent-preamble/preamble.md`