Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changes/pr-pipeline/feat-9215-refine-thin-issues-5b1e7c20.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
bump: minor
---

### Added

- Intake refines a thin issue: one whose triage flags `intent` or whose body has no task list line. A read-only model run in `intake-triage.yml` (`refine-issue`, contents read only, no project settings, `dontAsk`) explores the default branch, checks the open and closed issues and merged pull requests a title search found for duplicates and finished work, and reads the docs hosts resolve-issue reads. The `apply-refinement` activity posts its output as the lanes App in a separate comment opening with `<!-- intake-triage refinement -->`, once per issue.
- An exact refinement lists its acceptance criteria as a task list, lifts the lanes App's `status: needs-decision`, and triages the issue once more; one that is not exact asks numbered questions with `RECOMMENDED:` answers and leaves the issue at `status: needs-decision`. It never adds `agent-ready` or `needs-human`.
- Admission's criterion 7 also counts the task list in that comment when the lanes App's account posted it after the body's last edit, and the work lane's `issue.json` keeps that comment as `author_kind: refinement`.
- Only issues and pull requests a listed human or the lanes App opened reach the refinement model as duplicate candidates, and refinement text cannot add a link, an autolink or a `GH-N` reference.
- A refinement is dropped when the issue's title or body changed while the model ran. Labels change before the marker comment is posted, so a failed label update leaves no marker and the next triage refines the issue again.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
bump: patch
---

### Changed

- `/work-items:work` names the third `author_kind` its issue file can carry, `refinement`: the lanes App's intake refinement, model-drafted acceptance criteria to check against the body.
76 changes: 74 additions & 2 deletions .github/actions/resolve-config/callers.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ test("intake-triage.yml: apply-verdict writes as the lanes App only after a tria
const minting = Object.entries(jobs)
.filter(([, j]) => j.permissions?.["id-token"] !== undefined || j.permissions === "write-all")
.map(([id]) => id);
assert.deepEqual(minting, ["apply-verdict"], "only apply-verdict can request an OIDC token");
assert.deepEqual(minting, ["apply-verdict", "apply-refinement"], "only the two script writers can request an OIDC token");
assert.deepEqual(workflow("intake-triage.yml").permissions, {}, "no workflow-level grant");
assert.equal(job.concurrency["cancel-in-progress"], false);
assert.notEqual(job.concurrency.group, jobs["intake-triage"].concurrency.group, "its own concurrency group");
Expand Down Expand Up @@ -298,6 +298,72 @@ test("intake-triage.yml: apply-verdict writes as the lanes App only after a tria
assert.deepEqual(stepSecrets(job), []);
});

