@bastani/atomic 0.10.9 → 0.10.10-alpha.1

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 (401) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/README.md +211 -155
  3. package/dist/_shared/dist-KOELCESV.js +2 -2
  4. package/dist/_shared/fork-row-index-UAUAQRD5.js +2 -2
  5. package/dist/_shared/lib-4PES5P4V.js +2 -2
  6. package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js +27 -12
  7. package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js.map +1 -1
  8. package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +47 -7
  9. package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js.map +1 -1
  10. package/dist/_shared/mode-shared-2QJSCUM6.js +48 -19
  11. package/dist/_shared/mode-shared-2QJSCUM6.js.map +1 -1
  12. package/dist/_shared/{p1a-prewarm-UQY3X2UK.js → p1a-prewarm-XIU57JHF.js} +5 -5
  13. package/dist/_shared/{p1a-prewarm-UQY3X2UK.js.map → p1a-prewarm-XIU57JHF.js.map} +1 -1
  14. package/dist/_shared/p2-shell-main-B2WIALFD.js +30 -25
  15. package/dist/_shared/p2-shell-main-B2WIALFD.js.map +1 -1
  16. package/dist/_shared/runtime-O4KCSG4C.js +5 -5
  17. package/dist/_shared/{sdk-OSBEPR3Q.js → sdk-RRLVN7ER.js} +15 -9
  18. package/dist/_shared/sdk-RRLVN7ER.js.map +1 -0
  19. package/dist/_shared/session-data-AHTU7IS6.js +2 -2
  20. package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
  21. package/dist/_shared/settings-startup-8-DNZ2RIHM.js +4 -1
  22. package/dist/_shared/settings-startup-8-DNZ2RIHM.js.map +1 -1
  23. package/dist/_shared/{startup-0-0-TYUFUOJZ.js → startup-0-0-4VG2G44V.js} +427 -33
  24. package/dist/_shared/startup-0-0-4VG2G44V.js.map +1 -0
  25. package/dist/_shared/{startup-0-1-W2G2UY7R.js → startup-0-1-XTIL65D4.js} +18 -11
  26. package/dist/_shared/startup-0-1-XTIL65D4.js.map +1 -0
  27. package/dist/_shared/{startup-0-2-UXBUEOXW.js → startup-0-2-27OWFHV6.js} +145 -58
  28. package/dist/_shared/startup-0-2-27OWFHV6.js.map +1 -0
  29. package/dist/_shared/startup-0-3-T4DVFYWX.js +15 -25
  30. package/dist/_shared/startup-0-3-T4DVFYWX.js.map +1 -1
  31. package/dist/_shared/{startup-0-4-HN5EB4K7.js → startup-0-4-ZMJV547D.js} +81 -12
  32. package/dist/_shared/startup-0-4-ZMJV547D.js.map +1 -0
  33. package/dist/_shared/startup-0-5-FD2P735I.js +90 -50
  34. package/dist/_shared/startup-0-5-FD2P735I.js.map +1 -1
  35. package/dist/_shared/startup-10-0-TDQNBDDL.js +5 -5
  36. package/dist/_shared/startup-12-0-55AAXBJZ.js +13 -7
  37. package/dist/_shared/startup-12-0-55AAXBJZ.js.map +1 -1
  38. package/dist/_shared/startup-14-0-MLX36RBG.js +4 -4
  39. package/dist/_shared/startup-15-0-YUKGAC63.js +4 -4
  40. package/dist/_shared/startup-15-1-4S7FLMNG.js +88 -28
  41. package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
  42. package/dist/_shared/startup-8-0-34CBHPZH.js +5 -5
  43. package/dist/_shared/startup-8-1-4KANEHRA.js +61 -17
  44. package/dist/_shared/startup-8-1-4KANEHRA.js.map +1 -1
  45. package/dist/_shared/storage-command-7MGXLJGZ.js +4 -4
  46. package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
  47. package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
  48. package/dist/builtin/intercom/CHANGELOG.md +6 -0
  49. package/dist/builtin/intercom/README.md +85 -114
  50. package/dist/builtin/intercom/broker/broker.bundle.mjs +3 -3
  51. package/dist/builtin/intercom/broker/presence-handler.ts +1 -1
  52. package/dist/builtin/intercom/group.ts +7 -3
  53. package/dist/builtin/intercom/index.bundle.mjs +1 -1
  54. package/dist/builtin/intercom/package.json +1 -1
  55. package/dist/builtin/mcp/README.md +37 -27
  56. package/dist/builtin/mcp/index.bundle.mjs +1 -1
  57. package/dist/builtin/mcp/package.json +1 -1
  58. package/dist/builtin/subagents/CHANGELOG.md +8 -0
  59. package/dist/builtin/subagents/README.md +71 -138
  60. package/dist/builtin/subagents/package.json +1 -1
  61. package/dist/builtin/subagents/src/extension/index.bundle.mjs +213 -74
  62. package/dist/builtin/web-access/CHANGELOG.md +9 -0
  63. package/dist/builtin/web-access/README.md +60 -87
  64. package/dist/builtin/web-access/index.bundle.mjs +387 -351
  65. package/dist/builtin/web-access/package.json +1 -1
  66. package/dist/cli/args.js +2 -2
  67. package/dist/cli/auth-cli.code.js +4 -4
  68. package/dist/cli/auth-cli.impl.js +3 -3
  69. package/dist/cli/auth-cli.js +3 -3
  70. package/dist/cli/blueprint-command.code.js +2 -2
  71. package/dist/cli/blueprint-command.impl.js +3 -3
  72. package/dist/cli/blueprint-command.js +3 -3
  73. package/dist/cli/intercom-command.code.js +3 -3
  74. package/dist/cli/intercom-command.impl.js +3 -3
  75. package/dist/cli/intercom-command.js +3 -3
  76. package/dist/cli/list-models.code.js +3 -3
  77. package/dist/cli/list-models.impl.js +3 -3
  78. package/dist/cli/list-models.js +3 -3
  79. package/dist/cli/session-picker.code.js +2 -2
  80. package/dist/cli/session-picker.impl.js +3 -3
  81. package/dist/cli/session-picker.js +3 -3
  82. package/dist/cli/startup-ui.code.js +2 -2
  83. package/dist/cli/startup-ui.impl.js +3 -3
  84. package/dist/cli/startup-ui.js +3 -3
  85. package/dist/cli/storage-command.impl.js +3 -3
  86. package/dist/cli/storage-command.js +3 -3
  87. package/dist/cli/storage-search-session.code.js +2 -2
  88. package/dist/cli/storage-search-session.impl.js +3 -3
  89. package/dist/cli/storage-search-session.js +3 -3
  90. package/dist/cli/team-command.code.js +2 -2
  91. package/dist/cli/team-command.impl.js +3 -3
  92. package/dist/cli/team-command.js +3 -3
  93. package/dist/cli.js +2 -2
  94. package/dist/core/agent-session-methods.d.ts +4 -1
  95. package/dist/core/agent-session-methods.js.map +1 -1
  96. package/dist/core/agent-session.d.ts +3 -0
  97. package/dist/core/compaction/compactor.d.ts +20 -14
  98. package/dist/core/compaction/errors.d.ts +120 -0
  99. package/dist/core/compaction/index.d.ts +1 -0
  100. package/dist/core/compaction/model-resolver.d.ts +2 -2
  101. package/dist/core/debug.impl.js +3 -3
  102. package/dist/core/debug.js +3 -3
  103. package/dist/core/export-html/card-projection.impl.js +3 -3
  104. package/dist/core/export-html/card-projection.js +3 -3
  105. package/dist/core/export-html/index.code.js +2 -2
  106. package/dist/core/export-html/index.impl.js +3 -3
  107. package/dist/core/export-html/index.js +3 -3
  108. package/dist/core/export-html/json-spans.impl.js +3 -3
  109. package/dist/core/export-html/json-spans.js +3 -3
  110. package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
  111. package/dist/core/export-html/oversized-render-inputs.js +3 -3
  112. package/dist/core/export-html/tool-renderer.code.js +1 -1
  113. package/dist/core/export-html/tool-renderer.impl.js +3 -3
  114. package/dist/core/export-html/tool-renderer.js +3 -3
  115. package/dist/core/extensions/api-types.d.ts +1 -1
  116. package/dist/core/extensions/api-types.js.map +1 -1
  117. package/dist/core/extensions/index.d.ts +1 -1
  118. package/dist/core/extensions/jiti-loader.impl.js +3 -3
  119. package/dist/core/extensions/jiti-loader.js +3 -3
  120. package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
  121. package/dist/core/extensions/jiti-static-loader.js +3 -3
  122. package/dist/core/extensions/loader-host-modules.code.js +1 -1
  123. package/dist/core/extensions/loader-host-modules.impl.js +3 -3
  124. package/dist/core/extensions/loader-host-modules.js +3 -3
  125. package/dist/core/extensions/loader-virtual-modules.js +1 -1
  126. package/dist/core/extensions/provider-types.d.ts +18 -6
  127. package/dist/core/extensions/provider-types.js.map +1 -1
  128. package/dist/core/extensions/runner-context.js +1 -1
  129. package/dist/core/intercom-broker-control-host.code.js +1 -1
  130. package/dist/core/intercom-broker-control-host.impl.js +3 -3
  131. package/dist/core/intercom-broker-control-host.js +3 -3
  132. package/dist/core/intercom-broker-control.code.js +3 -3
  133. package/dist/core/intercom-broker-control.impl.js +3 -3
  134. package/dist/core/intercom-broker-control.js +3 -3
  135. package/dist/core/model-config.d.ts +40 -0
  136. package/dist/core/model-registry.js +1 -1
  137. package/dist/core/model-resolver-scope.d.ts +4 -4
  138. package/dist/core/model-runtime.d.ts +1 -1
  139. package/dist/core/package-manager-storage-adapters.impl.js +3 -3
  140. package/dist/core/package-manager-storage-adapters.js +3 -3
  141. package/dist/core/provider-composer-internal.d.ts +11 -2
  142. package/dist/core/sdk.code.js +3 -3
  143. package/dist/core/sdk.impl.js +3 -3
  144. package/dist/core/sdk.js +3 -3
  145. package/dist/core/session-manager-core.js +5 -5
  146. package/dist/core/session-manager-list.impl.js +3 -3
  147. package/dist/core/session-manager-list.js +3 -3
  148. package/dist/core/session-manager.code.js +1 -1
  149. package/dist/core/session-manager.impl.js +3 -3
  150. package/dist/core/session-manager.js +3 -3
  151. package/dist/core/session-storage.impl.js +3 -3
  152. package/dist/core/session-storage.js +3 -3
  153. package/dist/core/settings-manager-basic-accessors.d.ts +6 -2
  154. package/dist/core/storage/index.js +2 -2
  155. package/dist/core/storage/node-sqlite-thread.js +2 -2
  156. package/dist/core/storage/node-sqlite.js +2 -2
  157. package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
  158. package/dist/core/storage/offline-snapshot-file.js +3 -3
  159. package/dist/core/storage/provider.js +2 -2
  160. package/dist/core/storage/selection.js +2 -2
  161. package/dist/core/storage/session/branch-fork-source.code.js +2 -2
  162. package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
  163. package/dist/core/storage/session/branch-fork-source.js +3 -3
  164. package/dist/core/storage/session/card-view.impl.js +3 -3
  165. package/dist/core/storage/session/card-view.js +3 -3
  166. package/dist/core/storage/session/child-reader.code.js +3 -3
  167. package/dist/core/storage/session/child-reader.impl.js +3 -3
  168. package/dist/core/storage/session/child-reader.js +3 -3
  169. package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
  170. package/dist/core/storage/session/chunked-resume-projection.js +3 -3
  171. package/dist/core/storage/session/expanded-child-details.code.js +2 -2
  172. package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
  173. package/dist/core/storage/session/expanded-child-details.js +3 -3
  174. package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
  175. package/dist/core/storage/session/fork-row-bytes.js +3 -3
  176. package/dist/core/storage/session/fork-row-index.impl.js +3 -3
  177. package/dist/core/storage/session/fork-row-index.js +3 -3
  178. package/dist/core/storage/session/fork-staging.code.js +2 -2
  179. package/dist/core/storage/session/fork-staging.impl.js +3 -3
  180. package/dist/core/storage/session/fork-staging.js +3 -3
  181. package/dist/core/storage/session/fork-window.code.js +3 -3
  182. package/dist/core/storage/session/fork-window.impl.js +3 -3
  183. package/dist/core/storage/session/fork-window.js +3 -3
  184. package/dist/core/storage/session/history-pages.impl.js +3 -3
  185. package/dist/core/storage/session/history-pages.js +3 -3
  186. package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
  187. package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
  188. package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
  189. package/dist/core/storage/session/jsonl-session-store.js +3 -3
  190. package/dist/core/storage/session/memory-session-store.impl.js +3 -3
  191. package/dist/core/storage/session/memory-session-store.js +3 -3
  192. package/dist/core/storage/session/pinned-branch-resume.code.js +3 -3
  193. package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
  194. package/dist/core/storage/session/pinned-branch-resume.js +3 -3
  195. package/dist/core/storage/session/released-history-files.code.js +3 -3
  196. package/dist/core/storage/session/released-history-files.impl.js +3 -3
  197. package/dist/core/storage/session/released-history-files.js +3 -3
  198. package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
  199. package/dist/core/storage/session/resident-fork-rows.js +3 -3
  200. package/dist/core/storage/session/session-resume.impl.js +3 -3
  201. package/dist/core/storage/session/session-resume.js +3 -3
  202. package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
  203. package/dist/core/storage/session/snapshot-cut.js +3 -3
  204. package/dist/core/storage/session/snapshot-history.code.js +3 -3
  205. package/dist/core/storage/session/snapshot-history.impl.js +3 -3
  206. package/dist/core/storage/session/snapshot-history.js +3 -3
  207. package/dist/core/storage/session/sql-session-store.code.js +1 -1
  208. package/dist/core/storage/session/sql-session-store.impl.js +3 -3
  209. package/dist/core/storage/session/sql-session-store.js +3 -3
  210. package/dist/core/storage/session/tree-outline.impl.js +3 -3
  211. package/dist/core/storage/session/tree-outline.js +3 -3
  212. package/dist/core/storage/session/tree-presentation.impl.js +3 -3
  213. package/dist/core/storage/session/tree-presentation.js +3 -3
  214. package/dist/core/storage/storage-status.impl.js +3 -3
  215. package/dist/core/storage/storage-status.js +3 -3
  216. package/dist/core/storage/team.impl.js +3 -3
  217. package/dist/core/storage/team.js +3 -3
  218. package/dist/core/structured-output/index.code.js +1 -1
  219. package/dist/core/structured-output/index.impl.js +3 -3
  220. package/dist/core/structured-output/index.js +3 -3
  221. package/dist/core/tasks/task-completion-entry.impl.js +3 -3
  222. package/dist/core/tasks/task-completion-entry.js +3 -3
  223. package/dist/core/tasks/task-file-history.code.js +3 -3
  224. package/dist/core/tasks/task-file-history.impl.js +3 -3
  225. package/dist/core/tasks/task-file-history.js +3 -3
  226. package/dist/core/tasks/task-reference-archive.code.js +4 -4
  227. package/dist/core/tasks/task-reference-archive.js +3 -3
  228. package/dist/core/tasks/task-reference-identity.code.js +1 -1
  229. package/dist/core/tasks/task-reference-identity.js +3 -3
  230. package/dist/core/tasks/task-reference-stream.impl.js +3 -3
  231. package/dist/core/tasks/task-reference-stream.js +3 -3
  232. package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
  233. package/dist/core/tasks/task-unsaved-answer.js +3 -3
  234. package/dist/core/tasks/task-view-source.impl.js +3 -3
  235. package/dist/core/tasks/task-view-source.js +3 -3
  236. package/dist/core/tools/read-url.code.js +2 -2
  237. package/dist/core/tools/read-url.impl.js +3 -3
  238. package/dist/core/tools/read-url.js +3 -3
  239. package/dist/core/worktree-snapshot/blob-store.js +2 -2
  240. package/dist/core/worktree-snapshot/errors.code.js +3 -3
  241. package/dist/core/worktree-snapshot/errors.impl.js +3 -3
  242. package/dist/core/worktree-snapshot/errors.js +3 -3
  243. package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
  244. package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
  245. package/dist/extensions/codemode/execute.code.js +1 -1
  246. package/dist/extensions/codemode/execute.impl.js +3 -3
  247. package/dist/extensions/codemode/execute.js +3 -3
  248. package/dist/extensions/codemode/renderer.code.js +2 -2
  249. package/dist/extensions/codemode/renderer.impl.js +3 -3
  250. package/dist/extensions/codemode/renderer.js +3 -3
  251. package/dist/extensions/mcp/cli.code.js +2 -2
  252. package/dist/extensions/mcp/cli.impl.js +3 -3
  253. package/dist/extensions/mcp/cli.js +3 -3
  254. package/dist/extensions/mcp/cli.lazy.code.js +2 -2
  255. package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
  256. package/dist/extensions/mcp/cli.lazy.js +3 -3
  257. package/dist/extensions/mcp/runtime.code.js +1 -1
  258. package/dist/extensions/mcp/runtime.impl.js +3 -3
  259. package/dist/extensions/mcp/runtime.js +3 -3
  260. package/dist/index-extensions.d.ts +1 -1
  261. package/dist/index.d.ts +8 -1
  262. package/dist/index.js +7 -7
  263. package/dist/main-first-time-setup.code.js +2 -2
  264. package/dist/main-first-time-setup.impl.js +3 -3
  265. package/dist/main-first-time-setup.js +3 -3
  266. package/dist/modes/interactive/components/settings-selector-types.d.ts +1 -0
  267. package/dist/modes/interactive/components/settings-selector-types.js.map +1 -1
  268. package/dist/modes/interactive/components/stored-tree-view.code.js +2 -2
  269. package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
  270. package/dist/modes/interactive/components/stored-tree-view.js +3 -3
  271. package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
  272. package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
  273. package/dist/modes/interactive/theme/color-utils.d.ts +5 -5
  274. package/dist/modes/interactive/theme/theme-loading.d.ts +1 -0
  275. package/dist/modes/interactive-engine/engine-prewarm.js +1 -1
  276. package/dist/modes/interactive-engine/remote-model-catalog.d.ts +1 -0
  277. package/dist/modes/print-mode.js +1 -1
  278. package/dist/modes/rpc/rpc-client-api.d.ts +6 -0
  279. package/dist/modes/rpc/rpc-types.d.ts +29 -2
  280. package/dist/package-manager-cli.code.js +5 -5
  281. package/dist/package-manager-cli.impl.js +3 -3
  282. package/dist/package-manager-cli.js +3 -3
  283. package/dist/rpc-entry.js +1 -1
  284. package/dist/startup-files.json +1 -1
  285. package/dist/startup-stages/5.js +1 -1
  286. package/dist/startup-stages/7.js +1 -1
  287. package/dist/startup-stages/8.js +1 -2
  288. package/dist/startup-stages/9.js +2 -1
  289. package/dist/utils/native-module.d.ts +44 -0
  290. package/dist/utils/startup-database-spare.code.js +3 -3
  291. package/dist/utils/startup-database-spare.impl.js +3 -3
  292. package/dist/utils/startup-database-spare.js +3 -3
  293. package/dist/utils/tools-manager.code.js +1 -1
  294. package/dist/utils/tools-manager.impl.js +3 -3
  295. package/dist/utils/tools-manager.js +3 -3
  296. package/docs/background-tasks.md +235 -243
  297. package/docs/build.md +12 -11
  298. package/docs/codemode.md +60 -51
  299. package/docs/compaction/reference.md +61 -24
  300. package/docs/compaction.md +117 -65
  301. package/docs/computer-use.md +179 -146
  302. package/docs/containerization.md +79 -33
  303. package/docs/custom-provider/api-reference.md +148 -11
  304. package/docs/custom-provider/oauth.md +44 -27
  305. package/docs/custom-provider/override.md +14 -7
  306. package/docs/custom-provider/registration.md +75 -65
  307. package/docs/custom-provider/streaming.md +42 -19
  308. package/docs/custom-provider.md +25 -61
  309. package/docs/development.md +47 -43
  310. package/docs/docs.json +33 -33
  311. package/docs/environment-variables.md +83 -57
  312. package/docs/extensions/api-reference.md +323 -734
  313. package/docs/extensions/authoring.md +186 -269
  314. package/docs/extensions/events.md +308 -375
  315. package/docs/extensions/examples.md +122 -74
  316. package/docs/extensions/ui.md +217 -197
  317. package/docs/extensions.md +152 -259
  318. package/docs/getting-started/authentication.md +27 -14
  319. package/docs/getting-started/first-session.md +25 -26
  320. package/docs/getting-started/installation.md +62 -84
  321. package/docs/getting-started/project-instructions.md +39 -14
  322. package/docs/guides/configuration.md +42 -20
  323. package/docs/guides/intercom.md +17 -13
  324. package/docs/guides/non-interactive.md +29 -16
  325. package/docs/guides/orchestration.md +16 -10
  326. package/docs/guides/resume-on-any-machine.md +54 -49
  327. package/docs/guides/subagents.md +22 -14
  328. package/docs/guides/team-setup.md +37 -26
  329. package/docs/guides.md +22 -21
  330. package/docs/herdr.md +21 -16
  331. package/docs/index.md +16 -17
  332. package/docs/intercom/operations.md +68 -66
  333. package/docs/intercom/reference.md +196 -191
  334. package/docs/intercom.md +103 -92
  335. package/docs/json.md +71 -71
  336. package/docs/keybindings.md +63 -50
  337. package/docs/libraries/agent-core.md +49 -8
  338. package/docs/libraries/ai.md +21 -12
  339. package/docs/libraries/codemode.md +28 -6
  340. package/docs/libraries/schema.md +7 -7
  341. package/docs/libraries/telemetry.md +7 -7
  342. package/docs/libraries/tui.md +74 -94
  343. package/docs/libraries.md +5 -5
  344. package/docs/llama-cpp.md +38 -33
  345. package/docs/mcp-servers.md +96 -90
  346. package/docs/models/reference.md +46 -33
  347. package/docs/models-configuration.md +12 -6
  348. package/docs/models.md +93 -88
  349. package/docs/orchestration/migrating-workflows.md +21 -19
  350. package/docs/orchestration/patterns.md +35 -20
  351. package/docs/orchestration.md +22 -21
  352. package/docs/packages/authoring.md +28 -19
  353. package/docs/packages/reference.md +75 -16
  354. package/docs/packages.md +31 -33
  355. package/docs/programmatic.md +22 -21
  356. package/docs/prompt-templates.md +63 -41
  357. package/docs/providers/reference.md +35 -19
  358. package/docs/providers.md +61 -71
  359. package/docs/quickstart.md +32 -46
  360. package/docs/reference/cli.md +249 -252
  361. package/docs/reference.md +23 -20
  362. package/docs/rpc/examples.md +74 -17
  363. package/docs/rpc/extension-ui.md +79 -62
  364. package/docs/rpc/protocol.md +816 -358
  365. package/docs/rpc.md +75 -151
  366. package/docs/sdk/reference.md +175 -45
  367. package/docs/sdk/structured-decisions.md +92 -62
  368. package/docs/sdk/web-server.md +79 -46
  369. package/docs/sdk.md +237 -195
  370. package/docs/security.md +106 -43
  371. package/docs/session-format.md +96 -59
  372. package/docs/sessions.md +149 -113
  373. package/docs/settings.md +289 -204
  374. package/docs/shell-aliases.md +15 -6
  375. package/docs/skills/authoring.md +17 -9
  376. package/docs/skills/reference.md +23 -21
  377. package/docs/skills.md +104 -97
  378. package/docs/storage.md +140 -242
  379. package/docs/subagents/authoring.md +147 -16
  380. package/docs/subagents/reference.md +100 -30
  381. package/docs/subagents.md +220 -252
  382. package/docs/terminal-setup.md +97 -69
  383. package/docs/termux.md +51 -85
  384. package/docs/themes/reference.md +51 -37
  385. package/docs/themes.md +49 -54
  386. package/docs/tmux.md +38 -21
  387. package/docs/tools.md +198 -147
  388. package/docs/tui/reference.md +64 -32
  389. package/docs/tui.md +38 -66
  390. package/docs/usage.md +76 -78
  391. package/docs/verification.md +25 -25
  392. package/docs/web-access.md +72 -55
  393. package/docs/windows.md +53 -58
  394. package/docs/worktree-snapshots.md +62 -65
  395. package/package.json +8 -8
  396. package/schemas/models.schema.json +51 -0
  397. package/dist/_shared/sdk-OSBEPR3Q.js.map +0 -1
  398. package/dist/_shared/startup-0-0-TYUFUOJZ.js.map +0 -1
  399. package/dist/_shared/startup-0-1-W2G2UY7R.js.map +0 -1
  400. package/dist/_shared/startup-0-2-UXBUEOXW.js.map +0 -1
  401. package/dist/_shared/startup-0-4-HN5EB4K7.js.map +0 -1
