codingbuddy-rules 4.5.0 → 5.1.0

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 (129) hide show
  1. package/.ai-rules/adapters/aider.md +374 -0
  2. package/.ai-rules/adapters/antigravity.md +6 -6
  3. package/.ai-rules/adapters/claude-code.md +68 -4
  4. package/.ai-rules/adapters/codex.md +5 -5
  5. package/.ai-rules/adapters/cursor.md +2 -2
  6. package/.ai-rules/adapters/kiro.md +8 -8
  7. package/.ai-rules/adapters/opencode.md +7 -7
  8. package/.ai-rules/adapters/q.md +2 -2
  9. package/.ai-rules/adapters/windsurf.md +395 -0
  10. package/.ai-rules/agents/README.md +66 -16
  11. package/.ai-rules/agents/accessibility-specialist.json +8 -1
  12. package/.ai-rules/agents/act-mode.json +8 -1
  13. package/.ai-rules/agents/agent-architect.json +14 -7
  14. package/.ai-rules/agents/ai-ml-engineer.json +7 -0
  15. package/.ai-rules/agents/architecture-specialist.json +7 -0
  16. package/.ai-rules/agents/auto-mode.json +10 -2
  17. package/.ai-rules/agents/backend-developer.json +7 -0
  18. package/.ai-rules/agents/code-quality-specialist.json +7 -0
  19. package/.ai-rules/agents/code-reviewer.json +86 -64
  20. package/.ai-rules/agents/data-engineer.json +14 -7
  21. package/.ai-rules/agents/data-scientist.json +16 -9
  22. package/.ai-rules/agents/devops-engineer.json +7 -0
  23. package/.ai-rules/agents/documentation-specialist.json +7 -0
  24. package/.ai-rules/agents/eval-mode.json +30 -19
  25. package/.ai-rules/agents/event-architecture-specialist.json +7 -0
  26. package/.ai-rules/agents/frontend-developer.json +7 -0
  27. package/.ai-rules/agents/i18n-specialist.json +8 -1
  28. package/.ai-rules/agents/integration-specialist.json +7 -0
  29. package/.ai-rules/agents/migration-specialist.json +7 -0
  30. package/.ai-rules/agents/mobile-developer.json +8 -10
  31. package/.ai-rules/agents/observability-specialist.json +7 -0
  32. package/.ai-rules/agents/parallel-orchestrator.json +352 -0
  33. package/.ai-rules/agents/performance-specialist.json +7 -0
  34. package/.ai-rules/agents/plan-mode.json +9 -1
  35. package/.ai-rules/agents/plan-reviewer.json +211 -0
  36. package/.ai-rules/agents/platform-engineer.json +7 -0
  37. package/.ai-rules/agents/security-engineer.json +15 -8
  38. package/.ai-rules/agents/security-specialist.json +8 -1
  39. package/.ai-rules/agents/seo-specialist.json +7 -0
  40. package/.ai-rules/agents/software-engineer.json +7 -0
  41. package/.ai-rules/agents/solution-architect.json +17 -10
  42. package/.ai-rules/agents/systems-developer.json +15 -8
  43. package/.ai-rules/agents/technical-planner.json +17 -10
  44. package/.ai-rules/agents/test-engineer.json +13 -6
  45. package/.ai-rules/agents/test-strategy-specialist.json +7 -0
  46. package/.ai-rules/agents/tooling-engineer.json +10 -3
  47. package/.ai-rules/agents/ui-ux-designer.json +7 -0
  48. package/.ai-rules/keyword-modes.json +4 -4
  49. package/.ai-rules/rules/clarification-guide.md +14 -14
  50. package/.ai-rules/rules/core.md +73 -0
  51. package/.ai-rules/rules/parallel-execution.md +217 -0
  52. package/.ai-rules/schemas/agent.schema.json +38 -0
  53. package/.ai-rules/skills/README.md +29 -1
  54. package/.ai-rules/skills/agent-design/SKILL.md +5 -0
  55. package/.ai-rules/skills/agent-design/examples/agent-template.json +55 -0
  56. package/.ai-rules/skills/agent-design/references/expertise-guidelines.md +112 -0
  57. package/.ai-rules/skills/agent-discussion/SKILL.md +199 -0
  58. package/.ai-rules/skills/agent-discussion-panel/SKILL.md +448 -0
  59. package/.ai-rules/skills/api-design/SKILL.md +5 -0
  60. package/.ai-rules/skills/api-design/examples/error-response.json +159 -0
  61. package/.ai-rules/skills/api-design/examples/openapi-template.yaml +393 -0
  62. package/.ai-rules/skills/build-fix/SKILL.md +234 -0
  63. package/.ai-rules/skills/code-explanation/SKILL.md +4 -0
  64. package/.ai-rules/skills/context-management/SKILL.md +1 -0
  65. package/.ai-rules/skills/cost-budget/SKILL.md +348 -0
  66. package/.ai-rules/skills/cross-repo-issues/SKILL.md +257 -0
  67. package/.ai-rules/skills/database-migration/SKILL.md +1 -0
  68. package/.ai-rules/skills/deepsearch/SKILL.md +214 -0
  69. package/.ai-rules/skills/deployment-checklist/SKILL.md +1 -0
  70. package/.ai-rules/skills/error-analysis/SKILL.md +1 -0
  71. package/.ai-rules/skills/finishing-a-development-branch/SKILL.md +281 -0
  72. package/.ai-rules/skills/frontend-design/SKILL.md +5 -0
  73. package/.ai-rules/skills/frontend-design/examples/component-template.tsx +203 -0
  74. package/.ai-rules/skills/frontend-design/references/css-patterns.md +243 -0
  75. package/.ai-rules/skills/git-master/SKILL.md +358 -0
  76. package/.ai-rules/skills/incident-response/SKILL.md +1 -0
  77. package/.ai-rules/skills/legacy-modernization/SKILL.md +1 -0
  78. package/.ai-rules/skills/mcp-builder/SKILL.md +7 -0
  79. package/.ai-rules/skills/mcp-builder/examples/resource-example.ts +233 -0
  80. package/.ai-rules/skills/mcp-builder/examples/tool-example.ts +198 -0
  81. package/.ai-rules/skills/mcp-builder/references/protocol-spec.md +215 -0
  82. package/.ai-rules/skills/onboard/SKILL.md +150 -0
  83. package/.ai-rules/skills/performance-optimization/SKILL.md +3 -0
  84. package/.ai-rules/skills/plan-and-review/SKILL.md +115 -0
  85. package/.ai-rules/skills/plan-to-issues/SKILL.md +318 -0
  86. package/.ai-rules/skills/pr-all-in-one/SKILL.md +15 -13
  87. package/.ai-rules/skills/pr-all-in-one/configuration-guide.md +7 -7
  88. package/.ai-rules/skills/pr-all-in-one/pr-templates.md +10 -10
  89. package/.ai-rules/skills/pr-review/SKILL.md +4 -0
  90. package/.ai-rules/skills/receiving-code-review/SKILL.md +347 -0
  91. package/.ai-rules/skills/refactoring/SKILL.md +1 -0
  92. package/.ai-rules/skills/requesting-code-review/SKILL.md +348 -0
  93. package/.ai-rules/skills/retrospective/SKILL.md +192 -0
  94. package/.ai-rules/skills/rule-authoring/SKILL.md +5 -0
  95. package/.ai-rules/skills/rule-authoring/examples/rule-template.md +142 -0
  96. package/.ai-rules/skills/rule-authoring/examples/trigger-patterns.md +126 -0
  97. package/.ai-rules/skills/security-audit/SKILL.md +4 -0
  98. package/.ai-rules/skills/ship/SKILL.md +242 -0
  99. package/.ai-rules/skills/skill-creator/SKILL.md +461 -0
  100. package/.ai-rules/skills/skill-creator/agents/analyzer.md +206 -0
  101. package/.ai-rules/skills/skill-creator/agents/comparator.md +167 -0
  102. package/.ai-rules/skills/skill-creator/agents/grader.md +152 -0
  103. package/.ai-rules/skills/skill-creator/assets/eval_review.html +568 -0
  104. package/.ai-rules/skills/skill-creator/assets/skill-template.md +43 -0
  105. package/.ai-rules/skills/skill-creator/eval-viewer/generate_review.py +496 -0
  106. package/.ai-rules/skills/skill-creator/references/frontmatter-guide.md +632 -0
  107. package/.ai-rules/skills/skill-creator/references/multi-tool-compat.md +480 -0
  108. package/.ai-rules/skills/skill-creator/references/schemas.md +784 -0
  109. package/.ai-rules/skills/skill-creator/scripts/aggregate_benchmark.py +302 -0
  110. package/.ai-rules/skills/skill-creator/scripts/init_skill.sh +196 -0
  111. package/.ai-rules/skills/skill-creator/scripts/run_loop.py +327 -0
  112. package/.ai-rules/skills/systematic-debugging/SKILL.md +1 -0
  113. package/.ai-rules/skills/tech-debt/SKILL.md +1 -0
  114. package/.ai-rules/skills/test-coverage-gate/SKILL.md +303 -0
  115. package/.ai-rules/skills/tmux-master/SKILL.md +491 -0
  116. package/.ai-rules/skills/using-git-worktrees/SKILL.md +368 -0
  117. package/.ai-rules/skills/verification-before-completion/SKILL.md +234 -0
  118. package/.ai-rules/skills/widget-slot-architecture/SKILL.md +6 -0
  119. package/.ai-rules/skills/widget-slot-architecture/examples/parallel-route-setup.tsx +206 -0
  120. package/.ai-rules/skills/widget-slot-architecture/examples/widget-component.tsx +250 -0
  121. package/.ai-rules/skills/writing-plans/SKILL.md +78 -0
  122. package/bin/cli.js +170 -0
  123. package/lib/init/detect-stack.js +162 -0
  124. package/lib/init/generate-config.js +31 -0
  125. package/lib/init/index.js +86 -0
  126. package/lib/init/prompt.js +60 -0
  127. package/lib/init/scaffold.js +67 -0
  128. package/lib/init/suggest-agent.js +57 -0
  129. package/package.json +10 -2
