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

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,8 +164,12 @@ 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.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
+
167
169
  **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).
168
170
 
171
+ **9.3.0-rc.55 - a cut-off answer or a slow turn continues in a smaller step instead of ending the attempt (QUIKTR-1853).** Until now one turn that the AI Runtime cut off for length (`output_too_large`) or that ran past the turn limit (`turn_timeout`) threw the whole code-writing attempt away, and with two attempts per job two such turns ended a job with nothing written, though the AI was making progress (QTRIA-21: one slow turn, then one cut-off answer while writing tests, nothing written, $1.70). Nothing the attempt holds changes with a lost turn (the overlay, the transcript and the counters change only after a reply comes back as an answer), so the runner now asks again, once: the AI's transcript gets one fixed sentence of the runner's own - "your last answer was too long and was cut off / your last step took too long, so none of it was run. Take a smaller step: fewer files and fewer edits in one turn, and make each edit a small find-and-replace change" - as a refused turn with the shared rule word `length`, which every AI Runtime version already accepts, so nothing is deployed on the AI Runtime (`turnRecovery.ts`). It is never counted as a refusal or as a turn that changed nothing, so it cannot force `refused_repeatedly` or `no_progress`; it uses a turn and the attempt deadline and the step clock still bound it. It never happens twice in a row: a second lost turn straight after the first, and any lost turn on the final turn, end the attempt as before, and the failure message then says "a second time in a row, even after the AI was asked to take a smaller step". The run log gets `codegen.loop_recovered` (turn, reason, the service's code) and `afterRecovery` on `codegen.attempt_end`; the recovered turn appears in the record as a refused turn with the rule `length`. The AI Runtime's own log `output.measured` names the model that was cut off. `QUIKPILOT_TURN_RECOVERY=off` returns to ending the attempt. Also in rc.55: everything in rc.54.
172
+
169
173
  **9.3.0-rc.54 - eight languages share one tree-sitter base: a syntax check and "never weaken an existing test" by structure (QUIKTR-1701, release 1).** Until now the runner's safety checks read code with a JavaScript parser and switched off for any other language: nothing noticed a broken Go or Ruby file, and an existing test in another language was protected only by the text rule, which lets any text be added in front of or behind the matched part (`t.Skip()`, an early `return`, `@pytest.mark.skip`, `@Disabled`, a shadowing `test_a = lambda: None` all passed). Now `languages.ts` is the one table of the languages read with tree-sitter - Python, Go, Java, Kotlin, C#, Rust, Ruby and PHP (JavaScript and TypeScript keep acorn and sucrase and every check they have). (1) Syntax: after each edit the code-writing loop tells the AI "the file no longer parses (a syntax error at line N)" when a file that parsed does not, and at hand-over a file that parsed before and does not now stops the run, exactly as for JavaScript; a file that was already broken, or a language whose grammar is not loaded, is never judged. (2) Existing tests (`existingTestsLang.ts`): every unit of the test file as it was before the run (a function, a class, an import, a statement - with its decorators, annotations and modifiers) must still be there, byte for byte and in order; a class, module, `impl` or RSpec `describe` is compared by what is around its body and then by its own units; an import may only gain names or a whole new import may be added; comments between units are free; a NEW unit may only declare something whose name no unit of that level has, and may not be a hook that runs around every test (`setUp`, `TestMain`, `init`, `@BeforeEach`, `[SetUp]`, a constructor, an RSpec `before`/`let`, a fixture, a static or `init` block, an inner attribute), a build constraint, a statement that declares nothing (`pytest.skip(...)` at module level), or a Rust attribute in front of an old item. The reasons are the same closed words as for JavaScript (`changed_text`, `removed_text`, `moved_block`, `affects_existing`). A file that does not parse falls back to the text rule. Size: the five new grammars are vendored brotli-compressed and embedded the same way (each decoded on first use, 2-25 ms), and the published source map no longer copies the source text, so the package is about 1.4 MB (rc.53: about 1.9 MB). `QUIKPILOT_LANG_CHECKS=js` turns both checks back to the old behaviour. Also in rc.54: everything in rc.53.
170
174
 
171
175
  **9.3.0-rc.53 - a Python, Go or Java test that pins the bug can be reported to a person (QUIKTR-1855, release 2).** Until now the stop "an existing test expects what an approved case calls wrong - may I change it?" worked only for JavaScript and TypeScript tests: the test was found, and an edit of it judged, by a JavaScript parser, so a Go, Python or Java test ended the run with `test_unsupported_language`. Now `testLocateLang.ts` finds the tests of those languages with tree-sitter (a Python `def test_*` with its decorators, a Go `func TestX` whose subtests are its rows, a Java `@Test`/`@ParameterizedTest` method with its annotations) and judges an edit by its SHAPE: the test's tokens with every literal value (text, number, true/false/None/nil/null), assertion statements (`assert ...`, `self.assertEqual`, `assert.Equal`, `assertEquals`, `assertThat(...)...`), comments and the test's own name taken out must be the same before and after - so the values of a `parametrize` list, a Go table or a `@CsvSource` may change, and the call the test makes, its loops and its set-up may not. Data a test reads from elsewhere in the file (a module-level list, a `@MethodSource`) is outside the test and an edit there is refused as outside it. The tests are found by the function's name (a Java `@DisplayName` is the title when there is one); a reply that does not find the title lists the file's test names. A later job (the approval) reads the file the same way. The tree-sitter runtime and the three grammars (`vendor/tree-sitter/`, MIT, about 1.3 MB) are embedded in the bundle as base64 and decoded only when the first Python, Go or Java test file is read, so a JavaScript run pays nothing; the package grows from about 330 KB to about 700 KB gzipped and stays one file with no dependencies. A file that does not parse cleanly, and any other language (Kotlin, C#, Ruby, PHP), is still `test_unsupported_language`. `QUIKPILOT_TEST_LOCATE=js` turns the new readers off. Also in rc.53: everything in rc.52.
package/dist/index.js CHANGED
@@ -41893,12 +41893,13 @@ function failedAttemptRecord(n, failure) {
41893
41893
  outcome: "failed",
41894
41894
  reason: failure.reason,
41895
41895
  ...failure.runtimeCode ? { runtimeCode: runtimeCodeWord(failure.runtimeCode) } : {},
41896
+ ...failure.afterRecovery ? { afterRecovery: true } : {},
41896
41897
  turns: failure.summary?.turns ?? 0,
41897
41898
  toolCalls: failure.summary?.toolCalls ?? 0
41898
41899
  };
41899
41900
  }
41900
41901
  function attemptInWords(a, fallback) {
41901
- const words = reasonInWords(a?.reason ?? fallback);
41902
+ const words = a?.afterRecovery ? `${reasonInWords(a?.reason ?? fallback)}, a second time in a row, even after the AI was asked to take a smaller step` : reasonInWords(a?.reason ?? fallback);
41902
41903
  return a?.runtimeCode && a.runtimeCode !== "other" ? `${words} (error code ${a.runtimeCode})` : words;
41903
41904
  }
41904
41905
  function exhaustedMessage(attempts, stop2, unreportable) {
@@ -46281,6 +46282,35 @@ function missingImportSentence(m) {
46281
46282
  return `${first.path} imports ${first.name} from ${first.from}, which does not export it${more}: export it there, or change the import.`.slice(0, 300);
46282
46283
  }
46283
46284
 
46285
+ // src/turnRecovery.ts
46286
+ var RECOVERY_RULE = "length";
46287
+ var COMMON = "Take a smaller step: fewer files and fewer edits in one turn, and make each edit a small find-and-replace change.";
46288
+ var SENTENCES = {
46289
+ cut_off: {
46290
+ violation: "Your last answer was cut off because it was too long, so none of it was run.",
46291
+ message: `Your last answer was too long and was cut off, so none of it was run. ${COMMON}`
46292
+ },
46293
+ slow: {
46294
+ violation: "Your last step took too long, so none of it was run.",
46295
+ message: `Your last step took too long, so none of it was run. ${COMMON}`
46296
+ }
46297
+ };
46298
+ function turnRecoveryOff(env2 = process.env) {
46299
+ return env2.QUIKPILOT_TURN_RECOVERY === "off";
46300
+ }
46301
+ function shouldRecover(input) {
46302
+ return !(input.off ?? turnRecoveryOff()) && !input.isFinal && input.consecutive < 1;
46303
+ }
46304
+ function recoveryAnswer(kind) {
46305
+ const s = SENTENCES[kind];
46306
+ return { rules: [RECOVERY_RULE], violations: [s.violation], message: s.message };
46307
+ }
46308
+ function repeatedLossDetail(kind, first) {
46309
+ const now = kind === "cut_off" ? "cut off" : "too slow";
46310
+ const before = first === "cut_off" ? "cut off" : "too slow";
46311
+ return `a turn was ${before}, and the next one, after the AI was asked for a smaller step, was ${now} too`;
46312
+ }
46313
+
46284
46314
  // src/targetingErrors.ts
46285
46315
  var DeniedPathError = class extends Error {
46286
46316
  constructor(message) {
@@ -46650,6 +46680,8 @@ var CodegenLoopFailure = class extends Error {
46650
46680
  summary;
46651
46681
  /** QUIKTR-1823 (`test_conflict_unreportable` only): where each such test is and which case it contradicts. Never a title. */
46652
46682
  unreportable;
46683
+ /** QUIKTR-1853: a turn was lost straight after one that had been recovered (see `turnRecovery.ts`). */
46684
+ afterRecovery;
46653
46685
  constructor(reason, runtimeCode, cause, detail, told) {
46654
46686
  super(`pilot.codegen loop failed: ${reason}${runtimeCode ? ` (${runtimeCode})` : ""}`);
46655
46687
  this.name = "CodegenLoopFailure";
@@ -46866,6 +46898,8 @@ async function runCodegenLoop(args2, deps) {
46866
46898
  let turns = 0;
46867
46899
  let noProgressStreak = 0;
46868
46900
  let forced = null;
46901
+ let lostLast = null;
46902
+ let lostStreak = 0;
46869
46903
  const started = now();
46870
46904
  let toCheckList = null;
46871
46905
  const toCheck = () => toCheckList ??= (args2.testsToCheck?.() ?? []).slice(0, 10);
@@ -47008,6 +47042,22 @@ async function runCodegenLoop(args2, deps) {
47008
47042
  return null;
47009
47043
  };
47010
47044
  log({ event: "codegen.loop_start", maxTurns: limits.maxTurns, maxToolCalls: limits.maxToolCalls, listingFiles: args2.listing.length });
47045
+ const loseTurn = (turn, kind, isFinalTurn, runtimeCode, elapsedMs) => {
47046
+ const reason = kind === "cut_off" ? "output_too_large" : "turn_timeout";
47047
+ if (!shouldRecover({ isFinal: isFinalTurn, consecutive: lostStreak })) {
47048
+ const again = lostLast !== null && lostStreak > 0;
47049
+ const failure = new CodegenLoopFailure(reason, runtimeCode, void 0, again ? repeatedLossDetail(kind, lostLast) : void 0);
47050
+ if (again) failure.afterRecovery = true;
47051
+ return failure;
47052
+ }
47053
+ lostStreak += 1;
47054
+ lostLast = kind;
47055
+ refusedTurns.push({ turn, rules: [RECOVERY_RULE] });
47056
+ transcript.push({ turn, toolCalls: [], refused: recoveryAnswer(kind) });
47057
+ log({ event: "codegen.loop_recovered", turn, reason, ...runtimeCode ? { runtimeCode } : {}, elapsedMs });
47058
+ forced = settleNextTurn(turn, forced);
47059
+ return true;
47060
+ };
47011
47061
  try {
47012
47062
  for (let turn = 1; turn <= limits.maxTurns; turn++) {
47013
47063
  turns = turn;
@@ -47029,7 +47079,13 @@ async function runCodegenLoop(args2, deps) {
47029
47079
  try {
47030
47080
  envelope = await deps.post(contextData, AbortSignal.timeout(turnTimeoutFor(turn, turnTimeoutMs, deps.turnTimeoutMs !== void 0)));
47031
47081
  } catch (err2) {
47032
- throw classifyTransport2(err2);
47082
+ const lost = classifyTransport2(err2);
47083
+ if (lost.reason === "turn_timeout") {
47084
+ const handled = loseTurn(turn, "slow", isFinal, void 0, now() - turnStarted);
47085
+ if (handled === true) continue;
47086
+ throw handled;
47087
+ }
47088
+ throw lost;
47033
47089
  }
47034
47090
  usage.record(turn, contextData, requestTokens, envelope, now() - turnStarted);
47035
47091
  const code = envelope?.errorCode;
@@ -47050,7 +47106,12 @@ async function runCodegenLoop(args2, deps) {
47050
47106
  const fallbackText = `pilot.codegen failed: ${runtimeCode}`;
47051
47107
  throw new SafetyRefusalError(inner?.message ?? fallbackText, inner?.summary ?? fallbackText);
47052
47108
  }
47053
- throw new CodegenLoopFailure(runtimeCode && OUTPUT_TOO_LARGE_CODES.has(runtimeCode) ? "output_too_large" : "runtime_failed", runtimeCode);
47109
+ if (runtimeCode && OUTPUT_TOO_LARGE_CODES.has(runtimeCode)) {
47110
+ const handled = loseTurn(turn, "cut_off", isFinal, runtimeCode, now() - turnStarted);
47111
+ if (handled === true) continue;
47112
+ throw handled;
47113
+ }
47114
+ throw new CodegenLoopFailure("runtime_failed", runtimeCode);
47054
47115
  }
47055
47116
  let body2;
47056
47117
  try {
@@ -47058,6 +47119,7 @@ async function runCodegenLoop(args2, deps) {
47058
47119
  } catch (err2) {
47059
47120
  throw new CodegenLoopFailure("bad_reply", void 0, err2);
47060
47121
  }
47122
+ lostStreak = 0;
47061
47123
  const reasonText = typeof body2.reasoning === "string" ? body2.reasoning.slice(0, limits.maxReasoningChars) : void 0;
47062
47124
  if (body2.outcome === REFUSED_OUTCOME) {
47063
47125
  const answer = readRefusedAnswer(body2);
@@ -48783,7 +48845,7 @@ async function runCodegenStep(p) {
48783
48845
  return finish(first.done);
48784
48846
  }
48785
48847
  const f1 = first.failure;
48786
- log({ event: "codegen.attempt_end", attempt: 1, outcome: "failed", reason: f1.reason, turns: f1.summary?.turns ?? 0, toolCalls: f1.summary?.toolCalls ?? 0, durationMs: firstMs });
48848
+ log({ event: "codegen.attempt_end", attempt: 1, outcome: "failed", reason: f1.reason, ...f1.afterRecovery ? { afterRecovery: true } : {}, turns: f1.summary?.turns ?? 0, toolCalls: f1.summary?.toolCalls ?? 0, durationMs: firstMs });
48787
48849
  const said = f1.detail ? `: ${f1.detail}` : "";
48788
48850
  if (f1.reason === "contract_rejected") {
48789
48851
  p.out.loop = buildCodegenLoopRecord({ ...f1.summary ?? NO_SUMMARY, stopReason: "fallback", fellBack: true, fallbackReason: f1.reason });
@@ -48825,7 +48887,7 @@ async function runCodegenStep(p) {
48825
48887
  return finish(second.done, [firstRecord, { n: 2, outcome: "finished", turns: second.done.summary.turns, toolCalls: second.done.summary.toolCalls }]);
48826
48888
  }
48827
48889
  const f2 = second.failure;
48828
- log({ event: "codegen.attempt_end", attempt: 2, outcome: "failed", reason: f2.reason, turns: f2.summary?.turns ?? 0, toolCalls: f2.summary?.toolCalls ?? 0, durationMs: secondMs });
48890
+ log({ event: "codegen.attempt_end", attempt: 2, outcome: "failed", reason: f2.reason, ...f2.afterRecovery ? { afterRecovery: true } : {}, turns: f2.summary?.turns ?? 0, toolCalls: f2.summary?.toolCalls ?? 0, durationMs: secondMs });
48829
48891
  throw lose(p, f2.summary, [firstRecord, failedAttempt(2, f2)], f2.reason === "out_of_time" ? "out_of_time" : "failed", f2.unreportable);
48830
48892
  }
48831
48893
 
@@ -50807,7 +50869,7 @@ var FAILURE_ARTIFACT_DIR = "quikpilot-failure";
50807
50869
  var REPORT_COPY = "final-test-report.xml";
50808
50870
  var MAX_REPORT_BYTES = 5 * 1024 * 1024;
50809
50871
  var MAX_FILES = 200;
50810
- var RUNNER_VERSION = true ? "9.3.0-rc.56" : "dev";
50872
+ var RUNNER_VERSION = true ? "9.3.0-rc.57" : "dev";
50811
50873
  function safeDestination(base, repoPath) {
50812
50874
  if (!repoPath || (0, import_node_path25.isAbsolute)(repoPath)) return null;
50813
50875
  const destination = (0, import_node_path25.resolve)(base, repoPath);