Skip to content
This repository was archived by the owner on Apr 11, 2026. It is now read-only.

Commit cf99bb0

Browse files
authored
Merge pull request #18 from z23cc/fn-104-flatten-workflow-stepphase-numbering-to
refactor: flatten workflow phase/step numbering to sequential integers
2 parents 6461794 + cdb5bff commit cf99bb0

18 files changed

Lines changed: 370 additions & 344 deletions

File tree

CLAUDE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Rust: clippy for linting, cargo test for tests. No TypeScript, no npm. Skills an
8585
- **Review comparison**: `flowctl review-backend --compare <files>` or `--epic <id>` detects consensus/conflict across review receipts (auto-archived to `.flow/reviews/`)
8686
- **Domain tagging**: `flowctl task create --domain <domain>` tags tasks (frontend/backend/architecture/testing/docs/ops/general), filterable via `tasks --domain`
8787
- **Epic archival**: `flowctl epic archive <id>` moves closed epic + tasks + specs + reviews to `.flow/.archive/`; `flowctl epic clean` archives all closed epics at once
88-
- **Learning loop**: plan injects memory (Step 1b), worker saves lessons (Phase 5b, included in default sequence when memory.enabled is true), epic close prompts retro, retro verifies stale entries via `flowctl memory verify <id>`
88+
- **Learning loop**: plan injects memory (Step 6), worker saves lessons (Phase 11, included in default sequence when memory.enabled is true), epic close prompts retro, retro verifies stale entries via `flowctl memory verify <id>`
8989
- **Task duration**: `flowctl done` auto-tracks `duration_seconds` from start to completion, rendered in evidence
9090
- **File ownership**: `flowctl task create --files <paths>` declares owned files; `flowctl files --epic <id>` shows ownership map + conflict detection
9191
- **File locking (Teams)**: `flowctl lock --task <id> --files <paths>` acquires runtime file locks; `flowctl unlock --task <id>` releases on completion; `flowctl lock-check --file <path>` inspects lock state; `flowctl unlock --all` clears all locks between waves
@@ -95,9 +95,9 @@ Rust: clippy for linting, cargo test for tests. No TypeScript, no npm. Skills an
9595
- **Review circuit breaker**: impl-review fix loop capped at `MAX_REVIEW_ITERATIONS` (default 3) — prevents infinite NEEDS_WORK cycles
9696
- **Auto-improve analysis-driven**: generates custom program.md from codebase analysis (hotspots, lint, coverage, memory) with Action Catalog ranked by impact — not static templates
9797
- **Auto-improve quantitative**: captures before/after metrics per experiment, commit messages include delta `[lint:23→21]`
98-
- **Worker self-review**: Phase 2.5 runs guard + structured diff review (correctness, quality, performance, testing) before commit
98+
- **Worker self-review**: Phase 6 runs guard + structured diff review (correctness, quality, performance, testing) before commit
9999
- **Plan auto-execute**: `/flow-code:plan` defaults to auto-execute work after planning (Teams mode handles any task count); `--plan-only` to opt out
100-
- **Goal-backward verification**: worker Phase 5 re-reads acceptance criteria and verifies each is actually satisfied before completing
100+
- **Goal-backward verification**: worker Phase 10 re-reads acceptance criteria and verifies each is actually satisfied before completing
101101
- **Full-auto by default**: `/flow-code:plan` and `/flow-code:work` require zero interactive questions — AI reads git state, `.flow/` config, and request context to make branch, review, and research decisions autonomously. Default mode is Worktree + Teams + Phase-Gate (all three active). Work resumes from `.flow/` state on every startup (not a special "resume mode"). All tasks done → auto push + draft PR (`--no-pr` to skip)
102102
- **Cross-platform**: flowctl is a single Rust binary (macOS/Linux). RP plan-review auto-degrades to Codex on platforms where rp-cli is unavailable. Bash hooks degrade gracefully on Windows (skip, don't block)
103103
- **Session start**: CLAUDE.md instruction (not an enforced hook) — if `.flow/` exists, run `flowctl status --interrupted` to check for unfinished work from a previous session and resume with the suggested `/flow-code:work <id>` command

agents/worker.md

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ You implement a single flow-code task. Your prompt contains configuration values
2020
- `FLOWCTL` - path to flowctl CLI
2121
- `REVIEW_MODE` - none, rp, or codex
2222
- `RALPH_MODE` - true if running autonomously
23-
- `TDD_MODE` - true to enforce test-first development (Phase 2a)
24-
- `RP_CONTEXT` - mcp, cli, or none (controls RP-powered context gathering in Phase 1.5)
23+
- `TDD_MODE` - true to enforce test-first development (Phase 4)
24+
- `RP_CONTEXT` - mcp, cli, or none (controls RP-powered context gathering in Phase 3)
2525

2626
## Environment
2727

@@ -38,7 +38,7 @@ You execute phases one at a time via flowctl commands.
3838
4. Run: `$FLOWCTL worker-phase done --task $TASK_ID --phase <N> --json`
3939
5. Repeat from step 1 until response has `all_done: true`
4040

41-
Do NOT skip phases. Do NOT execute phases out of order. The gate enforces sequential execution — attempting to complete phase 3 before phase 2 will be rejected.
41+
Do NOT skip phases. Do NOT execute phases out of order. The gate enforces sequential execution — attempting to complete phase 5 before phase 4 will be rejected.
4242
<!-- /section:core -->
4343

4444
<!-- section:team -->
@@ -129,7 +129,7 @@ After `flowctl done`, send a `task_complete` message, then wait for next assignm
129129
<!-- /section:team -->
130130

131131
<!-- section:team -->
132-
## Phase 0: Verify Configuration (CRITICAL)
132+
## Phase 1: Verify Configuration (CRITICAL)
133133

134134
**If TEAM_MODE is `true`:**
135135

@@ -139,7 +139,7 @@ After `flowctl done`, send a `task_complete` message, then wait for next assignm
139139
SendMessage(to: "coordinator", summary: "Blocked: <TASK_ID>",
140140
message: "Task <TASK_ID> is blocked.\nReason: TEAM_MODE=true but OWNED_FILES is empty or missing.\nBlocked by: orchestrator configuration error")
141141
```
142-
- Do NOT proceed to Phase 1
142+
- Do NOT proceed to Phase 2
143143
144144
2. **Verify TASK_ID matches prompt**
145145
- Confirm the `TASK_ID` from your prompt matches what `flowctl show` returns
@@ -148,11 +148,11 @@ After `flowctl done`, send a `task_complete` message, then wait for next assignm
148148
3. **Log owned files for audit trail**
149149
- Print `OWNED_FILES: <file1>, <file2>, ...` so the conversation log captures your ownership set
150150
151-
**If TEAM_MODE is not set or `false`:** proceed directly to Phase 1 (unrestricted file access).
151+
**If TEAM_MODE is not set or `false`:** proceed directly to Phase 2 (unrestricted file access).
152152
<!-- /section:team -->
153153
154154
<!-- section:core -->
155-
## Phase 1: Re-anchor (CRITICAL - DO NOT SKIP)
155+
## Phase 2: Re-anchor (CRITICAL - DO NOT SKIP)
156156
157157
Use the FLOWCTL path and IDs from your prompt:
158158
@@ -217,13 +217,13 @@ GIT_BASELINE_REV=$(git rev-parse HEAD)
217217
echo "GIT_BASELINE_REV=$GIT_BASELINE_REV"
218218
git diff --stat HEAD 2>/dev/null || true
219219
```
220-
Save `GIT_BASELINE_REV` — you'll use it in Phase 5 to generate workspace change evidence.
220+
Save `GIT_BASELINE_REV` — you'll use it in Phase 10 to generate workspace change evidence.
221221
<!-- /section:core -->
222222

223223
<!-- section:core -->
224-
## Phase 1.5: Pre-implementation Investigation
224+
## Phase 3: Pre-implementation Investigation
225225

226-
**If the task spec contains `## Investigation targets` with content, execute this phase. Otherwise skip to Phase 2a/2.**
226+
**If the task spec contains `## Investigation targets` with content, execute this phase. Otherwise skip to Phase 4/5.**
227227

228228
### Step 0: RP-powered deep context (if RP_CONTEXT != none)
229229

@@ -237,15 +237,15 @@ IF RP_CONTEXT == "mcp":
237237
Timeout: 120 seconds. If context_builder does not return within 120s, log:
238238
"RP context_builder timed out after 120s, using built-in fallback"
239239
and skip to Step 1.
240-
Use the returned plan to guide Phase 2 implementation.
240+
Use the returned plan to guide Phase 5 implementation.
241241
242242
ELIF RP_CONTEXT == "cli":
243243
Run with 120s timeout:
244244
timeout 120 rp-cli -e 'builder "<task title>: <description + acceptance criteria>" --response-type plan'
245245
If timeout or failure, log:
246246
"rp-cli builder timed out or failed, using built-in fallback"
247247
and skip to Step 1.
248-
Use the returned plan to guide Phase 2 implementation.
248+
Use the returned plan to guide Phase 5 implementation.
249249
250250
ELSE (RP_CONTEXT == "none"):
251251
Skip to Step 1 (existing behavior, unchanged).
@@ -286,11 +286,11 @@ END
286286

287287
3. Read **Optional** files as needed based on Step 1 findings.
288288

289-
4. Continue to Phase 2a/2 only after investigation is complete.
289+
4. Continue to Phase 4/5 only after investigation is complete.
290290
<!-- /section:core -->
291291

292292
<!-- section:tdd -->
293-
## Phase 2a: TDD Red-Green (if TDD_MODE=true)
293+
## Phase 4: TDD Red-Green (if TDD_MODE=true)
294294

295295
**Skip this phase if TDD_MODE is not `true`.**
296296

@@ -303,15 +303,15 @@ Before implementing the feature, write failing tests first:
303303
```
304304
If tests pass already, the feature may already be implemented. Investigate before proceeding.
305305

306-
2. **Green** — Now implement the minimum code to make tests pass (this IS Phase 2).
306+
2. **Green** — Now implement the minimum code to make tests pass (this IS Phase 5).
307307

308308
3. **Refactor** — After tests pass, clean up without changing behavior. Run tests again to confirm still green.
309309

310310
The key constraint: **no implementation code before a failing test exists**. This ensures every change is test-driven.
311311
<!-- /section:tdd -->
312312

313313
<!-- section:core -->
314-
## Phase 2: Implement
314+
## Phase 5: Implement
315315

316316
**First, capture base commit for scoped review:**
317317
```bash
@@ -401,7 +401,7 @@ If during implementation you discover the spec is wrong, incomplete, or contradi
401401
- What the spec says vs what reality requires
402402
- Why the spec approach won't work
403403
- A suggested correction (if you have one)
404-
3. **Return early** with status `SPEC_CONFLICT` in your Phase 6 summary
404+
3. **Return early** with status `SPEC_CONFLICT` in your Phase 12 summary
405405
4. Do NOT mark the task as done — leave it `in_progress`
406406
407407
The main conversation will resolve the conflict and re-dispatch you (or update the spec).
@@ -414,7 +414,7 @@ The main conversation will resolve the conflict and re-dispatch you (or update t
414414
<!-- /section:core -->
415415
416416
<!-- section:core -->
417-
## Phase 2.3: Plan Alignment Check
417+
### Plan Alignment Check
418418
419419
Quick sanity check — did implementation stay within plan scope?
420420
@@ -431,11 +431,11 @@ Quick sanity check — did implementation stay within plan scope?
431431
Drift: <description of what changed and why>
432432
```
433433

434-
**This is a 30-second check, not a full re-review.** Read the spec, glance at your diff, note any drift. Then proceed to Phase 2.5.
434+
**This is a 30-second check, not a full re-review.** Read the spec, glance at your diff, note any drift. Then proceed to Phase 6.
435435
<!-- /section:core -->
436436

437437
<!-- section:core -->
438-
## Phase 2.5: Verify & Fix
438+
## Phase 6: Verify & Fix
439439

440440
**After implementing, before committing — verify your code works. This is normal development: implement → test → fix → retest → pass → commit.**
441441

@@ -451,7 +451,7 @@ Continue until guard passes. There is no retry limit — this is not a retry loo
451451

452452
**If the failure is not a code bug but a spec problem** (e.g., spec asks for something impossible, acceptance criteria contradict each other, required API doesn't exist):
453453
- Do NOT keep trying to fix code
454-
- Return early with `SPEC_CONFLICT` status (see Phase 2 spec conflict protocol)
454+
- Return early with `SPEC_CONFLICT` status (see Phase 5 spec conflict protocol)
455455
- In Teams mode, send a `Spec conflict` message to the coordinator
456456
457457
**Teams mode constraint:** When `TEAM_MODE=true`, only fix files in `OWNED_FILES`. If the failure is caused by a file you don't own, request access via `flowctl approval create --kind file_access` + `approval show --wait` (or fallback `Need file access:` SendMessage), then wait for a resolution. If access is rejected or times out, note the issue in your completion summary.
@@ -473,11 +473,11 @@ If you find issues, fix them and re-run `<FLOWCTL> guard` to verify.
473473

474474
**Rules:**
475475
- Only fix issues in YOUR changes — don't refactor unrelated code
476-
- If unsure whether something is an issue, leave it for Phase 4 (external review)
476+
- If unsure whether something is an issue, leave it for Phase 8 (external review)
477477
<!-- /section:core -->
478478
479479
<!-- section:core -->
480-
## Phase 3: Commit
480+
## Phase 7: Commit
481481
482482
```bash
483483
git add -A
@@ -493,9 +493,9 @@ Use conventional commits. Scope from task context.
493493
<!-- /section:core -->
494494
495495
<!-- section:review -->
496-
## Phase 4: Review (MANDATORY if REVIEW_MODE != none)
496+
## Phase 8: Review (MANDATORY if REVIEW_MODE != none)
497497
498-
**If REVIEW_MODE is `none`, skip to Phase 5.**
498+
**If REVIEW_MODE is `none`, skip to Phase 10.**
499499
500500
**If REVIEW_MODE is `rp` or `codex`, you MUST invoke impl-review and receive SHIP before proceeding.**
501501
@@ -520,13 +520,13 @@ If NEEDS_WORK:
520520
3. Commit fixes
521521
4. Re-invoke the skill: `/flow-code:impl-review <TASK_ID> --base $BASE_COMMIT`
522522

523-
Continue until SHIP verdict. Save final `REVIEW_ITERATIONS` count for Phase 5 evidence.
523+
Continue until SHIP verdict. Save final `REVIEW_ITERATIONS` count for Phase 10 evidence.
524524
<!-- /section:review -->
525525

526526
<!-- section:core -->
527-
## Phase 5: Complete
527+
## Phase 10: Complete
528528

529-
**Prerequisite:** Phase 5c (Outputs Dump) must have run if `outputs.enabled=true`. The phase registry orders 5c before 5 so the narrative handoff file exists before dependents unblock.
529+
**Prerequisite:** Phase 9 (Outputs Dump) must have run if `outputs.enabled=true`. The phase registry orders 9 before 10 so the narrative handoff file exists before dependents unblock.
530530

531531
**Verify before completing:**
532532
```bash
@@ -547,7 +547,7 @@ Go through each `- [ ]` acceptance criterion in the spec:
547547

548548
**Rules:**
549549
- This is a 1-minute sanity check, not a full re-review
550-
- Only check acceptance criteria, not general quality (Phase 2.5 already did that)
550+
- Only check acceptance criteria, not general quality (Phase 6 already did that)
551551
- If you discover a gap, fix + commit + re-run guard
552552
- If you discover the criterion is impossible, note it in the summary (not SPEC_CONFLICT at this stage)
553553

@@ -556,7 +556,7 @@ Capture the commit hash:
556556
COMMIT_HASH=$(git rev-parse HEAD)
557557
```
558558

559-
Capture workspace changes (compare against Phase 1 baseline):
559+
Capture workspace changes (compare against Phase 2 baseline):
560560
```bash
561561
# Generate workspace change summary
562562
DIFF_STAT=$(git diff --stat "$GIT_BASELINE_REV"..HEAD 2>/dev/null || echo "no diff")
@@ -574,7 +574,7 @@ EOF
574574

575575
**If a review was done (REVIEW_MODE != none)**, append the review receipt to evidence so it gets auto-archived:
576576
```bash
577-
# Only if RECEIPT_PATH exists from Phase 4
577+
# Only if RECEIPT_PATH exists from Phase 8
578578
if [ -f "${RECEIPT_PATH:-/tmp/impl-review-receipt.json}" ]; then
579579
# Merge review_receipt into evidence JSON
580580
python3 -c "
@@ -610,9 +610,9 @@ Status MUST be `done`. If not:
610610
<!-- /section:core -->
611611

612612
<!-- section:outputs -->
613-
## Phase 5c: Outputs Dump (if outputs.enabled)
613+
## Phase 9: Outputs Dump (if outputs.enabled)
614614

615-
**Runs BEFORE Phase 5 completion.** Phase 5c must produce the handoff artifact before `flowctl done` fires, otherwise a dependent task can start re-anchoring and race past the missing file. The phase registry in `flowctl-cli/src/commands/workflow/phase.rs` enforces this ordering (5c before 5).
615+
**Runs BEFORE Phase 10 completion.** Phase 9 must produce the handoff artifact before `flowctl done` fires, otherwise a dependent task can start re-anchoring and race past the missing file. The phase registry in `flowctl-cli/src/commands/workflow/phase.rs` enforces this ordering (9 before 10).
616616

617617
**Skip if `outputs.enabled` is false.** This is gated on its own config key — independent from `memory.enabled`. Outputs are a lightweight narrative handoff layer (plain markdown, no verification), separate from the verified memory system.
618618

@@ -645,18 +645,18 @@ fi
645645
- All three sections are allowed to be missing or empty — downstream readers handle that gracefully
646646
- Focus on narrative handoff: what would help the next worker, not comprehensive docs
647647
- Don't repeat spec content — only things you learned while working
648-
- This is narrative handoff, NOT verified memory. Save verified pitfalls/conventions in Phase 5b.
648+
- This is narrative handoff, NOT verified memory. Save verified pitfalls/conventions in Phase 11.
649649
<!-- /section:outputs -->
650650
651651
<!-- section:memory -->
652-
## Phase 5b: Memory Auto-Save (if memory enabled)
652+
## Phase 11: Memory Auto-Save (if memory enabled)
653653
654-
**Skip if memory.enabled is false or was not checked in Phase 1.**
654+
**Skip if memory.enabled is false or was not checked in Phase 2.**
655655
656656
After completing the task, capture any non-obvious lessons learned:
657657
658658
```bash
659-
# Check if memory is enabled (already checked in Phase 1)
659+
# Check if memory is enabled (already checked in Phase 2)
660660
<FLOWCTL> config get memory.enabled --json
661661
```
662662
@@ -686,7 +686,7 @@ If enabled, reflect on what you discovered during implementation and save **only
686686
<!-- /section:memory -->
687687
688688
<!-- section:core -->
689-
## Phase 6: Return
689+
## Phase 12: Return
690690
691691
Return a concise summary to the main conversation:
692692
- What was implemented (1-2 sentences)

0 commit comments

Comments
 (0)