mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-23 00:20:45 +00:00
fix(ci): close Cursor automation handoffs and label state machine (#2461)
- Format recovery dispatches triage before clearing invalid-format - Shared CJK-friendly title rules; codex label terminal state machine - Research steps in classify; agent TITLE + PR body for bot PRs - Single @codex review via CODEX_REQUEST_GITHUB_TOKEN (binaricat)
This commit is contained in:
7 files changed
+1032
-145
No files matched your search
@@ -17,7 +17,10 @@ re-comments `@codex review` after the author pushes more commits
|
||||
|
||||
Optional:
|
||||
|
||||
- `TRIAGE_GITHUB_TOKEN` — optional PAT for PR comments / fork re-`@codex`.
|
||||
- `TRIAGE_GITHUB_TOKEN` — bot PAT (netcatty-bot) for opening PRs, labels, triage replies.
|
||||
- `CODEX_REQUEST_GITHUB_TOKEN` — **maintainer PAT (binaricat)** used only for
|
||||
`@codex review` comments so the Codex GitHub connector sees a human identity.
|
||||
Falls back to `TRIAGE_GITHUB_TOKEN` / `GITHUB_TOKEN` if unset.
|
||||
- `SLACK_WEBHOOK_URL` — status pings.
|
||||
|
||||
Fork re-`@codex` uses `pull_request_target` (default-branch checkout only) so
|
||||
@@ -37,9 +40,40 @@ clone.
|
||||
|
||||
Actions → **Cursor automation** → Run workflow → provide an issue or PR number.
|
||||
|
||||
## Format recovery → triage
|
||||
|
||||
`issue-format` and triage share the same title/body rules in
|
||||
`scripts/cursor-automation.cjs` (CJK-friendly `[Bug]`/`[Feature]` summaries).
|
||||
|
||||
When a closed `invalid-format` issue is fixed, `issue-format` reopens it and
|
||||
**dispatches** `cursor-automation` via `workflow_dispatch` (GITHUB_TOKEN cannot
|
||||
silently chain `issues.reopened`, but `workflow_dispatch` is allowed).
|
||||
|
||||
## Bot PR titles and bodies
|
||||
|
||||
Implement agents write:
|
||||
|
||||
- `TITLE:` in `.cursor-runtime/implement-status.txt` → draft PR title
|
||||
(`selectBotPrTitle`, with short `fix(#N): …` fallback)
|
||||
- `.cursor-runtime/implement-pr-body.md` → full maintainer-style PR body
|
||||
(`buildPullRequestBody` prefers this; short template only if missing/thin)
|
||||
|
||||
Bodies always get bot markers + `Fixes #N` + an Automation footer when needed.
|
||||
|
||||
## Codex label handoffs
|
||||
|
||||
Terminal codex_loop outcomes always drop `automation:codex-loop`:
|
||||
|
||||
| Outcome | Labels |
|
||||
|---|---|
|
||||
| clean / mark_ready | `automation:codex-clean` (+ bot-pr), no loop/human |
|
||||
| give_up / verify fail / empty fix | `ready-for-human`, no loop/clean |
|
||||
|
||||
## Safety
|
||||
|
||||
- External / fork PRs: only re-trigger Codex; **no** Cursor CLI review and **no** commits.
|
||||
- Own / bot PR Codex findings: Cursor CLI may push fixes (max rounds).
|
||||
- Automation never publishes changes under `.github/` or automation scripts.
|
||||
- Issue text is sanitized before prompts.
|
||||
- Classify must research unknown product names and issue URLs before needs-info.
|
||||
- Author replies on `needs-info` / `triage:bug-needs-info` re-run classify (same research bar).
|
||||
@@ -14,23 +14,57 @@ Do not modify any repository files. Classification is read-only.
|
||||
|
||||
## Mandatory procedure (do not skip)
|
||||
|
||||
Execute these steps **in order**. Do not draft the final JSON until step 4.
|
||||
Execute these steps **in order**. Do not draft the final JSON until step 5.
|
||||
|
||||
### 1. Extract search terms from the issue
|
||||
|
||||
From the title/body, list concrete tokens to search:
|
||||
From the title/body (and recent comments in `issue.json`), list concrete tokens:
|
||||
|
||||
- English UI/feature words (Keychain, SFTP, port forward, WebDAV, …)
|
||||
- Chinese product words (凭证, 密钥, 身份, 证书, 终端, …)
|
||||
- Error strings, file names, component names if present
|
||||
- Related domain words (SSH, identity, host, vault, …)
|
||||
- **Unknown proper nouns / product names** (tools users run inside the terminal
|
||||
or compare against — e.g. herdr, OpenCode, WindTerm, xftp, tmux clones)
|
||||
- **URLs** in the issue or replies (project homepages, docs, screenshots are
|
||||
secondary — prioritise homepages and GitHub repos)
|
||||
|
||||
### 2. Search the repository (required)
|
||||
### 2. Active research for unknown terms and URLs (required when present)
|
||||
|
||||
If the report names a product/tool that is **not** an obvious Netcatty UI label,
|
||||
or includes an `http(s)://` link, you **must research before needs-info**:
|
||||
|
||||
1. **URLs in the issue/comments:** open or fetch enough to learn what the
|
||||
project is (README summary, one-line description). Note how it relates to
|
||||
SSH/terminal/SFTP/TUI — do not ignore a reporter-provided link.
|
||||
2. **Unknown names without a link:** use available web/search tools (or
|
||||
`gh` / public GitHub search if available) for the exact token + a short
|
||||
context word (`terminal`, `tmux`, `ssh`, `sftp`). Record the project name
|
||||
and role in `code_findings`.
|
||||
3. **Related history:** search this repository's issues/PRs for the same
|
||||
token (`gh issue list --search "…"` when available, or memory of paths/
|
||||
prior bugs). Mention prior issue numbers in `code_findings` when found.
|
||||
4. **Map to Netcatty surfaces:** after research, connect the external tool to
|
||||
local code (terminal mouse mode, scrollback, SFTP transfer, AI sidebar,
|
||||
etc.) and search those areas — not only for a page literally named after
|
||||
the external product.
|
||||
|
||||
**Hard failure:** answering only “仓库里没有叫 X 的页面 / we have no page
|
||||
named X” without steps 1–4 when X or a URL was present. That is not research.
|
||||
|
||||
Only after research, if evidence is still insufficient for a focused fix,
|
||||
use `bug_needs_info` with **specific** missing items (not a generic “what is
|
||||
this tool?” when the reporter already linked it).
|
||||
|
||||
### 3. Search the repository (required)
|
||||
|
||||
Run **at least two** searches in the workspace (shell/`rg`/`grep`/`find` tools
|
||||
are fine). Record **real file paths** you hit (not guessed).
|
||||
|
||||
### 3. Open and read code (required)
|
||||
Include tokens from research (TUI, mouse, SFTP throughput, stream decode, …)
|
||||
when the external product maps to those subsystems.
|
||||
|
||||
### 4. Open and read code (required)
|
||||
|
||||
Open **at least two** source files that search returned (prefer
|
||||
`components/`, `application/`, `domain/`, `electron/`, not docs-only).
|
||||
@@ -42,10 +76,10 @@ Read enough of each file to answer:
|
||||
- **How large is the change surface?** Count roughly: files, subsystems,
|
||||
protocol/data-model impact, cross-cutting settings.
|
||||
|
||||
If search finds nothing relevant, say so in `code_findings` and prefer
|
||||
`bug_needs_info` / `unclear` rather than inventing paths.
|
||||
If search finds nothing relevant after research, say so in `code_findings` and
|
||||
prefer `bug_needs_info` / `unclear` rather than inventing paths.
|
||||
|
||||
### 4. Only then classify and write the reply
|
||||
### 5. Only then classify and write the reply
|
||||
|
||||
## Category definitions (read carefully)
|
||||
|
||||
@@ -241,5 +275,5 @@ Hard requirements:
|
||||
- For `already_available`, `code_findings` names the entry and owning component;
|
||||
`reply` is a usable how-to in plain language.
|
||||
|
||||
If you cannot complete steps 2–3, set category to `bug_needs_info` or `unclear`
|
||||
If you cannot complete steps 2–4, set category to `bug_needs_info` or `unclear`
|
||||
and put the failed search terms in `code_findings` — still do not invent paths.
|
||||
@@ -32,8 +32,58 @@ Implement a **small, focused** fix for this single issue.
|
||||
write a short explanation to `.cursor-runtime/implement-status.txt` starting
|
||||
with `BLOCKED:`.
|
||||
|
||||
When successful, write `.cursor-runtime/implement-status.txt` with:
|
||||
When successful, write **both** of these files:
|
||||
|
||||
### 1. `.cursor-runtime/implement-status.txt`
|
||||
|
||||
```text
|
||||
OK: short summary of what changed
|
||||
OK: short one-line summary of what changed
|
||||
TITLE: concise PR title (imperative, area-scoped; e.g. fix(sftp): raise upload WRITE fanout)
|
||||
```
|
||||
|
||||
- `OK:` is required for a successful implement pass.
|
||||
- `TITLE:` is **required when you made code changes**. The workflow uses it as
|
||||
the GitHub PR title (sanitized). Prefer `fix(area): …` / `feat(area): …`
|
||||
style; do **not** paste the raw issue title. Keep it under ~100 characters.
|
||||
|
||||
### 2. `.cursor-runtime/implement-pr-body.md` (full PR description)
|
||||
|
||||
Write a **maintainer-quality** PR body in Markdown — not a one-liner template.
|
||||
Match the substance of a careful human PR (see real Netcatty PRs), including:
|
||||
|
||||
```markdown
|
||||
## Summary
|
||||
|
||||
- Bullet list of what changed and why (2–6 bullets; concrete, not vague)
|
||||
|
||||
## Why
|
||||
|
||||
Short context: root cause or product reason (optional but preferred for bugs).
|
||||
|
||||
## Changes
|
||||
|
||||
- Key files / behaviors touched (plain language is fine)
|
||||
|
||||
## Testing
|
||||
|
||||
- Commands you ran or would run (e.g. focused `node --test …`, lint)
|
||||
- Manual checks if UI/behavior is involved
|
||||
|
||||
Fixes #<issue-number>
|
||||
```
|
||||
|
||||
Rules for the body:
|
||||
|
||||
- Use the real issue number from `.cursor-runtime/issue.json`.
|
||||
- Do **not** paste the raw unedited issue title as the whole summary.
|
||||
- Do **not** invent benchmarks or test results you did not run; say what is
|
||||
unverified if needed.
|
||||
- No secrets, no credentials, no long code dumps.
|
||||
- Keep roughly 400–2500 characters — enough for a human reviewer to understand
|
||||
the change without opening every file.
|
||||
- Do **not** wrap the file in `<!-- cursor-bot-pr -->` markers; the workflow adds
|
||||
automation markers and an Automation footer if missing.
|
||||
|
||||
If you cannot implement safely, write only
|
||||
`.cursor-runtime/implement-status.txt` with `BLOCKED: reason` and make no edits
|
||||
(no PR body file).
|
||||
@@ -752,6 +752,11 @@ jobs:
|
||||
else
|
||||
echo "OK: automated fix" > .cursor-runtime/implement-status.out.txt
|
||||
fi
|
||||
if [[ -f .cursor-runtime/implement-pr-body.md ]]; then
|
||||
cp .cursor-runtime/implement-pr-body.md .cursor-runtime/implement-pr-body.out.md
|
||||
else
|
||||
: > .cursor-runtime/implement-pr-body.out.md
|
||||
fi
|
||||
echo "should_publish=true" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Scan implement patch for secret leaks
|
||||
@@ -768,6 +773,8 @@ jobs:
|
||||
".cursor-runtime/implement.patch",
|
||||
".cursor-runtime/implement-status.out.txt",
|
||||
".cursor-runtime/implement-status.txt",
|
||||
".cursor-runtime/implement-pr-body.out.md",
|
||||
".cursor-runtime/implement-pr-body.md",
|
||||
],
|
||||
process.env.CURSOR_API_KEY,
|
||||
"implement-publish",
|
||||
@@ -782,6 +789,7 @@ jobs:
|
||||
path: |
|
||||
.cursor-runtime/implement.patch
|
||||
.cursor-runtime/implement-status.out.txt
|
||||
.cursor-runtime/implement-pr-body.out.md
|
||||
if-no-files-found: error
|
||||
|
||||
- name: Mark needs human on implement failure
|
||||
@@ -866,7 +874,8 @@ jobs:
|
||||
git show "FETCH_HEAD:scripts/cursor-automation.cjs" > "$RUNNER_TEMP/cursor-automation.cjs"
|
||||
test -s "$RUNNER_TEMP/cursor-automation.cjs"
|
||||
|
||||
- name: Open draft PR and request Codex review
|
||||
- name: Open draft PR
|
||||
id: openpr
|
||||
uses: actions/github-script@v7
|
||||
env:
|
||||
BRANCH: ${{ needs.implement.outputs.branch }}
|
||||
@@ -876,20 +885,39 @@ jobs:
|
||||
with:
|
||||
# GITHUB_TOKEN cannot create PRs unless the repo enables
|
||||
# "Allow GitHub Actions to create and approve pull requests".
|
||||
# Prefer TRIAGE_GITHUB_TOKEN (PAT) so implement can open draft PRs.
|
||||
# Prefer TRIAGE_GITHUB_TOKEN (PAT) so implement can open draft PRs
|
||||
# as netcatty-bot — keep this separate from @codex identity.
|
||||
github-token: ${{ secrets.TRIAGE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
const auto = require(`${process.env.RUNNER_TEMP}/cursor-automation.cjs`);
|
||||
const fs = require('node:fs');
|
||||
let summary = '';
|
||||
let statusText = '';
|
||||
let agentBody = '';
|
||||
try {
|
||||
summary = fs.readFileSync(`${process.env.GITHUB_WORKSPACE}/patch-in/implement-status.out.txt`, 'utf8');
|
||||
statusText = fs.readFileSync(
|
||||
`${process.env.GITHUB_WORKSPACE}/patch-in/implement-status.out.txt`,
|
||||
'utf8',
|
||||
);
|
||||
} catch {}
|
||||
const title = `fix(#${process.env.ISSUE_NUMBER}): ${process.env.ISSUE_TITLE}`.slice(0, 110);
|
||||
try {
|
||||
agentBody = fs.readFileSync(
|
||||
`${process.env.GITHUB_WORKSPACE}/patch-in/implement-pr-body.out.md`,
|
||||
'utf8',
|
||||
);
|
||||
} catch {}
|
||||
const parsed = auto.parseImplementStatus(statusText);
|
||||
const summary = parsed.summary || statusText;
|
||||
const title = auto.selectBotPrTitle({
|
||||
agentTitle: parsed.title,
|
||||
issueNumber: process.env.ISSUE_NUMBER,
|
||||
issueTitle: process.env.ISSUE_TITLE,
|
||||
maxLength: 110,
|
||||
});
|
||||
const body = auto.buildPullRequestBody({
|
||||
issueNumber: process.env.ISSUE_NUMBER,
|
||||
issueTitle: process.env.ISSUE_TITLE,
|
||||
summary,
|
||||
agentBody,
|
||||
});
|
||||
const { data: pr } = await github.rest.pulls.create({
|
||||
...context.repo,
|
||||
@@ -912,12 +940,33 @@ jobs:
|
||||
clean: false,
|
||||
}),
|
||||
});
|
||||
// Expose PR number for a separate @codex step that may use a
|
||||
// human PAT (CODEX_REQUEST_GITHUB_TOKEN) without changing PR author.
|
||||
core.setOutput('pull_number', String(pr.number));
|
||||
core.setOutput('head_sha', pr.head.sha);
|
||||
core.info(`Opened draft PR ${pr.html_url}`);
|
||||
|
||||
- name: Request Codex review on implement PR
|
||||
if: steps.openpr.outputs.pull_number != ''
|
||||
uses: actions/github-script@v7
|
||||
env:
|
||||
PULL_NUMBER: ${{ steps.openpr.outputs.pull_number }}
|
||||
HEAD_SHA: ${{ steps.openpr.outputs.head_sha }}
|
||||
with:
|
||||
# Prefer maintainer PAT so Codex connector sees a human identity.
|
||||
github-token: ${{ secrets.CODEX_REQUEST_GITHUB_TOKEN || secrets.TRIAGE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
const auto = require(`${process.env.RUNNER_TEMP}/cursor-automation.cjs`);
|
||||
const pull_number = Number(process.env.PULL_NUMBER);
|
||||
const headSha = process.env.HEAD_SHA || '';
|
||||
await github.rest.issues.createComment({
|
||||
...context.repo,
|
||||
issue_number: pr.number,
|
||||
body: auto.buildCodexReviewRequestComment(1, pr.head.sha),
|
||||
issue_number: pull_number,
|
||||
body: auto.buildCodexReviewRequestComment(1, headSha, {
|
||||
includeExternalMarker: true,
|
||||
}),
|
||||
});
|
||||
core.info(`Opened draft PR ${pr.html_url}`);
|
||||
core.info(`Requested @codex review on PR #${pull_number}`);
|
||||
|
||||
codex_loop:
|
||||
name: Codex review loop
|
||||
@@ -1176,7 +1225,8 @@ jobs:
|
||||
if: steps.codex.outputs.action == 'request_review'
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
github-token: ${{ secrets.TRIAGE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
|
||||
# @codex must come from a human identity connected to Codex (binaricat PAT).
|
||||
github-token: ${{ secrets.CODEX_REQUEST_GITHUB_TOKEN || secrets.TRIAGE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
const auto = require(`${process.env.RUNNER_TEMP}/cursor-automation.cjs`);
|
||||
const pull_number = Number(process.env.PULL_NUMBER);
|
||||
@@ -1243,7 +1293,9 @@ jobs:
|
||||
await github.rest.issues.createComment({
|
||||
...context.repo,
|
||||
issue_number: pull_number,
|
||||
body: auto.buildCodexReviewRequestComment(1, pr.head.sha),
|
||||
body: auto.buildCodexReviewRequestComment(1, pr.head.sha, {
|
||||
includeExternalMarker: true,
|
||||
}),
|
||||
});
|
||||
|
||||
- name: Mark PR ready after clean Codex
|
||||
@@ -1280,14 +1332,14 @@ jobs:
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
# Tolerate already-ready / closed / permission noise.
|
||||
# Tolerate already-ready / closed / permission noise. Still apply labels below.
|
||||
ready_out="$(gh pr ready "$PULL_NUMBER" --repo "$GITHUB_REPOSITORY" 2>&1)" || {
|
||||
if echo "$ready_out" | grep -qiE 'already ready|not a draft|is not a draft|is closed|closed\.|only draft'; then
|
||||
echo "PR not convertible to ready (ok to skip): $ready_out"
|
||||
exit 0
|
||||
echo "PR not convertible to ready (ok to continue labeling): $ready_out"
|
||||
else
|
||||
echo "$ready_out" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "$ready_out" >&2
|
||||
exit 1
|
||||
}
|
||||
# Re-check head after gh pr ready (another push could race).
|
||||
live_head2="$(gh pr view "$PULL_NUMBER" --repo "$GITHUB_REPOSITORY" --json headRefOid -q .headRefOid)"
|
||||
@@ -1296,11 +1348,39 @@ jobs:
|
||||
gh pr ready "$PULL_NUMBER" --repo "$GITHUB_REPOSITORY" --undo 2>/dev/null || true
|
||||
exit 0
|
||||
fi
|
||||
gh pr edit "$PULL_NUMBER" --repo "$GITHUB_REPOSITORY" \
|
||||
--add-label "automation:codex-clean" \
|
||||
--add-label "automation:bot-pr" || true
|
||||
gh pr edit "$PULL_NUMBER" --repo "$GITHUB_REPOSITORY" \
|
||||
--remove-label "automation:codex-loop" || true
|
||||
# Terminal label transition: drop codex-loop, add codex-clean (pure helper).
|
||||
node -e '
|
||||
const { execSync } = require("node:child_process");
|
||||
const auto = require(process.env.RUNNER_TEMP + "/cursor-automation.cjs");
|
||||
const pull = process.env.PULL_NUMBER;
|
||||
const repo = process.env.GITHUB_REPOSITORY;
|
||||
const raw = execSync(
|
||||
`gh pr view ${pull} --repo ${repo} --json labels -q "[.labels[].name]"`,
|
||||
{ encoding: "utf8" },
|
||||
);
|
||||
const existing = JSON.parse(raw);
|
||||
const next = auto.nextCodexTerminalLabels(existing, "mark_ready");
|
||||
const remove = existing.filter((l) => !next.includes(l));
|
||||
const add = next.filter((l) => !existing.includes(l));
|
||||
for (const name of remove) {
|
||||
try {
|
||||
execSync(
|
||||
`gh pr edit ${pull} --repo ${repo} --remove-label ${JSON.stringify(name)}`,
|
||||
{ stdio: "inherit" },
|
||||
);
|
||||
} catch (err) {
|
||||
console.error("Failed to remove label", name, err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
if (add.length) {
|
||||
const args = add.map((n) => `--add-label ${JSON.stringify(n)}`).join(" ");
|
||||
execSync(`gh pr edit ${pull} --repo ${repo} ${args}`, {
|
||||
stdio: "inherit",
|
||||
});
|
||||
}
|
||||
console.log("mark_ready labels:", next.join(", "));
|
||||
'
|
||||
# Confirm draft=false before claiming success.
|
||||
draft="$(gh pr view "$PULL_NUMBER" --repo "$GITHUB_REPOSITORY" --json isDraft -q .isDraft)"
|
||||
if [[ "$draft" == "true" ]]; then
|
||||
@@ -1326,10 +1406,11 @@ jobs:
|
||||
script: |
|
||||
const auto = require(`${process.env.RUNNER_TEMP}/cursor-automation.cjs`);
|
||||
const pull_number = Number(process.env.PULL_NUMBER);
|
||||
await github.rest.issues.addLabels({
|
||||
...context.repo,
|
||||
issue_number: pull_number,
|
||||
labels: ['ready-for-human'],
|
||||
await auto.applyCodexTerminalLabels({
|
||||
github,
|
||||
context,
|
||||
pullNumber: pull_number,
|
||||
terminal: 'give_up',
|
||||
});
|
||||
const reason = process.env.REASON || 'max_rounds';
|
||||
const message =
|
||||
@@ -1626,7 +1707,10 @@ jobs:
|
||||
- name: Mark needs human when no fix produced
|
||||
if: steps.codex.outputs.action == 'fix' && steps.fixpatch.outputs.empty == 'true'
|
||||
uses: actions/github-script@v7
|
||||
env:
|
||||
PULL_NUMBER: ${{ needs.route.outputs.pull_number }}
|
||||
with:
|
||||
github-token: ${{ secrets.TRIAGE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
const auto = require(`${process.env.RUNNER_TEMP}/cursor-automation.cjs`);
|
||||
const pull_number = Number(process.env.PULL_NUMBER);
|
||||
@@ -1640,13 +1724,12 @@ jobs:
|
||||
'Automatic fix did not produce additional code changes for the latest Codex findings. Marking for human review.',
|
||||
].join('\n'),
|
||||
});
|
||||
await github.rest.issues.addLabels({
|
||||
...context.repo,
|
||||
issue_number: pull_number,
|
||||
labels: ['ready-for-human'],
|
||||
await auto.applyCodexTerminalLabels({
|
||||
github,
|
||||
context,
|
||||
pullNumber: pull_number,
|
||||
terminal: 'empty_fix',
|
||||
});
|
||||
env:
|
||||
PULL_NUMBER: ${{ needs.route.outputs.pull_number }}
|
||||
|
||||
- name: Mark needs human on fix failure
|
||||
if: failure() && steps.codex.outputs.action == 'fix'
|
||||
@@ -1654,6 +1737,7 @@ jobs:
|
||||
env:
|
||||
PULL_NUMBER: ${{ needs.route.outputs.pull_number }}
|
||||
with:
|
||||
github-token: ${{ secrets.TRIAGE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
const fs = require('node:fs');
|
||||
const helper = fs.existsSync(`${process.env.RUNNER_TEMP}/cursor-automation.cjs`)
|
||||
@@ -1671,10 +1755,11 @@ jobs:
|
||||
'Automatic Codex fix did not finish cleanly (agent, protected paths, or verification failed). Marking for human review.',
|
||||
].join('\n'),
|
||||
});
|
||||
await github.rest.issues.addLabels({
|
||||
...context.repo,
|
||||
issue_number: pull_number,
|
||||
labels: ['ready-for-human'],
|
||||
await auto.applyCodexTerminalLabels({
|
||||
github,
|
||||
context,
|
||||
pullNumber: pull_number,
|
||||
terminal: 'verify_fail',
|
||||
});
|
||||
|
||||
publish_codex_fix:
|
||||
@@ -1736,6 +1821,7 @@ jobs:
|
||||
- name: Re-request Codex after fix push
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
github-token: ${{ secrets.CODEX_REQUEST_GITHUB_TOKEN || secrets.TRIAGE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
const auto = require(`${process.env.RUNNER_TEMP}/cursor-automation.cjs`);
|
||||
const pull_number = Number(process.env.PULL_NUMBER);
|
||||
@@ -1747,7 +1833,9 @@ jobs:
|
||||
await github.rest.issues.createComment({
|
||||
...context.repo,
|
||||
issue_number: pull_number,
|
||||
body: auto.buildCodexReviewRequestComment(nextRound, pr.head.sha),
|
||||
body: auto.buildCodexReviewRequestComment(nextRound, pr.head.sha, {
|
||||
includeExternalMarker: true,
|
||||
}),
|
||||
});
|
||||
|
||||
own_rerequest_codex:
|
||||
@@ -1797,7 +1885,8 @@ jobs:
|
||||
- name: Comment @codex review after human push
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
github-token: ${{ secrets.TRIAGE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
|
||||
# Human-connected Codex identity (binaricat PAT); not netcatty-bot.
|
||||
github-token: ${{ secrets.CODEX_REQUEST_GITHUB_TOKEN || secrets.TRIAGE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
const auto = require(`${process.env.GITHUB_WORKSPACE}/scripts/cursor-automation.cjs`);
|
||||
const pull_number = Number(process.env.PULL_NUMBER);
|
||||
@@ -1887,13 +1976,13 @@ jobs:
|
||||
);
|
||||
}
|
||||
}
|
||||
// Exactly one @codex review mention; plant both marker families for dedupe.
|
||||
await github.rest.issues.createComment({
|
||||
...context.repo,
|
||||
issue_number: pull_number,
|
||||
body: [
|
||||
auto.buildCodexReviewRequestComment(round, pr.head.sha),
|
||||
auto.buildExternalCodexRerequestComment(pr.head.sha),
|
||||
].join('\n'),
|
||||
body: auto.buildCodexReviewRequestComment(round, pr.head.sha, {
|
||||
includeExternalMarker: true,
|
||||
}),
|
||||
});
|
||||
|
||||
external_rerequest_codex:
|
||||
@@ -1942,8 +2031,8 @@ jobs:
|
||||
- name: Comment @codex review after contributor push
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
# pull_request_target provides write GITHUB_TOKEN for forks; optional PAT override.
|
||||
github-token: ${{ secrets.TRIAGE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
|
||||
# Prefer human Codex-connected PAT; fall back for forks/write token.
|
||||
github-token: ${{ secrets.CODEX_REQUEST_GITHUB_TOKEN || secrets.TRIAGE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
const auto = require(`${process.env.GITHUB_WORKSPACE}/scripts/cursor-automation.cjs`);
|
||||
// External job checks out default branch only; tree is trusted.
|
||||
@@ -2032,7 +2121,8 @@ jobs:
|
||||
- name: Poll open automation PRs
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
github-token: ${{ secrets.TRIAGE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
|
||||
# Poll may re-@codex; use human-connected token for those comments.
|
||||
github-token: ${{ secrets.CODEX_REQUEST_GITHUB_TOKEN || secrets.TRIAGE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
const auto = require(`${process.env.GITHUB_WORKSPACE}/scripts/cursor-automation.cjs`);
|
||||
const ownActors = process.env.OWN_ACTORS;
|
||||
@@ -2272,20 +2362,12 @@ jobs:
|
||||
);
|
||||
continue;
|
||||
}
|
||||
await github.rest.issues.addLabels({
|
||||
...context.repo,
|
||||
issue_number: pr.number,
|
||||
labels: ['automation:codex-clean'],
|
||||
await auto.applyCodexTerminalLabels({
|
||||
github,
|
||||
context,
|
||||
pullNumber: pr.number,
|
||||
terminal: 'mark_ready',
|
||||
});
|
||||
try {
|
||||
await github.rest.issues.removeLabel({
|
||||
...context.repo,
|
||||
issue_number: pr.number,
|
||||
name: 'automation:codex-loop',
|
||||
});
|
||||
} catch {
|
||||
// label may already be absent
|
||||
}
|
||||
core.info(`PR #${pr.number}: marked ready via clean reaction`);
|
||||
handled += 1;
|
||||
} catch (err) {
|
||||
@@ -2321,6 +2403,7 @@ jobs:
|
||||
body: auto.buildCodexReviewRequestComment(
|
||||
round,
|
||||
pr.head.sha,
|
||||
{ includeExternalMarker: true },
|
||||
),
|
||||
});
|
||||
core.info(
|
||||
@@ -2338,7 +2421,9 @@ jobs:
|
||||
await github.rest.issues.createComment({
|
||||
...context.repo,
|
||||
issue_number: pr.number,
|
||||
body: auto.buildCodexReviewRequestComment(round, pr.head.sha),
|
||||
body: auto.buildCodexReviewRequestComment(round, pr.head.sha, {
|
||||
includeExternalMarker: true,
|
||||
}),
|
||||
});
|
||||
core.info(`PR #${pr.number}: re-requested Codex after timeout`);
|
||||
handled += 1;
|
||||
|
||||
@@ -5,7 +5,11 @@ on:
|
||||
types: [opened, edited]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
issues: write
|
||||
# workflow_dispatch is allowed from GITHUB_TOKEN (unlike issues.reopened)
|
||||
# so format recovery can start triage without a human re-dispatch.
|
||||
actions: write
|
||||
|
||||
jobs:
|
||||
validate:
|
||||
@@ -15,74 +19,83 @@ jobs:
|
||||
github.event.issue.user.type != 'Bot' &&
|
||||
!contains(github.event.issue.labels.*.name, 'format-exempt')
|
||||
steps:
|
||||
- name: Checkout format helpers
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
sparse-checkout: |
|
||||
scripts/cursor-automation.cjs
|
||||
sparse-checkout-cone-mode: false
|
||||
|
||||
- name: Validate title and body
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const auto = require(`${process.env.GITHUB_WORKSPACE}/scripts/cursor-automation.cjs`);
|
||||
const issue = context.payload.issue;
|
||||
const title = issue.title.trim();
|
||||
const body = (issue.body || '').trim();
|
||||
const errors = [];
|
||||
|
||||
const modernTitle = /^\[(Bug|Feature)\] .{8,}/.test(title);
|
||||
const legacyAppTitle = /^Bug:\s*.{5,}/i.test(title);
|
||||
if (!modernTitle && !legacyAppTitle) {
|
||||
errors.push(
|
||||
'Title must start with `[Bug]` or `[Feature]` followed by a short summary (at least 8 characters after the prefix). Legacy app links using `Bug: ...` are also accepted. Example: `[Bug] SFTP upload fails on Windows`'
|
||||
);
|
||||
}
|
||||
|
||||
if (body.length < 120) {
|
||||
errors.push(
|
||||
'Body is too short. Please use the Bug Report or Feature Request template and fill in all required fields.'
|
||||
);
|
||||
}
|
||||
|
||||
const templateMarkers = [
|
||||
'Steps to reproduce',
|
||||
'Expected behavior',
|
||||
'Actual behavior',
|
||||
'Describe the problem',
|
||||
'Problem / pain point',
|
||||
'Proposed solution',
|
||||
'Operating system',
|
||||
];
|
||||
const hasTemplateStructure = templateMarkers.some((marker) =>
|
||||
body.includes(marker)
|
||||
);
|
||||
if (!hasTemplateStructure) {
|
||||
errors.push(
|
||||
'Body does not look like it came from an issue template. Choose **Bug Report** or **Feature Request** when opening an issue.'
|
||||
);
|
||||
}
|
||||
|
||||
const errors = auto.getIssueFormatErrors(issue);
|
||||
const labels = new Set(
|
||||
(issue.labels || []).map((label) =>
|
||||
typeof label === 'string' ? label : label.name
|
||||
)
|
||||
);
|
||||
const formatOk = errors.length === 0;
|
||||
const recovery = auto.shouldRecoverIssueFormat({
|
||||
state: issue.state,
|
||||
labels: [...labels],
|
||||
formatOk,
|
||||
});
|
||||
|
||||
if (formatOk) {
|
||||
if (recovery.recover) {
|
||||
// Dispatch FIRST while invalid-format is still present and the
|
||||
// issue may still be closed. workflow_dispatch sets manual=true
|
||||
// so classify is eligible even with the label. Only after a
|
||||
// successful dispatch do we reopen / clear the label — so a
|
||||
// failed dispatch leaves a recoverable state (Codex P2).
|
||||
const ref =
|
||||
context.payload.repository?.default_branch || 'main';
|
||||
try {
|
||||
await github.rest.actions.createWorkflowDispatch({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
workflow_id: 'cursor-automation.yml',
|
||||
ref,
|
||||
inputs: {
|
||||
issue_number: String(issue.number),
|
||||
},
|
||||
});
|
||||
core.info(
|
||||
`Dispatched cursor-automation for recovered issue #${issue.number}`,
|
||||
);
|
||||
} catch (err) {
|
||||
core.setFailed(
|
||||
`Triage dispatch failed after format recovery; leaving invalid-format in place for retry: ${err.message}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (errors.length === 0) {
|
||||
if (
|
||||
issue.state === 'closed' &&
|
||||
labels.has('invalid-format')
|
||||
) {
|
||||
labels.delete('invalid-format');
|
||||
await github.rest.issues.update({
|
||||
const update = {
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: issue.number,
|
||||
state: 'open',
|
||||
labels: [...labels],
|
||||
});
|
||||
};
|
||||
if (recovery.reopen) {
|
||||
update.state = 'open';
|
||||
}
|
||||
await github.rest.issues.update(update);
|
||||
await github.rest.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: issue.number,
|
||||
body: '<!-- issue-format-bot --> Format looks good now. Reopening this issue.',
|
||||
body: recovery.reopen
|
||||
? '<!-- issue-format-bot --> Format looks good now. Reopening this issue and starting triage.'
|
||||
: '<!-- issue-format-bot --> Format looks good now. Starting triage.',
|
||||
});
|
||||
} else {
|
||||
core.info('Issue format OK');
|
||||
}
|
||||
core.info('Issue format OK');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user