@0perator/operator 0.1.359 → 0.1.360-next.0

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.
Files changed (64) hide show
  1. package/dashboard/index.html +2 -2
  2. package/dist/autonomy/cloud-agent.js +2 -2
  3. package/dist/autonomy/headless.js +15 -6
  4. package/dist/autonomy/session-factory.js +2 -1
  5. package/dist/background/notices.js +1 -1
  6. package/dist/browser/session.js +7 -0
  7. package/dist/cli.js +94 -52
  8. package/dist/config/features.js +6 -5
  9. package/dist/config/persona.js +57 -40
  10. package/dist/config/settings.js +39 -55
  11. package/dist/engine/agent.js +72 -33
  12. package/dist/engine/aurora.js +24 -2
  13. package/dist/engine/compaction.js +27 -7
  14. package/dist/engine/decision-points.js +16 -4
  15. package/dist/engine/kv-slot.js +87 -0
  16. package/dist/engine/loop-guard.js +49 -18
  17. package/dist/engine/messages.js +8 -1
  18. package/dist/engine/progress-deadline.js +37 -0
  19. package/dist/engine/verify-gate.js +134 -9
  20. package/dist/enterprise/cli.js +13 -1
  21. package/dist/mcp/craft-server.js +5 -3
  22. package/dist/memory/live-progress.js +35 -6
  23. package/dist/permissions/policy.js +8 -0
  24. package/dist/permissions/signature.js +9 -0
  25. package/dist/products/artifact-library.js +47 -0
  26. package/dist/products/craft.js +58 -94
  27. package/dist/products/temple.js +230 -0
  28. package/dist/remote/host.js +28 -1
  29. package/dist/router/discovery.js +23 -6
  30. package/dist/router/models.js +29 -70
  31. package/dist/services/preflight.js +3 -41
  32. package/dist/session.js +121 -38
  33. package/dist/skills/catalogue.js +2 -0
  34. package/dist/skills/finder.js +1 -1
  35. package/dist/tools/background-result.js +26 -0
  36. package/dist/tools/chauffeur-native.js +6 -0
  37. package/dist/tools/craft.js +17 -6
  38. package/dist/tools/deferred.js +64 -30
  39. package/dist/tools/executor.js +4 -2
  40. package/dist/tools/paths.js +3 -3
  41. package/dist/tools/read-ledger.js +44 -0
  42. package/dist/tools/registry.js +218 -264
  43. package/dist/tools/sandbox.js +52 -39
  44. package/dist/tools/shell-context.js +5 -0
  45. package/dist/tools/shell-session.js +61 -29
  46. package/dist/tools/vision-gateway.js +79 -34
  47. package/dist/tools/wave-tools.js +2 -2
  48. package/dist/tools/wave2-tools.js +6 -6
  49. package/dist/ui/ArtifactPicker.js +2 -2
  50. package/dist/ui/Composer.js +9 -2
  51. package/dist/ui/StatusRule.js +1 -1
  52. package/dist/ui/modelPicker.js +1 -1
  53. package/dist/ui/nextStep.js +1 -0
  54. package/dist/ui/pending.js +10 -0
  55. package/dist/update.js +78 -4
  56. package/dist/util/retry.js +34 -0
  57. package/dist/util/slash.js +2 -1
  58. package/dist/vault/tool.js +3 -1
  59. package/mcp/powertools-toolbox.mjs +166 -1
  60. package/package.json +9 -13
  61. package/dashboard/README.md +0 -62
  62. package/dist/compose/client.js +0 -56
  63. package/mcp/README.md +0 -88
  64. package/mcp/powertools.md +0 -210
@@ -7,7 +7,6 @@ import { join, dirname } from "node:path";
7
7
  import { operatorPath, globalMemoriesPath } from "./home.js";
8
8
  import { renderHarnessContext } from "./operator-harness.js";
9
9
  import { renderToolCatalogue, registry } from "../tools/registry.js";
10
- import { NATIVE_CORE_TOOLS } from "../tools/deferred.js";
11
10
  import { isFeatureEnabled } from "./features.js";
12
11
  import { renderSkillsIndex } from "./skills-index.js";
13
12
  import { decisionPointsEnabled } from "../engine/decision-points.js";
@@ -15,6 +14,7 @@ import { SUBAGENT_ROLES, SUBAGENT_TOOL_DENY } from "../engine/grandmaster.js";
15
14
  import { LESSONS_HEADING, isLessonHeading, mergeLessons, parseLessonTag, reinforcedRules, splitLessons } from "../selfimprove/lessons.js";
16
15
  import { redactSecrets } from "../engine/redact.js";
17
16
  import { fitWhole, splitItems, splitSections } from "./memory-sections.js";
17
+ import { freshHandoff, withoutSettled } from "../memory/live-progress.js";
18
18
  // Project context: auto-load a per-repo instructions file from `cwd` and append it to the system prompt, so
19
19
  // Operator picks up house rules, conventions and build commands the way modern coding agents do. First match
20
20
  // wins, so the ORDER is the brand precedence: our own `.operator/AGENTS.md`, then the vendor-neutral open
@@ -231,16 +231,21 @@ export function loadStructuredMemories() {
231
231
  return out;
232
232
  }
