@quikit/quikpilot-runner 9.3.0-rc.22 → 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,10 @@ 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
+
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.
156
+
153
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.
154
158
 
155
159
  **9.3.0-rc.21 (harness 6 of 7) — reproduce first, then fix (QUIKTR-1608, contract §33).** One step could change the tests and the code at once; when they disagreed the AI changed both (G18, G20, G23; fixes rescued 2 of 6 kept give-ups). Under the harness version an attempt is now written in phases, each held to its files by the runner (`codegenTools.ts` lane, answered `protected` before any budget is touched): (1) `loop.phase: "tests"` - only test files may change (the code answers `code_locked`); before the phase may end, each own test for a case with a known, non-Regression label must be seen FAILING in a whole-suite run on the untouched code. Otherwise the DONE is sent back as a refused turn (rule word `done_rule`, a fixed sentence naming the cases), at most twice; then the phase ends and the reviewer is warned (record `phases[].redUnproven`). (2) `loop.phase: "code"` - the phase-1 tests are frozen (`test_frozen`, also for any new or existing test file); the request carries them as a kept change (`endedWith: "tests_written"`, the red run, §32's steps). (3) When the code phase gives up while frozen tests of this run still fail: ONE amendment, a short code-phase loop with `loop.amend` (those files only, `edit_file` only, never emptied); the change then goes on with a warning naming the files. If the amendment fails too, the attempt fails `test_case_disagree` and is not tried again; no pull request. A second attempt after a failed code phase starts from the same frozen tests; fixes after the project's checks and the review fix are code-only with the tests frozen. The run record gains `phases` (phase, outcome, counts) and each test run its `phase`; the record now keeps 20 test runs and a run's `scope` (two gaps of the 1604 build). **`QUIKPILOT_TWO_PHASE=off` writes the change in one phase, as before.** AI Runtime contract §33 and QuikProjects (record schema) first. **Not published: waits for all seven harness tickets.**
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"]);
@@ -14293,22 +14300,38 @@ async function runCodegenLoop(args, deps) {
14293
14300
  const refusedTurns = [];
14294
14301
  let refusedStreak = 0;
14295
14302
  let sent = { entries: 0, results: 0 };
14296
- let lastTestVersion = null;
14303
+ const redRuns = [];
14297
14304
  let redRefusals = 0;
14298
14305
  let redUnproven;
14306
+ const currentRedRuns = () => {
14307
+ const now2 = versionOfFiles(filesOnDisk());
14308
+ return redRuns.filter((r) => r.version === now2);
14309
+ };
14299
14310
  const redProblem = () => {
14300
14311
  const ids = args.redCheckIds ?? [];
14301
14312
  if (ids.length === 0) return null;
14302
- if (!lastTestAnswer || lastTestVersion !== versionOfFiles(filesOnDisk())) {
14303
- return { ids, sentence: "Run the tests with run_tests before finishing phase 1: each new test must fail on the code before any change." };
14304
- }
14305
- if (lastTestAnswer.truncated) return null;
14306
- const failing = lastTestAnswer.failingTests;
14307
- const passing = ids.filter((id) => !failing.some((name) => name.includes(`[${id}]`)));
14308
- if (passing.length === 0) return null;
14309
- const named = passing.slice(0, 6).map((id) => `[${id}]`).join(", ");
14310
- const sentence = `${named} ${passing.length === 1 ? "passes" : "pass"} on the code before any change, so ${passing.length === 1 ? "it does" : "they do"} not show the bug: revise ${passing.length === 1 ? "it" : "them"} so ${passing.length === 1 ? "it fails" : "each fails"} for the reason its case gives.`;
14311
- return { ids: passing, sentence: sentence.slice(0, 300) };
14313
+ const runs = currentRedRuns();
14314
+ const passing = [];
14315
+ const unrun = [];
14316
+ for (const id of ids) {
14317
+ const token = `[${id}]`;
14318
+ if (runs.some((r) => r.failing.some((name) => name.includes(token)))) continue;
14319
+ const covering = runs.filter((r) => r.file === void 0 || (overlay.get(r.file)?.lf ?? "").includes(token));
14320
+ if (covering.length === 0) unrun.push(id);
14321
+ else if (covering.every((r) => !r.truncated)) passing.push(id);
14322
+ }
14323
+ if (passing.length > 0) {
14324
+ const one = passing.length === 1;
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.`;
14327
+ return { ids: passing, sentence: sentence.slice(0, 300), kind: "passing" };
14328
+ }
14329
+ if (unrun.length > 0) {
14330
+ const named = unrun.slice(0, 6).map((id) => `[${id}]`).join(", ");
14331
+ const sentence = `Run the tests with run_tests (the whole suite, or the file that holds them) before finishing phase 1: ${named} ${unrun.length === 1 ? "has" : "have"} not been run on the code as it is now.`;
14332
+ return { ids: unrun, sentence: sentence.slice(0, 300), kind: "unrun" };
14333
+ }
14334
+ return null;
14312
14335
  };
14313
14336
  const sentSteps = () => stepsOf(transcript.slice(0, sent.entries), toolResults.slice(0, sent.results));
14314
14337
  let turns = 0;
@@ -14485,9 +14508,11 @@ async function runCodegenLoop(args, deps) {
14485
14508
  log({ event: "codegen.loop_turn", turn, outcome: "cannot_complete", requestTokens, elapsedMs: now() - turnStarted, calls: [] });
14486
14509
  const said = typeof body.summary === "string" ? body.summary.slice(0, MAX_SUMMARY_CHARS) : void 0;
14487
14510
  const last = lastTestAnswer;
14488
- if (harness && args.phase === "tests" && last !== void 0 && lastTestVersion === versionOfFiles(filesOnDisk()) && handOverRefusal(turn, true) === null && redProblem() === null) {
14489
- log({ event: "codegen.red_check", turn, outcome: "gave_up_but_red", files: overlay.changedPaths().length });
14490
- return { results: overlay.results(), summary: snapshot("gave_up_kept"), doneSummary: said ?? "", steps: sentSteps(), lastTestAnswer: last };
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 } : {} });
14514
+ const red = currentRedRuns().at(-1).answer;
14515
+ return { results: overlay.results(), summary: snapshot("gave_up_kept"), doneSummary: said ?? "", steps: sentSteps(), ...redLeft ? { redUnproven: redLeft.ids } : {}, lastTestAnswer: last ?? red };
14491
14516
  }
14492
14517
  if (args.keepOnGiveUp === true && last !== void 0 && last.regressions + last.newFailures > 0 && handOverRefusal(turn, true) === null) {
14493
14518
  log({ event: "codegen.loop_kept", files: overlay.changedPaths().length, regressions: last.regressions, newFailures: last.newFailures });
@@ -14512,13 +14537,22 @@ async function runCodegenLoop(args, deps) {
14512
14537
  forced = settleNextTurn(turn, forced);
14513
14538
  continue;
14514
14539
  }
14515
- redUnproven = red.ids;
14516
- log({ event: "codegen.red_check", turn, outcome: "ended_unproven", cases: red.ids.length });
14540
+ if (red.kind === "passing") redUnproven = red.ids;
14541
+ log({ event: "codegen.red_check", turn, outcome: red.kind === "passing" ? "ended_unproven" : "ended_unrun", cases: red.ids.length });
14517
14542
  }
14518
- const stopReason = isFinal ? `forced_${finalReason}` : "model_done";
14519
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";
14520
14553
  log({ event: "codegen.loop_done", turns, toolCalls: ledger.toolCalls, edits: ws.edits.size, created: ws.created.size, stopReason });
14521
- return { results: overlay.results(), summary: snapshot(stopReason), doneSummary, steps: sentSteps(), ...redUnproven ? { redUnproven } : {}, ...lastTestAnswer ? { lastTestAnswer } : {} };
14554
+ const told = lastTestAnswer ?? (args.phase === "tests" ? currentRedRuns().at(-1)?.answer : void 0);
14555
+ return { results: overlay.results(), summary: snapshot(stopReason), doneSummary, steps: sentSteps(), ...redUnproven ? { redUnproven } : {}, ...told ? { lastTestAnswer: told } : {} };
14522
14556
  }
14523
14557
  if (body.outcome !== "TOOL_CALLS") throw new CodegenLoopFailure("bad_reply");
14524
14558
  if (isFinal) throw new CodegenLoopFailure("final_not_produced");
@@ -14570,9 +14604,10 @@ async function runCodegenLoop(args, deps) {
14570
14604
  }
14571
14605
  }
14572
14606
  results.push(result);
14573
- if (call.name === RUN_TESTS_TOOL && isTestAnswer(result.output) && result.output.scope === void 0) {
14574
- lastTestAnswer = result.output;
14575
- lastTestVersion = versionOfFiles(filesOnDisk());
14607
+ if (call.name === RUN_TESTS_TOOL && isTestAnswer(result.output) && result.output.scope === void 0) lastTestAnswer = result.output;
14608
+ if (call.name === RUN_TESTS_TOOL && isTestAnswer(result.output) && result.status !== "duplicate") {
14609
+ const file = result.output.scope === "file" && isPlainObject3(call.args) && typeof call.args.file === "string" ? call.args.file : void 0;
14610
+ redRuns.push({ version: versionOfFiles(filesOnDisk()), ...file ? { file } : {}, failing: result.output.failingTests, truncated: result.output.truncated, answer: result.output });
14576
14611
  }
14577
14612
  if (read) reads.push(read);
14578
14613
  statusCounts[result.status] = (statusCounts[result.status] ?? 0) + 1;
@@ -14587,8 +14622,8 @@ async function runCodegenLoop(args, deps) {
14587
14622
  transcript.push({ turn, ...reasonText ? { reasoning: reasonText } : {}, toolCalls: calls.map((c) => ({ id: c.id, name: c.name, args: c.args })) });
14588
14623
  toolResults.push(...results);
14589
14624
  refusedStreak = 0;
14590
- noProgressStreak = results.every((r) => r.status === "duplicate") ? noProgressStreak + 1 : 0;
14591
- 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";
14592
14627
  else if (ledger.toolCalls >= limits.maxToolCalls) forced = "tool_budget";
14593
14628
  else if (ledger.writeChars >= limits.writeCharsTotal) forced = "write_budget";
14594
14629
  else if (ledger.readChars >= limits.readCharsTotal || ledger.resultChars >= limits.resultCharsTotal) forced = "read_budget";
@@ -14608,10 +14643,55 @@ async function runCodegenLoop(args, deps) {
14608
14643
  }
14609
14644
 
14610
14645
  // src/codegenPhases.ts
14611
- function samePlace2(a, b) {
14612
- const x = a.replace(/\\/g, "/").replace(/^(\.\/)+/, "");
14613
- const y = b.replace(/\\/g, "/").replace(/^(\.\/)+/, "");
14614
- 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;
14615
14695
  }
14616
14696
  var record = (phase, outcome, summary, redUnproven) => ({
14617
14697
  phase,
@@ -14693,11 +14773,16 @@ async function runPhases(i2) {
14693
14773
  i2.log({ event: "codegen.phase_end", attempt: i2.attempt, phase: "code", outcome: "finished" });
14694
14774
  return { done: d2, tests, phases, summaries };
14695
14775
  }
14696
- const failing = (d2.lastTestAnswer?.failingTests ?? []).map((name) => name.split("::")[0] ?? "");
14697
- 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) : [];
14698
14783
  phases.push(record("code", "gave_up", d2.summary));
14699
- i2.log({ event: "codegen.phase_end", attempt: i2.attempt, phase: "code", outcome: "gave_up", amendFiles: amend.length });
14700
- 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 };
14701
14786
  i2.log({ event: "codegen.phase_start", attempt: i2.attempt, phase: "amend", files: amend.length });
14702
14787
  let d3;
14703
14788
  try {
@@ -14717,6 +14802,16 @@ async function runPhases(i2) {
14717
14802
  disagree.summary = f.summary ?? d2.summary;
14718
14803
  return { failure: recorded(disagree, "amend"), tests, phases, final: true };
14719
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
+ }
14720
14815
  phases.push(record("amend", "finished", d3.summary));
14721
14816
  summaries.push({ phase: "amend", summary: d3.summary });
14722
14817
  i2.log({ event: "codegen.phase_end", attempt: i2.attempt, phase: "amend", outcome: "finished" });
@@ -16544,7 +16639,7 @@ var FAILURE_ARTIFACT_DIR = "quikpilot-failure";
16544
16639
  var REPORT_COPY = "final-test-report.xml";
16545
16640
  var MAX_REPORT_BYTES = 5 * 1024 * 1024;
16546
16641
  var MAX_FILES = 200;
16547
- var RUNNER_VERSION = true ? "9.3.0-rc.22" : "dev";
16642
+ var RUNNER_VERSION = true ? "9.3.0-rc.24" : "dev";
16548
16643
  function safeDestination(base, repoPath) {
16549
16644
  if (!repoPath || (0, import_node_path15.isAbsolute)(repoPath)) return null;
16550
16645
  const destination = (0, import_node_path15.resolve)(base, repoPath);