@di-code/coding-agent 0.1.6 → 0.1.8

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 (338) hide show
  1. package/README.md +112 -68
  2. package/compositions/base.yml +54 -0
  3. package/compositions/interactive.yml +14 -0
  4. package/compositions/json.yml +6 -0
  5. package/compositions/print.yml +5 -0
  6. package/compositions/rpc.yml +12 -0
  7. package/compositions/webui.yml +9 -0
  8. package/dist/cli.d.ts +22 -1
  9. package/dist/cli.d.ts.map +1 -1
  10. package/dist/cli.js +97 -3
  11. package/dist/cli.js.map +1 -1
  12. package/dist/composition-loader-entry.d.ts +11 -0
  13. package/dist/composition-loader-entry.d.ts.map +1 -0
  14. package/dist/composition-loader-entry.js +12 -0
  15. package/dist/composition-loader-entry.js.map +1 -0
  16. package/dist/compositions.d.ts +32 -0
  17. package/dist/compositions.d.ts.map +1 -0
  18. package/dist/compositions.js +173 -0
  19. package/dist/compositions.js.map +1 -0
  20. package/dist/core/session/session-manager.d.ts +9 -2
  21. package/dist/core/session/session-manager.d.ts.map +1 -1
  22. package/dist/core/session/session-manager.js +28 -0
  23. package/dist/core/session/session-manager.js.map +1 -1
  24. package/dist/core/session/session-storage.d.ts.map +1 -1
  25. package/dist/core/session/session-storage.js +20 -3
  26. package/dist/core/session/session-storage.js.map +1 -1
  27. package/dist/core/session/types.d.ts +11 -2
  28. package/dist/core/session/types.d.ts.map +1 -1
  29. package/dist/core/session/types.js.map +1 -1
  30. package/dist/core/session-tools.d.ts +5 -0
  31. package/dist/core/session-tools.d.ts.map +1 -0
  32. package/dist/core/session-tools.js +17 -0
  33. package/dist/core/session-tools.js.map +1 -0
  34. package/dist/core/session.d.ts +21 -7
  35. package/dist/core/session.d.ts.map +1 -1
  36. package/dist/core/session.js +77 -41
  37. package/dist/core/session.js.map +1 -1
  38. package/dist/core/tools/bash.d.ts +1 -38
  39. package/dist/core/tools/bash.d.ts.map +1 -1
  40. package/dist/core/tools/bash.js +1 -207
  41. package/dist/core/tools/bash.js.map +1 -1
  42. package/dist/core/tools/edit-diff.d.ts +1 -24
  43. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  44. package/dist/core/tools/edit-diff.js +1 -135
  45. package/dist/core/tools/edit-diff.js.map +1 -1
  46. package/dist/core/tools/edit.d.ts +1 -26
  47. package/dist/core/tools/edit.d.ts.map +1 -1
  48. package/dist/core/tools/edit.js +1 -140
  49. package/dist/core/tools/edit.js.map +1 -1
  50. package/dist/core/tools/file-mutation-queue.d.ts +1 -1
  51. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
  52. package/dist/core/tools/file-mutation-queue.js +1 -23
  53. package/dist/core/tools/file-mutation-queue.js.map +1 -1
  54. package/dist/core/tools/file-search.d.ts +1 -13
  55. package/dist/core/tools/file-search.d.ts.map +1 -1
  56. package/dist/core/tools/file-search.js +1 -98
  57. package/dist/core/tools/file-search.js.map +1 -1
  58. package/dist/core/tools/glob.d.ts +1 -10
  59. package/dist/core/tools/glob.d.ts.map +1 -1
  60. package/dist/core/tools/glob.js +1 -43
  61. package/dist/core/tools/glob.js.map +1 -1
  62. package/dist/core/tools/grep.d.ts +1 -12
  63. package/dist/core/tools/grep.d.ts.map +1 -1
  64. package/dist/core/tools/grep.js +1 -66
  65. package/dist/core/tools/grep.js.map +1 -1
  66. package/dist/core/tools/load-skill.d.ts +1 -9
  67. package/dist/core/tools/load-skill.d.ts.map +1 -1
  68. package/dist/core/tools/load-skill.js +1 -21
  69. package/dist/core/tools/load-skill.js.map +1 -1
  70. package/dist/core/tools/path-boundary.d.ts +1 -4
  71. package/dist/core/tools/path-boundary.d.ts.map +1 -1
  72. package/dist/core/tools/path-boundary.js +1 -65
  73. package/dist/core/tools/path-boundary.js.map +1 -1
  74. package/dist/core/tools/read.d.ts +1 -16
  75. package/dist/core/tools/read.d.ts.map +1 -1
  76. package/dist/core/tools/read.js +1 -131
  77. package/dist/core/tools/read.js.map +1 -1
  78. package/dist/core/tools/write.d.ts +1 -16
  79. package/dist/core/tools/write.d.ts.map +1 -1
  80. package/dist/core/tools/write.js +1 -44
  81. package/dist/core/tools/write.js.map +1 -1
  82. package/dist/entry.js +30 -28
  83. package/dist/entry.js.map +1 -1
  84. package/dist/i18n.d.ts.map +1 -1
  85. package/dist/i18n.js +2 -0
  86. package/dist/i18n.js.map +1 -1
  87. package/dist/index.d.ts +6 -3
  88. package/dist/index.d.ts.map +1 -1
  89. package/dist/index.js +6 -3
  90. package/dist/index.js.map +1 -1
  91. package/dist/interactive/builtin.d.ts +17 -0
  92. package/dist/interactive/builtin.d.ts.map +1 -0
  93. package/dist/interactive/builtin.js +47 -0
  94. package/dist/interactive/builtin.js.map +1 -0
  95. package/dist/interactive/controller.d.ts +85 -0
  96. package/dist/interactive/controller.d.ts.map +1 -0
  97. package/dist/interactive/controller.js +211 -0
  98. package/dist/interactive/controller.js.map +1 -0
  99. package/dist/interactive/index.d.ts +3 -0
  100. package/dist/interactive/index.d.ts.map +1 -0
  101. package/dist/interactive/index.js +3 -0
  102. package/dist/interactive/index.js.map +1 -0
  103. package/dist/interactive-host-entry.d.ts +7 -0
  104. package/dist/interactive-host-entry.d.ts.map +1 -0
  105. package/dist/interactive-host-entry.js +123 -0
  106. package/dist/interactive-host-entry.js.map +1 -0
  107. package/dist/interactive-profile.d.ts +18 -0
  108. package/dist/interactive-profile.d.ts.map +1 -0
  109. package/dist/interactive-profile.js +290 -0
  110. package/dist/interactive-profile.js.map +1 -0
  111. package/dist/interactive-resources-entry.d.ts +7 -0
  112. package/dist/interactive-resources-entry.d.ts.map +1 -0
  113. package/dist/interactive-resources-entry.js +42 -0
  114. package/dist/interactive-resources-entry.js.map +1 -0
  115. package/dist/legacy-main.d.ts +39 -0
  116. package/dist/legacy-main.d.ts.map +1 -0
  117. package/dist/legacy-main.js +611 -0
  118. package/dist/legacy-main.js.map +1 -0
  119. package/dist/main.d.ts +15 -34
  120. package/dist/main.d.ts.map +1 -1
  121. package/dist/main.js +130 -513
  122. package/dist/main.js.map +1 -1
  123. package/dist/mcp/entries.d.ts +42 -0
  124. package/dist/mcp/entries.d.ts.map +1 -0
  125. package/dist/mcp/entries.js +98 -0
  126. package/dist/mcp/entries.js.map +1 -0
  127. package/dist/mcp-client-entry.d.ts +5 -0
  128. package/dist/mcp-client-entry.d.ts.map +1 -0
  129. package/dist/mcp-client-entry.js +6 -0
  130. package/dist/mcp-client-entry.js.map +1 -0
  131. package/dist/mcp-config-entry.d.ts +5 -0
  132. package/dist/mcp-config-entry.d.ts.map +1 -0
  133. package/dist/mcp-config-entry.js +6 -0
  134. package/dist/mcp-config-entry.js.map +1 -0
  135. package/dist/mcp-tools-entry.d.ts +5 -0
  136. package/dist/mcp-tools-entry.d.ts.map +1 -0
  137. package/dist/mcp-tools-entry.js +6 -0
  138. package/dist/mcp-tools-entry.js.map +1 -0
  139. package/dist/mcp-transport-entry.d.ts +5 -0
  140. package/dist/mcp-transport-entry.d.ts.map +1 -0
  141. package/dist/mcp-transport-entry.js +6 -0
  142. package/dist/mcp-transport-entry.js.map +1 -0
  143. package/dist/modes/interactive-entry.d.ts +18 -0
  144. package/dist/modes/interactive-entry.d.ts.map +1 -0
  145. package/dist/modes/interactive-entry.js +21 -0
  146. package/dist/modes/interactive-entry.js.map +1 -0
  147. package/dist/modes/interactive-state.js +1 -1
  148. package/dist/modes/interactive-state.js.map +1 -1
  149. package/dist/modes/interactive.d.ts +16 -6
  150. package/dist/modes/interactive.d.ts.map +1 -1
  151. package/dist/modes/interactive.js +99 -33
  152. package/dist/modes/interactive.js.map +1 -1
  153. package/dist/modes/json-entry.d.ts +13 -0
  154. package/dist/modes/json-entry.d.ts.map +1 -0
  155. package/dist/modes/json-entry.js +14 -0
  156. package/dist/modes/json-entry.js.map +1 -0
  157. package/dist/modes/json.d.ts +4 -1
  158. package/dist/modes/json.d.ts.map +1 -1
  159. package/dist/modes/json.js +3 -3
  160. package/dist/modes/json.js.map +1 -1
  161. package/dist/modes/print-entry.d.ts +10 -0
  162. package/dist/modes/print-entry.d.ts.map +1 -0
  163. package/dist/modes/print-entry.js +11 -0
  164. package/dist/modes/print-entry.js.map +1 -0
  165. package/dist/modes/tree-selector.d.ts.map +1 -1
  166. package/dist/modes/tree-selector.js +4 -0
  167. package/dist/modes/tree-selector.js.map +1 -1
  168. package/dist/plugin-dump-composition.d.ts +6 -0
  169. package/dist/plugin-dump-composition.d.ts.map +1 -0
  170. package/dist/plugin-dump-composition.js +7 -0
  171. package/dist/plugin-dump-composition.js.map +1 -0
  172. package/dist/plugin-inventory.d.ts +7 -0
  173. package/dist/plugin-inventory.d.ts.map +1 -0
  174. package/dist/plugin-inventory.js +8 -0
  175. package/dist/plugin-inventory.js.map +1 -0
  176. package/dist/plugin-manager.d.ts +6 -0
  177. package/dist/plugin-manager.d.ts.map +1 -0
  178. package/dist/plugin-manager.js +7 -0
  179. package/dist/plugin-manager.js.map +1 -0
  180. package/dist/plugin-trace.d.ts +6 -0
  181. package/dist/plugin-trace.d.ts.map +1 -0
  182. package/dist/plugin-trace.js +7 -0
  183. package/dist/plugin-trace.js.map +1 -0
  184. package/dist/plugins/dynamic-broker.d.ts +76 -0
  185. package/dist/plugins/dynamic-broker.d.ts.map +1 -0
  186. package/dist/plugins/dynamic-broker.js +852 -0
  187. package/dist/plugins/dynamic-broker.js.map +1 -0
  188. package/dist/plugins/profile.d.ts +15 -0
  189. package/dist/plugins/profile.d.ts.map +1 -0
  190. package/dist/plugins/profile.js +34 -0
  191. package/dist/plugins/profile.js.map +1 -0
  192. package/dist/plugins/runtime-host.d.ts +37 -0
  193. package/dist/plugins/runtime-host.d.ts.map +1 -0
  194. package/dist/plugins/runtime-host.js +95 -0
  195. package/dist/plugins/runtime-host.js.map +1 -0
  196. package/dist/plugins/trust.d.ts +8 -0
  197. package/dist/plugins/trust.d.ts.map +1 -0
  198. package/dist/plugins/trust.js +59 -0
  199. package/dist/plugins/trust.js.map +1 -0
  200. package/dist/project-trust-entry.d.ts +15 -0
  201. package/dist/project-trust-entry.d.ts.map +1 -0
  202. package/dist/project-trust-entry.js +15 -0
  203. package/dist/project-trust-entry.js.map +1 -0
  204. package/dist/rpc/client.d.ts +78 -6
  205. package/dist/rpc/client.d.ts.map +1 -1
  206. package/dist/rpc/client.js +172 -4
  207. package/dist/rpc/client.js.map +1 -1
  208. package/dist/rpc/dispatcher.d.ts +121 -0
  209. package/dist/rpc/dispatcher.d.ts.map +1 -0
  210. package/dist/rpc/dispatcher.js +994 -0
  211. package/dist/rpc/dispatcher.js.map +1 -0
  212. package/dist/rpc/index.d.ts +2 -0
  213. package/dist/rpc/index.d.ts.map +1 -1
  214. package/dist/rpc/index.js +2 -0
  215. package/dist/rpc/index.js.map +1 -1
  216. package/dist/rpc/lifecycle.d.ts +6 -0
  217. package/dist/rpc/lifecycle.d.ts.map +1 -0
  218. package/dist/rpc/lifecycle.js +24 -0
  219. package/dist/rpc/lifecycle.js.map +1 -0
  220. package/dist/rpc/protocol.d.ts +112 -31
  221. package/dist/rpc/protocol.d.ts.map +1 -1
  222. package/dist/rpc/protocol.js +569 -117
  223. package/dist/rpc/protocol.js.map +1 -1
  224. package/dist/rpc/server-service.d.ts +7 -0
  225. package/dist/rpc/server-service.d.ts.map +1 -0
  226. package/dist/rpc/server-service.js +3 -0
  227. package/dist/rpc/server-service.js.map +1 -0
  228. package/dist/rpc/server.d.ts +16 -19
  229. package/dist/rpc/server.d.ts.map +1 -1
  230. package/dist/rpc/server.js +59 -115
  231. package/dist/rpc/server.js.map +1 -1
  232. package/dist/rpc-client-sdk-entry.d.ts +12 -0
  233. package/dist/rpc-client-sdk-entry.d.ts.map +1 -0
  234. package/dist/rpc-client-sdk-entry.js +11 -0
  235. package/dist/rpc-client-sdk-entry.js.map +1 -0
  236. package/dist/rpc-entry.js +50 -18
  237. package/dist/rpc-entry.js.map +1 -1
  238. package/dist/rpc-server-entry.d.ts +8 -0
  239. package/dist/rpc-server-entry.d.ts.map +1 -0
  240. package/dist/rpc-server-entry.js +67 -0
  241. package/dist/rpc-server-entry.js.map +1 -0
  242. package/dist/runtime/attachment-store.d.ts +13 -0
  243. package/dist/runtime/attachment-store.d.ts.map +1 -0
  244. package/dist/runtime/attachment-store.js +93 -0
  245. package/dist/runtime/attachment-store.js.map +1 -0
  246. package/dist/runtime/bootstrap.d.ts +14 -0
  247. package/dist/runtime/bootstrap.d.ts.map +1 -0
  248. package/dist/runtime/bootstrap.js +29 -0
  249. package/dist/runtime/bootstrap.js.map +1 -0
  250. package/dist/runtime/interactive-host-service.d.ts +22 -0
  251. package/dist/runtime/interactive-host-service.d.ts.map +1 -0
  252. package/dist/runtime/interactive-host-service.js +2 -0
  253. package/dist/runtime/interactive-host-service.js.map +1 -0
  254. package/dist/runtime/interactive-resource-service.d.ts +11 -0
  255. package/dist/runtime/interactive-resource-service.d.ts.map +1 -0
  256. package/dist/runtime/interactive-resource-service.js +3 -0
  257. package/dist/runtime/interactive-resource-service.js.map +1 -0
  258. package/dist/runtime/plugin-inventory-entry.d.ts +5 -0
  259. package/dist/runtime/plugin-inventory-entry.d.ts.map +1 -0
  260. package/dist/runtime/plugin-inventory-entry.js +18 -0
  261. package/dist/runtime/plugin-inventory-entry.js.map +1 -0
  262. package/dist/runtime/plugin-inventory-service.d.ts +8 -0
  263. package/dist/runtime/plugin-inventory-service.d.ts.map +1 -0
  264. package/dist/runtime/plugin-inventory-service.js +3 -0
  265. package/dist/runtime/plugin-inventory-service.js.map +1 -0
  266. package/dist/runtime/plugin-manager-entry.d.ts +20 -0
  267. package/dist/runtime/plugin-manager-entry.d.ts.map +1 -0
  268. package/dist/runtime/plugin-manager-entry.js +96 -0
  269. package/dist/runtime/plugin-manager-entry.js.map +1 -0
  270. package/dist/runtime/plugin-observability-entry.d.ts +12 -0
  271. package/dist/runtime/plugin-observability-entry.d.ts.map +1 -0
  272. package/dist/runtime/plugin-observability-entry.js +73 -0
  273. package/dist/runtime/plugin-observability-entry.js.map +1 -0
  274. package/dist/runtime/product-host.d.ts +91 -0
  275. package/dist/runtime/product-host.d.ts.map +1 -0
  276. package/dist/runtime/product-host.js +529 -0
  277. package/dist/runtime/product-host.js.map +1 -0
  278. package/dist/runtime/session-factory.d.ts +17 -0
  279. package/dist/runtime/session-factory.d.ts.map +1 -0
  280. package/dist/runtime/session-factory.js +75 -0
  281. package/dist/runtime/session-factory.js.map +1 -0
  282. package/dist/runtime/session-host.d.ts +152 -0
  283. package/dist/runtime/session-host.d.ts.map +1 -0
  284. package/dist/runtime/session-host.js +895 -0
  285. package/dist/runtime/session-host.js.map +1 -0
  286. package/dist/runtime-core-entry.d.ts +11 -0
  287. package/dist/runtime-core-entry.d.ts.map +1 -0
  288. package/dist/runtime-core-entry.js +9 -0
  289. package/dist/runtime-core-entry.js.map +1 -0
  290. package/dist/session-factory-entry.d.ts +7 -0
  291. package/dist/session-factory-entry.d.ts.map +1 -0
  292. package/dist/session-factory-entry.js +9 -0
  293. package/dist/session-factory-entry.js.map +1 -0
  294. package/dist/session-store-jsonl-entry.d.ts +7 -0
  295. package/dist/session-store-jsonl-entry.d.ts.map +1 -0
  296. package/dist/session-store-jsonl-entry.js +33 -0
  297. package/dist/session-store-jsonl-entry.js.map +1 -0
  298. package/dist/startup.d.ts +21 -1
  299. package/dist/startup.d.ts.map +1 -1
  300. package/dist/startup.js +179 -10
  301. package/dist/startup.js.map +1 -1
  302. package/dist/subagents/index.d.ts +2 -0
  303. package/dist/subagents/index.d.ts.map +1 -0
  304. package/dist/subagents/index.js +2 -0
  305. package/dist/subagents/index.js.map +1 -0
  306. package/dist/subagents/service.d.ts +50 -0
  307. package/dist/subagents/service.d.ts.map +1 -0
  308. package/dist/subagents/service.js +521 -0
  309. package/dist/subagents/service.js.map +1 -0
  310. package/dist/ui-host.d.ts +125 -0
  311. package/dist/ui-host.d.ts.map +1 -0
  312. package/dist/ui-host.js +275 -0
  313. package/dist/ui-host.js.map +1 -0
  314. package/dist/web/assets/index-BwfuGMvv.css +1 -0
  315. package/dist/web/assets/index-DPUaJqFJ.js +41 -0
  316. package/dist/web/assets/index-DPUaJqFJ.js.map +1 -0
  317. package/dist/web/index.html +14 -0
  318. package/dist/web-command.d.ts +11 -0
  319. package/dist/web-command.d.ts.map +1 -0
  320. package/dist/web-command.js +114 -0
  321. package/dist/web-command.js.map +1 -0
  322. package/dist/web-frontend.d.ts +73 -0
  323. package/dist/web-frontend.d.ts.map +1 -0
  324. package/dist/web-frontend.js +249 -0
  325. package/dist/web-frontend.js.map +1 -0
  326. package/dist/web.d.ts +254 -0
  327. package/dist/web.d.ts.map +1 -0
  328. package/dist/web.js +740 -0
  329. package/dist/web.js.map +1 -0
  330. package/dist/webui-entry.d.ts +3 -0
  331. package/dist/webui-entry.d.ts.map +1 -0
  332. package/dist/webui-entry.js +73 -0
  333. package/dist/webui-entry.js.map +1 -0
  334. package/dist/webui.d.ts +91 -0
  335. package/dist/webui.d.ts.map +1 -0
  336. package/dist/webui.js +882 -0
  337. package/dist/webui.js.map +1 -0
  338. package/package.json +89 -8
