@draht/coding-agent 2026.5.12 → 2026.6.11

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 (605) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/bin/draht-tools.cjs +3756 -1
  3. package/dist/bun/cli.d.ts.map +1 -1
  4. package/dist/bun/cli.js +4 -2
  5. package/dist/bun/cli.js.map +1 -1
  6. package/dist/bun/restore-sandbox-env.d.ts +13 -0
  7. package/dist/bun/restore-sandbox-env.d.ts.map +1 -0
  8. package/dist/bun/restore-sandbox-env.js +32 -0
  9. package/dist/bun/restore-sandbox-env.js.map +1 -0
  10. package/dist/cli/args.d.ts +9 -4
  11. package/dist/cli/args.d.ts.map +1 -1
  12. package/dist/cli/args.js +88 -35
  13. package/dist/cli/args.js.map +1 -1
  14. package/dist/cli/config-selector.d.ts +2 -2
  15. package/dist/cli/config-selector.d.ts.map +1 -1
  16. package/dist/cli/config-selector.js +1 -1
  17. package/dist/cli/config-selector.js.map +1 -1
  18. package/dist/cli/file-processor.d.ts.map +1 -1
  19. package/dist/cli/file-processor.js +2 -3
  20. package/dist/cli/file-processor.js.map +1 -1
  21. package/dist/cli/initial-message.d.ts +1 -1
  22. package/dist/cli/initial-message.d.ts.map +1 -1
  23. package/dist/cli/initial-message.js.map +1 -1
  24. package/dist/cli/list-models.d.ts +1 -1
  25. package/dist/cli/list-models.d.ts.map +1 -1
  26. package/dist/cli/list-models.js +7 -1
  27. package/dist/cli/list-models.js.map +1 -1
  28. package/dist/cli/project-trust.d.ts +10 -0
  29. package/dist/cli/project-trust.d.ts.map +1 -0
  30. package/dist/cli/project-trust.js +48 -0
  31. package/dist/cli/project-trust.js.map +1 -0
  32. package/dist/cli/session-picker.d.ts +1 -1
  33. package/dist/cli/session-picker.d.ts.map +1 -1
  34. package/dist/cli/session-picker.js.map +1 -1
  35. package/dist/cli/startup-ui.d.ts +16 -0
  36. package/dist/cli/startup-ui.d.ts.map +1 -0
  37. package/dist/cli/startup-ui.js +112 -0
  38. package/dist/cli/startup-ui.js.map +1 -0
  39. package/dist/cli.d.ts.map +1 -1
  40. package/dist/cli.js +7 -4
  41. package/dist/cli.js.map +1 -1
  42. package/dist/config.d.ts +23 -13
  43. package/dist/config.d.ts.map +1 -1
  44. package/dist/config.js +264 -62
  45. package/dist/config.js.map +1 -1
  46. package/dist/core/agent-session-runtime.d.ts +45 -9
  47. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  48. package/dist/core/agent-session-runtime.js +100 -33
  49. package/dist/core/agent-session-runtime.js.map +1 -1
  50. package/dist/core/agent-session-services.d.ts +6 -4
  51. package/dist/core/agent-session-services.d.ts.map +1 -1
  52. package/dist/core/agent-session-services.js +7 -4
  53. package/dist/core/agent-session-services.js.map +1 -1
  54. package/dist/core/agent-session.d.ts +47 -31
  55. package/dist/core/agent-session.d.ts.map +1 -1
  56. package/dist/core/agent-session.js +470 -443
  57. package/dist/core/agent-session.js.map +1 -1
  58. package/dist/core/auth-guidance.d.ts +5 -0
  59. package/dist/core/auth-guidance.d.ts.map +1 -0
  60. package/dist/core/auth-guidance.js +21 -0
  61. package/dist/core/auth-guidance.js.map +1 -0
  62. package/dist/core/auth-storage.d.ts +10 -1
  63. package/dist/core/auth-storage.d.ts.map +1 -1
  64. package/dist/core/auth-storage.js +27 -6
  65. package/dist/core/auth-storage.js.map +1 -1
  66. package/dist/core/bash-executor.d.ts +1 -15
  67. package/dist/core/bash-executor.d.ts.map +1 -1
  68. package/dist/core/bash-executor.js +10 -24
  69. package/dist/core/bash-executor.js.map +1 -1
  70. package/dist/core/builtins/subagent.d.ts.map +1 -1
  71. package/dist/core/builtins/subagent.js +1 -2
  72. package/dist/core/builtins/subagent.js.map +1 -1
  73. package/dist/core/compaction/branch-summarization.d.ts +6 -4
  74. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  75. package/dist/core/compaction/branch-summarization.js +9 -3
  76. package/dist/core/compaction/branch-summarization.js.map +1 -1
  77. package/dist/core/compaction/compaction.d.ts +5 -5
  78. package/dist/core/compaction/compaction.d.ts.map +1 -1
  79. package/dist/core/compaction/compaction.js +43 -37
  80. package/dist/core/compaction/compaction.js.map +1 -1
  81. package/dist/core/compaction/index.d.ts +3 -3
  82. package/dist/core/compaction/index.d.ts.map +1 -1
  83. package/dist/core/compaction/index.js.map +1 -1
  84. package/dist/core/compaction/utils.d.ts +1 -1
  85. package/dist/core/compaction/utils.d.ts.map +1 -1
  86. package/dist/core/compaction/utils.js +1 -1
  87. package/dist/core/compaction/utils.js.map +1 -1
  88. package/dist/core/exec.d.ts.map +1 -1
  89. package/dist/core/exec.js.map +1 -1
  90. package/dist/core/experimental.d.ts +2 -0
  91. package/dist/core/experimental.d.ts.map +1 -0
  92. package/dist/core/experimental.js +4 -0
  93. package/dist/core/experimental.js.map +1 -0
  94. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
  95. package/dist/core/export-html/ansi-to-html.js +1 -1
  96. package/dist/core/export-html/ansi-to-html.js.map +1 -1
  97. package/dist/core/export-html/index.d.ts +1 -1
  98. package/dist/core/export-html/index.d.ts.map +1 -1
  99. package/dist/core/export-html/index.js +13 -11
  100. package/dist/core/export-html/index.js.map +1 -1
  101. package/dist/core/export-html/template.css +69 -4
  102. package/dist/core/export-html/template.js +231 -57
  103. package/dist/core/export-html/tool-renderer.d.ts +0 -6
  104. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  105. package/dist/core/export-html/tool-renderer.js +15 -2
  106. package/dist/core/export-html/tool-renderer.js.map +1 -1
  107. package/dist/core/extensions/index.d.ts +8 -8
  108. package/dist/core/extensions/index.d.ts.map +1 -1
  109. package/dist/core/extensions/index.js.map +1 -1
  110. package/dist/core/extensions/loader.d.ts +3 -3
  111. package/dist/core/extensions/loader.d.ts.map +1 -1
  112. package/dist/core/extensions/loader.js +27 -35
  113. package/dist/core/extensions/loader.js.map +1 -1
  114. package/dist/core/extensions/runner.d.ts +30 -12
  115. package/dist/core/extensions/runner.d.ts.map +1 -1
  116. package/dist/core/extensions/runner.js +215 -32
  117. package/dist/core/extensions/runner.js.map +1 -1
  118. package/dist/core/extensions/types.d.ts +163 -35
  119. package/dist/core/extensions/types.d.ts.map +1 -1
  120. package/dist/core/extensions/types.js.map +1 -1
  121. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  122. package/dist/core/extensions/wrapper.js +2 -2
  123. package/dist/core/extensions/wrapper.js.map +1 -1
  124. package/dist/core/footer-data-provider.d.ts +7 -1
  125. package/dist/core/footer-data-provider.d.ts.map +1 -1
  126. package/dist/core/footer-data-provider.js +78 -54
  127. package/dist/core/footer-data-provider.js.map +1 -1
  128. package/dist/core/http-dispatcher.d.ts +21 -0
  129. package/dist/core/http-dispatcher.d.ts.map +1 -0
  130. package/dist/core/http-dispatcher.js +48 -0
  131. package/dist/core/http-dispatcher.js.map +1 -0
  132. package/dist/core/index.d.ts +9 -8
  133. package/dist/core/index.d.ts.map +1 -1
  134. package/dist/core/index.js +2 -1
  135. package/dist/core/index.js.map +1 -1
  136. package/dist/core/keybindings.d.ts +66 -1
  137. package/dist/core/keybindings.d.ts.map +1 -1
  138. package/dist/core/keybindings.js +56 -1
  139. package/dist/core/keybindings.js.map +1 -1
  140. package/dist/core/model-registry.d.ts +22 -4
  141. package/dist/core/model-registry.d.ts.map +1 -1
  142. package/dist/core/model-registry.js +216 -44
  143. package/dist/core/model-registry.js.map +1 -1
  144. package/dist/core/model-resolver.d.ts +2 -1
  145. package/dist/core/model-resolver.d.ts.map +1 -1
  146. package/dist/core/model-resolver.js +48 -21
  147. package/dist/core/model-resolver.js.map +1 -1
  148. package/dist/core/output-guard.d.ts +1 -0
  149. package/dist/core/output-guard.d.ts.map +1 -1
  150. package/dist/core/output-guard.js +52 -22
  151. package/dist/core/output-guard.js.map +1 -1
  152. package/dist/core/package-manager.d.ts +17 -2
  153. package/dist/core/package-manager.d.ts.map +1 -1
  154. package/dist/core/package-manager.js +363 -121
  155. package/dist/core/package-manager.js.map +1 -1
  156. package/dist/core/project-trust.d.ts +15 -0
  157. package/dist/core/project-trust.d.ts.map +1 -0
  158. package/dist/core/project-trust.js +58 -0
  159. package/dist/core/project-trust.js.map +1 -0
  160. package/dist/core/prompt-templates.d.ts +13 -11
  161. package/dist/core/prompt-templates.d.ts.map +1 -1
  162. package/dist/core/prompt-templates.js +67 -76
  163. package/dist/core/prompt-templates.js.map +1 -1
  164. package/dist/core/provider-attribution.d.ts +4 -0
  165. package/dist/core/provider-attribution.d.ts.map +1 -0
  166. package/dist/core/provider-attribution.js +72 -0
  167. package/dist/core/provider-attribution.js.map +1 -0
  168. package/dist/core/provider-display-names.d.ts +2 -0
  169. package/dist/core/provider-display-names.d.ts.map +1 -0
  170. package/dist/core/provider-display-names.js +36 -0
  171. package/dist/core/provider-display-names.js.map +1 -0
  172. package/dist/core/resolve-config-value.d.ts +9 -1
  173. package/dist/core/resolve-config-value.d.ts.map +1 -1
  174. package/dist/core/resolve-config-value.js +134 -11
  175. package/dist/core/resolve-config-value.js.map +1 -1
  176. package/dist/core/resource-loader.d.ts +34 -14
  177. package/dist/core/resource-loader.d.ts.map +1 -1
  178. package/dist/core/resource-loader.js +165 -76
  179. package/dist/core/resource-loader.js.map +1 -1
  180. package/dist/core/sdk.d.ts +26 -10
  181. package/dist/core/sdk.d.ts.map +1 -1
  182. package/dist/core/sdk.js +45 -16
  183. package/dist/core/sdk.js.map +1 -1
  184. package/dist/core/session-manager.d.ts +11 -12
  185. package/dist/core/session-manager.d.ts.map +1 -1
  186. package/dist/core/session-manager.js +245 -132
  187. package/dist/core/session-manager.js.map +1 -1
  188. package/dist/core/settings-manager.d.ts +52 -5
  189. package/dist/core/settings-manager.d.ts.map +1 -1
  190. package/dist/core/settings-manager.js +202 -38
  191. package/dist/core/settings-manager.js.map +1 -1
  192. package/dist/core/skills.d.ts +10 -10
  193. package/dist/core/skills.d.ts.map +1 -1
  194. package/dist/core/skills.js +13 -35
  195. package/dist/core/skills.js.map +1 -1
  196. package/dist/core/slash-commands.d.ts +1 -1
  197. package/dist/core/slash-commands.d.ts.map +1 -1
  198. package/dist/core/slash-commands.js +7 -4
  199. package/dist/core/slash-commands.js.map +1 -1
  200. package/dist/core/source-info.d.ts +1 -1
  201. package/dist/core/source-info.d.ts.map +1 -1
  202. package/dist/core/source-info.js.map +1 -1
  203. package/dist/core/system-prompt.d.ts +4 -4
  204. package/dist/core/system-prompt.d.ts.map +1 -1
  205. package/dist/core/system-prompt.js +14 -10
  206. package/dist/core/system-prompt.js.map +1 -1
  207. package/dist/core/telemetry.d.ts +3 -0
  208. package/dist/core/telemetry.d.ts.map +1 -0
  209. package/dist/core/telemetry.js +9 -0
  210. package/dist/core/telemetry.js.map +1 -0
  211. package/dist/core/tools/bash.d.ts +11 -16
  212. package/dist/core/tools/bash.d.ts.map +1 -1
  213. package/dist/core/tools/bash.js +162 -177
  214. package/dist/core/tools/bash.js.map +1 -1
  215. package/dist/core/tools/edit-diff.d.ts +3 -1
  216. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  217. package/dist/core/tools/edit-diff.js +11 -3
  218. package/dist/core/tools/edit-diff.js.map +1 -1
  219. package/dist/core/tools/edit.d.ts +22 -24
  220. package/dist/core/tools/edit.d.ts.map +1 -1
  221. package/dist/core/tools/edit.js +199 -111
  222. package/dist/core/tools/edit.js.map +1 -1
  223. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
  224. package/dist/core/tools/file-mutation-queue.js +27 -12
  225. package/dist/core/tools/file-mutation-queue.js.map +1 -1
  226. package/dist/core/tools/find.d.ts +7 -18
  227. package/dist/core/tools/find.d.ts.map +1 -1
  228. package/dist/core/tools/find.js +134 -95
  229. package/dist/core/tools/find.js.map +1 -1
  230. package/dist/core/tools/grep.d.ts +11 -30
  231. package/dist/core/tools/grep.d.ts.map +1 -1
  232. package/dist/core/tools/grep.js +23 -12
  233. package/dist/core/tools/grep.js.map +1 -1
  234. package/dist/core/tools/index.d.ts +26 -101
  235. package/dist/core/tools/index.d.ts.map +1 -1
  236. package/dist/core/tools/index.js +78 -52
  237. package/dist/core/tools/index.js.map +1 -1
  238. package/dist/core/tools/ls.d.ts +6 -15
  239. package/dist/core/tools/ls.d.ts.map +1 -1
  240. package/dist/core/tools/ls.js +12 -17
  241. package/dist/core/tools/ls.js.map +1 -1
  242. package/dist/core/tools/output-accumulator.d.ts +52 -0
  243. package/dist/core/tools/output-accumulator.d.ts.map +1 -0
  244. package/dist/core/tools/output-accumulator.js +184 -0
  245. package/dist/core/tools/output-accumulator.js.map +1 -0
  246. package/dist/core/tools/path-utils.d.ts +2 -0
  247. package/dist/core/tools/path-utils.d.ts.map +1 -1
  248. package/dist/core/tools/path-utils.js +40 -22
  249. package/dist/core/tools/path-utils.js.map +1 -1
  250. package/dist/core/tools/read.d.ts +7 -18
  251. package/dist/core/tools/read.d.ts.map +1 -1
  252. package/dist/core/tools/read.js +100 -36
  253. package/dist/core/tools/read.js.map +1 -1
  254. package/dist/core/tools/render-utils.d.ts +5 -2
  255. package/dist/core/tools/render-utils.d.ts.map +1 -1
  256. package/dist/core/tools/render-utils.js +18 -2
  257. package/dist/core/tools/render-utils.js.map +1 -1
  258. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  259. package/dist/core/tools/tool-definition-wrapper.js +2 -0
  260. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  261. package/dist/core/tools/truncate.d.ts.map +1 -1
  262. package/dist/core/tools/truncate.js +12 -2
  263. package/dist/core/tools/truncate.js.map +1 -1
  264. package/dist/core/tools/write.d.ts +5 -14
  265. package/dist/core/tools/write.d.ts.map +1 -1
  266. package/dist/core/tools/write.js +27 -46
  267. package/dist/core/tools/write.js.map +1 -1
  268. package/dist/core/trust-manager.d.ts +31 -0
  269. package/dist/core/trust-manager.d.ts.map +1 -0
  270. package/dist/core/trust-manager.js +187 -0
  271. package/dist/core/trust-manager.js.map +1 -0
  272. package/dist/index.d.ts +31 -29
  273. package/dist/index.d.ts.map +1 -1
  274. package/dist/index.js +9 -8
  275. package/dist/index.js.map +1 -1
  276. package/dist/main.d.ts +5 -1
  277. package/dist/main.d.ts.map +1 -1
  278. package/dist/main.js +170 -87
  279. package/dist/main.js.map +1 -1
  280. package/dist/migrations.d.ts +2 -2
  281. package/dist/migrations.d.ts.map +1 -1
  282. package/dist/migrations.js +127 -5
  283. package/dist/migrations.js.map +1 -1
  284. package/dist/modes/index.d.ts +5 -5
  285. package/dist/modes/index.d.ts.map +1 -1
  286. package/dist/modes/index.js.map +1 -1
  287. package/dist/modes/interactive/components/assistant-message.d.ts +2 -0
  288. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  289. package/dist/modes/interactive/components/assistant-message.js +14 -0
  290. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  291. package/dist/modes/interactive/components/bash-execution.d.ts +1 -1
  292. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  293. package/dist/modes/interactive/components/bash-execution.js +3 -3
  294. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  295. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
  296. package/dist/modes/interactive/components/bordered-loader.js +3 -0
  297. package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
  298. package/dist/modes/interactive/components/config-selector.d.ts +4 -4
  299. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  300. package/dist/modes/interactive/components/config-selector.js +38 -11
  301. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  302. package/dist/modes/interactive/components/countdown-timer.d.ts +2 -2
  303. package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
  304. package/dist/modes/interactive/components/countdown-timer.js +2 -2
  305. package/dist/modes/interactive/components/countdown-timer.js.map +1 -1
  306. package/dist/modes/interactive/components/custom-editor.d.ts +1 -1
  307. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  308. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  309. package/dist/modes/interactive/components/custom-message.d.ts +2 -2
  310. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  311. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  312. package/dist/modes/interactive/components/diff.d.ts.map +1 -1
  313. package/dist/modes/interactive/components/diff.js.map +1 -1
  314. package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -1
  315. package/dist/modes/interactive/components/earendil-announcement.js.map +1 -1
  316. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  317. package/dist/modes/interactive/components/extension-editor.js +14 -6
  318. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  319. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  320. package/dist/modes/interactive/components/extension-input.js.map +1 -1
  321. package/dist/modes/interactive/components/extension-selector.d.ts +2 -0
  322. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  323. package/dist/modes/interactive/components/extension-selector.js +8 -3
  324. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  325. package/dist/modes/interactive/components/first-time-setup.d.ts +25 -0
  326. package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -0
  327. package/dist/modes/interactive/components/first-time-setup.js +103 -0
  328. package/dist/modes/interactive/components/first-time-setup.js.map +1 -0
  329. package/dist/modes/interactive/components/footer.d.ts +2 -1
  330. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  331. package/dist/modes/interactive/components/footer.js +23 -7
  332. package/dist/modes/interactive/components/footer.js.map +1 -1
  333. package/dist/modes/interactive/components/index.d.ts +33 -31
  334. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  335. package/dist/modes/interactive/components/index.js +2 -0
  336. package/dist/modes/interactive/components/index.js.map +1 -1
  337. package/dist/modes/interactive/components/keybinding-hints.d.ts +5 -0
  338. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  339. package/dist/modes/interactive/components/keybinding-hints.js +19 -5
  340. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  341. package/dist/modes/interactive/components/login-dialog.d.ts +12 -2
  342. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  343. package/dist/modes/interactive/components/login-dialog.js +46 -11
  344. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  345. package/dist/modes/interactive/components/model-selector.d.ts +2 -2
  346. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  347. package/dist/modes/interactive/components/model-selector.js +8 -5
  348. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  349. package/dist/modes/interactive/components/oauth-selector.d.ts +18 -6
  350. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  351. package/dist/modes/interactive/components/oauth-selector.js +93 -25
  352. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  353. package/dist/modes/interactive/components/scoped-models-selector.d.ts +5 -12
  354. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  355. package/dist/modes/interactive/components/scoped-models-selector.js +45 -30
  356. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  357. package/dist/modes/interactive/components/session-selector.d.ts +2 -1
  358. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  359. package/dist/modes/interactive/components/session-selector.js +20 -7
  360. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  361. package/dist/modes/interactive/components/settings-selector.d.ts +13 -0
  362. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  363. package/dist/modes/interactive/components/settings-selector.js +113 -4
  364. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  365. package/dist/modes/interactive/components/skill-invocation-message.d.ts +1 -1
  366. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  367. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  368. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  369. package/dist/modes/interactive/components/thinking-selector.js +1 -1
  370. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  371. package/dist/modes/interactive/components/tool-execution.d.ts +6 -1
  372. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  373. package/dist/modes/interactive/components/tool-execution.js +57 -14
  374. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  375. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  376. package/dist/modes/interactive/components/tree-selector.js +18 -9
  377. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  378. package/dist/modes/interactive/components/trust-selector.d.ts +23 -0
  379. package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -0
  380. package/dist/modes/interactive/components/trust-selector.js +91 -0
  381. package/dist/modes/interactive/components/trust-selector.js.map +1 -0
  382. package/dist/modes/interactive/components/user-message-selector.d.ts +2 -2
  383. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
  384. package/dist/modes/interactive/components/user-message-selector.js +8 -7
  385. package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
  386. package/dist/modes/interactive/components/user-message.d.ts +1 -0
  387. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  388. package/dist/modes/interactive/components/user-message.js +8 -7
  389. package/dist/modes/interactive/components/user-message.js.map +1 -1
  390. package/dist/modes/interactive/interactive-mode.d.ts +68 -13
  391. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  392. package/dist/modes/interactive/interactive-mode.js +1100 -319
  393. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  394. package/dist/modes/interactive/theme/dark.json +5 -4
  395. package/dist/modes/interactive/theme/light.json +5 -4
  396. package/dist/modes/interactive/theme/theme.d.ts +22 -3
  397. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  398. package/dist/modes/interactive/theme/theme.js +160 -105
  399. package/dist/modes/interactive/theme/theme.js.map +1 -1
  400. package/dist/modes/print-mode.d.ts.map +1 -1
  401. package/dist/modes/print-mode.js +40 -20
  402. package/dist/modes/print-mode.js.map +1 -1
  403. package/dist/modes/rpc/rpc-client.d.ts +11 -1
  404. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  405. package/dist/modes/rpc/rpc-client.js +73 -8
  406. package/dist/modes/rpc/rpc-client.js.map +1 -1
  407. package/dist/modes/rpc/rpc-mode.d.ts +2 -2
  408. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  409. package/dist/modes/rpc/rpc-mode.js +96 -30
  410. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  411. package/dist/modes/rpc/rpc-types.d.ts +16 -4
  412. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  413. package/dist/modes/rpc/rpc-types.js.map +1 -1
  414. package/dist/package-manager-cli.d.ts +6 -2
  415. package/dist/package-manager-cli.d.ts.map +1 -1
  416. package/dist/package-manager-cli.js +396 -21
  417. package/dist/package-manager-cli.js.map +1 -1
  418. package/dist/prompts/commands/map-codebase.md +14 -0
  419. package/dist/utils/ansi.d.ts +2 -0
  420. package/dist/utils/ansi.d.ts.map +1 -0
  421. package/dist/utils/ansi.js +52 -0
  422. package/dist/utils/ansi.js.map +1 -0
  423. package/dist/utils/changelog.d.ts +2 -1
  424. package/dist/utils/changelog.d.ts.map +1 -1
  425. package/dist/utils/changelog.js +78 -0
  426. package/dist/utils/changelog.js.map +1 -1
  427. package/dist/utils/child-process.d.ts +5 -1
  428. package/dist/utils/child-process.d.ts.map +1 -1
  429. package/dist/utils/child-process.js +10 -0
  430. package/dist/utils/child-process.js.map +1 -1
  431. package/dist/utils/clipboard-image.d.ts.map +1 -1
  432. package/dist/utils/clipboard-image.js +2 -2
  433. package/dist/utils/clipboard-image.js.map +1 -1
  434. package/dist/utils/clipboard-native.d.ts +3 -1
  435. package/dist/utils/clipboard-native.d.ts.map +1 -1
  436. package/dist/utils/clipboard-native.js +14 -8
  437. package/dist/utils/clipboard-native.js.map +1 -1
  438. package/dist/utils/clipboard.d.ts.map +1 -1
  439. package/dist/utils/clipboard.js +84 -45
  440. package/dist/utils/clipboard.js.map +1 -1
  441. package/dist/utils/deprecation.d.ts +4 -0
  442. package/dist/utils/deprecation.d.ts.map +1 -0
  443. package/dist/utils/deprecation.js +13 -0
  444. package/dist/utils/deprecation.js.map +1 -0
  445. package/dist/utils/exif-orientation.d.ts +1 -1
  446. package/dist/utils/exif-orientation.d.ts.map +1 -1
  447. package/dist/utils/exif-orientation.js.map +1 -1
  448. package/dist/utils/fs-watch.d.ts +5 -0
  449. package/dist/utils/fs-watch.d.ts.map +1 -0
  450. package/dist/utils/fs-watch.js +25 -0
  451. package/dist/utils/fs-watch.js.map +1 -0
  452. package/dist/utils/git.d.ts.map +1 -1
  453. package/dist/utils/git.js +54 -22
  454. package/dist/utils/git.js.map +1 -1
  455. package/dist/utils/html.d.ts +7 -0
  456. package/dist/utils/html.d.ts.map +1 -0
  457. package/dist/utils/html.js +40 -0
  458. package/dist/utils/html.js.map +1 -0
  459. package/dist/utils/image-convert.d.ts.map +1 -1
  460. package/dist/utils/image-convert.js.map +1 -1
  461. package/dist/utils/image-resize-core.d.ts +30 -0
  462. package/dist/utils/image-resize-core.d.ts.map +1 -0
  463. package/dist/utils/image-resize-core.js +124 -0
  464. package/dist/utils/image-resize-core.js.map +1 -0
  465. package/dist/utils/image-resize-worker.d.ts +2 -0
  466. package/dist/utils/image-resize-worker.d.ts.map +1 -0
  467. package/dist/utils/image-resize-worker.js +31 -0
  468. package/dist/utils/image-resize-worker.js.map +1 -0
  469. package/dist/utils/image-resize.d.ts +7 -27
  470. package/dist/utils/image-resize.d.ts.map +1 -1
  471. package/dist/utils/image-resize.js +75 -115
  472. package/dist/utils/image-resize.js.map +1 -1
  473. package/dist/utils/json.d.ts +3 -0
  474. package/dist/utils/json.d.ts.map +1 -0
  475. package/dist/utils/json.js +7 -0
  476. package/dist/utils/json.js.map +1 -0
  477. package/dist/utils/mime.d.ts +1 -0
  478. package/dist/utils/mime.d.ts.map +1 -1
  479. package/dist/utils/mime.js +59 -16
  480. package/dist/utils/mime.js.map +1 -1
  481. package/dist/utils/open-browser.d.ts +9 -0
  482. package/dist/utils/open-browser.d.ts.map +1 -0
  483. package/dist/utils/open-browser.js +22 -0
  484. package/dist/utils/open-browser.js.map +1 -0
  485. package/dist/utils/paths.d.ts +25 -1
  486. package/dist/utils/paths.d.ts.map +1 -1
  487. package/dist/utils/paths.js +75 -2
  488. package/dist/utils/paths.js.map +1 -1
  489. package/dist/utils/pi-user-agent.d.ts +2 -0
  490. package/dist/utils/pi-user-agent.d.ts.map +1 -0
  491. package/dist/utils/pi-user-agent.js +5 -0
  492. package/dist/utils/pi-user-agent.js.map +1 -0
  493. package/dist/utils/shell.d.ts +10 -6
  494. package/dist/utils/shell.d.ts.map +1 -1
  495. package/dist/utils/shell.js +35 -26
  496. package/dist/utils/shell.js.map +1 -1
  497. package/dist/utils/syntax-highlight.d.ts +12 -0
  498. package/dist/utils/syntax-highlight.d.ts.map +1 -0
  499. package/dist/utils/syntax-highlight.js +118 -0
  500. package/dist/utils/syntax-highlight.js.map +1 -0
  501. package/dist/utils/tools-manager.d.ts.map +1 -1
  502. package/dist/utils/tools-manager.js +86 -10
  503. package/dist/utils/tools-manager.js.map +1 -1
  504. package/dist/utils/version-check.d.ts +15 -0
  505. package/dist/utils/version-check.d.ts.map +1 -0
  506. package/dist/utils/version-check.js +82 -0
  507. package/dist/utils/version-check.js.map +1 -0
  508. package/dist/utils/windows-self-update.d.ts +3 -0
  509. package/dist/utils/windows-self-update.d.ts.map +1 -0
  510. package/dist/utils/windows-self-update.js +77 -0
  511. package/dist/utils/windows-self-update.js.map +1 -0
  512. package/docs/compaction.md +12 -12
  513. package/docs/containerization.md +111 -0
  514. package/docs/custom-provider.md +187 -47
  515. package/docs/development.md +5 -5
  516. package/docs/docs.json +156 -0
  517. package/docs/extensions.md +465 -71
  518. package/docs/index.md +82 -0
  519. package/docs/json.md +4 -4
  520. package/docs/keybindings.md +23 -1
  521. package/docs/models.md +119 -17
  522. package/docs/packages.md +17 -9
  523. package/docs/prompt-templates.md +30 -2
  524. package/docs/providers.md +83 -22
  525. package/docs/quickstart.md +165 -0
  526. package/docs/rpc.md +41 -10
  527. package/docs/sdk.md +68 -50
  528. package/docs/security.md +55 -0
  529. package/docs/{session.md → session-format.md} +11 -11
  530. package/docs/sessions.md +145 -0
  531. package/docs/settings.md +61 -11
  532. package/docs/skills.md +16 -17
  533. package/docs/terminal-setup.md +44 -2
  534. package/docs/termux.md +4 -4
  535. package/docs/themes.md +3 -3
  536. package/docs/tmux.md +4 -2
  537. package/docs/tui.md +44 -4
  538. package/docs/usage.md +305 -0
  539. package/examples/extensions/border-status-editor.ts +145 -0
  540. package/examples/extensions/built-in-tool-renderer.ts +3 -0
  541. package/examples/extensions/custom-header.ts +1 -1
  542. package/examples/extensions/custom-provider-anthropic/index.ts +1 -1
  543. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  544. package/examples/extensions/custom-provider-anthropic/package.json +2 -2
  545. package/examples/extensions/custom-provider-gitlab-duo/index.ts +55 -4
  546. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  547. package/examples/extensions/custom-provider-gitlab-duo/test.ts +1 -1
  548. package/examples/extensions/doom-overlay/doom-component.ts +2 -2
  549. package/examples/extensions/doom-overlay/index.ts +1 -1
  550. package/examples/extensions/dynamic-resources/dynamic.json +1 -1
  551. package/examples/extensions/dynamic-tools.ts +2 -2
  552. package/examples/extensions/git-merge-and-resolve.ts +115 -0
  553. package/examples/extensions/github-issue-autocomplete.ts +185 -0
  554. package/examples/extensions/gondolin/index.ts +531 -0
  555. package/examples/extensions/gondolin/package-lock.json +185 -0
  556. package/examples/extensions/gondolin/package.json +19 -0
  557. package/examples/extensions/handoff.ts +50 -12
  558. package/examples/extensions/input-transform-streaming.ts +39 -0
  559. package/examples/extensions/interactive-shell.ts +1 -1
  560. package/examples/extensions/notify.ts +2 -9
  561. package/examples/extensions/overlay-qa-tests.ts +240 -138
  562. package/examples/extensions/overlay-test.ts +7 -4
  563. package/examples/extensions/plan-mode/utils.ts +1 -1
  564. package/examples/extensions/preset.ts +36 -3
  565. package/examples/extensions/project-trust.ts +64 -0
  566. package/examples/extensions/prompt-customizer.ts +97 -0
  567. package/examples/extensions/provider-payload.ts +4 -0
  568. package/examples/extensions/qna.ts +1 -1
  569. package/examples/extensions/question.ts +2 -2
  570. package/examples/extensions/questionnaire.ts +2 -2
  571. package/examples/extensions/reload-runtime.ts +1 -1
  572. package/examples/extensions/sandbox/index.ts +4 -4
  573. package/examples/extensions/sandbox/package-lock.json +5 -5
  574. package/examples/extensions/sandbox/package.json +2 -2
  575. package/examples/extensions/shutdown-command.ts +1 -1
  576. package/examples/extensions/snake.ts +1 -1
  577. package/examples/extensions/space-invaders.ts +1 -1
  578. package/examples/extensions/structured-output.ts +65 -0
  579. package/examples/extensions/subagent/index.ts +51 -28
  580. package/examples/extensions/summarize.ts +1 -1
  581. package/examples/extensions/tic-tac-toe.ts +1008 -0
  582. package/examples/extensions/titlebar-spinner.ts +2 -2
  583. package/examples/extensions/todo.ts +2 -2
  584. package/examples/extensions/tool-override.ts +1 -1
  585. package/examples/extensions/tools.ts +5 -0
  586. package/examples/extensions/truncated-tool.ts +1 -1
  587. package/examples/extensions/with-deps/index.ts +1 -1
  588. package/examples/extensions/with-deps/package-lock.json +2 -2
  589. package/examples/extensions/with-deps/package.json +3 -3
  590. package/examples/extensions/working-indicator.ts +123 -0
  591. package/examples/extensions/working-message-test.ts +25 -0
  592. package/examples/sdk/01-minimal.ts +14 -10
  593. package/examples/sdk/02-custom-model.ts +12 -8
  594. package/examples/sdk/03-custom-prompt.ts +32 -17
  595. package/examples/sdk/04-skills.ts +5 -2
  596. package/examples/sdk/05-tools.ts +23 -31
  597. package/examples/sdk/06-extensions.ts +14 -8
  598. package/examples/sdk/07-context-files.ts +5 -3
  599. package/examples/sdk/08-prompt-templates.ts +5 -2
  600. package/examples/sdk/09-api-keys-and-oauth.ts +8 -4
  601. package/examples/sdk/10-settings.ts +8 -6
  602. package/examples/sdk/11-sessions.ts +4 -0
  603. package/examples/sdk/12-full-control.ts +13 -17
  604. package/package.json +13 -6
  605. package/prompts/commands/map-codebase.md +14 -0
