@draht/coding-agent 2026.6.11 → 2026.7.7

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 (302) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +1 -4
  3. package/dist/bun/register-bedrock.d.ts.map +1 -1
  4. package/dist/bun/register-bedrock.js +1 -1
  5. package/dist/bun/register-bedrock.js.map +1 -1
  6. package/dist/bun/restore-sandbox-env.d.ts +4 -0
  7. package/dist/bun/restore-sandbox-env.d.ts.map +1 -1
  8. package/dist/bun/restore-sandbox-env.js +4 -0
  9. package/dist/bun/restore-sandbox-env.js.map +1 -1
  10. package/dist/cli/args.d.ts.map +1 -1
  11. package/dist/cli/args.js +4 -4
  12. package/dist/cli/args.js.map +1 -1
  13. package/dist/cli/config-selector.d.ts +4 -2
  14. package/dist/cli/config-selector.d.ts.map +1 -1
  15. package/dist/cli/config-selector.js +1 -1
  16. package/dist/cli/config-selector.js.map +1 -1
  17. package/dist/cli/file-processor.d.ts.map +1 -1
  18. package/dist/cli/file-processor.js +13 -25
  19. package/dist/cli/file-processor.js.map +1 -1
  20. package/dist/cli/session-picker.d.ts +2 -1
  21. package/dist/cli/session-picker.d.ts.map +1 -1
  22. package/dist/cli/session-picker.js +5 -4
  23. package/dist/cli/session-picker.js.map +1 -1
  24. package/dist/cli/startup-ui.d.ts +5 -1
  25. package/dist/cli/startup-ui.d.ts.map +1 -1
  26. package/dist/cli/startup-ui.js +94 -22
  27. package/dist/cli/startup-ui.js.map +1 -1
  28. package/dist/config.d.ts +6 -2
  29. package/dist/config.d.ts.map +1 -1
  30. package/dist/config.js +35 -16
  31. package/dist/config.js.map +1 -1
  32. package/dist/core/agent-session.d.ts +10 -4
  33. package/dist/core/agent-session.d.ts.map +1 -1
  34. package/dist/core/agent-session.js +124 -83
  35. package/dist/core/agent-session.js.map +1 -1
  36. package/dist/core/auth-storage.d.ts +11 -12
  37. package/dist/core/auth-storage.d.ts.map +1 -1
  38. package/dist/core/auth-storage.js +25 -26
  39. package/dist/core/auth-storage.js.map +1 -1
  40. package/dist/core/compaction/branch-summarization.d.ts +3 -1
  41. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  42. package/dist/core/compaction/branch-summarization.js +3 -3
  43. package/dist/core/compaction/branch-summarization.js.map +1 -1
  44. package/dist/core/compaction/compaction.d.ts +5 -4
  45. package/dist/core/compaction/compaction.d.ts.map +1 -1
  46. package/dist/core/compaction/compaction.js +23 -20
  47. package/dist/core/compaction/compaction.js.map +1 -1
  48. package/dist/core/export-html/vendor/marked.min.js +75 -3
  49. package/dist/core/extensions/index.d.ts +1 -1
  50. package/dist/core/extensions/index.d.ts.map +1 -1
  51. package/dist/core/extensions/index.js.map +1 -1
  52. package/dist/core/extensions/loader.d.ts +2 -3
  53. package/dist/core/extensions/loader.d.ts.map +1 -1
  54. package/dist/core/extensions/loader.js +77 -14
  55. package/dist/core/extensions/loader.js.map +1 -1
  56. package/dist/core/extensions/runner.d.ts +2 -1
  57. package/dist/core/extensions/runner.d.ts.map +1 -1
  58. package/dist/core/extensions/runner.js +33 -1
  59. package/dist/core/extensions/runner.js.map +1 -1
  60. package/dist/core/extensions/types.d.ts +29 -2
  61. package/dist/core/extensions/types.d.ts.map +1 -1
  62. package/dist/core/extensions/types.js.map +1 -1
  63. package/dist/core/http-dispatcher.d.ts +1 -0
  64. package/dist/core/http-dispatcher.d.ts.map +1 -1
  65. package/dist/core/http-dispatcher.js +45 -2
  66. package/dist/core/http-dispatcher.js.map +1 -1
  67. package/dist/core/index.d.ts +1 -1
  68. package/dist/core/index.d.ts.map +1 -1
  69. package/dist/core/index.js.map +1 -1
  70. package/dist/core/keybindings.d.ts +1 -1
  71. package/dist/core/keybindings.d.ts.map +1 -1
  72. package/dist/core/keybindings.js +3 -6
  73. package/dist/core/keybindings.js.map +1 -1
  74. package/dist/core/model-registry.d.ts +2 -1
  75. package/dist/core/model-registry.d.ts.map +1 -1
  76. package/dist/core/model-registry.js +32 -67
  77. package/dist/core/model-registry.js.map +1 -1
  78. package/dist/core/model-resolver.d.ts +11 -1
  79. package/dist/core/model-resolver.d.ts.map +1 -1
  80. package/dist/core/model-resolver.js +37 -19
  81. package/dist/core/model-resolver.js.map +1 -1
  82. package/dist/core/package-manager.d.ts +5 -2
  83. package/dist/core/package-manager.d.ts.map +1 -1
  84. package/dist/core/package-manager.js +99 -43
  85. package/dist/core/package-manager.js.map +1 -1
  86. package/dist/core/project-trust.d.ts.map +1 -1
  87. package/dist/core/project-trust.js +4 -3
  88. package/dist/core/project-trust.js.map +1 -1
  89. package/dist/core/provider-attribution.d.ts +2 -2
  90. package/dist/core/provider-attribution.d.ts.map +1 -1
  91. package/dist/core/provider-attribution.js.map +1 -1
  92. package/dist/core/provider-display-names.d.ts.map +1 -1
  93. package/dist/core/provider-display-names.js +1 -1
  94. package/dist/core/provider-display-names.js.map +1 -1
  95. package/dist/core/resolve-config-value.d.ts +7 -8
  96. package/dist/core/resolve-config-value.d.ts.map +1 -1
  97. package/dist/core/resolve-config-value.js +24 -26
  98. package/dist/core/resolve-config-value.js.map +1 -1
  99. package/dist/core/resource-loader.d.ts +3 -2
  100. package/dist/core/resource-loader.d.ts.map +1 -1
  101. package/dist/core/resource-loader.js +16 -6
  102. package/dist/core/resource-loader.js.map +1 -1
  103. package/dist/core/sdk.d.ts +9 -9
  104. package/dist/core/sdk.d.ts.map +1 -1
  105. package/dist/core/sdk.js +3 -1
  106. package/dist/core/sdk.js.map +1 -1
  107. package/dist/core/session-manager.d.ts +21 -2
  108. package/dist/core/session-manager.d.ts.map +1 -1
  109. package/dist/core/session-manager.js +121 -77
  110. package/dist/core/session-manager.js.map +1 -1
  111. package/dist/core/settings-manager.d.ts +10 -1
  112. package/dist/core/settings-manager.d.ts.map +1 -1
  113. package/dist/core/settings-manager.js +29 -3
  114. package/dist/core/settings-manager.js.map +1 -1
  115. package/dist/core/system-prompt.d.ts.map +1 -1
  116. package/dist/core/system-prompt.js +7 -7
  117. package/dist/core/system-prompt.js.map +1 -1
  118. package/dist/core/timings.d.ts +4 -2
  119. package/dist/core/timings.d.ts.map +1 -1
  120. package/dist/core/timings.js +24 -14
  121. package/dist/core/timings.js.map +1 -1
  122. package/dist/core/tools/bash.d.ts.map +1 -1
  123. package/dist/core/tools/bash.js +32 -8
  124. package/dist/core/tools/bash.js.map +1 -1
  125. package/dist/core/tools/edit-diff.d.ts +23 -4
  126. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  127. package/dist/core/tools/edit-diff.js +99 -20
  128. package/dist/core/tools/edit-diff.js.map +1 -1
  129. package/dist/core/tools/edit.d.ts.map +1 -1
  130. package/dist/core/tools/edit.js +2 -2
  131. package/dist/core/tools/edit.js.map +1 -1
  132. package/dist/core/tools/find.d.ts.map +1 -1
  133. package/dist/core/tools/find.js +19 -11
  134. package/dist/core/tools/find.js.map +1 -1
  135. package/dist/core/tools/read.d.ts.map +1 -1
  136. package/dist/core/tools/read.js +12 -25
  137. package/dist/core/tools/read.js.map +1 -1
  138. package/dist/core/trust-manager.d.ts +8 -3
  139. package/dist/core/trust-manager.d.ts.map +1 -1
  140. package/dist/core/trust-manager.js +26 -11
  141. package/dist/core/trust-manager.js.map +1 -1
  142. package/dist/index.d.ts +6 -4
  143. package/dist/index.d.ts.map +1 -1
  144. package/dist/index.js +5 -3
  145. package/dist/index.js.map +1 -1
  146. package/dist/main.d.ts +2 -2
  147. package/dist/main.d.ts.map +1 -1
  148. package/dist/main.js +47 -15
  149. package/dist/main.js.map +1 -1
  150. package/dist/migrations.d.ts.map +1 -1
  151. package/dist/migrations.js +1 -123
  152. package/dist/migrations.js.map +1 -1
  153. package/dist/modes/interactive/assets/clankolas.png +0 -0
  154. package/dist/modes/interactive/components/assistant-message.d.ts +3 -1
  155. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  156. package/dist/modes/interactive/components/assistant-message.js +23 -15
  157. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  158. package/dist/modes/interactive/components/config-selector.d.ts +34 -3
  159. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  160. package/dist/modes/interactive/components/config-selector.js +284 -29
  161. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  162. package/dist/modes/interactive/components/custom-entry.d.ts +19 -0
  163. package/dist/modes/interactive/components/custom-entry.d.ts.map +1 -0
  164. package/dist/modes/interactive/components/custom-entry.js +52 -0
  165. package/dist/modes/interactive/components/custom-entry.js.map +1 -0
  166. package/dist/modes/interactive/components/extension-editor.d.ts +3 -1
  167. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  168. package/dist/modes/interactive/components/extension-editor.js +12 -3
  169. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  170. package/dist/modes/interactive/components/footer.d.ts +2 -2
  171. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  172. package/dist/modes/interactive/components/footer.js +4 -0
  173. package/dist/modes/interactive/components/footer.js.map +1 -1
  174. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  175. package/dist/modes/interactive/components/login-dialog.js +0 -1
  176. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  177. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  178. package/dist/modes/interactive/components/model-selector.js +2 -1
  179. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  180. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  181. package/dist/modes/interactive/components/scoped-models-selector.js +4 -1
  182. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  183. package/dist/modes/interactive/components/session-selector.d.ts +0 -1
  184. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  185. package/dist/modes/interactive/components/session-selector.js +14 -8
  186. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  187. package/dist/modes/interactive/components/settings-selector.d.ts +4 -0
  188. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  189. package/dist/modes/interactive/components/settings-selector.js +188 -16
  190. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  191. package/dist/modes/interactive/components/status-indicator.d.ts +28 -0
  192. package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -0
  193. package/dist/modes/interactive/components/status-indicator.js +60 -0
  194. package/dist/modes/interactive/components/status-indicator.js.map +1 -0
  195. package/dist/modes/interactive/components/tree-selector.d.ts +1 -1
  196. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  197. package/dist/modes/interactive/components/tree-selector.js +130 -15
  198. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  199. package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -1
  200. package/dist/modes/interactive/components/trust-selector.js +4 -4
  201. package/dist/modes/interactive/components/trust-selector.js.map +1 -1
  202. package/dist/modes/interactive/components/user-message.d.ts +6 -2
  203. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  204. package/dist/modes/interactive/components/user-message.js +19 -6
  205. package/dist/modes/interactive/components/user-message.js.map +1 -1
  206. package/dist/modes/interactive/interactive-mode.d.ts +13 -11
  207. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  208. package/dist/modes/interactive/interactive-mode.js +252 -233
  209. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  210. package/dist/modes/interactive/model-search.d.ts +12 -0
  211. package/dist/modes/interactive/model-search.d.ts.map +1 -0
  212. package/dist/modes/interactive/model-search.js +15 -0
  213. package/dist/modes/interactive/model-search.js.map +1 -0
  214. package/dist/modes/interactive/theme/theme-controller.d.ts +29 -0
  215. package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -0
  216. package/dist/modes/interactive/theme/theme-controller.js +102 -0
  217. package/dist/modes/interactive/theme/theme-controller.js.map +1 -0
  218. package/dist/modes/interactive/theme/theme-schema.json +2 -1
  219. package/dist/modes/interactive/theme/theme.d.ts +27 -8
  220. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  221. package/dist/modes/interactive/theme/theme.js +64 -42
  222. package/dist/modes/interactive/theme/theme.js.map +1 -1
  223. package/dist/modes/rpc/rpc-client.d.ts +19 -4
  224. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  225. package/dist/modes/rpc/rpc-client.js +14 -0
  226. package/dist/modes/rpc/rpc-client.js.map +1 -1
  227. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  228. package/dist/modes/rpc/rpc-mode.js +17 -1
  229. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  230. package/dist/modes/rpc/rpc-types.d.ts +26 -0
  231. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  232. package/dist/modes/rpc/rpc-types.js.map +1 -1
  233. package/dist/package-manager-cli.d.ts +2 -2
  234. package/dist/package-manager-cli.d.ts.map +1 -1
  235. package/dist/package-manager-cli.js +152 -48
  236. package/dist/package-manager-cli.js.map +1 -1
  237. package/dist/prompts/commands/brainstorm.md +148 -0
  238. package/dist/rpc-entry.d.ts +3 -0
  239. package/dist/rpc-entry.d.ts.map +1 -0
  240. package/dist/rpc-entry.js +10 -0
  241. package/dist/rpc-entry.js.map +1 -0
  242. package/dist/utils/child-process.d.ts +7 -4
  243. package/dist/utils/child-process.d.ts.map +1 -1
  244. package/dist/utils/child-process.js +23 -5
  245. package/dist/utils/child-process.js.map +1 -1
  246. package/dist/utils/image-convert.d.ts +1 -0
  247. package/dist/utils/image-convert.d.ts.map +1 -1
  248. package/dist/utils/image-convert.js +21 -15
  249. package/dist/utils/image-convert.js.map +1 -1
  250. package/dist/utils/image-process.d.ts +18 -0
  251. package/dist/utils/image-process.d.ts.map +1 -0
  252. package/dist/utils/image-process.js +83 -0
  253. package/dist/utils/image-process.js.map +1 -0
  254. package/dist/utils/mime.d.ts.map +1 -1
  255. package/dist/utils/mime.js +41 -0
  256. package/dist/utils/mime.js.map +1 -1
  257. package/dist/utils/shell.d.ts +1 -0
  258. package/dist/utils/shell.d.ts.map +1 -1
  259. package/dist/utils/shell.js +12 -5
  260. package/dist/utils/shell.js.map +1 -1
  261. package/dist/utils/version-check.d.ts.map +1 -1
  262. package/dist/utils/version-check.js +4 -27
  263. package/dist/utils/version-check.js.map +1 -1
  264. package/docs/extensions.md +55 -8
  265. package/docs/keybindings.md +1 -1
  266. package/docs/packages.md +2 -2
  267. package/docs/providers.md +2 -1
  268. package/docs/rpc.md +58 -0
  269. package/docs/sdk.md +50 -0
  270. package/docs/session-format.md +18 -8
  271. package/docs/settings.md +10 -0
  272. package/docs/usage.md +2 -2
  273. package/examples/extensions/README.md +1 -0
  274. package/examples/extensions/custom-compaction.ts +2 -1
  275. package/examples/extensions/custom-provider-anthropic/index.ts +1 -1
  276. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  277. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  278. package/examples/extensions/custom-provider-gitlab-duo/index.ts +9 -5
  279. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  280. package/examples/extensions/custom-provider-gitlab-duo/test.ts +1 -1
  281. package/examples/extensions/entry-renderer.ts +41 -0
  282. package/examples/extensions/gondolin/package-lock.json +2 -2
  283. package/examples/extensions/gondolin/package.json +1 -1
  284. package/examples/extensions/handoff.ts +2 -2
  285. package/examples/extensions/plan-mode/index.ts +87 -37
  286. package/examples/extensions/preset.ts +10 -4
  287. package/examples/extensions/provider-payload.ts +5 -5
  288. package/examples/extensions/qna.ts +2 -2
  289. package/examples/extensions/question.ts +32 -18
  290. package/examples/extensions/questionnaire.ts +41 -28
  291. package/examples/extensions/sandbox/index.ts +2 -2
  292. package/examples/extensions/sandbox/package-lock.json +2 -2
  293. package/examples/extensions/sandbox/package.json +1 -1
  294. package/examples/extensions/subagent/agents.ts +2 -2
  295. package/examples/extensions/subagent/index.ts +9 -3
  296. package/examples/extensions/summarize.ts +2 -1
  297. package/examples/extensions/with-deps/package-lock.json +2 -2
  298. package/examples/extensions/with-deps/package.json +1 -1
  299. package/examples/sdk/02-custom-model.ts +1 -1
  300. package/examples/sdk/12-full-control.ts +2 -2
  301. package/package.json +14 -15
  302. package/prompts/commands/brainstorm.md +148 -0
