@holmes-lab/holmes-kit 0.30.0 → 0.31.1
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 +505 -0
- package/README.md +10 -1
- package/bin/holmes-hook-antigravity.js +4 -0
- package/bin/holmes-kit.js +4 -0
- package/bin/holmes-pre-push.js +3 -0
- package/bin/holmes-stop-antigravity.js +4 -0
- package/dist/.build-id +1 -1
- package/dist/holmes/cli/agents.d.ts +41 -0
- package/dist/holmes/cli/agents.js +382 -2
- package/dist/holmes/cli/attest.d.ts +2 -0
- package/dist/holmes/cli/attest.js +66 -15
- package/dist/holmes/cli/ci-gate.js +16 -1
- package/dist/holmes/cli/claude-switches.d.ts +95 -0
- package/dist/holmes/cli/claude-switches.js +967 -0
- package/dist/holmes/cli/codex-hooks.d.ts +77 -0
- package/dist/holmes/cli/codex-hooks.js +802 -0
- package/dist/holmes/cli/codex-oracle.d.ts +194 -0
- package/dist/holmes/cli/codex-oracle.js +1245 -0
- package/dist/holmes/cli/codex-toml.d.ts +35 -0
- package/dist/holmes/cli/codex-toml.js +321 -52
- package/dist/holmes/cli/doctor.d.ts +98 -8
- package/dist/holmes/cli/doctor.js +1328 -94
- package/dist/holmes/cli/index.js +26 -11
- package/dist/holmes/cli/init.d.ts +11 -0
- package/dist/holmes/cli/init.js +736 -44
- package/dist/holmes/cli/mcp-launcher.d.ts +64 -6
- package/dist/holmes/cli/mcp-launcher.js +189 -6
- package/dist/holmes/cli/mcp-version.js +13 -2
- package/dist/holmes/cli/settings-merge.js +8 -2
- package/dist/holmes/cli/upgrade.d.ts +18 -0
- package/dist/holmes/cli/upgrade.js +129 -24
- package/dist/holmes/cli/workspace-scope.d.ts +22 -0
- package/dist/holmes/cli/workspace-scope.js +375 -0
- package/dist/holmes/cpg/cpg-scanner.d.ts +29 -0
- package/dist/holmes/cpg/cpg-scanner.js +403 -3
- package/dist/holmes/cpg/cycle-detect.js +2 -1
- package/dist/holmes/cpg/forbidden-edges.js +9 -2
- package/dist/holmes/cpg/required-calls.js +8 -1
- package/dist/holmes/governance/constitution-debt.js +3 -2
- package/dist/holmes/governance/constitution.js +15 -3
- package/dist/holmes/governance/provenance-chain.js +3 -2
- package/dist/holmes/governance/push-gate-runner.js +4 -3
- package/dist/holmes/guardrail/dependency-delta.js +4 -3
- package/dist/holmes/guardrail/linear-match.d.ts +57 -0
- package/dist/holmes/guardrail/linear-match.js +256 -0
- package/dist/holmes/guardrail/risk-classifier.d.ts +6 -7
- package/dist/holmes/guardrail/risk-classifier.js +931 -44
- package/dist/holmes/guardrail/risk-types.d.ts +6 -0
- package/dist/holmes/guardrail/scope-judgment.d.ts +4 -24
- package/dist/holmes/guardrail/scope-judgment.js +100 -23
- package/dist/holmes/guardrail/shell-words.d.ts +42 -0
- package/dist/holmes/guardrail/shell-words.js +1720 -0
- package/dist/holmes/guardrail/write-target.d.ts +168 -3
- package/dist/holmes/guardrail/write-target.js +2379 -87
- package/dist/holmes/hooks/adapters/antigravity.d.ts +3 -1
- package/dist/holmes/hooks/adapters/antigravity.js +115 -11
- package/dist/holmes/hooks/pre-tool-use.d.ts +32 -6
- package/dist/holmes/hooks/pre-tool-use.js +923 -87
- package/dist/holmes/hooks/rtm-refresh-child.js +3 -1
- package/dist/holmes/hooks/rtm-refresh.js +8 -4
- package/dist/holmes/hooks/session-start.d.ts +10 -0
- package/dist/holmes/hooks/session-start.js +31 -7
- package/dist/holmes/hooks/stop.d.ts +2 -1
- package/dist/holmes/hooks/stop.js +197 -91
- package/dist/holmes/mcp/approval-commit.d.ts +5 -6
- package/dist/holmes/mcp/approval-commit.js +18 -2
- package/dist/holmes/mcp/elicit-approval.js +4 -2
- package/dist/holmes/mcp/handlers/graph-operations.js +3 -2
- package/dist/holmes/mcp/handlers/maintenance-analysis.js +11 -5
- package/dist/holmes/mcp/handlers/maintenance-evidence.js +3 -2
- package/dist/holmes/mcp/handlers/phase-queries.d.ts +22 -7
- package/dist/holmes/mcp/handlers/phase-queries.js +81 -2
- package/dist/holmes/mcp/handlers/requirement-triage.js +5 -3
- package/dist/holmes/mcp/handlers/review-evidence.js +8 -2
- package/dist/holmes/mcp/handlers/slice-orchestration.d.ts +11 -0
- package/dist/holmes/mcp/handlers/slice-orchestration.js +115 -16
- package/dist/holmes/mcp/handlers/spec-approval.d.ts +9 -0
- package/dist/holmes/mcp/handlers/spec-approval.js +110 -17
- package/dist/holmes/mcp/handlers/spec-authoring.js +17 -2
- package/dist/holmes/mcp/handlers/spec-queries.d.ts +39 -3
- package/dist/holmes/mcp/handlers/spec-queries.js +114 -7
- package/dist/holmes/mcp/handlers/test-execution.js +9 -3
- package/dist/holmes/mcp/handlers.d.ts +81 -9
- package/dist/holmes/mcp/handlers.js +70 -23
- package/dist/holmes/mcp/harness-attestation.d.ts +20 -0
- package/dist/holmes/mcp/harness-attestation.js +179 -0
- package/dist/holmes/mcp/requirement-triage-evidence.d.ts +36 -0
- package/dist/holmes/mcp/requirement-triage-evidence.js +160 -4
- package/dist/holmes/mcp/server.js +20 -1
- package/dist/holmes/mcp/tool-schemas.js +26 -9
- package/dist/holmes/mcp/validate-args.js +12 -0
- package/dist/holmes/project/bounded-io.d.ts +102 -0
- package/dist/holmes/project/bounded-io.js +212 -0
- package/dist/holmes/project/change-source.js +3 -1
- package/dist/holmes/project/ci-runs.js +3 -2
- package/dist/holmes/project/ignore.d.ts +31 -2
- package/dist/holmes/project/ignore.js +409 -50
- package/dist/holmes/project/regular-file-guard.d.ts +13 -0
- package/dist/holmes/project/regular-file-guard.js +149 -0
- package/dist/holmes/project/root.js +12 -3
- package/dist/holmes/reverse/anchor.js +4 -3
- package/dist/holmes/reverse/scan.js +6 -2
- package/dist/holmes/review/commit-text.js +3 -2
- package/dist/holmes/review/condition-hunk-replay.js +3 -2
- package/dist/holmes/review/failed-test-names.js +13 -10
- package/dist/holmes/review/findings.js +3 -1
- package/dist/holmes/review/kills-check.js +6 -1
- package/dist/holmes/review/point-in-time-replay.js +5 -4
- package/dist/holmes/review/replay-corpus.js +5 -4
- package/dist/holmes/review/run-replay.js +3 -2
- package/dist/holmes/review/temporal-prior.js +3 -2
- package/dist/holmes/review/test-evidence.js +3 -2
- package/dist/holmes/review/test-outcomes.js +3 -2
- package/dist/holmes/review/test-runner.d.ts +6 -0
- package/dist/holmes/review/test-runner.js +36 -15
- package/dist/holmes/rtm/advisory-outcomes.js +3 -2
- package/dist/holmes/rtm/anchor-ids.js +42 -2
- package/dist/holmes/rtm/file-anchors.js +4 -1
- package/dist/holmes/rtm/ftt-fulfilment.js +8 -3
- package/dist/holmes/rtm/git-changes.js +3 -1
- package/dist/holmes/rtm/graph-store.js +3 -2
- package/dist/holmes/rtm/test-scope.js +9 -4
- package/dist/holmes/spec/compat-impact.d.ts +25 -4
- package/dist/holmes/spec/compat-impact.js +682 -11
- package/dist/holmes/spec/entity-git-snapshot.js +3 -2
- package/dist/holmes/spec/entity-integration.js +3 -2
- package/dist/holmes/spec/entity-renumber-transaction.d.ts +19 -0
- package/dist/holmes/spec/entity-renumber-transaction.js +79 -6
- package/dist/holmes/spec/remote-spec-refs.js +3 -2
- package/dist/holmes/spec/renumber.js +25 -10
- package/dist/holmes/spec/spec-parser.js +9 -3
- package/dist/holmes/spec/yaml-scalar.js +2 -2
- package/dist/holmes/update/refresh.d.ts +5 -0
- package/dist/holmes/update/refresh.js +26 -1
- package/dist/holmes/update/update-notice.d.ts +6 -0
- package/dist/holmes/update/update-notice.js +18 -1
- package/dist/holmes/update/upgrade-plan.d.ts +28 -0
- package/dist/holmes/update/upgrade-plan.js +31 -2
- package/package.json +11 -4
package/bin/holmes-pre-push.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// @implements A-SPEC-509.1
|
|
3
|
+
// @implements A-SPEC-734
|
|
3
4
|
// HOLMES-KIT PUSH GATE v1 — thin stdin adapter over dist/holmes/governance/push-gate-runner.js.
|
|
4
5
|
// Fail-open by contract (H-SPEC-509): this gate safens the default, it is not a security
|
|
5
6
|
// boundary, so any load or collection failure lets the push proceed.
|
|
6
7
|
try {
|
|
8
|
+
// A-SPEC-734 (round 14): no product process blocks on a file that is not a regular file.
|
|
9
|
+
require('../dist/holmes/project/regular-file-guard.js').installProcessGuards();
|
|
7
10
|
const { runPrePush } = require('../dist/holmes/governance/push-gate-runner.js');
|
|
8
11
|
let text = '';
|
|
9
12
|
process.stdin.setEncoding('utf8');
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// @implements A-SPEC-193
|
|
3
|
+
// @implements A-SPEC-734
|
|
3
4
|
// Antigravity Stop 진입점 — 번역만 한다. 판정은 dist 의 Stop 훅이 내린다.
|
|
4
5
|
//
|
|
5
6
|
// PreToolUse 와 달리 여기서는 실패가 **열어 준다**. Stop 훅은 이미 fail-open 계약이다: 턴을
|
|
@@ -20,6 +21,9 @@ let buf = '';
|
|
|
20
21
|
process.stdin.on('data', (c) => { buf += c; });
|
|
21
22
|
process.stdin.on('end', () => {
|
|
22
23
|
try {
|
|
24
|
+
// A-SPEC-734 (round 13): the adapters run in this process, so the guard is installed here — a FIFO in the
|
|
25
|
+
// workspace must never hold this hook (the other harnesses' hook processes install it themselves).
|
|
26
|
+
require(path.join(__dirname, '..', 'dist', 'holmes', 'project', 'regular-file-guard.js')).installProcessGuards();
|
|
23
27
|
const { adaptStop } = require(entry);
|
|
24
28
|
process.stdout.write(JSON.stringify(adaptStop(buf, process.cwd())));
|
|
25
29
|
} catch (e) {
|
package/dist/.build-id
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
019ba709-mumrfxed
|
|
@@ -44,6 +44,8 @@ export interface AgentWiringOptions {
|
|
|
44
44
|
packageRoot: string;
|
|
45
45
|
specsDir: string;
|
|
46
46
|
launcher?: LauncherMode;
|
|
47
|
+
/** A-SPEC-251.1 (round 27): `false` (`--no-mcp`) leaves the MCP registration out (Antigravity's was written anyway). */
|
|
48
|
+
mcp?: boolean;
|
|
47
49
|
}
|
|
48
50
|
export interface AgentFile {
|
|
49
51
|
path: string;
|
|
@@ -69,6 +71,13 @@ export declare function shortPathIfSpaced(p: string): string;
|
|
|
69
71
|
* these INSTEAD of "the gate is enforced". Empty when every path is space-free (posix without a
|
|
70
72
|
* space, or win32 where 8.3 resolved it).
|
|
71
73
|
*/
|
|
74
|
+
/**
|
|
75
|
+
* @implements A-SPEC-251.2 (round 45) — a script path agy's launcher passes on literally: agy runs `command` through `sh -c` on
|
|
76
|
+
* Unix and `cmd /c` on Windows (its embedded hooks.json documentation), so a path holding a character either shell reads —
|
|
77
|
+
* `'`, `(`, `&`, `$`, `;`, quotes, `%`, a leading `~` — does not run as written (`inst'q` was an sh syntax error, `R&D` two
|
|
78
|
+
* commands — measured).
|
|
79
|
+
*/
|
|
80
|
+
export declare const AGY_LITERAL_PATH: RegExp;
|
|
72
81
|
export declare function antigravityHookWarnings(packageRoot: string): string[];
|
|
73
82
|
export declare const AGENTS_MD: (_enforced: boolean) => string;
|
|
74
83
|
export { MANAGED_BEGIN, MANAGED_END } from './agents-guidance-plan';
|
|
@@ -111,6 +120,25 @@ export interface WiringMerge {
|
|
|
111
120
|
* all — is kept. Turning someone's switch back on without a word is the surprise this prevents.
|
|
112
121
|
*/
|
|
113
122
|
export declare function mergeMcpConfigJson(before: string | null, ours: string): WiringMerge;
|
|
123
|
+
export declare function agyHooksFileProblem(raw: string, parsed: unknown): string | null;
|
|
124
|
+
/**
|
|
125
|
+
* @implements A-SPEC-251.2 (round 46) — the user-level hooks file agy shares between its TUI and its backend
|
|
126
|
+
* (`~/.gemini/config/hooks.json`, agy's changelog; `/hooks` writes `"enabled": false` there). agy merges named hooks from
|
|
127
|
+
* every source by name, and the last source that sets `enabled` decides it: a `holmes-kit` entry switched off there switches
|
|
128
|
+
* the workspace gate off (read from the binary — not run).
|
|
129
|
+
*/
|
|
130
|
+
/** The largest hooks file read (round 47). */
|
|
131
|
+
export declare const AGY_HOOKS_MAX_BYTES: number;
|
|
132
|
+
/**
|
|
133
|
+
* @implements A-SPEC-251.2 (round 50) — agy's home: `USERPROFILE` on Windows (Go's `os.UserHomeDir`; Git Bash can set `HOME` to
|
|
134
|
+
* another drive — code reading, not measured on Windows), `HOME` elsewhere.
|
|
135
|
+
*/
|
|
136
|
+
export declare function agyHome(platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv): string;
|
|
137
|
+
export declare function agyUserHooksPath(home?: string): string;
|
|
138
|
+
export declare function agyUserSwitch(file?: string): {
|
|
139
|
+
off: boolean;
|
|
140
|
+
unconfirmed: string | null;
|
|
141
|
+
};
|
|
114
142
|
/** `.agents/hooks.json`. Top-level keys are tool namespaces; only ours is replaced. */
|
|
115
143
|
export declare function mergeHooksJson(before: string | null, ours: string): WiringMerge;
|
|
116
144
|
/**
|
|
@@ -136,3 +164,16 @@ export interface AgentLink {
|
|
|
136
164
|
* 지나간다(A-SPEC-193 §7 이 그 담장을 '타깃 밖만'으로 좁힌 이유이기도 하다).
|
|
137
165
|
*/
|
|
138
166
|
export declare function agentLinks(agent: Agent, opts: AgentWiringOptions): AgentLink[];
|
|
167
|
+
export declare function agyOtherHooksFiles(target: string, cut?: {
|
|
168
|
+
short: boolean;
|
|
169
|
+
}): string[];
|
|
170
|
+
/** The first switch among the user-level file and the other workspace roots: off, or not confirmed. */
|
|
171
|
+
export declare function agySwitches(target: string, userFile?: string): {
|
|
172
|
+
offIn: string | null;
|
|
173
|
+
unconfirmed: string | null;
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* `raw` (round 48): the text itself must be the parsed object written out again — parsing keeps only the last of two equal keys,
|
|
177
|
+
* so `"timeout": "10", "timeout": 30` and a first `"holmes-kit": {"enabled": false}` read as init's file (measured).
|
|
178
|
+
*/
|
|
179
|
+
export declare function agyCanonicalFile(parsed: unknown, raw?: string): boolean;
|
|
@@ -33,22 +33,31 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.MANAGED_END = exports.MANAGED_BEGIN = exports.AGENTS_MD = exports.CODEX_MARKETPLACE = exports.CODEX_PLUGIN_DIR = exports.HARNESS_ENFORCES = exports.AGENTS = void 0;
|
|
36
|
+
exports.AGY_HOOKS_MAX_BYTES = exports.MANAGED_END = exports.MANAGED_BEGIN = exports.AGENTS_MD = exports.AGY_LITERAL_PATH = exports.CODEX_MARKETPLACE = exports.CODEX_PLUGIN_DIR = exports.HARNESS_ENFORCES = exports.AGENTS = void 0;
|
|
37
37
|
exports.antigravityHookCommand = antigravityHookCommand;
|
|
38
38
|
exports.shortPathIfSpaced = shortPathIfSpaced;
|
|
39
39
|
exports.antigravityHookWarnings = antigravityHookWarnings;
|
|
40
40
|
exports.mergeAgentsMd = mergeAgentsMd;
|
|
41
41
|
exports.mergeMcpConfigJson = mergeMcpConfigJson;
|
|
42
|
+
exports.agyHooksFileProblem = agyHooksFileProblem;
|
|
43
|
+
exports.agyHome = agyHome;
|
|
44
|
+
exports.agyUserHooksPath = agyUserHooksPath;
|
|
45
|
+
exports.agyUserSwitch = agyUserSwitch;
|
|
42
46
|
exports.mergeHooksJson = mergeHooksJson;
|
|
43
47
|
exports.mergeMarketplaceJson = mergeMarketplaceJson;
|
|
44
48
|
exports.mergeWiringFile = mergeWiringFile;
|
|
45
49
|
exports.agentFiles = agentFiles;
|
|
46
50
|
exports.agentLinks = agentLinks;
|
|
51
|
+
exports.agyOtherHooksFiles = agyOtherHooksFiles;
|
|
52
|
+
exports.agySwitches = agySwitches;
|
|
53
|
+
exports.agyCanonicalFile = agyCanonicalFile;
|
|
47
54
|
// @implements A-SPEC-708, A-SPEC-707, A-SPEC-202, A-SPEC-250, A-SPEC-341
|
|
48
55
|
// @implements A-SPEC-442
|
|
49
56
|
// @implements A-SPEC-193
|
|
50
57
|
const agents_guidance_plan_1 = require("./agents-guidance-plan");
|
|
51
58
|
const agents_guidance_1 = require("./agents-guidance");
|
|
59
|
+
const fs = __importStar(require("node:fs"));
|
|
60
|
+
const os = __importStar(require("node:os"));
|
|
52
61
|
const path = __importStar(require("node:path"));
|
|
53
62
|
const node_child_process_1 = require("node:child_process");
|
|
54
63
|
const mcp_launcher_1 = require("./mcp-launcher");
|
|
@@ -160,10 +169,21 @@ function shortPathIfSpaced(p) {
|
|
|
160
169
|
* these INSTEAD of "the gate is enforced". Empty when every path is space-free (posix without a
|
|
161
170
|
* space, or win32 where 8.3 resolved it).
|
|
162
171
|
*/
|
|
172
|
+
/**
|
|
173
|
+
* @implements A-SPEC-251.2 (round 45) — a script path agy's launcher passes on literally: agy runs `command` through `sh -c` on
|
|
174
|
+
* Unix and `cmd /c` on Windows (its embedded hooks.json documentation), so a path holding a character either shell reads —
|
|
175
|
+
* `'`, `(`, `&`, `$`, `;`, quotes, `%`, a leading `~` — does not run as written (`inst'q` was an sh syntax error, `R&D` two
|
|
176
|
+
* commands — measured).
|
|
177
|
+
*/
|
|
178
|
+
exports.AGY_LITERAL_PATH = /^(?!~)[A-Za-z0-9_\-./:@+,=~\u0080-\uffff]+$/;
|
|
163
179
|
function antigravityHookWarnings(packageRoot) {
|
|
164
180
|
const out = [];
|
|
165
181
|
for (const script of ['holmes-hook-antigravity.js', 'holmes-stop-antigravity.js']) {
|
|
166
182
|
const final = shortPathIfSpaced(path.join(packageRoot, 'bin', script));
|
|
183
|
+
if (!/\s/.test(final) && !exports.AGY_LITERAL_PATH.test(final.replace(/\\/g, '/'))) {
|
|
184
|
+
out.push(`antigravity: the hook path holds a character agy's shell reads (${final.replace(/\\/g, '/')}) — agy runs the hook command through sh -c (cmd /c on Windows), so this hook does not run as written and the gate is NOT enforced. Install holmes-kit in a path of letters, digits and - _ . / : @ + , = only.`);
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
167
187
|
if (!/\s/.test(final))
|
|
168
188
|
continue;
|
|
169
189
|
out.push(`antigravity: the hook path still contains a space (${final.replace(/\\/g, '/')}) — agy's launcher splits the command on whitespace, so this hook never runs and the gate is NOT enforced. Install holmes-kit in a path without spaces${process.platform === 'win32' ? ' (or enable NTFS 8.3 names on this volume)' : ''}.`);
|
|
@@ -258,6 +278,213 @@ function mergeMcpConfigJson(before, ours) {
|
|
|
258
278
|
notes,
|
|
259
279
|
};
|
|
260
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* @implements A-SPEC-251.2 (round 46) — agy's hooks file as agy's parser reads it (the agy binary of 2026-09-25: `ParseHooks`
|
|
283
|
+
* validates every named hook and, on any error, loads nothing from the file — "Failed to parse hooks file"; field names match
|
|
284
|
+
* case-insensitively, the last one wins). A file outside the documented shape is reported, not guessed: a sibling's
|
|
285
|
+
* `"timeout": "10"` makes agy drop the whole file (Holmes's entry with it) while doctor read PASS and init said "enforced", and
|
|
286
|
+
* `"ENABLED": false` switched the entry off past round 45's rule (the wave-46 reviewer's emulation of agy's decoder).
|
|
287
|
+
*/
|
|
288
|
+
// Round 47: `SessionStart` too — agy's parser reads and validates it (its binary: "JSON session-start hook"), its documentation omits it.
|
|
289
|
+
const AGY_SPEC_FIELDS = ['enabled', 'PreToolUse', 'PostToolUse', 'PreInvocation', 'PostInvocation', 'Stop', 'SessionStart'];
|
|
290
|
+
const AGY_GROUP_FIELDS = ['matcher', 'hooks'];
|
|
291
|
+
const AGY_HANDLER_FIELDS = ['type', 'command', 'timeout', 'prompt', 'model'];
|
|
292
|
+
/** Go's case-insensitive name match, widened (dashes and underscores ignored too): a wider fold only reports more. */
|
|
293
|
+
const agyFold = (k) => k.toUpperCase().toLowerCase().replace(/[-_]/g, '');
|
|
294
|
+
const plainObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
295
|
+
const quoted = (s) => JSON.stringify(s.length > 40 ? `${s.slice(0, 40)}…` : s);
|
|
296
|
+
/** The fields agy reads from `o`, or the first key whose spelling differs from the field agy reads it as. */
|
|
297
|
+
function agyFieldsOf(o, fields, where) {
|
|
298
|
+
const byFold = new Map(fields.map((f) => [agyFold(f), f]));
|
|
299
|
+
const values = new Map();
|
|
300
|
+
for (const k of Object.keys(o)) {
|
|
301
|
+
const exact = byFold.get(agyFold(k));
|
|
302
|
+
if (exact === undefined)
|
|
303
|
+
continue;
|
|
304
|
+
if (k !== exact)
|
|
305
|
+
return { values, problem: `${where} has ${quoted(k)}, which agy reads as "${exact}" (it matches field names case-insensitively)` };
|
|
306
|
+
values.set(exact, o[k]);
|
|
307
|
+
}
|
|
308
|
+
return { values, problem: null };
|
|
309
|
+
}
|
|
310
|
+
function agyHandlerProblem(h, where) {
|
|
311
|
+
if (!plainObject(h))
|
|
312
|
+
return `${where} is not a handler object`;
|
|
313
|
+
const { values, problem } = agyFieldsOf(h, AGY_HANDLER_FIELDS, where);
|
|
314
|
+
if (problem !== null)
|
|
315
|
+
return problem;
|
|
316
|
+
const type = values.get('type');
|
|
317
|
+
if (type === 'prompt')
|
|
318
|
+
return `${where} is a prompt hook, which this reading does not confirm agy loads`;
|
|
319
|
+
if (!(type === undefined || type === null || type === '' || type === 'command'))
|
|
320
|
+
return `${where} has type ${JSON.stringify(type).slice(0, 60)}, which agy's parser rejects`;
|
|
321
|
+
const command = values.get('command');
|
|
322
|
+
if (typeof command !== 'string' || command === '')
|
|
323
|
+
return `${where} has no command, which agy's parser rejects`;
|
|
324
|
+
if (values.has('prompt') || values.has('model'))
|
|
325
|
+
return `${where} is a command hook with a prompt or model, which agy's parser rejects`;
|
|
326
|
+
const t = values.get('timeout');
|
|
327
|
+
if (t !== undefined && t !== null && !(typeof t === 'number' && Number.isInteger(t) && t >= -2147483648 && t <= 2147483647)) {
|
|
328
|
+
return `${where} has a timeout agy's parser does not read as whole seconds (${JSON.stringify(t).slice(0, 40)})`;
|
|
329
|
+
}
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
/** A number written with a fraction or an exponent after a key agy reads as `timeout` (`1e3`, `30.0`) — one pass over the text. */
|
|
333
|
+
function agyRawTimeoutProblem(raw) {
|
|
334
|
+
let key = null;
|
|
335
|
+
let afterColon = false;
|
|
336
|
+
for (let i = 0; i < raw.length;) {
|
|
337
|
+
const c = raw[i];
|
|
338
|
+
if (c === '"') {
|
|
339
|
+
let j = i + 1;
|
|
340
|
+
while (j < raw.length && raw[j] !== '"')
|
|
341
|
+
j += raw[j] === '\\' ? 2 : 1;
|
|
342
|
+
key = j - i < 80 ? raw.slice(i, j + 1) : null;
|
|
343
|
+
afterColon = false;
|
|
344
|
+
i = j + 1;
|
|
345
|
+
}
|
|
346
|
+
else if (c === ':') {
|
|
347
|
+
afterColon = true;
|
|
348
|
+
i++;
|
|
349
|
+
}
|
|
350
|
+
else if (c === '-' || (c >= '0' && c <= '9')) {
|
|
351
|
+
let j = i;
|
|
352
|
+
while (j < raw.length && /[-+0-9.eE]/.test(raw[j]))
|
|
353
|
+
j++;
|
|
354
|
+
const token = raw.slice(i, j);
|
|
355
|
+
if (afterColon && key !== null && /[.eE]/.test(token)) {
|
|
356
|
+
let name = null;
|
|
357
|
+
try {
|
|
358
|
+
name = JSON.parse(key);
|
|
359
|
+
}
|
|
360
|
+
catch { /* not a key */ }
|
|
361
|
+
if (typeof name === 'string' && agyFold(name) === 'timeout')
|
|
362
|
+
return `a timeout is written as ${token.slice(0, 40)}, which agy's parser does not read as whole seconds`;
|
|
363
|
+
}
|
|
364
|
+
afterColon = false;
|
|
365
|
+
i = j;
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
if (c !== ' ' && c !== '\t' && c !== '\n' && c !== '\r')
|
|
369
|
+
afterColon = false;
|
|
370
|
+
i++;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
return null;
|
|
374
|
+
}
|
|
375
|
+
function agyHooksFileProblem(raw, parsed) {
|
|
376
|
+
if (!plainObject(parsed))
|
|
377
|
+
return 'the file is not an object of named hooks';
|
|
378
|
+
const rawProblem = agyRawTimeoutProblem(raw);
|
|
379
|
+
if (rawProblem !== null)
|
|
380
|
+
return rawProblem;
|
|
381
|
+
for (const [name, spec] of Object.entries(parsed)) {
|
|
382
|
+
const where = `the named hook ${quoted(name)}`;
|
|
383
|
+
if (!plainObject(spec))
|
|
384
|
+
return `${where} is not an object`;
|
|
385
|
+
const { values, problem } = agyFieldsOf(spec, AGY_SPEC_FIELDS, where);
|
|
386
|
+
if (problem !== null)
|
|
387
|
+
return problem;
|
|
388
|
+
const enabled = values.get('enabled');
|
|
389
|
+
if (enabled !== undefined && enabled !== null && typeof enabled !== 'boolean')
|
|
390
|
+
return `${where} has "enabled" ${JSON.stringify(enabled).slice(0, 40)}, which agy's parser rejects`;
|
|
391
|
+
for (const event of AGY_SPEC_FIELDS.slice(1)) {
|
|
392
|
+
const list = values.get(event);
|
|
393
|
+
if (list === undefined || list === null)
|
|
394
|
+
continue;
|
|
395
|
+
if (!Array.isArray(list))
|
|
396
|
+
return `${where} ${event} is not a list`;
|
|
397
|
+
for (const [i, item] of list.entries()) {
|
|
398
|
+
const at = `${where} ${event}[${i}]`;
|
|
399
|
+
if (event !== 'PreToolUse' && event !== 'PostToolUse') {
|
|
400
|
+
const p = agyHandlerProblem(item, at);
|
|
401
|
+
if (p !== null)
|
|
402
|
+
return p;
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
if (!plainObject(item))
|
|
406
|
+
return `${at} is not a matcher group`;
|
|
407
|
+
const g = agyFieldsOf(item, AGY_GROUP_FIELDS, at);
|
|
408
|
+
if (g.problem !== null)
|
|
409
|
+
return g.problem;
|
|
410
|
+
const matcher = g.values.get('matcher');
|
|
411
|
+
if (matcher !== undefined && matcher !== null && typeof matcher !== 'string')
|
|
412
|
+
return `${at} has a matcher that is not a string`;
|
|
413
|
+
const hooks = g.values.get('hooks');
|
|
414
|
+
if (hooks === undefined || hooks === null)
|
|
415
|
+
continue;
|
|
416
|
+
if (!Array.isArray(hooks))
|
|
417
|
+
return `${at} hooks is not a list`;
|
|
418
|
+
for (const [j, h] of hooks.entries()) {
|
|
419
|
+
const p = agyHandlerProblem(h, `${at}.hooks[${j}]`);
|
|
420
|
+
if (p !== null)
|
|
421
|
+
return p;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
return null;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* @implements A-SPEC-251.2 (round 46) — the user-level hooks file agy shares between its TUI and its backend
|
|
430
|
+
* (`~/.gemini/config/hooks.json`, agy's changelog; `/hooks` writes `"enabled": false` there). agy merges named hooks from
|
|
431
|
+
* every source by name, and the last source that sets `enabled` decides it: a `holmes-kit` entry switched off there switches
|
|
432
|
+
* the workspace gate off (read from the binary — not run).
|
|
433
|
+
*/
|
|
434
|
+
/** The largest hooks file read (round 47). */
|
|
435
|
+
exports.AGY_HOOKS_MAX_BYTES = 2 * 1024 * 1024;
|
|
436
|
+
/** The most read from the user-level file and the other workspace roots together (round 48). */
|
|
437
|
+
const AGY_SWITCH_BYTES_MAX = 8 * 1024 * 1024;
|
|
438
|
+
/**
|
|
439
|
+
* @implements A-SPEC-251.2 (round 50) — agy's home: `USERPROFILE` on Windows (Go's `os.UserHomeDir`; Git Bash can set `HOME` to
|
|
440
|
+
* another drive — code reading, not measured on Windows), `HOME` elsewhere.
|
|
441
|
+
*/
|
|
442
|
+
function agyHome(platform = process.platform, env = process.env) {
|
|
443
|
+
return (platform === 'win32' ? env.USERPROFILE : env.HOME) || os.homedir();
|
|
444
|
+
}
|
|
445
|
+
function agyUserHooksPath(home = agyHome()) {
|
|
446
|
+
return path.join(home, '.gemini', 'config', 'hooks.json');
|
|
447
|
+
}
|
|
448
|
+
function agyUserSwitch(file = agyUserHooksPath()) {
|
|
449
|
+
// @implements A-SPEC-251.2 (round 47) — a switch only in a file agy loads: one its parser drops (a handler it rejects, a
|
|
450
|
+
// byte-order mark, not JSON) switches nothing off (round 46 read FAIL where the gate runs); past 2 MiB it is not read and
|
|
451
|
+
// not confirmed.
|
|
452
|
+
let raw;
|
|
453
|
+
try {
|
|
454
|
+
const st = fs.statSync(file);
|
|
455
|
+
if (!st.isFile())
|
|
456
|
+
return { off: false, unconfirmed: null };
|
|
457
|
+
if (st.size > exports.AGY_HOOKS_MAX_BYTES)
|
|
458
|
+
return { off: false, unconfirmed: `${file} is larger than ${exports.AGY_HOOKS_MAX_BYTES / (1024 * 1024)} MiB and was not read` };
|
|
459
|
+
raw = fs.readFileSync(file, 'utf8');
|
|
460
|
+
}
|
|
461
|
+
catch {
|
|
462
|
+
return { off: false, unconfirmed: null };
|
|
463
|
+
}
|
|
464
|
+
let parsed;
|
|
465
|
+
try {
|
|
466
|
+
parsed = JSON.parse(raw);
|
|
467
|
+
}
|
|
468
|
+
catch {
|
|
469
|
+
return { off: false, unconfirmed: null };
|
|
470
|
+
}
|
|
471
|
+
if (!plainObject(parsed) || !Object.prototype.hasOwnProperty.call(parsed, HOLMES))
|
|
472
|
+
return { off: false, unconfirmed: null };
|
|
473
|
+
if (agyHooksFileProblem(raw, parsed) !== null)
|
|
474
|
+
return { off: false, unconfirmed: null };
|
|
475
|
+
const spec = parsed[HOLMES];
|
|
476
|
+
if (!plainObject(spec))
|
|
477
|
+
return { off: false, unconfirmed: `${file} has a holmes-kit entry that is not an object` };
|
|
478
|
+
const { values, problem } = agyFieldsOf(spec, ['enabled'], `the holmes-kit entry in ${file}`);
|
|
479
|
+
if (problem !== null)
|
|
480
|
+
return { off: false, unconfirmed: problem };
|
|
481
|
+
const enabled = values.get('enabled');
|
|
482
|
+
if (enabled === false)
|
|
483
|
+
return { off: true, unconfirmed: null };
|
|
484
|
+
if (enabled !== undefined && enabled !== null && typeof enabled !== 'boolean')
|
|
485
|
+
return { off: false, unconfirmed: `the holmes-kit entry in ${file} has "enabled" that is not true or false` };
|
|
486
|
+
return { off: false, unconfirmed: null };
|
|
487
|
+
}
|
|
261
488
|
/** `.agents/hooks.json`. Top-level keys are tool namespaces; only ours is replaced. */
|
|
262
489
|
function mergeHooksJson(before, ours) {
|
|
263
490
|
const parsed = parseOr(before, ours, 'hooks.json');
|
|
@@ -321,7 +548,7 @@ function agentFiles(agent, opts) {
|
|
|
321
548
|
case 'antigravity':
|
|
322
549
|
return [
|
|
323
550
|
{ path: path.join(target, '.agents', 'hooks.json'), content: hooksJson(packageRoot) },
|
|
324
|
-
{ path: path.join(target, '.agents', 'mcp_config.json'), content: mcpConfig(packageRoot, specsDir, opts.launcher) },
|
|
551
|
+
...(opts.mcp === false ? [] : [{ path: path.join(target, '.agents', 'mcp_config.json'), content: mcpConfig(packageRoot, specsDir, opts.launcher) }]),
|
|
325
552
|
{ path: path.join(target, 'AGENTS.md'), content: (0, exports.AGENTS_MD)(exports.HARNESS_ENFORCES.antigravity) },
|
|
326
553
|
];
|
|
327
554
|
case 'codex':
|
|
@@ -411,3 +638,156 @@ function agentLinks(agent, opts) {
|
|
|
411
638
|
why: '스킬 본문은 .claude/skills 한 곳에 둔다 — 두 벌이면 하나가 낡는다',
|
|
412
639
|
}];
|
|
413
640
|
}
|
|
641
|
+
/**
|
|
642
|
+
* @implements A-SPEC-251.2 (round 47) — the other hooks files agy merges into a workspace: `hooks.json` under `.agents`, `.agent`,
|
|
643
|
+
* `_agents` and `_agent` (agy's documentation), from the target up to its repository root (the first directory holding `.git`,
|
|
644
|
+
* at most 64 levels; the target alone without one) — all but the target's own `.agents/hooks.json`.
|
|
645
|
+
*/
|
|
646
|
+
const AGY_ROOT_NAMES = ['.agents', '.agent', '_agents', '_agent'];
|
|
647
|
+
function agyOtherHooksFiles(target, cut) {
|
|
648
|
+
const walk = (start) => {
|
|
649
|
+
const dirs = [start];
|
|
650
|
+
let top = -1;
|
|
651
|
+
let ended = false;
|
|
652
|
+
for (let d = start, i = 0; i < 64; i++) {
|
|
653
|
+
if (fs.existsSync(path.join(d, '.git'))) {
|
|
654
|
+
top = i;
|
|
655
|
+
ended = true;
|
|
656
|
+
break;
|
|
657
|
+
}
|
|
658
|
+
const up = path.dirname(d);
|
|
659
|
+
if (up === d) {
|
|
660
|
+
ended = true;
|
|
661
|
+
break;
|
|
662
|
+
}
|
|
663
|
+
d = up;
|
|
664
|
+
dirs.push(d);
|
|
665
|
+
}
|
|
666
|
+
// Round 49: 64 levels walked with neither a repository root nor the top reached — what lies above was not seen.
|
|
667
|
+
if (!ended && cut !== undefined)
|
|
668
|
+
cut.short = true;
|
|
669
|
+
const own = path.join(start, '.agents', 'hooks.json');
|
|
670
|
+
return dirs.slice(0, top < 0 ? 1 : top + 1).flatMap((d) => AGY_ROOT_NAMES.map((n) => path.join(d, n, 'hooks.json'))).filter((f) => f !== own);
|
|
671
|
+
};
|
|
672
|
+
// @implements A-SPEC-251.2 (round 48) — from the target as written AND from its real path: through a link into a repository the
|
|
673
|
+
// written path climbed the link's own parents and never saw the repository's switched-off entry (PASS — measured).
|
|
674
|
+
const written = path.resolve(target);
|
|
675
|
+
const real = (() => { try {
|
|
676
|
+
return fs.realpathSync.native(written);
|
|
677
|
+
}
|
|
678
|
+
catch {
|
|
679
|
+
return written;
|
|
680
|
+
} })();
|
|
681
|
+
return [...new Set([...walk(written), ...(real === written ? [] : walk(real))])];
|
|
682
|
+
}
|
|
683
|
+
/** The first switch among the user-level file and the other workspace roots: off, or not confirmed. */
|
|
684
|
+
function agySwitches(target, userFile = agyUserHooksPath()) {
|
|
685
|
+
let unconfirmed = null;
|
|
686
|
+
// @implements A-SPEC-251.2 (round 48) — read within 8 MiB in all: 240 files of 2 MiB along the parents held doctor for 25 s
|
|
687
|
+
// (measured); past the budget the rest is not read and the gate is not confirmed.
|
|
688
|
+
let left = AGY_SWITCH_BYTES_MAX;
|
|
689
|
+
const cut = { short: false };
|
|
690
|
+
const others = agyOtherHooksFiles(target, cut);
|
|
691
|
+
if (cut.short)
|
|
692
|
+
unconfirmed = `the repository root was not found within 64 levels above ${target}, so agy's hooks files above it were not read`;
|
|
693
|
+
for (const f of [userFile, ...others]) {
|
|
694
|
+
let size = 0;
|
|
695
|
+
try {
|
|
696
|
+
const st = fs.statSync(f);
|
|
697
|
+
if (!st.isFile())
|
|
698
|
+
continue;
|
|
699
|
+
size = st.size;
|
|
700
|
+
}
|
|
701
|
+
catch {
|
|
702
|
+
continue;
|
|
703
|
+
}
|
|
704
|
+
if (size <= exports.AGY_HOOKS_MAX_BYTES && size > left) {
|
|
705
|
+
unconfirmed ??= `more agy hooks files than were read (${AGY_SWITCH_BYTES_MAX / (1024 * 1024)} MiB in all) — ${f} was not read`;
|
|
706
|
+
break;
|
|
707
|
+
}
|
|
708
|
+
if (size <= exports.AGY_HOOKS_MAX_BYTES)
|
|
709
|
+
left -= size;
|
|
710
|
+
const s = agyUserSwitch(f);
|
|
711
|
+
if (s.off)
|
|
712
|
+
return { offIn: f, unconfirmed: null };
|
|
713
|
+
unconfirmed ??= s.unconfirmed;
|
|
714
|
+
}
|
|
715
|
+
// @implements A-SPEC-251.2 (round 47, owner decision 2026-09-27) — only init's own file is confirmed: a hooks file in another
|
|
716
|
+
// workspace root (whatever it holds), or a `holmes-kit` entry in the user-level file, merges into the gate in ways this
|
|
717
|
+
// reading does not follow — not confirmed.
|
|
718
|
+
if (unconfirmed === null) {
|
|
719
|
+
const other = agyOtherHooksFiles(target).find((f) => { try {
|
|
720
|
+
return fs.lstatSync(f) !== undefined;
|
|
721
|
+
}
|
|
722
|
+
catch {
|
|
723
|
+
return false;
|
|
724
|
+
} });
|
|
725
|
+
if (other !== undefined)
|
|
726
|
+
unconfirmed = `another agy hooks file exists (${other}), which agy merges with this one`;
|
|
727
|
+
else if (agyHoldsHolmes(userFile))
|
|
728
|
+
unconfirmed = `${userFile} holds a holmes-kit entry, which agy merges with this one`;
|
|
729
|
+
}
|
|
730
|
+
return { offIn: null, unconfirmed };
|
|
731
|
+
}
|
|
732
|
+
/** Whether a hooks file agy loads holds a `holmes-kit` entry (a file it drops holds none for it). */
|
|
733
|
+
function agyHoldsHolmes(file) {
|
|
734
|
+
try {
|
|
735
|
+
const st = fs.statSync(file);
|
|
736
|
+
if (!st.isFile() || st.size > exports.AGY_HOOKS_MAX_BYTES)
|
|
737
|
+
return false;
|
|
738
|
+
const raw = fs.readFileSync(file, 'utf8');
|
|
739
|
+
const parsed = JSON.parse(raw);
|
|
740
|
+
return plainObject(parsed) && Object.prototype.hasOwnProperty.call(parsed, HOLMES) && agyHooksFileProblem(raw, parsed) === null;
|
|
741
|
+
}
|
|
742
|
+
catch {
|
|
743
|
+
return false;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* @implements A-SPEC-251.2 (round 47, owner decision 2026-09-27) — the file init writes, by shape: one named hook `holmes-kit`
|
|
748
|
+
* with `PreToolUse` (one `*` group of one handler) and `Stop` (one handler), each handler holding init's keys and values but
|
|
749
|
+
* for the script path. Anything else is not confirmed — agy's parser and merge rules are not transcribed.
|
|
750
|
+
*/
|
|
751
|
+
/** The text without the whitespace between its tokens (strings kept as written) — one pass. */
|
|
752
|
+
function jsonMinified(raw) {
|
|
753
|
+
let out = '';
|
|
754
|
+
for (let i = 0; i < raw.length; i++) {
|
|
755
|
+
const c = raw[i];
|
|
756
|
+
if (c === '"') {
|
|
757
|
+
let j = i + 1;
|
|
758
|
+
while (j < raw.length && raw[j] !== '"')
|
|
759
|
+
j += raw[j] === '\\' ? 2 : 1;
|
|
760
|
+
out += raw.slice(i, j + 1);
|
|
761
|
+
i = j;
|
|
762
|
+
}
|
|
763
|
+
else if (c !== ' ' && c !== '\t' && c !== '\n' && c !== '\r')
|
|
764
|
+
out += c;
|
|
765
|
+
}
|
|
766
|
+
return out;
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* `raw` (round 48): the text itself must be the parsed object written out again — parsing keeps only the last of two equal keys,
|
|
770
|
+
* so `"timeout": "10", "timeout": 30` and a first `"holmes-kit": {"enabled": false}` read as init's file (measured).
|
|
771
|
+
*/
|
|
772
|
+
function agyCanonicalFile(parsed, raw) {
|
|
773
|
+
if (raw !== undefined && jsonMinified(raw.replace(/^\uFEFF/, '')) !== JSON.stringify(parsed))
|
|
774
|
+
return false;
|
|
775
|
+
const keysAre = (o, keys) => plainObject(o) && Object.keys(o).length === keys.length && keys.every((k) => Object.prototype.hasOwnProperty.call(o, k));
|
|
776
|
+
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]) : h[k] === v));
|
|
779
|
+
if (!keysAre(parsed, [HOLMES]))
|
|
780
|
+
return false;
|
|
781
|
+
const spec = parsed[HOLMES];
|
|
782
|
+
if (!keysAre(spec, ['PreToolUse', 'Stop']))
|
|
783
|
+
return false;
|
|
784
|
+
const pre = spec.PreToolUse;
|
|
785
|
+
const stop = spec.Stop;
|
|
786
|
+
if (!Array.isArray(pre) || pre.length !== 1 || !Array.isArray(stop) || stop.length !== 1)
|
|
787
|
+
return false;
|
|
788
|
+
const group = pre[0];
|
|
789
|
+
if (!keysAre(group, ['matcher', 'hooks']) || group.matcher !== '*')
|
|
790
|
+
return false;
|
|
791
|
+
const hooks = group.hooks;
|
|
792
|
+
return Array.isArray(hooks) && hooks.length === 1 && handler(hooks[0]) && handler(stop[0]);
|
|
793
|
+
}
|
|
@@ -11,5 +11,7 @@ export interface AttestIo {
|
|
|
11
11
|
stderr(s: string): void;
|
|
12
12
|
}
|
|
13
13
|
export declare const BADGE_REL: string;
|
|
14
|
+
/** Round 15: the text of the qualifier when the working-tree status did not answer (it claimed a clean commit — measured). */
|
|
15
|
+
export declare const ATTEST_UNKNOWN = "+unknown";
|
|
14
16
|
export declare function buildAttestReport(root: string, exclude: string[]): Promise<AttestReport>;
|
|
15
17
|
export declare function runAttest(o: AttestOptions, io: AttestIo): Promise<number>;
|