@dirgha/code 1.20.39 → 1.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. package/CHANGELOG.md +0 -57
  2. package/README.md +4 -8
  3. package/dist/auth/keypool.js +26 -40
  4. package/dist/auth/keypool.js.map +1 -1
  5. package/dist/auth/keystore.js +11 -16
  6. package/dist/auth/keystore.js.map +1 -1
  7. package/dist/cli/config.d.ts +5 -8
  8. package/dist/cli/config.js +3 -24
  9. package/dist/cli/config.js.map +1 -1
  10. package/dist/cli/first-run.js +24 -40
  11. package/dist/cli/first-run.js.map +1 -1
  12. package/dist/cli/flows/wizard.js +18 -12
  13. package/dist/cli/flows/wizard.js.map +1 -1
  14. package/dist/cli/interactive.d.ts +0 -4
  15. package/dist/cli/interactive.js +1 -29
  16. package/dist/cli/interactive.js.map +1 -1
  17. package/dist/cli/main.js +18 -69
  18. package/dist/cli/main.js.map +1 -1
  19. package/dist/cli/slash/fleet.js +1 -19
  20. package/dist/cli/slash/fleet.js.map +1 -1
  21. package/dist/cli/slash/models.js +2 -4
  22. package/dist/cli/slash/models.js.map +1 -1
  23. package/dist/cli/slash/paste.js +7 -4
  24. package/dist/cli/slash/paste.js.map +1 -1
  25. package/dist/cli/slash.js +10 -26
  26. package/dist/cli/slash.js.map +1 -1
  27. package/dist/cli/subcommands/audit.js +8 -28
  28. package/dist/cli/subcommands/audit.js.map +1 -1
  29. package/dist/cli/subcommands/doctor.d.ts +0 -4
  30. package/dist/cli/subcommands/doctor.js +21 -82
  31. package/dist/cli/subcommands/doctor.js.map +1 -1
  32. package/dist/cli/subcommands/feature-setup.js +6 -6
  33. package/dist/cli/subcommands/feature-setup.js.map +1 -1
  34. package/dist/cli/subcommands/memory.js +0 -23
  35. package/dist/cli/subcommands/memory.js.map +1 -1
  36. package/dist/cli/subcommands/telemetry.d.ts +1 -2
  37. package/dist/cli/subcommands/telemetry.js +34 -47
  38. package/dist/cli/subcommands/telemetry.js.map +1 -1
  39. package/dist/context/branch.d.ts +2 -2
  40. package/dist/context/branch.js +23 -40
  41. package/dist/context/branch.js.map +1 -1
  42. package/dist/context/compaction.js +22 -45
  43. package/dist/context/compaction.js.map +1 -1
  44. package/dist/context/git-state.js +18 -31
  45. package/dist/context/git-state.js.map +1 -1
  46. package/dist/context/knowledge.js +20 -31
  47. package/dist/context/knowledge.js.map +1 -1
  48. package/dist/context/memory.js +1 -8
  49. package/dist/context/memory.js.map +1 -1
  50. package/dist/context/mode-enforcement.js +1 -11
  51. package/dist/context/mode-enforcement.js.map +1 -1
  52. package/dist/context/mode.js +30 -67
  53. package/dist/context/mode.js.map +1 -1
  54. package/dist/context/primer.js +3 -15
  55. package/dist/context/primer.js.map +1 -1
  56. package/dist/fleet/apply-back.js +1 -5
  57. package/dist/fleet/apply-back.js.map +1 -1
  58. package/dist/fleet/cli-command.d.ts +0 -2
  59. package/dist/fleet/cli-command.js +1 -15
  60. package/dist/fleet/cli-command.js.map +1 -1
  61. package/dist/fleet/runner.js +2 -35
  62. package/dist/fleet/runner.js.map +1 -1
  63. package/dist/fleet/scratchpad.js +2 -1
  64. package/dist/fleet/scratchpad.js.map +1 -1
  65. package/dist/fleet/state.d.ts +0 -4
  66. package/dist/fleet/state.js +2 -11
  67. package/dist/fleet/state.js.map +1 -1
  68. package/dist/fleet/templates.d.ts +0 -4
  69. package/dist/fleet/templates.js.map +1 -1
  70. package/dist/fleet/types.d.ts +0 -4
  71. package/dist/fleet/types.js.map +1 -1
  72. package/dist/intelligence/failover-chain.js +1 -10
  73. package/dist/intelligence/failover-chain.js.map +1 -1
  74. package/dist/intelligence/health-monitor.d.ts +8 -8
  75. package/dist/intelligence/health-monitor.js +74 -105
  76. package/dist/intelligence/health-monitor.js.map +1 -1
  77. package/dist/intelligence/prices.d.ts +4 -6
  78. package/dist/intelligence/prices.js +10 -36
  79. package/dist/intelligence/prices.js.map +1 -1
  80. package/dist/kernel/agent-loop.js +17 -60
  81. package/dist/kernel/agent-loop.js.map +1 -1
  82. package/dist/lsp/client.js +16 -29
  83. package/dist/lsp/client.js.map +1 -1
  84. package/dist/lsp/detector.js +6 -7
  85. package/dist/lsp/detector.js.map +1 -1
  86. package/dist/mcp/client.d.ts +1 -1
  87. package/dist/mcp/client.js +16 -19
  88. package/dist/mcp/client.js.map +1 -1
  89. package/dist/mcp/transport.js +38 -46
  90. package/dist/mcp/transport.js.map +1 -1
  91. package/dist/providers/deepseek.js +1 -1
  92. package/dist/providers/deepseek.js.map +1 -1
  93. package/dist/providers/dispatch.js +1 -15
  94. package/dist/providers/dispatch.js.map +1 -1
  95. package/dist/providers/index.d.ts +0 -11
  96. package/dist/providers/index.js +2 -29
  97. package/dist/providers/index.js.map +1 -1
  98. package/dist/providers/nvidia.js +1 -1
  99. package/dist/providers/nvidia.js.map +1 -1
  100. package/dist/providers/openai-compat.js +2 -4
  101. package/dist/providers/openai-compat.js.map +1 -1
  102. package/dist/providers/openrouter.js +1 -1
  103. package/dist/providers/openrouter.js.map +1 -1
  104. package/dist/safety/audit-log.d.ts +0 -15
  105. package/dist/safety/audit-log.js +0 -21
  106. package/dist/safety/audit-log.js.map +1 -1
  107. package/dist/state/db.js +5 -60
  108. package/dist/state/db.js.map +1 -1
  109. package/dist/tools/browser.js +16 -24
  110. package/dist/tools/browser.js.map +1 -1
  111. package/dist/tools/checkpoint.d.ts +1 -6
  112. package/dist/tools/checkpoint.js +62 -79
  113. package/dist/tools/checkpoint.js.map +1 -1
  114. package/dist/tools/cron.js +3 -1
  115. package/dist/tools/cron.js.map +1 -1
  116. package/dist/tools/diff.js +21 -25
  117. package/dist/tools/diff.js.map +1 -1
  118. package/dist/tools/exec.d.ts +0 -2
  119. package/dist/tools/exec.js +0 -13
  120. package/dist/tools/exec.js.map +1 -1
  121. package/dist/tools/fs-edit.d.ts +5 -3
  122. package/dist/tools/fs-edit.js +23 -8
  123. package/dist/tools/fs-edit.js.map +1 -1
  124. package/dist/tools/fs-ls.js +8 -6
  125. package/dist/tools/fs-ls.js.map +1 -1
  126. package/dist/tools/fs-read.d.ts +1 -1
  127. package/dist/tools/fs-read.js +28 -37
  128. package/dist/tools/fs-read.js.map +1 -1
  129. package/dist/tools/fs-write.d.ts +1 -1
  130. package/dist/tools/fs-write.js +33 -33
  131. package/dist/tools/fs-write.js.map +1 -1
  132. package/dist/tools/git.js +6 -12
  133. package/dist/tools/git.js.map +1 -1
  134. package/dist/tools/index.d.ts +2 -5
  135. package/dist/tools/index.js +4 -7
  136. package/dist/tools/index.js.map +1 -1
  137. package/dist/tools/multimodal.js +12 -11
  138. package/dist/tools/multimodal.js.map +1 -1
  139. package/dist/tools/rtk.js +9 -22
  140. package/dist/tools/rtk.js.map +1 -1
  141. package/dist/tools/search-glob.d.ts +1 -1
  142. package/dist/tools/search-glob.js +24 -42
  143. package/dist/tools/search-glob.js.map +1 -1
  144. package/dist/tools/search-grep.d.ts +1 -1
  145. package/dist/tools/search-grep.js +32 -56
  146. package/dist/tools/search-grep.js.map +1 -1
  147. package/dist/tools/shell.d.ts +1 -7
  148. package/dist/tools/shell.js +61 -114
  149. package/dist/tools/shell.js.map +1 -1
  150. package/dist/tui/ink/App.d.ts +1 -2
  151. package/dist/tui/ink/App.js +82 -194
  152. package/dist/tui/ink/App.js.map +1 -1
  153. package/dist/tui/ink/components/DenseToolMessage.js +8 -23
  154. package/dist/tui/ink/components/DenseToolMessage.js.map +1 -1
  155. package/dist/tui/ink/components/InputBox.js +25 -16
  156. package/dist/tui/ink/components/InputBox.js.map +1 -1
  157. package/dist/tui/ink/components/KeySetOverlay.d.ts +1 -1
  158. package/dist/tui/ink/components/KeySetOverlay.js +16 -18
  159. package/dist/tui/ink/components/KeySetOverlay.js.map +1 -1
  160. package/dist/tui/ink/components/Logo.d.ts +0 -20
  161. package/dist/tui/ink/components/Logo.js +1 -67
  162. package/dist/tui/ink/components/Logo.js.map +1 -1
  163. package/dist/tui/ink/components/ModelPicker.d.ts +2 -2
  164. package/dist/tui/ink/components/ModelPicker.js +26 -34
  165. package/dist/tui/ink/components/ModelPicker.js.map +1 -1
  166. package/dist/tui/ink/components/PasteCollapse.d.ts +1 -3
  167. package/dist/tui/ink/components/PasteCollapse.js +9 -11
  168. package/dist/tui/ink/components/PasteCollapse.js.map +1 -1
  169. package/dist/tui/ink/components/SpinnerGlyph.d.ts +4 -4
  170. package/dist/tui/ink/components/SpinnerGlyph.js +14 -34
  171. package/dist/tui/ink/components/SpinnerGlyph.js.map +1 -1
  172. package/dist/tui/ink/components/StatusBar.d.ts +0 -7
  173. package/dist/tui/ink/components/StatusBar.js +5 -11
  174. package/dist/tui/ink/components/StatusBar.js.map +1 -1
  175. package/dist/tui/ink/components/ThinkingBlock.d.ts +4 -15
  176. package/dist/tui/ink/components/ThinkingBlock.js +17 -34
  177. package/dist/tui/ink/components/ThinkingBlock.js.map +1 -1
  178. package/dist/tui/ink/components/ToolBox.js +13 -23
  179. package/dist/tui/ink/components/ToolBox.js.map +1 -1
  180. package/dist/tui/ink/index.js +1 -17
  181. package/dist/tui/ink/index.js.map +1 -1
  182. package/dist/tui/ink/theme-context.js +3 -6
  183. package/dist/tui/ink/theme-context.js.map +1 -1
  184. package/dist/tui/ink/use-declined-versions.js +2 -6
  185. package/dist/tui/ink/use-declined-versions.js.map +1 -1
  186. package/dist/tui/ink/use-event-projection.d.ts +0 -2
  187. package/dist/tui/ink/use-event-projection.js +2 -21
  188. package/dist/tui/ink/use-event-projection.js.map +1 -1
  189. package/dist/tui/ink/use-overlays.js +17 -16
  190. package/dist/tui/ink/use-overlays.js.map +1 -1
  191. package/package.json +6 -5
  192. package/dist/state/db-telemetry.d.ts +0 -21
  193. package/dist/state/db-telemetry.js +0 -116
  194. package/dist/state/db-telemetry.js.map +0 -1
  195. package/dist/telemetry/gateway-push.d.ts +0 -17
  196. package/dist/telemetry/gateway-push.js +0 -48
  197. package/dist/telemetry/gateway-push.js.map +0 -1
  198. package/dist/telemetry/index.d.ts +0 -9
  199. package/dist/telemetry/index.js +0 -9
  200. package/dist/telemetry/index.js.map +0 -1
  201. package/dist/tools/github.d.ts +0 -13
  202. package/dist/tools/github.js +0 -257
  203. package/dist/tools/github.js.map +0 -1
  204. package/dist/tui/ink/components/VirtualTranscript.d.ts +0 -19
  205. package/dist/tui/ink/components/VirtualTranscript.js +0 -31
  206. package/dist/tui/ink/components/VirtualTranscript.js.map +0 -1
  207. package/dist/tui/ink/markdown/syntax-highlight.d.ts +0 -13
  208. package/dist/tui/ink/markdown/syntax-highlight.js +0 -91
  209. package/dist/tui/ink/markdown/syntax-highlight.js.map +0 -1
  210. package/dist/tui/ink/use-elapsed.d.ts +0 -14
  211. package/dist/tui/ink/use-elapsed.js +0 -61
  212. package/dist/tui/ink/use-elapsed.js.map +0 -1
  213. package/dist/tui/ink/use-flicker-detector.d.ts +0 -12
  214. package/dist/tui/ink/use-flicker-detector.js +0 -37
  215. package/dist/tui/ink/use-flicker-detector.js.map +0 -1
  216. package/dist/tui/ink/use-render-metrics.d.ts +0 -14
  217. package/dist/tui/ink/use-render-metrics.js +0 -106
  218. package/dist/tui/ink/use-render-metrics.js.map +0 -1
  219. package/dist/tui/ink/use-transcript-scroll.d.ts +0 -19
  220. package/dist/tui/ink/use-transcript-scroll.js +0 -83
  221. package/dist/tui/ink/use-transcript-scroll.js.map +0 -1
  222. package/dist/utils/env.d.ts +0 -1
  223. package/dist/utils/env.js +0 -60
  224. package/dist/utils/env.js.map +0 -1
  225. package/dist/utils/fs.d.ts +0 -10
  226. package/dist/utils/fs.js +0 -37
  227. package/dist/utils/fs.js.map +0 -1
