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,17 +1,14 @@
1
1
  /**
2
- * Per-kind module for the CRAP baseline. Row shape:
3
- * `{ path, method, startLine, crap }`.
2
+ * Per-kind module for the CRAP baseline. In-memory row shape:
3
+ * `{ path, method, crap }`; on disk the rows are grouped by path (see
4
+ * `_crap-codec.js`). `startLine` lives on scan rows only.
4
5
  */
5
6
 
6
7
  import path from 'node:path';
7
8
  import { fileURLToPath } from 'node:url';
8
9
  import { COVERAGE_CAPTURE_DEFAULTS } from '../../config/gates/coverage.schema.js';
9
- import {
10
- COORDINATE_ORIGINAL,
11
- COORDINATE_TRANSPILED,
12
- deriveFixGuidance,
13
- } from '../../crap-engine.js';
14
- import { isAnonymousMethodLabel } from '../../crap-method-identity.js';
10
+ import { deriveFixGuidance } from '../../crap-engine.js';
11
+ import { methodStem } from '../../crap-method-identity.js';
15
12
  import { resolveEscomplexVersion } from '../../crap-utils.js';
16
13
  import { Logger } from '../../Logger.js';
17
14
  import { resolveTsTranspilerVersion } from '../../transpile.js';
@@ -22,15 +19,16 @@ import {
22
19
  } from '../envelope.js';
23
20
  import { canonicalise } from '../path-canon.js';
24
21
  import { mergeRowsByScope } from '../scope.js';
22
+ import { compareCrapRows } from './_crap-codec.js';
25
23
  import {
26
24
  buildNewViolation,
27
25
  deriveUncoveredFiles,
28
26
  formatNewViolationMeasure,
29
27
  newMethodGateScore,
30
28
  } from './_crap-new-method-gate.js';
