mandrel 2.81.0 → 2.83.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/docs/configuration.md +4 -3
- package/.agents/schemas/agentrc.schema.json +1 -1
- package/.agents/scripts/coverage-capture.js +55 -24
- package/.agents/scripts/evidence-gate.js +7 -1
- package/.agents/scripts/lib/audit-to-stories/parse-audit-md.js +49 -24
- package/.agents/scripts/lib/baselines/duplication-scanner.js +35 -7
- package/.agents/scripts/lib/bootstrap/manifest.js +128 -159
- package/.agents/scripts/lib/close-lock-events.js +109 -0
- package/.agents/scripts/lib/close-validation/commands.js +12 -0
- package/.agents/scripts/lib/close-validation/gates.js +6 -0
- package/.agents/scripts/lib/close-validation/process.js +5 -2
- package/.agents/scripts/lib/close-validation/runner.js +14 -4
- package/.agents/scripts/lib/config-settings-schema.js +1 -1
- package/.agents/scripts/lib/full-suite-lock.js +20 -0
- package/.agents/scripts/lib/full-suite-queue.js +24 -56
- package/.agents/scripts/lib/generated/agentrc-validator.js +1 -1
- package/.agents/scripts/lib/orchestration/git-cleanup/phases/cli.js +31 -27
- package/.agents/scripts/lib/orchestration/git-cleanup/phases/render.js +25 -21
- package/.agents/scripts/lib/orchestration/pr-watch-poll.js +107 -0
- package/.agents/scripts/lib/orchestration/pr-watch.js +168 -235
- package/.agents/scripts/lib/orchestration/reassert-status-column.js +102 -72
- package/.agents/scripts/lib/orchestration/single-story-close/phases/close-validation.js +73 -63
- package/.agents/scripts/lib/orchestration/single-story-close/phases/post-land.js +21 -3
- package/.agents/scripts/lib/orchestration/single-story-close/phases/pre-gate-steps.js +44 -2
- package/.agents/scripts/lib/orchestration/single-story-close/phases/reconcile-done.js +63 -0
- package/.agents/scripts/lib/orchestration/single-story-close/runner.js +3 -0
- package/.agents/scripts/lib/orchestration/story-close/duplication-close-rescore.js +257 -0
- package/.agents/scripts/lib/orchestration/story-close/ratchet-shrink-writeback.js +341 -0
- package/.agents/scripts/lib/orchestration/ticketing.js +0 -9
- package/.agents/scripts/lib/supervised-suite.js +8 -28
- package/README.md +167 -216
- package/docs/CHANGELOG.md +29 -0
- package/package.json +1 -1
|
@@ -17,19 +17,26 @@ import {
|
|
|
17
17
|
} from './phase-drivers.js';
|
|
18
18
|
import { buildJsonEnvelope, computeExitCode } from './render.js';
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const DEFAULT_DEPS = Object.freeze({
|
|
21
|
+
runFastForwardPhase,
|
|
22
|
+
runPrunePhase,
|
|
23
|
+
runBranchPhase,
|
|
24
|
+
runStashPhase,
|
|
25
|
+
resolveConfig,
|
|
26
|
+
write: (text) => process.stdout.write(text),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
function resolveBaseBranch(cwd, override, deps) {
|
|
22
30
|
if (override) return override;
|
|
23
31
|
try {
|
|
24
|
-
const cfg = resolveConfig({ cwd });
|
|
32
|
+
const cfg = deps.resolveConfig({ cwd });
|
|
25
33
|
return cfg?.project?.baseBranch || 'main';
|
|
26
34
|
} catch {
|
|
27
35
|
return 'main';
|
|
28
36
|
}
|
|
29
37
|
}
|
|
30
38
|
|
|
31
|
-
|
|
32
|
-
async function runActivePhases(opts, cwd, baseBranch) {
|
|
39
|
+
async function runActivePhases(opts, cwd, baseBranch, deps) {
|
|
33
40
|
const out = {
|
|
34
41
|
fastForward: null,
|
|
35
42
|
prune: null,
|
|
@@ -38,24 +45,23 @@ async function runActivePhases(opts, cwd, baseBranch) {
|
|
|
38
45
|
stashes: null,
|
|
39
46
|
};
|
|
40
47
|
if (opts.phases.fastForwardMain) {
|
|
41
|
-
out.fastForward = await runFastForwardPhase(opts, cwd, baseBranch);
|
|
48
|
+
out.fastForward = await deps.runFastForwardPhase(opts, cwd, baseBranch);
|
|
42
49
|
}
|
|
43
50
|
if (opts.phases.pruneRemotes) {
|
|
44
|
-
out.prune = await runPrunePhase(opts, cwd);
|
|
51
|
+
out.prune = await deps.runPrunePhase(opts, cwd);
|
|
45
52
|
}
|
|
46
53
|
if (opts.phases.branches) {
|
|
47
|
-
const r = await runBranchPhase(opts, cwd, baseBranch);
|
|
54
|
+
const r = await deps.runBranchPhase(opts, cwd, baseBranch);
|
|
48
55
|
out.branchesPlan = r.plan;
|
|
49
56
|
out.branchesResult = r.result;
|
|
50
57
|
}
|
|
51
58
|
if (opts.phases.stashes) {
|
|
52
|
-
out.stashes = await runStashPhase(opts, cwd);
|
|
59
|
+
out.stashes = await deps.runStashPhase(opts, cwd);
|
|
53
60
|
}
|
|
54
61
|
return out;
|
|
55
62
|
}
|
|
56
63
|
|
|
57
|
-
|
|
58
|
-
function maybeEmitJson(opts, baseBranch, phaseResults) {
|
|
64
|
+
function maybeEmitJson(opts, baseBranch, phaseResults, deps) {
|
|
59
65
|
if (!opts.json) return;
|
|
60
66
|
const envelope = buildJsonEnvelope({
|
|
61
67
|
dryRun: opts.dryRun,
|
|
@@ -66,7 +72,7 @@ function maybeEmitJson(opts, baseBranch, phaseResults) {
|
|
|
66
72
|
prune: phaseResults.prune,
|
|
67
73
|
stashes: phaseResults.stashes,
|
|
68
74
|
});
|
|
69
|
-
|
|
75
|
+
deps.write(`${JSON.stringify(envelope)}\n`);
|
|
70
76
|
}
|
|
71
77
|
|
|
72
78
|
/**
|
|
@@ -75,21 +81,19 @@ function maybeEmitJson(opts, baseBranch, phaseResults) {
|
|
|
75
81
|
* `runAsCli(...)` and applies `process.exit(envelope.exitCode)` at the
|
|
76
82
|
* harness boundary so library code stays free of direct `process.exit`
|
|
77
83
|
* calls (see `tests/enforcement/process-exit.test.js`).
|
|
84
|
+
*
|
|
85
|
+
* @param {{ argv?: string[], deps?: Partial<typeof DEFAULT_DEPS> }} [args]
|
|
86
|
+
* `deps` overrides the phase drivers, config resolver and stdout writer.
|
|
78
87
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
88
|
+
export async function runCleanup({
|
|
89
|
+
argv = process.argv.slice(2),
|
|
90
|
+
deps = {},
|
|
91
|
+
} = {}) {
|
|
92
|
+
const d = { ...DEFAULT_DEPS, ...deps };
|
|
93
|
+
const opts = parseCleanupArgs(argv);
|
|
82
94
|
const cwd = path.resolve(opts.cwd ?? PROJECT_ROOT);
|
|
83
|
-
const baseBranch = resolveBaseBranch(cwd, opts.base);
|
|
84
|
-
const phaseResults = await runActivePhases(opts, cwd, baseBranch);
|
|
85
|
-
maybeEmitJson(opts, baseBranch, phaseResults);
|
|
86
|
-
return {
|
|
87
|
-
exitCode: computeExitCode({
|
|
88
|
-
branchesPlan: phaseResults.branchesPlan,
|
|
89
|
-
branchesResult: phaseResults.branchesResult,
|
|
90
|
-
fastForward: phaseResults.fastForward,
|
|
91
|
-
prune: phaseResults.prune,
|
|
92
|
-
stashes: phaseResults.stashes,
|
|
93
|
-
}),
|
|
94
|
-
};
|
|
95
|
+
const baseBranch = resolveBaseBranch(cwd, opts.base, d);
|
|
96
|
+
const phaseResults = await runActivePhases(opts, cwd, baseBranch, d);
|
|
97
|
+
maybeEmitJson(opts, baseBranch, phaseResults, d);
|
|
98
|
+
return { exitCode: computeExitCode(phaseResults) };
|
|
95
99
|
}
|
|
@@ -281,6 +281,30 @@ function legacyExitCode(plan, result) {
|
|
|
281
281
|
return 0;
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
+
function anyPhaseFailed({ branchesResult, fastForward, prune, stashes }) {
|
|
285
|
+
return [branchesResult, fastForward, prune, stashes].some(
|
|
286
|
+
(phase) => phase && !phase.ok,
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function stashDropped(stashes) {
|
|
291
|
+
return (stashes?.actions ?? []).some((a) => a.action === 'drop' && a.dropped);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function anyPhaseWork({ branchesPlan, fastForward, prune, stashes }) {
|
|
295
|
+
return Boolean(
|
|
296
|
+
(branchesPlan?.candidates.length ?? 0) > 0 ||
|
|
297
|
+
fastForward?.applied ||
|
|
298
|
+
(prune?.pruned?.length ?? 0) > 0 ||
|
|
299
|
+
stashDropped(stashes),
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function multiPhaseExitCode(ctx) {
|
|
304
|
+
if (anyPhaseFailed(ctx)) return 1;
|
|
305
|
+
return anyPhaseWork(ctx) ? 0 : 2;
|
|
306
|
+
}
|
|
307
|
+
|
|
284
308
|
/**
|
|
285
309
|
* Accepts `(plan, result)` or a multi-phase context object.
|
|
286
310
|
*
|
|
@@ -292,25 +316,5 @@ export function computeExitCode(ctx, legacyResult) {
|
|
|
292
316
|
if (legacyResult !== undefined || Array.isArray(ctx?.candidates)) {
|
|
293
317
|
return legacyExitCode(ctx, legacyResult);
|
|
294
318
|
}
|
|
295
|
-
|
|
296
|
-
branchesPlan = null,
|
|
297
|
-
branchesResult = null,
|
|
298
|
-
fastForward = null,
|
|
299
|
-
prune = null,
|
|
300
|
-
stashes = null,
|
|
301
|
-
} = ctx ?? {};
|
|
302
|
-
const anyFailure =
|
|
303
|
-
(branchesResult && !branchesResult.ok) ||
|
|
304
|
-
(fastForward && !fastForward.ok) ||
|
|
305
|
-
(prune && !prune.ok) ||
|
|
306
|
-
(stashes && !stashes.ok);
|
|
307
|
-
if (anyFailure) return 1;
|
|
308
|
-
const anyWork =
|
|
309
|
-
(branchesPlan && branchesPlan.candidates.length > 0) ||
|
|
310
|
-
fastForward?.applied ||
|
|
311
|
-
(prune && (prune.pruned?.length ?? 0) > 0) ||
|
|
312
|
-
(stashes &&
|
|
313
|
-
(stashes.actions ?? []).some((a) => a.action === 'drop' && a.dropped));
|
|
314
|
-
if (!anyWork) return 2;
|
|
315
|
-
return 0;
|
|
319
|
+
return multiPhaseExitCode(ctx ?? {});
|
|
316
320
|
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pr-watch-poll.js — the pure outcome helpers and the bounded poll loop
|
|
3
|
+
* behind `watchPrToTerminal` (pr-watch.js).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { checkVerdict, classifyRequiredCheck } from './check-state.js';
|
|
7
|
+
|
|
8
|
+
/** Entries with a string `name`; `[]` for malformed input. */
|
|
9
|
+
export function parseGhPrChecks(stdout) {
|
|
10
|
+
const trimmed = String(stdout ?? '').trim();
|
|
11
|
+
if (trimmed.length === 0) return [];
|
|
12
|
+
try {
|
|
13
|
+
const parsed = JSON.parse(trimmed);
|
|
14
|
+
if (!Array.isArray(parsed)) return [];
|
|
15
|
+
return parsed.filter(
|
|
16
|
+
(e) => e && typeof e === 'object' && typeof e.name === 'string',
|
|
17
|
+
);
|
|
18
|
+
} catch {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** `{ checkName: outcome }`; a repeated name (matrix, retry) — last wins. */
|
|
24
|
+
export function reduceOutcomes(entries) {
|
|
25
|
+
const out = {};
|
|
26
|
+
for (const e of entries) {
|
|
27
|
+
out[e.name] = classifyRequiredCheck(e);
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Only `'pending'` is non-terminal (the classifier collapses running states). */
|
|
33
|
+
export function allTerminal(outcomes) {
|
|
34
|
+
for (const v of Object.values(outcomes)) {
|
|
35
|
+
if (v === 'pending') return false;
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Slow CI, not red: "re-arm the watch", never "the change is broken". */
|
|
41
|
+
const STILL_RUNNING = 'still-running';
|
|
42
|
+
|
|
43
|
+
/** Leftover `'pending'` → `'still-running'` (the schema forbids pending). */
|
|
44
|
+
export function promotePendingToStillRunning(outcomes) {
|
|
45
|
+
const out = {};
|
|
46
|
+
for (const [k, v] of Object.entries(outcomes)) {
|
|
47
|
+
out[k] = v === 'pending' ? STILL_RUNNING : v;
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** A genuinely red check: the hard stop that consumes no resume budget. */
|
|
53
|
+
export function hasFailingCheck(outcomes) {
|
|
54
|
+
return Object.values(outcomes).some((v) => checkVerdict(v) === 'fail');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function identityDiscount(_entries, outcomes) {
|
|
58
|
+
return outcomes;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* A transient `gh` failure is skipped; `maxPolls` bounds a broken `gh`.
|
|
63
|
+
*
|
|
64
|
+
* @param {object} opts
|
|
65
|
+
* @param {string} opts.prUrl
|
|
66
|
+
* @param {string} opts.cwd
|
|
67
|
+
* @param {string|null} [opts.repo] `owner/repo` passed to `gh` as `--repo`.
|
|
68
|
+
* @param {object} opts.outcomes Initial `{ checkName: outcome }` map.
|
|
69
|
+
* @param {number} opts.polls Current poll counter.
|
|
70
|
+
* @param {number} opts.maxPolls Hard cap on total poll iterations.
|
|
71
|
+
* @param {Function} opts.ghPrChecksFn
|
|
72
|
+
* @param {number} opts.pollIntervalMs
|
|
73
|
+
* @param {Function} opts.sleepFn
|
|
74
|
+
* @param {Function} [opts.discountFn]
|
|
75
|
+
* @param {{ warn?: Function }} opts.logger
|
|
76
|
+
* @returns {Promise<{ outcomes: object, polls: number }>}
|
|
77
|
+
*/
|
|
78
|
+
export async function pollUntilTerminal({
|
|
79
|
+
prUrl,
|
|
80
|
+
cwd,
|
|
81
|
+
repo = null,
|
|
82
|
+
outcomes,
|
|
83
|
+
polls,
|
|
84
|
+
maxPolls,
|
|
85
|
+
ghPrChecksFn,
|
|
86
|
+
pollIntervalMs,
|
|
87
|
+
sleepFn,
|
|
88
|
+
discountFn = identityDiscount,
|
|
89
|
+
logger,
|
|
90
|
+
}) {
|
|
91
|
+
let currentOutcomes = outcomes;
|
|
92
|
+
let currentPolls = polls;
|
|
93
|
+
while (!allTerminal(currentOutcomes) && currentPolls < maxPolls) {
|
|
94
|
+
await sleepFn(pollIntervalMs);
|
|
95
|
+
currentPolls += 1;
|
|
96
|
+
const probe = ghPrChecksFn({ prUrl, cwd, repo });
|
|
97
|
+
const entries = parseGhPrChecks(probe.stdout);
|
|
98
|
+
if (entries.length === 0 && probe.status !== 0 && probe.status !== 8) {
|
|
99
|
+
logger.warn?.(
|
|
100
|
+
`[Watcher] gh pr checks transient failure (status=${probe.status}): ${probe.stderr}`,
|
|
101
|
+
);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
currentOutcomes = await discountFn(entries, reduceOutcomes(entries));
|
|
105
|
+
}
|
|
106
|
+
return { outcomes: currentOutcomes, polls: currentPolls };
|
|
107
|
+
}
|