mandrel 2.111.0 → 2.112.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 (178) hide show
  1. package/.agents/agents/acceptance-critic.md +14 -0
  2. package/.agents/agents/auditor.md +14 -0
  3. package/.agents/agents/plan-critic.md +5 -0
  4. package/.agents/agents/story-worker.md +4 -1
  5. package/.agents/docs/agentrc-reference.json +22 -10
  6. package/.agents/docs/configuration.md +351 -37
  7. package/.agents/docs/execution-reference.md +11 -0
  8. package/.agents/rules/git-conventions-reference.md +7 -0
  9. package/.agents/schemas/agentrc.schema.json +174 -14
  10. package/.agents/schemas/baselines/baseline-envelope.schema.json +16 -4
  11. package/.agents/schemas/baselines/bundle-size.schema.json +1 -0
  12. package/.agents/schemas/baselines/coverage.schema.json +1 -0
  13. package/.agents/schemas/baselines/crap.schema.json +37 -10
  14. package/.agents/schemas/baselines/duplication.schema.json +1 -0
  15. package/.agents/schemas/baselines/maintainability.schema.json +1 -0
  16. package/.agents/schemas/baselines/mutation.schema.json +1 -0
  17. package/.agents/schemas/crap-report.schema.json +6 -5
  18. package/.agents/schemas/story-deliver-terminal.schema.json +41 -2
  19. package/.agents/schemas/story-progress.schema.json +1 -1
  20. package/.agents/schemas/validation-evidence.schema.json +2 -2
  21. package/.agents/scripts/boot-sweep.js +41 -3
  22. package/.agents/scripts/coverage-capture.js +37 -3
  23. package/.agents/scripts/coverage-ratchet.js +106 -0
  24. package/.agents/scripts/evidence-gate.js +84 -21
  25. package/.agents/scripts/lib/audit-baselines/read.js +8 -1
  26. package/.agents/scripts/lib/audit-baselines/trend.js +2 -1
  27. package/.agents/scripts/lib/baseline-loader.js +4 -2
  28. package/.agents/scripts/lib/baselines/codec.js +57 -0
  29. package/.agents/scripts/lib/baselines/crap-preview-incremental.js +8 -3
  30. package/.agents/scripts/lib/baselines/crap-preview-scan.js +10 -16
  31. package/.agents/scripts/lib/baselines/crap-updater-cli.js +4 -13
  32. package/.agents/scripts/lib/baselines/kernel.js +19 -1
  33. package/.agents/scripts/lib/baselines/kinds/_crap-codec.js +171 -0
  34. package/.agents/scripts/lib/baselines/kinds/_crap-read.js +56 -16
  35. package/.agents/scripts/lib/baselines/kinds/_shared-metric.js +0 -59
  36. package/.agents/scripts/lib/baselines/kinds/crap.js +283 -319
  37. package/.agents/scripts/lib/baselines/preview-gates.js +29 -10
  38. package/.agents/scripts/lib/baselines/reader.js +36 -9
  39. package/.agents/scripts/lib/baselines/refresh-service.js +79 -18
  40. package/.agents/scripts/lib/baselines/seat-missing.js +173 -7
  41. package/.agents/scripts/lib/baselines/writer.js +36 -21
  42. package/.agents/scripts/lib/changed-files.js +70 -6
  43. package/.agents/scripts/lib/child-exec.js +10 -0
  44. package/.agents/scripts/lib/claude/agents-projection.js +5 -5
  45. package/.agents/scripts/lib/close-lock-events.js +8 -3
  46. package/.agents/scripts/lib/close-validation/ci-deferral.js +40 -0
  47. package/.agents/scripts/lib/close-validation/gates.js +111 -35
  48. package/.agents/scripts/lib/close-validation/process.js +16 -7
  49. package/.agents/scripts/lib/close-validation/projections/crap.js +43 -10
  50. package/.agents/scripts/lib/close-validation/runner.js +55 -23
  51. package/.agents/scripts/lib/close-validation/skip-branch-test.js +144 -0
  52. package/.agents/scripts/lib/close-validation/test-delta.js +33 -8
  53. package/.agents/scripts/lib/codex/agents-projection.js +6 -0
  54. package/.agents/scripts/lib/config/agentrc-overlay.js +9 -5
  55. package/.agents/scripts/lib/config/explain.js +5 -2
  56. package/.agents/scripts/lib/config/gates/coverage.schema.js +45 -1
  57. package/.agents/scripts/lib/config/gates/crap-incremental-coverage.schema.js +1 -1
  58. package/.agents/scripts/lib/config/git-roots.js +38 -4
  59. package/.agents/scripts/lib/config/handoff.js +24 -0
  60. package/.agents/scripts/lib/config/quality.js +26 -13
  61. package/.agents/scripts/lib/config/worktree-isolation.js +2 -5
  62. package/.agents/scripts/lib/config-resolver.js +22 -2
  63. package/.agents/scripts/lib/config-settings-schema-delivery.js +87 -4
  64. package/.agents/scripts/lib/config-settings-schema-quality.js +36 -1
  65. package/.agents/scripts/lib/config-settings-schema.js +1 -1
  66. package/.agents/scripts/lib/coverage-capture-affected.js +1 -0
  67. package/.agents/scripts/lib/coverage-capture-delta.js +164 -32
  68. package/.agents/scripts/lib/coverage-capture-own-fix.js +232 -0
  69. package/.agents/scripts/lib/coverage-capture-usage.js +2 -2
  70. package/.agents/scripts/lib/coverage-capture.js +15 -0
  71. package/.agents/scripts/lib/coverage-deferral.js +96 -0
  72. package/.agents/scripts/lib/coverage-ratchet.js +187 -0
  73. package/.agents/scripts/lib/crap-baseline-join.js +5 -5
  74. package/.agents/scripts/lib/crap-engine.js +3 -3
  75. package/.agents/scripts/lib/crap-method-identity.js +104 -48
  76. package/.agents/scripts/lib/escomplex-anchor.js +135 -0
  77. package/.agents/scripts/lib/escomplex-kernel.js +30 -1
  78. package/.agents/scripts/lib/failure-rows.js +121 -0
  79. package/.agents/scripts/lib/full-suite-lock.js +44 -4
  80. package/.agents/scripts/lib/full-suite-queue.js +89 -13
  81. package/.agents/scripts/lib/generated/agentrc-validator.js +8 -2
  82. package/.agents/scripts/lib/gh-env.js +3 -6
  83. package/.agents/scripts/lib/gh-pr-rest.js +1 -0
  84. package/.agents/scripts/lib/git/base-sync-probe.js +182 -0
  85. package/.agents/scripts/lib/git-branch-lifecycle.js +9 -0
  86. package/.agents/scripts/lib/observability/close-telemetry.js +37 -2
  87. package/.agents/scripts/lib/observability/handoff-telemetry.js +170 -0
  88. package/.agents/scripts/lib/observability/review-dispositions.js +23 -6
  89. package/.agents/scripts/lib/observability/runtime-friction.js +17 -4
  90. package/.agents/scripts/lib/observability/source-classifier.js +3 -0
  91. package/.agents/scripts/lib/observability/story-outcome.js +393 -0
  92. package/.agents/scripts/lib/orchestration/check-baselines/phases/compare.js +2 -1
  93. package/.agents/scripts/lib/orchestration/check-baselines/phases/evaluate.js +19 -1
  94. package/.agents/scripts/lib/orchestration/check-baselines/phases/fail-detail.js +84 -0
  95. package/.agents/scripts/lib/orchestration/check-baselines/phases/pipeline.js +14 -5
  96. package/.agents/scripts/lib/orchestration/check-baselines/phases/refresh-ack.js +3 -2
  97. package/.agents/scripts/lib/orchestration/check-baselines/phases/report.js +26 -6
  98. package/.agents/scripts/lib/orchestration/code-review.js +223 -19
  99. package/.agents/scripts/lib/orchestration/handoff-gates.js +129 -62
  100. package/.agents/scripts/lib/orchestration/handoff-rescore.js +169 -0
  101. package/.agents/scripts/lib/orchestration/handoff-suite-of-record.js +45 -0
  102. package/.agents/scripts/lib/orchestration/preflight-lanes.js +208 -0
  103. package/.agents/scripts/lib/orchestration/review-base-ref.js +40 -17
  104. package/.agents/scripts/lib/orchestration/review-deposit.js +38 -12
  105. package/.agents/scripts/lib/orchestration/review-depth.js +21 -0
  106. package/.agents/scripts/lib/orchestration/review-history.js +124 -20
  107. package/.agents/scripts/lib/orchestration/review-providers/claude-verdict.js +23 -8
  108. package/.agents/scripts/lib/orchestration/review-providers/code-review.js +82 -39
  109. package/.agents/scripts/lib/orchestration/review-providers/critical-verifier.js +64 -11
  110. package/.agents/scripts/lib/orchestration/review-providers/degraded-gates.js +98 -3
  111. package/.agents/scripts/lib/orchestration/review-providers/finding-identity.js +6 -2
  112. package/.agents/scripts/lib/orchestration/review-providers/findings-renderer.js +55 -8
  113. package/.agents/scripts/lib/orchestration/review-providers/review-guidance.js +1 -0
  114. package/.agents/scripts/lib/orchestration/review-providers/review-provider-factory.js +42 -15
  115. package/.agents/scripts/lib/orchestration/review-providers/types.js +6 -0
  116. package/.agents/scripts/lib/orchestration/single-story-close/failed-terminal.js +10 -1
  117. package/.agents/scripts/lib/orchestration/single-story-close/gate-log.js +10 -0
  118. package/.agents/scripts/lib/orchestration/single-story-close/phases/base-sync.js +7 -4
  119. package/.agents/scripts/lib/orchestration/single-story-close/phases/close-validation.js +15 -3
  120. package/.agents/scripts/lib/orchestration/single-story-close/phases/code-review.js +59 -2
  121. package/.agents/scripts/lib/orchestration/single-story-close/phases/confirm-merge.js +6 -0
  122. package/.agents/scripts/lib/orchestration/single-story-close/phases/finish.js +15 -4
  123. package/.agents/scripts/lib/orchestration/single-story-close/phases/land-review-record.js +213 -0
  124. package/.agents/scripts/lib/orchestration/single-story-close/phases/normalize-pr-title.js +9 -12
  125. package/.agents/scripts/lib/orchestration/single-story-close/phases/open-pr.js +26 -12
  126. package/.agents/scripts/lib/orchestration/single-story-close/phases/post-land.js +51 -26
  127. package/.agents/scripts/lib/orchestration/single-story-close/phases/pre-push.js +3 -2
  128. package/.agents/scripts/lib/orchestration/single-story-close/phases/pull-request.js +50 -17
  129. package/.agents/scripts/lib/orchestration/single-story-close/phases/push.js +59 -11
  130. package/.agents/scripts/lib/orchestration/single-story-close/phases/reconcile-done.js +1 -0
  131. package/.agents/scripts/lib/orchestration/single-story-close/phases/review-block.js +31 -13
  132. package/.agents/scripts/lib/orchestration/single-story-close/phases/review-halt.js +29 -6
  133. package/.agents/scripts/lib/orchestration/single-story-close/phases/review-outcome.js +10 -12
  134. package/.agents/scripts/lib/orchestration/single-story-close/phases/review-override.js +19 -4
  135. package/.agents/scripts/lib/orchestration/single-story-close/result.js +30 -13
  136. package/.agents/scripts/lib/orchestration/single-story-close/review-overlap.js +73 -39
  137. package/.agents/scripts/lib/orchestration/single-story-close/runner.js +11 -3
  138. package/.agents/scripts/lib/orchestration/story-close/baseline-upward-writeback.js +3 -2
  139. package/.agents/scripts/lib/orchestration/story-close/duplication-close-rescore.js +20 -8
  140. package/.agents/scripts/lib/orchestration/story-deliver-terminal.js +7 -0
  141. package/.agents/scripts/lib/orchestration/story-handoff.js +774 -196
  142. package/.agents/scripts/lib/orchestration/ticketing/reads.js +2 -0
  143. package/.agents/scripts/lib/pr-body-lines.js +32 -0
  144. package/.agents/scripts/lib/single-story/ci-ratchet-gate.js +140 -0
  145. package/.agents/scripts/lib/single-story/confirm-and-land.js +17 -7
  146. package/.agents/scripts/lib/single-story/confirm-merge.js +12 -3
  147. package/.agents/scripts/lib/single-story-sweep/report-stalled-executing.js +202 -0
  148. package/.agents/scripts/lib/standalone-ratchets.js +37 -0
  149. package/.agents/scripts/lib/suite-admission.js +20 -8
  150. package/.agents/scripts/lib/suite-sizing.js +146 -0
  151. package/.agents/scripts/lib/workspace-provisioner.js +2 -2
  152. package/.agents/scripts/merge-baseline.js +14 -3
  153. package/.agents/scripts/providers/github/comments.js +19 -3
  154. package/.agents/scripts/providers/github.js +1 -0
  155. package/.agents/scripts/review-dispositions-report.js +1 -1
  156. package/.agents/scripts/role-scope-guard.js +267 -0
  157. package/.agents/scripts/single-story-close.js +4 -4
  158. package/.agents/scripts/single-story-confirm-merge.js +31 -5
  159. package/.agents/scripts/single-story-init.js +24 -4
  160. package/.agents/scripts/story-handoff.js +3 -3
  161. package/.agents/scripts/story-outcomes-report.js +231 -0
  162. package/.agents/scripts/story-review-compute.js +9 -5
  163. package/.agents/scripts/update-coverage-baseline.js +12 -2
  164. package/.agents/scripts/update-crap-baseline.js +9 -1
  165. package/.agents/workflows/helpers/code-review.md +63 -9
  166. package/.agents/workflows/helpers/deliver-digest.md +53 -54
  167. package/.agents/workflows/helpers/deliver-reference.md +233 -67
  168. package/.agents/workflows/helpers/deliver-story-reference.md +19 -8
  169. package/.agents/workflows/helpers/deliver-story.md +7 -2
  170. package/.agents/workflows/helpers/parallel-tooling.md +29 -0
  171. package/docs/CHANGELOG.md +46 -0
  172. package/lib/cli/doctor-checks/coverage-ratchet.js +54 -0
  173. package/lib/cli/doctor-checks/effective-agentrc.js +23 -0
  174. package/lib/cli/doctor-checks/llm-review.js +2 -11
  175. package/lib/cli/doctor-checks/sync-parity.js +5 -1
  176. package/lib/cli/doctor-checks/test-credit-path.js +7 -2
  177. package/lib/cli/registry.js +5 -0
  178. package/package.json +1 -1
