@quikit/quikpilot-runner 9.3.0-rc.8 → 9.3.0-rc.9

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/dist/index.js CHANGED
@@ -2083,6 +2083,44 @@ function resolveCodegenMode(env2 = process.env, packetSetting) {
2083
2083
  return parse(packetSetting) ?? parse(env2[CODEGEN_MODE_ENV]) ?? "single";
2084
2084
  }
2085
2085
 
2086
+ // src/refusedReply.ts
2087
+ var REFUSED_OUTCOME = "REFUSED";
2088
+ var REFUSED_STREAK_LIMIT = 3;
2089
+ var MAX_REFUSED_RULES = 8;
2090
+ var MAX_REFUSED_SENTENCES = 8;
2091
+ var MAX_REFUSED_SENTENCE_CHARS = 300;
2092
+ var MAX_REFUSED_RULE_CHARS = 40;
2093
+ var REFUSED_RULE_IDS = [
2094
+ "reply_shape",
2095
+ "last_turn",
2096
+ "no_calls_left",
2097
+ "too_many_calls",
2098
+ "call_id",
2099
+ "unknown_tool",
2100
+ "bad_args",
2101
+ "bad_path",
2102
+ "protected_path",
2103
+ "file_state",
2104
+ "budget",
2105
+ "run_tests_rule",
2106
+ "repeat_call",
2107
+ "done_rule",
2108
+ "length"
2109
+ ];
2110
+ var KNOWN_RULES = new Set(REFUSED_RULE_IDS);
2111
+ function readRefusedAnswer(body) {
2112
+ const { rules, violations, message } = body;
2113
+ if (!Array.isArray(rules) || rules.length < 1 || rules.length > MAX_REFUSED_RULES) return null;
2114
+ if (!rules.every((r) => typeof r === "string" && r.length > 0 && r.length <= MAX_REFUSED_RULE_CHARS)) return null;
2115
+ if (!Array.isArray(violations) || violations.length < 1 || violations.length > MAX_REFUSED_SENTENCES) return null;
2116
+ if (!violations.every((v) => typeof v === "string" && v.length <= MAX_REFUSED_SENTENCE_CHARS)) return null;
2117
+ if (typeof message !== "string" || message.length > MAX_REFUSED_SENTENCE_CHARS) return null;
2118
+ return { rules: [...rules], violations: [...violations], message };
2119
+ }
2120
+ function recordRuleWord(word) {
2121
+ return typeof word === "string" && KNOWN_RULES.has(word) ? word : "other";
2122
+ }
2123
+
2086
2124
  // src/codegenLoopRecord.ts
2087
2125
  var MAX_RECORD_PATHS = 50;
2088
2126
  var MAX_RECORD_PATH_CHARS = 300;
@@ -2090,6 +2128,8 @@ var MAX_RECORD_REASONING_TURNS = 30;
2090
2128
  var MAX_RECORD_REASONING_CHARS = 500;
2091
2129
  var MAX_RECORD_FALLBACK_REASON_CHARS = 40;
2092
2130
  var MAX_RECORD_TEST_RUNS = 3;
2131
+ var MAX_RECORD_REFUSED_TURNS = 30;
2132
+ var MAX_RECORD_REFUSED_RULES = 8;
2093
2133
  var MAX_STATUS_KEYS = 20;
2094
2134
  var MAX_STATUS_KEY_CHARS = 40;
2095
2135
  function whole(n) {
@@ -2160,6 +2200,16 @@ function buildCodegenLoopRecord(loop) {
2160
2200
  seconds: whole(t.seconds)
2161
2201
  });
2162
2202
  }
