@0perator/operator 0.1.222 → 0.1.261

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 (110) hide show
  1. package/README.md +6 -5
  2. package/dashboard/server.mjs +1 -1
  3. package/dist/acp/agent.js +320 -53
  4. package/dist/acp/auth.js +44 -0
  5. package/dist/acp/config-options.js +34 -0
  6. package/dist/acp/prompt.js +41 -0
  7. package/dist/acp/run.js +116 -10
  8. package/dist/acp/tool-map.js +48 -0
  9. package/dist/auth/byo.js +125 -0
  10. package/dist/auth/client.js +12 -6
  11. package/dist/auth/commands.js +71 -3
  12. package/dist/auth/identity.js +136 -0
  13. package/dist/auth/store.js +7 -5
  14. package/dist/autonomy/board.js +3 -2
  15. package/dist/autonomy/cron.js +332 -0
  16. package/dist/autonomy/delegate.js +168 -0
  17. package/dist/autonomy/dream.js +1 -1
  18. package/dist/autonomy/index.js +16 -2
  19. package/dist/autonomy/media-robot.js +137 -0
  20. package/dist/autonomy/profile.js +77 -0
  21. package/dist/autonomy/routines.js +5 -4
  22. package/dist/autonomy/session-factory.js +19 -10
  23. package/dist/background/index.js +8 -1
  24. package/dist/browser/cdp.js +266 -0
  25. package/dist/browser/session.js +286 -0
  26. package/dist/cli.js +207 -106
  27. package/dist/compose/client.js +56 -0
  28. package/dist/config/brand.js +3 -3
  29. package/dist/config/home.js +70 -0
  30. package/dist/config/managed.js +230 -0
  31. package/dist/config/persona.js +243 -21
  32. package/dist/config/scaffold.js +142 -0
  33. package/dist/config/settings.js +87 -20
  34. package/dist/config/skills-index.js +175 -0
  35. package/dist/consolidation/scheduler.js +10 -7
  36. package/dist/consolidation/sleep.js +17 -3
  37. package/dist/engine/agent.js +231 -21
  38. package/dist/engine/aurora.js +79 -14
  39. package/dist/engine/batch-scheduler.js +128 -0
  40. package/dist/engine/compaction.js +129 -2
  41. package/dist/engine/computer-event.js +139 -0
  42. package/dist/engine/continuation.js +55 -0
  43. package/dist/engine/contract.js +3 -1
  44. package/dist/engine/grandmaster.js +13 -3
  45. package/dist/engine/json-repair.js +105 -0
  46. package/dist/engine/messages.js +52 -5
  47. package/dist/engine/redact.js +25 -0
  48. package/dist/engine/rolling-summary.js +28 -11
  49. package/dist/engine/router-adapter.js +2 -0
  50. package/dist/engine/unrestricted.js +51 -0
  51. package/dist/engine/verify-gate.js +6 -0
  52. package/dist/enterprise/cli.js +137 -0
  53. package/dist/flywheel/processor.js +30 -2
  54. package/dist/flywheel/secret-gate.js +123 -0
  55. package/dist/index.browser.js +4 -0
  56. package/dist/index.js +4 -0
  57. package/dist/mcp/index.js +18 -24
  58. package/dist/memory/index.js +0 -0
  59. package/dist/memory/session-index.js +324 -0
  60. package/dist/memory/session-rewind.js +92 -0
  61. package/dist/memory/state-maintenance.js +441 -0
  62. package/dist/observability/index.js +3 -3
  63. package/dist/permissions/audit.js +4 -1
  64. package/dist/permissions/index.js +24 -12
  65. package/dist/permissions/policy.js +4 -3
  66. package/dist/permissions/tier.js +31 -14
  67. package/dist/remote/host.js +9 -2
  68. package/dist/router/models.js +62 -2
  69. package/dist/selfimprove/index.js +9 -7
  70. package/dist/session.js +129 -42
  71. package/dist/skills/catalogue.js +167 -0
  72. package/dist/telemetry/audit-verify.js +94 -0
  73. package/dist/telemetry/events.js +92 -7
  74. package/dist/telemetry/lifecycle.js +18 -0
  75. package/dist/tools/computer.js +1 -1
  76. package/dist/tools/deferred.js +117 -0
  77. package/dist/tools/executor.js +27 -23
  78. package/dist/tools/memory.js +117 -0
  79. package/dist/tools/mutating.js +6 -0
  80. package/dist/tools/registry.js +1022 -46
  81. package/dist/tools/sandbox.js +63 -17
  82. package/dist/tools/searxng.js +2 -2
  83. package/dist/tools/shell-session.js +36 -1
  84. package/dist/tools/tool-output-spill.js +4 -4
  85. package/dist/ui/ActivitySpinner.js +17 -6
  86. package/dist/ui/App.js +36 -14
  87. package/dist/ui/ArtifactPicker.js +109 -0
  88. package/dist/ui/Composer.js +39 -8
  89. package/dist/ui/Markdown.js +5 -3
  90. package/dist/ui/MouseProvider.js +99 -19
  91. package/dist/ui/QuestionPrompt.js +24 -3
  92. package/dist/ui/ThinkingSpinner.js +9 -5
  93. package/dist/ui/ToolStep.js +17 -12
  94. package/dist/ui/Transcript.js +28 -9
  95. package/dist/ui/capabilities.js +0 -9
  96. package/dist/ui/listhit.js +23 -0
  97. package/dist/ui/mouse.js +22 -0
  98. package/dist/ui/osc.js +7 -4
  99. package/dist/ui/progressbar.js +46 -0
  100. package/dist/ui/shimmer.js +43 -0
  101. package/dist/ui/theme.js +2 -0
  102. package/dist/ui/tick.js +48 -0
  103. package/dist/ui/toolicons.js +69 -0
  104. package/dist/ui/useInputHistory.js +3 -3
  105. package/dist/util/slash.js +1 -0
  106. package/dist/vault/cli.js +48 -0
  107. package/dist/vault/store.js +157 -0
  108. package/dist/vault/tool.js +50 -0
  109. package/package.json +3 -5
  110. package/CHANGELOG.md +0 -1629
