@galaxy-stack/blackhole-cli 2.0.0-alpha.9 → 2.0.0
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 +42 -2
- package/dist/application.d.ts +42 -0
- package/dist/application.d.ts.map +1 -1
- package/dist/application.js +113 -8
- package/dist/application.js.map +1 -1
- package/dist/cli-meta.d.ts +15 -0
- package/dist/cli-meta.d.ts.map +1 -0
- package/dist/cli-meta.js +37 -0
- package/dist/cli-meta.js.map +1 -0
- package/dist/cli.js +14 -2
- package/dist/cli.js.map +1 -1
- package/dist/commands.d.ts +13 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +40 -0
- package/dist/commands.js.map +1 -0
- package/dist/composer.d.ts +3 -1
- package/dist/composer.d.ts.map +1 -1
- package/dist/composer.js +15 -3
- package/dist/composer.js.map +1 -1
- package/dist/file-index.d.ts +20 -0
- package/dist/file-index.d.ts.map +1 -0
- package/dist/file-index.js +60 -0
- package/dist/file-index.js.map +1 -0
- package/dist/flow.d.ts +30 -0
- package/dist/flow.d.ts.map +1 -1
- package/dist/flow.js +172 -28
- package/dist/flow.js.map +1 -1
- package/dist/manual-config.d.ts +28 -0
- package/dist/manual-config.d.ts.map +1 -0
- package/dist/manual-config.js +67 -0
- package/dist/manual-config.js.map +1 -0
- package/dist/options.d.ts +10 -2
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +46 -7
- package/dist/options.js.map +1 -1
- package/dist/provider-display.d.ts +20 -0
- package/dist/provider-display.d.ts.map +1 -0
- package/dist/provider-display.js +26 -0
- package/dist/provider-display.js.map +1 -0
- package/dist/thinking-policy.d.ts +53 -0
- package/dist/thinking-policy.d.ts.map +1 -0
- package/dist/thinking-policy.js +135 -0
- package/dist/thinking-policy.js.map +1 -0
- package/dist/timeline.d.ts +52 -5
- package/dist/timeline.d.ts.map +1 -1
- package/dist/timeline.js +362 -32
- package/dist/timeline.js.map +1 -1
- package/dist/tui.d.ts +3 -1
- package/dist/tui.d.ts.map +1 -1
- package/dist/tui.js +353 -13
- package/dist/tui.js.map +1 -1
- package/dist/web/options.js +2 -2
- package/dist/web/options.js.map +1 -1
- package/package.json +2 -2
- package/skills/galaxy-ui/SKILL.md +13 -0
- package/skills/orbit-framework/SKILL.md +109 -4
- package/web/brand/client.template.js +184 -0
- package/web/brand/lib/client.js +212 -2
- package/web/brand/lib/index.d.ts +3 -0
- package/web/brand/lib/index.js +202 -0
- package/web/brand/lib/session-store.d.ts +54 -0
- package/web/brand/lib/session-store.js +288 -0
- package/web/brand/vi.locales.json +28 -2
- package/web/patches/gbh-brand.patch.yml +1 -1
package/dist/tui.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useMemo, useState } from "react";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
3
|
import { Box, Text, render, useApp, useInput, useStdout } from "ink";
|
|
4
|
-
import { AssistantRuntimeProvider, useAuiState, useLocalRuntime } from "@assistant-ui/react-ink";
|
|
4
|
+
import { AssistantRuntimeProvider, useAui, useAuiState, useLocalRuntime } from "@assistant-ui/react-ink";
|
|
5
5
|
import { GalaxyApplication } from "./application.js";
|
|
6
6
|
import { RunTimeline, terminalText, toolLabel, transcriptRows } from "./timeline.js";
|
|
7
7
|
import { FixedComposer } from "./composer.js";
|
|
8
8
|
import { parseMouseInput, ENABLE_MOUSE, DISABLE_MOUSE } from "./terminal-input.js";
|
|
9
|
+
import { commandFromText, matchCommands, TUI_COMMANDS, TUI_SHORTCUTS } from "./commands.js";
|
|
10
|
+
import { fileQuery, insertFilePath, listWorkspaceFiles } from "./file-index.js";
|
|
11
|
+
import { thinkingLabel } from "./thinking-policy.js";
|
|
12
|
+
import { DiffView } from "@assistant-ui/react-ink";
|
|
13
|
+
import { latestDiff, windowPatch } from "./timeline.js";
|
|
9
14
|
import stringWidth from "string-width";
|
|
10
15
|
export { terminalText } from "./timeline.js";
|
|
11
16
|
export function createCoreChatAdapter(app, onEvent, permission, onStart = () => { }, onFinish = () => { }) {
|
|
@@ -17,18 +22,31 @@ export function createCoreChatAdapter(app, onEvent, permission, onStart = () =>
|
|
|
17
22
|
const controller = new AbortController();
|
|
18
23
|
const signal = AbortSignal.any([abortSignal, controller.signal]);
|
|
19
24
|
const timeline = new RunTimeline();
|
|
25
|
+
const startedAt = Date.now();
|
|
26
|
+
let turnTokens;
|
|
20
27
|
let changed = false;
|
|
21
28
|
let done = false;
|
|
22
29
|
let error;
|
|
23
30
|
let wake;
|
|
24
31
|
const notify = () => { wake?.(); wake = undefined; };
|
|
25
32
|
const result = app.run(goal, signal, event => {
|
|
33
|
+
if (event.type === "context_pressure")
|
|
34
|
+
turnTokens = event.tokens;
|
|
35
|
+
if (event.type === "token_ledger")
|
|
36
|
+
turnTokens = event.ledger.actualInput ?? turnTokens;
|
|
26
37
|
onEvent(event);
|
|
27
38
|
timeline.event(event);
|
|
28
39
|
changed = true;
|
|
29
40
|
notify();
|
|
30
41
|
}, permission).then(value => {
|
|
31
42
|
timeline.finish(value.content, value.state, value.error?.message);
|
|
43
|
+
timeline.meta({
|
|
44
|
+
...(app.providerBrand === undefined ? {} : { brand: app.providerBrand }),
|
|
45
|
+
...(app.providerLabel === undefined ? {} : { model: app.providerLabel }),
|
|
46
|
+
...(typeof app.thinkingChoiceLabel !== "function" ? {} : { effort: app.thinkingChoiceLabel() }),
|
|
47
|
+
...(turnTokens === undefined ? {} : { tokens: turnTokens }),
|
|
48
|
+
durationMs: Date.now() - startedAt,
|
|
49
|
+
});
|
|
32
50
|
onFinish(value.state);
|
|
33
51
|
if (value.state === "failed")
|
|
34
52
|
error = new Error(value.error?.message ?? "Agent failed.");
|
|
@@ -54,8 +72,26 @@ export function createCoreChatAdapter(app, onEvent, permission, onStart = () =>
|
|
|
54
72
|
},
|
|
55
73
|
};
|
|
56
74
|
}
|
|
57
|
-
const colors = { plain: undefined, user: "green", assistant: "cyan", thinking: "magenta", running: "yellow", success: "green", error: "red", muted: "gray" };
|
|
58
|
-
function Row({ row
|
|
75
|
+
const colors = { plain: undefined, user: "green", assistant: "cyan", thinking: "magenta", running: "yellow", success: "green", error: "red", muted: "gray", accent: "cyan" };
|
|
76
|
+
function Row({ row, marginTop = 0 }) {
|
|
77
|
+
if (row.node !== undefined) {
|
|
78
|
+
// The node sizes itself; `height` is only the scroll-math estimate. Pinning a
|
|
79
|
+
// fixed height clips a taller diff and Ink merges the clipped tail into the
|
|
80
|
+
// previous line, so the box stays unconstrained.
|
|
81
|
+
return _jsx(Box, { marginTop: marginTop, flexShrink: 0, children: row.node.element });
|
|
82
|
+
}
|
|
83
|
+
const spans = row.spans;
|
|
84
|
+
if (spans === undefined) {
|
|
85
|
+
const color = colors[row.tone];
|
|
86
|
+
return _jsx(Text, { ...(color ? { color } : {}), bold: row.tone === "user" || row.tone === "assistant", wrap: "truncate-end", children: row.text || " " });
|
|
87
|
+
}
|
|
88
|
+
if (spans.length === 0)
|
|
89
|
+
return _jsx(Text, { wrap: "truncate-end", children: " " });
|
|
90
|
+
return _jsx(Text, { wrap: "truncate-end", children: spans.map((span, index) => {
|
|
91
|
+
const color = span.tone === undefined ? undefined : colors[span.tone];
|
|
92
|
+
return _jsx(Text, { ...(color ? { color } : {}), ...(span.bold ? { bold: true } : {}), ...(span.italic ? { italic: true } : {}), ...(span.dim ? { dimColor: true } : {}), children: span.text }, index);
|
|
93
|
+
}) });
|
|
94
|
+
}
|
|
59
95
|
export function Message() {
|
|
60
96
|
const message = useAuiState(s => s.message);
|
|
61
97
|
return _jsx(Box, { flexDirection: "column", children: transcriptRows([message], 80, true).map((row, i) => _jsx(Row, { row: row }, i)) });
|
|
@@ -79,7 +115,33 @@ function useTerminalSize() {
|
|
|
79
115
|
useEffect(() => { const resize = () => setSize(read()); stdout.on("resize", resize); resize(); return () => { stdout.off("resize", resize); }; }, [stdout]);
|
|
80
116
|
return size;
|
|
81
117
|
}
|
|
82
|
-
|
|
118
|
+
/** Snapshot the mutable application fields React needs to re-render. */
|
|
119
|
+
function providerSnapshot(app) {
|
|
120
|
+
// Tests render Screen with a partial application stub, so read defensively.
|
|
121
|
+
const effort = typeof app.thinkingChoiceLabel === "function" ? app.thinkingChoiceLabel() : "Mặc định (hệ thống)";
|
|
122
|
+
return { brand: app.providerBrand ?? "Ollama", model: app.providerLabel ?? "Auto", effort };
|
|
123
|
+
}
|
|
124
|
+
/** Rows shown by /session; read defensively so partial test stubs stay renderable. */
|
|
125
|
+
function sessionRows(app) {
|
|
126
|
+
const history = (() => { try {
|
|
127
|
+
return app.sessions.history(app.session).length;
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return 0;
|
|
131
|
+
} })();
|
|
132
|
+
const effort = typeof app.thinkingChoiceLabel === "function" ? app.thinkingChoiceLabel() : "-";
|
|
133
|
+
const logFile = typeof app.logger?.file === "string" ? app.logger.file : "-";
|
|
134
|
+
return [
|
|
135
|
+
"Session: " + app.session,
|
|
136
|
+
"Workspace: " + (app.options.workspace ?? "-"),
|
|
137
|
+
"State dir: " + (typeof app.stateDir === "string" ? app.stateDir : "-"),
|
|
138
|
+
"Provider: " + (app.providerBrand ?? "-") + " · " + (app.providerLabel ?? "-") + " · Mức suy luận: " + effort,
|
|
139
|
+
"Profile: " + (app.options.profile ?? "-"),
|
|
140
|
+
"Tin nhắn trong phiên: " + history,
|
|
141
|
+
"Log: " + logFile,
|
|
142
|
+
];
|
|
143
|
+
}
|
|
144
|
+
function Screen({ app, status, pending, tokens, cacheHitRate, cumulativeCacheHitRate, onNotice, onQuit, onOverlay }) {
|
|
83
145
|
const { columns, rows } = useTerminalSize();
|
|
84
146
|
const messages = useAuiState(s => s.thread.messages);
|
|
85
147
|
const running = useAuiState(s => s.thread.isRunning);
|
|
@@ -89,6 +151,55 @@ function Screen({ app, status, pending, tokens, cacheHitRate, cumulativeCacheHit
|
|
|
89
151
|
const [skillsOpen, setSkillsOpen] = useState(false);
|
|
90
152
|
const [skillRows, setSkillRows] = useState([]);
|
|
91
153
|
const [skillCursor, setSkillCursor] = useState(0);
|
|
154
|
+
const [modelOpen, setModelOpen] = useState(false);
|
|
155
|
+
const [modelRows, setModelRows] = useState([]);
|
|
156
|
+
const [modelCursor, setModelCursor] = useState(0);
|
|
157
|
+
const [provider, setProvider] = useState(() => providerSnapshot(app));
|
|
158
|
+
const composerText = useAuiState(s => s.composer.text);
|
|
159
|
+
const [helpOpen, setHelpOpen] = useState(false);
|
|
160
|
+
const [effortOpen, setEffortOpen] = useState(false);
|
|
161
|
+
const [effortCursor, setEffortCursor] = useState(0);
|
|
162
|
+
const [commandCursor, setCommandCursor] = useState(0);
|
|
163
|
+
const [sessionOpen, setSessionOpen] = useState(false);
|
|
164
|
+
const [diffOpen, setDiffOpen] = useState(false);
|
|
165
|
+
const [diffOffset, setDiffOffset] = useState(0);
|
|
166
|
+
const [viewHidden, setViewHidden] = useState(0);
|
|
167
|
+
const [files, setFiles] = useState([]);
|
|
168
|
+
const [fileCursor, setFileCursor] = useState(0);
|
|
169
|
+
const aui = useAui();
|
|
170
|
+
const effortRows = useMemo(() => {
|
|
171
|
+
if (typeof app.thinkingPolicy !== "function")
|
|
172
|
+
return ["default"];
|
|
173
|
+
return [...app.thinkingPolicy().choices];
|
|
174
|
+
}, [app, provider.effort]);
|
|
175
|
+
const commands = matchCommands(composerText);
|
|
176
|
+
const atQuery = fileQuery(composerText);
|
|
177
|
+
const fileMatches = useMemo(() => {
|
|
178
|
+
if (atQuery === undefined)
|
|
179
|
+
return [];
|
|
180
|
+
const query = atQuery.query.toLowerCase();
|
|
181
|
+
return files.filter(file => file.toLowerCase().includes(query)).slice(0, 200);
|
|
182
|
+
}, [atQuery?.query, files]);
|
|
183
|
+
const anyOverlay = skillsOpen || modelOpen || helpOpen || effortOpen || sessionOpen || diffOpen;
|
|
184
|
+
const commandMenuOpen = commands.length > 0 && !anyOverlay && !pending;
|
|
185
|
+
const fileMenuOpen = atQuery !== undefined && files.length > 0 && !anyOverlay && !pending;
|
|
186
|
+
const menuOpen = commandMenuOpen || fileMenuOpen;
|
|
187
|
+
const menuRows = commandMenuOpen ? commands.length : fileMatches.length;
|
|
188
|
+
useEffect(() => { onOverlay(anyOverlay); }, [anyOverlay, onOverlay]);
|
|
189
|
+
useEffect(() => {
|
|
190
|
+
if (atQuery === undefined || files.length > 0)
|
|
191
|
+
return;
|
|
192
|
+
let cancelled = false;
|
|
193
|
+
void listWorkspaceFiles(app.options.workspace).then(list => { if (!cancelled)
|
|
194
|
+
setFiles(list); }, () => undefined);
|
|
195
|
+
return () => { cancelled = true; };
|
|
196
|
+
}, [atQuery?.query, files.length, app.options.workspace]);
|
|
197
|
+
const refreshModels = async () => {
|
|
198
|
+
setModelRows(await app.availableModels().catch(() => []));
|
|
199
|
+
setModelCursor(0);
|
|
200
|
+
};
|
|
201
|
+
useEffect(() => { if (modelOpen)
|
|
202
|
+
void refreshModels(); }, [modelOpen]);
|
|
92
203
|
const refreshSkills = async () => {
|
|
93
204
|
const catalog = await app.skills.list().catch(() => []);
|
|
94
205
|
const market = app.marketplace ? await app.marketplace.search("").catch(() => []) : [];
|
|
@@ -105,15 +216,41 @@ function Screen({ app, status, pending, tokens, cacheHitRate, cumulativeCacheHit
|
|
|
105
216
|
const helpHeight = rows < 12 ? 0 : 1;
|
|
106
217
|
const approvalHeight = pending ? (compact ? 2 : 4) : 0;
|
|
107
218
|
const composerHeight = rows < 8 ? 1 : 3;
|
|
108
|
-
const
|
|
109
|
-
const
|
|
110
|
-
|
|
219
|
+
const menuHeight = menuOpen ? Math.min(menuRows, 6) : 0;
|
|
220
|
+
const viewportHeight = Math.max(1, rows - headerHeight - composerHeight - 1 - helpHeight - approvalHeight - menuHeight);
|
|
221
|
+
// The diff viewer is a single-child surface: DiffView sizes itself there.
|
|
222
|
+
const diff = useMemo(() => latestDiff(messages), [messages]);
|
|
223
|
+
const diffBudget = Math.max(4, viewportHeight - 3);
|
|
224
|
+
const diffWindow = useMemo(() => (diff === undefined ? undefined : windowPatch(diff.patch, diffOffset, diffBudget)), [diff, diffOffset, diffBudget]);
|
|
225
|
+
const lines = useMemo(() => transcriptRows(viewHidden > 0 ? messages.slice(viewHidden) : messages, columns - 2, showThinking, showToolDetails, { running }), [messages, viewHidden, columns, showThinking, showToolDetails, running]);
|
|
226
|
+
// Scrolling works on visual lines so rich rows (DiffView) count for their height.
|
|
227
|
+
const heights = useMemo(() => lines.map(row => Math.max(1, row.node?.height ?? 1)), [lines]);
|
|
228
|
+
if (process.env.GALAXY_TUI_DEBUG === "1")
|
|
229
|
+
process.stderr.write("ROWS " + JSON.stringify(lines.map(row => [row.text, row.node?.height ?? 1])) + "\n");
|
|
230
|
+
const totalVisual = heights.reduce((total, height) => total + height, 0);
|
|
231
|
+
const maxTop = Math.max(0, totalVisual - viewportHeight);
|
|
111
232
|
const top = scrollTop === null ? maxTop : Math.min(scrollTop, maxTop);
|
|
233
|
+
const visibleRows = useMemo(() => {
|
|
234
|
+
const visible = [];
|
|
235
|
+
let offset = 0;
|
|
236
|
+
for (let index = 0; index < lines.length && offset < top + viewportHeight; index += 1) {
|
|
237
|
+
const height = heights[index];
|
|
238
|
+
const start = offset;
|
|
239
|
+
offset += height;
|
|
240
|
+
if (offset <= top)
|
|
241
|
+
continue;
|
|
242
|
+
visible.push({ row: lines[index], marginTop: Math.max(0, start - top) });
|
|
243
|
+
}
|
|
244
|
+
return visible;
|
|
245
|
+
}, [lines, heights, top, viewportHeight]);
|
|
112
246
|
const tokenText = tokens === undefined ? "" : `${tokens} tokens${cacheHitRate === undefined ? "" : ` · cache ${Math.round(cacheHitRate * 100)}%`}${cumulativeCacheHitRate === undefined ? "" : ` · Σ ${Math.round(cumulativeCacheHitRate * 100)}%`}`;
|
|
113
247
|
const tokenWidth = Math.min(columns - 2, stringWidth(tokenText));
|
|
114
248
|
const skillVisible = Math.max(1, viewportHeight - 1);
|
|
115
249
|
const skillTop = Math.max(0, Math.min(skillCursor, Math.max(0, skillRows.length - skillVisible)));
|
|
116
250
|
const visibleSkills = skillRows.slice(skillTop, skillTop + skillVisible);
|
|
251
|
+
const modelVisible = Math.max(1, viewportHeight - 1);
|
|
252
|
+
const modelTop = Math.max(0, Math.min(modelCursor, Math.max(0, modelRows.length - modelVisible)));
|
|
253
|
+
const visibleModels = modelRows.slice(modelTop, modelTop + modelVisible);
|
|
117
254
|
useEffect(() => { if (running)
|
|
118
255
|
setScrollTop(null); }, [running]);
|
|
119
256
|
const scroll = (delta) => setScrollTop(previous => {
|
|
@@ -121,11 +258,195 @@ function Screen({ app, status, pending, tokens, cacheHitRate, cumulativeCacheHit
|
|
|
121
258
|
const next = Math.max(0, Math.min(maxTop, current + delta));
|
|
122
259
|
return next === maxTop ? null : next;
|
|
123
260
|
});
|
|
261
|
+
/** Run a "/command" typed in the composer; true when it was handled. */
|
|
262
|
+
const runCommand = (raw) => {
|
|
263
|
+
const target = commandFromText(raw) ?? commands[commandCursor] ?? commands[0];
|
|
264
|
+
if (target === undefined) {
|
|
265
|
+
onNotice("Lệnh không tồn tại: " + raw.trim() + " · gõ /help để xem danh sách");
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
switch (target.name) {
|
|
269
|
+
case "help":
|
|
270
|
+
setHelpOpen(true);
|
|
271
|
+
return true;
|
|
272
|
+
case "model":
|
|
273
|
+
setModelOpen(true);
|
|
274
|
+
return true;
|
|
275
|
+
case "effort": {
|
|
276
|
+
const current = typeof app.thinkingChoice === "function" ? app.thinkingChoice() : "default";
|
|
277
|
+
setEffortCursor(Math.max(0, effortRows.indexOf(current)));
|
|
278
|
+
setEffortOpen(true);
|
|
279
|
+
return true;
|
|
280
|
+
}
|
|
281
|
+
case "thinking":
|
|
282
|
+
setShowThinking(value => { onNotice("Thinking: " + (value ? "ẩn" : "hiện")); return !value; });
|
|
283
|
+
return true;
|
|
284
|
+
case "tools":
|
|
285
|
+
setShowToolDetails(value => { onNotice("Chi tiết tool: " + (value ? "ẩn" : "hiện")); return !value; });
|
|
286
|
+
return true;
|
|
287
|
+
case "skills":
|
|
288
|
+
setSkillsOpen(true);
|
|
289
|
+
return true;
|
|
290
|
+
case "diff": {
|
|
291
|
+
if (diff === undefined) {
|
|
292
|
+
onNotice("Phiên này chưa có diff nào");
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
setDiffOffset(0);
|
|
296
|
+
setDiffOpen(true);
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
case "session":
|
|
300
|
+
setSessionOpen(true);
|
|
301
|
+
return true;
|
|
302
|
+
case "clear":
|
|
303
|
+
setViewHidden(messages.length);
|
|
304
|
+
setScrollTop(null);
|
|
305
|
+
onNotice("Đã xoá màn hình · lịch sử phiên vẫn được lưu");
|
|
306
|
+
return true;
|
|
307
|
+
case "quit":
|
|
308
|
+
onQuit();
|
|
309
|
+
return true;
|
|
310
|
+
default: return false;
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
/** What Enter does: run a command, accept a @file reference, or send. */
|
|
314
|
+
const handleComposerAction = (text) => {
|
|
315
|
+
if (fileMenuOpen && fileMatches.length > 0) {
|
|
316
|
+
const file = fileMatches[fileCursor];
|
|
317
|
+
if (file !== undefined) {
|
|
318
|
+
aui.composer.setText(insertFilePath(text, file));
|
|
319
|
+
return "keep";
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (text.trim().startsWith("/"))
|
|
323
|
+
return runCommand(text) ? "clear" : "send";
|
|
324
|
+
return "send";
|
|
325
|
+
};
|
|
124
326
|
useInput((input, key) => {
|
|
125
327
|
if (key.ctrl && input === "s") {
|
|
126
328
|
setSkillsOpen(value => !value);
|
|
127
329
|
return;
|
|
128
330
|
}
|
|
331
|
+
if (key.ctrl && input === "p") {
|
|
332
|
+
setModelOpen(value => !value);
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
if (commandMenuOpen) {
|
|
336
|
+
if (key.upArrow) {
|
|
337
|
+
setCommandCursor(value => Math.max(0, value - 1));
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
if (key.downArrow) {
|
|
341
|
+
setCommandCursor(value => Math.min(Math.max(0, commands.length - 1), value + 1));
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
if (key.escape)
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
if (fileMenuOpen) {
|
|
348
|
+
if (key.upArrow) {
|
|
349
|
+
setFileCursor(value => Math.max(0, value - 1));
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
if (key.downArrow) {
|
|
353
|
+
setFileCursor(value => Math.min(Math.max(0, fileMatches.length - 1), value + 1));
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
if (key.escape)
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
if (diffOpen) {
|
|
360
|
+
if (key.escape) {
|
|
361
|
+
setDiffOpen(false);
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
if (key.upArrow) {
|
|
365
|
+
setDiffOffset(value => Math.max(0, value - 1));
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
if (key.downArrow) {
|
|
369
|
+
setDiffOffset(value => value + 1);
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
if (key.pageUp) {
|
|
373
|
+
setDiffOffset(value => Math.max(0, value - diffBudget));
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
if (key.pageDown) {
|
|
377
|
+
setDiffOffset(value => value + diffBudget);
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
if (!parseMouseInput(input))
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
if ((helpOpen || sessionOpen) && key.escape) {
|
|
384
|
+
setHelpOpen(false);
|
|
385
|
+
setSessionOpen(false);
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
if (effortOpen) {
|
|
389
|
+
if (key.escape) {
|
|
390
|
+
setEffortOpen(false);
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
if (key.upArrow) {
|
|
394
|
+
setEffortCursor(value => Math.max(0, value - 1));
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
if (key.downArrow) {
|
|
398
|
+
setEffortCursor(value => Math.min(Math.max(0, effortRows.length - 1), value + 1));
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
if (key.return) {
|
|
402
|
+
const choice = effortRows[effortCursor];
|
|
403
|
+
if (choice !== undefined) {
|
|
404
|
+
try {
|
|
405
|
+
app.setThinking(choice);
|
|
406
|
+
setProvider(providerSnapshot(app));
|
|
407
|
+
onNotice("Mức suy luận: " + app.thinkingChoiceLabel());
|
|
408
|
+
}
|
|
409
|
+
catch (error) {
|
|
410
|
+
onNotice(error instanceof Error ? error.message : String(error));
|
|
411
|
+
}
|
|
412
|
+
setEffortOpen(false);
|
|
413
|
+
}
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
if (!parseMouseInput(input))
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
if (modelOpen) {
|
|
420
|
+
if (key.escape) {
|
|
421
|
+
setModelOpen(false);
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
if (key.upArrow) {
|
|
425
|
+
setModelCursor(value => Math.max(0, value - 1));
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
if (key.downArrow) {
|
|
429
|
+
setModelCursor(value => Math.min(Math.max(0, modelRows.length - 1), value + 1));
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
if (key.return) {
|
|
433
|
+
const row = modelRows[modelCursor];
|
|
434
|
+
if (row !== undefined) {
|
|
435
|
+
try {
|
|
436
|
+
app.setModel(row.id);
|
|
437
|
+
setProvider(providerSnapshot(app));
|
|
438
|
+
onNotice("Model: " + (row.id ?? "theo cấu hình"));
|
|
439
|
+
}
|
|
440
|
+
catch (error) {
|
|
441
|
+
onNotice(error instanceof Error ? error.message : String(error));
|
|
442
|
+
}
|
|
443
|
+
setModelOpen(false);
|
|
444
|
+
}
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
if (!parseMouseInput(input))
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
129
450
|
if (skillsOpen) {
|
|
130
451
|
if (key.escape) {
|
|
131
452
|
setSkillsOpen(false);
|
|
@@ -168,6 +489,17 @@ function Screen({ app, status, pending, tokens, cacheHitRate, cumulativeCacheHit
|
|
|
168
489
|
if (key.pageDown)
|
|
169
490
|
scroll(Math.max(1, viewportHeight - 2));
|
|
170
491
|
if (key.ctrl && input === "t") {
|
|
492
|
+
try {
|
|
493
|
+
app.cycleThinkingChoice();
|
|
494
|
+
setProvider(providerSnapshot(app));
|
|
495
|
+
onNotice("Mức suy luận: " + app.thinkingChoiceLabel());
|
|
496
|
+
}
|
|
497
|
+
catch (error) {
|
|
498
|
+
onNotice(error instanceof Error ? error.message : String(error));
|
|
499
|
+
}
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
if (key.ctrl && input === "l") {
|
|
171
503
|
setShowThinking(value => !value);
|
|
172
504
|
}
|
|
173
505
|
if (key.ctrl && input === "o") {
|
|
@@ -176,7 +508,9 @@ function Screen({ app, status, pending, tokens, cacheHitRate, cumulativeCacheHit
|
|
|
176
508
|
if (key.ctrl && input === "g")
|
|
177
509
|
setScrollTop(null);
|
|
178
510
|
});
|
|
179
|
-
return _jsxs(Box, { width: columns, height: rows, flexDirection: "column", overflow: "hidden", children: [_jsxs(Box, { height: headerHeight, flexShrink: 0, flexDirection: "column", paddingX: 1, children: [_jsxs(Text, { color: "cyan", bold: true, wrap: "truncate-end", children: ["GALAXY CODE \u00B7 ", app.options.profile, " \u00B7 ", running ? "Đang chạy" : "Sẵn sàng"] }), headerHeight > 1 && _jsx(Text, { dimColor: true, wrap: "truncate-middle", children: terminalText(app.options.workspace) }), !compact && _jsxs(_Fragment, { children: [
|
|
511
|
+
return _jsxs(Box, { width: columns, height: rows, flexDirection: "column", overflow: "hidden", children: [_jsxs(Box, { height: headerHeight, flexShrink: 0, flexDirection: "column", paddingX: 1, children: [_jsxs(Text, { color: "cyan", bold: true, wrap: "truncate-end", children: ["GALAXY CODE \u00B7 ", app.options.profile, " \u00B7 ", running ? "Đang chạy" : "Sẵn sàng"] }), headerHeight > 1 && _jsx(Text, { dimColor: true, wrap: "truncate-middle", children: terminalText(app.options.workspace) }), !compact && _jsxs(_Fragment, { children: [_jsx(Text, { dimColor: true, wrap: "truncate-end", children: terminalText(provider.brand + " · " + provider.model + " · Mức suy luận: " + provider.effort + " · " + app.session) }), _jsx(Text, { dimColor: true, children: "─".repeat(Math.max(1, columns - 2)) })] })] }), _jsx(Box, { height: viewportHeight, flexShrink: 0, overflow: "hidden", flexDirection: "column", paddingX: 1, children: diffOpen && diff !== undefined && diffWindow !== undefined ? _jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { color: "cyan", bold: true, wrap: "truncate-end", children: ["DIFF \u00B7 ", terminalText(diff.label), " \u00B7 ", diffWindow.shown, "/", diffWindow.total, " d\u00F2ng \u00B7 \u2191/\u2193 PgUp/PgDn cu\u1ED9n \u00B7 esc \u0111\u00F3ng"] }), _jsx(DiffView, { patch: diffWindow.patch, showLineNumbers: true, maxLines: diffBudget })] }) : modelOpen ? _jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: "cyan", bold: true, wrap: "truncate-end", children: "MODEL \u00B7 Ctrl+P/esc \u0111\u00F3ng \u00B7 \u2191/\u2193 ch\u1ECDn \u00B7 Enter \u00E1p d\u1EE5ng" }), modelRows.length === 0 ? _jsx(Text, { dimColor: true, children: "(kh\u00F4ng c\u00F3 model)" }) : visibleModels.map((row, i) => _jsx(Text, { wrap: "truncate-end", ...(modelTop + i === modelCursor ? { color: "cyan" } : {}), children: (modelTop + i === modelCursor ? "❯ " : " ") + row.label }, row.label))] }) : skillsOpen ? _jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: "cyan", bold: true, wrap: "truncate-end", children: "SKILLS \u00B7 Ctrl+S/esc \u0111\u00F3ng \u00B7 \u2191/\u2193 ch\u1ECDn \u00B7 Enter c\u00E0i (marketplace)" }), skillRows.length === 0 ? _jsx(Text, { dimColor: true, children: "(kh\u00F4ng c\u00F3 skill)" }) : visibleSkills.map((row, i) => _jsx(Text, { wrap: "truncate-end", ...(skillTop + i === skillCursor ? { color: "cyan" } : {}), children: (skillTop + i === skillCursor ? "❯ " : " ") + row.label }, row.kind + ":" + row.id))] }) : helpOpen ? _jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: "cyan", bold: true, wrap: "truncate-end", children: "TR\u1EE2 GI\u00DAP \u00B7 esc \u0111\u00F3ng" }), TUI_SHORTCUTS.map(line => _jsx(Text, { dimColor: true, wrap: "truncate-end", children: line }, line)), TUI_COMMANDS.slice(0, Math.max(0, viewportHeight - 2 - TUI_SHORTCUTS.length)).map(command => _jsx(Text, { wrap: "truncate-end", children: " /" + command.name.padEnd(10) + command.summary }, command.name))] }) : sessionOpen ? _jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: "cyan", bold: true, wrap: "truncate-end", children: "PHI\u00CAN \u00B7 esc \u0111\u00F3ng" }), sessionRows(app).map(line => _jsx(Text, { wrap: "truncate-end", children: line }, line))] }) : effortOpen ? _jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: "cyan", bold: true, wrap: "truncate-end", children: "M\u1EE8C SUY LU\u1EACN \u00B7 esc \u0111\u00F3ng \u00B7 \u2191/\u2193 ch\u1ECDn \u00B7 Enter \u00E1p d\u1EE5ng" }), effortRows.map((choice, i) => _jsx(Text, { wrap: "truncate-end", ...(i === effortCursor ? { color: "cyan" } : {}), children: (i === effortCursor ? "❯ " : " ") + thinkingLabel(choice) }, choice)), _jsx(Text, { dimColor: true, wrap: "truncate-end", children: (typeof app.thinkingNotes === "function" ? app.thinkingNotes() : []).join(" ") })] }) : lines.length ? visibleRows.map((entry, i) => _jsx(Row, { row: entry.row, marginTop: entry.marginTop }, i)) : _jsx(Text, { dimColor: true, children: "Nh\u1EADp y\u00EAu c\u1EA7u \u0111\u1EC3 b\u1EAFt \u0111\u1EA7u. Thinking v\u00E0 c\u00F4ng c\u1EE5 s\u1EBD xu\u1EA5t hi\u1EC7n theo tr\u00ECnh t\u1EF1." }) }), _jsxs(Box, { height: 1, paddingX: 1, flexShrink: 0, children: [_jsx(Box, { flexGrow: 1, overflow: "hidden", children: pending ? _jsx(Text, { color: "yellow", wrap: "truncate-end", children: "CH\u1EDC C\u1EA4P QUY\u1EC0N \u00B7 ch\u1ECDn y ho\u1EB7c n b\u00EAn d\u01B0\u1EDBi" }) : running && status ? _jsx(AgentActivity, { label: terminalText(status) }) : _jsx(Text, { color: "yellow", wrap: "truncate-end", children: status }) }), scrollTop !== null && _jsx(Text, { dimColor: true, wrap: "truncate-end", children: `Lịch sử ${Math.min(top + 1, totalVisual)}–${Math.min(top + viewportHeight, totalVisual)}/${totalVisual}` })] }), pending && _jsxs(Box, { height: approvalHeight, flexShrink: 0, flexDirection: "column", paddingX: 1, borderStyle: compact ? undefined : "round", borderColor: "yellow", overflow: "hidden", children: [_jsx(Text, { bold: true, color: "yellow", wrap: "truncate-end", children: "Cho ph\u00E9p? [y] C\u00F3 \u00B7 [n] T\u1EEB ch\u1ED1i \u00B7 h\u1EBFt h\u1EA1n sau 5 ph\u00FAt" }), _jsx(Text, { wrap: "truncate-middle", children: toolLabel(pending.name, pending.args) })] }), menuOpen && _jsx(Box, { height: menuHeight, flexShrink: 0, flexDirection: "column", paddingX: 1, overflow: "hidden", children: commandMenuOpen
|
|
512
|
+
? commands.slice(0, menuHeight).map((command, i) => _jsx(Text, { wrap: "truncate-end", ...(i === commandCursor ? { color: "cyan" } : {}), children: (i === commandCursor ? "❯ /" : " /") + command.name + " " + command.summary }, command.name))
|
|
513
|
+
: fileMatches.slice(0, menuHeight).map((file, i) => _jsx(Text, { wrap: "truncate-end", ...(i === fileCursor ? { color: "cyan" } : {}), children: (i === fileCursor ? "❯ @" : " @") + file }, file)) }), _jsxs(Box, { height: composerHeight, flexShrink: 0, borderStyle: composerHeight === 3 ? "round" : undefined, borderColor: pending ? "yellow" : "cyan", paddingX: 1, overflow: "hidden", children: [_jsx(Text, { color: "cyan", children: "\u276F " }), _jsx(FixedComposer, { width: Math.max(2, columns - (composerHeight === 3 ? 6 : 4)), row: rows - helpHeight - (composerHeight === 3 ? 2 : 1), column: composerHeight === 3 ? 4 : 3, disabled: Boolean(pending) || anyOverlay, disabledHint: pending ? "Chọn y/n để tiếp tục…" : "Bảng chọn đang mở · esc để đóng", onAction: handleComposerAction })] }), helpHeight > 0 && _jsxs(Box, { height: 1, paddingX: 1, flexShrink: 0, children: [_jsx(Box, { width: Math.max(0, columns - 2 - tokenWidth - (tokenWidth ? 1 : 0)), overflow: "hidden", children: _jsx(Text, { dimColor: true, wrap: "truncate-end", children: "Enter g\u1EEDi \u00B7 Esc d\u1EEBng \u00B7 Ctrl+C tho\u00E1t \u00B7 g\u00F5 / l\u1EC7nh ho\u1EB7c @ file \u00B7 PgUp/PgDn cu\u1ED9n" }) }), tokenText && _jsx(Box, { width: tokenWidth, marginLeft: 1, flexShrink: 0, justifyContent: "flex-end", children: _jsx(Text, { dimColor: true, wrap: "truncate-start", children: tokenText }) })] })] });
|
|
180
514
|
}
|
|
181
515
|
export function GalaxyTui({ app }) {
|
|
182
516
|
const { exit } = useApp();
|
|
@@ -185,6 +519,8 @@ export function GalaxyTui({ app }) {
|
|
|
185
519
|
const [tokens, setTokens] = useState();
|
|
186
520
|
const [cacheHitRate, setCacheHitRate] = useState();
|
|
187
521
|
const [cumulativeCacheHitRate, setCumulativeCacheHitRate] = useState();
|
|
522
|
+
const overlayRef = useRef(false);
|
|
523
|
+
const onOverlay = useCallback((open) => { overlayRef.current = open; }, []);
|
|
188
524
|
const permission = useMemo(() => (name, args, signal) => new Promise(resolve => {
|
|
189
525
|
let settled = false;
|
|
190
526
|
const answer = (allow) => { if (settled)
|
|
@@ -199,7 +535,7 @@ export function GalaxyTui({ app }) {
|
|
|
199
535
|
}), []);
|
|
200
536
|
const adapter = useMemo(() => createCoreChatAdapter(app, event => {
|
|
201
537
|
if (event.type === "state")
|
|
202
|
-
setStatus({ inspecting: "Inspecting", planning: "Planning", executing: "Running tools", preparing: "Preparing", completed: "", failed: "Có lỗi", cancelled: "
|
|
538
|
+
setStatus({ inspecting: "Inspecting", planning: "Planning", executing: "Running tools", preparing: "Preparing", completed: "", failed: "Có lỗi", cancelled: "", paused: "Đã tạm dừng", reviewing: "Review", validating: "Validating", compacting: "Compacting", resuming: "Resuming", waiting_approval: "Waiting for approval" }[event.transition.to] ?? "Thinking");
|
|
203
539
|
if (event.type === "model" && ["started", "thinking"].includes(event.event.type))
|
|
204
540
|
setStatus("Thinking");
|
|
205
541
|
if (event.type === "model" && event.event.type === "content")
|
|
@@ -216,7 +552,7 @@ export function GalaxyTui({ app }) {
|
|
|
216
552
|
}
|
|
217
553
|
if (event.type === "model_retry")
|
|
218
554
|
setStatus(`Retrying (${event.attempt})`);
|
|
219
|
-
}, permission, () => { setStatus("Connecting"); setTokens(undefined); setCacheHitRate(undefined); setCumulativeCacheHitRate(undefined); }, state => setStatus({ completed: "", failed: "Có lỗi", cancelled: "
|
|
555
|
+
}, permission, () => { setStatus("Connecting"); setTokens(undefined); setCacheHitRate(undefined); setCumulativeCacheHitRate(undefined); }, state => setStatus({ completed: "", failed: "Có lỗi", cancelled: "", paused: "Đã tạm dừng" }[state] ?? state)), [app, permission]);
|
|
220
556
|
const initialMessages = useMemo(() => app.sessions.history(app.session).map(m => ({ role: m.role === "user" ? "user" : "assistant", content: m.content })), [app]);
|
|
221
557
|
const runtime = useLocalRuntime(adapter, { maxSteps: 1, initialMessages });
|
|
222
558
|
useEffect(() => () => runtime.thread.cancelRun(), [runtime]);
|
|
@@ -227,14 +563,18 @@ export function GalaxyTui({ app }) {
|
|
|
227
563
|
exit();
|
|
228
564
|
}
|
|
229
565
|
else if (key.escape) {
|
|
566
|
+
// An open picker owns Escape; otherwise stop the run and show the idle
|
|
567
|
+
// screen again instead of a "Đã huỷ" badge that stays behind.
|
|
568
|
+
if (overlayRef.current)
|
|
569
|
+
return;
|
|
230
570
|
pending?.answer(false);
|
|
231
571
|
runtime.thread.cancelRun();
|
|
232
|
-
setStatus("
|
|
572
|
+
setStatus("");
|
|
233
573
|
}
|
|
234
574
|
else if (pending && ["y", "n"].includes(input.toLowerCase()))
|
|
235
575
|
pending.answer(input.toLowerCase() === "y");
|
|
236
576
|
});
|
|
237
|
-
return _jsx(AssistantRuntimeProvider, { runtime: runtime, children: _jsx(Screen, { app: app, status: status, pending: pending, tokens: tokens, cacheHitRate: cacheHitRate, cumulativeCacheHitRate: cumulativeCacheHitRate }) });
|
|
577
|
+
return _jsx(AssistantRuntimeProvider, { runtime: runtime, children: _jsx(Screen, { app: app, status: status, pending: pending, tokens: tokens, cacheHitRate: cacheHitRate, cumulativeCacheHitRate: cumulativeCacheHitRate, onNotice: setStatus, onQuit: exit, onOverlay: onOverlay }) });
|
|
238
578
|
}
|
|
239
579
|
export async function startTui(app) {
|
|
240
580
|
const fullscreen = process.stdout.isTTY;
|