@phren/agent 0.1.9 → 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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useState, useCallback, useEffect } from "react";
|
|
3
3
|
import { Static, Box, Text, useApp, useInput } from "ink";
|
|
4
4
|
import { Banner } from "./Banner.js";
|
|
@@ -201,18 +201,7 @@ export function App({ state, completedMessages, streamingText, completedToolCall
|
|
|
201
201
|
return text;
|
|
202
202
|
return highlightMatches(text, search.state.query).highlighted;
|
|
203
203
|
}, [search.state.active, search.state.query]);
|
|
204
|
-
|
|
205
|
-
const staticItems = [];
|
|
206
|
-
if (showBanner) {
|
|
207
|
-
staticItems.push({ id: "banner", kind: "banner" });
|
|
208
|
-
}
|
|
209
|
-
for (const msg of completedMessages) {
|
|
210
|
-
staticItems.push(msg);
|
|
211
|
-
}
|
|
212
|
-
return (_jsxs(_Fragment, { children: [_jsx(Static, { items: staticItems, children: (item) => {
|
|
213
|
-
if (item.kind === "banner") {
|
|
214
|
-
return (_jsx(Box, { flexDirection: "column", children: _jsx(Banner, { version: state.version, theme: theme }) }, "banner"));
|
|
215
|
-
}
|
|
204
|
+
return (_jsxs(_Fragment, { children: [_jsx(Static, { items: completedMessages, children: (item) => {
|
|
216
205
|
if (item.kind === "user") {
|
|
217
206
|
return (_jsx(Box, { flexDirection: "column", children: _jsxs(Text, { bold: theme.user.bold ?? true, color: theme.user.color, children: [theme.user.label, " ", applySearch(item.text)] }) }, item.id));
|
|
218
207
|
}
|
|
@@ -227,7 +216,7 @@ export function App({ state, completedMessages, streamingText, completedToolCall
|
|
|
227
216
|
return _jsx(Text, { color: theme.system.color, dimColor: true, children: applySearch(item.text) }, item.id);
|
|
228
217
|
}
|
|
229
218
|
return null;
|
|
230
|
-
} }), _jsxs(Box, { flexDirection: "column", children: [completedToolCalls.map((tc, i) => (_jsx(ToolCall, { ...tc, verbose: verbose, theme: theme }, `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: streamingText })] })), thinking && _jsx(Box, { marginTop: 1, children: _jsx(ThinkingIndicator, { startTime: thinkStartTime, theme: theme }) }), thinkElapsed !== null && (_jsxs(Text, { color: theme.dim, dimColor: true, children: [" ", "\
|
|
219
|
+
} }), _jsxs(Box, { flexDirection: "column", children: [showBanner && completedMessages.length === 0 && _jsx(Banner, { version: state.version, theme: theme }), completedToolCalls.map((tc, i) => (_jsx(ToolCall, { ...tc, verbose: verbose, theme: theme }, `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 }), 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
|
|
231
220
|
? _jsxs(Text, { dimColor: true, color: theme.search?.match ?? undefined, children: [" (", search.state.currentMatch + 1, " of ", search.state.matchCount, ")"] })
|
|
232
221
|
: search.state.query.length > 0
|
|
233
222
|
? _jsx(Text, { dimColor: true, color: theme.search?.noMatch ?? "red", children: " (no matches)" })
|
|
@@ -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 (_jsx(Box, { flexDirection: "column", marginTop: 1, children: _jsxs(Box, { 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", // ●
|
|
@@ -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] })] })) : (_jsx(Text, { children: " " })), hasAgents ? (_jsxs(Text, { children: [" ", agents.map((agent, i) => {
|
|
52
|
+
return (_jsxs(Box, { children: [showPerm ? (_jsxs(Text, { children: [" ", _jsxs(Text, { color: color, children: [icon, " ", label] }), _jsx(Text, { dimColor: true, children: " (shift+tab to cycle)" })] })) : (_jsx(Text, { children: " " })), 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];
|
|
@@ -1,28 +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
|
|
4
|
+
// Phren's own thinking verbs — memory-oriented
|
|
5
5
|
const THINKING_VERBS = [
|
|
6
|
-
"
|
|
6
|
+
"recalling", "connecting", "reasoning", "threading", "mapping", "synthesizing",
|
|
7
7
|
];
|
|
8
|
-
export function ThinkingIndicator({ startTime, theme }) {
|
|
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
|
-
},
|
|
15
|
+
}, 500);
|
|
16
16
|
return () => clearInterval(timer);
|
|
17
17
|
}, []);
|
|
18
|
-
const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
|
|
19
18
|
// Gentle sine-wave interpolation between theme thinking colors
|
|
20
|
-
const t = (Math.sin(frame * 0.
|
|
19
|
+
const t = (Math.sin(frame * 0.4) + 1) / 2;
|
|
21
20
|
const [pr, pg, pb] = theme.thinking.primary;
|
|
22
21
|
const [sr, sg, sb] = theme.thinking.secondary;
|
|
23
22
|
const r = Math.round(pr * (1 - t) + sr * t);
|
|
24
23
|
const g = Math.round(pg * (1 - t) + sg * t);
|
|
25
24
|
const b = Math.round(pb * (1 - t) + sb * t);
|
|
26
25
|
const hex = `#${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}`;
|
|
27
|
-
return (_jsxs(Text, { children: [" ", _jsxs(Text, { color: hex, children: ["\u25c6", " ", verb
|
|
26
|
+
return (_jsxs(Text, { children: [" ", _jsxs(Text, { color: hex, children: ["\u25c6", " ", verb, "\\u2026"] })] }));
|
|
28
27
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Text } from "ink";
|
|
3
3
|
import { formatToolInput, formatDuration, fileLink, isFileToolPreview } from "../tool-render.js";
|
|
4
|
-
const
|
|
4
|
+
const FOLD_LINES = 3;
|
|
5
5
|
export function ToolCall({ name, input, output, isError, durationMs, diffRendered, verbose, theme }) {
|
|
6
6
|
const rawPreview = formatToolInput(name, input);
|
|
7
7
|
const preview = isFileToolPreview(name) && rawPreview ? fileLink(rawPreview) : rawPreview;
|
|
@@ -11,11 +11,13 @@ export function ToolCall({ name, input, output, isError, durationMs, diffRendere
|
|
|
11
11
|
const previewColor = theme?.tool.preview ?? theme?.separator ?? "gray";
|
|
12
12
|
const durationColor = theme?.tool.duration ?? undefined;
|
|
13
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] })] }));
|
|
14
16
|
if (!verbose) {
|
|
15
|
-
return (_jsxs(Box, { flexDirection: "column", paddingLeft: 2, children: [
|
|
17
|
+
return (_jsxs(Box, { flexDirection: "column", paddingLeft: 2, children: [header, diffRendered && (_jsxs(Text, { children: [" \u23bf ", diffRendered] }))] }));
|
|
16
18
|
}
|
|
17
19
|
const allLines = output.split("\n").filter(Boolean);
|
|
18
|
-
const shown = allLines.slice(0,
|
|
19
|
-
const overflow = allLines.length -
|
|
20
|
-
return (_jsxs(Box, { flexDirection: "column", paddingLeft: 2, children: [_jsxs(
|
|
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"] }))] }))] }));
|
|
21
23
|
}
|
package/dist/tui/ink-entry.js
CHANGED
|
@@ -12,8 +12,6 @@ import { nextPermissionMode } from "./ansi.js";
|
|
|
12
12
|
import { App } from "./components/App.js";
|
|
13
13
|
import { createRequire } from "node:module";
|
|
14
14
|
import { getTheme, THEME_NAMES } from "./themes.js";
|
|
15
|
-
import { TerminalControl } from "./terminal-control.js";
|
|
16
|
-
import { enableMouse, disableMouse, parseMouseEvent } from "./mouse.js";
|
|
17
15
|
const _require = createRequire(import.meta.url);
|
|
18
16
|
const AGENT_VERSION = _require("../../package.json").version;
|
|
19
17
|
export async function startInkTui(config, spawner) {
|
|
@@ -28,10 +26,6 @@ export async function startInkTui(config, spawner) {
|
|
|
28
26
|
let verbose = false;
|
|
29
27
|
let theme = getTheme();
|
|
30
28
|
let msgCounter = 0;
|
|
31
|
-
const terminalControl = new TerminalControl();
|
|
32
|
-
// Mouse handler ref — assigned after agentTabs/handleSelectAgent are defined.
|
|
33
|
-
// Stored here so handleExit (defined before the handler) can call .off on it.
|
|
34
|
-
let mouseHandler = () => { };
|
|
35
29
|
// Permission prompt state — when set, input field captures y/n/a/s
|
|
36
30
|
let permissionResolve = null;
|
|
37
31
|
// Ink-compatible askUser: shows prompt in chat, waits for y/n in input
|
|
@@ -79,17 +73,6 @@ export async function startInkTui(config, spawner) {
|
|
|
79
73
|
version: AGENT_VERSION,
|
|
80
74
|
};
|
|
81
75
|
}
|
|
82
|
-
function renderFixedStatus() {
|
|
83
|
-
if (!terminalControl.isEnabled)
|
|
84
|
-
return;
|
|
85
|
-
const s = getAppState();
|
|
86
|
-
const cols = process.stdout.columns || 80;
|
|
87
|
-
const left = ` \u25c6 phren \u00b7 ${s.provider}${s.project ? ` \u00b7 ${s.project}` : ""}`;
|
|
88
|
-
const right = `${s.permMode} T:${s.turns}${s.agentCount > 0 ? ` A:${s.agentCount}` : ""} `;
|
|
89
|
-
const pad = Math.max(0, cols - left.length - right.length);
|
|
90
|
-
const line = `\x1b[7m${left}${" ".repeat(pad)}${right}\x1b[0m`;
|
|
91
|
-
terminalControl.renderStatusBar(process.stdout, line);
|
|
92
|
-
}
|
|
93
76
|
// Re-render the Ink app with current state
|
|
94
77
|
let rerender = null;
|
|
95
78
|
// Ink app instance — set after render(), used by closures for clear()
|
|
@@ -110,18 +93,16 @@ export async function startInkTui(config, spawner) {
|
|
|
110
93
|
return;
|
|
111
94
|
// Determine what to display based on selected view
|
|
112
95
|
const agentConvo = selectedAgentId ? agentConvos.get(selectedAgentId) : null;
|
|
113
|
-
//
|
|
96
|
+
// Prefix IDs so <Static> re-renders after agent tab switch
|
|
114
97
|
const prefix = `v${viewSwitchCounter}-`;
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
: completedMessages.map((m) => ({ ...m, id: prefix + m.id }));
|
|
98
|
+
const rawMessages = agentConvo ? agentConvo.messages : completedMessages;
|
|
99
|
+
const displayMessages = rawMessages.map((m) => ({ ...m, id: prefix + m.id }));
|
|
118
100
|
const displayStreaming = agentConvo ? agentConvo.streamingText : streamingText;
|
|
119
101
|
const displayToolCalls = agentConvo ? [...agentConvo.toolCalls] : [...currentToolCalls];
|
|
120
102
|
const displayActiveTool = agentConvo ? agentConvo.activeTool : activeTool;
|
|
121
103
|
const displayThinking = agentConvo ? false : thinking;
|
|
122
104
|
const displayRunning = agentConvo ? (spawner?.getAgent(selectedAgentId)?.status === "running" || false) : running;
|
|
123
105
|
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) }));
|
|
124
|
-
renderFixedStatus();
|
|
125
106
|
}
|
|
126
107
|
function handlePermissionCycle() {
|
|
127
108
|
const next = nextPermissionMode(config.registry.permissionConfig.mode);
|
|
@@ -131,11 +112,6 @@ export async function startInkTui(config, spawner) {
|
|
|
131
112
|
}
|
|
132
113
|
let resolveSession = null;
|
|
133
114
|
function handleExit() {
|
|
134
|
-
disableMouse(process.stdout);
|
|
135
|
-
if (process.stdin.isTTY) {
|
|
136
|
-
process.stdin.off("data", mouseHandler);
|
|
137
|
-
}
|
|
138
|
-
terminalControl.disable(process.stdout);
|
|
139
115
|
if (resolveSession)
|
|
140
116
|
resolveSession(session);
|
|
141
117
|
}
|
|
@@ -339,10 +315,13 @@ export async function startInkTui(config, spawner) {
|
|
|
339
315
|
update();
|
|
340
316
|
return;
|
|
341
317
|
}
|
|
342
|
-
// Normal user message —
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
318
|
+
// Normal user message — defer static push to next tick so dynamic area is clean
|
|
319
|
+
update(); // flush clean state first (empty input)
|
|
320
|
+
setImmediate(() => {
|
|
321
|
+
completedMessages.push({ id: nextId(), kind: "user", text: line });
|
|
322
|
+
update();
|
|
323
|
+
runAgentTurn(line);
|
|
324
|
+
});
|
|
346
325
|
}
|
|
347
326
|
// TurnHooks bridge — updates mutable state, calls update()
|
|
348
327
|
const tuiHooks = {
|
|
@@ -387,6 +366,8 @@ export async function startInkTui(config, spawner) {
|
|
|
387
366
|
return result;
|
|
388
367
|
},
|
|
389
368
|
};
|
|
369
|
+
// Phren's past-tense verbs for turn summaries
|
|
370
|
+
const PAST_VERBS = ["Recalled", "Reasoned", "Connected", "Synthesized", "Reflected", "Distilled", "Threaded", "Mapped"];
|
|
390
371
|
async function runAgentTurn(userInput) {
|
|
391
372
|
running = true;
|
|
392
373
|
thinking = true;
|
|
@@ -395,6 +376,7 @@ export async function startInkTui(config, spawner) {
|
|
|
395
376
|
streamingText = "";
|
|
396
377
|
currentToolCalls = [];
|
|
397
378
|
activeTool = null;
|
|
379
|
+
const pastVerb = PAST_VERBS[Math.floor(Math.random() * PAST_VERBS.length)];
|
|
398
380
|
update();
|
|
399
381
|
try {
|
|
400
382
|
await runTurn(userInput, session, config, tuiHooks);
|
|
@@ -419,7 +401,7 @@ export async function startInkTui(config, spawner) {
|
|
|
419
401
|
currentToolCalls = [];
|
|
420
402
|
activeTool = null;
|
|
421
403
|
running = false;
|
|
422
|
-
thinkElapsed = elapsed
|
|
404
|
+
thinkElapsed = `${pastVerb} for ${elapsed}s`;
|
|
423
405
|
process.stdout.write("\x07"); // terminal bell on completion
|
|
424
406
|
update();
|
|
425
407
|
// Clear elapsed indicator after a brief display
|
|
@@ -469,14 +451,13 @@ export async function startInkTui(config, spawner) {
|
|
|
469
451
|
color: TAB_COLORS[i % TAB_COLORS.length],
|
|
470
452
|
}));
|
|
471
453
|
}
|
|
472
|
-
// Switch views: clear screen
|
|
454
|
+
// Switch views: clear screen so <Static> re-renders with fresh IDs
|
|
473
455
|
let viewSwitchCounter = 0;
|
|
474
456
|
function handleSelectAgent(agentId) {
|
|
475
457
|
if (agentId === selectedAgentId)
|
|
476
458
|
return;
|
|
477
459
|
selectedAgentId = agentId;
|
|
478
460
|
viewSwitchCounter++;
|
|
479
|
-
// Clear screen so Ink's <Static> re-renders with fresh items
|
|
480
461
|
if (appInstance)
|
|
481
462
|
appInstance.clear();
|
|
482
463
|
else
|
|
@@ -594,52 +575,11 @@ export async function startInkTui(config, spawner) {
|
|
|
594
575
|
process.title = "phren";
|
|
595
576
|
process.stdout.write(`\x1b]0;phren \xb7 ${projectName}\x07`); // set terminal window title
|
|
596
577
|
// Initial render
|
|
597
|
-
const app = render(_jsx(App, { state: getAppState(), completedMessages: [], streamingText: "", completedToolCalls: [], activeTool: null, thinking: false, thinkStartTime: 0, thinkElapsed: null, steerQueue: [], running: false, showBanner: true, inputHistory: [], verbose: verbose, theme: theme, onSubmit: handleSubmit, onPermissionCycle: handlePermissionCycle, onCancelTurn: handleCancelTurn, onExit: handleExit, agents: undefined, selectedAgentId: undefined, onCancelAgent: handleCancelAgent, onSelectAgent: handleSelectAgent }), { exitOnCtrlC: false
|
|
578
|
+
const app = render(_jsx(App, { state: getAppState(), completedMessages: [], streamingText: "", completedToolCalls: [], activeTool: null, thinking: false, thinkStartTime: 0, thinkElapsed: null, steerQueue: [], running: false, showBanner: true, inputHistory: [], verbose: verbose, theme: theme, onSubmit: handleSubmit, onPermissionCycle: handlePermissionCycle, onCancelTurn: handleCancelTurn, onExit: handleExit, agents: undefined, selectedAgentId: undefined, onCancelAgent: handleCancelAgent, onSelectAgent: handleSelectAgent }), { exitOnCtrlC: false });
|
|
598
579
|
rerender = app.rerender;
|
|
599
580
|
appInstance = app;
|
|
600
|
-
terminalControl.enable(process.stdout);
|
|
601
|
-
enableMouse(process.stdout);
|
|
602
|
-
// Mouse event handling — raw stdin listener catches SGR mouse events that
|
|
603
|
-
// Ink doesn't parse, enabling click-to-focus on agent tabs.
|
|
604
|
-
mouseHandler = (data) => {
|
|
605
|
-
const str = data.toString();
|
|
606
|
-
const evt = parseMouseEvent(str);
|
|
607
|
-
if (!evt || evt.type !== "press" || evt.button !== "left")
|
|
608
|
-
return;
|
|
609
|
-
// Check if click is in the agent tab row (row above the fixed status bar)
|
|
610
|
-
const rows = process.stdout.rows || 24;
|
|
611
|
-
const tabRow = rows - 1;
|
|
612
|
-
if (evt.y === tabRow && agentTabs.length > 0) {
|
|
613
|
-
// Determine which tab was clicked based on x position.
|
|
614
|
-
// Tab layout mirrors what InputArea renders: "phren● name● ..."
|
|
615
|
-
let xPos = 2; // initial padding offset
|
|
616
|
-
// First slot is always the "phren" (main) tab
|
|
617
|
-
const mainTabWidth = "phren●".length + 2;
|
|
618
|
-
if (evt.x >= xPos && evt.x < xPos + mainTabWidth) {
|
|
619
|
-
handleSelectAgent(null);
|
|
620
|
-
return;
|
|
621
|
-
}
|
|
622
|
-
xPos += mainTabWidth;
|
|
623
|
-
for (const tab of agentTabs) {
|
|
624
|
-
const tabWidth = tab.name.length + 3; // "name● "
|
|
625
|
-
if (evt.x >= xPos && evt.x < xPos + tabWidth) {
|
|
626
|
-
handleSelectAgent(tab.id);
|
|
627
|
-
return;
|
|
628
|
-
}
|
|
629
|
-
xPos += tabWidth;
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
};
|
|
633
|
-
if (process.stdin.isTTY) {
|
|
634
|
-
process.stdin.on("data", mouseHandler);
|
|
635
|
-
}
|
|
636
581
|
const done = new Promise((r) => { resolveSession = r; });
|
|
637
582
|
app.waitUntilExit().then(() => {
|
|
638
|
-
disableMouse(process.stdout);
|
|
639
|
-
if (process.stdin.isTTY) {
|
|
640
|
-
process.stdin.off("data", mouseHandler);
|
|
641
|
-
}
|
|
642
|
-
terminalControl.disable(process.stdout);
|
|
643
583
|
if (resolveSession)
|
|
644
584
|
resolveSession(session);
|
|
645
585
|
});
|