Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions bench/skills.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@
"words": 22
},
"reference.md": {
"sha256": "4c86b8a739b0d904f6ad19e684e4ff75c43a501d8722b0a6ef23f6135c99a8e9",
"lines": 54,
"words": 1011
"sha256": "d1ab37f4933b2eb45539e4c357d25bc37516a087f1438cdc2e1ed1f728072f6a",
"lines": 62,
"words": 1193
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion docs/PLAN.md

Large diffs are not rendered by default.

45 changes: 37 additions & 8 deletions plugin/scripts/lib/handoff.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ export function sanitize(text, { max = TEXT_MAX } = {}) {
return s;
}

/** One line of the review body for a judged entry: one line, sanitised, cut at 300 characters. */
const judgedLine = (a, splitPart) => {
const text = sanitize(`${a.entry}: ${a.met ? "met" : splitPart && a.deferred ? "deferred to a later part" : "not met"}${a.evidence ? ` (${a.evidence})` : ""}`).replace(/\s+/g, " ").trim();
/**
* One line of the review body for a judged entry: one line, sanitised, cut at 300 characters. `by`: the maintainer's
* decision that assigns a not-met entry elsewhere (reviewPost), named by its author and link; `open`: its finding is
* already open on the PR.
*/
const judgedLine = (a, { splitPart = false, by = null, open = false } = {}) => {
const how = a.met ? "met" : by ? `not met; assigned by ${by.author}'s decision${by.url ? ` ${by.url}` : ""}` : splitPart && a.deferred ? "deferred to a later part" : open ? "not met; its finding is already open on this PR" : "not met";
const text = sanitize(`${a.entry}: ${how}${a.evidence ? ` (${a.evidence})` : ""}`).replace(/\s+/g, " ").trim();
return `- ${text.length > 300 ? `${text.slice(0, 299)}…` : text}`;
};

Expand Down Expand Up @@ -145,7 +150,13 @@ export function noReviewReason(recs, reviewOf) {
* and the reviewer's judgment of each acceptance entry, one line each) and the line comments, sanitised and fitted to the
* diff. An entry judged not met with no comment of its own (its `entry`, or an "acceptance X:" body prefix) gets one at
* the judgment's path and line, so the answer pass handles it, except, on a split part that leaves work for the next
* (`splitPart`), one judged `deferred` (a later part delivers it), which the body lists as such; an entry of the issue (acceptanceEntries) the reviewer
* (`splitPart`), one judged `deferred` (a later part delivers it), which the body lists as such. Two more get none:
* an entry judged `"met": false, "decision": "<key>"`, where the key is exactly the key of one of `decisions` (the
* stage's trusted decisions: session.mjs objectiveDecisions, authors with write access; an exact lookup, so no text in
* the answer, the PR or a comment can supply one), which the body lists as assigned by that decision, with its author
* and link, and which stays not met; any other key is a plain not met. And an entry whose finding is already open on
* the PR (`open`: Pendulum's own open findings there, session.mjs unaddressedReviewComments), which the answer pass
* takes from that thread. An entry of the issue (acceptanceEntries) the reviewer
* left unjudged is named in the body and returned in `unjudged`. With no comment at all, Pendulum's placeholder goes on
* the first line the diff shows, and `placeholder` is true: nothing to answer. The placeholder only ever stands for a
* pass that ran and answered: a failed call (`ok` false) or an answer with no reviewer JSON throws, so no caller can
Expand All @@ -155,7 +166,7 @@ export function noReviewReason(recs, reviewOf) {
* first pass was posted before the Objective was labelled a foundation one; it judges no entry. `since`: the head
* Pendulum's review covered when this pass read only the commits written after it (review.mjs, #350); the body says so.
*/
export function reviewPost({ issue, review, diff, entries = [], ok = true, splitPart = false, foundation = null, since = null }) {
export function reviewPost({ issue, review, diff, entries = [], ok = true, splitPart = false, foundation = null, since = null, decisions = [], open = [] }) {
if (!ok) throw new Error("no review to post: the reviewer call failed");
if (!review && !foundation) throw new Error("no review to post: no pass answered");
if (review?.parsed === false) throw new Error("no review to post: the reviewer's answer held no findings JSON");
Expand All @@ -166,8 +177,13 @@ export function reviewPost({ issue, review, diff, entries = [], ok = true, split
const raw = [...own(review?.comments), ...extra];
// Only the first pass's comments cover its not-met judgments: a foundation comment on the same entry is another finding.
const commented = new Set(own(review?.comments).map(commentEntry).filter(Boolean));
// On a split part that is not the last, an entry judged deferred (a later part delivers it) gets no comment.
const unmet = judged.filter((a) => !a.met && !(splitPart && a.deferred) && !commented.has(entryKey(a.entry))).map((a) => ({ path: a.path ?? undefined, line: a.line, body: `acceptance ${a.entry.replace(/^\s*acceptance\s+/i, "")}: not met.${a.evidence ? ` ${a.evidence}` : ""}` }));
// The trusted decision a not-met judgment names by its exact key, or null: only such a judgment is assigned elsewhere.
const byKey = new Map((decisions || []).filter((d) => typeof d?.key === "string").map((d) => [d.key, d]));
const assignedBy = (a) => (!a.met && typeof a.decision === "string" ? (byKey.get(a.decision) ?? null) : null);
const openEntries = new Set(own(open).map(commentEntry).filter(Boolean));
// No comment is added for an entry judged deferred on a split part that is not the last (a later part delivers it),
// for one a trusted decision assigns elsewhere, or for one whose finding is already open on the PR.
const unmet = judged.filter((a) => !a.met && !(splitPart && a.deferred) && !assignedBy(a) && !commented.has(entryKey(a.entry)) && !openEntries.has(entryKey(a.entry))).map((a) => ({ path: a.path ?? undefined, line: a.line, body: `acceptance ${a.entry.replace(/^\s*acceptance\s+/i, "")}: not met.${a.evidence ? ` ${a.evidence}` : ""}` }));
let comments = snapComments(
[...raw, ...unmet].map((c) => ({ path: c.path, line: c.line, body: typeof c.body === "string" ? sanitize(c.body) : c.body })),
diff,
Expand All @@ -194,7 +210,7 @@ export function reviewPost({ issue, review, diff, entries = [], ok = true, split
? [marker(issue, "review"), marker(issue, "foundation"), `Pendulum reviewer: one comment-only review of two passes${on}, ${comments.length} comment(s); the foundation pass ${checked} and raised ${extra.length}.`]
: [marker(issue, "review"), marker(issue, "foundation"), `Pendulum reviewer: the foundation pass, after this PR's first review (the Objective was labelled a foundation one since), ${comments.length} comment(s); it ${checked}.`];
if (review) {
lines.push("", judged.length ? "Acceptance as the reviewer judged it:" : "The reviewer judged no acceptance entry.", ...judged.slice(0, 60).map((a) => judgedLine(a, splitPart)));
lines.push("", judged.length ? "Acceptance as the reviewer judged it:" : "The reviewer judged no acceptance entry.", ...judged.slice(0, 60).map((a) => judgedLine(a, { splitPart, by: assignedBy(a), open: !a.met && !commented.has(entryKey(a.entry)) && openEntries.has(entryKey(a.entry)) })));
if (unjudged.length) lines.push("", `Not judged: ${unjudged.map((id) => sanitize(id)).join(", ")}.`);
}
return { body: lines.join("\n"), comments, placeholder, unjudged };
Expand Down Expand Up @@ -470,6 +486,17 @@ export function inFiles({ issue, issueTitle, issueBody, decisions = [], plan = n
return files;
}

/**
* $PENDULUM_IN for a reviewer call: the issue and every maintainer decision, uncut, each under its key (logic.mjs
* decisionsSection), so the decisions the reviewer's prompt cuts for length are there to read before it judges.
*/
export function reviewerIn({ issue, issueTitle, issueBody, decisions = [] }) {
return {
"issue.md": `# #${issue}: ${issueTitle || ""}\n\n${issueBody || "(no body)"}\n`,
"decisions.md": decisions.length ? `${decisionsSection(decisions, Infinity, { reviewer: true })}\n` : "No maintainer decisions recorded.\n",
};
}

/**
* The plan's record of the Objective text it was made from, on the plan comment's marker line after the marker:
* `sha256` of that title and body (objective-trust.mjs objectiveSha), `label`, the Objective's start time (the later
Expand Down Expand Up @@ -966,6 +993,8 @@ export async function openHandoff({ repo, issue, issueData, env, opts, outbox, b
if (n) prNumber = n;
},
render,
/** $PENDULUM_IN as a reviewer call reads it (reviewerIn): written from what this stage holds, with no read of GitHub. */
reviewer: () => writeIn(dirs, reviewerIn({ issue, issueTitle: issueData.title, issueBody: issueData.body, decisions }), env),
collect,
/**
* What names a fix pass's scope (outbox.mjs fence), as of the last render: the plan comment, and the issue and the
Expand Down
25 changes: 16 additions & 9 deletions plugin/scripts/lib/logic.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1843,14 +1843,15 @@ export function reviewOfValue(v) {
if (Array.isArray(v)) return { comments: v, acceptance: null, parsed: true };
if (!v || typeof v !== "object" || !(Array.isArray(v.comments) || Array.isArray(v.acceptance))) return { comments: [], acceptance: null, parsed: false };
const acceptance = Array.isArray(v.acceptance)
? v.acceptance.filter((a) => a && (typeof a.entry === "string" || typeof a.entry === "number") && typeof a.met === "boolean").map((a) => ({ entry: String(a.entry).trim(), met: a.met, path: typeof a.path === "string" ? a.path : null, line: Number.isInteger(a.line) ? a.line : null, evidence: typeof a.evidence === "string" ? a.evidence : "", ...(a.deferred === true ? { deferred: true } : {}) }))
? v.acceptance.filter((a) => a && (typeof a.entry === "string" || typeof a.entry === "number") && typeof a.met === "boolean").map((a) => ({ entry: String(a.entry).trim(), met: a.met, path: typeof a.path === "string" ? a.path : null, line: Number.isInteger(a.line) ? a.line : null, evidence: typeof a.evidence === "string" ? a.evidence : "", ...(a.deferred === true ? { deferred: true } : {}), ...(typeof a.decision === "string" && a.decision.trim() ? { decision: a.decision.trim() } : {}) }))
: null;
return { comments: Array.isArray(v.comments) ? v.comments : [], acceptance, parsed: true };
}

/**
* The reviewer's whole answer: `comments` (line-tied findings) and `acceptance` (one judgment per acceptance entry,
* {entry, met, path, line, evidence}; null when the answer has no such list), and `parsed`: whether any JSON answer was
* {entry, met, path, line, evidence}, with `deferred` or `decision`, a decision's key, where the answer gives one; null
* when the answer has no such list), and `parsed`: whether any JSON answer was
* found. From a fenced ```json block or a bare object.
*/
export function parseReview(text) {
Expand Down Expand Up @@ -2600,7 +2601,8 @@ export const answersComment = (rootLogin, reply) => personAnswer(reply) && login
/**
* Candidate decisions on an Objective: comments on its issue and PR by a person (never a bot, never a Pendulum marker
* comment), oldest first, each with its `kind` (`comment`, `review` or `line`, an inline comment on the diff) and `state`
* (a review's GitHub state, an inline comment's the state of the review it was posted in, else null). Who may decide is
* (a review's GitHub state, an inline comment's the state of the review it was posted in, else null) and `url` (its
* link on GitHub, where GitHub gives one). Who may decide is
* not read from author_association: an App's token sees an organization
* member whose membership is private as CONTRIBUTOR or NONE. objectiveDecisions checks each author's write access.
*/
Expand Down Expand Up @@ -2648,7 +2650,7 @@ export function maintainerDecisions(comments) {
return all
.filter((c) => c?.user?.type !== "Bot" && !(c.body || "").includes("<!-- pendulum:") && (c.body || "").trim() && !pendulumThread(c) && !(Date.parse(c.created_at) <= since))
.sort((a, b) => Date.parse(a.created_at) - Date.parse(b.created_at))
.map((c) => ({ author: c.user?.login ?? "?", authorId: c.user?.id ?? null, at: c.created_at, body: c.body.trim(), key: `${c.kind || "comment"}:${c.id}`, kind: c.kind || "comment", state: stateOf(c), seen: latest(c.created_at, c.updated_at), ...(c.on ? { on: c.on } : {}) }));
.map((c) => ({ author: c.user?.login ?? "?", authorId: c.user?.id ?? null, at: c.created_at, body: c.body.trim(), key: `${c.kind || "comment"}:${c.id}`, kind: c.kind || "comment", state: stateOf(c), seen: latest(c.created_at, c.updated_at), ...(c.on ? { on: c.on } : {}), ...(typeof c.html_url === "string" && c.html_url ? { url: c.html_url } : {}) }));
}
const REVIEW_BODY = /<!-- pendulum:\d+:review -->/;
const latest = (...times) => times.filter((t) => Number.isFinite(Date.parse(t))).sort((a, b) => Date.parse(a) - Date.parse(b)).at(-1) ?? null;
Expand Down Expand Up @@ -2743,7 +2745,7 @@ export function answerDuring({ unread = [], writers = new Set(), events = [], re
return answers.length && ready ? `${ready.actor.login} marked the PR ready and ${answers.length} maintainer decision(s) arrived during the review` : "";
}

const decisionText = (d) => `### ${d.author}, ${String(d.at).slice(0, 16).replace("T", " ")}Z\n\n${d.body}`;
const decisionText = (d, keyed = false) => `### ${d.author}, ${String(d.at).slice(0, 16).replace("T", " ")}Z${keyed && d.key ? ` (decision \`${d.key}\`)` : ""}\n\n${d.body}`;
/**
* The decisions that fit a prompt section: the newest whole ones within `cap` characters (the newest always), oldest
* first. Only these reach the model, so only these are recorded as read; the cut ones stay unread.
Expand All @@ -2758,13 +2760,18 @@ export function decisionsShown(decisions, cap = 12_000) {
}
return shown;
}
/** The decisions as a prompt section ("" when none), capped so a long thread cannot crowd out the task. */
export function decisionsSection(decisions, cap = 12_000) {
/**
* The decisions as a prompt section ("" when none), capped so a long thread cannot crowd out the task. `reviewer`: the
* section as the reviewer reads it (review.mjs reviewerPrompt, handoff.mjs reviewerIn): each decision's heading carries
* its key, which an acceptance judgment names when that decision assigns the entry elsewhere (handoff.mjs reviewPost),
* and the cut note tells it to read the rest before it judges.
*/
export function decisionsSection(decisions, cap = 12_000, { reviewer = false } = {}) {
if (!decisions?.length) return "";
const shown = decisionsShown(decisions, cap);
const cut = decisions.length - shown.length;
const note = cut ? `${cut} earlier decision(s) are not shown here for length; read them all in \`$PENDULUM_IN/decisions.md\` before you change anything.\n\n` : "";
return `## Decisions recorded by maintainers (comments on the issue and PR, oldest first)\n\nWhere one answers a question or differs from the issue body, it wins: it is the owner's later word.\n\n${note}${shown.map(decisionText).join("\n\n")}`;
const note = cut ? `${cut} earlier decision(s) are not shown here for length; read them all in \`$PENDULUM_IN/decisions.md\` before you ${reviewer ? "judge" : "change anything"}.\n\n` : "";
return `## Decisions recorded by maintainers (comments on the issue and PR, oldest first)\n\nWhere one answers a question or differs from the issue body, it wins: it is the owner's later word.\n\n${note}${shown.map((d) => decisionText(d, reviewer)).join("\n\n")}`;
}

/**
Expand Down
Loading