mandrel 2.70.0 → 2.72.0

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 (79) hide show
  1. package/.agents/README.md +8 -9
  2. package/.agents/agents/acceptance-critic.md +1 -0
  3. package/.agents/agents/auditor.md +1 -0
  4. package/.agents/agents/plan-critic.md +1 -0
  5. package/.agents/agents/story-worker.md +63 -64
  6. package/.agents/docs/agentrc-reference.json +2 -1
  7. package/.agents/docs/configuration.md +7 -8
  8. package/.agents/rules/git-conventions-reference.md +2 -2
  9. package/.agents/schemas/agentrc.schema.json +19 -2
  10. package/.agents/schemas/story-deliver-terminal.schema.json +10 -1
  11. package/.agents/scripts/acceptance-eval.js +194 -15
  12. package/.agents/scripts/deliver-run.js +92 -43
  13. package/.agents/scripts/lib/audit-suite/index.js +1 -1
  14. package/.agents/scripts/lib/audit-suite/story-checklist.js +65 -0
  15. package/.agents/scripts/lib/audit-to-stories/audit-label-taxonomy.js +2 -2
  16. package/.agents/scripts/lib/bootstrap/issue-forms-template.js +1 -1
  17. package/.agents/scripts/lib/cli-args.js +22 -0
  18. package/.agents/scripts/lib/close-validation/gates.js +17 -3
  19. package/.agents/scripts/lib/config/agent-models.js +117 -0
  20. package/.agents/scripts/lib/config-settings-schema-delivery.js +13 -1
  21. package/.agents/scripts/lib/config-settings-schema-quality.js +1 -1
  22. package/.agents/scripts/lib/generated/agentrc-validator.js +1 -1
  23. package/.agents/scripts/lib/git/sync-from-base.js +89 -17
  24. package/.agents/scripts/lib/label-taxonomy.js +13 -3
  25. package/.agents/scripts/lib/notifications/notifier.js +11 -15
  26. package/.agents/scripts/lib/observability/close-telemetry.js +19 -3
  27. package/.agents/scripts/lib/observability/source-classifier.js +1 -0
  28. package/.agents/scripts/lib/orchestration/cancelled-run-discount.js +129 -0
  29. package/.agents/scripts/lib/orchestration/code-review.js +2 -2
  30. package/.agents/scripts/lib/orchestration/deliver-recover.js +166 -34
  31. package/.agents/scripts/lib/orchestration/file-assumptions.js +45 -11
  32. package/.agents/scripts/lib/orchestration/plan-context.js +17 -10
  33. package/.agents/scripts/lib/orchestration/plan-persist/changes-repair.js +130 -24
  34. package/.agents/scripts/lib/orchestration/plan-persist/run-plan-persist.js +19 -16
  35. package/.agents/scripts/lib/orchestration/plan-persist/story-ops.js +1 -0
  36. package/.agents/scripts/lib/orchestration/plan-persist/summary.js +4 -3
  37. package/.agents/scripts/lib/orchestration/pr-watch.js +14 -3
  38. package/.agents/scripts/lib/orchestration/resolve-stories.js +10 -2
  39. package/.agents/scripts/lib/orchestration/review-providers/native.js +5 -165
  40. package/.agents/scripts/lib/orchestration/single-story-close/failed-terminal.js +14 -2
  41. package/.agents/scripts/lib/orchestration/single-story-close/phases/auto-merge.js +45 -0
  42. package/.agents/scripts/lib/orchestration/single-story-close/phases/base-sync.js +162 -58
  43. package/.agents/scripts/lib/orchestration/single-story-close/phases/confirm-merge.js +58 -6
  44. package/.agents/scripts/lib/orchestration/single-story-close/phases/merge-wait-recovery.js +296 -0
  45. package/.agents/scripts/lib/orchestration/single-story-close/phases/options.js +20 -4
  46. package/.agents/scripts/lib/orchestration/single-story-close/phases/post-land.js +52 -6
  47. package/.agents/scripts/lib/orchestration/single-story-close/phases/pull-request.js +2 -2
  48. package/.agents/scripts/lib/orchestration/single-story-close/phases/story-branch-catch-up.js +50 -0
  49. package/.agents/scripts/lib/orchestration/single-story-close/phases/worktree-reap.js +64 -52
  50. package/.agents/scripts/lib/orchestration/single-story-close/phases/worktree-restore.js +133 -0
  51. package/.agents/scripts/lib/orchestration/single-story-close/runner.js +187 -74
  52. package/.agents/scripts/lib/orchestration/story-deliver-terminal.js +46 -6
  53. package/.agents/scripts/lib/orchestration/story-handoff.js +849 -0
  54. package/.agents/scripts/lib/orchestration/story-init-result.js +83 -0
  55. package/.agents/scripts/lib/orchestration/task-body-validator.js +35 -5
  56. package/.agents/scripts/lib/orchestration/ticket-validator-sizing.js +1 -1
  57. package/.agents/scripts/lib/orchestration/ticket-validator.js +20 -2
  58. package/.agents/scripts/lib/single-story/confirm-merge.js +44 -7
  59. package/.agents/scripts/lib/story-body/story-body.js +40 -5
  60. package/.agents/scripts/lib/templates/decomposer-prompts.js +33 -36
  61. package/.agents/scripts/pr-watch-with-update.js +5 -0
  62. package/.agents/scripts/single-story-close.js +8 -0
  63. package/.agents/scripts/single-story-confirm-merge.js +34 -3
  64. package/.agents/scripts/single-story-init.js +17 -32
  65. package/.agents/scripts/story-handoff.js +112 -0
  66. package/.agents/scripts/sync-claude-agents.js +58 -27
  67. package/.agents/workflows/helpers/acceptance-self-eval.md +24 -18
  68. package/.agents/workflows/helpers/code-review.md +3 -3
  69. package/.agents/workflows/helpers/deliver-digest.md +79 -80
  70. package/.agents/workflows/helpers/deliver-light.md +9 -7
  71. package/.agents/workflows/helpers/deliver-reference.md +38 -22
  72. package/.agents/workflows/helpers/deliver-story-reference.md +39 -18
  73. package/.agents/workflows/helpers/deliver-story.md +30 -23
  74. package/.agents/workflows/helpers/plan-reference.md +24 -9
  75. package/.agents/workflows/helpers/worktree-lifecycle.md +5 -5
  76. package/docs/CHANGELOG.md +31 -0
  77. package/lib/cli/registry.js +7 -0
  78. package/package.json +4 -3
  79. package/.agents/scripts/lib/orchestration/review-providers/scoped-lint.js +0 -272
