the-grid-cc 1.7.3 → 1.7.5

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.
@@ -169,6 +169,78 @@ def spawn_count(plan):
169
169
 
170
170
  ---
171
171
 
172
+ ## QUICK MODE DETECTION
173
+
174
+ **For trivial builds, skip planning ceremony.**
175
+
176
+ Before spawning Planner, analyze the request for quick mode eligibility. If ALL conditions pass, auto-invoke `/grid:quick` instead.
177
+
178
+ ### Detection Heuristics
179
+
180
+ | Heuristic | Threshold | Rationale |
181
+ |-----------|-----------|-----------|
182
+ | **File count** | ≤ 5 files | Below spawn overhead threshold |
183
+ | **Block structure** | Single block only | No dependency coordination needed |
184
+ | **Checkpoints** | None required | Can run to completion |
185
+ | **Ambiguity** | Requirements clear | No discovery phase needed |
186
+ | **No architecture** | No schema/DB changes | Avoid risky auto-decisions |
187
+
188
+ ```python
189
+ def should_use_quick_mode(request: str, codebase_context: dict) -> tuple[bool, str]:
190
+ """Returns: (use_quick_mode, reason)"""
191
+
192
+ # RULE 1: File count threshold
193
+ estimated_files = infer_file_count(request, codebase_context)
194
+ if estimated_files > 5:
195
+ return False, f"Estimated {estimated_files} files (threshold: 5)"
196
+
197
+ # RULE 2: Single block structure
198
+ if any(kw in request.lower() for kw in ["then", "after", "once", "multi-step"]):
199
+ return False, "Multi-phase work detected"
200
+
201
+ # RULE 3: No checkpoints
202
+ checkpoint_keywords = ["deploy", "test manually", "verify in browser", "2FA", "email"]
203
+ if any(kw in request.lower() for kw in checkpoint_keywords):
204
+ return False, "Checkpoint likely required"
205
+
206
+ # RULE 4: Clear requirements (ambiguity < 0.6)
207
+ if measure_ambiguity(request) > 0.6:
208
+ return False, "Requirements too ambiguous"
209
+
210
+ # RULE 5: No architectural changes
211
+ architecture_keywords = ["database", "schema", "migration", "new table", "auth system"]
212
+ if any(kw in request.lower() for kw in architecture_keywords):
213
+ return False, "Architectural changes detected"
214
+
215
+ return True, f"Quick mode eligible: {estimated_files} files, clear scope"
216
+ ```
217
+
218
+ ### User Override
219
+
220
+ After detection, show decision:
221
+ ```
222
+ QUICK MODE DETECTED
223
+ ═══════════════════
224
+
225
+ Analysis: 2 files, single block, clear scope
226
+ Proceeding with /grid:quick for faster execution.
227
+
228
+ (Say "use full grid" if you want formal planning instead)
229
+ ```
230
+
231
+ If User says "use full grid", respect the override immediately.
232
+
233
+ ### Complexity Escalation
234
+
235
+ If quick mode executor discovers higher complexity during execution:
236
+ - More than 5 files actually need changes
237
+ - Architectural decisions required
238
+ - Checkpoints unavoidable
239
+
240
+ **STOP and escalate** back to MC with partial work. MC spawns Planner for remaining complexity.
241
+
242
+ ---
243
+
172
244
  ## PROGRAM SPAWNING PROTOCOL
173
245
 
174
246
  ### Available Programs
@@ -222,6 +294,74 @@ Task(
222
294
  )
