@0perator/operator 0.1.332 → 0.1.334

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 (37) hide show
  1. package/dist/auth/byo.js +5 -0
  2. package/dist/auth/commands.js +1 -1
  3. package/dist/cli.js +2 -1
  4. package/dist/config/persona.js +42 -7
  5. package/dist/config/settings.js +29 -5
  6. package/dist/engine/agent.js +57 -4
  7. package/dist/engine/anthropic-chat.js +4 -4
  8. package/dist/engine/aurora.js +8 -1
  9. package/dist/engine/compaction.js +4 -2
  10. package/dist/engine/decision-points.js +78 -0
  11. package/dist/engine/moa.js +4 -1
  12. package/dist/engine/router-adapter.js +2 -0
  13. package/dist/engine/selfheal.js +41 -0
  14. package/dist/router/free-models.js +3 -2
  15. package/dist/router/models.js +15 -6
  16. package/dist/services/preflight.js +17 -2
  17. package/dist/session.js +25 -13
  18. package/dist/tools/doc-text.js +129 -0
  19. package/dist/tools/paths.js +13 -1
  20. package/dist/tools/registry.js +117 -44
  21. package/dist/tools/vision-gateway.js +55 -0
  22. package/dist/ui/QuestionPrompt.js +4 -3
  23. package/dist/ui/modelPicker.js +2 -2
  24. package/package.json +1 -1
  25. package/dist/engine/cli.js +0 -1171
  26. package/dist/router/models.js.bak +0 -78
  27. package/dist/router/models.js.bak-1791259923 +0 -78
  28. package/dist/router/models.js.bak-pre-gateway +0 -78
  29. package/dist/router/models.js.bak-pre-patch2 +0 -78
  30. package/dist/router/models.js.bak2 +0 -78
  31. package/dist/services/model-autodetect.js +0 -240
  32. package/dist/tools/native-redirect.js +0 -140
  33. package/dist/tools/power-tools.js +0 -627
  34. package/dist/tools/registry.js.bak-1791259948 +0 -1914
  35. package/dist/tools/registry.js.bak-pre-plugins +0 -1914
  36. package/dist/ui/BusTray.js +0 -70
  37. package/dist/ui/resize.js +0 -160
