codepro-ia 1.0.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 (393) hide show
  1. package/AGENTS.md +27 -0
  2. package/Dockerfile +18 -0
  3. package/README.md +70 -0
  4. package/bin/opencode +84 -0
  5. package/bunfig.toml +7 -0
  6. package/package.json +144 -0
  7. package/parsers-config.ts +253 -0
  8. package/script/build.ts +167 -0
  9. package/script/postinstall.mjs +125 -0
  10. package/script/publish-registries.ts +187 -0
  11. package/script/publish.ts +70 -0
  12. package/script/schema.ts +47 -0
  13. package/src/acp/README.md +164 -0
  14. package/src/acp/agent.ts +1127 -0
  15. package/src/acp/session.ts +101 -0
  16. package/src/acp/types.ts +22 -0
  17. package/src/agent/agent.ts +311 -0
  18. package/src/agent/generate.txt +75 -0
  19. package/src/agent/prompt/compaction.txt +12 -0
  20. package/src/agent/prompt/explore.txt +18 -0
  21. package/src/agent/prompt/summary.txt +11 -0
  22. package/src/agent/prompt/title.txt +43 -0
  23. package/src/auth/index.ts +73 -0
  24. package/src/bun/index.ts +134 -0
  25. package/src/bus/bus-event.ts +43 -0
  26. package/src/bus/global.ts +10 -0
  27. package/src/bus/index.ts +105 -0
  28. package/src/cli/bootstrap.ts +17 -0
  29. package/src/cli/cmd/acp.ts +69 -0
  30. package/src/cli/cmd/agent.ts +257 -0
  31. package/src/cli/cmd/auth.ts +400 -0
  32. package/src/cli/cmd/cmd.ts +7 -0
  33. package/src/cli/cmd/debug/agent.ts +166 -0
  34. package/src/cli/cmd/debug/config.ts +16 -0
  35. package/src/cli/cmd/debug/file.ts +97 -0
  36. package/src/cli/cmd/debug/index.ts +48 -0
  37. package/src/cli/cmd/debug/lsp.ts +52 -0
  38. package/src/cli/cmd/debug/ripgrep.ts +87 -0
  39. package/src/cli/cmd/debug/scrap.ts +16 -0
  40. package/src/cli/cmd/debug/skill.ts +16 -0
  41. package/src/cli/cmd/debug/snapshot.ts +52 -0
  42. package/src/cli/cmd/export.ts +88 -0
  43. package/src/cli/cmd/generate.ts +38 -0
  44. package/src/cli/cmd/github.ts +1548 -0
  45. package/src/cli/cmd/import.ts +98 -0
  46. package/src/cli/cmd/mcp.ts +755 -0
  47. package/src/cli/cmd/models.ts +77 -0
  48. package/src/cli/cmd/pr.ts +112 -0
  49. package/src/cli/cmd/run.ts +395 -0
  50. package/src/cli/cmd/serve.ts +20 -0
  51. package/src/cli/cmd/session.ts +135 -0
  52. package/src/cli/cmd/stats.ts +402 -0
  53. package/src/cli/cmd/tui/app.tsx +724 -0
  54. package/src/cli/cmd/tui/attach.ts +31 -0
  55. package/src/cli/cmd/tui/component/border.tsx +21 -0
  56. package/src/cli/cmd/tui/component/dialog-agent.tsx +31 -0
  57. package/src/cli/cmd/tui/component/dialog-command.tsx +124 -0
  58. package/src/cli/cmd/tui/component/dialog-mcp.tsx +86 -0
  59. package/src/cli/cmd/tui/component/dialog-model.tsx +234 -0
  60. package/src/cli/cmd/tui/component/dialog-provider.tsx +256 -0
  61. package/src/cli/cmd/tui/component/dialog-session-list.tsx +114 -0
  62. package/src/cli/cmd/tui/component/dialog-session-rename.tsx +31 -0
  63. package/src/cli/cmd/tui/component/dialog-stash.tsx +87 -0
  64. package/src/cli/cmd/tui/component/dialog-status.tsx +164 -0
  65. package/src/cli/cmd/tui/component/dialog-tag.tsx +44 -0
  66. package/src/cli/cmd/tui/component/dialog-theme-list.tsx +50 -0
  67. package/src/cli/cmd/tui/component/logo.tsx +106 -0
  68. package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +763 -0
  69. package/src/cli/cmd/tui/component/prompt/frecency.tsx +89 -0
  70. package/src/cli/cmd/tui/component/prompt/history.tsx +108 -0
  71. package/src/cli/cmd/tui/component/prompt/index.tsx +1090 -0
  72. package/src/cli/cmd/tui/component/prompt/stash.tsx +101 -0
  73. package/src/cli/cmd/tui/component/textarea-keybindings.ts +73 -0
  74. package/src/cli/cmd/tui/component/tips.tsx +153 -0
  75. package/src/cli/cmd/tui/component/todo-item.tsx +32 -0
  76. package/src/cli/cmd/tui/context/args.tsx +14 -0
  77. package/src/cli/cmd/tui/context/directory.ts +13 -0
  78. package/src/cli/cmd/tui/context/exit.tsx +23 -0
  79. package/src/cli/cmd/tui/context/helper.tsx +25 -0
  80. package/src/cli/cmd/tui/context/keybind.tsx +101 -0
  81. package/src/cli/cmd/tui/context/kv.tsx +52 -0
  82. package/src/cli/cmd/tui/context/local.tsx +402 -0
  83. package/src/cli/cmd/tui/context/prompt.tsx +18 -0
  84. package/src/cli/cmd/tui/context/route.tsx +46 -0
  85. package/src/cli/cmd/tui/context/sdk.tsx +94 -0
  86. package/src/cli/cmd/tui/context/sync.tsx +427 -0
  87. package/src/cli/cmd/tui/context/theme/aura.json +69 -0
  88. package/src/cli/cmd/tui/context/theme/ayu.json +80 -0
  89. package/src/cli/cmd/tui/context/theme/carbonfox.json +248 -0
  90. package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +233 -0
  91. package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +233 -0
  92. package/src/cli/cmd/tui/context/theme/catppuccin.json +112 -0
  93. package/src/cli/cmd/tui/context/theme/cobalt2.json +228 -0
  94. package/src/cli/cmd/tui/context/theme/cursor.json +249 -0
  95. package/src/cli/cmd/tui/context/theme/dracula.json +219 -0
  96. package/src/cli/cmd/tui/context/theme/everforest.json +241 -0
  97. package/src/cli/cmd/tui/context/theme/flexoki.json +237 -0
  98. package/src/cli/cmd/tui/context/theme/github.json +233 -0
  99. package/src/cli/cmd/tui/context/theme/gruvbox.json +95 -0
  100. package/src/cli/cmd/tui/context/theme/kanagawa.json +77 -0
  101. package/src/cli/cmd/tui/context/theme/lucent-orng.json +237 -0
  102. package/src/cli/cmd/tui/context/theme/material.json +235 -0
  103. package/src/cli/cmd/tui/context/theme/matrix.json +77 -0
  104. package/src/cli/cmd/tui/context/theme/mercury.json +252 -0
  105. package/src/cli/cmd/tui/context/theme/monokai.json +221 -0
  106. package/src/cli/cmd/tui/context/theme/nightowl.json +221 -0
  107. package/src/cli/cmd/tui/context/theme/nord.json +223 -0
  108. package/src/cli/cmd/tui/context/theme/one-dark.json +84 -0
  109. package/src/cli/cmd/tui/context/theme/orng.json +249 -0
  110. package/src/cli/cmd/tui/context/theme/osaka-jade.json +93 -0
  111. package/src/cli/cmd/tui/context/theme/palenight.json +222 -0
  112. package/src/cli/cmd/tui/context/theme/rosepine.json +234 -0
  113. package/src/cli/cmd/tui/context/theme/solarized.json +223 -0
  114. package/src/cli/cmd/tui/context/theme/synthwave84.json +226 -0
  115. package/src/cli/cmd/tui/context/theme/tokyonight.json +243 -0
  116. package/src/cli/cmd/tui/context/theme/vercel.json +245 -0
  117. package/src/cli/cmd/tui/context/theme/vesper.json +218 -0
  118. package/src/cli/cmd/tui/context/theme/zenburn.json +223 -0
  119. package/src/cli/cmd/tui/context/theme.tsx +1152 -0
  120. package/src/cli/cmd/tui/event.ts +46 -0
  121. package/src/cli/cmd/tui/routes/home.tsx +141 -0
  122. package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +64 -0
  123. package/src/cli/cmd/tui/routes/session/dialog-message.tsx +109 -0
  124. package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +26 -0
  125. package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +47 -0
  126. package/src/cli/cmd/tui/routes/session/footer.tsx +91 -0
  127. package/src/cli/cmd/tui/routes/session/header.tsx +136 -0
  128. package/src/cli/cmd/tui/routes/session/index.tsx +1936 -0
  129. package/src/cli/cmd/tui/routes/session/permission.tsx +489 -0
  130. package/src/cli/cmd/tui/routes/session/question.tsx +435 -0
  131. package/src/cli/cmd/tui/routes/session/sidebar.tsx +312 -0
  132. package/src/cli/cmd/tui/thread.ts +165 -0
  133. package/src/cli/cmd/tui/ui/dialog-alert.tsx +57 -0
  134. package/src/cli/cmd/tui/ui/dialog-confirm.tsx +83 -0
  135. package/src/cli/cmd/tui/ui/dialog-export-options.tsx +204 -0
  136. package/src/cli/cmd/tui/ui/dialog-help.tsx +38 -0
  137. package/src/cli/cmd/tui/ui/dialog-prompt.tsx +77 -0
  138. package/src/cli/cmd/tui/ui/dialog-select.tsx +354 -0
  139. package/src/cli/cmd/tui/ui/dialog.tsx +167 -0
  140. package/src/cli/cmd/tui/ui/link.tsx +28 -0
  141. package/src/cli/cmd/tui/ui/spinner.ts +368 -0
  142. package/src/cli/cmd/tui/ui/toast.tsx +100 -0
  143. package/src/cli/cmd/tui/util/clipboard.ts +144 -0
  144. package/src/cli/cmd/tui/util/editor.ts +32 -0
  145. package/src/cli/cmd/tui/util/signal.ts +7 -0
  146. package/src/cli/cmd/tui/util/terminal.ts +114 -0
  147. package/src/cli/cmd/tui/util/transcript.ts +98 -0
  148. package/src/cli/cmd/tui/worker.ts +152 -0
  149. package/src/cli/cmd/uninstall.ts +344 -0
  150. package/src/cli/cmd/upgrade.ts +73 -0
  151. package/src/cli/cmd/web.ts +81 -0
  152. package/src/cli/error.ts +57 -0
  153. package/src/cli/network.ts +53 -0
  154. package/src/cli/ui.ts +88 -0
  155. package/src/cli/upgrade.ts +25 -0
  156. package/src/command/index.ts +131 -0
  157. package/src/command/template/initialize.txt +10 -0
  158. package/src/command/template/review.txt +97 -0
  159. package/src/config/config.ts +1246 -0
  160. package/src/config/markdown.ts +93 -0
  161. package/src/env/index.ts +26 -0
  162. package/src/file/ignore.ts +83 -0
  163. package/src/file/index.ts +411 -0
  164. package/src/file/ripgrep.ts +409 -0
  165. package/src/file/time.ts +64 -0
  166. package/src/file/watcher.ts +118 -0
  167. package/src/flag/flag.ts +54 -0
  168. package/src/format/formatter.ts +359 -0
  169. package/src/format/index.ts +137 -0
  170. package/src/global/index.ts +55 -0
  171. package/src/id/id.ts +83 -0
  172. package/src/ide/index.ts +76 -0
  173. package/src/index.ts +159 -0
  174. package/src/installation/index.ts +246 -0
  175. package/src/lsp/client.ts +252 -0
  176. package/src/lsp/index.ts +485 -0
  177. package/src/lsp/language.ts +119 -0
  178. package/src/lsp/server.ts +2032 -0
  179. package/src/mcp/auth.ts +135 -0
  180. package/src/mcp/index.ts +926 -0
  181. package/src/mcp/oauth-callback.ts +200 -0
  182. package/src/mcp/oauth-provider.ts +154 -0
  183. package/src/patch/index.ts +622 -0
  184. package/src/permission/arity.ts +163 -0
  185. package/src/permission/index.ts +210 -0
  186. package/src/permission/next.ts +269 -0
  187. package/src/plugin/codex.ts +493 -0
  188. package/src/plugin/copilot.ts +269 -0
  189. package/src/plugin/index.ts +135 -0
  190. package/src/project/bootstrap.ts +31 -0
  191. package/src/project/instance.ts +91 -0
  192. package/src/project/project.ts +320 -0
  193. package/src/project/state.ts +66 -0
  194. package/src/project/vcs.ts +76 -0
  195. package/src/provider/auth.ts +147 -0
  196. package/src/provider/models-macro.ts +11 -0
  197. package/src/provider/models.ts +112 -0
  198. package/src/provider/provider.ts +1220 -0
  199. package/src/provider/sdk/openai-compatible/src/README.md +5 -0
  200. package/src/provider/sdk/openai-compatible/src/index.ts +2 -0
  201. package/src/provider/sdk/openai-compatible/src/openai-compatible-provider.ts +100 -0
  202. package/src/provider/sdk/openai-compatible/src/responses/convert-to-openai-responses-input.ts +303 -0
  203. package/src/provider/sdk/openai-compatible/src/responses/map-openai-responses-finish-reason.ts +22 -0
  204. package/src/provider/sdk/openai-compatible/src/responses/openai-config.ts +18 -0
  205. package/src/provider/sdk/openai-compatible/src/responses/openai-error.ts +22 -0
  206. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-api-types.ts +207 -0
  207. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-language-model.ts +1713 -0
  208. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-prepare-tools.ts +177 -0
  209. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-settings.ts +1 -0
  210. package/src/provider/sdk/openai-compatible/src/responses/tool/code-interpreter.ts +88 -0
  211. package/src/provider/sdk/openai-compatible/src/responses/tool/file-search.ts +128 -0
  212. package/src/provider/sdk/openai-compatible/src/responses/tool/image-generation.ts +115 -0
  213. package/src/provider/sdk/openai-compatible/src/responses/tool/local-shell.ts +65 -0
  214. package/src/provider/sdk/openai-compatible/src/responses/tool/web-search-preview.ts +104 -0
  215. package/src/provider/sdk/openai-compatible/src/responses/tool/web-search.ts +103 -0
  216. package/src/provider/transform.ts +705 -0
  217. package/src/pty/index.ts +229 -0
  218. package/src/question/index.ts +171 -0
  219. package/src/server/error.ts +36 -0
  220. package/src/server/mdns.ts +59 -0
  221. package/src/server/routes/config.ts +92 -0
  222. package/src/server/routes/experimental.ts +157 -0
  223. package/src/server/routes/file.ts +197 -0
  224. package/src/server/routes/global.ts +135 -0
  225. package/src/server/routes/mcp.ts +225 -0
  226. package/src/server/routes/permission.ts +68 -0
  227. package/src/server/routes/project.ts +82 -0
  228. package/src/server/routes/provider.ts +165 -0
  229. package/src/server/routes/pty.ts +169 -0
  230. package/src/server/routes/question.ts +98 -0
  231. package/src/server/routes/session.ts +935 -0
  232. package/src/server/routes/tui.ts +377 -0
  233. package/src/server/server.ts +578 -0
  234. package/src/session/compaction.ts +225 -0
  235. package/src/session/index.ts +488 -0
  236. package/src/session/llm.ts +279 -0
  237. package/src/session/message-v2.ts +702 -0
  238. package/src/session/message.ts +189 -0
  239. package/src/session/processor.ts +406 -0
  240. package/src/session/prompt/anthropic-20250930.txt +166 -0
  241. package/src/session/prompt/anthropic.txt +105 -0
  242. package/src/session/prompt/anthropic_spoof.txt +1 -0
  243. package/src/session/prompt/beast.txt +147 -0
  244. package/src/session/prompt/build-switch.txt +5 -0
  245. package/src/session/prompt/codex.txt +72 -0
  246. package/src/session/prompt/codex_header.txt +72 -0
  247. package/src/session/prompt/copilot-gpt-5.txt +143 -0
  248. package/src/session/prompt/gemini.txt +155 -0
  249. package/src/session/prompt/max-steps.txt +16 -0
  250. package/src/session/prompt/plan-reminder-anthropic.txt +67 -0
  251. package/src/session/prompt/plan.txt +26 -0
  252. package/src/session/prompt/qwen.txt +109 -0
  253. package/src/session/prompt.ts +1792 -0
  254. package/src/session/retry.ts +90 -0
  255. package/src/session/revert.ts +108 -0
  256. package/src/session/status.ts +76 -0
  257. package/src/session/summary.ts +150 -0
  258. package/src/session/system.ts +138 -0
  259. package/src/session/todo.ts +37 -0
  260. package/src/share/share-next.ts +194 -0
  261. package/src/share/share.ts +87 -0
  262. package/src/shell/shell.ts +67 -0
  263. package/src/skill/index.ts +1 -0
  264. package/src/skill/skill.ts +136 -0
  265. package/src/snapshot/index.ts +199 -0
  266. package/src/storage/storage.ts +227 -0
  267. package/src/tool/bash.ts +258 -0
  268. package/src/tool/bash.txt +115 -0
  269. package/src/tool/batch.ts +175 -0
  270. package/src/tool/batch.txt +24 -0
  271. package/src/tool/codesearch.ts +132 -0
  272. package/src/tool/codesearch.txt +12 -0
  273. package/src/tool/edit.ts +645 -0
  274. package/src/tool/edit.txt +10 -0
  275. package/src/tool/external-directory.ts +32 -0
  276. package/src/tool/glob.ts +77 -0
  277. package/src/tool/glob.txt +6 -0
  278. package/src/tool/grep.ts +154 -0
  279. package/src/tool/grep.txt +8 -0
  280. package/src/tool/invalid.ts +17 -0
  281. package/src/tool/ls.ts +121 -0
  282. package/src/tool/ls.txt +1 -0
  283. package/src/tool/lsp.ts +96 -0
  284. package/src/tool/lsp.txt +19 -0
  285. package/src/tool/multiedit.ts +46 -0
  286. package/src/tool/multiedit.txt +41 -0
  287. package/src/tool/patch.ts +201 -0
  288. package/src/tool/patch.txt +1 -0
  289. package/src/tool/plan-enter.txt +14 -0
  290. package/src/tool/plan-exit.txt +13 -0
  291. package/src/tool/plan.ts +130 -0
  292. package/src/tool/question.ts +33 -0
  293. package/src/tool/question.txt +10 -0
  294. package/src/tool/read.ts +200 -0
  295. package/src/tool/read.txt +12 -0
  296. package/src/tool/registry.ts +143 -0
  297. package/src/tool/skill.ts +75 -0
  298. package/src/tool/task.ts +188 -0
  299. package/src/tool/task.txt +60 -0
  300. package/src/tool/todo.ts +53 -0
  301. package/src/tool/todoread.txt +14 -0
  302. package/src/tool/todowrite.txt +167 -0
  303. package/src/tool/tool.ts +88 -0
  304. package/src/tool/truncation.ts +99 -0
  305. package/src/tool/webfetch.ts +182 -0
  306. package/src/tool/webfetch.txt +13 -0
  307. package/src/tool/websearch.ts +150 -0
  308. package/src/tool/websearch.txt +14 -0
  309. package/src/tool/write.ts +80 -0
  310. package/src/tool/write.txt +8 -0
  311. package/src/util/archive.ts +16 -0
  312. package/src/util/color.ts +19 -0
  313. package/src/util/context.ts +25 -0
  314. package/src/util/defer.ts +12 -0
  315. package/src/util/eventloop.ts +20 -0
  316. package/src/util/filesystem.ts +93 -0
  317. package/src/util/fn.ts +11 -0
  318. package/src/util/format.ts +20 -0
  319. package/src/util/iife.ts +3 -0
  320. package/src/util/keybind.ts +103 -0
  321. package/src/util/lazy.ts +18 -0
  322. package/src/util/locale.ts +81 -0
  323. package/src/util/lock.ts +98 -0
  324. package/src/util/log.ts +180 -0
  325. package/src/util/queue.ts +32 -0
  326. package/src/util/rpc.ts +66 -0
  327. package/src/util/scrap.ts +10 -0
  328. package/src/util/signal.ts +12 -0
  329. package/src/util/timeout.ts +14 -0
  330. package/src/util/token.ts +7 -0
  331. package/src/util/wildcard.ts +56 -0
  332. package/src/worktree/index.ts +217 -0
  333. package/sst-env.d.ts +9 -0
  334. package/test/agent/agent.test.ts +638 -0
  335. package/test/bun.test.ts +53 -0
  336. package/test/cli/github-action.test.ts +129 -0
  337. package/test/cli/github-remote.test.ts +80 -0
  338. package/test/cli/tui/transcript.test.ts +297 -0
  339. package/test/config/agent-color.test.ts +66 -0
  340. package/test/config/config.test.ts +1376 -0
  341. package/test/config/fixtures/empty-frontmatter.md +4 -0
  342. package/test/config/fixtures/frontmatter.md +28 -0
  343. package/test/config/fixtures/no-frontmatter.md +1 -0
  344. package/test/config/markdown.test.ts +192 -0
  345. package/test/file/ignore.test.ts +10 -0
  346. package/test/file/path-traversal.test.ts +198 -0
  347. package/test/fixture/fixture.ts +45 -0
  348. package/test/fixture/lsp/fake-lsp-server.js +77 -0
  349. package/test/ide/ide.test.ts +82 -0
  350. package/test/keybind.test.ts +421 -0
  351. package/test/lsp/client.test.ts +95 -0
  352. package/test/mcp/headers.test.ts +153 -0
  353. package/test/mcp/oauth-browser.test.ts +261 -0
  354. package/test/patch/patch.test.ts +348 -0
  355. package/test/permission/arity.test.ts +33 -0
  356. package/test/permission/next.test.ts +652 -0
  357. package/test/permission-task.test.ts +319 -0
  358. package/test/plugin/codex.test.ts +123 -0
  359. package/test/preload.ts +65 -0
  360. package/test/project/project.test.ts +120 -0
  361. package/test/provider/amazon-bedrock.test.ts +268 -0
  362. package/test/provider/gitlab-duo.test.ts +286 -0
  363. package/test/provider/provider.test.ts +2149 -0
  364. package/test/provider/transform.test.ts +1566 -0
  365. package/test/question/question.test.ts +300 -0
  366. package/test/server/session-list.test.ts +39 -0
  367. package/test/server/session-select.test.ts +78 -0
  368. package/test/session/compaction.test.ts +293 -0
  369. package/test/session/llm.test.ts +90 -0
  370. package/test/session/message-v2.test.ts +662 -0
  371. package/test/session/retry.test.ts +131 -0
  372. package/test/session/revert-compact.test.ts +285 -0
  373. package/test/session/session.test.ts +71 -0
  374. package/test/skill/skill.test.ts +185 -0
  375. package/test/snapshot/snapshot.test.ts +939 -0
  376. package/test/tool/__snapshots__/tool.test.ts.snap +9 -0
  377. package/test/tool/bash.test.ts +320 -0
  378. package/test/tool/external-directory.test.ts +126 -0
  379. package/test/tool/fixtures/large-image.png +0 -0
  380. package/test/tool/fixtures/models-api.json +33453 -0
  381. package/test/tool/grep.test.ts +109 -0
  382. package/test/tool/patch.test.ts +261 -0
  383. package/test/tool/read.test.ts +303 -0
  384. package/test/tool/registry.test.ts +76 -0
  385. package/test/tool/truncation.test.ts +159 -0
  386. package/test/util/filesystem.test.ts +39 -0
  387. package/test/util/format.test.ts +59 -0
  388. package/test/util/iife.test.ts +36 -0
  389. package/test/util/lazy.test.ts +50 -0
  390. package/test/util/lock.test.ts +72 -0
  391. package/test/util/timeout.test.ts +21 -0
  392. package/test/util/wildcard.test.ts +75 -0
  393. package/tsconfig.json +16 -0
