@quikit/quikpilot-runner 9.3.0-rc.62 → 9.3.0-rc.64

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 CHANGED
@@ -172,6 +172,10 @@ wrong (a field that arrives from a database row or a request), so it only warns
172
172
 
173
173
  **9.3.0-rc.62 - an approved test that is reported again is refused with what to do (QUIKTR-1951).** When a person has approved a change to an existing test and the AI reports that test again before the final test run (a second row of a table test that still expects the old behaviour), the answer was only `already_decided`: "Do not report it again". It now also says what the AI can do: finish the code first, and if rows of that test still fail in the final test run, the fix step that follows may report the test once more (QUIKTR-1844). Nothing about WHEN a test can be reported changes, so a person is still asked only when there is evidence; a test a person judged right, or reported in another file, keeps the bare refusal exactly. A new log event `codegen.conflict_refused_approved` (phase only) counts how often it happens. No change to the contract with the AI service. The AI Runtime's QUIKTR-1952 (a hung OpenRouter call is cut at 150 s for QuikPilot calls, so the backup model answers inside the runner's turn limit) ships with this version and needs no runner setting.
174
174
 
175
+ **9.3.0-rc.64 - every re-read of a file says why it happened, and (switched off by default) the files the AI is working in are no longer shrunk while it works on them (QUIKTR-1963).** In QuikIT bug 3 (31 Oct) the AI read the same 429-line test file 28 times in 40 turns and gave up. On the notes versions an answer older than the latest three turns is shrunk to a one-line stub on every turn, whatever the request's size, with no exception for the file being worked on; but some re-reads came one turn later, so paging through the file or indecision may be part of it. (1) Always on, log only: each `read_file` on the turn line now carries its line range, and a read of a file already read in the loop logs `codegen.reread` with the earlier read's turn and range, how the two ranges meet (`same`, `overlapping`, `disjoint`), what had become of the earlier answer (`whole`, `stubbed`, `dropped`, `after_write`) and whether it was answered as a repeat; `codegen.reread_summary` counts them at the loop's end. Paths and line numbers only, never file text. (2) `QUIKPILOT_KEEP_WORKING_FILES=on` (off by default; the workflow can set it): the newest answer per range of the files the AI is working in (a file it changed, or read in two different turns; at most three files and 40,000 characters, newest first) stays whole instead of shrinking, and only answers made after the file's latest change count, so a stale read is never kept; a repeat's copy of an earlier answer can then shrink like the answer itself. The hard ceiling's last-resort drop still drops anything, so a request never exceeds today's limit. With the switch off every request the AI Runtime receives is what it was. Nothing changes on the AI Runtime or in QuikProjects. Also in rc.64: everything in rc.63.
176
+
177
+ **9.3.0-rc.63 - a reply the AI service could not read is asked again once instead of ending the attempt (QUIKTR-1953).** On 30 Oct 3% of the AI calls of a run (8 of 267) came back as `SCHEMA_MISMATCH`: the AI service could not read the AI's reply in the required format, even after its own repair and one retry. Each one ended the whole attempt, and with two attempts per job two of them ended a job with nothing written (QTRIA-28 lost its file search to one). The runner lost nothing with such a turn, so the request is now made again, once, in the way a cut-off or a slow turn already is (QUIKTR-1853): one fixed sentence in the AI's transcript says its last answer could not be read in the required format and asks for exactly one reply in that format and a smaller step; the turn is recorded like the other recovered turns and is never counted as a refusal. It applies to the code-writing loop and to the file-search loop (where only this code is recovered: a cut-off or a slow turn there still falls back to the single call, as before). A second unreadable reply straight after the first, the final turn, and `QUIKPILOT_TURN_RECOVERY=off` end the attempt exactly as before; when it is the second in a row the failure message says so. New log event `targeting.loop_recovered` (the code-writing loop's `codegen.loop_recovered` now also carries `reason: schema_mismatch`). Nothing is deployed on the AI service, and nothing about the reply that failed is shown to the AI or logged.
178
+
175
179
  **9.3.0-rc.58 - write the fix first, then ask once about every existing test it breaks, with proof (QUIKTR-1851, absorbing QUIKTR-1850; release 1).** Until now, when an existing test expected the bug, the run stopped BEFORE any code was written and a person approved a change to that test with nothing to show it could ever pass, and the tests were found one at a time: QTRIA-23 approved a change that moved the status line off 401 and left `expect(body).toEqual({ ..., error: "Unauthorized" })`, which no fix can satisfy, and spent all three stops. Now, when the project switches it on (`packet.fixFirst`; `QUIKPILOT_FIX_FIRST=off` turns it off without a rebuild) the run speaks `codegen-loop-8`: a `report_test_conflict` is a PROPOSAL that does not end the run, the AI writes the tests and the fix and reports every existing test its fix breaks, and at its DONE the runner proves the proposals (`proofCheck.ts`): it runs the project's WHOLE suite (the related-tests planner off, a fresh tool, outside the AI's run allowance) with the fix and every proposed change written over the old code. A proposal whose test still fails is sent back with its name ("change EVERY expectation of it"), and an existing test the fix broke that no proposal covers is sent back by name (never a failure message: QUIKTR-1474), at most twice; one that still fails after that is not offered to a person. Then ONE stop, as before, whose proposals carry `oldCodeChecked` (fails on the old code with the change alone), `newCode` (`passes` / `fails` / `not_checked`) and `newEndLine` (where the changed test now ends, for showing the whole test); no time, no answer or a list of failures cut to fit is `not_checked`, never proven. The tests phase hands its proposals to the code phase. An AI Runtime that refuses `codegen-loop-8` is asked again as loop-7 (nothing else changes), a fix turn stays loop-7, and a project that did not switch it on sends and receives exactly what it did. Release 2 (keeping the fix across the stop) is not in this version: the next job still writes the code again. Also in rc.58: everything in rc.57.
