@holmes-lab/holmes-kit 0.35.18 → 0.35.20
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 +83 -0
- package/README.md +3 -2
- package/dist/.build-id +1 -1
- package/dist/holmes/cli/agents.js +13 -7
- package/dist/holmes/cli/approve-status.d.ts +4 -1
- package/dist/holmes/cli/approve-status.js +10 -0
- package/dist/holmes/cli/approve-watch.js +1 -1
- package/dist/holmes/cli/approve.d.ts +3 -3
- package/dist/holmes/cli/approve.js +12 -7
- package/dist/holmes/cli/autonomy.d.ts +13 -6
- package/dist/holmes/cli/autonomy.js +105 -16
- package/dist/holmes/cli/codex-hooks.js +3 -1
- package/dist/holmes/cli/doctor.js +7 -1
- package/dist/holmes/cli/index.js +25 -6
- package/dist/holmes/cli/init.js +2 -1
- package/dist/holmes/cli/runtime-binding.d.ts +18 -1
- package/dist/holmes/cli/runtime-binding.js +80 -5
- package/dist/holmes/cpg/scan-cache.d.ts +11 -1
- package/dist/holmes/cpg/scan-cache.js +72 -2
- package/dist/holmes/governance/approval-queue.d.ts +1 -1
- package/dist/holmes/governance/approval-queue.js +10 -4
- package/dist/holmes/governance/autonomy.d.ts +0 -2
- package/dist/holmes/governance/autonomy.js +14 -4
- package/dist/holmes/governance/delegation.d.ts +40 -0
- package/dist/holmes/governance/delegation.js +151 -0
- package/dist/holmes/guardrail/write-target.d.ts +10 -0
- package/dist/holmes/guardrail/write-target.js +82 -0
- package/dist/holmes/hooks/adapters/antigravity.d.ts +2 -0
- package/dist/holmes/hooks/adapters/antigravity.js +8 -1
- package/dist/holmes/hooks/pre-tool-use.d.ts +3 -1
- package/dist/holmes/hooks/pre-tool-use.js +22 -4
- package/dist/holmes/hooks/rtm-refresh-child.d.ts +27 -0
- package/dist/holmes/hooks/rtm-refresh-child.js +69 -3
- package/dist/holmes/hooks/rtm-refresh.d.ts +1 -0
- package/dist/holmes/hooks/rtm-refresh.js +8 -0
- package/dist/holmes/hooks/stop.d.ts +8 -0
- package/dist/holmes/hooks/stop.js +20 -5
- package/dist/holmes/mcp/handlers/spec-approval.d.ts +1 -1
- package/dist/holmes/mcp/handlers/spec-approval.js +21 -2
- package/dist/holmes/mcp/handlers.d.ts +5 -5
- package/dist/holmes/refresh/freshness-coordinator.d.ts +13 -0
- package/dist/holmes/refresh/freshness-coordinator.js +42 -2
- package/dist/holmes/runtime/dispatch.js +5 -3
- package/dist/holmes/runtime/hook-process.d.ts +8 -0
- package/dist/holmes/runtime/hook-process.js +13 -1
- package/dist/holmes/semantic/embedder.d.ts +6 -0
- package/dist/holmes/semantic/embedder.js +10 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,89 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
<!-- @implements A-SPEC-209 -->
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.35.20] - 2026-10-15
|
|
11
|
+
|
|
12
|
+
Upgrading: restart every session and MCP server, run `holmes-kit runtime-binding setup` again (the hook dispatcher runs
|
|
13
|
+
from the copy it installs), and trust the rewritten Codex Stop hook once with `/hooks`.
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- **One workspace runs one detached refresh at a time** (A-SPEC-719.1). Measured 2026-10-15 on a 3,083-document
|
|
18
|
+
workspace: the freshness lease expired two minutes after `startedAt`, so a refresh that needed longer lost its lease
|
|
19
|
+
while still running, every later Stop hook or `requirement_triage` spawned another `rtm-refresh-child`, and 13–16
|
|
20
|
+
ran at once (receipt `attempt: 13`, load average 300–520, Stop hooks of unrelated sessions over their 18 s budget).
|
|
21
|
+
The receipt now names its worker's `pid`; a lease whose worker is alive is not expired (up to 30 minutes, then it
|
|
22
|
+
is), a crashed worker still frees it after two minutes, and the worker ends itself at 30 minutes leaving `retry-at`
|
|
23
|
+
with `failure.stage: 'child'`. Receipts without `pid` keep the former rule.
|
|
24
|
+
- **A superseded refresh worker ends within 15 seconds, at background priority** (A-SPEC-719.2). The worker asked
|
|
25
|
+
whether it still held its lease only between phases, so nine superseded workers kept embedding for 2–4 hours after a
|
|
26
|
+
newer generation had already completed; each also ran at default priority with 16 ONNX threads. The child now lowers
|
|
27
|
+
itself to the lowest scheduling priority (nice 19; `PRIORITY_LOW` on Windows) and checks its lease every
|
|
28
|
+
`REFRESH_SUPERSEDE_POLL_MS` (15 s), exiting at the first answer that it no longer holds it. It still never writes a
|
|
29
|
+
receipt for a generation it does not own.
|
|
30
|
+
- **The Stop hook no longer re-parses the whole workspace every turn** (A-SPEC-769.9). Measured 2026-10-15 at load
|
|
31
|
+
~300: the Stop hook's shared scan parsed all 463 files with no cache in 23.0 s, against an 18 s budget, so every Stop
|
|
32
|
+
of every session was refused with `Selected hook runtime deadline exceeded`. It now reads the content-hash scan cache
|
|
33
|
+
the background refresh already keeps (`scanCacheDirFor(root)`): 0.48 s once warm. The cache file is now replaced
|
|
34
|
+
atomically, since two processes share it.
|
|
35
|
+
- **The Stop scan cache lives in the workspace and skips the compiler pass** (A-SPEC-769.11, review round 1 of
|
|
36
|
+
769.9/769.10). In a governed workspace the cache is `<root>/.ax/cpg_cache` — the directory the MCP server already
|
|
37
|
+
uses — instead of a computable name in the shared temp directory, where another local user on Linux could plant
|
|
38
|
+
entries the Stop gate then believed. The temporary file is created exclusively under a random name (a planted file or
|
|
39
|
+
link there is never written through), and leftovers older than ten minutes are swept. The Stop scan no longer runs the
|
|
40
|
+
whole-program TypeScript pass, which neither Stop judgement reads. The Stop stage-timing line prints from 9 s, and
|
|
41
|
+
`init`'s Codex trust-change refusal names the changed Stop timeout among its causes.
|
|
42
|
+
- **The Stop hook's deadline is 60 seconds** (A-SPEC-769.10). PreToolUse keeps 18 s. The runtime dispatcher gives the
|
|
43
|
+
Stop entry `STOP_HOOK_BUDGET_MS` (60 s), and Holmes Stop entries are written with `timeout: 75` on Claude, Codex and
|
|
44
|
+
Antigravity (budget, 8 s cleanup and a margin). The dispatcher runs from the copy `runtime-binding setup` installs
|
|
45
|
+
under `~/.holmes/runtime`, and harness wiring keeps its old `timeout: 30` until it is rewritten: after upgrading, run
|
|
46
|
+
`holmes-kit runtime-binding setup` (operator) or `holmes-kit init` again. Codex hashes a hook's timeout into its trust
|
|
47
|
+
identity, so the rewritten Codex Stop hook must be trusted again once with `/hooks`.
|
|
48
|
+
- **The local embedder keeps its progress** (A-SPEC-719.3). The local (BGE-M3) `warm()` flushed the vector cache once,
|
|
49
|
+
after its last text, so a refresh worker ended before then landed nothing and the next one started from zero. It
|
|
50
|
+
now publishes a segment after every 25 new vectors (`LOCAL_WARM_CHECKPOINT`), as the cloud warm does per batch.
|
|
51
|
+
|
|
52
|
+
## [0.35.19] - 2026-10-13
|
|
53
|
+
|
|
54
|
+
### Added
|
|
55
|
+
|
|
56
|
+
- **Run delegation — a third autonomy envelope for benchmark runs** (REQ-771, A-SPEC-771, A-SPEC-771.1). Measured
|
|
57
|
+
2026-10-12 (X1): a fixture the operator had approved as a whole still stopped a REQ and an H-SPEC on
|
|
58
|
+
`upstream-has-human-aspec: … — files-to-touch-root-only`, because neither the project default (A-SPEC-552.1) nor the
|
|
59
|
+
session marker (A-SPEC-553.1) can name a run, a workspace or a grader rule. `holmes-kit autonomy delegate --run <id>
|
|
60
|
+
--allow <rule[,rule]> [--for 2h] [--limit k=v]… [--rationale <text>]` (same human proof as `autonomy on`) writes
|
|
61
|
+
`.ax/state/delegation.json` with the resolved workspace realpath, the covered rules (a closed set: root-only or
|
|
62
|
+
gate-file Files to Touch, an undirected gate-behavior grade, an upstream without A-SPEC — never architecture
|
|
63
|
+
documents, un-admitted requirements, undeclared or unknown grades), an expiry and declared limits. `spec_approve`
|
|
64
|
+
then seals a hitl verdict whose rule the delegation covers with `source: 'delegated'`, actor `delegated:<client>`
|
|
65
|
+
and the ledger rationale `delegated grant (run <id>, rule <rule>)`; an uncovered case refuses with
|
|
66
|
+
`[delegation: run … does not cover …]`, `[delegation: expired …]`, `[delegation: for <workspace>, not this root]` or
|
|
67
|
+
`[delegation: invalid document …]`. `autonomy status`, `approve --status` and the session-start banner show it;
|
|
68
|
+
`revoke-delegation` (or `off`) ends it. The grader's verdicts are unchanged; the host's own approval layer is named
|
|
69
|
+
as not covered.
|
|
70
|
+
|
|
71
|
+
### Fixed
|
|
72
|
+
|
|
73
|
+
- **Every operator hint names the workspace the request lives in** (A-SPEC-770.2). Measured 2026-10-13 in the Codex X1
|
|
74
|
+
native run: the refusal hint read `approve --grant req-38dd3372238c` with no `--target`, while a request is stored in
|
|
75
|
+
the refusal log of the workspace whose hook refused — not the shell's cwd (2026-10-12: a worktree command's request
|
|
76
|
+
lived in the development root and `--target <worktree>` answered "no pending request matches"). The hook's deny text,
|
|
77
|
+
the inbox footer and the `--refusals` closing line now end their commands with `--target <absolute root>` (quoted once
|
|
78
|
+
when it contains white space, never folded); without a root the 0.35.18 text is produced byte for byte.
|
|
79
|
+
- **A context-only Codex patch is refused by its own name** (A-SPEC-769.7). Measured 2026-10-13 (X1 HB negative
|
|
80
|
+
control): an `apply_patch` whose update block had only context lines was refused as `file_path missing or not a
|
|
81
|
+
string` although its header named the file. `canonicalPatchReason` tells a no-op update from a grammar fault, and the
|
|
82
|
+
hook says `the patch to <path> adds or removes no line (a context-only update is a no-op), so there is nothing to
|
|
83
|
+
judge — include at least one + or - line`. The deny stays a deny; malformed, path-missing and non-application keep
|
|
84
|
+
their own sentences.
|
|
85
|
+
- **`runtime-binding status` and `doctor` report a Codex lifecycle routed to Holmes twice** (A-SPEC-769.8). Measured
|
|
86
|
+
2026-10-12 in both X1 fixtures: the Stop hook wrote two identical cycle rows 1 ms apart because `~/.codex/hooks.json`
|
|
87
|
+
and the workspace `.codex/hooks.json` both route `codex-stop.js` and `[hooks.state]` switches off only the user-level
|
|
88
|
+
`pre_tool_use`. The status carries `duplicateRoutes [{ harness, event, files, fix }]` and doctor prints one
|
|
89
|
+
`WARN codex duplicate route` line per lifecycle with the `enabled = false` fix; nothing is written or switched.
|
|
90
|
+
|
|
8
91
|
## [0.35.18] - 2026-10-12
|
|
9
92
|
|
|
10
93
|
### Fixed
|
package/README.md
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
<!-- holmes-kit:attest:begin -->
|
|
10
10
|

