the-grid-cc 1.7.12 → 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,438 @@
1
+ # /grid:budget - Budget and Cost Management
2
+
3
+ ---
4
+ name: grid:budget
5
+ description: Configure spending limits, track costs, and view usage reports
6
+ allowed-tools:
7
+ - Read
8
+ - Write
9
+ - Edit
10
+ - Glob
11
+ - Grep
12
+ - AskUserQuestion
13
+ ---
14
+
15
+ Manage cost tracking, budget limits, and usage reporting for Grid operations.
16
+
17
+ ## USAGE
18
+
19
+ ```
20
+ /grid:budget # Show current budget status and usage
21
+ /grid:budget set <amount> # Set budget limit (e.g., "set $50" or "set 50")
22
+ /grid:budget estimate # Estimate cost of pending work
23
+ /grid:budget report # Detailed usage report
24
+ /grid:budget reset # Reset usage counters (keeps budget limit)
25
+ /grid:budget unlimited # Remove budget limit (dangerous)
26
+ ```
27
+
28
+ ## CONCEPTS
29
+
30
+ ### Cost Model
31
+
32
+ The Grid estimates costs based on Claude API pricing:
33
+
34
+ | Model | Input (per 1M tokens) | Output (per 1M tokens) |
35
+ |-------|----------------------|------------------------|
36
+ | **Opus 4.5** | $5.00 | $25.00 |
37
+ | **Sonnet 4.5** | $3.00 | $15.00 |
38
+ | **Haiku 4.5** | $1.00 | $5.00 |
39
+
40
+ ### Token Estimation
41
+
42
+ Since The Grid runs within Claude Code (no direct API access), costs are ESTIMATED from:
43
+
44
+ 1. **Prompt size** - Characters in spawn prompts (chars / 4 ~ tokens)
45
+ 2. **Response patterns** - Typical output ratios per agent type
46
+ 3. **File operations** - Files read/written add to context
47
+ 4. **Historical data** - Learn from past executions
48
+
49
+ **Estimation Formula:**
50
+ ```
51
+ estimated_tokens = prompt_chars / 4
52
+ estimated_cost = (input_tokens * input_rate + output_tokens * output_rate) / 1_000_000
53
+ ```
54
+
55
+ ### Budget Enforcement
56
+
57
+ When a budget is set, The Grid tracks estimated costs and:
58
+
59
+ | Threshold | Action |
60
+ |-----------|--------|
61
+ | 0-75% | Normal operation |
62
+ | 75-90% | Warning displayed |
63
+ | 90-100% | Confirmation required before each spawn |
64
+ | 100%+ | **HARD STOP** - No new spawns until budget increased |
65
+
66
+ ## OUTPUT FORMATS
67
+
68
+ ### Status Display (`/grid:budget`)
69
+
70
+ ```
71
+ GRID BUDGET
72
+ ===========
73
+
74
+ Budget Limit: $50.00
75
+ Used: $12.47 (24.9%)
76
+ Remaining: $37.53
77
+
78
+ [=========- ] 24.9%
79
+
80
+ Session Breakdown:
81
+ Planner spawns: 2 x opus ~$3.20
82
+ Executor spawns: 4 x opus ~$8.40
83
+ Recognizer spawns: 1 x sonnet ~$0.87
84
+ ────────────────────────────────
85
+ Total estimated: $12.47
86
+
87
+ Last 24h:
88
+ Spawns: 7
89
+ Tokens: ~498,000 in / ~124,000 out
90
+
91
+ End of Line.
92
+ ```
93
+
94
+ ### Budget Warning (75%+)
95
+
96
+ ```
97
+ BUDGET WARNING
98
+ ==============
99
+
100
+ Budget: $50.00
101
+ Used: $42.15 (84.3%)
102
+
103
+ [================================-- ] 84.3%
104
+
105
+ Remaining budget may allow ~2 more agent spawns.
106
+
107
+ Options:
108
+ 1. Continue (carefully)
109
+ 2. Increase budget: /grid:budget set $100
110
+ 3. Switch to budget tier: /grid:model budget
111
+
112
+ Proceed with current spawn? [y/N]
113
+ ```
114
+
115
+ ### Budget Exceeded (100%+)
116
+
117
+ ```
118
+ BUDGET EXCEEDED
119
+ ===============
120
+
121
+ Budget: $50.00
122
+ Used: $52.34 (104.7%)
123
+
124
+ [========================================] 104.7% OVER
125
+
126
+ Current spawn BLOCKED.
127
+
128
+ To continue:
129
+ /grid:budget set $75 # Increase limit
130
+ /grid:budget reset # Reset counters (if new session)
131
+ /grid:budget unlimited # Remove limit (not recommended)
132
+
133
+ End of Line.
134
+ ```
135
+
136
+ ### Cost Estimate (`/grid:budget estimate`)
137
+
138
+ ```
139
+ COST ESTIMATE
140
+ =============
141
+
142
+ Pending Work:
143
+ Cluster: Authentication System
144
+ Blocks: 3
145
+ Estimated Spawns: 8
146
+
147
+ Breakdown:
148
+ Planning Phase:
149
+ 1x Planner (opus) ~$1.60
150
+
151
+ Execution Phase:
152
+ Wave 1: 2x Executor (opus) ~$4.20
153
+ Wave 2: 1x Executor (opus) ~$2.10
154
+
155
+ Verification Phase:
156
+ 3x Recognizer (sonnet) ~$2.61
157
+
158
+ Refinement Phase:
159
+ 1x Visual Inspector (sonnet) ~$0.87
160
+ 1x E2E Exerciser (sonnet) ~$0.87
161
+ 2x Persona Simulator (sonnet) ~$1.74
162
+ 1x Refinement Synth (sonnet) ~$0.87
163
+
164
+ ────────────────────────────────────────
165
+ ESTIMATED TOTAL: ~$14.86
166
+
167
+ Current Budget: $50.00
168
+ After completion: ~$35.14 remaining
169
+
170
+ Model Tier Comparison:
171
+ Quality (opus): ~$14.86
172
+ Balanced (sonnet): ~$8.92 (40% savings)
173
+ Budget (haiku): ~$4.46 (70% savings)
174
+
175
+ End of Line.
176
+ ```
177
+
178
+ ### Usage Report (`/grid:budget report`)
179
+
180
+ ```
181
+ GRID USAGE REPORT
182
+ =================
183
+
184
+ Period: 2026-01-20 to 2026-01-23
185
+
186
+ SUMMARY
187
+ -------
188
+ Total Sessions: 3
189
+ Total Spawns: 24
190
+ Est. Input Tokens: 1,847,000
191
+ Est. Output Tokens: 461,750
192
+ Est. Total Cost: $47.83
193
+
194
+ BY SESSION
195
+ ----------
196
+ | Date | Cluster | Spawns | Est. Cost |
197
+ |------------|------------------|--------|-----------|
198
+ | 2026-01-23 | Auth System | 8 | $14.86 |
199
+ | 2026-01-22 | Dashboard | 10 | $21.32 |
200
+ | 2026-01-20 | API Endpoints | 6 | $11.65 |
201
+
202
+ BY AGENT TYPE
203
+ -------------
204
+ | Agent | Count | Model | Est. Cost |
205
+ |--------------------|-------|--------|-----------|
206
+ | Planner | 3 | opus | $4.80 |
207
+ | Executor | 12 | opus | $25.20 |
208
+ | Recognizer | 5 | sonnet | $4.35 |
209
+ | Visual Inspector | 2 | sonnet | $1.74 |
210
+ | E2E Exerciser | 1 | sonnet | $0.87 |
211
+ | Persona Simulator | 1 | sonnet | $0.87 |
212
+
213
+ BY MODEL TIER
214
+ -------------
215
+ | Model | Spawns | Est. Cost | % of Total |
216
+ |--------|--------|-----------|------------|
217
+ | opus | 15 | $30.00 | 62.7% |
218
+ | sonnet | 9 | $17.83 | 37.3% |
219
+ | haiku | 0 | $0.00 | 0.0% |
220
+
221
+ COST TREND
222
+ ----------
223
+ $25 | *
224
+ | * *
225
+ $15 | * * *
226
+ | *
227
+ $5 |
228
+ +------------------
229
+ Mon Tue Wed Thu
230
+
231
+ End of Line.
232
+ ```
233
+
234
+ ## CONFIGURATION
235
+
236
+ ### Budget Config File
237
+
238
+ `.grid/budget.json`:
239
+
240
+ ```json
241
+ {
242
+ "budget_limit": 50.00,
243
+ "currency": "USD",
244
+ "enforcement": "hard",
245
+ "warning_threshold": 0.75,
246
+ "confirmation_threshold": 0.90,
247
+ "current_session": {
248
+ "started": "2026-01-23T10:00:00Z",
249
+ "estimated_cost": 12.47,
250
+ "spawns": [
251
+ {
252
+ "timestamp": "2026-01-23T10:05:00Z",
253
+ "agent": "planner",
254
+ "model": "opus",
255
+ "prompt_chars": 24000,
256
+ "est_input_tokens": 6000,
257
+ "est_output_tokens": 8000,
258
+ "est_cost": 1.60
259
+ }
260
+ ]
261
+ },
262
+ "history": {
263
+ "total_cost": 147.83,
264
+ "total_spawns": 84,
265
+ "sessions": 12
266
+ }
267
+ }
268
+ ```
269
+
270
+ ### Budget Settings
271
+
272
+ | Setting | Default | Description |
273
+ |---------|---------|-------------|
274
+ | `budget_limit` | null | Max spending (null = unlimited) |
275
+ | `enforcement` | "hard" | "hard" = block, "soft" = warn only |
276
+ | `warning_threshold` | 0.75 | Warn at 75% usage |
277
+ | `confirmation_threshold` | 0.90 | Require confirmation at 90% |
278
+
279
+ ## INTEGRATION WITH MC
280
+
281
+ Master Control checks budget before EVERY spawn:
282
+
283
+ ```python
284
+ def check_budget_before_spawn(agent_type, model):
285
+ """Returns: (allowed, message)"""
286
+ budget = load_budget_config()
287
+
288
+ if budget['budget_limit'] is None:
289
+ return True, None # Unlimited
290
+
291
+ estimated_spawn_cost = estimate_spawn_cost(agent_type, model)
292
+ new_total = budget['current_session']['estimated_cost'] + estimated_spawn_cost
293
+ usage_ratio = new_total / budget['budget_limit']
294
+
295
+ if usage_ratio > 1.0:
296
+ if budget['enforcement'] == 'hard':
297
+ return False, "BUDGET EXCEEDED - spawn blocked"
298
+ else:
299
+ return True, "WARNING: Over budget"
300
+
301
+ if usage_ratio > budget['confirmation_threshold']:
302
+ # Requires user confirmation (via I/O Tower)
303
+ return 'confirm', f"At {usage_ratio*100:.1f}% of budget"
304
+
305
+ if usage_ratio > budget['warning_threshold']:
306
+ # Display warning but continue
307
+ return True, f"WARNING: At {usage_ratio*100:.1f}% of budget"
308
+
309
+ return True, None
310
+ ```
311
+
312
+ ### Pre-Spawn Hook
313
+
314
+ Before spawning ANY agent, MC must:
315
+
316
+ ```python
317
+ # In MC spawn protocol
318
+ allowed, message = check_budget_before_spawn(agent_type, model)
319
+
320
+ if allowed == False:
321
+ display_budget_exceeded()
322
+ return # Block spawn
323
+
324
+ if allowed == 'confirm':
325
+ response = io_tower_confirm(message)
326
+ if not response:
327
+ return # User declined
328
+
329
+ if message:
330
+ display_budget_warning(message)
331
+
332
+ # Proceed with spawn
333
+ record_spawn_cost(agent_type, model, prompt_chars)
334
+ ```
335
+
336
+ ### Post-Spawn Hook
337
+
338
+ After spawn completes, record actual usage:
339
+
340
+ ```python
341
+ def record_spawn_completion(spawn_id, output_chars):
342
+ """Update estimates with actual output size."""
343
+ budget = load_budget_config()
344
+ spawn = find_spawn(budget, spawn_id)
345
+
346
+ spawn['actual_output_chars'] = output_chars
347
+ spawn['est_output_tokens'] = output_chars / 4
348
+ spawn['est_cost'] = calculate_cost(spawn)
349
+
350
+ budget['current_session']['estimated_cost'] = sum_spawn_costs(budget)
351
+ save_budget_config(budget)
352
+ ```
353
+
354
+ ## TYPICAL SPAWN COSTS
355
+
356
+ **Reference costs per spawn (estimates):**
357
+
358
+ | Agent | Opus | Sonnet | Haiku |
359
+ |-------|------|--------|-------|
360
+ | Planner | ~$1.60 | ~$0.96 | - |
361
+ | Executor | ~$2.10 | ~$1.26 | - |
362
+ | Recognizer | ~$1.45 | ~$0.87 | ~$0.29 |
363
+ | Visual Inspector | ~$1.45 | ~$0.87 | ~$0.29 |
364
+ | E2E Exerciser | ~$1.45 | ~$0.87 | ~$0.29 |
365
+ | Persona Simulator | ~$1.60 | ~$0.96 | ~$0.48 |
366
+ | Refinement Synth | ~$1.45 | ~$0.87 | ~$0.44 |
367
+
368
+ **Typical project costs:**
369
+
370
+ | Project Type | Est. Spawns | Quality | Balanced | Budget |
371
+ |--------------|-------------|---------|----------|--------|
372
+ | Quick fix | 1-2 | $2-4 | $1-2 | $0.50-1 |
373
+ | Small feature | 3-5 | $5-10 | $3-6 | $1-3 |
374
+ | Medium project | 8-12 | $15-25 | $9-15 | $4-8 |
375
+ | Large project | 15-25 | $30-50 | $18-30 | $8-15 |
376
+
377
+ ## RULES
378
+
379
+ 1. **Budget check before EVERY spawn** - No exceptions
380
+ 2. **Estimations, not actuals** - We estimate from prompt/response sizes
381
+ 3. **Hard stops are hard** - When enforcement=hard and budget exceeded, work stops
382
+ 4. **Session-based** - Each `/grid` invocation is a session
383
+ 5. **History persists** - Usage history survives across sessions
384
+ 6. **Model tier affects cost** - Budget tier can reduce costs 50-70%
385
+ 7. **Warn early** - 75% threshold gives user time to react
386
+
387
+ ## WORKFLOW INTEGRATION
388
+
389
+ ### With `/grid:model`
390
+
391
+ ```
392
+ # Check current costs
393
+ /grid:budget
394
+
395
+ # If over budget, switch to cheaper tier
396
+ /grid:model budget
397
+
398
+ # Continue work at lower cost
399
+ /grid:estimate # Recalculates with new tier
400
+ ```
401
+
402
+ ### With Planning
403
+
404
+ During planning, MC spawns Accountant to estimate total cluster cost:
405
+
406
+ ```
407
+ CLUSTER: Auth System (3 blocks)
408
+
409
+ Estimated Cost: ~$14.86 (quality tier)
410
+ Current Budget: $50.00
411
+ Budget after: ~$35.14
412
+
413
+ Proceed? [Y/n]
414
+ ```
415
+
416
+ ### With Refinement Swarm
417
+
418
+ Refinement phase can be expensive (4-6 spawns). Budget check happens before:
419
+
420
+ ```
421
+ REFINEMENT SWARM
422
+ ================
423
+
424
+ This will spawn:
425
+ - Visual Inspector (sonnet) ~$0.87
426
+ - E2E Exerciser (sonnet) ~$0.87
427
+ - 3x Persona Simulator (sonnet) ~$2.88
428
+ - Refinement Synth (sonnet) ~$0.87
429
+
430
+ Total: ~$5.49
431
+
432
+ Budget remaining: $12.53
433
+ After refinement: ~$7.04
434
+
435
+ Proceed? [Y/n]
436
+ ```
437
+
438
+ End of Line.