@0perator/operator 0.1.41 → 0.1.43

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.41";
22
+ const VERSION = "0.1.43";
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).
@@ -66,12 +66,17 @@ if (settings.computer.enabled) {
66
66
  // hub — not the whole fleet MCP surface. It fills osascript's blind spot: reading a modern/Electron UI.
67
67
  // When the owner has opted into the full fleet (settings.mcp), chauffeur is already reachable there, so
68
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");
69
+ const { buildChauffeurHub, CHAUFFEUR_ACTION_NAMES, CHAUFFEUR_TOOL_NAMES } = await import("./tools/chauffeur.js");
70
70
  if (!settings.mcp)
71
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"]));
72
+ // Foreground: computer_* and chauffeur ACTIONS prompt ("ask"); chauffeur READS (list_windows,
73
+ // get_window_state, …) are intentionally NOT gated, so the model reads the screen freely and completes
74
+ // a task end-to-end without walking the owner through each step. Only real input/mutation asks.
75
+ const askNames = [...COMPUTER_TOOL_NAMES, ...(embodimentHub ? CHAUFFEUR_ACTION_NAMES : [])];
76
+ computerAskRules = Object.fromEntries(askNames.map((n) => [n, "ask"]));
77
+ // Background sub-agents have no approver, so DENY every embodiment tool, reads included.
78
+ const denyNames = [...COMPUTER_TOOL_NAMES, ...(embodimentHub ? CHAUFFEUR_TOOL_NAMES : [])];
79
+ computerDenyRules = Object.fromEntries(denyNames.map((n) => [n, "deny"]));
75
80
  }
76
81
  // Foreground policy = the owner's settings with computer tools forced to "ask". When computer control is
77
82
  // off, computerAskRules is empty, so this is behaviorally identical to settings.permissions (an empty
@@ -141,7 +146,11 @@ const EMBODIMENT_GUIDE = settings.computer.enabled
141
146
  `accessibility tree — labels, values, and clickable elements with coordinates. Act via chauffeur:click / ` +
142
147
  `chauffeur:type_text / chauffeur:press_key using that element info. Do NOT hand-write osascript or System ` +
143
148
  `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.`
149
+ `error — always read them with chauffeur:get_window_state instead. Work the task END-TO-END from the ` +
150
+ `owner's one natural-language instruction: read the screen, decide, and act by chaining these tools ` +
151
+ `yourself, then report the result — do NOT narrate or stop to make the owner walk through each step. ` +
152
+ `Reads (list_windows/get_window_state) run without a prompt; only actions ask for approval. Use ask_user ` +
153
+ `ONLY for a genuine decision that is the owner's to make — never to step through a task you can just do.`
145
154
  : ` NOTE: reliably READING on-screen UI (especially Electron apps like Slack) needs the chauffeur driver, ` +
146
155
  `which is not installed here; computer_screenshot only saves a PNG you cannot read back yet. Do not ` +
147
156
  `hand-write osascript to scrape a GUI — it will error on Electron apps.`)
