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,1068 @@
1
+ /**
2
+ * Subagent Tool - Delegate tasks to specialized agents
3
+ *
4
+ * Spawns a separate `shortcut` process for each subagent invocation,
5
+ * giving it an isolated context window.
6
+ *
7
+ * Supports three modes:
8
+ * - Single: { agent: "name", task: "..." }
9
+ * - Parallel: { tasks: [{ agent: "name", task: "..." }, ...] }
10
+ * - Chain: { chain: [{ agent: "name", task: "... {previous} ..." }, ...] }
11
+ *
12
+ * Uses JSON mode to capture structured output from subagents.
13
+ */
14
+
15
+ import { Type } from '@sinclair/typebox';
16
+ import { spawn } from 'node:child_process';
17
+ import * as fs from 'node:fs';
18
+ import * as os from 'node:os';
19
+ import * as path from 'node:path';
20
+ import type { AgentToolResult, Message } from 'shortcutxl';
21
+ import {
22
+ Container,
23
+ type ExtensionAPI,
24
+ getMarkdownTheme,
25
+ Markdown,
26
+ Spacer,
27
+ StringEnum,
28
+ Text
29
+ } from 'shortcutxl';
30
+ import { type AgentConfig, type AgentScope, discoverAgents } from './agents.js';
31
+
32
+ const MAX_PARALLEL_TASKS = 8;
33
+ const MAX_CONCURRENCY = 4;
34
+ const COLLAPSED_ITEM_COUNT = 10;
35
+
36
+ function formatTokens(count: number): string {
37
+ if (count < 1000) return count.toString();
38
+ if (count < 10000) return `${(count / 1000).toFixed(1)}k`;
39
+ if (count < 1000000) return `${Math.round(count / 1000)}k`;
40
+ return `${(count / 1000000).toFixed(1)}M`;
41
+ }
42
+
43
+ function formatUsageStats(
44
+ usage: {
45
+ input: number;
46
+ output: number;
47
+ cacheRead: number;
48
+ cacheWrite: number;
49
+ cost: number;
50
+ contextTokens?: number;
51
+ turns?: number;
52
+ },
53
+ model?: string
54
+ ): string {
55
+ const parts: string[] = [];
56
+ if (usage.turns) parts.push(`${usage.turns} turn${usage.turns > 1 ? 's' : ''}`);
57
+ if (usage.input) parts.push(`↑${formatTokens(usage.input)}`);
58
+ if (usage.output) parts.push(`↓${formatTokens(usage.output)}`);
59
+ if (usage.cacheRead) parts.push(`R${formatTokens(usage.cacheRead)}`);
60
+ if (usage.cacheWrite) parts.push(`W${formatTokens(usage.cacheWrite)}`);
61
+ if (usage.cost) parts.push(`$${usage.cost.toFixed(4)}`);
62
+ if (usage.contextTokens && usage.contextTokens > 0) {
63
+ parts.push(`ctx:${formatTokens(usage.contextTokens)}`);
64
+ }
65
+ if (model) parts.push(model);
66
+ return parts.join(' ');
67
+ }
68
+
69
+ function formatToolCall(
70
+ toolName: string,
71
+ args: Record<string, unknown>,
72
+ themeFg: (color: any, text: string) => string
73
+ ): string {
74
+ const shortenPath = (p: string) => {
75
+ const home = os.homedir();
76
+ return p.startsWith(home) ? `~${p.slice(home.length)}` : p;
77
+ };
78
+
79
+ switch (toolName) {
80
+ case 'bash': {
81
+ const command = (args.command as string) || '...';
82
+ const preview = command.length > 60 ? `${command.slice(0, 60)}...` : command;
83
+ return themeFg('muted', '$ ') + themeFg('toolOutput', preview);
84
+ }
85
+ case 'read': {
86
+ const rawPath = (args.file_path || args.path || '...') as string;
87
+ const filePath = shortenPath(rawPath);
88
+ const offset = args.offset as number | undefined;
89
+ const limit = args.limit as number | undefined;
90
+ let text = themeFg('accent', filePath);
91
+ if (offset !== undefined || limit !== undefined) {
92
+ const startLine = offset ?? 1;
93
+ const endLine = limit !== undefined ? startLine + limit - 1 : '';
94
+ text += themeFg('warning', `:${startLine}${endLine ? `-${endLine}` : ''}`);
95
+ }
96
+ return themeFg('muted', 'read ') + text;
97
+ }
98
+ case 'write': {
99
+ const rawPath = (args.file_path || args.path || '...') as string;
100
+ const filePath = shortenPath(rawPath);
101
+ const content = (args.content || '') as string;
102
+ const lines = content.split('\n').length;
103
+ let text = themeFg('muted', 'write ') + themeFg('accent', filePath);
104
+ if (lines > 1) text += themeFg('dim', ` (${lines} lines)`);
105
+ return text;
106
+ }
107
+ case 'edit': {
108
+ const rawPath = (args.file_path || args.path || '...') as string;
109
+ return themeFg('muted', 'edit ') + themeFg('accent', shortenPath(rawPath));
110
+ }
111
+ case 'ls': {
112
+ const rawPath = (args.path || '.') as string;
113
+ return themeFg('muted', 'ls ') + themeFg('accent', shortenPath(rawPath));
114
+ }
115
+ case 'find': {
116
+ const pattern = (args.pattern || '*') as string;
117
+ const rawPath = (args.path || '.') as string;
118
+ return (
119
+ themeFg('muted', 'find ') +
120
+ themeFg('accent', pattern) +
121
+ themeFg('dim', ` in ${shortenPath(rawPath)}`)
122
+ );
123
+ }
124
+ case 'grep': {
125
+ const pattern = (args.pattern || '') as string;
126
+ const rawPath = (args.path || '.') as string;
127
+ return (
128
+ themeFg('muted', 'grep ') +
129
+ themeFg('accent', `/${pattern}/`) +
130
+ themeFg('dim', ` in ${shortenPath(rawPath)}`)
131
+ );
132
+ }
133
+ default: {
134
+ const argsStr = JSON.stringify(args);
135
+ const preview = argsStr.length > 50 ? `${argsStr.slice(0, 50)}...` : argsStr;
136
+ return themeFg('accent', toolName) + themeFg('dim', ` ${preview}`);
137
+ }
138
+ }
139
+ }
140
+
141
+ interface UsageStats {
142
+ input: number;
143
+ output: number;
144
+ cacheRead: number;
145
+ cacheWrite: number;
146
+ cost: number;
147
+ contextTokens: number;
148
+ turns: number;
149
+ }
150
+
151
+ interface SingleResult {
152
+ agent: string;
153
+ agentSource: 'user' | 'project' | 'unknown';
154
+ task: string;
155
+ exitCode: number;
156
+ messages: Message[];
157
+ stderr: string;
158
+ usage: UsageStats;
159
+ model?: string;
160
+ stopReason?: string;
161
+ errorMessage?: string;
162
+ step?: number;
163
+ }
164
+
165
+ interface SubagentDetails {
166
+ mode: 'single' | 'parallel' | 'chain';
167
+ agentScope: AgentScope;
168
+ projectAgentsDir: string | null;
169
+ results: SingleResult[];
170
+ }
171
+
172
+ function getFinalOutput(messages: Message[]): string {
173
+ for (let i = messages.length - 1; i >= 0; i--) {
174
+ const msg = messages[i];
175
+ if (msg.role === 'assistant') {
176
+ for (const part of msg.content) {
177
+ if (part.type === 'text') return part.text;
178
+ }
179
+ }
180
+ }
181
+ return '';
182
+ }
183
+
184
+ type DisplayItem =
185
+ | { type: 'text'; text: string }
186
+ | { type: 'toolCall'; name: string; args: Record<string, any> };
187
+
188
+ function getDisplayItems(messages: Message[]): DisplayItem[] {
189
+ const items: DisplayItem[] = [];
190
+ for (const msg of messages) {
191
+ if (msg.role === 'assistant') {
192
+ for (const part of msg.content) {
193
+ if (part.type === 'text') items.push({ type: 'text', text: part.text });
194
+ else if (part.type === 'toolCall')
195
+ items.push({ type: 'toolCall', name: part.name, args: part.arguments });
196
+ }
197
+ }
198
+ }
199
+ return items;
200
+ }
201
+
202
+ async function mapWithConcurrencyLimit<TIn, TOut>(
203
+ items: TIn[],
204
+ concurrency: number,
205
+ fn: (item: TIn, index: number) => Promise<TOut>
206
+ ): Promise<TOut[]> {
207
+ if (items.length === 0) return [];
208
+ const limit = Math.max(1, Math.min(concurrency, items.length));
209
+ const results: TOut[] = new Array(items.length);
210
+ let nextIndex = 0;
211
+ const workers = new Array(limit).fill(null).map(async () => {
212
+ while (true) {
213
+ const current = nextIndex++;
214
+ if (current >= items.length) return;
215
+ results[current] = await fn(items[current], current);
216
+ }
217
+ });
218
+ await Promise.all(workers);
219
+ return results;
220
+ }
221
+
222
+ function writePromptToTempFile(
223
+ agentName: string,
224
+ prompt: string
225
+ ): { dir: string; filePath: string } {
226
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'shortcut-subagent-'));
227
+ const safeName = agentName.replace(/[^\w.-]+/g, '_');
228
+ const filePath = path.join(tmpDir, `prompt-${safeName}.md`);
229
+ fs.writeFileSync(filePath, prompt, { encoding: 'utf-8', mode: 0o600 });
230
+ return { dir: tmpDir, filePath };
231
+ }
232
+
233
+ type OnUpdateCallback = (partial: AgentToolResult<SubagentDetails>) => void;
234
+
235
+ async function runSingleAgent(
236
+ defaultCwd: string,
237
+ agents: AgentConfig[],
238
+ agentName: string,
239
+ task: string,
240
+ cwd: string | undefined,
241
+ step: number | undefined,
242
+ signal: AbortSignal | undefined,
243
+ onUpdate: OnUpdateCallback | undefined,
244
+ makeDetails: (results: SingleResult[]) => SubagentDetails
245
+ ): Promise<SingleResult> {
246
+ const agent = agents.find((a) => a.name === agentName);
247
+
248
+ if (!agent) {
249
+ const available = agents.map((a) => `"${a.name}"`).join(', ') || 'none';
250
+ return {
251
+ agent: agentName,
252
+ agentSource: 'unknown',
253
+ task,
254
+ exitCode: 1,
255
+ messages: [],
256
+ stderr: `Unknown agent: "${agentName}". Available agents: ${available}.`,
257
+ usage: {
258
+ input: 0,
259
+ output: 0,
260
+ cacheRead: 0,
261
+ cacheWrite: 0,
262
+ cost: 0,
263
+ contextTokens: 0,
264
+ turns: 0
265
+ },
266
+ step
267
+ };
268
+ }
269
+
270
+ const args: string[] = ['--mode', 'json', '-p', '--no-session'];
271
+ if (agent.model) args.push('--model', agent.model);
272
+ if (agent.tools && agent.tools.length > 0) args.push('--tools', agent.tools.join(','));
273
+
274
+ let tmpPromptDir: string | null = null;
275
+ let tmpPromptPath: string | null = null;
276
+
277
+ const currentResult: SingleResult = {
278
+ agent: agentName,
279
+ agentSource: agent.source,
280
+ task,
281
+ exitCode: 0,
282
+ messages: [],
283
+ stderr: '',
284
+ usage: {
285
+ input: 0,
286
+ output: 0,
287
+ cacheRead: 0,
288
+ cacheWrite: 0,
289
+ cost: 0,
290
+ contextTokens: 0,
291
+ turns: 0
292
+ },
293
+ model: agent.model,
294
+ step
295
+ };
296
+
297
+ const emitUpdate = () => {
298
+ if (onUpdate) {
299
+ onUpdate({
300
+ content: [{ type: 'text', text: getFinalOutput(currentResult.messages) || '(running...)' }],
301
+ details: makeDetails([currentResult])
302
+ });
303
+ }
304
+ };
305
+
306
+ try {
307
+ if (agent.systemPrompt.trim()) {
308
+ const tmp = writePromptToTempFile(agent.name, agent.systemPrompt);
309
+ tmpPromptDir = tmp.dir;
310
+ tmpPromptPath = tmp.filePath;
311
+ args.push('--append-system-prompt', tmpPromptPath);
312
+ }
313
+
314
+ args.push(`Task: ${task}`);
315
+ let wasAborted = false;
316
+
317
+ const exitCode = await new Promise<number>((resolve) => {
318
+ const proc = spawn('shortcut', args, {
319
+ cwd: cwd ?? defaultCwd,
320
+ shell: false,
321
+ stdio: ['ignore', 'pipe', 'pipe']
322
+ });
323
+ let buffer = '';
324
+
325
+ const processLine = (line: string) => {
326
+ if (!line.trim()) return;
327
+ let event: any;
328
+ try {
329
+ event = JSON.parse(line);
330
+ } catch {
331
+ return;
332
+ }
333
+
334
+ if (event.type === 'message_end' && event.message) {
335
+ const msg = event.message as Message;
336
+ currentResult.messages.push(msg);
337
+
338
+ if (msg.role === 'assistant') {
339
+ currentResult.usage.turns++;
340
+ const usage = msg.usage;
341
+ if (usage) {
342
+ currentResult.usage.input += usage.input || 0;
343
+ currentResult.usage.output += usage.output || 0;
344
+ currentResult.usage.cacheRead += usage.cacheRead || 0;
345
+ currentResult.usage.cacheWrite += usage.cacheWrite || 0;
346
+ currentResult.usage.cost += usage.cost?.total || 0;
347
+ currentResult.usage.contextTokens = usage.totalTokens || 0;
348
+ }
349
+ if (!currentResult.model && msg.model) currentResult.model = msg.model;
350
+ if (msg.stopReason) currentResult.stopReason = msg.stopReason;
351
+ if (msg.errorMessage) currentResult.errorMessage = msg.errorMessage;
352
+ }
353
+ emitUpdate();
354
+ }
355
+
356
+ if (event.type === 'tool_result_end' && event.message) {
357
+ currentResult.messages.push(event.message as Message);
358
+ emitUpdate();
359
+ }
360
+ };
361
+
362
+ proc.stdout.on('data', (data) => {
363
+ buffer += data.toString();
364
+ const lines = buffer.split('\n');
365
+ buffer = lines.pop() || '';
366
+ for (const line of lines) processLine(line);
367
+ });
368
+
369
+ proc.stderr.on('data', (data) => {
370
+ currentResult.stderr += data.toString();
371
+ });
372
+
373
+ proc.on('close', (code) => {
374
+ if (buffer.trim()) processLine(buffer);
375
+ resolve(code ?? 0);
376
+ });
377
+
378
+ proc.on('error', () => {
379
+ resolve(1);
380
+ });
381
+
382
+ if (signal) {
383
+ const killProc = () => {
384
+ wasAborted = true;
385
+ proc.kill('SIGTERM');
386
+ setTimeout(() => {
387
+ if (!proc.killed) proc.kill('SIGKILL');
388
+ }, 5000);
389
+ };
390
+ if (signal.aborted) killProc();
391
+ else signal.addEventListener('abort', killProc, { once: true });
392
+ }
393
+ });
394
+
395
+ currentResult.exitCode = exitCode;
396
+ if (wasAborted) throw new Error('Subagent was aborted');
397
+ return currentResult;
398
+ } finally {
399
+ if (tmpPromptPath)
400
+ try {
401
+ fs.unlinkSync(tmpPromptPath);
402
+ } catch {
403
+ /* ignore */
404
+ }
405
+ if (tmpPromptDir)
406
+ try {
407
+ fs.rmdirSync(tmpPromptDir);
408
+ } catch {
409
+ /* ignore */
410
+ }
411
+ }
412
+ }
413
+
414
+ const TaskItem = Type.Object({
415
+ agent: Type.String({ description: 'Name of the agent to invoke' }),
416
+ task: Type.String({ description: 'Task to delegate to the agent' }),
417
+ cwd: Type.Optional(Type.String({ description: 'Working directory for the agent process' }))
418
+ });
419
+
420
+ const ChainItem = Type.Object({
421
+ agent: Type.String({ description: 'Name of the agent to invoke' }),
422
+ task: Type.String({ description: 'Task with optional {previous} placeholder for prior output' }),
423
+ cwd: Type.Optional(Type.String({ description: 'Working directory for the agent process' }))
424
+ });
425
+
426
+ const AgentScopeSchema = StringEnum(['user', 'project', 'both'] as const, {
427
+ description:
428
+ 'Which agent directories to use. Default: "user". Use "both" to include project-local agents.',
429
+ default: 'user'
430
+ });
431
+
432
+ const SubagentParams = Type.Object({
433
+ agent: Type.Optional(
434
+ Type.String({ description: 'Name of the agent to invoke (for single mode)' })
435
+ ),
436
+ task: Type.Optional(Type.String({ description: 'Task to delegate (for single mode)' })),
437
+ tasks: Type.Optional(
438
+ Type.Array(TaskItem, { description: 'Array of {agent, task} for parallel execution' })
439
+ ),
440
+ chain: Type.Optional(
441
+ Type.Array(ChainItem, { description: 'Array of {agent, task} for sequential execution' })
442
+ ),
443
+ agentScope: Type.Optional(AgentScopeSchema),
444
+ confirmProjectAgents: Type.Optional(
445
+ Type.Boolean({
446
+ description: 'Prompt before running project-local agents. Default: true.',
447
+ default: true
448
+ })
449
+ ),
450
+ cwd: Type.Optional(
451
+ Type.String({ description: 'Working directory for the agent process (single mode)' })
452
+ )
453
+ });
454
+
455
+ export default function (shortcut: ExtensionAPI) {
456
+ shortcut.registerTool({
457
+ name: 'subagent',
458
+ label: 'Subagent',
459
+ description: [
460
+ 'Delegate tasks to specialized subagents with isolated context.',
461
+ 'Modes: single (agent + task), parallel (tasks array), chain (sequential with {previous} placeholder).',
462
+ 'Default agent scope is "user" (from ~/.shortcut/agent/agents).',
463
+ 'To enable project-local agents in .shortcut/agents, set agentScope: "both" (or "project").'
464
+ ].join(' '),
465
+ parameters: SubagentParams,
466
+
467
+ async execute(_toolCallId, params, signal, onUpdate, ctx) {
468
+ const agentScope: AgentScope = params.agentScope ?? 'user';
469
+ const discovery = discoverAgents(ctx.cwd, agentScope);
470
+ const agents = discovery.agents;
471
+ const confirmProjectAgents = params.confirmProjectAgents ?? true;
472
+
473
+ const hasChain = (params.chain?.length ?? 0) > 0;
474
+ const hasTasks = (params.tasks?.length ?? 0) > 0;
475
+ const hasSingle = Boolean(params.agent && params.task);
476
+ const modeCount = Number(hasChain) + Number(hasTasks) + Number(hasSingle);
477
+
478
+ const makeDetails =
479
+ (mode: 'single' | 'parallel' | 'chain') =>
480
+ (results: SingleResult[]): SubagentDetails => ({
481
+ mode,
482
+ agentScope,
483
+ projectAgentsDir: discovery.projectAgentsDir,
484
+ results
485
+ });
486
+
487
+ if (modeCount !== 1) {
488
+ const available = agents.map((a) => `${a.name} (${a.source})`).join(', ') || 'none';
489
+ return {
490
+ content: [
491
+ {
492
+ type: 'text',
493
+ text: `Invalid parameters. Provide exactly one mode.\nAvailable agents: ${available}`
494
+ }
495
+ ],
496
+ details: makeDetails('single')([])
497
+ };
498
+ }
499
+
500
+ if (
501
+ (agentScope === 'project' || agentScope === 'both') &&
502
+ confirmProjectAgents &&
503
+ ctx.hasUI
504
+ ) {
505
+ const requestedAgentNames = new Set<string>();
506
+ if (params.chain) for (const step of params.chain) requestedAgentNames.add(step.agent);
507
+ if (params.tasks) for (const t of params.tasks) requestedAgentNames.add(t.agent);
508
+ if (params.agent) requestedAgentNames.add(params.agent);
509
+
510
+ const projectAgentsRequested = Array.from(requestedAgentNames)
511
+ .map((name) => agents.find((a) => a.name === name))
512
+ .filter((a): a is AgentConfig => a?.source === 'project');
513
+
514
+ if (projectAgentsRequested.length > 0) {
515
+ const names = projectAgentsRequested.map((a) => a.name).join(', ');
516
+ const dir = discovery.projectAgentsDir ?? '(unknown)';
517
+ const ok = await ctx.ui.confirm(
518
+ 'Run project-local agents?',
519
+ `Agents: ${names}\nSource: ${dir}\n\nProject agents are repo-controlled. Only continue for trusted repositories.`
520
+ );
521
+ if (!ok)
522
+ return {
523
+ content: [{ type: 'text', text: 'Canceled: project-local agents not approved.' }],
524
+ details: makeDetails(hasChain ? 'chain' : hasTasks ? 'parallel' : 'single')([])
525
+ };
526
+ }
527
+ }
528
+
529
+ if (params.chain && params.chain.length > 0) {
530
+ const results: SingleResult[] = [];
531
+ let previousOutput = '';
532
+
533
+ for (let i = 0; i < params.chain.length; i++) {
534
+ const step = params.chain[i];
535
+ const taskWithContext = step.task.replace(/\{previous\}/g, previousOutput);
536
+
537
+ // Create update callback that includes all previous results
538
+ const chainUpdate: OnUpdateCallback | undefined = onUpdate
539
+ ? (partial) => {
540
+ // Combine completed results with current streaming result
541
+ const currentResult = partial.details?.results[0];
542
+ if (currentResult) {
543
+ const allResults = [...results, currentResult];
544
+ onUpdate({
545
+ content: partial.content,
546
+ details: makeDetails('chain')(allResults)
547
+ });
548
+ }
549
+ }
550
+ : undefined;
551
+
552
+ const result = await runSingleAgent(
553
+ ctx.cwd,
554
+ agents,
555
+ step.agent,
556
+ taskWithContext,
557
+ step.cwd,
558
+ i + 1,
559
+ signal,
560
+ chainUpdate,
561
+ makeDetails('chain')
562
+ );
563
+ results.push(result);
564
+
565
+ const isError =
566
+ result.exitCode !== 0 ||
567
+ result.stopReason === 'error' ||
568
+ result.stopReason === 'aborted';
569
+ if (isError) {
570
+ const errorMsg =
571
+ result.errorMessage ||
572
+ result.stderr ||
573
+ getFinalOutput(result.messages) ||
574
+ '(no output)';
575
+ return {
576
+ content: [
577
+ {
578
+ type: 'text',
579
+ text: `Chain stopped at step ${i + 1} (${step.agent}): ${errorMsg}`
580
+ }
581
+ ],
582
+ details: makeDetails('chain')(results),
583
+ isError: true
584
+ };
585
+ }
586
+ previousOutput = getFinalOutput(result.messages);
587
+ }
588
+ return {
589
+ content: [
590
+ {
591
+ type: 'text',
592
+ text: getFinalOutput(results[results.length - 1].messages) || '(no output)'
593
+ }
594
+ ],
595
+ details: makeDetails('chain')(results)
596
+ };
597
+ }
598
+
599
+ if (params.tasks && params.tasks.length > 0) {
600
+ if (params.tasks.length > MAX_PARALLEL_TASKS)
601
+ return {
602
+ content: [
603
+ {
604
+ type: 'text',
605
+ text: `Too many parallel tasks (${params.tasks.length}). Max is ${MAX_PARALLEL_TASKS}.`
606
+ }
607
+ ],
608
+ details: makeDetails('parallel')([])
609
+ };
610
+
611
+ // Track all results for streaming updates
612
+ const allResults: SingleResult[] = new Array(params.tasks.length);
613
+
614
+ // Initialize placeholder results
615
+ for (let i = 0; i < params.tasks.length; i++) {
616
+ allResults[i] = {
617
+ agent: params.tasks[i].agent,
618
+ agentSource: 'unknown',
619
+ task: params.tasks[i].task,
620
+ exitCode: -1, // -1 = still running
621
+ messages: [],
622
+ stderr: '',
623
+ usage: {
624
+ input: 0,
625
+ output: 0,
626
+ cacheRead: 0,
627
+ cacheWrite: 0,
628
+ cost: 0,
629
+ contextTokens: 0,
630
+ turns: 0
631
+ }
632
+ };
633
+ }
634
+
635
+ const emitParallelUpdate = () => {
636
+ if (onUpdate) {
637
+ const running = allResults.filter((r) => r.exitCode === -1).length;
638
+ const done = allResults.filter((r) => r.exitCode !== -1).length;
639
+ onUpdate({
640
+ content: [
641
+ {
642
+ type: 'text',
643
+ text: `Parallel: ${done}/${allResults.length} done, ${running} running...`
644
+ }
645
+ ],
646
+ details: makeDetails('parallel')([...allResults])
647
+ });
648
+ }
649
+ };
650
+
651
+ const results = await mapWithConcurrencyLimit(
652
+ params.tasks,
653
+ MAX_CONCURRENCY,
654
+ async (t, index) => {
655
+ const result = await runSingleAgent(
656
+ ctx.cwd,
657
+ agents,
658
+ t.agent,
659
+ t.task,
660
+ t.cwd,
661
+ undefined,
662
+ signal,
663
+ // Per-task update callback
664
+ (partial) => {
665
+ if (partial.details?.results[0]) {
666
+ allResults[index] = partial.details.results[0];
667
+ emitParallelUpdate();
668
+ }
669
+ },
670
+ makeDetails('parallel')
671
+ );
672
+ allResults[index] = result;
673
+ emitParallelUpdate();
674
+ return result;
675
+ }
676
+ );
677
+
678
+ const successCount = results.filter((r) => r.exitCode === 0).length;
679
+ const summaries = results.map((r) => {
680
+ const output = getFinalOutput(r.messages);
681
+ const preview = output.slice(0, 100) + (output.length > 100 ? '...' : '');
682
+ return `[${r.agent}] ${r.exitCode === 0 ? 'completed' : 'failed'}: ${preview || '(no output)'}`;
683
+ });
684
+ return {
685
+ content: [
686
+ {
687
+ type: 'text',
688
+ text: `Parallel: ${successCount}/${results.length} succeeded\n\n${summaries.join('\n\n')}`
689
+ }
690
+ ],
691
+ details: makeDetails('parallel')(results)
692
+ };
693
+ }
694
+
695
+ if (params.agent && params.task) {
696
+ const result = await runSingleAgent(
697
+ ctx.cwd,
698
+ agents,
699
+ params.agent,
700
+ params.task,
701
+ params.cwd,
702
+ undefined,
703
+ signal,
704
+ onUpdate,
705
+ makeDetails('single')
706
+ );
707
+ const isError =
708
+ result.exitCode !== 0 || result.stopReason === 'error' || result.stopReason === 'aborted';
709
+ if (isError) {
710
+ const errorMsg =
711
+ result.errorMessage ||
712
+ result.stderr ||
713
+ getFinalOutput(result.messages) ||
714
+ '(no output)';
715
+ return {
716
+ content: [
717
+ { type: 'text', text: `Agent ${result.stopReason || 'failed'}: ${errorMsg}` }
718
+ ],
719
+ details: makeDetails('single')([result]),
720
+ isError: true
721
+ };
722
+ }
723
+ return {
724
+ content: [{ type: 'text', text: getFinalOutput(result.messages) || '(no output)' }],
725
+ details: makeDetails('single')([result])
726
+ };
727
+ }
728
+
729
+ const available = agents.map((a) => `${a.name} (${a.source})`).join(', ') || 'none';
730
+ return {
731
+ content: [{ type: 'text', text: `Invalid parameters. Available agents: ${available}` }],
732
+ details: makeDetails('single')([])
733
+ };
734
+ },
735
+
736
+ renderCall(args, theme) {
737
+ const scope: AgentScope = args.agentScope ?? 'user';
738
+ if (args.chain && args.chain.length > 0) {
739
+ let text =
740
+ theme.fg('toolTitle', theme.bold('subagent ')) +
741
+ theme.fg('accent', `chain (${args.chain.length} steps)`) +
742
+ theme.fg('muted', ` [${scope}]`);
743
+ for (let i = 0; i < Math.min(args.chain.length, 3); i++) {
744
+ const step = args.chain[i];
745
+ // Clean up {previous} placeholder for display
746
+ const cleanTask = step.task.replace(/\{previous\}/g, '').trim();
747
+ const preview = cleanTask.length > 40 ? `${cleanTask.slice(0, 40)}...` : cleanTask;
748
+ text +=
749
+ '\n ' +
750
+ theme.fg('muted', `${i + 1}.`) +
751
+ ' ' +
752
+ theme.fg('accent', step.agent) +
753
+ theme.fg('dim', ` ${preview}`);
754
+ }
755
+ if (args.chain.length > 3)
756
+ text += `\n ${theme.fg('muted', `... +${args.chain.length - 3} more`)}`;
757
+ return new Text(text, 0, 0);
758
+ }
759
+ if (args.tasks && args.tasks.length > 0) {
760
+ let text =
761
+ theme.fg('toolTitle', theme.bold('subagent ')) +
762
+ theme.fg('accent', `parallel (${args.tasks.length} tasks)`) +
763
+ theme.fg('muted', ` [${scope}]`);
764
+ for (const t of args.tasks.slice(0, 3)) {
765
+ const preview = t.task.length > 40 ? `${t.task.slice(0, 40)}...` : t.task;
766
+ text += `\n ${theme.fg('accent', t.agent)}${theme.fg('dim', ` ${preview}`)}`;
767
+ }
768
+ if (args.tasks.length > 3)
769
+ text += `\n ${theme.fg('muted', `... +${args.tasks.length - 3} more`)}`;
770
+ return new Text(text, 0, 0);
771
+ }
772
+ const agentName = args.agent || '...';
773
+ const preview = args.task
774
+ ? args.task.length > 60
775
+ ? `${args.task.slice(0, 60)}...`
776
+ : args.task
777
+ : '...';
778
+ let text =
779
+ theme.fg('toolTitle', theme.bold('subagent ')) +
780
+ theme.fg('accent', agentName) +
781
+ theme.fg('muted', ` [${scope}]`);
782
+ text += `\n ${theme.fg('dim', preview)}`;
783
+ return new Text(text, 0, 0);
784
+ },
785
+
786
+ renderResult(result, { expanded }, theme) {
787
+ const details = result.details as SubagentDetails | undefined;
788
+ if (!details || details.results.length === 0) {
789
+ const text = result.content[0];
790
+ return new Text(text?.type === 'text' ? text.text : '(no output)', 0, 0);
791
+ }
792
+
793
+ const mdTheme = getMarkdownTheme();
794
+
795
+ const renderDisplayItems = (items: DisplayItem[], limit?: number) => {
796
+ const toShow = limit ? items.slice(-limit) : items;
797
+ const skipped = limit && items.length > limit ? items.length - limit : 0;
798
+ let text = '';
799
+ if (skipped > 0) text += theme.fg('muted', `... ${skipped} earlier items\n`);
800
+ for (const item of toShow) {
801
+ if (item.type === 'text') {
802
+ const preview = expanded ? item.text : item.text.split('\n').slice(0, 3).join('\n');
803
+ text += `${theme.fg('toolOutput', preview)}\n`;
804
+ } else {
805
+ text += `${theme.fg('muted', '→ ') + formatToolCall(item.name, item.args, theme.fg.bind(theme))}\n`;
806
+ }
807
+ }
808
+ return text.trimEnd();
809
+ };
810
+
811
+ if (details.mode === 'single' && details.results.length === 1) {
812
+ const r = details.results[0];
813
+ const isError = r.exitCode !== 0 || r.stopReason === 'error' || r.stopReason === 'aborted';
814
+ const icon = isError ? theme.fg('error', '✗') : theme.fg('success', '✓');
815
+ const displayItems = getDisplayItems(r.messages);
816
+ const finalOutput = getFinalOutput(r.messages);
817
+
818
+ if (expanded) {
819
+ const container = new Container();
820
+ let header = `${icon} ${theme.fg('toolTitle', theme.bold(r.agent))}${theme.fg('muted', ` (${r.agentSource})`)}`;
821
+ if (isError && r.stopReason) header += ` ${theme.fg('error', `[${r.stopReason}]`)}`;
822
+ container.addChild(new Text(header, 0, 0));
823
+ if (isError && r.errorMessage)
824
+ container.addChild(new Text(theme.fg('error', `Error: ${r.errorMessage}`), 0, 0));
825
+ container.addChild(new Spacer(1));
826
+ container.addChild(new Text(theme.fg('muted', '─── Task ───'), 0, 0));
827
+ container.addChild(new Text(theme.fg('dim', r.task), 0, 0));
828
+ container.addChild(new Spacer(1));
829
+ container.addChild(new Text(theme.fg('muted', '─── Output ───'), 0, 0));
830
+ if (displayItems.length === 0 && !finalOutput) {
831
+ container.addChild(new Text(theme.fg('muted', '(no output)'), 0, 0));
832
+ } else {
833
+ for (const item of displayItems) {
834
+ if (item.type === 'toolCall')
835
+ container.addChild(
836
+ new Text(
837
+ theme.fg('muted', '→ ') +
838
+ formatToolCall(item.name, item.args, theme.fg.bind(theme)),
839
+ 0,
840
+ 0
841
+ )
842
+ );
843
+ }
844
+ if (finalOutput) {
845
+ container.addChild(new Spacer(1));
846
+ container.addChild(new Markdown(finalOutput.trim(), 0, 0, mdTheme));
847
+ }
848
+ }
849
+ const usageStr = formatUsageStats(r.usage, r.model);
850
+ if (usageStr) {
851
+ container.addChild(new Spacer(1));
852
+ container.addChild(new Text(theme.fg('dim', usageStr), 0, 0));
853
+ }
854
+ return container;
855
+ }
856
+
857
+ let text = `${icon} ${theme.fg('toolTitle', theme.bold(r.agent))}${theme.fg('muted', ` (${r.agentSource})`)}`;
858
+ if (isError && r.stopReason) text += ` ${theme.fg('error', `[${r.stopReason}]`)}`;
859
+ if (isError && r.errorMessage) text += `\n${theme.fg('error', `Error: ${r.errorMessage}`)}`;
860
+ else if (displayItems.length === 0) text += `\n${theme.fg('muted', '(no output)')}`;
861
+ else {
862
+ text += `\n${renderDisplayItems(displayItems, COLLAPSED_ITEM_COUNT)}`;
863
+ if (displayItems.length > COLLAPSED_ITEM_COUNT)
864
+ text += `\n${theme.fg('muted', '(Ctrl+O to expand)')}`;
865
+ }
866
+ const usageStr = formatUsageStats(r.usage, r.model);
867
+ if (usageStr) text += `\n${theme.fg('dim', usageStr)}`;
868
+ return new Text(text, 0, 0);
869
+ }
870
+
871
+ const aggregateUsage = (results: SingleResult[]) => {
872
+ const total = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, turns: 0 };
873
+ for (const r of results) {
874
+ total.input += r.usage.input;
875
+ total.output += r.usage.output;
876
+ total.cacheRead += r.usage.cacheRead;
877
+ total.cacheWrite += r.usage.cacheWrite;
878
+ total.cost += r.usage.cost;
879
+ total.turns += r.usage.turns;
880
+ }
881
+ return total;
882
+ };
883
+
884
+ if (details.mode === 'chain') {
885
+ const successCount = details.results.filter((r) => r.exitCode === 0).length;
886
+ const icon =
887
+ successCount === details.results.length
888
+ ? theme.fg('success', '✓')
889
+ : theme.fg('error', '✗');
890
+
891
+ if (expanded) {
892
+ const container = new Container();
893
+ container.addChild(
894
+ new Text(
895
+ icon +
896
+ ' ' +
897
+ theme.fg('toolTitle', theme.bold('chain ')) +
898
+ theme.fg('accent', `${successCount}/${details.results.length} steps`),
899
+ 0,
900
+ 0
901
+ )
902
+ );
903
+
904
+ for (const r of details.results) {
905
+ const rIcon = r.exitCode === 0 ? theme.fg('success', '✓') : theme.fg('error', '✗');
906
+ const displayItems = getDisplayItems(r.messages);
907
+ const finalOutput = getFinalOutput(r.messages);
908
+
909
+ container.addChild(new Spacer(1));
910
+ container.addChild(
911
+ new Text(
912
+ `${theme.fg('muted', `─── Step ${r.step}: `) + theme.fg('accent', r.agent)} ${rIcon}`,
913
+ 0,
914
+ 0
915
+ )
916
+ );
917
+ container.addChild(
918
+ new Text(theme.fg('muted', 'Task: ') + theme.fg('dim', r.task), 0, 0)
919
+ );
920
+
921
+ // Show tool calls
922
+ for (const item of displayItems) {
923
+ if (item.type === 'toolCall') {
924
+ container.addChild(
925
+ new Text(
926
+ theme.fg('muted', '→ ') +
927
+ formatToolCall(item.name, item.args, theme.fg.bind(theme)),
928
+ 0,
929
+ 0
930
+ )
931
+ );
932
+ }
933
+ }
934
+
935
+ // Show final output as markdown
936
+ if (finalOutput) {
937
+ container.addChild(new Spacer(1));
938
+ container.addChild(new Markdown(finalOutput.trim(), 0, 0, mdTheme));
939
+ }
940
+
941
+ const stepUsage = formatUsageStats(r.usage, r.model);
942
+ if (stepUsage) container.addChild(new Text(theme.fg('dim', stepUsage), 0, 0));
943
+ }
944
+
945
+ const usageStr = formatUsageStats(aggregateUsage(details.results));
946
+ if (usageStr) {
947
+ container.addChild(new Spacer(1));
948
+ container.addChild(new Text(theme.fg('dim', `Total: ${usageStr}`), 0, 0));
949
+ }
950
+ return container;
951
+ }
952
+
953
+ // Collapsed view
954
+ let text =
955
+ icon +
956
+ ' ' +
957
+ theme.fg('toolTitle', theme.bold('chain ')) +
958
+ theme.fg('accent', `${successCount}/${details.results.length} steps`);
959
+ for (const r of details.results) {
960
+ const rIcon = r.exitCode === 0 ? theme.fg('success', '✓') : theme.fg('error', '✗');
961
+ const displayItems = getDisplayItems(r.messages);
962
+ text += `\n\n${theme.fg('muted', `─── Step ${r.step}: `)}${theme.fg('accent', r.agent)} ${rIcon}`;
963
+ if (displayItems.length === 0) text += `\n${theme.fg('muted', '(no output)')}`;
964
+ else text += `\n${renderDisplayItems(displayItems, 5)}`;
965
+ }
966
+ const usageStr = formatUsageStats(aggregateUsage(details.results));
967
+ if (usageStr) text += `\n\n${theme.fg('dim', `Total: ${usageStr}`)}`;
968
+ text += `\n${theme.fg('muted', '(Ctrl+O to expand)')}`;
969
+ return new Text(text, 0, 0);
970
+ }
971
+
972
+ if (details.mode === 'parallel') {
973
+ const running = details.results.filter((r) => r.exitCode === -1).length;
974
+ const successCount = details.results.filter((r) => r.exitCode === 0).length;
975
+ const failCount = details.results.filter((r) => r.exitCode > 0).length;
976
+ const isRunning = running > 0;
977
+ const icon = isRunning
978
+ ? theme.fg('warning', '⏳')
979
+ : failCount > 0
980
+ ? theme.fg('warning', '◐')
981
+ : theme.fg('success', '✓');
982
+ const status = isRunning
983
+ ? `${successCount + failCount}/${details.results.length} done, ${running} running`
984
+ : `${successCount}/${details.results.length} tasks`;
985
+
986
+ if (expanded && !isRunning) {
987
+ const container = new Container();
988
+ container.addChild(
989
+ new Text(
990
+ `${icon} ${theme.fg('toolTitle', theme.bold('parallel '))}${theme.fg('accent', status)}`,
991
+ 0,
992
+ 0
993
+ )
994
+ );
995
+
996
+ for (const r of details.results) {
997
+ const rIcon = r.exitCode === 0 ? theme.fg('success', '✓') : theme.fg('error', '✗');
998
+ const displayItems = getDisplayItems(r.messages);
999
+ const finalOutput = getFinalOutput(r.messages);
1000
+
1001
+ container.addChild(new Spacer(1));
1002
+ container.addChild(
1003
+ new Text(`${theme.fg('muted', '─── ') + theme.fg('accent', r.agent)} ${rIcon}`, 0, 0)
1004
+ );
1005
+ container.addChild(
1006
+ new Text(theme.fg('muted', 'Task: ') + theme.fg('dim', r.task), 0, 0)
1007
+ );
1008
+
1009
+ // Show tool calls
1010
+ for (const item of displayItems) {
1011
+ if (item.type === 'toolCall') {
1012
+ container.addChild(
1013
+ new Text(
1014
+ theme.fg('muted', '→ ') +
1015
+ formatToolCall(item.name, item.args, theme.fg.bind(theme)),
1016
+ 0,
1017
+ 0
1018
+ )
1019
+ );
1020
+ }
1021
+ }
1022
+
1023
+ // Show final output as markdown
1024
+ if (finalOutput) {
1025
+ container.addChild(new Spacer(1));
1026
+ container.addChild(new Markdown(finalOutput.trim(), 0, 0, mdTheme));
1027
+ }
1028
+
1029
+ const taskUsage = formatUsageStats(r.usage, r.model);
1030
+ if (taskUsage) container.addChild(new Text(theme.fg('dim', taskUsage), 0, 0));
1031
+ }
1032
+
1033
+ const usageStr = formatUsageStats(aggregateUsage(details.results));
1034
+ if (usageStr) {
1035
+ container.addChild(new Spacer(1));
1036
+ container.addChild(new Text(theme.fg('dim', `Total: ${usageStr}`), 0, 0));
1037
+ }
1038
+ return container;
1039
+ }
1040
+
1041
+ // Collapsed view (or still running)
1042
+ let text = `${icon} ${theme.fg('toolTitle', theme.bold('parallel '))}${theme.fg('accent', status)}`;
1043
+ for (const r of details.results) {
1044
+ const rIcon =
1045
+ r.exitCode === -1
1046
+ ? theme.fg('warning', '⏳')
1047
+ : r.exitCode === 0
1048
+ ? theme.fg('success', '✓')
1049
+ : theme.fg('error', '✗');
1050
+ const displayItems = getDisplayItems(r.messages);
1051
+ text += `\n\n${theme.fg('muted', '─── ')}${theme.fg('accent', r.agent)} ${rIcon}`;
1052
+ if (displayItems.length === 0)
1053
+ text += `\n${theme.fg('muted', r.exitCode === -1 ? '(running...)' : '(no output)')}`;
1054
+ else text += `\n${renderDisplayItems(displayItems, 5)}`;
1055
+ }
1056
+ if (!isRunning) {
1057
+ const usageStr = formatUsageStats(aggregateUsage(details.results));
1058
+ if (usageStr) text += `\n\n${theme.fg('dim', `Total: ${usageStr}`)}`;
1059
+ }
1060
+ if (!expanded) text += `\n${theme.fg('muted', '(Ctrl+O to expand)')}`;
1061
+ return new Text(text, 0, 0);
1062
+ }
1063
+
1064
+ const text = result.content[0];
1065
+ return new Text(text?.type === 'text' ? text.text : '(no output)', 0, 0);
1066
+ }
1067
+ });
1068
+ }