@@ -1,70 +0,0 @@
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/resize.js DELETED
@@ -1,160 +0,0 @@
1
- import { cellWidth } from "./StatusRule.js";
2
- // Resize-safe stdout for the INLINE Ink frame. Ink redraws by erasing the previous frame with
3
- // ansi-escapes' eraseLines(n), where n is the number of LOGICAL lines it last wrote. That is only the number
4
- // of terminal rows while no line wraps. When the window SHRINKS, the terminal reflows what is already on
5
- // screen: every line wider than the new width (the status rule, bottom rule and footer are all ~full-width)
6
- // now spans 2+ rows, so the frame is physically taller than Ink thinks and eraseLines(n) climbs too few rows
7
- // — the top of the old frame (status line + "› " prompt) stays behind and the new frame is drawn below it.
8
- // A drag fires a resize event per step and each one redraws, so each step strands another copy: the
9
- // status/mode line spamming down the screen. (The earlier fix cleared on a 16ms debounce, which can't help:
10
- // Ink's own clear() erases by the same stale count, and a fast drag never lets the debounce fire.)
11
- //
12
- // So: wrap the stream Ink writes to, and do two things.
13
- // 1. Count rows truthfully. We remember the last frame Ink wrote and the width it was written at; when the
14
- // terminal has since gotten NARROWER and a redraw's erase prefix undercounts the rows that frame now
15
- // occupies, swap it for the true count. At an unchanged (or wider) width the write is passed through
16
- // byte-for-byte — normal rendering is untouched.
17
- // 2. Redraw once per drag, not once per step. Resize listeners registered through the wrapper (Ink's own
18
- // layout pass, useTerminalSize) fire after the window has been quiet for RESIZE_SETTLE_MS. Redrawing every
19
- // step makes a scrolled terminal creep: each step the old frame reflows taller (pushing the transcript up
20
- // a row), the redraw shrinks it back and leaves a blank row at the bottom, so the cursor climbs the
21
- // viewport until the top of the frame is in scrollback — out of reach of any erase.
22
- // Public Ink API only (the `stdout` render option); nothing is patched. Assumes the terminal reflows on resize
23
- // (iTerm2, Terminal.app, Ghostty, kitty, WezTerm, VS Code do — and the duplicates in the field prove the
24
- // reporter's does).
25
- const ESC = "\x1b";
26
- const ERASE_LINE = `${ESC}[2K`;
27
- const CURSOR_UP = `${ESC}[1A`;
28
- const CURSOR_LEFT = `${ESC}[G`;
29
- // How log-update opens a redraw: eraseLines(n) = n × erase-line joined by cursor-up, then cursor-left.
30
- const ERASE_PREFIX = new RegExp(`^(?:${ESC}\\[2K${ESC}\\[1A)*${ESC}\\[2K${ESC}\\[G`);
31
- // CSI (colors, cursor) and OSC (hyperlinks) — zero-width in the frame, must not count toward row math.
32
- const ANSI = new RegExp(`${ESC}\\[[0-?]*[ -/]*[@-~]|${ESC}\\][^\\x07${ESC}]*(?:\\x07|${ESC}\\\\)`, "g");
33
- const CLEAR_SCREEN = `${ESC}[2J`; // Ink's full-redraw path (frame as tall as the window) starts with this
34
- /** Quiet time after the last resize event before listeners fire — long enough to ride out one drag (events
35
- * arrive every ~16ms), short enough that a single resize still redraws before you notice. */
36
- export const RESIZE_SETTLE_MS = 80;
37
- /** The erase Ink's log-update emits for `n` rows — the cursor ends on the top row, column 0. */
38
- export function eraseLines(n) {
39
- let out = "";
40
- for (let i = 0; i < n; i++)
41
- out += ERASE_LINE + (i < n - 1 ? CURSOR_UP : "");
42
- return n > 0 ? out + CURSOR_LEFT : out;
43
- }
44
- /** Terminal rows ONE logical line occupies at width `cols`: placed cell by cell the way a terminal does, so a
45
- * double-width glyph that doesn't fit the last column wraps whole to the next row. Always ≥ 1 (a blank line
46
- * still takes a row). Measured with StatusRule's cellWidth — the repo's model of the real terminal, which
47
- * counts the dingbats macOS renders double-width as 2. Here over-counting is the safe side: it erases one
48
- * spare row (usually the blank spacer above the frame), while under-counting strands a copy of the frame. */
49
- export function wrappedRows(line, cols) {
50
- if (cols <= 0)
51
- return 1;
52
- let rows = 1;
53
- let col = 0;
54
- for (const ch of line.replace(ANSI, "")) {
55
- const w = cellWidth(ch);
56
- if (col + w > cols) {
57
- rows++;
58
- col = 0;
59
- }
60
- col += w;
61
- }
62
- return rows;
63
- }
64
- /** Rows a frame occupies at width `cols`, counting the empty row the cursor rests on after the frame's
65
- * trailing newline — exactly what Ink's own eraseLines(lines + 1) assumes when nothing wraps. */
66
- export function frameRows(lines, cols) {
67
- let rows = 1;
68
- for (const line of lines)
69
- rows += wrappedRows(line, cols);
70
- return rows;
71
- }
72
- /** Wrap `stream` (the real stdout) for Ink's `stdout` render option. `write` and 'resize' listeners are
73
- * intercepted; everything else is delegated to the real stream. */
74
- export function createResizeSafeStdout(stream = process.stdout, settleMs = RESIZE_SETTLE_MS) {
75
- // The last text Ink wrote, as lines, and the width it was written at. Ink writes the frame LAST in every
76
- // redraw (static output and patched console output go first), so "the last newline-terminated text
77
- // written" is the frame on screen.
78
- let frame;
79
- function rewrite(s) {
80
- const prefix = ERASE_PREFIX.exec(s);
81
- const text = prefix ? s.slice(prefix[0].length) : s;
82
- // A minimized/detached window reports 0 columns: the terminal hasn't reflowed anything we can reason about,
83
- // so make no correction then. Ink lays the frame out at 80 in that state, which is what we record.
84
- const live = stream.columns > 0 ? stream.columns : 0;
85
- const cols = live || 80;
86
- let out = s;
87
- if (prefix && frame && live > 0 && live < frame.cols) {
88
- const erased = prefix[0].split(ERASE_LINE).length - 1;
89
- // Only act when Ink's count is what we expect for the frame we saw — if the two ever disagree we don't
90
- // know what is on screen, so leave Ink's erase alone rather than guess.
91
- if (erased === frame.lines.length + 1) {
92
- const rows = Math.min(frameRows(frame.lines, live), stream.rows > 0 ? stream.rows : Infinity);
93
- if (rows > erased)
94
- out = eraseLines(rows) + text;
95
- }
96
- }
97
- if (text.includes(CLEAR_SCREEN) || (prefix && !text.endsWith("\n"))) {
98
- frame = undefined; // Ink's full-clear redraw, or an erase-only write (its clear()): nothing we can vouch for is on screen
99
- }
100
- else if (text.endsWith("\n")) {
101
- frame = { lines: text.slice(0, -1).split("\n"), cols };
102
- } // else: a bare control write (cursor show/hide…) — the frame on screen is unchanged
103
- return out;
104
- }
105
- const write = (chunk, ...rest) => stream.write.call(stream, typeof chunk === "string" ? rewrite(chunk) : chunk, ...rest);
106
- // 'resize' listeners registered through the wrapper share ONE debounced subscription to the real stream.
107
- const resizeListeners = new Set();
108
- let settleTimer;
109
- const onRawResize = () => {
110
- clearTimeout(settleTimer);
111
- settleTimer = setTimeout(() => {
112
- settleTimer = undefined;
113
- // Latest-registered first: components (useTerminalSize) re-render at the new width before Ink's own
114
- // layout pass (registered at construction) redraws, so the one redraw is the finished frame.
115
- for (const fn of [...resizeListeners].reverse())
116
- fn();
117
- }, settleMs);
118
- settleTimer.unref?.();
119
- };
120
- const addResizeListener = (fn) => {
121
- if (!resizeListeners.size)
122
- stream.on("resize", onRawResize);
123
- resizeListeners.add(fn);
124
- };
125
- const removeResizeListener = (fn) => {
126
- resizeListeners.delete(fn);
127
- if (!resizeListeners.size) {
128
- stream.off("resize", onRawResize);
129
- clearTimeout(settleTimer);
130
- settleTimer = undefined;
131
- }
132
- };
133
- const wrapper = new Proxy(stream, {
134
- get(target, prop) {
135
- if (prop === "write")
136
- return write;
137
- if (prop === "on" || prop === "addListener") {
138
- return (event, fn) => {
139
- if (event === "resize")
140
- addResizeListener(fn);
141
- else
142
- target.on(event, fn);
143
- return wrapper;
144
- };
145
- }
146
- if (prop === "off" || prop === "removeListener") {
147
- return (event, fn) => {
148
- if (event === "resize")
149
- removeResizeListener(fn);
150
- else
151
- target.off(event, fn);
152
- return wrapper;
153
- };
154
- }
155
- const value = Reflect.get(target, prop, target);
156
- return typeof value === "function" ? value.bind(target) : value;
157
- },
158
- });
159
- return wrapper;
160
- }