@@ -3,7 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  * Ink root component for the dirgha TUI.
4
4
  *
5
5
  * Layout is a single vertical stack:
6
- * 1. Logo (emitted to stdout once before Ink mounts — see ./index.ts)
6
+ * 1. Logo (rendered once inside <Static>, never re-renders)
7
7
  * 2. Transcript (finalised user messages + completed turn blocks)
8
8
  * 3. LiveTurn (the currently streaming turn, if any)
9
9
  * 4. InputBox
@@ -15,9 +15,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
15
15
  * focused on layout and lifecycle.
16
16
  */
17
17
  import * as React from "react";
18
- import { Box, Text, useApp, useInput } from "ink";
18
+ import { Box, Static, Text, useApp, useInput } from "ink";
19
19
  import { randomUUID } from "node:crypto";
20
- import { VirtualTranscript } from "./components/VirtualTranscript.js";
21
20
  import { appendAudit } from "../../audit/writer.js";
22
21
  import { maybeCompact } from "../../context/compaction.js";
23
22
  import { contextWindowFor } from "../../intelligence/prices.js";
@@ -27,7 +26,6 @@ import { loadProjectPrimer, composeSystemPrompt, } from "../../context/primer.js
27
26
  import { queryKb } from "../../context/kb-query.js";
28
27
  import { probeGitState, renderGitState } from "../../context/git-state.js";