package/dist/main.js CHANGED
@@ -1,542 +1,159 @@
1
- import { randomUUID } from "node:crypto";
2
- import { access, readdir, stat } from "node:fs/promises";
1
+ import { access } from "node:fs/promises";
3
2
  import { homedir } from "node:os";
4
- import { basename, dirname, extname, join, resolve } from "node:path";
5
- import { ProcessTerminal, TUI, truncateToWidth } from "@di-code/tui";
6
- import { runCli } from "./cli.js";
7
- import { loadImageInputs } from "./core/image-input.js";
8
- import { loadResources } from "./core/resources/loader.js";
9
- import { SessionManager } from "./core/session/session-manager.js";
10
- import { AgentSession } from "./core/session.js";
11
- import { buildSystemPrompt } from "./core/system-prompt.js";
12
- import { workspaceStorageKey } from "./core/user-data.js";
13
- import { ProjectTrustManager } from "./extensions/trust.js";
14
- import { DEFAULT_LOCALE, translate } from "./i18n.js";
15
- import { addMcpConfig, getMcpConfig, listMcpConfig, removeMcpConfig } from "./mcp/config.js";
16
- import { loadProjectMcp } from "./mcp/loader.js";
17
- import { InteractiveMode } from "./modes/interactive.js";
18
- import { runJsonMode } from "./modes/json.js";
19
- import { runPrintMode } from "./modes/print.js";
20
- import { loadPlugins } from "./plugins/loader.js";
21
- import { PluginManager } from "./plugins/manager.js";
22
- const MAX_SESSION_QUESTION_LENGTH = 72;
23
- function defaultSessionDirectory(agentDir, cwd) {
24
- return join(agentDir, "sessions", workspaceStorageKey(cwd));
25
- }
26
- const STARTUP_STATUS_COLORS = {
27
- error: "\x1b[31m",
28
- success: "\x1b[32m",
29
- warning: "\x1b[33m",
30
- reset: "\x1b[0m",
31
- };
32
- function formatMcpStatus(status) {
33
- switch (status.state) {
34
- case "connecting":
35
- return `${STARTUP_STATUS_COLORS.warning}MCP [loading]${STARTUP_STATUS_COLORS.reset} ${status.serverId}`;
36
- case "connected":
37
- return `${STARTUP_STATUS_COLORS.success}MCP [ok]${STARTUP_STATUS_COLORS.reset} ${status.serverId} (${status.tools} tools, ${status.resources} resources, ${status.prompts} prompts)`;
38
- case "failed":
39
- return `${STARTUP_STATUS_COLORS.error}MCP [error]${STARTUP_STATUS_COLORS.reset} ${status.serverId} (${status.stage}): ${status.message}`;
40
- }
41
- }
42
- function formatMcpDiagnostic(serverId, stage, message) {
43
- return `${STARTUP_STATUS_COLORS.error}MCP [error]${STARTUP_STATUS_COLORS.reset} ${serverId ?? "configuration"} (${stage}): ${message}\n`;
44
- }
45
- function formatPluginStatus(status) {
46
- switch (status.state) {
47
- case "loading":
48
- return `${STARTUP_STATUS_COLORS.warning}Plugin [loading]${STARTUP_STATUS_COLORS.reset} ${status.pluginId}`;
49
- case "loaded":
50
- return `${STARTUP_STATUS_COLORS.success}Plugin [ok]${STARTUP_STATUS_COLORS.reset} ${status.pluginId} (${status.tools} tools, ${status.commands} commands)`;
51
- case "failed":
52
- return `${STARTUP_STATUS_COLORS.error}Plugin [error]${STARTUP_STATUS_COLORS.reset} ${status.pluginId ?? "plugin"} (${status.stage}): ${status.message}`;
53
- }
54
- }
55
- function formatPluginDiagnostic(pluginId, stage, message) {
56
- return `${STARTUP_STATUS_COLORS.error}Plugin [error]${STARTUP_STATUS_COLORS.reset} ${pluginId ?? "plugin"} (${stage}): ${message}\n`;
57
- }
58
- function pluginStatusKey(status) {
59
- if (status.state === "failed" && status.pluginId === undefined)
60
- return `plugin:${status.sourcePath}`;
61
- return `plugin:${status.pluginId}`;
62
- }
63
- /** Renders startup states in place so terminal history retains only their final outcome. */
64
- export class StartupStatusRenderer {
65
- lines = [];
66
- indexes = new Map();
67
- write;
68
- replaceInPlace;
69
- width;
70
- constructor(write, replaceInPlace, width = 80) {
71
- this.write = write;
72
- this.replaceInPlace = replaceInPlace;
73
- this.width = width;
74
- }
75
- update(key, text) {
76
- const line = truncateToWidth(text.replace(/[\r\n]+/g, " "), Math.max(1, this.width), "...");
77
- const index = this.indexes.get(key);
78
- if (index === undefined || !this.replaceInPlace) {
79
- this.indexes.set(key, this.lines.length);
80
- this.lines.push(line);
81
- this.write(`${line}\n`);
82
- return;
83
- }
84
- this.lines[index] = line;
85
- const offset = this.lines.length - index;
86
- this.write(`\x1b[${offset}A\r\x1b[2K${line}\x1b[${offset}B\r`);
87
- }
88
- }
89
- function startupStatusRenderer(write, interactive) {
90
- const width = typeof process.stderr.columns === "number" && process.stderr.columns > 0 ? process.stderr.columns : 80;
91
- return new StartupStatusRenderer(write, interactive && process.stderr.isTTY === true, width);
92
- }
93
- async function openOrCreateSession(filePath, cwd, now) {
94
- try {
95
- await access(filePath);
96
- return await SessionManager.open(filePath, { now });
97
- }
98
- catch (cause) {
99
- if (!(cause instanceof Error && "code" in cause && cause.code === "ENOENT"))
100
- throw cause;
101
- return SessionManager.create({ filePath, cwd, now, deferCreate: true });
102
- }
103
- }
104
- function newSessionPath(sessionDirectory, now) {
105
- return join(sessionDirectory, `session-${now()}-${randomUUID().slice(0, 8)}.jsonl`);
106
- }
107
- async function mostRecentSessionPath(sessionDirectory) {
108
- let names;
109
- try {
110
- names = (await readdir(sessionDirectory, { withFileTypes: true }))
111
- .filter((entry) => entry.isFile() && extname(entry.name) === ".jsonl")
112
- .map((entry) => entry.name);
113
- }
114
- catch (cause) {
115
- if (cause instanceof Error && "code" in cause && cause.code === "ENOENT")
116
- return undefined;
117
- throw cause;
118
- }
119
- const candidates = await Promise.all(names.map(async (name) => {
120
- const filePath = join(sessionDirectory, name);
121
- try {
122
- return { filePath, modifiedAt: (await stat(filePath)).mtimeMs };
123
- }
124
- catch (cause) {
125
- if (cause instanceof Error && "code" in cause && cause.code === "ENOENT")
126
- return undefined;
127
- throw cause;
128
- }
129
- }));
130
- return candidates
131
- .filter((candidate) => candidate !== undefined)
132
- .sort((left, right) => right.modifiedAt - left.modifiedAt || right.filePath.localeCompare(left.filePath))[0]
133
- ?.filePath;
134
- }
135
- async function hasProjectLocalCapabilities(cwd) {
136
- const directories = [
3
+ import { join, resolve } from "node:path";
4
+ import { hostCommandRegistryKey, processExitKey, sessionStoreKey } from "@di-code/builtins";
5
+ import { createCompositionLoader } from "@di-code/plugin-loader";
6
+ import { createRootContext, redactSensitiveText } from "@di-code/plugin-runtime";
7
+ import { createCliParser } from "./cli.js";
8
+ import { importCompositionModule, resolveCompositionEntries, resolveManagedCompositionEntries, } from "./compositions.js";
9
+ import { createProjectTrustStore } from "./project-trust-entry.js";
10
+ import { pluginInventoryKey } from "./runtime/plugin-inventory-service.js";
11
+ function errorMessage(cause) {
12
+ return redactSensitiveText(cause instanceof Error ? cause.message : String(cause));
13
+ }
14
+ function isRun(command) {
15
+ return command.kind === "run";
16
+ }
17
+ function isMinimalCommand(command) {
18
+ return command.kind === "run" || command.kind === "plugin" || command.kind === "observe";
19
+ }
20
+ async function hasTrustedProjectContent(cwd) {
21
+ for (const path of [
137
22
  join(cwd, ".di-code", "skills"),
138
23
  join(cwd, ".agents", "skills"),
139
- join(cwd, ".di-code", "extensions"),
140
- join(cwd, ".di-code", "plugins"),
141
24
  join(cwd, ".di-code", "mcp.local.json"),
142
25
  join(cwd, ".mcp.json"),
143
- ];
144
- const results = await Promise.all(directories.map(async (directory) => {
26
+ ]) {
145
27
  try {
146
- const metadata = await stat(directory);
147
- return metadata.isDirectory() || metadata.isFile();
28
+ await access(path);
29
+ return true;
148
30
  }
149
31
  catch (cause) {
150
- if (cause instanceof Error && "code" in cause && cause.code === "ENOENT")
151
- return false;
152
- return false;
32
+ if (!(cause instanceof Error && "code" in cause && cause.code === "ENOENT"))
33
+ throw cause;
153
34
  }
154
- }));
155
- return results.some(Boolean);
156
- }
157
- async function selectStartupSession(command, allowedRoot, agentDir, now) {
158
- const sessionDirectory = defaultSessionDirectory(agentDir, allowedRoot);
159
- if (command.sessionPath !== undefined) {
160
- return openOrCreateSession(resolve(allowedRoot, command.sessionPath), allowedRoot, now);
161
- }
162
- if (command.continueSession) {
163
- const recentPath = await mostRecentSessionPath(sessionDirectory);
164
- if (recentPath !== undefined)
165
- return SessionManager.open(recentPath, { now });
166
35
  }
167
- return SessionManager.create({
168
- filePath: newSessionPath(sessionDirectory, now),
169
- cwd: allowedRoot,
170
- now,
171
- deferCreate: true,
172
- });
36
+ return false;
173
37
  }
174
- function formatSessionTimestamp(timestamp, fallback, timeZone) {
175
- const date = new Date(timestamp);
176
- if (Number.isNaN(date.getTime()))
177
- return fallback;
38
+ /** Starts a composition profile and executes its registered host command. */
39
+ export async function runMinimalProfile(args, options) {
40
+ const parser = createCliParser();
41
+ let command;
178
42
  try {
179
- const parts = new Map(new Intl.DateTimeFormat("en-CA", {
180
- timeZone: timeZone ?? Intl.DateTimeFormat().resolvedOptions().timeZone,
181
- year: "numeric",
182
- month: "2-digit",
183
- day: "2-digit",
184
- hour: "2-digit",
185
- minute: "2-digit",
186
- hourCycle: "h23",
187
- })
188
- .formatToParts(date)
189
- .filter((part) => part.type !== "literal")
190
- .map((part) => [part.type, part.value]));
191
- const year = parts.get("year");
192
- const month = parts.get("month");
193
- const day = parts.get("day");
194
- const hour = parts.get("hour");
195
- const minute = parts.get("minute");
196
- if (!year || !month || !day || !hour || !minute)
197
- return fallback;
198
- return `${year}-${month}-${day} ${hour}:${minute}`;
43
+ command = parser.parse(args);
199
44
  }
200
- catch {
201
- return fallback;
45
+ catch (cause) {
46
+ options.stderr(`${errorMessage(cause)}\n`);
47
+ return 1;
202
48
  }
203
- }
204
- export function formatSessionLabel(manager, timeZone) {
205
- const firstUserEntry = manager.entries.find((entry) => entry.type === "message" && entry.message.role === "user");
206
- const fileName = basename(manager.filePath, extname(manager.filePath));
207
- if (firstUserEntry?.type !== "message" || firstUserEntry.message.role !== "user") {
208
- return `${fileName} (${formatSessionTimestamp(Date.parse(manager.header.timestamp), manager.header.timestamp, timeZone)})`;
49
+ if (command.kind === "help") {
50
+ options.stdout(`${parser.help("en")}\n`);
51
+ return 0;
209
52
  }
210
- const question = firstUserEntry.message.content
211
- .filter((content) => content.type === "text")
212
- .map((content) => content.text)
213
- .join(" ")
214
- .replace(/\s+/g, " ")
215
- .trim();
216
- const label = question.length > MAX_SESSION_QUESTION_LENGTH
217
- ? `${question.slice(0, MAX_SESSION_QUESTION_LENGTH - 3)}...`
218
- : question || fileName;
219
- const timestamp = formatSessionTimestamp(firstUserEntry.message.timestamp, firstUserEntry.timestamp, timeZone);
220
- return `${label} (${timestamp})`;
221
- }
222
- async function sessionChoices(sessionDirectory, currentFile, open) {
223
- let names = [];
224
- try {
225
- names = (await readdir(sessionDirectory, { withFileTypes: true }))
226
- .filter((entry) => entry.isFile() && extname(entry.name) === ".jsonl")
227
- .map((entry) => entry.name)
228
- .sort();
53
+ if (command.kind === "version") {
54
+ options.stdout(`${options.version}\n`);
55
+ return 0;
229
56
  }
230
- catch (cause) {
231
- if (!(cause instanceof Error && "code" in cause && cause.code === "ENOENT"))
232
- throw cause;
57
+ if (!isMinimalCommand(command)) {
58
+ options.stderr("MCP commands are unavailable in the minimal profile.\n");
59
+ return 1;
233
60
  }
234
- return Promise.all(names
235
- .filter((name) => resolve(sessionDirectory, name) !== resolve(currentFile))
236
- .map(async (name) => {
237
- const filePath = join(sessionDirectory, name);
238
- const id = basename(name, extname(name));
239
- let label = id;
240
- try {
241
- label = formatSessionLabel(await SessionManager.open(filePath));
61
+ if (isRun(command) && command.mode === "interactive" && !options.interactive?.isInteractiveTerminal) {
62
+ options.stderr("Interactive mode requires an interactive TTY.\n");
63
+ return 1;
64
+ }
65
+ const mode = isRun(command) ? command.mode : "print";
66
+ const observability = command.kind === "observe";
67
+ const allowedRoot = resolve(options.allowedRoot ?? process.cwd());
68
+ const agentDir = resolve(options.agentDir ?? join(homedir(), ".di-code"));
69
+ const trustStore = createProjectTrustStore(join(agentDir, "trust.json"));
70
+ if (isRun(command) && command.projectTrust !== undefined)
71
+ await trustStore.set(allowedRoot, command.projectTrust);
72
+ let projectTrusted = isRun(command) && !command.noProjectPlugins && (await trustStore.get(allowedRoot)) === true;
73
+ if (isRun(command) &&
74
+ command.mode === "interactive" &&
75
+ !projectTrusted &&
76
+ command.projectTrust === undefined &&
77
+ options.interactive?.promptProjectTrust &&
78
+ (await hasTrustedProjectContent(allowedRoot))) {
79
+ projectTrusted = await options.interactive.promptProjectTrust(allowedRoot);
80
+ await trustStore.set(allowedRoot, projectTrusted);
81
+ }
82
+ const managedEntries = await resolveManagedCompositionEntries(agentDir);
83
+ const compositionEntries = await resolveCompositionEntries(isRun(command) ? (command.profile ?? command.mode) : "base", {
84
+ cwd: allowedRoot,
85
+ agentDir,
86
+ ...(isRun(command) && command.compositionPath ? { compositionPath: command.compositionPath } : {}),
87
+ includeProjectComposition: projectTrusted,
88
+ observability,
89
+ allowedRoot,
90
+ });
91
+ const context = createRootContext({ id: "minimal-profile", mode, trustedProject: projectTrusted });
92
+ const unsubscribe = context.events.subscribe((event) => options.onRuntimeEvent?.(event));
93
+ const loader = createCompositionLoader({
94
+ context,
95
+ entries: [...compositionEntries, ...managedEntries],
96
+ importModule: options.importModule ?? importCompositionModule,
97
+ projectTrusted,
98
+ });
99
+ try {
100
+ await loader.load();
101
+ context.require(pluginInventoryKey).set(loader.tree.snapshot());
102
+ const host = context.require(hostCommandRegistryKey);
103
+ let name;
104
+ let input;
105
+ if (command.kind === "observe") {
106
+ name = command.action === "trace" ? "trace-plugins" : "dump-composition";
107
+ input = { stdout: options.stdout };
242
108
  }
243
- catch {
244
- // Keep damaged sessions selectable so opening one can report the detailed load error.
109
+ else if (command.kind === "plugin") {
110
+ name = "plugin";
111
+ input = { ...command, stdout: options.stdout, stderr: options.stderr };
245
112
  }
246
- return {
247
- id,
248
- label,
249
- description: filePath,
250
- open: () => open(filePath),
251
- };
252
- }));
253
- }
254
- export async function runMain(args, options) {
255
- const dependencies = {
256
- stdout: options.stdout,
257
- stderr: options.stderr,
258
- version: options.version,
259
- locale: options.locale ?? options.startupConfiguration?.locale ?? DEFAULT_LOCALE,
260
- plugin: async (command) => {
261
- const agentDir = resolve(options.agentDir ?? join(homedir(), ".di-code"));
262
- const manager = new PluginManager({ agentDir });
263
- try {
264
- switch (command.action) {
265
- case "list":
266
- for (const plugin of await manager.list())
267
- options.stdout(`${plugin.id}\t${plugin.enabled ? "enabled" : "disabled"}\t${plugin.manifest.version}\n`);
268
- return 0;
269
- case "install": {
270
- const plugin = await manager.install(command.argument);
271
- options.stdout(`Installed ${plugin.id}\n`);
272
- return 0;
273
- }
274
- case "enable":
275
- await manager.enable(command.argument);
276
- return 0;
277
- case "disable":
278
- await manager.disable(command.argument);
279
- return 0;
280
- case "update":
281
- await manager.update(command.argument);
282
- return 0;
283
- case "remove":
284
- await manager.remove(command.argument);
285
- return 0;
286
- }
287
- }
288
- catch (cause) {
289
- options.stderr(`${cause instanceof Error ? cause.message : String(cause)}\n`);
290
- return 1;
291
- }
292
- },
293
- mcp: async (command) => {
294
- const cwd = resolve(options.allowedRoot ?? process.cwd());
295
- const scope = command.scope;
296
- const trustManager = new ProjectTrustManager(join(options.agentDir ?? join(homedir(), ".di-code"), "trust.json"));
297
- const requireProjectTrust = async (selected) => {
298
- if ((selected === "local" || selected === "project") && (await trustManager.get(cwd)) !== true)
299
- throw new Error(`Project trust is required to modify the ${selected} MCP scope.`);
300
- };
301
- try {
302
- switch (command.action) {
303
- case "add": {
304
- const selected = scope ?? "local";
305
- await requireProjectTrust(selected);
306
- const config = command.transport === "stdio"
307
- ? {
308
- command: command.command,
309
- ...(command.args && command.args.length > 0 ? { args: command.args } : {}),
310
- }
311
- : { type: "http", url: command.url };
312
- await addMcpConfig(cwd, selected, command.serverId, config);
313
- options.stdout(`Added MCP server "${command.serverId}" to ${selected} scope.\n`);
314
- return 0;
315
- }
316
- case "list": {
317
- const scopes = scope ? [scope] : ["local", "project", "user"];
318
- for (const selected of scopes) {
319
- for (const entry of await listMcpConfig(cwd, selected))
320
- options.stdout(`${entry.id}\t${entry.scope}\t${JSON.stringify(entry.config)}\n`);
321
- }
322
- return 0;
323
- }
324
- case "get": {
325
- const entry = await getMcpConfig(cwd, command.serverId, scope);
326
- if (!entry)
327
- throw new Error(`MCP server "${command.serverId}" was not found.`);
328
- options.stdout(`${JSON.stringify({ id: entry.id, scope: entry.scope, config: entry.config })}\n`);
329
- return 0;
330
- }
331
- case "remove": {
332
- const selected = scope ?? "local";
333
- await requireProjectTrust(selected);
334
- await removeMcpConfig(cwd, selected, command.serverId);
335
- options.stdout(`Removed MCP server "${command.serverId}" from ${selected} scope.\n`);
336
- return 0;
337
- }
338
- }
339
- }
340
- catch (cause) {
341
- options.stderr(`${cause instanceof Error ? cause.message : String(cause)}\n`);
342
- return 1;
343
- }
344
- },
345
- run: async (command) => {
346
- const allowedRoot = resolve(options.allowedRoot ?? process.cwd());
347
- const now = options.now ?? Date.now;
348
- const agentDir = resolve(options.agentDir ?? join(homedir(), ".di-code"));
349
- const trustManager = new ProjectTrustManager(join(agentDir, "trust.json"));
350
- if (command.projectTrust !== undefined)
351
- await trustManager.set(allowedRoot, command.projectTrust);
352
- let persistedTrust = await trustManager.get(allowedRoot);
353
- const shouldPromptForTrust = command.mode === "interactive" &&
354
- options.isInteractiveTerminal === true &&
355
- command.projectTrust === undefined &&
356
- persistedTrust === null &&
357
- options.promptProjectTrust !== undefined &&
358
- (await hasProjectLocalCapabilities(allowedRoot));
359
- if (shouldPromptForTrust) {
360
- let decision = false;
361
- try {
362
- decision = await options.promptProjectTrust(allowedRoot);
363
- }
364
- catch {
365
- // Fail closed when the prompt is interrupted or unavailable.
366
- }
367
- await trustManager.set(allowedRoot, decision);
368
- persistedTrust = decision;
369
- }
370
- const runtime = await options.createRuntime(command);
371
- if (runtime === undefined)
372
- return 0;
373
- const resources = await loadResources({
374
- cwd: allowedRoot,
375
- agentDir,
376
- projectTrusted: persistedTrust === true,
377
- noSkills: command.noSkills,
378
- noContextFiles: command.noContextFiles,
379
- skillPaths: command.skillPaths,
380
- });
381
- for (const diagnostic of resources.diagnostics) {
382
- if (diagnostic.kind !== "skill")
383
- continue;
384
- options.stderr(`${JSON.stringify({ type: "skill_diagnostic", path: diagnostic.path, stage: diagnostic.stage, severity: diagnostic.severity, message: diagnostic.message })}\n`);
385
- }
386
- const interactivePluginStatus = command.mode === "interactive";
387
- const startupStatus = startupStatusRenderer(options.stderr, interactivePluginStatus);
388
- const pluginStatusFailures = new Set();
389
- const extensions = await loadPlugins({
113
+ else if (command.mode === "interactive") {
114
+ name = "interactive";
115
+ input = {
116
+ command,
390
117
  cwd: allowedRoot,
391
118
  agentDir,
392
- trustManager,
393
- mode: command.mode,
394
- ...(interactivePluginStatus
395
- ? {
396
- onPluginLoadStatus: (status) => {
397
- if (status.state === "failed")
398
- pluginStatusFailures.add(status.sourcePath);
399
- startupStatus.update(pluginStatusKey(status), formatPluginStatus(status));
400
- },
401
- }
402
- : {}),
403
- });
404
- for (const diagnostic of extensions.diagnostics) {
405
- if (interactivePluginStatus) {
406
- if (pluginStatusFailures.has(diagnostic.sourcePath))
407
- continue;
408
- options.stderr(formatPluginDiagnostic(diagnostic.pluginId, diagnostic.stage, diagnostic.message));
409
- continue;
410
- }
411
- options.stderr(`${JSON.stringify({ type: "plugin_diagnostic", pluginId: diagnostic.pluginId, stage: diagnostic.stage, sourcePath: diagnostic.sourcePath, severity: diagnostic.severity, message: diagnostic.message })}\n`);
412
- }
413
- const interactiveMcpStatus = command.mode === "interactive";
414
- const mcp = await loadProjectMcp({
415
- cwd: allowedRoot,
416
- projectTrusted: persistedTrust === true,
417
- homeDirectory: homedir(),
418
- reservedToolNames: [
419
- "read",
420
- "write",
421
- "edit",
422
- "bash",
423
- "load_skill",
424
- ...extensions.host.listTools().map((tool) => tool.name),
425
- ],
426
- ...(interactiveMcpStatus
427
- ? {
428
- onServerConnectionStatus: (status) => startupStatus.update(`mcp:${status.serverId}`, formatMcpStatus(status)),
429
- }
119
+ projectTrusted,
120
+ stderr: options.stderr,
121
+ ...(options.interactive?.startInteractiveMode
122
+ ? { startInteractiveMode: options.interactive.startInteractiveMode }
430
123
  : {}),
431
- });
432
- for (const diagnostic of mcp.diagnostics) {
433
- if (interactiveMcpStatus) {
434
- if (diagnostic.serverId && (diagnostic.stage === "connect" || diagnostic.stage === "list_tools"))
435
- continue;
436
- options.stderr(formatMcpDiagnostic(diagnostic.serverId, diagnostic.stage, diagnostic.message));
437
- continue;
438
- }
439
- options.stderr(`${JSON.stringify({ type: "mcp_diagnostic", serverId: diagnostic.serverId, stage: diagnostic.stage, message: diagnostic.message })}\n`);
440
- }
441
- const systemPrompt = buildSystemPrompt({ cwd: allowedRoot, ...resources });
442
- const manager = await selectStartupSession(command, allowedRoot, agentDir, now);
443
- const sessionFile = manager.filePath;
444
- const session = new AgentSession({
445
- allowedRoot,
446
- provider: runtime.provider,
447
- model: runtime.model,
448
- systemPrompt,
449
- skills: resources.skills,
450
- now: options.now,
451
- sessionManager: manager,
452
- extensionHost: extensions.host,
453
- externalTools: mcp.tools,
454
- });
455
- const imagePaths = command.imagePaths ?? [];
456
- const promptRunner = {
457
- prompt: async (text) => session.promptWithImages(text, await loadImageInputs(imagePaths, allowedRoot)),
458
- subscribe: session.subscribe.bind(session),
459
124
  };
460
- if (command.mode === "json") {
461
- await extensions.host.emit({ type: "session_start", cwd: allowedRoot });
462
- try {
463
- return await runJsonMode(command.prompt, promptRunner, options);
464
- }
465
- finally {
466
- await extensions.host.emit({ type: "session_shutdown", reason: "user" });
467
- await mcp.manager.close();
468
- }
469
- }
470
- if (command.mode === "interactive") {
471
- const terminal = new ProcessTerminal();
472
- const tui = new TUI(terminal);
473
- const mode = new InteractiveMode({
474
- session,
475
- tui,
476
- agentDir,
477
- locale: options.locale ?? options.startupConfiguration?.locale ?? DEFAULT_LOCALE,
478
- onExit: () => {
479
- void mcp.manager.close();
480
- },
481
- extensionHost: extensions.host,
482
- ...(options.startupConfiguration
483
- ? { providerOnboarding: { configuration: options.startupConfiguration, agentDir } }
484
- : {}),
485
- sessions: [
486
- {
487
- id: "new-session",
488
- label: translate(options.locale ?? options.startupConfiguration?.locale ?? DEFAULT_LOCALE, "newSession"),
489
- description: translate(options.locale ?? options.startupConfiguration?.locale ?? DEFAULT_LOCALE, "newSessionDescription"),
490
- open: async () => {
491
- const filePath = newSessionPath(dirname(sessionFile), now);
492
- const nextManager = await SessionManager.create({
493
- filePath,
494
- cwd: allowedRoot,
495
- now,
496
- deferCreate: true,
497
- });
498
- return new AgentSession({
499
- allowedRoot,
500
- provider: runtime.provider,
501
- model: runtime.model,
502
- systemPrompt,
503
- skills: resources.skills,
504
- now: options.now,
505
- sessionManager: nextManager,
506
- extensionHost: extensions.host,
507
- externalTools: mcp.tools,
508
- });
509
- },
510
- },
511
- ...(await sessionChoices(dirname(sessionFile), sessionFile, async (filePath) => {
512
- const nextManager = await SessionManager.open(filePath, { now });
513
- return new AgentSession({
514
- allowedRoot,
515
- provider: runtime.provider,
516
- model: runtime.model,
517
- systemPrompt,
518
- skills: resources.skills,
519
- now: options.now,
520
- sessionManager: nextManager,
521
- extensionHost: extensions.host,
522
- externalTools: mcp.tools,
523
- });
524
- })),
525
- ],
526
- });
527
- mode.start(command.prompt);
528
- return 0;
529
- }
530
- await extensions.host.emit({ type: "session_start", cwd: allowedRoot });
125
+ }
126
+ else {
127
+ name = command.mode;
128
+ input = { prompt: command.prompt, stdout: options.stdout };
129
+ }
130
+ const code = await host.execute(name, input, context.signal);
131
+ const processExit = context.require(processExitKey);
132
+ processExit.setCode(code);
133
+ return processExit.code();
134
+ }
135
+ catch (cause) {
136
+ options.stderr(`${errorMessage(cause).replace(/^Required entry agent-loop failed: /, "")}\n`);
137
+ return 1;
138
+ }
139
+ finally {
140
+ const memory = context.get(sessionStoreKey);
141
+ try {
531
142
  try {
532
- return await runPrintMode(command.prompt, promptRunner, options);
143
+ await loader.dispose();
533
144
  }
534
145
  finally {
535
- await extensions.host.emit({ type: "session_shutdown", reason: "user" });
536
- await mcp.manager.close();
146
+ await context.dispose();
537
147
  }
538
- },
539
- };
540
- return runCli(args, dependencies);
148
+ }
149
+ finally {
150
+ unsubscribe();
151
+ if (memory) {
152
+ memory.dispose();
153
+ if (memory.disposed())
154
+ options.onSessionDisposed?.();
155
+ }
156
+ }
157
+ }
541
158
  }
542
159
  //# sourceMappingURL=main.js.map