alchemylab-opencode 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.
- package/LICENSE +21 -0
- package/NODE_COMPAT.md +184 -0
- package/package.json +112 -0
- package/packages/opencode/migration/20260127222353_familiar_lady_ursula/migration.sql +90 -0
- package/packages/opencode/migration/20260127222353_familiar_lady_ursula/snapshot.json +796 -0
- package/packages/opencode/migration/20260211171708_add_project_commands/migration.sql +1 -0
- package/packages/opencode/migration/20260211171708_add_project_commands/snapshot.json +806 -0
- package/packages/opencode/migration/20260213144116_wakeful_the_professor/migration.sql +11 -0
- package/packages/opencode/migration/20260213144116_wakeful_the_professor/snapshot.json +897 -0
- package/packages/opencode/migration/20260225215848_workspace/migration.sql +7 -0
- package/packages/opencode/migration/20260225215848_workspace/snapshot.json +959 -0
- package/packages/opencode/migration/20260227213759_add_session_workspace_id/migration.sql +2 -0
- package/packages/opencode/migration/20260227213759_add_session_workspace_id/snapshot.json +983 -0
- package/packages/opencode/migration/20260228203230_blue_harpoon/migration.sql +17 -0
- package/packages/opencode/migration/20260228203230_blue_harpoon/snapshot.json +1102 -0
- package/packages/opencode/migration/20260303231226_add_workspace_fields/migration.sql +5 -0
- package/packages/opencode/migration/20260303231226_add_workspace_fields/snapshot.json +1013 -0
- package/packages/opencode/migration/20260309230000_move_org_to_state/migration.sql +3 -0
- package/packages/opencode/migration/20260309230000_move_org_to_state/snapshot.json +1156 -0
- package/packages/opencode/migration/20260312043431_session_message_cursor/migration.sql +4 -0
- package/packages/opencode/migration/20260312043431_session_message_cursor/snapshot.json +1168 -0
- package/packages/opencode/migration/20260323234822_events/migration.sql +13 -0
- package/packages/opencode/migration/20260323234822_events/snapshot.json +1271 -0
- package/packages/opencode/package.json +140 -0
- package/packages/opencode/src/account/account.sql.ts +39 -0
- package/packages/opencode/src/account/index.ts +463 -0
- package/packages/opencode/src/account/repo.ts +163 -0
- package/packages/opencode/src/account/schema.ts +91 -0
- package/packages/opencode/src/acp/README.md +174 -0
- package/packages/opencode/src/acp/agent.ts +1847 -0
- package/packages/opencode/src/acp/session.ts +116 -0
- package/packages/opencode/src/acp/types.ts +24 -0
- package/packages/opencode/src/agent/agent.ts +420 -0
- package/packages/opencode/src/agent/generate.txt +75 -0
- package/packages/opencode/src/agent/prompt/compaction.txt +15 -0
- package/packages/opencode/src/agent/prompt/explore.txt +18 -0
- package/packages/opencode/src/agent/prompt/summary.txt +11 -0
- package/packages/opencode/src/agent/prompt/title.txt +44 -0
- package/packages/opencode/src/auth/index.ts +110 -0
- package/packages/opencode/src/bus/bus-event.ts +40 -0
- package/packages/opencode/src/bus/global.ts +10 -0
- package/packages/opencode/src/bus/index.ts +185 -0
- package/packages/opencode/src/cli/bootstrap.ts +17 -0
- package/packages/opencode/src/cli/cmd/cmd.ts +7 -0
- package/packages/opencode/src/cli/cmd/run.ts +689 -0
- package/packages/opencode/src/cli/cmd/serve.ts +24 -0
- package/packages/opencode/src/cli/cmd/tui/event.ts +49 -0
- package/packages/opencode/src/cli/effect/prompt.ts +25 -0
- package/packages/opencode/src/cli/error.ts +46 -0
- package/packages/opencode/src/cli/heap.ts +59 -0
- package/packages/opencode/src/cli/logo.ts +6 -0
- package/packages/opencode/src/cli/network.ts +60 -0
- package/packages/opencode/src/cli/ui.ts +133 -0
- package/packages/opencode/src/cli/upgrade.ts +31 -0
- package/packages/opencode/src/command/index.ts +195 -0
- package/packages/opencode/src/command/template/initialize.txt +66 -0
- package/packages/opencode/src/command/template/review.txt +101 -0
- package/packages/opencode/src/config/config.ts +1599 -0
- package/packages/opencode/src/config/console-state.ts +15 -0
- package/packages/opencode/src/config/markdown.ts +99 -0
- package/packages/opencode/src/config/paths.ts +167 -0
- package/packages/opencode/src/config/tui-migrate.ts +155 -0
- package/packages/opencode/src/config/tui-schema.ts +37 -0
- package/packages/opencode/src/config/tui.ts +179 -0
- package/packages/opencode/src/control-plane/adaptors/index.ts +20 -0
- package/packages/opencode/src/control-plane/adaptors/worktree.ts +42 -0
- package/packages/opencode/src/control-plane/schema.ts +17 -0
- package/packages/opencode/src/control-plane/sse.ts +66 -0
- package/packages/opencode/src/control-plane/types.ts +32 -0
- package/packages/opencode/src/control-plane/workspace.sql.ts +17 -0
- package/packages/opencode/src/control-plane/workspace.ts +168 -0
- package/packages/opencode/src/effect/cross-spawn-spawner.ts +502 -0
- package/packages/opencode/src/effect/instance-ref.ts +6 -0
- package/packages/opencode/src/effect/instance-registry.ts +12 -0
- package/packages/opencode/src/effect/instance-state.ts +82 -0
- package/packages/opencode/src/effect/run-service.ts +33 -0
- package/packages/opencode/src/effect/runner.ts +216 -0
- package/packages/opencode/src/env/index.ts +28 -0
- package/packages/opencode/src/file/ignore.ts +82 -0
- package/packages/opencode/src/file/index.ts +686 -0
- package/packages/opencode/src/file/protected.ts +59 -0
- package/packages/opencode/src/file/ripgrep.ts +376 -0
- package/packages/opencode/src/file/time.ts +133 -0
- package/packages/opencode/src/file/watcher.ts +173 -0
- package/packages/opencode/src/filesystem/index.ts +236 -0
- package/packages/opencode/src/flag/flag.ts +156 -0
- package/packages/opencode/src/format/formatter.ts +413 -0
- package/packages/opencode/src/format/index.ts +203 -0
- package/packages/opencode/src/git/index.ts +303 -0
- package/packages/opencode/src/global/index.ts +56 -0
- package/packages/opencode/src/id/id.ts +85 -0
- package/packages/opencode/src/ide/index.ts +74 -0
- package/packages/opencode/src/installation/index.ts +355 -0
- package/packages/opencode/src/installation/meta.ts +7 -0
- package/packages/opencode/src/lsp/client.ts +252 -0
- package/packages/opencode/src/lsp/index.ts +558 -0
- package/packages/opencode/src/lsp/language.ts +120 -0
- package/packages/opencode/src/lsp/launch.ts +21 -0
- package/packages/opencode/src/lsp/server.ts +1968 -0
- package/packages/opencode/src/mcp/auth.ts +173 -0
- package/packages/opencode/src/mcp/index.ts +931 -0
- package/packages/opencode/src/mcp/oauth-callback.ts +216 -0
- package/packages/opencode/src/mcp/oauth-provider.ts +185 -0
- package/packages/opencode/src/node-loader.mjs +104 -0
- package/packages/opencode/src/node-preload.mjs +39 -0
- package/packages/opencode/src/node.ts +1 -0
- package/packages/opencode/src/npm/index.ts +188 -0
- package/packages/opencode/src/patch/index.ts +680 -0
- package/packages/opencode/src/permission/arity.ts +163 -0
- package/packages/opencode/src/permission/evaluate.ts +15 -0
- package/packages/opencode/src/permission/index.ts +325 -0
- package/packages/opencode/src/permission/schema.ts +17 -0
- package/packages/opencode/src/plugin/cloudflare.ts +67 -0
- package/packages/opencode/src/plugin/codex.ts +608 -0
- package/packages/opencode/src/plugin/github-copilot/copilot.ts +361 -0
- package/packages/opencode/src/plugin/github-copilot/models.ts +144 -0
- package/packages/opencode/src/plugin/index.ts +299 -0
- package/packages/opencode/src/plugin/install.ts +439 -0
- package/packages/opencode/src/plugin/loader.ts +174 -0
- package/packages/opencode/src/plugin/meta.ts +188 -0
- package/packages/opencode/src/plugin/shared.ts +323 -0
- package/packages/opencode/src/project/bootstrap.ts +31 -0
- package/packages/opencode/src/project/instance.ts +175 -0
- package/packages/opencode/src/project/project.sql.ts +16 -0
- package/packages/opencode/src/project/project.ts +519 -0
- package/packages/opencode/src/project/schema.ts +16 -0
- package/packages/opencode/src/project/state.ts +70 -0
- package/packages/opencode/src/project/vcs.ts +240 -0
- package/packages/opencode/src/provider/auth.ts +253 -0
- package/packages/opencode/src/provider/error.ts +197 -0
- package/packages/opencode/src/provider/models.ts +162 -0
- package/packages/opencode/src/provider/provider.ts +1709 -0
- package/packages/opencode/src/provider/schema.ts +38 -0
- package/packages/opencode/src/provider/sdk/copilot/README.md +5 -0
- package/packages/opencode/src/provider/sdk/copilot/chat/convert-to-openai-compatible-chat-messages.ts +170 -0
- package/packages/opencode/src/provider/sdk/copilot/chat/get-response-metadata.ts +15 -0
- package/packages/opencode/src/provider/sdk/copilot/chat/map-openai-compatible-finish-reason.ts +19 -0
- package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-api-types.ts +64 -0
- package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-chat-language-model.ts +815 -0
- package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-chat-options.ts +28 -0
- package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-metadata-extractor.ts +44 -0
- package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-prepare-tools.ts +83 -0
- package/packages/opencode/src/provider/sdk/copilot/copilot-provider.ts +100 -0
- package/packages/opencode/src/provider/sdk/copilot/index.ts +2 -0
- package/packages/opencode/src/provider/sdk/copilot/openai-compatible-error.ts +27 -0
- package/packages/opencode/src/provider/sdk/copilot/responses/convert-to-openai-responses-input.ts +335 -0
- package/packages/opencode/src/provider/sdk/copilot/responses/map-openai-responses-finish-reason.ts +22 -0
- package/packages/opencode/src/provider/sdk/copilot/responses/openai-config.ts +18 -0
- package/packages/opencode/src/provider/sdk/copilot/responses/openai-error.ts +22 -0
- package/packages/opencode/src/provider/sdk/copilot/responses/openai-responses-api-types.ts +214 -0
- package/packages/opencode/src/provider/sdk/copilot/responses/openai-responses-language-model.ts +1769 -0
- package/packages/opencode/src/provider/sdk/copilot/responses/openai-responses-prepare-tools.ts +173 -0
- package/packages/opencode/src/provider/sdk/copilot/responses/openai-responses-settings.ts +1 -0
- package/packages/opencode/src/provider/sdk/copilot/responses/tool/code-interpreter.ts +87 -0
- package/packages/opencode/src/provider/sdk/copilot/responses/tool/file-search.ts +127 -0
- package/packages/opencode/src/provider/sdk/copilot/responses/tool/image-generation.ts +114 -0
- package/packages/opencode/src/provider/sdk/copilot/responses/tool/local-shell.ts +64 -0
- package/packages/opencode/src/provider/sdk/copilot/responses/tool/web-search-preview.ts +103 -0
- package/packages/opencode/src/provider/sdk/copilot/responses/tool/web-search.ts +102 -0
- package/packages/opencode/src/provider/transform.ts +1050 -0
- package/packages/opencode/src/pty/index.ts +397 -0
- package/packages/opencode/src/pty/pty.node.ts +27 -0
- package/packages/opencode/src/pty/pty.ts +25 -0
- package/packages/opencode/src/pty/schema.ts +17 -0
- package/packages/opencode/src/question/index.ts +224 -0
- package/packages/opencode/src/question/schema.ts +17 -0
- package/packages/opencode/src/run.ts +28 -0
- package/packages/opencode/src/serve.ts +45 -0
- package/packages/opencode/src/server/error.ts +36 -0
- package/packages/opencode/src/server/event.ts +7 -0
- package/packages/opencode/src/server/instance.ts +324 -0
- package/packages/opencode/src/server/mdns.ts +60 -0
- package/packages/opencode/src/server/middleware.ts +33 -0
- package/packages/opencode/src/server/projectors.ts +28 -0
- package/packages/opencode/src/server/proxy.ts +131 -0
- package/packages/opencode/src/server/router.ts +105 -0
- package/packages/opencode/src/server/routes/config.ts +92 -0
- package/packages/opencode/src/server/routes/event.ts +83 -0
- package/packages/opencode/src/server/routes/experimental.ts +374 -0
- package/packages/opencode/src/server/routes/file.ts +197 -0
- package/packages/opencode/src/server/routes/global.ts +312 -0
- package/packages/opencode/src/server/routes/mcp.ts +225 -0
- package/packages/opencode/src/server/routes/permission.ts +69 -0
- package/packages/opencode/src/server/routes/project.ts +118 -0
- package/packages/opencode/src/server/routes/provider.ts +171 -0
- package/packages/opencode/src/server/routes/pty.ts +210 -0
- package/packages/opencode/src/server/routes/question.ts +99 -0
- package/packages/opencode/src/server/routes/session.ts +1030 -0
- package/packages/opencode/src/server/routes/tui.ts +379 -0
- package/packages/opencode/src/server/routes/workspace.ts +94 -0
- package/packages/opencode/src/server/server.ts +353 -0
- package/packages/opencode/src/session/compaction.ts +428 -0
- package/packages/opencode/src/session/index.ts +887 -0
- package/packages/opencode/src/session/instruction.ts +258 -0
- package/packages/opencode/src/session/llm.ts +354 -0
- package/packages/opencode/src/session/message-v2.ts +1031 -0
- package/packages/opencode/src/session/message.ts +191 -0
- package/packages/opencode/src/session/overflow.ts +22 -0
- package/packages/opencode/src/session/processor.ts +523 -0
- package/packages/opencode/src/session/projectors.ts +135 -0
- package/packages/opencode/src/session/prompt/anthropic.txt +105 -0
- package/packages/opencode/src/session/prompt/beast.txt +147 -0
- package/packages/opencode/src/session/prompt/build-switch.txt +5 -0
- package/packages/opencode/src/session/prompt/codex.txt +79 -0
- package/packages/opencode/src/session/prompt/copilot-gpt-5.txt +143 -0
- package/packages/opencode/src/session/prompt/default.txt +105 -0
- package/packages/opencode/src/session/prompt/gemini.txt +155 -0
- package/packages/opencode/src/session/prompt/gpt.txt +107 -0
- package/packages/opencode/src/session/prompt/kimi.txt +95 -0
- package/packages/opencode/src/session/prompt/max-steps.txt +16 -0
- package/packages/opencode/src/session/prompt/plan-reminder-anthropic.txt +67 -0
- package/packages/opencode/src/session/prompt/plan.txt +26 -0
- package/packages/opencode/src/session/prompt/trinity.txt +97 -0
- package/packages/opencode/src/session/prompt.ts +1911 -0
- package/packages/opencode/src/session/retry.ts +106 -0
- package/packages/opencode/src/session/revert.ts +176 -0
- package/packages/opencode/src/session/schema.ts +38 -0
- package/packages/opencode/src/session/session.sql.ts +103 -0
- package/packages/opencode/src/session/status.ts +102 -0
- package/packages/opencode/src/session/summary.ts +177 -0
- package/packages/opencode/src/session/system.ts +76 -0
- package/packages/opencode/src/session/todo.ts +95 -0
- package/packages/opencode/src/share/share-next.ts +369 -0
- package/packages/opencode/src/share/share.sql.ts +13 -0
- package/packages/opencode/src/shell/shell.ts +110 -0
- package/packages/opencode/src/skill/discovery.ts +116 -0
- package/packages/opencode/src/skill/index.ts +277 -0
- package/packages/opencode/src/snapshot/index.ts +726 -0
- package/packages/opencode/src/sql.d.ts +4 -0
- package/packages/opencode/src/storage/db.node.ts +8 -0
- package/packages/opencode/src/storage/db.ts +177 -0
- package/packages/opencode/src/storage/json-migration.ts +425 -0
- package/packages/opencode/src/storage/schema.sql.ts +10 -0
- package/packages/opencode/src/storage/schema.ts +5 -0
- package/packages/opencode/src/storage/storage.ts +353 -0
- package/packages/opencode/src/sync/README.md +179 -0
- package/packages/opencode/src/sync/event.sql.ts +16 -0
- package/packages/opencode/src/sync/index.ts +263 -0
- package/packages/opencode/src/sync/schema.ts +14 -0
- package/packages/opencode/src/tool/apply_patch.ts +281 -0
- package/packages/opencode/src/tool/apply_patch.txt +33 -0
- package/packages/opencode/src/tool/bash.ts +496 -0
- package/packages/opencode/src/tool/bash.txt +117 -0
- package/packages/opencode/src/tool/batch.ts +183 -0
- package/packages/opencode/src/tool/batch.txt +24 -0
- package/packages/opencode/src/tool/codesearch.ts +132 -0
- package/packages/opencode/src/tool/codesearch.txt +12 -0
- package/packages/opencode/src/tool/edit.ts +667 -0
- package/packages/opencode/src/tool/edit.txt +10 -0
- package/packages/opencode/src/tool/external-directory.ts +46 -0
- package/packages/opencode/src/tool/glob.ts +78 -0
- package/packages/opencode/src/tool/glob.txt +6 -0
- package/packages/opencode/src/tool/grep.ts +156 -0
- package/packages/opencode/src/tool/grep.txt +8 -0
- package/packages/opencode/src/tool/invalid.ts +17 -0
- package/packages/opencode/src/tool/ls.ts +121 -0
- package/packages/opencode/src/tool/ls.txt +1 -0
- package/packages/opencode/src/tool/lsp.ts +97 -0
- package/packages/opencode/src/tool/lsp.txt +19 -0
- package/packages/opencode/src/tool/multiedit.ts +46 -0
- package/packages/opencode/src/tool/multiedit.txt +41 -0
- package/packages/opencode/src/tool/plan-enter.txt +14 -0
- package/packages/opencode/src/tool/plan-exit.txt +13 -0
- package/packages/opencode/src/tool/plan.ts +131 -0
- package/packages/opencode/src/tool/question.ts +46 -0
- package/packages/opencode/src/tool/question.txt +10 -0
- package/packages/opencode/src/tool/read.ts +332 -0
- package/packages/opencode/src/tool/read.txt +14 -0
- package/packages/opencode/src/tool/registry.ts +265 -0
- package/packages/opencode/src/tool/schema.ts +17 -0
- package/packages/opencode/src/tool/skill.ts +105 -0
- package/packages/opencode/src/tool/task.ts +166 -0
- package/packages/opencode/src/tool/task.txt +60 -0
- package/packages/opencode/src/tool/todo.ts +48 -0
- package/packages/opencode/src/tool/todowrite.txt +167 -0
- package/packages/opencode/src/tool/tool.ts +112 -0
- package/packages/opencode/src/tool/truncate.ts +144 -0
- package/packages/opencode/src/tool/truncation-dir.ts +4 -0
- package/packages/opencode/src/tool/webfetch.ts +206 -0
- package/packages/opencode/src/tool/webfetch.txt +13 -0
- package/packages/opencode/src/tool/websearch.ts +150 -0
- package/packages/opencode/src/tool/websearch.txt +14 -0
- package/packages/opencode/src/tool/write.ts +84 -0
- package/packages/opencode/src/tool/write.txt +8 -0
- package/packages/opencode/src/util/abort.ts +35 -0
- package/packages/opencode/src/util/archive.ts +17 -0
- package/packages/opencode/src/util/color.ts +19 -0
- package/packages/opencode/src/util/context.ts +25 -0
- package/packages/opencode/src/util/data-url.ts +9 -0
- package/packages/opencode/src/util/defer.ts +12 -0
- package/packages/opencode/src/util/effect-http-client.ts +11 -0
- package/packages/opencode/src/util/effect-zod.ts +98 -0
- package/packages/opencode/src/util/error.ts +77 -0
- package/packages/opencode/src/util/filesystem.ts +245 -0
- package/packages/opencode/src/util/flock.ts +333 -0
- package/packages/opencode/src/util/fn.ts +21 -0
- package/packages/opencode/src/util/format.ts +20 -0
- package/packages/opencode/src/util/glob.ts +34 -0
- package/packages/opencode/src/util/hash.ts +7 -0
- package/packages/opencode/src/util/iife.ts +3 -0
- package/packages/opencode/src/util/keybind.ts +103 -0
- package/packages/opencode/src/util/lazy.ts +23 -0
- package/packages/opencode/src/util/locale.ts +81 -0
- package/packages/opencode/src/util/lock.ts +98 -0
- package/packages/opencode/src/util/log.ts +182 -0
- package/packages/opencode/src/util/network.ts +9 -0
- package/packages/opencode/src/util/process.ts +176 -0
- package/packages/opencode/src/util/queue.ts +32 -0
- package/packages/opencode/src/util/record.ts +3 -0
- package/packages/opencode/src/util/rpc.ts +66 -0
- package/packages/opencode/src/util/schema.ts +53 -0
- package/packages/opencode/src/util/scrap.ts +10 -0
- package/packages/opencode/src/util/signal.ts +12 -0
- package/packages/opencode/src/util/timeout.ts +14 -0
- package/packages/opencode/src/util/token.ts +7 -0
- package/packages/opencode/src/util/update-schema.ts +13 -0
- package/packages/opencode/src/util/which.ts +14 -0
- package/packages/opencode/src/util/wildcard.ts +59 -0
- package/packages/opencode/src/worktree/index.ts +612 -0
- package/packages/plugin/package.json +38 -0
- package/packages/plugin/src/example.ts +18 -0
- package/packages/plugin/src/index.ts +282 -0
- package/packages/plugin/src/shell.ts +136 -0
- package/packages/plugin/src/tool.ts +38 -0
- package/packages/plugin/src/tui.ts +508 -0
- package/packages/script/package.json +16 -0
- package/packages/script/src/index.ts +77 -0
- package/packages/sdk/package.json +33 -0
- package/packages/sdk/src/client.ts +55 -0
- package/packages/sdk/src/gen/client/client.gen.ts +212 -0
- package/packages/sdk/src/gen/client/index.ts +25 -0
- package/packages/sdk/src/gen/client/types.gen.ts +222 -0
- package/packages/sdk/src/gen/client/utils.gen.ts +287 -0
- package/packages/sdk/src/gen/client.gen.ts +22 -0
- package/packages/sdk/src/gen/core/auth.gen.ts +41 -0
- package/packages/sdk/src/gen/core/bodySerializer.gen.ts +74 -0
- package/packages/sdk/src/gen/core/params.gen.ts +144 -0
- package/packages/sdk/src/gen/core/pathSerializer.gen.ts +167 -0
- package/packages/sdk/src/gen/core/queryKeySerializer.gen.ts +111 -0
- package/packages/sdk/src/gen/core/serverSentEvents.gen.ts +210 -0
- package/packages/sdk/src/gen/core/types.gen.ts +91 -0
- package/packages/sdk/src/gen/core/utils.gen.ts +109 -0
- package/packages/sdk/src/gen/sdk.gen.ts +1197 -0
- package/packages/sdk/src/gen/types.gen.ts +3904 -0
- package/packages/sdk/src/index.ts +21 -0
- package/packages/sdk/src/process.ts +31 -0
- package/packages/sdk/src/server.ts +134 -0
- package/packages/sdk/src/v2/client.ts +81 -0
- package/packages/sdk/src/v2/gen/client/client.gen.ts +285 -0
- package/packages/sdk/src/v2/gen/client/index.ts +25 -0
- package/packages/sdk/src/v2/gen/client/types.gen.ts +202 -0
- package/packages/sdk/src/v2/gen/client/utils.gen.ts +289 -0
- package/packages/sdk/src/v2/gen/client.gen.ts +18 -0
- package/packages/sdk/src/v2/gen/core/auth.gen.ts +41 -0
- package/packages/sdk/src/v2/gen/core/bodySerializer.gen.ts +82 -0
- package/packages/sdk/src/v2/gen/core/params.gen.ts +169 -0
- package/packages/sdk/src/v2/gen/core/pathSerializer.gen.ts +167 -0
- package/packages/sdk/src/v2/gen/core/queryKeySerializer.gen.ts +111 -0
- package/packages/sdk/src/v2/gen/core/serverSentEvents.gen.ts +239 -0
- package/packages/sdk/src/v2/gen/core/types.gen.ts +86 -0
- package/packages/sdk/src/v2/gen/core/utils.gen.ts +137 -0
- package/packages/sdk/src/v2/gen/sdk.gen.ts +4223 -0
- package/packages/sdk/src/v2/gen/types.gen.ts +5265 -0
- package/packages/sdk/src/v2/index.ts +21 -0
- package/packages/sdk/src/v2/server.ts +134 -0
- package/packages/util/package.json +20 -0
- package/packages/util/src/array.ts +10 -0
- package/packages/util/src/binary.ts +41 -0
- package/packages/util/src/encode.ts +51 -0
- package/packages/util/src/error.ts +54 -0
- package/packages/util/src/fn.ts +11 -0
- package/packages/util/src/identifier.ts +48 -0
- package/packages/util/src/iife.ts +3 -0
- package/packages/util/src/lazy.ts +11 -0
- package/packages/util/src/module.ts +10 -0
- package/packages/util/src/path.ts +37 -0
- package/packages/util/src/retry.ts +41 -0
- package/packages/util/src/slug.ts +74 -0
- package/postinstall.cjs +55 -0
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { Effect, Layer, Schema, ServiceMap, Stream } from "effect"
|
|
2
|
+
import { FetchHttpClient, HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstable/http"
|
|
3
|
+
import * as CrossSpawnSpawner from "@/effect/cross-spawn-spawner"
|
|
4
|
+
import { makeRuntime } from "@/effect/run-service"
|
|
5
|
+
import { withTransientReadRetry } from "@/util/effect-http-client"
|
|
6
|
+
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process"
|
|
7
|
+
import path from "path"
|
|
8
|
+
import z from "zod"
|
|
9
|
+
import { BusEvent } from "@/bus/bus-event"
|
|
10
|
+
import { Flag } from "../flag/flag"
|
|
11
|
+
import { Log } from "../util/log"
|
|
12
|
+
import { CHANNEL as channel, VERSION as version } from "./meta"
|
|
13
|
+
|
|
14
|
+
import semver from "semver"
|
|
15
|
+
|
|
16
|
+
export namespace Installation {
|
|
17
|
+
const log = Log.create({ service: "installation" })
|
|
18
|
+
|
|
19
|
+
export type Method = "curl" | "npm" | "yarn" | "pnpm" | "bun" | "brew" | "scoop" | "choco" | "unknown"
|
|
20
|
+
|
|
21
|
+
export type ReleaseType = "patch" | "minor" | "major"
|
|
22
|
+
|
|
23
|
+
export const Event = {
|
|
24
|
+
Updated: BusEvent.define(
|
|
25
|
+
"installation.updated",
|
|
26
|
+
z.object({
|
|
27
|
+
version: z.string(),
|
|
28
|
+
}),
|
|
29
|
+
),
|
|
30
|
+
UpdateAvailable: BusEvent.define(
|
|
31
|
+
"installation.update-available",
|
|
32
|
+
z.object({
|
|
33
|
+
version: z.string(),
|
|
34
|
+
}),
|
|
35
|
+
),
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function getReleaseType(current: string, latest: string): ReleaseType {
|
|
39
|
+
const currMajor = semver.major(current)
|
|
40
|
+
const currMinor = semver.minor(current)
|
|
41
|
+
const newMajor = semver.major(latest)
|
|
42
|
+
const newMinor = semver.minor(latest)
|
|
43
|
+
|
|
44
|
+
if (newMajor > currMajor) return "major"
|
|
45
|
+
if (newMinor > currMinor) return "minor"
|
|
46
|
+
return "patch"
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const Info = z
|
|
50
|
+
.object({
|
|
51
|
+
version: z.string(),
|
|
52
|
+
latest: z.string(),
|
|
53
|
+
})
|
|
54
|
+
.meta({
|
|
55
|
+
ref: "InstallationInfo",
|
|
56
|
+
})
|
|
57
|
+
export type Info = z.infer<typeof Info>
|
|
58
|
+
|
|
59
|
+
export const VERSION = version
|
|
60
|
+
export const CHANNEL = channel
|
|
61
|
+
export const USER_AGENT = `opencode/${CHANNEL}/${VERSION}/${Flag.OPENCODE_CLIENT}`
|
|
62
|
+
|
|
63
|
+
export function isPreview() {
|
|
64
|
+
return CHANNEL !== "latest"
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function isLocal() {
|
|
68
|
+
return CHANNEL === "local"
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export class UpgradeFailedError extends Schema.TaggedErrorClass<UpgradeFailedError>()("UpgradeFailedError", {
|
|
72
|
+
stderr: Schema.String,
|
|
73
|
+
}) {}
|
|
74
|
+
|
|
75
|
+
// Response schemas for external version APIs
|
|
76
|
+
const GitHubRelease = Schema.Struct({ tag_name: Schema.String })
|
|
77
|
+
const NpmPackage = Schema.Struct({ version: Schema.String })
|
|
78
|
+
const BrewFormula = Schema.Struct({ versions: Schema.Struct({ stable: Schema.String }) })
|
|
79
|
+
const BrewInfoV2 = Schema.Struct({
|
|
80
|
+
formulae: Schema.Array(Schema.Struct({ versions: Schema.Struct({ stable: Schema.String }) })),
|
|
81
|
+
})
|
|
82
|
+
const ChocoPackage = Schema.Struct({
|
|
83
|
+
d: Schema.Struct({ results: Schema.Array(Schema.Struct({ Version: Schema.String })) }),
|
|
84
|
+
})
|
|
85
|
+
const ScoopManifest = NpmPackage
|
|
86
|
+
|
|
87
|
+
export interface Interface {
|
|
88
|
+
readonly info: () => Effect.Effect<Info>
|
|
89
|
+
readonly method: () => Effect.Effect<Method>
|
|
90
|
+
readonly latest: (method?: Method) => Effect.Effect<string>
|
|
91
|
+
readonly upgrade: (method: Method, target: string) => Effect.Effect<void, UpgradeFailedError>
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export class Service extends ServiceMap.Service<Service, Interface>()("@opencode/Installation") {}
|
|
95
|
+
|
|
96
|
+
export const layer: Layer.Layer<Service, never, HttpClient.HttpClient | ChildProcessSpawner.ChildProcessSpawner> =
|
|
97
|
+
Layer.effect(
|
|
98
|
+
Service,
|
|
99
|
+
Effect.gen(function* () {
|
|
100
|
+
const http = yield* HttpClient.HttpClient
|
|
101
|
+
const httpOk = HttpClient.filterStatusOk(withTransientReadRetry(http))
|
|
102
|
+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner
|
|
103
|
+
|
|
104
|
+
const text = Effect.fnUntraced(
|
|
105
|
+
function* (cmd: string[], opts?: { cwd?: string; env?: Record<string, string> }) {
|
|
106
|
+
const proc = ChildProcess.make(cmd[0], cmd.slice(1), {
|
|
107
|
+
cwd: opts?.cwd,
|
|
108
|
+
env: opts?.env,
|
|
109
|
+
extendEnv: true,
|
|
110
|
+
})
|
|
111
|
+
const handle = yield* spawner.spawn(proc)
|
|
112
|
+
const out = yield* Stream.mkString(Stream.decodeText(handle.stdout))
|
|
113
|
+
yield* handle.exitCode
|
|
114
|
+
return out
|
|
115
|
+
},
|
|
116
|
+
Effect.scoped,
|
|
117
|
+
Effect.catch(() => Effect.succeed("")),
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
const run = Effect.fnUntraced(
|
|
121
|
+
function* (cmd: string[], opts?: { cwd?: string; env?: Record<string, string> }) {
|
|
122
|
+
const proc = ChildProcess.make(cmd[0], cmd.slice(1), {
|
|
123
|
+
cwd: opts?.cwd,
|
|
124
|
+
env: opts?.env,
|
|
125
|
+
extendEnv: true,
|
|
126
|
+
})
|
|
127
|
+
const handle = yield* spawner.spawn(proc)
|
|
128
|
+
const [stdout, stderr] = yield* Effect.all(
|
|
129
|
+
[Stream.mkString(Stream.decodeText(handle.stdout)), Stream.mkString(Stream.decodeText(handle.stderr))],
|
|
130
|
+
{ concurrency: 2 },
|
|
131
|
+
)
|
|
132
|
+
const code = yield* handle.exitCode
|
|
133
|
+
return { code, stdout, stderr }
|
|
134
|
+
},
|
|
135
|
+
Effect.scoped,
|
|
136
|
+
Effect.catch(() => Effect.succeed({ code: ChildProcessSpawner.ExitCode(1), stdout: "", stderr: "" })),
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
const getBrewFormula = Effect.fnUntraced(function* () {
|
|
140
|
+
const tapFormula = yield* text(["brew", "list", "--formula", "anomalyco/tap/opencode"])
|
|
141
|
+
if (tapFormula.includes("opencode")) return "anomalyco/tap/opencode"
|
|
142
|
+
const coreFormula = yield* text(["brew", "list", "--formula", "opencode"])
|
|
143
|
+
if (coreFormula.includes("opencode")) return "opencode"
|
|
144
|
+
return "opencode"
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
const upgradeCurl = Effect.fnUntraced(
|
|
148
|
+
function* (target: string) {
|
|
149
|
+
const response = yield* httpOk.execute(HttpClientRequest.get("https://opencode.ai/install"))
|
|
150
|
+
const body = yield* response.text
|
|
151
|
+
const bodyBytes = new TextEncoder().encode(body)
|
|
152
|
+
const proc = ChildProcess.make("bash", [], {
|
|
153
|
+
stdin: Stream.make(bodyBytes),
|
|
154
|
+
env: { VERSION: target },
|
|
155
|
+
extendEnv: true,
|
|
156
|
+
})
|
|
157
|
+
const handle = yield* spawner.spawn(proc)
|
|
158
|
+
const [stdout, stderr] = yield* Effect.all(
|
|
159
|
+
[Stream.mkString(Stream.decodeText(handle.stdout)), Stream.mkString(Stream.decodeText(handle.stderr))],
|
|
160
|
+
{ concurrency: 2 },
|
|
161
|
+
)
|
|
162
|
+
const code = yield* handle.exitCode
|
|
163
|
+
return { code, stdout, stderr }
|
|
164
|
+
},
|
|
165
|
+
Effect.scoped,
|
|
166
|
+
Effect.orDie,
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
const methodImpl = Effect.fn("Installation.method")(function* () {
|
|
170
|
+
if (process.execPath.includes(path.join(".opencode", "bin"))) return "curl" as Method
|
|
171
|
+
if (process.execPath.includes(path.join(".local", "bin"))) return "curl" as Method
|
|
172
|
+
const exec = process.execPath.toLowerCase()
|
|
173
|
+
|
|
174
|
+
const checks: Array<{ name: Method; command: () => Effect.Effect<string> }> = [
|
|
175
|
+
{ name: "npm", command: () => text(["npm", "list", "-g", "--depth=0"]) },
|
|
176
|
+
{ name: "yarn", command: () => text(["yarn", "global", "list"]) },
|
|
177
|
+
{ name: "pnpm", command: () => text(["pnpm", "list", "-g", "--depth=0"]) },
|
|
178
|
+
{ name: "bun", command: () => text(["bun", "pm", "ls", "-g"]) },
|
|
179
|
+
{ name: "brew", command: () => text(["brew", "list", "--formula", "opencode"]) },
|
|
180
|
+
{ name: "scoop", command: () => text(["scoop", "list", "opencode"]) },
|
|
181
|
+
{ name: "choco", command: () => text(["choco", "list", "--limit-output", "opencode"]) },
|
|
182
|
+
]
|
|
183
|
+
|
|
184
|
+
checks.sort((a, b) => {
|
|
185
|
+
const aMatches = exec.includes(a.name)
|
|
186
|
+
const bMatches = exec.includes(b.name)
|
|
187
|
+
if (aMatches && !bMatches) return -1
|
|
188
|
+
if (!aMatches && bMatches) return 1
|
|
189
|
+
return 0
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
for (const check of checks) {
|
|
193
|
+
const output = yield* check.command()
|
|
194
|
+
const installedName =
|
|
195
|
+
check.name === "brew" || check.name === "choco" || check.name === "scoop" ? "opencode" : "opencode-ai"
|
|
196
|
+
if (output.includes(installedName)) {
|
|
197
|
+
return check.name
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return "unknown" as Method
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
const latestImpl = Effect.fn("Installation.latest")(function* (installMethod?: Method) {
|
|
205
|
+
const detectedMethod = installMethod || (yield* methodImpl())
|
|
206
|
+
|
|
207
|
+
if (detectedMethod === "brew") {
|
|
208
|
+
const formula = yield* getBrewFormula()
|
|
209
|
+
if (formula.includes("/")) {
|
|
210
|
+
const infoJson = yield* text(["brew", "info", "--json=v2", formula])
|
|
211
|
+
const info = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(BrewInfoV2))(infoJson)
|
|
212
|
+
return info.formulae[0].versions.stable
|
|
213
|
+
}
|
|
214
|
+
const response = yield* httpOk.execute(
|
|
215
|
+
HttpClientRequest.get("https://formulae.brew.sh/api/formula/opencode.json").pipe(
|
|
216
|
+
HttpClientRequest.acceptJson,
|
|
217
|
+
),
|
|
218
|
+
)
|
|
219
|
+
const data = yield* HttpClientResponse.schemaBodyJson(BrewFormula)(response)
|
|
220
|
+
return data.versions.stable
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (detectedMethod === "npm" || detectedMethod === "bun" || detectedMethod === "pnpm") {
|
|
224
|
+
const r = (yield* text(["npm", "config", "get", "registry"])).trim()
|
|
225
|
+
const reg = r || "https://registry.npmjs.org"
|
|
226
|
+
const registry = reg.endsWith("/") ? reg.slice(0, -1) : reg
|
|
227
|
+
const channel = CHANNEL
|
|
228
|
+
const response = yield* httpOk.execute(
|
|
229
|
+
HttpClientRequest.get(`${registry}/opencode-ai/${channel}`).pipe(HttpClientRequest.acceptJson),
|
|
230
|
+
)
|
|
231
|
+
const data = yield* HttpClientResponse.schemaBodyJson(NpmPackage)(response)
|
|
232
|
+
return data.version
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (detectedMethod === "choco") {
|
|
236
|
+
const response = yield* httpOk.execute(
|
|
237
|
+
HttpClientRequest.get(
|
|
238
|
+
"https://community.chocolatey.org/api/v2/Packages?$filter=Id%20eq%20%27opencode%27%20and%20IsLatestVersion&$select=Version",
|
|
239
|
+
).pipe(HttpClientRequest.setHeaders({ Accept: "application/json;odata=verbose" })),
|
|
240
|
+
)
|
|
241
|
+
const data = yield* HttpClientResponse.schemaBodyJson(ChocoPackage)(response)
|
|
242
|
+
return data.d.results[0].Version
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (detectedMethod === "scoop") {
|
|
246
|
+
const response = yield* httpOk.execute(
|
|
247
|
+
HttpClientRequest.get(
|
|
248
|
+
"https://raw.githubusercontent.com/ScoopInstaller/Main/master/bucket/opencode.json",
|
|
249
|
+
).pipe(HttpClientRequest.setHeaders({ Accept: "application/json" })),
|
|
250
|
+
)
|
|
251
|
+
const data = yield* HttpClientResponse.schemaBodyJson(ScoopManifest)(response)
|
|
252
|
+
return data.version
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const response = yield* httpOk.execute(
|
|
256
|
+
HttpClientRequest.get("https://api.github.com/repos/anomalyco/opencode/releases/latest").pipe(
|
|
257
|
+
HttpClientRequest.acceptJson,
|
|
258
|
+
),
|
|
259
|
+
)
|
|
260
|
+
const data = yield* HttpClientResponse.schemaBodyJson(GitHubRelease)(response)
|
|
261
|
+
return data.tag_name.replace(/^v/, "")
|
|
262
|
+
}, Effect.orDie)
|
|
263
|
+
|
|
264
|
+
const upgradeImpl = Effect.fn("Installation.upgrade")(function* (m: Method, target: string) {
|
|
265
|
+
let result: { code: ChildProcessSpawner.ExitCode; stdout: string; stderr: string } | undefined
|
|
266
|
+
switch (m) {
|
|
267
|
+
case "curl":
|
|
268
|
+
result = yield* upgradeCurl(target)
|
|
269
|
+
break
|
|
270
|
+
case "npm":
|
|
271
|
+
result = yield* run(["npm", "install", "-g", `opencode-ai@${target}`])
|
|
272
|
+
break
|
|
273
|
+
case "pnpm":
|
|
274
|
+
result = yield* run(["pnpm", "install", "-g", `opencode-ai@${target}`])
|
|
275
|
+
break
|
|
276
|
+
case "bun":
|
|
277
|
+
result = yield* run(["bun", "install", "-g", `opencode-ai@${target}`])
|
|
278
|
+
break
|
|
279
|
+
case "brew": {
|
|
280
|
+
const formula = yield* getBrewFormula()
|
|
281
|
+
const env = { HOMEBREW_NO_AUTO_UPDATE: "1" }
|
|
282
|
+
if (formula.includes("/")) {
|
|
283
|
+
const tap = yield* run(["brew", "tap", "anomalyco/tap"], { env })
|
|
284
|
+
if (tap.code !== 0) {
|
|
285
|
+
result = tap
|
|
286
|
+
break
|
|
287
|
+
}
|
|
288
|
+
const repo = yield* text(["brew", "--repo", "anomalyco/tap"])
|
|
289
|
+
const dir = repo.trim()
|
|
290
|
+
if (dir) {
|
|
291
|
+
const pull = yield* run(["git", "pull", "--ff-only"], { cwd: dir, env })
|
|
292
|
+
if (pull.code !== 0) {
|
|
293
|
+
result = pull
|
|
294
|
+
break
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
result = yield* run(["brew", "upgrade", formula], { env })
|
|
299
|
+
break
|
|
300
|
+
}
|
|
301
|
+
case "choco":
|
|
302
|
+
result = yield* run(["choco", "upgrade", "opencode", `--version=${target}`, "-y"])
|
|
303
|
+
break
|
|
304
|
+
case "scoop":
|
|
305
|
+
result = yield* run(["scoop", "install", `opencode@${target}`])
|
|
306
|
+
break
|
|
307
|
+
default:
|
|
308
|
+
return yield* new UpgradeFailedError({ stderr: `Unknown method: ${m}` })
|
|
309
|
+
}
|
|
310
|
+
if (!result || result.code !== 0) {
|
|
311
|
+
const stderr = m === "choco" ? "not running from an elevated command shell" : result?.stderr || ""
|
|
312
|
+
return yield* new UpgradeFailedError({ stderr })
|
|
313
|
+
}
|
|
314
|
+
log.info("upgraded", {
|
|
315
|
+
method: m,
|
|
316
|
+
target,
|
|
317
|
+
stdout: result.stdout,
|
|
318
|
+
stderr: result.stderr,
|
|
319
|
+
})
|
|
320
|
+
yield* text([process.execPath, "--version"])
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
return Service.of({
|
|
324
|
+
info: Effect.fn("Installation.info")(function* () {
|
|
325
|
+
return {
|
|
326
|
+
version: VERSION,
|
|
327
|
+
latest: yield* latestImpl(),
|
|
328
|
+
}
|
|
329
|
+
}),
|
|
330
|
+
method: methodImpl,
|
|
331
|
+
latest: latestImpl,
|
|
332
|
+
upgrade: upgradeImpl,
|
|
333
|
+
})
|
|
334
|
+
}),
|
|
335
|
+
)
|
|
336
|
+
|
|
337
|
+
export const defaultLayer = layer.pipe(
|
|
338
|
+
Layer.provide(FetchHttpClient.layer),
|
|
339
|
+
Layer.provide(CrossSpawnSpawner.defaultLayer),
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
const { runPromise } = makeRuntime(Service, defaultLayer)
|
|
343
|
+
|
|
344
|
+
export async function method(): Promise<Method> {
|
|
345
|
+
return runPromise((svc) => svc.method())
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
export async function latest(installMethod?: Method): Promise<string> {
|
|
349
|
+
return runPromise((svc) => svc.latest(installMethod))
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export async function upgrade(m: Method, target: string): Promise<void> {
|
|
353
|
+
return runPromise((svc) => svc.upgrade(m, target))
|
|
354
|
+
}
|
|
355
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
const OPENCODE_VERSION: string
|
|
3
|
+
const OPENCODE_CHANNEL: string
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export const VERSION = typeof OPENCODE_VERSION === "string" ? OPENCODE_VERSION : "local"
|
|
7
|
+
export const CHANNEL = typeof OPENCODE_CHANNEL === "string" ? OPENCODE_CHANNEL : "local"
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { BusEvent } from "@/bus/bus-event"
|
|
2
|
+
import { Bus } from "@/bus"
|
|
3
|
+
import path from "path"
|
|
4
|
+
import { pathToFileURL, fileURLToPath } from "url"
|
|
5
|
+
import { createMessageConnection, StreamMessageReader, StreamMessageWriter } from "vscode-jsonrpc/node"
|
|
6
|
+
import type { Diagnostic as VSCodeDiagnostic } from "vscode-languageserver-types"
|
|
7
|
+
import { Log } from "../util/log"
|
|
8
|
+
import { Process } from "../util/process"
|
|
9
|
+
import { LANGUAGE_EXTENSIONS } from "./language"
|
|
10
|
+
import z from "zod"
|
|
11
|
+
import type { LSPServer } from "./server"
|
|
12
|
+
import { NamedError } from "@opencode-ai/util/error"
|
|
13
|
+
import { withTimeout } from "../util/timeout"
|
|
14
|
+
import { Instance } from "../project/instance"
|
|
15
|
+
import { Filesystem } from "../util/filesystem"
|
|
16
|
+
|
|
17
|
+
const DIAGNOSTICS_DEBOUNCE_MS = 150
|
|
18
|
+
|
|
19
|
+
export namespace LSPClient {
|
|
20
|
+
const log = Log.create({ service: "lsp.client" })
|
|
21
|
+
|
|
22
|
+
export type Info = NonNullable<Awaited<ReturnType<typeof create>>>
|
|
23
|
+
|
|
24
|
+
export type Diagnostic = VSCodeDiagnostic
|
|
25
|
+
|
|
26
|
+
export const InitializeError = NamedError.create(
|
|
27
|
+
"LSPInitializeError",
|
|
28
|
+
z.object({
|
|
29
|
+
serverID: z.string(),
|
|
30
|
+
}),
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
export const Event = {
|
|
34
|
+
Diagnostics: BusEvent.define(
|
|
35
|
+
"lsp.client.diagnostics",
|
|
36
|
+
z.object({
|
|
37
|
+
serverID: z.string(),
|
|
38
|
+
path: z.string(),
|
|
39
|
+
}),
|
|
40
|
+
),
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function create(input: { serverID: string; server: LSPServer.Handle; root: string }) {
|
|
44
|
+
const l = log.clone().tag("serverID", input.serverID)
|
|
45
|
+
l.info("starting client")
|
|
46
|
+
|
|
47
|
+
const connection = createMessageConnection(
|
|
48
|
+
new StreamMessageReader(input.server.process.stdout as any),
|
|
49
|
+
new StreamMessageWriter(input.server.process.stdin as any),
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
const diagnostics = new Map<string, Diagnostic[]>()
|
|
53
|
+
connection.onNotification("textDocument/publishDiagnostics", (params) => {
|
|
54
|
+
const filePath = Filesystem.normalizePath(fileURLToPath(params.uri))
|
|
55
|
+
l.info("textDocument/publishDiagnostics", {
|
|
56
|
+
path: filePath,
|
|
57
|
+
count: params.diagnostics.length,
|
|
58
|
+
})
|
|
59
|
+
const exists = diagnostics.has(filePath)
|
|
60
|
+
diagnostics.set(filePath, params.diagnostics)
|
|
61
|
+
if (!exists && input.serverID === "typescript") return
|
|
62
|
+
Bus.publish(Event.Diagnostics, { path: filePath, serverID: input.serverID })
|
|
63
|
+
})
|
|
64
|
+
connection.onRequest("window/workDoneProgress/create", (params) => {
|
|
65
|
+
l.info("window/workDoneProgress/create", params)
|
|
66
|
+
return null
|
|
67
|
+
})
|
|
68
|
+
connection.onRequest("workspace/configuration", async () => {
|
|
69
|
+
// Return server initialization options
|
|
70
|
+
return [input.server.initialization ?? {}]
|
|
71
|
+
})
|
|
72
|
+
connection.onRequest("client/registerCapability", async () => {})
|
|
73
|
+
connection.onRequest("client/unregisterCapability", async () => {})
|
|
74
|
+
connection.onRequest("workspace/workspaceFolders", async () => [
|
|
75
|
+
{
|
|
76
|
+
name: "workspace",
|
|
77
|
+
uri: pathToFileURL(input.root).href,
|
|
78
|
+
},
|
|
79
|
+
])
|
|
80
|
+
connection.listen()
|
|
81
|
+
|
|
82
|
+
l.info("sending initialize")
|
|
83
|
+
await withTimeout(
|
|
84
|
+
connection.sendRequest("initialize", {
|
|
85
|
+
rootUri: pathToFileURL(input.root).href,
|
|
86
|
+
processId: input.server.process.pid,
|
|
87
|
+
workspaceFolders: [
|
|
88
|
+
{
|
|
89
|
+
name: "workspace",
|
|
90
|
+
uri: pathToFileURL(input.root).href,
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
initializationOptions: {
|
|
94
|
+
...input.server.initialization,
|
|
95
|
+
},
|
|
96
|
+
capabilities: {
|
|
97
|
+
window: {
|
|
98
|
+
workDoneProgress: true,
|
|
99
|
+
},
|
|
100
|
+
workspace: {
|
|
101
|
+
configuration: true,
|
|
102
|
+
didChangeWatchedFiles: {
|
|
103
|
+
dynamicRegistration: true,
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
textDocument: {
|
|
107
|
+
synchronization: {
|
|
108
|
+
didOpen: true,
|
|
109
|
+
didChange: true,
|
|
110
|
+
},
|
|
111
|
+
publishDiagnostics: {
|
|
112
|
+
versionSupport: true,
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
}),
|
|
117
|
+
45_000,
|
|
118
|
+
).catch((err) => {
|
|
119
|
+
l.error("initialize error", { error: err })
|
|
120
|
+
throw new InitializeError(
|
|
121
|
+
{ serverID: input.serverID },
|
|
122
|
+
{
|
|
123
|
+
cause: err,
|
|
124
|
+
},
|
|
125
|
+
)
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
await connection.sendNotification("initialized", {})
|
|
129
|
+
|
|
130
|
+
if (input.server.initialization) {
|
|
131
|
+
await connection.sendNotification("workspace/didChangeConfiguration", {
|
|
132
|
+
settings: input.server.initialization,
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const files: {
|
|
137
|
+
[path: string]: number
|
|
138
|
+
} = {}
|
|
139
|
+
|
|
140
|
+
const result = {
|
|
141
|
+
root: input.root,
|
|
142
|
+
get serverID() {
|
|
143
|
+
return input.serverID
|
|
144
|
+
},
|
|
145
|
+
get connection() {
|
|
146
|
+
return connection
|
|
147
|
+
},
|
|
148
|
+
notify: {
|
|
149
|
+
async open(input: { path: string }) {
|
|
150
|
+
input.path = path.isAbsolute(input.path) ? input.path : path.resolve(Instance.directory, input.path)
|
|
151
|
+
const text = await Filesystem.readText(input.path)
|
|
152
|
+
const extension = path.extname(input.path)
|
|
153
|
+
const languageId = LANGUAGE_EXTENSIONS[extension] ?? "plaintext"
|
|
154
|
+
|
|
155
|
+
const version = files[input.path]
|
|
156
|
+
if (version !== undefined) {
|
|
157
|
+
log.info("workspace/didChangeWatchedFiles", input)
|
|
158
|
+
await connection.sendNotification("workspace/didChangeWatchedFiles", {
|
|
159
|
+
changes: [
|
|
160
|
+
{
|
|
161
|
+
uri: pathToFileURL(input.path).href,
|
|
162
|
+
type: 2, // Changed
|
|
163
|
+
},
|
|
164
|
+
],
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
const next = version + 1
|
|
168
|
+
files[input.path] = next
|
|
169
|
+
log.info("textDocument/didChange", {
|
|
170
|
+
path: input.path,
|
|
171
|
+
version: next,
|
|
172
|
+
})
|
|
173
|
+
await connection.sendNotification("textDocument/didChange", {
|
|
174
|
+
textDocument: {
|
|
175
|
+
uri: pathToFileURL(input.path).href,
|
|
176
|
+
version: next,
|
|
177
|
+
},
|
|
178
|
+
contentChanges: [{ text }],
|
|
179
|
+
})
|
|
180
|
+
return
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
log.info("workspace/didChangeWatchedFiles", input)
|
|
184
|
+
await connection.sendNotification("workspace/didChangeWatchedFiles", {
|
|
185
|
+
changes: [
|
|
186
|
+
{
|
|
187
|
+
uri: pathToFileURL(input.path).href,
|
|
188
|
+
type: 1, // Created
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
log.info("textDocument/didOpen", input)
|
|
194
|
+
diagnostics.delete(input.path)
|
|
195
|
+
await connection.sendNotification("textDocument/didOpen", {
|
|
196
|
+
textDocument: {
|
|
197
|
+
uri: pathToFileURL(input.path).href,
|
|
198
|
+
languageId,
|
|
199
|
+
version: 0,
|
|
200
|
+
text,
|
|
201
|
+
},
|
|
202
|
+
})
|
|
203
|
+
files[input.path] = 0
|
|
204
|
+
return
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
get diagnostics() {
|
|
208
|
+
return diagnostics
|
|
209
|
+
},
|
|
210
|
+
async waitForDiagnostics(input: { path: string }) {
|
|
211
|
+
const normalizedPath = Filesystem.normalizePath(
|
|
212
|
+
path.isAbsolute(input.path) ? input.path : path.resolve(Instance.directory, input.path),
|
|
213
|
+
)
|
|
214
|
+
log.info("waiting for diagnostics", { path: normalizedPath })
|
|
215
|
+
let unsub: () => void
|
|
216
|
+
let debounceTimer: ReturnType<typeof setTimeout> | undefined
|
|
217
|
+
return await withTimeout(
|
|
218
|
+
new Promise<void>((resolve) => {
|
|
219
|
+
unsub = Bus.subscribe(Event.Diagnostics, (event) => {
|
|
220
|
+
if (event.properties.path === normalizedPath && event.properties.serverID === result.serverID) {
|
|
221
|
+
// Debounce to allow LSP to send follow-up diagnostics (e.g., semantic after syntax)
|
|
222
|
+
if (debounceTimer) clearTimeout(debounceTimer)
|
|
223
|
+
debounceTimer = setTimeout(() => {
|
|
224
|
+
log.info("got diagnostics", { path: normalizedPath })
|
|
225
|
+
unsub?.()
|
|
226
|
+
resolve()
|
|
227
|
+
}, DIAGNOSTICS_DEBOUNCE_MS)
|
|
228
|
+
}
|
|
229
|
+
})
|
|
230
|
+
}),
|
|
231
|
+
3000,
|
|
232
|
+
)
|
|
233
|
+
.catch(() => {})
|
|
234
|
+
.finally(() => {
|
|
235
|
+
if (debounceTimer) clearTimeout(debounceTimer)
|
|
236
|
+
unsub?.()
|
|
237
|
+
})
|
|
238
|
+
},
|
|
239
|
+
async shutdown() {
|
|
240
|
+
l.info("shutting down")
|
|
241
|
+
connection.end()
|
|
242
|
+
connection.dispose()
|
|
243
|
+
await Process.stop(input.server.process)
|
|
244
|
+
l.info("shutdown")
|
|
245
|
+
},
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
l.info("initialized")
|
|
249
|
+
|
|
250
|
+
return result
|
|
251
|
+
}
|
|
252
|
+
}
|