@phren/agent 0.1.8 → 0.1.10

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 (58) hide show
  1. package/dist/commands/info.js +1 -0
  2. package/dist/commands/model.js +5 -4
  3. package/dist/commands/session.js +24 -2
  4. package/dist/commands.js +36 -1
  5. package/dist/config.js +27 -11
  6. package/dist/cost.js +11 -74
  7. package/dist/index.js +92 -35
  8. package/dist/mcp-client.js +4 -2
  9. package/dist/memory/context.js +56 -24
  10. package/dist/memory/session.js +21 -88
  11. package/dist/models.js +390 -0
  12. package/dist/multi/agent-types.js +170 -0
  13. package/dist/multi/child-entry.js +248 -78
  14. package/dist/multi/coordinator.js +69 -1
  15. package/dist/multi/diff-renderer.js +193 -17
  16. package/dist/multi/markdown.js +49 -23
  17. package/dist/multi/model-picker.js +12 -21
  18. package/dist/multi/multi-events.js +17 -0
  19. package/dist/multi/multi-render.js +1 -0
  20. package/dist/multi/provider-manager.js +23 -13
  21. package/dist/multi/spawner.js +84 -7
  22. package/dist/multi/syntax-highlight.js +64 -48
  23. package/dist/multi/worktree.js +43 -0
  24. package/dist/package-metadata.js +11 -0
  25. package/dist/permissions/checker.js +21 -1
  26. package/dist/providers/codex-auth.js +48 -34
  27. package/dist/providers/codex.js +110 -40
  28. package/dist/providers/ollama.js +5 -4
  29. package/dist/providers/openrouter.js +12 -5
  30. package/dist/providers/resolve.js +50 -32
  31. package/dist/providers/types.js +0 -1
  32. package/dist/repl.js +19 -34
  33. package/dist/tools/grep.js +111 -23
  34. package/dist/tools/mcp-resources.js +32 -0
  35. package/dist/tools/registry.js +13 -2
  36. package/dist/tools/shell.js +101 -3
  37. package/dist/tools/skill.js +44 -0
  38. package/dist/tools/spawn-agent.js +158 -0
  39. package/dist/tui/ansi.js +15 -11
  40. package/dist/tui/components/App.js +180 -20
  41. package/dist/tui/components/Banner.js +7 -4
  42. package/dist/tui/components/InputArea.js +54 -12
  43. package/dist/tui/components/PhrenInput.js +329 -0
  44. package/dist/tui/components/StatusBar.js +3 -1
  45. package/dist/tui/components/SteerQueue.js +4 -2
  46. package/dist/tui/components/ThinkingIndicator.js +12 -11
  47. package/dist/tui/components/ToolCall.js +17 -11
  48. package/dist/tui/components/ToolSpinner.js +13 -0
  49. package/dist/tui/hooks/useKeyboardShortcuts.js +65 -24
  50. package/dist/tui/hooks/useSearch.js +47 -0
  51. package/dist/tui/hooks/useSlashCommands.js +16 -19
  52. package/dist/tui/ink-entry.js +317 -18
  53. package/dist/tui/mouse.js +71 -0
  54. package/dist/tui/terminal-control.js +62 -0
  55. package/dist/tui/themes.js +398 -0
  56. package/dist/tui/tool-render.js +12 -1
  57. package/dist/tui.js +2 -1
  58. package/package.json +1 -3
