@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.
Files changed (176) hide show
  1. package/dist/cli/first-run.d.ts +6 -5
  2. package/dist/cli/first-run.js +79 -37
  3. package/dist/cli/first-run.js.map +1 -1
  4. package/dist/cli/flows/wizard.js +1 -1
  5. package/dist/cli/flows/wizard.js.map +1 -1
  6. package/dist/cli/interactive.js +25 -9
  7. package/dist/cli/interactive.js.map +1 -1
  8. package/dist/cli/main.js +8 -1
  9. package/dist/cli/main.js.map +1 -1
  10. package/dist/cli/setup.js +4 -2
  11. package/dist/cli/setup.js.map +1 -1
  12. package/dist/cli/slash/keys.js +50 -1
  13. package/dist/cli/slash/keys.js.map +1 -1
  14. package/dist/cli/slash/login.js +8 -1
  15. package/dist/cli/slash/login.js.map +1 -1
  16. package/dist/cli/slash/models.d.ts +1 -1
  17. package/dist/cli/slash/models.js +142 -18
  18. package/dist/cli/slash/models.js.map +1 -1
  19. package/dist/cli/slash/provider.js +1 -1
  20. package/dist/cli/slash/provider.js.map +1 -1
  21. package/dist/cli/subcommands/doctor.d.ts +1 -1
  22. package/dist/cli/subcommands/doctor.js +362 -84
  23. package/dist/cli/subcommands/doctor.js.map +1 -1
  24. package/dist/cli/subcommands/keys.js +44 -0
  25. package/dist/cli/subcommands/keys.js.map +1 -1
  26. package/dist/cli/subcommands/login.js +9 -0
  27. package/dist/cli/subcommands/login.js.map +1 -1
  28. package/dist/cli/update-check.d.ts +1 -0
  29. package/dist/cli/update-check.js +31 -7
  30. package/dist/cli/update-check.js.map +1 -1
  31. package/dist/context/compaction.js +8 -5
  32. package/dist/context/compaction.js.map +1 -1
  33. package/dist/context/session.d.ts +1 -0
  34. package/dist/context/session.js +4 -1
  35. package/dist/context/session.js.map +1 -1
  36. package/dist/fleet/runner.d.ts +2 -2
  37. package/dist/fleet/runner.js +117 -79
  38. package/dist/fleet/runner.js.map +1 -1
  39. package/dist/fleet/tripleshot.js +1 -1
  40. package/dist/fleet/tripleshot.js.map +1 -1
  41. package/dist/intelligence/error-classifier.js +37 -8
  42. package/dist/intelligence/error-classifier.js.map +1 -1
  43. package/dist/intelligence/failover-chain.d.ts +24 -0
  44. package/dist/intelligence/failover-chain.js +79 -6
  45. package/dist/intelligence/failover-chain.js.map +1 -1
  46. package/dist/intelligence/health-monitor.d.ts +27 -0
  47. package/dist/intelligence/health-monitor.js +242 -0
  48. package/dist/intelligence/health-monitor.js.map +1 -0
  49. package/dist/intelligence/index.d.ts +7 -5
  50. package/dist/intelligence/index.js +7 -5
  51. package/dist/intelligence/index.js.map +1 -1
  52. package/dist/intelligence/prices.js +134 -31
  53. package/dist/intelligence/prices.js.map +1 -1
  54. package/dist/intelligence/remote-catalogue.d.ts +31 -0
  55. package/dist/intelligence/remote-catalogue.js +174 -0
  56. package/dist/intelligence/remote-catalogue.js.map +1 -0
  57. package/dist/intelligence/remote-config.d.ts +26 -0
  58. package/dist/intelligence/remote-config.js +80 -0
  59. package/dist/intelligence/remote-config.js.map +1 -0
  60. package/dist/kernel/agent-loop.js +24 -1
  61. package/dist/kernel/agent-loop.js.map +1 -1
  62. package/dist/parity/scenarios.d.ts +3 -3
  63. package/dist/parity/scenarios.js +77 -36
  64. package/dist/parity/scenarios.js.map +1 -1
  65. package/dist/providers/anthropic-catalogue.d.ts +9 -0
  66. package/dist/providers/anthropic-catalogue.js +90 -0
  67. package/dist/providers/anthropic-catalogue.js.map +1 -0
  68. package/dist/providers/anthropic.js +3 -1
  69. package/dist/providers/anthropic.js.map +1 -1
  70. package/dist/providers/catalogue.d.ts +34 -0
  71. package/dist/providers/catalogue.js +20 -0
  72. package/dist/providers/catalogue.js.map +1 -0
  73. package/dist/providers/cerebras-catalogue.d.ts +9 -0
  74. package/dist/providers/cerebras-catalogue.js +54 -0
  75. package/dist/providers/cerebras-catalogue.js.map +1 -0
  76. package/dist/providers/cohere-catalogue.d.ts +9 -0
  77. package/dist/providers/cohere-catalogue.js +54 -0
  78. package/dist/providers/cohere-catalogue.js.map +1 -0
  79. package/dist/providers/deepseek-catalogue.d.ts +15 -0
  80. package/dist/providers/deepseek-catalogue.js +81 -0
  81. package/dist/providers/deepseek-catalogue.js.map +1 -0
  82. package/dist/providers/deepseek.d.ts +4 -2
  83. package/dist/providers/deepseek.js +7 -23
  84. package/dist/providers/deepseek.js.map +1 -1
  85. package/dist/providers/dispatch.js +22 -27
  86. package/dist/providers/dispatch.js.map +1 -1
  87. package/dist/providers/extra-providers.js +21 -0
  88. package/dist/providers/extra-providers.js.map +1 -1
  89. package/dist/providers/family-fallback.js +3 -3
  90. package/dist/providers/family-fallback.js.map +1 -1
  91. package/dist/providers/fireworks.d.ts +7 -6
  92. package/dist/providers/fireworks.js +13 -12
  93. package/dist/providers/fireworks.js.map +1 -1
  94. package/dist/providers/gemini-catalogue.d.ts +9 -0
  95. package/dist/providers/gemini-catalogue.js +73 -0
  96. package/dist/providers/gemini-catalogue.js.map +1 -0
  97. package/dist/providers/gemini.js +12 -3
  98. package/dist/providers/gemini.js.map +1 -1
  99. package/dist/providers/groq-catalogue.d.ts +9 -0
  100. package/dist/providers/groq-catalogue.js +82 -0
  101. package/dist/providers/groq-catalogue.js.map +1 -0
  102. package/dist/providers/mistral-catalogue.d.ts +9 -0
  103. package/dist/providers/mistral-catalogue.js +68 -0
  104. package/dist/providers/mistral-catalogue.js.map +1 -0
  105. package/dist/providers/nim-catalogue.d.ts +31 -0
  106. package/dist/providers/nim-catalogue.js +122 -0
  107. package/dist/providers/nim-catalogue.js.map +1 -0
  108. package/dist/providers/nvidia.js +33 -10
  109. package/dist/providers/nvidia.js.map +1 -1
  110. package/dist/providers/openai-catalogue.d.ts +9 -0
  111. package/dist/providers/openai-catalogue.js +82 -0
  112. package/dist/providers/openai-catalogue.js.map +1 -0
  113. package/dist/providers/perplexity-catalogue.d.ts +10 -0
  114. package/dist/providers/perplexity-catalogue.js +69 -0
  115. package/dist/providers/perplexity-catalogue.js.map +1 -0
  116. package/dist/providers/together-catalogue.d.ts +9 -0
  117. package/dist/providers/together-catalogue.js +54 -0
  118. package/dist/providers/together-catalogue.js.map +1 -0
  119. package/dist/providers/xai-catalogue.d.ts +9 -0
  120. package/dist/providers/xai-catalogue.js +54 -0
  121. package/dist/providers/xai-catalogue.js.map +1 -0
  122. package/dist/state/db-telemetry.d.ts +21 -0
  123. package/dist/state/db-telemetry.js +106 -0
  124. package/dist/state/db-telemetry.js.map +1 -0
  125. package/dist/state/db.js +7 -4
  126. package/dist/state/db.js.map +1 -1
  127. package/dist/tui/ink/App.d.ts +5 -1
  128. package/dist/tui/ink/App.js +244 -34
  129. package/dist/tui/ink/App.js.map +1 -1
  130. package/dist/tui/ink/components/DenseToolMessage.js +19 -8
  131. package/dist/tui/ink/components/DenseToolMessage.js.map +1 -1
  132. package/dist/tui/ink/components/InputBox.d.ts +4 -0
  133. package/dist/tui/ink/components/InputBox.js +41 -11
  134. package/dist/tui/ink/components/InputBox.js.map +1 -1
  135. package/dist/tui/ink/components/KeySetOverlay.d.ts +1 -1
  136. package/dist/tui/ink/components/KeySetOverlay.js +18 -16
  137. package/dist/tui/ink/components/KeySetOverlay.js.map +1 -1
  138. package/dist/tui/ink/components/PasteCollapse.d.ts +3 -1
  139. package/dist/tui/ink/components/PasteCollapse.js +11 -9
  140. package/dist/tui/ink/components/PasteCollapse.js.map +1 -1
  141. package/dist/tui/ink/components/StatusBar.d.ts +7 -0
  142. package/dist/tui/ink/components/StatusBar.js +11 -3
  143. package/dist/tui/ink/components/StatusBar.js.map +1 -1
  144. package/dist/tui/ink/components/ThinkingBlock.d.ts +15 -4
  145. package/dist/tui/ink/components/ThinkingBlock.js +34 -17
  146. package/dist/tui/ink/components/ThinkingBlock.js.map +1 -1
  147. package/dist/tui/ink/components/ToolBox.js +23 -11
  148. package/dist/tui/ink/components/ToolBox.js.map +1 -1
  149. package/dist/tui/ink/components/VirtualTranscript.d.ts +19 -0
  150. package/dist/tui/ink/components/VirtualTranscript.js +29 -0
  151. package/dist/tui/ink/components/VirtualTranscript.js.map +1 -0
  152. package/dist/tui/ink/index.d.ts +5 -1
  153. package/dist/tui/ink/index.js +19 -7
  154. package/dist/tui/ink/index.js.map +1 -1
  155. package/dist/tui/ink/markdown/syntax-highlight.d.ts +13 -0
  156. package/dist/tui/ink/markdown/syntax-highlight.js +91 -0
  157. package/dist/tui/ink/markdown/syntax-highlight.js.map +1 -0
  158. package/dist/tui/ink/use-declined-versions.d.ts +14 -0
  159. package/dist/tui/ink/use-declined-versions.js +57 -0
  160. package/dist/tui/ink/use-declined-versions.js.map +1 -0
  161. package/dist/tui/ink/use-elapsed.d.ts +6 -0
  162. package/dist/tui/ink/use-elapsed.js +46 -0
  163. package/dist/tui/ink/use-elapsed.js.map +1 -0
  164. package/dist/tui/ink/use-flicker-detector.d.ts +12 -0
  165. package/dist/tui/ink/use-flicker-detector.js +37 -0
  166. package/dist/tui/ink/use-flicker-detector.js.map +1 -0
  167. package/dist/tui/ink/use-render-metrics.d.ts +14 -0
  168. package/dist/tui/ink/use-render-metrics.js +93 -0
  169. package/dist/tui/ink/use-render-metrics.js.map +1 -0
  170. package/dist/tui/ink/use-startup-health.d.ts +10 -0
  171. package/dist/tui/ink/use-startup-health.js +125 -0
  172. package/dist/tui/ink/use-startup-health.js.map +1 -0
  173. package/dist/tui/ink/use-transcript-scroll.d.ts +19 -0
  174. package/dist/tui/ink/use-transcript-scroll.js +83 -0
  175. package/dist/tui/ink/use-transcript-scroll.js.map +1 -0
  176. package/package.json +1 -1
@@ -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 /upgrade /config /mode and friends.
293
- // The hardcoded branches above (clear/help/model[s]/theme) ran first
294
- // because they open Ink overlays and don't fit the registry string-output
295
- // contract. Without this dispatch, unrecognised slash commands fell
296
- // through to runTurn() and were sent to the LLM as user prompts —
297
- // surprising behaviour that S1/2026-04-27 fixes.
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: () => null,
353
- setToken: () => undefined,
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 committedJsx = React.useMemo(() => renderTranscript(transcript), [transcript]);
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(Static, { items: committedStaticItems, children: ({ el }) => el }), _jsx(Box, { flexDirection: "column", children: liveJsx }), pendingApproval !== null && approvalBusRef.current && (_jsx(ApprovalPrompt, { request: pendingApproval, onResolve: (decision) => {
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>. Non-tool items render via <TranscriptRow>. The grouping
843
- * is intentionally simple — we look at adjacency, not assistant-turn
844
- * boundaries, because the projection emits tools contiguously between
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
- out.push(_jsx(TranscriptRow, { item: item }, item.id));
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) +