@draht/coding-agent 2026.3.25 → 2026.4.23

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 (265) hide show
  1. package/CHANGELOG.md +896 -624
  2. package/README.md +110 -97
  3. package/dist/cli/args.d.ts +7 -10
  4. package/dist/cli/args.d.ts.map +1 -1
  5. package/dist/cli/args.js +42 -44
  6. package/dist/cli/args.js.map +1 -1
  7. package/dist/cli.d.ts.map +1 -1
  8. package/dist/cli.js +1 -0
  9. package/dist/cli.js.map +1 -1
  10. package/dist/config.d.ts +9 -0
  11. package/dist/config.d.ts.map +1 -1
  12. package/dist/config.js +18 -0
  13. package/dist/config.js.map +1 -1
  14. package/dist/core/agent-session-runtime.d.ts +83 -0
  15. package/dist/core/agent-session-runtime.d.ts.map +1 -0
  16. package/dist/core/agent-session-runtime.js +236 -0
  17. package/dist/core/agent-session-runtime.js.map +1 -0
  18. package/dist/core/agent-session-services.d.ts +86 -0
  19. package/dist/core/agent-session-services.d.ts.map +1 -0
  20. package/dist/core/agent-session-services.js +116 -0
  21. package/dist/core/agent-session-services.js.map +1 -0
  22. package/dist/core/agent-session.d.ts +17 -47
  23. package/dist/core/agent-session.d.ts.map +1 -1
  24. package/dist/core/agent-session.js +166 -291
  25. package/dist/core/agent-session.js.map +1 -1
  26. package/dist/core/auth-storage.d.ts +3 -1
  27. package/dist/core/auth-storage.d.ts.map +1 -1
  28. package/dist/core/auth-storage.js +5 -2
  29. package/dist/core/auth-storage.js.map +1 -1
  30. package/dist/core/bash-executor.d.ts.map +1 -1
  31. package/dist/core/bash-executor.js +19 -7
  32. package/dist/core/bash-executor.js.map +1 -1
  33. package/dist/core/compaction/branch-summarization.d.ts +2 -0
  34. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  35. package/dist/core/compaction/branch-summarization.js +2 -2
  36. package/dist/core/compaction/branch-summarization.js.map +1 -1
  37. package/dist/core/compaction/compaction.d.ts +3 -3
  38. package/dist/core/compaction/compaction.d.ts.map +1 -1
  39. package/dist/core/compaction/compaction.js +27 -26
  40. package/dist/core/compaction/compaction.js.map +1 -1
  41. package/dist/core/export-html/tool-renderer.d.ts +2 -0
  42. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  43. package/dist/core/export-html/tool-renderer.js +2 -2
  44. package/dist/core/export-html/tool-renderer.js.map +1 -1
  45. package/dist/core/extensions/index.d.ts +2 -2
  46. package/dist/core/extensions/index.d.ts.map +1 -1
  47. package/dist/core/extensions/index.js +1 -1
  48. package/dist/core/extensions/index.js.map +1 -1
  49. package/dist/core/extensions/loader.d.ts.map +1 -1
  50. package/dist/core/extensions/loader.js +7 -7
  51. package/dist/core/extensions/loader.js.map +1 -1
  52. package/dist/core/extensions/runner.d.ts +1 -0
  53. package/dist/core/extensions/runner.d.ts.map +1 -1
  54. package/dist/core/extensions/runner.js +4 -0
  55. package/dist/core/extensions/runner.js.map +1 -1
  56. package/dist/core/extensions/types.d.ts +30 -29
  57. package/dist/core/extensions/types.d.ts.map +1 -1
  58. package/dist/core/extensions/types.js +10 -0
  59. package/dist/core/extensions/types.js.map +1 -1
  60. package/dist/core/footer-data-provider.d.ts +5 -1
  61. package/dist/core/footer-data-provider.d.ts.map +1 -1
  62. package/dist/core/footer-data-provider.js +70 -8
  63. package/dist/core/footer-data-provider.js.map +1 -1
  64. package/dist/core/index.d.ts +3 -1
  65. package/dist/core/index.d.ts.map +1 -1
  66. package/dist/core/index.js +3 -1
  67. package/dist/core/index.js.map +1 -1
  68. package/dist/core/keybindings.d.ts +14 -1
  69. package/dist/core/keybindings.d.ts.map +1 -1
  70. package/dist/core/keybindings.js +13 -14
  71. package/dist/core/keybindings.js.map +1 -1
  72. package/dist/core/model-registry.d.ts +21 -3
  73. package/dist/core/model-registry.d.ts.map +1 -1
  74. package/dist/core/model-registry.js +120 -71
  75. package/dist/core/model-registry.js.map +1 -1
  76. package/dist/core/model-resolver.d.ts.map +1 -1
  77. package/dist/core/model-resolver.js +4 -4
  78. package/dist/core/model-resolver.js.map +1 -1
  79. package/dist/core/package-manager.d.ts +21 -1
  80. package/dist/core/package-manager.d.ts.map +1 -1
  81. package/dist/core/package-manager.js +108 -43
  82. package/dist/core/package-manager.js.map +1 -1
  83. package/dist/core/prompt-templates.d.ts.map +1 -1
  84. package/dist/core/prompt-templates.js +1 -22
  85. package/dist/core/prompt-templates.js.map +1 -1
  86. package/dist/core/resolve-config-value.d.ts +6 -0
  87. package/dist/core/resolve-config-value.d.ts.map +1 -1
  88. package/dist/core/resolve-config-value.js +37 -5
  89. package/dist/core/resolve-config-value.js.map +1 -1
  90. package/dist/core/resource-loader.d.ts.map +1 -1
  91. package/dist/core/resource-loader.js +25 -3
  92. package/dist/core/resource-loader.js.map +1 -1
  93. package/dist/core/sdk.d.ts +7 -4
  94. package/dist/core/sdk.d.ts.map +1 -1
  95. package/dist/core/sdk.js +18 -24
  96. package/dist/core/sdk.js.map +1 -1
  97. package/dist/core/session-cwd.d.ts +19 -0
  98. package/dist/core/session-cwd.d.ts.map +1 -0
  99. package/dist/core/session-cwd.js +38 -0
  100. package/dist/core/session-cwd.js.map +1 -0
  101. package/dist/core/session-manager.d.ts +5 -1
  102. package/dist/core/session-manager.d.ts.map +1 -1
  103. package/dist/core/session-manager.js +16 -8
  104. package/dist/core/session-manager.js.map +1 -1
  105. package/dist/core/settings-manager.d.ts +3 -1
  106. package/dist/core/settings-manager.d.ts.map +1 -1
  107. package/dist/core/settings-manager.js +5 -1
  108. package/dist/core/settings-manager.js.map +1 -1
  109. package/dist/core/skills.d.ts +1 -1
  110. package/dist/core/skills.d.ts.map +1 -1
  111. package/dist/core/skills.js +3 -3
  112. package/dist/core/skills.js.map +1 -1
  113. package/dist/core/system-prompt.d.ts.map +1 -1
  114. package/dist/core/system-prompt.js +6 -6
  115. package/dist/core/system-prompt.js.map +1 -1
  116. package/dist/core/timings.d.ts +1 -0
  117. package/dist/core/timings.d.ts.map +1 -1
  118. package/dist/core/timings.js +6 -0
  119. package/dist/core/timings.js.map +1 -1
  120. package/dist/core/tools/bash.d.ts.map +1 -1
  121. package/dist/core/tools/bash.js +19 -9
  122. package/dist/core/tools/bash.js.map +1 -1
  123. package/dist/core/tools/edit-diff.d.ts +23 -1
  124. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  125. package/dist/core/tools/edit-diff.js +150 -57
  126. package/dist/core/tools/edit-diff.js.map +1 -1
  127. package/dist/core/tools/edit.d.ts +13 -11
  128. package/dist/core/tools/edit.d.ts.map +1 -1
  129. package/dist/core/tools/edit.js +55 -77
  130. package/dist/core/tools/edit.js.map +1 -1
  131. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
  132. package/dist/core/tools/file-mutation-queue.js +4 -4
  133. package/dist/core/tools/file-mutation-queue.js.map +1 -1
  134. package/dist/core/tools/index.d.ts +9 -6
  135. package/dist/core/tools/index.d.ts.map +1 -1
  136. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  137. package/dist/core/tools/tool-definition-wrapper.js +2 -0
  138. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  139. package/dist/index.d.ts +4 -6
  140. package/dist/index.d.ts.map +1 -1
  141. package/dist/index.js +4 -6
  142. package/dist/index.js.map +1 -1
  143. package/dist/main.d.ts.map +1 -1
  144. package/dist/main.js +259 -422
  145. package/dist/main.js.map +1 -1
  146. package/dist/migrations.d.ts +3 -3
  147. package/dist/migrations.d.ts.map +1 -1
  148. package/dist/migrations.js +25 -5
  149. package/dist/migrations.js.map +1 -1
  150. package/dist/modes/interactive/components/assistant-message.d.ts +3 -1
  151. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  152. package/dist/modes/interactive/components/assistant-message.js +14 -3
  153. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  154. package/dist/modes/interactive/components/earendil-announcement.d.ts +5 -0
  155. package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -0
  156. package/dist/modes/interactive/components/earendil-announcement.js +40 -0
  157. package/dist/modes/interactive/components/earendil-announcement.js.map +1 -0
  158. package/dist/modes/interactive/components/footer.d.ts +1 -0
  159. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  160. package/dist/modes/interactive/components/footer.js +4 -1
  161. package/dist/modes/interactive/components/footer.js.map +1 -1
  162. package/dist/modes/interactive/components/tool-execution.d.ts +0 -1
  163. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  164. package/dist/modes/interactive/components/tool-execution.js +2 -7
  165. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  166. package/dist/modes/interactive/components/tree-selector.d.ts +4 -2
  167. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  168. package/dist/modes/interactive/components/tree-selector.js +48 -15
  169. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  170. package/dist/modes/interactive/interactive-mode.d.ts +18 -5
  171. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  172. package/dist/modes/interactive/interactive-mode.js +287 -188
  173. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  174. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  175. package/dist/modes/interactive/theme/theme.js +15 -11
  176. package/dist/modes/interactive/theme/theme.js.map +1 -1
  177. package/dist/modes/print-mode.d.ts +2 -2
  178. package/dist/modes/print-mode.d.ts.map +1 -1
  179. package/dist/modes/print-mode.js +89 -72
  180. package/dist/modes/print-mode.js.map +1 -1
  181. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  182. package/dist/modes/rpc/rpc-client.js +1 -0
  183. package/dist/modes/rpc/rpc-client.js.map +1 -1
  184. package/dist/modes/rpc/rpc-mode.d.ts +2 -2
  185. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  186. package/dist/modes/rpc/rpc-mode.js +95 -64
  187. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  188. package/dist/package-manager-cli.d.ts +4 -0
  189. package/dist/package-manager-cli.d.ts.map +1 -0
  190. package/dist/package-manager-cli.js +234 -0
  191. package/dist/package-manager-cli.js.map +1 -0
  192. package/dist/prompts/commands/atomic-commit.md +17 -0
  193. package/dist/prompts/commands/discuss-phase.md +15 -0
  194. package/dist/prompts/commands/execute-phase.md +14 -0
  195. package/dist/prompts/commands/fix.md +14 -0
  196. package/dist/prompts/commands/init-project.md +16 -0
  197. package/dist/prompts/commands/map-codebase.md +16 -0
  198. package/dist/prompts/commands/new-project.md +16 -0
  199. package/dist/prompts/commands/next-milestone.md +16 -0
  200. package/dist/prompts/commands/pause-work.md +13 -0
  201. package/dist/prompts/commands/plan-phase.md +15 -0
  202. package/dist/prompts/commands/progress.md +13 -0
  203. package/dist/prompts/commands/quick.md +14 -0
  204. package/dist/prompts/commands/resume-work.md +13 -0
  205. package/dist/prompts/commands/review.md +15 -0
  206. package/dist/prompts/commands/verify-work.md +15 -0
  207. package/dist/utils/paths.d.ts +7 -0
  208. package/dist/utils/paths.d.ts.map +1 -0
  209. package/dist/utils/paths.js +19 -0
  210. package/dist/utils/paths.js.map +1 -0
  211. package/docs/compaction.md +5 -3
  212. package/docs/custom-provider.md +1 -1
  213. package/docs/development.md +5 -3
  214. package/docs/extensions.md +221 -69
  215. package/docs/json.md +5 -2
  216. package/docs/keybindings.md +2 -0
  217. package/docs/models.md +60 -3
  218. package/docs/packages.md +3 -3
  219. package/docs/rpc.md +23 -9
  220. package/docs/sdk.md +240 -84
  221. package/docs/session.md +3 -3
  222. package/docs/settings.md +12 -0
  223. package/docs/skills.md +3 -2
  224. package/docs/tree.md +6 -3
  225. package/examples/README.md +1 -1
  226. package/examples/extensions/README.md +1 -0
  227. package/examples/extensions/antigravity-image-gen.ts +1 -1
  228. package/examples/extensions/custom-compaction.ts +17 -4
  229. package/examples/extensions/custom-provider-gitlab-duo/index.ts +1 -1
  230. package/examples/extensions/doom-overlay/doom/build.sh +2 -2
  231. package/examples/extensions/handoff.ts +5 -2
  232. package/examples/extensions/hello.ts +18 -17
  233. package/examples/extensions/hidden-thinking-label.ts +53 -0
  234. package/examples/extensions/overlay-qa-tests.ts +2 -2
  235. package/examples/extensions/qna.ts +5 -2
  236. package/examples/extensions/rpc-demo.ts +3 -9
  237. package/examples/extensions/sandbox/index.ts +8 -4
  238. package/examples/extensions/status-line.ts +0 -8
  239. package/examples/extensions/subagent/index.ts +6 -6
  240. package/examples/extensions/summarize.ts +15 -4
  241. package/examples/extensions/todo.ts +0 -2
  242. package/examples/extensions/tools.ts +0 -5
  243. package/examples/extensions/trigger-compact.ts +11 -1
  244. package/examples/extensions/widget-placement.ts +4 -12
  245. package/examples/sdk/02-custom-model.ts +1 -1
  246. package/examples/sdk/09-api-keys-and-oauth.ts +3 -3
  247. package/examples/sdk/12-full-control.ts +1 -1
  248. package/examples/sdk/13-session-runtime.ts +67 -0
  249. package/examples/sdk/README.md +8 -5
  250. package/package.json +7 -8
  251. package/prompts/commands/atomic-commit.md +17 -0
  252. package/prompts/commands/discuss-phase.md +15 -0
  253. package/prompts/commands/execute-phase.md +14 -0
  254. package/prompts/commands/fix.md +14 -0
  255. package/prompts/commands/init-project.md +16 -0
  256. package/prompts/commands/map-codebase.md +16 -0
  257. package/prompts/commands/new-project.md +16 -0
  258. package/prompts/commands/next-milestone.md +16 -0
  259. package/prompts/commands/pause-work.md +13 -0
  260. package/prompts/commands/plan-phase.md +15 -0
  261. package/prompts/commands/progress.md +13 -0
  262. package/prompts/commands/quick.md +14 -0
  263. package/prompts/commands/resume-work.md +13 -0
  264. package/prompts/commands/review.md +15 -0
  265. package/prompts/commands/verify-work.md +15 -0