@@ -0,0 +1,234 @@
1
+ ---
2
+ name: build-fix
3
+ description: Use when build fails, TypeScript errors appear, or compilation breaks. Minimal diff fixes only — no refactoring, no architecture changes.
4
+ user-invocable: true
5
+ allowed-tools: Read, Edit, Grep, Glob, Bash
6
+ ---
7
+
8
+ # Build Fix
9
+
10
+ ## Overview
11
+
12
+ Build errors block everything. Fix them fast, fix them small, fix nothing else.
13
+
14
+ **Core principle:** Fix ONLY what is broken. A build fix is not an opportunity to refactor, add features, or improve architecture. Touch the minimum lines required to restore a passing build.
15
+
16
+ **Violating the letter of this process is violating the spirit of build fixing.**
17
+
18
+ ## The Iron Law
19
+
20
+ ```
21
+ MINIMAL DIFF, NO ARCHITECTURE CHANGES — FIX WHAT'S BROKEN, NOTHING MORE
22
+ ```
23
+
24
+ If your diff touches lines unrelated to the error, you are not build-fixing. You are refactoring. Stop.
25
+
26
+ **No exceptions:**
27
+ - "While I'm here, I'll clean up..." → No. Separate PR.
28
+ - "This would be better as..." → No. Separate issue.
29
+ - "The real problem is the architecture..." → No. File an issue, fix the build now.
30
+
31
+ ## When to Use
32
+
33
+ Use for ANY build/compilation failure:
34
+ - TypeScript compiler errors (`tsc --noEmit` failures)
35
+ - Import/export resolution errors
36
+ - Dependency version mismatches or missing packages
37
+ - Configuration errors (tsconfig, webpack, vite, etc.)
38
+ - CI/CD build pipeline failures
39
+ - Module not found errors
40
+
41
+ **Use this ESPECIALLY when:**
42
+ - Build is red and blocking the team
43
+ - CI pipeline is failing on compilation
44
+ - Dependency update broke the build
45
+ - Merge conflict left broken imports
46
+
47
+ **Do NOT use when:**
48
+ - Tests fail but build succeeds → use `systematic-debugging`
49
+ - You want to improve code quality → use `refactoring`
50
+ - You want to add features → use `brainstorming` + TDD
51
+ - Runtime errors, not compile-time → use `error-analysis`
52
+
53
+ ## Error Classification
54
+
55
+ First, classify the build error:
56
+
57
+ | Class | Symptoms | Typical Minimal Fix |
58
+ |-------|----------|-------------------|
59
+ | **TypeScript Error** | `TS2345`, `TS2339`, `TS7006`, `TS2532` | Add type annotation, null check, or correct type |
60
+ | **Import Error** | `Cannot find module`, `has no exported member` | Fix path, add missing export, correct import name |
61
+ | **Dependency Error** | Version mismatch, missing peer dep, lockfile conflict | Align version, install missing package |
62
+ | **Config Error** | `tsconfig.json` invalid, env var missing, wrong target | Fix config value, add missing variable |
63
+ | **Syntax Error** | Unexpected token, missing bracket | Fix syntax at reported location |
64
+
65
+ ## The Four Phases
66
+
67
+ You MUST complete each phase before proceeding to the next.
68
+
69
+ ### Phase 1: Read the Error
70
+
71
+ **BEFORE attempting ANY fix:**
72
+
73
+ 1. **Read the FULL error output**
74
+ - Don't skim — read every line
75
+ - Note the error code (e.g., `TS2345`)
76
+ - Note the exact file and line number
77
+ - Note what the compiler expected vs. what it got
78
+
79
+ 2. **Classify the error** (see table above)
80
+ - What class does this error belong to?
81
+ - Is it a single error or a cascade?
82
+ - Cascading errors: fix the FIRST error only, then re-run
83
+
84
+ 3. **Count the errors**
85
+ - One error? Fix it directly.
86
+ - Many errors, same root cause? Fix the root, not each symptom.
87
+ - Many unrelated errors? Fix one at a time, verify after each.
88
+
89
+ ### Phase 2: Identify Root Cause
90
+
91
+ **Find the MINIMUM change needed:**
92
+
93
+ 1. **Check recent changes**
94
+ ```bash
95
+ git diff HEAD~1 # What changed?
96
+ git log --oneline -5 # Recent commits
97
+ ```
98
+
99
+ 2. **Trace the error to its source**
100
+ - TypeScript error at line 42? Read line 42.
101
+ - Import error? Check if the export exists at the source.
102
+ - Dependency error? Check `package.json` versions.
103
+
104
+ 3. **Identify the scope**
105
+ - How many files need to change?
106
+ - If more than 3 files → question whether this is truly a build fix
107
+ - If it requires new files → this is not a build fix, it's a feature
108
+
109
+ ### Phase 3: Minimal Fix
110
+
111
+ **Apply the SMALLEST possible change:**
112
+
113
+ 1. **One fix at a time**
114
+ - Change one thing
115
+ - Don't bundle fixes
116
+ - Don't "improve" surrounding code
117
+
118
+ 2. **Common minimal fixes**
119
+
120
+ ```typescript
121
+ // TypeScript: TS2345 - Type mismatch
122
+ // BAD: Rewrite the function with new types
123
+ // GOOD: Add the correct type annotation or assertion
124
+ const value = data as ExpectedType;
125
+
126
+ // TypeScript: TS2532 - Possibly undefined
127
+ // BAD: Refactor to eliminate the possibility
128
+ // GOOD: Add null check or optional chaining
129
+ const name = user?.name ?? 'default';
130
+
131
+ // Import: Cannot find module
132
+ // BAD: Restructure the module system
133
+ // GOOD: Fix the import path
134
+ import { Thing } from './correct/path';
135
+
136
+ // Dependency: Missing peer dependency
137
+ // BAD: Upgrade the entire dependency tree
138
+ // GOOD: Install the specific missing package
139
+ // $ yarn add missing-package@^required.version
140
+ ```
141
+
142
+ 3. **What NOT to do**
143
+ - Do NOT rename variables for "clarity"
144
+ - Do NOT extract functions for "reusability"
145
+ - Do NOT add error handling beyond what's needed
146
+ - Do NOT update unrelated dependencies
147
+ - Do NOT change code formatting
148
+
149
+ ### Phase 4: Verify
150
+
151
+ **Confirm the build passes:**
152
+
153
+ 1. **Run the build command**
154
+ ```bash
155
+ # Run the same command that failed
156
+ yarn build # or npm run build
157
+ tsc --noEmit # TypeScript check
158
+ ```
159
+
160
+ 2. **Run tests to ensure no regressions**
161
+ ```bash
162
+ yarn test # or npm test
163
+ ```
164
+
165
+ 3. **Check the diff**
166
+ ```bash
167
+ git diff
168
+ ```
169
+ - Is every changed line directly related to the error?
170
+ - Did you touch anything unrelated? Revert it.
171
+ - Is the diff as small as possible?
172
+
173
+ 4. **If build still fails**
174
+ - Read the NEW error message
175
+ - Is it the same error? → Your fix was wrong. Revert.
176
+ - Is it a different error? → Return to Phase 1 for the new error.
177
+ - Do NOT stack fixes without verifying between each one.
178
+
179
+ ## Red Flags — STOP and Return to Phase 1
180
+
181
+ If you catch yourself thinking:
182
+
183
+ | Thought | Reality |
184
+ |---------|---------|
185
+ | "While I'm fixing this, I'll also..." | Build fix. Nothing else. |
186
+ | "This function should really be..." | File an issue. Fix the build. |
187
+ | "The types are all wrong, let me redesign..." | Fix the ONE type error. Not all types. |
188
+ | "I need to add a new abstraction..." | No new abstractions in a build fix. |
189
+ | "Let me upgrade this dependency to latest..." | Only change the version if it fixes the error. |
190
+ | "This code is messy, let me clean up..." | Messy code that compiles > clean code in a broken build. |
191
+ | "The architecture caused this, so I should..." | Architecture changes are not build fixes. |
192
+
193
+ **ALL of these mean: STOP. You are no longer build-fixing.**
194
+
195
+ ## Common Rationalizations
196
+
197
+ | Excuse | Reality |
198
+ |--------|---------|
199
+ | "The refactor prevents future build errors" | Future prevention is a separate task. Fix now. |
200
+ | "It's just a small improvement" | Small improvements compound into large diffs. |
201
+ | "The code is already open in my editor" | Being convenient doesn't make it a build fix. |
202
+ | "No one will review a 1-line PR" | 1-line PRs are the BEST PRs. Ship it. |
203
+ | "I need to understand the whole module" | You need to understand the error. Not the module. |
204
+ | "The dependency is outdated anyway" | Outdated but compiling > updated and broken. |
205
+
206
+ ## Scope Guard
207
+
208
+ Before committing, verify your changes pass the scope guard:
209
+
210
+ ```
211
+ For EACH changed line, ask:
212
+ "Would the build fail without this specific change?"
213
+
214
+ YES → Keep it
215
+ NO → Revert it
216
+ ```
217
+
218
+ If any changed line fails the scope guard, you have scope creep. Remove it.
219
+
220
+ ## Quick Reference
221
+
222
+ | Phase | Key Activity | Success Criteria |
223
+ |-------|-------------|------------------|
224
+ | **1. Read** | Read full error, classify, count | Know WHAT is broken |
225
+ | **2. Identify** | Check changes, trace source | Know WHERE and WHY |
226
+ | **3. Fix** | Smallest possible change | Minimal diff applied |
227
+ | **4. Verify** | Build passes, tests pass, diff is clean | Build green, no extras |
228
+
229
+ ## Related Skills
230
+
231
+ - **`error-analysis`** — For classifying and understanding error messages (Phase 1)
232
+ - **`systematic-debugging`** — For runtime bugs, not compile-time errors
233
+ - **`verification-before-completion`** — For confirming the fix before claiming success
234
+ - **`refactoring`** — For when you actually WANT to improve structure (not during build fix)
@@ -1,6 +1,10 @@
1
1
  ---
