@nightloom/isy 1.0.5 → 1.0.6
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/README.md +17 -2
- package/dist/agents/claude.js +3 -2
- package/dist/agents/claude.js.map +1 -1
- package/dist/agents/codex.js +14 -5
- package/dist/agents/codex.js.map +1 -1
- package/dist/agents/index.d.ts +14 -10
- package/dist/agents/index.js +65 -15
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/kimi.js +26 -8
- package/dist/agents/kimi.js.map +1 -1
- package/dist/agents/types.d.ts +12 -3
- package/dist/commands/commit.d.ts +6 -0
- package/dist/commands/commit.js +326 -16
- package/dist/commands/commit.js.map +1 -1
- package/dist/commands/health.js +1 -1
- package/dist/commands/health.js.map +1 -1
- package/dist/commands/init.js +30 -5
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/status.d.ts +2 -0
- package/dist/commands/status.js +7 -4
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/upload.d.ts +8 -1
- package/dist/commands/upload.js +46 -39
- package/dist/commands/upload.js.map +1 -1
- package/dist/detectors.d.ts +32 -0
- package/dist/detectors.js +279 -72
- package/dist/detectors.js.map +1 -1
- package/dist/git.d.ts +52 -0
- package/dist/git.js +166 -9
- package/dist/git.js.map +1 -1
- package/dist/githook.d.ts +18 -7
- package/dist/githook.js +147 -17
- package/dist/githook.js.map +1 -1
- package/dist/hook.d.ts +22 -2
- package/dist/hook.js +28 -3
- package/dist/hook.js.map +1 -1
- package/dist/index.js +14 -5
- package/dist/index.js.map +1 -1
- package/dist/mask-paths.d.ts +4 -3
- package/dist/mask-paths.js +4 -3
- package/dist/mask-paths.js.map +1 -1
- package/dist/parser.d.ts +58 -9
- package/dist/parser.js +337 -58
- package/dist/parser.js.map +1 -1
- package/dist/paths.d.ts +19 -1
- package/dist/paths.js +28 -3
- package/dist/paths.js.map +1 -1
- package/dist/redact.d.ts +2 -0
- package/dist/redact.js +956 -97
- package/dist/redact.js.map +1 -1
- package/dist/stage0.js +27 -8
- package/dist/stage0.js.map +1 -1
- package/dist/state.d.ts +15 -0
- package/dist/state.js +8 -0
- package/dist/state.js.map +1 -1
- package/dist/test/check.test.js +1 -1
- package/dist/test/check.test.js.map +1 -1
- package/dist/test/codex.test.js +27 -4
- package/dist/test/codex.test.js.map +1 -1
- package/dist/test/commit.test.js +1466 -6
- package/dist/test/commit.test.js.map +1 -1
- package/dist/test/e2e-harness.test.d.ts +1 -0
- package/dist/test/e2e-harness.test.js +53 -0
- package/dist/test/e2e-harness.test.js.map +1 -0
- package/dist/test/git.test.js +72 -2
- package/dist/test/git.test.js.map +1 -1
- package/dist/test/hook.test.js +138 -3
- package/dist/test/hook.test.js.map +1 -1
- package/dist/test/init.test.js +60 -1
- package/dist/test/init.test.js.map +1 -1
- package/dist/test/kimi-config.test.js +27 -5
- package/dist/test/kimi-config.test.js.map +1 -1
- package/dist/test/kimi-hook.test.js +1 -1
- package/dist/test/kimi-hook.test.js.map +1 -1
- package/dist/test/kimi-listing.test.js +42 -2
- package/dist/test/kimi-listing.test.js.map +1 -1
- package/dist/test/kimi.test.js +26 -2
- package/dist/test/kimi.test.js.map +1 -1
- package/dist/test/parser.test.js +527 -1
- package/dist/test/parser.test.js.map +1 -1
- package/dist/test/redact.test.js +2442 -14
- package/dist/test/redact.test.js.map +1 -1
- package/dist/test/stage0.test.js +617 -1
- package/dist/test/stage0.test.js.map +1 -1
- package/dist/test/sweep.test.js +99 -3
- package/dist/test/sweep.test.js.map +1 -1
- package/package.json +1 -1
- package/src/agents/claude.ts +3 -2
- package/src/agents/codex.ts +14 -5
- package/src/agents/index.ts +71 -16
- package/src/agents/kimi.ts +28 -8
- package/src/agents/types.ts +12 -3
- package/src/commands/commit.ts +354 -18
- package/src/commands/health.ts +1 -1
- package/src/commands/init.ts +37 -7
- package/src/commands/status.ts +9 -4
- package/src/commands/upload.ts +54 -54
- package/src/detectors.ts +284 -75
- package/src/git.ts +175 -9
- package/src/githook.ts +151 -19
- package/src/hook.ts +30 -3
- package/src/index.ts +15 -5
- package/src/mask-paths.ts +5 -4
- package/src/parser.ts +355 -51
- package/src/paths.ts +30 -3
- package/src/redact.ts +959 -100
- package/src/stage0.ts +28 -8
- package/src/state.ts +18 -0
package/src/detectors.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
shellReadPaths,
|
|
9
9
|
withoutHeredocs,
|
|
10
10
|
} from "./parser.js";
|
|
11
|
+
import type { Budget } from "./parser.js";
|
|
11
12
|
import type { Candidate, FileEdit, ParsedSession, ToolUse } from "./types.js";
|
|
12
13
|
|
|
13
14
|
const FAILURE_LOOKBACK_RECORDS = 10;
|
|
@@ -79,20 +80,46 @@ export function weakensTest(oldString: string, newString: string): string | unde
|
|
|
79
80
|
return undefined;
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
function
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const result = use.result;
|
|
88
|
-
if (!result) return false;
|
|
89
|
-
return (
|
|
90
|
-
result.isError ||
|
|
83
|
+
function saysItFailed(use: ToolUse): boolean {
|
|
84
|
+
const result = use.result;
|
|
85
|
+
return (
|
|
86
|
+
result !== undefined &&
|
|
87
|
+
(result.isError ||
|
|
91
88
|
FAILURE_OUTPUT.test(result.stdout ?? "") ||
|
|
92
89
|
FAILURE_OUTPUT.test(result.stderr ?? "") ||
|
|
93
|
-
FAILURE_OUTPUT.test(result.text)
|
|
94
|
-
|
|
95
|
-
|
|
90
|
+
FAILURE_OUTPUT.test(result.text))
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* A session's shell calls by record, and the first of them to fail once an edit has
|
|
96
|
+
* asked. Only what an edit reaches is read, and each record once: every block of a record
|
|
97
|
+
* can carry that record's one output, which can run to megabytes, and thousands of edits
|
|
98
|
+
* can ask about 100000 calls. The parse is over by the time a detector runs, so what a
|
|
99
|
+
* call came to no longer changes.
|
|
100
|
+
*/
|
|
101
|
+
const shellCalls = new WeakMap<ParsedSession, Map<number, { calls: ToolUse[]; failing?: ToolUse | null }>>();
|
|
102
|
+
|
|
103
|
+
function failedBefore(session: ParsedSession, recordIndex: number): ToolUse | undefined {
|
|
104
|
+
let records = shellCalls.get(session);
|
|
105
|
+
if (records === undefined) {
|
|
106
|
+
records = new Map();
|
|
107
|
+
for (const use of session.toolUses) {
|
|
108
|
+
if (use.name !== "Bash") continue;
|
|
109
|
+
const record = records.get(use.recordIndex);
|
|
110
|
+
if (record === undefined) records.set(use.recordIndex, { calls: [use] });
|
|
111
|
+
else record.calls.push(use);
|
|
112
|
+
}
|
|
113
|
+
shellCalls.set(session, records);
|
|
114
|
+
}
|
|
115
|
+
// Earliest first, as a finding starts from it.
|
|
116
|
+
for (let back = FAILURE_LOOKBACK_RECORDS; back >= 1; back -= 1) {
|
|
117
|
+
const record = records.get(recordIndex - back);
|
|
118
|
+
if (record === undefined) continue;
|
|
119
|
+
if (record.failing === undefined) record.failing = record.calls.find(saysItFailed) ?? null;
|
|
120
|
+
if (record.failing !== null) return record.failing;
|
|
121
|
+
}
|
|
122
|
+
return undefined;
|
|
96
123
|
}
|
|
97
124
|
|
|
98
125
|
export function detectTestModifiedToPass(session: ParsedSession): Candidate[] {
|
|
@@ -158,14 +185,53 @@ interface FileState {
|
|
|
158
185
|
edited: boolean;
|
|
159
186
|
}
|
|
160
187
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
188
|
+
// What following a session's files may cost, in characters walked: each edit
|
|
189
|
+
// walks its file and digests the result, so a file doubled by replace_all, or
|
|
190
|
+
// edited thousands of times at full size, took the heap or many minutes. The
|
|
191
|
+
// most in a real session, of 518 MB of transcript, was 10.6 million.
|
|
192
|
+
// ponytail: past this no file is followed and later abandoned approaches go unseen; a budget per file if one file should not blind the rest.
|
|
193
|
+
const TRACKED_CHARS = 32 * 1024 * 1024;
|
|
194
|
+
|
|
195
|
+
// `text.split(pattern)`, or only around the first occurrence, in time
|
|
196
|
+
// proportional to both: the engine's own search walks a long pattern that almost
|
|
197
|
+
// repeats again from every position, half a minute for 100 KB over a 1 MB file.
|
|
198
|
+
function piecesAround(text: string, pattern: string, all: boolean): string[] {
|
|
199
|
+
const fallback = new Int32Array(pattern.length);
|
|
200
|
+
for (let at = 1, matched = 0; at < pattern.length; at += 1) {
|
|
201
|
+
while (matched > 0 && pattern.charCodeAt(at) !== pattern.charCodeAt(matched)) matched = fallback[matched - 1]!;
|
|
202
|
+
if (pattern.charCodeAt(at) === pattern.charCodeAt(matched)) matched += 1;
|
|
203
|
+
fallback[at] = matched;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const pieces: string[] = [];
|
|
207
|
+
let end = 0;
|
|
208
|
+
for (let at = 0, matched = 0; at < text.length; at += 1) {
|
|
209
|
+
while (matched > 0 && text.charCodeAt(at) !== pattern.charCodeAt(matched)) matched = fallback[matched - 1]!;
|
|
210
|
+
if (text.charCodeAt(at) === pattern.charCodeAt(matched)) matched += 1;
|
|
211
|
+
if (matched === pattern.length) {
|
|
212
|
+
pieces.push(text.slice(end, at + 1 - matched));
|
|
213
|
+
end = at + 1;
|
|
214
|
+
matched = 0;
|
|
215
|
+
if (!all) break;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
pieces.push(text.slice(end));
|
|
219
|
+
return pieces;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Literal, as the edit tools are, and undefined when the text is not there or
|
|
223
|
+
// the result would not fit in `room`, which is known before it is built.
|
|
224
|
+
function applyEdit(content: string, oldString: string, newString: string, all: boolean, room: number): string | undefined {
|
|
225
|
+
if (oldString.length === 0 || oldString.length > content.length || room < 0) return undefined;
|
|
226
|
+
const pieces = piecesAround(content, oldString, all);
|
|
227
|
+
const length = content.length + (pieces.length - 1) * (newString.length - oldString.length);
|
|
228
|
+
return pieces.length === 1 || length > room ? undefined : pieces.join(newString);
|
|
164
229
|
}
|
|
165
230
|
|
|
166
231
|
function trackContent(session: ParsedSession): Candidate[] {
|
|
167
232
|
const candidates: Candidate[] = [];
|
|
168
233
|
const states = new Map<string, FileState>();
|
|
234
|
+
let room = TRACKED_CHARS;
|
|
169
235
|
|
|
170
236
|
const state = (filePath: string): FileState => {
|
|
171
237
|
let existing = states.get(filePath);
|
|
@@ -178,6 +244,11 @@ function trackContent(session: ParsedSession): Candidate[] {
|
|
|
178
244
|
|
|
179
245
|
const record = (file: FileState, filePath: string, use: ToolUse, isEdit: boolean): void => {
|
|
180
246
|
if (file.content === undefined) return;
|
|
247
|
+
room -= file.content.length;
|
|
248
|
+
if (room < 0) {
|
|
249
|
+
file.content = undefined;
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
181
252
|
const key = digest(file.content);
|
|
182
253
|
const firstSeen = file.seen.get(key);
|
|
183
254
|
const unchanged = key === file.lastKey;
|
|
@@ -236,7 +307,8 @@ function trackContent(session: ParsedSession): Candidate[] {
|
|
|
236
307
|
file.content = undefined;
|
|
237
308
|
break;
|
|
238
309
|
}
|
|
239
|
-
|
|
310
|
+
room -= file.content.length + from.length;
|
|
311
|
+
file.content = applyEdit(file.content, from, to, use.input.replace_all === true, room);
|
|
240
312
|
}
|
|
241
313
|
|
|
242
314
|
record(file, filePath, use, true);
|
|
@@ -246,21 +318,21 @@ function trackContent(session: ParsedSession): Candidate[] {
|
|
|
246
318
|
return candidates;
|
|
247
319
|
}
|
|
248
320
|
|
|
321
|
+
/** An edit's two sides as one key. A digest, since past 16 KB a string hashes by its length alone, and a set of those is a walk. */
|
|
322
|
+
function sidesOf(from: string, to: string): string {
|
|
323
|
+
return createHash("sha1").update(`${from.length}:${from}${to}`).digest("hex");
|
|
324
|
+
}
|
|
325
|
+
|
|
249
326
|
function detectRevertPairs(session: ParsedSession): Candidate[] {
|
|
250
327
|
const candidates: Candidate[] = [];
|
|
251
328
|
|
|
252
329
|
for (const [filePath, edits] of session.fileEdits) {
|
|
253
|
-
|
|
254
|
-
|
|
330
|
+
const earlier = new Set<string>();
|
|
331
|
+
for (const current of edits) {
|
|
255
332
|
if (current.oldString === undefined || current.newString === undefined) continue;
|
|
256
333
|
|
|
257
|
-
const reverted =
|
|
258
|
-
|
|
259
|
-
earlier.oldString !== undefined &&
|
|
260
|
-
earlier.newString !== undefined &&
|
|
261
|
-
earlier.oldString === current.newString &&
|
|
262
|
-
earlier.newString === current.oldString,
|
|
263
|
-
);
|
|
334
|
+
const reverted = earlier.has(sidesOf(current.newString, current.oldString));
|
|
335
|
+
earlier.add(sidesOf(current.oldString, current.newString));
|
|
264
336
|
if (!reverted) continue;
|
|
265
337
|
|
|
266
338
|
candidates.push({
|
|
@@ -281,9 +353,9 @@ function detectRevertPairs(session: ParsedSession): Candidate[] {
|
|
|
281
353
|
return candidates;
|
|
282
354
|
}
|
|
283
355
|
|
|
284
|
-
function revertTargets(command: string): { everything: boolean;
|
|
356
|
+
function revertTargets(command: string): { everything: boolean; names: Set<string> } | undefined {
|
|
285
357
|
if (GIT_RESET.test(command) || GIT_STASH.test(command)) {
|
|
286
|
-
return { everything: true,
|
|
358
|
+
return { everything: true, names: new Set() };
|
|
287
359
|
}
|
|
288
360
|
|
|
289
361
|
const match = GIT_CHECKOUT.exec(command) ?? GIT_RESTORE.exec(command);
|
|
@@ -293,21 +365,20 @@ function revertTargets(command: string): { everything: boolean; paths: string[]
|
|
|
293
365
|
const paths = raw
|
|
294
366
|
.trim()
|
|
295
367
|
.split(/\s+/)
|
|
296
|
-
.filter((part) => part.length > 0 && !part.startsWith("-"))
|
|
368
|
+
.filter((part) => part.length > 0 && !part.startsWith("-"))
|
|
369
|
+
.map((part) => part.replace(/^\.\//, "").replace(/["']/g, ""));
|
|
297
370
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
function matchesPath(filePath: string, target: string): boolean {
|
|
302
|
-
const cleaned = target.replace(/^\.\//, "").replace(/["']/g, "");
|
|
303
|
-
if (cleaned === "." || cleaned === "*") return true;
|
|
304
|
-
return filePath.endsWith(`/${cleaned}`) || basename(filePath) === basename(cleaned);
|
|
371
|
+
if (paths.length === 0) return undefined;
|
|
372
|
+
// A file goes by its last part, so a command takes one look per file whatever it lists.
|
|
373
|
+
return { everything: paths.includes(".") || paths.includes("*"), names: new Set(paths.map((path) => basename(path))) };
|
|
305
374
|
}
|
|
306
375
|
|
|
307
376
|
const REVERT_FILES_LISTED = 5;
|
|
308
377
|
|
|
309
378
|
function detectGitReverts(session: ParsedSession): Candidate[] {
|
|
310
379
|
const candidates: Candidate[] = [];
|
|
380
|
+
// Once each, as a long path walked again for every discard is what takes the time.
|
|
381
|
+
const files = [...session.fileEdits].map(([filePath, edits]) => ({ filePath, edits, name: basename(filePath) }));
|
|
311
382
|
|
|
312
383
|
for (const use of session.toolUses) {
|
|
313
384
|
if (use.name !== "Bash") continue;
|
|
@@ -320,15 +391,13 @@ function detectGitReverts(session: ParsedSession): Candidate[] {
|
|
|
320
391
|
const discarded: string[] = [];
|
|
321
392
|
let startedAt: string | undefined;
|
|
322
393
|
|
|
323
|
-
for (const
|
|
324
|
-
const
|
|
325
|
-
if (
|
|
326
|
-
if (!targets.everything && !targets.
|
|
327
|
-
continue;
|
|
328
|
-
}
|
|
394
|
+
for (const { filePath, edits, name } of files) {
|
|
395
|
+
const earliest = edits.find((edit) => edit.recordIndex < use.recordIndex);
|
|
396
|
+
if (!earliest) continue;
|
|
397
|
+
if (!targets.everything && !targets.names.has(name)) continue;
|
|
329
398
|
|
|
330
399
|
discarded.push(filePath);
|
|
331
|
-
const first =
|
|
400
|
+
const first = earliest.timestamp;
|
|
332
401
|
if (first && (!startedAt || first < startedAt)) startedAt = first;
|
|
333
402
|
}
|
|
334
403
|
|
|
@@ -361,10 +430,11 @@ function detectGitReverts(session: ParsedSession): Candidate[] {
|
|
|
361
430
|
function detectAbandonedBranches(session: ParsedSession): Candidate[] {
|
|
362
431
|
const candidates: Candidate[] = [];
|
|
363
432
|
if (session.mainPath.size === 0) return candidates;
|
|
433
|
+
const walked = new Map<string, boolean>();
|
|
364
434
|
|
|
365
435
|
for (const [filePath, edits] of session.fileEdits) {
|
|
366
436
|
for (const edit of edits) {
|
|
367
|
-
if (!onAbandonedBranch(session, edit.uuid)) continue;
|
|
437
|
+
if (!onAbandonedBranch(session, edit.uuid, walked)) continue;
|
|
368
438
|
|
|
369
439
|
candidates.push({
|
|
370
440
|
category: "abandoned_approach",
|
|
@@ -498,11 +568,12 @@ function jsonDependencies(text: string): Set<string> {
|
|
|
498
568
|
|
|
499
569
|
function otherDependencies(text: string): Set<string> {
|
|
500
570
|
const names = new Set<string>();
|
|
571
|
+
// A line's indentation is `\s` short of what ends a line: from each line, `\s` would walk all the blank ones after it.
|
|
501
572
|
const patterns = [
|
|
502
|
-
|
|
503
|
-
|
|
573
|
+
/^[^\S\r\n\u2028\u2029]*([A-Za-z0-9._-]+)\s*(?:==|>=|<=|~=|!=)/gm,
|
|
574
|
+
/^[^\S\r\n\u2028\u2029]*gem\s+["']([^"']+)["']/gm,
|
|
504
575
|
/<artifactId>([^<]+)<\/artifactId>/g,
|
|
505
|
-
|
|
576
|
+
/^[^\S\r\n\u2028\u2029]*(?:require\s+)?([a-z0-9.-]+\.[a-z]{2,}\/[^\s]+)\s+v[0-9]/gm,
|
|
506
577
|
/(?:implementation|api|testImplementation)\s+["']([^"':]+:[^"':]+)/g,
|
|
507
578
|
];
|
|
508
579
|
|
|
@@ -522,10 +593,11 @@ const TOML_DEPENDENCY_SUBTABLE = /(?:^|\.)(?:dev-|build-)?dependencies\.([A-Za-z
|
|
|
522
593
|
const TOML_REQUIREMENT_TABLES = new Set(["project.optional-dependencies", "dependency-groups"]);
|
|
523
594
|
/** Keys a TOML manifest gives a version, none of them a package. */
|
|
524
595
|
const TOML_VERSION_KEYS = new Set(["python", "version", "edition", "rust-version", "requires-python"]);
|
|
525
|
-
|
|
526
|
-
const
|
|
596
|
+
/** The name comes with its spaces, which its reader takes out: looked for here, they are a cubic walk of an open table. */
|
|
597
|
+
const TOML_HEADER = /^\s*\[\[?([^\]]+)\]\]?\s*(?:#.*)?$/;
|
|
598
|
+
const TOML_ASSIGNMENT = /^[^\S\r\n\u2028\u2029]*["']?([A-Za-z0-9._-]+)["']?\s*=\s*(.*)$/gm;
|
|
527
599
|
/** `key = [ … ]`, across lines, a `]` inside a quoted requirement (`"requests[socks]"`) included. */
|
|
528
|
-
const TOML_ARRAY =
|
|
600
|
+
const TOML_ARRAY = /^[^\S\r\n\u2028\u2029]*["']?([A-Za-z0-9_-]+)["']?\s*=\s*\[((?:"[^"]*"|'[^']*'|[^\]"'])*)/gm;
|
|
529
601
|
|
|
530
602
|
/** Package names out of the body of a TOML array of PEP 508 requirement strings. */
|
|
531
603
|
function requirementNames(array: string): string[] {
|
|
@@ -635,7 +707,7 @@ function packagesInSegment(segment: string, afterIndex: number): string[] | unde
|
|
|
635
707
|
}
|
|
636
708
|
|
|
637
709
|
const cleaned = token.replace(/["']/g, "");
|
|
638
|
-
const trimmed = cleaned.replace(/[.,;:]+$/, "");
|
|
710
|
+
const trimmed = cleaned.replace(/(?<![.,;:])[.,;:]+$/, "");
|
|
639
711
|
// A registry name, not whatever else stood in that position: a line
|
|
640
712
|
// continuation, a shell expansion whose value only the shell knows, a
|
|
641
713
|
// stray brace from prose the command happened to carry.
|
|
@@ -721,40 +793,105 @@ export function detectExternalDependency(session: ParsedSession): Candidate[] {
|
|
|
721
793
|
* way round, a directory matches everything under it, and a glob from
|
|
722
794
|
* `cat src/*.js` matches every file it could have expanded to.
|
|
723
795
|
*/
|
|
724
|
-
function samePath(known: string, filePath: string): boolean {
|
|
796
|
+
function samePath(known: string, filePath: string, budget: Budget): boolean {
|
|
725
797
|
if (known === filePath) return true;
|
|
726
|
-
|
|
798
|
+
budget.left -= known.length / CHARS_PER_STEP;
|
|
799
|
+
if (budget.left <= 0) return false;
|
|
800
|
+
if (/[*?]/.test(known)) return globMatches(known, filePath, budget);
|
|
727
801
|
if (filePath.startsWith(known.endsWith("/") ? known : `${known}/`)) return true;
|
|
728
802
|
if (!filePath.startsWith("/") && known.endsWith(`/${filePath}`)) return true;
|
|
729
803
|
return !known.startsWith("/") && filePath.endsWith(`/${known}`);
|
|
730
804
|
}
|
|
731
805
|
|
|
732
|
-
|
|
806
|
+
// What holding reads up to a session's edited files may cost, in steps, where a
|
|
807
|
+
// long glob over a long path takes millions each. Any other read walks as far as
|
|
808
|
+
// the two paths agree, at a fraction of a step a character. The most in a real
|
|
809
|
+
// session was 350 thousand steps of glob and 7.4 million characters.
|
|
810
|
+
// ponytail: past this only the path itself counts, so what else was read counts as unread; matching in linear time if a real session comes near.
|
|
811
|
+
const GLOB_STEPS = 20_000_000;
|
|
812
|
+
const CHARS_PER_STEP = 10;
|
|
813
|
+
const STAR = 42;
|
|
814
|
+
const QUESTION = 63;
|
|
815
|
+
const SLASH = 47;
|
|
733
816
|
|
|
734
|
-
/**
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
817
|
+
/**
|
|
818
|
+
* `*` and `?` within one path segment, `**` across them; a relative glob matches
|
|
819
|
+
* by suffix, like a relative path. It goes back only to the last star of each
|
|
820
|
+
* kind, since what an earlier one could take a later one can too: compiled to a
|
|
821
|
+
* pattern, a dozen stars over 100 characters never came back. For that a `**\/`
|
|
822
|
+
* stands for no directories only as a whole segment; `a**\/b` needs its slash.
|
|
823
|
+
*/
|
|
824
|
+
function globMatches(glob: string, filePath: string, budget: Budget): boolean {
|
|
825
|
+
let g = 0;
|
|
826
|
+
let at = 0;
|
|
827
|
+
let star = -1;
|
|
828
|
+
let starAt = 0;
|
|
829
|
+
let across = glob.startsWith("/") ? -1 : 0;
|
|
830
|
+
let acrossAt = 0;
|
|
831
|
+
let afterSlash = across === 0;
|
|
832
|
+
|
|
833
|
+
while (budget.left > 0) {
|
|
834
|
+
budget.left -= 1;
|
|
835
|
+
if (g < glob.length) {
|
|
836
|
+
const char = glob.charCodeAt(g);
|
|
837
|
+
if (char === STAR && glob.charCodeAt(g + 1) === STAR) {
|
|
838
|
+
afterSlash = glob.charCodeAt(g + 2) === SLASH && (g === 0 || glob.charCodeAt(g - 1) === SLASH);
|
|
839
|
+
g += afterSlash ? 3 : 2;
|
|
840
|
+
across = g;
|
|
841
|
+
acrossAt = at;
|
|
842
|
+
star = -1;
|
|
843
|
+
continue;
|
|
844
|
+
}
|
|
845
|
+
if (char === STAR) {
|
|
846
|
+
g += 1;
|
|
847
|
+
star = g;
|
|
848
|
+
starAt = at;
|
|
849
|
+
continue;
|
|
850
|
+
}
|
|
851
|
+
if (at < filePath.length && (char === QUESTION ? filePath.charCodeAt(at) !== SLASH : filePath.charCodeAt(at) === char)) {
|
|
852
|
+
g += 1;
|
|
853
|
+
at += 1;
|
|
854
|
+
continue;
|
|
855
|
+
}
|
|
856
|
+
} else if (at === filePath.length) {
|
|
857
|
+
return true;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
if (star !== -1 && starAt < filePath.length && filePath.charCodeAt(starAt) !== SLASH) {
|
|
861
|
+
starAt += 1;
|
|
862
|
+
g = star;
|
|
863
|
+
at = starAt;
|
|
864
|
+
continue;
|
|
865
|
+
}
|
|
866
|
+
if (across === -1) return false;
|
|
867
|
+
const next = afterSlash ? filePath.indexOf("/", acrossAt) + 1 : acrossAt + 1;
|
|
868
|
+
if (next === 0 || next > filePath.length) return false;
|
|
869
|
+
budget.left -= next - acrossAt;
|
|
870
|
+
acrossAt = next;
|
|
871
|
+
g = across;
|
|
872
|
+
at = next;
|
|
873
|
+
star = -1;
|
|
874
|
+
}
|
|
875
|
+
return false;
|
|
740
876
|
}
|
|
741
877
|
|
|
742
|
-
function wasLookedUp(session: ParsedSession, filePath: string): boolean {
|
|
878
|
+
function wasLookedUp(session: ParsedSession, filePath: string, budget: Budget): boolean {
|
|
743
879
|
for (const known of session.filesRead) {
|
|
744
|
-
if (samePath(known, filePath)) return true;
|
|
880
|
+
if (samePath(known, filePath, budget)) return true;
|
|
745
881
|
}
|
|
746
882
|
return false;
|
|
747
883
|
}
|
|
748
884
|
|
|
749
885
|
export function detectUnverifiedAssumption(session: ParsedSession): Candidate[] {
|
|
750
886
|
const candidates: Candidate[] = [];
|
|
887
|
+
const globSteps: Budget = { left: GLOB_STEPS };
|
|
751
888
|
|
|
752
889
|
for (const [filePath, edits] of session.fileEdits) {
|
|
753
890
|
const first = edits[0];
|
|
754
891
|
if (!first) continue;
|
|
755
892
|
// `sed -i` edits in place like Edit does, on the same picture of the file.
|
|
756
893
|
if (first.tool !== "Edit" && first.tool !== "MultiEdit" && first.tool !== "Bash") continue;
|
|
757
|
-
if (wasLookedUp(session, filePath)) continue;
|
|
894
|
+
if (wasLookedUp(session, filePath, globSteps)) continue;
|
|
758
895
|
|
|
759
896
|
candidates.push({
|
|
760
897
|
category: "unverified_assumption",
|
|
@@ -847,9 +984,16 @@ export function detectUnverifiedFix(session: ParsedSession): Candidate[] {
|
|
|
847
984
|
/**
|
|
848
985
|
* Silencing rather than fixing. `test_modified_to_pass` covers the test-file
|
|
849
986
|
* half of this; here it is production code, where a suppression comment has no
|
|
850
|
-
* failing test to explain it and simply removes the warning from view.
|
|
987
|
+
* failing test to explain it and simply removes the warning from view. Whole
|
|
988
|
+
* files go through these, so every run is bounded or has one way to match.
|
|
989
|
+
*
|
|
990
|
+
* ponytail: an `except` tuple or its comment past 1000 characters goes unread,
|
|
991
|
+
* and so does a blank run past 200. Raise them if one shows up: 1 MB built to
|
|
992
|
+
* stall these takes most of a second as it is. A catch's parameter needs no bound:
|
|
993
|
+
* no scan goes past the next `(`, so they cannot pile up, and a parameter holding
|
|
994
|
+
* one was no match anyway.
|
|
851
995
|
*/
|
|
852
|
-
const SUPPRESSORS: { pattern: RegExp; detail: string }[] = [
|
|
996
|
+
export const SUPPRESSORS: { pattern: RegExp; detail: string }[] = [
|
|
853
997
|
{ pattern: /@ts-(?:ignore|nocheck|expect-error)\b/g, detail: "a TypeScript error was suppressed" },
|
|
854
998
|
{ pattern: /eslint-disable(?:-next-line|-line)?\b/g, detail: "an ESLint rule was disabled" },
|
|
855
999
|
{ pattern: /#\s*type:\s*ignore\b/g, detail: "a type error was suppressed" },
|
|
@@ -857,16 +1001,41 @@ const SUPPRESSORS: { pattern: RegExp; detail: string }[] = [
|
|
|
857
1001
|
{ pattern: /#\s*pylint:\s*disable\b/g, detail: "a pylint rule was disabled" },
|
|
858
1002
|
{ pattern: /@SuppressWarnings\b/g, detail: "a compiler warning was suppressed" },
|
|
859
1003
|
{ pattern: /#\[allow\(/g, detail: "a Rust lint was allowed" },
|
|
860
|
-
{ pattern: /except[^\n:]
|
|
861
|
-
{ pattern: /catch\s
|
|
862
|
-
{ pattern: /rescue\s
|
|
1004
|
+
{ pattern: /except(?:(?!except)[^\n:]){0,1000}:\s{0,200}(?:#[^\n]{0,1000})?\n\s{0,200}pass\b/g, detail: "an exception is caught and dropped" },
|
|
1005
|
+
{ pattern: /catch\s{0,200}(?:\([^()]*\)\s{0,200})?\{\s{0,200}\}/g, detail: "an exception is caught and dropped" },
|
|
1006
|
+
{ pattern: /rescue\s{0,200}(?:=>\s{0,200}\w+\s{0,200})?\n\s{0,200}end\b/g, detail: "an exception is caught and dropped" },
|
|
1007
|
+
];
|
|
1008
|
+
|
|
1009
|
+
/**
|
|
1010
|
+
* A catch that only logs, and returns nothing much if it returns at all: the
|
|
1011
|
+
* failure is still there, and the check that reported it goes green. Everyday
|
|
1012
|
+
* code otherwise, so these count only right after a check failed. Python's needs
|
|
1013
|
+
* the return: read line by line, a log call alone could be the start of a real
|
|
1014
|
+
* handler. Whole files go through these, so every run is bounded or has one way
|
|
1015
|
+
* to match.
|
|
1016
|
+
*
|
|
1017
|
+
* ponytail: a quote earlier on the line is what says `catch` sits in a string. A
|
|
1018
|
+
* real catch after a string on its own line goes unread, and a sample spanning
|
|
1019
|
+
* lines of a template literal reads as code. Tokenize the file if either shows up.
|
|
1020
|
+
*/
|
|
1021
|
+
export const LOG_ONLY_CATCHES: { pattern: RegExp; detail: string }[] = [
|
|
1022
|
+
{
|
|
1023
|
+
pattern:
|
|
1024
|
+
/\bcatch(?<!["'`][^\n]{0,200}catch)\s*(?:\([^)]{0,200}\)\s*)?\{(?:[ \t\r\n]{0,200}\/\/[^\n]{0,400}\n){0,20}\s*(?:this\.)?(?:console|logger|log)\.(?:warn|warning|error|info|debug|log)\((?:[^;\n]{0,400}|[ \t]*\n[^;]{0,400}\n[ \t]*)\)(?:\s*;)?\s*(?:return(?:\s+(?:null|undefined|false|\[\]|\{\}))?(?:\s*;)?\s*)?\}/g,
|
|
1025
|
+
detail: "an exception is caught and only logged",
|
|
1026
|
+
},
|
|
1027
|
+
{
|
|
1028
|
+
pattern:
|
|
1029
|
+
/^[ \t]*except\b[^\n:]{0,200}:[ \t]*(?:#[^\n]*)?\n(?:[ \t]*#[^\n]*\n)*[ \t]*(?:print|(?:self\.)?(?:logger|logging|log)\.(?:warning|warn|error|info|debug|exception)|warnings\.warn)\([^\n]{0,400}\)[ \t]*\n[ \t]*return(?:[ \t]+(?:None|False|\[\]|\{\}))?[ \t]*(?:#[^\n]*)?$/gm,
|
|
1030
|
+
detail: "an exception is caught and only logged",
|
|
1031
|
+
},
|
|
863
1032
|
];
|
|
864
1033
|
|
|
865
1034
|
/** `|| true` on a check, and the flags that walk past a failing hook. */
|
|
866
1035
|
const SUPPRESSING_FLAG = /--no-verify\b|--ignore-errors\b|--exit-zero\b/;
|
|
867
1036
|
|
|
868
|
-
function suppressionAdded(oldString: string, newString: string): string | undefined {
|
|
869
|
-
for (const { pattern, detail } of
|
|
1037
|
+
function suppressionAdded(oldString: string, newString: string, rules = SUPPRESSORS): string | undefined {
|
|
1038
|
+
for (const { pattern, detail } of rules) {
|
|
870
1039
|
// Counted, not tested: an edit that keeps one suppression and adds a second
|
|
871
1040
|
// is still an addition, and the file may have arrived with one already.
|
|
872
1041
|
if (countMatches(newString, pattern) > countMatches(oldString, pattern)) return detail;
|
|
@@ -874,8 +1043,39 @@ function suppressionAdded(oldString: string, newString: string): string | undefi
|
|
|
874
1043
|
return undefined;
|
|
875
1044
|
}
|
|
876
1045
|
|
|
1046
|
+
/**
|
|
1047
|
+
* A check that failed by its exit status, shortly before. Narrower than
|
|
1048
|
+
* `failedBefore`, for a rule with nothing else to go on: that one's word reads
|
|
1049
|
+
* `0 failed` and a `git log` as failures, and a grep that found nothing exits 1
|
|
1050
|
+
* too, with the name of a check as its pattern as often as not. A failure piped
|
|
1051
|
+
* through `tail` exits 0 and goes unread here.
|
|
1052
|
+
*/
|
|
1053
|
+
function failedChecks(session: ParsedSession): Set<number> {
|
|
1054
|
+
const records = new Set<number>();
|
|
1055
|
+
for (const use of session.toolUses) {
|
|
1056
|
+
if (
|
|
1057
|
+
use.result?.isError === true &&
|
|
1058
|
+
verifies(use) &&
|
|
1059
|
+
commandSegments(withoutHeredocs(use.input.command as string)).some(
|
|
1060
|
+
(segment) => VERIFY_COMMAND.test(segment) && !READER.test(segment),
|
|
1061
|
+
)
|
|
1062
|
+
) {
|
|
1063
|
+
records.add(use.recordIndex);
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
return records;
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
function checkFailedBefore(failed: ReadonlySet<number>, recordIndex: number): boolean {
|
|
1070
|
+
for (let back = 1; back <= FAILURE_LOOKBACK_RECORDS; back += 1) {
|
|
1071
|
+
if (failed.has(recordIndex - back)) return true;
|
|
1072
|
+
}
|
|
1073
|
+
return false;
|
|
1074
|
+
}
|
|
1075
|
+
|
|
877
1076
|
export function detectErrorSuppressed(session: ParsedSession): Candidate[] {
|
|
878
1077
|
const candidates: Candidate[] = [];
|
|
1078
|
+
const failed = failedChecks(session);
|
|
879
1079
|
|
|
880
1080
|
for (const [filePath, edits] of session.fileEdits) {
|
|
881
1081
|
// A weakened test is the same act with its own category and its own weight.
|
|
@@ -886,7 +1086,14 @@ export function detectErrorSuppressed(session: ParsedSession): Candidate[] {
|
|
|
886
1086
|
const after = edit.newString ?? edit.content ?? "";
|
|
887
1087
|
if (after.length === 0) continue;
|
|
888
1088
|
|
|
889
|
-
|
|
1089
|
+
// Taken out of this same edit, a suppression makes a log line the better
|
|
1090
|
+
// of the two: a silent catch given one hides less than it did. What a
|
|
1091
|
+
// whole-file write replaced is not in the transcript, so that reads as new.
|
|
1092
|
+
const logOnly =
|
|
1093
|
+
CODE_EXTENSION.test(filePath) && checkFailedBefore(failed, edit.recordIndex) && !suppressionAdded(after, before)
|
|
1094
|
+
? suppressionAdded(before, after, LOG_ONLY_CATCHES)
|
|
1095
|
+
: undefined;
|
|
1096
|
+
const reason = suppressionAdded(before, after) ?? logOnly;
|
|
890
1097
|
if (!reason) continue;
|
|
891
1098
|
|
|
892
1099
|
const failure = failedBefore(session, edit.recordIndex);
|
|
@@ -941,8 +1148,9 @@ export function detectErrorSuppressed(session: ParsedSession): Candidate[] {
|
|
|
941
1148
|
const DESTRUCTIVE: { pattern: RegExp; weight: number; detail: string }[] = [
|
|
942
1149
|
{ pattern: /\bDROP\s+(TABLE|DATABASE|SCHEMA)\b/i, weight: 0.8, detail: "a database object was dropped" },
|
|
943
1150
|
{ pattern: /\bTRUNCATE\s+(TABLE\s+)?\w/i, weight: 0.8, detail: "a table was truncated" },
|
|
944
|
-
{ pattern: /\bDELETE\s+FROM\s+\w+\s*["']
|
|
945
|
-
|
|
1151
|
+
{ pattern: /\bDELETE\s+FROM\s+\w+\s*(?:["']\s*)?(?:;|$)/i, weight: 0.8, detail: "rows were deleted with no WHERE clause" },
|
|
1152
|
+
// Only as far as the next push, which looks on from there, short of one with its `-f` right behind it: that flag wants a space of its own.
|
|
1153
|
+
{ pattern: /\bgit\s+push\s(?:(?!\bgit\s+push\s(?!-f\b))[^\n;|&])*(?:--force\b(?!-with-lease)|(?:^|\s)-f\b)/, weight: 0.7, detail: "a branch was force-pushed" },
|
|
946
1154
|
{ pattern: /\bgit\s+clean\s+-[a-z]*[fd]/, weight: 0.6, detail: "untracked files were deleted by git clean" },
|
|
947
1155
|
{ pattern: /\bgit\s+branch\s+-D\b/, weight: 0.5, detail: "a branch was deleted unmerged" },
|
|
948
1156
|
{ pattern: /\bgit\s+reset\s+--hard\b/, weight: 0.6, detail: "the working tree was reset, discarding uncommitted work" },
|
|
@@ -1083,10 +1291,10 @@ function pathsSeen(use: ToolUse): string[] {
|
|
|
1083
1291
|
}
|
|
1084
1292
|
|
|
1085
1293
|
/** The last call that looked at this file, or nothing if none did. */
|
|
1086
|
-
function lastLook(seen: ReadonlyMap<string, number>, filePath: string): number | undefined {
|
|
1294
|
+
function lastLook(seen: ReadonlyMap<string, number>, filePath: string, budget: Budget): number | undefined {
|
|
1087
1295
|
let latest: number | undefined;
|
|
1088
1296
|
for (const [known, index] of seen) {
|
|
1089
|
-
if (!samePath(known, filePath)) continue;
|
|
1297
|
+
if (!samePath(known, filePath, budget)) continue;
|
|
1090
1298
|
if (latest === undefined || index > latest) latest = index;
|
|
1091
1299
|
}
|
|
1092
1300
|
return latest;
|
|
@@ -1112,6 +1320,7 @@ function lastLook(seen: ReadonlyMap<string, number>, filePath: string): number |
|
|
|
1112
1320
|
export function detectStaleContext(session: ParsedSession): Candidate[] {
|
|
1113
1321
|
const breaks: { use: ToolUse; filePath: string; pauseMs: number; pausedAt?: string }[] = [];
|
|
1114
1322
|
const seen = new Map<string, number>();
|
|
1323
|
+
const globSteps: Budget = { left: GLOB_STEPS };
|
|
1115
1324
|
|
|
1116
1325
|
let previous: ToolUse | undefined;
|
|
1117
1326
|
let pauseIndex: number | undefined;
|
|
@@ -1133,7 +1342,7 @@ export function detectStaleContext(session: ParsedSession): Candidate[] {
|
|
|
1133
1342
|
|
|
1134
1343
|
if (!reported && pauseIndex !== undefined && EDIT_TOOLS.has(use.name)) {
|
|
1135
1344
|
const filePath = typeof use.input.file_path === "string" ? use.input.file_path : undefined;
|
|
1136
|
-
const looked = filePath === undefined ? undefined : lastLook(seen, filePath);
|
|
1345
|
+
const looked = filePath === undefined ? undefined : lastLook(seen, filePath, globSteps);
|
|
1137
1346
|
|
|
1138
1347
|
// A file nobody ever looked at is `unverified_assumption`, and saying it
|
|
1139
1348
|
// twice under two headings is one edit and two notes to reconcile.
|