@dirgha/code 1.20.14 → 1.20.25
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/cli/first-run.d.ts +6 -5
- package/dist/cli/first-run.js +79 -37
- package/dist/cli/first-run.js.map +1 -1
- package/dist/cli/flows/wizard.js +1 -1
- package/dist/cli/flows/wizard.js.map +1 -1
- package/dist/cli/interactive.js +25 -9
- package/dist/cli/interactive.js.map +1 -1
- package/dist/cli/main.js +8 -1
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/setup.js +4 -2
- package/dist/cli/setup.js.map +1 -1
- package/dist/cli/slash/keys.js +50 -1
- package/dist/cli/slash/keys.js.map +1 -1
- package/dist/cli/slash/login.js +8 -1
- package/dist/cli/slash/login.js.map +1 -1
- package/dist/cli/slash/models.d.ts +1 -1
- package/dist/cli/slash/models.js +142 -18
- package/dist/cli/slash/models.js.map +1 -1
- package/dist/cli/slash/provider.js +1 -1
- package/dist/cli/slash/provider.js.map +1 -1
- package/dist/cli/subcommands/doctor.d.ts +1 -1
- package/dist/cli/subcommands/doctor.js +362 -84
- package/dist/cli/subcommands/doctor.js.map +1 -1
- package/dist/cli/subcommands/keys.js +44 -0
- package/dist/cli/subcommands/keys.js.map +1 -1
- package/dist/cli/subcommands/login.js +9 -0
- package/dist/cli/subcommands/login.js.map +1 -1
- package/dist/cli/update-check.d.ts +1 -0
- package/dist/cli/update-check.js +31 -7
- package/dist/cli/update-check.js.map +1 -1
- package/dist/context/compaction.js +8 -5
- package/dist/context/compaction.js.map +1 -1
- package/dist/context/session.d.ts +1 -0
- package/dist/context/session.js +4 -1
- package/dist/context/session.js.map +1 -1
- package/dist/fleet/runner.d.ts +2 -2
- package/dist/fleet/runner.js +117 -79
- package/dist/fleet/runner.js.map +1 -1
- package/dist/fleet/tripleshot.js +1 -1
- package/dist/fleet/tripleshot.js.map +1 -1
- package/dist/intelligence/error-classifier.js +37 -8
- package/dist/intelligence/error-classifier.js.map +1 -1
- package/dist/intelligence/failover-chain.d.ts +24 -0
- package/dist/intelligence/failover-chain.js +79 -6
- package/dist/intelligence/failover-chain.js.map +1 -1
- package/dist/intelligence/health-monitor.d.ts +27 -0
- package/dist/intelligence/health-monitor.js +242 -0
- package/dist/intelligence/health-monitor.js.map +1 -0
- package/dist/intelligence/index.d.ts +7 -5
- package/dist/intelligence/index.js +7 -5
- package/dist/intelligence/index.js.map +1 -1
- package/dist/intelligence/prices.js +134 -31
- package/dist/intelligence/prices.js.map +1 -1
- package/dist/intelligence/remote-catalogue.d.ts +31 -0
- package/dist/intelligence/remote-catalogue.js +174 -0
- package/dist/intelligence/remote-catalogue.js.map +1 -0
- package/dist/intelligence/remote-config.d.ts +26 -0
- package/dist/intelligence/remote-config.js +80 -0
- package/dist/intelligence/remote-config.js.map +1 -0
- package/dist/kernel/agent-loop.js +24 -1
- package/dist/kernel/agent-loop.js.map +1 -1
- package/dist/parity/scenarios.d.ts +3 -3
- package/dist/parity/scenarios.js +77 -36
- package/dist/parity/scenarios.js.map +1 -1
- package/dist/providers/anthropic-catalogue.d.ts +9 -0
- package/dist/providers/anthropic-catalogue.js +90 -0
- package/dist/providers/anthropic-catalogue.js.map +1 -0
- package/dist/providers/anthropic.js +3 -1
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/catalogue.d.ts +34 -0
- package/dist/providers/catalogue.js +20 -0
- package/dist/providers/catalogue.js.map +1 -0
- package/dist/providers/cerebras-catalogue.d.ts +9 -0
- package/dist/providers/cerebras-catalogue.js +54 -0
- package/dist/providers/cerebras-catalogue.js.map +1 -0
- package/dist/providers/cohere-catalogue.d.ts +9 -0
- package/dist/providers/cohere-catalogue.js +54 -0
- package/dist/providers/cohere-catalogue.js.map +1 -0
- package/dist/providers/deepseek-catalogue.d.ts +15 -0
- package/dist/providers/deepseek-catalogue.js +81 -0
- package/dist/providers/deepseek-catalogue.js.map +1 -0
- package/dist/providers/deepseek.d.ts +4 -2
- package/dist/providers/deepseek.js +7 -23
- package/dist/providers/deepseek.js.map +1 -1
- package/dist/providers/dispatch.js +22 -27
- package/dist/providers/dispatch.js.map +1 -1
- package/dist/providers/extra-providers.js +21 -0
- package/dist/providers/extra-providers.js.map +1 -1
- package/dist/providers/family-fallback.js +3 -3
- package/dist/providers/family-fallback.js.map +1 -1
- package/dist/providers/fireworks.d.ts +7 -6
- package/dist/providers/fireworks.js +13 -12
- package/dist/providers/fireworks.js.map +1 -1
- package/dist/providers/gemini-catalogue.d.ts +9 -0
- package/dist/providers/gemini-catalogue.js +73 -0
- package/dist/providers/gemini-catalogue.js.map +1 -0
- package/dist/providers/gemini.js +12 -3
- package/dist/providers/gemini.js.map +1 -1
- package/dist/providers/groq-catalogue.d.ts +9 -0
- package/dist/providers/groq-catalogue.js +82 -0
- package/dist/providers/groq-catalogue.js.map +1 -0
- package/dist/providers/mistral-catalogue.d.ts +9 -0
- package/dist/providers/mistral-catalogue.js +68 -0
- package/dist/providers/mistral-catalogue.js.map +1 -0
- package/dist/providers/nim-catalogue.d.ts +31 -0
- package/dist/providers/nim-catalogue.js +122 -0
- package/dist/providers/nim-catalogue.js.map +1 -0
- package/dist/providers/nvidia.js +33 -10
- package/dist/providers/nvidia.js.map +1 -1
- package/dist/providers/openai-catalogue.d.ts +9 -0
- package/dist/providers/openai-catalogue.js +82 -0
- package/dist/providers/openai-catalogue.js.map +1 -0
- package/dist/providers/perplexity-catalogue.d.ts +10 -0
- package/dist/providers/perplexity-catalogue.js +69 -0
- package/dist/providers/perplexity-catalogue.js.map +1 -0
- package/dist/providers/together-catalogue.d.ts +9 -0
- package/dist/providers/together-catalogue.js +54 -0
- package/dist/providers/together-catalogue.js.map +1 -0
- package/dist/providers/xai-catalogue.d.ts +9 -0
- package/dist/providers/xai-catalogue.js +54 -0
- package/dist/providers/xai-catalogue.js.map +1 -0
- package/dist/state/db-telemetry.d.ts +21 -0
- package/dist/state/db-telemetry.js +106 -0
- package/dist/state/db-telemetry.js.map +1 -0
- package/dist/state/db.js +7 -4
- package/dist/state/db.js.map +1 -1
- package/dist/tui/ink/App.d.ts +5 -1
- package/dist/tui/ink/App.js +244 -34
- package/dist/tui/ink/App.js.map +1 -1
- package/dist/tui/ink/components/DenseToolMessage.js +19 -8
- package/dist/tui/ink/components/DenseToolMessage.js.map +1 -1
- package/dist/tui/ink/components/InputBox.d.ts +4 -0
- package/dist/tui/ink/components/InputBox.js +41 -11
- package/dist/tui/ink/components/InputBox.js.map +1 -1
- package/dist/tui/ink/components/KeySetOverlay.d.ts +1 -1
- package/dist/tui/ink/components/KeySetOverlay.js +18 -16
- package/dist/tui/ink/components/KeySetOverlay.js.map +1 -1
- package/dist/tui/ink/components/PasteCollapse.d.ts +3 -1
- package/dist/tui/ink/components/PasteCollapse.js +11 -9
- package/dist/tui/ink/components/PasteCollapse.js.map +1 -1
- package/dist/tui/ink/components/StatusBar.d.ts +7 -0
- package/dist/tui/ink/components/StatusBar.js +11 -3
- package/dist/tui/ink/components/StatusBar.js.map +1 -1
- package/dist/tui/ink/components/ThinkingBlock.d.ts +15 -4
- package/dist/tui/ink/components/ThinkingBlock.js +34 -17
- package/dist/tui/ink/components/ThinkingBlock.js.map +1 -1
- package/dist/tui/ink/components/ToolBox.js +23 -11
- package/dist/tui/ink/components/ToolBox.js.map +1 -1
- package/dist/tui/ink/components/VirtualTranscript.d.ts +19 -0
- package/dist/tui/ink/components/VirtualTranscript.js +29 -0
- package/dist/tui/ink/components/VirtualTranscript.js.map +1 -0
- package/dist/tui/ink/index.d.ts +5 -1
- package/dist/tui/ink/index.js +19 -7
- package/dist/tui/ink/index.js.map +1 -1
- package/dist/tui/ink/markdown/syntax-highlight.d.ts +13 -0
- package/dist/tui/ink/markdown/syntax-highlight.js +91 -0
- package/dist/tui/ink/markdown/syntax-highlight.js.map +1 -0
- package/dist/tui/ink/use-declined-versions.d.ts +14 -0
- package/dist/tui/ink/use-declined-versions.js +57 -0
- package/dist/tui/ink/use-declined-versions.js.map +1 -0
- package/dist/tui/ink/use-elapsed.d.ts +6 -0
- package/dist/tui/ink/use-elapsed.js +46 -0
- package/dist/tui/ink/use-elapsed.js.map +1 -0
- package/dist/tui/ink/use-flicker-detector.d.ts +12 -0
- package/dist/tui/ink/use-flicker-detector.js +37 -0
- package/dist/tui/ink/use-flicker-detector.js.map +1 -0
- package/dist/tui/ink/use-render-metrics.d.ts +14 -0
- package/dist/tui/ink/use-render-metrics.js +93 -0
- package/dist/tui/ink/use-render-metrics.js.map +1 -0
- package/dist/tui/ink/use-startup-health.d.ts +10 -0
- package/dist/tui/ink/use-startup-health.js +125 -0
- package/dist/tui/ink/use-startup-health.js.map +1 -0
- package/dist/tui/ink/use-transcript-scroll.d.ts +19 -0
- package/dist/tui/ink/use-transcript-scroll.js +83 -0
- package/dist/tui/ink/use-transcript-scroll.js.map +1 -0
- package/package.json +1 -1
package/dist/tui/ink/App.js
CHANGED
|
@@ -17,6 +17,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
17
17
|
import * as React from "react";
|
|
18
18
|
import { Box, Static, Text, useApp, useInput } from "ink";
|
|
19
19
|
import { randomUUID } from "node:crypto";
|
|
20
|
+
import { VirtualTranscript } from "./components/VirtualTranscript.js";
|
|
20
21
|
import { appendAudit } from "../../audit/writer.js";
|
|
21
22
|
import { maybeCompact } from "../../context/compaction.js";
|
|
22
23
|
import { contextWindowFor } from "../../intelligence/prices.js";
|
|
@@ -36,7 +37,7 @@ import { PRICES } from "../../intelligence/prices.js";
|
|
|
36
37
|
import { Logo } from "./components/Logo.js";
|
|
37
38
|
import { StatusBar } from "./components/StatusBar.js";
|
|
38
39
|
import { StreamingText } from "./components/StreamingText.js";
|
|
39
|
-
import { ThinkingBlock } from "./components/ThinkingBlock.js";
|
|
40
|
+
import { ThinkingBlock, ThinkingBlockGroup, } from "./components/ThinkingBlock.js";
|
|
40
41
|
import { ToolBox } from "./components/ToolBox.js";
|
|
41
42
|
import { ToolGroup } from "./components/ToolGroup.js";
|
|
42
43
|
import { InputBox } from "./components/InputBox.js";
|
|
@@ -47,16 +48,24 @@ import { ProviderPicker, } from "./components/ProviderPicker.js";
|
|
|
47
48
|
import { HelpOverlay, } from "./components/HelpOverlay.js";
|
|
48
49
|
import { KeySetOverlay } from "./components/KeySetOverlay.js";
|
|
49
50
|
import { saveKey } from "../../auth/keystore.js";
|
|
51
|
+
import { loadToken, migrateLegacyAuth, } from "../../integrations/device-auth.js";
|
|
52
|
+
import { getUpdateBannerVersion } from "../../cli/update-check.js";
|
|
50
53
|
import { AtFileComplete } from "./components/AtFileComplete.js";
|
|
51
54
|
import { SlashComplete } from "./components/SlashComplete.js";
|
|
52
55
|
import { ThemePicker } from "./components/ThemePicker.js";
|
|
53
|
-
import { ThemeProvider } from "./theme-context.js";
|
|
56
|
+
import { ThemeProvider, useTheme } from "./theme-context.js";
|
|
54
57
|
import { SpinnerContext } from "./spinner-context.js";
|
|
58
|
+
import { SpinnerGlyph } from "./components/SpinnerGlyph.js";
|
|
55
59
|
import { writeFile, mkdir, readFile } from "node:fs/promises";
|
|
56
60
|
import { homedir } from "node:os";
|
|
57
61
|
import { join as pathJoin } from "node:path";
|
|
58
62
|
import { useEventProjection, } from "./use-event-projection.js";
|
|
59
63
|
import { useOverlays } from "./use-overlays.js";
|
|
64
|
+
import { useDeclinedVersions } from "./use-declined-versions.js";
|
|
65
|
+
import { useStartupHealth } from "./use-startup-health.js";
|
|
66
|
+
import { useFlickerDetector } from "./use-flicker-detector.js";
|
|
67
|
+
import { useRenderMetrics, } from "./use-render-metrics.js";
|
|
68
|
+
import { getRemoteConfig, isVersionBelowMin, } from "../../intelligence/remote-config.js";
|
|
60
69
|
import { createRequire } from "node:module";
|
|
61
70
|
// Pulled from the installed package.json so the TUI title matches the
|
|
62
71
|
// shipped binary version. Falls back to '0.0.0-dev' if the file isn't
|
|
@@ -77,9 +86,31 @@ export function App(props) {
|
|
|
77
86
|
const historyRef = React.useRef(initialHistory(props));
|
|
78
87
|
const abortRef = React.useRef(null);
|
|
79
88
|
const pendingModelRef = React.useRef(null);
|
|
89
|
+
const sessionRef = React.useRef(null);
|
|
90
|
+
React.useEffect(() => {
|
|
91
|
+
const id = sessionIdRef.current;
|
|
92
|
+
void props.sessions.create(id).then((s) => {
|
|
93
|
+
sessionRef.current = s;
|
|
94
|
+
if (props.sessionHandle)
|
|
95
|
+
props.sessionHandle.session = s;
|
|
96
|
+
});
|
|
97
|
+
return () => {
|
|
98
|
+
if (sessionRef.current) {
|
|
99
|
+
try {
|
|
100
|
+
sessionRef.current.close();
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
/* swallow */
|
|
104
|
+
}
|
|
105
|
+
if (props.sessionHandle)
|
|
106
|
+
props.sessionHandle.session = null;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}, [props.sessions, props.sessionHandle]);
|
|
80
110
|
const [transcript, setTranscript] = React.useState([]);
|
|
81
111
|
const [input, setInput] = React.useState("");
|
|
82
112
|
const [busy, setBusy] = React.useState(false);
|
|
113
|
+
const [thinkingStreaming, setThinkingStreaming] = React.useState(false);
|
|
83
114
|
// Prompt queue: while a turn is streaming the user can still type and
|
|
84
115
|
// press Enter. Submissions land here instead of being dropped, then
|
|
85
116
|
// drain FIFO when the turn finishes (see useEffect below).
|
|
@@ -99,6 +130,19 @@ export function App(props) {
|
|
|
99
130
|
// the input box; submitting any other prompt also clears it.
|
|
100
131
|
const [pendingFailover, setPendingFailover] = React.useState(null);
|
|
101
132
|
const lastUserPromptRef = React.useRef("");
|
|
133
|
+
const [promptHistory, setPromptHistory] = React.useState([]);
|
|
134
|
+
// Dirgha Gateway token loaded from ~/.dirgha/credentials.json.
|
|
135
|
+
// Required for billing, entitlements, deploy, and /account.
|
|
136
|
+
const tokenRef = React.useRef(null);
|
|
137
|
+
React.useEffect(() => {
|
|
138
|
+
migrateLegacyAuth()
|
|
139
|
+
.then(() => loadToken())
|
|
140
|
+
.then((t) => {
|
|
141
|
+
if (t)
|
|
142
|
+
tokenRef.current = t;
|
|
143
|
+
})
|
|
144
|
+
.catch(() => { });
|
|
145
|
+
}, []);
|
|
102
146
|
// Approval bus — single instance per App so subscriptions persist across
|
|
103
147
|
// turns. Replaces the legacy `createTuiApprovalBus` that wrote prompts
|
|
104
148
|
// direct to stdout (overdrawn by Ink) and read stdin raw (hung on
|
|
@@ -133,6 +177,116 @@ export function App(props) {
|
|
|
133
177
|
const [liveDurationMs, setLiveDurationMs] = React.useState(0);
|
|
134
178
|
const turnStartRef = React.useRef(0);
|
|
135
179
|
const liveOutputTokensAccRef = React.useRef(0);
|
|
180
|
+
const [updateVersion, setUpdateVersion] = React.useState(null);
|
|
181
|
+
const updateShownRef = React.useRef(false);
|
|
182
|
+
const declined = useDeclinedVersions();
|
|
183
|
+
React.useEffect(() => {
|
|
184
|
+
if (updateShownRef.current)
|
|
185
|
+
return;
|
|
186
|
+
updateShownRef.current = true;
|
|
187
|
+
getUpdateBannerVersion(VERSION).then((v) => {
|
|
188
|
+
if (v && !declined.isDeclined(v))
|
|
189
|
+
setUpdateVersion(v);
|
|
190
|
+
});
|
|
191
|
+
}, [declined]);
|
|
192
|
+
// Startup health check — non-blocking, cached for 24h.
|
|
193
|
+
const healthResult = useStartupHealth();
|
|
194
|
+
// Flicker detector — compares estimated tree height to terminal rows.
|
|
195
|
+
const estimatedLineCount = (transcript.length + projection.liveItems.length) * 2 + 15;
|
|
196
|
+
const flicker = useFlickerDetector(estimatedLineCount);
|
|
197
|
+
// Render performance metrics — track frame timing, expose for StatusBar.
|
|
198
|
+
const renderMetrics = useRenderMetrics();
|
|
199
|
+
const [showRenderMetrics, setShowRenderMetrics] = React.useState(false);
|
|
200
|
+
// Alt+M toggles the render-metrics display in the StatusBar.
|
|
201
|
+
useInput((ch, key) => {
|
|
202
|
+
if (key.meta && ch === "m") {
|
|
203
|
+
setShowRenderMetrics((v) => !v);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
// Remote config: fetch once on mount, set model default, show MOTD.
|
|
207
|
+
const [remoteConfig, setRemoteConfig] = React.useState(null);
|
|
208
|
+
const [motdShown, setMotdShown] = React.useState(false);
|
|
209
|
+
const [remoteConfigFetched, setRemoteConfigFetched] = React.useState(false);
|
|
210
|
+
React.useEffect(() => {
|
|
211
|
+
if (remoteConfigFetched)
|
|
212
|
+
return;
|
|
213
|
+
setRemoteConfigFetched(true);
|
|
214
|
+
void getRemoteConfig().then((cfg) => {
|
|
215
|
+
if (cfg)
|
|
216
|
+
setRemoteConfig(cfg);
|
|
217
|
+
});
|
|
218
|
+
}, [remoteConfigFetched]);
|
|
219
|
+
// Apply remote config model default on first load if no explicit model set.
|
|
220
|
+
const remoteModelAppliedRef = React.useRef(false);
|
|
221
|
+
React.useEffect(() => {
|
|
222
|
+
if (!remoteConfig || remoteModelAppliedRef.current)
|
|
223
|
+
return;
|
|
224
|
+
remoteModelAppliedRef.current = true;
|
|
225
|
+
const explicit = props.config.model;
|
|
226
|
+
const hasDefault = explicit !== undefined &&
|
|
227
|
+
explicit !== "" &&
|
|
228
|
+
explicit !== "accounts/fireworks/routers/kimi-k2p5-turbo";
|
|
229
|
+
if (!hasDefault && remoteConfig.recommendedModel) {
|
|
230
|
+
setCurrentModel(remoteConfig.recommendedModel);
|
|
231
|
+
}
|
|
232
|
+
}, [remoteConfig, props.config.model]);
|
|
233
|
+
// Show MOTD once per session.
|
|
234
|
+
React.useEffect(() => {
|
|
235
|
+
if (!remoteConfig?.motd || motdShown)
|
|
236
|
+
return;
|
|
237
|
+
setMotdShown(true);
|
|
238
|
+
const note = {
|
|
239
|
+
kind: "notice",
|
|
240
|
+
id: randomUUID(),
|
|
241
|
+
text: remoteConfig.motd,
|
|
242
|
+
};
|
|
243
|
+
setTranscript((prev) => [...prev, note]);
|
|
244
|
+
}, [remoteConfig, motdShown]);
|
|
245
|
+
// Warn about deprecated models if the current model is in the list.
|
|
246
|
+
const deprecatedWarnedRef = React.useRef(false);
|
|
247
|
+
React.useEffect(() => {
|
|
248
|
+
if (!remoteConfig || deprecatedWarnedRef.current)
|
|
249
|
+
return;
|
|
250
|
+
if (remoteConfig.deprecatedModels.length > 0 &&
|
|
251
|
+
remoteConfig.deprecatedModels.includes(currentModel)) {
|
|
252
|
+
deprecatedWarnedRef.current = true;
|
|
253
|
+
const note = {
|
|
254
|
+
kind: "notice",
|
|
255
|
+
id: randomUUID(),
|
|
256
|
+
text: `[DEPRECATED] Model ${currentModel} is deprecated. Switch to ${remoteConfig.recommendedModel ?? "a supported model"} via /model.`,
|
|
257
|
+
};
|
|
258
|
+
setTranscript((prev) => [...prev, note]);
|
|
259
|
+
}
|
|
260
|
+
}, [remoteConfig, currentModel]);
|
|
261
|
+
// Minimum version nag: show upgrade banner immediately if below minimum.
|
|
262
|
+
const [minVersionNagShown, setMinVersionNagShown] = React.useState(false);
|
|
263
|
+
React.useEffect(() => {
|
|
264
|
+
if (!remoteConfig || minVersionNagShown)
|
|
265
|
+
return;
|
|
266
|
+
if (isVersionBelowMin(VERSION, remoteConfig.minimumVersion)) {
|
|
267
|
+
setMinVersionNagShown(true);
|
|
268
|
+
setUpdateVersion(remoteConfig.minimumVersion);
|
|
269
|
+
}
|
|
270
|
+
}, [remoteConfig, minVersionNagShown]);
|
|
271
|
+
// Self-upgrade handler (Ctrl+U or /upgrade).
|
|
272
|
+
const handleUpgrade = React.useCallback(() => {
|
|
273
|
+
void (async () => {
|
|
274
|
+
try {
|
|
275
|
+
const { execFileSync } = await import("node:child_process");
|
|
276
|
+
const isWin = process.platform === "win32";
|
|
277
|
+
const npmBin = isWin ? "npm.cmd" : "npm";
|
|
278
|
+
execFileSync(npmBin, ["i", "-g", "@dirgha/code@latest"], {
|
|
279
|
+
stdio: "inherit",
|
|
280
|
+
shell: isWin,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
catch {
|
|
284
|
+
/* fall through to exit */
|
|
285
|
+
}
|
|
286
|
+
exit();
|
|
287
|
+
process.exit(0);
|
|
288
|
+
})();
|
|
289
|
+
}, [exit]);
|
|
136
290
|
React.useEffect(() => {
|
|
137
291
|
const unsub = props.events.subscribe((ev) => {
|
|
138
292
|
if (ev.type === "agent_start") {
|
|
@@ -140,6 +294,13 @@ export function App(props) {
|
|
|
140
294
|
liveOutputTokensAccRef.current = 0;
|
|
141
295
|
setLiveOutputTokens(0);
|
|
142
296
|
setLiveDurationMs(0);
|
|
297
|
+
setThinkingStreaming(false);
|
|
298
|
+
}
|
|
299
|
+
else if (ev.type === "thinking_start") {
|
|
300
|
+
setThinkingStreaming(true);
|
|
301
|
+
}
|
|
302
|
+
else if (ev.type === "thinking_end") {
|
|
303
|
+
setThinkingStreaming(false);
|
|
143
304
|
}
|
|
144
305
|
else if (ev.type === "text_delta" || ev.type === "thinking_delta") {
|
|
145
306
|
liveOutputTokensAccRef.current += (ev.delta?.length ?? 0) / 4;
|
|
@@ -237,6 +398,11 @@ export function App(props) {
|
|
|
237
398
|
// Remember the last user prompt so we can re-submit it after a
|
|
238
399
|
// failover model swap (D2 — auto-prompt model switch on failure).
|
|
239
400
|
lastUserPromptRef.current = value;
|
|
401
|
+
// Up/down arrow prompt history (keep last 100 prompts, newest first).
|
|
402
|
+
setPromptHistory((prev) => {
|
|
403
|
+
const deduped = prev.filter((p) => p !== value);
|
|
404
|
+
return [value, ...deduped].slice(0, 100);
|
|
405
|
+
});
|
|
240
406
|
// A new submission supersedes any pending failover prompt.
|
|
241
407
|
setPendingFailover(null);
|
|
242
408
|
if (value === "/exit" || value === "/quit") {
|
|
@@ -287,14 +453,28 @@ export function App(props) {
|
|
|
287
453
|
overlays.openOverlay("theme");
|
|
288
454
|
return;
|
|
289
455
|
}
|
|
456
|
+
// /upgrade and /self-update trigger npm install + restart.
|
|
457
|
+
if (value === "/upgrade" ||
|
|
458
|
+
value === "/self-update" ||
|
|
459
|
+
value === "/update --self") {
|
|
460
|
+
const note = {
|
|
461
|
+
kind: "notice",
|
|
462
|
+
id: randomUUID(),
|
|
463
|
+
text: "Upgrading @dirgha/code to latest via npm…",
|
|
464
|
+
};
|
|
465
|
+
setTranscript((prev) => [...prev, note]);
|
|
466
|
+
handleUpgrade();
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
290
469
|
// Anything else starting with `/` goes through the SlashRegistry — that
|
|
291
470
|
// covers /init /keys /memory /compact /setup /login /status /resume
|
|
292
|
-
// /session /history /fleet /account /
|
|
293
|
-
// The hardcoded branches above (clear/help/model[s]/theme) ran first
|
|
294
|
-
// because they open Ink overlays and don't fit
|
|
295
|
-
// contract. Without this dispatch,
|
|
296
|
-
// through to runTurn() and were sent
|
|
297
|
-
// surprising behaviour that S1/2026-04-27
|
|
471
|
+
// /session /history /fleet /account /config /mode and friends.
|
|
472
|
+
// The hardcoded branches above (clear/help/model[s]/theme/upgrade) ran first
|
|
473
|
+
// because they open Ink overlays or trigger self-upgrade and don't fit
|
|
474
|
+
// the registry string-output contract. Without this dispatch,
|
|
475
|
+
// unrecognised slash commands fell through to runTurn() and were sent
|
|
476
|
+
// to the LLM as user prompts — surprising behaviour that S1/2026-04-27
|
|
477
|
+
// fixes.
|
|
298
478
|
if (value.startsWith("/")) {
|
|
299
479
|
const ctx = {
|
|
300
480
|
get model() {
|
|
@@ -349,8 +529,10 @@ export function App(props) {
|
|
|
349
529
|
exit();
|
|
350
530
|
process.exit(code);
|
|
351
531
|
},
|
|
352
|
-
getToken: () =>
|
|
353
|
-
setToken: () =>
|
|
532
|
+
getToken: () => tokenRef.current,
|
|
533
|
+
setToken: (newToken) => {
|
|
534
|
+
tokenRef.current = newToken;
|
|
535
|
+
},
|
|
354
536
|
apiBase: () => process.env["DIRGHA_API_BASE"] ??
|
|
355
537
|
process.env["DIRGHA_GATEWAY_URL"] ??
|
|
356
538
|
"https://api.dirgha.ai",
|
|
@@ -415,6 +597,11 @@ export function App(props) {
|
|
|
415
597
|
};
|
|
416
598
|
setTranscript((prev) => [...prev, userItem]);
|
|
417
599
|
historyRef.current.push({ role: "user", content: value });
|
|
600
|
+
void sessionRef.current?.append({
|
|
601
|
+
type: "message",
|
|
602
|
+
ts: new Date().toISOString(),
|
|
603
|
+
message: { role: "user", content: value },
|
|
604
|
+
});
|
|
418
605
|
void runTurnRef.current();
|
|
419
606
|
}, [
|
|
420
607
|
busy,
|
|
@@ -435,6 +622,7 @@ export function App(props) {
|
|
|
435
622
|
overlays.setSlashQuery,
|
|
436
623
|
overlays.setActive,
|
|
437
624
|
overlays.active,
|
|
625
|
+
handleUpgrade,
|
|
438
626
|
]);
|
|
439
627
|
const runTurn = async () => {
|
|
440
628
|
setBusy(true);
|
|
@@ -502,6 +690,7 @@ export function App(props) {
|
|
|
502
690
|
const userHooks = buildAgentHooksFromConfig(props.config);
|
|
503
691
|
const composedHooks = composeHooks(enforceMode(mode), userHooks);
|
|
504
692
|
const autoApprove = isAutoApprove(mode);
|
|
693
|
+
const prevHistoryLen = historyRef.current.length;
|
|
505
694
|
const result = await runAgentLoop({
|
|
506
695
|
sessionId: sessionIdRef.current,
|
|
507
696
|
model: currentModel,
|
|
@@ -519,6 +708,13 @@ export function App(props) {
|
|
|
519
708
|
...(composedHooks !== undefined ? { hooks: composedHooks } : {}),
|
|
520
709
|
});
|
|
521
710
|
historyRef.current = result.messages;
|
|
711
|
+
for (const msg of result.messages.slice(prevHistoryLen)) {
|
|
712
|
+
void sessionRef.current?.append({
|
|
713
|
+
type: "message",
|
|
714
|
+
ts: new Date().toISOString(),
|
|
715
|
+
message: msg,
|
|
716
|
+
});
|
|
717
|
+
}
|
|
522
718
|
}
|
|
523
719
|
catch (err) {
|
|
524
720
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -768,19 +964,10 @@ export function App(props) {
|
|
|
768
964
|
}
|
|
769
965
|
})();
|
|
770
966
|
}, [overlays]);
|
|
771
|
-
const
|
|
772
|
-
// Gemini CLI approach: freeze committed history inside <Static>
|
|
773
|
-
// so Ink caches the output and never re-renders it. Without this,
|
|
774
|
-
// every streaming flush tick re-conciles the entire transcript
|
|
775
|
-
// against the terminal — causing visible flicker/jitter.
|
|
776
|
-
const committedStaticItems = React.useMemo(() => committedJsx.map((el, i) => ({
|
|
777
|
-
key: el?.key ?? `c-${i}`,
|
|
778
|
-
el,
|
|
779
|
-
})), [committedJsx]);
|
|
780
|
-
const liveJsx = React.useMemo(() => renderTranscript(projection.liveItems), [projection.liveItems]);
|
|
967
|
+
const liveJsx = React.useMemo(() => renderTranscript(projection.liveItems, thinkingStreaming), [projection.liveItems, thinkingStreaming]);
|
|
781
968
|
const providerEntries = React.useMemo(() => buildProviderEntries(models, currentModel), [models, currentModel]);
|
|
782
969
|
const LOGO_ITEMS = React.useMemo(() => [{ key: "logo" }], []);
|
|
783
|
-
return (_jsx(ThemeProvider, { activeTheme: themeName, children: _jsx(SpinnerContext.Provider, { value: { busy, frame: 0 }, children: _jsxs(Box, { flexDirection: "column", children: [_jsx(Static, { items: LOGO_ITEMS, children: () => _jsx(Logo, { version: VERSION }, "logo") }), _jsx(
|
|
970
|
+
return (_jsx(ThemeProvider, { activeTheme: themeName, children: _jsx(SpinnerContext.Provider, { value: { busy, frame: 0 }, children: _jsxs(Box, { flexDirection: "column", children: [_jsx(Static, { items: LOGO_ITEMS, children: () => _jsx(Logo, { version: VERSION }, "logo") }), _jsx(VirtualTranscript, { items: transcript, renderItem: (item) => _jsx(TranscriptRow, { item: item }, item.id), autoScroll: true, inputFocus: inputFocus }), _jsx(Box, { flexDirection: "column", children: liveJsx }), busy && projection.liveItems.length === 0 && _jsx(GeneratingIndicator, {}), pendingApproval !== null && approvalBusRef.current && (_jsx(ApprovalPrompt, { request: pendingApproval, onResolve: (decision) => {
|
|
784
971
|
approvalBusRef.current?.resolve(pendingApproval.id, decision);
|
|
785
972
|
} })), pendingFailover !== null && (_jsx(ModelSwitchPrompt, { failedModel: pendingFailover.failedModel, failoverModel: pendingFailover.failoverModel, onAccept: (failover) => {
|
|
786
973
|
const lastPrompt = pendingFailover.lastPrompt;
|
|
@@ -793,7 +980,7 @@ export function App(props) {
|
|
|
793
980
|
}, onReject: () => setPendingFailover(null), onPicker: () => {
|
|
794
981
|
setPendingFailover(null);
|
|
795
982
|
overlays.openOverlay("models");
|
|
796
|
-
} })), _jsx(PromptQueueIndicator, { queued: promptQueue }), _jsx(InputBox, { value: input, onChange: setInput, onSubmit: handleSubmit, busy: busy, liveDurationMs: liveDurationMs, vimMode: props.config.vimMode === true, onAtQueryChange: overlays.setAtQuery, onSlashQueryChange: overlays.setSlashQuery, onRequestOverlay: overlays.openOverlay, onRequestYoloToggle: () => {
|
|
983
|
+
} })), _jsx(PromptQueueIndicator, { queued: promptQueue }), _jsx(InputBox, { value: input, onChange: setInput, onSubmit: handleSubmit, busy: busy, liveDurationMs: liveDurationMs, vimMode: props.config.vimMode === true, onAtQueryChange: overlays.setAtQuery, onSlashQueryChange: overlays.setSlashQuery, onRequestOverlay: overlays.openOverlay, promptHistory: promptHistory, onRequestYoloToggle: () => {
|
|
797
984
|
const next = mode === "yolo" ? "act" : "yolo";
|
|
798
985
|
setMode(next);
|
|
799
986
|
setTranscript((prev) => [
|
|
@@ -806,7 +993,7 @@ export function App(props) {
|
|
|
806
993
|
: "YOLO mode OFF — back to standard confirmation.",
|
|
807
994
|
},
|
|
808
995
|
]);
|
|
809
|
-
}, inputFocus: inputFocus }), overlays.active === "atfile" && overlays.atQuery !== null && (_jsx(AtFileComplete, { cwd: props.cwd, query: overlays.atQuery, onPick: handleAtPick, onCancel: () => {
|
|
996
|
+
}, onRequestUpgrade: handleUpgrade, inputFocus: inputFocus }), healthResult !== null && !healthResult.allOk && (_jsx(Box, { paddingX: 1, children: _jsxs(Text, { color: "yellow", children: ["[! System check: ", healthResult.failures.length, " issue", healthResult.failures.length !== 1 ? "s" : "", " found \u2014 run 'dirgha doctor' for details]"] }) })), overlays.active === "atfile" && overlays.atQuery !== null && (_jsx(AtFileComplete, { cwd: props.cwd, query: overlays.atQuery, onPick: handleAtPick, onCancel: () => {
|
|
810
997
|
overlays.setAtQuery(null);
|
|
811
998
|
overlays.setActive(null);
|
|
812
999
|
} })), overlays.active === "slash" && overlays.slashQuery !== null && (_jsx(SlashComplete, { commands: slashCommands, query: overlays.slashQuery, onPick: handleSlashPick, onCancel: () => {
|
|
@@ -835,28 +1022,40 @@ export function App(props) {
|
|
|
835
1022
|
// Esc inside ModelPicker → back to ProviderPicker (NOT close).
|
|
836
1023
|
setPickerStage("provider");
|
|
837
1024
|
setPickerProvider(null);
|
|
838
|
-
} })), overlays.active === "help" && (_jsx(HelpOverlay, { slashCommands: slashCommands, onClose: overlays.closeOverlay })), overlays.active === "theme" && (_jsx(ThemePicker, { current: themeName, onPick: handleThemePick, onCancel: overlays.closeOverlay })), pendingKey && (_jsx(KeySetOverlay, { keyName: pendingKey.keyName, onSave: handleKeySetSave, onCancel: () => setPendingKey(null) })), _jsx(StatusBar, { model: currentModel, provider: providerIdForModel(currentModel), inputTokens: projection.totals.inputTokens, outputTokens: projection.totals.outputTokens, costUsd: projection.totals.costUsd, cwd: props.cwd, busy: busy, mode: mode, contextWindow: contextWindowFor(currentModel), liveOutputTokens: liveOutputTokens, liveDurationMs: liveDurationMs })] }) }) }));
|
|
1025
|
+
} })), overlays.active === "help" && (_jsx(HelpOverlay, { slashCommands: slashCommands, onClose: overlays.closeOverlay })), overlays.active === "theme" && (_jsx(ThemePicker, { current: themeName, onPick: handleThemePick, onCancel: overlays.closeOverlay })), pendingKey && (_jsx(KeySetOverlay, { keyName: pendingKey.keyName, onSave: handleKeySetSave, onCancel: () => setPendingKey(null) })), updateVersion !== null && (_jsx(Box, { paddingX: 1, children: _jsxs(Text, { color: "yellow", children: ["[v", updateVersion, " available \u2014 press Ctrl+U or /upgrade to upgrade]"] }) })), _jsx(StatusBar, { model: currentModel, provider: providerIdForModel(currentModel), inputTokens: projection.totals.inputTokens, outputTokens: projection.totals.outputTokens, costUsd: projection.totals.costUsd, cwd: props.cwd, busy: busy, mode: mode, contextWindow: contextWindowFor(currentModel), liveOutputTokens: liveOutputTokens, liveDurationMs: liveDurationMs, overflowDetected: flicker.overflowDetected, showMetrics: showRenderMetrics, renderMetrics: renderMetrics })] }) }) }));
|
|
839
1026
|
}
|
|
840
1027
|
/**
|
|
841
1028
|
* Walk the transcript and fold consecutive `tool` items into a single
|
|
842
|
-
* <ToolGroup>.
|
|
843
|
-
*
|
|
844
|
-
*
|
|
845
|
-
* `text` spans of the same turn.
|
|
1029
|
+
* <ToolGroup>. Fold 3+ consecutive `thinking` items into a single
|
|
1030
|
+
* <ThinkingBlockGroup>. Non-tool / non-thinking items render via
|
|
1031
|
+
* <TranscriptRow>.
|
|
846
1032
|
*/
|
|
847
|
-
function renderTranscript(items) {
|
|
1033
|
+
function renderTranscript(items, thinkingStreaming) {
|
|
848
1034
|
const out = [];
|
|
849
1035
|
let toolBuf = [];
|
|
1036
|
+
let thinkBuf = [];
|
|
850
1037
|
const flushTools = () => {
|
|
851
1038
|
if (toolBuf.length === 0)
|
|
852
1039
|
return;
|
|
853
|
-
// Key on the stable ID of the first tool so React never unmounts/remounts
|
|
854
|
-
// the ToolGroup subtree when the counter resets (which caused flicker).
|
|
855
1040
|
out.push(_jsx(ToolGroup, { tools: toolBuf }, toolBuf[0].id));
|
|
856
1041
|
toolBuf = [];
|
|
857
1042
|
};
|
|
1043
|
+
const flushThinking = () => {
|
|
1044
|
+
if (thinkBuf.length === 0)
|
|
1045
|
+
return;
|
|
1046
|
+
if (thinkBuf.length >= 3) {
|
|
1047
|
+
out.push(_jsx(ThinkingBlockGroup, { blocks: thinkBuf }, thinkBuf[0].id));
|
|
1048
|
+
}
|
|
1049
|
+
else {
|
|
1050
|
+
for (const tb of thinkBuf) {
|
|
1051
|
+
out.push(_jsx(TranscriptRow, { item: { kind: "thinking", id: tb.id, content: tb.content }, isStreaming: thinkingStreaming }, tb.id));
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
thinkBuf = [];
|
|
1055
|
+
};
|
|
858
1056
|
for (const item of items) {
|
|
859
1057
|
if (item.kind === "tool") {
|
|
1058
|
+
flushThinking();
|
|
860
1059
|
toolBuf.push({
|
|
861
1060
|
id: item.id,
|
|
862
1061
|
name: item.name,
|
|
@@ -869,20 +1068,27 @@ function renderTranscript(items) {
|
|
|
869
1068
|
});
|
|
870
1069
|
continue;
|
|
871
1070
|
}
|
|
1071
|
+
if (item.kind === "thinking") {
|
|
1072
|
+
flushTools();
|
|
1073
|
+
thinkBuf.push({ id: item.id, content: item.content });
|
|
1074
|
+
continue;
|
|
1075
|
+
}
|
|
872
1076
|
flushTools();
|
|
873
|
-
|
|
1077
|
+
flushThinking();
|
|
1078
|
+
out.push(_jsx(TranscriptRow, { item: item, isStreaming: thinkingStreaming }, item.id));
|
|
874
1079
|
}
|
|
875
1080
|
flushTools();
|
|
1081
|
+
flushThinking();
|
|
876
1082
|
return out;
|
|
877
1083
|
}
|
|
878
|
-
function TranscriptRow({ item, }) {
|
|
1084
|
+
function TranscriptRow({ item, isStreaming = false, }) {
|
|
879
1085
|
switch (item.kind) {
|
|
880
1086
|
case "user":
|
|
881
1087
|
return (_jsxs(Box, { gap: 2, marginBottom: 1, children: [_jsx(Text, { color: "magenta", children: "\u276F" }), _jsx(Text, { color: "white", children: item.text })] }));
|
|
882
1088
|
case "text":
|
|
883
1089
|
return _jsx(StreamingText, { content: item.content });
|
|
884
1090
|
case "thinking":
|
|
885
|
-
return _jsx(ThinkingBlock, { content: item.content });
|
|
1091
|
+
return _jsx(ThinkingBlock, { content: item.content, isStreaming: isStreaming });
|
|
886
1092
|
case "tool":
|
|
887
1093
|
// Should not be reached — tools are folded by renderTranscript() into
|
|
888
1094
|
// <ToolGroup>. Kept as a safety net so an unexpected tool item still
|
|
@@ -894,6 +1100,10 @@ function TranscriptRow({ item, }) {
|
|
|
894
1100
|
return (_jsx(Box, { marginBottom: 1, children: _jsx(Text, { color: "yellow", children: item.text }) }));
|
|
895
1101
|
}
|
|
896
1102
|
}
|
|
1103
|
+
function GeneratingIndicator() {
|
|
1104
|
+
const palette = useTheme();
|
|
1105
|
+
return (_jsxs(Box, { gap: 1, marginBottom: 1, children: [_jsx(SpinnerGlyph, { isActive: true, color: palette.text.secondary }), _jsx(Text, { color: palette.text.secondary, dimColor: true, children: "generating\u2026" })] }));
|
|
1106
|
+
}
|
|
897
1107
|
function initialHistory(props) {
|
|
898
1108
|
const base = props.initialMessages ? [...props.initialMessages] : [];
|
|
899
1109
|
// Boot context: mode preamble + project primer (DIRGHA.md) +
|