package/dist/session.js CHANGED
@@ -49,7 +49,8 @@ function makeAskTool(handler) {
49
49
  description: "Ask the owner a single, clarifying multiple-choice question when the task is genuinely ambiguous " +
50
50
  "and a wrong assumption would waste real work. Blocks until they choose, then returns the chosen " +
51
51
  "option. Use SPARINGLY — prefer a sensible default and proceeding; never ask what you can determine " +
52
- "from the code or the request. Provide 2-4 concrete, mutually-exclusive options.",
52
+ "from the code or the request. Provide 2-4 concrete, mutually-exclusive options — the owner ALWAYS " +
53
+ "also gets a free-text 'type your own' choice, so list the likely paths, don't try to enumerate every one.",
53
54
  parameters: {
54
55
  type: "object",
55
56
  properties: {
@@ -66,7 +67,7 @@ function makeAskTool(handler) {
66
67
  if (options.length < 2)
67
68
  return "error: ask_user needs at least 2 options";
68
69
  const answer = await handler(question, options.slice(0, 4));
69
- return `The user chose: ${answer}`;
70
+ return `The user replied: ${answer}`;
70
71
  },
71
72
  };
72
73
  }
@@ -8,16 +8,21 @@
8
8
  // bundle — so it may reach for node builtins lazily like the rest of the embodiment path.
9
9
  import { McpHub } from "../mcp/index.js";
10
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)
11
+ // all, so we surface only the desktop-control essentials. Split into READS (non-destructive inspection —
12
+ // run WITHOUT an approval prompt so the model can read the screen freely and the owner isn't walked
13
+ // through each step) and ACTIONS (input/mutation — always gated "ask" in the foreground, "deny" in bg).
14
+ export const CHAUFFEUR_READ_TOOLS = [
15
+ "list_windows", "get_window_state", "get_desktop_state", "list_apps", "clipboard_read",
16
+ ];
17
+ export const CHAUFFEUR_ACTION_TOOLS = [
14
18
  "launch_app", "bring_to_front", // window/app management
15
19
  "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",
20
+ "scroll", "move_cursor", "drag", "invoke_menu", "set_value", "clipboard_write",
18
21
  ];
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.
22
+ export const CHAUFFEUR_TOOLS = [...CHAUFFEUR_READ_TOOLS, ...CHAUFFEUR_ACTION_TOOLS];
23
+ // Namespaced names (server:tool) the hub exposes. ACTION names are what cli.tsx forces to "ask" (fg);
24
+ // ALL names are what it "deny"s for background sub-agents (no computer use of any kind off the main seat).
25
+ export const CHAUFFEUR_ACTION_NAMES = CHAUFFEUR_ACTION_TOOLS.map((t) => `chauffeur:${t}`);
21
26
  export const CHAUFFEUR_TOOL_NAMES = CHAUFFEUR_TOOLS.map((t) => `chauffeur:${t}`);
22
27
  // Resolve the chauffeur binary: explicit override, then the fleet install path, else bare `chauffeur` on
23
28
  // PATH. Returns null only when nothing is found, so cli.tsx can skip wiring a dead hub.
@@ -1,18 +1,56 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // Interactive clarification (parity with modern coding agents). When the model calls the `ask_user` tool,
3
+ // the shell parks the question here (React state) and this renders it with numbered options. On TOP of the
4
+ // model's options there is ALWAYS a final "Chat about it / type your own" escape hatch: the owner is never
5
+ // boxed into the listed choices — picking it opens a free-text line whose typed answer is returned to the
6
+ // model verbatim. useInput is active ONLY while a question is pending (the Composer is suspended meanwhile),
7
+ // so a digit selects an option rather than typing into the prompt. Mirrors ApprovalPrompt.
8
+ import { useEffect, useState } from "react";
2
9
  import { Box, Text, useInput } from "ink";