29
28
  import { loadSoul } from "../../context/soul.js";
30
- import { routeModel } from "../../providers/dispatch.js";
31
29
  import { isAutoApprove, modePreamble } from "../../context/mode.js";
32
30
  import { runAgentLoop } from "../../kernel/agent-loop.js";
33
31
  import { createErrorClassifier } from "../../intelligence/error-classifier.js";
@@ -35,9 +33,10 @@ import { createToolExecutor } from "../../tools/exec.js";
35
33
  import { createInkApprovalBus, } from "./ink-approval-bus.js";
36
34
  import { ApprovalPrompt, } from "./components/ApprovalPrompt.js";
37
35
  import { PRICES } from "../../intelligence/prices.js";
36
+ import { Logo } from "./components/Logo.js";
38
37
  import { StatusBar } from "./components/StatusBar.js";
39
38
  import { StreamingText } from "./components/StreamingText.js";
40
- import { ThinkingBlock, ThinkingBlockGroup, } from "./components/ThinkingBlock.js";
39
+ import { ThinkingBlock } from "./components/ThinkingBlock.js";
41
40
  import { ToolBox } from "./components/ToolBox.js";
42
41
  import { ToolGroup } from "./components/ToolGroup.js";
43
42
  import { InputBox } from "./components/InputBox.js";
