@dirgha/code 1.20.39 → 1.22.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 (217) 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 -51
  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 +21 -44
  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/prices.d.ts +4 -6
  75. package/dist/intelligence/prices.js +10 -36
  76. package/dist/intelligence/prices.js.map +1 -1
  77. package/dist/kernel/agent-loop.js +17 -60
  78. package/dist/kernel/agent-loop.js.map +1 -1
  79. package/dist/lsp/client.js +16 -29
  80. package/dist/lsp/client.js.map +1 -1
  81. package/dist/lsp/detector.js +6 -7
  82. package/dist/lsp/detector.js.map +1 -1
  83. package/dist/mcp/client.d.ts +1 -1
  84. package/dist/mcp/client.js +16 -19
  85. package/dist/mcp/client.js.map +1 -1
  86. package/dist/mcp/transport.js +38 -46
  87. package/dist/mcp/transport.js.map +1 -1
  88. package/dist/providers/deepseek.js +1 -1
  89. package/dist/providers/deepseek.js.map +1 -1
  90. package/dist/providers/dispatch.js +1 -15
  91. package/dist/providers/dispatch.js.map +1 -1
  92. package/dist/providers/index.d.ts +0 -11
  93. package/dist/providers/index.js +2 -29
  94. package/dist/providers/index.js.map +1 -1
  95. package/dist/providers/nvidia.js +1 -1
  96. package/dist/providers/nvidia.js.map +1 -1
  97. package/dist/providers/openai-compat.js +2 -4
  98. package/dist/providers/openai-compat.js.map +1 -1
  99. package/dist/providers/openrouter.js +1 -1
  100. package/dist/providers/openrouter.js.map +1 -1
  101. package/dist/safety/audit-log.d.ts +0 -15
  102. package/dist/safety/audit-log.js +0 -21
  103. package/dist/safety/audit-log.js.map +1 -1
  104. package/dist/state/db-telemetry.js +1 -11
  105. package/dist/state/db-telemetry.js.map +1 -1
  106. package/dist/state/db.js +1 -53
  107. package/dist/state/db.js.map +1 -1
  108. package/dist/tools/browser.js +16 -24
  109. package/dist/tools/browser.js.map +1 -1
  110. package/dist/tools/checkpoint.d.ts +1 -6
  111. package/dist/tools/checkpoint.js +62 -79
  112. package/dist/tools/checkpoint.js.map +1 -1
  113. package/dist/tools/cron.js +3 -1
  114. package/dist/tools/cron.js.map +1 -1
  115. package/dist/tools/diff.js +21 -25
  116. package/dist/tools/diff.js.map +1 -1
  117. package/dist/tools/exec.d.ts +0 -2
  118. package/dist/tools/exec.js +0 -13
  119. package/dist/tools/exec.js.map +1 -1
  120. package/dist/tools/fs-edit.d.ts +5 -3
  121. package/dist/tools/fs-edit.js +23 -8
  122. package/dist/tools/fs-edit.js.map +1 -1
  123. package/dist/tools/fs-ls.js +8 -6
  124. package/dist/tools/fs-ls.js.map +1 -1
  125. package/dist/tools/fs-read.d.ts +1 -1
  126. package/dist/tools/fs-read.js +28 -37
  127. package/dist/tools/fs-read.js.map +1 -1
  128. package/dist/tools/fs-write.d.ts +1 -1
  129. package/dist/tools/fs-write.js +33 -33
  130. package/dist/tools/fs-write.js.map +1 -1
  131. package/dist/tools/git.js +6 -12
  132. package/dist/tools/git.js.map +1 -1
  133. package/dist/tools/index.d.ts +2 -5
  134. package/dist/tools/index.js +4 -7
  135. package/dist/tools/index.js.map +1 -1
  136. package/dist/tools/multimodal.js +12 -11
  137. package/dist/tools/multimodal.js.map +1 -1
  138. package/dist/tools/rtk.js +9 -22
  139. package/dist/tools/rtk.js.map +1 -1
  140. package/dist/tools/search-glob.d.ts +1 -1
  141. package/dist/tools/search-glob.js +24 -42
  142. package/dist/tools/search-glob.js.map +1 -1
  143. package/dist/tools/search-grep.d.ts +1 -1
  144. package/dist/tools/search-grep.js +32 -56
  145. package/dist/tools/search-grep.js.map +1 -1
  146. package/dist/tools/shell.d.ts +1 -7
  147. package/dist/tools/shell.js +61 -114
  148. package/dist/tools/shell.js.map +1 -1
  149. package/dist/tui/ink/App.d.ts +1 -2
  150. package/dist/tui/ink/App.js +72 -178
  151. package/dist/tui/ink/App.js.map +1 -1
  152. package/dist/tui/ink/components/DenseToolMessage.js +3 -20
  153. package/dist/tui/ink/components/DenseToolMessage.js.map +1 -1
  154. package/dist/tui/ink/components/InputBox.js +15 -16
  155. package/dist/tui/ink/components/InputBox.js.map +1 -1
  156. package/dist/tui/ink/components/KeySetOverlay.d.ts +1 -1
  157. package/dist/tui/ink/components/KeySetOverlay.js +16 -18
  158. package/dist/tui/ink/components/KeySetOverlay.js.map +1 -1
  159. package/dist/tui/ink/components/Logo.d.ts +0 -20
  160. package/dist/tui/ink/components/Logo.js +1 -67
  161. package/dist/tui/ink/components/Logo.js.map +1 -1
  162. package/dist/tui/ink/components/ModelPicker.d.ts +2 -2
  163. package/dist/tui/ink/components/ModelPicker.js +26 -34
  164. package/dist/tui/ink/components/ModelPicker.js.map +1 -1
  165. package/dist/tui/ink/components/PasteCollapse.d.ts +1 -3
  166. package/dist/tui/ink/components/PasteCollapse.js +9 -11
  167. package/dist/tui/ink/components/PasteCollapse.js.map +1 -1
  168. package/dist/tui/ink/components/SpinnerGlyph.d.ts +4 -4
  169. package/dist/tui/ink/components/SpinnerGlyph.js +14 -34
  170. package/dist/tui/ink/components/SpinnerGlyph.js.map +1 -1
  171. package/dist/tui/ink/components/StatusBar.js +2 -0
  172. package/dist/tui/ink/components/StatusBar.js.map +1 -1
  173. package/dist/tui/ink/components/ThinkingBlock.d.ts +4 -15
  174. package/dist/tui/ink/components/ThinkingBlock.js +17 -34
  175. package/dist/tui/ink/components/ThinkingBlock.js.map +1 -1
  176. package/dist/tui/ink/components/ToolBox.js +13 -21
  177. package/dist/tui/ink/components/ToolBox.js.map +1 -1
  178. package/dist/tui/ink/components/VirtualTranscript.d.ts +1 -1
  179. package/dist/tui/ink/components/VirtualTranscript.js +3 -5
  180. package/dist/tui/ink/components/VirtualTranscript.js.map +1 -1
  181. package/dist/tui/ink/index.js +1 -17
  182. package/dist/tui/ink/index.js.map +1 -1
  183. package/dist/tui/ink/theme-context.js +3 -6
  184. package/dist/tui/ink/theme-context.js.map +1 -1
  185. package/dist/tui/ink/use-declined-versions.js +2 -6
  186. package/dist/tui/ink/use-declined-versions.js.map +1 -1
  187. package/dist/tui/ink/use-elapsed.d.ts +1 -9
  188. package/dist/tui/ink/use-elapsed.js +2 -17
  189. package/dist/tui/ink/use-elapsed.js.map +1 -1
  190. package/dist/tui/ink/use-event-projection.d.ts +0 -2
  191. package/dist/tui/ink/use-event-projection.js +2 -21
  192. package/dist/tui/ink/use-event-projection.js.map +1 -1
  193. package/dist/tui/ink/use-flicker-detector.js +0 -9
  194. package/dist/tui/ink/use-flicker-detector.js.map +1 -1
  195. package/dist/tui/ink/use-overlays.js +17 -16
  196. package/dist/tui/ink/use-overlays.js.map +1 -1
  197. package/dist/tui/ink/use-render-metrics.js +5 -18
  198. package/dist/tui/ink/use-render-metrics.js.map +1 -1
  199. package/package.json +6 -5
  200. package/dist/telemetry/gateway-push.d.ts +0 -17
  201. package/dist/telemetry/gateway-push.js +0 -48
  202. package/dist/telemetry/gateway-push.js.map +0 -1
  203. package/dist/telemetry/index.d.ts +0 -9
  204. package/dist/telemetry/index.js +0 -9
  205. package/dist/telemetry/index.js.map +0 -1
  206. package/dist/tools/github.d.ts +0 -13
  207. package/dist/tools/github.js +0 -257
  208. package/dist/tools/github.js.map +0 -1
  209. package/dist/tui/ink/markdown/syntax-highlight.d.ts +0 -13
  210. package/dist/tui/ink/markdown/syntax-highlight.js +0 -91
  211. package/dist/tui/ink/markdown/syntax-highlight.js.map +0 -1
  212. package/dist/utils/env.d.ts +0 -1
  213. package/dist/utils/env.js +0 -60
  214. package/dist/utils/env.js.map +0 -1
  215. package/dist/utils/fs.d.ts +0 -10
  216. package/dist/utils/fs.js +0 -37
  217. package/dist/utils/fs.js.map +0 -1
