@bastani/atomic 0.10.14 → 0.10.15-alpha.2

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 (342) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +1 -1
  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 +3 -3
  7. package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +3 -3
  8. package/dist/_shared/mode-shared-2QJSCUM6.js +3 -3
  9. package/dist/_shared/p1a-prewarm-XIU57JHF.js +3 -3
  10. package/dist/_shared/runtime-O4KCSG4C.js +2 -2
  11. package/dist/_shared/{sdk-B5LEWGGI.js → sdk-OHKMDJ74.js} +27 -5
  12. package/dist/_shared/{sdk-B5LEWGGI.js.map → sdk-OHKMDJ74.js.map} +1 -1
  13. package/dist/_shared/session-data-AHTU7IS6.js +2 -2
  14. package/dist/_shared/startup-0-0-Q3MWKUK4.js +2 -2
  15. package/dist/_shared/startup-0-1-M6OWAYHH.js +2 -2
  16. package/dist/_shared/{startup-0-2-5QHPCEON.js → startup-0-2-2HUMCPKX.js} +14 -16
  17. package/dist/_shared/startup-0-2-2HUMCPKX.js.map +1 -0
  18. package/dist/_shared/startup-0-3-4ZYBYQNM.js +3 -3
  19. package/dist/_shared/startup-0-4-ZMJV547D.js +3 -3
  20. package/dist/_shared/startup-0-5-YDW47QX6.js +3 -3
  21. package/dist/_shared/startup-10-0-TDQNBDDL.js +3 -3
  22. package/dist/_shared/startup-14-0-MLX36RBG.js +1 -1
  23. package/dist/_shared/startup-15-0-YUKGAC63.js +1 -1
  24. package/dist/_shared/startup-15-1-4S7FLMNG.js +6 -30
  25. package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
  26. package/dist/_shared/startup-8-0-34CBHPZH.js +3 -3
  27. package/dist/_shared/startup-8-1-LZFXSD3Z.js +3 -3
  28. package/dist/_shared/storage-command-7MGXLJGZ.js +2 -2
  29. package/dist/_shared/storage-status-K7PX2RXA.js +3 -3
  30. package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
  31. package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
  32. package/dist/builtin/intercom/index.bundle.mjs +1 -1
  33. package/dist/builtin/intercom/package.json +1 -1
  34. package/dist/builtin/mcp/index.bundle.mjs +1 -1
  35. package/dist/builtin/mcp/package.json +1 -1
  36. package/dist/builtin/subagents/package.json +1 -1
  37. package/dist/builtin/subagents/src/extension/index.bundle.mjs +1 -1
  38. package/dist/builtin/web-access/index.bundle.mjs +1 -1
  39. package/dist/builtin/web-access/package.json +1 -1
  40. package/dist/cli/auth-cli.code.js +1 -1
  41. package/dist/cli/auth-cli.impl.js +3 -3
  42. package/dist/cli/auth-cli.js +3 -3
  43. package/dist/cli/blueprint-command.impl.js +3 -3
  44. package/dist/cli/blueprint-command.js +3 -3
  45. package/dist/cli/intercom-command.code.js +3 -3
  46. package/dist/cli/intercom-command.impl.js +3 -3
  47. package/dist/cli/intercom-command.js +3 -3
  48. package/dist/cli/list-models.impl.js +3 -3
  49. package/dist/cli/list-models.js +3 -3
  50. package/dist/cli/session-picker.code.js +1 -1
  51. package/dist/cli/session-picker.impl.js +3 -3
  52. package/dist/cli/session-picker.js +3 -3
  53. package/dist/cli/startup-ui.code.js +1 -1
  54. package/dist/cli/startup-ui.impl.js +3 -3
  55. package/dist/cli/startup-ui.js +3 -3
  56. package/dist/cli/storage-command.impl.js +3 -3
  57. package/dist/cli/storage-command.js +3 -3
  58. package/dist/cli/storage-search-session.code.js +1 -1
  59. package/dist/cli/storage-search-session.impl.js +3 -3
  60. package/dist/cli/storage-search-session.js +3 -3
  61. package/dist/cli/team-command.code.js +1 -1
  62. package/dist/cli/team-command.impl.js +3 -3
  63. package/dist/cli/team-command.js +3 -3
  64. package/dist/cli.js +2 -2
  65. package/dist/core/compaction/compactor.d.ts +0 -8
  66. package/dist/core/debug.impl.js +3 -3
  67. package/dist/core/debug.js +3 -3
  68. package/dist/core/export-html/card-projection.impl.js +3 -3
  69. package/dist/core/export-html/card-projection.js +3 -3
  70. package/dist/core/export-html/index.code.js +2 -2
  71. package/dist/core/export-html/index.impl.js +3 -3
  72. package/dist/core/export-html/index.js +3 -3
  73. package/dist/core/export-html/json-spans.impl.js +3 -3
  74. package/dist/core/export-html/json-spans.js +3 -3
  75. package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
  76. package/dist/core/export-html/oversized-render-inputs.js +3 -3
  77. package/dist/core/export-html/tool-renderer.impl.js +3 -3
  78. package/dist/core/export-html/tool-renderer.js +3 -3
  79. package/dist/core/extensions/jiti-loader.impl.js +3 -3
  80. package/dist/core/extensions/jiti-loader.js +3 -3
  81. package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
  82. package/dist/core/extensions/jiti-static-loader.js +3 -3
  83. package/dist/core/extensions/loader-host-modules.impl.js +3 -3
  84. package/dist/core/extensions/loader-host-modules.js +3 -3
  85. package/dist/core/intercom-broker-control-host.code.js +1 -1
  86. package/dist/core/intercom-broker-control-host.impl.js +3 -3
  87. package/dist/core/intercom-broker-control-host.js +3 -3
  88. package/dist/core/intercom-broker-control.code.js +2 -2
  89. package/dist/core/intercom-broker-control.impl.js +3 -3
  90. package/dist/core/intercom-broker-control.js +3 -3
  91. package/dist/core/package-manager-storage-adapters.impl.js +3 -3
  92. package/dist/core/package-manager-storage-adapters.js +3 -3
  93. package/dist/core/sdk.code.js +1 -1
  94. package/dist/core/sdk.impl.js +3 -3
  95. package/dist/core/sdk.js +3 -3
  96. package/dist/core/session-manager-core.js +3 -3
  97. package/dist/core/session-manager-list.impl.js +3 -3
  98. package/dist/core/session-manager-list.js +3 -3
  99. package/dist/core/session-manager.impl.js +3 -3
  100. package/dist/core/session-manager.js +3 -3
  101. package/dist/core/session-storage.impl.js +3 -3
  102. package/dist/core/session-storage.js +3 -3
  103. package/dist/core/storage/index.js +2 -2
  104. package/dist/core/storage/node-sqlite-thread.js +2 -2
  105. package/dist/core/storage/node-sqlite.js +2 -2
  106. package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
  107. package/dist/core/storage/offline-snapshot-file.js +3 -3
  108. package/dist/core/storage/provider.js +2 -2
  109. package/dist/core/storage/selection.js +2 -2
  110. package/dist/core/storage/session/branch-fork-source.code.js +2 -2
  111. package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
  112. package/dist/core/storage/session/branch-fork-source.js +3 -3
  113. package/dist/core/storage/session/card-view.impl.js +3 -3
  114. package/dist/core/storage/session/card-view.js +3 -3
  115. package/dist/core/storage/session/child-reader.code.js +2 -2
  116. package/dist/core/storage/session/child-reader.impl.js +3 -3
  117. package/dist/core/storage/session/child-reader.js +3 -3
  118. package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
  119. package/dist/core/storage/session/chunked-resume-projection.js +3 -3
  120. package/dist/core/storage/session/expanded-child-details.code.js +2 -2
  121. package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
  122. package/dist/core/storage/session/expanded-child-details.js +3 -3
  123. package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
  124. package/dist/core/storage/session/fork-row-bytes.js +3 -3
  125. package/dist/core/storage/session/fork-row-index.impl.js +3 -3
  126. package/dist/core/storage/session/fork-row-index.js +3 -3
  127. package/dist/core/storage/session/fork-staging.code.js +1 -1
  128. package/dist/core/storage/session/fork-staging.impl.js +3 -3
  129. package/dist/core/storage/session/fork-staging.js +3 -3
  130. package/dist/core/storage/session/fork-window.code.js +2 -2
  131. package/dist/core/storage/session/fork-window.impl.js +3 -3
  132. package/dist/core/storage/session/fork-window.js +3 -3
  133. package/dist/core/storage/session/history-pages.impl.js +3 -3
  134. package/dist/core/storage/session/history-pages.js +3 -3
  135. package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
  136. package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
  137. package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
  138. package/dist/core/storage/session/jsonl-session-store.js +3 -3
  139. package/dist/core/storage/session/memory-session-store.impl.js +3 -3
  140. package/dist/core/storage/session/memory-session-store.js +3 -3
  141. package/dist/core/storage/session/pinned-branch-resume.code.js +2 -2
  142. package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
  143. package/dist/core/storage/session/pinned-branch-resume.js +3 -3
  144. package/dist/core/storage/session/released-history-files.code.js +1 -1
  145. package/dist/core/storage/session/released-history-files.impl.js +3 -3
  146. package/dist/core/storage/session/released-history-files.js +3 -3
  147. package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
  148. package/dist/core/storage/session/resident-fork-rows.js +3 -3
  149. package/dist/core/storage/session/session-resume.impl.js +3 -3
  150. package/dist/core/storage/session/session-resume.js +3 -3
  151. package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
  152. package/dist/core/storage/session/snapshot-cut.js +3 -3
  153. package/dist/core/storage/session/snapshot-history.code.js +2 -2
  154. package/dist/core/storage/session/snapshot-history.impl.js +3 -3
  155. package/dist/core/storage/session/snapshot-history.js +3 -3
  156. package/dist/core/storage/session/sql-session-store.code.js +1 -1
  157. package/dist/core/storage/session/sql-session-store.impl.js +3 -3
  158. package/dist/core/storage/session/sql-session-store.js +3 -3
  159. package/dist/core/storage/session/tree-outline.impl.js +3 -3
  160. package/dist/core/storage/session/tree-outline.js +3 -3
  161. package/dist/core/storage/session/tree-presentation.impl.js +3 -3
  162. package/dist/core/storage/session/tree-presentation.js +3 -3
  163. package/dist/core/storage/storage-status.impl.js +3 -3
  164. package/dist/core/storage/storage-status.js +3 -3
  165. package/dist/core/storage/team.impl.js +3 -3
  166. package/dist/core/storage/team.js +3 -3
  167. package/dist/core/structured-output/index.code.js +1 -1
  168. package/dist/core/structured-output/index.impl.js +3 -3
  169. package/dist/core/structured-output/index.js +3 -3
  170. package/dist/core/tasks/task-completion-entry.impl.js +3 -3
  171. package/dist/core/tasks/task-completion-entry.js +3 -3
  172. package/dist/core/tasks/task-file-history.code.js +2 -2
  173. package/dist/core/tasks/task-file-history.impl.js +3 -3
  174. package/dist/core/tasks/task-file-history.js +3 -3
  175. package/dist/core/tasks/task-reference-archive.code.js +2 -2
  176. package/dist/core/tasks/task-reference-archive.js +3 -3
  177. package/dist/core/tasks/task-reference-identity.js +3 -3
  178. package/dist/core/tasks/task-reference-stream.impl.js +3 -3
  179. package/dist/core/tasks/task-reference-stream.js +3 -3
  180. package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
  181. package/dist/core/tasks/task-unsaved-answer.js +3 -3
  182. package/dist/core/tasks/task-view-source.impl.js +3 -3
  183. package/dist/core/tasks/task-view-source.js +3 -3
  184. package/dist/core/tools/read-url.impl.js +3 -3
  185. package/dist/core/tools/read-url.js +3 -3
  186. package/dist/core/worktree-snapshot/blob-store.js +2 -2
  187. package/dist/core/worktree-snapshot/errors.code.js +1 -1
  188. package/dist/core/worktree-snapshot/errors.impl.js +3 -3
  189. package/dist/core/worktree-snapshot/errors.js +3 -3
  190. package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
  191. package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
  192. package/dist/extensions/codemode/execute.impl.js +3 -3
  193. package/dist/extensions/codemode/execute.js +3 -3
  194. package/dist/extensions/codemode/renderer.impl.js +3 -3
  195. package/dist/extensions/codemode/renderer.js +3 -3
  196. package/dist/extensions/mcp/cli.code.js +1 -1
  197. package/dist/extensions/mcp/cli.impl.js +3 -3
  198. package/dist/extensions/mcp/cli.js +3 -3
  199. package/dist/extensions/mcp/cli.lazy.code.js +2 -2
  200. package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
  201. package/dist/extensions/mcp/cli.lazy.js +3 -3
  202. package/dist/extensions/mcp/runtime.code.js +1 -1
  203. package/dist/extensions/mcp/runtime.impl.js +3 -3
  204. package/dist/extensions/mcp/runtime.js +3 -3
  205. package/dist/index.d.ts +21 -1
  206. package/dist/index.js +2 -2
  207. package/dist/main-first-time-setup.code.js +1 -1
  208. package/dist/main-first-time-setup.impl.js +3 -3
  209. package/dist/main-first-time-setup.js +3 -3
  210. package/dist/modes/interactive/components/stored-tree-view.code.js +2 -2
  211. package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
  212. package/dist/modes/interactive/components/stored-tree-view.js +3 -3
  213. package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
  214. package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
  215. package/dist/modes/print-mode.js +1 -1
  216. package/dist/package-manager-cli.code.js +2 -2
  217. package/dist/package-manager-cli.impl.js +3 -3
  218. package/dist/package-manager-cli.js +3 -3
  219. package/dist/startup-files.json +1 -1
  220. package/dist/startup-stages/6.js +1 -1
  221. package/dist/utils/startup-database-spare.code.js +1 -1
  222. package/dist/utils/startup-database-spare.impl.js +3 -3
  223. package/dist/utils/startup-database-spare.js +3 -3
  224. package/dist/utils/tools-manager.impl.js +3 -3
  225. package/dist/utils/tools-manager.js +3 -3
  226. package/docs/background-tasks/reference.md +182 -0
  227. package/docs/background-tasks.md +98 -405
  228. package/docs/build.md +67 -27
  229. package/docs/changelog.mdx +11 -1
  230. package/docs/codemode.md +108 -39
  231. package/docs/compaction/branch-summaries.md +54 -0
  232. package/docs/compaction/custom-compactors.md +161 -0
  233. package/docs/compaction/memory-compaction.md +77 -0
  234. package/docs/compaction/reference.md +86 -38
  235. package/docs/compaction.md +51 -252
  236. package/docs/computer-use.md +169 -321
  237. package/docs/containerization.md +71 -57
  238. package/docs/custom-provider/api-reference.md +119 -25
  239. package/docs/custom-provider/oauth.md +114 -132
  240. package/docs/custom-provider/override.md +37 -27
  241. package/docs/custom-provider/registration.md +107 -83
  242. package/docs/custom-provider/streaming.md +85 -71
  243. package/docs/custom-provider.md +85 -52
  244. package/docs/development.md +39 -29
  245. package/docs/docs.json +80 -67
  246. package/docs/environment-variables.md +94 -44
  247. package/docs/extensions/api-reference.md +86 -43
  248. package/docs/extensions/authoring.md +162 -154
  249. package/docs/extensions/events.md +80 -25
  250. package/docs/extensions/examples.md +90 -85
  251. package/docs/extensions/ui.md +206 -82
  252. package/docs/extensions.md +79 -108
  253. package/docs/getting-started/authentication.md +67 -36
  254. package/docs/getting-started/first-session.md +53 -43
  255. package/docs/getting-started/installation.md +117 -90
  256. package/docs/getting-started/project-instructions.md +48 -34
  257. package/docs/guides/configuration.md +82 -20
  258. package/docs/guides/non-interactive.md +66 -24
  259. package/docs/guides/resume-on-any-machine.md +135 -82
  260. package/docs/guides/team-setup.md +114 -105
  261. package/docs/guides.md +76 -32
  262. package/docs/herdr.md +16 -17
  263. package/docs/how-atomic-works.md +140 -0
  264. package/docs/index.md +58 -44
  265. package/docs/intercom/operations.md +141 -151
  266. package/docs/intercom/reference.md +85 -108
  267. package/docs/intercom.md +84 -145
  268. package/docs/json.md +120 -67
  269. package/docs/keybindings.md +85 -49
  270. package/docs/libraries/agent-core.md +137 -275
  271. package/docs/libraries/ai.md +100 -84
  272. package/docs/libraries/codemode.md +210 -300
  273. package/docs/libraries/schema.md +59 -53
  274. package/docs/libraries/storage-postgres.md +49 -35
  275. package/docs/libraries/telemetry.md +153 -354
  276. package/docs/libraries/tui.md +265 -393
  277. package/docs/libraries.md +42 -26
  278. package/docs/llama-cpp.md +171 -161
  279. package/docs/mcp-servers.md +90 -51
  280. package/docs/models/choose-a-model.md +188 -0
  281. package/docs/models/reference.md +74 -30
  282. package/docs/models.md +153 -88
  283. package/docs/orchestration/migrating-workflows.md +23 -16
  284. package/docs/orchestration/patterns.md +39 -44
  285. package/docs/orchestration.md +65 -26
  286. package/docs/packages/authoring.md +51 -29
  287. package/docs/packages/reference.md +42 -21
  288. package/docs/packages.md +69 -58
  289. package/docs/programmatic.md +118 -24
  290. package/docs/prompt-templates.md +84 -83
  291. package/docs/providers/reference.md +43 -48
  292. package/docs/providers.md +219 -451
  293. package/docs/quickstart.md +140 -120
  294. package/docs/reference/cli.md +135 -97
  295. package/docs/reference.md +20 -19
  296. package/docs/rpc/examples.md +76 -20
  297. package/docs/rpc/extension-ui.md +64 -38
  298. package/docs/rpc/protocol.md +361 -110
  299. package/docs/rpc.md +57 -17
  300. package/docs/sdk/reference.md +409 -534
  301. package/docs/sdk/storage.md +53 -13
  302. package/docs/sdk/structured-decisions.md +82 -56
  303. package/docs/sdk/web-server.md +57 -43
  304. package/docs/sdk.md +106 -84
  305. package/docs/security.md +42 -64
  306. package/docs/session-format.md +62 -38
  307. package/docs/sessions.md +99 -214
  308. package/docs/settings.md +165 -195
  309. package/docs/shell-aliases.md +9 -6
  310. package/docs/skills/authoring.md +69 -48
  311. package/docs/skills/reference.md +51 -20
  312. package/docs/skills.md +99 -148
  313. package/docs/slash-commands.md +129 -0
  314. package/docs/storage/custom-adapters.md +160 -85
  315. package/docs/storage/jsonl.md +81 -66
  316. package/docs/storage/postgres/pgbouncer.md +120 -126
  317. package/docs/storage/postgres/tuning.md +120 -143
  318. package/docs/storage/postgres.md +314 -330
  319. package/docs/storage/sqlite.md +71 -42
  320. package/docs/storage.md +298 -302
  321. package/docs/subagents/authoring.md +55 -38
  322. package/docs/subagents/reference.md +73 -33
  323. package/docs/subagents.md +119 -187
  324. package/docs/terminal-setup.md +51 -39
  325. package/docs/themes/reference.md +23 -19
  326. package/docs/themes.md +142 -127
  327. package/docs/tmux.md +47 -55
  328. package/docs/tools.md +147 -109
  329. package/docs/tui/reference.md +166 -214
  330. package/docs/tui.md +196 -341
  331. package/docs/usage.md +118 -138
  332. package/docs/verification.md +79 -51
  333. package/docs/web-access.md +121 -101
  334. package/docs/windows.md +26 -27
  335. package/docs/worktree-snapshots/reference.md +245 -0
  336. package/docs/worktree-snapshots.md +71 -259
  337. package/package.json +8 -8
  338. package/dist/_shared/startup-0-2-5QHPCEON.js.map +0 -1
  339. package/docs/guides/intercom.md +0 -32
  340. package/docs/guides/orchestration.md +0 -28
  341. package/docs/guides/subagents.md +0 -37
  342. package/docs/termux.md +0 -118
