@ouro.bot/cli 0.1.0-alpha.175 → 0.1.0-alpha.177

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.
@@ -0,0 +1,296 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.OuroTui = OuroTui;
37
+ const jsx_runtime_1 = require("react/jsx-runtime");
38
+ /**
39
+ * Ouroboros TUI — full terminal interface using Ink v3 + Static.
40
+ *
41
+ * Architecture:
42
+ * <Static> renders completed messages ONCE — they scroll up naturally.
43
+ * Only the "live" area (current streaming + spinner + input) re-renders.
44
+ * This avoids the screen-clearing problem that broke the previous Ink attempt.
45
+ *
46
+ * Design language: ouroboros brand palette from ouroboros.bot / Outlook UI.
47
+ * ZERO business logic here — pure rendering from CliStore state.
48
+ */
49
+ const react_1 = __importStar(require("react"));
50
+ const ink_1 = require("ink");
51
+ const streaming_markdown_1 = require("./streaming-markdown");
52
+ // ─── Ouroboros Brand Palette (ANSI RGB) ─────────────────────────────
53
+ // From packages/outlook-ui/src/style.css and ouroboros.bot
54
+ const OURO = {
55
+ scale: "#2f8f4e", // primary green
56
+ teal: "#4ec9b0", // tool/accent teal
57
+ glow: "#74e08f", // bright green (highlights)
58
+ bone: "#eef2ea", // light text
59
+ mist: "#a5b8a8", // dim text
60
+ shadow: "#708373", // very dim
61
+ fang: "#d35f47", // error red
62
+ gold: "#d6b56f", // warning amber
63
+ moss: "#183325", // subtle bg accent
64
+ separator: "#3a5a40", // dim line separator
65
+ };
66
+ // ─── Ring Spinner (growing/shrinking) ───────────────────────────────
67
+ const RING_FRAMES = ["∙", "○", "◎", "●", "◎", "○"];
68
+ function ringColor(elapsedSec) {
69
+ if (elapsedSec >= 45)
70
+ return OURO.fang;
71
+ if (elapsedSec >= 15)
72
+ return OURO.gold;
73
+ return OURO.scale;
74
+ }
75
+ // ─── Header ─────────────────────────────────────────────────────────
76
+ function Header({ agentName, model, contextPercent, cwd }) {
77
+ const showCtx = contextPercent > 0;
78
+ const info = [agentName, model, cwd, showCtx ? `ctx ${contextPercent}%` : ""].filter(Boolean).join(" · ");
79
+ // 3-segment snake: TAIL (fixed) + MIDDLE (stretches) + HEAD (fixed)
80
+ // From the reference art, segments split at the dots:
81
+ //
82
+ // . . ____
83
+ // __.__________________.____/ O \___/
84
+ // <__.__________________._________/ \
85
+ //
86
+ // TAIL: line1="" line2=" __" line3="<__"
87
+ // MIDDLE: line1=" " line2="_" line3="_" (or text)
88
+ // HEAD: line1=" ____" line2="____/ O \\___/" line3="_________/ \\"
89
+ const HEAD1 = " ____";
90
+ const HEAD2 = "____/ O \\___/";
91
+ const HEAD3 = "_________/ \\";
92
+ const TAIL1 = " ";
93
+ const TAIL2 = " __";
94
+ const TAIL3 = "<__";
95
+ const middleLen = Math.max(info.length, 20);
96
+ const textPad = middleLen - info.length;
97
+ const line1 = TAIL1 + " ".repeat(middleLen) + HEAD1;
98
+ const line2 = TAIL2 + "_".repeat(middleLen) + HEAD2;
99
+ const line3text = info + "_".repeat(textPad);
100
+ return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { color: OURO.scale, children: line1 }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: OURO.scale, children: line2 }), (0, jsx_runtime_1.jsxs)(ink_1.Text, { color: OURO.scale, children: [TAIL3, (0, jsx_runtime_1.jsx)(ink_1.Text, { color: OURO.glow, children: line3text }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: OURO.scale, children: HEAD3 })] })] }));
101
+ }
102
+ // ─── Message Rendering ──────────────────────────────────────────────
103
+ // Flow control tools are invisible to the user — they are internal agent mechanics
104
+ const FLOW_CONTROL_TOOLS = new Set(["settle", "ponder", "observe", "rest"]);
105
+ function ToolResultLine({ tc }) {
106
+ const icon = tc.success !== false ? "✓" : "✗";
107
+ const iconColor = tc.success !== false ? OURO.scale : OURO.fang;
108
+ const argColor = tc.success === false ? OURO.fang : OURO.shadow;
109
+ return ((0, jsx_runtime_1.jsxs)(ink_1.Text, { children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { color: iconColor, children: icon }), " ", (0, jsx_runtime_1.jsx)(ink_1.Text, { color: OURO.teal, children: tc.name }), " ", (0, jsx_runtime_1.jsx)(ink_1.Text, { color: argColor, children: tc.argSummary })] }));
110
+ }
111
+ function MessageBlock({ msg }) {
112
+ if (msg.role === "tool") {
113
+ const visibleCalls = msg.toolCalls?.filter(tc => !FLOW_CONTROL_TOOLS.has(tc.name));
114
+ if (!visibleCalls || visibleCalls.length === 0)
115
+ return (0, jsx_runtime_1.jsx)(ink_1.Box, { height: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Text, { children: " " }) });
116
+ return ((0, jsx_runtime_1.jsx)(ink_1.Box, { flexDirection: "column", children: visibleCalls.map((tc, i) => (0, jsx_runtime_1.jsx)(ToolResultLine, { tc: tc }, i)) }));
117
+ }
118
+ if (msg.role === "user") {
119
+ return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", marginTop: 1, children: [msg.content ? (0, jsx_runtime_1.jsx)(ink_1.Text, { color: OURO.bone, bold: true, children: msg.content }) : null, (0, jsx_runtime_1.jsx)(ink_1.Box, { height: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Text, { children: " " }) })] }));
120
+ }
121
+ if (msg.role === "assistant") {
122
+ return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", children: [msg.content ? (0, jsx_runtime_1.jsx)(streaming_markdown_1.StreamingMarkdown, { text: msg.content }) : null, (0, jsx_runtime_1.jsx)(ink_1.Box, { height: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Text, { children: " " }) })] }));
123
+ }
124
+ return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", marginTop: 1, children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { color: OURO.shadow, children: msg.content }), (0, jsx_runtime_1.jsx)(ink_1.Box, { height: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Text, { children: " " }) })] }));
125
+ }
126
+ // ─── Live Area (re-renders) ─────────────────────────────────────────
127
+ function Spinner({ phrasePool, elapsed }) {
128
+ const [frame, setFrame] = (0, react_1.useState)(0);
129
+ const [currentPhrase, setCurrentPhrase] = (0, react_1.useState)(() => phrasePool.length > 0 ? phrasePool[Math.floor(Math.random() * phrasePool.length)] : "");
130
+ // Animate ring frames
131
+ (0, react_1.useEffect)(() => {
132
+ const iv = setInterval(() => setFrame(f => (f + 1) % RING_FRAMES.length), 120);
133
+ return () => clearInterval(iv);
134
+ }, []);
135
+ // Rotate phrases every 3 seconds
136
+ (0, react_1.useEffect)(() => {
137
+ if (phrasePool.length <= 1)
138
+ return;
139
+ const iv = setInterval(() => {
140
+ setCurrentPhrase(phrasePool[Math.floor(Math.random() * phrasePool.length)]);
141
+ }, 3000);
142
+ return () => clearInterval(iv);
143
+ }, [phrasePool]);
144
+ const color = ringColor(elapsed);
145
+ const timeStr = elapsed > 0 ? `${elapsed}s` : "";
146
+ return ((0, jsx_runtime_1.jsxs)(ink_1.Text, { color: color, children: [RING_FRAMES[frame], " ", timeStr ? (0, jsx_runtime_1.jsxs)(ink_1.Text, { color: OURO.shadow, children: [timeStr, " \u00B7 "] }) : "", currentPhrase] }));
147
+ }
148
+ function formatActiveToolArgs(name, args) {
149
+ switch (name) {
150
+ case "shell":
151
+ return `$ ${args.command ?? "?"}`;
152
+ case "read_file":
153
+ return `path=${args.path ?? "?"}`;
154
+ case "write_file":
155
+ return `path=${args.path ?? "?"}`;
156
+ case "edit_file":
157
+ return args.path ?? "?";
158
+ case "glob":
159
+ return `pattern=${args.pattern ?? "?"}`;
160
+ case "grep":
161
+ return `pattern=${args.pattern ?? "?"} ${args.path ? `path=${args.path}` : ""}`.trim();
162
+ default: {
163
+ // Show first 2 key=value pairs
164
+ const entries = Object.entries(args).slice(0, 2);
165
+ return entries.map(([k, v]) => `${k}=${String(v).slice(0, 50)}`).join(" ");
166
+ }
167
+ }
168
+ }
169
+ function ActiveToolLine({ tool }) {
170
+ // Hide flow control tools from in-progress display
171
+ if (FLOW_CONTROL_TOOLS.has(tool.name))
172
+ return (0, jsx_runtime_1.jsx)(ink_1.Box, { height: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Text, { children: " " }) });
173
+ const argStr = formatActiveToolArgs(tool.name, tool.args);
174
+ return ((0, jsx_runtime_1.jsxs)(ink_1.Text, { children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { color: OURO.shadow, children: "∙" }), " ", (0, jsx_runtime_1.jsx)(ink_1.Text, { color: OURO.teal, children: tool.name }), " ", (0, jsx_runtime_1.jsx)(ink_1.Text, { color: OURO.shadow, children: argStr })] }));
175
+ }
176
+ function LiveArea({ live, elapsed }) {
177
+ return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", children: [live.streamingText ? ((0, jsx_runtime_1.jsx)(streaming_markdown_1.StreamingMarkdown, { text: live.streamingText })) : null, live.activeTool ? ((0, jsx_runtime_1.jsx)(ActiveToolLine, { tool: live.activeTool })) : null, live.loading ? ((0, jsx_runtime_1.jsx)(Spinner, { phrasePool: live.spinnerPhrasePool, elapsed: elapsed })) : null, live.errorMessage ? ((0, jsx_runtime_1.jsxs)(ink_1.Text, { color: OURO.fang, children: ["✗ ", live.errorMessage] })) : null, live.kickMessage ? ((0, jsx_runtime_1.jsxs)(ink_1.Text, { color: OURO.gold, children: ["↻ ", live.kickMessage] })) : null] }));
178
+ }
179
+ // ─── Input ──────────────────────────────────────────────────────────
180
+ function InputArea({ onSubmit, suppressed, onCtrlC, agentName, model, history }) {
181
+ const [input, setInput] = (0, react_1.useState)("");
182
+ const [tooltip, setTooltip] = (0, react_1.useState)("");
183
+ const [cursorVisible, setCursorVisible] = (0, react_1.useState)(true);
184
+ const inputRef = (0, react_1.useRef)("");
185
+ const historyIdx = (0, react_1.useRef)(-1); // -1 = not browsing history
186
+ const savedInput = (0, react_1.useRef)(""); // saves current input when entering history
187
+ // Blinking cursor
188
+ (0, react_1.useEffect)(() => {
189
+ const iv = setInterval(() => setCursorVisible(v => !v), 530);
190
+ return () => clearInterval(iv);
191
+ }, []);
192
+ const handleCtrlC = (0, react_1.useCallback)(() => {
193
+ const action = onCtrlC(inputRef.current.length > 0);
194
+ if (action === "clear") {
195
+ inputRef.current = "";
196
+ setInput("");
197
+ setTooltip("");
198
+ setTooltip("");
199
+ }
200
+ else if (action === "warn") {
201
+ // tooltip handled below
202
+ setTooltip("Ctrl-C again to exit");
203
+ setTimeout(() => setTooltip(""), 3000);
204
+ }
205
+ // "abort" and "exit" are handled by the parent (cli.ts)
206
+ }, [onCtrlC]);
207
+ (0, ink_1.useInput)((inputChar, key) => {
208
+ if (key.ctrl && inputChar === "c") {
209
+ handleCtrlC();
210
+ return;
211
+ }
212
+ if (suppressed)
213
+ return;
214
+ // Any non-Ctrl-C input clears tooltip
215
+ setTooltip("");
216
+ if (key.escape) {
217
+ if (inputRef.current) {
218
+ inputRef.current = "";
219
+ setInput("");
220
+ historyIdx.current = -1;
221
+ setTooltip("Esc again to clear");
222
+ setTimeout(() => setTooltip(""), 2000);
223
+ }
224
+ else {
225
+ setTooltip("");
226
+ }
227
+ return;
228
+ }
229
+ if (key.return) {
230
+ const text = inputRef.current;
231
+ if (text.trim())
232
+ onSubmit(text);
233
+ inputRef.current = "";
234
+ setInput("");
235
+ historyIdx.current = -1;
236
+ return;
237
+ }
238
+ if (key.backspace || key.delete) {
239
+ inputRef.current = inputRef.current.slice(0, -1);
240
+ setInput(inputRef.current);
241
+ historyIdx.current = -1;
242
+ return;
243
+ }
244
+ // Up arrow: browse history (newest first)
245
+ if (key.upArrow && history.length > 0) {
246
+ if (historyIdx.current === -1) {
247
+ // Entering history — save current input
248
+ savedInput.current = inputRef.current;
249
+ historyIdx.current = history.length - 1;
250
+ }
251
+ else if (historyIdx.current > 0) {
252
+ historyIdx.current--;
253
+ }
254
+ inputRef.current = history[historyIdx.current];
255
+ setInput(inputRef.current);
256
+ return;
257
+ }
258
+ // Down arrow: browse forward or restore saved input
259
+ if (key.downArrow) {
260
+ if (historyIdx.current >= 0) {
261
+ if (historyIdx.current < history.length - 1) {
262
+ historyIdx.current++;
263
+ inputRef.current = history[historyIdx.current];
264
+ }
265
+ else {
266
+ // Past end of history — restore saved input
267
+ historyIdx.current = -1;
268
+ inputRef.current = savedInput.current;
269
+ }
270
+ setInput(inputRef.current);
271
+ }
272
+ return;
273
+ }
274
+ if (!key.ctrl && !key.meta && inputChar) {
275
+ inputRef.current += inputChar;
276
+ setInput(inputRef.current);
277
+ historyIdx.current = -1; // typing resets history browsing
278
+ }
279
+ });
280
+ // Get terminal width (capped for sanity)
281
+ const cols = Math.min(process.stdout.columns || 80, 200);
282
+ if (suppressed) {
283
+ // During model generation: show status bar but no input
284
+ return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: "─".repeat(cols) }), (0, jsx_runtime_1.jsxs)(ink_1.Text, { dimColor: true, children: [agentName, model ? ` · ${model}` : ""] }), (0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: "─".repeat(cols) })] }));
285
+ }
286
+ return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: "─".repeat(cols) }), (0, jsx_runtime_1.jsxs)(ink_1.Box, { children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { color: OURO.teal, bold: true, children: ") " }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: OURO.bone, children: input }), cursorVisible ? (0, jsx_runtime_1.jsx)(ink_1.Text, { color: OURO.scale, children: "█" }) : (0, jsx_runtime_1.jsx)(ink_1.Text, { children: " " })] }), (0, jsx_runtime_1.jsxs)(ink_1.Box, { children: [(0, jsx_runtime_1.jsxs)(ink_1.Text, { dimColor: true, children: [agentName, model ? ` · ${model}` : ""] }), (0, jsx_runtime_1.jsx)(ink_1.Box, { flexGrow: 1 }), tooltip ? (0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: tooltip }) : null] }), (0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: "─".repeat(cols) })] }));
287
+ }
288
+ // ─── Main TUI Component ─────────────────────────────────────────────
289
+ function OuroTui({ agentName, model, completedMessages, inputHistory, live, elapsedSeconds, contextPercent, onSubmit, onCtrlC, cwd, }) {
290
+ return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", children: [(0, jsx_runtime_1.jsx)(ink_1.Static, { items: [{ id: "__header__" }, ...completedMessages], children: (item, index) => {
291
+ if (index === 0) {
292
+ return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { children: " " }), (0, jsx_runtime_1.jsx)(Header, { agentName: agentName, model: model, contextPercent: contextPercent, cwd: cwd }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: OURO.shadow, children: " Press Ctrl-C twice to exit \u00b7 \u2191\u2193 history \u00b7 Esc clear" }), (0, jsx_runtime_1.jsx)(ink_1.Text, { children: " " })] }, "header"));
293
+ }
294
+ return (0, jsx_runtime_1.jsx)(MessageBlock, { msg: item }, item.id);
295
+ } }), (live.loading || live.streamingText || live.activeTool) ? (0, jsx_runtime_1.jsx)(ink_1.Box, { height: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Text, { children: " " }) }) : null, (0, jsx_runtime_1.jsx)(LiveArea, { live: live, elapsed: elapsedSeconds }), (live.loading || live.streamingText || live.activeTool) ? (0, jsx_runtime_1.jsx)(ink_1.Box, { height: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Text, { children: " " }) }) : null, (0, jsx_runtime_1.jsx)(InputArea, { onSubmit: onSubmit, suppressed: live.inputSuppressed, onCtrlC: onCtrlC, agentName: agentName, model: model, history: inputHistory })] }));
296
+ }
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ /**
3
+ * Imperative snake-themed spinner for the CLI.
4
+ *
5
+ * Writes directly to stderr via setInterval — no React, no Ink.
6
+ * Features:
7
+ * - Ouroboros snake animation frames (serpent eating its own tail)
8
+ * - Elapsed time display
9
+ * - Stall detection with color interpolation: green -> amber (15s) -> red (45s)
10
+ * - Phrase rotation from agent.json phrase pools
11
+ * - Pause/resume for log coordination
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.ImperativeSpinner = void 0;
15
+ const phrases_1 = require("../../mind/phrases");
16
+ const runtime_1 = require("../../nerves/runtime");
17
+ // Ring spinner frames (growing/shrinking — option #6)
18
+ const SNAKE_FRAMES = [
19
+ "\u2219", // ∙ (small dot)
20
+ "\u25CB", // ○ (white circle)
21
+ "\u25CE", // ◎ (bullseye)
22
+ "\u25CF", // ● (black circle)
23
+ "\u25CE", // ◎ (bullseye)
24
+ "\u25CB", // ○ (white circle)
25
+ ];
26
+ // ANSI color helpers — RGB escape sequences
27
+ const RGB_GREEN = "\x1b[38;2;46;204;64m"; // #2ecc40 — ouroboros green
28
+ const RGB_AMBER = "\x1b[38;2;243;156;18m"; // #f39c12
29
+ const RGB_RED = "\x1b[38;2;231;76;60m"; // #e74c3c
30
+ const DIM = "\x1b[2m";
31
+ const RESET = "\x1b[0m";
32
+ function stallColor(seconds) {
33
+ if (seconds >= 45)
34
+ return RGB_RED;
35
+ if (seconds >= 15)
36
+ return RGB_AMBER;
37
+ return RGB_GREEN;
38
+ }
39
+ function formatTime(seconds) {
40
+ const h = Math.floor(seconds / 3600);
41
+ const m = Math.floor((seconds % 3600) / 60);
42
+ const s = seconds % 60;
43
+ if (h > 0)
44
+ return `${h}h${m}m`;
45
+ if (m > 0)
46
+ return `${m}m${s}s`;
47
+ return `${s}s`;
48
+ }
49
+ class ImperativeSpinner {
50
+ frames = SNAKE_FRAMES;
51
+ frameIdx = 0;
52
+ iv = null;
53
+ phraseIv = null;
54
+ msg;
55
+ phrases = null;
56
+ lastPhrase = "";
57
+ stopped = false;
58
+ startTime = 0;
59
+ paused = false;
60
+ constructor(message = "working", phrases) {
61
+ this.msg = message;
62
+ if (phrases && phrases.length > 0)
63
+ this.phrases = phrases;
64
+ }
65
+ start() {
66
+ this.stopped = false;
67
+ this.paused = false;
68
+ this.startTime = Date.now();
69
+ process.stderr.write("\r\x1b[K");
70
+ this.render();
71
+ this.iv = setInterval(() => this.render(), 120);
72
+ if (this.phrases) {
73
+ this.phraseIv = setInterval(() => this.rotatePhrase(), 1500);
74
+ }
75
+ (0, runtime_1.emitNervesEvent)({
76
+ component: "senses",
77
+ event: "senses.spinner_start",
78
+ message: "imperative spinner started",
79
+ meta: { phrase: this.msg },
80
+ });
81
+ }
82
+ render() {
83
+ /* v8 ignore next -- race guard: timer callback fires after stop() @preserve */
84
+ if (this.stopped || this.paused)
85
+ return;
86
+ const elapsed = Math.floor((Date.now() - this.startTime) / 1000);
87
+ const color = stallColor(elapsed);
88
+ const timeStr = formatTime(elapsed);
89
+ const frame = this.frames[this.frameIdx % this.frames.length];
90
+ process.stderr.write(`\r\x1b[K${color}${frame} ${this.msg}${RESET} ${DIM}${timeStr}${RESET} `);
91
+ this.frameIdx++;
92
+ }
93
+ rotatePhrase() {
94
+ /* v8 ignore next -- race guard: timer callback fires after stop() @preserve */
95
+ if (this.stopped)
96
+ return;
97
+ const next = (0, phrases_1.pickPhrase)(this.phrases, this.lastPhrase);
98
+ this.lastPhrase = next;
99
+ this.msg = next;
100
+ }
101
+ /* v8 ignore start -- pause/resume: exercised at runtime via log sink coordination @preserve */
102
+ pause() {
103
+ if (this.stopped)
104
+ return;
105
+ this.paused = true;
106
+ process.stderr.write("\r\x1b[K");
107
+ }
108
+ resume() {
109
+ if (this.stopped)
110
+ return;
111
+ this.paused = false;
112
+ this.render();
113
+ }
114
+ /* v8 ignore stop */
115
+ stop(ok) {
116
+ this.stopped = true;
117
+ if (this.iv) {
118
+ clearInterval(this.iv);
119
+ this.iv = null;
120
+ }
121
+ if (this.phraseIv) {
122
+ clearInterval(this.phraseIv);
123
+ this.phraseIv = null;
124
+ }
125
+ process.stderr.write("\r\x1b[K");
126
+ /* v8 ignore next -- ok parameter currently unused by callers @preserve */
127
+ if (ok)
128
+ process.stderr.write(`\x1b[32m\u2713\x1b[0m ${ok}\n`);
129
+ }
130
+ fail(msg) {
131
+ this.stop();
132
+ process.stderr.write(`\x1b[31m\u2717\x1b[0m ${msg}\n`);
133
+ }
134
+ }
135
+ exports.ImperativeSpinner = ImperativeSpinner;
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.EnhancedSpinner = EnhancedSpinner;
37
+ const jsx_runtime_1 = require("react/jsx-runtime");
38
+ const react_1 = __importStar(require("react"));
39
+ const ink_1 = require("ink");
40
+ /**
41
+ * Enhanced spinner with ouroboros/snake-themed animation.
42
+ *
43
+ * Features:
44
+ * - Snake-themed animation frames (serpent eating its own tail)
45
+ * - Elapsed time display
46
+ * - Color interpolation: normal -> amber (>15s) -> red (>45s)
47
+ * - Output token counter during streaming
48
+ * - Phrase rotation (driven externally via props)
49
+ * - Reduced-motion: static text, no animation
50
+ */
51
+ // Ouroboros brand palette
52
+ const OURO_GREEN = "#2ecc40";
53
+ const COLOR_AMBER = "#f39c12";
54
+ const COLOR_RED = "#e74c3c";
55
+ // Ouroboros snake-themed spinner frames
56
+ // The serpent cycles through eating its own tail
57
+ const SNAKE_FRAMES = [
58
+ "\u{1F40D}", // snake emoji
59
+ "\u25E0", // upper half circle
60
+ "\u25D4", // circle with upper right quadrant
61
+ "\u25D1", // circle with right half
62
+ "\u25D5", // circle with all but upper left quadrant
63
+ "\u25E1", // lower half circle
64
+ "\u25CB", // white circle (tail swallowed)
65
+ "\u25CF", // black circle (digesting)
66
+ ];
67
+ // Static indicator for reduced-motion
68
+ const STATIC_INDICATOR = "\u2022"; // bullet
69
+ function formatTime(seconds) {
70
+ const h = Math.floor(seconds / 3600);
71
+ const m = Math.floor((seconds % 3600) / 60);
72
+ const s = seconds % 60;
73
+ if (h > 0)
74
+ return `${h}h${m}m`;
75
+ if (m > 0)
76
+ return `${m}m${s}s`;
77
+ return `${s}s`;
78
+ }
79
+ function stallColor(seconds) {
80
+ if (seconds >= 45)
81
+ return COLOR_RED;
82
+ if (seconds >= 15)
83
+ return COLOR_AMBER;
84
+ return OURO_GREEN;
85
+ }
86
+ function EnhancedSpinner({ elapsedSeconds, phrase, outputTokens, reducedMotion, }) {
87
+ const [frame, setFrame] = (0, react_1.useState)(0);
88
+ // Animate spinner (unless reduced-motion)
89
+ react_1.default.useEffect(() => {
90
+ if (reducedMotion)
91
+ return;
92
+ const iv = setInterval(() => {
93
+ setFrame(f => (f + 1) % SNAKE_FRAMES.length);
94
+ }, 120);
95
+ return () => clearInterval(iv);
96
+ }, [reducedMotion]);
97
+ const color = stallColor(elapsedSeconds);
98
+ const timeStr = formatTime(elapsedSeconds);
99
+ const indicator = reducedMotion ? STATIC_INDICATOR : SNAKE_FRAMES[frame % SNAKE_FRAMES.length];
100
+ return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { children: [(0, jsx_runtime_1.jsxs)(ink_1.Text, { color: color, children: [indicator, " "] }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: color, children: phrase }), (0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: ` ${timeStr}` }), outputTokens !== undefined ? ((0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: ` ${outputTokens} tok` })) : null] }));
101
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.StatusLine = StatusLine;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const react_1 = __importDefault(require("react"));
9
+ const ink_1 = require("ink");
10
+ /**
11
+ * Persistent bottom status bar for the CLI TUI.
12
+ *
13
+ * Shows: model + provider, token usage, session time, context utilization,
14
+ * active tool name.
15
+ *
16
+ * Information-dense single line. Context usage color-coded:
17
+ * green (<60%), amber (60-80%), red (>80%).
18
+ *
19
+ * Ouroboros-themed: teal/green palette.
20
+ */
21
+ // Ouroboros brand palette
22
+ const OURO_TEAL = "#4ec9b0";
23
+ const COLOR_GREEN = "#2ecc40";
24
+ const COLOR_AMBER = "#f39c12";
25
+ const COLOR_RED = "#e74c3c";
26
+ function formatTokens(n) {
27
+ if (n >= 1000)
28
+ return `${Math.round(n / 1000)}K`;
29
+ return String(n);
30
+ }
31
+ function formatTime(seconds) {
32
+ const h = Math.floor(seconds / 3600);
33
+ const m = Math.floor((seconds % 3600) / 60);
34
+ const s = seconds % 60;
35
+ if (h > 0)
36
+ return `${h}h${m}m`;
37
+ if (m > 0)
38
+ return `${m}m${s}s`;
39
+ return `${s}s`;
40
+ }
41
+ function contextColor(pct) {
42
+ if (pct >= 80)
43
+ return COLOR_RED;
44
+ if (pct >= 60)
45
+ return COLOR_AMBER;
46
+ return COLOR_GREEN;
47
+ }
48
+ function StatusLine({ model, provider, tokensUsed, tokensTotal, elapsedSeconds, contextPercent, activeTool, }) {
49
+ const tokenPct = tokensTotal > 0 ? Math.round((tokensUsed / tokensTotal) * 100) : 0;
50
+ const ctxPct = contextPercent ?? tokenPct;
51
+ const ctxColor = contextColor(ctxPct);
52
+ const segments = [
53
+ `${model} ${provider}`,
54
+ `${formatTokens(tokensUsed)}/${formatTokens(tokensTotal)} (${tokenPct}%)`,
55
+ formatTime(elapsedSeconds),
56
+ ];
57
+ if (contextPercent !== undefined) {
58
+ segments.push(`ctx: ${ctxPct}%`);
59
+ }
60
+ if (activeTool) {
61
+ segments.push(activeTool);
62
+ }
63
+ return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { color: OURO_TEAL, dimColor: true, children: segments[0] }), (0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: " | " }), (0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: segments[1] }), (0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: " | " }), (0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: segments[2] }), contextPercent !== undefined ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: " | " }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: ctxColor, children: `ctx: ${ctxPct}%` })] })) : null, activeTool ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: " | " }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: OURO_TEAL, children: `[${activeTool}]` })] })) : null] }));
64
+ }