From 2840463b3d2eb89113df669e0b5822fdbf3f548b Mon Sep 17 00:00:00 2001 From: bincxz <16399091+binaricat@users.noreply.github.com> Date: Sun, 26 Jul 2026 21:43:37 +0800 Subject: [PATCH] fix(automation): gate ready-state follow-ups and research web denials Only automation bot PRs re-check source-issue pending comments before mark-ready, so maintainer Fixes-only PRs are not stuck draft. Write WebSearch/WebFetch denials after the isolated research pass so classify and follow-up research can still call those tools. --- .github/cursor/README.md | 14 ++- .github/workflows/cursor-automation.yml | 60 ++++++++--- scripts/cursor-automation.cjs | 23 ++++- scripts/cursor-automation.test.cjs | 132 ++++++++++++++++++++++++ 4 files changed, 208 insertions(+), 21 deletions(-) diff --git a/.github/cursor/README.md b/.github/cursor/README.md index d8ad7cbb6..82d1a3dcf 100644 --- a/.github/cursor/README.md +++ b/.github/cursor/README.md @@ -88,6 +88,10 @@ Terminal codex_loop outcomes always drop `automation:codex-loop`: source-linked notes are passed to classify, implement, or follow-up agents. The workflow also verifies the CLI stream contains a real WebSearch/WebFetch tool event; an answer that merely prints a URL is rejected. +- User-level WebSearch/WebFetch denials are written only after that research + pass (or in implement/fix jobs that never research). Pre-research sandbox + setup enables the command sandbox without denying web tools, so research is + not blocked by the later classify/follow-up denylist. - WebSearch and WebFetch are explicitly denied again for classify, implement, follow-up, and fix agents. Those stages cannot silently perform another web request outside the isolated research pass. @@ -116,7 +120,9 @@ compares the new information with the current diff: - contradiction, larger scope, unsafe update, or no active PR needing work: acknowledge the reporter and hand the issue/PR to a maintainer. -Every clean-to-ready transition re-checks the source issue. A PR cannot become -ready while an eligible author/maintainer follow-up is still unprocessed. Patch -publication also verifies the PR head has not moved, so a follow-up update never -overwrites a concurrent maintainer or automation push. +Every clean-to-ready transition re-checks the source issue for automation bot +PRs only (`automation:bot-pr` / bot PR marker). A maintainer PR that merely +says `Fixes #N` is not kept draft solely because issue comments lack automation +processed markers. Patch publication also verifies the PR head has not moved, +so a follow-up update never overwrites a concurrent maintainer or automation +push. diff --git a/.github/workflows/cursor-automation.yml b/.github/workflows/cursor-automation.yml index 74dc75a11..307af1f9d 100644 --- a/.github/workflows/cursor-automation.yml +++ b/.github/workflows/cursor-automation.yml @@ -521,19 +521,13 @@ jobs: mkdir -p .cursor-runtime agent sandbox reset agent sandbox enable + # Enable sandbox + block shell network only. Do NOT deny built-in + # web tools yet — the isolated research pass must still call them. node -e ' const fs = require("node:fs"); const p = process.env.HOME + "/.cursor/cli-config.json"; const c = JSON.parse(fs.readFileSync(p, "utf8")); c.sandbox = { ...(c.sandbox || {}), mode: "enabled", networkAccess: "user_config" }; - c.permissions = { - ...(c.permissions || {}), - deny: [...new Set([ - ...(c.permissions?.deny || []), - "WebSearch(*)", - "WebFetch(*)", - ])], - }; fs.writeFileSync(p, JSON.stringify(c, null, 2) + "\n"); ' agent sandbox run --sandbox bash -c 'touch .cursor-runtime/sandbox-check' @@ -626,6 +620,26 @@ jobs: if-no-files-found: error overwrite: true + - name: Deny WebSearch and WebFetch after classification research + if: steps.prepare.outputs.should_run == 'true' + run: | + # Research has finished. Block web tools for classify and later agents + # that share this HOME / user-level cli-config. + node -e ' + const fs = require("node:fs"); + const p = process.env.HOME + "/.cursor/cli-config.json"; + const c = JSON.parse(fs.readFileSync(p, "utf8")); + c.permissions = { + ...(c.permissions || {}), + deny: [...new Set([ + ...(c.permissions?.deny || []), + "WebSearch(*)", + "WebFetch(*)", + ])], + }; + fs.writeFileSync(p, JSON.stringify(c, null, 2) + "\n"); + ' + - name: Classify with Cursor CLI if: steps.prepare.outputs.should_run == 'true' env: @@ -1087,19 +1101,13 @@ jobs: mkdir -p .cursor-runtime agent sandbox reset agent sandbox enable + # Enable sandbox + block shell network only. Do NOT deny built-in + # web tools yet — the isolated research pass must still call them. node -e ' const fs = require("node:fs"); const p = process.env.HOME + "/.cursor/cli-config.json"; const c = JSON.parse(fs.readFileSync(p, "utf8")); c.sandbox = { ...(c.sandbox || {}), mode: "enabled", networkAccess: "user_config" }; - c.permissions = { - ...(c.permissions || {}), - deny: [...new Set([ - ...(c.permissions?.deny || []), - "WebSearch(*)", - "WebFetch(*)", - ])], - }; fs.writeFileSync(p, JSON.stringify(c, null, 2) + "\n"); ' agent sandbox run --sandbox bash -c 'touch .cursor-runtime/followup-sandbox-check' @@ -1181,6 +1189,26 @@ jobs: ); ' + - name: Deny WebSearch and WebFetch after follow-up research + if: steps.prepare.outputs.should_run == 'true' + run: | + # Research has finished. Block web tools for the follow-up agent and + # any later steps that share this HOME / user-level cli-config. + node -e ' + const fs = require("node:fs"); + const p = process.env.HOME + "/.cursor/cli-config.json"; + const c = JSON.parse(fs.readFileSync(p, "utf8")); + c.permissions = { + ...(c.permissions || {}), + deny: [...new Set([ + ...(c.permissions?.deny || []), + "WebSearch(*)", + "WebFetch(*)", + ])], + }; + fs.writeFileSync(p, JSON.stringify(c, null, 2) + "\n"); + ' + - name: Review follow-up with Cursor CLI if: steps.prepare.outputs.should_run == 'true' env: diff --git a/scripts/cursor-automation.cjs b/scripts/cursor-automation.cjs index 52f8266ae..fa784eaf5 100644 --- a/scripts/cursor-automation.cjs +++ b/scripts/cursor-automation.cjs @@ -2642,6 +2642,22 @@ async function findOpenBotPrForIssue({ github, context, issueNumber }) { return pulls.find((pull) => isBotPrForIssue(pull, issueNumber)) || null; } +/** + * Source-issue follow-up readiness is only meaningful for automation bot PRs. + * Maintainer/own-actor PRs that merely say `Fixes #N` must not stay draft + * forever because issue comments lack automation processed markers. + */ +function shouldGatePullOnSourceIssueFollowups(pull) { + if (!pull) return false; + if (!extractSourceIssueNumber(pull)) return false; + const body = String(pull.body || ''); + if (isBotPrMarker(body)) return true; + return (pull.labels || []).some((label) => { + const name = typeof label === 'string' ? label : label?.name; + return name === BOT_PR_LABEL; + }); +} + async function getPendingIssueFollowupsForPull({ github, context, @@ -2649,7 +2665,10 @@ async function getPendingIssueFollowupsForPull({ botLogins = ['netcatty-bot', 'github-actions[bot]'], }) { const issueNumber = extractSourceIssueNumber(pull); - if (!issueNumber) return { issue: null, pending: [] }; + if (!issueNumber) return { issue: null, pending: [], gated: false }; + if (!shouldGatePullOnSourceIssueFollowups(pull)) { + return { issue: null, pending: [], gated: false }; + } const { data: issue } = await github.rest.issues.get({ ...context.repo, issue_number: issueNumber, @@ -2662,6 +2681,7 @@ async function getPendingIssueFollowupsForPull({ const commentList = Array.isArray(comments) ? comments.filter(Boolean) : []; return { issue, + gated: true, pending: findPendingIssueFollowups({ comments: commentList, issueAuthorLogin: issue.user?.login, @@ -3057,6 +3077,7 @@ module.exports = { markNeedsHuman, isBotPrForIssue, findOpenBotPrForIssue, + shouldGatePullOnSourceIssueFollowups, getPendingIssueFollowupsForPull, ensurePullRequestDraft, ensurePullRequestReady, diff --git a/scripts/cursor-automation.test.cjs b/scripts/cursor-automation.test.cjs index deeada5cf..99f981664 100644 --- a/scripts/cursor-automation.test.cjs +++ b/scripts/cursor-automation.test.cjs @@ -742,6 +742,8 @@ test('getPendingIssueFollowupsForPull protects ready state with live issue comme number: 77, body: `${auto.BOT_PR_MARKER}\n\nFixes #42`, created_at: '2026-07-24T10:00:00Z', + labels: [{ name: 'automation:bot-pr' }], + user: { login: 'netcatty-bot' }, }; const github = { rest: { @@ -776,10 +778,82 @@ test('getPendingIssueFollowupsForPull protects ready state with live issue comme context: { repo: { owner: 'binaricat', repo: 'Netcatty' } }, pull, }); + assert.equal(result.gated, true); assert.equal(result.issue.number, 42); assert.deepEqual(result.pending.map((comment) => comment.id), [2]); }); +test('shouldGatePullOnSourceIssueFollowups is limited to automation bot PRs', () => { + assert.equal( + auto.shouldGatePullOnSourceIssueFollowups({ + body: `${auto.BOT_PR_MARKER}\n\nFixes #42`, + labels: [{ name: 'automation:bot-pr' }], + user: { login: 'netcatty-bot' }, + }), + true, + ); + assert.equal( + auto.shouldGatePullOnSourceIssueFollowups({ + body: 'Maintainer fix\n\nFixes #42', + labels: [{ name: 'bug' }], + user: { login: 'binaricat' }, + }), + false, + ); + assert.equal( + auto.shouldGatePullOnSourceIssueFollowups({ + body: 'No closing keyword or automation marker', + labels: [{ name: 'automation:bot-pr' }], + user: { login: 'netcatty-bot' }, + }), + false, + ); +}); + +test('getPendingIssueFollowupsForPull does not block maintainer Fixes-only PRs', async () => { + let issuesFetched = 0; + const pull = { + number: 88, + body: 'Hand-written fix for the reporter.\n\nFixes #42', + created_at: '2026-07-24T10:00:00Z', + labels: [{ name: 'bug' }], + user: { login: 'binaricat' }, + head: { ref: 'fix/issue-42-manual', repo: { full_name: 'binaricat/Netcatty' } }, + base: { repo: { full_name: 'binaricat/Netcatty' } }, + }; + const github = { + rest: { + issues: { + get: async () => { + issuesFetched += 1; + return { data: { number: 42, user: { login: 'alice' } } }; + }, + listComments: Symbol('listComments'), + }, + }, + paginate: async () => { + issuesFetched += 1; + return [ + { + id: 99, + user: { login: 'alice', type: 'User' }, + body: 'still broken after your PR', + created_at: '2026-07-24T12:00:00Z', + }, + ]; + }, + }; + const result = await auto.getPendingIssueFollowupsForPull({ + github, + context: { repo: { owner: 'binaricat', repo: 'Netcatty' } }, + pull, + }); + assert.equal(result.gated, false); + assert.equal(result.issue, null); + assert.deepEqual(result.pending, []); + assert.equal(issuesFetched, 0); +}); + test('prepareIssueFollowupContext uses the triggering comment when no PR exists', async () => { const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'cursor-followup-')); const outputPath = path.join(dir, 'followup.json'); @@ -1891,6 +1965,9 @@ test('workflow confines forced WebSearch to isolated read-only research passes', assert.match(run, /Read\(input\.json\)/); assert.match(run, /process\.env\.HOME/); assert.match(run, /process\.env\.GITHUB_WORKSPACE/); + // Research itself must not write the non-research web-tool denylist. + assert.doesNotMatch(run, /"WebSearch\(\*\)"/); + assert.doesNotMatch(run, /"WebFetch\(\*\)"/); } const nonResearchAgentLines = workflow @@ -1907,6 +1984,61 @@ test('workflow confines forced WebSearch to isolated read-only research passes', assert.match(workflow, /name: issue-research-\$\{\{ github\.run_id \}\}[\s\S]*?overwrite: true/); }); +test('workflow denies WebSearch only after isolated research, not before it', () => { + const workflow = fs.readFileSync( + path.join(__dirname, '..', '.github', 'workflows', 'cursor-automation.yml'), + 'utf8', + ); + + const classifyJob = workflow.match( + /\n classify:\n[\s\S]*?(?=\n [a-zA-Z0-9_]+:\n)/, + )?.[0] || ''; + const followupJob = workflow.match( + /\n issue_followup:\n[\s\S]*?(?=\n [a-zA-Z0-9_]+:\n)/, + )?.[0] || ''; + assert.ok(classifyJob.includes('Research external context for classification')); + assert.ok(followupJob.includes('Research external context for follow-up')); + + for (const [label, job] of [ + ['classify', classifyJob], + ['issue_followup', followupJob], + ]) { + const researchIdx = job.indexOf('- name: Research external context'); + assert.ok(researchIdx > 0, `${label} research step missing`); + const preResearch = job.slice(0, researchIdx); + assert.doesNotMatch( + preResearch, + /"WebSearch\(\*\)"/, + `${label} must not deny WebSearch before research`, + ); + assert.doesNotMatch( + preResearch, + /"WebFetch\(\*\)"/, + `${label} must not deny WebFetch before research`, + ); + + const postResearch = job.slice(researchIdx); + const denyStep = postResearch.match( + /- name: Deny WebSearch and WebFetch after[\s\S]*?(?=\n\s{6}- name:)/, + )?.[0] || ''; + assert.match(denyStep, /"WebSearch\(\*\)"/, `${label} post-research deny missing WebSearch`); + assert.match(denyStep, /"WebFetch\(\*\)"/, `${label} post-research deny missing WebFetch`); + + const denyIdx = postResearch.indexOf('- name: Deny WebSearch and WebFetch after'); + const agentIdx = postResearch.search( + /- name: (Classify with Cursor CLI|Review follow-up with Cursor CLI)/, + ); + assert.ok(denyIdx >= 0 && agentIdx > denyIdx, `${label} deny must precede agent`); + } + + // Jobs without a research pass still deny web tools in their sandbox step. + const implementJob = workflow.match( + /\n implement:\n[\s\S]*?(?=\n [a-zA-Z0-9_]+:\n)/, + )?.[0] || ''; + assert.match(implementJob, /Require the Cursor command sandbox for implementation[\s\S]*?"WebSearch\(\*\)"/); + assert.doesNotMatch(implementJob, /Research external context/); +}); + test('initial issue failures still label and notify without a trigger comment id', () => { const workflow = fs.readFileSync( path.join(__dirname, '..', '.github', 'workflows', 'cursor-automation.yml'),