@0perator/operator 0.1.274 → 0.1.275

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -143,14 +143,7 @@ async function bringUp() {
143
143
  if (all.out === CONTAINER) {
144
144
  return (await docker(["start", CONTAINER])).code === 0;
145
145
  }
146
- // fresh run — pull the image FIRST with generous headroom. A cold `docker run` pulls inline, and the
147
- // first-ever ~376MB SearXNG pull routinely exceeds a 60s run timeout on a normal/slow link → the setup
148
- // Operator does FOR the user would fail silently on install. Pull explicitly (10 min) when the image is
149
- // absent, then run against the now-local image under the short timeout.
150
- if ((await docker(["image", "inspect", "--format", "{{.Id}}", image()], 8_000)).code !== 0) {
151
- if ((await docker(["pull", image()], 600_000)).code !== 0)
152
- return false;
153
- }
146
+ // fresh run
154
147
  const dir = await ensureSettingsDir();
155
148
  const run = await docker([
156
149
  "run", "-d", "--name", CONTAINER, "--restart", "unless-stopped",
@@ -5,18 +5,6 @@ import { theme } from "./theme.js";
5
5
  const GLYPH = { queued: "◌", working: "●", idle: "✓", stopped: "✗" };
6
6
  const COLOR = { queued: theme.muted, working: theme.running, idle: theme.success, stopped: theme.error };
7
7
  const DISPLAY_STATUS = { queued: "queued", working: "running", idle: "done", stopped: "errored" };
8
- // Per-agent accent — each concurrent sub-agent gets its OWN stable colour so you can tell them apart at a glance
9
- // when several run at once (grandmaster: a team you can read). The status glyph stays status-coloured (working /
10
- // done / errored), so a row shows BOTH which agent (label hue) and how it's doing (glyph). Named ANSI colours
11
- // render on every terminal level; red/green/yellow are omitted here so an agent's hue never reads as a status.
12
- const AGENT_PALETTE = ["cyan", "magenta", "blue", "cyanBright", "magentaBright", "blueBright", "white"];
13
- function agentColor(a) {
14
- const key = a.id || a.label;
15
- let h = 0;
16
- for (let i = 0; i < key.length; i++)
17
- h = (h * 31 + key.charCodeAt(i)) >>> 0;
18
- return AGENT_PALETTE[h % AGENT_PALETTE.length];
19
- }
20
8
  const toks = (n) => (n >= 1000 ? `${(n / 1000).toFixed(1)}k` : `${n}`);
21
9
  // Live per-agent metrics: tokens generated + elapsed. While working, elapsed is derived from
22
10
  // startedAt at render time (updates each round tick); once finished, the wall time is frozen.
@@ -113,5 +101,5 @@ export function BgPanel({ agents, title = "sub-agents" }) {
113
101
  // frame SHORT — BG_MAX_VISIBLE caps rows, activity lines are capped — so the box stays a few rows tall.
114
102
  // If stray border rows ever reappear on a very long turn, drop `borderStyle`/`borderColor` for the
115
103
  // borderless column (the label line alone still heads it).
116
- return (_jsxs(Box, { flexDirection: "column", marginTop: 1, borderStyle: "round", borderColor: theme.muted, paddingX: 1, children: [_jsx(Text, { dimColor: true, children: label }), shown.map((a) => (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { justifyContent: "space-between", children: [_jsxs(Text, { children: [a.status === "working" ? _jsx(OrbitGlyph, {}) : _jsx(Text, { color: COLOR[a.status], children: GLYPH[a.status] }), " ", _jsx(Text, { color: agentColor(a), bold: true, children: a.label }), a.round != null ? ` · round ${a.round}` : "", a.status === "working" && roundActivity(a) ? _jsxs(Text, { color: theme.accent, children: [" \u00B7 ", cap(roundActivity(a), 28)] }) : null] }), _jsx(Text, { dimColor: true, children: (() => { const m = metrics(a); const ds = DISPLAY_STATUS[a.status]; return m ? `${m} · ${ds}` : ds; })() })] }), _jsx(ActivityLines, { a: a }), _jsx(GrandmasterLine, { a: a }), a.status === "idle" && _jsx(Box, { paddingLeft: 2, children: _jsx(Text, { dimColor: true, children: "result posted \u2014 scroll up or /agents to review" }) }), a.status === "stopped" && _jsx(Box, { paddingLeft: 2, children: _jsx(Text, { dimColor: true, children: "errored \u2014 check transcript for details" }) })] }, a.id))), hidden > 0 ? _jsx(Text, { dimColor: true, children: ` +${hidden} more running` }) : null] }));
104
+ return (_jsxs(Box, { flexDirection: "column", marginTop: 1, borderStyle: "round", borderColor: theme.muted, paddingX: 1, children: [_jsx(Text, { dimColor: true, children: label }), shown.map((a) => (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { justifyContent: "space-between", children: [_jsxs(Text, { children: [a.status === "working" ? _jsx(OrbitGlyph, {}) : _jsx(Text, { color: COLOR[a.status], children: GLYPH[a.status] }), " ", a.label, a.round != null ? ` · round ${a.round}` : "", a.status === "working" && roundActivity(a) ? _jsxs(Text, { color: theme.accent, children: [" \u00B7 ", cap(roundActivity(a), 28)] }) : null] }), _jsx(Text, { dimColor: true, children: (() => { const m = metrics(a); const ds = DISPLAY_STATUS[a.status]; return m ? `${m} · ${ds}` : ds; })() })] }), _jsx(ActivityLines, { a: a }), _jsx(GrandmasterLine, { a: a }), a.status === "idle" && _jsx(Box, { paddingLeft: 2, children: _jsx(Text, { dimColor: true, children: "result posted \u2014 scroll up or /agents to review" }) }), a.status === "stopped" && _jsx(Box, { paddingLeft: 2, children: _jsx(Text, { dimColor: true, children: "errored \u2014 check transcript for details" }) })] }, a.id))), hidden > 0 ? _jsx(Text, { dimColor: true, children: ` +${hidden} more running` }) : null] }));
117
105
  }