2203
+ const refusedTurns = [];
2204
+ for (const t of loop.refusedTurns ?? []) {
2205
+ if (refusedTurns.length >= MAX_RECORD_REFUSED_TURNS) {
2206
+ cut = true;
2207
+ break;
2208
+ }
2209
+ if (t.rules.length > MAX_RECORD_REFUSED_RULES) cut = true;
2210
+ const rules = [...new Set(t.rules.map(recordRuleWord))].slice(0, MAX_RECORD_REFUSED_RULES);
2211
+ if (rules.length > 0) refusedTurns.push({ turn: whole(t.turn), rules });
2212
+ }
2163
2213
  return {
2164
2214
  turns: whole(loop.turns),
2165
2215
  toolCalls: whole(loop.toolCalls),
@@ -2174,6 +2224,7 @@ function buildCodegenLoopRecord(loop) {
2174
2224
  ...whole(loop.syntaxWarnings) > 0 ? { syntaxWarnings: whole(loop.syntaxWarnings) } : {},
2175
2225
  ...typeof loop.contractVersion === "string" && loop.contractVersion.length > 0 ? { contractVersion: loop.contractVersion.slice(0, 40) } : {},
2176
2226
  ...testRuns.length > 0 ? { testRuns } : {},
2227
+ ...refusedTurns.length > 0 ? { refusedTurns } : {},
2177
2228
  reasoning,
2178
2229
  ...cut ? { truncated: true } : {}
2179
2230
  };
@@ -12886,6 +12937,8 @@ async function runCodegenLoop(args, deps) {
12886
12937
  const transcript = [];
12887
12938
  const toolResults = [];
12888
12939
  const usedIds = /* @__PURE__ */ new Set();
12940
+ const refusedTurns = [];
12941
+ let refusedStreak = 0;
12889
12942
  let turns = 0;
12890
12943
  let noProgressStreak = 0;
12891
12944
  let forced = null;
@@ -12898,6 +12951,8 @@ async function runCodegenLoop(args, deps) {
12898
12951
  maxTurns: limits.maxTurns,
12899
12952
  final: isFinal,
12900
12953
  ...isFinal ? { finalReason } : {},
12954
+ // Says this runner can carry a REFUSED answer (24.12a). Without it the runtime fails the request, as it always did.
12955
+ acceptsRefused: true,
12901
12956
  remaining: {
12902
12957
  toolCalls: Math.max(0, limits.maxToolCalls - ledger.toolCalls),
12903
12958
  readChars: Math.max(0, limits.readCharsTotal - ledger.readChars),
@@ -12919,6 +12974,7 @@ async function runCodegenLoop(args, deps) {
12919
12974
  statusCounts: { ...statusCounts },
12920
12975
  syntaxWarnings: ws.syntaxWarnings,
12921
12976
  ...tests ? { contractVersion: CODEGEN_LOOP_2_CONTRACT_VERSION, testRuns: tests.record() } : {},
12977
+ ...refusedTurns.length > 0 ? { refusedTurns: refusedTurns.map((t) => ({ turn: t.turn, rules: [...t.rules] })) } : {},
12922
12978
  reasoning: [...reasoning]
12923
12979
  });
12924
12980
  const makeRoom = (nextTurn, nextFinal, finalReason) => {
@@ -12943,6 +12999,17 @@ async function runCodegenLoop(args, deps) {
12943
12999
  }
12944
13000
  return fits();
12945
13001
  };
13002
+ const settleNextTurn = (turn, forcedNow) => {
13003
+ const nextTurn = turn + 1;
13004
+ if (nextTurn > limits.maxTurns) return forcedNow;
13005
+ const nextFinal = forcedNow !== null || nextTurn === limits.maxTurns;
13006
+ if (makeRoom(nextTurn, nextFinal, forcedNow ?? "max_turns")) return forcedNow;
13007
+ const reason = forcedNow ?? "read_budget";
13008
+ const fits = makeRoom(nextTurn, true, reason);
13009
+ log({ event: "codegen.loop_ceiling", turn, action: fits ? "forced_final" : "fallback", ceiling: limits.maxRequestTokens });
13010
+ if (!fits) throw new CodegenLoopFailure("token_ceiling");
13011
+ return reason;
13012
+ };
12946
13013
  log({ event: "codegen.loop_start", maxTurns: limits.maxTurns, maxToolCalls: limits.maxToolCalls, listingFiles: args.listing.length });
12947
13014
  try {
12948
13015
  for (let turn = 1; turn <= limits.maxTurns; turn++) {
@@ -12990,6 +13057,18 @@ async function runCodegenLoop(args, deps) {
12990
13057
  throw new CodegenLoopFailure("bad_reply", void 0, err);
12991
13058
  }
12992
13059
  const reasonText = typeof body.reasoning === "string" ? body.reasoning.slice(0, limits.maxReasoningChars) : void 0;
13060
+ if (body.outcome === REFUSED_OUTCOME) {
13061
+ const answer = readRefusedAnswer(body);
13062
+ if (!answer) throw new CodegenLoopFailure("bad_reply");
13063
+ refusedStreak += 1;
13064
+ refusedTurns.push({ turn, rules: answer.rules });
13065
+ log({ event: "codegen.loop_turn", turn, outcome: "refused", requestTokens, elapsedMs: now() - turnStarted, calls: [], rules: answer.rules.map(recordRuleWord), streak: refusedStreak });
13066
+ if (isFinal) throw new CodegenLoopFailure("final_not_produced");
13067
+ transcript.push({ turn, toolCalls: [], refused: answer });
13068
+ if (refusedStreak >= REFUSED_STREAK_LIMIT) forced = "refused_repeatedly";
13069
+ forced = settleNextTurn(turn, forced);
13070
+ continue;
13071
+ }
12993
13072
  if (body.outcome === "CANNOT_COMPLETE") {
12994
13073
  log({ event: "codegen.loop_turn", turn, outcome: "cannot_complete", requestTokens, elapsedMs: now() - turnStarted, calls: [] });
12995
13074
  const said = typeof body.summary === "string" ? body.summary.slice(0, MAX_SUMMARY_CHARS) : void 0;
@@ -13076,21 +13155,13 @@ async function runCodegenLoop(args, deps) {
13076
13155
  if (reasonText) reasoning.push({ turn, text: reasonText });
13077
13156
  transcript.push({ turn, ...reasonText ? { reasoning: reasonText } : {}, toolCalls: calls.map((c) => ({ id: c.id, name: c.name, args: c.args })) });
13078
13157
  toolResults.push(...results);
13158
+ refusedStreak = 0;
13079
13159
  noProgressStreak = results.every((r) => r.status === "duplicate") ? noProgressStreak + 1 : 0;
13080
13160
  if (noProgressStreak >= 2) forced = "no_progress";
13081
13161
  else if (ledger.toolCalls >= limits.maxToolCalls) forced = "tool_budget";
13082
13162
  else if (ledger.writeChars >= limits.writeCharsTotal) forced = "write_budget";
13083
13163
  else if (ledger.readChars >= limits.readCharsTotal || ledger.resultChars >= limits.resultCharsTotal) forced = "read_budget";
13084
- const nextTurn = turn + 1;
13085
- if (nextTurn <= limits.maxTurns) {
13086
- const nextFinal = forced !== null || nextTurn === limits.maxTurns;
13087
- if (!makeRoom(nextTurn, nextFinal, forced ?? "max_turns")) {
13088
- forced = forced ?? "read_budget";
13089
- const fits = makeRoom(nextTurn, true, forced);
13090
- log({ event: "codegen.loop_ceiling", turn, action: fits ? "forced_final" : "fallback", ceiling: limits.maxRequestTokens });
13091
- if (!fits) throw new CodegenLoopFailure("token_ceiling");
13092
- }
13093
- }
13164
+ forced = settleNextTurn(turn, forced);
13094
13165
  log({ event: "codegen.loop_turn", turn, outcome: "tool_calls", requestTokens, elapsedMs: now() - turnStarted, calls: logged });
13095
13166
  }
13096
13167
  throw new CodegenLoopFailure("final_not_produced");
@@ -13686,7 +13757,7 @@ var FAILURE_ARTIFACT_DIR = "quikpilot-failure";
13686
13757
  var REPORT_COPY = "final-test-report.xml";
13687
13758
  var MAX_REPORT_BYTES = 5 * 1024 * 1024;
13688
13759
  var MAX_FILES = 200;
13689
- var RUNNER_VERSION = true ? "9.3.0-rc.8" : "dev";
13760
+ var RUNNER_VERSION = true ? "9.3.0-rc.9" : "dev";
13690
13761
  function safeDestination(base, repoPath) {
13691
13762
  if (!repoPath || (0, import_node_path12.isAbsolute)(repoPath)) return null;
13692
13763
  const destination = (0, import_node_path12.resolve)(base, repoPath);