@@ -0,0 +1,329 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState, useEffect } from "react";
3
+ import { Box, Text, useInput } from "ink";
4
+ import * as fs from "fs";
5
+ import * as nodePath from "path";
6
+ import * as os from "os";
7
+ /** Map a flat cursor offset to { line, col } within a multi-line string. */
8
+ function offsetToPos(text, offset) {
9
+ let line = 0;
10
+ let col = 0;
11
+ for (let i = 0; i < offset && i < text.length; i++) {
12
+ if (text[i] === "\n") {
13
+ line++;
14
+ col = 0;
15
+ }
16
+ else {
17
+ col++;
18
+ }
19
+ }
20
+ return { line, col };
21
+ }
22
+ /** Map { line, col } back to a flat cursor offset. */
23
+ function posToOffset(lines, line, col) {
24
+ let offset = 0;
25
+ for (let i = 0; i < line && i < lines.length; i++) {
26
+ offset += lines[i].length + 1; // +1 for the \n
27
+ }
28
+ const targetLine = lines[line] ?? "";
29
+ return offset + Math.min(col, targetLine.length);
30
+ }
31
+ /**
32
+ * Custom controlled text input with full cursor and multi-line support.
33
+ * Replaces ink-text-input to enable cursor positioning, word jump,
34
+ * kill-line, Shift+Enter multi-line, and other readline-style keybindings.
35
+ */
36
+ export function PhrenInput({ value, onChange, onSubmit, placeholder, focus = true }) {
37
+ const [cursor, setCursor] = useState(value.length);
38
+ // Keep cursor within bounds when value changes externally
39
+ useEffect(() => {
40
+ setCursor((c) => Math.min(c, value.length));
41
+ }, [value]);
42
+ const lines = value.split("\n");
43
+ const isMultiLine = lines.length > 1;
44
+ useInput((input, key) => {
45
+ // Bracketed paste: strip \x1b[200~ (start) and \x1b[201~ (end) markers.
46
+ // If markers are present, insert the cleaned text at cursor as a single paste.
47
+ const PASTE_START = "\x1b[200~";
48
+ const PASTE_END = "\x1b[201~";
49
+ if (input.includes(PASTE_START) || input.includes(PASTE_END)) {
50
+ const cleaned = input
51
+ .replaceAll(PASTE_START, "")
52
+ .replaceAll(PASTE_END, "")
53
+ .replace(/\r\n?/g, "\n"); // normalize line endings
54
+ if (cleaned.length > 0) {
55
+ const next = value.slice(0, cursor) + cleaned + value.slice(cursor);
56
+ onChange(next);
57
+ setCursor(cursor + cleaned.length);
58
+ }
59
+ return;
60
+ }
61
+ // Heuristic paste detection for terminals without bracketed paste
62
+ if (input.length > 10 && !input.startsWith("\x1b")) {
63
+ const normalized = input.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
64
+ const before = value.slice(0, cursor);
65
+ const after = value.slice(cursor);
66
+ const newValue = before + normalized + after;
67
+ const newCursor = cursor + normalized.length;
68
+ onChange(newValue);
69
+ setCursor(newCursor);
70
+ return;
71
+ }
72
+ // Shift+Enter — insert newline (multi-line input)
73
+ if (key.return && key.shift) {
74
+ const next = value.slice(0, cursor) + "\n" + value.slice(cursor);
75
+ onChange(next);
76
+ setCursor(cursor + 1);
77
+ return;
78
+ }
79
+ // Plain Enter — submit
80
+ if (key.return) {
81
+ onSubmit(value);
82
+ setCursor(0);
83
+ return;
84
+ }
85
+ // Up arrow — in multi-line: move cursor up; single-line: pass through
86
+ if (key.upArrow && isMultiLine) {
87
+ const { line, col } = offsetToPos(value, cursor);
88
+ if (line > 0) {
89
+ setCursor(posToOffset(lines, line - 1, col));
90
+ }
91
+ return;
92
+ }
93
+ // Down arrow — in multi-line: move cursor down; single-line: pass through
94
+ if (key.downArrow && isMultiLine) {
95
+ const { line, col } = offsetToPos(value, cursor);
96
+ if (line < lines.length - 1) {
97
+ setCursor(posToOffset(lines, line + 1, col));
98
+ }
99
+ return;
100
+ }
101
+ // Left arrow / Ctrl+B — move cursor left
102
+ if (key.leftArrow || (key.ctrl && input === "b")) {
103
+ if (key.meta) {
104
+ // Alt+Left / Alt+B — word jump left
105
+ setCursor((c) => wordBoundaryLeft(value, c));
106
+ }
107
+ else {
108
+ setCursor((c) => Math.max(0, c - 1));
109
+ }
110
+ return;
111
+ }
112
+ // Right arrow / Ctrl+F — move cursor right
113
+ if (key.rightArrow || (key.ctrl && input === "f")) {
114
+ if (key.meta) {
115
+ // Alt+Right / Alt+F — word jump right
116
+ setCursor((c) => wordBoundaryRight(value, c));
117
+ }
118
+ else {
119
+ setCursor((c) => Math.min(value.length, c + 1));
120
+ }
121
+ return;
122
+ }
123
+ // Alt+B — word jump left (standalone, not combined with arrow)
124
+ if (key.meta && input === "b") {
125
+ setCursor((c) => wordBoundaryLeft(value, c));
126
+ return;
127
+ }
128
+ // Alt+F — word jump right (standalone)
129
+ if (key.meta && input === "f") {
130
+ setCursor((c) => wordBoundaryRight(value, c));
131
+ return;
132
+ }
133
+ // Home / Ctrl+A — beginning of current line
134
+ if (key.ctrl && input === "a") {
135
+ const { line } = offsetToPos(value, cursor);
136
+ setCursor(posToOffset(lines, line, 0));
137
+ return;
138
+ }
139
+ // End / Ctrl+E — end of current line
140
+ if (key.ctrl && input === "e") {
141
+ const { line } = offsetToPos(value, cursor);
142
+ setCursor(posToOffset(lines, line, lines[line].length));
143
+ return;
144
+ }
145
+ // Backspace — delete character before cursor
146
+ if (key.backspace || key.delete) {
147
+ if (cursor > 0) {
148
+ const next = value.slice(0, cursor - 1) + value.slice(cursor);
149
+ onChange(next);
150
+ setCursor(cursor - 1);
151
+ }
152
+ return;
153
+ }
154
+ // Ctrl+W — delete word before cursor
155
+ if (key.ctrl && input === "w") {
156
+ const boundary = wordBoundaryLeft(value, cursor);
157
+ onChange(value.slice(0, boundary) + value.slice(cursor));
158
+ setCursor(boundary);
159
+ return;
160
+ }
161
+ // Ctrl+U — kill to beginning of current line
162
+ if (key.ctrl && input === "u") {
163
+ const { line } = offsetToPos(value, cursor);
164
+ const lineStart = posToOffset(lines, line, 0);
165
+ onChange(value.slice(0, lineStart) + value.slice(cursor));
166
+ setCursor(lineStart);
167
+ return;
168
+ }
169
+ // Ctrl+K — kill to end of current line
170
+ if (key.ctrl && input === "k") {
171
+ const { line } = offsetToPos(value, cursor);
172
+ const lineEnd = posToOffset(lines, line, lines[line].length);
173
+ onChange(value.slice(0, cursor) + value.slice(lineEnd));
174
+ return;
175
+ }
176
+ // Tab — file path completion (slash commands handled by shortcuts hook)
177
+ if (key.tab && !key.shift) {
178
+ if (!value.startsWith("/")) {
179
+ const result = completeFilePath(value, cursor);
180
+ if (result) {
181
+ onChange(result.value);
182
+ setCursor(result.cursor);
183
+ }
184
+ }
185
+ return;
186
+ }
187
+ // Escape, arrows already handled — skip control sequences
188
+ if (key.escape || key.upArrow || key.downArrow) {
189
+ return;
190
+ }
191
+ // Skip remaining ctrl sequences we don't handle
192
+ if (key.ctrl || key.meta) {
193
+ return;
194
+ }
195
+ // Regular character input
196
+ if (input.length > 0) {
197
+ const next = value.slice(0, cursor) + input + value.slice(cursor);
198
+ onChange(next);
199
+ setCursor(cursor + input.length);
200
+ }
201
+ }, { isActive: focus });
202
+ // Render: empty with placeholder
203
+ if (value.length === 0 && placeholder) {
204
+ return (_jsxs(Text, { children: [_jsx(Text, { inverse: true, children: " " }), _jsx(Text, { dimColor: true, children: placeholder })] }));
205
+ }
206
+ // Single-line render (fast path)
207
+ if (!isMultiLine) {
208
+ const before = value.slice(0, cursor);
209
+ const cursorChar = cursor < value.length ? value[cursor] : " ";
210
+ const after = cursor < value.length ? value.slice(cursor + 1) : "";
211
+ return (_jsxs(Text, { children: [before, _jsx(Text, { inverse: true, children: cursorChar }), after] }));
212
+ }
213
+ // Multi-line render: each line separately, cursor inverse on correct position
214
+ let charsSeen = 0;
215
+ return (_jsx(Box, { flexDirection: "column", children: lines.map((line, lineIdx) => {
216
+ const lineStart = charsSeen;
217
+ const lineEnd = lineStart + line.length;
218
+ // Advance past this line's content + its \n separator (except last line)
219
+ charsSeen = lineEnd + (lineIdx < lines.length - 1 ? 1 : 0);
220
+ const cursorInLine = cursor >= lineStart && cursor <= lineEnd;
221
+ if (!cursorInLine) {
222
+ return _jsx(Text, { children: line || " " }, lineIdx);
223
+ }
224
+ const localCursor = cursor - lineStart;
225
+ const before = line.slice(0, localCursor);
226
+ const cursorChar = localCursor < line.length ? line[localCursor] : " ";
227
+ const after = localCursor < line.length ? line.slice(localCursor + 1) : "";
228
+ return (_jsxs(Text, { children: [before, _jsx(Text, { inverse: true, children: cursorChar }), after] }, lineIdx));
229
+ }) }));
230
+ }
231
+ /** Find the start of the word to the left of pos (stops at newlines). */
232
+ function wordBoundaryLeft(text, pos) {
233
+ if (pos <= 0)
234
+ return 0;
235
+ let i = pos - 1;
236
+ // Skip whitespace but not newlines
237
+ while (i > 0 && text[i] !== "\n" && /\s/.test(text[i]))
238
+ i--;
239
+ // Skip word characters
240
+ while (i > 0 && text[i - 1] !== "\n" && /\S/.test(text[i - 1]))
241
+ i--;
242
+ return i;
243
+ }
244
+ /** Find the end of the word to the right of pos (stops at newlines). */
245
+ function wordBoundaryRight(text, pos) {
246
+ const len = text.length;
247
+ if (pos >= len)
248
+ return len;
249
+ let i = pos;
250
+ // Skip word characters
251
+ while (i < len && text[i] !== "\n" && /\S/.test(text[i]))
252
+ i++;
253
+ // Skip whitespace but not newlines
254
+ while (i < len && text[i] !== "\n" && /\s/.test(text[i]))
255
+ i++;
256
+ return i;
257
+ }
258
+ /** Expand ~ to home directory. */
259
+ function expandHome(p) {
260
+ if (p === "~" || p.startsWith("~/")) {
261
+ return os.homedir() + p.slice(1);
262
+ }
263
+ return p;
264
+ }
265
+ /**
266
+ * File path tab completion.
267
+ * Extracts the last whitespace-delimited token before the cursor,
268
+ * checks if it looks like a path, and completes it from the filesystem.
269
+ * Returns null if no completion applies.
270
+ */
271
+ function completeFilePath(value, cursor) {
272
+ // Extract the text before cursor and find the last token
273
+ const before = value.slice(0, cursor);
274
+ const tokenMatch = before.match(/(\S+)$/);
275
+ if (!tokenMatch)
276
+ return null;
277
+ const token = tokenMatch[1];
278
+ const tokenStart = cursor - token.length;
279
+ // Only complete tokens that look like paths
280
+ if (!/[/.~]/.test(token))
281
+ return null;
282
+ const expanded = expandHome(token);
283
+ const resolved = nodePath.resolve(expanded);
284
+ const dir = expanded.endsWith("/") ? resolved : nodePath.dirname(resolved);
285
+ const partial = expanded.endsWith("/") ? "" : nodePath.basename(resolved);
286
+ let entries;
287
+ try {
288
+ entries = fs.readdirSync(dir);
289
+ }
290
+ catch {
291
+ return null;
292
+ }
293
+ const matches = entries.filter((e) => e.startsWith(partial));
294
+ if (matches.length === 0)
295
+ return null;
296
+ let completion;
297
+ if (matches.length === 1) {
298
+ completion = matches[0];
299
+ // Append / for directories
300
+ try {
301
+ const stat = fs.statSync(nodePath.join(dir, completion));
302
+ if (stat.isDirectory())
303
+ completion += "/";
304
+ }
305
+ catch { /* leave as is */ }
306
+ }
307
+ else {
308
+ // Find longest common prefix among matches
309
+ let prefix = matches[0];
310
+ for (let i = 1; i < matches.length; i++) {
311
+ const m = matches[i];
312
+ let j = 0;
313
+ while (j < prefix.length && j < m.length && prefix[j] === m[j])
314
+ j++;
315
+ prefix = prefix.slice(0, j);
316
+ }
317
+ if (prefix.length <= partial.length)
318
+ return null; // no progress
319
+ completion = prefix;
320
+ }
321
+ // Build the completed token: keep the original prefix up to partial, append completion
322
+ const suffix = completion.slice(partial.length);
323
+ if (suffix.length === 0)
324
+ return null;
325
+ const after = value.slice(cursor);
326
+ const newValue = before + suffix + after;
327
+ const newCursor = cursor + suffix.length;
328
+ return { value: newValue, cursor: newCursor };
329
+ }
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Text, useStdout } from "ink";
3
3
  import { PERMISSION_LABELS } from "../ansi.js";