@@ -53,25 +52,21 @@ import { getUpdateBannerVersion } from "../../cli/update-check.js";
53
52
  import { AtFileComplete } from "./components/AtFileComplete.js";
54
53
  import { SlashComplete } from "./components/SlashComplete.js";
55
54
  import { ThemePicker } from "./components/ThemePicker.js";
56
- import { ThemeProvider, useTheme } from "./theme-context.js";
55
+ import { ThemeProvider } from "./theme-context.js";
57
56
  import { SpinnerContext } from "./spinner-context.js";
58
- import { SpinnerGlyph } from "./components/SpinnerGlyph.js";
59
57
  import { writeFile, mkdir, readFile } from "node:fs/promises";
60
- import { readFileSync, existsSync } from "node:fs";
61
58
  import { homedir } from "node:os";
62
59
  import { join as pathJoin } from "node:path";
63
60
  import { useEventProjection, } from "./use-event-projection.js";
64
61
  import { useOverlays } from "./use-overlays.js";
65
62
  import { useDeclinedVersions } from "./use-declined-versions.js";
66
63
  import { useStartupHealth } from "./use-startup-health.js";
67
- import { useFlickerDetector } from "./use-flicker-detector.js";
68
- import { useRenderMetrics, } from "./use-render-metrics.js";
69
64
  import { getRemoteConfig, isVersionBelowMin, } from "../../intelligence/remote-config.js";
70
65
  import { createRequire } from "node:module";
71
66
  // Pulled from the installed package.json so the TUI title matches the
72
67
  // shipped binary version. Falls back to '0.0.0-dev' if the file isn't
73
68
  // reachable (e.g. an unusual deploy layout).
