@dirgha/code 1.20.15 → 1.20.27

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 (294) hide show
  1. package/dist/auth/keypool.js +40 -26
  2. package/dist/auth/keypool.js.map +1 -1
  3. package/dist/auth/keystore.js +16 -11
  4. package/dist/auth/keystore.js.map +1 -1
  5. package/dist/cli/config.js +23 -2
  6. package/dist/cli/config.js.map +1 -1
  7. package/dist/cli/first-run.d.ts +6 -5
  8. package/dist/cli/first-run.js +100 -42
  9. package/dist/cli/first-run.js.map +1 -1
  10. package/dist/cli/flows/wizard.js +13 -19
  11. package/dist/cli/flows/wizard.js.map +1 -1
  12. package/dist/cli/interactive.d.ts +4 -0
  13. package/dist/cli/interactive.js +54 -10
  14. package/dist/cli/interactive.js.map +1 -1
  15. package/dist/cli/main.js +67 -18
  16. package/dist/cli/main.js.map +1 -1
  17. package/dist/cli/setup.js +4 -2
  18. package/dist/cli/setup.js.map +1 -1
  19. package/dist/cli/slash/fleet.js +19 -1
  20. package/dist/cli/slash/fleet.js.map +1 -1
  21. package/dist/cli/slash/keys.js +49 -0
  22. package/dist/cli/slash/keys.js.map +1 -1
  23. package/dist/cli/slash/login.js +7 -3
  24. package/dist/cli/slash/login.js.map +1 -1
  25. package/dist/cli/slash/models.d.ts +1 -1
  26. package/dist/cli/slash/models.js +144 -18
  27. package/dist/cli/slash/models.js.map +1 -1
  28. package/dist/cli/slash/provider.js +1 -1
  29. package/dist/cli/slash/provider.js.map +1 -1
  30. package/dist/cli/slash.js +26 -10
  31. package/dist/cli/slash.js.map +1 -1
  32. package/dist/cli/subcommands/doctor.d.ts +1 -1
  33. package/dist/cli/subcommands/doctor.js +362 -84
  34. package/dist/cli/subcommands/doctor.js.map +1 -1
  35. package/dist/cli/subcommands/keys.js +44 -0
  36. package/dist/cli/subcommands/keys.js.map +1 -1
  37. package/dist/cli/subcommands/login.js +8 -3
  38. package/dist/cli/subcommands/login.js.map +1 -1
  39. package/dist/cli/subcommands/telemetry.d.ts +2 -1
  40. package/dist/cli/subcommands/telemetry.js +47 -34
  41. package/dist/cli/subcommands/telemetry.js.map +1 -1
  42. package/dist/cli/update-check.d.ts +1 -0
  43. package/dist/cli/update-check.js +31 -7
  44. package/dist/cli/update-check.js.map +1 -1
  45. package/dist/context/branch.d.ts +2 -2
  46. package/dist/context/branch.js +40 -23
  47. package/dist/context/branch.js.map +1 -1
  48. package/dist/context/compaction.js +45 -22
  49. package/dist/context/compaction.js.map +1 -1
  50. package/dist/context/git-state.js +31 -18
  51. package/dist/context/git-state.js.map +1 -1
  52. package/dist/context/knowledge.js +31 -20
  53. package/dist/context/knowledge.js.map +1 -1
  54. package/dist/context/memory.js +7 -0
  55. package/dist/context/memory.js.map +1 -1
  56. package/dist/context/mode-enforcement.js +11 -2
  57. package/dist/context/mode-enforcement.js.map +1 -1
  58. package/dist/context/mode.js +67 -30
  59. package/dist/context/mode.js.map +1 -1
  60. package/dist/context/primer.js +15 -3
  61. package/dist/context/primer.js.map +1 -1
  62. package/dist/context/session.d.ts +1 -0
  63. package/dist/context/session.js +4 -1
  64. package/dist/context/session.js.map +1 -1
  65. package/dist/fleet/apply-back.js +5 -1
  66. package/dist/fleet/apply-back.js.map +1 -1
  67. package/dist/fleet/cli-command.d.ts +2 -0
  68. package/dist/fleet/cli-command.js +15 -1
  69. package/dist/fleet/cli-command.js.map +1 -1
  70. package/dist/fleet/runner.js +35 -2
  71. package/dist/fleet/runner.js.map +1 -1
  72. package/dist/fleet/scratchpad.js +1 -2
  73. package/dist/fleet/scratchpad.js.map +1 -1
  74. package/dist/fleet/state.d.ts +4 -0
  75. package/dist/fleet/state.js +11 -2
  76. package/dist/fleet/state.js.map +1 -1
  77. package/dist/fleet/templates.d.ts +4 -0
  78. package/dist/fleet/templates.js.map +1 -1
  79. package/dist/fleet/types.d.ts +4 -0
  80. package/dist/fleet/types.js.map +1 -1
  81. package/dist/intelligence/error-classifier.js +37 -8
  82. package/dist/intelligence/error-classifier.js.map +1 -1
  83. package/dist/intelligence/failover-chain.d.ts +24 -0
  84. package/dist/intelligence/failover-chain.js +79 -6
  85. package/dist/intelligence/failover-chain.js.map +1 -1
  86. package/dist/intelligence/health-monitor.d.ts +27 -0
  87. package/dist/intelligence/health-monitor.js +242 -0
  88. package/dist/intelligence/health-monitor.js.map +1 -0
  89. package/dist/intelligence/index.d.ts +7 -5
  90. package/dist/intelligence/index.js +7 -5
  91. package/dist/intelligence/index.js.map +1 -1
  92. package/dist/intelligence/prices.d.ts +6 -4
  93. package/dist/intelligence/prices.js +169 -40
  94. package/dist/intelligence/prices.js.map +1 -1
  95. package/dist/intelligence/remote-catalogue.d.ts +31 -0
  96. package/dist/intelligence/remote-catalogue.js +174 -0
  97. package/dist/intelligence/remote-catalogue.js.map +1 -0
  98. package/dist/intelligence/remote-config.d.ts +26 -0
  99. package/dist/intelligence/remote-config.js +80 -0
  100. package/dist/intelligence/remote-config.js.map +1 -0
  101. package/dist/kernel/agent-loop.js +73 -16
  102. package/dist/kernel/agent-loop.js.map +1 -1
  103. package/dist/lsp/client.js +29 -16
  104. package/dist/lsp/client.js.map +1 -1
  105. package/dist/lsp/detector.js +7 -6
  106. package/dist/lsp/detector.js.map +1 -1
  107. package/dist/mcp/client.d.ts +1 -1
  108. package/dist/mcp/client.js +19 -16
  109. package/dist/mcp/client.js.map +1 -1
  110. package/dist/mcp/transport.js +46 -38
  111. package/dist/mcp/transport.js.map +1 -1
  112. package/dist/parity/scenarios.d.ts +3 -3
  113. package/dist/parity/scenarios.js +77 -36
  114. package/dist/parity/scenarios.js.map +1 -1
  115. package/dist/providers/anthropic-catalogue.d.ts +9 -0
  116. package/dist/providers/anthropic-catalogue.js +90 -0
  117. package/dist/providers/anthropic-catalogue.js.map +1 -0
  118. package/dist/providers/anthropic.js +3 -1
  119. package/dist/providers/anthropic.js.map +1 -1
  120. package/dist/providers/catalogue.d.ts +34 -0
  121. package/dist/providers/catalogue.js +20 -0
  122. package/dist/providers/catalogue.js.map +1 -0
  123. package/dist/providers/cerebras-catalogue.d.ts +9 -0
  124. package/dist/providers/cerebras-catalogue.js +54 -0
  125. package/dist/providers/cerebras-catalogue.js.map +1 -0
  126. package/dist/providers/cohere-catalogue.d.ts +9 -0
  127. package/dist/providers/cohere-catalogue.js +54 -0
  128. package/dist/providers/cohere-catalogue.js.map +1 -0
  129. package/dist/providers/deepseek-catalogue.d.ts +15 -0
  130. package/dist/providers/deepseek-catalogue.js +81 -0
  131. package/dist/providers/deepseek-catalogue.js.map +1 -0
  132. package/dist/providers/deepseek.d.ts +4 -2
  133. package/dist/providers/deepseek.js +7 -23
  134. package/dist/providers/deepseek.js.map +1 -1
  135. package/dist/providers/dispatch.js +37 -28
  136. package/dist/providers/dispatch.js.map +1 -1
  137. package/dist/providers/extra-providers.js +21 -0
  138. package/dist/providers/extra-providers.js.map +1 -1
  139. package/dist/providers/family-fallback.js +3 -3
  140. package/dist/providers/family-fallback.js.map +1 -1
  141. package/dist/providers/gemini-catalogue.d.ts +9 -0
  142. package/dist/providers/gemini-catalogue.js +73 -0
  143. package/dist/providers/gemini-catalogue.js.map +1 -0
  144. package/dist/providers/gemini.js +12 -3
  145. package/dist/providers/gemini.js.map +1 -1
  146. package/dist/providers/groq-catalogue.d.ts +9 -0
  147. package/dist/providers/groq-catalogue.js +82 -0
  148. package/dist/providers/groq-catalogue.js.map +1 -0
  149. package/dist/providers/index.d.ts +11 -0
  150. package/dist/providers/index.js +29 -2
  151. package/dist/providers/index.js.map +1 -1
  152. package/dist/providers/mistral-catalogue.d.ts +9 -0
  153. package/dist/providers/mistral-catalogue.js +68 -0
  154. package/dist/providers/mistral-catalogue.js.map +1 -0
  155. package/dist/providers/nim-catalogue.d.ts +31 -0
  156. package/dist/providers/nim-catalogue.js +122 -0
  157. package/dist/providers/nim-catalogue.js.map +1 -0
  158. package/dist/providers/nvidia.js +33 -10
  159. package/dist/providers/nvidia.js.map +1 -1
  160. package/dist/providers/openai-catalogue.d.ts +9 -0
  161. package/dist/providers/openai-catalogue.js +82 -0
  162. package/dist/providers/openai-catalogue.js.map +1 -0
  163. package/dist/providers/openai-compat.js +4 -2
  164. package/dist/providers/openai-compat.js.map +1 -1
  165. package/dist/providers/perplexity-catalogue.d.ts +10 -0
  166. package/dist/providers/perplexity-catalogue.js +69 -0
  167. package/dist/providers/perplexity-catalogue.js.map +1 -0
  168. package/dist/providers/together-catalogue.d.ts +9 -0
  169. package/dist/providers/together-catalogue.js +54 -0
  170. package/dist/providers/together-catalogue.js.map +1 -0
  171. package/dist/providers/xai-catalogue.d.ts +9 -0
  172. package/dist/providers/xai-catalogue.js +54 -0
  173. package/dist/providers/xai-catalogue.js.map +1 -0
  174. package/dist/safety/audit-log.d.ts +15 -0
  175. package/dist/safety/audit-log.js +21 -0
  176. package/dist/safety/audit-log.js.map +1 -1
  177. package/dist/state/db-telemetry.d.ts +21 -0
  178. package/dist/state/db-telemetry.js +106 -0
  179. package/dist/state/db-telemetry.js.map +1 -0
  180. package/dist/state/db.js +7 -4
  181. package/dist/state/db.js.map +1 -1
  182. package/dist/telemetry/gateway-push.d.ts +17 -0
  183. package/dist/telemetry/gateway-push.js +48 -0
  184. package/dist/telemetry/gateway-push.js.map +1 -0
  185. package/dist/telemetry/index.d.ts +9 -0
  186. package/dist/telemetry/index.js +9 -0
  187. package/dist/telemetry/index.js.map +1 -0
  188. package/dist/tools/browser.js +24 -16
  189. package/dist/tools/browser.js.map +1 -1
  190. package/dist/tools/checkpoint.d.ts +6 -1
  191. package/dist/tools/checkpoint.js +79 -62
  192. package/dist/tools/checkpoint.js.map +1 -1
  193. package/dist/tools/cron.js +1 -3
  194. package/dist/tools/cron.js.map +1 -1
  195. package/dist/tools/diff.js +25 -21
  196. package/dist/tools/diff.js.map +1 -1
  197. package/dist/tools/exec.d.ts +2 -0
  198. package/dist/tools/exec.js +13 -0
  199. package/dist/tools/exec.js.map +1 -1
  200. package/dist/tools/fs-edit.d.ts +3 -5
  201. package/dist/tools/fs-edit.js +8 -23
  202. package/dist/tools/fs-edit.js.map +1 -1
  203. package/dist/tools/fs-ls.js +6 -8
  204. package/dist/tools/fs-ls.js.map +1 -1
  205. package/dist/tools/fs-read.d.ts +1 -1
  206. package/dist/tools/fs-read.js +37 -28
  207. package/dist/tools/fs-read.js.map +1 -1
  208. package/dist/tools/fs-write.d.ts +1 -1
  209. package/dist/tools/fs-write.js +33 -33
  210. package/dist/tools/fs-write.js.map +1 -1
  211. package/dist/tools/git.js +12 -6
  212. package/dist/tools/git.js.map +1 -1
  213. package/dist/tools/index.d.ts +3 -1
  214. package/dist/tools/index.js +4 -3
  215. package/dist/tools/index.js.map +1 -1
  216. package/dist/tools/multimodal.js +11 -12
  217. package/dist/tools/multimodal.js.map +1 -1
  218. package/dist/tools/rtk.js +22 -9
  219. package/dist/tools/rtk.js.map +1 -1
  220. package/dist/tools/search-glob.d.ts +1 -1
  221. package/dist/tools/search-glob.js +42 -24
  222. package/dist/tools/search-glob.js.map +1 -1
  223. package/dist/tools/search-grep.d.ts +1 -1
  224. package/dist/tools/search-grep.js +56 -32
  225. package/dist/tools/search-grep.js.map +1 -1
  226. package/dist/tools/shell.d.ts +1 -1
  227. package/dist/tools/shell.js +78 -54
  228. package/dist/tools/shell.js.map +1 -1
  229. package/dist/tui/ink/App.d.ts +5 -1
  230. package/dist/tui/ink/App.js +310 -73
  231. package/dist/tui/ink/App.js.map +1 -1
  232. package/dist/tui/ink/components/DenseToolMessage.js +23 -8
  233. package/dist/tui/ink/components/DenseToolMessage.js.map +1 -1
  234. package/dist/tui/ink/components/InputBox.d.ts +2 -0
  235. package/dist/tui/ink/components/InputBox.js +22 -25
  236. package/dist/tui/ink/components/InputBox.js.map +1 -1
  237. package/dist/tui/ink/components/KeySetOverlay.d.ts +1 -1
  238. package/dist/tui/ink/components/KeySetOverlay.js +18 -16
  239. package/dist/tui/ink/components/KeySetOverlay.js.map +1 -1
  240. package/dist/tui/ink/components/ModelPicker.d.ts +2 -2
  241. package/dist/tui/ink/components/ModelPicker.js +34 -26
  242. package/dist/tui/ink/components/ModelPicker.js.map +1 -1
  243. package/dist/tui/ink/components/PasteCollapse.d.ts +3 -1
  244. package/dist/tui/ink/components/PasteCollapse.js +11 -9
  245. package/dist/tui/ink/components/PasteCollapse.js.map +1 -1
  246. package/dist/tui/ink/components/SpinnerGlyph.d.ts +4 -4
  247. package/dist/tui/ink/components/SpinnerGlyph.js +34 -14
  248. package/dist/tui/ink/components/SpinnerGlyph.js.map +1 -1
  249. package/dist/tui/ink/components/StatusBar.d.ts +7 -0
  250. package/dist/tui/ink/components/StatusBar.js +11 -5
  251. package/dist/tui/ink/components/StatusBar.js.map +1 -1
  252. package/dist/tui/ink/components/ThinkingBlock.d.ts +15 -4
  253. package/dist/tui/ink/components/ThinkingBlock.js +34 -17
  254. package/dist/tui/ink/components/ThinkingBlock.js.map +1 -1
  255. package/dist/tui/ink/components/ToolBox.js +23 -13
  256. package/dist/tui/ink/components/ToolBox.js.map +1 -1
  257. package/dist/tui/ink/components/VirtualTranscript.d.ts +19 -0
  258. package/dist/tui/ink/components/VirtualTranscript.js +31 -0
  259. package/dist/tui/ink/components/VirtualTranscript.js.map +1 -0
  260. package/dist/tui/ink/index.d.ts +5 -1
  261. package/dist/tui/ink/index.js +19 -7
  262. package/dist/tui/ink/index.js.map +1 -1
  263. package/dist/tui/ink/markdown/syntax-highlight.d.ts +13 -0
  264. package/dist/tui/ink/markdown/syntax-highlight.js +91 -0
  265. package/dist/tui/ink/markdown/syntax-highlight.js.map +1 -0
  266. package/dist/tui/ink/use-declined-versions.d.ts +14 -0
  267. package/dist/tui/ink/use-declined-versions.js +61 -0
  268. package/dist/tui/ink/use-declined-versions.js.map +1 -0
  269. package/dist/tui/ink/use-elapsed.d.ts +6 -0
  270. package/dist/tui/ink/use-elapsed.js +46 -0
  271. package/dist/tui/ink/use-elapsed.js.map +1 -0
  272. package/dist/tui/ink/use-event-projection.js +12 -0
  273. package/dist/tui/ink/use-event-projection.js.map +1 -1
  274. package/dist/tui/ink/use-flicker-detector.d.ts +12 -0
  275. package/dist/tui/ink/use-flicker-detector.js +37 -0
  276. package/dist/tui/ink/use-flicker-detector.js.map +1 -0
  277. package/dist/tui/ink/use-overlays.js +16 -17
  278. package/dist/tui/ink/use-overlays.js.map +1 -1
  279. package/dist/tui/ink/use-render-metrics.d.ts +14 -0
  280. package/dist/tui/ink/use-render-metrics.js +97 -0
  281. package/dist/tui/ink/use-render-metrics.js.map +1 -0
  282. package/dist/tui/ink/use-startup-health.d.ts +10 -0
  283. package/dist/tui/ink/use-startup-health.js +125 -0
  284. package/dist/tui/ink/use-startup-health.js.map +1 -0
  285. package/dist/tui/ink/use-transcript-scroll.d.ts +19 -0
  286. package/dist/tui/ink/use-transcript-scroll.js +83 -0
  287. package/dist/tui/ink/use-transcript-scroll.js.map +1 -0
  288. package/dist/utils/env.d.ts +1 -0
  289. package/dist/utils/env.js +60 -0
  290. package/dist/utils/env.js.map +1 -0
  291. package/dist/utils/fs.d.ts +10 -0
  292. package/dist/utils/fs.js +37 -0
  293. package/dist/utils/fs.js.map +1 -0
  294. 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";