2
2
  name: code-explanation
3
3
  description: Use when explaining complex code to new team members, conducting code reviews, onboarding, or understanding unfamiliar codebases. Provides structured analysis from high-level overview to implementation details.
4
+ context: fork
5
+ agent: Explore
6
+ allowed-tools: Read, Grep, Glob
7
+ argument-hint: [file-or-symbol]
4
8
  ---
5
9
 
6
10
  # Code Explanation
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  name: context-management
3
3
  description: Use when working on long tasks that span multiple sessions, when context compaction is a concern, or when decisions from PLAN mode need to persist through ACT and EVAL modes.
4
+ user-invocable: false
4
5
  ---
5
6
 
6
7
  # Context Management
@@ -0,0 +1,348 @@
1
+ ---
2
+ name: cost-budget
3
+ description: >-
4
+ Use when managing AI session costs, setting budget limits, or preventing
5
+ cost overruns in autonomous workflows like taskMaestro, autopilot, ralph
6
+ loops, and parallel agent execution. Defines cost tracking protocol,
7
+ threshold alerts, and auto-pause mechanism.
8
+ ---
9
+
10
+ # Cost Budget Management
11
+
12
+ ## Overview
13
+
14
+ Autonomous AI workflows can consume unbounded resources without guardrails. A single runaway loop — autopilot, ralph, or a multi-wave taskMaestro session — can burn through API credits before anyone notices.
15
+
16
+ **Core principle:** Every autonomous workflow must have a cost ceiling. No budget means unlimited spend.
17
+
18
+ **Iron Law:**
19
+ ```
20
+ NO AUTONOMOUS EXECUTION WITHOUT A DECLARED BUDGET
21
+ If no budget is set, warn before starting. If budget is exceeded, pause and require override.
22
+ ```
23
+
24
+ ## When to Use
25
+
26
+ - Starting any autonomous workflow (autopilot, ralph, ultrawork, taskMaestro)
27
+ - Running parallel agents across multiple panes or worktrees
28
+ - Multi-session tasks expected to exceed a few dollars
29
+ - Any workflow where cost visibility matters to the user
30
+ - Setting up per-project or per-team cost guardrails
31
+
32
+ ## When NOT to Use
33
+
34
+ - Single interactive conversations (cost is negligible)
35
+ - Quick one-off questions or file reads
36
+ - Workflows where the user explicitly opts out of budget tracking
37
+
38
+ ---
39
+
40
+ ## Cost Tracking Protocol
41
+
42
+ ### Data Collection Points
43
+
44
+ Cost data is collected at three levels:
45
+
46
+ | Level | Scope | Data Source | Granularity |
47
+ |-------|-------|-------------|-------------|
48
+ | **Session** | Single Claude Code session | Token usage from API responses | Per-request |
49
+ | **Wave** | One taskMaestro wave (N parallel panes) | Aggregated session costs per pane | Per-wave |
50
+ | **Project** | All sessions in a project directory | Cumulative across sessions | Running total |
51
+
52
+ ### Cost Estimation
53
+
54
+ ```
55
+ Cost = (input_tokens × input_price) + (output_tokens × output_price)
56
+
57
+ Model pricing (per 1M tokens):
58
+ opus: input=$15.00 output=$75.00
59
+ sonnet: input=$3.00 output=$15.00
60
+ haiku: input=$0.25 output=$1.25
61
+ ```
62
+
63
+ **Note:** Prices are approximate and should be updated when model pricing changes. The skill defines the protocol, not hardcoded prices.
64
+
65
+ ### Collection Methods
66
+
67
+ 1. **Environment variables** (preferred):
68
+ ```bash
69
+ export COST_BUDGET_USD=10.00 # Total budget in USD
70
+ export COST_BUDGET_TOKENS=5000000 # Alternative: token-based budget
71
+ export COST_BUDGET_SCOPE=project # session | wave | project
72
+ ```
73
+
74
+ 2. **Configuration file** (`codingbuddy.config.json`):
75
+ ```json
76
+ {
77
+ "costBudget": {
78
+ "limit": 10.00,
79
+ "currency": "USD",
80
+ "scope": "project",
81
+ "thresholds": {
82
+ "info": 0.50,
83
+ "warn": 0.80,
84
+ "critical": 1.00
85
+ }
86
+ }
87
+ }
88
+ ```
89
+
90
+ 3. **MCP state** (runtime tracking):
91
+ ```
92
+ state_write(mode: "cost-budget", state: {
93
+ "spent": "4.52",
94
+ "budget": "10.00",
95
+ "tokens_used": "2340000"
96
+ })
97
+ ```
98
+
99
+ ### Token Counting
100
+
101
+ Track tokens per request and accumulate:
102
+
103
+ ```
104
+ Per request:
105
+ input_tokens → from API response headers or usage field
106
+ output_tokens → from API response headers or usage field
107
+ cost_usd → calculated from model pricing
108
+
109
+ Accumulated:
110
+ session_total = sum(all request costs in session)
111
+ wave_total = sum(all session costs in wave)
112
+ project_total = sum(all wave/session costs in project)
113
+ ```
114
+
115
+ ---
116
+
117
+ ## Budget Configuration
118
+
119
+ ### Threshold Levels
120
+
121
+ Three threshold levels trigger different actions:
122
+
123
+ | Level | Default | Trigger | Action |
124
+ |-------|---------|---------|--------|
125
+ | **INFO** | 50% of budget | Informational milestone | Log to terminal, continue |
126
+ | **WARN** | 80% of budget | Approaching limit | Terminal alert + optional webhook, continue |
127
+ | **CRITICAL** | 100% of budget | Budget exhausted | Terminal alert + webhook + **auto-pause** |
128
+
129
+ ### Budget Scopes
130
+
131
+ | Scope | Description | Use Case |
132
+ |-------|-------------|----------|
133
+ | `session` | Single CLI session | Quick tasks, one-off work |
134
+ | `wave` | One taskMaestro wave | Per-wave cost control in parallel execution |
135
+ | `project` | Cumulative across all sessions | Long-running projects with total budget |
136
+
137
+ ### Budget Override
138
+
139
+ When the CRITICAL threshold is reached, the workflow pauses. To continue:
140
+
141
+ ```bash
142
+ # Explicit override for current session
143
+ export COST_BUDGET_OVERRIDE=true
144
+
145
+ # Or increase the budget
146
+ export COST_BUDGET_USD=20.00
147
+ ```
148
+
149
+ **Override rules:**
150
+ - Override must be explicit — never auto-continue past 100%
151
+ - Override resets the threshold to the new budget
152
+ - Log every override event for audit trail
153
+ - Override does not disable future threshold checks
154
+
155
+ ---
156
+
157
+ ## Alert Channels
158
+
159
+ ### Terminal Notification (Default)
160
+
161
+ Always active. Alerts appear inline in the terminal:
162
+
163
+ ```
164
+ ┌─────────────────────────────────────────────┐
165
+ │ 💰 COST ALERT [INFO] │
166
+ │ Budget: $5.00 / $10.00 (50%) │
167
+ │ Tokens: 1.2M used │
168
+ │ Status: Continuing │
169
+ └─────────────────────────────────────────────┘
170
+ ```
171
+
172
+ ```
173
+ ┌─────────────────────────────────────────────┐
174
+ │ ⚠️ COST ALERT [WARN] │
175
+ │ Budget: $8.00 / $10.00 (80%) │
176
+ │ Tokens: 3.8M used │
177
+ │ Status: Approaching limit — review spend │
178
+ └─────────────────────────────────────────────┘
179
+ ```
180
+
181
+ ```
182
+ ┌─────────────────────────────────────────────┐
183
+ │ 🛑 COST ALERT [CRITICAL] │
184
+ │ Budget: $10.00 / $10.00 (100%) │
185
+ │ Tokens: 5.0M used │
186
+ │ Status: PAUSED — override required │
187
+ │ │
188
+ │ To continue: │
189
+ │ export COST_BUDGET_OVERRIDE=true │
190
+ │ # or increase: export COST_BUDGET_USD=20 │
191
+ └─────────────────────────────────────────────┘
192
+ ```
193
+
194
+ ### Webhook (Optional)
195
+
196
+ For remote notifications (Slack, Discord, PagerDuty, custom endpoints):
197
+
198
+ ```bash
199
+ export COST_ALERT_WEBHOOK_URL=https://hooks.slack.com/services/...
200
+ export COST_ALERT_WEBHOOK_EVENTS=warn,critical # which levels trigger webhook
201
+ ```
202
+
203
+ **Webhook payload:**
204
+ ```json
205
+ {
206
+ "event": "cost_alert",
207
+ "level": "warn",
208
+ "budget_usd": 10.00,
209
+ "spent_usd": 8.00,
210
+ "percent": 80,
211
+ "tokens_used": 3800000,
212
+ "scope": "project",
213
+ "project": "codingbuddy",
214
+ "session_id": "abc-123",
215
+ "timestamp": "2026-03-22T14:00:00Z"
216
+ }
217
+ ```
218
+
219
+ **Webhook rules:**
220
+ - Webhook failures must not block the workflow
221
+ - Retry once on failure, then log and continue
222
+ - Include project name and session ID for traceability
223
+
224
+ ---
225
+
226
+ ## Auto-Pause Mechanism
227
+
228
+ ### Pause Behavior
229
+
230
+ When the CRITICAL threshold (100%) is reached:
231
+
232
+ 1. **Stop** — Halt the current autonomous loop iteration
233
+ 2. **Alert** — Display terminal notification + fire webhook
234
+ 3. **Save state** — Persist current progress to context document
235
+ 4. **Wait** — Do not proceed until explicit override or budget increase
236
+ 5. **Log** — Record the pause event with timestamp and spend data
237
+
238
+ ### Pause Points by Workflow
239
+
240
+ | Workflow | Pause Point | What Happens |
241
+ |----------|-------------|--------------|
242
+ | **autopilot** | Between iterations | Current iteration completes, next blocked |
243
+ | **ralph** | Between architect reviews | Current cycle completes, next blocked |
244
+ | **ultrawork** | Between task assignments | Current task completes, next blocked |
245
+ | **taskMaestro** | Between waves | Current wave completes, next wave blocked |
246
+ | **parallel agents** | At agent completion | Running agents finish, no new agents spawn |
247
+
248
+ **Key:** Never interrupt mid-operation. Always complete the current atomic unit, then pause.
249
+
250
+ ### Override Protocol
251
+
252
+ ```
253
+ 1. User sees CRITICAL alert
254
+ 2. User reviews spend breakdown
255
+ 3. User decides:
256
+ a. Stop entirely → no action needed, workflow stays paused
257
+ b. Continue with new budget → export COST_BUDGET_USD=<new_amount>
258
+ c. Continue without limit → export COST_BUDGET_OVERRIDE=true
259
+ 4. Workflow resumes from saved state
260
+ ```
261
+
262
+ ---
263
+
264
+ ## TaskMaestro Integration
265
+
266
+ ### Per-Wave Budget Allocation
267
+
268
+ When running taskMaestro with a project budget, allocate per-wave:
269
+
270
+ ```
271
+ Total budget: $20.00
272
+ Estimated waves: 4
273
+ Per-wave allocation: $5.00 per wave
274
+
275
+ Wave 1: $5.00 budget → actual: $3.20 → remaining pool: $16.80
276
+ Wave 2: $5.60 budget (redistributed) → actual: $4.10 → remaining pool: $12.70
277
+ Wave 3: $6.35 budget (redistributed) → ...
278
+ ```
279
+
280
+ **Redistribution rule:** Unspent budget from completed waves rolls into remaining waves equally.
281
+
282
+ ### Cross-Pane Aggregation
283
+
284
+ Each tmux pane in a taskMaestro wave runs an independent session. Aggregation:
285
+
286
+ ```
287
+ Wave cost = sum(pane_1_cost + pane_2_cost + ... + pane_N_cost)
288
+
289
+ Tracking via shared state:
290
+ state_write(mode: "cost-budget", state: {
291
+ "wave_id": "wave-2",
292
+ "pane_id": "pane-3",
293
+ "pane_cost": "1.25",
294
+ "wave_budget": "5.60"
295
+ })
296
+ ```
297
+
298
+ ### Wave-Level Threshold Checks
299
+
300
+ After each pane completes, check the wave aggregate:
301
+
302
+ ```
303
+ 1. Pane completes → reports cost to shared state
304
+ 2. Orchestrator reads all pane costs for current wave
305
+ 3. Calculate: wave_spent = sum(all pane costs)
306
+ 4. Check: wave_spent vs wave_budget
307
+ 5. If WARN → alert, continue remaining panes
308
+ 6. If CRITICAL → let running panes finish, block next wave
309
+ ```
310
+
311
+ ---
312
+
313
+ ## Verification Checklist
314
+
315
+ Before starting an autonomous workflow:
316
+
317
+ - [ ] Budget is declared (`COST_BUDGET_USD` or config)
318
+ - [ ] Scope is appropriate (`session` / `wave` / `project`)
319
+ - [ ] Thresholds are configured (default: 50/80/100%)
320
+ - [ ] Alert channels are set up (terminal is automatic)
321
+ - [ ] Webhook URL is valid (if using webhook alerts)
322
+ - [ ] Override protocol is understood by the operator
323
+
324
+ During execution:
325
+
326
+ - [ ] Cost is tracked per request
327
+ - [ ] Thresholds trigger correct alert level
328
+ - [ ] WARN alerts appear in terminal
329
+ - [ ] CRITICAL threshold pauses the workflow
330
+ - [ ] State is saved before pause
331
+ - [ ] Override resumes workflow correctly
332
+
333
+ After completion:
334
+
335
+ - [ ] Total cost is logged
336
+ - [ ] Cost breakdown is available (per-session, per-wave)
337
+ - [ ] Budget vs actual comparison is recorded
338
+
339
+ ## Red Flags — STOP
340
+
341
+ | Thought | Reality |
342
+ |---------|---------|
343
+ | "It's just a quick autopilot run, no budget needed" | Quick runs become long runs. Set a budget. |
344
+ | "I'll check the cost later" | Later is after the money is spent. Track now. |
345
+ | "The budget is too small, I'll just override" | If you're always overriding, your budget is wrong. Increase it properly. |
346
+ | "Token counting is too much overhead" | API responses include token counts. No extra cost to read them. |
347
+ | "I'll skip the webhook, terminal alerts are enough" | You won't see terminal alerts if you walk away. Set up webhooks for unattended runs. |
348
+ | "One pane won't affect the total budget much" | Parallel panes multiply cost linearly. 8 panes = 8x the cost rate. |