@quikit/quikpilot-runner 9.3.0-rc.19 → 9.3.0-rc.20

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.20 — a change with blocks no test depends on gets ONE fix attempt (QUIKTR-1569 Stage C).** Twice in live runs the AI fixed the requested bug and also rewrote a neighbouring line wrongly, with every test green; the check added in QUIKTR-1569 (put each changed block back on its own and see whether any test notices) found it, but only told the reviewer afterwards. Now, in `loop-tests` mode, when the change has passed every check and the fix allowance and the time allow it, the check runs BEFORE the change is committed. If it flags blocks, the change is taken off the disk and ONE fix attempt starts from it, told the file and line numbers (`loop.previousAttempt`: `endedWith: "unneeded_changes"`, `changesKept`, the passing run, `detail` e.g. `src/history.js, line 36`; never code, at most 300 characters): put each block back if the issue and the cases do not ask for it, or add a test of it that can fail. It can only improve the run: if the fix gives up, errors, or its change no longer passes every check, the change that had already passed is checked again and shipped, with the same notice as before. One review fix per run; it uses one of the fix attempts, so the three-in-all limit still holds. The check's result is reused for the final notice when the change did not change. The run record marks the earlier attempt `checks: passed` and the fix as started by `heal`; a fix put back ends as the new stop word `review_reverted`. **`QUIKPILOT_REVIEW_FIX=off` restores today's notice-only behaviour without a release.** The AI Runtime's contract 24.12g (one new reason word and one fixed paragraph) must be deployed FIRST; without it the new word is only logged as `other` and the fix gets the general kept-change paragraph. No QuikProjects change. **Also in rc.20 -** the failure line the AI reads names the failing assertion (below).
154
+
155
+ **9.3.0-rc.20 — the failure line the AI reads names the failing assertion (test-expectations plan, Part A2).** In the one failed run of the 12-run live test (F7) the AI's own test asserted a field its case never named; the message was `expected false to be true // Object.is equality`, which fits any of a test's assertions, and the fix argued with the code instead of the test. The test report's failure body holds the stack, so the first frame that points into a source file and is not under `node_modules` (vitest `❯ src/a.test.js:6:23`, node and jest `at fn (/abs/src/a.test.js:130:30)`) now gives `path:line`, made relative to the checkout. It is added to the END of the first line of the failure message the AI is shown for a test written in this run: `expected false to be true // Object.is equality [at src/a.test.js:6]`, in the `run_tests` answer and in the fix attempt's `lastTestRun.messages` (the same function). A path and a line number only; the line is cut so the place always survives within 120 characters. It is kept in its own map and is NOT added to the general failure text that appears in run reasons and logs, which still carries no ordinary stack frame. Tests the run did not write show no message and so no place. No AI Runtime change.
156
+
153
157
  **9.3.0-rc.19 — when no old test broke, the test answer says so (test-expectations plan, Part 0).** Checking 11 runs of one pagination bug, every give-up was a test the AI had written itself with a wrong expectation (which item is first, in what order) over code that was already right; where its test data had no explicit date the code stamped the current time, records tied within a millisecond and the order of tied records depended on the clock. The `run_tests` answer for a failed run now carries one more fixed sentence when `regressions` is 0, `newFailures` is above 0 and a baseline was compared with: no test that passed before the change fails now, and the failures counted in `newFailures` are tests that were not in the test run before it. It names no test and quotes no text, changes no key of the answer, and the log line `codegen.run_tests` gains `ownOnly` (a flag). What to do with it is said in the AI Runtime's prompt, which is deployed FIRST (its loop-2 text moved); without that prompt the sentence is only a fact. **Also in rc.19 - a fix may correct a test written in this run, but not empty it (test-expectations plan, Part 4).** The AI Runtime's fix instruction (§24.12f) now lets a fix correct a test the run itself wrote when no test that passed before fails. Wording cannot stop a model from making a test pass by emptying it, so during a fix attempt an edit that removes a test written in this run, renames it away from its `[QP-...]` token, skips it (`it.skip`, `xit`, `it.todo`) or leaves it with fewer `expect`/`assert` checks is refused with the ordinary `protected` answer and the closed reason `test_removed` or `test_emptied`; the AI edits again. Tests that existed before the run stay locked exactly as before, and a first attempt or a clean retry is not touched. JavaScript test files only (like the existing-test rule; TypeScript is QUIKTR-1547); a file it cannot read is never refused. When a fix was made and the change then passed every check, the run also reports which tests written in this run the fix changed, as paths and line numbers only (`testsCorrected`), so the run page and the pull request can say so; `QUIKPILOT_TESTS_CORRECTED=off` stops that report. The rail cannot judge whether a changed expectation is right; it only closes the way of passing by saying nothing. QuikProjects must be deployed first (it validates the new field); an older one ignores it. Nothing else changes, and the sentence about no old test breaking has no switch: a revert of this release restores the old sentence.
