@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
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.RUN_ID_RE = exports.NEVER_DELEGABLE = exports.DELEGABLE_RULES = exports.DELEGATION_SCHEMA = exports.DELEGATION_MARKER = void 0;
|
|
37
|
+
exports.baseRule = baseRule;
|
|
38
|
+
exports.readDelegation = readDelegation;
|
|
39
|
+
exports.delegationCovers = delegationCovers;
|
|
40
|
+
exports.delegationNote = delegationNote;
|
|
41
|
+
exports.writeDelegation = writeDelegation;
|
|
42
|
+
exports.removeDelegation = removeDelegation;
|
|
43
|
+
// @implements A-SPEC-771
|
|
44
|
+
// The run delegation — the third autonomy envelope. Measured need (X1, 2026-10-12): a benchmark fixture the operator
|
|
45
|
+
// had approved as a whole still stopped on `upstream-has-human-aspec: … — files-to-touch-root-only`, because neither
|
|
46
|
+
// the project default (A-SPEC-552.1) nor the session marker (A-SPEC-553.1) can name a run, a workspace boundary or a
|
|
47
|
+
// grader rule. This document can. It is written only by the operator CLI under operator proof, lives under the
|
|
48
|
+
// protected state directory an agent cannot write, binds to the workspace by realpath, expires, and covers a CLOSED
|
|
49
|
+
// set of grader rules — never the NEVER set. The grader itself is untouched: this module only answers "does the
|
|
50
|
+
// operator's delegation cover the rule the grader named?".
|
|
51
|
+
const fs = __importStar(require("node:fs"));
|
|
52
|
+
const path = __importStar(require("node:path"));
|
|
53
|
+
exports.DELEGATION_MARKER = ['.ax', 'state', 'delegation.json'];
|
|
54
|
+
exports.DELEGATION_SCHEMA = 'run-delegation/1';
|
|
55
|
+
/** Grader rules an operator may delegate for a run (bare names; a suffixed rule is matched by its bare name). */
|
|
56
|
+
exports.DELEGABLE_RULES = [
|
|
57
|
+
'files-to-touch-root-only', 'files-to-touch-gate-file', 'breaking-change-gate-behavior', 'upstream-without-aspec',
|
|
58
|
+
];
|
|
59
|
+
/** Never delegable, whatever the document says: a decision, an un-admitted requirement, an undeclared or unknown grade. */
|
|
60
|
+
exports.NEVER_DELEGABLE = [
|
|
61
|
+
'architecture-document', 'requirement-without-intake', 'breaking-change-undeclared', 'unknown-kind',
|
|
62
|
+
];
|
|
63
|
+
exports.RUN_ID_RE = /^[A-Za-z0-9._-]{1,64}$/;
|
|
64
|
+
/** The bare rule name a grader reason resolves to: the child rule of an upstream reason, with any `: <argument>` dropped. */
|
|
65
|
+
function baseRule(rule) {
|
|
66
|
+
const upstream = /^upstream-has-human-aspec: \S+ — (.+)$/.exec(rule);
|
|
67
|
+
const inner = upstream ? upstream[1] : rule;
|
|
68
|
+
return inner.split(':')[0].trim();
|
|
69
|
+
}
|
|
70
|
+
function realpathOrNull(p) {
|
|
71
|
+
try {
|
|
72
|
+
return fs.realpathSync.native(p);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** Read the document for `root` as it stands at `now`. Fail-closed: anything unreadable or malformed grants nothing. */
|
|
79
|
+
function readDelegation(root, now) {
|
|
80
|
+
const file = path.join(root, ...exports.DELEGATION_MARKER);
|
|
81
|
+
let raw;
|
|
82
|
+
try {
|
|
83
|
+
raw = fs.readFileSync(file, 'utf8');
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
return e.code === 'ENOENT' ? { active: false, why: 'none' } : { active: false, why: 'unreadable' };
|
|
87
|
+
}
|
|
88
|
+
let doc;
|
|
89
|
+
try {
|
|
90
|
+
doc = JSON.parse(raw);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return { active: false, why: 'unreadable' };
|
|
94
|
+
}
|
|
95
|
+
if (!doc || typeof doc !== 'object')
|
|
96
|
+
return { active: false, why: 'invalid' };
|
|
97
|
+
const d = doc;
|
|
98
|
+
const str = (v) => typeof v === 'string' && v.trim() !== '';
|
|
99
|
+
if (d.schema !== exports.DELEGATION_SCHEMA || !str(d.run) || !exports.RUN_ID_RE.test(d.run) || !str(d.workspace) || !str(d.expires) || !str(d.issuedBy) || !Array.isArray(d.allow)) {
|
|
100
|
+
return { active: false, why: 'invalid' };
|
|
101
|
+
}
|
|
102
|
+
const allow = d.allow.filter((a) => typeof a === 'string');
|
|
103
|
+
if (allow.length !== d.allow.length || allow.length === 0)
|
|
104
|
+
return { active: false, why: 'invalid' };
|
|
105
|
+
// A NEVER rule anywhere in `allow` voids the document: the CLI never writes one, so its presence is a forgery or a
|
|
106
|
+
// hand edit, and a forged document must not cover even the rules it names correctly.
|
|
107
|
+
if (allow.some((a) => !exports.DELEGABLE_RULES.includes(a)))
|
|
108
|
+
return { active: false, why: 'invalid' };
|
|
109
|
+
const exp = Date.parse(d.expires);
|
|
110
|
+
const nowMs = Date.parse(now);
|
|
111
|
+
if (!Number.isFinite(exp) || !Number.isFinite(nowMs) || nowMs >= exp)
|
|
112
|
+
return { active: false, why: 'expired', expires: d.expires, run: d.run };
|
|
113
|
+
const here = realpathOrNull(root);
|
|
114
|
+
const there = realpathOrNull(d.workspace);
|
|
115
|
+
if (here === null || there === null || here !== there)
|
|
116
|
+
return { active: false, why: 'workspace-mismatch', workspace: d.workspace, run: d.run };
|
|
117
|
+
return { active: true, delegation: { schema: exports.DELEGATION_SCHEMA, run: d.run, workspace: d.workspace, allow, issuedAt: str(d.issuedAt) ? d.issuedAt : '', expires: d.expires, issuedBy: d.issuedBy,
|
|
118
|
+
...(d.limits && typeof d.limits === 'object' ? { limits: d.limits } : {}), ...(str(d.rationale) ? { rationale: d.rationale } : {}) } };
|
|
119
|
+
}
|
|
120
|
+
/** Whether an active delegation covers the grader reason `rule` (its bare name must be delegable and in `allow`). */
|
|
121
|
+
function delegationCovers(d, rule) {
|
|
122
|
+
const bare = baseRule(rule);
|
|
123
|
+
if (exports.NEVER_DELEGABLE.includes(bare) || !exports.DELEGABLE_RULES.includes(bare))
|
|
124
|
+
return false;
|
|
125
|
+
return d.allow.includes(bare);
|
|
126
|
+
}
|
|
127
|
+
/** The one refusal line that names which limit of the delegation applied (empty when there is no document). */
|
|
128
|
+
function delegationNote(state, rule) {
|
|
129
|
+
if (state.active)
|
|
130
|
+
return delegationCovers(state.delegation, rule) ? '' : `\n[delegation: run ${state.delegation.run} does not cover ${rule}]`;
|
|
131
|
+
switch (state.why) {
|
|
132
|
+
case 'none': return '';
|
|
133
|
+
case 'expired': return `\n[delegation: expired ${state.expires ?? '?'}]`;
|
|
134
|
+
case 'workspace-mismatch': return `\n[delegation: for ${state.workspace ?? '?'}, not this root]`;
|
|
135
|
+
case 'unreadable': return '\n[delegation: unreadable document — covers nothing]';
|
|
136
|
+
case 'invalid': return '\n[delegation: invalid document (schema, run id, expiry or a rule outside the delegable set) — covers nothing]';
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/** Write the document for the CLI (operator proof is the caller's job). Returns the written document. */
|
|
140
|
+
function writeDelegation(root, d) {
|
|
141
|
+
const file = path.join(root, ...exports.DELEGATION_MARKER);
|
|
142
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
143
|
+
fs.writeFileSync(file, JSON.stringify(d, null, 2) + '\n');
|
|
144
|
+
}
|
|
145
|
+
/** Remove the document; true when one was there. Never throws on absence. */
|
|
146
|
+
function removeDelegation(root) {
|
|
147
|
+
const file = path.join(root, ...exports.DELEGATION_MARKER);
|
|
148
|
+
const existed = fs.existsSync(file);
|
|
149
|
+
fs.rmSync(file, { force: true });
|
|
150
|
+
return existed;
|
|
151
|
+
}
|
|
@@ -94,6 +94,16 @@ export declare function patchAmbiguous(text: string): boolean;
|
|
|
94
94
|
* pattern over the whole text, nothing to back-track on.
|
|
95
95
|
*/
|
|
96
96
|
export declare function canonicalPatch(text: string): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* @implements A-SPEC-769.7 — WHY a text is not canonical, for the refusal that names it. `null` when `canonicalPatch`
|
|
99
|
+
* is true; `'no-op'` when every grammar rule holds and the only fault is an update block with no `+`/`-` line (the
|
|
100
|
+
* X1 HB negative control, 2026-10-13: a context-only `apply_patch` was refused as "file_path missing" although its
|
|
101
|
+
* header named the file); `'grammar'` for every other shape. Invariant pinned by its test: `canonicalPatch(t) ===
|
|
102
|
+
* (canonicalPatchReason(t) === null)`. The walk is the same walk as `canonicalPatch`, with one difference: an update
|
|
103
|
+
* block that closes with zero content lines is counted instead of refused, and an add block that adds nothing stays a
|
|
104
|
+
* grammar fault (an add must add). This function changes no gate decision — only the reason text a caller prints.
|
|
105
|
+
*/
|
|
106
|
+
export declare function canonicalPatchReason(text: string): null | 'no-op' | 'grammar';
|
|
97
107
|
/** Every header is a target, in order; nothing is merged or dropped by path (A-SPEC-163.2 rule 2). */
|
|
98
108
|
export declare function patchTargetsOf(text: string): PatchTarget[];
|
|
99
109
|
/**
|
|
@@ -41,6 +41,7 @@ exports.hasPatchEnvelope = hasPatchEnvelope;
|
|
|
41
41
|
exports.isWholePatch = isWholePatch;
|
|
42
42
|
exports.patchAmbiguous = patchAmbiguous;
|
|
43
43
|
exports.canonicalPatch = canonicalPatch;
|
|
44
|
+
exports.canonicalPatchReason = canonicalPatchReason;
|
|
44
45
|
exports.patchTargetsOf = patchTargetsOf;
|
|
45
46
|
exports.applyPatchUpdate = applyPatchUpdate;
|
|
46
47
|
exports.applyPatchUpdateDetailed = applyPatchUpdateDetailed;
|
|
@@ -315,6 +316,87 @@ function canonicalPatch(text) {
|
|
|
315
316
|
}
|
|
316
317
|
return block !== null && closes();
|
|
317
318
|
}
|
|
319
|
+
/**
|
|
320
|
+
* @implements A-SPEC-769.7 — WHY a text is not canonical, for the refusal that names it. `null` when `canonicalPatch`
|
|
321
|
+
* is true; `'no-op'` when every grammar rule holds and the only fault is an update block with no `+`/`-` line (the
|
|
322
|
+
* X1 HB negative control, 2026-10-13: a context-only `apply_patch` was refused as "file_path missing" although its
|
|
323
|
+
* header named the file); `'grammar'` for every other shape. Invariant pinned by its test: `canonicalPatch(t) ===
|
|
324
|
+
* (canonicalPatchReason(t) === null)`. The walk is the same walk as `canonicalPatch`, with one difference: an update
|
|
325
|
+
* block that closes with zero content lines is counted instead of refused, and an add block that adds nothing stays a
|
|
326
|
+
* grammar fault (an add must add). This function changes no gate decision — only the reason text a caller prints.
|
|
327
|
+
*/
|
|
328
|
+
function canonicalPatchReason(text) {
|
|
329
|
+
const lines = text.split('\n').map(unCR);
|
|
330
|
+
let start = 0;
|
|
331
|
+
let end = lines.length;
|
|
332
|
+
while (start < end && lines[start].trim() === '')
|
|
333
|
+
start++;
|
|
334
|
+
while (end > start && lines[end - 1].trim() === '')
|
|
335
|
+
end--;
|
|
336
|
+
if (end - start < 3 || lines[start] !== PATCH_BEGIN || lines[end - 1] !== PATCH_END)
|
|
337
|
+
return 'grammar';
|
|
338
|
+
let block = null;
|
|
339
|
+
let content = 0;
|
|
340
|
+
let sinceHeader = 0;
|
|
341
|
+
let moved = false;
|
|
342
|
+
let emptyUpdates = 0;
|
|
343
|
+
const closes = () => {
|
|
344
|
+
if (block === 'update' && content === 0) {
|
|
345
|
+
emptyUpdates++;
|
|
346
|
+
return true;
|
|
347
|
+
}
|
|
348
|
+
return block === null || block === 'delete' || content > 0;
|
|
349
|
+
};
|
|
350
|
+
for (let i = start + 1; i < end - 1; i++) {
|
|
351
|
+
const line = lines[i];
|
|
352
|
+
if (PATCH_LINE_BREAK.test(line))
|
|
353
|
+
return 'grammar';
|
|
354
|
+
if (line === PATCH_BEGIN || line === PATCH_END)
|
|
355
|
+
return 'grammar';
|
|
356
|
+
if (line.startsWith('*** ')) {
|
|
357
|
+
if (line === PATCH_EOF) {
|
|
358
|
+
if (block !== 'update')
|
|
359
|
+
return 'grammar';
|
|
360
|
+
sinceHeader++;
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
if (line.startsWith(PATCH_MOVE)) {
|
|
364
|
+
if (block !== 'update' || sinceHeader !== 0 || moved || !canonicalPath(line.slice(PATCH_MOVE.length)))
|
|
365
|
+
return 'grammar';
|
|
366
|
+
moved = true;
|
|
367
|
+
sinceHeader++;
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
const header = PATCH_FILE_HEADERS.find(([prefix]) => line.startsWith(prefix));
|
|
371
|
+
if (header === undefined || !canonicalPath(line.slice(header[0].length)) || !closes())
|
|
372
|
+
return 'grammar';
|
|
373
|
+
block = header[1];
|
|
374
|
+
content = 0;
|
|
375
|
+
sinceHeader = 0;
|
|
376
|
+
moved = false;
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
if (block === 'add') {
|
|
380
|
+
if (!line.startsWith('+'))
|
|
381
|
+
return 'grammar';
|
|
382
|
+
content++;
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
if (block !== 'update')
|
|
386
|
+
return 'grammar';
|
|
387
|
+
sinceHeader++;
|
|
388
|
+
if (line === '@@' || line.startsWith('@@ '))
|
|
389
|
+
continue;
|
|
390
|
+
const head = line.charAt(0);
|
|
391
|
+
if (head === '+' || head === '-')
|
|
392
|
+
content++;
|
|
393
|
+
else if (head !== ' ')
|
|
394
|
+
return 'grammar';
|
|
395
|
+
}
|
|
396
|
+
if (block === null || !closes())
|
|
397
|
+
return 'grammar';
|
|
398
|
+
return emptyUpdates > 0 ? 'no-op' : null;
|
|
399
|
+
}
|
|
318
400
|
/** Every header is a target, in order; nothing is merged or dropped by path (A-SPEC-163.2 rule 2). */
|
|
319
401
|
function patchTargetsOf(text) {
|
|
320
402
|
if (!text.includes('*** '))
|
|
@@ -26,6 +26,8 @@ export declare const TOOL_MAP: Record<string, {
|
|
|
26
26
|
}>;
|
|
27
27
|
/** 훅을 실행해 그 표준 출력을 돌려준다. 실행 자체가 실패하면 `null`(호출자가 닫는 쪽으로 받는다). */
|
|
28
28
|
export type HookRunner = (hookPath: string, payload: string, cwd: string) => Record<string, unknown> | null;
|
|
29
|
+
/** @implements A-SPEC-769.10, A-SPEC-769.11 — stop.js gets the Stop budget; the other hooks keep 30 s. */
|
|
30
|
+
export declare function shippedHookTimeoutMs(hookPath: string): number;
|
|
29
31
|
/**
|
|
30
32
|
* PreToolUse: Antigravity 의 말 → 게이트 → Antigravity 의 말.
|
|
31
33
|
*
|
|
@@ -34,13 +34,16 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.TOOL_MAP = void 0;
|
|
37
|
+
exports.shippedHookTimeoutMs = shippedHookTimeoutMs;
|
|
37
38
|
exports.adaptPreToolUse = adaptPreToolUse;
|
|
38
39
|
exports.adaptStop = adaptStop;
|
|
39
40
|
// @implements A-SPEC-193
|
|
40
41
|
// @implements A-SPEC-734
|
|
42
|
+
// @implements A-SPEC-769.10, A-SPEC-769.11
|
|
41
43
|
const fs = __importStar(require("node:fs"));
|
|
42
44
|
const path = __importStar(require("node:path"));
|
|
43
45
|
const node_child_process_1 = require("node:child_process");
|
|
46
|
+
const hook_process_1 = require("../../runtime/hook-process");
|
|
44
47
|
const bounded_io_1 = require("../../project/bounded-io");
|
|
45
48
|
/**
|
|
46
49
|
* 실측한 도구만 등재한다.
|
|
@@ -63,9 +66,13 @@ exports.TOOL_MAP = {
|
|
|
63
66
|
const str = (v) => (typeof v === 'string' ? v : undefined);
|
|
64
67
|
/** 출하된 훅 프로그램의 자리 — 이 파일에서 패키지 뿌리로 올라간다. */
|
|
65
68
|
const shippedHook = (name) => path.resolve(__dirname, '..', '..', '..', '..', 'dist', 'holmes', 'hooks', name);
|
|
69
|
+
/** @implements A-SPEC-769.10, A-SPEC-769.11 — stop.js gets the Stop budget; the other hooks keep 30 s. */
|
|
70
|
+
function shippedHookTimeoutMs(hookPath) {
|
|
71
|
+
return path.basename(hookPath) === 'stop.js' ? hook_process_1.STOP_HOOK_BUDGET_MS : 30_000;
|
|
72
|
+
}
|
|
66
73
|
const runShippedHook = (hookPath, payload, cwd) => {
|
|
67
74
|
const r = (0, node_child_process_1.spawnSync)(process.execPath, [hookPath], {
|
|
68
|
-
cwd, input: payload, encoding: 'utf8', timeout:
|
|
75
|
+
cwd, input: payload, encoding: 'utf8', timeout: shippedHookTimeoutMs(hookPath),
|
|
69
76
|
env: { ...process.env },
|
|
70
77
|
});
|
|
71
78
|
// @implements A-SPEC-734 (round 16) — three-harness parity: the hook's "not judged" notices reach the harness as
|
|
@@ -94,7 +94,9 @@ export interface HookInput {
|
|
|
94
94
|
/** @implements A-SPEC-163.2 — the payload carries a patch whose targets cannot be read one way; denied whichever tool sent it. */
|
|
95
95
|
patchUnreadable?: boolean;
|
|
96
96
|
/** @implements A-SPEC-163.7 — set only when the one cause is a marked shell command (A-SPEC-163.6 rule 3). */
|
|
97
|
-
|
|
97
|
+
/** @implements A-SPEC-769.7 — `'no-op'`: the one cause is an update block with no `+`/`-` line; the paths are named. */
|
|
98
|
+
patchUnreadableCause?: 'shell-marker' | 'no-op';
|
|
99
|
+
patchNoopPaths?: string[];
|
|
98
100
|
}
|
|
99
101
|
/**
|
|
100
102
|
* @implements A-SPEC-753.2 — what a denial leaves in the provenance ledger: the reason up to the operator command.
|
|
@@ -955,6 +955,9 @@ const PATCH_UNREADABLE_REASON = '[Holmes-Kit] cannot read the edit target path,
|
|
|
955
955
|
// @implements A-SPEC-768.2 — a patch the tool could not apply is told so, by file and chunk; measured 2026-10-11 (H0 arm)
|
|
956
956
|
// the path-missing sentence above was returned for a readable file whose patch simply did not apply.
|
|
957
957
|
const patchNotAppliedReason = (file, why) => `[Holmes-Kit] the patch does not apply to ${file} as it stands (${why}), so the result cannot be judged`;
|
|
958
|
+
// @implements A-SPEC-769.7 — a context-only update is refused by its own name (measured 2026-10-13, X1 HB control: the
|
|
959
|
+
// path-missing sentence was printed for a patch whose header named the file). The deny is unchanged; the reason is not.
|
|
960
|
+
const patchNoopReason = (files) => `[Holmes-Kit] the patch to ${files.join(', ')} adds or removes no line (a context-only update is a no-op), so there is nothing to judge — include at least one + or - line`;
|
|
958
961
|
// @implements A-SPEC-163.7 — the refusal of A-SPEC-163.6 rule 3 in its own words (each refusal names its channel, A-SPEC-737).
|
|
959
962
|
const SHELL_MARKED_REASON = '[Holmes-Kit] this shell command mentions the patch tool or a patch marker and is not one plain read, so it is not judged — '
|
|
960
963
|
+ 'search with the harness\'s own search tool, or run one plain grep, egrep, fgrep, rg, cat, head, tail, wc or ls with literal words (no pipe, redirect or substitution)';
|
|
@@ -1032,6 +1035,7 @@ function normalizeHookInput(raw) {
|
|
|
1032
1035
|
// A patch that cannot be read one way (no target, an empty path, too many, an indented header) is unreadable.
|
|
1033
1036
|
const toolName = (str(r.tool_name) ?? '').toLowerCase();
|
|
1034
1037
|
let patchUnreadable = false;
|
|
1038
|
+
let noopPaths = null; // @implements A-SPEC-769.7
|
|
1035
1039
|
// @implements A-SPEC-163.7 — why: a shell command refused for a patch marker is told so (it has no file path to miss).
|
|
1036
1040
|
let shellMarked = false;
|
|
1037
1041
|
let otherUnreadable = false;
|
|
@@ -1078,13 +1082,22 @@ function normalizeHookInput(raw) {
|
|
|
1078
1082
|
if (targets.length === 0 || targets.length > write_target_1.PATCH_TARGETS_MAX || patches.some((text) => !(0, write_target_1.canonicalPatch)(text))) {
|
|
1079
1083
|
patchUnreadable = true;
|
|
1080
1084
|
otherUnreadable = true;
|
|
1085
|
+
// @implements A-SPEC-769.7 — when the targets are readable and the only fault is a context-only update block,
|
|
1086
|
+
// the refusal names that condition and those paths instead of a missing path.
|
|
1087
|
+
if (targets.length > 0 && targets.length <= write_target_1.PATCH_TARGETS_MAX) {
|
|
1088
|
+
const reasons = patches.map(write_target_1.canonicalPatchReason);
|
|
1089
|
+
if (reasons.every((why) => why === null || why === 'no-op') && reasons.includes('no-op')) {
|
|
1090
|
+
noopPaths = targets.filter((t) => t.kind === 'update' && !/^[+-]/m.test(t.hunk ?? '')).map((t) => t.path);
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1081
1093
|
}
|
|
1082
1094
|
else
|
|
1083
1095
|
out.patch_targets = targets;
|
|
1084
1096
|
}
|
|
1085
1097
|
}
|
|
1086
1098
|
return { tool_name: str(r.tool_name) ?? '', tool_input: out, ...(cwd === undefined ? {} : { cwd }), ...(malformed ? { malformed: true } : {}),
|
|
1087
|
-
...(patchUnreadable ? { patchUnreadable: true } : {}), ...(shellMarked && !otherUnreadable ? { patchUnreadableCause: 'shell-marker' } : {})
|
|
1099
|
+
...(patchUnreadable ? { patchUnreadable: true } : {}), ...(shellMarked && !otherUnreadable ? { patchUnreadableCause: 'shell-marker' } : {}),
|
|
1100
|
+
...(noopPaths !== null && !shellMarked ? { patchUnreadableCause: 'no-op', patchNoopPaths: noopPaths } : {}) };
|
|
1088
1101
|
}
|
|
1089
1102
|
/**
|
|
1090
1103
|
* Which way to fail when the gate itself throws.
|
|
@@ -1236,8 +1249,11 @@ function evaluateHook(input, specsDir, opts) {
|
|
|
1236
1249
|
// a patch that cannot be read or applied is denied. When no target is denied, a payload with a path field or a
|
|
1237
1250
|
// shell command is then judged as before.
|
|
1238
1251
|
if (input.patchUnreadable) {
|
|
1239
|
-
|
|
1240
|
-
|
|
1252
|
+
const cause = input;
|
|
1253
|
+
// @implements A-SPEC-769.7 — four conditions, four sentences: shell marker, no-op update, and (below) the
|
|
1254
|
+
// path-missing sentence for a payload whose targets cannot be read; non-application has its own site.
|
|
1255
|
+
return { permissionDecision: 'deny', permissionDecisionReason: cause.patchUnreadableCause === 'shell-marker'
|
|
1256
|
+
? SHELL_MARKED_REASON : cause.patchUnreadableCause === 'no-op' ? patchNoopReason(cause.patchNoopPaths ?? []) : PATCH_UNREADABLE_REASON };
|
|
1241
1257
|
}
|
|
1242
1258
|
const patchTargets = input.tool_input.patch_targets;
|
|
1243
1259
|
if (patchTargets !== undefined && !input.malformed) {
|
|
@@ -2598,7 +2614,9 @@ function evaluateHook(input, specsDir, opts) {
|
|
|
2598
2614
|
if (!hint) {
|
|
2599
2615
|
const id = (0, approval_queue_1.approvalRequestId)('code-write', relPath);
|
|
2600
2616
|
if ((0, approval_queue_1.readQueue)(projectRoot).pending.some((request) => request.id === id)) {
|
|
2601
|
-
|
|
2617
|
+
// @implements A-SPEC-770.2 — the already-pending line names the same kind and workspace the filing line
|
|
2618
|
+
// did, so the two refusals of one request read the same (gate-isolation pins their equality).
|
|
2619
|
+
hint = (0, approval_queue_1.pendingRequestLine)(id, 'code-write', projectRoot);
|
|
2602
2620
|
}
|
|
2603
2621
|
}
|
|
2604
2622
|
return {
|
|
@@ -3,6 +3,33 @@ import { FreshnessLane, FreshnessReceipt, RefreshFailure } from '../refresh/fres
|
|
|
3
3
|
export declare function failureReason(error: unknown): string;
|
|
4
4
|
/** The detached worker must publish its own failure; the parent is intentionally non-blocking. */
|
|
5
5
|
export declare function recordRefreshFailure(root: string, generation: string, head: string | null, now: Date, failure?: RefreshFailure): FreshnessReceipt | null;
|
|
6
|
+
/**
|
|
7
|
+
* @implements A-SPEC-719.1 — the worker's own deadline. A live worker keeps its lease up to FRESHNESS_WORKER_MAX_MS;
|
|
8
|
+
* at that point it publishes `retry-at` (a no-op when a newer lease superseded it) and ends, so the next request
|
|
9
|
+
* spawns exactly one replacement instead of a worker running beside it.
|
|
10
|
+
*/
|
|
11
|
+
export declare function armWorkerDeadline(root: string, generation: string, opts: {
|
|
12
|
+
ms: number;
|
|
13
|
+
exit: () => void;
|
|
14
|
+
now?: () => Date;
|
|
15
|
+
}): void;
|
|
16
|
+
/**
|
|
17
|
+
* @implements A-SPEC-719.2 — the worker yields the machine. Measured 2026-10-15: each child ran at default priority with
|
|
18
|
+
* 16 ONNX threads (260–335 % CPU), so two of them kept the load above 330 and other sessions' Stop hooks over budget.
|
|
19
|
+
*/
|
|
20
|
+
export declare const REFRESH_CHILD_PRIORITY: number;
|
|
21
|
+
export declare const REFRESH_SUPERSEDE_POLL_MS = 15000;
|
|
22
|
+
/** Lowers the CURRENT process to the lowest scheduling priority; false when the OS refuses. */
|
|
23
|
+
export declare function lowerOwnPriority(setPriority?: (priority: number) => void): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* @implements A-SPEC-719.2 — a superseded worker ends within one poll instead of finishing its phase. Measured
|
|
26
|
+
* 2026-10-15: nine superseded jarvis workers kept embedding for 2–4 h because the lease was asked only between phases.
|
|
27
|
+
*/
|
|
28
|
+
export declare function armSupersedeWatch(root: string, generation: string, opts: {
|
|
29
|
+
intervalMs: number;
|
|
30
|
+
exit: () => void;
|
|
31
|
+
owns?: (root: string, generation: string) => boolean;
|
|
32
|
+
}): void;
|
|
6
33
|
export interface RefreshChildDeps {
|
|
7
34
|
head: (root: string) => string | null;
|
|
8
35
|
refreshGraph: (root: string) => Promise<unknown>;
|
|
@@ -33,13 +33,20 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.REFRESH_SUPERSEDE_POLL_MS = exports.REFRESH_CHILD_PRIORITY = void 0;
|
|
36
37
|
exports.failureReason = failureReason;
|
|
37
38
|
exports.recordRefreshFailure = recordRefreshFailure;
|
|
39
|
+
exports.armWorkerDeadline = armWorkerDeadline;
|
|
40
|
+
exports.lowerOwnPriority = lowerOwnPriority;
|
|
41
|
+
exports.armSupersedeWatch = armSupersedeWatch;
|
|
38
42
|
exports.runRefreshChild = runRefreshChild;
|
|
39
43
|
exports.defaultRefreshChildDeps = defaultRefreshChildDeps;
|
|
40
44
|
// @implements A-SPEC-719, A-SPEC-734
|
|
41
45
|
// @implements A-SPEC-566.4
|
|
42
46
|
// @implements A-SPEC-768.4
|
|
47
|
+
// @implements A-SPEC-719.1
|
|
48
|
+
// @implements A-SPEC-719.2
|
|
49
|
+
// @implements A-SPEC-769.9
|
|
43
50
|
/**
|
|
44
51
|
* The detached refresh child — the ONLY place this slice touches the scan/build machinery. Spawned
|
|
45
52
|
* by `maybeSpawnRtmRefresh` (rtm-refresh.ts) outside any turn; nothing in the hook path imports
|
|
@@ -47,6 +54,7 @@ exports.defaultRefreshChildDeps = defaultRefreshChildDeps;
|
|
|
47
54
|
* rtm_impact's warm path IS the refresh: hash-cached scan, reusable-graph rebuild when stale.
|
|
48
55
|
*/
|
|
49
56
|
const fs = __importStar(require("node:fs"));
|
|
57
|
+
const os = __importStar(require("node:os"));
|
|
50
58
|
const path = __importStar(require("node:path"));
|
|
51
59
|
const freshness_coordinator_1 = require("../refresh/freshness-coordinator");
|
|
52
60
|
const currentHead = (root) => {
|
|
@@ -71,6 +79,58 @@ function recordRefreshFailure(root, generation, head, now, failure) {
|
|
|
71
79
|
...(failure ? { failure } : {}), // A-SPEC-768.4
|
|
72
80
|
}, now);
|
|
73
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* @implements A-SPEC-719.1 — the worker's own deadline. A live worker keeps its lease up to FRESHNESS_WORKER_MAX_MS;
|
|
84
|
+
* at that point it publishes `retry-at` (a no-op when a newer lease superseded it) and ends, so the next request
|
|
85
|
+
* spawns exactly one replacement instead of a worker running beside it.
|
|
86
|
+
*/
|
|
87
|
+
function armWorkerDeadline(root, generation, opts) {
|
|
88
|
+
const timer = setTimeout(() => {
|
|
89
|
+
try {
|
|
90
|
+
recordRefreshFailure(root, generation, currentHead(root), (opts.now ?? (() => new Date()))(), { stage: 'child', reason: `worker exceeded ${opts.ms} ms` });
|
|
91
|
+
}
|
|
92
|
+
catch { /* fail-soft: ending is what matters */ }
|
|
93
|
+
opts.exit();
|
|
94
|
+
}, opts.ms);
|
|
95
|
+
timer.unref?.();
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* @implements A-SPEC-719.2 — the worker yields the machine. Measured 2026-10-15: each child ran at default priority with
|
|
99
|
+
* 16 ONNX threads (260–335 % CPU), so two of them kept the load above 330 and other sessions' Stop hooks over budget.
|
|
100
|
+
*/
|
|
101
|
+
exports.REFRESH_CHILD_PRIORITY = os.constants.priority.PRIORITY_LOW;
|
|
102
|
+
exports.REFRESH_SUPERSEDE_POLL_MS = 15_000;
|
|
103
|
+
/** Lowers the CURRENT process to the lowest scheduling priority; false when the OS refuses. */
|
|
104
|
+
function lowerOwnPriority(setPriority = (p) => os.setPriority(p)) {
|
|
105
|
+
try {
|
|
106
|
+
setPriority(exports.REFRESH_CHILD_PRIORITY);
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* @implements A-SPEC-719.2 — a superseded worker ends within one poll instead of finishing its phase. Measured
|
|
115
|
+
* 2026-10-15: nine superseded jarvis workers kept embedding for 2–4 h because the lease was asked only between phases.
|
|
116
|
+
*/
|
|
117
|
+
function armSupersedeWatch(root, generation, opts) {
|
|
118
|
+
const owns = opts.owns ?? freshness_coordinator_1.ownsLease;
|
|
119
|
+
const timer = setInterval(() => {
|
|
120
|
+
let current = true;
|
|
121
|
+
try {
|
|
122
|
+
current = owns(root, generation);
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
current = true;
|
|
126
|
+
} // an unreadable receipt is not a supersession
|
|
127
|
+
if (current)
|
|
128
|
+
return;
|
|
129
|
+
clearInterval(timer);
|
|
130
|
+
opts.exit();
|
|
131
|
+
}, opts.intervalMs);
|
|
132
|
+
timer.unref?.();
|
|
133
|
+
}
|
|
74
134
|
/**
|
|
75
135
|
* One refresh run for one lease generation. Every phase that writes is preceded by a lease check,
|
|
76
136
|
* so a superseded worker, or one whose root was removed, stops without writing (A-SPEC-724). Any
|
|
@@ -144,9 +204,8 @@ function defaultRefreshChildDeps(env = process.env) {
|
|
|
144
204
|
refreshSource: async (root) => {
|
|
145
205
|
const { refreshSemanticVectors } = require('../mcp/handlers/graph-operations');
|
|
146
206
|
const { CpgScanner } = require('../cpg/cpg-scanner');
|
|
147
|
-
const { ScanFileCache } = require('../cpg/scan-cache');
|
|
148
|
-
const
|
|
149
|
-
const dir = path.join(require('node:os').tmpdir(), 'holmes-cpg-cache-' + crypto.createHash('sha256').update(root).digest('hex').slice(0, 16));
|
|
207
|
+
const { ScanFileCache, scanCacheDirFor } = require('../cpg/scan-cache');
|
|
208
|
+
const dir = scanCacheDirFor(root); // A-SPEC-769.9 — the directory the Stop hook's scan shares
|
|
150
209
|
return refreshSemanticVectors(root, env, undefined, () => new CpgScanner(undefined, new ScanFileCache(dir)).scan(root, root));
|
|
151
210
|
},
|
|
152
211
|
refreshRequirement: async (root) => {
|
|
@@ -167,6 +226,13 @@ if (require.main === module) {
|
|
|
167
226
|
require('../project/regular-file-guard').installProcessGuards();
|
|
168
227
|
const root = process.argv[2];
|
|
169
228
|
const generation = process.argv[3];
|
|
229
|
+
lowerOwnPriority(); // A-SPEC-719.2 — background work yields to foreground sessions
|
|
230
|
+
// @implements A-SPEC-719.1 — never outlive the lease cap
|
|
231
|
+
if (root && generation)
|
|
232
|
+
armWorkerDeadline(root, generation, { ms: freshness_coordinator_1.FRESHNESS_WORKER_MAX_MS, exit: () => process.exit(0) });
|
|
233
|
+
// @implements A-SPEC-719.2 — end promptly once superseded
|
|
234
|
+
if (root && generation)
|
|
235
|
+
armSupersedeWatch(root, generation, { intervalMs: exports.REFRESH_SUPERSEDE_POLL_MS, exit: () => process.exit(0) });
|
|
170
236
|
// fail-soft: a failed refresh leaves the old graph, which the advisory tolerates
|
|
171
237
|
if (root && generation)
|
|
172
238
|
void runRefreshChild(root, generation, defaultRefreshChildDeps()).catch(() => undefined);
|
|
@@ -37,6 +37,7 @@ exports.RTM_REFRESH_MARKER = exports.RTM_REFRESH_TTL_MS = void 0;
|
|
|
37
37
|
exports.maybeSpawnRtmRefresh = maybeSpawnRtmRefresh;
|
|
38
38
|
exports.requestBackgroundFreshness = requestBackgroundFreshness;
|
|
39
39
|
// @implements A-SPEC-724, A-SPEC-723, A-SPEC-719, A-SPEC-734
|
|
40
|
+
// @implements A-SPEC-719.1
|
|
40
41
|
/**
|
|
41
42
|
* Graph freshness, kept by the product itself. The impact advisory's quality factor was MEASURED to
|
|
42
43
|
* be staleness (an 8-day-old graph found 7 advisories; a 1-second reindex found 17), so the Stop
|
|
@@ -93,6 +94,13 @@ function maybeSpawnRtmRefresh(opts) {
|
|
|
93
94
|
try {
|
|
94
95
|
const child = opts.spawn(opts.execPath, [opts.scriptPath, opts.root, decision.receipt.generation], { detached: true, stdio: 'ignore' });
|
|
95
96
|
child?.unref?.();
|
|
97
|
+
// @implements A-SPEC-719.1 — the lease names its worker, so a live refresh is not taken for a crashed one.
|
|
98
|
+
if (typeof child?.pid === 'number') {
|
|
99
|
+
try {
|
|
100
|
+
(0, freshness_coordinator_1.recordLeaseWorker)(opts.root, decision.receipt.generation, child.pid);
|
|
101
|
+
}
|
|
102
|
+
catch { /* fail-soft: the 2-minute lease still bounds it */ }
|
|
103
|
+
}
|
|
96
104
|
return { status: 'spawned', generation: decision.receipt.generation };
|
|
97
105
|
}
|
|
98
106
|
catch {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { PendingRequest } from '../governance/approval-queue';
|
|
2
|
+
/** @implements A-SPEC-769.11 — the stage line prints from 9 s: the 18–29 s range of the 2026-10-15 incident stays visible. */
|
|
3
|
+
export declare const STOP_TIMING_REPORT_MS = 9000;
|
|
2
4
|
export declare const STOP_NOTICES: Set<string>;
|
|
3
5
|
import { Spec } from '../spec/spec-parser';
|
|
4
6
|
import type { TestOutcome } from '../review/test-runner';
|
|
@@ -393,6 +395,12 @@ export declare function collectForbiddenEdgeJudgement(specs: readonly Spec[], sc
|
|
|
393
395
|
* @implements A-SPEC-693 — `shared` is a scan the caller already made. When given it is BELIEVED
|
|
394
396
|
* and no second scan runs, so one turn pays for one scan however many judgements read it.
|
|
395
397
|
*/
|
|
398
|
+
/**
|
|
399
|
+
* @implements A-SPEC-769.9 — the turn's ONE shared scan (A-SPEC-693), served from the content-hash scan cache the
|
|
400
|
+
* refresh child already keeps. Measured 2026-10-15 at load ~300: uncached 23.0 s against an 18 s budget, refusing every
|
|
401
|
+
* Stop; through the cache 0.48 s warm. Only unchanged files are served from it.
|
|
402
|
+
*/
|
|
403
|
+
export declare function stopSharedScan(root: string, cache?: import('../cpg/scan-cache').ScanFileCache): ScannedFile[];
|
|
396
404
|
export declare function scanCodeCycles(root: string, shared?: ScannedFile[]): {
|
|
397
405
|
current: import('../cpg/cycle-detect').Cycle[];
|
|
398
406
|
allowed: string[];
|