@@ -26,6 +27,7 @@ import { loadProjectPrimer, composeSystemPrompt, } from "../../context/primer.js
26
27
  import { queryKb } from "../../context/kb-query.js";
27
28
  import { probeGitState, renderGitState } from "../../context/git-state.js";
28
29
  import { loadSoul } from "../../context/soul.js";
30
+ import { routeModel } from "../../providers/dispatch.js";
29
31
  import { isAutoApprove, modePreamble } from "../../context/mode.js";
30
32
  import { runAgentLoop } from "../../kernel/agent-loop.js";
31
33
  import { createErrorClassifier } from "../../intelligence/error-classifier.js";
@@ -36,7 +38,7 @@ import { PRICES } from "../../intelligence/prices.js";
36
38
  import { Logo } from "./components/Logo.js";
37
39
  import { StatusBar } from "./components/StatusBar.js";
38
40
  import { StreamingText } from "./components/StreamingText.js";
39
- import { ThinkingBlock } from "./components/ThinkingBlock.js";
41
+ import { ThinkingBlock, ThinkingBlockGroup, } from "./components/ThinkingBlock.js";
40
42
  import { ToolBox } from "./components/ToolBox.js";
41
43
  import { ToolGroup } from "./components/ToolGroup.js";
42
44
  import { InputBox } from "./components/InputBox.js";
