@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,307 @@
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.CliStore = void 0;
37
+ exports.createInkCallbacks = createInkCallbacks;
38
+ exports.InkCliApp = InkCliApp;
39
+ const jsx_runtime_1 = require("react/jsx-runtime");
40
+ const react_1 = __importStar(require("react"));
41
+ const ink_1 = require("ink");
42
+ const streaming_markdown_1 = require("./streaming-markdown");
43
+ const spinner_1 = require("./spinner");
44
+ const tool_render_1 = require("./tool-render");
45
+ const phrases_1 = require("../../mind/phrases");
46
+ const format_1 = require("../../mind/format");
47
+ const runtime_1 = require("../../nerves/runtime");
48
+ /**
49
+ * Ink CLI Adapter — bridges RunCliSessionOptions with Ink/React rendering.
50
+ *
51
+ * Architecture:
52
+ * - CliStore: mutable external state, updated by callbacks
53
+ * - InkCliApp: reads from store via subscription, renders Ink components
54
+ * - createInkCallbacks: returns ChannelCallbacks that update the store
55
+ *
56
+ * The business logic (runAgent, pipeline, commands) stays unchanged.
57
+ * Only the rendering layer is replaced: readline -> Ink.
58
+ */
59
+ // Ouroboros brand palette
60
+ const OURO_GREEN = "#2ecc40";
61
+ const OURO_TEAL = "#4ec9b0";
62
+ /**
63
+ * Mutable external store. Callbacks mutate state; React subscribes via
64
+ * useSyncExternalStore pattern (simplified: we use a version counter +
65
+ * forceUpdate in the component).
66
+ */
67
+ class CliStore {
68
+ state = {
69
+ streamingText: "",
70
+ loading: false,
71
+ spinnerPhrase: "",
72
+ activeTool: null,
73
+ toolResults: [],
74
+ errorMessage: null,
75
+ kickMessage: null,
76
+ inputSuppressed: false,
77
+ bannerLines: [],
78
+ };
79
+ listeners = new Set();
80
+ spinnerStartTime = 0;
81
+ hadToolRun = false;
82
+ getState() {
83
+ return this.state;
84
+ }
85
+ subscribe(listener) {
86
+ this.listeners.add(listener);
87
+ return () => { this.listeners.delete(listener); };
88
+ }
89
+ notify() {
90
+ for (const fn of this.listeners)
91
+ fn();
92
+ }
93
+ // ─── Mutation methods called by callbacks ───
94
+ modelStart() {
95
+ const phrases = (0, phrases_1.getPhrases)();
96
+ const pool = this.hadToolRun ? phrases.followup : phrases.thinking;
97
+ const first = (0, phrases_1.pickPhrase)(pool);
98
+ this.state = {
99
+ ...this.state,
100
+ loading: true,
101
+ spinnerPhrase: first,
102
+ streamingText: "",
103
+ activeTool: null,
104
+ toolResults: [],
105
+ errorMessage: null,
106
+ kickMessage: null,
107
+ };
108
+ this.spinnerStartTime = Date.now();
109
+ this.notify();
110
+ }
111
+ clearText() {
112
+ this.state = { ...this.state, streamingText: "" };
113
+ this.notify();
114
+ }
115
+ appendText(text) {
116
+ this.state = {
117
+ ...this.state,
118
+ loading: false,
119
+ streamingText: this.state.streamingText + text,
120
+ };
121
+ this.notify();
122
+ }
123
+ toolStart(name, args) {
124
+ this.hadToolRun = true;
125
+ this.state = {
126
+ ...this.state,
127
+ loading: true,
128
+ activeTool: { name, args },
129
+ spinnerPhrase: (0, phrases_1.pickPhrase)((0, phrases_1.getPhrases)().tool),
130
+ };
131
+ this.spinnerStartTime = Date.now();
132
+ this.notify();
133
+ }
134
+ toolEnd(name, argSummary, success) {
135
+ this.state = {
136
+ ...this.state,
137
+ loading: false,
138
+ activeTool: null,
139
+ toolResults: [...this.state.toolResults, { name, argSummary, success }],
140
+ };
141
+ this.notify();
142
+ }
143
+ setError(message) {
144
+ this.state = { ...this.state, loading: false, errorMessage: message };
145
+ this.notify();
146
+ }
147
+ setKick() {
148
+ this.state = { ...this.state, loading: false, kickMessage: (0, format_1.formatKick)() };
149
+ this.notify();
150
+ }
151
+ suppressInput() {
152
+ this.state = { ...this.state, inputSuppressed: true };
153
+ this.notify();
154
+ }
155
+ restoreInput() {
156
+ this.state = { ...this.state, inputSuppressed: false };
157
+ this.notify();
158
+ }
159
+ /** Flush streaming state at end of turn */
160
+ endTurn() {
161
+ this.state = {
162
+ ...this.state,
163
+ loading: false,
164
+ activeTool: null,
165
+ errorMessage: null,
166
+ kickMessage: null,
167
+ };
168
+ this.notify();
169
+ }
170
+ setBanner(lines) {
171
+ this.state = { ...this.state, bannerLines: lines };
172
+ this.notify();
173
+ }
174
+ getElapsedSeconds() {
175
+ if (!this.state.loading)
176
+ return 0;
177
+ return Math.floor((Date.now() - this.spinnerStartTime) / 1000);
178
+ }
179
+ }
180
+ exports.CliStore = CliStore;
181
+ // ─── Callbacks factory ─────────────────────────────────────────────
182
+ function createInkCallbacks(store) {
183
+ (0, runtime_1.emitNervesEvent)({
184
+ component: "senses",
185
+ event: "senses.cli_callbacks_created",
186
+ message: "ink cli callbacks created",
187
+ meta: {},
188
+ });
189
+ return {
190
+ onModelStart: () => { store.modelStart(); },
191
+ onModelStreamStart: () => { },
192
+ onClearText: () => { store.clearText(); },
193
+ onTextChunk: (text) => { store.appendText(text); },
194
+ onReasoningChunk: (_text) => { },
195
+ onToolStart: (name, args) => { store.toolStart(name, args); },
196
+ onToolEnd: (name, argSummary, success) => { store.toolEnd(name, argSummary, success); },
197
+ onError: (error, severity) => {
198
+ if (severity === "transient") {
199
+ store.setError(error.message);
200
+ }
201
+ else {
202
+ store.setError((0, format_1.formatError)(error));
203
+ }
204
+ },
205
+ onKick: () => { store.setKick(); },
206
+ flushMarkdown: () => { store.endTurn(); },
207
+ };
208
+ }
209
+ // ─── Input Area ────────────────────────────────────────────────────
210
+ function InputArea({ onSubmit, suppressed, }) {
211
+ const [input, setInput] = (0, react_1.useState)("");
212
+ const inputRef = (0, react_1.useRef)("");
213
+ const [history, setHistory] = (0, react_1.useState)([]);
214
+ const historyIdx = (0, react_1.useRef)(-1);
215
+ (0, ink_1.useInput)((inputChar, key) => {
216
+ if (suppressed)
217
+ return;
218
+ if (key.return) {
219
+ const text = inputRef.current;
220
+ if (text.trim()) {
221
+ onSubmit(text);
222
+ setHistory(prev => {
223
+ const next = [...prev, text];
224
+ return next;
225
+ });
226
+ historyIdx.current = -1;
227
+ }
228
+ inputRef.current = "";
229
+ setInput("");
230
+ return;
231
+ }
232
+ if (key.backspace || key.delete) {
233
+ inputRef.current = inputRef.current.slice(0, -1);
234
+ setInput(inputRef.current);
235
+ return;
236
+ }
237
+ // History navigation
238
+ if (key.upArrow) {
239
+ if (history.length > 0) {
240
+ const idx = historyIdx.current < 0 ? history.length - 1 : Math.max(0, historyIdx.current - 1);
241
+ historyIdx.current = idx;
242
+ inputRef.current = history[idx];
243
+ setInput(history[idx]);
244
+ }
245
+ return;
246
+ }
247
+ if (key.downArrow) {
248
+ if (historyIdx.current >= 0) {
249
+ const idx = historyIdx.current + 1;
250
+ if (idx >= history.length) {
251
+ historyIdx.current = -1;
252
+ inputRef.current = "";
253
+ setInput("");
254
+ }
255
+ else {
256
+ historyIdx.current = idx;
257
+ inputRef.current = history[idx];
258
+ setInput(history[idx]);
259
+ }
260
+ }
261
+ return;
262
+ }
263
+ if (!key.ctrl && !key.meta && inputChar) {
264
+ inputRef.current += inputChar;
265
+ setInput(inputRef.current);
266
+ }
267
+ });
268
+ if (suppressed) {
269
+ return (0, jsx_runtime_1.jsx)(ink_1.Text, { children: "" });
270
+ }
271
+ return ((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, { children: input })] }));
272
+ }
273
+ function InkCliApp({ store, onSubmit, onExit }) {
274
+ const { exit } = (0, ink_1.useApp)();
275
+ const [, forceUpdate] = (0, react_1.useState)(0);
276
+ const [elapsed, setElapsed] = (0, react_1.useState)(0);
277
+ // Subscribe to store changes
278
+ (0, react_1.useEffect)(() => {
279
+ return store.subscribe(() => {
280
+ forceUpdate(n => n + 1);
281
+ });
282
+ }, [store]);
283
+ // Elapsed timer for spinner
284
+ (0, react_1.useEffect)(() => {
285
+ const iv = setInterval(() => {
286
+ setElapsed(store.getElapsedSeconds());
287
+ }, 1000);
288
+ return () => clearInterval(iv);
289
+ }, [store]);
290
+ // Ctrl-C handling
291
+ (0, ink_1.useInput)((_input, key) => {
292
+ if (key.ctrl && _input === "c") {
293
+ if (onExit) {
294
+ onExit();
295
+ }
296
+ else {
297
+ exit();
298
+ }
299
+ }
300
+ });
301
+ const state = store.getState();
302
+ return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", children: [state.bannerLines.length > 0 ? ((0, jsx_runtime_1.jsx)(ink_1.Box, { flexDirection: "column", children: state.bannerLines.map((line, i) => ((0, jsx_runtime_1.jsx)(ink_1.Text, { children: line }, i))) })) : null, state.streamingText ? ((0, jsx_runtime_1.jsx)(streaming_markdown_1.StreamingMarkdown, { text: state.streamingText })) : null, state.toolResults.map((tr, i) => {
303
+ const color = tr.success ? OURO_GREEN : "#e74c3c";
304
+ const icon = tr.success ? "\u2713" : "\u2717";
305
+ return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { children: [(0, jsx_runtime_1.jsxs)(ink_1.Text, { color: color, children: [icon, " "] }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: OURO_TEAL, bold: true, children: tr.name }), (0, jsx_runtime_1.jsxs)(ink_1.Text, { dimColor: true, children: [" ", tr.argSummary] })] }, i));
306
+ }), state.activeTool ? ((0, jsx_runtime_1.jsxs)(ink_1.Box, { children: [(0, jsx_runtime_1.jsx)(tool_render_1.ToolBadge, { name: state.activeTool.name }), (0, jsx_runtime_1.jsx)(tool_render_1.ToolParams, { name: state.activeTool.name, args: state.activeTool.args })] })) : null, state.loading ? ((0, jsx_runtime_1.jsx)(spinner_1.EnhancedSpinner, { elapsedSeconds: elapsed, phrase: state.spinnerPhrase })) : null, state.errorMessage ? ((0, jsx_runtime_1.jsx)(ink_1.Text, { color: "#e74c3c", children: state.errorMessage })) : null, state.kickMessage ? ((0, jsx_runtime_1.jsx)(ink_1.Text, { color: "#f39c12", children: state.kickMessage })) : null, (0, jsx_runtime_1.jsx)(InputArea, { onSubmit: onSubmit, suppressed: state.inputSuppressed })] }));
307
+ }
@@ -0,0 +1,156 @@
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.InkApp = InkApp;
37
+ const jsx_runtime_1 = require("react/jsx-runtime");
38
+ const react_1 = __importStar(require("react"));
39
+ const ink_1 = require("ink");
40
+ const streaming_markdown_1 = require("./streaming-markdown");
41
+ /**
42
+ * Ouroboros CLI TUI — Ink application shell.
43
+ *
44
+ * Replaces the imperative readline-based CLI with a React/Ink component tree.
45
+ * Provides: message list, input area, spinner, tool result display.
46
+ *
47
+ * Design: Ouroboros-themed (green serpent), NOT Claude/Anthropic design language.
48
+ * Copy-paste integrity: no padding characters. Visual hierarchy via color/bold/dim only.
49
+ */
50
+ // Ouroboros brand palette
51
+ const OURO_GREEN = "#2ecc40";
52
+ const OURO_TEAL = "#4ec9b0";
53
+ const OURO_DIM = true;
54
+ // Snake-themed spinner frames: serpent eating its own tail
55
+ const SNAKE_FRAMES = [
56
+ "\u{1F40D}\u2003", // snake emoji
57
+ "\u25E0\u2003", // upper half circle
58
+ "\u25D4\u2003", // circle with upper right quadrant
59
+ "\u25D1\u2003", // circle with right half
60
+ "\u25D5\u2003", // circle with all but upper left quadrant
61
+ "\u25E1\u2003", // lower half circle
62
+ "\u{1F40D}\u2003", // snake emoji again
63
+ "\u25CB\u2003", // white circle (tail eaten)
64
+ ];
65
+ function UserMessage({ content }) {
66
+ return ((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, { children: content })] }));
67
+ }
68
+ function AssistantMessage({ content }) {
69
+ return ((0, jsx_runtime_1.jsx)(ink_1.Box, { children: (0, jsx_runtime_1.jsx)(streaming_markdown_1.StreamingMarkdown, { text: content }) }));
70
+ }
71
+ function ToolCallDisplay({ toolCall }) {
72
+ let argSummary = "";
73
+ try {
74
+ const args = JSON.parse(toolCall.function.arguments);
75
+ const first = Object.values(args)[0];
76
+ if (typeof first === "string")
77
+ argSummary = first.length > 60 ? first.slice(0, 57) + "..." : first;
78
+ }
79
+ catch {
80
+ argSummary = toolCall.function.arguments.slice(0, 60);
81
+ }
82
+ return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { color: OURO_GREEN, bold: true, children: toolCall.function.name }), argSummary ? (0, jsx_runtime_1.jsxs)(ink_1.Text, { dimColor: true, children: [" ", argSummary] }) : null] }));
83
+ }
84
+ function ToolResultDisplay({ result }) {
85
+ const color = result.success ? OURO_GREEN : "#e74c3c";
86
+ const icon = result.success ? "\u2713" : "\u2717";
87
+ const summary = result.result.length > 120
88
+ ? result.result.slice(0, 117) + "..."
89
+ : result.result;
90
+ return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { children: [(0, jsx_runtime_1.jsxs)(ink_1.Text, { color: color, children: [icon, " ", result.name] }), (0, jsx_runtime_1.jsxs)(ink_1.Text, { dimColor: true, children: [" ", summary.replace(/\n/g, " ")] })] }));
91
+ }
92
+ function SpinnerComponent({ text, frame }) {
93
+ const char = SNAKE_FRAMES[frame % SNAKE_FRAMES.length];
94
+ return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { color: OURO_GREEN, children: char }), (0, jsx_runtime_1.jsxs)(ink_1.Text, { dimColor: OURO_DIM, children: [text, "..."] })] }));
95
+ }
96
+ function InputArea({ onSubmit, }) {
97
+ const [input, setInput] = (0, react_1.useState)("");
98
+ // Ref tracks the latest input value so useInput callback always sees current state
99
+ const inputRef = (0, react_1.useRef)("");
100
+ (0, ink_1.useInput)((inputChar, key) => {
101
+ if (key.return) {
102
+ if (inputRef.current.trim() && onSubmit) {
103
+ onSubmit(inputRef.current);
104
+ }
105
+ inputRef.current = "";
106
+ setInput("");
107
+ return;
108
+ }
109
+ if (key.backspace || key.delete) {
110
+ inputRef.current = inputRef.current.slice(0, -1);
111
+ setInput(inputRef.current);
112
+ return;
113
+ }
114
+ if (!key.ctrl && !key.meta && inputChar) {
115
+ inputRef.current += inputChar;
116
+ setInput(inputRef.current);
117
+ }
118
+ });
119
+ return ((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, { children: input })] }));
120
+ }
121
+ function MessageList({ messages, toolResults, }) {
122
+ const toolResultMap = new Map();
123
+ if (toolResults) {
124
+ for (const tr of toolResults) {
125
+ toolResultMap.set(tr.toolCallId, tr);
126
+ }
127
+ }
128
+ return ((0, jsx_runtime_1.jsx)(ink_1.Box, { flexDirection: "column", children: messages.map((msg, i) => {
129
+ if (msg.role === "user" && msg.content) {
130
+ return (0, jsx_runtime_1.jsx)(UserMessage, { content: msg.content }, i);
131
+ }
132
+ if (msg.role === "assistant") {
133
+ return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", children: [msg.content ? (0, jsx_runtime_1.jsx)(AssistantMessage, { content: msg.content }) : null, msg.tool_calls?.map(tc => {
134
+ const tr = toolResultMap.get(tc.id);
135
+ return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", children: [(0, jsx_runtime_1.jsx)(ToolCallDisplay, { toolCall: tc }), tr ? (0, jsx_runtime_1.jsx)(ToolResultDisplay, { result: tr }) : null] }, tc.id));
136
+ })] }, i));
137
+ }
138
+ return null;
139
+ }) }));
140
+ }
141
+ function InkApp({ messages, onSubmit, loading, spinnerText, toolResults, }) {
142
+ const [spinnerFrame, setSpinnerFrame] = (0, react_1.useState)(0);
143
+ // Animate spinner
144
+ react_1.default.useEffect(() => {
145
+ if (!loading)
146
+ return;
147
+ const iv = setInterval(() => {
148
+ setSpinnerFrame(f => (f + 1) % SNAKE_FRAMES.length);
149
+ }, 120);
150
+ return () => clearInterval(iv);
151
+ }, [loading]);
152
+ const handleSubmit = (0, react_1.useCallback)((text) => {
153
+ onSubmit?.(text);
154
+ }, [onSubmit]);
155
+ return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", children: [(0, jsx_runtime_1.jsx)(MessageList, { messages: messages, toolResults: toolResults }), loading && spinnerText ? ((0, jsx_runtime_1.jsx)(SpinnerComponent, { text: spinnerText, frame: spinnerFrame })) : null, (0, jsx_runtime_1.jsx)(InputArea, { onSubmit: handleSubmit })] }));
156
+ }
@@ -0,0 +1,68 @@
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.InlineDiff = InlineDiff;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const react_1 = __importDefault(require("react"));
9
+ const ink_1 = require("ink");
10
+ // Ouroboros brand colors
11
+ const OURO_GREEN = "#2ecc40"; // added lines -- serpent green
12
+ const OURO_RED = "#e74c3c"; // removed lines
13
+ const OURO_HEADER = "#4ec9b0"; // file header -- teal
14
+ const OURO_LINE_NUM = "gray"; // line numbers -- subtle
15
+ /**
16
+ * Simple line-level diff algorithm (Myers-like via LCS).
17
+ * Produces a sequence of add/remove/context lines.
18
+ */
19
+ function computeDiff(before, after) {
20
+ const oldLines = before ? before.split("\n") : [];
21
+ const newLines = after ? after.split("\n") : [];
22
+ // LCS-based diff
23
+ const m = oldLines.length;
24
+ const n = newLines.length;
25
+ const dp = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
26
+ for (let i = 1; i <= m; i++) {
27
+ for (let j = 1; j <= n; j++) {
28
+ if (oldLines[i - 1] === newLines[j - 1]) {
29
+ dp[i][j] = dp[i - 1][j - 1] + 1;
30
+ }
31
+ else {
32
+ dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
33
+ }
34
+ }
35
+ }
36
+ // Backtrack to build diff
37
+ const result = [];
38
+ let i = m;
39
+ let j = n;
40
+ while (i > 0 || j > 0) {
41
+ if (i > 0 && j > 0 && oldLines[i - 1] === newLines[j - 1]) {
42
+ result.unshift({ type: "context", content: oldLines[i - 1], oldNum: i, newNum: j });
43
+ i--;
44
+ j--;
45
+ }
46
+ else if (j > 0 && (i === 0 || dp[i][j - 1] >= dp[i - 1][j])) {
47
+ result.unshift({ type: "add", content: newLines[j - 1], newNum: j });
48
+ j--;
49
+ }
50
+ else {
51
+ result.unshift({ type: "remove", content: oldLines[i - 1], oldNum: i });
52
+ i--;
53
+ }
54
+ }
55
+ return result;
56
+ }
57
+ function DiffLineComponent({ line }) {
58
+ const num = line.type === "remove" ? line.oldNum : line.newNum;
59
+ /* v8 ignore next -- defensive fallback; line numbers always present @preserve */
60
+ const lineNum = num !== undefined ? String(num) : "";
61
+ const prefix = line.type === "add" ? "+" : line.type === "remove" ? "-" : " ";
62
+ const color = line.type === "add" ? OURO_GREEN : line.type === "remove" ? OURO_RED : undefined;
63
+ return ((0, jsx_runtime_1.jsxs)(ink_1.Text, { children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { color: OURO_LINE_NUM, children: lineNum.padStart(4) }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: color, children: ` ${prefix} ${line.content}` })] }));
64
+ }
65
+ function InlineDiff({ before, after, filePath }) {
66
+ const diffLines = computeDiff(before, after);
67
+ return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { color: OURO_HEADER, bold: true, children: filePath }), diffLines.map((line, i) => ((0, jsx_runtime_1.jsx)(DiffLineComponent, { line: line }, i)))] }));
68
+ }
@@ -0,0 +1,84 @@
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.ScrollableMessageList = ScrollableMessageList;
37
+ const jsx_runtime_1 = require("react/jsx-runtime");
38
+ const react_1 = __importStar(require("react"));
39
+ const ink_1 = require("ink");
40
+ const streaming_markdown_1 = require("./streaming-markdown");
41
+ /**
42
+ * Scrollable message list with virtual rendering.
43
+ *
44
+ * Only renders messages within the viewport window. Supports:
45
+ * - Auto-scroll to bottom (pinned mode, default)
46
+ * - Scroll lock at a specific offset
47
+ * - "N below" indicator when scrolled up
48
+ *
49
+ * Ouroboros-themed: green serpent palette, no padding decoration.
50
+ */
51
+ // Ouroboros brand palette
52
+ const OURO_TEAL = "#4ec9b0";
53
+ const OURO_INDICATOR = "#2ecc40";
54
+ function MessageItem({ message }) {
55
+ if (message.role === "user" && message.content) {
56
+ return ((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, { children: message.content })] }));
57
+ }
58
+ if (message.role === "assistant" && message.content) {
59
+ return (0, jsx_runtime_1.jsx)(streaming_markdown_1.StreamingMarkdown, { text: message.content });
60
+ }
61
+ // system or empty messages render nothing visible
62
+ return (0, jsx_runtime_1.jsx)(ink_1.Text, { children: "" });
63
+ }
64
+ function ScrollableMessageList({ messages, viewportHeight, scrollOffset, }) {
65
+ const { visibleMessages, belowCount } = (0, react_1.useMemo)(() => {
66
+ if (messages.length === 0) {
67
+ return { visibleMessages: [], belowCount: 0 };
68
+ }
69
+ let start;
70
+ if (scrollOffset !== undefined) {
71
+ start = Math.max(0, Math.min(scrollOffset, messages.length - 1));
72
+ }
73
+ else {
74
+ // Auto-scroll: pin to bottom
75
+ start = Math.max(0, messages.length - viewportHeight);
76
+ }
77
+ const end = Math.min(start + viewportHeight, messages.length);
78
+ return {
79
+ visibleMessages: messages.slice(start, end),
80
+ belowCount: messages.length - end,
81
+ };
82
+ }, [messages, viewportHeight, scrollOffset]);
83
+ return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", children: [visibleMessages.map((msg, i) => ((0, jsx_runtime_1.jsx)(MessageItem, { message: msg }, i))), belowCount > 0 ? ((0, jsx_runtime_1.jsx)(ink_1.Text, { color: OURO_INDICATOR, dimColor: true, children: `${belowCount} below` })) : null] }));
84
+ }