10
+ // The always-present final choice. Selecting it lets the owner type their own reply (or just talk it
11
+ // through) instead of picking one of the model's options — so every prompt has an out.
12
+ export const CHAT_LABEL = "Chat about it — type your own reply";
13
+ // Returned to the model when the owner opens the chat line but sends it empty: a clear signal to stop
14
+ // offering a menu and discuss, rather than a blank answer.
15
+ export const DISCUSS = "Let's talk it through — I don't want to pick one of the listed options; discuss it with me.";
16
+ // Pure keystroke reducer (no React, no I/O) so the whole selection + free-text behavior is testable without
17
+ // a TTY. Returns either the next state, or a `resolve` string = the answer to hand back to the model.
18
+ export function questionKey(st, input, key, options) {
19
+ if (st.mode === "type") {
20
+ if (key.return)
21
+ return { resolve: st.buffer.trim() || DISCUSS };
22
+ if (key.escape)
23
+ return { state: { mode: "choose", buffer: "" } }; // back to the menu
24
+ if (key.backspace || key.delete)
25
+ return { state: { ...st, buffer: st.buffer.slice(0, -1) } };
26
+ if (input && !key.ctrl && !key.meta)
27
+ return { state: { ...st, buffer: st.buffer + input } };
28
+ return {};
29
+ }
30
+ if (key.ctrl && input.toLowerCase() === "c")
31
+ return { resolve: options[0] }; // bail = first option
32
+ const chatIndex = options.length + 1;
33
+ const n = Number(input);
34
+ if (Number.isInteger(n) && n >= 1 && n <= options.length)
35
+ return { resolve: options[n - 1] };
36
+ if (n === chatIndex)
37
+ return { state: { mode: "type", buffer: "" } }; // open the free-text line
38
+ return {};
39
+ }
3
40
  export function QuestionPrompt({ pending }) {
41
+ const [st, setSt] = useState({ mode: "choose", buffer: "" });
42
+ useEffect(() => { setSt({ mode: "choose", buffer: "" }); }, [pending]); // reset for each new question
4
43
  useInput((input, key) => {
5
44
  if (!pending)
6
45
  return;
7
- if (key.ctrl && input.toLowerCase() === "c") {
8
- pending.resolve(pending.options[0]);
9
- return;
10
- } // bail = first option
11
- const n = Number(input);
12
- if (Number.isInteger(n) && n >= 1 && n <= pending.options.length)
13
- pending.resolve(pending.options[n - 1]);
46
+ const a = questionKey(st, input, key, pending.options);
47
+ if (a.resolve !== undefined)
48
+ pending.resolve(a.resolve);
49
+ else if (a.state)
50
+ setSt(a.state);
14
51
  }, { isActive: !!pending });
15
52
  if (!pending)
16
53
  return null;
17
- return (_jsxs(Box, { flexDirection: "column", marginTop: 1, marginBottom: 1, borderStyle: "round", borderColor: "cyan", paddingX: 1, children: [_jsxs(Text, { color: "cyan", bold: true, children: ["? ", _jsx(Text, { color: "white", children: pending.question })] }), pending.options.map((o, i) => (_jsxs(Text, { children: [" ", _jsxs(Text, { color: "cyan", children: ["[", i + 1, "]"] }), " ", o] }, i))), _jsx(Text, { dimColor: true, children: " press 1-" + pending.options.length + " to choose" })] }));
54
+ const chatIndex = pending.options.length + 1;
55
+ return (_jsxs(Box, { flexDirection: "column", marginTop: 1, marginBottom: 1, borderStyle: "round", borderColor: "cyan", paddingX: 1, children: [_jsxs(Text, { color: "cyan", bold: true, children: ["? ", _jsx(Text, { color: "white", children: pending.question })] }), pending.options.map((o, i) => (_jsxs(Text, { children: [" ", _jsxs(Text, { color: "cyan", children: ["[", i + 1, "]"] }), " ", o] }, i))), _jsxs(Text, { children: [" ", _jsxs(Text, { color: "cyan", children: ["[", chatIndex, "]"] }), " ", _jsx(Text, { color: "magenta", children: CHAT_LABEL })] }), st.mode === "type" ? (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsxs(Text, { children: [_jsx(Text, { color: "magenta", children: "› " }), st.buffer, _jsx(Text, { color: "cyan", children: "\u258C" })] }), _jsx(Text, { dimColor: true, children: " type your reply · Enter to send · Esc for the menu" })] })) : (_jsx(Text, { dimColor: true, children: ` press 1-${chatIndex} to choose (${chatIndex} = type your own)` }))] }));
18
56
  }
@@ -5,6 +5,35 @@ import { Markdown } from "./Markdown.js";
5
5
  function entryKey(entry) {
6
6
  return entry.kind === "message" ? entry.message.id : entry.step.id;
7
7
  }
