@openadapter/koda 1.0.0-beta.3

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 (357) hide show
  1. package/CHANGELOG.md +4448 -0
  2. package/README.md +665 -0
  3. package/dist/bun/cli.d.ts +2 -0
  4. package/dist/bun/cli.js +2 -0
  5. package/dist/bun/register-bedrock.d.ts +1 -0
  6. package/dist/bun/register-bedrock.js +1 -0
  7. package/dist/bun/restore-sandbox-env.d.ts +12 -0
  8. package/dist/bun/restore-sandbox-env.js +1 -0
  9. package/dist/cli/args.d.ts +55 -0
  10. package/dist/cli/args.js +167 -0
  11. package/dist/cli/config-selector.d.ts +13 -0
  12. package/dist/cli/config-selector.js +1 -0
  13. package/dist/cli/file-processor.d.ts +14 -0
  14. package/dist/cli/file-processor.js +7 -0
  15. package/dist/cli/import-sessions.d.ts +34 -0
  16. package/dist/cli/import-sessions.js +6 -0
  17. package/dist/cli/initial-message.d.ts +17 -0
  18. package/dist/cli/initial-message.js +1 -0
  19. package/dist/cli/list-models.d.ts +8 -0
  20. package/dist/cli/list-models.js +2 -0
  21. package/dist/cli/openadapter-setup.d.ts +29 -0
  22. package/dist/cli/openadapter-setup.js +3 -0
  23. package/dist/cli/session-picker.d.ts +8 -0
  24. package/dist/cli/session-picker.js +1 -0
  25. package/dist/cli.d.ts +2 -0
  26. package/dist/cli.js +2 -0
  27. package/dist/config.d.ts +92 -0
  28. package/dist/config.js +1 -0
  29. package/dist/core/agent-session-runtime.d.ts +116 -0
  30. package/dist/core/agent-session-runtime.js +1 -0
  31. package/dist/core/agent-session-services.d.ts +86 -0
  32. package/dist/core/agent-session-services.js +1 -0
  33. package/dist/core/agent-session.d.ts +747 -0
  34. package/dist/core/agent-session.js +32 -0
  35. package/dist/core/auth-guidance.d.ts +4 -0
  36. package/dist/core/auth-guidance.js +8 -0
  37. package/dist/core/auth-storage.d.ts +140 -0
  38. package/dist/core/auth-storage.js +1 -0
  39. package/dist/core/bash-executor.d.ts +31 -0
  40. package/dist/core/bash-executor.js +1 -0
  41. package/dist/core/compaction/branch-summarization.d.ts +89 -0
  42. package/dist/core/compaction/branch-summarization.js +38 -0
  43. package/dist/core/compaction/compaction.d.ts +120 -0
  44. package/dist/core/compaction/compaction.js +104 -0
  45. package/dist/core/compaction/index.d.ts +6 -0
  46. package/dist/core/compaction/index.js +1 -0
  47. package/dist/core/compaction/utils.d.ts +37 -0
  48. package/dist/core/compaction/utils.js +19 -0
  49. package/dist/core/defaults.d.ts +2 -0
  50. package/dist/core/defaults.js +1 -0
  51. package/dist/core/diagnostics.d.ts +14 -0
  52. package/dist/core/diagnostics.js +0 -0
  53. package/dist/core/event-bus.d.ts +8 -0
  54. package/dist/core/event-bus.js +1 -0
  55. package/dist/core/exec.d.ts +28 -0
  56. package/dist/core/exec.js +1 -0
  57. package/dist/core/export-html/ansi-to-html.d.ts +21 -0
  58. package/dist/core/export-html/ansi-to-html.js +1 -0
  59. package/dist/core/export-html/index.d.ts +36 -0
  60. package/dist/core/export-html/index.js +2 -0
  61. package/dist/core/export-html/template.css +1066 -0
  62. package/dist/core/export-html/template.html +55 -0
  63. package/dist/core/export-html/template.js +72 -0
  64. package/dist/core/export-html/tool-renderer.d.ts +33 -0
  65. package/dist/core/export-html/tool-renderer.js +1 -0
  66. package/dist/core/export-html/vendor/highlight.min.js +8 -0
  67. package/dist/core/export-html/vendor/marked.min.js +56 -0
  68. package/dist/core/extensions/index.d.ts +11 -0
  69. package/dist/core/extensions/index.js +1 -0
  70. package/dist/core/extensions/loader.d.ts +23 -0
  71. package/dist/core/extensions/loader.js +1 -0
  72. package/dist/core/extensions/runner.d.ts +160 -0
  73. package/dist/core/extensions/runner.js +1 -0
  74. package/dist/core/extensions/types.d.ts +1180 -0
  75. package/dist/core/extensions/types.js +1 -0
  76. package/dist/core/extensions/wrapper.d.ts +19 -0
  77. package/dist/core/extensions/wrapper.js +1 -0
  78. package/dist/core/footer-data-provider.d.ts +53 -0
  79. package/dist/core/footer-data-provider.js +1 -0
  80. package/dist/core/http-dispatcher.d.ts +20 -0
  81. package/dist/core/http-dispatcher.js +1 -0
  82. package/dist/core/index.d.ts +11 -0
  83. package/dist/core/index.js +1 -0
  84. package/dist/core/keybindings.d.ts +352 -0
  85. package/dist/core/keybindings.js +1 -0
  86. package/dist/core/messages.d.ts +76 -0
  87. package/dist/core/messages.js +17 -0
  88. package/dist/core/model-registry.d.ts +149 -0
  89. package/dist/core/model-registry.js +9 -0
  90. package/dist/core/model-resolver.d.ts +109 -0
  91. package/dist/core/model-resolver.js +1 -0
  92. package/dist/core/output-guard.d.ts +6 -0
  93. package/dist/core/output-guard.js +1 -0
  94. package/dist/core/package-manager.d.ts +203 -0
  95. package/dist/core/package-manager.js +3 -0
  96. package/dist/core/prompt-templates.d.ts +51 -0
  97. package/dist/core/prompt-templates.js +2 -0
  98. package/dist/core/provider-attribution.d.ts +3 -0
  99. package/dist/core/provider-attribution.js +1 -0
  100. package/dist/core/provider-display-names.d.ts +1 -0
  101. package/dist/core/provider-display-names.js +1 -0
  102. package/dist/core/resolve-config-value.d.ts +30 -0
  103. package/dist/core/resolve-config-value.js +1 -0
  104. package/dist/core/resource-loader.d.ts +193 -0
  105. package/dist/core/resource-loader.js +1 -0
  106. package/dist/core/sdk.d.ts +108 -0
  107. package/dist/core/sdk.js +1 -0
  108. package/dist/core/session-cwd.d.ts +18 -0
  109. package/dist/core/session-cwd.js +7 -0
  110. package/dist/core/session-manager.d.ts +331 -0
  111. package/dist/core/session-manager.js +11 -0
  112. package/dist/core/settings-manager.d.ts +265 -0
  113. package/dist/core/settings-manager.js +1 -0
  114. package/dist/core/skills.d.ts +59 -0
  115. package/dist/core/skills.js +4 -0
  116. package/dist/core/slash-commands.d.ts +13 -0
  117. package/dist/core/slash-commands.js +1 -0
  118. package/dist/core/source-info.d.ts +17 -0
  119. package/dist/core/source-info.js +1 -0
  120. package/dist/core/system-prompt.d.ts +27 -0
  121. package/dist/core/system-prompt.js +52 -0
  122. package/dist/core/telemetry.d.ts +2 -0
  123. package/dist/core/telemetry.js +1 -0
  124. package/dist/core/timings.d.ts +7 -0
  125. package/dist/core/timings.js +3 -0
  126. package/dist/core/tools/bash.d.ts +67 -0
  127. package/dist/core/tools/bash.js +18 -0
  128. package/dist/core/tools/edit-diff.d.ts +86 -0
  129. package/dist/core/tools/edit-diff.js +16 -0
  130. package/dist/core/tools/edit.d.ts +50 -0
  131. package/dist/core/tools/edit.js +2 -0
  132. package/dist/core/tools/file-mutation-queue.d.ts +5 -0
  133. package/dist/core/tools/file-mutation-queue.js +1 -0
  134. package/dist/core/tools/find.d.ts +34 -0
  135. package/dist/core/tools/find.js +13 -0
  136. package/dist/core/tools/grep.d.ts +36 -0
  137. package/dist/core/tools/grep.js +13 -0
  138. package/dist/core/tools/index.d.ts +39 -0
  139. package/dist/core/tools/index.js +1 -0
  140. package/dist/core/tools/ls.d.ts +36 -0
  141. package/dist/core/tools/ls.js +9 -0
  142. package/dist/core/tools/output-accumulator.d.ts +51 -0
  143. package/dist/core/tools/output-accumulator.js +4 -0
  144. package/dist/core/tools/path-utils.d.ts +9 -0
  145. package/dist/core/tools/path-utils.js +1 -0
  146. package/dist/core/tools/read.d.ts +34 -0
  147. package/dist/core/tools/read.js +22 -0
  148. package/dist/core/tools/render-utils.d.ts +23 -0
  149. package/dist/core/tools/render-utils.js +4 -0
  150. package/dist/core/tools/tool-definition-wrapper.d.ts +13 -0
  151. package/dist/core/tools/tool-definition-wrapper.js +1 -0
  152. package/dist/core/tools/truncate.d.ts +69 -0
  153. package/dist/core/tools/truncate.js +5 -0
  154. package/dist/core/tools/write.d.ts +25 -0
  155. package/dist/core/tools/write.js +13 -0
  156. package/dist/index.d.ts +30 -0
  157. package/dist/index.js +1 -0
  158. package/dist/main.d.ts +11 -0
  159. package/dist/main.js +1 -0
  160. package/dist/migrations.d.ts +32 -0
  161. package/dist/migrations.js +8 -0
  162. package/dist/modes/index.d.ts +8 -0
  163. package/dist/modes/index.js +1 -0
  164. package/dist/modes/interactive/assets/clankolas.png +0 -0
  165. package/dist/modes/interactive/components/armin.d.ts +33 -0
  166. package/dist/modes/interactive/components/armin.js +1 -0
  167. package/dist/modes/interactive/components/assistant-message.d.ts +19 -0
  168. package/dist/modes/interactive/components/assistant-message.js +1 -0
  169. package/dist/modes/interactive/components/bash-execution.d.ts +33 -0
  170. package/dist/modes/interactive/components/bash-execution.js +13 -0
  171. package/dist/modes/interactive/components/bordered-loader.d.ts +15 -0
  172. package/dist/modes/interactive/components/bordered-loader.js +1 -0
  173. package/dist/modes/interactive/components/branch-summary-message.d.ts +15 -0
  174. package/dist/modes/interactive/components/branch-summary-message.js +3 -0
  175. package/dist/modes/interactive/components/compaction-summary-message.d.ts +15 -0
  176. package/dist/modes/interactive/components/compaction-summary-message.js +3 -0
  177. package/dist/modes/interactive/components/config-selector.d.ts +70 -0
  178. package/dist/modes/interactive/components/config-selector.js +1 -0
  179. package/dist/modes/interactive/components/countdown-timer.d.ts +13 -0
  180. package/dist/modes/interactive/components/countdown-timer.js +1 -0
  181. package/dist/modes/interactive/components/custom-editor.d.ts +20 -0
  182. package/dist/modes/interactive/components/custom-editor.js +1 -0
  183. package/dist/modes/interactive/components/custom-message.d.ts +19 -0
  184. package/dist/modes/interactive/components/custom-message.js +2 -0
  185. package/dist/modes/interactive/components/daxnuts.d.ts +22 -0
  186. package/dist/modes/interactive/components/daxnuts.js +1 -0
  187. package/dist/modes/interactive/components/diff.d.ts +11 -0
  188. package/dist/modes/interactive/components/diff.js +3 -0
  189. package/dist/modes/interactive/components/dynamic-border.d.ts +14 -0
  190. package/dist/modes/interactive/components/dynamic-border.js +1 -0
  191. package/dist/modes/interactive/components/earendil-announcement.d.ts +4 -0
  192. package/dist/modes/interactive/components/earendil-announcement.js +1 -0
  193. package/dist/modes/interactive/components/extension-editor.d.ts +19 -0
  194. package/dist/modes/interactive/components/extension-editor.js +3 -0
  195. package/dist/modes/interactive/components/extension-input.d.ts +22 -0
  196. package/dist/modes/interactive/components/extension-input.js +2 -0
  197. package/dist/modes/interactive/components/extension-selector.d.ts +25 -0
  198. package/dist/modes/interactive/components/extension-selector.js +2 -0
  199. package/dist/modes/interactive/components/footer.d.ts +27 -0
  200. package/dist/modes/interactive/components/footer.js +1 -0
  201. package/dist/modes/interactive/components/index.d.ts +31 -0
  202. package/dist/modes/interactive/components/index.js +1 -0
  203. package/dist/modes/interactive/components/keybinding-hints.d.ts +12 -0
  204. package/dist/modes/interactive/components/keybinding-hints.js +1 -0
  205. package/dist/modes/interactive/components/login-dialog.d.ts +51 -0
  206. package/dist/modes/interactive/components/login-dialog.js +1 -0
  207. package/dist/modes/interactive/components/model-selector.d.ts +46 -0
  208. package/dist/modes/interactive/components/model-selector.js +2 -0
  209. package/dist/modes/interactive/components/oauth-selector.d.ts +30 -0
  210. package/dist/modes/interactive/components/oauth-selector.js +1 -0
  211. package/dist/modes/interactive/components/scoped-models-selector.d.ts +41 -0
  212. package/dist/modes/interactive/components/scoped-models-selector.js +1 -0
  213. package/dist/modes/interactive/components/session-selector-search.d.ts +22 -0
  214. package/dist/modes/interactive/components/session-selector-search.js +1 -0
  215. package/dist/modes/interactive/components/session-selector.d.ts +95 -0
  216. package/dist/modes/interactive/components/session-selector.js +2 -0
  217. package/dist/modes/interactive/components/settings-selector.d.ts +68 -0
  218. package/dist/modes/interactive/components/settings-selector.js +1 -0
  219. package/dist/modes/interactive/components/show-images-selector.d.ts +9 -0
  220. package/dist/modes/interactive/components/show-images-selector.js +1 -0
  221. package/dist/modes/interactive/components/skill-invocation-message.d.ts +16 -0
  222. package/dist/modes/interactive/components/skill-invocation-message.js +3 -0
  223. package/dist/modes/interactive/components/theme-selector.d.ts +10 -0
  224. package/dist/modes/interactive/components/theme-selector.js +1 -0
  225. package/dist/modes/interactive/components/thinking-selector.d.ts +10 -0
  226. package/dist/modes/interactive/components/thinking-selector.js +1 -0
  227. package/dist/modes/interactive/components/tool-execution.d.ts +62 -0
  228. package/dist/modes/interactive/components/tool-execution.js +4 -0
  229. package/dist/modes/interactive/components/tree-selector.d.ts +88 -0
  230. package/dist/modes/interactive/components/tree-selector.js +1 -0
  231. package/dist/modes/interactive/components/user-message-selector.d.ts +29 -0
  232. package/dist/modes/interactive/components/user-message-selector.js +1 -0
  233. package/dist/modes/interactive/components/user-message.d.ts +9 -0
  234. package/dist/modes/interactive/components/user-message.js +1 -0
  235. package/dist/modes/interactive/components/visual-truncate.d.ts +23 -0
  236. package/dist/modes/interactive/components/visual-truncate.js +1 -0
  237. package/dist/modes/interactive/interactive-mode.d.ts +417 -0
  238. package/dist/modes/interactive/interactive-mode.js +116 -0
  239. package/dist/modes/interactive/theme/dark.json +86 -0
  240. package/dist/modes/interactive/theme/light.json +85 -0
  241. package/dist/modes/interactive/theme/theme-schema.json +335 -0
  242. package/dist/modes/interactive/theme/theme.d.ts +101 -0
  243. package/dist/modes/interactive/theme/theme.js +18 -0
  244. package/dist/modes/print-mode.d.ts +27 -0
  245. package/dist/modes/print-mode.js +4 -0
  246. package/dist/modes/rpc/jsonl.d.ts +16 -0
  247. package/dist/modes/rpc/jsonl.js +3 -0
  248. package/dist/modes/rpc/rpc-client.d.ts +226 -0
  249. package/dist/modes/rpc/rpc-client.js +1 -0
  250. package/dist/modes/rpc/rpc-mode.d.ts +19 -0
  251. package/dist/modes/rpc/rpc-mode.js +1 -0
  252. package/dist/modes/rpc/rpc-types.d.ts +419 -0
  253. package/dist/modes/rpc/rpc-types.js +0 -0
  254. package/dist/package-manager-cli.d.ts +3 -0
  255. package/dist/package-manager-cli.js +49 -0
  256. package/dist/utils/ansi.d.ts +1 -0
  257. package/dist/utils/ansi.js +1 -0
  258. package/dist/utils/auto-update.d.ts +13 -0
  259. package/dist/utils/auto-update.js +1 -0
  260. package/dist/utils/changelog.d.ts +20 -0
  261. package/dist/utils/changelog.js +4 -0
  262. package/dist/utils/child-process.d.ts +14 -0
  263. package/dist/utils/child-process.js +1 -0
  264. package/dist/utils/clipboard-image.d.ts +10 -0
  265. package/dist/utils/clipboard-image.js +1 -0
  266. package/dist/utils/clipboard-native.d.ts +9 -0
  267. package/dist/utils/clipboard-native.js +1 -0
  268. package/dist/utils/clipboard.d.ts +1 -0
  269. package/dist/utils/clipboard.js +1 -0
  270. package/dist/utils/deprecation.d.ts +3 -0
  271. package/dist/utils/deprecation.js +1 -0
  272. package/dist/utils/exif-orientation.d.ts +4 -0
  273. package/dist/utils/exif-orientation.js +1 -0
  274. package/dist/utils/frontmatter.d.ts +7 -0
  275. package/dist/utils/frontmatter.js +4 -0
  276. package/dist/utils/fs-watch.d.ts +4 -0
  277. package/dist/utils/fs-watch.js +1 -0
  278. package/dist/utils/git.d.ts +25 -0
  279. package/dist/utils/git.js +1 -0
  280. package/dist/utils/html.d.ts +6 -0
  281. package/dist/utils/html.js +1 -0
  282. package/dist/utils/image-convert.d.ts +8 -0
  283. package/dist/utils/image-convert.js +1 -0
  284. package/dist/utils/image-resize-core.d.ts +29 -0
  285. package/dist/utils/image-resize-core.js +1 -0
  286. package/dist/utils/image-resize-worker.d.ts +1 -0
  287. package/dist/utils/image-resize-worker.js +1 -0
  288. package/dist/utils/image-resize.d.ts +15 -0
  289. package/dist/utils/image-resize.js +1 -0
  290. package/dist/utils/json.d.ts +2 -0
  291. package/dist/utils/json.js +1 -0
  292. package/dist/utils/koda-user-agent.d.ts +1 -0
  293. package/dist/utils/koda-user-agent.js +1 -0
  294. package/dist/utils/mime.d.ts +2 -0
  295. package/dist/utils/mime.js +1 -0
  296. package/dist/utils/paths.d.ts +30 -0
  297. package/dist/utils/paths.js +1 -0
  298. package/dist/utils/photon.d.ts +20 -0
  299. package/dist/utils/photon.js +1 -0
  300. package/dist/utils/shell.d.ts +29 -0
  301. package/dist/utils/shell.js +8 -0
  302. package/dist/utils/sleep.d.ts +4 -0
  303. package/dist/utils/sleep.js +1 -0
  304. package/dist/utils/syntax-highlight.d.ts +11 -0
  305. package/dist/utils/syntax-highlight.js +2 -0
  306. package/dist/utils/tools-manager.d.ts +2 -0
  307. package/dist/utils/tools-manager.js +1 -0
  308. package/dist/utils/version-check.d.ts +14 -0
  309. package/dist/utils/version-check.js +1 -0
  310. package/dist/utils/windows-self-update.d.ts +2 -0
  311. package/dist/utils/windows-self-update.js +1 -0
  312. package/docs/compaction.md +394 -0
  313. package/docs/custom-provider.md +736 -0
  314. package/docs/development.md +71 -0
  315. package/docs/docs.json +148 -0
  316. package/docs/extensions.md +2626 -0
  317. package/docs/images/doom-extension.png +0 -0
  318. package/docs/images/exy.png +0 -0
  319. package/docs/images/interactive-mode.png +0 -0
  320. package/docs/images/tree-view.png +0 -0
  321. package/docs/index.md +80 -0
  322. package/docs/json.md +82 -0
  323. package/docs/keybindings.md +197 -0
  324. package/docs/models.md +493 -0
  325. package/docs/packages.md +226 -0
  326. package/docs/prompt-templates.md +88 -0
  327. package/docs/providers.md +253 -0
  328. package/docs/quickstart.md +165 -0
  329. package/docs/rpc.md +1408 -0
  330. package/docs/sdk.md +1137 -0
  331. package/docs/session-format.md +412 -0
  332. package/docs/sessions.md +145 -0
  333. package/docs/settings.md +281 -0
  334. package/docs/shell-aliases.md +13 -0
  335. package/docs/skills.md +231 -0
  336. package/docs/terminal-setup.md +114 -0
  337. package/docs/termux.md +127 -0
  338. package/docs/themes.md +295 -0
  339. package/docs/tmux.md +61 -0
  340. package/docs/tui.md +927 -0
  341. package/docs/usage.md +288 -0
  342. package/docs/windows.md +17 -0
  343. package/npm-shrinkwrap.json +1792 -0
  344. package/openadapter/extensions/koda-ask.js +12 -0
  345. package/openadapter/extensions/koda-bg.js +14 -0
  346. package/openadapter/extensions/koda-commands.mjs +15 -0
  347. package/openadapter/extensions/koda-help.js +8 -0
  348. package/openadapter/extensions/koda-memory.js +16 -0
  349. package/openadapter/extensions/koda-status.js +1 -0
  350. package/openadapter/extensions/koda-todo.js +4 -0
  351. package/openadapter/extensions/koda-vision.js +4 -0
  352. package/openadapter/extensions/koda-web.js +7 -0
  353. package/openadapter/setup.mjs +173 -0
  354. package/openadapter/skills/code-review/SKILL.md +22 -0
  355. package/openadapter/skills/debugging/SKILL.md +28 -0
  356. package/openadapter/skills/frontend/SKILL.md +38 -0
  357. package/package.json +108 -0