@@ -1,12 +1,9 @@
1
1
  ---
2
- title: Writing extensions
3
- description: Write an extension, manage its state, and register custom tools.
2
+ title: "Write an extension"
3
+ sidebarTitle: "Write an extension"
4
+ description: "Structure an extension, persist state across reloads and restarts, register custom tools, and customize terminal rendering."
4
5
  ---
5
6
 
6
- # Writing extensions
7
-
8
- ## Writing an extension
9
-
10
7
  An extension exports a default factory function that receives `ExtensionAPI`. The parameter can have any name; older extensions and examples call it `pi`. The factory can be synchronous or asynchronous:
11
8
 
12
9
  ```typescript
@@ -15,11 +12,10 @@ import type { ExtensionAPI } from "@bastani/atomic";
15
12
  export default function (atomic: ExtensionAPI) {
16
13
  // Subscribe to events
17
14
  atomic.on("event_name", async (event, ctx) => {
18
- // ctx.ui for user interaction
19
15
  const ok = await ctx.ui.confirm("Title", "Are you sure?");
20
16
  ctx.ui.notify("Done!", "info");
21
- ctx.ui.setStatus("my-ext", "Processing..."); // Footer status
22
- ctx.ui.setWidget("my-ext", ["Line 1", "Line 2"]); // Widget above editor (default)
17
+ ctx.ui.setStatus("my-ext", "Processing..."); // Footer status
18
+ ctx.ui.setWidget("my-ext", ["Line 1", "Line 2"]); // Widget above editor (default)
23
19
  });
24
20
 
25
21
  // Register tools, commands, shortcuts, flags
@@ -30,17 +26,17 @@ export default function (atomic: ExtensionAPI) {
30
26
  }
31
27
  ```
