// What state an issue is in, as far as a maintainer is concerned. // // Deterministic: no LLM, no network. The labels already say where an issue is; this turns them into the questions a // maintainer asks: is the Concierge managing this issue, whose move is it, has the reporter answered, what did the // gates cost. The status issue (status-issue.mjs) renders the answers, and the commands that come after it will // read the same state, so that what a maintainer is shown and what a command does cannot drift apart. // Rules and reasons: docs/multi-phase-design.md, "The maintainer's view". // // Install: copy to .github/scripts/issue-concierge-state.mjs (it imports janitor.mjs and opt-out.mjs, so install those too). import { GATE, LABEL_AGENT_FAILED, isCodingAgent } from './janitor.mjs'; import { isOptedOut, labelNames } from './opt-out.mjs'; export const BOT = 'github-actions[bot]'; /** * The repository variables that pause the Concierge (docs/decisions/0037): the name of the product, and the name it had * before, which still works so that a pause set under it does not lift when the Concierge is updated. Either one set to * `true` pauses; the workflow conditions read both (tools/pause.test.mjs keeps the two readings together). */ export const PAUSE_VARIABLES = ['ISSUE_CONCIERGE_PAUSED', 'CONCIERGE_PAUSED']; /** The pause variables that are `true` in `env`, the environment a workflow fills from `vars`. Any case: a workflow condition compares strings without regard to case. */ export const pausedBy = (env = {}) => PAUSE_VARIABLES.filter((name) => String(env[name] ?? '').toLowerCase() === 'true'); /** The people whose answer is a maintainer's: a reply from anyone else is a reporter's. */ export const MAINTAINER_ASSOCIATIONS = new Set(['OWNER', 'MEMBER', 'COLLABORATOR']); /** Whose move it is, and the label that says so, in the order the status issue lists them. */ export const QUEUES = [ { id: 'decision', who: 'you', label: 'needs-decision', title: 'Held: changes what exists' }, { id: 'scope', who: 'you', label: 'scope-review', title: 'Held: may not fit the scope' }, { id: 'plan', who: 'you', label: 'plan-approval-required', title: 'Held: waiting for your approval' }, { id: 'agent', who: 'you', label: LABEL_AGENT_FAILED, title: 'Held: the coding agent did not start' }, { id: 'dependency', who: 'another issue', label: 'dependency-required', title: 'Waiting for a dependency' }, { id: 'reporter', who: 'the reporter', label: 'needs-info', title: 'Waiting for the reporter' }, { id: 'parked', who: 'nobody', label: 'backlog', title: 'Parked' }, ]; export const GATE_LABELS = [...GATE.issue, ...GATE.pr]; /** The labels that only the Concierge applies. A label a repository may use for itself (`duplicate`, `spam`) proves nothing. */ const OTHER_CONCIERGE_LABELS = [ 'plan-approval-required', 'needs-decision', 'scope-review', 'out-of-scope', 'dependency-required', 'dependency-satisfied', 'needs-info', 'backlog', 'low-hanging-fruit', 'related-repo', 'original-in-related-repo', 'waiting-for-release', 'released', 'declined', LABEL_AGENT_FAILED, ]; export const CONCIERGE_LABELS = [...GATE_LABELS, ...OTHER_CONCIERGE_LABELS]; export const isConciergeLabel = (name) => CONCIERGE_LABELS.includes(name) || /^(complexity|risk)\//.test(name); /** An issue in a gate for longer than this is stuck: a whole run of the three gates takes about a quarter of an hour. */ export const STUCK_AFTER_MINUTES = 60; /** * How long a plan that was asked for (a hand-off to the plan worker, or a `/replan`) is taken as still on its way, and * the options comment is kept back. The plan worker stops after 6 minutes and plan triage after 4, and the plan worker * answers every hand-off with `plan-worker-ready`, even when it writes no plan, so a healthy hand-off is answered well * inside this time. It is the limit for a worker that fails or never starts; the stuck limit above, an hour, would * leave a maintainer without the commands for that long. */ export const PLAN_OWED_MINUTES = 20; /** * The queue of a managed issue, or the stage it is in when nobody has to move. `backlog` says an issue is parked, and it * stays on an issue that a maintainer has since approved (frodo-lib#783 kept it from its first triage to its pull request), * so it counts only when nothing is working on the issue: a gate label or the coding agent outranks it. The other queues * are waits that something else is not working on, and they come first. */ export function queueOf(issue) { const labels = new Set(labelNames(issue)); const queue = QUEUES.find((q) => q.id !== 'parked' && labels.has(q.label)); if (queue) return queue.id; if (GATE_LABELS.some((l) => labels.has(l))) return 'in-flight'; if ((issue.assignees || []).some((a) => isCodingAgent(a.login || a))) return 'with-agent'; if (labels.has('backlog')) return 'parked'; if (labels.has('related-repo')) return 'elsewhere'; return 'settled'; } /** * What the Concierge is to this issue. `analysed` says the issue worker has commented on it, which the labels cannot * show for an issue that was analysed and then given no label (a fix already in review, say). * kind: pull-request | opted-out | bot-authored | managed (with a queue) | not-picked-up */ export function classify(issue, { analysed = false } = {}) { if (issue.pull_request) return { kind: 'pull-request' }; if (isOptedOut(issue)) return { kind: 'opted-out' }; if (issue.user && issue.user.type === 'Bot') return { kind: 'bot-authored' }; if (!analysed && !labelNames(issue).some(isConciergeLabel)) return { kind: 'not-picked-up' }; return { kind: 'managed', queue: queueOf(issue) }; } /** * How long an issue may be with the coding agent before the page says no pull request has come. A session opens its draft * pull request within seconds of starting, so half an hour with none means the session did not start (or the pull request was * closed), and the agent says so itself only in the case scripts/agent-start-watch.mjs reads. */ export const AGENT_QUIET_MINUTES = 30; /** When the coding agent was assigned, from the issue's events (the latest assignment); null when it was never seen. */ export function assignedAt(events) { const times = (events || []).filter((e) => e.event === 'assigned' && e.assignee && isCodingAgent(e.assignee.login)).map((e) => Date.parse(e.created_at)); return times.length ? Math.max(...times) : null; } /** True when a pull request body closes issue `number` of `repo`: `Fixes #7`, `Closes owner/repo#7`, in any case. */ export function closesIssue(body, number, repo) { for (const m of String(body || '').matchAll(/\b(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s*:?\s+(?:([\w.-]+\/[\w.-]+))?#(\d+)\b/gi)) { if (Number(m[2]) === number && (!m[1] || m[1].toLowerCase() === String(repo).toLowerCase())) return true; } return false; } /** The newest open pull request of the coding agent that closes the issue, or null. items: the open items of the repository, pull requests among them. */ export function agentPullFor(number, repo, items) { const mine = (items || []).filter((i) => i.pull_request && i.user && isCodingAgent(i.user.login) && closesIssue(i.body, number, repo)); mine.sort((a, b) => Date.parse(b.updated_at || 0) - Date.parse(a.updated_at || 0)); return mine[0] ?? null; } const esc = (s) => String(s).replace(/[.*+?^${}()|[\]\\/]/g, '\\$&'); /** True when a comment is the issue worker's analysis of this repository (gh-aw appends the marker to every comment). */ export function isAnalysis(comment, repo) { return Boolean(comment.user && comment.user.login === BOT && new RegExp(`gh-aw-workflow-call-id:\\s*${esc(repo)}/issue-worker(?![\\w-])`, 'i').test(comment.body || '')); } /** When a label was last applied, from the issue's events; null when it was never seen. */ export function labelledAt(events, label) { const times = (events || []).filter((e) => e.event === 'labeled' && e.label && e.label.name === label).map((e) => Date.parse(e.created_at)); return times.length ? Math.max(...times) : null; } /** * The hidden line the options comment starts with (scripts/commands.mjs). It is the bot's, and not anybody's reply. New menus * are written with the product's name; a menu written by an earlier version has the older line and is still the bot's menu * (the next sync edits it, so it carries the new line from then on). */ export const OPTIONS_MARKER = '