@phren/agent 0.1.8 → 0.1.9
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.
- package/dist/commands/info.js +1 -0
- package/dist/commands/model.js +5 -4
- package/dist/commands/session.js +24 -2
- package/dist/commands.js +36 -1
- package/dist/config.js +27 -11
- package/dist/cost.js +11 -74
- package/dist/index.js +92 -35
- package/dist/mcp-client.js +4 -2
- package/dist/memory/context.js +56 -24
- package/dist/memory/session.js +21 -88
- package/dist/models.js +390 -0
- package/dist/multi/agent-types.js +170 -0
- package/dist/multi/child-entry.js +248 -78
- package/dist/multi/coordinator.js +69 -1
- package/dist/multi/diff-renderer.js +193 -17
- package/dist/multi/markdown.js +49 -23
- package/dist/multi/model-picker.js +12 -21
- package/dist/multi/multi-events.js +17 -0
- package/dist/multi/multi-render.js +1 -0
- package/dist/multi/provider-manager.js +23 -13
- package/dist/multi/spawner.js +84 -7
- package/dist/multi/syntax-highlight.js +64 -48
- package/dist/multi/worktree.js +43 -0
- package/dist/package-metadata.js +11 -0
- package/dist/permissions/checker.js +21 -1
- package/dist/providers/codex-auth.js +48 -34
- package/dist/providers/codex.js +110 -40
- package/dist/providers/ollama.js +5 -4
- package/dist/providers/openrouter.js +12 -5
- package/dist/providers/resolve.js +50 -32
- package/dist/providers/types.js +0 -1
- package/dist/repl.js +19 -34
- package/dist/tools/grep.js +111 -23
- package/dist/tools/mcp-resources.js +32 -0
- package/dist/tools/registry.js +13 -2
- package/dist/tools/shell.js +101 -3
- package/dist/tools/skill.js +44 -0
- package/dist/tools/spawn-agent.js +158 -0
- package/dist/tui/ansi.js +15 -11
- package/dist/tui/components/App.js +179 -8
- package/dist/tui/components/Banner.js +7 -4
- package/dist/tui/components/InputArea.js +54 -12
- package/dist/tui/components/PhrenInput.js +329 -0
- package/dist/tui/components/StatusBar.js +3 -1
- package/dist/tui/components/SteerQueue.js +4 -2
- package/dist/tui/components/ThinkingIndicator.js +7 -5
- package/dist/tui/components/ToolCall.js +12 -8
- package/dist/tui/components/ToolSpinner.js +13 -0
- package/dist/tui/hooks/useKeyboardShortcuts.js +65 -24
- package/dist/tui/hooks/useSearch.js +47 -0
- package/dist/tui/hooks/useSlashCommands.js +16 -19
- package/dist/tui/ink-entry.js +373 -14
- package/dist/tui/mouse.js +71 -0
- package/dist/tui/terminal-control.js +62 -0
- package/dist/tui/themes.js +398 -0
- package/dist/tui/tool-render.js +12 -1
- package/dist/tui.js +2 -1
- package/package.json +1 -3
|
@@ -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
|
-
|
|
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
|
}
|
|
@@ -5,7 +5,7 @@ import { Text } from "ink";
|
|
|
5
5
|
const THINKING_VERBS = [
|
|
6
6
|
"thinking", "reasoning", "recalling", "connecting", "processing",
|
|
7
7
|
];
|
|
8
|
-
export function ThinkingIndicator({ startTime }) {
|
|
8
|
+
export function ThinkingIndicator({ 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)], []);
|
|
@@ -16,11 +16,13 @@ export function ThinkingIndicator({ startTime }) {
|
|
|
16
16
|
return () => clearInterval(timer);
|
|
17
17
|
}, []);
|
|
18
18
|
const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
|
|
19
|
-
// Gentle sine-wave interpolation between
|
|
19
|
+
// Gentle sine-wave interpolation between theme thinking colors
|
|
20
20
|
const t = (Math.sin(frame * 0.08) + 1) / 2;
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
21
|
+
const [pr, pg, pb] = theme.thinking.primary;
|
|
22
|
+
const [sr, sg, sb] = theme.thinking.secondary;
|
|
23
|
+
const r = Math.round(pr * (1 - t) + sr * t);
|
|
24
|
+
const g = Math.round(pg * (1 - t) + sg * t);
|
|
25
|
+
const b = Math.round(pb * (1 - t) + sb * t);
|
|
24
26
|
const hex = `#${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}`;
|
|
25
27
|
return (_jsxs(Text, { children: [" ", _jsxs(Text, { color: hex, children: ["\u25c6", " ", verb] }), " ", _jsxs(Text, { dimColor: true, children: [elapsed, "s"] })] }));
|
|
26
28
|
}
|
|
@@ -1,17 +1,21 @@
|
|
|
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";
|
|
3
|
+
import { formatToolInput, formatDuration, fileLink, isFileToolPreview } from "../tool-render.js";
|
|
4
4
|
const VERBOSE_LINES = 5;
|
|
5
|
-
export function ToolCall({ name, input, output, isError, durationMs, verbose }) {
|
|
6
|
-
const
|
|
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;
|
|
8
14
|
if (!verbose) {
|
|
9
|
-
|
|
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] })] }) }));
|
|
15
|
+
return (_jsxs(Box, { flexDirection: "column", paddingLeft: 2, children: [_jsxs(Box, { children: [_jsxs(Text, { color: statusColor, children: [isError ? "\u2717" : "\u2192", " "] }), _jsx(Text, { bold: true, color: nameColor, children: name }), _jsxs(Text, { color: previewColor, children: [" ", preview] }), _jsxs(Text, { color: durationColor, dimColor: true, children: [" ", dur] })] }), diffRendered && (_jsx(Text, { children: diffRendered }))] }));
|
|
11
16
|
}
|
|
12
|
-
// Verbose: header + first 5 lines of output + overflow count
|
|
13
17
|
const allLines = output.split("\n").filter(Boolean);
|
|
14
18
|
const shown = allLines.slice(0, VERBOSE_LINES);
|
|
15
19
|
const overflow = allLines.length - VERBOSE_LINES;
|
|
16
|
-
return (_jsxs(Box, { flexDirection: "column", paddingLeft: 2, children: [_jsxs(Box, { children: [_jsxs(Text, { color:
|
|
20
|
+
return (_jsxs(Box, { flexDirection: "column", paddingLeft: 2, children: [_jsxs(Box, { children: [_jsxs(Text, { color: statusColor, children: [isError ? "\u2717" : "\u2192", " "] }), _jsx(Text, { bold: true, color: nameColor, children: name }), _jsxs(Text, { color: previewColor, children: [" ", preview] }), _jsxs(Text, { color: durationColor, dimColor: true, children: [" ", dur] })] }), diffRendered ? (_jsx(Text, { children: diffRendered })) : (_jsxs(_Fragment, { children: [shown.map((line, i) => (_jsx(Text, { color: outputColor, dimColor: true, children: " " + line.slice(0, 120) }, i))), overflow > 0 && (_jsx(Text, { color: outputColor, dimColor: true, children: " ... +" + overflow + " lines" }))] }))] }));
|
|
17
21
|
}
|
|
@@ -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
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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
|