@quikit/quikpilot-runner 9.3.0-rc.23 → 9.3.0-rc.24

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
@@ -150,6 +150,8 @@ it, the callback carries it as `unsuppliedInputs` (at most 10 functions, 5 names
150
150
  noticed" as a check. This is the shape of a change whose new tests pass only because they hand the function the field themselves. It can be
151
151
  wrong (a field that arrives from a database row or a request), so it only warns and never blocks. TypeScript is not covered (QUIKTR-1547).
152
152
 
153
+ **9.3.0-rc.24 — cases that must keep working, a tighter amendment, and a stop for loops that change nothing (QUIKTR-1608, live batch of 15 Oct).** On rc.23 no pull request of bugs 1 to 7 was fully right. Six bugs had an approved case that passes on the old code by design ("splits that already divide cleanly must not change"); the red check told the AI to make it fail, and the AI broke a correct test. (1) Phase 1's DONE is sent back once, not twice, and the sentence says a case that must keep working may stay as it is; the second DONE is accepted and the reviewer warned about the cases seen passing. A phase-1 give-up with at least one own test failing on the untouched code is phase 1 done, the passing ones warned the same way. (2) A phase-2 DONE whose latest run still fails a frozen test is handed over as a give-up (live run QUIKSPL-210). (3) The amendment runs only when exactly one frozen test fails (QUIKSPL-209 rewrote three to match wrong code), and afterwards the runner checks that only that test's expected values changed: its set-up, its inputs and the rest of the file must be as phase 2 left them, or the run fails `test_case_disagree`. (4) Under the harness version, three replies in a row that change nothing (repeats, no-op or missed edits, unchanged test runs) make the next turn the last (`no_progress`). The AI Runtime's three phase paragraphs (contract §33.6) say the same; deploy them first.
154
+
153
155
  **9.3.0-rc.23 — the red check counts one-file runs (QUIKTR-1608, live run QUIKSPL-208).** On rc.22 the first two-phase run opened a correct pull request (#112), but phase 1 proved the bug with a run of its test file (4 failing on the old code), the red check counted whole-suite runs only, sent the DONE back twice and ended phase 1 marked 5 cases unproven, so the reviewer was wrongly warned. Every run of phase 1 is now evidence, with the change it ran on: a case is FAILING when a run on the change as it stands lists its test failing; PASSING when such a run covered its test (the whole suite, or the one file that holds its `[QP-...]` token) and it did not fail; NOT RUN when nothing covered it. A test seen passing is sent back as before; one not run is sent back with a sentence naming it, and if phase 1 ends anyway it is logged (`ended_unrun`) but never shown to the reviewer as unproven: only a test seen passing on the old code is. A cut failing list still cannot tell. The next phase is told about the latest run on the change as it stands, a one-file run included. Runner only.
154
156
 
155
157
  **9.3.0-rc.22 — phase 1 after the first live run (QUIKTR-1608, live run QUIKSPL-207).** On rc.21 the first live two-phase run failed in phase 1 in both attempts: the AI fought the existing-test rule for ten turns, then made its red tests pass and gave up. (1) In phase `tests`, a give-up (`CANNOT_COMPLETE`) whose change passes every hand-over check (every case covered, tests only) and whose tests were seen failing on the untouched code, in a whole-suite run on the change as it stands, is phase 1 done: the code phase follows (log `codegen.red_check` `gave_up_but_red`). (2) A failed two-phase attempt now records the phases it went through and their counts, as a finished one does. The AI Runtime's phase-1 paragraph (contract §33.4, amended) says failing is the goal (DONE then) and to put new tests and their helpers in a new test file when an existing one sends additions back; deploy it first.
package/dist/index.js CHANGED
@@ -14201,8 +14201,15 @@ var CodegenLoopFailure = class extends Error {
14201
14201
  if (cause !== void 0) this.cause = cause;
14202
14202
  }
14203
14203
  };
14204
+ function samePlace2(a, b) {
14205
+ const x = a.replace(/\\/g, "/").replace(/^(\.\/)+/, "");
14206
+ const y = b.replace(/\\/g, "/").replace(/^(\.\/)+/, "");
14207
+ return x === y || x.endsWith(`/${y}`) || y.endsWith(`/${x}`);
14208
+ }
14204
14209
  var MAX_ID_CHARS2 = 64;
14205
- var MAX_RED_REFUSALS = 2;
14210
+ var MAX_RED_REFUSALS = 1;
14211
+ var NOTHING_NEW = /* @__PURE__ */ new Set(["duplicate", "no_effect", "no_change_since_last_run", "no_match", "ambiguous"]);
14212
+ var HARNESS_NO_PROGRESS_TURNS = 3;
14206
14213
  var MAX_CALLS_IN_A_REPLY2 = 50;
14207
14214
  var MAX_SUMMARY_CHARS = 300;
14208
14215
  var READ_TOOLS = /* @__PURE__ */ new Set(["list_files", "read_file", "grep", "show_changes"]);
@@ -14315,8 +14322,8 @@ async function runCodegenLoop(args, deps) {
14315
14322
  }
14316
14323
  if (passing.length > 0) {
14317
14324
  const one = passing.length === 1;
14318
- const named = passing.slice(0, 6).map((id) => `[${id}]`).join(", ");
14319
- const sentence = `${named} ${one ? "passes" : "pass"} on the code before any change, so ${one ? "it does" : "they do"} not show the bug: revise ${one ? "it" : "them"} so ${one ? "it fails" : "each fails"} for the reason its case gives.`;
14325
+ const named = passing.slice(0, 4).map((id) => `[${id}]`).join(", ");
14326
+ const sentence = `${named} ${one ? "passes" : "pass"} on the code before any change. A case that shows the bug: make its test fail for the reason the case gives. A case that must keep working: leave its test as it is and answer DONE again.`;
14320
14327
  return { ids: passing, sentence: sentence.slice(0, 300), kind: "passing" };
14321
14328
  }
14322
14329
  if (unrun.length > 0) {
@@ -14501,10 +14508,11 @@ async function runCodegenLoop(args, deps) {
14501
14508
  log({ event: "codegen.loop_turn", turn, outcome: "cannot_complete", requestTokens, elapsedMs: now() - turnStarted, calls: [] });
14502
14509
  const said = typeof body.summary === "string" ? body.summary.slice(0, MAX_SUMMARY_CHARS) : void 0;
14503
14510
  const last = lastTestAnswer;
14504
- if (harness && args.phase === "tests" && currentRedRuns().length > 0 && handOverRefusal(turn, true) === null && redProblem() === null) {
14505
- log({ event: "codegen.red_check", turn, outcome: "gave_up_but_red", files: overlay.changedPaths().length });
14511
+ const redLeft = harness && args.phase === "tests" ? redProblem() : null;
14512
+ if (harness && args.phase === "tests" && currentRedRuns().some((r) => r.failing.length > 0) && handOverRefusal(turn, true) === null && (redLeft === null || redLeft.kind === "passing")) {
14513
+ log({ event: "codegen.red_check", turn, outcome: "gave_up_but_red", files: overlay.changedPaths().length, ...redLeft ? { unproven: redLeft.ids.length } : {} });
14506
14514
  const red = currentRedRuns().at(-1).answer;
14507
- return { results: overlay.results(), summary: snapshot("gave_up_kept"), doneSummary: said ?? "", steps: sentSteps(), lastTestAnswer: last ?? red };
14515
+ return { results: overlay.results(), summary: snapshot("gave_up_kept"), doneSummary: said ?? "", steps: sentSteps(), ...redLeft ? { redUnproven: redLeft.ids } : {}, lastTestAnswer: last ?? red };
14508
14516
  }
14509
14517
  if (args.keepOnGiveUp === true && last !== void 0 && last.regressions + last.newFailures > 0 && handOverRefusal(turn, true) === null) {
14510
14518
  log({ event: "codegen.loop_kept", files: overlay.changedPaths().length, regressions: last.regressions, newFailures: last.newFailures });
@@ -14532,8 +14540,16 @@ async function runCodegenLoop(args, deps) {
14532
14540
  if (red.kind === "passing") redUnproven = red.ids;
14533
14541
  log({ event: "codegen.red_check", turn, outcome: red.kind === "passing" ? "ended_unproven" : "ended_unrun", cases: red.ids.length });
14534
14542
  }
14535
- const stopReason = isFinal ? `forced_${finalReason}` : "model_done";
14536
14543
  const doneSummary = typeof body.summary === "string" ? body.summary.slice(0, MAX_SUMMARY_CHARS) : "";
14544
+ const lane = args.lane;
14545
+ if (harness && args.phase === "code" && lane?.kind === "code" && !lane.amend && args.keepOnGiveUp === true) {
14546
+ const red2 = currentRedRuns().filter((r) => r.failing.some((name) => lane.frozen.some((p) => samePlace2(name.split("::")[0] ?? "", p)))).at(-1);
14547
+ if (red2) {
14548
+ log({ event: "codegen.loop_kept", files: overlay.changedPaths().length, regressions: red2.answer.regressions, newFailures: red2.answer.newFailures, after: "done" });
14549
+ return { results: overlay.results(), summary: snapshot("gave_up_kept"), doneSummary, gaveUp: true, steps: sentSteps(), lastTestAnswer: red2.answer };
14550
+ }
14551
+ }
14552
+ const stopReason = isFinal ? `forced_${finalReason}` : "model_done";
14537
14553
  log({ event: "codegen.loop_done", turns, toolCalls: ledger.toolCalls, edits: ws.edits.size, created: ws.created.size, stopReason });
14538
14554
  const told = lastTestAnswer ?? (args.phase === "tests" ? currentRedRuns().at(-1)?.answer : void 0);
14539
14555
  return { results: overlay.results(), summary: snapshot(stopReason), doneSummary, steps: sentSteps(), ...redUnproven ? { redUnproven } : {}, ...told ? { lastTestAnswer: told } : {} };
@@ -14606,8 +14622,8 @@ async function runCodegenLoop(args, deps) {
14606
14622
  transcript.push({ turn, ...reasonText ? { reasoning: reasonText } : {}, toolCalls: calls.map((c) => ({ id: c.id, name: c.name, args: c.args })) });
14607
14623
  toolResults.push(...results);
14608
14624
  refusedStreak = 0;
14609
- noProgressStreak = results.every((r) => r.status === "duplicate") ? noProgressStreak + 1 : 0;
14610
- if (noProgressStreak >= 2 && !harness) forced = "no_progress";
14625
+ noProgressStreak = harness ? results.every((r) => NOTHING_NEW.has(r.status)) ? noProgressStreak + 1 : 0 : results.every((r) => r.status === "duplicate") ? noProgressStreak + 1 : 0;
14626
+ if (noProgressStreak >= (harness ? HARNESS_NO_PROGRESS_TURNS : 2)) forced = "no_progress";
14611
14627
  else if (ledger.toolCalls >= limits.maxToolCalls) forced = "tool_budget";
14612
14628
  else if (ledger.writeChars >= limits.writeCharsTotal) forced = "write_budget";
14613
14629
  else if (ledger.readChars >= limits.readCharsTotal || ledger.resultChars >= limits.resultCharsTotal) forced = "read_budget";
@@ -14627,10 +14643,55 @@ async function runCodegenLoop(args, deps) {
14627
14643
  }
14628
14644
 
14629
14645
  // src/codegenPhases.ts
14630
- function samePlace2(a, b) {
14631
- const x = a.replace(/\\/g, "/").replace(/^(\.\/)+/, "");
14632
- const y = b.replace(/\\/g, "/").replace(/^(\.\/)+/, "");
14633
- return x === y || x.endsWith(`/${y}`) || y.endsWith(`/${x}`);
14646
+ var QP_TOKEN = /\[QP-[^\]\s]+\]/;
14647
+ function testBlock(text, token) {
14648
+ const lines = text.split("\n");
14649
+ const at2 = lines.flatMap((line, n) => line.includes(token) ? [n] : []);
14650
+ if (at2.length !== 1) return null;
14651
+ let end = at2[0] + 1;
14652
+ while (end < lines.length && !QP_TOKEN.test(lines[end])) end += 1;
14653
+ return { start: at2[0], end };
14654
+ }
14655
+ function withoutExpectations(text) {
14656
+ let out = "";
14657
+ let i2 = 0;
14658
+ while (i2 < text.length) {
14659
+ const at2 = text.indexOf("expect(", i2);
14660
+ if (at2 === -1) {
14661
+ out += text.slice(i2);
14662
+ break;
14663
+ }
14664
+ out += text.slice(i2, at2);
14665
+ let depth = 0;
14666
+ let j = at2;
14667
+ let quote = null;
14668
+ for (; j < text.length; j++) {
14669
+ const c = text[j];
14670
+ if (quote) {
14671
+ if (c === "\\") j += 1;
14672
+ else if (c === quote) quote = null;
14673
+ continue;
14674
+ }
14675
+ if (c === '"' || c === "'" || c === "`") quote = c;
14676
+ else if (c === "(" || c === "[" || c === "{") depth += 1;
14677
+ else if (c === ")" || c === "]" || c === "}") depth -= 1;
14678
+ else if (depth <= 0 && (c === ";" || c === "\n")) break;
14679
+ }
14680
+ i2 = j;
14681
+ }
14682
+ return out;
14683
+ }
14684
+ function amendmentOverreach(before, after, token) {
14685
+ const a = testBlock(before, token);
14686
+ const b = testBlock(after, token);
14687
+ if (!a || !b) return "the test can no longer be found by its case";
14688
+ const la = before.split("\n");
14689
+ const lb = after.split("\n");
14690
+ const outside = (lines, s) => [...lines.slice(0, s.start), ...lines.slice(s.end)].join("\n");
14691
+ if (outside(la, a) !== outside(lb, b)) return "lines outside that test changed";
14692
+ const inside = (lines, s) => withoutExpectations(lines.slice(s.start, s.end).join("\n")).replace(/\s+/g, "");
14693
+ if (inside(la, a) !== inside(lb, b)) return "the test's setup or inputs changed, not only its expected values";
14694
+ return null;
14634
14695
  }
14635
14696
  var record = (phase, outcome, summary, redUnproven) => ({
14636
14697
  phase,
@@ -14712,11 +14773,16 @@ async function runPhases(i2) {
14712
14773
  i2.log({ event: "codegen.phase_end", attempt: i2.attempt, phase: "code", outcome: "finished" });
14713
14774
  return { done: d2, tests, phases, summaries };
14714
14775
  }
14715
- const failing = (d2.lastTestAnswer?.failingTests ?? []).map((name) => name.split("::")[0] ?? "");
14716
- const amend = tests.frozen.filter((path) => failing.some((file) => file !== "" && samePlace2(file, path))).slice(0, 20);
14776
+ const frozenFailing = (d2.lastTestAnswer?.failingTests ?? []).filter((name) => {
14777
+ const file2 = name.split("::")[0] ?? "";
14778
+ return file2 !== "" && tests.frozen.some((path2) => samePlace2(file2, path2));
14779
+ });
14780
+ const token = frozenFailing.length === 1 && d2.lastTestAnswer?.truncated !== true ? QP_TOKEN.exec(frozenFailing[0])?.[0] : void 0;
14781
+ const file = token ? frozenFailing[0].split("::")[0] ?? "" : "";
14782
+ const amend = token ? tests.frozen.filter((path2) => samePlace2(file, path2)).slice(0, 1) : [];
14717
14783
  phases.push(record("code", "gave_up", d2.summary));
14718
- i2.log({ event: "codegen.phase_end", attempt: i2.attempt, phase: "code", outcome: "gave_up", amendFiles: amend.length });
14719
- if (amend.length === 0) return { done: d2, tests, phases, summaries };
14784
+ i2.log({ event: "codegen.phase_end", attempt: i2.attempt, phase: "code", outcome: "gave_up", amendFiles: amend.length, frozenFailing: frozenFailing.length });
14785
+ if (amend.length === 0 || !token) return { done: d2, tests, phases, summaries };
14720
14786
  i2.log({ event: "codegen.phase_start", attempt: i2.attempt, phase: "amend", files: amend.length });
14721
14787
  let d3;
14722
14788
  try {
@@ -14736,6 +14802,16 @@ async function runPhases(i2) {
14736
14802
  disagree.summary = f.summary ?? d2.summary;
14737
14803
  return { failure: recorded(disagree, "amend"), tests, phases, final: true };
14738
14804
  }
14805
+ const path = amend[0];
14806
+ const textOf = (results) => results.find((r) => r.targetPath === path)?.newContent ?? "";
14807
+ const overreach = amendmentOverreach(textOf(d2.results), textOf(d3.results), token);
14808
+ if (overreach) {
14809
+ phases.push(record("amend", "failed", d3.summary));
14810
+ i2.log({ event: "codegen.phase_end", attempt: i2.attempt, phase: "amend", outcome: "overreached", why: overreach });
14811
+ const disagree = new CodegenLoopFailure("test_case_disagree", void 0, void 0, `the correction of ${token} went further than its expected values: ${overreach}`);
14812
+ disagree.summary = d3.summary;
14813
+ return { failure: recorded(disagree, "amend"), tests, phases, final: true };
14814
+ }
14739
14815
  phases.push(record("amend", "finished", d3.summary));
14740
14816
  summaries.push({ phase: "amend", summary: d3.summary });
14741
14817
  i2.log({ event: "codegen.phase_end", attempt: i2.attempt, phase: "amend", outcome: "finished" });
@@ -16563,7 +16639,7 @@ var FAILURE_ARTIFACT_DIR = "quikpilot-failure";
16563
16639
  var REPORT_COPY = "final-test-report.xml";
16564
16640
  var MAX_REPORT_BYTES = 5 * 1024 * 1024;
16565
16641
  var MAX_FILES = 200;
16566
- var RUNNER_VERSION = true ? "9.3.0-rc.23" : "dev";
16642
+ var RUNNER_VERSION = true ? "9.3.0-rc.24" : "dev";
16567
16643
  function safeDestination(base, repoPath) {
16568
16644
  if (!repoPath || (0, import_node_path15.isAbsolute)(repoPath)) return null;
16569
16645
  const destination = (0, import_node_path15.resolve)(base, repoPath);