@agjs/tsforge 0.2.2 → 0.2.4
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/package.json
CHANGED
|
@@ -12,7 +12,8 @@ export const FAILURE_CLASS = {
|
|
|
12
12
|
none: "none",
|
|
13
13
|
/** Model emitted tool calls the parser couldn't read (repair L3 / salvage). */
|
|
14
14
|
toolMalformed: "tool-malformed",
|
|
15
|
-
/** Edits
|
|
15
|
+
/** Edits/tool calls were rejected — missing target (missing-file / not-found /
|
|
16
|
+
* ambiguous) or out-of-scope (the dispatcher's tool_rejected). */
|
|
16
17
|
editReject: "edit-reject",
|
|
17
18
|
/** Hit the turn cap or the gate stalled with no decisive error class. */
|
|
18
19
|
noProgress: "no-progress",
|
|
@@ -44,6 +45,8 @@ export interface IFailureSignals {
|
|
|
44
45
|
salvages: number;
|
|
45
46
|
editRejects: number;
|
|
46
47
|
degenerated: boolean;
|
|
48
|
+
timedOut: boolean;
|
|
49
|
+
toolUseFailed: boolean;
|
|
47
50
|
tsErrors: number;
|
|
48
51
|
lintErrors: number;
|
|
49
52
|
missingModule: number;
|
|
@@ -60,10 +63,25 @@ export interface IFailureSummary {
|
|
|
60
63
|
|
|
61
64
|
const TS_CODE = /^TS\d+$/;
|
|
62
65
|
const MISSING_MODULE = /cannot find module/i;
|
|
63
|
-
|
|
66
|
+
// The terminal degeneration stops say "repetition loop" (run.ts, session.ts) —
|
|
67
|
+
// NOT "degenerate". Match both the user-facing phrase and the internal term.
|
|
68
|
+
const DEGENERATE = /repetition loop|degenerat/i;
|
|
69
|
+
// Salvage telemetry on the tool channel ("recovered N malformed tool call(s)").
|
|
64
70
|
const TOOL_MALFORMED = /salvage|recovered|malformed|re-ask/i;
|
|
71
|
+
// Terminal stops where the model never produced usable tool calls: the leaked
|
|
72
|
+
// malformed-tool-call stop and the narrate-instead-of-build stop (session.ts).
|
|
73
|
+
const TOOL_USE_FAILED =
|
|
74
|
+
/malformed tool-call|writing files as chat|instead of creating them/i;
|
|
75
|
+
// Edit/scope rejections surface on TWO channels: model-agent emits a `kind:"edit"`
|
|
76
|
+
// "<file> — rejected (<reason>)"; the tool dispatcher emits `kind:"tool"`
|
|
77
|
+
// "tool_rejected:" / "tool_input_rejected:". Both contain "reject".
|
|
65
78
|
const REJECTED = /reject/i;
|
|
66
|
-
|
|
79
|
+
// The TERMINAL timeout stop ("timed out repeatedly … stopped"), NOT the transient
|
|
80
|
+
// per-turn re-steer ("timed out … re-steering (1/3)") — only the former ends a run.
|
|
81
|
+
const TIMED_OUT = /timed out repeatedly/i;
|
|
82
|
+
// The actual browser-oracle failure strings (oracle.ts): "rendered blank",
|
|
83
|
+
// "app did not mount", "console error:", "uncaught:", "route X failed to load".
|
|
84
|
+
const BROWSER = /blank|did not mount|console error|uncaught|failed to load/i;
|
|
67
85
|
const ROUTE = /route|phantom|stub/i;
|
|
68
86
|
const BUILD = /vite|esbuild|build failed|bundl/i;
|
|
69
87
|
|
|
@@ -146,10 +164,15 @@ function gatherSignals(
|
|
|
146
164
|
salvages: events.filter(
|
|
147
165
|
(e) => e.kind === "tool" && TOOL_MALFORMED.test(e.message)
|
|
148
166
|
).length,
|
|
167
|
+
// Rejections come on both the "edit" channel (model-agent) and the "tool"
|
|
168
|
+
// channel (dispatcher: tool_rejected / tool_input_rejected).
|
|
149
169
|
editRejects: events.filter(
|
|
150
|
-
(e) =>
|
|
170
|
+
(e) =>
|
|
171
|
+
(e.kind === "edit" || e.kind === "tool") && REJECTED.test(e.message)
|
|
151
172
|
).length,
|
|
152
173
|
degenerated: events.some((e) => DEGENERATE.test(e.message)),
|
|
174
|
+
timedOut: events.some((e) => TIMED_OUT.test(e.message)),
|
|
175
|
+
toolUseFailed: events.some((e) => TOOL_USE_FAILED.test(e.message)),
|
|
153
176
|
tsErrors: rules.filter((r) => TS_CODE.test(r) && r !== "TS2307").length,
|
|
154
177
|
lintErrors: rules.filter((r) => !TS_CODE.test(r)).length,
|
|
155
178
|
missingModule,
|
|
@@ -203,11 +226,7 @@ function classifyGateErrors(
|
|
|
203
226
|
|
|
204
227
|
/** Behavioral fallback when no gate-error class dominates. */
|
|
205
228
|
function classifyBehavior(signals: IFailureSignals): FailureClass {
|
|
206
|
-
if (signals.
|
|
207
|
-
return FAILURE_CLASS.degeneration;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if (signals.salvages > 0 || signals.repairs > 0) {
|
|
229
|
+
if (signals.toolUseFailed || signals.salvages > 0 || signals.repairs > 0) {
|
|
211
230
|
return FAILURE_CLASS.toolMalformed;
|
|
212
231
|
}
|
|
213
232
|
|
|
@@ -234,6 +253,18 @@ export function classifyRun(
|
|
|
234
253
|
return { failureClass: FAILURE_CLASS.none, signals };
|
|
235
254
|
}
|
|
236
255
|
|
|
256
|
+
// A repeated request timeout is the terminal cause — the model couldn't even
|
|
257
|
+
// respond — so it outranks any stale gate error from an earlier turn.
|
|
258
|
+
if (signals.timedOut) {
|
|
259
|
+
return { failureClass: FAILURE_CLASS.timeout, signals };
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Likewise a repetition-loop stop: the run died because generation degenerated,
|
|
263
|
+
// not because of whatever the gate last reported.
|
|
264
|
+
if (signals.degenerated) {
|
|
265
|
+
return { failureClass: FAILURE_CLASS.degeneration, signals };
|
|
266
|
+
}
|
|
267
|
+
|
|
237
268
|
if (signals.missingModule > 0) {
|
|
238
269
|
return { failureClass: FAILURE_CLASS.hallucinatedImport, signals };
|
|
239
270
|
}
|
|
@@ -108,3 +108,22 @@ export function isValidHash(hash: string): boolean {
|
|
|
108
108
|
export function normalizeHash(hash: string): string {
|
|
109
109
|
return hash.toUpperCase();
|
|
110
110
|
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Extract the 4-hex hash from a raw value that may be a full `¶path#HASH` tag,
|
|
114
|
+
* a `path#HASH`, a `#HASH`, or a bare `HASH`. The model frequently pastes the
|
|
115
|
+
* whole header tag (what it saw on read) into the `hash` arg, which then fails
|
|
116
|
+
* the staleness compare against a real 4-hex hash. Returns undefined when no
|
|
117
|
+
* valid hash is present.
|
|
118
|
+
*/
|
|
119
|
+
export function extractHash(raw: string | undefined): string | undefined {
|
|
120
|
+
if (raw === undefined) {
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const candidate = raw.includes(HL_HASH_SEP)
|
|
125
|
+
? raw.slice(raw.lastIndexOf(HL_HASH_SEP) + 1).trim()
|
|
126
|
+
: raw.trim();
|
|
127
|
+
|
|
128
|
+
return isValidHash(candidate) ? candidate : undefined;
|
|
129
|
+
}
|
package/src/files/hashline.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
computeFileHash,
|
|
11
11
|
parseHashHeader,
|
|
12
12
|
normalizeHash,
|
|
13
|
+
HL_HEADER_SIGIL,
|
|
13
14
|
} from "./hashline-format";
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -318,26 +319,35 @@ export function parseHashlineEdit(input: string): {
|
|
|
318
319
|
|
|
319
320
|
let i = 0;
|
|
320
321
|
|
|
321
|
-
//
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
322
|
+
// The `¶path#HASH` header is OPTIONAL. The model frequently sends bare ops
|
|
323
|
+
// (`delete 79..164`) — the path is already in the tool args and the hash
|
|
324
|
+
// comes from the `hash` arg — so only treat the first line as a header when
|
|
325
|
+
// it actually looks like one (a malformed sigil header is still an error).
|
|
326
|
+
const headerLine = lines[0] ?? "";
|
|
325
327
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
+
if (headerLine.startsWith(HL_HEADER_SIGIL)) {
|
|
329
|
+
const parsed = parseHeaderLine(headerLine, errors);
|
|
328
330
|
|
|
329
|
-
if (
|
|
330
|
-
i++;
|
|
331
|
-
} else if (errors.length > 0) {
|
|
331
|
+
if (errors.length > 0) {
|
|
332
332
|
return { filePath: "", fileHash: undefined, ops: [], errors };
|
|
333
|
-
} else if (headerLine.trim() === "") {
|
|
334
|
-
i++;
|
|
335
333
|
}
|
|
334
|
+
|
|
335
|
+
filePath = parsed.filePath;
|
|
336
|
+
fileHash = parsed.fileHash;
|
|
337
|
+
i = 1;
|
|
338
|
+
} else if (headerLine.trim() === "") {
|
|
339
|
+
i = 1;
|
|
336
340
|
}
|
|
337
341
|
|
|
338
342
|
// Parse operations
|
|
339
343
|
const ops = parseOperations(lines, i, errors);
|
|
340
344
|
|
|
345
|
+
if (ops.length === 0 && errors.length === 0) {
|
|
346
|
+
errors.push(
|
|
347
|
+
"No edit operations found. Provide replace/delete/insert ops (optionally after a ¶path#HASH header)."
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
|
|
341
351
|
return { filePath, fileHash, ops, errors };
|
|
342
352
|
}
|
|
343
353
|
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
parseHashlineEdit,
|
|
4
4
|
SessionSnapshotStore,
|
|
5
5
|
} from "../../files/hashline";
|
|
6
|
+
import { extractHash } from "../../files/hashline-format";
|
|
6
7
|
import { parseOrRepair, reject, type IToolContext } from "./tool-context";
|
|
7
8
|
import { toHashlineEdit } from "../../agent";
|
|
8
9
|
|
|
@@ -50,11 +51,17 @@ export async function doHashlineEdit(
|
|
|
50
51
|
// Ensure the store exists on the context
|
|
51
52
|
ctx.snapshotStore ??= new SessionSnapshotStore();
|
|
52
53
|
|
|
54
|
+
// Hash source priority: the `¶path#HASH` header the model wrote in `input`
|
|
55
|
+
// (the format it saw on read), else the `hash` arg — tolerantly extracted so
|
|
56
|
+
// a pasted full tag (`¶path#HASH`) still yields the bare hash. Using the raw
|
|
57
|
+
// arg directly caused false stale-anchor rejections on unchanged files.
|
|
58
|
+
const fileHash = parsed.fileHash ?? extractHash(edit.hash);
|
|
59
|
+
|
|
53
60
|
const result = await applyHashlineEdit(
|
|
54
61
|
ctx.snapshotStore,
|
|
55
62
|
ctx.cwd,
|
|
56
63
|
edit.file,
|
|
57
|
-
|
|
64
|
+
fileHash,
|
|
58
65
|
parsed.ops
|
|
59
66
|
);
|
|
60
67
|
|