4
- export function StatusBar({ provider, project, turns, cost, permMode, agentCount }) {
4
+ export function StatusBar({ provider, project, turns, cost, permMode, agentCount, theme }) {
5
5
  const { stdout } = useStdout();
6
6
  const width = stdout?.columns || 80;
7
7
  const modeLabel = permMode ? PERMISSION_LABELS[permMode] : "";
@@ -21,5 +21,7 @@ export function StatusBar({ provider, project, turns, cost, permMode, agentCount
21
21
  const right = rightParts.join(" ") + " ";
22
22
  const pad = Math.max(0, width - left.length - right.length);
23
23
  const fullLine = left + " ".repeat(pad) + right;
24
+ // theme.statusBar.accent is available for future use (e.g. highlighted segments)
25
+ const _accent = theme?.statusBar.accent;
24
26
  return _jsx(Text, { inverse: true, children: fullLine });
25
27
  }
@@ -1,7 +1,9 @@
1
1
  import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Box, Text } from "ink";
3
- export function SteerQueue({ items }) {
3
+ export function SteerQueue({ items, theme }) {
4
4
  if (items.length === 0)
5
5
  return null;
6
- return (_jsx(Box, { flexDirection: "column", children: items.map((item, i) => (_jsxs(Text, { color: "yellow", children: [" ", "\u21B3 steer: ", item.slice(0, 60)] }, i))) }));
6
+ const color = theme?.steer.color ?? "yellow";
7
+ const icon = theme?.steer.icon ?? "↳";
8
+ return (_jsx(Box, { flexDirection: "column", children: items.map((item, i) => (_jsxs(Text, { color: color, children: [" ", icon, " steer: ", item.slice(0, 60)] }, i))) }));
7
9
  }
@@ -1,26 +1,27 @@
1
1
  import { jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useState, useEffect, useMemo } from "react";
3
3
  import { Text } from "ink";
4
- // Phren's own thinking verbs — memory-oriented, not generic
4
+ // Phren's own thinking verbs — memory-oriented
5
5
  const THINKING_VERBS = [
6
- "thinking", "reasoning", "recalling", "connecting", "processing",
6
+ "recalling", "connecting", "reasoning", "threading", "mapping", "synthesizing",
7
7
  ];
8
- export function ThinkingIndicator({ startTime }) {
8
+ export function ThinkingIndicator({ startTime: _startTime, theme }) {
9
9
  const [frame, setFrame] = useState(0);
10
10
  // Pick a random verb once per mount
11
11
  const verb = useMemo(() => THINKING_VERBS[Math.floor(Math.random() * THINKING_VERBS.length)], []);
12
12
  useEffect(() => {
13
13
  const timer = setInterval(() => {
14
14
  setFrame((f) => f + 1);
15
- }, 50);
15
+ }, 500);
16
16
  return () => clearInterval(timer);
17
17
  }, []);
18
- const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
19
- // Gentle sine-wave interpolation between phren purple and cyan
20
- const t = (Math.sin(frame * 0.08) + 1) / 2;
21
- const r = Math.round(155 * (1 - t) + 40 * t);
22
- const g = Math.round(140 * (1 - t) + 211 * t);
23
- const b = Math.round(250 * (1 - t) + 242 * t);
18
+ // Gentle sine-wave interpolation between theme thinking colors
19
+ const t = (Math.sin(frame * 0.4) + 1) / 2;
20
+ const [pr, pg, pb] = theme.thinking.primary;
21
+ const [sr, sg, sb] = theme.thinking.secondary;
22
+ const r = Math.round(pr * (1 - t) + sr * t);
23
+ const g = Math.round(pg * (1 - t) + sg * t);
24
+ const b = Math.round(pb * (1 - t) + sb * t);
24
25
  const hex = `#${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}`;
25
- return (_jsxs(Text, { children: [" ", _jsxs(Text, { color: hex, children: ["\u25c6", " ", verb] }), " ", _jsxs(Text, { dimColor: true, children: [elapsed, "s"] })] }));
26
+ return (_jsxs(Text, { children: [" ", _jsxs(Text, { color: hex, children: ["\u25c6", " ", verb, "\\u2026"] })] }));
26
27
  }
@@ -1,17 +1,23 @@
1
- import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { Box, Text } from "ink";
3
- import { formatToolInput, formatDuration } from "../tool-render.js";
4
- const VERBOSE_LINES = 5;
5
- export function ToolCall({ name, input, output, isError, durationMs, verbose }) {
6
- const preview = formatToolInput(name, input);
3
+ import { formatToolInput, formatDuration, fileLink, isFileToolPreview } from "../tool-render.js";
4
+ const FOLD_LINES = 3;
5
+ export function ToolCall({ name, input, output, isError, durationMs, diffRendered, verbose, theme }) {
6
+ const rawPreview = formatToolInput(name, input);
7
+ const preview = isFileToolPreview(name) && rawPreview ? fileLink(rawPreview) : rawPreview;
7
8
  const dur = formatDuration(durationMs);
9
+ const statusColor = isError ? (theme?.tool.error ?? "red") : (theme?.tool.success ?? "green");
10
+ const nameColor = theme?.tool.name ?? undefined;
11
+ const previewColor = theme?.tool.preview ?? theme?.separator ?? "gray";
12
+ const durationColor = theme?.tool.duration ?? undefined;
13
+ const outputColor = theme?.tool.output ?? undefined;
14
+ // Header: ◇ Name(preview) dur
15
+ const header = (_jsxs(Box, { children: [_jsxs(Text, { color: statusColor, children: [isError ? "\u2717" : "\u25c7", " "] }), _jsx(Text, { bold: true, color: nameColor, children: name }), preview ? _jsxs(Text, { color: previewColor, children: ["(", preview, ")"] }) : null, _jsxs(Text, { color: durationColor, dimColor: true, children: [" ", dur] })] }));
8
16
  if (!verbose) {
9
- // Non-verbose: header only, no output body
10
- return (_jsx(Box, { flexDirection: "column", paddingLeft: 2, children: _jsxs(Box, { children: [_jsxs(Text, { color: isError ? "red" : "green", children: [isError ? "\u2717" : "\u2192", " "] }), _jsx(Text, { bold: true, children: name }), _jsxs(Text, { color: "gray", children: [" ", preview] }), _jsxs(Text, { dimColor: true, children: [" ", dur] })] }) }));
17
+ return (_jsxs(Box, { flexDirection: "column", paddingLeft: 2, children: [header, diffRendered && (_jsxs(Text, { children: [" \u23bf ", diffRendered] }))] }));
11
18
  }
12
- // Verbose: header + first 5 lines of output + overflow count
13
19
  const allLines = output.split("\n").filter(Boolean);
14
- const shown = allLines.slice(0, VERBOSE_LINES);
15
- const overflow = allLines.length - VERBOSE_LINES;
16
- return (_jsxs(Box, { flexDirection: "column", paddingLeft: 2, children: [_jsxs(Box, { children: [_jsxs(Text, { color: isError ? "red" : "green", children: [isError ? "\u2717" : "\u2192", " "] }), _jsx(Text, { bold: true, children: name }), _jsxs(Text, { color: "gray", children: [" ", preview] }), _jsxs(Text, { dimColor: true, children: [" ", dur] })] }), shown.map((line, i) => (_jsx(Text, { dimColor: true, children: " " + line.slice(0, 120) }, i))), overflow > 0 && (_jsx(Text, { dimColor: true, children: " ... +" + overflow + " lines" }))] }));
20
+ const shown = allLines.slice(0, FOLD_LINES);
21
+ const overflow = allLines.length - FOLD_LINES;
22
+ return (_jsxs(Box, { flexDirection: "column", paddingLeft: 2, children: [header, diffRendered ? (_jsxs(_Fragment, { children: [_jsxs(Text, { children: [" \u23bf ", diffRendered.split("\n")[0] ?? ""] }), diffRendered.split("\n").slice(1).map((line, i) => (_jsxs(Text, { children: [" ", line] }, i)))] })) : (_jsxs(_Fragment, { children: [shown.map((line, i) => (_jsxs(Text, { color: outputColor, dimColor: true, children: [i === 0 ? " \u23bf " : " ", line.slice(0, 120)] }, i))), overflow > 0 && (_jsxs(Text, { color: outputColor, dimColor: true, children: [" \u2026 +", overflow, " lines"] }))] }))] }));
17
23
  }
@@ -0,0 +1,13 @@
1
+ import { jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState, useEffect } from "react";
3
+ import { Text } from "ink";
4
+ const FRAMES = ["\u25CC", "\u25CD", "\u25CF", "\u25CD"]; // ◌ ◍ ● ◍
5
+ export function ToolSpinner({ theme } = {}) {
6
+ const [frame, setFrame] = useState(0);
7
+ useEffect(() => {
8
+ const timer = setInterval(() => setFrame((f) => (f + 1) % FRAMES.length), 150);
9
+ return () => clearInterval(timer);
10
+ }, []);
11
+ const color = theme?.accent ?? "magenta";
12
+ return _jsxs(Text, { color: color, children: [FRAMES[frame], " "] });
13
+ }
@@ -1,10 +1,5 @@
1
1
  import { useInput } from "ink";
2
- const SLASH_COMMANDS = [
3
- "/help", "/turns", "/clear", "/cwd", "/files", "/cost", "/plan", "/undo",
4
- "/context", "/model", "/provider", "/preset", "/session", "/history",
5
- "/compact", "/diff", "/git", "/mem", "/ask", "/spawn", "/agents",
6
- "/mode", "/verbose", "/exit", "/quit",
7
- ];
2
+ import { COMMAND_NAMES } from "../../commands.js";
8
3
  export function useKeyboardShortcuts(opts) {
9
4
  useInput((input, key) => {
10
5
  // Reset Ctrl+C count on any non-Ctrl+C keypress
@@ -12,6 +7,64 @@ export function useKeyboardShortcuts(opts) {
12
7
  if (opts.ctrlCCount > 0)
13
8
  opts.onSetCtrlCCount(0);
14
9
  }
10
+ // ── Tab bar navigation ────────────────────────────────────
11
+ if (opts.tabFocused) {
12
+ if (key.leftArrow) {
13
+ opts.onTabLeft?.();
14
+ return;
15
+ }
16
+ if (key.rightArrow) {
17
+ opts.onTabRight?.();
18
+ return;
19
+ }
20
+ if (key.return) {
21
+ opts.onTabSelect?.();
22
+ return;
23
+ }
24
+ if (key.upArrow) {
25
+ opts.onExitTabBar?.();
26
+ return;
27
+ }
28
+ if (key.escape) {
29
+ opts.onExitTabBar?.();
30
+ return;
31
+ }
32
+ // Any other key: exit tab bar and fall through
33
+ opts.onExitTabBar?.();
34
+ }
35
+ // Down arrow (empty input) → enter tab bar
36
+ if (key.downArrow && opts.inputValue === "" && opts.onEnterTabBar && !opts.tabFocused) {
37
+ opts.onEnterTabBar();
38
+ return;
39
+ }
40
+ // Ctrl+G -- open external editor for input
41
+ if (key.ctrl && input === "g") {
42
+ opts.onOpenEditor?.();
43
+ return;
44
+ }
45
+ // Ctrl+S -- stash/unstash input
46
+ if (key.ctrl && input === "s") {
47
+ if (opts.inputValue && opts.onStash) {
48
+ opts.onStash(opts.inputValue);
49
+ opts.onSetInput("");
50
+ }
51
+ else if (!opts.inputValue && opts.onUnstash) {
52
+ const stashed = opts.onUnstash();
53
+ if (stashed)
54
+ opts.onSetInput(stashed);
55
+ }
56
+ return;
57
+ }
58
+ // Ctrl+R -- history search
59
+ if (key.ctrl && input === "r") {
60
+ opts.onHistorySearch?.();
61
+ return;
62
+ }
63
+ // Ctrl+F -- content search
64
+ if (key.ctrl && input === "f") {
65
+ opts.onContentSearch?.();
66
+ return;
67
+ }
15
68
  // Ctrl+D -- exit cleanly
16
69
  if (key.ctrl && input === "d") {
17
70
  opts.onExit();
@@ -45,7 +98,7 @@ export function useKeyboardShortcuts(opts) {
45
98
  opts.onSetCtrlCCount(opts.ctrlCCount + 1);
46
99
  return;
47
100
  }
48
- // Escape -- exit bash mode or clear input
101
+ // Escape -- cancel agent work, exit bash mode, or clear input
49
102
  if (key.escape) {
50
103
  if (opts.bashMode) {
51
104
  opts.onSetBashMode(false);
@@ -54,6 +107,10 @@ export function useKeyboardShortcuts(opts) {
54
107
  else if (opts.inputValue) {
55
108
  opts.onSetInput("");
56
109
  }
110
+ else if (opts.onEscCancelAgent) {
111
+ // No input, not in bash mode — cancel the selected agent's work
112
+ opts.onEscCancelAgent();
113
+ }
57
114
  return;
58
115
  }
59
116
  // Up arrow -- recall older history
@@ -79,27 +136,11 @@ export function useKeyboardShortcuts(opts) {
79
136
  opts.onSetInput(history[history.length - 1 - newIndex]);
80
137
  return;
81
138
  }
82
- // Ctrl+W or Ctrl+Backspace -- delete last word
83
- if ((key.ctrl && input === "w") || (key.ctrl && key.backspace) || input === "\x1b\x7f") {
84
- const val = opts.inputValue;
85
- const trimmed = val.replace(/\s+$/, ""); // strip trailing spaces
86
- const lastSpace = trimmed.lastIndexOf(" ");
87
- opts.onSetInput(lastSpace >= 0 ? trimmed.slice(0, lastSpace + 1) : "");
88
- return;
89
- }
90
- // Ctrl+U -- clear entire line
91
- if (key.ctrl && input === "u") {
92
- opts.onSetInput("");
93
- return;
94
- }
95
- // Ctrl+A -- move cursor to start (clear and re-set — Ink TextInput doesn't expose cursor)
96
- // Ctrl+E -- move cursor to end (no-op, cursor is always at end in Ink TextInput)
97
- // These are limited by ink-text-input which doesn't support cursor positioning
98
139
  // Tab -- slash command completion when input starts with /
99
140
  if (key.tab && !key.shift && !opts.isRunning) {
100
141
  const val = opts.inputValue;
101
142
  if (val.startsWith("/") && val.length > 1) {
102
- const matches = SLASH_COMMANDS.filter(c => c.startsWith(val));
143
+ const matches = COMMAND_NAMES.filter(c => c.startsWith(val));
103
144
  if (matches.length === 1) {
104
145
  opts.onSetInput(matches[0]);
105
146
  }
@@ -0,0 +1,47 @@
1
+ import { useState, useCallback } from "react";
2
+ export function useSearch() {
3
+ const [state, setState] = useState({
4
+ active: false,
5
+ query: "",
6
+ matchCount: 0,
7
+ currentMatch: 0,
8
+ });
9
+ const activate = useCallback(() => {
10
+ setState(s => ({ ...s, active: true, query: "", matchCount: 0, currentMatch: 0 }));
11
+ }, []);
12
+ const deactivate = useCallback(() => {
13
+ setState(s => ({ ...s, active: false }));
14
+ }, []);
15
+ const setQuery = useCallback((query) => {
16
+ setState(s => ({ ...s, query }));
17
+ }, []);
18
+ const setMatchInfo = useCallback((matchCount, currentMatch) => {
19
+ setState(s => ({ ...s, matchCount, currentMatch }));
20
+ }, []);
21
+ const nextMatch = useCallback(() => {
22
+ setState(s => ({
23
+ ...s,
24
+ currentMatch: s.matchCount > 0 ? (s.currentMatch + 1) % s.matchCount : 0,
25
+ }));
26
+ }, []);
27
+ const prevMatch = useCallback(() => {
28
+ setState(s => ({
29
+ ...s,
30
+ currentMatch: s.matchCount > 0 ? (s.currentMatch - 1 + s.matchCount) % s.matchCount : 0,
31
+ }));
32
+ }, []);
33
+ return { state, activate, deactivate, setQuery, setMatchInfo, nextMatch, prevMatch };
34
+ }
35
+ /** Highlight all occurrences of query in text with ANSI yellow background. */
36
+ export function highlightMatches(text, query) {
37
+ if (!query || query.length === 0)
38
+ return { highlighted: text, count: 0 };
39
+ const escaped = query.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
40
+ const regex = new RegExp(escaped, "gi");
41
+ let count = 0;
42
+ const highlighted = text.replace(regex, (match) => {
43
+ count++;
44
+ return `\x1b[43m\x1b[30m${match}\x1b[0m`;
45
+ });
46
+ return { highlighted, count };
47
+ }
@@ -16,29 +16,26 @@ export function useSlashCommands(opts) {
16
16
  captured.push(typeof chunk === "string" ? chunk : Buffer.from(chunk).toString());
17
17
  return true;
18
18
  });
19
+ let result;
19
20
  try {
20
- const result = handleCommand(input, opts.commandContext);
21
- if (result instanceof Promise) {
22
- // Async command — restore stderr, then capture async output
23
- process.stderr.write = origWrite;
24
- result.then(() => {
25
- // For async commands, stderr was already restored so output went to real stderr.
26
- // Future improvement: capture async output too.
27
- });
28
- flush();
29
- return true;
30
- }
31
- if (result === true) {
32
- flush();
33
- return true;
34
- }
35
- // Not a recognized command (result === false)
36
- flush();
37
- return true; // Still starts with /, so don't send to agent
21
+ result = handleCommand(input, opts.commandContext);
38
22
  }
39
- finally {
23
+ catch {
40
24
  process.stderr.write = origWrite;
25
+ return true;
26
+ }
27
+ if (result instanceof Promise) {
28
+ result.then(() => {
29
+ process.stderr.write = origWrite;
30
+ flush();
31
+ }).catch(() => {
32
+ process.stderr.write = origWrite;
33
+ });
34
+ return true;
41
35
  }
36
+ process.stderr.write = origWrite;
37
+ flush();
38
+ return true;
42
39
  function flush() {
43
40
  if (captured.length > 0) {
44
41
  // Strip ANSI dim/reset codes for cleaner display in Ink