stacktrace-cli 0.0.1__tar.gz

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,35 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/claude-code-settings.json",
3
+ "hooks": {
4
+ "SessionStart": [
5
+ {
6
+ "hooks": [
7
+ {
8
+ "type": "command",
9
+ "command": "if [ -f docs/adrs/INDEX.md ]; then printf '=== ARCHITECTURE DECISIONS (docs/adrs/) ===\\n\\nRead a full ADR before changing logic in the area it covers.\\n\\n'; cat docs/adrs/INDEX.md; fi"
10
+ }
11
+ ]
12
+ }
13
+ ],
14
+ "PreCompact": [
15
+ {
16
+ "hooks": [
17
+ {
18
+ "type": "command",
19
+ "command": "if [ -f docs/adrs/HOOK-PROMPT.md ]; then printf '=== ADR CHECK BEFORE COMPACTION ===\\n\\n'; cat docs/adrs/HOOK-PROMPT.md; fi"
20
+ }
21
+ ]
22
+ }
23
+ ],
24
+ "SessionEnd": [
25
+ {
26
+ "hooks": [
27
+ {
28
+ "type": "command",
29
+ "command": "if [ -f docs/adrs/HOOK-PROMPT.md ]; then printf '=== ADR CHECK BEFORE SESSION END ===\\n\\n'; cat docs/adrs/HOOK-PROMPT.md; fi"
30
+ }
31
+ ]
32
+ }
33
+ ]
34
+ }
35
+ }
@@ -0,0 +1,194 @@
1
+ ---
2
+ name: release-stacktrace
3
+ description: Use when cutting a new stacktrace-cli PyPI release. Walks through version bump, release-notes drafting, pre-flight checks, tag, and push — enforces the publish-pypi.yml notes-file gate so the GitHub Releases page can't silently drift from PyPI.
4
+ ---
5
+
6
+ # release-stacktrace
7
+
8
+ End-to-end release procedure for the `stacktrace-cli` distribution.
9
+ `.github/workflows/publish-pypi.yml` enforces the machine-checkable gates
10
+ (tag on main, tag matches both version strings, notes file present, four
11
+ CI gates green). This skill is the human-side counterpart: it drafts the
12
+ notes with judgment, runs the pre-flight checks, and pushes the tag.
13
+
14
+ **Announce at start:** "I'm using the release-stacktrace skill to cut a new
15
+ stacktrace-cli release."
16
+
17
+ ## When to invoke
18
+
19
+ User says any of: "cut a release", "ship 0.0.N", "release stacktrace",
20
+ "tag a new version", or starts editing `pyproject.toml`'s version field
21
+ in this repo.
22
+
23
+ ## Inputs
24
+
25
+ 1. **Target version** (e.g. `0.1.0`). Inferred from `pyproject.toml` if
26
+ the user already bumped it; otherwise ask.
27
+ 2. **Theme** — the H1 line of the notes file. Ask the user; a commit log
28
+ can't infer it.
29
+
30
+ ## Procedure
31
+
32
+ ### Step 1. Pre-flight checks
33
+
34
+ Run from the repo root. Stop and ask if any fails — do not "fix" a dirty
35
+ tree or out-of-sync main automatically, those signal in-flight work.
36
+
37
+ ```bash
38
+ git rev-parse --abbrev-ref HEAD # must be main
39
+ git status --porcelain # must be empty
40
+ git fetch --tags origin
41
+ git rev-parse --verify "v<version>" 2>/dev/null # MUST FAIL — tag must not exist
42
+ test "$(git rev-parse HEAD)" = "$(git rev-parse origin/main)"
43
+ ```
44
+
45
+ PyPI versions are immutable, including yanked ones. If `<version>` is
46
+ already on PyPI, the only path forward is a new version number:
47
+
48
+ ```bash
49
+ curl -s https://pypi.org/pypi/stacktrace-cli/json | python3 -c 'import json,sys; print(sorted(json.load(sys.stdin)["releases"]))'
50
+ ```
51
+
52
+ ### Step 2. Gather the commit log
53
+
54
+ ```bash
55
+ prev_tag=$(git describe --tags --abbrev=0) # empty on the first release
56
+ git log --oneline "${prev_tag}..HEAD"
57
+ ```
58
+
59
+ Raw material only — do not dump it into the notes file verbatim.
60
+
61
+ ### Step 3. Draft `docs/releases/v<version>.md`
62
+
63
+ Follow the shape of the existing files in `docs/releases/`:
64
+
65
+ ```markdown
66
+ # <version> — <theme>
67
+
68
+ ## Highlights
69
+
70
+ - **<Theme A>.** 1-3 sentences pitched at someone who installs the CLI.
71
+ Reference ADRs by number when a design doc backs the change.
72
+ - **Bug fixes.** Combine small fixes into one bullet, comma-separated.
73
+
74
+ ## Install
75
+
76
+ `uv tool install stacktrace-cli==<version>` or `pip install stacktrace-cli==<version>`.
77
+
78
+ ## Compatibility
79
+
80
+ <Behavior changes existing users will notice. Say "pre-alpha, no
81
+ back-compat hedging" while that's still true.>
82
+ ```
83
+
84
+ **Judgment guidelines (apply ruthlessly):**
85
+
86
+ - **Group by theme, not by commit.** Five commits adding one capability
87
+ are one bullet.
88
+ - **Lead with user-visible impact**, not implementation.
89
+ - **Cut chore/format/docs-only and release-machinery commits.** They
90
+ aren't release-visible.
91
+ - **Acknowledge breaking changes explicitly** under `## Compatibility` —
92
+ a renamed subcommand or changed output shape goes there.
93
+
94
+ Show the draft to the user and iterate until they agree it captures what
95
+ shipped.
96
+
97
+ ### Step 4. Bump both version strings together
98
+
99
+ `pyproject.toml`'s `version` and `src/stacktrace_cli/__init__.py`'s
100
+ `__version__` are separate sources; the workflow fails the build if they
101
+ disagree with the tag. Move them together:
102
+
103
+ ```bash
104
+ sed -i.bak 's/^version = ".*"/version = "<version>"/' pyproject.toml && rm pyproject.toml.bak
105
+ sed -i.bak 's/^__version__ = ".*"/__version__ = "<version>"/' src/stacktrace_cli/__init__.py && rm src/stacktrace_cli/__init__.py.bak
106
+ uv lock # refresh uv.lock
107
+ uv run stacktrace --version # sanity: prints <version>
108
+ ```
109
+
110
+ ### Step 5. Release-prep commit + PR
111
+
112
+ If the user's original request did not explicitly ask to cut, ship, or
113
+ publish a release, stop before the push and ask. Editing the version
114
+ field is enough to invoke this skill; it is not permission to publish.
115
+
116
+ ```bash
117
+ git checkout -b release/<version>
118
+ git add pyproject.toml uv.lock src/stacktrace_cli/__init__.py docs/releases/v<version>.md
119
+ git status --porcelain # inspect anything still unstaged; stage intentionally or stop
120
+ git commit -m "release: <version> — <theme>"
121
+ git push -u origin release/<version>
122
+ ```
123
+
124
+ Opening the PR needs its own explicit ask. Then:
125
+
126
+ ```bash
127
+ gh pr create --title "release: <version>" --body "Release prep for <version>.
128
+
129
+ - Bumps \`pyproject.toml\` and \`__version__\` to <version>
130
+ - Adds release notes at \`docs/releases/v<version>.md\`
131
+ - After merge: tag \`v<version>\` on main and push to trigger PyPI publish + GitHub Release"
132
+ ```
133
+
134
+ Surface the PR URL. **Stop here.** The user reviews and merges.
135
+
136
+ ### Step 6. After merge: tag + push
137
+
138
+ After the user confirms the PR merged, on a clean main:
139
+
140
+ ```bash
141
+ git checkout main
142
+ git pull --ff-only
143
+ git tag v<version>
144
+ git push origin v<version>
145
+ ```
146
+
147
+ The tag-triggered run registers asynchronously, so `--limit 1` can grab a
148
+ stale earlier run. Poll for the run tied to the tagged commit:
149
+
150
+ ```bash
151
+ tag_sha=$(git rev-parse "v<version>^{commit}")
152
+ run_id=""
153
+ until [ -n "$run_id" ]; do
154
+ run_id=$(gh run list --repo stacktrace-ai/stacktrace \
155
+ --workflow publish-pypi.yml --commit "$tag_sha" \
156
+ --json databaseId --jq '.[0].databaseId // empty')
157
+ [ -z "$run_id" ] && sleep 5
158
+ done
159
+ gh run watch --repo stacktrace-ai/stacktrace "$run_id"
160
+ ```
161
+
162
+ ### Step 7. Verify
163
+
164
+ ```bash
165
+ curl -s https://pypi.org/pypi/stacktrace-cli/json | python3 -c 'import json,sys; print(sorted(json.load(sys.stdin)["releases"]))'
166
+ gh release view v<version> --repo stacktrace-ai/stacktrace --json name,body
167
+ uvx --from stacktrace-cli==<version> stacktrace --version # installs from PyPI, must print <version>
168
+ ```
169
+
170
+ All three must succeed. If any fails, surface the workflow run URL rather
171
+ than guessing.
172
+
173
+ ## Failure modes this prevents
174
+
175
+ 1. **On PyPI but not on GitHub Releases.** The workflow's notes-file gate
176
+ runs before publish: no notes file at the tag → no PyPI upload.
177
+ 2. **Notes file is a raw commit dump.** Step 3's judgment guidelines.
178
+ 3. **Tagging a non-main commit.** The workflow's "Verify tag is on main".
179
+ 4. **Tag ≠ `pyproject.toml` version, or `__version__` drift.** Two
180
+ separate workflow steps; Step 4 keeps them moving together.
181
+ 5. **Forgetting to refresh `uv.lock`.** `uv sync --frozen` fails in the
182
+ build job; Step 4 bumps the lock to avoid the round-trip.
183
+
184
+ ## What this skill does NOT do
185
+
186
+ - **Doesn't publish to PyPI directly.** The workflow does, via Trusted
187
+ Publishing (OIDC). There is no PyPI token anywhere in this repo, and
188
+ none should be added.
189
+ - **Doesn't create the GitHub Release directly.** The workflow's
190
+ `release-github` job does, from the notes file.
191
+ - **Doesn't write a CHANGELOG.md.** The convention is per-release files
192
+ under `docs/releases/`.
193
+ - **Doesn't yank.** PyPI versions are immutable; a broken release is
194
+ fixed by shipping the next version, not by re-uploading.
@@ -0,0 +1,332 @@
1
+ name: Autofix
2
+
3
+ # Two-direction comment-bounce that closes the Codex/Claude review loop
4
+ # without human intervention:
5
+ #
6
+ # 1. Codex bot reviews a PR -> this workflow posts `@claude please
7
+ # address...` -> claude.yml fires, claude reads the review, fixes
8
+ # it, pushes commits, posts a "Claude finished" summary comment.
9
+ #
10
+ # 2. Any new commits land on a PR head (`pull_request: synchronize`) ->
11
+ # this workflow posts `@codex review` -> Codex re-reviews HEAD. ONE
12
+ # job covers every source of new commits — the claude bot's fixes, a
13
+ # human / local-agent push, AND the auto-rebase force-push below —
14
+ # because `synchronize` fires regardless of who pushed. (Codex
15
+ # auto-reviews on PR open / draft->ready natively, but NOT on
16
+ # subsequent pushes; without this, later commits land unreviewed.)
17
+ #
18
+ # The two bounces together produce: codex-flag -> claude-fix ->
19
+ # codex-rereview -> ... bounded by the claude-side iteration cap in
20
+ # bounce 1 (the cap counts claude runs, so push-driven re-reviews add
21
+ # entry points, not an unbounded cycle). Codex is silent when clean
22
+ # (thumbs reaction), so an unnecessary @codex review on a no-op SHA costs
23
+ # one cheap call with no PR noise.
24
+ #
25
+ # Authentication: comments are posted (and PR branches are rebased)
26
+ # using AUTOFIX_TRIGGER_PAT, NOT secrets.GITHUB_TOKEN. GitHub explicitly
27
+ # suppresses workflow runs triggered by events created with
28
+ # GITHUB_TOKEN (recursion guard) — so a comment posted under
29
+ # github-actions[bot] would be silently dropped before claude.yml ever
30
+ # fired, and a rebase pushed under GITHUB_TOKEN would not re-trigger
31
+ # CI / Codex on the rebased branch. The PAT is fine-grained, owned by
32
+ # a repo OWNER/MEMBER, with BOTH:
33
+ # - `Pull requests: Read and write` — for `gh pr comment` (bounces 1
34
+ # and 2) and `gh pr list` (bounce 0).
35
+ # - `Contents: Read and write` — for `actions/checkout` to fetch and
36
+ # `git push` from the rebase-stale-prs job. WITHOUT this, the job
37
+ # fails at the `Checkout` step with `403: Write access to
38
+ # repository not granted` — actions/checkout asks GitHub to verify
39
+ # write permission upfront because the same token will push later.
40
+ # The resulting comments/pushes are authored by that user, which DOES
41
+ # trigger downstream workflows AND naturally passes claude.yml's
42
+ # OWNER/MEMBER/COLLABORATOR trust gate. The same PAT serves all three
43
+ # bounces — Codex's webhook listener watches @-mentions in PR comments
44
+ # regardless of author.
45
+ #
46
+ # If AUTOFIX_TRIGGER_PAT is unset, both `gh pr comment` paths fail
47
+ # with an auth error and the chain breaks; rebase-stale-prs detects
48
+ # the missing secret and skips with a workflow warning. Manual
49
+ # @claude triggers are unaffected.
50
+ #
51
+ # Workflow-injection safety: every user/bot-controlled input (PR number,
52
+ # comment body, review id) is read via env: and referenced as a shell
53
+ # variable. Comment bodies posted to the PR are hardcoded literals — no
54
+ # interpolation of untrusted input into shell.
55
+
56
+ on:
57
+ pull_request_review:
58
+ types: [submitted]
59
+ pull_request:
60
+ # Bounce 2: new commits on a PR head -> request a Codex re-review.
61
+ # `synchronize` fires for pushes from ANY author — claude bot fixes,
62
+ # human / local-agent pushes, AND the auto-rebase force-push from
63
+ # rebase-stale-prs. App-authored pushes (claude[bot]) are NOT the
64
+ # workflow's GITHUB_TOKEN, so they are not recursion-suppressed and DO
65
+ # fire this event (verified: CI runs on claude's pushed commits).
66
+ types: [synchronize]
67
+ push:
68
+ # Bounce 0: main moved -> rebase open PRs that are now stale. Catches
69
+ # both PR merges AND direct pushes to main (manual hotfixes, manual
70
+ # main pushes). pull_request:closed+merged would miss the latter.
71
+ branches: [main]
72
+
73
+ jobs:
74
+ trigger-claude-via-comment:
75
+ # Bounce 1: Codex review submitted -> @claude addresses it.
76
+ if: github.event_name == 'pull_request_review' && github.event.review.user.login == 'chatgpt-codex-connector[bot]' && github.event.review.state == 'commented'
77
+ runs-on: ubuntu-latest
78
+ permissions:
79
+ pull-requests: write
80
+ env:
81
+ GH_TOKEN: ${{ secrets.AUTOFIX_TRIGGER_PAT }}
82
+ REPO: ${{ github.repository }}
83
+ PR_NUM: ${{ github.event.pull_request.number }}
84
+ REVIEW_ID: ${{ github.event.review.id }}
85
+ RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
86
+ steps:
87
+ # Cap the auto-address loop at 7 claude runs per PR. If claude has
88
+ # already run 7+ times and Codex is still finding issues, the loop
89
+ # isn't converging — force human attention rather than burn cycles.
90
+ #
91
+ # Default was 3 originally; bumped to 7 because legitimate Codex
92
+ # reviews on substantive PRs routinely surface 5-6 rounds of real
93
+ # findings (defensive type guards across sibling files, CLI-flag
94
+ # table extensions, OSV event-window edge cases). 3 was capping
95
+ # real review work, not just runaway loops; 7 keeps the safety
96
+ # net while accommodating multi-round legitimate review. Adjust
97
+ # MAX below if your project's review patterns differ.
98
+ #
99
+ # Count claude-code-action runs by counting top-level PR comments
100
+ # authored by the bot (the action posts ONE in-progress comment
101
+ # per run and edits it in place to the "Claude finished..." summary
102
+ # — 1 comment == 1 run). More accurate than counting bot commits:
103
+ # a run that lands 0 commits (no-op fix or pre-push failure) and a
104
+ # run that lands N commits both equal one iteration of the loop.
105
+ #
106
+ # Login string is "claude" — NOT "claude[bot]" — because
107
+ # `gh pr view --json comments` uses GraphQL, and GraphQL's
108
+ # `author.login` returns the bare bot name without the `[bot]`
109
+ # suffix. The `[bot]` suffix only appears in REST surfaces (e.g.
110
+ # `github.event.comment.user.login` at bounce-2 below). Same bot,
111
+ # two string representations depending on which API you read.
112
+ - name: Cap auto-address iterations (max 7)
113
+ run: |
114
+ MAX=7
115
+ CLAUDE_RUNS=$(gh pr view "$PR_NUM" -R "$REPO" --json comments \
116
+ --jq '[.comments[] | select(.author.login == "claude")] | length')
117
+ if [ "$CLAUDE_RUNS" -ge "$MAX" ]; then
118
+ gh pr comment "$PR_NUM" -R "$REPO" --body "🛑 Auto-address loop limit hit — claude has already run $CLAUDE_RUNS times on this PR (max $MAX). Codex review id $REVIEW_ID was NOT auto-addressed. Manual review needed; re-tag claude explicitly after addressing the underlying issue if you want to continue. ([workflow run]($RUN_URL))"
119
+ echo "::error::Auto-address loop limit hit ($CLAUDE_RUNS/$MAX) — see PR comment."
120
+ exit 1
121
+ fi
122
+ echo "Auto-address iteration $((CLAUDE_RUNS + 1)) of $MAX"
123
+
124
+ # Post the @claude trigger. The body intentionally references "the
125
+ # Codex review above" — claude-code-action's default prompt
126
+ # construction will include the full review thread so the bot has
127
+ # the actual findings + line context to act on.
128
+ #
129
+ # No HEAD-SHA marker is needed here: bounce 2 is now driven by
130
+ # `pull_request: synchronize` (a real push), so "claude finished
131
+ # without pushing" simply produces no synchronize and no re-review —
132
+ # the old comment-driven no-push detection it required is gone.
133
+ - name: Post @claude trigger comment
134
+ run: |
135
+ gh pr comment "$PR_NUM" -R "$REPO" --body "@claude please address the Codex review feedback above. CRITICAL: before applying any fix that depends on infrastructure or invariants you have not verified, check the claim against its actual source of truth: for in-repo invariants (DLQ, schema, contracts, ADRs in docs/adrs/), grep the repo for the prerequisite; for claims about EXTERNAL behavior (a third-party SDK's import paths or API contract, a vendor's documented semantics, a wire format), use WebFetch/WebSearch to check the current official docs — do not accept the reviewer's citation on authority, and do not defend repo-internal assertions you cannot falsify. Only if the claim cannot be verified either way, push back via a PR comment explaining exactly what needs human confirmation rather than implementing on a false premise."
136
+
137
+ request-codex-rereview-on-push:
138
+ # Bounce 2: new commits pushed to a PR head -> @codex re-reviews HEAD.
139
+ # `pull_request: synchronize` fires on EVERY push to the PR head
140
+ # regardless of author — the claude bot's fixes, a human / local-agent
141
+ # push, AND the auto-rebase force-push from rebase-stale-prs — so this
142
+ # single job covers all of them. Replaces the old issue_comment /
143
+ # "Claude finished" trigger: claude-code-action commits via the Claude
144
+ # GitHub App (author claude[bot]), and App-authored pushes fire
145
+ # pull_request events (they are not the workflow's GITHUB_TOKEN, so not
146
+ # recursion-suppressed). "Claude finished without pushing" needs no
147
+ # special case now — no commits means no synchronize means no review.
148
+ #
149
+ # Same-repo only: GitHub withholds secrets from pull_request runs on
150
+ # fork PRs, so AUTOFIX_TRIGGER_PAT would be empty and `gh pr comment`
151
+ # would fail. Excluding forks here keeps fork PRs from producing red
152
+ # runs (and claude.yml refuses fork PRs downstream anyway).
153
+ if: >
154
+ github.event_name == 'pull_request'
155
+ && github.event.pull_request.head.repo.full_name == github.repository
156
+ runs-on: ubuntu-latest
157
+ permissions:
158
+ pull-requests: write
159
+ concurrency:
160
+ # Coalesce rapid pushes to one review of the final SHA. Without this,
161
+ # 5 quick commits = 5 separate @codex reviews (each distinct SHA
162
+ # dodges the per-SHA marker). cancel-in-progress keeps only the
163
+ # latest push's job, which then reads the current HEAD.
164
+ group: codex-rereview-${{ github.event.pull_request.number }}
165
+ cancel-in-progress: true
166
+ env:
167
+ GH_TOKEN: ${{ secrets.AUTOFIX_TRIGGER_PAT }}
168
+ REPO: ${{ github.repository }}
169
+ PR_NUM: ${{ github.event.pull_request.number }}
170
+ steps:
171
+ # Per-SHA idempotency: skip if we already requested review for the
172
+ # current HEAD. Guards a double-synchronize on the same SHA and any
173
+ # overlap with a manual @codex review. Read live HEAD (not the event
174
+ # SHA) so a coalesced burst reviews the latest commit.
175
+ - name: Post @codex re-review trigger (idempotent per SHA)
176
+ run: |
177
+ HEAD_SHA=$(gh pr view "$PR_NUM" -R "$REPO" --json headRefOid --jq '.headRefOid')
178
+ MARKER="<!-- autofix-rereview-sha:$HEAD_SHA -->"
179
+ ALREADY=$(gh pr view "$PR_NUM" -R "$REPO" --json comments \
180
+ --jq "[.comments[] | select(.body | contains(\"$MARKER\"))] | length")
181
+ if [ "$ALREADY" -gt 0 ]; then
182
+ echo "Already requested @codex review for $HEAD_SHA — skipping."
183
+ exit 0
184
+ fi
185
+ gh pr comment "$PR_NUM" -R "$REPO" --body "$MARKER
186
+ @codex review the latest commits pushed to this PR."
187
+
188
+ rebase-stale-prs:
189
+ # Bounce 0: main moved -> for each open PR (same-repo only, fork PRs
190
+ # excluded), check mergeStateStatus and either rebase cleanly or ask
191
+ # @claude to resolve conflicts. Catches both PR-merge pushes and
192
+ # direct pushes to main.
193
+ if: github.event_name == 'push' && github.ref == 'refs/heads/main'
194
+ runs-on: ubuntu-latest
195
+ permissions:
196
+ contents: write
197
+ pull-requests: write
198
+ concurrency:
199
+ # Coalesce: if main moves twice while we're still working on the
200
+ # first push, cancel and re-run with the latest SHA. Avoids racing
201
+ # two rebase runs against the same PR.
202
+ group: rebase-stale-prs
203
+ cancel-in-progress: true
204
+ env:
205
+ # Use the PAT for both gh API calls AND the git push. Pushing to a
206
+ # PR branch under GITHUB_TOKEN works but invalidates downstream
207
+ # workflow triggers (recursion guard) — the PAT keeps the @claude
208
+ # comment path working if this rebase later races with a Codex
209
+ # review on the same PR.
210
+ GH_TOKEN: ${{ secrets.AUTOFIX_TRIGGER_PAT }}
211
+ REPO: ${{ github.repository }}
212
+ MAIN_SHA: ${{ github.sha }}
213
+ steps:
214
+ # Graceful skip when the PAT secret isn't configured yet (initial
215
+ # repo setup). Without this guard, actions/checkout fails with
216
+ # "Input required and not supplied: token" on every push to main,
217
+ # turning every merge into a red workflow run during the window
218
+ # between "workflows scaffolded" and "secrets configured."
219
+ - id: have_pat
220
+ name: Check AUTOFIX_TRIGGER_PAT presence
221
+ env:
222
+ PAT: ${{ secrets.AUTOFIX_TRIGGER_PAT }}
223
+ run: |
224
+ if [ -z "$PAT" ]; then
225
+ echo "::warning::AUTOFIX_TRIGGER_PAT not set; skipping rebase. Add the secret per setup-autofix instructions to enable."
226
+ echo "skip=true" >> "$GITHUB_OUTPUT"
227
+ else
228
+ echo "skip=false" >> "$GITHUB_OUTPUT"
229
+ fi
230
+
231
+ - name: Checkout (full history for rebase)
232
+ if: steps.have_pat.outputs.skip != 'true'
233
+ uses: actions/checkout@v4
234
+ with:
235
+ fetch-depth: 0
236
+ token: ${{ secrets.AUTOFIX_TRIGGER_PAT }}
237
+
238
+ - name: Configure git author
239
+ if: steps.have_pat.outputs.skip != 'true'
240
+ run: |
241
+ git config user.email "actions@users.noreply.github.com"
242
+ git config user.name "github-actions[bot]"
243
+
244
+ - name: Rebase BEHIND PRs / flag DIRTY ones
245
+ if: steps.have_pat.outputs.skip != 'true'
246
+ run: |
247
+ set -euo pipefail
248
+
249
+ # mergeStateStatus values that matter:
250
+ # CLEAN - up to date with main (or ahead). skip.
251
+ # BEHIND - mergeable, base moved. clean rebase needed.
252
+ # DIRTY - conflicts. ask @claude.
253
+ # BLOCKED - branch protection or required checks failing. skip.
254
+ # UNSTABLE - mergeable but failing checks. skip — pre-existing.
255
+ # UNKNOWN - GitHub still computing. skip; next push retries.
256
+ #
257
+ # We exclude fork PRs: pushing to a fork branch from this workflow
258
+ # 403s, and posting @claude on a fork is blocked downstream by
259
+ # claude.yml's fork-refusal step anyway.
260
+ PRS_JSON=$(gh pr list --state open -R "$REPO" \
261
+ --json number,headRefName,mergeStateStatus,baseRefName,headRepository \
262
+ --jq "[.[] | select(.baseRefName == \"main\") | select(.headRepository.nameWithOwner == \"$REPO\")]")
263
+
264
+ echo "Open same-repo PRs targeting main:"
265
+ echo "$PRS_JSON" | jq -r '.[] | " #\(.number) [\(.mergeStateStatus)] \(.headRefName)"'
266
+
267
+ # Process each PR. Loop over JSON array via index so we can read
268
+ # only env-style fields and never interpolate untrusted data.
269
+ COUNT=$(echo "$PRS_JSON" | jq 'length')
270
+ for i in $(seq 0 $((COUNT - 1))); do
271
+ PR_NUM=$(echo "$PRS_JSON" | jq -r ".[$i].number")
272
+ BRANCH=$(echo "$PRS_JSON" | jq -r ".[$i].headRefName")
273
+ STATUS=$(echo "$PRS_JSON" | jq -r ".[$i].mergeStateStatus")
274
+
275
+ # Defensive: branch names are user-controlled. Refuse anything
276
+ # that isn't a sane ref. (`refs/heads/<name>` syntax: letters,
277
+ # digits, slashes, dashes, underscores, dots.)
278
+ if ! printf '%s' "$BRANCH" | grep -qE '^[A-Za-z0-9._/-]+$'; then
279
+ echo "::warning::PR #$PR_NUM has unsafe branch name; skipping"
280
+ continue
281
+ fi
282
+
283
+ case "$STATUS" in
284
+ BEHIND)
285
+ echo "PR #$PR_NUM ($BRANCH): clean rebase needed"
286
+ git fetch origin "$BRANCH":"refs/remotes/origin/$BRANCH" --force
287
+ git checkout -B "$BRANCH" "origin/$BRANCH"
288
+ if git rebase origin/main; then
289
+ if git push --force-with-lease origin "$BRANCH"; then
290
+ gh pr comment "$PR_NUM" -R "$REPO" \
291
+ --body "🔁 Auto-rebased on \`main\` (no conflicts) after $MAIN_SHA."
292
+ else
293
+ echo "::warning::Force-push of #$PR_NUM failed (lease lost?). Will retry on next push."
294
+ fi
295
+ else
296
+ # Race: GitHub said BEHIND but the rebase produced
297
+ # conflicts. The next push will see DIRTY and route to
298
+ # the @claude path.
299
+ git rebase --abort
300
+ echo "::warning::Rebase of #$PR_NUM failed despite BEHIND status (likely race with another push)"
301
+ fi
302
+ git checkout main
303
+ ;;
304
+ DIRTY)
305
+ echo "PR #$PR_NUM ($BRANCH): conflicts — asking @claude to rebase"
306
+ # Idempotency: don't re-ask claude for the same main SHA.
307
+ MARKER="<!-- autofix-rebase-claude:$MAIN_SHA -->"
308
+ ALREADY=$(gh pr view "$PR_NUM" -R "$REPO" --json comments \
309
+ --jq "[.comments[] | select(.body | contains(\"$MARKER\"))] | length")
310
+ if [ "$ALREADY" -gt 0 ]; then
311
+ echo " already asked @claude for $MAIN_SHA — skipping"
312
+ continue
313
+ fi
314
+ gh pr comment "$PR_NUM" -R "$REPO" --body "$MARKER
315
+ @claude main has moved and this PR has merge conflicts. Rebase \`$BRANCH\` onto the LATEST \`origin/main\` and resolve the conflicts.
316
+
317
+ CRITICAL — main may move again while you work (resolve + gate take minutes), so a rebase onto the main you first fetched can be stale by the time you push. Immediately before force-pushing, run \`git fetch origin main\` and verify ALL of:
318
+ 1. \`git merge-base --is-ancestor origin/main HEAD\` exits 0 — the branch is on top of CURRENT main. If it fails, main advanced mid-rebase: re-fetch and rebase again.
319
+ 2. \`git log --oneline origin/main..HEAD\` shows ONLY this PR's own commits — no main commits and no merge commit (a merge commit means you merged instead of rebased).
320
+ 3. the local pre-push gate passes.
321
+ Then force-push. AFTER pushing, confirm \`gh pr view $PR_NUM --json mergeStateStatus -q .mergeStateStatus\` is no longer DIRTY/CONFLICTING (wait for it to leave UNKNOWN — GitHub recomputes for a few seconds). Do NOT report the rebase as done until that check passes; if it stays conflicting or main keeps moving, say so in a comment instead of force-fitting a resolution.
322
+
323
+ If the conflicts indicate the new main invalidates this PR's approach, push back via a comment instead of resolving."
324
+ ;;
325
+ CLEAN)
326
+ echo "PR #$PR_NUM ($BRANCH): already current — skipping"
327
+ ;;
328
+ *)
329
+ echo "PR #$PR_NUM ($BRANCH): status $STATUS — leaving alone"
330
+ ;;
331
+ esac
332
+ done
@@ -0,0 +1,61 @@
1
+ name: ci
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ lint-and-test:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+
14
+ # Skip the gates on chore/setup PRs that don't have Python sources yet.
15
+ # Without this, `uv sync --frozen` fails on a clean repo because there's
16
+ # no pyproject.toml/uv.lock to install from. Once the first pyproject.toml
17
+ # lands, the rest of the workflow runs.
18
+ - id: project_check
19
+ name: Detect Python project files
20
+ run: |
21
+ if [ -f pyproject.toml ] && [ -f uv.lock ]; then
22
+ echo "have_project=true" >> "$GITHUB_OUTPUT"
23
+ else
24
+ echo "have_project=false" >> "$GITHUB_OUTPUT"
25
+ echo "::notice::No pyproject.toml + uv.lock yet — skipping lint/test gates."
26
+ fi
27
+
28
+ - name: Install uv
29
+ if: steps.project_check.outputs.have_project == 'true'
30
+ uses: astral-sh/setup-uv@v6
31
+ with:
32
+ enable-cache: true
33
+ # Match pyproject.toml `requires-python`. Pinning here in CI catches
34
+ # any newer-syntax regressions that would break the lower bound.
35
+ # `python-version` here both installs that interpreter AND sets
36
+ # UV_PYTHON so every subsequent `uv sync`/`uv run` uses it.
37
+ python-version: "3.11"
38
+
39
+ - name: Sync deps
40
+ if: steps.project_check.outputs.have_project == 'true'
41
+ # `--frozen` forbids re-resolution: CI installs exactly what's in the
42
+ # committed uv.lock instead of silently picking up newer transitive
43
+ # versions. If uv.lock is missing or stale vs. pyproject.toml, this
44
+ # fails fast — exactly what we want in CI.
45
+ run: uv sync --frozen
46
+
47
+ - name: Lint (ruff check)
48
+ if: steps.project_check.outputs.have_project == 'true'
49
+ run: uv run ruff check .
50
+
51
+ - name: Format check (ruff format)
52
+ if: steps.project_check.outputs.have_project == 'true'
53
+ run: uv run ruff format --check .
54
+
55
+ - name: Type check (pyright)
56
+ if: steps.project_check.outputs.have_project == 'true'
57
+ run: uv run pyright
58
+
59
+ - name: Tests (pytest)
60
+ if: steps.project_check.outputs.have_project == 'true'
61
+ run: uv run pytest -q