32
28
 
33
- Editable extensions support TypeScript without compilation. `/reload` picks up edits to an extension or its imported helpers; unchanged modules may retain module-scoped state.
29
+ Editable extensions support TypeScript without a separate build step. Running `/reload` picks up edits to your extension and local modules it imports; unchanged modules may retain module-scoped state.
34
30
 
35
- Imports from Atomic's supplied core packages keep the running host's classes and shared state across `/reload`, including on Windows. The supported `@earendil-works/pi-coding-agent` compatibility import shares those exports with `@bastani/atomic`, so class comparisons and `instanceof` checks work across both names after reload. Edits to your extension and its imported local helpers still take effect; restart Atomic after updating Atomic itself.
31
+ Imports from Atomic's bundled core packages keep the running host's classes and shared state across `/reload`, including on Windows. The `@earendil-works/pi-coding-agent` compatibility import shares those exports with `@bastani/atomic`, so `instanceof` checks work across both names after reload. Restart Atomic after updating Atomic itself.
36
32
 
37
- In Bun single-file builds, installed builtin bundles retain module-scoped state across `/reload`. Restart Atomic to reload shipped code.
33
+ In Bun single-file builds, bundled built-in packages keep their module-scoped state across `/reload`. Restart Atomic to reload shipped code.
38
34
 
39
- If the factory returns a `Promise`, Atomic awaits it before continuing startup. That means async initialization completes before `session_start`, before `resources_discover`, and before provider registrations queued via `atomic.registerProvider()` are flushed.
35
+ If your factory returns a `Promise`, Atomic awaits it before continuing startup. Async initialization completes before `session_start`, before `resources_discover`, and before provider registrations queued with `atomic.registerProvider()` are flushed.
40
36
 
41
- ### Async factory functions
37
+ ## Async factory functions
42
38
 
43
- Use an async factory for one-time startup work such as fetching remote configuration or dynamically discovering available models.
39
+ Use an async factory for one-time startup work such as fetching remote configuration or discovering available models:
44
40
 
45
41
  ```typescript
46
42
  import type { ExtensionAPI } from "@bastani/atomic";
@@ -73,26 +69,26 @@ export default async function (atomic: ExtensionAPI) {
73
69
  }
74
70
  ```
75
71
 
76
- This pattern makes the fetched models available during normal startup and to `atomic --list-models`.
72
+ Models registered here become available during normal startup and in `atomic --list-models`.
77
73
 
78
- ### Long-lived resources and shutdown
74
+ ## Long-lived resources and shutdown
79
75
 
80
- Extension factories may run in invocations that never start a session, such as metadata commands or early configuration checks. Do not start background resources such as processes, sockets, file watchers, or timers from the factory.
76
+ Extension factories can run during commands that never start a full session, such as metadata commands or early configuration checks. Do not start child processes, sockets, file watchers, or timers directly inside the factory function.
81
77
 
82
- Defer background resource startup until `session_start` or the command/tool/event that needs the resource. Register an idempotent `session_shutdown` handler to close any session-scoped resources you start.
78
+ Start background resources inside `session_start` or inside the command, tool, or event handler that needs them. Register an idempotent `session_shutdown` handler to close every resource you open.
83
79
 
84
- ### Extension styles
80
+ ## Extension layouts
85
81
 
86
- **Single file.** Simplest layout for small extensions:
82
+ **Single file.** Best for small extensions:
87
83
 
88
- ```
84
+ ```text
89
85
  ~/.atomic/agent/extensions/
90
86
  └── my-extension.ts
91
87
  ```
92
88
 
93
- **Directory with `index.ts`.** Multi-file extensions:
89
+ **Directory with `index.ts`.** Best for multi-file extensions:
94
90
 
95
- ```
91
+ ```text
96
92
  ~/.atomic/agent/extensions/
97
93
  └── my-extension/
98
94
  ├── index.ts # Entry point (exports default function)
@@ -100,9 +96,9 @@ Defer background resource startup until `session_start` or the command/tool/even
100
96
  └── utils.ts # Helper module
101
97
  ```
102
98
 
103
- **Package with dependencies.** Extensions that need npm packages:
99
+ **Package with dependencies.** Best for extensions that need npm packages:
104
100
 
105
- ```
101
+ ```text
106
102
  ~/.atomic/agent/extensions/
107
103
  └── my-extension/
108
104
  ├── package.json # Declares dependencies and entry points
@@ -113,7 +109,6 @@ Defer background resource startup until `session_start` or the command/tool/even
113
109
  ```
114
110
 
115
111
  ```json