@@ -21,15 +21,10 @@ import {
21
21
  * Refuse when the declared baseline merge driver is unregistered: git would
22
22
  * text-merge generated baselines and silently land a wrong one on `main`.
23
23
  *
24
- * @param {string} cwd
25
- * @param {typeof defaultGitSpawn} gitSpawn
24
+ * @param {{ declared: boolean, command: string }} driver
26
25
  * @returns {{ synced: false, kind: 'merge-driver-missing', stderr: string, remedy: string }|null}
27
26
  */
28
- function refuseWithoutMergeDriver(cwd, gitSpawn) {
29
- const { declared, command } = probeBaselineMergeDriver({
30
- projectRoot: cwd,
31
- runGit: (args) => gitSpawn(cwd, ...args),
32
- });
27
+ function refuseWithoutMergeDriver({ declared, command }) {
33
28
  if (!declared || command.length > 0) return null;
34
29
  return {
35
30
  synced: false,
@@ -76,8 +71,41 @@ function diffPaths(gitSpawn, cwd, fromSha) {
76
71
  .filter((s) => s.length > 0);
77
72
  }
78
73
 
74
+ /** The paths `.gitattributes` routes through the driver: `baselines/*.json`. */
75
+ const DRIVER_OWNED_BASELINE = /^baselines\/[^/]+\.json$/;
76
+
79
77
  /**
80
- * A conflict is aborted before returning; the caller surfaces it.
78
+ * Take `origin/<base>`'s side of each conflicted baseline and commit the
79
+ * merge; the seat and close's gates re-derive the Story's rows. False on any
80
+ * failed step.
81
+ *
82
+ * @param {typeof defaultGitSpawn} gitSpawn
83
+ * @param {string} cwd
84
+ * @param {string} baseBranch
85
+ * @param {string[]} files
86
+ * @returns {boolean}
87
+ */
88
+ function resolveBaselinesToBase(gitSpawn, cwd, baseBranch, files) {
89
+ const steps = [
90
+ ['checkout', `origin/${baseBranch}`, '--', ...files],
91
+ ['add', '--', ...files],
92
+ ['commit', '--no-edit'],
93
+ ];
94
+ return steps.every((args) => gitSpawn(cwd, ...args).status === 0);
95
+ }
96
+
97
+ function unmergedPaths(gitSpawn, cwd) {
98
+ const unmerged = gitSpawn(cwd, 'diff', '--name-only', '--diff-filter=U');
99
+ return (unmerged.stdout ?? '')
100
+ .toString()
101
+ .split(/\r?\n/)
102
+ .map((s) => s.trim())
103
+ .filter((s) => s.length > 0);
104
+ }
105
+
106
+ /**
107
+ * A baseline-only conflict resolves to the base (`resolvedBaselineFiles`);
108
+ * any other conflict is aborted for the caller to surface.
81
109
  *
82
110
  * @param {object} opts
83
111
  * @param {string} opts.cwd Branch must already be checked out.
@@ -89,7 +117,7 @@ function diffPaths(gitSpawn, cwd, fromSha) {
89
117
  * @returns {Promise<
90
118
  * | { synced: true, kind: 'noop-already-current', changedPaths: string[] }
91
119
  * | { synced: true, kind: 'fast-forward', changedPaths: string[] }
92
- * | { synced: true, kind: 'merge-commit', changedPaths: string[] }
120
+ * | { synced: true, kind: 'merge-commit', changedPaths: string[], resolvedBaselineFiles?: string[] }
93
121
  * | { synced: false, kind: 'fetch-failed', stderr: string }
94
122
  * | { synced: false, kind: 'conflict', conflictFiles: string[] }
95
123
  * | { synced: false, kind: 'merge-failed', stderr: string }
@@ -111,7 +139,11 @@ export async function syncBranchFromBase({
111
139
  );
112
140
  }
113
141
 
114
- const driverGap = refuseWithoutMergeDriver(cwd, gitSpawn);
142
+ const driver = probeBaselineMergeDriver({
143
+ projectRoot: cwd,
144
+ runGit: (args) => gitSpawn(cwd, ...args),
145
+ });
146
+ const driverGap = refuseWithoutMergeDriver(driver);
115
147
  if (driverGap) {
116
148
  log('SYNC', driverGap.stderr);
117
149
  return driverGap;
@@ -166,16 +198,56 @@ export async function syncBranchFromBase({
166
198
  };
167
199
  }
168
200
 
169
- const unmerged = gitSpawn(cwd, 'diff', '--name-only', '--diff-filter=U');
170
- const conflictFiles = (unmerged.stdout ?? '')
171
- .toString()
172
- .split(/\r?\n/)
173
- .map((s) => s.trim())
174
- .filter((s) => s.length > 0);
201
+ const conflictFiles = unmergedPaths(gitSpawn, cwd);
202
+ const resolved = resolveBaselineOnlyConflict({
203
+ gitSpawn,
204
+ cwd,
205
+ baseBranch,
206
+ driver,
207
+ conflictFiles,
208
+ preMergeHead,
209
+ log,
210
+ });
211
+ if (resolved) return resolved;
175
212
 
176
- // Always abort: a half-merged worktree blocks the next recovery.
213
+ // A half-merged worktree blocks the next recovery.
177
214
  gitSpawn(cwd, 'merge', '--abort');
215
+ return failedMergeResult(conflictFiles, merge);
216
+ }
217
+
218
+ /** The resolved merge-commit result, or null for any other conflict. */
219
+ function resolveBaselineOnlyConflict({
220
+ gitSpawn,
221
+ cwd,
222
+ baseBranch,
223
+ driver,
224
+ conflictFiles,
225
+ preMergeHead,
226
+ log,
227
+ }) {
228
+ const baselineOnly =
229
+ driver.declared &&
230
+ conflictFiles.length > 0 &&
231
+ conflictFiles.every((f) => DRIVER_OWNED_BASELINE.test(f));
232
+ if (
233
+ !baselineOnly ||
234
+ !resolveBaselinesToBase(gitSpawn, cwd, baseBranch, conflictFiles)
235
+ ) {
236
+ return null;
237
+ }
238
+ log(
239
+ 'SYNC',
240
+ `Resolved baseline-only conflict to origin/${baseBranch}: ${conflictFiles.join(', ')}`,
241
+ );
242
+ return {
243
+ synced: true,
244
+ kind: 'merge-commit',
245
+ changedPaths: diffPaths(gitSpawn, cwd, preMergeHead),
246
+ resolvedBaselineFiles: conflictFiles,
247
+ };
248
+ }
178
249
 
250
+ function failedMergeResult(conflictFiles, merge) {
179
251
  if (conflictFiles.length > 0) {
180
252
  return { synced: false, kind: 'conflict', conflictFiles };
181
253
  }
@@ -32,13 +32,12 @@ export const LABEL_TAXONOMY = [
32
32
  name: AGENT_LABELS.REVIEW_SPEC,
33
33
  color: LABEL_COLORS.AGENT,
34
34
  description:
35
- 'Parking state — Tech Spec exists; awaiting human review before decomposition',
35
+ 'Parking state — awaiting planning before delivery; run /mandrel-plan <id>',
36
36
  },
37
37
  {
38
38
  name: AGENT_LABELS.READY,
39
39
  color: LABEL_COLORS.AGENT,
40
- description:
41
- 'Parking state — frozen dispatch manifest exists; awaiting local /mandrel-deliver',
40
+ description: 'Parking state — planned; awaiting local /mandrel-deliver',
42
41
  },
43
42
  {
44
43
  name: AGENT_LABELS.EXECUTING,
@@ -76,6 +75,17 @@ export const LABEL_TAXONOMY = [
76
75
  },
77
76
  ];
78
77
 
78
+ /**
79
+ * The repo-wide description for `name`, so another taxonomy that creates the
80
+ * same label carries this one instead of its own copy.
81
+ *
82
+ * @param {string} name
83
+ * @returns {string|undefined}
84
+ */
85
+ export function labelDescription(name) {
86
+ return LABEL_TAXONOMY.find((row) => row.name === name)?.description;
87
+ }
88
+
79
89
  /** @type {Array<{ name: string, type: 'single_select', options?: string[] }>} */
80
90
  export const PROJECT_FIELD_DEFS = [
81
91
  {
@@ -4,8 +4,9 @@
4
4
  * their event allowlists; severity is envelope metadata:
5
5
  * - low — routine progress; `transitionTicketState` skips `notify()`.
6
6
  * - medium — operator-visible milestones (Story/Epic done, merged).
7
- * - high — operator must act: webhook prefix `[Action Required]`, and
8
- * comments always `@mention` the operator.
7
+ * - high — operator must act (Story/Epic blocked): webhook prefix
8
+ * `[Action Required]`, and comments always `@mention` the
9
+ * operator.
9
10
  *
10
11
  * The webhook URL comes only from `process.env.NOTIFICATION_WEBHOOK_URL`,
11
12
  * never from `.agentrc.json` or `.mcp.json`.
@@ -16,9 +17,9 @@ import { AGENT_LABELS } from '../label-constants.js';
16
17
  export const SEVERITY_RANK = Object.freeze({ low: 0, medium: 1, high: 2 });
17
18
 
18
19
  /**
19
- * Only a Story/Epic reaching `agent::done` rates `medium`; transitions never
20
- * reach `high`, which is reserved for explicit operator-action `notify()`
21
- * calls.
20
+ * A Story/Epic entering `agent::blocked` rates `high` — the protocol's one
21
+ * runtime pause point, so the operator must act. A Story/Epic reaching
22
+ * `agent::done` rates `medium`. Every other transition is `low`.
22
23
  *
23
24
  * @param {{ kind?: string, ticket?: { type?: string }, toState?: string|null }} event
24
25
  */
@@ -26,6 +27,7 @@ export function eventSeverity(event) {
26
27
  if (event?.kind === 'state-transition') {
27
28
  const type = event.ticket?.type;
28
29
  const isStoryOrEpic = type === 'story' || type === 'epic';
30
+ if (isStoryOrEpic && event.toState === AGENT_LABELS.BLOCKED) return 'high';
29
31
  if (isStoryOrEpic && event.toState === AGENT_LABELS.DONE) return 'medium';
30
32
  }
31
33
  return 'low';
@@ -33,16 +35,10 @@ export function eventSeverity(event) {
33
35
 
34
36
  /** Used as both comment body and webhook text. */
35
37
  export function renderTransitionMessage(event) {
36
- const type = event.ticket?.type ?? 'ticket';
37
- const id = event.ticket?.id;
38
- const title = event.ticket?.title ?? '';
39
- const toState = event.toState ?? '';
40
- const fromState = event.fromState ?? '';
41
- let summary = fromState
42
- ? `${type} #${id} · \`${fromState}\` → \`${toState}\``
43
- : `${type} #${id} · → \`${toState}\``;
44
- if (title) summary += ` — ${title.slice(0, 80)}`;
45
- return summary;
38
+ const ticket = event.ticket ?? {};
39
+ const from = event.fromState ? `\`${event.fromState}\` ` : '';
40
+ const summary = `${ticket.type ?? 'ticket'} #${ticket.id} · ${from}→ \`${event.toState ?? ''}\``;
41
+ return ticket.title ? `${summary} — ${ticket.title.slice(0, 80)}` : summary;
46
42
  }
47
43
 
48
44
  export function resolveWebhookUrl() {
@@ -8,7 +8,7 @@
8
8
 
9
9
  import crypto from 'node:crypto';
10
10
 
11
- import { parseWorkerTokens } from '../cli-args.js';
11
+ import { parseWorkerModel, parseWorkerTokens } from '../cli-args.js';
12
12
  import { Logger } from '../Logger.js';
13
13
  import { EVENT_KINDS } from '../signals/schema.js';
14
14
  import {
@@ -246,13 +246,15 @@ async function readStoryTally({ storyId, config, readFn = forEachLine }) {
246
246
 
247
247
  /**
248
248
  * @param {{ storyId: number, config?: object, workerTokens?: number|null,
249
- * landed?: boolean, readFn?: typeof forEachLine }} args
249
+ * workerModel?: string|null, landed?: boolean,
250
+ * readFn?: typeof forEachLine }} args
250
251
  * @returns {Promise<object>}
251
252
  */
252
253
  async function buildCloseTelemetry({
253
254
  storyId,
254
255
  config,
255
256
  workerTokens = null,
257
+ workerModel = null,
256
258
  landed = false,
257
259
  readFn,
258
260
  }) {
@@ -265,6 +267,7 @@ async function buildCloseTelemetry({
265
267
  confirmedHaltsByProvider: confirmedHalts(tally, landed),
266
268
  },
267
269
  workerTokens: Number.isInteger(workerTokens) ? workerTokens : null,
270
+ workerModel,
268
271
  };
269
272
  }
270
273
 
@@ -296,12 +299,23 @@ export function resolveWorkerTokens(raw) {
296
299
  return tokens;
297
300
  }
298
301
 
302
+ /**
303
+ * @param {unknown} raw
304
+ * @returns {string|null}
305
+ */
306
+ export function resolveWorkerModel(raw) {
307
+ const { model, warning } = parseWorkerModel(raw);
308
+ if (warning) Logger.warn(`[single-story-close] ${warning}`);
309
+ return model;
310
+ }
311
+
299
312
  /**
300
313
  * The retry goes first so the summary counts it; a failure leaves
301
314
  * `telemetry: null` and the close's status untouched.
302
315
  *
303
316
  * @param {{ terminal: object, result?: object|null, config?: object,
304
- * workerTokens?: number|null, readFn?: typeof forEachLine }} args
317
+ * workerTokens?: number|null, workerModel?: string|null,
318
+ * readFn?: typeof forEachLine }} args
305
319
  * @returns {Promise<void>}
306
320
  */
307
321
  export async function recordCloseTelemetry({
@@ -309,6 +323,7 @@ export async function recordCloseTelemetry({
309
323
  result,
310
324
  config,
311
325
  workerTokens = null,
326
+ workerModel = null,
312
327
  readFn,
313
328
  }) {
314
329
  await emitCloseRetrySignal({ envelope: terminal, config });
@@ -318,6 +333,7 @@ export async function recordCloseTelemetry({
318
333
  storyId: result.storyId,
319
334
  config,
320
335
  workerTokens,
336
+ workerModel,
321
337
  landed: terminal?.status === 'landed',
322
338
  readFn,
323
339
  });
@@ -75,6 +75,7 @@ const FRAMEWORK_SCRIPT_BASENAMES = Object.freeze([
75
75
  'single-story-confirm-merge.js',
76
76
  'single-story-init.js',
77
77
  'stories-wave-tick.js',
78
+ 'story-handoff.js',
78
79
  'story-review-compute.js',
79
80
  'sync-agentrc.js',
80
81
  'sync-claude-agents.js',
@@ -0,0 +1,129 @@
1
+ // .agents/scripts/lib/orchestration/cancelled-run-discount.js
2
+ /**
3
+ * cancelled-run-discount.js — a red required check from a run that concluded
4
+ * `cancelled` takes the verdict of the newest other run of its workflow on
5
+ * the same head SHA. Every read fails closed: the red stands.
6
+ */
7
+
8
+ import { gh } from '../gh-exec.js';
9
+ import { checkVerdict } from './check-state.js';
10
+ import { parseWorkflowRunId } from './merge-poll.js';
11
+
12
+ const REPO_PLACEHOLDER = '{owner}/{repo}';
13
+
14
+ async function defaultGhApi(endpoint) {
15
+ const { stdout } = await gh.api({ endpoint });
16
+ return JSON.parse(stdout);
17
+ }
18
+
19
+ function repoSegment(repo) {
20
+ const trimmed = String(repo ?? '').trim();
21
+ return trimmed.length > 0 ? trimmed : REPO_PLACEHOLDER;
22
+ }
23
+
24
+ async function readJson(ghApiFn, endpoint) {
25
+ try {
26
+ const body = await ghApiFn(endpoint);
27
+ return body && typeof body === 'object' ? body : null;
28
+ } catch {
29
+ return null;
30
+ }
31
+ }
32
+
33
+ function parseCancelledRun(body) {
34
+ if (body?.conclusion !== 'cancelled') return null;
35
+ const headSha = body.head_sha;
36
+ const workflowId = body.workflow_id;
37
+ if (typeof headSha !== 'string' || headSha.length === 0) return null;
38
+ if (!Number.isInteger(workflowId) || workflowId < 1) return null;
39
+ return { headSha, workflowId };
40
+ }
41
+
42
+ /** Newest sibling by run id, never start time (the cancelled job starts later). */
43
+ function pickLiveSibling(body, cancelledRunId) {
44
+ const runs = Array.isArray(body?.workflow_runs) ? body.workflow_runs : [];
45
+ let newest = null;
46
+ for (const run of runs) {
47
+ const id = run?.id;
48
+ if (!Number.isInteger(id) || id === cancelledRunId) continue;
49
+ if (newest === null || id > newest.id) {
50
+ newest = {
51
+ id,
52
+ status: String(run.status ?? ''),
53
+ conclusion: String(run.conclusion ?? ''),
54
+ };
55
+ }
56
+ }
57
+ return newest;
58
+ }
59
+
60
+ /** @returns {'pending'|'success'|'failure'} */
61
+ function siblingOutcome(sibling) {
62
+ if (sibling.status !== 'completed') return 'pending';
63
+ return sibling.conclusion === 'success' ? 'success' : 'failure';
64
+ }
65
+
66
+ function lastEntryByName(entries) {
67
+ const byName = new Map();
68
+ for (const e of entries) byName.set(e.name, e);
69
+ return byName;
70
+ }
71
+
72
+ /**
73
+ * One per watcher invocation: a `cancelled` read is final, so it is cached
74
+ * per run id; the sibling list is re-read on every call.
75
+ *
76
+ * @returns {(entries: object[], outcomes: object) => Promise<object>}
77
+ */
78
+ export function createCancelledRunDiscount({
79
+ repo = null,
80
+ ghApiFn = defaultGhApi,
81
+ logger = {},
82
+ } = {}) {
83
+ const base = `repos/${repoSegment(repo)}/actions`;
84
+ const cancelledRuns = new Map();
85
+
86
+ async function readCancelledRun(runId) {
87
+ if (cancelledRuns.has(runId)) return cancelledRuns.get(runId);
88
+ const run = parseCancelledRun(
89
+ await readJson(ghApiFn, `${base}/runs/${runId}`),
90
+ );
91
+ if (run) cancelledRuns.set(runId, run);
92
+ return run;
93
+ }
94
+
95
+ async function discountOne(name, entry) {
96
+ const runId = parseWorkflowRunId(entry?.link);
97
+ if (runId === null) return null;
98
+ const run = await readCancelledRun(runId);
99
+ if (!run) return null;
100
+ const sibling = pickLiveSibling(
101
+ await readJson(
102
+ ghApiFn,
103
+ `${base}/workflows/${run.workflowId}/runs?head_sha=${run.headSha}`,
104
+ ),
105
+ runId,
106
+ );
107
+ if (!sibling) return null;
108
+ const outcome = siblingOutcome(sibling);
109
+ logger.info?.(
110
+ `[Watcher] required check "${name}" failed in concurrency-cancelled run ${runId}; ` +
111
+ `reading live run ${sibling.id} instead (${outcome}).`,
112
+ );
113
+ return outcome;
114
+ }
115
+
116
+ return async function discount(entries, outcomes) {
117
+ const red = Object.keys(outcomes).filter(
118
+ (name) => checkVerdict(outcomes[name]) === 'fail',
119
+ );
120
+ if (red.length === 0) return outcomes;
121
+ const byName = lastEntryByName(entries);
122
+ const out = { ...outcomes };
123
+ for (const name of red) {
124
+ const outcome = await discountOne(name, byName.get(name));
125
+ if (outcome !== null) out[name] = outcome;
126
+ }
127
+ return out;
128
+ };
129
+ }
@@ -143,8 +143,8 @@ function resolveProviderName(codeReviewConfig, reviewProvider) {
143
143
  /**
144
144
  * `opts.changedFiles` has three states: an array is used verbatim; `null`
145
145
  * means the caller already found the diff unenumerable (fail-safe tier, no
146
- * retry); absent means enumerate here. The close path always injects, so
147
- * review and lens pass agree on what changed.
146
+ * retry); absent means enumerate here. The close path always injects the
147
+ * change set it derived, so the review scores the same files close routed.
148
148
  */
149
149
  function resolveInjectedChangedFiles({ opts, baseRef, headRef }) {
150
150
  if (opts.changedFiles === undefined) {