8
+ // Rows the live frame must leave free for the spinner + status/input rules + composer + margins. The live
9
+ // streaming message is tailed to (terminal rows - this) so the DYNAMIC (non-Static) frame never grows
10
+ // taller than the window — the Ink failure that collapses the whole frame to the top and scrolls the
11
+ // transcript away. The full text is unaffected: it renders complete via <Static> once it settles.
12
+ // The live tail must keep the WHOLE dynamic (non-Static) frame comfortably under the terminal height —
13
+ // not just fit it. Ink corrupts (clears to the top, scrolls the transcript away) when the dynamic frame
14
+ // approaches the window height, and the worst moment is the settle transition when this frame is erased.
15
+ // So cap the live view to a small slice (≤ ~16 rows, less on short terminals): enough to watch the answer
16
+ // stream, while the full text always renders complete via <Static> once it settles. Pure (dimensions
17
+ // passed in) so the bound is unit-testable.
18
+ export function liveTail(s, rows, cols) {
19
+ const budget = Math.max(6, Math.min(rows - 14, 16)); // rendered rows the live frame may occupy
20
+ const lines = s.split("\n");
21
+ // Walk up from the last line, counting the PHYSICAL rows each takes after wrapping, and keep only what
22
+ // fits the budget — so even all-long-wrapping lines can't push the dynamic frame past the window.
23
+ let used = 0, start = lines.length;
24
+ for (let i = lines.length - 1; i >= 0; i--) {
25
+ const wrapped = Math.max(1, Math.ceil(lines[i].length / cols));
26
+ if (used + wrapped > budget && start !== lines.length)
27
+ break;
28
+ used += wrapped;
29
+ start = i;
30
+ if (used >= budget)
31
+ break;
32
+ }
33
+ if (start <= 0)
34
+ return { text: s, clipped: 0 };
35
+ return { text: lines.slice(start).join("\n"), clipped: start };
36
+ }
8
37
  function renderEntry(entry, live = false) {
9
38
  if (entry.kind === "message") {
10
39
  const { message } = entry;
@@ -14,11 +43,22 @@ function renderEntry(entry, live = false) {
14
43
  if (message.role === "system") {
15
44
  return _jsx(Text, { dimColor: true, children: message.content }); // slash-command output / status notes
16
45
  }
17
- // Thought process first, dimmed and lower-opacity; the real answer follows at full weight, so the
18
- // reasoning reads as recessive scaffolding and the answer stands out (per the requested look).
19
- // Settled answers render as markdown (bold/code/lists/headers formatted, not raw `**`/backticks);
20
- // the LIVE stream stays plain text so a half-open ``` fence can't swallow the text while it types.
21
- return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [message.reasoning ? _jsx(Text, { dimColor: true, children: message.reasoning }) : null, message.content ? (live ? _jsx(Text, { children: message.content }) : _jsx(Markdown, { content: message.content })) : null] }));
46
+ // Settled answers render as markdown (bold/code/lists/headers formatted, not raw `**`/backticks); the
47
+ // LIVE stream stays plain text (a half-open ``` fence can't swallow it) AND is height-bounded: while
48
+ // streaming we show only the tail that fits the window, so the dynamic frame can't overflow. Once the
49
+ // message settles it leaves `live` and renders in full via <Static> below, into scrollback.
50
+ if (live) {
51
+ // Prefer the answer once it starts; before then, tail the reasoning so a long "thinking" stream
52
+ // can't overflow either. Only the in-flight tail is shown here — never the whole message.
53
+ const src = message.content ? message.content : (message.reasoning ?? "");
54
+ if (!src)
55
+ return _jsx(Box, { marginBottom: 1 });
56
+ const { text, clipped } = liveTail(src, process.stdout.rows ?? 24, process.stdout.columns ?? 80);
57
+ const dim = !message.content; // reasoning is dim; the answer is full weight
58
+ return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [clipped > 0 ? _jsx(Text, { dimColor: true, children: `⋯ +${clipped} more line${clipped === 1 ? "" : "s"} above (full text shown when complete)` }) : null, _jsx(Text, { dimColor: dim, children: text })] }));
59
+ }
60
+ // Thought process first, dimmed; the real answer follows at full weight.
61
+ return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [message.reasoning ? _jsx(Text, { dimColor: true, children: message.reasoning }) : null, message.content ? _jsx(Markdown, { content: message.content }) : null] }));
22
62
  }
23
63
  return _jsx(ToolStep, { step: entry.step });
24
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0perator/operator",
3
- "version": "0.1.41",
3
+ "version": "0.1.43",
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": {