@@ -15,6 +15,7 @@ import { KeybindingsManager } from "../../core/keybindings.js";
15
15
  import { createCompactionSummaryMessage } from "../../core/messages.js";
16
16
  import { findExactModelReferenceMatch, resolveModelScope } from "../../core/model-resolver.js";
17
17
  import { DefaultPackageManager } from "../../core/package-manager.js";
18
+ import { formatMissingSessionCwdPrompt, MissingSessionCwdError } from "../../core/session-cwd.js";
18
19
  import { SessionManager } from "../../core/session-manager.js";
19
20
  import { BUILTIN_SLASH_COMMANDS } from "../../core/slash-commands.js";
20
21
  import { getChangelogPath, getNewEntries, parseChangelog } from "../../utils/changelog.js";
@@ -32,6 +33,7 @@ import { CustomEditor } from "./components/custom-editor.js";
32
33
  import { CustomMessageComponent } from "./components/custom-message.js";
33
34
  import { DaxnutsComponent } from "./components/daxnuts.js";
34
35
  import { DynamicBorder } from "./components/dynamic-border.js";
36
+ import { EarendilAnnouncementComponent } from "./components/earendil-announcement.js";
35
37
  import { ExtensionEditorComponent } from "./components/extension-editor.js";
36
38
  import { ExtensionInputComponent } from "./components/extension-input.js";
