@quikit/quikpilot-runner 9.3.0-rc.57 → 9.3.0-rc.58

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
@@ -164,6 +164,8 @@ wrong (a field that arrives from a database row or a request), so it only warns
164
164
 
165
165
  **9.3.0-rc.46 — the existing tests to read first include the ones that reach the code through one file in between (QUIKTR-1845).** On the live bug-6 run (QTRIA-17) the design changed `lib/services/issueFilters.ts`, and the two tests that assert the bug import `app/api/issues/route.ts`, which imports it, so the list of existing tests the AI reads before writing (`testsToCheck`, rc.44) was empty. When fewer than 3 test files are found by name or a direct import, the runner now takes one more step: of the files the tests import (code, not a test, not under a denied path; the 150 most shared first) it keeps the ones that import a changed file, and adds the tests that import them, after the others and up to 10 in all. A file in between imported by more than 12 tests only brings the tests named after it (a route by its folder) or after the changed file. Paths only, as before. With 3 or more found the list is exactly as in rc.45. Also in rc.46: everything in rc.45. Nothing else changes.
166
166
 
167
+ **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.
168
+
167
169
  **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.
168
170
 
169
171
  **9.3.0-rc.56 - outline and find_definition for eight languages, the last test-file names, and the AI's own tests kept in Python, Go and Java (QUIKTR-1701, release 2).** (1) `definitions.ts` reads the definitions of a Python, Go, Java, Kotlin, C#, Rust, Ruby or PHP file from its tree-sitter tree - functions, classes, methods, structs, interfaces, enums, modules, with exact line ranges and nesting (a Java or C# method, a Kotlin `fun`, a Ruby `valid?` and `def self.x`, a Rust `impl`). `read_file` mode "outline" and the too-large answer use it (`engine: "treesitter"`), and `find_definition` looks a name up in the tree of every file that holds it (at most 80 files are parsed per call; the rest, a file that does not parse and any other language keep the line patterns). The name rule is widened to any language: a letter of any script, `_` or `$`, then letters, digits, `_` or `$`, optionally a Ruby-style `?` or `!` at the end (the AI service checks the same rule first: deploy it BEFORE this runner), and a regular-expression character in a name can no longer break the pattern. The grammars are loaded once at the start of a run for the languages in the repository. (2) Test-file names: Surefire's `Test*.java` and `*TestCase.java`, Failsafe's `*IT.java`, Kotest and ScalaTest `FooSpec.kt/.scala`, Django `tests.py` and every file of a C# test project (`Acme.Tests/`) are test files (same table in the AI service and QuikProjects). (3) A fix may correct a test the AI wrote in this run in a Python, Go or Java file but not remove it, skip it (`@pytest.mark.skip`, `t.Skip()`, `@Disabled`) or leave it with fewer checks (assertion statements, `t.Error`/`t.Fatal`, `pytest.raises`, `fail(...)`), as for JavaScript. `QUIKPILOT_LANG_CHECKS=js` and `QUIKPILOT_TEST_LOCATE=js` switch the readers off. Also in rc.56: everything in rc.54 (rc.55 is QUIKTR-1853, built on its own branch).
package/dist/index.js CHANGED
@@ -37514,6 +37514,7 @@ function titlesHint(tests) {
37514
37514
  return shown.length === 0 ? "none" : `${shown.join(", ")}${tests.length > 12 ? ", ..." : ""}`;
37515
37515
  }
37516
37516
  var RECORDED_MESSAGE = "Recorded. This run will now stop before any code is delivered, and a person will decide about this test. Finish your answer; there is nothing more to do for this test.";
37517
+ var RECORDED_MESSAGE_FIX_FIRST = "Recorded as a proposal; nothing was changed. Carry on: write the tests and the fix, run the project's tests, and report every other existing test your fix breaks that expects what a case calls wrong. When your change is complete, answer DONE: QuikPilot then checks each proposal against your code and a person decides about them together.";
37517
37518
  var BOUNDS = { find: 8e3, replace: 2e4, title: 300, reason: 300, caseText: 1e3, value: 120, why: 300 };