@@ -48,16 +50,24 @@ import { HelpOverlay, } from "./components/HelpOverlay.js";
48
50
  import { KeySetOverlay } from "./components/KeySetOverlay.js";
49
51
  import { saveKey } from "../../auth/keystore.js";
50
52
  import { loadToken, migrateLegacyAuth, } from "../../integrations/device-auth.js";
53
+ import { getUpdateBannerVersion } from "../../cli/update-check.js";
51
54
  import { AtFileComplete } from "./components/AtFileComplete.js";
52
55
  import { SlashComplete } from "./components/SlashComplete.js";
53
56
  import { ThemePicker } from "./components/ThemePicker.js";
54
- import { ThemeProvider } from "./theme-context.js";
57
+ import { ThemeProvider, useTheme } from "./theme-context.js";
55
58
  import { SpinnerContext } from "./spinner-context.js";
59
+ import { SpinnerGlyph } from "./components/SpinnerGlyph.js";
56
60
  import { writeFile, mkdir, readFile } from "node:fs/promises";
61
+ import { readFileSync, existsSync } from "node:fs";
57
62
  import { homedir } from "node:os";
58
63
  import { join as pathJoin } from "node:path";
59
64
  import { useEventProjection, } from "./use-event-projection.js";
60
65
  import { useOverlays } from "./use-overlays.js";