@@ -1,19 +1,23 @@
1
1
  /**
2
2
  * The Story-scope review, overlapped with the close-validation gates: started
3
3
  * once the pre-gate self-heal commits land and held (computed, never posted)
4
- * until the PR exists. A worker deposit whose diff digest matches the diff at
5
- * that point **is** the held result, so nothing is computed. After PR-open a
6
- * pushed diff with a different digest discards it for a serial review — a
7
- * clean base-sync merge moves HEAD without changing the digest. The held
8
- * promise never rejects, so an abandoned review leaves no unhandled rejection.
4
+ * until the PR exists. A deposit whose diff digest matches the diff at that
5
+ * point **is** the held result, so nothing is computed. After PR-open a
6
+ * pushed diff with a different digest discards it for a serial review of the
7
+ * pushed SHA — a base-sync merge that moves only offsets keeps the digest.
8
+ * Every non-degraded review close computes is deposited when it settles, so a
9
+ * retry on the same diff adopts it. The held promise never rejects, so an
10
+ * abandoned review leaves no unhandled rejection.
9
11
  */
10
12
 
11
13
  import { postReviewComment } from '../code-review.js';
12
14
  import {
15
+ buildReviewDeposit,
13
16
  computeReviewDiffDigest,
14
17
  depositAsComputedReview,
15
18
  probeHeldReviewDiff,
16
19
  resolveRefSha,
20
+ writeReviewDeposit,
17
21
  } from '../review-deposit.js';
