@stonerzju/opencode 1.2.16-offline.1

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 (496) hide show
  1. package/AGENTS.md +10 -0
  2. package/BUN_SHELL_MIGRATION_PLAN.md +136 -0
  3. package/Dockerfile +18 -0
  4. package/README.md +15 -0
  5. package/bin/opencode +179 -0
  6. package/bunfig.toml +7 -0
  7. package/drizzle.config.ts +10 -0
  8. package/migration/20260127222353_familiar_lady_ursula/migration.sql +90 -0
  9. package/migration/20260127222353_familiar_lady_ursula/snapshot.json +796 -0
  10. package/migration/20260211171708_add_project_commands/migration.sql +1 -0
  11. package/migration/20260211171708_add_project_commands/snapshot.json +806 -0
  12. package/migration/20260213144116_wakeful_the_professor/migration.sql +11 -0
  13. package/migration/20260213144116_wakeful_the_professor/snapshot.json +897 -0
  14. package/migration/20260225215848_workspace/migration.sql +7 -0
  15. package/migration/20260225215848_workspace/snapshot.json +959 -0
  16. package/package.json +140 -0
  17. package/package.json.bak +140 -0
  18. package/parsers-config.ts +254 -0
  19. package/script/build.ts +224 -0
  20. package/script/check-migrations.ts +16 -0
  21. package/script/postinstall.mjs +131 -0
  22. package/script/publish.ts +181 -0
  23. package/script/schema.ts +63 -0
  24. package/script/seed-e2e.ts +50 -0
  25. package/src/acp/README.md +174 -0
  26. package/src/acp/agent.ts +1741 -0
  27. package/src/acp/session.ts +116 -0
  28. package/src/acp/types.ts +23 -0
  29. package/src/agent/agent.ts +339 -0
  30. package/src/agent/generate.txt +75 -0
  31. package/src/agent/prompt/compaction.txt +14 -0
  32. package/src/agent/prompt/explore.txt +18 -0
  33. package/src/agent/prompt/summary.txt +11 -0
  34. package/src/agent/prompt/title.txt +44 -0
  35. package/src/auth/index.ts +68 -0
  36. package/src/bun/index.ts +131 -0
  37. package/src/bun/registry.ts +50 -0
  38. package/src/bus/bus-event.ts +43 -0
  39. package/src/bus/global.ts +10 -0
  40. package/src/bus/index.ts +105 -0
  41. package/src/cli/bootstrap.ts +17 -0
  42. package/src/cli/cmd/acp.ts +70 -0
  43. package/src/cli/cmd/agent.ts +257 -0
  44. package/src/cli/cmd/auth.ts +449 -0
  45. package/src/cli/cmd/cmd.ts +7 -0
  46. package/src/cli/cmd/db.ts +118 -0
  47. package/src/cli/cmd/debug/agent.ts +167 -0
  48. package/src/cli/cmd/debug/config.ts +16 -0
  49. package/src/cli/cmd/debug/file.ts +97 -0
  50. package/src/cli/cmd/debug/index.ts +48 -0
  51. package/src/cli/cmd/debug/lsp.ts +52 -0
  52. package/src/cli/cmd/debug/ripgrep.ts +87 -0
  53. package/src/cli/cmd/debug/scrap.ts +16 -0
  54. package/src/cli/cmd/debug/skill.ts +16 -0
  55. package/src/cli/cmd/debug/snapshot.ts +52 -0
  56. package/src/cli/cmd/export.ts +88 -0
  57. package/src/cli/cmd/generate.ts +38 -0
  58. package/src/cli/cmd/github.ts +1631 -0
  59. package/src/cli/cmd/import.ts +170 -0
  60. package/src/cli/cmd/mcp.ts +754 -0
  61. package/src/cli/cmd/models.ts +77 -0
  62. package/src/cli/cmd/pr.ts +112 -0
  63. package/src/cli/cmd/run.ts +625 -0
  64. package/src/cli/cmd/serve.ts +31 -0
  65. package/src/cli/cmd/session.ts +156 -0
  66. package/src/cli/cmd/stats.ts +410 -0
  67. package/src/cli/cmd/tui/app.tsx +845 -0
  68. package/src/cli/cmd/tui/attach.ts +88 -0
  69. package/src/cli/cmd/tui/component/border.tsx +21 -0
  70. package/src/cli/cmd/tui/component/dialog-agent.tsx +31 -0
  71. package/src/cli/cmd/tui/component/dialog-command.tsx +147 -0
  72. package/src/cli/cmd/tui/component/dialog-mcp.tsx +86 -0
  73. package/src/cli/cmd/tui/component/dialog-model.tsx +165 -0
  74. package/src/cli/cmd/tui/component/dialog-provider.tsx +259 -0
  75. package/src/cli/cmd/tui/component/dialog-session-list.tsx +108 -0
  76. package/src/cli/cmd/tui/component/dialog-session-rename.tsx +31 -0
  77. package/src/cli/cmd/tui/component/dialog-skill.tsx +36 -0
  78. package/src/cli/cmd/tui/component/dialog-stash.tsx +87 -0
  79. package/src/cli/cmd/tui/component/dialog-status.tsx +167 -0
  80. package/src/cli/cmd/tui/component/dialog-tag.tsx +44 -0
  81. package/src/cli/cmd/tui/component/dialog-theme-list.tsx +50 -0
  82. package/src/cli/cmd/tui/component/logo.tsx +85 -0
  83. package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +667 -0
  84. package/src/cli/cmd/tui/component/prompt/frecency.tsx +90 -0
  85. package/src/cli/cmd/tui/component/prompt/history.tsx +108 -0
  86. package/src/cli/cmd/tui/component/prompt/index.tsx +1155 -0
  87. package/src/cli/cmd/tui/component/prompt/stash.tsx +101 -0
  88. package/src/cli/cmd/tui/component/spinner.tsx +24 -0
  89. package/src/cli/cmd/tui/component/textarea-keybindings.ts +73 -0
  90. package/src/cli/cmd/tui/component/tips.tsx +152 -0
  91. package/src/cli/cmd/tui/component/todo-item.tsx +32 -0
  92. package/src/cli/cmd/tui/context/args.tsx +15 -0
  93. package/src/cli/cmd/tui/context/directory.ts +13 -0
  94. package/src/cli/cmd/tui/context/exit.tsx +53 -0
  95. package/src/cli/cmd/tui/context/helper.tsx +25 -0
  96. package/src/cli/cmd/tui/context/keybind.tsx +102 -0
  97. package/src/cli/cmd/tui/context/kv.tsx +52 -0
  98. package/src/cli/cmd/tui/context/local.tsx +406 -0
  99. package/src/cli/cmd/tui/context/prompt.tsx +18 -0
  100. package/src/cli/cmd/tui/context/route.tsx +46 -0
  101. package/src/cli/cmd/tui/context/sdk.tsx +101 -0
  102. package/src/cli/cmd/tui/context/sync.tsx +488 -0
  103. package/src/cli/cmd/tui/context/theme/aura.json +69 -0
  104. package/src/cli/cmd/tui/context/theme/ayu.json +80 -0
  105. package/src/cli/cmd/tui/context/theme/carbonfox.json +248 -0
  106. package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +233 -0
  107. package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +233 -0
  108. package/src/cli/cmd/tui/context/theme/catppuccin.json +112 -0
  109. package/src/cli/cmd/tui/context/theme/cobalt2.json +228 -0
  110. package/src/cli/cmd/tui/context/theme/cursor.json +249 -0
  111. package/src/cli/cmd/tui/context/theme/dracula.json +219 -0
  112. package/src/cli/cmd/tui/context/theme/everforest.json +241 -0
  113. package/src/cli/cmd/tui/context/theme/flexoki.json +237 -0
  114. package/src/cli/cmd/tui/context/theme/github.json +233 -0
  115. package/src/cli/cmd/tui/context/theme/gruvbox.json +242 -0
  116. package/src/cli/cmd/tui/context/theme/kanagawa.json +77 -0
  117. package/src/cli/cmd/tui/context/theme/lucent-orng.json +237 -0
  118. package/src/cli/cmd/tui/context/theme/material.json +235 -0
  119. package/src/cli/cmd/tui/context/theme/matrix.json +77 -0
  120. package/src/cli/cmd/tui/context/theme/mercury.json +252 -0
  121. package/src/cli/cmd/tui/context/theme/monokai.json +221 -0
  122. package/src/cli/cmd/tui/context/theme/nightowl.json +221 -0
  123. package/src/cli/cmd/tui/context/theme/nord.json +223 -0
  124. package/src/cli/cmd/tui/context/theme/one-dark.json +84 -0
  125. package/src/cli/cmd/tui/context/theme/orng.json +249 -0
  126. package/src/cli/cmd/tui/context/theme/osaka-jade.json +93 -0
  127. package/src/cli/cmd/tui/context/theme/palenight.json +222 -0
  128. package/src/cli/cmd/tui/context/theme/rosepine.json +234 -0
  129. package/src/cli/cmd/tui/context/theme/solarized.json +223 -0
  130. package/src/cli/cmd/tui/context/theme/synthwave84.json +226 -0
  131. package/src/cli/cmd/tui/context/theme/tokyonight.json +243 -0
  132. package/src/cli/cmd/tui/context/theme/vercel.json +245 -0
  133. package/src/cli/cmd/tui/context/theme/vesper.json +218 -0
  134. package/src/cli/cmd/tui/context/theme/zenburn.json +223 -0
  135. package/src/cli/cmd/tui/context/theme.tsx +1152 -0
  136. package/src/cli/cmd/tui/context/tui-config.tsx +9 -0
  137. package/src/cli/cmd/tui/event.ts +48 -0
  138. package/src/cli/cmd/tui/routes/home.tsx +145 -0
  139. package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +64 -0
  140. package/src/cli/cmd/tui/routes/session/dialog-message.tsx +109 -0
  141. package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +26 -0
  142. package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +47 -0
  143. package/src/cli/cmd/tui/routes/session/footer.tsx +91 -0
  144. package/src/cli/cmd/tui/routes/session/header.tsx +135 -0
  145. package/src/cli/cmd/tui/routes/session/index.tsx +2219 -0
  146. package/src/cli/cmd/tui/routes/session/permission.tsx +685 -0
  147. package/src/cli/cmd/tui/routes/session/question.tsx +466 -0
  148. package/src/cli/cmd/tui/routes/session/sidebar.tsx +321 -0
  149. package/src/cli/cmd/tui/thread.ts +199 -0
  150. package/src/cli/cmd/tui/ui/dialog-alert.tsx +59 -0
  151. package/src/cli/cmd/tui/ui/dialog-confirm.tsx +85 -0
  152. package/src/cli/cmd/tui/ui/dialog-export-options.tsx +207 -0
  153. package/src/cli/cmd/tui/ui/dialog-help.tsx +40 -0
  154. package/src/cli/cmd/tui/ui/dialog-prompt.tsx +80 -0
  155. package/src/cli/cmd/tui/ui/dialog-select.tsx +401 -0
  156. package/src/cli/cmd/tui/ui/dialog.tsx +182 -0
  157. package/src/cli/cmd/tui/ui/link.tsx +28 -0
  158. package/src/cli/cmd/tui/ui/spinner.ts +368 -0
  159. package/src/cli/cmd/tui/ui/toast.tsx +100 -0
  160. package/src/cli/cmd/tui/util/clipboard.ts +164 -0
  161. package/src/cli/cmd/tui/util/editor.ts +33 -0
  162. package/src/cli/cmd/tui/util/selection.ts +25 -0
  163. package/src/cli/cmd/tui/util/signal.ts +7 -0
  164. package/src/cli/cmd/tui/util/terminal.ts +114 -0
  165. package/src/cli/cmd/tui/util/transcript.ts +98 -0
  166. package/src/cli/cmd/tui/win32.ts +129 -0
  167. package/src/cli/cmd/tui/worker.ts +157 -0
  168. package/src/cli/cmd/uninstall.ts +356 -0
  169. package/src/cli/cmd/upgrade.ts +73 -0
  170. package/src/cli/cmd/web.ts +81 -0
  171. package/src/cli/cmd/workspace-serve.ts +16 -0
  172. package/src/cli/error.ts +57 -0
  173. package/src/cli/logo.ts +6 -0
  174. package/src/cli/network.ts +60 -0
  175. package/src/cli/ui.ts +116 -0
  176. package/src/cli/upgrade.ts +25 -0
  177. package/src/command/index.ts +150 -0
  178. package/src/command/template/initialize.txt +10 -0
  179. package/src/command/template/review.txt +101 -0
  180. package/src/config/config.ts +1408 -0
  181. package/src/config/markdown.ts +99 -0
  182. package/src/config/migrate-tui-config.ts +155 -0
  183. package/src/config/paths.ts +174 -0
  184. package/src/config/tui-schema.ts +34 -0
  185. package/src/config/tui.ts +118 -0
  186. package/src/control/control.sql.ts +22 -0
  187. package/src/control/index.ts +67 -0
  188. package/src/control-plane/adaptors/index.ts +10 -0
  189. package/src/control-plane/adaptors/types.ts +7 -0
  190. package/src/control-plane/adaptors/worktree.ts +26 -0
  191. package/src/control-plane/config.ts +10 -0
  192. package/src/control-plane/session-proxy-middleware.ts +46 -0
  193. package/src/control-plane/sse.ts +66 -0
  194. package/src/control-plane/workspace-server/routes.ts +33 -0
  195. package/src/control-plane/workspace-server/server.ts +24 -0
  196. package/src/control-plane/workspace.sql.ts +12 -0
  197. package/src/control-plane/workspace.ts +160 -0
  198. package/src/env/index.ts +28 -0
  199. package/src/file/ignore.ts +82 -0
  200. package/src/file/index.ts +646 -0
  201. package/src/file/ripgrep.ts +372 -0
  202. package/src/file/time.ts +71 -0
  203. package/src/file/watcher.ts +128 -0
  204. package/src/flag/flag.ts +109 -0
  205. package/src/format/formatter.ts +395 -0
  206. package/src/format/index.ts +140 -0
  207. package/src/global/index.ts +54 -0
  208. package/src/id/id.ts +84 -0
  209. package/src/ide/index.ts +76 -0
  210. package/src/index.ts +210 -0
  211. package/src/installation/index.ts +266 -0
  212. package/src/lsp/client.ts +251 -0
  213. package/src/lsp/index.ts +485 -0
  214. package/src/lsp/language.ts +120 -0
  215. package/src/lsp/server.ts +2142 -0
  216. package/src/mcp/auth.ts +130 -0
  217. package/src/mcp/index.ts +937 -0
  218. package/src/mcp/oauth-callback.ts +200 -0
  219. package/src/mcp/oauth-provider.ts +176 -0
  220. package/src/patch/index.ts +680 -0
  221. package/src/permission/arity.ts +163 -0
  222. package/src/permission/index.ts +210 -0
  223. package/src/permission/next.ts +286 -0
  224. package/src/plugin/codex.ts +624 -0
  225. package/src/plugin/copilot.ts +327 -0
  226. package/src/plugin/index.ts +143 -0
  227. package/src/project/bootstrap.ts +33 -0
  228. package/src/project/instance.ts +114 -0
  229. package/src/project/project.sql.ts +15 -0
  230. package/src/project/project.ts +441 -0
  231. package/src/project/state.ts +70 -0
  232. package/src/project/vcs.ts +76 -0
  233. package/src/provider/auth.ts +147 -0
  234. package/src/provider/error.ts +189 -0
  235. package/src/provider/models.ts +146 -0
  236. package/src/provider/provider.ts +1338 -0
  237. package/src/provider/sdk/copilot/README.md +5 -0
  238. package/src/provider/sdk/copilot/chat/convert-to-openai-compatible-chat-messages.ts +164 -0
  239. package/src/provider/sdk/copilot/chat/get-response-metadata.ts +15 -0
  240. package/src/provider/sdk/copilot/chat/map-openai-compatible-finish-reason.ts +17 -0
  241. package/src/provider/sdk/copilot/chat/openai-compatible-api-types.ts +64 -0
  242. package/src/provider/sdk/copilot/chat/openai-compatible-chat-language-model.ts +780 -0
  243. package/src/provider/sdk/copilot/chat/openai-compatible-chat-options.ts +28 -0
  244. package/src/provider/sdk/copilot/chat/openai-compatible-metadata-extractor.ts +44 -0
  245. package/src/provider/sdk/copilot/chat/openai-compatible-prepare-tools.ts +87 -0
  246. package/src/provider/sdk/copilot/copilot-provider.ts +100 -0
  247. package/src/provider/sdk/copilot/index.ts +2 -0
  248. package/src/provider/sdk/copilot/openai-compatible-error.ts +27 -0
  249. package/src/provider/sdk/copilot/responses/convert-to-openai-responses-input.ts +303 -0
  250. package/src/provider/sdk/copilot/responses/map-openai-responses-finish-reason.ts +22 -0
  251. package/src/provider/sdk/copilot/responses/openai-config.ts +18 -0
  252. package/src/provider/sdk/copilot/responses/openai-error.ts +22 -0
  253. package/src/provider/sdk/copilot/responses/openai-responses-api-types.ts +207 -0
  254. package/src/provider/sdk/copilot/responses/openai-responses-language-model.ts +1732 -0
  255. package/src/provider/sdk/copilot/responses/openai-responses-prepare-tools.ts +177 -0
  256. package/src/provider/sdk/copilot/responses/openai-responses-settings.ts +1 -0
  257. package/src/provider/sdk/copilot/responses/tool/code-interpreter.ts +88 -0
  258. package/src/provider/sdk/copilot/responses/tool/file-search.ts +128 -0
  259. package/src/provider/sdk/copilot/responses/tool/image-generation.ts +115 -0
  260. package/src/provider/sdk/copilot/responses/tool/local-shell.ts +65 -0
  261. package/src/provider/sdk/copilot/responses/tool/web-search-preview.ts +104 -0
  262. package/src/provider/sdk/copilot/responses/tool/web-search.ts +103 -0
  263. package/src/provider/transform.ts +955 -0
  264. package/src/pty/index.ts +324 -0
  265. package/src/question/index.ts +171 -0
  266. package/src/scheduler/index.ts +61 -0
  267. package/src/server/error.ts +36 -0
  268. package/src/server/event.ts +7 -0
  269. package/src/server/mdns.ts +60 -0
  270. package/src/server/routes/config.ts +92 -0
  271. package/src/server/routes/experimental.ts +270 -0
  272. package/src/server/routes/file.ts +197 -0
  273. package/src/server/routes/global.ts +185 -0
  274. package/src/server/routes/mcp.ts +225 -0
  275. package/src/server/routes/permission.ts +68 -0
  276. package/src/server/routes/project.ts +82 -0
  277. package/src/server/routes/provider.ts +165 -0
  278. package/src/server/routes/pty.ts +200 -0
  279. package/src/server/routes/question.ts +98 -0
  280. package/src/server/routes/session.ts +974 -0
  281. package/src/server/routes/tui.ts +379 -0
  282. package/src/server/routes/workspace.ts +104 -0
  283. package/src/server/server.ts +623 -0
  284. package/src/session/compaction.ts +261 -0
  285. package/src/session/index.ts +877 -0
  286. package/src/session/instruction.ts +192 -0
  287. package/src/session/llm.ts +279 -0
  288. package/src/session/message-v2.ts +899 -0
  289. package/src/session/message.ts +189 -0
  290. package/src/session/processor.ts +421 -0
  291. package/src/session/prompt/anthropic-20250930.txt +166 -0
  292. package/src/session/prompt/anthropic.txt +105 -0
  293. package/src/session/prompt/beast.txt +147 -0
  294. package/src/session/prompt/build-switch.txt +5 -0
  295. package/src/session/prompt/codex_header.txt +79 -0
  296. package/src/session/prompt/copilot-gpt-5.txt +143 -0
  297. package/src/session/prompt/gemini.txt +155 -0
  298. package/src/session/prompt/max-steps.txt +16 -0
  299. package/src/session/prompt/plan-reminder-anthropic.txt +67 -0
  300. package/src/session/prompt/plan.txt +26 -0
  301. package/src/session/prompt/qwen.txt +109 -0
  302. package/src/session/prompt/trinity.txt +97 -0
  303. package/src/session/prompt.ts +1959 -0
  304. package/src/session/retry.ts +101 -0
  305. package/src/session/revert.ts +138 -0
  306. package/src/session/session.sql.ts +88 -0
  307. package/src/session/status.ts +76 -0
  308. package/src/session/summary.ts +161 -0
  309. package/src/session/system.ts +54 -0
  310. package/src/session/todo.ts +56 -0
  311. package/src/share/share-next.ts +210 -0
  312. package/src/share/share.sql.ts +13 -0
  313. package/src/shell/shell.ts +68 -0
  314. package/src/skill/discovery.ts +98 -0
  315. package/src/skill/index.ts +1 -0
  316. package/src/skill/skill.ts +189 -0
  317. package/src/snapshot/index.ts +297 -0
  318. package/src/sql.d.ts +4 -0
  319. package/src/storage/db.ts +155 -0
  320. package/src/storage/json-migration.ts +425 -0
  321. package/src/storage/schema.sql.ts +10 -0
  322. package/src/storage/schema.ts +5 -0
  323. package/src/storage/storage.ts +220 -0
  324. package/src/tool/apply_patch.ts +281 -0
  325. package/src/tool/apply_patch.txt +33 -0
  326. package/src/tool/bash.ts +274 -0
  327. package/src/tool/bash.txt +115 -0
  328. package/src/tool/batch.ts +181 -0
  329. package/src/tool/batch.txt +24 -0
  330. package/src/tool/codesearch.ts +132 -0
  331. package/src/tool/codesearch.txt +12 -0
  332. package/src/tool/edit.ts +654 -0
  333. package/src/tool/edit.txt +10 -0
  334. package/src/tool/external-directory.ts +32 -0
  335. package/src/tool/glob.ts +78 -0
  336. package/src/tool/glob.txt +6 -0
  337. package/src/tool/grep.ts +156 -0
  338. package/src/tool/grep.txt +8 -0
  339. package/src/tool/invalid.ts +17 -0
  340. package/src/tool/ls.ts +121 -0
  341. package/src/tool/ls.txt +1 -0
  342. package/src/tool/lsp.ts +97 -0
  343. package/src/tool/lsp.txt +19 -0
  344. package/src/tool/multiedit.ts +46 -0
  345. package/src/tool/multiedit.txt +41 -0
  346. package/src/tool/plan-enter.txt +14 -0
  347. package/src/tool/plan-exit.txt +13 -0
  348. package/src/tool/plan.ts +131 -0
  349. package/src/tool/question.ts +33 -0
  350. package/src/tool/question.txt +10 -0
  351. package/src/tool/read.ts +293 -0
  352. package/src/tool/read.txt +14 -0
  353. package/src/tool/registry.ts +173 -0
  354. package/src/tool/skill.ts +123 -0
  355. package/src/tool/task.ts +165 -0
  356. package/src/tool/task.txt +60 -0
  357. package/src/tool/todo.ts +53 -0
  358. package/src/tool/todoread.txt +14 -0
  359. package/src/tool/todowrite.txt +167 -0
  360. package/src/tool/tool.ts +89 -0
  361. package/src/tool/truncation.ts +107 -0
  362. package/src/tool/webfetch.ts +206 -0
  363. package/src/tool/webfetch.txt +13 -0
  364. package/src/tool/websearch.ts +150 -0
  365. package/src/tool/websearch.txt +14 -0
  366. package/src/tool/write.ts +84 -0
  367. package/src/tool/write.txt +8 -0
  368. package/src/util/abort.ts +35 -0
  369. package/src/util/archive.ts +16 -0
  370. package/src/util/color.ts +19 -0
  371. package/src/util/context.ts +25 -0
  372. package/src/util/defer.ts +12 -0
  373. package/src/util/eventloop.ts +20 -0
  374. package/src/util/filesystem.ts +189 -0
  375. package/src/util/fn.ts +11 -0
  376. package/src/util/format.ts +20 -0
  377. package/src/util/git.ts +35 -0
  378. package/src/util/glob.ts +34 -0
  379. package/src/util/iife.ts +3 -0
  380. package/src/util/keybind.ts +103 -0
  381. package/src/util/lazy.ts +23 -0
  382. package/src/util/locale.ts +81 -0
  383. package/src/util/lock.ts +98 -0
  384. package/src/util/log.ts +182 -0
  385. package/src/util/process.ts +126 -0
  386. package/src/util/proxied.ts +3 -0
  387. package/src/util/queue.ts +32 -0
  388. package/src/util/rpc.ts +66 -0
  389. package/src/util/scrap.ts +10 -0
  390. package/src/util/signal.ts +12 -0
  391. package/src/util/timeout.ts +14 -0
  392. package/src/util/token.ts +7 -0
  393. package/src/util/wildcard.ts +59 -0
  394. package/src/worktree/index.ts +643 -0
  395. package/sst-env.d.ts +10 -0
  396. package/test/AGENTS.md +81 -0
  397. package/test/acp/agent-interface.test.ts +51 -0
  398. package/test/acp/event-subscription.test.ts +683 -0
  399. package/test/agent/agent.test.ts +689 -0
  400. package/test/bun.test.ts +53 -0
  401. package/test/cli/github-action.test.ts +197 -0
  402. package/test/cli/github-remote.test.ts +80 -0
  403. package/test/cli/import.test.ts +38 -0
  404. package/test/cli/plugin-auth-picker.test.ts +120 -0
  405. package/test/cli/tui/transcript.test.ts +322 -0
  406. package/test/config/agent-color.test.ts +71 -0
  407. package/test/config/config.test.ts +1886 -0
  408. package/test/config/fixtures/empty-frontmatter.md +4 -0
  409. package/test/config/fixtures/frontmatter.md +28 -0
  410. package/test/config/fixtures/markdown-header.md +11 -0
  411. package/test/config/fixtures/no-frontmatter.md +1 -0
  412. package/test/config/fixtures/weird-model-id.md +13 -0
  413. package/test/config/markdown.test.ts +228 -0
  414. package/test/config/tui.test.ts +510 -0
  415. package/test/control-plane/session-proxy-middleware.test.ts +147 -0
  416. package/test/control-plane/sse.test.ts +56 -0
  417. package/test/control-plane/workspace-server-sse.test.ts +65 -0
  418. package/test/control-plane/workspace-sync.test.ts +97 -0
  419. package/test/file/ignore.test.ts +10 -0
  420. package/test/file/index.test.ts +394 -0
  421. package/test/file/path-traversal.test.ts +198 -0
  422. package/test/file/ripgrep.test.ts +39 -0
  423. package/test/file/time.test.ts +361 -0
  424. package/test/fixture/db.ts +11 -0
  425. package/test/fixture/fixture.ts +45 -0
  426. package/test/fixture/lsp/fake-lsp-server.js +77 -0
  427. package/test/fixture/skills/agents-sdk/SKILL.md +152 -0
  428. package/test/fixture/skills/agents-sdk/references/callable.md +92 -0
  429. package/test/fixture/skills/cloudflare/SKILL.md +211 -0
  430. package/test/fixture/skills/index.json +6 -0
  431. package/test/ide/ide.test.ts +82 -0
  432. package/test/keybind.test.ts +421 -0
  433. package/test/lsp/client.test.ts +95 -0
  434. package/test/mcp/headers.test.ts +153 -0
  435. package/test/mcp/oauth-browser.test.ts +249 -0
  436. package/test/memory/abort-leak.test.ts +136 -0
  437. package/test/patch/patch.test.ts +348 -0
  438. package/test/permission/arity.test.ts +33 -0
  439. package/test/permission/next.test.ts +689 -0
  440. package/test/permission-task.test.ts +319 -0
  441. package/test/plugin/auth-override.test.ts +44 -0
  442. package/test/plugin/codex.test.ts +123 -0
  443. package/test/preload.ts +80 -0
  444. package/test/project/project.test.ts +348 -0
  445. package/test/project/worktree-remove.test.ts +65 -0
  446. package/test/provider/amazon-bedrock.test.ts +446 -0
  447. package/test/provider/copilot/convert-to-copilot-messages.test.ts +523 -0
  448. package/test/provider/copilot/copilot-chat-model.test.ts +592 -0
  449. package/test/provider/gitlab-duo.test.ts +262 -0
  450. package/test/provider/provider.test.ts +2220 -0
  451. package/test/provider/transform.test.ts +2353 -0
  452. package/test/pty/pty-output-isolation.test.ts +140 -0
  453. package/test/question/question.test.ts +300 -0
  454. package/test/scheduler.test.ts +73 -0
  455. package/test/server/global-session-list.test.ts +89 -0
  456. package/test/server/session-list.test.ts +90 -0
  457. package/test/server/session-select.test.ts +78 -0
  458. package/test/session/compaction.test.ts +423 -0
  459. package/test/session/instruction.test.ts +170 -0
  460. package/test/session/llm.test.ts +667 -0
  461. package/test/session/message-v2.test.ts +924 -0
  462. package/test/session/prompt.test.ts +211 -0
  463. package/test/session/retry.test.ts +188 -0
  464. package/test/session/revert-compact.test.ts +285 -0
  465. package/test/session/session.test.ts +71 -0
  466. package/test/session/structured-output-integration.test.ts +233 -0
  467. package/test/session/structured-output.test.ts +385 -0
  468. package/test/skill/discovery.test.ts +110 -0
  469. package/test/skill/skill.test.ts +388 -0
  470. package/test/snapshot/snapshot.test.ts +1180 -0
  471. package/test/storage/json-migration.test.ts +846 -0
  472. package/test/tool/__snapshots__/tool.test.ts.snap +9 -0
  473. package/test/tool/apply_patch.test.ts +566 -0
  474. package/test/tool/bash.test.ts +402 -0
  475. package/test/tool/edit.test.ts +496 -0
  476. package/test/tool/external-directory.test.ts +127 -0
  477. package/test/tool/fixtures/large-image.png +0 -0
  478. package/test/tool/fixtures/models-api.json +38413 -0
  479. package/test/tool/grep.test.ts +110 -0
  480. package/test/tool/question.test.ts +107 -0
  481. package/test/tool/read.test.ts +504 -0
  482. package/test/tool/registry.test.ts +122 -0
  483. package/test/tool/skill.test.ts +112 -0
  484. package/test/tool/truncation.test.ts +160 -0
  485. package/test/tool/webfetch.test.ts +100 -0
  486. package/test/tool/write.test.ts +348 -0
  487. package/test/util/filesystem.test.ts +443 -0
  488. package/test/util/format.test.ts +59 -0
  489. package/test/util/glob.test.ts +164 -0
  490. package/test/util/iife.test.ts +36 -0
  491. package/test/util/lazy.test.ts +50 -0
  492. package/test/util/lock.test.ts +72 -0
  493. package/test/util/process.test.ts +59 -0
  494. package/test/util/timeout.test.ts +21 -0
  495. package/test/util/wildcard.test.ts +90 -0
  496. package/tsconfig.json +16 -0