74
- export const VERSION = (() => {
69
+ const VERSION = (() => {
75
70
  try {
76
71
  const req = createRequire(import.meta.url);
77
72
  const pkg = req("../../../package.json");
@@ -81,19 +76,11 @@ export const VERSION = (() => {
81
76
  return "0.0.0-dev";
82
77
  }
83
78
  })();
84
- // Cache for initialHistory — avoids sync fs I/O in the render phase
85
- // on re-calls (e.g. /clear). The underlying files rarely change within
86
- // a session so a single snapshot is sufficient.
87
- let _cachedInitialMessages = null;
88
79
  export function App(props) {
89
80
  const { exit } = useApp();
90
81
  const sessionIdRef = React.useRef(randomUUID());
91
82
  const historyRef = React.useRef(initialHistory(props));
92
83
  const abortRef = React.useRef(null);
93
- // Stores the user-facing cancellation message so the finally block can
94
- // inject it via appendLiveSync (avoids the React state-updater race
95
- // where appendLive doesn't update liveItemsRef before commitLive reads it).
96
- const interruptMsgRef = React.useRef(null);
97
84
  const pendingModelRef = React.useRef(null);
98
85
  const sessionRef = React.useRef(null);
99
86
  React.useEffect(() => {
@@ -119,7 +106,6 @@ export function App(props) {
119
106
  const [transcript, setTranscript] = React.useState([]);
120
107
  const [input, setInput] = React.useState("");
121
108
  const [busy, setBusy] = React.useState(false);
122
- const [thinkingStreaming, setThinkingStreaming] = React.useState(false);
123
109
  // Prompt queue: while a turn is streaming the user can still type and
124
110
  // press Enter. Submissions land here instead of being dropped, then
125
111
  // drain FIFO when the turn finishes (see useEffect below).
@@ -156,7 +142,7 @@ export function App(props) {
156
142
  // turns. Replaces the legacy `createTuiApprovalBus` that wrote prompts
157
143
  // direct to stdout (overdrawn by Ink) and read stdin raw (hung on
158
144
  // Windows). See `ink-approval-bus.ts` for the full rationale.
159
- const approvalBusRef = React.useRef(null);
145
+ const approvalBusRef = React.useRef();
160
146
  if (!approvalBusRef.current) {
161
147
  approvalBusRef.current = createInkApprovalBus(new Set(props.config.autoApproveTools));
162
148
  }
@@ -200,18 +186,6 @@ export function App(props) {
200
186
  }, [declined]);
201
187
  // Startup health check — non-blocking, cached for 24h.
202
188
  const healthResult = useStartupHealth();
203
- // Flicker detector — compares estimated tree height to terminal rows.
204
- const estimatedLineCount = (transcript.length + projection.liveItems.length) * 2 + 15;
205
- const flicker = useFlickerDetector(estimatedLineCount);
206
- // Render performance metrics — track frame timing, expose for StatusBar.
207
- const renderMetrics = useRenderMetrics();
208
- const [showRenderMetrics, setShowRenderMetrics] = React.useState(false);
209
- // Alt+M toggles the render-metrics display in the StatusBar.
210
- useInput((ch, key) => {
211
- if (key.meta && ch === "m") {
212
- setShowRenderMetrics((v) => !v);
213
- }
214
- });
215
189
  // Remote config: fetch once on mount, set model default, show MOTD.
216
190
  const [remoteConfig, setRemoteConfig] = React.useState(null);
217
191
  const [motdShown, setMotdShown] = React.useState(false);
@@ -303,18 +277,8 @@ export function App(props) {
303
277
  liveOutputTokensAccRef.current = 0;
304
278
  setLiveOutputTokens(0);
305
279
  setLiveDurationMs(0);
306
- setThinkingStreaming(false);
307
- }
308
- else if (ev.type === "thinking_start") {
309
- setThinkingStreaming(true);
310
- }
311
- else if (ev.type === "thinking_end") {
312
- setThinkingStreaming(false);
313
280
  }
314
281
  else if (ev.type === "text_delta" || ev.type === "thinking_delta") {
315
- // Approximate tokens as chars ÷ 4 — a common heuristic for English
316
- // text where avg token length is ~4 characters. Not exact but keeps
317
- // the tok/s rate plausible without an expensive tokenizer.
318
282
  liveOutputTokensAccRef.current += (ev.delta?.length ?? 0) / 4;
319
283
  }
320
284
  else if (ev.type === "usage") {
@@ -417,7 +381,7 @@ export function App(props) {
417
381
  });
418
382
  // A new submission supersedes any pending failover prompt.
419
383
  setPendingFailover(null);
420
- if (value === "/exit" || value === "/quit" || value === "/stop") {
384
+ if (value === "/exit" || value === "/quit") {
421
385
  exit();
422
386
  return;
423
387
  }
@@ -435,36 +399,23 @@ export function App(props) {
435
399
  if (value.startsWith("/model ")) {
436
400
  const id = value.slice("/model ".length).trim();
437
401
  if (id !== "") {
438
- // Exact match first, then suffix fallback — mirrors slash.ts /model handler.
439
- const exactMatch = PRICES.find((p) => p.model === id);
440
- if (exactMatch) {
441
- setCurrentModel(exactMatch.model);
402
+ const valid = PRICES.some((p) => p.model === id);
403
+ if (!valid) {
442
404
  const note = {
443
405
  kind: "notice",
444
406
  id: randomUUID(),
445
- text: `Model set to ${exactMatch.model}`,
407
+ text: `Invalid model: ${id}. Use /models to see the catalogue.`,
446
408
  };
447
409
  setTranscript((prev) => [...prev, note]);
448
410
  }
449
411
  else {
450
- const suffixMatch = PRICES.find((p) => p.model.endsWith("/" + id));
451
- if (suffixMatch) {
452
- setCurrentModel(suffixMatch.model);
453
- const note = {
454
- kind: "notice",
455
- id: randomUUID(),
456
- text: `Model set to ${suffixMatch.model}`,
457
- };
458
- setTranscript((prev) => [...prev, note]);
459
- }
460
- else {
461
- const note = {
462
- kind: "notice",
463
- id: randomUUID(),
464
- text: `Invalid model: ${id}. Use /models to see the catalogue.`,
465
- };
466
- setTranscript((prev) => [...prev, note]);
467
- }
412
+ setCurrentModel(id);
413
+ const note = {
414
+ kind: "notice",
415
+ id: randomUUID(),
416
+ text: `Model set to ${id}`,
417
+ };
418
+ setTranscript((prev) => [...prev, note]);
468
419
  }
469
420
  }
470
421
  return;
@@ -554,11 +505,7 @@ export function App(props) {
554
505
  exit();
555
506
  process.exit(code);
556
507
  },
557
- getToken: () => {
558
- // Token loads asynchronously after mount; return null
559
- // gracefully so slash commands don't crash on first call.
560
- return tokenRef.current;
561
- },
508
+ getToken: () => tokenRef.current,
562
509
  setToken: (newToken) => {
563
510
  tokenRef.current = newToken;
564
511
  },
@@ -747,10 +694,7 @@ export function App(props) {
747
694
  }
748
695
  catch (err) {
749
696
  const msg = err instanceof Error ? err.message : String(err);
750
- // Only match provider-key errors, not errors from deep inside the agent
751
- // loop that happen to contain a similar pattern. The message must start
752
- // with the key name and end with "is required" to qualify.
753
- const keyMatch = /^([A-Z][A-Z0-9_]+_API_KEY) is required$/.exec(msg);
697
+ const keyMatch = /^([A-Z][A-Z0-9_]+_API_KEY) is required/.exec(msg);
754
698
  if (keyMatch?.[1]) {
755
699
  setPendingKey({
756
700
  keyName: keyMatch[1],
@@ -766,19 +710,6 @@ export function App(props) {
766
710
  }
767
711
  }
768
712
  finally {
769
- // If the turn was cancelled via ESC / Ctrl-C, inject the notice
770
- // synchronously into liveItemsRef before commitLive reads it — this
771
- // avoids the React-state race where appendLive's functional updater
772
- // hasn't flushed to the ref yet when commitLive runs.
773
- const interruptMsg = interruptMsgRef.current;
774
- interruptMsgRef.current = null;
775
- if (abort.signal.aborted && interruptMsg !== null) {
776
- projection.appendLiveSync({
777
- kind: "notice",
778
- id: randomUUID(),
779
- text: interruptMsg,
780
- });
781
- }
782
713
  const committed = projection.commitLive();
783
714
  if (committed.length > 0)
784
715
  setTranscript((prev) => [...prev, ...committed]);
@@ -786,12 +717,7 @@ export function App(props) {
786
717
  abortRef.current = null;
787
718
  }
788
719
  };
789
- // Keep runTurnRef pointed at the latest runTurn closure so
790
- // handleSubmit always calls the current version without adding
791
- // runTurn's deps to handleSubmit's dependency array.
792
- React.useEffect(() => {
793
- runTurnRef.current = runTurn;
794
- });
720
+ runTurnRef.current = runTurn;
795
721
  // Drain the prompt queue when a turn finishes. Pops the oldest queued
796
722
  // prompt and re-submits it through handleSubmit (which transitions
797
723
  // back into busy=true via runTurn). Guarded on `!busy` so we never
@@ -811,8 +737,6 @@ export function App(props) {
811
737
  // 2. If a turn is streaming → abort it (cancels the in-flight LLM
812
738
  // request via the AbortController plumbed through runAgentLoop).
813
739
  // 3. If the input box has draft text → clear it.
814
- // (step 3 is skipped when vimMode is on — InputBox's own handler
815
- // enters NORMAL mode; clearing here would destroy the text.)
816
740
  // Always active so Esc behaves like the user expects regardless of
817
741
  // which surface they're looking at. The atfile overlay handles its
818
742
  // own Esc (cancel completion) so we skip step 1 there.
@@ -824,23 +748,33 @@ export function App(props) {
824
748
  return;
825
749
  }
826
750
  if (busy && abortRef.current !== null) {
827
- interruptMsgRef.current = "Cancelled.";
828
751
  abortRef.current.abort();
752
+ projection.appendLive({
753
+ kind: "notice",
754
+ id: randomUUID(),
755
+ text: "Cancelled.",
756
+ });
829
757
  return;
830
758
  }
831
- if (input.length > 0 && props.config.vimMode !== true)
759
+ if (input.length > 0)
832
760
  setInput("");
833
761
  });
834
762
  // Ctrl-C handler: if a turn is running, abort it and show "[Interrupted]"
835
763
  // in the transcript (matching the readline path in src/cli/interactive.ts).
836
- // Idle exit is handled by InputBox's own Ctrl-C handler (2-press safety
837
- // within 1.5s) — we don't override that here.
764
+ // If idle, let the process exit normally via app.exit().
838
765
  useInput((ch, key) => {
839
766
  if (!(key.ctrl && ch === "c"))
840
767
  return;
841
768
  if (busy && abortRef.current !== null) {
842
- interruptMsgRef.current = "[Interrupted]";
843
769
  abortRef.current.abort();
770
+ projection.appendLive({
771
+ kind: "notice",
772
+ id: randomUUID(),
773
+ text: "[Interrupted]",
774
+ });
775
+ }
776
+ else {
777
+ exit();
844
778
  }
845
779
  });
846
780
  const handleModelPick = React.useCallback((id) => {
@@ -866,7 +800,7 @@ export function App(props) {
866
800
  }
867
801
  catch (err) {
868
802
  const msg = err instanceof Error ? err.message : String(err);
869
- const m = /^([A-Z][A-Z0-9_]+_API_KEY) is required$/.exec(msg);
803
+ const m = /([A-Z][A-Z0-9_]+_API_KEY) is required/.exec(msg);
870
804
  if (m?.[1]) {
871
805
  // Open inline key entry instead of a static hint — the user can
872
806
  // paste their key right here without leaving the REPL.
@@ -1006,18 +940,19 @@ export function App(props) {
1006
940
  }
1007
941
  })();
1008
942
  }, [overlays]);
1009
- const liveJsx = React.useMemo(() => renderTranscript(projection.liveItems, thinkingStreaming), [projection.liveItems, thinkingStreaming]);
943
+ const committedJsx = React.useMemo(() => renderTranscript(transcript), [transcript]);
944
+ // Gemini CLI approach: freeze committed history inside <Static>
945
+ // so Ink caches the output and never re-renders it. Without this,
946
+ // every streaming flush tick re-conciles the entire transcript
947
+ // against the terminal — causing visible flicker/jitter.
948
+ const committedStaticItems = React.useMemo(() => committedJsx.map((el, i) => ({
949
+ key: el?.key ?? `c-${i}`,
950
+ el,
951
+ })), [committedJsx]);
952
+ const liveJsx = React.useMemo(() => renderTranscript(projection.liveItems), [projection.liveItems]);
1010
953
  const providerEntries = React.useMemo(() => buildProviderEntries(models, currentModel), [models, currentModel]);
1011
- const spinnerCtx = React.useMemo(() => ({ busy, frame: 0 }), [busy]);
1012
- const renderTranscriptItem = React.useCallback((item) => _jsx(TranscriptRow, { item: item }, item.id), []);
1013
- // Logo is emitted via process.stdout.write() before Ink mounts (see
1014
- // tui/ink/index.ts). Keeping it out of Ink's render tree avoids the
1015
- // re-emission flicker users hit when transcripts overflow the
1016
- // viewport: Ink's onRender prepends `fullStaticOutput` (which includes
1017
- // the logo) on every overflow redraw, repainting it on every chat
1018
- // turn that fills the screen. `use-flicker-detector` already warns
1019
- // when this is about to happen.
1020
- return (_jsx(ThemeProvider, { activeTheme: themeName, children: _jsx(SpinnerContext.Provider, { value: spinnerCtx, children: _jsxs(Box, { flexDirection: "column", children: [_jsx(VirtualTranscript, { items: transcript, renderItem: renderTranscriptItem, autoScroll: true, inputFocus: inputFocus }), _jsx(Box, { flexDirection: "column", children: liveJsx }), busy && projection.liveItems.length === 0 && _jsx(GeneratingIndicator, { startedAtMs: turnStartRef.current, liveOutputTokens: liveOutputTokens }), pendingApproval !== null && approvalBusRef.current && (_jsx(ApprovalPrompt, { request: pendingApproval, onResolve: (decision) => {
954
+ const LOGO_ITEMS = React.useMemo(() => [{ key: "logo" }], []);
955
+ 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) => {
1021
956
  approvalBusRef.current?.resolve(pendingApproval.id, decision);
1022
957
  } })), pendingFailover !== null && (_jsx(ModelSwitchPrompt, { failedModel: pendingFailover.failedModel, failoverModel: pendingFailover.failoverModel, onAccept: (failover) => {
1023
958
  const lastPrompt = pendingFailover.lastPrompt;
@@ -1072,40 +1007,28 @@ export function App(props) {
1072
1007
  // Esc inside ModelPicker → back to ProviderPicker (NOT close).
1073
1008
  setPickerStage("provider");
1074
1009
  setPickerProvider(null);
1075
- } })), 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 })] }) }) }));
1010
+ } })), 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 })] }) }) }));
1076
1011
  }
