@holmes-lab/holmes-kit 0.34.0 → 0.35.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 +89 -0
- package/README.md +6 -0
- package/dist/.build-id +1 -1
- package/dist/holmes/cli/codex-oracle.js +36 -2
- package/dist/holmes/cli/doctor.d.ts +14 -1
- package/dist/holmes/cli/doctor.js +335 -71
- package/dist/holmes/cli/index.d.ts +1 -1
- package/dist/holmes/cli/index.js +38 -5
- package/dist/holmes/cli/runtime-binding-approval.d.ts +7 -0
- package/dist/holmes/cli/runtime-binding-approval.js +102 -0
- package/dist/holmes/cli/runtime-binding.d.ts +29 -0
- package/dist/holmes/cli/runtime-binding.js +570 -0
- package/dist/holmes/governance/approval-queue.d.ts +2 -0
- package/dist/holmes/governance/approval-queue.js +11 -4
- package/dist/holmes/guardrail/impact-gate.js +90 -5
- package/dist/holmes/guardrail/linear-match.js +8 -1
- package/dist/holmes/guardrail/risk-classifier.d.ts +6 -0
- package/dist/holmes/guardrail/risk-classifier.js +68 -23
- package/dist/holmes/guardrail/shell-argument-roles.d.ts +15 -0
- package/dist/holmes/guardrail/shell-argument-roles.js +209 -0
- package/dist/holmes/guardrail/shell-syntax.d.ts +20 -0
- package/dist/holmes/guardrail/shell-syntax.js +489 -0
- package/dist/holmes/guardrail/shell-words.d.ts +2 -18
- package/dist/holmes/guardrail/shell-words.js +67 -442
- package/dist/holmes/guardrail/write-target.d.ts +54 -0
- package/dist/holmes/guardrail/write-target.js +327 -1
- package/dist/holmes/hooks/pre-tool-use.d.ts +12 -0
- package/dist/holmes/hooks/pre-tool-use.js +377 -66
- package/dist/holmes/mcp/handlers/maintenance-analysis.js +4 -2
- package/dist/holmes/mcp/handlers/test-execution.js +6 -2
- package/dist/holmes/mcp/handlers.d.ts +9 -1
- package/dist/holmes/mcp/handlers.js +6 -4
- package/dist/holmes/mcp/maintenance-evidence.d.ts +16 -1
- package/dist/holmes/mcp/maintenance-evidence.js +29 -3
- package/dist/holmes/mcp/operator-recovery.d.ts +9 -0
- package/dist/holmes/mcp/operator-recovery.js +63 -0
- package/dist/holmes/rtm/test-scope.d.ts +9 -0
- package/dist/holmes/rtm/test-scope.js +284 -14
- package/dist/holmes/runtime/binding.d.ts +30 -0
- package/dist/holmes/runtime/binding.js +164 -0
- package/dist/holmes/runtime/dispatch.d.ts +9 -0
- package/dist/holmes/runtime/dispatch.js +169 -0
- package/dist/holmes/runtime/hook-process.d.ts +11 -0
- package/dist/holmes/runtime/hook-process.js +130 -0
- package/docs/install-guide.md +65 -0
- package/package.json +1 -1
|
@@ -33,10 +33,16 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.AX_CLIMB_BASES_MAX = exports.WIRING_FILE_NAMES = exports.WIRING_DIR_NAMES = exports.GOVERNANCE_STORE_LABEL = exports.AX_PROTECTED_CHILDREN = exports.PATH_FIELDS = exports.READ_ONLY_TOOLS = void 0;
|
|
36
|
+
exports.AX_CLIMB_BASES_MAX = exports.WIRING_FILE_NAMES = exports.WIRING_DIR_NAMES = exports.GOVERNANCE_STORE_LABEL = exports.AX_PROTECTED_CHILDREN = exports.PATCH_TARGETS_MAX = exports.PATH_FIELDS = exports.READ_ONLY_TOOLS = void 0;
|
|
37
37
|
exports.absoluteKindOf = absoluteKindOf;
|
|
38
38
|
exports.foldsCaseBySyntax = foldsCaseBySyntax;
|
|
39
39
|
exports.writesFiles = writesFiles;
|
|
40
|
+
exports.hasPatchEnvelope = hasPatchEnvelope;
|
|
41
|
+
exports.isWholePatch = isWholePatch;
|
|
42
|
+
exports.patchAmbiguous = patchAmbiguous;
|
|
43
|
+
exports.canonicalPatch = canonicalPatch;
|
|
44
|
+
exports.patchTargetsOf = patchTargetsOf;
|
|
45
|
+
exports.applyPatchUpdate = applyPatchUpdate;
|
|
40
46
|
exports.pathFlavorFor = pathFlavorFor;
|
|
41
47
|
exports.resolveTarget = resolveTarget;
|
|
42
48
|
exports.isProtectedTarget = isProtectedTarget;
|
|
@@ -130,6 +136,326 @@ function writesFiles(toolName, input) {
|
|
|
130
136
|
const name = (typeof toolName === 'string' ? toolName : '').toLowerCase();
|
|
131
137
|
return !exports.READ_ONLY_TOOLS.includes(name);
|
|
132
138
|
}
|
|
139
|
+
const PATCH_HEADERS = [
|
|
140
|
+
['*** Add File:', 'add'], ['*** Update File:', 'update'], ['*** Delete File:', 'delete'], ['*** Move to:', 'move'],
|
|
141
|
+
];
|
|
142
|
+
const PATCH_BEGIN = '*** Begin Patch';
|
|
143
|
+
const PATCH_EOF = '*** End of File';
|
|
144
|
+
/** More targets than this is not judged target by target; the caller refuses the patch (A-SPEC-163.2). */
|
|
145
|
+
exports.PATCH_TARGETS_MAX = 64;
|
|
146
|
+
const unCR = (raw) => (raw.endsWith('\r') ? raw.slice(0, -1) : raw);
|
|
147
|
+
/** A header is recognised only at the start of a line (A-SPEC-163.2 rule 2). */
|
|
148
|
+
const patchHeaderOf = (line) => {
|
|
149
|
+
if (!line.startsWith('*** '))
|
|
150
|
+
return null;
|
|
151
|
+
for (const [prefix, kind] of PATCH_HEADERS)
|
|
152
|
+
if (line.startsWith(prefix))
|
|
153
|
+
return { path: line.slice(prefix.length).trim(), kind };
|
|
154
|
+
return null;
|
|
155
|
+
};
|
|
156
|
+
/** Whether a string carries a patch envelope: a begin line or any file header, at any indentation. */
|
|
157
|
+
function hasPatchEnvelope(text) {
|
|
158
|
+
if (!text.includes('*** '))
|
|
159
|
+
return false;
|
|
160
|
+
for (const raw of text.split('\n')) {
|
|
161
|
+
const s = raw.trimStart();
|
|
162
|
+
if (s.startsWith(PATCH_BEGIN) || patchHeaderOf(s) !== null)
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
/** A whole patch: the first non-blank line, trimmed, is the begin line (A-SPEC-163.2 rule 1). */
|
|
168
|
+
function isWholePatch(text) {
|
|
169
|
+
if (!text.includes(PATCH_BEGIN))
|
|
170
|
+
return false;
|
|
171
|
+
for (const raw of text.split('\n')) {
|
|
172
|
+
const s = raw.trim();
|
|
173
|
+
if (s === '')
|
|
174
|
+
continue;
|
|
175
|
+
return s === PATCH_BEGIN;
|
|
176
|
+
}
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* An indented line that would be a header after trimming: harnesses differ on whether it is a header or a context
|
|
181
|
+
* line, so the patch cannot be read one way (A-SPEC-163.2 rule 2).
|
|
182
|
+
*/
|
|
183
|
+
function patchAmbiguous(text) {
|
|
184
|
+
if (!text.includes('*** '))
|
|
185
|
+
return false;
|
|
186
|
+
let adding = false;
|
|
187
|
+
for (const raw of text.split('\n')) {
|
|
188
|
+
const line = unCR(raw);
|
|
189
|
+
if (line.startsWith('*** ')) {
|
|
190
|
+
if (!line.startsWith(PATCH_EOF))
|
|
191
|
+
adding = line.startsWith('*** Add File:');
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
// @implements A-SPEC-163.3 (rule 3) — behind ANY leading white space or control character, not only what
|
|
195
|
+
// `trimStart` strips: a parser that trims more reads a header where this one read content.
|
|
196
|
+
if (patchHeaderOf(line.replace(PATCH_LEAD, '')) !== null)
|
|
197
|
+
return true;
|
|
198
|
+
// @implements A-SPEC-163.3 (rule 2) — an add block holds only `+` lines.
|
|
199
|
+
if (adding && !line.startsWith('+'))
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
const codeClass = (ranges) => {
|
|
205
|
+
const unit = (n) => String.fromCharCode(0x5c) + 'u' + n.toString(16).padStart(4, '0');
|
|
206
|
+
return ranges.map((r) => (typeof r === 'number' ? unit(r) : unit(r[0]) + '-' + unit(r[1]))).join('');
|
|
207
|
+
};
|
|
208
|
+
/** C0/C1 controls, NEL, and the zero-width and byte-order marks: what `\s` does not cover but a parser may trim. */
|
|
209
|
+
const PATCH_INVISIBLE = [[0x0000, 0x001f], [0x007f, 0x009f], [0x200b, 0x200d], 0x2060, 0xfeff];
|
|
210
|
+
/** Non-ASCII spaces (a plain space is not one of them). */
|
|
211
|
+
const PATCH_SPACES = [0x00a0, 0x1680, [0x2000, 0x200a], 0x202f, 0x205f, 0x3000];
|
|
212
|
+
/** Leading characters some parser may trim: Unicode white space, NEL, zero-width and byte-order marks, C0/C1 controls. */
|
|
213
|
+
const PATCH_LEAD = new RegExp('^[' + String.fromCharCode(0x5c) + 's' + codeClass(PATCH_INVISIBLE) + ']+');
|
|
214
|
+
const PATCH_EDGE = new RegExp('[' + String.fromCharCode(0x5c) + 's' + codeClass(PATCH_INVISIBLE) + ']');
|
|
215
|
+
const PATCH_DASHES = new RegExp('[' + codeClass([[0x2010, 0x2015], 0x2212]) + ']', 'g');
|
|
216
|
+
const PATCH_SINGLE_QUOTES = new RegExp('[' + codeClass([[0x2018, 0x201b]]) + ']', 'g');
|
|
217
|
+
const PATCH_DOUBLE_QUOTES = new RegExp('[' + codeClass([[0x201c, 0x201f]]) + ']', 'g');
|
|
218
|
+
/** A carriage return, a vertical tab, a form feed, NEL, and the line and paragraph separators. */
|
|
219
|
+
const PATCH_LINE_BREAK = new RegExp('[' + codeClass([[0x000b, 0x000d], 0x0085, 0x2028, 0x2029]) + ']');
|
|
220
|
+
const PATCH_SPACE_FOLD = new RegExp('[' + codeClass(PATCH_SPACES) + ']', 'g');
|
|
221
|
+
/**
|
|
222
|
+
* The loosest reading of a line any patch tool is known to compare by: surrounding white space and controls removed,
|
|
223
|
+
* and dashes, quotation marks and non-ASCII spaces folded to ASCII (A-SPEC-163.4 rule 4). Used only to COUNT places.
|
|
224
|
+
*/
|
|
225
|
+
function patchLoose(line) {
|
|
226
|
+
// The tail is walked by index: an end-anchored repeat would re-scan every run of spaces inside the line.
|
|
227
|
+
let end = line.length;
|
|
228
|
+
while (end > 0 && PATCH_EDGE.test(line.charAt(end - 1)))
|
|
229
|
+
end--;
|
|
230
|
+
return line.slice(0, end).replace(PATCH_LEAD, '')
|
|
231
|
+
.replace(PATCH_DASHES, '-').replace(PATCH_SINGLE_QUOTES, "'").replace(PATCH_DOUBLE_QUOTES, '"').replace(PATCH_SPACE_FOLD, ' ');
|
|
232
|
+
}
|
|
233
|
+
/** A character a header path may not hold: quotes, expansion and glob characters, a backslash, controls, any white space but a plain space. */
|
|
234
|
+
const PATCH_PATH_FORBIDDEN = new RegExp('["' + "'" + '`$*?' + String.fromCharCode(0x5c, 0x5c) + codeClass(PATCH_INVISIBLE) + codeClass(PATCH_SPACES)
|
|
235
|
+
+ codeClass([0x0009, 0x2028, 0x2029]) + ']');
|
|
236
|
+
const PATCH_END = '*** End Patch';
|
|
237
|
+
const PATCH_FILE_HEADERS = [
|
|
238
|
+
['*** Add File: ', 'add'], ['*** Update File: ', 'update'], ['*** Delete File: ', 'delete'],
|
|
239
|
+
];
|
|
240
|
+
const PATCH_MOVE = '*** Move to: ';
|
|
241
|
+
const canonicalPath = (p) => p !== '' && !p.startsWith(' ') && !p.endsWith(' ') && !PATCH_PATH_FORBIDDEN.test(p);
|
|
242
|
+
/**
|
|
243
|
+
* Whether a text is the one patch form the gate judges.
|
|
244
|
+
*
|
|
245
|
+
* @implements A-SPEC-163.4 (rule 1)
|
|
246
|
+
* Four review rounds each found a shape the previous list of refused shapes did not name. This states what IS read:
|
|
247
|
+
* begin and end lines, the three file headers, a move directly after an update header, `+` lines in an add, and
|
|
248
|
+
* `@@` / ` ` / `+` / `-` / end-of-file lines in an update. Any other line — an empty one, an unknown `*** ` line, a
|
|
249
|
+
* header behind anything — makes the text not canonical, and the caller refuses it. A line-by-line prefix walk: no
|
|
250
|
+
* pattern over the whole text, nothing to back-track on.
|
|
251
|
+
*/
|
|
252
|
+
function canonicalPatch(text) {
|
|
253
|
+
const lines = text.split('\n').map(unCR);
|
|
254
|
+
let start = 0;
|
|
255
|
+
let end = lines.length;
|
|
256
|
+
while (start < end && lines[start].trim() === '')
|
|
257
|
+
start++;
|
|
258
|
+
while (end > start && lines[end - 1].trim() === '')
|
|
259
|
+
end--;
|
|
260
|
+
if (end - start < 3 || lines[start] !== PATCH_BEGIN || lines[end - 1] !== PATCH_END)
|
|
261
|
+
return false;
|
|
262
|
+
let block = null;
|
|
263
|
+
let content = 0; // `+` lines of an add, or `+`/`-` lines of an update
|
|
264
|
+
let sinceHeader = 0; // lines since the update header (a move must be the first)
|
|
265
|
+
let moved = false;
|
|
266
|
+
const closes = () => block === null || block === 'delete' || content > 0;
|
|
267
|
+
for (let i = start + 1; i < end - 1; i++) {
|
|
268
|
+
const line = lines[i];
|
|
269
|
+
// @implements A-SPEC-163.5 (rule 4) — a tool that splits lines on more than a line feed would read the rest of
|
|
270
|
+
// this line as a line of its own, and a header there as a target.
|
|
271
|
+
if (PATCH_LINE_BREAK.test(line))
|
|
272
|
+
return false;
|
|
273
|
+
if (line === PATCH_BEGIN || line === PATCH_END)
|
|
274
|
+
return false;
|
|
275
|
+
if (line.startsWith('*** ')) {
|
|
276
|
+
if (line === PATCH_EOF) {
|
|
277
|
+
if (block !== 'update')
|
|
278
|
+
return false;
|
|
279
|
+
sinceHeader++;
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
if (line.startsWith(PATCH_MOVE)) {
|
|
283
|
+
if (block !== 'update' || sinceHeader !== 0 || moved || !canonicalPath(line.slice(PATCH_MOVE.length)))
|
|
284
|
+
return false;
|
|
285
|
+
moved = true;
|
|
286
|
+
sinceHeader++;
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
const header = PATCH_FILE_HEADERS.find(([prefix]) => line.startsWith(prefix));
|
|
290
|
+
if (header === undefined || !canonicalPath(line.slice(header[0].length)) || !closes())
|
|
291
|
+
return false;
|
|
292
|
+
block = header[1];
|
|
293
|
+
content = 0;
|
|
294
|
+
sinceHeader = 0;
|
|
295
|
+
moved = false;
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
if (block === 'add') {
|
|
299
|
+
if (!line.startsWith('+'))
|
|
300
|
+
return false;
|
|
301
|
+
content++;
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
if (block !== 'update')
|
|
305
|
+
return false;
|
|
306
|
+
sinceHeader++;
|
|
307
|
+
if (line === '@@' || line.startsWith('@@ '))
|
|
308
|
+
continue;
|
|
309
|
+
const head = line.charAt(0);
|
|
310
|
+
if (head === '+' || head === '-')
|
|
311
|
+
content++;
|
|
312
|
+
else if (head !== ' ')
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
return block !== null && closes();
|
|
316
|
+
}
|
|
317
|
+
/** Every header is a target, in order; nothing is merged or dropped by path (A-SPEC-163.2 rule 2). */
|
|
318
|
+
function patchTargetsOf(text) {
|
|
319
|
+
if (!text.includes('*** '))
|
|
320
|
+
return [];
|
|
321
|
+
const out = [];
|
|
322
|
+
let adding = null;
|
|
323
|
+
let hunked = null;
|
|
324
|
+
for (const raw of text.split('\n')) {
|
|
325
|
+
const line = unCR(raw);
|
|
326
|
+
if (line.startsWith('*** ') && !line.startsWith(PATCH_EOF)) {
|
|
327
|
+
const header = patchHeaderOf(line);
|
|
328
|
+
const previous = hunked;
|
|
329
|
+
adding = null;
|
|
330
|
+
hunked = null;
|
|
331
|
+
if (header === null)
|
|
332
|
+
continue;
|
|
333
|
+
const target = { path: header.path, kind: header.kind };
|
|
334
|
+
if (header.kind === 'add') {
|
|
335
|
+
target.content = '';
|
|
336
|
+
adding = target;
|
|
337
|
+
}
|
|
338
|
+
if (header.kind === 'update') {
|
|
339
|
+
target.hunk = '';
|
|
340
|
+
hunked = target;
|
|
341
|
+
}
|
|
342
|
+
if (header.kind === 'move') {
|
|
343
|
+
// A move belongs to the update it follows directly; anywhere else it has no file to read.
|
|
344
|
+
if (previous !== null && previous.kind === 'update' && previous.hunk === '') {
|
|
345
|
+
target.from = previous.path;
|
|
346
|
+
previous.movedTo = header.path;
|
|
347
|
+
}
|
|
348
|
+
target.hunk = '';
|
|
349
|
+
hunked = target;
|
|
350
|
+
}
|
|
351
|
+
out.push(target);
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
if (adding !== null)
|
|
355
|
+
adding.content += (line.startsWith('+') ? line.slice(1) : line) + '\n';
|
|
356
|
+
else if (hunked !== null)
|
|
357
|
+
hunked.hunk += line + '\n';
|
|
358
|
+
}
|
|
359
|
+
return out;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* The file an update hunk produces, or null when it does not apply.
|
|
363
|
+
*
|
|
364
|
+
* @implements A-SPEC-163.2 (rule 3)
|
|
365
|
+
* Chunks are separated by lines starting with `@@`; a chunk's old text is its ` ` and `-` lines. A kept line stays
|
|
366
|
+
* as the file has it. Plain line comparison: no pattern, nothing to back-track on. Where a chunk goes is A-SPEC-163.3's
|
|
367
|
+
* rule (below): its one place in the file, or no result.
|
|
368
|
+
*/
|
|
369
|
+
function applyPatchUpdate(original, hunk) {
|
|
370
|
+
const endsWithNewline = original.endsWith('\n');
|
|
371
|
+
const lines = original.split('\n');
|
|
372
|
+
if (endsWithNewline)
|
|
373
|
+
lines.pop();
|
|
374
|
+
const chunks = [];
|
|
375
|
+
let current = null;
|
|
376
|
+
const hunkLines = hunk.split('\n');
|
|
377
|
+
if (hunkLines.length > 0 && hunkLines[hunkLines.length - 1] === '')
|
|
378
|
+
hunkLines.pop();
|
|
379
|
+
for (const raw of hunkLines) {
|
|
380
|
+
const line = unCR(raw);
|
|
381
|
+
if (line.startsWith(PATCH_EOF))
|
|
382
|
+
continue;
|
|
383
|
+
if (line.startsWith('@@')) {
|
|
384
|
+
const seek = line.slice(2).trim();
|
|
385
|
+
current = { seek: seek === '' ? null : seek, ops: [] };
|
|
386
|
+
chunks.push(current);
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
if (current === null) {
|
|
390
|
+
current = { seek: null, ops: [] };
|
|
391
|
+
chunks.push(current);
|
|
392
|
+
}
|
|
393
|
+
const head = line.charAt(0);
|
|
394
|
+
if (line === '')
|
|
395
|
+
current.ops.push({ kind: ' ', text: '', empty: true });
|
|
396
|
+
else if (head === ' ' || head === '-' || head === '+')
|
|
397
|
+
current.ops.push({ kind: head, text: line.slice(1) });
|
|
398
|
+
else
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
// @implements A-SPEC-163.3 (rule 4) — a chunk is applied only where its old text is found exactly once in the whole
|
|
402
|
+
// file, compared with surrounding white space ignored (the loosest comparison any parser uses), and in file order.
|
|
403
|
+
// Then exact-first, `@@` seeking and end-of-file anchoring all choose the same place, so the result does not depend
|
|
404
|
+
// on which parser applies it. No old text (an add-only chunk), none found, or two found: no one result.
|
|
405
|
+
// The loose reading of each file line is computed once and spliced beside `lines`: per chunk it would be
|
|
406
|
+
// chunks x lines regex passes inside a hook with a deadline.
|
|
407
|
+
const loose = lines.map(patchLoose);
|
|
408
|
+
let pos = 0;
|
|
409
|
+
for (const chunk of chunks) {
|
|
410
|
+
const blank = (o) => o.empty === true;
|
|
411
|
+
const ops = chunk.ops.slice();
|
|
412
|
+
while (ops.length > 0 && blank(ops[0]))
|
|
413
|
+
ops.shift();
|
|
414
|
+
while (ops.length > 0 && blank(ops[ops.length - 1]))
|
|
415
|
+
ops.pop();
|
|
416
|
+
if (ops.length === 0)
|
|
417
|
+
continue;
|
|
418
|
+
const oldExact = ops.filter((o) => o.kind !== '+').map((o) => o.text);
|
|
419
|
+
if (oldExact.length === 0)
|
|
420
|
+
return null;
|
|
421
|
+
const old = oldExact.map(patchLoose);
|
|
422
|
+
let at = -1;
|
|
423
|
+
for (let i = 0; i + old.length <= lines.length; i++) {
|
|
424
|
+
let ok = true;
|
|
425
|
+
for (let j = 0; j < old.length; j++)
|
|
426
|
+
if (loose[i + j] !== old[j]) {
|
|
427
|
+
ok = false;
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
430
|
+
if (!ok)
|
|
431
|
+
continue;
|
|
432
|
+
if (at !== -1)
|
|
433
|
+
return null;
|
|
434
|
+
at = i;
|
|
435
|
+
}
|
|
436
|
+
if (at === -1 || at < pos)
|
|
437
|
+
return null;
|
|
438
|
+
// @implements A-SPEC-163.4 (rule 4) — the one loose place must also be an exact one: then the lines the patch
|
|
439
|
+
// keeps are the same text in the file and in the patch, whichever of the two a tool writes back.
|
|
440
|
+
for (let j = 0; j < oldExact.length; j++)
|
|
441
|
+
if (lines[at + j] !== oldExact[j])
|
|
442
|
+
return null;
|
|
443
|
+
const replacement = [];
|
|
444
|
+
let k = at;
|
|
445
|
+
for (const op of ops) {
|
|
446
|
+
if (op.kind === ' ')
|
|
447
|
+
replacement.push(lines[k++]);
|
|
448
|
+
else if (op.kind === '-')
|
|
449
|
+
k++;
|
|
450
|
+
else
|
|
451
|
+
replacement.push(op.text);
|
|
452
|
+
}
|
|
453
|
+
lines.splice(at, old.length, ...replacement);
|
|
454
|
+
loose.splice(at, old.length, ...replacement.map(patchLoose));
|
|
455
|
+
pos = at + replacement.length;
|
|
456
|
+
}
|
|
457
|
+
return lines.join('\n') + (endsWithNewline ? '\n' : '');
|
|
458
|
+
}
|
|
133
459
|
/**
|
|
134
460
|
* The file a raw path actually names.
|
|
135
461
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Spec } from '../spec/spec-parser';
|
|
2
|
+
import { PatchTarget } from '../guardrail/write-target';
|
|
2
3
|
import { Approval } from '../guardrail/risk-gate';
|
|
3
4
|
import { RiskAction, RiskAssessment, RmSignal } from '../guardrail/risk-types';
|
|
4
5
|
import { type PreEditEvidenceMode } from '../guardrail/impact-gate';
|
|
@@ -71,6 +72,8 @@ export interface HookInput {
|
|
|
71
72
|
}>;
|
|
72
73
|
/** @implements A-SPEC-728 (round 17) — Codex's shell tool runs the command in `workdir` when given. */
|
|
73
74
|
workdir?: string;
|
|
75
|
+
/** @implements A-SPEC-163.1 — the files a patch tool names in its patch text; judged one by one like `file_path`. */
|
|
76
|
+
patch_targets?: PatchTarget[];
|
|
74
77
|
};
|
|
75
78
|
/**
|
|
76
79
|
* @implements A-SPEC-728 (round 17) — the directory the harness runs the shell in (every harness
|
|
@@ -88,7 +91,15 @@ export interface HookInput {
|
|
|
88
91
|
* Recording the fact makes it independent of which tool asked.
|
|
89
92
|
*/
|
|
90
93
|
malformed?: boolean;
|
|
94
|
+
/** @implements A-SPEC-163.2 — the payload carries a patch whose targets cannot be read one way; denied whichever tool sent it. */
|
|
95
|
+
patchUnreadable?: boolean;
|
|
91
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* @implements A-SPEC-753.2 — what a denial leaves in the provenance ledger: the reason up to the operator command.
|
|
99
|
+
* The installer refusal (A-SPEC-753.1) carries the raw command after ` Operator: ` for the operator to run; the ledger
|
|
100
|
+
* is the one artefact meant to carry no raw command. The reason printed to the harness is unchanged.
|
|
101
|
+
*/
|
|
102
|
+
export declare function ledgerSummaryOf(reason: string): string;
|
|
92
103
|
export declare function normalizeHookInput(raw: unknown): HookInput;
|
|
93
104
|
/**
|
|
94
105
|
* Which way to fail when the gate itself throws.
|
|
@@ -193,6 +204,7 @@ export declare function evaluateHook(input: {
|
|
|
193
204
|
new_string?: string;
|
|
194
205
|
command?: string;
|
|
195
206
|
workdir?: string;
|
|
207
|
+
patch_targets?: PatchTarget[];
|
|
196
208
|
};
|
|
197
209
|
cwd?: string;
|
|
198
210
|
}, specsDir: string, opts: {
|