the-grid-cc 1.7.13 → 1.7.14

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.
@@ -0,0 +1,950 @@
1
+ # MC Protocols Reference
2
+
3
+ This document contains detailed protocol specifications for Grid operations. Agents read this for full implementation details. MC contains summaries; this document contains the complete specifications.
4
+
5
+ ---
6
+
7
+ ## PROGRAM SPAWNING PROTOCOL
8
+
9
+ ### Plan-Execute Direct Pipeline
10
+
11
+ **Planner returns structured plan data.** MC receives plans directly in memory, no re-reading from disk.
12
+
13
+ **Planner completion format:**
14
+ ```yaml
15
+ ## PLANNING COMPLETE
16
+
17
+ cluster: {name}
18
+ total_blocks: {N}
19
+ total_waves: {M}
20
+
21
+ plans:
22
+ - id: "01"
23
+ path: ".grid/phases/01-foundation/01-PLAN.md"
24
+ wave: 1
25
+ depends_on: []
26
+ autonomous: true
27
+ files_modified: [list]
28
+ objective: "{brief objective}"
29
+
30
+ frontmatter: {full YAML frontmatter}
31
+ content: |
32
+ <objective>...</objective>
33
+ <context>...</context>
34
+ <threads>...</threads>
35
+
36
+ wave_structure:
37
+ 1: ["01", "02"]
38
+ 2: ["03"]
39
+ ```
40
+
41
+ **MC workflow:**
42
+ ```python
43
+ # Step 1: Spawn Planner
44
+ planner_result = Task(prompt="...", ...)
45
+
46
+ # Step 2: Parse plan data (already in memory!)
47
+ plan_data = parse_yaml(planner_result)
48
+
49
+ # Step 3: Execute by wave (no file reads needed!)
50
+ for wave_num in sorted(plan_data['wave_structure'].keys()):
51
+ for plan_id in plan_data['wave_structure'][wave_num]:
52
+ plan = get_plan_by_id(plan_data['plans'], plan_id)
53
+
54
+ Task(
55
+ prompt=f"""
56
+ First, read ~/.claude/agents/grid-executor.md for your role.
57
+
58
+ <plan>
59
+ ---
60
+ {plan['frontmatter']}
61
+ ---
62
+ {plan['content']}
63
+ </plan>
64
+
65
+ Execute the plan.
66
+ """,
67
+ ...
68
+ )
69
+ ```
70
+
71
+ **Benefits:**
72
+ - Zero file reads between planning and execution
73
+ - MC has all plan metadata immediately
74
+ - Wave execution begins instantly after planning
75
+ - Files still written by Planner (for persistence/audit)
76
+
77
+ ---
78
+
79
+ ## WAVE EXECUTION PROTOCOL
80
+
81
+ Plans are assigned **wave numbers** during planning. Execute waves sequentially, with **automatic verification** after each wave:
82
+
83
+ ```
84
+ WAVE 1: [plan-01, plan-02]
85
+ |-- Spawn Executors (parallel)
86
+ |-- Wait for completion
87
+ |-- Auto-spawn Recognizer (wave-level verification)
88
+ |-- If GAPS_FOUND -> Spawn Planner --gaps
89
+ v
90
+ WAVE 2: [plan-03]
91
+ |-- Spawn Executor
92
+ |-- Wait for completion
93
+ |-- Auto-spawn Recognizer
94
+ |-- If CLEAR -> Proceed
95
+ v
96
+ WAVE 3: [plan-04, plan-05]
97
+ |-- Spawn Executors (parallel)
98
+ |-- Wait for completion
99
+ |-- Auto-spawn Recognizer
100
+ ```
101
+
102
+ **Verification Timing:** Wave-level, not plan-level. This prevents redundant checks on interdependent plans.
103
+
104
+ **Verification Skipped When:**
105
+ - Executor returned CHECKPOINT (incomplete work)
106
+ - Executor returned FAILURE (broken state)
107
+ - Plan frontmatter has `verify: false`
108
+ - User said "skip verification"
109
+
110
+ Read wave numbers from plan frontmatter:
111
+ ```yaml
112
+ ---
113
+ phase: 01-foundation
114
+ plan: 02
115
+ wave: 1
116
+ depends_on: []
117
+ ---
118
+ ```
119
+
120
+ ---
121
+
122
+ ## EXECUTE-AND-VERIFY PRIMITIVE
123
+
124
+ **Verification is AUTOMATIC after successful execution.** The atomic unit is:
125
+ ```
126
+ Executor -> (if SUCCESS) -> Recognizer -> (if GAPS) -> Planner --gaps
127
+ ```
128
+
129
+ ### Protocol
130
+
131
+ **1. Executor completes with status:**
132
+ - `SUCCESS` -> Auto-spawn Recognizer (default path)
133
+ - `CHECKPOINT` -> Return to MC, don't verify incomplete work
134
+ - `FAILURE` -> Return to MC with structured failure report
135
+
136
+ **2. Recognizer spawns AUTOMATICALLY unless:**
137
+ - Executor returned CHECKPOINT (incomplete work)
138
+ - Executor returned FAILURE (broken build)
139
+ - Plan frontmatter contains `verify: false`
140
+ - User explicitly said "skip verification"
141
+
142
+ ### Wave Execution with Auto-Verify
143
+
144
+ ```python
145
+ def execute_wave(wave_plans, state_content, warmth=None):
146
+ """Execute a wave and auto-verify results."""
147
+
148
+ # 1. Spawn all Executors in wave (parallel)
149
+ exec_results = []
150
+ for plan in wave_plans:
151
+ result = Task(
152
+ prompt=f"""
153
+ First, read ~/.claude/agents/grid-executor.md for your role.
154
+
155
+ <state>{state_content}</state>
156
+ <plan>{plan['content']}</plan>
157
+ {f'<warmth>{warmth}</warmth>' if warmth else ''}
158
+
159
+ <scratchpad_rules>
160
+ You MUST write to .grid/SCRATCHPAD.md during execution:
161
+ 1. On discovering codebase patterns (IMMEDIATELY)
162
+ 2. On making decisions affecting other areas (BEFORE COMMITTING)
163
+ 3. On finding blockers (IMMEDIATELY)
164
+ 4. On long work (EVERY 5 MINUTES as progress heartbeat)
165
+
166
+ Before starting, READ scratchpad to see what other Programs learned.
167
+ </scratchpad_rules>
168
+
169
+ Execute the plan. Return SUCCESS | CHECKPOINT | FAILURE.
170
+ Include lessons_learned in your SUMMARY.
171
+ """,
172
+ subagent_type="general-purpose",
173
+ model=get_model("executor"),
174
+ description=f"Execute {plan['id']}"
175
+ )
176
+ exec_results.append((plan, result))
177
+
178
+ # 2. Analyze wave results
179
+ checkpoints = [r for r in exec_results if "CHECKPOINT" in r[1]]
180
+ failures = [r for r in exec_results if "FAILURE" in r[1]]
181
+
182
+ if checkpoints:
183
+ return {"status": "CHECKPOINT", "details": checkpoints}
184
+ if failures:
185
+ return {"status": "FAILURE", "details": failures}
186
+
187
+ # 3. Skip verification if opted out
188
+ if should_skip_verification(wave_plans):
189
+ return {"status": "SUCCESS", "verification": "SKIPPED"}
190
+
191
+ # 4. Collect summaries for wave
192
+ summaries = collect_wave_summaries(wave_plans)
193
+ must_haves = extract_wave_must_haves(wave_plans)
194
+
195
+ # 5. Auto-spawn Recognizer
196
+ verify_result = Task(
197
+ prompt=f"""
198
+ First, read ~/.claude/agents/grid-recognizer.md for your role.
199
+
200
+ PATROL MODE: Wave verification
201
+
202
+ <wave_summaries>
203
+ {summaries}
204
+ </wave_summaries>
205
+
206
+ <must_haves>
207
+ {must_haves}
208
+ </must_haves>
209
+
210
+ Verify goal achievement. Three-level check:
211
+ 1. Existence
212
+ 2. Substantive (not stubs)
213
+ 3. Wired (connected to system)
214
+
215
+ Return: CLEAR | GAPS_FOUND | CRITICAL_ANOMALY
216
+ """,
217
+ subagent_type="general-purpose",
218
+ model=get_model("recognizer"),
219
+ description=f"Verify wave"
220
+ )
221
+
222
+ # 6. Handle gaps
223
+ if "GAPS_FOUND" in verify_result:
224
+ gaps = extract_gaps(verify_result)
225
+ gap_plan = spawn_planner_gaps(gaps, state_content)
226
+ return {"status": "GAPS_FOUND", "verification": verify_result, "gap_closure": gap_plan}
227
+
228
+ return {"status": "VERIFIED", "verification": verify_result}
229
+
230
+
231
+ def should_skip_verification(wave_plans):
232
+ """Check if verification should be skipped."""
233
+ for plan in wave_plans:
234
+ if plan.get('frontmatter', {}).get('verify') == False:
235
+ return True
236
+ return session_state.get("skip_verification", False)
237
+ ```
238
+
239
+ ### Opt-Out Mechanism
240
+
241
+ **Plan-level:** Add `verify: false` to frontmatter:
242
+ ```yaml
243
+ ---
244
+ wave: 1
245
+ verify: false
246
+ verify_reason: "Prototype/throwaway code"
247
+ ---
248
+ ```
249
+
250
+ **Session-level:** User says "skip verification for this session"
251
+
252
+ ---
253
+
254
+ ## WARMTH TRANSFER PROTOCOL
255
+
256
+ **Programs die, but their knowledge shouldn't.**
257
+
258
+ When spawning a continuation or fresh Program after another completes:
259
+
260
+ ### 1. Extract Warmth from Dying Program
261
+
262
+ Programs include `lessons_learned` in their SUMMARY.md:
263
+
264
+ ```yaml
265
+ ---
266
+ # ... other frontmatter
267
+ lessons_learned:
268
+ codebase_patterns:
269
+ - "This codebase uses barrel exports (index.ts)"
270
+ - "API routes expect req.json() not req.body"
271
+ gotchas:
272
+ - "The auth middleware runs before validation"
273
+ - "Database timestamps are UTC, not local"
274
+ user_preferences:
275
+ - "User prefers explicit error messages"
276
+ - "User wants mobile-first styling"
277
+ almost_did:
278
+ - "Considered using Zustand but stuck with useState for simplicity"
279
+ ---
280
+ ```
281
+
282
+ ### 2. Pass Warmth to Fresh Program
283
+
284
+ ```python
285
+ Task(
286
+ prompt=f"""
287
+ First, read ~/.claude/agents/grid-executor.md for your role.
288
+
289
+ <warmth>
290
+ Previous Program learned:
291
+ {lessons_learned_yaml}
292
+ </warmth>
293
+
294
+ <state>{state}</state>
295
+ <plan>{plan}</plan>
296
+
297
+ Apply the warmth above. Don't repeat mistakes. Build on discoveries.
298
+ """,
299
+ ...
300
+ )
301
+ ```
302
+
303
+ ### 3. Warmth Categories
304
+
305
+ | Category | Contents |
306
+ |----------|----------|
307
+ | `codebase_patterns` | How this codebase does things |
308
+ | `gotchas` | Traps to avoid |
309
+ | `user_preferences` | What User seems to want |
310
+ | `almost_did` | Decisions considered but rejected (with why) |
311
+ | `fragile_areas` | Code that breaks easily |
312
+
313
+ ---
314
+
315
+ ## SCRATCHPAD PROTOCOL
316
+
317
+ **Mandatory observability during execution.** Programs MUST write to scratchpad--it's not optional.
318
+
319
+ `.grid/SCRATCHPAD.md` - Programs write here during execution, not just at end.
320
+
321
+ ### Mandatory Writing Rules
322
+
323
+ Executors MUST write to scratchpad in these situations:
324
+
325
+ 1. **On unexpected codebase patterns** (WRITE IMMEDIATELY)
326
+ - File structure differs from assumption
327
+ - Naming conventions found (e.g., displayName not name)
328
+ - API patterns (e.g., req.json() not req.body)
329
+
330
+ 2. **On decisions affecting other areas** (WRITE BEFORE COMMITTING)
331
+ - Choosing library A over B
332
+ - Schema changes
333
+ - API contract changes
334
+
335
+ 3. **On finding blockers or gotchas** (WRITE IMMEDIATELY)
336
+ - Missing dependencies
337
+ - Authentication requirements
338
+ - External service configuration needs
339
+
340
+ 4. **On long-running work** (WRITE EVERY 5 MINUTES)
341
+ - Progress heartbeat: "Still working on X, 60% complete"
342
+ - Prevents MC from thinking agent died
343
+
344
+ **Failure to write = protocol violation.** Recognizer checks for scratchpad entries.
345
+
346
+ ### Entry Format
347
+
348
+ Each entry MUST follow this structure:
349
+
350
+ ```
351
+ ### {program-id} | {ISO-timestamp} | {category}
352
+
353
+ **Finding:** {one clear sentence}
354
+
355
+ **Impact:** {who needs to know / areas affected}
356
+
357
+ **Action:** [INFORM_ONLY | REQUIRES_CHANGE | BLOCKER]
358
+
359
+ **Details:**
360
+ {Additional context, file paths}
361
+ ```
362
+
363
+ **Categories:**
364
+ - `PATTERN` - Codebase pattern discovered
365
+ - `DECISION` - Decision made affecting other work
366
+ - `BLOCKER` - Blocking issue found
367
+ - `PROGRESS` - Heartbeat progress update
368
+ - `CORRECTION` - Correcting a previous entry
369
+
370
+ ### MC Monitoring During Execution
371
+
372
+ MC actively monitors scratchpad while Programs execute:
373
+
374
+ ```python
375
+ def monitor_scratchpad_during_wave(active_programs, wave_start_time):
376
+ """Monitor scratchpad for updates while Programs execute."""
377
+ last_check = wave_start_time
378
+ max_silence = timedelta(minutes=10)
379
+
380
+ while programs_still_running(active_programs):
381
+ time.sleep(30) # Check every 30 seconds
382
+ scratchpad = read(".grid/SCRATCHPAD.md")
383
+ new_entries = parse_entries_since(scratchpad, last_check)
384
+
385
+ if new_entries:
386
+ display_live_updates(new_entries)
387
+ last_check = datetime.now()
388
+
389
+ # Alert on stalled agents
390
+ for program in active_programs:
391
+ if time_since_last_entry(program) > max_silence:
392
+ alert_user(f"{program} hasn't written in 10 minutes")
393
+ ```
394
+
395
+ **Display live updates:**
396
+ ```
397
+ Live Updates from Executors:
398
+ |-- executor-01 (14:32): Found pattern - using displayName not name
399
+ |-- executor-02 (14:35): Decision - chose JWT over sessions
400
+ |-- executor-01 (14:40): Progress - Auth endpoints 60% done
401
+ |-- executor-03 (14:42): BLOCKER - Missing Stripe API keys
402
+ ```
403
+
404
+ ### Archival After Wave Completion
405
+
406
+ After wave completes, archive scratchpad:
407
+
408
+ ```python
409
+ def archive_scratchpad(wave_number, phase, block):
410
+ scratchpad = read(".grid/SCRATCHPAD.md")
411
+ archive_entry = f"""
412
+ ---
413
+ wave: {wave_number}
414
+ phase: {phase}
415
+ archived: {datetime.now().isoformat()}
416
+ ---
417
+
418
+ {scratchpad}
419
+ """
420
+ append(".grid/SCRATCHPAD_ARCHIVE.md", archive_entry)
421
+
422
+ # Clear for next wave
423
+ write(".grid/SCRATCHPAD.md", "---\nupdated: ...\nactive_programs: []\n---\n")
424
+ ```
425
+
426
+ ---
427
+
428
+ ## CHECKPOINT PROTOCOL
429
+
430
+ When a Program hits a checkpoint, it returns structured data:
431
+
432
+ ```markdown
433
+ ## CHECKPOINT REACHED
434
+
435
+ **Type:** [human-verify | decision | human-action]
436
+ **Block:** {block-id}
437
+ **Progress:** {completed}/{total} threads complete
438
+
439
+ ### Completed Threads
440
+ | Thread | Name | Commit | Files |
441
+ | ------ | ---- | ------ | ----- |
442
+ | 1.1 | ... | abc123 | ... |
443
+
444
+ ### Current Thread
445
+ **Thread {N}:** [name]
446
+ **Status:** [blocked | awaiting verification]
447
+
448
+ ### Checkpoint Details
449
+ [Type-specific content]
450
+
451
+ ### Awaiting
452
+ [What User needs to do]
453
+ ```
454
+
455
+ **MC response:**
456
+ 1. Present checkpoint to User via I/O Tower
457
+ 2. Collect User response
458
+ 3. Spawn FRESH continuation Program (not resume) with:
459
+ - Completed threads table
460
+ - User's response
461
+ - Resume point
462
+ - **Warmth from prior Program**
463
+
464
+ ### Checkpoint Types
465
+
466
+ | Type | Use | Frequency |
467
+ |------|-----|-----------|
468
+ | `human-verify` | User confirms automation works | 90% |
469
+ | `decision` | User chooses between options | 9% |
470
+ | `human-action` | Unavoidable manual step (2FA, email link) | 1% |
471
+
472
+ ### Type-Specific Content
473
+
474
+ **human-verify:**
475
+ ```markdown
476
+ **What was built:**
477
+ {Description of completed work}
478
+
479
+ **How to verify:**
480
+ 1. {Step 1 - exact URL/command}
481
+ 2. {Step 2 - what to check}
482
+ 3. {Expected behavior}
483
+ ```
484
+
485
+ **decision:**
486
+ ```markdown
487
+ **Decision needed:**
488
+ {What's being decided}
489
+
490
+ **Options:**
491
+ | Option | Pros | Cons |
492
+ |--------|------|------|
493
+ | option-a | {benefits} | {tradeoffs} |
494
+ | option-b | {benefits} | {tradeoffs} |
495
+ ```
496
+
497
+ **human-action:**
498
+ ```markdown
499
+ **Automation attempted:**
500
+ {What you already did via CLI/API}
501
+
502
+ **What you need to do:**
503
+ {Single unavoidable step}
504
+
505
+ **I'll verify after:**
506
+ {Verification command/check}
507
+ ```
508
+
509
+ ---
510
+
511
+ ## RETRY PROTOCOL
512
+
513
+ **When Programs fail, don't retry blind.**
514
+
515
+ ### Structured Failure Report
516
+
517
+ Programs return on failure:
518
+ ```yaml
519
+ ## EXECUTION FAILED
520
+
521
+ **Block:** {block-id}
522
+ **Thread:** {thread that failed}
523
+ **Attempts:** {N}
524
+
525
+ ### What Was Tried
526
+ 1. {Approach 1} -- Failed because: {reason}
527
+ 2. {Approach 2} -- Failed because: {reason}
528
+
529
+ ### Partial Work
530
+ - Created: {files created before failure}
531
+ - Commits: {commits made}
532
+
533
+ ### Hypothesis
534
+ {Why it's failing}
535
+
536
+ ### Suggested Retry Approach
537
+ {Different approach to try}
538
+
539
+ ### Do NOT Retry
540
+ - {Approach that definitely won't work}
541
+ ```
542
+
543
+ ### Retry Spawning
544
+
545
+ Pass failure context to retry:
546
+ ```python
547
+ Task(
548
+ prompt=f"""
549
+ First, read ~/.claude/agents/grid-executor.md for your role.
550
+
551
+ <prior_failure>
552
+ {failure_report}
553
+ </prior_failure>
554
+
555
+ <state>{state}</state>
556
+ <plan>{plan}</plan>
557
+
558
+ Previous attempt failed. DO NOT repeat failed approaches.
559
+ Try the suggested retry approach or a novel approach.
560
+ """,
561
+ subagent_type="general-purpose",
562
+ model="sonnet", # Maybe upgrade to opus for retries
563
+ description="Retry execution"
564
+ )
565
+ ```
566
+
567
+ ---
568
+
569
+ ## STATE MANAGEMENT
570
+
571
+ ### STATE.md Structure
572
+
573
+ Check `.grid/STATE.md` on startup. If it exists, load context:
574
+
575
+ ```markdown
576
+ ---
577
+ cluster: React Todo App
578
+ current_phase: 02
579
+ current_block: 01
580
+ status: in_progress
581
+ ---
582
+
583
+ ## Current Position
584
+ Phase: 2 of 4 (Authentication)
585
+ Block: 1 of 3
586
+ Status: In progress
587
+
588
+ Progress: [|||||||| ] 25%
589
+
590
+ ## Decisions Made
591
+ - Use JWT with refresh rotation
592
+ - httpOnly cookies for tokens
593
+
594
+ ## Blockers/Concerns
595
+ - CORS headers need careful handling
596
+
597
+ ## Session Continuity
598
+ Last session: 2024-01-23 14:30
599
+ Stopped at: Block 2.1 checkpoint
600
+ ```
601
+
602
+ ### SUMMARY.md Per Plan
603
+
604
+ After each plan completes, ensure SUMMARY.md exists with frontmatter:
605
+
606
+ ```yaml
607
+ ---
608
+ phase: 01-foundation
609
+ plan: 02
610
+ subsystem: auth
611
+ requires:
612
+ - phase: 01-foundation
613
+ provides: "Database setup"
614
+ provides:
615
+ - "JWT auth endpoints"
616
+ affects:
617
+ - 02-dashboard (uses auth)
618
+ tech-stack:
619
+ added: [jose, bcrypt]
620
+ key-files:
621
+ created: [src/lib/auth.ts]
622
+ modified: [prisma/schema.prisma]
623
+ commits: [abc123, def456]
624
+
625
+ # WARMTH - knowledge that survives
626
+ lessons_learned:
627
+ codebase_patterns:
628
+ - "Pattern discovered"
629
+ gotchas:
630
+ - "Gotcha found"
631
+ almost_did:
632
+ - "Considered X, chose Y because Z"
633
+ ---
634
+ ```
635
+
636
+ This frontmatter enables fast context assembly AND warmth transfer.
637
+
638
+ ---
639
+
640
+ ## EXPERIENCE REPLAY
641
+
642
+ Master Control learns from past projects. This institutional memory improves planning decisions over time.
643
+
644
+ ### Session Startup
645
+
646
+ On every session start, check for and load learnings:
647
+
648
+ ```python
649
+ LEARNINGS_PATH = ".grid/LEARNINGS.md"
650
+
651
+ if file_exists(LEARNINGS_PATH):
652
+ learnings = read(LEARNINGS_PATH)
653
+ # Parse and apply relevant learnings to current context
654
+ ```
655
+
656
+ **What to extract from learnings:**
657
+ - Similar project types -> What worked before
658
+ - Common failure patterns -> What to avoid
659
+ - Successful patterns -> What to replicate
660
+ - Tech stack experiences -> Informed choices
661
+
662
+ ### Post-Project Capture
663
+
664
+ After project completion (all phases done, Recognizer verified), capture learnings:
665
+
666
+ ```python
667
+ Task(
668
+ prompt=f"""
669
+ First, read ~/.claude/agents/grid-executor.md for your role.
670
+
671
+ Analyze this completed project and extract learnings.
672
+
673
+ <project_context>
674
+ {STATE_CONTENT}
675
+ </project_context>
676
+
677
+ <all_summaries>
678
+ {COLLECTED_SUMMARIES}
679
+ </all_summaries>
680
+
681
+ Write findings to .grid/LEARNINGS.md using the append format below.
682
+ Focus on actionable patterns, not project-specific details.
683
+ """,
684
+ subagent_type="general-purpose",
685
+ model="sonnet",
686
+ description="Capture project learnings"
687
+ )
688
+ ```
689
+
690
+ ### LEARNINGS.md Format
691
+
692
+ ```markdown
693
+ # Grid Learnings
694
+
695
+ Accumulated patterns from past projects. Read at session start, write after completion.
696
+
697
+ ---
698
+
699
+ ## Entry: {YYYY-MM-DD} - {Project Name}
700
+
701
+ **Project Type:** {web-app | api | cli | library | integration | etc}
702
+ **Tech Stack:** {key technologies used}
703
+ **Complexity:** {simple | medium | complex | massive}
704
+
705
+ ### What Worked
706
+ - {Pattern or approach that succeeded}
707
+
708
+ ### What Failed
709
+ - {Approach that caused problems} -> {How it was fixed}
710
+
711
+ ### Patterns Discovered
712
+ - **{Pattern Name}:** {Description of reusable pattern}
713
+
714
+ ### Recommendations for Similar Projects
715
+ - {Specific actionable advice}
716
+
717
+ ---
718
+ ```
719
+
720
+ ---
721
+
722
+ ## PROGRESS UPDATES FORMAT
723
+
724
+ Never leave User in darkness. Show what's happening (including automatic verification):
725
+
726
+ ```
727
+ Executing Wave 1...
728
+ |-- Spawning Executors: plan-01, plan-02 (parallel)
729
+ | |-- plan-01: Creating components... [done]
730
+ | |-- plan-02: Writing API routes... [done]
731
+ |-- Executors complete
732
+ |-- Auto-spawning Recognizer...
733
+ | |-- Verifying artifacts and goal achievement... [done] CLEAR
734
+ |-- Wave 1 verified
735
+
736
+ Executing Wave 2...
737
+ |-- Spawning Executor: plan-03
738
+ | |-- plan-03: Integrating auth... [done]
739
+ |-- Auto-spawning Recognizer...
740
+ | |-- Verifying artifacts... [warning] GAPS_FOUND
741
+ |-- Spawning Planner for gap closure...
742
+ | |-- Creating closure plan... [done]
743
+ |-- Wave 2 needs fixes (gap closure plan ready)
744
+
745
+ Live Scratchpad Updates:
746
+ |-- executor-01 (14:32): Found pattern - using displayName
747
+ |-- executor-02 (14:35): Decision - chose JWT over sessions
748
+
749
+ End of Line.
750
+ ```
751
+
752
+ The "Auto-spawning Recognizer" line shows verification is automatic, not manual.
753
+
754
+ ---
755
+
756
+ ## VERIFICATION (RECOGNIZER)
757
+
758
+ After execution completes, spawn Recognizer for goal-backward verification:
759
+
760
+ **Three-Level Artifact Check:**
761
+ 1. **Existence** - Does the file exist?
762
+ 2. **Substantive** - Is it real code (not stub)? Min lines, no TODO/FIXME
763
+ 3. **Wired** - Is it connected to the system?
764
+
765
+ **Stub Detection Patterns:**
766
+ ```
767
+ TODO|FIXME|PLACEHOLDER
768
+ return null|return {}|return []
769
+ <div>Component</div>
770
+ onClick={() => {}}
771
+ ```
772
+
773
+ If Recognizer finds gaps, spawn Planner with `--gaps` flag to create closure plans.
774
+
775
+ ### Recognizer Patrol Mode
776
+
777
+ After execution waves complete, spawn Recognizer in patrol mode:
778
+
779
+ ```python
780
+ Task(
781
+ prompt=f"""
782
+ First, read ~/.claude/agents/grid-recognizer.md for your role.
783
+
784
+ PATROL MODE ACTIVATED.
785
+
786
+ <block_summaries>
787
+ {all_summary_contents}
788
+ </block_summaries>
789
+
790
+ <must_haves>
791
+ {from_plan_frontmatter}
792
+ </must_haves>
793
+
794
+ Survey all completed work. Verify goal achievement, not just task completion.
795
+ Report gaps structured in YAML for gap closure planning.
796
+ """,
797
+ subagent_type="general-purpose",
798
+ model="sonnet",
799
+ description="Patrol completed blocks"
800
+ )
801
+ ```
802
+
803
+ Recognizer returns VERIFICATION.md with gaps -> Spawn Planner with `--gaps` flag.
804
+
805
+ ---
806
+
807
+ ## DEBUG SESSION MANAGEMENT
808
+
809
+ Debug sessions persist in `.grid/debug/` and survive `/clear`:
810
+
811
+ ### Debug Session Structure
812
+
813
+ ```markdown
814
+ ---
815
+ session_id: {timestamp}-{slug}
816
+ symptoms: [immutable list]
817
+ status: investigating | hypothesis | testing | resolved
818
+ created: {ISO timestamp}
819
+ updated: {ISO timestamp}
820
+ ---
821
+
822
+ ## Investigation Graph
823
+
824
+ ### Hypotheses
825
+ | # | Hypothesis | Status | Evidence |
826
+ |---|------------|--------|----------|
827
+ | 1 | Auth token expired | RULED OUT | Token valid per jwt.io |
828
+ | 2 | CORS misconfigured | TESTING | Seeing preflight fail |
829
+
830
+ ### Tried
831
+ - Checked token expiry -> Valid
832
+ - Checked network tab -> CORS error on preflight
833
+
834
+ ### Ruled Out
835
+ - Token issues (verified valid)
836
+ - Server down (other endpoints work)
837
+
838
+ ### Current Focus
839
+ CORS configuration in API route
840
+
841
+ ## Findings
842
+ {Updated as investigation proceeds}
843
+ ```
844
+
845
+ This captures the investigation graph, not just findings. Resuming knows what was tried.
846
+
847
+ ---
848
+
849
+ ## REFINEMENT SWARM
850
+
851
+ After building, run refinement to test and polish. In AUTOPILOT mode, this runs automatically.
852
+
853
+ ### Manual Invocation
854
+ ```
855
+ /grid:refine # Full swarm (visual + E2E + personas)
856
+ /grid:refine visual # Visual inspection only
857
+ /grid:refine e2e # E2E testing only
858
+ /grid:refine personas # Persona simulation only
859
+ ```
860
+
861
+ ### Refinement Flow
862
+ ```
863
+ 1. Infer project context (type, likely users)
864
+ 2. Generate personas dynamically (3-5 based on context)
865
+ 3. Spawn in parallel:
866
+ |-- Visual Inspector (screenshots all routes)
867
+ |-- E2E Exerciser (clicks everything)
868
+ |-- Persona Simulators (one per persona)
869
+ 4. Synthesize all findings -> REFINEMENT_PLAN.md
870
+ 5. Execute fixes by priority (P0 first)
871
+ ```
872
+
873
+ ### Output
874
+ - `.grid/refinement/screenshots/` - All visual captures
875
+ - `.grid/refinement/e2e/` - E2E test screenshots
876
+ - `.grid/refinement/personas/` - Per-persona reports
877
+ - `.grid/REFINEMENT_PLAN.md` - Prioritized fix plan
878
+
879
+ ---
880
+
881
+ ## DEVIATION RULES (EXECUTOR REFERENCE)
882
+
883
+ Programs can auto-fix certain issues without asking:
884
+
885
+ ### RULE 1: Auto-fix bugs
886
+ **Trigger:** Code doesn't work (broken behavior, errors, wrong output)
887
+ **Action:** Fix immediately, add tests if appropriate, verify, continue
888
+ **Examples:** SQL errors, logic bugs, type errors, validation bugs, security vulnerabilities, race conditions
889
+ **Track:** `[Rule 1 - Bug] {description}`
890
+
891
+ ### RULE 2: Auto-add missing critical functionality
892
+ **Trigger:** Missing essential features for correctness/security/operation
893
+ **Action:** Add immediately, verify, continue
894
+ **Examples:** Error handling, input validation, null checks, auth on protected routes, CSRF protection, rate limiting, indexes, logging
895
+ **Track:** `[Rule 2 - Missing Critical] {description}`
896
+
897
+ ### RULE 3: Auto-fix blocking issues
898
+ **Trigger:** Something prevents task completion
899
+ **Action:** Fix immediately to unblock, verify task can proceed
900
+ **Examples:** Missing dependency, wrong types, broken imports, missing env vars, database config, build errors
901
+ **Track:** `[Rule 3 - Blocking] {description}`
902
+
903
+ ### RULE 4: Ask about architectural changes
904
+ **Trigger:** Fix/addition requires significant structural modification
905
+ **Action:** STOP and return checkpoint
906
+ **Examples:** New database table, major schema changes, new service layer, library switches, auth approach changes
907
+ **Requires:** User decision via I/O Tower
908
+
909
+ **Priority:** Rule 4 first (if applies, STOP). Otherwise Rules 1-3 auto-fix.
910
+
911
+ Programs document deviations in SUMMARY.md with rule citations.
912
+
913
+ ---
914
+
915
+ ## MODEL SELECTION LOGIC
916
+
917
+ ```python
918
+ def get_model(program_type):
919
+ """Get model based on .grid/config.json or default to opus."""
920
+ try:
921
+ config = json.loads(read(".grid/config.json"))
922
+ tier = config.get("model_tier", "quality")
923
+ except:
924
+ tier = "quality" # Default: Opus
925
+
926
+ if tier == "quality":
927
+ return "opus"
928
+ elif tier == "balanced":
929
+ return "sonnet"
930
+ elif tier == "budget":
931
+ # Some programs need reasoning capability
932
+ if program_type in ["planner", "executor", "persona_simulator"]:
933
+ return "sonnet"
934
+ return "haiku"
935
+ return "opus"
936
+ ```
937
+
938
+ Pass `model` parameter to Task():
939
+ ```python
940
+ Task(
941
+ prompt="...",
942
+ subagent_type="general-purpose",
943
+ model="opus", # Default: quality tier
944
+ description="..."
945
+ )
946
+ ```
947
+
948
+ ---
949
+
950
+ *End of Protocols Reference*