@@ -0,0 +1,70 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // BusTray — live Switchboard messages surfaced in the Operator TUI as click-to-expand cards. Top-anchored
3
+ // in the fullscreen layout so each card's absolute terminal row is deterministic (topRow + Σ heights above),
4
+ // which is what makes mouse hit-testing reliable without Ink absolute-position measurement. Clicking a card
5
+ // toggles its body (the Phase-1 mouse layer in action). In inline mode (no mouse) the cards still render,
6
+ // just not clickable. Messages are DATA from other agents — shown, never executed.
7
+ import { useEffect, useState } from "react";
8
+ import { Box, Text } from "ink";
9
+ import { useMouse } from "./MouseProvider.js";
10
+ const MAX_BODY_LINES = 8; // cap an expanded card's body so one big message can't dominate the screen
11
+ function wrap(line, width) {
12
+ const w = Math.max(1, width);
13
+ if (line.length <= w)
14
+ return [line];
15
+ const out = [];
16
+ for (let i = 0; i < line.length; i += w)
17
+ out.push(line.slice(i, i + w));
18
+ return out;
19
+ }
20
+ /** Pure layout: assign each message a card with an absolute row (y) and height, given which ids are
21
+ * expanded and the terminal width. Deterministic top-to-bottom stacking from `topRow` — the basis for both
22
+ * render order and click hit-testing. Exported for unit tests. */
23
+ export function trayLayout(messages, expanded, cols, topRow = 1) {
24
+ const width = cols > 0 ? cols : 80;
25
+ const cards = [];
26
+ let y = topRow;
27
+ for (const msg of messages) {
28
+ const isExp = expanded.has(msg.id);
29
+ const bodyLines = isExp
30
+ ? msg.body.split("\n").flatMap((l) => wrap(l, width - 2)).slice(0, MAX_BODY_LINES)
31
+ : [];
32
+ const height = 1 + bodyLines.length;
33
+ cards.push({ msg, y, height, expanded: isExp, bodyLines });
34
+ y += height;
35
+ }
36
+ return cards;
37
+ }
38
+ function preview(body, cols) {
39
+ const one = body.replace(/\s+/g, " ").trim();
40
+ const budget = Math.max(10, (cols > 0 ? cols : 80) - 28);
41
+ return one.length > budget ? one.slice(0, budget - 1) + "…" : one;
42
+ }
43
+ /** The tray. `cols` is the terminal width (for wrapping + region width). Renders nothing when empty. */
44
+ export function BusTray({ messages, cols }) {
45
+ const { registerRegion, enabled } = useMouse();
46
+ const [expanded, setExpanded] = useState(() => new Set());
47
+ const cards = trayLayout(messages, expanded, cols);
48
+ // Register every card's clickable region imperatively (one effect, not a hook-per-card — the message
49
+ // count varies, which would violate rules-of-hooks). A left-press anywhere on a card toggles its body.
50
+ const sig = cards.map((c) => `${c.msg.id}:${c.y}:${c.height}`).join("|");
51
+ useEffect(() => {
52
+ if (!enabled || !cards.length)
53
+ return;
54
+ const disposers = cards.map((c) => registerRegion({ id: `bus:${c.msg.id}`, x: 1, y: c.y, width: Math.max(1, cols), height: c.height }, () => {
55
+ setExpanded((prev) => {
56
+ const next = new Set(prev);
57
+ if (next.has(c.msg.id))
58
+ next.delete(c.msg.id);
59
+ else
60
+ next.add(c.msg.id);
61
+ return next;
62
+ });
63
+ }));
64
+ return () => disposers.forEach((d) => d());
65
+ // eslint-disable-next-line react-hooks/exhaustive-deps
66
+ }, [enabled, registerRegion, cols, sig]);
67
+ if (!messages.length)
68
+ return null;
69
+ return (_jsx(Box, { flexDirection: "column", children: cards.map((c) => (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { color: "cyan", children: [c.expanded ? "▾" : "▸", " ", "📨 ", c.msg.from, c.msg.subject ? ` [${c.msg.subject}]` : "", c.expanded ? "" : `: ${preview(c.msg.body, cols)}`, enabled && !c.expanded ? _jsx(Text, { dimColor: true, children: " \u00B7 click to expand" }) : null] }), c.expanded ? c.bodyLines.map((l, i) => _jsx(Text, { dimColor: true, children: " " + l }, i)) : null] }, c.msg.id))) }));
70
+ }
package/dist/ui/term.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { useState, useEffect } from "react";
2
- import { useStdout } from "ink";
3
2
  // Terminal dimensions, floored to a sane minimum — the ONE place layout reads the window size.
