shortcutxl 0.2.0

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 (423) hide show
  1. package/README.md +59 -0
  2. package/agent-docs/README.md +397 -0
  3. package/agent-docs/docs/compaction.md +390 -0
  4. package/agent-docs/docs/custom-provider.md +580 -0
  5. package/agent-docs/docs/development.md +69 -0
  6. package/agent-docs/docs/extensions.md +1971 -0
  7. package/agent-docs/docs/json.md +79 -0
  8. package/agent-docs/docs/keybindings.md +174 -0
  9. package/agent-docs/docs/models.md +293 -0
  10. package/agent-docs/docs/packages.md +209 -0
  11. package/agent-docs/docs/prompt-templates.md +67 -0
  12. package/agent-docs/docs/providers.md +186 -0
  13. package/agent-docs/docs/rpc.md +1317 -0
  14. package/agent-docs/docs/sdk.md +962 -0
  15. package/agent-docs/docs/session.md +412 -0
  16. package/agent-docs/docs/settings.md +223 -0
  17. package/agent-docs/docs/shell-aliases.md +13 -0
  18. package/agent-docs/docs/skills.md +231 -0
  19. package/agent-docs/docs/terminal-setup.md +70 -0
  20. package/agent-docs/docs/termux.md +127 -0
  21. package/agent-docs/docs/themes.md +295 -0
  22. package/agent-docs/docs/tree.md +219 -0
  23. package/agent-docs/docs/tui.md +887 -0
  24. package/agent-docs/docs/windows.md +17 -0
  25. package/agent-docs/examples/README.md +25 -0
  26. package/agent-docs/examples/extensions/README.md +205 -0
  27. package/agent-docs/examples/extensions/antigravity-image-gen.ts +447 -0
  28. package/agent-docs/examples/extensions/auto-commit-on-exit.ts +49 -0
  29. package/agent-docs/examples/extensions/bash-spawn-hook.ts +30 -0
  30. package/agent-docs/examples/extensions/bookmark.ts +50 -0
  31. package/agent-docs/examples/extensions/built-in-tool-renderer.ts +256 -0
  32. package/agent-docs/examples/extensions/claude-rules.ts +86 -0
  33. package/agent-docs/examples/extensions/commands.ts +75 -0
  34. package/agent-docs/examples/extensions/confirm-destructive.ts +59 -0
  35. package/agent-docs/examples/extensions/custom-compaction.ts +126 -0
  36. package/agent-docs/examples/extensions/custom-footer.ts +63 -0
  37. package/agent-docs/examples/extensions/custom-header.ts +73 -0
  38. package/agent-docs/examples/extensions/custom-provider-anthropic/index.ts +660 -0
  39. package/agent-docs/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
  40. package/agent-docs/examples/extensions/custom-provider-anthropic/package.json +19 -0
  41. package/agent-docs/examples/extensions/custom-provider-gitlab-duo/index.ts +362 -0
  42. package/agent-docs/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
  43. package/agent-docs/examples/extensions/custom-provider-gitlab-duo/test.ts +88 -0
  44. package/agent-docs/examples/extensions/custom-provider-qwen-cli/index.ts +349 -0
  45. package/agent-docs/examples/extensions/custom-provider-qwen-cli/package.json +16 -0
  46. package/agent-docs/examples/extensions/dirty-repo-guard.ts +56 -0
  47. package/agent-docs/examples/extensions/doom-overlay/README.md +46 -0
  48. package/agent-docs/examples/extensions/doom-overlay/doom/build.sh +152 -0
  49. package/agent-docs/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
  50. package/agent-docs/examples/extensions/doom-overlay/doom-component.ts +133 -0
  51. package/agent-docs/examples/extensions/doom-overlay/doom-engine.ts +186 -0
  52. package/agent-docs/examples/extensions/doom-overlay/doom-keys.ts +108 -0
  53. package/agent-docs/examples/extensions/doom-overlay/index.ts +74 -0
  54. package/agent-docs/examples/extensions/doom-overlay/wad-finder.ts +51 -0
  55. package/agent-docs/examples/extensions/dynamic-resources/SKILL.md +8 -0
  56. package/agent-docs/examples/extensions/dynamic-resources/dynamic.json +79 -0
  57. package/agent-docs/examples/extensions/dynamic-resources/dynamic.md +5 -0
  58. package/agent-docs/examples/extensions/dynamic-resources/index.ts +15 -0
  59. package/agent-docs/examples/extensions/dynamic-tools.ts +77 -0
  60. package/agent-docs/examples/extensions/event-bus.ts +43 -0
  61. package/agent-docs/examples/extensions/file-trigger.ts +41 -0
  62. package/agent-docs/examples/extensions/git-checkpoint.ts +53 -0
  63. package/agent-docs/examples/extensions/handoff.ts +155 -0
  64. package/agent-docs/examples/extensions/hello.ts +25 -0
  65. package/agent-docs/examples/extensions/inline-bash.ts +94 -0
  66. package/agent-docs/examples/extensions/input-transform.ts +43 -0
  67. package/agent-docs/examples/extensions/interactive-shell.ts +209 -0
  68. package/agent-docs/examples/extensions/mac-system-theme.ts +47 -0
  69. package/agent-docs/examples/extensions/message-renderer.ts +59 -0
  70. package/agent-docs/examples/extensions/minimal-mode.ts +430 -0
  71. package/agent-docs/examples/extensions/modal-editor.ts +90 -0
  72. package/agent-docs/examples/extensions/model-status.ts +31 -0
  73. package/agent-docs/examples/extensions/notify.ts +55 -0
  74. package/agent-docs/examples/extensions/overlay-qa-tests.ts +936 -0
  75. package/agent-docs/examples/extensions/overlay-test.ts +159 -0
  76. package/agent-docs/examples/extensions/permission-gate.ts +37 -0
  77. package/agent-docs/examples/extensions/pirate.ts +47 -0
  78. package/agent-docs/examples/extensions/plan-mode/README.md +65 -0
  79. package/agent-docs/examples/extensions/plan-mode/index.ts +363 -0
  80. package/agent-docs/examples/extensions/plan-mode/utils.ts +173 -0
  81. package/agent-docs/examples/extensions/preset.ts +418 -0
  82. package/agent-docs/examples/extensions/protected-paths.ts +30 -0
  83. package/agent-docs/examples/extensions/qna.ts +122 -0
  84. package/agent-docs/examples/extensions/question.ts +278 -0
  85. package/agent-docs/examples/extensions/questionnaire.ts +440 -0
  86. package/agent-docs/examples/extensions/rainbow-editor.ts +90 -0
  87. package/agent-docs/examples/extensions/reload-runtime.ts +37 -0
  88. package/agent-docs/examples/extensions/rpc-demo.ts +124 -0
  89. package/agent-docs/examples/extensions/sandbox/index.ts +324 -0
  90. package/agent-docs/examples/extensions/sandbox/package-lock.json +92 -0
  91. package/agent-docs/examples/extensions/sandbox/package.json +19 -0
  92. package/agent-docs/examples/extensions/send-user-message.ts +97 -0
  93. package/agent-docs/examples/extensions/session-name.ts +27 -0
  94. package/agent-docs/examples/extensions/shutdown-command.ts +69 -0
  95. package/agent-docs/examples/extensions/snake.ts +343 -0
  96. package/agent-docs/examples/extensions/space-invaders.ts +566 -0
  97. package/agent-docs/examples/extensions/ssh.ts +233 -0
  98. package/agent-docs/examples/extensions/status-line.ts +40 -0
  99. package/agent-docs/examples/extensions/subagent/README.md +172 -0
  100. package/agent-docs/examples/extensions/subagent/agents/planner.md +37 -0
  101. package/agent-docs/examples/extensions/subagent/agents/reviewer.md +35 -0
  102. package/agent-docs/examples/extensions/subagent/agents/scout.md +50 -0
  103. package/agent-docs/examples/extensions/subagent/agents/worker.md +24 -0
  104. package/agent-docs/examples/extensions/subagent/agents.ts +130 -0
  105. package/agent-docs/examples/extensions/subagent/index.ts +1068 -0
  106. package/agent-docs/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
  107. package/agent-docs/examples/extensions/subagent/prompts/implement.md +10 -0
  108. package/agent-docs/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
  109. package/agent-docs/examples/extensions/summarize.ts +206 -0
  110. package/agent-docs/examples/extensions/system-prompt-header.ts +17 -0
  111. package/agent-docs/examples/extensions/timed-confirm.ts +72 -0
  112. package/agent-docs/examples/extensions/titlebar-spinner.ts +58 -0
  113. package/agent-docs/examples/extensions/todo.ts +314 -0
  114. package/agent-docs/examples/extensions/tool-override.ts +146 -0
  115. package/agent-docs/examples/extensions/tools.ts +145 -0
  116. package/agent-docs/examples/extensions/trigger-compact.ts +40 -0
  117. package/agent-docs/examples/extensions/truncated-tool.ts +194 -0
  118. package/agent-docs/examples/extensions/widget-placement.ts +17 -0
  119. package/agent-docs/examples/extensions/with-deps/index.ts +37 -0
  120. package/agent-docs/examples/extensions/with-deps/package-lock.json +31 -0
  121. package/agent-docs/examples/extensions/with-deps/package.json +22 -0
  122. package/agent-docs/examples/rpc-extension-ui.ts +654 -0
  123. package/agent-docs/examples/sdk/01-minimal.ts +22 -0
  124. package/agent-docs/examples/sdk/02-custom-model.ts +48 -0
  125. package/agent-docs/examples/sdk/03-custom-prompt.ts +55 -0
  126. package/agent-docs/examples/sdk/04-skills.ts +53 -0
  127. package/agent-docs/examples/sdk/05-tools.ts +56 -0
  128. package/agent-docs/examples/sdk/06-extensions.ts +88 -0
  129. package/agent-docs/examples/sdk/07-context-files.ts +40 -0
  130. package/agent-docs/examples/sdk/08-prompt-templates.ts +47 -0
  131. package/agent-docs/examples/sdk/09-api-keys-and-oauth.ts +48 -0
  132. package/agent-docs/examples/sdk/10-settings.ts +54 -0
  133. package/agent-docs/examples/sdk/11-sessions.ts +48 -0
  134. package/agent-docs/examples/sdk/12-full-control.ts +82 -0
  135. package/agent-docs/examples/sdk/README.md +144 -0
  136. package/agent-docs/xll-skill.md +61 -0
  137. package/agent-docs/xll-spec.md +110 -0
  138. package/dist/cli/args.js +290 -0
  139. package/dist/cli/config-selector.js +31 -0
  140. package/dist/cli/file-processor.js +79 -0
  141. package/dist/cli/list-models.js +92 -0
  142. package/dist/cli/package-commands.js +210 -0
  143. package/dist/cli/report-settings-errors.js +11 -0
  144. package/dist/cli/session-picker.js +34 -0
  145. package/dist/cli.js +19 -0
  146. package/dist/config.js +288 -0
  147. package/dist/core/abort.js +15 -0
  148. package/dist/core/agent-loop.js +352 -0
  149. package/dist/core/agent-session.js +2019 -0
  150. package/dist/core/agent.js +410 -0
  151. package/dist/core/auth-storage.js +456 -0
  152. package/dist/core/bash-executor.js +222 -0
  153. package/dist/core/compaction/branch-summarization.js +242 -0
  154. package/dist/core/compaction/compaction.js +610 -0
  155. package/dist/core/compaction/index.js +7 -0
  156. package/dist/core/compaction/utils.js +139 -0
  157. package/dist/core/defaults.js +6 -0
  158. package/dist/core/diagnostics.js +2 -0
  159. package/dist/core/event-bus.js +25 -0
  160. package/dist/core/exec.js +71 -0
  161. package/dist/core/export-html/ansi-to-html.js +256 -0
  162. package/dist/core/export-html/index.js +238 -0
  163. package/dist/core/export-html/session-view-model.js +342 -0
  164. package/dist/core/export-html/template.css +1110 -0
  165. package/dist/core/export-html/template.html +76 -0
  166. package/dist/core/export-html/template.js +1990 -0
  167. package/dist/core/export-html/tool-renderer.js +63 -0
  168. package/dist/core/export-html/vendor/highlight.min.js +7725 -0
  169. package/dist/core/export-html/vendor/marked.min.js +1803 -0
  170. package/dist/core/extensions/index.js +9 -0
  171. package/dist/core/extensions/loader.js +422 -0
  172. package/dist/core/extensions/runner.js +651 -0
  173. package/dist/core/extensions/types.js +35 -0
  174. package/dist/core/extensions/wrapper.js +102 -0
  175. package/dist/core/footer-data-provider.js +162 -0
  176. package/dist/core/index.js +9 -0
  177. package/dist/core/keybindings.js +153 -0
  178. package/dist/core/messages.js +133 -0
  179. package/dist/core/model-registry.js +539 -0
  180. package/dist/core/model-resolver.js +370 -0
  181. package/dist/core/package-manager.js +1485 -0
  182. package/dist/core/prompt-templates.js +253 -0
  183. package/dist/core/resolve-config-value.js +59 -0
  184. package/dist/core/resource-loader.js +700 -0
  185. package/dist/core/sdk.js +197 -0
  186. package/dist/core/session-bash.js +99 -0
  187. package/dist/core/session-compaction.js +165 -0
  188. package/dist/core/session-manager.js +1153 -0
  189. package/dist/core/session-models.js +99 -0
  190. package/dist/core/session-retry.js +155 -0
  191. package/dist/core/settings-manager.js +572 -0
  192. package/dist/core/skills.js +382 -0
  193. package/dist/core/slash-commands.js +31 -0
  194. package/dist/core/system-prompt.js +161 -0
  195. package/dist/core/theme.js +770 -0
  196. package/dist/core/timings.js +26 -0
  197. package/dist/core/tools/bash.js +258 -0
  198. package/dist/core/tools/edit-diff.js +245 -0
  199. package/dist/core/tools/edit.js +148 -0
  200. package/dist/core/tools/find.js +208 -0
  201. package/dist/core/tools/grep.js +246 -0
  202. package/dist/core/tools/index.js +67 -0
  203. package/dist/core/tools/ls.js +123 -0
  204. package/dist/core/tools/path-utils.js +81 -0
  205. package/dist/core/tools/read.js +160 -0
  206. package/dist/core/tools/truncate.js +70 -0
  207. package/dist/core/tools/write.js +82 -0
  208. package/dist/custom/agents/action.js +13 -0
  209. package/dist/custom/agents/document-reader.js +70 -0
  210. package/dist/custom/agents/general.js +26 -0
  211. package/dist/custom/agents/index.js +49 -0
  212. package/dist/custom/agents/installation.js +13 -0
  213. package/dist/custom/agents/types.js +7 -0
  214. package/dist/custom/auth/refresh-timer.js +33 -0
  215. package/dist/custom/auth/shortcut-oauth.js +145 -0
  216. package/dist/custom/constants.js +21 -0
  217. package/dist/custom/context/workbook-summary.js +73 -0
  218. package/dist/custom/credits/shortcut-credits.js +29 -0
  219. package/dist/custom/cron/cron-daemon-entry.js +18 -0
  220. package/dist/custom/cron/daemon-ipc.js +131 -0
  221. package/dist/custom/cron/daemon.js +224 -0
  222. package/dist/custom/cron/jobs.js +226 -0
  223. package/dist/custom/cron/run-log.js +51 -0
  224. package/dist/custom/cron/schedule.js +72 -0
  225. package/dist/custom/cron/status-line.js +98 -0
  226. package/dist/custom/cron/store.js +87 -0
  227. package/dist/custom/cron/types.js +8 -0
  228. package/dist/custom/dev/index.js +59 -0
  229. package/dist/custom/dev/trace-export.js +58 -0
  230. package/dist/custom/ensure-excel.js +63 -0
  231. package/dist/custom/excel-config.js +36 -0
  232. package/dist/custom/preflight.js +422 -0
  233. package/dist/custom/prompts/action.js +100 -0
  234. package/dist/custom/prompts/api.js +66 -0
  235. package/dist/custom/prompts/installation.js +124 -0
  236. package/dist/custom/prompts/shared.js +138 -0
  237. package/dist/custom/providers/llm-usage.js +42 -0
  238. package/dist/custom/providers/message-converter.js +74 -0
  239. package/dist/custom/providers/provider-ids.js +9 -0
  240. package/dist/custom/providers/register-openai-codex-provider.js +27 -0
  241. package/dist/custom/providers/register-shortcut-provider.js +52 -0
  242. package/dist/custom/providers/shortcut-invoke.js +117 -0
  243. package/dist/custom/providers/shortcut-stream.js +252 -0
  244. package/dist/custom/providers/sse-protocol.js +38 -0
  245. package/dist/custom/sync-xll.js +130 -0
  246. package/dist/custom/tools/cron.js +413 -0
  247. package/dist/custom/tools/excel-exec.js +167 -0
  248. package/dist/custom/tools/excel-range.js +50 -0
  249. package/dist/custom/tools/llm-analysis.js +265 -0
  250. package/dist/custom/tools/render-helpers.js +38 -0
  251. package/dist/custom/tools/switch-mode.js +94 -0
  252. package/dist/custom/tools/task/agents.js +6 -0
  253. package/dist/custom/tools/task/index.js +8 -0
  254. package/dist/custom/tools/task/render.js +348 -0
  255. package/dist/custom/tools/task/subprocess.js +320 -0
  256. package/dist/custom/tools/task/task.js +205 -0
  257. package/dist/custom/tools/todo-list.js +195 -0
  258. package/dist/custom/tracing/session-upload.js +93 -0
  259. package/dist/index.js +45 -0
  260. package/dist/main.js +613 -0
  261. package/dist/migrations.js +265 -0
  262. package/dist/modes/index.js +8 -0
  263. package/dist/modes/interactive/components/armin.js +337 -0
  264. package/dist/modes/interactive/components/assistant-message.js +94 -0
  265. package/dist/modes/interactive/components/bash-execution.js +171 -0
  266. package/dist/modes/interactive/components/bordered-loader.js +51 -0
  267. package/dist/modes/interactive/components/branch-summary-message.js +45 -0
  268. package/dist/modes/interactive/components/compaction-summary-message.js +46 -0
  269. package/dist/modes/interactive/components/config-selector.js +488 -0
  270. package/dist/modes/interactive/components/countdown-timer.js +33 -0
  271. package/dist/modes/interactive/components/custom-editor.js +93 -0
  272. package/dist/modes/interactive/components/custom-message.js +81 -0
  273. package/dist/modes/interactive/components/daxnuts.js +140 -0
  274. package/dist/modes/interactive/components/diff.js +133 -0
  275. package/dist/modes/interactive/components/dynamic-border.js +21 -0
  276. package/dist/modes/interactive/components/extension-editor.js +105 -0
  277. package/dist/modes/interactive/components/extension-input.js +61 -0
  278. package/dist/modes/interactive/components/extension-selector.js +78 -0
  279. package/dist/modes/interactive/components/footer.js +309 -0
  280. package/dist/modes/interactive/components/index.js +33 -0
  281. package/dist/modes/interactive/components/keybinding-hints.js +61 -0
  282. package/dist/modes/interactive/components/layout.js +64 -0
  283. package/dist/modes/interactive/components/login-dialog.js +148 -0
  284. package/dist/modes/interactive/components/model-selector.js +237 -0
  285. package/dist/modes/interactive/components/oauth-selector.js +111 -0
  286. package/dist/modes/interactive/components/session-selector-search.js +157 -0
  287. package/dist/modes/interactive/components/session-selector.js +860 -0
  288. package/dist/modes/interactive/components/settings-selector.js +123 -0
  289. package/dist/modes/interactive/components/show-images-selector.js +35 -0
  290. package/dist/modes/interactive/components/skill-invocation-message.js +48 -0
  291. package/dist/modes/interactive/components/theme-selector.js +47 -0
  292. package/dist/modes/interactive/components/thinking-selector.js +47 -0
  293. package/dist/modes/interactive/components/tool-execution.js +789 -0
  294. package/dist/modes/interactive/components/tool-group.js +106 -0
  295. package/dist/modes/interactive/components/tree-selector.js +962 -0
  296. package/dist/modes/interactive/components/user-message-selector.js +115 -0
  297. package/dist/modes/interactive/components/user-message.js +48 -0
  298. package/dist/modes/interactive/components/visual-truncate.js +33 -0
  299. package/dist/modes/interactive/file-attachments.js +135 -0
  300. package/dist/modes/interactive/interactive-mode.js +3775 -0
  301. package/dist/modes/interactive/theme/dark.json +85 -0
  302. package/dist/modes/interactive/theme/light.json +85 -0
  303. package/dist/modes/interactive/theme/theme-schema.json +335 -0
  304. package/dist/modes/interactive/theme/theme.js +177 -0
  305. package/dist/modes/print-mode.js +101 -0
  306. package/dist/modes/rpc/rpc-client.js +387 -0
  307. package/dist/modes/rpc/rpc-mode.js +509 -0
  308. package/dist/modes/rpc/rpc-types.js +8 -0
  309. package/dist/subagent-entry.js +145 -0
  310. package/dist/tool-names.js +34 -0
  311. package/dist/tui/autocomplete.js +596 -0
  312. package/dist/tui/components/box.js +104 -0
  313. package/dist/tui/components/cancellable-loader.js +35 -0
  314. package/dist/tui/components/editor.js +1679 -0
  315. package/dist/tui/components/image.js +69 -0
  316. package/dist/tui/components/input.js +433 -0
  317. package/dist/tui/components/loader.js +49 -0
  318. package/dist/tui/components/markdown.js +629 -0
  319. package/dist/tui/components/select-list.js +152 -0
  320. package/dist/tui/components/settings-list.js +185 -0
  321. package/dist/tui/components/spacer.js +23 -0
  322. package/dist/tui/components/text.js +89 -0
  323. package/dist/tui/components/truncated-text.js +51 -0
  324. package/dist/tui/editor-component.js +2 -0
  325. package/dist/tui/fuzzy.js +107 -0
  326. package/dist/tui/get-east-asian-width/index.js +32 -0
  327. package/dist/tui/get-east-asian-width/lookup.js +404 -0
  328. package/dist/tui/index.js +32 -0
  329. package/dist/tui/keybindings.js +114 -0
  330. package/dist/tui/keys.js +959 -0
  331. package/dist/tui/kill-ring.js +44 -0
  332. package/dist/tui/stdin-buffer.js +317 -0
  333. package/dist/tui/terminal-image.js +288 -0
  334. package/dist/tui/terminal.js +249 -0
  335. package/dist/tui/tui/autocomplete.js +596 -0
  336. package/dist/tui/tui/components/box.js +106 -0
  337. package/dist/tui/tui/components/cancellable-loader.js +35 -0
  338. package/dist/tui/tui/components/editor.js +1679 -0
  339. package/dist/tui/tui/components/image.js +69 -0
  340. package/dist/tui/tui/components/input.js +433 -0
  341. package/dist/tui/tui/components/loader.js +49 -0
  342. package/dist/tui/tui/components/markdown.js +629 -0
  343. package/dist/tui/tui/components/select-list.js +152 -0
  344. package/dist/tui/tui/components/settings-list.js +185 -0
  345. package/dist/tui/tui/components/spacer.js +23 -0
  346. package/dist/tui/tui/components/text.js +91 -0
  347. package/dist/tui/tui/components/truncated-text.js +51 -0
  348. package/dist/tui/tui/editor-component.js +2 -0
  349. package/dist/tui/tui/fuzzy.js +107 -0
  350. package/dist/tui/tui/get-east-asian-width/index.js +32 -0
  351. package/dist/tui/tui/get-east-asian-width/lookup.js +404 -0
  352. package/dist/tui/tui/index.js +32 -0
  353. package/dist/tui/tui/keybindings.js +114 -0
  354. package/dist/tui/tui/keys.js +959 -0
  355. package/dist/tui/tui/kill-ring.js +44 -0
  356. package/dist/tui/tui/stdin-buffer.js +317 -0
  357. package/dist/tui/tui/terminal-image.js +288 -0
  358. package/dist/tui/tui/terminal.js +249 -0
  359. package/dist/tui/tui/tui.js +955 -0
  360. package/dist/tui/tui/undo-stack.js +25 -0
  361. package/dist/tui/tui/utils.js +800 -0
  362. package/dist/tui/tui.js +955 -0
  363. package/dist/tui/undo-stack.js +25 -0
  364. package/dist/tui/utils.js +800 -0
  365. package/dist/utils/changelog.js +87 -0
  366. package/dist/utils/clipboard-image.js +164 -0
  367. package/dist/utils/clipboard-native.js +14 -0
  368. package/dist/utils/clipboard.js +67 -0
  369. package/dist/utils/frontmatter.js +26 -0
  370. package/dist/utils/git.js +166 -0
  371. package/dist/utils/image-convert.js +35 -0
  372. package/dist/utils/image-resize.js +183 -0
  373. package/dist/utils/mime.js +26 -0
  374. package/dist/utils/photon.js +121 -0
  375. package/dist/utils/shell.js +217 -0
  376. package/dist/utils/sleep.js +17 -0
  377. package/dist/utils/tools-manager.js +259 -0
  378. package/package.json +78 -0
  379. package/skills/excel-com-api/SKILL.md +74 -0
  380. package/skills/excel-com-api/excel-type-library.py +27767 -0
  381. package/skills/excel-com-api/office-type-library.py +10867 -0
  382. package/skills/integrations/SKILL.md +138 -0
  383. package/skills/integrations/alphasense.md +457 -0
  384. package/skills/integrations/bloomberg.md +803 -0
  385. package/skills/integrations/calcbench.md +315 -0
  386. package/skills/integrations/capiq.md +848 -0
  387. package/skills/integrations/dynamics-365-finance.md +354 -0
  388. package/skills/integrations/earnings_transcripts.md +387 -0
  389. package/skills/integrations/factset.md +758 -0
  390. package/skills/integrations/ice-fixed-income.md +344 -0
  391. package/skills/integrations/moodys-analytics.md +313 -0
  392. package/skills/integrations/morningstar.md +433 -0
  393. package/skills/integrations/nasdaq-data-link.md +249 -0
  394. package/skills/integrations/pitchbook.md +413 -0
  395. package/skills/integrations/preqin.md +422 -0
  396. package/skills/integrations/quickbooks.md +289 -0
  397. package/skills/integrations/quickfs.md +314 -0
  398. package/skills/integrations/refinitiv.md +473 -0
  399. package/skills/integrations/sage-intacct.md +401 -0
  400. package/skills/integrations/visible-alpha.md +320 -0
  401. package/skills/integrations/xero.md +393 -0
  402. package/skills/integrations/ycharts.md +306 -0
  403. package/skills/pdf-creation/SKILL.md +93 -0
  404. package/skills/pdf-extraction/SKILL.md +32 -0
  405. package/skills/powerpoint-creation/SKILL.md +110 -0
  406. package/skills/sec-edgar/SKILL.md +127 -0
  407. package/skills/sec-edgar/sec_to_pdf.py +109 -0
  408. package/xll/ShortcutXL.xll +0 -0
  409. package/xll/modules/debug_render.py +272 -0
  410. package/xll/modules/gameboy.py +241 -0
  411. package/xll/modules/pong.py +188 -0
  412. package/xll/modules/shortcut_xl/__init__.py +18 -0
  413. package/xll/modules/shortcut_xl/_categorize.py +200 -0
  414. package/xll/modules/shortcut_xl/_com.py +108 -0
  415. package/xll/modules/shortcut_xl/_format.py +252 -0
  416. package/xll/modules/shortcut_xl/_log.py +12 -0
  417. package/xll/modules/shortcut_xl/_managed.py +116 -0
  418. package/xll/modules/shortcut_xl/_registry.py +44 -0
  419. package/xll/modules/shortcut_xl/_threading.py +161 -0
  420. package/xll/modules/shortcut_xl/_tracking.py +283 -0
  421. package/xll/modules/stocks.py +100 -0
  422. package/xll/python3.dll +0 -0
  423. package/xll/python312.dll +0 -0
