mandrel 2.93.0 → 2.95.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 +8 -3
- package/.agents/runtime-deps.json +6 -6
- package/.agents/schemas/lifecycle/merge.unlanded.schema.json +2 -1
- package/.agents/schemas/story-deliver-terminal.schema.json +1 -0
- package/.agents/scripts/agents-bootstrap-github.js +1 -1
- package/.agents/scripts/board-backfill.js +1 -1
- package/.agents/scripts/boot-sweep.js +1 -1
- package/.agents/scripts/check-arch-cycles.js +69 -41
- package/.agents/scripts/check-doc-links.js +5 -7
- package/.agents/scripts/check-gherkin-corpus.js +2 -11
- package/.agents/scripts/clean-temp.js +1 -1
- package/.agents/scripts/cleanup-repo-test-temp.js +1 -1
- package/.agents/scripts/diagnose-friction.js +1 -1
- package/.agents/scripts/generate-lens-checklists.js +4 -4
- package/.agents/scripts/generate-skills-index.js +3 -2
- package/.agents/scripts/generate-workflows-doc.js +2 -1
- package/.agents/scripts/lib/audit-baselines/read.js +2 -1
- package/.agents/scripts/lib/audit-exceptions/adapters/tool-config.js +13 -3
- package/.agents/scripts/lib/audit-exceptions/globs.js +12 -1
- package/.agents/scripts/lib/audit-exceptions/probe.js +24 -2
- package/.agents/scripts/lib/audit-exceptions/read.js +2 -2
- package/.agents/scripts/lib/audit-to-stories/group-findings.js +77 -67
- package/.agents/scripts/lib/baselines/components.js +21 -19
- package/.agents/scripts/lib/baselines/duplication-scanner.js +4 -8
- package/.agents/scripts/lib/baselines/kinds/maintainability.js +2 -3
- package/.agents/scripts/lib/baselines/preview-gates.js +2 -2
- package/.agents/scripts/lib/baselines/refresh-service.js +4 -7
- package/.agents/scripts/lib/baselines/writer.js +2 -7
- package/.agents/scripts/lib/bdd-runner-detect.js +2 -2
- package/.agents/scripts/lib/bdd-step-index.js +3 -7
- package/.agents/scripts/lib/bootstrap/baseline-merge-driver.js +11 -7
- package/.agents/scripts/lib/bootstrap/install-ledger.js +19 -4
- package/.agents/scripts/lib/bootstrap/json-io.js +14 -0
- package/.agents/scripts/lib/bootstrap/project-bootstrap.js +20 -44
- package/.agents/scripts/lib/bootstrap/quality-bootstrap.js +38 -54
- package/.agents/scripts/lib/branch-name-guard.js +2 -3
- package/.agents/scripts/lib/claude/agents-projection.js +1 -12
- package/.agents/scripts/lib/codex/agents-projection.js +2 -5
- package/.agents/scripts/lib/codex/skills-projection.js +4 -12
- package/.agents/scripts/lib/config/defaults.js +2 -1
- package/.agents/scripts/lib/config/qa.js +4 -5
- package/.agents/scripts/lib/config-schema.js +1 -8
- package/.agents/scripts/lib/config-settings-schema.js +0 -3
- package/.agents/scripts/lib/coverage-baseline.js +2 -3
- package/.agents/scripts/lib/coverage-utils.js +2 -1
- package/.agents/scripts/lib/cpu-pool.js +0 -1
- package/.agents/scripts/lib/cyclomatic-scope.js +2 -1
- package/.agents/scripts/lib/doc-tiers.js +2 -1
- package/.agents/scripts/lib/duplicate-search.js +52 -18
- package/.agents/scripts/lib/feedback-loop/prior-feedback-fetcher.js +47 -20
- package/.agents/scripts/lib/gh-exec.js +115 -25
- package/.agents/scripts/lib/gh-pr-rest.js +371 -0
- package/.agents/scripts/lib/git/sync-from-base.js +1 -1
- package/.agents/scripts/lib/import-graph.js +13 -28
- package/.agents/scripts/lib/json-utils.js +11 -0
- package/.agents/scripts/lib/label-constants.js +7 -1
- package/.agents/scripts/lib/maintainability-utils.js +14 -22
- package/.agents/scripts/lib/observability/runtime-friction.js +37 -1
- package/.agents/scripts/lib/orchestration/board-graphql-latch.js +75 -0
- package/.agents/scripts/lib/orchestration/check-baselines/phases/parse-args.js +25 -1
- package/.agents/scripts/lib/orchestration/ci-rerun-guard.js +82 -41
- package/.agents/scripts/lib/orchestration/code-review.js +1 -6
- package/.agents/scripts/lib/orchestration/column-sync.js +23 -21
- package/.agents/scripts/lib/orchestration/deliver-recover.js +2 -1
- package/.agents/scripts/lib/orchestration/git-cleanup/phases/fast-forward.js +7 -14
- package/.agents/scripts/lib/orchestration/git-cleanup/phases/git-probes-ff.js +2 -21
- package/.agents/scripts/lib/orchestration/git-cleanup/phases/git-probes.js +11 -20
- package/.agents/scripts/lib/orchestration/git-cleanup/phases/phase-drivers.js +65 -86
- package/.agents/scripts/lib/orchestration/git-cleanup/phases/prompts.js +2 -2
- package/.agents/scripts/lib/orchestration/git-cleanup/phases/stashes.js +15 -6
- package/.agents/scripts/lib/orchestration/lifecycle/emit-merge-unlanded.js +5 -2
- package/.agents/scripts/lib/orchestration/merge-block-class.js +48 -47
- package/.agents/scripts/lib/orchestration/merge-queue.js +49 -4
- package/.agents/scripts/lib/orchestration/plan-persist/run-plan-persist.js +20 -1
- package/.agents/scripts/lib/orchestration/project-meta-resolver.js +2 -2
- package/.agents/scripts/lib/orchestration/required-checks.js +72 -12
- package/.agents/scripts/lib/orchestration/review-providers/claude-verdict.js +2 -3
- package/.agents/scripts/lib/orchestration/review-providers/parse-findings.js +4 -2
- package/.agents/scripts/lib/orchestration/single-story-close/phases/auto-merge.js +132 -58
- package/.agents/scripts/lib/orchestration/single-story-close/phases/confirm-merge.js +92 -9
- package/.agents/scripts/lib/orchestration/single-story-close/phases/graphql-preflight.js +41 -18
- package/.agents/scripts/lib/orchestration/story-close/baseline-upward-writeback.js +2 -2
- package/.agents/scripts/lib/orchestration/story-close/ratchet-shrink-writeback.js +3 -3
- package/.agents/scripts/lib/orchestration/story-handoff.js +18 -5
- package/.agents/scripts/lib/orchestration/ticketing/transition.js +18 -22
- package/.agents/scripts/lib/runtime-deps/dep-resolution.js +19 -5
- package/.agents/scripts/lib/runtime-deps/scan-imports.js +4 -10
- package/.agents/scripts/lib/skills/parse-skill.js +2 -2
- package/.agents/scripts/lib/skills/walk-skill-files.js +7 -23
- package/.agents/scripts/lib/story-body/story-body.js +4 -14
- package/.agents/scripts/lib/util/atomic-write.js +14 -3
- package/.agents/scripts/lib/util/regex.js +4 -0
- package/.agents/scripts/notify.js +1 -1
- package/.agents/scripts/plan-context.js +1 -1
- package/.agents/scripts/plan-critics.js +3 -11
- package/.agents/scripts/providers/github/auth.js +0 -4
- package/.agents/scripts/providers/github/board-add.js +3 -3
- package/.agents/scripts/providers/github/compose.js +2 -0
- package/.agents/scripts/providers/github/errors.js +41 -0
- package/.agents/scripts/providers/github/project-board.js +0 -1
- package/.agents/scripts/providers/github/sub-issues-rest.js +55 -0
- package/.agents/scripts/providers/github/sub-issues.js +9 -1
- package/.agents/scripts/providers/github/tickets.js +0 -2
- package/.agents/scripts/resync-status-column.js +1 -1
- package/.agents/scripts/run-tests.js +1 -1
- package/.agents/scripts/single-story-confirm-merge.js +2 -0
- package/.agents/scripts/test-wrapper.js +1 -1
- package/.agents/scripts/update-ticket-state.js +4 -3
- package/.agents/scripts/validate-skills.js +2 -1
- package/.agents/skills/core/gates-and-baselines/reference.md +1 -0
- package/.agents/workflows/audit-baselines.md +21 -9
- package/.agents/workflows/clean-git.md +1 -1
- package/.agents/workflows/helpers/audit-lens-core.md +1 -1
- package/.agents/workflows/helpers/code-quality-guardrails.md +3 -3
- package/README.md +1 -1
- package/docs/CHANGELOG.md +46 -0
- package/lib/cli/claude-code-version.js +13 -7
- package/lib/cli/doctor-checks/llm-review.js +12 -5
- package/lib/cli/doctor-checks/merge-driver.js +10 -6
- package/lib/cli/doctor-checks/project-access.js +21 -8
- package/lib/cli/doctor-checks/read-json.js +2 -15
- package/lib/cli/doctor-checks/spawn.js +29 -9
- package/lib/cli/doctor-checks/test-credit-path.js +2 -1
- package/lib/cli/doctor-checks/toolchain.js +16 -12
- package/lib/cli/doctor.js +31 -8
- package/lib/cli/registry.js +7 -10
- package/lib/cli/sync.js +46 -10
- package/lib/cli/uninstall.js +259 -175
- package/lib/cli/update.js +3 -3
- package/package.json +23 -20
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import fs from 'node:fs';
|
|
10
10
|
import path from 'node:path';
|
|
11
|
+
import { toPosix, walkFiles } from './util/paths.js';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* The npm-published roots, resolved into one graph so cross-root cycles show.
|
|
@@ -21,26 +22,11 @@ export const DEFAULT_ROOTS = [path.join('.agents', 'scripts'), 'bin', 'lib'];
|
|
|
21
22
|
* @returns {string[]} absolute paths, sorted
|
|
22
23
|
*/
|
|
23
24
|
export function collectJsFiles(rootDir) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
} catch {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
for (const entry of entries) {
|
|
33
|
-
if (entry.name === 'node_modules') continue;
|
|
34
|
-
const full = path.join(dir, entry.name);
|
|
35
|
-
if (entry.isDirectory()) {
|
|
36
|
-
walk(full);
|
|
37
|
-
} else if (entry.isFile() && entry.name.endsWith('.js')) {
|
|
38
|
-
out.push(full);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
walk(rootDir);
|
|
43
|
-
return out.sort();
|
|
25
|
+
return walkFiles(rootDir, {
|
|
26
|
+
skipDirs: ['node_modules'],
|
|
27
|
+
filter: (abs, dirent) => dirent.isFile() && abs.endsWith('.js'),
|
|
28
|
+
onError: () => {},
|
|
29
|
+
}).sort();
|
|
44
30
|
}
|
|
45
31
|
|
|
46
32
|
const IMPORT_RE = /from\s+['"](\.\.?\/[^'"]+\.js)['"]/g;
|
|
@@ -67,11 +53,11 @@ export function parseRelativeImports(source) {
|
|
|
67
53
|
*/
|
|
68
54
|
export function buildGraph(files, rootDir, { readFile } = {}) {
|
|
69
55
|
const read = readFile ?? ((p) => fs.readFileSync(p, 'utf-8'));
|
|
70
|
-
const
|
|
71
|
-
const idSet = new Set(
|
|
56
|
+
const ids = files.map((file) => toPosix(path.relative(rootDir, file)));
|
|
57
|
+
const idSet = new Set(ids);
|
|
72
58
|
const graph = new Map();
|
|
73
|
-
for (const file of files) {
|
|
74
|
-
const id =
|
|
59
|
+
for (const [i, file] of files.entries()) {
|
|
60
|
+
const id = ids[i];
|
|
75
61
|
let source;
|
|
76
62
|
try {
|
|
77
63
|
source = read(file);
|
|
@@ -81,10 +67,9 @@ export function buildGraph(files, rootDir, { readFile } = {}) {
|
|
|
81
67
|
}
|
|
82
68
|
const edges = [];
|
|
83
69
|
for (const spec of parseRelativeImports(source)) {
|
|
84
|
-
const target =
|
|
85
|
-
.relative(rootDir, path.resolve(path.dirname(file), spec))
|
|
86
|
-
|
|
87
|
-
.join('/');
|
|
70
|
+
const target = toPosix(
|
|
71
|
+
path.relative(rootDir, path.resolve(path.dirname(file), spec)),
|
|
72
|
+
);
|
|
88
73
|
if (idSet.has(target) && target !== id) edges.push(target);
|
|
89
74
|
}
|
|
90
75
|
graph.set(id, [...new Set(edges)].sort());
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* Sets, RegExps or class instances).
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* @param {unknown} v
|
|
8
10
|
* @returns {boolean}
|
|
@@ -42,3 +44,12 @@ export function deepEqual(a, b) {
|
|
|
42
44
|
}
|
|
43
45
|
return true;
|
|
44
46
|
}
|
|
47
|
+
|
|
48
|
+
/** Missing or unparsable → `null`; never throws. */
|
|
49
|
+
export function readJsonOrNull(file, fsImpl = fs) {
|
|
50
|
+
try {
|
|
51
|
+
return JSON.parse(fsImpl.readFileSync(file, 'utf8'));
|
|
52
|
+
} catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -17,7 +17,13 @@ export const AGENT_LABELS = {
|
|
|
17
17
|
export const VALID_TRANSITIONS = {
|
|
18
18
|
'agent::review-spec': ['agent::ready', 'agent::blocked'],
|
|
19
19
|
'agent::ready': ['agent::executing', 'agent::blocked'],
|
|
20
|
-
|
|
20
|
+
// `ready`: init's claim rollback after a provisioning failure.
|
|
21
|
+
'agent::executing': [
|
|
22
|
+
'agent::ready',
|
|
23
|
+
'agent::closing',
|
|
24
|
+
'agent::done',
|
|
25
|
+
'agent::blocked',
|
|
26
|
+
],
|
|
21
27
|
'agent::closing': ['agent::done', 'agent::blocked'],
|
|
22
28
|
'agent::blocked': [
|
|
23
29
|
'agent::ready',
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
1
|
import path from 'node:path';
|
|
3
2
|
import picomatch from 'picomatch';
|
|
4
3
|
import { canonicalise as canonicalisePath } from './baselines/path-canon.js';
|
|
@@ -8,6 +7,7 @@ import { scoreFile } from './maintainability-engine.js';
|
|
|
8
7
|
import { isScored, reportUnscorable } from './maintainability-unscorable.js';
|
|
9
8
|
import { isScorableSourceFile } from './source-extensions.js';
|
|
10
9
|
import { CompilerMissingError } from './transpile.js';
|
|
10
|
+
import { walkFiles } from './util/paths.js';
|
|
11
11
|
|
|
12
12
|
const MAINTAINABILITY_WORKER_URL = new URL(
|
|
13
13
|
'./workers/maintainability-worker.js',
|
|
@@ -110,6 +110,10 @@ export function isIgnoredByGlobs(filePath, ignoreGlobs = [], cwd) {
|
|
|
110
110
|
);
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
function skipVanishedDir(err) {
|
|
114
|
+
if (err?.code !== 'ENOENT') throw err;
|
|
115
|
+
}
|
|
116
|
+
|
|
113
117
|
/**
|
|
114
118
|
* Recursively collect scorable source files, using the shared extension set
|
|
115
119
|
* so the walk, coverage freshness and CRAP projection cannot drift apart.
|
|
@@ -122,27 +126,15 @@ export function isIgnoredByGlobs(filePath, ignoreGlobs = [], cwd) {
|
|
|
122
126
|
export function scanDirectory(dir, fileList = [], opts = {}) {
|
|
123
127
|
const { ignoreGlobs = [], cwd: optsCwd } = opts;
|
|
124
128
|
const matchCwd = optsCwd ?? process.cwd();
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
for (const
|
|
134
|
-
const filePath = path.join(dir, entry.name);
|
|
135
|
-
if (entry.isDirectory()) {
|
|
136
|
-
if (!IGNORED_DIRS.has(entry.name)) {
|
|
137
|
-
scanDirectory(filePath, fileList, opts);
|
|
138
|
-
}
|
|
139
|
-
} else if (entry.isFile() && isScorableSourceFile(entry.name)) {
|
|
140
|
-
if (isIgnoredByGlobs(filePath, ignoreGlobs, matchCwd)) {
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
fileList.push(filePath);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
129
|
+
const found = walkFiles(dir, {
|
|
130
|
+
skipDirs: IGNORED_DIRS,
|
|
131
|
+
filter: (abs, dirent) =>
|
|
132
|
+
dirent.isFile() &&
|
|
133
|
+
isScorableSourceFile(dirent.name) &&
|
|
134
|
+
!isIgnoredByGlobs(abs, ignoreGlobs, matchCwd),
|
|
135
|
+
onError: skipVanishedDir,
|
|
136
|
+
});
|
|
137
|
+
for (const file of found) fileList.push(file);
|
|
146
138
|
return fileList;
|
|
147
139
|
}
|
|
148
140
|
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import crypto from 'node:crypto';
|
|
11
|
-
|
|
12
11
|
import { Logger } from '../Logger.js';
|
|
12
|
+
import { isValidTransition, VALID_TRANSITIONS } from '../label-constants.js';
|
|
13
13
|
import { appendSignal, forEachLine } from './signals-writer.js';
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -27,6 +27,8 @@ export const RUNTIME_FRICTION_CATEGORIES = Object.freeze({
|
|
|
27
27
|
REVIEW_BLOCKED: 'review-blocked',
|
|
28
28
|
/** A human shipped over a review blocker; a rising count means miscalibration. */
|
|
29
29
|
REVIEW_BLOCK_OVERRIDDEN: 'review-block-overridden',
|
|
30
|
+
/** An `agent::*` flip outside `VALID_TRANSITIONS`; observed, never refused. */
|
|
31
|
+
INVALID_AGENT_TRANSITION: 'invalid-agent-transition',
|
|
30
32
|
});
|
|
31
33
|
|
|
32
34
|
/**
|
|
@@ -153,6 +155,40 @@ export async function emitBlockRecoveredFriction({
|
|
|
153
155
|
});
|
|
154
156
|
}
|
|
155
157
|
|
|
158
|
+
/**
|
|
159
|
+
* Record an `agent::*` flip outside `VALID_TRANSITIONS` — observe-only, the
|
|
160
|
+
* label write already happened, and this never throws. A self-transition is
|
|
161
|
+
* an idempotent re-apply (resume, `--steal`, a rollback whose flip never
|
|
162
|
+
* landed), not a fault. `allowed` names the targets the table admits.
|
|
163
|
+
*
|
|
164
|
+
* @param {number} storyId
|
|
165
|
+
* @param {string|null} fromState Prior state label, or null.
|
|
166
|
+
* @param {string} toState
|
|
167
|
+
* @param {{ config?: object }} [opts]
|
|
168
|
+
* @returns {Promise<boolean>} true when a record was appended.
|
|
169
|
+
*/
|
|
170
|
+
export async function emitInvalidTransitionFriction(
|
|
171
|
+
storyId,
|
|
172
|
+
fromState,
|
|
173
|
+
toState,
|
|
174
|
+
opts,
|
|
175
|
+
) {
|
|
176
|
+
if (fromState === toState || isValidTransition(fromState, toState)) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
return emitRuntimeFriction({
|
|
180
|
+
storyId,
|
|
181
|
+
category: RUNTIME_FRICTION_CATEGORIES.INVALID_AGENT_TRANSITION,
|
|
182
|
+
tool: 'transitionTicketState',
|
|
183
|
+
details: {
|
|
184
|
+
fromState,
|
|
185
|
+
toState,
|
|
186
|
+
allowed: VALID_TRANSITIONS[fromState] ?? [],
|
|
187
|
+
},
|
|
188
|
+
config: opts?.config,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
156
192
|
/**
|
|
157
193
|
* On land, emit a `recovered: true` marker in `category` so the retro nets
|
|
158
194
|
* the `(category, storyId)` incident out. Hung off `runPostLandTail` because
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* board-graphql-latch — a cloud session's proxy refuses GraphQL, and
|
|
3
|
+
* Projects v2 is GraphQL-only, so board seams report `graphql-blocked` and
|
|
4
|
+
* warn once per process. Wraps `board-access-latch.js`.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { isGraphqlBlocked } from '../../providers/github/errors.js';
|
|
8
|
+
import { Logger } from '../Logger.js';
|
|
9
|
+
import {
|
|
10
|
+
boardScopeFailure,
|
|
11
|
+
isProjectAccessFailure,
|
|
12
|
+
reportBoardScopeFailure,
|
|
13
|
+
SCOPE_FAILURE,
|
|
14
|
+
} from './board-access-latch.js';
|
|
15
|
+
|
|
16
|
+
const GRAPHQL_BLOCKED_FAILURE = Object.freeze({
|
|
17
|
+
reason: 'graphql-blocked',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const REMEDY =
|
|
21
|
+
'GitHub Projects v2 board updates are skipped: this session refuses GitHub GraphQL (Claude Code cloud proxy), and Projects v2 is GraphQL-only, so board adds and Status flips cannot sync from a cloud session (labels still move). Run `node .agents/scripts/board-backfill.js` from a local session to catch the board up.';
|
|
22
|
+
|
|
23
|
+
const warnedSinks = new WeakSet();
|
|
24
|
+
|
|
25
|
+
function reportBoardGraphqlBlocked({ logger = Logger } = {}) {
|
|
26
|
+
if (warnedSinks.has(logger)) return false;
|
|
27
|
+
warnedSinks.add(logger);
|
|
28
|
+
logger.warn?.(REMEDY);
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param {unknown} err
|
|
34
|
+
* @returns {boolean}
|
|
35
|
+
*/
|
|
36
|
+
export function isBoardAccessFailure(err) {
|
|
37
|
+
return isGraphqlBlocked(err) || isProjectAccessFailure(err);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {unknown} err
|
|
42
|
+
* @returns {'graphql-blocked' | 'insufficient-scope' | null}
|
|
43
|
+
*/
|
|
44
|
+
export function boardAccessFailureReason(err) {
|
|
45
|
+
if (isGraphqlBlocked(err)) return GRAPHQL_BLOCKED_FAILURE.reason;
|
|
46
|
+
return isProjectAccessFailure(err) ? SCOPE_FAILURE.reason : null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The Status-sync outcome for `reason`: a blocked session skips, a scope
|
|
51
|
+
* refusal fails.
|
|
52
|
+
*
|
|
53
|
+
* @param {'graphql-blocked' | 'insufficient-scope'} reason
|
|
54
|
+
* @param {{ logger?: { warn?: Function } }} [opts]
|
|
55
|
+
* @returns {{ status: string, reason: string, scope?: string }}
|
|
56
|
+
*/
|
|
57
|
+
export function reportBoardAccessFailure(reason, { logger } = {}) {
|
|
58
|
+
if (reason === GRAPHQL_BLOCKED_FAILURE.reason) {
|
|
59
|
+
reportBoardGraphqlBlocked({ logger });
|
|
60
|
+
return { status: 'skipped', ...GRAPHQL_BLOCKED_FAILURE };
|
|
61
|
+
}
|
|
62
|
+
reportBoardScopeFailure({ logger });
|
|
63
|
+
return { status: 'failed', ...SCOPE_FAILURE };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @param {unknown} err
|
|
68
|
+
* @param {{ logger?: { warn?: Function } }} [opts]
|
|
69
|
+
* @returns {{ reason: string, scope?: string } | null}
|
|
70
|
+
*/
|
|
71
|
+
export function boardAccessFailure(err, { logger } = {}) {
|
|
72
|
+
if (!isGraphqlBlocked(err)) return boardScopeFailure(err, { logger });
|
|
73
|
+
reportBoardGraphqlBlocked({ logger });
|
|
74
|
+
return GRAPHQL_BLOCKED_FAILURE;
|
|
75
|
+
}
|
|
@@ -82,6 +82,28 @@ function flattenGateTokens(raw) {
|
|
|
82
82
|
return parts.length === 0 ? null : parts;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
/** Out-of-band ratchet kinds this dispatcher never evaluates, and their checkers. */
|
|
86
|
+
const RATCHET_CHECKERS = Object.freeze({
|
|
87
|
+
'arch-cycles': 'check-arch-cycles.js',
|
|
88
|
+
'context-budget': 'check-context-budget.js',
|
|
89
|
+
cyclomatic: 'check-cyclomatic.js',
|
|
90
|
+
'dead-exports': 'check-dead-exports.js',
|
|
91
|
+
'dead-exports-production': 'check-dead-exports.js --production',
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
/** Reject a mistyped kind rather than silently evaluating nothing. */
|
|
95
|
+
function assertKnownKinds(gates) {
|
|
96
|
+
const unknown = (gates ?? []).filter((k) => !KNOWN_KINDS.includes(k));
|
|
97
|
+
if (unknown.length === 0) return;
|
|
98
|
+
const checkers = Object.entries(RATCHET_CHECKERS)
|
|
99
|
+
.map(([kind, cmd]) => `${kind} (node .agents/scripts/${cmd})`)
|
|
100
|
+
.join(', ');
|
|
101
|
+
throw new Error(
|
|
102
|
+
`unknown --gate kind "${unknown.join(', ')}"; valid kinds: ${KNOWN_KINDS.join(', ')}. ` +
|
|
103
|
+
`Ratchet kinds run via their own checker: ${checkers}.`,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
85
107
|
/**
|
|
86
108
|
* @param {string[]} argv process.argv.slice(2)
|
|
87
109
|
* @returns {{
|
|
@@ -125,9 +147,11 @@ export function parseArgs(argv) {
|
|
|
125
147
|
}
|
|
126
148
|
|
|
127
149
|
const { values } = parsed;
|
|
150
|
+
const gates = flattenGateTokens(values.gate);
|
|
151
|
+
assertKnownKinds(gates);
|
|
128
152
|
const out = {
|
|
129
153
|
configPath: values.configPath ?? null,
|
|
130
|
-
gates
|
|
154
|
+
gates,
|
|
131
155
|
format: values.format ?? 'json',
|
|
132
156
|
friction: !values.noFriction,
|
|
133
157
|
storyId: values.storyId,
|
|
@@ -13,18 +13,13 @@
|
|
|
13
13
|
* dies with the digest). A missing SHA on either side fails closed.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import {
|
|
17
|
-
existsSync,
|
|
18
|
-
mkdirSync,
|
|
19
|
-
readFileSync,
|
|
20
|
-
rmSync,
|
|
21
|
-
writeFileSync,
|
|
22
|
-
} from 'node:fs';
|
|
16
|
+
import { existsSync, readFileSync, rmSync } from 'node:fs';
|
|
23
17
|
import path from 'node:path';
|
|
24
18
|
import { resolveConfig } from '../config-resolver.js';
|
|
25
|
-
import { runGh } from '../gh-exec.js';
|
|
19
|
+
import { prSurfaceUsesRest, runGh } from '../gh-exec.js';
|
|
26
20
|
import { Logger } from '../Logger.js';
|
|
27
21
|
import { createProvider } from '../provider-factory.js';
|
|
22
|
+
import { writeFileAtomic } from '../util/atomic-write.js';
|
|
28
23
|
import { isRerunPermitted } from './check-state.js';
|
|
29
24
|
import {
|
|
30
25
|
STATE_LABELS,
|
|
@@ -108,6 +103,65 @@ function ghRunLogTail({ runId, cwd, spawnFn, maxLines = 40 }) {
|
|
|
108
103
|
return lines.slice(-maxLines).join('\n');
|
|
109
104
|
}
|
|
110
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Parsed JSON stdout of a `gh` run, or `null` on an unparseable one — or a
|
|
108
|
+
* failed one, unless `anyExit` (`gh pr checks` exits non-zero on a red or
|
|
109
|
+
* pending check and still prints the rows).
|
|
110
|
+
*/
|
|
111
|
+
function readGhJson(args, { cwd, spawnFn, anyExit = false }) {
|
|
112
|
+
const result = runGh(args, { cwd }, spawnFn);
|
|
113
|
+
if (!anyExit && (result?.status ?? 1) !== 0) return null;
|
|
114
|
+
try {
|
|
115
|
+
return JSON.parse((result.stdout ?? '').trim() || 'null');
|
|
116
|
+
} catch {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** The PR number in a number, numeric string, or PR URL; `null` otherwise. */
|
|
122
|
+
function prNumberOfRef(prRef) {
|
|
123
|
+
const match = /^(\d+)$|\/pull\/(\d+)/.exec(String(prRef ?? ''));
|
|
124
|
+
return match ? (match[1] ?? match[2]) : null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The head SHA over the REST transport (GraphQL answers 403 there, and
|
|
129
|
+
* `gh pr view` needs it).
|
|
130
|
+
*
|
|
131
|
+
* @returns {string|null}
|
|
132
|
+
*/
|
|
133
|
+
function resolvePrHeadShaRest({ prRef, cwd, spawnFn }) {
|
|
134
|
+
const n = prNumberOfRef(prRef);
|
|
135
|
+
if (!n) return null;
|
|
136
|
+
const pull = readGhJson(['api', `repos/{owner}/{repo}/pulls/${n}`], {
|
|
137
|
+
cwd,
|
|
138
|
+
spawnFn,
|
|
139
|
+
});
|
|
140
|
+
const sha = pull?.head?.sha;
|
|
141
|
+
return typeof sha === 'string' && sha.length > 0 ? sha : null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** `[{ name, link }]` for the PR head's check runs, as `gh pr checks --json` gives it. */
|
|
145
|
+
function readCheckLinks({ prRef, cwd, spawnFn }) {
|
|
146
|
+
if (!prSurfaceUsesRest()) {
|
|
147
|
+
return readGhJson(['pr', 'checks', prRef, '--json', 'name,link'], {
|
|
148
|
+
cwd,
|
|
149
|
+
spawnFn,
|
|
150
|
+
anyExit: true,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
const sha = resolvePrHeadShaRest({ prRef, cwd, spawnFn });
|
|
154
|
+
if (!sha) return null;
|
|
155
|
+
const runs = readGhJson(
|
|
156
|
+
['api', `repos/{owner}/{repo}/commits/${sha}/check-runs?per_page=100`],
|
|
157
|
+
{ cwd, spawnFn },
|
|
158
|
+
);
|
|
159
|
+
return (runs?.check_runs ?? []).map((run) => ({
|
|
160
|
+
name: run?.name,
|
|
161
|
+
link: run?.details_url ?? run?.html_url ?? null,
|
|
162
|
+
}));
|
|
163
|
+
}
|
|
164
|
+
|
|
111
165
|
/**
|
|
112
166
|
* The failing check's run id and URL (the intake filing needs the link).
|
|
113
167
|
* Best-effort.
|
|
@@ -115,22 +169,13 @@ function ghRunLogTail({ runId, cwd, spawnFn, maxLines = 40 }) {
|
|
|
115
169
|
* @returns {{ runId: string|null, url: string|null }}
|
|
116
170
|
*/
|
|
117
171
|
function resolveFailingCheckRun({ prRef, checkName, cwd, spawnFn }) {
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const entry = Array.isArray(parsed)
|
|
126
|
-
? parsed.find((e) => e?.name === checkName)
|
|
127
|
-
: null;
|
|
128
|
-
const link = entry?.link ? String(entry.link) : null;
|
|
129
|
-
const m = link ? /\/runs\/(\d+)/.exec(link) : null;
|
|
130
|
-
return { runId: m ? m[1] : null, url: link };
|
|
131
|
-
} catch {
|
|
132
|
-
return { runId: null, url: null };
|
|
133
|
-
}
|
|
172
|
+
const parsed = readCheckLinks({ prRef, cwd, spawnFn });
|
|
173
|
+
const entry = Array.isArray(parsed)
|
|
174
|
+
? parsed.find((e) => e?.name === checkName)
|
|
175
|
+
: null;
|
|
176
|
+
const link = entry?.link ? String(entry.link) : null;
|
|
177
|
+
const m = link ? /\/runs\/(\d+)/.exec(link) : null;
|
|
178
|
+
return { runId: m ? m[1] : null, url: link };
|
|
134
179
|
}
|
|
135
180
|
|
|
136
181
|
/**
|
|
@@ -141,19 +186,13 @@ function resolveFailingCheckRun({ prRef, checkName, cwd, spawnFn }) {
|
|
|
141
186
|
* @returns {string|null}
|
|
142
187
|
*/
|
|
143
188
|
export function resolvePrHeadSha({ prRef, cwd, spawnFn }) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
189
|
+
if (prSurfaceUsesRest()) return resolvePrHeadShaRest({ prRef, cwd, spawnFn });
|
|
190
|
+
const parsed = readGhJson(['pr', 'view', prRef, '--json', 'headRefOid'], {
|
|
191
|
+
cwd,
|
|
147
192
|
spawnFn,
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const parsed = JSON.parse((result.stdout ?? '').trim() || '{}');
|
|
152
|
-
const sha = parsed?.headRefOid;
|
|
153
|
-
return typeof sha === 'string' && sha.length > 0 ? sha : null;
|
|
154
|
-
} catch {
|
|
155
|
-
return null;
|
|
156
|
-
}
|
|
193
|
+
});
|
|
194
|
+
const sha = parsed?.headRefOid;
|
|
195
|
+
return typeof sha === 'string' && sha.length > 0 ? sha : null;
|
|
157
196
|
}
|
|
158
197
|
|
|
159
198
|
/**
|
|
@@ -169,7 +208,10 @@ export function readCiDigest({ storyId = null, tempRoot, cwd }) {
|
|
|
169
208
|
try {
|
|
170
209
|
const parsed = JSON.parse(readFileSync(paths.jsonPath, 'utf8'));
|
|
171
210
|
return parsed && typeof parsed === 'object' ? parsed : null;
|
|
172
|
-
} catch {
|
|
211
|
+
} catch (err) {
|
|
212
|
+
Logger.warn(
|
|
213
|
+
`ignoring unreadable CI digest ${paths.jsonPath} (${err.message}) — treated as absent`,
|
|
214
|
+
);
|
|
173
215
|
return null;
|
|
174
216
|
}
|
|
175
217
|
}
|
|
@@ -307,9 +349,8 @@ export function writeCiDigest({
|
|
|
307
349
|
logTail,
|
|
308
350
|
generatedAt: new Date().toISOString(),
|
|
309
351
|
};
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
writeFileSync(paths.mdPath, renderDigestMarkdown(digest, failures));
|
|
352
|
+
writeFileAtomic(paths.jsonPath, `${JSON.stringify(digest, null, 2)}\n`);
|
|
353
|
+
writeFileAtomic(paths.mdPath, renderDigestMarkdown(digest, failures));
|
|
313
354
|
return { jsonPath: paths.jsonPath, mdPath: paths.mdPath };
|
|
314
355
|
}
|
|
315
356
|
|
|
@@ -344,7 +385,7 @@ export function recordRerunAllowance({
|
|
|
344
385
|
recordedAt: now().toISOString(),
|
|
345
386
|
};
|
|
346
387
|
try {
|
|
347
|
-
|
|
388
|
+
writeFileAtomic(
|
|
348
389
|
paths.jsonPath,
|
|
349
390
|
`${JSON.stringify({ ...digest, rerunAllowance: allowance }, null, 2)}\n`,
|
|
350
391
|
);
|
|
@@ -76,11 +76,6 @@ function resolveStoryScope(opts, config) {
|
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
/** `'story'` is the only scope. */
|
|
80
|
-
function resolveScopeEnvelope(opts, config) {
|
|
81
|
-
return resolveStoryScope(opts, config);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
79
|
/**
|
|
85
80
|
* Run a Story-scope review. `headRef` is required; `baseRef` defaults to
|
|
86
81
|
* the remote base branch; `commentTargetId` (e.g. a PR number) overrides
|
|
@@ -349,7 +344,7 @@ export async function runCodeReview(opts = {}) {
|
|
|
349
344
|
const { resolveConfigFn = resolveConfig } = opts;
|
|
350
345
|
|
|
351
346
|
const config = resolveConfigFn();
|
|
352
|
-
const envelope =
|
|
347
|
+
const envelope = resolveStoryScope(opts, config);
|
|
353
348
|
|
|
354
349
|
return executeReviewPipeline({ opts, config, envelope });
|
|
355
350
|
}
|
|
@@ -4,15 +4,16 @@
|
|
|
4
4
|
* GraphQL. Soft no-op when no project is configured, the Status field or
|
|
5
5
|
* option is missing, or the issue is not on the board. A token that cannot
|
|
6
6
|
* reach the board (missing `project` scope) reports `{ status: 'failed',
|
|
7
|
-
* reason: 'insufficient-scope' }`
|
|
7
|
+
* reason: 'insufficient-scope' }` (a GraphQL-blocked session: `skipped` /
|
|
8
|
+
* `graphql-blocked`) and trips a warn-once latch instead.
|
|
8
9
|
*/
|
|
9
10
|
|
|
10
11
|
import { AGENT_LABELS } from '../label-constants.js';
|
|
11
12
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} from './board-
|
|
13
|
+
boardAccessFailureReason,
|
|
14
|
+
isBoardAccessFailure,
|
|
15
|
+
reportBoardAccessFailure,
|
|
16
|
+
} from './board-graphql-latch.js';
|
|
16
17
|
import {
|
|
17
18
|
invalidateProjectMetaCache,
|
|
18
19
|
readProjectMetaCache,
|
|
@@ -128,8 +129,8 @@ export class ColumnSync {
|
|
|
128
129
|
this._meta = null; // lazy-cached { projectId, fieldId, options: Map<name, id> }
|
|
129
130
|
// Disk-hydrated meta may be stale; a failed mutation then invalidates it.
|
|
130
131
|
this._metaFromDiskCache = false;
|
|
131
|
-
//
|
|
132
|
-
this.
|
|
132
|
+
// Access-failure reason seen this process; memory only, never on disk.
|
|
133
|
+
this._accessFailure = null;
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
/**
|
|
@@ -157,8 +158,8 @@ export class ColumnSync {
|
|
|
157
158
|
try {
|
|
158
159
|
return await this.#setColumnOnBoard(issueId, column);
|
|
159
160
|
} catch (err) {
|
|
160
|
-
if (!
|
|
161
|
-
return this.#
|
|
161
|
+
if (!isBoardAccessFailure(err)) throw err;
|
|
162
|
+
return this.#accessFailure(err);
|
|
162
163
|
}
|
|
163
164
|
}
|
|
164
165
|
|
|
@@ -184,26 +185,27 @@ export class ColumnSync {
|
|
|
184
185
|
// Likely a reconfigured board: drop cached meta so the next flip
|
|
185
186
|
// self-heals, and re-throw for the caller's handling. A scope refusal
|
|
186
187
|
// is not staleness, so the cache stays.
|
|
187
|
-
if (!
|
|
188
|
+
if (!isBoardAccessFailure(err)) this.#invalidateMetaCache();
|
|
188
189
|
throw err;
|
|
189
190
|
}
|
|
190
191
|
return { status: 'synced', column };
|
|
191
192
|
}
|
|
192
193
|
|
|
193
|
-
/** No meta: a latched
|
|
194
|
+
/** No meta: a latched access refusal, or a board without a Status field. */
|
|
194
195
|
#metaMiss() {
|
|
195
|
-
if (this.
|
|
196
|
+
if (this._accessFailure) return this.#accessFailure();
|
|
196
197
|
return { status: 'skipped', reason: 'no-meta' };
|
|
197
198
|
}
|
|
198
199
|
|
|
199
200
|
/**
|
|
200
|
-
* Latch the
|
|
201
|
-
*
|
|
201
|
+
* Latch the access failure (first reason holds) and report it; never
|
|
202
|
+
* throws, so the label transition still completes.
|
|
202
203
|
*/
|
|
203
|
-
#
|
|
204
|
-
this.
|
|
205
|
-
|
|
206
|
-
|
|
204
|
+
#accessFailure(err) {
|
|
205
|
+
this._accessFailure ??= boardAccessFailureReason(err);
|
|
206
|
+
return reportBoardAccessFailure(this._accessFailure, {
|
|
207
|
+
logger: this.logger,
|
|
208
|
+
});
|
|
207
209
|
}
|
|
208
210
|
|
|
209
211
|
/**
|
|
@@ -231,7 +233,7 @@ export class ColumnSync {
|
|
|
231
233
|
}
|
|
232
234
|
|
|
233
235
|
async #loadMeta() {
|
|
234
|
-
if (this.
|
|
236
|
+
if (this._accessFailure) return null;
|
|
235
237
|
if (this._meta !== null) return this._meta || null;
|
|
236
238
|
// Board meta is repo-invariant; the disk cache spares each cold CLI
|
|
237
239
|
// process the resolve round-trips.
|
|
@@ -282,8 +284,8 @@ export class ColumnSync {
|
|
|
282
284
|
this._metaFromDiskCache = false;
|
|
283
285
|
return this._meta;
|
|
284
286
|
} catch (err) {
|
|
285
|
-
if (
|
|
286
|
-
this.
|
|
287
|
+
if (isBoardAccessFailure(err)) {
|
|
288
|
+
this._accessFailure = boardAccessFailureReason(err);
|
|
287
289
|
return null;
|
|
288
290
|
}
|
|
289
291
|
this.logger.warn?.(
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
} from '../config/temp-paths.js';
|
|
14
14
|
import { gh as defaultGh } from '../gh-exec.js';
|
|
15
15
|
import { gitSpawn as defaultGitSpawn, getStoryBranch } from '../git-utils.js';
|
|
16
|
+
import { isObject } from '../json-utils.js';
|
|
16
17
|
import { defaultSleep } from '../util/sleep.js';
|
|
17
18
|
import {
|
|
18
19
|
CHECKS_FAILED_CLASS,
|
|
@@ -226,7 +227,7 @@ export function probeCloseArtifacts({
|
|
|
226
227
|
let envelopeMtimeMs = null;
|
|
227
228
|
try {
|
|
228
229
|
const parsed = JSON.parse(fsImpl.readFileSync(envelopePath, 'utf8'));
|
|
229
|
-
if (
|
|
230
|
+
if (isObject(parsed)) {
|
|
230
231
|
envelope = parsed;
|
|
231
232
|
envelopeMtimeMs = fsImpl.statSync(envelopePath).mtimeMs;
|
|
232
233
|
}
|