@galaxy-stack/blackhole-cli 2.4.0 → 3.0.1
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/README.md +82 -47
- package/dist/application.d.ts.map +1 -1
- package/dist/application.js +13 -2
- package/dist/application.js.map +1 -1
- package/dist/cli-meta.d.ts +8 -0
- package/dist/cli-meta.d.ts.map +1 -1
- package/dist/cli-meta.js +11 -0
- package/dist/cli-meta.js.map +1 -1
- package/dist/cli.js +26 -9
- package/dist/cli.js.map +1 -1
- package/dist/config-command.d.ts +11 -14
- package/dist/config-command.d.ts.map +1 -1
- package/dist/config-command.js +41 -118
- package/dist/config-command.js.map +1 -1
- package/dist/doctor.d.ts +8 -2
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +11 -15
- package/dist/doctor.js.map +1 -1
- package/dist/file-index.d.ts +50 -0
- package/dist/file-index.d.ts.map +1 -1
- package/dist/file-index.js +124 -0
- package/dist/file-index.js.map +1 -1
- package/dist/harness/boot.d.ts +87 -0
- package/dist/harness/boot.d.ts.map +1 -0
- package/dist/harness/boot.js +111 -0
- package/dist/harness/boot.js.map +1 -0
- package/dist/harness/catalogs.d.ts +50 -0
- package/dist/harness/catalogs.d.ts.map +1 -0
- package/dist/harness/catalogs.js +34 -0
- package/dist/harness/catalogs.js.map +1 -0
- package/dist/harness/chat.d.ts +90 -0
- package/dist/harness/chat.d.ts.map +1 -0
- package/dist/harness/chat.js +260 -0
- package/dist/harness/chat.js.map +1 -0
- package/dist/harness/client.d.ts +72 -0
- package/dist/harness/client.d.ts.map +1 -0
- package/dist/harness/client.js +173 -0
- package/dist/harness/client.js.map +1 -0
- package/dist/harness/command.d.ts +22 -0
- package/dist/harness/command.d.ts.map +1 -0
- package/dist/harness/command.js +142 -0
- package/dist/harness/command.js.map +1 -0
- package/dist/harness/composer.d.ts +46 -0
- package/dist/harness/composer.d.ts.map +1 -0
- package/dist/harness/composer.js +127 -0
- package/dist/harness/composer.js.map +1 -0
- package/dist/harness/conversation.d.ts +75 -0
- package/dist/harness/conversation.d.ts.map +1 -0
- package/dist/harness/conversation.js +196 -0
- package/dist/harness/conversation.js.map +1 -0
- package/dist/harness/help.d.ts +56 -0
- package/dist/harness/help.d.ts.map +1 -0
- package/dist/harness/help.js +85 -0
- package/dist/harness/help.js.map +1 -0
- package/dist/harness/history.d.ts +108 -0
- package/dist/harness/history.d.ts.map +1 -0
- package/dist/harness/history.js +268 -0
- package/dist/harness/history.js.map +1 -0
- package/dist/harness/labels.d.ts +164 -0
- package/dist/harness/labels.d.ts.map +1 -0
- package/dist/harness/labels.js +271 -0
- package/dist/harness/labels.js.map +1 -0
- package/dist/harness/locate.d.ts +28 -0
- package/dist/harness/locate.d.ts.map +1 -0
- package/dist/harness/locate.js +73 -0
- package/dist/harness/locate.js.map +1 -0
- package/dist/harness/menus.d.ts +74 -0
- package/dist/harness/menus.d.ts.map +1 -0
- package/dist/harness/menus.js +140 -0
- package/dist/harness/menus.js.map +1 -0
- package/dist/harness/model-name.d.ts +73 -0
- package/dist/harness/model-name.d.ts.map +1 -0
- package/dist/harness/model-name.js +101 -0
- package/dist/harness/model-name.js.map +1 -0
- package/dist/harness/node-runtime.d.ts +64 -0
- package/dist/harness/node-runtime.d.ts.map +1 -0
- package/dist/harness/node-runtime.js +109 -0
- package/dist/harness/node-runtime.js.map +1 -0
- package/dist/harness/parts.d.ts +239 -0
- package/dist/harness/parts.d.ts.map +1 -0
- package/dist/harness/parts.js +266 -0
- package/dist/harness/parts.js.map +1 -0
- package/dist/harness/preset.d.ts +124 -0
- package/dist/harness/preset.d.ts.map +1 -0
- package/dist/harness/preset.js +197 -0
- package/dist/harness/preset.js.map +1 -0
- package/dist/harness/process.d.ts +55 -0
- package/dist/harness/process.d.ts.map +1 -0
- package/dist/harness/process.js +124 -0
- package/dist/harness/process.js.map +1 -0
- package/dist/harness/screen.d.ts +33 -0
- package/dist/harness/screen.d.ts.map +1 -0
- package/dist/harness/screen.js +1070 -0
- package/dist/harness/screen.js.map +1 -0
- package/dist/harness/sessions.d.ts +55 -0
- package/dist/harness/sessions.d.ts.map +1 -0
- package/dist/harness/sessions.js +92 -0
- package/dist/harness/sessions.js.map +1 -0
- package/dist/harness/skills.d.ts +90 -0
- package/dist/harness/skills.d.ts.map +1 -0
- package/dist/harness/skills.js +133 -0
- package/dist/harness/skills.js.map +1 -0
- package/dist/harness/slash-palette.d.ts +32 -0
- package/dist/harness/slash-palette.d.ts.map +1 -0
- package/dist/harness/slash-palette.js +48 -0
- package/dist/harness/slash-palette.js.map +1 -0
- package/dist/harness/slash.d.ts +113 -0
- package/dist/harness/slash.d.ts.map +1 -0
- package/dist/harness/slash.js +187 -0
- package/dist/harness/slash.js.map +1 -0
- package/dist/harness/trajectory.d.ts +74 -0
- package/dist/harness/trajectory.d.ts.map +1 -0
- package/dist/harness/trajectory.js +270 -0
- package/dist/harness/trajectory.js.map +1 -0
- package/dist/harness/tui.d.ts +28 -0
- package/dist/harness/tui.d.ts.map +1 -0
- package/dist/harness/tui.js +143 -0
- package/dist/harness/tui.js.map +1 -0
- package/dist/manual-config.d.ts +23 -10
- package/dist/manual-config.d.ts.map +1 -1
- package/dist/manual-config.js +45 -37
- package/dist/manual-config.js.map +1 -1
- package/dist/migrate.d.ts +32 -0
- package/dist/migrate.d.ts.map +1 -0
- package/dist/migrate.js +155 -0
- package/dist/migrate.js.map +1 -0
- package/dist/options.d.ts +5 -1
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +23 -4
- package/dist/options.js.map +1 -1
- package/dist/setup.d.ts +14 -10
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +25 -92
- package/dist/setup.js.map +1 -1
- package/dist/timeline.d.ts.map +1 -1
- package/dist/timeline.js +11 -0
- package/dist/timeline.js.map +1 -1
- package/dist/web/command.d.ts +5 -1
- package/dist/web/command.d.ts.map +1 -1
- package/dist/web/command.js +34 -6
- package/dist/web/command.js.map +1 -1
- package/dist/web/credentials.d.ts +7 -5
- package/dist/web/credentials.d.ts.map +1 -1
- package/dist/web/credentials.js +13 -48
- package/dist/web/credentials.js.map +1 -1
- package/dist/web/doctor.d.ts +1 -1
- package/dist/web/doctor.d.ts.map +1 -1
- package/dist/web/doctor.js +49 -61
- package/dist/web/doctor.js.map +1 -1
- package/dist/web/options.d.ts +26 -2
- package/dist/web/options.d.ts.map +1 -1
- package/dist/web/options.js +54 -18
- package/dist/web/options.js.map +1 -1
- package/dist/web/paths.d.ts +1 -1
- package/dist/web/paths.d.ts.map +1 -1
- package/dist/web/paths.js +2 -2
- package/dist/web/paths.js.map +1 -1
- package/dist/web/web.d.ts +56 -16
- package/dist/web/web.d.ts.map +1 -1
- package/dist/web/web.js +184 -168
- package/dist/web/web.js.map +1 -1
- package/package.json +4 -3
- package/web/brand/lib/client.js +4 -4
- package/web/patches/gbh-ui.patch.yml +6 -24
|
@@ -0,0 +1,1070 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* author Bùi Trọng Hiếu
|
|
4
|
+
* email kevinbui210191@gmail.com
|
|
5
|
+
* create date 15/10/2026
|
|
6
|
+
* modify date 11/11/2026
|
|
7
|
+
* desc Doc row.effort cua session/list o ca ba cho set effort, de chip va panel hien dung muc suy luan
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* The desktop-shaped `blackhole chat` screen.
|
|
11
|
+
*
|
|
12
|
+
* Layout, top to bottom: a body row (workspace/session sidebar, then the main
|
|
13
|
+
* column with its "Hội thoại" / "Luồng chạy" tabs), an optional dropdown menu,
|
|
14
|
+
* the composer, and one status row. State is the conversation reducer plus the
|
|
15
|
+
* screen's own bookkeeping; the harness engine stays behind `HarnessChat` and
|
|
16
|
+
* `HarnessClient`.
|
|
17
|
+
*/
|
|
18
|
+
import { useCallback, useEffect, useMemo, useReducer, useRef, useState } from "react";
|
|
19
|
+
import { homedir } from "node:os";
|
|
20
|
+
import { Box, Text, useApp, useInput, useStdout } from "ink";
|
|
21
|
+
import { HarnessChat } from "./chat.js";
|
|
22
|
+
import { chatReducer, emptyChatState } from "./conversation.js";
|
|
23
|
+
import { loadHistory } from "./history.js";
|
|
24
|
+
import { accessLabel, accessPresets, formatTokens, sessionTitle, UI, workspaceName } from "./labels.js";
|
|
25
|
+
import { HELP_KEY_WIDTH, helpLines, LOCAL_COMMANDS } from "./help.js";
|
|
26
|
+
import { loadTrajectory } from "./trajectory.js";
|
|
27
|
+
import { readPackageVersion } from "../cli-meta.js";
|
|
28
|
+
import { groupSessions, listSessions } from "./sessions.js";
|
|
29
|
+
import { Activity, ConversationHeader, EmptyConversation, HelpPanel, InfoPanel, ListPicker, MenuPanel, Sidebar, SlashPanel, StatusBar, Trajectory } from "./parts.js";
|
|
30
|
+
import { ChatComposer, COMPOSER_CHIPS } from "./composer.js";
|
|
31
|
+
import { defaultPresetId, loadPresets, presetFailure, presetLabel, presetName, presetOptions, selectPreset } from "./preset.js";
|
|
32
|
+
import { EXTRA_COMMANDS, moveSlash, slashLine } from "./slash.js";
|
|
33
|
+
import { useSlashPalette } from "./slash-palette.js";
|
|
34
|
+
import { flattenModels } from "./catalogs.js";
|
|
35
|
+
import { DEFAULT_EFFORT_VALUE, effortLabel, effortOptions, menuCurrent, menuRows, menuTitle, plusOptions } from "./menus.js";
|
|
36
|
+
import { modelNamesOf, modelRouteName } from "./model-name.js";
|
|
37
|
+
import { fileQuery, filterFiles, insertFilePath, listWorkspaceDirs, workspaceFileIndex } from "../file-index.js";
|
|
38
|
+
import { terminalText, transcriptRows } from "../timeline.js";
|
|
39
|
+
import { join } from "node:path";
|
|
40
|
+
function errorMessage(error) {
|
|
41
|
+
return error instanceof Error ? error.message : String(error);
|
|
42
|
+
}
|
|
43
|
+
/** Terminal size, reserving the trailing row Ink leaves for its last newline. */
|
|
44
|
+
function useSize() {
|
|
45
|
+
const { stdout } = useStdout();
|
|
46
|
+
const read = () => ({
|
|
47
|
+
columns: Math.max(24, stdout.columns || 80),
|
|
48
|
+
rows: Math.max(10, stdout.rows || 24) - (stdout.isTTY ? 1 : 0),
|
|
49
|
+
});
|
|
50
|
+
const [size, setSize] = useState(read);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
const resize = () => setSize(read());
|
|
53
|
+
stdout.on("resize", resize);
|
|
54
|
+
return () => { stdout.off("resize", resize); };
|
|
55
|
+
}, [stdout]);
|
|
56
|
+
return size;
|
|
57
|
+
}
|
|
58
|
+
const TONE = { plain: undefined, user: "cyan", assistant: "white", thinking: "magenta", running: "yellow", success: "green", error: "red", muted: "gray", accent: "cyan" };
|
|
59
|
+
/** One transcript row, already wrapped and styled by `transcriptRows`. */
|
|
60
|
+
function Row(props) {
|
|
61
|
+
const spans = props.row.spans;
|
|
62
|
+
if (spans === undefined) {
|
|
63
|
+
const color = TONE[props.row.tone];
|
|
64
|
+
return _jsx(Text, { ...(color === undefined ? {} : { color }), bold: props.row.tone === "user", wrap: "truncate-end", children: props.row.text || " " });
|
|
65
|
+
}
|
|
66
|
+
return _jsx(Text, { wrap: "truncate-end", children: spans.map((span, index) => {
|
|
67
|
+
const color = span.tone === undefined ? undefined : TONE[span.tone];
|
|
68
|
+
return _jsx(Text, { ...(color === undefined ? {} : { color }), ...(span.bold === true ? { bold: true } : {}), ...(span.italic === true ? { italic: true } : {}), ...(span.dim === true ? { dimColor: true } : {}), children: span.text }, index);
|
|
69
|
+
}) });
|
|
70
|
+
}
|
|
71
|
+
/** The full screen: sidebar, conversation, dropdown, composer and status. */
|
|
72
|
+
export function HarnessScreen(props) {
|
|
73
|
+
const { exit } = useApp();
|
|
74
|
+
const { columns, rows } = useSize();
|
|
75
|
+
const home = useMemo(() => homedir(), []);
|
|
76
|
+
const [models, setModels] = useState([]);
|
|
77
|
+
/** Display names for the catalog's routes, so no line ever prints a wire id. */
|
|
78
|
+
const modelNames = useMemo(() => modelNamesOf(models), [models]);
|
|
79
|
+
const [state, dispatch] = useReducer((current, action) => chatReducer(current, action, modelNames), undefined, emptyChatState);
|
|
80
|
+
const stateRef = useRef(state);
|
|
81
|
+
useEffect(() => { stateRef.current = state; }, [state]);
|
|
82
|
+
const chatRef = useRef(props.chat);
|
|
83
|
+
const abortRef = useRef(undefined);
|
|
84
|
+
const [active, setActive] = useState({ key: "new", cwd: props.cwd });
|
|
85
|
+
const [selectedKey, setSelectedKey] = useState("new");
|
|
86
|
+
const [rowsList, setRowsList] = useState([]);
|
|
87
|
+
const [connection, setConnection] = useState("connected");
|
|
88
|
+
const [historyLoading, setHistoryLoading] = useState(false);
|
|
89
|
+
const [composerText, setComposerText] = useState("");
|
|
90
|
+
const [focus, setFocus] = useState("composer");
|
|
91
|
+
const [sidebarHidden, setSidebarHidden] = useState(false);
|
|
92
|
+
const [tab, setTab] = useState("chat");
|
|
93
|
+
const [overlay, setOverlay] = useState();
|
|
94
|
+
const [menu, setMenu] = useState();
|
|
95
|
+
const [chipIndex, setChipIndex] = useState(0);
|
|
96
|
+
const [accessOptions, setAccessOptions] = useState(accessPresets(undefined));
|
|
97
|
+
const [currentAccess, setCurrentAccess] = useState();
|
|
98
|
+
/** The agent modes this harness runs; the shipped four until the roster answers. */
|
|
99
|
+
const [presets, setPresets] = useState(() => presetOptions(undefined));
|
|
100
|
+
/** The host's own roster, so the default mode is the one the host names. */
|
|
101
|
+
const rosterRef = useRef([]);
|
|
102
|
+
const [modelLabel, setModelLabel] = useState(props.model ?? "Auto");
|
|
103
|
+
const [modelRoute, setModelRoute] = useState();
|
|
104
|
+
const [effortId, setEffortId] = useState();
|
|
105
|
+
const [files, setFiles] = useState([]);
|
|
106
|
+
const [fileIndex, setFileIndex] = useState(0);
|
|
107
|
+
const [filesDismissed, setFilesDismissed] = useState(false);
|
|
108
|
+
const [workspacePicker, setWorkspacePicker] = useState();
|
|
109
|
+
const [showThinking, setShowThinking] = useState(false);
|
|
110
|
+
const [showTools, setShowTools] = useState(false);
|
|
111
|
+
const [notice, setNotice] = useState();
|
|
112
|
+
const [scroll, setScroll] = useState(0);
|
|
113
|
+
const [clock, setClock] = useState(Date.now());
|
|
114
|
+
const [now, setNow] = useState(Date.now());
|
|
115
|
+
// "Luồng chạy" is the harness ledger, so it is read from the host — not derived from our turns.
|
|
116
|
+
const [trajectoryRows, setTrajectoryRows] = useState([]);
|
|
117
|
+
const [trajectoryLoading, setTrajectoryLoading] = useState(false);
|
|
118
|
+
const [trajectoryError, setTrajectoryError] = useState();
|
|
119
|
+
const [trajectoryMore, setTrajectoryMore] = useState(false);
|
|
120
|
+
const [trajectoryScroll, setTrajectoryScroll] = useState(0);
|
|
121
|
+
const [helpScroll, setHelpScroll] = useState(0);
|
|
122
|
+
const [settled, setSettled] = useState(0);
|
|
123
|
+
/** The version this terminal runs, read once from the package.json beside the entry point. */
|
|
124
|
+
const version = useMemo(() => readPackageVersion(), []);
|
|
125
|
+
const defaultAccess = useRef(undefined);
|
|
126
|
+
const currentModel = models.find(model => model.provider === modelRoute?.provider && model.model === modelRoute?.model);
|
|
127
|
+
/** The agent mode in force: the one the session records, else the host's own default. */
|
|
128
|
+
const presetNow = active.preset ?? defaultPresetId(rosterRef.current);
|
|
129
|
+
/** The effort chip's word: the host's own name for the id, else ours, else "Mặc định". */
|
|
130
|
+
const effortText = effortLabel(effortId, currentModel?.efforts?.find(entry => entry.id === effortId)?.name);
|
|
131
|
+
/** The route as a person reads it ("Galaxy Blackhole/Auto"); the wire pair never prints. */
|
|
132
|
+
const routeText = modelRouteName(modelRoute?.provider, modelRoute?.model, modelNames) || modelLabel;
|
|
133
|
+
/** The trailing @token being typed, and the rows that answer it. */
|
|
134
|
+
const fileToken = useMemo(() => fileQuery(composerText), [composerText]);
|
|
135
|
+
const fileMatches = useMemo(() => (fileToken === undefined ? [] : filterFiles(files, fileToken.query, 200)), [fileToken, files]);
|
|
136
|
+
const fileQueryText = fileToken?.query;
|
|
137
|
+
/** Whether the @ picker is on screen: a trailing @token, files known, and nothing above it. */
|
|
138
|
+
const pickerOpen = fileToken !== undefined
|
|
139
|
+
&& files.length > 0
|
|
140
|
+
&& !filesDismissed
|
|
141
|
+
&& menu === undefined
|
|
142
|
+
&& workspacePicker === undefined
|
|
143
|
+
&& overlay === undefined
|
|
144
|
+
&& tab === "chat"
|
|
145
|
+
&& focus === "composer"
|
|
146
|
+
&& !historyLoading;
|
|
147
|
+
/** The "/" palette: the rows, the cursor and the session's own skill catalogue. */
|
|
148
|
+
const palette = useSlashPalette(props.client, { text: composerText, ...(active.sessionId === undefined ? {} : { sessionId: active.sessionId }), cwd: active.cwd });
|
|
149
|
+
const { skills, rows: slashRows, index: slashIndex } = palette;
|
|
150
|
+
/** Whether the popup is on screen: a bare "/word", not dismissed, and nothing drawn above it. */
|
|
151
|
+
const slashOpen = palette.state.active
|
|
152
|
+
&& !palette.dismissed
|
|
153
|
+
&& !pickerOpen
|
|
154
|
+
&& menu === undefined
|
|
155
|
+
&& workspacePicker === undefined
|
|
156
|
+
&& overlay === undefined
|
|
157
|
+
&& tab === "chat"
|
|
158
|
+
&& focus === "composer"
|
|
159
|
+
&& !historyLoading;
|
|
160
|
+
/** Refresh the sidebar book; every failure becomes the status row's notice. */
|
|
161
|
+
const loadSessionsSafe = useCallback(async () => {
|
|
162
|
+
try {
|
|
163
|
+
const list = await listSessions(props.client);
|
|
164
|
+
setRowsList(list);
|
|
165
|
+
setConnection("connected");
|
|
166
|
+
return list;
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
setConnection("disconnected");
|
|
170
|
+
setNotice(UI.sessionsFailed + ": " + errorMessage(error));
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
173
|
+
}, [props.client]);
|
|
174
|
+
useEffect(() => {
|
|
175
|
+
void loadSessionsSafe();
|
|
176
|
+
const timer = setInterval(() => { if (!stateRef.current.running)
|
|
177
|
+
void loadSessionsSafe(); }, 30_000);
|
|
178
|
+
return () => clearInterval(timer);
|
|
179
|
+
}, [loadSessionsSafe]);
|
|
180
|
+
// The mode picker's book: the roster the harness publishes, filled in with the shipped copy.
|
|
181
|
+
useEffect(() => {
|
|
182
|
+
const controller = new AbortController();
|
|
183
|
+
void loadPresets(props.client, controller.signal).then(rows => {
|
|
184
|
+
if (controller.signal.aborted)
|
|
185
|
+
return;
|
|
186
|
+
rosterRef.current = rows;
|
|
187
|
+
setPresets(presetOptions(rows));
|
|
188
|
+
}, () => undefined);
|
|
189
|
+
return () => controller.abort();
|
|
190
|
+
}, [props.client]);
|
|
191
|
+
useEffect(() => {
|
|
192
|
+
const controller = new AbortController();
|
|
193
|
+
void (async () => {
|
|
194
|
+
try {
|
|
195
|
+
const catalog = await props.client.call("permissionPresets.catalog", {}, controller.signal);
|
|
196
|
+
const values = (catalog.options ?? []).map(option => option.value).filter((value) => typeof value === "string");
|
|
197
|
+
setAccessOptions(accessPresets(values));
|
|
198
|
+
if (catalog.defaultPreset !== undefined) {
|
|
199
|
+
defaultAccess.current = catalog.defaultPreset;
|
|
200
|
+
setCurrentAccess(current => current ?? catalog.defaultPreset);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
catch { /* the three named presets stay selectable; /permission still applies them */ }
|
|
204
|
+
try {
|
|
205
|
+
const catalog = await props.client.call("session.modelCatalog", {}, controller.signal);
|
|
206
|
+
const options = flattenModels(catalog);
|
|
207
|
+
setModels(options);
|
|
208
|
+
const selected = catalog.default === undefined ? undefined : options.find(option => option.provider === catalog.default?.provider && option.model === catalog.default?.model);
|
|
209
|
+
if (selected !== undefined) {
|
|
210
|
+
setModelLabel(selected.name);
|
|
211
|
+
setModelRoute({ provider: selected.provider, model: selected.model });
|
|
212
|
+
setEffortId(selected.effort);
|
|
213
|
+
}
|
|
214
|
+
else if (catalog.default?.model !== undefined && props.model === undefined) {
|
|
215
|
+
setModelLabel(catalog.default.model);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
setNotice(UI.catalogFailed);
|
|
220
|
+
}
|
|
221
|
+
})();
|
|
222
|
+
return () => controller.abort();
|
|
223
|
+
}, [props.client, props.model]);
|
|
224
|
+
// A timer only while a turn runs: the status row's clock is live, not wall-clock noise.
|
|
225
|
+
useEffect(() => {
|
|
226
|
+
if (!state.running)
|
|
227
|
+
return;
|
|
228
|
+
const timer = setInterval(() => setClock(Date.now()), 500);
|
|
229
|
+
return () => clearInterval(timer);
|
|
230
|
+
}, [state.running]);
|
|
231
|
+
useEffect(() => {
|
|
232
|
+
const timer = setInterval(() => setNow(Date.now()), 60_000);
|
|
233
|
+
return () => clearInterval(timer);
|
|
234
|
+
}, []);
|
|
235
|
+
useEffect(() => {
|
|
236
|
+
if (notice === undefined)
|
|
237
|
+
return;
|
|
238
|
+
const timer = setTimeout(() => setNotice(undefined), 8_000);
|
|
239
|
+
return () => clearTimeout(timer);
|
|
240
|
+
}, [notice]);
|
|
241
|
+
useEffect(() => () => { abortRef.current?.abort(); }, []);
|
|
242
|
+
// The @ picker reads the workspace from disk once per cwd (2000 files, ignored folders
|
|
243
|
+
// dropped), and every keystroke filters that list in memory.
|
|
244
|
+
useEffect(() => {
|
|
245
|
+
let live = true;
|
|
246
|
+
void workspaceFileIndex(active.cwd, { limit: 2000 }).files().then(list => { if (live)
|
|
247
|
+
setFiles(list); }, () => { if (live)
|
|
248
|
+
setFiles([]); });
|
|
249
|
+
return () => { live = false; };
|
|
250
|
+
}, [active.cwd]);
|
|
251
|
+
useEffect(() => { setFileIndex(0); setFilesDismissed(false); }, [fileQueryText]);
|
|
252
|
+
// The ledger is read when the tab opens, when the conversation changes, and once after every
|
|
253
|
+
// settled turn. The read is a page, not a subscription: loadTrajectory closes its stream.
|
|
254
|
+
useEffect(() => {
|
|
255
|
+
if (tab !== "trajectory")
|
|
256
|
+
return;
|
|
257
|
+
if (active.sessionId === undefined) {
|
|
258
|
+
setTrajectoryRows([]);
|
|
259
|
+
setTrajectoryMore(false);
|
|
260
|
+
setTrajectoryError(undefined);
|
|
261
|
+
setTrajectoryLoading(false);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const controller = new AbortController();
|
|
265
|
+
setTrajectoryScroll(0);
|
|
266
|
+
setTrajectoryLoading(true);
|
|
267
|
+
void loadTrajectory(props.client, active.sessionId, controller.signal, { names: modelNames }).then(page => {
|
|
268
|
+
if (controller.signal.aborted)
|
|
269
|
+
return;
|
|
270
|
+
setTrajectoryRows(page.rows);
|
|
271
|
+
setTrajectoryMore(page.hasMore);
|
|
272
|
+
setTrajectoryError(undefined);
|
|
273
|
+
setTrajectoryLoading(false);
|
|
274
|
+
}, (error) => {
|
|
275
|
+
if (controller.signal.aborted)
|
|
276
|
+
return;
|
|
277
|
+
setTrajectoryError(errorMessage(error));
|
|
278
|
+
setTrajectoryLoading(false);
|
|
279
|
+
});
|
|
280
|
+
return () => controller.abort();
|
|
281
|
+
// A catalog that lands after the rows were folded re-reads them, so the names are the host's.
|
|
282
|
+
}, [tab, active.sessionId, props.client, settled, modelNames]);
|
|
283
|
+
// Keep the active row's title, permission and preset in step with the host's book.
|
|
284
|
+
useEffect(() => {
|
|
285
|
+
if (active.sessionId === undefined)
|
|
286
|
+
return;
|
|
287
|
+
const row = rowsList.find(item => item.sessionId === active.sessionId);
|
|
288
|
+
if (row === undefined)
|
|
289
|
+
return;
|
|
290
|
+
if (row.permission !== undefined)
|
|
291
|
+
setCurrentAccess(row.permission);
|
|
292
|
+
const option = row.model === undefined ? undefined : models.find(model => model.model === row.model);
|
|
293
|
+
if (row.model !== undefined) {
|
|
294
|
+
setModelLabel(option?.name ?? row.model);
|
|
295
|
+
if (row.provider !== undefined)
|
|
296
|
+
setModelRoute({ provider: row.provider, model: row.model });
|
|
297
|
+
}
|
|
298
|
+
// The ledger's word wins, and its silence is an answer too: a session the host records as running
|
|
299
|
+
// "max" is not the model's default, and a session that records none must not inherit the last one.
|
|
300
|
+
setEffortId(row.effort ?? option?.effort);
|
|
301
|
+
setActive(previous => previous.sessionId === row.sessionId && (previous.title !== row.title || previous.preset !== row.preset)
|
|
302
|
+
? { ...previous, title: row.title, ...(row.preset === undefined ? {} : { preset: row.preset }) }
|
|
303
|
+
: previous);
|
|
304
|
+
}, [rowsList, active.sessionId, models]);
|
|
305
|
+
const sidebarWidth = sidebarHidden || columns < 76 ? 0 : columns >= 100 ? 32 : columns >= 84 ? 28 : 24;
|
|
306
|
+
const composerHeight = rows >= 16 ? 4 : 1;
|
|
307
|
+
const statusHeight = 1;
|
|
308
|
+
const effortRowCount = effortOptions(currentModel).length;
|
|
309
|
+
const menuHeight = menu === undefined
|
|
310
|
+
? 0
|
|
311
|
+
: menu.kind === "access"
|
|
312
|
+
? Math.min(accessOptions.length + 4, 12)
|
|
313
|
+
: menu.kind === "plus"
|
|
314
|
+
? 6
|
|
315
|
+
: menu.kind === "mode"
|
|
316
|
+
? Math.min(presets.length + 4, 12)
|
|
317
|
+
: menu.kind === "effort"
|
|
318
|
+
? Math.min(effortRowCount + 4, 12)
|
|
319
|
+
: Math.min(Math.max(2, models.length) + 4, 14);
|
|
320
|
+
const pickerHeight = pickerOpen || workspacePicker !== undefined ? Math.min(9, Math.max(4, Math.floor(rows / 3))) : 0;
|
|
321
|
+
/** The "/" palette: every row when the terminal has room, a window when it does not. */
|
|
322
|
+
const slashHeight = slashOpen ? Math.max(4, Math.min(slashRows.length + 4, Math.max(4, rows - composerHeight - statusHeight - 8))) : 0;
|
|
323
|
+
const bodyHeight = Math.max(5, rows - composerHeight - statusHeight - menuHeight - pickerHeight - slashHeight);
|
|
324
|
+
const perWorkspace = Math.max(2, Math.min(6, bodyHeight - 15));
|
|
325
|
+
const maxGroups = bodyHeight >= 34 ? 2 : 1;
|
|
326
|
+
const mainWidth = Math.max(20, columns - sidebarWidth);
|
|
327
|
+
const noticeHeight = notice === undefined ? 0 : 1;
|
|
328
|
+
const contentHeight = Math.max(1, bodyHeight - 2 - noticeHeight - 1);
|
|
329
|
+
const transcriptHeight = contentHeight;
|
|
330
|
+
/** Rows the ledger can draw, and how far it can scroll from the newest event. */
|
|
331
|
+
const trajectoryVisible = Math.max(1, contentHeight - 4);
|
|
332
|
+
const maxTrajectoryTop = Math.max(0, trajectoryRows.length - trajectoryVisible);
|
|
333
|
+
/** The help table is a document: it starts at its first line and pages down. */
|
|
334
|
+
const helpTable = helpLines();
|
|
335
|
+
const maxHelpTop = Math.max(0, helpTable.length - Math.max(1, contentHeight - 2));
|
|
336
|
+
const textWidth = Math.max(2, columns - 8);
|
|
337
|
+
const composerRow = bodyHeight + menuHeight + pickerHeight + slashHeight + 1;
|
|
338
|
+
const groups = useMemo(() => groupSessions(rowsList, active.cwd, home, perWorkspace), [rowsList, active.cwd, home, perWorkspace]);
|
|
339
|
+
const items = useMemo(() => {
|
|
340
|
+
const list = [{ kind: "new" }, { kind: "section", label: UI.workspace }];
|
|
341
|
+
for (const group of groups.slice(0, maxGroups)) {
|
|
342
|
+
list.push({ kind: "workspace", cwd: group.cwd, label: group.label });
|
|
343
|
+
if (group.sessions.length === 0)
|
|
344
|
+
list.push({ kind: "empty" });
|
|
345
|
+
for (const row of group.sessions)
|
|
346
|
+
list.push({ kind: "session", row });
|
|
347
|
+
if (group.total > group.sessions.length)
|
|
348
|
+
list.push({ kind: "more", count: group.total - group.sessions.length });
|
|
349
|
+
}
|
|
350
|
+
return list;
|
|
351
|
+
}, [groups, maxGroups]);
|
|
352
|
+
const selectableKeys = useMemo(() => items.flatMap(item => (item.kind === "new" ? [item.kind] : item.kind === "session" ? [item.row.sessionId] : [])), [items]);
|
|
353
|
+
const moveSelection = useCallback((delta) => {
|
|
354
|
+
const index = Math.max(0, selectableKeys.indexOf(selectedKey));
|
|
355
|
+
const next = Math.max(0, Math.min(selectableKeys.length - 1, index + delta));
|
|
356
|
+
const key = selectableKeys[next];
|
|
357
|
+
if (key !== undefined)
|
|
358
|
+
setSelectedKey(key);
|
|
359
|
+
}, [selectableKeys, selectedKey]);
|
|
360
|
+
/** Run one harness turn and fold its facts into the screen. */
|
|
361
|
+
const send = useCallback((text) => {
|
|
362
|
+
if (stateRef.current.running) {
|
|
363
|
+
setNotice("Đang chạy — Esc để dừng lượt hiện tại rồi gửi tiếp.");
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
setComposerText("");
|
|
367
|
+
setScroll(0);
|
|
368
|
+
dispatch({ type: "prompt", text, at: Date.now() });
|
|
369
|
+
const controller = new AbortController();
|
|
370
|
+
abortRef.current = controller;
|
|
371
|
+
const chat = chatRef.current;
|
|
372
|
+
void chat.send(text, chunk => dispatch({ type: "chunk", chunk }), controller.signal)
|
|
373
|
+
.then(async (result) => {
|
|
374
|
+
dispatch({ type: "settled", result });
|
|
375
|
+
// One ledger refresh per settled turn, so the tab keeps up without a live subscription.
|
|
376
|
+
setSettled(value => value + 1);
|
|
377
|
+
setActive(previous => previous.sessionId === undefined ? { ...previous, sessionId: result.sessionId, key: result.sessionId } : previous);
|
|
378
|
+
setSelectedKey(key => (key === "new" ? result.sessionId : key));
|
|
379
|
+
const list = await loadSessionsSafe();
|
|
380
|
+
const row = list.find(item => item.sessionId === result.sessionId);
|
|
381
|
+
if (row === undefined)
|
|
382
|
+
return;
|
|
383
|
+
dispatch({ type: "stats", steps: row.steps, ...(row.tokens === undefined ? {} : { tokens: row.tokens }) });
|
|
384
|
+
if (row.permission !== undefined)
|
|
385
|
+
setCurrentAccess(row.permission);
|
|
386
|
+
if (row.model !== undefined) {
|
|
387
|
+
const option = models.find(model => model.model === row.model);
|
|
388
|
+
setModelLabel(option?.name ?? row.model);
|
|
389
|
+
if (row.provider !== undefined)
|
|
390
|
+
setModelRoute({ provider: row.provider, model: row.model });
|
|
391
|
+
}
|
|
392
|
+
})
|
|
393
|
+
.catch(error => dispatch({ type: "notice", text: errorMessage(error) }))
|
|
394
|
+
.finally(() => { abortRef.current = undefined; });
|
|
395
|
+
}, [loadSessionsSafe, models]);
|
|
396
|
+
/** Stop the running turn; the engine cancels it on the host as well. */
|
|
397
|
+
const cancel = useCallback(() => {
|
|
398
|
+
if (!stateRef.current.running)
|
|
399
|
+
return;
|
|
400
|
+
setNotice("Đã yêu cầu dừng lượt.");
|
|
401
|
+
abortRef.current?.abort();
|
|
402
|
+
}, []);
|
|
403
|
+
/** Apply one access preset to the current session through the host's /permission command. */
|
|
404
|
+
const applyAccess = useCallback(async (value) => {
|
|
405
|
+
const label = accessOptions.find(option => option.value === value)?.label ?? accessLabel(value);
|
|
406
|
+
try {
|
|
407
|
+
const sessionId = await chatRef.current.ensureSession();
|
|
408
|
+
const answer = await props.client.call("commands.execute", { agentId: sessionId, line: "/permission " + value, submittedAttachments: [] });
|
|
409
|
+
if (answer.result?.kind !== "success")
|
|
410
|
+
throw new Error(answer.result?.text ?? "harness từ chối lệnh");
|
|
411
|
+
setCurrentAccess(value);
|
|
412
|
+
setActive(previous => ({ ...previous, sessionId, ...(previous.sessionId === undefined ? { key: sessionId } : {}) }));
|
|
413
|
+
setSelectedKey(key => (key === "new" ? sessionId : key));
|
|
414
|
+
setNotice(UI.permissionApplied + ": " + label);
|
|
415
|
+
setConnection("connected");
|
|
416
|
+
await loadSessionsSafe();
|
|
417
|
+
}
|
|
418
|
+
catch (error) {
|
|
419
|
+
setNotice(UI.accessFailed + ": " + errorMessage(error));
|
|
420
|
+
}
|
|
421
|
+
}, [accessOptions, loadSessionsSafe, props.client]);
|
|
422
|
+
/** Install one model selection for the current session. */
|
|
423
|
+
const applyModel = useCallback(async (option) => {
|
|
424
|
+
try {
|
|
425
|
+
const sessionId = await chatRef.current.ensureSession();
|
|
426
|
+
const answer = await props.client.call("session.selectModel", {
|
|
427
|
+
request: {
|
|
428
|
+
sessionId,
|
|
429
|
+
provider: option.provider,
|
|
430
|
+
model: option.model,
|
|
431
|
+
...(option.effort === undefined ? {} : { reasoningEffort: option.effort }),
|
|
432
|
+
},
|
|
433
|
+
});
|
|
434
|
+
setModelLabel(answer.selected?.model === undefined ? option.name : (models.find(model => model.model === answer.selected?.model)?.name ?? option.name));
|
|
435
|
+
setModelRoute({ provider: option.provider, model: option.model });
|
|
436
|
+
setActive(previous => ({ ...previous, sessionId, ...(previous.sessionId === undefined ? { key: sessionId } : {}) }));
|
|
437
|
+
setSelectedKey(key => (key === "new" ? sessionId : key));
|
|
438
|
+
setNotice(UI.modelApplied + ": " + option.name);
|
|
439
|
+
setConnection("connected");
|
|
440
|
+
const list = await loadSessionsSafe();
|
|
441
|
+
const row = list.find(item => item.sessionId === sessionId);
|
|
442
|
+
setEffortId(row?.effort ?? option.effort);
|
|
443
|
+
}
|
|
444
|
+
catch (error) {
|
|
445
|
+
setNotice(UI.modelFailed + ": " + errorMessage(error));
|
|
446
|
+
}
|
|
447
|
+
}, [loadSessionsSafe, models, props.client]);
|
|
448
|
+
/** Open a remembered conversation: read its page first, then point the driver at it. */
|
|
449
|
+
const openSession = useCallback(async (row) => {
|
|
450
|
+
if (stateRef.current.running) {
|
|
451
|
+
setNotice("Đang chạy — Esc để dừng trước khi mở phiên khác.");
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
setHistoryLoading(true);
|
|
455
|
+
setNotice(undefined);
|
|
456
|
+
const timeout = AbortSignal.timeout(20_000);
|
|
457
|
+
try {
|
|
458
|
+
const history = await loadHistory(props.client, row.sessionId, timeout);
|
|
459
|
+
chatRef.current = new HarnessChat(props.client, { cwd: row.cwd, sessionId: row.sessionId, ...(row.preset === undefined ? {} : { preset: row.preset }) });
|
|
460
|
+
dispatch({ type: "reset", messages: history.messages, steps: row.steps, ...(row.tokens > 0 ? { tokens: row.tokens } : {}) });
|
|
461
|
+
setActive({ key: row.sessionId, cwd: row.cwd, sessionId: row.sessionId, title: row.title, ...(row.preset === undefined ? {} : { preset: row.preset }) });
|
|
462
|
+
setSelectedKey(row.sessionId);
|
|
463
|
+
if (row.permission !== undefined)
|
|
464
|
+
setCurrentAccess(row.permission);
|
|
465
|
+
const option = row.model === undefined ? undefined : models.find(model => model.model === row.model);
|
|
466
|
+
if (row.model !== undefined) {
|
|
467
|
+
setModelLabel(option?.name ?? row.model);
|
|
468
|
+
if (row.provider !== undefined)
|
|
469
|
+
setModelRoute({ provider: row.provider, model: row.model });
|
|
470
|
+
}
|
|
471
|
+
// A resumed session shows what it runs: the row's effort, else the model's catalog default.
|
|
472
|
+
setEffortId(row.effort ?? option?.effort);
|
|
473
|
+
setScroll(0);
|
|
474
|
+
setComposerText("");
|
|
475
|
+
setFocus("composer");
|
|
476
|
+
setConnection("connected");
|
|
477
|
+
setNotice("Đã mở phiên · " + row.title);
|
|
478
|
+
}
|
|
479
|
+
catch (error) {
|
|
480
|
+
setConnection("disconnected");
|
|
481
|
+
setNotice(UI.historyFailed + ": " + errorMessage(error));
|
|
482
|
+
}
|
|
483
|
+
finally {
|
|
484
|
+
setHistoryLoading(false);
|
|
485
|
+
}
|
|
486
|
+
}, [models, props.client]);
|
|
487
|
+
/** Start a draft in the active workspace, or in one the workspace chooser named. */
|
|
488
|
+
const startNew = useCallback((targetCwd) => {
|
|
489
|
+
if (stateRef.current.running) {
|
|
490
|
+
setNotice("Đang chạy — Esc để dừng trước khi tạo phiên mới.");
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
const cwd = targetCwd ?? active.cwd;
|
|
494
|
+
// The mode the composer shows travels WITH the creation: a session born on the host's
|
|
495
|
+
// default and re-pointed afterwards is a mode the user never really chose.
|
|
496
|
+
const preset = active.preset;
|
|
497
|
+
chatRef.current = new HarnessChat(props.client, { cwd, ...(preset === undefined ? {} : { preset }) });
|
|
498
|
+
dispatch({ type: "reset", messages: [], steps: 0 });
|
|
499
|
+
setActive({ key: "new", cwd, ...(preset === undefined ? {} : { preset }) });
|
|
500
|
+
setSelectedKey("new");
|
|
501
|
+
setScroll(0);
|
|
502
|
+
setComposerText("");
|
|
503
|
+
setHistoryLoading(false);
|
|
504
|
+
setFocus("composer");
|
|
505
|
+
setNotice(undefined);
|
|
506
|
+
if (defaultAccess.current !== undefined)
|
|
507
|
+
setCurrentAccess(defaultAccess.current);
|
|
508
|
+
}, [active.cwd, active.preset, props.client]);
|
|
509
|
+
const openSelected = useCallback(() => {
|
|
510
|
+
if (selectedKey === "new") {
|
|
511
|
+
if (active.sessionId === undefined) {
|
|
512
|
+
setFocus("composer");
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
startNew();
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
const item = items.find((entry) => entry.kind === "session" && entry.row.sessionId === selectedKey);
|
|
519
|
+
if (item === undefined)
|
|
520
|
+
return;
|
|
521
|
+
if (item.row.sessionId === active.sessionId) {
|
|
522
|
+
setFocus("composer");
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
void openSession(item.row);
|
|
526
|
+
}, [active.sessionId, items, openSession, selectedKey, startNew]);
|
|
527
|
+
const openAccessMenu = useCallback(() => {
|
|
528
|
+
const index = Math.max(0, accessOptions.findIndex(option => option.value === currentAccess));
|
|
529
|
+
setMenu({ kind: "access", index });
|
|
530
|
+
}, [accessOptions, currentAccess]);
|
|
531
|
+
/**
|
|
532
|
+
* Point the blank session at another agent mode.
|
|
533
|
+
*
|
|
534
|
+
* The host locks a mode once the first turn starts, so the picker acts on the draft: it opens
|
|
535
|
+
* (or reuses) the session this conversation already owns, and the notice prints what the host
|
|
536
|
+
* RECORDED rather than what was asked for — the header then reads the host's own answer.
|
|
537
|
+
*/
|
|
538
|
+
const applyMode = useCallback(async (value) => {
|
|
539
|
+
try {
|
|
540
|
+
const id = await chatRef.current.ensureSession();
|
|
541
|
+
const recorded = await selectPreset(props.client, id, value);
|
|
542
|
+
setActive(previous => ({ ...previous, sessionId: id, preset: recorded }));
|
|
543
|
+
setSelectedKey(key => (key === "new" ? id : key));
|
|
544
|
+
setNotice(presetLabel(recorded));
|
|
545
|
+
setConnection("connected");
|
|
546
|
+
await loadSessionsSafe();
|
|
547
|
+
}
|
|
548
|
+
catch (error) {
|
|
549
|
+
setNotice(presetFailure(error));
|
|
550
|
+
}
|
|
551
|
+
}, [loadSessionsSafe, props.client]);
|
|
552
|
+
/** Open the mode menu on the mode the conversation runs. */
|
|
553
|
+
const openModeMenu = useCallback(() => {
|
|
554
|
+
const index = Math.max(0, presets.findIndex(option => option.value === presetNow));
|
|
555
|
+
setMenu({ kind: "mode", index });
|
|
556
|
+
}, [presets, presetNow]);
|
|
557
|
+
const openModelMenu = useCallback(() => {
|
|
558
|
+
if (models.length === 0) {
|
|
559
|
+
setNotice(UI.catalogFailed);
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
const index = Math.max(0, models.findIndex(option => option.provider === modelRoute?.provider && option.model === modelRoute?.model));
|
|
563
|
+
setMenu({ kind: "model", index });
|
|
564
|
+
}, [models, modelRoute]);
|
|
565
|
+
/** Open the reasoning submenu for the highlighted (or the active) model. */
|
|
566
|
+
const openEffortMenu = useCallback((modelIndex) => {
|
|
567
|
+
if (models.length === 0) {
|
|
568
|
+
setNotice(UI.catalogFailed);
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
const index = modelIndex ?? Math.max(0, models.findIndex(option => option.provider === modelRoute?.provider && option.model === modelRoute?.model));
|
|
572
|
+
const rows = effortOptions(models[index]);
|
|
573
|
+
const current = Math.max(0, rows.findIndex(row => row.value === (effortId ?? DEFAULT_EFFORT_VALUE)));
|
|
574
|
+
setMenu({ kind: "effort", index: current, modelIndex: index });
|
|
575
|
+
}, [effortId, models, modelRoute]);
|
|
576
|
+
/** Open the "Thêm" menu: real actions, not decoration. */
|
|
577
|
+
const openPlusMenu = useCallback(() => { setMenu({ kind: "plus", index: 0 }); }, []);
|
|
578
|
+
/** Put an @ token in the composer so the file picker answers it. */
|
|
579
|
+
const openAttach = useCallback(() => {
|
|
580
|
+
setFilesDismissed(false);
|
|
581
|
+
setComposerText(text => (text.length === 0 || text.endsWith(" ") ? text : text + " ") + "@");
|
|
582
|
+
setFocus("composer");
|
|
583
|
+
}, []);
|
|
584
|
+
/** List the workspaces this screen knows: the sessions' own, then the folders under this one. */
|
|
585
|
+
const openWorkspacePicker = useCallback(async () => {
|
|
586
|
+
const dirs = await listWorkspaceDirs(active.cwd);
|
|
587
|
+
const known = [...new Set(rowsList.map(row => row.cwd))].filter(cwd => cwd !== active.cwd);
|
|
588
|
+
const rows = [
|
|
589
|
+
...known.map(cwd => ({ value: cwd, label: workspaceName(cwd, home), hint: cwd })),
|
|
590
|
+
...dirs.map(name => ({ value: join(active.cwd, name), label: name + "/", hint: join(active.cwd, name) })),
|
|
591
|
+
];
|
|
592
|
+
setWorkspacePicker({ index: 0, rows });
|
|
593
|
+
}, [active.cwd, home, rowsList]);
|
|
594
|
+
/** Install one reasoning effort on the active model through session.selectModel. */
|
|
595
|
+
const applyEffort = useCallback(async (option, value) => {
|
|
596
|
+
const label = effortLabel(value, option.efforts?.find(entry => entry.id === value)?.name);
|
|
597
|
+
try {
|
|
598
|
+
const sessionId = await chatRef.current.ensureSession();
|
|
599
|
+
const answer = await props.client.call("session.selectModel", {
|
|
600
|
+
request: {
|
|
601
|
+
sessionId,
|
|
602
|
+
provider: option.provider,
|
|
603
|
+
model: option.model,
|
|
604
|
+
...(value.length === 0 ? {} : { reasoningEffort: value }),
|
|
605
|
+
},
|
|
606
|
+
});
|
|
607
|
+
setEffortId(answer.selected?.reasoningEffort);
|
|
608
|
+
setModelRoute({ provider: option.provider, model: option.model });
|
|
609
|
+
setModelLabel(option.name);
|
|
610
|
+
setActive(previous => ({ ...previous, sessionId, ...(previous.sessionId === undefined ? { key: sessionId } : {}) }));
|
|
611
|
+
setSelectedKey(key => (key === "new" ? sessionId : key));
|
|
612
|
+
setNotice(UI.effortApplied + ": " + label + " · " + option.name);
|
|
613
|
+
setConnection("connected");
|
|
614
|
+
await loadSessionsSafe();
|
|
615
|
+
}
|
|
616
|
+
catch (error) {
|
|
617
|
+
setNotice(UI.effortFailed + ": " + errorMessage(error));
|
|
618
|
+
}
|
|
619
|
+
}, [loadSessionsSafe, props.client]);
|
|
620
|
+
/** Apply the highlighted row of whichever menu is open. */
|
|
621
|
+
const acceptMenu = useCallback(() => {
|
|
622
|
+
const current = menu;
|
|
623
|
+
if (current === undefined)
|
|
624
|
+
return;
|
|
625
|
+
if (current.kind === "access") {
|
|
626
|
+
setMenu(undefined);
|
|
627
|
+
const option = accessOptions[current.index];
|
|
628
|
+
if (option !== undefined)
|
|
629
|
+
void applyAccess(option.value);
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
if (current.kind === "mode") {
|
|
633
|
+
setMenu(undefined);
|
|
634
|
+
const option = presets[current.index];
|
|
635
|
+
if (option !== undefined)
|
|
636
|
+
void applyMode(option.value);
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
if (current.kind === "model") {
|
|
640
|
+
setMenu(undefined);
|
|
641
|
+
const option = models[current.index];
|
|
642
|
+
if (option !== undefined)
|
|
643
|
+
void applyModel(option);
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
if (current.kind === "effort") {
|
|
647
|
+
const option = models[current.modelIndex ?? current.index];
|
|
648
|
+
const row = option === undefined ? undefined : effortOptions(option)[current.index];
|
|
649
|
+
setMenu(undefined);
|
|
650
|
+
if (option !== undefined)
|
|
651
|
+
void applyEffort(option, row?.value ?? DEFAULT_EFFORT_VALUE);
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
const row = plusOptions()[current.index];
|
|
655
|
+
setMenu(undefined);
|
|
656
|
+
if (row?.value === "attach")
|
|
657
|
+
openAttach();
|
|
658
|
+
else if (row?.value === "workspace")
|
|
659
|
+
void openWorkspacePicker();
|
|
660
|
+
}, [accessOptions, applyAccess, applyEffort, applyMode, applyModel, menu, models, openAttach, openWorkspacePicker, presets]);
|
|
661
|
+
/** Insert the highlighted file into the composer and close the picker. */
|
|
662
|
+
const acceptFile = useCallback(() => {
|
|
663
|
+
const chosen = fileMatches[fileIndex];
|
|
664
|
+
if (chosen === undefined)
|
|
665
|
+
return;
|
|
666
|
+
setComposerText(text => insertFilePath(text, chosen));
|
|
667
|
+
setFileIndex(0);
|
|
668
|
+
setFilesDismissed(true);
|
|
669
|
+
}, [fileIndex, fileMatches]);
|
|
670
|
+
/** Open a draft in the workspace the chooser named. */
|
|
671
|
+
const acceptWorkspace = useCallback(() => {
|
|
672
|
+
const choice = workspacePicker?.rows[workspacePicker.index];
|
|
673
|
+
setWorkspacePicker(undefined);
|
|
674
|
+
if (choice === undefined)
|
|
675
|
+
return;
|
|
676
|
+
startNew(choice.value);
|
|
677
|
+
}, [startNew, workspacePicker]);
|
|
678
|
+
/** "/" lines are terminal actions; everything else is a prompt. */
|
|
679
|
+
const runCommand = useCallback((raw) => {
|
|
680
|
+
const [nameRaw, ...rest] = raw.slice(1).trim().split(/\s+/u);
|
|
681
|
+
const name = (nameRaw ?? "").toLowerCase();
|
|
682
|
+
const argument = rest.join(" ").trim();
|
|
683
|
+
setComposerText("");
|
|
684
|
+
if (name === "help") {
|
|
685
|
+
setHelpScroll(0);
|
|
686
|
+
setOverlay("help");
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
689
|
+
if (name === "session") {
|
|
690
|
+
setOverlay("session");
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
if (name === "mode" || name === "preset") {
|
|
694
|
+
openModeMenu();
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
if (name === "model") {
|
|
698
|
+
openModelMenu();
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
if (name === "effort" || name === "reasoning") {
|
|
702
|
+
openEffortMenu();
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
if (name === "more" || name === "them") {
|
|
706
|
+
openPlusMenu();
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
if (name === "attach" || name === "file" || name === "files") {
|
|
710
|
+
openAttach();
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
if (name === "permission" || name === "quyen") {
|
|
714
|
+
if (argument.length > 0)
|
|
715
|
+
void applyAccess(argument);
|
|
716
|
+
else
|
|
717
|
+
openAccessMenu();
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
if (name === "thinking") {
|
|
721
|
+
setShowThinking(value => !value);
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
724
|
+
if (name === "tools") {
|
|
725
|
+
setShowTools(value => !value);
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
if (name === "clear") {
|
|
729
|
+
dispatch({ type: "reset", messages: [], steps: stateRef.current.steps });
|
|
730
|
+
setScroll(0);
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
if (name === "quit" || name === "exit") {
|
|
734
|
+
exit();
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
setNotice("Lệnh không tồn tại: /" + name + " · gõ /help để xem danh sách");
|
|
738
|
+
}, [applyAccess, exit, openAccessMenu, openAttach, openEffortMenu, openModeMenu, openModelMenu, openPlusMenu]);
|
|
739
|
+
/**
|
|
740
|
+
* Enter on the "/" palette: a command runs at once, a skill is inserted for the user to finish.
|
|
741
|
+
*
|
|
742
|
+
* A command is the terminal's own work and needs no args to be useful; a skill is a prompt the
|
|
743
|
+
* model acts on, so the composer keeps it as text until the user adds the actual request.
|
|
744
|
+
*/
|
|
745
|
+
const acceptSlash = useCallback(() => {
|
|
746
|
+
const row = slashRows[slashIndex] ?? slashRows[0];
|
|
747
|
+
if (row === undefined)
|
|
748
|
+
return;
|
|
749
|
+
const line = slashLine(row);
|
|
750
|
+
if (row.kind === "command") {
|
|
751
|
+
runCommand(line);
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
setComposerText(line + " ");
|
|
755
|
+
palette.dismiss();
|
|
756
|
+
setFocus("composer");
|
|
757
|
+
}, [palette, runCommand, slashIndex, slashRows]);
|
|
758
|
+
const submit = useCallback(() => {
|
|
759
|
+
if (menu !== undefined || overlay !== undefined)
|
|
760
|
+
return;
|
|
761
|
+
// Enter belongs to an open palette: it runs the highlighted row instead of sending "/offi".
|
|
762
|
+
if (slashOpen) {
|
|
763
|
+
acceptSlash();
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
const text = composerText.trim();
|
|
767
|
+
if (text.length === 0) {
|
|
768
|
+
openSelected();
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
if (stateRef.current.running) {
|
|
772
|
+
setNotice("Đang chạy — Esc để dừng lượt hiện tại rồi gửi tiếp.");
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
if (text.startsWith("/")) {
|
|
776
|
+
// A line that names a skill is work for the model, not a terminal command: the palette
|
|
777
|
+
// inserted it so the user could finish the request, so it belongs in the turn.
|
|
778
|
+
const name = (text.slice(1).trim().split(/\s+/u)[0] ?? "").toLowerCase();
|
|
779
|
+
const terminal = LOCAL_COMMANDS.some(command => command.name === name) || EXTRA_COMMANDS.some(command => command.name === name);
|
|
780
|
+
if (!terminal && skills.some(skill => skill.name === name)) {
|
|
781
|
+
send(composerText);
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
784
|
+
runCommand(text);
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
send(composerText);
|
|
788
|
+
}, [acceptSlash, composerText, menu, openSelected, overlay, runCommand, send, skills, slashOpen]);
|
|
789
|
+
/** Enter on the chip row: each chip opens the menu it names, or sends. */
|
|
790
|
+
const activateChip = useCallback((index) => {
|
|
791
|
+
if (index === 0) {
|
|
792
|
+
openPlusMenu();
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
if (index === 1) {
|
|
796
|
+
openModeMenu();
|
|
797
|
+
return;
|
|
798
|
+
}
|
|
799
|
+
if (index === 2) {
|
|
800
|
+
openAccessMenu();
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
if (index === 3) {
|
|
804
|
+
openModelMenu();
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
submit();
|
|
808
|
+
}, [openAccessMenu, openModeMenu, openModelMenu, openPlusMenu, submit]);
|
|
809
|
+
useInput((input, key) => {
|
|
810
|
+
if (key.ctrl && input === "c") {
|
|
811
|
+
abortRef.current?.abort();
|
|
812
|
+
exit();
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
815
|
+
// The workspace chooser is the innermost surface: it owns the arrows and Enter.
|
|
816
|
+
if (workspacePicker !== undefined) {
|
|
817
|
+
if (key.upArrow) {
|
|
818
|
+
setWorkspacePicker({ ...workspacePicker, index: Math.max(0, workspacePicker.index - 1) });
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
821
|
+
if (key.downArrow) {
|
|
822
|
+
setWorkspacePicker({ ...workspacePicker, index: Math.min(Math.max(0, workspacePicker.rows.length - 1), workspacePicker.index + 1) });
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
if (key.return) {
|
|
826
|
+
acceptWorkspace();
|
|
827
|
+
return;
|
|
828
|
+
}
|
|
829
|
+
if (key.escape || key.tab) {
|
|
830
|
+
setWorkspacePicker(undefined);
|
|
831
|
+
return;
|
|
832
|
+
}
|
|
833
|
+
return;
|
|
834
|
+
}
|
|
835
|
+
// The @ picker owns the arrows and Enter while a trailing @token is being typed.
|
|
836
|
+
if (pickerOpen) {
|
|
837
|
+
if (key.upArrow) {
|
|
838
|
+
setFileIndex(value => Math.max(0, value - 1));
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
if (key.downArrow) {
|
|
842
|
+
setFileIndex(value => Math.min(Math.max(0, fileMatches.length - 1), value + 1));
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
if (key.return) {
|
|
846
|
+
acceptFile();
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
if (key.escape) {
|
|
850
|
+
setFilesDismissed(true);
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
return;
|
|
854
|
+
}
|
|
855
|
+
// The "/" palette owns the arrows while a bare "/word" is being typed. Enter is the
|
|
856
|
+
// composer's key and lands in `submit`, so it is only ever handled once.
|
|
857
|
+
if (slashOpen) {
|
|
858
|
+
if (key.upArrow) {
|
|
859
|
+
palette.setIndex(value => moveSlash(value, -1, slashRows.length));
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
if (key.downArrow) {
|
|
863
|
+
palette.setIndex(value => moveSlash(value, 1, slashRows.length));
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
866
|
+
if (key.escape) {
|
|
867
|
+
palette.dismiss();
|
|
868
|
+
return;
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
if (key.escape) {
|
|
872
|
+
if (menu !== undefined) {
|
|
873
|
+
setMenu(undefined);
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
876
|
+
if (overlay !== undefined) {
|
|
877
|
+
setOverlay(undefined);
|
|
878
|
+
return;
|
|
879
|
+
}
|
|
880
|
+
if (stateRef.current.running) {
|
|
881
|
+
cancel();
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
884
|
+
if (notice !== undefined) {
|
|
885
|
+
setNotice(undefined);
|
|
886
|
+
return;
|
|
887
|
+
}
|
|
888
|
+
if (focus !== "composer") {
|
|
889
|
+
setFocus("composer");
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
892
|
+
if (composerText.length > 0)
|
|
893
|
+
setComposerText("");
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
896
|
+
if (menu !== undefined) {
|
|
897
|
+
const total = menuRows(menu, accessOptions, models, currentAccess, modelRoute === undefined ? undefined : modelRoute.provider + "/" + modelRoute.model, presets, presetNow).length;
|
|
898
|
+
if (key.upArrow) {
|
|
899
|
+
setMenu({ ...menu, index: Math.max(0, menu.index - 1) });
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
if (key.downArrow) {
|
|
903
|
+
setMenu({ ...menu, index: Math.min(Math.max(0, total - 1), menu.index + 1) });
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
906
|
+
if (key.return) {
|
|
907
|
+
acceptMenu();
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
// Right opens the reasoning submenu from a model row; left walks back out of it.
|
|
911
|
+
if (menu.kind === "model" && (key.rightArrow || key.tab)) {
|
|
912
|
+
openEffortMenu(menu.index);
|
|
913
|
+
return;
|
|
914
|
+
}
|
|
915
|
+
if (menu.kind === "effort" && key.leftArrow) {
|
|
916
|
+
setMenu({ kind: "model", index: menu.modelIndex ?? 0 });
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
919
|
+
return;
|
|
920
|
+
}
|
|
921
|
+
if (overlay !== undefined) {
|
|
922
|
+
// The help table can be longer than a short terminal, so it scrolls while it is open.
|
|
923
|
+
if (overlay === "help" && (key.pageUp || key.pageDown || key.upArrow || key.downArrow)) {
|
|
924
|
+
const page = Math.max(1, contentHeight - 4);
|
|
925
|
+
const delta = key.pageUp ? -page : key.pageDown ? page : key.upArrow ? -1 : 1;
|
|
926
|
+
setHelpScroll(value => Math.max(0, Math.min(maxHelpTop, value + delta)));
|
|
927
|
+
return;
|
|
928
|
+
}
|
|
929
|
+
if (key.return || key.tab || input === "q")
|
|
930
|
+
setOverlay(undefined);
|
|
931
|
+
return;
|
|
932
|
+
}
|
|
933
|
+
if (key.ctrl && input === "b") {
|
|
934
|
+
const hidden = !sidebarHidden;
|
|
935
|
+
setSidebarHidden(hidden);
|
|
936
|
+
if (hidden)
|
|
937
|
+
setFocus("composer");
|
|
938
|
+
return;
|
|
939
|
+
}
|
|
940
|
+
if (key.ctrl && input === "t") {
|
|
941
|
+
setTab(tab === "chat" ? "trajectory" : "chat");
|
|
942
|
+
setScroll(0);
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
if (key.ctrl && input === "l") {
|
|
946
|
+
setShowThinking(value => !value);
|
|
947
|
+
return;
|
|
948
|
+
}
|
|
949
|
+
if (key.ctrl && input === "o") {
|
|
950
|
+
setShowTools(value => !value);
|
|
951
|
+
return;
|
|
952
|
+
}
|
|
953
|
+
if (key.ctrl && input === "p") {
|
|
954
|
+
openModelMenu();
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
if (key.ctrl && input === "k") {
|
|
958
|
+
openAccessMenu();
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
961
|
+
if (key.ctrl && input === "e") {
|
|
962
|
+
openEffortMenu();
|
|
963
|
+
return;
|
|
964
|
+
}
|
|
965
|
+
if (key.ctrl && input === "g") {
|
|
966
|
+
setScroll(0);
|
|
967
|
+
return;
|
|
968
|
+
}
|
|
969
|
+
// Tab walks the three regions: text line, chip row, sidebar.
|
|
970
|
+
if (key.tab) {
|
|
971
|
+
setFocus(focus === "composer" ? "chips" : focus === "chips" ? "sidebar" : "composer");
|
|
972
|
+
return;
|
|
973
|
+
}
|
|
974
|
+
if (focus === "chips") {
|
|
975
|
+
if (key.leftArrow) {
|
|
976
|
+
setChipIndex(value => Math.max(0, value - 1));
|
|
977
|
+
return;
|
|
978
|
+
}
|
|
979
|
+
if (key.rightArrow) {
|
|
980
|
+
setChipIndex(value => Math.min(COMPOSER_CHIPS.length - 1, value + 1));
|
|
981
|
+
return;
|
|
982
|
+
}
|
|
983
|
+
if (key.return) {
|
|
984
|
+
activateChip(chipIndex);
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
if (input.length > 0 && !key.ctrl && !key.meta) {
|
|
988
|
+
// A printable key means the person wants to type: hand the row back and keep the character.
|
|
989
|
+
setFocus("composer");
|
|
990
|
+
setComposerText(text => text + terminalText(input).replace(/[\n\t]+/gu, " "));
|
|
991
|
+
return;
|
|
992
|
+
}
|
|
993
|
+
return;
|
|
994
|
+
}
|
|
995
|
+
if (key.pageUp || key.pageDown) {
|
|
996
|
+
const page = Math.max(1, (tab === "trajectory" ? trajectoryVisible : transcriptHeight) - 2);
|
|
997
|
+
if (tab === "trajectory") {
|
|
998
|
+
setTrajectoryScroll(value => Math.max(0, Math.min(maxTrajectoryTop, value + (key.pageUp ? page : -page))));
|
|
999
|
+
return;
|
|
1000
|
+
}
|
|
1001
|
+
if (key.pageUp)
|
|
1002
|
+
setScroll(value => Math.min(maxTop, value + page));
|
|
1003
|
+
else
|
|
1004
|
+
setScroll(value => Math.max(0, value - page));
|
|
1005
|
+
return;
|
|
1006
|
+
}
|
|
1007
|
+
if (key.upArrow || key.downArrow) {
|
|
1008
|
+
const delta = key.upArrow ? -1 : 1;
|
|
1009
|
+
// On the ledger tab the arrows walk the table, because the transcript is not on screen.
|
|
1010
|
+
if (tab === "trajectory" && focus === "composer") {
|
|
1011
|
+
setTrajectoryScroll(value => Math.max(0, Math.min(maxTrajectoryTop, value - delta)));
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
if (focus === "sidebar" || composerText.trim().length === 0) {
|
|
1015
|
+
moveSelection(delta);
|
|
1016
|
+
return;
|
|
1017
|
+
}
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
if (focus === "sidebar" && key.return) {
|
|
1021
|
+
openSelected();
|
|
1022
|
+
return;
|
|
1023
|
+
}
|
|
1024
|
+
if (focus === "sidebar" && input === "n") {
|
|
1025
|
+
startNew();
|
|
1026
|
+
}
|
|
1027
|
+
});
|
|
1028
|
+
const lines = useMemo(() => transcriptRows(state.messages, Math.max(16, mainWidth - 2), showThinking, showTools, { running: state.running }), [state.messages, mainWidth, showThinking, showTools, state.running]);
|
|
1029
|
+
const maxTop = Math.max(0, lines.length - transcriptHeight);
|
|
1030
|
+
const top = Math.max(0, Math.min(maxTop, maxTop - scroll));
|
|
1031
|
+
const visible = lines.slice(top, top + transcriptHeight);
|
|
1032
|
+
const pad = Math.max(0, transcriptHeight - visible.length);
|
|
1033
|
+
const runningTurn = state.turns.findLast(turn => turn.state === "running");
|
|
1034
|
+
const duration = runningTurn === undefined ? state.durationMs : Math.max(0, clock - runningTurn.startedAt);
|
|
1035
|
+
const activeTitle = active.title ?? (active.sessionId === undefined ? UI.newSession : sessionTitle(undefined));
|
|
1036
|
+
const workspace = workspaceName(active.cwd, home);
|
|
1037
|
+
const accessText = accessLabel(currentAccess);
|
|
1038
|
+
const currentRoute = modelRoute === undefined ? undefined : modelRoute.provider + "/" + modelRoute.model;
|
|
1039
|
+
const menuOptions = menuRows(menu, accessOptions, models, currentAccess, currentRoute, presets, presetNow);
|
|
1040
|
+
const checkedValue = menu === undefined ? undefined : menuCurrent(menu.kind, currentAccess, currentRoute, effortId, presetNow);
|
|
1041
|
+
const sessionLines = [
|
|
1042
|
+
"Phiên: " + (active.sessionId ?? "chưa tạo"),
|
|
1043
|
+
"Workspace: " + terminalText(active.cwd),
|
|
1044
|
+
"Harness: " + terminalText(props.client.base),
|
|
1045
|
+
"Log host: " + terminalText(props.host.logFile),
|
|
1046
|
+
"Chế độ: " + presetName(presetNow),
|
|
1047
|
+
"Quyền: " + accessText,
|
|
1048
|
+
UI.model + ": " + routeText + " · " + UI.reasoning + ": " + effortText,
|
|
1049
|
+
"Thống kê: " + String(state.turns.length) + " lượt · " + String(state.steps) + " bước · " + formatTokens(state.tokens ?? 0) + " token",
|
|
1050
|
+
];
|
|
1051
|
+
let content;
|
|
1052
|
+
if (overlay === "help")
|
|
1053
|
+
content = _jsx(HelpPanel, { lines: helpTable, keyWidth: HELP_KEY_WIDTH, width: Math.max(16, mainWidth - 6), height: contentHeight, scroll: helpScroll });
|
|
1054
|
+
else if (overlay === "session")
|
|
1055
|
+
content = _jsx(InfoPanel, { title: UI.sessionInfo, lines: sessionLines, width: Math.max(16, mainWidth - 4) });
|
|
1056
|
+
else if (tab === "trajectory")
|
|
1057
|
+
content = _jsx(Trajectory, { rows: trajectoryRows, width: mainWidth - 2, height: contentHeight, scroll: trajectoryScroll, loading: trajectoryLoading, ...(trajectoryError === undefined ? {} : { error: trajectoryError }), hasMore: trajectoryMore });
|
|
1058
|
+
else if (historyLoading)
|
|
1059
|
+
content = _jsx(Box, { height: contentHeight, flexGrow: 1, alignItems: "center", justifyContent: "center", children: _jsx(Activity, { label: UI.loadingHistory }) });
|
|
1060
|
+
else if (state.messages.length === 0)
|
|
1061
|
+
content = _jsx(EmptyConversation, { width: Math.max(16, mainWidth - 4) });
|
|
1062
|
+
else
|
|
1063
|
+
content = _jsxs(Box, { height: contentHeight, flexShrink: 0, flexDirection: "column", paddingX: 1, overflow: "hidden", children: [pad > 0 && _jsx(Box, { height: pad, flexShrink: 0 }), visible.map((row, index) => _jsx(Box, { height: 1, flexShrink: 0, overflow: "hidden", children: _jsx(Row, { row: row }) }, index))] });
|
|
1064
|
+
return _jsxs(Box, { width: columns, height: rows, flexDirection: "column", overflow: "hidden", children: [_jsxs(Box, { height: bodyHeight, flexShrink: 0, flexDirection: "row", overflow: "hidden", children: [sidebarWidth > 0 && _jsx(Sidebar, { items: items, width: sidebarWidth, height: bodyHeight, selectedKey: selectedKey, ...(active.sessionId === undefined ? {} : { activeSessionId: active.sessionId }), focused: focus === "sidebar", now: now }), _jsxs(Box, { width: mainWidth, height: bodyHeight, flexDirection: "column", overflow: "hidden", children: [_jsx(ConversationHeader, { workspace: workspace, title: activeTitle, preset: presetLabel(presetNow), tab: tab, running: state.running, turn: state.turns.length, width: mainWidth }), notice !== undefined && _jsx(Box, { height: 1, flexShrink: 0, paddingX: 1, overflow: "hidden", children: _jsx(Text, { color: "yellow", wrap: "truncate-end", children: "! " + notice }) }), _jsx(Box, { height: contentHeight, flexShrink: 0, overflow: "hidden", flexDirection: "column", children: content }), _jsxs(Box, { height: 1, flexShrink: 0, paddingX: 1, overflow: "hidden", children: [state.running
|
|
1065
|
+
? _jsx(Activity, { label: state.thinking ? UI.thinking : state.status.length > 0 ? state.status : UI.thinking })
|
|
1066
|
+
: historyLoading
|
|
1067
|
+
? _jsx(Activity, { label: UI.loadingHistory })
|
|
1068
|
+
: _jsx(Text, { dimColor: true, wrap: "truncate-end", children: slashOpen ? UI.pickerHint + " · " + String(slashRows.length) + " gợi ý" : UI.composerHint }), _jsx(Box, { flexGrow: 1 }), scroll > 0 && _jsx(Text, { dimColor: true, children: "↑ lịch sử " + String(scroll) })] })] })] }), menu !== undefined && _jsx(Box, { marginLeft: sidebarWidth, width: mainWidth, height: menuHeight, flexShrink: 0, overflow: "hidden", children: _jsx(MenuPanel, { title: menuTitle(menu.kind), options: menuOptions, selected: menu.index, ...(checkedValue === undefined ? {} : { current: checkedValue }), width: mainWidth, height: menuHeight }) }), workspacePicker !== undefined && _jsx(Box, { marginLeft: sidebarWidth, width: mainWidth, height: pickerHeight, flexShrink: 0, overflow: "hidden", children: _jsx(ListPicker, { title: UI.workspacePicker, rows: workspacePicker.rows, selected: workspacePicker.index, width: mainWidth, height: pickerHeight, empty: UI.noWorkspaces }) }), workspacePicker === undefined && pickerOpen && _jsx(Box, { marginLeft: sidebarWidth, width: mainWidth, height: pickerHeight, flexShrink: 0, overflow: "hidden", children: _jsx(ListPicker, { title: UI.filePicker + (fileQueryText === undefined || fileQueryText.length === 0 ? "" : " · @" + fileQueryText), rows: fileMatches.slice(0, 200).map(path => ({ value: path, label: path })), selected: fileIndex, width: mainWidth, height: pickerHeight, empty: UI.noFiles }) }), slashOpen && _jsx(Box, { marginLeft: sidebarWidth, width: mainWidth, height: slashHeight, flexShrink: 0, overflow: "hidden", children: _jsx(SlashPanel, { rows: slashRows, selected: slashIndex, width: mainWidth, height: slashHeight }) }), _jsx(Box, { height: composerHeight, width: columns, flexShrink: 0, overflow: "hidden", children: _jsx(ChatComposer, { value: composerText, onChange: setComposerText, onSubmit: submit, active: focus === "composer" && menu === undefined && overlay === undefined && !historyLoading, row: composerRow, column: 4, width: textWidth, height: composerHeight, running: state.running, preset: presetLabel(presetNow), access: accessText, model: routeText, modelShort: modelLabel, effort: effortText, picker: pickerOpen, chipsFocused: focus === "chips", chipIndex: chipIndex }) }), _jsx(StatusBar, { connection: { base: props.client.base, state: connection === "disconnected" ? "disconnected" : state.running ? "running" : "connected" }, steps: state.steps, ...(state.tokens === undefined ? {} : { tokens: state.tokens }), ...(duration === undefined ? {} : { durationMs: duration }), model: routeText, version: version, width: columns })] });
|
|
1069
|
+
}
|
|
1070
|
+
//# sourceMappingURL=screen.js.map
|