116
- // package.json
117
112
  {
118
113
  "name": "my-extension",
119
114
  "dependencies": {
@@ -126,25 +121,25 @@ Defer background resource startup until `session_start` or the command/tool/even
126
121
  }
127
122
  ```
128
123
 
129
- The manifest key is the configured Atomic app name (`atomic`), not the extension package's own `"name"` field. The legacy `pi` key is still accepted as a compatibility shim. Run `npm install` (or your package manager's install command) in the extension directory, and imports from `node_modules/` resolve automatically.
124
+ Use `"atomic"` as the manifest key (legacy `"pi"` is also accepted). Run `npm install` (or your package manager's install command) in the extension directory so imports from `node_modules/` resolve automatically.
130
125
 
131
126
  ## State management
132
127
 
133
128
  Choose the store that matches the lifetime you need:
134
129
 
135
- - **Tool result `details`.** Reconstructs across `/branch` and `/resume` from the transcript.
136
- - **`atomic.appendEntry()`.** Durable custom entries that survive process restart. They do not enter model context.
137
- - **`sessionScopedExtensionState()`.** In-memory objects that survive `/reload` for the current process. They do not survive process restart.
130
+ - **Tool result `details`.** Rebuilds state across `/branch`, `/tree`, and `/resume` from the conversation transcript.
131
+ - **`atomic.appendEntry()`.** Stores durable custom entries that survive process restarts without entering model context.
132
+ - **`sessionScopedExtensionState()`.** Keeps live in-memory objects alive across `/reload` within the current process (lost on process restart).
138
133
 
139
- In Bun single-file builds, an editable file extension whose imported graph is unchanged can reuse its evaluated factory, so its module-scoped variables may survive `/reload`. An edit anywhere in that graph re-evaluates its modules and resets those singletons. Installed built-in bundles keep their evaluated module state across `/reload`; restart Atomic to reload shipped code.
134
+ In Bun single-file builds, an editable file extension whose imported files have not changed can reuse its evaluated factory and keep module-scoped variables across `/reload`. Editing any file in that import graph re-evaluates its modules and resets those variables.
140
135
 
141
- Extensions with state that must follow conversation branches should store it in tool result `details`:
136
+ Extensions whose state must follow conversation branches should store a snapshot in tool result `details`:
142
137
 
143
138
  ```typescript
144
139
  export default function (atomic: ExtensionAPI) {
145
140
  let items: string[] = [];
146
141
 
147
- // Reconstruct state from session
142
+ // Reconstruct state from the active branch
148
143
  atomic.on("session_start", async (_event, ctx) => {
149
144
  items = [];
150
145
  for (const entry of ctx.sessionManager.getBranch()) {
@@ -159,11 +154,11 @@ export default function (atomic: ExtensionAPI) {
159
154
  atomic.registerTool({
160
155
  name: "my_tool",
161
156
  // ...
162
- async execute(toolCallId, params, signal, onUpdate, ctx) {
157
+ async execute(_toolCallId, _params) {
163
158
  items.push("new item");
164
159
  return {
165
160
  content: [{ type: "text", text: "Added" }],
166
- details: { items: [...items] }, // Store for reconstruction
161
+ details: { items: [...items] },
167
162
  };
168
163
  },
169
164
  });
@@ -172,7 +167,7 @@ export default function (atomic: ExtensionAPI) {
172
167
 
173
168
  ### Session-scoped in-memory state
174
169
 
175
- Import `sessionScopedExtensionState` from `@bastani/atomic` when an extension must keep a live object across `/reload`, such as a registry, abort controller, connection pool, or another handle that cannot be rebuilt from the transcript.
170
+ Import `sessionScopedExtensionState` from `@bastani/atomic` when an extension must keep a live object across `/reload`, such as a registry, abort controller, connection pool, or handle that cannot be rebuilt from the transcript:
176
171
 
177
172
  ```typescript
178
173
  import { sessionScopedExtensionState, type ExtensionAPI } from "@bastani/atomic";
@@ -182,7 +177,7 @@ interface CounterState {
182
177
  }
183
178
 
184
179
  export default function (atomic: ExtensionAPI) {
185
- const state = sessionScopedExtensionState(atomic.events, "my-extension:counter:v1", () => ({
180
+ const state = sessionScopedExtensionState<CounterState>(atomic.events, "my-extension:counter:v1", () => ({
186
181
  count: 0,
187
182
  }));
188
183
 
@@ -196,37 +191,33 @@ export default function (atomic: ExtensionAPI) {
196
191
  }
197
192
  ```
198
193
 
199
- **Required scope.** Pass the extension's `atomic.events` facade (or the session `EventBus` itself). The host resolves that facade to the canonical session bus, so every load generation of one session re-binds to the same object. Two in-process sessions with distinct buses stay isolated. Do not pass an arbitrary object: an unregistered scope is treated as its own bus and will not re-bind after reload.
200
-
201
- **Session-wide key namespace.** Keys are not automatically namespaced by extension. Two extensions that pass the same key on the same session receive the first extension's object, and the later factory is not called. Prefix every key with a stable extension identity.
202
-
203
- **Key versioning.** Append a version suffix and bump it when the stored shape changes, for example from `"my-extension:counter:v1"` to `"my-extension:counter:v2"`. The new key ignores the incompatible predecessor instead of reusing it under a new type.
204
-
205
- **Reload behavior.** `/reload` builds a new `atomic.events` facade that still forwards to the same bus. Calling `sessionScopedExtensionState` again with the same namespaced key returns the existing object without invoking `create`.
206
-
207
- The reload transaction does not clone this object or roll back mutations made in factory code. Keep factory setup idempotent, and mutate durable state only after the new generation starts when failed reloads must not affect it. Entries live as long as that bus and are not written to the session store; use `atomic.appendEntry()` when data must survive process restart.
208
-
209
- **Shutdown.** `session_shutdown` still runs for resources you opened. Close sockets, watchers, or timers there; the next `session_start` or first use can recreate them inside the same session-scoped object.
194
+ - **Required scope.** Pass the extension's `atomic.events` object (or the session `EventBus` directly). Every `/reload` of the same session reconnects to the same stored object, while separate sessions stay independent. Do not pass a random object; an unregistered scope will not reconnect after reload.
195
+ - **Session-wide key namespace.** Keys are shared across all extensions in the session. Two extensions passing the same key receive the first extension's object, and the second factory does not run. Prefix every key with a unique extension identifier.
196
+ - **Key versioning.** Append a version suffix and bump it when the stored shape changes (for example `"my-extension:counter:v1"` to `"my-extension:counter:v2"`). The new key ignores older incompatible state.
197
+ - **Reload behavior.** `/reload` creates a new `atomic.events` wrapper backed by the same session bus. Calling `sessionScopedExtensionState()` with the same key returns the existing object without running `create` again. Failed reloads do not undo mutations made to this object during factory setup. Keep factory setup idempotent and avoid mutating shared state until `session_start`. Use `atomic.appendEntry()` when data must survive a full restart.
198
+ - **Shutdown.** `session_shutdown` still runs for resources you opened. Close sockets, watchers, or timers there; the next `session_start` or first use can recreate them inside the same session-scoped object.
210
199
 
211
200
  ## Custom tools
212
201
 
213
- Register tools the LLM can call via `atomic.registerTool()`. Tools appear in the system prompt and can define custom rendering.
202
+ Register tools the model can call with `atomic.registerTool()`. Use the `defineTool(tool)` helper from `@bastani/atomic` when storing tool definitions in variables or arrays so TypeScript preserves parameter type inference.
214
203
 
215
- Use `promptSnippet` for a short one-line entry in the `Available tools` section of the default system prompt. If omitted, custom tools are left out of that section.
204
+ Tool name collisions follow two rules:
216
205
 
217
- Use `promptGuidelines` to add tool-specific bullets to the default system prompt `Guidelines` section. These bullets are included only while the tool is active (for example, after `atomic.setActiveTools([...])`).
206
+ - Within a single extension, registering the same tool name twice keeps the last registration and emits a warning.
207
+ - Across multiple extensions, the **first** loaded extension wins. The mandatory bundled `intercom` tool cannot be shadowed.
218
208
 
219
- **Important:** `promptGuidelines` bullets are appended flat to the `Guidelines` section with no tool name prefix or grouping. Each guideline must name the tool it refers to. Avoid "Use this tool when..." because the LLM cannot tell which tool "this" means; write "Use my_tool when..." instead.
209
+ Prompt metadata options:
220
210
 
221
- Some models include the @ prefix in tool path arguments. Built-in tools strip a leading @ before resolving paths. If your custom tool accepts a path, normalize a leading @ as well.
211
+ - **`promptSnippet`:** Adds a short one-line entry in the `Available tools` section of the default system prompt. If omitted, the tool is left out of that list.
212
+ - **`promptGuidelines`:** Adds tool-specific bullets to the default system prompt `Guidelines` section while the tool is active. Because guidelines are appended flat without grouping, always name the tool explicitly (write `"Use my_tool when..."`, not `"Use this tool when..."`).
222
213
 
223
- If your custom tool mutates files, use `withFileMutationQueue()` so it participates in the same per-file queue as built-in `edit` and `write`. This matters because tool calls run in parallel by default. Without the queue, two tools can read the same old file contents, compute different updates, and then whichever write lands last overwrites the other.
214
+ Some models include a leading `@` prefix in file path arguments. Built-in tools strip a leading `@` before resolving paths; normalize it in your custom path-taking tools as well.
224
215
 
225
- Example failure case: your custom tool edits `foo.ts` while built-in `edit` also changes `foo.ts` in the same assistant turn. If your tool does not participate in the queue, both can read the original `foo.ts`, apply separate changes, and one of those changes is lost.
216
+ ### Serializing file mutations
226
217
 
227
- Pass the real target file path to `withFileMutationQueue()`, not the raw user argument. Resolve it to an absolute path first, relative to `ctx.cwd` or your tool's working directory. For existing files, the helper canonicalizes through `realpath()`, so symlink aliases for the same file share one queue. For new files, it falls back to the resolved absolute path because there is nothing to `realpath()` yet.
218
+ If your tool edits files, wrap the full read-modify-write operation in `withFileMutationQueue()` so it shares the same per-file lock as built-in `edit` and `write`. Because tool calls run concurrently by default, unqueued tools can read stale contents and overwrite each other's changes.
228
219
 
229
- Queue the entire mutation window on that target path. That includes read-modify-write logic, not just the final write.
220
+ Resolve the target path to an absolute path relative to `ctx.cwd` before calling `withFileMutationQueue()`. For existing files, Atomic canonicalizes the path with `realpath()` so symlinks share the same queue; for new files, it uses the resolved absolute path. If your callback throws, the queue releases automatically so waiting mutations can proceed.
230
221
 
231
222
  ```typescript
232
223
  import { withFileMutationQueue } from "@bastani/atomic";
@@ -252,25 +243,27 @@ async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
252
243
 
253
244
  ### Tool definition
254
245
 
255
- `parameters` is required, including for no-argument tools (use `Type.Object({})`). Registration rejects missing, null, array, and primitive schema values before they can break a provider request. This checks the schema container, not its JSON Schema `type`: object-valued union and non-object-type schemas remain accepted and unchanged.
246
+ `parameters` is required, including for no-argument tools (`Type.Object({})`). Registration rejects missing, null, array, and primitive values before they can break provider requests.
247
+
248
+ If a root schema is an `anyOf` or `oneOf` union, give every branch an explicit `type: "object"` (xAI rejects non-object root branches with `tool parameter root must be an object type`). Prefer a plain `Type.Object` root with optional properties when a union is unnecessary.
256
249
 
257
- Registration is not provider validation. If a root schema is an `anyOf` or `oneOf` union, give every branch an explicit `type: "object"`; xAI rejects a non-object root branch with `tool parameter root must be an object type` before the model can call the tool. Prefer a plain `Type.Object` root with optional properties when a union is not needed.
250
+ Use `StringEnum` from `@bastani/atomic` (also exported from `@bastani/atomic-ai`) for string enums instead of `Type.Union` with `Type.Literal`, which Google's API rejects.
258
251
 
259
252
  ```typescript
260
253
  import { Type } from "typebox";
261
- import { StringEnum } from "@bastani/atomic";
262
- import { Text } from "@bastani/atomic-tui";
254
+ import { defineTool, StringEnum } from "@bastani/atomic";
263
255
 
264
- atomic.registerTool({
256
+ const myTool = defineTool({
265
257
  name: "my_tool",
266
258
  label: "My Tool",
267
- description: "What this tool does (shown to LLM)",
259
+ description: "What this tool does (shown to the model)",
268
260
  promptSnippet: "List or add items in the project todo list",
269
261
  promptGuidelines: [
270
- "Use my_tool for todo planning instead of direct file edits when the user asks for a task list."
262
+ "Use my_tool for todo planning instead of direct file edits when the user asks for a task list.",
271
263
  ],
264
+ maxResultSizeChars: 40_000, // Per-tool cap for persisted model-visible output (Infinity opts out)
272
265
  parameters: Type.Object({
273
- action: StringEnum(["list", "add"] as const), // Google-compatible TypeBox string enum
266
+ action: StringEnum(["list", "add"] as const),
274
267
  text: Type.Optional(Type.String()),
275
268
  }),
276
269
  prepareArguments(args) {
@@ -282,50 +275,43 @@ atomic.registerTool({
282
275
  return args;
283
276
  },
284
277
 
285
- async execute(toolCallId, params, signal, onUpdate, ctx) {
286
- // Check for cancellation
278
+ async execute(_toolCallId, params, signal, onUpdate) {
287
279
  if (signal?.aborted) {
288
280
  return { content: [{ type: "text", text: "Cancelled" }] };
289
281
  }
290
282
 
291
- // Stream progress updates
292
283
  onUpdate?.({
293
284
  content: [{ type: "text", text: "Working..." }],
294
285
  details: { progress: 50 },
295
286
  });
296
287
 
297
- // Run commands via atomic.exec (captured from extension closure)
298
288
  const result = await atomic.exec("some-command", [], { signal });
299
289
 
300
- // Return result
301
290
  return {
302
- content: [{ type: "text", text: "Done" }], // Sent to LLM
303
- details: { data: result }, // For rendering & state
304
- // Optional: stop after this tool batch when every finalized tool result
305
- // in the batch also returns terminate: true.
291
+ content: [{ type: "text", text: "Done" }], // Sent to model
292
+ details: { data: result }, // For rendering and state
293
+ // Optional: end the turn without a follow-up model call when every
294
+ // finalized tool result in the batch also returns terminate: true.
306
295
  terminate: true,
307
296
  };
308
297
  },
309
298
 
310
- // Optional: Custom rendering
311
- renderCall(args, theme, context) { ... },
312
- renderResult(result, options, theme, context) { ... },
299
+ renderCall(args, theme, context) { /* optional */ },
300
+ renderResult(result, options, theme, context) { /* optional */ },
313
301
  });
314
- ```
315
-
316
- **Signaling errors.** Throw from `execute` to report an execution failure. When a failure also carries useful data, return an error result with `isError: true`, `content`, and optional `structuredContent`.
317
302
 
318
- Return `terminate: true` from `execute()` to skip the automatic follow-up model call when every finalized result in the tool batch also terminates.
319
-
320
- For a schema-backed decision, use `createStructuredOutputTool({ schema, name })`. Atomic does not register `structured_output` in normal sessions by default. The calling model supplies `instructions`, nonempty named `state`, and optional `model` and `fallbackModels`. The tool resolves those exact IDs through the session model registry, infers a value matching `schema`, and returns that value as terminating JSON rather than treating the calling model's arguments as the result.
303
+ atomic.registerTool(myTool);
304
+ ```
321
305
 
322
- Omit `model` to use the current session chat model; explicit fallbacks run next, and the current chat model is the terminal fallback. A registered classifier runs only for a finite Choice schema and is skipped for incompatible schemas.
306
+ Additional `ToolDefinition` fields:
323
307
 
324
- Provider errors (including refusals) advance to the next model, and plain-text responses without the required result are repaired up to three times before advancing. Cancellation stops the call, and a wall-clock deadline covering every repair attempt, retry, and fallback defaults to `httpIdleTimeoutMs` (`createStructuredOutputTool({ timeoutMs })` overrides it). Include a custom name such as `final_decision` in any explicit tool allowlist.
308
+ - **`maxResultSizeChars?: number`:** Sets a per-tool character cap for model-visible result persistence. Pass `Infinity` to opt out for self-bounded tools.
309
+ - **`prepareArguments(args)`:** Optional normalizer that runs before schema validation and `execute()`. Keep the public schema clean instead of advertising deprecated fields.
310
+ - **`terminate: true`:** Return on a tool result to skip the automatic follow-up model call when every finalized result in the batch also sets `terminate: true`.
311
+ - **Signaling errors:** Throw an `Error` from `execute()` to report a failure. When a failure also carries structured data, return `{ isError: true, content, structuredContent }`.
325
312
 
326
313
  ```typescript
327
- // Correct: throw to signal an error
328
- async execute(toolCallId, params) {
314
+ async execute(_toolCallId, params) {
329
315
  if (!isValid(params.input)) {
330
316
  throw new Error(`Invalid input: ${params.input}`);
331
317
  }
@@ -333,11 +319,23 @@ async execute(toolCallId, params) {
333
319
  }
334
320
  ```
335
321
 
336
- **Important:** Use `StringEnum` from `@bastani/atomic` (also exported from `@bastani/atomic-ai`) for string enums. It produces a Google-compatible schema that composes with Atomic's TypeBox types; `Type.Union` with `Type.Literal` does not work with Google's API.
322
+ #### Structured output tool helper
323
+
324
+ For a schema-backed decision, use `createStructuredOutputTool({ schema, name?, capture?, output?, timeoutMs? })`. Atomic does not register `structured_output` in normal sessions by default. Include any custom `name` (such as `"final_decision"`) in explicit tool allowlists.
325
+
326
+ - **`capture`:** Pass `createStructuredOutputCapture()` to inspect `{ called, value }` in memory after the call finishes.
327
+ - **`output`:** Pass `{ outputPath }` to write the validated JSON result to disk with `0o600` file permissions.
328
+ - **`timeoutMs`:** Overrides the default wall-clock deadline (`httpIdleTimeoutMs`) covering every repair attempt, transport retry, and model fallback.
329
+
330
+ When the model calls the tool, it supplies `instructions`, nonempty named `state`, and optional `model` and `fallbackModels`:
331
+
332
+ - Omitting `model` uses the session's configured **`decisionModel`** (via `ctx.getDecisionModel()`, which defaults to the current chat model when unset or `""`), then any explicit `fallbackModels`, and finally the current chat model as the terminal fallback.
333
+ - A registered classifier runs only for a finite Choice schema and is skipped for incompatible schemas.
334
+ - Provider errors (including refusals) advance to the next model. Plain-text responses without a valid structured value are repaired up to three times before advancing. Cancellation stops the call immediately.
337
335
 
338
336
  #### Constrained sampling
339
337
 
340
- `ToolDefinition.constrainedSampling` is preserved for extension tools, SDK `customTools`, wrappers, and isolated execution. It accepts `false` or the exported `ConstrainedSamplingConfig`:
338
+ `ToolDefinition.constrainedSampling` is preserved for extension tools, SDK `customTools`, wrappers, and default interactive mode. It accepts `false` or a `ConstrainedSamplingConfig`:
341
339
 
342
340
  ```typescript
343
341
  atomic.registerTool({
@@ -352,53 +350,27 @@ atomic.registerTool({
352
350
  });
353
351
  ```
354
352
 
355
- Exact modes:
353
+ Supported values:
356
354
 
357
- - `{ type: "json_schema", strict: "prefer" }` requests strict provider enforcement and falls back to ordinary tool calling when unavailable.
358
- - `{ type: "json_schema", strict: "require" }` fails the request rather than silently weakening the constraint.
359
- - `{ type: "grammar", variants: { openai_lark?: string, openai_regex?: string } }` requests an OpenAI custom grammar tool; Lark wins when both non-empty variants are present.
360
- - `false` explicitly opts out. Its runtime effect matches omission, while public tool inspection preserves `false` as an explicit opt-out value.
355
+ - `{ type: "json_schema", strict: "prefer" }`: requests strict provider enforcement and falls back to ordinary tool calling when unavailable.
356
+ - `{ type: "json_schema", strict: "require" }`: fails the request instead of weakening the constraint.
357
+ - `{ type: "grammar", variants: { openai_lark?: string, openai_regex?: string } }`: requests an OpenAI custom grammar tool (Lark wins when both non-empty variants are set).
358
+ - `false`: explicitly opts out while preserving `false` during public tool inspection.
361
359
 
362
- If Anthropic rejects a request because strict tools exceed its grammar-size, tool-count, or union-parameter limits, Atomic retries once with `prefer` tools using their ordinary schemas. Tools marked `require` remain strict. A response that has already started streaming is not retried this way.
360
+ If Anthropic rejects a request because strict tools exceed its grammar-size, tool-count, or union-parameter limits, Atomic retries once with `prefer` tools using ordinary schemas while keeping `require` tools strict (never retried after streaming starts).
363
361
 
364
- Built-in `read`, `edit`, `write`, `bash`, and its Windows PowerShell variant request strict JSON-schema sampling with `prefer` by default. This is a provider hint, not a schema rewrite or a sandbox; unsupported providers keep ordinary tool calling. Other experimental tool hints still follow the experimental environment flag.
362
+ Built-in `read`, `edit`, `write`, `bash`, and `powershell` default to `{ type: "json_schema", strict: "prefer" }`. Grammar tools require an object schema with one required string property and apply only when model metadata advertises `supportsOpenAIGrammarTools` (alias `supportsGrammarTools`). See [Custom models](/models/reference#constrained-tool-sampling) and [RPC](/rpc/protocol#get_available_models).
365
363
 
366
- Grammar tools require an object schema with exactly one required string property. They are emitted only when model metadata advertises `supportsOpenAIGrammarTools` (also exposed as `supportsGrammarTools`); otherwise provider handling falls back to the normal JSON-schema path. Older OpenAI models and gateways that rewrite schemas cannot honor custom grammar tools. Typed RPC clients receive these claims through optional `ModelInfo.compat`. See [Custom models](/models/reference#constrained-tool-sampling) and [RPC](/rpc/protocol#get_available_models).
367
-
368
- **Argument preparation:** `prepareArguments(args)` is optional. If defined, it runs before schema validation and before `execute()`. Use it only when a custom tool must normalize arguments before validation. Return the object you want validated against `parameters`, keep the public schema strict, and avoid advertising deprecated fields.
369
-
370
- ```typescript
371
- atomic.registerTool({
372
- name: "deploy_plan",
373
- label: "Deploy Plan",
374
- description: "Create a deployment plan for one target environment",
375
- parameters: Type.Object({
376
- environment: Type.String(),
377
- dryRun: Type.Optional(Type.Boolean()),
378
- }),
379
- prepareArguments(args) {
380
- if (!args || typeof args !== "object") return args;
381
- const input = args as { env?: unknown; environment?: unknown; dryRun?: unknown };
382
- if (typeof input.environment === "string") return args;
383
- if (typeof input.env !== "string") return args;
384
- return { environment: input.env, dryRun: input.dryRun };
385
- },
386
- async execute(toolCallId, params) {
387
- return {
388
- content: [{ type: "text", text: `Planning deploy to ${params.environment}` }],
389
- details: {},
390
- };
391
- },
392
- });
393
- ```
364
+ #### Concurrency, sequential execution, and detachable waits
394
365
 
395
- **Call ordering:** when one assistant message contains several tool calls, Atomic starts them in message order and runs them concurrently unless a tool declares `concurrency`:
366
+ When one assistant message contains multiple tool calls, Atomic runs them concurrently by default unless configured otherwise:
396
367
 
397
- - `"shared"` (default): may overlap other shared calls, but starts only after the latest earlier `"exclusive"` call finishes.
398
- - `"exclusive"`: starts only after every earlier call in the message finishes, and later calls wait for it.
399
- - A function `(args) => "shared" | "exclusive"` decides per call. If it throws, the call runs exclusively.
368
+ - **`concurrency: "shared"` (default):** May overlap other shared calls, starting only after any earlier `"exclusive"` call finishes.
369
+ - **`concurrency: "exclusive"`:** Waits for every earlier call in the message to finish, and blocks later calls until it completes.
370
+ - **`concurrency: (args) => "shared" | "exclusive"`:** Decides per call. If the function throws, the call runs exclusively.
371
+ - **`executionMode: "sequential" | "parallel"`:** Setting `executionMode: "sequential"` forces every call in the message to execute strictly one at a time in order (see `examples/extensions/tic-tac-toe.ts`).
400
372
 
401
- Built-in `edit`, `write`, `todo`, and `ask_user_question` are exclusive, and `bash` is exclusive when it runs with `pty: true`. Other `bash` calls are shared, so a later call in the same message can run before a shell command's file changes land. Declare `"exclusive"` for a tool that changes state later calls depend on. `executionMode: "sequential"` still runs the whole message one call at a time.
373
+ Built-in `edit`, `write`, `todo`, and `ask_user_question` are exclusive, and `bash` is exclusive when `pty: true`. Other `bash` calls are shared, so declare `"exclusive"` on custom tools that modify state later calls depend on:
402
374
 
403
375
  ```typescript
404
376
  atomic.registerTool({
@@ -407,29 +379,31 @@ atomic.registerTool({
407
379
  description: "Apply one database migration",
408
380
  parameters: Type.Object({ name: Type.String(), dryRun: Type.Optional(Type.Boolean()) }),
409
381
  concurrency: (args) => (args.dryRun === true ? "shared" : "exclusive"),
410
- async execute(toolCallId, params) {
382
+ async execute(_toolCallId, params) {
411
383
  return { content: [{ type: "text", text: `Applied ${params.name}` }], details: {} };
412
384
  },
413
385
  });
414
386
  ```
415
387
 
416
- **Long waits:** a tool whose calls only wait for something outside the session, such as a CI run or a deployment, can declare `detachable: true`, or a function `(args) => boolean` that decides per call. In a session whose host releases waiting agents, such as a background subagent, a call still running after the host's delay continues without the session, the session is released, and the call's result wakes it later.
388
+ **Detachable long waits:** A tool that only waits on external work (such as a CI job or deployment) can set `detachable: true` or `(args) => boolean`, plus optional `detachmentRequiresReady?: boolean`. When running inside a background subagent that suspends while waiting, a call still running after the delay continues independently, releases the subagent, and wakes it when the result arrives.
417
389
 
418
- After a restart such a call may start again with the same ID and arguments, so declare `detachable` only when that is safe. Built-in `bash` detaches only `{ action: "wait" }` calls without a `budgetMs`.
390
+ Once a call detaches, `onUpdate` progress updates are dropped and `ctx` only answers `cwd`. Because a restarted session can re-run a detached call with the same ID and arguments, mark a tool `detachable` only when re-running it is safe. Built-in `bash` detaches only `{ action: "wait" }` calls without `budgetMs`.
419
391
 
420
392
  ### Structured results and nested tools
421
393
 
422
- Declare `outputSchema` when a tool returns machine-readable data, and return a matching `structuredContent` alongside model-facing `content`. Script callers receive the structured value; tools without an output schema return text to scripts. A `tool_result` handler that redacts text must also replace `structuredContent`; replacing only `content` drops the structured value to prevent it leaking through another path.
394
+ Declare `outputSchema` when a tool returns machine-readable data, and return a matching `structuredContent` alongside model-facing `content`. Script callers receive `structuredContent`; tools without an `outputSchema` return text to scripts. A `tool_result` handler that redacts text must also replace `structuredContent`; replacing only `content` drops `structuredContent` so redacted data cannot leak.
423
395
 
424
- Inside `execute`, the context is an `ExtensionToolContext`. `ctx.tools` lists permitted callable tools, and `ctx.executeTool(name, args, { signal, onUpdate })` returns an `AgentToolCallOutcome`. Nested calls use the ordinary argument preparation, schema validation, permission hooks, and result hooks. They cannot bypass session allowlists, exclusions, or `model-only` exposure.
396
+ Inside `execute()`, `ctx` is an `ExtensionToolContext`:
425
397
 
426
- If your orchestrator invokes a tool with `concurrency: "exclusive"`, give the orchestrator `concurrency: "exclusive"` too. A shared orchestrator cannot safely upgrade its nested call to exclusive access and receives an error before that target executes. File mutation queues remain required for read-modify-write operations.
398
+ - `ctx.tools` lists callable tools allowed by the session.
399
+ - `ctx.executeTool(name, args, { signal, onUpdate })` invokes another tool through the normal argument preparation, validation, permission hooks, and result hooks, returning an `AgentToolCallOutcome`. Nested calls cannot bypass session allowlists, exclusions, or `model-only` exposure.
400
+ - If your orchestrator calls a tool with `concurrency: "exclusive"`, mark the orchestrator `concurrency: "exclusive"` as well. A shared tool cannot upgrade a nested call to exclusive access and receives an error before the target runs.
427
401
 
428
- Nested execution events and the nested tool's `ctx` include `parentToolCallId`. Nested calls do not create separate conversation messages; the parent reports their results. Its final result may carry bounded `nestedCalls` metadata for exports and file-operation tracking. Report only the parent's own usage: nested usage is aggregated automatically, including deeper calls.
402
+ Nested execution events and the nested tool's `ctx` include `parentToolCallId`. Nested calls do not create separate transcript messages; the parent reports their outcomes and may attach bounded `nestedCalls` metadata. Report only the parent's own usage because nested usage aggregates automatically.
429
403
 
430
404
  ### Tool exposure
431
405
 
432
- `ToolDefinition.exposure` controls whether a tool is declared to the model or callable by another tool. Omission means `direct`:
406
+ `ToolDefinition.exposure` controls whether a tool is declared to the model or callable from another tool. Omitting it defaults to `"direct"`:
433
407
 
434
408
  | Exposure | Model declaration | Callable from another tool |
435
409
  | --- | --- | --- |
@@ -439,76 +413,62 @@ Nested execution events and the nested tool's `ctx` include `parentToolCallId`.
439
413
  | `deferred` | Only if explicitly activated | When registered and permitted by the session |
440
414
  | `hidden` | Never | Never |
441
415
 
442
- Use `model-only` for interactive or orchestration tools that should not be called from scripts. `codemode` tools are advertised in the codemode tool's catalog; `deferred` tools are discoverable without occupying that inline catalog. Session allowlists and exclusions remain authoritative. Exposure cannot restore a suppressed tool.
443
-
444
- Scripts can launch and control their session's subagents and send exact-target Intercom messages. They cannot edit agent definitions, ask questions of other sessions, or request interactive input. Use `model-only` for tools or actions that require the model to interact directly.
445
-
446
- A `model-only` tool can offer scripts part of its actions with `scriptAccess: { description, outputSchema?, refuse(params) }`. While the tool is active, scripts see it with `description` and receive its `structuredContent` as described by `outputSchema`. `refuse` runs after schema validation and before permission hooks, and returns why a script may not make the call, or `undefined` to run the tool's own `execute`. Direct calls are unaffected. Intercom uses it to let scripts list sessions and send to exact targets.
447
-
448
- `direct` and `model-only` tools activate by default. Set `defaultActive: false` to keep a registered tool inactive until you select it with `atomic.setActiveTools()`. `namespace: { name, description }` groups related tools. Optional `annotations` carry `readOnlyHint`, `destructiveHint`, `idempotentHint`, and `openWorldHint`; these are advisory hints, not permission checks or verified guarantees. Set `writesFiles: true` on a tool that changes files, so a turn that calls it records a [worktree snapshot](/worktree-snapshots) as `bash`, `edit`, and `write` do.
449
-
450
- An active orchestrator may implement `prepareLoadout(loadout)`. The loadout lists `declared`, `callable`, and `registered` tools and provides `getExposure(name)`, `getNamespace(name)`, and `getPromptGuidelines(name)`. Return `descriptions` to replace model-facing descriptions or `hiddenDeclarations` to hide declarations while retaining permitted nested access. This changes presentation, not authorization.
451
-
452
- ### Fireworks deferred tool loading
453
-
454
- Extensions making requests directly through `@bastani/atomic-ai` can use native deferred tool loading with Fireworks `anthropic-messages` models. Keep the discovery tool in `context.tools`. After the discovery tool result, append a chronological system message with `toolsAdded` (and `toolsRemoved` if needed) containing the newly loaded tool definitions. The provider serializes deferred definitions with `defer_loading` and inserts `tool_reference` content at the load point.
416
+ - Use `model-only` for interactive or orchestration tools that scripts should not invoke freely. You can expose a restricted subset to scripts with `scriptAccess: { description, outputSchema?, refuse(params) }`. `refuse` runs after validation and before permission hooks, returning an error reason string or `undefined` to allow execution. Direct model calls are unaffected.
417
+ - `codemode` tools appear in the codemode tool catalog; `deferred` tools stay discoverable without occupying the inline catalog. Session allowlists and exclusions always take precedence.
418
+ - `direct` and `model-only` tools activate by default. Set `defaultActive: false` to keep a tool inactive until activated with `atomic.setActiveTools()`.
419
+ - `namespace: { name, description, instructions? }` groups related tools and optional namespace-level guidance.
420
+ - Optional `annotations` carry advisory hints (`readOnlyHint`, `destructiveHint`, `idempotentHint`, `openWorldHint`) that do not enforce permissions.
421
+ - Set `writesFiles: true` on tools that modify files so turns calling them record a [worktree snapshot](/worktree-snapshots) like `bash`, `edit`, and `write`.
422
+ - An active orchestrator tool can implement `prepareLoadout(loadout)` to adjust how tools are described or hidden from the model (returning `descriptions` or `hiddenDeclarations`). This changes model presentation only, not authorization.
455
423
 
456
- Name the loader `ToolSearch` or `tool_search` to keep deferred schemas out of the initial prompt prefix. Other names work, but Fireworks includes the schemas in the prefix and loses that cache benefit. Fireworks GLM models and Kimi K3 still use Chat Completions; this feature does not change their routing.
457
-
458
- This is an AI SDK capability. Atomic's `atomic.setActiveTools()` updates the active tool list and records chronological system-message tool deltas for the next request; it does not attach tool names to a tool result. See the [AI SDK deferred tool-loading guide](https://github.com/bastani-inc/atomic/blob/main/packages/ai/README.md#fireworks-deferred-tools) for details.
424
+ **Fireworks deferred tool loading:** Extensions calling `@bastani/atomic-ai` directly can use native deferred tool loading on Fireworks `anthropic-messages` models. See [Libraries: AI](/libraries/ai) and the [AI SDK deferred tool-loading guide](https://github.com/bastani-inc/atomic/blob/main/packages/ai/README.md#fireworks-deferred-tools).
459
425
 
460
426
  ### Overriding built-in tools
461
427
 
462
- Extensions can override built-in tools (`read`, `bash`, `powershell`, `kill`, `edit`, `write`, `find`, `search`, `ask_user_question`, `todo`) by registering a tool with the same name. Interactive mode displays a warning when this happens.
428
+ Extensions can override built-in tools (`read`, `bash`, `powershell`, `kill`, `edit`, `write`, `find`, `search`, `ls`, `ask_user_question`, `todo`) by registering a tool with the same name. Interactive mode displays a warning when a built-in tool is overridden:
463
429
 
464
430
  ```bash
465
431
  # Extension's read tool replaces built-in read
466
432
  atomic -e ./tool-override.ts
467
433
  ```
468
434
 
469
- Alternatively, use `--no-builtin-tools` to start without any built-in tools while keeping extension tools enabled:
435
+ Use `--no-builtin-tools` (short flag `-nbt`) to start with no built-in tools while keeping extension tools enabled:
470
436
 
471
437
  ```bash
472
- # No built-in tools, only extension tools
473
438
  atomic --no-builtin-tools -e ./my-extension.ts
474
439
  ```
475
440
 
476
- See [examples/extensions/tool-override.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/tool-override.ts) for a complete example that overrides `read` with logging and access control.
477
-
478
- **Rendering.** Built-in renderer inheritance is resolved per slot. Execution override and rendering override are independent. If your override omits `renderCall`, the built-in `renderCall` is used. If your override omits `renderResult`, the built-in `renderResult` is used. If your override omits both, the built-in renderer is used automatically for syntax highlighting, diffs, and status framing. This lets you wrap built-in tools for logging or access control without reimplementing the UI.
479
-
480
- **Prompt metadata.** `promptSnippet` and `promptGuidelines` are not inherited from the built-in tool. If your override should keep those prompt instructions, define them on the override explicitly (or reuse the exported `*ToolSystemPromptContribution` constants from `@bastani/atomic`).
481
-
482
- **Matching result shapes.** Your implementation must match the built-in tool's `details` shape because the UI and session logic depend on these fields for rendering and state tracking. Import the detail types and tool factories from `@bastani/atomic`:
441
+ See [examples/extensions/tool-override.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/tool-override.ts) for a complete override example.
483
442
 
484
- - `read`: `ReadToolDetails` (`createReadToolDefinition`)
485
- - `bash`: `BashToolDetails` (`createBashToolDefinition`)
486
- - `powershell`: `PowerShellToolDetails` (`createPowerShellToolDefinition`)
487
- - `edit`: `EditToolDetails` (`createEditToolDefinition`)
488
- - `find`: `FindToolDetails` (`createFindToolDefinition`)
489
- - `search`: `SearchToolDetails` (`createSearchToolDefinition`)
490
- - `ls`: `LsToolDetails` (`createLsToolDefinition`)
491
- - `write`, `kill`, `ask_user_question`, `todo`: `createWriteToolDefinition`, `createKillToolDefinition`, `createAskUserQuestionToolDefinition`, `createTodoToolDefinition`
443
+ - **Renderer inheritance:** Execution and rendering overrides are independent per slot. If your override omits `renderCall` or `renderResult`, Atomic keeps the built-in renderer for that slot (syntax highlighting, diffs, and framing).
444
+ - **Prompt metadata:** `promptSnippet` and `promptGuidelines` are not inherited from the built-in tool. Set them explicitly or reuse the exported `*ToolSystemPromptContribution` constants from `@bastani/atomic`.
445
+ - **Matching `details` shapes:** Match the built-in tool's `details` type so built-in renderers and session logic work. Import detail types and factories from `@bastani/atomic`:
446
+ - `read`: `ReadToolDetails` (`createReadToolDefinition`)
447
+ - `bash`: `BashToolDetails` (`createBashToolDefinition`)
448
+ - `powershell`: `PowerShellToolDetails` (`createPowerShellToolDefinition`)
449
+ - `edit`: `EditToolDetails` (`createEditToolDefinition`)
450
+ - `find`: `FindToolDetails` (`createFindToolDefinition`)
451
+ - `search`: `SearchToolDetails` (`createSearchToolDefinition`)
452
+ - `ls`: `LsToolDetails` (`createLsToolDefinition`)
453
+ - `write`, `kill`, `ask_user_question`, `todo`: `createWriteToolDefinition`, `createKillToolDefinition`, `createAskUserQuestionToolDefinition`, `createTodoToolDefinition`
492
454
 
493
455
  ### Remote execution
494
456
 
495
- Built-in tools support pluggable operations for delegating to remote systems (SSH, containers, and sandboxes):
457
+ Built-in tools accept pluggable operations objects for SSH, containers, and sandboxes:
496
458
 
497
459
  ```typescript
498
- import { createReadTool, createBashTool, type ReadOperations } from "@bastani/atomic";
460
+ import { createReadTool, type ReadOperations } from "@bastani/atomic";
499
461
 
500
- // Create tool with custom operations
501
462
  const remoteRead = createReadTool(cwd, {
502
463
  operations: {
503
464
  readFile: (path) => sshExec(remote, `cat ${path}`),
504
465
  access: (path) => sshExec(remote, `test -r ${path}`).then(() => {}),
505
- }
466
+ },
506
467
  });
507
468
 
508
- // Register, checking flag at execution time
509
469
  atomic.registerTool({
510
470
  ...remoteRead,
511
- async execute(id, params, signal, onUpdate, _ctx) {
471
+ async execute(id, params, signal, onUpdate) {
512
472
  const ssh = getSshConfig();
513
473
  if (ssh) {
514
474
  const tool = createReadTool(cwd, { operations: createRemoteOps(ssh) });
@@ -519,17 +479,11 @@ atomic.registerTool({
519
479
  });
520
480
  ```
521
481
 
522
- `ReadOperations` may also provide `stat` and `listDir` to keep directory-tree reads on the injected filesystem. A custom read backend without both members keeps file-only remote behavior. Archive, SQLite, internal-resource, notebook, and path-variant helpers still use Atomic's local filesystem unless the tool gains dedicated remote hooks.
523
-
524
- `ReadOperations.createReadStream` is optional. When it returns the file as an async iterable of `Uint8Array` chunks (a Node `Readable` without an encoding works), `read` keeps only the lines it shows in memory, so a line range of a large file stays small, and stops consuming the stream when the call is cancelled. Without it, `read` loads the whole file through `readFile`. `:conflicts` views and notebooks still read the whole file.
525
-
526
- **Operations interfaces:** `ReadOperations`, `WriteOperations`, `EditOperations`, `BashOperations`, `PowerShellOperations`, `LsOperations`, `GrepOperations`, `FindOperations`
527
-
528
- `GrepOperations` only uses the directory check because search always scans the local filesystem with native search or `rg`. The optional `readFile` callback is deprecated and ignored, including for context lines. Existing integrations can leave it in place, but to search a remote system, override `execute()` instead.
529
-
530
- For `user_bash`, extensions can reuse Atomic's local shell backend via `createLocalBashOperations()` instead of reimplementing local process spawning, shell resolution, and process-tree termination.
531
-
532
- The bash tool also supports a spawn hook to adjust the command, cwd, or env before execution:
482
+ - `ReadOperations` can provide `stat` and `listDir` for remote directory reads, and optional `createReadStream` (returning an async iterable of `Uint8Array` chunks, such as a Node `Readable` without encoding) so line ranges of large files stream without reading the whole file into memory. `:conflicts` views and notebooks still read the full file. Archive, SQLite, internal-resource, and notebook helpers stay local.
483
+ - **Operations interfaces:** `ReadOperations`, `WriteOperations`, `EditOperations`, `BashOperations`, `PowerShellOperations`, `LsOperations`, `GrepOperations`, `FindOperations`.
484
+ - `GrepOperations` checks only directories because search scans the local filesystem with native search or `rg`; its optional `readFile` callback is deprecated and ignored. Override `execute()` to search a remote host.
485
+ - For `user_bash` handlers, call `createLocalBashOperations()` to reuse Atomic's local shell spawning and process-tree cleanup.
486
+ - `createBashTool()` supports `spawnHook` to modify `command`, `cwd`, or `env` before launch:
533
487
 
534
488
  ```typescript
535
489
  import { createBashTool } from "@bastani/atomic";
@@ -543,43 +497,32 @@ const bashTool = createBashTool(cwd, {
543
497
  });
544
498
  ```
545
499
 
546
- See [examples/extensions/ssh.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/ssh.ts) for a complete SSH example with `--ssh` flag.
500
+ See [examples/extensions/ssh.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/ssh.ts) for a full SSH example.
547
501
 
548
502
  ### Output truncation
549
503
 
550
- **Tools MUST truncate their output** to avoid overwhelming the LLM context. Large outputs can cause:
551
- - Context overflow errors (prompt too long)
552
- - Compaction failures
553
- - Degraded model performance
554
-
555
- The built-in limit is **50KB** (~10k tokens) and **2000 lines**, whichever is hit first. Use the exported truncation utilities:
504
+ **Tools must truncate large output** to avoid context overflow errors, compaction failures, and degraded responses. The built-in limit is **50 KB** (~10k tokens) and **2,000 lines**, whichever comes first:
556
505
 
557
506
  ```typescript
558
507
  import {
559
- truncateHead, // Keep first N lines/bytes (good for file reads, search results)
560
- truncateTail, // Keep last N lines/bytes (good for logs, command output)
508
+ truncateHead, // Keep first N lines/bytes (file reads, search results)
509
+ truncateTail, // Keep last N lines/bytes (logs, command output)
561
510
  truncateLine, // Truncate a single line to maxBytes with ellipsis
562
- formatSize, // Human-readable size (e.g., "50KB", "1.5MB")
511
+ formatSize, // Human-readable size ("50KB", "1.5MB")
563
512
  DEFAULT_MAX_BYTES, // 50KB
564
513
  DEFAULT_MAX_LINES, // 2000
565
514
  } from "@bastani/atomic";
566
515
 
567
- async execute(toolCallId, params, signal, onUpdate, ctx) {
516
+ async execute() {
568
517
  const output = await runCommand();
569
-
570
- // Apply truncation
571
518
  const truncation = truncateHead(output, {
572
519
  maxLines: DEFAULT_MAX_LINES,
573
520
  maxBytes: DEFAULT_MAX_BYTES,
574
521
  });
575
522
 
576
523
  let result = truncation.content;
577
-
578
524
  if (truncation.truncated) {
579
- // Write full output to temp file
580
525
  const tempFile = writeTempFile(output);
581
-
582
- // Inform the LLM where to find complete output
583
526
  result += `\n\n[Output truncated: ${truncation.outputLines} of ${truncation.totalLines} lines`;
584
527
  result += ` (${formatSize(truncation.outputBytes)} of ${formatSize(truncation.totalBytes)}).`;
585
528
  result += ` Full output saved to: ${tempFile}]`;
@@ -589,28 +532,23 @@ async execute(toolCallId, params, signal, onUpdate, ctx) {
589
532
  }
590
533
  ```
591
534
 
592
- **Key points:**
593
- - Use `truncateHead` for content where the beginning matters (search results, file reads)
594
- - Use `truncateTail` for content where the end matters (logs, command output)
595
- - Always inform the LLM when output is truncated and where to find the full version
596
- - Document the truncation limits in your tool's description
597
-
598
- See [examples/extensions/truncated-tool.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/truncated-tool.ts) for a complete example wrapping `rg` (ripgrep) with proper truncation.
535
+ Use `truncateHead` when the beginning matters, `truncateTail` when the end matters, inform the model where full output was saved, and document truncation limits in the tool description. See [examples/extensions/truncated-tool.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/truncated-tool.ts).
599
536
 
600
537
  ### Multiple tools
601
538
 
602
- One extension can register multiple tools with shared state:
539
+ One extension can register multiple tools sharing one resource and release it on `session_shutdown`:
603
540
 
604
541
  ```typescript
605
542
  export default function (atomic: ExtensionAPI) {
606
- let connection = null;
543
+ let connection: DbConnection | null = null;
607
544
 
608
- atomic.registerTool({ name: "db_connect", ... });
609
- atomic.registerTool({ name: "db_query", ... });
610
- atomic.registerTool({ name: "db_close", ... });
545
+ atomic.registerTool({ name: "db_connect", /* ... */ });
546
+ atomic.registerTool({ name: "db_query", /* ... */ });
547
+ atomic.registerTool({ name: "db_close", /* ... */ });
611
548
 
612
549
  atomic.on("session_shutdown", async () => {
613
550
  connection?.close();
551
+ connection = null;
614
552
  });
615
553
  }
616
554
  ```
@@ -619,13 +557,11 @@ export default function (atomic: ExtensionAPI) {
619
557
 
620
558
  Tools can provide `renderCall` and `renderResult` for custom display in the interactive transcript and HTML exports. See [TUI components](/tui) for the full component API.
621
559
 
622
- To choose renderers dynamically for any tool, including MCP tools in resumed sessions before their server connects, register a resolver with `atomic.registerToolRenderer((toolName, next) => renderers)`. Resolvers run in extension load order. `next()` returns the remaining resolvers' choice and then the registered tool's renderers, so `next() ?? mine` fills in only when no renderer exists. See [`atomic.registerToolRenderer()`](/extensions/api-reference#atomic-registertoolrenderer-resolver).
560
+ To select renderers dynamically for any tool (including MCP tools in resumed sessions before their server connects), register a resolver with `atomic.registerToolRenderer((toolName, next) => renderers)`. Resolvers run in extension load order; `next()` returns the remaining resolvers' choice and then the tool's own renderers, so `next() ?? mine` acts as a fallback. See [`atomic.registerToolRenderer()`](/extensions/api-reference#atomic-registertoolrenderer-resolver).
623
561
 
624
- Extension `Image` components render JPEG, GIF, and WebP images on Kitty-protocol terminals automatically, just like tool result images.
562
+ Extension `Image` components render JPEG, GIF, and WebP images on Kitty-protocol terminals automatically.
625
563
 
626
- By default, tool output is wrapped in a `Box` that handles padding and background. A defined `renderCall` or `renderResult` must return a `Component`. If a slot renderer is omitted, Atomic uses its fallback renderer for that slot.
627
-
628
- Set `renderShell: "self"` when the tool should draw its own shell instead of using the default `Box`. This is useful for tools that need complete control over framing or background behavior, for example large previews that must stay visually stable after the tool settles.
564
+ By default, tool output wraps in a `Box` handling padding and background. Each defined `renderCall` or `renderResult` must return a `Component`; an omitted slot falls back to Atomic's default renderer. Set `renderShell: "self"` when the tool draws its own outer framing and background:
629
565
 
630
566
  ```typescript
631
567
  atomic.registerTool({
@@ -637,28 +573,27 @@ atomic.registerTool({
637
573
  async execute() {
638
574
  return { content: [{ type: "text", text: "ok" }], details: undefined };
639
575
  },
640
- renderCall(args, theme, context) {
576
+ renderCall(_args, theme) {
641
577
  return new Text(theme.fg("accent", "my custom shell"), 0, 0);
642
578
  },
643
579
  });
644
580
  ```
645
581
 
646
- `renderCall` and `renderResult` each receive a `context` object with:
647
-
648
- - `args`. The current tool call arguments.
649
- - `state`. Shared row-local state across `renderCall` and `renderResult`.
650
- - `lastComponent`. The previously returned component for that slot, if any.
651
- - `invalidate()`. Request a rerender of this tool row.
652
- - `toolCallId`, `cwd`, `executionStarted`, `argsComplete`, `isPartial`, `expanded`, `showImages`, `isError`.
653
- - `durationMs`. Recorded execution time of the final result; `undefined` while running, when the tool did not run, or for older saved results.
654
- - `outputPad`. Configured horizontal padding; renderers with `renderShell: "self"` apply it themselves.
655
- - `keyText()`, `keyHint()`. Format the user's configured keybindings; see [Keybinding hints](#keybinding-hints).
582
+ `renderCall` and `renderResult` receive a `ToolRenderContext` object with:
656
583
 
657
- Use `context.state` for cross-slot shared state. Keep slot-local caches on the returned component instance when you want to reuse and mutate the same component across renders.
584
+ - `args`: current tool call arguments
585
+ - `state`: shared row-local state across `renderCall` and `renderResult`
586
+ - `lastComponent`: previously returned component for that slot, if any
587
+ - `invalidate()`: request a rerender of this tool row
588
+ - `toolCallId`, `cwd`, `executionStarted`, `argsComplete`, `isPartial`, `expanded`, `showImages`, `isError`
589
+ - `durationMs`: recorded execution time of the final result (`undefined` while running, when skipped, or on older saved results)
590
+ - `outputPad`: configured horizontal padding (apply it yourself when `renderShell: "self"`)
591
+ - `keyText()`, `keyHint()`: format the user's configured keybindings (see [Keybinding hints](#keybinding-hints))
592
+ - Optional helpers `getTaskRecord?()`, `getElapsedMs?()`, and `getToolDefinition?()` when exposed by the host
658
593
 
659
594
  #### renderCall
660
595
 
661
- Renders the tool call or header:
596
+ Renders the tool call header:
662
597
 
663
598
  ```typescript
664
599
  import { Text } from "@bastani/atomic-tui";
@@ -677,10 +612,10 @@ renderCall(args, theme, context) {
677
612
 
678
613
  #### renderResult
679
614
 
680
- Renders the tool result or output:
615
+ Renders the tool output:
681
616
 
682
617
  ```typescript
683
- renderResult(result, { expanded, isPartial }, theme, context) {
618
+ renderResult(result, { expanded, isPartial }, theme) {
684
619
  if (isPartial) {
685
620
  return new Text(theme.fg("warning", "Processing..."), 0, 0);
686
621
  }
@@ -699,11 +634,11 @@ renderResult(result, { expanded, isPartial }, theme, context) {
699
634
  }
700
635
  ```
701
636
 
702
- If a slot intentionally has no visible content, return an empty `Component` such as an empty `Container`.
637
+ Return an empty `Container` when a slot intentionally displays nothing.
703
638
 
704
639
  #### Keybinding hints
705
640
 
706
- Use `keyHint()` and `keyText()` from the render context to display keybinding hints that respect the user's keybinding configuration. Test `keyText()` for an empty string when a hint should disappear if the action has no effective keybinding, and add surrounding punctuation only when there is text:
641
+ Use `context.keyHint()` and `context.keyText()` (or `options.keyHint()` and `options.keyText()` in message and entry renderers) so hints match the user's `keybindings.json`. Test `keyText()` for an empty string before adding punctuation when a keybinding may be unbound:
707
642
 
708
643
  ```typescript
709
644
  renderResult(result, { expanded }, theme, context) {
@@ -715,47 +650,29 @@ renderResult(result, { expanded }, theme, context) {
715
650
  }
716
651
  ```
717
652
 
718
- The same functions are available as `options.keyHint()` and `options.keyText()` in message and entry renderers:
719
-
720
- - `keyHint(keybinding, description)`. Formats a configured keybinding id such as `"app.tools.expand"` or `"tui.select.confirm"`, followed by the description.
721
- - `keyText(keybinding)`. Returns the raw configured key text for a keybinding id, or `""` if the id has no keys.
722
-
723
- In renderers, use these context methods instead of importing `keyHint()`, `keyHintIfBound()`, or `keyText()` from `@bastani/atomic`. An extension can resolve its own copy of the package (for example from its own `node_modules`), and that copy does not see Atomic's configured keybindings, so `app.*` ids format as `""`. `rawKeyHint(key, description)` formats a literal key string and is safe to import.
724
-
725
- In fullscreen mode, clicking a hint from `keyHint()` or `rawKeyHint()` presses the key it names. A hint for `app.tools.expand` drawn inside a block that a click expands (such as your tool's result or message) is the exception: clicking it toggles that block alone, as clicking anywhere else on the block does. The hint carries zero-width marks that the renderer strips before writing to the terminal; use `keyText()` for key names in plain text such as notifications or log lines.
726
-
727
- To make a plain-text hint clickable, pass it through `clickableHintText()` from `@bastani/atomic-tui`, for example `clickableHintText("↑↓ select · enter choose · esc cancel")`. Named or modified keys can be separated from their label by a tab or Unicode space; for bare keys with that spacing, use `clickableKeysHint([{ text: "a", key: "a" }], "\u00a0accept")`.
728
-
729
- In `clickableHintText("esc / a destination")`, the slash and its label run `/`. Pass `["a"]` as the second argument if `a` is another key instead (`clickableHintText("1/2 / esc pick", ["1", "2"])` marks all three keys, while a plain ratio like `1 / 2` stays text).
730
-
731
- Use namespaced keybinding ids:
653
+ Do not import `keyHint()`, `keyHintIfBound()`, or `keyText()` from `@bastani/atomic` inside renderers; use the injected context methods so they read Atomic's active keybinding config. `rawKeyHint(key, description)` formats a literal key string and is safe to import.
732
654
 
733
- - Coding-agent ids use the `app.*` namespace, for example `app.tools.expand`, `app.editor.external`, `app.session.rename`.
734
- - Shared TUI ids use the `tui.*` namespace, for example `tui.select.confirm`, `tui.select.cancel`, `tui.input.tab`.
655
+ In fullscreen mode, clicking a hint from `keyHint()` or `rawKeyHint()` sends the named key (except `app.tools.expand` inside an expandable block, which toggles that block alone). Hints embed zero-width markers that the renderer strips before writing to the terminal; use `keyText()` for plain text such as notifications or logs.
735
656
 
736
- For the complete list of keybinding ids and defaults, see [Keybindings](/keybindings). `keybindings.json` uses those same namespaced ids.
657
+ To make a plain-text hint clickable, pass it through `clickableHintText()` from `@bastani/atomic-tui` (for example `clickableHintText("↑↓ select · enter choose · esc cancel")`), or use `clickableKeysHint([{ text: "a", key: "a" }], "\u00a0accept")` for bare keys. When a label contains `/`, pass extra bare keys in the second argument (for example `clickableHintText("1/2 / esc pick", ["1", "2"])`).
737
658
 
738
- Custom editors and `ctx.ui.custom()` components receive `keybindings: KeybindingsManager` as an injected argument. Use that injected manager directly instead of calling `getKeybindings()` or `setKeybindings()`.
659
+ Use namespaced keybinding IDs (`app.*` for coding-agent actions and `tui.*` for shared TUI actions; see [Keybindings](/keybindings)). Custom editors and `ctx.ui.custom()` components receive `keybindings: KeybindingsManager` as an argument; use it directly instead of calling `getKeybindings()` or `setKeybindings()`.
739
660
 
740
661
  #### Best practices
741
662
 
742
- - Use `Text` with padding `(0, 0)` because the default `Box` handles padding.
743
- - Use `\n` for multi-line content.
744
- - Handle `isPartial` for streaming progress.
745
- - Support `expanded` for detail on demand. Ctrl+O sets it for every block, and a click on your block toggles it for that block alone.
746
- - Keep the default view compact.
747
- - Read `context.args` in `renderResult` instead of copying args into `context.state`.
748
- - Use `context.state` only for data that must be shared across call and result slots.
749
- - Reuse `context.lastComponent` when the same component instance can be updated in place.
750
- - Use `renderShell: "self"` only when the default boxed shell gets in the way. In self-shell mode the tool is responsible for its own framing, padding, and background.
663
+ - Use `Text` with padding `(0, 0)` because the default `Box` adds padding.
664
+ - Handle `isPartial` for streaming progress and `expanded` for details on demand (`Ctrl+O` toggles all blocks; clicking toggles one block).
665
+ - Read `context.args` in `renderResult` instead of copying arguments into `context.state`.
666
+ - Reuse `context.lastComponent` when updating the same component across renders.
667
+ - Use `renderShell: "self"` only when you need custom outer framing, padding, and background.
751
668
 
752
669
  #### Fallback
753
670
 
754
- If a slot renderer is not defined or throws:
671
+ If a slot renderer is omitted or throws:
755
672
 
756
673
  - `renderCall`: shows the tool name
757
674
  - `renderResult`: shows raw text from `content`
758
675
 
759
676
  ## Next steps
760
677
 
761
- Continue with [extension events](/extensions/events) to hook into the session lifecycle. Use the [Extension API reference](/extensions/api-reference) to look up context properties and registration methods.
678
+ Continue with [Extension events](/extensions/events) to hook into the session lifecycle, or look up context properties and registration methods in the [Extension API reference](/extensions/api-reference).