cvc-tui 0.1.0 → 0.4.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/dist/app/completion.js +4 -0
- package/dist/app/createGatewayEventHandler.js +508 -0
- package/dist/app/createSlashHandler.js +101 -0
- package/dist/app/delegationStore.js +51 -0
- package/dist/app/gatewayContext.js +17 -0
- package/dist/app/historyStore.js +4 -0
- package/dist/app/inputBuffer.js +4 -0
- package/dist/app/inputSelectionStore.js +8 -0
- package/dist/app/inputStore.js +4 -0
- package/dist/app/interfaces.js +6 -0
- package/dist/app/overlayStore.js +40 -0
- package/dist/app/promptStore.js +4 -0
- package/dist/app/queueStore.js +4 -0
- package/dist/app/scroll.js +44 -0
- package/dist/app/setupHandoff.js +28 -0
- package/dist/app/slash/commands/core.js +421 -234
- package/dist/app/slash/commands/debug.js +39 -6
- package/dist/app/slash/commands/ops.js +471 -136
- package/dist/app/slash/commands/session.js +405 -65
- package/dist/app/slash/commands/setup.js +16 -43
- package/dist/app/slash/commands/toggles.js +4 -0
- package/dist/app/slash/registry.js +7 -68
- package/dist/app/slash/types.js +1 -16
- package/dist/app/spawnHistoryStore.js +105 -0
- package/dist/app/turnController.js +650 -0
- package/dist/app/turnStore.js +47 -59
- package/dist/app/uiStore.js +34 -29
- package/dist/app/useComposerState.js +265 -0
- package/dist/app/useConfigSync.js +144 -0
- package/dist/app/useInputHandlers.js +403 -0
- package/dist/app/useLongRunToolCharms.js +50 -0
- package/dist/app/useMainApp.js +629 -0
- package/dist/app/useSessionLifecycle.js +175 -0
- package/dist/app/useSubmission.js +287 -0
- package/dist/app.js +13 -217
- package/dist/banner.js +40 -3
- package/dist/components/agentsOverlay.js +474 -0
- package/dist/components/appChrome.js +252 -0
- package/dist/components/appLayout.js +121 -22
- package/dist/components/appOverlays.js +65 -0
- package/dist/components/branding.js +97 -6
- package/dist/components/fpsOverlay.js +22 -0
- package/dist/components/helpHint.js +21 -0
- package/dist/components/markdown.js +501 -0
- package/dist/components/maskedPrompt.js +12 -0
- package/dist/components/messageLine.js +82 -0
- package/dist/components/modelPicker.js +254 -0
- package/dist/components/overlayControls.js +30 -0
- package/dist/components/overlays/helpOverlay.js +1 -0
- package/dist/components/overlays/historySearch.js +1 -0
- package/dist/components/overlays/modelPicker.js +2 -1
- package/dist/components/overlays/overlayUtils.js +2 -1
- package/dist/components/overlays/secretPrompt.js +1 -0
- package/dist/components/overlays/sessionPicker.js +1 -0
- package/dist/components/overlays/skillsHub.js +1 -0
- package/dist/components/prompts.js +95 -0
- package/dist/components/queuedMessages.js +24 -0
- package/dist/components/sessionPicker.js +130 -0
- package/dist/components/skillsHub.js +165 -0
- package/dist/components/streamingAssistant.js +35 -0
- package/dist/components/streamingMarkdown.js +110 -186
- package/dist/components/textInput.js +748 -218
- package/dist/components/themed.js +12 -0
- package/dist/components/thinking.js +493 -36
- package/dist/components/todoPanel.js +40 -0
- package/dist/config/env.js +18 -0
- package/dist/config/limits.js +22 -0
- package/dist/config/timing.js +4 -0
- package/dist/content/charms.js +5 -0
- package/dist/content/faces.js +21 -0
- package/dist/content/fortunes.js +29 -0
- package/dist/content/hotkeys.js +38 -0
- package/dist/content/placeholders.js +15 -0
- package/dist/content/setup.js +14 -0
- package/dist/content/verbs.js +41 -0
- package/dist/domain/details.js +53 -0
- package/dist/domain/messages.js +63 -0
- package/dist/domain/paths.js +16 -0
- package/dist/domain/providers.js +11 -0
- package/dist/domain/roles.js +6 -0
- package/dist/domain/slash.js +11 -0
- package/dist/domain/usage.js +1 -0
- package/dist/domain/viewport.js +33 -0
- package/dist/entry.js +65 -40
- package/dist/gatewayClient.js +574 -0
- package/dist/gatewayTypes.js +1 -0
- package/dist/hooks/useCompletion.js +86 -0
- package/dist/hooks/useGitBranch.js +58 -0
- package/dist/hooks/useInputHistory.js +12 -0
- package/dist/hooks/useQueue.js +57 -0
- package/dist/hooks/useVirtualHistory.js +401 -0
- package/dist/lib/circularBuffer.js +43 -0
- package/dist/lib/clipboard.js +126 -0
- package/dist/lib/editor.js +41 -0
- package/dist/lib/editor.test.js +58 -0
- package/dist/lib/emoji.js +49 -0
- package/dist/lib/externalCli.js +11 -0
- package/dist/lib/forceTruecolor.js +26 -0
- package/dist/lib/fpsStore.js +36 -0
- package/dist/lib/gracefulExit.js +29 -0
- package/dist/lib/history.js +69 -0
- package/dist/lib/inputMetrics.js +143 -0
- package/dist/lib/liveProgress.js +51 -0
- package/dist/lib/liveProgress.test.js +89 -0
- package/dist/lib/mathUnicode.js +685 -0
- package/dist/lib/memory.js +123 -0
- package/dist/lib/memoryMonitor.js +76 -0
- package/dist/lib/messages.js +3 -0
- package/dist/lib/messages.test.js +25 -0
- package/dist/lib/osc52.js +53 -0
- package/dist/lib/perfPane.js +94 -0
- package/dist/lib/platform.js +312 -0
- package/dist/lib/precisionWheel.js +25 -0
- package/dist/lib/reasoning.js +39 -0
- package/dist/lib/rpc.js +26 -0
- package/dist/lib/subagentTree.js +287 -0
- package/dist/lib/syntax.js +89 -0
- package/dist/lib/terminalModes.js +46 -0
- package/dist/lib/terminalParity.js +48 -0
- package/dist/lib/terminalSetup.js +321 -0
- package/dist/lib/text.js +203 -0
- package/dist/lib/text.test.js +18 -0
- package/dist/lib/todo.js +2 -0
- package/dist/lib/todo.test.js +22 -0
- package/dist/lib/viewportStore.js +82 -0
- package/dist/lib/virtualHeights.js +61 -0
- package/dist/lib/wheelAccel.js +143 -0
- package/dist/theme.js +398 -0
- package/dist/types.js +1 -7
- package/package.json +2 -1
package/dist/app/completion.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Ported from CVC Agent (https://github.com/NousResearch/cvc)
|
|
4
|
+
// Original Copyright (c) 2025 Nous Research. CVC adaptations (c) 2026 Jai Kumar Meena.
|
|
1
5
|
// Tab-completion logic. Pure functions where possible, with one
|
|
2
6
|
// fs-touching helper for path expansion.
|
|
3
7
|
import * as fs from 'node:fs';
|
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Ported from CVC Agent (https://github.com/NousResearch/cvc)
|
|
4
|
+
// Original Copyright (c) 2025 Nous Research. CVC adaptations (c) 2026 Jai Kumar Meena.
|
|
5
|
+
import { STARTUP_IMAGE, STARTUP_QUERY } from '../config/env.js';
|
|
6
|
+
import { STREAM_BATCH_MS } from '../config/timing.js';
|
|
7
|
+
import { SETUP_REQUIRED_TITLE, buildSetupRequiredSections } from '../content/setup.js';
|
|
8
|
+
import { rpcErrorMessage } from '../lib/rpc.js';
|
|
9
|
+
import { topLevelSubagents } from '../lib/subagentTree.js';
|
|
10
|
+
import { formatToolCall, stripAnsi } from '../lib/text.js';
|
|
11
|
+
import { fromSkin } from '../theme.js';
|
|
12
|
+
import { applyDelegationStatus, getDelegationState } from './delegationStore.js';
|
|
13
|
+
import { patchOverlayState } from './overlayStore.js';
|
|
14
|
+
import { turnController } from './turnController.js';
|
|
15
|
+
import { getUiState, patchUiState } from './uiStore.js';
|
|
16
|
+
const NO_PROVIDER_RE = /\bNo (?:LLM|inference) provider configured\b/i;
|
|
17
|
+
const statusFromBusy = () => (getUiState().busy ? 'running…' : 'ready');
|
|
18
|
+
const applySkin = (s) => patchUiState({
|
|
19
|
+
theme: fromSkin(s.colors ?? {}, s.branding ?? {}, s.banner_logo ?? '', s.banner_hero ?? '', s.tool_prefix ?? '', s.help_header ?? '')
|
|
20
|
+
});
|
|
21
|
+
const dropBgTask = (taskId) => patchUiState(state => {
|
|
22
|
+
const next = new Set(state.bgTasks);
|
|
23
|
+
next.delete(taskId);
|
|
24
|
+
return { ...state, bgTasks: next };
|
|
25
|
+
});
|
|
26
|
+
const pushUnique = (max) => (xs, x) => xs.at(-1) === x ? xs : [...xs, x].slice(-max);
|
|
27
|
+
const pushThinking = pushUnique(6);
|
|
28
|
+
const pushNote = pushUnique(6);
|
|
29
|
+
const pushTool = pushUnique(8);
|
|
30
|
+
export function createGatewayEventHandler(ctx) {
|
|
31
|
+
const { rpc } = ctx.gateway;
|
|
32
|
+
const { STARTUP_RESUME_ID, newSession, resumeById, setCatalog } = ctx.session;
|
|
33
|
+
const { bellOnComplete, stdout, sys } = ctx.system;
|
|
34
|
+
const { appendMessage, panel, setHistoryItems } = ctx.transcript;
|
|
35
|
+
const { setInput } = ctx.composer;
|
|
36
|
+
const { submitRef } = ctx.submission;
|
|
37
|
+
const { setProcessing: setVoiceProcessing, setRecording: setVoiceRecording, setVoiceEnabled } = ctx.voice;
|
|
38
|
+
let pendingThinkingStatus = '';
|
|
39
|
+
let thinkingStatusTimer = null;
|
|
40
|
+
let startupPromptSubmitted = false;
|
|
41
|
+
// Inject the disk-save callback into turnController so recordMessageComplete
|
|
42
|
+
// can fire-and-forget a persist without having to plumb a gateway ref around.
|
|
43
|
+
turnController.persistSpawnTree = async (subagents, sessionId) => {
|
|
44
|
+
try {
|
|
45
|
+
const startedAt = subagents.reduce((min, s) => {
|
|
46
|
+
if (!s.startedAt) {
|
|
47
|
+
return min;
|
|
48
|
+
}
|
|
49
|
+
return min === 0 ? s.startedAt : Math.min(min, s.startedAt);
|
|
50
|
+
}, 0);
|
|
51
|
+
const top = topLevelSubagents(subagents)
|
|
52
|
+
.map(s => s.goal)
|
|
53
|
+
.filter(Boolean)
|
|
54
|
+
.slice(0, 2);
|
|
55
|
+
const label = top.length ? top.join(' · ') : `${subagents.length} subagents`;
|
|
56
|
+
await rpc('spawn_tree.save', {
|
|
57
|
+
finished_at: Date.now() / 1000,
|
|
58
|
+
label: label.slice(0, 120),
|
|
59
|
+
session_id: sessionId ?? 'default',
|
|
60
|
+
started_at: startedAt ? startedAt / 1000 : null,
|
|
61
|
+
subagents
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// Persistence is best-effort; in-memory history is the authoritative
|
|
66
|
+
// same-session source. A write failure doesn't block the turn.
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
// Refresh delegation caps at most every 5s so the status bar HUD can
|
|
70
|
+
// render a /warning close to the configured cap without spamming the RPC.
|
|
71
|
+
let lastDelegationFetchAt = 0;
|
|
72
|
+
const refreshDelegationStatus = (force = false) => {
|
|
73
|
+
const now = Date.now();
|
|
74
|
+
if (!force && now - lastDelegationFetchAt < 5000) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
lastDelegationFetchAt = now;
|
|
78
|
+
rpc('delegation.status', {})
|
|
79
|
+
.then(r => applyDelegationStatus(r))
|
|
80
|
+
.catch(() => { });
|
|
81
|
+
};
|
|
82
|
+
const setStatus = (status) => {
|
|
83
|
+
pendingThinkingStatus = '';
|
|
84
|
+
if (thinkingStatusTimer) {
|
|
85
|
+
clearTimeout(thinkingStatusTimer);
|
|
86
|
+
thinkingStatusTimer = null;
|
|
87
|
+
}
|
|
88
|
+
patchUiState({ status });
|
|
89
|
+
};
|
|
90
|
+
const scheduleThinkingStatus = (status) => {
|
|
91
|
+
pendingThinkingStatus = status;
|
|
92
|
+
if (thinkingStatusTimer) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
thinkingStatusTimer = setTimeout(() => {
|
|
96
|
+
thinkingStatusTimer = null;
|
|
97
|
+
patchUiState({ status: pendingThinkingStatus || statusFromBusy() });
|
|
98
|
+
}, STREAM_BATCH_MS);
|
|
99
|
+
};
|
|
100
|
+
const restoreStatusAfter = (ms) => {
|
|
101
|
+
turnController.clearStatusTimer();
|
|
102
|
+
turnController.statusTimer = setTimeout(() => {
|
|
103
|
+
turnController.statusTimer = null;
|
|
104
|
+
patchUiState({ status: statusFromBusy() });
|
|
105
|
+
}, ms);
|
|
106
|
+
};
|
|
107
|
+
const scheduleStartupPrompt = () => {
|
|
108
|
+
if (startupPromptSubmitted || (!STARTUP_QUERY && !STARTUP_IMAGE)) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
startupPromptSubmitted = true;
|
|
112
|
+
setTimeout(async () => {
|
|
113
|
+
let sid = getUiState().sid;
|
|
114
|
+
for (let i = 0; !sid && i < 40; i += 1) {
|
|
115
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
116
|
+
sid = getUiState().sid;
|
|
117
|
+
}
|
|
118
|
+
if (!sid) {
|
|
119
|
+
return sys('startup query skipped: no active session');
|
|
120
|
+
}
|
|
121
|
+
if (STARTUP_IMAGE) {
|
|
122
|
+
try {
|
|
123
|
+
await rpc('image.attach', { path: STARTUP_IMAGE, session_id: sid });
|
|
124
|
+
}
|
|
125
|
+
catch (e) {
|
|
126
|
+
sys(`startup image attach failed: ${rpcErrorMessage(e)}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
submitRef.current(STARTUP_QUERY || 'What do you see in this image?');
|
|
130
|
+
}, 0);
|
|
131
|
+
};
|
|
132
|
+
// Terminal statuses are never overwritten by late-arriving live events —
|
|
133
|
+
// otherwise a stale `subagent.start` / `spawn_requested` can clobber a
|
|
134
|
+
// `failed` or `interrupted` terminal state (Copilot review #14045).
|
|
135
|
+
const isTerminalStatus = (s) => s === 'completed' || s === 'failed' || s === 'interrupted';
|
|
136
|
+
const keepTerminalElseRunning = (s) => (isTerminalStatus(s) ? s : 'running');
|
|
137
|
+
const handleReady = (skin) => {
|
|
138
|
+
if (skin) {
|
|
139
|
+
applySkin(skin);
|
|
140
|
+
}
|
|
141
|
+
rpc('commands.catalog', {})
|
|
142
|
+
.then(r => {
|
|
143
|
+
if (!r?.pairs) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
setCatalog({
|
|
147
|
+
canon: (r.canon ?? {}),
|
|
148
|
+
categories: r.categories ?? [],
|
|
149
|
+
pairs: r.pairs,
|
|
150
|
+
skillCount: (r.skill_count ?? 0),
|
|
151
|
+
sub: (r.sub ?? {})
|
|
152
|
+
});
|
|
153
|
+
if (r.warning) {
|
|
154
|
+
turnController.pushActivity(String(r.warning), 'warn');
|
|
155
|
+
}
|
|
156
|
+
})
|
|
157
|
+
.catch((e) => turnController.pushActivity(`command catalog unavailable: ${rpcErrorMessage(e)}`, 'info'));
|
|
158
|
+
if (STARTUP_RESUME_ID) {
|
|
159
|
+
patchUiState({ status: 'resuming…' });
|
|
160
|
+
resumeById(STARTUP_RESUME_ID);
|
|
161
|
+
scheduleStartupPrompt();
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
// Opt-in: when `display.tui_auto_resume_recent` is true, look up
|
|
165
|
+
// the most recent human-facing session and resume it instead of
|
|
166
|
+
// forging a brand-new one. Mirrors classic CLI's `hermes -c` /
|
|
167
|
+
// `hermes --tui` muscle memory and addresses the audit's "session
|
|
168
|
+
// unrecoverable after disconnection" gap. Default off so existing
|
|
169
|
+
// users aren't surprised.
|
|
170
|
+
rpc('config.get', { key: 'full' })
|
|
171
|
+
.then(cfg => {
|
|
172
|
+
if (!cfg?.config?.display?.tui_auto_resume_recent) {
|
|
173
|
+
patchUiState({ status: 'forging session…' });
|
|
174
|
+
newSession();
|
|
175
|
+
scheduleStartupPrompt();
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
return rpc('session.most_recent', {}).then(r => {
|
|
179
|
+
const target = r?.session_id;
|
|
180
|
+
if (target) {
|
|
181
|
+
patchUiState({ status: 'resuming most recent…' });
|
|
182
|
+
resumeById(target);
|
|
183
|
+
scheduleStartupPrompt();
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
patchUiState({ status: 'forging session…' });
|
|
187
|
+
newSession();
|
|
188
|
+
scheduleStartupPrompt();
|
|
189
|
+
});
|
|
190
|
+
})
|
|
191
|
+
.catch(() => {
|
|
192
|
+
patchUiState({ status: 'forging session…' });
|
|
193
|
+
newSession();
|
|
194
|
+
scheduleStartupPrompt();
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
return (ev) => {
|
|
198
|
+
const sid = getUiState().sid;
|
|
199
|
+
if (ev.session_id && sid && ev.session_id !== sid && !ev.type.startsWith('gateway.')) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
switch (ev.type) {
|
|
203
|
+
case 'gateway.ready':
|
|
204
|
+
handleReady(ev.payload?.skin);
|
|
205
|
+
return;
|
|
206
|
+
case 'skin.changed':
|
|
207
|
+
if (ev.payload) {
|
|
208
|
+
applySkin(ev.payload);
|
|
209
|
+
}
|
|
210
|
+
return;
|
|
211
|
+
case 'session.info': {
|
|
212
|
+
const info = ev.payload;
|
|
213
|
+
patchUiState(state => ({
|
|
214
|
+
...state,
|
|
215
|
+
info,
|
|
216
|
+
status: state.status === 'starting agent…' ? 'ready' : state.status,
|
|
217
|
+
usage: info.usage ? { ...state.usage, ...info.usage } : state.usage
|
|
218
|
+
}));
|
|
219
|
+
setHistoryItems(prev => prev.map(m => (m.kind === 'intro' ? { ...m, info } : m)));
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
case 'thinking.delta': {
|
|
223
|
+
const text = ev.payload?.text;
|
|
224
|
+
if (text !== undefined) {
|
|
225
|
+
const value = String(text);
|
|
226
|
+
scheduleThinkingStatus(value || statusFromBusy());
|
|
227
|
+
if (value) {
|
|
228
|
+
turnController.recordReasoningDelta(value);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
case 'message.start':
|
|
234
|
+
turnController.startMessage();
|
|
235
|
+
return;
|
|
236
|
+
case 'status.update': {
|
|
237
|
+
const p = ev.payload;
|
|
238
|
+
if (!p?.text) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
setStatus(p.text);
|
|
242
|
+
if (p.kind === 'compressing') {
|
|
243
|
+
sys(p.text);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (p.kind === 'goal') {
|
|
247
|
+
sys(p.text);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
if (!p.kind || p.kind === 'status') {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if (turnController.lastStatusNote !== p.text) {
|
|
254
|
+
turnController.lastStatusNote = p.text;
|
|
255
|
+
turnController.pushActivity(p.text, p.kind === 'error' ? 'error' : p.kind === 'warn' || p.kind === 'approval' ? 'warn' : 'info');
|
|
256
|
+
}
|
|
257
|
+
restoreStatusAfter(4000);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
case 'gateway.stderr': {
|
|
261
|
+
const line = String(ev.payload.line).slice(0, 120);
|
|
262
|
+
turnController.pushActivity(line, 'info');
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
case 'browser.progress': {
|
|
266
|
+
const message = String(ev.payload?.message ?? '').trim();
|
|
267
|
+
if (message) {
|
|
268
|
+
sys(message);
|
|
269
|
+
}
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
case 'voice.status': {
|
|
273
|
+
// Continuous VAD loop reports its internal state so the status bar
|
|
274
|
+
// can show listening / transcribing / idle without polling.
|
|
275
|
+
const state = String(ev.payload?.state ?? '');
|
|
276
|
+
if (state === 'listening') {
|
|
277
|
+
setVoiceRecording(true);
|
|
278
|
+
setVoiceProcessing(false);
|
|
279
|
+
}
|
|
280
|
+
else if (state === 'transcribing') {
|
|
281
|
+
setVoiceRecording(false);
|
|
282
|
+
setVoiceProcessing(true);
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
setVoiceRecording(false);
|
|
286
|
+
setVoiceProcessing(false);
|
|
287
|
+
}
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
case 'voice.transcript': {
|
|
291
|
+
// CLI parity: the 3-strikes silence detector flipped off automatically.
|
|
292
|
+
// Mirror that on the UI side and tell the user why the mode is off.
|
|
293
|
+
if (ev.payload?.no_speech_limit) {
|
|
294
|
+
setVoiceEnabled(false);
|
|
295
|
+
setVoiceRecording(false);
|
|
296
|
+
setVoiceProcessing(false);
|
|
297
|
+
sys('voice: no speech detected 3 times, continuous mode stopped');
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
const text = String(ev.payload?.text ?? '').trim();
|
|
301
|
+
if (!text) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
// CLI parity: _pending_input.put(transcript) unconditionally feeds
|
|
305
|
+
// the transcript to the agent as its next turn — draft handling
|
|
306
|
+
// doesn't apply because voice-mode users are speaking, not typing.
|
|
307
|
+
//
|
|
308
|
+
// We can't branch on composer input from inside a setInput updater
|
|
309
|
+
// (React strict mode double-invokes it, duplicating the submit).
|
|
310
|
+
// Just clear + defer submit so the cleared input is committed before
|
|
311
|
+
// submit reads it.
|
|
312
|
+
setInput('');
|
|
313
|
+
setTimeout(() => submitRef.current(text), 0);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
case 'gateway.start_timeout': {
|
|
317
|
+
const { cwd, python, stderr_tail: stderrTail } = ev.payload ?? {};
|
|
318
|
+
const trace = python || cwd ? ` · ${String(python || '')} ${String(cwd || '')}`.trim() : '';
|
|
319
|
+
setStatus('gateway startup timeout');
|
|
320
|
+
turnController.pushActivity(`gateway startup timed out${trace} · /logs to inspect`, 'error');
|
|
321
|
+
// Surface the most useful stderr lines inline so users can tell
|
|
322
|
+
// "wrong python", "missing dep", and "config parse failure"
|
|
323
|
+
// apart without leaving the TUI. Filter blank rows BEFORE
|
|
324
|
+
// taking the last N so trailing empty lines in the buffer
|
|
325
|
+
// don't crowd out actual content; truncate to match the
|
|
326
|
+
// 120-char clip used for `gateway.stderr` activity entries.
|
|
327
|
+
const STDERR_LINE_CAP = 120;
|
|
328
|
+
const STDERR_LINES_MAX = 8;
|
|
329
|
+
const tailLines = (stderrTail ?? '')
|
|
330
|
+
.split('\n')
|
|
331
|
+
.map(l => l.trim())
|
|
332
|
+
.filter(Boolean)
|
|
333
|
+
.slice(-STDERR_LINES_MAX);
|
|
334
|
+
for (const line of tailLines) {
|
|
335
|
+
turnController.pushActivity(line.slice(0, STDERR_LINE_CAP), 'error');
|
|
336
|
+
}
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
case 'gateway.protocol_error':
|
|
340
|
+
setStatus('protocol warning');
|
|
341
|
+
restoreStatusAfter(4000);
|
|
342
|
+
if (!turnController.protocolWarned) {
|
|
343
|
+
turnController.protocolWarned = true;
|
|
344
|
+
turnController.pushActivity('protocol noise detected · /logs to inspect', 'info');
|
|
345
|
+
}
|
|
346
|
+
if (ev.payload?.preview) {
|
|
347
|
+
turnController.pushActivity(`protocol noise: ${String(ev.payload.preview).slice(0, 120)}`, 'info');
|
|
348
|
+
}
|
|
349
|
+
return;
|
|
350
|
+
case 'reasoning.delta':
|
|
351
|
+
if (ev.payload?.text) {
|
|
352
|
+
turnController.recordReasoningDelta(ev.payload.text);
|
|
353
|
+
}
|
|
354
|
+
return;
|
|
355
|
+
case 'reasoning.available':
|
|
356
|
+
turnController.recordReasoningAvailable(String(ev.payload?.text ?? ''));
|
|
357
|
+
return;
|
|
358
|
+
case 'tool.progress':
|
|
359
|
+
if (ev.payload?.preview && ev.payload.name) {
|
|
360
|
+
turnController.recordToolProgress(ev.payload.name, ev.payload.preview);
|
|
361
|
+
}
|
|
362
|
+
return;
|
|
363
|
+
case 'tool.generating':
|
|
364
|
+
if (ev.payload?.name) {
|
|
365
|
+
turnController.pushTrail(`drafting ${ev.payload.name}…`);
|
|
366
|
+
}
|
|
367
|
+
return;
|
|
368
|
+
case 'tool.start':
|
|
369
|
+
turnController.recordTodos(ev.payload.todos);
|
|
370
|
+
turnController.recordToolStart(ev.payload.tool_id, ev.payload.name ?? 'tool', ev.payload.context ?? '');
|
|
371
|
+
return;
|
|
372
|
+
case 'tool.complete': {
|
|
373
|
+
const inlineDiffText = ev.payload.inline_diff && getUiState().inlineDiffs ? stripAnsi(String(ev.payload.inline_diff)).trim() : '';
|
|
374
|
+
if (inlineDiffText) {
|
|
375
|
+
turnController.recordInlineDiffToolComplete(inlineDiffText, ev.payload.tool_id, ev.payload.name, ev.payload.error, ev.payload.duration_s);
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
turnController.recordToolComplete(ev.payload.tool_id, ev.payload.name, ev.payload.error, ev.payload.summary, ev.payload.duration_s, ev.payload.todos);
|
|
379
|
+
}
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
case 'clarify.request':
|
|
383
|
+
patchOverlayState({
|
|
384
|
+
clarify: { choices: ev.payload.choices, question: ev.payload.question, requestId: ev.payload.request_id }
|
|
385
|
+
});
|
|
386
|
+
setStatus('waiting for input…');
|
|
387
|
+
return;
|
|
388
|
+
case 'approval.request': {
|
|
389
|
+
const description = String(ev.payload.description ?? 'dangerous command');
|
|
390
|
+
patchOverlayState({ approval: { command: String(ev.payload.command ?? ''), description } });
|
|
391
|
+
setStatus('approval needed');
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
case 'sudo.request':
|
|
395
|
+
patchOverlayState({ sudo: { requestId: ev.payload.request_id } });
|
|
396
|
+
setStatus('sudo password needed');
|
|
397
|
+
return;
|
|
398
|
+
case 'secret.request':
|
|
399
|
+
patchOverlayState({
|
|
400
|
+
secret: { envVar: ev.payload.env_var, prompt: ev.payload.prompt, requestId: ev.payload.request_id }
|
|
401
|
+
});
|
|
402
|
+
setStatus('secret input needed');
|
|
403
|
+
return;
|
|
404
|
+
case 'background.complete':
|
|
405
|
+
dropBgTask(ev.payload.task_id);
|
|
406
|
+
sys(`[bg ${ev.payload.task_id}] ${ev.payload.text}`);
|
|
407
|
+
return;
|
|
408
|
+
case 'review.summary': {
|
|
409
|
+
// Self-improvement background review emitted a persistent summary
|
|
410
|
+
// of what it saved to memory/skills. Surface it as a system line
|
|
411
|
+
// in the transcript so it never gets lost to a transient status
|
|
412
|
+
// flash. Python-side already formats it as "💾 Self-improvement
|
|
413
|
+
// review: …".
|
|
414
|
+
const text = String(ev.payload?.text ?? '').trim();
|
|
415
|
+
if (text) {
|
|
416
|
+
sys(text);
|
|
417
|
+
}
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
case 'subagent.spawn_requested':
|
|
421
|
+
// Child built but not yet running (waiting on ThreadPoolExecutor slot).
|
|
422
|
+
// Preserve completed state if a later event races in before this one.
|
|
423
|
+
turnController.upsertSubagent(ev.payload, c => (isTerminalStatus(c.status) ? {} : { status: 'queued' }));
|
|
424
|
+
// Prime the status-bar HUD: fetch caps (once every 5s) so we can
|
|
425
|
+
// warn as depth/concurrency approaches the configured ceiling.
|
|
426
|
+
if (getDelegationState().maxSpawnDepth === null) {
|
|
427
|
+
refreshDelegationStatus(true);
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
refreshDelegationStatus();
|
|
431
|
+
}
|
|
432
|
+
return;
|
|
433
|
+
case 'subagent.start':
|
|
434
|
+
turnController.upsertSubagent(ev.payload, c => (isTerminalStatus(c.status) ? {} : { status: 'running' }));
|
|
435
|
+
return;
|
|
436
|
+
case 'subagent.thinking': {
|
|
437
|
+
const text = String(ev.payload.text ?? '').trim();
|
|
438
|
+
if (!text) {
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
// Update-only: never resurrect subagents whose spawn_requested/start
|
|
442
|
+
// we missed or that already flushed via message.complete.
|
|
443
|
+
turnController.upsertSubagent(ev.payload, c => ({
|
|
444
|
+
status: keepTerminalElseRunning(c.status),
|
|
445
|
+
thinking: pushThinking(c.thinking, text)
|
|
446
|
+
}), { createIfMissing: false });
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
case 'subagent.tool': {
|
|
450
|
+
const line = formatToolCall(ev.payload.tool_name ?? 'delegate_task', ev.payload.tool_preview ?? ev.payload.text ?? '');
|
|
451
|
+
turnController.upsertSubagent(ev.payload, c => ({
|
|
452
|
+
status: keepTerminalElseRunning(c.status),
|
|
453
|
+
tools: pushTool(c.tools, line)
|
|
454
|
+
}), { createIfMissing: false });
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
case 'subagent.progress': {
|
|
458
|
+
const text = String(ev.payload.text ?? '').trim();
|
|
459
|
+
if (!text) {
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
turnController.upsertSubagent(ev.payload, c => ({
|
|
463
|
+
notes: pushNote(c.notes, text),
|
|
464
|
+
status: keepTerminalElseRunning(c.status)
|
|
465
|
+
}), { createIfMissing: false });
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
case 'subagent.complete':
|
|
469
|
+
turnController.upsertSubagent(ev.payload, c => ({
|
|
470
|
+
durationSeconds: ev.payload.duration_seconds ?? c.durationSeconds,
|
|
471
|
+
status: ev.payload.status ?? 'completed',
|
|
472
|
+
summary: ev.payload.summary || ev.payload.text || c.summary
|
|
473
|
+
}), { createIfMissing: false });
|
|
474
|
+
return;
|
|
475
|
+
case 'message.delta':
|
|
476
|
+
turnController.recordMessageDelta(ev.payload ?? {});
|
|
477
|
+
return;
|
|
478
|
+
case 'message.complete': {
|
|
479
|
+
const { finalMessages, finalText, wasInterrupted } = turnController.recordMessageComplete(ev.payload ?? {});
|
|
480
|
+
if (!wasInterrupted) {
|
|
481
|
+
const msgs = finalMessages.length ? finalMessages : [{ role: 'assistant', text: finalText }];
|
|
482
|
+
msgs.forEach(appendMessage);
|
|
483
|
+
if (bellOnComplete && stdout?.isTTY) {
|
|
484
|
+
stdout.write('\x07');
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
setStatus('ready');
|
|
488
|
+
if (ev.payload?.usage) {
|
|
489
|
+
patchUiState(state => ({ ...state, usage: { ...state.usage, ...ev.payload.usage } }));
|
|
490
|
+
}
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
case 'error':
|
|
494
|
+
turnController.recordError();
|
|
495
|
+
{
|
|
496
|
+
const message = String(ev.payload?.message || 'unknown error');
|
|
497
|
+
turnController.pushActivity(message, 'error');
|
|
498
|
+
if (NO_PROVIDER_RE.test(message)) {
|
|
499
|
+
panel(SETUP_REQUIRED_TITLE, buildSetupRequiredSections());
|
|
500
|
+
setStatus('setup required');
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
sys(`error: ${message}`);
|
|
504
|
+
setStatus('ready');
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Ported from CVC Agent (https://github.com/NousResearch/cvc)
|
|
4
|
+
// Original Copyright (c) 2025 Nous Research. CVC adaptations (c) 2026 Jai Kumar Meena.
|
|
5
|
+
import { parseSlashCommand } from '../domain/slash.js';
|
|
6
|
+
import { asCommandDispatch, rpcErrorMessage } from '../lib/rpc.js';
|
|
7
|
+
import { findSlashCommand } from './slash/registry.js';
|
|
8
|
+
import { getUiState } from './uiStore.js';
|
|
9
|
+
export function createSlashHandler(ctx) {
|
|
10
|
+
const { gw } = ctx.gateway;
|
|
11
|
+
const { catalog } = ctx.local;
|
|
12
|
+
const { page, send, sys } = ctx.transcript;
|
|
13
|
+
const handler = (cmd) => {
|
|
14
|
+
const flight = ++ctx.slashFlightRef.current;
|
|
15
|
+
const ui = getUiState();
|
|
16
|
+
const sid = ui.sid;
|
|
17
|
+
const parsed = parseSlashCommand(cmd);
|
|
18
|
+
const argTail = parsed.arg ? ` ${parsed.arg}` : '';
|
|
19
|
+
const stale = () => flight !== ctx.slashFlightRef.current || getUiState().sid !== sid;
|
|
20
|
+
const guarded = (fn) => (r) => {
|
|
21
|
+
if (!stale() && r) {
|
|
22
|
+
fn(r);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const guardedErr = (e) => {
|
|
26
|
+
if (!stale()) {
|
|
27
|
+
sys(`error: ${rpcErrorMessage(e)}`);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const runCtx = { ...ctx, flight, guarded, guardedErr, sid, stale, ui };
|
|
31
|
+
const found = findSlashCommand(parsed.name);
|
|
32
|
+
if (found) {
|
|
33
|
+
found.run(parsed.arg, runCtx, cmd);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
if (catalog?.canon) {
|
|
37
|
+
const needle = `/${parsed.name}`.toLowerCase();
|
|
38
|
+
const exact = Object.entries(catalog.canon).find(([alias]) => alias.toLowerCase() === needle)?.[1];
|
|
39
|
+
if (exact) {
|
|
40
|
+
if (exact.toLowerCase() !== needle) {
|
|
41
|
+
return handler(`${exact}${argTail}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
const matches = [
|
|
46
|
+
...new Set(Object.entries(catalog.canon)
|
|
47
|
+
.filter(([alias]) => alias.startsWith(needle))
|
|
48
|
+
.map(([, canon]) => canon))
|
|
49
|
+
];
|
|
50
|
+
if (matches.length === 1 && matches[0].toLowerCase() !== needle) {
|
|
51
|
+
return handler(`${matches[0]}${argTail}`);
|
|
52
|
+
}
|
|
53
|
+
if (matches.length > 1) {
|
|
54
|
+
sys(`ambiguous command: ${matches.slice(0, 6).join(', ')}${matches.length > 6 ? ', …' : ''}`);
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
gw.request('slash.exec', { command: cmd.slice(1), session_id: sid })
|
|
60
|
+
.then(r => {
|
|
61
|
+
if (stale()) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const body = r?.output || `/${parsed.name}: no output`;
|
|
65
|
+
const text = r?.warning ? `warning: ${r.warning}\n${body}` : body;
|
|
66
|
+
const long = text.length > 180 || text.split('\n').filter(Boolean).length > 2;
|
|
67
|
+
long ? page(text, parsed.name[0].toUpperCase() + parsed.name.slice(1)) : sys(text);
|
|
68
|
+
})
|
|
69
|
+
.catch(() => {
|
|
70
|
+
gw.request('command.dispatch', { arg: parsed.arg, name: parsed.name, session_id: sid })
|
|
71
|
+
.then((raw) => {
|
|
72
|
+
if (stale()) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const d = asCommandDispatch(raw);
|
|
76
|
+
if (!d) {
|
|
77
|
+
return sys('error: invalid response: command.dispatch');
|
|
78
|
+
}
|
|
79
|
+
if (d.type === 'exec' || d.type === 'plugin') {
|
|
80
|
+
return sys(d.output || '(no output)');
|
|
81
|
+
}
|
|
82
|
+
if (d.type === 'alias') {
|
|
83
|
+
return handler(`/${d.target}${argTail}`);
|
|
84
|
+
}
|
|
85
|
+
if (d.type === 'skill') {
|
|
86
|
+
sys(`⚡ loading skill: ${d.name}`);
|
|
87
|
+
return d.message?.trim() ? send(d.message) : sys(`/${parsed.name}: skill payload missing message`);
|
|
88
|
+
}
|
|
89
|
+
if (d.type === 'send') {
|
|
90
|
+
if (d.notice?.trim()) {
|
|
91
|
+
sys(d.notice);
|
|
92
|
+
}
|
|
93
|
+
return d.message?.trim() ? send(d.message) : sys(`/${parsed.name}: empty message`);
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
.catch(guardedErr);
|
|
97
|
+
});
|
|
98
|
+
return true;
|
|
99
|
+
};
|
|
100
|
+
return handler;
|
|
101
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Ported from CVC Agent (https://github.com/NousResearch/cvc)
|
|
4
|
+
// Original Copyright (c) 2025 Nous Research. CVC adaptations (c) 2026 Jai Kumar Meena.
|
|
5
|
+
import { atom } from 'nanostores';
|
|
6
|
+
const buildState = () => ({
|
|
7
|
+
maxConcurrentChildren: null,
|
|
8
|
+
maxSpawnDepth: null,
|
|
9
|
+
paused: false,
|
|
10
|
+
updatedAt: null
|
|
11
|
+
});
|
|
12
|
+
export const $delegationState = atom(buildState());
|
|
13
|
+
export const getDelegationState = () => $delegationState.get();
|
|
14
|
+
export const patchDelegationState = (next) => $delegationState.set({ ...$delegationState.get(), ...next });
|
|
15
|
+
export const resetDelegationState = () => $delegationState.set(buildState());
|
|
16
|
+
// ── Overlay accordion open-state ──────────────────────────────────────
|
|
17
|
+
//
|
|
18
|
+
// Lifted out of OverlaySection's local useState so collapse choices
|
|
19
|
+
// survive:
|
|
20
|
+
// - navigating to a different subagent (Detail remounts)
|
|
21
|
+
// - switching list ↔ detail mode (Detail unmounts in list mode)
|
|
22
|
+
// - walking history (←/→)
|
|
23
|
+
// Keyed by section title; missing entries fall back to the section's
|
|
24
|
+
// `defaultOpen` prop.
|
|
25
|
+
export const $overlaySectionsOpen = atom({});
|
|
26
|
+
export const toggleOverlaySection = (title, defaultOpen) => {
|
|
27
|
+
const state = $overlaySectionsOpen.get();
|
|
28
|
+
const current = title in state ? state[title] : defaultOpen;
|
|
29
|
+
$overlaySectionsOpen.set({ ...state, [title]: !current });
|
|
30
|
+
};
|
|
31
|
+
export const getOverlaySectionOpen = (title, defaultOpen) => {
|
|
32
|
+
const state = $overlaySectionsOpen.get();
|
|
33
|
+
return title in state ? state[title] : defaultOpen;
|
|
34
|
+
};
|
|
35
|
+
/** Merge a raw RPC response into the store. Tolerant of partial/omitted fields. */
|
|
36
|
+
export const applyDelegationStatus = (r) => {
|
|
37
|
+
if (!r) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const patch = { updatedAt: Date.now() };
|
|
41
|
+
if (typeof r.max_spawn_depth === 'number') {
|
|
42
|
+
patch.maxSpawnDepth = r.max_spawn_depth;
|
|
43
|
+
}
|
|
44
|
+
if (typeof r.max_concurrent_children === 'number') {
|
|
45
|
+
patch.maxConcurrentChildren = r.max_concurrent_children;
|
|
46
|
+
}
|
|
47
|
+
if (typeof r.paused === 'boolean') {
|
|
48
|
+
patch.paused = r.paused;
|
|
49
|
+
}
|
|
50
|
+
patchDelegationState(patch);
|
|
51
|
+
};
|