the-grid-cc 1.7.13 → 1.7.15

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 (42) hide show
  1. package/02-SUMMARY.md +156 -0
  2. package/DAEMON_VALIDATION.md +354 -0
  3. package/README.md +6 -6
  4. package/agents/grid-accountant.md +519 -0
  5. package/agents/grid-git-operator.md +661 -0
  6. package/agents/grid-researcher.md +421 -0
  7. package/agents/grid-scout.md +376 -0
  8. package/commands/grid/VERSION +1 -1
  9. package/commands/grid/branch.md +567 -0
  10. package/commands/grid/budget.md +438 -0
  11. package/commands/grid/daemon.md +637 -0
  12. package/commands/grid/help.md +29 -0
  13. package/commands/grid/init.md +409 -18
  14. package/commands/grid/mc.md +163 -1111
  15. package/commands/grid/resume.md +656 -0
  16. package/docs/BUDGET_SYSTEM.md +745 -0
  17. package/docs/CONFIG_SCHEMA.md +479 -0
  18. package/docs/DAEMON_ARCHITECTURE.md +780 -0
  19. package/docs/GIT_AUTONOMY.md +981 -0
  20. package/docs/GIT_AUTONOMY_INTEGRATION.md +343 -0
  21. package/docs/MC_OPTIMIZATION.md +181 -0
  22. package/docs/MC_PROTOCOLS.md +950 -0
  23. package/docs/PERSISTENCE.md +962 -0
  24. package/docs/PERSISTENCE_IMPLEMENTATION.md +361 -0
  25. package/docs/PERSISTENCE_QUICKSTART.md +283 -0
  26. package/docs/RESEARCH_CONFIG.md +511 -0
  27. package/docs/RESEARCH_FIRST.md +591 -0
  28. package/docs/WIRING_VERIFICATION.md +389 -0
  29. package/package.json +1 -1
  30. package/templates/daemon-checkpoint.json +51 -0
  31. package/templates/daemon-config.json +28 -0
  32. package/templates/git-config.json +65 -0
  33. package/templates/grid-state/.gitignore-entry +3 -0
  34. package/templates/grid-state/BLOCK-SUMMARY.md +66 -0
  35. package/templates/grid-state/BLOCKERS.md +31 -0
  36. package/templates/grid-state/CHECKPOINT.md +59 -0
  37. package/templates/grid-state/DECISIONS.md +30 -0
  38. package/templates/grid-state/README.md +138 -0
  39. package/templates/grid-state/SCRATCHPAD.md +29 -0
  40. package/templates/grid-state/STATE.md +47 -0
  41. package/templates/grid-state/WARMTH.md +48 -0
  42. package/templates/grid-state/config.json +24 -0