4
3
  // process.stdout.columns/rows report 0 (not undefined) when the window is minimized, hidden, or the
5
4
  // stream is momentarily detached, and `process.stdout.columns ?? 80` does NOT catch 0 (?? only falls
@@ -17,22 +16,18 @@ export function termRows(fallback = 24) {
17
16
  return typeof r === "number" && r > 0 ? r : fallback;
18
17
  }
19
18
  // Reactive terminal size. termCols()/termRows() read the live size AT RENDER TIME, so the pinned UI only
20
- // reflows when something ELSE re-renders — Ink's own resize pass re-lays-out the existing tree but never
21
- // re-runs a component, so the width-dependent rules would sit at the old width until the next keystroke or
22
- // tick. A component that calls this hook re-renders when the window changes, so the status rule / composer /
23
- // footer resize correctly when the terminal grows or shrinks. It subscribes through Ink's stdout (not
24
- // process.stdout) so that in the inline layout it rides the debounced listener of the resize-safe stdout
25
- // (resize.ts) — one redraw per drag instead of one per step.
19
+ // reflows when something ELSE re-renders — after a resize the frame is cleared (cli.tsx) but then sits
20
+ // blank/stale until the next keystroke or tick. A component that calls this hook re-renders the instant the
21
+ // window changes, so the status rule / composer / footer resize correctly when the terminal grows or shrinks.
26
22
  export function useTerminalSize() {
27
- const { stdout } = useStdout();
28
23
  const [size, setSize] = useState(() => ({ cols: termCols(), rows: termRows() }));
29
24
  useEffect(() => {
30
25
  const onResize = () => setSize((prev) => {
31
26
  const next = { cols: termCols(), rows: termRows() };
32
27
  return next.cols === prev.cols && next.rows === prev.rows ? prev : next; // skip no-op renders
33
28
  });
34
- stdout.on?.("resize", onResize);
35
- return () => { stdout.off?.("resize", onResize); };
36
- }, [stdout]);
29
+ process.stdout.on?.("resize", onResize);
30
+ return () => { process.stdout.off?.("resize", onResize); };
31
+ }, []);
37
32
  return size;
38
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0perator/operator",
3
- "version": "0.1.274",
3
+ "version": "0.1.275",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "operator": "dist/cli.js",