|
| 1 | +--- |
| 2 | +name: bugs |
| 3 | +description: Automated bug triage and fix pipeline. Fetches open GitHub Issues, performs root cause analysis, writes failing tests, fixes bugs in isolated worktrees, and publishes. Use when the user says /bugs, "check for bugs", "triage bugs", or "fix reported issues". |
| 4 | +--- |
| 5 | + |
| 6 | +# /bugs - Triage, Fix, Publish |
| 7 | + |
| 8 | +Autonomous bug triage pipeline for `run402-mcp`. Fetches all open GitHub issues, analyzes root causes, fixes what can be fixed, and publishes. |
| 9 | + |
| 10 | +Execute all steps in order. Do NOT ask for confirmation until Step 6. |
| 11 | + |
| 12 | +Note: this package is a client-side MCP server / CLI with no server-side error telemetry, so there is no Bugsnag source. GitHub issues on `kychee-com/run402` are the only bug source. |
| 13 | + |
| 14 | +## Step 0: Sync with remote |
| 15 | + |
| 16 | +Before analyzing any issues, make sure the local `main` branch is up to date with the remote. A stale local branch leads to wasted analysis, version-bump collisions at publish time, and worktrees that rebase poorly. |
| 17 | + |
| 18 | +``` |
| 19 | +git fetch origin main |
| 20 | +git status |
| 21 | +``` |
| 22 | + |
| 23 | +If the working tree is clean and local `main` is behind `origin/main`, fast-forward: `git pull --ff-only origin main`. |
| 24 | +If there are uncommitted changes, stop and tell the user before continuing. |
| 25 | +If `main` has diverged (local commits that aren't on remote), stop and ask the user how to proceed — do not auto-rebase or force-push. |
| 26 | + |
| 27 | +## Step 1: Fetch all open bugs |
| 28 | + |
| 29 | +### GitHub issues |
| 30 | + |
| 31 | +``` |
| 32 | +gh issue list --repo kychee-com/run402 --state open --json number,title,body,labels,createdAt |
| 33 | +``` |
| 34 | + |
| 35 | +### Build unified list |
| 36 | + |
| 37 | +Assign each issue an ID for reference throughout the pipeline: |
| 38 | +- GitHub issues: `GH-<number>` (using the actual issue number) |
| 39 | + |
| 40 | +Ignore issues labelled `feature-request`, `enhancement`, `question`, or `discussion` - this pipeline only triages bug reports. |
| 41 | + |
| 42 | +If zero bug-type issues found, report "No open bugs" and stop. |
| 43 | + |
| 44 | +## Step 2: Root cause analysis |
| 45 | + |
| 46 | +For each bug: |
| 47 | + |
| 48 | +1. Read the issue title, body, and any reproduction steps or stack traces |
| 49 | +2. Trace through the source code. Relevant roots in this monorepo: |
| 50 | + - `src/` - MCP server entry + tool handlers |
| 51 | + - `core/src/` - shared logic (config, client, keystore, allowance, allowance-auth) |
| 52 | + - `cli/lib/` - CLI command modules (`*.mjs`) |
| 53 | + - `openclaw/scripts/` - OpenClaw skill shims (`*.mjs`, usually re-export from `cli/lib/`) |
| 54 | +3. Check git log to see if the relevant code has already been changed |
| 55 | +4. Categorize into exactly one bucket: |
| 56 | + |
| 57 | +| Category | Criteria | Action | |
| 58 | +|----------|----------|--------| |
| 59 | +| `already-fixed` | Code already changed, or a release was published that contains the fix | Close | |
| 60 | +| `not-a-bug` | Expected behavior, environment issue, or user error | Close with explanation | |
| 61 | +| `needs-spec-change` | "Bug" is actually missing functionality or a design decision | Flag as feature request - do NOT fix | |
| 62 | +| `fixable` | Real code bug with a clear fix | Spawn fix agent | |
| 63 | + |
| 64 | +Print a summary table as you go so progress is visible. |
| 65 | + |
| 66 | +## Step 3: Close resolved bugs and flag feature requests |
| 67 | + |
| 68 | +### Already-fixed / not-a-bug |
| 69 | + |
| 70 | +``` |
| 71 | +gh issue close <NUMBER> --repo kychee-com/run402 --comment "<one-line explanation>" |
| 72 | +``` |
| 73 | + |
| 74 | +### Needs-spec-change |
| 75 | + |
| 76 | +Add label and comment, do NOT close: |
| 77 | + |
| 78 | +``` |
| 79 | +gh issue edit <NUMBER> --repo kychee-com/run402 --add-label "feature-request" |
| 80 | +gh issue comment <NUMBER> --repo kychee-com/run402 --body "Triaged as feature request: <explanation>" |
| 81 | +``` |
| 82 | + |
| 83 | +If no fixable bugs remain, skip to Step 5. |
| 84 | + |
| 85 | +## Step 4: Fix bugs in isolated worktrees |
| 86 | + |
| 87 | +For each fixable bug, launch an Agent tool call with `isolation: "worktree"`. Launch all fixable bugs in parallel (single message, multiple Agent tool calls). |
| 88 | + |
| 89 | +Each agent prompt MUST be self-contained - include the literal issue title, reproduction steps, file paths with line numbers, and root cause analysis. The agent has no access to this conversation's context. |
| 90 | + |
| 91 | +**Agent prompt template:** |
| 92 | + |
| 93 | + Fix bug {ID}: {issue title} |
| 94 | + |
| 95 | + Repro / symptom: {from the issue body} |
| 96 | + Root cause: {analysis} |
| 97 | + Files: {file paths with line numbers} |
| 98 | + |
| 99 | + Steps: |
| 100 | + 1. Write a failing test in the appropriate test file. Follow the existing pattern for the area: |
| 101 | + - `src/tools/*.test.ts` or `core/src/*.test.ts` - Node `node:test` + `assert` + `mock.module`, TypeScript via `tsx` |
| 102 | + - `cli-e2e.test.mjs` - CLI end-to-end tests (plain `node --test`, no `tsx`) |
| 103 | + 2. Run the test to confirm it fails: |
| 104 | + - TS unit test: `node --experimental-test-module-mocks --test --import tsx <test-file>` |
| 105 | + - CLI e2e: `node --test <test-file>` |
| 106 | + 3. Implement the fix in the source file. Respect the shared-core pattern: if the bug is in `core/src/`, fix it there and rebuild; MCP/CLI/OpenClaw should not diverge. |
| 107 | + 4. Run the test again to confirm it passes |
| 108 | + 5. Run typecheck: `npx tsc --noEmit && npx tsc --noEmit -p core/tsconfig.json` |
| 109 | + 6. Run the full build: `npm run build` |
| 110 | + 7. Run the full test suite: `npm test` |
| 111 | + 8. If all pass, commit with message: `fix(<scope>): <description>` |
| 112 | + Add `Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>` to the commit. |
| 113 | + 9. If any step fails, do NOT commit. Report what went wrong. |
| 114 | + |
| 115 | + IMPORTANT: |
| 116 | + - Never use `$()` command substitution in shell commands. Run commands separately and use literal values. |
| 117 | + - If you add a new MCP tool or CLI command as part of the fix, update the `SURFACE` array in `sync.test.ts` so `npm run test:sync` passes. |
| 118 | + |
| 119 | +If more than 10 fixable bugs are found, warn the user and suggest batching before spawning agents. |
| 120 | + |
| 121 | +## Step 5: Report |
| 122 | + |
| 123 | +After all agents complete (or if there were no fixable bugs), present the full report: |
| 124 | + |
| 125 | +``` |
| 126 | +## Bug Triage Report |
| 127 | +
|
| 128 | +### Summary |
| 129 | +- Total: N open GitHub issues |
| 130 | +- Closed (already-fixed): N |
| 131 | +- Closed (not-a-bug): N |
| 132 | +- Feature requests (flagged): N |
| 133 | +- Fixes ready: N |
| 134 | +- Fix failures: N |
| 135 | +
|
| 136 | +### Fixes Ready to Merge |
| 137 | +| ID | Title | Worktree Branch | Test | TSC | Build | npm test | |
| 138 | +|---|---|---|---|---|---|---| |
| 139 | +
|
| 140 | +### Failed Fixes (if any) |
| 141 | +| ID | Title | What went wrong | |
| 142 | +|---|---|---| |
| 143 | +
|
| 144 | +### Closed Bugs |
| 145 | +| ID | Title | Reason | |
| 146 | +|---|---|---| |
| 147 | +
|
| 148 | +### Feature Requests (not auto-fixed) |
| 149 | +| ID | Title | Recommendation | |
| 150 | +|---|---|---| |
| 151 | +``` |
| 152 | + |
| 153 | +If there are no fixes to merge, stop here. |
| 154 | + |
| 155 | +## Step 6: User decision |
| 156 | + |
| 157 | +Use AskUserQuestion with these options: |
| 158 | +- **Merge all** - merge all ready fixes, publish, and close issues |
| 159 | +- **Exclude specific bugs** - let the user type which bug IDs to skip |
| 160 | +- **Merge only, skip publish** - land the fixes on `main` without cutting a new release |
| 161 | + |
| 162 | +Wait for the user's response before proceeding. |
| 163 | + |
| 164 | +## Step 7: Merge, publish, close |
| 165 | + |
| 166 | +### 7a. Merge fix branches |
| 167 | + |
| 168 | +For each included fix, the Agent tool with `isolation: "worktree"` returns the worktree path and branch name. Merge each branch into the current branch: |
| 169 | + |
| 170 | +``` |
| 171 | +git merge <branch-name> --no-edit |
| 172 | +``` |
| 173 | + |
| 174 | +If a merge conflict occurs, stop and report which branches conflict. Let the user resolve manually. |
| 175 | + |
| 176 | +### 7b. Publish (if the user chose to publish) |
| 177 | + |
| 178 | +Invoke the publish skill: |
| 179 | + |
| 180 | +``` |
| 181 | +Use the Skill tool: Skill(skill: "publish") |
| 182 | +``` |
| 183 | + |
| 184 | +The publish skill runs pre-publish checks (clean tree, `npm test`, `npm run build`), bumps versions in both `package.json` files, and publishes `run402-mcp` and `run402`. It will ask for the bump type (patch/minor/major) - recommend `patch` for pure bug fixes. |
| 185 | + |
| 186 | +### 7c. Close fixed bugs |
| 187 | + |
| 188 | +After a successful merge (and publish, if applicable): |
| 189 | + |
| 190 | +``` |
| 191 | +gh issue close <NUMBER> --repo kychee-com/run402 --comment "Fixed in <commit-hash>, released in v<version>" |
| 192 | +``` |
| 193 | + |
| 194 | +If the user chose "merge only, skip publish", drop the "released in" clause. |
| 195 | + |
| 196 | +### 7d. Clean up |
| 197 | + |
| 198 | +Excluded fix worktrees are kept (user can revisit). Merged worktrees are cleaned up automatically by the Agent tool. |
| 199 | + |
| 200 | +Report final summary: which bugs were fixed, merged, published (if applicable), and closed. |
0 commit comments