@@ -40,6 +40,7 @@
40
40
 
41
41
  import { existsSync, readFileSync } from "node:fs";
42
42
  import { join } from "node:path";
43
+ import type { Api, Model } from "@draht/ai";
43
44
  import type { ExtensionAPI, ExtensionContext } from "@draht/coding-agent";
44
45
  import { DynamicBorder, getAgentDir } from "@draht/coding-agent";
45
46
  import { Container, Key, type SelectItem, SelectList, Text } from "@draht/tui";
@@ -97,10 +98,17 @@ function loadPresets(cwd: string): PresetsConfig {
97
98
  return { ...globalPresets, ...projectPresets };
98
99
  }
99
100
 
101
+ interface OriginalState {
102
+ model: Model<Api> | undefined;
103
+ thinkingLevel: "off" | "minimal" | "low" | "medium" | "high" | "xhigh";
104
+ tools: string[];
105
+ }
106
+
100
107
  export default function presetExtension(pi: ExtensionAPI) {
101
108
  let presets: PresetsConfig = {};
102
109
  let activePresetName: string | undefined;
103
110
  let activePreset: Preset | undefined;
111
+ let originalState: OriginalState | undefined;
104
112
 
105
113
  // Register --preset CLI flag
106
114
  pi.registerFlag("preset", {
@@ -112,6 +120,15 @@ export default function presetExtension(pi: ExtensionAPI) {
112
120
  * Apply a preset configuration.
113
121
  */
114
122
  async function applyPreset(name: string, preset: Preset, ctx: ExtensionContext): Promise<boolean> {
123
+ // Snapshot state before the first preset is applied (i.e. only when transitioning from no-preset)
124
+ if (activePresetName === undefined) {
125
+ originalState = {
126
+ model: ctx.model,
127
+ thinkingLevel: pi.getThinkingLevel(),
128
+ tools: pi.getActiveTools(),
129
+ };
130
+ }
131
+
115
132
  // Apply model if specified
116
133
  if (preset.provider && preset.model) {
117
134
  const model = ctx.modelRegistry.find(preset.provider, preset.model);
@@ -248,10 +265,18 @@ export default function presetExtension(pi: ExtensionAPI) {
248
265
  if (!result) return;
249
266
 
250
267
  if (result === "(none)") {
251
- // Clear preset and restore defaults
268
+ // Clear preset and restore original state
252
269
  activePresetName = undefined;
253
270
  activePreset = undefined;
254
- pi.setActiveTools(["read", "bash", "edit", "write"]);
271
+ if (originalState) {
272
+ if (originalState.model) {
273
+ await pi.setModel(originalState.model);
274
+ }
275
+ pi.setThinkingLevel(originalState.thinkingLevel);
276
+ pi.setActiveTools(originalState.tools);
277
+ } else {
278
+ pi.setActiveTools(["read", "bash", "edit", "write"]);
279
+ }
255
280
  ctx.ui.notify("Preset cleared, defaults restored", "info");
256
281
  updateStatus(ctx);
257
282
  return;
@@ -296,7 +321,15 @@ export default function presetExtension(pi: ExtensionAPI) {
296
321
  if (nextName === "(none)") {
297
322
  activePresetName = undefined;
298
323
  activePreset = undefined;
299
- pi.setActiveTools(["read", "bash", "edit", "write"]);
324
+ if (originalState) {
325
+ if (originalState.model) {
326
+ await pi.setModel(originalState.model);
327
+ }
328
+ pi.setThinkingLevel(originalState.thinkingLevel);
329
+ pi.setActiveTools(originalState.tools);
330
+ } else {
331
+ pi.setActiveTools(["read", "bash", "edit", "write"]);
332
+ }
300
333
  ctx.ui.notify("Preset cleared, defaults restored", "info");
301
334
  updateStatus(ctx);
302
335
  return;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Project Trust Extension
3
+ *
4
+ * Demonstrates the project_trust event. Install globally or pass via -e:
5
+ *
6
+ * mkdir -p ~/.pi/agent/extensions
7
+ * cp packages/coding-agent/examples/extensions/project-trust.ts ~/.pi/agent/extensions/
8
+ *
9
+ * Or:
10
+ *
11
+ * pi -e packages/coding-agent/examples/extensions/project-trust.ts
12
+ *
13
+ * Try it in a project containing .pi, AGENTS.md/CLAUDE.md, or .agents/skills.
14
+ */
15
+
16
+ import type { ExtensionAPI, ProjectTrustEventResult } from "@draht/coding-agent";
17
+
18
+ export default function (pi: ExtensionAPI) {
19
+ let loadCount = 0;
20
+ loadCount++;
21
+
22
+ // Multiple handlers in one extension are allowed. The first handler that returns
23
+ // { trusted: "yes" } or { trusted: "no" } wins and suppresses the built-in
24
+ // trust prompt. Return { trusted: "undecided" } to let another handler or the
25
+ // built-in flow decide.
26
+ pi.on("project_trust", async (event, ctx): Promise<ProjectTrustEventResult> => {
27
+ ctx.ui.notify(`project_trust fired for ${event.cwd} (mode: ${ctx.mode}, load: ${loadCount})`, "info");
28
+
29
+ if (!ctx.hasUI) {
30
+ return { trusted: "undecided" };
31
+ }
32
+
33
+ const choice = await ctx.ui.select(`Project trust for:\n${event.cwd}`, [
34
+ "Trust and remember",
35
+ "Trust with note and remember",
36
+ "Trust this session",
37
+ "Do not trust this session",
38
+ "Let built-in prompt decide",
39
+ ]);
40
+
41
+ if (choice === "Trust with note and remember") {
42
+ const note = await ctx.ui.input("Project trust note", "Optional note for this demo");
43
+ ctx.ui.notify(note ? `Recorded demo note: ${note}` : "No demo note entered", "info");
44
+ return { trusted: "yes", remember: true };
45
+ }
46
+ if (choice === "Trust and remember") {
47
+ return { trusted: "yes", remember: true };
48
+ }
49
+ if (choice === "Trust this session") {
50
+ return { trusted: "yes" };
51
+ }
52
+ if (choice === "Do not trust this session") {
53
+ return { trusted: "no" };
54
+ }
55
+ if (choice === "Let built-in prompt decide") {
56
+ return { trusted: "undecided" };
57
+ }
58
+ return { trusted: "undecided" };
59
+ });
60
+
61
+ pi.on("session_start", (_event, ctx) => {
62
+ ctx.ui.notify(`project-trust example loaded after trust resolution in ${ctx.cwd}`, "info");
63
+ });
64
+ }
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Prompt Customizer Extension
3
+ *
4
+ * Demonstrates using systemPromptOptions to make informed, context-aware
5
+ * modifications to the system prompt without re-discovering resources.
6
+ *
7
+ * This extension adds tool-specific guidance based on what tools and skills
8
+ * are currently active, respecting whatever the user has configured.
9
+ *
10
+ * Usage:
11
+ * 1. Copy this file to ~/.pi/agent/extensions/ or your project's .pi/extensions/
12
+ * 2. Use the extension — it automatically adapts to your active tools and skills
13
+ */
14
+
15
+ import type { BuildSystemPromptOptions, ExtensionAPI } from "@draht/coding-agent";
16
+
17
+ /**
18
+ * Adds tool-specific guidance that adapts to the active tool set.
19
+ * Instead of appending one-size-fits-all instructions, this reads what's
20
+ * actually loaded and tailors the guidance accordingly.
21
+ */
22
+ function addToolGuidance(options: BuildSystemPromptOptions, basePrompt: string): string {
23
+ const hasTool = (name: string) => options.selectedTools?.includes(name) ?? false;
24
+
25
+ const parts: string[] = [];
26
+
27
+ if (hasTool("read")) {
28
+ parts.push(
29
+ "• Use the `read` tool for file contents (supports text and images).",
30
+ " - For large files, use `offset` and `limit` to read in chunks.",
31
+ );
32
+ }
33
+
34
+ if (hasTool("bash")) {
35
+ parts.push("• Execute commands with the `bash` tool. Use it for file operations like `ls`, `find`, `grep`.");
36
+ }
37
+
38
+ if (hasTool("edit")) {
39
+ parts.push(
40
+ "• Use the `edit` tool for precise text replacements in files. Match exact content including whitespace.",
41
+ );
42
+ }
43
+
44
+ if (hasTool("write")) {
45
+ parts.push("• Use the `write` tool to create new files or overwrite existing ones completely.");
46
+ }
47
+
48
+ if (options.skills && options.skills.length > 0) {
49
+ const skillNames = options.skills.map((s) => s.name).join(", ");
50
+ parts.push(`\nAvailable skills: ${skillNames}`, "Use skill documentation for best practices on specific tools.");
51
+ }
52
+
53
+ if (parts.length === 0) {
54
+ return basePrompt;
55
+ }
56
+
57
+ return `${basePrompt}
58
+
59
+ ## Tool Guidance
60
+
61
+ ${parts.join("\n")}
62
+ `;
63
+ }
64
+
65
+ /**
66
+ * Merges extension instructions with user-provided append prompts.
67
+ * This respects whatever the user configured via --append-system-prompt
68
+ * flags or files, rather than duplicating that work.
69
+ */
70
+ function mergeWithUserAppend(options: BuildSystemPromptOptions): string {
71
+ const userAppend = options.appendSystemPrompt;
72
+ const extensionSpecific = `
73
+ ## Extension-Added Context
74
+
75
+ This prompt includes tool guidance and skill information loaded dynamically.
76
+ If you have additional requirements, configure them via --append-system-prompt or project context files.
77
+ `;
78
+
79
+ if (userAppend) {
80
+ return `${userAppend}\n\n${extensionSpecific}`;
81
+ }
82
+
83
+ return extensionSpecific;
84
+ }
85
+
86
+ export default function promptCustomizer(pi: ExtensionAPI) {
87
+ pi.on("before_agent_start", async (event) => {
88
+ const { systemPrompt, systemPromptOptions } = event;
89
+
90
+ const customPrompt = addToolGuidance(systemPromptOptions, systemPrompt);
91
+ const appendSection = mergeWithUserAppend(systemPromptOptions);
92
+
93
+ return {
94
+ systemPrompt: `${customPrompt}${appendSection}`,
95
+ };
96
+ });
97
+ }
@@ -11,4 +11,8 @@ export default function (pi: ExtensionAPI) {
11
11
  // Optional: replace the payload instead of only logging it.
12
12
  // return { ...event.payload, temperature: 0 };
13
13
  });
14
+
15
+ pi.on("after_provider_response", (event) => {
16
+ appendFileSync(logFile, `[${event.status}] ${JSON.stringify(event.headers)}\n\n`, "utf8");
17
+ });
14
18
  }
@@ -31,7 +31,7 @@ export default function (pi: ExtensionAPI) {
31
31
  pi.registerCommand("qna", {
32
32
  description: "Extract questions from last assistant message into editor",
33
33
  handler: async (_args, ctx) => {
34
- if (!ctx.hasUI) {
34
+ if (ctx.mode !== "tui") {
35
35
  ctx.ui.notify("qna requires interactive mode", "error");
36
36
  return;
37
37
  }
@@ -6,7 +6,7 @@
6
6
 
7
7
  import type { ExtensionAPI } from "@draht/coding-agent";
8
8
  import { Editor, type EditorTheme, Key, matchesKey, Text, truncateToWidth } from "@draht/tui";
9
- import { Type } from "@sinclair/typebox";
9
+ import { Type } from "typebox";
10
10
 
11
11
  interface OptionWithDesc {
12
12
  label: string;
@@ -41,7 +41,7 @@ export default function question(pi: ExtensionAPI) {
41
41
  parameters: QuestionParams,
42
42
 
43
43
  async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
44
- if (!ctx.hasUI) {
44
+ if (ctx.mode !== "tui") {
45
45
  return {
46
46
  content: [{ type: "text", text: "Error: UI not available (running in non-interactive mode)" }],
47
47
  details: {
@@ -7,7 +7,7 @@
7
7
 
8
8
  import type { ExtensionAPI } from "@draht/coding-agent";
9
9
  import { Editor, type EditorTheme, Key, matchesKey, Text, truncateToWidth } from "@draht/tui";
10
- import { Type } from "@sinclair/typebox";
10
+ import { Type } from "typebox";
11
11
 
12
12
  // Types
13
13
  interface QuestionOption {
@@ -82,7 +82,7 @@ export default function questionnaire(pi: ExtensionAPI) {
82
82
  parameters: QuestionnaireParams,
83
83
 
84
84
  async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
85
- if (!ctx.hasUI) {
85
+ if (ctx.mode !== "tui") {
86
86
  return errorResult("Error: UI not available (running in non-interactive mode)");
87
87
  }
88
88
  if (params.questions.length === 0) {
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import type { ExtensionAPI } from "@draht/coding-agent";
9
- import { Type } from "@sinclair/typebox";
9
+ import { Type } from "typebox";
10
10
 
11
11
  export default function (pi: ExtensionAPI) {
12
12
  // Command entrypoint for reload.
@@ -10,8 +10,8 @@
10
10
  * via `tool_call` input mutation without replacing the tool.
11
11
  *
12
12
  * Config files (merged, project takes precedence):
13
- * - ~/.draht/agent/extensions/sandbox.json (global)
14
- * - <cwd>/.draht/sandbox.json (project-local)
13
+ * - ~/.pi/agent/extensions/sandbox.json (global)
14
+ * - <cwd>/.pi/sandbox.json (project-local)
15
15
  *
16
16
  * Example .pi/sandbox.json:
17
17
  * ```json
@@ -35,8 +35,8 @@
35
35
  * - `/sandbox` - show current sandbox configuration
36
36
  *
37
37
  * Setup:
38
- * 1. Copy sandbox/ directory to ~/.draht/agent/extensions/
39
- * 2. Run `npm install` in ~/.draht/agent/extensions/sandbox/
38
+ * 1. Copy sandbox/ directory to ~/.pi/agent/extensions/
39
+ * 2. Run `npm install` in ~/.pi/agent/extensions/sandbox/
40
40
  *
41
41
  * Linux also requires: bubblewrap, socat, ripgrep
42
42
  */
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pi-extension-sandbox",
3
- "version": "1.0.0",
3
+ "version": "1.9.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pi-extension-sandbox",
9
- "version": "1.0.0",
9
+ "version": "1.9.1",
10
10
  "dependencies": {
11
11
  "@anthropic-ai/sandbox-runtime": "^0.0.26"
12
12
  }
@@ -62,9 +62,9 @@
62
62
  }
63
63
  },
64
64
  "node_modules/lodash-es": {
65
- "version": "4.17.22",
66
- "resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.22.tgz",
67
- "integrity": "sha512-XEawp1t0gxSi9x01glktRZ5HDy0HXqrM0x5pXQM98EaI0NxO6jVM7omDOxsuEo5UIASAnm2bRp1Jt/e0a2XU8Q==",
65
+ "version": "4.18.1",
66
+ "resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.18.1.tgz",
67
+ "integrity": "sha512-J8xewKD/Gk22OZbhpOVSwcs60zhd95ESDwezOFuA3/099925PdHJ7OFHNTGtajL3AlZkykD32HykiMo+BIBI8A==",
68
68
  "license": "MIT"
69
69
  },
70
70
  "node_modules/shell-quote": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-extension-sandbox",
3
3
  "private": true,
4
- "version": "1.0.0",
4
+ "version": "1.9.1",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "echo 'nothing to clean'",
@@ -14,6 +14,6 @@
14
14
  ]
15
15
  },
16
16
  "dependencies": {
17
- "@anthropic-ai/sandbox-runtime": "^0.0.26"
17
+ "@anthropic-ai/sandbox-runtime": "0.0.26"
18
18
  }
19
19
  }
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import type { ExtensionAPI } from "@draht/coding-agent";
9
- import { Type } from "@sinclair/typebox";
9
+ import { Type } from "typebox";
10
10
 
11
11
  export default function (pi: ExtensionAPI) {
12
12
  // Register a /quit command that cleanly exits pi
@@ -311,7 +311,7 @@ export default function (pi: ExtensionAPI) {
311
311
  description: "Play Snake!",
312
312
 
313
313
  handler: async (_args, ctx) => {
314
- if (!ctx.hasUI) {
314
+ if (ctx.mode !== "tui") {
315
315
  ctx.ui.notify("Snake requires interactive mode", "error");
316
316
  return;
317
317
  }
@@ -529,7 +529,7 @@ export default function (pi: ExtensionAPI) {
529
529
  description: "Play Space Invaders!",
530
530
 
531
531
  handler: async (_args, ctx) => {
532
- if (!ctx.hasUI) {
532
+ if (ctx.mode !== "tui") {
533
533
  ctx.ui.notify("Space Invaders requires interactive mode", "error");
534
534
  return;
535
535
  }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Structured Output Tool
3
+ *
4
+ * Demonstrates `terminate: true` so the agent can end on a tool call
5
+ * without paying for an extra follow-up LLM turn.
6
+ */
7
+
8
+ import { defineTool, type ExtensionAPI } from "@draht/coding-agent";
9
+ import { Text } from "@draht/tui";
10
+ import { Type } from "typebox";
11
+
12
+ interface StructuredOutputDetails {
13
+ headline: string;
14
+ summary: string;
15
+ actionItems: string[];
16
+ }
17
+
18
+ const structuredOutputTool = defineTool({
19
+ name: "structured_output",
20
+ label: "Structured Output",
21
+ description:
22
+ "Return a final structured answer. Use this as your last action when the user asks for structured output or a machine-readable summary.",
23
+ promptSnippet: "Emit a final structured answer as a terminating tool result",
24
+ promptGuidelines: [
25
+ "Use structured_output as your final action when the user asks for structured output, JSON-like output, or a machine-readable summary.",
26
+ "After calling structured_output, do not emit another assistant response in the same turn.",
27
+ ],
28
+ parameters: Type.Object({
29
+ headline: Type.String({ description: "Short title for the result" }),
30
+ summary: Type.String({ description: "One-paragraph summary" }),
31
+ actionItems: Type.Array(Type.String(), { description: "Concrete next steps or key bullets" }),
32
+ }),
33
+
34
+ async execute(_toolCallId, params) {
35
+ return {
36
+ content: [{ type: "text", text: `Saved structured output: ${params.headline}` }],
37
+ details: {
38
+ headline: params.headline,
39
+ summary: params.summary,
40
+ actionItems: params.actionItems,
41
+ } satisfies StructuredOutputDetails,
42
+ terminate: true,
43
+ };
44
+ },
45
+
46
+ renderResult(result, _options, theme) {
47
+ const details = result.details as StructuredOutputDetails | undefined;
48
+ if (!details) {
49
+ const text = result.content[0];
50
+ return new Text(text?.type === "text" ? text.text : "", 0, 0);
51
+ }
52
+
53
+ const lines = [
54
+ theme.fg("toolTitle", theme.bold(details.headline)),
55
+ theme.fg("text", details.summary),
56
+ "",
57
+ ...details.actionItems.map((item, index) => theme.fg("muted", `${index + 1}. ${item}`)),
58
+ ];
59
+ return new Text(lines.join("\n"), 0, 0);
60
+ },
61
+ });
62
+
63
+ export default function (pi: ExtensionAPI) {
64
+ pi.registerTool(structuredOutputTool);
65
+ }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Subagent Tool - Delegate tasks to specialized agents
3
3
  *
4
- * Spawns a separate `draht` process for each subagent invocation,
4
+ * Spawns a separate `pi` process for each subagent invocation,
5
5
  * giving it an isolated context window.
6
6
  *
7
7
  * Supports three modes:
@@ -16,17 +16,18 @@ import { spawn } from "node:child_process";
16
16
  import * as fs from "node:fs";
17
17
  import * as os from "node:os";
18
18
  import * as path from "node:path";
19
- import type { AgentToolResult } from "@draht/agent";
19
+ import type { AgentToolResult } from "@draht/agent-core";
20
20
  import type { Message } from "@draht/ai";
21
21
  import { StringEnum } from "@draht/ai";
22
22
  import { type ExtensionAPI, getMarkdownTheme, withFileMutationQueue } from "@draht/coding-agent";
23
23
  import { Container, Markdown, Spacer, Text } from "@draht/tui";
24
- import { Type } from "@sinclair/typebox";
25
- import { type AgentConfig, type AgentScope, discoverAgents } from "./agents.js";
24
+ import { Type } from "typebox";
25
+ import { type AgentConfig, type AgentScope, discoverAgents } from "./agents.ts";
26
26
 
27
27
  const MAX_PARALLEL_TASKS = 8;
28
28
  const MAX_CONCURRENCY = 4;
29
29
  const COLLAPSED_ITEM_COUNT = 10;
30
+ const PER_TASK_OUTPUT_CAP = 50 * 1024;
30
31
 
31
32
  function formatTokens(count: number): string {
32
33
  if (count < 1000) return count.toString();
@@ -172,6 +173,28 @@ function getFinalOutput(messages: Message[]): string {
172
173
  return "";
173
174
  }
174
175
 
176
+ function isFailedResult(result: SingleResult): boolean {
177
+ return result.exitCode !== 0 || result.stopReason === "error" || result.stopReason === "aborted";
178
+ }
179
+
180
+ function getResultOutput(result: SingleResult): string {
181
+ if (isFailedResult(result)) {
182
+ return result.errorMessage || result.stderr || getFinalOutput(result.messages) || "(no output)";
183
+ }
184
+ return getFinalOutput(result.messages) || "(no output)";
185
+ }
186
+
187
+ function truncateParallelOutput(output: string): string {
188
+ const byteLength = Buffer.byteLength(output, "utf8");
189
+ if (byteLength <= PER_TASK_OUTPUT_CAP) return output;
190
+
191
+ let truncated = output.slice(0, PER_TASK_OUTPUT_CAP);
192
+ while (Buffer.byteLength(truncated, "utf8") > PER_TASK_OUTPUT_CAP) {
193
+ truncated = truncated.slice(0, -1);
194
+ }
195
+ return `${truncated}\n\n[Output truncated: ${byteLength - Buffer.byteLength(truncated, "utf8")} bytes omitted. Full output preserved in tool details.]`;
196
+ }
197
+
175
198
  type DisplayItem = { type: "text"; text: string } | { type: "toolCall"; name: string; args: Record<string, any> };
176
199
 
177
200
  function getDisplayItems(messages: Message[]): DisplayItem[] {
@@ -208,7 +231,7 @@ async function mapWithConcurrencyLimit<TIn, TOut>(
208
231
  }
209
232
 
210
233
  async function writePromptToTempFile(agentName: string, prompt: string): Promise<{ dir: string; filePath: string }> {
211
- const tmpDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), "draht-subagent-"));
234
+ const tmpDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), "pi-subagent-"));
212
235
  const safeName = agentName.replace(/[^\w.-]+/g, "_");
213
236
  const filePath = path.join(tmpDir, `prompt-${safeName}.md`);
214
237
  await withFileMutationQueue(filePath, async () => {
@@ -219,7 +242,8 @@ async function writePromptToTempFile(agentName: string, prompt: string): Promise
219
242
 
220
243
  function getPiInvocation(args: string[]): { command: string; args: string[] } {
221
244
  const currentScript = process.argv[1];
222
- if (currentScript && fs.existsSync(currentScript)) {
245
+ const isBunVirtualScript = currentScript?.startsWith("/$bunfs/root/");
246
+ if (currentScript && !isBunVirtualScript && fs.existsSync(currentScript)) {
223
247
  return { command: process.execPath, args: [currentScript, ...args] };
224
248
  }
225
249
 
@@ -229,7 +253,7 @@ function getPiInvocation(args: string[]): { command: string; args: string[] } {
229
253
  return { command: process.execPath, args };
230
254
  }
231
255
 
232
- return { command: "draht", args };
256
+ return { command: "pi", args };
233
257
  }
234
258
 
235
259
  type OnUpdateCallback = (partial: AgentToolResult<SubagentDetails>) => void;
@@ -434,8 +458,8 @@ export default function (pi: ExtensionAPI) {
434
458
  description: [
435
459
  "Delegate tasks to specialized subagents with isolated context.",
436
460
  "Modes: single (agent + task), parallel (tasks array), chain (sequential with {previous} placeholder).",
437
- 'Default agent scope is "user" (from ~/.draht/agent/agents).',
438
- 'To enable project-local agents in .draht/agents, set agentScope: "both" (or "project").',
461
+ 'Default agent scope is "user" (from ~/.pi/agent/agents).',
462
+ 'To enable project-local agents in .pi/agents, set agentScope: "both" (or "project").',
439
463
  ].join(" "),
440
464
  parameters: SubagentParams,
441
465
 
@@ -533,11 +557,9 @@ export default function (pi: ExtensionAPI) {
533
557
  );
534
558
  results.push(result);
535
559
 
536
- const isError =
537
- result.exitCode !== 0 || result.stopReason === "error" || result.stopReason === "aborted";
560
+ const isError = isFailedResult(result);
538
561
  if (isError) {
539
- const errorMsg =
540
- result.errorMessage || result.stderr || getFinalOutput(result.messages) || "(no output)";
562
+ const errorMsg = getResultOutput(result);
541
563
  return {
542
564
  content: [{ type: "text", text: `Chain stopped at step ${i + 1} (${step.agent}): ${errorMsg}` }],
543
565
  details: makeDetails("chain")(results),
@@ -616,17 +638,19 @@ export default function (pi: ExtensionAPI) {
616
638
  return result;
617
639
  });
618
640
 
619
- const successCount = results.filter((r) => r.exitCode === 0).length;
641
+ const successCount = results.filter((r) => !isFailedResult(r)).length;
620
642
  const summaries = results.map((r) => {
621
- const output = getFinalOutput(r.messages);
622
- const preview = output.slice(0, 100) + (output.length > 100 ? "..." : "");
623
- return `[${r.agent}] ${r.exitCode === 0 ? "completed" : "failed"}: ${preview || "(no output)"}`;
643
+ const output = truncateParallelOutput(getResultOutput(r));
644
+ const status = isFailedResult(r)
645
+ ? `failed${r.stopReason && r.stopReason !== "end" ? ` (${r.stopReason})` : ""}`
646
+ : "completed";
647
+ return `### [${r.agent}] ${status}\n\n${output}`;
624
648
  });
625
649
  return {
626
650
  content: [
627
651
  {
628
652
  type: "text",
629
- text: `Parallel: ${successCount}/${results.length} succeeded\n\n${summaries.join("\n\n")}`,
653
+ text: `Parallel: ${successCount}/${results.length} succeeded\n\n${summaries.join("\n\n---\n\n")}`,
630
654
  },
631
655
  ],
632
656
  details: makeDetails("parallel")(results),
@@ -645,10 +669,9 @@ export default function (pi: ExtensionAPI) {
645
669
  onUpdate,
646
670
  makeDetails("single"),
647
671
  );
648
- const isError = result.exitCode !== 0 || result.stopReason === "error" || result.stopReason === "aborted";
672
+ const isError = isFailedResult(result);
649
673
  if (isError) {
650
- const errorMsg =
651
- result.errorMessage || result.stderr || getFinalOutput(result.messages) || "(no output)";
674
+ const errorMsg = getResultOutput(result);
652
675
  return {
653
676
  content: [{ type: "text", text: `Agent ${result.stopReason || "failed"}: ${errorMsg}` }],
654
677
  details: makeDetails("single")([result]),
@@ -739,7 +762,7 @@ export default function (pi: ExtensionAPI) {
739
762
 
740
763
  if (details.mode === "single" && details.results.length === 1) {
741
764
  const r = details.results[0];
742
- const isError = r.exitCode !== 0 || r.stopReason === "error" || r.stopReason === "aborted";
765
+ const isError = isFailedResult(r);
743
766
  const icon = isError ? theme.fg("error", "✗") : theme.fg("success", "✓");
744
767
  const displayItems = getDisplayItems(r.messages);
745
768
  const finalOutput = getFinalOutput(r.messages);
@@ -892,8 +915,8 @@ export default function (pi: ExtensionAPI) {
892
915
 
893
916
  if (details.mode === "parallel") {
894
917
  const running = details.results.filter((r) => r.exitCode === -1).length;
895
- const successCount = details.results.filter((r) => r.exitCode === 0).length;
896
- const failCount = details.results.filter((r) => r.exitCode > 0).length;
918
+ const successCount = details.results.filter((r) => r.exitCode !== -1 && !isFailedResult(r)).length;
919
+ const failCount = details.results.filter((r) => r.exitCode !== -1 && isFailedResult(r)).length;
897
920
  const isRunning = running > 0;
898
921
  const icon = isRunning
899
922
  ? theme.fg("warning", "⏳")
@@ -915,7 +938,7 @@ export default function (pi: ExtensionAPI) {
915
938
  );
916
939
 
917
940
  for (const r of details.results) {
918
- const rIcon = r.exitCode === 0 ? theme.fg("success", "✓") : theme.fg("error", "✗");
941
+ const rIcon = isFailedResult(r) ? theme.fg("error", "✗") : theme.fg("success", "✓");
919
942
  const displayItems = getDisplayItems(r.messages);
920
943
  const finalOutput = getFinalOutput(r.messages);
921
944
 
@@ -962,9 +985,9 @@ export default function (pi: ExtensionAPI) {
962
985
  const rIcon =
963
986
  r.exitCode === -1
964
987
  ? theme.fg("warning", "⏳")
965
- : r.exitCode === 0
966
- ? theme.fg("success", "✓")
967
- : theme.fg("error", "✗");
988
+ : isFailedResult(r)
989
+ ? theme.fg("error", "✗")
990
+ : theme.fg("success", "✓");
968
991
  const displayItems = getDisplayItems(r.messages);
969
992
  text += `\n\n${theme.fg("muted", "─── ")}${theme.fg("accent", r.agent)} ${rIcon}`;
970
993
  if (displayItems.length === 0)