@phren/agent 0.1.10 → 0.1.11
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/agent-loop/index.js +8 -1
- package/dist/agent-loop/stream.js +3 -1
- package/dist/commands/config.js +13 -0
- package/dist/commands.js +3 -1
- package/dist/tui/ansi.js +10 -5
- package/dist/tui/components/App.js +28 -3
- package/dist/tui/components/Banner.js +16 -38
- package/dist/tui/components/InputArea.js +6 -6
- package/dist/tui/components/PhrenInput.js +21 -7
- package/dist/tui/components/ThinkingIndicator.js +1 -1
- package/dist/tui/components/ToolCall.js +3 -3
- package/dist/tui/hooks/useKeyboardShortcuts.js +20 -2
- package/dist/tui/ink-entry.js +38 -28
- package/dist/tui/themes.js +2 -2
- package/package.json +1 -1
package/dist/agent-loop/index.js
CHANGED
|
@@ -25,7 +25,11 @@ export async function runTurn(userInput, session, config, hooks) {
|
|
|
25
25
|
session.messages.push({ role: "user", content: userInput });
|
|
26
26
|
let turnToolCalls = 0;
|
|
27
27
|
const turnStart = session.turns;
|
|
28
|
+
const signal = hooks?.signal;
|
|
28
29
|
while (session.turns - turnStart < maxTurns) {
|
|
30
|
+
// Abort check
|
|
31
|
+
if (signal?.aborted)
|
|
32
|
+
break;
|
|
29
33
|
// Budget check
|
|
30
34
|
if (costTracker?.isOverBudget()) {
|
|
31
35
|
status(`\x1b[33m[budget exceeded: ${costTracker.formatCost()}]\x1b[0m\n`);
|
|
@@ -61,7 +65,7 @@ export async function runTurn(userInput, session, config, hooks) {
|
|
|
61
65
|
if (useStream) {
|
|
62
66
|
// Streaming path — retry the initial connection (before consuming deltas)
|
|
63
67
|
const stream = await withRetry(async () => provider.chatStream(systemPrompt, session.messages, turnTools), undefined, verbose);
|
|
64
|
-
const result = await consumeStream(stream, costTracker, hooks?.onTextDelta);
|
|
68
|
+
const result = await consumeStream(stream, costTracker, hooks?.onTextDelta, signal);
|
|
65
69
|
assistantContent = result.content;
|
|
66
70
|
stopReason = result.stop_reason;
|
|
67
71
|
}
|
|
@@ -92,6 +96,9 @@ export async function runTurn(userInput, session, config, hooks) {
|
|
|
92
96
|
}
|
|
93
97
|
session.messages.push({ role: "assistant", content: assistantContent });
|
|
94
98
|
session.turns++;
|
|
99
|
+
// Abort check after LLM response
|
|
100
|
+
if (signal?.aborted)
|
|
101
|
+
break;
|
|
95
102
|
// Show turn cost
|
|
96
103
|
if (verbose && costTracker) {
|
|
97
104
|
status(`\x1b[2m cost: ${costTracker.formatCost()}\x1b[0m\n`);
|
|
@@ -30,13 +30,15 @@ export async function runToolsConcurrently(blocks, registry) {
|
|
|
30
30
|
return results;
|
|
31
31
|
}
|
|
32
32
|
/** Consume a chatStream into ContentBlock[] + stop_reason, streaming text via callback. */
|
|
33
|
-
export async function consumeStream(stream, costTracker, onTextDelta) {
|
|
33
|
+
export async function consumeStream(stream, costTracker, onTextDelta, signal) {
|
|
34
34
|
const content = [];
|
|
35
35
|
let stop_reason = "end_turn";
|
|
36
36
|
let currentText = "";
|
|
37
37
|
// Map block index -> tool state for Anthropic-style index-based IDs
|
|
38
38
|
const toolsByIndex = new Map();
|
|
39
39
|
for await (const delta of stream) {
|
|
40
|
+
if (signal?.aborted)
|
|
41
|
+
break;
|
|
40
42
|
if (delta.type === "text_delta") {
|
|
41
43
|
(onTextDelta ?? process.stdout.write.bind(process.stdout))(delta.text);
|
|
42
44
|
currentText += delta.text;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const DIM = "\x1b[2m";
|
|
2
|
+
const BOLD = "\x1b[1m";
|
|
3
|
+
const RESET = "\x1b[0m";
|
|
4
|
+
export function configCommand(parts, ctx) {
|
|
5
|
+
void parts; // no sub-commands yet — display-only
|
|
6
|
+
process.stderr.write(`\n${BOLD}Configuration${RESET}\n`);
|
|
7
|
+
process.stderr.write(`${DIM} Provider: ${ctx.providerName ?? "unknown"}${RESET}\n`);
|
|
8
|
+
process.stderr.write(`${DIM} Model: ${ctx.currentModel ?? "default"}${RESET}\n`);
|
|
9
|
+
process.stderr.write(`${DIM} Reasoning: ${ctx.currentReasoning ?? "default"}${RESET}\n`);
|
|
10
|
+
process.stderr.write(`${DIM} Project: ${ctx.phrenCtx?.project ?? "none"}${RESET}\n`);
|
|
11
|
+
process.stderr.write(`\n`);
|
|
12
|
+
return true;
|
|
13
|
+
}
|
package/dist/commands.js
CHANGED
|
@@ -3,6 +3,7 @@ import { helpCommand, turnsCommand, clearCommand, cwdCommand, filesCommand, cost
|
|
|
3
3
|
import { sessionCommand, historyCommand, compactCommand, diffCommand, gitCommand, resumeCommand } from "./commands/session.js";
|
|
4
4
|
import { memCommand, askCommand } from "./commands/memory.js";
|
|
5
5
|
import { modelCommand, providerCommand, presetCommand } from "./commands/model.js";
|
|
6
|
+
import { configCommand } from "./commands/config.js";
|
|
6
7
|
import { loadInputMode, saveInputMode, savePermissionMode } from "./settings.js";
|
|
7
8
|
const DIM = "\x1b[2m";
|
|
8
9
|
const RESET = "\x1b[0m";
|
|
@@ -20,7 +21,7 @@ export function createCommandContext(session, contextLimit) {
|
|
|
20
21
|
export const COMMAND_NAMES = [
|
|
21
22
|
"/help", "/turns", "/clear", "/cwd", "/files", "/cost", "/plan", "/undo",
|
|
22
23
|
"/context", "/model", "/provider", "/preset", "/session", "/history",
|
|
23
|
-
"/compact", "/diff", "/git", "/mem", "/ask", "/resume", "/spawn", "/agents",
|
|
24
|
+
"/compact", "/diff", "/git", "/mem", "/ask", "/resume", "/config", "/spawn", "/agents",
|
|
24
25
|
"/mode", "/permissions", "/verbose", "/theme", "/agent",
|
|
25
26
|
"/exit", "/quit", "/q",
|
|
26
27
|
];
|
|
@@ -52,6 +53,7 @@ export function handleCommand(input, ctx) {
|
|
|
52
53
|
case "/mem": return memCommand(parts, ctx);
|
|
53
54
|
case "/ask": return askCommand(parts, ctx);
|
|
54
55
|
case "/resume": return resumeCommand(parts, ctx);
|
|
56
|
+
case "/config": return configCommand(parts, ctx);
|
|
55
57
|
case "/mode": {
|
|
56
58
|
const current = loadInputMode();
|
|
57
59
|
const newMode = current === "steering" ? "queue" : "steering";
|
package/dist/tui/ansi.js
CHANGED
|
@@ -25,9 +25,14 @@ export function stripAnsi(t) {
|
|
|
25
25
|
// ── Permission mode helpers ─────────────────────────────────────────────────
|
|
26
26
|
// Cycle: ask → auto edits → plan → autopilot (matches Claude Code pattern)
|
|
27
27
|
export const PERMISSION_MODES = ["suggest", "auto-confirm", "plan", "full-auto"];
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
/** Cycle to next permission mode. Skips full-auto unless yolo is true. */
|
|
29
|
+
export function nextPermissionMode(current, yolo = false) {
|
|
30
|
+
const modes = yolo ? PERMISSION_MODES : PERMISSION_MODES.filter(m => m !== "full-auto");
|
|
31
|
+
const idx = modes.indexOf(current);
|
|
32
|
+
// If current mode is full-auto but yolo is false, jump to suggest
|
|
33
|
+
if (idx === -1)
|
|
34
|
+
return modes[0];
|
|
35
|
+
return modes[(idx + 1) % modes.length];
|
|
31
36
|
}
|
|
32
37
|
export const PERMISSION_LABELS = {
|
|
33
38
|
"suggest": "",
|
|
@@ -43,9 +48,9 @@ export const PERMISSION_ICONS = {
|
|
|
43
48
|
};
|
|
44
49
|
export const PERMISSION_COLORS = {
|
|
45
50
|
"suggest": (t) => t, // invisible / no color
|
|
46
|
-
"auto-confirm": s.
|
|
51
|
+
"auto-confirm": s.blue, // blue
|
|
47
52
|
"plan": s.magenta, // purple
|
|
48
|
-
"full-auto": s.green, // green
|
|
53
|
+
"full-auto": s.green, // green (requires --yolo to enable)
|
|
49
54
|
};
|
|
50
55
|
export function permTag(mode) {
|
|
51
56
|
return PERMISSION_COLORS[mode](`${PERMISSION_ICONS[mode]} ${PERMISSION_LABELS[mode]}`);
|
|
@@ -10,7 +10,7 @@ import { InputArea, PermissionsLine } from "./InputArea.js";
|
|
|
10
10
|
import { useKeyboardShortcuts } from "../hooks/useKeyboardShortcuts.js";
|
|
11
11
|
import { renderMarkdown } from "../../multi/markdown.js";
|
|
12
12
|
import { useSearch, highlightMatches } from "../hooks/useSearch.js";
|
|
13
|
-
export function App({ state, completedMessages, streamingText, completedToolCalls, activeTool, thinking, thinkStartTime, thinkElapsed, steerQueue, running, showBanner, inputHistory, verbose, theme, onSubmit, onPermissionCycle, onCancelTurn, onExit, agents, selectedAgentId, onSelectAgent, onCancelAgent, }) {
|
|
13
|
+
export function App({ state, completedMessages, streamingText, completedToolCalls, activeTool, thinking, thinkStartTime, thinkElapsed, steerQueue, running, showBanner, inputHistory, verbose, theme, onSubmit, onPermissionCycle, onCancelTurn, onExit, onExpandTool, agents, selectedAgentId, onSelectAgent, onCancelAgent, }) {
|
|
14
14
|
const { exit } = useApp();
|
|
15
15
|
const [inputValue, setInputValue] = useState("");
|
|
16
16
|
const [bashMode, setBashMode] = useState(false);
|
|
@@ -18,10 +18,12 @@ export function App({ state, completedMessages, streamingText, completedToolCall
|
|
|
18
18
|
const [ctrlCCount, setCtrlCCount] = useState(0);
|
|
19
19
|
const [tabFocused, setTabFocused] = useState(false);
|
|
20
20
|
const [highlightedTabIndex, setHighlightedTabIndex] = useState(0);
|
|
21
|
+
const [showTaskList, setShowTaskList] = useState(false);
|
|
21
22
|
const [stashedInput, setStashedInput] = useState("");
|
|
22
23
|
const [historySearchMode, setHistorySearchMode] = useState(false);
|
|
23
24
|
const [historySearchQuery, setHistorySearchQuery] = useState("");
|
|
24
25
|
const [historySearchIndex, setHistorySearchIndex] = useState(0);
|
|
26
|
+
const [expandedTools, setExpandedTools] = useState(new Set());
|
|
25
27
|
// ── Ctrl+F content search ────────────────────────────────────────────────
|
|
26
28
|
const search = useSearch();
|
|
27
29
|
// When the query changes, recompute total match count across all completed messages
|
|
@@ -163,6 +165,22 @@ export function App({ state, completedMessages, streamingText, completedToolCall
|
|
|
163
165
|
onContentSearch: () => {
|
|
164
166
|
search.activate();
|
|
165
167
|
},
|
|
168
|
+
onExpandTool: () => {
|
|
169
|
+
const lastIndex = completedToolCalls.length - 1;
|
|
170
|
+
if (lastIndex < 0)
|
|
171
|
+
return;
|
|
172
|
+
setExpandedTools((prev) => {
|
|
173
|
+
const next = new Set(prev);
|
|
174
|
+
if (next.has(lastIndex)) {
|
|
175
|
+
next.delete(lastIndex);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
next.add(lastIndex);
|
|
179
|
+
}
|
|
180
|
+
return next;
|
|
181
|
+
});
|
|
182
|
+
onExpandTool?.();
|
|
183
|
+
},
|
|
166
184
|
onOpenEditor: () => {
|
|
167
185
|
// Write input to temp file, open $EDITOR, read back
|
|
168
186
|
const tmpFile = `/tmp/phren-input-${Date.now()}.md`;
|
|
@@ -192,6 +210,13 @@ export function App({ state, completedMessages, streamingText, completedToolCall
|
|
|
192
210
|
onSelectAgent?.(id === "__main__" ? null : id);
|
|
193
211
|
}
|
|
194
212
|
},
|
|
213
|
+
onCycleAgent: agents && agents.length > 0 ? () => {
|
|
214
|
+
const currentIdx = agents.findIndex(a => a.id === selectedAgentId || (selectedAgentId === null && a.id === "__main__"));
|
|
215
|
+
const nextIdx = (currentIdx + 1) % agents.length;
|
|
216
|
+
const nextId = agents[nextIdx].id;
|
|
217
|
+
onSelectAgent?.(nextId === "__main__" ? null : nextId);
|
|
218
|
+
} : undefined,
|
|
219
|
+
onToggleTaskList: () => setShowTaskList(v => !v),
|
|
195
220
|
});
|
|
196
221
|
// Helper: apply search highlighting to a text string (ANSI only works in
|
|
197
222
|
// non-Ink raw text mode). Since Ink's <Text> will escape ANSI we pass raw
|
|
@@ -216,7 +241,7 @@ export function App({ state, completedMessages, streamingText, completedToolCall
|
|
|
216
241
|
return _jsx(Text, { color: theme.system.color, dimColor: true, children: applySearch(item.text) }, item.id);
|
|
217
242
|
}
|
|
218
243
|
return null;
|
|
219
|
-
} }), _jsxs(Box, { flexDirection: "column", children: [showBanner && completedMessages.length === 0 && _jsx(Banner, {
|
|
244
|
+
} }), _jsxs(Box, { flexDirection: "column", children: [showBanner && completedMessages.length === 0 && _jsx(Banner, { state: state, theme: theme }), completedToolCalls.map((tc, i) => (_jsx(ToolCall, { ...tc, verbose: verbose, theme: theme, expanded: expandedTools.has(i) }, `tc-${i}`))), activeTool && (_jsxs(Box, { paddingLeft: 2, children: [_jsx(ToolSpinner, { theme: theme }), _jsx(Text, { bold: true, color: theme.tool.name, children: activeTool.name }), activeTool.preview ? _jsxs(Text, { color: theme.tool.preview ?? theme.separator, children: [" ", activeTool.preview] }) : null] })), streamingText !== "" && (_jsxs(Box, { marginTop: 1, children: [_jsxs(Text, { color: theme.agent.color, wrap: "truncate", children: [theme.agent.label, " "] }), _jsx(Text, { wrap: "wrap", children: renderMarkdown(streamingText, theme.markdown) })] })), thinking && _jsx(Box, { marginTop: 1, children: _jsx(ThinkingIndicator, { startTime: thinkStartTime, theme: theme }) }), thinkElapsed !== null && (_jsxs(Text, { color: theme.dim, dimColor: true, children: [" ", "\u25c8", " ", thinkElapsed] })), ctrlCCount > 0 && !running && (_jsxs(Text, { dimColor: true, children: [" ", "Press Ctrl+C again to exit."] })), _jsx(SteerQueue, { items: steerQueue, theme: theme }), showTaskList && (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsxs(Text, { dimColor: true, children: [" ", "Tasks: (ctrl+t to hide)"] }), _jsxs(Text, { dimColor: true, children: [" ", "No shared task list in this session."] })] })), search.state.active && (_jsxs(Box, { children: [_jsxs(Text, { color: theme.search?.prompt ?? "cyan", children: [" ", "find: ", search.state.query, _jsx(Text, { inverse: true, children: " " })] }), search.state.matchCount > 0
|
|
220
245
|
? _jsxs(Text, { dimColor: true, color: theme.search?.match ?? undefined, children: [" (", search.state.currentMatch + 1, " of ", search.state.matchCount, ")"] })
|
|
221
246
|
: search.state.query.length > 0
|
|
222
247
|
? _jsx(Text, { dimColor: true, color: theme.search?.noMatch ?? "red", children: " (no matches)" })
|
|
@@ -224,5 +249,5 @@ export function App({ state, completedMessages, streamingText, completedToolCall
|
|
|
224
249
|
? _jsxs(Text, { dimColor: true, color: theme.search?.match ?? undefined, children: [" (match ", (historySearchIndex % historyMatches.length) + 1, " of ", historyMatches.length, ")"] })
|
|
225
250
|
: historySearchQuery.length > 0
|
|
226
251
|
? _jsx(Text, { dimColor: true, color: theme.search?.noMatch ?? "red", children: " (no matches)" })
|
|
227
|
-
: _jsx(Text, { dimColor: true, children: " (type to search history)" })] })), historySearchMode && currentMatch && (_jsx(Box, { children: _jsxs(Text, { dimColor: true, children: [" ", "\u25b8", " ", currentMatch] }) })), _jsx(InputArea, { value: inputValue, onChange: setInputValue, onSubmit: handleSubmit, bashMode: bashMode, focus: !isAnyModeActive, separatorColor: theme.separator, theme: theme }), _jsx(PermissionsLine, { mode: state.permMode, theme: theme, agents: agents, selectedAgentId: selectedAgentId, highlightedTabId: agents?.[highlightedTabIndex]?.id ?? null, tabFocused: tabFocused })] })] }));
|
|
252
|
+
: _jsx(Text, { dimColor: true, children: " (type to search history)" })] })), historySearchMode && currentMatch && (_jsx(Box, { children: _jsxs(Text, { dimColor: true, children: [" ", "\u25b8", " ", currentMatch] }) })), _jsx(InputArea, { value: inputValue, onChange: setInputValue, onSubmit: handleSubmit, bashMode: bashMode, focus: !isAnyModeActive, separatorColor: theme.separator, theme: theme }), _jsx(PermissionsLine, { mode: state.permMode, theme: theme, running: running, agents: agents, selectedAgentId: selectedAgentId, highlightedTabId: agents?.[highlightedTabIndex]?.id ?? null, tabFocused: tabFocused })] })] }));
|
|
228
253
|
}
|
|
@@ -1,47 +1,25 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Text } from "ink";
|
|
3
3
|
import * as os from "os";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return cachedArt ?? [];
|
|
11
|
-
artLoaded = true;
|
|
12
|
-
try {
|
|
13
|
-
const mod = _require("@phren/cli/phren-art");
|
|
14
|
-
cachedArt = mod.PHREN_ART.filter((l) => l.trim());
|
|
15
|
-
return cachedArt;
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
return [];
|
|
19
|
-
}
|
|
4
|
+
function formatContextWindow(n) {
|
|
5
|
+
if (n >= 1_000_000)
|
|
6
|
+
return `${Math.round(n / 1_000_000)}M ctx`;
|
|
7
|
+
if (n >= 1_000)
|
|
8
|
+
return `${Math.round(n / 1_000)}k ctx`;
|
|
9
|
+
return `${n} ctx`;
|
|
20
10
|
}
|
|
21
|
-
function
|
|
22
|
-
return t.replace(/\x1b\[[0-9;?]*[ -/]*[@-~]/g, "");
|
|
23
|
-
}
|
|
24
|
-
export function Banner({ version, theme }) {
|
|
11
|
+
export function Banner({ state, theme }) {
|
|
25
12
|
const cwd = process.cwd().replace(os.homedir(), "~");
|
|
26
|
-
const artLines = getArtLines();
|
|
27
|
-
const maxArtWidth = 26;
|
|
28
13
|
const logoColor = theme?.banner.logo ?? "magenta";
|
|
29
14
|
const versionColor = theme?.banner.version ?? "gray";
|
|
30
15
|
const cwdColor = theme?.banner.cwd ?? "cyan";
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const artVisible = stripAnsi(artLine).length;
|
|
41
|
-
const padding = Math.max(0, maxArtWidth - artVisible);
|
|
42
|
-
const info = i < infoLines.length ? infoLines[i] : null;
|
|
43
|
-
return (_jsxs(Box, { flexDirection: "row", children: [_jsx(Text, { children: artLine + " ".repeat(padding) }), info ? info.node : _jsx(Text, { children: "" })] }, i));
|
|
44
|
-
}), _jsx(Text, { children: "" })] }));
|
|
45
|
-
}
|
|
46
|
-
return (_jsxs(Box, { flexDirection: "column", paddingLeft: 2, children: [_jsxs(Box, { children: [infoLines[0].node, infoLines[1].node] }), infoLines[2].node, _jsx(Text, { children: "" })] }));
|
|
16
|
+
const modelParts = [];
|
|
17
|
+
if (state.model)
|
|
18
|
+
modelParts.push(state.model);
|
|
19
|
+
if (state.contextWindow)
|
|
20
|
+
modelParts.push(formatContextWindow(state.contextWindow));
|
|
21
|
+
if (state.reasoningEffort)
|
|
22
|
+
modelParts.push(state.reasoningEffort);
|
|
23
|
+
const modelLine = modelParts.join(" · ");
|
|
24
|
+
return (_jsxs(Box, { flexDirection: "column", paddingLeft: 2, children: [_jsxs(Box, { flexDirection: "row", children: [_jsx(Text, { bold: true, color: logoColor, children: "◆ phren" }), _jsx(Text, { color: versionColor, dimColor: true, children: " v" + state.version })] }), modelLine ? (_jsx(Text, { color: versionColor, dimColor: true, children: modelLine })) : null, _jsx(Text, { color: cwdColor, dimColor: true, children: cwd }), _jsx(Text, { children: "" })] }));
|
|
47
25
|
}
|
|
@@ -9,9 +9,9 @@ export function InputArea({ value, onChange, onSubmit, bashMode, focus, separato
|
|
|
9
9
|
const sepColor = theme?.input.separator ?? separatorColor ?? "gray";
|
|
10
10
|
const promptColor = theme?.input.prompt ?? undefined;
|
|
11
11
|
const bashPromptColor = theme?.input.bashPrompt ?? "yellow";
|
|
12
|
-
return (
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
return (_jsxs(Box, { flexDirection: "row", borderStyle: "round", borderColor: sepColor, borderLeft: false, borderRight: false, borderTop: true, borderBottom: true, width: columns, marginTop: 1, children: [bashMode
|
|
13
|
+
? _jsx(Text, { color: bashPromptColor, children: "! " })
|
|
14
|
+
: _jsxs(Text, { color: promptColor, dimColor: true, children: ["\u276f", " "] }), _jsx(PhrenInput, { value: value, onChange: onChange, onSubmit: onSubmit, focus: focus })] }));
|
|
15
15
|
}
|
|
16
16
|
const STATUS_ICON = {
|
|
17
17
|
running: "\u25cf", // ●
|
|
@@ -21,14 +21,14 @@ const STATUS_ICON = {
|
|
|
21
21
|
starting: "\u25cc", // ◌
|
|
22
22
|
cancelled: "\u2500", // ─
|
|
23
23
|
};
|
|
24
|
-
export function PermissionsLine({ mode, theme, agents, selectedAgentId, highlightedTabId, tabFocused }) {
|
|
24
|
+
export function PermissionsLine({ mode, theme, running, agents, selectedAgentId, highlightedTabId, tabFocused }) {
|
|
25
25
|
const icon = PERMISSION_ICONS[mode];
|
|
26
26
|
const label = PERMISSION_LABELS[mode];
|
|
27
27
|
const permColors = theme?.permission;
|
|
28
28
|
const color = mode === "suggest"
|
|
29
29
|
? (permColors?.suggest ?? "")
|
|
30
30
|
: mode === "auto-confirm"
|
|
31
|
-
? (permColors?.auto ?? "
|
|
31
|
+
? (permColors?.auto ?? "blue")
|
|
32
32
|
: mode === "plan"
|
|
33
33
|
? (permColors?.plan ?? "magenta")
|
|
34
34
|
: (permColors?.fullAuto ?? "green");
|
|
@@ -49,7 +49,7 @@ export function PermissionsLine({ mode, theme, agents, selectedAgentId, highligh
|
|
|
49
49
|
}
|
|
50
50
|
return agent.color;
|
|
51
51
|
}
|
|
52
|
-
return (_jsxs(Box, { children: [showPerm ? (_jsxs(Text, { children: [" ", _jsxs(Text, { color: color, children: [icon, " ", label] }),
|
|
52
|
+
return (_jsxs(Box, { children: [showPerm ? (_jsxs(Text, { children: [" ", _jsxs(Text, { color: color, children: [icon, " ", label] }), _jsxs(Text, { dimColor: true, children: [" (shift+tab to cycle)", running ? " \u00b7 esc to interrupt" : ""] })] })) : (_jsxs(Text, { children: [" ", running ? _jsx(Text, { dimColor: true, children: "esc to interrupt" }) : null] })), hasAgents ? (_jsxs(Text, { children: [" ", agents.map((agent, i) => {
|
|
53
53
|
const isActive = agent.id === selectedAgentId;
|
|
54
54
|
const isHighlighted = tabFocused && agent.id === highlightedTabId;
|
|
55
55
|
const statusIcon = STATUS_ICON[agent.status];
|
|
@@ -98,10 +98,10 @@ export function PhrenInput({ value, onChange, onSubmit, placeholder, focus = tru
|
|
|
98
98
|
}
|
|
99
99
|
return;
|
|
100
100
|
}
|
|
101
|
-
// Left arrow
|
|
101
|
+
// Left arrow — move cursor left (with word jump modifiers)
|
|
102
102
|
if (key.leftArrow || (key.ctrl && input === "b")) {
|
|
103
|
-
if (key.meta) {
|
|
104
|
-
// Alt+Left / Alt+B — word jump left
|
|
103
|
+
if (key.meta || key.ctrl) {
|
|
104
|
+
// Alt+Left / Ctrl+Left / Alt+B / Ctrl+B — word jump left
|
|
105
105
|
setCursor((c) => wordBoundaryLeft(value, c));
|
|
106
106
|
}
|
|
107
107
|
else {
|
|
@@ -109,10 +109,10 @@ export function PhrenInput({ value, onChange, onSubmit, placeholder, focus = tru
|
|
|
109
109
|
}
|
|
110
110
|
return;
|
|
111
111
|
}
|
|
112
|
-
// Right arrow
|
|
112
|
+
// Right arrow — move cursor right (with word jump modifiers)
|
|
113
113
|
if (key.rightArrow || (key.ctrl && input === "f")) {
|
|
114
|
-
if (key.meta) {
|
|
115
|
-
// Alt+Right / Alt+F — word jump right
|
|
114
|
+
if (key.meta || key.ctrl) {
|
|
115
|
+
// Alt+Right / Ctrl+Right / Alt+F / Ctrl+F — word jump right
|
|
116
116
|
setCursor((c) => wordBoundaryRight(value, c));
|
|
117
117
|
}
|
|
118
118
|
else {
|
|
@@ -120,7 +120,7 @@ export function PhrenInput({ value, onChange, onSubmit, placeholder, focus = tru
|
|
|
120
120
|
}
|
|
121
121
|
return;
|
|
122
122
|
}
|
|
123
|
-
// Alt+B — word jump left (standalone
|
|
123
|
+
// Alt+B — word jump left (standalone)
|
|
124
124
|
if (key.meta && input === "b") {
|
|
125
125
|
setCursor((c) => wordBoundaryLeft(value, c));
|
|
126
126
|
return;
|
|
@@ -142,6 +142,20 @@ export function PhrenInput({ value, onChange, onSubmit, placeholder, focus = tru
|
|
|
142
142
|
setCursor(posToOffset(lines, line, lines[line].length));
|
|
143
143
|
return;
|
|
144
144
|
}
|
|
145
|
+
// Alt+Backspace / Alt+Delete — delete word before cursor
|
|
146
|
+
if ((key.backspace || key.delete) && key.meta) {
|
|
147
|
+
const boundary = wordBoundaryLeft(value, cursor);
|
|
148
|
+
onChange(value.slice(0, boundary) + value.slice(cursor));
|
|
149
|
+
setCursor(boundary);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
// Ctrl+Backspace / Ctrl+Delete — delete word before cursor
|
|
153
|
+
if ((key.backspace || key.delete) && key.ctrl) {
|
|
154
|
+
const boundary = wordBoundaryLeft(value, cursor);
|
|
155
|
+
onChange(value.slice(0, boundary) + value.slice(cursor));
|
|
156
|
+
setCursor(boundary);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
145
159
|
// Backspace — delete character before cursor
|
|
146
160
|
if (key.backspace || key.delete) {
|
|
147
161
|
if (cursor > 0) {
|
|
@@ -23,5 +23,5 @@ export function ThinkingIndicator({ startTime: _startTime, theme }) {
|
|
|
23
23
|
const g = Math.round(pg * (1 - t) + sg * t);
|
|
24
24
|
const b = Math.round(pb * (1 - t) + sb * t);
|
|
25
25
|
const hex = `#${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}`;
|
|
26
|
-
return (_jsxs(Text, { children: [" ", _jsxs(Text, { color: hex, children: ["\u25c6", " ", verb, "
|
|
26
|
+
return (_jsxs(Text, { children: [" ", _jsxs(Text, { color: hex, children: ["\u25c6", " ", verb, "\u2026"] })] }));
|
|
27
27
|
}
|
|
@@ -2,7 +2,7 @@ import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-run
|
|
|
2
2
|
import { Box, Text } from "ink";
|
|
3
3
|
import { formatToolInput, formatDuration, fileLink, isFileToolPreview } from "../tool-render.js";
|
|
4
4
|
const FOLD_LINES = 3;
|
|
5
|
-
export function ToolCall({ name, input, output, isError, durationMs, diffRendered, verbose, theme }) {
|
|
5
|
+
export function ToolCall({ name, input, output, isError, durationMs, diffRendered, verbose, theme, expanded }) {
|
|
6
6
|
const rawPreview = formatToolInput(name, input);
|
|
7
7
|
const preview = isFileToolPreview(name) && rawPreview ? fileLink(rawPreview) : rawPreview;
|
|
8
8
|
const dur = formatDuration(durationMs);
|
|
@@ -17,7 +17,7 @@ export function ToolCall({ name, input, output, isError, durationMs, diffRendere
|
|
|
17
17
|
return (_jsxs(Box, { flexDirection: "column", paddingLeft: 2, children: [header, diffRendered && (_jsxs(Text, { children: [" \u23bf ", diffRendered] }))] }));
|
|
18
18
|
}
|
|
19
19
|
const allLines = output.split("\n").filter(Boolean);
|
|
20
|
-
const shown = allLines.slice(0, FOLD_LINES);
|
|
20
|
+
const shown = expanded ? allLines : allLines.slice(0, FOLD_LINES);
|
|
21
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"] }))] }))] }));
|
|
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))), !expanded && overflow > 0 && (_jsxs(Text, { color: outputColor, dimColor: true, children: [" \u2026 +", overflow, " lines (ctrl+o to expand)"] }))] }))] }));
|
|
23
23
|
}
|
|
@@ -32,6 +32,11 @@ export function useKeyboardShortcuts(opts) {
|
|
|
32
32
|
// Any other key: exit tab bar and fall through
|
|
33
33
|
opts.onExitTabBar?.();
|
|
34
34
|
}
|
|
35
|
+
// Shift+Down → cycle through agent tabs
|
|
36
|
+
if (key.downArrow && key.shift && opts.onCycleAgent) {
|
|
37
|
+
opts.onCycleAgent();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
35
40
|
// Down arrow (empty input) → enter tab bar
|
|
36
41
|
if (key.downArrow && opts.inputValue === "" && opts.onEnterTabBar && !opts.tabFocused) {
|
|
37
42
|
opts.onEnterTabBar();
|
|
@@ -65,6 +70,16 @@ export function useKeyboardShortcuts(opts) {
|
|
|
65
70
|
opts.onContentSearch?.();
|
|
66
71
|
return;
|
|
67
72
|
}
|
|
73
|
+
// Ctrl+O -- expand/collapse last tool call output
|
|
74
|
+
if (key.ctrl && input === "o") {
|
|
75
|
+
opts.onExpandTool?.();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// Ctrl+T -- toggle task list display
|
|
79
|
+
if (key.ctrl && input === "t") {
|
|
80
|
+
opts.onToggleTaskList?.();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
68
83
|
// Ctrl+D -- exit cleanly
|
|
69
84
|
if (key.ctrl && input === "d") {
|
|
70
85
|
opts.onExit();
|
|
@@ -98,8 +113,12 @@ export function useKeyboardShortcuts(opts) {
|
|
|
98
113
|
opts.onSetCtrlCCount(opts.ctrlCCount + 1);
|
|
99
114
|
return;
|
|
100
115
|
}
|
|
101
|
-
// Escape -- cancel
|
|
116
|
+
// Escape -- cancel running turn, exit bash mode, clear input, or cancel agent
|
|
102
117
|
if (key.escape) {
|
|
118
|
+
if (opts.isRunning) {
|
|
119
|
+
opts.onCancelTurn();
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
103
122
|
if (opts.bashMode) {
|
|
104
123
|
opts.onSetBashMode(false);
|
|
105
124
|
opts.onSetInput("");
|
|
@@ -108,7 +127,6 @@ export function useKeyboardShortcuts(opts) {
|
|
|
108
127
|
opts.onSetInput("");
|
|
109
128
|
}
|
|
110
129
|
else if (opts.onEscCancelAgent) {
|
|
111
|
-
// No input, not in bash mode — cancel the selected agent's work
|
|
112
130
|
opts.onEscCancelAgent();
|
|
113
131
|
}
|
|
114
132
|
return;
|
package/dist/tui/ink-entry.js
CHANGED
|
@@ -26,9 +26,10 @@ export async function startInkTui(config, spawner) {
|
|
|
26
26
|
let verbose = false;
|
|
27
27
|
let theme = getTheme();
|
|
28
28
|
let msgCounter = 0;
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
// Autopilot (full-auto) requires --yolo flag to be cycleable via Shift+Tab
|
|
30
|
+
const yoloEnabled = config.registry.permissionConfig.mode === "full-auto";
|
|
31
|
+
const permissionQueue = [];
|
|
32
|
+
// Ink-compatible askUser: shows prompt in chat, queues for y/n in input
|
|
32
33
|
config.registry.askUser = async (toolName, input, reason) => {
|
|
33
34
|
const { addAllow } = await import("../permissions/allowlist.js");
|
|
34
35
|
const summary = Object.keys(input).length > 0
|
|
@@ -37,18 +38,11 @@ export async function startInkTui(config, spawner) {
|
|
|
37
38
|
completedMessages.push({
|
|
38
39
|
id: nextId(),
|
|
39
40
|
kind: "status",
|
|
40
|
-
text: `\x1b[1m\x1b[33m
|
|
41
|
+
text: `\x1b[1m\x1b[33m◇ Allow ${toolName}?\x1b[0m ${summary}\n \x1b[2m[y]es [n]o [a]llow [s]ession or type feedback to deny & redirect\x1b[0m`,
|
|
41
42
|
});
|
|
42
43
|
update();
|
|
43
44
|
return new Promise((resolve) => {
|
|
44
|
-
|
|
45
|
-
permissionResolve = null;
|
|
46
|
-
resolve(allowed);
|
|
47
|
-
};
|
|
48
|
-
// Store the addAllow function for a/s responses
|
|
49
|
-
permissionResolve.toolName = toolName;
|
|
50
|
-
permissionResolve.input = input;
|
|
51
|
-
permissionResolve.addAllow = addAllow;
|
|
45
|
+
permissionQueue.push({ resolve, toolName, input, addAllow });
|
|
52
46
|
});
|
|
53
47
|
};
|
|
54
48
|
// Mutable render state — updated then pushed to React via rerender()
|
|
@@ -71,6 +65,9 @@ export async function startInkTui(config, spawner) {
|
|
|
71
65
|
permMode: config.registry.permissionConfig.mode,
|
|
72
66
|
agentCount: spawner?.listAgents().length ?? 0,
|
|
73
67
|
version: AGENT_VERSION,
|
|
68
|
+
model: config.provider.model,
|
|
69
|
+
contextWindow: config.provider.contextWindow,
|
|
70
|
+
reasoningEffort: config.provider.reasoningEffort,
|
|
74
71
|
};
|
|
75
72
|
}
|
|
76
73
|
// Re-render the Ink app with current state
|
|
@@ -105,7 +102,7 @@ export async function startInkTui(config, spawner) {
|
|
|
105
102
|
rerender(_jsx(App, { state: getAppState(), completedMessages: displayMessages, streamingText: displayStreaming, completedToolCalls: displayToolCalls, activeTool: displayActiveTool, thinking: displayThinking, thinkStartTime: thinkStartTime, thinkElapsed: agentConvo ? null : thinkElapsed, steerQueue: agentConvo ? [] : [...steerQueueBuf], running: displayRunning, showBanner: !selectedAgentId, inputHistory: [...inputHistory], verbose: verbose, theme: theme, onSubmit: handleSubmit, onPermissionCycle: handlePermissionCycle, onCancelTurn: handleCancelTurn, onExit: handleExit, agents: agentTabs.length > 0 ? [{ id: "__main__", name: "phren", status: running ? "running" : "idle", color: "magentaBright" }, ...agentTabs] : undefined, selectedAgentId: selectedAgentId ?? (agentTabs.length > 0 ? "__main__" : undefined), onCancelAgent: handleCancelAgent, onSelectAgent: (id) => handleSelectAgent(id === "__main__" ? null : id) }));
|
|
106
103
|
}
|
|
107
104
|
function handlePermissionCycle() {
|
|
108
|
-
const next = nextPermissionMode(config.registry.permissionConfig.mode);
|
|
105
|
+
const next = nextPermissionMode(config.registry.permissionConfig.mode, yoloEnabled);
|
|
109
106
|
config.registry.setPermissions({ ...config.registry.permissionConfig, mode: next });
|
|
110
107
|
savePermissionMode(next);
|
|
111
108
|
update();
|
|
@@ -115,8 +112,12 @@ export async function startInkTui(config, spawner) {
|
|
|
115
112
|
if (resolveSession)
|
|
116
113
|
resolveSession(session);
|
|
117
114
|
}
|
|
115
|
+
let turnAbort = null;
|
|
118
116
|
function handleCancelTurn() {
|
|
119
|
-
|
|
117
|
+
if (turnAbort) {
|
|
118
|
+
turnAbort.abort();
|
|
119
|
+
turnAbort = null;
|
|
120
|
+
}
|
|
120
121
|
pendingInput = null;
|
|
121
122
|
steerQueueBuf.length = 0;
|
|
122
123
|
update();
|
|
@@ -157,27 +158,35 @@ export async function startInkTui(config, spawner) {
|
|
|
157
158
|
const line = input.trim();
|
|
158
159
|
if (!line)
|
|
159
160
|
return;
|
|
160
|
-
// Permission prompt active — intercept y/n/a/s
|
|
161
|
-
if (
|
|
161
|
+
// Permission prompt active — intercept y/n/a/s (process next in queue)
|
|
162
|
+
if (permissionQueue.length > 0) {
|
|
163
|
+
const entry = permissionQueue.shift();
|
|
162
164
|
const key = line.toLowerCase();
|
|
163
|
-
const meta = permissionResolve;
|
|
164
165
|
if (key === "y" || key === "yes") {
|
|
165
|
-
completedMessages.push({ id: nextId(), kind: "status", text:
|
|
166
|
-
|
|
166
|
+
completedMessages.push({ id: nextId(), kind: "status", text: `\x1b[32m\u2713 ${entry.toolName}\x1b[0m` });
|
|
167
|
+
entry.resolve(true);
|
|
167
168
|
}
|
|
168
169
|
else if (key === "a") {
|
|
169
|
-
completedMessages.push({ id: nextId(), kind: "status", text:
|
|
170
|
-
|
|
171
|
-
|
|
170
|
+
completedMessages.push({ id: nextId(), kind: "status", text: `\x1b[32m\u2713 ${entry.toolName} (always)\x1b[0m` });
|
|
171
|
+
entry.addAllow(entry.toolName, entry.input, "tool");
|
|
172
|
+
entry.resolve(true);
|
|
172
173
|
}
|
|
173
174
|
else if (key === "s") {
|
|
174
|
-
completedMessages.push({ id: nextId(), kind: "status", text:
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
completedMessages.push({ id: nextId(), kind: "status", text: `\x1b[32m\u2713 ${entry.toolName} (session)\x1b[0m` });
|
|
176
|
+
entry.addAllow(entry.toolName, entry.input, "session");
|
|
177
|
+
entry.resolve(true);
|
|
177
178
|
}
|
|
178
179
|
else {
|
|
179
|
-
|
|
180
|
-
|
|
180
|
+
// Deny with feedback: if the input is more than a single n/no, treat it as a redirect message
|
|
181
|
+
const isSilentDeny = key === "n" || key === "no";
|
|
182
|
+
if (!isSilentDeny && line.length > 1) {
|
|
183
|
+
completedMessages.push({ id: nextId(), kind: "status", text: `\x1b[31m\u2717 ${entry.toolName} \x1b[2m\u2014 redirecting: "${line}"\x1b[0m` });
|
|
184
|
+
steerQueueBuf.push(line);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
completedMessages.push({ id: nextId(), kind: "status", text: `\x1b[31m\u2717 ${entry.toolName}\x1b[0m` });
|
|
188
|
+
}
|
|
189
|
+
entry.resolve(false);
|
|
181
190
|
}
|
|
182
191
|
update();
|
|
183
192
|
return;
|
|
@@ -371,6 +380,7 @@ export async function startInkTui(config, spawner) {
|
|
|
371
380
|
async function runAgentTurn(userInput) {
|
|
372
381
|
running = true;
|
|
373
382
|
thinking = true;
|
|
383
|
+
turnAbort = new AbortController();
|
|
374
384
|
thinkStartTime = Date.now();
|
|
375
385
|
thinkElapsed = null;
|
|
376
386
|
streamingText = "";
|
|
@@ -379,7 +389,7 @@ export async function startInkTui(config, spawner) {
|
|
|
379
389
|
const pastVerb = PAST_VERBS[Math.floor(Math.random() * PAST_VERBS.length)];
|
|
380
390
|
update();
|
|
381
391
|
try {
|
|
382
|
-
await runTurn(userInput, session, config, tuiHooks);
|
|
392
|
+
await runTurn(userInput, session, config, { ...tuiHooks, signal: turnAbort?.signal });
|
|
383
393
|
}
|
|
384
394
|
catch (err) {
|
|
385
395
|
const msg = err instanceof Error ? err.message : String(err);
|
package/dist/tui/themes.js
CHANGED