@@ -0,0 +1,747 @@
1
+ /**
2
+ * AgentSession - Core abstraction for agent lifecycle and session management.
3
+ *
4
+ * This class is shared between all run modes (interactive, print, rpc).
5
+ * It encapsulates:
6
+ * - Agent state access
7
+ * - Event subscription with automatic session persistence
8
+ * - Model and thinking level management
9
+ * - Compaction (manual and auto)
10
+ * - Bash execution
11
+ * - Session switching and branching
12
+ *
13
+ * Modes use this class and add their own I/O layer on top.
14
+ */
15
+ import type { Agent, AgentEvent, AgentMessage, AgentState, AgentTool, ThinkingLevel } from "@openadapter/koda-agent-core";
16
+ import type { ImageContent, Model, TextContent } from "@openadapter/koda-ai";
17
+ import { type BashResult } from "./bash-executor.ts";
18
+ import { type CompactionResult } from "./compaction/index.ts";
19
+ import { type ContextUsage, type ExtensionCommandContextActions, type ExtensionErrorListener, type ExtensionMode, ExtensionRunner, type ExtensionUIContext, type InputSource, type ReplacedSessionContext, type SessionStartEvent, type ShutdownHandler, type ToolDefinition, type ToolInfo } from "./extensions/index.ts";
20
+ import type { CustomMessage } from "./messages.ts";
21
+ import type { ModelRegistry } from "./model-registry.ts";
22
+ import { type PromptTemplate } from "./prompt-templates.ts";
23
+ import type { ResourceLoader } from "./resource-loader.ts";
24
+ import type { BranchSummaryEntry, SessionManager } from "./session-manager.ts";
25
+ import type { SettingsManager } from "./settings-manager.ts";
26
+ import { type BashOperations } from "./tools/bash.ts";
27
+ /** Parsed skill block from a user message */
28
+ export interface ParsedSkillBlock {
29
+ name: string;
30
+ location: string;
31
+ content: string;
32
+ userMessage: string | undefined;
33
+ }
34
+ /**
35
+ * Parse a skill block from message text.
36
+ * Returns null if the text doesn't contain a skill block.
37
+ */
38
+ export declare function parseSkillBlock(text: string): ParsedSkillBlock | null;
39
+ /** Session-specific events that extend the core AgentEvent */
40
+ export type AgentSessionEvent = Exclude<AgentEvent, {
41
+ type: "agent_end";
42
+ }> | {
43
+ type: "agent_end";
44
+ messages: AgentMessage[];
45
+ willRetry: boolean;
46
+ } | {
47
+ type: "queue_update";
48
+ steering: readonly string[];
49
+ followUp: readonly string[];
50
+ } | {
51
+ type: "compaction_start";
52
+ reason: "manual" | "threshold" | "overflow";
53
+ } | {
54
+ type: "session_info_changed";
55
+ name: string | undefined;
56
+ } | {
57
+ type: "thinking_level_changed";
58
+ level: ThinkingLevel;
59
+ } | {
60
+ type: "compaction_end";
61
+ reason: "manual" | "threshold" | "overflow";
62
+ result: CompactionResult | undefined;
63
+ aborted: boolean;
64
+ willRetry: boolean;
65
+ errorMessage?: string;
66
+ } | {
67
+ type: "auto_retry_start";
68
+ attempt: number;
69
+ maxAttempts: number;
70
+ delayMs: number;
71
+ errorMessage: string;
72
+ } | {
73
+ type: "auto_retry_end";
74
+ success: boolean;
75
+ attempt: number;
76
+ finalError?: string;
77
+ } | {
78
+ type: "overseer_start";
79
+ model: string;
80
+ } | {
81
+ type: "overseer_end";
82
+ outcome: "complete" | "nudging" | "skipped";
83
+ detail?: string;
84
+ } | {
85
+ type: "model_switch_notice";
86
+ message: string;
87
+ } | {
88
+ type: "goal_set";
89
+ text: string;
90
+ milestones: {
91
+ text: string;
92
+ done: boolean;
93
+ }[];
94
+ } | {
95
+ type: "goal_progress";
96
+ text: string;
97
+ milestones: {
98
+ text: string;
99
+ done: boolean;
100
+ }[];
101
+ achieved: boolean;
102
+ drift?: string;
103
+ } | {
104
+ type: "goal_cleared";
105
+ } | {
106
+ type: "task_recap";
107
+ elapsedMs: number;
108
+ recap: string;
109
+ } | {
110
+ type: "suggest_feature";
111
+ id: string;
112
+ message: string;
113
+ };
114
+ /** Listener function for agent session events */
115
+ export type AgentSessionEventListener = (event: AgentSessionEvent) => void;
116
+ export interface AgentSessionConfig {
117
+ agent: Agent;
118
+ sessionManager: SessionManager;
119
+ settingsManager: SettingsManager;
120
+ cwd: string;
121
+ /** Models to cycle through with Ctrl+P (from --models flag) */
122
+ scopedModels?: Array<{
123
+ model: Model<any>;
124
+ thinkingLevel?: ThinkingLevel;
125
+ }>;
126
+ /** Resource loader for skills, prompts, themes, context files, system prompt */
127
+ resourceLoader: ResourceLoader;
128
+ /** SDK custom tools registered outside extensions */
129
+ customTools?: ToolDefinition[];
130
+ /** Model registry for API key resolution and model discovery */
131
+ modelRegistry: ModelRegistry;
132
+ /** Initial active built-in tool names. Default: [read, bash, edit, write] */
133
+ initialActiveToolNames?: string[];
134
+ /** Optional allowlist of tool names. When provided, only these tool names are exposed. */
135
+ allowedToolNames?: string[];
136
+ /** Optional denylist of tool names. When provided, these tool names are not exposed. */
137
+ excludedToolNames?: string[];
138
+ /**
139
+ * Override base tools (useful for custom runtimes).
140
+ *
141
+ * These are synthesized into minimal ToolDefinitions internally so AgentSession can keep
142
+ * a definition-first registry even when callers provide plain AgentTool instances.
143
+ */
144
+ baseToolsOverride?: Record<string, AgentTool>;
145
+ /** Mutable ref used by Agent to access the current ExtensionRunner */
146
+ extensionRunnerRef?: {
147
+ current?: ExtensionRunner;
148
+ };
149
+ /** Session start event metadata emitted when extensions bind to this runtime. */
150
+ sessionStartEvent?: SessionStartEvent;
151
+ }
152
+ export interface ExtensionBindings {
153
+ uiContext?: ExtensionUIContext;
154
+ mode?: ExtensionMode;
155
+ commandContextActions?: ExtensionCommandContextActions;
156
+ abortHandler?: () => void;
157
+ shutdownHandler?: ShutdownHandler;
158
+ onError?: ExtensionErrorListener;
159
+ }
160
+ /** Options for AgentSession.prompt() */
161
+ export interface PromptOptions {
162
+ /** Whether to expand file-based prompt templates (default: true) */
163
+ expandPromptTemplates?: boolean;
164
+ /** Image attachments */
165
+ images?: ImageContent[];
166
+ /** When streaming, how to queue the message: "steer" (interrupt) or "followUp" (wait). Required if streaming. */
167
+ streamingBehavior?: "steer" | "followUp";
168
+ /** Source of input for extension input event handlers. Defaults to "interactive". */
169
+ source?: InputSource;
170
+ /** Internal hook used by RPC mode to observe prompt preflight acceptance or rejection. */
171
+ preflightResult?: (success: boolean) => void;
172
+ }
173
+ /** Result from cycleModel() */
174
+ export interface ModelCycleResult {
175
+ model: Model<any>;
176
+ thinkingLevel: ThinkingLevel;
177
+ /** Whether cycling through scoped models (--models flag) or all available */
178
+ isScoped: boolean;
179
+ }
180
+ /** Session statistics for /session command */
181
+ export interface SessionStats {
182
+ sessionFile: string | undefined;
183
+ sessionId: string;
184
+ userMessages: number;
185
+ assistantMessages: number;
186
+ toolCalls: number;
187
+ toolResults: number;
188
+ totalMessages: number;
189
+ tokens: {
190
+ input: number;
191
+ output: number;
192
+ cacheRead: number;
193
+ cacheWrite: number;
194
+ total: number;
195
+ };
196
+ cost: number;
197
+ contextUsage?: ContextUsage;
198
+ }
199
+ export declare class AgentSession {
200
+ readonly agent: Agent;
201
+ readonly sessionManager: SessionManager;
202
+ readonly settingsManager: SettingsManager;
203
+ private _scopedModels;
204
+ private _unsubscribeAgent?;
205
+ private _eventListeners;
206
+ /** Tracks pending steering messages for UI display. Removed when delivered. */
207
+ private _steeringMessages;
208
+ /** Tracks pending follow-up messages for UI display. Removed when delivered. */
209
+ private _followUpMessages;
210
+ /** Messages queued to be included with the next user prompt as context ("asides"). */
211
+ private _pendingNextTurnMessages;
212
+ private _compactionAbortController;
213
+ private _autoCompactionAbortController;
214
+ private _overflowRecoveryAttempted;
215
+ private _branchSummaryAbortController;
216
+ private _retryAbortController;
217
+ private _retryAttempt;
218
+ private _overseerAbortController;
219
+ private _failoverTried;
220
+ private get _zenitsu();
221
+ private _zenitsuPreferred;
222
+ private _zenitsuCooldown;
223
+ private _zenitsuHealthCache;
224
+ private _overseerRounds;
225
+ private _currentGoal;
226
+ private _tierCache;
227
+ private _overseerLastError;
228
+ private _escalationsDone;
229
+ private _escalateTried;
230
+ private _sessionEscalations;
231
+ private _stickyModel;
232
+ private _homeModel;
233
+ private _sessionGoal;
234
+ private _pinnedSkills;
235
+ private _codeChangedThisTask;
236
+ private _verifyCmd;
237
+ private _taskStartTs;
238
+ private _taskHadActivity;
239
+ private _suggestShown;
240
+ private _suggestedThisTask;
241
+ private _harnessTrace;
242
+ private _gatewayCircuit;
243
+ private _bashAbortController;
244
+ private _pendingBashMessages;
245
+ private _extensionRunner;
246
+ private _turnIndex;
247
+ private _resourceLoader;
248
+ private _customTools;
249
+ private _baseToolDefinitions;
250
+ private _cwd;
251
+ private _protectedSnap;
252
+ private _extensionRunnerRef?;
253
+ private _initialActiveToolNames?;
254
+ private _allowedToolNames?;
255
+ private _excludedToolNames?;
256
+ private _baseToolsOverride?;
257
+ private _sessionStartEvent;
258
+ private _extensionUIContext?;
259
+ private _extensionMode;
260
+ private _extensionCommandContextActions?;
261
+ private _extensionAbortHandler?;
262
+ private _extensionShutdownHandler?;
263
+ private _extensionErrorListener?;
264
+ private _extensionErrorUnsubscriber?;
265
+ private _modelRegistry;
266
+ private _toolRegistry;
267
+ private _toolDefinitions;
268
+ private _toolPromptSnippets;
269
+ private _toolPromptGuidelines;
270
+ private _baseSystemPrompt;
271
+ private _baseSystemPromptOptions;
272
+ constructor(config: AgentSessionConfig);
273
+ /** Model registry for API key resolution and model discovery */
274
+ get modelRegistry(): ModelRegistry;
275
+ private _getRequiredRequestAuth;
276
+ private _getCompactionRequestAuth;
277
+ /**
278
+ * Install tool hooks once on the Agent instance.
279
+ *
280
+ * The callbacks read `this._extensionRunner` at execution time, so extension reload swaps in the
281
+ * new runner without reinstalling hooks. Extension-specific tool wrappers are still used to adapt
282
+ * registered tool execution to the extension context. Tool call and tool result interception now
283
+ * happens here instead of in wrappers.
284
+ */
285
+ private _installAgentToolHooks;
286
+ /** Emit an event to all listeners */
287
+ private _emit;
288
+ private _emitQueueUpdate;
289
+ private _lastAssistantMessage;
290
+ /** Internal handler for agent events - shared by subscribe and reconnect */
291
+ private _handleAgentEvent;
292
+ private _willRetryAfterAgentEnd;
293
+ /** Extract text content from a message */
294
+ private _getUserMessageText;
295
+ /** Find the last assistant message in agent state (including aborted ones) */
296
+ private _findLastAssistantMessage;
297
+ private _replaceMessageInPlace;
298
+ private _emitExtensionEvent;
299
+ /**
300
+ * Subscribe to agent events.
301
+ * Session persistence is handled internally (saves messages on message_end).
302
+ * Multiple listeners can be added. Returns unsubscribe function for this listener.
303
+ */
304
+ subscribe(listener: AgentSessionEventListener): () => void;
305
+ /**
306
+ * Temporarily disconnect from agent events.
307
+ * User listeners are preserved and will receive events again after resubscribe().
308
+ * Used internally during operations that need to pause event processing.
309
+ */
310
+ private _disconnectFromAgent;
311
+ /**
312
+ * Reconnect to agent events after _disconnectFromAgent().
313
+ * Preserves all existing listeners.
314
+ */
315
+ private _reconnectToAgent;
316
+ /**
317
+ * Remove all listeners and disconnect from agent.
318
+ * Call this when completely done with the session.
319
+ */
320
+ dispose(): void;
321
+ /** Full agent state */
322
+ get state(): AgentState;
323
+ /** Current model (may be undefined if not yet selected) */
324
+ get model(): Model<any> | undefined;
325
+ /** Current thinking level */
326
+ get thinkingLevel(): ThinkingLevel;
327
+ /** Whether agent is currently streaming a response */
328
+ get isStreaming(): boolean;
329
+ /** Current effective system prompt (includes any per-turn extension modifications) */
330
+ get systemPrompt(): string;
331
+ /** Current retry attempt (0 if not retrying) */
332
+ get retryAttempt(): number;
333
+ /**
334
+ * Get the names of currently active tools.
335
+ * Returns the names of tools currently set on the agent.
336
+ */
337
+ getActiveToolNames(): string[];
338
+ /**
339
+ * Get all configured tools with name, description, parameter schema, prompt guidelines, and source metadata.
340
+ */
341
+ getAllTools(): ToolInfo[];
342
+ getToolDefinition(name: string): ToolDefinition | undefined;
343
+ /**
344
+ * Set active tools by name.
345
+ * Only tools in the registry can be enabled. Unknown tool names are ignored.
346
+ * Also rebuilds the system prompt to reflect the new tool set.
347
+ * Changes take effect on the next agent turn.
348
+ */
349
+ setActiveToolsByName(toolNames: string[]): void;
350
+ /** Whether compaction or branch summarization is currently running */
351
+ get isCompacting(): boolean;
352
+ /** All messages including custom types like BashExecutionMessage */
353
+ get messages(): AgentMessage[];
354
+ /** Current steering mode */
355
+ get steeringMode(): "all" | "one-at-a-time";
356
+ /** Current follow-up mode */
357
+ get followUpMode(): "all" | "one-at-a-time";
358
+ /** Current session file path, or undefined if sessions are disabled */
359
+ get sessionFile(): string | undefined;
360
+ /** Current session ID */
361
+ get sessionId(): string;
362
+ /** Current session display name, if set */
363
+ get sessionName(): string | undefined;
364
+ /** Scoped models for cycling (from --models flag) */
365
+ get scopedModels(): ReadonlyArray<{
366
+ model: Model<any>;
367
+ thinkingLevel?: ThinkingLevel;
368
+ }>;
369
+ /** Update scoped models for cycling */
370
+ setScopedModels(scopedModels: Array<{
371
+ model: Model<any>;
372
+ thinkingLevel?: ThinkingLevel;
373
+ }>): void;
374
+ /** File-based prompt templates */
375
+ get promptTemplates(): ReadonlyArray<PromptTemplate>;
376
+ private _normalizePromptSnippet;
377
+ private _normalizePromptGuidelines;
378
+ private _rebuildSystemPrompt;
379
+ private _runAgentPrompt;
380
+ private _generateRecap;
381
+ private _recapOnce;
382
+ private _handlePostAgentRun;
383
+ /**
384
+ * Send a prompt to the agent.
385
+ * - Handles extension commands (registered via pi.registerCommand) immediately, even during streaming
386
+ * - Expands file-based prompt templates by default
387
+ * - During streaming, queues via steer() or followUp() based on streamingBehavior option
388
+ * - Validates model and API key before sending (when not streaming)
389
+ * @throws Error if streaming and no streamingBehavior specified
390
+ * @throws Error if no model selected or no API key available (when not streaming)
391
+ */
392
+ prompt(text: string, options?: PromptOptions): Promise<void>;
393
+ private _tryExecuteExtensionCommand;
394
+ /**
395
+ * Expand skill commands (/skill:name args) to their full content.
396
+ * Returns the expanded text, or the original text if not a skill command or skill not found.
397
+ * Emits errors via extension runner if file read fails.
398
+ */
399
+ private _expandSkillCommand;
400
+ /**
401
+ * Queue a steering message while the agent is running.
402
+ * Delivered after the current assistant turn finishes executing its tool calls,
403
+ * before the next LLM call.
404
+ * Expands skill commands and prompt templates. Errors on extension commands.
405
+ * @param images Optional image attachments to include with the message
406
+ * @throws Error if text is an extension command
407
+ */
408
+ steer(text: string, images?: ImageContent[]): Promise<void>;
409
+ /**
410
+ * Queue a follow-up message to be processed after the agent finishes.
411
+ * Delivered only when agent has no more tool calls or steering messages.
412
+ * Expands skill commands and prompt templates. Errors on extension commands.
413
+ * @param images Optional image attachments to include with the message
414
+ * @throws Error if text is an extension command
415
+ */
416
+ followUp(text: string, images?: ImageContent[]): Promise<void>;
417
+ private _queueSteer;
418
+ private _queueFollowUp;
419
+ /**
420
+ * Throw an error if the text is an extension command.
421
+ */
422
+ private _throwIfExtensionCommand;
423
+ /**
424
+ * Send a custom message to the session. Creates a CustomMessageEntry.
425
+ *
426
+ * Handles three cases:
427
+ * - Streaming: queues message, processed when loop pulls from queue
428
+ * - Not streaming + triggerTurn: appends to state/session, starts new turn
429
+ * - Not streaming + no trigger: appends to state/session, no turn
430
+ *
431
+ * @param message Custom message with customType, content, display, details
432
+ * @param options.triggerTurn If true and not streaming, triggers a new LLM turn
433
+ * @param options.deliverAs Delivery mode: "steer", "followUp", or "nextTurn"
434
+ */
435
+ sendCustomMessage<T = unknown>(message: Pick<CustomMessage<T>, "customType" | "content" | "display" | "details">, options?: {
436
+ triggerTurn?: boolean;
437
+ deliverAs?: "steer" | "followUp" | "nextTurn";
438
+ }): Promise<void>;
439
+ /**
440
+ * Send a user message to the agent. Always triggers a turn.
441
+ * When the agent is streaming, use deliverAs to specify how to queue the message.
442
+ *
443
+ * @param content User message content (string or content array)
444
+ * @param options.deliverAs Delivery mode when streaming: "steer" or "followUp"
445
+ */
446
+ sendUserMessage(content: string | (TextContent | ImageContent)[], options?: {
447
+ deliverAs?: "steer" | "followUp";
448
+ }): Promise<void>;
449
+ /**
450
+ * Clear all queued messages and return them.
451
+ * Useful for restoring to editor when user aborts.
452
+ * @returns Object with steering and followUp arrays
453
+ */
454
+ clearQueue(): {
455
+ steering: string[];
456
+ followUp: string[];
457
+ };
458
+ /** Number of pending messages (includes both steering and follow-up) */
459
+ get pendingMessageCount(): number;
460
+ /** Get pending steering messages (read-only) */
461
+ getSteeringMessages(): readonly string[];
462
+ /** Get pending follow-up messages (read-only) */
463
+ getFollowUpMessages(): readonly string[];
464
+ get resourceLoader(): ResourceLoader;
465
+ /**
466
+ * Abort current operation and wait for agent to become idle.
467
+ */
468
+ abort(): Promise<void>;
469
+ private _emitModelSelect;
470
+ /**
471
+ * Set model directly.
472
+ * Validates that auth is configured, saves to session and settings.
473
+ * @throws Error if no auth is configured for the model
474
+ */
475
+ setModel(model: Model<any>): Promise<void>;
476
+ /**
477
+ * Cycle to next/previous model.
478
+ * Uses scoped models (from --models flag) if available, otherwise all available models.
479
+ * @param direction - "forward" (default) or "backward"
480
+ * @returns The new model info, or undefined if only one model available
481
+ */
482
+ cycleModel(direction?: "forward" | "backward"): Promise<ModelCycleResult | undefined>;
483
+ private _cycleScopedModel;
484
+ private _cycleAvailableModel;
485
+ /**
486
+ * Set thinking level.
487
+ * Clamps to model capabilities based on available thinking levels.
488
+ * Saves to session and settings only if the level actually changes.
489
+ */
490
+ setThinkingLevel(level: ThinkingLevel): void;
491
+ /**
492
+ * Cycle to next thinking level.
493
+ * @returns New level, or undefined if model doesn't support thinking
494
+ */
495
+ cycleThinkingLevel(): ThinkingLevel | undefined;
496
+ /**
497
+ * Get available thinking levels for current model.
498
+ * The provider will clamp to what the specific model supports internally.
499
+ */
500
+ getAvailableThinkingLevels(): ThinkingLevel[];
501
+ /**
502
+ * Check if current model supports thinking/reasoning.
503
+ */
504
+ supportsThinking(): boolean;
505
+ private _getThinkingLevelForModelSwitch;
506
+ private _clampThinkingLevel;
507
+ /**
508
+ * Set steering message mode.
509
+ * Saves to settings.
510
+ */
511
+ setSteeringMode(mode: "all" | "one-at-a-time"): void;
512
+ /**
513
+ * Set follow-up message mode.
514
+ * Saves to settings.
515
+ */
516
+ setFollowUpMode(mode: "all" | "one-at-a-time"): void;
517
+ /**
518
+ * Manually compact the session context.
519
+ * Aborts current agent operation first.
520
+ * @param customInstructions Optional instructions for the compaction summary
521
+ */
522
+ compact(customInstructions?: string): Promise<CompactionResult>;
523
+ /**
524
+ * Cancel in-progress compaction (manual or auto).
525
+ */
526
+ abortCompaction(): void;
527
+ /**
528
+ * Cancel in-progress branch summarization.
529
+ */
530
+ abortBranchSummary(): void;
531
+ /** Cancel an in-progress overseer review (the "reviewing…" phase). */
532
+ abortOverseer(): void;
533
+ private _checkCompaction;
534
+ private _runAutoCompaction;
535
+ /**
536
+ * Toggle auto-compaction setting.
537
+ */
538
+ setAutoCompactionEnabled(enabled: boolean): void;
539
+ /** Whether auto-compaction is enabled */
540
+ get autoCompactionEnabled(): boolean;
541
+ bindExtensions(bindings: ExtensionBindings): Promise<void>;
542
+ private extendResourcesFromExtensions;
543
+ private buildExtensionResourcePaths;
544
+ private getExtensionSourceLabel;
545
+ private _applyExtensionBindings;
546
+ private _refreshCurrentModelFromRegistry;
547
+ private _bindExtensionCore;
548
+ private _refreshToolRegistry;
549
+ private _buildRuntime;
550
+ reload(): Promise<void>;
551
+ private _isNonRetryableProviderLimitError;
552
+ /**
553
+ * Check if an error is retryable (overloaded, rate limit, server errors).
554
+ * Context overflow errors are NOT retryable (handled by compaction instead).
555
+ */
556
+ /** True when an assistant turn failed specifically due to rate limiting. */
557
+ private _isRateLimited;
558
+ /**
559
+ * Contextual feature discovery: surface the right feature the moment it would
560
+ * help. Each tip shows at most once per session, and at most one tip fires per
561
+ * task — so it's a helpful nudge, never spam. Adding a tip = one `_suggest` call.
562
+ */
563
+ private _suggest;
564
+ private _isRetryableError;
565
+ private _prepareRetry;
566
+ private _failoverModel;
567
+ private _fetchModelHealth;
568
+ private _zenitsuGetHealth;
569
+ private _zenitsuPickModel;
570
+ /** Extract readable text from a message's content (string or text blocks). */
571
+ private _messageText;
572
+ /** The user's request for the current task (latest user message). */
573
+ private _goalFromMessages;
574
+ /** A compact log of what was actually done this task (for the judge to ground on). */
575
+ private _overseerContext;
576
+ private _getModelTier;
577
+ /** Detect degenerate output (repetition collapse) — "poison" to strip from context. */
578
+ private _isDegenerateOutput;
579
+ private _escalate;
580
+ /** Names of available skills (for the /use selector). */
581
+ listSkillNames(): string[];
582
+ getPinnedSkills(): string[];
583
+ /**
584
+ * Pin a skill: inject its instructions into the system prompt for the rest of
585
+ * the session, so it's active every turn. Takes effect next turn; never calls
586
+ * the model. Returns false if the skill name is unknown.
587
+ */
588
+ pinSkill(name: string): boolean;
589
+ unpinSkill(name: string): boolean;
590
+ /** Rebuild the system prompt in place (no model call) so pinned-skill changes apply next turn. */
591
+ private _refreshSystemPrompt;
592
+ getSessionGoal(): {
593
+ text: string;
594
+ milestones: {
595
+ text: string;
596
+ done: boolean;
597
+ }[];
598
+ achieved: boolean;
599
+ } | undefined;
600
+ clearSessionGoal(): void;
601
+ /** Set the session goal; a capable model breaks it into milestones. */
602
+ setSessionGoal(text: string): Promise<void>;
603
+ private _generateMilestones;
604
+ /** Record a harness decision (for /trace and debugging). */
605
+ private _trace;
606
+ getHarnessTrace(): Array<{
607
+ ts: number;
608
+ kind: string;
609
+ detail: string;
610
+ }>;
611
+ /** Gateway circuit breaker — skip calls while the gateway is failing repeatedly. */
612
+ private _gatewayOpen;
613
+ private _gatewayResult;
614
+ /** Detect the project's verify command (cached). KODA_VERIFY overrides; "0" disables. */
615
+ private _detectVerify;
616
+ private _runVerification;
617
+ private _overseerCheck;
618
+ private _taskEndReview;
619
+ private _reviewOnce;
620
+ /**
621
+ * Heuristic: does a bash command change state (vs. read-only investigation)?
622
+ * Used by plan mode to allow inspection but block mutations. Errs toward
623
+ * blocking writes; redirects to /dev/null and fd-dups (2>&1) are allowed.
624
+ */
625
+ private _isMutatingBash;
626
+ /** Parse a retry-after hint (seconds) from a provider error message. */
627
+ private _parseRetrySeconds;
628
+ private _zenitsuHandle429;
629
+ /**
630
+ * Return to the user's preferred (floor) model as soon as it's available again.
631
+ * Zenitsu reroutes are temporary; the instant the preferred model is off cooldown,
632
+ * snap back. Called after every clean turn so we never ride a fallback longer than
633
+ * needed — this is what the user actually wants. Returns true if it switched.
634
+ */
635
+ private _maybeReturnHome;
636
+ /**
637
+ * Cancel in-progress retry.
638
+ */
639
+ abortRetry(): void;
640
+ /** Whether auto-retry is currently in progress */
641
+ get isRetrying(): boolean;
642
+ /** Whether auto-retry is enabled */
643
+ get autoRetryEnabled(): boolean;
644
+ /**
645
+ * Toggle auto-retry setting.
646
+ */
647
+ setAutoRetryEnabled(enabled: boolean): void;
648
+ /**
649
+ * Execute a bash command.
650
+ * Adds result to agent context and session.
651
+ * @param command The bash command to execute
652
+ * @param onChunk Optional streaming callback for output
653
+ * @param options.excludeFromContext If true, command output won't be sent to LLM (!! prefix)
654
+ * @param options.operations Custom BashOperations for remote execution
655
+ */
656
+ executeBash(command: string, onChunk?: (chunk: string) => void, options?: {
657
+ excludeFromContext?: boolean;
658
+ operations?: BashOperations;
659
+ }): Promise<BashResult>;
660
+ /**
661
+ * Record a bash execution result in session history.
662
+ * Used by executeBash and by extensions that handle bash execution themselves.
663
+ */
664
+ recordBashResult(command: string, result: BashResult, options?: {
665
+ excludeFromContext?: boolean;
666
+ }): void;
667
+ /**
668
+ * Cancel running bash command.
669
+ */
670
+ abortBash(): void;
671
+ /** Whether a bash command is currently running */
672
+ get isBashRunning(): boolean;
673
+ /** Whether there are pending bash messages waiting to be flushed */
674
+ get hasPendingBashMessages(): boolean;
675
+ /**
676
+ * Flush pending bash messages to agent state and session.
677
+ * Called after agent turn completes to maintain proper message ordering.
678
+ */
679
+ private _flushPendingBashMessages;
680
+ /**
681
+ * Set a display name for the current session.
682
+ */
683
+ setSessionName(name: string): void;
684
+ /**
685
+ * Navigate to a different node in the session tree.
686
+ * Unlike fork() which creates a new session file, this stays in the same file.
687
+ *
688
+ * @param targetId The entry ID to navigate to
689
+ * @param options.summarize Whether user wants to summarize abandoned branch
690
+ * @param options.customInstructions Custom instructions for summarizer
691
+ * @param options.replaceInstructions If true, customInstructions replaces the default prompt
692
+ * @param options.label Label to attach to the branch summary entry
693
+ * @returns Result with editorText (if user message) and cancelled status
694
+ */
695
+ navigateTree(targetId: string, options?: {
696
+ summarize?: boolean;
697
+ customInstructions?: string;
698
+ replaceInstructions?: boolean;
699
+ label?: string;
700
+ }): Promise<{
701
+ editorText?: string;
702
+ cancelled: boolean;
703
+ aborted?: boolean;
704
+ summaryEntry?: BranchSummaryEntry;
705
+ }>;
706
+ /**
707
+ * Get all user messages from session for fork selector.
708
+ */
709
+ getUserMessagesForForking(): Array<{
710
+ entryId: string;
711
+ text: string;
712
+ }>;
713
+ private _extractUserMessageText;
714
+ /**
715
+ * Get session statistics.
716
+ */
717
+ getSessionStats(): SessionStats;
718
+ getContextUsage(): ContextUsage | undefined;
719
+ /**
720
+ * Export session to HTML.
721
+ * @param outputPath Optional output path (defaults to session directory)
722
+ * @returns Path to exported file
723
+ */
724
+ exportToHtml(outputPath?: string): Promise<string>;
725
+ /**
726
+ * Export the current session branch to a JSONL file.
727
+ * Writes the session header followed by all entries on the current branch path.
728
+ * @param outputPath Target file path. If omitted, generates a timestamped file in cwd.
729
+ * @returns The resolved output file path.
730
+ */
731
+ exportToJsonl(outputPath?: string): string;
732
+ /**
733
+ * Get text content of last assistant message.
734
+ * Useful for /copy command.
735
+ * @returns Text content, or undefined if no assistant message exists
736
+ */
737
+ getLastAssistantText(): string | undefined;
738
+ createReplacedSessionContext(): ReplacedSessionContext;
739
+ /**
740
+ * Check if extensions have handlers for a specific event type.
741
+ */
742
+ hasExtensionHandlers(eventType: string): boolean;
743
+ /**
744
+ * Get the extension runner (for setting UI context and error handlers).
745
+ */
746
+ get extensionRunner(): ExtensionRunner;
747
+ }