@0perator/operator 0.1.274 → 0.1.275

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
@@ -72,25 +72,6 @@ const NO_EDIT_NUDGE = 15; // tool rounds that change NO file ⇒ ONE soft "conve
72
72
  const THINK_SPIRAL_ROUNDS = 5; // consecutive heavy-reasoning, no-file-edit rounds (while /think on) ⇒ latch think OFF
73
73
  const THINK_SPIRAL_MIN_REASON_CHARS = 400; // a round counts as "heavy reasoning" only past this much reasoning_content
74
74
  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
75
  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
76
  const MAX_TRUNC_RETRIES = 3; // chunk-write nudges before a repeatedly-truncated tool call surfaces honestly — a
96
77
  // genuinely large body (docstring, generated file) can need one extra round past the quote-fix case: first
@@ -477,7 +458,6 @@ export async function runTurn(userInput, conversation, opts) {
477
458
  let tokensTotal = 0; // output tokens summed across rounds (from llama.cpp timings)
478
459
  let genMsTotal = 0; // server-side generation ms summed across rounds
479
460
  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
461
  let promptMsTotal = 0; // prefill ms summed across rounds
482
462
  let emptyRetries = 0; // reasoning models sometimes return a "dud" round (no content, no tool calls)
483
463
  let truncRetries = 0; // chunk-write nudges spent recovering a truncated-tool-call 500 (truncatedToolNudge)
@@ -536,7 +516,7 @@ export async function runTurn(userInput, conversation, opts) {
536
516
  tools: opts.toolSchemas,
537
517
  summarize: opts.summarize,
538
518
  threshold: opts.compactionThreshold,
539
- ceilingTokens: speedProtectedCeiling(opts.compactionCeilingTokens, lastDecodeTokPerSec), // latency guarantee: tighten when decode is below the floor
519
+ ceilingTokens: opts.compactionCeilingTokens,
540
520
  minKeepTurns: opts.minKeepTurns,
541
521
  meter: globalTokenMeter, // SPEC §5: size to THIS endpoint's learned ratio, not chars/4
542
522
  meterKey: endpointKey(ep.base, ep.model),
@@ -600,12 +580,6 @@ export async function runTurn(userInput, conversation, opts) {
600
580
  });
601
581
  tokensTotal += response.tokens ?? 0;
602
582
  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
583
  promptTokensTotal += response.promptTokens ?? 0;
610
584
  promptMsTotal += response.promptMs ?? 0; // and prefill (the invisible wall-time cost)
611
585
  // Token meter (SPEC §5): teach the endpoint its real chars/token from the server's EXACT
@@ -792,9 +766,7 @@ export async function runTurn(userInput, conversation, opts) {
792
766
  opts.onSelfHeal?.("server_error", seen - CONTENT_LOOP_LIMIT + 1); // footer ↻ — breaking a stall
793
767
  conversation.user(`You've repeated the same step ${seen}× with the same result — that approach is not working. Do NOT ` +
794
768
  `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 ` +
769
+ `different command, tool, path, or angle; if a tool seems broken, work around it. If you already ` +
798
770
  `know the fix (you often do — you just described one), do it now.`);
799
771
  continue;
800
772
  }
@@ -817,8 +789,7 @@ export async function runTurn(userInput, conversation, opts) {
817
789
  ` (a) BREAK IT DOWN — split the stuck step into a smaller, concrete sub-action and do just that ` +
818
790
  `one thing now; or\n` +
819
791
  ` (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` +
792
+ `tool or command seems broken, work around it.\n` +
822
793
  `Do NOT reproduce your previous output, do NOT end the turn, and do NOT ask me how to proceed — ` +
823
794
  `decide and act on the smallest next concrete step.`);
824
795
  continue;