planflow-ai 1.4.1 → 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.
Files changed (52) hide show
  1. package/.claude/commands/brainstorm.md +6 -14
  2. package/.claude/commands/create-contract.md +6 -38
  3. package/.claude/commands/create-plan.md +7 -38
  4. package/.claude/commands/discovery-plan.md +7 -49
  5. package/.claude/commands/execute-plan.md +11 -63
  6. package/.claude/commands/heartbeat.md +12 -14
  7. package/.claude/commands/learn.md +20 -80
  8. package/.claude/commands/note.md +6 -23
  9. package/.claude/commands/review-code.md +8 -51
  10. package/.claude/commands/review-pr.md +10 -57
  11. package/.claude/commands/setup.md +8 -56
  12. package/.claude/commands/write-tests.md +7 -41
  13. package/.claude/resources/core/phase-isolation.md +46 -1
  14. package/.claude/resources/core/shared-context.md +110 -0
  15. package/.claude/resources/core/wave-execution.md +79 -1
  16. package/.claude/resources/skills/execute-plan-skill.md +74 -13
  17. package/README.md +154 -96
  18. package/dist/cli/commands/brain.d.ts +20 -0
  19. package/dist/cli/commands/brain.d.ts.map +1 -0
  20. package/dist/cli/commands/brain.js +127 -0
  21. package/dist/cli/commands/brain.js.map +1 -0
  22. package/dist/cli/commands/init.d.ts.map +1 -1
  23. package/dist/cli/commands/init.js +9 -0
  24. package/dist/cli/commands/init.js.map +1 -1
  25. package/dist/cli/commands/state-query.d.ts +13 -0
  26. package/dist/cli/commands/state-query.d.ts.map +1 -0
  27. package/dist/cli/commands/state-query.js +32 -0
  28. package/dist/cli/commands/state-query.js.map +1 -0
  29. package/dist/cli/daemon/shared-context.d.ts +38 -0
  30. package/dist/cli/daemon/shared-context.d.ts.map +1 -0
  31. package/dist/cli/daemon/shared-context.js +129 -0
  32. package/dist/cli/daemon/shared-context.js.map +1 -0
  33. package/dist/cli/handlers/claude.d.ts.map +1 -1
  34. package/dist/cli/handlers/claude.js +18 -0
  35. package/dist/cli/handlers/claude.js.map +1 -1
  36. package/dist/cli/handlers/shared.js +1 -1
  37. package/dist/cli/handlers/shared.js.map +1 -1
  38. package/dist/cli/index.js +21 -0
  39. package/dist/cli/index.js.map +1 -1
  40. package/dist/cli/state/brain-query.d.ts +48 -0
  41. package/dist/cli/state/brain-query.d.ts.map +1 -0
  42. package/dist/cli/state/brain-query.js +113 -0
  43. package/dist/cli/state/brain-query.js.map +1 -0
  44. package/dist/cli/state/types.d.ts +31 -0
  45. package/dist/cli/state/types.d.ts.map +1 -1
  46. package/package.json +4 -1
  47. package/.claude/resources/core/_index.md +0 -347
  48. package/.claude/resources/languages/_index.md +0 -76
  49. package/.claude/resources/patterns/_index.md +0 -200
  50. package/.claude/resources/skills/_index.md +0 -287
  51. package/.claude/resources/tools/_index.md +0 -110
  52. package/.claude/resources/tools/reference-expansion-tool.md +0 -326
@@ -120,60 +120,17 @@ review-pr https://github.com/org/repo/pull/123
120
120
  review-pr https://dev.azure.com/org/project/_git/repo/pullrequest/456