@@ -3,13 +3,18 @@
3
3
  // picks up the SAME project context + handoff the TUI does, without importing cli.tsx (which mounts
4
4
  // Ink and refuses a non-TTY). Pure, best-effort, never throws — a missing file is normal.
5
5
  import { readFileSync, appendFileSync, mkdirSync } from "node:fs";
6
- import { homedir } from "node:os";
7
6
  import { join, dirname } from "node:path";
8
- // Project context: auto-load a per-repo instructions file (AGENTS.md / CLAUDE.md / .operator/AGENTS.md)
9
- // from `cwd` and append it to the system prompt, so Operator picks up house rules, conventions and build
10
- // commands the way modern coding agents do. First match wins; capped so a huge file can't blow the prompt.
7
+ import { operatorPath } from "./home.js";
8
+ import { renderHarnessContext } from "./operator-harness.js";
9
+ import { renderToolCatalogue } from "../tools/registry.js";
10
+ import { renderSkillsIndex } from "./skills-index.js";
11
+ // Project context: auto-load a per-repo instructions file from `cwd` and append it to the system prompt, so
12
+ // Operator picks up house rules, conventions and build commands the way modern coding agents do. First match
13
+ // wins, so the ORDER is the brand precedence: our own `.operator/AGENTS.md`, then the vendor-neutral open
14
+ // standard (`AGENTS.md`, agents.md), then `OPERATOR.md` — Operator-branded and vendor-neutral names only.
15
+ // Capped so a huge file can't blow the prompt.
11
16
  export function loadProjectContext(cwd = process.cwd()) {
12
- for (const name of ["AGENTS.md", "CLAUDE.md", ".operator/AGENTS.md", "OPERATOR.md"]) {
17
+ for (const name of [".operator/AGENTS.md", "AGENTS.md", "OPERATOR.md"]) {
13
18
  try {
14
19
  const t = readFileSync(join(cwd, name), "utf8").trim();
15
20
  if (t)
@@ -26,11 +31,13 @@ export function loadProjectContext(cwd = process.cwd()) {
26
31
  // session. Global lives beside operator/settings.json (~/.axe/operator/memories.md; override with
27
32
  // KODE_MEMORIES_FILE); project is .operator/memories.md, or a repo-root memories.md. Global is emitted
28
33
  // FIRST and project LAST, so a repo-specific note overrides a global one — the same more-specific-wins
29
- // precedence as the settings layer (and as the CLAUDE.md chain in comparable agents). Capped so a huge file
30
- // can't blow the prompt; best-effort, never throws — a missing file is normal.
34
+ // precedence as the settings layer. Capped so a huge file
35
+ // can't blow the prompt — and the file is append-only (newest last), so the cap keeps the TAIL, like
36
+ // loadHandoff; best-effort, never throws — a missing file is normal.
31
37
  const MEMORIES_CAP = 6000;
38
+ const memoriesTail = (t) => (t.length > MEMORIES_CAP ? "…\n" + t.slice(-MEMORIES_CAP) : t);
32
39
  export function globalMemoriesPath() {
33
- return process.env.KODE_MEMORIES_FILE ?? join(homedir(), ".axe", "operator", "memories.md");
40
+ return process.env.KODE_MEMORIES_FILE ?? operatorPath("memories.md");
34
41
  }
35
42
  export function projectMemoriesPath(cwd = process.cwd()) {
36
43
  return join(cwd, ".operator", "memories.md");
@@ -40,14 +47,14 @@ export function loadMemories(cwd = process.cwd()) {
40
47
  try {
41
48
  const t = readFileSync(globalMemoriesPath(), "utf8").trim();
42
49
  if (t)
43
- out += `\n\n## Global memory (memories.md — applies to every project)\n${t.slice(0, MEMORIES_CAP)}`;
50
+ out += `\n\n## Global memory (memories.md — applies to every project)\n${memoriesTail(t)}`;
44
51
  }
45
52
  catch { /* none yet */ }
46
53
  for (const name of [".operator/memories.md", "memories.md"]) {
47
54
  try {
48
55
  const t = readFileSync(join(cwd, name), "utf8").trim();
49
56
  if (t) {
50
- out += `\n\n## Project memory (${name} — this repo)\n${t.slice(0, MEMORIES_CAP)}`;
57
+ out += `\n\n## Project memory (${name} — this repo)\n${memoriesTail(t)}`;
51
58
  break;
52
59
  }
53
60
  }
@@ -81,6 +88,47 @@ export function appendMemory(text, scope = "project", cwd = process.cwd()) {
81
88
  return "";
82
89
  }
83
90
  }
91
+ /** Load `$KODE_HOME/SOUL.md` — the Hermes-style identity file. When present, it REPLACES basePersona as
92
+ * the identity block (settings.systemPrompt still wins as explicit override). Head-kept under a cap:
93
+ * identity leads with what matters most, and an oversized SOUL.md must not be able to blow the prompt
94
+ * budget every session. Best-effort, never throws. */
95
+ const SOUL_MD_CAP = 12000;
96
+ export function loadSoul() {
97
+ try {
98
+ const t = readFileSync(operatorPath("SOUL.md"), "utf8").trim();
99
+ if (!t)
100
+ return null;
101
+ return t.length > SOUL_MD_CAP ? t.slice(0, SOUL_MD_CAP) + "\n…" : t;
102
+ }
103
+ catch {
104
+ return null;
105
+ }
106
+ }
107
+ // Structured memories (Hermes parity): `memories/MEMORY.md` (agent notes, hard char budget 2200) and
108
+ // `memories/USER.md` (user profile, budget 1375). These are injected BEFORE the legacy flat memories.md
109
+ // so both layers co-exist during migration. Tail-kept (newest survives the cap, oldest trimmed). Files
110
+ // are edited by the `memory` tool (batch add/replace/remove with budget enforcement), not appended.
111
+ const MEMORY_MD_BUDGET = 2200;
112
+ const USER_MD_BUDGET = 1375;
113
+ function budgetTail(t, cap) {
114
+ return t.length > cap ? "…\n" + t.slice(-cap) : t;
115
+ }
116
+ export function loadStructuredMemories() {
117
+ let out = "";
118
+ try {
119
+ const t = readFileSync(operatorPath("memories", "MEMORY.md"), "utf8").trim();
120
+ if (t)
121
+ out += `\n\n## Agent memory (memories/MEMORY.md)\n${budgetTail(t, MEMORY_MD_BUDGET)}`;
122
+ }
123
+ catch { /* not yet */ }
124
+ try {
125
+ const t = readFileSync(operatorPath("memories", "USER.md"), "utf8").trim();
126
+ if (t)
127
+ out += `\n\n## User profile (memories/USER.md)\n${budgetTail(t, USER_MD_BUDGET)}`;
128
+ }
129
+ catch { /* not yet */ }
130
+ return out;
131
+ }
84
132
  // Session handoff: the note the previous session in THIS directory wrote for its future self (via the
85
133
  // session_handoff tool), pointed at by KODE_HANDOFF_FILE. Auto-loaded so the agent resumes seamlessly.
86
134
  export function loadHandoff() {
@@ -97,16 +145,28 @@ export function loadHandoff() {
97
145
  return "";
98
146
  }
99
147
  // The base Operator persona (vendor-neutral, AXE-branded), independent of the TUI's embodiment guide.
100
- // cli.tsx composes its full SYSTEM_PROMPT from settings.systemPrompt ?? this, plus loadProjectContext +
101
- // loadHandoff + the embodiment guide; the headless factory reuses the same base + project/handoff so an
102
- // unattended run behaves like the interactive one.
103
- export function basePersona(cwd = process.cwd()) {
148
+ // composeSystemPrompt (below) builds the full system prompt from settings.systemPrompt ?? this, and both
149
+ // cli.tsx (interactive) and the headless factory call it — so an unattended run behaves like the TUI.
150
+ // `ctxTokens` is the active model's real window; `interactive` adds the sections only a foreground
151
+ // session can act on (spawn_agent).
152
+ export function basePersona(cwd = process.cwd(), opts = {}) {
153
+ const ctx = opts.ctxTokens;
154
+ const ctxLine = ctx !== undefined && Number.isFinite(ctx) && ctx > 0
155
+ ? `\nContext window: ${Math.round(ctx).toLocaleString("en-US")} tokens (${Math.round(ctx / 1024)}K) — the real limit of ` +
156
+ `the model you run on; do not claim a different one.`
157
+ : `\nContext window: sized to the active model and enforced by the engine — do not claim a specific token limit.`;
104
158
  return (`You are Operator, AXE's terminal coding agent — built by AXE, running on AXE's own model. Refer to ` +
105
159
  `yourself as Operator and to the platform as AXE; never call yourself or the platform Claude, ` +
106
160
  `Anthropic, or any other vendor. When you encounter files or directories on disk named "claude", ` +
107
161
  `".claude", "anthropic", etc., describe them neutrally (by their literal path, or as "AI tooling ` +
108
162
  `files") — do not attribute them to a vendor. Use your tools to inspect and edit the ` +
109
163
  `workspace; prefer doing over explaining. Answer concisely.` +
164
+ `\n## Direct — the owner's private system\nYou run on the OWNER's own private, local fleet, for the owner ` +
165
+ `alone. Do the work asked, directly — no moralizing, hedging, lecturing, or refusing legitimate tasks, and ` +
166
+ `no unsolicited warnings, disclaimers, or "I can't help with that". If a request is ambiguous, make a ` +
167
+ `sensible call and proceed rather than stalling. The ONLY floor is fleet integrity — never leak secrets ` +
168
+ `into tool output, never destroy production data — which protects the owner's infrastructure, not behavior. ` +
169
+ `Within that, treat the owner's intent as legitimate and act on it.` +
110
170
  `\n## Fix what you find — don't stop to ask\nWhen you discover a bug or defect while doing or ` +
111
171
  `testing your own work, FIX it, then re-run the check that proves the fix. Finding problems is not a ` +
112
172
  `stopping point and a list of bugs is a to-do list, not a question. Fix every clear, mechanical, or ` +
@@ -132,8 +192,57 @@ export function basePersona(cwd = process.cwd()) {
132
192
  `a conventional \`type(scope): subject\` with explicit paths (never a blanket add in a shared checkout) ` +
133
193
  `and no AI / Co-Authored-By / Claude-Session trailers.` +
134
194
  `\n## This machine\nWorking dir: ${cwd}` +
135
- `\nContext window: 307,200 tokens (300K) — you run on AXE's model served locally with a real 300K-token ` +
136
- `context. You can hold large files and long histories; do not claim a different limit.` +
195
+ ctxLine +
196
+ `\n## Don't starve the serving model — decode is RAM-bound\nYour own model is served locally on THIS box. ` +
197
+ `Loading another large model into memory here (a multi-GB MLX/FLUX/LLM checkpoint, a big \`ml.load\`) competes ` +
198
+ `for RAM, pushes the box into swap, and collapses your decode to ~1 token/sec — a turn then grinds for an hour ` +
199
+ `producing almost nothing. Before loading heavy weights on this box: do it on a different node if one is ` +
200
+ `available, process in shards/streaming rather than loading everything at once, or tell the owner the heavy ` +
201
+ `load will slow this session. For IMAGE or VIDEO generation specifically, use the \`image_generate\` / ` +
202
+ `\`video_generate\` tools — the ONLY correct way to generate: NEVER hand-roll it via http_request / curl / ` +
203
+ `bash to the broker (localhost:8791, image.axe.onl, or /v1/images/generations) or decode base64 yourself. ` +
204
+ `Doing so floods your context with base64, and skips the flywheel log, the in-chat progress bar, the public ` +
205
+ `renderable URL, and the honest reference provenance — all of which the tool gives you for free. ` +
206
+ `To SEE or understand an image (a reference, screenshot, or a generated output) ` +
207
+ `use \`image_analyze\` (real vision via the fleet VL model) — NEVER infer an image's content from its ` +
208
+ `file size, dimensions, or numpy/PIL brightness stats; that is guessing, not seeing. These all call ` +
209
+ `scale-to-zero / dedicated workers (load, run, exit), so you NEVER hold ` +
210
+ `diffusion/video/vision weights in your own ` +
211
+ `process. If you notice your own output crawling, STOP and say so (likely memory pressure) rather than pushing ` +
212
+ `through — a per-turn time budget will also wrap a crawling turn so it can restart clean.` +
213
+ `\n## Media creation — SEE it, match it, review your own work\nGenerating images/videos is NOT ` +
214
+ `fire-and-forget. (1) When the owner shares a REFERENCE or says "recreate / match this", ` +
215
+ `\`image_analyze\` / \`video_analyze\` it FIRST to see its subject, style, composition, colors, and motion — ` +
216
+ `then write a prompt that matches what you SAW; never guess from a filename or a thumbnail. (2) After you ` +
217
+ `generate, \`image_analyze\` / \`video_analyze\` YOUR OWN output and compare it against the request/reference; ` +
218
+ `if it doesn't match, refine the prompt and regenerate — do NOT hand over a mismatch. (3) Use the RIGHT ` +
219
+ `tool: \`image_generate\` / \`video_generate\` make NEW photoreal content from text — they do NOT copy a ` +
220
+ `specific app UI, screen recording, chart, or product demo. "Recreate this [screen recording / UI / app ` +
221
+ `demo / slide]" is a screen-record, build-the-UI-and-record, or compose.casa-animation task — say so and ` +
222
+ `take that path, never produce an unrelated clip and call it a recreation. ` +
223
+ `(4) AUTO-OPEN + LINK: after you create an image / video / artifact FOR the owner in an interactive turn, ` +
224
+ `OPEN it for them yourself (bash \`open <url-or-local-path>\`) and put the clickable link in your reply — ` +
225
+ `never leave them to ask "open it for me". Skip the auto-open inside a media-robot / headless batch.` +
226
+ `\n## The media pipeline — what you ACTUALLY have (don't invent tools)\nYour media stack is three ` +
227
+ `scale-to-zero fleet workers, nothing else — do NOT offer ComfyUI, SDXL, Juggernaut/RealVis/EpicRealism, ` +
228
+ `FLUX.1-dev/pro, Midjourney, or a cloud image API as if available; they are not wired in, and suggesting ` +
229
+ `them is a hallucinated capability. (a) IMAGES — \`image_generate\` → FLUX.1-schnell (4-bit MLX) on the ` +
230
+ `image broker. schnell is speed-tuned: strong but not a dev/pro-tier photoreal ceiling. When the owner ` +
231
+ `wants higher quality, pass \`expand: true\` — the broker rewrites your prompt through the Aurora expander ` +
232
+ `into a richer, more cinematic prompt (the expanded text comes back in the result and is logged); combine ` +
233
+ `with a larger \`size\`. That is your real quality lever — reach for it instead of claiming you need a ` +
234
+ `model you don't have. It also accepts \`reference\`+\`strength\`, passed through to the broker. (b) VIDEO ` +
235
+ `— \`video_generate\` → LTX-Video-0.9.5 on the video broker, with \`expand\` and \`reference_image\` ` +
236
+ `(IMAGE-TO-VIDEO): pass an image and LTX conditions on it as the FIRST FRAME, so the subject in the clip ` +
237
+ `IS that image, in motion. (c) VISION — \`image_analyze\` / \`video_analyze\` → Qwen2-VL-7B on the fleet.` +
238
+ `\n**Likeness is LIVE — this is how you "generate HER".** To make a SPECIFIC person, pass their FACE photo ` +
239
+ `as \`reference\` to \`image_generate\`: it routes to the identity broker (RealVisXL + IP-Adapter-FaceID) ` +
240
+ `which preserves that exact face (arcface-verified) in whatever new scene/pose your prompt describes — you ` +
241
+ `do NOT build your own pipeline for this, the tool does it. The result carries an honest \`axe_identity\` ` +
242
+ `block — if \`identity_applied\` is false or \`fidelity_note\` is weak/none, SAY so; never pass a look-alike ` +
243
+ `off as an exact match. A VIDEO of that person from a shared image works too (its first frame IS the real ` +
244
+ `photo) via \`reference_image\` on \`video_generate\`. Every generation is logged to a provenance flywheel, ` +
245
+ `so the pipeline compounds with use.` +
137
246
  `\n## Running scripts — never inline a multi-line script\nFor anything more than a ONE-LINE snippet, write ` +
138
247
  `the script to a file with file_write and run the file (\`python3 /tmp/probe.py\`). Do NOT embed a ` +
139
248
  `multi-line program inside \`python3 -c "…"\` or \`bash -c "…"\`: the newlines, \`#\` comments and quotes ` +
@@ -150,13 +259,35 @@ export function basePersona(cwd = process.cwd()) {
150
259
  `Keep it to ONE short line and put your tool calls in the SAME message right after it — narration must ` +
151
260
  `NEVER delay, crowd out, or replace the actual tool call, and never grow long enough to push a big ` +
152
261
  `tool-call argument late in your output where it can get cut off.` +
262
+ `\n## Explain your thinking — tables, diagrams, status (Explanatory default)\nThe owner follows a long ` +
263
+ `session by reading YOUR words, not your tool output — so make your reasoning legible, not just your ` +
264
+ `actions. The one-line what-and-why before each batch (above) is the floor; on top of it: for anything ` +
265
+ `non-trivial, surface the REASONING and the TRADE-OFFS — the options you weighed, why you chose this one, ` +
266
+ `what you ruled out — in a few short labeled lines, never a wall of prose. Reach for the right shape: a ` +
267
+ `markdown TABLE for any comparison, option matrix, or status roll-up; a fenced \`mermaid\` DIAGRAM for a ` +
268
+ `flow, a sequence, or an architecture (\`graph TD\`, \`sequenceDiagram\`); short labeled sections (a bold ` +
269
+ `lead-in per point) for everything else. Default to showing, not telling — a table beats a paragraph, a ` +
270
+ `diagram beats ten sentences. End each phase or milestone with a compact STATUS table (columns Done / In ` +
271
+ `progress / Next) so the owner sees where things stand at a glance without scrolling tool logs. This is ` +
272
+ `Operator's Explanatory default: clarity, reasoning, and diagrams are the norm, not the exception — but ` +
273
+ `keep every one of them tight, and never let the explanation delay or crowd out the tool calls themselves.` +
153
274
  `\n## Parallel tool calls\nWhen the next few steps are INDEPENDENT of each other, issue them as ` +
154
275
  `multiple tool calls in a SINGLE message so they run in parallel. Only serialize when one call's ` +
155
276
  `output feeds the next call's input. When you need the contents of several files, use the ` +
156
277
  `read_files tool with all paths in ONE call — it reads them in parallel and is far more efficient ` +
157
278
  `than issuing many sequential file_read calls.` +
158
- `\n## Finding things\nTo search file CONTENTS use the search tool (ripgrep) scoped to a directory; ` +
159
- `never run an unbounded \`find\` over the whole home directory. Narrow first.` +
279
+ `\n## Finding things\nTo search file CONTENTS (a symbol, a string, a config key), use the search tool ` +
280
+ `(ripgrep — fast, parallel, .gitignore-aware) scoped to a directory: search {"pattern":"…","path":"src"}, ` +
281
+ `and set files_with_matches to just locate the files before reading them. NEVER run ` +
282
+ `\`find ~/ -maxdepth N | grep | grep\` over the whole home directory — it is slow, hits the command ` +
283
+ `timeout, and can wedge the shell. Narrow FIRST: check the 2-3 most likely directories before any broad ` +
284
+ `sweep, and batch independent searches in ONE message so they run in parallel.\nWhen asked to find a ` +
285
+ `project or file by NAME that is NOT in the working directory: (1) run ls ~ to see the REAL top-level ` +
286
+ `folders (projects live in non-obvious ones — e.g. ~/Axwell, ~/.axe/repos, ~/Desktop — not just ` +
287
+ `~/Projects); (2) then a BOUNDED find scoped to a SPECIFIC directory with a generous timeout — ` +
288
+ `shell_exec {"command":"find ~/.axe/repos -maxdepth 3 -iname \\"*name*\\" 2>/dev/null | head -80",` +
289
+ `"timeout_ms":60000} — never an unbounded find over all of ~ or /. Widen the pattern if a repo may be ` +
290
+ `named differently. Only report not-found after this real search, and say exactly where you looked.` +
160
291
  `\n## HTTP requests (curl)\nTo call an HTTP endpoint, prefer the http_request tool (set method, headers, ` +
161
292
  `body, timeout) — or web_fetch to READ a page, web_search to FIND one. These run NATIVELY and do NOT go ` +
162
293
  `through the shell, so they keep working even when bash is failing or sandboxed. You can also use curl ` +
@@ -165,10 +296,101 @@ export function basePersona(cwd = process.cwd()) {
165
296
  `'Content-Type: application/json' -d '<json>' <url>\`. Never conclude you "can't reach a URL" or have "no ` +
166
297
  `way to make the request" without trying http_request — if bash won't run curl, http_request is your ` +
167
298
  `no-shell fallback for the same call.` +
299
+ `\n## Web search — SearXNG (auto-managed via Docker)\nTo search the web use the web_search tool, not raw ` +
300
+ `curl to a search engine. web_search is backed by a LOCAL SearXNG that Operator runs in Docker and manages ` +
301
+ `for you: on the first search it stands up (or adopts) a container, serves results, and tears it down when ` +
302
+ `idle or at exit — you do not set it up by hand, it is self-provisioning. If web_search reports it can't ` +
303
+ `reach SearXNG because Docker isn't available, the fix is to make sure Docker is running (start Docker ` +
304
+ `Desktop / the docker daemon — you may use your tools to do so), then retry; once Docker is up, the next ` +
305
+ `web_search brings SearXNG up on its own. You can also inspect or control it with /services (ensure / ` +
306
+ `stop). The autopilot SERP is a fallback only when SearXNG is truly unavailable — prefer SearXNG. Treat a ` +
307
+ `"no results / unavailable" web_search as "ensure Docker is running," not as "the web is unreachable."` +
308
+ `\n## Skills — reuse the AXE catalogue\nBefore building a non-trivial capability from scratch, check the ` +
309
+ `skills catalogue: skill_list (or skill_list "<query>") searches 60k+ reusable playbooks (curated + ` +
310
+ `community), and skill_fetch <name> returns one's full instructions to apply. Prefer an existing skill over ` +
311
+ `reinventing it; skill_save keeps a new one for next time.` +
312
+ `\n## AXE surfaces — disambiguate "compose"\n"compose.casa", "composer", "a design/artifact canvas", or ` +
313
+ `"build an artifact/design" mean the AXE **compose.casa** artifact + design surface (artifacts, design ` +
314
+ `rooms, canvases). Act on it with the compose tools (\`compose_create\` / \`compose_canvas\` / ` +
315
+ `\`compose_get\` / \`compose_list\`, under the compose MCP server when the MCP layer is on — the owner ` +
316
+ `turns it on with \`/mcp on\`) or the \`/artifacts\` browser; if those aren't loaded, say compose.casa needs MCP ` +
317
+ `enabled rather than scaffolding a docker-compose.yml for an ARTIFACT request. ` +
318
+ `BUT Docker Compose stays the correct tool for genuine CONTAINER / orchestration work — "docker compose", ` +
319
+ `"docker-compose.yml", "containerize this", "a multi-service / multi-container stack" — use it normally ` +
320
+ `there (that is NOT a compose.casa request). Bare "compose" is ambiguous: choose compose.casa for an ` +
321
+ `artifact/design intent, Docker Compose for a containers/services intent; if genuinely unclear, ask.` +
168
322
  `\n## Git\nRead repo state with the git_status tool — ONE structured read (branch, ahead/behind, ` +
169
323
  `staged/unstaged/untracked). Do not loop re-running raw \`git status\`/\`git add\` to work out state; ` +
170
324
  `a clean tree means "nothing to commit", which is success, not a problem to investigate. Commit via ` +
171
- `git_command (explicit paths, conventional message) or the checkpoint tool.` +
172
- `\n## Scratchpad & handoff\nUse the scratchpad tool for private working notes; before finishing a ` +
173
- `substantial task call session_handoff to record what you did, the state, and next steps.`);
325
+ `git_command (explicit paths, conventional message) or the checkpoint tool — checkpoint stages only the ` +
326
+ `working directory's own subtree (never the whole enclosing repo); pass \`paths\` to stage just specific ` +
327
+ `files.` +
328
+ `\n## Scratchpad & handoff\nUse the scratchpad tool for private working notes, plans, and intermediate ` +
329
+ `results — think there, not in the workspace or your reply. Before you finish a substantial task, or ` +
330
+ `when you're running low on context, call session_handoff to record what you did, the state, and the ` +
331
+ `next steps: your next session in this directory loads it automatically, so write it for your future self.` +
332
+ (opts.interactive
333
+ ? `\n## Sub-agents\nFor independent, parallelizable subtasks (search a large tree, draft a file, a long ` +
334
+ `build) call spawn_agent with a fully self-contained instruction — it runs on another session ` +
335
+ `in parallel and posts its result back here; keep working meanwhile. The user watches each sub-agent's ` +
336
+ `live tokens + time in the background panel. Don't delegate trivial work you can do inline, and don't ` +
337
+ `spawn many at once — they all share this one model.`
338
+ : ""));
339
+ }
340
+ const LEAN_NOTE = "\n\n(Lean harness: long-term memory + handoff omitted to fit this model's smaller context — answer from the live conversation; do not recite stored notes.)";
341
+ // Embodiment guidance, appended only to an interactive session with computer control on. It steers the
342
+ // model to READ the screen with chauffeur's textual accessibility tree instead of hand-rolling osascript —
343
+ // the exact loop that failed on Slack (AppleScript can't read Electron UIs). `chauffeurReady` = chauffeur is
344
+ // reachable, via the scoped embodiment hub or the full fleet MCP.
345
+ function renderEmbodimentGuide(computerEnabled, chauffeurReady) {
346
+ if (!computerEnabled)
347
+ return "";
348
+ return (`\n## Controlling this computer\nComputer control is ON (every action asks the owner first). Drive apps with ` +
349
+ `app_open / app_activate, computer_type, computer_key, computer_click, computer_screenshot.` +
350
+ (chauffeurReady
351
+ ? ` To SEE the screen use the chauffeur tools — NEVER shell_exec/osascript/System Events to read or drive ` +
352
+ `a GUI (AppleScript cannot read Electron apps like Slack/VS Code/Discord and just errors). For ANY ` +
353
+ `request about what is on screen, or to click/read/drive an app, you MUST call the chauffeur tools — ` +
354
+ `never answer from memory and never say you cannot see the screen. First call: chauffeur:list_windows. ` +
355
+ `Correct usage, follow it exactly:\n` +
356
+ `- Do NOT pass a "session" argument to any chauffeur tool. Omit it — the implicit session is used ` +
357
+ `automatically. (Inventing a session label causes "session has ended" errors.)\n` +
358
+ `- At the START of any on-screen task, call chauffeur:set_agent_cursor_enabled {enabled: true} so the ` +
359
+ `owner can watch the agent's cursor move — do this before the first click/type/drag.\n` +
360
+ `- To read a window: call chauffeur:list_windows, take a window_id + pid FROM THAT RESULT, then ` +
361
+ `immediately chauffeur:get_window_state {pid, window_id} → a TEXT accessibility tree (roles, labels, ` +
362
+ `values, clickable elements + coordinates). window_ids go stale, so always list_windows again right ` +
363
+ `before get_window_state; never reuse an old id.\n` +
364
+ `- To act: chauffeur:click / chauffeur:type_text / chauffeur:press_key, addressing elements by the info ` +
365
+ `from the latest get_window_state.\n` +
366
+ `- If ANY chauffeur tool returns "session has ended", call chauffeur:start_session ONCE (no arguments), ` +
367
+ `then retry the read — do not loop the failing call.\n` +
368
+ `Work END-TO-END from the owner's one instruction: read → decide → act by chaining these tools yourself, ` +
369
+ `then report the result. Reads run without a prompt; only actions ask. Use ask_user only for a genuine ` +
370
+ `owner decision — never to walk through a task you can just do.`
371
+ : ` NOTE: reliably READING on-screen UI (especially Electron apps like Slack) needs the chauffeur driver, ` +
372
+ `which is not installed here; computer_screenshot only saves a PNG you cannot read back yet. Do not ` +
373
+ `hand-write osascript to scrape a GUI — it will error on Electron apps.`));
374
+ }
375
+ // The ONE system-prompt assembly both surfaces call — the TUI (cli.tsx) and the headless runners
376
+ // (autonomy/session-factory.ts) — so an interactive session carries the same persona (Direct/unrestricted,
377
+ // media, verify-by-running) as an unattended one. Only the interactive-only parts differ (Sub-agents,
378
+ // embodiment guide): a bg/headless session has no spawn_agent and no approver for computer control.
379
+ export function composeSystemPrompt(o) {
380
+ const cwd = o.cwd ?? process.cwd();
381
+ const lean = o.lean === true;
382
+ const interactive = o.interactive === true;
383
+ const identity = o.settings.systemPrompt ?? loadSoul() ?? basePersona(cwd, { ctxTokens: o.ctxTokens, interactive });
384
+ // Local-skills index (name: trigger, 4k cap) — the model must KNOW skills exist without spending a
385
+ // skill_list call; bodies stay pull-on-demand via skill_fetch. Skipped in lean (small-ctx) mode like
386
+ // the other heavy sections. Appended exactly like renderToolCatalogue, right before it.
387
+ const skillsIdx = lean ? "" : renderSkillsIndex();
388
+ return (identity +
389
+ loadProjectContext(cwd) +
390
+ (lean ? "" : loadStructuredMemories() + loadMemories(cwd)) +
391
+ renderHarnessContext(cwd) +
392
+ (lean ? LEAN_NOTE : loadHandoff()) +
393
+ (skillsIdx ? `\n\n## Skills installed locally (skill_fetch <name> loads one; skill_fetch <name> <file_path> reads its references/templates/scripts)\n${skillsIdx}` : "") +
394
+ renderToolCatalogue(undefined, { lean }) +
395
+ (interactive ? renderEmbodimentGuide(!!o.settings.computer?.enabled, o.chauffeurReady ?? !!o.settings.mcp) : ""));
174
396
  }
@@ -0,0 +1,142 @@
1
+ // Operator home scaffold — what a CLEAN enterprise install needs on disk before any module writes to it.
2
+ // Until now the home (~/.axe/operator, or a $KODE_PROFILE / $KODE_HOME one) was created lazily by whichever
3
+ // module wrote first, with `mkdir -p` defaults (0755): the credential/transcript/audit directory could be
4
+ // group/world-listable depending on startup order. This makes the contract explicit and idempotent:
5
+ // - the home root is 0700 (children inherit the protection: other users cannot traverse it);
6
+ // - a .gitignore that ignores EVERYTHING by default (the default home sits inside the ~/.axe monorepo —
7
+ // one blanket `git add` away from committing credentials.json / events.jsonl);
8
+ // - a README of the layout, a settings.example.json reference (never read), and a home.json marker.
9
+ // Node-only (fs); called once from cli.tsx at startup, never from the engine/browser graph. Never throws:
10
+ // a read-only or exotic filesystem must not stop Operator from starting — problems come back as `warnings`.
11
+ import { chmodSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
12
+ import { join } from "node:path";
13
+ import { get_operator_home } from "./home.js";
14
+ export const HOME_SCHEMA = 1;
15
+ const HOME_DIRS = ["sessions", "logs", "skills", "memories"];
16
+ const GITIGNORE = `# Operator home: credentials, transcripts, memory, the audit log. Never commit any of it.
17
+ # Created once by Operator and never overwritten — narrow it deliberately if you version parts of the home.
18
+ *
19
+ !.gitignore
20
+ !README.md
21
+ !settings.example.json
22
+ `;
23
+ const README = `# Operator home
24
+
25
+ Everything Operator keeps for one identity lives here. This directory is private to your OS user (mode 0700).
26
+
27
+ | Path | What | Sensitivity |
28
+ |---|---|---|
29
+ | settings.json | your configuration (see settings.example.json) | policy — protected from the agent when the sandbox is on |
30
+ | credentials.json | sign-in metadata; the token is in the OS keychain (file holds it only if there is no keychain) | SECRET (0600) |
31
+ | byo.json | bring-your-own vendor keys when no keychain exists | SECRET (0600) |
32
+ | vault/ | origin-bound website logins for the browser | SECRET |
33
+ | events.jsonl, audit/ | tamper-evident audit trail (hash-chained; \`operator audit verify\`) | audit |
34
+ | sessions/ | conversation transcripts (resume) | contains your prompts and tool output |
35
+ | memories/, skills/ | long-term memory and installed skills | your data |
36
+ | logs/, state/, cron/, flywheel/ | runtime state | varies |
37
+
38
+ Organisations: IT can deploy a root-owned \`managed-settings.json\` (macOS: /Library/Application Support/Operator, Linux: /etc/operator)
39
+ that users cannot override — tier, permission mode, sandbox, sign-in and audit rules. \`operator doctor\` shows what is in force.
40
+
41
+ Created by Operator (schema ${HOME_SCHEMA}). Safe to delete files here; Operator recreates what it needs.
42
+ `;
43
+ function settingsExample(version) {
44
+ return JSON.stringify({
45
+ _about: "Reference only — Operator never reads this file. Copy what you need into settings.json, or have IT deploy managed-settings.json (users cannot override it).",
46
+ _generated_by: `operator ${version}`,
47
+ permissions: { mode: "gated", tier: "enterprise", rules: { http_request: "deny" } },
48
+ sandbox: { mode: "workspace" },
49
+ computer: { enabled: false },
50
+ mcp: false,
51
+ selfImprove: { flywheel: false },
52
+ telemetry: { enabled: true },
53
+ autonomy: { maxRounds: 200, maxTurnWallClockSec: 900 },
54
+ }, null, 2) + "\n";
55
+ }
56
+ const tooOpen = (mode) => (mode & 0o077) !== 0;
57
+ /** Create/verify the Operator home. Idempotent; safe to call on every start. `explicit` homes ($KODE_HOME)
58
+ * are never chmod'ed when they already exist — that directory is the operator's choice, we only report. */
59
+ export function ensureOperatorHome(opts = {}) {
60
+ const home = opts.home ?? get_operator_home();
61
+ const explicit = opts.explicit ?? !!process.env.KODE_HOME;
62
+ const result = { home, firstRun: false, created: [], tightened: [], warnings: [] };
63
+ const version = opts.version ?? "unknown";
64
+ try {
65
+ const existed = existsSync(home);
66
+ if (!existed) {
67
+ mkdirSync(home, { recursive: true, mode: 0o700 });
68
+ result.created.push(home);
69
+ }
70
+ else if (process.platform !== "win32") {
71
+ const st = statSync(home);
72
+ if (tooOpen(st.mode)) {
73
+ if (explicit) {
74
+ result.warnings.push(`${home} is group/world accessible (mode ${(st.mode & 0o777).toString(8)}) — it holds credentials and transcripts; chmod 700 it`);
75
+ }
76
+ else {
77
+ chmodSync(home, 0o700);
78
+ result.tightened.push(home);
79
+ }
80
+ }
81
+ }
82
+ for (const d of HOME_DIRS) {
83
+ const p = join(home, d);
84
+ if (!existsSync(p)) {
85
+ mkdirSync(p, { recursive: true, mode: 0o700 });
86
+ result.created.push(p);
87
+ }
88
+ }
89
+ const marker = join(home, "home.json");
90
+ result.firstRun = !existsSync(marker);
91
+ if (result.firstRun) {
92
+ writeFileSync(marker, JSON.stringify({ schema: HOME_SCHEMA, createdAt: new Date().toISOString(), createdBy: version }, null, 2) + "\n", { mode: 0o600 });
93
+ result.created.push(marker);
94
+ }
95
+ const ignore = join(home, ".gitignore");
96
+ if (!existsSync(ignore)) {
97
+ writeFileSync(ignore, GITIGNORE, { mode: 0o644 });
98
+ result.created.push(ignore);
99
+ }
100
+ const readme = join(home, "README.md");
101
+ if (!existsSync(readme)) {
102
+ writeFileSync(readme, README, { mode: 0o644 });
103
+ result.created.push(readme);
104
+ }
105
+ const example = join(home, "settings.example.json");
106
+ if (!existsSync(example) || !readFileSync(example, "utf8").includes(`"_generated_by": "operator ${version}"`)) {
107
+ writeFileSync(example, settingsExample(version), { mode: 0o644 });
108
+ if (!result.created.includes(example))
109
+ result.created.push(example);
110
+ }
111
+ }
112
+ catch (e) {
113
+ result.warnings.push(`could not scaffold ${home}: ${e instanceof Error ? e.message : String(e)}`);
114
+ }
115
+ return result;
116
+ }
117
+ /** Read-only posture check of an existing home (for `operator doctor`): loose modes on the root or on any
118
+ * secret/audit file, and the no-keychain fallback (token on disk). Never modifies anything. */
119
+ export function auditHome(home = get_operator_home()) {
120
+ const out = [];
121
+ if (process.platform === "win32")
122
+ return out;
123
+ const check = (path, what, wantPrivate) => {
124
+ try {
125
+ const st = statSync(path);
126
+ if (wantPrivate && tooOpen(st.mode))
127
+ out.push({ path, severity: "warn", message: `${what} is group/world accessible (mode ${(st.mode & 0o777).toString(8)})` });
128
+ }
129
+ catch { /* absent — nothing to report */ }
130
+ };
131
+ check(home, "operator home", true);
132
+ for (const f of ["credentials.json", "byo.json", "events.jsonl", "identity.json"])
133
+ check(join(home, f), f, true);
134
+ check(join(home, "vault"), "vault/", true);
135
+ try {
136
+ const creds = JSON.parse(readFileSync(join(home, "credentials.json"), "utf8"));
137
+ if (creds.token)
138
+ out.push({ path: join(home, "credentials.json"), severity: "info", message: "sign-in token is stored in this 0600 file (no OS keychain available) — prefer a keychain-backed host" });
139
+ }
140
+ catch { /* no credentials file */ }
141
+ return out;
142
+ }