package/docs/tui.md CHANGED
@@ -1,38 +1,40 @@
1
1
  ---
2
2
  title: "Build TUI components"
3
- sidebarTitle: "TUI components"
3
+ sidebarTitle: "Build TUI components"
4
4
  description: "Build custom interactive terminal UI components, overlays, selectors, widgets, and editors for Atomic extensions."
5
5
  ---
6
6
 
7
- Extensions and custom tools can render custom terminal UI (TUI) components for interactive workflows. This guide covers `ctx.ui.custom()`, overlays, built-in components, theming, and common patterns. For the full `Component`, `ExtensionCustomComponent`, `Focusable`, keyboard, invalidation, debug logging, and host-native UI contracts, see [TUI API reference](/tui/reference) and [`@bastani/atomic-tui`](/libraries/tui).
7
+ Extensions and custom tools can render interactive terminal UI (TUI) components with `ctx.ui.custom()`, overlays, widgets, status indicators, and custom editors. For low-level rendering primitives (`TuiMainScreen`, `TuiAltScreen`, `Component`, `Focusable`, `matchesKey`, and built-in primitives), see [`@bastani/atomic-tui`](/libraries/tui). For full Atomic extension contracts (`ToolBlock`, `ExtensionCustomComponent`, advanced `ctx.ui.custom()` options, theme invalidation, debug logging, and host-native dialogs), see [TUI API reference](/tui/reference).
8
8
 