121
121
  ```
122
122
 
123
- ---
123
+ ## Context Loading
124
+
125
+ This command uses the **brain index** for context retrieval. Before executing, query the project brain for relevant documentation:
126
+
127
+ **Queries**:
128
+ - `planflow-ai state-query "PR review workflow" --scope resources`
129
+ - `planflow-ai state-query "adaptive depth" --scope resources`
130
+ - `planflow-ai state-query "severity ranking" --scope resources`
131
+ - `planflow-ai state-query "PR authentication" --scope resources`
124
132
 
125
- ## Context Optimization
126
-
127
- This command uses hierarchical context loading to reduce context consumption. Instead of loading full files, load indexes first and expand specific sections on-demand.
128
-
129
- ### Recommended Loading Order
130
-
131
- 1. **Always load first**: This command file (`commands/review-pr.md`)
132
- 2. **Load indexes**: Load `_index.md` files for relevant folders
133
- 3. **Expand on-demand**: Use reference codes to load specific sections when needed
134
-
135
- ### Index Files for PR Review
136
-
137
- | Index | When to Load |
138
- |-------|--------------|
139
- | `resources/skills/_index.md` | To understand review workflow |
140
- | `resources/tools/_index.md` | For authentication tool |
141
- | `resources/patterns/_index.md` | For review patterns |
142
- | `resources/core/_index.md` | For allowed/forbidden patterns |
143
-
144
- ### Reference Codes for PR Review
145
-
146
- | Code | Description | When to Expand |
147
- |------|-------------|----------------|
148
- | SKL-PR-1 | Purpose and restrictions | Understanding allowed actions |
149
- | SKL-PR-2 | Authenticate for PR access | Setting up authentication |
150
- | SKL-PR-3 | Fetch PR info + determine depth | Getting PR data and review mode |
151
- | SKL-PR-5 | Analyze + verify + re-rank | Processing findings |
152
- | SKL-PR-6 | Generate review document | Creating the output file |
153
- | SKL-PR-7 | Output template | Review document structure |
154
- | SKL-PR-8 | Fix complexity scoring | Severity and complexity details |
155
- | SKL-PR-9 | Link format (GitHub/Azure DevOps) | Platform-specific link formats |
156
- | TLS-AUTH-1 | Auth tool configuration | Setting up authentication |
157
- | TLS-AUTH-2 | Authentication workflow | Authenticating to platform |
158
- | PTN-PR-1 | PR review patterns | Creating review output |
159
- | COR-AP-1 | Allowed patterns overview | Checking pattern compliance |
160
- | COR-FP-1 | Forbidden patterns overview | Identifying anti-patterns |
161
- | COR-MA-1 | Multi-agent subagent definitions | Deep mode parallel review setup |
162
- | COR-MA-2 | Coordinator dedup and merge | Deep mode result processing |
163
- | COR-SR-1 | Severity re-ranking algorithm | Ordering findings by impact |
164
- | COR-SR-2 | Finding grouping rules | Grouping related findings |
165
- | COR-AD-1 | Adaptive depth size detection | Determining review mode |
166
- | COR-AD-2 | Lightweight review mode | Changeset < 50 lines |
167
- | COR-AD-3 | Deep review mode | Changeset 500+ lines |
168
-
169
- ### Expansion Instructions
170
-
171
- When executing this command:
172
-
173
- 1. **Start with indexes**: Read `resources/skills/_index.md` and `resources/tools/_index.md`
174
- 2. **Expand auth first**: Load TLS-AUTH-* codes for authentication
175
- 3. **Then expand review patterns**: Load PTN-PR-* codes for review structure
176
- 4. **Don't expand everything**: Only load patterns relevant to the PR being reviewed
133
+ The brain returns ranked chunks from indexed markdown files. Use the top results to inform execution.
177
134
 
178
135
  ---
179
136
 
@@ -181,10 +138,6 @@ When executing this command:
181
138
 
182
139
  | Resource | Purpose |
183
140
  | ------------------------------ | -------------------------------------- |
184
- | `resources/skills/_index.md` | Index of skills with reference codes |
185
- | `resources/tools/_index.md` | Index of tools with reference codes |
186
- | `resources/patterns/_index.md` | Index of patterns with reference codes |
187
- | `resources/core/_index.md` | Index of core rules with reference codes |
188
141
  | `review-pr-skill.md` | Skill that executes the review |
189
142
  | `auth-pr-tool.md` | Authentication tool for PR platforms |
190
143
  | `review-pr-patterns.md` | Review patterns and guidelines |
@@ -648,59 +648,15 @@ flow/
648
648
  - Component structure
649
649
  - Error handling approach
650
650
 
651
- ---
651
+ ## Context Loading
652
+
653
+ This command uses the **brain index** for context retrieval. Before executing, query the project brain for relevant documentation:
654
+
655
+ **Queries**:
656
+ - `planflow-ai state-query "project setup" --scope resources`
657
+ - `planflow-ai state-query "pattern generation" --scope resources`
652
658
 
653
- ## Context Optimization
654
-
655
- This command uses hierarchical context loading to reduce context consumption. Instead of loading full files, load indexes first and expand specific sections on-demand.
656
-
657
- ### Recommended Loading Order
658
-
659
- 1. **Always load first**: This command file (`commands/setup.md`)
660
- 2. **Load indexes**: Load `_index.md` files for relevant folders
661
- 3. **Expand on-demand**: Use reference codes to load specific sections when needed
662
-
663
- ### Index Files for Setup
664
-
665
- | Index | When to Load |
666
- |-------|--------------|
667
- | `resources/skills/_index.md` | To understand setup workflow |
668
- | `resources/tools/_index.md` | For interactive questions tool |
669
- | `resources/core/_index.md` | For pattern references |
670
- | `resources/languages/_index.md` | For language-specific patterns |
671
-
672
- ### Reference Codes for Setup
673
-
674
- | Code | Description | When to Expand |
675
- |------|-------------|----------------|
676
- | SKL-SETUP-1 | Purpose and critical approach | Understanding setup goals |
677
- | SKL-SETUP-2 | Scan project structure | Scanning files and directories |
678
- | SKL-SETUP-3 | Deep dependency analysis | Analyzing package dependencies |
679
- | SKL-SETUP-4 | Deep code analysis | Sampling files and extracting patterns |
680
- | SKL-SETUP-7 | Ask confirming questions | Presenting questions via Plan mode |
681
- | SKL-SETUP-8 | Generate pattern files | Creating framework/library pattern files |
682
- | SKL-SETUP-9 | Update core pattern files | Updating allowed/forbidden patterns |
683
- | SKL-SETUP-11 | Create analysis document | Generating project analysis doc |
684
- | SKL-SETUP-12 | Index documentation | Indexing project docs with reference codes |
685
- | SKL-SETUP-13 | Create flow folder | Setting up flow/ directory structure |
686
- | SKL-SETUP-14 | Present summary | Final setup summary output |
687
- | TLS-IQ-1 | Interactive questions overview | Before asking questions |
688
- | TLS-IQ-2 | Switch to Plan mode | Starting question session |
689
- | TLS-IQ-3 | Ask questions format | Asking confirmation questions |
690
- | COR-AP-1 | Allowed patterns structure | Updating allowed patterns |
691
- | COR-FP-1 | Forbidden patterns structure | Updating forbidden patterns |
692
- | LNG-TS-1 | TypeScript patterns | If TS project detected |
693
- | LNG-PY-1 | Python patterns | If Python project detected |
694
-
695
- ### Expansion Instructions
696
-
697
- When executing this command:
698
-
699
- 1. **Start with indexes**: Read `resources/skills/_index.md` and `resources/tools/_index.md`
700
- 2. **Expand for detection phase**: Load minimal context during code analysis
701
- 3. **Expand for questions**: Load TLS-IQ-* before asking confirmation questions
702
- 4. **Expand for generation**: Load relevant language patterns when generating files
703
- 5. **Don't expand everything**: Only load patterns relevant to detected stack
659
+ The brain returns ranked chunks from indexed markdown files. Use the top results to inform execution.
704
660
 
705
661
  ---
706
662
 
@@ -708,10 +664,6 @@ When executing this command:
708
664
 
709
665
  | Resource | Purpose |
710
666
  | ------------------------------ | -------------------------------------- |
711
- | `resources/skills/_index.md` | Index of skills with reference codes |
712
- | `resources/tools/_index.md` | Index of tools with reference codes |
713
- | `resources/core/_index.md` | Index of core rules with reference codes |
714
- | `resources/languages/_index.md` | Index of language patterns with reference codes |
715
667
  | `setup-skill.md` | Detailed execution logic |
716
668
  | `interactive-questions-tool.md` | Questions UI for confirmations |
717
669
  | `allowed-patterns.md` | Core allowed patterns |
@@ -199,47 +199,16 @@ All metrics (Lines, Branches, Functions, Statements) meet the target.
199
199
  3. Invoke write-tests skill
200
200
  4. Present final coverage summary
201
201
 
202
- ---
203
-
204
- ## Context Optimization
205
-
206
- This command uses hierarchical context loading to reduce context consumption. Instead of loading full files, load indexes first and expand specific sections on-demand.
207
-
208
- ### Recommended Loading Order
209
-
210
- 1. **Always load first**: This command file (`commands/write-tests.md`)
211
- 2. **Load indexes**: Load `_index.md` files for relevant folders
212
- 3. **Expand on-demand**: Use reference codes to load specific sections when needed
213
-
214
- ### Index Files for Writing Tests
215
-
216
- | Index | When to Load |
217
- |-------|--------------|
218
- | `resources/skills/_index.md` | To understand test writing workflow |
219
- | `resources/patterns/_index.md` | For testing patterns |
220
- | `resources/tools/_index.md` | For testing tool commands |
221
-
222
- ### Reference Codes for Writing Tests
223
-
224
- | Code | Description | When to Expand |
225
- |------|-------------|----------------|
226
- | SKL-TEST-1 | Write tests skill workflow | Understanding full process |
227
- | PTN-JEST-1 | Jest test structure | Writing Jest tests |
228
- | PTN-JEST-2 | Jest mocking patterns | When mocking is needed |
229
- | PTN-PYTEST-1 | Pytest test structure | Writing Pytest tests |
230
- | PTN-PYTEST-2 | Pytest fixtures | When fixtures are needed |
231
- | TLS-JEST-1 | Jest commands | Running Jest tests |
232
- | TLS-PYTEST-1 | Pytest commands | Running Pytest tests |
202
+ ## Context Loading
233
203
 
234
- ### Expansion Instructions
204
+ This command uses the **brain index** for context retrieval. Before executing, query the project brain for relevant documentation:
235
205
 
236
- When executing this command:
206
+ **Queries**:
207
+ - `planflow-ai state-query "test writing" --scope resources`
208
+ - `planflow-ai state-query "jest patterns" --scope resources`
209
+ - `planflow-ai state-query "pytest patterns" --scope resources`
237
210
 
238
- 1. **Start with indexes**: Read `resources/skills/_index.md` and `resources/patterns/_index.md`
239
- 2. **Detect framework first**: Determine Jest or Pytest before expanding patterns
240
- 3. **Expand framework-specific**: Only load PTN-JEST-* or PTN-PYTEST-*, not both
241
- 4. **Expand tool commands**: Load TLS-JEST-* or TLS-PYTEST-* for running tests
242
- 5. **Don't expand everything**: Only load patterns relevant to detected framework
211
+ The brain returns ranked chunks from indexed markdown files. Use the top results to inform execution.
243
212
 
244
213
  ---
245
214
 
@@ -247,9 +216,6 @@ When executing this command:
247
216
 
248
217
  | Resource | Purpose |
249
218
  | ------------------------- | ------------------------------- |
250
- | `resources/skills/_index.md` | Index of skills with reference codes |
251
- | `resources/patterns/_index.md` | Index of patterns with reference codes |
252
- | `resources/tools/_index.md` | Index of tools with reference codes |
253
219
  | `write-tests-skill.md` | Skill that writes the tests |
254
220
  | `jest-patterns.md` | Jest testing patterns |
255
221
  | `pytest-patterns.md` | Pytest testing patterns |
@@ -108,6 +108,20 @@ Read these files before implementing:
108
108
  {Only if UI phase — include design tokens from discovery doc}
109
109
  {Otherwise omit this section entirely}
110
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
+
111
125
  ## Commit Instructions
112
126
  {Only include this section when `commit: true` in `.flowconfig`}
113
127
 
@@ -157,6 +171,21 @@ When spawning sub-agents within a wave, the context template is **identical** to
157
171
 
158
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.
159
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
+
160
189
  ---
161
190
 
162
191
  ## Return Format Schema
@@ -221,6 +250,20 @@ The sub-agent must return a JSON object with this structure:
221
250
  "files_created": ["src/middleware/rate-limit.ts"],
222
251
  "files_modified": ["src/api/routes.ts"]
223
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
+ }
224
267
  ]
225
268
  }
226
269
  ```