test("intake-triage.yml: a thin issue's refinement runs its model with no write token and writes through the lanes App only", () => {
const { jobs } = workflow("intake-triage.yml");
const select = jobs["refine-select"];
const model = jobs["refine-issue"];
const apply = jobs["apply-refinement"];
const again = jobs["redispatch-refined"];
assert.deepEqual(select.permissions, { contents: "read", issues: "read", "pull-requests": "read" });
assert.deepEqual(model.permissions, { contents: "read" }, "the model job holds no write grant");
assert.deepEqual(apply.permissions, { contents: "read", "id-token": "write" });
assert.deepEqual(again.permissions, { actions: "write" }, "the dispatch grant is not on the job with the App token");
assert.deepEqual(select.needs, ["born-triaged", "apply-verdict"]);
assert.deepEqual(model.needs, ["refine-select"]);
assert.deepEqual(apply.needs, ["born-triaged", "refine-select", "refine-issue"]);
assert.deepEqual(again.needs, ["apply-refinement"]);

const groups = Object.values(jobs)
.map((job) => job.concurrency?.group)
.filter(Boolean);
assert.equal(new Set(groups).size, groups.length, "each job has its own concurrency group");
for (const job of [select, model, apply]) {
assert.equal(job.concurrency["cancel-in-progress"], false);
}

assert.equal(evaluate(select.if, { "needs.apply-verdict.result": "success" }), true);
assert.equal(evaluate(select.if, { "needs.apply-verdict.result": "failure" }), false);
assert.equal(evaluate(model.if, { "needs.refine-select.outputs.refine": "true" }), true);
assert.equal(evaluate(model.if, { "needs.refine-select.outputs.refine": "false" }), false);
assert.equal(evaluate(apply.if, { "needs.refine-issue.result": "success" }), true);
assert.equal(evaluate(apply.if, { "needs.refine-issue.result": "skipped" }), false);
assert.equal(evaluate(again.if, { "needs.apply-refinement.outputs.redispatch": "true" }), true);
assert.equal(evaluate(again.if, { "needs.apply-refinement.outputs.redispatch": "" }), false);

// Every checkout is the default branch without credentials.
for (const job of [select, model, apply]) {
const checkout = job.steps.find((s) => s.uses?.startsWith("actions/checkout@"));
assert.equal(checkout.with.ref, "refs/heads/main");
assert.equal(checkout.with["persist-credentials"], false);
}

// The model step: no project settings, an explicit permission mode, and
// no tool that writes or runs code.
const run = model.steps.find((s) => s.uses?.startsWith("anthropics/claude-code-action@"));
const args = run.with.claude_args;
assert.match(args, /--setting-sources user/);
assert.match(args, /--permission-mode dontAsk/);
assert.doesNotMatch(JSON.stringify(model), /bypassPermissions|dangerously/);
const prompt = model.steps.find((s) => s.id === "prompt").run;
assert.match(prompt, /denied="Bash,Edit,Write,NotebookEdit,WebSearch,Agent,Skill"/);
assert.match(prompt, /mcp__github,mcp__github_comment,mcp__github_file_ops,mcp__github_ci,mcp__github_inline_comment/);
assert.match(prompt, /WebFetch\(domain:\$domain\)/);
assert.deepEqual(stepSecrets(model), ["AUTOMATIONS_CLAUDE_CODE_OAUTH_TOKEN"]);
for (const job of [select, apply, again]) {
assert.deepEqual(stepSecrets(job), []);
}

const step = (job, id) => job.steps.find((s) => s.id === id);
assert.match(step(select, "who").run, /apply-verdict\.mjs --check$/);
assert.match(step(apply, "who").run, /apply-verdict\.mjs --check$/);
assert.equal(step(apply, "config").with.activity, "apply-refinement");
const token = step(apply, "lane-token");
assert.equal(token.with.lane, "intake-triage");
assert.equal(token.with.activity, "apply-refinement");
assert.equal(token.with["issue-number"], "${{ format('{0}', github.event.issue.number || inputs.issue-number) }}");
assert.equal(step(apply, "apply").run, 'node ".base/$SCRIPT" --apply');
});