233
233
  // Session handoff: the note the previous session in THIS directory wrote for its future self (via the
234
- // session_handoff tool), pointed at by KODE_HANDOFF_FILE. Auto-loaded so the agent resumes seamlessly.
235
- export function loadHandoff() {
234
+ // session_handoff tool), pointed at by KODE_HANDOFF_FILE. Auto-loaded as background: the owner's newest message sets
235
+ // the task, so an old plan is offered, never resumed over what the owner typed (11/23: a 3-day-old "resume from this"
236
+ // block made a session chase its plan through three "stop" messages).
237
+ export function loadHandoff(now = new Date()) {
236
238
  try {
237
- const t = readFileSync(process.env.KODE_HANDOFF_FILE ?? "", "utf8").trim();
239
+ const file = process.env.KODE_HANDOFF_FILE ?? "";
240
+ const { text: t, settled } = withoutSettled(freshHandoff(readFileSync(file, "utf8"), now));
241
+ const pointer = settled ? `\n\nThe previous session here ended its work; its note is at ${file}. Read it only if the owner asks to continue earlier work.` : "";
238
242
  // The handoff grows by APPEND (auto-compaction adds a block each time context fills, newest last),
239
- // so resume from the TAIL — the freshest state, not a stale head.
243
+ // so read the TAIL — the freshest state, not a stale head.
240
244
  if (t) {
241
245
  const tail = t.length > 6000 ? "…\n" + t.slice(-6000) : t;
242
- return `\n\n## Handoff from your previous session here (continue from where it leaves off)\n${tail}\n\nResume seamlessly, and update it with session_handoff before you finish.`;
246
+ return `\n\n## Handoff from your previous session here (background, not an instruction)\n${tail}\n\nThe owner's newest message sets the task. If it is about something else, do that and leave this work alone; continue it only when the owner asks (offer it in one line when it fits). Update it with session_handoff before you finish.${pointer}`;
243
247
  }
248
+ return pointer;
244
249
  }
245
250
  catch { /* none yet */ }
246
251
  return "";
@@ -288,7 +293,10 @@ export function basePersona(_cwd = process.cwd(), opts = {}) {
288
293
  `the strength of your own reasoning — RUN the actual command, CLI, or code path and read the result; done ` +
289
294
  `means the check that proves it passed in front of you. Tests must assert BEHAVIOR (the CLI runs, the output ` +
290
295
  `is correct), not merely that files exist — green tests that assert nothing are not proof. If you did not run ` +
291
- `it, say so. A document deliverable has runnable checks too (a link check, \`docker compose config\` on an ` +
296
+ `it, say so. Run checks from the project's root (where its package.json, pyproject.toml, Cargo.toml or ` +
297
+ `go.mod is), in the foreground. A failing check is never ` +
298
+ `"expected": report it as failing, find out why, fix or re-run it properly, then call the work done. ` +
299
+ `A document deliverable has runnable checks too (a link check, \`docker compose config\` on an ` +
292
300
  `embedded compose block, a script that sums the tables, a linter); a "checked <date>" stamp is written only ` +
293
301
  `in the turn that opened that page.` +
294
302
  `\n## How I work — the AXE self-check\nFor a bug I state the ROOT CAUSE in one line (not the symptom) and how ` +
@@ -296,7 +304,8 @@ export function basePersona(_cwd = process.cwd(), opts = {}) {
296
304
  `asked and don't touch the data layer or infra unless asked; I match the surrounding code — naming, idioms, ` +
297
305
  `comment density. I record the non-obvious WHY in the repo's _ai-docs/, and commit clean: a conventional ` +
298
306
  `\`type(scope): subject\` with explicit paths (never a blanket add in a shared checkout) and no AI / ` +
299
- `Co-Authored-By / Claude-Session trailers.` +
307
+ `Co-Authored-By / Claude-Session trailers. Before calling work done I ask: can it be smaller and ` +
308
+ `more direct, with nothing between the question and the answer? If so, I cut first.` +
300
309
  `\n## This machine\nWorking dir and scratch dir: named in the session context at the top of the conversation.` +
301
310
  `\nScratch dir (also \`$OPERATOR_SCRATCH\` in every shell) — temporary scripts, probe ` +
302
311
  `output, downloads to inspect, intermediate files: ALWAYS here, never /tmp and never the repo root. It is ` +
@@ -311,7 +320,7 @@ export function basePersona(_cwd = process.cwd(), opts = {}) {
311
320
  `\n## Don't starve the serving model — decode is RAM-bound\nLoading a large model on this box (a multi-GB ` +
312
321
  `MLX/FLUX/LLM checkpoint, a big \`ml.load\`) pushes it into swap and collapses your decode to ~1 token/sec: use ` +
313
322
  `another node, process in shards, or warn the owner first. Media goes ONLY through the tools (\`image_generate\`, ` +
314
- `\`video_generate\`, \`image_analyze\`, \`video_analyze\`) — never curl a broker or decode base64 yourself. A ` +
323
+ `\`video_generate\`, \`image_analyze\`, \`video_analyze\`; video ones on demand) — never curl a broker or decode base64 yourself. A ` +
315
324
  `screenshot the owner shares is snapshotted by the engine: \`image_analyze\` the path exactly as given, one call ` +
316
325
  `per DISTINCT path. If your own output crawls, STOP and say so rather than pushing through.` +
317
326
  // Tool-promotion sections below prime reflexive tool use; a small/weak model (lean) does better with the
@@ -321,7 +330,7 @@ export function basePersona(_cwd = process.cwd(), opts = {}) {
321
330
  `generating, analyze YOUR OWN output against the request; on a mismatch refine and regenerate — never hand ` +
322
331
  `over a mismatch. (3) \`image_generate\` / \`video_generate\` make NEW photoreal content; they do not copy an ` +
323
332
  `app UI, screen recording, chart or demo — "recreate this screen recording / UI / slide" is a screen-record, ` +
324
- `build-the-UI, or compose.casa-animation task; say so. (4) In an interactive turn, OPEN what you made for the ` +
333
+ `build-the-UI, or hosted-artifact (\`artifact_create\`, on demand) task; say so. (4) In an interactive turn, OPEN what you made for the ` +
325
334
  `owner (bash \`open <url-or-path>\`) and put the clickable link in your reply; skip that in a headless batch.` +
326
335
  `\n## The media pipeline — what you ACTUALLY have (don't invent tools)\nThree scale-to-zero fleet workers, ` +
327
336
  `nothing else — never offer ComfyUI, SDXL, Juggernaut/RealVis/EpicRealism, FLUX.1-dev/pro, Midjourney or a ` +
@@ -329,9 +338,9 @@ export function basePersona(_cwd = process.cwd(), opts = {}) {
329
338
  `prompt is rewritten richer) plus a larger \`size\`. LIKENESS: a FACE photo as \`reference\` routes to the ` +
330
339
  `identity broker and keeps that exact person; if the result's \`axe_identity\` says \`identity_applied\` false ` +
331
340
  `or a weak \`fidelity_note\`, SAY so — never pass a look-alike off as a match. VIDEO: \`video_generate\` ` +
332
- `(LTX-Video); \`reference_image\` makes that image the FIRST FRAME. VISION: \`image_analyze\` / ` +
341
+ `(on demand; LTX-Video); \`reference_image\` makes that image the FIRST FRAME. VISION: \`image_analyze\` / ` +
333
342
  `\`video_analyze\`; a document (PDF, DOCX, XLSX, PPTX) is read as TEXT, every page.` +
334
- `\n## Deep research — \`deep_research\` (cited, multi-source)\nFor a comparison, a state-of-the-art survey ` +
343
+ `\n## Deep research — \`deep_research\` (on demand; cited, multi-source)\nFor a comparison, a state-of-the-art survey ` +
335
344
  `or sourced background use \`deep_research\` (planned angles, inline citations); a single lookup is faster ` +
336
345
  `with plain \`web_search\`.`)) +
337
346
  // 96e159b swallowed the OPENING line of the section below ("## Running scripts — …\nFor anything more
@@ -372,7 +381,7 @@ export function basePersona(_cwd = process.cwd(), opts = {}) {
372
381
  `Serialize only when one call's output feeds the next. Read several files with ONE read_files call.` +
373
382
  `\n## Long-running commands\nBuilds, servers, watchers, test suites and batches go to shell_background from ` +
374
383
  `the start; a finished job announces itself at your next turn, so do NOT poll bash_output in a loop.` +
375
- `\n## Downloading files\nUse download_file, never curl/wget, and NEVER say a file is downloaded until its ` +
384
+ `\n## Downloading files\nUse download_file (on demand), never curl/wget, and NEVER say a file is downloaded until its ` +
376
385
  `completion notice says so; a 0-byte file, an HTML page with an .iso/.zip name or a failed hash is a FAILURE ` +
377
386
  `to report and fix, not to retry blindly.` +
378
387
  `\n## Finding things\nContent: the search tool scoped to a directory — never bash \`grep -r\` / \`rg\` / ` +
@@ -380,35 +389,46 @@ export function basePersona(_cwd = process.cwd(), opts = {}) {
380
389
  `2-3 most likely directories first, batched in ONE message.\nA FLEET HOST / server name (acropolis, jl1, jla, …): ` +
381
390
  `\`~/.ssh/config\` + \`ssh <name> 'hostname; uptime'\`, then \`gh repo view axetechnologies/<name>\`, then fleet ` +
382
391
  `docs — never ripgrep the home directory.\nA project or file by NAME outside the working directory: find_files ` +
383
- `first; if the index is unavailable, \`ls ~\` for the REAL top-level folders (~/Axwell, ~/.axe/repos, ~/Desktop), ` +
392
+ `(on demand) first; if the index is unavailable, \`ls ~\` for the REAL top-level folders (~/Axwell, ~/.axe/repos, ~/Desktop), ` +
384
393
  `then a BOUNDED find on a SPECIFIC directory (\`-maxdepth 3 … | head -80\`, timeout_ms 60000) — never over ~ or /. ` +
385
394
  `Report not-found only after this real search, and say exactly where you looked.` +
386
- (opts.lean ? "" : (`\n## HTTP requests (curl)\nCall an endpoint with http_request (any method, headers, body); web_fetch READS a ` +
395
+ (opts.lean ? "" : (`\n## HTTP requests (curl)\nCall an endpoint with http_request (on demand; any method, headers, body); web_fetch READS a ` +
387
396
  `page, web_search FINDS one. They run natively, not through the shell, so they work when bash is failing — ` +
388
397
  `never conclude a URL is unreachable without trying http_request. curl via bash is fine for anything special.` +
389
398
  `\n## Web search — SearXNG (auto-managed via Docker)\nweb_search runs a local SearXNG that Operator stands up ` +
390
399
  `in Docker on demand. If it reports SearXNG unreachable, start Docker and retry (/services shows it) — an ` +
391
400
  `"unavailable" web_search means "ensure Docker is running", not "the web is unreachable".` +
392
- `\n## Skills — reuse the AXE catalogue\nBefore building a non-trivial capability from scratch, skill_list ` +
393
- `"<query>" the 60k+ playbooks and skill_fetch the one that fits; skill_save keeps a new one.` +
401
+ `\n## Skills — reuse the AXE catalogue\nBefore building a non-trivial capability from scratch, search the ` +
402
+ `60k+ playbooks (skill_list) and load the one that fits (skill_fetch); skill_save keeps a new one. All on demand.` +
394
403
  `\n## Documents & PDFs — a downloadable FILE vs a hosted page\nA PDF / report / deck as a FILE to open or send ` +
395
- `→ \`document_generate\` (renders on every box — never pandoc/wkhtmltopdf/chrome, never "no PDF tools ` +
396
- `installed"). A shareable hosted PAGE/URL → \`artifact_create\` (compose.casa).` +
397
- `\n## AXE surfaces — disambiguate "compose"\n"compose.casa", "composer", "a design/artifact canvas" or "build ` +
398
- `an artifact/design" mean the AXE compose.casa surface: use the compose tools (\`compose_create\` / ` +
399
- `\`compose_canvas\` / \`compose_get\` / \`compose_list\`, loaded when the owner turns MCP on with \`/mcp on\`) or ` +
400
- `\`/artifacts\`; if they aren't loaded, say compose.casa needs MCP enabled — never scaffold a docker-compose.yml ` +
401
- `for an ARTIFACT request. "docker compose", "containerize this", a multi-container stack → Docker Compose as ` +
402
- `usual. Bare "compose": artifact/design intent → compose.casa, containers intent → Docker; genuinely unclear → ask.`)) +
404
+ `→ \`document_generate\` (on demand; renders on every box — never pandoc/wkhtmltopdf/chrome, never "no PDF tools ` +
405
+ `installed"). A shareable hosted PAGE/URL → \`artifact_create\`.` +
406
+ `\n## AXE surfaces — artifacts, one surface for every kind\nA page, dashboard, deck, doc, board, interactive app, image or video ` +
407
+ `to share → \`artifact_create\` (on demand; content and/or local file \`paths\`); it returns the 0perator.co share link — ` +
408
+ `put it in your reply. The owner's library is \`/artifacts\`. "compose", "composer", "a design/artifact canvas" ` +
409
+ `or "build an artifact/design" mean this, never a docker-compose.yml. "docker compose", "containerize this", a ` +
410
+ `multi-container stack → Docker Compose as usual; genuinely unclear → ask. Other MCP tools load when the owner ` +
411
+ `turns MCP on with \`/mcp on\`.`)) +
403
412
  `\n## Git\nRead repo state with git_status (one structured read) — don't loop raw \`git status\`/\`git add\`; ` +
404
- `a clean tree is success. Commit via git_command (explicit paths, conventional message) or checkpoint (stages ` +
413
+ `a clean tree is success. Commit via git_command (explicit paths, conventional message) or checkpoint (on demand; stages ` +
405
414
  `only the working directory's subtree; \`paths\` for specific files).` +
406
- `\n## Scratchpad & handoff\nPrivate working notes and intermediate results go in the scratchpad tool, not the ` +
407
- `workspace or your reply. Before you finish a substantial task, or when context runs low, call ` +
408
- `session_handoff with what you did, the state and next steps — the next session here loads it, so write it ` +
409
- `for your future self.` +
415
+ `\n## Scratchpad & handoff\nPrivate working notes and intermediate results go in the scratchpad, not the ` +
416
+ `workspace or your reply. Before you finish a substantial task, or when context runs low, write a session ` +
417
+ `handoff: what you did, the state and next steps — the next session here loads it, so write it for your ` +
418
+ `future self. Both tools (scratchpad, session_handoff) are on demand.` +
410
419
  subagentsSection(opts));
411
420
  }
421
+ /** Where basePersona stops being identity and starts being operating rules. */
422
+ export const HARNESS_RULES_HEADING = "\n## Fix what you find — don't stop to ask\n";
423
+ /** basePersona's operating rules without its identity: everything from the first rule heading on (verify before
424
+ * done, the self-check, narration, the task list, decision points, sub-agents…). A SOUL.md or settings.systemPrompt
425
+ * replaces WHO Operator is; it must never remove HOW the harness works (11/23: on a box with a SOUL.md no session
426
+ * had "verify before you claim done", and a model reported unchecked work as verified). */
427
+ export function harnessRules(cwd = process.cwd(), opts = {}) {
428
+ const p = basePersona(cwd, opts);
429
+ const i = p.indexOf(HARNESS_RULES_HEADING);
430
+ return i < 0 ? "" : p.slice(i);
431
+ }
412
432
  // Harness behavior, not identity: a SOUL.md replaces basePersona, so composeSystemPrompt appends this to it too
413
433
  // (10/31: on JL2 Cortana never saw the rule). Static per session — cache-safe.
414
434
  function subagentsSection(opts) {
@@ -417,7 +437,7 @@ function subagentsSection(opts) {
417
437
  `you decide to (never announce it without the call; its description carries the brief format and rules) and ` +
418
438
  `tell the owner who you are sending and why. While they run, do what does not depend on them and never redo a ` +
419
439
  `step an agent is still working on. When a report or a STUCK notice arrives, check what the agent produced ` +
420
- `against its Done line before you relay it; steer a stuck agent (message_agent) or stop it (stop_agent) and do ` +
440
+ `against its Done line before you relay it; steer a stuck agent (message_agent) or stop it (stop_agent), both on demand, and do ` +
421
441
  `its step yourself. Every turn ends with one status line per running agent and the owner's options.`
422
442
  : "";
423
443
  }
@@ -513,25 +533,22 @@ export function composeSystemPrompt(o) {
513
533
  const lean = o.lean === true;
514
534
  const interactive = o.interactive === true;
515
535
  const custom = o.settings.systemPrompt ?? loadSoul();
516
- // A SOUL.md / settings.systemPrompt REPLACES basePersona (JL2 runs one), so the decision-points and sub-agent
517
- // rules — harness behavior, not identity — are appended to it here; basePersona already carries them inline.
518
- const identity = custom
519
- ? custom + decisionPointsSection({ interactive, lean, decisionPoints: o.settings.decisionPoints }) + subagentsSection({ interactive })
520
- : basePersona(cwd, { ctxTokens: o.ctxTokens, interactive, lean, decisionPoints: o.settings.decisionPoints });
536
+ // A SOUL.md / settings.systemPrompt replaces the identity only: the operating rules follow it, the same bytes
537
+ // basePersona carries (decision points and sub-agents included).
538
+ const personaOpts = { ctxTokens: o.ctxTokens, interactive, lean, decisionPoints: o.settings.decisionPoints };
539
+ const identity = custom ? custom + harnessRules(cwd, personaOpts) : basePersona(cwd, personaOpts);
521
540
  // Local-skills index (name: trigger, 4k cap) — the model must KNOW skills exist without spending a
522
541
  // skill_list call; bodies stay pull-on-demand via skill_fetch. Skipped in lean (small-ctx) mode like
523
542
  // the other heavy sections. Appended exactly like renderToolCatalogue, right before it.
524
543
  const skillsIdx = lean ? "" : renderSkillsIndex();
525
544
  // `deferredTools`: the same split the Session advertises (tools/deferred.ts) — fixed for the session, so cache-safe.
526
- const deferred = isFeatureEnabled("deferredTools", o.settings)
527
- ? new Set([...registry.keys()].filter((n) => !NATIVE_CORE_TOOLS.includes(n)))
528
- : undefined;
545
+ const deferred = isFeatureEnabled("deferredTools", o.settings);
529
546
  return (identity +
530
547
  loadProjectContext(cwd) +
531
548
  (lean ? "" : loadStructuredMemories() + loadMemories(cwd)) +
532
549
  renderHarnessContext(cwd) +
533
550
  (lean ? LEAN_NOTE : loadHandoff()) +
534
- (skillsIdx ? `\n\n## Skills installed locally (skill_fetch <name> loads one; skill_fetch <name> <file_path> reads its references/templates/scripts)\n${skillsIdx}` : "") +
551
+ (skillsIdx ? `\n\n## Skills installed locally (skill_fetch, on demand: <name> loads one; skill_fetch <name> <file_path> reads its references/templates/scripts)\n${skillsIdx}` : "") +
535
552
  renderToolCatalogue(undefined, { lean, deferred }) +
536
553
  (interactive ? renderEmbodimentGuide(!!o.settings.computer?.enabled, o.chauffeurReady ?? !!o.settings.mcp) : ""));
537
554
  }
@@ -3,7 +3,6 @@
3
3
  // default. Never throws — a missing or malformed file just falls back to defaults, same as an env
4
4
  // var that was never set.
5
5
  import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
6
- import { totalmem } from "node:os";
7
6
  import { dirname } from "node:path";
8
7
  import { operatorPath } from "./home.js";
9
8
  import { applyManagedPolicy, loadManagedPolicy } from "./managed.js";
@@ -42,13 +41,11 @@ const DEFAULTS = {
42
41
  // Fleet nodes with ~/.operator/runtime/server.json dynamically override this at startup via the
43
42
  // gateway-discovery path in cli.tsx — single source of truth, enterprise-safe for both postures.
44
43
  aurora: { base: "http://127.0.0.1:8097", ctxWindow: 1000000, model: "aurora-code-1" },
45
- // HA hot-standby: JL2 (64GB) serving Aurora @ 300K on the LAN — task #50, replaces the old
46
- // dolphin3-tools:8b "8k trap". Same model + same real window as primary, so a failover holds any live
47
- // session instead of truncating it. Point elsewhere / omit to disable.
48
- failover: { base: "http://192.168.1.146:8097", ctxWindow: 1000000, model: "aurora-code-1" },
44
+ // No built-in standby: a deployment names its own in settings.json (endpoints.failover — same model and the
45
+ // same real window as the primary, so a failover holds a live session instead of truncating it).
49
46
  },
50
47
  modelMode: "local", // default: this node uses its own local model (endpoints.aurora); set "aurora" to use the shared fleet
51
- fleet: { auroraNodes: ["http://192.168.1.103:8097", "http://192.168.1.146:8097"] }, // JL1, JL2 — the live Aurora serving nodes (priority order)
48
+ fleet: { auroraNodes: [] }, // a deployment's own serving nodes, in priority order — set in settings.json; none are built in
52
49
  maxTokens: 32768, // generous per-reply output cap — 1M ctx has ample room; clampMaxTokens still trims
53
50
  // to the space left after the prompt so a reply never overflows. A small cap (was
54
51
  // 2048) forced the model to truncate + work around; this lets full files/answers land.
@@ -62,17 +59,17 @@ const DEFAULTS = {
62
59
  ui: { fullscreen: false, reasoning: "think" }, // inline by default; reasoning "think" = the model's thoughts stream dim above the answer every turn (the owner wants to see the process); set "off" for spinner-only, or /think to toggle per-session
63
60
  permissions: { mode: "gated" }, // ask-by-default: the user decides Allow/Deny; bypass is the opt-out
64
61
  telemetry: { enabled: true }, // local-only metrics (silent JSONL); remote sink opt-in via KODE_TELEMETRY_URL
65
- sandbox: { mode: "off" }, // no isolation by default — enterprise turns it on (KODE_SANDBOX / settings)
62
+ sandbox: { mode: "off" }, // the local owner's baseline: unconfined (unrestricted+admin, no managed policy — AGENTS.md: the only floor is fleet integrity). loadSettings RAISES this to "workspace" (OS write-floor) for an ENFORCED seat — a managed policy, a narrowed tier, or unrestricted disabled — unless sandbox is set explicitly. KODE_SANDBOX / settings.sandbox.mode always win; "strict" also cuts the network.
66
63
  computer: { enabled: true }, // computer control ON (actions ask outside Autonomous mode; bg agents denied; macOS TCC on top). Off: KODE_COMPUTER=0, settings.json or managed policy
67
64
  sessionSearch: { enabled: true }, // /sessions + session_search over Operator's and agents.md providers' sessions; per-provider switches in sources; KODE_SESSION_SEARCH=0 to disable
68
65
  search: {}, // web_search backend unset by default; set search.searxngUrl / search.autopilotUrl or the env vars
69
- // Service lever — JL1 defaults. On a machine without these launchd agents every start step just fails
66
+ // Service lever. On a machine without these launchd agents every start step just fails
70
67
  // harmlessly and the boot screen falls back to the manual hint (autostart is best-effort by design).
71
68
  services: {
72
69
  // co.0perator.* since 2026-10-28; legacyLabels keeps a box that still runs the old job self-healing.
73
70
  aurora: { autostart: true, launchdLabel: "co.0perator.gateway", plistPath: "~/Library/LaunchAgents/co.0perator.gateway.plist", legacyLabels: ["ai.operator.gateway"], waitSec: 90 },
74
71
  autopilot: { autostart: true, launchdLabel: "com.axe.autopilot", plistPath: "~/Library/LaunchAgents/com.axe.autopilot.plist", url: "http://127.0.0.1:9333" },
75
- vision: { autostart: false, launchdLabel: "co.0perator.vision", plistPath: "~/Library/LaunchAgents/co.0perator.vision.plist", legacyLabels: ["axe.vision-bot"], url: "http://127.0.0.1:7788", remoteUrl: "http://192.168.1.103:8095" },
72
+ vision: { autostart: false, launchdLabel: "co.0perator.vision", plistPath: "~/Library/LaunchAgents/co.0perator.vision.plist", legacyLabels: ["axe.vision-bot"], url: "http://127.0.0.1:7788" },
76
73
  stopOnExit: { searxng: true }, // aurora/autopilot are shared + never stopped; only the SearXNG container is
77
74
  },
78
75
  // MOA (2026-10-31, James): a planner/specialist team, Manus-style — Cortana plans, delegates each step to a
@@ -246,53 +243,22 @@ function applyEnv(s) {
246
243
  return out;
247
244
  }
248
245
  /** The proactive-compaction trigger to hand runTurn: settings.compaction.threshold (env-overridden in
249
- * loadSettings), clamped to a sane [0.3, 0.95]. Out-of-range or unset → undefined, so runTurn keeps its
250
- * own 0.85 default. Kept here (not inline at the call sites) so the CLI, headless, and ACP surfaces all
251
- * resolve it identically. */
246
+ * loadSettings), accepted in [0.3, 0.95]. Out-of-range or unset → undefined, so the engine derives it from the
247
+ * served window (compaction.ts defaultThreshold: 0.92 wherever the window leaves room for the reply and the
248
+ * summarize request). Kept here so the CLI, headless, and ACP surfaces all resolve it identically. */
252
249
  export function compactionThreshold(s) {
253
250
  const t = s.compaction?.threshold;
254
251
  return typeof t === "number" && t >= 0.3 && t <= 0.95 ? t : undefined;
255
252
  }
256
- /** A RAM-aware SAFE default compaction ceiling (pure; exported for tests). The context window is a TOKEN
257
- * limit, but the real failure is a MEMORY limit: model weights + KV cache must fit in RAM or macOS swaps and
258
- * decode collapses to ~0 tok/s (measured 2026-10-01 on a 64GB box: context reached ~191K tok → 7.6GB swap →
259
- * decode 26→2.7→0 tok/s). The %-of-window threshold can't see that cliff (it's the same % regardless of RAM),
260
- * so we cap effective context by a budget derived from the box's RAM. Reserve ~28GB (≈20GB model + OS/app/KV
261
- * overhead), then ~3500 tok/GB of what's left — deliberately BELOW the measured cliff (errs toward compacting
262
- * a little early, which only costs some fidelity that retrieval reclaims; the alternative is the swap stall).
263
- * Clamped to [8000, 0.85·window], so on a small window it never fires before the threshold path would. */
264
- export function defaultCompactionCeiling(totalBytes, windowTokens) {
265
- const totalGB = totalBytes / 2 ** 30;
266
- const budgetGB = Math.max(0, totalGB - 28);
267
- const raw = Math.floor(budgetGB * 3500);
268
- const cap = Math.floor((windowTokens > 0 ? windowTokens : 0) * 0.85);
269
- return Math.max(8000, Math.min(raw, cap));
270
- }
271
- // Per-mode default ceilings (tokens), applied when no explicit setting/env is present, then clamped by the
272
- // RAM-aware safe ceiling (defaultCompactionCeiling) so neither can push the KV cache past the box's swap cliff.
273
- // Interactive stays tight because decode is context-bound (measured ~45→9→5 tok/s as the live context grows), so
274
- // a small live context keeps every owner-facing reply fast; retrieval reclaims what compaction summarizes out.
275
- // Autonomy rides high — just under the 64GB swap cliff (~126k) — because an unattended run isn't waiting on
276
- // decode and fewer compactions means it holds the thread across a long multi-step mission instead of thrashing.
277
- const INTERACTIVE_DEFAULT_CEILING = 24_000;
278
- const AUTONOMY_DEFAULT_CEILING = 100_000;
279
- /** The absolute-token proactive-compaction ceiling to hand runTurn, resolved PER SESSION MODE — the one knob
280
- * that stops us trading reign for speed. Interactive and autonomy each have their own explicit override
281
- * (`compaction.ceilingTokens` / `compaction.autonomyCeilingTokens`, env-overridden in loadSettings) validated
282
- * to a sane floor of 8000; the other mode's override is deliberately ignored, so a tight interactive value can
283
- * no longer throttle an unattended build into a compaction-thrash loop (the 0.1.178 fix). When a mode has no
284
- * explicit override we apply its per-mode default (above), clamped by the RAM-aware safe ceiling
285
- * (defaultCompactionCeiling) so a large window can't grow the KV cache into swap (the "88 tokens in 6 minutes"
286
- * stall). `windowTokens` is the active endpoint's context window; pass 0 if unknown (then only the floor path
287
- * applies). Resolved here so CLI (interactive), headless/autonomy, and ACP surfaces read it identically. */
288
- export function compactionCeilingTokens(s, windowTokens = 0, mode = "interactive") {
253
+ /** The absolute-token proactive-compaction ceiling to hand runTurn: the owner's own setting for this session mode
254
+ * (`compaction.ceilingTokens` / `compaction.autonomyCeilingTokens`, env-overridden in loadSettings; 8000 is the
255
+ * floor), or none. There is no default ceiling (2026-11-24): the 24K interactive / 100K autonomy defaults and their
256
+ * RAM clamp were tuned to one model on one box and compacted a 262K window at ~50K; the window-derived threshold is
257
+ * the default trigger for every model. The other mode's setting is ignored, so a tight interactive value cannot
258
+ * throttle an unattended build (the 0.1.178 fix). */
259
+ export function compactionCeilingTokens(s, mode = "interactive") {
289
260
  const explicit = mode === "autonomy" ? s.compaction?.autonomyCeilingTokens : s.compaction?.ceilingTokens;
290
- if (typeof explicit === "number" && Number.isFinite(explicit) && explicit >= 8000)
291
- return Math.floor(explicit);
292
- const target = mode === "autonomy" ? AUTONOMY_DEFAULT_CEILING : INTERACTIVE_DEFAULT_CEILING;
293
- if (windowTokens >= 8000)
294
- return Math.min(target, defaultCompactionCeiling(totalmem(), windowTokens));
295
- return undefined;
261
+ return typeof explicit === "number" && Number.isFinite(explicit) && explicit >= 8000 ? Math.floor(explicit) : undefined;
296
262
  }
297
263
  /** The per-turn WALL-CLOCK budget (ms) to hand runTurn — the only bound on TIME, the brake on hour-long turns.
298
264
  * settings.autonomy.maxTurnWallClockSec, env KODE_TURN_MAX_WALLCLOCK_SEC wins; 0/unset ⇒ undefined (no cap).
@@ -357,7 +323,7 @@ export function rcAutostart(s) {
357
323
  /** Load operator settings: built-in defaults <- ~/.axe/operator/settings.json (override path via
358
324
  * KODE_TSI_SETTINGS) <- env vars. Never throws. */
359
325
  /** Resolve the model MODE into the concrete `endpoints` chain the router consumes. "aurora" points the
360
- * primary + failover at the shared fleet Aurora nodes (JL1/JL2 hybrid). "local" (default) keeps this
326
+ * primary + failover at the shared fleet Aurora nodes. "local" (default) keeps this
361
327
  * node's own primary and, only when no failover is configured, backstops with the first DIFFERENT fleet
362
328
  * node so a node with no local model still degrades to the fleet. Pure + backward-compatible: with no
363
329
  * modelMode/fleet and an explicit failover already set, it returns the settings unchanged. The model id +
@@ -448,6 +414,19 @@ export function applySeat(s, seat) {
448
414
  return out;
449
415
  }
450
416
  export function setActiveSeat(seat) { activeSeat = seat; }
417
+ /** The OS-sandbox floor is a PRODUCT / enterprise default, NOT the local owner's. An unrestricted admin seat
418
+ * with no managed policy in force is the owner's private system — full FS / network / ssh, AGENTS.md: the only
419
+ * floor is fleet integrity — so it stays unconfined ("off"). Any ENFORCED seat — a managed policy, a narrowed
420
+ * tier, or unrestricted disabled — gets the "workspace" write-floor by default. An explicit sandbox mode
421
+ * (user file / env / managed policy, incl. an explicit "off") always wins and is never overridden. Pure. */
422
+ export function applySandboxFloor(s, sandboxPinned) {
423
+ if (sandboxPinned || s.sandbox.mode !== "off")
424
+ return s; // set explicitly, or already raised
425
+ const tier = s.permissions.tier ?? "admin";
426
+ const managedInForce = !!s.managed && s.managed.status === "ok";
427
+ const ownerPrivate = s.unrestricted === true && tier === "admin" && !managedInForce;
428
+ return ownerPrivate ? s : { ...s, sandbox: { ...s.sandbox, mode: "workspace" } };
429
+ }
451
430
  export function loadSettings() {
452
431
  const file = readSettingsFile(settingsPath());
453
432
  // structuredClone the base so a returned settings object never aliases the module-level DEFAULTS —
@@ -459,9 +438,11 @@ export function loadSettings() {
459
438
  const flywheelPinned = (isPlainObject(file) && isPlainObject(file.selfImprove) && typeof file.selfImprove.flywheel === "boolean") ||
460
439
  process.env.KODE_SELFIMPROVE !== undefined ||
461
440
  typeof managed.policy?.selfImprove?.flywheel === "boolean";
462
- const fv = isPlainObject(file) && isPlainObject(file.services) && isPlainObject(file.services.vision) ? file.services.vision : undefined;
463
- const visionUrlPinned = !!fv && (typeof fv.url === "string" || typeof fv.remoteUrl === "string");
464
- let out = applyManagedPolicy({ ...merged, explicit: { flywheel: flywheelPinned, visionUrl: visionUrlPinned } }, managed);
441
+ // Did the owner/org set the sandbox mode anywhere? If so it wins over the contextual floor below (applySandboxFloor).
442
+ const sandboxPinned = (isPlainObject(file) && isPlainObject(file.sandbox) && typeof file.sandbox.mode === "string") ||
443
+ ["off", "workspace", "strict"].includes((process.env.KODE_SANDBOX ?? "").toLowerCase()) ||
444
+ typeof managed.policy?.sandbox?.mode === "string";
445
+ let out = applyManagedPolicy({ ...merged, explicit: { flywheel: flywheelPinned } }, managed);
465
446
  if (managed.info.status === "invalid" && !warnedManaged) {
466
447
  warnedManaged = true;
467
448
  process.stderr.write(`[operator] managed policy ${managed.info.path} is not usable (${managed.info.errors.join("; ")}) — running locked down (read-only) until it is fixed\n`);
@@ -471,6 +452,9 @@ export function loadSettings() {
471
452
  out = { ...out, selfImprove: { ...out.selfImprove, flywheel: false } };
472
453
  if (activeSeat)
473
454
  out = applySeat(out, activeSeat);
455
+ // Raise the OS-sandbox floor for an enforced seat (never the unrestricted local owner). After applySeat so
456
+ // the tier is final; before resolveModelMode (which only touches endpoints).
457
+ out = applySandboxFloor(out, sandboxPinned);
474
458
  return resolveModelMode(out);
475
459
  }
476
460
  /** Persist a partial settings patch onto whatever's on disk (deep-merged, file values win over