66
+ import { useDeclinedVersions } from "./use-declined-versions.js";
67
+ import { useStartupHealth } from "./use-startup-health.js";
68
+ import { useFlickerDetector } from "./use-flicker-detector.js";
69
+ import { useRenderMetrics, } from "./use-render-metrics.js";
70
+ import { getRemoteConfig, isVersionBelowMin, } from "../../intelligence/remote-config.js";
61
71
  import { createRequire } from "node:module";
62
72
  // Pulled from the installed package.json so the TUI title matches the
63
73
  // shipped binary version. Falls back to '0.0.0-dev' if the file isn't
@@ -72,15 +82,41 @@ const VERSION = (() => {
72
82
  return "0.0.0-dev";
73
83
  }
74
84
  })();
85
+ // Cache for initialHistory — avoids sync fs I/O in the render phase
86
+ // on re-calls (e.g. /clear). The underlying files rarely change within
87
+ // a session so a single snapshot is sufficient.
88
+ let _cachedInitialMessages = null;
75
89
  export function App(props) {
76
90
  const { exit } = useApp();
77
91
  const sessionIdRef = React.useRef(randomUUID());
78
92
  const historyRef = React.useRef(initialHistory(props));
79
93
  const abortRef = React.useRef(null);
80
94
  const pendingModelRef = React.useRef(null);
95
+ const sessionRef = React.useRef(null);
96
+ React.useEffect(() => {
97
+ const id = sessionIdRef.current;
98
+ void props.sessions.create(id).then((s) => {
99
+ sessionRef.current = s;
100
+ if (props.sessionHandle)
101
+ props.sessionHandle.session = s;
102
+ });
103
+ return () => {
104
+ if (sessionRef.current) {
105
+ try {
106
+ sessionRef.current.close();
107
+ }
108
+ catch {
109
+ /* swallow */
110
+ }
111
+ if (props.sessionHandle)
112
+ props.sessionHandle.session = null;
113
+ }
114
+ };
115
+ }, [props.sessions, props.sessionHandle]);
81
116
  const [transcript, setTranscript] = React.useState([]);
82
117
  const [input, setInput] = React.useState("");
83
118
  const [busy, setBusy] = React.useState(false);
119
+ const [thinkingStreaming, setThinkingStreaming] = React.useState(false);
84
120
  // Prompt queue: while a turn is streaming the user can still type and
85
121
  // press Enter. Submissions land here instead of being dropped, then
86
122
  // drain FIFO when the turn finishes (see useEffect below).
@@ -147,6 +183,116 @@ export function App(props) {
147
183
  const [liveDurationMs, setLiveDurationMs] = React.useState(0);
148
184
  const turnStartRef = React.useRef(0);
149
185
  const liveOutputTokensAccRef = React.useRef(0);
186
+ const [updateVersion, setUpdateVersion] = React.useState(null);
187
+ const updateShownRef = React.useRef(false);
188
+ const declined = useDeclinedVersions();
189
+ React.useEffect(() => {
190
+ if (updateShownRef.current)
191
+ return;
192
+ updateShownRef.current = true;
193
+ getUpdateBannerVersion(VERSION).then((v) => {
194
+ if (v && !declined.isDeclined(v))
195
+ setUpdateVersion(v);
196
+ });
197
+ }, [declined]);
198
+ // Startup health check — non-blocking, cached for 24h.
199
+ const healthResult = useStartupHealth();
200
+ // Flicker detector — compares estimated tree height to terminal rows.
201
+ const estimatedLineCount = (transcript.length + projection.liveItems.length) * 2 + 15;
202
+ const flicker = useFlickerDetector(estimatedLineCount);
203
+ // Render performance metrics — track frame timing, expose for StatusBar.
204
+ const renderMetrics = useRenderMetrics();
205
+ const [showRenderMetrics, setShowRenderMetrics] = React.useState(false);
206
+ // Alt+M toggles the render-metrics display in the StatusBar.
207
+ useInput((ch, key) => {
208
+ if (key.meta && ch === "m") {
209
+ setShowRenderMetrics((v) => !v);
210
+ }
211
+ });
212
+ // Remote config: fetch once on mount, set model default, show MOTD.
213
+ const [remoteConfig, setRemoteConfig] = React.useState(null);
214
+ const [motdShown, setMotdShown] = React.useState(false);
215
+ const [remoteConfigFetched, setRemoteConfigFetched] = React.useState(false);
216
+ React.useEffect(() => {
217
+ if (remoteConfigFetched)
218
+ return;
219
+ setRemoteConfigFetched(true);
220
+ void getRemoteConfig().then((cfg) => {
221
+ if (cfg)
222
+ setRemoteConfig(cfg);
223
+ });
224
+ }, [remoteConfigFetched]);
225
+ // Apply remote config model default on first load if no explicit model set.
226
+ const remoteModelAppliedRef = React.useRef(false);
227
+ React.useEffect(() => {
228
+ if (!remoteConfig || remoteModelAppliedRef.current)
229
+ return;
230
+ remoteModelAppliedRef.current = true;
231
+ const explicit = props.config.model;
232
+ const hasDefault = explicit !== undefined &&
233
+ explicit !== "" &&
234
+ explicit !== "accounts/fireworks/routers/kimi-k2p5-turbo";
235
+ if (!hasDefault && remoteConfig.recommendedModel) {
236
+ setCurrentModel(remoteConfig.recommendedModel);
237
+ }
238
+ }, [remoteConfig, props.config.model]);
239
+ // Show MOTD once per session.
240
+ React.useEffect(() => {
241
+ if (!remoteConfig?.motd || motdShown)
242
+ return;
243
+ setMotdShown(true);
244
+ const note = {
245
+ kind: "notice",
246
+ id: randomUUID(),
247
+ text: remoteConfig.motd,
248
+ };
249
+ setTranscript((prev) => [...prev, note]);
250
+ }, [remoteConfig, motdShown]);
251
+ // Warn about deprecated models if the current model is in the list.
252
+ const deprecatedWarnedRef = React.useRef(false);
253
+ React.useEffect(() => {
254
+ if (!remoteConfig || deprecatedWarnedRef.current)
255
+ return;
256
+ if (remoteConfig.deprecatedModels.length > 0 &&
257
+ remoteConfig.deprecatedModels.includes(currentModel)) {
258
+ deprecatedWarnedRef.current = true;
259
+ const note = {
260
+ kind: "notice",
261
+ id: randomUUID(),
262
+ text: `[DEPRECATED] Model ${currentModel} is deprecated. Switch to ${remoteConfig.recommendedModel ?? "a supported model"} via /model.`,
263
+ };
264
+ setTranscript((prev) => [...prev, note]);
265
+ }
266
+ }, [remoteConfig, currentModel]);
267
+ // Minimum version nag: show upgrade banner immediately if below minimum.
268
+ const [minVersionNagShown, setMinVersionNagShown] = React.useState(false);
269
+ React.useEffect(() => {
270
+ if (!remoteConfig || minVersionNagShown)
271
+ return;
272
+ if (isVersionBelowMin(VERSION, remoteConfig.minimumVersion)) {
273
+ setMinVersionNagShown(true);
274
+ setUpdateVersion(remoteConfig.minimumVersion);
275
+ }
276
+ }, [remoteConfig, minVersionNagShown]);
277
+ // Self-upgrade handler (Ctrl+U or /upgrade).
278
+ const handleUpgrade = React.useCallback(() => {
279
+ void (async () => {
280
+ try {
281
+ const { execFileSync } = await import("node:child_process");
282
+ const isWin = process.platform === "win32";
283
+ const npmBin = isWin ? "npm.cmd" : "npm";
284
+ execFileSync(npmBin, ["i", "-g", "@dirgha/code@latest"], {
285
+ stdio: "inherit",
286
+ shell: isWin,
287
+ });
288
+ }
289
+ catch {
290
+ /* fall through to exit */
291
+ }
292
+ exit();
293
+ process.exit(0);
294
+ })();
295
+ }, [exit]);
150
296
  React.useEffect(() => {
151
297
  const unsub = props.events.subscribe((ev) => {
152
298
  if (ev.type === "agent_start") {
@@ -154,8 +300,18 @@ export function App(props) {
154
300
  liveOutputTokensAccRef.current = 0;
155
301
  setLiveOutputTokens(0);
156
302
  setLiveDurationMs(0);
303
+ setThinkingStreaming(false);
304
+ }
305
+ else if (ev.type === "thinking_start") {
306
+ setThinkingStreaming(true);
307
+ }
308
+ else if (ev.type === "thinking_end") {
309
+ setThinkingStreaming(false);
157
310
  }
158
311
  else if (ev.type === "text_delta" || ev.type === "thinking_delta") {
312
+ // Approximate tokens as chars ÷ 4 — a common heuristic for English
313
+ // text where avg token length is ~4 characters. Not exact but keeps
314
+ // the tok/s rate plausible without an expensive tokenizer.
159
315
  liveOutputTokensAccRef.current += (ev.delta?.length ?? 0) / 4;
160
316
  }
161
317
  else if (ev.type === "usage") {
@@ -258,7 +414,7 @@ export function App(props) {
258
414
  });
259
415
  // A new submission supersedes any pending failover prompt.
260
416
  setPendingFailover(null);
261
- if (value === "/exit" || value === "/quit") {
417
+ if (value === "/exit" || value === "/quit" || value === "/stop") {
262
418
  exit();
263
419
  return;
264
420
  }
@@ -276,23 +432,36 @@ export function App(props) {
276
432
  if (value.startsWith("/model ")) {
277
433
  const id = value.slice("/model ".length).trim();
278
434
  if (id !== "") {
279
- const valid = PRICES.some((p) => p.model === id);
280
- if (!valid) {
435
+ // Exact match first, then suffix fallback — mirrors slash.ts /model handler.
436
+ const exactMatch = PRICES.find((p) => p.model === id);
437
+ if (exactMatch) {
438
+ setCurrentModel(exactMatch.model);
281
439
  const note = {
282
440
  kind: "notice",
283
441
  id: randomUUID(),
284
- text: `Invalid model: ${id}. Use /models to see the catalogue.`,
442
+ text: `Model set to ${exactMatch.model}`,
285
443
  };
286
444
  setTranscript((prev) => [...prev, note]);
287
445
  }
288
446
  else {
289
- setCurrentModel(id);
290
- const note = {
291
- kind: "notice",
292
- id: randomUUID(),
293
- text: `Model set to ${id}`,
294
- };
295
- setTranscript((prev) => [...prev, note]);
447
+ const suffixMatch = PRICES.find((p) => p.model.endsWith("/" + id));
448
+ if (suffixMatch) {
449
+ setCurrentModel(suffixMatch.model);
450
+ const note = {
451
+ kind: "notice",
452
+ id: randomUUID(),
453
+ text: `Model set to ${suffixMatch.model}`,
454
+ };
455
+ setTranscript((prev) => [...prev, note]);
456
+ }
457
+ else {
458
+ const note = {
459
+ kind: "notice",
460
+ id: randomUUID(),
461
+ text: `Invalid model: ${id}. Use /models to see the catalogue.`,
462
+ };
463
+ setTranscript((prev) => [...prev, note]);
464
+ }
296
465
  }
297
466
  }
298
467
  return;
@@ -306,14 +475,28 @@ export function App(props) {
306
475
  overlays.openOverlay("theme");
307
476
  return;
308
477
  }
478
+ // /upgrade and /self-update trigger npm install + restart.
479
+ if (value === "/upgrade" ||
480
+ value === "/self-update" ||
481
+ value === "/update --self") {
482
+ const note = {
483
+ kind: "notice",
484
+ id: randomUUID(),
485
+ text: "Upgrading @dirgha/code to latest via npm…",
486
+ };
487
+ setTranscript((prev) => [...prev, note]);
488
+ handleUpgrade();
489
+ return;
490
+ }
309
491
  // Anything else starting with `/` goes through the SlashRegistry — that
310
492
  // covers /init /keys /memory /compact /setup /login /status /resume
311
- // /session /history /fleet /account /upgrade /config /mode and friends.
312
- // The hardcoded branches above (clear/help/model[s]/theme) ran first
313
- // because they open Ink overlays and don't fit the registry string-output
314
- // contract. Without this dispatch, unrecognised slash commands fell
315
- // through to runTurn() and were sent to the LLM as user prompts —
316
- // surprising behaviour that S1/2026-04-27 fixes.
493
+ // /session /history /fleet /account /config /mode and friends.
494
+ // The hardcoded branches above (clear/help/model[s]/theme/upgrade) ran first
495
+ // because they open Ink overlays or trigger self-upgrade and don't fit
496
+ // the registry string-output contract. Without this dispatch,
497
+ // unrecognised slash commands fell through to runTurn() and were sent
498
+ // to the LLM as user prompts — surprising behaviour that S1/2026-04-27
499
+ // fixes.
317
500
  if (value.startsWith("/")) {
318
501
  const ctx = {
319
502
  get model() {
@@ -368,7 +551,11 @@ export function App(props) {
368
551
  exit();
369
552
  process.exit(code);
370
553
  },
371
- getToken: () => tokenRef.current,
554
+ getToken: () => {
555
+ // Token loads asynchronously after mount; return null
556
+ // gracefully so slash commands don't crash on first call.
557
+ return tokenRef.current;
558
+ },
372
559
  setToken: (newToken) => {
373
560
  tokenRef.current = newToken;
374
561
  },
@@ -436,6 +623,11 @@ export function App(props) {
436
623
  };
437
624
  setTranscript((prev) => [...prev, userItem]);
438
625
  historyRef.current.push({ role: "user", content: value });
626
+ void sessionRef.current?.append({
627
+ type: "message",
628
+ ts: new Date().toISOString(),
629
+ message: { role: "user", content: value },
630
+ });
439
631
  void runTurnRef.current();
440
632
  }, [
441
633
  busy,
@@ -456,6 +648,7 @@ export function App(props) {
456
648
  overlays.setSlashQuery,
457
649
  overlays.setActive,
458
650
  overlays.active,
651
+ handleUpgrade,
459
652
  ]);
460
653
  const runTurn = async () => {
461
654
  setBusy(true);
@@ -523,6 +716,7 @@ export function App(props) {
523
716
  const userHooks = buildAgentHooksFromConfig(props.config);
524
717
  const composedHooks = composeHooks(enforceMode(mode), userHooks);
525
718
  const autoApprove = isAutoApprove(mode);
719
+ const prevHistoryLen = historyRef.current.length;
526
720
  const result = await runAgentLoop({
527
721
  sessionId: sessionIdRef.current,
528
722
  model: currentModel,
@@ -540,10 +734,20 @@ export function App(props) {
540
734
  ...(composedHooks !== undefined ? { hooks: composedHooks } : {}),
541
735
  });
542
736
  historyRef.current = result.messages;
737
+ for (const msg of result.messages.slice(prevHistoryLen)) {
738
+ void sessionRef.current?.append({
739
+ type: "message",
740
+ ts: new Date().toISOString(),
741
+ message: msg,
742
+ });
743
+ }
543
744
  }
544
745
  catch (err) {
545
746
  const msg = err instanceof Error ? err.message : String(err);
546
- const keyMatch = /^([A-Z][A-Z0-9_]+_API_KEY) is required/.exec(msg);
747
+ // Only match provider-key errors, not errors from deep inside the agent
748
+ // loop that happen to contain a similar pattern. The message must start
749
+ // with the key name and end with "is required" to qualify.
750
+ const keyMatch = /^([A-Z][A-Z0-9_]+_API_KEY) is required$/.exec(msg);
547
751
  if (keyMatch?.[1]) {
548
752
  setPendingKey({
549
753
  keyName: keyMatch[1],
@@ -566,7 +770,12 @@ export function App(props) {
566
770
  abortRef.current = null;
567
771
  }
568
772
  };
569
- runTurnRef.current = runTurn;
773
+ // Keep runTurnRef pointed at the latest runTurn closure so
774
+ // handleSubmit always calls the current version without adding
775
+ // runTurn's deps to handleSubmit's dependency array.
776
+ React.useEffect(() => {
777
+ runTurnRef.current = runTurn;
778
+ });
570
779
  // Drain the prompt queue when a turn finishes. Pops the oldest queued
571
780
  // prompt and re-submits it through handleSubmit (which transitions
572
781
  // back into busy=true via runTurn). Guarded on `!busy` so we never
@@ -586,6 +795,8 @@ export function App(props) {
586
795
  // 2. If a turn is streaming → abort it (cancels the in-flight LLM
587
796
  // request via the AbortController plumbed through runAgentLoop).
588
797
  // 3. If the input box has draft text → clear it.
798
+ // (step 3 is skipped when vimMode is on — InputBox's own handler
799
+ // enters NORMAL mode; clearing here would destroy the text.)
589
800
  // Always active so Esc behaves like the user expects regardless of
590
801
  // which surface they're looking at. The atfile overlay handles its
591
802
  // own Esc (cancel completion) so we skip step 1 there.
@@ -605,12 +816,13 @@ export function App(props) {
605
816
  });
606
817
  return;
607
818
  }
608
- if (input.length > 0)
819
+ if (input.length > 0 && props.config.vimMode !== true)
609
820
  setInput("");
610
821
  });
611
822
  // Ctrl-C handler: if a turn is running, abort it and show "[Interrupted]"
612
823
  // in the transcript (matching the readline path in src/cli/interactive.ts).
613
- // If idle, let the process exit normally via app.exit().
824
+ // Idle exit is handled by InputBox's own Ctrl-C handler (2-press safety
825
+ // within 1.5s) — we don't override that here.
614
826
  useInput((ch, key) => {
615
827
  if (!(key.ctrl && ch === "c"))
616
828
  return;
@@ -622,9 +834,6 @@ export function App(props) {
622
834
  text: "[Interrupted]",
623
835
  });
624
836
  }
625
- else {
626
- exit();
627
- }
628
837
  });
629
838
  const handleModelPick = React.useCallback((id) => {
630
839
  overlays.closeOverlay();
@@ -649,7 +858,7 @@ export function App(props) {
649
858
  }
650
859
  catch (err) {
651
860
  const msg = err instanceof Error ? err.message : String(err);
652
- const m = /([A-Z][A-Z0-9_]+_API_KEY) is required/.exec(msg);
861
+ const m = /^([A-Z][A-Z0-9_]+_API_KEY) is required$/.exec(msg);
653
862
  if (m?.[1]) {
654
863
  // Open inline key entry instead of a static hint — the user can
655
864
  // paste their key right here without leaving the REPL.
@@ -789,19 +998,10 @@ export function App(props) {
789
998
  }
790
999
  })();
791
1000
  }, [overlays]);
792
- const committedJsx = React.useMemo(() => renderTranscript(transcript), [transcript]);
793
- // Gemini CLI approach: freeze committed history inside <Static>
794
- // so Ink caches the output and never re-renders it. Without this,
795
- // every streaming flush tick re-conciles the entire transcript
796
- // against the terminal — causing visible flicker/jitter.
797
- const committedStaticItems = React.useMemo(() => committedJsx.map((el, i) => ({
798
- key: el?.key ?? `c-${i}`,
799
- el,
800
- })), [committedJsx]);
801
- const liveJsx = React.useMemo(() => renderTranscript(projection.liveItems), [projection.liveItems]);
1001
+ const liveJsx = React.useMemo(() => renderTranscript(projection.liveItems, thinkingStreaming), [projection.liveItems, thinkingStreaming]);
802
1002
  const providerEntries = React.useMemo(() => buildProviderEntries(models, currentModel), [models, currentModel]);
803
1003
  const LOGO_ITEMS = React.useMemo(() => [{ key: "logo" }], []);
804
- 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) => {
1004
+ 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) => {
805
1005
  approvalBusRef.current?.resolve(pendingApproval.id, decision);
806
1006
  } })), pendingFailover !== null && (_jsx(ModelSwitchPrompt, { failedModel: pendingFailover.failedModel, failoverModel: pendingFailover.failoverModel, onAccept: (failover) => {
807
1007
  const lastPrompt = pendingFailover.lastPrompt;
@@ -827,7 +1027,7 @@ export function App(props) {
827
1027
  : "YOLO mode OFF — back to standard confirmation.",
828
1028
  },
829
1029
  ]);
830
- }, inputFocus: inputFocus }), overlays.active === "atfile" && overlays.atQuery !== null && (_jsx(AtFileComplete, { cwd: props.cwd, query: overlays.atQuery, onPick: handleAtPick, onCancel: () => {
1030
+ }, 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: () => {
831
1031
  overlays.setAtQuery(null);
832
1032
  overlays.setActive(null);
833
1033
  } })), overlays.active === "slash" && overlays.slashQuery !== null && (_jsx(SlashComplete, { commands: slashCommands, query: overlays.slashQuery, onPick: handleSlashPick, onCancel: () => {
@@ -856,28 +1056,40 @@ export function App(props) {
856
1056
  // Esc inside ModelPicker → back to ProviderPicker (NOT close).
857
1057
  setPickerStage("provider");
858
1058
  setPickerProvider(null);
859
- } })), 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 })] }) }) }));
1059
+ } })), 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 })] }) }) }));
860
1060
  }