@@ -240,6 +283,7 @@ The sub-agent must return a JSON object with this structure:
240
283
  | `patterns_captured` | object[] | No | Patterns observed during implementation |
241
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. |
242
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. |
243
287
 
244
288
  ### Failure Return Example
245
289
 
@@ -392,7 +436,7 @@ Phase isolation is the **foundation** for wave execution — wave mode spawns mu
392
436
  5. **Never auto-retry** — on failure, present to user and ask
393
437
  6. **Pass paths, not content** — give file paths, sub-agent reads them
394
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)
395
- 8. **No cross-wave awareness** — sub-agents in the same wave know nothing about each other
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`
396
440
  9. **Deterministic processing** — wave results are always processed in phase number order
397
441
  10. **Collect before commit** — in wave mode, all JSON returns are collected before any commits happen
398
442
  11. **Verification is internal** — per-task verification loops run inside the phase sub-agent; the coordinator sees only the final `task_verifications` results
@@ -407,4 +451,5 @@ Phase isolation is the **foundation** for wave execution — wave mode spawns mu
407
451
  | `.claude/resources/core/model-routing.md` | Model tier selection per phase complexity |
408
452
  | `.claude/resources/core/discovery-sub-agents.md` | Parallel spawning pattern reference |
409
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 |
410
455
  | `.claude/resources/skills/execute-plan-skill.md` | Execute-plan skill with wave integration (Steps 2b, 3, 4) |
@@ -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
@@ -24,19 +24,24 @@ Coordinator (main session)
24
24
  │ │
25
25
  │ ├─ Sequential: Approve each phase in Plan Mode
26
26
  │ │
27
+ │ ├─ Create shared context file (flow/.wave-context.jsonl)
28
+ │ │
27
29
  │ ├─ Parallel: Spawn Agent sub-agents for all wave phases
28
30
  │ │ ├─► Agent: Phase A (model: [tier from model routing])
29
31
  │ │ ├─► Agent: Phase B (model: [tier from model routing])
30
32
  │ │ └─► Agent: Phase C (model: [tier from model routing])
33
+ │ │ (agents read/append to .wave-context.jsonl during execution)
31
34
  │ │
32
35
  │ ├─ Collect JSON returns from all sub-agents
33
36
  │ │
34
37
  │ ├─ Post-wave processing:
35
38
  │ │ ├─ Detect file conflicts (files_modified overlap)
39
+ │ │ ├─ Detect contract conflicts (same name, different signatures)
36
40
  │ │ ├─ Accumulate files_modified list
37
41
  │ │ ├─ Buffer patterns from all phases
38
42
  │ │ ├─ Git commit per-task (iterate tasks within each phase, in phase order)
39
- │ │ └─ Handle failures (present to user)
43
+ │ │ ├─ Handle failures (present to user)
44
+ │ │ └─ Delete .wave-context.jsonl (clean slate for next wave)
40
45
  │ │
41
46
  │ └─ Next Wave...
42
47
 
@@ -47,6 +52,56 @@ Planning and user approval always happen **sequentially** in the main session. O
47
52
 
48
53
  ---
49
54
 
55
+ ## Shared Context
56
+
57
+ ### Overview
58
+
59
+ During wave execution, parallel phases share a context file (`flow/.wave-context.jsonl`) that enables real-time coordination. Agents share API contracts, architectural decisions, and progress status via append-only JSONL entries. Before each task, sub-agents receive shared context from sibling phases, preventing broken contracts and duplicate decisions.
60
+
61
+ ### Lifecycle
62
+
63
+ 1. **Wave start**: Coordinator creates `flow/.wave-context.jsonl` (empty file) before spawning sub-agents
64
+ 2. **During execution**: Sub-agents append entries as they make decisions, define contracts, or complete tasks
65
+ 3. **Before each task**: Sub-agents read the shared context file to pick up entries from sibling phases
66
+ 4. **Wave end**: Coordinator reads the final context file for post-wave conflict detection
67
+ 5. **Cleanup**: Context file is deleted after the wave completes (each wave gets a fresh file)
68
+
69
+ ### Entry Format
70
+
71
+ Each line in `.wave-context.jsonl` is a JSON object with one of three types:
72
+
73
+ ```jsonl
74
+ {"type":"contract","phase":2,"task":1,"name":"UserAPI","signature":{"endpoint":"/api/users","method":"GET","response":"User[]"},"timestamp":"2024-01-15T10:30:00Z"}
75
+ {"type":"decision","phase":1,"task":2,"name":"auth-strategy","value":"JWT with refresh tokens","reason":"Aligns with existing session management","timestamp":"2024-01-15T10:31:00Z"}
76
+ {"type":"progress","phase":3,"task":1,"status":"complete","files_modified":["src/utils/helpers.ts"],"timestamp":"2024-01-15T10:32:00Z"}
77
+ ```
78
+
79
+ | Type | Purpose | Key Fields |
80
+ |------|---------|------------|
81
+ | `contract` | API shapes, interfaces, shared types | `name`, `signature` |
82
+ | `decision` | Architecture choices, technology selections | `name`, `value`, `reason` |
83
+ | `progress` | Task completion status, files touched | `status`, `files_modified` |
84
+
85
+ ### Sub-Agent Context Injection
86
+
87
+ When spawning each sub-agent, the coordinator includes in the context template:
88
+
89
+ ```
90
+ ## Shared Context (from sibling phases)
91
+
92
+ [Contents of flow/.wave-context.jsonl, if any entries exist]
93
+
94
+ RULES:
95
+ - Read shared context before starting each task
96
+ - Append contract/decision/progress entries as you work
97
+ - If a sibling defined a contract, use that exact signature
98
+ - If a sibling made an architecture decision, follow it
99
+ ```
100
+
101
+ For the first task in a wave, the context file may be empty. As phases progress, entries accumulate and inform subsequent tasks.
102
+
103
+ ---
104
+
50
105
  ## Dependency Analysis
51
106
 
52
107
  ### Dependency Declaration Syntax
@@ -229,6 +284,25 @@ For each pair of phases (A, B) in the wave:
229
284
 
230
285
  File conflict does NOT affect non-conflicting phases — their results are preserved.
231
286
 
287
+ ### Contract Conflict Detection
288
+
289
+ After collecting all wave results, parse `flow/.wave-context.jsonl` and check for **contract conflicts**:
290
+
291
+ ```
292
+ For each pair of "contract" entries with the same name:
293
+ if entry_A.signature != entry_B.signature:
294
+ → Contract conflict detected
295
+ ```
296
+
297
+ **On contract conflict**:
298
+ 1. Present the conflicting contract definitions — show the name, the two signatures, and which phases defined them
299
+ 2. Offer options:
300
+ - **(1) Pick one**: User selects which phase's contract to use; the other phase must be re-run with the chosen contract injected
301
+ - **(2) Re-run conflicting phases sequentially**: Re-execute only the conflicting phases in order, so the second phase sees the first's contract
302
+ - **(3) Stop execution**: Halt for manual resolution
303
+
304
+ Contract conflicts are checked **after** file conflicts. Both may exist simultaneously — present all conflicts before asking for resolution.
305
+
232
306
  ### Failure Handling
233
307
 
234
308
  | Scenario | Behavior |
@@ -312,6 +386,9 @@ When phases are aggregated (combined complexity ≤ 6), aggregated phases are tr
312
386
  9. **Reuse phase-isolation format** — sub-agent prompts and JSON returns follow phase-isolation.md exactly
313
387
  10. **Wave analysis is fast** — dependency parsing and topological sort add negligible overhead
314
388
  11. **Verification is internal to sub-agents** — per-task verification loops run entirely inside each phase sub-agent. The wave coordinator does not interact with verification; it only processes the final `task_verifications` field from the JSON return. See `.claude/resources/core/per-task-verification.md` for the complete verification system.
389
+ 12. **Shared context per wave** — each wave creates a fresh `.wave-context.jsonl` file, deleted after post-wave processing
390
+ 13. **Contract conflicts require user intervention** — never silently resolve conflicting contract signatures between parallel phases
391
+ 14. **Append-only context** — sub-agents only append to `.wave-context.jsonl`, never edit or delete existing entries
315
392
 
316
393
  ---
317
394
 
@@ -323,6 +400,7 @@ When phases are aggregated (combined complexity ≤ 6), aggregated phases are tr
323
400
  | `.claude/resources/core/discovery-sub-agents.md` | Parallel spawning pattern (3 agents → collect → merge) |
324
401
  | `.claude/resources/core/review-multi-agent.md` | Parallel agents with deduplication |
325
402
  | `.claude/resources/core/model-routing.md` | Model tier selection per phase complexity |
403
+ | `.claude/resources/core/shared-context.md` | Shared context file format, entry types, and coordination rules |
326
404
  | `.claude/resources/core/complexity-scoring.md` | Complexity scores and aggregation rules |
327
405
  | `.claude/resources/core/per-task-verification.md` | Per-task verification system, debug sub-agent, and repair loops |
328
406
  | `.claude/resources/skills/execute-plan-skill.md` | Execute-plan skill (Steps 2b, 3, 4 modified for waves) |