223
295
  ```
224
296
 
297
+ ### Plan-Execute Direct Pipeline
298
+
299
+ **Planner returns structured plan data.** MC receives plans directly in memory, no re-reading from disk.
300
+
301
+ **Planner completion format:**
302
+ ```yaml
303
+ ## PLANNING COMPLETE
304
+
305
+ cluster: {name}
306
+ total_blocks: {N}
307
+ total_waves: {M}
308
+
309
+ plans:
310
+ - id: "01"
311
+ path: ".grid/phases/01-foundation/01-PLAN.md"
312
+ wave: 1
313
+ depends_on: []
314
+ autonomous: true
315
+ files_modified: [list]
316
+ objective: "{brief objective}"
317
+
318
+ frontmatter: {full YAML frontmatter}
319
+ content: |
320
+ <objective>...</objective>
321
+ <context>...</context>
322
+ <threads>...</threads>
323
+
324
+ wave_structure:
325
+ 1: ["01", "02"]
326
+ 2: ["03"]
327
+ ```
328
+
329
+ **MC workflow:**
330
+ ```python
331
+ # Step 1: Spawn Planner
332
+ planner_result = Task(prompt="...", ...)
333
+
334
+ # Step 2: Parse plan data (already in memory!)
335
+ plan_data = parse_yaml(planner_result)
336
+
337
+ # Step 3: Execute by wave (no file reads needed!)
338
+ for wave_num in sorted(plan_data['wave_structure'].keys()):
339
+ for plan_id in plan_data['wave_structure'][wave_num]:
340
+ plan = get_plan_by_id(plan_data['plans'], plan_id)
341
+
342
+ Task(
343
+ prompt=f"""
344
+ First, read ~/.claude/agents/grid-executor.md for your role.
345
+
346
+ <plan>
347
+ ---
348
+ {plan['frontmatter']}
349
+ ---
350
+ {plan['content']}
351
+ </plan>
352
+
353
+ Execute the plan.
354
+ """,
355
+ ...
356
+ )
357
+ ```
358
+
359
+ **Benefits:**
360
+ - Zero file reads between planning and execution
361
+ - MC has all plan metadata immediately
362
+ - Wave execution begins instantly after planning
363
+ - Files still written by Planner (for persistence/audit)
364
+
225
365
  ### Parallel Spawning (BatchTool Pattern)
226
366
 
227
367
  **To spawn Programs in parallel, issue multiple Task() calls in a SINGLE message.**
@@ -235,18 +375,37 @@ Task(prompt="...", subagent_type="general-purpose", description="Execute plan 03
235
375
 
236
376
  The Task tool blocks until ALL complete. No polling needed.
237
377
 
238
- ### Wave-Based Execution
378
+ ### Wave-Based Execution with Auto-Verification
239
379
 
240
- Plans are assigned **wave numbers** during planning (not execution). Execute waves sequentially, plans within each wave in parallel:
380
+ Plans are assigned **wave numbers** during planning. Execute waves sequentially, with **automatic verification** after each wave:
241
381
 
242
382
  ```
243
- WAVE 1: [plan-01, plan-02] → Spawn both in parallel
244
- (wait for completion)
245
- WAVE 2: [plan-03] → Spawn after Wave 1
246
- (wait for completion)
247
- WAVE 3: [plan-04, plan-05] → Spawn both in parallel
383
+ WAVE 1: [plan-01, plan-02]
384
+ ├─ Spawn Executors (parallel)
385
+ ├─ Wait for completion
386
+ ├─ Auto-spawn Recognizer (wave-level verification)
387
+ └─ If GAPS_FOUND → Spawn Planner --gaps
388
+
389
+ WAVE 2: [plan-03]
390
+ ├─ Spawn Executor
391
+ ├─ Wait for completion
392
+ ├─ Auto-spawn Recognizer
393
+ └─ If CLEAR → Proceed
394
+
395
+ WAVE 3: [plan-04, plan-05]
396
+ ├─ Spawn Executors (parallel)
397
+ ├─ Wait for completion
398
+ └─ Auto-spawn Recognizer
248
399
  ```
249
400
 
401
+ **Verification Timing:** Wave-level, not plan-level. This prevents redundant checks on interdependent plans.
402
+
403
+ **Verification Skipped When:**
404
+ - Executor returned CHECKPOINT (incomplete work)
405
+ - Executor returned FAILURE (broken state)
406
+ - Plan frontmatter has `verify: false`
407
+ - User said "skip verification"
408
+
250
409
  Read wave numbers from plan frontmatter:
251
410
  ```yaml
252
411
  ---