1077
1012
  /**
1078
1013
  * Walk the transcript and fold consecutive `tool` items into a single
1079
- * <ToolGroup>. Fold 3+ consecutive `thinking` items into a single
1080
- * <ThinkingBlockGroup>. Non-tool / non-thinking items render via
1081
- * <TranscriptRow>.
1014
+ * <ToolGroup>. Non-tool items render via <TranscriptRow>. The grouping
1015
+ * is intentionally simple — we look at adjacency, not assistant-turn
1016
+ * boundaries, because the projection emits tools contiguously between
1017
+ * `text` spans of the same turn.
1082
1018
  */
1083
- function renderTranscript(items, thinkingStreaming) {
1019
+ function renderTranscript(items) {
1084
1020
  const out = [];
1085
1021
  let toolBuf = [];
1086
- let thinkBuf = [];
1087
1022
  const flushTools = () => {
1088
1023
  if (toolBuf.length === 0)
1089
1024
  return;
1025
+ // Key on the stable ID of the first tool so React never unmounts/remounts
1026
+ // the ToolGroup subtree when the counter resets (which caused flicker).
1090
1027
  out.push(_jsx(ToolGroup, { tools: toolBuf }, toolBuf[0].id));
1091
1028
  toolBuf = [];
1092
1029
  };
1093
- const flushThinking = () => {
1094
- if (thinkBuf.length === 0)
1095
- return;
1096
- if (thinkBuf.length >= 3) {
1097
- out.push(_jsx(ThinkingBlockGroup, { blocks: thinkBuf }, thinkBuf[0].id));
1098
- }
1099
- else {
1100
- for (const tb of thinkBuf) {
1101
- out.push(_jsx(TranscriptRow, { item: { kind: "thinking", id: tb.id, content: tb.content }, isStreaming: thinkingStreaming }, tb.id));
1102
- }
1103
- }
1104
- thinkBuf = [];
1105
- };
1106
1030
  for (const item of items) {
1107
1031
  if (item.kind === "tool") {
1108
- flushThinking();
1109
1032
  toolBuf.push({
1110
1033
  id: item.id,
1111
1034
  name: item.name,
@@ -1118,27 +1041,20 @@ function renderTranscript(items, thinkingStreaming) {
1118
1041
  });
1119
1042
  continue;
1120
1043
  }
1121
- if (item.kind === "thinking") {
1122
- flushTools();
1123
- thinkBuf.push({ id: item.id, content: item.content });
1124
- continue;
1125
- }
1126
1044
  flushTools();
1127
- flushThinking();
1128
- out.push(_jsx(TranscriptRow, { item: item, isStreaming: thinkingStreaming }, item.id));
1045
+ out.push(_jsx(TranscriptRow, { item: item }, item.id));
1129
1046
  }
1130
1047
  flushTools();
1131
- flushThinking();
1132
1048
  return out;
1133
1049
  }
1134
- function TranscriptRow({ item, isStreaming = false, }) {
1050
+ function TranscriptRow({ item, }) {
1135
1051
  switch (item.kind) {
1136
1052
  case "user":
1137
1053
  return (_jsxs(Box, { gap: 2, marginBottom: 1, children: [_jsx(Text, { color: "magenta", children: "\u276F" }), _jsx(Text, { color: "white", children: item.text })] }));
1138
1054
  case "text":
1139
1055
  return _jsx(StreamingText, { content: item.content });
1140
1056
  case "thinking":
1141
- return _jsx(ThinkingBlock, { content: item.content, isStreaming: isStreaming });
1057
+ return _jsx(ThinkingBlock, { content: item.content });
1142
1058
  case "tool":
1143
1059
  // Should not be reached — tools are folded by renderTranscript() into
1144
1060
  // <ToolGroup>. Kept as a safety net so an unexpected tool item still
@@ -1150,23 +1066,7 @@ function TranscriptRow({ item, isStreaming = false, }) {
1150
1066
  return (_jsx(Box, { marginBottom: 1, children: _jsx(Text, { color: "yellow", children: item.text }) }));
1151
1067
  }
1152
1068
  }
1153
- function GeneratingIndicator(props) {
1154
- const palette = useTheme();
1155
- const [now, setNow] = React.useState(Date.now());
1156
- React.useEffect(() => {
1157
- const t = setInterval(() => setNow(Date.now()), 1000);
1158
- return () => clearInterval(t);
1159
- }, []);
1160
- const elapsedSec = props.startedAtMs > 0 ? Math.round((now - props.startedAtMs) / 1000) : 0;
1161
- const slow = elapsedSec >= 5 && props.liveOutputTokens === 0;
1162
- const label = slow
1163
- ? `warming up · ${elapsedSec}s · first token can take 10–30s on free models`
1164
- : `generating · ${elapsedSec}s`;
1165
- 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: label })] }));
1166
- }
1167
1069
  function initialHistory(props) {
1168
- if (_cachedInitialMessages !== null)
1169
- return _cachedInitialMessages;
1170
1070
  const base = props.initialMessages ? [...props.initialMessages] : [];
1171
1071
  // Boot context: mode preamble + project primer (DIRGHA.md) +
1172
1072
  // caller's --system. Without this, the Ink TUI starts with zero
@@ -1183,18 +1083,30 @@ function initialHistory(props) {
1183
1083
  userSystem: props.systemPrompt,
1184
1084
  });
