@massu/core 0.4.1 → 0.4.2

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.
@@ -74,3 +74,13 @@ After every bug fix or issue resolution:
74
74
  2. Check if pattern scanner should be updated - Can the check be automated?
75
75
  3. Update session state - Record in `.claude/session-state/CURRENT.md`
76
76
  4. Search codebase-wide for same bad pattern (CR-9) and fix all instances
77
+
78
+ Full protocol: [_shared-references/auto-learning-protocol.md](_shared-references/auto-learning-protocol.md)
79
+
80
+ ## Folder-Based Skills
81
+
82
+ Some commands are folder-based skills (directories instead of single files). For these:
83
+ 1. Read the main `.md` file first (contains overview + START NOW)
84
+ 2. Check the `## Skill Contents` table for available reference docs
85
+ 3. Load reference docs on-demand as needed during execution
86
+ 4. Helper scripts in `scripts/` can be executed directly
@@ -0,0 +1,327 @@
1
+ ---
2
+ name: massu-batch
3
+ description: "When user wants to apply the same code-only change across multiple files in parallel — 'batch update', 'apply to all', 'migrate these files'"
4
+ allowed-tools: Bash(*), Read(*), Write(*), Edit(*), Grep(*), Glob(*)
5
+ ---
6
+ name: massu-batch
7
+
8
+ # Massu Batch: Parallel Code Migration via Worktree Agents
9
+
10
+ > **Shared rules apply.** Read `.claude/commands/_shared-preamble.md` before proceeding.
11
+
12
+ ---
13
+
14
+ ## Workflow Position
15
+
16
+ ```
17
+ /massu-batch [migration] → /massu-simplify → /massu-commit → /massu-push
18
+ ```
19
+
20
+ **This command is for CODE-ONLY migrations. It REFUSES database work.**
21
+
22
+ ---
23
+
24
+ ## What This Command Does
25
+
26
+ Takes a migration description, identifies all affected files, splits them into batches, and spawns parallel agents in isolated git worktrees. Each agent transforms its files independently, runs checks, and the results merge back into your branch.
27
+
28
+ **Best for**: Import renames, component swaps, API call updates, class name migrations, pattern replacements across 5+ files.
29
+
30
+ **NOT for**: New features, database migrations, changes requiring cross-file coordination.
31
+
32
+ ---
33
+
34
+ ## EXECUTION PROTOCOL
35
+
36
+ ### Step 1: Parse Migration Description
37
+
38
+ Read `$ARGUMENTS` for the migration description.
39
+
40
+ If no arguments provided, ask:
41
+ - **Search pattern**: What to find (glob pattern or grep pattern)
42
+ - **Transformation**: What to change it to
43
+ - **Scope**: Directory to limit search (default: `src/`)
44
+
45
+ ### Step 2: DB Guard (Safety Gate — MANDATORY)
46
+
47
+ **This step CANNOT be skipped. No exceptions.**
48
+
49
+ Check the migration description for these keywords:
50
+ ```
51
+ migration, schema, ALTER, CREATE TABLE, DROP, column, RLS, GRANT,
52
+ database, prisma, supabase, ctx.db, ctx.prisma, $queryRaw, execute_sql
53
+ ```
54
+
55
+ And check target file paths for:
56
+ ```
57
+ src/server/api/routers/
58
+ src/lib/db
59
+ prisma/
60
+ supabase/migrations/
61
+ ```
62
+
63
+ **If ANY check triggers**: HALT immediately with:
64
+
65
+ ```
66
+ ## DB GUARD: Migration Blocked
67
+
68
+ This migration touches database-related code. Database migrations require
69
+ sequential coordination across environments.
70
+
71
+ /massu-batch is designed for code-only migrations:
72
+ - Import path changes
73
+ - Component library swaps
74
+ - API call updates
75
+ - Renaming patterns
76
+ - Style/class name migrations
77
+ - Utility function swaps
78
+
79
+ To proceed with database work: /massu-create-plan → /massu-loop
80
+ ```
81
+
82
+ **STOP HERE. Do not proceed. Do not offer workarounds.**
83
+
84
+ ### Step 3: Identify Affected Files
85
+
86
+ ```bash
87
+ # Use Grep to find all files matching the migration pattern
88
+ grep -rn "[search_pattern]" src/ --include="*.ts" --include="*.tsx" -l
89
+ ```
90
+
91
+ If 0 files found: "No files match the migration pattern. Check your search pattern." STOP.
92
+ If < 5 files found: "Only N files affected. Consider making these changes manually instead of using /massu-batch." Offer to proceed anyway or cancel.
93
+
94
+ ### Step 4: Planning Phase (Interactive — Requires User Approval)
95
+
96
+ Split files into batches:
97
+ - **Batch size**: 5-8 files per agent
98
+ - **Minimum agents**: 2 (otherwise manual is faster)
99
+ - **Maximum agents**: 15 (beyond this, consolidation risk increases)
100
+ - **Grouping strategy**: Group files from the same directory together when possible
101
+
102
+ Present the plan:
103
+
104
+ ```markdown
105
+ ## Batch Migration Plan
106
+
107
+ **Migration**: [description]
108
+ **Search pattern**: [pattern]
109
+ **Total files**: N
110
+ **Batches**: M agents x ~K files each
111
+
112
+ | Batch | Files | Directory |
113
+ |-------|-------|-----------|
114
+ | 1 | file1.tsx, file2.tsx, file3.tsx, file4.tsx, file5.tsx | src/components/ |
115
+ | 2 | file6.tsx, file7.tsx, file8.tsx, file9.tsx | src/app/ |
116
+ | 3 | file10.tsx, file11.tsx, file12.tsx | src/lib/ |
117
+
118
+ Each agent will:
119
+ 1. Apply the transformation to its assigned files
120
+ 2. Run pattern-scanner.sh --single-file on each changed file
121
+ 3. Run tsc type check
122
+ 4. Report results
123
+ ```
124
+
125
+ **Wait for explicit user approval. Do NOT proceed without it.**
126
+
127
+ ### Step 5: Execution Phase (Parallel Worktree Agents)
128
+
129
+ Spawn all agents simultaneously using the Agent tool with `isolation: "worktree"`:
130
+
131
+ ```
132
+ FOR each batch (IN PARALLEL):
133
+ result_{batch_id} = Agent(
134
+ subagent_type="general-purpose",
135
+ isolation="worktree",
136
+ model="sonnet",
137
+ description="Batch {batch_id}: migrate {N} files",
138
+ prompt="
139
+ You are a CODE MIGRATION AGENT. Apply this transformation to the assigned files.
140
+
141
+ ## Migration
142
+ {migration_description}
143
+
144
+ ## Transformation Rule
145
+ FIND: {search_pattern}
146
+ REPLACE WITH: {replacement_pattern}
147
+
148
+ ## Assigned Files
149
+ {file_list_for_this_batch}
150
+
151
+ ## Instructions
152
+ For EACH file in your assignment:
153
+ 1. Read the file completely
154
+ 2. Apply the transformation — change ONLY what matches the pattern
155
+ 3. Do NOT modify unrelated code
156
+ 4. Do NOT add comments about the migration
157
+ 5. Do NOT change formatting or whitespace beyond the transformation
158
+ 6. Save the file
159
+
160
+ After ALL files are modified:
161
+ 7. Run: ./scripts/pattern-scanner.sh --single-file [file] for each changed file
162
+ 8. If pattern-scanner finds violations, fix them
163
+ 9. Run: NODE_OPTIONS='--max-old-space-size=8192' npx tsc --noEmit
164
+ 10. If tsc finds errors in your changed files, fix them
165
+
166
+ ## Output Format (MANDATORY)
167
+ Return this EXACT structure:
168
+
169
+ BATCH_ID: {batch_id}
170
+ FILES_MODIFIED: [count]
171
+ PATTERN_SCANNER: PASS | FAIL
172
+ TSC_CHECK: PASS | FAIL
173
+ CHANGES:
174
+ - [file]: [brief description of change]
175
+ - [file]: [brief description of change]
176
+ ERRORS: [any errors encountered, or NONE]
177
+ "
178
+ )
179
+ END FOR
180
+ ```
181
+
182
+ **All agents run simultaneously.** This is the core parallelization benefit.
183
+
184
+ ### Step 6: Consolidation Phase
185
+
186
+ After ALL agents complete:
187
+
188
+ 1. **Collect results** from each agent
189
+ 2. **Check for failures**:
190
+ - If any agent's worktree has changes, the branch name is returned
191
+ - Failed agents: log the failure, mark batch as needs-retry
192
+ 3. **Merge worktree branches**:
193
+ ```bash
194
+ # For each successful agent's worktree branch:
195
+ git merge [worktree-branch] --no-edit
196
+ # If merge conflict: flag for manual resolution
197
+ ```
198
+ 4. **Handle conflicts**:
199
+ - Conflicts should be RARE since files don't overlap between batches
200
+ - If conflicts occur: report to user with conflicting files and stop
201
+ - User can resolve manually and re-run verification
202
+
203
+ ### Step 7: Verification Phase
204
+
205
+ Run on the consolidated result:
206
+
207
+ ```bash
208
+ # Full pattern scanner
209
+ ./scripts/pattern-scanner.sh
210
+
211
+ # Full type check
212
+ NODE_OPTIONS="--max-old-space-size=8192" npx tsc --noEmit
213
+
214
+ # Build check
215
+ npm run build
216
+ ```
217
+
218
+ ### Step 8: Output Structured Result
219
+
220
+ ```markdown
221
+ ## /massu-batch Results
222
+
223
+ **Migration**: [description]
224
+ **Total files**: N across M batches
225
+ **Duration**: Xs
226
+
227
+ | Batch | Files | Agent Status | Pattern Scanner | TSC |
228
+ |-------|-------|-------------|-----------------|-----|
229
+ | 1 | 5 | PASS | PASS | PASS |
230
+ | 2 | 5 | PASS | PASS | PASS |
231
+ | 3 | 3 | PASS | PASS | PASS |
232
+
233
+ ### Consolidated Verification
234
+
235
+ | Check | Status |
236
+ |-------|--------|
237
+ | Pattern Scanner (full) | PASS / FAIL |
238
+ | TypeScript (full) | PASS / FAIL |
239
+ | Build | PASS / FAIL |
240
+
241
+ BATCH_GATE: PASS
242
+
243
+ ### Changes Summary
244
+ - [file]: [change]
245
+ - [file]: [change]
246
+ ...
247
+
248
+ ### Next Steps
249
+ 1. Run /massu-simplify for efficiency review (recommended)
250
+ 2. Run /massu-commit to commit
251
+ 3. Run /massu-push to push
252
+ ```
253
+
254
+ If verification fails:
255
+
256
+ ```
257
+ BATCH_GATE: FAIL
258
+
259
+ ### Failures
260
+ - [check]: [error details]
261
+
262
+ ### Recovery Options
263
+ 1. Fix the failing files manually, then re-run verification
264
+ 2. Run /massu-batch again with adjusted scope
265
+ 3. Abort and use /massu-loop for sequential implementation
266
+ ```
267
+
268
+ ### Step 9: Cleanup
269
+
270
+ Worktrees are auto-cleaned by the Agent tool. If any remain:
271
+
272
+ ```bash
273
+ # List lingering worktrees
274
+ git worktree list
275
+
276
+ # Remove if needed (user confirmation required)
277
+ git worktree remove [path]
278
+ ```
279
+
280
+ ---
281
+
282
+ ## SAFETY RULES
283
+
284
+ | Rule | Enforcement |
285
+ |------|-------------|
286
+ | **No database changes** | DB guard inline keyword check + path check |
287
+ | **User approval required** | Interactive approval before execution phase |
288
+ | **No file overlap between batches** | Planning phase ensures each file appears in exactly one batch |
289
+ | **Per-agent verification** | Each agent runs pattern-scanner + tsc before completing |
290
+ | **Consolidated verification** | Full checks run after merge |
291
+ | **Merge conflicts halt execution** | No automatic conflict resolution |
292
+
293
+ ---
294
+
295
+ ## EXAMPLES
296
+
297
+ ```bash
298
+ # Rename an import path
299
+ /massu-batch "change all imports from @/components/ui/old-button to @/components/ui/button"
300
+
301
+ # Replace a deprecated hook
302
+ /massu-batch "replace all useToast() calls with the new toast() pattern from @/components/ui/sonner"
303
+
304
+ # Migrate CSS classes
305
+ /massu-batch "replace className='container mx-auto' with className='page-container' in all page files"
306
+
307
+ # Update API calls
308
+ /massu-batch "update all fetch('/api/v1/...') calls to fetch('/api/v2/...') in src/lib/integrations/"
309
+ ```
310
+
311
+ ---
312
+
313
+ ## WHEN NOT TO USE THIS COMMAND
314
+
315
+ | Scenario | Use Instead |
316
+ |----------|-------------|
317
+ | Database/schema changes | `/massu-loop` |
318
+ | < 5 files affected | Manual changes + `/massu-simplify` |
319
+ | New feature development | `/massu-create-plan` → `/massu-loop` |
320
+ | Cross-file dependencies | `/massu-loop` (sequential is safer) |
321
+ | Changes needing plan coverage | `/massu-loop` (has plan audit loop) |
322
+
323
+ ## Gotchas
324
+
325
+ - **NEVER for database work** — batch migrations are CODE-ONLY. Database migrations must be applied to all environments in sequence, which requires coordination that parallel agents cannot provide
326
+ - **Worktree isolation** — each agent runs in a git worktree. Changes must be mergeable. Agents editing the same file will cause merge conflicts
327
+ - **One task per agent** — each worktree agent gets exactly one plan item. Never combine unrelated items in a single agent
@@ -0,0 +1,204 @@
1
+ ---
2
+ name: massu-bearings
3
+ description: "When user starts a new session, says 'good morning', asks 'where was I', 'what should I work on', or needs session orientation after being away"
4
+ allowed-tools: Bash(*), Read(*), Grep(*), Glob(*)
5
+ ---
6
+ name: massu-bearings
7
+
8
+ # Massu Bearings: Session Orientation
9
+
10
+ > **Shared rules apply.** Read `.claude/commands/_shared-preamble.md` before proceeding.
11
+
12
+ ---
13
+
14
+ ## Purpose
15
+
16
+ Answer one question: **"Where am I and what should I focus on?"**
17
+
18
+ This is a READ-ONLY orientation command. It reads session state, recent history, parked ideas, and open plans, then presents a concise human-readable briefing. It does NOT modify any files.
19
+
20
+ **Privilege level**: Level 1 (read-only) — same as `massu-create-plan` in recovery.md hierarchy.
21
+
22
+ **This does NOT replace the recovery protocol** (`protocols/recovery.md`). Recovery is the full post-compaction restoration procedure. Bearings is the quick "good morning" briefing that layers on top.
23
+
24
+ ---
25
+
26
+ ## Data Sources
27
+
28
+ Read these in parallel where possible:
29
+
30
+ | # | Source | What to extract |
31
+ |---|--------|----------------|
32
+ | 1 | `session-state/CURRENT.md` | Active task, status, decisions, blockers |
33
+ | 2 | Last 5 session archives (by date) | Recent completed work, patterns |
34
+ | 3 | `session-state/squirrels.md` | Parked ideas count and list |
35
+ | 4 | `.claude/plans/*.md` | Any open/in-progress plans |
36
+ | 5 | `git log --oneline -10` | Recent commits for context |
37
+ | 6 | `git diff --stat` | Any uncommitted changes |
38
+ | 7 | `memory/corrections.md` | Active correction rules |
39
+ | 8 | `memory/auto-patterns/*.md` | Auto-extracted pattern candidates (status: candidate) |
40
+ | 9 | `.claude/metrics/command-scores.jsonl` | Command quality scores — flag any below 60% on last 3 runs |
41
+ | 10 | `.claude/metrics/command-invocations.jsonl` | Command usage frequency — top/least used in last 7 days |
42
+ | 11 | `.claude/metrics/bearings-history.jsonl` | Previous bearings runs — show trends |
43
+ | 12 | `.claude/commands/` (ls -d */`) | Detect folder-based skills (directories vs flat files) |
44
+
45
+ ---
46
+
47
+ ## Output Format
48
+
49
+ Present directly to terminal. Do NOT write to a file.
50
+
51
+ ```
52
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
53
+ BEARINGS — [date]
54
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
55
+
56
+ CURRENT STATE
57
+ Status: [active task or "No active task"]
58
+ Branch: [current git branch]
59
+ Uncommitted: [N files changed / clean]
60
+
61
+ STILL OPEN
62
+ - [item 1 from CURRENT.md or recent archives]
63
+ - [item 2]
64
+
65
+ RECENTLY COMPLETED (last 3-5)
66
+ - [commit hash] [message] ([date])
67
+ - [commit hash] [message] ([date])
68
+
69
+ OPEN PLANS
70
+ - [plan name] — [status, items remaining]
71
+ (or "No open plans")
72
+
73
+ PARKED IDEAS ([N] squirrels)
74
+ - [idea 1]
75
+ - [idea 2]
76
+ (or "No parked squirrels")
77
+
78
+ SUGGESTED FOCUS
79
+ 1. [highest priority item — why]
80
+ 2. [next priority item — why]
81
+ 3. [optional third item]
82
+
83
+ PATTERN CANDIDATES ([N] pending review)
84
+ - [date] [title] (confidence: X/15) — review and promote or dismiss
85
+ (or "No auto-extracted patterns")
86
+
87
+ COMMAND HEALTH ALERTS
88
+ ! [command] — [X]% on last 3 runs. Weakest: [check_name]
89
+ (or "All commands healthy (above 60%)")
90
+
91
+ COMMAND USAGE (last 7 days)
92
+ Top: [command] (N invocations), [command] (N), [command] (N)
93
+ Least: [command] (N invocations), [command] (N)
94
+ (or "No invocation data yet")
95
+
96
+ FOLDER-BASED SKILLS
97
+ [list any commands that are directories: massu-golden-path, massu-debug, massu-loop, massu-data]
98
+ (or "No folder-based skills detected")
99
+
100
+ ACTIVE WARNINGS
101
+ - [any correction rules or memory enforcement reminders]
102
+ (or "No active warnings")
103
+
104
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
105
+ ```
106
+
107
+ ---
108
+
109
+ ## Suggested Focus Logic
110
+
111
+ Prioritize items in this order:
112
+ 1. **Blockers** — anything marked as blocked in CURRENT.md
113
+ 2. **In-progress tasks** — partially completed work from last session
114
+ 3. **Open plan items** — next items in an active plan
115
+ 4. **Aging squirrels** — ideas parked > 7 days ago (mention but don't auto-promote)
116
+ 5. **New work** — only if nothing else is open
117
+
118
+ Keep to 2-3 items. This is a focus list, not an inventory.
119
+
120
+ ---
121
+
122
+ ## Auto-Extracted Pattern Candidates
123
+
124
+ Check `memory/auto-patterns/` for files with `status: candidate` in frontmatter. For each candidate:
125
+ - Read the title and confidence score
126
+ - Display in the PATTERN CANDIDATES section
127
+ - If confidence >= 12/15, mark as "HIGH — consider promoting to corrections.md"
128
+ - If confidence 8-11/15, mark as "MEDIUM — review in next implementation session"
129
+
130
+ To act on candidates:
131
+ - **Promote**: Move key content to `memory/corrections.md` or `patterns-quickref.md`, change status to `promoted`
132
+ - **Dismiss**: Change status to `dismissed` (auto-cleanup after 60 days)
133
+ - **Ignore**: Leave as `candidate` (auto-dismissed after 30 days)
134
+
135
+ ---
136
+
137
+ ## Command Health Alerts Logic
138
+
139
+ Read `.claude/metrics/command-scores.jsonl`. If the file is empty or missing, show "All commands healthy (above 60%)".
140
+
141
+ For each command in the file:
142
+ 1. Parse all JSONL lines for that command
143
+ 2. Take the last 3 runs
144
+ 3. Calculate average pass rate (e.g., "3/4" = 75%, "2/5" = 40%)
145
+ 4. If average < 60%, flag as alert with the weakest check name
146
+ 5. Display in COMMAND HEALTH ALERTS section
147
+
148
+ If no commands are below 60%, show "All commands healthy (above 60%)".
149
+
150
+ ---
151
+
152
+ ## Edge Cases
153
+
154
+ - **No CURRENT.md**: Say "No active session state. Starting fresh."
155
+ - **No archives**: Say "No session history found. This appears to be a new project."
156
+ - **No squirrels.md**: Skip the squirrels section (don't create the file — that's `/massu-squirrels`' job)
157
+ - **No open plans**: Say "No open plans"
158
+ - **No corrections.md**: Skip the warnings section
159
+
160
+ ---
161
+
162
+ ## Gotchas
163
+
164
+ - **Read-only command** — bearings READS state, it does NOT modify files or start work. Wait for user direction after presenting findings
165
+ - **Don't start working unprompted** — after showing bearings, wait for the user to tell you what to work on. Don't assume the suggested focus is approved
166
+ - **Session state may be stale** — CURRENT.md may be from a previous session that ended abruptly. Cross-reference with git log for ground truth
167
+ - **Archive files are historical** — session-state/archive/ files show past work but should not drive current decisions unless user references them
168
+
169
+ ---
170
+
171
+ ## Bearings History
172
+
173
+ After presenting the bearings output, append a JSONL line to `.claude/metrics/bearings-history.jsonl`:
174
+
175
+ ```json
176
+ {"timestamp":"ISO","branch":"main","uncommitted":3,"open_plans":1,"squirrels":5,"suggested_focus":"item"}
177
+ ```
178
+
179
+ On next bearings run, read last 5 entries from `bearings-history.jsonl` to show trends:
180
+ - "Uncommitted files trending up: 1 → 3 → 5"
181
+ - "Open plans stable at 1"
182
+ - If no history file exists, skip trends.
183
+
184
+ ---
185
+
186
+ ## Command Usage Logic
187
+
188
+ Read `.claude/metrics/command-invocations.jsonl`. Filter to last 7 days by `timestamp` field. Group by `skill`, count invocations, sort descending. Show top 3 and bottom 2. If no data exists, show "No invocation data yet".
189
+
190
+ ---
191
+
192
+ ## Folder-Based Skill Detection
193
+
194
+ Run `ls -d .claude/commands/*/` to find commands that are directories. Display the list in FOLDER-BASED SKILLS section. Each folder-based skill has a `## Skill Contents` table in its main file listing sub-files.
195
+
196
+ ---
197
+
198
+ ## START NOW
199
+
200
+ 1. Read all data sources in parallel (CURRENT.md, archives, squirrels, plans, git log, git diff, corrections, metrics, bearings-history)
201
+ 2. Synthesize into the output format above
202
+ 3. Present to terminal
203
+ 4. Append bearings-history.jsonl entry
204
+ 5. Do NOT start working on anything — wait for user to choose what to focus on
@@ -0,0 +1,148 @@
1
+ ---
2
+ name: massu-ci-fix
3
+ description: "When CI fails after push — auto-diagnoses failures, fixes, commits, and re-pushes. 'ci fix', 'fix ci', 'ci failed', 'workflow failed'"
4
+ allowed-tools: Bash(*), Read(*), Edit(*), Write(*), Grep(*), Glob(*)
5
+ ---
6
+ name: massu-ci-fix
7
+
8
+ # Massu CI Fix: Auto-Diagnose and Fix CI Failures
9
+
10
+ > **Shared rules apply.** Read `.claude/commands/_shared-preamble.md` before proceeding.
11
+
12
+ ## Objective
13
+
14
+ Automatically pull CI failure logs, diagnose root cause, fix, commit, and re-push. Zero cognitive load.
15
+
16
+ ---
17
+
18
+ ## EXECUTION FLOW
19
+
20
+ ### Step 1: Identify Failed Runs
21
+
22
+ ```bash
23
+ # Get failed runs for current commit
24
+ gh run list --commit $(git rev-parse HEAD) --limit 5 --json status,conclusion,name,databaseId | jq '.[] | select(.conclusion == "failure")'
25
+ ```
26
+
27
+ If no failures found, check the most recent run on the branch:
28
+ ```bash
29
+ gh run list --branch $(git branch --show-current) --limit 3
30
+ ```
31
+
32
+ ### Step 2: Pull Failure Logs
33
+
34
+ For EACH failed run:
35
+ ```bash
36
+ gh run view [RUN_ID] --log-failed 2>&1 | tail -100
37
+ ```
38
+
39
+ Extract:
40
+ - **Failed step name**
41
+ - **Error message**
42
+ - **File and line number** (if available)
43
+ - **Exit code**
44
+
45
+ ### Step 3: Diagnose
46
+
47
+ Map the failure to a known pattern:
48
+
49
+ | CI Step | Common Cause | Fix Strategy |
50
+ |---------|-------------|--------------|
51
+ | TypeScript | Type error in committed code | Fix the type error |
52
+ | ESLint | Lint violation | Fix or disable with justification |
53
+ | Build | Import error, missing dep | Fix import or install dep |
54
+ | Tests | Test failure | Fix test or code |
55
+
56
+ ### Step 4: Fix
57
+
58
+ 1. Apply the fix
59
+ 2. Run the same check locally to verify:
60
+ ```bash
61
+ # Run the specific check that failed
62
+ npm run build # or whatever CI step failed
63
+ ```
64
+ 3. Verify fix passes locally
65
+
66
+ ### Step 5: Commit and Re-Push
67
+
68
+ ```bash
69
+ git add [fixed files]
70
+ git commit -m "fix(ci): [description of fix]
71
+
72
+ Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>"
73
+ git push origin $(git branch --show-current)
74
+ ```
75
+
76
+ ### Step 6: Monitor Re-Run
77
+
78
+ ```bash
79
+ # Wait for CI to complete (check periodically)
80
+ gh run list --branch $(git branch --show-current) --limit 1
81
+ ```
82
+
83
+ If CI fails again, loop back to Step 2 (max 3 attempts).
84
+
85
+ ---
86
+
87
+ ## LOOP CONTROL
88
+
89
+ ```
90
+ attempt = 0
91
+ MAX_ATTEMPTS = 3
92
+
93
+ WHILE attempt < MAX_ATTEMPTS:
94
+ attempt += 1
95
+
96
+ 1. Pull failure logs
97
+ 2. Diagnose
98
+ 3. Fix
99
+ 4. Verify locally
100
+ 5. Commit + push
101
+ 6. Wait for CI
102
+
103
+ IF CI passes:
104
+ Output: "CI fixed in {attempt} attempt(s)"
105
+ BREAK
106
+ ELSE:
107
+ Output: "Attempt {attempt} failed, retrying..."
108
+ CONTINUE
109
+
110
+ IF attempt == MAX_ATTEMPTS AND still failing:
111
+ Output: "CI still failing after 3 attempts. Manual investigation needed."
112
+ Show: last failure logs
113
+ ```
114
+
115
+ ---
116
+
117
+ ## OUTPUT FORMAT
118
+
119
+ ```
120
+ == CI FIX ==
121
+
122
+ Failed Run: [workflow name] (#[run_id])
123
+ Failed Step: [step_name]
124
+ Error: [error message]
125
+
126
+ Diagnosis: [root cause]
127
+ Fix: [what was changed]
128
+
129
+ Local Verification: [check command] -> PASS
130
+ Committed: fix(ci): [description]
131
+ Pushed: origin/[branch]
132
+
133
+ CI Status: Monitoring...
134
+ [step]: success
135
+
136
+ CI FIXED (1 attempt)
137
+ ```
138
+
139
+ ---
140
+
141
+ ## START NOW
142
+
143
+ 1. Identify failed CI runs
144
+ 2. Pull logs for each failure
145
+ 3. Diagnose, fix, verify locally
146
+ 4. Commit and push
147
+ 5. Monitor CI
148
+ 6. Loop if needed (max 3)