|
|
11
11
|
|
|
12
|
-
**
|
|
13
|
-
Measured at `
|
|
12
|
+
**440/442** source files (99.5%) trace to an approved spec · **774/837** approved A-SPECs (92.4%) are anchored from code.
|
|
13
|
+
Measured at `80944935ee8a` (specs `sha256:2e7481e061f1`) — reproduce with `holmes-kit attest`.
|
|
14
14
|
<!-- holmes-kit:attest:end -->
|
|
15
15
|
|
|
16
16
|
---
|
|
@@ -23,6 +23,7 @@ Measured at `32936217f72e` (specs `sha256:889a6e38d4b1`) — reproduce with `hol
|
|
|
23
23
|
|
|
24
24
|
### 🛡️ Currently Supported Features (Production Features)
|
|
25
25
|
|
|
26
|
+
- **A benchmark run the operator pre-approved finishes with zero human waits — the run delegation** *(new in 0.35.19)*: `holmes-kit autonomy delegate --run <id> --allow <rule[,rule]> [--for 2h] [--limit k=v]… [--rationale <text>]` (same human proof as `autonomy on`) writes a run-scoped, workspace-bound (realpath), expiring delegation that covers a closed set of autonomy-grader rules — root-only or gate-file Files to Touch, an undirected gate-behavior grade, an upstream without A-SPEC; never architecture documents, un-admitted requirements, undeclared or unknown grades. A hitl spec whose only reason is a covered rule seals on its own with `source: 'delegated'` and a ledger row naming the run and the rule; an uncovered case refuses with the named limit (`does not cover`, `expired`, `for <workspace>, not this root`, `invalid document`). `autonomy status`, `approve --status` and the session-start banner show it; `revoke-delegation` or `off` ends it. The host's own approval layer is named as not covered. Measured need: X1 (2026-10-12) stopped a pre-approved fixture on `files-to-touch-root-only`. Every operator hint now also names the workspace (`--target <root>`), a context-only Codex patch is refused as a no-op by name, and `runtime-binding status`/`doctor` report a Codex lifecycle routed to Holmes from both the user-level and the workspace hooks file.
|
|
26
27
|
- **A refusal you cannot see in the inbox is still answerable from its own hint** *(new in 0.35.18)*: six repairs measured in a Codex X1 runtime session and a field report. Every refusal line written to the refusal log ends with `run: holmes-kit approve --grant <id> --target <root>` carrying the actual id, the inbox (`approve --list` / `--watch`) prints a footer counting requests outside the inbox, and the `--refusals` closing line spells the same command (the positional `approve <id>` the first repair wrote is refused by the CLI, so it was measured and rewritten). An autonomy refusal on a parent spec names the child rule that forces the human decision (`upstream-has-human-aspec: <id> — <rule>`). A runtime deadline refusal ends with the per-phase millisecond split, and the Stop hook prints how much of its 18 s budget it used once it passes half. `runtime-binding status` separates `drift` (operator-config / stale-workspace) from `conflicts` and reports whether the router is intact. The `--autonomy` usage, the `init` refusal and the interactive prompt now say the same thing.
|
|
27
28
|
- **An agent is told what to do after an approval, and a patch is judged the way the tool applies it** *(new in 0.35.17)*: five repairs measured on a Codex worker in a SWE-bench comparison. `approval_status` now carries `request { id, state, question?, reason?, ts? }` (pending / held / granted / consumed / denied / revoked, read from the approval queue, with the operator's LATEST hold question) and one `nextAction` sentence — a sealed spec says "stop polling", a held request relays the question; the pending-approval hint ends with an `Agent:` line beside the unchanged operator lines. `test_run` reports `anchorDiagnostics` for an `@implements` list joined by `;`, `|`, `&`, `/` or `and` (the comma grammar does not read them; attribution is unchanged, the omission is named). A Codex `apply_patch` update is applied chunk by chunk from the previous chunk's position, as the tool does, so a context line that recurs earlier in the file no longer makes it "unreadable", and a patch that does not apply is refused by a sentence naming the file and the chunk. A quoted or escaped glob (`rg ".*"`) is no longer read as a spelling of the `.ax` store (an unquoted `.*` still is). The background refresh child records `failure { stage, reason }` on its freshness receipt instead of failing silently.
|
|
28
29
|
- **The analysis names the unchanged files a change has broken** *(new in 0.35.16)*: with `changedFiles` given, `maintenance_analyze` reports under `impacts.removedNameUsers` every unchanged file that imports a changed file and still uses a top-level name that file no longer defines (removed or renamed), and the files still importing a deleted TypeScript/JavaScript file. Deterministic and read-only; TypeScript/JavaScript and Python. Measured on public repositories: every file named was one the commit did change (22 of 22, 21 of 21). It fires rarely — 2–7% of the files an incomplete change set was missing. Member names and changed signatures are not read.
|
package/dist/.build-id
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
c8cb7cb6-mv91ezzh
|
|
@@ -54,6 +54,7 @@ exports.agyCanonicalFile = agyCanonicalFile;
|
|
|
54
54
|
// @implements A-SPEC-708, A-SPEC-707, A-SPEC-202, A-SPEC-250, A-SPEC-341
|
|
55
55
|
// @implements A-SPEC-442
|
|
56
56
|
// @implements A-SPEC-193
|
|
57
|
+
// @implements A-SPEC-769.10
|
|
57
58
|
const agents_guidance_plan_1 = require("./agents-guidance-plan");
|
|
58
59
|
const agents_guidance_1 = require("./agents-guidance");
|
|
59
60
|
const fs = __importStar(require("node:fs"));
|
|
@@ -61,6 +62,7 @@ const os = __importStar(require("node:os"));
|
|
|
61
62
|
const path = __importStar(require("node:path"));
|
|
62
63
|
const node_child_process_1 = require("node:child_process");
|
|
63
64
|
const mcp_launcher_1 = require("./mcp-launcher");
|
|
65
|
+
const hook_process_1 = require("../runtime/hook-process");
|
|
64
66
|
/**
|
|
65
67
|
* 하네스별 배선물.
|
|
66
68
|
*
|
|
@@ -190,11 +192,14 @@ function antigravityHookWarnings(packageRoot) {
|
|
|
190
192
|
}
|
|
191
193
|
return out;
|
|
192
194
|
}
|
|
193
|
-
|
|
195
|
+
// @implements A-SPEC-769.10 — the Stop handler carries the Stop deadline; PreToolUse keeps 30 s.
|
|
196
|
+
const antigravityHookEntry = (packageRoot, script, timeout = 30) => ({
|
|
194
197
|
type: 'command',
|
|
195
198
|
command: antigravityHookCommand(shortPathIfSpaced(path.join(packageRoot, 'bin', script))),
|
|
196
|
-
timeout
|
|
199
|
+
timeout,
|
|
197
200
|
});
|
|
201
|
+
/** Stop handler timeouts a canonical file may carry: the current one and the one init wrote before A-SPEC-769.10. */
|
|
202
|
+
const AGY_STOP_TIMEOUTS = [hook_process_1.STOP_HOOK_TIMEOUT_SECONDS, 30];
|
|
198
203
|
/**
|
|
199
204
|
* @implements A-SPEC-442
|
|
200
205
|
* Codex 훅이 부를 것: **Claude 와 같은 정책 커널**.
|
|
@@ -212,7 +217,7 @@ const hooksJson = (packageRoot) => `${JSON.stringify({
|
|
|
212
217
|
matcher: '*',
|
|
213
218
|
hooks: [antigravityHookEntry(packageRoot, 'holmes-hook-antigravity.js')],
|
|
214
219
|
}],
|
|
215
|
-
Stop: [antigravityHookEntry(packageRoot, 'holmes-stop-antigravity.js')],
|
|
220
|
+
Stop: [antigravityHookEntry(packageRoot, 'holmes-stop-antigravity.js', hook_process_1.STOP_HOOK_TIMEOUT_SECONDS)],
|
|
216
221
|
},
|
|
217
222
|
}, null, 2)}\n`;
|
|
218
223
|
const AGENTS_MD = (_enforced) => (0, agents_guidance_1.renderCommonGuidance)();
|
|
@@ -609,7 +614,7 @@ function agentFiles(agent, opts) {
|
|
|
609
614
|
Stop: [{
|
|
610
615
|
type: 'command',
|
|
611
616
|
command: kernelCommand(packageRoot, 'stop.js'),
|
|
612
|
-
timeout:
|
|
617
|
+
timeout: hook_process_1.STOP_HOOK_TIMEOUT_SECONDS, // A-SPEC-769.10
|
|
613
618
|
}],
|
|
614
619
|
},
|
|
615
620
|
}, null, 2)}\n`,
|
|
@@ -774,8 +779,9 @@ function agyCanonicalFile(parsed, raw) {
|
|
|
774
779
|
return false;
|
|
775
780
|
const keysAre = (o, keys) => plainObject(o) && Object.keys(o).length === keys.length && keys.every((k) => Object.prototype.hasOwnProperty.call(o, k));
|
|
776
781
|
const template = antigravityHookEntry('/x', 'x.js');
|
|
777
|
-
const handler = (h) => keysAre(h, Object.keys(template))
|
|
778
|
-
&& Object.entries(template).every(([k, v]) => (k === 'command' ? typeof h[k] === 'string' && /^node \S+$/.test(h[k])
|
|
782
|
+
const handler = (h, timeouts = [template.timeout]) => keysAre(h, Object.keys(template))
|
|
783
|
+
&& Object.entries(template).every(([k, v]) => (k === 'command' ? typeof h[k] === 'string' && /^node \S+$/.test(h[k])
|
|
784
|
+
: k === 'timeout' ? timeouts.includes(h[k]) : h[k] === v));
|
|
779
785
|
if (!keysAre(parsed, [HOLMES]))
|
|
780
786
|
return false;
|
|
781
787
|
const spec = parsed[HOLMES];
|
|
@@ -789,5 +795,5 @@ function agyCanonicalFile(parsed, raw) {
|
|
|
789
795
|
if (!keysAre(group, ['matcher', 'hooks']) || group.matcher !== '*')
|
|
790
796
|
return false;
|
|
791
797
|
const hooks = group.hooks;
|
|
792
|
-
return Array.isArray(hooks) && hooks.length === 1 && handler(hooks[0]) && handler(stop[0]);
|
|
798
|
+
return Array.isArray(hooks) && hooks.length === 1 && handler(hooks[0]) && handler(stop[0], AGY_STOP_TIMEOUTS);
|
|
793
799
|
}
|
|
@@ -6,9 +6,12 @@ export interface StatusContext {
|
|
|
6
6
|
workspaceId?: string;
|
|
7
7
|
replicaId?: string;
|
|
8
8
|
};
|
|
9
|
+
/** @implements A-SPEC-771 — `run`: an operator-issued run delegation (A-SPEC-771) is on for this workspace. */
|
|
9
10
|
delegation: {
|
|
10
|
-
mode: 'project-default' | 'session' | 'off';
|
|
11
|
+
mode: 'project-default' | 'session' | 'run' | 'off';
|
|
11
12
|
until?: string;
|
|
13
|
+
run?: string;
|
|
14
|
+
covers?: string[];
|
|
12
15
|
};
|
|
13
16
|
/** Nonces that still have a grant file — a granted decision is LIVE only while its file exists. */
|
|
14
17
|
liveGrants: ReadonlySet<string>;
|
|
@@ -75,6 +75,13 @@ function statusContext(root, now = new Date().toISOString()) {
|
|
|
75
75
|
}
|
|
76
76
|
delegation = { mode: 'session', ...(until ? { until } : {}) };
|
|
77
77
|
}
|
|
78
|
+
else {
|
|
79
|
+
// @implements A-SPEC-771 — the run delegation is the third envelope, read the same way the server reads it.
|
|
80
|
+
const { readDelegation } = require('../governance/delegation');
|
|
81
|
+
const s = readDelegation(root, now);
|
|
82
|
+
if (s.active)
|
|
83
|
+
delegation = { mode: 'run', run: s.delegation.run, until: s.delegation.expires, covers: s.delegation.allow };
|
|
84
|
+
}
|
|
78
85
|
}
|
|
79
86
|
catch {
|
|
80
87
|
delegation = { mode: 'off' };
|
|
@@ -124,6 +131,9 @@ function renderStatus(state, ctx, opts) {
|
|
|
124
131
|
lines.push('\u25c6 delegation: autonomous spec approval ON (project default, .mcp.json) \u2014 governance-critical, high-risk and irreversible still ask you');
|
|
125
132
|
else if (ctx.delegation.mode === 'session')
|
|
126
133
|
lines.push(`\u25c6 delegation: autonomous spec approval ON (this session, until ${(0, screen_safe_1.rowField)(ctx.delegation.until ?? '?', 28)}) \u2014 end early: holmes-kit autonomy off`);
|
|
134
|
+
// @implements A-SPEC-771 \u2014 the run delegation names its run, expiry and covered rules; end early with revoke-delegation.
|
|
135
|
+
else if (ctx.delegation.mode === 'run')
|
|
136
|
+
lines.push(`\u25c6 delegation: run ${(0, screen_safe_1.rowField)(ctx.delegation.run ?? '?', 24)} until ${(0, screen_safe_1.rowField)(ctx.delegation.until ?? '?', 28)} \u2014 covers ${(ctx.delegation.covers ?? []).join(', ')} \u2014 end early: holmes-kit autonomy revoke-delegation`);
|
|
127
137
|
else
|
|
128
138
|
lines.push('\u25c6 delegation: autonomous spec approval OFF \u2014 every spec approval is human');
|
|
129
139
|
lines.push('');
|
|
@@ -206,7 +206,7 @@ async function runWatch(root, io, actor, opts = {}) {
|
|
|
206
206
|
io.print(exports.WATCH_IDLE);
|
|
207
207
|
idleAnnounced = true;
|
|
208
208
|
// @implements A-SPEC-770 — once per idle announcement: the refusals this surface does not list, by count.
|
|
209
|
-
const footer = (0, approve_1.outsideInboxFooter)((0, approval_queue_1.refusalsOutsideInbox)(root));
|
|
209
|
+
const footer = (0, approve_1.outsideInboxFooter)((0, approval_queue_1.refusalsOutsideInbox)(root), root); // @implements A-SPEC-770.2
|
|
210
210
|
if (footer !== null)
|
|
211
211
|
io.print(footer);
|
|
212
212
|
}
|
|
@@ -63,11 +63,11 @@ export declare function staleView(flags: Record<string, unknown>): {
|
|
|
63
63
|
* `approve --grant <id>` reach them). A count and two commands — never a target. `null` when there is nothing to say.
|
|
64
64
|
* @implements A-SPEC-770.1 — the grant command is spelled with its flag: a positional id is refused by the CLI.
|
|
65
65
|
*/
|
|
66
|
-
export declare function outsideInboxFooter(outside: number | undefined): string | null;
|
|
66
|
+
export declare function outsideInboxFooter(outside: number | undefined, root?: string): string | null;
|
|
67
67
|
export declare function renderPending(state: QueueState, view?: {
|
|
68
68
|
staleHours: number;
|
|
69
69
|
showAll: boolean;
|
|
70
|
-
}, outside?: number): string;
|
|
70
|
+
}, outside?: number, root?: string): string;
|
|
71
71
|
/**
|
|
72
72
|
* @implements A-SPEC-262.1
|
|
73
73
|
* What a decision line must say. Round-1: `✓ approved — valid until <expires>` named NOTHING, so an index
|
|
@@ -130,7 +130,7 @@ export declare function renderRefusals(refusals: Array<{
|
|
|
130
130
|
target: string;
|
|
131
131
|
why: string;
|
|
132
132
|
ts: string;
|
|
133
|
-
}>, limit?: number): string;
|
|
133
|
+
}>, limit?: number, root?: string): string;
|
|
134
134
|
export declare function renderNonTtyHint(state: QueueState): string;
|
|
135
135
|
export interface ApproveIO {
|
|
136
136
|
print: (s: string) => void;
|
|
@@ -352,16 +352,19 @@ function staleView(flags) {
|
|
|
352
352
|
* `approve --grant <id>` reach them). A count and two commands — never a target. `null` when there is nothing to say.
|
|
353
353
|
* @implements A-SPEC-770.1 — the grant command is spelled with its flag: a positional id is refused by the CLI.
|
|
354
354
|
*/
|
|
355
|
-
function outsideInboxFooter(outside) {
|
|
355
|
+
function outsideInboxFooter(outside, root) {
|
|
356
356
|
if (!outside || outside <= 0)
|
|
357
357
|
return null;
|
|
358
|
+
// @implements A-SPEC-770.2 — the commands name the workspace this screen read, so a line pasted elsewhere resolves
|
|
359
|
+
// the id against the right store (measured 2026-10-13: the hint reached the operator without any `--target`).
|
|
360
|
+
const target = root === undefined ? '' : ` --target ${/\s/.test(root) ? `"${root}"` : root}`;
|
|
358
361
|
// `◆` rather than the `◇` the spec sketched: §13 (approve-corpus) admits only the template's own glyphs on a decision
|
|
359
362
|
// row, and U+25C7 is of ambiguous width while U+25C6 is already furniture of this screen.
|
|
360
|
-
return `◆ ${outside} refusal(s) on this machine are outside this inbox (shell/gate refusals) — list them: ${(0, npx_bin_1.npxBin)()} holmes-kit approve --refusals · grant one: ${(0, npx_bin_1.npxBin)()} holmes-kit approve --grant <id
|
|
363
|
+
return `◆ ${outside} refusal(s) on this machine are outside this inbox (shell/gate refusals) — list them: ${(0, npx_bin_1.npxBin)()} holmes-kit approve --refusals${target} · grant one: ${(0, npx_bin_1.npxBin)()} holmes-kit approve --grant <id>${target}`;
|
|
361
364
|
}
|
|
362
|
-
function renderPending(state, view, outside) {
|
|
365
|
+
function renderPending(state, view, outside, root) {
|
|
363
366
|
const withFooter = (lines) => {
|
|
364
|
-
const footer = outsideInboxFooter(outside);
|
|
367
|
+
const footer = outsideInboxFooter(outside, root);
|
|
365
368
|
return (footer === null ? lines : [...lines, footer]).join('\n');
|
|
366
369
|
};
|
|
367
370
|
if (state.pending.length === 0) {
|
|
@@ -485,7 +488,7 @@ function decisionDetail(p, tail = '') {
|
|
|
485
488
|
* and this renderer is the reason an operator can find the id the deny message named. Row width
|
|
486
489
|
* follows the decision list's screen-safe discipline.
|
|
487
490
|
*/
|
|
488
|
-
function renderRefusals(refusals, limit = 20) {
|
|
491
|
+
function renderRefusals(refusals, limit = 20, root) {
|
|
489
492
|
if (refusals.length === 0)
|
|
490
493
|
return '◆ no refusals recorded on this machine';
|
|
491
494
|
const recent = refusals.slice(-Math.max(1, limit));
|
|
@@ -495,7 +498,9 @@ function renderRefusals(refusals, limit = 20) {
|
|
|
495
498
|
lines.push(` \u2502 ${(0, screen_safe_1.rowField)(r.why, 66)} ${(0, screen_safe_1.rowField)(r.ts, 24)}`);
|
|
496
499
|
}
|
|
497
500
|
// @implements A-SPEC-770.1 — `--grant <id>`: the positional form this line named since 2026-09-06 is refused.
|
|
498
|
-
|
|
501
|
+
// @implements A-SPEC-770.2 — and the workspace whose log this screen read, when the caller knows it.
|
|
502
|
+
const target = root === undefined ? '' : ` --target ${/\s/.test(root) ? `"${root}"` : root}`;
|
|
503
|
+
lines.push('', `decide one: ${(0, npx_bin_1.npxBin)()} holmes-kit approve --grant <id>${target}`);
|
|
499
504
|
return lines.join('\n');
|
|
500
505
|
}
|
|
501
506
|
function renderNonTtyHint(state) {
|
|
@@ -549,7 +554,7 @@ function renderNonTtyHint(state) {
|
|
|
549
554
|
*/
|
|
550
555
|
async function runInteractive(root, io, actor) {
|
|
551
556
|
const state = (0, approval_queue_1.readQueue)(root);
|
|
552
|
-
io.print(renderPending(state, undefined, (0, approval_queue_1.refusalsOutsideInbox)(root))); // @implements A-SPEC-770
|
|
557
|
+
io.print(renderPending(state, undefined, (0, approval_queue_1.refusalsOutsideInbox)(root), root)); // @implements A-SPEC-770, A-SPEC-770.2
|
|
553
558
|
if (state.pending.length === 0)
|
|
554
559
|
return;
|
|
555
560
|
const grantDefault = (p) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Approval } from '../guardrail/risk-gate';
|
|
2
|
-
/** `--for` accepts `2h` / `90m` / a bare number of hours. Minutes, capped at 7 days (like grants);
|
|
2
|
+
/** `--for` accepts `2h` / `90m` / `7d` / a bare number of hours. Minutes, capped at 7 days (like grants);
|
|
3
3
|
* null on a malformed value; default 2h when omitted. */
|
|
4
4
|
export declare function parseForMinutes(s: string | undefined): number | null;
|
|
5
5
|
export interface AutonomyIO {
|
|
@@ -8,15 +8,22 @@ export interface AutonomyIO {
|
|
|
8
8
|
approval?: Approval;
|
|
9
9
|
env?: NodeJS.ProcessEnv;
|
|
10
10
|
}
|
|
11
|
+
/** @implements A-SPEC-771 — the delegation subcommand's own inputs, parsed by the CLI entry and passed through. */
|
|
12
|
+
export interface AutonomyExtra {
|
|
13
|
+
run?: string;
|
|
14
|
+
allow?: string;
|
|
15
|
+
limits?: string[];
|
|
16
|
+
rationale?: string;
|
|
17
|
+
}
|
|
11
18
|
export interface AutonomyResult {
|
|
12
19
|
ok: boolean;
|
|
13
20
|
exitCode: 0 | 1 | 2;
|
|
14
21
|
message: string;
|
|
15
22
|
}
|
|
16
23
|
/**
|
|
17
|
-
* The `holmes-kit autonomy status|on|off` core. Pure over injected io (clock/TTY/approval/
|
|
18
|
-
* every branch is testable. Enabling (`on`)
|
|
19
|
-
* terminal is the human-presence proof, and a non-TTY caller (an agent's Bash) must carry an
|
|
20
|
-
*
|
|
24
|
+
* The `holmes-kit autonomy status|on|off|delegate|revoke-delegation` core. Pure over injected io (clock/TTY/approval/
|
|
25
|
+
* env) so every branch is testable. Enabling (`on`) and delegating are protected exactly like `init --autonomy`: the
|
|
26
|
+
* raw-TTY terminal is the human-presence proof, and a non-TTY caller (an agent's Bash) must carry an out-of-band
|
|
27
|
+
* HOLMES_APPROVAL covering kind `autonomy-grant`. Disabling and revoking are always free.
|
|
21
28
|
*/
|
|
22
|
-
export declare function runAutonomy(root: string, sub: string | undefined, forStr: string | undefined, io: AutonomyIO): AutonomyResult;
|
|
29
|
+
export declare function runAutonomy(root: string, sub: string | undefined, forStr: string | undefined, io: AutonomyIO, extra?: AutonomyExtra): AutonomyResult;
|
|
@@ -35,61 +35,96 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.parseForMinutes = parseForMinutes;
|
|
37
37
|
exports.runAutonomy = runAutonomy;
|
|
38
|
-
// @implements A-SPEC-553.1, A-SPEC-553.2
|
|
38
|
+
// @implements A-SPEC-553.1, A-SPEC-553.2, A-SPEC-771
|
|
39
39
|
const fs = __importStar(require("node:fs"));
|
|
40
40
|
const path = __importStar(require("node:path"));
|
|
41
41
|
const risk_gate_1 = require("../guardrail/risk-gate");
|
|
42
42
|
const autonomy_1 = require("../governance/autonomy");
|
|
43
|
+
const delegation_1 = require("../governance/delegation");
|
|
43
44
|
const PROJECT_DEFAULT_ON = 'autonomous spec approval: ON (project default, .mcp.json) — governance-critical still ask you. '
|
|
44
45
|
+ 'Turn it off by removing HOLMES_AUTONOMOUS_APPROVAL from .mcp.json (or holmes-kit init --no-autonomy).';
|
|
45
46
|
const ledger_store_1 = require("../governance/ledger-store");
|
|
46
47
|
const provenance_chain_1 = require("../governance/provenance-chain");
|
|
47
|
-
/** `--for` accepts `2h` / `90m` / a bare number of hours. Minutes, capped at 7 days (like grants);
|
|
48
|
+
/** `--for` accepts `2h` / `90m` / `7d` / a bare number of hours. Minutes, capped at 7 days (like grants);
|
|
48
49
|
* null on a malformed value; default 2h when omitted. */
|
|
49
50
|
function parseForMinutes(s) {
|
|
50
51
|
if (s === undefined)
|
|
51
52
|
return 120;
|
|
52
|
-
|
|
53
|
+
// @implements A-SPEC-771 — `d` joins `h` and `m` (a run window is days-long); a compound like `7d1m` stays malformed.
|
|
54
|
+
const m = /^\s*(\d+)\s*(h|m|d)?\s*$/.exec(s);
|
|
53
55
|
if (!m)
|
|
54
56
|
return null;
|
|
55
57
|
const n = parseInt(m[1], 10);
|
|
56
58
|
if (!Number.isFinite(n) || n <= 0)
|
|
57
59
|
return null;
|
|
58
|
-
const mins = m[2] === 'm' ? n : n * 60;
|
|
60
|
+
const mins = m[2] === 'm' ? n : m[2] === 'd' ? n * 24 * 60 : n * 60;
|
|
59
61
|
return mins <= 7 * 24 * 60 ? mins : null;
|
|
60
62
|
}
|
|
63
|
+
const DELEGATION_HOST_NOTE = 'host approval layer: not covered (a harness\'s own tool-confirmation stays the host\'s)';
|
|
64
|
+
function delegationStatusLine(root, now) {
|
|
65
|
+
const s = (0, delegation_1.readDelegation)(root, now);
|
|
66
|
+
if (!s.active)
|
|
67
|
+
return null;
|
|
68
|
+
const d = s.delegation;
|
|
69
|
+
const limits = d.limits && Object.keys(d.limits).length ? `; limits ${Object.entries(d.limits).map(([k, v]) => `${k}=${v}`).join(', ')}` : '';
|
|
70
|
+
return `delegation: run ${d.run} until ${d.expires} — covers ${d.allow.join(', ')}${limits}; ${DELEGATION_HOST_NOTE}`;
|
|
71
|
+
}
|
|
72
|
+
function revokeDelegationQuietly(root, io, rationale) {
|
|
73
|
+
let run = '';
|
|
74
|
+
try {
|
|
75
|
+
const s = (0, delegation_1.readDelegation)(root, io.now);
|
|
76
|
+
run = s.active ? s.delegation.run : (s.run ?? '');
|
|
77
|
+
}
|
|
78
|
+
catch { /* best effort */ }
|
|
79
|
+
if (!(0, delegation_1.removeDelegation)(root))
|
|
80
|
+
return;
|
|
81
|
+
try {
|
|
82
|
+
new ledger_store_1.FileLedgerStore(path.join(root, '.ax', 'ledger')).append({
|
|
83
|
+
ts: io.now, actor: io.approval?.actor ?? 'operator', kind: 'autonomy-delegation-revoked',
|
|
84
|
+
summary: `run delegation revoked${run ? ` (run ${run})` : ''}`, rationale,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
catch { /* the document is gone either way */ }
|
|
88
|
+
}
|
|
61
89
|
/**
|
|
62
|
-
* The `holmes-kit autonomy status|on|off` core. Pure over injected io (clock/TTY/approval/
|
|
63
|
-
* every branch is testable. Enabling (`on`)
|
|
64
|
-
* terminal is the human-presence proof, and a non-TTY caller (an agent's Bash) must carry an
|
|
65
|
-
*
|
|
90
|
+
* The `holmes-kit autonomy status|on|off|delegate|revoke-delegation` core. Pure over injected io (clock/TTY/approval/
|
|
91
|
+
* env) so every branch is testable. Enabling (`on`) and delegating are protected exactly like `init --autonomy`: the
|
|
92
|
+
* raw-TTY terminal is the human-presence proof, and a non-TTY caller (an agent's Bash) must carry an out-of-band
|
|
93
|
+
* HOLMES_APPROVAL covering kind `autonomy-grant`. Disabling and revoking are always free.
|
|
66
94
|
*/
|
|
67
|
-
function runAutonomy(root, sub, forStr, io) {
|
|
95
|
+
function runAutonomy(root, sub, forStr, io, extra = {}) {
|
|
68
96
|
const env = io.env ?? process.env;
|
|
69
97
|
const markerPath = path.join(root, ...autonomy_1.SESSION_AUTONOMY_MARKER);
|
|
70
98
|
if (sub === undefined || sub === 'status') {
|
|
99
|
+
// @implements A-SPEC-771 — an active run delegation is reported beside whichever posture is on.
|
|
100
|
+
const delegationLine = delegationStatusLine(root, io.now);
|
|
101
|
+
const withDelegation = (message) => delegationLine === null ? message : `${message}\n${delegationLine}`;
|
|
71
102
|
const envOn = typeof env[autonomy_1.AUTONOMY_ENV] === 'string' && env[autonomy_1.AUTONOMY_ENV] !== '';
|
|
72
103
|
if (envOn)
|
|
73
|
-
return { ok: true, exitCode: 0, message: 'autonomous spec approval: ON (project default, .mcp.json) — governance-critical still ask you' };
|
|
104
|
+
return { ok: true, exitCode: 0, message: withDelegation('autonomous spec approval: ON (project default, .mcp.json) — governance-critical still ask you') };
|
|
74
105
|
// @implements A-SPEC-553.2 — the same project default the server and the session banner read
|
|
75
106
|
// (A-SPEC-560.2). The CLI read only the shell environment, which never carries .mcp.json's env, and
|
|
76
107
|
// answered OFF while the server sealed specs autonomously.
|
|
77
108
|
if ((0, autonomy_1.projectDefaultAutonomy)(root))
|
|
78
|
-
return { ok: true, exitCode: 0, message: PROJECT_DEFAULT_ON };
|
|
109
|
+
return { ok: true, exitCode: 0, message: withDelegation(PROJECT_DEFAULT_ON) };
|
|
79
110
|
if ((0, autonomy_1.sessionAutonomyActive)(root, io.now)) {
|
|
80
111
|
let expires = '';
|
|
81
112
|
try {
|
|
82
113
|
expires = String(JSON.parse(fs.readFileSync(markerPath, 'utf8')).expires);
|
|
83
114
|
}
|
|
84
115
|
catch { /* best effort */ }
|
|
85
|
-
return { ok: true, exitCode: 0, message: `autonomous spec approval: ON (this session, until ${expires}) — governance-critical still ask you` };
|
|
116
|
+
return { ok: true, exitCode: 0, message: withDelegation(`autonomous spec approval: ON (this session, until ${expires}) — governance-critical still ask you`) };
|
|
86
117
|
}
|
|
118
|
+
if (delegationLine !== null)
|
|
119
|
+
return { ok: true, exitCode: 0, message: `autonomous spec approval: ON (run delegation) — ${delegationLine}` };
|
|
87
120
|
return { ok: true, exitCode: 0, message: 'autonomous spec approval: OFF — every spec approval is human (holmes-kit autonomy on to self-drive this session)' };
|
|
88
121
|
}
|
|
89
122
|
if (sub === 'off') {
|
|
90
123
|
// @implements A-SPEC-558.1 — `off` is the emergency de-escalation control; it must fail CLOSED.
|
|
91
124
|
// If the marker cannot be removed it is still ON, so never report OFF: re-check after rmSync and
|
|
92
125
|
// report failure honestly if it survives.
|
|
126
|
+
// @implements A-SPEC-771 — the run delegation goes with it: `off` ends every envelope this CLI issued.
|
|
127
|
+
revokeDelegationQuietly(root, io, 'holmes-kit autonomy off');
|
|
93
128
|
let existed = false;
|
|
94
129
|
let removeError;
|
|
95
130
|
try {
|
|
@@ -128,16 +163,70 @@ function runAutonomy(root, sub, forStr, io) {
|
|
|
128
163
|
}
|
|
129
164
|
return { ok: true, exitCode: 0, message: 'autonomous spec approval: OFF — every spec approval is human again' };
|
|
130
165
|
}
|
|
131
|
-
|
|
166
|
+
// @implements A-SPEC-771 — revoking needs no proof (de-escalation is always free), like `off`.
|
|
167
|
+
if (sub === 'revoke-delegation') {
|
|
168
|
+
const s = (0, delegation_1.readDelegation)(root, io.now);
|
|
169
|
+
const had = s.active || (s.why !== 'none');
|
|
170
|
+
revokeDelegationQuietly(root, io, 'holmes-kit autonomy revoke-delegation');
|
|
171
|
+
return { ok: true, exitCode: 0, message: had ? 'run delegation revoked — hitl specs ask a person again' : 'no run delegation on file' };
|
|
172
|
+
}
|
|
173
|
+
if (sub === 'on' || sub === 'delegate') {
|
|
132
174
|
if (!io.isTTY && !(0, risk_gate_1.approvalCovers)(io.approval, { kind: 'autonomy-grant', target: root }, io.now)) {
|
|
133
|
-
return { ok: false, exitCode: 2, message: 'Enabling session autonomy needs a human: run it at a terminal, or supply an out-of-band approval.\n
|
|
175
|
+
return { ok: false, exitCode: 2, message: `${sub === 'on' ? 'Enabling session autonomy' : 'Issuing a run delegation'} needs a human: run it at a terminal, or supply an out-of-band approval.\n`
|
|
134
176
|
+ `Set HOLMES_APPROVAL='{"actor":"<you>","token":"<any>","rationale":"<why>"}' (scoped approvals need kind "autonomy-grant") and re-run.` };
|
|
135
177
|
}
|
|
136
178
|
const mins = parseForMinutes(forStr);
|
|
137
179
|
if (mins === null)
|
|
138
|
-
return { ok: false, exitCode: 2, message: '--for must look like 2h or
|
|
180
|
+
return { ok: false, exitCode: 2, message: '--for must look like 2h, 90m or 7d (1 minute .. 7 days)' };
|
|
139
181
|
const expires = new Date(Date.parse(io.now) + mins * 60_000).toISOString();
|
|
140
182
|
const grantedBy = io.approval?.actor ?? 'operator(tty)';
|
|
183
|
+
if (sub === 'delegate') {
|
|
184
|
+
// @implements A-SPEC-771 — the document names the run, the resolved workspace, the covered grader rules, the
|
|
185
|
+
// expiry and the declared limits; a NEVER or unknown rule is refused before anything is written.
|
|
186
|
+
const run = extra.run?.trim() ?? '';
|
|
187
|
+
if (!delegation_1.RUN_ID_RE.test(run))
|
|
188
|
+
return { ok: false, exitCode: 2, message: '--run <id> is required: 1..64 characters of letters, digits, dot, underscore or dash' };
|
|
189
|
+
const allow = (extra.allow ?? '').split(',').map((a) => a.trim()).filter((a) => a !== '');
|
|
190
|
+
if (allow.length === 0)
|
|
191
|
+
return { ok: false, exitCode: 2, message: `--allow <rule[,rule]> is required; delegable rules: ${delegation_1.DELEGABLE_RULES.join(', ')}` };
|
|
192
|
+
for (const a of allow) {
|
|
193
|
+
if (delegation_1.NEVER_DELEGABLE.includes(a))
|
|
194
|
+
return { ok: false, exitCode: 1, message: `rule ${a} is never delegable (${delegation_1.NEVER_DELEGABLE.join(', ')} stay the operator's)` };
|
|
195
|
+
if (!delegation_1.DELEGABLE_RULES.includes(a))
|
|
196
|
+
return { ok: false, exitCode: 1, message: `rule ${a} is not a delegable grader rule; delegable: ${delegation_1.DELEGABLE_RULES.join(', ')}` };
|
|
197
|
+
}
|
|
198
|
+
const limits = {};
|
|
199
|
+
for (const kv of extra.limits ?? []) {
|
|
200
|
+
const eq = kv.indexOf('=');
|
|
201
|
+
if (eq <= 0)
|
|
202
|
+
return { ok: false, exitCode: 2, message: `--limit expects key=value, received: ${kv}` };
|
|
203
|
+
limits[kv.slice(0, eq).trim()] = kv.slice(eq + 1).trim();
|
|
204
|
+
}
|
|
205
|
+
let workspace;
|
|
206
|
+
try {
|
|
207
|
+
workspace = fs.realpathSync.native(root);
|
|
208
|
+
}
|
|
209
|
+
catch (e) {
|
|
210
|
+
return { ok: false, exitCode: 1, message: `the workspace root cannot be resolved: ${e instanceof Error ? e.message : String(e)}` };
|
|
211
|
+
}
|
|
212
|
+
try {
|
|
213
|
+
(0, delegation_1.writeDelegation)(root, { schema: delegation_1.DELEGATION_SCHEMA, run, workspace, allow, issuedAt: io.now, expires, issuedBy: grantedBy,
|
|
214
|
+
...(Object.keys(limits).length ? { limits } : {}), ...(extra.rationale ? { rationale: extra.rationale } : {}) });
|
|
215
|
+
}
|
|
216
|
+
catch (e) {
|
|
217
|
+
return { ok: false, exitCode: 1, message: `could not write the run delegation: ${e instanceof Error ? e.message : String(e)}` };
|
|
218
|
+
}
|
|
219
|
+
try {
|
|
220
|
+
new ledger_store_1.FileLedgerStore(path.join(root, '.ax', 'ledger')).append({
|
|
221
|
+
ts: io.now, actor: grantedBy, kind: 'autonomy-delegated', summary: `run delegation ${run} until ${expires}`,
|
|
222
|
+
rationale: `covers ${allow.join(', ')}${Object.keys(limits).length ? `; limits ${Object.entries(limits).map(([k, v]) => `${k}=${v}`).join(', ')}` : ''}${extra.rationale ? ` — ${extra.rationale}` : ''}`,
|
|
223
|
+
...(io.approval ? { authorization: (0, provenance_chain_1.authorizationRef)(io.approval.actor, io.approval.token) } : {}),
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
catch { /* the document IS the record; the ledger entry is additive */ }
|
|
227
|
+
return { ok: true, exitCode: 0, message: `run delegation: run ${run} until ${expires} — covers ${allow.join(', ')} in ${workspace}.\n`
|
|
228
|
+
+ `Hitl specs whose only reason is a covered rule seal on their own and the ledger names the run and the rule; ${DELEGATION_HOST_NOTE}. End early: holmes-kit autonomy revoke-delegation.` };
|
|
229
|
+
}
|
|
141
230
|
try {
|
|
142
231
|
fs.mkdirSync(path.dirname(markerPath), { recursive: true });
|
|
143
232
|
fs.writeFileSync(markerPath, JSON.stringify({ enabled: true, expires, grantedBy, rationale: `session autonomy for ${mins}m` }, null, 2) + '\n');
|
|
@@ -155,5 +244,5 @@ function runAutonomy(root, sub, forStr, io) {
|
|
|
155
244
|
return { ok: true, exitCode: 0, message: `autonomous spec approval: ON for this session, until ${expires}.\n`
|
|
156
245
|
+ 'Low-risk specs self-approve; governance-critical, high-risk and irreversible still ask you. End early: holmes-kit autonomy off.' };
|
|
157
246
|
}
|
|
158
|
-
return { ok: false, exitCode: 2, message: 'usage: holmes-kit autonomy [status|on [--for 2h]|off]' };
|
|
247
|
+
return { ok: false, exitCode: 2, message: 'usage: holmes-kit autonomy [status|on [--for 2h]|off|delegate --run <id> --allow <rule[,rule]> [--for 2h] [--limit k=v]… [--rationale <text>]|revoke-delegation]' };
|
|
159
248
|
}
|
|
@@ -45,12 +45,14 @@ exports.hasHolmesCodexHooks = hasHolmesCodexHooks;
|
|
|
45
45
|
exports.inspectCodexUserHooks = inspectCodexUserHooks;
|
|
46
46
|
exports.codexKernelScripts = codexKernelScripts;
|
|
47
47
|
// @implements A-SPEC-727
|
|
48
|
+
// @implements A-SPEC-769.10
|
|
48
49
|
// codex-cli 0.155 removed plugin hooks (`plugin_hooks: removed`, measured 2026-09-23), so the Holmes
|
|
49
50
|
// gate reaches Codex only through a hooks file Codex loads for every workspace: the user-level
|
|
50
51
|
// `$CODEX_HOME/hooks.json`. Codex runs a non-managed hook only after the user trusts its exact
|
|
51
52
|
// definition (`/hooks`); Holmes never writes that trust — it wires the file and says so.
|
|
52
53
|
const os = __importStar(require("node:os"));
|
|
53
54
|
const path = __importStar(require("node:path"));
|
|
55
|
+
const hook_process_1 = require("../runtime/hook-process");
|
|
54
56
|
/** `$CODEX_HOME/hooks.json`, else `<home>/.codex/hooks.json`. Injectable for deterministic tests. */
|
|
55
57
|
function defaultCodexHooksPath(env = process.env, home = os.homedir()) {
|
|
56
58
|
return path.join(env.CODEX_HOME || path.join(home, '.codex'), 'hooks.json');
|
|
@@ -636,7 +638,7 @@ function withoutHolmes(hooks) {
|
|
|
636
638
|
const render = (doc) => `${JSON.stringify(doc, null, 2)}\n`;
|
|
637
639
|
const shippedGroup = (event, packageRoot) => event === 'PreToolUse'
|
|
638
640
|
? { matcher: '.*', hooks: [{ type: 'command', command: kernelCommand(packageRoot, 'pre-tool-use.js'), timeout: 30 }] }
|
|
639
|
-
: { hooks: [{ type: 'command', command: kernelCommand(packageRoot, 'stop.js'), timeout:
|
|
641
|
+
: { hooks: [{ type: 'command', command: kernelCommand(packageRoot, 'stop.js'), timeout: hook_process_1.STOP_HOOK_TIMEOUT_SECONDS }] }; // A-SPEC-769.10
|
|
640
642
|
/**
|
|
641
643
|
* One Holmes PreToolUse and one Holmes Stop group, IN PLACE. Codex keys trust by (file, event, group
|
|
642
644
|
* index, hook index) plus a hash of the definition, so the first Holmes-only group of an event is
|
|
@@ -710,7 +710,8 @@ async function runDoctor(packageRoot, target, opts, extraChecks) {
|
|
|
710
710
|
let routed;
|
|
711
711
|
if (fs.existsSync(runtimeRegistry)) {
|
|
712
712
|
try {
|
|
713
|
-
|
|
713
|
+
// @implements A-SPEC-769.8 — the Codex home the duplicate-route check reads is the one doctor was pointed at.
|
|
714
|
+
const report = (0, runtime_binding_1.runtimeBindingStatus)(runtimeRegistry, target ?? process.cwd(), { codexHome: opts?.codexConfigPath ? path.dirname(opts.codexConfigPath) : undefined });
|
|
714
715
|
const s = report.selection;
|
|
715
716
|
// @implements A-SPEC-769.6 — the identity is the ROUTER's: conferred when the receipt rows under the registry
|
|
716
717
|
// directory are intact, whatever a settings or workspace wiring row says (those are reported on their own rows
|
|
@@ -751,6 +752,11 @@ async function runDoctor(packageRoot, target, opts, extraChecks) {
|
|
|
751
752
|
+ (report.conflicts.length ? `; ${report.conflicts.join('; ')}` : '')
|
|
752
753
|
+ (changedSinceInstall.length ? `; changed since installation (operator-owned, still routed): ${changedSinceInstall.join(', ')}` : '')
|
|
753
754
|
+ (staleRows.length ? `; stale receipt rows (workspace gone): ${staleRows.join(', ')}` : ''), 'Use runtime-binding status and setup --dry-run to inspect routed wiring. Native hook trust and enable state remain operator-controlled.');
|
|
755
|
+
// @implements A-SPEC-769.8 — one WARN per Codex lifecycle routed to Holmes from both the user-level and the
|
|
756
|
+
// workspace hooks file (measured 2026-10-12: the Stop hook ran twice per session end in both X1 fixtures).
|
|
757
|
+
for (const d of report.duplicateRoutes ?? []) {
|
|
758
|
+
add('codex duplicate route', 'WARN', `${d.event} is routed to Holmes from ${d.files[0]} and ${d.files[1]}; Codex runs both, so the ${d.event} hook runs twice per lifecycle (for stop: the Stop scan twice per session end)`, d.fix);
|
|
759
|
+
}
|
|
754
760
|
// @implements A-SPEC-751.4 — a source checkout whose sessions are routed to another package: say whether the
|
|
755
761
|
// hooks it builds are the hooks those sessions run. A consumer project holds no package source and gets no row.
|
|
756
762
|
const checkoutRoot = [target ?? process.cwd(), packageRoot].find((candidate) => {
|