feat: pre-compute wave numbers at plan time
Wave numbers now computed during plan-phase and stored in PLAN.md frontmatter. Execute-phase reads wave directly instead of deriving from depends_on at runtime. - Add assign_waves step to plan-phase workflow - Add wave field to frontmatter (plan-format, phase-prompt template) - Simplify execute-phase: remove analyze_dependencies and group_into_waves - Replace with group_by_wave that just reads frontmatter integers Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -68,68 +68,50 @@ ls -1 "$PHASE_DIR"/*-SUMMARY.md 2>/dev/null | sort
|
||||
```
|
||||
|
||||
For each plan, read frontmatter to extract:
|
||||
- `depends_on: []` - Plan IDs this plan requires
|
||||
- `files_modified: []` - Files this plan touches
|
||||
- `wave: N` - Execution wave (pre-computed)
|
||||
- `autonomous: true/false` - Whether plan has checkpoints
|
||||
|
||||
Build plan inventory:
|
||||
- Plan path
|
||||
- Plan ID (e.g., "03-01")
|
||||
- Dependencies
|
||||
- Files modified
|
||||
- Wave number
|
||||
- Autonomous flag
|
||||
- Completion status (SUMMARY exists = complete)
|
||||
|
||||
Skip completed plans. If all complete, report "Phase already executed" and exit.
|
||||
</step>
|
||||
|
||||
<step name="analyze_dependencies">
|
||||
Build dependency graph from frontmatter:
|
||||
<step name="group_by_wave">
|
||||
Read `wave` from each plan's frontmatter and group by wave number:
|
||||
|
||||
**Direct dependencies:**
|
||||
- `depends_on: ["03-01"]` → this plan depends on 03-01
|
||||
|
||||
**File conflict dependencies:**
|
||||
- If two plans modify same file, later plan (by number) depends on earlier
|
||||
|
||||
**Build graph:**
|
||||
```bash
|
||||
# For each plan, extract wave from frontmatter
|
||||
for plan in $PHASE_DIR/*-PLAN.md; do
|
||||
wave=$(grep "^wave:" "$plan" | cut -d: -f2 | tr -d ' ')
|
||||
autonomous=$(grep "^autonomous:" "$plan" | cut -d: -f2 | tr -d ' ')
|
||||
echo "$plan:$wave:$autonomous"
|
||||
done
|
||||
```
|
||||
plan-01: {deps: [], files: [src/user.ts], autonomous: true}
|
||||
plan-02: {deps: [], files: [src/product.ts], autonomous: true}
|
||||
plan-03: {deps: ["plan-01"], files: [src/dashboard.tsx], autonomous: false}
|
||||
plan-04: {deps: ["plan-02"], files: [src/cart.ts], autonomous: true}
|
||||
plan-05: {deps: ["plan-03", "plan-04"], files: [src/checkout.ts], autonomous: true}
|
||||
|
||||
**Group plans:**
|
||||
```
|
||||
</step>
|
||||
|
||||
<step name="group_into_waves">
|
||||
Group plans into execution waves based on dependencies:
|
||||
|
||||
**Wave assignment algorithm:**
|
||||
1. Wave 1: All plans with no dependencies AND autonomous=true
|
||||
2. Non-autonomous plans with no dependencies: execute after Wave 1, before Wave 2
|
||||
3. Wave N: Plans whose dependencies are all in earlier waves
|
||||
|
||||
**Separate checkpoint plans:**
|
||||
Plans with `autonomous: false` execute in main context (not parallel subagent) to handle user interaction.
|
||||
|
||||
**Example:**
|
||||
```
|
||||
Wave 1 (parallel): [plan-01, plan-02]
|
||||
Checkpoint: [plan-03] - has human-verify, runs in main context
|
||||
Wave 2 (parallel): [plan-04]
|
||||
Wave 3: [plan-05]
|
||||
waves = {
|
||||
1: [plan-01, plan-02],
|
||||
2: [plan-03, plan-04],
|
||||
3: [plan-05]
|
||||
}
|
||||
```
|
||||
|
||||
**No dependency analysis needed.** Wave numbers are pre-computed during `/gsd:plan-phase`.
|
||||
|
||||
Report wave structure to user:
|
||||
```
|
||||
Execution Plan:
|
||||
Wave 1 (parallel): 03-01, 03-02
|
||||
Checkpoint: 03-03 (requires user verification)
|
||||
Wave 2 (parallel): 03-04
|
||||
Wave 2 (parallel): 03-03 [checkpoint], 03-04
|
||||
Wave 3: 03-05
|
||||
|
||||
Total: 5 plans in 3 waves + 1 checkpoint
|
||||
Total: 5 plans in 3 waves
|
||||
```
|
||||
</step>
|
||||
|
||||
|
||||
@@ -367,6 +367,37 @@ For each plan, determine:
|
||||
- `autonomous: true|false` - has checkpoints requiring user interaction?
|
||||
</step>
|
||||
|
||||
<step name="assign_waves">
|
||||
**Compute wave numbers before writing plans.**
|
||||
|
||||
Wave assignment algorithm (run in memory before writing any files):
|
||||
|
||||
```
|
||||
waves = {} # plan_id -> wave_number
|
||||
|
||||
for each plan in plan_order:
|
||||
if plan.depends_on is empty:
|
||||
plan.wave = 1
|
||||
else:
|
||||
# Wave = max wave of dependencies + 1
|
||||
plan.wave = max(waves[dep] for dep in plan.depends_on) + 1
|
||||
|
||||
waves[plan.id] = plan.wave
|
||||
```
|
||||
|
||||
**Example:**
|
||||
|
||||
```
|
||||
Plan 01: depends_on: [] → wave: 1
|
||||
Plan 02: depends_on: [] → wave: 1
|
||||
Plan 03: depends_on: ["01"] → wave: 2
|
||||
Plan 04: depends_on: ["02"] → wave: 2
|
||||
Plan 05: depends_on: ["03", "04"] → wave: 3
|
||||
```
|
||||
|
||||
Store wave number with each plan in memory. Write to frontmatter in next step.
|
||||
</step>
|
||||
|
||||
<step name="group_into_plans">
|
||||
**Group tasks into plans based on dependency waves and autonomy.**
|
||||
|
||||
@@ -521,14 +552,15 @@ Each plan follows template structure with:
|
||||
phase: XX-name
|
||||
plan: NN
|
||||
type: execute
|
||||
depends_on: [] # Plan IDs this plan requires. Empty = Wave 1 candidate.
|
||||
files_modified: [] # Files this plan touches. Used for conflict detection.
|
||||
wave: N # Execution wave (1, 2, 3...). Computed at plan time.
|
||||
depends_on: [] # Plan IDs this plan requires.
|
||||
files_modified: [] # Files this plan touches.
|
||||
autonomous: true # false if plan has checkpoints requiring user interaction
|
||||
domain: [optional]
|
||||
---
|
||||
```
|
||||
|
||||
**Wave assignment is automatic:** `/gsd:execute-phase` reads `depends_on` to build waves. Plans with empty `depends_on` and no file conflicts run in Wave 1 (parallel).
|
||||
**Wave is pre-computed:** Wave numbers are assigned during planning (see `assign_waves` step). `/gsd:execute-phase` reads `wave` directly from frontmatter and groups plans by wave number. No runtime dependency analysis needed.
|
||||
|
||||
**Context section - parallel-aware:**
|
||||
|
||||
|
||||
Reference in New Issue
Block a user