37518
37519
  var ALLOWED_KEYS = /* @__PURE__ */ new Set([
37519
37520
  "path",
@@ -37638,6 +37639,22 @@ var TestConflictTool = class {
37638
37639
  recorded() {
37639
37640
  return [...this.byTest.values()];
37640
37641
  }
37642
+ /**
37643
+ * QUIKTR-1851: proposals recorded by an earlier phase of the same attempt (the tests phase), which the code phase's tool then holds as its own, so
37644
+ * the one stop at the end lists them all. They are replaced by a later report for the same test, like any other.
37645
+ */
37646
+ seed(conflicts) {
37647
+ for (const c of conflicts) this.byTest.set(`${c.path}\0${c.testTitle}`, { ...c });
37648
+ }
37649
+ /** QUIKTR-1851: the proofs of the checks at DONE, written onto the proposals they are about (by place in `recorded()`). */
37650
+ setEvidence(path, title, evidence) {
37651
+ const c = this.byTest.get(`${path}\0${title}`);
37652
+ if (c) Object.assign(c, evidence);
37653
+ }
37654
+ /** QUIKTR-1851: a proposal that could not be made to pass is taken out of the stop. */
37655
+ drop(path, title) {
37656
+ this.byTest.delete(`${path}\0${title}`);
37657
+ }
37641
37658
  /** QUIKTR-1823: the tests reported that are written once for many rows, one entry per test, in the order they were first reported. */
37642
37659
  unreportable() {
37643
37660
  return [...this.generated.values()];
@@ -37755,7 +37772,7 @@ var TestConflictTool = class {
37755
37772
  this.byTest.set(key, conflict);
37756
37773
  this.counts.recorded += 1;
37757
37774
  d.log?.({ event: "codegen.conflict_recorded", reading: r.reading, phase: d.phase ?? null, historyAvailable: history.available, ...isTable ? { rows: mine.length } : {} });
37758
- return { status: "conflict_recorded", message: RECORDED_MESSAGE, output: { history } };
37775
+ return { status: "conflict_recorded", message: d.fixFirst ? RECORDED_MESSAGE_FIX_FIRST : RECORDED_MESSAGE, output: { history } };
37759
37776
  }
37760
37777
  /** QUIKTR-1844: record a revision of an approved test change that does not fit. */
37761
37778
  recordRevision(r, revision, at2, key) {
@@ -37783,7 +37800,7 @@ var TestConflictTool = class {
37783
37800
  this.byTest.set(key, conflict);
37784
37801
  this.counts.recorded += 1;
37785
37802
  d.log?.({ event: "codegen.conflict_recorded", reading: r.reading, phase: d.phase ?? null, historyAvailable: history.available, revision: true, ...at2.isTable ? { rows: revision.rows } : {} });
37786
- return { status: "conflict_recorded", message: RECORDED_MESSAGE, output: { history } };
37803
+ return { status: "conflict_recorded", message: d.fixFirst ? RECORDED_MESSAGE_FIX_FIRST : RECORDED_MESSAGE, output: { history } };
37787
37804
  }
37788
37805
  };
37789
37806
  function fileText(lf, ending, bom) {
@@ -37875,6 +37892,8 @@ function lineOf2(c, file) {
37875
37892
  correction: c.correction,
37876
37893
  history: c.history,
37877
37894
  oldCodeChecked: c.oldCodeChecked === true,
37895
+ ...c.newCode !== void 0 ? { newCode: c.newCode } : {},
37896
+ ...c.newEndLine !== void 0 ? { newEndLine: c.newEndLine } : {},
37878
37897
  ...c.rows !== void 0 ? { rows: c.rows } : {},
37879
37898
  ...file.stale.get(c.index) ? { stale: file.stale.get(c.index) } : {},
37880
37899
  ...c.revises !== void 0 ? { revises: c.revises } : {},
@@ -37909,6 +37928,9 @@ function buildProposalMessage(input) {
37909
37928
  ...l.history.available ? [` Added ${l.history.addedAt ?? ""} in ${l.history.addedBySha?.slice(0, 10) ?? "a commit"}${l.history.subject ? `: ${oneLine(l.history.subject)}` : ""}`] : [],
37910
37929
  ...l.history.sameCommitPaths && l.history.sameCommitPaths.length > 0 ? [` The same change also touched: ${l.history.sameCommitPaths.slice(0, 5).join(", ")}${l.history.sameCommitPaths.length > 5 || l.history.sameCommitMore ? ", ..." : ""}`] : [],
37911
37930
  ...l.oldCodeChecked ? [" With this change the test fails on the code as it is today, so it shows the bug."] : [],
37931
+ ...l.newCode === "passes" ? [" With this change the test passes on the fix QuikPilot wrote."] : [],
37932
+ ...l.newCode === "fails" ? [" With this change the test still fails on the fix QuikPilot wrote."] : [],
37933
+ ...l.newCode === "not_checked" ? [" It was not checked whether this change passes on the fix QuikPilot wrote."] : [],
37912
37934
  ...l.stale ? [` ${staleNote(l.stale)}`] : [],
37913
37935
  ...l.revises ? [` ${revisionNote(l.revises, l.misfit)}`] : [],
37914
37936
  ""
@@ -37948,7 +37970,7 @@ function parseProposalMessage(message) {
37948
37970
  const o = j;
37949
37971
  const c = o.correction;
37950
37972
  const h = o.history;
37951
- if (o.v !== 1 || !isStr(o.path, 300) || !isStr(o.title, 300) || o.newTitle !== void 0 && !isStr(o.newTitle, 300) || !isStr(o.caseId, 64) || !CONFLICT_READINGS.includes(o.reading) || !isLine(o.startLine) || !isLine(o.endLine) || !isLine(o.changeLine) || !isStr(o.reason, 300) || typeof c !== "object" || c === null || !CONFLICT_CASE_FIELDS.includes(c.field) || !isStr(c.text, 1e3) || !isStr(c.why, 300) || typeof h !== "object" || h === null || typeof h.available !== "boolean" || typeof o.oldCodeChecked !== "boolean" || o.rows !== void 0 && !(typeof o.rows === "number" && Number.isInteger(o.rows) && o.rows >= 1 && o.rows <= 1e4) || o.stale !== void 0 && !isStale(o.stale) || o.revises !== void 0 && !(typeof o.revises === "string" && /^[0-9a-f]{40}$/.test(o.revises)) || o.misfit !== void 0 && (o.revises === void 0 || !isMisfit(o.misfit))) {
37973
+ if (o.v !== 1 || !isStr(o.path, 300) || !isStr(o.title, 300) || o.newTitle !== void 0 && !isStr(o.newTitle, 300) || !isStr(o.caseId, 64) || !CONFLICT_READINGS.includes(o.reading) || !isLine(o.startLine) || !isLine(o.endLine) || !isLine(o.changeLine) || !isStr(o.reason, 300) || typeof c !== "object" || c === null || !CONFLICT_CASE_FIELDS.includes(c.field) || !isStr(c.text, 1e3) || !isStr(c.why, 300) || typeof h !== "object" || h === null || typeof h.available !== "boolean" || typeof o.oldCodeChecked !== "boolean" || o.newCode !== void 0 && !["passes", "fails", "not_checked"].includes(o.newCode) || o.newEndLine !== void 0 && !isLine(o.newEndLine) || o.rows !== void 0 && !(typeof o.rows === "number" && Number.isInteger(o.rows) && o.rows >= 1 && o.rows <= 1e4) || o.stale !== void 0 && !isStale(o.stale) || o.revises !== void 0 && !(typeof o.revises === "string" && /^[0-9a-f]{40}$/.test(o.revises)) || o.misfit !== void 0 && (o.revises === void 0 || !isMisfit(o.misfit))) {
37952
37974
  continue;
37953
37975
  }
37954
37976
  out2.push(o);
@@ -37995,6 +38017,9 @@ function conflictsReport(p) {
37995
38017
  caseId: l.caseId,
37996
38018
  reading: l.reading,
37997
38019
  oldCodeChecked: l.oldCodeChecked,
38020
+ // QUIKTR-1851: only a fix-first stop carries them, so a loop-7 report is byte for byte what it was (QuikProjects reads a strict shape).
38021
+ ...l.newCode !== void 0 ? { newCode: l.newCode } : {},
38022
+ ...l.newEndLine !== void 0 ? { newEndLine: l.newEndLine } : {},
37998
38023
  ...l.rows !== void 0 ? { rows: l.rows } : {},
37999
38024
  ...l.history.available ? {
38000
38025
  history: {
@@ -46311,6 +46336,107 @@ function repeatedLossDetail(kind, first) {
46311
46336
  return `a turn was ${before}, and the next one, after the AI was asked for a smaller step, was ${now} too`;
46312
46337
  }
46313
46338
 
46339
+ // src/conflictVerify.ts
46340
+ var CUT_AT = 190;
46341
+ function failingNameIs(id, file, conflict) {
46342
+ const { file: where, name: name2 } = splitTestId(id);
46343
+ if (where !== null && !idPlaceMatches(where, file.path)) return false;
46344
+ const title = file.newTitles.get(conflict.index) ?? conflict.testTitle;
46345
+ if (conflict.rows !== void 0) return rowPattern({ describes: conflict.describes, title }, file.path).test(name2);
46346
+ const full = [...conflict.describes, title];
46347
+ const candidates = [title, full.join(" > "), full.join(" "), full.join(" \u203A ")];
46348
+ return candidates.includes(name2) || name2.length >= CUT_AT && candidates.some((c) => c.startsWith(name2));
46349
+ }
46350
+ async function verifyOnOldCode(conflicts, run3, log = () => void 0) {
46351
+ const { files, dropped: unmergeable } = buildProposalFiles(conflicts);
46352
+ if (files.length === 0 || run3 === null) return { kept: conflicts.filter((c) => !unmergeable.includes(c)), dropped: [] };
46353
+ let answer = null;
46354
+ try {
46355
+ answer = await run3(files.map((f) => ({ targetPath: f.path, newContent: fileText(f.newLf, f.ending, f.bom) })));
46356
+ } catch (err2) {
46357
+ if (err2 instanceof TreeNotRestoredError) throw err2;
46358
+ answer = null;
46359
+ }
46360
+ const usable = answer !== null && !answer.timedOut;
46361
+ const kept = [];
46362
+ const dropped = [];
46363
+ const outcomes = { fails: 0, passes: 0, unknown: 0 };
46364
+ for (const file of files) {
46365
+ for (const c of file.conflicts) {
46366
+ const fails = usable && answer.failingTests.some((id) => failingNameIs(id, file, c));
46367
+ if (fails) {
46368
+ kept.push({ ...c, oldCodeChecked: true });
46369
+ outcomes.fails += 1;
46370
+ } else if (usable && !answer.truncated) {
46371
+ dropped.push(c);
46372
+ outcomes.passes += 1;
46373
+ } else {
46374
+ kept.push({ ...c, oldCodeChecked: false });
46375
+ outcomes.unknown += 1;
46376
+ }
46377
+ }
46378
+ }
46379
+ const order = new Map(conflicts.map((c, i3) => [`${c.path}\0${c.testTitle}`, i3]));
46380
+ kept.sort((a, b) => (order.get(`${a.path}\0${a.testTitle}`) ?? 0) - (order.get(`${b.path}\0${b.testTitle}`) ?? 0));
46381
+ log({ event: "codegen.conflict_old_code", ...outcomes, files: files.length, ran: answer !== null, timedOut: answer?.timedOut ?? false });
46382
+ return { kept, dropped };
46383
+ }
46384
+
46385
+ // src/proofCheck.ts
46386
+ var keyOf2 = (c) => `${c.path}\0${c.testTitle}`;
46387
+ function newEndLineOf(f, c) {
46388
+ const located = locateTests(f.path, f.newLf);
46389
+ return located ? allTests(located)[c.index]?.endLine : void 0;
46390
+ }
46391
+ async function proveProposals(input) {
46392
+ const evidence = /* @__PURE__ */ new Map();
46393
+ const { files, dropped } = buildProposalFiles(input.conflicts);
46394
+ for (const c of dropped) evidence.set(keyOf2(c), { newCode: "not_checked" });
46395
+ const notChecked = () => {
46396
+ for (const f of files) for (const c of f.conflicts) evidence.set(keyOf2(c), { newCode: "not_checked", ...endOf(f, c) });
46397
+ return { ran: false, evidence, stillFailing: [], unexplained: [] };
46398
+ };
46399
+ const endOf = (f, c) => {
46400
+ const line = newEndLineOf(f, c);
46401
+ return line === void 0 ? {} : { newEndLine: line };
46402
+ };
46403
+ if (files.length === 0 || input.run === null) return notChecked();
46404
+ const proposed = files.map((f) => ({ targetPath: f.path, newContent: fileText(f.newLf, f.ending, f.bom) }));
46405
+ const merged = [...input.fix.filter((r) => !proposed.some((p) => p.targetPath === r.targetPath)).map((r) => ({ targetPath: r.targetPath, newContent: r.newContent })), ...proposed];
46406
+ let answer = null;
46407
+ try {
46408
+ answer = await input.run(merged);
46409
+ } catch {
46410
+ answer = null;
46411
+ }
46412
+ if (answer === null || answer.timedOut) return notChecked();
46413
+ const stillFailing = [];
46414
+ const covered = /* @__PURE__ */ new Set();
46415
+ for (const f of files) {
46416
+ for (const c of f.conflicts) {
46417
+ const failing = answer.failingTests.filter((id) => failingNameIs(id, f, c));
46418
+ for (const id of failing) covered.add(id);
46419
+ const newCode = failing.length > 0 ? "fails" : answer.truncated ? "not_checked" : "passes";
46420
+ evidence.set(keyOf2(c), { newCode, ...endOf(f, c) });
46421
+ if (newCode === "fails") stillFailing.push(c);
46422
+ }
46423
+ }
46424
+ const broken = answer.failingTests.slice(0, answer.regressions).filter((id) => !covered.has(id));
46425
+ return { ran: true, evidence, stillFailing, unexplained: groupRegressions(broken) };
46426
+ }
46427
+ var MAX_NAMED2 = 8;
46428
+ function proofSentences(proof) {
46429
+ const out2 = [];
46430
+ if (proof.stillFailing.length > 0) {
46431
+ const named = proof.stillFailing.slice(0, MAX_NAMED2).map((c) => `${c.path}: "${c.testTitle.replace(/\s+/g, " ").slice(0, 120)}"`);
46432
+ out2.push(
46433
+ `Your proposed change to ${named.join("; ")}${proof.stillFailing.length > MAX_NAMED2 ? `; and ${proof.stillFailing.length - MAX_NAMED2} more` : ""} still fails on your fix. Another line of that test still expects the old behaviour: change EVERY expectation of it (status, body, message) and report the test again.`
46434
+ );
46435
+ }
46436
+ if (proof.unexplained.length > 0) out2.push(...giveUpSentences(proof.unexplained).slice(0, MAX_NAMED2));
46437
+ return out2.map((s) => s.length > 300 ? `${s.slice(0, 299)}\u2026` : s);
46438
+ }
46439
+
46314
46440
  // src/targetingErrors.ts
46315
46441
  var DeniedPathError = class extends Error {
46316
46442
  constructor(message) {
@@ -46649,6 +46775,7 @@ var CODEGEN_LOOP_4_CONTRACT_VERSION = "codegen-loop-4";
46649
46775
  var CODEGEN_LOOP_5_CONTRACT_VERSION = "codegen-loop-5";
46650
46776
  var CODEGEN_LOOP_6_CONTRACT_VERSION = "codegen-loop-6";
46651
46777
  var CODEGEN_LOOP_7_CONTRACT_VERSION = "codegen-loop-7";
46778
+ var CODEGEN_LOOP_8_CONTRACT_VERSION = "codegen-loop-8";
46652
46779
  var MAP_SOFT_REQUEST_TOKENS = 4e4;
46653
46780
  var MAP_SOFT_HEADROOM_TOKENS = 2e4;
46654
46781
  function mapSoftTarget(firstRequestTokens, ceiling) {
@@ -46824,9 +46951,15 @@ async function runCodegenLoop(args2, deps) {
46824
46951
  baseline: args2.tests.baseline,
46825
46952
  scrub,
46826
46953
  ...args2.phase ? { phase: args2.phase } : {},
46954
+ ...args2.fixFirst === true ? { fixFirst: true } : {},
46827
46955
  log
46828
46956
  }) : null;
46829
- const contractVersion = harness ? args2.tools2 ? conflictTool ? CODEGEN_LOOP_7_CONTRACT_VERSION : notesOn ? CODEGEN_LOOP_6_CONTRACT_VERSION : CODEGEN_LOOP_5_CONTRACT_VERSION : args2.readRoots ? CODEGEN_LOOP_4_CONTRACT_VERSION : CODEGEN_LOOP_3_CONTRACT_VERSION : tests ? CODEGEN_LOOP_2_CONTRACT_VERSION : CODEGEN_LOOP_CONTRACT_VERSION;
46957
+ if (conflictTool && args2.seedProposals && args2.seedProposals.length > 0) conflictTool.seed(args2.seedProposals);
46958
+ const markNotChecked = () => {
46959
+ if (!conflictTool || args2.fixFirst !== true) return;
46960
+ for (const c of conflictTool.recorded()) if (c.newCode === void 0) conflictTool.setEvidence(c.path, c.testTitle, { newCode: "not_checked" });
46961
+ };
46962
+ const contractVersion = harness ? args2.tools2 ? conflictTool ? args2.fixFirst === true ? CODEGEN_LOOP_8_CONTRACT_VERSION : CODEGEN_LOOP_7_CONTRACT_VERSION : notesOn ? CODEGEN_LOOP_6_CONTRACT_VERSION : CODEGEN_LOOP_5_CONTRACT_VERSION : args2.readRoots ? CODEGEN_LOOP_4_CONTRACT_VERSION : CODEGEN_LOOP_3_CONTRACT_VERSION : tests ? CODEGEN_LOOP_2_CONTRACT_VERSION : CODEGEN_LOOP_CONTRACT_VERSION;
46830
46963
  let peakRequestTokens = 0;
46831
46964
  let firstRequestTokens = 0;
46832
46965
  const usage = new TurnUsage();
@@ -46853,6 +46986,7 @@ async function runCodegenLoop(args2, deps) {
46853
46986
  const redRuns = [];
46854
46987
  let redRefusals = 0;
46855
46988
  let importRefusals = 0;
46989
+ let proofSendBacks = 0;
46856
46990
  let giveUpRefusals = 0;
46857
46991
  let redUnproven;
46858
46992
  const currentRedRuns = () => {
@@ -47137,6 +47271,7 @@ async function runCodegenLoop(args2, deps) {
47137
47271
  log({ event: "codegen.loop_turn", turn, outcome: "cannot_complete", requestTokens, elapsedMs: now() - turnStarted, calls: [] });
47138
47272
  const said = typeof body2.summary === "string" ? body2.summary.slice(0, MAX_SUMMARY_CHARS) : void 0;
47139
47273
  if (conflictTool && conflictTool.recorded().length > 0) {
47274
+ markNotChecked();
47140
47275
  throw new TestConflictStop(conflictTool.recorded(), new CodegenLoopFailure("cannot_complete", void 0, void 0, said, said));
47141
47276
  }
47142
47277
  if (conflictTool && conflictTool.unreportable().length > 0) {
@@ -47181,7 +47316,35 @@ async function runCodegenLoop(args2, deps) {
47181
47316
  }
47182
47317
  if (conflictTool && conflictTool.recorded().length > 0) {
47183
47318
  const said = typeof body2.summary === "string" ? body2.summary.slice(0, MAX_SUMMARY_CHARS) : void 0;
47184
- throw new TestConflictStop(conflictTool.recorded(), new CodegenLoopFailure("cannot_complete", void 0, void 0, said, said));
47319
+ if (args2.fixFirst !== true) throw new TestConflictStop(conflictTool.recorded(), new CodegenLoopFailure("cannot_complete", void 0, void 0, said, said));
47320
+ if (args2.phase !== "tests") {
47321
+ const proof = await proveProposals({ conflicts: conflictTool.recorded(), fix: overlay.results(), run: pastHardStop() ? null : deps.wholeSuite ?? null });
47322
+ for (const c of conflictTool.recorded()) {
47323
+ const ev = proof.evidence.get(keyOf2(c));
47324
+ if (ev) conflictTool.setEvidence(c.path, c.testTitle, ev);
47325
+ }
47326
+ const sentences = proofSentences(proof);
47327
+ const counts = { passes: 0, fails: 0, notChecked: 0 };
47328
+ for (const ev of proof.evidence.values()) counts[ev.newCode === "passes" ? "passes" : ev.newCode === "fails" ? "fails" : "notChecked"] += 1;
47329
+ log({ event: "codegen.proof_check", turn, ran: proof.ran, proposals: proof.evidence.size, ...counts, unexplained: proof.unexplained.length, sendBacks: proofSendBacks });
47330
+ if (sentences.length > 0 && proofSendBacks < 2 && !isFinal) {
47331
+ proofSendBacks += 1;
47332
+ const answer = {
47333
+ rules: ["done_rule"],
47334
+ violations: sentences,
47335
+ message: "Your answer was sent back: QuikPilot ran the project's tests on your finished change with every proposed test change written over it, and found problems. Each sentence names them."
47336
+ };
47337
+ refusedStreak += 1;
47338
+ refusedTurns.push({ turn, rules: answer.rules });
47339
+ transcript.push({ turn, toolCalls: [], refused: answer });
47340
+ if (refusedStreak >= REFUSED_STREAK_LIMIT) forced = "refused_repeatedly";
47341
+ forced = settleNextTurn(turn, forced);
47342
+ continue;
47343
+ }
47344
+ for (const c of proof.stillFailing) conflictTool.drop(c.path, c.testTitle);
47345
+ const detail = proof.unexplained.length > 0 ? oldBehaviourSentence(proof.unexplained, MAX_PREVIOUS_DETAIL_CHARS) : proof.stillFailing.length > 0 ? "a proposed change to an existing test could not be made to pass on the fix" : said;
47346
+ throw new TestConflictStop(conflictTool.recorded(), new CodegenLoopFailure("cannot_complete", void 0, void 0, detail, said));
47347
+ }
47185
47348
  }
47186
47349
  const refusal = handOverRefusal(turn, false);
47187
47350
  if (refusal) throw refusal;
@@ -47259,7 +47422,16 @@ async function runCodegenLoop(args2, deps) {
47259
47422
  const stopReason = isFinal ? `forced_${finalReason}` : "model_done";
47260
47423
  log({ event: "codegen.loop_done", turns, toolCalls: ledger.toolCalls, edits: ws.edits.size, created: ws.created.size, stopReason });
47261
47424
  const told = lastTestAnswer ?? (args2.phase === "tests" ? currentRedRuns().at(-1)?.answer : void 0);
47262
- return { results: overlay.results(), summary: snapshot(stopReason), doneSummary, steps: sentSteps(), ...redUnproven ? { redUnproven } : {}, ...told ? { lastTestAnswer: told } : {} };
47425
+ const proposals = args2.fixFirst === true && conflictTool ? conflictTool.recorded() : [];
47426
+ return {
47427
+ results: overlay.results(),
47428
+ summary: snapshot(stopReason),
47429
+ doneSummary,
47430
+ steps: sentSteps(),
47431
+ ...redUnproven ? { redUnproven } : {},
47432
+ ...told ? { lastTestAnswer: told } : {},
47433
+ ...proposals.length > 0 ? { proposals } : {}
47434
+ };
47263
47435
  }
47264
47436
  if (body2.outcome !== "TOOL_CALLS") throw new CodegenLoopFailure("bad_reply");
47265
47437
  if (isFinal) throw new CodegenLoopFailure("final_not_produced");
@@ -47364,6 +47536,7 @@ async function runCodegenLoop(args2, deps) {
47364
47536
  }
47365
47537
  let failure = err2 instanceof CodegenLoopFailure ? err2 : new CodegenLoopFailure("internal_error", void 0, err2);
47366
47538
  if (conflictTool && conflictTool.recorded().length > 0) {
47539
+ markNotChecked();
47367
47540
  const stop2 = new TestConflictStop(conflictTool.recorded(), failure);
47368
47541
  stop2.summary = failure.summary ?? snapshot("test_conflict");
47369
47542
  throw withUnreportable(stop2, unreportable);
@@ -47484,7 +47657,8 @@ async function runPhases(i3) {
47484
47657
  summary: d1.summary,
47485
47658
  ...d1.lastTestAnswer ? { answer: d1.lastTestAnswer } : {},
47486
47659
  ...d1.steps ? { steps: d1.steps } : {},
47487
- ...d1.redUnproven ? { redUnproven: d1.redUnproven } : {}
47660
+ ...d1.redUnproven ? { redUnproven: d1.redUnproven } : {},
47661
+ ...d1.proposals ? { proposals: d1.proposals } : {}
47488
47662
  };
47489
47663
  }
47490
47664
  i3.log({ event: "codegen.phase_start", attempt: i3.attempt, phase: "code" });
@@ -47495,6 +47669,7 @@ async function runPhases(i3) {
47495
47669
  phase: "code",
47496
47670
  lane: { kind: "code", testPaths: i3.testPaths, frozen: tests.frozen },
47497
47671
  seed: tests.results,
47672
+ ...tests.proposals ? { seedProposals: tests.proposals } : {},
47498
47673
  keepOnGiveUp: true,
47499
47674
  previousAttempt: keptChange(i3.attempt, "tests_written", tests.answer, tests.steps)
47500
47675
  });
@@ -48379,52 +48554,6 @@ function mapModeMessage(phase, reason) {
48379
48554
  return `QuikPilot could not ${what}: this project is too large to send the AI its full list of files, so it was sent a summary instead, and that did not finish (${WHY[reason] ?? reason}). There is no other way to try on a project this size, so nothing was changed.`;
48380
48555
  }
48381
48556
 
48382
- // src/conflictVerify.ts
48383
- var CUT_AT = 190;
48384
- function failingNameIs(id, file, conflict) {
48385
- const { file: where, name: name2 } = splitTestId(id);
48386
- if (where !== null && !idPlaceMatches(where, file.path)) return false;
48387
- const title = file.newTitles.get(conflict.index) ?? conflict.testTitle;
48388
- if (conflict.rows !== void 0) return rowPattern({ describes: conflict.describes, title }, file.path).test(name2);
48389
- const full = [...conflict.describes, title];
48390
- const candidates = [title, full.join(" > "), full.join(" "), full.join(" \u203A ")];
48391
- return candidates.includes(name2) || name2.length >= CUT_AT && candidates.some((c) => c.startsWith(name2));
48392
- }
48393
- async function verifyOnOldCode(conflicts, run3, log = () => void 0) {
48394
- const { files, dropped: unmergeable } = buildProposalFiles(conflicts);
48395
- if (files.length === 0 || run3 === null) return { kept: conflicts.filter((c) => !unmergeable.includes(c)), dropped: [] };
48396
- let answer = null;
48397
- try {
48398
- answer = await run3(files.map((f) => ({ targetPath: f.path, newContent: fileText(f.newLf, f.ending, f.bom) })));
48399
- } catch (err2) {
48400
- if (err2 instanceof TreeNotRestoredError) throw err2;
48401
- answer = null;
48402
- }
48403
- const usable = answer !== null && !answer.timedOut;
48404
- const kept = [];
48405
- const dropped = [];
48406
- const outcomes = { fails: 0, passes: 0, unknown: 0 };
48407
- for (const file of files) {
48408
- for (const c of file.conflicts) {
48409
- const fails = usable && answer.failingTests.some((id) => failingNameIs(id, file, c));
48410
- if (fails) {
48411
- kept.push({ ...c, oldCodeChecked: true });
48412
- outcomes.fails += 1;
48413
- } else if (usable && !answer.truncated) {
48414
- dropped.push(c);
48415
- outcomes.passes += 1;
48416
- } else {
48417
- kept.push({ ...c, oldCodeChecked: false });
48418
- outcomes.unknown += 1;
48419
- }
48420
- }
48421
- }
48422
- const order = new Map(conflicts.map((c, i3) => [`${c.path}\0${c.testTitle}`, i3]));
48423
- kept.sort((a, b) => (order.get(`${a.path}\0${a.testTitle}`) ?? 0) - (order.get(`${b.path}\0${b.testTitle}`) ?? 0));
48424
- log({ event: "codegen.conflict_old_code", ...outcomes, files: files.length, ran: answer !== null, timedOut: answer?.timedOut ?? false });
48425
- return { kept, dropped };
48426
- }
48427
-
48428
48557
  // src/testsToCheck.ts
48429
48558
  var import_node_fs16 = require("node:fs");
48430
48559
  var import_node_path19 = require("node:path");
@@ -48621,6 +48750,7 @@ function buildCodegenLoopArgs(p, context = collectLoopContext({
48621
48750
  ...p.mode === "loop-tests" && p.tests && p.harness !== false && p.tools2 ? { tools2: p.tools2 } : {},
48622
48751
  ...p.mode === "loop-tests" && p.tests && p.harness !== false && p.callFunction ? { callFunction: p.callFunction } : {},
48623
48752
  ...p.mode === "loop-tests" && p.tests && p.harness !== false && p.tools2?.notes === true && p.conflicts ? { conflicts: p.conflicts, ...testsToCheckOf(p) } : {},
48753
+ ...p.mode === "loop-tests" && p.tests && p.harness !== false && p.tools2?.notes === true && p.conflicts && p.fixFirst === true ? { fixFirst: true } : {},
48624
48754
  // An approved test change stands whatever version the AI Runtime speaks: a person decided it.
48625
48755
  ...p.approved && p.approved.length > 0 ? { approved: p.approved.map((r) => ({ targetPath: r.targetPath, newContent: r.newContent })) } : {}
48626
48756
  };
@@ -48668,16 +48798,18 @@ function lose(p, summary, attempts, stop2, unreportable) {
48668
48798
  p.out.loop = buildCodegenLoopRecord({ ...summary ?? NO_SUMMARY, stopReason: stop2, attempts });
48669
48799
  return new CodegenAttemptsExhausted(attempts, stop2, unreportable);
48670
48800
  }
48671
- function oldCodeRunner(args2, log, now) {
48801
+ function oldCodeRunner(args2, log, now, wholeSuite = false) {
48672
48802
  return async (files) => {
48673
48803
  const disk = files.map((r) => ({ path: r.targetPath, content: r.newContent }));
48674
48804
  const tool = new RunTestsTool({
48675
48805
  ...args2.tests,
48806
+ // QUIKTR-1851: the proof of a proposal needs the WHOLE suite, never only the tests related to the change (the planner would leave a broken test out).
48807
+ ...wholeSuite ? { planner: void 0 } : {},
48676
48808
  requiredAutomationIds: args2.requiredAutomationIds,
48677
48809
  harness: true,
48678
48810
  overlayFiles: () => disk,
48679
48811
  overlayVersion: () => versionOfFiles(disk),
48680
- log: (e) => log({ ...e, event: "codegen.old_code_run" }),
48812
+ log: (e) => log({ ...e, event: wholeSuite ? "codegen.proof_run" : "codegen.old_code_run" }),
48681
48813
  now
48682
48814
  });
48683
48815
  const answer = await tool.execute("old-code");
@@ -48737,6 +48869,8 @@ async function runCodegenStep(p) {
48737
48869
  const loopDeps = {
48738
48870
  post: (contextData, signal) => postCodegenTurn(p.gateway, contextData, signal),
48739
48871
  secrets: [p.gateway.token],
48872
+ // QUIKTR-1851: built per call, because `args` is rebuilt when a version is refused. A fresh tool per run: the AI's run allowance is not touched.
48873
+ wholeSuite: async (files) => args2?.tests && now() < hardStopAtMs ? oldCodeRunner(args2, log, now, true)(files) : null,
48740
48874
  ...p.deps,
48741
48875
  hardStopAtMs
48742
48876
  };
@@ -48800,6 +48934,12 @@ async function runCodegenStep(p) {
48800
48934
  log({ event: "codegen.attempt_start", attempt: 1 });
48801
48935
  const firstStarted = now();
48802
48936
  let first = await attempt2();
48937
+ if ("failure" in first && first.failure.reason === "contract_rejected" && p.fixFirst === true && args2?.fixFirst === true) {
48938
+ log({ event: "codegen.version_fallback", from: "codegen-loop-8", to: "codegen-loop-7" });
48939
+ p.fixFirst = false;
48940
+ args2 = buildCodegenLoopArgs(p, context);
48941
+ first = await attempt2();
48942
+ }
48803
48943
  if ("failure" in first && first.failure.reason === "contract_rejected" && p.conflicts && args2?.conflicts) {
48804
48944
  log({ event: "codegen.version_fallback", from: "codegen-loop-7", to: "codegen-loop-6" });
48805
48945
  p.conflicts = void 0;
@@ -48980,7 +49120,7 @@ async function runHealAttempt(i3) {
48980
49120
  p,
48981
49121
  collectLoopContext({ targets: p.targets, listing: p.workspaceListing, deniedPaths: p.deniedPaths, writeRoot: p.writeRoot ?? "", ...discoveredTests ? { discoveredTests } : {}, readFile: disk })
48982
49122
  );
48983
- const args2 = buildCodegenLoopArgs({ ...p, targets, workspaceListing }, context);
49123
+ const args2 = buildCodegenLoopArgs({ ...p, targets, workspaceListing, fixFirst: false }, context);
48984
49124
  if (i3.review !== void 0 || i3.answer.regressions <= 0) delete args2.conflicts;
48985
49125
  if (args2.conflicts && i3.misfits && i3.misfits.length > 0) args2.conflicts = withMisfits(args2.conflicts, i3.misfits);
48986
49126
  args2.protectedTestPaths = original.protectedTestPaths;
@@ -50869,7 +51009,7 @@ var FAILURE_ARTIFACT_DIR = "quikpilot-failure";
50869
51009
  var REPORT_COPY = "final-test-report.xml";
50870
51010
  var MAX_REPORT_BYTES = 5 * 1024 * 1024;
50871
51011
  var MAX_FILES = 200;
50872
- var RUNNER_VERSION = true ? "9.3.0-rc.57" : "dev";
51012
+ var RUNNER_VERSION = true ? "9.3.0-rc.58" : "dev";
50873
51013
  function safeDestination(base, repoPath) {
50874
51014
  if (!repoPath || (0, import_node_path25.isAbsolute)(repoPath)) return null;
50875
51015
  const destination = (0, import_node_path25.resolve)(base, repoPath);
@@ -51692,6 +51832,8 @@ async function run2(env2) {
51692
51832
  mode: codegenMode,
51693
51833
  ...keepOnGiveUp ? { keepOnGiveUp: true } : {},
51694
51834
  ...conflictsOn ? { conflicts: { decided, titles: approved?.titles ?? [], approvedTests: approved?.approvedTests ?? [] } } : {},
51835
+ // QUIKTR-1851: write the fix first, then ask once; the project switched it on, and `QUIKPILOT_FIX_FIRST=off` turns it off without a rebuild.
51836
+ ...conflictsOn && packet.fixFirst === true && process.env.QUIKPILOT_FIX_FIRST?.trim().toLowerCase() !== "off" ? { fixFirst: true } : {},
51695
51837
  ...approved && approved.files.length > 0 ? { approved: approved.files } : {},
51696
51838
  ...callFunction ? { callFunction } : {},
51697
51839
  ...twoPhase ? { twoPhase: true, ...packet.requiredTestTypes ? { requiredTestTypes: packet.requiredTestTypes } : {} } : {},