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,181 @@
1
+ # MC Optimization Documentation
2
+
3
+ ## Overview
4
+
5
+ This document explains the refactoring of `mc.md` from 1366 lines to approximately 370 lines, a **73% reduction** in size while maintaining full capability.
6
+
7
+ ## Rationale
8
+
9
+ ### The Problem
10
+
11
+ MC (Master Control) is loaded into context every time `/grid` or `/grid:mc` is invoked. At 1366 lines, the original mc.md consumed significant context budget before any orchestration work began. This created several issues:
12
+
13
+ 1. **Context bloat**: MC starts at ~22% context usage just from loading instructions
14
+ 2. **Working memory pollution**: Detailed protocol specifications cluttered MC's working memory when most of it is reference material
15
+ 3. **Redundancy**: Agents already read their own detailed instructions; duplicating everything in MC is wasteful
16
+
17
+ ### The Solution
18
+
19
+ Separate **core identity and decision-making** (what MC needs in working memory) from **detailed protocols** (what agents read when spawned).
20
+
21
+ ## What Stays in mc.md
22
+
23
+ MC's lean version retains everything needed for real-time orchestration:
24
+
25
+ ### Identity (~30 lines)
26
+ - "You are Master Control" core identity
27
+ - Prime directive (stay lean, spawn)
28
+ - Authority and communication style
29
+
30
+ ### Delegation Enforcement (~50 lines)
31
+ - Pre-action gate (critical for preventing rogue behavior)
32
+ - Context budget rules
33
+ - Forbidden actions
34
+
35
+ ### Mode Behavior (~40 lines)
36
+ - AUTOPILOT/GUIDED/HANDS ON summaries
37
+ - Mode detection signals
38
+ - Key behavioral constraints
39
+
40
+ ### Spawn Heuristics (~20 lines)
41
+ - Complexity-to-agent-count mapping
42
+ - Parallelization guidelines
43
+
44
+ ### Quick Mode Detection (~30 lines)
45
+ - Detection heuristics (thresholds)
46
+ - User override mechanism
47
+
48
+ ### Program Spawning (~70 lines)
49
+ - Available programs table
50
+ - Inline content pattern (CRITICAL)
51
+ - Parallel spawning syntax
52
+ - Model routing table
53
+
54
+ ### Protocol Summaries (~50 lines)
55
+ - One-paragraph summaries of each protocol
56
+ - Pointer to full protocols doc
57
+
58
+ ### Anti-Patterns (~30 lines)
59
+ - All six documented failure patterns
60
+ - These MUST stay in MC's working memory to prevent rogue behavior
61
+
62
+ ### Rules & Quick Reference (~50 lines)
63
+ - 13 numbered rules
64
+ - Spawn command reference
65
+ - Key file locations
66
+
67
+ ## What Moved to MC_PROTOCOLS.md
68
+
69
+ Detailed specifications that agents read when spawned:
70
+
71
+ ### Full Code Examples
72
+ - Complete `execute_wave()` implementation
73
+ - Complete `monitor_scratchpad_during_wave()` implementation
74
+ - Complete YAML/markdown format specifications
75
+
76
+ ### Protocol Deep Dives
77
+ - Wave execution protocol (full pseudocode)
78
+ - Execute-and-verify primitive (complete flow)
79
+ - Warmth transfer protocol (full YAML examples)
80
+ - Scratchpad protocol (all four mandatory write situations, entry format, archival)
81
+ - Checkpoint protocol (all three type-specific content formats)
82
+ - Retry protocol (full failure report structure)
83
+ - State management (STATE.md and SUMMARY.md complete formats)
84
+ - Experience replay (full LEARNINGS.md format)
85
+ - Verification/Recognizer (stub detection patterns, patrol mode)
86
+ - Debug session management (investigation graph structure)
87
+ - Refinement swarm (flow details, output locations)
88
+ - Deviation rules (all four rules with examples)
89
+ - Model selection logic (complete function)
90
+
91
+ ## Integration
92
+
93
+ ### MC References Protocols
94
+
95
+ The lean mc.md includes:
96
+
97
+ ```markdown
98
+ ## CORE PROTOCOLS
99
+
100
+ **For detailed protocol specifications, agents read:** `~/.claude/docs/MC_PROTOCOLS.md`
101
+
102
+ The following are protocol summaries. Full details in the protocols doc.
103
+ ```
104
+
105
+ ### Agents Read Protocols When Needed
106
+
107
+ Agent spawn prompts can include:
108
+
109
+ ```python
110
+ Task(
111
+ prompt=f"""
112
+ First, read ~/.claude/agents/grid-executor.md for your role.
113
+ For protocol details, read ~/.claude/docs/MC_PROTOCOLS.md.
114
+
115
+ <plan>...</plan>
116
+ Execute the plan.
117
+ """,
118
+ ...
119
+ )
120
+ ```
121
+
122
+ ## Line Count Analysis
123
+
124
+ | Section | Original | Optimized | Saved |
125
+ |---------|----------|-----------|-------|
126
+ | Identity | 29 | 28 | 1 |
127
+ | Delegation | 62 | 47 | 15 |
128
+ | First interaction | 17 | 15 | 2 |
129
+ | Mode behavior | 79 | 34 | 45 |
130
+ | Spawn heuristics | 42 | 16 | 26 |
131
+ | Quick mode | 71 | 25 | 46 |
132
+ | Program spawning | 222 | 68 | 154 |
133
+ | Wave execution | 119 | 0 (moved) | 119 |
134
+ | Execute-verify | 131 | 0 (moved) | 131 |
135
+ | Warmth transfer | 60 | 9 | 51 |
136
+ | Scratchpad | 119 | 4 | 115 |
137
+ | Checkpoint | 36 | 6 | 30 |
138
+ | I/O Tower | 15 | 0 (merged) | 15 |
139
+ | Retry | 55 | 4 | 51 |
140
+ | State management | 70 | 0 (moved) | 70 |
141
+ | Experience replay | 81 | 0 (moved) | 81 |
142
+ | Progress updates | 33 | 0 (moved) | 33 |
143
+ | Deviation rules | 12 | 0 (moved) | 12 |
144
+ | Verification | 20 | 8 | 12 |
145
+ | Debug sessions | 42 | 0 (moved) | 42 |
146
+ | Recognizer patrol | 31 | 0 (merged) | 31 |
147
+ | Refinement swarm | 30 | 0 (moved) | 30 |
148
+ | Anti-patterns | 35 | 28 | 7 |
149
+ | Rules | 18 | 18 | 0 |
150
+ | Quick reference | 28 | 29 | -1 |
151
+ | **TOTAL** | **1366** | **~370** | **~996** |
152
+
153
+ ## Verification
154
+
155
+ The refactored mc.md was tested conceptually for:
156
+
157
+ 1. **Identity preservation**: MC still identifies as Master Control, speaks with authority
158
+ 2. **Delegation enforcement**: Pre-action gate and all forbidden actions remain
159
+ 3. **Mode behavior**: All three modes defined with detection signals
160
+ 4. **Spawn mechanics**: Inline content pattern, parallel spawning, model routing intact
161
+ 5. **Anti-patterns**: All six anti-patterns preserved (critical for preventing rogue behavior)
162
+ 6. **Rules**: All 13 rules present
163
+ 7. **Quick reference**: All spawn commands and key locations listed
164
+
165
+ ## Benefits
166
+
167
+ 1. **Reduced context consumption**: MC loads faster, leaves more room for orchestration
168
+ 2. **Clearer working memory**: MC sees only what it needs for decisions
169
+ 3. **Single source of truth**: Protocols doc is the authoritative reference
170
+ 4. **Agent independence**: Agents read protocols directly, don't need MC to inline everything
171
+ 5. **Maintainability**: Protocol changes happen in one place
172
+
173
+ ## Future Considerations
174
+
175
+ 1. **Agent file updates**: Consider adding "read protocols doc" instruction to agent files
176
+ 2. **Protocol versioning**: If protocols evolve significantly, version the protocols doc
177
+ 3. **Context budget monitoring**: Track actual context usage to validate optimization
178
+
179
+ ---
180
+
181
+ *Optimization completed as part of Grid evolution. Version 1.7.x.*