@@ -6,11 +6,11 @@ import * as crypto from "node:crypto";
6
6
  import * as fs from "node:fs";
7
7
  import * as os from "node:os";
8
8
  import * as path from "node:path";
9
- import { getProviders, } from "@draht/ai";
10
- import { CombinedAutocompleteProvider, Container, fuzzyFilter, getCapabilities, hyperlink, Loader, Markdown, matchesKey, ProcessTerminal, Spacer, setKeybindings, Text, TruncatedText, TUI, visibleWidth, } from "@draht/tui";
9
+ import { getProviders, } from "@draht/ai/compat";
10
+ import { CombinedAutocompleteProvider, Container, fuzzyFilter, getCapabilities, hyperlink, Markdown, matchesKey, ProcessTerminal, Spacer, setKeybindings, Text, TruncatedText, TUI, visibleWidth, } from "@draht/tui";
11
11
  import chalk from "chalk";
12
12
  import { spawn, spawnSync } from "child_process";
13
- import { APP_NAME, APP_TITLE, DISPLAY_VERSION, getAgentDir, getAuthPath, getDebugLogPath, getDocsPath, getShareViewerUrl, VERSION, } from "../../config.js";
13
+ import { APP_NAME, APP_TITLE, CONFIG_DIR_NAME, DISPLAY_VERSION, getAgentDir, getAuthPath, getDebugLogPath, getDocsPath, getShareViewerUrl, VERSION, } from "../../config.js";
14
14
  import { parseSkillBlock } from "../../core/agent-session.js";
15
15
  import { SessionImportFileNotFoundError } from "../../core/agent-session-runtime.js";
16
16
  import { FooterDataProvider } from "../../core/footer-data-provider.js";