test("intake-triage.yml: the model may not apply good first issue or help wanted, and is told the verdict lines", () => {
const intake = workflow("intake-triage.yml").jobs["intake-triage"];
const allowed = intake.with["allowed-labels"].trim().split("\n");
Expand Down Expand Up @@ -1088,9 +1154,13 @@ function ifTerms(condition) {
// check-trusted-trigger run from the default branch (work-resolve-issue.yml's
// admit), or the pinned intake reusable, whose claude job starts only for a
// sender in allowed-author-ids (ci-workflows intake-triage.yml, the claude job's
// if:) and whose other Claude job needs it.
// if:) and whose other Claude job needs it, or a needed job's refine output
// from refine.mjs --select run from the default branch, which refines only an
// issue a listed human or the lanes App opened, in a run apply-verdict --check
// admitted (intake-triage.yml's refine-issue).
const SAME_REPO = "github.event.workflow_run.head_repository.full_name == github.repository";
const TRUSTED_TRIGGER = "./.base/.github/actions/check-trusted-trigger";
const REFINE_SELECT = "node .base/.github/scripts/intake-triage/refine.mjs --select";
const INTAKE_REUSABLE = /^melodic-software\/ci-workflows\/\.github\/workflows\/intake-triage\.yml@[0-9a-f]{40}$/;
function jobGates(doc, job) {
const gates = new Set();
Expand All @@ -1102,6 +1172,8 @@ function jobGates(doc, job) {
const gateJob = doc.jobs?.[need] ?? {};
const [, stepId] = String(gateJob.outputs?.[output] ?? "").match(/^\$\{\{\s*steps\.([\w-]+)\.outputs\.proceed\s*\}\}$/) ?? [];
if (stepId && (gateJob.steps ?? []).some((step) => step.id === stepId && step.uses === TRUSTED_TRIGGER)) gates.add("author");
const [, selectId] = String(gateJob.outputs?.[output] ?? "").match(/^\$\{\{\s*steps\.([\w-]+)\.outputs\.refine\s*\}\}$/) ?? [];
if (selectId && (gateJob.steps ?? []).some((step) => step.id === selectId && String(step.run ?? "").split("\n").some((line) => line.trim() === REFINE_SELECT))) gates.add("author");
}
if (INTAKE_REUSABLE.test(String(job.uses ?? "")) && String(job.with?.["allowed-author-ids"] ?? "").trim() !== "") gates.add("author");
return [...gates].sort();
Expand Down
3 changes: 2 additions & 1 deletion .github/lane-funding.json
Comment thread
kyle-sexton marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"keyed": true,
"category": "intake",
"lanes": [
{ "id": "intake-triage", "workflow": "intake-triage.yml", "launcher": "run-claude-cli", "triggers": ["issues", "workflow_dispatch"], "gate": "author", "currentSecrets": ["AUTOMATIONS_CLAUDE_API_KEY", "AUTOMATIONS_CLAUDE_CODE_OAUTH_TOKEN"] }
{ "id": "intake-triage", "workflow": "intake-triage.yml", "launcher": "run-claude-cli", "triggers": ["issues", "workflow_dispatch"], "gate": "author", "currentSecrets": ["AUTOMATIONS_CLAUDE_API_KEY", "AUTOMATIONS_CLAUDE_CODE_OAUTH_TOKEN"] },
{ "id": "refine-issue", "workflow": "intake-triage.yml", "launcher": "claude-code-action", "triggers": ["issues", "workflow_dispatch"], "gate": "author", "currentSecrets": ["AUTOMATIONS_CLAUDE_CODE_OAUTH_TOKEN"] }
]
},
{
Expand Down
48 changes: 40 additions & 8 deletions .github/scripts/intake-triage/admit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
// parent issue a listed human filed that awaits no decision;
// - 3: the class, Size and Uncertainty apply-verdict wrote are in `classes`,
// `sizes` and `uncertainty`;
// - 7: the body has a `task-list` line, the criteria the lane checks;
// - 7: the body, or a comment the lanes App's account posted opening with
// REFINE_MARKER (refine.mjs, which writes a task list only for an issue
// it made exact) after the body's last edit, has a `task-list` line, the
// criteria the lane checks;
// - 8: no `refuse-labels` label, every blocker a merged pull request or an
// issue closed as completed by a listed human or a merge here (the close
// work-unblock counts), and no open pull request in this repository names
Expand Down Expand Up @@ -47,6 +50,8 @@ import { isTrustedClose, paginate } from "../../actions/check-trusted-trigger/ch
export const AGENT_READY = "agent-ready";
export const DEFERRED = "admission-deferred";
export const ADMIT_MARKER = "<!-- intake-triage admission -->";
// Opens the lanes App's refinement comment (refine.mjs).
export const REFINE_MARKER = "<!-- intake-triage refinement -->";
const READY = "status: ready";
const NEEDS_DECISION = "status: needs-decision";
const LANES_APP_LOGIN = "melodic-automation-lanes[bot]";
Expand Down Expand Up @@ -196,7 +201,7 @@ export function admissionSettled(labels, events) {
}

// {verdict: admit | refuse | wait | skip, reasons}. Pure.
export function decide({ issue, verdict, rules, parent, blockers, trustedCloses, timeline, events, humans, appId, repository, webHosts }) {
export function decide({ issue, verdict, rules, parent, blockers, trustedCloses, timeline, events, comments = [], bodyEditedAt = null, humans, appId, repository, webHosts }) {
const labels = names(issue.labels);
if (!labels.includes(READY)) {
return { verdict: "skip", reasons: [`no ${READY}`] };
Expand Down Expand Up @@ -230,11 +235,17 @@ export function decide({ issue, verdict, rules, parent, blockers, trustedCloses,
if (!rules.uncertainty.includes(verdict.dimensions?.uncertainty)) {
refuse.push(`Uncertainty ${verdict.dimensions?.uncertainty} is not one of ${rules.uncertainty.join(", ")}`);
}
const lines = String(issue.body ?? "").split("\n");
// A refinement drafted before the body's last edit may not fit the body now.
const refinements = refinementsOf(comments, appId)
.filter((comment) => bodyEditedAt === null || Date.parse(comment.created_at) >= Date.parse(bodyEditedAt))
.map((comment) => String(comment.body));
const lines = [String(issue.body ?? ""), ...refinements].flatMap((text) => text.split("\n"));
if (!lines.some((line) => line.trimStart().startsWith(rules["task-list"]))) {
refuse.push(`it has no \`${rules["task-list"]}\` task list to check`);
}
const unrunnable = unrunnableReason(unrunnableCriteria(issue.body, rules["task-list"], webHosts));
// A refinement breaks `://` and `www.` with a zero-width space so no link
// renders; the check reads the URL as written.
const unrunnable = unrunnableReason(unrunnableCriteria(lines.join("\n").replaceAll("\u200b", ""), rules["task-list"], webHosts));
if (unrunnable) {
refuse.push(unrunnable);
}
Expand Down Expand Up @@ -281,9 +292,9 @@ async function parentOf(github, base) {
}

// One App comment carrying ADMIT_MARKER, edited in place on a later run.
async function sayWhy(github, repository, base, text) {
async function sayWhy(github, repository, base, comments, text) {
const body = `${ADMIT_MARKER}\n${text}`;
const own = (await paginate(github, `${base}/comments`)).find(
const own = comments.find(
(comment) => comment.user?.login === LANES_APP_LOGIN && String(comment.body ?? "").startsWith(ADMIT_MARKER),
);
if (own?.body === body) {
Expand All @@ -298,6 +309,23 @@ async function sayWhy(github, repository, base, text) {
}
}

const refinementsOf = (comments, appId) =>
comments.filter((comment) => appId !== undefined && comment?.user?.id === appId && String(comment.body ?? "").startsWith(REFINE_MARKER));

const BODY_EDIT_QUERY = `query($owner: String!, $name: String!, $number: Int!) {
repository(owner: $owner, name: $name) { issue(number: $number) { lastEditedAt } }
}`;

// When the issue's body was last edited, or null when never. An unexpected shape throws.
async function bodyEditedAtOf(github, repository, number) {
const [owner, name] = repository.split("/");
const issue = (await github("POST", "/graphql", { query: BODY_EDIT_QUERY, variables: { owner, name, number: Number(number) } }))?.data?.repository?.issue;
if (issue === null || typeof issue !== "object" || (issue.lastEditedAt !== null && typeof issue.lastEditedAt !== "string")) {
throw new Error("the issue's body edit time has an unexpected shape");
}
return issue.lastEditedAt;
}

// For an issue apply-verdict held without admission (a flag, an escalation or
// a hold), the same split note a refusal posts, when a done-when item is one
// the lane cannot perform, so the split survives a verdict that never reaches
Expand All @@ -314,7 +342,7 @@ export async function noteUnrunnable({ github, repository, issue, rules, webHost
log(`admit: #${issue.number} left as is (${settled})`);
return { outcome: "skipped", reasons: [settled] };
}
await sayWhy(github, repository, base, `Not admitted to the issue lane: ${reason}.`);
await sayWhy(github, repository, base, await paginate(github, `${base}/comments`), `Not admitted to the issue lane: ${reason}.`);
log(`admit: #${issue.number} held; split noted (${reason})`);
return { outcome: "noted", reasons: [reason] };
}
Expand All @@ -335,8 +363,11 @@ export async function admit({ github, repository, number, verdict, rules, humans
}
}
}
const comments = await paginate(github, `${base}/comments`);
const decision = decide({
issue,
comments,
bodyEditedAt: refinementsOf(comments, appId).length > 0 ? await bodyEditedAtOf(github, repository, number) : null,
verdict,
rules,
parent: rules["types-under-parent"].includes(issue.type?.name) ? await parentOf(github, base) : null,
Expand Down Expand Up @@ -367,6 +398,7 @@ export async function admit({ github, repository, number, verdict, rules, humans
github,
repository,
base,
comments,
`Not admitted to the issue lane: ${reasons}. A recorded decision does not change these rules (\`.github/actions/resolve-config/admission-rules.json\`); a person who wants it worked adds \`agent-ready\`.`,
);
log(`admit: #${number} refused (${reasons})`);
Expand All @@ -378,7 +410,7 @@ export async function admit({ github, repository, number, verdict, rules, humans
} else if (!names(issue.labels).includes(DEFERRED)) {
await github("POST", `${base}/labels`, { labels: [DEFERRED] });
}
await sayWhy(github, repository, base, `Not admitted to the issue lane yet: ${reasons}.`);
await sayWhy(github, repository, base, comments, `Not admitted to the issue lane yet: ${reasons}.`);
log(`admit: #${number} waits (${reasons})`);
return { outcome: "waiting", reasons: decision.reasons };
}
Expand Down
Loading
Loading