agent-dealer 1.4.2 → 1.4.4

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.
Files changed (33) hide show
  1. package/bundle/server/dist/adapters/github.js +66 -3
  2. package/bundle/server/dist/adapters/github.test.js +90 -0
  3. package/bundle/server/dist/coordinator/args.js +7 -9
  4. package/bundle/server/dist/coordinator/args.test.js +5 -2
  5. package/bundle/server/dist/coordinator/auto-merge.js +17 -6
  6. package/bundle/server/dist/coordinator/commands.js +18 -2
  7. package/bundle/server/dist/coordinator/developer-effect.js +46 -5
  8. package/bundle/server/dist/coordinator/developer-effect.test.js +118 -4
  9. package/bundle/server/dist/coordinator/muse-spawn.js +1 -0
  10. package/bundle/server/dist/coordinator/operator-criteria.js +250 -17
  11. package/bundle/server/dist/coordinator/operator-criteria.test.js +177 -4
  12. package/bundle/server/dist/coordinator/operator-verification.integration.test.js +208 -0
  13. package/bundle/server/dist/coordinator/projection.js +5 -1
  14. package/bundle/server/dist/coordinator/prompts.js +77 -4
  15. package/bundle/server/dist/coordinator/prompts.test.js +22 -4
  16. package/bundle/server/dist/coordinator/reviewer-browser-probe.js +2 -3
  17. package/bundle/server/dist/coordinator/reviewer-effect.js +64 -45
  18. package/bundle/server/dist/coordinator/reviewer-effect.test.js +63 -10
  19. package/bundle/server/dist/coordinator/reviewer-pr-evidence.test.js +245 -0
  20. package/bundle/server/dist/coordinator/reviewer-result.js +4 -3
  21. package/bundle/server/dist/coordinator/reviewer-result.test.js +6 -0
  22. package/bundle/server/dist/coordinator/routing.js +3 -0
  23. package/bundle/server/dist/coordinator/routing.test.js +19 -0
  24. package/bundle/server/dist/coordinator/spawn.js +25 -5
  25. package/bundle/server/dist/coordinator/spawn.test.js +84 -0
  26. package/bundle/server/dist/docs-api-reference.test.js +89 -0
  27. package/bundle/server/dist/runners/muse-config-core.js +33 -9
  28. package/bundle/server/dist/runners/muse-config.test.js +13 -8
  29. package/bundle/server/dist/runners/spawn-cli.js +12 -4
  30. package/bundle/server/dist/runners/spawn-cli.test.js +19 -0
  31. package/bundle/server/package.json +2 -2
  32. package/bundle/shared/package.json +1 -1
  33. package/package.json +1 -1
@@ -1,7 +1,8 @@
1
1
  // NOT-314: `[operator]` criterion parser — pure cases (no DB).
2
+ // NOT-575: only the trailing tag decides (never a mention in the text).
2
3
  import { test } from "node:test";
3
4
  import assert from "node:assert/strict";