@@ -21,10 +21,10 @@ import { defaultModelPerProvider, findExactModelReferenceMatch, resolveModelScop
21
21
  import { DefaultPackageManager } from "../../core/package-manager.js";
22
22
  import { BUILT_IN_PROVIDER_DISPLAY_NAMES } from "../../core/provider-display-names.js";
23
23
  import { formatMissingSessionCwdPrompt, MissingSessionCwdError } from "../../core/session-cwd.js";
24
- import { SessionManager } from "../../core/session-manager.js";
24
+ import { SessionManager, sessionEntryToContextMessages } from "../../core/session-manager.js";
25
25
  import { BUILTIN_SLASH_COMMANDS } from "../../core/slash-commands.js";
26
26
  import { isInstallTelemetryEnabled } from "../../core/telemetry.js";
27
- import { hasProjectConfigDir, hasProjectTrustInputs, ProjectTrustStore } from "../../core/trust-manager.js";
27
+ import { hasTrustRequiringProjectResources, ProjectTrustStore } from "../../core/trust-manager.js";
28
28
  import { getChangelogPath, getNewEntries, normalizeChangelogLinks, parseChangelog } from "../../utils/changelog.js";
29
29
  import { copyToClipboard } from "../../utils/clipboard.js";
30
30
  import { extensionForImageMimeType, readClipboardImage } from "../../utils/clipboard-image.js";
@@ -40,8 +40,8 @@ import { BashExecutionComponent } from "./components/bash-execution.js";
40
40
  import { BorderedLoader } from "./components/bordered-loader.js";
41
41
  import { BranchSummaryMessageComponent } from "./components/branch-summary-message.js";
42
42
  import { CompactionSummaryMessageComponent } from "./components/compaction-summary-message.js";
43
- import { CountdownTimer } from "./components/countdown-timer.js";
44
43
  import { CustomEditor } from "./components/custom-editor.js";
44
+ import { CustomEntryComponent } from "./components/custom-entry.js";
45
45
  import { CustomMessageComponent } from "./components/custom-message.js";
46
46
  import { DaxnutsComponent } from "./components/daxnuts.js";
47
47
  import { DynamicBorder } from "./components/dynamic-border.js";
@@ -58,12 +58,15 @@ import { ScopedModelsSelectorComponent } from "./components/scoped-models-select
58
58
  import { SessionSelectorComponent } from "./components/session-selector.js";
59
59
  import { SettingsSelectorComponent } from "./components/settings-selector.js";
60
60
  import { SkillInvocationMessageComponent } from "./components/skill-invocation-message.js";
61
+ import { BranchSummaryStatusIndicator, CompactionStatusIndicator, IdleStatus, RetryStatusIndicator, WorkingStatusIndicator, } from "./components/status-indicator.js";
61
62
  import { ToolExecutionComponent } from "./components/tool-execution.js";
62
63
  import { TreeSelectorComponent } from "./components/tree-selector.js";
63
64
  import { TrustSelectorComponent } from "./components/trust-selector.js";
64
65
  import { UserMessageComponent } from "./components/user-message.js";
65
66
  import { UserMessageSelectorComponent } from "./components/user-message-selector.js";
66
- import { getAvailableThemes, getAvailableThemesWithPaths, getEditorTheme, getMarkdownTheme, getThemeByName, initTheme, onThemeChange, setRegisteredThemes, setTheme, setThemeInstance, stopThemeWatcher, Theme, theme, } from "./theme/theme.js";
67
+ import { getModelSearchText } from "./model-search.js";
68
+ import { getAvailableThemes, getAvailableThemesWithPaths, getEditorTheme, getMarkdownTheme, getThemeByName, onThemeChange, setRegisteredThemes, stopThemeWatcher, Theme, theme, } from "./theme/theme.js";
69
+ import { InteractiveThemeController } from "./theme/theme-controller.js";
67
70
  function isExpandable(obj) {
68
71
  return typeof obj === "object" && obj !== null && "setExpanded" in obj && typeof obj.setExpanded === "function";
69
72
  }
@@ -79,6 +82,9 @@ class ExpandableText extends Text {
79
82
  this.setText(expanded ? this.getExpandedText() : this.getCollapsedText());
80
83
  }
81
84
  }
85
+ function isCustomSessionEntry(item) {
86
+ return "type" in item && item.type === "custom";
87
+ }
82
88
  const DEAD_TERMINAL_ERROR_CODES = new Set(["EIO", "EPIPE", "ENOTCONN"]);