1185
1085
  base.unshift({ role: "system", content: composedSystem });
1186
- _cachedInitialMessages = base;
1187
1086
  return base;
1188
1087
  }
1189
1088
  function providerIdForModel(model) {
1190
- // Delegate to providers/dispatch.ts so the StatusBar readout
1191
- // matches the actual runtime routing at all times.
1192
- try {
1193
- return routeModel(model);
1194
- }
1195
- catch {
1196
- return "local";
1197
- }
1089
+ // Light heuristic so StatusBar has a hint without importing dispatch.
1090
+ // Real routing still lives in providers/dispatch.ts at run time.
1091
+ if (model.includes("claude"))
1092
+ return "anthropic";
1093
+ if (model.includes("gpt") || model.startsWith("o1") || model.startsWith("o3"))
1094
+ return "openai";
1095
+ if (model.includes("gemini"))
1096
+ return "gemini";
1097
+ if (model.includes("deepseek"))
1098
+ return "deepseek";
1099
+ if (model.includes("kimi") || model.includes("moonshot"))
1100
+ return "nvidia";
1101
+ if (model.includes("llama") ||
1102
+ model.includes("nvidia") ||
1103
+ model.includes("minimax"))
1104
+ return "nvidia";
1105
+ if (model.includes("fireworks"))
1106
+ return "fireworks";
1107
+ if (model.includes("/"))
1108
+ return "openrouter";
1109
+ return "local";
1198
1110
  }
