agent-dealer 1.4.2 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/server/dist/adapters/github.js +66 -3
- package/bundle/server/dist/adapters/github.test.js +90 -0
- package/bundle/server/dist/coordinator/auto-merge.js +17 -6
- package/bundle/server/dist/coordinator/commands.js +18 -2
- package/bundle/server/dist/coordinator/developer-effect.js +46 -5
- package/bundle/server/dist/coordinator/developer-effect.test.js +118 -4
- package/bundle/server/dist/coordinator/operator-criteria.js +250 -17
- package/bundle/server/dist/coordinator/operator-criteria.test.js +177 -4
- package/bundle/server/dist/coordinator/operator-verification.integration.test.js +208 -0
- package/bundle/server/dist/coordinator/projection.js +5 -1
- package/bundle/server/dist/coordinator/prompts.js +77 -4
- package/bundle/server/dist/coordinator/prompts.test.js +22 -4
- package/bundle/server/dist/coordinator/reviewer-effect.js +64 -45
- package/bundle/server/dist/coordinator/reviewer-effect.test.js +63 -10
- package/bundle/server/dist/coordinator/reviewer-pr-evidence.test.js +245 -0
- package/bundle/server/dist/coordinator/reviewer-result.js +4 -3
- package/bundle/server/dist/coordinator/reviewer-result.test.js +6 -0
- package/bundle/server/dist/coordinator/routing.js +3 -0
- package/bundle/server/dist/coordinator/routing.test.js +19 -0
- package/bundle/server/dist/docs-api-reference.test.js +89 -0
- package/bundle/server/package.json +2 -2
- package/bundle/shared/package.json +1 -1
- package/package.json +1 -1
|
@@ -29,6 +29,17 @@ export const PR_VIEW_FIELDS = "number,url,baseRefName,headRefName,headRefOid,isD
|
|
|
29
29
|
export function parsePrMergeableState(raw) {
|
|
30
30
|
return raw === "CONFLICTING" || raw === "MERGEABLE" ? raw : "UNKNOWN";
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* NOT-575: normalizes `gh pr view --json body` output — the body text, or
|
|
34
|
+
* null when absent, non-string, or blank. Callers treat null as "unavailable",
|
|
35
|
+
* never as evidence of anything.
|
|
36
|
+
*/
|
|
37
|
+
export function parsePrBody(raw) {
|
|
38
|
+
if (typeof raw !== "string")
|
|
39
|
+
return null;
|
|
40
|
+
const trimmed = raw.trim();
|
|
41
|
+
return trimmed ? raw : null;
|
|
42
|
+
}
|
|
32
43
|
const FAILURE_STATES = new Set([
|
|
33
44
|
"failure",
|
|
34
45
|
"error",
|
|
@@ -41,10 +52,55 @@ const FAILURE_STATES = new Set([
|
|
|
41
52
|
const PENDING_STATES = new Set(["pending", "queued", "in_progress", "expected", "waiting", "requested"]);
|
|
42
53
|
/** Every terminal-and-genuinely-ok conclusion `gh` can report — anything else fails closed. */
|
|
43
54
|
const SUCCESS_STATES = new Set(["success", "neutral", "skipped"]);
|
|
55
|
+
function checkIdentity(check) {
|
|
56
|
+
if (typeof check.context === "string" && check.context) {
|
|
57
|
+
return JSON.stringify(["status", check.context]);
|
|
58
|
+
}
|
|
59
|
+
if (typeof check.name === "string" && check.name) {
|
|
60
|
+
return JSON.stringify(["check", check.workflowName ?? "", check.name]);
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
function checkTime(check) {
|
|
65
|
+
const candidates = check.context
|
|
66
|
+
? [check.startedAt, check.createdAt]
|
|
67
|
+
: [check.startedAt, check.completedAt];
|
|
68
|
+
for (const candidate of candidates) {
|
|
69
|
+
if (typeof candidate !== "string" || !candidate)
|
|
70
|
+
continue;
|
|
71
|
+
const time = Date.parse(candidate);
|
|
72
|
+
if (Number.isFinite(time))
|
|
73
|
+
return time;
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* GitHub keeps earlier attempts in the rollup when a check runs again on the same
|
|
79
|
+
* commit. Drop superseded timed entries by the provider's check identity. Untimed
|
|
80
|
+
* entries remain untouched because their relative age cannot be established safely.
|
|
81
|
+
*/
|
|
82
|
+
function newestChecks(rollup) {
|
|
83
|
+
const newestIndexByIdentity = new Map();
|
|
84
|
+
for (const [index, check] of rollup.entries()) {
|
|
85
|
+
const identity = checkIdentity(check);
|
|
86
|
+
const time = checkTime(check);
|
|
87
|
+
if (identity == null || time == null)
|
|
88
|
+
continue;
|
|
89
|
+
const current = newestIndexByIdentity.get(identity);
|
|
90
|
+
if (current == null || time >= current.time)
|
|
91
|
+
newestIndexByIdentity.set(identity, { index, time });
|
|
92
|
+
}
|
|
93
|
+
return rollup.filter((check, index) => {
|
|
94
|
+
const identity = checkIdentity(check);
|
|
95
|
+
const time = checkTime(check);
|
|
96
|
+
return identity == null || time == null || newestIndexByIdentity.get(identity)?.index === index;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
44
99
|
export function summarizeChecks(rollup) {
|
|
45
|
-
|
|
100
|
+
const currentChecks = newestChecks(rollup);
|
|
101
|
+
if (currentChecks.length === 0)
|
|
46
102
|
return "none";
|
|
47
|
-
const states =
|
|
103
|
+
const states = currentChecks.map((c) => (c.conclusion || c.state || c.status || "").toLowerCase());
|
|
48
104
|
if (states.some((s) => FAILURE_STATES.has(s)))
|
|
49
105
|
return "failure";
|
|
50
106
|
if (states.some((s) => PENDING_STATES.has(s)))
|
|
@@ -390,6 +446,9 @@ export function createGithubAdapter(exec = defaultExec) {
|
|
|
390
446
|
return { ok: false, reason: message, noCommits: NO_COMMITS_PATTERN.test(message) };
|
|
391
447
|
}
|
|
392
448
|
},
|
|
449
|
+
async updatePrBody({ cwd, number, bodyFilePath }) {
|
|
450
|
+
await exec(["pr", "edit", String(number), "--body-file", bodyFilePath], { cwd });
|
|
451
|
+
},
|
|
393
452
|
async checksSnapshot({ cwd, number, branch }) {
|
|
394
453
|
const selector = number != null ? String(number) : branch;
|
|
395
454
|
const raw = await ghPrView(exec, cwd, "statusCheckRollup", selector);
|
|
@@ -422,6 +481,10 @@ export function createGithubAdapter(exec = defaultExec) {
|
|
|
422
481
|
return "UNKNOWN";
|
|
423
482
|
}
|
|
424
483
|
},
|
|
484
|
+
async prBody({ cwd, number }) {
|
|
485
|
+
const raw = await ghPrView(exec, cwd, "body", String(number));
|
|
486
|
+
return parsePrBody(raw?.body);
|
|
487
|
+
},
|
|
425
488
|
async listWorkflowRunsForCommit({ cwd, workflow, commitSha }) {
|
|
426
489
|
try {
|
|
427
490
|
const { stdout } = await exec([
|
|
@@ -497,7 +560,7 @@ export async function fetchChecksFailureEvidence(exec, opts) {
|
|
|
497
560
|
// Never attach another commit's failure: the head must still be the verified one.
|
|
498
561
|
if (!headSha || headSha !== opts.expectedHeadSha)
|
|
499
562
|
return null;
|
|
500
|
-
const rollup = raw.statusCheckRollup ?? [];
|
|
563
|
+
const rollup = newestChecks(raw.statusCheckRollup ?? []);
|
|
501
564
|
const failed = rollup.filter((c) => isFailedCheckState(rawCheckState(c)));
|
|
502
565
|
if (failed.length === 0)
|
|
503
566
|
return null;
|
|
@@ -31,6 +31,66 @@ test("summarizeChecks accepts neutral/skipped as success but fails closed on an
|
|
|
31
31
|
assert.equal(summarizeChecks([{ conclusion: "neutral" }, { conclusion: "skipped" }]), "success");
|
|
32
32
|
assert.equal(summarizeChecks([{ conclusion: "some_new_gh_conclusion_this_code_does_not_know" }]), "failure");
|
|
33
33
|
});
|
|
34
|
+
test("summarizeChecks uses the newest run of the same workflow check", () => {
|
|
35
|
+
const failedRun = {
|
|
36
|
+
name: "PR body",
|
|
37
|
+
workflowName: "CI",
|
|
38
|
+
status: "COMPLETED",
|
|
39
|
+
conclusion: "FAILURE",
|
|
40
|
+
startedAt: "2026-11-15T18:00:00Z",
|
|
41
|
+
completedAt: "2026-11-15T18:01:00Z",
|
|
42
|
+
};
|
|
43
|
+
const successfulRerun = {
|
|
44
|
+
name: "PR body",
|
|
45
|
+
workflowName: "CI",
|
|
46
|
+
status: "COMPLETED",
|
|
47
|
+
conclusion: "SUCCESS",
|
|
48
|
+
startedAt: "2026-11-15T18:02:00Z",
|
|
49
|
+
completedAt: "2026-11-15T18:03:00Z",
|
|
50
|
+
};
|
|
51
|
+
assert.equal(summarizeChecks([failedRun, successfulRerun]), "success");
|
|
52
|
+
assert.equal(summarizeChecks([successfulRerun, { ...failedRun, startedAt: "2026-11-15T18:04:00Z" }]), "failure");
|
|
53
|
+
});
|
|
54
|
+
test("summarizeChecks keeps checks from different workflows and jobs separate", () => {
|
|
55
|
+
assert.equal(summarizeChecks([
|
|
56
|
+
{
|
|
57
|
+
name: "build",
|
|
58
|
+
workflowName: "CI",
|
|
59
|
+
status: "COMPLETED",
|
|
60
|
+
conclusion: "FAILURE",
|
|
61
|
+
startedAt: "2026-11-15T18:00:00Z",
|
|
62
|
+
completedAt: "2026-11-15T18:01:00Z",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: "build",
|
|
66
|
+
workflowName: "Release",
|
|
67
|
+
status: "COMPLETED",
|
|
68
|
+
conclusion: "SUCCESS",
|
|
69
|
+
startedAt: "2026-11-15T18:02:00Z",
|
|
70
|
+
completedAt: "2026-11-15T18:03:00Z",
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: "lint",
|
|
74
|
+
workflowName: "CI",
|
|
75
|
+
status: "COMPLETED",
|
|
76
|
+
conclusion: "SUCCESS",
|
|
77
|
+
startedAt: "2026-11-15T18:02:00Z",
|
|
78
|
+
completedAt: "2026-11-15T18:03:00Z",
|
|
79
|
+
},
|
|
80
|
+
]), "failure");
|
|
81
|
+
});
|
|
82
|
+
test("summarizeChecks uses the newest status context", () => {
|
|
83
|
+
assert.equal(summarizeChecks([
|
|
84
|
+
{ context: "ci/external", state: "FAILURE", startedAt: "2026-11-15T18:00:00Z" },
|
|
85
|
+
{ context: "ci/external", state: "SUCCESS", createdAt: "2026-11-15T18:02:00Z" },
|
|
86
|
+
]), "success");
|
|
87
|
+
});
|
|
88
|
+
test("summarizeChecks preserves same-identity entries when their run times are unavailable", () => {
|
|
89
|
+
assert.equal(summarizeChecks([
|
|
90
|
+
{ name: "build", workflowName: "CI", status: "COMPLETED", conclusion: "FAILURE" },
|
|
91
|
+
{ name: "build", workflowName: "CI", status: "COMPLETED", conclusion: "SUCCESS" },
|
|
92
|
+
]), "failure");
|
|
93
|
+
});
|
|
34
94
|
/** Records every `gh` invocation and returns responses off a queue — never calls real `gh`. */
|
|
35
95
|
function queuedExec(responses) {
|
|
36
96
|
const calls = [];
|
|
@@ -77,6 +137,11 @@ test("createDraftPr passes --head explicitly and re-verifies by that same branch
|
|
|
77
137
|
assert.deepEqual(calls[1], ["pr", "view", "issue-x", "--json", "number,url"]);
|
|
78
138
|
assert.deepEqual(result, { ok: true, number: 9, url: "https://github.com/o/r/pull/9" });
|
|
79
139
|
});
|
|
140
|
+
test("updatePrBody replaces the PR body from the provided file", async () => {
|
|
141
|
+
const { exec, calls } = queuedExec([{ stdout: "" }]);
|
|
142
|
+
await createGithubAdapter(exec).updatePrBody({ cwd: "/repo", number: 17, bodyFilePath: "/tmp/body.md" });
|
|
143
|
+
assert.deepEqual(calls[0], ["pr", "edit", "17", "--body-file", "/tmp/body.md"]);
|
|
144
|
+
});
|
|
80
145
|
// NOT-82 dogfood repro: a real Dev-review run pushed its generated branch to origin, but
|
|
81
146
|
// the local worktree had no configured upstream — `gh pr create` (bare, no `--head`)
|
|
82
147
|
// refused with exactly this error, and the coordinator must never hit it.
|
|
@@ -400,6 +465,31 @@ test("NOT-252: no failed checks yields no enrichment", async () => {
|
|
|
400
465
|
assert.equal(await fetchChecksFailureEvidence(exec, { cwd: "/repo", number: 42, expectedHeadSha: HEAD_SHA }), null);
|
|
401
466
|
assert.ok(calls.every((c) => c[0] === "pr"), "no log fetch without a failure");
|
|
402
467
|
});
|
|
468
|
+
test("NOT-629: failure evidence excludes a stale failed run after a successful rerun", async () => {
|
|
469
|
+
const { exec, calls } = queuedExec([
|
|
470
|
+
{
|
|
471
|
+
stdout: prViewWithRollup([
|
|
472
|
+
actionsCheck("build", "FAILURE", "111", {
|
|
473
|
+
startedAt: "2026-11-15T18:00:00Z",
|
|
474
|
+
completedAt: "2026-11-15T18:01:00Z",
|
|
475
|
+
}),
|
|
476
|
+
actionsCheck("build", "SUCCESS", "222", {
|
|
477
|
+
startedAt: "2026-11-15T18:02:00Z",
|
|
478
|
+
completedAt: "2026-11-15T18:03:00Z",
|
|
479
|
+
}),
|
|
480
|
+
actionsCheck("lint", "FAILURE", "333", {
|
|
481
|
+
startedAt: "2026-11-15T18:02:00Z",
|
|
482
|
+
completedAt: "2026-11-15T18:03:00Z",
|
|
483
|
+
}),
|
|
484
|
+
]),
|
|
485
|
+
},
|
|
486
|
+
{ stdout: "lint failed\nError: nit\n" },
|
|
487
|
+
]);
|
|
488
|
+
const evidence = await fetchChecksFailureEvidence(exec, { cwd: "/repo", number: 42, expectedHeadSha: HEAD_SHA });
|
|
489
|
+
assert.ok(evidence);
|
|
490
|
+
assert.deepEqual(evidence.failedChecks.map((check) => check.name), ["lint"]);
|
|
491
|
+
assert.deepEqual(calls.filter((call) => call[0] === "run"), [["run", "view", "333", "--log-failed"]]);
|
|
492
|
+
});
|
|
403
493
|
test("NOT-252: noisy log focuses the excerpt on the actionable E404 lines", async () => {
|
|
404
494
|
const setup = Array.from({ length: 200 }, (_, i) => `setup step ${i}: downloading dependency cache chunk ${i}`).join("\n");
|
|
405
495
|
const tail = Array.from({ length: 100 }, (_, i) => `cleanup temp dir ${i}`).join("\n");
|
|
@@ -33,7 +33,7 @@ import { isMergeConflictFailure, runMergeConflictSync } from "./merge-conflict-s
|
|
|
33
33
|
import { triggerLinearPostMerge } from "./linear-merge-verify.js";
|
|
34
34
|
import { startBaseAdvancedScan } from "./base-advanced-scan.js";
|
|
35
35
|
import { runHeldWork } from "../power/host-awake-lifecycle.js";
|
|
36
|
-
import { OPERATOR_VERIFICATION_RESPONSE_OPTIONS, formatOperatorCriteria, getOperatorCriteriaForIssue, hasOperatorVerificationForHead, operatorVerificationRequestId, } from "./operator-criteria.js";
|
|
36
|
+
import { OPERATOR_VERIFICATION_RESPONSE_OPTIONS, formatOperatorCriteria, getOperatorCriteriaForIssue, hasOperatorVerificationForHead, missingOperatorCriteriaForHead, operatorVerificationRequestId, } from "./operator-criteria.js";
|
|
37
37
|
import { readVisualEvidenceHold } from "./reviewer-visual-evidence.js";
|
|
38
38
|
const run = promisify(execFile);
|
|
39
39
|
/** Bound each `gh` shell-out so a hang cannot freeze the coordinator process. */
|
|
@@ -360,10 +360,17 @@ function formatVisualHold(hold) {
|
|
|
360
360
|
* (criteria and visual items together), so one recorded result releases it;
|
|
361
361
|
* no repair round is ever queued for missing evidence alone.
|
|
362
362
|
*
|
|
363
|
+
* NOT-575: each trailing-`[operator]` criterion needs a recorded result for
|
|
364
|
+
* that exact criterion on the exact head SHA — a result recorded for one
|
|
365
|
+
* criterion never releases another. The visual hold (no criterion list) still
|
|
366
|
+
* releases on any recorded result for the head, so a combined action's one
|
|
367
|
+
* resolve — which covers the gated criteria and counts as a head result —
|
|
368
|
+
* still releases the whole head.
|
|
369
|
+
*
|
|
363
370
|
* Returns null when the merge may proceed (no operator criteria, no visual
|
|
364
|
-
* hold, a recorded result for this head, or no
|
|
365
|
-
* a second finalize for the same head reuses
|
|
366
|
-
* raising another.
|
|
371
|
+
* hold, a recorded result for this head covering every criterion, or no
|
|
372
|
+
* workflow to gate). Idempotent: a second finalize for the same head reuses
|
|
373
|
+
* the open action instead of raising another.
|
|
367
374
|
*
|
|
368
375
|
* Fail-closed: when operator criteria exist, every non-proceed path returns a
|
|
369
376
|
* result (never null), so a missing head SHA or an unexpected status blocks the
|
|
@@ -382,8 +389,12 @@ export function gateOperatorVerification(issueId) {
|
|
|
382
389
|
const visualHold = head ? readVisualEvidenceHold(issueId, head) : null;
|
|
383
390
|
if (criteria.length === 0 && !visualHold)
|
|
384
391
|
return null;
|
|
385
|
-
if (head
|
|
386
|
-
|
|
392
|
+
if (head) {
|
|
393
|
+
const criteriaCovered = missingOperatorCriteriaForHead(issueId, head, criteria).length === 0;
|
|
394
|
+
const visualCovered = !visualHold || hasOperatorVerificationForHead(issueId, head);
|
|
395
|
+
if (criteriaCovered && visualCovered)
|
|
396
|
+
return null;
|
|
397
|
+
}
|
|
387
398
|
if (current.status === "done")
|
|
388
399
|
return null;
|
|
389
400
|
// Only the auto-merge park (or an already-gated issue) is gated — any other
|
|
@@ -35,7 +35,7 @@ import { AUTH_TRANSIENT_RETRY_PAYLOAD_KEY, RUNTIME_AUTH_PARK_EVIDENCE_KEY, authP
|
|
|
35
35
|
import { AUTO_MERGE_INTENT, OPERATOR_VERIFICATION_INTENT, finalizeAutoMerge } from "./auto-merge.js";
|
|
36
36
|
import { triggerLinearPostMerge } from "./linear-merge-verify.js";
|
|
37
37
|
import { conflictRepairSpent, queueConflictRepairRound } from "./merge-conflict-sync.js";
|
|
38
|
-
import { OPERATOR_VERIFICATION_ARTIFACT_KIND, OPERATOR_VERIFICATION_RESPONSE_OPTIONS, } from "./operator-criteria.js";
|
|
38
|
+
import { OPERATOR_VERIFICATION_ARTIFACT_KIND, OPERATOR_VERIFICATION_RESPONSE_OPTIONS, criteriaTextsFromActionEvidence, getOperatorCriteriaForIssue, } from "./operator-criteria.js";
|
|
39
39
|
import { externalMergeStateForIssue } from "./external-merge.js";
|
|
40
40
|
import { detectNonConvergence, formatNonConvergenceReason, reviewHistoryFromEvents, } from "./non-convergence.js";
|
|
41
41
|
import { capEscalationEvents, checksWaitDeferralStartedAt, deferLeasedWorkItemForBaseFetch, deferLeasedWorkItemForChecksPending, deferLeasedWorkItemForDeckOutage, deferLeasedWorkItemForUsageCap, formatCapEscalationReason, formatChecksWaitEscalationReason, usageCapDeferralStartedAt, } from "./usage-cap-defer.js";
|
|
@@ -1318,7 +1318,13 @@ function applyReviewer(issue, instance, item, outcome, authFailure) {
|
|
|
1318
1318
|
}
|
|
1319
1319
|
const hasVerdict = outcome.kind === "verdict";
|
|
1320
1320
|
// Normalize before emit/finding reconcile so remapped blocking findings (NOT-150) persist.
|
|
1321
|
-
|
|
1321
|
+
// A truncated review routed directly to an operator preserves the reviewer's own result;
|
|
1322
|
+
// in particular, a bare escalate must not acquire normalizeReviewer's synthetic repair finding.
|
|
1323
|
+
const verdictResult = outcome.kind === "verdict"
|
|
1324
|
+
? outcome.finalReviewReason
|
|
1325
|
+
? outcome.result
|
|
1326
|
+
: normalizeReviewerResult(outcome.result)
|
|
1327
|
+
: null;
|
|
1322
1328
|
const { projection, effect, advance } = projectReviewerRoute(route, issue.currentRound, hasVerdict);
|
|
1323
1329
|
const ev = eventEmitter(issue, instance, item.workerSessionId, projection.issueStatus, issue.currentRound);
|
|
1324
1330
|
const patch = {};
|
|
@@ -1944,6 +1950,14 @@ export function resolveHumanActionAndAdvance(actionId, resolvedBy, choice, opts)
|
|
|
1944
1950
|
// re-checks the record against the then-current head, so new commits
|
|
1945
1951
|
// re-block the gate.
|
|
1946
1952
|
if (resolution.actionType === "operator_verification" && operatorNote) {
|
|
1953
|
+
// NOT-575: the result covers exactly the criteria the gated action
|
|
1954
|
+
// listed (read off the action's own stored evidence — never
|
|
1955
|
+
// re-derived, so the coverage is provably the gated set). A result
|
|
1956
|
+
// for one criterion never releases another; the fallback recomputes
|
|
1957
|
+
// from the frozen snapshot for actions raised before that evidence
|
|
1958
|
+
// shape existed.
|
|
1959
|
+
const coveredCriteria = criteriaTextsFromActionEvidence(action) ??
|
|
1960
|
+
getOperatorCriteriaForIssue(issue).map((c) => c.text);
|
|
1947
1961
|
if (resolution.choice === "verified") {
|
|
1948
1962
|
createIssueArtifact({
|
|
1949
1963
|
issueId: issue.id,
|
|
@@ -1954,6 +1968,7 @@ export function resolveHumanActionAndAdvance(actionId, resolvedBy, choice, opts)
|
|
|
1954
1968
|
note: operatorNote,
|
|
1955
1969
|
verifiedBy: resolvedBy,
|
|
1956
1970
|
verifiedAt: new Date().toISOString(),
|
|
1971
|
+
criteria: coveredCriteria,
|
|
1957
1972
|
},
|
|
1958
1973
|
});
|
|
1959
1974
|
}
|
|
@@ -1972,6 +1987,7 @@ export function resolveHumanActionAndAdvance(actionId, resolvedBy, choice, opts)
|
|
|
1972
1987
|
headSha: issue.headSha,
|
|
1973
1988
|
waivedBy: resolvedBy,
|
|
1974
1989
|
note: operatorNote,
|
|
1990
|
+
criteria: coveredCriteria,
|
|
1975
1991
|
},
|
|
1976
1992
|
});
|
|
1977
1993
|
}
|
|
@@ -20,7 +20,7 @@ import { parsePhaseBudget, parseProfileSnapshot, roleCeiling } from "@agent-deal
|
|
|
20
20
|
import { CONFLICTING_FILES_MAX, runMergeConflictSync } from "./merge-conflict-sync.js";
|
|
21
21
|
import { getTaskSnapshot } from "./commands.js";
|
|
22
22
|
import { materializeSourceAttachments, SourceAttachmentError, } from "./source-attachments.js";
|
|
23
|
-
import {
|
|
23
|
+
import { operatorCriteriaForSnapshot } from "./operator-criteria.js";
|
|
24
24
|
import { buildDeveloperPrompt } from "./prompts.js";
|
|
25
25
|
import { VISUAL_QA_EXCLUDE_LINE, collectDeveloperVisualQa } from "./visual-qa.js";
|
|
26
26
|
import { ensureWorktreeExcluded } from "../adapters/worktree-exclude.js";
|
|
@@ -161,6 +161,31 @@ function extractConclusion(transcript) {
|
|
|
161
161
|
return "";
|
|
162
162
|
return trimmed.length > 4000 ? trimmed.slice(-4000) : trimmed;
|
|
163
163
|
}
|
|
164
|
+
/** Full contents of the last valid four-backtick `pr-description` block. */
|
|
165
|
+
export function extractPrDescription(transcript) {
|
|
166
|
+
const blocks = transcript.matchAll(/^````pr-description[ \t]*\r?\n([\s\S]*?)^````[ \t]*(?:\r?\n|$)/gm);
|
|
167
|
+
let last = null;
|
|
168
|
+
for (const block of blocks)
|
|
169
|
+
last = (block[1] ?? "").replace(/\r?\n$/, "");
|
|
170
|
+
return last?.trim() ? last : null;
|
|
171
|
+
}
|
|
172
|
+
/** A body refresh must never turn completed developer work into a failed round. */
|
|
173
|
+
async function bestEffortUpdatePrBody(opts) {
|
|
174
|
+
if (!opts.github.updatePrBody)
|
|
175
|
+
return;
|
|
176
|
+
const bodyDir = fs.mkdtempSync(path.join(os.tmpdir(), "dealer-pr-body-"));
|
|
177
|
+
const bodyFilePath = path.join(bodyDir, "body.md");
|
|
178
|
+
try {
|
|
179
|
+
fs.writeFileSync(bodyFilePath, opts.body);
|
|
180
|
+
await opts.github.updatePrBody({ cwd: opts.cwd, number: opts.number, bodyFilePath });
|
|
181
|
+
}
|
|
182
|
+
catch (err) {
|
|
183
|
+
console.warn(`[dealer] PR body update failed for ${opts.issueId} (#${opts.number}): ${String(err)}`);
|
|
184
|
+
}
|
|
185
|
+
finally {
|
|
186
|
+
fs.rmSync(bodyDir, { recursive: true, force: true });
|
|
187
|
+
}
|
|
188
|
+
}
|
|
164
189
|
/** NOT-130: mine + persist a SHA-scoped suite receipt while the worktree still exists.
|
|
165
190
|
* Tip-tree equivalence: only vouch for HEAD when the tree is clean — a green suite on a
|
|
166
191
|
* dirty checkout must not be reloaded as tip evidence after a later clean/revert.
|
|
@@ -707,8 +732,12 @@ async function runPublishOnlyHandoff(ctx, deps, branchName) {
|
|
|
707
732
|
if (prior?.contentJson) {
|
|
708
733
|
try {
|
|
709
734
|
const parsed = JSON.parse(prior.contentJson);
|
|
710
|
-
if (typeof parsed.
|
|
735
|
+
if (typeof parsed.prDescription === "string" && parsed.prDescription.trim()) {
|
|
736
|
+
body = parsed.prDescription;
|
|
737
|
+
}
|
|
738
|
+
else if (typeof parsed.text === "string" && parsed.text.trim()) {
|
|
711
739
|
body = parsed.text.trim();
|
|
740
|
+
}
|
|
712
741
|
}
|
|
713
742
|
catch {
|
|
714
743
|
// keep description
|
|
@@ -1216,7 +1245,8 @@ export async function runDeveloperEffect(ctx, deps = defaultDeps) {
|
|
|
1216
1245
|
: undefined;
|
|
1217
1246
|
// NOT-314: the frozen snapshot's operator criteria, parsed here so the
|
|
1218
1247
|
// worker never re-derives them — the section renders only when non-empty.
|
|
1219
|
-
|
|
1248
|
+
// NOT-575: the same union the gate uses (AC text + structured contract).
|
|
1249
|
+
const operatorCriteria = operatorCriteriaForSnapshot(taskSnapshot);
|
|
1220
1250
|
const hasOperatorCriteria = operatorCriteria.length > 0 ? operatorCriteria : undefined;
|
|
1221
1251
|
// NOT-310: the conflict directive rides only the work item queued by the merge
|
|
1222
1252
|
// path — exactly this round reads it; nothing is re-read from the DB. Shaped
|
|
@@ -1772,12 +1802,13 @@ export async function runDeveloperEffect(ctx, deps = defaultDeps) {
|
|
|
1772
1802
|
// dropped on any later verification failure (checks failing, a gh error), even though
|
|
1773
1803
|
// NOT-61 requires the conclusion/raw trace to stay available through the evidence API
|
|
1774
1804
|
// regardless of how the handoff subsequently resolves.
|
|
1805
|
+
const prDescription = extractPrDescription(spawned.transcript);
|
|
1775
1806
|
createIssueArtifact({
|
|
1776
1807
|
issueId: issue.id,
|
|
1777
1808
|
workerSessionId: sessionId,
|
|
1778
1809
|
kind: "implementation_conclusion",
|
|
1779
1810
|
author: "agent",
|
|
1780
|
-
content: { text: extractConclusion(spawned.transcript) },
|
|
1811
|
+
content: { text: extractConclusion(spawned.transcript), prDescription },
|
|
1781
1812
|
});
|
|
1782
1813
|
createIssueArtifact({
|
|
1783
1814
|
issueId: issue.id,
|
|
@@ -1908,11 +1939,12 @@ export async function runDeveloperEffect(ctx, deps = defaultDeps) {
|
|
|
1908
1939
|
// rather than asking `gh` to infer "the current branch" from upstream tracking, which
|
|
1909
1940
|
// pushBranch's push does not reliably leave configured (NOT-82).
|
|
1910
1941
|
let prView = await deps.github.viewPr({ cwd: worktreePath, branch: branchName });
|
|
1942
|
+
const prAlreadyExisted = prView !== null;
|
|
1911
1943
|
if (!prView) {
|
|
1912
1944
|
setLiveIntent(issue.id, `Developer · opening draft PR (round ${round})`);
|
|
1913
1945
|
const bodyDir = fs.mkdtempSync(path.join(os.tmpdir(), "dealer-pr-body-"));
|
|
1914
1946
|
const bodyFilePath = path.join(bodyDir, "body.md");
|
|
1915
|
-
fs.writeFileSync(bodyFilePath, extractConclusion(spawned.transcript) || taskSnapshot.description);
|
|
1947
|
+
fs.writeFileSync(bodyFilePath, (prDescription ?? extractConclusion(spawned.transcript)) || taskSnapshot.description);
|
|
1916
1948
|
const created = await deps.github.createDraftPr({
|
|
1917
1949
|
cwd: worktreePath,
|
|
1918
1950
|
base: baseBranch,
|
|
@@ -1963,6 +1995,15 @@ export async function runDeveloperEffect(ctx, deps = defaultDeps) {
|
|
|
1963
1995
|
publishable: { branch: branchName },
|
|
1964
1996
|
};
|
|
1965
1997
|
}
|
|
1998
|
+
if (prAlreadyExisted && prDescription) {
|
|
1999
|
+
await bestEffortUpdatePrBody({
|
|
2000
|
+
github: deps.github,
|
|
2001
|
+
cwd: worktreePath,
|
|
2002
|
+
number: prView.number,
|
|
2003
|
+
body: prDescription,
|
|
2004
|
+
issueId: issue.id,
|
|
2005
|
+
});
|
|
2006
|
+
}
|
|
1966
2007
|
// NOT-381: collect the structured Visual QA receipt against the just-pushed
|
|
1967
2008
|
// head, before the checks wait. Accepted screenshots move to Dealer-owned
|
|
1968
2009
|
// storage and the transient worktree directory is removed; a rejection is
|
|
@@ -31,7 +31,7 @@ const { getActiveWorkflowInstance, listWorkflowEventsForIssue } = await import("
|
|
|
31
31
|
const { startWorkflow, resolveHumanActionAndAdvance } = await import("./commands.js");
|
|
32
32
|
const { registerEffectHandler, resetEffectHandlers } = await import("./effect-registry.js");
|
|
33
33
|
const { runCoordinatorTick, drainCoordinator } = await import("./worker-loop.js");
|
|
34
|
-
const { runDeveloperEffect } = await import("./developer-effect.js");
|
|
34
|
+
const { runDeveloperEffect, extractPrDescription } = await import("./developer-effect.js");
|
|
35
35
|
const { realDeveloperSpawn } = await import("./spawn.js");
|
|
36
36
|
const { realGithubAdapter } = await import("../adapters/github.js");
|
|
37
37
|
const { branchExists, roleWorktreePath, withRepoLock, observeGitCommands } = await import("../adapters/git-worktree.js");
|
|
@@ -113,6 +113,23 @@ const commitingSpawn = async (input) => {
|
|
|
113
113
|
const noopSpawn = async () => ({ exitCode: 0, transcript: "", logPath: "/dev/null", timedOut: false });
|
|
114
114
|
const crashingSpawn = async () => ({ exitCode: 1, transcript: "boom", logPath: "/dev/null", timedOut: false });
|
|
115
115
|
const timedOutSpawn = async () => ({ exitCode: 1, transcript: "", logPath: "/dev/null", timedOut: true });
|
|
116
|
+
test("extractPrDescription returns one block's contents", () => {
|
|
117
|
+
assert.equal(extractPrDescription("done\n````pr-description\n## Summary\nBuilt it.\n````"), "## Summary\nBuilt it.");
|
|
118
|
+
});
|
|
119
|
+
test("extractPrDescription uses the last block", () => {
|
|
120
|
+
const transcript = "````pr-description\nold\n````\nnotes\n````pr-description\nnew\n````";
|
|
121
|
+
assert.equal(extractPrDescription(transcript), "new");
|
|
122
|
+
});
|
|
123
|
+
test("extractPrDescription preserves template headings and nested triple-backtick fences", () => {
|
|
124
|
+
const body = "## Record\n\n```ts\nconst answer = 42;\n```";
|
|
125
|
+
assert.equal(extractPrDescription(`conclusion\n\`\`\`\`pr-description\n${body}\n\`\`\`\``), body);
|
|
126
|
+
});
|
|
127
|
+
test("extractPrDescription returns null without a block", () => {
|
|
128
|
+
assert.equal(extractPrDescription("Implementation conclusion only."), null);
|
|
129
|
+
});
|
|
130
|
+
test("extractPrDescription returns null for a blank block", () => {
|
|
131
|
+
assert.equal(extractPrDescription("````pr-description\n \n````"), null);
|
|
132
|
+
});
|
|
116
133
|
/**
|
|
117
134
|
* In-memory PR store keyed by branch — real git tells it the head SHA, nothing hits real
|
|
118
135
|
* GitHub. `viewPr`/`createDraftPr` deliberately require an explicit `branch`/`head` and
|
|
@@ -139,16 +156,22 @@ function fakeGithub(opts = {}) {
|
|
|
139
156
|
return null;
|
|
140
157
|
return { number: pr.number, url: pr.url, baseRefName: pr.base, headRefName: branch, headRefOid: remoteHead(branch), isDraft: true };
|
|
141
158
|
},
|
|
142
|
-
async createDraftPr({ base, head }) {
|
|
159
|
+
async createDraftPr({ base, head, bodyFilePath }) {
|
|
143
160
|
if (shouldFailCreate())
|
|
144
161
|
return { ok: false, reason: "gh: simulated failure", noCommits: false };
|
|
145
162
|
if (!head)
|
|
146
163
|
throw new Error("fakeGithub.createDraftPr requires an explicit --head — bare create is the NOT-82 bug");
|
|
164
|
+
opts.createdBodies?.push(fs.readFileSync(bodyFilePath, "utf8"));
|
|
147
165
|
const number = nextNumber++;
|
|
148
166
|
const url = `https://github.com/o/r/pull/${number}`;
|
|
149
167
|
prs.set(head, { number, url, base });
|
|
150
168
|
return { ok: true, number, url };
|
|
151
169
|
},
|
|
170
|
+
async updatePrBody({ bodyFilePath }) {
|
|
171
|
+
opts.updatedBodies?.push(fs.readFileSync(bodyFilePath, "utf8"));
|
|
172
|
+
if (opts.updateFails)
|
|
173
|
+
throw new Error("gh: simulated body edit failure");
|
|
174
|
+
},
|
|
152
175
|
async checksSnapshot({ number, branch }) {
|
|
153
176
|
if (number == null && !branch) {
|
|
154
177
|
throw new Error("fakeGithub.checksSnapshot requires an explicit number or branch — bare checks lookup is the NOT-82 bug");
|
|
@@ -557,6 +580,91 @@ test("checks_failed: CI failure after a clean push/PR retries without a human ac
|
|
|
557
580
|
assert.ok(kinds.includes("implementation_conclusion"), "conclusion must survive a post-session verification failure");
|
|
558
581
|
assert.ok(kinds.includes("developer_transcript"), "raw trace must survive a post-session verification failure");
|
|
559
582
|
});
|
|
583
|
+
test("PR creation uses the developer's full pr-description block", async () => {
|
|
584
|
+
const issueId = await makeIssue();
|
|
585
|
+
const createdBodies = [];
|
|
586
|
+
const body = "## Summary\nBuilt the widget.\n\n## Record\nDealer-owned.";
|
|
587
|
+
const spawn = async (input) => {
|
|
588
|
+
const result = await commitingSpawn(input);
|
|
589
|
+
return { ...result, transcript: `Implementation conclusion: done.\n\n\`\`\`\`pr-description\n${body}\n\`\`\`\`` };
|
|
590
|
+
};
|
|
591
|
+
registerEffectHandler("developer", (ctx) => runDeveloperEffect(ctx, { deckCallTool: okDeckCallTool, spawn, github: fakeGithub({ createdBodies }) }));
|
|
592
|
+
startWorkflow(issueId);
|
|
593
|
+
await pump(1);
|
|
594
|
+
assert.deepEqual(createdBodies, [body]);
|
|
595
|
+
});
|
|
596
|
+
test("PR creation falls back to the implementation conclusion when there is no block", async () => {
|
|
597
|
+
const issueId = await makeIssue();
|
|
598
|
+
const createdBodies = [];
|
|
599
|
+
registerEffectHandler("developer", (ctx) => runDeveloperEffect(ctx, { deckCallTool: okDeckCallTool, spawn: commitingSpawn, github: fakeGithub({ createdBodies }) }));
|
|
600
|
+
startWorkflow(issueId);
|
|
601
|
+
await pump(1);
|
|
602
|
+
assert.deepEqual(createdBodies, ["Implementation conclusion: added the widget."]);
|
|
603
|
+
});
|
|
604
|
+
test("PR creation falls back to the ticket description when the transcript is blank", async () => {
|
|
605
|
+
const issueId = await makeIssue();
|
|
606
|
+
const createdBodies = [];
|
|
607
|
+
const spawn = async (input) => {
|
|
608
|
+
const result = await commitingSpawn(input);
|
|
609
|
+
return { ...result, transcript: "" };
|
|
610
|
+
};
|
|
611
|
+
registerEffectHandler("developer", (ctx) => runDeveloperEffect(ctx, { deckCallTool: okDeckCallTool, spawn, github: fakeGithub({ createdBodies }) }));
|
|
612
|
+
startWorkflow(issueId);
|
|
613
|
+
await pump(1);
|
|
614
|
+
assert.deepEqual(createdBodies, ["Build the widget."]);
|
|
615
|
+
});
|
|
616
|
+
async function runBodyRefreshScenario(opts) {
|
|
617
|
+
const issueId = await makeIssue();
|
|
618
|
+
const updatedBodies = [];
|
|
619
|
+
let calls = 0;
|
|
620
|
+
const spawn = async (input) => {
|
|
621
|
+
calls++;
|
|
622
|
+
const file = calls === 1 ? "feature.txt" : "followup.txt";
|
|
623
|
+
fs.writeFileSync(path.join(input.cwd, file), `${calls}\n`);
|
|
624
|
+
git(input.cwd, "add", ".");
|
|
625
|
+
git(input.cwd, "-c", "user.email=agent@test", "-c", "user.name=Agent", "commit", "-q", "-m", `round ${calls}`);
|
|
626
|
+
const description = calls === 1 ? "initial body" : opts.secondBody;
|
|
627
|
+
const transcript = description
|
|
628
|
+
? `Implementation conclusion: round ${calls}.\n\n\`\`\`\`pr-description\n${description}\n\`\`\`\``
|
|
629
|
+
: `Implementation conclusion: round ${calls}.`;
|
|
630
|
+
return { exitCode: 0, transcript, logPath: "/dev/null", timedOut: false };
|
|
631
|
+
};
|
|
632
|
+
const github = fakeGithub({
|
|
633
|
+
checks: () => (calls === 1 ? "failure" : "success"),
|
|
634
|
+
updatedBodies,
|
|
635
|
+
updateFails: opts.updateFails,
|
|
636
|
+
});
|
|
637
|
+
registerEffectHandler("developer", (ctx) => runDeveloperEffect(ctx, { deckCallTool: okDeckCallTool, spawn, github }));
|
|
638
|
+
startWorkflow(issueId);
|
|
639
|
+
await pump(2);
|
|
640
|
+
return { issueId, calls, updatedBodies };
|
|
641
|
+
}
|
|
642
|
+
test("an existing PR is replaced with the later round's pr-description", async () => {
|
|
643
|
+
const result = await runBodyRefreshScenario({ secondBody: "current full body" });
|
|
644
|
+
assert.equal(result.calls, 2);
|
|
645
|
+
assert.deepEqual(result.updatedBodies, ["current full body"]);
|
|
646
|
+
assert.equal(getIssue(result.issueId).status, "reviewing");
|
|
647
|
+
});
|
|
648
|
+
test("an existing PR is left unchanged when the later round has no pr-description", async () => {
|
|
649
|
+
const result = await runBodyRefreshScenario({ secondBody: null });
|
|
650
|
+
assert.equal(result.calls, 2);
|
|
651
|
+
assert.deepEqual(result.updatedBodies, []);
|
|
652
|
+
assert.equal(getIssue(result.issueId).status, "reviewing");
|
|
653
|
+
});
|
|
654
|
+
test("a failed existing-PR body update is logged and does not fail the round", async () => {
|
|
655
|
+
const warnings = [];
|
|
656
|
+
const originalWarn = console.warn;
|
|
657
|
+
console.warn = (...args) => warnings.push(args.map(String).join(" "));
|
|
658
|
+
try {
|
|
659
|
+
const result = await runBodyRefreshScenario({ secondBody: "current full body", updateFails: true });
|
|
660
|
+
assert.deepEqual(result.updatedBodies, ["current full body"]);
|
|
661
|
+
assert.equal(getIssue(result.issueId).status, "reviewing");
|
|
662
|
+
assert.ok(warnings.some((warning) => /PR body update failed/.test(warning)));
|
|
663
|
+
}
|
|
664
|
+
finally {
|
|
665
|
+
console.warn = originalWarn;
|
|
666
|
+
}
|
|
667
|
+
});
|
|
560
668
|
test("NOT-311: checks_pending — checks still pending at the poll deadline defers, spending no attempt", async () => {
|
|
561
669
|
// Previously this returned `timed_out`, spending an infra attempt on a session that
|
|
562
670
|
// had already ended cleanly. Now the item waits on backoff and re-polls.
|
|
@@ -1133,10 +1241,15 @@ test("publish-only retry: post-push gh create failure reopens the PR without res
|
|
|
1133
1241
|
const issueId = await makeIssue();
|
|
1134
1242
|
let createAttempt = 0;
|
|
1135
1243
|
let spawnCalls = 0;
|
|
1136
|
-
const
|
|
1244
|
+
const createdBodies = [];
|
|
1245
|
+
const github = fakeGithub({ createFails: () => ++createAttempt === 1, createdBodies });
|
|
1137
1246
|
const countingSpawn = async (input) => {
|
|
1138
1247
|
spawnCalls++;
|
|
1139
|
-
|
|
1248
|
+
const result = await commitingSpawn(input);
|
|
1249
|
+
return {
|
|
1250
|
+
...result,
|
|
1251
|
+
transcript: "Implementation conclusion: added the widget.\n\n````pr-description\n## Summary\nFull retry body.\n````",
|
|
1252
|
+
};
|
|
1140
1253
|
};
|
|
1141
1254
|
registerEffectHandler("developer", (ctx) => runDeveloperEffect(ctx, { deckCallTool: okDeckCallTool, spawn: countingSpawn, github }));
|
|
1142
1255
|
startWorkflow(issueId);
|
|
@@ -1147,6 +1260,7 @@ test("publish-only retry: post-push gh create failure reopens the PR without res
|
|
|
1147
1260
|
assert.equal(issue.status, "reviewing");
|
|
1148
1261
|
assert.ok(issue.prNumber, "draft PR must exist after the publish-only retry");
|
|
1149
1262
|
assert.equal(issue.currentRound, 1, "publish-only infra retry does not spend a review round");
|
|
1263
|
+
assert.deepEqual(createdBodies, ["## Summary\nFull retry body."], "publish retry must reuse the stored description");
|
|
1150
1264
|
});
|
|
1151
1265
|
test("unpushed_commit: the coordinator's own push is rejected by a diverged remote branch — escalates, work preserved", async () => {
|
|
1152
1266
|
const issueId = await makeIssue();
|