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,201 @@
1
+ import z from "zod"
2
+ import * as path from "path"
3
+ import * as fs from "fs/promises"
4
+ import { Tool } from "./tool"
5
+ import { FileTime } from "../file/time"
6
+ import { Bus } from "../bus"
7
+ import { FileWatcher } from "../file/watcher"
8
+ import { Instance } from "../project/instance"
9
+ import { Patch } from "../patch"
10
+ import { createTwoFilesPatch } from "diff"
11
+ import { assertExternalDirectory } from "./external-directory"
12
+
13
+ const PatchParams = z.object({
14
+ patchText: z.string().describe("The full patch text that describes all changes to be made"),
15
+ })
16
+
17
+ export const PatchTool = Tool.define("patch", {
18
+ description:
19
+ "Apply a patch to modify multiple files. Supports adding, updating, and deleting files with context-aware changes.",
20
+ parameters: PatchParams,
21
+ async execute(params, ctx) {
22
+ if (!params.patchText) {
23
+ throw new Error("patchText is required")
24
+ }
25
+
26
+ // Parse the patch to get hunks
27
+ let hunks: Patch.Hunk[]
28
+ try {
29
+ const parseResult = Patch.parsePatch(params.patchText)
30
+ hunks = parseResult.hunks
31
+ } catch (error) {
32
+ throw new Error(`Failed to parse patch: ${error}`)
33
+ }
34
+
35
+ if (hunks.length === 0) {
36
+ throw new Error("No file changes found in patch")
37
+ }
38
+
39
+ // Validate file paths and check permissions
40
+ const fileChanges: Array<{
41
+ filePath: string
42
+ oldContent: string
43
+ newContent: string
44
+ type: "add" | "update" | "delete" | "move"
45
+ movePath?: string
46
+ }> = []
47
+
48
+ let totalDiff = ""
49
+
50
+ for (const hunk of hunks) {
51
+ const filePath = path.resolve(Instance.directory, hunk.path)
52
+ await assertExternalDirectory(ctx, filePath)
53
+
54
+ switch (hunk.type) {
55
+ case "add":
56
+ if (hunk.type === "add") {
57
+ const oldContent = ""
58
+ const newContent = hunk.contents
59
+ const diff = createTwoFilesPatch(filePath, filePath, oldContent, newContent)
60
+
61
+ fileChanges.push({
62
+ filePath,
63
+ oldContent,
64
+ newContent,
65
+ type: "add",
66
+ })
67
+
68
+ totalDiff += diff + "\n"
69
+ }
70
+ break
71
+
72
+ case "update":
73
+ // Check if file exists for update
74
+ const stats = await fs.stat(filePath).catch(() => null)
75
+ if (!stats || stats.isDirectory()) {
76
+ throw new Error(`File not found or is directory: ${filePath}`)
77
+ }
78
+
79
+ // Read file and update time tracking (like edit tool does)
80
+ await FileTime.assert(ctx.sessionID, filePath)
81
+ const oldContent = await fs.readFile(filePath, "utf-8")
82
+ let newContent = oldContent
83
+
84
+ // Apply the update chunks to get new content
85
+ try {
86
+ const fileUpdate = Patch.deriveNewContentsFromChunks(filePath, hunk.chunks)
87
+ newContent = fileUpdate.content
88
+ } catch (error) {
89
+ throw new Error(`Failed to apply update to ${filePath}: ${error}`)
90
+ }
91
+
92
+ const diff = createTwoFilesPatch(filePath, filePath, oldContent, newContent)
93
+
94
+ const movePath = hunk.move_path ? path.resolve(Instance.directory, hunk.move_path) : undefined
95
+ await assertExternalDirectory(ctx, movePath)
96
+
97
+ fileChanges.push({
98
+ filePath,
99
+ oldContent,
100
+ newContent,
101
+ type: hunk.move_path ? "move" : "update",
102
+ movePath,
103
+ })
104
+
105
+ totalDiff += diff + "\n"
106
+ break
107
+
108
+ case "delete":
109
+ // Check if file exists for deletion
110
+ await FileTime.assert(ctx.sessionID, filePath)
111
+ const contentToDelete = await fs.readFile(filePath, "utf-8")
112
+ const deleteDiff = createTwoFilesPatch(filePath, filePath, contentToDelete, "")
113
+
114
+ fileChanges.push({
115
+ filePath,
116
+ oldContent: contentToDelete,
117
+ newContent: "",
118
+ type: "delete",
119
+ })
120
+
121
+ totalDiff += deleteDiff + "\n"
122
+ break
123
+ }
124
+ }
125
+
126
+ // Check permissions if needed
127
+ await ctx.ask({
128
+ permission: "edit",
129
+ patterns: fileChanges.map((c) => path.relative(Instance.worktree, c.filePath)),
130
+ always: ["*"],
131
+ metadata: {
132
+ diff: totalDiff,
133
+ },
134
+ })
135
+
136
+ // Apply the changes
137
+ const changedFiles: string[] = []
138
+
139
+ for (const change of fileChanges) {
140
+ switch (change.type) {
141
+ case "add":
142
+ // Create parent directories
143
+ const addDir = path.dirname(change.filePath)
144
+ if (addDir !== "." && addDir !== "/") {
145
+ await fs.mkdir(addDir, { recursive: true })
146
+ }
147
+ await fs.writeFile(change.filePath, change.newContent, "utf-8")
148
+ changedFiles.push(change.filePath)
149
+ break
150
+
151
+ case "update":
152
+ await fs.writeFile(change.filePath, change.newContent, "utf-8")
153
+ changedFiles.push(change.filePath)
154
+ break
155
+
156
+ case "move":
157
+ if (change.movePath) {
158
+ // Create parent directories for destination
159
+ const moveDir = path.dirname(change.movePath)
160
+ if (moveDir !== "." && moveDir !== "/") {
161
+ await fs.mkdir(moveDir, { recursive: true })
162
+ }
163
+ // Write to new location
164
+ await fs.writeFile(change.movePath, change.newContent, "utf-8")
165
+ // Remove original
166
+ await fs.unlink(change.filePath)
167
+ changedFiles.push(change.movePath)
168
+ }
169
+ break
170
+
171
+ case "delete":
172
+ await fs.unlink(change.filePath)
173
+ changedFiles.push(change.filePath)
174
+ break
175
+ }
176
+
177
+ // Update file time tracking
178
+ FileTime.read(ctx.sessionID, change.filePath)
179
+ if (change.movePath) {
180
+ FileTime.read(ctx.sessionID, change.movePath)
181
+ }
182
+ }
183
+
184
+ // Publish file change events
185
+ for (const filePath of changedFiles) {
186
+ await Bus.publish(FileWatcher.Event.Updated, { file: filePath, event: "change" })
187
+ }
188
+
189
+ // Generate output summary
190
+ const relativePaths = changedFiles.map((filePath) => path.relative(Instance.worktree, filePath))
191
+ const summary = `${fileChanges.length} files changed`
192
+
193
+ return {
194
+ title: summary,
195
+ metadata: {
196
+ diff: totalDiff,
197
+ },
198
+ output: `Patch applied successfully. ${summary}:\n${relativePaths.map((p) => ` ${p}`).join("\n")}`,
199
+ }
200
+ },
201
+ })
@@ -0,0 +1 @@
1
+ do not use
@@ -0,0 +1,14 @@
1
+ Use this tool to suggest switching to plan agent when the user's request would benefit from planning before implementation.
2
+
3
+ If they explicitly mention wanting to create a plan ALWAYS call this tool first.
4
+
5
+ This tool will ask the user if they want to switch to plan agent.
6
+
7
+ Call this tool when:
8
+ - The user's request is complex and would benefit from planning first
9
+ - You want to research and design before making changes
10
+ - The task involves multiple files or significant architectural decisions
11
+
12
+ Do NOT call this tool:
13
+ - For simple, straightforward tasks
14
+ - When the user explicitly wants immediate implementation
@@ -0,0 +1,13 @@
1
+ Use this tool when you have completed the planning phase and are ready to exit plan agent.
2
+
3
+ This tool will ask the user if they want to switch to build agent to start implementing the plan.
4
+
5
+ Call this tool:
6
+ - After you have written a complete plan to the plan file
7
+ - After you have clarified any questions with the user
8
+ - When you are confident the plan is ready for implementation
9
+
10
+ Do NOT call this tool:
11
+ - Before you have created or finalized the plan
12
+ - If you still have unanswered questions about the implementation
13
+ - If the user has indicated they want to continue planning
@@ -0,0 +1,130 @@
1
+ import z from "zod"
2
+ import path from "path"
3
+ import { Tool } from "./tool"
4
+ import { Question } from "../question"
5
+ import { Session } from "../session"
6
+ import { MessageV2 } from "../session/message-v2"
7
+ import { Identifier } from "../id/id"
8
+ import { Provider } from "../provider/provider"
9
+ import { Instance } from "../project/instance"
10
+ import EXIT_DESCRIPTION from "./plan-exit.txt"
11
+ import ENTER_DESCRIPTION from "./plan-enter.txt"
12
+
13
+ async function getLastModel(sessionID: string) {
14
+ for await (const item of MessageV2.stream(sessionID)) {
15
+ if (item.info.role === "user" && item.info.model) return item.info.model
16
+ }
17
+ return Provider.defaultModel()
18
+ }
19
+
20
+ export const PlanExitTool = Tool.define("plan_exit", {
21
+ description: EXIT_DESCRIPTION,
22
+ parameters: z.object({}),
23
+ async execute(_params, ctx) {
24
+ const session = await Session.get(ctx.sessionID)
25
+ const plan = path.relative(Instance.worktree, Session.plan(session))
26
+ const answers = await Question.ask({
27
+ sessionID: ctx.sessionID,
28
+ questions: [
29
+ {
30
+ question: `Plan at ${plan} is complete. Would you like to switch to the build agent and start implementing?`,
31
+ header: "Build Agent",
32
+ custom: false,
33
+ options: [
34
+ { label: "Yes", description: "Switch to build agent and start implementing the plan" },
35
+ { label: "No", description: "Stay with plan agent to continue refining the plan" },
36
+ ],
37
+ },
38
+ ],
39
+ tool: ctx.callID ? { messageID: ctx.messageID, callID: ctx.callID } : undefined,
40
+ })
41
+
42
+ const answer = answers[0]?.[0]
43
+ if (answer === "No") throw new Question.RejectedError()
44
+
45
+ const model = await getLastModel(ctx.sessionID)
46
+
47
+ const userMsg: MessageV2.User = {
48
+ id: Identifier.ascending("message"),
49
+ sessionID: ctx.sessionID,
50
+ role: "user",
51
+ time: {
52
+ created: Date.now(),
53
+ },
54
+ agent: "build",
55
+ model,
56
+ }
57
+ await Session.updateMessage(userMsg)
58
+ await Session.updatePart({
59
+ id: Identifier.ascending("part"),
60
+ messageID: userMsg.id,
61
+ sessionID: ctx.sessionID,
62
+ type: "text",
63
+ text: `The plan at ${plan} has been approved, you can now edit files. Execute the plan`,
64
+ synthetic: true,
65
+ } satisfies MessageV2.TextPart)
66
+
67
+ return {
68
+ title: "Switching to build agent",
69
+ output: "User approved switching to build agent. Wait for further instructions.",
70
+ metadata: {},
71
+ }
72
+ },
73
+ })
74
+
75
+ export const PlanEnterTool = Tool.define("plan_enter", {
76
+ description: ENTER_DESCRIPTION,
77
+ parameters: z.object({}),
78
+ async execute(_params, ctx) {
79
+ const session = await Session.get(ctx.sessionID)
80
+ const plan = path.relative(Instance.worktree, Session.plan(session))
81
+
82
+ const answers = await Question.ask({
83
+ sessionID: ctx.sessionID,
84
+ questions: [
85
+ {
86
+ question: `Would you like to switch to the plan agent and create a plan saved to ${plan}?`,
87
+ header: "Plan Mode",
88
+ custom: false,
89
+ options: [
90
+ { label: "Yes", description: "Switch to plan agent for research and planning" },
91
+ { label: "No", description: "Stay with build agent to continue making changes" },
92
+ ],
93
+ },
94
+ ],
95
+ tool: ctx.callID ? { messageID: ctx.messageID, callID: ctx.callID } : undefined,
96
+ })
97
+
98
+ const answer = answers[0]?.[0]
99
+
100
+ if (answer === "No") throw new Question.RejectedError()
101
+
102
+ const model = await getLastModel(ctx.sessionID)
103
+
104
+ const userMsg: MessageV2.User = {
105
+ id: Identifier.ascending("message"),
106
+ sessionID: ctx.sessionID,
107
+ role: "user",
108
+ time: {
109
+ created: Date.now(),
110
+ },
111
+ agent: "plan",
112
+ model,
113
+ }
114
+ await Session.updateMessage(userMsg)
115
+ await Session.updatePart({
116
+ id: Identifier.ascending("part"),
117
+ messageID: userMsg.id,
118
+ sessionID: ctx.sessionID,
119
+ type: "text",
120
+ text: "User has requested to enter plan mode. Switch to plan mode and begin planning.",
121
+ synthetic: true,
122
+ } satisfies MessageV2.TextPart)
123
+
124
+ return {
125
+ title: "Switching to plan agent",
126
+ output: `User confirmed to switch to plan mode. A new message has been created to switch you to plan mode. The plan file will be at ${plan}. Begin planning.`,
127
+ metadata: {},
128
+ }
129
+ },
130
+ })
@@ -0,0 +1,33 @@
1
+ import z from "zod"
2
+ import { Tool } from "./tool"
3
+ import { Question } from "../question"
4
+ import DESCRIPTION from "./question.txt"
5
+
6
+ export const QuestionTool = Tool.define("question", {
7
+ description: DESCRIPTION,
8
+ parameters: z.object({
9
+ questions: z.array(Question.Info.omit({ custom: true })).describe("Questions to ask"),
10
+ }),
11
+ async execute(params, ctx) {
12
+ const answers = await Question.ask({
13
+ sessionID: ctx.sessionID,
14
+ questions: params.questions,
15
+ tool: ctx.callID ? { messageID: ctx.messageID, callID: ctx.callID } : undefined,
16
+ })
17
+
18
+ function format(answer: Question.Answer | undefined) {
19
+ if (!answer?.length) return "Unanswered"
20
+ return answer.join(", ")
21
+ }
22
+
23
+ const formatted = params.questions.map((q, i) => `"${q.question}"="${format(answers[i])}"`).join(", ")
24
+
25
+ return {
26
+ title: `Asked ${params.questions.length} question${params.questions.length > 1 ? "s" : ""}`,
27
+ output: `User has answered your questions: ${formatted}. You can now continue with the user's answers in mind.`,
28
+ metadata: {
29
+ answers,
30
+ },
31
+ }
32
+ },
33
+ })
@@ -0,0 +1,10 @@
1
+ Use this tool when you need to ask the user questions during execution. This allows you to:
2
+ 1. Gather user preferences or requirements
3
+ 2. Clarify ambiguous instructions
4
+ 3. Get decisions on implementation choices as you work
5
+ 4. Offer choices to the user about what direction to take.
6
+
7
+ Usage notes:
8
+ - When `custom` is enabled (default), a "Type your own answer" option is added automatically; don't include "Other" or catch-all options
9
+ - Answers are returned as arrays of labels; set `multiple: true` to allow selecting more than one
10
+ - If you recommend a specific option, make that the first option in the list and add "(Recommended)" at the end of the label
@@ -0,0 +1,200 @@
1
+ import z from "zod"
2
+ import * as fs from "fs"
3
+ import * as path from "path"
4
+ import { Tool } from "./tool"
5
+ import { LSP } from "../lsp"
6
+ import { FileTime } from "../file/time"
7
+ import DESCRIPTION from "./read.txt"
8
+ import { Instance } from "../project/instance"
9
+ import { Identifier } from "../id/id"
10
+ import { assertExternalDirectory } from "./external-directory"
11
+
12
+ const DEFAULT_READ_LIMIT = 2000
13
+ const MAX_LINE_LENGTH = 2000
14
+ const MAX_BYTES = 50 * 1024
15
+
16
+ export const ReadTool = Tool.define("read", {
17
+ description: DESCRIPTION,
18
+ parameters: z.object({
19
+ filePath: z.string().describe("The path to the file to read"),
20
+ offset: z.coerce.number().describe("The line number to start reading from (0-based)").optional(),
21
+ limit: z.coerce.number().describe("The number of lines to read (defaults to 2000)").optional(),
22
+ }),
23
+ async execute(params, ctx) {
24
+ let filepath = params.filePath
25
+ if (!path.isAbsolute(filepath)) {
26
+ filepath = path.join(process.cwd(), filepath)
27
+ }
28
+ const title = path.relative(Instance.worktree, filepath)
29
+
30
+ await assertExternalDirectory(ctx, filepath, {
31
+ bypass: Boolean(ctx.extra?.["bypassCwdCheck"]),
32
+ })
33
+
34
+ await ctx.ask({
35
+ permission: "read",
36
+ patterns: [filepath],
37
+ always: ["*"],
38
+ metadata: {},
39
+ })
40
+
41
+ const file = Bun.file(filepath)
42
+ if (!(await file.exists())) {
43
+ const dir = path.dirname(filepath)
44
+ const base = path.basename(filepath)
45
+
46
+ const dirEntries = fs.readdirSync(dir)
47
+ const suggestions = dirEntries
48
+ .filter(
49
+ (entry) =>
50
+ entry.toLowerCase().includes(base.toLowerCase()) || base.toLowerCase().includes(entry.toLowerCase()),
51
+ )
52
+ .map((entry) => path.join(dir, entry))
53
+ .slice(0, 3)
54
+
55
+ if (suggestions.length > 0) {
56
+ throw new Error(`File not found: ${filepath}\n\nDid you mean one of these?\n${suggestions.join("\n")}`)
57
+ }
58
+
59
+ throw new Error(`File not found: ${filepath}`)
60
+ }
61
+
62
+ const isImage = file.type.startsWith("image/") && file.type !== "image/svg+xml"
63
+ const isPdf = file.type === "application/pdf"
64
+ if (isImage || isPdf) {
65
+ const mime = file.type
66
+ const msg = `${isImage ? "Image" : "PDF"} read successfully`
67
+ return {
68
+ title,
69
+ output: msg,
70
+ metadata: {
71
+ preview: msg,
72
+ truncated: false,
73
+ },
74
+ attachments: [
75
+ {
76
+ id: Identifier.ascending("part"),
77
+ sessionID: ctx.sessionID,
78
+ messageID: ctx.messageID,
79
+ type: "file",
80
+ mime,
81
+ url: `data:${mime};base64,${Buffer.from(await file.bytes()).toString("base64")}`,
82
+ },
83
+ ],
84
+ }
85
+ }
86
+
87
+ const isBinary = await isBinaryFile(filepath, file)
88
+ if (isBinary) throw new Error(`Cannot read binary file: ${filepath}`)
89
+
90
+ const limit = params.limit ?? DEFAULT_READ_LIMIT
91
+ const offset = params.offset || 0
92
+ const lines = await file.text().then((text) => text.split("\n"))
93
+
94
+ const raw: string[] = []
95
+ let bytes = 0
96
+ let truncatedByBytes = false
97
+ for (let i = offset; i < Math.min(lines.length, offset + limit); i++) {
98
+ const line = lines[i].length > MAX_LINE_LENGTH ? lines[i].substring(0, MAX_LINE_LENGTH) + "..." : lines[i]
99
+ const size = Buffer.byteLength(line, "utf-8") + (raw.length > 0 ? 1 : 0)
100
+ if (bytes + size > MAX_BYTES) {
101
+ truncatedByBytes = true
102
+ break
103
+ }
104
+ raw.push(line)
105
+ bytes += size
106
+ }
107
+
108
+ const content = raw.map((line, index) => {
109
+ return `${(index + offset + 1).toString().padStart(5, "0")}| ${line}`
110
+ })
111
+ const preview = raw.slice(0, 20).join("\n")
112
+
113
+ let output = "<file>\n"
114
+ output += content.join("\n")
115
+
116
+ const totalLines = lines.length
117
+ const lastReadLine = offset + raw.length
118
+ const hasMoreLines = totalLines > lastReadLine
119
+ const truncated = hasMoreLines || truncatedByBytes
120
+
121
+ if (truncatedByBytes) {
122
+ output += `\n\n(Output truncated at ${MAX_BYTES} bytes. Use 'offset' parameter to read beyond line ${lastReadLine})`
123
+ } else if (hasMoreLines) {
124
+ output += `\n\n(File has more lines. Use 'offset' parameter to read beyond line ${lastReadLine})`
125
+ } else {
126
+ output += `\n\n(End of file - total ${totalLines} lines)`
127
+ }
128
+ output += "\n</file>"
129
+
130
+ // just warms the lsp client
131
+ LSP.touchFile(filepath, false)
132
+ FileTime.read(ctx.sessionID, filepath)
133
+
134
+ return {
135
+ title,
136
+ output,
137
+ metadata: {
138
+ preview,
139
+ truncated,
140
+ },
141
+ }
142
+ },
143
+ })
144
+
145
+ async function isBinaryFile(filepath: string, file: Bun.BunFile): Promise<boolean> {
146
+ const ext = path.extname(filepath).toLowerCase()
147
+ // binary check for common non-text extensions
148
+ switch (ext) {
149
+ case ".zip":
150
+ case ".tar":
151
+ case ".gz":
152
+ case ".exe":
153
+ case ".dll":
154
+ case ".so":
155
+ case ".class":
156
+ case ".jar":
157
+ case ".war":
158
+ case ".7z":
159
+ case ".doc":
160
+ case ".docx":
161
+ case ".xls":
162
+ case ".xlsx":
163
+ case ".ppt":
164
+ case ".pptx":
165
+ case ".odt":
166
+ case ".ods":
167
+ case ".odp":
168
+ case ".bin":
169
+ case ".dat":
170
+ case ".obj":
171
+ case ".o":
172
+ case ".a":
173
+ case ".lib":
174
+ case ".wasm":
175
+ case ".pyc":
176
+ case ".pyo":
177
+ return true
178
+ default:
179
+ break
180
+ }
181
+
182
+ const stat = await file.stat()
183
+ const fileSize = stat.size
184
+ if (fileSize === 0) return false
185
+
186
+ const bufferSize = Math.min(4096, fileSize)
187
+ const buffer = await file.arrayBuffer()
188
+ if (buffer.byteLength === 0) return false
189
+ const bytes = new Uint8Array(buffer.slice(0, bufferSize))
190
+
191
+ let nonPrintableCount = 0
192
+ for (let i = 0; i < bytes.length; i++) {
193
+ if (bytes[i] === 0) return true
194
+ if (bytes[i] < 9 || (bytes[i] > 13 && bytes[i] < 32)) {
195
+ nonPrintableCount++
196
+ }
197
+ }
198
+ // If >30% non-printable characters, consider it binary
199
+ return nonPrintableCount / bytes.length > 0.3
200
+ }
@@ -0,0 +1,12 @@
1
+ Reads a file from the local filesystem. You can access any file directly by using this tool.
2
+ Assume this tool is able to read all files on the machine. If the User provides a path to a file assume that path is valid. It is okay to read a file that does not exist; an error will be returned.
3
+
4
+ Usage:
5
+ - The filePath parameter must be an absolute path, not a relative path
6
+ - By default, it reads up to 2000 lines starting from the beginning of the file
7
+ - You can optionally specify a line offset and limit (especially handy for long files), but it's recommended to read the whole file by not providing these parameters
8
+ - Any lines longer than 2000 characters will be truncated
9
+ - Results are returned using cat -n format, with line numbers starting at 1
10
+ - You have the capability to call multiple tools in a single response. It is always better to speculatively read multiple files as a batch that are potentially useful.
11
+ - If you read a file that exists but has empty contents you will receive a system reminder warning in place of file contents.
12
+ - You can read image files using this tool.