18
22
  import { upsertStructuredComment } from '../ticketing.js';
19
23
  import {
@@ -29,33 +33,76 @@ function resolveBranchSha({ cwd, storyBranch, gitSpawnFn }) {
29
33
  return resolveRefSha({ cwd, ref: storyBranch, gitSpawnFn });
30
34
  }
31
35
 
32
- /** A held result already in hand: the worker deposit. */
36
+ /** A held result already in hand: the deposit. */
33
37
  function adoptedSettlement(deposit, atMs) {
34
38
  const value = depositAsComputedReview(deposit);
35
39
  return Promise.resolve({ ok: true, value, endedAtMs: atMs });
36
40
  }
37
41
 
38
- /** Compute the review of `sha`, held unposted; never rejects. */
39
- function computeHeldReview({ sha, nowMs, ...args }) {
42
+ /** Deposit a computed result; a failed write is a warning, never a failure. */
43
+ function depositReview(args, held, result) {
44
+ if (!result || result.degraded || !held.diffDigest) return;
45
+ const { writeDepositFn = writeReviewDeposit, progress } = args;
46
+ try {
47
+ const deposit = buildReviewDeposit({
48
+ storyId: Number(args.storyId),
49
+ headSha: held.sha,
50
+ baseRef: held.baseRef,
51
+ diffDigest: held.diffDigest,
52
+ result,
53
+ });
54
+ writeDepositFn(deposit, { config: args.config });
55
+ } catch (err) {
56
+ progress(
57
+ 'REVIEW',
58
+ `⚠️ Could not deposit the Story-scope review: ${err?.message ?? err}`,
59
+ );
60
+ }
61
+ }
62
+
63
+ /** Compute the review of `held.sha`, held unposted; never rejects. */
64
+ function computeHeldReview(args, held) {
65
+ const { nowMs = Date.now } = args;
40
66
  return computeStoryScopeReview({
41
67
  ...args,
42
- headRef: sha,
68
+ headRef: held.sha,
43
69
  deferPost: true,
44
70
  }).then(
45
- (value) => ({ ok: true, value, endedAtMs: nowMs() }),
71
+ (value) => {
72
+ const endedAtMs = nowMs();
73
+ depositReview(args, held, value.result);
74
+ return { ok: true, value, endedAtMs };
75
+ },
46
76
  (error) => ({ ok: false, error, endedAtMs: nowMs() }),
47
77
  );
48
78
  }
49
79
 
80
+ /** Adopt the matching deposit for `sha`, else compute (and deposit) it. */
81
+ function holdReview(args, sha) {
82
+ const { progress, nowMs = Date.now } = args;
83
+ const { baseRef, diffDigest, deposit } = probeHeldReviewDiff({
84
+ ...args,
85
+ sha,
86
+ });
87
+ const startedAtMs = nowMs();
88
+ const held = { sha, baseRef, diffDigest, adopted: !!deposit, startedAtMs };
89
+ if (deposit) {
90
+ progress('REVIEW', `♻️ Adopting the deposited review; none computed.`);
91
+ return { ...held, settled: adoptedSettlement(deposit, startedAtMs) };
92
+ }
93
+ return { ...held, settled: computeHeldReview(args, held) };
94
+ }
95
+
50
96
  /**
51
97
  * @param {{ cwd: string, storyId: number, storyBranch: string,
52
98
  * baseBranch: string, provider: object, runCodeReviewFn: Function,
53
99
  * gitSpawnFn: Function, progress: Function, config?: object,
54
- * readDepositFn?: Function, nowMs?: () => number }} args
100
+ * readDepositFn?: Function, writeDepositFn?: Function,
101
+ * nowMs?: () => number }} args
55
102
  * @returns {HeldReview|null} null when the SHA is unresolvable.
56
103
  */
57
104
  export function startHeldReview(args) {
58
- const { cwd, storyBranch, gitSpawnFn, progress, nowMs = Date.now } = args;
105
+ const { cwd, storyBranch, gitSpawnFn, progress } = args;
59
106
  const sha = resolveBranchSha({ cwd, storyBranch, gitSpawnFn });
60
107
  if (!sha) {
61
108
  progress(
@@ -64,18 +111,7 @@ export function startHeldReview(args) {
64
111
  );
65
112
  return null;
66
113
  }
67
- const { baseRef, diffDigest, deposit } = probeHeldReviewDiff({
68
- ...args,
69
- sha,
70
- });
71
- const startedAtMs = nowMs();
72
- const held = { sha, baseRef, diffDigest, adopted: !!deposit, startedAtMs };
73
- if (deposit) {
74
- progress('REVIEW', `♻️ Adopting the worker's held review; none computed.`);
75
- return { ...held, settled: adoptedSettlement(deposit, startedAtMs) };
76
- }
77
- const settled = computeHeldReview({ ...args, sha, nowMs });
78
- return { ...held, settled };
114
+ return holdReview(args, sha);
79
115
  }
80
116
 
81
117
  /** Drop a held review unposted. */
@@ -115,19 +151,28 @@ async function postHeldReview(held, args) {
115
151
  }
116
152
  }
117
153
 
154
+ /** Review `sha` and post it; the branch name only when no SHA or PR. */
155
+ function reviewSerially(args, sha) {
156
+ if (args.prNumber == null || !sha) return runStoryScopeReview(args);
157
+ args.pauseTimer();
158
+ return postHeldReview(holdReview(args, sha), args);
159
+ }
160
+
118
161
  /**
119
- * Post a held review whose diff digest matches the pushed diff (phase
120
- * untimed: it records its own wall time), else run the serial review.
162
+ * Post a held review whose diff digest matches the pushed diff, else review
163
+ * the pushed SHA serially (deposited before it posts). Either phase is
164
+ * untimed: the review records its own wall time.
121
165
  *
122
166
  * @returns {Promise<object>} the review outcome.
123
167
  */
124
168
  export async function reviewAfterPrOpen(args) {
125
169
  const { held, setPhase, progress } = args;
170
+ const sha = resolveBranchSha(args);
126
171
  if (held && args.prNumber != null) {
127
172
  const pushedDigest = computeReviewDiffDigest({
128
173
  cwd: args.cwd,
129
174
  baseRef: held.baseRef,
130
- headRef: resolveBranchSha(args),
175
+ headRef: sha,
131
176
  gitSpawnFn: args.gitSpawnFn,
132
177
  });
133
178
  if (pushedDigest !== null && pushedDigest === held.diffDigest) {
@@ -146,16 +191,5 @@ export async function reviewAfterPrOpen(args) {
146
191
  );
147
192
  }
148
193
  setPhase('code-review');
149
- return await runStoryScopeReview({
150
- cwd: args.cwd,
151
- storyId: args.storyId,
152
- storyBranch: args.storyBranch,
153
- baseBranch: args.baseBranch,
154
- prUrl: args.prUrl,
155
- prNumber: args.prNumber,
156
- provider: args.provider,
157
- runCodeReviewFn: args.runCodeReviewFn,
158
- gitSpawnFn: args.gitSpawnFn,
159
- progress,
160
- });
194
+ return await reviewSerially(args, sha);
161
195
  }
@@ -363,13 +363,18 @@ function landedPrePush(ctx) {
363
363
  lockWait: null,
364
364
  suiteTimings: null,
365
365
  pending: false,
366
- coverageDeferred: false,
366
+ coverageDeferred: null,
367
367
  };
368
368
  return null;
369
369
  }
370
370
 
371
371
  function landedPr(ctx) {
372
- ctx.pr = { ...ctx.landedPr, alreadyMerged: true, reviewOverride: null };
372
+ ctx.pr = {
373
+ ...ctx.landedPr,
374
+ alreadyMerged: true,
375
+ reviewOverride: null,
376
+ reviewSkipped: true,
377
+ };
373
378
  return null;
374
379
  }
375
380
 
@@ -449,12 +454,15 @@ function buildPrContext(ctx, deps) {
449
454
  phaseTimer: ctx.phaseTimer,
450
455
  worker: ctx.worker,
451
456
  lockWait: ctx.prePush.lockWait,
457
+ baseSync: ctx.baseSync?.decision ?? null,
458
+ pushOutcome: ctx.pr.pushOutcome ?? null,
452
459
  suiteTimings: envelopeSuiteTimings(ctx, deps),
453
460
  gates: closeEnvelopeGates(
454
461
  options,
455
462
  ctx.prePush.validationGates,
456
463
  ctx.pr.reviewOverride,
457
- ctx.pr.reviewDegraded,
464
+ ctx.pr.reviewDegradations,
465
+ { reviewSkipped: ctx.pr.reviewSkipped === true },
458
466
  ),
459
467
  };
460
468
  }
@@ -7,8 +7,9 @@
7
7
  * Invariants:
8
8
  * 1. Only classifier `improvements` are written — a regression never enters
9
9
  * the written set, so it still fails the gate.
10
- * 2. Maintainability only: CRAP rows re-key on `method@startLine` when code
11
- * above moves, so write-back there is churn.
10
+ * 2. Maintainability only: CRAP is coverage-derived and flaps under
11
+ * non-deterministic V8 instrumentation, so writing its improvements
12
+ * back would ratchet the baseline on noise.
12
13
  * 3. Changed files only — a full-scope write would absorb other branches'
13
14
  * drift into whichever PR lands next.
14
15
  * 4. Idempotent: no empty commit.
@@ -31,7 +31,7 @@ const TAG = '[duplication-rescore]';
31
31
 
32
32
  const KIND = 'duplication';
33
33
 
34
- const DEFAULT_BASELINE_REL_PATH = 'baselines/duplication.json';
34
+ export const DEFAULT_BASELINE_REL_PATH = 'baselines/duplication.json';
35
35
 
36
36
  /**
37
37
  * Untagged on purpose (see the module header): never `baseline-refresh:`.
@@ -63,9 +63,20 @@ function buildCommitBody(moved) {
63
63
  * @param {object} logger
64
64
  * @param {string} reason
65
65
  */
66
- function skip(logger, reason) {
66
+ function skip(logger, reason, extra = {}) {
67
67
  logger.info?.(`${TAG} no re-score commit (${reason}).`);
68
- return { ran: false, committed: false, reason };
68
+ return { ran: false, committed: false, reason, ...extra };
69
+ }
70
+
71
+ /** A completed scan that moved nothing still reports its clone partners. */
72
+ function unchanged(logger, partners) {
73
+ return skip(logger, 'unchanged', { moved: [], partners });
74
+ }
75
+
76
+ /** @returns {object} a committed re-score's result. */
77
+ function committedResult(sha, moved, partners) {
78
+ const movedPaths = moved.map((m) => m.path);
79
+ return { ran: true, committed: true, sha, movedPaths, moved, partners };
69
80
  }
70
81
 
71
82
  /**
@@ -185,7 +196,8 @@ async function attempt(fn, label) {
185
196
  * refreshBaseline?: typeof defaultRefreshBaseline,
186
197
  * scorer?: (files: string[], opts: object) => Promise<object[]>|object[],
187
198
  * }} opts
188
- * @returns {Promise<{ ran: boolean, committed: boolean, sha?: string, movedPaths?: string[], reason?: string }>}
199
+ * @returns {Promise<{ ran: boolean, committed: boolean, sha?: string, movedPaths?: string[], reason?: string, moved?: Array<{ path: string, before: number|null, after: number|null }>, partners?: Record<string, string[]> }>}
200
+ * `moved` and `partners` (write-scope clone partners) whenever a scan completed.
189
201
  */
190
202
  export async function runDuplicationCloseRescore({
191
203
  cwd,
@@ -245,7 +257,8 @@ export async function runDuplicationCloseRescore({
245
257
  'scorer-failed',
246
258
  );
247
259
  if (refreshed.reason) return skip(logger, refreshed.reason);
248
- if (!refreshed.value?.wrote) return skip(logger, 'unchanged');
260
+ const { partners = {} } = refreshed.value;
261
+ if (!refreshed.value.wrote) return unchanged(logger, partners);
249
262
 
250
263
  const moved = diffScopedRows({
251
264
  files: refreshed.value.scope?.files ?? files,
@@ -264,9 +277,8 @@ export async function runDuplicationCloseRescore({
264
277
  'git-failed',
265
278
  );
266
279
  if (committed.reason) return skip(logger, committed.reason);
267
- const movedPaths = moved.map((m) => m.path);
268
280
  logger.warn?.(
269
- `${TAG} re-scored ${movedPaths.length} duplication row(s) on story #${storyId}; committed as ${committed.value}.`,
281
+ `${TAG} re-scored ${moved.length} duplication row(s) on story #${storyId}; committed as ${committed.value}.`,
270
282
  );
271
- return { ran: true, committed: true, sha: committed.value, movedPaths };
283
+ return committedResult(committed.value, moved, partners);
272
284
  }
@@ -118,6 +118,9 @@ function compact(obj) {
118
118
  * Full-suite lock wait; `waitBudget` is merge-wait only.
119
119
  * @param {{ lockWaitMs: number, hostWaitMs: number|null, testRunMs: number, source: 'close'|'credited-run', spawns: object[] }|null} [args.suiteTimings]
120
120
  * @param {Record<string, number>|null} [args.phaseDurations] Seconds per phase.
121
+ * @param {{ mode: string, outcome: string, reason: string, incoming: number }|null} [args.baseSync]
122
+ * Close's base-sync decision; `null` when no sync ran, absent when not passed.
123
+ * @param {'pushed'|'skipped-already-at-head'|null} [args.pushOutcome]
121
124
  * @param {string} [args.timestamp]
122
125
  * @param {{ schema: object|null, error: string|null }} [args.schemaSource]
123
126
  * Test seam.
@@ -141,6 +144,8 @@ export function buildTerminalEnvelope({
141
144
  lockWait,
142
145
  suiteTimings,
143
146
  phaseDurations,
147
+ baseSync,
148
+ pushOutcome,
144
149
  timestamp = new Date().toISOString(),
145
150
  schemaSource,
146
151
  }) {
@@ -164,6 +169,8 @@ export function buildTerminalEnvelope({
164
169
  lockWait: lockWait ?? null,
165
170
  suiteTimings: suiteTimings ?? null,
166
171
  phaseDurations,
172
+ baseSync,
173
+ pushOutcome,
167
174
  timestamp,
168
175
  });
169
176