@@ -2,7 +2,7 @@
2
2
  * Ink root component for the dirgha TUI.
3
3
  *
4
4
  * Layout is a single vertical stack:
5
- * 1. Logo (emitted to stdout once before Ink mounts — see ./index.ts)
5
+ * 1. Logo (rendered once inside <Static>, never re-renders)
6
6
  * 2. Transcript (finalised user messages + completed turn blocks)
7
7
  * 3. LiveTurn (the currently streaming turn, if any)
8
8
  * 4. InputBox
@@ -23,7 +23,6 @@ import type { DirghaConfig } from "../../cli/config.js";
23
23
  import type { SlashRegistry } from "../../cli/slash.js";
24
24
  import { type ModelEntry } from "./components/ModelPicker.js";
25
25
  import { type HelpSlashCommand } from "./components/HelpOverlay.js";
26
- export declare const VERSION: string;
27
26
  export interface AppProps {
28
27
  events: EventStream;
29
28
  registry: ToolRegistry;
@@ -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,7 +15,7 @@ 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
20
  import { VirtualTranscript } from "./components/VirtualTranscript.js";
21
21
  import { appendAudit } from "../../audit/writer.js";
@@ -27,7 +27,6 @@ import { loadProjectPrimer, composeSystemPrompt, } from "../../context/primer.js
27
27
  import { queryKb } from "../../context/kb-query.js";
28
28
  import { probeGitState, renderGitState } from "../../context/git-state.js";
29
29
  import { loadSoul } from "../../context/soul.js";
30
- import { routeModel } from "../../providers/dispatch.js";
31
30
  import { isAutoApprove, modePreamble } from "../../context/mode.js";
32
31
  import { runAgentLoop } from "../../kernel/agent-loop.js";
33
32
  import { createErrorClassifier } from "../../intelligence/error-classifier.js";
@@ -35,9 +34,10 @@ import { createToolExecutor } from "../../tools/exec.js";
35
34
  import { createInkApprovalBus, } from "./ink-approval-bus.js";
36
35
  import { ApprovalPrompt, } from "./components/ApprovalPrompt.js";
37
36
  import { PRICES } from "../../intelligence/prices.js";
37
+ import { Logo } from "./components/Logo.js";
38
38
  import { StatusBar } from "./components/StatusBar.js";
39
39
  import { StreamingText } from "./components/StreamingText.js";
40
- import { ThinkingBlock, ThinkingBlockGroup, } from "./components/ThinkingBlock.js";
40
+ import { ThinkingBlock } from "./components/ThinkingBlock.js";
41
41
  import { ToolBox } from "./components/ToolBox.js";
42
42
  import { ToolGroup } from "./components/ToolGroup.js";
43
43
  import { InputBox } from "./components/InputBox.js";
@@ -53,11 +53,9 @@ import { getUpdateBannerVersion } from "../../cli/update-check.js";
53
53
  import { AtFileComplete } from "./components/AtFileComplete.js";
54
54
  import { SlashComplete } from "./components/SlashComplete.js";
55
55
  import { ThemePicker } from "./components/ThemePicker.js";
56
- import { ThemeProvider, useTheme } from "./theme-context.js";
56
+ import { ThemeProvider } from "./theme-context.js";
57
57
  import { SpinnerContext } from "./spinner-context.js";
58
- import { SpinnerGlyph } from "./components/SpinnerGlyph.js";
59
58
  import { writeFile, mkdir, readFile } from "node:fs/promises";
60
- import { readFileSync, existsSync } from "node:fs";
61
59
  import { homedir } from "node:os";
62
60
  import { join as pathJoin } from "node:path";
63
61
  import { useEventProjection, } from "./use-event-projection.js";
@@ -71,7 +69,7 @@ import { createRequire } from "node:module";
71
69
  // Pulled from the installed package.json so the TUI title matches the
72
70
  // shipped binary version. Falls back to '0.0.0-dev' if the file isn't
73
71
  // reachable (e.g. an unusual deploy layout).
74
- export const VERSION = (() => {
72
+ const VERSION = (() => {
75
73
  try {
76
74
  const req = createRequire(import.meta.url);
77
75
  const pkg = req("../../../package.json");
@@ -81,19 +79,11 @@ export const VERSION = (() => {
81
79
  return "0.0.0-dev";
82
80
  }
83
81
  })();
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
82
  export function App(props) {
89
83
  const { exit } = useApp();
90
84
  const sessionIdRef = React.useRef(randomUUID());
91
85
  const historyRef = React.useRef(initialHistory(props));
92
86
  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
87
  const pendingModelRef = React.useRef(null);
98
88
  const sessionRef = React.useRef(null);
99
89
  React.useEffect(() => {
@@ -119,7 +109,6 @@ export function App(props) {
119
109
  const [transcript, setTranscript] = React.useState([]);
120
110
  const [input, setInput] = React.useState("");
121
111
  const [busy, setBusy] = React.useState(false);
122
- const [thinkingStreaming, setThinkingStreaming] = React.useState(false);
123
112
  // Prompt queue: while a turn is streaming the user can still type and
124
113
  // press Enter. Submissions land here instead of being dropped, then
125
114
  // drain FIFO when the turn finishes (see useEffect below).
@@ -156,7 +145,7 @@ export function App(props) {
156
145
  // turns. Replaces the legacy `createTuiApprovalBus` that wrote prompts
157
146
  // direct to stdout (overdrawn by Ink) and read stdin raw (hung on
158
147
  // Windows). See `ink-approval-bus.ts` for the full rationale.
159
- const approvalBusRef = React.useRef(null);
148
+ const approvalBusRef = React.useRef();
160
149
  if (!approvalBusRef.current) {
161
150
  approvalBusRef.current = createInkApprovalBus(new Set(props.config.autoApproveTools));
162
151
  }
@@ -303,18 +292,8 @@ export function App(props) {
303
292
  liveOutputTokensAccRef.current = 0;
304
293
  setLiveOutputTokens(0);
305
294
  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
295
  }
314
296
  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
297
  liveOutputTokensAccRef.current += (ev.delta?.length ?? 0) / 4;
319
298
  }
320
299
  else if (ev.type === "usage") {
@@ -417,7 +396,7 @@ export function App(props) {
417
396
  });
418
397
  // A new submission supersedes any pending failover prompt.
419
398
  setPendingFailover(null);
420
- if (value === "/exit" || value === "/quit" || value === "/stop") {
399
+ if (value === "/exit" || value === "/quit") {
421
400
  exit();
422
401
  return;
423
402
  }
@@ -435,36 +414,23 @@ export function App(props) {
435
414
  if (value.startsWith("/model ")) {
436
415
  const id = value.slice("/model ".length).trim();
437
416
  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);
417
+ const valid = PRICES.some((p) => p.model === id);
418
+ if (!valid) {
442
419
  const note = {
443
420
  kind: "notice",
444
421
  id: randomUUID(),
445
- text: `Model set to ${exactMatch.model}`,
422
+ text: `Invalid model: ${id}. Use /models to see the catalogue.`,
446
423
  };
447
424
  setTranscript((prev) => [...prev, note]);
448
425
  }
449
426
  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
- }
427
+ setCurrentModel(id);
428
+ const note = {
429
+ kind: "notice",
430
+ id: randomUUID(),
431
+ text: `Model set to ${id}`,
432
+ };
433
+ setTranscript((prev) => [...prev, note]);
468
434
  }
469
435
  }
470
436
  return;
@@ -554,11 +520,7 @@ export function App(props) {
554
520
  exit();
555
521
  process.exit(code);
556
522
  },
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
- },
523
+ getToken: () => tokenRef.current,
562
524
  setToken: (newToken) => {
563
525
  tokenRef.current = newToken;
564
526
  },
@@ -747,10 +709,7 @@ export function App(props) {
747
709
  }
748
710
  catch (err) {
749
711
  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);
712
+ const keyMatch = /^([A-Z][A-Z0-9_]+_API_KEY) is required/.exec(msg);
754
713
  if (keyMatch?.[1]) {
755
714
  setPendingKey({
756
715
  keyName: keyMatch[1],
@@ -766,19 +725,6 @@ export function App(props) {
766
725
  }
767
726
  }
768
727
  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
728
  const committed = projection.commitLive();
783
729
  if (committed.length > 0)
784
730
  setTranscript((prev) => [...prev, ...committed]);
@@ -786,12 +732,7 @@ export function App(props) {
786
732
  abortRef.current = null;
787
733
  }
788
734
  };
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
- });
735
+ runTurnRef.current = runTurn;
795
736
  // Drain the prompt queue when a turn finishes. Pops the oldest queued
796
737
  // prompt and re-submits it through handleSubmit (which transitions
797
738
  // back into busy=true via runTurn). Guarded on `!busy` so we never
@@ -811,8 +752,6 @@ export function App(props) {
811
752
  // 2. If a turn is streaming → abort it (cancels the in-flight LLM
812
753
  // request via the AbortController plumbed through runAgentLoop).
813
754
  // 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
755
  // Always active so Esc behaves like the user expects regardless of
817
756
  // which surface they're looking at. The atfile overlay handles its
818
757
  // own Esc (cancel completion) so we skip step 1 there.
@@ -824,23 +763,33 @@ export function App(props) {
824
763
  return;
825
764
  }
826
765
  if (busy && abortRef.current !== null) {
827
- interruptMsgRef.current = "Cancelled.";
828
766
  abortRef.current.abort();
767
+ projection.appendLive({
768
+ kind: "notice",
769
+ id: randomUUID(),
770
+ text: "Cancelled.",
771
+ });
829
772
  return;
830
773
  }
831
- if (input.length > 0 && props.config.vimMode !== true)
774
+ if (input.length > 0)
832
775
  setInput("");
833
776
  });
834
777
  // Ctrl-C handler: if a turn is running, abort it and show "[Interrupted]"
835
778
  // 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.
779
+ // If idle, let the process exit normally via app.exit().
838
780
  useInput((ch, key) => {
839
781
  if (!(key.ctrl && ch === "c"))
840
782
  return;
841
783
  if (busy && abortRef.current !== null) {
842
- interruptMsgRef.current = "[Interrupted]";
843
784
  abortRef.current.abort();
785
+ projection.appendLive({
786
+ kind: "notice",
787
+ id: randomUUID(),
788
+ text: "[Interrupted]",
789
+ });
790
+ }
791
+ else {
792
+ exit();
844
793
  }
845
794
  });
846
795
  const handleModelPick = React.useCallback((id) => {
@@ -866,7 +815,7 @@ export function App(props) {
866
815
  }
867
816
  catch (err) {
868
817
  const msg = err instanceof Error ? err.message : String(err);
869
- const m = /^([A-Z][A-Z0-9_]+_API_KEY) is required$/.exec(msg);
818
+ const m = /([A-Z][A-Z0-9_]+_API_KEY) is required/.exec(msg);
870
819
  if (m?.[1]) {
871
820
  // Open inline key entry instead of a static hint — the user can
872
821
  // paste their key right here without leaving the REPL.
@@ -1006,18 +955,10 @@ export function App(props) {
1006
955
  }
1007
956
  })();
1008
957
  }, [overlays]);
1009
- const liveJsx = React.useMemo(() => renderTranscript(projection.liveItems, thinkingStreaming), [projection.liveItems, thinkingStreaming]);
958
+ const liveJsx = React.useMemo(() => renderTranscript(projection.liveItems), [projection.liveItems]);
1010
959
  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) => {
960
+ const LOGO_ITEMS = React.useMemo(() => [{ key: "logo" }], []);
961
+ 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 }), pendingApproval !== null && approvalBusRef.current && (_jsx(ApprovalPrompt, { request: pendingApproval, onResolve: (decision) => {
1021
962
  approvalBusRef.current?.resolve(pendingApproval.id, decision);
1022
963
  } })), pendingFailover !== null && (_jsx(ModelSwitchPrompt, { failedModel: pendingFailover.failedModel, failoverModel: pendingFailover.failoverModel, onAccept: (failover) => {
1023
964
  const lastPrompt = pendingFailover.lastPrompt;
@@ -1076,36 +1017,24 @@ export function App(props) {
1076
1017
  }
1077
1018
  /**
1078
1019
  * 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>.
1020
+ * <ToolGroup>. Non-tool items render via <TranscriptRow>. The grouping
1021
+ * is intentionally simple — we look at adjacency, not assistant-turn
1022
+ * boundaries, because the projection emits tools contiguously between
1023
+ * `text` spans of the same turn.
1082
1024
  */
1083
- function renderTranscript(items, thinkingStreaming) {
1025
+ function renderTranscript(items) {
1084
1026
  const out = [];
1085
1027
  let toolBuf = [];
1086
- let thinkBuf = [];
1087
1028
  const flushTools = () => {
1088
1029
  if (toolBuf.length === 0)
1089
1030
  return;
1031
+ // Key on the stable ID of the first tool so React never unmounts/remounts
1032
+ // the ToolGroup subtree when the counter resets (which caused flicker).
1090
1033
  out.push(_jsx(ToolGroup, { tools: toolBuf }, toolBuf[0].id));
1091
1034
  toolBuf = [];
1092
1035
  };
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
1036
  for (const item of items) {
1107
1037
  if (item.kind === "tool") {
1108
- flushThinking();
1109
1038
  toolBuf.push({
1110
1039
  id: item.id,
1111
1040
  name: item.name,
@@ -1118,27 +1047,20 @@ function renderTranscript(items, thinkingStreaming) {
1118
1047
  });
1119
1048
  continue;
1120
1049
  }
1121
- if (item.kind === "thinking") {
1122
- flushTools();
1123
- thinkBuf.push({ id: item.id, content: item.content });
1124
- continue;
1125
- }
1126
1050
  flushTools();
1127
- flushThinking();
1128
- out.push(_jsx(TranscriptRow, { item: item, isStreaming: thinkingStreaming }, item.id));
1051
+ out.push(_jsx(TranscriptRow, { item: item }, item.id));
1129
1052
  }
1130
1053
  flushTools();
1131
- flushThinking();
1132
1054
  return out;
1133
1055
  }
1134
- function TranscriptRow({ item, isStreaming = false, }) {
1056
+ function TranscriptRow({ item, }) {
1135
1057
  switch (item.kind) {
1136
1058
  case "user":
1137
1059
  return (_jsxs(Box, { gap: 2, marginBottom: 1, children: [_jsx(Text, { color: "magenta", children: "\u276F" }), _jsx(Text, { color: "white", children: item.text })] }));
1138
1060
  case "text":
1139
1061
  return _jsx(StreamingText, { content: item.content });
1140
1062
  case "thinking":
1141
- return _jsx(ThinkingBlock, { content: item.content, isStreaming: isStreaming });
1063
+ return _jsx(ThinkingBlock, { content: item.content });
1142
1064
  case "tool":
1143
1065
  // Should not be reached — tools are folded by renderTranscript() into
1144
1066
  // <ToolGroup>. Kept as a safety net so an unexpected tool item still
@@ -1150,23 +1072,7 @@ function TranscriptRow({ item, isStreaming = false, }) {
1150
1072
  return (_jsx(Box, { marginBottom: 1, children: _jsx(Text, { color: "yellow", children: item.text }) }));
1151
1073
  }
1152
1074
  }
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
1075
  function initialHistory(props) {
1168
- if (_cachedInitialMessages !== null)
1169
- return _cachedInitialMessages;
1170
1076
  const base = props.initialMessages ? [...props.initialMessages] : [];
1171
1077
  // Boot context: mode preamble + project primer (DIRGHA.md) +
1172
1078
  // caller's --system. Without this, the Ink TUI starts with zero
@@ -1183,18 +1089,30 @@ function initialHistory(props) {
1183
1089
  userSystem: props.systemPrompt,
1184
1090
  });
1185
1091
  base.unshift({ role: "system", content: composedSystem });
1186
- _cachedInitialMessages = base;
1187
1092
  return base;
1188
1093
  }
1189
1094
  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
- }
1095
+ // Light heuristic so StatusBar has a hint without importing dispatch.
1096
+ // Real routing still lives in providers/dispatch.ts at run time.
1097
+ if (model.includes("claude"))
1098
+ return "anthropic";
1099
+ if (model.includes("gpt") || model.startsWith("o1") || model.startsWith("o3"))
1100
+ return "openai";
1101
+ if (model.includes("gemini"))
1102
+ return "gemini";
1103
+ if (model.includes("deepseek"))
1104
+ return "deepseek";
1105
+ if (model.includes("kimi") || model.includes("moonshot"))
1106
+ return "nvidia";
1107
+ if (model.includes("llama") ||
1108
+ model.includes("nvidia") ||
1109
+ model.includes("minimax"))
1110
+ return "nvidia";
1111
+ if (model.includes("fireworks"))
1112
+ return "fireworks";
1113
+ if (model.includes("/"))
1114
+ return "openrouter";
1115
+ return "local";
1198
1116
  }
1199
1117
  const PROVIDER_BLURB = {
1200
1118
  anthropic: "Claude — Opus, Sonnet, Haiku",
@@ -1253,24 +1171,6 @@ const PROVIDER_LABEL = {
1253
1171
  zai: "Z.AI / GLM",
1254
1172
  local: "Local",
1255
1173
  };
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
1174
  /**
1275
1175
  * Group the flat model catalogue into per-provider entries for stage 1
1276
1176
  * of the picker. Skips providers with zero models in the catalogue.
@@ -1286,13 +1186,7 @@ function buildProviderEntries(models, currentModel) {
1286
1186
  const out = [];
1287
1187
  for (const [id, items] of buckets) {
1288
1188
  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
1189
+ const hasKey = env ? !!process.env[env] : true; // local providers don't need keys
1296
1190
  out.push({
1297
1191
  id,
1298
1192
  label: PROVIDER_LABEL[id] ?? id,