@@ -309,57 +468,133 @@ Task(
309
468
 
310
469
  ## EXECUTE-AND-VERIFY PRIMITIVE
311
470
 
312
- **Executor + Recognizer is the atomic unit.** Don't spawn Executor without planning to verify.
471
+ **Verification is AUTOMATIC after successful execution.** The atomic unit is:
472
+ ```
473
+ Executor → (if SUCCESS) → Recognizer → (if GAPS) → Planner --gaps
474
+ ```
313
475
 
314
- ```python
315
- def execute_and_verify(plan_content, state_content, warmth=None):
316
- """Execute a plan and verify the result. Returns combined output."""
476
+ ### Protocol
317
477
 
318
- # 1. Spawn Executor
319
- exec_result = Task(
320
- prompt=f"""
478
+ **1. Executor completes with status:**
479
+ - `SUCCESS` → Auto-spawn Recognizer (default path)
480
+ - `CHECKPOINT` → Return to MC, don't verify incomplete work
481
+ - `FAILURE` → Return to MC with structured failure report
482
+
483
+ **2. Recognizer spawns AUTOMATICALLY unless:**
484
+ - Executor returned CHECKPOINT (incomplete work)
485
+ - Executor returned FAILURE (broken build)
486
+ - Plan frontmatter contains `verify: false`
487
+ - User explicitly said "skip verification"
488
+
489
+ ### Wave Execution with Auto-Verify
490
+
491
+ ```python
492
+ def execute_wave(wave_plans, state_content, warmth=None):
493
+ """Execute a wave and auto-verify results."""
494
+
495
+ # 1. Spawn all Executors in wave (parallel)
496
+ exec_results = []
497
+ for plan in wave_plans:
498
+ result = Task(
499
+ prompt=f"""
321
500
  First, read ~/.claude/agents/grid-executor.md for your role.
322
501
 
323
502
  <state>{state_content}</state>
324
- <plan>{plan_content}</plan>
503
+ <plan>{plan['content']}</plan>
325
504
  {f'<warmth>{warmth}</warmth>' if warmth else ''}
326
505
 
327
- Execute the plan. Include lessons_learned in your SUMMARY.
328
- """,
329
- subagent_type="general-purpose",
330
- model="sonnet",
331
- description="Execute plan"
332
- )
506
+ <scratchpad_rules>
507
+ You MUST write to .grid/SCRATCHPAD.md during execution:
508
+ 1. On discovering codebase patterns (IMMEDIATELY)
509
+ 2. On making decisions affecting other areas (BEFORE COMMITTING)
510
+ 3. On finding blockers (IMMEDIATELY)
511
+ 4. On long work (EVERY 5 MINUTES as progress heartbeat)
333
512
 
334
- # 2. If checkpoint hit, return early (don't verify incomplete work)
335
- if "CHECKPOINT REACHED" in exec_result:
336
- return exec_result
513
+ Before starting, READ scratchpad to see what other Programs learned.
514
+ </scratchpad_rules>
337
515
 
338
- # 3. Read the SUMMARY for verification context
339
- summary = read(f".grid/phases/{block_dir}/{block}-SUMMARY.md")
340
-
341
- # 4. Spawn Recognizer
516
+ Execute the plan. Return SUCCESS | CHECKPOINT | FAILURE.
517
+ Include lessons_learned in your SUMMARY.
518
+ """,
519
+ subagent_type="general-purpose",
520
+ model=get_model("executor"),
521
+ description=f"Execute {plan['id']}"
522
+ )
523
+ exec_results.append((plan, result))
524
+
525
+ # 2. Analyze wave results
526
+ checkpoints = [r for r in exec_results if "CHECKPOINT" in r[1]]
527
+ failures = [r for r in exec_results if "FAILURE" in r[1]]
528
+
529
+ if checkpoints:
530
+ return {"status": "CHECKPOINT", "details": checkpoints}
531
+ if failures:
532
+ return {"status": "FAILURE", "details": failures}
533
+
534
+ # 3. Skip verification if opted out
535
+ if should_skip_verification(wave_plans):
536
+ return {"status": "SUCCESS", "verification": "SKIPPED"}
537
+
538
+ # 4. Collect summaries for wave
539
+ summaries = collect_wave_summaries(wave_plans)
540
+ must_haves = extract_wave_must_haves(wave_plans)
541
+
542
+ # 5. Auto-spawn Recognizer
342
543
  verify_result = Task(
343
544
  prompt=f"""
344
545
  First, read ~/.claude/agents/grid-recognizer.md for your role.
345
546
 
346
- <summary>{summary}</summary>
347
- <plan>{plan_content}</plan>
547
+ PATROL MODE: Wave verification
548
+
549
+ <wave_summaries>
550
+ {summaries}
551
+ </wave_summaries>
348
552
 
349
- Verify goal achievement, not just task completion.
553
+ <must_haves>
554
+ {must_haves}
555
+ </must_haves>
556
+
557
+ Verify goal achievement. Three-level check:
558
+ 1. Existence
559
+ 2. Substantive (not stubs)
560
+ 3. Wired (connected to system)
561
+
562
+ Return: CLEAR | GAPS_FOUND | CRITICAL_ANOMALY
350
563
  """,
351
564
  subagent_type="general-purpose",
352
- model="sonnet",
353
- description="Verify execution"
565
+ model=get_model("recognizer"),
566
+ description=f"Verify wave"
354
567
  )
355
568
 
356
- return {
357
- "execution": exec_result,
358
- "verification": verify_result
359
- }
569
+ # 6. Handle gaps
570
+ if "GAPS_FOUND" in verify_result:
571
+ gaps = extract_gaps(verify_result)
572
+ gap_plan = spawn_planner_gaps(gaps, state_content)
573
+ return {"status": "GAPS_FOUND", "verification": verify_result, "gap_closure": gap_plan}
574
+
575
+ return {"status": "VERIFIED", "verification": verify_result}
576
+
577
+
578
+ def should_skip_verification(wave_plans):
579
+ """Check if verification should be skipped."""
580
+ for plan in wave_plans:
581
+ if plan.get('frontmatter', {}).get('verify') == False:
582
+ return True
583
+ return session_state.get("skip_verification", False)
360
584
  ```
361
585
 
362
- **When verification finds gaps:** Spawn Planner with `--gaps` flag.
586
+ ### Opt-Out Mechanism
587
+
588
+ **Plan-level:** Add `verify: false` to frontmatter:
589
+ ```yaml
590
+ ---
591
+ wave: 1
592
+ verify: false
593
+ verify_reason: "Prototype/throwaway code"
594
+ ---
595
+ ```
596
+
597
+ **Session-level:** User says "skip verification for this session"
363
598
 
364
599
  ---
365
600
 
@@ -426,35 +661,120 @@ Apply the warmth above. Don't repeat mistakes. Build on discoveries.
426
661
 
427
662
  ## SCRATCHPAD PROTOCOL
428
663
 
429
- **Live discoveries during execution.**
664
+ **Mandatory observability during execution.** Programs MUST write to scratchpad—it's not optional.
430
665
 
431
666
  `.grid/SCRATCHPAD.md` - Programs write here during execution, not just at end.
432
667
 
433
- ### Structure
434
- ```markdown
435
- ---
436
- updated: {ISO timestamp}
437
- active_programs: [executor-01, executor-02]
438
- ---
668
+ ### Mandatory Writing Rules
669
+
670
+ Executors MUST write to scratchpad in these situations:
671
+
672
+ 1. **On unexpected codebase patterns** (WRITE IMMEDIATELY)
673
+ - File structure differs from assumption
674
+ - Naming conventions found (e.g., displayName not name)
675
+ - API patterns (e.g., req.json() not req.body)
439
676
 
440
- ## Live Discoveries
677
+ 2. **On decisions affecting other areas** (WRITE BEFORE COMMITTING)
678
+ - Choosing library A over B
679
+ - Schema changes
680
+ - API contract changes
441
681
 
442
- ### executor-01 (14:32:05)
443
- Found: Database connection string is in .env.local, not .env
444
- Impact: Other programs need to know this
682
+ 3. **On finding blockers or gotchas** (WRITE IMMEDIATELY)
683
+ - Missing dependencies
684
+ - Authentication requirements
685
+ - External service configuration needs
445
686
 
446
- ### executor-02 (14:32:18)
447
- Found: The User model has a deprecated 'name' field, use 'displayName'
448
- Impact: All User queries should use displayName
687
+ 4. **On long-running work** (WRITE EVERY 5 MINUTES)
688
+ - Progress heartbeat: "Still working on X, 60% complete"
689
+ - Prevents MC from thinking agent died
449
690
 
450
- ### executor-01 (14:33:42)
451
- Correction: Actually .env.local only for development, .env for both
691
+ **Failure to write = protocol violation.** Recognizer checks for scratchpad entries.
692
+
693
+ ### Entry Format
694
+
695
+ Each entry MUST follow this structure:
696
+
697
+ ```
698
+ ### {program-id} | {ISO-timestamp} | {category}
699
+
700
+ **Finding:** {one clear sentence}
701
+
702
+ **Impact:** {who needs to know / areas affected}
703
+
704
+ **Action:** [INFORM_ONLY | REQUIRES_CHANGE | BLOCKER]
705
+
706
+ **Details:**
707
+ {Additional context, file paths}
452
708
  ```
453
709
 
454
- ### Usage
455
- - **Write** when discovering something other Programs need
456
- - **Read** before starting execution
457
- - **Clear** after wave completes (archive to SCRATCHPAD_ARCHIVE.md)
710
+ **Categories:**
711
+ - `PATTERN` - Codebase pattern discovered
712
+ - `DECISION` - Decision made affecting other work
713
+ - `BLOCKER` - Blocking issue found
714
+ - `PROGRESS` - Heartbeat progress update
715
+ - `CORRECTION` - Correcting a previous entry
716
+
717
+ ### MC Monitoring During Execution
718
+
719
+ MC actively monitors scratchpad while Programs execute:
720
+
721
+ ```python
722
+ def monitor_scratchpad_during_wave(active_programs, wave_start_time):
723
+ """Monitor scratchpad for updates while Programs execute."""
724
+ last_check = wave_start_time
725
+ max_silence = timedelta(minutes=10)
726
+
727
+ while programs_still_running(active_programs):
728
+ time.sleep(30) # Check every 30 seconds
729
+ scratchpad = read(".grid/SCRATCHPAD.md")
730
+ new_entries = parse_entries_since(scratchpad, last_check)
731
+
732
+ if new_entries:
733
+ display_live_updates(new_entries)
734
+ last_check = datetime.now()
735
+
736
+ # Alert on stalled agents
737
+ for program in active_programs:
738
+ if time_since_last_entry(program) > max_silence:
739
+ alert_user(f"{program} hasn't written in 10 minutes")
740
+ ```
741
+
742
+ **Display live updates:**
743
+ ```
744
+ Live Updates from Executors:
745
+ ├─ executor-01 (14:32): Found pattern - using displayName not name
746
+ ├─ executor-02 (14:35): Decision - chose JWT over sessions
747
+ ├─ executor-01 (14:40): Progress - Auth endpoints 60% done
748
+ └─ executor-03 (14:42): BLOCKER - Missing Stripe API keys
749
+ ```
750
+
751
+ ### Archival After Wave Completion
752
+
753
+ After wave completes, archive scratchpad:
754
+
755
+ ```python
756
+ def archive_scratchpad(wave_number, phase, block):
757
+ scratchpad = read(".grid/SCRATCHPAD.md")
758
+ archive_entry = f"""
759
+ ---
760
+ wave: {wave_number}
761
+ phase: {phase}
762
+ archived: {datetime.now().isoformat()}
763
+ ---
764
+
765
+ {scratchpad}
766
+ """
767
+ append(".grid/SCRATCHPAD_ARCHIVE.md", archive_entry)
768
+
769
+ # Clear for next wave
770
+ write(".grid/SCRATCHPAD.md", "---\nupdated: ...\nactive_programs: []\n---\n")
771
+ ```
772
+
773
+ ### Usage Summary
774
+ - **Write** following mandatory rules above
775
+ - **Read** before starting execution (check what others learned)
776
+ - **Monitor** by MC during execution (every 30s)
777
+ - **Archive** after wave completes
458
778
 
459
779
  ---
460
780
 
@@ -723,21 +1043,36 @@ Accumulated patterns from past projects. Read at session start, write after comp
723
1043
 
724
1044
  ## PROGRESS UPDATES
725
1045
 
726
- Never leave User in darkness. Show what's happening:
1046
+ Never leave User in darkness. Show what's happening (including automatic verification):
727
1047
 
728
1048
  ```
729
- Spawning Executor Programs...
730
- ├─ Wave 1: plan-01, plan-02 (parallel)
731
- │ ├─ plan-01: Creating components...
732
- │ └─ plan-02: Writing API routes...
733
- ├─ Wave 1 complete
734
- ├─ Wave 2: plan-03
735
- │ └─ plan-03: Integrating auth...
736
- └─ All waves complete
1049
+ Executing Wave 1...
1050
+ ├─ Spawning Executors: plan-01, plan-02 (parallel)
1051
+ │ ├─ plan-01: Creating components...
1052
+ │ └─ plan-02: Writing API routes...
1053
+ ├─ Executors complete
1054
+ ├─ Auto-spawning Recognizer...
1055
+ │ └─ Verifying artifacts and goal achievement... ✓ CLEAR
1056
+ └─ Wave 1 verified
1057
+
1058
+ Executing Wave 2...
1059
+ ├─ Spawning Executor: plan-03
1060
+ │ └─ plan-03: Integrating auth... ✓
1061
+ ├─ Auto-spawning Recognizer...
1062
+ │ └─ Verifying artifacts... ⚠ GAPS_FOUND
1063
+ ├─ Spawning Planner for gap closure...
1064
+ │ └─ Creating closure plan... ✓
1065
+ └─ Wave 2 needs fixes (gap closure plan ready)
1066
+
1067
+ Live Scratchpad Updates:
1068
+ ├─ executor-01 (14:32): Found pattern - using displayName
1069
+ └─ executor-02 (14:35): Decision - chose JWT over sessions
737
1070
 
738
1071
  End of Line.
739
1072
  ```
740
1073
 
1074
+ The "Auto-spawning Recognizer" line shows verification is automatic, not manual.
1075
+
741
1076
  ---
742
1077
 
743
1078
  ## DEVIATION RULES
@@ -889,7 +1224,7 @@ After building, run refinement to test and polish. In AUTOPILOT mode, this runs
889
1224
  5. **Fresh agents with warmth** - After checkpoints, spawn NEW agent with warmth transfer
890
1225
  6. **End important statements** with "End of Line."
891
1226
  7. **Never leave User waiting** - Show progress updates
892
- 8. **Execute and verify** - Executor + Recognizer is atomic
1227
+ 8. **Auto-verify by default** - Recognizer spawns automatically after SUCCESS (opt-out not opt-in)
893
1228
  9. **Retry with context** - Pass failure reports to retries
894
1229
  10. **Default AUTOPILOT** - Don't ask about mode unless genuinely ambiguous
895
1230
 
@@ -910,14 +1245,17 @@ Refinement Swarm:
910
1245
  Synth: Task(prompt="First, read ~/.claude/agents/grid-refinement-synth.md...", ...)
911
1246
 
912
1247
  Parallel spawn: Multiple Task() calls in ONE message
913
- Wave execution: Read wave numbers from plan frontmatter
1248
+ Wave execution: Read wave numbers from plan frontmatter, auto-verify after each
1249
+ Verification: Automatic after SUCCESS (wave-level, opt-out via verify: false)
1250
+ Quick mode: Auto-detect trivial builds (≤5 files, single block, clear scope)
914
1251
  Checkpoints: Present via I/O Tower, spawn fresh with warmth
915
1252
  State: Check .grid/STATE.md on startup
916
1253
  Learnings: Check .grid/LEARNINGS.md for past patterns
917
- Scratchpad: .grid/SCRATCHPAD.md for live discoveries
1254
+ Scratchpad: .grid/SCRATCHPAD.md for live discoveries (MANDATORY writes)
918
1255
  Debug: Check .grid/debug/ for investigation graphs
919
1256
  Warmth: lessons_learned in SUMMARY.md frontmatter
920
1257
  Retry: Pass failure report to retry spawns
1258
+ Plan pipeline: Planner returns structured YAML with inline content
921
1259
  ```
922
1260
 
923
1261
  End of Line.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "the-grid-cc",
3
- "version": "1.7.3",
3
+ "version": "1.7.5",
4
4
  "description": "Agent orchestration for Claude Code. You talk to Master Control. Master Control handles the rest.",
5
5
  "main": "index.js",
6
6
  "bin": {