@@ -0,0 +1,2142 @@
1
+ import { spawn, type ChildProcessWithoutNullStreams } from "child_process"
2
+ import path from "path"
3
+ import os from "os"
4
+ import { Global } from "../global"
5
+ import { Log } from "../util/log"
6
+ import { BunProc } from "../bun"
7
+ import { $ } from "bun"
8
+ import { text } from "node:stream/consumers"
9
+ import fs from "fs/promises"
10
+ import { Filesystem } from "../util/filesystem"
11
+ import { Instance } from "../project/instance"
12
+ import { Flag } from "../flag/flag"
13
+ import { Archive } from "../util/archive"
14
+ import { Process } from "../util/process"
15
+
16
+ export namespace LSPServer {
17
+ const log = Log.create({ service: "lsp.server" })
18
+
19
+ // Helper function to check offline mode
20
+ function isOfflineMode(): boolean {
21
+ return process.env.OPENCODE_OFFLINE_MODE === "true"
22
+ }
23
+
24
+ const pathExists = async (p: string) =>
25
+ fs
26
+ .stat(p)
27
+ .then(() => true)
28
+ .catch(() => false)
29
+
30
+ export interface Handle {
31
+ process: ChildProcessWithoutNullStreams
32
+ initialization?: Record<string, any>
33
+ }
34
+
35
+ type RootFunction = (file: string) => Promise<string | undefined>
36
+
37
+ const NearestRoot = (includePatterns: string[], excludePatterns?: string[]): RootFunction => {
38
+ return async (file) => {
39
+ if (excludePatterns) {
40
+ const excludedFiles = Filesystem.up({
41
+ targets: excludePatterns,
42
+ start: path.dirname(file),
43
+ stop: Instance.directory,
44
+ })
45
+ const excluded = await excludedFiles.next()
46
+ await excludedFiles.return()
47
+ if (excluded.value) return undefined
48
+ }
49
+ const files = Filesystem.up({
50
+ targets: includePatterns,
51
+ start: path.dirname(file),
52
+ stop: Instance.directory,
53
+ })
54
+ const first = await files.next()
55
+ await files.return()
56
+ if (!first.value) return Instance.directory
57
+ return path.dirname(first.value)
58
+ }
59
+ }
60
+
61
+ export interface Info {
62
+ id: string
63
+ extensions: string[]
64
+ global?: boolean
65
+ root: RootFunction
66
+ spawn(root: string): Promise<Handle | undefined>
67
+ }
68
+
69
+ export const Deno: Info = {
70
+ id: "deno",
71
+ root: async (file) => {
72
+ const files = Filesystem.up({
73
+ targets: ["deno.json", "deno.jsonc"],
74
+ start: path.dirname(file),
75
+ stop: Instance.directory,
76
+ })
77
+ const first = await files.next()
78
+ await files.return()
79
+ if (!first.value) return undefined
80
+ return path.dirname(first.value)
81
+ },
82
+ extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs"],
83
+ async spawn(root) {
84
+ const deno = Bun.which("deno")
85
+ if (!deno) {
86
+ log.info("deno not found, please install deno first")
87
+ return
88
+ }
89
+ return {
90
+ process: spawn(deno, ["lsp"], {
91
+ cwd: root,
92
+ }),
93
+ }
94
+ },
95
+ }
96
+
97
+ export const Typescript: Info = {
98
+ id: "typescript",
99
+ root: NearestRoot(
100
+ ["package-lock.json", "bun.lockb", "bun.lock", "pnpm-lock.yaml", "yarn.lock"],
101
+ ["deno.json", "deno.jsonc"],
102
+ ),
103
+ extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts"],
104
+ async spawn(root) {
105
+ const tsserver = await Bun.resolve("typescript/lib/tsserver.js", Instance.directory).catch(() => {})
106
+ log.info("typescript server", { tsserver })
107
+ if (!tsserver) return
108
+ const proc = spawn(BunProc.which(), ["x", "typescript-language-server", "--stdio"], {
109
+ cwd: root,
110
+ env: {
111
+ ...process.env,
112
+ BUN_BE_BUN: "1",
113
+ },
114
+ })
115
+ return {
116
+ process: proc,
117
+ initialization: {
118
+ tsserver: {
119
+ path: tsserver,
120
+ },
121
+ },
122
+ }
123
+ },
124
+ }
125
+
126
+ export const Vue: Info = {
127
+ id: "vue",
128
+ extensions: [".vue"],
129
+ root: NearestRoot(["package-lock.json", "bun.lockb", "bun.lock", "pnpm-lock.yaml", "yarn.lock"]),
130
+ async spawn(root) {
131
+ let binary = Bun.which("vue-language-server")
132
+ const args: string[] = []
133
+ if (!binary) {
134
+ const js = path.join(
135
+ Global.Path.bin,
136
+ "node_modules",
137
+ "@vue",
138
+ "language-server",
139
+ "bin",
140
+ "vue-language-server.js",
141
+ )
142
+ if (!(await Filesystem.exists(js))) {
143
+ if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
144
+ await Process.spawn([BunProc.which(), "install", "@vue/language-server"], {
145
+ cwd: Global.Path.bin,
146
+ env: {
147
+ ...process.env,
148
+ BUN_BE_BUN: "1",
149
+ },
150
+ stdout: "pipe",
151
+ stderr: "pipe",
152
+ stdin: "pipe",
153
+ }).exited
154
+ }
155
+ binary = BunProc.which()
156
+ args.push("run", js)
157
+ }
158
+ args.push("--stdio")
159
+ const proc = spawn(binary, args, {
160
+ cwd: root,
161
+ env: {
162
+ ...process.env,
163
+ BUN_BE_BUN: "1",
164
+ },
165
+ })
166
+ return {
167
+ process: proc,
168
+ initialization: {
169
+ // Leave empty; the server will auto-detect workspace TypeScript.
170
+ },
171
+ }
172
+ },
173
+ }
174
+
175
+ export const ESLint: Info = {
176
+ id: "eslint",
177
+ root: NearestRoot(["package-lock.json", "bun.lockb", "bun.lock", "pnpm-lock.yaml", "yarn.lock"]),
178
+ extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts", ".vue"],
179
+ async spawn(root) {
180
+ const eslint = await Bun.resolve("eslint", Instance.directory).catch(() => {})
181
+ if (!eslint) return
182
+ log.info("spawning eslint server")
183
+ const serverPath = path.join(Global.Path.bin, "vscode-eslint", "server", "out", "eslintServer.js")
184
+ if (!(await Filesystem.exists(serverPath))) {
185
+ if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
186
+
187
+ // Offline mode: skip download
188
+ if (isOfflineMode()) {
189
+ log.warn("offline mode: cannot download VS Code ESLint server")
190
+ log.warn("please install manually: bun install -g @vue/language-server")
191
+ return
192
+ }
193
+
194
+ log.info("downloading and building VS Code ESLint server")
195
+ const response = await fetch("https://github.com/microsoft/vscode-eslint/archive/refs/heads/main.zip")
196
+ if (!response.ok) return
197
+
198
+ const zipPath = path.join(Global.Path.bin, "vscode-eslint.zip")
199
+ if (response.body) await Filesystem.writeStream(zipPath, response.body)
200
+
201
+ const ok = await Archive.extractZip(zipPath, Global.Path.bin)
202
+ .then(() => true)
203
+ .catch((error) => {
204
+ log.error("Failed to extract vscode-eslint archive", { error })
205
+ return false
206
+ })
207
+ if (!ok) return
208
+ await fs.rm(zipPath, { force: true })
209
+
210
+ const extractedPath = path.join(Global.Path.bin, "vscode-eslint-main")
211
+ const finalPath = path.join(Global.Path.bin, "vscode-eslint")
212
+
213
+ const stats = await fs.stat(finalPath).catch(() => undefined)
214
+ if (stats) {
215
+ log.info("removing old eslint installation", { path: finalPath })
216
+ await fs.rm(finalPath, { force: true, recursive: true })
217
+ }
218
+ await fs.rename(extractedPath, finalPath)
219
+
220
+ const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm"
221
+ await $`${npmCmd} install`.cwd(finalPath).quiet()
222
+ await $`${npmCmd} run compile`.cwd(finalPath).quiet()
223
+
224
+ log.info("installed VS Code ESLint server", { serverPath })
225
+ }
226
+
227
+ const proc = spawn(BunProc.which(), [serverPath, "--stdio"], {
228
+ cwd: root,
229
+ env: {
230
+ ...process.env,
231
+ BUN_BE_BUN: "1",
232
+ },
233
+ })
234
+
235
+ return {
236
+ process: proc,
237
+ }
238
+ },
239
+ }
240
+
241
+ export const Oxlint: Info = {
242
+ id: "oxlint",
243
+ root: NearestRoot([
244
+ ".oxlintrc.json",
245
+ "package-lock.json",
246
+ "bun.lockb",
247
+ "bun.lock",
248
+ "pnpm-lock.yaml",
249
+ "yarn.lock",
250
+ "package.json",
251
+ ]),
252
+ extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts", ".vue", ".astro", ".svelte"],
253
+ async spawn(root) {
254
+ const ext = process.platform === "win32" ? ".cmd" : ""
255
+
256
+ const serverTarget = path.join("node_modules", ".bin", "oxc_language_server" + ext)
257
+ const lintTarget = path.join("node_modules", ".bin", "oxlint" + ext)
258
+
259
+ const resolveBin = async (target: string) => {
260
+ const localBin = path.join(root, target)
261
+ if (await Filesystem.exists(localBin)) return localBin
262
+
263
+ const candidates = Filesystem.up({
264
+ targets: [target],
265
+ start: root,
266
+ stop: Instance.worktree,
267
+ })
268
+ const first = await candidates.next()
269
+ await candidates.return()
270
+ if (first.value) return first.value
271
+
272
+ return undefined
273
+ }
274
+
275
+ let lintBin = await resolveBin(lintTarget)
276
+ if (!lintBin) {
277
+ const found = Bun.which("oxlint")
278
+ if (found) lintBin = found
279
+ }
280
+
281
+ if (lintBin) {
282
+ const proc = Process.spawn([lintBin, "--help"], { stdout: "pipe" })
283
+ await proc.exited
284
+ if (proc.stdout) {
285
+ const help = await text(proc.stdout)
286
+ if (help.includes("--lsp")) {
287
+ return {
288
+ process: spawn(lintBin, ["--lsp"], {
289
+ cwd: root,
290
+ }),
291
+ }
292
+ }
293
+ }
294
+ }
295
+
296
+ let serverBin = await resolveBin(serverTarget)
297
+ if (!serverBin) {
298
+ const found = Bun.which("oxc_language_server")
299
+ if (found) serverBin = found
300
+ }
301
+ if (serverBin) {
302
+ return {
303
+ process: spawn(serverBin, [], {
304
+ cwd: root,
305
+ }),
306
+ }
307
+ }
308
+
309
+ log.info("oxlint not found, please install oxlint")
310
+ return
311
+ },
312
+ }
313
+
314
+ export const Biome: Info = {
315
+ id: "biome",
316
+ root: NearestRoot([
317
+ "biome.json",
318
+ "biome.jsonc",
319
+ "package-lock.json",
320
+ "bun.lockb",
321
+ "bun.lock",
322
+ "pnpm-lock.yaml",
323
+ "yarn.lock",
324
+ ]),
325
+ extensions: [
326
+ ".ts",
327
+ ".tsx",
328
+ ".js",
329
+ ".jsx",
330
+ ".mjs",
331
+ ".cjs",
332
+ ".mts",
333
+ ".cts",
334
+ ".json",
335
+ ".jsonc",
336
+ ".vue",
337
+ ".astro",
338
+ ".svelte",
339
+ ".css",
340
+ ".graphql",
341
+ ".gql",
342
+ ".html",
343
+ ],
344
+ async spawn(root) {
345
+ const localBin = path.join(root, "node_modules", ".bin", "biome")
346
+ let bin: string | undefined
347
+ if (await Filesystem.exists(localBin)) bin = localBin
348
+ if (!bin) {
349
+ const found = Bun.which("biome")
350
+ if (found) bin = found
351
+ }
352
+
353
+ let args = ["lsp-proxy", "--stdio"]
354
+
355
+ if (!bin) {
356
+ const resolved = await Bun.resolve("biome", root).catch(() => undefined)
357
+ if (!resolved) return
358
+ bin = BunProc.which()
359
+ args = ["x", "biome", "lsp-proxy", "--stdio"]
360
+ }
361
+
362
+ const proc = spawn(bin, args, {
363
+ cwd: root,
364
+ env: {
365
+ ...process.env,
366
+ BUN_BE_BUN: "1",
367
+ },
368
+ })
369
+
370
+ return {
371
+ process: proc,
372
+ }
373
+ },
374
+ }
375
+
376
+ export const Gopls: Info = {
377
+ id: "gopls",
378
+ root: async (file) => {
379
+ const work = await NearestRoot(["go.work"])(file)
380
+ if (work) return work
381
+ return NearestRoot(["go.mod", "go.sum"])(file)
382
+ },
383
+ extensions: [".go"],
384
+ async spawn(root) {
385
+ let bin = Bun.which("gopls", {
386
+ PATH: process.env["PATH"] + path.delimiter + Global.Path.bin,
387
+ })
388
+ if (!bin) {
389
+ if (!Bun.which("go")) return
390
+ if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
391
+
392
+ log.info("installing gopls")
393
+ const proc = Process.spawn(["go", "install", "golang.org/x/tools/gopls@latest"], {
394
+ env: { ...process.env, GOBIN: Global.Path.bin },
395
+ stdout: "pipe",
396
+ stderr: "pipe",
397
+ stdin: "pipe",
398
+ })
399
+ const exit = await proc.exited
400
+ if (exit !== 0) {
401
+ log.error("Failed to install gopls")
402
+ return
403
+ }
404
+ bin = path.join(Global.Path.bin, "gopls" + (process.platform === "win32" ? ".exe" : ""))
405
+ log.info(`installed gopls`, {
406
+ bin,
407
+ })
408
+ }
409
+ return {
410
+ process: spawn(bin!, {
411
+ cwd: root,
412
+ }),
413
+ }
414
+ },
415
+ }
416
+
417
+ export const Rubocop: Info = {
418
+ id: "ruby-lsp",
419
+ root: NearestRoot(["Gemfile"]),
420
+ extensions: [".rb", ".rake", ".gemspec", ".ru"],
421
+ async spawn(root) {
422
+ let bin = Bun.which("rubocop", {
423
+ PATH: process.env["PATH"] + path.delimiter + Global.Path.bin,
424
+ })
425
+ if (!bin) {
426
+ const ruby = Bun.which("ruby")
427
+ const gem = Bun.which("gem")
428
+ if (!ruby || !gem) {
429
+ log.info("Ruby not found, please install Ruby first")
430
+ return
431
+ }
432
+ if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
433
+ log.info("installing rubocop")
434
+ const proc = Process.spawn(["gem", "install", "rubocop", "--bindir", Global.Path.bin], {
435
+ stdout: "pipe",
436
+ stderr: "pipe",
437
+ stdin: "pipe",
438
+ })
439
+ const exit = await proc.exited
440
+ if (exit !== 0) {
441
+ log.error("Failed to install rubocop")
442
+ return
443
+ }
444
+ bin = path.join(Global.Path.bin, "rubocop" + (process.platform === "win32" ? ".exe" : ""))
445
+ log.info(`installed rubocop`, {
446
+ bin,
447
+ })
448
+ }
449
+ return {
450
+ process: spawn(bin!, ["--lsp"], {
451
+ cwd: root,
452
+ }),
453
+ }
454
+ },
455
+ }
456
+
457
+ export const Ty: Info = {
458
+ id: "ty",
459
+ extensions: [".py", ".pyi"],
460
+ root: NearestRoot([
461
+ "pyproject.toml",
462
+ "ty.toml",
463
+ "setup.py",
464
+ "setup.cfg",
465
+ "requirements.txt",
466
+ "Pipfile",
467
+ "pyrightconfig.json",
468
+ ]),
469
+ async spawn(root) {
470
+ if (!Flag.OPENCODE_EXPERIMENTAL_LSP_TY) {
471
+ return undefined
472
+ }
473
+
474
+ let binary = Bun.which("ty")
475
+
476
+ const initialization: Record<string, string> = {}
477
+
478
+ const potentialVenvPaths = [process.env["VIRTUAL_ENV"], path.join(root, ".venv"), path.join(root, "venv")].filter(
479
+ (p): p is string => p !== undefined,
480
+ )
481
+ for (const venvPath of potentialVenvPaths) {
482
+ const isWindows = process.platform === "win32"
483
+ const potentialPythonPath = isWindows
484
+ ? path.join(venvPath, "Scripts", "python.exe")
485
+ : path.join(venvPath, "bin", "python")
486
+ if (await Filesystem.exists(potentialPythonPath)) {
487
+ initialization["pythonPath"] = potentialPythonPath
488
+ break
489
+ }
490
+ }
491
+
492
+ if (!binary) {
493
+ for (const venvPath of potentialVenvPaths) {
494
+ const isWindows = process.platform === "win32"
495
+ const potentialTyPath = isWindows
496
+ ? path.join(venvPath, "Scripts", "ty.exe")
497
+ : path.join(venvPath, "bin", "ty")
498
+ if (await Filesystem.exists(potentialTyPath)) {
499
+ binary = potentialTyPath
500
+ break
501
+ }
502
+ }
503
+ }
504
+
505
+ if (!binary) {
506
+ log.error("ty not found, please install ty first")
507
+ return
508
+ }
509
+
510
+ const proc = spawn(binary, ["server"], {
511
+ cwd: root,
512
+ })
513
+
514
+ return {
515
+ process: proc,
516
+ initialization,
517
+ }
518
+ },
519
+ }
520
+
521
+ export const Pyright: Info = {
522
+ id: "pyright",
523
+ extensions: [".py", ".pyi"],
524
+ root: NearestRoot(["pyproject.toml", "setup.py", "setup.cfg", "requirements.txt", "Pipfile", "pyrightconfig.json"]),
525
+ async spawn(root) {
526
+ let binary = Bun.which("pyright-langserver")
527
+ const args = []
528
+ if (!binary) {
529
+ const js = path.join(Global.Path.bin, "node_modules", "pyright", "dist", "pyright-langserver.js")
530
+ if (!(await Filesystem.exists(js))) {
531
+ if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
532
+ await Process.spawn([BunProc.which(), "install", "pyright"], {
533
+ cwd: Global.Path.bin,
534
+ env: {
535
+ ...process.env,
536
+ BUN_BE_BUN: "1",
537
+ },
538
+ }).exited
539
+ }
540
+ binary = BunProc.which()
541
+ args.push(...["run", js])
542
+ }
543
+ args.push("--stdio")
544
+
545
+ const initialization: Record<string, string> = {}
546
+
547
+ const potentialVenvPaths = [process.env["VIRTUAL_ENV"], path.join(root, ".venv"), path.join(root, "venv")].filter(
548
+ (p): p is string => p !== undefined,
549
+ )
550
+ for (const venvPath of potentialVenvPaths) {
551
+ const isWindows = process.platform === "win32"
552
+ const potentialPythonPath = isWindows
553
+ ? path.join(venvPath, "Scripts", "python.exe")
554
+ : path.join(venvPath, "bin", "python")
555
+ if (await Filesystem.exists(potentialPythonPath)) {
556
+ initialization["pythonPath"] = potentialPythonPath
557
+ break
558
+ }
559
+ }
560
+
561
+ const proc = spawn(binary, args, {
562
+ cwd: root,
563
+ env: {
564
+ ...process.env,
565
+ BUN_BE_BUN: "1",
566
+ },
567
+ })
568
+ return {
569
+ process: proc,
570
+ initialization,
571
+ }
572
+ },
573
+ }
574
+
575
+ export const ElixirLS: Info = {
576
+ id: "elixir-ls",
577
+ extensions: [".ex", ".exs"],
578
+ root: NearestRoot(["mix.exs", "mix.lock"]),
579
+ async spawn(root) {
580
+ let binary = Bun.which("elixir-ls")
581
+ if (!binary) {
582
+ const elixirLsPath = path.join(Global.Path.bin, "elixir-ls")
583
+ binary = path.join(
584
+ Global.Path.bin,
585
+ "elixir-ls-master",
586
+ "release",
587
+ process.platform === "win32" ? "language_server.bat" : "language_server.sh",
588
+ )
589
+
590
+ if (!(await Filesystem.exists(binary))) {
591
+ const elixir = Bun.which("elixir")
592
+ if (!elixir) {
593
+ log.error("elixir is required to run elixir-ls")
594
+ return
595
+ }
596
+
597
+ if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
598
+
599
+ // Offline mode: skip download
600
+ if (isOfflineMode()) {
601
+ log.warn("offline mode: cannot download elixir-ls")
602
+ log.warn("please install manually: mix archive.install hex elixir_ls")
603
+ return
604
+ }
605
+
606
+ log.info("downloading elixir-ls from GitHub releases")
607
+
608
+ const response = await fetch("https://github.com/elixir-lsp/elixir-ls/archive/refs/heads/master.zip")
609
+ if (!response.ok) return
610
+ const zipPath = path.join(Global.Path.bin, "elixir-ls.zip")
611
+ if (response.body) await Filesystem.writeStream(zipPath, response.body)
612
+
613
+ const ok = await Archive.extractZip(zipPath, Global.Path.bin)
614
+ .then(() => true)
615
+ .catch((error) => {
616
+ log.error("Failed to extract elixir-ls archive", { error })
617
+ return false
618
+ })
619
+ if (!ok) return
620
+
621
+ await fs.rm(zipPath, {
622
+ force: true,
623
+ recursive: true,
624
+ })
625
+
626
+ await $`mix deps.get && mix compile && mix elixir_ls.release2 -o release`
627
+ .quiet()
628
+ .cwd(path.join(Global.Path.bin, "elixir-ls-master"))
629
+ .env({ MIX_ENV: "prod", ...process.env })
630
+
631
+ log.info(`installed elixir-ls`, {
632
+ path: elixirLsPath,
633
+ })
634
+ }
635
+ }
636
+
637
+ return {
638
+ process: spawn(binary, {
639
+ cwd: root,
640
+ }),
641
+ }
642
+ },
643
+ }
644
+
645
+ export const Zls: Info = {
646
+ id: "zls",
647
+ extensions: [".zig", ".zon"],
648
+ root: NearestRoot(["build.zig"]),
649
+ async spawn(root) {
650
+ let bin = Bun.which("zls", {
651
+ PATH: process.env["PATH"] + path.delimiter + Global.Path.bin,
652
+ })
653
+
654
+ if (!bin) {
655
+ const zig = Bun.which("zig")
656
+ if (!zig) {
657
+ log.error("Zig is required to use zls. Please install Zig first.")
658
+ return
659
+ }
660
+
661
+ if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
662
+
663
+ // Offline mode: skip download
664
+ if (isOfflineMode()) {
665
+ log.warn("offline mode: cannot download zls")
666
+ log.warn("please install manually from https://github.com/zigtools/zls/releases")
667
+ return
668
+ }
669
+
670
+ log.info("downloading zls from GitHub releases")
671
+
672
+ const releaseResponse = await fetch("https://api.github.com/repos/zigtools/zls/releases/latest")
673
+ if (!releaseResponse.ok) {
674
+ log.error("Failed to fetch zls release info")
675
+ return
676
+ }
677
+
678
+ const release = (await releaseResponse.json()) as any
679
+
680
+ const platform = process.platform
681
+ const arch = process.arch
682
+ let assetName = ""
683
+
684
+ let zlsArch: string = arch
685
+ if (arch === "arm64") zlsArch = "aarch64"
686
+ else if (arch === "x64") zlsArch = "x86_64"
687
+ else if (arch === "ia32") zlsArch = "x86"
688
+
689
+ let zlsPlatform: string = platform
690
+ if (platform === "darwin") zlsPlatform = "macos"
691
+ else if (platform === "win32") zlsPlatform = "windows"
692
+
693
+ const ext = platform === "win32" ? "zip" : "tar.xz"
694
+
695
+ assetName = `zls-${zlsArch}-${zlsPlatform}.${ext}`
696
+
697
+ const supportedCombos = [
698
+ "zls-x86_64-linux.tar.xz",
699
+ "zls-x86_64-macos.tar.xz",
700
+ "zls-x86_64-windows.zip",
701
+ "zls-aarch64-linux.tar.xz",
702
+ "zls-aarch64-macos.tar.xz",
703
+ "zls-aarch64-windows.zip",
704
+ "zls-x86-linux.tar.xz",
705
+ "zls-x86-windows.zip",
706
+ ]
707
+
708
+ if (!supportedCombos.includes(assetName)) {
709
+ log.error(`Platform ${platform} and architecture ${arch} is not supported by zls`)
710
+ return
711
+ }
712
+
713
+ const asset = release.assets.find((a: any) => a.name === assetName)
714
+ if (!asset) {
715
+ log.error(`Could not find asset ${assetName} in latest zls release`)
716
+ return
717
+ }
718
+
719
+ const downloadUrl = asset.browser_download_url
720
+ const downloadResponse = await fetch(downloadUrl)
721
+ if (!downloadResponse.ok) {
722
+ log.error("Failed to download zls")
723
+ return
724
+ }
725
+
726
+ const tempPath = path.join(Global.Path.bin, assetName)
727
+ if (downloadResponse.body) await Filesystem.writeStream(tempPath, downloadResponse.body)
728
+
729
+ if (ext === "zip") {
730
+ const ok = await Archive.extractZip(tempPath, Global.Path.bin)
731
+ .then(() => true)
732
+ .catch((error) => {
733
+ log.error("Failed to extract zls archive", { error })
734
+ return false
735
+ })
736
+ if (!ok) return
737
+ } else {
738
+ await $`tar -xf ${tempPath}`.cwd(Global.Path.bin).quiet().nothrow()
739
+ }
740
+
741
+ await fs.rm(tempPath, { force: true })
742
+
743
+ bin = path.join(Global.Path.bin, "zls" + (platform === "win32" ? ".exe" : ""))
744
+
745
+ if (!(await Filesystem.exists(bin))) {
746
+ log.error("Failed to extract zls binary")
747
+ return
748
+ }
749
+
750
+ if (platform !== "win32") {
751
+ await $`chmod +x ${bin}`.quiet().nothrow()
752
+ }
753
+
754
+ log.info(`installed zls`, { bin })
755
+ }
756
+
757
+ return {
758
+ process: spawn(bin, {
759
+ cwd: root,
760
+ }),
761
+ }
762
+ },
763
+ }
764
+
765
+ export const CSharp: Info = {
766
+ id: "csharp",
767
+ root: NearestRoot([".slnx", ".sln", ".csproj", "global.json"]),
768
+ extensions: [".cs"],
769
+ async spawn(root) {
770
+ let bin = Bun.which("csharp-ls", {
771
+ PATH: process.env["PATH"] + path.delimiter + Global.Path.bin,
772
+ })
773
+ if (!bin) {
774
+ if (!Bun.which("dotnet")) {
775
+ log.error(".NET SDK is required to install csharp-ls")
776
+ return
777
+ }
778
+
779
+ if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
780
+ log.info("installing csharp-ls via dotnet tool")
781
+ const proc = Process.spawn(["dotnet", "tool", "install", "csharp-ls", "--tool-path", Global.Path.bin], {
782
+ stdout: "pipe",
783
+ stderr: "pipe",
784
+ stdin: "pipe",
785
+ })
786
+ const exit = await proc.exited
787
+ if (exit !== 0) {
788
+ log.error("Failed to install csharp-ls")
789
+ return
790
+ }
791
+
792
+ bin = path.join(Global.Path.bin, "csharp-ls" + (process.platform === "win32" ? ".exe" : ""))
793
+ log.info(`installed csharp-ls`, { bin })
794
+ }
795
+
796
+ return {
797
+ process: spawn(bin, {
798
+ cwd: root,
799
+ }),
800
+ }
801
+ },
802
+ }
803
+
804
+ export const FSharp: Info = {
805
+ id: "fsharp",
806
+ root: NearestRoot([".slnx", ".sln", ".fsproj", "global.json"]),
807
+ extensions: [".fs", ".fsi", ".fsx", ".fsscript"],
808
+ async spawn(root) {
809
+ let bin = Bun.which("fsautocomplete", {
810
+ PATH: process.env["PATH"] + path.delimiter + Global.Path.bin,
811
+ })
812
+ if (!bin) {
813
+ if (!Bun.which("dotnet")) {
814
+ log.error(".NET SDK is required to install fsautocomplete")
815
+ return
816
+ }
817
+
818
+ if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
819
+ log.info("installing fsautocomplete via dotnet tool")
820
+ const proc = Process.spawn(["dotnet", "tool", "install", "fsautocomplete", "--tool-path", Global.Path.bin], {
821
+ stdout: "pipe",
822
+ stderr: "pipe",
823
+ stdin: "pipe",
824
+ })
825
+ const exit = await proc.exited
826
+ if (exit !== 0) {
827
+ log.error("Failed to install fsautocomplete")
828
+ return
829
+ }
830
+
831
+ bin = path.join(Global.Path.bin, "fsautocomplete" + (process.platform === "win32" ? ".exe" : ""))
832
+ log.info(`installed fsautocomplete`, { bin })
833
+ }
834
+
835
+ return {
836
+ process: spawn(bin, {
837
+ cwd: root,
838
+ }),
839
+ }
840
+ },
841
+ }
842
+
843
+ export const SourceKit: Info = {
844
+ id: "sourcekit-lsp",
845
+ extensions: [".swift", ".objc", "objcpp"],
846
+ root: NearestRoot(["Package.swift", "*.xcodeproj", "*.xcworkspace"]),
847
+ async spawn(root) {
848
+ // Check if sourcekit-lsp is available in the PATH
849
+ // This is installed with the Swift toolchain
850
+ const sourcekit = Bun.which("sourcekit-lsp")
851
+ if (sourcekit) {
852
+ return {
853
+ process: spawn(sourcekit, {
854
+ cwd: root,
855
+ }),
856
+ }
857
+ }
858
+
859
+ // If sourcekit-lsp not found, check if xcrun is available
860
+ // This is specific to macOS where sourcekit-lsp is typically installed with Xcode
861
+ if (!Bun.which("xcrun")) return
862
+
863
+ const lspLoc = await $`xcrun --find sourcekit-lsp`.quiet().nothrow()
864
+
865
+ if (lspLoc.exitCode !== 0) return
866
+
867
+ const bin = lspLoc.text().trim()
868
+
869
+ return {
870
+ process: spawn(bin, {
871
+ cwd: root,
872
+ }),
873
+ }
874
+ },
875
+ }
876
+
877
+ export const RustAnalyzer: Info = {
878
+ id: "rust",
879
+ root: async (root) => {
880
+ const crateRoot = await NearestRoot(["Cargo.toml", "Cargo.lock"])(root)
881
+ if (crateRoot === undefined) {
882
+ return undefined
883
+ }
884
+ let currentDir = crateRoot
885
+
886
+ while (currentDir !== path.dirname(currentDir)) {
887
+ // Stop at filesystem root
888
+ const cargoTomlPath = path.join(currentDir, "Cargo.toml")
889
+ try {
890
+ const cargoTomlContent = await Filesystem.readText(cargoTomlPath)
891
+ if (cargoTomlContent.includes("[workspace]")) {
892
+ return currentDir
893
+ }
894
+ } catch (err) {
895
+ // File doesn't exist or can't be read, continue searching up
896
+ }
897
+
898
+ const parentDir = path.dirname(currentDir)
899
+ if (parentDir === currentDir) break // Reached filesystem root
900
+ currentDir = parentDir
901
+
902
+ // Stop if we've gone above the app root
903
+ if (!currentDir.startsWith(Instance.worktree)) break
904
+ }
905
+
906
+ return crateRoot
907
+ },
908
+ extensions: [".rs"],
909
+ async spawn(root) {
910
+ const bin = Bun.which("rust-analyzer")
911
+ if (!bin) {
912
+ log.info("rust-analyzer not found in path, please install it")
913
+ return
914
+ }
915
+ return {
916
+ process: spawn(bin, {
917
+ cwd: root,
918
+ }),
919
+ }
920
+ },
921
+ }
922
+
923
+ export const Clangd: Info = {
924
+ id: "clangd",
925
+ root: NearestRoot(["compile_commands.json", "compile_flags.txt", ".clangd", "CMakeLists.txt", "Makefile"]),
926
+ extensions: [".c", ".cpp", ".cc", ".cxx", ".c++", ".h", ".hpp", ".hh", ".hxx", ".h++"],
927
+ async spawn(root) {
928
+ const args = ["--background-index", "--clang-tidy"]
929
+ const fromPath = Bun.which("clangd")
930
+ if (fromPath) {
931
+ return {
932
+ process: spawn(fromPath, args, {
933
+ cwd: root,
934
+ }),
935
+ }
936
+ }
937
+
938
+ const ext = process.platform === "win32" ? ".exe" : ""
939
+ const direct = path.join(Global.Path.bin, "clangd" + ext)
940
+ if (await Filesystem.exists(direct)) {
941
+ return {
942
+ process: spawn(direct, args, {
943
+ cwd: root,
944
+ }),
945
+ }
946
+ }
947
+
948
+ const entries = await fs.readdir(Global.Path.bin, { withFileTypes: true }).catch(() => [])
949
+ for (const entry of entries) {
950
+ if (!entry.isDirectory()) continue
951
+ if (!entry.name.startsWith("clangd_")) continue
952
+ const candidate = path.join(Global.Path.bin, entry.name, "bin", "clangd" + ext)
953
+ if (await Filesystem.exists(candidate)) {
954
+ return {
955
+ process: spawn(candidate, args, {
956
+ cwd: root,
957
+ }),
958
+ }
959
+ }
960
+ }
961
+
962
+ if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
963
+
964
+ // Offline mode: skip download
965
+ if (isOfflineMode()) {
966
+ log.warn("offline mode: cannot download clangd")
967
+ log.warn("please install manually from https://github.com/clangd/clangd/releases")
968
+ return
969
+ }
970
+
971
+ log.info("downloading clangd from GitHub releases")
972
+
973
+ const releaseResponse = await fetch("https://api.github.com/repos/clangd/clangd/releases/latest")
974
+ if (!releaseResponse.ok) {
975
+ log.error("Failed to fetch clangd release info")
976
+ return
977
+ }
978
+
979
+ const release: {
980
+ tag_name?: string
981
+ assets?: { name?: string; browser_download_url?: string }[]
982
+ } = await releaseResponse.json()
983
+
984
+ const tag = release.tag_name
985
+ if (!tag) {
986
+ log.error("clangd release did not include a tag name")
987
+ return
988
+ }
989
+ const platform = process.platform
990
+ const tokens: Record<string, string> = {
991
+ darwin: "mac",
992
+ linux: "linux",
993
+ win32: "windows",
994
+ }
995
+ const token = tokens[platform]
996
+ if (!token) {
997
+ log.error(`Platform ${platform} is not supported by clangd auto-download`)
998
+ return
999
+ }
1000
+
1001
+ const assets = release.assets ?? []
1002
+ const valid = (item: { name?: string; browser_download_url?: string }) => {
1003
+ if (!item.name) return false
1004
+ if (!item.browser_download_url) return false
1005
+ if (!item.name.includes(token)) return false
1006
+ return item.name.includes(tag)
1007
+ }
1008
+
1009
+ const asset =
1010
+ assets.find((item) => valid(item) && item.name?.endsWith(".zip")) ??
1011
+ assets.find((item) => valid(item) && item.name?.endsWith(".tar.xz")) ??
1012
+ assets.find((item) => valid(item))
1013
+ if (!asset?.name || !asset.browser_download_url) {
1014
+ log.error("clangd could not match release asset", { tag, platform })
1015
+ return
1016
+ }
1017
+
1018
+ const name = asset.name
1019
+ const downloadResponse = await fetch(asset.browser_download_url)
1020
+ if (!downloadResponse.ok) {
1021
+ log.error("Failed to download clangd")
1022
+ return
1023
+ }
1024
+
1025
+ const archive = path.join(Global.Path.bin, name)
1026
+ const buf = await downloadResponse.arrayBuffer()
1027
+ if (buf.byteLength === 0) {
1028
+ log.error("Failed to write clangd archive")
1029
+ return
1030
+ }
1031
+ await Filesystem.write(archive, Buffer.from(buf))
1032
+
1033
+ const zip = name.endsWith(".zip")
1034
+ const tar = name.endsWith(".tar.xz")
1035
+ if (!zip && !tar) {
1036
+ log.error("clangd encountered unsupported asset", { asset: name })
1037
+ return
1038
+ }
1039
+
1040
+ if (zip) {
1041
+ const ok = await Archive.extractZip(archive, Global.Path.bin)
1042
+ .then(() => true)
1043
+ .catch((error) => {
1044
+ log.error("Failed to extract clangd archive", { error })
1045
+ return false
1046
+ })
1047
+ if (!ok) return
1048
+ }
1049
+ if (tar) {
1050
+ await $`tar -xf ${archive}`.cwd(Global.Path.bin).quiet().nothrow()
1051
+ }
1052
+ await fs.rm(archive, { force: true })
1053
+
1054
+ const bin = path.join(Global.Path.bin, "clangd_" + tag, "bin", "clangd" + ext)
1055
+ if (!(await Filesystem.exists(bin))) {
1056
+ log.error("Failed to extract clangd binary")
1057
+ return
1058
+ }
1059
+
1060
+ if (platform !== "win32") {
1061
+ await $`chmod +x ${bin}`.quiet().nothrow()
1062
+ }
1063
+
1064
+ await fs.unlink(path.join(Global.Path.bin, "clangd")).catch(() => {})
1065
+ await fs.symlink(bin, path.join(Global.Path.bin, "clangd")).catch(() => {})
1066
+
1067
+ log.info(`installed clangd`, { bin })
1068
+
1069
+ return {
1070
+ process: spawn(bin, args, {
1071
+ cwd: root,
1072
+ }),
1073
+ }
1074
+ },
1075
+ }
1076
+
1077
+ export const Svelte: Info = {
1078
+ id: "svelte",
1079
+ extensions: [".svelte"],
1080
+ root: NearestRoot(["package-lock.json", "bun.lockb", "bun.lock", "pnpm-lock.yaml", "yarn.lock"]),
1081
+ async spawn(root) {
1082
+ let binary = Bun.which("svelteserver")
1083
+ const args: string[] = []
1084
+ if (!binary) {
1085
+ const js = path.join(Global.Path.bin, "node_modules", "svelte-language-server", "bin", "server.js")
1086
+ if (!(await Filesystem.exists(js))) {
1087
+ if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
1088
+ await Process.spawn([BunProc.which(), "install", "svelte-language-server"], {
1089
+ cwd: Global.Path.bin,
1090
+ env: {
1091
+ ...process.env,
1092
+ BUN_BE_BUN: "1",
1093
+ },
1094
+ stdout: "pipe",
1095
+ stderr: "pipe",
1096
+ stdin: "pipe",
1097
+ }).exited
1098
+ }
1099
+ binary = BunProc.which()
1100
+ args.push("run", js)
1101
+ }
1102
+ args.push("--stdio")
1103
+ const proc = spawn(binary, args, {
1104
+ cwd: root,
1105
+ env: {
1106
+ ...process.env,
1107
+ BUN_BE_BUN: "1",
1108
+ },
1109
+ })
1110
+ return {
1111
+ process: proc,
1112
+ initialization: {},
1113
+ }
1114
+ },
1115
+ }
1116
+
1117
+ export const Astro: Info = {
1118
+ id: "astro",
1119
+ extensions: [".astro"],
1120
+ root: NearestRoot(["package-lock.json", "bun.lockb", "bun.lock", "pnpm-lock.yaml", "yarn.lock"]),
1121
+ async spawn(root) {
1122
+ const tsserver = await Bun.resolve("typescript/lib/tsserver.js", Instance.directory).catch(() => {})
1123
+ if (!tsserver) {
1124
+ log.info("typescript not found, required for Astro language server")
1125
+ return
1126
+ }
1127
+ const tsdk = path.dirname(tsserver)
1128
+
1129
+ let binary = Bun.which("astro-ls")
1130
+ const args: string[] = []
1131
+ if (!binary) {
1132
+ const js = path.join(Global.Path.bin, "node_modules", "@astrojs", "language-server", "bin", "nodeServer.js")
1133
+ if (!(await Filesystem.exists(js))) {
1134
+ if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
1135
+ await Process.spawn([BunProc.which(), "install", "@astrojs/language-server"], {
1136
+ cwd: Global.Path.bin,
1137
+ env: {
1138
+ ...process.env,
1139
+ BUN_BE_BUN: "1",
1140
+ },
1141
+ stdout: "pipe",
1142
+ stderr: "pipe",
1143
+ stdin: "pipe",
1144
+ }).exited
1145
+ }
1146
+ binary = BunProc.which()
1147
+ args.push("run", js)
1148
+ }
1149
+ args.push("--stdio")
1150
+ const proc = spawn(binary, args, {
1151
+ cwd: root,
1152
+ env: {
1153
+ ...process.env,
1154
+ BUN_BE_BUN: "1",
1155
+ },
1156
+ })
1157
+ return {
1158
+ process: proc,
1159
+ initialization: {
1160
+ typescript: {
1161
+ tsdk,
1162
+ },
1163
+ },
1164
+ }
1165
+ },
1166
+ }
1167
+
1168
+ export const JDTLS: Info = {
1169
+ id: "jdtls",
1170
+ root: NearestRoot(["pom.xml", "build.gradle", "build.gradle.kts", ".project", ".classpath"]),
1171
+ extensions: [".java"],
1172
+ async spawn(root) {
1173
+ const java = Bun.which("java")
1174
+ if (!java) {
1175
+ log.error("Java 21 or newer is required to run the JDTLS. Please install it first.")
1176
+ return
1177
+ }
1178
+ const javaMajorVersion = await $`java -version`
1179
+ .quiet()
1180
+ .nothrow()
1181
+ .then(({ stderr }) => {
1182
+ const m = /"(\d+)\.\d+\.\d+"/.exec(stderr.toString())
1183
+ return !m ? undefined : parseInt(m[1])
1184
+ })
1185
+ if (javaMajorVersion == null || javaMajorVersion < 21) {
1186
+ log.error("JDTLS requires at least Java 21.")
1187
+ return
1188
+ }
1189
+ const distPath = path.join(Global.Path.bin, "jdtls")
1190
+ const launcherDir = path.join(distPath, "plugins")
1191
+ const installed = await pathExists(launcherDir)
1192
+ if (!installed) {
1193
+ if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
1194
+ log.info("Downloading JDTLS LSP server.")
1195
+ await fs.mkdir(distPath, { recursive: true })
1196
+ const releaseURL =
1197
+ "https://www.eclipse.org/downloads/download.php?file=/jdtls/snapshots/jdt-language-server-latest.tar.gz"
1198
+ const archiveName = "release.tar.gz"
1199
+
1200
+ log.info("Downloading JDTLS archive", { url: releaseURL, dest: distPath })
1201
+ const curlResult = await $`curl -L -o ${archiveName} '${releaseURL}'`.cwd(distPath).quiet().nothrow()
1202
+ if (curlResult.exitCode !== 0) {
1203
+ log.error("Failed to download JDTLS", { exitCode: curlResult.exitCode, stderr: curlResult.stderr.toString() })
1204
+ return
1205
+ }
1206
+
1207
+ log.info("Extracting JDTLS archive")
1208
+ const tarResult = await $`tar -xzf ${archiveName}`.cwd(distPath).quiet().nothrow()
1209
+ if (tarResult.exitCode !== 0) {
1210
+ log.error("Failed to extract JDTLS", { exitCode: tarResult.exitCode, stderr: tarResult.stderr.toString() })
1211
+ return
1212
+ }
1213
+
1214
+ await fs.rm(path.join(distPath, archiveName), { force: true })
1215
+ log.info("JDTLS download and extraction completed")
1216
+ }
1217
+ const jarFileName = await $`ls org.eclipse.equinox.launcher_*.jar`
1218
+ .cwd(launcherDir)
1219
+ .quiet()
1220
+ .nothrow()
1221
+ .then(({ stdout }) => stdout.toString().trim())
1222
+ const launcherJar = path.join(launcherDir, jarFileName)
1223
+ if (!(await pathExists(launcherJar))) {
1224
+ log.error(`Failed to locate the JDTLS launcher module in the installed directory: ${distPath}.`)
1225
+ return
1226
+ }
1227
+ const configFile = path.join(
1228
+ distPath,
1229
+ (() => {
1230
+ switch (process.platform) {
1231
+ case "darwin":
1232
+ return "config_mac"
1233
+ case "linux":
1234
+ return "config_linux"
1235
+ case "win32":
1236
+ return "config_win"
1237
+ default:
1238
+ return "config_linux"
1239
+ }
1240
+ })(),
1241
+ )
1242
+ const dataDir = await fs.mkdtemp(path.join(os.tmpdir(), "opencode-jdtls-data"))
1243
+ return {
1244
+ process: spawn(
1245
+ java,
1246
+ [
1247
+ "-jar",
1248
+ launcherJar,
1249
+ "-configuration",
1250
+ configFile,
1251
+ "-data",
1252
+ dataDir,
1253
+ "-Declipse.application=org.eclipse.jdt.ls.core.id1",
1254
+ "-Dosgi.bundles.defaultStartLevel=4",
1255
+ "-Declipse.product=org.eclipse.jdt.ls.core.product",
1256
+ "-Dlog.level=ALL",
1257
+ "--add-modules=ALL-SYSTEM",
1258
+ "--add-opens java.base/java.util=ALL-UNNAMED",
1259
+ "--add-opens java.base/java.lang=ALL-UNNAMED",
1260
+ ],
1261
+ {
1262
+ cwd: root,
1263
+ },
1264
+ ),
1265
+ }
1266
+ },
1267
+ }
1268
+
1269
+ export const KotlinLS: Info = {
1270
+ id: "kotlin-ls",
1271
+ extensions: [".kt", ".kts"],
1272
+ root: async (file) => {
1273
+ // 1) Nearest Gradle root (multi-project or included build)
1274
+ const settingsRoot = await NearestRoot(["settings.gradle.kts", "settings.gradle"])(file)
1275
+ if (settingsRoot) return settingsRoot
1276
+ // 2) Gradle wrapper (strong root signal)
1277
+ const wrapperRoot = await NearestRoot(["gradlew", "gradlew.bat"])(file)
1278
+ if (wrapperRoot) return wrapperRoot
1279
+ // 3) Single-project or module-level build
1280
+ const buildRoot = await NearestRoot(["build.gradle.kts", "build.gradle"])(file)
1281
+ if (buildRoot) return buildRoot
1282
+ // 4) Maven fallback
1283
+ return NearestRoot(["pom.xml"])(file)
1284
+ },
1285
+ async spawn(root) {
1286
+ const distPath = path.join(Global.Path.bin, "kotlin-ls")
1287
+ const launcherScript =
1288
+ process.platform === "win32" ? path.join(distPath, "kotlin-lsp.cmd") : path.join(distPath, "kotlin-lsp.sh")
1289
+ const installed = await Filesystem.exists(launcherScript)
1290
+ if (!installed) {
1291
+ if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
1292
+
1293
+ // Offline mode: skip download
1294
+ if (isOfflineMode()) {
1295
+ log.warn("offline mode: cannot download kotlin-lsp")
1296
+ log.warn("please install manually from https://github.com/Kotlin/kotlin-lsp/releases")
1297
+ return
1298
+ }
1299
+
1300
+ log.info("Downloading Kotlin Language Server from GitHub.")
1301
+
1302
+ const releaseResponse = await fetch("https://api.github.com/repos/Kotlin/kotlin-lsp/releases/latest")
1303
+ if (!releaseResponse.ok) {
1304
+ log.error("Failed to fetch kotlin-lsp release info")
1305
+ return
1306
+ }
1307
+
1308
+ const release = await releaseResponse.json()
1309
+ const version = release.name?.replace(/^v/, "")
1310
+
1311
+ if (!version) {
1312
+ log.error("Could not determine Kotlin LSP version from release")
1313
+ return
1314
+ }
1315
+
1316
+ const platform = process.platform
1317
+ const arch = process.arch
1318
+
1319
+ let kotlinArch: string = arch
1320
+ if (arch === "arm64") kotlinArch = "aarch64"
1321
+ else if (arch === "x64") kotlinArch = "x64"
1322
+
1323
+ let kotlinPlatform: string = platform
1324
+ if (platform === "darwin") kotlinPlatform = "mac"
1325
+ else if (platform === "linux") kotlinPlatform = "linux"
1326
+ else if (platform === "win32") kotlinPlatform = "win"
1327
+
1328
+ const supportedCombos = ["mac-x64", "mac-aarch64", "linux-x64", "linux-aarch64", "win-x64", "win-aarch64"]
1329
+
1330
+ const combo = `${kotlinPlatform}-${kotlinArch}`
1331
+
1332
+ if (!supportedCombos.includes(combo)) {
1333
+ log.error(`Platform ${platform}/${arch} is not supported by Kotlin LSP`)
1334
+ return
1335
+ }
1336
+
1337
+ const assetName = `kotlin-lsp-${version}-${kotlinPlatform}-${kotlinArch}.zip`
1338
+ const releaseURL = `https://download-cdn.jetbrains.com/kotlin-lsp/${version}/${assetName}`
1339
+
1340
+ await fs.mkdir(distPath, { recursive: true })
1341
+ const archivePath = path.join(distPath, "kotlin-ls.zip")
1342
+ await $`curl -L -o '${archivePath}' '${releaseURL}'`.quiet().nothrow()
1343
+ const ok = await Archive.extractZip(archivePath, distPath)
1344
+ .then(() => true)
1345
+ .catch((error) => {
1346
+ log.error("Failed to extract Kotlin LS archive", { error })
1347
+ return false
1348
+ })
1349
+ if (!ok) return
1350
+ await fs.rm(archivePath, { force: true })
1351
+ if (process.platform !== "win32") {
1352
+ await $`chmod +x ${launcherScript}`.quiet().nothrow()
1353
+ }
1354
+ log.info("Installed Kotlin Language Server", { path: launcherScript })
1355
+ }
1356
+ if (!(await Filesystem.exists(launcherScript))) {
1357
+ log.error(`Failed to locate the Kotlin LS launcher script in the installed directory: ${distPath}.`)
1358
+ return
1359
+ }
1360
+ return {
1361
+ process: spawn(launcherScript, ["--stdio"], {
1362
+ cwd: root,
1363
+ }),
1364
+ }
1365
+ },
1366
+ }
1367
+
1368
+ export const YamlLS: Info = {
1369
+ id: "yaml-ls",
1370
+ extensions: [".yaml", ".yml"],
1371
+ root: NearestRoot(["package-lock.json", "bun.lockb", "bun.lock", "pnpm-lock.yaml", "yarn.lock"]),
1372
+ async spawn(root) {
1373
+ let binary = Bun.which("yaml-language-server")
1374
+ const args: string[] = []
1375
+ if (!binary) {
1376
+ const js = path.join(
1377
+ Global.Path.bin,
1378
+ "node_modules",
1379
+ "yaml-language-server",
1380
+ "out",
1381
+ "server",
1382
+ "src",
1383
+ "server.js",
1384
+ )
1385
+ const exists = await Filesystem.exists(js)
1386
+ if (!exists) {
1387
+ if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
1388
+ await Process.spawn([BunProc.which(), "install", "yaml-language-server"], {
1389
+ cwd: Global.Path.bin,
1390
+ env: {
1391
+ ...process.env,
1392
+ BUN_BE_BUN: "1",
1393
+ },
1394
+ stdout: "pipe",
1395
+ stderr: "pipe",
1396
+ stdin: "pipe",
1397
+ }).exited
1398
+ }
1399
+ binary = BunProc.which()
1400
+ args.push("run", js)
1401
+ }
1402
+ args.push("--stdio")
1403
+ const proc = spawn(binary, args, {
1404
+ cwd: root,
1405
+ env: {
1406
+ ...process.env,
1407
+ BUN_BE_BUN: "1",
1408
+ },
1409
+ })
1410
+ return {
1411
+ process: proc,
1412
+ }
1413
+ },
1414
+ }
1415
+
1416
+ export const LuaLS: Info = {
1417
+ id: "lua-ls",
1418
+ root: NearestRoot([
1419
+ ".luarc.json",
1420
+ ".luarc.jsonc",
1421
+ ".luacheckrc",
1422
+ ".stylua.toml",
1423
+ "stylua.toml",
1424
+ "selene.toml",
1425
+ "selene.yml",
1426
+ ]),
1427
+ extensions: [".lua"],
1428
+ async spawn(root) {
1429
+ let bin = Bun.which("lua-language-server", {
1430
+ PATH: process.env["PATH"] + path.delimiter + Global.Path.bin,
1431
+ })
1432
+
1433
+ if (!bin) {
1434
+ if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
1435
+
1436
+ // Offline mode: skip download
1437
+ if (isOfflineMode()) {
1438
+ log.warn("offline mode: cannot download lua-language-server")
1439
+ log.warn("please install manually from https://github.com/LuaLS/lua-language-server/releases")
1440
+ return
1441
+ }
1442
+ log.info("downloading lua-language-server from GitHub releases")
1443
+
1444
+ const releaseResponse = await fetch("https://api.github.com/repos/LuaLS/lua-language-server/releases/latest")
1445
+ if (!releaseResponse.ok) {
1446
+ log.error("Failed to fetch lua-language-server release info")
1447
+ return
1448
+ }
1449
+
1450
+ const release = await releaseResponse.json()
1451
+
1452
+ const platform = process.platform
1453
+ const arch = process.arch
1454
+ let assetName = ""
1455
+
1456
+ let lualsArch: string = arch
1457
+ if (arch === "arm64") lualsArch = "arm64"
1458
+ else if (arch === "x64") lualsArch = "x64"
1459
+ else if (arch === "ia32") lualsArch = "ia32"
1460
+
1461
+ let lualsPlatform: string = platform
1462
+ if (platform === "darwin") lualsPlatform = "darwin"
1463
+ else if (platform === "linux") lualsPlatform = "linux"
1464
+ else if (platform === "win32") lualsPlatform = "win32"
1465
+
1466
+ const ext = platform === "win32" ? "zip" : "tar.gz"
1467
+
1468
+ assetName = `lua-language-server-${release.tag_name}-${lualsPlatform}-${lualsArch}.${ext}`
1469
+
1470
+ const supportedCombos = [
1471
+ "darwin-arm64.tar.gz",
1472
+ "darwin-x64.tar.gz",
1473
+ "linux-x64.tar.gz",
1474
+ "linux-arm64.tar.gz",
1475
+ "win32-x64.zip",
1476
+ "win32-ia32.zip",
1477
+ ]
1478
+
1479
+ const assetSuffix = `${lualsPlatform}-${lualsArch}.${ext}`
1480
+ if (!supportedCombos.includes(assetSuffix)) {
1481
+ log.error(`Platform ${platform} and architecture ${arch} is not supported by lua-language-server`)
1482
+ return
1483
+ }
1484
+
1485
+ const asset = release.assets.find((a: any) => a.name === assetName)
1486
+ if (!asset) {
1487
+ log.error(`Could not find asset ${assetName} in latest lua-language-server release`)
1488
+ return
1489
+ }
1490
+
1491
+ const downloadUrl = asset.browser_download_url
1492
+ const downloadResponse = await fetch(downloadUrl)
1493
+ if (!downloadResponse.ok) {
1494
+ log.error("Failed to download lua-language-server")
1495
+ return
1496
+ }
1497
+
1498
+ const tempPath = path.join(Global.Path.bin, assetName)
1499
+ if (downloadResponse.body) await Filesystem.writeStream(tempPath, downloadResponse.body)
1500
+
1501
+ // Unlike zls which is a single self-contained binary,
1502
+ // lua-language-server needs supporting files (meta/, locale/, etc.)
1503
+ // Extract entire archive to dedicated directory to preserve all files
1504
+ const installDir = path.join(Global.Path.bin, `lua-language-server-${lualsArch}-${lualsPlatform}`)
1505
+
1506
+ // Remove old installation if exists
1507
+ const stats = await fs.stat(installDir).catch(() => undefined)
1508
+ if (stats) {
1509
+ await fs.rm(installDir, { force: true, recursive: true })
1510
+ }
1511
+
1512
+ await fs.mkdir(installDir, { recursive: true })
1513
+
1514
+ if (ext === "zip") {
1515
+ const ok = await Archive.extractZip(tempPath, installDir)
1516
+ .then(() => true)
1517
+ .catch((error) => {
1518
+ log.error("Failed to extract lua-language-server archive", { error })
1519
+ return false
1520
+ })
1521
+ if (!ok) return
1522
+ } else {
1523
+ const ok = await $`tar -xzf ${tempPath} -C ${installDir}`
1524
+ .quiet()
1525
+ .then(() => true)
1526
+ .catch((error) => {
1527
+ log.error("Failed to extract lua-language-server archive", { error })
1528
+ return false
1529
+ })
1530
+ if (!ok) return
1531
+ }
1532
+
1533
+ await fs.rm(tempPath, { force: true })
1534
+
1535
+ // Binary is located in bin/ subdirectory within the extracted archive
1536
+ bin = path.join(installDir, "bin", "lua-language-server" + (platform === "win32" ? ".exe" : ""))
1537
+
1538
+ if (!(await Filesystem.exists(bin))) {
1539
+ log.error("Failed to extract lua-language-server binary")
1540
+ return
1541
+ }
1542
+
1543
+ if (platform !== "win32") {
1544
+ const ok = await $`chmod +x ${bin}`.quiet().catch((error) => {
1545
+ log.error("Failed to set executable permission for lua-language-server binary", {
1546
+ error,
1547
+ })
1548
+ })
1549
+ if (!ok) return
1550
+ }
1551
+
1552
+ log.info(`installed lua-language-server`, { bin })
1553
+ }
1554
+
1555
+ return {
1556
+ process: spawn(bin, {
1557
+ cwd: root,
1558
+ }),
1559
+ }
1560
+ },
1561
+ }
1562
+
1563
+ export const PHPIntelephense: Info = {
1564
+ id: "php intelephense",
1565
+ extensions: [".php"],
1566
+ root: NearestRoot(["composer.json", "composer.lock", ".php-version"]),
1567
+ async spawn(root) {
1568
+ let binary = Bun.which("intelephense")
1569
+ const args: string[] = []
1570
+ if (!binary) {
1571
+ const js = path.join(Global.Path.bin, "node_modules", "intelephense", "lib", "intelephense.js")
1572
+ if (!(await Filesystem.exists(js))) {
1573
+ if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
1574
+ await Process.spawn([BunProc.which(), "install", "intelephense"], {
1575
+ cwd: Global.Path.bin,
1576
+ env: {
1577
+ ...process.env,
1578
+ BUN_BE_BUN: "1",
1579
+ },
1580
+ stdout: "pipe",
1581
+ stderr: "pipe",
1582
+ stdin: "pipe",
1583
+ }).exited
1584
+ }
1585
+ binary = BunProc.which()
1586
+ args.push("run", js)
1587
+ }
1588
+ args.push("--stdio")
1589
+ const proc = spawn(binary, args, {
1590
+ cwd: root,
1591
+ env: {
1592
+ ...process.env,
1593
+ BUN_BE_BUN: "1",
1594
+ },
1595
+ })
1596
+ return {
1597
+ process: proc,
1598
+ initialization: {
1599
+ telemetry: {
1600
+ enabled: false,
1601
+ },
1602
+ },
1603
+ }
1604
+ },
1605
+ }
1606
+
1607
+ export const Prisma: Info = {
1608
+ id: "prisma",
1609
+ extensions: [".prisma"],
1610
+ root: NearestRoot(["schema.prisma", "prisma/schema.prisma", "prisma"], ["package.json"]),
1611
+ async spawn(root) {
1612
+ const prisma = Bun.which("prisma")
1613
+ if (!prisma) {
1614
+ log.info("prisma not found, please install prisma")
1615
+ return
1616
+ }
1617
+ return {
1618
+ process: spawn(prisma, ["language-server"], {
1619
+ cwd: root,
1620
+ }),
1621
+ }
1622
+ },
1623
+ }
1624
+
1625
+ export const Dart: Info = {
1626
+ id: "dart",
1627
+ extensions: [".dart"],
1628
+ root: NearestRoot(["pubspec.yaml", "analysis_options.yaml"]),
1629
+ async spawn(root) {
1630
+ const dart = Bun.which("dart")
1631
+ if (!dart) {
1632
+ log.info("dart not found, please install dart first")
1633
+ return
1634
+ }
1635
+ return {
1636
+ process: spawn(dart, ["language-server", "--lsp"], {
1637
+ cwd: root,
1638
+ }),
1639
+ }
1640
+ },
1641
+ }
1642
+
1643
+ export const Ocaml: Info = {
1644
+ id: "ocaml-lsp",
1645
+ extensions: [".ml", ".mli"],
1646
+ root: NearestRoot(["dune-project", "dune-workspace", ".merlin", "opam"]),
1647
+ async spawn(root) {
1648
+ const bin = Bun.which("ocamllsp")
1649
+ if (!bin) {
1650
+ log.info("ocamllsp not found, please install ocaml-lsp-server")
1651
+ return
1652
+ }
1653
+ return {
1654
+ process: spawn(bin, {
1655
+ cwd: root,
1656
+ }),
1657
+ }
1658
+ },
1659
+ }
1660
+ export const BashLS: Info = {
1661
+ id: "bash",
1662
+ extensions: [".sh", ".bash", ".zsh", ".ksh"],
1663
+ root: async () => Instance.directory,
1664
+ async spawn(root) {
1665
+ let binary = Bun.which("bash-language-server")
1666
+ const args: string[] = []
1667
+ if (!binary) {
1668
+ const js = path.join(Global.Path.bin, "node_modules", "bash-language-server", "out", "cli.js")
1669
+ if (!(await Filesystem.exists(js))) {
1670
+ if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
1671
+
1672
+ // Offline mode: skip download
1673
+ if (isOfflineMode()) {
1674
+ log.warn("offline mode: cannot download bash-language-server")
1675
+ log.warn("please install manually: bun install -g bash-language-server")
1676
+ return
1677
+ }
1678
+
1679
+ await Process.spawn([BunProc.which(), "install", "bash-language-server"], {
1680
+ cwd: Global.Path.bin,
1681
+ env: {
1682
+ ...process.env,
1683
+ BUN_BE_BUN: "1",
1684
+ },
1685
+ stdout: "pipe",
1686
+ stderr: "pipe",
1687
+ stdin: "pipe",
1688
+ }).exited
1689
+ }
1690
+ binary = BunProc.which()
1691
+ args.push("run", js)
1692
+ }
1693
+ args.push("start")
1694
+ const proc = spawn(binary, args, {
1695
+ cwd: root,
1696
+ env: {
1697
+ ...process.env,
1698
+ BUN_BE_BUN: "1",
1699
+ },
1700
+ })
1701
+ return {
1702
+ process: proc,
1703
+ }
1704
+ },
1705
+ }
1706
+
1707
+ export const TerraformLS: Info = {
1708
+ id: "terraform",
1709
+ extensions: [".tf", ".tfvars"],
1710
+ root: NearestRoot([".terraform.lock.hcl", "terraform.tfstate", "*.tf"]),
1711
+ async spawn(root) {
1712
+ let bin = Bun.which("terraform-ls", {
1713
+ PATH: process.env["PATH"] + path.delimiter + Global.Path.bin,
1714
+ })
1715
+
1716
+ if (!bin) {
1717
+ if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
1718
+
1719
+ // Offline mode: skip download
1720
+ if (isOfflineMode()) {
1721
+ log.warn("offline mode: cannot download terraform-ls")
1722
+ log.warn("please install manually from https://releases.hashicorp.com/terraform-ls/")
1723
+ return
1724
+ }
1725
+
1726
+ log.info("downloading terraform-ls from HashiCorp releases")
1727
+
1728
+ const releaseResponse = await fetch("https://api.releases.hashicorp.com/v1/releases/terraform-ls/latest")
1729
+ if (!releaseResponse.ok) {
1730
+ log.error("Failed to fetch terraform-ls release info")
1731
+ return
1732
+ }
1733
+
1734
+ const release = (await releaseResponse.json()) as {
1735
+ version?: string
1736
+ builds?: { arch?: string; os?: string; url?: string }[]
1737
+ }
1738
+
1739
+ const platform = process.platform
1740
+ const arch = process.arch
1741
+
1742
+ const tfArch = arch === "arm64" ? "arm64" : "amd64"
1743
+ const tfPlatform = platform === "win32" ? "windows" : platform
1744
+
1745
+ const builds = release.builds ?? []
1746
+ const build = builds.find((b) => b.arch === tfArch && b.os === tfPlatform)
1747
+ if (!build?.url) {
1748
+ log.error(`Could not find build for ${tfPlatform}/${tfArch} terraform-ls release version ${release.version}`)
1749
+ return
1750
+ }
1751
+
1752
+ const downloadResponse = await fetch(build.url)
1753
+ if (!downloadResponse.ok) {
1754
+ log.error("Failed to download terraform-ls")
1755
+ return
1756
+ }
1757
+
1758
+ const tempPath = path.join(Global.Path.bin, "terraform-ls.zip")
1759
+ if (downloadResponse.body) await Filesystem.writeStream(tempPath, downloadResponse.body)
1760
+
1761
+ const ok = await Archive.extractZip(tempPath, Global.Path.bin)
1762
+ .then(() => true)
1763
+ .catch((error) => {
1764
+ log.error("Failed to extract terraform-ls archive", { error })
1765
+ return false
1766
+ })
1767
+ if (!ok) return
1768
+ await fs.rm(tempPath, { force: true })
1769
+
1770
+ bin = path.join(Global.Path.bin, "terraform-ls" + (platform === "win32" ? ".exe" : ""))
1771
+
1772
+ if (!(await Filesystem.exists(bin))) {
1773
+ log.error("Failed to extract terraform-ls binary")
1774
+ return
1775
+ }
1776
+
1777
+ if (platform !== "win32") {
1778
+ await $`chmod +x ${bin}`.quiet().nothrow()
1779
+ }
1780
+
1781
+ log.info(`installed terraform-ls`, { bin })
1782
+ }
1783
+
1784
+ return {
1785
+ process: spawn(bin, ["serve"], {
1786
+ cwd: root,
1787
+ }),
1788
+ initialization: {
1789
+ experimentalFeatures: {
1790
+ prefillRequiredFields: true,
1791
+ validateOnSave: true,
1792
+ },
1793
+ },
1794
+ }
1795
+ },
1796
+ }
1797
+
1798
+ export const TexLab: Info = {
1799
+ id: "texlab",
1800
+ extensions: [".tex", ".bib"],
1801
+ root: NearestRoot([".latexmkrc", "latexmkrc", ".texlabroot", "texlabroot"]),
1802
+ async spawn(root) {
1803
+ let bin = Bun.which("texlab", {
1804
+ PATH: process.env["PATH"] + path.delimiter + Global.Path.bin,
1805
+ })
1806
+
1807
+ if (!bin) {
1808
+ if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
1809
+
1810
+ // Offline mode: skip download
1811
+ if (isOfflineMode()) {
1812
+ log.warn("offline mode: cannot download texlab")
1813
+ log.warn("please install manually from https://github.com/latex-lsp/texlab/releases")
1814
+ return
1815
+ }
1816
+
1817
+ log.info("downloading texlab from GitHub releases")
1818
+
1819
+ const response = await fetch("https://api.github.com/repos/latex-lsp/texlab/releases/latest")
1820
+ if (!response.ok) {
1821
+ log.error("Failed to fetch texlab release info")
1822
+ return
1823
+ }
1824
+
1825
+ const release = (await response.json()) as {
1826
+ tag_name?: string
1827
+ assets?: { name?: string; browser_download_url?: string }[]
1828
+ }
1829
+ const version = release.tag_name?.replace("v", "")
1830
+ if (!version) {
1831
+ log.error("texlab release did not include a version tag")
1832
+ return
1833
+ }
1834
+
1835
+ const platform = process.platform
1836
+ const arch = process.arch
1837
+
1838
+ const texArch = arch === "arm64" ? "aarch64" : "x86_64"
1839
+ const texPlatform = platform === "darwin" ? "macos" : platform === "win32" ? "windows" : "linux"
1840
+ const ext = platform === "win32" ? "zip" : "tar.gz"
1841
+ const assetName = `texlab-${texArch}-${texPlatform}.${ext}`
1842
+
1843
+ const assets = release.assets ?? []
1844
+ const asset = assets.find((a) => a.name === assetName)
1845
+ if (!asset?.browser_download_url) {
1846
+ log.error(`Could not find asset ${assetName} in texlab release`)
1847
+ return
1848
+ }
1849
+
1850
+ const downloadResponse = await fetch(asset.browser_download_url)
1851
+ if (!downloadResponse.ok) {
1852
+ log.error("Failed to download texlab")
1853
+ return
1854
+ }
1855
+
1856
+ const tempPath = path.join(Global.Path.bin, assetName)
1857
+ if (downloadResponse.body) await Filesystem.writeStream(tempPath, downloadResponse.body)
1858
+
1859
+ if (ext === "zip") {
1860
+ const ok = await Archive.extractZip(tempPath, Global.Path.bin)
1861
+ .then(() => true)
1862
+ .catch((error) => {
1863
+ log.error("Failed to extract texlab archive", { error })
1864
+ return false
1865
+ })
1866
+ if (!ok) return
1867
+ }
1868
+ if (ext === "tar.gz") {
1869
+ await $`tar -xzf ${tempPath}`.cwd(Global.Path.bin).quiet().nothrow()
1870
+ }
1871
+
1872
+ await fs.rm(tempPath, { force: true })
1873
+
1874
+ bin = path.join(Global.Path.bin, "texlab" + (platform === "win32" ? ".exe" : ""))
1875
+
1876
+ if (!(await Filesystem.exists(bin))) {
1877
+ log.error("Failed to extract texlab binary")
1878
+ return
1879
+ }
1880
+
1881
+ if (platform !== "win32") {
1882
+ await $`chmod +x ${bin}`.quiet().nothrow()
1883
+ }
1884
+
1885
+ log.info("installed texlab", { bin })
1886
+ }
1887
+
1888
+ return {
1889
+ process: spawn(bin, {
1890
+ cwd: root,
1891
+ }),
1892
+ }
1893
+ },
1894
+ }
1895
+
1896
+ export const DockerfileLS: Info = {
1897
+ id: "dockerfile",
1898
+ extensions: [".dockerfile", "Dockerfile"],
1899
+ root: async () => Instance.directory,
1900
+ async spawn(root) {
1901
+ let binary = Bun.which("docker-langserver")
1902
+ const args: string[] = []
1903
+ if (!binary) {
1904
+ const js = path.join(Global.Path.bin, "node_modules", "dockerfile-language-server-nodejs", "lib", "server.js")
1905
+ if (!(await Filesystem.exists(js))) {
1906
+ if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
1907
+ await Process.spawn([BunProc.which(), "install", "dockerfile-language-server-nodejs"], {
1908
+ cwd: Global.Path.bin,
1909
+ env: {
1910
+ ...process.env,
1911
+ BUN_BE_BUN: "1",
1912
+ },
1913
+ stdout: "pipe",
1914
+ stderr: "pipe",
1915
+ stdin: "pipe",
1916
+ }).exited
1917
+ }
1918
+ binary = BunProc.which()
1919
+ args.push("run", js)
1920
+ }
1921
+ args.push("--stdio")
1922
+ const proc = spawn(binary, args, {
1923
+ cwd: root,
1924
+ env: {
1925
+ ...process.env,
1926
+ BUN_BE_BUN: "1",
1927
+ },
1928
+ })
1929
+ return {
1930
+ process: proc,
1931
+ }
1932
+ },
1933
+ }
1934
+
1935
+ export const Gleam: Info = {
1936
+ id: "gleam",
1937
+ extensions: [".gleam"],
1938
+ root: NearestRoot(["gleam.toml"]),
1939
+ async spawn(root) {
1940
+ const gleam = Bun.which("gleam")
1941
+ if (!gleam) {
1942
+ log.info("gleam not found, please install gleam first")
1943
+ return
1944
+ }
1945
+ return {
1946
+ process: spawn(gleam, ["lsp"], {
1947
+ cwd: root,
1948
+ }),
1949
+ }
1950
+ },
1951
+ }
1952
+
1953
+ export const Clojure: Info = {
1954
+ id: "clojure-lsp",
1955
+ extensions: [".clj", ".cljs", ".cljc", ".edn"],
1956
+ root: NearestRoot(["deps.edn", "project.clj", "shadow-cljs.edn", "bb.edn", "build.boot"]),
1957
+ async spawn(root) {
1958
+ let bin = Bun.which("clojure-lsp")
1959
+ if (!bin && process.platform === "win32") {
1960
+ bin = Bun.which("clojure-lsp.exe")
1961
+ }
1962
+ if (!bin) {
1963
+ log.info("clojure-lsp not found, please install clojure-lsp first")
1964
+ return
1965
+ }
1966
+ return {
1967
+ process: spawn(bin, ["listen"], {
1968
+ cwd: root,
1969
+ }),
1970
+ }
1971
+ },
1972
+ }
1973
+
1974
+ export const Nixd: Info = {
1975
+ id: "nixd",
1976
+ extensions: [".nix"],
1977
+ root: async (file) => {
1978
+ // First, look for flake.nix - the most reliable Nix project root indicator
1979
+ const flakeRoot = await NearestRoot(["flake.nix"])(file)
1980
+ if (flakeRoot && flakeRoot !== Instance.directory) return flakeRoot
1981
+
1982
+ // If no flake.nix, fall back to git repository root
1983
+ if (Instance.worktree && Instance.worktree !== Instance.directory) return Instance.worktree
1984
+
1985
+ // Finally, use the instance directory as fallback
1986
+ return Instance.directory
1987
+ },
1988
+ async spawn(root) {
1989
+ const nixd = Bun.which("nixd")
1990
+ if (!nixd) {
1991
+ log.info("nixd not found, please install nixd first")
1992
+ return
1993
+ }
1994
+ return {
1995
+ process: spawn(nixd, [], {
1996
+ cwd: root,
1997
+ env: {
1998
+ ...process.env,
1999
+ },
2000
+ }),
2001
+ }
2002
+ },
2003
+ }
2004
+
2005
+ export const Tinymist: Info = {
2006
+ id: "tinymist",
2007
+ extensions: [".typ", ".typc"],
2008
+ root: NearestRoot(["typst.toml"]),
2009
+ async spawn(root) {
2010
+ let bin = Bun.which("tinymist", {
2011
+ PATH: process.env["PATH"] + path.delimiter + Global.Path.bin,
2012
+ })
2013
+
2014
+ if (!bin) {
2015
+ if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
2016
+
2017
+ // Offline mode: skip download
2018
+ if (isOfflineMode()) {
2019
+ log.warn("offline mode: cannot download tinymist")
2020
+ log.warn("please install manually from https://github.com/Myriad-Dreamin/tinymist/releases")
2021
+ return
2022
+ }
2023
+
2024
+ log.info("downloading tinymist from GitHub releases")
2025
+
2026
+ const response = await fetch("https://api.github.com/repos/Myriad-Dreamin/tinymist/releases/latest")
2027
+ if (!response.ok) {
2028
+ log.error("Failed to fetch tinymist release info")
2029
+ return
2030
+ }
2031
+
2032
+ const release = (await response.json()) as {
2033
+ tag_name?: string
2034
+ assets?: { name?: string; browser_download_url?: string }[]
2035
+ }
2036
+
2037
+ const platform = process.platform
2038
+ const arch = process.arch
2039
+
2040
+ const tinymistArch = arch === "arm64" ? "aarch64" : "x86_64"
2041
+ let tinymistPlatform: string
2042
+ let ext: string
2043
+
2044
+ if (platform === "darwin") {
2045
+ tinymistPlatform = "apple-darwin"
2046
+ ext = "tar.gz"
2047
+ } else if (platform === "win32") {
2048
+ tinymistPlatform = "pc-windows-msvc"
2049
+ ext = "zip"
2050
+ } else {
2051
+ tinymistPlatform = "unknown-linux-gnu"
2052
+ ext = "tar.gz"
2053
+ }
2054
+
2055
+ const assetName = `tinymist-${tinymistArch}-${tinymistPlatform}.${ext}`
2056
+
2057
+ const assets = release.assets ?? []
2058
+ const asset = assets.find((a) => a.name === assetName)
2059
+ if (!asset?.browser_download_url) {
2060
+ log.error(`Could not find asset ${assetName} in tinymist release`)
2061
+ return
2062
+ }
2063
+
2064
+ const downloadResponse = await fetch(asset.browser_download_url)
2065
+ if (!downloadResponse.ok) {
2066
+ log.error("Failed to download tinymist")
2067
+ return
2068
+ }
2069
+
2070
+ const tempPath = path.join(Global.Path.bin, assetName)
2071
+ if (downloadResponse.body) await Filesystem.writeStream(tempPath, downloadResponse.body)
2072
+
2073
+ if (ext === "zip") {
2074
+ const ok = await Archive.extractZip(tempPath, Global.Path.bin)
2075
+ .then(() => true)
2076
+ .catch((error) => {
2077
+ log.error("Failed to extract tinymist archive", { error })
2078
+ return false
2079
+ })
2080
+ if (!ok) return
2081
+ } else {
2082
+ await $`tar -xzf ${tempPath} --strip-components=1`.cwd(Global.Path.bin).quiet().nothrow()
2083
+ }
2084
+
2085
+ await fs.rm(tempPath, { force: true })
2086
+
2087
+ bin = path.join(Global.Path.bin, "tinymist" + (platform === "win32" ? ".exe" : ""))
2088
+
2089
+ if (!(await Filesystem.exists(bin))) {
2090
+ log.error("Failed to extract tinymist binary")
2091
+ return
2092
+ }
2093
+
2094
+ if (platform !== "win32") {
2095
+ await $`chmod +x ${bin}`.quiet().nothrow()
2096
+ }
2097
+
2098
+ log.info("installed tinymist", { bin })
2099
+ }
2100
+
2101
+ return {
2102
+ process: spawn(bin, { cwd: root }),
2103
+ }
2104
+ },
2105
+ }
2106
+
2107
+ export const HLS: Info = {
2108
+ id: "haskell-language-server",
2109
+ extensions: [".hs", ".lhs"],
2110
+ root: NearestRoot(["stack.yaml", "cabal.project", "hie.yaml", "*.cabal"]),
2111
+ async spawn(root) {
2112
+ const bin = Bun.which("haskell-language-server-wrapper")
2113
+ if (!bin) {
2114
+ log.info("haskell-language-server-wrapper not found, please install haskell-language-server")
2115
+ return
2116
+ }
2117
+ return {
2118
+ process: spawn(bin, ["--lsp"], {
2119
+ cwd: root,
2120
+ }),
2121
+ }
2122
+ },
2123
+ }
2124
+
2125
+ export const JuliaLS: Info = {
2126
+ id: "julials",
2127
+ extensions: [".jl"],
2128
+ root: NearestRoot(["Project.toml", "Manifest.toml", "*.jl"]),
2129
+ async spawn(root) {
2130
+ const julia = Bun.which("julia")
2131
+ if (!julia) {
2132
+ log.info("julia not found, please install julia first (https://julialang.org/downloads/)")
2133
+ return
2134
+ }
2135
+ return {
2136
+ process: spawn(julia, ["--startup-file=no", "--history-file=no", "-e", "using LanguageServer; runserver()"], {
2137
+ cwd: root,
2138
+ }),
2139
+ }
2140
+ },
2141
+ }
2142
+ }