154
158
 
155
159
  **9.3.0-rc.18 — an honest "I cannot finish" no longer throws away a change that is one fix away (QUIKSPL-139).** The AI wrote the fix and its tests, ran the project's tests until its runs were used (4 failing, then 3, then 3) and answered `CANNOT_COMPLETE`; the whole change was thrown away and a second attempt started from nothing, which did worse. Had it said `DONE`, every check would have run and the fix step (QUIKTR-1527) would have continued from the same change. Now a give-up is KEPT when the change would have passed as a `DONE` (something changed, every required test case written, no file cut short or broken) and the AI's LAST test run came back with failing tests that are the change's doing. It is recorded as attempt 1 `kept`, goes through every check like any result, and when only the tests fail the existing fix continues from it (three attempts in all, so at most two fixes). Only in `loop-tests` mode with fixing on (the project's setting above 0); a fix attempt that gives up is not kept again; time-outs, network errors and every other ending behave as before. `QUIKPILOT_KEEP_ON_GIVE_UP=off` restores the clean second attempt without a new release. Nothing new goes to the AI service.
package/dist/index.js CHANGED
@@ -2314,7 +2314,7 @@ var MAX_ATTEMPT_COUNT = 1e3;
2314
2314
  var MAX_STATUS_KEYS = 20;
2315
2315
  var MAX_STATUS_KEY_CHARS = 40;
2316
2316
  var MAX_GATE_COUNT = 1e5;
2317
- var HEAL_STOPS = /* @__PURE__ */ new Set(["passed", "no_progress", "limit", "out_of_time", "off", "not_eligible", "tree_not_restored", "heal_failed", "refused"]);
2317
+ var HEAL_STOPS = /* @__PURE__ */ new Set(["passed", "no_progress", "limit", "out_of_time", "off", "not_eligible", "tree_not_restored", "heal_failed", "review_reverted", "refused"]);
2318
2318
  var STARTED_BY = /* @__PURE__ */ new Set(["retry", "heal"]);
2319
2319
  var CHECKS = /* @__PURE__ */ new Set(["passed", "tests_failed", "failed_check"]);