1199
1111
  const PROVIDER_BLURB = {
1200
1112
  anthropic: "Claude — Opus, Sonnet, Haiku",
@@ -1253,24 +1165,6 @@ const PROVIDER_LABEL = {
1253
1165
  zai: "Z.AI / GLM",
1254
1166
  local: "Local",
1255
1167
  };
1256
- /**
1257
- * Synchronously check whether an env var exists in ~/.dirgha/keys.json.
1258
- * Used by buildProviderEntries as a fallback when process.env doesn't
1259
- * contain the key yet (race with startup hydration).
1260
- */
1261
- function tryReadKeyFromStore(envVar) {
1262
- try {
1263
- const path = pathJoin(homedir(), ".dirgha", "keys.json");
1264
- if (!existsSync(path))
1265
- return false;
1266
- const raw = readFileSync(path, "utf8");
1267
- const store = JSON.parse(raw);
1268
- return typeof store[envVar] === "string" && store[envVar].length > 0;
1269
- }
1270
- catch {
1271
- return false;
1272
- }
1273
- }
1274
1168
  /**
1275
1169
  * Group the flat model catalogue into per-provider entries for stage 1
1276
1170
  * of the picker. Skips providers with zero models in the catalogue.
@@ -1286,13 +1180,7 @@ function buildProviderEntries(models, currentModel) {
1286
1180
  const out = [];
1287
1181
  for (const [id, items] of buckets) {
1288
1182
  const env = PROVIDER_ENV[id];
1289
- // Check env vars AND keys.json (env vars win). keys.json is hydrated
1290
- // into process.env by hydrateEnvFromKeyStore at startup, but this
1291
- // synchronous fallback handles the edge case where hydration hasn't
1292
- // run yet (e.g. TUI mounts before startup hydration completes).
1293
- const hasKey = env
1294
- ? !!process.env[env] || !!tryReadKeyFromStore(env)
1295
- : true; // local providers don't need keys
1183
+ const hasKey = env ? !!process.env[env] : true; // local providers don't need keys
1296
1184
  out.push({
1297
1185
  id,
1298
1186
  label: PROVIDER_LABEL[id] ?? id,