@@ -0,0 +1,143 @@
1
+ import { QuestionTool } from "./question"
2
+ import { BashTool } from "./bash"
3
+ import { EditTool } from "./edit"
4
+ import { GlobTool } from "./glob"
5
+ import { GrepTool } from "./grep"
6
+ import { BatchTool } from "./batch"
7
+ import { ReadTool } from "./read"
8
+ import { TaskTool } from "./task"
9
+ import { TodoWriteTool, TodoReadTool } from "./todo"
10
+ import { WebFetchTool } from "./webfetch"
11
+ import { WriteTool } from "./write"
12
+ import { InvalidTool } from "./invalid"
13
+ import { SkillTool } from "./skill"
14
+ import type { Agent } from "../agent/agent"
15
+ import { Tool } from "./tool"
16
+ import { Instance } from "../project/instance"
17
+ import { Config } from "../config/config"
18
+ import path from "path"
19
+ import { type ToolDefinition } from "@codepro-ai/plugin"
20
+ import z from "zod"
21
+ import { Plugin } from "../plugin"
22
+ import { WebSearchTool } from "./websearch"
23
+ import { CodeSearchTool } from "./codesearch"
24
+ import { Flag } from "@/flag/flag"
25
+ import { Log } from "@/util/log"
26
+ import { LspTool } from "./lsp"
27
+ import { Truncate } from "./truncation"
28
+ import { PlanExitTool, PlanEnterTool } from "./plan"
29
+
30
+ export namespace ToolRegistry {
31
+ const log = Log.create({ service: "tool.registry" })
32
+
33
+ export const state = Instance.state(async () => {
34
+ const custom = [] as Tool.Info[]
35
+ const glob = new Bun.Glob("{tool,tools}/*.{js,ts}")
36
+
37
+ for (const dir of await Config.directories()) {
38
+ for await (const match of glob.scan({
39
+ cwd: dir,
40
+ absolute: true,
41
+ followSymlinks: true,
42
+ dot: true,
43
+ })) {
44
+ const namespace = path.basename(match, path.extname(match))
45
+ const mod = await import(match)
46
+ for (const [id, def] of Object.entries<ToolDefinition>(mod)) {
47
+ custom.push(fromPlugin(id === "default" ? namespace : `${namespace}_${id}`, def))
48
+ }
49
+ }
50
+ }
51
+
52
+ const plugins = await Plugin.list()
53
+ for (const plugin of plugins) {
54
+ for (const [id, def] of Object.entries(plugin.tool ?? {})) {
55
+ custom.push(fromPlugin(id, def))
56
+ }
57
+ }
58
+
59
+ return { custom }
60
+ })
61
+
62
+ function fromPlugin(id: string, def: ToolDefinition): Tool.Info {
63
+ return {
64
+ id,
65
+ init: async (initCtx) => ({
66
+ parameters: z.object(def.args),
67
+ description: def.description,
68
+ execute: async (args, ctx) => {
69
+ const result = await def.execute(args as any, ctx)
70
+ const out = await Truncate.output(result, {}, initCtx?.agent)
71
+ return {
72
+ title: "",
73
+ output: out.truncated ? out.content : result,
74
+ metadata: { truncated: out.truncated, outputPath: out.truncated ? out.outputPath : undefined },
75
+ }
76
+ },
77
+ }),
78
+ }
79
+ }
80
+
81
+ export async function register(tool: Tool.Info) {
82
+ const { custom } = await state()
83
+ const idx = custom.findIndex((t) => t.id === tool.id)
84
+ if (idx >= 0) {
85
+ custom.splice(idx, 1, tool)
86
+ return
87
+ }
88
+ custom.push(tool)
89
+ }
90
+
91
+ async function all(): Promise<Tool.Info[]> {
92
+ const custom = await state().then((x) => x.custom)
93
+ const config = await Config.get()
94
+
95
+ return [
96
+ InvalidTool,
97
+ ...(["app", "cli", "desktop"].includes(Flag.OPENCODE_CLIENT) ? [QuestionTool] : []),
98
+ BashTool,
99
+ ReadTool,
100
+ GlobTool,
101
+ GrepTool,
102
+ EditTool,
103
+ WriteTool,
104
+ TaskTool,
105
+ WebFetchTool,
106
+ TodoWriteTool,
107
+ TodoReadTool,
108
+ WebSearchTool,
109
+ CodeSearchTool,
110
+ SkillTool,
111
+ ...(Flag.OPENCODE_EXPERIMENTAL_LSP_TOOL ? [LspTool] : []),
112
+ ...(config.experimental?.batch_tool === true ? [BatchTool] : []),
113
+ ...(Flag.OPENCODE_EXPERIMENTAL_PLAN_MODE && Flag.OPENCODE_CLIENT === "cli" ? [PlanExitTool, PlanEnterTool] : []),
114
+ ...custom,
115
+ ]
116
+ }
117
+
118
+ export async function ids() {
119
+ return all().then((x) => x.map((t) => t.id))
120
+ }
121
+
122
+ export async function tools(providerID: string, agent?: Agent.Info) {
123
+ const tools = await all()
124
+ const result = await Promise.all(
125
+ tools
126
+ .filter((t) => {
127
+ // Enable websearch/codesearch for zen users OR via enable flag
128
+ if (t.id === "codesearch" || t.id === "websearch") {
129
+ return providerID === "opencode" || Flag.OPENCODE_ENABLE_EXA
130
+ }
131
+ return true
132
+ })
133
+ .map(async (t) => {
134
+ using _ = log.time(t.id)
135
+ return {
136
+ id: t.id,
137
+ ...(await t.init({ agent })),
138
+ }
139
+ }),
140
+ )
141
+ return result
142
+ }
143
+ }
@@ -0,0 +1,75 @@
1
+ import path from "path"
2
+ import z from "zod"
3
+ import { Tool } from "./tool"
4
+ import { Skill } from "../skill"
5
+ import { ConfigMarkdown } from "../config/markdown"
6
+ import { PermissionNext } from "../permission/next"
7
+
8
+ const parameters = z.object({
9
+ name: z.string().describe("The skill identifier from available_skills (e.g., 'code-review' or 'category/helper')"),
10
+ })
11
+
12
+ export const SkillTool = Tool.define("skill", async (ctx) => {
13
+ const skills = await Skill.all()
14
+
15
+ // Filter skills by agent permissions if agent provided
16
+ const agent = ctx?.agent
17
+ const accessibleSkills = agent
18
+ ? skills.filter((skill) => {
19
+ const rule = PermissionNext.evaluate("skill", skill.name, agent.permission)
20
+ return rule.action !== "deny"
21
+ })
22
+ : skills
23
+
24
+ const description =
25
+ accessibleSkills.length === 0
26
+ ? "Load a skill to get detailed instructions for a specific task. No skills are currently available."
27
+ : [
28
+ "Load a skill to get detailed instructions for a specific task.",
29
+ "Skills provide specialized knowledge and step-by-step guidance.",
30
+ "Use this when a task matches an available skill's description.",
31
+ "<available_skills>",
32
+ ...accessibleSkills.flatMap((skill) => [
33
+ ` <skill>`,
34
+ ` <name>${skill.name}</name>`,
35
+ ` <description>${skill.description}</description>`,
36
+ ` </skill>`,
37
+ ]),
38
+ "</available_skills>",
39
+ ].join(" ")
40
+
41
+ return {
42
+ description,
43
+ parameters,
44
+ async execute(params: z.infer<typeof parameters>, ctx) {
45
+ const skill = await Skill.get(params.name)
46
+
47
+ if (!skill) {
48
+ const available = await Skill.all().then((x) => Object.keys(x).join(", "))
49
+ throw new Error(`Skill "${params.name}" not found. Available skills: ${available || "none"}`)
50
+ }
51
+
52
+ await ctx.ask({
53
+ permission: "skill",
54
+ patterns: [params.name],
55
+ always: [params.name],
56
+ metadata: {},
57
+ })
58
+ // Load and parse skill content
59
+ const parsed = await ConfigMarkdown.parse(skill.location)
60
+ const dir = path.dirname(skill.location)
61
+
62
+ // Format output similar to plugin pattern
63
+ const output = [`## Skill: ${skill.name}`, "", `**Base directory**: ${dir}`, "", parsed.content.trim()].join("\n")
64
+
65
+ return {
66
+ title: `Loaded skill: ${skill.name}`,
67
+ output,
68
+ metadata: {
69
+ name: skill.name,
70
+ dir,
71
+ },
72
+ }
73
+ },
74
+ }
75
+ })
@@ -0,0 +1,188 @@
1
+ import { Tool } from "./tool"
2
+ import DESCRIPTION from "./task.txt"
3
+ import z from "zod"
4
+ import { Session } from "../session"
5
+ import { Bus } from "../bus"
6
+ import { MessageV2 } from "../session/message-v2"
7
+ import { Identifier } from "../id/id"
8
+ import { Agent } from "../agent/agent"
9
+ import { SessionPrompt } from "../session/prompt"
10
+ import { iife } from "@/util/iife"
11
+ import { defer } from "@/util/defer"
12
+ import { Config } from "../config/config"
13
+ import { PermissionNext } from "@/permission/next"
14
+
15
+ const parameters = z.object({
16
+ description: z.string().describe("A short (3-5 words) description of the task"),
17
+ prompt: z.string().describe("The task for the agent to perform"),
18
+ subagent_type: z.string().describe("The type of specialized agent to use for this task"),
19
+ session_id: z.string().describe("Existing Task session to continue").optional(),
20
+ command: z.string().describe("The command that triggered this task").optional(),
21
+ })
22
+
23
+ export const TaskTool = Tool.define("task", async (ctx) => {
24
+ const agents = await Agent.list().then((x) => x.filter((a) => a.mode !== "primary"))
25
+
26
+ // Filter agents by permissions if agent provided
27
+ const caller = ctx?.agent
28
+ const accessibleAgents = caller
29
+ ? agents.filter((a) => PermissionNext.evaluate("task", a.name, caller.permission).action !== "deny")
30
+ : agents
31
+
32
+ const description = DESCRIPTION.replace(
33
+ "{agents}",
34
+ accessibleAgents
35
+ .map((a) => `- ${a.name}: ${a.description ?? "This subagent should only be called manually by the user."}`)
36
+ .join("\n"),
37
+ )
38
+ return {
39
+ description,
40
+ parameters,
41
+ async execute(params: z.infer<typeof parameters>, ctx) {
42
+ const config = await Config.get()
43
+
44
+ // Skip permission check when user explicitly invoked via @ or command subtask
45
+ if (!ctx.extra?.bypassAgentCheck) {
46
+ await ctx.ask({
47
+ permission: "task",
48
+ patterns: [params.subagent_type],
49
+ always: ["*"],
50
+ metadata: {
51
+ description: params.description,
52
+ subagent_type: params.subagent_type,
53
+ },
54
+ })
55
+ }
56
+
57
+ const agent = await Agent.get(params.subagent_type)
58
+ if (!agent) throw new Error(`Unknown agent type: ${params.subagent_type} is not a valid agent type`)
59
+
60
+ const hasTaskPermission = agent.permission.some((rule) => rule.permission === "task")
61
+
62
+ const session = await iife(async () => {
63
+ if (params.session_id) {
64
+ const found = await Session.get(params.session_id).catch(() => {})
65
+ if (found) return found
66
+ }
67
+
68
+ return await Session.create({
69
+ parentID: ctx.sessionID,
70
+ title: params.description + ` (@${agent.name} subagent)`,
71
+ permission: [
72
+ {
73
+ permission: "todowrite",
74
+ pattern: "*",
75
+ action: "deny",
76
+ },
77
+ {
78
+ permission: "todoread",
79
+ pattern: "*",
80
+ action: "deny",
81
+ },
82
+ ...(hasTaskPermission
83
+ ? []
84
+ : [
85
+ {
86
+ permission: "task" as const,
87
+ pattern: "*" as const,
88
+ action: "deny" as const,
89
+ },
90
+ ]),
91
+ ...(config.experimental?.primary_tools?.map((t) => ({
92
+ pattern: "*",
93
+ action: "allow" as const,
94
+ permission: t,
95
+ })) ?? []),
96
+ ],
97
+ })
98
+ })
99
+ const msg = await MessageV2.get({ sessionID: ctx.sessionID, messageID: ctx.messageID })
100
+ if (msg.info.role !== "assistant") throw new Error("Not an assistant message")
101
+
102
+ ctx.metadata({
103
+ title: params.description,
104
+ metadata: {
105
+ sessionId: session.id,
106
+ },
107
+ })
108
+
109
+ const messageID = Identifier.ascending("message")
110
+ const parts: Record<string, { id: string; tool: string; state: { status: string; title?: string } }> = {}
111
+ const unsub = Bus.subscribe(MessageV2.Event.PartUpdated, async (evt) => {
112
+ if (evt.properties.part.sessionID !== session.id) return
113
+ if (evt.properties.part.messageID === messageID) return
114
+ if (evt.properties.part.type !== "tool") return
115
+ const part = evt.properties.part
116
+ parts[part.id] = {
117
+ id: part.id,
118
+ tool: part.tool,
119
+ state: {
120
+ status: part.state.status,
121
+ title: part.state.status === "completed" ? part.state.title : undefined,
122
+ },
123
+ }
124
+ ctx.metadata({
125
+ title: params.description,
126
+ metadata: {
127
+ summary: Object.values(parts).sort((a, b) => a.id.localeCompare(b.id)),
128
+ sessionId: session.id,
129
+ },
130
+ })
131
+ })
132
+
133
+ const model = agent.model ?? {
134
+ modelID: msg.info.modelID,
135
+ providerID: msg.info.providerID,
136
+ }
137
+
138
+ function cancel() {
139
+ SessionPrompt.cancel(session.id)
140
+ }
141
+ ctx.abort.addEventListener("abort", cancel)
142
+ using _ = defer(() => ctx.abort.removeEventListener("abort", cancel))
143
+ const promptParts = await SessionPrompt.resolvePromptParts(params.prompt)
144
+
145
+ const result = await SessionPrompt.prompt({
146
+ messageID,
147
+ sessionID: session.id,
148
+ model: {
149
+ modelID: model.modelID,
150
+ providerID: model.providerID,
151
+ },
152
+ agent: agent.name,
153
+ tools: {
154
+ todowrite: false,
155
+ todoread: false,
156
+ ...(hasTaskPermission ? {} : { task: false }),
157
+ ...Object.fromEntries((config.experimental?.primary_tools ?? []).map((t) => [t, false])),
158
+ },
159
+ parts: promptParts,
160
+ })
161
+ unsub()
162
+ const messages = await Session.messages({ sessionID: session.id })
163
+ const summary = messages
164
+ .filter((x) => x.info.role === "assistant")
165
+ .flatMap((msg) => msg.parts.filter((x: any) => x.type === "tool") as MessageV2.ToolPart[])
166
+ .map((part) => ({
167
+ id: part.id,
168
+ tool: part.tool,
169
+ state: {
170
+ status: part.state.status,
171
+ title: part.state.status === "completed" ? part.state.title : undefined,
172
+ },
173
+ }))
174
+ const text = result.parts.findLast((x) => x.type === "text")?.text ?? ""
175
+
176
+ const output = text + "\n\n" + ["<task_metadata>", `session_id: ${session.id}`, "</task_metadata>"].join("\n")
177
+
178
+ return {
179
+ title: params.description,
180
+ metadata: {
181
+ summary,
182
+ sessionId: session.id,
183
+ },
184
+ output,
185
+ }
186
+ },
187
+ }
188
+ })
@@ -0,0 +1,60 @@
1
+ Launch a new agent to handle complex, multistep tasks autonomously.
2
+
3
+ Available agent types and the tools they have access to:
4
+ {agents}
5
+
6
+ When using the Task tool, you must specify a subagent_type parameter to select which agent type to use.
7
+
8
+ When to use the Task tool:
9
+ - When you are instructed to execute custom slash commands. Use the Task tool with the slash command invocation as the entire prompt. The slash command can take arguments. For example: Task(description="Check the file", prompt="/check-file path/to/file.py")
10
+
11
+ When NOT to use the Task tool:
12
+ - If you want to read a specific file path, use the Read or Glob tool instead of the Task tool, to find the match more quickly
13
+ - If you are searching for a specific class definition like "class Foo", use the Glob tool instead, to find the match more quickly
14
+ - If you are searching for code within a specific file or set of 2-3 files, use the Read tool instead of the Task tool, to find the match more quickly
15
+ - Other tasks that are not related to the agent descriptions above
16
+
17
+
18
+ Usage notes:
19
+ 1. Launch multiple agents concurrently whenever possible, to maximize performance; to do that, use a single message with multiple tool uses
20
+ 2. When the agent is done, it will return a single message back to you. The result returned by the agent is not visible to the user. To show the user the result, you should send a text message back to the user with a concise summary of the result.
21
+ 3. Each agent invocation is stateless unless you provide a session_id. Your prompt should contain a highly detailed task description for the agent to perform autonomously and you should specify exactly what information the agent should return back to you in its final and only message to you.
22
+ 4. The agent's outputs should generally be trusted
23
+ 5. Clearly tell the agent whether you expect it to write code or just to do research (search, file reads, web fetches, etc.), since it is not aware of the user's intent
24
+ 6. If the agent description mentions that it should be used proactively, then you should try your best to use it without the user having to ask for it first. Use your judgement.
25
+
26
+ Example usage (NOTE: The agents below are fictional examples for illustration only - use the actual agents listed above):
27
+
28
+ <example_agent_descriptions>
29
+ "code-reviewer": use this agent after you are done writing a significant piece of code
30
+ "greeting-responder": use this agent when to respond to user greetings with a friendly joke
31
+ </example_agent_description>
32
+
33
+ <example>
34
+ user: "Please write a function that checks if a number is prime"
35
+ assistant: Sure let me write a function that checks if a number is prime
36
+ assistant: First let me use the Write tool to write a function that checks if a number is prime
37
+ assistant: I'm going to use the Write tool to write the following code:
38
+ <code>
39
+ function isPrime(n) {
40
+ if (n <= 1) return false
41
+ for (let i = 2; i * i <= n; i++) {
42
+ if (n % i === 0) return false
43
+ }
44
+ return true
45
+ }
46
+ </code>
47
+ <commentary>
48
+ Since a significant piece of code was written and the task was completed, now use the code-reviewer agent to review the code
49
+ </commentary>
50
+ assistant: Now let me use the code-reviewer agent to review the code
51
+ assistant: Uses the Task tool to launch the code-reviewer agent
52
+ </example>
53
+
54
+ <example>
55
+ user: "Hello"
56
+ <commentary>
57
+ Since the user is greeting, use the greeting-responder agent to respond with a friendly joke
58
+ </commentary>
59
+ assistant: "I'm going to use the Task tool to launch the with the greeting-responder agent"
60
+ </example>
@@ -0,0 +1,53 @@
1
+ import z from "zod"
2
+ import { Tool } from "./tool"
3
+ import DESCRIPTION_WRITE from "./todowrite.txt"
4
+ import { Todo } from "../session/todo"
5
+
6
+ export const TodoWriteTool = Tool.define("todowrite", {
7
+ description: DESCRIPTION_WRITE,
8
+ parameters: z.object({
9
+ todos: z.array(z.object(Todo.Info.shape)).describe("The updated todo list"),
10
+ }),
11
+ async execute(params, ctx) {
12
+ await ctx.ask({
13
+ permission: "todowrite",
14
+ patterns: ["*"],
15
+ always: ["*"],
16
+ metadata: {},
17
+ })
18
+
19
+ await Todo.update({
20
+ sessionID: ctx.sessionID,
21
+ todos: params.todos,
22
+ })
23
+ return {
24
+ title: `${params.todos.filter((x) => x.status !== "completed").length} todos`,
25
+ output: JSON.stringify(params.todos, null, 2),
26
+ metadata: {
27
+ todos: params.todos,
28
+ },
29
+ }
30
+ },
31
+ })
32
+
33
+ export const TodoReadTool = Tool.define("todoread", {
34
+ description: "Use this tool to read your todo list",
35
+ parameters: z.object({}),
36
+ async execute(_params, ctx) {
37
+ await ctx.ask({
38
+ permission: "todoread",
39
+ patterns: ["*"],
40
+ always: ["*"],
41
+ metadata: {},
42
+ })
43
+
44
+ const todos = await Todo.get(ctx.sessionID)
45
+ return {
46
+ title: `${todos.filter((x) => x.status !== "completed").length} todos`,
47
+ metadata: {
48
+ todos,
49
+ },
50
+ output: JSON.stringify(todos, null, 2),
51
+ }
52
+ },
53
+ })
@@ -0,0 +1,14 @@
1
+ Use this tool to read the current to-do list for the session. This tool should be used proactively and frequently to ensure that you are aware of
2
+ the status of the current task list. You should make use of this tool as often as possible, especially in the following situations:
3
+ - At the beginning of conversations to see what's pending
4
+ - Before starting new tasks to prioritize work
5
+ - When the user asks about previous tasks or plans
6
+ - Whenever you're uncertain about what to do next
7
+ - After completing tasks to update your understanding of remaining work
8
+ - After every few messages to ensure you're on track
9
+
10
+ Usage:
11
+ - This tool takes in no parameters. So leave the input blank or empty. DO NOT include a dummy object, placeholder string or a key like "input" or "empty". LEAVE IT BLANK.
12
+ - Returns a list of todo items with their status, priority, and content
13
+ - Use this information to track progress and plan next steps
14
+ - If no todos exist yet, an empty list will be returned