@ngockhoale/ukit 3.4.83 → 3.4.85
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/CHANGELOG.md +17 -0
- package/package.json +1 -1
- package/scripts/release/publish-guard.mjs +2 -2
- package/src/diagnostics/failurePatterns.js +6 -4
- package/src/learning/codeProposals.js +2 -2
- package/template_project/.claude/ukit/index/reset-auto-permissions.mjs +31 -1
- package/template_project/.claude/ukit/index/route-task.mjs +10 -3
- package/template_project/.claude/ukit/runtime/execution-ledger.mjs +127 -22
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to UKit are documented here.
|
|
4
4
|
|
|
5
|
+
## 3.4.85 - 2026-11-14
|
|
6
|
+
|
|
7
|
+
- Release gate (repository only): **the publish guard no longer has an owner-authorization prerequisite.** Since 3.4.72 `npm publish` also required a fresh owner chat message naming the exact version, so finished, verified and reviewed work stopped to ask for a sentence. The project owner did not want that step: a release is a new version number for users to check. The per-version message check and the standing-grant form added in 3.4.84 are both removed; a receipt needs no `authorization` block and a leftover one is ignored. Still mandatory: an official `release:verify` PASS on the exact candidate (unchanged), and an independent review whose final verdict is exactly APPROVED, derived from a native reviewer session. One review rule replaces a side effect of the removed step: the owner-session comparison was also what kept the reviewer apart from the working session, so the cited review message must now come from a separate reviewer agent's own transcript (`<session>/subagents/agent-<id>.jsonl`); a message from a main session is refused. `PROJECT_IMPORTANT.md` §4.4 now records the rule (finished work ships without asking; the two quality gates stay).
|
|
8
|
+
- Tests: `tests/release/publishGuard.test.js` drops the owner-message and standing-grant cases; the session-store provenance cases (unknown uuid, hash mismatch, foreign store, cwd binding, session metadata, text blocks) now run against the reviewer message. New cases: a main-session reviewer message refuses; a reviewer agent working in a linked worktree passes.
|
|
9
|
+
|
|
10
|
+
## 3.4.84 - 2026-11-14
|
|
11
|
+
|
|
12
|
+
Follow-up to the 3.4.83 hook audit: the items that release left open.
|
|
13
|
+
|
|
14
|
+
- Fix: **a command that only mentions a test runner no longer counts as verification.** The completion gate's classifier matched runner names anywhere in the command text, so `grep -n pytest file`, `ls node_modules/.bin/vitest`, `echo yarn test`, `yarn add -D vitest`, `npm install jest` or `which vitest`, run with exit 0, were recorded as a verification receipt with a satisfying `test-verified` verdict — a task could be declared verified with no test run. Each simple command is now judged by the word that executes: direct runners (`vitest`, `jest`, `mocha`, `ava`, `pytest`, `tsc`, `eslint`, `biome`, `ruff`, `mypy`), package-manager scripts (`test`, `test:*`, `lint`, `typecheck`, `check`, `build`, `release:verify`, via `run`/`exec`/`dlx`/`workspace` and `npx`), `python -m pytest`, `uv`/`poetry run …`, `node --test` / `node --check`. Leading assignments, the env/time/timeout/sudo/nohup/corepack wrappers and value-taking options (`yarn --cwd DIR …`, `pnpm -C DIR …`, `npm --prefix DIR …`) are skipped; arguments, paths, comments, quoted strings and heredoc bodies are never evidence. Newly recognised: `pnpm -C pkg test`, `npm --prefix pkg test`, `yarn workspace foo test`, `node node_modules/vitest/vitest.mjs run`. `[ vitest = vitest ]` / `test vitest = vitest` now produce no verification receipt at all.
|
|
15
|
+
- Fix: **`reset-auto-permissions.mjs --help` no longer performs a reset.** Arguments were checked with `includes`, so `--help` or any typo (`--dry-runn`) fell through to the real reset. `--help` / `-h` print usage and exit 0; any unknown argument exits 2; both return before a file is read.
|
|
16
|
+
- Fix: **decision-plane shadow calls stop timing out on a healthy endpoint.** The detached hook-path shadow child blocks no hook, yet shared the inline path's 3 s cap; an 8-question batch to the local `unic-decision` endpoint measured about 2 s typical with 3–6 s tails, so whole batches timed out and then opened the circuit breaker. The detached child now honours `decisionPlane.timeoutMs` up to 8 s; the inline path keeps 3 s and shadow answers still never change a route. The "five keys never answered" note in 3.4.83 was not reproduced: all eight asked keys returned valid answers in the audited week (five have no baseline to compare against and log `agree=unknown`).
|
|
17
|
+
- Fix: self-improve classifies `timeout-hang` from host evidence. A Bash receipt carries `timedOut` when Claude Code reports the call as a failure whose own error reads "Command timed out after …"; mined patterns carry the marker and `timeout-hang` accepts it. Exit 137/143 alone stay unclassified (137 is also the OOM-kill status). Codex and omp expose no equivalent field that could be confirmed, so their timeouts still rely on exit 124 or the text markers.
|
|
18
|
+
- Release gate (repository only): **the publish guard accepts a standing owner authorization.** Since 3.4.72 every publish needed a fresh owner chat message naming the exact version, so a finished, verified and reviewed fix still stopped to ask. The receipt may now cite `authorization: { by: 'user', standing: true }`; the guard then reads the grant from the "Standing publish authorization" section of the git-tracked `PROJECT_IMPORTANT.md` (regular file, committed and unmodified at HEAD, names the package, covers every version, one line that authorizes publishing, states the verification + review conditions, no denial, pending or negated grant). The verified run and the independent APPROVED review are unchanged and still mandatory; a receipt that cites a message is judged on that message only. The template `PROJECT_IMPORTANT.md` shipped to installed projects carries no grant.
|
|
19
|
+
- Tests: new `tests/hooks/verificationCommandWord.test.js`; argument-safety cases in `tests/hooks/c91ResetAutoPermissions.test.js`; timeout-budget cases in `tests/index/unicDecisionCircuit.test.js`; `timedOut` cases in the ledger, pattern and proposal tests; standing-authorization cases in `tests/release/publishGuard.test.js`. `tests/hooks/nativePublicationRouting.test.js` now reports router and gate output when its foreign-session assertion fails.
|
|
20
|
+
- Not changed: that test failed once under full-suite load in 3.4.83 and could not be reproduced (load average 60, slowed git, paused coordinator), so no product change was made for it. A related gap was found and is not fixed here: when the router is killed by its deadline before its first route write, or its session lock is busy, the following Stop evaluates no route and releases without a message.
|
|
21
|
+
|
|
5
22
|
## 3.4.83 - 2026-11-13
|
|
6
23
|
|
|
7
24
|
Hook fixes from a one-week audit of this repository's own Claude Code transcripts, hook-latency rows, decision log and permission audit log (6,685 hook runs, no hook timeouts; Stop p95 about 1.6s).
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Shipped prepublishOnly dispatcher for the release publish gate (3.4.72).
|
|
3
3
|
// In the UKit development repository it hands over to the maintainer-only gate core
|
|
4
|
-
// (scripts/release/publish-guard-core.mjs, which enforces verification PASS
|
|
5
|
-
// exactly-APPROVED review
|
|
4
|
+
// (scripts/release/publish-guard-core.mjs, which enforces verification PASS and an independent
|
|
5
|
+
// exactly-APPROVED review before any npm publish).
|
|
6
6
|
// In an installed copy of @ngockhoale/ukit the core does not exist — publishing happens
|
|
7
7
|
// only from the development repository — and this script must fail CLOSED with a clear
|
|
8
8
|
// refusal, never a MODULE_NOT_FOUND crash.
|
|
@@ -60,7 +60,7 @@ function failureCommands(ledger) {
|
|
|
60
60
|
const verifyFail = receipt.success === false && VERIFY_KINDS.has(receipt.kind);
|
|
61
61
|
const ledgerFlagged = ledger.verificationFailed === true && receipt.success === false;
|
|
62
62
|
if (verifyFail || ledgerFlagged) {
|
|
63
|
-
out.push({ command: receipt.command, file: receipt.file, exitCode: receipt.exitCode });
|
|
63
|
+
out.push({ command: receipt.command, file: receipt.file, exitCode: receipt.exitCode, timedOut: receipt.timedOut === true });
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
return out;
|
|
@@ -87,7 +87,7 @@ async function writeArtifact(filePath, result) {
|
|
|
87
87
|
* @returns {Promise<{generatedAt: string, ledgersScanned: number,
|
|
88
88
|
* ledgersWithFailures: number,
|
|
89
89
|
* patterns: Array<{signature: string, count: number, sessions: number,
|
|
90
|
-
* commands: string[], files: string[], exitCodes: number[]}>}>} never throws.
|
|
90
|
+
* commands: string[], files: string[], exitCodes: number[], timedOut?: true}>}>} never throws.
|
|
91
91
|
*/
|
|
92
92
|
export async function mineFailurePatterns(projectRoot, { limitLedgers = 500, minCount = 2 } = {}) {
|
|
93
93
|
const result = {
|
|
@@ -116,17 +116,18 @@ export async function mineFailurePatterns(projectRoot, { limitLedgers = 500, min
|
|
|
116
116
|
result.ledgersWithFailures += 1;
|
|
117
117
|
const sessionId = typeof ledger.sessionId === 'string' ? ledger.sessionId : null;
|
|
118
118
|
|
|
119
|
-
for (const { command, file, exitCode } of failures) {
|
|
119
|
+
for (const { command, file, exitCode, timedOut } of failures) {
|
|
120
120
|
const signature = normalizeSignature(command);
|
|
121
121
|
if (!signature) continue;
|
|
122
122
|
let group = groups.get(signature);
|
|
123
123
|
if (!group) {
|
|
124
|
-
group = { signature, count: 0, sessions: new Set(), commands: [], files: [], exitCodes: new Set() };
|
|
124
|
+
group = { signature, count: 0, sessions: new Set(), commands: [], files: [], exitCodes: new Set(), timedOut: false };
|
|
125
125
|
groups.set(signature, group);
|
|
126
126
|
}
|
|
127
127
|
group.count += 1;
|
|
128
128
|
// Real failure evidence: non-zero exit status the host reported (e.g. 124 = timeout(1)).
|
|
129
129
|
if (Number.isInteger(exitCode) && exitCode !== 0) group.exitCodes.add(exitCode);
|
|
130
|
+
if (timedOut) group.timedOut = true; // host-structured timeout marker on the receipt
|
|
130
131
|
if (sessionId) group.sessions.add(sessionId);
|
|
131
132
|
if (group.commands.length < MAX_EXAMPLES && !group.commands.includes(command)) {
|
|
132
133
|
group.commands.push(command);
|
|
@@ -148,6 +149,7 @@ export async function mineFailurePatterns(projectRoot, { limitLedgers = 500, min
|
|
|
148
149
|
commands: g.commands,
|
|
149
150
|
files: g.files,
|
|
150
151
|
exitCodes: [...g.exitCodes].sort((a, b) => a - b),
|
|
152
|
+
...(g.timedOut ? { timedOut: true } : {}),
|
|
151
153
|
}));
|
|
152
154
|
} catch {
|
|
153
155
|
// Any unexpected failure → return whatever was computed so far.
|
|
@@ -36,7 +36,7 @@ const DENIED_TARGET_RES = [
|
|
|
36
36
|
// Whitelist — bounded deterministic mapping only. Classification needs evidence,
|
|
37
37
|
// not a word that happens to occur in a command's text: the ledger records no
|
|
38
38
|
// timed-out/killed/signal marker, only `exitCode` (mined onto pattern.exitCodes),
|
|
39
|
-
// so timeout-hang keys on exit 124 (GNU timeout(1)). Text markers are a fallback:
|
|
39
|
+
// so timeout-hang keys on a host timed-out marker (`pattern.timedOut`, from the receipt's `timedOut`) or exit 124 (GNU timeout(1)); 137/143 alone are not evidence (137 is also OOM-kill). Text markers are a fallback:
|
|
40
40
|
// whole words only, matched against the command's invocation lines — never
|
|
41
41
|
// heredoc bodies, comments, env-var names or file names.
|
|
42
42
|
const TIMEOUT_EXIT_CODES = new Set([124]);
|
|
@@ -44,7 +44,7 @@ const TIMEOUT_EXIT_CODES = new Set([124]);
|
|
|
44
44
|
const FIX_CLASSES = [
|
|
45
45
|
{
|
|
46
46
|
id: 'timeout-hang',
|
|
47
|
-
matches: (text, pattern) => (Array.isArray(pattern.exitCodes)
|
|
47
|
+
matches: (text, pattern) => pattern.timedOut === true || (Array.isArray(pattern.exitCodes)
|
|
48
48
|
&& pattern.exitCodes.some((code) => TIMEOUT_EXIT_CODES.has(code)))
|
|
49
49
|
|| /\b(?:timed out|timeout (?:exceeded|expired)|hangs|hanging|hung)\b/.test(text.commands),
|
|
50
50
|
change: 'Increase the timeout, add an explicit deadline, and retry once before giving up.',
|
|
@@ -3,8 +3,28 @@ import fs from 'node:fs/promises';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
5
5
|
|
|
6
|
+
const USAGE = `Usage: reset-auto-permissions.mjs [--dry-run] [--quiet] [--sanitize] [--help]
|
|
7
|
+
|
|
8
|
+
Run from the project root. A bare run is a REAL reset: it removes every
|
|
9
|
+
UKit-managed auto-permission allow rule from .claude/settings.local.json and
|
|
10
|
+
clears managedRules in .claude/ukit/permission-usage.json.
|
|
11
|
+
|
|
12
|
+
Options:
|
|
13
|
+
--dry-run Report what would be removed; write nothing.
|
|
14
|
+
--sanitize Remove only proven UKit-minted denylist rules (not a full reset).
|
|
15
|
+
--quiet Suppress the report output.
|
|
16
|
+
-h, --help Print this help and exit without touching anything.
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
const KNOWN_FLAGS = new Set(['--dry-run', '--quiet', '--sanitize', '--help', '-h']);
|
|
20
|
+
|
|
21
|
+
// Strict: any argument that is not a known flag aborts BEFORE any state is read
|
|
22
|
+
// or written — an unknown/typo'd flag must never fall through to a real reset.
|
|
6
23
|
function parseArgs(argv) {
|
|
24
|
+
const unknown = argv.filter((arg) => !KNOWN_FLAGS.has(arg));
|
|
7
25
|
return {
|
|
26
|
+
unknown,
|
|
27
|
+
help: argv.includes('--help') || argv.includes('-h'),
|
|
8
28
|
dryRun: argv.includes('--dry-run'),
|
|
9
29
|
quiet: argv.includes('--quiet'),
|
|
10
30
|
sanitize: argv.includes('--sanitize'),
|
|
@@ -406,7 +426,17 @@ async function runSanitize({ rootDir, dryRun, quiet }) {
|
|
|
406
426
|
}
|
|
407
427
|
|
|
408
428
|
async function main() {
|
|
409
|
-
const { dryRun, quiet, sanitize } = parseArgs(process.argv.slice(2));
|
|
429
|
+
const { unknown, help, dryRun, quiet, sanitize } = parseArgs(process.argv.slice(2));
|
|
430
|
+
if (unknown.length > 0) {
|
|
431
|
+
console.error(`[UKit] Unrecognised argument(s): ${unknown.join(' ')} — nothing was changed.\n`);
|
|
432
|
+
console.error(USAGE);
|
|
433
|
+
process.exitCode = 2;
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
if (help) {
|
|
437
|
+
console.log(USAGE);
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
410
440
|
const rootDir = process.cwd();
|
|
411
441
|
if (sanitize) {
|
|
412
442
|
await runSanitize({ rootDir, dryRun, quiet });
|
|
@@ -1373,7 +1373,7 @@ async function main() {
|
|
|
1373
1373
|
// spawns this fire-and-forget per emitted route. Self-deadline so a wedged
|
|
1374
1374
|
// import/read can never leave an orphan (same watchdog posture as the hook).
|
|
1375
1375
|
if (args.includes('--decision-shadow')) {
|
|
1376
|
-
setTimeout(() => process.exit(0),
|
|
1376
|
+
setTimeout(() => process.exit(0), DECISION_SHADOW_DETACHED_CAP_MS * 2).unref();
|
|
1377
1377
|
await runHookPathDecisionShadow({
|
|
1378
1378
|
rootDir,
|
|
1379
1379
|
statePath: sharedStatePath,
|
|
@@ -1938,6 +1938,11 @@ async function prepareTaskRoute({
|
|
|
1938
1938
|
// fail-silent to the deterministic baseline.
|
|
1939
1939
|
const UNIC_DECISION_CLI_PATH = path.join(__routeTaskDir, 'unic-decision.mjs');
|
|
1940
1940
|
const DECISION_SHADOW_TIMEOUT_CAP_MS = 3000;
|
|
1941
|
+
// The detached hook-path child blocks nothing (fire-and-forget, own watchdog),
|
|
1942
|
+
// so it may honour the configured decisionPlane.timeoutMs up to this ceiling.
|
|
1943
|
+
// Measured 8-question batches take ~2s typical with 3-6s tails, so the inline
|
|
1944
|
+
// 3s cap timed out a large share of calls and tripped the circuit breaker.
|
|
1945
|
+
const DECISION_SHADOW_DETACHED_CAP_MS = 8000;
|
|
1941
1946
|
|
|
1942
1947
|
|
|
1943
1948
|
// Probability → band for receipts. Bands only; raw probabilities never leave
|
|
@@ -2111,6 +2116,7 @@ export async function runRouteDecisionShadow({
|
|
|
2111
2116
|
spawnImpl = spawnSync,
|
|
2112
2117
|
appendDecisionImpl = null,
|
|
2113
2118
|
now = () => Date.now(),
|
|
2119
|
+
timeoutCapMs = DECISION_SHADOW_TIMEOUT_CAP_MS,
|
|
2114
2120
|
} = {}) {
|
|
2115
2121
|
const stage = resolveDecisionPlaneStage(config);
|
|
2116
2122
|
if (stage === 'off') return null;
|
|
@@ -2163,8 +2169,8 @@ export async function runRouteDecisionShadow({
|
|
|
2163
2169
|
const timeoutMs = Math.min(
|
|
2164
2170
|
(Number.isFinite(config?.decisionPlane?.timeoutMs)
|
|
2165
2171
|
? config.decisionPlane.timeoutMs
|
|
2166
|
-
:
|
|
2167
|
-
|
|
2172
|
+
: timeoutCapMs) + 1000,
|
|
2173
|
+
timeoutCapMs + 1000,
|
|
2168
2174
|
);
|
|
2169
2175
|
const batchId = `route-shadow-${now().toString(36)}-${crypto.randomBytes(3).toString('hex')}`;
|
|
2170
2176
|
// BL-017: historySignals feed laneDeepening/verificationDepth features —
|
|
@@ -2382,6 +2388,7 @@ async function runHookPathDecisionShadow({
|
|
|
2382
2388
|
config,
|
|
2383
2389
|
routeSummary,
|
|
2384
2390
|
routingContext,
|
|
2391
|
+
timeoutCapMs: DECISION_SHADOW_DETACHED_CAP_MS,
|
|
2385
2392
|
});
|
|
2386
2393
|
} catch {
|
|
2387
2394
|
// Detached child: a failed shadow pass is observable via decisions.tsv
|
|
@@ -698,6 +698,16 @@ function malformedNativeExitPayload(payload = {}) {
|
|
|
698
698
|
return objects.some((obj) => EXIT_FIELDS.some((field) => Object.hasOwn(obj, field) && invalidExit(obj[field])));
|
|
699
699
|
}
|
|
700
700
|
|
|
701
|
+
// Structured host evidence of a timeout: Claude Code's Bash tool reports a killed-on-timeout call as a
|
|
702
|
+
// PostToolUseFailure whose host-generated `error` reads "[Exit code N\n]Command timed out after Ns". The
|
|
703
|
+
// text is the host's own error field (never the command), anchored so command output cannot spoof it.
|
|
704
|
+
// Exit 137/143 alone stay unclassified (137 is also OOM-kill).
|
|
705
|
+
const HOST_TIMEOUT_ERROR_RE = /^(?:Exit code \d+\s*\n)?Command timed out after \d+(?:\.\d+)?m?s\b/;
|
|
706
|
+
function hostTimedOut(payload = {}) {
|
|
707
|
+
return payload.hook_event_name === 'PostToolUseFailure' && typeof payload.error === 'string'
|
|
708
|
+
&& HOST_TIMEOUT_ERROR_RE.test(payload.error.trim());
|
|
709
|
+
}
|
|
710
|
+
|
|
701
711
|
function extractExitCode(payload = {}) {
|
|
702
712
|
const candidates = [
|
|
703
713
|
payload.tool_output?.exitCode,
|
|
@@ -809,27 +819,128 @@ function executableSubstitutions(command) {
|
|
|
809
819
|
return String(command || '').replace(/'[^']*'/g, '').match(/\$\([^]*?\)|`[^`]*`/g) || [];
|
|
810
820
|
}
|
|
811
821
|
|
|
812
|
-
|
|
822
|
+
// Verification evidence comes from the word(s) that EXECUTE (the runner invocation), never from
|
|
823
|
+
// arguments, paths, comments, heredoc bodies or quoted strings: `grep -n pytest f`, `ls .bin/vitest`
|
|
824
|
+
// and `sed -n 1,5p tests/jest.js` ran no verifier. Each simple command is reduced to its command
|
|
825
|
+
// word (env assignments / time / sudo / timeout wrappers skipped) and judged on its own.
|
|
826
|
+
const TEST_RUNNER_WORDS = new Set(['vitest', 'jest', 'mocha', 'ava', 'pytest', 'py.test']);
|
|
827
|
+
const CHECK_RUNNER_WORDS = new Set(['tsc', 'eslint', 'biome', 'ruff', 'mypy']);
|
|
828
|
+
const PY_RUNNER_MODULES = new Set(['pytest', 'py.test', 'mypy', 'ruff']);
|
|
829
|
+
const PM_WORDS = new Set(['npm', 'pnpm', 'yarn', 'bun']);
|
|
830
|
+
const PM_SCRIPT = /^(test(?::[\w:.-]+)?|lint|typecheck|check|build|release:verify)$/;
|
|
831
|
+
const UNIT_KEYWORDS = new Set(['if', 'then', 'else', 'elif', 'do', 'while', 'until', '!', '{', '(', 'time', 'command', 'exec', 'nohup', 'builtin', 'coproc', 'setsid', 'corepack']);
|
|
832
|
+
// Leading options are skipped; an option known to take a value (`yarn --cwd DIR vitest`, `timeout -s KILL 60 yarn test`) also drops that value.
|
|
833
|
+
function dropOptions(list, valueFlags) {
|
|
834
|
+
const copy = list.slice();
|
|
835
|
+
while (copy.length && /^-/.test(copy[0])) {
|
|
836
|
+
const flag = copy.shift();
|
|
837
|
+
if (valueFlags.has(flag) && copy.length) copy.shift();
|
|
838
|
+
}
|
|
839
|
+
return copy;
|
|
840
|
+
}
|
|
841
|
+
const PM_VALUE_FLAGS = new Set(['--cwd', '-C', '--dir', '--prefix', '--filter', '-F', '-w', '--workspace']);
|
|
842
|
+
const NPX_VALUE_FLAGS = new Set(['-p', '--package']);
|
|
843
|
+
const PM_SUBCOMMAND_VALUE_FLAGS = new Set([...PM_VALUE_FLAGS, ...NPX_VALUE_FLAGS]);
|
|
844
|
+
|
|
845
|
+
function runnerWordKind(word) {
|
|
846
|
+
const base = String(word || '').replace(/^.*\//, '').replace(/\.(?:c|m)?js$/, '');
|
|
847
|
+
if (TEST_RUNNER_WORDS.has(base.toLowerCase())) return 'test';
|
|
848
|
+
if (CHECK_RUNNER_WORDS.has(base.toLowerCase())) return 'check';
|
|
849
|
+
return null;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
function pmScriptKind(script) {
|
|
853
|
+
if (!PM_SCRIPT.test(script)) return null;
|
|
854
|
+
const isTest = /^(?:test|release:verify)$/.test(script) || (/^test:/.test(script) && !NON_TEST_SCRIPT_SUFFIX.test(script.slice(5)));
|
|
855
|
+
return isTest ? 'test' : 'check';
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
// Returns 'test' | 'check' | null for one simple command (already quote-masked).
|
|
859
|
+
function simpleCommandVerifierKind(tokens) {
|
|
860
|
+
let t = tokens.slice();
|
|
861
|
+
for (;;) {
|
|
862
|
+
while (t.length && (UNIT_KEYWORDS.has(t[0]) || /^[A-Za-z_][A-Za-z0-9_]*=/.test(t[0]) || /^[({]+$/.test(t[0]))) t.shift();
|
|
863
|
+
if (t[0] && /^[({]/.test(t[0]) && !t[0].startsWith('$(')) t[0] = t[0].replace(/^[({]+/, '');
|
|
864
|
+
if (!t[0]) return null;
|
|
865
|
+
const head = t[0].replace(/^.*\//, '');
|
|
866
|
+
if (head === 'env') { t.shift(); while (t.length && (/^-/.test(t[0]) || /^[A-Za-z_][A-Za-z0-9_]*=/.test(t[0]))) t.shift(); continue; }
|
|
867
|
+
if (head === 'timeout') { t = dropOptions(t.slice(1), new Set(['-s', '--signal', '-k', '--kill-after'])); t.shift(); continue; }
|
|
868
|
+
if (head === 'sudo') { t = dropOptions(t.slice(1), new Set(['-u', '--user', '-g', '--group'])); continue; }
|
|
869
|
+
break;
|
|
870
|
+
}
|
|
871
|
+
const head = t[0].replace(/^.*\//, '');
|
|
872
|
+
const direct = runnerWordKind(head);
|
|
873
|
+
if (direct) return direct;
|
|
874
|
+
const rest = t.slice(1);
|
|
875
|
+
if (PM_WORDS.has(head)) {
|
|
876
|
+
let r = dropOptions(rest, PM_VALUE_FLAGS);
|
|
877
|
+
if (r[0] === 'workspace' && r.length > 2) r = dropOptions(r.slice(2), PM_VALUE_FLAGS);
|
|
878
|
+
if (r[0] === 'run' || r[0] === 'exec' || r[0] === 'dlx' || r[0] === 'x') r = dropOptions(r.slice(1), PM_SUBCOMMAND_VALUE_FLAGS);
|
|
879
|
+
if (!r[0]) return null;
|
|
880
|
+
return runnerWordKind(r[0]) || pmScriptKind(r[0]);
|
|
881
|
+
}
|
|
882
|
+
if (head === 'npx' || head === 'bunx' || head === 'pnpx') {
|
|
883
|
+
const r = dropOptions(rest, NPX_VALUE_FLAGS);
|
|
884
|
+
return r[0] ? runnerWordKind(r[0]) : null;
|
|
885
|
+
}
|
|
886
|
+
if (/^python[\d.]*$/.test(head)) {
|
|
887
|
+
// Only a `-m MOD` among the interpreter's own leading options runs a module: after a script
|
|
888
|
+
// path or `-c CODE`, `-m pytest` is just an argument to that program.
|
|
889
|
+
let mod = null;
|
|
890
|
+
for (let i = 0; i < rest.length; i += 1) {
|
|
891
|
+
const arg = rest[i];
|
|
892
|
+
if (arg === '-m') { mod = rest[i + 1] || null; break; }
|
|
893
|
+
if (arg === '-W' || arg === '-X') { i += 1; continue; }
|
|
894
|
+
if (arg === '-c' || arg === '-' || arg === '--' || !/^-/.test(arg)) break;
|
|
895
|
+
}
|
|
896
|
+
if (!mod) return null;
|
|
897
|
+
if (mod === 'pytest' || mod === 'py.test') return 'test';
|
|
898
|
+
return PY_RUNNER_MODULES.has(mod) ? 'check' : null;
|
|
899
|
+
}
|
|
900
|
+
if (['uv', 'poetry', 'pipenv', 'pdm', 'hatch', 'rye', 'pipx'].includes(head)) {
|
|
901
|
+
const at = rest.indexOf('run');
|
|
902
|
+
return at >= 0 ? simpleCommandVerifierKind(dropOptions(rest.slice(at + 1), new Set(['--with', '--python', '-p']))) : null;
|
|
903
|
+
}
|
|
904
|
+
if (head === 'node') {
|
|
905
|
+
for (let i = 0; i < rest.length; i += 1) {
|
|
906
|
+
const arg = rest[i];
|
|
907
|
+
if (arg === '--test') return 'test';
|
|
908
|
+
if (arg === '--check') return 'check';
|
|
909
|
+
if (/^(?:-e|-p|--eval|--print)$/.test(arg)) return null; // inline code: later words are its argv
|
|
910
|
+
if (/^(?:-r|--require|--import|--loader|--experimental-loader|-C|--conditions)$/.test(arg)) { i += 1; continue; }
|
|
911
|
+
if (/^-/.test(arg)) continue;
|
|
912
|
+
return runnerWordKind(arg);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
return null;
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
function classifyVerifierCommand(command, depth = 0) {
|
|
919
|
+
const result = { any: false, test: false };
|
|
813
920
|
const raw = withoutInertHeredocBodies(command).trim();
|
|
814
|
-
if (!raw) return
|
|
921
|
+
if (!raw) return result;
|
|
922
|
+
const merge = (inner) => { if (inner.any) result.any = true; if (inner.test) result.test = true; };
|
|
815
923
|
if (depth < 2) {
|
|
816
924
|
for (const sub of executableSubstitutions(raw)) {
|
|
817
|
-
|
|
925
|
+
merge(classifyVerifierCommand(sub.slice(sub.startsWith('$(') ? 2 : 1, -1), depth + 1));
|
|
818
926
|
}
|
|
819
927
|
for (const match of raw.matchAll(SHELL_C_WRAPPER)) {
|
|
820
928
|
// A wrapper that is itself inside a quoted literal (`git commit -m "sh -c 'yarn test'"`) ran nothing.
|
|
821
929
|
if (insideQuote(raw, match.index)) continue;
|
|
822
|
-
|
|
930
|
+
merge(classifyVerifierCommand(match[1] ?? match[2] ?? '', depth + 1));
|
|
823
931
|
}
|
|
824
932
|
}
|
|
825
|
-
const
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
933
|
+
const units = verificationShellUnits(raw) || raw.split(/\|\||&&|[;&|\n]/).map((text) => ({ text: text.trim() }));
|
|
934
|
+
for (const unit of units) {
|
|
935
|
+
if (!unit.text) continue;
|
|
936
|
+
const kind = simpleCommandVerifierKind(maskQuotedLiterals(unit.text).trim().replace(/[)}\s]+$/, '').split(/\s+/));
|
|
937
|
+
if (kind) { result.any = true; if (kind === 'test') result.test = true; }
|
|
938
|
+
}
|
|
939
|
+
return result;
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
function isVerificationCommand(command, depth = 0) {
|
|
943
|
+
return classifyVerifierCommand(command, depth).any;
|
|
833
944
|
}
|
|
834
945
|
|
|
835
946
|
// Bounded shell exit-proof recognition, not a shell interpreter. Keep separators so a
|
|
@@ -1162,7 +1273,7 @@ function compactReceipt(receipt) {
|
|
|
1162
1273
|
kind: receipt.kind,
|
|
1163
1274
|
success: receipt.success,
|
|
1164
1275
|
};
|
|
1165
|
-
for (const key of ['toolName', 'toolUseId', 'file', 'command', 'exitCode', 'exitProof', 'scope', 'error', 'verdict', 'evidence', 'evidenceSurface', 'class', 'status', 'detail', 'operation', 'transportSuccess', 'taskInstanceId', 'sessionKey', 'sequence', 'exitStatusUnproven', 'backgroundTaskId', 'backgroundCompletion', 'agentId', 'agentType', 'contentSha']) {
|
|
1276
|
+
for (const key of ['toolName', 'toolUseId', 'file', 'command', 'exitCode', 'exitProof', 'scope', 'error', 'verdict', 'evidence', 'evidenceSurface', 'class', 'status', 'detail', 'operation', 'transportSuccess', 'taskInstanceId', 'sessionKey', 'sequence', 'exitStatusUnproven', 'backgroundTaskId', 'backgroundCompletion', 'agentId', 'agentType', 'contentSha', 'timedOut']) {
|
|
1166
1277
|
if (receipt[key] !== undefined && receipt[key] !== null && receipt[key] !== '') {
|
|
1167
1278
|
compact[key] = key === 'operation' ? compactOperation(receipt[key]) : receipt[key];
|
|
1168
1279
|
}
|
|
@@ -1496,20 +1607,13 @@ export function verdictCurrent(verdict, { cwd = process.cwd() } = {}) {
|
|
|
1496
1607
|
// (a hook or subagent can attest its own kind/verifier); otherwise the kind is
|
|
1497
1608
|
// derived from the command shape — test runners prove `test-verified`, a run that
|
|
1498
1609
|
// only type-checks/lints is honestly `check-only`.
|
|
1499
|
-
const TEST_RUNNER_COMMAND = /(?:^|[\s({]|\.bin\/)(?:vitest|jest|mocha|ava|pytest|py\.test)(?:\s|$)|(?:npm|pnpm|yarn|bun)(?:\s+run)?\s+test(?:\s|$)/i;
|
|
1500
1610
|
// Package-script gates that actually execute tests: `test`, `test:<suite>` and the
|
|
1501
1611
|
// project's `release:verify` gate. Static-check / fixture-mutating variants
|
|
1502
1612
|
// (`test:types`, `test:lint`, `test:update-snapshots`, `test:watch`, ...) stay check-only.
|
|
1503
|
-
const TEST_SCRIPT_COMMAND = /(?:^|[\s;&|(])(?:npm|pnpm|yarn|bun)(?:\s+run)?\s+(test(?::[\w:.-]+)?|release:verify)(?=$|[\s;&|)])/gi;
|
|
1504
1613
|
const NON_TEST_SCRIPT_SUFFIX = /(?:^|:)(?:types?|typecheck|tsc|lint|format|fmt|snapshots?|update[\w-]*|watch|coverage-?report|clean|setup|fixtures?)(?::|$)/i;
|
|
1505
1614
|
|
|
1506
1615
|
function isTestGateCommand(command) {
|
|
1507
|
-
|
|
1508
|
-
if (TEST_RUNNER_COMMAND.test(text)) return true;
|
|
1509
|
-
for (const m of text.matchAll(TEST_SCRIPT_COMMAND)) {
|
|
1510
|
-
if (!NON_TEST_SCRIPT_SUFFIX.test(m[1])) return true;
|
|
1511
|
-
}
|
|
1512
|
-
return false;
|
|
1616
|
+
return classifyVerifierCommand(command).test;
|
|
1513
1617
|
}
|
|
1514
1618
|
|
|
1515
1619
|
function mintVerificationVerdict(receipt, payload, projectRoot, sessionRoot = projectRoot) {
|
|
@@ -2118,7 +2222,7 @@ function newEventId() {
|
|
|
2118
2222
|
return `${Date.now().toString(36)}-${crypto.randomBytes(8).toString('hex')}`;
|
|
2119
2223
|
}
|
|
2120
2224
|
|
|
2121
|
-
const JOURNAL_RECEIPT_FIELDS = ['ts', 'kind', 'toolName', 'toolUseId', 'success', 'exitCode', 'exitProof', 'file', 'command', 'scope', 'workspaceFp', 'workspaceRoot', 'workspaceHeadTs', 'bashReadOnly', 'exitStatusUnproven', 'backgroundTaskId', 'backgroundCompletion', 'detail', 'operation', 'transportSuccess', 'taskInstanceId', 'sessionKey', 'sequence', 'agentId', 'agentType', 'contentSha', 'handback', 'review', 'verdict'];
|
|
2225
|
+
const JOURNAL_RECEIPT_FIELDS = ['ts', 'kind', 'toolName', 'toolUseId', 'success', 'exitCode', 'exitProof', 'file', 'command', 'scope', 'workspaceFp', 'workspaceRoot', 'workspaceHeadTs', 'bashReadOnly', 'exitStatusUnproven', 'backgroundTaskId', 'backgroundCompletion', 'detail', 'operation', 'transportSuccess', 'taskInstanceId', 'sessionKey', 'sequence', 'agentId', 'agentType', 'contentSha', 'timedOut', 'handback', 'review', 'verdict'];
|
|
2122
2226
|
|
|
2123
2227
|
// TASK-009 (BL-011): evidence attestations are whitelisted verbatim — class /
|
|
2124
2228
|
// surface / result / claim, the ARCH §Evidence Schema fields a receipt may
|
|
@@ -3619,6 +3723,7 @@ export async function recordExecutionReceipt({
|
|
|
3619
3723
|
success,
|
|
3620
3724
|
exitCode,
|
|
3621
3725
|
};
|
|
3726
|
+
if (toolName === 'Bash' && hostTimedOut(payload)) receipt.timedOut = true;
|
|
3622
3727
|
const featureRun = routeState?.routeSummary?.playbookId === playbookExecution.FEATURE_PLAYBOOK_ID;
|
|
3623
3728
|
|
|
3624
3729
|
const policy = routeState?.routeSummary?.executionContract?.releasePolicy;
|