37
39
  import { ExtensionSelectorComponent } from "./components/extension-selector.js";
@@ -48,13 +50,17 @@ import { ToolExecutionComponent } from "./components/tool-execution.js";
48
50
  import { TreeSelectorComponent } from "./components/tree-selector.js";
49
51
  import { UserMessageComponent } from "./components/user-message.js";
50
52
  import { UserMessageSelectorComponent } from "./components/user-message-selector.js";
51
- import { getAvailableThemes, getAvailableThemesWithPaths, getEditorTheme, getMarkdownTheme, getThemeByName, initTheme, onThemeChange, setRegisteredThemes, setTheme, setThemeInstance, Theme, theme, } from "./theme/theme.js";
53
+ import { getAvailableThemes, getAvailableThemesWithPaths, getEditorTheme, getMarkdownTheme, getThemeByName, initTheme, onThemeChange, setRegisteredThemes, setTheme, setThemeInstance, stopThemeWatcher, Theme, theme, } from "./theme/theme.js";
52
54
  function isExpandable(obj) {
53
55
  return typeof obj === "object" && obj !== null && "setExpanded" in obj && typeof obj.setExpanded === "function";
54
56
  }
57
+ const ANTHROPIC_SUBSCRIPTION_AUTH_WARNING = "Anthropic subscription auth is active. Third-party usage now draws from extra usage and is billed per token, not your Claude plan limits. Manage extra usage at https://claude.ai/settings/usage.";
58
+ function isAnthropicSubscriptionAuthKey(apiKey) {
59
+ return typeof apiKey === "string" && apiKey.startsWith("sk-ant-oat");
60
+ }
55
61
  export class InteractiveMode {
56
62
  options;
57
- session;
63
+ runtimeHost;
58
64
  ui;
59
65
  chatContainer;
60
66
  pendingMessagesContainer;
@@ -74,9 +80,13 @@ export class InteractiveMode {
74
80
  loadingAnimation = undefined;
75
81
  pendingWorkingMessage = undefined;
76
82
  defaultWorkingMessage = "Working...";
83
+ defaultHiddenThinkingLabel = "Thinking...";
84
+ hiddenThinkingLabel = this.defaultHiddenThinkingLabel;
77
85
  lastSigintTime = 0;
78
86
  lastEscapeTime = 0;
79
87
  changelogMarkdown = undefined;
88
+ startupNoticesShown = false;
89
+ anthropicSubscriptionWarningShown = false;
80
90
  // Status line tracking (for mutating immediately-sequential status updates)
81
91
  lastStatusSpacer = undefined;
82
92
  lastStatusText = undefined;
@@ -128,6 +138,9 @@ export class InteractiveMode {
128
138
  // Custom header from extension (undefined = use built-in header)
129
139
  customHeader = undefined;
130
140
  // Convenience accessors
141
+ get session() {
142
+ return this.runtimeHost.session;
143
+ }
131
144
  get agent() {
132
145
  return this.session.agent;
133
146
  }
@@ -137,9 +150,9 @@ export class InteractiveMode {
137
150
  get settingsManager() {
138
151
  return this.session.settingsManager;
139
152
  }
140
- constructor(session, options = {}) {
153
+ constructor(runtimeHost, options = {}) {
141
154
  this.options = options;
142
- this.session = session;
155
+ this.runtimeHost = runtimeHost;
143
156
  this.version = VERSION;
144
157
  this.ui = new TUI(new ProcessTerminal(), this.settingsManager.getShowHardwareCursor());
145
158
  this.ui.setClearOnShrink(this.settingsManager.getClearOnShrink());
@@ -160,9 +173,9 @@ export class InteractiveMode {
160
173
  this.editor = this.defaultEditor;
161
174
  this.editorContainer = new Container();
162
175
  this.editorContainer.addChild(this.editor);
163
- this.footerDataProvider = new FooterDataProvider();
164
- this.footer = new FooterComponent(session, this.footerDataProvider);
165
- this.footer.setAutoCompactEnabled(session.autoCompactionEnabled);
176
+ this.footerDataProvider = new FooterDataProvider(this.sessionManager.getCwd());
177
+ this.footer = new FooterComponent(this.session, this.footerDataProvider);
178
+ this.footer.setAutoCompactEnabled(this.session.autoCompactionEnabled);
166
179
  // Load hide thinking block setting
167
180
  this.hideThinkingBlock = this.settingsManager.getHideThinkingBlock();
168
181
  // Register themes from resource loader and initialize
@@ -269,12 +282,38 @@ export class InteractiveMode {
269
282
  }
270
283
  }
271
284
  // Setup autocomplete
272
- this.autocompleteProvider = new CombinedAutocompleteProvider([...slashCommands, ...templateCommands, ...extensionCommands, ...skillCommandList], process.cwd(), fdPath);
285
+ this.autocompleteProvider = new CombinedAutocompleteProvider([...slashCommands, ...templateCommands, ...extensionCommands, ...skillCommandList], this.sessionManager.getCwd(), fdPath);
273
286
  this.defaultEditor.setAutocompleteProvider(this.autocompleteProvider);
274
287
  if (this.editor !== this.defaultEditor) {
275
288
  this.editor.setAutocompleteProvider?.(this.autocompleteProvider);
276
289
  }
277
290
  }
291
+ showStartupNoticesIfNeeded() {
292
+ if (this.startupNoticesShown) {
293
+ return;
294
+ }
295
+ this.startupNoticesShown = true;
296
+ if (!this.changelogMarkdown) {
297
+ return;
298
+ }
299
+ if (this.chatContainer.children.length > 0) {
300
+ this.chatContainer.addChild(new Spacer(1));
301
+ }
302
+ this.chatContainer.addChild(new DynamicBorder());
303
+ if (this.settingsManager.getCollapseChangelog()) {
304
+ const versionMatch = this.changelogMarkdown.match(/##\s+\[?(\d+\.\d+\.\d+)\]?/);
305
+ const latestVersion = versionMatch ? versionMatch[1] : this.version;
306
+ const condensedText = `Updated to v${latestVersion}. Use ${theme.bold("/changelog")} to view full changelog.`;
307
+ this.chatContainer.addChild(new Text(condensedText, 1, 0));
308
+ }
309
+ else {
310
+ this.chatContainer.addChild(new Text(theme.bold(theme.fg("accent", "What's New")), 1, 0));
311
+ this.chatContainer.addChild(new Spacer(1));
312
+ this.chatContainer.addChild(new Markdown(this.changelogMarkdown.trim(), 1, 0, this.getMarkdownThemeWithSettings()));
313
+ this.chatContainer.addChild(new Spacer(1));
314
+ }
315
+ this.chatContainer.addChild(new DynamicBorder());
316
+ }
278
317
  async init() {
279
318
  if (this.isInitialized)
280
319
  return;
@@ -312,41 +351,17 @@ export class InteractiveMode {
312
351
  hint("app.clipboard.pasteImage", "to paste image"),
313
352
  rawKeyHint("drop files", "to attach"),
314
353
  ].join("\n");
315
- this.builtInHeader = new Text(`${logo}\n${instructions}`, 1, 0);
354
+ const onboarding = theme.fg("dim", `Draht can explain its own features and look up its docs. Ask it how to use or extend draht.`);
355
+ this.builtInHeader = new Text(`${logo}\n${instructions}\n\n${onboarding}`, 1, 0);
316
356
  // Setup UI layout
317
357
  this.headerContainer.addChild(new Spacer(1));
318
358
  this.headerContainer.addChild(this.builtInHeader);
319
359
  this.headerContainer.addChild(new Spacer(1));
320
- // Add changelog if provided
321
- if (this.changelogMarkdown) {
322
- this.headerContainer.addChild(new DynamicBorder());
323
- if (this.settingsManager.getCollapseChangelog()) {
324
- const versionMatch = this.changelogMarkdown.match(/##\s+\[?(\d+\.\d+\.\d+)\]?/);
325
- const latestVersion = versionMatch ? versionMatch[1] : this.version;
326
- const condensedText = `Updated to v${latestVersion}. Use ${theme.bold("/changelog")} to view full changelog.`;
327
- this.headerContainer.addChild(new Text(condensedText, 1, 0));
328
- }
329
- else {
330
- this.headerContainer.addChild(new Text(theme.bold(theme.fg("accent", "What's New")), 1, 0));
331
- this.headerContainer.addChild(new Spacer(1));
332
- this.headerContainer.addChild(new Markdown(this.changelogMarkdown.trim(), 1, 0, this.getMarkdownThemeWithSettings()));
333
- this.headerContainer.addChild(new Spacer(1));
334
- }
335
- this.headerContainer.addChild(new DynamicBorder());
336
- }
337
360
  }
338
361
  else {
339
362
  // Minimal header when silenced
340
363
  this.builtInHeader = new Text("", 0, 0);
341
364
  this.headerContainer.addChild(this.builtInHeader);
342
- if (this.changelogMarkdown) {
343
- // Still show changelog notification even in silent mode
344
- this.headerContainer.addChild(new Spacer(1));
345
- const versionMatch = this.changelogMarkdown.match(/##\s+\[?(\d+\.\d+\.\d+)\]?/);
346
- const latestVersion = versionMatch ? versionMatch[1] : this.version;
347
- const condensedText = `Updated to v${latestVersion}. Use ${theme.bold("/changelog")} to view full changelog.`;
348
- this.headerContainer.addChild(new Text(condensedText, 1, 0));
349
- }
350
365
  }
351
366
  this.ui.addChild(this.chatContainer);
352
367
  this.ui.addChild(this.pendingMessagesContainer);
@@ -363,7 +378,7 @@ export class InteractiveMode {
363
378
  this.ui.start();
364
379
  this.isInitialized = true;
365
380
  // Initialize extensions first so resources are shown before messages
366
- await this.initExtensions();
381
+ await this.bindCurrentSessionExtensions();
367
382
  // Render initial messages AFTER showing loaded resources
368
383
  this.renderInitialMessages();
369
384
  // Set terminal title
@@ -387,13 +402,13 @@ export class InteractiveMode {
387
402
  * Update terminal title with session name and cwd.
388
403
  */
389
404
  updateTerminalTitle() {
390
- const cwdBasename = path.basename(process.cwd());
405
+ const cwdBasename = path.basename(this.sessionManager.getCwd());
391
406
  const sessionName = this.sessionManager.getSessionName();
392
407
  if (sessionName) {
393
- this.ui.terminal.setTitle(`D - ${sessionName} - ${cwdBasename}`);
408
+ this.ui.terminal.setTitle(`π - ${sessionName} - ${cwdBasename}`);
394
409
  }
395
410
  else {
396
- this.ui.terminal.setTitle(`D - ${cwdBasename}`);
411
+ this.ui.terminal.setTitle(`π - ${cwdBasename}`);
397
412
  }
398
413
  }
399
414
  /**
@@ -432,6 +447,7 @@ export class InteractiveMode {
432
447
  if (modelFallbackMessage) {
433
448
  this.showWarning(modelFallbackMessage);
434
449
  }
450
+ void this.maybeWarnAboutAnthropicSubscriptionAuth();
435
451
  // Process initial messages
436
452
  if (initialMessage) {
437
453
  try {
@@ -494,7 +510,7 @@ export class InteractiveMode {
494
510
  }
495
511
  try {
496
512
  const packageManager = new DefaultPackageManager({
497
- cwd: process.cwd(),
513
+ cwd: this.sessionManager.getCwd(),
498
514
  agentDir: getAgentDir(),
499
515
  settingsManager: this.settingsManager,
500
516
  });
@@ -882,7 +898,7 @@ export class InteractiveMode {
882
898
  /**
883
899
  * Initialize the extension system with TUI-based UI context.
884
900
  */
885
- async initExtensions() {
901
+ async bindCurrentSessionExtensions() {
886
902
  const uiContext = this.createExtensionUIContext();
887
903
  await this.session.bindExtensions({
888
904
  uiContext,
@@ -894,33 +910,33 @@ export class InteractiveMode {
894
910
  this.loadingAnimation = undefined;
895
911
  }
896
912
  this.statusContainer.clear();
897
- // Delegate to AgentSession (handles setup + agent state sync)
898
- const success = await this.session.newSession(options);
899
- if (!success) {
900
- return { cancelled: true };
913
+ try {
914
+ const result = await this.runtimeHost.newSession(options);
915
+ if (!result.cancelled) {
916
+ await this.handleRuntimeSessionChange();
917
+ this.renderCurrentSessionState();
918
+ this.ui.requestRender();
919
+ }
920
+ return result;
921
+ }
922
+ catch (error) {
923
+ return this.handleFatalRuntimeError("Failed to create session", error);
901
924
  }
902
- // Clear UI state
903
- this.chatContainer.clear();
904
- this.pendingMessagesContainer.clear();
905
- this.compactionQueuedMessages = [];
906
- this.streamingComponent = undefined;
907
- this.streamingMessage = undefined;
908
- this.pendingTools.clear();
909
- // Render any messages added via setup, or show empty session
910
- this.renderInitialMessages();
911
- this.ui.requestRender();
912
- return { cancelled: false };
913
925
  },
914
926
  fork: async (entryId) => {
915
- const result = await this.session.fork(entryId);
916
- if (result.cancelled) {
917
- return { cancelled: true };
927
+ try {
928
+ const result = await this.runtimeHost.fork(entryId);
929
+ if (!result.cancelled) {
930
+ await this.handleRuntimeSessionChange();
931
+ this.renderCurrentSessionState();
932
+ this.editor.setText(result.selectedText ?? "");
933
+ this.showStatus("Forked to new session");
934
+ }
935
+ return { cancelled: result.cancelled };
936
+ }
937
+ catch (error) {
938
+ return this.handleFatalRuntimeError("Failed to fork session", error);
918
939
  }
919
- this.chatContainer.clear();
920
- this.renderInitialMessages();
921
- this.editor.setText(result.selectedText);
922
- this.showStatus("Forked to new session");
923
- return { cancelled: false };
924
940
  },
925
941
  navigateTree: async (targetId, options) => {
926
942
  const result = await this.session.navigateTree(targetId, {
@@ -963,10 +979,55 @@ export class InteractiveMode {
963
979
  const extensionRunner = this.session.extensionRunner;
964
980
  if (!extensionRunner) {
965
981
  this.showLoadedResources({ extensions: [], force: false });
982
+ this.showStartupNoticesIfNeeded();
966
983
  return;
967
984
  }
968
985
  this.setupExtensionShortcuts(extensionRunner);
969
986
  this.showLoadedResources({ force: false });
987
+ this.showStartupNoticesIfNeeded();
988
+ }
989
+ applyRuntimeSettings() {
990
+ this.footer.setSession(this.session);
991
+ this.footer.setAutoCompactEnabled(this.session.autoCompactionEnabled);
992
+ this.footerDataProvider.setCwd(this.sessionManager.getCwd());
993
+ this.hideThinkingBlock = this.settingsManager.getHideThinkingBlock();
994
+ this.ui.setShowHardwareCursor(this.settingsManager.getShowHardwareCursor());
995
+ this.ui.setClearOnShrink(this.settingsManager.getClearOnShrink());
996
+ const editorPaddingX = this.settingsManager.getEditorPaddingX();
997
+ const autocompleteMaxVisible = this.settingsManager.getAutocompleteMaxVisible();
998
+ this.defaultEditor.setPaddingX(editorPaddingX);
999
+ this.defaultEditor.setAutocompleteMaxVisible(autocompleteMaxVisible);
1000
+ if (this.editor !== this.defaultEditor) {
1001
+ this.editor.setPaddingX?.(editorPaddingX);
1002
+ this.editor.setAutocompleteMaxVisible?.(autocompleteMaxVisible);
1003
+ }
1004
+ }
1005
+ async handleRuntimeSessionChange() {
1006
+ this.resetExtensionUI();
1007
+ this.unsubscribe?.();
1008
+ this.unsubscribe = undefined;
1009
+ this.applyRuntimeSettings();
1010
+ await this.bindCurrentSessionExtensions();
1011
+ this.subscribeToAgent();
1012
+ await this.updateAvailableProviderCount();
1013
+ this.updateEditorBorderColor();
1014
+ this.updateTerminalTitle();
1015
+ }
1016
+ async handleFatalRuntimeError(prefix, error) {
1017
+ const message = error instanceof Error ? error.message : String(error);
1018
+ this.showError(`${prefix}: ${message}`);
1019
+ stopThemeWatcher();
1020
+ this.stop();
1021
+ process.exit(1);
1022
+ }
1023
+ renderCurrentSessionState() {
1024
+ this.chatContainer.clear();
1025
+ this.pendingMessagesContainer.clear();
1026
+ this.compactionQueuedMessages = [];
1027
+ this.streamingComponent = undefined;
1028
+ this.streamingMessage = undefined;
1029
+ this.pendingTools.clear();
1030
+ this.renderInitialMessages();
970
1031
  }
971
1032
  /**
972
1033
  * Get a registered tool definition by name (for custom rendering).
@@ -985,11 +1046,12 @@ export class InteractiveMode {
985
1046
  const createContext = () => ({
986
1047
  ui: this.createExtensionUIContext(),
987
1048
  hasUI: true,
988
- cwd: process.cwd(),
1049
+ cwd: this.sessionManager.getCwd(),
989
1050
  sessionManager: this.sessionManager,
990
1051
  modelRegistry: this.session.modelRegistry,
991
1052
  model: this.session.model,
992
1053
  isIdle: () => !this.session.isStreaming,
1054
+ signal: this.session.agent.signal,
993
1055
  abort: () => this.session.abort(),
994
1056
  hasPendingMessages: () => this.session.pendingMessageCount > 0,
995
1057
  shutdown: () => {
@@ -999,10 +1061,8 @@ export class InteractiveMode {
999
1061
  compact: (options) => {
1000
1062
  void (async () => {
1001
1063
  try {
1002
- const result = await this.executeCompaction(options?.customInstructions, false);
1003
- if (result) {
1004
- options?.onComplete?.(result);
1005
- }
1064
+ const result = await this.session.compact(options?.customInstructions);
1065
+ options?.onComplete?.(result);
1006
1066
  }
1007
1067
  catch (error) {
1008
1068
  const err = error instanceof Error ? error : new Error(String(error));
@@ -1034,6 +1094,18 @@ export class InteractiveMode {
1034
1094
  this.footerDataProvider.setExtensionStatus(key, text);
1035
1095
  this.ui.requestRender();
1036
1096
  }
1097
+ setHiddenThinkingLabel(label) {
1098
+ this.hiddenThinkingLabel = label ?? this.defaultHiddenThinkingLabel;
1099
+ for (const child of this.chatContainer.children) {
1100
+ if (child instanceof AssistantMessageComponent) {
1101
+ child.setHiddenThinkingLabel(this.hiddenThinkingLabel);
1102
+ }
1103
+ }
1104
+ if (this.streamingComponent) {
1105
+ this.streamingComponent.setHiddenThinkingLabel(this.hiddenThinkingLabel);
1106
+ }
1107
+ this.ui.requestRender();
1108
+ }
1037
1109
  /**
1038
1110
  * Set an extension widget (string array or custom component).
1039
1111
  */
@@ -1105,6 +1177,7 @@ export class InteractiveMode {
1105
1177
  if (this.loadingAnimation) {
1106
1178
  this.loadingAnimation.setMessage(`${this.defaultWorkingMessage} (${keyText("app.interrupt")} to interrupt)`);
1107
1179
  }
1180
+ this.setHiddenThinkingLabel();
1108
1181
  }
1109
1182
  // Maximum total widget lines to prevent viewport overflow
1110
1183
  static MAX_WIDGET_LINES = 10;
@@ -1234,6 +1307,7 @@ export class InteractiveMode {
1234
1307
  this.pendingWorkingMessage = message;
1235
1308
  }
1236
1309
  },
1310
+ setHiddenThinkingLabel: (label) => this.setHiddenThinkingLabel(label),
1237
1311
  setWidget: (key, content, options) => this.setExtensionWidget(key, content, options),
1238
1312
  setFooter: (factory) => this.setExtensionFooter(factory),
1239
1313
  setHeader: (factory) => this.setExtensionHeader(factory),
@@ -1315,6 +1389,10 @@ export class InteractiveMode {
1315
1389
  const result = await this.showExtensionSelector(`${title}\n${message}`, ["Yes", "No"], opts);
1316
1390
  return result === "Yes";
1317
1391
  }
1392
+ async promptForMissingSessionCwd(error) {
1393
+ const confirmed = await this.showExtensionConfirm("Session cwd not found", formatMissingSessionCwdPrompt(error.issue));
1394
+ return confirmed ? error.issue.fallbackCwd : undefined;
1395
+ }
1318
1396
  /**
1319
1397
  * Show a text input for extensions.
1320
1398
  */
@@ -1742,6 +1820,11 @@ export class InteractiveMode {
1742
1820
  this.editor.setText("");
1743
1821
  return;
1744
1822
  }
1823
+ if (text === "/dementedelves") {
1824
+ this.handleDementedDelves();
1825
+ this.editor.setText("");
1826
+ return;
1827
+ }
1745
1828
  if (text === "/resume") {
1746
1829
  this.showSessionSelector();
1747
1830
  this.editor.setText("");
@@ -1837,6 +1920,10 @@ export class InteractiveMode {
1837
1920
  }
1838
1921
  this.ui.requestRender();
1839
1922
  break;
1923
+ case "queue_update":
1924
+ this.updatePendingMessagesDisplay();
1925
+ this.ui.requestRender();
1926
+ break;
1840
1927
  case "message_start":
1841
1928
  if (event.message.role === "custom") {
1842
1929
  this.addMessageToChat(event.message);
@@ -1848,7 +1935,7 @@ export class InteractiveMode {
1848
1935
  this.ui.requestRender();
1849
1936
  }
1850
1937
  else if (event.message.role === "assistant") {
1851
- this.streamingComponent = new AssistantMessageComponent(undefined, this.hideThinkingBlock, this.getMarkdownThemeWithSettings());
1938
+ this.streamingComponent = new AssistantMessageComponent(undefined, this.hideThinkingBlock, this.getMarkdownThemeWithSettings(), this.hiddenThinkingLabel);
1852
1939
  this.streamingMessage = event.message;
1853
1940
  this.chatContainer.addChild(this.streamingComponent);
1854
1941
  this.streamingComponent.updateContent(this.streamingMessage);
@@ -1864,7 +1951,7 @@ export class InteractiveMode {
1864
1951
  if (!this.pendingTools.has(content.id)) {
1865
1952
  const component = new ToolExecutionComponent(content.name, content.id, content.arguments, {
1866
1953
  showImages: this.settingsManager.getShowImages(),
1867
- }, this.getRegisteredToolDefinition(content.name), this.ui);
1954
+ }, this.getRegisteredToolDefinition(content.name), this.ui, this.sessionManager.getCwd());
1868
1955
  component.setExpanded(this.toolOutputExpanded);
1869
1956
  this.chatContainer.addChild(component);
1870
1957
  this.pendingTools.set(content.id, component);
@@ -1924,7 +2011,7 @@ export class InteractiveMode {
1924
2011
  if (!component) {
1925
2012
  component = new ToolExecutionComponent(event.toolName, event.toolCallId, event.args, {
1926
2013
  showImages: this.settingsManager.getShowImages(),
1927
- }, this.getRegisteredToolDefinition(event.toolName), this.ui);
2014
+ }, this.getRegisteredToolDefinition(event.toolName), this.ui, this.sessionManager.getCwd());
1928
2015
  component.setExpanded(this.toolOutputExpanded);
1929
2016
  this.chatContainer.addChild(component);
1930
2017
  this.pendingTools.set(event.toolCallId, component);
@@ -1965,54 +2052,54 @@ export class InteractiveMode {
1965
2052
  await this.checkShutdownRequested();
1966
2053
  this.ui.requestRender();
1967
2054
  break;
1968
- case "auto_compaction_start": {
2055
+ case "compaction_start": {
1969
2056
  // Keep editor active; submissions are queued during compaction.
1970
- // Set up escape to abort auto-compaction
1971
2057
  this.autoCompactionEscapeHandler = this.defaultEditor.onEscape;
1972
2058
  this.defaultEditor.onEscape = () => {
1973
2059
  this.session.abortCompaction();
1974
2060
  };
1975
- // Show compacting indicator with reason
1976
2061
  this.statusContainer.clear();
1977
- const reasonText = event.reason === "overflow" ? "Context overflow detected, " : "";
1978
- this.autoCompactionLoader = new Loader(this.ui, (spinner) => theme.fg("accent", spinner), (text) => theme.fg("muted", text), `${reasonText}Auto-compacting... (${keyText("app.interrupt")} to cancel)`);
2062
+ const cancelHint = `(${keyText("app.interrupt")} to cancel)`;
2063
+ const label = event.reason === "manual"
2064
+ ? `Compacting context... ${cancelHint}`
2065
+ : `${event.reason === "overflow" ? "Context overflow detected, " : ""}Auto-compacting... ${cancelHint}`;
2066
+ this.autoCompactionLoader = new Loader(this.ui, (spinner) => theme.fg("accent", spinner), (text) => theme.fg("muted", text), label);
1979
2067
  this.statusContainer.addChild(this.autoCompactionLoader);
1980
2068
  this.ui.requestRender();
1981
2069
  break;
1982
2070
  }
1983
- case "auto_compaction_end": {
1984
- // Restore escape handler
2071
+ case "compaction_end": {
1985
2072
  if (this.autoCompactionEscapeHandler) {
1986
2073
  this.defaultEditor.onEscape = this.autoCompactionEscapeHandler;
1987
2074
  this.autoCompactionEscapeHandler = undefined;
1988
2075
  }
1989
- // Stop loader
1990
2076
  if (this.autoCompactionLoader) {
1991
2077
  this.autoCompactionLoader.stop();
1992
2078
  this.autoCompactionLoader = undefined;
1993
2079
  this.statusContainer.clear();
1994
2080
  }
1995
- // Handle result
1996
2081
  if (event.aborted) {
1997
- this.showStatus("Auto-compaction cancelled");
2082
+ if (event.reason === "manual") {
2083
+ this.showError("Compaction cancelled");
2084
+ }
2085
+ else {
2086
+ this.showStatus("Auto-compaction cancelled");
2087
+ }
1998
2088
  }
1999
2089
  else if (event.result) {
2000
- // Rebuild chat to show compacted state
2001
2090
  this.chatContainer.clear();
2002
2091
  this.rebuildChatFromMessages();
2003
- // Add compaction component at bottom so user sees it without scrolling
2004
- this.addMessageToChat({
2005
- role: "compactionSummary",
2006
- tokensBefore: event.result.tokensBefore,
2007
- summary: event.result.summary,
2008
- timestamp: Date.now(),
2009
- });
2092
+ this.addMessageToChat(createCompactionSummaryMessage(event.result.summary, event.result.tokensBefore, new Date().toISOString()));
2010
2093
  this.footer.invalidate();
2011
2094
  }
2012
2095
  else if (event.errorMessage) {
2013
- // Compaction failed (e.g., quota exceeded, API error)
2014
- this.chatContainer.addChild(new Spacer(1));
2015
- this.chatContainer.addChild(new Text(theme.fg("error", event.errorMessage), 1, 0));
2096
+ if (event.reason === "manual") {
2097
+ this.showError(event.errorMessage);
2098
+ }
2099
+ else {
2100
+ this.chatContainer.addChild(new Spacer(1));
2101
+ this.chatContainer.addChild(new Text(theme.fg("error", event.errorMessage), 1, 0));
2102
+ }
2016
2103
  }
2017
2104
  void this.flushCompactionQueue({ willRetry: event.willRetry });
2018
2105
  this.ui.requestRender();
@@ -2146,7 +2233,7 @@ export class InteractiveMode {
2146
2233
  break;
2147
2234
  }
2148
2235
  case "assistant": {
2149
- const assistantComponent = new AssistantMessageComponent(message, this.hideThinkingBlock, this.getMarkdownThemeWithSettings());
2236
+ const assistantComponent = new AssistantMessageComponent(message, this.hideThinkingBlock, this.getMarkdownThemeWithSettings(), this.hiddenThinkingLabel);
2150
2237
  this.chatContainer.addChild(assistantComponent);
2151
2238
  break;
2152
2239
  }
@@ -2178,7 +2265,7 @@ export class InteractiveMode {
2178
2265
  // Render tool call components
2179
2266
  for (const content of message.content) {
2180
2267
  if (content.type === "toolCall") {
2181
- const component = new ToolExecutionComponent(content.name, content.id, content.arguments, { showImages: this.settingsManager.getShowImages() }, this.getRegisteredToolDefinition(content.name), this.ui);
2268
+ const component = new ToolExecutionComponent(content.name, content.id, content.arguments, { showImages: this.settingsManager.getShowImages() }, this.getRegisteredToolDefinition(content.name), this.ui, this.sessionManager.getCwd());
2182
2269
  component.setExpanded(this.toolOutputExpanded);
2183
2270
  this.chatContainer.addChild(component);
2184
2271
  if (message.stopReason === "aborted" || message.stopReason === "error") {
@@ -2271,13 +2358,7 @@ export class InteractiveMode {
2271
2358
  if (this.isShuttingDown)
2272
2359
  return;
2273
2360
  this.isShuttingDown = true;
2274
- // Emit shutdown event to extensions
2275
- const extensionRunner = this.session.extensionRunner;
2276
- if (extensionRunner?.hasHandlers("session_shutdown")) {
2277
- await extensionRunner.emit({
2278
- type: "session_shutdown",
2279
- });
2280
- }
2361
+ await this.runtimeHost.dispose();
2281
2362
  // Wait for any pending renders to complete
2282
2363
  // requestRender() uses process.nextTick(), so we wait one tick
2283
2364
  await new Promise((resolve) => process.nextTick(resolve));
@@ -2395,6 +2476,7 @@ export class InteractiveMode {
2395
2476
  this.updateEditorBorderColor();
2396
2477
  const thinkingStr = result.model.reasoning && result.thinkingLevel !== "off" ? ` (thinking: ${result.thinkingLevel})` : "";
2397
2478
  this.showStatus(`Switched to ${result.model.name || result.model.id}${thinkingStr}`);
2479
+ void this.maybeWarnAboutAnthropicSubscriptionAuth(result.model);
2398
2480
  }
2399
2481
  }
2400
2482
  catch (error) {
@@ -2747,7 +2829,7 @@ export class InteractiveMode {
2747
2829
  },
2748
2830
  onTransportChange: (transport) => {
2749
2831
  this.settingsManager.setTransport(transport);
2750
- this.session.agent.setTransport(transport);
2832
+ this.session.agent.transport = transport;
2751
2833
  },
2752
2834
  onThinkingLevelChange: (level) => {
2753
2835
  this.session.setThinkingLevel(level);
@@ -2834,6 +2916,7 @@ export class InteractiveMode {
2834
2916
  this.footer.invalidate();
2835
2917
  this.updateEditorBorderColor();
2836
2918
  this.showStatus(`Model: ${model.id}`);
2919
+ void this.maybeWarnAboutAnthropicSubscriptionAuth(model);
2837
2920
  this.checkDaxnutsEasterEgg(model);
2838
2921
  }
2839
2922
  catch (error) {
@@ -2865,6 +2948,31 @@ export class InteractiveMode {
2865
2948
  const uniqueProviders = new Set(models.map((m) => m.provider));
2866
2949
  this.footerDataProvider.setAvailableProviderCount(uniqueProviders.size);
2867
2950
  }
2951
+ async maybeWarnAboutAnthropicSubscriptionAuth(model = this.session.model) {
2952
+ if (this.anthropicSubscriptionWarningShown) {
2953
+ return;
2954
+ }
2955
+ if (!model || model.provider !== "anthropic") {
2956
+ return;
2957
+ }
2958
+ const storedCredential = this.session.modelRegistry.authStorage.get("anthropic");
2959
+ if (storedCredential?.type === "oauth") {
2960
+ this.anthropicSubscriptionWarningShown = true;
2961
+ this.showWarning(ANTHROPIC_SUBSCRIPTION_AUTH_WARNING);
2962
+ return;
2963
+ }
2964
+ try {
2965
+ const apiKey = await this.session.modelRegistry.getApiKeyForProvider(model.provider);
2966
+ if (!isAnthropicSubscriptionAuthKey(apiKey)) {
2967
+ return;
2968
+ }
2969
+ this.anthropicSubscriptionWarningShown = true;
2970
+ this.showWarning(ANTHROPIC_SUBSCRIPTION_AUTH_WARNING);
2971
+ }
2972
+ catch {
2973
+ // Ignore auth lookup failures for warning-only checks.
2974
+ }
2975
+ }
2868
2976
  showModelSelector(initialSearchInput) {
2869
2977
  this.showSelector((done) => {
2870
2978
  const selector = new ModelSelectorComponent(this.ui, this.session.model, this.settingsManager, this.session.modelRegistry, this.session.scopedModels, async (model) => {
@@ -2874,6 +2982,7 @@ export class InteractiveMode {
2874
2982
  this.updateEditorBorderColor();
2875
2983
  done();
2876
2984
  this.showStatus(`Model: ${model.id}`);
2985
+ void this.maybeWarnAboutAnthropicSubscriptionAuth(model);
2877
2986
  this.checkDaxnutsEasterEgg(model);
2878
2987
  }
2879
2988
  catch (error) {
@@ -3003,16 +3112,15 @@ export class InteractiveMode {
3003
3112
  }
3004
3113
  this.showSelector((done) => {
3005
3114
  const selector = new UserMessageSelectorComponent(userMessages.map((m) => ({ id: m.entryId, text: m.text })), async (entryId) => {
3006
- const result = await this.session.fork(entryId);
3115
+ const result = await this.runtimeHost.fork(entryId);
3007
3116
  if (result.cancelled) {
3008
- // Extension cancelled the fork
3009
3117
  done();
3010
3118
  this.ui.requestRender();
3011
3119
  return;
3012
3120
  }
3013
- this.chatContainer.clear();
3014
- this.renderInitialMessages();
3015
- this.editor.setText(result.selectedText);
3121
+ await this.handleRuntimeSessionChange();
3122
+ this.renderCurrentSessionState();
3123
+ this.editor.setText(result.selectedText ?? "");
3016
3124
  done();
3017
3125
  this.showStatus("Branched to new session");
3018
3126
  }, () => {
@@ -3148,24 +3256,38 @@ export class InteractiveMode {
3148
3256
  });
3149
3257
  }
3150
3258
  async handleResumeSession(sessionPath) {
3151
- // Stop loading animation
3152
3259
  if (this.loadingAnimation) {
3153
3260
  this.loadingAnimation.stop();
3154
3261
  this.loadingAnimation = undefined;
3155
3262
  }
3156
3263
  this.statusContainer.clear();
3157
- // Clear UI state
3158
- this.pendingMessagesContainer.clear();
3159
- this.compactionQueuedMessages = [];
3160
- this.streamingComponent = undefined;
3161
- this.streamingMessage = undefined;
3162
- this.pendingTools.clear();
3163
- // Switch session via AgentSession (emits extension session events)
3164
- await this.session.switchSession(sessionPath);
3165
- // Clear and re-render the chat
3166
- this.chatContainer.clear();
3167
- this.renderInitialMessages();
3168
- this.showStatus("Resumed session");
3264
+ try {
3265
+ const result = await this.runtimeHost.switchSession(sessionPath);
3266
+ if (result.cancelled) {
3267
+ return;
3268
+ }
3269
+ await this.handleRuntimeSessionChange();
3270
+ this.renderCurrentSessionState();
3271
+ this.showStatus("Resumed session");
3272
+ }
3273
+ catch (error) {
3274
+ if (error instanceof MissingSessionCwdError) {
3275
+ const selectedCwd = await this.promptForMissingSessionCwd(error);
3276
+ if (!selectedCwd) {
3277
+ this.showStatus("Resume cancelled");
3278
+ return;
3279
+ }
3280
+ const result = await this.runtimeHost.switchSession(sessionPath, selectedCwd);
3281
+ if (result.cancelled) {
3282
+ return;
3283
+ }
3284
+ await this.handleRuntimeSessionChange();
3285
+ this.renderCurrentSessionState();
3286
+ this.showStatus("Resumed session in current cwd");
3287
+ return;
3288
+ }
3289
+ await this.handleFatalRuntimeError("Failed to resume session", error);
3290
+ }
3169
3291
  }
3170
3292
  async showOAuthSelector(mode) {
3171
3293
  if (mode === "logout") {
@@ -3383,30 +3505,38 @@ export class InteractiveMode {
3383
3505
  return;
3384
3506
  }
3385
3507
  try {
3386
- // Stop loading animation
3387
3508
  if (this.loadingAnimation) {
3388
3509
  this.loadingAnimation.stop();
3389
3510
  this.loadingAnimation = undefined;
3390
3511
  }
3391
3512
  this.statusContainer.clear();
3392
- // Clear UI state
3393
- this.pendingMessagesContainer.clear();
3394
- this.compactionQueuedMessages = [];
3395
- this.streamingComponent = undefined;
3396
- this.streamingMessage = undefined;
3397
- this.pendingTools.clear();
3398
- const success = await this.session.importFromJsonl(inputPath);
3399
- if (!success) {
3400
- this.showWarning("Import cancelled");
3513
+ const result = await this.runtimeHost.importFromJsonl(inputPath);
3514
+ if (result.cancelled) {
3515
+ this.showStatus("Import cancelled");
3401
3516
  return;
3402
3517
  }
3403
- // Clear and re-render the chat
3404
- this.chatContainer.clear();
3405
- this.renderInitialMessages();
3518
+ await this.handleRuntimeSessionChange();
3519
+ this.renderCurrentSessionState();
3406
3520
  this.showStatus(`Session imported from: ${inputPath}`);
3407
3521
  }
3408
3522
  catch (error) {
3409
- this.showError(`Failed to import session: ${error instanceof Error ? error.message : "Unknown error"}`);
3523
+ if (error instanceof MissingSessionCwdError) {
3524
+ const selectedCwd = await this.promptForMissingSessionCwd(error);
3525
+ if (!selectedCwd) {
3526
+ this.showStatus("Import cancelled");
3527
+ return;
3528
+ }
3529
+ const result = await this.runtimeHost.importFromJsonl(inputPath, selectedCwd);
3530
+ if (result.cancelled) {
3531
+ this.showStatus("Import cancelled");
3532
+ return;
3533
+ }
3534
+ await this.handleRuntimeSessionChange();
3535
+ this.renderCurrentSessionState();
3536
+ this.showStatus(`Session imported from: ${inputPath}`);
3537
+ return;
3538
+ }
3539
+ await this.handleFatalRuntimeError("Failed to import session", error);
3410
3540
  }
3411
3541
  }
3412
3542
  async handleShareCommand() {
@@ -3716,25 +3846,25 @@ export class InteractiveMode {
3716
3846
  this.ui.requestRender();
3717
3847
  }
3718
3848
  async handleClearCommand() {
3719
- // Stop loading animation
3720
3849
  if (this.loadingAnimation) {
3721
3850
  this.loadingAnimation.stop();
3722
3851
  this.loadingAnimation = undefined;
3723
3852
  }
3724
3853
  this.statusContainer.clear();
3725
- // New session via session (emits extension session events)
3726
- await this.session.newSession();
3727
- // Clear UI state
3728
- this.headerContainer.clear();
3729
- this.chatContainer.clear();
3730
- this.pendingMessagesContainer.clear();
3731
- this.compactionQueuedMessages = [];
3732
- this.streamingComponent = undefined;
3733
- this.streamingMessage = undefined;
3734
- this.pendingTools.clear();
3735
- this.chatContainer.addChild(new Spacer(1));
3736
- this.chatContainer.addChild(new Text(`${theme.fg("accent", "✓ New session started")}`, 1, 1));
3737
- this.ui.requestRender();
3854
+ try {
3855
+ const result = await this.runtimeHost.newSession();
3856
+ if (result.cancelled) {
3857
+ return;
3858
+ }
3859
+ await this.handleRuntimeSessionChange();
3860
+ this.renderCurrentSessionState();
3861
+ this.chatContainer.addChild(new Spacer(1));
3862
+ this.chatContainer.addChild(new Text(`${theme.fg("accent", "✓ New session started")}`, 1, 1));
3863
+ this.ui.requestRender();
3864
+ }
3865
+ catch (error) {
3866
+ await this.handleFatalRuntimeError("Failed to create session", error);
3867
+ }
3738
3868
  }
3739
3869
  handleDebugCommand() {
3740
3870
  const width = this.ui.terminal.columns;
@@ -3768,6 +3898,11 @@ export class InteractiveMode {
3768
3898
  this.chatContainer.addChild(new ArminComponent(this.ui));
3769
3899
  this.ui.requestRender();
3770
3900
  }
3901
+ handleDementedDelves() {
3902
+ this.chatContainer.addChild(new Spacer(1));
3903
+ this.chatContainer.addChild(new EarendilAnnouncementComponent());
3904
+ this.ui.requestRender();
3905
+ }
3771
3906
  handleDaxnuts() {
3772
3907
  this.chatContainer.addChild(new Spacer(1));
3773
3908
  this.chatContainer.addChild(new DaxnutsComponent(this.ui));
@@ -3786,7 +3921,7 @@ export class InteractiveMode {
3786
3921
  type: "user_bash",
3787
3922
  command,
3788
3923
  excludeFromContext,
3789
- cwd: process.cwd(),
3924
+ cwd: this.sessionManager.getCwd(),
3790
3925
  })
3791
3926
  : undefined;
3792
3927
  // If extension returned a full result, use it directly
@@ -3852,53 +3987,17 @@ export class InteractiveMode {
3852
3987
  this.showWarning("Nothing to compact (no messages yet)");
3853
3988
  return;
3854
3989
  }
3855
- await this.executeCompaction(customInstructions, false);
3856
- }
3857
- async executeCompaction(customInstructions, isAuto = false) {
3858
- // Stop loading animation
3859
3990
  if (this.loadingAnimation) {
3860
3991
  this.loadingAnimation.stop();
3861
3992
  this.loadingAnimation = undefined;
3862
3993
  }
3863
3994
  this.statusContainer.clear();
3864
- // Set up escape handler during compaction
3865
- const originalOnEscape = this.defaultEditor.onEscape;
3866
- this.defaultEditor.onEscape = () => {
3867
- this.session.abortCompaction();
3868
- };
3869
- // Show compacting status
3870
- this.chatContainer.addChild(new Spacer(1));
3871
- const cancelHint = `(${keyText("app.interrupt")} to cancel)`;
3872
- const label = isAuto ? `Auto-compacting context... ${cancelHint}` : `Compacting context... ${cancelHint}`;
3873
- const compactingLoader = new Loader(this.ui, (spinner) => theme.fg("accent", spinner), (text) => theme.fg("muted", text), label);
3874
- this.statusContainer.addChild(compactingLoader);
3875
- this.ui.requestRender();
3876
- let result;
3877
3995
  try {
3878
- result = await this.session.compact(customInstructions);
3879
- // Rebuild UI
3880
- this.rebuildChatFromMessages();
3881
- // Add compaction component at bottom so user sees it without scrolling
3882
- const msg = createCompactionSummaryMessage(result.summary, result.tokensBefore, new Date().toISOString());
3883
- this.addMessageToChat(msg);
3884
- this.footer.invalidate();
3885
- }
3886
- catch (error) {
3887
- const message = error instanceof Error ? error.message : String(error);
3888
- if (message === "Compaction cancelled" || (error instanceof Error && error.name === "AbortError")) {
3889
- this.showError("Compaction cancelled");
3890
- }
3891
- else {
3892
- this.showError(`Compaction failed: ${message}`);
3893
- }
3996
+ await this.session.compact(customInstructions);
3894
3997
  }
3895
- finally {
3896
- compactingLoader.stop();
3897
- this.statusContainer.clear();
3898
- this.defaultEditor.onEscape = originalOnEscape;
3998
+ catch {
3999
+ // Ignore, will be emitted as an event
3899
4000
  }
3900
- void this.flushCompactionQueue({ willRetry: false });
3901
- return result;
3902
4001
  }
3903
4002
  stop() {
3904
4003
  if (this.loadingAnimation) {