Ci fix

From phatblat/dotfiles · View interactive version

Ci fix is an AI agent skill from the GitHub repository phatblat/dotfiles. Use when the user says "fix CI", "CI is red", or pastes a failing run URL: find root causes, fix, push, watch until green. Not for authoring workflows or read-only diagnosis.

How to use this skill

Skill file

CI Fix

Drive failing CI to green: resolve the target, enumerate failures, extract

evidence, cluster into root causes, fix the narrowest way possible, push, and

watch — repeating until checks pass or a stop condition trips.

1. Resolve the target

Priority order:

  1. GHA run/job URL — https://github.com/{owner}/{repo}/actions/runs/{run_id}

optionally /job/{job_id}; parse owner, repo, run_id, job_id.

  1. PR reference — #N, N, owner/repo#N, or PR URL:

```bash

gh pr view <ref> --json number,headRefName,headRefOid,baseRefName,url,isCrossRepository

```

  1. Branch name — gh run list --branch <branch> --limit 20.
  2. Nothing / prose only — default to the current branch's PR (gh pr view --json ...

with no ref); if no PR, fall back to gh run list --branch "$(git branch --show-current)".

  1. Freeform text — never discard. Treat as a scope hint narrowing which

failures to attack (e.g. "the lint and agent-harness checks are failing")

and echo it back as the user's stated scope.

Ambiguity rule: if the input resolves to more than one plausible PR or repo,

stop and ask once, listing candidates. Never guess a repo.

Non-GitHub URL (GitLab, Buildkite, CircleCI, Jenkins, Azure): fetch the URL,

read the visible log text, and continue with the same clustering logic. State

plainly that reproduction and watch automation are GHA-only; non-GHA targets

get analysis + a fix, with re-run verification left to the user.

2. Enumerate failures

```bash

gh pr checks <ref> --json name,state,bucket,link,workflow,description

gh run list --branch <branch> --limit 20 \

--json databaseId,name,conclusion,status,event,headSha,workflowName,createdAt

```

Field names for gh pr checks --json vary by gh version; if it errors,

run gh pr checks --json 2>&1 — it prints the valid field list — and use

that.

startup_failure. cancelled is usually collateral from a fail-fast

sibling and must not be counted as its own root cause.

Chasing an already-fixed failure from a superseded push is the most common

wasted loop.

```bash

gh run view <run_id> --json jobs \

--jq '.jobs[] | select(.conclusion=="failure") | {name, databaseId, steps: [.steps[] | select(.conclusion=="failure") | {name, number}]}'

```

symptom) before any analysis. This table is the loop's unit of progress and

is re-emitted each iteration.

3. Extract evidence

raw logs into context.

capped at the first error line plus the last ~100 lines of the failing

step. (Do not use gh job view — it is not a stable gh command.)

file:line when present.

possible:

```bash

gh run view <run_id> --json workflowName,path

```

then read .github/workflows/<file> locally at the head SHA, noting

working-directory, env, and matrix values for the failing leg.

4. Cluster into root causes

Group by cause, not by job. Signals that two failures share one cause:

identical error text, same failing file, same tool/step name across matrix

legs, or a common upstream artifact/job.

Classify each cluster into exactly one:

its source. High prior in this repo: ~/scripts/agent-harnesses.py

generates ~/.agents/harness/** and the native adapter trees, and

just harness-check fails on stale artifacts. Fix by re-running the

generator (just harness-generate), never by hand-editing generated

output.

is wrong.

missing secret. Not fixable by a code change.

code change.

this PR. Verify rather than assert:

```bash

gh run list --branch <baseRefName> --limit 5 --json conclusion,workflowName,headSha

```

Attempt local reproduction before editing. Derive the local command from

the failing workflow step (honoring working-directory and required env),

run it, and confirm it fails the same way. A locally validated fix saves a

full CI round trip. If the step cannot run locally (needs secrets, a specific

runner, service containers), say so and proceed to a reasoned fix.

5. Fix

continue-on-error, weaken assertions, or edit fixtures/expected values to

make a check pass. Suppressing a check is not fixing CI. If the only

viable fix is suppression, stop and ask.

re-run instead: gh run rerun <run_id> --failed.

revert stays surgical.

without write access, or when the working tree carries unrelated staged

changes — report instead.

6. Watch and iterate

created after a push, so poll for its existence before watching:

```bash

gh pr checks <ref> --watch --fail-fast=false

```

or gh run watch <run_id> --exit-status for a single run.

SHA.

repeating a failing strategy signals a wrong diagnosis, so report

evidence and ask for direction;

remains, per-cluster evidence, commits pushed.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.