@@ -0,0 +1,1971 @@
1
+ > Shortcut can create extensions. Ask it to build one for your use case.
2
+
3
+ # Extensions
4
+
5
+ Extensions are TypeScript modules that extend Shortcut's behavior. They can subscribe to lifecycle events, register custom tools callable by the LLM, add commands, and more.
6
+
7
+ > **Placement for /reload:** Put extensions in `~/.shortcut/agent/extensions/` (global) or `.shortcut/extensions/` (project-local) for auto-discovery. Use `shortcut -e ./path.ts` only for quick tests. Extensions in auto-discovered locations can be hot-reloaded with `/reload`.
8
+
9
+ **Key capabilities:**
10
+ - **Custom tools** - Register tools the LLM can call via `shortcut.registerTool()`
11
+ - **Event interception** - Block or modify tool calls, inject context, customize compaction
12
+ - **User interaction** - Prompt users via `ctx.ui` (select, confirm, input, notify)
13
+ - **Custom UI components** - Full TUI components with keyboard input via `ctx.ui.custom()` for complex interactions
14
+ - **Custom commands** - Register commands like `/mycommand` via `shortcut.registerCommand()`
15
+ - **Session persistence** - Store state that survives restarts via `shortcut.appendEntry()`
16
+ - **Custom rendering** - Control how tool calls/results and messages appear in TUI
17
+
18
+ **Example use cases:**
19
+ - Permission gates (confirm before `rm -rf`, `sudo`, etc.)
20
+ - Git checkpointing (stash at each turn, restore on branch)
21
+ - Path protection (block writes to `.env`, `node_modules/`)
22
+ - Custom compaction (summarize conversation your way)
23
+ - Conversation summaries (see `summarize.ts` example)
24
+ - Interactive tools (questions, wizards, custom dialogs)
25
+ - Stateful tools (todo lists, connection pools)
26
+ - External integrations (file watchers, webhooks, CI triggers)
27
+ - Games while you wait (see `snake.ts` example)
28
+
29
+ See [examples/extensions/](../examples/extensions/) for working implementations.
30
+
31
+ ## Table of Contents
32
+
33
+ - [Quick Start](#quick-start)
34
+ - [Extension Locations](#extension-locations)
35
+ - [Available Imports](#available-imports)
36
+ - [Writing an Extension](#writing-an-extension)
37
+ - [Extension Styles](#extension-styles)
38
+ - [Events](#events)
39
+ - [Lifecycle Overview](#lifecycle-overview)
40
+ - [Session Events](#session-events)
41
+ - [Agent Events](#agent-events)
42
+ - [Tool Events](#tool-events)
43
+ - [ExtensionContext](#extensioncontext)
44
+ - [ExtensionCommandContext](#extensioncommandcontext)
45
+ - [ExtensionAPI Methods](#extensionapi-methods)
46
+ - [State Management](#state-management)
47
+ - [Custom Tools](#custom-tools)
48
+ - [Custom UI](#custom-ui)
49
+ - [Error Handling](#error-handling)
50
+ - [Mode Behavior](#mode-behavior)
51
+ - [Examples Reference](#examples-reference)
52
+
53
+ ## Quick Start
54
+
55
+ Create `~/.shortcut/agent/extensions/my-extension.ts`:
56
+
57
+ ```typescript
58
+ import type { ExtensionAPI } from "shortcutxl";
59
+ import { Type } from "@sinclair/typebox";
60
+
61
+ export default function (shortcut: ExtensionAPI) {
62
+ // React to events
63
+ shortcut.on("session_start", async (_event, ctx) => {
64
+ ctx.ui.notify("Extension loaded!", "info");
65
+ });
66
+
67
+ shortcut.on("tool_call", async (event, ctx) => {
68
+ if (event.toolName === "bash" && event.input.command?.includes("rm -rf")) {
69
+ const ok = await ctx.ui.confirm("Dangerous!", "Allow rm -rf?");
70
+ if (!ok) return { block: true, reason: "Blocked by user" };
71
+ }
72
+ });
73
+
74
+ // Register a custom tool
75
+ shortcut.registerTool({
76
+ name: "greet",
77
+ label: "Greet",
78
+ description: "Greet someone by name",
79
+ parameters: Type.Object({
80
+ name: Type.String({ description: "Name to greet" }),
81
+ }),
82
+ async execute(toolCallId, params, signal, onUpdate, ctx) {
83
+ return {
84
+ content: [{ type: "text", text: `Hello, ${params.name}!` }],
85
+ details: {},
86
+ };
87
+ },
88
+ });
89
+
90
+ // Register a command
91
+ shortcut.registerCommand("hello", {
92
+ description: "Say hello",
93
+ handler: async (args, ctx) => {
94
+ ctx.ui.notify(`Hello ${args || "world"}!`, "info");
95
+ },
96
+ });
97
+ }
98
+ ```
99
+
100
+ Test with `--extension` (or `-e`) flag:
101
+
102
+ ```bash
103
+ shortcut -e ./my-extension.ts
104
+ ```
105
+
106
+ ## Extension Locations
107
+
108
+ > **Security:** Extensions run with your full system permissions and can execute arbitrary code. Only install from sources you trust.
109
+
110
+ Extensions are auto-discovered from:
111
+
112
+ | Location | Scope |
113
+ |----------|-------|
114
+ | `~/.shortcut/agent/extensions/*.ts` | Global (all projects) |
115
+ | `~/.shortcut/agent/extensions/*/index.ts` | Global (subdirectory) |
116
+ | `.shortcut/extensions/*.ts` | Project-local |
117
+ | `.shortcut/extensions/*/index.ts` | Project-local (subdirectory) |
118
+
119
+ Additional paths via `settings.json`:
120
+
121
+ ```json
122
+ {
123
+ "packages": [
124
+ "npm:@foo/bar@1.0.0",
125
+ "git:github.com/user/repo@v1"
126
+ ],
127
+ "extensions": [
128
+ "/path/to/local/extension.ts",
129
+ "/path/to/local/extension/dir"
130
+ ]
131
+ }
132
+ ```
133
+
134
+ To share extensions via npm or git as Shortcut packages, see [packages.md](packages.md).
135
+
136
+ ## Available Imports
137
+
138
+ | Package | Purpose |
139
+ |---------|---------|
140
+ | `shortcutxl` | Extension types (`ExtensionAPI`, `ExtensionContext`, events) |
141
+ | `@sinclair/typebox` | Schema definitions for tool parameters |
142
+ | `shortcutxl` | AI utilities (`StringEnum` for Google-compatible enums) |
143
+ | `shortcutxl` | TUI components for custom rendering |
144
+
145
+ npm dependencies work too. Add a `package.json` next to your extension (or in a parent directory), run `npm install`, and imports from `node_modules/` are resolved automatically.
146
+
147
+ Node.js built-ins (`node:fs`, `node:path`, etc.) are also available.
148
+
149
+ ## Writing an Extension
150
+
151
+ An extension exports a default function that receives `ExtensionAPI`:
152
+
153
+ ```typescript
154
+ import type { ExtensionAPI } from "shortcutxl";
155
+
156
+ export default function (shortcut: ExtensionAPI) {
157
+ // Subscribe to events
158
+ shortcut.on("event_name", async (event, ctx) => {
159
+ // ctx.ui for user interaction
160
+ const ok = await ctx.ui.confirm("Title", "Are you sure?");
161
+ ctx.ui.notify("Done!", "success");
162
+ ctx.ui.setStatus("my-ext", "Processing..."); // Footer status
163
+ ctx.ui.setWidget("my-ext", ["Line 1", "Line 2"]); // Widget above editor (default)
164
+ });
165
+
166
+ // Register tools, commands, shortcuts, flags
167
+ shortcut.registerTool({ ... });
168
+ shortcut.registerCommand("name", { ... });
169
+ shortcut.registerShortcut("ctrl+x", { ... });
170
+ shortcut.registerFlag("my-flag", { ... });
171
+ }
172
+ ```
173
+
174
+ Extensions are loaded via [jiti](https://github.com/unjs/jiti), so TypeScript works without compilation.
175
+
176
+ ### Extension Styles
177
+
178
+ **Single file** - simplest, for small extensions:
179
+
180
+ ```
181
+ ~/.shortcut/agent/extensions/
182
+ └── my-extension.ts
183
+ ```
184
+
185
+ **Directory with index.ts** - for multi-file extensions:
186
+
187
+ ```
188
+ ~/.shortcut/agent/extensions/
189
+ └── my-extension/
190
+ ├── index.ts # Entry point (exports default function)
191
+ ├── tools.ts # Helper module
192
+ └── utils.ts # Helper module
193
+ ```
194
+
195
+ **Package with dependencies** - for extensions that need npm packages:
196
+
197
+ ```
198
+ ~/.shortcut/agent/extensions/
199
+ └── my-extension/
200
+ ├── package.json # Declares dependencies and entry points
201
+ ├── package-lock.json
202
+ ├── node_modules/ # After npm install
203
+ └── src/
204
+ └── index.ts
205
+ ```
206
+
207
+ ```json
208
+ // package.json
209
+ {
210
+ "name": "my-extension",
211
+ "dependencies": {
212
+ "zod": "^3.0.0",
213
+ "chalk": "^5.0.0"
214
+ },
215
+ "shortcut": {
216
+ "extensions": ["./src/index.ts"]
217
+ }
218
+ }
219
+ ```
220
+
221
+ Run `npm install` in the extension directory, then imports from `node_modules/` work automatically.
222
+
223
+ ## Events
224
+
225
+ ### Lifecycle Overview
226
+
227
+ ```
228
+ Shortcut starts
229
+
230
+ └─► session_start
231
+
232
+
233
+ user sends prompt ─────────────────────────────────────────┐
234
+ │ │
235
+ ├─► (extension commands checked first, bypass if found) │
236
+ ├─► input (can intercept, transform, or handle) │
237
+ ├─► (skill/template expansion if not handled) │
238
+ ├─► before_agent_start (can inject message, modify system prompt)
239
+ ├─► agent_start │
240
+ ├─► message_start / message_update / message_end │
241
+ │ │
242
+ │ ┌─── turn (repeats while LLM calls tools) ───┐ │
243
+ │ │ │ │
244
+ │ ├─► turn_start │ │
245
+ │ ├─► context (can modify messages) │ │
246
+ │ │ │ │
247
+ │ │ LLM responds, may call tools: │ │
248
+ │ │ ├─► tool_call (can block) │ │
249
+ │ │ ├─► tool_execution_start │ │
250
+ │ │ ├─► tool_execution_update │ │
251
+ │ │ ├─► tool_execution_end │ │
252
+ │ │ └─► tool_result (can modify) │ │
253
+ │ │ │ │
254
+ │ └─► turn_end │ │
255
+ │ │
256
+ └─► agent_end │
257
+
258
+ user sends another prompt ◄────────────────────────────────┘
259
+
260
+ /new (new session) or /resume (switch session)
261
+ ├─► session_before_switch (can cancel)
262
+ └─► session_switch
263
+
264
+ /fork
265
+ ├─► session_before_fork (can cancel)
266
+ └─► session_fork
267
+
268
+ /compact or auto-compaction
269
+ ├─► session_before_compact (can cancel or customize)
270
+ └─► session_compact
271
+
272
+ /tree navigation
273
+ ├─► session_before_tree (can cancel or customize)
274
+ └─► session_tree
275
+
276
+ /model or Ctrl+P (model selection/cycling)
277
+ └─► model_select
278
+
279
+ exit (Ctrl+C, Ctrl+D)
280
+ └─► session_shutdown
281
+ ```
282
+
283
+ ### Session Events
284
+
285
+ See [session.md](session.md) for session storage internals and the SessionManager API.
286
+
287
+ #### session_start
288
+
289
+ Fired on initial session load.
290
+
291
+ ```typescript
292
+ shortcut.on("session_start", async (_event, ctx) => {
293
+ ctx.ui.notify(`Session: ${ctx.sessionManager.getSessionFile() ?? "ephemeral"}`, "info");
294
+ });
295
+ ```
296
+
297
+ #### session_before_switch / session_switch
298
+
299
+ Fired when starting a new session (`/new`) or switching sessions (`/resume`).
300
+
301
+ ```typescript
302
+ shortcut.on("session_before_switch", async (event, ctx) => {
303
+ // event.reason - "new" or "resume"
304
+ // event.targetSessionFile - session we're switching to (only for "resume")
305
+
306
+ if (event.reason === "new") {
307
+ const ok = await ctx.ui.confirm("Clear?", "Delete all messages?");
308
+ if (!ok) return { cancel: true };
309
+ }
310
+ });
311
+
312
+ shortcut.on("session_switch", async (event, ctx) => {
313
+ // event.reason - "new" or "resume"
314
+ // event.previousSessionFile - session we came from
315
+ });
316
+ ```
317
+
318
+ #### session_before_fork / session_fork
319
+
320
+ Fired when forking via `/fork`.
321
+
322
+ ```typescript
323
+ shortcut.on("session_before_fork", async (event, ctx) => {
324
+ // event.entryId - ID of the entry being forked from
325
+ return { cancel: true }; // Cancel fork
326
+ // OR
327
+ return { skipConversationRestore: true }; // Fork but don't rewind messages
328
+ });
329
+
330
+ shortcut.on("session_fork", async (event, ctx) => {
331
+ // event.previousSessionFile - previous session file
332
+ });
333
+ ```
334
+
335
+ #### session_before_compact / session_compact
336
+
337
+ Fired on compaction. See [compaction.md](compaction.md) for details.
338
+
339
+ ```typescript
340
+ shortcut.on("session_before_compact", async (event, ctx) => {
341
+ const { preparation, branchEntries, customInstructions, signal } = event;
342
+
343
+ // Cancel:
344
+ return { cancel: true };
345
+
346
+ // Custom summary:
347
+ return {
348
+ compaction: {
349
+ summary: "...",
350
+ firstKeptEntryId: preparation.firstKeptEntryId,
351
+ tokensBefore: preparation.tokensBefore,
352
+ }
353
+ };
354
+ });
355
+
356
+ shortcut.on("session_compact", async (event, ctx) => {
357
+ // event.compactionEntry - the saved compaction
358
+ // event.fromExtension - whether extension provided it
359
+ });
360
+ ```
361
+
362
+ #### session_before_tree / session_tree
363
+
364
+ Fired on `/tree` navigation. See [tree.md](tree.md) for tree navigation concepts.
365
+
366
+ ```typescript
367
+ shortcut.on("session_before_tree", async (event, ctx) => {
368
+ const { preparation, signal } = event;
369
+ return { cancel: true };
370
+ // OR provide custom summary:
371
+ return { summary: { summary: "...", details: {} } };
372
+ });
373
+
374
+ shortcut.on("session_tree", async (event, ctx) => {
375
+ // event.newLeafId, oldLeafId, summaryEntry, fromExtension
376
+ });
377
+ ```
378
+
379
+ #### session_shutdown
380
+
381
+ Fired on exit (Ctrl+C, Ctrl+D, SIGTERM).
382
+
383
+ ```typescript
384
+ shortcut.on("session_shutdown", async (_event, ctx) => {
385
+ // Cleanup, save state, etc.
386
+ });
387
+ ```
388
+
389
+ ### Agent Events
390
+
391
+ #### before_agent_start
392
+
393
+ Fired after user submits prompt, before agent loop. Can inject a message and/or modify the system prompt.
394
+
395
+ ```typescript
396
+ shortcut.on("before_agent_start", async (event, ctx) => {
397
+ // event.prompt - user's prompt text
398
+ // event.images - attached images (if any)
399
+ // event.systemPrompt - current system prompt
400
+
401
+ return {
402
+ // Inject a persistent message (stored in session, sent to LLM)
403
+ message: {
404
+ customType: "my-extension",
405
+ content: "Additional context for the LLM",
406
+ display: true,
407
+ },
408
+ // Replace the system prompt for this turn (chained across extensions)
409
+ systemPrompt: event.systemPrompt + "\n\nExtra instructions for this turn...",
410
+ };
411
+ });
412
+ ```
413
+
414
+ #### agent_start / agent_end
415
+
416
+ Fired once per user prompt.
417
+
418
+ ```typescript
419
+ shortcut.on("agent_start", async (_event, ctx) => {});
420
+
421
+ shortcut.on("agent_end", async (event, ctx) => {
422
+ // event.messages - messages from this prompt
423
+ });
424
+ ```
425
+
426
+ #### turn_start / turn_end
427
+
428
+ Fired for each turn (one LLM response + tool calls).
429
+
430
+ ```typescript
431
+ shortcut.on("turn_start", async (event, ctx) => {
432
+ // event.turnIndex, event.timestamp
433
+ });
434
+
435
+ shortcut.on("turn_end", async (event, ctx) => {
436
+ // event.turnIndex, event.message, event.toolResults
437
+ });
438
+ ```
439
+
440
+ #### message_start / message_update / message_end
441
+
442
+ Fired for message lifecycle updates.
443
+
444
+ - `message_start` and `message_end` fire for user, assistant, and toolResult messages.
445
+ - `message_update` fires for assistant streaming updates.
446
+
447
+ ```typescript
448
+ shortcut.on("message_start", async (event, ctx) => {
449
+ // event.message
450
+ });
451
+
452
+ shortcut.on("message_update", async (event, ctx) => {
453
+ // event.message
454
+ // event.assistantMessageEvent (token-by-token stream event)
455
+ });
456
+
457
+ shortcut.on("message_end", async (event, ctx) => {
458
+ // event.message
459
+ });
460
+ ```
461
+
462
+ #### tool_execution_start / tool_execution_update / tool_execution_end
463
+
464
+ Fired for tool execution lifecycle updates.
465
+
466
+ ```typescript
467
+ shortcut.on("tool_execution_start", async (event, ctx) => {
468
+ // event.toolCallId, event.toolName, event.args
469
+ });
470
+
471
+ shortcut.on("tool_execution_update", async (event, ctx) => {
472
+ // event.toolCallId, event.toolName, event.args, event.partialResult
473
+ });
474
+
475
+ shortcut.on("tool_execution_end", async (event, ctx) => {
476
+ // event.toolCallId, event.toolName, event.result, event.isError
477
+ });
478
+ ```
479
+
480
+ #### context
481
+
482
+ Fired before each LLM call. Modify messages non-destructively. See [session.md](session.md) for message types.
483
+
484
+ ```typescript
485
+ shortcut.on("context", async (event, ctx) => {
486
+ // event.messages - deep copy, safe to modify
487
+ const filtered = event.messages.filter(m => !shouldPrune(m));
488
+ return { messages: filtered };
489
+ });
490
+ ```
491
+
492
+ ### Model Events
493
+
494
+ #### model_select
495
+
496
+ Fired when the model changes via `/model` command, model cycling (`Ctrl+P`), or session restore.
497
+
498
+ ```typescript
499
+ shortcut.on("model_select", async (event, ctx) => {
500
+ // event.model - newly selected model
501
+ // event.previousModel - previous model (undefined if first selection)
502
+ // event.source - "set" | "cycle" | "restore"
503
+
504
+ const prev = event.previousModel
505
+ ? `${event.previousModel.provider}/${event.previousModel.id}`
506
+ : "none";
507
+ const next = `${event.model.provider}/${event.model.id}`;
508
+
509
+ ctx.ui.notify(`Model changed (${event.source}): ${prev} -> ${next}`, "info");
510
+ });
511
+ ```
512
+
513
+ Use this to update UI elements (status bars, footers) or perform model-specific initialization when the active model changes.
514
+
515
+ ### Tool Events
516
+
517
+ #### tool_call
518
+
519
+ Fired before tool executes. **Can block.** Use `isToolCallEventType` to narrow and get typed inputs.
520
+
521
+ ```typescript
522
+ import { isToolCallEventType } from "shortcutxl";
523
+
524
+ shortcut.on("tool_call", async (event, ctx) => {
525
+ // event.toolName - "bash", "read", "write", "edit", etc.
526
+ // event.toolCallId
527
+ // event.input - tool parameters
528
+
529
+ // Built-in tools: no type params needed
530
+ if (isToolCallEventType("bash", event)) {
531
+ // event.input is { command: string; timeout?: number }
532
+ if (event.input.command.includes("rm -rf")) {
533
+ return { block: true, reason: "Dangerous command" };
534
+ }
535
+ }
536
+
537
+ if (isToolCallEventType("read", event)) {
538
+ // event.input is { path: string; offset?: number; limit?: number }
539
+ console.log(`Reading: ${event.input.path}`);
540
+ }
541
+ });
542
+ ```
543
+
544
+ #### Typing custom tool input
545
+
546
+ Custom tools should export their input type:
547
+
548
+ ```typescript
549
+ // my-extension.ts
550
+ export type MyToolInput = Static<typeof myToolSchema>;
551
+ ```
552
+
553
+ Use `isToolCallEventType` with explicit type parameters:
554
+
555
+ ```typescript
556
+ import { isToolCallEventType } from "shortcutxl";
557
+ import type { MyToolInput } from "my-extension";
558
+
559
+ shortcut.on("tool_call", (event) => {
560
+ if (isToolCallEventType<"my_tool", MyToolInput>("my_tool", event)) {
561
+ event.input.action; // typed
562
+ }
563
+ });
564
+ ```
565
+
566
+ #### tool_result
567
+
568
+ Fired after tool executes. **Can modify result.**
569
+
570
+ `tool_result` handlers chain like middleware:
571
+ - Handlers run in extension load order
572
+ - Each handler sees the latest result after previous handler changes
573
+ - Handlers can return partial patches (`content`, `details`, or `isError`); omitted fields keep their current values
574
+
575
+ ```typescript
576
+ import { isBashToolResult } from "shortcutxl";
577
+
578
+ shortcut.on("tool_result", async (event, ctx) => {
579
+ // event.toolName, event.toolCallId, event.input
580
+ // event.content, event.details, event.isError
581
+
582
+ if (isBashToolResult(event)) {
583
+ // event.details is typed as BashToolDetails
584
+ }
585
+
586
+ // Modify result:
587
+ return { content: [...], details: {...}, isError: false };
588
+ });
589
+ ```
590
+
591
+ ### User Bash Events
592
+
593
+ #### user_bash
594
+
595
+ Fired when user executes `!` or `!!` commands. **Can intercept.**
596
+
597
+ ```typescript
598
+ shortcut.on("user_bash", (event, ctx) => {
599
+ // event.command - the bash command
600
+ // event.excludeFromContext - true if !! prefix
601
+ // event.cwd - working directory
602
+
603
+ // Option 1: Provide custom operations (e.g., SSH)
604
+ return { operations: remoteBashOps };
605
+
606
+ // Option 2: Full replacement - return result directly
607
+ return { result: { output: "...", exitCode: 0, cancelled: false, truncated: false } };
608
+ });
609
+ ```
610
+
611
+ ### Input Events
612
+
613
+ #### input
614
+
615
+ Fired when user input is received, after extension commands are checked but before skill and template expansion. The event sees the raw input text, so `/skill:foo` and `/template` are not yet expanded.
616
+
617
+ **Processing order:**
618
+ 1. Extension commands (`/cmd`) checked first - if found, handler runs and input event is skipped
619
+ 2. `input` event fires - can intercept, transform, or handle
620
+ 3. If not handled: skill commands (`/skill:name`) expanded to skill content
621
+ 4. If not handled: prompt templates (`/template`) expanded to template content
622
+ 5. Agent processing begins (`before_agent_start`, etc.)
623
+
624
+ ```typescript
625
+ shortcut.on("input", async (event, ctx) => {
626
+ // event.text - raw input (before skill/template expansion)
627
+ // event.images - attached images, if any
628
+ // event.source - "interactive" (typed), "rpc" (API), or "extension" (via sendUserMessage)
629
+
630
+ // Transform: rewrite input before expansion
631
+ if (event.text.startsWith("?quick "))
632
+ return { action: "transform", text: `Respond briefly: ${event.text.slice(7)}` };
633
+
634
+ // Handle: respond without LLM (extension shows its own feedback)
635
+ if (event.text === "ping") {
636
+ ctx.ui.notify("pong", "info");
637
+ return { action: "handled" };
638
+ }
639
+
640
+ // Route by source: skip processing for extension-injected messages
641
+ if (event.source === "extension") return { action: "continue" };
642
+
643
+ // Intercept skill commands before expansion
644
+ if (event.text.startsWith("/skill:")) {
645
+ // Could transform, block, or let pass through
646
+ }
647
+
648
+ return { action: "continue" }; // Default: pass through to expansion
649
+ });
650
+ ```
651
+
652
+ **Results:**
653
+ - `continue` - pass through unchanged (default if handler returns nothing)
654
+ - `transform` - modify text/images, then continue to expansion
655
+ - `handled` - skip agent entirely (first handler to return this wins)
656
+
657
+ Transforms chain across handlers. See [input-transform.ts](../examples/extensions/input-transform.ts).
658
+
659
+ ## ExtensionContext
660
+
661
+ Every handler receives `ctx: ExtensionContext`:
662
+
663
+ ### ctx.ui
664
+
665
+ UI methods for user interaction. See [Custom UI](#custom-ui) for full details.
666
+
667
+ ### ctx.hasUI
668
+
669
+ `false` in print mode (`-p`) and JSON mode. `true` in interactive and RPC mode. In RPC mode, dialog methods (`select`, `confirm`, `input`, `editor`) work via the extension UI sub-protocol, and fire-and-forget methods (`notify`, `setStatus`, `setWidget`, `setTitle`, `setEditorText`) emit requests to the client. Some TUI-specific methods are no-ops or return defaults (see [rpc.md](rpc.md#extension-ui-protocol)).
670
+
671
+ ### ctx.cwd
672
+
673
+ Current working directory.
674
+
675
+ ### ctx.sessionManager
676
+
677
+ Read-only access to session state. See [session.md](session.md) for the full SessionManager API and entry types.
678
+
679
+ ```typescript
680
+ ctx.sessionManager.getEntries() // All entries
681
+ ctx.sessionManager.getBranch() // Current branch
682
+ ctx.sessionManager.getLeafId() // Current leaf entry ID
683
+ ```
684
+
685
+ ### ctx.modelRegistry / ctx.model
686
+
687
+ Access to models and API keys.
688
+
689
+ ### ctx.isIdle() / ctx.abort() / ctx.hasPendingMessages()
690
+
691
+ Control flow helpers.
692
+
693
+ ### ctx.shutdown()
694
+
695
+ Request a graceful shutdown of Shortcut.
696
+
697
+ - **Interactive mode:** Deferred until the agent becomes idle (after processing all queued steering and follow-up messages).
698
+ - **RPC mode:** Deferred until the next idle state (after completing the current command response, when waiting for the next command).
699
+ - **Print mode:** No-op. The process exits automatically when all prompts are processed.
700
+
701
+ Emits `session_shutdown` event to all extensions before exiting. Available in all contexts (event handlers, tools, commands, shortcuts).
702
+
703
+ ```typescript
704
+ shortcut.on("tool_call", (event, ctx) => {
705
+ if (isFatal(event.input)) {
706
+ ctx.shutdown();
707
+ }
708
+ });
709
+ ```
710
+
711
+ ### ctx.getContextUsage()
712
+
713
+ Returns current context usage for the active model. Uses last assistant usage when available, then estimates tokens for trailing messages.
714
+
715
+ ```typescript
716
+ const usage = ctx.getContextUsage();
717
+ if (usage && usage.tokens > 100_000) {
718
+ // ...
719
+ }
720
+ ```
721
+
722
+ ### ctx.compact()
723
+
724
+ Trigger compaction without awaiting completion. Use `onComplete` and `onError` for follow-up actions.
725
+
726
+ ```typescript
727
+ ctx.compact({
728
+ customInstructions: "Focus on recent changes",
729
+ onComplete: (result) => {
730
+ ctx.ui.notify("Compaction completed", "info");
731
+ },
732
+ onError: (error) => {
733
+ ctx.ui.notify(`Compaction failed: ${error.message}`, "error");
734
+ },
735
+ });
736
+ ```
737
+
738
+ ### ctx.getSystemPrompt()
739
+
740
+ Returns the current effective system prompt. This includes any modifications made by `before_agent_start` handlers for the current turn.
741
+
742
+ ```typescript
743
+ shortcut.on("before_agent_start", (event, ctx) => {
744
+ const prompt = ctx.getSystemPrompt();
745
+ console.log(`System prompt length: ${prompt.length}`);
746
+ });
747
+ ```
748
+
749
+ ## ExtensionCommandContext
750
+
751
+ Command handlers receive `ExtensionCommandContext`, which extends `ExtensionContext` with session control methods. These are only available in commands because they can deadlock if called from event handlers.
752
+
753
+ ### ctx.waitForIdle()
754
+
755
+ Wait for the agent to finish streaming:
756
+
757
+ ```typescript
758
+ shortcut.registerCommand("my-cmd", {
759
+ handler: async (args, ctx) => {
760
+ await ctx.waitForIdle();
761
+ // Agent is now idle, safe to modify session
762
+ },
763
+ });
764
+ ```
765
+
766
+ ### ctx.newSession(options?)
767
+
768
+ Create a new session:
769
+
770
+ ```typescript
771
+ const result = await ctx.newSession({
772
+ parentSession: ctx.sessionManager.getSessionFile(),
773
+ setup: async (sm) => {
774
+ sm.appendMessage({
775
+ role: "user",
776
+ content: [{ type: "text", text: "Context from previous session..." }],
777
+ timestamp: Date.now(),
778
+ });
779
+ },
780
+ });
781
+
782
+ if (result.cancelled) {
783
+ // An extension cancelled the new session
784
+ }
785
+ ```
786
+
787
+ ### ctx.fork(entryId)
788
+
789
+ Fork from a specific entry, creating a new session file:
790
+
791
+ ```typescript
792
+ const result = await ctx.fork("entry-id-123");
793
+ if (!result.cancelled) {
794
+ // Now in the forked session
795
+ }
796
+ ```
797
+
798
+ ### ctx.navigateTree(targetId, options?)
799
+
800
+ Navigate to a different point in the session tree:
801
+
802
+ ```typescript
803
+ const result = await ctx.navigateTree("entry-id-456", {
804
+ summarize: true,
805
+ customInstructions: "Focus on error handling changes",
806
+ replaceInstructions: false, // true = replace default prompt entirely
807
+ label: "review-checkpoint",
808
+ });
809
+ ```
810
+
811
+ Options:
812
+ - `summarize`: Whether to generate a summary of the abandoned branch
813
+ - `customInstructions`: Custom instructions for the summarizer
814
+ - `replaceInstructions`: If true, `customInstructions` replaces the default prompt instead of being appended
815
+ - `label`: Label to attach to the branch summary entry (or target entry if not summarizing)
816
+
817
+ ### ctx.reload()
818
+
819
+ Run the same reload flow as `/reload`.
820
+
821
+ ```typescript
822
+ shortcut.registerCommand("reload-runtime", {
823
+ description: "Reload extensions, skills, prompts, and themes",
824
+ handler: async (_args, ctx) => {
825
+ await ctx.reload();
826
+ return;
827
+ },
828
+ });
829
+ ```
830
+
831
+ Important behavior:
832
+ - `await ctx.reload()` emits `session_shutdown` for the current extension runtime
833
+ - It then reloads resources and emits `session_start` (and `resources_discover` with reason `"reload"`) for the new runtime
834
+ - The currently running command handler still continues in the old call frame
835
+ - Code after `await ctx.reload()` still runs from the pre-reload version
836
+ - Code after `await ctx.reload()` must not assume old in-memory extension state is still valid
837
+ - After the handler returns, future commands/events/tool calls use the new extension version
838
+
839
+ For predictable behavior, treat reload as terminal for that handler (`await ctx.reload(); return;`).
840
+
841
+ Tools run with `ExtensionContext`, so they cannot call `ctx.reload()` directly. Use a command as the reload entrypoint, then expose a tool that queues that command as a follow-up user message.
842
+
843
+ Example tool the LLM can call to trigger reload:
844
+
845
+ ```typescript
846
+ import type { ExtensionAPI } from "shortcutxl";
847
+ import { Type } from "@sinclair/typebox";
848
+
849
+ export default function (shortcut: ExtensionAPI) {
850
+ shortcut.registerCommand("reload-runtime", {
851
+ description: "Reload extensions, skills, prompts, and themes",
852
+ handler: async (_args, ctx) => {
853
+ await ctx.reload();
854
+ return;
855
+ },
856
+ });
857
+
858
+ shortcut.registerTool({
859
+ name: "reload_runtime",
860
+ label: "Reload Runtime",
861
+ description: "Reload extensions, skills, prompts, and themes",
862
+ parameters: Type.Object({}),
863
+ async execute() {
864
+ shortcut.sendUserMessage("/reload-runtime", { deliverAs: "followUp" });
865
+ return {
866
+ content: [{ type: "text", text: "Queued /reload-runtime as a follow-up command." }],
867
+ };
868
+ },
869
+ });
870
+ }
871
+ ```
872
+
873
+ ## ExtensionAPI Methods
874
+
875
+ ### shortcut.on(event, handler)
876
+
877
+ Subscribe to events. See [Events](#events) for event types and return values.
878
+
879
+ ### shortcut.registerTool(definition)
880
+
881
+ Register a custom tool callable by the LLM. See [Custom Tools](#custom-tools) for full details.
882
+
883
+ `shortcut.registerTool()` works both during extension load and after startup. You can call it inside `session_start`, command handlers, or other event handlers. New tools are refreshed immediately in the same session, so they appear in `shortcut.getAllTools()` and are callable by the LLM without `/reload`.
884
+
885
+ Use `shortcut.setActiveTools()` to enable or disable tools (including dynamically added tools) at runtime.
886
+
887
+ Use `promptSnippet` to customize that tool's one-line entry in `Available tools`, and `promptGuidelines` to append tool-specific bullets to the default `Guidelines` section when the tool is active.
888
+
889
+ See [dynamic-tools.ts](../examples/extensions/dynamic-tools.ts) for a full example.
890
+
891
+ ```typescript
892
+ import { Type } from "@sinclair/typebox";
893
+ import { StringEnum } from "shortcutxl";
894
+
895
+ shortcut.registerTool({
896
+ name: "my_tool",
897
+ label: "My Tool",
898
+ description: "What this tool does",
899
+ promptSnippet: "Summarize or transform text according to action",
900
+ promptGuidelines: ["Use this tool when the user asks to summarize previously generated text."],
901
+ parameters: Type.Object({
902
+ action: StringEnum(["list", "add"] as const),
903
+ text: Type.Optional(Type.String()),
904
+ }),
905
+
906
+ async execute(toolCallId, params, signal, onUpdate, ctx) {
907
+ // Stream progress
908
+ onUpdate?.({ content: [{ type: "text", text: "Working..." }] });
909
+
910
+ return {
911
+ content: [{ type: "text", text: "Done" }],
912
+ details: { result: "..." },
913
+ };
914
+ },
915
+
916
+ // Optional: Custom rendering
917
+ renderCall(args, theme) { ... },
918
+ renderResult(result, options, theme) { ... },
919
+ });
920
+ ```
921
+
922
+ ### shortcut.sendMessage(message, options?)
923
+
924
+ Inject a custom message into the session.
925
+
926
+ ```typescript
927
+ shortcut.sendMessage({
928
+ customType: "my-extension",
929
+ content: "Message text",
930
+ display: true,
931
+ details: { ... },
932
+ }, {
933
+ triggerTurn: true,
934
+ deliverAs: "steer",
935
+ });
936
+ ```
937
+
938
+ **Options:**
939
+ - `deliverAs` - Delivery mode:
940
+ - `"steer"` (default) - Interrupts streaming. Delivered after current tool finishes, remaining tools skipped.
941
+ - `"followUp"` - Waits for agent to finish. Delivered only when agent has no more tool calls.
942
+ - `"nextTurn"` - Queued for next user prompt. Does not interrupt or trigger anything.
943
+ - `triggerTurn: true` - If agent is idle, trigger an LLM response immediately. Only applies to `"steer"` and `"followUp"` modes (ignored for `"nextTurn"`).
944
+
945
+ ### shortcut.sendUserMessage(content, options?)
946
+
947
+ Send a user message to the agent. Unlike `sendMessage()` which sends custom messages, this sends an actual user message that appears as if typed by the user. Always triggers a turn.
948
+
949
+ ```typescript
950
+ // Simple text message
951
+ shortcut.sendUserMessage("What is 2+2?");
952
+
953
+ // With content array (text + images)
954
+ shortcut.sendUserMessage([
955
+ { type: "text", text: "Describe this image:" },
956
+ { type: "image", source: { type: "base64", mediaType: "image/png", data: "..." } },
957
+ ]);
958
+
959
+ // During streaming - must specify delivery mode
960
+ shortcut.sendUserMessage("Focus on error handling", { deliverAs: "steer" });
961
+ shortcut.sendUserMessage("And then summarize", { deliverAs: "followUp" });
962
+ ```
963
+
964
+ **Options:**
965
+ - `deliverAs` - Required when agent is streaming:
966
+ - `"steer"` - Interrupts after current tool, remaining tools skipped
967
+ - `"followUp"` - Waits for agent to finish all tools
968
+
969
+ When not streaming, the message is sent immediately and triggers a new turn. When streaming without `deliverAs`, throws an error.
970
+
971
+ See [send-user-message.ts](../examples/extensions/send-user-message.ts) for a complete example.
972
+
973
+ ### shortcut.appendEntry(customType, data?)
974
+
975
+ Persist extension state (does NOT participate in LLM context).
976
+
977
+ ```typescript
978
+ shortcut.appendEntry("my-state", { count: 42 });
979
+
980
+ // Restore on reload
981
+ shortcut.on("session_start", async (_event, ctx) => {
982
+ for (const entry of ctx.sessionManager.getEntries()) {
983
+ if (entry.type === "custom" && entry.customType === "my-state") {
984
+ // Reconstruct from entry.data
985
+ }
986
+ }
987
+ });
988
+ ```
989
+
990
+ ### shortcut.setSessionName(name)
991
+
992
+ Set the session display name (shown in session selector instead of first message).
993
+
994
+ ```typescript
995
+ shortcut.setSessionName("Refactor auth module");
996
+ ```
997
+
998
+ ### shortcut.getSessionName()
999
+
1000
+ Get the current session name, if set.
1001
+
1002
+ ```typescript
1003
+ const name = shortcut.getSessionName();
1004
+ if (name) {
1005
+ console.log(`Session: ${name}`);
1006
+ }
1007
+ ```
1008
+
1009
+ ### shortcut.setLabel(entryId, label)
1010
+
1011
+ Set or clear a label on an entry. Labels are user-defined markers for bookmarking and navigation (shown in `/tree` selector).
1012
+
1013
+ ```typescript
1014
+ // Set a label
1015
+ shortcut.setLabel(entryId, "checkpoint-before-refactor");
1016
+
1017
+ // Clear a label
1018
+ shortcut.setLabel(entryId, undefined);
1019
+
1020
+ // Read labels via sessionManager
1021
+ const label = ctx.sessionManager.getLabel(entryId);
1022
+ ```
1023
+
1024
+ Labels persist in the session and survive restarts. Use them to mark important points (turns, checkpoints) in the conversation tree.
1025
+
1026
+ ### shortcut.registerCommand(name, options)
1027
+
1028
+ Register a command.
1029
+
1030
+ ```typescript
1031
+ shortcut.registerCommand("stats", {
1032
+ description: "Show session statistics",
1033
+ handler: async (args, ctx) => {
1034
+ const count = ctx.sessionManager.getEntries().length;
1035
+ ctx.ui.notify(`${count} entries`, "info");
1036
+ }
1037
+ });
1038
+ ```
1039
+
1040
+ Optional: add argument auto-completion for `/command ...`:
1041
+
1042
+ ```typescript
1043
+ import type { AutocompleteItem } from "shortcutxl";
1044
+
1045
+ shortcut.registerCommand("deploy", {
1046
+ description: "Deploy to an environment",
1047
+ getArgumentCompletions: (prefix: string): AutocompleteItem[] | null => {
1048
+ const envs = ["dev", "staging", "prod"];
1049
+ const items = envs.map((e) => ({ value: e, label: e }));
1050
+ const filtered = items.filter((i) => i.value.startsWith(prefix));
1051
+ return filtered.length > 0 ? filtered : null;
1052
+ },
1053
+ handler: async (args, ctx) => {
1054
+ ctx.ui.notify(`Deploying: ${args}`, "info");
1055
+ },
1056
+ });
1057
+ ```
1058
+
1059
+ ### shortcut.getCommands()
1060
+
1061
+ Get the slash commands available for invocation via `prompt` in the current session. Includes extension commands, prompt templates, and skill commands.
1062
+ The list matches the RPC `get_commands` ordering: extensions first, then templates, then skills.
1063
+
1064
+ ```typescript
1065
+ const commands = shortcut.getCommands();
1066
+ const bySource = commands.filter((command) => command.source === "extension");
1067
+ ```
1068
+
1069
+ Each entry has this shape:
1070
+
1071
+ ```typescript
1072
+ {
1073
+ name: string; // Command name without the leading slash
1074
+ description?: string;
1075
+ source: "extension" | "prompt" | "skill";
1076
+ location?: "user" | "project" | "path"; // For templates and skills
1077
+ path?: string; // Files backing templates, skills, and extensions
1078
+ }
1079
+ ```
1080
+
1081
+ Built-in interactive commands (like `/model` and `/settings`) are not included here. They are handled only in interactive
1082
+ mode and would not execute if sent via `prompt`.
1083
+
1084
+ ### shortcut.registerMessageRenderer(customType, renderer)
1085
+
1086
+ Register a custom TUI renderer for messages with your `customType`. See [Custom UI](#custom-ui).
1087
+
1088
+ ### shortcut.registerShortcut(shortcut, options)
1089
+
1090
+ Register a keyboard shortcut. See [keybindings.md](keybindings.md) for the shortcut format and built-in keybindings.
1091
+
1092
+ ```typescript
1093
+ shortcut.registerShortcut("ctrl+shift+p", {
1094
+ description: "Toggle plan mode",
1095
+ handler: async (ctx) => {
1096
+ ctx.ui.notify("Toggled!");
1097
+ },
1098
+ });
1099
+ ```
1100
+
1101
+ ### shortcut.registerFlag(name, options)
1102
+
1103
+ Register a CLI flag.
1104
+
1105
+ ```typescript
1106
+ shortcut.registerFlag("plan", {
1107
+ description: "Start in plan mode",
1108
+ type: "boolean",
1109
+ default: false,
1110
+ });
1111
+
1112
+ // Check value
1113
+ if (shortcut.getFlag("--plan")) {
1114
+ // Plan mode enabled
1115
+ }
1116
+ ```
1117
+
1118
+ ### shortcut.exec(command, args, options?)
1119
+
1120
+ Execute a shell command.
1121
+
1122
+ ```typescript
1123
+ const result = await shortcut.exec("git", ["status"], { signal, timeout: 5000 });
1124
+ // result.stdout, result.stderr, result.code, result.killed
1125
+ ```
1126
+
1127
+ ### shortcut.getActiveTools() / shortcut.getAllTools() / shortcut.setActiveTools(names)
1128
+
1129
+ Manage active tools. This works for both built-in tools and dynamically registered tools.
1130
+
1131
+ ```typescript
1132
+ const active = shortcut.getActiveTools(); // ["read", "bash", "edit", "write"]
1133
+ const all = shortcut.getAllTools(); // [{ name: "read", description: "Read file contents..." }, ...]
1134
+ const names = all.map(t => t.name); // Just names if needed
1135
+ shortcut.setActiveTools(["read", "bash"]); // Switch to read-only
1136
+ ```
1137
+
1138
+ ### shortcut.setModel(model)
1139
+
1140
+ Set the current model. Returns `false` if no API key is available for the model. See [models.md](models.md) for configuring custom models.
1141
+
1142
+ ```typescript
1143
+ const model = ctx.modelRegistry.find("anthropic", "claude-sonnet-4-5");
1144
+ if (model) {
1145
+ const success = await shortcut.setModel(model);
1146
+ if (!success) {
1147
+ ctx.ui.notify("No API key for this model", "error");
1148
+ }
1149
+ }
1150
+ ```
1151
+
1152
+ ### shortcut.getThinkingLevel() / shortcut.setThinkingLevel(level)
1153
+
1154
+ Get or set the thinking level. Level is clamped to model capabilities (non-reasoning models always use "off").
1155
+
1156
+ ```typescript
1157
+ const current = shortcut.getThinkingLevel(); // "off" | "minimal" | "low" | "medium" | "high" | "xhigh"
1158
+ shortcut.setThinkingLevel("high");
1159
+ ```
1160
+
1161
+ ### shortcut.events
1162
+
1163
+ Shared event bus for communication between extensions:
1164
+
1165
+ ```typescript
1166
+ shortcut.events.on("my:event", (data) => { ... });
1167
+ shortcut.events.emit("my:event", { ... });
1168
+ ```
1169
+
1170
+ ### shortcut.registerProvider(name, config)
1171
+
1172
+ Register or override a model provider dynamically. Useful for proxies, custom endpoints, or team-wide model configurations.
1173
+
1174
+ Calls made during the extension factory function are queued and applied once the runner initialises. Calls made after that — for example from a command handler following a user setup flow — take effect immediately without requiring a `/reload`.
1175
+
1176
+ ```typescript
1177
+ // Register a new provider with custom models
1178
+ shortcut.registerProvider("my-proxy", {
1179
+ baseUrl: "https://proxy.example.com",
1180
+ apiKey: "PROXY_API_KEY", // env var name or literal
1181
+ api: "anthropic-messages",
1182
+ models: [
1183
+ {
1184
+ id: "claude-sonnet-4-20250514",
1185
+ name: "Claude 4 Sonnet (proxy)",
1186
+ reasoning: false,
1187
+ input: ["text", "image"],
1188
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
1189
+ contextWindow: 200000,
1190
+ maxTokens: 16384
1191
+ }
1192
+ ]
1193
+ });
1194
+
1195
+ // Override baseUrl for an existing provider (keeps all models)
1196
+ shortcut.registerProvider("anthropic", {
1197
+ baseUrl: "https://proxy.example.com"
1198
+ });
1199
+
1200
+ // Register provider with OAuth support for /login
1201
+ shortcut.registerProvider("corporate-ai", {
1202
+ baseUrl: "https://ai.corp.com",
1203
+ api: "openai-responses",
1204
+ models: [...],
1205
+ oauth: {
1206
+ name: "Corporate AI (SSO)",
1207
+ async login(callbacks) {
1208
+ // Custom OAuth flow
1209
+ callbacks.onAuth({ url: "https://sso.corp.com/..." });
1210
+ const code = await callbacks.onPrompt({ message: "Enter code:" });
1211
+ return { refresh: code, access: code, expires: Date.now() + 3600000 };
1212
+ },
1213
+ async refreshToken(credentials) {
1214
+ // Refresh logic
1215
+ return credentials;
1216
+ },
1217
+ getApiKey(credentials) {
1218
+ return credentials.access;
1219
+ }
1220
+ }
1221
+ });
1222
+ ```
1223
+
1224
+ **Config options:**
1225
+ - `baseUrl` - API endpoint URL. Required when defining models.
1226
+ - `apiKey` - API key or environment variable name. Required when defining models (unless `oauth` provided).
1227
+ - `api` - API type: `"anthropic-messages"`, `"openai-completions"`, `"openai-responses"`, etc.
1228
+ - `headers` - Custom headers to include in requests.
1229
+ - `authHeader` - If true, adds `Authorization: Bearer` header automatically.
1230
+ - `models` - Array of model definitions. If provided, replaces all existing models for this provider.
1231
+ - `oauth` - OAuth provider config for `/login` support. When provided, the provider appears in the login menu.
1232
+ - `streamSimple` - Custom streaming implementation for non-standard APIs.
1233
+
1234
+ See [custom-provider.md](custom-provider.md) for advanced topics: custom streaming APIs, OAuth details, model definition reference.
1235
+
1236
+ ### shortcut.unregisterProvider(name)
1237
+
1238
+ Remove a previously registered provider and its models. Built-in models that were overridden by the provider are restored. Has no effect if the provider was not registered.
1239
+
1240
+ Like `registerProvider`, this takes effect immediately when called after the initial load phase, so a `/reload` is not required.
1241
+
1242
+ ```typescript
1243
+ shortcut.registerCommand("my-setup-teardown", {
1244
+ description: "Remove the custom proxy provider",
1245
+ handler: async (_args, _ctx) => {
1246
+ shortcut.unregisterProvider("my-proxy");
1247
+ },
1248
+ });
1249
+ ```
1250
+
1251
+ ## State Management
1252
+
1253
+ Extensions with state should store it in tool result `details` for proper branching support:
1254
+
1255
+ ```typescript
1256
+ export default function (shortcut: ExtensionAPI) {
1257
+ let items: string[] = [];
1258
+
1259
+ // Reconstruct state from session
1260
+ shortcut.on("session_start", async (_event, ctx) => {
1261
+ items = [];
1262
+ for (const entry of ctx.sessionManager.getBranch()) {
1263
+ if (entry.type === "message" && entry.message.role === "toolResult") {
1264
+ if (entry.message.toolName === "my_tool") {
1265
+ items = entry.message.details?.items ?? [];
1266
+ }
1267
+ }
1268
+ }
1269
+ });
1270
+
1271
+ shortcut.registerTool({
1272
+ name: "my_tool",
1273
+ // ...
1274
+ async execute(toolCallId, params, signal, onUpdate, ctx) {
1275
+ items.push("new item");
1276
+ return {
1277
+ content: [{ type: "text", text: "Added" }],
1278
+ details: { items: [...items] }, // Store for reconstruction
1279
+ };
1280
+ },
1281
+ });
1282
+ }
1283
+ ```
1284
+
1285
+ ## Custom Tools
1286
+
1287
+ Register tools the LLM can call via `shortcut.registerTool()`. Tools appear in the system prompt and can have custom rendering.
1288
+
1289
+ Use `promptSnippet` for a short one-line entry in the `Available tools` section in the default system prompt. If omitted, Shortcut falls back to `description`.
1290
+
1291
+ 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 `shortcut.setActiveTools([...])`).
1292
+
1293
+ Note: Some models are idiots and 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.
1294
+
1295
+ ### Tool Definition
1296
+
1297
+ ```typescript
1298
+ import { Type } from "@sinclair/typebox";
1299
+ import { StringEnum } from "shortcutxl";
1300
+ import { Text } from "shortcutxl";
1301
+
1302
+ shortcut.registerTool({
1303
+ name: "my_tool",
1304
+ label: "My Tool",
1305
+ description: "What this tool does (shown to LLM)",
1306
+ promptSnippet: "List or add items in the project todo list",
1307
+ promptGuidelines: [
1308
+ "Use this tool for todo planning instead of direct file edits when the user asks for a task list."
1309
+ ],
1310
+ parameters: Type.Object({
1311
+ action: StringEnum(["list", "add"] as const), // Use StringEnum for Google compatibility
1312
+ text: Type.Optional(Type.String()),
1313
+ }),
1314
+
1315
+ async execute(toolCallId, params, signal, onUpdate, ctx) {
1316
+ // Check for cancellation
1317
+ if (signal?.aborted) {
1318
+ return { content: [{ type: "text", text: "Cancelled" }] };
1319
+ }
1320
+
1321
+ // Stream progress updates
1322
+ onUpdate?.({
1323
+ content: [{ type: "text", text: "Working..." }],
1324
+ details: { progress: 50 },
1325
+ });
1326
+
1327
+ // Run commands via shortcut.exec (captured from extension closure)
1328
+ const result = await shortcut.exec("some-command", [], { signal });
1329
+
1330
+ // Return result
1331
+ return {
1332
+ content: [{ type: "text", text: "Done" }], // Sent to LLM
1333
+ details: { data: result }, // For rendering & state
1334
+ };
1335
+ },
1336
+
1337
+ // Optional: Custom rendering
1338
+ renderCall(args, theme) { ... },
1339
+ renderResult(result, options, theme) { ... },
1340
+ });
1341
+ ```
1342
+
1343
+ **Important:** Use `StringEnum` from `shortcutxl` for string enums. `Type.Union`/`Type.Literal` doesn't work with Google's API.
1344
+
1345
+ ### Overriding Built-in Tools
1346
+
1347
+ Extensions can override built-in tools (`read`, `bash`, `edit`, `write`, `grep`, `find`, `ls`) by registering a tool with the same name. Interactive mode displays a warning when this happens.
1348
+
1349
+ ```bash
1350
+ # Extension's read tool replaces built-in read
1351
+ shortcut -e ./tool-override.ts
1352
+ ```
1353
+
1354
+ Alternatively, use `--no-tools` to start without any built-in tools:
1355
+ ```bash
1356
+ # No built-in tools, only extension tools
1357
+ shortcut --no-tools -e ./my-extension.ts
1358
+ ```
1359
+
1360
+ See [examples/extensions/tool-override.ts](../examples/extensions/tool-override.ts) for a complete example that overrides `read` with logging and access control.
1361
+
1362
+ **Rendering:** If your override doesn't provide custom `renderCall`/`renderResult` functions, the built-in renderer is used automatically (syntax highlighting, diffs, etc.). This lets you wrap built-in tools for logging or access control without reimplementing the UI.
1363
+
1364
+ **Your implementation must match the exact result shape**, including the `details` type. The UI and session logic depend on these shapes for rendering and state tracking.
1365
+
1366
+ Built-in tool implementations:
1367
+ - [read.ts](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/src/core/tools/read.ts) - `ReadToolDetails`
1368
+ - [bash.ts](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/src/core/tools/bash.ts) - `BashToolDetails`
1369
+ - [edit.ts](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/src/core/tools/edit.ts)
1370
+ - [write.ts](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/src/core/tools/write.ts)
1371
+ - [grep.ts](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/src/core/tools/grep.ts) - `GrepToolDetails`
1372
+ - [find.ts](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/src/core/tools/find.ts) - `FindToolDetails`
1373
+ - [ls.ts](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/src/core/tools/ls.ts) - `LsToolDetails`
1374
+
1375
+ ### Remote Execution
1376
+
1377
+ Built-in tools support pluggable operations for delegating to remote systems (SSH, containers, etc.):
1378
+
1379
+ ```typescript
1380
+ import { createReadTool, createBashTool, type ReadOperations } from "shortcutxl";
1381
+
1382
+ // Create tool with custom operations
1383
+ const remoteRead = createReadTool(cwd, {
1384
+ operations: {
1385
+ readFile: (path) => sshExec(remote, `cat ${path}`),
1386
+ access: (path) => sshExec(remote, `test -r ${path}`).then(() => {}),
1387
+ }
1388
+ });
1389
+
1390
+ // Register, checking flag at execution time
1391
+ shortcut.registerTool({
1392
+ ...remoteRead,
1393
+ async execute(id, params, signal, onUpdate, _ctx) {
1394
+ const ssh = getSshConfig();
1395
+ if (ssh) {
1396
+ const tool = createReadTool(cwd, { operations: createRemoteOps(ssh) });
1397
+ return tool.execute(id, params, signal, onUpdate);
1398
+ }
1399
+ return localRead.execute(id, params, signal, onUpdate);
1400
+ },
1401
+ });
1402
+ ```
1403
+
1404
+ **Operations interfaces:** `ReadOperations`, `WriteOperations`, `EditOperations`, `BashOperations`, `LsOperations`, `GrepOperations`, `FindOperations`
1405
+
1406
+ The bash tool also supports a spawn hook to adjust the command, cwd, or env before execution:
1407
+
1408
+ ```typescript
1409
+ import { createBashTool } from "shortcutxl";
1410
+
1411
+ const bashTool = createBashTool(cwd, {
1412
+ spawnHook: ({ command, cwd, env }) => ({
1413
+ command: `source ~/.profile\n${command}`,
1414
+ cwd: `/mnt/sandbox${cwd}`,
1415
+ env: { ...env, CI: "1" },
1416
+ }),
1417
+ });
1418
+ ```
1419
+
1420
+ See [examples/extensions/ssh.ts](../examples/extensions/ssh.ts) for a complete SSH example with `--ssh` flag.
1421
+
1422
+ ### Output Truncation
1423
+
1424
+ **Tools MUST truncate their output** to avoid overwhelming the LLM context. Large outputs can cause:
1425
+ - Context overflow errors (prompt too long)
1426
+ - Compaction failures
1427
+ - Degraded model performance
1428
+
1429
+ The built-in limit is **50KB** (~10k tokens) and **2000 lines**, whichever is hit first. Use the exported truncation utilities:
1430
+
1431
+ ```typescript
1432
+ import {
1433
+ truncateHead, // Keep first N lines/bytes (good for file reads, search results)
1434
+ truncateTail, // Keep last N lines/bytes (good for logs, command output)
1435
+ truncateLine, // Truncate a single line to maxBytes with ellipsis
1436
+ formatSize, // Human-readable size (e.g., "50KB", "1.5MB")
1437
+ DEFAULT_MAX_BYTES, // 50KB
1438
+ DEFAULT_MAX_LINES, // 2000
1439
+ } from "shortcutxl";
1440
+
1441
+ async execute(toolCallId, params, signal, onUpdate, ctx) {
1442
+ const output = await runCommand();
1443
+
1444
+ // Apply truncation
1445
+ const truncation = truncateHead(output, {
1446
+ maxLines: DEFAULT_MAX_LINES,
1447
+ maxBytes: DEFAULT_MAX_BYTES,
1448
+ });
1449
+
1450
+ let result = truncation.content;
1451
+
1452
+ if (truncation.truncated) {
1453
+ // Write full output to temp file
1454
+ const tempFile = writeTempFile(output);
1455
+
1456
+ // Inform the LLM where to find complete output
1457
+ result += `\n\n[Output truncated: ${truncation.outputLines} of ${truncation.totalLines} lines`;
1458
+ result += ` (${formatSize(truncation.outputBytes)} of ${formatSize(truncation.totalBytes)}).`;
1459
+ result += ` Full output saved to: ${tempFile}]`;
1460
+ }
1461
+
1462
+ return { content: [{ type: "text", text: result }] };
1463
+ }
1464
+ ```
1465
+
1466
+ **Key points:**
1467
+ - Use `truncateHead` for content where the beginning matters (search results, file reads)
1468
+ - Use `truncateTail` for content where the end matters (logs, command output)
1469
+ - Always inform the LLM when output is truncated and where to find the full version
1470
+ - Document the truncation limits in your tool's description
1471
+
1472
+ See [examples/extensions/truncated-tool.ts](../examples/extensions/truncated-tool.ts) for a complete example wrapping `rg` (ripgrep) with proper truncation.
1473
+
1474
+ ### Multiple Tools
1475
+
1476
+ One extension can register multiple tools with shared state:
1477
+
1478
+ ```typescript
1479
+ export default function (shortcut: ExtensionAPI) {
1480
+ let connection = null;
1481
+
1482
+ shortcut.registerTool({ name: "db_connect", ... });
1483
+ shortcut.registerTool({ name: "db_query", ... });
1484
+ shortcut.registerTool({ name: "db_close", ... });
1485
+
1486
+ shortcut.on("session_shutdown", async () => {
1487
+ connection?.close();
1488
+ });
1489
+ }
1490
+ ```
1491
+
1492
+ ### Custom Rendering
1493
+
1494
+ Tools can provide `renderCall` and `renderResult` for custom TUI display. See [tui.md](tui.md) for the full component API and [tool-execution.ts](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/src/modes/interactive/components/tool-execution.ts) for how built-in tools render.
1495
+
1496
+ Tool output is wrapped in a `Box` that handles padding and background. Your render methods return `Component` instances (typically `Text`).
1497
+
1498
+ #### renderCall
1499
+
1500
+ Renders the tool call (before/during execution):
1501
+
1502
+ ```typescript
1503
+ import { Text } from "shortcutxl";
1504
+
1505
+ renderCall(args, theme) {
1506
+ let text = theme.fg("toolTitle", theme.bold("my_tool "));
1507
+ text += theme.fg("muted", args.action);
1508
+ if (args.text) {
1509
+ text += " " + theme.fg("dim", `"${args.text}"`);
1510
+ }
1511
+ return new Text(text, 0, 0); // 0,0 padding - Box handles it
1512
+ }
1513
+ ```
1514
+
1515
+ #### renderResult
1516
+
1517
+ Renders the tool result:
1518
+
1519
+ ```typescript
1520
+ renderResult(result, { expanded, isPartial }, theme) {
1521
+ // Handle streaming
1522
+ if (isPartial) {
1523
+ return new Text(theme.fg("warning", "Processing..."), 0, 0);
1524
+ }
1525
+
1526
+ // Handle errors
1527
+ if (result.details?.error) {
1528
+ return new Text(theme.fg("error", `Error: ${result.details.error}`), 0, 0);
1529
+ }
1530
+
1531
+ // Normal result - support expanded view (Ctrl+O)
1532
+ let text = theme.fg("success", "✓ Done");
1533
+ if (expanded && result.details?.items) {
1534
+ for (const item of result.details.items) {
1535
+ text += "\n " + theme.fg("dim", item);
1536
+ }
1537
+ }
1538
+ return new Text(text, 0, 0);
1539
+ }
1540
+ ```
1541
+
1542
+ #### Keybinding Hints
1543
+
1544
+ Use `keyHint()` to display keybinding hints that respect user's keybinding configuration:
1545
+
1546
+ ```typescript
1547
+ import { keyHint } from "shortcutxl";
1548
+
1549
+ renderResult(result, { expanded }, theme) {
1550
+ let text = theme.fg("success", "✓ Done");
1551
+ if (!expanded) {
1552
+ text += ` (${keyHint("expandTools", "to expand")})`;
1553
+ }
1554
+ return new Text(text, 0, 0);
1555
+ }
1556
+ ```
1557
+
1558
+ Available functions:
1559
+ - `keyHint(action, description)` - Editor actions (e.g., `"expandTools"`, `"selectConfirm"`)
1560
+ - `appKeyHint(keybindings, action, description)` - App actions (requires `KeybindingsManager`)
1561
+ - `editorKey(action)` - Get raw key string for editor action
1562
+ - `rawKeyHint(key, description)` - Format a raw key string
1563
+
1564
+ #### Best Practices
1565
+
1566
+ - Use `Text` with padding `(0, 0)` - the Box handles padding
1567
+ - Use `\n` for multi-line content
1568
+ - Handle `isPartial` for streaming progress
1569
+ - Support `expanded` for detail on demand
1570
+ - Keep default view compact
1571
+
1572
+ #### Fallback
1573
+
1574
+ If `renderCall`/`renderResult` is not defined or throws:
1575
+ - `renderCall`: Shows tool name
1576
+ - `renderResult`: Shows raw text from `content`
1577
+
1578
+ ## Custom UI
1579
+
1580
+ Extensions can interact with users via `ctx.ui` methods and customize how messages/tools render.
1581
+
1582
+ **For custom components, see [tui.md](tui.md)** which has copy-paste patterns for:
1583
+ - Selection dialogs (SelectList)
1584
+ - Async operations with cancel (BorderedLoader)
1585
+ - Settings toggles (SettingsList)
1586
+ - Status indicators (setStatus)
1587
+ - Working message during streaming (setWorkingMessage)
1588
+ - Widgets above/below editor (setWidget)
1589
+ - Custom footers (setFooter)
1590
+
1591
+ ### Dialogs
1592
+
1593
+ ```typescript
1594
+ // Select from options
1595
+ const choice = await ctx.ui.select("Pick one:", ["A", "B", "C"]);
1596
+
1597
+ // Confirm dialog
1598
+ const ok = await ctx.ui.confirm("Delete?", "This cannot be undone");
1599
+
1600
+ // Text input
1601
+ const name = await ctx.ui.input("Name:", "placeholder");
1602
+
1603
+ // Multi-line editor
1604
+ const text = await ctx.ui.editor("Edit:", "prefilled text");
1605
+
1606
+ // Notification (non-blocking)
1607
+ ctx.ui.notify("Done!", "info"); // "info" | "warning" | "error"
1608
+ ```
1609
+
1610
+ #### Timed Dialogs with Countdown
1611
+
1612
+ Dialogs support a `timeout` option that auto-dismisses with a live countdown display:
1613
+
1614
+ ```typescript
1615
+ // Dialog shows "Title (5s)" → "Title (4s)" → ... → auto-dismisses at 0
1616
+ const confirmed = await ctx.ui.confirm(
1617
+ "Timed Confirmation",
1618
+ "This dialog will auto-cancel in 5 seconds. Confirm?",
1619
+ { timeout: 5000 }
1620
+ );
1621
+
1622
+ if (confirmed) {
1623
+ // User confirmed
1624
+ } else {
1625
+ // User cancelled or timed out
1626
+ }
1627
+ ```
1628
+
1629
+ **Return values on timeout:**
1630
+ - `select()` returns `undefined`
1631
+ - `confirm()` returns `false`
1632
+ - `input()` returns `undefined`
1633
+
1634
+ #### Manual Dismissal with AbortSignal
1635
+
1636
+ For more control (e.g., to distinguish timeout from user cancel), use `AbortSignal`:
1637
+
1638
+ ```typescript
1639
+ const controller = new AbortController();
1640
+ const timeoutId = setTimeout(() => controller.abort(), 5000);
1641
+
1642
+ const confirmed = await ctx.ui.confirm(
1643
+ "Timed Confirmation",
1644
+ "This dialog will auto-cancel in 5 seconds. Confirm?",
1645
+ { signal: controller.signal }
1646
+ );
1647
+
1648
+ clearTimeout(timeoutId);
1649
+
1650
+ if (confirmed) {
1651
+ // User confirmed
1652
+ } else if (controller.signal.aborted) {
1653
+ // Dialog timed out
1654
+ } else {
1655
+ // User cancelled (pressed Escape or selected "No")
1656
+ }
1657
+ ```
1658
+
1659
+ See [examples/extensions/timed-confirm.ts](../examples/extensions/timed-confirm.ts) for complete examples.
1660
+
1661
+ ### Widgets, Status, and Footer
1662
+
1663
+ ```typescript
1664
+ // Status in footer (persistent until cleared)
1665
+ ctx.ui.setStatus("my-ext", "Processing...");
1666
+ ctx.ui.setStatus("my-ext", undefined); // Clear
1667
+
1668
+ // Working message (shown during streaming)
1669
+ ctx.ui.setWorkingMessage("Thinking deeply...");
1670
+ ctx.ui.setWorkingMessage(); // Restore default
1671
+
1672
+ // Widget above editor (default)
1673
+ ctx.ui.setWidget("my-widget", ["Line 1", "Line 2"]);
1674
+ // Widget below editor
1675
+ ctx.ui.setWidget("my-widget", ["Line 1", "Line 2"], { placement: "belowEditor" });
1676
+ ctx.ui.setWidget("my-widget", (tui, theme) => new Text(theme.fg("accent", "Custom"), 0, 0));
1677
+ ctx.ui.setWidget("my-widget", undefined); // Clear
1678
+
1679
+ // Custom footer (replaces built-in footer entirely)
1680
+ ctx.ui.setFooter((tui, theme) => ({
1681
+ render(width) { return [theme.fg("dim", "Custom footer")]; },
1682
+ invalidate() {},
1683
+ }));
1684
+ ctx.ui.setFooter(undefined); // Restore built-in footer
1685
+
1686
+ // Terminal title
1687
+ ctx.ui.setTitle("shortcut - my-project");
1688
+
1689
+ // Editor text
1690
+ ctx.ui.setEditorText("Prefill text");
1691
+ const current = ctx.ui.getEditorText();
1692
+
1693
+ // Paste into editor (triggers paste handling, including collapse for large content)
1694
+ ctx.ui.pasteToEditor("pasted content");
1695
+
1696
+ // Tool output expansion
1697
+ const wasExpanded = ctx.ui.getToolsExpanded();
1698
+ ctx.ui.setToolsExpanded(true);
1699
+ ctx.ui.setToolsExpanded(wasExpanded);
1700
+
1701
+ // Custom editor (vim mode, emacs mode, etc.)
1702
+ ctx.ui.setEditorComponent((tui, theme, keybindings) => new VimEditor(tui, theme, keybindings));
1703
+ ctx.ui.setEditorComponent(undefined); // Restore default editor
1704
+
1705
+ // Theme management (see themes.md for creating themes)
1706
+ const themes = ctx.ui.getAllThemes(); // [{ name: "dark", path: "/..." | undefined }, ...]
1707
+ const lightTheme = ctx.ui.getTheme("light"); // Load without switching
1708
+ const result = ctx.ui.setTheme("light"); // Switch by name
1709
+ if (!result.success) {
1710
+ ctx.ui.notify(`Failed: ${result.error}`, "error");
1711
+ }
1712
+ ctx.ui.setTheme(lightTheme!); // Or switch by Theme object
1713
+ ctx.ui.theme.fg("accent", "styled text"); // Access current theme
1714
+ ```
1715
+
1716
+ ### Custom Components
1717
+
1718
+ For complex UI, use `ctx.ui.custom()`. This temporarily replaces the editor with your component until `done()` is called:
1719
+
1720
+ ```typescript
1721
+ import { Text, Component } from "shortcutxl";
1722
+
1723
+ const result = await ctx.ui.custom<boolean>((tui, theme, keybindings, done) => {
1724
+ const text = new Text("Press Enter to confirm, Escape to cancel", 1, 1);
1725
+
1726
+ text.onKey = (key) => {
1727
+ if (key === "return") done(true);
1728
+ if (key === "escape") done(false);
1729
+ return true;
1730
+ };
1731
+
1732
+ return text;
1733
+ });
1734
+
1735
+ if (result) {
1736
+ // User pressed Enter
1737
+ }
1738
+ ```
1739
+
1740
+ The callback receives:
1741
+ - `tui` - TUI instance (for screen dimensions, focus management)
1742
+ - `theme` - Current theme for styling
1743
+ - `keybindings` - App keybinding manager (for checking shortcuts)
1744
+ - `done(value)` - Call to close component and return value
1745
+
1746
+ See [tui.md](tui.md) for the full component API.
1747
+
1748
+ #### Overlay Mode (Experimental)
1749
+
1750
+ Pass `{ overlay: true }` to render the component as a floating modal on top of existing content, without clearing the screen:
1751
+
1752
+ ```typescript
1753
+ const result = await ctx.ui.custom<string | null>(
1754
+ (tui, theme, keybindings, done) => new MyOverlayComponent({ onClose: done }),
1755
+ { overlay: true }
1756
+ );
1757
+ ```
1758
+
1759
+ For advanced positioning (anchors, margins, percentages, responsive visibility), pass `overlayOptions`. Use `onHandle` to control visibility programmatically:
1760
+
1761
+ ```typescript
1762
+ const result = await ctx.ui.custom<string | null>(
1763
+ (tui, theme, keybindings, done) => new MyOverlayComponent({ onClose: done }),
1764
+ {
1765
+ overlay: true,
1766
+ overlayOptions: { anchor: "top-right", width: "50%", margin: 2 },
1767
+ onHandle: (handle) => { /* handle.setHidden(true/false) */ }
1768
+ }
1769
+ );
1770
+ ```
1771
+
1772
+ See [tui.md](tui.md) for the full `OverlayOptions` API and [overlay-qa-tests.ts](../examples/extensions/overlay-qa-tests.ts) for examples.
1773
+
1774
+ ### Custom Editor
1775
+
1776
+ Replace the main input editor with a custom implementation (vim mode, emacs mode, etc.):
1777
+
1778
+ ```typescript
1779
+ import { CustomEditor, type ExtensionAPI } from "shortcutxl";
1780
+ import { matchesKey } from "shortcutxl";
1781
+
1782
+ class VimEditor extends CustomEditor {
1783
+ private mode: "normal" | "insert" = "insert";
1784
+
1785
+ handleInput(data: string): void {
1786
+ if (matchesKey(data, "escape") && this.mode === "insert") {
1787
+ this.mode = "normal";
1788
+ return;
1789
+ }
1790
+ if (this.mode === "normal" && data === "i") {
1791
+ this.mode = "insert";
1792
+ return;
1793
+ }
1794
+ super.handleInput(data); // App keybindings + text editing
1795
+ }
1796
+ }
1797
+
1798
+ export default function (shortcut: ExtensionAPI) {
1799
+ shortcut.on("session_start", (_event, ctx) => {
1800
+ ctx.ui.setEditorComponent((_tui, theme, keybindings) =>
1801
+ new VimEditor(theme, keybindings)
1802
+ );
1803
+ });
1804
+ }
1805
+ ```
1806
+
1807
+ **Key points:**
1808
+ - Extend `CustomEditor` (not base `Editor`) to get app keybindings (escape to abort, ctrl+d, model switching)
1809
+ - Call `super.handleInput(data)` for keys you don't handle
1810
+ - Factory receives `theme` and `keybindings` from the app
1811
+ - Pass `undefined` to restore default: `ctx.ui.setEditorComponent(undefined)`
1812
+
1813
+ See [tui.md](tui.md) Pattern 7 for a complete example with mode indicator.
1814
+
1815
+ ### Message Rendering
1816
+
1817
+ Register a custom renderer for messages with your `customType`:
1818
+
1819
+ ```typescript
1820
+ import { Text } from "shortcutxl";
1821
+
1822
+ shortcut.registerMessageRenderer("my-extension", (message, options, theme) => {
1823
+ const { expanded } = options;
1824
+ let text = theme.fg("accent", `[${message.customType}] `);
1825
+ text += message.content;
1826
+
1827
+ if (expanded && message.details) {
1828
+ text += "\n" + theme.fg("dim", JSON.stringify(message.details, null, 2));
1829
+ }
1830
+
1831
+ return new Text(text, 0, 0);
1832
+ });
1833
+ ```
1834
+
1835
+ Messages are sent via `shortcut.sendMessage()`:
1836
+
1837
+ ```typescript
1838
+ shortcut.sendMessage({
1839
+ customType: "my-extension", // Matches registerMessageRenderer
1840
+ content: "Status update",
1841
+ display: true, // Show in TUI
1842
+ details: { ... }, // Available in renderer
1843
+ });
1844
+ ```
1845
+
1846
+ ### Theme Colors
1847
+
1848
+ All render functions receive a `theme` object. See [themes.md](themes.md) for creating custom themes and the full color palette.
1849
+
1850
+ ```typescript
1851
+ // Foreground colors
1852
+ theme.fg("toolTitle", text) // Tool names
1853
+ theme.fg("accent", text) // Highlights
1854
+ theme.fg("success", text) // Success (green)
1855
+ theme.fg("error", text) // Errors (red)
1856
+ theme.fg("warning", text) // Warnings (yellow)
1857
+ theme.fg("muted", text) // Secondary text
1858
+ theme.fg("dim", text) // Tertiary text
1859
+
1860
+ // Text styles
1861
+ theme.bold(text)
1862
+ theme.italic(text)
1863
+ theme.strikethrough(text)
1864
+ ```
1865
+
1866
+ For syntax highlighting in custom tool renderers:
1867
+
1868
+ ```typescript
1869
+ import { highlightCode, getLanguageFromPath } from "shortcutxl";
1870
+
1871
+ // Highlight code with explicit language
1872
+ const highlighted = highlightCode("const x = 1;", "typescript", theme);
1873
+
1874
+ // Auto-detect language from file path
1875
+ const lang = getLanguageFromPath("/path/to/file.rs"); // "rust"
1876
+ const highlighted = highlightCode(code, lang, theme);
1877
+ ```
1878
+
1879
+ ## Error Handling
1880
+
1881
+ - Extension errors are logged, agent continues
1882
+ - `tool_call` errors block the tool (fail-safe)
1883
+ - Tool `execute` errors are reported to the LLM with `isError: true`
1884
+
1885
+ ## Mode Behavior
1886
+
1887
+ | Mode | UI Methods | Notes |
1888
+ |------|-----------|-------|
1889
+ | Interactive | Full TUI | Normal operation |
1890
+ | RPC (`--mode rpc`) | JSON protocol | Host handles UI, see [rpc.md](rpc.md) |
1891
+ | JSON (`--mode json`) | No-op | Event stream to stdout, see [json.md](json.md) |
1892
+ | Print (`-p`) | No-op | Extensions run but can't prompt |
1893
+
1894
+ In non-interactive modes, check `ctx.hasUI` before using UI methods.
1895
+
1896
+ ## Examples Reference
1897
+
1898
+ All examples in [examples/extensions/](../examples/extensions/).
1899
+
1900
+ | Example | Description | Key APIs |
1901
+ |---------|-------------|----------|
1902
+ | **Tools** |||
1903
+ | `hello.ts` | Minimal tool registration | `registerTool` |
1904
+ | `question.ts` | Tool with user interaction | `registerTool`, `ui.select` |
1905
+ | `questionnaire.ts` | Multi-step wizard tool | `registerTool`, `ui.custom` |
1906
+ | `todo.ts` | Stateful tool with persistence | `registerTool`, `appendEntry`, `renderResult`, session events |
1907
+ | `dynamic-tools.ts` | Register tools after startup and during commands | `registerTool`, `session_start`, `registerCommand` |
1908
+ | `truncated-tool.ts` | Output truncation example | `registerTool`, `truncateHead` |
1909
+ | `tool-override.ts` | Override built-in read tool | `registerTool` (same name as built-in) |
1910
+ | **Commands** |||
1911
+ | `pirate.ts` | Modify system prompt per-turn | `registerCommand`, `before_agent_start` |
1912
+ | `summarize.ts` | Conversation summary command | `registerCommand`, `ui.custom` |
1913
+ | `handoff.ts` | Cross-provider model handoff | `registerCommand`, `ui.editor`, `ui.custom` |
1914
+ | `qna.ts` | Q&A with custom UI | `registerCommand`, `ui.custom`, `setEditorText` |
1915
+ | `send-user-message.ts` | Inject user messages | `registerCommand`, `sendUserMessage` |
1916
+ | `reload-runtime.ts` | Reload command and LLM tool handoff | `registerCommand`, `ctx.reload()`, `sendUserMessage` |
1917
+ | `shutdown-command.ts` | Graceful shutdown command | `registerCommand`, `shutdown()` |
1918
+ | **Events & Gates** |||
1919
+ | `permission-gate.ts` | Block dangerous commands | `on("tool_call")`, `ui.confirm` |
1920
+ | `protected-paths.ts` | Block writes to specific paths | `on("tool_call")` |
1921
+ | `confirm-destructive.ts` | Confirm session changes | `on("session_before_switch")`, `on("session_before_fork")` |
1922
+ | `dirty-repo-guard.ts` | Warn on dirty git repo | `on("session_before_*")`, `exec` |
1923
+ | `input-transform.ts` | Transform user input | `on("input")` |
1924
+ | `model-status.ts` | React to model changes | `on("model_select")`, `setStatus` |
1925
+ | `system-prompt-header.ts` | Display system prompt info | `on("agent_start")`, `getSystemPrompt` |
1926
+ | `claude-rules.ts` | Load rules from files | `on("session_start")`, `on("before_agent_start")` |
1927
+ | `file-trigger.ts` | File watcher triggers messages | `sendMessage` |
1928
+ | **Compaction & Sessions** |||
1929
+ | `custom-compaction.ts` | Custom compaction summary | `on("session_before_compact")` |
1930
+ | `trigger-compact.ts` | Trigger compaction manually | `compact()` |
1931
+ | `git-checkpoint.ts` | Git stash on turns | `on("turn_end")`, `on("session_fork")`, `exec` |
1932
+ | `auto-commit-on-exit.ts` | Commit on shutdown | `on("session_shutdown")`, `exec` |
1933
+ | **UI Components** |||
1934
+ | `status-line.ts` | Footer status indicator | `setStatus`, session events |
1935
+ | `custom-footer.ts` | Replace footer entirely | `registerCommand`, `setFooter` |
1936
+ | `custom-header.ts` | Replace startup header | `on("session_start")`, `setHeader` |
1937
+ | `modal-editor.ts` | Vim-style modal editor | `setEditorComponent`, `CustomEditor` |
1938
+ | `rainbow-editor.ts` | Custom editor styling | `setEditorComponent` |
1939
+ | `widget-placement.ts` | Widget above/below editor | `setWidget` |
1940
+ | `overlay-test.ts` | Overlay components | `ui.custom` with overlay options |
1941
+ | `overlay-qa-tests.ts` | Comprehensive overlay tests | `ui.custom`, all overlay options |
1942
+ | `notify.ts` | Simple notifications | `ui.notify` |
1943
+ | `timed-confirm.ts` | Dialogs with timeout | `ui.confirm` with timeout/signal |
1944
+ | `mac-system-theme.ts` | Auto-switch theme | `setTheme`, `exec` |
1945
+ | **Complex Extensions** |||
1946
+ | `plan-mode/` | Full plan mode implementation | All event types, `registerCommand`, `registerShortcut`, `registerFlag`, `setStatus`, `setWidget`, `sendMessage`, `setActiveTools` |
1947
+ | `preset.ts` | Saveable presets (model, tools, thinking) | `registerCommand`, `registerShortcut`, `registerFlag`, `setModel`, `setActiveTools`, `setThinkingLevel`, `appendEntry` |
1948
+ | `tools.ts` | Toggle tools on/off UI | `registerCommand`, `setActiveTools`, `SettingsList`, session events |
1949
+ | **Remote & Sandbox** |||
1950
+ | `ssh.ts` | SSH remote execution | `registerFlag`, `on("user_bash")`, `on("before_agent_start")`, tool operations |
1951
+ | `interactive-shell.ts` | Persistent shell session | `on("user_bash")` |
1952
+ | `sandbox/` | Sandboxed tool execution | Tool operations |
1953
+ | `subagent/` | Spawn sub-agents | `registerTool`, `exec` |
1954
+ | **Games** |||
1955
+ | `snake.ts` | Snake game | `registerCommand`, `ui.custom`, keyboard handling |
1956
+ | `space-invaders.ts` | Space Invaders game | `registerCommand`, `ui.custom` |
1957
+ | `doom-overlay/` | Doom in overlay | `ui.custom` with overlay |
1958
+ | **Providers** |||
1959
+ | `custom-provider-anthropic/` | Custom Anthropic proxy | `registerProvider` |
1960
+ | `custom-provider-gitlab-duo/` | GitLab Duo integration | `registerProvider` with OAuth |
1961
+ | **Messages & Communication** |||
1962
+ | `message-renderer.ts` | Custom message rendering | `registerMessageRenderer`, `sendMessage` |
1963
+ | `event-bus.ts` | Inter-extension events | `shortcut.events` |
1964
+ | **Session Metadata** |||
1965
+ | `session-name.ts` | Name sessions for selector | `setSessionName`, `getSessionName` |
1966
+ | `bookmark.ts` | Bookmark entries for /tree | `setLabel` |
1967
+ | **Misc** |||
1968
+ | `antigravity-image-gen.ts` | Image generation tool | `registerTool`, Google Antigravity |
1969
+ | `inline-bash.ts` | Inline bash in tool calls | `on("tool_call")` |
1970
+ | `bash-spawn-hook.ts` | Adjust bash command, cwd, and env before execution | `createBashTool`, `spawnHook` |
1971
+ | `with-deps/` | Extension with npm dependencies | Package structure with `package.json` |