@0perator/operator 0.1.39 → 0.1.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -19,7 +19,7 @@ import { expandFileMentions } from "./util/mentions.js";
19
19
  import { join } from "node:path";
20
20
  import { homedir, hostname } from "node:os";
21
21
  import { createHash } from "node:crypto";
22
- const VERSION = "0.1.39";
22
+ const VERSION = "0.1.41";
23
23
  // operator/settings.json (override path via KODE_TSI_SETTINGS), env vars still win — see config/settings.ts.
24
24
  const settings = loadSettings();
25
25
  // Propagate the resolved sandbox mode to the tool layer (registry reads KODE_SANDBOX at exec time).
@@ -55,14 +55,23 @@ if (settings.services?.stopOnExit?.searxng === false)
55
55
  // mobile bundle never sees these tools.
56
56
  let computerAskRules = {};
57
57
  let computerDenyRules = {};
58
+ let embodimentHub; // chauffeur, scoped to embodiment
58
59
  if (settings.computer.enabled) {
59
60
  const { COMPUTER_TOOLS, COMPUTER_TOOL_NAMES, setComputerEnabled } = await import("./tools/computer.js");
60
61
  const { registry } = await import("./tools/registry.js");
61
62
  setComputerEnabled(true);
62
63
  for (const t of COMPUTER_TOOLS)
63
64
  registry.set(t.name, t);
64
- computerAskRules = Object.fromEntries(COMPUTER_TOOL_NAMES.map((n) => [n, "ask"]));
65
- computerDenyRules = Object.fromEntries(COMPUTER_TOOL_NAMES.map((n) => [n, "deny"]));
65
+ // Embodiment also wires chauffeur (robust textual-AX computer use) when installed, as its OWN curated
66
+ // hub — not the whole fleet MCP surface. It fills osascript's blind spot: reading a modern/Electron UI.
67
+ // When the owner has opted into the full fleet (settings.mcp), chauffeur is already reachable there, so
68
+ // we don't double-wire; otherwise we inject the scoped hub so embodiment alone is enough.
69
+ const { buildChauffeurHub, CHAUFFEUR_TOOL_NAMES } = await import("./tools/chauffeur.js");
70
+ if (!settings.mcp)
71
+ embodimentHub = (await buildChauffeurHub()) ?? undefined;
72
+ const gated = [...COMPUTER_TOOL_NAMES, ...(embodimentHub ? CHAUFFEUR_TOOL_NAMES : [])];
73
+ computerAskRules = Object.fromEntries(gated.map((n) => [n, "ask"]));
74
+ computerDenyRules = Object.fromEntries(gated.map((n) => [n, "deny"]));
66
75
  }
67
76
  // Foreground policy = the owner's settings with computer tools forced to "ask". When computer control is
68
77
  // off, computerAskRules is empty, so this is behaviorally identical to settings.permissions (an empty
@@ -118,6 +127,25 @@ function loadProjectContext() {
118
127
  }
119
128
  return "";
120
129
  }