861
1061
  /**
862
1062
  * Walk the transcript and fold consecutive `tool` items into a single
863
- * <ToolGroup>. Non-tool items render via <TranscriptRow>. The grouping
864
- * is intentionally simple — we look at adjacency, not assistant-turn
865
- * boundaries, because the projection emits tools contiguously between
866
- * `text` spans of the same turn.
1063
+ * <ToolGroup>. Fold 3+ consecutive `thinking` items into a single
1064
+ * <ThinkingBlockGroup>. Non-tool / non-thinking items render via
1065
+ * <TranscriptRow>.
867
1066
  */
868
- function renderTranscript(items) {
1067
+ function renderTranscript(items, thinkingStreaming) {
869
1068
  const out = [];
870
1069
  let toolBuf = [];
1070
+ let thinkBuf = [];
871
1071
  const flushTools = () => {
872
1072
  if (toolBuf.length === 0)
873
1073
  return;
874
- // Key on the stable ID of the first tool so React never unmounts/remounts
875
- // the ToolGroup subtree when the counter resets (which caused flicker).
876
1074
  out.push(_jsx(ToolGroup, { tools: toolBuf }, toolBuf[0].id));
877
1075
  toolBuf = [];
878
1076
  };
1077
+ const flushThinking = () => {
1078
+ if (thinkBuf.length === 0)
1079
+ return;
1080
+ if (thinkBuf.length >= 3) {
1081
+ out.push(_jsx(ThinkingBlockGroup, { blocks: thinkBuf }, thinkBuf[0].id));
1082
+ }
1083
+ else {
1084
+ for (const tb of thinkBuf) {
1085
+ out.push(_jsx(TranscriptRow, { item: { kind: "thinking", id: tb.id, content: tb.content }, isStreaming: thinkingStreaming }, tb.id));
1086
+ }
1087
+ }
1088
+ thinkBuf = [];
1089
+ };
879
1090
  for (const item of items) {
880
1091
  if (item.kind === "tool") {
1092
+ flushThinking();
881
1093
  toolBuf.push({
882
1094
  id: item.id,
883
1095
  name: item.name,
@@ -890,20 +1102,27 @@ function renderTranscript(items) {
890
1102
  });
891
1103
  continue;
892
1104
  }
1105
+ if (item.kind === "thinking") {
1106
+ flushTools();
1107
+ thinkBuf.push({ id: item.id, content: item.content });
1108
+ continue;
1109
+ }
893
1110
  flushTools();
894
- out.push(_jsx(TranscriptRow, { item: item }, item.id));
1111
+ flushThinking();
1112
+ out.push(_jsx(TranscriptRow, { item: item, isStreaming: thinkingStreaming }, item.id));
895
1113
  }
896
1114
  flushTools();
1115
+ flushThinking();
897
1116
  return out;
898
1117
  }
899
- function TranscriptRow({ item, }) {
1118
+ function TranscriptRow({ item, isStreaming = false, }) {
900
1119
  switch (item.kind) {
901
1120
  case "user":
902
1121
  return (_jsxs(Box, { gap: 2, marginBottom: 1, children: [_jsx(Text, { color: "magenta", children: "\u276F" }), _jsx(Text, { color: "white", children: item.text })] }));
903
1122
  case "text":
904
1123
  return _jsx(StreamingText, { content: item.content });
905
1124
  case "thinking":
906
- return _jsx(ThinkingBlock, { content: item.content });
1125
+ return _jsx(ThinkingBlock, { content: item.content, isStreaming: isStreaming });
907
1126
  case "tool":
908
1127
  // Should not be reached — tools are folded by renderTranscript() into
909
1128
  // <ToolGroup>. Kept as a safety net so an unexpected tool item still
@@ -915,7 +1134,13 @@ function TranscriptRow({ item, }) {
915
1134
  return (_jsx(Box, { marginBottom: 1, children: _jsx(Text, { color: "yellow", children: item.text }) }));
916
1135
  }
917
1136
  }
1137
+ function GeneratingIndicator() {
1138
+ const palette = useTheme();
1139
+ 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" })] }));
1140
+ }
918
1141
  function initialHistory(props) {
1142
+ if (_cachedInitialMessages !== null)
1143
+ return _cachedInitialMessages;
919
1144
  const base = props.initialMessages ? [...props.initialMessages] : [];
920
1145
  // Boot context: mode preamble + project primer (DIRGHA.md) +
921
1146
  // caller's --system. Without this, the Ink TUI starts with zero
@@ -932,30 +1157,18 @@ function initialHistory(props) {
932
1157
  userSystem: props.systemPrompt,
933
1158
  });
934
1159
  base.unshift({ role: "system", content: composedSystem });
1160
+ _cachedInitialMessages = base;
935
1161
  return base;
936
1162
  }
937
1163
  function providerIdForModel(model) {
938
- // Light heuristic so StatusBar has a hint without importing dispatch.
939
- // Real routing still lives in providers/dispatch.ts at run time.
940
- if (model.includes("claude"))
941
- return "anthropic";
942
- if (model.includes("gpt") || model.startsWith("o1") || model.startsWith("o3"))
943
- return "openai";
944
- if (model.includes("gemini"))
945
- return "gemini";
946
- if (model.includes("deepseek"))
947
- return "deepseek";
948
- if (model.includes("kimi") || model.includes("moonshot"))
949
- return "nvidia";
950
- if (model.includes("llama") ||
951
- model.includes("nvidia") ||
952
- model.includes("minimax"))
953
- return "nvidia";
954
- if (model.includes("fireworks"))
955
- return "fireworks";
956
- if (model.includes("/"))
957
- return "openrouter";
958
- return "local";
1164
+ // Delegate to providers/dispatch.ts so the StatusBar readout
1165
+ // matches the actual runtime routing at all times.
1166
+ try {
1167
+ return routeModel(model);
1168
+ }
1169
+ catch {
1170
+ return "local";
1171
+ }
959
1172
  }
960
1173
  const PROVIDER_BLURB = {
961
1174
  anthropic: "Claude — Opus, Sonnet, Haiku",
@@ -1014,6 +1227,24 @@ const PROVIDER_LABEL = {
1014
1227
  zai: "Z.AI / GLM",
1015
1228
  local: "Local",
1016
1229
  };
1230
+ /**
1231
+ * Synchronously check whether an env var exists in ~/.dirgha/keys.json.
1232
+ * Used by buildProviderEntries as a fallback when process.env doesn't
1233
+ * contain the key yet (race with startup hydration).
1234
+ */
1235
+ function tryReadKeyFromStore(envVar) {
1236
+ try {
1237
+ const path = pathJoin(homedir(), ".dirgha", "keys.json");
1238
+ if (!existsSync(path))
1239
+ return false;
1240
+ const raw = readFileSync(path, "utf8");
1241
+ const store = JSON.parse(raw);
1242
+ return typeof store[envVar] === "string" && store[envVar].length > 0;
1243
+ }
1244
+ catch {
1245
+ return false;
1246
+ }
1247
+ }
1017
1248
  /**
1018
1249
  * Group the flat model catalogue into per-provider entries for stage 1
1019
1250
  * of the picker. Skips providers with zero models in the catalogue.
@@ -1029,7 +1260,13 @@ function buildProviderEntries(models, currentModel) {
1029
1260
  const out = [];
1030
1261
  for (const [id, items] of buckets) {
1031
1262
  const env = PROVIDER_ENV[id];
1032
- const hasKey = env ? !!process.env[env] : true; // local providers don't need keys
1263
+ // Check env vars AND keys.json (env vars win). keys.json is hydrated
1264
+ // into process.env by hydrateEnvFromKeyStore at startup, but this
1265
+ // synchronous fallback handles the edge case where hydration hasn't
1266
+ // run yet (e.g. TUI mounts before startup hydration completes).
1267
+ const hasKey = env
1268
+ ? !!process.env[env] || !!tryReadKeyFromStore(env)
1269
+ : true; // local providers don't need keys
1033
1270
  out.push({
1034
1271
  id,
1035
1272
  label: PROVIDER_LABEL[id] ?? id,