2320
2320
  function gateCount(n) {
@@ -12660,6 +12660,21 @@ function parseFailureLocation(body) {
12660
12660
  const shown = path.startsWith(root) ? path.slice(root.length) : path;
12661
12661
  return shown.length > MAX_FAILURE_LOCATION ? `${shown.slice(0, MAX_FAILURE_LOCATION)}\u2026` : shown;
12662
12662
  }
12663
+ var STACK_FRAME_RE = /^[ \t]*(?:❯|at)[ \t]+(?:[^\r\n]*?[ \t(])?([^\s()]+\.(?:[cm]?[jt]sx?|py|go|java|rb|rs|cs|php|kt)):(\d+)/gm;
12664
+ function parseAssertionLocation(body) {
12665
+ const text = unescapeXmlEntities(body);
12666
+ STACK_FRAME_RE.lastIndex = 0;
12667
+ let frame;
12668
+ while (frame = STACK_FRAME_RE.exec(text)) {
12669
+ const path = normalizeSlashes(frame[1]);
12670
+ if (path.split("/").includes("node_modules")) continue;
12671
+ const root = `${normalizeSlashes(process.cwd()).replace(/\/+$/, "")}/`;
12672
+ const shown = path.startsWith(root) ? path.slice(root.length) : path;
12673
+ if (shown.length > MAX_FAILURE_LOCATION) return null;
12674
+ return `${shown}:${frame[2]}`;
12675
+ }
12676
+ return null;
12677
+ }
12663
12678
  function extractFailureText(testcaseBody) {
12664
12679
  const tag = FAILURE_TAG_RE.exec(testcaseBody);
12665
12680
  if (!tag) return null;
@@ -12677,6 +12692,7 @@ function parseJUnitOutcomes(xml) {
12677
12692
  const outcomes = /* @__PURE__ */ new Map();
12678
12693
  const automationIdResults = /* @__PURE__ */ new Map();
12679
12694
  const failureText = /* @__PURE__ */ new Map();
12695
+ const failureWhere = /* @__PURE__ */ new Map();
12680
12696
  const discoveredFiles = /* @__PURE__ */ new Set();
12681
12697
  const discoveredAutomationIds = /* @__PURE__ */ new Set();
12682
12698
  let unmappedEntries = 0;
@@ -12701,6 +12717,8 @@ function parseJUnitOutcomes(xml) {
12701
12717
  if (failed) {
12702
12718
  const text = extractFailureText(body);
12703
12719
  if (text) failureText.set(id, text);
12720
+ const where = parseAssertionLocation(FAILURE_TAG_RE.exec(body)?.[2] ?? "");
12721
+ if (where) failureWhere.set(id, where);
12704
12722
  }
12705
12723
  const file = FILE_ATTR_RE.exec(attrs)?.[1];
12706
12724
  if (file) discoveredFiles.add(normalizeSlashes(file));
@@ -12714,7 +12732,7 @@ function parseJUnitOutcomes(xml) {
12714
12732
  if (!seen || RESULT_RANK[result] > RESULT_RANK[seen]) automationIdResults.set(bracket, result);
12715
12733
  }
12716
12734
  }
12717
- return { outcomes, automationIdResults, failureText, discoveredFiles, discoveredAutomationIds, unmappedEntries };
12735
+ return { outcomes, automationIdResults, failureText, failureWhere, discoveredFiles, discoveredAutomationIds, unmappedEntries };
12718
12736
  }
12719
12737
  function readJUnitOutcomes(cwd) {
12720
12738
  const report = findJUnitReport(cwd);
@@ -12735,6 +12753,7 @@ function captureTestSnapshot(command, cwd = process.cwd()) {
12735
12753
  outcome,
12736
12754
  results: parsed?.outcomes ?? null,
12737
12755
  failureText: parsed?.failureText,
12756
+ failureWhere: parsed?.failureWhere,
12738
12757
  discoveredFiles: parsed?.discoveredFiles ?? null,
12739
12758
  discoveredAutomationIds: parsed?.discoveredAutomationIds ?? null,
12740
12759
  unmappedEntries: parsed?.unmappedEntries
@@ -12746,6 +12765,7 @@ function readTestSnapshot(outcome, cwd = process.cwd()) {
12746
12765
  outcome,
12747
12766
  results: parsed?.outcomes ?? null,
12748
12767
  failureText: parsed?.failureText,
12768
+ failureWhere: parsed?.failureWhere,
12749
12769
  discoveredFiles: parsed?.discoveredFiles ?? null,
12750
12770
  discoveredAutomationIds: parsed?.discoveredAutomationIds ?? null,
12751
12771
  unmappedEntries: parsed?.unmappedEntries
@@ -12758,6 +12778,7 @@ async function captureBaselineSnapshot(command, cwd = process.cwd()) {
12758
12778
  outcome,
12759
12779
  results: parsed?.outcomes ?? null,
12760
12780
  failureText: parsed?.failureText,
12781
+ failureWhere: parsed?.failureWhere,
12761
12782
  discoveredFiles: parsed?.discoveredFiles ?? null,
12762
12783
  discoveredAutomationIds: parsed?.discoveredAutomationIds ?? null,
12763
12784
  unmappedEntries: parsed?.unmappedEntries
@@ -12771,6 +12792,7 @@ function checkForRegressions(baseline, after) {
12771
12792
  const newFailures = [];
12772
12793
  const preExisting = [];
12773
12794
  const failureText = /* @__PURE__ */ new Map();
12795
+ const failureWhere = /* @__PURE__ */ new Map();
12774
12796
  const afterFailureText = after.failureText;
12775
12797
  for (const [testId, passed] of after.results) {
12776
12798
  if (passed) continue;
@@ -12779,15 +12801,19 @@ function checkForRegressions(baseline, after) {
12779
12801
  regressions.push(testId);
12780
12802
  const text = afterFailureText?.get(testId);
12781
12803
  if (text) failureText.set(testId, text);
12804
+ const where = after.failureWhere?.get(testId);
12805
+ if (where) failureWhere.set(testId, where);
12782
12806
  } else if (before === false) {
12783
12807
  preExisting.push(testId);
12784
12808
  } else {
12785
12809
  newFailures.push(testId);
12786
12810
  const text = afterFailureText?.get(testId);
12787
12811
  if (text) failureText.set(testId, text);
12812
+ const where = after.failureWhere?.get(testId);
12813
+ if (where) failureWhere.set(testId, where);
12788
12814
  }
12789
12815
  }
12790
- return { blocked: regressions.length > 0 || newFailures.length > 0, regressions, newFailures, preExisting, failureText };
12816
+ return { blocked: regressions.length > 0 || newFailures.length > 0, regressions, newFailures, preExisting, failureText, failureWhere };
12791
12817
  }
12792
12818
  function describeRegressions(check) {
12793
12819
  const withText = (id) => {
@@ -12841,11 +12867,15 @@ var MESSAGES = {
12841
12867
  };
12842
12868
  var TESTS_FAILED_NO_OLD_TEST_BROKE = "Some tests failed. No test that passed before your change fails now: the failures counted in newFailures are tests that were not in the test run before your change. For a test you wrote in this run, messages gives the first line of why it failed.";
12843
12869
  var sha = (s) => (0, import_node_crypto2.createHash)("sha256").update(s).digest("hex");
12844
- function firstLine(text) {
12870
+ var LOCATION_SUFFIX = / \[at [^\]\r\n]{1,70}\]$/;
12871
+ function firstLine(text, where) {
12845
12872
  const line = text.split(LINE_BREAK).map((l) => l.replace(CONTROL_CHARS, "").trim()).find((l) => l.length > 0);
12846
12873
  if (line === void 0) return "";
12847
- const safe = scrubSecrets(line);
12848
- return safe.length > MAX_MESSAGE_CHARS ? `${safe.slice(0, MAX_MESSAGE_CHARS - 1)}\u2026` : safe;
12874
+ const safe = scrubSecrets(where ? `${line} [at ${where}]` : line);
12875
+ if (safe.length <= MAX_MESSAGE_CHARS) return safe;
12876
+ const kept = LOCATION_SUFFIX.exec(safe);
12877
+ if (kept) return `${safe.slice(0, kept.index).slice(0, MAX_MESSAGE_CHARS - kept[0].length - 1)}\u2026${kept[0]}`;
12878
+ return `${safe.slice(0, MAX_MESSAGE_CHARS - 1)}\u2026`;
12849
12879
  }
12850
12880
  var normalisePath = (p) => p.replace(/\\/g, "/").replace(/^(\.\/)+/, "");
12851
12881
  function samePlace(a, b) {
@@ -12889,6 +12919,7 @@ function testAnswerFrom(args) {
12889
12919
  let alreadyFailing;
12890
12920
  let own = /* @__PURE__ */ new Set();
12891
12921
  let failureText = /* @__PURE__ */ new Map();
12922
+ let failureWhere = /* @__PURE__ */ new Map();
12892
12923
  if (args.baseline?.results) {
12893
12924
  const check = checkForRegressions(args.baseline, after);
12894
12925
  regressions = check.regressions;
@@ -12896,6 +12927,7 @@ function testAnswerFrom(args) {
12896
12927
  alreadyFailing = check.preExisting;
12897
12928
  own = ownFailureIds(newFailures, [...args.changedPaths], args.requiredIds);
12898
12929
  failureText = check.failureText;
12930
+ failureWhere = check.failureWhere ?? /* @__PURE__ */ new Map();
12899
12931
  } else {
12900
12932
  regressions = [];
12901
12933
  newFailures = [...after.results.entries()].filter(([, ok]) => !ok).map(([id]) => id);
@@ -12907,7 +12939,7 @@ function testAnswerFrom(args) {
12907
12939
  const messages = {};
12908
12940
  listed.forEach((id, i2) => {
12909
12941
  if (!own.has(id)) return;
12910
- const line = firstLine(failureText.get(id) ?? "");
12942
+ const line = firstLine(failureText.get(id) ?? "", failureWhere.get(id));
12911
12943
  if (line) messages[names[i2]] = line;
12912
12944
  });
12913
12945
  const messageCount = Object.keys(messages).length;
@@ -13992,6 +14024,29 @@ function healPreviousAttempt(attempt2, answer) {
13992
14024
  ...lastTestRun ? { lastTestRun } : {}
13993
14025
  };
13994
14026
  }
14027
+ var REVIEW_DETAIL_MAX = 300;
14028
+ function reviewDetailFrom(blocks) {
14029
+ const parts = blocks.map((b) => {
14030
+ const file = b.file.replace(/[\r\n\t]+/g, " ").slice(0, 120);
14031
+ return b.endLine > b.startLine ? `${file}, lines ${b.startLine} to ${b.endLine}` : `${file}, line ${b.startLine}`;
14032
+ });
14033
+ if (parts.join("; ").length <= REVIEW_DETAIL_MAX) return parts.join("; ");
14034
+ for (let n = parts.length - 1; n > 0; n--) {
14035
+ const text = `${parts.slice(0, n).join("; ")}; and ${parts.length - n} more`;
14036
+ if (text.length <= REVIEW_DETAIL_MAX) return text;
14037
+ }
14038
+ return `${parts.length} blocks`;
14039
+ }
14040
+ function healReviewPreviousAttempt(attempt2, blocks, answer) {
14041
+ const lastTestRun = testRunFrom(answer);
14042
+ return {
14043
+ attempt: attempt2,
14044
+ endedWith: "unneeded_changes",
14045
+ changesKept: true,
14046
+ ...lastTestRun ? { lastTestRun } : {},
14047
+ detail: reviewDetailFrom(blocks)
14048
+ };
14049
+ }
13995
14050
 
13996
14051
  // src/codegenHeal.ts
13997
14052
  async function runHealAttempt(i2) {
@@ -14014,7 +14069,7 @@ async function runHealAttempt(i2) {
14014
14069
  const done = await runCodegenLoop(
14015
14070
  // `keepOnGiveUp` is off on purpose, whatever the step says: only a first attempt keeps a give-up. A fix that gives up ends as `heal_failed`
14016
14071
  // with the earlier failure, so a hopeless change cannot be carried from fix to fix.
14017
- { ...args, keepOnGiveUp: false, seed: i2.results, previousAttempt: healPreviousAttempt(i2.attempt, i2.answer) },
14072
+ { ...args, keepOnGiveUp: false, seed: i2.results, previousAttempt: i2.review ? healReviewPreviousAttempt(i2.attempt, i2.review.blocks, i2.answer) : healPreviousAttempt(i2.attempt, i2.answer) },
14018
14073
  {
14019
14074
  post: (contextData, signal) => postCodegenTurn(p.gateway, contextData, signal),
14020
14075
  ...p.deps,
@@ -14034,6 +14089,11 @@ async function runHealAttempt(i2) {
14034
14089
  }
14035
14090
 
14036
14091
  // src/healLoop.ts
14092
+ var REVIEW_MIN_BUDGET_MS = 3 * 6e4;
14093
+ function greenAnswer(testCount) {
14094
+ const n = Number.isInteger(testCount) && testCount >= 0 ? testCount : 0;
14095
+ return { passed: n, failed: 0, total: n, regressions: 0, newFailures: 0, alreadyFailing: 0, failingTests: [], timedOut: false, truncated: false };
14096
+ }
14037
14097
  function countsOf(answer) {
14038
14098
  return {
14039
14099
  passed: answer.passed,
@@ -14049,6 +14109,7 @@ async function runVerifyAndFix(p) {
14049
14109
  let healsRun = 0;
14050
14110
  let lastFailingKey = null;
14051
14111
  let lastAttemptMs = p.lastAttemptMs;
14112
+ let lastReview;
14052
14113
  const attempts = [];
14053
14114
  const allowed = healAllowance(p.setting, attemptsRun, 0, p.mode);
14054
14115
  let startedFrom;
@@ -14060,6 +14121,76 @@ async function runVerifyAndFix(p) {
14060
14121
  ...startedFrom ? { startedFrom } : {},
14061
14122
  ...extra
14062
14123
  });
14124
+ const reviewFix = async (verdict, v) => {
14125
+ const before = results;
14126
+ try {
14127
+ v.undo();
14128
+ } catch (err) {
14129
+ if (err instanceof TreeNotRestoredError || err instanceof TreeUnverifiableError) p.onStop?.("tree_not_restored");
14130
+ throw err;
14131
+ }
14132
+ healsRun += 1;
14133
+ attemptsRun += 1;
14134
+ const first = healsRun === 1 ? { trigger: "unneeded_changes" } : {};
14135
+ p.log({ event: "heal.start", attempt: attemptsRun, healsRun, trigger: "unneeded_changes", blocks: verdict.blocks.length });
14136
+ const startedAt = p.now();
14137
+ let fixed = null;
14138
+ let failureReason;
14139
+ try {
14140
+ fixed = await p.heal({
14141
+ results: before,
14142
+ answer: greenAnswer(verdict.testCount),
14143
+ attempt: attemptsRun - 1,
14144
+ hardStopAtMs: p.jobStopAtMs - v.gateMs,
14145
+ review: { blocks: verdict.blocks, testCount: verdict.testCount }
14146
+ });
14147
+ } catch (err) {
14148
+ if (err instanceof SafetyRefusalError) {
14149
+ p.onStop?.("refused");
14150
+ throw err;
14151
+ }
14152
+ if (err instanceof TreeNotRestoredError || err instanceof TreeUnverifiableError) {
14153
+ p.onStop?.("tree_not_restored");
14154
+ throw err;
14155
+ }
14156
+ if (err instanceof CodegenLoopFailure) {
14157
+ p.log({ event: "heal.failed", attempt: attemptsRun, reason: err.reason, trigger: "unneeded_changes" });
14158
+ failureReason = err.reason;
14159
+ } else if (err instanceof SeedRefused) {
14160
+ p.log({ event: "heal.failed", attempt: attemptsRun, reason: "seed_refused", trigger: "unneeded_changes" });
14161
+ failureReason = "seed_refused";
14162
+ } else {
14163
+ p.log({ event: "heal.failed", attempt: attemptsRun, reason: "internal_error", trigger: "unneeded_changes" });
14164
+ failureReason = "internal_error";
14165
+ }
14166
+ }
14167
+ lastAttemptMs = p.now() - startedAt;
14168
+ const review = lastReview ? { review: lastReview } : {};
14169
+ if (fixed) {
14170
+ const v2 = await p.verify(fixed, true);
14171
+ attempts.push({
14172
+ n: attemptsRun,
14173
+ startedBy: "heal",
14174
+ checks: v2.ok ? "passed" : v2.stage === "gate" ? "tests_failed" : "failed_check",
14175
+ ...!v2.ok && v2.answer ? { gate: countsOf(v2.answer) } : {}
14176
+ });
14177
+ if (v2.ok) return { outcome: v2, results: fixed, heal: record("passed", first), ...review };
14178
+ try {
14179
+ v2.undo();
14180
+ } catch (err) {
14181
+ if (err instanceof TreeNotRestoredError || err instanceof TreeUnverifiableError) p.onStop?.("tree_not_restored");
14182
+ throw err;
14183
+ }
14184
+ p.log({ event: "heal.review_reverted", attempt: attemptsRun });
14185
+ }
14186
+ const back = await p.verify(before, false);
14187
+ return {
14188
+ outcome: back,
14189
+ results: before,
14190
+ heal: fixed ? record("review_reverted", first) : record("heal_failed", { ...first, ...failureReason ? { failureReason } : {} }),
14191
+ ...review
14192
+ };
14193
+ };
14063
14194
  for (; ; ) {
14064
14195
  const undoable = healAllowance(p.setting, attemptsRun, healsRun, p.mode) > 0;
14065
14196
  const v = await p.verify(results, undoable);
@@ -14071,7 +14202,26 @@ async function runVerifyAndFix(p) {
14071
14202
  ...!v.ok && v.answer ? { gate: countsOf(v.answer) } : {}
14072
14203
  });
14073
14204
  }
14074
- if (v.ok) return { outcome: v, results, ...healsRun > 0 ? { heal: record("passed") } : {} };
14205
+ if (v.ok) {
14206
+ const canReview = p.review !== void 0 && healAllowance(p.setting, attemptsRun, healsRun, p.mode) > 0 && p.jobStopAtMs - p.now() >= healNeededMs({ attemptMs: lastAttemptMs, gateMs: v.gateMs }) + REVIEW_MIN_BUDGET_MS;
14207
+ if (canReview && p.review) {
14208
+ let verdict = null;
14209
+ try {
14210
+ verdict = await p.review(results, v);
14211
+ } catch (err) {
14212
+ if (err instanceof TreeNotRestoredError || err instanceof TreeUnverifiableError) {
14213
+ p.onStop?.("tree_not_restored");
14214
+ throw err;
14215
+ }
14216
+ verdict = null;
14217
+ }
14218
+ if (verdict) lastReview = { results, raw: verdict.raw };
14219
+ if (verdict && verdict.blocks.length > 0) {
14220
+ return await reviewFix(verdict, v);
14221
+ }
14222
+ }
14223
+ return { outcome: v, results, ...healsRun > 0 ? { heal: record("passed") } : {}, ...lastReview ? { review: lastReview } : {} };
14224
+ }
14075
14225
  const decision = decideHeal({
14076
14226
  mode: p.mode,
14077
14227
  setting: p.setting,
@@ -14456,7 +14606,7 @@ function mergeHealRecord(existing, heal, calls) {
14456
14606
  const attempts = before.map((a) => ({ ...a }));
14457
14607
  if (heal.made > 0 && attempts.length > 0) {
14458
14608
  const finalOne = attempts[attempts.length - 1];
14459
- finalOne.checks = "tests_failed";
14609
+ finalOne.checks = heal.trigger === "unneeded_changes" ? "passed" : "tests_failed";
14460
14610
  if (heal.startedFrom) finalOne.gate = heal.startedFrom;
14461
14611
  }
14462
14612
  calls.forEach((call, i2) => {
@@ -14483,7 +14633,8 @@ var STOP_WORDS = {
14483
14633
  no_progress: "the same tests kept failing in the same way",
14484
14634
  limit: "the limit of fix attempts was reached",
14485
14635
  out_of_time: "there was not enough time left for another attempt",
14486
- heal_failed: "the fix attempt could not finish"
14636
+ heal_failed: "the fix attempt could not finish",
14637
+ review_reverted: "the change made after the review no longer passed, so the earlier one was kept"
14487
14638
  };
14488
14639
  function healFailureSuffix(heal) {
14489
14640
  if (!heal || heal.made <= 0) return "";
@@ -15316,7 +15467,7 @@ var FAILURE_ARTIFACT_DIR = "quikpilot-failure";
15316
15467
  var REPORT_COPY = "final-test-report.xml";
15317
15468
  var MAX_REPORT_BYTES = 5 * 1024 * 1024;
15318
15469
  var MAX_FILES = 200;
15319
- var RUNNER_VERSION = true ? "9.3.0-rc.19" : "dev";
15470
+ var RUNNER_VERSION = true ? "9.3.0-rc.20" : "dev";
15320
15471
  function safeDestination(base, repoPath) {
15321
15472
  if (!repoPath || (0, import_node_path14.isAbsolute)(repoPath)) return null;
15322
15473
  const destination = (0, import_node_path14.resolve)(base, repoPath);
@@ -16007,6 +16158,25 @@ async function run(env2) {
16007
16158
  const jobStopAtMs = runStartedAt + packet.guardrails.maxWallClockMinutes * 6e4 - JOB_RESERVE_MS;
16008
16159
  const healCalls = [];
16009
16160
  let healStop;
16161
+ const testCommand = packet.commands.test;
16162
+ const hunkCheckOver = async (changed, testCount) => {
16163
+ if (codegenMode !== "loop-tests" || process.env.QUIKPILOT_HUNK_CHECK?.trim().toLowerCase() === "off") return null;
16164
+ const deadlineAtMs = Math.min(jobStopAtMs - HUNK_CHECK_END_BEFORE_STOP_MS, Date.now() + HUNK_CHECK_MAX_MS);
16165
+ if (deadlineAtMs - Date.now() < HUNK_CHECK_MIN_BUDGET_MS) return null;
16166
+ const files = collectHunkCheckFiles(changed, process.cwd());
16167
+ if (files.length === 0) return null;
16168
+ return runHunkCheck({
16169
+ root: process.cwd(),
16170
+ command: testCommand,
16171
+ baseline,
16172
+ baselineMs: timedBaseline.durationMs,
16173
+ finalTestCount: testCount,
16174
+ files,
16175
+ deadlineAtMs,
16176
+ log: (e) => console.log(JSON.stringify(e))
16177
+ });
16178
+ };
16179
+ const reviewOn = process.env.QUIKPILOT_REVIEW_FIX?.trim().toLowerCase() !== "off";
16010
16180
  let fixed;
16011
16181
  try {
16012
16182
  fixed = await runVerifyAndFix({
@@ -16018,10 +16188,19 @@ async function run(env2) {
16018
16188
  jobStopAtMs,
16019
16189
  lastAttemptMs,
16020
16190
  verify: (r, undoable) => verifyChange(verifyCtx, r, undoable),
16021
- heal: async ({ results: kept, answer, attempt: attempt2, hardStopAtMs }) => {
16191
+ ...reviewOn ? {
16192
+ review: async (changed, outcome) => {
16193
+ const testCount = outcome.outputs.testCount ?? 0;
16194
+ const checked = await hunkCheckOver(changed, testCount);
16195
+ if (!checked) return null;
16196
+ console.log(JSON.stringify({ event: "hunk_check", phase: "review", checked: checked.checked, total: checked.total, flagged: checked.unnecessary.length, skipped: checked.skipped, stopped: checked.stopped ?? null }));
16197
+ return { blocks: checked.unnecessary, testCount, raw: checked };
16198
+ }
16199
+ } : {},
16200
+ heal: async ({ results: kept, answer, attempt: attempt2, hardStopAtMs, review }) => {
16022
16201
  const out = {};
16023
16202
  try {
16024
- return await runHealAttempt({ step: stepParams, results: kept, answer, attempt: attempt2, hardStopAtMs, out });
16203
+ return await runHealAttempt({ step: stepParams, results: kept, answer, attempt: attempt2, hardStopAtMs, out, ...review ? { review: { blocks: review.blocks } } : {} });
16025
16204
  } finally {
16026
16205
  healCalls.push({ ...out.summary ? { summary: out.summary } : {}, ...out.failure ? { failureReason: out.failure.reason } : {} });
16027
16206
  }
@@ -16057,35 +16236,23 @@ async function run(env2) {
16057
16236
  }
16058
16237
  }
16059
16238
  if (codegenMode === "loop-tests" && process.env.QUIKPILOT_HUNK_CHECK?.trim().toLowerCase() !== "off") {
16060
- const deadlineAtMs = Math.min(jobStopAtMs - HUNK_CHECK_END_BEFORE_STOP_MS, Date.now() + HUNK_CHECK_MAX_MS);
16061
- if (deadlineAtMs - Date.now() >= HUNK_CHECK_MIN_BUDGET_MS) {
16062
- try {
16063
- const files = collectHunkCheckFiles(fixed.results, process.cwd());
16064
- if (files.length > 0) {
16065
- const checked = await runHunkCheck({
16066
- root: process.cwd(),
16067
- command: packet.commands.test,
16068
- baseline,
16069
- baselineMs: timedBaseline.durationMs,
16070
- finalTestCount: final.outputs.testCount ?? 0,
16071
- files,
16072
- deadlineAtMs,
16073
- log: (e) => console.log(JSON.stringify(e))
16074
- });
16075
- console.log(JSON.stringify({ event: "hunk_check", checked: checked.checked, total: checked.total, flagged: checked.unnecessary.length, skipped: checked.skipped, stopped: checked.stopped ?? null }));
16076
- changesNoTestDependsOn = toFinding(checked);
16077
- if (checked.unnecessary.length > 0) {
16078
- const w = describeHunkCheck(checked);
16079
- warnings.push(w);
16080
- console.warn(`QuikPilot change warning (not blocking): ${w}`);
16081
- }
16239
+ try {
16240
+ const reused = fixed.review && fixed.review.results === fixed.results ? fixed.review.raw : void 0;
16241
+ const checked = reused ?? await hunkCheckOver(fixed.results, final.outputs.testCount ?? 0);
16242
+ if (checked) {
16243
+ if (!reused) console.log(JSON.stringify({ event: "hunk_check", checked: checked.checked, total: checked.total, flagged: checked.unnecessary.length, skipped: checked.skipped, stopped: checked.stopped ?? null }));
16244
+ changesNoTestDependsOn = toFinding(checked);
16245
+ if (checked.unnecessary.length > 0) {
16246
+ const w = describeHunkCheck(checked);
16247
+ warnings.push(w);
16248
+ console.warn(`QuikPilot change warning (not blocking): ${w}`);
16082
16249
  }
16083
- } catch (err) {
16084
- if (err instanceof TreeNotRestoredError) throw err;
16085
- const message = `The check for changes no test depends on could not run: ${err instanceof Error ? err.message : String(err)}`;
16086
- console.error(message);
16087
- warnings.push(message);
16088
16250
  }
16251
+ } catch (err) {
16252
+ if (err instanceof TreeNotRestoredError) throw err;
16253
+ const message = `The check for changes no test depends on could not run: ${err instanceof Error ? err.message : String(err)}`;
16254
+ console.error(message);
16255
+ warnings.push(message);
16089
16256
  }
16090
16257
  }
16091
16258
  }