@@ -0,0 +1,511 @@
1
+ # Research-First Configuration
2
+
3
+ **Technical Reference**
4
+ **Version:** 1.0
5
+ **Date:** 2026-01-23
6
+
7
+ ---
8
+
9
+ ## Overview
10
+
11
+ This document specifies configuration options for The Grid's Research-First Architecture. Research configuration controls when and how Scout and Researcher programs are spawned before planning.
12
+
13
+ ---
14
+
15
+ ## Configuration Schema
16
+
17
+ ### Proposed `.grid/config.json`
18
+
19
+ ```json
20
+ {
21
+ "version": "1.0",
22
+ "project": {
23
+ "name": "my-project",
24
+ "cluster": "project-cluster"
25
+ },
26
+ "research": {
27
+ "enabled": true,
28
+ "scout": {
29
+ "enabled": true,
30
+ "timeout_seconds": 120,
31
+ "max_files_analyzed": 1000,
32
+ "depth_limit": 4,
33
+ "skip_dirs": ["node_modules", ".git", "dist", "build", ".next"]
34
+ },
35
+ "researcher": {
36
+ "enabled": true,
37
+ "timeout_seconds": 300,
38
+ "max_researchers_parallel": 3,
39
+ "max_queries_per_topic": 10,
40
+ "search_tool_preference": ["mcp__exa__get_code_context_exa", "WebSearch", "WebFetch"]
41
+ },
42
+ "cache": {
43
+ "enabled": true,
44
+ "ttl_hours": 24,
45
+ "max_entries": 50,
46
+ "max_size_mb": 100,
47
+ "eviction_policy": "lru"
48
+ },
49
+ "skip_conditions": {
50
+ "quick_mode_eligible": true,
51
+ "debug_mode": true,
52
+ "explicit_user_skip": true,
53
+ "all_tech_cached": true
54
+ }
55
+ }
56
+ }
57
+ ```
58
+
59
+ ---
60
+
61
+ ## Configuration Fields
62
+
63
+ ### `research.enabled` (boolean, default: `true`)
64
+
65
+ Master switch for research-first architecture.
66
+
67
+ - `true`: MC spawns Scout/Researcher before Planner
68
+ - `false`: MC spawns Planner directly (legacy behavior)
69
+
70
+ ### `research.scout.enabled` (boolean, default: `true`)
71
+
72
+ Enable Scout reconnaissance of existing codebases.
73
+
74
+ - `true`: Scout analyzes existing code before planning
75
+ - `false`: Skip Scout, no codebase context
76
+
77
+ ### `research.scout.timeout_seconds` (integer, default: `120`)
78
+
79
+ Maximum time Scout can spend on reconnaissance.
80
+
81
+ - Recommended: `120` (2 minutes)
82
+ - Range: `60-300`
83
+
84
+ ### `research.scout.max_files_analyzed` (integer, default: `1000`)
85
+
86
+ Maximum number of files Scout will analyze before early exit.
87
+
88
+ - Prevents performance issues on massive codebases
89
+ - Scout samples first N files for pattern detection
90
+
91
+ ### `research.scout.depth_limit` (integer, default: `4`)
92
+
93
+ Maximum directory depth for tree traversal.
94
+
95
+ - Prevents deep recursion on complex directory structures
96
+ - Most patterns detectable within 4 levels
97
+
98
+ ### `research.scout.skip_dirs` (array[string], default: `["node_modules", ".git", "dist", "build", ".next"]`)
99
+
100
+ Directories Scout will never enter.
101
+
102
+ - Always respect `.gitignore` patterns
103
+ - Add project-specific build directories
104
+
105
+ ### `research.researcher.enabled` (boolean, default: `true`)
106
+
107
+ Enable Researcher web intelligence gathering.
108
+
109
+ - `true`: MC spawns Researchers for external context
110
+ - `false`: Skip research, plan with training knowledge only
111
+
112
+ ### `research.researcher.timeout_seconds` (integer, default: `300`)
113
+
114
+ Maximum time per Researcher Program.
115
+
116
+ - Recommended: `300` (5 minutes)
117
+ - Range: `180-600`
118
+
119
+ ### `research.researcher.max_researchers_parallel` (integer, default: `3`)
120
+
121
+ Maximum number of Researcher Programs spawned in parallel.
122
+
123
+ - Balances speed vs. API rate limits
124
+ - Each Researcher gets fresh 200k context
125
+
126
+ ### `research.researcher.max_queries_per_topic` (integer, default: `10`)
127
+
128
+ Maximum search queries per research topic.
129
+
130
+ - Prevents runaway searches
131
+ - Ensures timely completion
132
+
133
+ ### `research.researcher.search_tool_preference` (array[string], default: `["mcp__exa__get_code_context_exa", "WebSearch", "WebFetch"]`)
134
+
135
+ Ordered list of preferred search tools.
136
+
137
+ Researcher tries tools in order based on query type:
138
+ - Code examples: `mcp__exa__get_code_context_exa`
139
+ - Best practices: `WebSearch`
140
+ - Documentation: `WebFetch` with URL
141
+
142
+ ### `research.cache.enabled` (boolean, default: `true`)
143
+
144
+ Enable research caching.
145
+
146
+ - `true`: Cache research outputs, check cache before searching
147
+ - `false`: Always fresh research (slow)
148
+
149
+ ### `research.cache.ttl_hours` (integer, default: `24`)
150
+
151
+ Time-to-live for cache entries in hours.
152
+
153
+ - Recommended: `24` (balance freshness/speed)
154
+ - Range: `1-168` (1 hour to 1 week)
155
+
156
+ ### `research.cache.max_entries` (integer, default: `50`)
157
+
158
+ Maximum cached research topics.
159
+
160
+ - Prevents unbounded cache growth
161
+ - LRU eviction when limit reached
162
+
163
+ ### `research.cache.max_size_mb` (integer, default: `100`)
164
+
165
+ Maximum total cache size in megabytes.
166
+
167
+ - Hard limit to prevent disk bloat
168
+ - Evicts oldest entries when exceeded
169
+
170
+ ### `research.cache.eviction_policy` (string, default: `"lru"`)
171
+
172
+ Cache eviction strategy.
173
+
174
+ Options:
175
+ - `"lru"`: Least Recently Used
176
+ - `"fifo"`: First In First Out
177
+ - `"ttl"`: Time-based only
178
+
179
+ ### `research.skip_conditions.*` (boolean, all default: `true`)
180
+
181
+ Conditions under which research phase is skipped.
182
+
183
+ | Condition | When It Triggers |
184
+ |-----------|-----------------|
185
+ | `quick_mode_eligible` | User request is simple (≤5 files affected) |
186
+ | `debug_mode` | User says "debug" or "fix bug" |
187
+ | `explicit_user_skip` | User says "skip research" |
188
+ | `all_tech_cached` | All detected technologies already cached |
189
+
190
+ ---
191
+
192
+ ## Runtime Configuration
193
+
194
+ ### Environment Variables
195
+
196
+ Research behavior can be overridden via environment variables:
197
+
198
+ ```bash
199
+ # Disable research entirely
200
+ export GRID_RESEARCH_ENABLED=false
201
+
202
+ # Force fresh research (ignore cache)
203
+ export GRID_RESEARCH_FORCE_FRESH=true
204
+
205
+ # Increase researcher timeout
206
+ export GRID_RESEARCHER_TIMEOUT=600
207
+
208
+ # Limit parallel researchers
209
+ export GRID_MAX_RESEARCHERS=2
210
+ ```
211
+
212
+ ### User Commands
213
+
214
+ Users can control research via natural language:
215
+
216
+ | User Says | Effect |
217
+ |-----------|--------|
218
+ | "skip research" | Skip research phase for this request |
219
+ | "fresh research" | Ignore cache, research anew |
220
+ | "research only" | Run research, don't plan/execute |
221
+ | "deep research" | Extended timeout (10 min vs 5 min) |
222
+ | "quick mode" | Skip research, use /quick workflow |
223
+
224
+ ---
225
+
226
+ ## Configuration Discovery
227
+
228
+ ### Loading Priority
229
+
230
+ MC loads configuration in this order (first found wins):
231
+
232
+ 1. `.grid/config.json` - Project-specific config
233
+ 2. `~/.claude/grid-config.json` - User global config
234
+ 3. Built-in defaults (as documented above)
235
+
236
+ ### Configuration Validation
237
+
238
+ On load, MC validates:
239
+ - All boolean fields are `true` or `false`
240
+ - All integer fields are within valid ranges
241
+ - `skip_dirs` contains at least `[".git", "node_modules"]`
242
+ - `search_tool_preference` contains valid tool names
243
+
244
+ Invalid config falls back to defaults with warning.
245
+
246
+ ---
247
+
248
+ ## Integration with MC
249
+
250
+ ### Research Phase Decision Flow
251
+
252
+ ```python
253
+ def should_run_research(user_request: str, config: dict) -> dict:
254
+ """Determine if research phase should run."""
255
+
256
+ if not config['research']['enabled']:
257
+ return {'run': False, 'reason': 'Research disabled in config'}
258
+
259
+ # Check skip conditions
260
+ if config['research']['skip_conditions']['explicit_user_skip']:
261
+ if 'skip research' in user_request.lower():
262
+ return {'run': False, 'reason': 'User explicitly skipped'}
263
+
264
+ if config['research']['skip_conditions']['quick_mode_eligible']:
265
+ if quick_mode_eligible(user_request):
266
+ return {'run': False, 'reason': 'Quick mode eligible'}
267
+
268
+ if config['research']['skip_conditions']['debug_mode']:
269
+ if is_debug_request(user_request):
270
+ return {'run': False, 'reason': 'Debug mode'}
271
+
272
+ # Check if all tech is cached
273
+ if config['research']['skip_conditions']['all_tech_cached']:
274
+ techs = extract_technologies(user_request)
275
+ if all(is_cached(tech) for tech in techs):
276
+ return {'run': False, 'reason': 'All tech cached'}
277
+
278
+ return {'run': True, 'reason': 'Research needed'}
279
+ ```
280
+
281
+ ### MC Spawn Logic
282
+
283
+ ```python
284
+ def research_phase(user_request: str, config: dict) -> dict:
285
+ """Execute research phase with configuration."""
286
+
287
+ decision = should_run_research(user_request, config)
288
+ if not decision['run']:
289
+ return {'skipped': True, 'reason': decision['reason']}
290
+
291
+ context = {}
292
+
293
+ # Scout Phase
294
+ if config['research']['scout']['enabled'] and has_existing_code():
295
+ scout_config = config['research']['scout']
296
+ scout_prompt = f"""
297
+ First, read ~/.claude/agents/grid-scout.md for your role.
298
+
299
+ <config>
300
+ timeout: {scout_config['timeout_seconds']}s
301
+ max_files: {scout_config['max_files_analyzed']}
302
+ depth_limit: {scout_config['depth_limit']}
303
+ skip_dirs: {scout_config['skip_dirs']}
304
+ </config>
305
+
306
+ Scan the codebase at {os.getcwd()}.
307
+ Return structured scout report.
308
+ """
309
+ context['codebase'] = Task(
310
+ prompt=scout_prompt,
311
+ subagent_type="general-purpose",
312
+ description="Scout codebase reconnaissance"
313
+ )
314
+
315
+ # Researcher Phase
316
+ if config['research']['researcher']['enabled']:
317
+ research_needs = extract_research_needs(user_request)
318
+
319
+ # Check cache
320
+ cache_config = config['research']['cache']
321
+ if cache_config['enabled']:
322
+ cached, needed = check_research_cache(research_needs, cache_config)
323
+ context['cached_research'] = cached
324
+ else:
325
+ needed = research_needs
326
+
327
+ # Spawn researchers (parallel)
328
+ researcher_config = config['research']['researcher']
329
+ max_parallel = researcher_config['max_researchers_parallel']
330
+ needed = needed[:max_parallel] # Limit spawns
331
+
332
+ research_tasks = []
333
+ for need in needed:
334
+ researcher_prompt = f"""
335
+ First, read ~/.claude/agents/grid-researcher.md for your role.
336
+
337
+ <config>
338
+ timeout: {researcher_config['timeout_seconds']}s
339
+ max_queries: {researcher_config['max_queries_per_topic']}
340
+ tools: {researcher_config['search_tool_preference']}
341
+ </config>
342
+
343
+ <research_request>
344
+ {need}
345
+ </research_request>
346
+
347
+ Research and return structured context.
348
+ """
349
+ task = Task(
350
+ prompt=researcher_prompt,
351
+ subagent_type="general-purpose",
352
+ description=f"Research {need['topic']}"
353
+ )
354
+ research_tasks.append(task)
355
+
356
+ context['fresh_research'] = research_tasks # Spawned in parallel
357
+
358
+ return context
359
+ ```
360
+
361
+ ---
362
+
363
+ ## Migration Path
364
+
365
+ ### Phase 1: Infrastructure Only
366
+ - Create directories: `.grid/research/`, `.grid/research_cache/`, `.grid/scout/`
367
+ - Create README files documenting structure
368
+ - Initialize `index.json` cache index
369
+
370
+ ### Phase 2: Agent Validation
371
+ - Verify `grid-scout.md` and `grid-researcher.md` are properly formatted
372
+ - Test spawning agents with mock config
373
+
374
+ ### Phase 3: MC Integration
375
+ - Add config loading to MC initialization
376
+ - Implement research phase decision logic
377
+ - Add research context to Planner prompts
378
+
379
+ ### Phase 4: User Experience
380
+ - Add user command parsing ("skip research", "fresh research")
381
+ - Document research phase in `/grid:help`
382
+ - Add research metrics to progress output
383
+
384
+ ---
385
+
386
+ ## Example Configuration Files
387
+
388
+ ### Minimal Config (Defaults)
389
+
390
+ ```json
391
+ {
392
+ "version": "1.0",
393
+ "research": {
394
+ "enabled": true
395
+ }
396
+ }
397
+ ```
398
+
399
+ All other settings use built-in defaults.
400
+
401
+ ### Research Disabled
402
+
403
+ ```json
404
+ {
405
+ "version": "1.0",
406
+ "research": {
407
+ "enabled": false
408
+ }
409
+ }
410
+ ```
411
+
412
+ Legacy behavior - no Scout or Researcher, plan directly.
413
+
414
+ ### Aggressive Research
415
+
416
+ ```json
417
+ {
418
+ "version": "1.0",
419
+ "research": {
420
+ "enabled": true,
421
+ "researcher": {
422
+ "max_researchers_parallel": 5,
423
+ "timeout_seconds": 600
424
+ },
425
+ "cache": {
426
+ "ttl_hours": 1,
427
+ "max_entries": 100
428
+ },
429
+ "skip_conditions": {
430
+ "quick_mode_eligible": false,
431
+ "debug_mode": false,
432
+ "all_tech_cached": false
433
+ }
434
+ }
435
+ }
436
+ ```
437
+
438
+ Research on every request, fresh results, extended timeouts.
439
+
440
+ ### Large Codebase Optimized
441
+
442
+ ```json
443
+ {
444
+ "version": "1.0",
445
+ "research": {
446
+ "scout": {
447
+ "timeout_seconds": 180,
448
+ "max_files_analyzed": 5000,
449
+ "depth_limit": 6,
450
+ "skip_dirs": [
451
+ "node_modules", ".git", "dist", "build",
452
+ "vendor", "target", ".next", ".nuxt"
453
+ ]
454
+ }
455
+ }
456
+ }
457
+ ```
458
+
459
+ Longer Scout timeout, more files, deeper traversal for monorepos.
460
+
461
+ ---
462
+
463
+ ## Observability
464
+
465
+ ### Research Metrics Logged
466
+
467
+ ```yaml
468
+ research_metrics:
469
+ scout:
470
+ duration_ms: 1234
471
+ files_scanned: 456
472
+ patterns_detected: 8
473
+ constraints_found: 12
474
+
475
+ researcher:
476
+ topics_researched: 3
477
+ queries_executed: 18
478
+ cache_hits: 2
479
+ cache_misses: 1
480
+ avg_query_time_ms: 2345
481
+
482
+ cache:
483
+ hit_rate: 0.67
484
+ entries_cached: 15
485
+ size_mb: 12.3
486
+ evictions: 2
487
+ ```
488
+
489
+ ### Log Files
490
+
491
+ ```
492
+ .grid/logs/research/
493
+ ├── scout_{timestamp}.log
494
+ └── researcher_{topic}_{timestamp}.log
495
+ ```
496
+
497
+ ---
498
+
499
+ ## Summary
500
+
501
+ Research configuration provides fine-grained control over The Grid's research-first architecture:
502
+
503
+ 1. **`research.enabled`** - Master switch
504
+ 2. **Scout settings** - Control codebase reconnaissance
505
+ 3. **Researcher settings** - Control web intelligence gathering
506
+ 4. **Cache settings** - Control research reuse
507
+ 5. **Skip conditions** - When to bypass research
508
+
509
+ Configuration is optional - sensible defaults enable research-first behavior out of the box.
510
+
511
+ **End of Line.**