@0perator/operator 0.1.274 → 0.1.276

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.
@@ -8,7 +8,6 @@ import { dirname } from "node:path";
8
8
  import { operatorPath } from "./home.js";
9
9
  import { applyManagedPolicy, loadManagedPolicy } from "./managed.js";
10
10
  import { DEFAULT_MODEL_ID } from "../router/models.js";
11
- import { DEFAULT_POWER_TOOLS } from "../tools/power-tools.js";
12
11
  // The sole endpoint: Aurora on :8097 at its REAL served context — 307,200 tokens (300K; the llama-server
13
12
  // runs --ctx-size 307200 with q8_0 KV cache, standardized on JL1+JL2 2026-09-27). ctxWindow MUST match the
14
13
  // server's real --ctx-size: an inflated value (it was 1048576/"1M") makes compaction fire far too late — the
@@ -24,15 +23,10 @@ const DEFAULTS = {
24
23
  },
25
24
  modelMode: "local", // default: this node uses its own local model (endpoints.aurora); set "aurora" to use the shared fleet
26
25
  fleet: { auroraNodes: ["http://192.168.1.103:8097", "http://192.168.1.146:8097"] }, // JL1, JL2 — the live Aurora serving nodes (priority order)
27
- maxTokens: 64000, // per-reply output ceiling at the frontier bar (Claude Code/Sonnet allow up to 64k output;
28
- // Codex/Gemini similar). clampMaxTokens still fits it to the space left after the prompt, so a
29
- // reply never overflows — this is a CEILING the model rarely reaches, not a target. Max output
30
- // so a big file/answer lands whole in one reply instead of truncating + working around.
26
+ maxTokens: 32768, // generous per-reply output cap — 1M ctx has ample room; clampMaxTokens still trims
27
+ // to the space left after the prompt so a reply never overflows. A small cap (was
28
+ // 2048) forced the model to truncate + work around; this lets full files/answers land.
31
29
  temperature: 0.7,
32
- compaction: { threshold: 0.9 }, // compact only NEAR the window (frontier posture: Claude Code/Gemini use the
33
- // full context + compact near the limit), not at a conservative fraction. The
34
- // absolute RAM-safe ceiling (compactionCeilingTokens) still binds first on a
35
- // local big-window model; this governs fast/cloud models with ample decode.
36
30
  mcp: false,
37
31
  memory: { recall: true },
38
32
  selfImprove: { flywheel: true, memory: false, skills: false, reflect: false }, // trajectory capture ON; memory/skills/reflect sinks staged
