mandrel 2.100.0 → 2.102.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 +7 -1
- package/.agents/audit-checklists/resilience.md +40 -0
- package/.agents/audit-checklists/sre.md +2 -4
- package/.agents/docs/agentrc-reference.json +3 -0
- package/.agents/docs/configuration.md +3 -0
- package/.agents/docs/workflows.md +2 -1
- package/.agents/rules/ci-remediation.md +8 -0
- package/.agents/schemas/agentrc.schema.json +26 -0
- package/.agents/schemas/audit-rules.json +44 -2
- package/.agents/schemas/audit-rules.schema.json +2 -2
- package/.agents/schemas/story-deliver-terminal.schema.json +17 -3
- package/.agents/schemas/validation-evidence.schema.json +10 -0
- package/.agents/scripts/lib/audit-suite/selector.js +80 -1
- package/.agents/scripts/lib/audit-to-stories/audit-lenses.js +1 -0
- package/.agents/scripts/lib/close-lock-events.js +18 -5
- package/.agents/scripts/lib/close-validation/gates.js +6 -1
- package/.agents/scripts/lib/close-validation/runner.js +10 -11
- package/.agents/scripts/lib/close-validation/test-delta.js +124 -0
- package/.agents/scripts/lib/config/pull-request.js +25 -0
- package/.agents/scripts/lib/config-settings-schema-delivery.js +22 -0
- package/.agents/scripts/lib/config-settings-schema.js +5 -0
- package/.agents/scripts/lib/coverage-capture-delta.js +2 -1
- package/.agents/scripts/lib/generated/agentrc-validator.js +2 -2
- package/.agents/scripts/lib/git/sync-from-base.js +4 -2
- package/.agents/scripts/lib/orchestration/ci-red-handling.js +4 -3
- package/.agents/scripts/lib/orchestration/ci-rerun-guard.js +81 -25
- package/.agents/scripts/lib/orchestration/handoff-state.js +41 -0
- package/.agents/scripts/lib/orchestration/review-providers/code-review.js +97 -28
- package/.agents/scripts/lib/orchestration/single-story-close/phases/base-sync.js +7 -0
- package/.agents/scripts/lib/orchestration/single-story-close/phases/close-validation.js +22 -4
- package/.agents/scripts/lib/orchestration/single-story-close/phases/confirm-merge.js +104 -57
- package/.agents/scripts/lib/orchestration/single-story-close/phases/merge-wait-recovery.js +16 -16
- package/.agents/scripts/lib/orchestration/single-story-close/phases/normalize-pr-title.js +28 -13
- package/.agents/scripts/lib/orchestration/single-story-close/phases/open-pr.js +1 -0
- package/.agents/scripts/lib/orchestration/single-story-close/phases/pr-body-trailers.js +38 -0
- package/.agents/scripts/lib/orchestration/single-story-close/phases/pre-push.js +24 -16
- package/.agents/scripts/lib/orchestration/single-story-close/phases/pull-request.js +18 -7
- package/.agents/scripts/lib/orchestration/single-story-close/runner.js +60 -34
- package/.agents/scripts/lib/orchestration/story-deliver-terminal.js +1 -1
- package/.agents/scripts/lib/orchestration/story-handoff.js +36 -9
- package/.agents/scripts/lib/test-run-credit.js +26 -0
- package/.agents/scripts/lib/validation-evidence.js +6 -0
- package/.agents/workflows/audit-resilience.md +290 -0
- package/.agents/workflows/audit-sre.md +12 -21
- package/.agents/workflows/helpers/deliver-reference.md +28 -1
- package/docs/CHANGELOG.md +25 -0
- package/package.json +1 -1
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Close's `test` delta re-credit: after base-sync merged incoming paths, plan
|
|
3
|
+
* a `testChanged` run keyed on the pre-sync head instead of the full suite.
|
|
4
|
+
* The incoming-path rules are coverage-capture's own delta rules.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { getChangedFiles } from '../changed-files.js';
|
|
8
|
+
import { deltaIneligibility } from '../coverage-capture-delta.js';
|
|
9
|
+
import { hasTestCreditAt } from '../test-run-credit.js';
|
|
10
|
+
import { resolveTestGateArgv } from './commands.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* `project.commands.testChanged`: absent or `null` is disabled with no argv —
|
|
14
|
+
* it has no default. The schema guards it like every other command.
|
|
15
|
+
*
|
|
16
|
+
* @param {object|null|undefined} config
|
|
17
|
+
*/
|
|
18
|
+
function resolveTestChangedCommand(config) {
|
|
19
|
+
const raw = config?.project?.commands?.testChanged?.trim() || null;
|
|
20
|
+
const [cmd, ...args] = raw ? raw.split(/\s+/) : [];
|
|
21
|
+
return { cmd, args, raw, disabled: raw === null };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const CHANGED_SINCE_TOKEN = '$MANDREL_CHANGED_SINCE';
|
|
25
|
+
|
|
26
|
+
/** `testChanged` keyed on `since`, credited as the full suite; no shell runs it, so the token is substituted here. */
|
|
27
|
+
function buildTestDeltaGate({ config, testChanged, since, incoming }) {
|
|
28
|
+
const label = `test (delta since ${since.slice(0, 12)}, ${incoming} incoming path(s))`;
|
|
29
|
+
return {
|
|
30
|
+
name: 'test',
|
|
31
|
+
label,
|
|
32
|
+
cmd: testChanged.cmd,
|
|
33
|
+
args: testChanged.args.map((a) => (a === CHANGED_SINCE_TOKEN ? since : a)),
|
|
34
|
+
env: { MANDREL_CHANGED_SINCE: since },
|
|
35
|
+
fullSuiteLock: true,
|
|
36
|
+
evidenceIdentity: resolveTestGateArgv(config),
|
|
37
|
+
evidenceNote: { scope: 'delta', since },
|
|
38
|
+
hint: `The delta re-credit failed — \`${testChanged.raw}\` (\`project.commands.testChanged\`, scope: delta, the tests affected since ${since.slice(0, 12)}) exited non-zero after the base sync. Fix the failing tests, commit, and re-run close.`,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Why the delta cannot replace the full run, or `null`; probes run lazily, cheapest first. */
|
|
43
|
+
function testDeltaIneligibility({
|
|
44
|
+
testChanged,
|
|
45
|
+
captureRuns,
|
|
46
|
+
credited,
|
|
47
|
+
incoming,
|
|
48
|
+
storyFiles,
|
|
49
|
+
}) {
|
|
50
|
+
if (testChanged.disabled) return 'no `project.commands.testChanged`';
|
|
51
|
+
if (captureRuns) return 'coverage-capture runs the suite';
|
|
52
|
+
if (!credited()) return 'no `test` credit for the pre-sync head';
|
|
53
|
+
const files = storyFiles();
|
|
54
|
+
if (!files) return 'Story change set unreadable';
|
|
55
|
+
return deltaIneligibility({ delta: incoming, storyFiles: files });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The Story's own change set against the synced base, or `null`. */
|
|
59
|
+
function readStoryFiles({ cwd, baseBranch, getChangedFilesImpl }) {
|
|
60
|
+
if (!cwd || !baseBranch) return null;
|
|
61
|
+
try {
|
|
62
|
+
const files = getChangedFilesImpl({ ref: `origin/${baseBranch}`, cwd });
|
|
63
|
+
return Array.isArray(files) ? files : null;
|
|
64
|
+
} catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Swap the plain `test` gate for the delta re-credit when every rule holds;
|
|
71
|
+
* otherwise return `gates` unchanged, logging the failed rule (no base move
|
|
72
|
+
* logs nothing). No plain `test` gate means coverage-capture runs the suite.
|
|
73
|
+
*
|
|
74
|
+
* @param {import('./gates.js').Gate[]} gates
|
|
75
|
+
* @returns {import('./gates.js').Gate[]}
|
|
76
|
+
*/
|
|
77
|
+
export function applyTestDelta(
|
|
78
|
+
gates,
|
|
79
|
+
{
|
|
80
|
+
baseSync,
|
|
81
|
+
config,
|
|
82
|
+
storyId,
|
|
83
|
+
cwd,
|
|
84
|
+
evidenceCwd,
|
|
85
|
+
baseBranch,
|
|
86
|
+
shouldSkipImpl,
|
|
87
|
+
getChangedFilesImpl = getChangedFiles,
|
|
88
|
+
log,
|
|
89
|
+
},
|
|
90
|
+
) {
|
|
91
|
+
const incoming = baseSync?.changedPaths ?? [];
|
|
92
|
+
if (incoming.length === 0) return gates;
|
|
93
|
+
const since = baseSync.creditedCommit;
|
|
94
|
+
const testChanged = resolveTestChangedCommand(config);
|
|
95
|
+
const index = gates.findIndex((g) => g.name === 'test');
|
|
96
|
+
const reason = testDeltaIneligibility({
|
|
97
|
+
testChanged,
|
|
98
|
+
captureRuns: index === -1,
|
|
99
|
+
credited: () =>
|
|
100
|
+
hasTestCreditAt({
|
|
101
|
+
config,
|
|
102
|
+
storyId,
|
|
103
|
+
cwd,
|
|
104
|
+
evidenceCwd,
|
|
105
|
+
sha: since,
|
|
106
|
+
...(shouldSkipImpl ? { shouldSkipImpl } : {}),
|
|
107
|
+
}),
|
|
108
|
+
incoming,
|
|
109
|
+
storyFiles: () => readStoryFiles({ cwd, baseBranch, getChangedFilesImpl }),
|
|
110
|
+
});
|
|
111
|
+
if (reason) {
|
|
112
|
+
log?.(
|
|
113
|
+
`[close-validation] test delta re-credit not eligible (${reason}) — running the full suite`,
|
|
114
|
+
);
|
|
115
|
+
return gates;
|
|
116
|
+
}
|
|
117
|
+
const delta = buildTestDeltaGate({
|
|
118
|
+
config,
|
|
119
|
+
testChanged,
|
|
120
|
+
since,
|
|
121
|
+
incoming: incoming.length,
|
|
122
|
+
});
|
|
123
|
+
return gates.map((g, i) => (i === index ? delta : g));
|
|
124
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** `delivery.pullRequest`: trailer keys close lifts into the PR body. */
|
|
2
|
+
|
|
3
|
+
export const TRAILER_KEY_PATTERN = '^[A-Za-z][A-Za-z0-9-]*$';
|
|
4
|
+
|
|
5
|
+
export const PULL_REQUEST_DELIVERY_DEFAULTS = Object.freeze({
|
|
6
|
+
bodyTrailers: Object.freeze([]),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const TRAILER_KEY_RE = new RegExp(TRAILER_KEY_PATTERN);
|
|
10
|
+
|
|
11
|
+
/** Accepts the full config, `delivery`, or `pullRequest`; drops bad keys. */
|
|
12
|
+
export function getPullRequestDelivery(config) {
|
|
13
|
+
const block =
|
|
14
|
+
config?.delivery?.pullRequest ?? config?.pullRequest ?? config ?? {};
|
|
15
|
+
const keys = Array.isArray(block.bodyTrailers) ? block.bodyTrailers : [];
|
|
16
|
+
return {
|
|
17
|
+
bodyTrailers: [
|
|
18
|
+
...new Set(
|
|
19
|
+
keys.filter(
|
|
20
|
+
(key) => typeof key === 'string' && TRAILER_KEY_RE.test(key),
|
|
21
|
+
),
|
|
22
|
+
),
|
|
23
|
+
],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -9,6 +9,10 @@ import {
|
|
|
9
9
|
} from './config/agent-models.js';
|
|
10
10
|
import { CI_DELIVERY_DEFAULTS } from './config/ci.js';
|
|
11
11
|
import { DELIVERY_ROUTING_DEFAULTS } from './config/delivery-routing.js';
|
|
12
|
+
import {
|
|
13
|
+
PULL_REQUEST_DELIVERY_DEFAULTS,
|
|
14
|
+
TRAILER_KEY_PATTERN,
|
|
15
|
+
} from './config/pull-request.js';
|
|
12
16
|
import { DEFAULT_CODE_REVIEW } from './config/runners.js';
|
|
13
17
|
import { WORKTREE_ISOLATION_DEFAULTS } from './config/worktree-isolation.js';
|
|
14
18
|
import { SHELL_INJECTION_PATTERN_STRING } from './config-schema-shared.js';
|
|
@@ -280,6 +284,23 @@ const CI_DELIVERY_SCHEMA = {
|
|
|
280
284
|
additionalProperties: false,
|
|
281
285
|
};
|
|
282
286
|
|
|
287
|
+
const PULL_REQUEST_DELIVERY_SCHEMA = {
|
|
288
|
+
type: 'object',
|
|
289
|
+
description:
|
|
290
|
+
'Story #5875. What close writes into the pull request it opens, beyond the title and the `Closes #<id>` line.',
|
|
291
|
+
properties: {
|
|
292
|
+
bodyTrailers: {
|
|
293
|
+
type: 'array',
|
|
294
|
+
items: { type: 'string', pattern: TRAILER_KEY_PATTERN },
|
|
295
|
+
uniqueItems: true,
|
|
296
|
+
description:
|
|
297
|
+
'Story #5875. Git-trailer keys close lifts from the Story branch commits into the PR body, for a consumer whose required check reads a body line (e.g. `Policy-impact`). For each key the last branch commit carrying `<Key>: <value>` as a trailer wins, and the line is appended after the auto-opened marker and before any `BREAKING CHANGE:` footer. A key no commit carries appends nothing and logs one info line. Workers record the value with `git commit --trailer`. Default [] leaves the body unchanged.',
|
|
298
|
+
default: [...PULL_REQUEST_DELIVERY_DEFAULTS.bodyTrailers],
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
additionalProperties: false,
|
|
302
|
+
};
|
|
303
|
+
|
|
283
304
|
const REFACTOR_STAGE_SCHEMA = {
|
|
284
305
|
type: 'object',
|
|
285
306
|
description:
|
|
@@ -412,6 +433,7 @@ export const DELIVERY_SCHEMA = {
|
|
|
412
433
|
acceptanceEval: ACCEPTANCE_EVAL_SCHEMA,
|
|
413
434
|
feedbackLoop: FEEDBACK_LOOP_SCHEMA,
|
|
414
435
|
ci: CI_DELIVERY_SCHEMA,
|
|
436
|
+
pullRequest: PULL_REQUEST_DELIVERY_SCHEMA,
|
|
415
437
|
routing: ROUTING_SCHEMA,
|
|
416
438
|
},
|
|
417
439
|
additionalProperties: false,
|
|
@@ -86,6 +86,11 @@ const COMMANDS_SCHEMA = {
|
|
|
86
86
|
"Full test-suite command close's `test` gate spawns, and the identity its `test` credit is hashed under — the deposit `run-tests.js` makes, close's credit probe and `verify[]` credit all key on it, as does `mandrel doctor`'s `test-credit-path` check. Set it for a non-npm project (e.g. `python3 scripts/validation.py`). Mandatory: `null` is rejected.",
|
|
87
87
|
default: COMMANDS_DEFAULTS.test,
|
|
88
88
|
},
|
|
89
|
+
testChanged: {
|
|
90
|
+
...NULLABLE_NONEMPTY_SAFE_STRING,
|
|
91
|
+
description:
|
|
92
|
+
"Optional changed-tests command for the delta re-credit: when close's base sync merged sibling landings into a branch whose pre-sync head holds `test` credit, close's `test` gate runs this instead of the full suite, with the credited commit in the `MANDREL_CHANGED_SINCE` environment variable and in place of a literal `$MANDREL_CHANGED_SINCE` argument (e.g. `pnpm vitest run --changed $MANDREL_CHANGED_SINCE`; no shell runs it), and a green run re-credits the merged tree. Ineligible when coverage-capture runs the suite, an incoming path is a coverage-config file or one of the Story's own files. Absent or `null` keeps the full re-run.",
|
|
93
|
+
},
|
|
89
94
|
typecheck: {
|
|
90
95
|
...NULLABLE_NONEMPTY_SAFE_STRING,
|
|
91
96
|
description:
|
|
@@ -118,7 +118,8 @@ function treeIneligibility({ cwd, commit, spawn }) {
|
|
|
118
118
|
return null;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
/** Shared with close's `test` delta re-credit: the reason a delta is ineligible, or `null`. */
|
|
122
|
+
export function deltaIneligibility({ delta, storyFiles }) {
|
|
122
123
|
if (delta.length === 0) return 'no committed delta since the stamp';
|
|
123
124
|
const story = new Set(storyFiles);
|
|
124
125
|
const shared = delta.find((f) => story.has(f));
|