83
89
  function isDeadTerminalError(error) {
84
90
  if (!error || typeof error !== "object" || !("code" in error)) {
@@ -132,6 +138,7 @@ export function isApiKeyLoginProvider(providerId, oauthProviderIds, builtInProvi
132
138
  export class InteractiveMode {
133
139
  runtimeHost;
134
140
  ui;
141
+ loadedResourcesContainer;
135
142
  chatContainer;
136
143
  pendingMessagesContainer;
137
144
  statusContainer;
@@ -150,7 +157,8 @@ export class InteractiveMode {
150
157
  isInitialized = false;
151
158
  onInputCallback;
152
159
  pendingUserInputs = [];
153
- loadingAnimation = undefined;
160
+ activeStatusIndicator = undefined;
161
+ idleStatus = new IdleStatus();
154
162
  workingMessage = undefined;
155
163
  workingVisible = true;
156
164
  workingIndicatorOptions = undefined;
@@ -174,6 +182,7 @@ export class InteractiveMode {
174
182
  toolOutputExpanded = false;
175
183
  // Thinking block visibility state
176
184
  hideThinkingBlock = false;
185
+ outputPad = 1;
177
186
  // Skill commands: command name -> skill file path
178
187
  skillCommands = new Map();
179
188
  // Agent subscription unsubscribe function
@@ -186,11 +195,8 @@ export class InteractiveMode {
186
195
  // Track pending bash components (shown in pending area, moved to chat on submit)
187
196
  pendingBashComponents = [];
188
197
  // Auto-compaction state
189
- autoCompactionLoader = undefined;
190
198
  autoCompactionEscapeHandler;
191
199
  // Auto-retry state
192
- retryLoader = undefined;
193
- retryCountdown = undefined;
194
200
  retryEscapeHandler;
195
201
  // Messages queued while compaction is running
196
202
  compactionQueuedMessages = [];
@@ -216,6 +222,7 @@ export class InteractiveMode {
216
222
  customHeader = undefined;
217
223
  options;
218
224
  autoTrustOnReloadCwd;
225
+ themeController;
219
226
  // Convenience accessors
220
227
  get session() {
221
228
  return this.runtimeHost.session;
@@ -237,12 +244,13 @@ export class InteractiveMode {
237
244
  this.resetExtensionUI();
238
245
  });
239
246
  this.runtimeHost.setRebindSession(async () => {
240
- await this.rebindCurrentSession();
247
+ await this.rebindCurrentSession({ renderBeforeBind: true });
241
248
  });
242
249
  this.version = VERSION;
243
250
  this.ui = new TUI(new ProcessTerminal(), this.settingsManager.getShowHardwareCursor());
244
251
  this.ui.setClearOnShrink(this.settingsManager.getClearOnShrink());
245
252
  this.headerContainer = new Container();
253
+ this.loadedResourcesContainer = new Container();
246
254
  this.chatContainer = new Container();
247
255
  this.pendingMessagesContainer = new Container();
248
256
  this.statusContainer = new Container();
@@ -264,9 +272,10 @@ export class InteractiveMode {
264
272
  this.footer.setAutoCompactEnabled(this.session.autoCompactionEnabled);
265
273
  // Load hide thinking block setting
266
274
  this.hideThinkingBlock = this.settingsManager.getHideThinkingBlock();
275
+ this.outputPad = this.settingsManager.getOutputPad();
267
276
  // Register themes from resource loader and initialize
268
277
  setRegisteredThemes(this.session.resourceLoader.getThemes().themes);
269
- initTheme(this.settingsManager.getTheme(), true);
278
+ this.themeController = new InteractiveThemeController(this.ui, this.settingsManager, (message) => this.showError(message), () => this.updateEditorBorderColor());
270
279
  }
271
280
  getAutocompleteSourceTag(sourceInfo) {
272
281
  if (!sourceInfo) {
@@ -326,10 +335,11 @@ export class InteractiveMode {
326
335
  const items = models.map((m) => ({
327
336
  id: m.id,
328
337
  provider: m.provider,
338
+ name: m.name,
329
339
  label: `${m.provider}/${m.id}`,
330
340
  }));
331
- // Fuzzy filter by model ID + provider (allows "opus anthropic" to match)
332
- const filtered = fuzzyFilter(items, prefix, (item) => `${item.id} ${item.provider}`);
341
+ // Fuzzy filter by model ID + provider in either order.
342
+ const filtered = fuzzyFilter(items, prefix, getModelSearchText);
333
343
  if (filtered.length === 0)
334
344
  return null;
335
345
  return filtered.map((item) => ({
@@ -435,8 +445,25 @@ export class InteractiveMode {
435
445
  : "";
436
446
  console.log(theme.fg("dim", `Model scope: ${modelList}${cycleHint}`));
437
447
  }
438
- // Add header container as first child
448
+ // Add header container as first child. Populate it after applying theme settings.
449
+ // Keep loaded resources before chat so restored session messages never precede them.
439
450
  this.ui.addChild(this.headerContainer);
451
+ this.ui.addChild(this.loadedResourcesContainer);
452
+ this.ui.addChild(this.chatContainer);
453
+ this.ui.addChild(this.pendingMessagesContainer);
454
+ this.ui.addChild(this.statusContainer);
455
+ this.renderWidgets(); // Initialize with default spacer
456
+ this.ui.addChild(this.widgetContainerAbove);
457
+ this.ui.addChild(this.editorContainer);
458
+ this.ui.addChild(this.widgetContainerBelow);
459
+ this.ui.addChild(this.footer);
460
+ this.ui.setFocus(this.editor);
461
+ this.setupKeyHandlers();
462
+ this.setupEditorSubmitHandler();
463
+ // Start the UI before initializing extensions so session_start handlers can use interactive dialogs
464
+ this.ui.start();
465
+ this.isInitialized = true;
466
+ await this.themeController.applyFromSettings();
440
467
  // Add header with keybindings from config (unless silenced)
441
468
  if (this.options.verbose || !this.settingsManager.getQuietStartup()) {
442
469
  const asciiArt = [
@@ -495,20 +522,7 @@ export class InteractiveMode {
495
522
  this.builtInHeader = new Text("", 0, 0);
496
523
  this.headerContainer.addChild(this.builtInHeader);
497
524
  }
498
- this.ui.addChild(this.chatContainer);
499
- this.ui.addChild(this.pendingMessagesContainer);
500
- this.ui.addChild(this.statusContainer);
501
- this.renderWidgets(); // Initialize with default spacer
502
- this.ui.addChild(this.widgetContainerAbove);
503
- this.ui.addChild(this.editorContainer);
504
- this.ui.addChild(this.widgetContainerBelow);
505
- this.ui.addChild(this.footer);
506
- this.ui.setFocus(this.editor);
507
- this.setupKeyHandlers();
508
- this.setupEditorSubmitHandler();
509
- // Start the UI before initializing extensions so session_start handlers can use interactive dialogs
510
- this.ui.start();
511
- this.isInitialized = true;
525
+ this.ui.requestRender();
512
526
  // Initialize extensions first so resources are shown before messages
513
527
  await this.rebindCurrentSession();
514
528
  // Render initial messages AFTER showing loaded resources
@@ -996,6 +1010,8 @@ export class InteractiveMode {
996
1010
  return lines.join("\n");
997
1011
  }
998
1012
  showLoadedResources(options) {
1013
+ // Resource rendering is idempotent; chat clears no longer clear this separate container.
1014
+ this.loadedResourcesContainer.clear();
999
1015
  const showListing = options?.force || this.options.verbose || !this.settingsManager.getQuietStartup();
1000
1016
  const showDiagnostics = showListing || options?.showDiagnosticsWhenQuiet === true;
1001
1017
  if (!showListing && !showDiagnostics) {
@@ -1011,8 +1027,8 @@ export class InteractiveMode {
1011
1027
  };
1012
1028
  const addLoadedSection = (name, collapsedBody, expandedBody = collapsedBody, color = "mdHeading") => {
1013
1029
  const section = new ExpandableText(() => `${sectionHeader(name, color)}\n${collapsedBody}`, () => `${sectionHeader(name, color)}\n${expandedBody}`, this.getStartupExpansionState(), 0, 0);
1014
- this.chatContainer.addChild(section);
1015
- this.chatContainer.addChild(new Spacer(1));
1030
+ this.loadedResourcesContainer.addChild(section);
1031
+ this.loadedResourcesContainer.addChild(new Spacer(1));
1016
1032
  };
1017
1033
  const skillsResult = this.session.resourceLoader.getSkills();
1018
1034
  const promptsResult = this.session.resourceLoader.getPrompts();
@@ -1046,7 +1062,7 @@ export class InteractiveMode {
1046
1062
  if (showListing) {
1047
1063
  const contextFiles = this.session.resourceLoader.getAgentsFiles().agentsFiles;
1048
1064
  if (contextFiles.length > 0) {
1049
- this.chatContainer.addChild(new Spacer(1));
1065
+ this.loadedResourcesContainer.addChild(new Spacer(1));
1050
1066
  const contextList = contextFiles
1051
1067
  .map((f) => theme.fg("dim", ` ${this.formatDisplayPath(f.path)}`))
1052
1068
  .join("\n");
@@ -1109,14 +1125,14 @@ export class InteractiveMode {
1109
1125
  const skillDiagnostics = skillsResult.diagnostics;
1110
1126
  if (skillDiagnostics.length > 0) {
1111
1127
  const warningLines = this.formatDiagnostics(skillDiagnostics, sourceInfos);
1112
- this.chatContainer.addChild(new Text(`${theme.fg("warning", "[Skill conflicts]")}\n${warningLines}`, 0, 0));
1113
- this.chatContainer.addChild(new Spacer(1));
1128
+ this.loadedResourcesContainer.addChild(new Text(`${theme.fg("warning", "[Skill conflicts]")}\n${warningLines}`, 0, 0));
1129
+ this.loadedResourcesContainer.addChild(new Spacer(1));
1114
1130
  }
1115
1131
  const promptDiagnostics = promptsResult.diagnostics;
1116
1132
  if (promptDiagnostics.length > 0) {
1117
1133
  const warningLines = this.formatDiagnostics(promptDiagnostics, sourceInfos);
1118
- this.chatContainer.addChild(new Text(`${theme.fg("warning", "[Prompt conflicts]")}\n${warningLines}`, 0, 0));
1119
- this.chatContainer.addChild(new Spacer(1));
1134
+ this.loadedResourcesContainer.addChild(new Text(`${theme.fg("warning", "[Prompt conflicts]")}\n${warningLines}`, 0, 0));
1135
+ this.loadedResourcesContainer.addChild(new Spacer(1));
1120
1136
  }
1121
1137
  const extensionDiagnostics = [];
1122
1138
  const extensionErrors = this.session.resourceLoader.getExtensions().errors;
@@ -1132,14 +1148,14 @@ export class InteractiveMode {
1132
1148
  extensionDiagnostics.push(...shortcutDiagnostics);
1133
1149
  if (extensionDiagnostics.length > 0) {
1134
1150
  const warningLines = this.formatDiagnostics(extensionDiagnostics, sourceInfos);
1135
- this.chatContainer.addChild(new Text(`${theme.fg("warning", "[Extension issues]")}\n${warningLines}`, 0, 0));
1136
- this.chatContainer.addChild(new Spacer(1));
1151
+ this.loadedResourcesContainer.addChild(new Text(`${theme.fg("warning", "[Extension issues]")}\n${warningLines}`, 0, 0));
1152
+ this.loadedResourcesContainer.addChild(new Spacer(1));
1137
1153
  }
1138
1154
  const themeDiagnostics = themesResult.diagnostics;
1139
1155
  if (themeDiagnostics.length > 0) {
1140
1156
  const warningLines = this.formatDiagnostics(themeDiagnostics, sourceInfos);
1141
- this.chatContainer.addChild(new Text(`${theme.fg("warning", "[Theme conflicts]")}\n${warningLines}`, 0, 0));
1142
- this.chatContainer.addChild(new Spacer(1));
1157
+ this.loadedResourcesContainer.addChild(new Text(`${theme.fg("warning", "[Theme conflicts]")}\n${warningLines}`, 0, 0));
1158
+ this.loadedResourcesContainer.addChild(new Spacer(1));
1143
1159
  }
1144
1160
  }
1145
1161
  }
@@ -1157,18 +1173,9 @@ export class InteractiveMode {
1157
1173
  commandContextActions: {
1158
1174
  waitForIdle: () => this.session.agent.waitForIdle(),
1159
1175
  newSession: async (options) => {
1160
- if (this.loadingAnimation) {
1161
- this.loadingAnimation.stop();
1162
- this.loadingAnimation = undefined;
1163
- }
1164
- this.statusContainer.clear();
1176
+ this.clearStatusIndicator();
1165
1177
  try {
1166
- const result = await this.runtimeHost.newSession(options);
1167
- if (!result.cancelled) {
1168
- this.renderCurrentSessionState();
1169
- this.ui.requestRender();
1170
- }
1171
- return result;
1178
+ return await this.runtimeHost.newSession(options);
1172
1179
  }
1173
1180
  catch (error) {
1174
1181
  return this.handleFatalRuntimeError("Failed to create session", error);
@@ -1178,7 +1185,6 @@ export class InteractiveMode {
1178
1185
  try {
1179
1186
  const result = await this.runtimeHost.fork(entryId, options);
1180
1187
  if (!result.cancelled) {
1181
- this.renderCurrentSessionState();
1182
1188
  this.editor.setText(result.selectedText ?? "");
1183
1189
  this.showStatus("Forked to new session");
1184
1190
  }
@@ -1237,8 +1243,13 @@ export class InteractiveMode {
1237
1243
  this.footer.setAutoCompactEnabled(this.session.autoCompactionEnabled);
1238
1244
  this.footerDataProvider.setCwd(this.sessionManager.getCwd());
1239
1245
  this.hideThinkingBlock = this.settingsManager.getHideThinkingBlock();
1246
+ this.outputPad = this.settingsManager.getOutputPad();
1240
1247
  this.ui.setShowHardwareCursor(this.settingsManager.getShowHardwareCursor());
1241
- this.ui.setClearOnShrink(this.settingsManager.getClearOnShrink());
1248
+ const clearOnShrink = this.settingsManager.getClearOnShrink();
1249
+ this.ui.setClearOnShrink(clearOnShrink);
1250
+ if (!clearOnShrink && !this.activeStatusIndicator) {
1251
+ this.statusContainer.clear();
1252
+ }
1242
1253
  const editorPaddingX = this.settingsManager.getEditorPaddingX();
1243
1254
  const autocompleteMaxVisible = this.settingsManager.getAutocompleteMaxVisible();
1244
1255
  this.defaultEditor.setPaddingX(editorPaddingX);
@@ -1248,12 +1259,19 @@ export class InteractiveMode {
1248
1259
  this.editor.setAutocompleteMaxVisible?.(autocompleteMaxVisible);
1249
1260
  }
1250
1261
  }
1251
- async rebindCurrentSession() {
1262
+ async rebindCurrentSession(options = {}) {
1252
1263
  this.unsubscribe?.();
1253
1264
  this.unsubscribe = undefined;
1254
1265
  this.applyRuntimeSettings();
1255
- await this.bindCurrentSessionExtensions();
1256
- this.subscribeToAgent();
1266
+ if (options.renderBeforeBind) {
1267
+ this.renderCurrentSessionState();
1268
+ this.subscribeToAgent();
1269
+ await this.bindCurrentSessionExtensions();
1270
+ }
1271
+ else {
1272
+ await this.bindCurrentSessionExtensions();
1273
+ this.subscribeToAgent();
1274
+ }
1257
1275
  await this.updateAvailableProviderCount();
1258
1276
  this.updateEditorBorderColor();
1259
1277
  this.updateTerminalTitle();
@@ -1266,6 +1284,7 @@ export class InteractiveMode {
1266
1284
  process.exit(1);
1267
1285
  }
1268
1286
  renderCurrentSessionState() {
1287
+ this.loadedResourcesContainer.clear();
1269
1288
  this.chatContainer.clear();
1270
1289
  this.pendingMessagesContainer.clear();
1271
1290
  this.compactionQueuedMessages = [];
@@ -1343,36 +1362,41 @@ export class InteractiveMode {
1343
1362
  this.footerDataProvider.setExtensionStatus(key, text);
1344
1363
  this.ui.requestRender();
1345
1364
  }
1346
- getWorkingLoaderMessage() {
1347
- return this.workingMessage ?? this.defaultWorkingMessage;
1348
- }
1349
- createWorkingLoader() {
1350
- return new Loader(this.ui, (spinner) => theme.fg("accent", spinner), (text) => theme.fg("muted", text), this.getWorkingLoaderMessage(), this.workingIndicatorOptions);
1365
+ showStatusIndicator(indicator) {
1366
+ this.activeStatusIndicator?.dispose();
1367
+ this.activeStatusIndicator = indicator;
1368
+ this.statusContainer.clear();
1369
+ this.statusContainer.addChild(indicator);
1351
1370
  }
1352
- stopWorkingLoader() {
1353
- if (this.loadingAnimation) {
1354
- this.loadingAnimation.stop();
1355
- this.loadingAnimation = undefined;
1371
+ clearStatusIndicator(kind) {
1372
+ if (kind && this.activeStatusIndicator?.kind !== kind) {
1373
+ return;
1356
1374
  }
1375
+ const hadActiveStatusIndicator = this.activeStatusIndicator !== undefined;
1376
+ this.activeStatusIndicator?.dispose();
1377
+ this.activeStatusIndicator = undefined;
1357
1378
  this.statusContainer.clear();
1379
+ if (hadActiveStatusIndicator && this.ui.getClearOnShrink()) {
1380
+ this.statusContainer.addChild(this.idleStatus);
1381
+ }
1358
1382
  }
1359
1383
  setWorkingVisible(visible) {
1360
1384
  this.workingVisible = visible;
1361
1385
  if (!visible) {
1362
- this.stopWorkingLoader();
1386
+ this.clearStatusIndicator("working");
1363
1387
  this.ui.requestRender();
1364
1388
  return;
1365
1389
  }
1366
- if (this.session.isStreaming && !this.loadingAnimation) {
1367
- this.statusContainer.clear();
1368
- this.loadingAnimation = this.createWorkingLoader();
1369
- this.statusContainer.addChild(this.loadingAnimation);
1390
+ if (this.session.isStreaming && this.activeStatusIndicator?.kind !== "working") {
1391
+ this.showStatusIndicator(new WorkingStatusIndicator(this.ui, this.workingMessage ?? this.defaultWorkingMessage, this.workingIndicatorOptions));
1370
1392
  }
1371
1393
  this.ui.requestRender();
1372
1394
  }
1373
1395
  setWorkingIndicator(options) {
1374
1396
  this.workingIndicatorOptions = options;
1375
- this.loadingAnimation?.setIndicator(options);
1397
+ if (this.activeStatusIndicator?.kind === "working") {
1398
+ this.activeStatusIndicator.setIndicator(options);
1399
+ }
1376
1400
  this.ui.requestRender();
1377
1401
  }
1378
1402
  setHiddenThinkingLabel(label) {
@@ -1460,8 +1484,8 @@ export class InteractiveMode {
1460
1484
  this.workingMessage = undefined;
1461
1485
  this.workingVisible = true;
1462
1486
  this.setWorkingIndicator();
1463
- if (this.loadingAnimation) {
1464
- this.loadingAnimation.setMessage(`${this.defaultWorkingMessage} (${keyText("app.interrupt")} to interrupt)`);
1487
+ if (this.activeStatusIndicator?.kind === "working") {
1488
+ this.activeStatusIndicator.setMessage(`${this.defaultWorkingMessage} (${keyText("app.interrupt")} to interrupt)`);
1465
1489
  }
1466
1490
  this.setHiddenThinkingLabel();
1467
1491
  }
@@ -1601,8 +1625,8 @@ export class InteractiveMode {
1601
1625
  setStatus: (key, text) => this.setExtensionStatus(key, text),
1602
1626
  setWorkingMessage: (message) => {
1603
1627
  this.workingMessage = message;
1604
- if (this.loadingAnimation) {
1605
- this.loadingAnimation.setMessage(message ?? this.defaultWorkingMessage);
1628
+ if (this.activeStatusIndicator?.kind === "working") {
1629
+ this.activeStatusIndicator.setMessage(message ?? this.defaultWorkingMessage);
1606
1630
  }
1607
1631
  },
1608
1632
  setWorkingVisible: (visible) => this.setWorkingVisible(visible),
@@ -1630,16 +1654,13 @@ export class InteractiveMode {
1630
1654
  getTheme: (name) => getThemeByName(name),
1631
1655
  setTheme: (themeOrName) => {
1632
1656
  if (themeOrName instanceof Theme) {
1633
- setThemeInstance(themeOrName);
1634
- this.ui.requestRender();
1635
- return { success: true };
1657
+ return this.themeController.setThemeInstance(themeOrName);
1636
1658
  }
1637
- const result = setTheme(themeOrName, true);
1659
+ const result = this.themeController.setThemeName(themeOrName);
1638
1660
  if (result.success) {
1639
1661
  if (this.settingsManager.getTheme() !== themeOrName) {
1640
1662
  this.settingsManager.setTheme(themeOrName);
1641
1663
  }
1642
- this.ui.requestRender();
1643
1664
  }
1644
1665
  return result;
1645
1666
  },
@@ -1749,7 +1770,7 @@ export class InteractiveMode {
1749
1770
  }, () => {
1750
1771
  this.hideExtensionEditor();
1751
1772
  resolve(undefined);
1752
- });
1773
+ }, undefined, this.settingsManager.getExternalEditorCommand());
1753
1774
  this.editorContainer.clear();
1754
1775
  this.editorContainer.addChild(this.extensionEditor);
1755
1776
  this.ui.setFocus(this.extensionEditor);
@@ -2224,18 +2245,11 @@ export class InteractiveMode {
2224
2245
  this.defaultEditor.onEscape = this.retryEscapeHandler;
2225
2246
  this.retryEscapeHandler = undefined;
2226
2247
  }
2227
- if (this.retryCountdown) {
2228
- this.retryCountdown.dispose();
2229
- this.retryCountdown = undefined;
2230
- }
2231
- if (this.retryLoader) {
2232
- this.retryLoader.stop();
2233
- this.retryLoader = undefined;
2234
- }
2235
- this.stopWorkingLoader();
2236
2248
  if (this.workingVisible) {
2237
- this.loadingAnimation = this.createWorkingLoader();
2238
- this.statusContainer.addChild(this.loadingAnimation);
2249
+ this.showStatusIndicator(new WorkingStatusIndicator(this.ui, this.workingMessage ?? this.defaultWorkingMessage, this.workingIndicatorOptions));
2250
+ }
2251
+ else {
2252
+ this.clearStatusIndicator();
2239
2253
  }
2240
2254
  this.ui.requestRender();
2241
2255
  break;
@@ -2243,6 +2257,12 @@ export class InteractiveMode {
2243
2257
  this.updatePendingMessagesDisplay();
2244
2258
  this.ui.requestRender();
2245
2259
  break;
2260
+ case "entry_appended":
2261
+ if (event.entry.type === "custom") {
2262
+ this.addCustomEntryToChat(event.entry);
2263
+ this.ui.requestRender();
2264
+ }
2265
+ break;
2246
2266
  case "session_info_changed":
2247
2267
  this.updateTerminalTitle();
2248
2268
  this.footer.invalidate();
@@ -2263,7 +2283,7 @@ export class InteractiveMode {
2263
2283
  this.ui.requestRender();
2264
2284
  }
2265
2285
  else if (event.message.role === "assistant") {
2266
- this.streamingComponent = new AssistantMessageComponent(undefined, this.hideThinkingBlock, this.getMarkdownThemeWithSettings(), this.hiddenThinkingLabel);
2286
+ this.streamingComponent = new AssistantMessageComponent(undefined, this.hideThinkingBlock, this.getMarkdownThemeWithSettings(), this.hiddenThinkingLabel, this.outputPad);
2267
2287
  this.streamingMessage = event.message;
2268
2288
  this.chatContainer.addChild(this.streamingComponent);
2269
2289
  this.streamingComponent.updateContent(this.streamingMessage);
@@ -2371,11 +2391,7 @@ export class InteractiveMode {
2371
2391
  if (this.settingsManager.getShowTerminalProgress()) {
2372
2392
  this.ui.terminal.setProgress(false);
2373
2393
  }
2374
- if (this.loadingAnimation) {
2375
- this.loadingAnimation.stop();
2376
- this.loadingAnimation = undefined;
2377
- this.statusContainer.clear();
2378
- }
2394
+ this.clearStatusIndicator("working");
2379
2395
  if (this.streamingComponent) {
2380
2396
  this.chatContainer.removeChild(this.streamingComponent);
2381
2397
  this.streamingComponent = undefined;
@@ -2394,13 +2410,7 @@ export class InteractiveMode {
2394
2410
  this.defaultEditor.onEscape = () => {
2395
2411
  this.session.abortCompaction();
2396
2412
  };
2397
- this.statusContainer.clear();
2398
- const cancelHint = `(${keyText("app.interrupt")} to cancel)`;
2399
- const label = event.reason === "manual"
2400
- ? `Compacting context... ${cancelHint}`
2401
- : `${event.reason === "overflow" ? "Context overflow detected, " : ""}Auto-compacting... ${cancelHint}`;
2402
- this.autoCompactionLoader = new Loader(this.ui, (spinner) => theme.fg("accent", spinner), (text) => theme.fg("muted", text), label);
2403
- this.statusContainer.addChild(this.autoCompactionLoader);
2413
+ this.showStatusIndicator(new CompactionStatusIndicator(this.ui, event.reason));
2404
2414
  this.ui.requestRender();
2405
2415
  break;
2406
2416
  }
@@ -2412,11 +2422,7 @@ export class InteractiveMode {
2412
2422
  this.defaultEditor.onEscape = this.autoCompactionEscapeHandler;
2413
2423
  this.autoCompactionEscapeHandler = undefined;
2414
2424
  }
2415
- if (this.autoCompactionLoader) {
2416
- this.autoCompactionLoader.stop();
2417
- this.autoCompactionLoader = undefined;
2418
- this.statusContainer.clear();
2419
- }
2425
+ this.clearStatusIndicator("compaction");
2420
2426
  if (event.aborted) {
2421
2427
  if (event.reason === "manual") {
2422
2428
  this.showError("Compaction cancelled");
@@ -2450,17 +2456,7 @@ export class InteractiveMode {
2450
2456
  this.defaultEditor.onEscape = () => {
2451
2457
  this.session.abortRetry();
2452
2458
  };
2453
- // Show retry indicator
2454
- this.statusContainer.clear();
2455
- this.retryCountdown?.dispose();
2456
- const retryMessage = (seconds) => `Retrying (${event.attempt}/${event.maxAttempts}) in ${seconds}s... (${keyText("app.interrupt")} to cancel)`;
2457
- this.retryLoader = new Loader(this.ui, (spinner) => theme.fg("warning", spinner), (text) => theme.fg("muted", text), retryMessage(Math.ceil(event.delayMs / 1000)));
2458
- this.retryCountdown = new CountdownTimer(event.delayMs, this.ui, (seconds) => {
2459
- this.retryLoader?.setMessage(retryMessage(seconds));
2460
- }, () => {
2461
- this.retryCountdown = undefined;
2462
- });
2463
- this.statusContainer.addChild(this.retryLoader);
2459
+ this.showStatusIndicator(new RetryStatusIndicator(this.ui, event.attempt, event.maxAttempts, event.delayMs));
2464
2460
  this.ui.requestRender();
2465
2461
  break;
2466
2462
  }
@@ -2470,16 +2466,7 @@ export class InteractiveMode {
2470
2466
  this.defaultEditor.onEscape = this.retryEscapeHandler;
2471
2467
  this.retryEscapeHandler = undefined;
2472
2468
  }
2473
- if (this.retryCountdown) {
2474
- this.retryCountdown.dispose();
2475
- this.retryCountdown = undefined;
2476
- }
2477
- // Stop loader
2478
- if (this.retryLoader) {
2479
- this.retryLoader.stop();
2480
- this.retryLoader = undefined;
2481
- this.statusContainer.clear();
2482
- }
2469
+ this.clearStatusIndicator("retry");
2483
2470
  // Show error only on final failure (success shows normal response)
2484
2471
  if (!event.success) {
2485
2472
  this.showError(`Retry failed after ${event.attempt} attempts: ${event.finalError || "Unknown error"}`);
@@ -2521,6 +2508,25 @@ export class InteractiveMode {
2521
2508
  this.lastStatusText = text;
2522
2509
  this.ui.requestRender();
2523
2510
  }
2511
+ addCustomEntryToChat(entry) {
2512
+ const renderer = this.session.extensionRunner.getEntryRenderer(entry.customType);
2513
+ if (!renderer) {
2514
+ return;
2515
+ }
2516
+ const component = new CustomEntryComponent(entry, renderer);
2517
+ component.setExpanded(this.toolOutputExpanded);
2518
+ if (!component.hasContent()) {
2519
+ return;
2520
+ }
2521
+ if (this.streamingComponent) {
2522
+ const streamingIndex = this.chatContainer.children.indexOf(this.streamingComponent);
2523
+ if (streamingIndex >= 0) {
2524
+ this.chatContainer.children.splice(streamingIndex, 0, component);
2525
+ return;
2526
+ }
2527
+ }
2528
+ this.chatContainer.addChild(component);
2529
+ }
2524
2530
  addMessageToChat(message, options) {
2525
2531
  switch (message.role) {
2526
2532
  case "bashExecution": {
@@ -2570,12 +2576,12 @@ export class InteractiveMode {
2570
2576
  // Render user message separately if present
2571
2577
  if (skillBlock.userMessage) {
2572
2578
  this.chatContainer.addChild(new Spacer(1));
2573
- const userComponent = new UserMessageComponent(skillBlock.userMessage, this.getMarkdownThemeWithSettings());
2579
+ const userComponent = new UserMessageComponent(skillBlock.userMessage, this.getMarkdownThemeWithSettings(), this.outputPad);
2574
2580
  this.chatContainer.addChild(userComponent);
2575
2581
  }
2576
2582
  }
2577
2583
  else {
2578
- const userComponent = new UserMessageComponent(textContent, this.getMarkdownThemeWithSettings());
2584
+ const userComponent = new UserMessageComponent(textContent, this.getMarkdownThemeWithSettings(), this.outputPad);
2579
2585
  this.chatContainer.addChild(userComponent);
2580
2586
  }
2581
2587
  if (options?.populateHistory) {
@@ -2585,7 +2591,7 @@ export class InteractiveMode {
2585
2591
  break;
2586
2592
  }
2587
2593
  case "assistant": {
2588
- const assistantComponent = new AssistantMessageComponent(message, this.hideThinkingBlock, this.getMarkdownThemeWithSettings(), this.hiddenThinkingLabel);
2594
+ const assistantComponent = new AssistantMessageComponent(message, this.hideThinkingBlock, this.getMarkdownThemeWithSettings(), this.hiddenThinkingLabel, this.outputPad);
2589
2595
  this.chatContainer.addChild(assistantComponent);
2590
2596
  break;
2591
2597
  }
@@ -2598,20 +2604,19 @@ export class InteractiveMode {
2598
2604
  }
2599
2605
  }
2600
2606
  }
2601
- /**
2602
- * Render session context to chat. Used for initial load and rebuild after compaction.
2603
- * @param sessionContext Session context to render
2604
- * @param options.updateFooter Update footer state
2605
- * @param options.populateHistory Add user messages to editor history
2606
- */
2607
- renderSessionContext(sessionContext, options = {}) {
2607
+ renderSessionItems(items, options = {}) {
2608
2608
  this.pendingTools.clear();
2609
2609
  const renderedPendingTools = new Map();
2610
2610
  if (options.updateFooter) {
2611
2611
  this.footer.invalidate();
2612
2612
  this.updateEditorBorderColor();
2613
2613
  }
2614
- for (const message of sessionContext.messages) {
2614
+ for (const item of items) {
2615
+ if (isCustomSessionEntry(item)) {
2616
+ this.addCustomEntryToChat(item);
2617
+ continue;
2618
+ }
2619
+ const message = item;
2615
2620
  // Assistant messages need special handling for tool calls
2616
2621
  if (message.role === "assistant") {
2617
2622
  this.addMessageToChat(message);
@@ -2662,10 +2667,24 @@ export class InteractiveMode {
2662
2667
  }
2663
2668
  this.ui.requestRender();
2664
2669
  }
2670
+ /**
2671
+ * Render session entries to chat. Used for initial load and rebuild after compaction.
2672
+ * @param entries Compaction-aware session entries to render
2673
+ * @param options.updateFooter Update footer state
2674
+ * @param options.populateHistory Add user messages to editor history
2675
+ */
2676
+ renderSessionEntries(entries, options = {}) {
2677
+ const items = entries.flatMap((entry) => {
2678
+ if (entry.type === "custom") {
2679
+ return [entry];
2680
+ }
2681
+ return sessionEntryToContextMessages(entry);
2682
+ });
2683
+ this.renderSessionItems(items, options);
2684
+ }
2665
2685
  renderInitialMessages() {
2666
- // Get aligned messages and entries from session context
2667
- const context = this.sessionManager.buildSessionContext();
2668
- this.renderSessionContext(context, {
2686
+ const entries = this.sessionManager.buildContextEntries();
2687
+ this.renderSessionEntries(entries, {
2669
2688
  updateFooter: true,
2670
2689
  populateHistory: true,
2671
2690
  });
@@ -2679,13 +2698,13 @@ export class InteractiveMode {
2679
2698
  }
2680
2699
  }
2681
2700
  renderProjectTrustWarningIfNeeded() {
2682
- if (this.settingsManager.isProjectTrusted() || !hasProjectTrustInputs(this.sessionManager.getCwd())) {
2701
+ if (this.settingsManager.isProjectTrusted() || !hasTrustRequiringProjectResources(this.sessionManager.getCwd())) {
2683
2702
  return;
2684
2703
  }
2685
2704
  if (this.chatContainer.children.length > 0) {
2686
2705
  this.chatContainer.addChild(new Spacer(1));
2687
2706
  }
2688
- this.chatContainer.addChild(new Text(theme.fg("warning", "This project is not trusted. Project .pi resources and packages are ignored. Use /trust to save a trust decision, then restart pi."), 1, 0));
2707
+ this.chatContainer.addChild(new Text(theme.fg("warning", `This project is not trusted. Project ${CONFIG_DIR_NAME} resources and packages are ignored. Use /trust to save a trust decision, then restart pi.`), 1, 0));
2689
2708
  }
2690
2709
  async getUserInput() {
2691
2710
  const queuedInput = this.pendingUserInputs.shift();
@@ -2701,8 +2720,7 @@ export class InteractiveMode {
2701
2720
  }
2702
2721
  rebuildChatFromMessages() {
2703
2722
  this.chatContainer.clear();
2704
- const context = this.sessionManager.buildSessionContext();
2705
- this.renderSessionContext(context);
2723
+ this.renderSessionEntries(this.sessionManager.buildContextEntries());
2706
2724
  }
2707
2725
  // =========================================================================
2708
2726
  // Key handlers
@@ -2731,7 +2749,9 @@ export class InteractiveMode {
2731
2749
  if (this.isShuttingDown)
2732
2750
  return;
2733
2751
  this.isShuttingDown = true;
2734
- this.unregisterSignalHandlers();
2752
+ // Keep signal handlers registered until terminal cleanup has completed.
2753
+ // `signal-exit` checks the listener list during the same SIGTERM/SIGHUP
2754
+ // dispatch and re-sends the signal if only its own listeners remain.
2735
2755
  if (options?.fromSignal) {
2736
2756
  // Signal-triggered shutdown (SIGTERM/SIGHUP). Emit extension cleanup
2737
2757
  // (session_shutdown) BEFORE touching the terminal. Extension teardown
@@ -2741,6 +2761,7 @@ export class InteractiveMode {
2741
2761
  // which the stdout/stderr error handler turns into emergencyTerminalExit;
2742
2762
  // the render loop is already idle, so this cannot hot-spin (see #4144).
2743
2763
  await this.runtimeHost.dispose();
2764
+ this.themeController.disableAutoSync();
2744
2765
  await this.ui.terminal.drainInput(1000);
2745
2766
  this.stop();
2746
2767
  process.exit(0);
@@ -2750,6 +2771,7 @@ export class InteractiveMode {
2750
2771
  // the final frame while the process is exiting.
2751
2772
  // Drain any in-flight Kitty key release events before stopping.
2752
2773
  // This prevents escape sequences from leaking to the parent shell over slow SSH.
2774
+ this.themeController.disableAutoSync();
2753
2775
  await this.ui.terminal.drainInput(1000);
2754
2776
  this.stop();
2755
2777
  await this.runtimeHost.dispose();
@@ -2969,9 +2991,11 @@ export class InteractiveMode {
2969
2991
  if (isExpandable(activeHeader)) {
2970
2992
  activeHeader.setExpanded(expanded);
2971
2993
  }
2972
- for (const child of this.chatContainer.children) {
2973
- if (isExpandable(child)) {
2974
- child.setExpanded(expanded);
2994
+ for (const container of [this.loadedResourcesContainer, this.chatContainer]) {
2995
+ for (const child of container.children) {
2996
+ if (isExpandable(child)) {
2997
+ child.setExpanded(expanded);
2998
+ }
2975
2999
  }
2976
3000
  }
2977
3001
  this.ui.requestRender();
@@ -2991,10 +3015,9 @@ export class InteractiveMode {
2991
3015
  this.showStatus(`Thinking blocks: ${this.hideThinkingBlock ? "hidden" : "visible"}`);
2992
3016
  }
2993
3017
  async openExternalEditor() {
2994
- // Determine editor (respect $VISUAL, then $EDITOR)
2995
- const editorCmd = process.env.VISUAL || process.env.EDITOR;
3018
+ const editorCmd = this.settingsManager.getExternalEditorCommand();
2996
3019
  if (!editorCmd) {
2997
- this.showWarning("No editor configured. Set $VISUAL or $EDITOR environment variable.");
3020
+ this.showWarning("No editor configured. Set externalEditor in settings.json or $VISUAL/$EDITOR.");
2998
3021
  return;
2999
3022
  }
3000
3023
  const currentText = this.editor.getExpandedText?.() ?? this.editor.getText();
@@ -3049,7 +3072,6 @@ export class InteractiveMode {
3049
3072
  showError(errorMessage) {
3050
3073
  this.chatContainer.addChild(new Spacer(1));
3051
3074
  this.chatContainer.addChild(new Text(theme.fg("error", `Error: ${errorMessage}`), 1, 0));
3052
- this.chatContainer.addChild(new Spacer(1));
3053
3075
  this.ui.requestRender();
3054
3076
  }
3055
3077
  showWarning(warningMessage) {
@@ -3062,7 +3084,7 @@ export class InteractiveMode {
3062
3084
  const updateInstruction = theme.fg("muted", `New version ${release.version} is available. Run `) + action;
3063
3085
  const changelogUrl = "https://pi.dev/changelog";
3064
3086
  const changelogLink = getCapabilities().hyperlinks
3065
- ? hyperlink(theme.fg("accent", "open changelog"), changelogUrl)
3087
+ ? hyperlink(theme.fg("accent", changelogUrl), changelogUrl)
3066
3088
  : theme.fg("accent", changelogUrl);
3067
3089
  const changelogLine = theme.fg("muted", "Changelog: ") + changelogLink;
3068
3090
  const note = release.note?.trim();
@@ -3081,7 +3103,7 @@ export class InteractiveMode {
3081
3103
  this.ui.requestRender();
3082
3104
  }
3083
3105
  showPackageUpdateNotification(packages) {
3084
- const action = theme.fg("accent", `${APP_NAME} update`);
3106
+ const action = theme.fg("accent", `${APP_NAME} update --extensions`);
3085
3107
  const updateInstruction = theme.fg("muted", "Package updates are available. Run ") + action;
3086
3108
  const packageLines = packages.map((pkg) => `- ${pkg}`).join("\n");
3087
3109
  this.chatContainer.addChild(new Spacer(1));
@@ -3288,7 +3310,8 @@ export class InteractiveMode {
3288
3310
  httpIdleTimeoutMs: this.settingsManager.getHttpIdleTimeoutMs(),
3289
3311
  thinkingLevel: this.session.thinkingLevel,
3290
3312
  availableThinkingLevels: this.session.getAvailableThinkingLevels(),
3291
- currentTheme: this.settingsManager.getTheme() || "dark",
3313
+ currentTheme: this.settingsManager.getThemeSetting() || "dark",
3314
+ terminalTheme: this.themeController.getTerminalTheme(),
3292
3315
  availableThemes: getAvailableThemes(),
3293
3316
  hideThinkingBlock: this.hideThinkingBlock,
3294
3317
  collapseChangelog: this.settingsManager.getCollapseChangelog(),
@@ -3298,6 +3321,7 @@ export class InteractiveMode {
3298
3321
  showHardwareCursor: this.settingsManager.getShowHardwareCursor(),
3299
3322
  defaultProjectTrust: this.settingsManager.getDefaultProjectTrust(),
3300
3323
  editorPaddingX: this.settingsManager.getEditorPaddingX(),
3324
+ outputPad: this.settingsManager.getOutputPad(),
3301
3325
  autocompleteMaxVisible: this.settingsManager.getAutocompleteMaxVisible(),
3302
3326
  quietStartup: this.settingsManager.getQuietStartup(),
3303
3327
  clearOnShrink: this.settingsManager.getClearOnShrink(),
@@ -3354,21 +3378,11 @@ export class InteractiveMode {
3354
3378
  this.footer.invalidate();
3355
3379
  this.updateEditorBorderColor();
3356
3380
  },
3357
- onThemeChange: (themeName) => {
3358
- const result = setTheme(themeName, true);
3359
- this.settingsManager.setTheme(themeName);
3360
- this.ui.invalidate();
3361
- if (!result.success) {
3362
- this.showError(`Failed to load theme "${themeName}": ${result.error}\nFell back to dark theme.`);
3363
- }
3364
- },
3365
- onThemePreview: (themeName) => {
3366
- const result = setTheme(themeName, true);
3367
- if (result.success) {
3368
- this.ui.invalidate();
3369
- this.ui.requestRender();
3370
- }
3381
+ onThemeChange: (themeSetting) => {
3382
+ this.settingsManager.setTheme(themeSetting);
3383
+ void this.themeController.applyFromSettings();
3371
3384
  },
3385
+ onThemePreview: (themeName) => this.themeController.preview(themeName),
3372
3386
  onHideThinkingBlockChange: (hidden) => {
3373
3387
  this.hideThinkingBlock = hidden;
3374
3388
  this.settingsManager.setHideThinkingBlock(hidden);
@@ -3409,6 +3423,23 @@ export class InteractiveMode {
3409
3423
  this.editor.setPaddingX(padding);
3410
3424
  }
3411
3425
  },
3426
+ onOutputPadChange: (padding) => {
3427
+ this.settingsManager.setOutputPad(padding);
3428
+ this.outputPad = padding;
3429
+ if (this.streamingComponent || this.session.isStreaming) {
3430
+ for (const child of this.chatContainer.children) {
3431
+ if (child instanceof AssistantMessageComponent || child instanceof UserMessageComponent) {
3432
+ child.setOutputPad(padding);
3433
+ }
3434
+ }
3435
+ if (this.streamingComponent) {
3436
+ this.streamingComponent.setOutputPad(padding);
3437
+ }
3438
+ this.ui.requestRender();
3439
+ return;
3440
+ }
3441
+ this.rebuildChatFromMessages();
3442
+ },
3412
3443
  onAutocompleteMaxVisibleChange: (maxVisible) => {
3413
3444
  this.settingsManager.setAutocompleteMaxVisible(maxVisible);
3414
3445
  this.defaultEditor.setAutocompleteMaxVisible(maxVisible);
@@ -3419,6 +3450,9 @@ export class InteractiveMode {
3419
3450
  onClearOnShrinkChange: (enabled) => {
3420
3451
  this.settingsManager.setClearOnShrink(enabled);
3421
3452
  this.ui.setClearOnShrink(enabled);
3453
+ if (!enabled && !this.activeStatusIndicator) {
3454
+ this.statusContainer.clear();
3455
+ }
3422
3456
  },
3423
3457
  onShowTerminalProgressChange: (enabled) => {
3424
3458
  this.settingsManager.setShowTerminalProgress(enabled);
@@ -3511,7 +3545,7 @@ export class InteractiveMode {
3511
3545
  if (this.autoTrustOnReloadCwd !== cwd) {
3512
3546
  return false;
3513
3547
  }
3514
- if (!this.settingsManager.isProjectTrusted() || !hasProjectConfigDir(cwd)) {
3548
+ if (!this.settingsManager.isProjectTrusted() || !hasTrustRequiringProjectResources(cwd)) {
3515
3549
  return false;
3516
3550
  }
3517
3551
  const trustStore = new ProjectTrustStore(this.runtimeHost.services.agentDir);
@@ -3656,7 +3690,6 @@ export class InteractiveMode {
3656
3690
  this.ui.requestRender();
3657
3691
  return;
3658
3692
  }
3659
- this.renderCurrentSessionState();
3660
3693
  this.editor.setText(result.selectedText ?? "");
3661
3694
  done();
3662
3695
  this.showStatus("Forked to new session");
@@ -3684,7 +3717,6 @@ export class InteractiveMode {
3684
3717
  this.ui.requestRender();
3685
3718
  return;
3686
3719
  }
3687
- this.renderCurrentSessionState();
3688
3720
  this.editor.setText("");
3689
3721
  this.showStatus("Cloned to new session");
3690
3722
  }
@@ -3738,16 +3770,16 @@ export class InteractiveMode {
3738
3770
  break;
3739
3771
  }
3740
3772
  }
3741
- // Set up escape handler and loader if summarizing
3742
- let summaryLoader;
3773
+ // Set up escape handler and status indicator if summarizing
3774
+ let showingSummaryIndicator = false;
3743
3775
  const originalOnEscape = this.defaultEditor.onEscape;
3744
3776
  if (wantsSummary) {
3745
3777
  this.defaultEditor.onEscape = () => {
3746
3778
  this.session.abortBranchSummary();
3747
3779
  };
3748
3780
  this.chatContainer.addChild(new Spacer(1));
3749
- summaryLoader = new Loader(this.ui, (spinner) => theme.fg("accent", spinner), (text) => theme.fg("muted", text), `Summarizing branch... (${keyText("app.interrupt")} to cancel)`);
3750
- this.statusContainer.addChild(summaryLoader);
3781
+ this.showStatusIndicator(new BranchSummaryStatusIndicator(this.ui));
3782
+ showingSummaryIndicator = true;
3751
3783
  this.ui.requestRender();
3752
3784
  }
3753
3785
  try {
@@ -3778,9 +3810,8 @@ export class InteractiveMode {
3778
3810
  this.showError(error instanceof Error ? error.message : String(error));
3779
3811
  }
3780
3812
  finally {
3781
- if (summaryLoader) {
3782
- summaryLoader.stop();
3783
- this.statusContainer.clear();
3813
+ if (showingSummaryIndicator) {
3814
+ this.clearStatusIndicator("branchSummary");
3784
3815
  }
3785
3816
  this.defaultEditor.onEscape = originalOnEscape;
3786
3817
  }
@@ -3821,11 +3852,7 @@ export class InteractiveMode {
3821
3852
  });
3822
3853
  }
3823
3854
  async handleResumeSession(sessionPath, options) {
3824
- if (this.loadingAnimation) {
3825
- this.loadingAnimation.stop();
3826
- this.loadingAnimation = undefined;
3827
- }
3828
- this.statusContainer.clear();
3855
+ this.clearStatusIndicator();
3829
3856
  try {
3830
3857
  const result = await this.runtimeHost.switchSession(sessionPath, {
3831
3858
  withSession: options?.withSession,
@@ -3834,7 +3861,6 @@ export class InteractiveMode {
3834
3861
  if (result.cancelled) {
3835
3862
  return result;
3836
3863
  }
3837
- this.renderCurrentSessionState();
3838
3864
  this.showStatus("Resumed session");
3839
3865
  return result;
3840
3866
  }
@@ -3853,7 +3879,6 @@ export class InteractiveMode {
3853
3879
  if (result.cancelled) {
3854
3880
  return result;
3855
3881
  }
3856
- this.renderCurrentSessionState();
3857
3882
  this.showStatus("Resumed session in current cwd");
3858
3883
  return result;
3859
3884
  }
@@ -4213,8 +4238,20 @@ export class InteractiveMode {
4213
4238
  this.ui.setFocus(editor);
4214
4239
  this.ui.requestRender();
4215
4240
  };
4241
+ let chatRestoredBeforeSessionStart = false;
4242
+ let reloadBoxDismissed = false;
4243
+ const restoreChatBeforeSessionStart = () => {
4244
+ if (chatRestoredBeforeSessionStart) {
4245
+ return;
4246
+ }
4247
+ this.hideThinkingBlock = this.settingsManager.getHideThinkingBlock();
4248
+ this.outputPad = this.settingsManager.getOutputPad();
4249
+ this.rebuildChatFromMessages();
4250
+ chatRestoredBeforeSessionStart = true;
4251
+ };
4216
4252
  try {
4217
- await this.session.reload();
4253
+ await this.session.reload({ beforeSessionStart: restoreChatBeforeSessionStart });
4254
+ restoreChatBeforeSessionStart();
4218
4255
  configureHttpDispatcher(this.settingsManager.getHttpIdleTimeoutMs());
4219
4256
  this.keybindings.reload();
4220
4257
  const activeHeader = this.customHeader ?? this.builtInHeader;
@@ -4222,12 +4259,7 @@ export class InteractiveMode {
4222
4259
  activeHeader.setExpanded(this.toolOutputExpanded);
4223
4260
  }
4224
4261
  setRegisteredThemes(this.session.resourceLoader.getThemes().themes);
4225
- this.hideThinkingBlock = this.settingsManager.getHideThinkingBlock();
4226
- const themeName = this.settingsManager.getTheme();
4227
- const themeResult = themeName ? setTheme(themeName, true) : { success: true };
4228
- if (!themeResult.success) {
4229
- this.showError(`Failed to load theme "${themeName}": ${themeResult.error}\nFell back to dark theme.`);
4230
- }
4262
+ await this.themeController.applyFromSettings();
4231
4263
  const editorPaddingX = this.settingsManager.getEditorPaddingX();
4232
4264
  const autocompleteMaxVisible = this.settingsManager.getAutocompleteMaxVisible();
4233
4265
  this.defaultEditor.setPaddingX(editorPaddingX);
@@ -4237,12 +4269,14 @@ export class InteractiveMode {
4237
4269
  this.editor.setAutocompleteMaxVisible?.(autocompleteMaxVisible);
4238
4270
  }
4239
4271
  this.ui.setShowHardwareCursor(this.settingsManager.getShowHardwareCursor());
4240
- this.ui.setClearOnShrink(this.settingsManager.getClearOnShrink());
4272
+ const clearOnShrink = this.settingsManager.getClearOnShrink();
4273
+ this.ui.setClearOnShrink(clearOnShrink);
4274
+ if (!clearOnShrink && !this.activeStatusIndicator) {
4275
+ this.statusContainer.clear();
4276
+ }
4241
4277
  this.setupAutocompleteProvider();
4242
4278
  const runner = this.session.extensionRunner;
4243
4279
  this.setupExtensionShortcuts(runner);
4244
- this.rebuildChatFromMessages();
4245
- dismissReloadBox(this.editor);
4246
4280
  this.showLoadedResources({
4247
4281
  force: false,
4248
4282
  showDiagnosticsWhenQuiet: true,
@@ -4255,9 +4289,13 @@ export class InteractiveMode {
4255
4289
  this.showStatus(savedImplicitProjectTrust
4256
4290
  ? "Reloaded keybindings, extensions, skills, prompts, themes; saved project trust"
4257
4291
  : "Reloaded keybindings, extensions, skills, prompts, themes");
4292
+ dismissReloadBox(this.editor);
4293
+ reloadBoxDismissed = true;
4258
4294
  }
4259
4295
  catch (error) {
4260
- dismissReloadBox(previousEditor);
4296
+ if (!reloadBoxDismissed) {
4297
+ dismissReloadBox(previousEditor);
4298
+ }
4261
4299
  this.showError(`Reload failed: ${error instanceof Error ? error.message : String(error)}`);
4262
4300
  }
4263
4301
  }
@@ -4314,17 +4352,12 @@ export class InteractiveMode {
4314
4352
  return;
4315
4353
  }
4316
4354
  try {
4317
- if (this.loadingAnimation) {
4318
- this.loadingAnimation.stop();
4319
- this.loadingAnimation = undefined;
4320
- }
4321
- this.statusContainer.clear();
4355
+ this.clearStatusIndicator();
4322
4356
  const result = await this.runtimeHost.importFromJsonl(inputPath);
4323
4357
  if (result.cancelled) {
4324
4358
  this.showStatus("Import cancelled");
4325
4359
  return;
4326
4360
  }
4327
- this.renderCurrentSessionState();
4328
4361
  this.showStatus(`Session imported from: ${inputPath}`);
4329
4362
  }
4330
4363
  catch (error) {
@@ -4339,7 +4372,6 @@ export class InteractiveMode {
4339
4372
  this.showStatus("Import cancelled");
4340
4373
  return;
4341
4374
  }
4342
- this.renderCurrentSessionState();
4343
4375
  this.showStatus(`Session imported from: ${inputPath}`);
4344
4376
  return;
4345
4377
  }
@@ -4466,8 +4498,12 @@ export class InteractiveMode {
4466
4498
  return;
4467
4499
  }
4468
4500
  this.session.setSessionName(name);
4501
+ const sessionName = this.sessionManager.getSessionName();
4502
+ if (sessionName !== name) {
4503
+ this.showWarning(`Session name was normalized from ${JSON.stringify(name)} to ${JSON.stringify(sessionName)}`);
4504
+ }
4469
4505
  this.chatContainer.addChild(new Spacer(1));
4470
- this.chatContainer.addChild(new Text(theme.fg("dim", `Session name set: ${name}`), 1, 0));
4506
+ this.chatContainer.addChild(new Text(theme.fg("dim", `Session name set: ${sessionName ?? name}`), 1, 0));
4471
4507
  this.ui.requestRender();
4472
4508
  }
4473
4509
  handleSessionCommand() {
@@ -4642,17 +4678,12 @@ export class InteractiveMode {
4642
4678
  this.ui.requestRender();
4643
4679
  }
4644
4680
  async handleClearCommand() {
4645
- if (this.loadingAnimation) {
4646
- this.loadingAnimation.stop();
4647
- this.loadingAnimation = undefined;
4648
- }
4649
- this.statusContainer.clear();
4681
+ this.clearStatusIndicator();
4650
4682
  try {
4651
4683
  const result = await this.runtimeHost.newSession();
4652
4684
  if (result.cancelled) {
4653
4685
  return;
4654
4686
  }
4655
- this.renderCurrentSessionState();
4656
4687
  this.chatContainer.addChild(new Spacer(1));
4657
4688
  this.chatContainer.addChild(new Text(`${theme.fg("accent", "✓ New session started")}`, 1, 1));
4658
4689
  this.ui.requestRender();
@@ -4774,17 +4805,7 @@ export class InteractiveMode {
4774
4805
  this.ui.requestRender();
4775
4806
  }
4776
4807
  async handleCompactCommand(customInstructions) {
4777
- const entries = this.sessionManager.getEntries();
4778
- const messageCount = entries.filter((e) => e.type === "message").length;
4779
- if (messageCount < 2) {
4780
- this.showWarning("Nothing to compact (no messages yet)");
4781
- return;
4782
- }
4783
- if (this.loadingAnimation) {
4784
- this.loadingAnimation.stop();
4785
- this.loadingAnimation = undefined;
4786
- }
4787
- this.statusContainer.clear();
4808
+ this.clearStatusIndicator();
4788
4809
  try {
4789
4810
  await this.session.compact(customInstructions);
4790
4811
  }
@@ -4793,14 +4814,11 @@ export class InteractiveMode {
4793
4814
  }
4794
4815
  }
4795
4816
  stop() {
4796
- this.unregisterSignalHandlers();
4797
4817
  if (this.settingsManager.getShowTerminalProgress()) {
4798
4818
  this.ui.terminal.setProgress(false);
4799
4819
  }
4800
- if (this.loadingAnimation) {
4801
- this.loadingAnimation.stop();
4802
- this.loadingAnimation = undefined;
4803
- }
4820
+ this.clearStatusIndicator();
4821
+ this.themeController.disableAutoSync();
4804
4822
  this.clearExtensionTerminalInputListeners();
4805
4823
  this.footer.dispose();
4806
4824
  this.footerDataProvider.dispose();
@@ -4811,6 +4829,7 @@ export class InteractiveMode {
4811
4829
  this.ui.stop();
4812
4830
  this.isInitialized = false;
4813
4831
  }
4832
+ this.unregisterSignalHandlers();
4814
4833
  }
4815
4834
  }
4816
4835
  //# sourceMappingURL=interactive-mode.js.map