mandrel 2.107.0 → 2.109.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.
- package/.agents/agents/story-worker.md +3 -3
- package/.agents/docs/configuration.md +29 -0
- package/.agents/scripts/evidence-gate.js +2 -2
- package/.agents/scripts/lib/close-validation/gates.js +1 -1
- package/.agents/scripts/lib/close-validation/process.js +2 -2
- package/.agents/scripts/lib/close-validation/runner.js +1 -1
- package/.agents/scripts/lib/config/commands.js +23 -6
- package/.agents/scripts/lib/full-suite-lock.js +81 -8
- package/.agents/scripts/lib/orchestration/handoff-gates.js +150 -0
- package/.agents/scripts/lib/orchestration/story-handoff.js +97 -35
- package/.agents/scripts/lib/suite-admission.js +45 -3
- package/.agents/workflows/helpers/deliver-digest.md +7 -7
- package/.agents/workflows/helpers/deliver-reference.md +30 -9
- package/docs/CHANGELOG.md +20 -0
- package/package.json +5 -3
|
@@ -129,9 +129,9 @@ the authoritative gate — do not pre-run it. Your whole tail is one command:
|
|
|
129
129
|
|
|
130
130
|
`node <main-repo>/.agents/scripts/story-handoff.js --story <storyId> --cwd <workCwd>`
|
|
131
131
|
|
|
132
|
-
It runs the
|
|
133
|
-
`--seat-missing` seat, the push with its remote-ref
|
|
134
|
-
review, then prints one envelope (what each step runs:
|
|
132
|
+
It runs the base merge, the blocking preflight, the one credited run, the
|
|
133
|
+
`--seat-missing` seat, the post-capture checks, the push with its remote-ref
|
|
134
|
+
check, and the held review, then prints one envelope (what each step runs:
|
|
135
135
|
[`deliver-digest.md`](../workflows/helpers/deliver-digest.md) § 5).
|
|
136
136
|
`ready` → return. `fix-required` (exit 2) → fix the cause it names, commit,
|
|
137
137
|
re-run it; the same cause surviving the same fix twice is your blocked path.
|
|
@@ -403,6 +403,35 @@ A config still carrying the retired key is a hard validation failure; the
|
|
|
403
403
|
reporters. `coverage-capture.js` fails a green run that leaves no artifact
|
|
404
404
|
there (and writes no capture stamp), and a full-scope coverage or CRAP
|
|
405
405
|
refresh with no artifact exits non-zero naming the path.
|
|
406
|
+
- **Admission for a script you run by hand.** Every suite spawn Mandrel
|
|
407
|
+
admits under `execution.fullSuiteLock` carries `MANDREL_SUITE_RESERVATION`,
|
|
408
|
+
the absolute path of the lockfile or reservation it holds, and every
|
|
409
|
+
descendant inherits it. A consumer script that may also be started by hand
|
|
410
|
+
(say `test:coverage:affected`, run from an agent shell) admits itself
|
|
411
|
+
through the materialized lock library rather than bypassing admission:
|
|
412
|
+
|
|
413
|
+
```js
|
|
414
|
+
import { withSuiteAdmission } from '../.agents/scripts/lib/full-suite-lock.js';
|
|
415
|
+
|
|
416
|
+
const code = await withSuiteAdmission(
|
|
417
|
+
{ argv: ['pnpm', 'run', 'test:coverage:affected'], cwd: process.cwd() },
|
|
418
|
+
({ env }) => runSuite({ env: { ...process.env, ...env } }),
|
|
419
|
+
);
|
|
420
|
+
process.exit(code);
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
Pass `argv` exactly as it appears in `execution.workloads[]`. `env` (default
|
|
424
|
+
`process.env`), `log` and `config` (default: resolved from `cwd`) are
|
|
425
|
+
optional. When the environment already names a live reservation in this
|
|
426
|
+
repository's lock home, the callback runs at once inside it and nothing new
|
|
427
|
+
is reserved. Otherwise, including when that reservation's file is gone,
|
|
428
|
+
its holder has died or its heartbeat is stale, the run queues for its
|
|
429
|
+
declared workload, or exclusively when the argv is undeclared, exactly as a
|
|
430
|
+
Mandrel caller would. The callback's `env` names the reservation that
|
|
431
|
+
admitted it; merge it into the child's environment. The helper resolves to
|
|
432
|
+
the callback's result, `75` when the wait expires, or `78` when the
|
|
433
|
+
declared weight exceeds `capacity`. With `MANDREL_FULL_SUITE_LOCK=0` or
|
|
434
|
+
`fullSuiteLock: false` it calls the callback directly with an empty `env`.
|
|
406
435
|
- **Duplication needs jscpd.** The duplication gate scans with `jscpd` 4, an
|
|
407
436
|
**optional peer dependency** of `mandrel`: a project that enables
|
|
408
437
|
`quality.gates.duplication` installs it itself — `npm i -D jscpd@^4`.
|
|
@@ -240,13 +240,13 @@ export function runLockedSuite(
|
|
|
240
240
|
onLockProgress: lockHooks.onLockProgress,
|
|
241
241
|
...lockOptions,
|
|
242
242
|
},
|
|
243
|
-
(
|
|
243
|
+
(lock) =>
|
|
244
244
|
runSuiteImpl({
|
|
245
245
|
cmd,
|
|
246
246
|
args,
|
|
247
247
|
cwd,
|
|
248
248
|
timeoutMs,
|
|
249
|
-
|
|
249
|
+
...lock,
|
|
250
250
|
onTimings: (t) => {
|
|
251
251
|
log(`[evidence-gate] ${formatSuiteTimings(t)}`);
|
|
252
252
|
lockHooks.onTimings(t);
|
|
@@ -396,7 +396,7 @@ const COVERAGE_CAPTURE_ARGS = Object.freeze([
|
|
|
396
396
|
* the CRAP half stays serial behind coverage-capture. Every name MUST be in
|
|
397
397
|
* the `gateName` enum of `validation-evidence.schema.json`.
|
|
398
398
|
*/
|
|
399
|
-
const QUALITY_PREVIEW_GATE_NAMES = Object.freeze({
|
|
399
|
+
export const QUALITY_PREVIEW_GATE_NAMES = Object.freeze({
|
|
400
400
|
maintainability: 'quality-preview-mi',
|
|
401
401
|
crap: 'quality-preview-crap',
|
|
402
402
|
});
|
|
@@ -70,7 +70,7 @@ const MARKER_PROBE_TAIL_LINES = 32;
|
|
|
70
70
|
* @param {string} output - Combined stdout/stderr.
|
|
71
71
|
* @returns {boolean}
|
|
72
72
|
*/
|
|
73
|
-
function isBiomeNoFilesProcessed(output) {
|
|
73
|
+
export function isBiomeNoFilesProcessed(output) {
|
|
74
74
|
return (
|
|
75
75
|
typeof output === 'string' && output.includes(BIOME_NO_FILES_PROCESSED)
|
|
76
76
|
);
|
|
@@ -99,7 +99,7 @@ export function defaultGateRunner(cmd, args, opts = {}) {
|
|
|
99
99
|
// `skipIfSatisfied` re-probes after the wait: evidence another suite
|
|
100
100
|
// deposited meanwhile is returned instead of spawning.
|
|
101
101
|
return withFullSuiteLockAsync(gateLockOptions(opts), (lock) =>
|
|
102
|
-
spawnGate(cmd, args, opts, lock),
|
|
102
|
+
spawnGate(cmd, args, { ...opts, env: { ...opts.env, ...lock.env } }, lock),
|
|
103
103
|
);
|
|
104
104
|
}
|
|
105
105
|
|
|
@@ -63,7 +63,7 @@ function reportGateExit({ gate, status, cwd, log }) {
|
|
|
63
63
|
return { gate, status, cwd, outcome: 'failed' };
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
function applyChangedFileScope({ gate, spawnCwd, log }) {
|
|
66
|
+
export function applyChangedFileScope({ gate, spawnCwd, log }) {
|
|
67
67
|
// A skip decided when the gate list was built wins over everything.
|
|
68
68
|
if (gate.skip) {
|
|
69
69
|
log(`[close-validation] ⏭ ${gate.name} skipped (${gate.skip.reason})`);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `project.commands.*` tri-state: absent → default; own-present `null` →
|
|
3
3
|
* disabled (optional gates only); string → that command. Anything else throws.
|
|
4
|
+
* A no-default key (`testChanged`) resolves absent the same as `null`.
|
|
4
5
|
*/
|
|
5
6
|
|
|
6
7
|
import { isObject } from '../json-utils.js';
|
|
@@ -14,11 +15,18 @@ export const COMMANDS_DEFAULTS = Object.freeze({
|
|
|
14
15
|
formatWrite: 'npx biome format --write .',
|
|
15
16
|
});
|
|
16
17
|
|
|
18
|
+
/** Every known key's absent value — a default, or `null` (disabled, no argv). */
|
|
19
|
+
const ABSENT_COMMANDS = Object.freeze({
|
|
20
|
+
...COMMANDS_DEFAULTS,
|
|
21
|
+
testChanged: null,
|
|
22
|
+
});
|
|
23
|
+
|
|
17
24
|
/** The gates an explicit `null` disables. */
|
|
18
25
|
const OPTIONAL_COMMAND_KEYS = Object.freeze([
|
|
19
26
|
'typecheck',
|
|
20
27
|
'lint',
|
|
21
28
|
'formatCheck',
|
|
29
|
+
'testChanged',
|
|
22
30
|
]);
|
|
23
31
|
|
|
24
32
|
/** @param {string} raw */
|
|
@@ -54,6 +62,17 @@ function disabledCommand(key) {
|
|
|
54
62
|
return { argv: [], raw: null, disabled: true, source: 'disabled' };
|
|
55
63
|
}
|
|
56
64
|
|
|
65
|
+
/** @param {object} commands @param {string} key */
|
|
66
|
+
function isUnset(commands, key) {
|
|
67
|
+
return !Object.hasOwn(commands, key) || commands[key] === undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** @param {string} key */
|
|
71
|
+
function absentCommand(key) {
|
|
72
|
+
const fallback = ABSENT_COMMANDS[key];
|
|
73
|
+
return fallback ? enabled(fallback, 'default') : disabledCommand(key);
|
|
74
|
+
}
|
|
75
|
+
|
|
57
76
|
/** @param {string} key @param {unknown} value */
|
|
58
77
|
function configuredCommand(key, value) {
|
|
59
78
|
const raw = typeof value === 'string' ? value.trim() : '';
|
|
@@ -65,22 +84,20 @@ function configuredCommand(key, value) {
|
|
|
65
84
|
|
|
66
85
|
/** @param {string} key */
|
|
67
86
|
function assertKnownKey(key) {
|
|
68
|
-
if (!Object.hasOwn(
|
|
87
|
+
if (!Object.hasOwn(ABSENT_COMMANDS, key)) {
|
|
69
88
|
throw configError(`.${key} is not a known command`);
|
|
70
89
|
}
|
|
71
90
|
}
|
|
72
91
|
|
|
73
92
|
/**
|
|
74
93
|
* @param {object|null|undefined} config
|
|
75
|
-
* @param {keyof typeof COMMANDS_DEFAULTS} key
|
|
94
|
+
* @param {keyof typeof COMMANDS_DEFAULTS | 'testChanged'} key
|
|
76
95
|
* @returns {{ argv: string[], raw: string|null, disabled: boolean, source: 'default'|'disabled'|'config' }}
|
|
77
96
|
*/
|
|
78
97
|
export function resolveProjectCommand(config, key) {
|
|
79
98
|
assertKnownKey(key);
|
|
80
99
|
const commands = commandsBlock(config);
|
|
81
|
-
if (
|
|
82
|
-
return enabled(COMMANDS_DEFAULTS[key], 'default');
|
|
83
|
-
}
|
|
100
|
+
if (isUnset(commands, key)) return absentCommand(key);
|
|
84
101
|
return commands[key] === null
|
|
85
102
|
? disabledCommand(key)
|
|
86
103
|
: configuredCommand(key, commands[key]);
|
|
@@ -89,7 +106,7 @@ export function resolveProjectCommand(config, key) {
|
|
|
89
106
|
/** Projection over {@link resolveProjectCommand}; a disabled gate keeps `null`. */
|
|
90
107
|
export function getCommands(config) {
|
|
91
108
|
return Object.fromEntries(
|
|
92
|
-
Object.keys(
|
|
109
|
+
Object.keys(ABSENT_COMMANDS).map((key) => [
|
|
93
110
|
key,
|
|
94
111
|
resolveProjectCommand(config, key).raw,
|
|
95
112
|
]),
|
|
@@ -15,6 +15,7 @@ import path from 'node:path';
|
|
|
15
15
|
|
|
16
16
|
import { getQuality } from './config/quality.js';
|
|
17
17
|
import { mainCheckoutRoot } from './config/temp-paths.js';
|
|
18
|
+
import { resolveConfig } from './config-resolver.js';
|
|
18
19
|
import { packageScriptArgv } from './detect-package-manager.js';
|
|
19
20
|
import { isFirstInLine, waitInLine } from './full-suite-queue.js';
|
|
20
21
|
import { acquireSweepLock } from './single-story-sweep/sweep-lock.js';
|
|
@@ -24,12 +25,15 @@ import {
|
|
|
24
25
|
createAttempt,
|
|
25
26
|
describeRefusal,
|
|
26
27
|
FULL_SUITE_STALE_MS,
|
|
28
|
+
inheritedReservation,
|
|
29
|
+
reservationEnv,
|
|
27
30
|
resolveAdmission,
|
|
28
31
|
resolveSuiteCapacity,
|
|
32
|
+
SUITE_RESERVATION_ENV,
|
|
29
33
|
} from './suite-admission.js';
|
|
30
34
|
import { defaultSleep } from './util/sleep.js';
|
|
31
35
|
|
|
32
|
-
export { ADMISSION_REFUSED_EXIT_CODE };
|
|
36
|
+
export { ADMISSION_REFUSED_EXIT_CODE, SUITE_RESERVATION_ENV };
|
|
33
37
|
|
|
34
38
|
/** Environment escape hatch: set to `0`/`false`/`off`/`no` to disable. */
|
|
35
39
|
export const FULL_SUITE_LOCK_ENV = 'MANDREL_FULL_SUITE_LOCK';
|
|
@@ -59,6 +63,7 @@ const LOCK_DEFAULTS = Object.freeze({
|
|
|
59
63
|
pollMs: DEFAULT_POLL_MS,
|
|
60
64
|
reportMs: DEFAULT_REPORT_MS,
|
|
61
65
|
fsImpl: fs,
|
|
66
|
+
env: process.env,
|
|
62
67
|
nowFn: Date.now,
|
|
63
68
|
sleepFn: (ms) => defaultSleep(ms),
|
|
64
69
|
acquireOnceFn: (opts) => acquireSweepLock(opts),
|
|
@@ -180,6 +185,7 @@ function consult(probe, applies) {
|
|
|
180
185
|
* @param {{
|
|
181
186
|
* cwd: string,
|
|
182
187
|
* enabled?: boolean,
|
|
188
|
+
* env?: Record<string, string|undefined>,
|
|
183
189
|
* log?: (m: string) => void,
|
|
184
190
|
* waitMs?: number,
|
|
185
191
|
* pollMs?: number,
|
|
@@ -196,22 +202,46 @@ function consult(probe, applies) {
|
|
|
196
202
|
* onLockProgress?: (progress: import('./full-suite-queue.js').LockProgress) => void,
|
|
197
203
|
* rerunCommand?: string,
|
|
198
204
|
* }} opts A non-`undefined` `skipIfSatisfied` return stands in for the spawn.
|
|
199
|
-
*
|
|
205
|
+
* `env` naming a live holder in this lock home spawns at once, inside it.
|
|
206
|
+
* @param {(lock: { lockWaitMs: number, env: Record<string, string> }) => Promise<T>} spawn
|
|
207
|
+
* `env` carries {@link SUITE_RESERVATION_ENV} for the child; merge it in.
|
|
200
208
|
* @returns {Promise<T>}
|
|
201
209
|
*/
|
|
202
210
|
export async function withFullSuiteLockAsync(options, spawn) {
|
|
203
211
|
const opts = withDefaults(options);
|
|
204
212
|
if (isRefused(opts)) return refuse(opts);
|
|
213
|
+
return admitAndSpawn(opts, spawn);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function admitAndSpawn(opts, spawn) {
|
|
217
|
+
const inherited = inheritedMarker(opts);
|
|
218
|
+
return inherited === null
|
|
219
|
+
? lockAndSpawn(opts, spawn)
|
|
220
|
+
: spawnInside(opts, inherited, spawn);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
async function lockAndSpawn(opts, spawn) {
|
|
205
224
|
const begun = beginLock(opts);
|
|
206
225
|
try {
|
|
207
226
|
const wait = await awaitTurn(opts, begun);
|
|
208
227
|
reportOutcome(opts.onLockOutcome, wait);
|
|
209
|
-
return await spawnOrStandIn(opts, wait, spawn);
|
|
228
|
+
return await spawnOrStandIn(opts, wait, spawn, begun.attempt);
|
|
210
229
|
} finally {
|
|
211
230
|
begun.attempt?.release();
|
|
212
231
|
}
|
|
213
232
|
}
|
|
214
233
|
|
|
234
|
+
function inheritedMarker(opts) {
|
|
235
|
+
return inheritedReservation({ ...opts, lockHomeFn: () => lockHome(opts) });
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function spawnInside(opts, marker, spawn) {
|
|
239
|
+
opts.log(
|
|
240
|
+
`${LOCK_TAG} ↪ already admitted under ${path.basename(marker)} — spawning inside it.`,
|
|
241
|
+
);
|
|
242
|
+
return spawn({ lockWaitMs: 0, env: reservationEnv(marker) });
|
|
243
|
+
}
|
|
244
|
+
|
|
215
245
|
function isRefused({ enabled, workload }) {
|
|
216
246
|
return enabled && workload?.kind === 'refused';
|
|
217
247
|
}
|
|
@@ -253,7 +283,7 @@ function withDefaults(options) {
|
|
|
253
283
|
return opts;
|
|
254
284
|
}
|
|
255
285
|
|
|
256
|
-
async function spawnOrStandIn(opts, wait, spawn) {
|
|
286
|
+
async function spawnOrStandIn(opts, wait, spawn, attempt) {
|
|
257
287
|
const probe = consult(opts.skipIfSatisfied, wait.waited);
|
|
258
288
|
if (probe.satisfied) {
|
|
259
289
|
opts.log(
|
|
@@ -263,13 +293,16 @@ async function spawnOrStandIn(opts, wait, spawn) {
|
|
|
263
293
|
}
|
|
264
294
|
return wait.expired
|
|
265
295
|
? opts.onWaitExpired(wait.holder)
|
|
266
|
-
: await timedSpawn(opts, wait, spawn);
|
|
296
|
+
: await timedSpawn(opts, wait, spawn, attempt);
|
|
267
297
|
}
|
|
268
298
|
|
|
269
299
|
/** Wait and execution reach progress as separate figures. */
|
|
270
|
-
async function timedSpawn(opts, wait, spawn) {
|
|
300
|
+
async function timedSpawn(opts, wait, spawn, attempt) {
|
|
271
301
|
const startedAt = opts.nowFn();
|
|
272
|
-
const result = await spawn({
|
|
302
|
+
const result = await spawn({
|
|
303
|
+
lockWaitMs: wait.waitedMs ?? 0,
|
|
304
|
+
env: reservationEnv(attempt?.heldPath?.()),
|
|
305
|
+
});
|
|
273
306
|
if (wait.waited) reportCompleted(opts, wait, opts.nowFn() - startedAt);
|
|
274
307
|
return result;
|
|
275
308
|
}
|
|
@@ -338,15 +371,55 @@ export function lockedCapture(
|
|
|
338
371
|
env,
|
|
339
372
|
coverageCaptureArgv(config, captureOpts),
|
|
340
373
|
),
|
|
374
|
+
env,
|
|
341
375
|
...lockOptions,
|
|
342
376
|
cwd: captureOpts.cwd,
|
|
343
377
|
log: captureOpts.log,
|
|
344
378
|
skipIfSatisfied: freshnessProbe(captureOpts),
|
|
345
379
|
},
|
|
346
|
-
(
|
|
380
|
+
captureInLock(runCaptureFn, captureOpts),
|
|
347
381
|
);
|
|
348
382
|
}
|
|
349
383
|
|
|
384
|
+
/** The lock's marker joins the capture's own `env`, never replacing it. */
|
|
385
|
+
function captureInLock(runCaptureFn, captureOpts) {
|
|
386
|
+
return ({ lockWaitMs, env }) =>
|
|
387
|
+
runCaptureFn({
|
|
388
|
+
...captureOpts,
|
|
389
|
+
env: { ...captureOpts.env, ...env },
|
|
390
|
+
lockWaitMs,
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* The consumer entry point: admit `argv` exactly as an in-framework caller
|
|
396
|
+
* would, or — when `env` already names a live holder — run inside it.
|
|
397
|
+
* Resolves to `spawn`'s result, 75 on an expired wait, or 78 on a refusal.
|
|
398
|
+
*
|
|
399
|
+
* @template T
|
|
400
|
+
* @param {{ argv: string[], cwd: string,
|
|
401
|
+
* env?: Record<string, string|undefined>, log?: (m: string) => void,
|
|
402
|
+
* config?: object, lockOptions?: object }} opts `lockOptions`: test seams.
|
|
403
|
+
* @param {(lock: { lockWaitMs: number, env: Record<string, string> }) => Promise<T>} spawn
|
|
404
|
+
* @returns {Promise<T|number>}
|
|
405
|
+
*/
|
|
406
|
+
export function withSuiteAdmission(
|
|
407
|
+
{ argv, cwd, env = process.env, log, config, lockOptions },
|
|
408
|
+
spawn,
|
|
409
|
+
) {
|
|
410
|
+
const resolved = config ?? resolveConfig({ cwd });
|
|
411
|
+
return withFullSuiteLockAsync(
|
|
412
|
+
{
|
|
413
|
+
...fullSuiteLockPolicy(resolved, env, argv),
|
|
414
|
+
...lockOptions,
|
|
415
|
+
cwd,
|
|
416
|
+
env,
|
|
417
|
+
log,
|
|
418
|
+
},
|
|
419
|
+
spawn,
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
|
|
350
423
|
/**
|
|
351
424
|
* A fresh recheck means exit 0 without spawning.
|
|
352
425
|
*
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* handoff-gates.js — the handoff's view of close's own gate list, so argv,
|
|
3
|
+
* env and evidence keys never drift from close.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
BASELINES_GATE_NAMES,
|
|
11
|
+
buildDefaultGates,
|
|
12
|
+
QUALITY_PREVIEW_GATE_NAMES,
|
|
13
|
+
} from '../close-validation/gates.js';
|
|
14
|
+
import {
|
|
15
|
+
hashCommandConfig,
|
|
16
|
+
recordPass,
|
|
17
|
+
treeFingerprint,
|
|
18
|
+
} from '../validation-evidence.js';
|
|
19
|
+
|
|
20
|
+
const EVIDENCE_GATE = path.resolve(
|
|
21
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
22
|
+
'..',
|
|
23
|
+
'..',
|
|
24
|
+
'evidence-gate.js',
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
/** Close's gate list, built with the inputs its validation phase passes. */
|
|
28
|
+
function closeGates(ctx) {
|
|
29
|
+
return buildDefaultGates({
|
|
30
|
+
config: ctx.config,
|
|
31
|
+
baseBranch: ctx.baseBranch,
|
|
32
|
+
cwd: ctx.cwd,
|
|
33
|
+
evidenceCwd: ctx.evidenceCwd,
|
|
34
|
+
storyId: ctx.storyId,
|
|
35
|
+
packageScripts: ctx.scripts,
|
|
36
|
+
presentBaselines: ctx.presentBaselines,
|
|
37
|
+
getChangedFilesImpl: ctx.getChangedFilesFn,
|
|
38
|
+
gitSpawnImpl: ctx.git,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Close's `lint` and `format` entries wrapped in `evidence-gate.js` with the
|
|
44
|
+
* argv close executes; a disabled or scoped-out gate deposits nothing.
|
|
45
|
+
*/
|
|
46
|
+
export function creditedPreflight(ctx) {
|
|
47
|
+
const checks = [];
|
|
48
|
+
for (const gate of closeGates(ctx).filter((g) =>
|
|
49
|
+
['lint', 'format'].includes(g.name),
|
|
50
|
+
)) {
|
|
51
|
+
const run = ctx.scopeGate({
|
|
52
|
+
gate,
|
|
53
|
+
spawnCwd: ctx.cwd,
|
|
54
|
+
log: (m) => ctx.progress('preflight', m),
|
|
55
|
+
});
|
|
56
|
+
if (run.skip) continue;
|
|
57
|
+
checks.push({
|
|
58
|
+
key: gate.name,
|
|
59
|
+
cmd: 'node',
|
|
60
|
+
args: [
|
|
61
|
+
EVIDENCE_GATE,
|
|
62
|
+
'--standalone',
|
|
63
|
+
'--scope-id',
|
|
64
|
+
String(ctx.storyId),
|
|
65
|
+
'--gate',
|
|
66
|
+
gate.name,
|
|
67
|
+
'--worktree',
|
|
68
|
+
ctx.cwd,
|
|
69
|
+
'--cwd',
|
|
70
|
+
ctx.evidenceCwd,
|
|
71
|
+
'--',
|
|
72
|
+
run.cmd,
|
|
73
|
+
...run.args,
|
|
74
|
+
],
|
|
75
|
+
deposit: { cmd: run.cmd, args: run.args },
|
|
76
|
+
tolerateNoFilesProcessed: run.tolerateNoFilesProcessed,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return checks;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The `lint` credit a clean preflight deposited, hashed as close hashes it. */
|
|
83
|
+
export function lintCredit(ctx, check) {
|
|
84
|
+
return {
|
|
85
|
+
head: ctx.head,
|
|
86
|
+
configHash: hashCommandConfig({ ...check.deposit, cwd: ctx.cwd }),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Re-key the `lint` pass deposited at `priorHead` onto the seated HEAD. Not
|
|
92
|
+
* `format`: its scoped argv names the changed files, which the seat changes.
|
|
93
|
+
* Best-effort: a failed write only costs close a lint run.
|
|
94
|
+
*/
|
|
95
|
+
export function carryLintCredit(ctx, priorHead) {
|
|
96
|
+
const credit = ctx.state.lintCredit;
|
|
97
|
+
if (credit?.head !== priorHead) return;
|
|
98
|
+
try {
|
|
99
|
+
recordPass(
|
|
100
|
+
{
|
|
101
|
+
storyId: ctx.storyId,
|
|
102
|
+
gateName: 'lint',
|
|
103
|
+
sha: ctx.head,
|
|
104
|
+
configHash: credit.configHash,
|
|
105
|
+
inputFingerprint: treeFingerprint(ctx.cwd, ctx.git),
|
|
106
|
+
},
|
|
107
|
+
{ cwd: ctx.evidenceCwd, standalone: true },
|
|
108
|
+
);
|
|
109
|
+
ctx.state.lintCredit = { ...credit, head: ctx.head };
|
|
110
|
+
} catch (err) {
|
|
111
|
+
ctx.progress('seat', `⚠️ lint credit not carried: ${err?.message ?? err}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** `quality-preview-crap` (capture depositor only) and every baselines entry. */
|
|
116
|
+
function postCaptureGates(ctx) {
|
|
117
|
+
const names = new Set(Object.values(BASELINES_GATE_NAMES));
|
|
118
|
+
if (ctx.depositor === 'coverage-capture') {
|
|
119
|
+
names.add(QUALITY_PREVIEW_GATE_NAMES.crap);
|
|
120
|
+
}
|
|
121
|
+
return closeGates(ctx).filter((g) => names.has(g.name) && !g.skip);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** The gate name, plus the kinds a baselines entry scores. */
|
|
125
|
+
function describeGate(gate) {
|
|
126
|
+
const i = gate.args.indexOf('--gate');
|
|
127
|
+
return i === -1 ? gate.name : `${gate.name} (kinds: ${gate.args[i + 1]})`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Run each post-capture gate through `run`; the first non-zero exit is the finding. */
|
|
131
|
+
export async function scorePostCapture(ctx, run) {
|
|
132
|
+
const gates = postCaptureGates(ctx);
|
|
133
|
+
for (const gate of gates) {
|
|
134
|
+
const env = gate.env ? { ...ctx.env, ...gate.env } : undefined;
|
|
135
|
+
const res = await run(
|
|
136
|
+
`post-capture-${gate.name}`,
|
|
137
|
+
gate.cmd,
|
|
138
|
+
gate.args,
|
|
139
|
+
env,
|
|
140
|
+
);
|
|
141
|
+
if (res.status !== 0) {
|
|
142
|
+
const finding = `${describeGate(gate)} finding (exit ${res.status}) — fix and commit, then re-run`;
|
|
143
|
+
return {
|
|
144
|
+
gates,
|
|
145
|
+
failed: { gate: gate.name, finding, evidencePath: res.evidencePath },
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return { gates, failed: null };
|
|
150
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* story-handoff.js — the story-worker's whole post-implementation tail as one
|
|
3
|
-
* deterministic sequence: blocking preflight (lint
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
3
|
+
* deterministic sequence: base merge → blocking preflight (lint and format
|
|
4
|
+
* deposited as close's credit, quality-preview, baselined ratchets) → the one
|
|
5
|
+
* credited run with the held review beside it → baseline seating → close's
|
|
6
|
+
* post-capture CRAP and baselines scoring → push + remote-ref check → review
|
|
7
|
+
* awaited. It runs exactly what deliver-digest § 5 and deliver-reference
|
|
8
|
+
* define, with close's own gate identities, and settles one envelope:
|
|
8
9
|
*
|
|
9
10
|
* - `ready` (exit 0) — hand off.
|
|
10
11
|
* - `fix-required` (exit 2) — the worker can fix it by editing the branch;
|
|
@@ -27,14 +28,13 @@ import {
|
|
|
27
28
|
createLockEventChannel,
|
|
28
29
|
summarizeLockEvents,
|
|
29
30
|
} from '../close-lock-events.js';
|
|
30
|
-
import {
|
|
31
|
-
resolveGateCommand,
|
|
32
|
-
resolveTestGateArgv,
|
|
33
|
-
} from '../close-validation/commands.js';
|
|
31
|
+
import { resolveTestGateArgv } from '../close-validation/commands.js';
|
|
34
32
|
import {
|
|
35
33
|
isCrapGateEnabled,
|
|
36
34
|
resolveCreditedDepositor,
|
|
37
35
|
} from '../close-validation/gates.js';
|
|
36
|
+
import { isBiomeNoFilesProcessed } from '../close-validation/process.js';
|
|
37
|
+
import { applyChangedFileScope } from '../close-validation/runner.js';
|
|
38
38
|
import {
|
|
39
39
|
orchestrationLogDir,
|
|
40
40
|
storyReviewDepositPath,
|
|
@@ -47,10 +47,17 @@ import { syncBranchFromBase } from '../git/sync-from-base.js';
|
|
|
47
47
|
import { getStoryBranch, gitSpawn } from '../git-utils.js';
|
|
48
48
|
import { readPackageScripts } from '../npm-scripts.js';
|
|
49
49
|
import { TIMEOUT_EXIT_CODE } from '../process-group.js';
|
|
50
|
+
import { PROJECT_ROOT } from '../project-root.js';
|
|
50
51
|
import { describeBlocking } from '../suite-admission.js';
|
|
51
52
|
import { writeFileAtomic } from '../util/atomic-write.js';
|
|
52
53
|
import { defaultSleep } from '../util/sleep.js';
|
|
53
54
|
import { runStreamed } from './evidence-stream.js';
|
|
55
|
+
import {
|
|
56
|
+
carryLintCredit,
|
|
57
|
+
creditedPreflight,
|
|
58
|
+
lintCredit,
|
|
59
|
+
scorePostCapture,
|
|
60
|
+
} from './handoff-gates.js';
|
|
54
61
|
import { handoffStatePath } from './handoff-state.js';
|
|
55
62
|
import { probeHeldReviewDiff } from './review-deposit.js';
|
|
56
63
|
import { createStoryProgress, handoffStepName } from './story-progress.js';
|
|
@@ -314,21 +321,11 @@ function describeSuiteFailure(status) {
|
|
|
314
321
|
}
|
|
315
322
|
|
|
316
323
|
/**
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
* @param {object} config
|
|
320
|
-
* @returns {Array<{ key: string, cmd: string, args: string[] }>}
|
|
321
|
-
*/
|
|
322
|
-
function lintPreflight(config) {
|
|
323
|
-
const lint = resolveGateCommand(config, 'lint');
|
|
324
|
-
return lint.disabled ? [] : [{ key: 'lint', cmd: lint.cmd, args: lint.args }];
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* Lint, quality-preview, then each ratchet whose baseline is committed.
|
|
324
|
+
* Lint and format (deposited), quality-preview, then each ratchet whose
|
|
325
|
+
* baseline is committed.
|
|
329
326
|
*
|
|
330
327
|
* @param {object} ctx
|
|
331
|
-
* @returns {Array<{ key: string, cmd: string, args: string[], gated?: boolean }>}
|
|
328
|
+
* @returns {Array<{ key: string, cmd: string, args: string[], gated?: boolean, deposit?: object }>}
|
|
332
329
|
*/
|
|
333
330
|
function preflightChecks(ctx) {
|
|
334
331
|
const ratchets = RATCHETS.filter((r) =>
|
|
@@ -340,7 +337,7 @@ function preflightChecks(ctx) {
|
|
|
340
337
|
gated: true,
|
|
341
338
|
}));
|
|
342
339
|
return [
|
|
343
|
-
...
|
|
340
|
+
...creditedPreflight(ctx),
|
|
344
341
|
{
|
|
345
342
|
key: 'quality-preview',
|
|
346
343
|
cmd: 'node',
|
|
@@ -364,6 +361,10 @@ function preflightChecks(ctx) {
|
|
|
364
361
|
function preflightFinding(check, run) {
|
|
365
362
|
const gateFailed = check.gated === true && SIGNALS.gateFail.test(run.output);
|
|
366
363
|
if (run.status === 0 && !gateFailed) return null;
|
|
364
|
+
// Close downgrades biome's all-paths-ignored exit the same way.
|
|
365
|
+
if (check.tolerateNoFilesProcessed && isBiomeNoFilesProcessed(run.output)) {
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
367
368
|
const offending = check.gated
|
|
368
369
|
? run.output
|
|
369
370
|
.split(/\r?\n/)
|
|
@@ -383,7 +384,16 @@ async function stepPreflight(ctx) {
|
|
|
383
384
|
`preflight already passed at ${ctx.head.slice(0, 12)}`,
|
|
384
385
|
);
|
|
385
386
|
}
|
|
386
|
-
|
|
387
|
+
ctx.state.lintCredit = null;
|
|
388
|
+
let checks;
|
|
389
|
+
try {
|
|
390
|
+
checks = preflightChecks(ctx);
|
|
391
|
+
} catch (err) {
|
|
392
|
+
return fixRequired(
|
|
393
|
+
name,
|
|
394
|
+
`could not resolve close's lint/format gates: ${err?.message ?? err}`,
|
|
395
|
+
);
|
|
396
|
+
}
|
|
387
397
|
for (const check of checks) {
|
|
388
398
|
const run = await runLogged(
|
|
389
399
|
ctx,
|
|
@@ -395,6 +405,7 @@ async function stepPreflight(ctx) {
|
|
|
395
405
|
if (finding) {
|
|
396
406
|
return fixRequired(name, finding, { evidencePath: run.evidencePath });
|
|
397
407
|
}
|
|
408
|
+
if (check.key === 'lint') ctx.state.lintCredit = lintCredit(ctx, check);
|
|
398
409
|
}
|
|
399
410
|
ctx.state.preflightHead = ctx.head;
|
|
400
411
|
return ran(name, `${checks.map((c) => c.key).join(', ')} clean`);
|
|
@@ -575,7 +586,8 @@ async function commitSeatedRows(ctx, total, evidencePath) {
|
|
|
575
586
|
{ evidencePath: ctx.writeEvidence('seat-commit', detail) },
|
|
576
587
|
);
|
|
577
588
|
}
|
|
578
|
-
const
|
|
589
|
+
const priorHead = ctx.head;
|
|
590
|
+
const creditedPrior = ctx.state.creditHead === priorHead;
|
|
579
591
|
ctx.head = headSha(ctx) ?? ctx.head;
|
|
580
592
|
ctx.state.seatHead = ctx.head;
|
|
581
593
|
// Both capture-stamp digests leave `baselines/` out, so a baseline-JSON-only
|
|
@@ -583,6 +595,9 @@ async function commitSeatedRows(ctx, total, evidencePath) {
|
|
|
583
595
|
if (creditedPrior && ctx.depositor === 'coverage-capture') {
|
|
584
596
|
recordCredit(ctx, { ...ctx.state.creditTimings, head: ctx.head });
|
|
585
597
|
}
|
|
598
|
+
if (paths.every((p) => p.startsWith('baselines/'))) {
|
|
599
|
+
carryLintCredit(ctx, priorHead);
|
|
600
|
+
}
|
|
586
601
|
return ran(name, `seated ${total} row(s) and committed them`, {
|
|
587
602
|
evidencePath,
|
|
588
603
|
});
|
|
@@ -839,7 +854,35 @@ function stepReview(ctx) {
|
|
|
839
854
|
}
|
|
840
855
|
|
|
841
856
|
/**
|
|
842
|
-
*
|
|
857
|
+
* Pure scoring after depositor and seat: no lock, no suite, no evidence, so
|
|
858
|
+
* close re-scores them and stays authoritative.
|
|
859
|
+
*
|
|
860
|
+
* @param {object} ctx @returns {Promise<StepResult>}
|
|
861
|
+
*/
|
|
862
|
+
async function stepPostCapture(ctx) {
|
|
863
|
+
const name = 'post-capture';
|
|
864
|
+
const { postCaptureHead, creditHead } = ctx.state;
|
|
865
|
+
if (postCaptureHead === ctx.head && creditHead === ctx.head) {
|
|
866
|
+
return skipped(name, `already clean at ${ctx.head.slice(0, 12)}`);
|
|
867
|
+
}
|
|
868
|
+
const { gates, failed } = await scorePostCapture(ctx, (...a) =>
|
|
869
|
+
runLogged(ctx, ...a),
|
|
870
|
+
);
|
|
871
|
+
if (failed) {
|
|
872
|
+
return fixRequired(name, failed.finding, {
|
|
873
|
+
evidencePath: failed.evidencePath,
|
|
874
|
+
gate: failed.gate,
|
|
875
|
+
});
|
|
876
|
+
}
|
|
877
|
+
ctx.state.postCaptureHead = ctx.head;
|
|
878
|
+
return gates.length > 0
|
|
879
|
+
? ran(name, `${gates.map((g) => g.name).join(', ')} clean`)
|
|
880
|
+
: skipped(name, 'no post-capture gate registered');
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
/**
|
|
884
|
+
* The run's step order. The base merges first, so every check scores the
|
|
885
|
+
* tree that is pushed. On the evidence-gate path the `test` credit is keyed
|
|
843
886
|
* on the tree, so seating (static MI) goes first and cannot void it; the
|
|
844
887
|
* capture stamp's digests leave `baselines/` out, so a baseline seat after it
|
|
845
888
|
* keeps the stamp fresh.
|
|
@@ -852,7 +895,14 @@ function stepOrder(depositor) {
|
|
|
852
895
|
depositor === 'test'
|
|
853
896
|
? [stepSeat, stepCreditedRun]
|
|
854
897
|
: [stepCreditedRun, stepSeat];
|
|
855
|
-
return [
|
|
898
|
+
return [
|
|
899
|
+
stepBaseMerge,
|
|
900
|
+
stepPreflight,
|
|
901
|
+
...middle,
|
|
902
|
+
stepPostCapture,
|
|
903
|
+
stepPush,
|
|
904
|
+
stepReview,
|
|
905
|
+
];
|
|
856
906
|
}
|
|
857
907
|
|
|
858
908
|
/**
|
|
@@ -907,7 +957,7 @@ function precheck(ctx) {
|
|
|
907
957
|
*
|
|
908
958
|
* @param {string} statePath
|
|
909
959
|
* @param {(tag: string, msg: string) => void} progress
|
|
910
|
-
* @returns {{ preflightHead?: string, creditHead?: string, creditTimings?: object, seatHead?: string }}
|
|
960
|
+
* @returns {{ preflightHead?: string, lintCredit?: { head: string, configHash: string }|null, creditHead?: string, creditTimings?: object, seatHead?: string, postCaptureHead?: string }}
|
|
911
961
|
*/
|
|
912
962
|
function readState(statePath, progress) {
|
|
913
963
|
let raw;
|
|
@@ -984,7 +1034,11 @@ async function defaultBlock({
|
|
|
984
1034
|
* reraise?: (signal: string) => void,
|
|
985
1035
|
* evidenceFs?: typeof fs,
|
|
986
1036
|
* now?: () => number,
|
|
987
|
-
*
|
|
1037
|
+
* evidenceCwd?: string,
|
|
1038
|
+
* scopeGate?: typeof applyChangedFileScope,
|
|
1039
|
+
* presentBaselines?: string[],
|
|
1040
|
+
* }} deps `evidenceCwd` anchors close's evidence store (the main checkout);
|
|
1041
|
+
* `runCommand` receives `onChunk`, `signal` and (when set)
|
|
988
1042
|
* `timeoutMs` beside `cwd`/`env`; a runner that never calls `onChunk`
|
|
989
1043
|
* still gets its whole output written at settle.
|
|
990
1044
|
* @returns {Promise<{ envelope: object, exitCode: number }>}
|
|
@@ -1011,6 +1065,9 @@ export async function runStoryHandoff({ storyId, cwd, config }, deps) {
|
|
|
1011
1065
|
reraise,
|
|
1012
1066
|
evidenceFs,
|
|
1013
1067
|
now = Date.now,
|
|
1068
|
+
evidenceCwd = PROJECT_ROOT,
|
|
1069
|
+
scopeGate = applyChangedFileScope,
|
|
1070
|
+
presentBaselines,
|
|
1014
1071
|
} = deps;
|
|
1015
1072
|
const block =
|
|
1016
1073
|
deps.block ??
|
|
@@ -1047,17 +1104,16 @@ export async function runStoryHandoff({ storyId, cwd, config }, deps) {
|
|
|
1047
1104
|
lockPollMs,
|
|
1048
1105
|
env,
|
|
1049
1106
|
now,
|
|
1107
|
+
evidenceCwd,
|
|
1108
|
+
scopeGate,
|
|
1109
|
+
presentBaselines,
|
|
1110
|
+
getChangedFilesFn,
|
|
1050
1111
|
state: readState(statePath, progress),
|
|
1051
1112
|
review: null,
|
|
1052
1113
|
reviewPending: null,
|
|
1053
1114
|
reviewMs: null,
|
|
1054
1115
|
reviewPath: storyReviewDepositPath(storyId, config),
|
|
1055
|
-
|
|
1056
|
-
config,
|
|
1057
|
-
scripts: readPackageScriptsFn(cwd),
|
|
1058
|
-
cwd,
|
|
1059
|
-
getChangedFilesImpl: getChangedFilesFn,
|
|
1060
|
-
}),
|
|
1116
|
+
scripts: readPackageScriptsFn(cwd),
|
|
1061
1117
|
storyProgress,
|
|
1062
1118
|
// Undefined fields take runStreamed's defaults.
|
|
1063
1119
|
stream: {
|
|
@@ -1074,6 +1130,12 @@ export async function runStoryHandoff({ storyId, cwd, config }, deps) {
|
|
|
1074
1130
|
return file;
|
|
1075
1131
|
},
|
|
1076
1132
|
};
|
|
1133
|
+
ctx.depositor = selectCreditedDepositor({
|
|
1134
|
+
config,
|
|
1135
|
+
scripts: ctx.scripts,
|
|
1136
|
+
cwd,
|
|
1137
|
+
getChangedFilesImpl: getChangedFilesFn,
|
|
1138
|
+
});
|
|
1077
1139
|
ctx.head = headSha(ctx);
|
|
1078
1140
|
|
|
1079
1141
|
const steps = [];
|
|
@@ -21,6 +21,12 @@ import {
|
|
|
21
21
|
readLockHolderPid,
|
|
22
22
|
} from './single-story-sweep/sweep-lock.js';
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Set on every spawn made under a held lockfile or reservation, naming it, so
|
|
26
|
+
* a descendant that asks for admission runs inside its parent's.
|
|
27
|
+
*/
|
|
28
|
+
export const SUITE_RESERVATION_ENV = 'MANDREL_SUITE_RESERVATION';
|
|
29
|
+
|
|
24
30
|
/** `EX_CONFIG`: a declared weight the capacity can never admit. */
|
|
25
31
|
export const ADMISSION_REFUSED_EXIT_CODE = 78;
|
|
26
32
|
|
|
@@ -259,6 +265,7 @@ function createDeclaredAttempt(opts) {
|
|
|
259
265
|
const { workload, capacity } = opts;
|
|
260
266
|
const acquire = opts.acquireReservationFn ?? acquireSweepLock;
|
|
261
267
|
let held = null;
|
|
268
|
+
let heldPath = null;
|
|
262
269
|
const admit = () => {
|
|
263
270
|
const legacy = liveLegacyHolder(opts);
|
|
264
271
|
if (legacy) return blocked({ reason: 'exclusive', holder: legacy });
|
|
@@ -289,18 +296,22 @@ function createDeclaredAttempt(opts) {
|
|
|
289
296
|
} catch {
|
|
290
297
|
return { acquired: false, reason: 'error' };
|
|
291
298
|
}
|
|
299
|
+
const file = path.join(dir, reservationName(workload));
|
|
292
300
|
const result = acquire({
|
|
293
|
-
lockPath:
|
|
301
|
+
lockPath: file,
|
|
294
302
|
timeoutMs: opts.staleMs,
|
|
295
303
|
heartbeatMs: HOLDER_HEARTBEAT_MS,
|
|
296
304
|
fsImpl: opts.fsImpl,
|
|
297
305
|
});
|
|
298
|
-
if (result.acquired)
|
|
299
|
-
|
|
306
|
+
if (!result.acquired) return { acquired: false, reason: 'error' };
|
|
307
|
+
held = result;
|
|
308
|
+
heldPath = file;
|
|
309
|
+
return result;
|
|
300
310
|
};
|
|
301
311
|
return {
|
|
302
312
|
tryOnce: () => underAdmissionMutex(opts, admit),
|
|
303
313
|
release: () => held?.release(),
|
|
314
|
+
heldPath: () => heldPath,
|
|
304
315
|
};
|
|
305
316
|
}
|
|
306
317
|
|
|
@@ -315,6 +326,7 @@ function createDeclaredAttempt(opts) {
|
|
|
315
326
|
*/
|
|
316
327
|
function createExclusiveAttempt(opts) {
|
|
317
328
|
let held = null;
|
|
329
|
+
let heldPath = null;
|
|
318
330
|
const drained = () => {
|
|
319
331
|
const live = readLiveReservations(opts);
|
|
320
332
|
if (live === null || live.length === 0) return held;
|
|
@@ -336,6 +348,7 @@ function createExclusiveAttempt(opts) {
|
|
|
336
348
|
});
|
|
337
349
|
if (!first.acquired) return first;
|
|
338
350
|
held = first;
|
|
351
|
+
heldPath = opts.lockPath;
|
|
339
352
|
}
|
|
340
353
|
const verdict = underAdmissionMutex(opts, drained);
|
|
341
354
|
return verdict.reason === 'error' ? held : verdict;
|
|
@@ -343,9 +356,38 @@ function createExclusiveAttempt(opts) {
|
|
|
343
356
|
return {
|
|
344
357
|
tryOnce,
|
|
345
358
|
release: () => held?.release(),
|
|
359
|
+
heldPath: () => heldPath,
|
|
346
360
|
};
|
|
347
361
|
}
|
|
348
362
|
|
|
363
|
+
/** The child environment naming `heldPath`; empty when nothing is held. */
|
|
364
|
+
export function reservationEnv(heldPath) {
|
|
365
|
+
return heldPath ? { [SUITE_RESERVATION_ENV]: heldPath } : {};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* The marker `env` inherits, when it names a live holder in this lock home:
|
|
370
|
+
* the legacy lockfile or one of its reservations, with a live pid and a fresh
|
|
371
|
+
* heartbeat. Any other path — another repository's, a stray file — is `null`.
|
|
372
|
+
*
|
|
373
|
+
* @param {{ env?: Record<string, string|undefined>,
|
|
374
|
+
* lockHomeFn: () => string|null, staleMs: number, fsImpl: object,
|
|
375
|
+
* nowFn: () => number, killFn?: Function }} probe
|
|
376
|
+
* @returns {string|null}
|
|
377
|
+
*/
|
|
378
|
+
export function inheritedReservation({ env, lockHomeFn, ...probe }) {
|
|
379
|
+
const marker = env?.[SUITE_RESERVATION_ENV];
|
|
380
|
+
if (typeof marker !== 'string' || !path.isAbsolute(marker)) return null;
|
|
381
|
+
const home = lockHomeFn();
|
|
382
|
+
if (home === null) return null;
|
|
383
|
+
const file = path.resolve(marker);
|
|
384
|
+
const inHome =
|
|
385
|
+
file === path.resolve(home) ||
|
|
386
|
+
(path.dirname(file) === reservationsDir(path.resolve(home)) &&
|
|
387
|
+
RESERVATION_RE.test(path.basename(file)));
|
|
388
|
+
return inHome && holderState(file, probe).live ? marker : null;
|
|
389
|
+
}
|
|
390
|
+
|
|
349
391
|
const LOCK_TAG = '[full-suite-lock]';
|
|
350
392
|
|
|
351
393
|
/** The declared-run wait line; `null` leaves the exclusive wording. */
|
|
@@ -113,12 +113,11 @@ or an unregistered merge driver: it flips `agent::blocked` and posts
|
|
|
113
113
|
close, opens a PR or writes another label. Outruns the sync Bash ceiling → run
|
|
114
114
|
it in the **background**.
|
|
115
115
|
|
|
116
|
-
1. **
|
|
116
|
+
1. **Base merge.** It will merge `origin/<baseBranch>` into the Story branch
|
|
117
|
+
**first**, ahead of every check: close's base-sync then no-ops.
|
|
118
|
+
2. **Preflight — blocking.** `lint`/`format` (close's credit),
|
|
117
119
|
`quality-preview.js --changed-since origin/<baseBranch>`, then each
|
|
118
|
-
baselined
|
|
119
|
-
2. **Base merge.** It will merge `origin/<baseBranch>` into the Story branch
|
|
120
|
-
**first**, ahead of this run and the push: close's base-sync then no-ops,
|
|
121
|
-
so neither stamp goes stale.
|
|
120
|
+
baselined ratchet — [`deliver-reference.md`](deliver-reference.md) § Preflight.
|
|
122
121
|
3. **One depositor**, by the one predicate close registers `coverage-capture`
|
|
123
122
|
on — coverage or CRAP gate on **and** a `captureScript`:
|
|
124
123
|
- **Capture-active** →
|
|
@@ -129,12 +128,13 @@ it in the **background**.
|
|
|
129
128
|
--standalone --scope-id <storyId> --gate test --worktree <workCwd> -- npm test`.
|
|
130
129
|
Signal: `✓ test passed` — the `test` evidence close reads.
|
|
131
130
|
4. **Seat.** CRAP or MI gate on → `--seat-missing` for each (signal
|
|
132
|
-
`seated: N`), committed as `chore(baselines): baseline-refresh:
|
|
131
|
+
`seated: N`), committed as `chore(baselines): baseline-refresh: …`; then
|
|
132
|
+
post-capture checks: close's `quality-preview-crap` and `check-baselines`.
|
|
133
133
|
5. **Push** `story-<id>`; the remote ref must equal HEAD.
|
|
134
134
|
6. **Held review** beside step 3, which a CRITICAL aborts —
|
|
135
135
|
[`deliver-reference.md`](deliver-reference.md) § Held review.
|
|
136
136
|
|
|
137
|
-
A later commit voids
|
|
137
|
+
A later commit voids any credit; a baseline-JSON seat keeps the stamp. It
|
|
138
138
|
reads the **output**, not the exit code: a run that prints no signal
|
|
139
139
|
deposits nothing. Seat order, runner shapes, redraft rounds:
|
|
140
140
|
[`deliver-reference.md`](deliver-reference.md) § Credited run.
|
|
@@ -367,15 +367,26 @@ sibling to unblock, and the foreground wait is the cheapest path to `landed`.
|
|
|
367
367
|
|
|
368
368
|
## Preflight (before close) {#preflight}
|
|
369
369
|
|
|
370
|
-
Digest § 5 states the rule: `story-handoff.js` runs,
|
|
371
|
-
suite run,
|
|
372
|
-
`
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
370
|
+
Digest § 5 states the rule: `story-handoff.js` runs, after the base merge
|
|
371
|
+
and before the credited suite run, close's own `lint` and `format` gates,
|
|
372
|
+
`quality-preview.js --changed-since origin/<baseBranch>`, then the shipped
|
|
373
|
+
standalone ratchets CI's `baselines` job runs — `check-dead-exports.js`
|
|
374
|
+
(default and `--production`), `check-arch-cycles.js` and
|
|
375
|
+
`check-cyclomatic.js` — in the worktree; a finding is `fix-required` — fix,
|
|
376
|
+
commit, re-run it. It runs **before** the credited run because a fix commit
|
|
377
|
+
afterwards would void that run's credit.
|
|
378
|
+
|
|
379
|
+
- **Lint and format are close's credit.** The handoff takes both entries from
|
|
380
|
+
close's `buildDefaultGates` (same config, base branch, worktree and
|
|
381
|
+
evidence root) and runs them through `evidence-gate.js --standalone
|
|
382
|
+
--gate <name>`, so the pass lands in close's evidence store keyed to the
|
|
383
|
+
post-merge HEAD and tree, with close's command hash. `format` runs the argv
|
|
384
|
+
close's runner scopes to the changed files, and deposits nothing when that
|
|
385
|
+
scoping skips it or `project.commands.formatCheck` is `null`. Close on the
|
|
386
|
+
handed-off HEAD skips both as `evidence-match`. A baselines-only seat commit
|
|
387
|
+
re-keys the `lint` record to the seated HEAD; `format` is not carried (its
|
|
388
|
+
argv names the changed files). Any other commit, or a close-time base move,
|
|
389
|
+
re-runs them.
|
|
379
390
|
- **Why.** Close runs lint and the maintainability half of the preview
|
|
380
391
|
(`quality-preview-mi`) in its parallel phase, but a regression found there
|
|
381
392
|
still costs a close round-trip. Seconds of preflight in the worktree is
|
|
@@ -391,6 +402,7 @@ fix commit afterwards would void that run's credit.
|
|
|
391
402
|
rows. Close does not run them — CI stays their backstop.
|
|
392
403
|
- **Close stays authoritative.** Its `quality-preview-crap` gate scores a
|
|
393
404
|
fresh capture after `coverage-capture`; a preflight pass never skips it.
|
|
405
|
+
The handoff's post-capture step (§ Credited run) runs that gate early too.
|
|
394
406
|
|
|
395
407
|
## Credited run (situational) {#credited-run}
|
|
396
408
|
|
|
@@ -437,6 +449,15 @@ Digest § 5 states the rule and both invocations; this is what surrounds them.
|
|
|
437
449
|
over the in-scope files is exactly 100% — a lower rate means the artifact's
|
|
438
450
|
coordinates predate the tree. The refusal names the rate, the unresolved
|
|
439
451
|
files and the fix: re-run the digest § 5 capture, then seat.
|
|
452
|
+
- **Post-capture checks.** After depositor and seat, the handoff runs close's
|
|
453
|
+
`quality-preview-crap` entry — only when the depositor is
|
|
454
|
+
`coverage-capture`, so a project with no capture keeps its CRAP behaviour —
|
|
455
|
+
and every registered `check-baselines` entry (`single`, or `independent`
|
|
456
|
+
plus `coverage`), each with close's argv and env (`BASELINE_REF`). A
|
|
457
|
+
non-zero exit is `fix-required` naming the gate and its kinds, with the log
|
|
458
|
+
as evidence; nothing is pushed. They are pure scoring: no lock, no suite,
|
|
459
|
+
no evidence, so close re-scores them. A re-run at a credited, unchanged
|
|
460
|
+
HEAD skips them.
|
|
440
461
|
- **Seat order vs credit.** Neither capture-stamp digest reads
|
|
441
462
|
`baselines/`, so a baseline-JSON-only seat commit leaves it fresh and the
|
|
442
463
|
capture credit stands. The evidence-gate `test` credit is keyed on the tree, so on that
|
package/docs/CHANGELOG.md
CHANGED
|
@@ -15,6 +15,26 @@ All notable changes to this project will be documented in this file.
|
|
|
15
15
|
-->
|
|
16
16
|
<!-- markdownlint-disable-file MD004 MD012 MD037 -->
|
|
17
17
|
|
|
18
|
+
## [2.109.0](https://github.com/dsj1984/mandrel/compare/mandrel-v2.108.0...mandrel-v2.109.0) (2026-10-30)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
* handoff merges the base first, deposits lint/format credit close reuses, and scores CRAP and baselines after the capture ([#5937](https://github.com/dsj1984/mandrel/issues/5937)) ([#5941](https://github.com/dsj1984/mandrel/issues/5941)) ([76f7191](https://github.com/dsj1984/mandrel/commit/76f71918fb06cfc5b99ce2db42039b420b64027f))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
|
|
28
|
+
* **deps:** pin re2js ^2.8.7 tree-wide to clear GHSA-gg6h-894w-4m9c (refs [#5932](https://github.com/dsj1984/mandrel/issues/5932)) ([#5938](https://github.com/dsj1984/mandrel/issues/5938)) ([cf7a25e](https://github.com/dsj1984/mandrel/commit/cf7a25e473514f9061048efa90d46db324c8babd))
|
|
29
|
+
* resolveConfig() keeps project.commands.testChanged so close's base-moved delta re-credit fires ([#5936](https://github.com/dsj1984/mandrel/issues/5936)) ([#5940](https://github.com/dsj1984/mandrel/issues/5940)) ([7931049](https://github.com/dsj1984/mandrel/commit/7931049e346eb29d9139c334a7421c18bcf60271))
|
|
30
|
+
|
|
31
|
+
## [2.108.0](https://github.com/dsj1984/mandrel/compare/mandrel-v2.107.0...mandrel-v2.108.0) (2026-10-27)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### Added
|
|
35
|
+
|
|
36
|
+
* mark admitted suite spawns and export a self-admitting wrapper so hand-run consumer scripts cannot bypass or double-book suite admission ([#5929](https://github.com/dsj1984/mandrel/issues/5929)) ([#5930](https://github.com/dsj1984/mandrel/issues/5930)) ([ed43efc](https://github.com/dsj1984/mandrel/commit/ed43efcc573ac2171f1c59654b2c58bd8059761c))
|
|
37
|
+
|
|
18
38
|
## [2.107.0](https://github.com/dsj1984/mandrel/compare/mandrel-v2.106.0...mandrel-v2.107.0) (2026-10-27)
|
|
19
39
|
|
|
20
40
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mandrel",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.109.0",
|
|
4
4
|
"description": "Claude Code-first opinionated workflow framework: instructions, skills, rules, and SDLC workflows that govern AI coding assistants.",
|
|
5
5
|
"files": [
|
|
6
6
|
".agents/",
|
|
@@ -150,12 +150,14 @@
|
|
|
150
150
|
"dependencies.js-yaml": "States the SAME range as overrides.js-yaml above. The two are deliberate duplicates — npm has no way to reference the direct range from the overrides block — so they MUST move in lockstep; changing one without the other silently splits the direct and transitive resolutions.",
|
|
151
151
|
"overrides.markdown-it": "Load-bearing: markdownlint-cli2 0.24.x declares an EXACT markdown-it 15.0.3, and this tree-wide ^15.0.3 pin keeps every markdown-it consumer on that patched major. The 14.x line carried GHSA-253c-mchw-3w2r (moderate — quadratic linkify paths) and GHSA-gfr2-rv44-r23c (high — quadratic-time rendering of a multi-line link reference definition, vulnerable >=14.1.0 <14.3.3); the pin's floor tracks markdownlint-cli2's own declaration so the two never split. `npm run lint` is what must be re-run if this pin moves.",
|
|
152
152
|
"overrides.smol-toml": "Load-bearing: markdownlint-cli2 0.24.x declares an EXACT smol-toml 1.9.1, and this tree-wide ^1.9.1 pin keeps every smol-toml consumer at or above it. Older lines carried GHSA-7w5x-hrqm-74c2 (high — denial of service via malformed TOML, vulnerable <= 1.7.0) and GHSA-r4xh-jqrq-34v2 (moderate — quadratic-time parse(), vulnerable <= 1.8.0). knip declares ^1.6.1 and is satisfied natively. `npm run lint` is what must be re-run if this pin moves. smol-toml is NOT a direct dependency, so unlike overrides.js-yaml there is no lockstep duplicate range to keep in sync.",
|
|
153
|
-
"overrides.katex": "Clears GHSA-238p-pmpm-9mq7 (low — prototype pollution bypassing trust restrictions, vulnerable >=0.11.0 <0.18.2). katex reaches the tree only through markdownlint (micromark-extension-math declares ^0.16.0, so no lockfile-only resolution reaches the fix). markdownlint imports only the math SYNTAX extension, never the HTML renderer that loads katex, so this tree-wide ^0.18.2 pin changes no executed code; `npm run lint` is what must be re-run if it moves. katex is NOT a direct dependency, so there is no lockstep duplicate range."
|
|
153
|
+
"overrides.katex": "Clears GHSA-238p-pmpm-9mq7 (low — prototype pollution bypassing trust restrictions, vulnerable >=0.11.0 <0.18.2). katex reaches the tree only through markdownlint (micromark-extension-math declares ^0.16.0, so no lockfile-only resolution reaches the fix). markdownlint imports only the math SYNTAX extension, never the HTML renderer that loads katex, so this tree-wide ^0.18.2 pin changes no executed code; `npm run lint` is what must be re-run if it moves. katex is NOT a direct dependency, so there is no lockstep duplicate range.",
|
|
154
|
+
"overrides.re2js": "Clears GHSA-gg6h-894w-4m9c (high — quadratic-time denial of service in lookbehind matching, vulnerable >=2.2.0 <=2.8.6). re2js reaches the tree only through markdownlint, which declares an EXACT re2js 2.8.6 even in its latest release, so neither a lockfile-only resolution nor a parent bump reaches the fix; `npm audit fix --force` would instead downgrade markdownlint-cli2 to 0.23.x and break the overrides above. This tree-wide ^2.8.7 pin stays on the 2.x major; `npm run lint` is what must be re-run if it moves. Drop it once markdownlint declares re2js >= 2.8.7. re2js is NOT a direct dependency, so there is no lockstep duplicate range."
|
|
154
155
|
},
|
|
155
156
|
"overrides": {
|
|
156
157
|
"js-yaml": "^5.4.3",
|
|
157
158
|
"markdown-it": "^15.0.3",
|
|
158
159
|
"smol-toml": "^1.9.1",
|
|
159
|
-
"katex": "^0.18.2"
|
|
160
|
+
"katex": "^0.18.2",
|
|
161
|
+
"re2js": "^2.8.7"
|
|
160
162
|
}
|
|
161
163
|
}
|