planflow-ai 1.3.5 → 1.4.3
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.
- package/.claude/commands/brainstorm.md +6 -14
- package/.claude/commands/create-contract.md +6 -38
- package/.claude/commands/create-plan.md +18 -38
- package/.claude/commands/discovery-plan.md +19 -49
- package/.claude/commands/execute-plan.md +116 -77
- package/.claude/commands/flow.md +27 -2
- package/.claude/commands/heartbeat.md +12 -14
- package/.claude/commands/learn.md +20 -80
- package/.claude/commands/note.md +6 -23
- package/.claude/commands/resume-work.md +261 -0
- package/.claude/commands/review-code.md +19 -51
- package/.claude/commands/review-pr.md +21 -57
- package/.claude/commands/setup.md +8 -56
- package/.claude/commands/write-tests.md +7 -41
- package/.claude/resources/core/atomic-commits.md +380 -0
- package/.claude/resources/core/autopilot-mode.md +3 -2
- package/.claude/resources/core/compaction-guide.md +15 -1
- package/.claude/resources/core/heartbeat.md +129 -1
- package/.claude/resources/core/per-task-verification.md +362 -0
- package/.claude/resources/core/phase-isolation.md +237 -4
- package/.claude/resources/core/session-scratchpad.md +1 -0
- package/.claude/resources/core/shared-context.md +110 -0
- package/.claude/resources/core/wave-execution.md +407 -0
- package/.claude/resources/patterns/plans-patterns.md +56 -0
- package/.claude/resources/patterns/plans-templates.md +152 -0
- package/.claude/resources/skills/create-plan-skill.md +71 -5
- package/.claude/resources/skills/execute-plan-skill.md +420 -14
- package/.claude/resources/skills/resume-work-skill.md +159 -0
- package/README.md +154 -96
- package/dist/cli/commands/brain.d.ts +20 -0
- package/dist/cli/commands/brain.d.ts.map +1 -0
- package/dist/cli/commands/brain.js +127 -0
- package/dist/cli/commands/brain.js.map +1 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +10 -1
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/state-query.d.ts +13 -0
- package/dist/cli/commands/state-query.d.ts.map +1 -0
- package/dist/cli/commands/state-query.js +32 -0
- package/dist/cli/commands/state-query.js.map +1 -0
- package/dist/cli/commands/state.d.ts +12 -0
- package/dist/cli/commands/state.d.ts.map +1 -0
- package/dist/cli/commands/state.js +47 -0
- package/dist/cli/commands/state.js.map +1 -0
- package/dist/cli/daemon/desktop-notifier.d.ts +16 -0
- package/dist/cli/daemon/desktop-notifier.d.ts.map +1 -0
- package/dist/cli/daemon/desktop-notifier.js +53 -0
- package/dist/cli/daemon/desktop-notifier.js.map +1 -0
- package/dist/cli/daemon/event-writer.d.ts +22 -0
- package/dist/cli/daemon/event-writer.d.ts.map +1 -0
- package/dist/cli/daemon/event-writer.js +76 -0
- package/dist/cli/daemon/event-writer.js.map +1 -0
- package/dist/cli/daemon/heartbeat-daemon.js +81 -1
- package/dist/cli/daemon/heartbeat-daemon.js.map +1 -1
- package/dist/cli/daemon/log-writer.d.ts +17 -0
- package/dist/cli/daemon/log-writer.d.ts.map +1 -0
- package/dist/cli/daemon/log-writer.js +62 -0
- package/dist/cli/daemon/log-writer.js.map +1 -0
- package/dist/cli/daemon/notification-router.d.ts +17 -0
- package/dist/cli/daemon/notification-router.d.ts.map +1 -0
- package/dist/cli/daemon/notification-router.js +35 -0
- package/dist/cli/daemon/notification-router.js.map +1 -0
- package/dist/cli/daemon/prompt-manager.d.ts +27 -0
- package/dist/cli/daemon/prompt-manager.d.ts.map +1 -0
- package/dist/cli/daemon/prompt-manager.js +107 -0
- package/dist/cli/daemon/prompt-manager.js.map +1 -0
- package/dist/cli/daemon/shared-context.d.ts +38 -0
- package/dist/cli/daemon/shared-context.d.ts.map +1 -0
- package/dist/cli/daemon/shared-context.js +129 -0
- package/dist/cli/daemon/shared-context.js.map +1 -0
- package/dist/cli/handlers/claude.d.ts.map +1 -1
- package/dist/cli/handlers/claude.js +18 -0
- package/dist/cli/handlers/claude.js.map +1 -1
- package/dist/cli/handlers/shared.js +1 -1
- package/dist/cli/handlers/shared.js.map +1 -1
- package/dist/cli/index.js +30 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/state/brain-query.d.ts +48 -0
- package/dist/cli/state/brain-query.d.ts.map +1 -0
- package/dist/cli/state/brain-query.js +113 -0
- package/dist/cli/state/brain-query.js.map +1 -0
- package/dist/cli/state/flowconfig-parser.d.ts +16 -0
- package/dist/cli/state/flowconfig-parser.d.ts.map +1 -0
- package/dist/cli/state/flowconfig-parser.js +166 -0
- package/dist/cli/state/flowconfig-parser.js.map +1 -0
- package/dist/cli/state/heartbeat-state.d.ts +16 -0
- package/dist/cli/state/heartbeat-state.d.ts.map +1 -0
- package/dist/cli/state/heartbeat-state.js +97 -0
- package/dist/cli/state/heartbeat-state.js.map +1 -0
- package/dist/cli/state/model-router.d.ts +8 -0
- package/dist/cli/state/model-router.d.ts.map +1 -0
- package/dist/cli/state/model-router.js +36 -0
- package/dist/cli/state/model-router.js.map +1 -0
- package/dist/cli/state/plan-parser.d.ts +16 -0
- package/dist/cli/state/plan-parser.d.ts.map +1 -0
- package/dist/cli/state/plan-parser.js +124 -0
- package/dist/cli/state/plan-parser.js.map +1 -0
- package/dist/cli/state/session-state.d.ts +21 -0
- package/dist/cli/state/session-state.d.ts.map +1 -0
- package/dist/cli/state/session-state.js +36 -0
- package/dist/cli/state/session-state.js.map +1 -0
- package/dist/cli/state/state-md-parser.d.ts +18 -0
- package/dist/cli/state/state-md-parser.d.ts.map +1 -0
- package/dist/cli/state/state-md-parser.js +222 -0
- package/dist/cli/state/state-md-parser.js.map +1 -0
- package/dist/cli/state/types.d.ts +137 -0
- package/dist/cli/state/types.d.ts.map +1 -0
- package/dist/cli/state/types.js +8 -0
- package/dist/cli/state/types.js.map +1 -0
- package/dist/cli/state/wave-calculator.d.ts +18 -0
- package/dist/cli/state/wave-calculator.d.ts.map +1 -0
- package/dist/cli/state/wave-calculator.js +134 -0
- package/dist/cli/state/wave-calculator.js.map +1 -0
- package/dist/cli/types.d.ts +15 -0
- package/dist/cli/types.d.ts.map +1 -1
- package/package.json +7 -2
- package/templates/shared/CLAUDE.md.template +4 -0
- package/.claude/resources/core/_index.md +0 -304
- package/.claude/resources/languages/_index.md +0 -76
- package/.claude/resources/patterns/_index.md +0 -200
- package/.claude/resources/skills/_index.md +0 -285
- package/.claude/resources/tools/_index.md +0 -110
- package/.claude/resources/tools/reference-expansion-tool.md +0 -326
|
@@ -7,10 +7,16 @@ When `phase_isolation: true` in `flow/.flowconfig` (default), each `/execute-pla
|
|
|
7
7
|
|
|
8
8
|
**Core principle**: Clean context in, structured summary out.
|
|
9
9
|
|
|
10
|
+
### Per-Task Verification
|
|
11
|
+
|
|
12
|
+
Phase sub-agents support **per-task verification** when plan tasks include `<verify>` tags. After completing each task, the sub-agent runs the verification command and, on failure, spawns a debug sub-agent (haiku) for diagnosis and repair. See `.claude/resources/core/per-task-verification.md` for the complete verification system, debug sub-agent prompt template, JSON schemas, and configuration.
|
|
13
|
+
|
|
10
14
|
---
|
|
11
15
|
|
|
12
16
|
## Architecture
|
|
13
17
|
|
|
18
|
+
### Sequential Mode (default)
|
|
19
|
+
|
|
14
20
|
```
|
|
15
21
|
Coordinator (main session)
|
|
16
22
|
│
|
|
@@ -35,6 +41,40 @@ Coordinator (main session)
|
|
|
35
41
|
└─ Next phase...
|
|
36
42
|
```
|
|
37
43
|
|
|
44
|
+
### Wave Mode (when `wave_execution: true`)
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
Coordinator (main session)
|
|
48
|
+
│
|
|
49
|
+
├─ For each Wave:
|
|
50
|
+
│ │
|
|
51
|
+
│ ├─ Approve each phase sequentially in Plan Mode
|
|
52
|
+
│ │
|
|
53
|
+
│ ├─ Prepare isolated context for EACH phase in the wave
|
|
54
|
+
│ │
|
|
55
|
+
│ ├─ Spawn MULTIPLE Agent sub-agents IN PARALLEL:
|
|
56
|
+
│ │ ├─► Agent: Phase A (model: [tier_A], prompt: phase_A_context)
|
|
57
|
+
│ │ ├─► Agent: Phase B (model: [tier_B], prompt: phase_B_context)
|
|
58
|
+
│ │ └─► Agent: Phase C (model: [tier_C], prompt: phase_C_context)
|
|
59
|
+
│ │
|
|
60
|
+
│ ├─ Wait for ALL sub-agents to complete
|
|
61
|
+
│ │
|
|
62
|
+
│ ├─ Collect JSON returns from all sub-agents
|
|
63
|
+
│ │
|
|
64
|
+
│ ├─ Post-wave processing (sequential, in phase order):
|
|
65
|
+
│ │ ├─ Detect file conflicts (files_modified overlap)
|
|
66
|
+
│ │ ├─ Process each phase result
|
|
67
|
+
│ │ ├─ Update plan file (mark tasks [x])
|
|
68
|
+
│ │ ├─ Accumulate files_modified list
|
|
69
|
+
│ │ ├─ Buffer patterns from all phases
|
|
70
|
+
│ │ ├─ Git commit sequentially (Phase A, then B, then C)
|
|
71
|
+
│ │ └─ Handle failures (present to user)
|
|
72
|
+
│ │
|
|
73
|
+
│ └─ Next Wave...
|
|
74
|
+
│
|
|
75
|
+
└─ Completion summary with wave execution stats
|
|
76
|
+
```
|
|
77
|
+
|
|
38
78
|
Planning and user approval always happen in the **main session** (full context). Only the **implementation step** is isolated.
|
|
39
79
|
|
|
40
80
|
---
|
|
@@ -68,11 +108,51 @@ Read these files before implementing:
|
|
|
68
108
|
{Only if UI phase — include design tokens from discovery doc}
|
|
69
109
|
{Otherwise omit this section entirely}
|
|
70
110
|
|
|
111
|
+
## Shared Context from Sibling Phases
|
|
112
|
+
|
|
113
|
+
{Only included for multi-phase waves. Omitted for single-phase waves and sequential execution.}
|
|
114
|
+
|
|
115
|
+
The following contracts, decisions, and progress updates were emitted by other phases running in parallel with yours. Use these to inform your implementation:
|
|
116
|
+
|
|
117
|
+
{Injected context entries as formatted text}
|
|
118
|
+
|
|
119
|
+
**Instructions**:
|
|
120
|
+
- Before each task, review shared context entries for relevant contracts or decisions
|
|
121
|
+
- If a sibling phase defined an API endpoint you consume, match its signature exactly
|
|
122
|
+
- If a sibling phase made an architectural decision, follow it for consistency
|
|
123
|
+
- If you define a new API endpoint, type interface, or make an architectural decision, include it in your `context_entries` return array
|
|
124
|
+
|
|
125
|
+
## Commit Instructions
|
|
126
|
+
{Only include this section when `commit: true` in `.flowconfig`}
|
|
127
|
+
|
|
128
|
+
### Sequential Mode (wave_execution: false)
|
|
129
|
+
- After each task completes and verification passes (if applicable):
|
|
130
|
+
1. Stage changed files: `git add -A`
|
|
131
|
+
2. Create atomic commit: `git commit -m "feat(phase-N.task-M): <truncated description> — <feature>"`
|
|
132
|
+
- Use format: feat(phase-{phase_number}.task-{task_number_in_phase}): <description> — <feature>
|
|
133
|
+
- Truncate description to 50 chars (use ellipsis if truncated)
|
|
134
|
+
- Task numbers are 1-indexed within each phase
|
|
135
|
+
3. Continue to next task
|
|
136
|
+
- Return `tasks_completed` array in JSON with files_created/files_modified per task
|
|
137
|
+
- Do NOT create a final phase commit (coordinator will not create one either)
|
|
138
|
+
|
|
139
|
+
### Wave Mode (wave_execution: true)
|
|
140
|
+
- Do NOT create any commits during task implementation
|
|
141
|
+
- The coordinator will commit your changes after this wave completes
|
|
142
|
+
- Return `tasks_completed` array with per-task file lists (see Return Format below)
|
|
143
|
+
- Coordinator will iterate tasks and commit: feat(phase-N.task-M): ... per task
|
|
144
|
+
|
|
71
145
|
## Instructions
|
|
72
146
|
1. Read the plan file to understand the full feature context
|
|
73
147
|
2. Implement all tasks listed above
|
|
74
148
|
3. Follow the project patterns from the files listed
|
|
75
|
-
4.
|
|
149
|
+
4. After completing each task, check if it has a `<verify>` tag indented beneath it:
|
|
150
|
+
- If yes: run the verification command inside the tag
|
|
151
|
+
- If the command exits 0: record a pass result and continue to the next task
|
|
152
|
+
- If the command exits non-zero: spawn a debug sub-agent (haiku, mode: "auto") with the error output, task context, and file content. Apply the repair actions from the diagnosis and re-run the verification command (up to `max_verify_retries` attempts, default 2). See `.claude/resources/core/per-task-verification.md` for the debug sub-agent prompt template and return schema.
|
|
153
|
+
- If max retries exceeded: record a fail result and continue to the next task (do NOT abort)
|
|
154
|
+
- If no `<verify>` tag: skip verification for that task
|
|
155
|
+
5. Return a JSON summary in the exact format below — do NOT return markdown
|
|
76
156
|
|
|
77
157
|
## Return Format
|
|
78
158
|
Return ONLY a JSON object (no markdown fences, no explanation):
|
|
@@ -83,6 +163,29 @@ Return ONLY a JSON object (no markdown fences, no explanation):
|
|
|
83
163
|
|
|
84
164
|
The prompt should be **under 2K tokens** (excluding files the sub-agent reads itself via the Read tool). Keep it focused — the sub-agent will read project files as needed during implementation.
|
|
85
165
|
|
|
166
|
+
### Wave Mode Context Additions
|
|
167
|
+
|
|
168
|
+
When spawning sub-agents within a wave, the context template is **identical** to sequential mode with one key difference:
|
|
169
|
+
|
|
170
|
+
- **`Files Modified in Previous Phases`**: Include files from ALL completed waves (Wave 1 through Wave N-1), not just the immediately preceding phase. This gives each sub-agent awareness of everything that changed before the current wave.
|
|
171
|
+
|
|
172
|
+
Sub-agents within the same wave do NOT receive information about each other — no cross-phase awareness. Each sub-agent operates as if it is the only phase running.
|
|
173
|
+
|
|
174
|
+
**Exception**: When shared context is available from sibling phases (via `.wave-context.jsonl`), the coordinator injects a "Shared Context from Sibling Phases" section into the context template. See below for details.
|
|
175
|
+
|
|
176
|
+
### Shared Context Injection
|
|
177
|
+
|
|
178
|
+
**When shared context is injected**:
|
|
179
|
+
- Multi-phase waves only (2+ phases in the same wave)
|
|
180
|
+
- Coordinator reads `.wave-context.jsonl` before spawning each sub-agent
|
|
181
|
+
- Entries from OTHER phases in the wave are injected (not the agent's own)
|
|
182
|
+
- Single-phase waves and sequential mode: section is omitted entirely
|
|
183
|
+
|
|
184
|
+
**When to emit context entries**:
|
|
185
|
+
- After implementing a task that creates or modifies an API endpoint, type interface, function signature, or makes an architectural decision
|
|
186
|
+
- Include in the `context_entries` array of your JSON return
|
|
187
|
+
- Format as ContextEntry objects (see `shared-context.md` COR-SC-2 for schema)
|
|
188
|
+
|
|
86
189
|
---
|
|
87
190
|
|
|
88
191
|
## Return Format Schema
|
|
@@ -115,6 +218,52 @@ The sub-agent must return a JSON object with this structure:
|
|
|
115
218
|
"description": "All Zod schemas live next to their type definitions",
|
|
116
219
|
"confidence": "high"
|
|
117
220
|
}
|
|
221
|
+
],
|
|
222
|
+
"task_verifications": [
|
|
223
|
+
{
|
|
224
|
+
"task": "Create user authentication middleware",
|
|
225
|
+
"verify_command": "npx tsc --noEmit src/middleware/auth.ts",
|
|
226
|
+
"status": "pass",
|
|
227
|
+
"attempts": 2,
|
|
228
|
+
"repairs_applied": [
|
|
229
|
+
"Added missing import for AuthMiddleware type"
|
|
230
|
+
]
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
"task": "Add rate limiting to API routes",
|
|
234
|
+
"verify_command": "npx jest src/middleware/__tests__/rate-limit.test.ts --no-coverage",
|
|
235
|
+
"status": "pass",
|
|
236
|
+
"attempts": 1,
|
|
237
|
+
"repairs_applied": []
|
|
238
|
+
}
|
|
239
|
+
],
|
|
240
|
+
"tasks_completed": [
|
|
241
|
+
{
|
|
242
|
+
"task_number": 1,
|
|
243
|
+
"task_name": "Create user authentication middleware",
|
|
244
|
+
"files_created": ["src/middleware/auth.ts"],
|
|
245
|
+
"files_modified": []
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
"task_number": 2,
|
|
249
|
+
"task_name": "Add rate limiting to API routes",
|
|
250
|
+
"files_created": ["src/middleware/rate-limit.ts"],
|
|
251
|
+
"files_modified": ["src/api/routes.ts"]
|
|
252
|
+
}
|
|
253
|
+
],
|
|
254
|
+
"context_entries": [
|
|
255
|
+
{
|
|
256
|
+
"agent": "phase-N",
|
|
257
|
+
"type": "contract",
|
|
258
|
+
"timestamp": "ISO8601",
|
|
259
|
+
"data": { "name": "GET /users", "kind": "endpoint", "signature": "GET /users → { id, name, email }", "fields": ["id", "name", "email"] }
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
"agent": "phase-N",
|
|
263
|
+
"type": "decision",
|
|
264
|
+
"timestamp": "ISO8601",
|
|
265
|
+
"data": { "choice": "Using Redis for session caching", "reason": "Low latency requirement" }
|
|
266
|
+
}
|
|
118
267
|
]
|
|
119
268
|
}
|
|
120
269
|
```
|
|
@@ -132,6 +281,9 @@ The sub-agent must return a JSON object with this structure:
|
|
|
132
281
|
| `deviations` | string[] | No | Tasks skipped or changed from plan |
|
|
133
282
|
| `errors` | string[] | No | Errors encountered (even if resolved) |
|
|
134
283
|
| `patterns_captured` | object[] | No | Patterns observed during implementation |
|
|
284
|
+
| `task_verifications` | object[] | No | Array of per-task verification results. Only present when at least one task had a `<verify>` tag. Each entry contains: `task` (string), `verify_command` (string), `status` (`"pass" \| "fail"`), `attempts` (number), `repairs_applied` (string[]), and optionally `last_diagnosis` (object, only when status is `"fail"`). See `.claude/resources/core/per-task-verification.md` for full schema. |
|
|
285
|
+
| `tasks_completed` | object[] | No | Array of per-task file tracking for atomic commits. Each entry: `task_number` (number, 1-indexed within phase), `task_name` (string), `files_created` (string[]), `files_modified` (string[]). Present when any tasks ran. Used by coordinator for per-task commit messages. See `.claude/resources/core/atomic-commits.md` for full schema. |
|
|
286
|
+
| `context_entries` | object[] | No | Array of context entries emitted by this phase for sibling phases. Each entry: `agent` (string, e.g. "phase-3"), `type` (`"contract" \| "decision" \| "progress"`), `timestamp` (ISO8601 string), `data` (object with type-specific fields). Only relevant in multi-phase waves. See `.claude/resources/core/shared-context.md` COR-SC-2 for full schema. |
|
|
135
287
|
|
|
136
288
|
### Failure Return Example
|
|
137
289
|
|
|
@@ -163,9 +315,15 @@ After receiving the sub-agent's JSON summary, the coordinator:
|
|
|
163
315
|
1. **Update plan file**: Mark all phase tasks as `[x]`
|
|
164
316
|
2. **Accumulate file list**: Merge `files_created` and `files_modified` into running list
|
|
165
317
|
3. **Buffer patterns**: Append `patterns_captured` entries to `flow/resources/pending-patterns.md`
|
|
166
|
-
4. **Git commit**: If `commit: true
|
|
318
|
+
4. **Git commit (per-task)**: If `commit: true` and `tasks_completed` is present:
|
|
319
|
+
- **Sequential mode**: Sub-agent already created per-task commits — verify they exist, do NOT create phase commit
|
|
320
|
+
- **Wave mode**: Coordinator iterates `tasks_completed` in task_number order and creates per-task commits:
|
|
321
|
+
- For each task: `git add -A && git commit -m "feat(phase-N.task-M): <truncated task_name> — <feature>"`
|
|
322
|
+
- Truncate `task_name` to 50 chars if needed
|
|
323
|
+
- **Fallback**: If `tasks_completed` is absent (legacy sub-agent), fall back to single phase commit: `git add -A && git commit -m "Phase N: {name} — {feature}"`
|
|
167
324
|
5. **Log decisions**: Include `decisions` in phase completion message
|
|
168
|
-
6. **
|
|
325
|
+
6. **Display verification results**: If `task_verifications` is present, show pass/fail counts and any repairs applied
|
|
326
|
+
7. **Proceed**: Move to next phase
|
|
169
327
|
|
|
170
328
|
### On Failure (`status: "failure"`)
|
|
171
329
|
|
|
@@ -178,7 +336,49 @@ After receiving the sub-agent's JSON summary, the coordinator:
|
|
|
178
336
|
|
|
179
337
|
1. **Present summary**: Show what was completed and what wasn't
|
|
180
338
|
2. **Show deviations**: List `deviations` explaining what was skipped
|
|
181
|
-
3. **
|
|
339
|
+
3. **Display verification failures**: If `task_verifications` contains failed entries, show task name, last diagnosis, and repair attempts
|
|
340
|
+
4. **Ask user**: "Phase partially complete. Continue to next phase or retry remaining tasks?"
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
344
|
+
## Wave Coordinator Processing
|
|
345
|
+
|
|
346
|
+
When multiple sub-agents return simultaneously from a wave, the coordinator handles them differently from sequential mode. See `.claude/resources/core/wave-execution.md` for the full wave system and `.claude/resources/skills/execute-plan-skill.md` Step 4c for the detailed processing flow.
|
|
347
|
+
|
|
348
|
+
**Per-task commits in wave mode**: After collecting all JSON returns from a wave, the coordinator commits per-task (not per-phase). For each phase in phase-number order, iterate `tasks_completed` and create atomic commits: `feat(phase-N.task-M): <desc> — <feature>`. See `.claude/resources/core/atomic-commits.md` for the complete commit format and coordinator processing rules.
|
|
349
|
+
|
|
350
|
+
### Collecting Multiple JSON Returns
|
|
351
|
+
|
|
352
|
+
After all sub-agents in a wave complete, the coordinator collects all JSON returns before processing any of them. This allows file conflict detection before committing.
|
|
353
|
+
|
|
354
|
+
### Processing Order
|
|
355
|
+
|
|
356
|
+
Results are always processed **sequentially in phase number order**, regardless of which sub-agent finished first. This ensures:
|
|
357
|
+
- Deterministic commit history (Phase A committed before Phase B)
|
|
358
|
+
- Predictable plan file updates
|
|
359
|
+
- Consistent file accumulation order
|
|
360
|
+
|
|
361
|
+
### File Conflict Detection
|
|
362
|
+
|
|
363
|
+
After collecting all wave results, check for `files_modified` overlap between phases:
|
|
364
|
+
|
|
365
|
+
```
|
|
366
|
+
For each pair of phases (A, B) in the wave:
|
|
367
|
+
overlap = A.files_modified ∩ B.files_modified
|
|
368
|
+
if overlap is not empty:
|
|
369
|
+
→ File conflict detected
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
**On conflict**: Present to user with options (accept as-is, re-run conflicting phases sequentially, or stop). Never silently resolve conflicts.
|
|
373
|
+
|
|
374
|
+
### Wave Failure Isolation
|
|
375
|
+
|
|
376
|
+
A failed phase in a wave does NOT affect other phases in the same wave:
|
|
377
|
+
- Successful phases are processed normally (plan updates, file accumulation, git commits)
|
|
378
|
+
- Failed phases are presented to the user after all successful phases are processed
|
|
379
|
+
- The user chooses per failed phase: retry, skip, or stop
|
|
380
|
+
|
|
381
|
+
This differs from sequential mode where a failure immediately pauses execution. In wave mode, all parallel phases complete independently before any failure handling.
|
|
182
382
|
|
|
183
383
|
---
|
|
184
384
|
|
|
@@ -186,6 +386,8 @@ After receiving the sub-agent's JSON summary, the coordinator:
|
|
|
186
386
|
|
|
187
387
|
When phases are aggregated (combined complexity ≤ 6), they run as **one sub-agent call** with all tasks from all aggregated phases. The context template lists all phases and tasks together. The return uses the highest phase number as the `phase` field.
|
|
188
388
|
|
|
389
|
+
In wave mode, aggregated phases within the same wave are treated as a **single unit** — they share one wave slot, one dependency set (union of all aggregated phases' dependencies), and one sub-agent call.
|
|
390
|
+
|
|
189
391
|
---
|
|
190
392
|
|
|
191
393
|
## Configuration
|
|
@@ -210,6 +412,19 @@ Phase isolation **enhances** model routing — it doesn't replace it:
|
|
|
210
412
|
| `model_routing: false` + `phase_isolation: true` | Sub-agent spawned with session model, clean context |
|
|
211
413
|
| `model_routing: false` + `phase_isolation: false` | Inline execution, no sub-agents (original behavior) |
|
|
212
414
|
|
|
415
|
+
### Interaction with Wave Execution
|
|
416
|
+
|
|
417
|
+
Phase isolation is the **foundation** for wave execution — wave mode spawns multiple isolated sub-agents per wave instead of one at a time:
|
|
418
|
+
|
|
419
|
+
| Setting | Behavior |
|
|
420
|
+
|---------|----------|
|
|
421
|
+
| `wave_execution: true` + `phase_isolation: true` | Multiple sub-agents per wave, each with clean context (optimal) |
|
|
422
|
+
| `wave_execution: true` + `phase_isolation: false` | Multiple sub-agents per wave, but sharing session context (may cause interference) |
|
|
423
|
+
| `wave_execution: false` + `phase_isolation: true` | One sub-agent at a time, clean context (existing behavior) |
|
|
424
|
+
| `wave_execution: false` + `phase_isolation: false` | Inline execution, no sub-agents (original behavior) |
|
|
425
|
+
|
|
426
|
+
**Recommendation**: `wave_execution: true` works best with `phase_isolation: true`. Without phase isolation, parallel sub-agents may interfere with each other's context.
|
|
427
|
+
|
|
213
428
|
---
|
|
214
429
|
|
|
215
430
|
## Rules
|
|
@@ -220,3 +435,21 @@ Phase isolation **enhances** model routing — it doesn't replace it:
|
|
|
220
435
|
4. **Coordinator validates** — check status field before proceeding
|
|
221
436
|
5. **Never auto-retry** — on failure, present to user and ask
|
|
222
437
|
6. **Pass paths, not content** — give file paths, sub-agent reads them
|
|
438
|
+
7. **Each phase gets own sub-agent** — even in wave mode, phases are never merged into one sub-agent (except for aggregated phases per complexity rules)
|
|
439
|
+
8. **No cross-wave awareness** — sub-agents in the same wave know nothing about each other unless shared context entries are injected from `.wave-context.jsonl`
|
|
440
|
+
9. **Deterministic processing** — wave results are always processed in phase number order
|
|
441
|
+
10. **Collect before commit** — in wave mode, all JSON returns are collected before any commits happen
|
|
442
|
+
11. **Verification is internal** — per-task verification loops run inside the phase sub-agent; the coordinator sees only the final `task_verifications` results
|
|
443
|
+
|
|
444
|
+
---
|
|
445
|
+
|
|
446
|
+
## Related Files
|
|
447
|
+
|
|
448
|
+
| File | Purpose |
|
|
449
|
+
|------|---------|
|
|
450
|
+
| `.claude/resources/core/wave-execution.md` | Full wave-based parallel execution system |
|
|
451
|
+
| `.claude/resources/core/model-routing.md` | Model tier selection per phase complexity |
|
|
452
|
+
| `.claude/resources/core/discovery-sub-agents.md` | Parallel spawning pattern reference |
|
|
453
|
+
| `.claude/resources/core/per-task-verification.md` | Per-task verification system, debug sub-agent, and repair loops |
|
|
454
|
+
| `.claude/resources/core/shared-context.md` | Shared context schema, JSONL format, and coordinator injection rules |
|
|
455
|
+
| `.claude/resources/skills/execute-plan-skill.md` | Execute-plan skill with wave integration (Steps 2b, 3, 4) |
|
|
@@ -103,3 +103,4 @@ After compaction, the model should re-read `flow/.scratchpad.md` to restore any
|
|
|
103
103
|
3. **Self-manage size** — promote or discard when approaching 50 lines
|
|
104
104
|
4. **Promote before ending** — always scan for promotable items before session ends
|
|
105
105
|
5. **Not a task list** — use `flow/tasklist.md` for tasks, scratchpad is for observations
|
|
106
|
+
6. **Different from STATE.md** — `flow/STATE.md` tracks structured execution position (current skill, phase, status) for session resumability. The scratchpad tracks informal observations, insights, and open questions. They coexist and serve different purposes: STATE.md is machine-readable execution state, scratchpad is human-readable notes.
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Shared Context System
|
|
2
|
+
|
|
3
|
+
## COR-SC-1: Purpose
|
|
4
|
+
|
|
5
|
+
Inter-agent communication during parallel wave execution via a shared JSONL context file. When multiple phases run in parallel (wave execution), each sub-agent may produce contracts, decisions, or progress updates that sibling agents need. The shared context file acts as the coordination bus.
|
|
6
|
+
|
|
7
|
+
## COR-SC-2: Context Entry Types
|
|
8
|
+
|
|
9
|
+
Each entry in the context file is a JSON object with these fields:
|
|
10
|
+
|
|
11
|
+
| Field | Type | Description |
|
|
12
|
+
|-------|------|-------------|
|
|
13
|
+
| `agent` | string | Phase identifier (e.g., `"phase-3"`) |
|
|
14
|
+
| `type` | `'contract' \| 'decision' \| 'progress'` | Entry category |
|
|
15
|
+
| `timestamp` | string | ISO-8601 timestamp |
|
|
16
|
+
| `data` | object | Type-specific payload (see below) |
|
|
17
|
+
|
|
18
|
+
### Contract Entries (`type: 'contract'`)
|
|
19
|
+
|
|
20
|
+
Declare API shapes, interfaces, function signatures, or type definitions that other phases may depend on.
|
|
21
|
+
|
|
22
|
+
```json
|
|
23
|
+
{
|
|
24
|
+
"agent": "phase-2",
|
|
25
|
+
"type": "contract",
|
|
26
|
+
"timestamp": "2026-03-24T10:00:00.000Z",
|
|
27
|
+
"data": {
|
|
28
|
+
"name": "UserService.getById",
|
|
29
|
+
"kind": "function",
|
|
30
|
+
"signature": "(id: string) => Promise<User>",
|
|
31
|
+
"fields": ["id", "name", "email"]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`data` fields for contracts:
|
|
37
|
+
- `name` (required): Unique identifier for the contract
|
|
38
|
+
- `kind` (required): One of `endpoint`, `interface`, `function`, `type`
|
|
39
|
+
- `signature` (required): The type signature or shape
|
|
40
|
+
- `fields` (optional): Array of field/property names
|
|
41
|
+
|
|
42
|
+
### Decision Entries (`type: 'decision'`)
|
|
43
|
+
|
|
44
|
+
Record architecture or implementation choices made during execution.
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"agent": "phase-3",
|
|
49
|
+
"type": "decision",
|
|
50
|
+
"timestamp": "2026-03-24T10:01:00.000Z",
|
|
51
|
+
"data": {
|
|
52
|
+
"choice": "Use Redis for session storage",
|
|
53
|
+
"reason": "Faster than DB lookups for frequent reads"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Progress Entries (`type: 'progress'`)
|
|
59
|
+
|
|
60
|
+
Report task completion status within a phase.
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"agent": "phase-2",
|
|
65
|
+
"type": "progress",
|
|
66
|
+
"timestamp": "2026-03-24T10:02:00.000Z",
|
|
67
|
+
"data": {
|
|
68
|
+
"task": 1,
|
|
69
|
+
"status": "complete",
|
|
70
|
+
"summary": "Created UserService with CRUD operations"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## COR-SC-3: File Format and Lifecycle
|
|
76
|
+
|
|
77
|
+
**File**: `.wave-context.jsonl` inside the `flow/` directory. Append-only JSONL — one JSON object per line.
|
|
78
|
+
|
|
79
|
+
**Lifecycle**:
|
|
80
|
+
|
|
81
|
+
1. **Created** — at the start of each wave, an empty `.wave-context.jsonl` is created
|
|
82
|
+
2. **Injected** — before spawning sub-agents (Step 4b), existing entries are read and passed as context
|
|
83
|
+
3. **Appended** — sub-agents append entries during execution via atomic write (read, append, write-to-temp, rename)
|
|
84
|
+
4. **Collected** — after sub-agents return (Step 4c), all entries are read and checked for conflicts
|
|
85
|
+
5. **Cleared** — between waves, the file is deleted to start fresh for the next wave
|
|
86
|
+
6. **Deleted** — after plan execution completes, the file is removed
|
|
87
|
+
|
|
88
|
+
## COR-SC-4: Contract Conflict Detection
|
|
89
|
+
|
|
90
|
+
A conflict exists when two or more entries share the same `name` but have different `signature` or `fields` values.
|
|
91
|
+
|
|
92
|
+
**Detection rules**:
|
|
93
|
+
- Filter entries to `type === 'contract'`
|
|
94
|
+
- Group by `data.name`
|
|
95
|
+
- For each group with 2+ entries: compare `signature` and `fields` (order-insensitive for fields)
|
|
96
|
+
- If any pair within a group differs: flag as conflict
|
|
97
|
+
|
|
98
|
+
**Resolution**: Present both conflicting versions to the user with the originating agent names. The user decides which version to keep or how to reconcile.
|
|
99
|
+
|
|
100
|
+
## COR-SC-5: Integration Points and Backward Compatibility
|
|
101
|
+
|
|
102
|
+
**Integration points**:
|
|
103
|
+
- **Step 4b (inject)**: Read `.wave-context.jsonl`, pass entries array to sub-agent prompt
|
|
104
|
+
- **Step 4c (collect)**: Parse `context_entries` from sub-agent return JSON, append to file, run conflict detection
|
|
105
|
+
|
|
106
|
+
**Backward compatibility**:
|
|
107
|
+
- Single-phase waves: context injection is skipped (no sibling data to share)
|
|
108
|
+
- Sequential mode (`wave_execution: false`): shared context system is not used
|
|
109
|
+
- `context_entries` field is optional in sub-agent return JSON — absence means no entries to contribute
|
|
110
|
+
- Existing plans without wave execution are completely unaffected
|