9
- ## Using components
9
+ ## Using `ctx.ui.custom()`
10
10
 
11
- Use `ctx.ui.custom()` with a synchronous or `async` component factory (`ExtensionCustomComponent | Promise<ExtensionCustomComponent>`). The factory receives `done(result)`, and `ctx.ui.custom()` resolves with that value when the component calls `done()`. Components may also implement `dispose?(): void` for cleanup when dismissed.
11
+ Pass a synchronous or `async` component factory (`ExtensionCustomComponent | Promise<ExtensionCustomComponent>`) to `ctx.ui.custom()`. The factory receives `(tui, theme, keybindings, done)`, and `ctx.ui.custom()` resolves with the value you pass to `done()`. Components can also implement `dispose?(): void` for cleanup when dismissed.
12
12
 
13
13
  ```typescript
14
14
  atomic.on("session_start", async (_event, ctx) => {
15
15
  const result = await ctx.ui.custom((tui, theme, keybindings, done) => {
16
- return new MyComponent(done);
16
+ return new MyComponent(theme, done);
17
17
  });
18
18
  ctx.ui.notify(`Selected: ${result}`, "info");
19
19
  });
20
20
  ```
21
21
 
22
- Key options for `ctx.ui.custom(factory, options?)`:
22
+ Common options for `ctx.ui.custom(factory, options?)`:
23
23
 
