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
|
@@ -116,8 +116,8 @@ function unmergedPaths(gitSpawn, cwd) {
|
|
|
116
116
|
*
|
|
117
117
|
* @returns {Promise<
|
|
118
118
|
* | { synced: true, kind: 'noop-already-current', changedPaths: string[] }
|
|
119
|
-
* | { synced: true, kind: 'fast-forward', changedPaths: string[] }
|
|
120
|
-
* | { synced: true, kind: 'merge-commit', changedPaths: string[], resolvedBaselineFiles?: string[] }
|
|
119
|
+
* | { synced: true, kind: 'fast-forward', changedPaths: string[], preSyncHead: string|null }
|
|
120
|
+
* | { synced: true, kind: 'merge-commit', changedPaths: string[], preSyncHead: string|null, resolvedBaselineFiles?: string[] }
|
|
121
121
|
* | { synced: false, kind: 'fetch-failed', stderr: string }
|
|
122
122
|
* | { synced: false, kind: 'conflict', conflictFiles: string[] }
|
|
123
123
|
* | { synced: false, kind: 'merge-failed', stderr: string }
|
|
@@ -195,6 +195,7 @@ export async function syncBranchFromBase({
|
|
|
195
195
|
synced: true,
|
|
196
196
|
kind: willFastForward ? 'fast-forward' : 'merge-commit',
|
|
197
197
|
changedPaths: diffPaths(gitSpawn, cwd, preMergeHead),
|
|
198
|
+
preSyncHead: preMergeHead,
|
|
198
199
|
};
|
|
199
200
|
}
|
|
200
201
|
|
|
@@ -243,6 +244,7 @@ function resolveBaselineOnlyConflict({
|
|
|
243
244
|
synced: true,
|
|
244
245
|
kind: 'merge-commit',
|
|
245
246
|
changedPaths: diffPaths(gitSpawn, cwd, preMergeHead),
|
|
247
|
+
preSyncHead: preMergeHead,
|
|
246
248
|
resolvedBaselineFiles: conflictFiles,
|
|
247
249
|
};
|
|
248
250
|
}
|
|
@@ -15,8 +15,8 @@ import {
|
|
|
15
15
|
} from './ci-rerun-guard.js';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* The first-red handling every
|
|
19
|
-
*
|
|
18
|
+
* The first-red handling every red goes through — the watcher's red path,
|
|
19
|
+
* the close's `checks-failed` fail-fast and its advisory-gate block alike: disarm
|
|
20
20
|
* auto-merge FIRST (the race-free moment), then write the digest keyed to the
|
|
21
21
|
* red head SHA. One implementation, so the guard cannot drift per path.
|
|
22
22
|
* Never throws: a digest-write failure is returned as `digestError`.
|
|
@@ -25,7 +25,8 @@ import {
|
|
|
25
25
|
* @param {number|string|null} [opts.storyId]
|
|
26
26
|
* @param {number} opts.prNumber
|
|
27
27
|
* @param {string} opts.prRef
|
|
28
|
-
* @param {Array<{name:string, outcome:string}>} opts.failures
|
|
28
|
+
* @param {Array<{name:string, outcome:string, required?:boolean}>} opts.failures
|
|
29
|
+
* `required: false` marks an advisory red; absent reads as required.
|
|
29
30
|
* @param {string} opts.tempRoot
|
|
30
31
|
* @param {string} opts.cwd
|
|
31
32
|
* @param {(args: { prRef: string }) => Promise<{ disarmed: boolean, alreadyUnarmed?: boolean, detail: string }>} opts.disarmFn
|
|
@@ -256,11 +256,22 @@ function carryPriorReds(previous, headSha) {
|
|
|
256
256
|
return history.slice(-MAX_PRIOR_REDS);
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
+
/** `required` unless the entry says `required: false` — an old digest is never advisory. */
|
|
260
|
+
function isRequiredFailure(failure) {
|
|
261
|
+
return failure?.required !== false;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** `name`=outcome plus whether the check is required or advisory. */
|
|
265
|
+
function describeFailure(failure) {
|
|
266
|
+
const kind = isRequiredFailure(failure) ? 'required' : 'advisory';
|
|
267
|
+
return `\`${failure.name}\`=${failure.outcome} (${kind})`;
|
|
268
|
+
}
|
|
269
|
+
|
|
259
270
|
function renderDigestMarkdown(digest, failures) {
|
|
260
271
|
return [
|
|
261
272
|
`# CI failure digest — Story #${digest.storyId} (PR #${digest.prNumber})`,
|
|
262
273
|
'',
|
|
263
|
-
`- **Failing check:**
|
|
274
|
+
`- **Failing check:** ${describeFailure(failures[0] ?? { name: digest.failingCheck, outcome: digest.failingOutcome })}`,
|
|
264
275
|
`- **Head SHA:** ${digest.headSha ?? 'unresolved'}`,
|
|
265
276
|
`- **Run id:** ${digest.runId ?? 'unresolved'}`,
|
|
266
277
|
`- **Run link:** ${digest.runUrl ?? 'unresolved'}`,
|
|
@@ -270,7 +281,7 @@ function renderDigestMarkdown(digest, failures) {
|
|
|
270
281
|
failures.length > 1
|
|
271
282
|
? `Other non-green checks: ${failures
|
|
272
283
|
.slice(1)
|
|
273
|
-
.map(
|
|
284
|
+
.map(describeFailure)
|
|
274
285
|
.join(', ')}`
|
|
275
286
|
: '',
|
|
276
287
|
digest.priorReds.length > 0
|
|
@@ -301,7 +312,8 @@ function renderDigestMarkdown(digest, failures) {
|
|
|
301
312
|
* @param {number|string|null} [opts.storyId] The v2 delivery scope.
|
|
302
313
|
* @param {number} opts.prNumber
|
|
303
314
|
* @param {string|null} [opts.headSha] PR head SHA at the moment of the red.
|
|
304
|
-
* @param {Array<{name:string, outcome:string}>} opts.failures
|
|
315
|
+
* @param {Array<{name:string, outcome:string, required?:boolean}>} opts.failures
|
|
316
|
+
* `required` is recorded per entry; anything but `false` is stored as `true`.
|
|
305
317
|
* @param {string} opts.tempRoot
|
|
306
318
|
* @param {string} opts.cwd
|
|
307
319
|
* @param {string} opts.prRef
|
|
@@ -324,7 +336,15 @@ export function writeCiDigest({
|
|
|
324
336
|
}) {
|
|
325
337
|
const paths = ciDigestPaths({ storyId, tempRoot, cwd });
|
|
326
338
|
if (!paths) return null;
|
|
327
|
-
const
|
|
339
|
+
const recorded = failures.map((f) => ({
|
|
340
|
+
...f,
|
|
341
|
+
required: isRequiredFailure(f),
|
|
342
|
+
}));
|
|
343
|
+
const primary = recorded[0] ?? {
|
|
344
|
+
name: 'unknown',
|
|
345
|
+
outcome: 'failure',
|
|
346
|
+
required: true,
|
|
347
|
+
};
|
|
328
348
|
const checkRun =
|
|
329
349
|
checkRunFn({ prRef, checkName: primary.name, cwd, spawnFn }) ?? {};
|
|
330
350
|
const logTail = logTailFn({ runId: checkRun.runId, cwd, spawnFn });
|
|
@@ -344,13 +364,13 @@ export function writeCiDigest({
|
|
|
344
364
|
url: checkRun.url ?? null,
|
|
345
365
|
},
|
|
346
366
|
classification: classifyFailure(primary.name),
|
|
347
|
-
allFailures:
|
|
367
|
+
allFailures: recorded,
|
|
348
368
|
priorReds: carryPriorReds(previous, headSha),
|
|
349
369
|
logTail,
|
|
350
370
|
generatedAt: new Date().toISOString(),
|
|
351
371
|
};
|
|
352
372
|
writeFileAtomic(paths.jsonPath, `${JSON.stringify(digest, null, 2)}\n`);
|
|
353
|
-
writeFileAtomic(paths.mdPath, renderDigestMarkdown(digest,
|
|
373
|
+
writeFileAtomic(paths.mdPath, renderDigestMarkdown(digest, recorded));
|
|
354
374
|
return { jsonPath: paths.jsonPath, mdPath: paths.mdPath };
|
|
355
375
|
}
|
|
356
376
|
|
|
@@ -411,13 +431,64 @@ function allowanceFor(digest, headSha) {
|
|
|
411
431
|
: null;
|
|
412
432
|
}
|
|
413
433
|
|
|
434
|
+
/**
|
|
435
|
+
* The digest's failures when every one is advisory and `checks` reads each
|
|
436
|
+
* `success` on this head; `null` otherwise (a required, still-red or unread
|
|
437
|
+
* check keeps the no-rerun guard).
|
|
438
|
+
*
|
|
439
|
+
* @param {object} digest
|
|
440
|
+
* @param {Record<string, string>|null|undefined} checks
|
|
441
|
+
* @returns {Array<{ name: string, outcome: string }>|null}
|
|
442
|
+
*/
|
|
443
|
+
function clearedAdvisoryFailures(digest, checks) {
|
|
444
|
+
const failures = digest.allFailures;
|
|
445
|
+
if (!Array.isArray(failures) || failures.length === 0) return null;
|
|
446
|
+
if (!checks || typeof checks !== 'object') return null;
|
|
447
|
+
const cleared = failures.every(
|
|
448
|
+
(f) => !isRequiredFailure(f) && checks[f?.name] === 'success',
|
|
449
|
+
);
|
|
450
|
+
return cleared ? failures : null;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* A green on the head the red was recorded against: `advisory-cleared`, the
|
|
455
|
+
* allowance's one rerun, or a forbidden rerun.
|
|
456
|
+
*
|
|
457
|
+
* @returns {{ verdict: string, reason: string }}
|
|
458
|
+
*/
|
|
459
|
+
function sameHeadVerdict(digest, headSha, checks) {
|
|
460
|
+
const cleared = clearedAdvisoryFailures(digest, checks);
|
|
461
|
+
if (cleared) {
|
|
462
|
+
return {
|
|
463
|
+
verdict: 'advisory-cleared',
|
|
464
|
+
reason: `advisory check(s) ${cleared.map((f) => `\`${f.name}\``).join(', ')} now green on head ${headSha}`,
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
// Not cleared: an advisory red still red keeps the required-red rule.
|
|
468
|
+
const allowance = allowanceFor(digest, headSha);
|
|
469
|
+
return isRerunPermitted({
|
|
470
|
+
required: true,
|
|
471
|
+
allowanceRecorded: allowance !== null,
|
|
472
|
+
})
|
|
473
|
+
? {
|
|
474
|
+
verdict: 'rerun-permitted',
|
|
475
|
+
reason: `one rerun admitted: \`${allowance.verdict}\` verdict recorded for this head SHA (${headSha})`,
|
|
476
|
+
}
|
|
477
|
+
: {
|
|
478
|
+
verdict: 'rerun',
|
|
479
|
+
reason: `green on the SAME head SHA the red was recorded against (${headSha})`,
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
|
|
414
483
|
/**
|
|
415
484
|
* Adjudicate an all-green watch against the scope's digest (see header).
|
|
485
|
+
* `checks` — the probe's per-check states (`name → success|failure|pending`)
|
|
486
|
+
* for the current head — admits `advisory-cleared`.
|
|
416
487
|
*
|
|
417
|
-
* @param {{ digest: object|null, headSha: string|null }} opts
|
|
418
|
-
* @returns {{ verdict: 'clean'|'fix-at-source'|'rerun-permitted'|'rerun'|'unverifiable', reason: string }}
|
|
488
|
+
* @param {{ digest: object|null, headSha: string|null, checks?: Record<string, string>|null }} opts
|
|
489
|
+
* @returns {{ verdict: 'clean'|'fix-at-source'|'rerun-permitted'|'rerun'|'unverifiable'|'advisory-cleared', reason: string }}
|
|
419
490
|
*/
|
|
420
|
-
export function classifyGreenVerdict({ digest, headSha }) {
|
|
491
|
+
export function classifyGreenVerdict({ digest, headSha, checks }) {
|
|
421
492
|
if (!digest) return { verdict: 'clean', reason: 'no digest for this scope' };
|
|
422
493
|
const recorded = digest.headSha ?? null;
|
|
423
494
|
if (!recorded || !headSha) {
|
|
@@ -426,22 +497,7 @@ export function classifyGreenVerdict({ digest, headSha }) {
|
|
|
426
497
|
reason: `cannot prove the red was fixed at source (digest head=${recorded ?? 'unknown'}, current head=${headSha ?? 'unresolved'})`,
|
|
427
498
|
};
|
|
428
499
|
}
|
|
429
|
-
if (recorded === headSha)
|
|
430
|
-
// Digests only record required checks.
|
|
431
|
-
const allowance = allowanceFor(digest, headSha);
|
|
432
|
-
return isRerunPermitted({
|
|
433
|
-
required: true,
|
|
434
|
-
allowanceRecorded: allowance !== null,
|
|
435
|
-
})
|
|
436
|
-
? {
|
|
437
|
-
verdict: 'rerun-permitted',
|
|
438
|
-
reason: `one rerun admitted: \`${allowance.verdict}\` verdict recorded for this head SHA (${headSha})`,
|
|
439
|
-
}
|
|
440
|
-
: {
|
|
441
|
-
verdict: 'rerun',
|
|
442
|
-
reason: `green on the SAME head SHA the red was recorded against (${headSha})`,
|
|
443
|
-
};
|
|
444
|
-
}
|
|
500
|
+
if (recorded === headSha) return sameHeadVerdict(digest, headSha, checks);
|
|
445
501
|
return {
|
|
446
502
|
verdict: 'fix-at-source',
|
|
447
503
|
reason: `head SHA moved ${recorded} → ${headSha}`,
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* handoff-state.js — where `story-handoff.js` keeps its per-Story state, and
|
|
3
|
+
* the one read close makes of it: the credited run's lock wait and suite
|
|
4
|
+
* timings. Kept apart from the handoff so close need not load its graph.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
|
|
10
|
+
import { orchestrationLogDir } from '../config/temp-paths.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {string} logDir
|
|
14
|
+
* @param {number} storyId
|
|
15
|
+
* @returns {string}
|
|
16
|
+
*/
|
|
17
|
+
export function handoffStatePath(logDir, storyId) {
|
|
18
|
+
return path.join(logDir, `story-handoff-${storyId}.json`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* `null` unless the state's `creditTimings` is keyed to its current
|
|
23
|
+
* `creditHead` and that run spawned a suite.
|
|
24
|
+
*
|
|
25
|
+
* @param {number} storyId
|
|
26
|
+
* @param {object} config
|
|
27
|
+
* @param {{ fsImpl?: typeof fs }} [opts]
|
|
28
|
+
* @returns {{ head: string, lockWait: object|null, suiteTimings: object, spawns: object[] }|null}
|
|
29
|
+
*/
|
|
30
|
+
export function readCreditTimings(storyId, config, { fsImpl = fs } = {}) {
|
|
31
|
+
let state;
|
|
32
|
+
try {
|
|
33
|
+
const file = handoffStatePath(orchestrationLogDir(config), storyId);
|
|
34
|
+
state = JSON.parse(fsImpl.readFileSync(file, 'utf8'))?.state;
|
|
35
|
+
} catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const credit = state?.creditTimings;
|
|
39
|
+
if (!credit?.suiteTimings || credit.head !== state.creditHead) return null;
|
|
40
|
+
return credit;
|
|
41
|
+
}
|
|
@@ -12,9 +12,10 @@
|
|
|
12
12
|
* A missing CLI throws at construction (the chain entry is optional). A
|
|
13
13
|
* review with no verdict records one degraded gate via `getDegradations()`
|
|
14
14
|
* and returns no findings, so "never ran" cannot read as "found nothing".
|
|
15
|
-
* A
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* A diff over the cap is reviewed chunk by chunk (file-aligned, sequential,
|
|
16
|
+
* findings merged); what went unchecked — a truncated file, files past the
|
|
17
|
+
* chunk bound, a chunk with no verdict, a capped `<callers>` block — is
|
|
18
|
+
* recorded beside the findings, naming the files.
|
|
18
19
|
*
|
|
19
20
|
* @typedef {import('./types.js').Finding} Finding
|
|
20
21
|
* @typedef {import('./types.js').ReviewInput} ReviewInput
|
|
@@ -55,8 +56,10 @@ const CLAUDE_ARGS = Object.freeze([
|
|
|
55
56
|
const AUTH_ARGS = Object.freeze(['auth', 'status', '--json']);
|
|
56
57
|
const INVOKE_TIMEOUT_MS = 10 * 60 * 1000;
|
|
57
58
|
const AUTH_TIMEOUT_MS = 15 * 1000;
|
|
58
|
-
/** Larger diffs are
|
|
59
|
+
/** Larger diffs are reviewed in file-aligned chunks of at most this size. */
|
|
59
60
|
const MAX_DIFF_CHARS = 200_000;
|
|
61
|
+
/** Files packed past this many chunks are not reviewed; each is degraded by name. */
|
|
62
|
+
const MAX_REVIEW_CHUNKS = 6;
|
|
60
63
|
const DEGRADATION_BASE = Object.freeze({
|
|
61
64
|
tool: 'code-review',
|
|
62
65
|
gate: 'codeReview',
|
|
@@ -81,40 +84,67 @@ const PROMPT_HEAD =
|
|
|
81
84
|
'Emit {"findings":[]} if there is nothing you would block the merge for.\n\n';
|
|
82
85
|
|
|
83
86
|
/**
|
|
84
|
-
*
|
|
85
|
-
* unreviewed character count and the files whose first header is past the cut.
|
|
87
|
+
* Split a diff at `diff --git` boundaries into per-file sections.
|
|
86
88
|
*
|
|
87
89
|
* @param {string} diff
|
|
88
|
-
* @returns {string
|
|
90
|
+
* @returns {{ file: string, text: string }[]}
|
|
89
91
|
*/
|
|
90
|
-
function
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
function splitSections(diff) {
|
|
93
|
+
const starts = [...diff.matchAll(/^diff --git /gm)].map((m) => m.index);
|
|
94
|
+
if (starts[0] !== 0) starts.unshift(0);
|
|
95
|
+
return starts.map((start, i) => {
|
|
96
|
+
const text = diff.slice(start, starts[i + 1] ?? diff.length);
|
|
97
|
+
const name =
|
|
98
|
+
text.match(/^\+\+\+ b\/(.+)$/m) ??
|
|
99
|
+
text.match(/^diff --git a\/.+ b\/(.+)$/m);
|
|
100
|
+
return { file: name ? name[1] : '(unnamed)', text };
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* First-fit, in diff order, into chunks of at most `budget` characters; a
|
|
106
|
+
* section over the budget gets a chunk of its own (truncated when reviewed).
|
|
107
|
+
*
|
|
108
|
+
* @param {{ file: string, text: string }[]} sections
|
|
109
|
+
* @param {number} budget
|
|
110
|
+
*/
|
|
111
|
+
function packChunks(sections, budget) {
|
|
112
|
+
const chunks = [];
|
|
113
|
+
for (const section of sections) {
|
|
114
|
+
const size = section.text.length;
|
|
115
|
+
const open = chunks.find((c) => c.size + size <= budget);
|
|
116
|
+
if (open) {
|
|
117
|
+
open.sections.push(section);
|
|
118
|
+
open.size += size;
|
|
119
|
+
} else {
|
|
120
|
+
chunks.push({ sections: [section], size });
|
|
121
|
+
}
|
|
95
122
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
123
|
+
return chunks;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** @param {Finding[]} findings */
|
|
127
|
+
function dedupeFindings(findings) {
|
|
128
|
+
const seen = new Set();
|
|
129
|
+
return findings.filter((f) => {
|
|
130
|
+
const key = JSON.stringify([f.file, f.line, f.title]);
|
|
131
|
+
if (seen.has(key)) return false;
|
|
132
|
+
seen.add(key);
|
|
133
|
+
return true;
|
|
134
|
+
});
|
|
104
135
|
}
|
|
105
136
|
|
|
106
137
|
/**
|
|
107
138
|
* @param {ReviewInput} input
|
|
108
139
|
* @param {string} diff
|
|
109
140
|
* @param {string} callers - the `<callers>` section, or '' below `deep`.
|
|
141
|
+
* @param {number} [cap]
|
|
110
142
|
* @returns {string}
|
|
111
143
|
*/
|
|
112
|
-
function buildPrompt(input, diff, callers) {
|
|
113
|
-
const truncated = diff.length >
|
|
114
|
-
const body = truncated ? diff.slice(0,
|
|
115
|
-
const note = truncated
|
|
116
|
-
? `\n[diff truncated at ${MAX_DIFF_CHARS} characters]\n`
|
|
117
|
-
: '';
|
|
144
|
+
function buildPrompt(input, diff, callers, cap = MAX_DIFF_CHARS) {
|
|
145
|
+
const truncated = diff.length > cap;
|
|
146
|
+
const body = truncated ? diff.slice(0, cap) : diff;
|
|
147
|
+
const note = truncated ? `\n[diff truncated at ${cap} characters]\n` : '';
|
|
118
148
|
const head = PROMPT_HEAD.replace('{baseRef}', input.baseRef)
|
|
119
149
|
.replace('{headRef}', input.headRef)
|
|
120
150
|
.replace('{ticketId}', String(input.ticketId))
|
|
@@ -253,6 +283,44 @@ export function createCodeReviewProviderForRegistry(deps = {}) {
|
|
|
253
283
|
return [];
|
|
254
284
|
}
|
|
255
285
|
|
|
286
|
+
/** The `<callers>` block rides every chunk, so it comes out of the budget. */
|
|
287
|
+
async function reviewInChunks(input, text, callers) {
|
|
288
|
+
const budget = MAX_DIFF_CHARS - callers.length;
|
|
289
|
+
const chunks = packChunks(splitSections(text), budget);
|
|
290
|
+
const overflow = chunks
|
|
291
|
+
.splice(MAX_REVIEW_CHUNKS)
|
|
292
|
+
.flatMap((c) => c.sections.map((s) => s.file));
|
|
293
|
+
if (overflow.length > 0) {
|
|
294
|
+
noteDegradation(
|
|
295
|
+
`review bounded at ${MAX_REVIEW_CHUNKS} chunks: ${overflow.length} ` +
|
|
296
|
+
`file(s) not reviewed: ${overflow.join(', ')}`,
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
const findings = [];
|
|
300
|
+
for (const chunk of chunks) {
|
|
301
|
+
const files = chunk.sections.map((s) => s.file).join(', ');
|
|
302
|
+
if (chunk.size > budget) {
|
|
303
|
+
noteDegradation(
|
|
304
|
+
`${files} truncated at ${budget} characters: ` +
|
|
305
|
+
`${chunk.size - budget} characters not reviewed`,
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
const prompt = buildPrompt(
|
|
309
|
+
input,
|
|
310
|
+
chunk.sections.map((s) => s.text).join(''),
|
|
311
|
+
callers,
|
|
312
|
+
budget,
|
|
313
|
+
);
|
|
314
|
+
const verdict = await reviewInTempDir(prompt, runDeps);
|
|
315
|
+
if ('reason' in verdict) {
|
|
316
|
+
noteDegradation(`no verdict for ${files}: ${verdict.reason}`);
|
|
317
|
+
} else {
|
|
318
|
+
findings.push(...verdict.findings);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return dedupeFindings(findings);
|
|
322
|
+
}
|
|
323
|
+
|
|
256
324
|
return {
|
|
257
325
|
async runReview(input) {
|
|
258
326
|
degradations = [];
|
|
@@ -260,8 +328,6 @@ export function createCodeReviewProviderForRegistry(deps = {}) {
|
|
|
260
328
|
const diff = readDiff(gitSpawnFn, input, PROJECT_ROOT);
|
|
261
329
|
if ('reason' in diff) return settle(diff);
|
|
262
330
|
if (diff.text.trim().length === 0) return [];
|
|
263
|
-
const truncation = truncationReason(diff.text);
|
|
264
|
-
if (truncation) noteDegradation(truncation);
|
|
265
331
|
const callers = buildCallersSection({
|
|
266
332
|
diff: diff.text,
|
|
267
333
|
input,
|
|
@@ -269,6 +335,9 @@ export function createCodeReviewProviderForRegistry(deps = {}) {
|
|
|
269
335
|
gitSpawnFn,
|
|
270
336
|
});
|
|
271
337
|
if (callers.reason) noteDegradation(callers.reason);
|
|
338
|
+
if (diff.text.length > MAX_DIFF_CHARS) {
|
|
339
|
+
return reviewInChunks(input, diff.text, callers.text);
|
|
340
|
+
}
|
|
272
341
|
return settle(
|
|
273
342
|
await reviewInTempDir(
|
|
274
343
|
buildPrompt(input, diff.text, callers.text),
|
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
* resolveConfigImpl?: typeof resolveConfig,
|
|
36
36
|
* progress: (tag: string, msg: string) => void,
|
|
37
37
|
* }} args
|
|
38
|
+
* @returns {Promise<{ changedPaths: string[], creditedCommit: string|null }>} The pre-sync head is the credited commit.
|
|
38
39
|
*/
|
|
39
40
|
export async function runBaseSyncPhase({
|
|
40
41
|
cwd,
|
|
@@ -89,6 +90,12 @@ export async function runBaseSyncPhase({
|
|
|
89
90
|
})) {
|
|
90
91
|
progress('SYNC', line);
|
|
91
92
|
}
|
|
93
|
+
return {
|
|
94
|
+
changedPaths: Array.isArray(syncResult.changedPaths)
|
|
95
|
+
? syncResult.changedPaths
|
|
96
|
+
: [],
|
|
97
|
+
creditedCommit: syncResult.preSyncHead ?? null,
|
|
98
|
+
};
|
|
92
99
|
}
|
|
93
100
|
|
|
94
101
|
/** A handed-back conflict re-runs close next (`closeNextCommand`). */
|
|
@@ -11,10 +11,12 @@
|
|
|
11
11
|
|
|
12
12
|
import {
|
|
13
13
|
createLockEventChannel as defaultCreateLockEventChannel,
|
|
14
|
+
sourcedTimings,
|
|
14
15
|
summarizeLockEvents,
|
|
15
16
|
} from '../../../close-lock-events.js';
|
|
16
17
|
import { buildDefaultGates as defaultBuildDefaultGates } from '../../../close-validation/gates.js';
|
|
17
18
|
import { runCloseValidation as defaultRunCloseValidation } from '../../../close-validation/runner.js';
|
|
19
|
+
import { applyTestDelta as defaultApplyTestDelta } from '../../../close-validation/test-delta.js';
|
|
18
20
|
import { LOCK_WAIT_EXPIRED_EXIT_CODE } from '../../../full-suite-lock.js';
|
|
19
21
|
import { createGateLogSink as defaultCreateGateLogSink } from '../gate-log.js';
|
|
20
22
|
import { runPreGateSteps as defaultRunPreGateSteps } from './pre-gate-steps.js';
|
|
@@ -31,9 +33,11 @@ import { runPreGateSteps as defaultRunPreGateSteps } from './pre-gate-steps.js';
|
|
|
31
33
|
* baseBranch: string,
|
|
32
34
|
* storyBranch?: string,
|
|
33
35
|
* storyId: number,
|
|
36
|
+
* baseSync?: { changedPaths: string[], creditedCommit: string|null }|null,
|
|
34
37
|
* progress: (tag: string, msg: string) => void,
|
|
35
38
|
* runCloseValidation?: typeof defaultRunCloseValidation,
|
|
36
39
|
* buildDefaultGates?: typeof defaultBuildDefaultGates,
|
|
40
|
+
* applyTestDelta?: typeof defaultApplyTestDelta,
|
|
37
41
|
* runPreGateSteps?: typeof defaultRunPreGateSteps,
|
|
38
42
|
* runScopedFormatAutofix?: Function,
|
|
39
43
|
* runBaselineUpwardWriteback?: Function,
|
|
@@ -45,7 +49,7 @@ import { runPreGateSteps as defaultRunPreGateSteps } from './pre-gate-steps.js';
|
|
|
45
49
|
* @returns {Promise<{
|
|
46
50
|
* gates: Record<string, 'passed'|'skipped'>|null,
|
|
47
51
|
* lockWait: { waitedSeconds: number, expired: boolean, holder?: object }|null,
|
|
48
|
-
* suiteTimings: { lockWaitMs: number, hostWaitMs: number|null, testRunMs: number }|null,
|
|
52
|
+
* suiteTimings: { lockWaitMs: number, hostWaitMs: number|null, testRunMs: number, source: 'close', spawns: object[] }|null,
|
|
49
53
|
* pending: boolean,
|
|
50
54
|
* }>} `pending` (with `gates: null`) when a lock wait expired; any other
|
|
51
55
|
* failure throws with `err.closeGate` naming the gate.
|
|
@@ -57,9 +61,11 @@ export async function runCloseValidationPhase({
|
|
|
57
61
|
baseBranch,
|
|
58
62
|
storyBranch,
|
|
59
63
|
storyId,
|
|
64
|
+
baseSync = null,
|
|
60
65
|
progress,
|
|
61
66
|
runCloseValidation = defaultRunCloseValidation,
|
|
62
67
|
buildDefaultGates = defaultBuildDefaultGates,
|
|
68
|
+
applyTestDelta = defaultApplyTestDelta,
|
|
63
69
|
runPreGateSteps = defaultRunPreGateSteps,
|
|
64
70
|
runScopedFormatAutofix,
|
|
65
71
|
runBaselineUpwardWriteback,
|
|
@@ -87,15 +93,20 @@ export async function runCloseValidationPhase({
|
|
|
87
93
|
// One sink for both `log` seams so nothing routes around the artifact.
|
|
88
94
|
const gateLog = createGateLogSink({ storyId, config });
|
|
89
95
|
const lockEvents = createLockEventChannel();
|
|
90
|
-
const
|
|
96
|
+
const gateOpts = {
|
|
91
97
|
config,
|
|
92
98
|
baseBranch,
|
|
93
99
|
cwd: worktreePath || cwd,
|
|
94
100
|
log: gateLog.log,
|
|
95
101
|
storyId,
|
|
96
102
|
evidenceCwd: cwd,
|
|
103
|
+
};
|
|
104
|
+
const gateList = applyTestDelta(buildDefaultGates(gateOpts), {
|
|
105
|
+
...gateOpts,
|
|
106
|
+
baseSync,
|
|
97
107
|
});
|
|
98
|
-
|
|
108
|
+
reportGateLabels(gateList, progress);
|
|
109
|
+
const { validation, lockWait, ...timings } = await runGateChain({
|
|
99
110
|
runCloseValidation,
|
|
100
111
|
gateLog,
|
|
101
112
|
lockEvents,
|
|
@@ -121,11 +132,18 @@ export async function runCloseValidationPhase({
|
|
|
121
132
|
return {
|
|
122
133
|
gates: gateOutcomes(gateList, validation),
|
|
123
134
|
lockWait,
|
|
124
|
-
suiteTimings,
|
|
135
|
+
suiteTimings: sourcedTimings(timings, 'close'),
|
|
125
136
|
pending: false,
|
|
126
137
|
};
|
|
127
138
|
}
|
|
128
139
|
|
|
140
|
+
/** A labelled gate (the `test` delta re-credit) names itself on the progress line. */
|
|
141
|
+
function reportGateLabels(gateList, progress) {
|
|
142
|
+
for (const gate of gateList) {
|
|
143
|
+
if (gate.label) progress('VALIDATE', gate.label);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
129
147
|
async function prepareTree({ runPreGateSteps, onPreGateStepsDone, stepArgs }) {
|
|
130
148
|
await runPreGateSteps(stepArgs);
|
|
131
149
|
onPreGateStepsDone?.();
|