4
- import { extractOperatorCriteria } from "./operator-criteria.js";
5
+ import { criteriaTextsFromActionEvidence, extractOperatorCriteria, extractOperatorCriteriaFromContract, hasTrailingOperatorTag, operatorCriteriaForSnapshot, } from "./operator-criteria.js";
5
6
  test("two [operator] ACs return both; the indented command sub-bullet is collected", () => {
6
7
  const criteria = extractOperatorCriteria([
7
8
  "- [ ] Agent can list sessions from the registry",
@@ -26,15 +27,51 @@ test("tag case variants match: [OPERATOR], [Operator], [oPeRaToR]", () => {
26
27
  const criteria = extractOperatorCriteria(["- [ ] First [OPERATOR]", "- [ ] Second [Operator]", "- [ ] Third [oPeRaToR]"].join("\n"));
27
28
  assert.equal(criteria.length, 3);
28
29
  });
29
- test("tag position variants match: leading, middle, trailing, and bare", () => {
30
+ test("NOT-575: only the trailing tag decides — leading, middle, and bare mention do not gate", () => {
30
31
  const criteria = extractOperatorCriteria([
31
32
  "- [ ] [operator] Leading tag proves login",
32
33
  "- [ ] Middle [operator] tag proves login",
33
34
  "- [ ] Trailing tag proves login [operator]",
34
35
  "- [ ] [operator]",
35
36
  ].join("\n"));
36
- assert.equal(criteria.length, 4);
37
- assert.equal(criteria[0].text, "[operator] Leading tag proves login");
37
+ // The bare `[operator]` line IS a trailing tag (the whole text is the tag);
38
+ // leading and middle mentions never open the gate.
39
+ assert.equal(criteria.length, 2);
40
+ assert.equal(criteria[0].text, "Trailing tag proves login [operator]");
41
+ assert.equal(criteria[1].text, "[operator]");
42
+ });
43
+ test("NOT-575: a criterion ending in [agent] whose text mentions [operator] is not flagged", () => {
44
+ // The NOT-568 shape: the [agent] criterion's prose merely contained the
45
+ // string [operator], while the real [operator] criterion gated.
46
+ const criteria = extractOperatorCriteria([
47
+ "- [ ] Verify the [operator] handoff renders for the agent review [agent]",
48
+ " Evidence: agent run | run the render test | green",
49
+ "- [ ] Operator can sign in with SSO and see the org dashboard [operator]",
50
+ " Evidence: operator run | `npm run probe:sso -- --env staging` | dashboard lists orgs",
51
+ ].join("\n"));
52
+ assert.equal(criteria.length, 1);
53
+ assert.equal(criteria[0].text, "Operator can sign in with SSO and see the org dashboard [operator]");
54
+ assert.deepEqual(criteria[0].commands, [
55
+ "Evidence: operator run | `npm run probe:sso -- --env staging` | dashboard lists orgs",
56
+ ]);
57
+ });
58
+ test("NOT-575: trailing-tag matching is case-insensitive and tolerates trailing whitespace", () => {
59
+ const criteria = extractOperatorCriteria(["- [ ] First [OPERATOR] ", "- [ ] Second [Operator]\t", "- [ ] Third [oPeRaToR]"].join("\n"));
60
+ assert.equal(criteria.length, 3);
61
+ });
62
+ test("NOT-575: hasTrailingOperatorTag — last tag wins, punctuation after the tag is not a tag", () => {
63
+ assert.equal(hasTrailingOperatorTag("Proves login [operator]"), true);
64
+ assert.equal(hasTrailingOperatorTag("Proves login [OPERATOR]"), true);
65
+ assert.equal(hasTrailingOperatorTag("Proves login [operator] "), true);
66
+ assert.equal(hasTrailingOperatorTag("[operator]"), true);
67
+ assert.equal(hasTrailingOperatorTag("Mentions [operator] then ends [agent]"), false);
68
+ assert.equal(hasTrailingOperatorTag("[operator] Leading tag proves login"), false);
69
+ assert.equal(hasTrailingOperatorTag("Proves login [operator]."), false);
70
+ assert.equal(hasTrailingOperatorTag("Proves login [operators]"), false);
71
+ assert.equal(hasTrailingOperatorTag("Two tags [agent] [operator]"), true);
72
+ assert.equal(hasTrailingOperatorTag("Two tags [operator] [agent]"), false);
73
+ assert.equal(hasTrailingOperatorTag("No tag at all"), false);
74
+ assert.equal(hasTrailingOperatorTag(""), false);
38
75
  });
39
76
  test("multiple indented sub-bullets all collect; blank lines inside the block are skipped", () => {
40
77
  const criteria = extractOperatorCriteria([
@@ -76,3 +113,139 @@ test("the next top-level checkbox ends the command block; prose ends it too", ()
76
113
  test("[agent] in AC text is not an operator criterion", () => {
77
114
  assert.deepEqual(extractOperatorCriteria("- [ ] Agent lists sessions [agent]\n"), []);
78
115
  });
116
+ test("NOT-575: the contract's indented Evidence: line is collected, not a block terminator", () => {
117
+ const criteria = extractOperatorCriteria([
118
+ "- [ ] Paid checkout works end to end [operator]",
119
+ " Evidence: operator run | `npm run probe:checkout -- --env staging` | receipt shown",
120
+ " - see docs/probes/checkout.md for the test card",
121
+ ].join("\n"));
122
+ assert.equal(criteria.length, 1);
123
+ assert.deepEqual(criteria[0].commands, [
124
+ "Evidence: operator run | `npm run probe:checkout -- --env staging` | receipt shown",
125
+ "see docs/probes/checkout.md for the test card",
126
+ ]);
127
+ });
128
+ test("NOT-575: the nested-bullet Evidence form collects the same way", () => {
129
+ const criteria = extractOperatorCriteria(["- [ ] Paid checkout works end to end [operator]", " * Evidence: operator run | paste the output | reviewed"].join("\n"));
130
+ assert.equal(criteria.length, 1);
131
+ assert.deepEqual(criteria[0].commands, ["Evidence: operator run | paste the output | reviewed"]);
132
+ });
133
+ test("NOT-575: contract criteria gate on the trailing tag with their evidence as the command", () => {
134
+ const criteria = extractOperatorCriteriaFromContract({
135
+ version: "v1",
136
+ executionMode: "bug fix",
137
+ nonGoals: ["x"],
138
+ exitPredicate: "done",
139
+ onePrStoppingPoint: "stop",
140
+ acceptanceCriteria: [
141
+ { text: "Verify the [operator] handoff renders [agent]", evidence: "agent run" },
142
+ { text: "Operator signs in with SSO [operator]", evidence: "operator run | paste the output" },
143
+ { text: "Untagged work", evidence: null },
144
+ ],
145
+ });
146
+ assert.equal(criteria.length, 1);
147
+ assert.equal(criteria[0].text, "Operator signs in with SSO [operator]");
148
+ assert.deepEqual(criteria[0].commands, ["Evidence: operator run | paste the output"]);
149
+ assert.deepEqual(extractOperatorCriteriaFromContract(null), []);
150
+ assert.deepEqual(extractOperatorCriteriaFromContract(undefined), []);
151
+ });
152
+ test("NOT-575: the snapshot union dedupes AC text and contract by exact criterion text", () => {
153
+ const merged = operatorCriteriaForSnapshot({
154
+ acceptanceCriteria: "- [ ] Operator signs in with SSO [operator]\n Evidence: ac text evidence",
155
+ executionContract: {
156
+ version: "v1",
157
+ executionMode: "bug fix",
158
+ nonGoals: ["x"],
159
+ exitPredicate: "done",
160
+ onePrStoppingPoint: "stop",
161
+ acceptanceCriteria: [
162
+ { text: "Operator signs in with SSO [operator]", evidence: "contract evidence" },
163
+ { text: "Operator completes a paid checkout [operator]", evidence: "checkout evidence" },
164
+ ],
165
+ },
166
+ });
167
+ // The shared criterion appears once (AC-text form wins); the contract-only
168
+ // criterion still gates even though the AC string diverges from it.
169
+ assert.equal(merged.length, 2);
170
+ assert.equal(merged[0].text, "Operator signs in with SSO [operator]");
171
+ assert.deepEqual(merged[0].commands, ["Evidence: ac text evidence"]);
172
+ assert.equal(merged[1].text, "Operator completes a paid checkout [operator]");
173
+ assert.deepEqual(merged[1].commands, ["Evidence: checkout evidence"]);
174
+ });
175
+ test("NOT-575 repair 2: a Linear-escaped trailing \\[operator\\] gates with its Evidence line", () => {
176
+ // Linear markdown escapes the tag brackets; intake and the contract
177
+ // compiler keep the raw `\[operator\]` text, so the gate must accept it —
178
+ // the NOT-567/569-572 tickets merged with no operator action because it did not.
179
+ const criteria = extractOperatorCriteria([
180
+ "- [ ] Agent can list sessions from the registry \\[agent\\]",
181
+ " Evidence: unit tests | run the registry suite | green",
182
+ "- [ ] Operator can sign in with SSO and see the org dashboard \\[operator\\]",
183
+ " Evidence: operator run | `npm run probe:sso -- --env staging` | dashboard lists orgs",
184
+ ].join("\n"));
185
+ assert.equal(criteria.length, 1);
186
+ assert.equal(criteria[0].text, "Operator can sign in with SSO and see the org dashboard \\[operator\\]");
187
+ assert.deepEqual(criteria[0].commands, [
188
+ "Evidence: operator run | `npm run probe:sso -- --env staging` | dashboard lists orgs",
189
+ ]);
190
+ });
191
+ test("NOT-575 repair 2: an escaped \\[agent\\] line mentioning [operator] is not flagged", () => {
192
+ // The NOT-568 mis-flag shape under Linear escaping: the [agent]
193
+ // criterion's prose contains the string [operator] (backticked, unescaped)
194
+ // but its trailing tag is `\[agent\]` — never a gate. The genuine escaped
195
+ // `\[operator\]` criterion alongside it still gates.
196
+ const criteria = extractOperatorCriteria([
197
+ "- [ ] Verify the `[operator]` handoff renders for the agent review \\[agent\\]",
198
+ " Evidence: agent run | run the render test | green",
199
+ "- [ ] Operator can sign in with SSO \\[operator\\]",
200
+ " Evidence: operator run | `npm run probe:sso` | dashboard shown",
201
+ ].join("\n"));
202
+ assert.equal(criteria.length, 1);
203
+ assert.equal(criteria[0].text, "Operator can sign in with SSO \\[operator\\]");
204
+ });
205
+ test("NOT-575 repair 2: hasTrailingOperatorTag accepts the escaped tag, still rejects escaped non-tags", () => {
206
+ assert.equal(hasTrailingOperatorTag("Proves login \\[operator\\]"), true);
207
+ assert.equal(hasTrailingOperatorTag("Proves login \\[OPERATOR\\]"), true);
208
+ assert.equal(hasTrailingOperatorTag("Proves login \\[operator\\] "), true);
209
+ assert.equal(hasTrailingOperatorTag("\\[operator\\]"), true);
210
+ assert.equal(hasTrailingOperatorTag("Mentions [operator] then ends \\[agent\\]"), false);
211
+ assert.equal(hasTrailingOperatorTag("Proves login \\[agent\\]"), false);
212
+ assert.equal(hasTrailingOperatorTag("Proves login \\[operators\\]"), false);
213
+ assert.equal(hasTrailingOperatorTag("Proves login \\[operator\\]."), false);
214
+ assert.equal(hasTrailingOperatorTag("Two tags \\[agent\\] \\[operator\\]"), true);
215
+ assert.equal(hasTrailingOperatorTag("Two tags [operator] \\[agent\\]"), false);
216
+ });
217
+ test("NOT-575 repair 2: contract criteria gate on the escaped trailing tag", () => {
218
+ const criteria = extractOperatorCriteriaFromContract({
219
+ version: "v1",
220
+ executionMode: "bug fix",
221
+ nonGoals: ["x"],
222
+ exitPredicate: "done",
223
+ onePrStoppingPoint: "stop",
224
+ acceptanceCriteria: [
225
+ { text: "Verify the `[operator]` handoff renders \\[agent\\]", evidence: "agent run" },
226
+ { text: "Operator signs in with SSO \\[operator\\]", evidence: "operator run | paste the output" },
227
+ ],
228
+ });
229
+ assert.equal(criteria.length, 1);
230
+ assert.equal(criteria[0].text, "Operator signs in with SSO \\[operator\\]");
231
+ assert.deepEqual(criteria[0].commands, ["Evidence: operator run | paste the output"]);
232
+ });
233
+ test("NOT-575: criteriaTextsFromActionEvidence reads the gated list, null when unreadable", () => {
234
+ assert.deepEqual(criteriaTextsFromActionEvidence({
235
+ evidenceJson: JSON.stringify({
236
+ operatorVerification: {
237
+ headSha: "abc",
238
+ criteria: [
239
+ { text: "First [operator]", commands: [] },
240
+ { text: "Second [operator]", commands: ["Evidence: x"] },
241
+ ],
242
+ },
243
+ }),
244
+ }), ["First [operator]", "Second [operator]"]);
245
+ assert.equal(criteriaTextsFromActionEvidence({ evidenceJson: null }), null);
246
+ assert.equal(criteriaTextsFromActionEvidence({ evidenceJson: "not json" }), null);
247
+ assert.equal(criteriaTextsFromActionEvidence({ evidenceJson: JSON.stringify({}) }), null);
248
+ assert.equal(criteriaTextsFromActionEvidence({
249
+ evidenceJson: JSON.stringify({ operatorVerification: { criteria: "nope" } }),
250
+ }), null);
251
+ });
@@ -438,6 +438,214 @@ test("NOT-538: not_applicable visual evidence (no Visual workflow) on a UI head
438
438
  assert.deepEqual(calls, [{ cwd: managedCwd, number: 42 }]);
439
439
  assert.equal(getIssue(issueId).status, "done");
440
440
  });
441
+ test("NOT-575: an [agent] criterion that merely mentions [operator] never opens the gate", async () => {
442
+ const calls = [];
443
+ setMergePrForTests(async (opts) => {
444
+ calls.push(opts);
445
+ return { ok: true };
446
+ });
447
+ // The NOT-568 shape: the [agent] criterion's prose contains the string
448
+ // [operator], but its trailing tag is [agent] — not a gate.
449
+ const issueId = newIssue([
450
+ "- [ ] Verify the [operator] handoff renders for the agent review [agent]",
451
+ " Evidence: agent run | run the render test | green",
452
+ "- [ ] Docs describe the probe [agent]",
453
+ " Evidence: doc review | read the probe doc | command documented",
454
+ ].join("\n"));
455
+ startWorkflow(issueId);
456
+ const result = await approve(issueId);
457
+ assert.equal(result.applied, true);
458
+ if (result.applied) {
459
+ assert.equal(result.issueStatus, "done");
460
+ assert.equal(result.instanceCompleted, true);
461
+ }
462
+ assert.deepEqual(calls, [{ cwd: managedCwd, number: 42 }]);
463
+ assert.equal(getIssue(issueId).status, "done");
464
+ assert.equal(listHumanActionsForIssue(issueId).filter((a) => a.status === "open").length, 0);
465
+ });
466
+ test("NOT-575: a trailing-[operator] criterion with an Evidence line gates with the evidence in the action", async () => {
467
+ const calls = [];
468
+ setMergePrForTests(async (opts) => {
469
+ calls.push(opts);
470
+ return { ok: true };
471
+ });
472
+ const issueId = newIssue([
473
+ "- [ ] Agent can list sessions from the registry [agent]",
474
+ " Evidence: unit tests | run the registry suite | green",
475
+ "- [ ] Operator can sign in with SSO and see the org dashboard [operator]",
476
+ " Evidence: operator run | `npm run probe:sso -- --env staging` | dashboard lists orgs",
477
+ ].join("\n"));
478
+ startWorkflow(issueId);
479
+ await approve(issueId);
480
+ assert.equal(calls.length, 0, "the merge adapter must not run behind the gate");
481
+ assert.equal(getIssue(issueId).status, "needs_human");
482
+ const action = openOperatorAction(issueId);
483
+ assert.match(action.question, /sign in with SSO and see the org dashboard \[operator\]/);
484
+ assert.match(action.question, /Evidence: operator run \| `npm run probe:sso -- --env staging`/);
485
+ assert.doesNotMatch(action.question, /list sessions from the registry/);
486
+ const evidence = JSON.parse(action.evidenceJson);
487
+ assert.equal(evidence.operatorVerification.headSha, "abc123");
488
+ assert.equal(evidence.operatorVerification.criteria.length, 1);
489
+ assert.deepEqual(evidence.operatorVerification.criteria[0].commands, [
490
+ "Evidence: operator run | `npm run probe:sso -- --env staging` | dashboard lists orgs",
491
+ ]);
492
+ const resolved = await resolveHumanActionAndAdvanceAsync(action.id, "op", "verified", {
493
+ note: "SSO login OK — org dashboard listed 3 orgs.",
494
+ });
495
+ assert.equal(resolved.ok, true);
496
+ if (resolved.ok)
497
+ assert.equal(resolved.issueStatus, "done");
498
+ assert.equal(calls.length, 1);
499
+ assert.equal(getIssue(issueId).status, "done");
500
+ });
501
+ test("NOT-575: a result recorded for only one of two [operator] criteria still blocks the merge", async () => {
502
+ let merges = 0;
503
+ setMergePrForTests(async () => {
504
+ merges += 1;
505
+ return { ok: true };
506
+ });
507
+ const issueId = newIssue([
508
+ "- [ ] Operator can sign in with SSO [operator]",
509
+ " Evidence: operator run | `npm run probe:sso` | dashboard shown",
510
+ "- [ ] Operator can complete a paid checkout [operator]",
511
+ " Evidence: operator run | `npm run probe:checkout` | receipt shown",
512
+ ].join("\n"));
513
+ startWorkflow(issueId);
514
+ await approve(issueId);
515
+ assert.equal(merges, 0);
516
+ const action = openOperatorAction(issueId);
517
+ const evidence = JSON.parse(action.evidenceJson);
518
+ assert.equal(evidence.operatorVerification.criteria.length, 2);
519
+ // A result covering only the first criterion (same head) must not release
520
+ // the second — the gate still holds and reuses the open action.
521
+ createIssueArtifact({
522
+ issueId,
523
+ kind: "operator_verification",
524
+ author: "human",
525
+ content: {
526
+ headSha: "abc123",
527
+ note: "SSO login OK.",
528
+ verifiedBy: "op",
529
+ verifiedAt: new Date().toISOString(),
530
+ criteria: ["Operator can sign in with SSO [operator]"],
531
+ },
532
+ });
533
+ const stillBlocked = await finalizeAutoMerge(issueId);
534
+ assert.equal(stillBlocked.issueStatus, "needs_human");
535
+ assert.equal(stillBlocked.humanActionId, action.id, "the same head reuses the open action");
536
+ assert.equal(merges, 0);
537
+ // Resolving the gated action covers both listed criteria and merges.
538
+ const resolved = await resolveHumanActionAndAdvanceAsync(action.id, "op", "verified", {
539
+ note: "SSO login OK; paid checkout receipt shown.",
540
+ });
541
+ assert.equal(resolved.ok, true);
542
+ if (resolved.ok)
543
+ assert.equal(resolved.issueStatus, "done");
544
+ assert.equal(merges, 1);
545
+ const stored = listArtifactsForIssueByKind(issueId, "operator_verification");
546
+ // Newest first: [0] is the resolve-recorded result covering both criteria.
547
+ const recorded = JSON.parse(stored[0].contentJson);
548
+ assert.deepEqual(recorded.criteria, [
549
+ "Operator can sign in with SSO [operator]",
550
+ "Operator can complete a paid checkout [operator]",
551
+ ]);
552
+ });
553
+ test("NOT-575: a trailing-[operator] contract criterion gates even when the AC string diverges", async () => {
554
+ let merges = 0;
555
+ setMergePrForTests(async () => {
556
+ merges += 1;
557
+ return { ok: true };
558
+ });
559
+ // The contract carries the genuine trailing-[operator] tag while an
560
+ // explicitly-provided AC string has no tags at all — the gate must still
561
+ // flag the contract criterion (the Agent Deck program's missed-gate shape).
562
+ const description = [
563
+ "Ship the SSO probe.",
564
+ "",
565
+ "## Builder execution mode",
566
+ "bug fix",
567
+ "",
568
+ "## Non-goals",
569
+ "- Rewriting the installer",
570
+ "",
571
+ "## Exit predicate",
572
+ "SSO sign-in works with operator proof.",
573
+ "",
574
+ "## One-PR stopping point",
575
+ "Stop after the probe lands.",
576
+ "",
577
+ "## Acceptance criteria",
578
+ "- [ ] Agent lists sessions [agent]",
579
+ " Evidence: unit tests | run the registry suite | green",
580
+ "- [ ] Operator signs in with SSO [operator]",
581
+ " Evidence: operator run | paste the output | dashboard shown",
582
+ "",
583
+ ].join("\n");
584
+ const issueId = createIssue({
585
+ title: "SSO probe",
586
+ description,
587
+ acceptanceCriteria: "- [ ] Agent lists sessions\n- [ ] Operator signs in with SSO",
588
+ repo: "acme/app",
589
+ developerAgentId: BUILTIN_AGENT_CLAUDE_ID,
590
+ reviewerAgentId: BUILTIN_AGENT_CURSOR_ID,
591
+ baseBranch: "main",
592
+ maxReviewRounds: 3,
593
+ maxInfraAttempts: 3,
594
+ source: "manual",
595
+ autoMerge: true,
596
+ }).id;
597
+ startWorkflow(issueId);
598
+ await approve(issueId);
599
+ assert.equal(merges, 0, "the contract-tagged criterion must gate");
600
+ assert.equal(getIssue(issueId).status, "needs_human");
601
+ const action = openOperatorAction(issueId);
602
+ assert.match(action.question, /Operator signs in with SSO \[operator\]/);
603
+ const resolved = await resolveHumanActionAndAdvanceAsync(action.id, "op", "verified", {
604
+ note: "SSO login OK — dashboard shown.",
605
+ });
606
+ assert.equal(resolved.ok, true);
607
+ if (resolved.ok)
608
+ assert.equal(resolved.issueStatus, "done");
609
+ assert.equal(merges, 1);
610
+ });
611
+ test("NOT-575 repair 2: a Linear-escaped trailing \\[operator\\] gates and merges after verify", async () => {
612
+ const calls = [];
613
+ setMergePrForTests(async (opts) => {
614
+ calls.push(opts);
615
+ return { ok: true };
616
+ });
617
+ // The NOT-567/569-572 shape: Linear escapes the tag brackets, so the
618
+ // frozen text ends in `\]` — the gate must still flag the genuine
619
+ // operator criterion, while the escaped `\[agent\]` criterion whose prose
620
+ // mentions [operator] (the NOT-568 shape) must not appear in the action.
621
+ const issueId = newIssue([
622
+ "- [ ] Verify the `[operator]` handoff renders for the agent review \\[agent\\]",
623
+ " Evidence: agent run | run the render test | green",
624
+ "- [ ] Operator can sign in with SSO and see the org dashboard \\[operator\\]",
625
+ " Evidence: operator run | `npm run probe:sso -- --env staging` | dashboard lists orgs",
626
+ ].join("\n"));
627
+ startWorkflow(issueId);
628
+ await approve(issueId);
629
+ assert.equal(calls.length, 0, "the merge adapter must not run behind the gate");
630
+ assert.equal(getIssue(issueId).status, "needs_human");
631
+ const action = openOperatorAction(issueId);
632
+ assert.match(action.question, /sign in with SSO and see the org dashboard/);
633
+ assert.doesNotMatch(action.question, /handoff renders for the agent review/);
634
+ const evidence = JSON.parse(action.evidenceJson);
635
+ assert.equal(evidence.operatorVerification.headSha, "abc123");
636
+ assert.equal(evidence.operatorVerification.criteria.length, 1);
637
+ assert.deepEqual(evidence.operatorVerification.criteria[0].commands, [
638
+ "Evidence: operator run | `npm run probe:sso -- --env staging` | dashboard lists orgs",
639
+ ]);
640
+ const resolved = await resolveHumanActionAndAdvanceAsync(action.id, "op", "verified", {
641
+ note: "SSO login OK — org dashboard listed 3 orgs.",
642
+ });
643
+ assert.equal(resolved.ok, true);
644
+ if (resolved.ok)
645
+ assert.equal(resolved.issueStatus, "done");
646
+ assert.equal(calls.length, 1);
647
+ assert.equal(getIssue(issueId).status, "done");
648
+ });
441
649
  test("NOT-384: [operator] criteria plus a visual hold raise one action naming both", async () => {
442
650
  let merges = 0;
443
651
  setMergePrForTests(async () => {
@@ -94,7 +94,11 @@ export function projectReviewerRoute(route, round, hasVerdict) {
94
94
  currentIntent: "Awaiting final human review",
95
95
  events: ["worker.completed", ...verdictEvents],
96
96
  },
97
- effect: { kind: "human_action", actionType: "final_review", reason: "Reviewer approved the PR" },
97
+ effect: {
98
+ kind: "human_action",
99
+ actionType: "final_review",
100
+ reason: route.reason ?? "Reviewer approved the PR",
101
+ },
98
102
  advance: "none",
99
103
  hasVerdict,
100
104
  };
@@ -303,7 +303,7 @@ export function buildDeveloperPrompt(input) {
303
303
  // NOT-146: timed-spawn handoff bar is commits + targeted tests for the change.
304
304
  // Full suite / Lens run on a separate verify/review budget (NOT-74) — they do not
305
305
  // gate developer clean_handoff; the coordinator does not block on full-suite alone.
306
- `Run targeted tests for the change. A clean handoff is valid with commits plus those targeted tests — full suite / Lens checks are not required inside this timed developer spawn (they run on a separate review/verify budget). Make incremental commits with \`git\` at coherent slice boundaries (for example after the tests for that slice pass) — do not leave all work uncommitted until the very end. A final commit of any remaining changes and the **implementation conclusion** remain required before you exit.`, `Commit any remaining changes with \`git\` — do NOT push and do NOT open a pull request; the coordinator pushes your branch and opens/updates the draft PR after this session ends.`, `End your reply with a short **implementation conclusion**: what changed, why, any deviations from the acceptance criteria, and known follow-ups. This is distinct from the PR description and is required every round.`);
306
+ `Run targeted tests for the change. A clean handoff is valid with commits plus those targeted tests — full suite / Lens checks are not required inside this timed developer spawn (they run on a separate review/verify budget). Make incremental commits with \`git\` at coherent slice boundaries (for example after the tests for that slice pass) — do not leave all work uncommitted until the very end. A final commit of any remaining changes and the **implementation conclusion** remain required before you exit.`, `Commit any remaining changes with \`git\` — do NOT push and do NOT open a pull request; the coordinator pushes your branch and opens/updates the draft PR after this session ends.`, `Every round, end your reply with a short **implementation conclusion**: what changed, why, any deviations from the acceptance criteria, and known follow-ups. After it, end with exactly one block fenced by four backticks whose info string is \`pr-description\` (\`\`\`\`pr-description\`). The block must contain the full PR description for the branch as it now stands, not only this round's change. If the repository contains \`.github/pull_request_template.md\`, \`.github/PULL_REQUEST_TEMPLATE.md\`, \`PULL_REQUEST_TEMPLATE.md\`, or \`docs/pull_request_template.md\`, read it from this worktree, keep every heading, and fill it in. Four-backtick fencing lets triple-backtick code fences survive inside the description.`);
307
307
  return parts.join("\n");
308
308
  }
309
309
  const REVIEWER_RESULT_SHAPE = '{"verdict":"approved"|"changes_requested"|"escalated","baseSha":"...","headSha":"...","acceptanceCriteriaAssessment":"...","evidenceAssessment":"...","exitPredicateAssessment":"...","findings":[{"fingerprint":"stable-slug","severity":"blocking"|"non_blocking","title":"...","rationale":"...","file":"...","line":0}],"risks":["..."],"productScopeQuestion":"..."}';
@@ -323,7 +323,7 @@ function reviewerContractSection(baseSha, headSha) {
323
323
  `- "acceptanceCriteriaAssessment" judges the acceptance criteria; "evidenceAssessment" must judge EACH criterion's stated evidence (where to look, action/command, expected result) one by one — never a blanket "evidence looks good".`,
324
324
  `- When the task carries an execution contract, set "exitPredicateAssessment" to whether the frozen exit predicate observably holds at this tip, and "approved" additionally requires the exit predicate to hold (AC met alone is not enough). Tasks without a contract omit "exitPredicateAssessment".`,
325
325
  `- "approved": AC met for this tip and no finding is "blocking" (non_blocking nits allowed).`,
326
- `- "changes_requested": any "blocking" finding a coding pass can address — including incomplete review because AC-critical files were omitted/truncated from the diff. List omitted paths in a blocking finding.`,
326
+ `- "changes_requested": any "blocking" finding a coding pass can address. Do not add a finding solely because the coordinator omitted files from an oversized diff; the coordinator routes an otherwise incomplete truncated review to the operator.`,
327
327
  `- "escalated": only when acceptance criteria / product scope are ambiguous, contradictory, or need a human product call — not ordinary code defects, not "diff too large". You MUST set non-empty "productScopeQuestion"; omit the field otherwise.`,
328
328
  // NOT-303: a missing screenshot is never a pass. Some runtimes (Muse Code: the
329
329
  // Chrome.app headless abort) cannot do visual QA in-session and say so in the
@@ -340,7 +340,7 @@ function reviewerContractSection(baseSha, headSha) {
340
340
  * omitted and listed in `omittedPaths`. Truncation policy (PRD §6.4 / NOT-150): coordinator
341
341
  * remaps illegal escalate / approved+blocking; never blind escalate → Resume|Close.
342
342
  */
343
- export const TOTAL_DIFF_LIMIT = 300_000;
343
+ export const TOTAL_DIFF_LIMIT = 600_000;
344
344
  function pathFromDiffGitHeader(headerLine) {
345
345
  // `diff --git a/path b/path` — prefer the b/ side; fall back to a/.
346
346
  const m = headerLine.match(/^diff --git a\/(.+?) b\/(.+)$/);
@@ -368,7 +368,7 @@ export function formatDiffForPrompt(diff) {
368
368
  }
369
369
  const truncated = omittedPaths.length > 0;
370
370
  const footer = truncated
371
- ? `\n... [${omittedPaths.length} changed file(s) omitted — diff exceeds ${TOTAL_DIFF_LIMIT} characters. Omitted: ${omittedPaths.join(", ")}. If any omitted path is AC-critical, verdict MUST be "changes_requested" with a blocking finding listing those paths. If AC is still certifiable from the visible tip with only non_blocking findings, "approved" is allowed. Do NOT use "escalated" for truncation — escalate only with productScopeQuestion for a true product gap.]`
371
+ ? `\n... [${omittedPaths.length} changed file(s) omitted — diff exceeds ${TOTAL_DIFF_LIMIT} characters. Omitted: ${omittedPaths.join(", ")}. Review the visible diff normally. Do not add a blocking finding or use "escalated" solely because files were omitted; the coordinator sends an otherwise incomplete truncated review to the operator. If AC is still certifiable from the visible tip with only non_blocking findings, "approved" is allowed.]`
372
372
  : "";
373
373
  return {
374
374
  text: `Changed files (${blocks.length}):\n${manifest}\n\n${pieces.join("\n")}${footer}`,
@@ -419,6 +419,75 @@ function visualEvidenceSection(evidence) {
419
419
  ``,
420
420
  ];
421
421
  }
422
+ /** NOT-575: cap for the live PR body embedded as reviewer evidence — a body
423
+ * can carry a full ticket description plus pasted output. */
424
+ export const PR_BODY_EVIDENCE_MAX_CHARS = 8000;
425
+ /** NOT-575: at most this many attestations render (the most recent win). */
426
+ export const OPERATOR_ATTESTATIONS_MAX_COUNT = 5;
427
+ /** NOT-575: per-attestation note cap — pasted probe output can be long. */
428
+ export const OPERATOR_ATTESTATION_NOTE_MAX_CHARS = 2000;
429
+ function capText(text, maxChars, what) {
430
+ const trimmed = text.trim();
431
+ if (trimmed.length <= maxChars)
432
+ return trimmed;
433
+ return `${trimmed.slice(0, maxChars).trimEnd()}\n\n... [${what} truncated to ${maxChars} characters]`;
434
+ }
435
+ /**
436
+ * NOT-575: the PR's live body as reviewer evidence. The reviewer's sandbox
437
+ * has no network and no `gh`, so ticket evidence that says to paste output,
438
+ * commands, or verification notes in the PR body is invisible to it unless
439
+ * the coordinator embeds the body here. Pasted output that matches the
440
+ * criterion IS the evidence — never escalate only because it lives in the PR
441
+ * body instead of the diff. Blank/absent renders nothing.
442
+ */
443
+ export function prBodyEvidenceSection(prBody) {
444
+ if (!prBody?.trim())
445
+ return [];
446
+ return [
447
+ `## PR body (live — evidence pasted there counts)`,
448
+ `Your sandbox cannot read the PR body, so the coordinator fetched it live for this review. When a criterion's stated evidence says to paste output, a command, or verification notes in the PR body, that pasted text IS the evidence — judge it like any other evidence and never escalate only because it lives here instead of in the diff.`,
449
+ ``,
450
+ capText(prBody, PR_BODY_EVIDENCE_MAX_CHARS, "PR body"),
451
+ ``,
452
+ ];
453
+ }
454
+ /**
455
+ * NOT-575: recorded operator attestations as reviewer evidence. A `verified`
456
+ * result's note carries the operator's pasted output; a `waive` carries the
457
+ * waiver reason. Either counts as the evidence for the criteria it names —
458
+ * never escalate for evidence an attestation already provides. A result
459
+ * pinned to a different head does not release this head's gate (Dealer
460
+ * handles that itself), but its pasted output is still evidence you can
461
+ * judge. Empty/absent renders nothing.
462
+ */
463
+ export function operatorAttestationsSection(attestations, pinnedHeadSha) {
464
+ if (!attestations?.length)
465
+ return [];
466
+ const shown = attestations.slice(-OPERATOR_ATTESTATIONS_MAX_COUNT);
467
+ const lines = [
468
+ `## Operator attestations (recorded results count as evidence)`,
469
+ `A human operator already recorded these results on this issue. A recorded result counts as the evidence for the criteria it names — never escalate for evidence an attestation below already provides. Only a result pinned to this exact head (\`${pinnedHeadSha.slice(0, 8)}\`) releases this head's merge gate; other heads' output below is still evidence you can judge.`,
470
+ ``,
471
+ ];
472
+ for (const attestation of shown) {
473
+ const head8 = attestation.headSha.slice(0, 8);
474
+ const pinned = attestation.headSha === pinnedHeadSha ? "this head" : `head \`${head8}\``;
475
+ const by = attestation.by ? ` by ${attestation.by}` : "";
476
+ const at = attestation.at ? ` at ${attestation.at}` : "";
477
+ lines.push(`### ${attestation.kind === "verified" ? "Verified" : "Waived"} (${pinned}${by}${at})`);
478
+ if (attestation.criteria.length > 0) {
479
+ for (const criterion of attestation.criteria)
480
+ lines.push(`- Criterion: ${criterion}`);
481
+ }
482
+ lines.push(attestation.note.trim()
483
+ ? capText(attestation.note, OPERATOR_ATTESTATION_NOTE_MAX_CHARS, "attestation note")
484
+ : "(no note recorded)", ``);
485
+ }
486
+ if (attestations.length > shown.length) {
487
+ lines.push(`... [${attestations.length - shown.length} older attestation(s) omitted]`, ``);
488
+ }
489
+ return lines;
490
+ }
422
491
  export function buildReviewerPrompt(input) {
423
492
  const parts = [
424
493
  input.round === 1
@@ -460,6 +529,10 @@ export function buildReviewerPrompt(input) {
460
529
  // NOT-381: the coordinator-validated visual receipt (or loud rejection),
461
530
  // SHA-bound to the pinned head — the raw conclusion line above is unverified.
462
531
  parts.push(...visualQaReviewerSection(input.visualQa?.record ?? null, input.visualQa?.pinnedHeadSha ?? input.headSha));
532
+ // NOT-575: the live PR body and recorded operator attestations — evidence
533
+ // the sandbox cannot fetch itself. Absent renders nothing.
534
+ parts.push(...prBodyEvidenceSection(input.prBody));
535
+ parts.push(...operatorAttestationsSection(input.operatorAttestations, input.headSha));
463
536
  if (input.findings?.length) {
464
537
  parts.push(`## Findings from prior rounds (verify each is actually resolved)`);
465
538
  for (const f of input.findings) {
@@ -27,6 +27,15 @@ test("developer prompt asks for incremental commits at slice boundaries and keep
27
27
  assert.match(prompt, /implementation conclusion/i);
28
28
  assert.match(prompt, /do NOT push and do NOT open a pull request/);
29
29
  });
30
+ test("developer prompt requires a full template-preserving pr-description every round", () => {
31
+ const prompt = buildDeveloperPrompt({ taskSnapshot, round: 1 });
32
+ assert.match(prompt, /Every round/);
33
+ assert.match(prompt, /````pr-description/);
34
+ assert.match(prompt, /full PR description for the branch as it now stands/);
35
+ assert.match(prompt, /\.github\/pull_request_template\.md/);
36
+ assert.match(prompt, /keep every heading/);
37
+ assert.doesNotMatch(prompt, /distinct from the PR description/);
38
+ });
30
39
  // NOT-146: timed developer spawn covers implement + targeted tests; full suite / Lens
31
40
  // live on a separate budget (NOT-74), not inside the same wall clock.
32
41
  test("NOT-146: developer prompt handoff bar is commits + targeted tests, not full suite/Lens in-spawn", () => {
@@ -189,16 +198,25 @@ test("NOT-150: reviewer verdict rules match the design table (blocking ⇒ chang
189
198
  assert.match(prompt, /not ordinary code defects/);
190
199
  assert.match(prompt, /not "diff too large"/);
191
200
  });
192
- test("NOT-150: truncated-diff footer does not reject approved/changes_requested; forbids escalate-for-truncation", async () => {
201
+ test("NOT-630: truncated-diff footer names omissions and leaves non-truncation findings to the reviewer", async () => {
193
202
  const { formatDiffForPrompt, TOTAL_DIFF_LIMIT } = await import("./prompts.js");
194
203
  const big = "x".repeat(TOTAL_DIFF_LIMIT + 1);
195
204
  const diff = `diff --git a/small.ts b/small.ts\n+ok\n\ndiff --git a/huge.ts b/huge.ts\n+${big}\n`;
196
205
  const formatted = formatDiffForPrompt(diff);
197
206
  assert.equal(formatted.truncated, true);
198
207
  assert.ok(formatted.omittedPaths.some((p) => p.includes("huge.ts")));
199
- assert.match(formatted.text, /changes_requested/);
200
- assert.match(formatted.text, /Do NOT use "escalated" for truncation/);
201
- assert.doesNotMatch(formatted.text, /will not accept "approved" or "changes_requested"/);
208
+ assert.match(formatted.text, /Omitted: huge\.ts/);
209
+ assert.match(formatted.text, /Do not add a blocking finding or use "escalated" solely because files were omitted/);
210
+ assert.match(formatted.text, /coordinator sends an otherwise incomplete truncated review to the operator/);
211
+ });
212
+ test("NOT-630: a 450,000-character file reaches the reviewer without truncation", async () => {
213
+ const { formatDiffForPrompt, TOTAL_DIFF_LIMIT } = await import("./prompts.js");
214
+ assert.equal(TOTAL_DIFF_LIMIT, 600_000);
215
+ const body = "x".repeat(450_000);
216
+ const formatted = formatDiffForPrompt(`diff --git a/large.ts b/large.ts\n+${body}\n`);
217
+ assert.equal(formatted.truncated, false);
218
+ assert.deepEqual(formatted.omittedPaths, []);
219
+ assert.match(formatted.text, new RegExp(`${body.slice(0, 100)}$`));
202
220
  });
203
221
  test("reviewer prompt includes the developer's conclusion, checks summary, and prior findings when given", () => {
204
222
  const prompt = buildReviewerPrompt({
@@ -202,9 +202,8 @@ export function resolveProbeBin(runtime) {
202
202
  }
203
203
  }
204
204
  /**
205
- * Exact argv the real reviewer path would spawn for this probe prompt. Same
206
- * builder (`buildReviewerArgs`) and same ceiling (`roleCeiling("reviewer")`) as
207
- * production — the probe records it and `realReviewerSpawn` re-derives it.
205
+ * Reviewer argv from the same builder and role ceiling as production.
206
+ * Cursor's per-attempt prompt file is allocated later by realReviewerSpawn.
208
207
  */
209
208
  export function resolveProbeArgv(opts) {
210
209
  return buildReviewerArgs(opts.runtime, opts.prompt, opts.model, opts.policy ?? roleCeiling("reviewer"), opts.mcpConfigPath, opts.effort ?? null);