mandrel 2.120.0 → 2.122.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 (41) hide show
  1. package/.agents/agents/acceptance-critic.md +5 -1
  2. package/.agents/agents/story-worker.md +1 -1
  3. package/.agents/docs/agentrc-reference.json +1 -0
  4. package/.agents/docs/configuration.md +1 -0
  5. package/.agents/instructions.md +3 -3
  6. package/.agents/schemas/acceptance-eval-verdict.schema.json +6 -1
  7. package/.agents/schemas/agentrc.schema.json +9 -0
  8. package/.agents/scripts/acceptance-eval.js +125 -13
  9. package/.agents/scripts/audit-to-stories.js +21 -0
  10. package/.agents/scripts/evidence-gate.js +15 -2
  11. package/.agents/scripts/lib/audit-to-stories/audit-label-taxonomy.js +7 -3
  12. package/.agents/scripts/lib/audit-to-stories/audit-lenses.js +18 -1
  13. package/.agents/scripts/lib/baselines/crap-preview-scan.js +1 -0
  14. package/.agents/scripts/lib/baselines/git-base.js +43 -0
  15. package/.agents/scripts/lib/baselines/kinds/_crap-new-method-gate.js +29 -5
  16. package/.agents/scripts/lib/baselines/kinds/crap.js +7 -1
  17. package/.agents/scripts/lib/baselines/kinds/kind-factory.js +81 -52
  18. package/.agents/scripts/lib/close-validation/projections/advisories.js +1 -0
  19. package/.agents/scripts/lib/close-validation/projections/crap.js +3 -0
  20. package/.agents/scripts/lib/config/gates/crap.schema.js +7 -0
  21. package/.agents/scripts/lib/config/quality.js +13 -6
  22. package/.agents/scripts/lib/generated/agentrc-validator.js +2 -2
  23. package/.agents/scripts/lib/orchestrate/classify.js +30 -14
  24. package/.agents/scripts/lib/orchestrate/inventory.js +10 -6
  25. package/.agents/scripts/lib/orchestration/acceptance-eval-decision.js +65 -6
  26. package/.agents/scripts/lib/orchestration/check-baselines/phases/compare.js +34 -2
  27. package/.agents/scripts/lib/orchestration/check-baselines/phases/fail-detail.js +7 -2
  28. package/.agents/scripts/lib/orchestration/handoff-gates.js +2 -0
  29. package/.agents/scripts/lib/orchestration/preflight-lanes.js +2 -0
  30. package/.agents/scripts/lib/orchestration/ticket-validator.js +35 -0
  31. package/.agents/scripts/lib/orchestration/verify-credit.js +144 -0
  32. package/.agents/scripts/lib/validation-evidence.js +27 -0
  33. package/.agents/workflows/audit-to-stories.md +6 -3
  34. package/.agents/workflows/helpers/acceptance-self-eval.md +9 -1
  35. package/.agents/workflows/helpers/deliver-digest.md +7 -8
  36. package/.agents/workflows/helpers/deliver-story-reference.md +1 -1
  37. package/.agents/workflows/helpers/plan-reference.md +3 -1
  38. package/.agents/workflows/mandrel-orchestrate.md +4 -0
  39. package/.agents/workflows/memory-consolidate.md +1 -1
  40. package/docs/CHANGELOG.md +27 -0
  41. package/package.json +1 -1
@@ -1,5 +1,16 @@
1
1
  /** Pure scaffold factory for the row-metric baseline kinds. */
2
2
 
3
+ /**
4
+ * `newFileMinimum`: a head row with no base row that falls below it on any
5
+ * axis is a regression against it. `renames`: head key → base key, so a
6
+ * renamed row is compared against its old base row.
7
+ *
8
+ * @typedef {{
9
+ * newFileMinimum?: Record<string, number> | null,
10
+ * renames?: Map<string, string> | null,
11
+ * }} CompareOptions
12
+ */
13
+
3
14
  import { componentMatches } from '../component-matcher.js';
4
15
  import { mergeRowsByScope } from '../scope.js';
5
16
 
@@ -29,7 +40,7 @@ import { mergeRowsByScope } from '../scope.js';
29
40
  * rowIdentity: (row: object) => string,
30
41
  * sortRows: (rows: object[]) => object[],