@@ -44,7 +38,6 @@ const DEFAULTS = {
44
38
  telemetry: { enabled: true }, // local-only metrics (silent JSONL); remote sink opt-in via KODE_TELEMETRY_URL
45
39
  sandbox: { mode: "off" }, // no isolation by default — enterprise turns it on (KODE_SANDBOX / settings)
46
40
  computer: { enabled: false }, // computer control OFF by default; enable with KODE_COMPUTER=1 or settings.json
47
- powerTools: DEFAULT_POWER_TOOLS, // agnostic logWatch ON; fleet-coupled groups OFF (KODE_POWERTOOLS_* / settings.json)
48
41
  search: {}, // web_search backend unset by default; set search.searxngUrl / search.autopilotUrl or the env vars
49
42
  // Service lever — JL1 defaults. On a machine without these launchd agents every start step just fails
50
43
  // harmlessly and the boot screen falls back to the manual hint (autostart is best-effort by design).
@@ -99,7 +92,7 @@ function readSettingsFile(path) {
99
92
  /** Fold env vars over the file+default merge — the top layer of the precedence stack. Only an env
100
93
  * var that's actually set overrides; an unset one leaves the file/default value alone. */
101
94
  function applyEnv(s) {
102
- const out = { ...s, endpoints: { ...s.endpoints }, memory: { ...s.memory }, selfImprove: { ...s.selfImprove }, verifyGate: { ...s.verifyGate }, background: { ...s.background }, ui: { ...s.ui }, permissions: { ...s.permissions }, telemetry: { ...s.telemetry }, sandbox: { ...s.sandbox }, computer: { ...s.computer }, powerTools: { ...s.powerTools }, search: { ...s.search }, services: s.services ? structuredClone(s.services) : undefined, compaction: s.compaction ? { ...s.compaction } : undefined };
95
+ const out = { ...s, endpoints: { ...s.endpoints }, memory: { ...s.memory }, selfImprove: { ...s.selfImprove }, verifyGate: { ...s.verifyGate }, background: { ...s.background }, ui: { ...s.ui }, permissions: { ...s.permissions }, telemetry: { ...s.telemetry }, sandbox: { ...s.sandbox }, computer: { ...s.computer }, search: { ...s.search }, services: s.services ? structuredClone(s.services) : undefined, compaction: s.compaction ? { ...s.compaction } : undefined };
103
96
  if (process.env.KODE_MODEL)
104
97
  out.endpoints = { ...out.endpoints, aurora: { ...out.endpoints.aurora, model: process.env.KODE_MODEL } }; // AI-agnostic quick-swap (keeps failover)
105
98
  const mm = process.env.KODE_MODEL_MODE; // local | aurora — env override of the node's model source
@@ -142,27 +135,6 @@ function applyEnv(s) {
142
135
  out.sandbox = { mode: sb };
143
136
  if (process.env.KODE_COMPUTER === "1")
144
137
  out.computer = { enabled: true };
145
- // Power-tools feature flags — each KODE_POWERTOOLS_* (1/0) overrides its group; agnostic logWatch defaults
146
- // ON, the fleet-coupled groups OFF. A disabled group's tools are absent from schemas/catalogue/executor.
147
- const ptFlag = (name) => {
148
- const v = process.env[name];
149
- return v === "1" ? true : v === "0" ? false : undefined;
150
- };
151
- const ptLog = ptFlag("KODE_POWERTOOLS_LOGWATCH");
152
- const ptFleet = ptFlag("KODE_POWERTOOLS_FLEET");
153
- const ptMem = ptFlag("KODE_POWERTOOLS_FLEETMEM");
154
- const ptHydra = ptFlag("KODE_POWERTOOLS_HYDRA");
155
- const ptHf = ptFlag("KODE_POWERTOOLS_HFUPLOAD");
156
- if (ptLog !== undefined)
157
- out.powerTools = { ...out.powerTools, logWatch: ptLog };
158
- if (ptFleet !== undefined)
159
- out.powerTools = { ...out.powerTools, fleetOps: ptFleet };
160
- if (ptMem !== undefined)
161
- out.powerTools = { ...out.powerTools, fleetMemory: ptMem };
162
- if (ptHydra !== undefined)
163
- out.powerTools = { ...out.powerTools, trainingCapture: ptHydra };
164
- if (ptHf !== undefined)
165
- out.powerTools = { ...out.powerTools, hfUpload: ptHf };
166
138
  // Service lever: KODE_SERVICES_AUTOSTART=0 disables autostart of BOTH launchd services (Operator then
167
139
  // only probes + reports); KODE_STOP_SEARXNG_ON_EXIT=0 keeps the SearXNG container running after exit.
168
140
  if (out.services) {
@@ -177,11 +149,6 @@ function applyEnv(s) {
177
149
  out.services = { ...out.services, stopOnExit: { ...out.services.stopOnExit, searxng: false } };
178
150
  }
179
151
  }
180
- // Auto-detect boot: KODE_AUTODETECT=0 probes only the active endpoint; KODE_AUTODETECT_CLOUD=0 never falls back to a BYO vendor.
181
- if (process.env.KODE_AUTODETECT === "0")
182
- out.autodetect = { ...out.autodetect, enabled: false };
183
- if (process.env.KODE_AUTODETECT_CLOUD === "0")
184
- out.autodetect = { ...out.autodetect, cloud: false };
185
152
  // Autonomy env overrides. KODE_KEEP_AWAKE=1 forces keep-awake for the run; KODE_AUTONOMY_DREAM=0/1
186
153
  // is the hard dream off/on switch that overrides the file. Both only act when actually set.
187
154
  if (out.autonomy) {
@@ -230,16 +197,8 @@ export function defaultCompactionCeiling(totalBytes, windowTokens) {
230
197
  // a small live context keeps every owner-facing reply fast; retrieval reclaims what compaction summarizes out.
231
198
  // Autonomy rides high — just under the 64GB swap cliff (~126k) — because an unattended run isn't waiting on
232
199
  // decode and fewer compactions means it holds the thread across a long multi-step mission instead of thrashing.
233
- // Owner directive (James 2026-10-10): max every software limit — hold as much context as the hardware safely
234
- // allows, compact only near the real limit (the frontier posture: Claude Code / Codex / Gemini use the full
235
- // window and compact near it, not at an artificial low ceiling). Both modes now ride the RAM-aware safe ceiling
236
- // (defaultCompactionCeiling clamps 1_000_000 down to what fits without swapping — ~126k on a 64GB box, higher on
237
- // more RAM, 0.85·window on a huge-RAM box). The clamp is NOT a policy limit: crossing it swaps the KV cache and
238
- // decode collapses to ~0 tok/s (a freeze, not a slowdown), so it stays as crash-prevention. NOTE the tradeoff
239
- // the owner accepts: a larger live context = slower per-reply DECODE on a bandwidth-bound local model; the ceiling
240
- // never limited token SPEND, it protected decode speed. An explicit settings/env override still wins either way.
241
- const INTERACTIVE_DEFAULT_CEILING = 1_000_000;
242
- const AUTONOMY_DEFAULT_CEILING = 1_000_000;
200
+ const INTERACTIVE_DEFAULT_CEILING = 24_000;
201
+ const AUTONOMY_DEFAULT_CEILING = 100_000;
243
202
  /** The absolute-token proactive-compaction ceiling to hand runTurn, resolved PER SESSION MODE — the one knob
244
203
  * that stops us trading reign for speed. Interactive and autonomy each have their own explicit override
245
204
  * (`compaction.ceilingTokens` / `compaction.autonomyCeilingTokens`, env-overridden in loadSettings) validated
@@ -33,6 +33,37 @@ const LOOP_GUARD_EXEMPT = new Set(["agent_status", "bash_output"]);
33
33
  // burning rounds to maxRoundsHard. An Aurora blip once drove the same blocked bash call 16× before the turn
34
34
  // died: LOOP_GUARD_LIMIT only *short-circuits* the call, it never *stopped* the spin — this does.
35
35
  const LOOP_GUARD_HARD = LOOP_GUARD_LIMIT * 2; // 10
36
+ // Repeated-completed-action (RCA) guard — THE live-loop killer. The identical-args guard above is beaten by
37
+ // a model that varies a call by ONE WORD (`print result` -> `print results`), and the converge guard needs
38
+ // EXACTLY repeated narration and only speaks at NO_CONVERGE_LIMIT=25 rounds. Measured 2026-10-11: a session
39
+ // re-emitted the same bash heredoc write+run for 35+ rounds, each "✓ completed" — every guard was evaded or
40
+ // reset and the turn ran until the human cancelled it. RCA keys on the one signal that cannot be varied
41
+ // away: ACTION SUCCESS. Division of labour with LOOP_GUARD — exact repeats stay the counter's; RCA owns the
42
+ // NEAR-identical class: a call whose NORMALIZED fingerprint (lowercase, punctuation/whitespace stripped,
43
+ // word-singularized) already SUCCEEDED this turn under a DIFFERENT exact spelling is never re-dispatched —
44
+ // short-circuited with "already completed", and RCA_STOP dressed-up repeats later force-stop the turn
45
+ // ("stuck — repeated completed action"). A landed mutation clears the tallies (from the same place the
46
+ // callCounts reset happens), so edit → re-run iteration stays unbounded; EMPTY and failure-prefixed results
47
+ // never arm (the no-progress guard owns silence; failed calls stay retryable); poll/status tools are exempt
48
+ // like everywhere else.
49
+ const RCA_STOP = 3;
50
+ const normActionWord = (w) => (w.length > 3 ? w.replace(/(?:es|s)$/u, "") : w);
51
+ const normalizeActionValue = (v) => {
52
+ if (typeof v === "string")
53
+ return v.toLowerCase().normalize("NFKC").replace(/[^\p{L}\p{N} ]+/gu, " ").replace(/\s+/g, " ").trim().split(" ").map(normActionWord).join(" ");
54
+ if (Array.isArray(v))
55
+ return v.map(normalizeActionValue);
56
+ if (v && typeof v === "object") {
57
+ const o = {};
58
+ for (const [k, val] of Object.entries(v))
59
+ o[k] = normalizeActionValue(val);
60
+ return o;
61
+ }
62
+ return v;
63
+ };
64
+ const actionFingerprint = (name, args) => name + ":" + JSON.stringify(normalizeActionValue(args));
65
+ // A tool result counts as a COMPLETED action unless it opens with a failure prefix the tool layer uses.
66
+ const ACTION_FAILED_RE = /^(error|loop guard|permission denied|repeated action)/i;
36
67
  const CONTENT_LOOP_LIMIT = 3; // whole round (prose + actions) repeats this many times ⇒ light NUDGE to pivot
37
68
  const CONTENT_LOOP_REDIRECT = 6; // …and at this many, escalate to a FORCED REDIRECT: make the model diagnose the
38
69
  // loop and decompose OR switch approach, then reset its runway and CONTINUE (enterprise loop-recovery — the
@@ -72,25 +103,6 @@ const NO_EDIT_NUDGE = 15; // tool rounds that change NO file ⇒ ONE soft "conve
72
103
  const THINK_SPIRAL_ROUNDS = 5; // consecutive heavy-reasoning, no-file-edit rounds (while /think on) ⇒ latch think OFF
73
104
  const THINK_SPIRAL_MIN_REASON_CHARS = 400; // a round counts as "heavy reasoning" only past this much reasoning_content
74
105
  const REHYDRATE_MAX_FILES = 5; // after a compaction, name up to this many recently-touched files for the model to re-read
75
- // Decode-speed floor — the latency guarantee (James 2026-10-10, AXE-WARDEN: "a field user's life is on the line,
76
- // Operator cannot crawl"). A bandwidth-bound local model's DECODE rate falls as the live context grows (measured
77
- // ~45→9→5 tok/s on a 64GB box; a 300k-ctx model at ~89k was 7 tok/s → 7-min turns). When the last round's measured
78
- // decode rate drops below the floor, the compaction ceiling is tightened to SPEED_PROTECT_CEILING so the NEXT round
79
- // compacts hard — Operator shrinks its own context to restore speed instead of sitting at a few tok/s for minutes.
80
- // ADAPTIVE: it only tightens WHEN decode is actually suffering, so a fast model (cloud / spec-decode / small local)
81
- // keeps its full context ceiling — speed AND context, not one fixed slider. Env KODE_DECODE_FLOOR_TPS overrides.
82
- const DECODE_SPEED_FLOOR_TPS = (() => { const v = Number(process.env.KODE_DECODE_FLOOR_TPS); return Number.isFinite(v) && v >= 0 ? v : 12; })();
83
- const SPEED_PROTECT_CEILING = (() => { const v = Number(process.env.KODE_SPEED_PROTECT_CEILING); return Number.isFinite(v) && v >= 8000 ? v : 32_000; })();
84
- /** The effective compaction ceiling after the decode-speed floor. When the model decoded BELOW the floor last
85
- * round (a big context on bandwidth-bound HW), cap the ceiling at SPEED_PROTECT_CEILING so the proactive-compaction
86
- * gate fires and the context shrinks; above the floor (or no measurement yet) the configured ceiling stands, so
87
- * context is traded for speed ONLY while speed is actually suffering. Pure + exported for tests. */
88
- export function speedProtectedCeiling(ceiling, decodeTokPerSec) {
89
- if (decodeTokPerSec != null && decodeTokPerSec > 0 && decodeTokPerSec < DECODE_SPEED_FLOOR_TPS) {
90
- return Math.min(ceiling ?? SPEED_PROTECT_CEILING, SPEED_PROTECT_CEILING);
91
- }
92
- return ceiling;
93
- }
94
106
  const COMPACTION_FAIL_LIMIT = 3; // rounds still OVER the window after compaction ran ⇒ it can't free space (summarizer failing / un-evictable bulk); stop spinning into the same wall
95
107
  const MAX_TRUNC_RETRIES = 3; // chunk-write nudges before a repeatedly-truncated tool call surfaces honestly — a
96
108
  // genuinely large body (docstring, generated file) can need one extra round past the quote-fix case: first
@@ -276,7 +288,7 @@ function parseArgs(raw) {
276
288
  * guard (SPEC §2: identical (name,args) ≥3× this turn is short-circuited) and reporting the
277
289
  * batch via onToolBatch with a real (unrounded) duration.
278
290
  */
279
- async function runToolCalls(toolCalls, tools, callCounts, onToolBatch, onToolStart, onToolResult, signal) {
291
+ async function runToolCalls(toolCalls, tools, callCounts, rca, onToolBatch, onToolStart, onToolResult, signal) {
280
292
  // One id for this whole round (SPEC parallel-tool-batch) — every call made here, however it
281
293
  // resolves (executed, parse error, loop-guarded), shares it, so a host can box "N tools in
282
294
  // parallel" together even for the calls that never reached the executor. Same id-shape idiom as
@@ -319,6 +331,21 @@ async function runToolCalls(toolCalls, tools, callCounts, onToolBatch, onToolSta
319
331
  `arguments. Try a different approach instead of repeating this call.`);
320
332
  return;
321
333
  }
334
+ // RCA gate (see RCA_STOP above): division of labour with the guard above — EXACT repeats are LOOP_GUARD's
335
+ // (its count/short-circuit/hard-stop escalation and pinned tests stay authoritative); RCA owns only the
336
+ // NEAR-identical class the exact count can never reach: a call whose NORMALIZED fingerprint already
337
+ // SUCCEEDED this turn under a DIFFERENT exact spelling. One-word-dressed repeats die here.
338
+ const fp = actionFingerprint(tc.function.name, parsed.args);
339
+ const arm = rca.succeeded.get(fp);
340
+ if (arm && !arm.has(sig)) {
341
+ const refused = (rca.refused.get(fp) ?? 0) + 1;
342
+ rca.refused.set(fp, refused);
343
+ if (refused >= RCA_STOP) {
344
+ loopAbort = `stuck — repeated completed action: "${tc.function.name}" already COMPLETED this turn (spelled ${arm.size} way(s)) and a merely re-worded variant was re-issued ${refused}× despite the short-circuit. The action is DONE — its result is already in the history above.`;
345
+ }
346
+ preResolved.set(tc.id, `Repeated action: "${tc.function.name}" with these arguments already COMPLETED successfully this turn (re-wording it does not make it new work). Re-running cannot produce anything new. Finalize your answer from the existing result, or take a materially DIFFERENT action.`);
347
+ return;
348
+ }
322
349
  pending.push({ id: tc.id, name: tc.function.name, args: parsed.args, batchId, batchSize, batchIndex });
323
350
  });
324
351
  // A signature blew past the hard loop ceiling: stop the turn cleanly rather than let the model spin to the
@@ -340,8 +367,28 @@ async function runToolCalls(toolCalls, tools, callCounts, onToolBatch, onToolSta
340
367
  // toward LOOP_GUARD_LIMIT. This is what lets Operator iterate (edit → re-run → edit → re-run) unbounded.
341
368
  // A FAILING edit ("error: old_string not found") changed nothing — it must not reset the count, or a model
342
369
  // can alternate a failing edit with the same poisoned call forever (the guard could never stop it).
343
- if (pending.some((p, i) => mutationLanded(p.name, executed[i])))
370
+ const mutated = pending.some((p, i) => mutationLanded(p.name, executed[i]));
371
+ if (mutated) {
344
372
  callCounts.clear();
373
+ rca.succeeded.clear();
374
+ rca.refused.clear();
375
+ }
376
+ // RCA bookkeeping: record each SUCCESSFUL dispatch's exact signature under its normalized fingerprint —
377
+ // "completed spellings" is what the gate compares against (an unrecorded spelling of a completed action
378
+ // is a dressed-up repeat). Empty and failure-prefixed results never arm: an action that produced NOTHING
379
+ // is the no-progress guard's territory, a FAILED one is legitimately retryable. A round that LANDED a
380
+ // mutation skips recording: "completed" is always relative to the LAST CHANGE.
381
+ if (!mutated)
382
+ pending.forEach((p, i) => {
383
+ const out = executed[i] ?? "";
384
+ const t = out.trimStart();
385
+ if (t.length > 0 && !ACTION_FAILED_RE.test(t)) {
386
+ const fp = actionFingerprint(p.name, p.args);
387
+ const seen = rca.succeeded.get(fp) ?? new Set();
388
+ rca.succeeded.set(fp, seen);
389
+ seen.add(callSignature(p.name, p.args));
390
+ }
391
+ });
345
392
  if (onToolBatch) {
346
393
  const events = toolCalls.map((tc, batchIndex) => ({
347
394
  name: tc.function.name,
@@ -394,6 +441,7 @@ export async function runTurn(userInput, conversation, opts) {
394
441
  const absCeiling = Math.max(softRounds + 1, opts.maxRoundsHard ?? 400); // absolute safety stop; progress-aware below
395
442
  const turnStart = Date.now(); // for the per-turn wall-clock budget (opts.maxTurnWallClockMs) — the only bound on TIME
396
443
  const callCounts = new Map();
444
+ const rca = { succeeded: new Map(), refused: new Map() }; // normalized-fingerprint → completed exact spellings; + refusal tally (see RCA_STOP)
397
445
  const contentSigs = new Map(); // per-round prose fingerprints → the narration loop guard
398
446
  let forcedRedirects = 0; // enterprise loop-recovery: forced redirects spent this turn (each resets a repeated round's runway; the turn hands back only after CONTENT_LOOP_REDIRECT_MAX of them fail to break the loop)
399
447
  let progressed = true; // did the PREVIOUS tool batch advance? gates the guard (progress clears it)
@@ -477,7 +525,6 @@ export async function runTurn(userInput, conversation, opts) {
477
525
  let tokensTotal = 0; // output tokens summed across rounds (from llama.cpp timings)
478
526
  let genMsTotal = 0; // server-side generation ms summed across rounds
479
527
  let promptTokensTotal = 0; // prompt tokens PREFILLED, summed across rounds
480
- let lastDecodeTokPerSec; // last round's measured decode rate (tok/s) — drives the speed-floor on the NEXT round's compaction gate
481
528
  let promptMsTotal = 0; // prefill ms summed across rounds
482
529
  let emptyRetries = 0; // reasoning models sometimes return a "dud" round (no content, no tool calls)
483
530
  let truncRetries = 0; // chunk-write nudges spent recovering a truncated-tool-call 500 (truncatedToolNudge)
@@ -536,7 +583,7 @@ export async function runTurn(userInput, conversation, opts) {
536
583
  tools: opts.toolSchemas,
537
584
  summarize: opts.summarize,
538
585
  threshold: opts.compactionThreshold,
539
- ceilingTokens: speedProtectedCeiling(opts.compactionCeilingTokens, lastDecodeTokPerSec), // latency guarantee: tighten when decode is below the floor
586
+ ceilingTokens: opts.compactionCeilingTokens,
540
587
  minKeepTurns: opts.minKeepTurns,
541
588
  meter: globalTokenMeter, // SPEC §5: size to THIS endpoint's learned ratio, not chars/4
542
589
  meterKey: endpointKey(ep.base, ep.model),
@@ -600,12 +647,6 @@ export async function runTurn(userInput, conversation, opts) {
600
647
  });
601
648
  tokensTotal += response.tokens ?? 0;
602
649
  genMsTotal += response.genMs ?? 0; // accumulate real gen metrics across rounds
603
- // Measure THIS round's decode rate (tok/s) from the server's own gen timing — feeds the speed-floor
604
- // (speedProtectedCeiling) on the next round's compaction gate. Needs a real sample (enough tokens over
605
- // enough time) so a tiny/instant round can't spuriously trip or clear the floor.
606
- if ((response.tokens ?? 0) >= 16 && (response.genMs ?? 0) >= 250) {
607
- lastDecodeTokPerSec = response.tokens / (response.genMs / 1000);
608
- }
609
650
  promptTokensTotal += response.promptTokens ?? 0;
610
651
  promptMsTotal += response.promptMs ?? 0; // and prefill (the invisible wall-time cost)
611
652
  // Token meter (SPEC §5): teach the endpoint its real chars/token from the server's EXACT
@@ -792,9 +833,7 @@ export async function runTurn(userInput, conversation, opts) {
792
833
  opts.onSelfHeal?.("server_error", seen - CONTENT_LOOP_LIMIT + 1); // footer ↻ — breaking a stall
793
834
  conversation.user(`You've repeated the same step ${seen}× with the same result — that approach is not working. Do NOT ` +
794
835
  `end the turn or ask me how to proceed. STOP repeating it and try a genuinely DIFFERENT approach: a ` +
795
- `different command, tool, path, or angle; if a tool seems broken, work around it — but NEVER replace ` +
796
- `a native tool (image/video/vision/voice, search, delegate) by installing tooling or downloading ` +
797
- `models: a tool that errors is an outage, so retry it once and report it. If you already ` +
836
+ `different command, tool, path, or angle; if a tool seems broken, work around it. If you already ` +
798
837
  `know the fix (you often do — you just described one), do it now.`);
799
838
  continue;
800
839
  }
@@ -817,8 +856,7 @@ export async function runTurn(userInput, conversation, opts) {
817
856
  ` (a) BREAK IT DOWN — split the stuck step into a smaller, concrete sub-action and do just that ` +
818
857
  `one thing now; or\n` +
819
858
  ` (b) SWITCH APPROACH — a genuinely different tool, command, path, or order of operations; if a ` +
820
- `tool or command seems broken, work around it — but NEVER replace a native tool by installing ` +
821
- `tooling or downloading models (a failing tool is an outage: retry once, then report it).\n` +
859
+ `tool or command seems broken, work around it.\n` +
822
860
  `Do NOT reproduce your previous output, do NOT end the turn, and do NOT ask me how to proceed — ` +
823
861
  `decide and act on the smallest next concrete step.`);
824
862
  continue;
@@ -889,7 +927,7 @@ export async function runTurn(userInput, conversation, opts) {
889
927
  conversation.assistant(response.content, response.toolCalls);
890
928
  // Race the batch against the abort signal so esc breaks even a hung tool (a frozen child process) —
891
929
  // the abandoned tool runs to its own timeout, but the turn is never wedged.
892
- const toolMsgs = await abortable(runToolCalls(response.toolCalls, opts.tools, callCounts, opts.onToolBatch, onToolStartFx, onToolResultFx, opts.signal), opts.signal);
930
+ const toolMsgs = await abortable(runToolCalls(response.toolCalls, opts.tools, callCounts, rca, opts.onToolBatch, onToolStartFx, onToolResultFx, opts.signal), opts.signal);
893
931
  for (const tm of capToolRound(toolMsgs))
894
932
  conversation.tool(tm.tool_call_id, tm.content); // cap the ROUND's total tool output so a high-fanout round can't overflow the window / defeat compaction
895
933
  observeVerify(verify, response.toolCalls, toolMsgs); // verify-before-done: record mutation / verify signal
@@ -907,7 +945,7 @@ export async function runTurn(userInput, conversation, opts) {
907
945
  if (recovered.calls.length > 0) {
908
946
  throwIfAborted(opts.signal);
909
947
  conversation.assistant(recovered.cleanedContent, recovered.calls);
910
- const toolMsgs = await abortable(runToolCalls(recovered.calls, opts.tools, callCounts, opts.onToolBatch, onToolStartFx, onToolResultFx, opts.signal), opts.signal);
948
+ const toolMsgs = await abortable(runToolCalls(recovered.calls, opts.tools, callCounts, rca, opts.onToolBatch, onToolStartFx, onToolResultFx, opts.signal), opts.signal);
911
949
  for (const tm of capToolRound(toolMsgs))
912
950
  conversation.tool(tm.tool_call_id, tm.content); // cap the ROUND's total tool output so a high-fanout round can't overflow the window / defeat compaction
913
951
  observeVerify(verify, recovered.calls, toolMsgs); // verify-before-done: record mutation / verify signal