29
+ import { classifyScoringSemantics, SCORING_SEMANTICS } from './_crap-read.js';
31
30
  import {
32
31
  makeAggregate,
33
- makeCompare,
34
32
  makeEpsilon,
35
33
  makeRollup,
36
34
  percentile,
@@ -39,7 +37,7 @@ import {
39
37
  export const name = 'crap';
40
38
  export const keyField = 'path';
41
39
 
42
- export { loadCrapBaseline } from './_crap-read.js';
40
+ export { aheadStampOf, loadCrapBaseline } from './_crap-read.js';
43
41
 
44
42
  const __filename = fileURLToPath(import.meta.url);
45
43
 
@@ -55,75 +53,34 @@ export function kernelVersion() {
55
53
  return resolveEscomplexVersion(path.dirname(__filename));
56
54
  }
57
55
 
58
- /**
59
- * Scoring-semantics stamp. The scorer version does not move when this repo's
60
- * coverage join changes, yet rows scored under different joins are not
61
- * comparable (phantom regressions and phantom passes), so the stamp fails
62
- * closed across that boundary. Bump it whenever the coverage join, the line
63
- * coordinate system, the unresolved-method policy, or the method identity
64
- * rule changes. Module-local: read it via `envelopeExtras().scoringSemantics`.
65
- */
66
- const SCORING_SEMANTICS = 'method-identity-v3';
67
-
68
56
  /**
69
57
  * Envelope stamps this kind adds, consumed by `writer.write`. A transpiler
70
- * change can move every TS row's `startLine` (half the row identity key), so
71
- * `tsTranspilerVersion` is stamped for the `ts-transpiler-drift` axis.
72
- * `provenanceStamped` is a positive marker that per-row provenance was
73
- * recorded; no other stamp can detect its absence. `ctx` carries the scan's
74
- * `cwd` / `targetDirs` so the stamp names the compiler the scorer resolved.
58
+ * change can rename or re-nest emitted methods, which moves scope-path keys,
59
+ * so `tsTranspilerVersion` is stamped for the `ts-transpiler-drift` axis.
60
+ * `ctx` carries the scan's `cwd` / `targetDirs` so the stamp names the
61
+ * compiler the scorer resolved.
75
62
  *
76
63
  * @param {{ cwd?: string, targetDirs?: string[] }} [ctx]
77
- * @returns {{scoringSemantics: string, tsTranspilerVersion: string,
78
- * provenanceStamped: boolean}}
64
+ * @returns {{scoringSemantics: string, tsTranspilerVersion: string}}
79
65
  */
80
66
  export function envelopeExtras(ctx = {}) {
81
67
  return {
82
68
  scoringSemantics: SCORING_SEMANTICS,
83
69
  tsTranspilerVersion: resolveTsTranspilerVersion(ctx),
84
- provenanceStamped: true,
85
70
  };
86
71
  }
87
72
 
88
- /**
89
- * Project a scan row onto the persisted row shape. `coordinateSystem` and
90
- * `anonymous` are written only when non-default, so a plain JS row stays the
91
- * four-key row and existing baselines stay byte-identical.
92
- */
73
+ /** Project a scan row onto the persisted row shape. */
93
74
  export function projectRow(row) {
94
- const projected = {
75
+ return {
95
76
  path: canonicalise(row.path ?? row.file),
96
77
  method: row.method,
97
- startLine: row.startLine,
98
78
  crap: row.crap,
99
79
  };
100
- if (row.coordinateSystem === COORDINATE_TRANSPILED) {
101
- projected.coordinateSystem = COORDINATE_TRANSPILED;
102
- }
103
- // `anonymous`: `method` is a derived scope-path identity, not a source name.
104
- if (row.anonymous === true) {
105
- projected.anonymous = true;
106
- }
107
- return projected;
108
- }
109
-
110
- /**
111
- * A row's coordinate provenance. An unstamped row is always an
112
- * original-source coordinate, so the default is sound, not a guess.
113
- *
114
- * @param {{coordinateSystem?: string}|null|undefined} row
115
- * @returns {string}
116
- */
117
- function coordinateSystemOf(row) {
118
- return row?.coordinateSystem ?? COORDINATE_ORIGINAL;
119
80
  }
120
81
 
121
82
  export function sortRows(rows) {
122
- return [...rows].sort((a, b) => {
123
- if (a.path !== b.path) return a.path.localeCompare(b.path);
124
- if (a.startLine !== b.startLine) return a.startLine - b.startLine;
125
- return a.method.localeCompare(b.method);
126
- });
83
+ return [...rows].sort(compareCrapRows);
127
84
  }
128
85
 
129
86
  export { percentile };
@@ -144,35 +101,95 @@ const aggregate = makeAggregate({
144
101
  export const rollup = makeRollup({ aggregate });
145
102
 
146
103
  /**
147
- * Pure compare(head, base) keyed by `path::method@startLine`; higher CRAP is
148
- * worse. New methods are `additions`, not regressions — the new-method
149
- * ceiling is `check-baselines`' job.
104
+ * Pure compare(head, base); higher CRAP is worse. Rows pair through
105
+ * {@link compareCrap}'s stem-bucket alignment, so an inserted namesake does
106
+ * not mis-pair its siblings by ordinal. New methods are `additions`.
150
107
  */
151
- export const compare = makeCompare({
152
- identity: rowIdentity,
153
- betterIsHigher: false,
154
- metricField: 'crap',
155
- // Removed methods whose crap > 0 are improvements (the debt is gone).
156
- removedIsImprovement: (b) => (b.crap ?? 0) > 0,
157
- });
108
+ export function compare(head, base) {
109
+ const headRows = rowsOf(head);
110
+ const baseRows = rowsOf(base);
111
+ const pairs = pairByStem(headRows, baseRows);
112
+ const out = {
113
+ regressions: [],
114
+ improvements: [],
115
+ unchanged: [],
116
+ additions: [],
117
+ };
118
+ for (const row of headRows) binHeadRow(out, row, pairs.get(row));
119
+ const claimed = new Set(pairs.values());
120
+ for (const b of baseRows) {
121
+ if (!claimed.has(b)) binRemovedRow(out, b);
122
+ }
123
+ return out;
124
+ }
125
+
126
+ function rowsOf(snapshot) {
127
+ return Array.isArray(snapshot?.rows) ? snapshot.rows : [];
128
+ }
129
+
130
+ /** Head rows grouped with base rows by `[path, method stem]`. */
131
+ function stemBuckets(headRows, baseRows) {
132
+ const buckets = new Map();
133
+ const bucketOf = (r) => {
134
+ const key = JSON.stringify([r.path, methodStem(r.method)]);
135
+ if (!buckets.has(key)) buckets.set(key, { cur: [], base: [] });
136
+ return buckets.get(key);
137
+ };
138
+ for (const b of baseRows) bucketOf(b).base.push(b);
139
+ for (const row of headRows) bucketOf(row).cur.push({ row });
140
+ return buckets.values();
141
+ }
142
+
143
+ function pairByStem(headRows, baseRows) {
144
+ const pairs = new Map();
145
+ for (const { cur, base } of stemBuckets(headRows, baseRows)) {
146
+ const curSorted = cur.sort((a, b) => byKeyOrder(a.row, b.row));
147
+ for (const [e, b] of pairBucket(curSorted, base, 0)) pairs.set(e.row, b);
148
+ }
149
+ return pairs;
150
+ }
151
+
152
+ function binHeadRow(out, row, b) {
153
+ const key = rowIdentity(row);
154
+ if (!b) {
155
+ out.additions.push({ key, head: row, base: null });
156
+ return;
157
+ }
158
+ out[deltaBin((row.crap ?? 0) - (b.crap ?? 0))].push({
159
+ key,
160
+ head: row,
161
+ base: b,
162
+ });
163
+ }
164
+
165
+ function deltaBin(delta) {
166
+ if (delta > 0) return 'regressions';
167
+ return delta < 0 ? 'improvements' : 'unchanged';
168
+ }
169
+
170
+ /** A removed base row is an improvement only when it carried CRAP. */
171
+ function binRemovedRow(out, b) {
172
+ const bin = (b.crap ?? 0) > 0 ? 'improvements' : 'unchanged';
173
+ out[bin].push({ key: rowIdentity(b), head: null, base: b });
174
+ }
158
175
 
159
176
  /**
160
177
  * Canonical row identity. Distinct from `keyField` (`'path'`, the rollup
161
178
  * grouping): a file has one row per method, so keying a merge on `keyField`
162
179
  * would collapse them.
163
180
  *
164
- * @param {{path: string, method: string, startLine: number}} row
181
+ * @param {{path: string, method: string}} row
165
182
  * @returns {string}
166
183
  */
167
184
  export function rowIdentity(row) {
168
- return `${row.path}::${row.method}@${row.startLine}`;
185
+ return `${row.path}::${row.method}`;
169
186
  }
170
187
 
171
188
  /**
172
189
  * Sub-epsilon CRAP deltas resolve to the prior row bytes.
173
190
  *
174
- * @param {Array<{path: string, method: string, startLine: number, crap: number}>} prior
175
- * @param {Array<{path: string, method: string, startLine: number, crap: number}>} regenerated
191
+ * @param {Array<{path: string, method: string, crap: number}>} prior
192
+ * @param {Array<{path: string, method: string, crap: number}>} regenerated
176
193
  * @param {number} epsilon non-negative absolute tolerance on CRAP
177
194
  * @returns {Array<object>}
178
195
  */
@@ -185,8 +202,8 @@ export const applyEpsilon = makeEpsilon({
185
202
  * Scope-aware merge: identity is per method, but scope filters on `path`
186
203
  * alone (a diff names files), so out-of-scope files keep every prior row.
187
204
  *
188
- * @param {Array<{path: string, method: string, startLine: number, crap: number}>} prior
189
- * @param {Array<{path: string, method: string, startLine: number, crap: number}>} regenerated
205
+ * @param {Array<{path: string, method: string, crap: number}>} prior
206
+ * @param {Array<{path: string, method: string, crap: number}>} regenerated
190
207
  * @param {{mode: 'full'|'diff', files: Set<string>}|null|undefined} scope
191
208
  * @returns {Array<object>}
192
209
  */
@@ -223,7 +240,7 @@ export function filterRowsByFileScope(rows, scopeSet) {
223
240
  * regression would add branches and lose the exemption anyway.
224
241
  *
225
242
  * @param {{cyclomatic: number, crap: number}} row
226
- * @param {{crap: number, startLine: number}} baseline
243
+ * @param {{crap: number, method: string}} baseline
227
244
  * @param {number} tolerance
228
245
  * @param {'regression'|'drifted-regression'} kind
229
246
  * @returns {object | null}
@@ -235,23 +252,19 @@ export function checkCrapRegression(row, baseline, tolerance, kind) {
235
252
  ...row,
236
253
  kind,
237
254
  baseline: baseline.crap,
238
- baselineStartLine: baseline.startLine,
255
+ baselineMethod: baseline.method,
239
256
  };
240
257
  }
241
258
 
242
259
  /**
243
- * Compare scanned rows to baseline rows. Match arms: **exact** (same file,
244
- * method, startLine), **drifted** (same method, nearest startLine),
245
- * **incomparable** (every candidate is in a different coordinate system),
246
- * **new** (gated against the ceiling), **removed** (surfaced only).
247
- *
248
- * Across coordinate systems the drift heuristic would pair rows arbitrarily
249
- * and report regressions no edit can satisfy, so such rows are counted, not
250
- * scored, and never fall through to the new-method arm.
251
- * `provenanceMismatched` counts any row with at least one mismatched
252
- * candidate, captured before the filter discards that evidence — it feeds the
253
- * unsound-basis backstop. Unscorable rows (null crap/coverage) are bucketed
254
- * and excluded from `comparable` so they cannot dilute a ratio.
260
+ * Compare scanned rows to baseline rows. Both sides bucket by (file, stem) —
261
+ * the key with every `#<n>` stripped — and align in order inside a bucket
262
+ * (see {@link alignBucket}): an exact key pairs first, so an unchanged method
263
+ * is a plain comparison; an insert, remove or reorder re-pairs its namesakes
264
+ * (`drifted`) instead of reporting them new and removed. Unpaired current
265
+ * rows face the new-method ceiling; unpaired baseline rows are `removed`.
266
+ * Unscorable rows (null crap/coverage) are bucketed and excluded from
267
+ * `comparable` so they cannot dilute a ratio.
255
268
  */
256
269
  export function compareCrap({
257
270
  currentRows,
@@ -259,207 +272,205 @@ export function compareCrap({
259
272
  newMethodCeiling,
260
273
  tolerance,
261
274
  }) {
262
- const uncoveredFiles = deriveUncoveredFiles(currentRows);
263
- const exactIndex = new Map();
264
- const methodIndex = new Map();
265
- for (const b of baselineRows ?? []) {
266
- exactIndex.set(`${b.file}::${b.method}@${b.startLine}`, b);
267
- const mk = `${b.file}::${b.method}`;
268
- if (!methodIndex.has(mk)) methodIndex.set(mk, []);
269
- methodIndex.get(mk).push(b);
270
- }
271
- const seenBaselineKeys = new Set();
272
-
273
- const violations = [];
274
- const incomparableRows = [];
275
+ const rows = currentRows ?? [];
276
+ const state = {
277
+ uncoveredFiles: deriveUncoveredFiles(currentRows),
278
+ newMethodCeiling,
279
+ tolerance: Number.isFinite(tolerance) ? tolerance : 0,
280
+ claimed: new Set(),
281
+ verdicts: new Array(rows.length).fill(null),
282
+ regressions: 0,
283
+ newViolations: 0,
284
+ drifted: 0,
285
+ };
286
+ const buckets = new Map();
287
+ const bucketOf = (file, method) => {
288
+ const key = JSON.stringify([file, methodStem(method)]);
289
+ if (!buckets.has(key)) buckets.set(key, { cur: [], base: [] });
290
+ return buckets.get(key);
291
+ };
292
+ for (const b of baselineRows ?? []) bucketOf(b.file, b.method).base.push(b);
275
293
  const unscorableRows = [];
276
- let regressions = 0;
277
- let newViolations = 0;
278
- let drifted = 0;
279
- let provenanceMismatched = 0;
280
-
281
- for (const row of currentRows ?? []) {
294
+ for (const [idx, row] of rows.entries()) {
282
295
  if (isUnscorableRow(row)) {
283
296
  unscorableRows.push({ ...row, kind: 'unscorable' });
284
297
  continue;
285
298
  }
286
- const exactKey = `${row.file}::${row.method}@${row.startLine}`;
287
- const methodKey = `${row.file}::${row.method}`;
288
- const rowCoords = coordinateSystemOf(row);
289
- const candidates = methodIndex.get(methodKey) ?? [];
290
- if (candidates.some((c) => coordinateSystemOf(c) !== rowCoords)) {
291
- provenanceMismatched += 1;
292
- }
293
-
294
- const exact = exactIndex.get(exactKey);
295
- if (exact && coordinateSystemOf(exact) === rowCoords) {
296
- seenBaselineKeys.add(exactKey);
297
- const v = checkCrapRegression(row, exact, tolerance, 'regression');
298
- if (v) {
299
- regressions += 1;
300
- violations.push(v);
301
- }
302
- continue;
303
- }
304
-
305
- if (candidates.length > 0) {
306
- const comparable = candidates.filter(
307
- (c) => coordinateSystemOf(c) === rowCoords,
308
- );
309
- if (comparable.length === 0) {
310
- incomparableRows.push({
311
- ...row,
312
- kind: 'incomparable',
313
- coordinateSystem: rowCoords,
314
- baselineCoordinateSystem: coordinateSystemOf(candidates[0]),
315
- });
316
- for (const c of candidates) {
317
- seenBaselineKeys.add(`${c.file}::${c.method}@${c.startLine}`);
318
- }
319
- continue;
320
- }
321
- const pick = pickDriftCandidate(comparable, row, seenBaselineKeys);
322
- seenBaselineKeys.add(`${pick.file}::${pick.method}@${pick.startLine}`);
323
- drifted += 1;
324
- const v = checkCrapRegression(row, pick, tolerance, 'drifted-regression');
325
- if (v) {
326
- regressions += 1;
327
- violations.push(v);
328
- }
329
- continue;
330
- }
331
-
332
- const gateScore = newMethodGateScore(row, uncoveredFiles);
333
- if (gateScore > newMethodCeiling + tolerance) {
334
- newViolations += 1;
335
- violations.push(buildNewViolation(row, newMethodCeiling, gateScore));
336
- }
299
+ bucketOf(row.file, row.method).cur.push({ idx, row });
337
300
  }
338
-
339
- const removedRows = [];
340
- for (const b of baselineRows ?? []) {
341
- const k = `${b.file}::${b.method}@${b.startLine}`;
342
- if (!seenBaselineKeys.has(k)) removedRows.push(b);
301
+ for (const { cur, base } of buckets.values()) {
302
+ if (cur.length > 0) alignBucket(state, cur, base);
343
303
  }
344
304
 
345
- const total = currentRows?.length ?? 0;
305
+ const removedRows = (baselineRows ?? []).filter((b) => !state.claimed.has(b));
306
+ const total = rows.length;
346
307
  return {
347
308
  total,
348
309
  // Denominator of every ratio derived from this result.
349
310
  comparable: total - unscorableRows.length,
350
- regressions,
351
- newViolations,
352
- drifted,
353
- provenanceMismatched,
354
- incomparable: incomparableRows.length,
311
+ regressions: state.regressions,
312
+ newViolations: state.newViolations,
313
+ drifted: state.drifted,
355
314
  unscorable: unscorableRows.length,
356
315
  removed: removedRows.length,
357
- violations,
358
- incomparableRows,
316
+ violations: state.verdicts.filter((v) => v !== null),
359
317
  unscorableRows,
360
318
  removedRows,
361
319
  };
362
320
  }
363
321
 
322
+ /** Score one (current, baseline) pair into the verdict slot `idx`. */
323
+ function scorePair(state, idx, row, baseline, kind) {
324
+ const v = checkCrapRegression(row, baseline, state.tolerance, kind);
325
+ if (v) {
326
+ state.regressions += 1;
327
+ state.verdicts[idx] = v;
328
+ }
329
+ }
330
+
331
+ /** A current row with no baseline row: the new-method ceiling. */
332
+ function scoreNewMethod(state, idx, row) {
333
+ const gateScore = newMethodGateScore(row, state.uncoveredFiles);
334
+ if (gateScore > state.newMethodCeiling + state.tolerance) {
335
+ state.newViolations += 1;
336
+ state.verdicts[idx] = buildNewViolation(
337
+ row,
338
+ state.newMethodCeiling,
339
+ gateScore,
340
+ );
341
+ }
342
+ }
343
+
364
344
  /**
365
- * Strict on `null` (the scorer's "unresolved" value); a row merely omitting
366
- * `coverage` stays scorable.
345
+ * Source order of a persisted key: its per-segment `#<n>` ordinals (a bare
346
+ * segment is 0), compared left to right.
367
347
  *
368
- * @param {{crap?: number|null, coverage?: number|null, unscorable?: boolean}} row
369
- * @returns {boolean}
348
+ * @param {{method: string}} a
349
+ * @param {{method: string}} b
350
+ * @returns {number}
370
351
  */
371
- function isUnscorableRow(row) {
372
- return (
373
- row?.unscorable === true || row?.crap === null || row?.coverage === null
374
- );
352
+ function byKeyOrder(a, b) {
353
+ const ords = (m) =>
354
+ m
355
+ .split('/')
356
+ .flatMap((seg) =>
357
+ (seg.match(/#\d+/g) ?? ['#0']).map((o) => Number(o.slice(1))),
358
+ );
359
+ const [x, y] = [ords(a.method), ords(b.method)];
360
+ for (let i = 0; i < Math.max(x.length, y.length); i++) {
361
+ const d = (x[i] ?? 0) - (y[i] ?? 0);
362
+ if (d !== 0) return d;
363
+ }
364
+ return a.method.localeCompare(b.method);
375
365
  }
376
366
 
377
367
  /**
378
- * Closest unclaimed candidate by `startLine`; the first when all are claimed
379
- * (duplicate method names in one file).
368
+ * Order-aware pairing inside one stem bucket — current rows by `startLine`,
369
+ * baseline rows by key order: same key within `tolerance` first; then the
370
+ * earliest unclaimed row within `tolerance` (a re-keyed pair — never a
371
+ * regression); then leftovers by key, then order, scored as regressions;
372
+ * surplus current rows are new methods, surplus baseline rows stay removed.
373
+ */
374
+ function alignBucket(state, cur, base) {
375
+ const curSorted = [...cur].sort((a, b) => a.row.startLine - b.row.startLine);
376
+ const pairs = pairBucket(curSorted, base, state.tolerance);
377
+ for (const e of curSorted) scoreAligned(state, e, pairs.get(e));
378
+ }
379
+
380
+ /** Score one current entry against the baseline row it paired with, if any. */
381
+ function scoreAligned(state, e, b) {
382
+ if (!b) {
383
+ scoreNewMethod(state, e.idx, e.row);
384
+ return;
385
+ }
386
+ state.claimed.add(b);
387
+ if (b.method === e.row.method) {
388
+ scorePair(state, e.idx, e.row, b, 'regression');
389
+ return;
390
+ }
391
+ state.drifted += 1;
392
+ scorePair(state, e.idx, e.row, b, 'drifted-regression');
393
+ }
394
+
395
+ /**
396
+ * The pairing core of {@link alignBucket}: maps each entry of `curSorted`
397
+ * (source order) to its baseline row; an unpaired entry has no mapping.
380
398
  *
381
- * @param {Array<{file: string, method: string, startLine: number}>} comparable
382
- * @param {{startLine: number}} row
383
- * @param {Set<string>} seenBaselineKeys
384
- * @returns {object}
399
+ * @param {Array<{row: {method: string, crap: number}}>} curSorted
400
+ * @param {Array<{method: string, crap: number}>} base
401
+ * @param {number} tol
402
+ * @returns {Map<object, object>}
385
403
  */
386
- function pickDriftCandidate(comparable, row, seenBaselineKeys) {
387
- let pick = null;
388
- let bestDist = Number.POSITIVE_INFINITY;
389
- for (const c of comparable) {
390
- const k = `${c.file}::${c.method}@${c.startLine}`;
391
- if (seenBaselineKeys.has(k)) continue;
392
- const d = Math.abs(c.startLine - row.startLine);
393
- if (d < bestDist) {
394
- bestDist = d;
395
- pick = c;
404
+ function pairBucket(curSorted, base, tol) {
405
+ const free = [...base].sort(byKeyOrder);
406
+ const near = (row) => (b) => Math.abs(row.crap - b.crap) <= tol;
407
+ const sameKey = (row) => (b) => b.method === row.method;
408
+ const passes = [
409
+ (row) => (b) => sameKey(row)(b) && near(row)(b),
410
+ near,
411
+ sameKey,
412
+ () => () => true,
413
+ ];
414
+ const pairs = new Map();
415
+ for (const matches of passes) {
416
+ for (const e of curSorted) {
417
+ if (pairs.has(e)) continue;
418
+ const at = free.findIndex(matches(e.row));
419
+ if (at >= 0) pairs.set(e, free.splice(at, 1)[0]);
396
420
  }
397
421
  }
398
- return pick ?? comparable[0];
422
+ reclaimOwnRows(pairs, free, tol, curSorted);
423
+ return pairs;
399
424
  }
400
425
 
401
426
  /**
402
- * Share of comparable rows with a provenance mismatch above which the basis
403
- * is unsound. The numerator must be provenance mismatch, never `drifted`:
404
- * drifted rows passed the provenance filter, and ordinary insertions drift
405
- * most rows.
427
+ * A re-keyed pair must not hide an increase: a row that scored higher than
428
+ * its own exact-key baseline row takes it back when that row went unpaired
429
+ * (a sibling removed alongside an increase), or when the row itself went
430
+ * unpaired because a namesake re-keyed onto it (a later namesake added
431
+ * alongside an increase; that namesake becomes the new method). Fails safe:
432
+ * an earlier namesake inserted more complex than the existing one reads as
433
+ * the existing method's regression.
406
434
  */
407
- const UNSOUND_BASIS_MISMATCH_RATIO = 0.5;
408
-
409
- /** Small diff-scoped samples legitimately drift; don't judge them. */
410
- const UNSOUND_BASIS_MIN_SAMPLE = 20;
411
-
412
- const UNSOUND_BASIS_DIAGNOSTIC = 'crap-unsound-comparison-basis';
413
-
414
- export const INCOMPATIBLE_BASELINE_DIAGNOSTIC = 'crap-baseline-incompatible';
435
+ function reclaimOwnRows(pairs, free, tol, curSorted) {
436
+ for (const e of curSorted) {
437
+ const mine = pairs.get(e);
438
+ if (mine?.method === e.row.method) continue;
439
+ const isOwnIncrease = (b) =>
440
+ b.method === e.row.method && e.row.crap > b.crap + tol;
441
+ const at = free.findIndex(isOwnIncrease);
442
+ if (at >= 0) {
443
+ pairs.set(e, free.splice(at, 1)[0]);
444
+ if (mine) free.push(mine);
445
+ continue;
446
+ }
447
+ const holder = mine
448
+ ? undefined
449
+ : [...pairs.keys()].find((o) => isOwnIncrease(pairs.get(o)));
450
+ if (holder) {
451
+ pairs.set(e, pairs.get(holder));
452
+ pairs.delete(holder);
453
+ }
454
+ }
455
+ }
415
456
 
416
457
  /**
417
- * Whether a `compareCrap` result rests on a sound basis
418
- * (`provenanceMismatched / comparable`). Above the ratio the per-method
419
- * verdicts come from a mis-keyed join and must be suppressed.
420
- * Returns `{ sound: true }` or `{ sound: false, diagnostic: {name, message} }`.
458
+ * Strict on `null` (the scorer's "unresolved" value); a row merely omitting
459
+ * `coverage` stays scorable.
421
460
  *
422
- * @param {{total?: number, comparable?: number, provenanceMismatched?: number,
423
- * incomparable?: number}} compareResult
424
- * @param {{ratio?: number, minSample?: number, captureScript?: string}} [opts]
461
+ * @param {{crap?: number|null, coverage?: number|null, unscorable?: boolean}} row
462
+ * @returns {boolean}
425
463
  */
426
- export function assessComparisonBasis(compareResult, opts = {}) {
427
- const ratio = Number.isFinite(opts.ratio)
428
- ? opts.ratio
429
- : UNSOUND_BASIS_MISMATCH_RATIO;
430
- const minSample = Number.isFinite(opts.minSample)
431
- ? opts.minSample
432
- : UNSOUND_BASIS_MIN_SAMPLE;
433
- const comparable = compareResult?.comparable ?? compareResult?.total ?? 0;
434
- if (comparable < minSample) return { sound: true };
435
- // `incomparable` is a subset; max guards a caller supplying only one.
436
- const mismatched = Math.max(
437
- compareResult?.provenanceMismatched ?? 0,
438
- compareResult?.incomparable ?? 0,
464
+ function isUnscorableRow(row) {
465
+ return (
466
+ row?.unscorable === true || row?.crap === null || row?.coverage === null
439
467
  );
440
- const observed = mismatched / comparable;
441
- if (observed <= ratio) return { sound: true };
442
- return {
443
- sound: false,
444
- diagnostic: {
445
- name: UNSOUND_BASIS_DIAGNOSTIC,
446
- message:
447
- `[CRAP] ⚠ Comparison basis is unsound: ${mismatched}/${comparable} ` +
448
- `(${(observed * 100).toFixed(1)}%) of comparable methods matched a ` +
449
- 'baseline row expressed in a DIFFERENT line coordinate system — ' +
450
- `above the ${(ratio * 100).toFixed(0)}% threshold.\n` +
451
- ' At this ratio the baseline and the scan are not describing ' +
452
- 'the same line coordinates, so every per-method verdict below would ' +
453
- 'be derived from a mis-keyed join rather than from your change. ' +
454
- 'They are suppressed.\n' +
455
- ` Re-seed the baseline: run 'npm run ${captureScriptOf(opts)}' then ` +
456
- "'npm run crap:update -- --full-scope' and commit the result with a " +
457
- "'baseline-refresh:' subject. The authoritative check-baselines gate " +
458
- 'still gates the merge.',
459
- },
460
- };
461
468
  }
462
469
 
470
+ export const INCOMPATIBLE_BASELINE_DIAGNOSTIC = 'crap-baseline-incompatible';
471
+
472
+ export const AHEAD_BASELINE_DIAGNOSTIC = 'crap-baseline-ahead';
473
+
463
474
  /**
464
475
  * The CRAP capture script an operator hint names — the resolved
465
476
  * `gates.crap.captureScript` when the caller passes it, else the coverage
@@ -487,8 +498,8 @@ function reseedRemedy(ctx) {
487
498
  * Compat axes for `evaluateBaselineCompatibility`: `{ name, severity, check }`,
488
499
  * where `check(ctx)` returns null or a failure message. The first `fatal`
489
500
  * match fails; `warn` matches accumulate. Kernel drift only warns; a
490
- * transpiler change is fatal because it moves `startLine`, half the row
491
- * identity key.
501
+ * transpiler change is fatal because it can rename or re-nest emitted
502
+ * methods, which moves their scope-path keys.
492
503
  */
493
504
  export const CRAP_COMPAT_AXES = [
494
505
  missingBaselineAxis('CRAP'),
@@ -499,12 +510,14 @@ export const CRAP_COMPAT_AXES = [
499
510
  check: ({ baseline, captureScript }) => {
500
511
  if (!baseline) return null;
501
512
  const stamped = baseline.scoringSemantics ?? null;
502
- if (stamped === SCORING_SEMANTICS) return null;
513
+ // `ahead` is a skip, not a failure: see `aheadStampOf`.
514
+ if (classifyScoringSemantics(stamped) !== 'behind') return null;
503
515
  return (
504
516
  `[CRAP] scoring semantics changed: baseline=${stamped ?? '<unstamped>'} ` +
505
- `running=${SCORING_SEMANTICS}. Rows scored by the previous per-method ` +
506
- 'coverage join are not comparable to rows scored by the current one, ' +
507
- `so this baseline cannot be compared. ${reseedRemedy({ captureScript })}`
517
+ `running=${SCORING_SEMANTICS}. Rows keyed or scored under other ` +
518
+ 'semantics (or in the previous rows[] layout) are not comparable to ' +
519
+ 'rows scored now, so this baseline cannot be compared. ' +
520
+ reseedRemedy({ captureScript })
508
521
  );
509
522
  },
510
523
  },
@@ -515,64 +528,22 @@ export const CRAP_COMPAT_AXES = [
515
528
  if (!baseline) return null;
516
529
  if (!isKnownVersion(runningTsTranspilerVersion)) return null;
517
530
  const baselineTs = baseline.tsTranspilerVersion;
518
- // Unstamped: no evidence either way (see `provenance-unstamped`).
531
+ // Unstamped: no evidence either way.
519
532
  if (!isKnownVersion(baselineTs)) return null;
520
533
  if (baselineTs === runningTsTranspilerVersion) return null;
521
- // A pure-JS baseline has no transpiled coordinate to move.
534
+ // A pure-JS baseline has no transpiled method to re-key.
522
535
  if (!hasTranspiledRows(baseline)) return null;
523
536
  return (
524
537
  `[CRAP] tsTranspilerVersion changed: baseline=${baselineTs} running=${runningTsTranspilerVersion}. ` +
525
- "A TS row's startLine is an original-source coordinate only because the transpiler's " +
526
- 'sourcemap said so, and that coordinate is half the row identity key — so rows scored ' +
527
- `under the previous transpiler are not comparable to rows scored under this one. ${reseedRemedy({ captureScript })}`
528
- );
529
- },
530
- },
531
- {
532
- // Closes the unstamped exemption above. Keyed on a positive marker, since
533
- // absence can't separate "no provenance" from "typescript unresolvable";
534
- // scoped to transpiled rows because pure-JS coordinates coincide.
535
- name: 'provenance-unstamped',
536
- severity: 'fatal',
537
- check: ({ baseline, captureScript }) =>
538
- baseline &&
539
- baseline.provenanceStamped !== true &&
540
- hasTranspiledRows(baseline)
541
- ? '[CRAP] baseline predates coordinate-provenance stamping: it carries ' +
542
- 'transpiled-source rows but no `provenanceStamped` marker, so it ' +
543
- 'asserts by omission that every row is an original-source coordinate. ' +
544
- '`startLine` is half the row identity key, so the comparator would ' +
545
- 'key those rows against a coordinate space they are not in and ' +
546
- `report regressions no edit can satisfy. ${reseedRemedy({ captureScript })}`
547
- : null,
548
- },
549
- {
550
- // Catches a half-migrated baseline: a diff-scoped refresh keeps
551
- // out-of-scope ordinal-keyed anonymous rows under a current-semantics
552
- // stamp, and those rows pair with nothing. Keyed on the positive
553
- // `anonymous` marker.
554
- name: 'anon-identity-unstamped',
555
- severity: 'fatal',
556
- check: ({ baseline, captureScript }) => {
557
- if (!baseline) return null;
558
- const stale = (baseline.rows ?? []).filter(
559
- (row) => isAnonymousMethodLabel(row?.method) && row?.anonymous !== true,
560
- );
561
- if (stale.length === 0) return null;
562
- return (
563
- `[CRAP] baseline carries ${stale.length} anonymous row(s) keyed by the ` +
564
- 'superseded `<anon method-N>` ordinal (e.g. ' +
565
- `${stale[0].path ?? stale[0].file}::${stale[0].method}) while the ` +
566
- 'envelope claims the current scoring semantics. Those ordinals ' +
567
- 'renumber whenever any anonymous function is added or removed, so the ' +
568
- 'comparator would score the live methods against the new-method ' +
569
- `ceiling instead of their own baseline. ${reseedRemedy({ captureScript })}`
538
+ 'A transpiler change can rename or re-nest the methods it emits, which moves their ' +
539
+ 'scope-path keys — so rows scored under the previous transpiler are not comparable ' +
540
+ `to rows scored under this one. ${reseedRemedy({ captureScript })}`
570
541
  );
571
542
  },
572
543
  },
573
544
  ];
574
545
 
575
- /** Sources whose escomplex coordinates are transpiled, not original. */
546
+ /** Sources escomplex scores through the TypeScript transpiler. */
576
547
  const TRANSPILED_SOURCE_RE = /\.(?:ts|tsx|mts|cts)$/i;
577
548
 
578
549
  /**
@@ -603,12 +574,7 @@ export function evaluateBaselineCompatibility(ctx) {
603
574
  * Axes a loaded envelope can be judged on alone. `kernel-drift` is excluded:
604
575
  * it only warns, and this pass fails closed on any message.
605
576
  */
606
- const LOADED_ENVELOPE_AXES = [
607
- 'scoring-semantics-drift',
608
- 'ts-transpiler-drift',
609
- 'provenance-unstamped',
610
- 'anon-identity-unstamped',
611
- ];
577
+ const LOADED_ENVELOPE_AXES = ['scoring-semantics-drift', 'ts-transpiler-drift'];
612
578
 
613
579
  /**
614
580
  * Kind-module hook: `check-baselines` calls it after `reader.load` and fails
@@ -680,8 +646,9 @@ export function buildCrapReport({
680
646
  regressions: compareResult.regressions,
681
647
  newViolations: compareResult.newViolations,
682
648
  drifted: compareResult.drifted,
683
- incomparable: compareResult.incomparable ?? 0,
684
- provenanceMismatched: compareResult.provenanceMismatched ?? 0,
649
+ // Kept for report-schema stability; no coordinate arm remains.
650
+ incomparable: 0,
651
+ provenanceMismatched: 0,
685
652
  // Never scored from an assumed zero coverage.
686
653
  unscorable: (compareResult.unscorable ?? 0) + skippedNoCoverage,
687
654
  removed: compareResult.removed,
@@ -695,7 +662,7 @@ export function buildCrapReport({
695
662
 
696
663
  /**
697
664
  * Replace per-method verdicts with one diagnostic, keeping the counts as
698
- * evidence. Used when the baseline is incompatible or the basis unsound.
665
+ * evidence. Used when the baseline is incompatible or stamped ahead.
699
666
  *
700
667
  * @param {object} envelope
701
668
  * @param {{name: string, message: string}} diagnostic
@@ -719,8 +686,7 @@ export function printSummaryHeader(result, scanSummary) {
719
686
  Logger.info(`Total methods scanned: ${result.total}`);
720
687
  Logger.info(`Regressions: ${result.regressions}`);
721
688
  Logger.info(`New-method violations: ${result.newViolations}`);
722
- Logger.info(`Drifted (matched): ${result.drifted}`);
723
- Logger.info(`Provenance mismatched: ${result.provenanceMismatched ?? 0}`);
689
+ Logger.info(`Re-keyed (matched): ${result.drifted}`);
724
690
  Logger.info(`Unscorable (no cov): ${result.unscorable ?? 0}`);
725
691
  Logger.info(`Removed from baseline: ${result.removed}`);
726
692
  if (scanSummary?.skippedFilesNoCoverage) {
@@ -742,7 +708,7 @@ export function printViolation(v) {
742
708
  return;
743
709
  }
744
710
  Logger.error(
745
- `[CRAP] ❌ REGRESSION: ${v.file}::${v.method} (line ${v.startLine}${v.kind === 'drifted-regression' ? `, baseline line ${v.baselineStartLine}` : ''})`,
711
+ `[CRAP] ❌ REGRESSION: ${v.file}::${v.method} (line ${v.startLine}${v.kind === 'drifted-regression' ? `, baseline key ${v.baselineMethod}` : ''})`,
746
712
  );
747
713
  Logger.error(
748
714
  ` crap=${v.crap.toFixed(2)} > baseline=${v.baseline.toFixed(2)} (c=${v.cyclomatic}, cov=${v.coverage.toFixed(2)})`,
@@ -755,8 +721,6 @@ export function printRemovedRows(result) {
755
721
  `[CRAP] ℹ ${result.removed} baseline row(s) absent from current scan (deleted or moved):`,
756
722
  );
757
723
  for (const r of result.removedRows) {
758
- Logger.info(
759
- ` - ${r.file}::${r.method} (baseline line ${r.startLine})`,
760
- );
724
+ Logger.info(` - ${r.file}::${r.method}`);
761
725
  }
762
726
  }