130
+ // Embodiment guidance, appended only when computer control is on. It steers Aurora to READ the screen
131
+ // with chauffeur's textual accessibility tree instead of hand-rolling osascript — the exact loop that
132
+ // failed on Slack (AppleScript can't read Electron UIs). chauffeur is reachable either via the scoped
133
+ // embodiment hub or the full fleet MCP.
134
+ const chauffeurReady = !!embodimentHub || settings.mcp;
135
+ const EMBODIMENT_GUIDE = settings.computer.enabled
136
+ ? `\n## Controlling this computer\nComputer control is ON (every action asks the owner first). Drive apps with ` +
137
+ `computer_app_open / computer_app_activate, computer_type, computer_key, computer_click, computer_screenshot.` +
138
+ (chauffeurReady
139
+ ? ` To SEE the screen, use chauffeur: call chauffeur:list_windows to enumerate windows (each with pid + ` +
140
+ `window_id + title), then chauffeur:get_window_state {pid, window_id} to read a window's UI as a TEXT ` +
141
+ `accessibility tree — labels, values, and clickable elements with coordinates. Act via chauffeur:click / ` +
142
+ `chauffeur:type_text / chauffeur:press_key using that element info. Do NOT hand-write osascript or System ` +
143
+ `Events to scrape a GUI: AppleScript cannot reliably read Electron apps (Slack, VS Code, Discord) and will ` +
144
+ `error — always read them with chauffeur:get_window_state instead.`
145
+ : ` NOTE: reliably READING on-screen UI (especially Electron apps like Slack) needs the chauffeur driver, ` +
146
+ `which is not installed here; computer_screenshot only saves a PNG you cannot read back yet. Do not ` +
147
+ `hand-write osascript to scrape a GUI — it will error on Electron apps.`)
148
+ : "";
121
149
  const SYSTEM_PROMPT = (settings.systemPrompt ??
122
150
  `You are Operator, AXE's terminal coding agent — built by AXE, running on AXE's Aurora model. Refer to ` +
123
151
  `yourself as Operator and to the platform as AXE; never call yourself or the platform Claude, ` +
@@ -140,7 +168,7 @@ const SYSTEM_PROMPT = (settings.systemPrompt ??
140
168
  `head -80","timeout_ms":60000}. Do NOT use an unbounded find / (too slow, it times out). Also check ` +
141
169
  `~/.axe/repos and any folder ls ~ revealed, and widen the pattern (a repo may be named slightly ` +
142
170
  `differently). Only report not-found after this real search, and say exactly where you looked.`) +
143
- loadProjectContext();
171
+ loadProjectContext() + EMBODIMENT_GUIDE;
144
172
  const MAX_BG = 4; // concurrent background sub-agents — all share the single Aurora 1M endpoint, so cap fan-out
145
173
  const HELP = [
146
174
  "commands:",
@@ -237,6 +265,7 @@ function Root() {
237
265
  systemPrompt: SYSTEM_PROMPT,
238
266
  router: buildRouter(),
239
267
  mcp: settings.mcp,
268
+ mcpHub: embodimentHub, // scoped chauffeur hub when embodiment is on (undefined otherwise → no change)
240
269
  maxTokens: settings.maxTokens,
241
270
  temperature: settings.temperature,
242
271
  recall: settings.memory.recall,
package/dist/mcp/index.js CHANGED
@@ -29,7 +29,10 @@ export class McpHub {
29
29
  return;
30
30
  this.clients.push(client);
31
31
  try {
32
+ const allow = s.tools && s.tools.length ? new Set(s.tools) : null;
32
33
  for (const def of await client.listTools()) {
34
+ if (allow && !allow.has(def.name))
35
+ continue; // curated allowlist: skip un-listed tools
33
36
  this.tools.set(`${s.name}${SEP}${def.name}`, { server: s.name, client, def });
34
37
  }
35
38
  }
@@ -0,0 +1,59 @@
1
+ // Chauffeur — the robust computer-use backend for Operator's embodiment (macOS + cross-platform). It is
2
+ // a separate driver process (com.axe.chauffeur, granted Accessibility + Screen Recording) that we speak
3
+ // to over MCP stdio. Why it exists alongside the osascript computer_* tools: osascript can DRIVE apps but
4
+ // has no reliable way to READ a modern UI — asked to read an Electron app (Slack) it returns -1728/-2740
5
+ // errors, so the model resorts to hand-rolled AppleScript and fails. Chauffeur returns the UI as TEXT
6
+ // (`list_windows`, `get_window_state` → an accessibility tree in markdown), which a local model can act on
7
+ // directly without vision. This module is node-only and imported solely from cli.tsx — never the mobile
8
+ // bundle — so it may reach for node builtins lazily like the rest of the embodiment path.
9
+ import { McpHub } from "../mcp/index.js";
10
+ // Curated allowlist: chauffeur exposes 56 tools; a local model's tool-calling drowns if we advertise them
11
+ // all, so we surface only the desktop-control essentials. Ordered read → window/app → input → clipboard.
12
+ export const CHAUFFEUR_TOOLS = [
13
+ "list_windows", "get_window_state", "get_desktop_state", "list_apps", // inspect (textual UI reads)
14
+ "launch_app", "bring_to_front", // window/app management
15
+ "click", "double_click", "right_click", "type_text", "press_key", "hotkey", // input
16
+ "scroll", "move_cursor", "drag", "invoke_menu", "set_value",
17
+ "clipboard_read", "clipboard_write",
18
+ ];
19
+ // The namespaced names the hub exposes to the model (server:tool) — used to force each to "ask" (fg) /
20
+ // "deny" (bg sub-agents), mirroring the osascript computer_* posture.
21
+ export const CHAUFFEUR_TOOL_NAMES = CHAUFFEUR_TOOLS.map((t) => `chauffeur:${t}`);
22
+ // Resolve the chauffeur binary: explicit override, then the fleet install path, else bare `chauffeur` on
23
+ // PATH. Returns null only when nothing is found, so cli.tsx can skip wiring a dead hub.
24
+ async function resolveBinary() {
25
+ const override = process.env.KODE_CHAUFFEUR_BIN;
26
+ if (override)
27
+ return override;
28
+ const { existsSync } = await import("node:fs");
29
+ const { homedir } = await import("node:os");
30
+ const local = `${homedir()}/.local/bin/chauffeur-local`;
31
+ if (existsSync(local))
32
+ return local;
33
+ // Fall back to PATH resolution; if `chauffeur` isn't there either, give up (no dead hub, no failed spawn).
34
+ try {
35
+ const { execFileSync } = await import("node:child_process");
36
+ const p = execFileSync("command", ["-v", "chauffeur"], { shell: "/bin/sh", encoding: "utf8" }).trim();
37
+ return p || null;
38
+ }
39
+ catch {
40
+ return null;
41
+ }
42
+ }
43
+ /** Build a chauffeur-only MCP hub (curated tools, `mcp --direct` so it self-contains without a daemon),
44
+ * or null when chauffeur isn't installed. Injected into the foreground Session when computer control is
45
+ * enabled, so embodiment gets the robust driver without turning on the whole fleet MCP surface. */
46
+ export async function buildChauffeurHub() {
47
+ const command = await resolveBinary();
48
+ if (!command)
49
+ return null;
50
+ const server = {
51
+ name: "chauffeur",
52
+ transport: "stdio",
53
+ command,
54
+ args: ["mcp", "--direct"], // --direct = own the runtime in-process; no separate `chauffeur serve` daemon
55
+ advertise: true,
56
+ tools: [...CHAUFFEUR_TOOLS], // curated allowlist (the McpHub filters discovery to these)
57
+ };
58
+ return new McpHub([server]);
59
+ }
@@ -0,0 +1,19 @@
1
+ // Home-relative path expansion for the file tools. `shell_exec` runs through a shell, which expands a
2
+ // leading `~` itself; the file tools (file_read/file_write/file_edit/grep_search) call fs directly, so
3
+ // without this a path like "~/Downloads/x.md" is treated as RELATIVE to cwd — it lands in a literal
4
+ // folder named "~" under the working directory, the tool reports success, and the user never sees the
5
+ // file where they asked for it. Expanding here makes the file tools agree with the shell.
6
+ //
7
+ // Node-free by construction (reads process.env only, no imports) so the tools module still loads in the
8
+ // headless conformance runner. Only a LEADING ~ is a home reference: bare "~" and "~/rest"; "~user" (a
9
+ // different account's home) and a ~ anywhere but the first character are left untouched, matching the shell.
10
+ export function expandPath(p) {
11
+ const home = process.env.HOME ?? process.env.USERPROFILE ?? "";
12
+ if (!home)
13
+ return p;
14
+ if (p === "~")
15
+ return home;
16
+ if (p.startsWith("~/"))
17
+ return home + p.slice(1);
18
+ return p;
19
+ }
@@ -7,6 +7,7 @@
7
7
  const nodeImport = (m) => import(m);
8
8
  import { MemoryStore } from "../memory/index.js";
9
9
  import { pexecFile } from "./exec.js";
10
+ import { expandPath } from "./paths.js";
10
11
  import { deniedWriteAsync, deniedReadAsync, wrapShell } from "./sandbox.js";
11
12
  import { ensureSearxng, noteSearxngUsed } from "./searxng.js";
12
13
  // execFile helper lives in ./exec (shared with computer.ts — one copy, not two).
@@ -17,7 +18,7 @@ async function shellExec(args) {
17
18
  const command = str(args.command);
18
19
  if (!command)
19
20
  return "error: no command given";
20
- const cwd = args.cwd ? str(args.cwd) : undefined;
21
+ const cwd = args.cwd ? expandPath(str(args.cwd)) : undefined;
21
22
  const timeout = Number(args.timeout_ms ?? 120_000);
22
23
  const MAXBUF = 64 * 1024 * 1024; // 64MB — big greps/finds no longer hard-fail on a 10MB cap
23
24
  // Run under the OS sandbox when KODE_SANDBOX is on (macOS sandbox-exec); otherwise plain bash. The
@@ -52,7 +53,7 @@ async function shellExec(args) {
52
53
  const FILE_READ_DEFAULT_LIMIT_LINES = 2000;
53
54
  const FILE_READ_MAX_CHARS = 40_000;
54
55
  async function fileRead(args) {
55
- const path = str(args.path);
56
+ const path = expandPath(str(args.path));
56
57
  if (!path)
57
58
  return "error: no path given";
58
59
  const blocked = await deniedReadAsync(path); // sandbox on: refuse reads of credential paths (exfil guard)
@@ -79,7 +80,7 @@ async function fileRead(args) {
79
80
  }
80
81
  }
81
82
  async function fileWrite(args) {
82
- const path = str(args.path);
83
+ const path = expandPath(str(args.path));
83
84
  if (!path)
84
85
  return "error: no path given";
85
86
  const blocked = await deniedWriteAsync(path); // async: realpath closes the symlink-laundering gap
@@ -97,7 +98,7 @@ async function fileWrite(args) {
97
98
  }
98
99
  }
99
100
  async function fileEdit(args) {
100
- const path = str(args.path);
101
+ const path = expandPath(str(args.path));
101
102
  const oldStr = str(args.old_string);
102
103
  const newStr = str(args.new_string);
103
104
  const replaceAll = Boolean(args.replace_all);
@@ -125,7 +126,7 @@ async function fileEdit(args) {
125
126
  }
126
127
  async function grepSearch(args) {
127
128
  const pattern = str(args.pattern);
128
- const path = str(args.path, ".");
129
+ const path = expandPath(str(args.path, "."));
129
130
  if (!pattern)
130
131
  return "error: no pattern given";
131
132
  // -s suppresses errors for unreadable/special files (sockets, FIFOs, permission-denied) that a
@@ -191,7 +192,7 @@ async function listDirectory(args) {
191
192
  }
192
193
  async function gitCommand(args) {
193
194
  const gitArgs = Array.isArray(args.args) ? args.args.map(String) : [];
194
- const cwd = args.cwd ? str(args.cwd) : undefined;
195
+ const cwd = args.cwd ? expandPath(str(args.cwd)) : undefined;
195
196
  if (!gitArgs.length)
196
197
  return "error: no args given";
197
198
  try {
@@ -228,7 +229,7 @@ async function checkpoint(args) {
228
229
  const summary = str(args.summary);
229
230
  if (!summary)
230
231
  return "error: no summary given";
231
- const workspace = args.workspace ? str(args.workspace) : process.cwd();
232
+ const workspace = args.workspace ? expandPath(str(args.workspace)) : process.cwd();
232
233
  const push = Boolean(args.push);
233
234
  try {
234
235
  await pexecFile("git", ["add", "-A"], { cwd: workspace });
@@ -363,7 +364,7 @@ async function shellBackground(args) {
363
364
  const running = [...bgJobs.values()].filter((j) => !j.done).length;
364
365
  if (running >= BG_MAX_RUNNING)
365
366
  return `error: ${BG_MAX_RUNNING} background jobs already running — bash_kill one before starting another`;
366
- const cwd = args.cwd ? str(args.cwd) : undefined;
367
+ const cwd = args.cwd ? expandPath(str(args.cwd)) : undefined;
367
368
  const { spawn } = await nodeImport("node:child_process");
368
369
  const { file, args: argv } = await wrapShell(command); // same OS sandbox wrap as shell_exec
369
370
  const id = `sh${++bgSeq}`;
@@ -1,20 +1,65 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Box, Text } from "ink";
3
- export function StatusRule({ route, ctxPct, version, build, user, tier, planMode, thinkMode }) {
4
- const who = user ? `⬤ ${user} · ` : "";
5
- const seat = tier && tier !== "admin" ? `⛨ ${tier} · ` : ""; // a narrowed seat is visible; the owner's admin is not
6
- const plan = planMode ? `◔ plan · ` : ""; // read-only research mode is visible while active
7
- const think = thinkMode === "ultrathink" ? `✲✲ ultrathink · ` : thinkMode === "think" ? `✲ think · ` : "";
8
- // Info block: think · plan · seat · identity · route · ctx% · version. One string so the width math is exact.
9
- const info = `${think}${plan}${seat}${who}${route} · ${Math.round(ctxPct)}% · v${version}${build ? ` ·${build}` : ""}`;
10
- // The full right-hand content, styled below in segments (✷ magenta, OPERATOR bold, info dim). This
11
- // plain string is only used to measure width so the leading rule fills precisely.
12
- const right = `✷ OPERATOR · ${info} ─`;
3
+ // Conservative terminal cell width: ASCII, Latin punctuation (·), and the box-drawing block (─, ≤ U+257F)
4
+ // are one cell; anything above the box-drawing block is a symbol/dingbat/geometric glyph the terminal
5
+ // font is free to render two cells wide, so we count it as 2. Over-estimating is safe (a shorter rule);
6
+ // under-estimating wraps the line and creeps the frame. See ruleFill for why this must not lie.
7
+ export function cellWidth(s) {
8
+ let w = 0;
9
+ for (const ch of s)
10
+ w += (ch.codePointAt(0) ?? 0) >= 0x2580 ? 2 : 1;
11
+ return w;
12
+ }
13
+ // Truncate `s` to at most `max` terminal cells, measured with cellWidth (so a double-width glyph counts
14
+ // for two), appending a single-cell ellipsis when anything was cut. Whole code points only — never split
15
+ // one, which would leave a stray surrogate and a torn glyph.
16
+ export function truncateToWidth(s, max) {
17
+ if (max <= 0)
18
+ return "";
19
+ if (cellWidth(s) <= max)
20
+ return s;
21
+ let w = 0, out = "";
22
+ for (const ch of s) {
23
+ const cw = cellWidth(ch);
24
+ if (w + cw > max - 1)
25
+ break; // reserve one cell for the ellipsis
26
+ out += ch;
27
+ w += cw;
28
+ }
29
+ return out + "…";
30
+ }
31
+ // The dim `info` string (right of the wordmark) and the full measured `right` line, kept as one pure
32
+ // function so the width math is testable without a render. `info` = think · plan · seat · identity ·
33
+ // route · ctx% · version; `right` prefixes the ✷ OPERATOR wordmark and suffixes the trailing " ─". When
34
+ // the terminal is too narrow to hold every badge, `info` is truncated so cellWidth(right) ≤ cols-3 —
35
+ // which keeps the leading fill ≥ 1 and the whole line at cols-1, so the rule never becomes the line that
36
+ // wraps (the creep bug) no matter how many badges are lit or how narrow the window.
37
+ export function statusRight(p, cols) {
38
+ const who = p.user ? `⬤ ${p.user} · ` : "";
39
+ const seat = p.tier && p.tier !== "admin" ? `⛨ ${p.tier} · ` : ""; // a narrowed seat shows; owner's admin doesn't
40
+ const plan = p.planMode ? `◔ plan · ` : ""; // read-only research mode is visible while active
41
+ const think = p.thinkMode === "ultrathink" ? `✲✲ ultrathink · ` : p.thinkMode === "think" ? `✲ think · ` : "";
42
+ let info = `${think}${plan}${seat}${who}${p.route} · ${Math.round(p.ctxPct)}% · v${p.version}${p.build ? ` ·${p.build}` : ""}`;
43
+ let right = `✷ OPERATOR · ${info} ─`;
44
+ const maxRight = cols - 3; // leaves fill ≥ 1 and total = cols-1
45
+ if (cellWidth(right) > maxRight) {
46
+ const framing = cellWidth(right) - cellWidth(info); // the wordmark + separators + trailing " ─"
47
+ info = truncateToWidth(info, maxRight - framing);
48
+ right = `✷ OPERATOR · ${info} ─`;
49
+ }
50
+ return { info, right };
51
+ }
52
+ // Leading-dash count so the whole line renders at cols-1, NEVER cols. A line exactly the terminal width
53
+ // auto-wraps to a 2nd physical row Ink's height accounting misses, so its per-render erase is off by one
54
+ // and the whole dynamic frame (incl. the input) creeps UP the screen on each keystroke. Total rendered =
55
+ // fill + 1 (space) + cellWidth(right); solving fill so that equals cols-1 gives cols - cellWidth(right) - 2.
56
+ export function ruleFill(right, cols) {
57
+ return Math.max(1, cols - cellWidth(right) - 2);
58
+ }
59
+ export function StatusRule(props) {
13
60
  const cols = process.stdout.columns ?? 80;
14
- // Total width = fill + 1 space + right. Fill to cols-1, NOT cols: a line exactly the terminal width
15
- // auto-wraps to a 2nd physical line Ink's height accounting misses, so its per-render erase is off by
16
- // one and the whole dynamic frame (incl. the input) creeps UP the screen on each keystroke.
17
- const fill = Math.max(1, cols - right.length - 2);
61
+ const { info, right } = statusRight(props, cols);
62
+ const fill = ruleFill(right, cols);
18
63
  // Enterprise header: a dim rule sweeping to a magenta ✷ mark + bright OPERATOR wordmark + dim info,
19
64
  // sitting just above the composer (the input is bounded between this and the InputRule below).
20
65
  return (_jsxs(Box, { children: [_jsx(Text, { dimColor: true, children: "─".repeat(fill) + " " }), _jsx(Text, { color: "magenta", children: "\u2737 " }), _jsx(Text, { bold: true, children: "OPERATOR" }), _jsx(Text, { dimColor: true, children: ` · ${info} ─` })] }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0perator/operator",
3
- "version": "0.1.39",
3
+ "version": "0.1.41",
4
4
  "description": "Operator (KODE) — TypeScript + Ink terminal coding agent. Full-frame render, single-engine core shared across CLI/web/mobile; runs against a local Aurora model.",
5
5
  "type": "module",
6
6
  "bin": {