Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
Issue and PR reset bot: intake check, /reopen, 5-day sweep, with node tests
Niko1221eac694ae4c74
diff --git a/.github/scripts/item-check.js b/.github/scripts/item-check.jsnew file mode 100644index 000000000..b07b6350c--- /dev/null+++ b/.github/scripts/item-check.js@@ -0,0 +1,218 @@+'use strict';+// Format check for issues and pull requests (see CONTRIBUTING.md and .github/ISSUE_TEMPLATE/*.yml).+// Pure functions only: no network, no filesystem. Used by intake.yml and reopen.yml through reset-bot.js.++const AREAS = ['Engine', 'GUI', 'TUI', 'Benchmark', 'Docs', 'Other'];+const TITLE_RE = new RegExp('^\\[(' + AREAS.join('|') + ')\\] \\S');+const NO_ANSWER = /^(_no response_|none|n\/a|na|-|todo|tbd|\.|\?)$/i;+const NOT_RUN_LABELS = /^\*\*(passed|failed|not run)\s*:?\*\*\s*:?/gim;++// Version the reopened work must be tested on.+const CURRENT_VERSION_RE = /\b0\.2\.\d+|0\.2\.0-beta/i;+// Any version or commit.+const ANY_VERSION_RE = /\bv?\d+\.\d+(\.\d+)*(-[a-z0-9.]+)?\b|\b[0-9a-f]{7,40}\b|\bcommit\b/i;+const HARDWARE_RE = /\b(rtx|gtx|geforce|quadro|tesla|radeon|rx ?\d|instinct|arc|a\d{3,4}|b\d{2,3}|apple|m[1-5]( pro| max| ultra)?|nvidia|amd|intel|gpu|cpu|vram|\d+ ?gb|ram|windows|linux|ubuntu|debian|fedora|arch|macos|mac os|wsl)\b/i;+const REVISION_RE = /0\.2\.\d|beta|\bmain\b|\b[0-9a-f]{7,40}\b/i;++function stripComments(text) {+ return String(text || '').replace(/<!--[\s\S]*?-->/g, '');+}++function hasAreaPrefix(title) {+ return TITLE_RE.test(String(title || ''));+}++// Issue forms render as "### Label\n\nvalue". Returns { label: value } for those headings.+function parseSections(body) {+ const out = {};+ let cur = null;+ for (const line of stripComments(body).split(/\r?\n/)) {+ const m = /^#{1,6}\s+(.+?)\s*#*\s*$/.exec(line);+ if (m) {+ cur = m[1].trim();+ out[cur] = '';+ } else if (cur !== null) {+ out[cur] += line + '\n';+ }+ }+ for (const k of Object.keys(out)) out[k] = out[k].trim();+ return out;+}++function realText(value) {+ const t = String(value || '').replace(NOT_RUN_LABELS, '').replace(/\s+/g, ' ').trim();+ return NO_ANSWER.test(t) ? '' : t;+}++function findSection(sections, re) {+ for (const k of Object.keys(sections)) if (re.test(k)) return { key: k, value: sections[k] };+ return null;+}++// Required parts of each issue form: [display name, heading regex, minimum characters of real text].+const FORMS = {+ bug: {+ detect: /what happened/i,+ parts: [+ ['Area', /^area$/i, 2],+ ['Desktop app, Terminal or source?', /desktop app, terminal or source/i, 2],+ ['What happened', /what happened/i, 20],+ ['Reproduction status', /reproduction status/i, 2],+ ['Strata version', /strata version/i, 3],+ ['Graphics card, memory and system', /graphics card|memory and system/i, 3],+ ],+ needsCurrentVersion: 'Strata version',+ },+ feature: {+ detect: /what do you want to do/i,+ parts: [+ ['Area', /^area$/i, 2],+ ['What do you want to do?', /what do you want to do/i, 20],+ ],+ },+ question: {+ detect: /your question/i,+ parts: [+ ['Area', /^area$/i, 2],+ ['Your question', /your question/i, 15],+ ],+ },+ benchmark: {+ detect: /what did you measure/i,+ parts: [+ ['What did you measure, or what went wrong', /what did you measure/i, 30],+ ['Reproduction status', /reproduction status/i, 2],+ ],+ needsCurrentVersionInBody: true,+ },+};++function checkIssue({ title, body, labels = [], mode = 'intake' }) {+ const missing = [];+ if (!hasAreaPrefix(title)) {+ missing.push('Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other], then a short description. Example: "[Engine] decode stops after 2 minutes".');+ }+ const text = stripComments(body);+ const sections = parseSections(text);+ const labelSet = new Set(labels.map((l) => String(l).toLowerCase()));+ const needCurrent = mode === 'reopen';++ let formKey = null;+ for (const [key, f] of Object.entries(FORMS)) {+ if (findSection(sections, f.detect)) { formKey = key; break; }+ }++ if (formKey) {+ const form = FORMS[formKey];+ for (const [name, re, min] of form.parts) {+ const s = findSection(sections, re);+ if (!s || realText(s.value).length < min) missing.push('Fill in "' + name + '".');+ }+ if (needCurrent && form.needsCurrentVersion) {+ const s = findSection(sections, /strata version/i);+ if (s && realText(s.value) && !CURRENT_VERSION_RE.test(s.value)) {+ missing.push('Re-test on Strata 0.2.0-beta and put that version in "' + form.needsCurrentVersion + '". If it no longer happens, say so in a comment instead.');+ }+ }+ if (needCurrent && form.needsCurrentVersionInBody && !CURRENT_VERSION_RE.test(text)) {+ missing.push('Say which Strata version you measured on. Re-measure on 0.2.0-beta if you can.');+ }+ return { ok: missing.length === 0, missing, kind: formKey };+ }++ // Free-form text (older issues, blank issues).+ const plain = realText(text);+ const lenient = labelSet.has('enhancement') || labelSet.has('question');+ if (plain.length < (lenient ? 40 : 80)) {+ missing.push('Describe it in the issue body: what happened, what you expected, and the exact error if there is one. The issue forms (New issue > Bug report) list what to include.');+ }+ if (!lenient) {+ if (!ANY_VERSION_RE.test(text)) missing.push('Add the Strata version (Settings > About, or `strata --version`).');+ else if (needCurrent && !CURRENT_VERSION_RE.test(text)) missing.push('Re-test on Strata 0.2.0-beta and name that version in the issue. If it no longer happens, say so in a comment instead.');+ if (!HARDWARE_RE.test(text)) missing.push('Add your graphics card with its VRAM, your RAM and your operating system.');+ }+ return { ok: missing.length === 0, missing, kind: 'free-form' };+}++function checkPull({ title, body, mode = 'intake' }) {+ const missing = [];+ if (!hasAreaPrefix(title)) {+ missing.push('Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other], then a short description. Example: "[Engine] fix decode stop on long prompts".');+ }+ const text = stripComments(body);+ const sections = parseSections(text);+ const problem = findSection(sections, /problem|result|summary|what.*change/i);+ const validation = findSection(sections, /validation|testing|tests?\b|how.*tested/i);++ let valText = '';+ if (problem || validation) {+ if (!problem || realText(problem.value).length < 20) missing.push('Fill in "Problem and result": what triggered the change, and how it behaves before and after.');+ if (!validation || realText(validation.value).length < 20) {+ missing.push('Fill in "Validation": the exact commands, the revision and environment tested, what you saw. Keep Passed, Failed and Not run apart.');+ } else {+ valText = validation.value;+ }+ } else {+ const plain = realText(text);+ if (plain.length < 150) {+ missing.push('Describe the pull request: the problem and the result. The pull request template shows the parts (Problem and result, Related discussion, Approach, Validation, Limits).');+ }+ if (!/(problem|result|before|after|fix|because|bug)/i.test(plain)) missing.push('Add "Problem and result": what triggered the change, and how it behaves before and after.');+ if (!/(validat|tested|passed|ran |built|build|not run)/i.test(plain)) missing.push('Add "Validation": the exact commands, the revision and environment tested, and what you saw.');+ valText = plain;+ }+ if (mode === 'reopen' && valText && !REVISION_RE.test(valText)) {+ missing.push('Say in Validation which revision you tested: rebase on main (or 0.2.0-beta) and re-run your checks.');+ }+ return { ok: missing.length === 0, missing, kind: 'pull' };+}++function checkItem({ isPull, ...rest }) {+ return isPull ? checkPull(rest) : checkIssue(rest);+}++function checklist(missing) {+ return missing.map((m) => '- [ ] ' + m).join('\n');+}++const CONTRIB = 'https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md';++function intakeComment(isPull, missing) {+ return [+ 'Thanks for the ' + (isPull ? 'pull request' : 'issue') + '. To keep the tracker readable, every item needs an area prefix in the title and the parts of the ' + (isPull ? 'pull request template' : 'issue form') + ' filled in. This one is missing:',+ '',+ checklist(missing),+ '',+ 'Edit the ' + (isPull ? 'pull request' : 'issue') + ' (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment `/reopen`.',+ '',+ 'Details: [CONTRIBUTING.md](' + CONTRIB + ')',+ ].join('\n');+}++function reopenMissingComment(isPull, missing) {+ return [+ 'Not reopened yet. Still missing:',+ '',+ checklist(missing),+ '',+ 'Edit the ' + (isPull ? 'pull request' : 'issue') + ' and comment `/reopen` again. Details: [CONTRIBUTING.md](' + CONTRIB + ')',+ ].join('\n');+}++function reopenOkComment(isPull) {+ return 'Reopened, thank you. A maintainer will pick it up from here.' + (isPull ? ' If it conflicts with main, rebase it first; that speeds up review.' : '');+}++function staleComment(isPull) {+ return [+ 'Closing this ' + (isPull ? 'pull request' : 'issue') + ' because it still did not follow the format after 5 days. That is housekeeping, not a rejection.',+ '',+ 'To bring it back: fix the title (area prefix) and the missing parts, then comment `/reopen`. A check runs and reopens it, or tells you what is still missing. See [CONTRIBUTING.md](' + CONTRIB + ').',+ ].join('\n');+}++module.exports = {+ AREAS, TITLE_RE, hasAreaPrefix, parseSections, stripComments, realText,+ checkIssue, checkPull, checkItem, checklist,+ intakeComment, reopenMissingComment, reopenOkComment, staleComment,+};diff --git a/.github/scripts/item-check.test.js b/.github/scripts/item-check.test.jsnew file mode 100644index 000000000..c870f144c--- /dev/null+++ b/.github/scripts/item-check.test.js@@ -0,0 +1,192 @@+'use strict';+const test = require('node:test');+const assert = require('node:assert');+const c = require('./item-check');+const bot = require('./reset-bot');++const bugForm = (over = {}) => {+ const f = {+ 'Area': '[Engine] (speed, kernels, models, the server and API)',+ 'Desktop app, Terminal or source?': 'Terminal (the `strata` command)',+ 'What happened': 'Decode stops after two minutes with "CUDA error 700". I expected it to continue.',+ 'Smallest steps or command that reproduce it': '_No response_',+ 'Reproduction status': 'Reproduced locally',+ 'Strata version': 'Strata 0.2.0-beta · engine 0.1.45.3',+ 'Graphics card, memory and system': 'RTX 5070 12 GB · 64 GB RAM · Windows 11',+ ...over,+ };+ return Object.entries(f).map(([k, v]) => `### ${k}\n\n${v}`).join('\n\n');+};++test('title prefix', () => {+ assert.ok(c.hasAreaPrefix('[Engine] fix decode'));+ assert.ok(c.hasAreaPrefix('[Docs] x'));+ assert.ok(!c.hasAreaPrefix('Engine fix'));+ assert.ok(!c.hasAreaPrefix('[engine] fix'));+ assert.ok(!c.hasAreaPrefix('[Engine]'));+ assert.ok(!c.hasAreaPrefix('[Engine] '));+ assert.ok(!c.hasAreaPrefix('[Area] foo'));+ assert.ok(!c.hasAreaPrefix(''));+ assert.ok(!c.hasAreaPrefix(undefined));+});++test('filled bug form passes in both modes', () => {+ for (const mode of ['intake', 'reopen']) {+ const r = c.checkIssue({ title: '[Engine] decode stops', body: bugForm(), labels: ['bug'], mode });+ assert.deepStrictEqual(r.missing, []);+ assert.strictEqual(r.kind, 'bug');+ }+});++test('bug form: missing parts are named', () => {+ const r = c.checkIssue({ title: 'decode stops', body: bugForm({ 'Strata version': '_No response_', 'What happened': 'bad' }) });+ assert.ok(!r.ok);+ assert.ok(r.missing.some((m) => /title/i.test(m)));+ assert.ok(r.missing.some((m) => m.includes('What happened')));+ assert.ok(r.missing.some((m) => m.includes('Strata version')));+});++test('reopen needs a 0.2 version, intake does not', () => {+ const body = bugForm({ 'Strata version': 'Strata 0.1.44' });+ assert.ok(c.checkIssue({ title: '[Engine] x y', body, mode: 'intake' }).ok);+ const r = c.checkIssue({ title: '[Engine] x y', body, mode: 'reopen' });+ assert.ok(!r.ok);+ assert.ok(r.missing.some((m) => m.includes('0.2.0-beta')));+});++test('html comments and placeholders do not count', () => {+ const r = c.checkIssue({ title: '[Engine] x y', body: bugForm({ 'What happened': '<!-- describe -->' }) });+ assert.ok(r.missing.some((m) => m.includes('What happened')));+});++test('feature and question forms', () => {+ const f = '### Area\n\n[GUI] (the desktop app)\n\n### What do you want to do?\n\nLet me pin a model to the top of the list in the app.';+ assert.ok(c.checkIssue({ title: '[GUI] pin models', body: f, mode: 'reopen' }).ok);+ assert.ok(!c.checkIssue({ title: '[GUI] pin models', body: '### Area\n\n[GUI]\n\n### What do you want to do?\n\n_No response_' }).ok);+ const q = '### Area\n\n[Other]\n\n### Your question\n\nHow do I move the model folder to another drive?';+ assert.ok(c.checkIssue({ title: '[Other] model folder', body: q }).ok);+});++test('free-form issue', () => {+ const good = 'Strata 0.2.0-beta on an RTX 3060 12 GB with 32 GB RAM on Linux: the server hangs when I send two requests at once. Expected both to finish.';+ assert.ok(c.checkIssue({ title: '[Engine] hang on two requests', body: good, mode: 'reopen' }).ok);+ assert.ok(!c.checkIssue({ title: '[Engine] hang', body: 'it crashes', mode: 'intake' }).ok);+ const old = good.replace('0.2.0-beta', '0.1.40');+ assert.ok(c.checkIssue({ title: '[Engine] hang', body: old, mode: 'intake' }).ok);+ assert.ok(!c.checkIssue({ title: '[Engine] hang', body: old, mode: 'reopen' }).ok);+ assert.ok(c.checkIssue({ title: '[Other] idea', body: 'It would help if the app remembered my last model between runs, today I pick it again.', labels: ['enhancement'], mode: 'reopen' }).ok);+});++const prBody = (over = {}) => {+ const p = {+ problem: 'Decode stopped on prompts above 8k because the stop check read the wrong length. Now it continues.',+ validation: '**Passed:** `ctest -R decode`, commit abcdef1, RTX 3060, 12 of 12.\n\n**Failed:** none observed\n\n**Not run:** HIP build',+ ...over,+ };+ return `## Problem and result\n<!-- hint -->\n${p.problem}\n\n## Related discussion\nnone\n\n## Approach\nFix the length.\n\n## Validation\n${p.validation}\n\n## Limits\nnone`;+};++test('filled PR passes', () => {+ assert.deepStrictEqual(c.checkPull({ title: '[Engine] fix stop', body: prBody(), mode: 'reopen' }).missing, []);+});++test('untouched PR template fails', () => {+ const tpl = '## Problem and result\n<!-- What triggered -->\n\n## Validation\n<!-- cmds -->\n\n**Passed:**\n<!-- x -->\n\n**Failed:**\n\n**Not run:**\n';+ const r = c.checkPull({ title: '[Engine] fix stop', body: tpl });+ assert.ok(!r.ok);+ assert.ok(r.missing.some((m) => m.includes('Problem and result')));+ assert.ok(r.missing.some((m) => m.includes('Validation')));+});++test('PR: empty body and bad title', () => {+ const r = c.checkPull({ title: 'fix', body: null });+ assert.ok(!r.ok);+ assert.ok(r.missing.length >= 2);+});++test('PR reopen needs a revision', () => {+ const body = prBody({ validation: '**Passed:** I tried it and it worked for me on my machine, looked fine.' });+ assert.ok(c.checkPull({ title: '[Engine] x y', body, mode: 'intake' }).ok);+ assert.ok(!c.checkPull({ title: '[Engine] x y', body, mode: 'reopen' }).ok);+});++test('free-form PR', () => {+ const body = 'This fixes a crash when the context is above 8k, because the length was read from the wrong field. Before it aborted, after it continues. I built it on CUDA and ran the decode test, passed.';+ assert.ok(c.checkPull({ title: '[Engine] fix crash', body }).ok);+ assert.ok(!c.checkPull({ title: '[Engine] fix crash', body: 'fixes stuff' }).ok);+});++test('messages', () => {+ const m = c.intakeComment(false, ['a', 'b']);+ assert.ok(m.includes('- [ ] a') && m.includes('/reopen') && m.includes('CONTRIBUTING.md'));+ assert.ok(c.staleComment(true).includes('/reopen'));+});++// handlers with a fake GitHub client+function fake(calls, extra = {}) {+ const rest = {+ issues: {+ getLabel: async () => ({}),+ createLabel: async (a) => calls.push(['createLabel', a.name]),+ addLabels: async (a) => calls.push(['addLabels', a.labels]),+ removeLabel: async (a) => calls.push(['removeLabel', a.name]),+ createComment: async (a) => calls.push(['comment', a.body]),+ update: async (a) => calls.push(['update', a.state]),+ get: async () => ({ data: extra.live }),+ listEvents: async () => {},+ listForRepo: async () => {},+ },+ pulls: { get: async () => ({ data: { mergeable_state: 'clean' } }) },+ };+ return { rest, paginate: async (fn) => (fn === rest.issues.listEvents ? (extra.events || []) : (extra.items || [])) };+}+const core = { info() {} };+const repo = { owner: 'o', repo: 'r' };++test('intake labels and comments once', async () => {+ const calls = [];+ const item = { number: 1, title: 'bad', body: '', labels: [], user: { type: 'User' }, author_association: 'NONE' };+ await bot.intake({ github: fake(calls), context: { repo, payload: { action: 'opened', issue: item } }, core });+ assert.deepStrictEqual(calls.map((c) => c[0]), ['addLabels', 'comment']);+ calls.length = 0;+ item.labels = [{ name: 'needs-format' }];+ await bot.intake({ github: fake(calls), context: { repo, payload: { action: 'edited', issue: item } }, core });+ assert.deepStrictEqual(calls, []);+});++test('intake clears the label when edited into shape', async () => {+ const calls = [];+ const item = { number: 1, title: '[Engine] x y', body: bugForm(), labels: [{ name: 'needs-format' }], user: { type: 'User' } };+ await bot.intake({ github: fake(calls), context: { repo, payload: { action: 'edited', issue: item } }, core });+ assert.deepStrictEqual(calls.map((c) => c[0]), ['removeLabel', 'comment']);+});++test('reopen: ignores strangers, reopens the author when it passes', async () => {+ const issue = { number: 5, state: 'closed', user: { login: 'amy' }, labels: [] };+ let calls = [];+ const comment = { body: '/reopen', user: { login: 'bob', type: 'User' }, author_association: 'NONE' };+ await bot.reopen({ github: fake(calls), context: { repo, payload: { issue, comment } }, core });+ assert.deepStrictEqual(calls, []);++ const live = { number: 5, title: '[Engine] x y', body: bugForm(), labels: [] };+ comment.user.login = 'amy';+ await bot.reopen({ github: fake(calls, { live }), context: { repo, payload: { issue, comment } }, core });+ assert.deepStrictEqual(calls.map((c) => c[0]), ['update', 'removeLabel', 'comment']);+ assert.strictEqual(calls[0][1], 'open');++ calls = [];+ live.title = 'no prefix';+ await bot.reopen({ github: fake(calls, { live }), context: { repo, payload: { issue, comment } }, core });+ assert.deepStrictEqual(calls.map((c) => c[0]), ['comment']);+ assert.ok(calls[0][1].includes('Not reopened'));+});++test('sweep closes only old flagged items', async () => {+ const calls = [];+ const old = new Date(Date.now() - 6 * 86400000).toISOString();+ const fresh = new Date(Date.now() - 1 * 86400000).toISOString();+ const mk = (n, created) => ({ number: n, title: 'bad', body: '', labels: [{ name: 'needs-format' }], created_at: created });+ const gh = fake(calls, { items: [mk(1, old), mk(2, fresh)] });+ await bot.sweep({ github: gh, context: { repo }, core });+ assert.deepStrictEqual(calls.map((c) => c[0]), ['comment', 'update']);+});diff --git a/.github/scripts/reset-bot.js b/.github/scripts/reset-bot.jsnew file mode 100644index 000000000..11eb63ae3--- /dev/null+++ b/.github/scripts/reset-bot.js@@ -0,0 +1,164 @@+'use strict';+// GitHub-side handlers for intake.yml, reopen.yml and the 5-day sweep.+// They take the actions/github-script objects ({ github, context, core }) and never touch PR code:+// everything comes from the event payload and the REST API.++const check = require('./item-check');++const LABEL = 'needs-format';+const STALE_DAYS = 5;+const MAINTAINER = new Set(['OWNER', 'MEMBER', 'COLLABORATOR']);+// Items a maintainer closed on purpose stay closed.+const BLOCK_LABELS = new Set(['wontfix', 'invalid', 'duplicate', 'declined']);++function labelNames(item) {+ return (item.labels || []).map((l) => (typeof l === 'string' ? l : l.name));+}++async function ensureLabel(github, context) {+ const { owner, repo } = context.repo;+ try {+ await github.rest.issues.getLabel({ owner, repo, name: LABEL });+ } catch (e) {+ if (e.status !== 404) throw e;+ await github.rest.issues.createLabel({+ owner, repo, name: LABEL, color: 'fbca04',+ description: 'Title or description does not follow CONTRIBUTING.md yet',+ });+ }+}++async function removeLabel(github, context, number) {+ const { owner, repo } = context.repo;+ try {+ await github.rest.issues.removeLabel({ owner, repo, issue_number: number, name: LABEL });+ } catch (e) {+ if (e.status !== 404) throw e;+ }+}++function itemFromPayload(context) {+ const p = context.payload;+ return p.pull_request || p.issue;+}++function isPullItem(item, context) {+ return Boolean(context.payload.pull_request || item.pull_request);+}++// issues: opened/edited/reopened, pull_request_target: opened/edited/reopened+async function intake({ github, context, core }) {+ const { owner, repo } = context.repo;+ const item = itemFromPayload(context);+ if (!item || (item.user && item.user.type === 'Bot')) return;+ if (MAINTAINER.has(item.author_association) && context.payload.action === 'opened') {+ // Maintainer items are not nagged on creation.+ return;+ }+ const isPull = isPullItem(item, context);+ const labels = labelNames(item);+ const hasLabel = labels.includes(LABEL);+ const res = check.checkItem({ isPull, title: item.title, body: item.body, labels, mode: 'intake' });+ core.info('check ' + (isPull ? 'PR' : 'issue') + ' #' + item.number + ': ' + (res.ok ? 'ok' : res.missing.join(' | ')));++ if (res.ok) {+ if (hasLabel) {+ await removeLabel(github, context, item.number);+ await github.rest.issues.createComment({ owner, repo, issue_number: item.number, body: 'Thanks, this follows the format now.' });+ }+ return;+ }+ if (context.payload.action === 'edited' && !hasLabel) return; // edits only matter for items already flagged+ if (hasLabel) return; // one note only+ await ensureLabel(github, context);+ await github.rest.issues.addLabels({ owner, repo, issue_number: item.number, labels: [LABEL] });+ await github.rest.issues.createComment({ owner, repo, issue_number: item.number, body: check.intakeComment(isPull, res.missing) });+}++// issue_comment created, body starts with /reopen+async function reopen({ github, context, core }) {+ const { owner, repo } = context.repo;+ const comment = context.payload.comment;+ const issue = context.payload.issue;+ if (!/^\s*\/reopen\b/.test(comment.body || '')) return;+ if (comment.user.type === 'Bot') return;+ const isAuthor = comment.user.login === issue.user.login;+ const isMaint = MAINTAINER.has(comment.author_association);+ if (!isAuthor && !isMaint) {+ core.info('ignored /reopen from ' + comment.user.login + ' (not the author or a maintainer)');+ return;+ }+ const isPull = Boolean(issue.pull_request);+ const say = (body) => github.rest.issues.createComment({ owner, repo, issue_number: issue.number, body });+ const labels = labelNames(issue);+ const wasOpen = issue.state === 'open';++ if (labels.some((l) => BLOCK_LABELS.has(l.toLowerCase())) && !isMaint) {+ await say('This one was closed on purpose (' + labels.filter((l) => BLOCK_LABELS.has(l.toLowerCase())).join(', ') + '). Please add your new evidence in a comment and a maintainer will decide.');+ return;+ }+ if (wasOpen && !labels.includes(LABEL)) {+ core.info('already open, nothing to do');+ return;+ }++ // The bot reads the live item, not the possibly stale event copy.+ const live = (await github.rest.issues.get({ owner, repo, issue_number: issue.number })).data;+ const res = check.checkItem({ isPull, title: live.title, body: live.body, labels: labelNames(live), mode: 'reopen' });+ core.info('reopen check #' + live.number + ': ' + (res.ok ? 'ok' : res.missing.join(' | ')));++ if (!res.ok) {+ await say(check.reopenMissingComment(isPull, res.missing));+ return;+ }+ if (!wasOpen) {+ try {+ await github.rest.issues.update({ owner, repo, issue_number: live.number, state: 'open' });+ } catch (e) {+ await say('The check passed, but GitHub would not reopen it (' + (e.message || e.status) + '). ' + (isPull ? 'If the branch was deleted, restore it or open a new pull request and link this one.' : 'Please open a new issue and link this one.'));+ return;+ }+ }+ await removeLabel(github, context, live.number);+ let extra = '';+ if (isPull) {+ try {+ const pr = (await github.rest.pulls.get({ owner, repo, pull_number: live.number })).data;+ if (pr.mergeable_state === 'dirty') extra = '\n\nIt has conflicts with main now: please rebase it.';+ } catch (e) { /* best effort */ }+ }+ await say(check.reopenOkComment(isPull) + extra);+}++async function labelTime(github, owner, repo, number, fallback) {+ const events = await github.paginate(github.rest.issues.listEvents, { owner, repo, issue_number: number, per_page: 100 });+ let t = null;+ for (const e of events) {+ if (e.event === 'labeled' && e.label && e.label.name === LABEL) t = e.created_at;+ }+ return t || fallback;+}++// scheduled: close items that kept the needs-format label for more than 5 days+async function sweep({ github, context, core }) {+ const { owner, repo } = context.repo;+ const cutoff = Date.now() - STALE_DAYS * 86400 * 1000;+ const items = await github.paginate(github.rest.issues.listForRepo, { owner, repo, state: 'open', labels: LABEL, per_page: 100 });+ core.info(items.length + ' open items with ' + LABEL);+ for (const item of items) {+ const since = new Date(await labelTime(github, owner, repo, item.number, item.created_at)).getTime();+ if (since > cutoff) continue;+ const isPull = Boolean(item.pull_request);+ // Re-check first: an edit that fixed it should have cleared the label already; do not close good items.+ const res = check.checkItem({ isPull, title: item.title, body: item.body, labels: labelNames(item), mode: 'intake' });+ if (res.ok) {+ await removeLabel(github, context, item.number);+ continue;+ }+ await github.rest.issues.createComment({ owner, repo, issue_number: item.number, body: check.staleComment(isPull) });+ await github.rest.issues.update({ owner, repo, issue_number: item.number, state: 'closed', state_reason: 'not_planned' });+ core.info('closed #' + item.number);+ }+}++module.exports = { intake, reopen, sweep, LABEL, STALE_DAYS };diff --git a/.github/workflows/intake.yml b/.github/workflows/intake.ymlnew file mode 100644index 000000000..326a0d924--- /dev/null+++ b/.github/workflows/intake.yml@@ -0,0 +1,58 @@+name: Intake++# New issues and pull requests that do not follow CONTRIBUTING.md get the needs-format label and one friendly note.+# Items that keep the label for 5 days are closed by the daily sweep, with a note on how to /reopen.+#+# pull_request_target is used instead of pull_request on purpose: a pull request from a fork gets a read-only+# GITHUB_TOKEN under pull_request, so it could not be labelled or commented on. It is safe here because this+# workflow never checks out or runs the pull request's code. It checks out the default branch only (the bot+# scripts) and reads the title and description from the event payload and the REST API.++on:+ issues:+ types: [opened, edited]+ pull_request_target:+ types: [opened, edited]+ schedule:+ - cron: '17 4 * * *'+ workflow_dispatch:++permissions:+ contents: read+ issues: write+ pull-requests: write++concurrency:+ group: intake-${{ github.event.issue.number || github.event.pull_request.number || 'sweep' }}+ cancel-in-progress: false++jobs:+ check:+ if: github.event_name == 'issues' || github.event_name == 'pull_request_target'+ runs-on: ubuntu-latest+ steps:+ - uses: actions/checkout@v4+ with:+ ref: ${{ github.event.repository.default_branch }}+ sparse-checkout: .github/scripts+ persist-credentials: false+ - uses: actions/github-script@v7+ with:+ script: |+ const bot = require('./.github/scripts/reset-bot.js');+ await bot.intake({ github, context, core });++ sweep:+ if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'+ runs-on: ubuntu-latest+ steps:+ - uses: actions/checkout@v4+ with:+ ref: ${{ github.event.repository.default_branch }}+ sparse-checkout: .github/scripts+ persist-credentials: false+ - uses: actions/github-script@v7+ with:+ script: |+ const bot = require('./.github/scripts/reset-bot.js');+ await bot.sweep({ github, context, core });diff --git a/.github/workflows/reopen.yml b/.github/workflows/reopen.ymlnew file mode 100644index 000000000..ff7c10f9a--- /dev/null+++ b/.github/workflows/reopen.yml@@ -0,0 +1,38 @@+name: Reopen++# An author comments /reopen on their closed issue or pull request. The check runs and the item is reopened,+# or the bot replies with what is still missing. GitHub does not let authors reopen items a maintainer closed,+# so this workflow does it for them.+#+# issue_comment always runs the workflow file from the default branch with a write-capable token, which is what+# we need for fork authors too. It never checks out or executes the pull request's code: it reads the live+# title and description through the REST API. Only the author of the item or a maintainer can trigger it.++on:+ issue_comment:+ types: [created]++permissions:+ contents: read+ issues: write+ pull-requests: write++concurrency:+ group: reopen-${{ github.event.issue.number }}+ cancel-in-progress: false++jobs:+ reopen:+ if: startsWith(github.event.comment.body, '/reopen') && github.event.comment.user.type != 'Bot'+ runs-on: ubuntu-latest+ steps:+ - uses: actions/checkout@v4+ with:+ ref: ${{ github.event.repository.default_branch }}+ sparse-checkout: .github/scripts+ persist-credentials: false+ - uses: actions/github-script@v7+ with:+ script: |+ const bot = require('./.github/scripts/reset-bot.js');+ await bot.reopen({ github, context, core });diff --git a/.github/workflows/scripts-test.yml b/.github/workflows/scripts-test.ymlnew file mode 100644index 000000000..97b5de9c0--- /dev/null+++ b/.github/workflows/scripts-test.yml@@ -0,0 +1,21 @@+name: Scripts test++on:+ pull_request:+ paths:+ - '.github/scripts/**'+ - '.github/workflows/intake.yml'+ - '.github/workflows/reopen.yml'++permissions:+ contents: read++jobs:+ node-test:+ runs-on: ubuntu-latest+ steps:+ - uses: actions/checkout@v4+ - uses: actions/setup-node@v4+ with:+ node-version: 22+ - run: node --test .github/scripts/item-check.test.js