the-grid-cc 1.7.3 → 1.7.4
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/.grid-drafts/01-plan-execute-pipeline.md +709 -0
- package/.grid-drafts/02-auto-verify-default.md +867 -0
- package/.grid-drafts/03-quick-mode-detection.md +589 -0
- package/.grid-drafts/04-scratchpad-enforcement.md +669 -0
- package/README.md +13 -1
- package/assets/terminal-v3.svg +112 -0
- package/commands/grid/VERSION +1 -1
- package/commands/grid/mc.md +166 -7
- package/package.json +1 -1
- package/assets/terminal.svg +0 -120
|
@@ -0,0 +1,709 @@
|
|
|
1
|
+
# Feature: Plan-Execute Pipeline
|
|
2
|
+
|
|
3
|
+
## Research Summary
|
|
4
|
+
|
|
5
|
+
Based on analysis of 2026 multi-agent orchestration best practices and production systems, several key patterns emerge for effective plan-to-execution handoffs:
|
|
6
|
+
|
|
7
|
+
### Key Findings from Industry
|
|
8
|
+
|
|
9
|
+
**1. Structured Memory Passing (Multi-Agent Systems)**
|
|
10
|
+
- Modern multi-agent frameworks increasingly use **structured state objects** that flow between agents rather than file-based handoffs
|
|
11
|
+
- Systems like LangGraph, AutoGen, and CrewAI emphasize "shared memory" patterns where context flows directly through orchestration graphs
|
|
12
|
+
- The shift is from "read from disk" to "pass in memory" for hot-path data
|
|
13
|
+
|
|
14
|
+
**2. Plan-Execute Architecture Patterns**
|
|
15
|
+
- Plan-and-Execute agents (vs ReAct) separate planning from execution with **explicit data flow**
|
|
16
|
+
- Successful implementations return **structured plan objects** (YAML, JSON, or structured markdown) that executors consume directly
|
|
17
|
+
- File persistence happens in parallel to in-memory handoff, not as the primary mechanism
|
|
18
|
+
|
|
19
|
+
**3. Orchestrator Best Practices**
|
|
20
|
+
- Leading orchestrators (IBM research shows 45% reduction in handoffs) use **coordinator agents** that maintain working memory
|
|
21
|
+
- Plans are treated as **first-class data structures** in the orchestration layer, not just file artifacts
|
|
22
|
+
- Wave-based execution systems pass **plan metadata** (dependencies, wave assignments) separately from plan content
|
|
23
|
+
|
|
24
|
+
**4. Context Management Wisdom**
|
|
25
|
+
- Fresh agent spawns are expensive (~5-15% overhead from context assembly)
|
|
26
|
+
- Re-reading files that were just written is an anti-pattern in modern agent systems
|
|
27
|
+
- Best practice: "Write once for persistence, pass directly for execution"
|
|
28
|
+
|
|
29
|
+
**5. Structured vs. Unstructured Data**
|
|
30
|
+
- Markdown is human-readable but requires parsing on every handoff
|
|
31
|
+
- Hybrid approach: YAML frontmatter for machine-readable metadata + markdown body for human context
|
|
32
|
+
- Executors benefit from pre-parsed structures (no need to extract wave numbers, dependencies, etc.)
|
|
33
|
+
|
|
34
|
+
### What This Means for The Grid
|
|
35
|
+
|
|
36
|
+
Currently, The Grid's flow is:
|
|
37
|
+
```
|
|
38
|
+
Planner → writes PLAN.md to disk → returns filepath
|
|
39
|
+
MC → reads PLAN.md from disk → parses frontmatter → inlines content → spawns Executor
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
This is **3 I/O operations** (write, read, parse) for what should be a direct handoff. The industry research strongly suggests:
|
|
43
|
+
- Planner should return structured plan data directly to MC
|
|
44
|
+
- MC can immediately pass to Executor without re-reading disk
|
|
45
|
+
- File still gets written for persistence/audit trail, but handoff is direct
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Current Protocol
|
|
50
|
+
|
|
51
|
+
### How Planning Works Now (mc.md lines 172-215)
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
# WRONG - @-refs don't cross Task boundaries
|
|
55
|
+
Task(
|
|
56
|
+
prompt="Execute @.grid/phases/01-foundation/01-01-PLAN.md", # FAILS!
|
|
57
|
+
...
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
# CORRECT - Read and inline BEFORE spawning
|
|
61
|
+
STATE_CONTENT = read(".grid/STATE.md")
|
|
62
|
+
PLAN_CONTENT = read(".grid/phases/01-foundation/01-01-PLAN.md")
|
|
63
|
+
|
|
64
|
+
Task(
|
|
65
|
+
prompt=f"""
|
|
66
|
+
First, read ~/.claude/agents/grid-executor.md for your role.
|
|
67
|
+
|
|
68
|
+
<state>
|
|
69
|
+
{STATE_CONTENT}
|
|
70
|
+
</state>
|
|
71
|
+
|
|
72
|
+
<plan>
|
|
73
|
+
{PLAN_CONTENT}
|
|
74
|
+
</plan>
|
|
75
|
+
|
|
76
|
+
Execute the plan above.
|
|
77
|
+
""",
|
|
78
|
+
subagent_type="general-purpose",
|
|
79
|
+
description="Execute plan 01-01"
|
|
80
|
+
)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### The Problem
|
|
84
|
+
|
|
85
|
+
**Step 1:** MC spawns Planner
|
|
86
|
+
- Planner does all planning work
|
|
87
|
+
- Planner **writes** PLAN.md to disk
|
|
88
|
+
- Planner returns completion message with file paths
|
|
89
|
+
|
|
90
|
+
**Step 2:** MC spawns Executor
|
|
91
|
+
- MC **reads** the PLAN.md file Planner just wrote
|
|
92
|
+
- MC **inlines** the content into Executor prompt
|
|
93
|
+
- Only now can Executor begin
|
|
94
|
+
|
|
95
|
+
**This creates unnecessary latency:**
|
|
96
|
+
- Planner already has the plan content in memory
|
|
97
|
+
- MC must wait for file write to complete
|
|
98
|
+
- MC must re-read what was just written
|
|
99
|
+
- File I/O adds 50-200ms per plan (multiplied by wave count)
|
|
100
|
+
|
|
101
|
+
### What Planner Returns Now (planner.md lines 308-339)
|
|
102
|
+
|
|
103
|
+
```markdown
|
|
104
|
+
## PLANNING COMPLETE
|
|
105
|
+
|
|
106
|
+
**Cluster:** {name}
|
|
107
|
+
**Blocks:** {N} block(s) in {M} wave(s)
|
|
108
|
+
|
|
109
|
+
### Wave Structure
|
|
110
|
+
| Wave | Blocks | Autonomous |
|
|
111
|
+
|------|--------|------------|
|
|
112
|
+
| 1 | block-01, block-02 | yes, yes |
|
|
113
|
+
| 2 | block-03 | no |
|
|
114
|
+
|
|
115
|
+
### Blocks Created
|
|
116
|
+
| Block | Objective | Threads | Files |
|
|
117
|
+
|-------|-----------|---------|-------|
|
|
118
|
+
| 01 | [brief] | 2 | [files] |
|
|
119
|
+
| 02 | [brief] | 3 | [files] |
|
|
120
|
+
|
|
121
|
+
### Must-Haves Summary
|
|
122
|
+
| Truth | Supporting Artifacts |
|
|
123
|
+
|-------|---------------------|
|
|
124
|
+
| User can see messages | Chat.tsx, /api/chat |
|
|
125
|
+
|
|
126
|
+
### Next Steps
|
|
127
|
+
Execute: `/grid:execute` or Master Control will spawn Executors
|
|
128
|
+
|
|
129
|
+
End of Line.
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**Notice:** Planner returns a **summary table** but MC still needs to read the actual PLAN.md files to get:
|
|
133
|
+
- Full thread specifications
|
|
134
|
+
- Verification criteria
|
|
135
|
+
- Frontmatter metadata (wave, depends_on, files_modified)
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## Proposed Changes
|
|
140
|
+
|
|
141
|
+
### 1. Planner Returns Structured Plan Data
|
|
142
|
+
|
|
143
|
+
**Update planner.md completion section (lines 308-339):**
|
|
144
|
+
|
|
145
|
+
**BEFORE:**
|
|
146
|
+
```markdown
|
|
147
|
+
## COMPLETION MESSAGE
|
|
148
|
+
|
|
149
|
+
When planning complete, return:
|
|
150
|
+
|
|
151
|
+
```markdown
|
|
152
|
+
## PLANNING COMPLETE
|
|
153
|
+
|
|
154
|
+
**Cluster:** {name}
|
|
155
|
+
**Blocks:** {N} block(s) in {M} wave(s)
|
|
156
|
+
|
|
157
|
+
### Wave Structure
|
|
158
|
+
[table...]
|
|
159
|
+
|
|
160
|
+
### Next Steps
|
|
161
|
+
Execute: `/grid:execute` or Master Control will spawn Executors
|
|
162
|
+
|
|
163
|
+
End of Line.
|
|
164
|
+
```
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
**AFTER:**
|
|
168
|
+
```markdown
|
|
169
|
+
## COMPLETION MESSAGE
|
|
170
|
+
|
|
171
|
+
When planning complete, write all PLAN.md files to disk, then return structured data to Master Control:
|
|
172
|
+
|
|
173
|
+
```yaml
|
|
174
|
+
## PLANNING COMPLETE
|
|
175
|
+
|
|
176
|
+
cluster: {name}
|
|
177
|
+
total_blocks: {N}
|
|
178
|
+
total_waves: {M}
|
|
179
|
+
|
|
180
|
+
plans:
|
|
181
|
+
- id: "01"
|
|
182
|
+
path: ".grid/phases/01-foundation/01-PLAN.md"
|
|
183
|
+
wave: 1
|
|
184
|
+
depends_on: []
|
|
185
|
+
autonomous: true
|
|
186
|
+
files_modified: [list]
|
|
187
|
+
objective: "{brief objective}"
|
|
188
|
+
threads: 3
|
|
189
|
+
|
|
190
|
+
# Full plan content inline
|
|
191
|
+
frontmatter:
|
|
192
|
+
cluster: {name}
|
|
193
|
+
block: 01
|
|
194
|
+
type: execute
|
|
195
|
+
wave: 1
|
|
196
|
+
depends_on: []
|
|
197
|
+
files_modified: [list]
|
|
198
|
+
autonomous: true
|
|
199
|
+
must_haves:
|
|
200
|
+
truths: [list]
|
|
201
|
+
artifacts: [list]
|
|
202
|
+
key_links: [list]
|
|
203
|
+
|
|
204
|
+
content: |
|
|
205
|
+
<objective>
|
|
206
|
+
{full objective section}
|
|
207
|
+
</objective>
|
|
208
|
+
|
|
209
|
+
<context>
|
|
210
|
+
{full context section}
|
|
211
|
+
</context>
|
|
212
|
+
|
|
213
|
+
<threads>
|
|
214
|
+
{full threads XML}
|
|
215
|
+
</threads>
|
|
216
|
+
|
|
217
|
+
<verification>
|
|
218
|
+
{verification criteria}
|
|
219
|
+
</verification>
|
|
220
|
+
|
|
221
|
+
- id: "02"
|
|
222
|
+
path: ".grid/phases/01-foundation/02-PLAN.md"
|
|
223
|
+
wave: 1
|
|
224
|
+
depends_on: []
|
|
225
|
+
autonomous: true
|
|
226
|
+
files_modified: [list]
|
|
227
|
+
objective: "{brief objective}"
|
|
228
|
+
threads: 2
|
|
229
|
+
|
|
230
|
+
frontmatter: {...}
|
|
231
|
+
content: |
|
|
232
|
+
{...}
|
|
233
|
+
|
|
234
|
+
wave_structure:
|
|
235
|
+
1: ["01", "02"]
|
|
236
|
+
2: ["03"]
|
|
237
|
+
3: ["04", "05"]
|
|
238
|
+
|
|
239
|
+
must_haves_summary:
|
|
240
|
+
- truth: "User can see messages"
|
|
241
|
+
artifacts: ["Chat.tsx", "/api/chat"]
|
|
242
|
+
|
|
243
|
+
End of Line.
|
|
244
|
+
```
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### 2. MC Receives and Processes Plan Data Directly
|
|
248
|
+
|
|
249
|
+
**Update mc.md PROGRAM SPAWNING PROTOCOL section (lines 172-308):**
|
|
250
|
+
|
|
251
|
+
Add new subsection after "Available Programs" table:
|
|
252
|
+
|
|
253
|
+
```markdown
|
|
254
|
+
### Plan-Execute Direct Pipeline
|
|
255
|
+
|
|
256
|
+
**Planner returns structured plan data.** MC receives:
|
|
257
|
+
- All plan metadata (wave, depends_on, files_modified)
|
|
258
|
+
- Full plan content (ready to inline)
|
|
259
|
+
- File paths (for reference and warmth loading)
|
|
260
|
+
|
|
261
|
+
**MC workflow:**
|
|
262
|
+
1. Planner completes → returns YAML structure with inline plans
|
|
263
|
+
2. MC parses plan data (already in memory, no disk read needed)
|
|
264
|
+
3. MC spawns Executors with plan content directly
|
|
265
|
+
4. Files already written by Planner (for persistence/audit)
|
|
266
|
+
|
|
267
|
+
**Example flow:**
|
|
268
|
+
|
|
269
|
+
```python
|
|
270
|
+
# Step 1: Spawn Planner
|
|
271
|
+
planner_result = Task(
|
|
272
|
+
prompt=f"""
|
|
273
|
+
First, read ~/.claude/agents/grid-planner.md for your role.
|
|
274
|
+
|
|
275
|
+
<user_intent>{intent}</user_intent>
|
|
276
|
+
<state>{state}</state>
|
|
277
|
+
|
|
278
|
+
Create execution plans. Return structured YAML with inline plan content.
|
|
279
|
+
""",
|
|
280
|
+
subagent_type="general-purpose",
|
|
281
|
+
model="opus",
|
|
282
|
+
description="Create execution plans"
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
# Step 2: Parse plan data (already in memory!)
|
|
286
|
+
import yaml
|
|
287
|
+
plan_data = yaml.safe_load(planner_result)
|
|
288
|
+
|
|
289
|
+
# Step 3: Execute by wave (no file reads needed!)
|
|
290
|
+
for wave_num in sorted(plan_data['wave_structure'].keys()):
|
|
291
|
+
plan_ids = plan_data['wave_structure'][wave_num]
|
|
292
|
+
|
|
293
|
+
# Spawn executors in parallel for this wave
|
|
294
|
+
for plan_id in plan_ids:
|
|
295
|
+
plan = next(p for p in plan_data['plans'] if p['id'] == plan_id)
|
|
296
|
+
|
|
297
|
+
Task(
|
|
298
|
+
prompt=f"""
|
|
299
|
+
First, read ~/.claude/agents/grid-executor.md for your role.
|
|
300
|
+
|
|
301
|
+
<state>{STATE_CONTENT}</state>
|
|
302
|
+
|
|
303
|
+
<plan>
|
|
304
|
+
---
|
|
305
|
+
{yaml.dump(plan['frontmatter'])}
|
|
306
|
+
---
|
|
307
|
+
|
|
308
|
+
{plan['content']}
|
|
309
|
+
</plan>
|
|
310
|
+
|
|
311
|
+
Execute the plan above.
|
|
312
|
+
""",
|
|
313
|
+
subagent_type="general-purpose",
|
|
314
|
+
model=get_model("executor"),
|
|
315
|
+
description=f"Execute plan {plan_id}"
|
|
316
|
+
)
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
**Benefits:**
|
|
320
|
+
- Zero file reads between planning and execution
|
|
321
|
+
- MC has all plan metadata immediately (for smart spawn decisions)
|
|
322
|
+
- Wave execution can begin instantly after planning
|
|
323
|
+
- File still exists on disk for human inspection and warmth loading
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
### 3. Update Execute-and-Verify Primitive
|
|
327
|
+
|
|
328
|
+
**Update mc.md EXECUTE-AND-VERIFY PRIMITIVE section (lines 310-363):**
|
|
329
|
+
|
|
330
|
+
**BEFORE:**
|
|
331
|
+
```python
|
|
332
|
+
def execute_and_verify(plan_content, state_content, warmth=None):
|
|
333
|
+
"""Execute a plan and verify the result. Returns combined output."""
|
|
334
|
+
|
|
335
|
+
# 1. Spawn Executor
|
|
336
|
+
exec_result = Task(
|
|
337
|
+
prompt=f"""
|
|
338
|
+
First, read ~/.claude/agents/grid-executor.md for your role.
|
|
339
|
+
|
|
340
|
+
<state>{state_content}</state>
|
|
341
|
+
<plan>{plan_content}</plan>
|
|
342
|
+
{f'<warmth>{warmth}</warmth>' if warmth else ''}
|
|
343
|
+
|
|
344
|
+
Execute the plan. Include lessons_learned in your SUMMARY.
|
|
345
|
+
""",
|
|
346
|
+
subagent_type="general-purpose",
|
|
347
|
+
model="sonnet",
|
|
348
|
+
description="Execute plan"
|
|
349
|
+
)
|
|
350
|
+
# ... rest
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
**AFTER:**
|
|
354
|
+
```python
|
|
355
|
+
def execute_and_verify(plan_obj, state_content, warmth=None):
|
|
356
|
+
"""
|
|
357
|
+
Execute a plan and verify the result.
|
|
358
|
+
|
|
359
|
+
Args:
|
|
360
|
+
plan_obj: Plan object from Planner (dict with frontmatter + content)
|
|
361
|
+
state_content: Current STATE.md content
|
|
362
|
+
warmth: Optional warmth from prior Programs
|
|
363
|
+
|
|
364
|
+
Returns:
|
|
365
|
+
Combined execution and verification output
|
|
366
|
+
"""
|
|
367
|
+
|
|
368
|
+
# Reconstruct full plan markdown from object
|
|
369
|
+
plan_md = f"""---
|
|
370
|
+
{yaml.dump(plan_obj['frontmatter'])}
|
|
371
|
+
---
|
|
372
|
+
|
|
373
|
+
{plan_obj['content']}
|
|
374
|
+
"""
|
|
375
|
+
|
|
376
|
+
# 1. Spawn Executor (using direct plan data)
|
|
377
|
+
exec_result = Task(
|
|
378
|
+
prompt=f"""
|
|
379
|
+
First, read ~/.claude/agents/grid-executor.md for your role.
|
|
380
|
+
|
|
381
|
+
<state>{state_content}</state>
|
|
382
|
+
<plan>{plan_md}</plan>
|
|
383
|
+
{f'<warmth>{warmth}</warmth>' if warmth else ''}
|
|
384
|
+
|
|
385
|
+
Execute the plan. Include lessons_learned in your SUMMARY.
|
|
386
|
+
""",
|
|
387
|
+
subagent_type="general-purpose",
|
|
388
|
+
model="sonnet",
|
|
389
|
+
description=f"Execute plan {plan_obj['id']}"
|
|
390
|
+
)
|
|
391
|
+
|
|
392
|
+
# 2-4. Same as before (checkpoint handling, verification, etc.)
|
|
393
|
+
# ...
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
### 4. Backward Compatibility
|
|
397
|
+
|
|
398
|
+
**Files still written for:**
|
|
399
|
+
- Human inspection during development
|
|
400
|
+
- Warmth loading from SUMMARY.md
|
|
401
|
+
- Audit trail / debugging
|
|
402
|
+
- Resume after crashes
|
|
403
|
+
|
|
404
|
+
**What changes:**
|
|
405
|
+
- Hot path (MC → Executor handoff) uses in-memory plan objects
|
|
406
|
+
- Cold path (human reading, warmth loading) uses files
|
|
407
|
+
- Best of both worlds: fast execution + persistent audit trail
|
|
408
|
+
|
|
409
|
+
---
|
|
410
|
+
|
|
411
|
+
## Rationale
|
|
412
|
+
|
|
413
|
+
### Why This Is Better
|
|
414
|
+
|
|
415
|
+
**1. Performance**
|
|
416
|
+
- Eliminates 2-3 file I/O operations per plan
|
|
417
|
+
- Reduces handoff latency by ~50-200ms per plan
|
|
418
|
+
- Wave execution can begin immediately after planning completes
|
|
419
|
+
- For 10-plan projects: saves ~1-2 seconds in handoff overhead
|
|
420
|
+
|
|
421
|
+
**2. Architectural Clarity**
|
|
422
|
+
- Separates concerns: persistence vs. data flow
|
|
423
|
+
- Aligns with industry best practices (LangGraph, AutoGen patterns)
|
|
424
|
+
- MC maintains "working memory" of current plans
|
|
425
|
+
- Files are audit trail, not primary data pipeline
|
|
426
|
+
|
|
427
|
+
**3. Flexibility**
|
|
428
|
+
- MC can make smarter spawn decisions with full plan metadata
|
|
429
|
+
- Can adjust wave assignments dynamically if needed
|
|
430
|
+
- Can inspect plan structure before execution (spawn count formula)
|
|
431
|
+
- Easier to implement future features (plan merging, dynamic re-planning)
|
|
432
|
+
|
|
433
|
+
**4. Developer Experience**
|
|
434
|
+
- Fewer "magic file paths" to remember
|
|
435
|
+
- Clearer data flow (explicit structure vs. implicit files)
|
|
436
|
+
- Easier to debug (plan data visible in MC's output)
|
|
437
|
+
- Better TypeScript/type safety opportunities (structured objects)
|
|
438
|
+
|
|
439
|
+
**5. Consistency**
|
|
440
|
+
- Matches how Executor returns data (structured SUMMARY, not just file path)
|
|
441
|
+
- Matches how Recognizer returns data (structured VERIFICATION)
|
|
442
|
+
- Matches how debug sessions work (structured session objects)
|
|
443
|
+
|
|
444
|
+
### Why This Doesn't Break Existing Patterns
|
|
445
|
+
|
|
446
|
+
**Files still written:**
|
|
447
|
+
- Planner still writes PLAN.md to disk (nothing changes for Planner's file-writing logic)
|
|
448
|
+
- Executor still writes SUMMARY.md to disk
|
|
449
|
+
- Human inspection still works (files are there)
|
|
450
|
+
|
|
451
|
+
**What changes:**
|
|
452
|
+
- Planner's return value includes the plan data inline
|
|
453
|
+
- MC consumes plan data from return value, not from re-reading file
|
|
454
|
+
- Handoff is faster, but behavior is identical
|
|
455
|
+
|
|
456
|
+
**Wave execution still works:**
|
|
457
|
+
- Wave numbers still in frontmatter
|
|
458
|
+
- MC reads wave structure from plan objects (not parsing files)
|
|
459
|
+
- Parallel spawning unchanged (multiple Task calls in one message)
|
|
460
|
+
|
|
461
|
+
---
|
|
462
|
+
|
|
463
|
+
## Edge Cases Considered
|
|
464
|
+
|
|
465
|
+
### 1. Plan Content Too Large for YAML?
|
|
466
|
+
|
|
467
|
+
**Concern:** If plan content is massive, might blow up the YAML structure.
|
|
468
|
+
|
|
469
|
+
**Solution:**
|
|
470
|
+
- Current plans are ~200-500 lines of markdown
|
|
471
|
+
- YAML can handle this easily (text blocks with `|` indicator)
|
|
472
|
+
- If plan is >1000 lines, that's a signal it needs splitting anyway (per Grid guidelines)
|
|
473
|
+
- Worst case: fall back to file path only for truly massive plans
|
|
474
|
+
|
|
475
|
+
**Implementation:**
|
|
476
|
+
```python
|
|
477
|
+
# In planner completion logic
|
|
478
|
+
if len(plan_content) > 2000 lines:
|
|
479
|
+
# Fall back to path-only mode
|
|
480
|
+
plan_obj['content'] = "[Content too large - read from file]"
|
|
481
|
+
plan_obj['content_path'] = plan_path
|
|
482
|
+
else:
|
|
483
|
+
# Normal mode - inline content
|
|
484
|
+
plan_obj['content'] = plan_content
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
### 2. MC Crashes Between Planning and Execution?
|
|
488
|
+
|
|
489
|
+
**Concern:** If MC crashes after Planner completes but before spawning Executors, does MC lose the plan data?
|
|
490
|
+
|
|
491
|
+
**Solution:**
|
|
492
|
+
- Files are already written by Planner (persistent)
|
|
493
|
+
- On resume, MC can detect plans exist, read them from disk (cold start)
|
|
494
|
+
- This is the existing behavior (MC reads plans on resume anyway)
|
|
495
|
+
- New flow only optimizes the hot path (planning → immediate execution)
|
|
496
|
+
|
|
497
|
+
**Resume logic:**
|
|
498
|
+
```python
|
|
499
|
+
if resuming_project:
|
|
500
|
+
# Cold start - read plans from disk (current behavior)
|
|
501
|
+
plans = [read(path) for path in plan_paths]
|
|
502
|
+
else:
|
|
503
|
+
# Hot path - use plans from Planner's return value
|
|
504
|
+
plans = plan_data['plans']
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
### 3. Human Wants to Edit Plans Before Execution?
|
|
508
|
+
|
|
509
|
+
**Concern:** If user wants to manually edit PLAN.md before execution, will MC's in-memory copy be stale?
|
|
510
|
+
|
|
511
|
+
**Solution:**
|
|
512
|
+
- User edits file → MC detects file mtime > plan object timestamp
|
|
513
|
+
- MC asks: "Plans were edited. Re-read from disk or use original?"
|
|
514
|
+
- Default to re-reading (safer)
|
|
515
|
+
- This is rare edge case (AUTOPILOT mode doesn't pause for editing)
|
|
516
|
+
|
|
517
|
+
**Detection:**
|
|
518
|
+
```python
|
|
519
|
+
import os
|
|
520
|
+
|
|
521
|
+
for plan in plans:
|
|
522
|
+
file_mtime = os.path.getmtime(plan['path'])
|
|
523
|
+
if file_mtime > planning_completed_time:
|
|
524
|
+
print(f"Plan {plan['id']} was edited. Re-reading from disk.")
|
|
525
|
+
plan['content'] = read(plan['path'])
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
### 4. Checkpoint Resumes?
|
|
529
|
+
|
|
530
|
+
**Concern:** After checkpoint, continuation agent needs to read previous plan. Does this break?
|
|
531
|
+
|
|
532
|
+
**Solution:**
|
|
533
|
+
- Continuation agents already read from disk (they're fresh spawns)
|
|
534
|
+
- This change doesn't affect continuation flow
|
|
535
|
+
- MC still inlines plan content when spawning continuation agent
|
|
536
|
+
- Only the initial handoff (Planner → first Executor spawn) is optimized
|
|
537
|
+
|
|
538
|
+
**No change needed:**
|
|
539
|
+
```python
|
|
540
|
+
# Continuation spawn (already reads from disk for warmth anyway)
|
|
541
|
+
Task(
|
|
542
|
+
prompt=f"""
|
|
543
|
+
<completed_threads>{from_checkpoint}</completed_threads>
|
|
544
|
+
<plan>{read(plan_path)}</plan> # Still read from disk
|
|
545
|
+
<user_response>{user_input}</user_response>
|
|
546
|
+
|
|
547
|
+
Resume execution from thread {N+1}.
|
|
548
|
+
""",
|
|
549
|
+
...
|
|
550
|
+
)
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
### 5. Wave Dependencies Change During Execution?
|
|
554
|
+
|
|
555
|
+
**Concern:** If a plan fails and MC needs to re-plan, will wave structure be stale?
|
|
556
|
+
|
|
557
|
+
**Solution:**
|
|
558
|
+
- Re-planning spawns Planner again (fresh plan data returned)
|
|
559
|
+
- Old plan objects discarded, new ones used
|
|
560
|
+
- Wave structure is always current (comes from latest planning)
|
|
561
|
+
- This is safer than current file-based approach (no stale file reads)
|
|
562
|
+
|
|
563
|
+
### 6. Debugging / Inspection?
|
|
564
|
+
|
|
565
|
+
**Concern:** Will it be harder to debug if plans aren't just "read this file"?
|
|
566
|
+
|
|
567
|
+
**Solution:**
|
|
568
|
+
- Files still exist on disk (unchanged from user's perspective)
|
|
569
|
+
- MC can optionally log plan objects to `.grid/plan-objects.json` for debugging
|
|
570
|
+
- Actually easier: MC's output shows plan structure directly
|
|
571
|
+
- Dev tools can pretty-print plan objects from MC's output
|
|
572
|
+
|
|
573
|
+
**Debug output:**
|
|
574
|
+
```python
|
|
575
|
+
# Optional: write plan objects for debugging
|
|
576
|
+
with open(".grid/debug/plan-objects.json", "w") as f:
|
|
577
|
+
json.dump(plan_data, f, indent=2)
|
|
578
|
+
```
|
|
579
|
+
|
|
580
|
+
### 7. Multiple MC Sessions (Concurrent)?
|
|
581
|
+
|
|
582
|
+
**Concern:** If two MC instances run concurrently, could they conflict on plan data?
|
|
583
|
+
|
|
584
|
+
**Solution:**
|
|
585
|
+
- Not a real concern (Grid is single-session by design)
|
|
586
|
+
- If concurrent sessions happen, they're independent (different .grid/ dirs)
|
|
587
|
+
- Each MC gets its own plan objects from its own Planner spawn
|
|
588
|
+
- Files on disk are source of truth for cross-session coordination
|
|
589
|
+
|
|
590
|
+
---
|
|
591
|
+
|
|
592
|
+
## Migration Path
|
|
593
|
+
|
|
594
|
+
### Phase 1: Implement Return Format (Planner Change)
|
|
595
|
+
- Update `planner.md` completion message format
|
|
596
|
+
- Planner starts returning YAML with inline plan content
|
|
597
|
+
- Files still written (no change)
|
|
598
|
+
- Backward compatible: MC can ignore new format initially
|
|
599
|
+
|
|
600
|
+
### Phase 2: Implement Direct Pipeline (MC Change)
|
|
601
|
+
- Update `mc.md` to parse plan objects from Planner
|
|
602
|
+
- Add plan object → Executor spawning logic
|
|
603
|
+
- Keep fallback: if plan object missing, read from file (old behavior)
|
|
604
|
+
|
|
605
|
+
### Phase 3: Update Execute-and-Verify
|
|
606
|
+
- Change signature to accept plan objects instead of file paths
|
|
607
|
+
- Update all callers in mc.md
|
|
608
|
+
|
|
609
|
+
### Phase 4: Testing
|
|
610
|
+
- Test normal flow (planning → execution)
|
|
611
|
+
- Test resume flow (MC restart between planning and execution)
|
|
612
|
+
- Test checkpoint flow (continuation after user input)
|
|
613
|
+
- Test failure flow (re-planning after execution failure)
|
|
614
|
+
|
|
615
|
+
### Phase 5: Documentation
|
|
616
|
+
- Update mc.md comments with new flow diagram
|
|
617
|
+
- Add example to QUICK REFERENCE section
|
|
618
|
+
- Update Grid README if needed
|
|
619
|
+
|
|
620
|
+
---
|
|
621
|
+
|
|
622
|
+
## Implementation Checklist
|
|
623
|
+
|
|
624
|
+
**Planner (planner.md):**
|
|
625
|
+
- [ ] Update completion message format (lines 308-339)
|
|
626
|
+
- [ ] Add structured YAML output specification
|
|
627
|
+
- [ ] Ensure backward compatibility (files still written)
|
|
628
|
+
|
|
629
|
+
**Master Control (mc.md):**
|
|
630
|
+
- [ ] Add "Plan-Execute Direct Pipeline" section
|
|
631
|
+
- [ ] Update spawn example code
|
|
632
|
+
- [ ] Update execute_and_verify signature
|
|
633
|
+
- [ ] Add plan object parsing logic
|
|
634
|
+
- [ ] Add fallback for missing plan objects (resume cases)
|
|
635
|
+
- [ ] Update QUICK REFERENCE section
|
|
636
|
+
|
|
637
|
+
**Testing:**
|
|
638
|
+
- [ ] Test hot path (Planner → Executor direct)
|
|
639
|
+
- [ ] Test cold path (resume from disk)
|
|
640
|
+
- [ ] Test checkpoint continuation
|
|
641
|
+
- [ ] Test re-planning after failure
|
|
642
|
+
- [ ] Test large plan content (>1000 lines)
|
|
643
|
+
- [ ] Test concurrent wave execution
|
|
644
|
+
|
|
645
|
+
**Documentation:**
|
|
646
|
+
- [ ] Update mc.md QUICK REFERENCE
|
|
647
|
+
- [ ] Add flow diagram comment
|
|
648
|
+
- [ ] Update any Grid tutorials that show spawning
|
|
649
|
+
|
|
650
|
+
---
|
|
651
|
+
|
|
652
|
+
## Alternative Considered: Keep Current Approach
|
|
653
|
+
|
|
654
|
+
**Why not just keep reading from files?**
|
|
655
|
+
|
|
656
|
+
Arguments for status quo:
|
|
657
|
+
- It works (not broken)
|
|
658
|
+
- Simpler mental model (fewer abstractions)
|
|
659
|
+
- Files are self-documenting
|
|
660
|
+
|
|
661
|
+
Counter-arguments:
|
|
662
|
+
- Performance: 50-200ms per plan adds up (10 plans = 2 seconds wasted)
|
|
663
|
+
- Consistency: Other programs (Executor, Recognizer) return structured data
|
|
664
|
+
- Industry alignment: Modern orchestrators use direct handoffs
|
|
665
|
+
- Scalability: As Grid adds features (dynamic re-planning, plan merging), structured objects are easier to manipulate than re-parsing files
|
|
666
|
+
|
|
667
|
+
**Verdict:** The benefits outweigh the cost of change, especially as The Grid scales to larger projects.
|
|
668
|
+
|
|
669
|
+
---
|
|
670
|
+
|
|
671
|
+
## Success Metrics
|
|
672
|
+
|
|
673
|
+
After implementation, measure:
|
|
674
|
+
|
|
675
|
+
**Performance:**
|
|
676
|
+
- Planning → execution latency (expect 50-200ms improvement per plan)
|
|
677
|
+
- Total handoff time for 10-plan project (expect ~1-2 second improvement)
|
|
678
|
+
|
|
679
|
+
**Code Quality:**
|
|
680
|
+
- Lines of code in mc.md spawning logic (expect reduction)
|
|
681
|
+
- Number of file reads in hot path (expect 0 vs. current N reads)
|
|
682
|
+
|
|
683
|
+
**Reliability:**
|
|
684
|
+
- Resume success rate (should be unchanged)
|
|
685
|
+
- Checkpoint continuation success rate (should be unchanged)
|
|
686
|
+
|
|
687
|
+
**Developer Experience:**
|
|
688
|
+
- MC output clarity (plan structure visible vs. hidden in files)
|
|
689
|
+
- Debugging ease (can inspect plan objects directly)
|
|
690
|
+
|
|
691
|
+
---
|
|
692
|
+
|
|
693
|
+
## Conclusion
|
|
694
|
+
|
|
695
|
+
This feature brings The Grid's plan-execute handoff in line with 2026 industry best practices for multi-agent orchestration. By having Planner return structured plan data directly to MC, we:
|
|
696
|
+
|
|
697
|
+
1. **Eliminate unnecessary I/O** (2-3 file operations per plan)
|
|
698
|
+
2. **Improve handoff latency** (~50-200ms per plan)
|
|
699
|
+
3. **Maintain backward compatibility** (files still written for persistence)
|
|
700
|
+
4. **Enable future features** (dynamic re-planning, plan merging)
|
|
701
|
+
5. **Improve consistency** (all programs return structured data)
|
|
702
|
+
|
|
703
|
+
The change is surgical: Planner's return value includes inline plan content, MC consumes it directly instead of re-reading. Files remain for human inspection and audit trail. Wave-based execution is unaffected. Edge cases (crashes, checkpoints, resumes) are handled gracefully.
|
|
704
|
+
|
|
705
|
+
This is a foundation upgrade that makes The Grid faster, more maintainable, and better aligned with production multi-agent systems.
|
|
706
|
+
|
|
707
|
+
**Recommendation:** Implement in Grid 1.7.2, with careful testing of resume and checkpoint flows.
|
|
708
|
+
|
|
709
|
+
End of Line.
|