176
180
 
177
181
  **9.3.0-rc.57 - rc.56 and rc.55 together.** rc.56 (QUIKTR-1701 release 2) was built and published from a source that did not yet contain rc.55's turn recovery (QUIKTR-1853: a cut-off answer or a slow turn is asked again once in a smaller step instead of ending the attempt), so a project pinned to rc.56 lost it. rc.57 is the merge of the two and nothing else: everything in rc.56 and everything in rc.55. Also in rc.57: everything in rc.54.
package/dist/index.js CHANGED
@@ -42366,7 +42366,9 @@ function stubOldLooks(i3) {
42366
42366
  let shrunk = 0;
42367
42367
  for (let index = 0; index < i3.results.length; index++) {
42368
42368
  const r = i3.results[index];
42369
- if (!LOOK_TOOLS.has(r.name) || r.status !== "ok" || r.output === void 0 || isStubbed(r.output)) continue;
42369
+ const shrinkable = r.status === "ok" || i3.repeats === true && r.status === "duplicate";
42370
+ if (!LOOK_TOOLS.has(r.name) || !shrinkable || r.output === void 0 || isStubbed(r.output)) continue;
42371
+ if (i3.keep?.(r.id)) continue;
42370
42372
  const turn = i3.turnOf(r.id);
42371
42373
  if (turn === void 0 || turn > i3.currentTurn - KEEP_TURNS) continue;
42372
42374
  const call = i3.callOf(r.id);
@@ -46707,6 +46709,7 @@ function missingImportSentence(m) {
46707
46709
 
46708
46710
  // src/turnRecovery.ts
46709
46711
  var RECOVERY_RULE = "length";
46712
+ var MALFORMED_REPLY_CODE = "SCHEMA_MISMATCH";
46710
46713
  var COMMON = "Take a smaller step: fewer files and fewer edits in one turn, and make each edit a small find-and-replace change.";
46711
46714
  var SENTENCES = {
46712
46715
  cut_off: {
@@ -46716,8 +46719,13 @@ var SENTENCES = {
46716
46719
  slow: {
46717
46720
  violation: "Your last step took too long, so none of it was run.",
46718
46721
  message: `Your last step took too long, so none of it was run. ${COMMON}`
46722
+ },
46723
+ malformed: {
46724
+ violation: "Your last answer could not be read as the required format, so none of it was run.",
46725
+ message: `Your last answer was not in the required format, so none of it was run. Answer again with exactly one reply in the required format and nothing else. ${COMMON}`
46719
46726
  }
46720
46727
  };
46728
+ var IN_WORDS = { cut_off: "cut off", slow: "too slow", malformed: "unreadable" };
46721
46729
  function turnRecoveryOff(env2 = process.env) {
46722
46730
  return env2.QUIKPILOT_TURN_RECOVERY === "off";
46723
46731
  }
@@ -46729,9 +46737,7 @@ function recoveryAnswer(kind) {
46729
46737
  return { rules: [RECOVERY_RULE], violations: [s.violation], message: s.message };
46730
46738
  }
46731
46739
  function repeatedLossDetail(kind, first) {
46732
- const now = kind === "cut_off" ? "cut off" : "too slow";
46733
- const before = first === "cut_off" ? "cut off" : "too slow";
46734
- return `a turn was ${before}, and the next one, after the AI was asked for a smaller step, was ${now} too`;
46740
+ return `a turn was ${IN_WORDS[first]}, and the next one, after the AI was asked for a smaller step, was ${IN_WORDS[kind]} too`;
46735
46741
  }
46736
46742
 
46737
46743
  // src/conflictVerify.ts
@@ -46946,6 +46952,7 @@ async function runTargetingLoop(args2, deps) {
46946
46952
  const usedIds = /* @__PURE__ */ new Set();
46947
46953
  const refusedTurns = [];
46948
46954
  let refusedStreak = 0;
46955
+ let unreadableStreak = 0;
46949
46956
  let peakRequestTokens = 0;
46950
46957
  const usage = new TurnUsage();
46951
46958
  let turns = 0;
@@ -47028,6 +47035,13 @@ async function runTargetingLoop(args2, deps) {
47028
47035
  const fallbackText = `pilot.targeting failed: ${runtimeCode}`;
47029
47036
  throw new SafetyRefusalError(inner?.message ?? fallbackText, inner?.summary ?? fallbackText);
47030
47037
  }
47038
+ if (runtimeCode === MALFORMED_REPLY_CODE && shouldRecover({ isFinal, consecutive: unreadableStreak })) {
47039
+ unreadableStreak += 1;
47040
+ refusedTurns.push({ turn, rules: [RECOVERY_RULE] });
47041
+ transcript.push({ turn, toolCalls: [], refused: recoveryAnswer("malformed") });
47042
+ log({ event: "targeting.loop_recovered", turn, reason: "schema_mismatch", runtimeCode, elapsedMs: now() - turnStarted });
47043
+ continue;
47044
+ }
47031
47045
  throw new LoopFailure(runtimeCode && OUTPUT_TOO_LARGE_CODES.has(runtimeCode) ? "output_too_large" : "runtime_failed", runtimeCode);
47032
47046
  }
47033
47047
  let body2;
@@ -47036,6 +47050,7 @@ async function runTargetingLoop(args2, deps) {
47036
47050
  } catch (err2) {
47037
47051
  throw new LoopFailure("bad_reply", void 0, err2);
47038
47052
  }
47053
+ unreadableStreak = 0;
47039
47054
  if (body2.outcome === REFUSED_OUTCOME) {
47040
47055
  const answer = readRefusedAnswer(body2);
47041
47056
  if (!answer) throw new LoopFailure("bad_reply");
@@ -47165,6 +47180,123 @@ async function runTargetingLoop(args2, deps) {
47165
47180
  }
47166
47181
  }
47167
47182
 
47183
+ // src/workingFiles.ts
47184
+ var KEEP_WORKING_FILES_ENV = "QUIKPILOT_KEEP_WORKING_FILES";
47185
+ var MAX_WORKING_PATHS = 3;
47186
+ var MAX_KEPT_CHARS = 4e4;
47187
+ function keepWorkingFilesOn(env2 = process.env) {
47188
+ return env2[KEEP_WORKING_FILES_ENV]?.trim().toLowerCase() === "on";
47189
+ }
47190
+ function rangeOf(args2) {
47191
+ if (typeof args2 !== "object" || args2 === null) return {};
47192
+ const a = args2;
47193
+ if (a.mode === "outline") return { mode: "outline" };
47194
+ const out2 = {};
47195
+ if (typeof a.startLine === "number" && Number.isInteger(a.startLine)) out2.startLine = a.startLine;
47196
+ if (typeof a.endLine === "number" && Number.isInteger(a.endLine)) out2.endLine = a.endLine;
47197
+ return out2;
47198
+ }
47199
+ function overlapOf(a, b) {
47200
+ if (a.mode === "outline" || b.mode === "outline") return a.mode === b.mode ? "same" : "disjoint";
47201
+ const aStart = a.startLine ?? 1;
47202
+ const bStart = b.startLine ?? 1;
47203
+ const aEnd = a.endLine ?? Number.POSITIVE_INFINITY;
47204
+ const bEnd = b.endLine ?? Number.POSITIVE_INFINITY;
47205
+ if (aStart === bStart && aEnd === bEnd) return "same";
47206
+ return aStart <= bEnd && bStart <= aEnd ? "overlapping" : "disjoint";
47207
+ }
47208
+ function stateOf(output, writtenSince, dropNotes) {
47209
+ if (writtenSince) return "after_write";
47210
+ if (!isStubbed(output)) return "whole";
47211
+ const note = output.note;
47212
+ return typeof note === "string" && dropNotes.has(note) ? "dropped" : "stubbed";
47213
+ }
47214
+ function rangeKey(r) {
47215
+ return r.mode === "outline" ? "outline" : `${r.startLine ?? ""}-${r.endLine ?? ""}`;
47216
+ }
47217
+ function sizeOf2(output) {
47218
+ try {
47219
+ return JSON.stringify(output)?.length ?? 0;
47220
+ } catch {
47221
+ return Number.POSITIVE_INFINITY;
47222
+ }
47223
+ }
47224
+ var ReadTracker = class {
47225
+ reads = [];
47226
+ writes = [];
47227
+ seq = 0;
47228
+ noteRead(entry) {
47229
+ this.reads.push({ ...entry, seq: this.seq++ });
47230
+ }
47231
+ noteWrite(path, turn) {
47232
+ this.writes.push({ path, turn, seq: this.seq++ });
47233
+ }
47234
+ lastWriteSeq(path) {
47235
+ let last = -1;
47236
+ for (const w of this.writes) if (w.path === path) last = w.seq;
47237
+ return last;
47238
+ }
47239
+ /**
47240
+ * The re-read report for `entry`, called BEFORE it is noted: null for a path not read before in this loop. `outputOf(id)` answers what the
47241
+ * earlier answer is now; `duplicate` is whether this read was answered as a repeat.
47242
+ */
47243
+ reread(entry, duplicate, outputOf, dropNotes) {
47244
+ let prev;
47245
+ for (const r of this.reads) if (r.path === entry.path) prev = r;
47246
+ if (!prev) return null;
47247
+ const writtenSince = this.writes.some((w) => w.path === entry.path && w.seq > prev.seq);
47248
+ const range = { startLine: entry.startLine, endLine: entry.endLine, mode: entry.mode };
47249
+ const prevRange = { startLine: prev.startLine, endLine: prev.endLine, mode: prev.mode };
47250
+ return {
47251
+ turn: entry.turn,
47252
+ path: entry.path,
47253
+ ...entry.mode ? { mode: entry.mode } : {},
47254
+ ...entry.startLine !== void 0 ? { startLine: entry.startLine } : {},
47255
+ ...entry.endLine !== void 0 ? { endLine: entry.endLine } : {},
47256
+ prevTurn: prev.turn,
47257
+ ...prev.mode ? { prevMode: prev.mode } : {},
47258
+ ...prev.startLine !== void 0 ? { prevStartLine: prev.startLine } : {},
47259
+ ...prev.endLine !== void 0 ? { prevEndLine: prev.endLine } : {},
47260
+ overlap: overlapOf(range, prevRange),
47261
+ prevState: stateOf(outputOf(prev.id), writtenSince, dropNotes),
47262
+ duplicate
47263
+ };
47264
+ }
47265
+ /**
47266
+ * The ids of the answers to keep whole: for each working file (written in this loop, or read in two different turns; the three most recently
47267
+ * used), the newest answer per range made after the file's latest write, while it is still whole; at most 40,000 characters, newest first.
47268
+ */
47269
+ keep(outputOf) {
47270
+ const lastUse = /* @__PURE__ */ new Map();
47271
+ const turnsRead = /* @__PURE__ */ new Map();
47272
+ for (const r of this.reads) {
47273
+ lastUse.set(r.path, Math.max(lastUse.get(r.path) ?? -1, r.seq));
47274
+ turnsRead.set(r.path, (turnsRead.get(r.path) ?? /* @__PURE__ */ new Set()).add(r.turn));
47275
+ }
47276
+ for (const w of this.writes) lastUse.set(w.path, Math.max(lastUse.get(w.path) ?? -1, w.seq));
47277
+ const working = [...lastUse.keys()].filter((path) => this.writes.some((w) => w.path === path) || (turnsRead.get(path)?.size ?? 0) >= 2).sort((a, b) => lastUse.get(b) - lastUse.get(a)).slice(0, MAX_WORKING_PATHS);
47278
+ const candidates = [];
47279
+ for (const path of working) {
47280
+ const after = this.lastWriteSeq(path);
47281
+ const newestPerRange = /* @__PURE__ */ new Map();
47282
+ for (const r of this.reads) if (r.path === path && r.seq > after) newestPerRange.set(rangeKey(r), r);
47283
+ candidates.push(...newestPerRange.values());
47284
+ }
47285
+ candidates.sort((a, b) => b.seq - a.seq);
47286
+ const kept = /* @__PURE__ */ new Set();
47287
+ let chars = 0;
47288
+ for (const c of candidates) {
47289
+ const output = outputOf(c.id);
47290
+ if (output === void 0 || isStubbed(output)) continue;
47291
+ const size = sizeOf2(output);
47292
+ if (chars + size > MAX_KEPT_CHARS) continue;
47293
+ chars += size;
47294
+ kept.add(c.id);
47295
+ }
47296
+ return kept;
47297
+ }
47298
+ };
47299
+
47168
47300
  // src/codegenLoop.ts
47169
47301
  var CODEGEN_LOOP_CONTRACT_VERSION = "codegen-loop-1";
47170
47302
  var CODEGEN_LOOP_2_CONTRACT_VERSION = "codegen-loop-2";
@@ -47280,6 +47412,7 @@ function isTestAnswer(x) {
47280
47412
  }
47281
47413
  var DROPPED_OUTPUT = { dropped: true, note: "Dropped to keep the request small. Read the file again if you need it." };
47282
47414
  var DROPPED_UNSEEN_OUTPUT = { dropped: true, note: "Too large to send with the rest of this request. Read a smaller part of the file." };
47415
+ var DROP_NOTES = /* @__PURE__ */ new Set([DROPPED_OUTPUT.note, DROPPED_UNSEEN_OUTPUT.note]);
47283
47416
  function repoMapGuidancePaths(baseContext) {
47284
47417
  const map = baseContext.repoMap;
47285
47418
  return (Array.isArray(map?.guidance) ? map.guidance : []).map((g) => g.path).filter((p) => typeof p === "string");
@@ -47336,6 +47469,7 @@ async function runCodegenLoop(args2, deps) {
47336
47469
  now
47337
47470
  }) : null;
47338
47471
  const notesOn = harness && args2.tools2?.notes === true;
47472
+ const keepOn = notesOn && keepWorkingFilesOn();
47339
47473
  const conflictTool = notesOn && args2.conflicts !== void 0 && args2.tests !== void 0 ? new TestConflictTool({
47340
47474
  existingTests: new Set(args2.protectedTestPaths),
47341
47475
  deniedPaths: args2.deniedPaths,
@@ -47381,6 +47515,16 @@ async function runCodegenLoop(args2, deps) {
47381
47515
  const usage = new TurnUsage();
47382
47516
  let notes = "";
47383
47517
  let stubbed = 0;
47518
+ const tracker = new ReadTracker();
47519
+ const rereadCounts = { rereads: 0, rereadsAfterStub: 0, rereadsAfterDrop: 0 };
47520
+ let keptMax = 0;
47521
+ let rereadsLogged = false;
47522
+ const logRereads = () => {
47523
+ if (rereadsLogged) return;
47524
+ rereadsLogged = true;
47525
+ log({ event: "codegen.reread_summary", ...rereadCounts, ...keepOn ? { kept: keptMax } : {} });
47526
+ };
47527
+ const outputOf = (id) => toolResults.find((r) => r.id === id)?.output;
47384
47528
  const turnOfId = /* @__PURE__ */ new Map();
47385
47529
  const callOfId = /* @__PURE__ */ new Map();
47386
47530
  const previousAttempt = args2.previousAttempt && !harness ? previousForLoop2(args2.previousAttempt) : args2.previousAttempt;
@@ -47507,7 +47651,7 @@ async function runCodegenLoop(args2, deps) {
47507
47651
  ...usage.totals.calls > 0 ? { turnUsage: usage.rows.map((r) => ({ ...r, parts: { ...r.parts } })), usage: { ...usage.totals } } : {},
47508
47652
  ...usage.rowsCut ? { turnUsageCut: true } : {}
47509
47653
  });
47510
- const dropOutputs = (upTo, done, output) => {
47654
+ const dropOutputs = (upTo, done, output, keep) => {
47511
47655
  const lastTestRun = toolResults.map((r) => r.name).lastIndexOf(RUN_TESTS_TOOL);
47512
47656
  const lastCall = toolResults.map((r) => r.name).lastIndexOf(CALL_FUNCTION_TOOL);
47513
47657
  const lastScratch = toolResults.map((r) => r.name).lastIndexOf(RUN_SCRATCH_TOOL);
@@ -47515,7 +47659,8 @@ async function runCodegenLoop(args2, deps) {
47515
47659
  for (let i3 = 0; i3 < upTo && !done(); i3++) {
47516
47660
  const r = toolResults[i3];
47517
47661
  if (r.output === DROPPED_OUTPUT || r.output === DROPPED_UNSEEN_OUTPUT) continue;
47518
- const stale = READ_TOOLS.has(r.name) && r.status === "ok" || r.name === RUN_TESTS_TOOL && i3 !== lastTestRun && r.output !== void 0 || r.name === CALL_FUNCTION_TOOL && i3 !== lastCall && r.output !== void 0 || r.name === RUN_SCRATCH_TOOL && i3 !== lastScratch && r.output !== void 0;
47662
+ if (keep?.has(r.id)) continue;
47663
+ const stale = READ_TOOLS.has(r.name) && (r.status === "ok" || keepOn && r.status === "duplicate" && r.output !== void 0) || r.name === RUN_TESTS_TOOL && i3 !== lastTestRun && r.output !== void 0 || r.name === CALL_FUNCTION_TOOL && i3 !== lastCall && r.output !== void 0 || r.name === RUN_SCRATCH_TOOL && i3 !== lastScratch && r.output !== void 0;
47519
47664
  if (!stale) continue;
47520
47665
  toolResults[i3] = { ...r, output };
47521
47666
  dropped++;
@@ -47527,7 +47672,7 @@ async function runCodegenLoop(args2, deps) {
47527
47672
  const fits = () => under(limits.maxRequestTokens);
47528
47673
  const soft = args2.readRoots ? mapSoftTarget(firstRequestTokens, limits.maxRequestTokens) : limits.maxRequestTokens;
47529
47674
  if (under(soft)) return true;
47530
- dropOutputs(sent.results, () => under(soft), DROPPED_OUTPUT);
47675
+ dropOutputs(sent.results, () => under(soft), DROPPED_OUTPUT, keepOn ? tracker.keep(outputOf) : void 0);
47531
47676
  for (const key of [...ledger.seen.keys()]) {
47532
47677
  if (key.startsWith("read_file:") || key.startsWith("grep:") || key.startsWith("list_files:") || key.startsWith("show_changes:")) ledger.seen.delete(key);
47533
47678
  }
@@ -47594,7 +47739,7 @@ async function runCodegenLoop(args2, deps) {
47594
47739
  };
47595
47740
  log({ event: "codegen.loop_start", maxTurns: limits.maxTurns, maxToolCalls: limits.maxToolCalls, listingFiles: args2.listing.length });
47596
47741
  const loseTurn = (turn, kind, isFinalTurn, runtimeCode, elapsedMs) => {
47597
- const reason = kind === "cut_off" ? "output_too_large" : "turn_timeout";
47742
+ const reason = kind === "cut_off" ? "output_too_large" : kind === "slow" ? "turn_timeout" : "runtime_failed";
47598
47743
  if (!shouldRecover({ isFinal: isFinalTurn, consecutive: lostStreak })) {
47599
47744
  const again = lostLast !== null && lostStreak > 0;
47600
47745
  const failure = new CodegenLoopFailure(reason, runtimeCode, void 0, again ? repeatedLossDetail(kind, lostLast) : void 0);
@@ -47605,7 +47750,7 @@ async function runCodegenLoop(args2, deps) {
47605
47750
  lostLast = kind;
47606
47751
  refusedTurns.push({ turn, rules: [RECOVERY_RULE] });
47607
47752
  transcript.push({ turn, toolCalls: [], refused: recoveryAnswer(kind) });
47608
- log({ event: "codegen.loop_recovered", turn, reason, ...runtimeCode ? { runtimeCode } : {}, elapsedMs });
47753
+ log({ event: "codegen.loop_recovered", turn, reason: kind === "malformed" ? "schema_mismatch" : reason, ...runtimeCode ? { runtimeCode } : {}, elapsedMs });
47609
47754
  forced = settleNextTurn(turn, forced);
47610
47755
  return true;
47611
47756
  };
@@ -47662,6 +47807,11 @@ async function runCodegenLoop(args2, deps) {
47662
47807
  if (handled === true) continue;
47663
47808
  throw handled;
47664
47809
  }
47810
+ if (runtimeCode === MALFORMED_REPLY_CODE) {
47811
+ const handled = loseTurn(turn, "malformed", isFinal, runtimeCode, now() - turnStarted);
47812
+ if (handled === true) continue;
47813
+ throw handled;
47814
+ }
47665
47815
  throw new CodegenLoopFailure("runtime_failed", runtimeCode);
47666
47816
  }
47667
47817
  let body2;
@@ -47837,6 +47987,7 @@ async function runCodegenLoop(args2, deps) {
47837
47987
  }
47838
47988
  }
47839
47989
  const stopReason = isFinal ? `forced_${finalReason}` : "model_done";
47990
+ logRereads();
47840
47991
  log({ event: "codegen.loop_done", turns, toolCalls: ledger.toolCalls, edits: ws.edits.size, created: ws.created.size, stopReason });
47841
47992
  const told = lastTestAnswer ?? (args2.phase === "tests" ? currentRedRuns().at(-1)?.answer : void 0);
47842
47993
  const proposals = args2.fixFirst === true && conflictTool ? conflictTool.recorded() : [];
@@ -47919,6 +48070,20 @@ async function runCodegenLoop(args2, deps) {
47919
48070
  }
47920
48071
  }
47921
48072
  results.push(result);
48073
+ if (call.name === "read_file" && isPlainObject3(call.args) && typeof call.args.path === "string" && (result.status === "ok" || result.status === "duplicate")) {
48074
+ const entry = { id: call.id, turn, path: call.args.path, ...rangeOf(call.args) };
48075
+ const again = tracker.reread(entry, result.status === "duplicate", (id) => results.find((x) => x.id === id)?.output ?? outputOf(id), DROP_NOTES);
48076
+ if (again) {
48077
+ rereadCounts.rereads += 1;
48078
+ if (again.prevState === "stubbed") rereadCounts.rereadsAfterStub += 1;
48079
+ else if (again.prevState === "dropped") rereadCounts.rereadsAfterDrop += 1;
48080
+ log({ event: "codegen.reread", ...again });
48081
+ }
48082
+ tracker.noteRead(entry);
48083
+ }
48084
+ if ((WRITE_TOOLS.has(call.name) || call.name === "revert_file") && result.status === "ok" && isPlainObject3(call.args) && typeof call.args.path === "string") {
48085
+ tracker.noteWrite(call.args.path, turn);
48086
+ }
47922
48087
  if (call.name === RUN_TESTS_TOOL && isTestAnswer(result.output) && result.output.scope === void 0) lastTestAnswer = result.output;
47923
48088
  if (call.name === RUN_TESTS_TOOL && isTestAnswer(result.output) && result.status !== "duplicate") {
47924
48089
  const file = result.output.scope === "file" && isPlainObject3(call.args) && typeof call.args.file === "string" ? call.args.file : void 0;
@@ -47930,7 +48095,8 @@ async function runCodegenLoop(args2, deps) {
47930
48095
  statusCounts[result.status] = (statusCounts[result.status] ?? 0) + 1;
47931
48096
  const tool = TOOL_NAMES2.has(call.name) ? call.name : "unknown";
47932
48097
  const pathArg = isPlainObject3(call.args) && typeof call.args.path === "string" && result.status !== "refused" ? { path: call.args.path } : {};
47933
- logged.push({ tool, status: result.status, ...result.reason && result.status !== "duplicate" ? { reason: result.reason } : {}, ...pathArg });
48098
+ const rangeArg = call.name === "read_file" && result.status !== "refused" ? rangeOf(call.args) : {};
48099
+ logged.push({ tool, status: result.status, ...result.reason && result.status !== "duplicate" ? { reason: result.reason } : {}, ...pathArg, ...rangeArg });
47934
48100
  if (result.status === "refused" || result.status === "protected") {
47935
48101
  log({ event: "codegen.loop_refused", turn, tool, status: result.status, reason: result.reason });
47936
48102
  }
@@ -47945,7 +48111,16 @@ async function runCodegenLoop(args2, deps) {
47945
48111
  callOfId.set(c.id, { name: c.name, args: c.args });
47946
48112
  }
47947
48113
  notes = keepNotes(notes, body2.notes, scrub);
47948
- stubbed += stubOldLooks({ results: toolResults, turnOf: (id) => turnOfId.get(id), callOf: (id) => callOfId.get(id), currentTurn: turn, ledger });
48114
+ const kept = keepOn ? tracker.keep(outputOf) : null;
48115
+ if (kept) keptMax = Math.max(keptMax, kept.size);
48116
+ stubbed += stubOldLooks({
48117
+ results: toolResults,
48118
+ turnOf: (id) => turnOfId.get(id),
48119
+ callOf: (id) => callOfId.get(id),
48120
+ currentTurn: turn,
48121
+ ledger,
48122
+ ...kept ? { keep: (id) => kept.has(id), repeats: true } : {}
48123
+ });
47949
48124
  }
47950
48125
  noProgressStreak = harness ? results.every((r) => NOTHING_NEW.has(r.status)) ? noProgressStreak + 1 : 0 : results.every((r) => r.status === "duplicate") ? noProgressStreak + 1 : 0;
47951
48126
  if (noProgressStreak >= (harness ? HARNESS_NO_PROGRESS_TURNS : 2)) forced = "no_progress";
@@ -47957,6 +48132,7 @@ async function runCodegenLoop(args2, deps) {
47957
48132
  }
47958
48133
  throw new CodegenLoopFailure("final_not_produced");
47959
48134
  } catch (err2) {
48135
+ logRereads();
47960
48136
  if (err2 instanceof SafetyRefusalError) throw err2;
47961
48137
  if (err2 instanceof TreeNotRestoredError) throw err2;
47962
48138
  const unreportable = conflictTool?.unreportable() ?? [];
@@ -51448,7 +51624,7 @@ var FAILURE_ARTIFACT_DIR = "quikpilot-failure";
51448
51624
  var REPORT_COPY = "final-test-report.xml";
51449
51625
  var MAX_REPORT_BYTES = 5 * 1024 * 1024;
51450
51626
  var MAX_FILES = 200;
51451
- var RUNNER_VERSION = true ? "9.3.0-rc.62" : "dev";
51627
+ var RUNNER_VERSION = true ? "9.3.0-rc.64" : "dev";
51452
51628
  function safeDestination(base, repoPath) {
51453
51629
  if (!repoPath || (0, import_node_path26.isAbsolute)(repoPath)) return null;
51454
51630
  const destination = (0, import_node_path26.resolve)(base, repoPath);