31
42
  * rollup: (rows: object[], components?: object[]) => Record<string, object>,
32
- * compare: (head: object, base: object) => object,
43
+ * compare: (head: object, base: object, opts?: CompareOptions) => object,
33
44
  * applyEpsilon: (prior: object[], regenerated: object[], epsilon: number) => object[],
34
45
  * mergeRows: (prior: object[], regenerated: object[], scope: object) => object[],
35
46
  * }}
@@ -73,67 +84,85 @@ export function makeBaselineKind({
73
84
  return out;
74
85
  }
75
86
 
76
- function classify(regressions, improvements, unchanged, key, head, base) {
77
- let down = false;
87
+ function direction(head, base, axesToCompare = axes) {
78
88
  let up = false;
79
- for (const axis of axes) {
89
+ for (const axis of axesToCompare) {
80
90
  const delta = (head[axis] ?? 0) - (base[axis] ?? 0);
81
- const worse = betterWhen === 'higher' ? delta < 0 : delta > 0;
82
- const better = betterWhen === 'higher' ? delta > 0 : delta < 0;
83
- if (worse) down = true;
84
- else if (better) up = true;
91
+ const signed = betterWhen === 'higher' ? delta : -delta;
92
+ if (signed < 0) return 'down';
93
+ if (signed > 0) up = true;
94
+ }
95
+ return up ? 'up' : 'same';
96
+ }
97
+
98
+ function classify(out, key, head, base, extra) {
99
+ const entry = { key, head, base, ...extra };
100
+ const dir = direction(head, base);
101
+ if (dir === 'down') out.regressions.push(entry);
102
+ else if (dir === 'up') out.improvements.push(entry);
103
+ else out.unchanged.push(entry);
104
+ }
105
+
106
+ /** A head row with no base row, under `missingBasePolicy: 'addition'`. */
107
+ function judgeAddition(out, key, h, newFileMinimum) {
108
+ const minAxes = newFileMinimum
109
+ ? axes.filter((a) => Number.isFinite(newFileMinimum[a]))
110
+ : [];
111
+ const minimum = { [keyField]: key, ...newFileMinimum };
112
+ if (minAxes.length > 0 && direction(h, minimum, minAxes) === 'down') {
113
+ out.regressions.push({ key, head: h, base: minimum, newFile: true });
114
+ } else {
115
+ out.additions.push({ key, head: h, base: null });
85
116
  }
86
- if (down) regressions.push({ key, head, base });
87
- else if (up) improvements.push({ key, head, base });
88
- else unchanged.push({ key, head, base });
89
117
  }
90
118
 
91
- function compare(head, base) {
119
+ function judgeHeadRow(out, h, baseByKey, seen, opts) {
120
+ const key = keyOf(h);
121
+ seen.add(key);
122
+ if (baseByKey.has(key)) {
123
+ classify(out, key, h, baseByKey.get(key));
124
+ return;
125
+ }
126
+ const renamedFrom = opts.renames?.get(key);
127
+ if (baseByKey.has(renamedFrom)) {
128
+ seen.add(renamedFrom);
129
+ classify(out, key, h, baseByKey.get(renamedFrom), { renamedFrom });
130
+ } else if (missingBasePolicy === 'addition') {
131
+ judgeAddition(out, key, h, opts.newFileMinimum);
132
+ } else {
133
+ classify(out, key, h, perfectRow(key));
134
+ }
135
+ }
136
+
137
+ function judgeRemovedRow(out, b) {
138
+ const key = keyOf(b);
139
+ if (removedRowPolicy.kind === 'perfect-head') {
140
+ classify(out, key, perfectRow(key), b);
141
+ } else if (removedRowPolicy.when(b)) {
142
+ out.improvements.push({ key, head: null, base: b });
143
+ } else {
144
+ out.unchanged.push({ key, head: null, base: b });
145
+ }
146
+ }
147
+
148
+ function compare(head, base, opts = {}) {
92
149
  const headRows = Array.isArray(head?.rows) ? head.rows : [];
93
150
  const baseRows = Array.isArray(base?.rows) ? base.rows : [];
94
- const baseByKey = new Map();
95
- for (const r of baseRows) baseByKey.set(keyOf(r), r);
151
+ const baseByKey = new Map(baseRows.map((r) => [keyOf(r), r]));
96
152
  const seen = new Set();
97
- const regressions = [];
98
- const improvements = [];
99
- const unchanged = [];
100
- const additions = [];
101
- for (const h of headRows) {
102
- const key = keyOf(h);
103
- seen.add(key);
104
- const b = baseByKey.get(key);
105
- if (!b) {
106
- if (missingBasePolicy === 'addition') {
107
- additions.push({ key, head: h, base: null });
108
- } else {
109
- classify(
110
- regressions,
111
- improvements,
112
- unchanged,
113
- key,
114
- h,
115
- perfectRow(key),
116
- );
117
- }
118
- continue;
119
- }
120
- classify(regressions, improvements, unchanged, key, h, b);
121
- }
153
+ const out = {
154
+ regressions: [],
155
+ improvements: [],
156
+ unchanged: [],
157
+ additions: [],
158
+ };
159
+ for (const h of headRows) judgeHeadRow(out, h, baseByKey, seen, opts ?? {});
122
160
  for (const b of baseRows) {
123
- const key = keyOf(b);
124
- if (seen.has(key)) continue;
125
- if (removedRowPolicy.kind === 'perfect-head') {
126
- classify(regressions, improvements, unchanged, key, perfectRow(key), b);
127
- } else if (removedRowPolicy.when(b)) {
128
- improvements.push({ key, head: null, base: b });
129
- } else {
130
- unchanged.push({ key, head: null, base: b });
131
- }
132
- }
133
- if (missingBasePolicy === 'addition') {
134
- return { regressions, improvements, unchanged, additions };
161
+ if (!seen.has(keyOf(b))) judgeRemovedRow(out, b);
135
162
  }
136
- return { regressions, improvements, unchanged };
163
+ if (missingBasePolicy === 'addition') return out;
164
+ const { additions: _unused, ...rest } = out;
165
+ return rest;
137
166
  }
138
167
 
139
168
  function applyEpsilon(prior, regenerated, epsilon) {
@@ -141,6 +141,7 @@ export async function runProjectionAdvisories({
141
141
  storyBranch,
142
142
  baselinePath: resolveBaselinePath('crap', crapGate, cwd),
143
143
  newMethodCeiling: crapGate?.newMethodCeiling,
144
+ untestableWiringGlobs: crapGate?.untestableWiringGlobs,
144
145
  scoreFiles: createCrapScorer({
145
146
  cwd,
146
147
  targetDirs: crapGate?.targetDirs,
@@ -184,6 +184,7 @@ function behindDetail(raw) {
184
184
  * baselinePath: string,
185
185
  * newMethodCeiling?: number,
186
186
  * tolerance?: number,
187
+ * untestableWiringGlobs?: string[],
187
188
  * git?: { gitSpawn: typeof defaultGitSpawn },
188
189
  * loadBaseline?: (path: string) => Array<object>,
189
190
  * peekBaseline?: (path: string) => unknown,
@@ -203,6 +204,7 @@ export async function projectCrapBreaches({
203
204
  baselinePath,
204
205
  newMethodCeiling = DEFAULT_NEW_METHOD_CEILING,
205
206
  tolerance = DEFAULT_CRAP_TOLERANCE,
207
+ untestableWiringGlobs = [],
206
208
  git = { gitSpawn: defaultGitSpawn },
207
209
  loadBaseline = loadCrapBaselineRows,
208
210
  peekBaseline = peekFile,
@@ -252,6 +254,7 @@ export async function projectCrapBreaches({
252
254
  baselineRows: filterRowsByFileScope(baselineRows, scopeSet),
253
255
  newMethodCeiling,
254
256
  tolerance,
257
+ untestableWiringGlobs,
255
258
  });
256
259
  const breaches = result.violations ?? [];
257
260
  return { ok: breaches.length === 0, breaches };
@@ -48,6 +48,13 @@ export const CRAP_GATE = {
48
48
  'Minimatch glob patterns matched against the canonicalised repo-relative path of each discovered file. Files matching any pattern are excluded from CRAP discovery before scoring. Orthogonal to `components` (grouping) — a file excluded here never appears in any component bucket. Absent or empty preserves the existing IGNORED_DIRS-only behaviour (Story #3217).',
49
49
  default: [...CRAP_GATE_DEFAULTS.ignoreGlobs],
50
50
  },
51
+ untestableWiringGlobs: {
52
+ type: 'array',
53
+ items: { type: 'string', minLength: 1 },
54
+ description:
55
+ 'Minimatch glob patterns matched against the canonicalised repo-relative path of a wholly uncovered file. A new method in a matching file meets `newMethodCeiling` on its complexity alone, for CLI wiring (argv, spawn, `main()`) that no test can load. Every other uncovered file is judged on its measured CRAP. Default `[]`.',
56
+ default: [...CRAP_GATE_DEFAULTS.untestableWiringGlobs],
57
+ },
51
58
  incrementalCoverage: INCREMENTAL_COVERAGE_SCHEMA,
52
59
  previewScope: {
53
60
  type: 'string',
@@ -53,6 +53,7 @@ export const CRAP_GATE_DEFAULTS = Object.freeze({
53
53
  requireCoverage: true,
54
54
  refreshTag: BASELINE_REFRESH_TAG,
55
55
  ignoreGlobs: Object.freeze([]),
56
+ untestableWiringGlobs: Object.freeze([]),
56
57
  // Fail-closed floor on the coverage join (over files that have coverage):
57
58
  // a broken join is silent, so the updater refuses to persist below it.
58
59
  // Healthy runs resolve ~98%; a coordinate mismatch resolves 4–6%.
@@ -83,6 +84,7 @@ const CRAP_GATE_KEYS = new Set([
83
84
  'newMethodCeiling',
84
85
  'requireCoverage',
85
86
  'ignoreGlobs',
87
+ 'untestableWiringGlobs',
86
88
  'minMethodResolutionRate',
87
89
  'incrementalCoverage',
88
90
  'coveragePath',
@@ -251,6 +253,7 @@ export function resolveMaintainabilityCrap(userCrap, coverageGate) {
251
253
  requireCoverage: defaults.requireCoverage,
252
254
  minMethodResolutionRate: defaults.minMethodResolutionRate,
253
255
  ignoreGlobs: [...defaults.ignoreGlobs],
256
+ untestableWiringGlobs: [...defaults.untestableWiringGlobs],
254
257
  incrementalCoverage: { ...defaults.incrementalCoverage },
255
258
  ...fixed,
256
259
  };
@@ -273,9 +276,11 @@ export function resolveMaintainabilityCrap(userCrap, coverageGate) {
273
276
  userCrap.minMethodResolutionRate,
274
277
  defaults.minMethodResolutionRate,
275
278
  ),
276
- ignoreGlobs: Array.isArray(userCrap.ignoreGlobs)
277
- ? userCrap.ignoreGlobs.slice()
278
- : [...defaults.ignoreGlobs],
279
+ ignoreGlobs: listOr(userCrap.ignoreGlobs, defaults.ignoreGlobs),
280
+ untestableWiringGlobs: listOr(
281
+ userCrap.untestableWiringGlobs,
282
+ defaults.untestableWiringGlobs,
283
+ ),
279
284
  incrementalCoverage: resolveIncrementalCoverage(
280
285
  userCrap.incrementalCoverage,
281
286
  defaults.incrementalCoverage,
@@ -284,6 +289,10 @@ export function resolveMaintainabilityCrap(userCrap, coverageGate) {
284
289
  };
285
290
  }
286
291
 
292
+ function listOr(value, fallback) {
293
+ return Array.isArray(value) ? value.slice() : [...fallback];
294
+ }
295
+
287
296
  function resolveMaintainabilityQuality(userBlock) {
288
297
  const defaults = MAINTAINABILITY_GATE_DEFAULTS;
289
298
  const fixed = {
@@ -301,9 +310,7 @@ function resolveMaintainabilityQuality(userBlock) {
301
310
  warnUnknownKeys(userBlock, MI_GATE_KEYS, 'quality.gates.maintainability');
302
311
  const out = {
303
312
  targetDirs: resolveListValue(defaults.targetDirs, userBlock.targetDirs),
304
- ignoreGlobs: Array.isArray(userBlock.ignoreGlobs)
305
- ? userBlock.ignoreGlobs.slice()
306
- : [...defaults.ignoreGlobs],
313
+ ignoreGlobs: listOr(userBlock.ignoreGlobs, defaults.ignoreGlobs),
307
314
  ...fixed,
308
315
  };
309
316
  if (userBlock.tolerance !== undefined) {