24
- - **`handlesCtrlC?: boolean`:** By default (`false`), Atomic closes a custom component on the first `Ctrl+C` so a wedged component cannot trap the keyboard. Set `handlesCtrlC: true` only when your component handles `Ctrl+C` itself (for example to cancel, skip, or close cleanly).
25
- - **`handlesInternalUiAction?: boolean`:** Set `true` when the component claims internal UI actions such as clicking the jump-to-bottom URL.
26
- - **`signal?: AbortSignal`:** Dismisses the component and releases input ownership when aborted. Inside Atomic's CLI terminal UI, aborting resolves with `undefined` (matching user cancellation); in an embedded SDK TUI host, aborting rejects with `signal.reason`.
27
- - **`purpose?: "prompt" | "navigation"`:** Defaults to `"prompt"` (for approvals and required user decisions). Pass `{ purpose: "navigation" }` for inspection or browsing views so Atomic mounts the component without emitting `ui_prompt_start`/`ui_prompt_end`. Inline navigation temporarily hides `ctx.ui.setWidget()` widgets, the agent panel, and queued previews until the last inline navigation view closes (overlays do not hide them). In `getHostCustomUiState()`, `blockingInlineCustomUiActive` counts all inline mounts while `blockingInlineCustomUiNeedsInput` distinguishes required prompts from navigation views.
28
- - **`blocked?: { kind: "question" | "permission" | "auth", message: string }`:** Reports Atomic as waiting for user input through [program status](/terminal-setup#program-status). Inline components report blocked while visible; overlays report blocked from mount until `done()` or `signal` abort, even while hidden with `setHidden()` or covered by another overlay. When several blocking prompts are open, the most recently shown one supplies `kind` and `message`.
29
- - **`overlay?: boolean`, `overlayOptions?: OverlayOptions | (() => OverlayOptions)`, `onHandle?: (handle: OverlayHandle) => void`:** Mounts the component as a floating overlay (see [Overlays](#overlays)). `overlayOptions` may be a static object or a callback evaluated dynamically on render.
30
- - **`deferInlineCustomUiFocus?: boolean`:** Overlay option that keeps pending inline custom UI deferred in the background while the overlay holds focus.
31
- - **`reserveTranscriptRows?: boolean`:** Overlay-only option for blocking bottom-anchored dialogs (such as `ask_user_question`). Requires a bottom anchor (`bottom-left`, `bottom-center`, or `bottom-right`), rejects `row` and nonzero `offsetY`, leaves at least 6 transcript rows visible above the overlay, and extends transcript scrollback so every line can scroll into view. On short terminals, embed `OVERLAY_ACTIVE_ROW_MARKER` (exported from `@bastani/atomic`) once per frame in your selected row so Atomic windows the cropped overlay around that row instead of clipping it from the top.
24
+ | Option | Default | Purpose |
25
+ | --- | --- | --- |
26
+ | `overlay` | `false` | Mount the component as a floating overlay instead of replacing the editor slot (see [Overlays](#overlays)). |
27
+ | `overlayOptions` | Centered, max 80 cols | Static `OverlayOptions` object or `() => OverlayOptions` callback evaluated on render. |
28
+ | `onHandle` | — | Receives an `OverlayHandle` for programmatic focus and visibility control. |
29
+ | `handlesCtrlC` | `false` | By default, Atomic closes a custom component on the first `Ctrl+C` so a wedged component cannot trap input. Set `true` only if your component handles `Ctrl+C` cleanly itself. |
30
+ | `signal` | — | `AbortSignal` that dismisses the component when aborted (resolves `undefined` in Atomic's CLI TUI; rejects with `signal.reason` in embedded SDK TUI hosts). |
31
+ | `blocked` | — | `{ kind: "question" \| "permission" \| "auth", message: string }`. Reports Atomic as waiting for user input through [program status](/terminal-setup#program-status). |
32
32
 
33
- Main-chat inline custom UIs share the editor slot. Completing an older mount leaves the current one visible; closing the current mount restores the most recent pending inline UI, and the main editor returns only after the last inline owner closes. Reserving bottom prompts (`reserveTranscriptRows`) wait out of view while inline navigation or an overlay with `deferInlineCustomUiFocus` owns input, and `Escape` belongs to the active navigation view until it closes.
33
+ For advanced options (`purpose`, `handlesInternalUiAction`, `deferInlineCustomUiFocus`, `reserveTranscriptRows`, `OVERLAY_ACTIVE_ROW_MARKER`, and `HostCustomUiState`), see [Custom component options](/tui/reference#custom-component-options).
34
34
 
35
- Do not rely on host process globals from `render()` or `handleInput()`, and pass only JSON-safe values to `done()`. Return `true` for consumed viewport keys or overlay mouse events and `false` to let the transcript handle them. Set `wantsKeyRelease = true` only when your component needs key release events. Non-overlay components leave mouse scrolling and selection with the transcript.
35
+ <Note>
36
+ Do not rely on host process globals from `render()` or `handleInput()`, and pass only JSON-safe values to `done()`. Return `true` for consumed viewport keys or overlay mouse events and `false` to let the transcript handle them. Non-overlay components leave mouse scrolling and selection with the transcript.
37
+ </Note>
36
38
 
37
39
  ## Overlays
38
40
 
@@ -54,9 +56,9 @@ const result = await ctx.ui.custom<string | null>(
54
56
  overlay: true,
55
57
  overlayOptions: {
56
58
  // Size: number or percentage string
57
- width: "50%", // 50% of terminal width
58
- minWidth: 40, // minimum 40 columns
59
- maxHeight: "80%", // max 80% of terminal height
59
+ width: "50%", // 50% of terminal width
60
+ minWidth: 40, // minimum 40 columns
61
+ maxHeight: "80%", // max 80% of terminal height
60
62
 
61
63
  // Position: anchor-based (default: "center")
62
64
  anchor: "right-center", // 9 positions: center, top-left, top-center, etc.
@@ -64,16 +66,15 @@ const result = await ctx.ui.custom<string | null>(
64
66
  offsetY: 0,
65
67
 
66
68
  // Or percentage/absolute positioning
67
- row: "25%", // 25% from top
68
- col: 10, // column 10
69
+ row: "25%", // 25% from top
70
+ col: 10, // column 10
69
71
 
70
72
  // Margins
71
- margin: 2, // all sides, or { top, right, bottom, left }
73
+ margin: 2, // all sides, or { top, right, bottom, left }
72
74
 
73
75
  // Responsive: hide on narrow terminals
74
76
  visible: (termWidth, termHeight) => termWidth >= 80,
75
77
  },
76
- // Get handle for programmatic focus and visibility control
77
78
  onHandle: (handle) => {
78
79
  // handle.focus() - focus this overlay and bring it to the visual front
79
80
  // handle.unfocus() - release input to normal fallback
@@ -85,133 +86,55 @@ const result = await ctx.ui.custom<string | null>(
85
86
  );
86
87
  ```
87
88
 
88
- ### Overlay focus
89
+ ### Overlay focus and lifecycle
89
90
 
90
- A focused visible overlay keeps input ownership across temporary non-overlay UI. If an overlay opens another `ctx.ui.custom()` component without `{ overlay: true }`, that replacement UI receives input while active; when it closes, the focused overlay reclaims input.
91
+ A focused visible overlay keeps input ownership across temporary non-overlay UI: if it opens another inline `ctx.ui.custom()` component, that component receives input while active, and the overlay reclaims input when it closes. Call `handle.unfocus()` to release input to the fallback target, or `handle.unfocus({ target })` to focus a specific component (or `null` for none).
91
92
 
92
- Use `handle.unfocus()` to release input to another visible capturing overlay or the previous focus target. Use `handle.unfocus({ target })` to focus a specific component while keeping the overlay visible, or `{ target: null }` to leave no focused component until focus is set again.
93
-
94
- ### Overlay lifecycle
95
-
96
- Overlay components are disposed when closed. Create fresh instances rather than reusing references:
93
+ Overlay components are disposed when closed, so always create fresh instances instead of reusing closed references:
97
94
 
98
95
  ```typescript
99
- // Wrong - stale reference
100
- let menu: MenuComponent;
101
- await ctx.ui.custom((_, __, ___, done) => {
102
- menu = new MenuComponent(done);
103
- return menu;
104
- }, { overlay: true });
105
- setActiveComponent(menu); // Disposed
106
-
107
- // Correct - re-call to re-show
108
- const showMenu = () => ctx.ui.custom((_, __, ___, done) =>
109
- new MenuComponent(done), { overlay: true });
110
-
111
- await showMenu(); // First show
112
- await showMenu(); // "Back" = just call again
113
- ```
114
-
115
- See [overlay-qa-tests.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/overlay-qa-tests.ts) for examples covering anchors, margins, stacking, responsive visibility, and animation.
116
-
117
- ## Built-in components
118
-
119
- Import from `@bastani/atomic-tui`:
96
+ // Correct: call ctx.ui.custom() again to re-open a fresh instance
97
+ const showMenu = () =>
98
+ ctx.ui.custom((_, __, ___, done) => new MenuComponent(done), { overlay: true });
120
99
 
121
- ```typescript
122
- import { Text, Box, Container, Spacer, Markdown } from "@bastani/atomic-tui";
123
- ```
124
-
125
- ### Text
126
-
127
- Multi-line text with word wrapping.
128
-
129
- ```typescript
130
- const text = new Text(
131
- "Hello World", // content
132
- 1, // paddingX (default: 1)
133
- 1, // paddingY (default: 1)
134
- (s) => bgGray(s) // optional background function
135
- );
136
- text.setText("Updated");
137
- ```
138
-
139
- ### Box
140
-
141
- Container with padding and background color.
142
-
143
- ```typescript
144
- const box = new Box(
145
- 1, // paddingX
146
- 1, // paddingY
147
- (s) => bgGray(s) // background function
148
- );
149
- box.addChild(new Text("Content", 0, 0));
150
- box.setBgFn((s) => bgBlue(s));
151
- ```
152
-
153
- ### Container
154
-
155
- Groups child components vertically.
156
-
157
- ```typescript
158
- const container = new Container();
159
- container.addChild(component1);
160
- container.addChild(component2);
161
- container.removeChild(component1);
100
+ await showMenu(); // First show
101
+ await showMenu(); // Re-show cleanly
162
102
  ```
163
103
 
164
- ### Spacer
165
-
166
- Empty vertical space.
167
-
168
- ```typescript
169
- const spacer = new Spacer(2); // 2 empty lines
170
- ```
104
+ See [overlay-qa-tests.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/overlay-qa-tests.ts) for examples covering anchors, margins, stacking, responsive visibility, and animation.
171
105
 
172
- ### Markdown
106
+ ## Built-in primitives
173
107
 
174
- Renders markdown with syntax highlighting.
108
+ Import layout and content primitives from `@bastani/atomic-tui` (provided by Atomic without installing it):
175
109
 
176
110
  ```typescript
177
- const md = new Markdown(
178
- "# Title\n\nSome **bold** text",
179
- 1, // paddingX
180
- 1, // paddingY
181
- theme // MarkdownTheme (see below)
182
- );
183
- md.setText("Updated markdown");
111
+ import { Box, Container, Image, Markdown, Spacer, Text } from "@bastani/atomic-tui";
184
112
  ```
185
113
 
186
- ### Image
114
+ | Component | Purpose | Typical usage |
115
+ | --- | --- | --- |
116
+ | `Text` | Multi-line wrapped text with padding and optional background | `new Text(theme.fg("accent", "Ready"), 1, 0)` |
117
+ | `Box` | Padded container with optional background color | `new Box(1, 1, (s) => theme.bg("selectedBg", s))` |
118
+ | `Container` | Vertical group of child components | `container.addChild(child); container.removeChild(child);` |
119
+ | `Spacer` | Vertical blank rows | `new Spacer(1)` |
120
+ | `Markdown` | Styled Markdown renderer with optional syntax highlighting | `new Markdown(md, 1, 1, getMarkdownTheme())` |
121
+ | `Image` | Inline image for Kitty/iTerm2-capable terminals (text fallback elsewhere) | `new Image(base64Data, "image/png", imageTheme, { maxWidthCells: 80 })` |
187
122
 
188
- Renders images in supported terminals (Kitty, iTerm2, Ghostty, WezTerm, Warp).
189
-
190
- ```typescript
191
- const image = new Image(
192
- base64Data, // base64-encoded image
193
- "image/png", // MIME type
194
- theme, // ImageTheme
195
- { maxWidthCells: 80, maxHeightCells: 24 }
196
- );
197
- ```
123
+ See [`@bastani/atomic-tui` built-in components](/libraries/tui#built-in-components) for full constructor signatures, options, and additional primitives (`Input`, `Editor`, `Loader`, `CancellableLoader`, `TruncatedText`, `WindowedContainer`, `VStack`, `HStack`, `ScrollView`).
198
124
 
199
125
  ## Creating custom components
200
126
 
201
- Example: Interactive selector
127
+ Implement `render(width)`, `invalidate()`, and optional `handleInput(data)` to build a custom interactive component:
202
128
 
203
129
  ```typescript
204
- import {
205
- matchesKey, Key,
206
- truncateToWidth, visibleWidth
207
- } from "@bastani/atomic-tui";
130
+ import { Key, matchesKey, truncateToWidth } from "@bastani/atomic-tui";
208
131
 
209
132
  class MySelector {
210
133
  private items: string[];
211
134
  private selected = 0;
212
135
  private cachedWidth?: number;
213
136
  private cachedLines?: string[];
214
-
137
+
215
138
  public onSelect?: (item: string) => void;
216
139
  public onCancel?: () => void;
217
140
 
@@ -229,7 +152,7 @@ class MySelector {
229
152
  this.invalidate();
230
153
  return true;
231
154
  } else if (matchesKey(data, Key.enter)) {
232
- this.onSelect?.(this.items[this.selected]);
155
+ this.onSelect?.(this.items[this.selected]!);
233
156
  return true;
234
157
  } else if (matchesKey(data, Key.escape)) {
235
158
  this.onCancel?.();
@@ -258,41 +181,45 @@ class MySelector {
258
181
  }
259
182
  ```
260
183
 
261
- Usage in an extension:
184
+ Use it inside a slash command handler:
262
185
 
263
186
  ```typescript
264
187
  atomic.registerCommand("pick", {
265
188
  description: "Pick an item",
266
- handler: async (args, ctx) => {
189
+ handler: async (_args, ctx) => {
267
190
  const items = ["Option A", "Option B", "Option C"];
268
191
  const selector = new MySelector(items);
269
-
270
- const selected = await ctx.ui.custom<string | undefined>((_tui, _theme, _keybindings, done) => {
192
+
193
+ const selected = await ctx.ui.custom<string | undefined>((tui, _theme, _keybindings, done) => {
271
194
  selector.onSelect = (item) => done(item);
272
195
  selector.onCancel = () => done(undefined);
273
- return selector;
196
+ return {
197
+ render: (w) => selector.render(w),
198
+ invalidate: () => selector.invalidate(),
199
+ handleInput: (data) => {
200
+ const handled = selector.handleInput(data);
201
+ if (handled) tui.requestRender();
202
+ return handled;
203
+ },
204
+ };
274
205
  });
275
206
 
276
207
  if (selected) {
277
208
  ctx.ui.notify(`Selected: ${selected}`, "info");
278
209
  }
279
- }
210
+ },
280
211
  });
281
212
  ```
282
213
 
283
214
  ## Theming
284
215
 
285
- Components accept theme objects for styling.
286
-
287
- **In `renderCall`/`renderResult`**, use the `theme` parameter:
216
+ Always use the `theme` passed to your callback (`ctx.ui.custom`, `ctx.ui.setWidget`, `renderCall`, `renderResult`) rather than importing a theme singleton directly:
288
217
 
289
218
  ```typescript
290
219
  renderResult(result, options, theme, context) {
291
- // Use theme.fg() for foreground colors
292
- return new Text(theme.fg("success", "Done!"), 0, 0);
293
-
294
- // Use theme.bg() for background colors
295
- const styled = theme.bg("toolPendingBg", theme.fg("accent", "text"));
220
+ const status = theme.fg("success", "Done!");
221
+ const badge = theme.bg("toolPendingBg", theme.fg("accent", "pending"));
222
+ return new Text(`${status} ${badge}`, 0, 0);
296
223
  }
297
224
  ```
298
225
 
@@ -311,38 +238,28 @@ renderResult(result, options, theme, context) {
311
238
  | Thinking | `thinkingText`, `thinkingOff`, `thinkingMinimal`, `thinkingLow`, `thinkingMedium`, `thinkingHigh`, `thinkingXhigh` |
312
239
  | Modes | `bashMode` |
313
240
 
314
- **Background colors** (`theme.bg(color, text)`):
315
-
316
- `selectedBg`, `userMessageBg`, `customMessageBg`, `toolPendingBg`, `toolSuccessBg`, `toolErrorBg`, `scrollbarThumb`, `searchMatchBg`
241
+ **Background colors** (`theme.bg(color, text)`): `selectedBg`, `userMessageBg`, `customMessageBg`, `toolPendingBg`, `toolSuccessBg`, `toolErrorBg`, `scrollbarThumb`, `searchMatchBg`.
317
242
 
318
- **For Markdown**, use `getMarkdownTheme()`:
243
+ For `Markdown` components, call `getMarkdownTheme()` from `@bastani/atomic`:
319
244
 
320
245
  ```typescript
321
246
  import { getMarkdownTheme } from "@bastani/atomic";
322
247
  import { Markdown } from "@bastani/atomic-tui";
323
248
 
324
- renderResult(result, options, theme, context) {
325
- const mdTheme = getMarkdownTheme();
326
- return new Markdown(result.details.markdown, 0, 0, mdTheme);
249
+ renderResult(result, _options, _theme, _context) {
250
+ return new Markdown(result.details.markdown, 0, 0, getMarkdownTheme());
327
251
  }
328
252
  ```
329
253
 
330
- **For custom components**, define your own theme interface:
331
-
332
- ```typescript
333
- interface MyTheme {
334
- selected: (s: string) => string;
335
- normal: (s: string) => string;
336
- }
337
- ```
254
+ If your component stores pre-baked themed strings in child components, rebuild them in `invalidate()` so live theme changes take effect; see [Invalidation and theme changes](/tui/reference#invalidation-and-theme-changes).
338
255
 
339
256
  ## Common patterns
340
257
 
341
- These patterns cover the most common UI needs in extensions. Copy these patterns instead of building from scratch.
258
+ Use these built-in Atomic patterns instead of building interactive widgets from scratch.
342
259
 
343
- ### Pattern 1: Selection dialog (`Selector`)
260
+ ### Selection dialog (`Selector`)
344
261
 
345
- For letting users pick from a list, use `Selector` from `@bastani/atomic`. It powers `/model`, `/login`, `/logout`, `/thinking`, `/trust`, `/scoped-models`, and extension `select` and `confirm` dialogs, with a title, optional search box, one- or two-line rows with dim descriptions and right-aligned tags, scroll indicators, an empty state, and a key hint line.
262
+ Use `Selector` from `@bastani/atomic` for searchable, keyboard- and mouse-accessible pickers (the same component behind `/model`, `/login`, `/thinking`, `/trust`, and `ctx.ui.select`/`confirm`):
346
263
 
347
264
  ```typescript
348
265
  import { DynamicBorder, Selector } from "@bastani/atomic";
@@ -350,7 +267,7 @@ import { DynamicBorder, Selector } from "@bastani/atomic";
350
267
  const choice = await ctx.ui.custom<string | null>((tui, _theme, _kb, done) => {
351
268
  const selector = new Selector<string>({
352
269
  title: "Pick a preset",
353
- search: true, // typing filters; esc clears the search, then cancels
270
+ search: true, // typing filters; Esc clears search, then cancels
354
271
  items: [
355
272
  { id: "fast", value: "fast", label: "fast", description: "small model, low effort", mark: "on", tag: "current" },
356
273
  { id: "deep", value: "deep", label: "deep", description: "large model, high effort", mark: "off" },
@@ -371,48 +288,39 @@ const choice = await ctx.ui.custom<string | null>((tui, _theme, _kb, done) => {
371
288
  });
372
289
  ```
373
290
 
374
- Keys: Up/Down select (wrapping), PageUp/PageDown page, Home/End jump when search is off, Enter confirms, Right confirms when search is empty, Esc clears search before cancelling, and Ctrl+C always cancels. Mouse click chooses a row (or toggles in multi-select) and wheel input scrolls to the ends. Key options:
375
-
376
- | Option | Effect |
377
- | --- | --- |
378
- | `layout: "two-line"` | Places each description on the line under its label, for rows like sessions or runs. |
379
- | `wrap: true` | Wraps long titles and option labels instead of truncating. Extension `select` and `confirm` dialogs enable this automatically. |
380
- | `mode: "multi"` | Checkboxes: Space toggles, Enter calls `onConfirm` with checked rows and stops the picker regardless of `closeOnSelect`. |
381
- | `closeOnSelect: false` | Single-select only. Choosing a row calls `onSelect` and leaves the picker open so Enter or a click can choose again. Default `true`. |
382
- | `numbered: true` | Numbers rows; without a search box, digits 1 to 9 choose a row directly (or toggle with `mode: "multi"`). |
383
- | `onPreview` | Space previews the selected row; the hint shows `space preview`. |
384
- | `rightConfirms: false` | Disables the `app.list.open` shortcut (Right by default) when only Enter should confirm. |
385
- | `minDescriptionWidth` | Reserves columns for a one-line row's description, shortening its label before the value or right-hand tag. |
386
- | `onSelectionChange` | Fires when navigation or filtering changes the selected row's identity, or `undefined` when no enabled row matches. |
387
- | `extraKeys` | Custom keys with hints and `enabled(item)` checks so unavailable keys stay hidden. |
388
- | `group` on items | Groups rows under section labels (hidden while searching). |
389
- | `disabled` on items | Drawn dim, skipped by navigation and wheel, and ignored by Enter and clicks. |
390
- | `mark` on items | `"on"`/`"off"` draw `●`/`○`; `"checked"`/`"unchecked"` draw `[✓]`/`[ ]`. |
391
- | `labelStyle` on items | Custom label styling callback receiving whether the row is selected. |
392
- | `searchText` on items | Extra text matched by type-to-search (combined with label, description, and tag by default). |
393
- | `searchTextMode: "replace"` on items | Matches search only against `searchText` instead of label, description, and tag (default `"extend"`). |
394
- | `subtitle` | Dim text under the title; `\n` starts new lines and long lines wrap. |
395
-
396
- Without a search box, `?` opens key help (ignoring mouse input while open) and `j`/`k` navigate down/up. `setNotice({ text, tone })` displays a one-line status under the list.
397
-
398
- A picker stops accepting input once it invokes `onCancel`, `onConfirm`, or `onSelect` (unless `closeOnSelect` is `false`), so repeated keypresses or clicks run callbacks once. If an async callback fails (for example while saving), call `selector.retrySelection()` to resume input and pair it with `setNotice()` to display the error.
399
-
400
- `setItems()` replaces rows while keeping the selected enabled row by ID, then tries `preferId`, then scans forward (clamped) and backward for an enabled row. `onSelectionChange` fires only when the selected ID changes. `SelectorState.items` is read-only and frozen; use `state.setItems(rows)` or copy with `[...state.items]`. For persistent single-select pickers that replace rows after `onSelect`, set `closeOnSelect: false`.
401
-
402
- Call `selector.invalidate()` before `tui.requestRender()` when external data used by a custom `style` or `extraKeys` `enabled` callback changes. A row's `labelStyle` runs on every render.
403
-
404
- `SelectorState` holds search, selection, and checked rows headless for testing, and `selectorHintEntries(state, options)` returns its hint keys. `themeSelectorStyle()` returns themed colors; pass `style: PLAIN_SELECTOR_STYLE` for unstyled output.
405
-
406
- For live lists, call `selector.setItems(nextItems)` and `tui.requestRender()`. Selection stays on the same `id` when still enabled and matching, otherwise moves to the first enabled match, and removed checked items are dropped.
407
-
408
- `UserMessageSelectorComponent` implements the `/fork` picker on `Selector`: `new UserMessageSelectorComponent(messages, onSelect, onCancel, initialSelectedId?)` accepts user messages oldest first (`{ id, text }`), renders two-line rows, selects `initialSelectedId` or the newest message, and filters as you type. Focus the component directly; `getMessageList()` returns the component, and `onSelect`/`onCancel` are assignable properties.
409
-
410
- ### Pattern 1b: Selection dialog (`SelectList`)
411
-
412
- The lower-level `SelectList` from `@bastani/atomic-tui` is still available when you need a bare list inside your own layout, such as autocomplete rows. Frame it with `DynamicBorder`.
291
+ Navigation supports `Up`/`Down` (wrapping), `PageUp`/`PageDown`, `Home`/`End` (when search is off), `Enter`, `Right` (when search is empty), `Esc` (clears search, then cancels), `Ctrl+C`, mouse click, and wheel scrolling. Without a search box, `?` opens key help and `j`/`k` navigate.
292
+
293
+ Key `SelectorOptions` and item fields:
294
+
295
+ | Option | Default | Effect |
296
+ | --- | --- | --- |
297
+ | `title` / `subtitle` | — | Heading and dim wrapped subtitle (`\n` starts new lines). |
298
+ | `layout` | `"one-line"` | `"two-line"` places each description under its label (good for sessions or runs). |
299
+ | `mode` | `"single"` | `"multi"` adds checkboxes; `Space` toggles and `Enter` calls `onConfirm` with checked rows. |
300
+ | `search` / `searchPlaceholder` / `initialQuery` | `false` | Enables type-to-search with optional placeholder and starting query. |
301
+ | `maxVisible` | `10` | Maximum visible rows before scrolling. |
302
+ | `emptyText` | — | Message shown when `items` is empty. |
303
+ | `numbered` | `false` | Numbers rows `1.` `2.`; without search, digits `1`–`9` choose or toggle directly. |
304
+ | `wrap` | `false` | Wraps long titles and labels instead of truncating. |
305
+ | `initialId` / `initialChecked` | First `mark: "on"` or enabled row | Starting selection ID (and starting checked IDs in `"multi"` mode). |
306
+ | `closeOnSelect` | `true` | Single-select only. Set `false` to keep the picker open after `onSelect`. |
307
+ | `confirmLabel` / `cancelLabel` / `previewLabel` | `"choose"` or `"confirm"` / `"cancel"` | Custom hint text for `Enter`, `Esc`, and `Space` preview. |
308
+ | `spaceConfirms` / `rightConfirms` | `false` / `true` | Allow `Space` to confirm, or disable `Right` (`app.list.open`) confirmation. |
309
+ | `minDescriptionWidth` | — | Reserves columns for one-line descriptions, shortening labels first. |
310
+ | `selectedDetail` | — | Callback `(item) => string \| undefined` rendering extra detail for the selected row. |
311
+ | `onPreview` | — | `Space` previews the selected row; hint shows `space <previewLabel>`. |
312
+ | `onSelectionChange` | — | Fires when navigation or filtering changes the selected row ID (or `undefined`). |
313
+ | `extraKeys` | — | Custom key actions with hints and `enabled(item)` predicates. |
314
+ | `helpTitle` / `keybindings` / `style` | `title` / global / active theme | Title for `?` help overlay, keybindings source, and colors (`PLAIN_SELECTOR_STYLE` for unstyled). |
315
+ | Item fields | — | `group` (section label), `disabled`, `mark` (`"on"`/`"off"`/`"checked"`/`"unchecked"`), `tag` + `tagTone` (`"accent"` \| `"success"` \| `"warning"` \| `"error"` \| `"muted"` \| `"dim"`), `labelStyle`, `searchText`, `searchTextMode` (`"extend"` \| `"replace"`). |
316
+
317
+ For live updates, call `selector.setItems(nextItems)` and `tui.requestRender()`; selection stays on the same `id` when still enabled and matching. Call `selector.setNotice({ text, tone })` for a one-line status under the list, and call `selector.retrySelection()` if an async `onSelect`/`onConfirm` callback fails and should re-enable input. For headless testing (`SelectorState`, `selectorHintEntries`) and `UserMessageSelectorComponent`, see [Selector helpers](/tui/reference#selector-helpers).
318
+
319
+ ### Bare list (`SelectList`)
320
+
321
+ Use `SelectList` from `@bastani/atomic-tui` when you need a minimal list inside your own layout (such as custom autocomplete rows) framed with `DynamicBorder`:
413
322
 
414
323
  ```typescript
415
- import type { ExtensionAPI } from "@bastani/atomic";
416
324
  import { DynamicBorder } from "@bastani/atomic";
417
325
  import { Container, type SelectItem, SelectList, Text } from "@bastani/atomic-tui";
418
326
 
@@ -421,19 +329,14 @@ atomic.registerCommand("pick", {
421
329
  const items: SelectItem[] = [
422
330
  { value: "opt1", label: "Option 1", description: "First option" },
423
331
  { value: "opt2", label: "Option 2", description: "Second option" },
424
- { value: "opt3", label: "Option 3" }, // description is optional
332
+ { value: "opt3", label: "Option 3" },
425
333
  ];
426
334
 
427
335
  const result = await ctx.ui.custom<string | null>((tui, theme, _kb, done) => {
428
336
  const container = new Container();
429
-
430
- // Top border
431
337
  container.addChild(new DynamicBorder((s: string) => theme.fg("accent", s)));
432
-
433
- // Title
434
338
  container.addChild(new Text(theme.fg("accent", theme.bold("Pick an Option")), 1, 0));
435
339
 
436
- // SelectList with theme
437
340
  const selectList = new SelectList(items, Math.min(items.length, 10), {
438
341
  selectedPrefix: (t) => theme.fg("accent", t),
439
342
  selectedText: (t) => theme.fg("accent", t),
@@ -445,10 +348,7 @@ atomic.registerCommand("pick", {
445
348
  selectList.onCancel = () => done(null);
446
349
  container.addChild(selectList);
447
350
 
448
- // Help text
449
351
  container.addChild(new Text(theme.fg("dim", "↑↓ Navigate • Enter Select • Escape Cancel"), 1, 0));
450
-
451
- // Bottom border
452
352
  container.addChild(new DynamicBorder((s: string) => theme.fg("accent", s)));
453
353
 
454
354
  return {
@@ -462,18 +362,16 @@ atomic.registerCommand("pick", {
462
362
  };
463
363
  });
464
364
 
465
- if (result) {
466
- ctx.ui.notify(`Selected: ${result}`, "info");
467
- }
365
+ if (result) ctx.ui.notify(`Selected: ${result}`, "info");
468
366
  },
469
367
  });
470
368
  ```
471
369
 
472
370
  **Examples:** [preset.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/preset.ts), [tools.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/tools.ts)
473
371
 
474
- ### Pattern 2: Async operation with cancel (`BorderedLoader`)
372
+ ### Cancellable loader (`BorderedLoader`)
475
373
 
476
- For operations that take time and should be cancellable. `BorderedLoader` shows a spinner and handles escape to cancel.
374
+ Use `BorderedLoader` for async operations that users should be able to cancel with `Escape`:
477
375
 
478
376
  ```typescript
479
377
  import { BorderedLoader } from "@bastani/atomic";
@@ -484,7 +382,6 @@ atomic.registerCommand("fetch", {
484
382
  const loader = new BorderedLoader(tui, theme, "Fetching data...");
485
383
  loader.onAbort = () => done(null);
486
384
 
487
- // Do async work
488
385
  fetchData(loader.signal)
489
386
  .then((data) => done(data))
490
387
  .catch(() => done(null));
@@ -503,9 +400,9 @@ atomic.registerCommand("fetch", {
503
400
 
504
401
  **Examples:** [qna.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/qna.ts), [handoff.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/handoff.ts)
505
402
 
506
- ### Pattern 3: Settings and toggles (`SettingsList`)
403
+ ### Settings toggles (`SettingsList`)
507
404
 
508
- For toggling multiple settings. Use `SettingsList` from `@bastani/atomic-tui` with `getSettingsListTheme()`.
405
+ Use `SettingsList` from `@bastani/atomic-tui` with `getSettingsListTheme()` from `@bastani/atomic`:
509
406
 
510
407
  ```typescript
511
408
  import { getSettingsListTheme } from "@bastani/atomic";
@@ -527,11 +424,10 @@ atomic.registerCommand("settings", {
527
424
  Math.min(items.length + 2, 15),
528
425
  getSettingsListTheme(),
529
426
  (id, newValue) => {
530
- // Handle value change
531
427
  ctx.ui.notify(`${id} = ${newValue}`, "info");
532
428
  },
533
- () => done(undefined), // On close
534
- { enableSearch: true }, // Optional: enable fuzzy search by label
429
+ () => done(undefined),
430
+ { enableSearch: true },
535
431
  );
536
432
  container.addChild(settingsList);
537
433
 
@@ -550,23 +446,20 @@ atomic.registerCommand("settings", {
550
446
 
551
447
  **Examples:** [tools.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/tools.ts)
552
448
 
553
- ### Pattern 4: Persistent status indicator
449
+ ### Status indicator
554
450
 
555
- Show status in the footer that persists across renders. Good for mode indicators.
451
+ Display persistent mode indicators in the footer:
556
452
 
557
453
  ```typescript
558
- // Set status (shown in footer)
559
454
  ctx.ui.setStatus("my-ext", ctx.ui.theme.fg("accent", "● active"));
560
-
561
- // Clear status
562
- ctx.ui.setStatus("my-ext", undefined);
455
+ ctx.ui.setStatus("my-ext", undefined); // clear
563
456
  ```
564
457
 
565
458
  **Examples:** [status-line.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/status-line.ts), [plan-mode/index.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/plan-mode/index.ts), [preset.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/preset.ts)
566
459
 
567
- ### Pattern 4b: Working indicator customization
460
+ ### Working indicator {#pattern-4b-working-indicator-customization}
568
461
 
569
- Customize the inline Working indicator shown from accepted interactive prompt submission through the active agent turn.
462
+ Customize the inline Working indicator shown from accepted prompt submission through response streaming:
570
463
 
571
464
  ```typescript
572
465
  // Static indicator
@@ -586,23 +479,19 @@ ctx.ui.setWorkingIndicator({
586
479
  // Hide the indicator entirely
587
480
  ctx.ui.setWorkingIndicator({ frames: [] });
588
481
 
589
- // Restore Atomic's default one-cell identity pulse
482
+ // Restore Atomic's default one-cell ∀ pulse
590
483
  ctx.ui.setWorkingIndicator();
591
484
  ```
592
485
 
593
- This affects the normal Working indicator from accepted prompt submission through response streaming. It appears in a standalone status row by default; custom editors may place it in their top border. Newlines and terminal control characters in extension-supplied messages or frames remain stored verbatim, and the standalone row preserves their multi-line rendering.
594
-
595
- Working appears during prompt startup and response streaming, then disappears on completion, failure, or a no-turn result. Manual retry clears stale status; automatic retry and fallback messages take precedence.
596
-
597
- The default is a one-cell `∀` pulse beside a message selected once per turn. Theme `workingIndicator` tones customize its colors. `NO_COLOR` disables foreground and background colors and text styles (bold, italic, dim, underline, inverse, and strikethrough), rendering the indicator unstyled. `ATOMIC_REDUCED_MOTION=1` makes it static. Custom frames and intervals render unchanged.
486
+ By default, Atomic shows a one-cell `∀` pulse beside a turn status message in a standalone row (custom editors can opt in to embedding it in their top border with `embedWorkingStatus: true`). `NO_COLOR` disables colors and text styles, and `ATOMIC_REDUCED_MOTION=1` freezes the built-in pulse (custom frames and intervals render verbatim).
598
487
 
599
- Compaction and retry loaders use their own factual text and the built-in indicator, not extension frames. Successful mid-turn compaction restores Working without another user submission. Cancelled or failed compaction stops activity; errors appear when supplied by the compaction event.
488
+ Working appears during prompt startup and response streaming and disappears on completion, failure, or a no-turn result. Automatic retry, fallback, and compaction loaders use their own built-in indicators and take precedence; successful mid-turn compaction restores Working automatically.
600
489
 
601
490
  **Examples:** [working-indicator.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/working-indicator.ts)
602
491
 
603
- ### Pattern 5: Widgets above or below the editor
492
+ ### Editor widgets
604
493
 
605
- Show persistent content above or below the input editor. Good for todo lists, progress.
494
+ Show persistent content above or below the input editor (such as todo lists or progress panels):
606
495
 
607
496
  ```typescript
608
497
  // Simple string array (above editor by default)
@@ -611,106 +500,77 @@ ctx.ui.setWidget("my-widget", ["Line 1", "Line 2"]);
611
500
  // Render below the editor
612
501
  ctx.ui.setWidget("my-widget", ["Line 1", "Line 2"], { placement: "belowEditor" });
613
502
 
614
- // Or with theme
503
+ // Component factory with theme
615
504
  ctx.ui.setWidget("my-widget", (_tui, theme) => {
616
- const lines = items.map((item, i) =>
505
+ const lines = items.map((item) =>
617
506
  item.done
618
507
  ? theme.fg("success", "✓ ") + theme.fg("muted", item.text)
619
508
  : theme.fg("dim", "○ ") + item.text
620
509
  );
621
- return {
622
- render: () => lines,
623
- invalidate: () => {},
624
- };
510
+ return { render: () => lines, invalidate: () => {} };
625
511
  });
626
512
 
627
513
  // Clear
628
514
  ctx.ui.setWidget("my-widget", undefined);
629
515
  ```
630
516
 
631
- Hosts may clear extension widgets during a UI reset, and `ctx.ui.setWidget(key, undefined)` is the same kind of host removal. A reactive extension that needs to keep a long-lived widget registration can observe `ctx.ui.onWidgetRelease(key, listener)` when available.
632
- The listener runs after the host removes that key, so the extension can reset local mount state and re-register on its next refresh. Replacing a widget with another factory is not a release. Ordinary content changes should continue to update the existing component with `requestRender()` rather than repeatedly calling `setWidget()`.
517
+ To react when the host clears a widget during a UI reset, subscribe with `ctx.ui.onWidgetRelease(key, listener)` when available (replacing a widget with another factory does not trigger release). For ordinary updates, mutate your component state and call `requestRender()` rather than re-registering `setWidget()`.
633
518
 
634
519
  #### Scrollable widgets
635
520
 
636
- Opt in with `scroll: { maxHeight: 6 }` to give a widget its own fullscreen viewport. The host may allocate fewer rows when the editor or other widgets need space. Render the full content, not a pre-clipped slice. Wheel input over the widget scrolls only that widget, including at either end. A one-column scrollbar appears only while content overflows. Scrolling does not take editor focus or register keyboard shortcuts.
637
-
638
- For a cap that follows terminal resizing, use `scroll: { maxHeight: 10, maxHeightFraction: 1 / 3 }`. The fraction applies to live terminal rows, rounded down with a one-row minimum, then capped at `maxHeight`. Actual allocation may still be zero when other dock content uses all available rows. Omitting the fraction keeps the fixed cap.
521
+ Pass `scroll: { maxHeight: 6 }` (or `{ maxHeight: 10, maxHeightFraction: 1 / 3 }` to scale with live terminal rows) to give a widget its own fullscreen viewport with mouse-wheel scrolling and a one-column overflow scrollbar. Render the full content rather than a pre-clipped slice:
639
522
 
640
523
  ```typescript
641
524
  import type { ScrollableWidgetComponent, WidgetScrollRequest } from "@bastani/atomic";
642
525
  import { truncateToWidth } from "@bastani/atomic-tui";
643
526
 
644
527
  let position: WidgetScrollRequest = { version: 0, scrollTop: 0 };
645
- let currentTop = 0;
646
- ctx.ui.setWidget("scrolling-items", () => ({
647
- render: (width) => items.map((item) => truncateToWidth(item.label, width)),
648
- invalidate() {},
649
- getScrollRequest: () => position,
650
- onScroll: (state) => {
651
- // state reports scrollTop, viewportHeight and contentHeight in rendered rows.
652
- currentTop = state.scrollTop;
653
- },
654
- } satisfies ScrollableWidgetComponent), {
655
- placement: "belowEditor",
656
- scroll: { maxHeight: 6 },
657
- });
528
+ ctx.ui.setWidget(
529
+ "scrolling-items",
530
+ () =>
531
+ ({
532
+ render: (width) => items.map((item) => truncateToWidth(item.label, width)),
533
+ invalidate() {},
534
+ getScrollRequest: () => position,
535
+ onScroll: (_state) => {
536
+ // state reports { scrollTop, viewportHeight, contentHeight } in rendered rows
537
+ },
538
+ }) satisfies ScrollableWidgetComponent,
539
+ { placement: "belowEditor", scroll: { maxHeight: 6 } },
540
+ );
658
541
 
659
- // To intentionally reposition, increase version, then request a render.
542
+ // Increment version only when intentionally repositioning, then request a render
660
543
  position = { version: position.version + 1, scrollTop: 10 };
661
544
  ctx.ui.requestRender();
662
545
  ```
663
546
 
664
- `getScrollRequest` and `onScroll` are optional. Keep the request version unchanged during ordinary updates so they do not reset wheel scrolling. New positions are clamped to the actual viewport. Requests with older versions are ignored. Unmounting starts a fresh viewport. Keep item identity and insertion/deletion anchors in your extension; positions here count rendered rows.
665
-
666
- `installReactiveWidget` accepts the same `scroll`, `getScrollRequest`, and `onScroll` options. Existing widgets remain unscrolled unless they opt in. Native wheel input requires fullscreen mode and a terminal that forwards mouse events; the main-screen fallback (such as `TERM=dumb` or non-TTY sessions) does not provide a native viewport. No Option/Alt key setup is required for wheel input.
547
+ `getScrollRequest` and `onScroll` are optional, and `installReactiveWidget` accepts the same `scroll` options. Keep `version` unchanged during ordinary content updates so user wheel scrolling is preserved. Native wheel scrolling requires fullscreen mode and a mouse-capable terminal.
667
548
 
668
549
  **Examples:** [plan-mode/index.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/plan-mode/index.ts)
669
550
 
670
- ### Pattern 6: Custom footer
551
+ ### Custom footer
671
552
 
672
- Replace the footer. `footerData` exposes data not otherwise accessible to extensions.
553
+ Replace the footer and read live Git branch and extension statuses from `footerData`:
673
554
 
674
555
  ```typescript
675
- ctx.ui.setFooter((tui, theme, footerData) => ({
556
+ ctx.ui.setFooter((tui, _theme, footerData) => ({
676
557
  invalidate() {},
677
- render(width: number): string[] {
678
- // footerData.getGitBranch(): string | null
679
- // footerData.getExtensionStatuses(): ReadonlyMap<string, string>
558
+ render(_width: number): string[] {
680
559
  return [`${ctx.model?.id} (${footerData.getGitBranch() || "no git"})`];
681
560
  },
682
- dispose: footerData.onBranchChange(() => tui.requestRender()), // reactive
561
+ dispose: footerData.onBranchChange(() => tui.requestRender()),
683
562
  }));
684
563
 
685
564
  ctx.ui.setFooter(undefined); // restore default
686
565
  ```
687
566
 
688
- `ctx.ui.getFooterDataProvider()` exposes the same read-only status and Git-branch provider to embedded extension UIs in Atomic's terminal UI.
689
-
690
- For a viewer with a different cwd, subscribe with that cwd to retain its branch watcher, and read the live branch during each render using the same raw cwd string:
691
-
692
- ```typescript
693
- // viewerCwd is fixed for this viewer's lifetime.
694
- ctx.ui.setFooter((tui, theme, footerData) => ({
695
- invalidate() {},
696
- render(width: number): string[] {
697
- return [`${ctx.model?.id} (${footerData.getGitBranch(viewerCwd) || "no git"})`];
698
- },
699
- dispose: footerData.onBranchChange(() => tui.requestRender(), viewerCwd),
700
- }));
701
- ```
702
-
703
- The returned unsubscribe function belongs to the viewer: call it on disposal or before replacing the viewer's cwd, then subscribe for the new cwd. Embedded UIs using `ctx.ui.getFooterDataProvider()` must likewise release their own subscription. Active viewers using the same raw cwd share the cached provider and watcher; the last unsubscribe releases that alternate-cwd resource. Do not call the parent provider's `dispose()` from an individual viewer.
704
-
705
- An unleased `getGitBranch(viewerCwd)` lookup is transient: it does not retain an alternate-cwd cache or watcher, so an unscoped callback alone does not enable branch updates for that directory. Scoped subscriptions retain resources, but notifications still reach the same branch-change listeners; they are not filtered by cwd. Omitting the cwd argument retains the provider's own cwd behavior shown in the default recipe above.
706
-
707
- Token stats available via `ctx.sessionManager.getBranch()` and `ctx.model`.
567
+ `ctx.ui.getFooterDataProvider()` exposes the same read-only provider to embedded extension UIs. For a viewer showing a different working directory (`viewerCwd`), pass `viewerCwd` to both `footerData.onBranchChange(listener, viewerCwd)` and `footerData.getGitBranch(viewerCwd)`, and call the returned unsubscribe function on disposal (never call the parent provider's `dispose()`). An unsubscribed `getGitBranch(viewerCwd)` lookup is transient and does not retain a branch watcher.
708
568
 
709
569
  **Examples:** [custom-footer.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/custom-footer.ts)
710
570
 
711
- ### Pattern 7: Custom editor (vim mode)
571
+ ### Custom editor (vim mode)
712
572
 
713
- Replace the main input editor with a custom implementation. Useful for modal editing (vim), different keybindings (emacs), or specialized input handling.
573
+ Extend `CustomEditor` (not base `Editor`) to customize editing while keeping Atomic's app keybindings (`Escape` to abort, `Ctrl+D` to exit, model switching, and autocomplete):
714
574
 
715
575
  ```typescript
716
576
  import { CustomEditor, type ExtensionAPI } from "@bastani/atomic";
@@ -722,41 +582,32 @@ class VimEditor extends CustomEditor {
722
582
  private mode: Mode = "insert";
723
583
 
724
584
  handleInput(data: string): boolean {
725
- // Escape: switch to normal mode, or pass through for app handling
726
585
  if (matchesKey(data, "escape")) {
727
586
  if (this.mode === "insert") {
728
587
  this.mode = "normal";
729
588
  return true;
730
589
  }
731
- // In normal mode, escape aborts agent (handled by CustomEditor)
732
590
  return super.handleInput(data);
733
591
  }
734
592
 
735
- // Insert mode: pass everything to CustomEditor
736
- if (this.mode === "insert") {
737
- return super.handleInput(data);
738
- }
593
+ if (this.mode === "insert") return super.handleInput(data);
739
594
 
740
- // Normal mode: vim-style navigation
741
595
  switch (data) {
742
596
  case "i": this.mode = "insert"; return true;
743
- case "h": return super.handleInput("\x1b[D"); // Left
744
- case "j": return super.handleInput("\x1b[B"); // Down
745
- case "k": return super.handleInput("\x1b[A"); // Up
746
- case "l": return super.handleInput("\x1b[C"); // Right
597
+ case "h": return super.handleInput("\x1b[D");
598
+ case "j": return super.handleInput("\x1b[B");
599
+ case "k": return super.handleInput("\x1b[A");
600
+ case "l": return super.handleInput("\x1b[C");
747
601
  }
748
- // Pass unhandled keys to super (ctrl+c, etc.), but filter printable chars
749
602
  if (data.length === 1 && data.charCodeAt(0) >= 32) return false;
750
603
  return super.handleInput(data);
751
604
  }
752
605
 
753
606
  render(width: number): string[] {
754
607
  const lines = super.render(width);
755
- // Add mode indicator to bottom border (use truncateToWidth for ANSI-safe truncation)
756
608
  if (lines.length > 0) {
757
609
  const label = this.mode === "normal" ? " NORMAL " : " INSERT ";
758
610
  const lastLine = lines[lines.length - 1]!;
759
- // Pass "" as ellipsis to avoid adding "..." when truncating
760
611
  lines[lines.length - 1] = truncateToWidth(lastLine, width - label.length, "") + label;
761
612
  }
762
613
  return lines;
@@ -765,28 +616,33 @@ class VimEditor extends CustomEditor {
765
616
 
766
617
  export default function (atomic: ExtensionAPI) {
767
618
  atomic.on("session_start", (_event, ctx) => {
768
- // Factory receives the TUI, theme, and keybindings from the app
769
- ctx.ui.setEditorComponent((tui, theme, keybindings) =>
770
- new VimEditor(tui, theme, keybindings)
771
- );
619
+ ctx.ui.setEditorComponent((tui, theme, keybindings) => new VimEditor(tui, theme, keybindings));
772
620
  });
773
621
  }
774
622
  ```
775
623
 
776
- **Key points:**
624
+ Pass `undefined` to `ctx.ui.setEditorComponent(undefined)` to restore the default editor. Custom editors exposing `setAutocompleteMaxVisible()` inherit the active `autocompleteMaxVisible` setting.
625
+
626
+ `new CustomEditor(tui, theme, keybindings, options?)` accepts `CustomEditorOptions`:
777
627
 
778
- - **Extend `CustomEditor`** (not base `Editor`) to get app keybindings (escape to abort, ctrl+d to exit, model switching, etc.)
779
- - **Call `super.handleInput(data)`** for keys you don't handle
780
- - **`CustomEditorOptions`**: The optional fourth argument to `new CustomEditor(tui, theme, keybindings, options?)` accepts `{ promptPrefix?, placeholder?, embedWorkingStatus?, topRuleLabel?, paddingX?, autocompleteMaxVisible? }`. Editors keep the standalone working row by default; pass `{ embedWorkingStatus: true }` to render the working spinner in the editor's top border.
781
- - **Factory pattern**: `setEditorComponent` receives a factory function that gets `tui`, `theme`, and `keybindings`.
782
- - **Autocomplete limit**: Custom editors installed through `setEditorComponent()` that expose `setAutocompleteMaxVisible()` inherit the active `autocompleteMaxVisible` setting.
783
- - **Pass `undefined`** to restore the default editor: `ctx.ui.setEditorComponent(undefined)`.
628
+ | Option | Type | Purpose |
629
+ | --- | --- | --- |
630
+ | `promptPrefix` | `string` | Custom prompt prefix rendered before input text. |
631
+ | `placeholder` | `string \| (() => string)` | Static or dynamic placeholder shown when the editor is empty. |
632
+ | `embedWorkingStatus` | `boolean` | When `true`, renders the streaming working indicator inside the editor's top rule instead of a standalone row. |
633
+ | `topRuleLabel` | `() => string \| undefined` | Optional dynamic label drawn on the editor's top rule. |
634
+ | `paddingX` | `number` | Horizontal padding (inherited from `EditorOptions`). |
635
+ | `autocompleteMaxVisible` | `number` | Maximum visible autocomplete rows (inherited from `EditorOptions`). |
636
+
637
+ <Note>
638
+ `setEditorComponent`, `setFooter`, `setHeader`, `onTerminalInput`, and `addAutocompleteProvider` require synchronous terminal callbacks and run only in single-process TUI hosts (they warn and do not run in default isolated interactive mode). See [Extension UI](/extensions/ui).
639
+ </Note>
784
640
 
785
641
  **Examples:** [modal-editor.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/modal-editor.ts)
786
642
 
787
- ### Pattern 7b: Attached composer
643
+ ### Attached composer
788
644
 
789
- When an extension or custom SDK host embeds a secondary chat editor, `applyAttachedComposer(style, label, placeholder, lines)` distinguishes it from the main prompt: accent-coloured rules above and below the prompt, the top rule ending in a bold `label`, and a dim `placeholder` after the cursor while nothing is typed.
645
+ When an extension or custom SDK host embeds a secondary chat editor, `applyAttachedComposer(style, label, placeholder, lines)` styles its rules with accent color, adds a bold `label` to the top rule, and displays a dim `placeholder` while empty:
790
646
 
791
647
  ```typescript
792
648
  import { applyAttachedComposer, CustomEditor, type ExtensionAPI, type Theme } from "@bastani/atomic";
@@ -821,30 +677,29 @@ export default function (atomic: ExtensionAPI) {
821
677
  }
822
678
  ```
823
679
 
824
- It replaces only a plain editor rule or one that reads `↑ N more` or `↓ N more`: a first or last line that is not a rule, such as one your editor draws itself, is left unchanged. Composer rules draw with the light box-drawing glyph (`─`). A long label truncates with `…` to fit, and below `INPUT_LABEL_MIN_COLUMNS` (40) columns, the light `─` rules render without the label. Pass `undefined` for `label` or `placeholder` to omit either.
825
-
826
- ## Key rules
827
-
828
- 1. **Always use theme from callback.** Do not import theme directly; use `theme` passed to `ctx.ui.custom((tui, theme, keybindings, done) => ...)`.
829
-
830
- 2. **Always type `DynamicBorder` color parameters.** Write `(s: string) => theme.fg("accent", s)`, not `(s) => theme.fg("accent", s)`.
680
+ `applyAttachedComposer()` replaces plain `─` rules and editor overflow rules (`↑ N more` / `↓ N more`). For the bottom border, it scans upward from the end of `lines` to find and recolor the last rule line even when non-rule lines (such as a hint or autocomplete menu) follow it. It inserts `placeholder` only when the editor has a single empty prompt row (the bottom rule is at line index `2` and line `1` is bare `❯`). Long labels truncate with `…`, and below `INPUT_LABEL_MIN_COLUMNS` (`40`) columns the rules render without the label. Pass `undefined` for `label` or `placeholder` to omit either.
831
681
 
832
- 3. **Call `tui.requestRender()` after state changes.** In `handleInput`, call `tui.requestRender()` after updating state.
682
+ For `buildInputLabel()` and `applyInputLabelToEditorTopRule()`, see [Input label helpers](/tui/reference#input-label-helpers).
833
683
 
834
- 4. **Return the component object.** Custom components implement `{ render, invalidate, handleInput?, dispose? }`.
684
+ ## Key rules
835
685
 
836
- 5. **Use existing components.** `Selector`, `SelectList`, `SettingsList`, and `BorderedLoader` cover most interactive UI cases.
686
+ <Tip>
687
+ - **Always use `theme` from callbacks.** Do not import a theme singleton directly; use the `theme` passed to `ctx.ui.custom()`, `setWidget()`, `renderCall()`, or `renderResult()`.
688
+ - **Type `DynamicBorder` parameters explicitly.** Write `(s: string) => theme.fg("accent", s)`.
689
+ - **Call `tui.requestRender()` after state changes** inside `handleInput()`.
690
+ - **Prefer built-in components.** `Selector`, `SelectList`, `SettingsList`, and `BorderedLoader` cover most interactive UI cases.
691
+ </Tip>
837
692
 
838
693
  ## Examples
839
694
 
840
- - **Selection UI**: [examples/extensions/preset.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/preset.ts): `SelectList` with `DynamicBorder` framing.
841
- - **Async with cancel**: [examples/extensions/qna.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/qna.ts): `BorderedLoader` for LLM calls.
842
- - **Settings toggles**: [examples/extensions/tools.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/tools.ts): `SettingsList` for tool enable/disable.
843
- - **Status indicators**: [examples/extensions/plan-mode/index.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/plan-mode/index.ts): `setStatus` and `setWidget`.
844
- - **Working indicator**: [examples/extensions/working-indicator.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/working-indicator.ts): `setWorkingIndicator`.
845
- - **Custom footer**: [examples/extensions/custom-footer.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/custom-footer.ts): `setFooter` with stats.
846
- - **Custom editor**: [examples/extensions/modal-editor.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/modal-editor.ts): Vim-like modal editing.
847
- - **Snake game**: [examples/extensions/snake.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/snake.ts): game with keyboard input and game loop.
848
- - **Custom tool rendering**: [examples/extensions/todo.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/todo.ts): `renderCall` and `renderResult`.
849
-
850
- For component, focusable, keyboard input, invalidation, debug logging, and host-native UI contracts, continue to [TUI API reference](/tui/reference).
695
+ - **Selection UI:** [preset.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/preset.ts) (`SelectList` with `DynamicBorder`)
696
+ - **Async with cancel:** [qna.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/qna.ts) (`BorderedLoader`)
697
+ - **Settings toggles:** [tools.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/tools.ts) (`SettingsList`)
698
+ - **Status and widgets:** [plan-mode/index.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/plan-mode/index.ts) (`setStatus`, `setWidget`)
699
+ - **Working indicator:** [working-indicator.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/working-indicator.ts) (`setWorkingIndicator`)
700
+ - **Custom footer:** [custom-footer.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/custom-footer.ts) (`setFooter`)
701
+ - **Custom editor:** [modal-editor.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/modal-editor.ts) (Vim-like modal editing)
702
+ - **Interactive game loop:** [snake.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/snake.ts) (keyboard input and loop)
703
+ - **Custom tool rendering:** [todo.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/todo.ts) (`renderCall` and `renderResult`)
704
+
705
+ Continue to [TUI API reference](/tui/reference) for `ToolBlock`, `ExtensionCustomComponent`, theme invalidation, debug logging, and host-native UI contracts.