oh-my-opencode 4.8.1 → 4.9.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/dist/agents/prometheus/system-prompt.d.ts +1 -1
- package/dist/agents/sisyphus/claude-fable-5.d.ts +19 -0
- package/dist/agents/sisyphus/claude-opus-4-7.d.ts +3 -1
- package/dist/agents/sisyphus/claude-opus-4-8.d.ts +19 -0
- package/dist/agents/sisyphus/index.d.ts +4 -0
- package/dist/agents/types.d.ts +2 -2
- package/dist/cli/doctor/checks/codex.d.ts +1 -0
- package/dist/cli/doctor/checks/tools-gh.d.ts +8 -1
- package/dist/cli/doctor/index.d.ts +1 -0
- package/dist/cli/doctor/types.d.ts +2 -0
- package/dist/cli/index.js +1885 -776
- package/dist/cli/install-codex/codex-config-permissions.d.ts +1 -1
- package/dist/cli/install-codex/codex-config-plugins.d.ts +1 -0
- package/dist/cli/install-codex/codex-config-toml.d.ts +1 -0
- package/dist/cli/install-codex/codex-installer-bin-dir.d.ts +8 -0
- package/dist/cli/install-codex/install-codex.d.ts +1 -8
- package/dist/cli/install-codex/lsp-daemon-reaper.d.ts +5 -0
- package/dist/cli/sparkshell-condense.d.ts +10 -0
- package/dist/cli/sparkshell-parse.d.ts +3 -0
- package/dist/cli/sparkshell-session-context.d.ts +20 -0
- package/dist/cli/sparkshell-spark.d.ts +23 -0
- package/dist/cli/sparkshell.d.ts +8 -1
- package/dist/cli-node/index.js +92552 -0
- package/dist/config/schema/agent-names.d.ts +2 -0
- package/dist/config/schema/hooks.d.ts +0 -2
- package/dist/config/schema/keyword-detector.d.ts +0 -6
- package/dist/config/schema/oh-my-opencode-config.d.ts +2 -4
- package/dist/create-hooks.d.ts +0 -2
- package/dist/features/background-agent/parent-wake-dedupe.d.ts +2 -0
- package/dist/features/background-agent/parent-wake-flush-runner.d.ts +2 -0
- package/dist/features/background-agent/parent-wake-prompt-dispatch.d.ts +1 -0
- package/dist/features/background-agent/parent-wake-session-history.d.ts +4 -0
- package/dist/features/background-agent/parent-wake-session-inspector.d.ts +1 -0
- package/dist/features/builtin-commands/templates/handoff.d.ts +1 -1
- package/dist/features/builtin-skills/index.d.ts +1 -1
- package/dist/features/builtin-skills/skills.d.ts +4 -0
- package/dist/features/opencode-runtime-skills/source-server.d.ts +16 -1
- package/dist/features/opencode-skill-loader/skill-definition-record.d.ts +2 -0
- package/dist/features/team-mode/tools/lifecycle-test-fixture.d.ts +2 -0
- package/dist/features/team-mode/types.d.ts +1 -0
- package/dist/features/tmux-subagent/failed-readiness-cache.d.ts +28 -0
- package/dist/features/tmux-subagent/manager.d.ts +1 -9
- package/dist/features/tmux-subagent/resolve-server-url.d.ts +3 -0
- package/dist/hooks/anthropic-context-window-limit-recovery/executor.d.ts +1 -1
- package/dist/hooks/index.d.ts +0 -1
- package/dist/hooks/keyword-detector/constants.d.ts +0 -4
- package/dist/hooks/keyword-detector/ultrawork/source-detector.d.ts +1 -1
- package/dist/index.js +9001 -1795
- package/dist/oh-my-opencode.schema.json +2 -4
- package/dist/plugin/chat-params.d.ts +1 -8
- package/dist/plugin/hooks/create-core-hooks.d.ts +0 -2
- package/dist/plugin/hooks/create-session-hooks.d.ts +0 -2
- package/dist/plugin/hooks/create-transform-hooks.d.ts +1 -2
- package/dist/plugin/messages-transform.d.ts +0 -1
- package/dist/shared/model-availability.d.ts +10 -2
- package/package.json +25 -18
- package/packages/ast-grep-mcp/dist/cli.js +2 -10
- package/packages/git-bash-mcp/dist/cli.js +11 -4
- package/packages/lsp-daemon/dist/cli.d.ts +2 -0
- package/packages/lsp-daemon/dist/cli.js +3711 -0
- package/packages/lsp-daemon/dist/daemon-client.d.ts +19 -0
- package/packages/lsp-daemon/dist/daemon-client.js +114 -0
- package/packages/lsp-daemon/dist/daemon-server.d.ts +12 -0
- package/packages/lsp-daemon/dist/daemon-server.js +106 -0
- package/packages/lsp-daemon/dist/ensure-daemon.d.ts +21 -0
- package/packages/lsp-daemon/dist/ensure-daemon.js +97 -0
- package/packages/lsp-daemon/dist/index.d.ts +5 -0
- package/packages/lsp-daemon/dist/index.js +3573 -0
- package/packages/lsp-daemon/dist/lock.d.ts +7 -0
- package/packages/lsp-daemon/dist/lock.js +61 -0
- package/packages/lsp-daemon/dist/package.json +6 -0
- package/packages/lsp-daemon/dist/paths.d.ts +11 -0
- package/packages/lsp-daemon/dist/paths.js +49 -0
- package/packages/lsp-daemon/dist/proxy.d.ts +10 -0
- package/packages/lsp-daemon/dist/proxy.js +61 -0
- package/packages/lsp-daemon/dist/request-routing.d.ts +9 -0
- package/packages/lsp-daemon/dist/request-routing.js +44 -0
- package/packages/lsp-daemon/dist/run-daemon.d.ts +1 -0
- package/packages/lsp-daemon/dist/run-daemon.js +11 -0
- package/packages/lsp-daemon/dist/socket-jsonrpc.d.ts +5 -0
- package/packages/lsp-daemon/dist/socket-jsonrpc.js +25 -0
- package/packages/lsp-daemon/package.json +38 -0
- package/packages/lsp-tools-mcp/dist/cli.js +0 -0
- package/packages/lsp-tools-mcp/dist/lsp/client-wrapper.js +40 -17
- package/packages/lsp-tools-mcp/dist/lsp/client.js +11 -9
- package/packages/lsp-tools-mcp/dist/lsp/config-loader.js +5 -5
- package/packages/lsp-tools-mcp/dist/lsp/directory-diagnostics.js +5 -3
- package/packages/lsp-tools-mcp/dist/lsp/effective-extension.d.ts +1 -0
- package/packages/lsp-tools-mcp/dist/lsp/effective-extension.js +8 -0
- package/packages/lsp-tools-mcp/dist/lsp/infer-extension.js +3 -2
- package/packages/lsp-tools-mcp/dist/lsp/language-mappings.js +1 -0
- package/packages/lsp-tools-mcp/dist/lsp/server-definitions.js +12 -0
- package/packages/lsp-tools-mcp/dist/lsp/server-install-state.d.ts +12 -0
- package/packages/lsp-tools-mcp/dist/lsp/server-install-state.js +51 -0
- package/packages/lsp-tools-mcp/dist/lsp/workspace-edit.js +2 -1
- package/packages/lsp-tools-mcp/dist/request-context.d.ts +7 -0
- package/packages/lsp-tools-mcp/dist/request-context.js +14 -0
- package/packages/lsp-tools-mcp/dist/tools.js +44 -1
- package/packages/omo-codex/plugin/.codex-plugin/plugin.json +46 -33
- package/packages/omo-codex/plugin/.mcp.json +1 -1
- package/packages/omo-codex/plugin/components/comment-checker/dist/apply-patch.d.ts +7 -0
- package/packages/omo-codex/plugin/components/comment-checker/dist/apply-patch.js +173 -0
- package/packages/omo-codex/plugin/components/comment-checker/dist/cli.d.ts +2 -0
- package/packages/omo-codex/plugin/components/comment-checker/dist/cli.js +10 -0
- package/packages/omo-codex/plugin/components/comment-checker/dist/codex-hook.d.ts +22 -0
- package/packages/omo-codex/plugin/components/comment-checker/dist/codex-hook.js +165 -0
- package/packages/omo-codex/plugin/components/comment-checker/dist/core-values.d.ts +1 -0
- package/packages/omo-codex/plugin/components/comment-checker/dist/core-values.js +1 -0
- package/packages/omo-codex/plugin/components/comment-checker/dist/core.d.ts +5 -0
- package/packages/omo-codex/plugin/components/comment-checker/dist/core.js +4 -0
- package/packages/omo-codex/plugin/components/comment-checker/dist/hook-input.d.ts +6 -0
- package/packages/omo-codex/plugin/components/comment-checker/dist/hook-input.js +10 -0
- package/packages/omo-codex/plugin/components/comment-checker/dist/record.d.ts +2 -0
- package/packages/omo-codex/plugin/components/comment-checker/dist/record.js +11 -0
- package/packages/omo-codex/plugin/components/comment-checker/dist/request-extractor.d.ts +3 -0
- package/packages/omo-codex/plugin/components/comment-checker/dist/request-extractor.js +104 -0
- package/packages/omo-codex/plugin/components/comment-checker/dist/runner.d.ts +26 -0
- package/packages/omo-codex/plugin/components/comment-checker/dist/runner.js +144 -0
- package/packages/omo-codex/plugin/components/comment-checker/dist/types.d.ts +43 -0
- package/packages/omo-codex/plugin/components/comment-checker/dist/types.js +1 -0
- package/packages/omo-codex/plugin/components/comment-checker/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/comment-checker/package.json +1 -1
- package/packages/omo-codex/plugin/components/git-bash/dist/cli.d.ts +2 -0
- package/packages/omo-codex/plugin/components/git-bash/dist/cli.js +29 -0
- package/packages/omo-codex/plugin/components/git-bash/dist/codex-hook.d.ts +28 -0
- package/packages/omo-codex/plugin/components/git-bash/dist/codex-hook.js +137 -0
- package/packages/omo-codex/plugin/components/git-bash/dist/index.d.ts +1 -0
- package/packages/omo-codex/plugin/components/git-bash/dist/index.js +1 -0
- package/packages/omo-codex/plugin/components/git-bash/hooks/hooks.json +2 -2
- package/packages/omo-codex/plugin/components/git-bash/package.json +5 -2
- package/packages/omo-codex/plugin/components/lsp/.mcp.json +1 -1
- package/packages/omo-codex/plugin/components/lsp/dist/cli.d.ts +2 -0
- package/packages/omo-codex/plugin/components/lsp/dist/cli.js +42 -0
- package/packages/omo-codex/plugin/components/lsp/dist/codex-hook-cli.d.ts +2 -0
- package/packages/omo-codex/plugin/components/lsp/dist/codex-hook-cli.js +40 -0
- package/packages/omo-codex/plugin/components/lsp/dist/codex-hook.d.ts +16 -0
- package/packages/omo-codex/plugin/components/lsp/dist/codex-hook.js +180 -0
- package/packages/omo-codex/plugin/components/lsp/dist/lsp-session-state.d.ts +12 -0
- package/packages/omo-codex/plugin/components/lsp/dist/lsp-session-state.js +95 -0
- package/packages/omo-codex/plugin/components/lsp/dist/mutated-file-paths.d.ts +6 -0
- package/packages/omo-codex/plugin/components/lsp/dist/mutated-file-paths.js +79 -0
- package/packages/omo-codex/plugin/components/lsp/hooks/hooks.json +2 -2
- package/packages/omo-codex/plugin/components/lsp/package.json +7 -7
- package/packages/omo-codex/plugin/components/lsp/scripts/build-lsp-daemon.mjs +68 -0
- package/packages/omo-codex/plugin/components/lsp/scripts/build-lsp-tools.mjs +45 -22
- package/packages/omo-codex/plugin/components/lsp/src/cli.ts +1 -1
- package/packages/omo-codex/plugin/components/lsp/src/codex-hook-cli.ts +1 -1
- package/packages/omo-codex/plugin/components/lsp/src/codex-hook.ts +6 -2
- package/packages/omo-codex/plugin/components/lsp/src/lsp-session-state.ts +4 -0
- package/packages/omo-codex/plugin/components/lsp/test/codex-hook-unavailable.test.ts +68 -0
- package/packages/omo-codex/plugin/components/lsp/test/package-smoke.test.ts +8 -20
- package/packages/omo-codex/plugin/components/rules/bundled-rules/hephaestus.md +69 -96
- package/packages/omo-codex/plugin/components/rules/dist/cli.d.ts +2 -0
- package/packages/omo-codex/plugin/components/rules/dist/cli.js +118 -0
- package/packages/omo-codex/plugin/components/rules/dist/codex-hook-options.d.ts +5 -0
- package/packages/omo-codex/plugin/components/rules/dist/codex-hook-options.js +1 -0
- package/packages/omo-codex/plugin/components/rules/dist/codex-hook.d.ts +47 -0
- package/packages/omo-codex/plugin/components/rules/dist/codex-hook.js +127 -0
- package/packages/omo-codex/plugin/components/rules/dist/config.d.ts +2 -0
- package/packages/omo-codex/plugin/components/rules/dist/config.js +100 -0
- package/packages/omo-codex/plugin/components/rules/dist/context-pressure.d.ts +2 -0
- package/packages/omo-codex/plugin/components/rules/dist/context-pressure.js +26 -0
- package/packages/omo-codex/plugin/components/rules/dist/debug-log.d.ts +8 -0
- package/packages/omo-codex/plugin/components/rules/dist/debug-log.js +36 -0
- package/packages/omo-codex/plugin/components/rules/dist/dynamic-target-fingerprints.d.ts +7 -0
- package/packages/omo-codex/plugin/components/rules/dist/dynamic-target-fingerprints.js +65 -0
- package/packages/omo-codex/plugin/components/rules/dist/event-budget.d.ts +3 -0
- package/packages/omo-codex/plugin/components/rules/dist/event-budget.js +14 -0
- package/packages/omo-codex/plugin/components/rules/dist/hook-output.d.ts +2 -0
- package/packages/omo-codex/plugin/components/rules/dist/hook-output.js +24 -0
- package/packages/omo-codex/plugin/components/rules/dist/path-utils.d.ts +4 -0
- package/packages/omo-codex/plugin/components/rules/dist/path-utils.js +24 -0
- package/packages/omo-codex/plugin/components/rules/dist/persistent-cache.d.ts +13 -0
- package/packages/omo-codex/plugin/components/rules/dist/persistent-cache.js +172 -0
- package/packages/omo-codex/plugin/components/rules/dist/post-compact-budget.d.ts +6 -0
- package/packages/omo-codex/plugin/components/rules/dist/post-compact-budget.js +74 -0
- package/packages/omo-codex/plugin/components/rules/dist/post-compact-claim.d.ts +4 -0
- package/packages/omo-codex/plugin/components/rules/dist/post-compact-claim.js +6 -0
- package/packages/omo-codex/plugin/components/rules/dist/post-compact-directive.d.ts +1 -0
- package/packages/omo-codex/plugin/components/rules/dist/post-compact-directive.js +32 -0
- package/packages/omo-codex/plugin/components/rules/dist/post-compact-state.d.ts +13 -0
- package/packages/omo-codex/plugin/components/rules/dist/post-compact-state.js +29 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/cache.d.ts +9 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/cache.js +51 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/constants.d.ts +70 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/constants.js +101 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/engine-dynamic-cache.d.ts +5 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/engine-dynamic-cache.js +60 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/engine-dynamic-loader.d.ts +6 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/engine-dynamic-loader.js +61 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/engine-loader.d.ts +7 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/engine-loader.js +60 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/engine-paths.d.ts +11 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/engine-paths.js +75 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/engine-static-loader.d.ts +6 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/engine-static-loader.js +29 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/engine-types.d.ts +44 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/engine-types.js +1 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/engine.d.ts +5 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/engine.js +85 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/errors.d.ts +6 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/errors.js +12 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/finder-cache.d.ts +14 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/finder-cache.js +51 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/finder-paths.d.ts +6 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/finder-paths.js +33 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/finder-sources.d.ts +5 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/finder-sources.js +40 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/finder.d.ts +28 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/finder.js +146 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/formatter.d.ts +7 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/formatter.js +112 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/matcher.d.ts +18 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/matcher.js +93 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/ordering.d.ts +3 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/ordering.js +27 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/parser-frontmatter.d.ts +7 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/parser-frontmatter.js +30 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/parser-yaml.d.ts +2 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/parser-yaml.js +237 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/parser.d.ts +3 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/parser.js +31 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/plugin-root.d.ts +1 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/plugin-root.js +48 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/project-root.d.ts +1 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/project-root.js +23 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/scanner.d.ts +14 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/scanner.js +111 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/sources.d.ts +3 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/sources.js +9 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/truncator.d.ts +18 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/truncator.js +59 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/types.d.ts +126 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules/types.js +8 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules-engine-factory.d.ts +6 -0
- package/packages/omo-codex/plugin/components/rules/dist/rules-engine-factory.js +20 -0
- package/packages/omo-codex/plugin/components/rules/dist/session-state-lock.d.ts +3 -0
- package/packages/omo-codex/plugin/components/rules/dist/session-state-lock.js +41 -0
- package/packages/omo-codex/plugin/components/rules/dist/sparkshell-awareness.d.ts +10 -0
- package/packages/omo-codex/plugin/components/rules/dist/sparkshell-awareness.js +90 -0
- package/packages/omo-codex/plugin/components/rules/dist/static-injection.d.ts +3 -0
- package/packages/omo-codex/plugin/components/rules/dist/static-injection.js +128 -0
- package/packages/omo-codex/plugin/components/rules/dist/tool-paths.d.ts +6 -0
- package/packages/omo-codex/plugin/components/rules/dist/tool-paths.js +168 -0
- package/packages/omo-codex/plugin/components/rules/dist/transcript-rule-filter.d.ts +4 -0
- package/packages/omo-codex/plugin/components/rules/dist/transcript-rule-filter.js +49 -0
- package/packages/omo-codex/plugin/components/rules/dist/transcript-search.d.ts +4 -0
- package/packages/omo-codex/plugin/components/rules/dist/transcript-search.js +91 -0
- package/packages/omo-codex/plugin/components/rules/hooks/hooks.json +4 -4
- package/packages/omo-codex/plugin/components/rules/package.json +1 -1
- package/packages/omo-codex/plugin/components/rules/src/codex-hook.ts +4 -2
- package/packages/omo-codex/plugin/components/rules/src/config.ts +13 -0
- package/packages/omo-codex/plugin/components/rules/src/event-budget.ts +17 -0
- package/packages/omo-codex/plugin/components/rules/src/persistent-cache.ts +4 -1
- package/packages/omo-codex/plugin/components/rules/src/post-compact-directive.ts +39 -0
- package/packages/omo-codex/plugin/components/rules/src/rules/constants.ts +16 -0
- package/packages/omo-codex/plugin/components/rules/src/rules/engine.ts +8 -0
- package/packages/omo-codex/plugin/components/rules/src/rules/types.ts +4 -0
- package/packages/omo-codex/plugin/components/rules/src/sparkshell-awareness.ts +53 -4
- package/packages/omo-codex/plugin/components/rules/src/static-injection.ts +127 -7
- package/packages/omo-codex/plugin/components/rules/src/transcript-rule-filter.ts +9 -1
- package/packages/omo-codex/plugin/components/rules/test/bundled-rules.test.ts +4 -2
- package/packages/omo-codex/plugin/components/rules/test/codex-hook-post-compact-budget.test.ts +7 -2
- package/packages/omo-codex/plugin/components/rules/test/codex-hook-post-compact-context.test.ts +9 -9
- package/packages/omo-codex/plugin/components/rules/test/codex-hook-post-compact-dedup.test.ts +10 -4
- package/packages/omo-codex/plugin/components/rules/test/codex-hook-post-compact-directive.test.ts +241 -0
- package/packages/omo-codex/plugin/components/rules/test/event-budget.test.ts +168 -0
- package/packages/omo-codex/plugin/components/rules/test/post-compact-budget.test.ts +4 -0
- package/packages/omo-codex/plugin/components/rules/test/sparkshell-awareness.test.ts +86 -3
- package/packages/omo-codex/plugin/components/start-work-continuation/directive.md +15 -15
- package/packages/omo-codex/plugin/components/start-work-continuation/dist/boulder-reader.d.ts +16 -0
- package/packages/omo-codex/plugin/components/start-work-continuation/dist/boulder-reader.js +146 -0
- package/packages/omo-codex/plugin/components/start-work-continuation/dist/cli.d.ts +2 -0
- package/packages/omo-codex/plugin/components/start-work-continuation/dist/cli.js +49 -0
- package/packages/omo-codex/plugin/components/start-work-continuation/dist/codex-hook.d.ts +2 -0
- package/packages/omo-codex/plugin/components/start-work-continuation/dist/codex-hook.js +80 -0
- package/packages/omo-codex/plugin/components/start-work-continuation/dist/directive.d.ts +1 -0
- package/packages/omo-codex/plugin/components/start-work-continuation/dist/directive.js +2 -0
- package/packages/omo-codex/plugin/components/start-work-continuation/dist/index.d.ts +5 -0
- package/packages/omo-codex/plugin/components/start-work-continuation/dist/index.js +3 -0
- package/packages/omo-codex/plugin/components/start-work-continuation/dist/types.d.ts +20 -0
- package/packages/omo-codex/plugin/components/start-work-continuation/dist/types.js +1 -0
- package/packages/omo-codex/plugin/components/start-work-continuation/hooks/hooks.json +2 -2
- package/packages/omo-codex/plugin/components/start-work-continuation/package.json +1 -1
- package/packages/omo-codex/plugin/components/start-work-continuation/test/codex-hook.test.ts +24 -2
- package/packages/omo-codex/plugin/components/telemetry/dist/atomic-write.d.ts +1 -0
- package/packages/omo-codex/plugin/components/telemetry/dist/atomic-write.js +18 -0
- package/packages/omo-codex/plugin/components/telemetry/dist/cli.d.ts +2 -0
- package/packages/omo-codex/plugin/components/telemetry/dist/cli.js +62 -0
- package/packages/omo-codex/plugin/components/telemetry/dist/codex-hook.d.ts +15 -0
- package/packages/omo-codex/plugin/components/telemetry/dist/codex-hook.js +42 -0
- package/packages/omo-codex/plugin/components/telemetry/dist/data-path.d.ts +10 -0
- package/packages/omo-codex/plugin/components/telemetry/dist/data-path.js +35 -0
- package/packages/omo-codex/plugin/components/telemetry/dist/diagnostics.d.ts +12 -0
- package/packages/omo-codex/plugin/components/telemetry/dist/diagnostics.js +108 -0
- package/packages/omo-codex/plugin/components/telemetry/dist/env-flags.d.ts +4 -0
- package/packages/omo-codex/plugin/components/telemetry/dist/env-flags.js +31 -0
- package/packages/omo-codex/plugin/components/telemetry/dist/posthog-activity-state.d.ts +8 -0
- package/packages/omo-codex/plugin/components/telemetry/dist/posthog-activity-state.js +68 -0
- package/packages/omo-codex/plugin/components/telemetry/dist/posthog.d.ts +21 -0
- package/packages/omo-codex/plugin/components/telemetry/dist/posthog.js +133 -0
- package/packages/omo-codex/plugin/components/telemetry/dist/product-identity.d.ts +8 -0
- package/packages/omo-codex/plugin/components/telemetry/dist/product-identity.js +29 -0
- package/packages/omo-codex/plugin/components/telemetry/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/telemetry/package.json +1 -1
- package/packages/omo-codex/plugin/components/ultrawork/agents/explorer.toml +5 -13
- package/packages/omo-codex/plugin/components/ultrawork/agents/librarian.toml +61 -185
- package/packages/omo-codex/plugin/components/ultrawork/agents/plan.toml +1 -1
- package/packages/omo-codex/plugin/components/ultrawork/directive.md +122 -117
- package/packages/omo-codex/plugin/components/ultrawork/dist/cli.d.ts +2 -0
- package/packages/omo-codex/plugin/components/ultrawork/dist/cli.js +48 -0
- package/packages/omo-codex/plugin/components/ultrawork/dist/codex-hook.d.ts +7 -0
- package/packages/omo-codex/plugin/components/ultrawork/dist/codex-hook.js +122 -0
- package/packages/omo-codex/plugin/components/ultrawork/dist/directive.d.ts +1 -0
- package/packages/omo-codex/plugin/components/ultrawork/dist/directive.js +2 -0
- package/packages/omo-codex/plugin/components/ultrawork/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/ultrawork/package.json +1 -1
- package/packages/omo-codex/plugin/components/ultrawork/skills/ulw-plan/SKILL.md +20 -11
- package/packages/omo-codex/plugin/components/ultrawork/skills/ulw-plan/references/full-workflow.md +17 -11
- package/packages/omo-codex/plugin/components/ultrawork/test/codex-hook.test.ts +2 -5
- package/packages/omo-codex/plugin/components/ultrawork/test/package-smoke.test.ts +0 -71
- package/packages/omo-codex/plugin/components/ulw-loop/dist/checkpoint.d.ts +16 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/checkpoint.js +200 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/cli-arg-parser.d.ts +17 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/cli-arg-parser.js +97 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/cli-commands.d.ts +4 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/cli-commands.js +183 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/cli-output.d.ts +6 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/cli-output.js +55 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/cli-steering.d.ts +12 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/cli-steering.js +145 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/cli.d.ts +2 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/cli.js +39 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/codex-goal-instruction.d.ts +13 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/codex-goal-instruction.js +100 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/codex-goal-snapshot.d.ts +26 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/codex-goal-snapshot.js +97 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/codex-hook.d.ts +28 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/codex-hook.js +145 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/command-types.d.ts +34 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/command-types.js +1 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/constants.d.ts +16 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/constants.js +41 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/domain-types.d.ts +95 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/domain-types.js +1 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/evidence.d.ts +31 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/evidence.js +119 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/goal-status.d.ts +12 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/goal-status.js +69 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/paths.d.ts +16 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/paths.js +59 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/plan-crud.d.ts +48 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/plan-crud.js +119 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/plan-io.d.ts +8 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/plan-io.js +89 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/quality-gate.d.ts +6 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/quality-gate.js +123 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/review-blockers.d.ts +16 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/review-blockers.js +70 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/runtime.d.ts +10 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/runtime.js +13 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/steering-types.d.ts +63 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/steering-types.js +1 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/steering.d.ts +6 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/steering.js +292 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/types.d.ts +5 -0
- package/packages/omo-codex/plugin/components/ulw-loop/dist/types.js +5 -0
- package/packages/omo-codex/plugin/components/ulw-loop/hooks/hooks.json +2 -2
- package/packages/omo-codex/plugin/components/ulw-loop/package.json +1 -1
- package/packages/omo-codex/plugin/components/ulw-loop/skills/ulw-loop/SKILL.md +14 -14
- package/packages/omo-codex/plugin/components/ulw-loop/skills/ulw-loop/references/full-workflow.md +24 -25
- package/packages/omo-codex/plugin/components/ulw-loop/src/cli-commands.ts +17 -3
- package/packages/omo-codex/plugin/components/ulw-loop/src/cli.ts +2 -1
- package/packages/omo-codex/plugin/components/ulw-loop/src/codex-goal-instruction.ts +1 -1
- package/packages/omo-codex/plugin/components/ulw-loop/test/cli-entrypoint.test.ts +95 -0
- package/packages/omo-codex/plugin/components/ulw-loop/test/package-smoke.test.ts +0 -96
- package/packages/omo-codex/plugin/components/ulw-loop/test/quality-gate.test.ts +23 -0
- package/packages/omo-codex/plugin/components/ulw-loop/test/skill-contract.test.ts +46 -0
- package/packages/omo-codex/plugin/hooks/hooks.json +16 -16
- package/packages/omo-codex/plugin/package-lock.json +10 -9
- package/packages/omo-codex/plugin/package.json +27 -26
- package/packages/omo-codex/plugin/scripts/auto-update.mjs +64 -15
- package/packages/omo-codex/plugin/scripts/build-bundled-mcp-runtimes.mjs +16 -0
- package/packages/omo-codex/plugin/scripts/migrate-codex-config/multi-agent-v2-guard.mjs +82 -18
- package/packages/omo-codex/plugin/scripts/migrate-codex-config.mjs +2 -2
- package/packages/omo-codex/plugin/scripts/sync-skills.mjs +23 -11
- package/packages/omo-codex/plugin/scripts/sync-version.mjs +94 -0
- package/packages/omo-codex/plugin/skills/init-deep/SKILL.md +9 -9
- package/packages/omo-codex/plugin/skills/lcx-contribute-bug-fix/SKILL.md +16 -1
- package/packages/omo-codex/plugin/skills/lcx-doctor/SKILL.md +93 -0
- package/packages/omo-codex/plugin/skills/lcx-doctor/agents/openai.yaml +11 -0
- package/packages/omo-codex/plugin/skills/lcx-report-bug/SKILL.md +17 -13
- package/packages/omo-codex/plugin/skills/lsp-setup/SKILL.md +139 -0
- package/packages/omo-codex/plugin/skills/lsp-setup/references/bash/README.md +60 -0
- package/packages/omo-codex/plugin/skills/lsp-setup/references/c-cpp/README.md +61 -0
- package/packages/omo-codex/plugin/skills/lsp-setup/references/csharp/README.md +71 -0
- package/packages/omo-codex/plugin/skills/lsp-setup/references/dart/README.md +48 -0
- package/packages/omo-codex/plugin/skills/lsp-setup/references/elixir/README.md +51 -0
- package/packages/omo-codex/plugin/skills/lsp-setup/references/go/README.md +57 -0
- package/packages/omo-codex/plugin/skills/lsp-setup/references/haskell/README.md +57 -0
- package/packages/omo-codex/plugin/skills/lsp-setup/references/java/README.md +57 -0
- package/packages/omo-codex/plugin/skills/lsp-setup/references/julia/README.md +60 -0
- package/packages/omo-codex/plugin/skills/lsp-setup/references/kotlin/README.md +59 -0
- package/packages/omo-codex/plugin/skills/lsp-setup/references/lua/README.md +66 -0
- package/packages/omo-codex/plugin/skills/lsp-setup/references/php/README.md +62 -0
- package/packages/omo-codex/plugin/skills/lsp-setup/references/python/README.md +71 -0
- package/packages/omo-codex/plugin/skills/lsp-setup/references/ruby/README.md +53 -0
- package/packages/omo-codex/plugin/skills/lsp-setup/references/rust/README.md +59 -0
- package/packages/omo-codex/plugin/skills/lsp-setup/references/swift/README.md +51 -0
- package/packages/omo-codex/plugin/skills/lsp-setup/references/terraform/README.md +62 -0
- package/packages/omo-codex/plugin/skills/lsp-setup/references/typescript/README.md +77 -0
- package/packages/omo-codex/plugin/skills/lsp-setup/references/yaml/README.md +70 -0
- package/packages/omo-codex/plugin/skills/lsp-setup/references/zig/README.md +49 -0
- package/packages/omo-codex/plugin/skills/lsp-setup/scripts/detect-lsp.ts +210 -0
- package/packages/omo-codex/plugin/skills/lsp-setup/scripts/lsp-server-table.ts +177 -0
- package/packages/omo-codex/plugin/skills/lsp-setup/scripts/tsconfig.json +17 -0
- package/packages/omo-codex/plugin/skills/lsp-setup/scripts/verify-lsp.ts +147 -0
- package/packages/omo-codex/plugin/skills/refactor/SKILL.md +9 -9
- package/packages/omo-codex/plugin/skills/remove-ai-slops/SKILL.md +10 -10
- package/packages/omo-codex/plugin/skills/review-work/SKILL.md +20 -22
- package/packages/omo-codex/plugin/skills/start-work/SKILL.md +38 -61
- package/packages/omo-codex/plugin/skills/ultraresearch/SKILL.md +135 -677
- package/packages/omo-codex/plugin/skills/ulw-loop/SKILL.md +14 -14
- package/packages/omo-codex/plugin/skills/ulw-loop/references/full-workflow.md +24 -25
- package/packages/omo-codex/plugin/skills/ulw-plan/SKILL.md +20 -11
- package/packages/omo-codex/plugin/skills/ulw-plan/references/full-workflow.md +17 -11
- package/packages/omo-codex/plugin/skills/visual-qa/SKILL.md +9 -9
- package/packages/omo-codex/plugin/test/aggregate-build.test.mjs +2 -1
- package/packages/omo-codex/plugin/test/aggregate-mcp.test.mjs +1 -1
- package/packages/omo-codex/plugin/test/aggregate-plugin-fixture.mjs +5 -5
- package/packages/omo-codex/plugin/test/aggregate-skills.test.mjs +6 -6
- package/packages/omo-codex/plugin/test/auto-update-restart-notice.test.mjs +194 -0
- package/packages/omo-codex/plugin/test/auto-update.test.mjs +17 -0
- package/packages/omo-codex/plugin/test/lcx-bug-skills.test.mjs +15 -44
- package/packages/omo-codex/plugin/test/lsp-prebuild-layouts.test.mjs +140 -0
- package/packages/omo-codex/plugin/test/migrate-codex-config.test.mjs +189 -7
- package/packages/omo-codex/plugin/test/start-work-skill.test.mjs +9 -31
- package/packages/omo-codex/plugin/test/sync-skills-orchestration.test.mjs +68 -4
- package/packages/omo-codex/plugin/test/sync-skills-test-support.mjs +119 -0
- package/packages/omo-codex/plugin/test/sync-skills.test.mjs +11 -112
- package/packages/omo-codex/plugin/test/sync-version.test.mjs +68 -0
- package/packages/omo-codex/plugin/test/ultraresearch-skill-contract.test.mjs +126 -0
- package/packages/omo-codex/plugin/test/ulw-plan-skill.test.mjs +2 -2
- package/packages/omo-codex/scripts/install/bin-dir.mjs +20 -0
- package/packages/omo-codex/scripts/install/bin-links.mjs +43 -6
- package/packages/omo-codex/scripts/install/cache.mjs +4 -0
- package/packages/omo-codex/scripts/install/config.mjs +4 -4
- package/packages/omo-codex/scripts/install/delegated-command.mjs +5 -1
- package/packages/omo-codex/scripts/install/git-bash-mcp-env.mjs +28 -0
- package/packages/omo-codex/scripts/install/git-bash.mjs +12 -4
- package/packages/omo-codex/scripts/install/git-bash.test.mjs +39 -4
- package/packages/omo-codex/scripts/install/hook-targets.mjs +46 -0
- package/packages/omo-codex/scripts/install/multi-agent-v2-config.mjs +12 -2
- package/packages/omo-codex/scripts/install/process.mjs +1 -0
- package/packages/omo-codex/scripts/install-bin-links.test.mjs +131 -3
- package/packages/omo-codex/scripts/install-config-git-bash.test.mjs +91 -0
- package/packages/omo-codex/scripts/install-config.test.mjs +50 -44
- package/packages/omo-codex/scripts/install-delegated-command.test.mjs +78 -0
- package/packages/omo-codex/scripts/install-git-bash-mcp-env.test.mjs +93 -0
- package/packages/omo-codex/scripts/install-hook-targets.test.mjs +100 -0
- package/packages/omo-codex/scripts/install-lazycodex-version-stamp.test.mjs +3 -1
- package/packages/omo-codex/scripts/install-local.mjs +7 -18
- package/packages/omo-codex/scripts/install-local.test.mjs +34 -1
- package/packages/shared-skills/skills/lcx-contribute-bug-fix/SKILL.md +16 -1
- package/packages/shared-skills/skills/lcx-doctor/SKILL.md +93 -0
- package/packages/shared-skills/skills/lcx-doctor/agents/openai.yaml +11 -0
- package/packages/shared-skills/skills/lcx-report-bug/SKILL.md +17 -13
- package/packages/shared-skills/skills/lsp-setup/SKILL.md +139 -0
- package/packages/shared-skills/skills/lsp-setup/references/bash/README.md +60 -0
- package/packages/shared-skills/skills/lsp-setup/references/c-cpp/README.md +61 -0
- package/packages/shared-skills/skills/lsp-setup/references/csharp/README.md +71 -0
- package/packages/shared-skills/skills/lsp-setup/references/dart/README.md +48 -0
- package/packages/shared-skills/skills/lsp-setup/references/elixir/README.md +51 -0
- package/packages/shared-skills/skills/lsp-setup/references/go/README.md +57 -0
- package/packages/shared-skills/skills/lsp-setup/references/haskell/README.md +57 -0
- package/packages/shared-skills/skills/lsp-setup/references/java/README.md +57 -0
- package/packages/shared-skills/skills/lsp-setup/references/julia/README.md +60 -0
- package/packages/shared-skills/skills/lsp-setup/references/kotlin/README.md +59 -0
- package/packages/shared-skills/skills/lsp-setup/references/lua/README.md +66 -0
- package/packages/shared-skills/skills/lsp-setup/references/php/README.md +62 -0
- package/packages/shared-skills/skills/lsp-setup/references/python/README.md +71 -0
- package/packages/shared-skills/skills/lsp-setup/references/ruby/README.md +53 -0
- package/packages/shared-skills/skills/lsp-setup/references/rust/README.md +59 -0
- package/packages/shared-skills/skills/lsp-setup/references/swift/README.md +51 -0
- package/packages/shared-skills/skills/lsp-setup/references/terraform/README.md +62 -0
- package/packages/shared-skills/skills/lsp-setup/references/typescript/README.md +77 -0
- package/packages/shared-skills/skills/lsp-setup/references/yaml/README.md +70 -0
- package/packages/shared-skills/skills/lsp-setup/references/zig/README.md +49 -0
- package/packages/shared-skills/skills/lsp-setup/scripts/detect-lsp.ts +210 -0
- package/packages/shared-skills/skills/lsp-setup/scripts/lsp-server-table.ts +177 -0
- package/packages/shared-skills/skills/lsp-setup/scripts/tsconfig.json +17 -0
- package/packages/shared-skills/skills/lsp-setup/scripts/verify-lsp.ts +147 -0
- package/packages/shared-skills/skills/remove-ai-slops/SKILL.md +1 -1
- package/packages/shared-skills/skills/review-work/SKILL.md +10 -14
- package/packages/shared-skills/skills/start-work/SKILL.md +30 -59
- package/packages/shared-skills/skills/ultraresearch/SKILL.md +126 -667
- package/dist/hooks/anthropic-effort/hook.d.ts +0 -26
- package/dist/hooks/anthropic-effort/index.d.ts +0 -1
- package/dist/hooks/keyword-detector/analyze/default.d.ts +0 -12
- package/dist/hooks/keyword-detector/analyze/index.d.ts +0 -1
- package/dist/hooks/keyword-detector/search/default.d.ts +0 -12
- package/dist/hooks/keyword-detector/search/index.d.ts +0 -1
- package/dist/hooks/thinking-block-validator/hook.d.ts +0 -12
- package/dist/hooks/thinking-block-validator/index.d.ts +0 -1
- package/packages/omo-codex/plugin/components/ultrawork/test/directive-contract.test.ts +0 -18
- package/packages/omo-codex/plugin/test/global-review-debug-gate.test.mjs +0 -29
- package/packages/omo-codex/plugin/test/subagent-guidance.test.mjs +0 -151
|
@@ -0,0 +1,3711 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli.ts
|
|
4
|
+
import { argv, stderr } from "node:process";
|
|
5
|
+
|
|
6
|
+
// src/proxy.ts
|
|
7
|
+
import { createInterface } from "node:readline";
|
|
8
|
+
|
|
9
|
+
// ../lsp-tools-mcp/dist/tools.js
|
|
10
|
+
import { resolve as resolve5 } from "node:path";
|
|
11
|
+
|
|
12
|
+
// ../lsp-tools-mcp/dist/lsp/client-wrapper.js
|
|
13
|
+
import { existsSync as existsSync5, statSync as statSync2 } from "node:fs";
|
|
14
|
+
import { dirname as dirname2, join as join5, resolve as resolve2 } from "node:path";
|
|
15
|
+
|
|
16
|
+
// ../lsp-tools-mcp/dist/request-context.js
|
|
17
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
18
|
+
var storage = new AsyncLocalStorage;
|
|
19
|
+
function runWithRequestContext(context, fn) {
|
|
20
|
+
return storage.run(context, fn);
|
|
21
|
+
}
|
|
22
|
+
function contextCwd() {
|
|
23
|
+
return storage.getStore()?.cwd ?? process.cwd();
|
|
24
|
+
}
|
|
25
|
+
function contextEnv(key) {
|
|
26
|
+
const store = storage.getStore();
|
|
27
|
+
if (store?.env)
|
|
28
|
+
return store.env[key];
|
|
29
|
+
return process.env[key];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// ../lsp-tools-mcp/dist/lsp/effective-extension.js
|
|
33
|
+
import { basename, extname } from "node:path";
|
|
34
|
+
var BASENAME_EXTENSIONS = {
|
|
35
|
+
Dockerfile: ".dockerfile",
|
|
36
|
+
Containerfile: ".dockerfile"
|
|
37
|
+
};
|
|
38
|
+
function effectiveExtension(filePath) {
|
|
39
|
+
return BASENAME_EXTENSIONS[basename(filePath)] ?? extname(filePath);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// ../lsp-tools-mcp/dist/lsp/errors.js
|
|
43
|
+
class LspConnectionClosedError extends Error {
|
|
44
|
+
constructor(serverId, root, message) {
|
|
45
|
+
super(message ?? `LSP connection closed for ${serverId} at ${root}`);
|
|
46
|
+
this.serverId = serverId;
|
|
47
|
+
this.root = root;
|
|
48
|
+
this.name = "LspConnectionClosedError";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
class LspProcessExitedError extends Error {
|
|
53
|
+
constructor(serverId, root, exitCode, stderrTail) {
|
|
54
|
+
const stderrSuffix = stderrTail ? `
|
|
55
|
+
stderr tail: ${stderrTail}` : "";
|
|
56
|
+
super(`LSP server ${serverId} at ${root} exited with code ${exitCode ?? "null"}${stderrSuffix}`);
|
|
57
|
+
this.serverId = serverId;
|
|
58
|
+
this.root = root;
|
|
59
|
+
this.exitCode = exitCode;
|
|
60
|
+
this.stderrTail = stderrTail;
|
|
61
|
+
this.name = "LspProcessExitedError";
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
class LspRequestTimeoutError extends Error {
|
|
66
|
+
constructor(method, stderrTail) {
|
|
67
|
+
const stderrSuffix = stderrTail ? `
|
|
68
|
+
recent stderr: ${stderrTail}` : "";
|
|
69
|
+
super(`LSP request timeout (method: ${method})${stderrSuffix}`);
|
|
70
|
+
this.method = method;
|
|
71
|
+
this.stderrTail = stderrTail;
|
|
72
|
+
this.name = "LspRequestTimeoutError";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
class LspInvalidPathError extends Error {
|
|
77
|
+
constructor() {
|
|
78
|
+
super(...arguments);
|
|
79
|
+
this.name = "LspInvalidPathError";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
class LspServerLookupError extends Error {
|
|
84
|
+
constructor() {
|
|
85
|
+
super(...arguments);
|
|
86
|
+
this.name = "LspServerLookupError";
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
class LspServerInitializingError extends Error {
|
|
91
|
+
constructor(originalError) {
|
|
92
|
+
super(`LSP server is still initializing. Please retry in a few seconds. Original error: ${originalError.message}`);
|
|
93
|
+
this.originalError = originalError;
|
|
94
|
+
this.name = "LspServerInitializingError";
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
class LspProcessSpawnError extends Error {
|
|
99
|
+
constructor() {
|
|
100
|
+
super(...arguments);
|
|
101
|
+
this.name = "LspProcessSpawnError";
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function isLspDeadConnectionError(err) {
|
|
105
|
+
return err instanceof LspConnectionClosedError || err instanceof LspProcessExitedError;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// ../lsp-tools-mcp/dist/lsp/cleanup-errors.js
|
|
109
|
+
function reportBestEffortCleanupError(operation, error) {
|
|
110
|
+
if (process.env["CODEX_LSP_DEBUG_CLEANUP"] !== "1")
|
|
111
|
+
return;
|
|
112
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
113
|
+
console.error(`[codex-lsp] ignored ${operation} failure during cleanup: ${message}`);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ../lsp-tools-mcp/dist/lsp/client.js
|
|
117
|
+
import { readFileSync } from "node:fs";
|
|
118
|
+
import { resolve } from "node:path";
|
|
119
|
+
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
120
|
+
|
|
121
|
+
// ../lsp-tools-mcp/dist/lsp/connection.js
|
|
122
|
+
import { pathToFileURL } from "node:url";
|
|
123
|
+
|
|
124
|
+
// ../lsp-tools-mcp/dist/lsp/constants.js
|
|
125
|
+
var DEFAULT_MAX_REFERENCES = 200;
|
|
126
|
+
var DEFAULT_MAX_SYMBOLS = 200;
|
|
127
|
+
var DEFAULT_MAX_DIAGNOSTICS = 200;
|
|
128
|
+
var DEFAULT_MAX_DIRECTORY_FILES = 50;
|
|
129
|
+
var REQUEST_TIMEOUT_MS = 15000;
|
|
130
|
+
var INIT_TIMEOUT_MS = 60000;
|
|
131
|
+
var IDLE_TIMEOUT_MS = 5 * 60000;
|
|
132
|
+
var REAPER_INTERVAL_MS = 60000;
|
|
133
|
+
var STOP_HARD_KILL_TIMEOUT_MS = 5000;
|
|
134
|
+
var STOP_SIGKILL_GRACE_MS = 1000;
|
|
135
|
+
|
|
136
|
+
// ../lsp-tools-mcp/dist/lsp/json-rpc-connection.js
|
|
137
|
+
var HEADER_SEPARATOR = `\r
|
|
138
|
+
\r
|
|
139
|
+
`;
|
|
140
|
+
var PARSE_ERROR = -32700;
|
|
141
|
+
var INVALID_REQUEST = -32600;
|
|
142
|
+
var METHOD_NOT_FOUND = -32601;
|
|
143
|
+
var INTERNAL_ERROR = -32603;
|
|
144
|
+
|
|
145
|
+
class JsonRpcConnection {
|
|
146
|
+
constructor(reader, writer) {
|
|
147
|
+
this.reader = reader;
|
|
148
|
+
this.writer = writer;
|
|
149
|
+
this.pendingRequests = new Map;
|
|
150
|
+
this.notificationHandlers = new Map;
|
|
151
|
+
this.requestHandlers = new Map;
|
|
152
|
+
this.closeHandlers = [];
|
|
153
|
+
this.errorHandlers = [];
|
|
154
|
+
this.inputBuffer = Buffer.alloc(0);
|
|
155
|
+
this.nextRequestId = 1;
|
|
156
|
+
this.listening = false;
|
|
157
|
+
this.disposed = false;
|
|
158
|
+
this.handleData = (chunk) => {
|
|
159
|
+
const chunkBuffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, "utf8");
|
|
160
|
+
this.inputBuffer = Buffer.concat([this.inputBuffer, chunkBuffer]);
|
|
161
|
+
this.drainInputBuffer();
|
|
162
|
+
};
|
|
163
|
+
this.handleClose = () => {
|
|
164
|
+
for (const handler of this.closeHandlers) {
|
|
165
|
+
handler();
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
this.handleStreamError = (error) => {
|
|
169
|
+
this.emitError(error);
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
listen() {
|
|
173
|
+
if (this.listening)
|
|
174
|
+
return;
|
|
175
|
+
this.listening = true;
|
|
176
|
+
this.reader.on("data", this.handleData);
|
|
177
|
+
this.reader.on("close", this.handleClose);
|
|
178
|
+
this.reader.on("end", this.handleClose);
|
|
179
|
+
this.reader.on("error", this.handleStreamError);
|
|
180
|
+
this.writer.on("error", this.handleStreamError);
|
|
181
|
+
}
|
|
182
|
+
onNotification(method, handler) {
|
|
183
|
+
this.notificationHandlers.set(method, handler);
|
|
184
|
+
}
|
|
185
|
+
onRequest(method, handler) {
|
|
186
|
+
this.requestHandlers.set(method, handler);
|
|
187
|
+
}
|
|
188
|
+
onClose(handler) {
|
|
189
|
+
this.closeHandlers.push(handler);
|
|
190
|
+
}
|
|
191
|
+
onError(handler) {
|
|
192
|
+
this.errorHandlers.push(handler);
|
|
193
|
+
}
|
|
194
|
+
async sendRequest(method, params) {
|
|
195
|
+
if (this.disposed)
|
|
196
|
+
throw new Error("JSON-RPC connection is disposed");
|
|
197
|
+
const id = this.nextRequestId;
|
|
198
|
+
this.nextRequestId += 1;
|
|
199
|
+
const message = params === undefined ? { jsonrpc: "2.0", id, method } : { jsonrpc: "2.0", id, method, params };
|
|
200
|
+
const responsePromise = new Promise((resolve, reject) => {
|
|
201
|
+
this.pendingRequests.set(String(id), {
|
|
202
|
+
resolve(result) {
|
|
203
|
+
resolve(result);
|
|
204
|
+
},
|
|
205
|
+
reject
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
try {
|
|
209
|
+
await this.writeMessage(message);
|
|
210
|
+
} catch (error) {
|
|
211
|
+
this.pendingRequests.delete(String(id));
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
return responsePromise;
|
|
215
|
+
}
|
|
216
|
+
async sendNotification(method, params) {
|
|
217
|
+
if (this.disposed)
|
|
218
|
+
return;
|
|
219
|
+
const message = params === undefined ? { jsonrpc: "2.0", method } : { jsonrpc: "2.0", method, params };
|
|
220
|
+
await this.writeMessage(message);
|
|
221
|
+
}
|
|
222
|
+
dispose() {
|
|
223
|
+
if (this.disposed)
|
|
224
|
+
return;
|
|
225
|
+
this.disposed = true;
|
|
226
|
+
this.reader.off("data", this.handleData);
|
|
227
|
+
this.reader.off("close", this.handleClose);
|
|
228
|
+
this.reader.off("end", this.handleClose);
|
|
229
|
+
this.reader.off("error", this.handleStreamError);
|
|
230
|
+
this.writer.off("error", this.handleStreamError);
|
|
231
|
+
for (const pending of this.pendingRequests.values()) {
|
|
232
|
+
pending.reject(new Error("JSON-RPC connection disposed"));
|
|
233
|
+
}
|
|
234
|
+
this.pendingRequests.clear();
|
|
235
|
+
this.notificationHandlers.clear();
|
|
236
|
+
this.requestHandlers.clear();
|
|
237
|
+
}
|
|
238
|
+
drainInputBuffer() {
|
|
239
|
+
while (true) {
|
|
240
|
+
const headerEnd = this.inputBuffer.indexOf(HEADER_SEPARATOR);
|
|
241
|
+
if (headerEnd === -1)
|
|
242
|
+
return;
|
|
243
|
+
const headers = this.inputBuffer.subarray(0, headerEnd).toString("ascii");
|
|
244
|
+
const contentLength = parseContentLength(headers);
|
|
245
|
+
if (contentLength === null) {
|
|
246
|
+
this.inputBuffer = Buffer.alloc(0);
|
|
247
|
+
this.emitError(new Error("JSON-RPC message is missing Content-Length header"));
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const bodyStart = headerEnd + Buffer.byteLength(HEADER_SEPARATOR);
|
|
251
|
+
const bodyEnd = bodyStart + contentLength;
|
|
252
|
+
if (this.inputBuffer.length < bodyEnd)
|
|
253
|
+
return;
|
|
254
|
+
const body = this.inputBuffer.subarray(bodyStart, bodyEnd).toString("utf8");
|
|
255
|
+
this.inputBuffer = this.inputBuffer.subarray(bodyEnd);
|
|
256
|
+
this.dispatchBody(body);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
dispatchBody(body) {
|
|
260
|
+
let parsed;
|
|
261
|
+
try {
|
|
262
|
+
parsed = JSON.parse(body);
|
|
263
|
+
} catch (error) {
|
|
264
|
+
this.writeError(null, PARSE_ERROR, error instanceof Error ? error.message : "Parse error").catch((writeError) => this.emitError(toError(writeError)));
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (!isJsonRpcObject(parsed)) {
|
|
268
|
+
this.writeError(null, INVALID_REQUEST, "Invalid JSON-RPC message").catch((error) => this.emitError(toError(error)));
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
if ("id" in parsed && (("result" in parsed) || ("error" in parsed))) {
|
|
272
|
+
this.handleResponse(parsed);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
if (typeof parsed["method"] !== "string") {
|
|
276
|
+
const id = getMessageId(parsed) ?? null;
|
|
277
|
+
this.writeError(id, INVALID_REQUEST, "Invalid JSON-RPC method").catch((error) => this.emitError(toError(error)));
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if ("id" in parsed) {
|
|
281
|
+
this.handleRequest(parsed);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
this.handleNotification(parsed["method"], parsed["params"]);
|
|
285
|
+
}
|
|
286
|
+
handleResponse(message) {
|
|
287
|
+
const id = getMessageId(message);
|
|
288
|
+
if (id === undefined)
|
|
289
|
+
return;
|
|
290
|
+
const pending = this.pendingRequests.get(String(id));
|
|
291
|
+
if (!pending)
|
|
292
|
+
return;
|
|
293
|
+
this.pendingRequests.delete(String(id));
|
|
294
|
+
if ("error" in message) {
|
|
295
|
+
pending.reject(jsonRpcErrorToError(message["error"]));
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
pending.resolve(message["result"]);
|
|
299
|
+
}
|
|
300
|
+
handleNotification(method, params) {
|
|
301
|
+
const handler = this.notificationHandlers.get(method);
|
|
302
|
+
if (!handler)
|
|
303
|
+
return;
|
|
304
|
+
try {
|
|
305
|
+
handler(params);
|
|
306
|
+
} catch (error) {
|
|
307
|
+
this.emitError(toError(error));
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
handleRequest(message) {
|
|
311
|
+
const id = getMessageId(message);
|
|
312
|
+
if (id === undefined) {
|
|
313
|
+
this.writeError(null, INVALID_REQUEST, "Invalid JSON-RPC id").catch((error) => this.emitError(toError(error)));
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const method = typeof message["method"] === "string" ? message["method"] : "";
|
|
317
|
+
const handler = this.requestHandlers.get(method);
|
|
318
|
+
if (!handler) {
|
|
319
|
+
this.writeError(id, METHOD_NOT_FOUND, `Method not found: ${method}`).catch((error) => this.emitError(toError(error)));
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
Promise.resolve().then(() => handler(message["params"])).then((result) => this.writeMessage({ jsonrpc: "2.0", id, result }), (error) => this.writeError(id, INTERNAL_ERROR, toError(error).message)).catch((error) => this.emitError(toError(error)));
|
|
323
|
+
}
|
|
324
|
+
async writeError(id, code, message) {
|
|
325
|
+
await this.writeMessage({ jsonrpc: "2.0", id, error: { code, message } });
|
|
326
|
+
}
|
|
327
|
+
writeMessage(message) {
|
|
328
|
+
const body = JSON.stringify(message);
|
|
329
|
+
const payload = `Content-Length: ${Buffer.byteLength(body, "utf8")}\r
|
|
330
|
+
\r
|
|
331
|
+
${body}`;
|
|
332
|
+
return new Promise((resolve, reject) => {
|
|
333
|
+
this.writer.write(payload, (error) => {
|
|
334
|
+
if (error) {
|
|
335
|
+
reject(error);
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
resolve();
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
emitError(error) {
|
|
343
|
+
for (const handler of this.errorHandlers) {
|
|
344
|
+
handler(error);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
function parseContentLength(headers) {
|
|
349
|
+
for (const line of headers.split(`\r
|
|
350
|
+
`)) {
|
|
351
|
+
const separatorIndex = line.indexOf(":");
|
|
352
|
+
if (separatorIndex === -1)
|
|
353
|
+
continue;
|
|
354
|
+
const name = line.slice(0, separatorIndex).trim().toLowerCase();
|
|
355
|
+
if (name !== "content-length")
|
|
356
|
+
continue;
|
|
357
|
+
const value = Number.parseInt(line.slice(separatorIndex + 1).trim(), 10);
|
|
358
|
+
return Number.isFinite(value) && value >= 0 ? value : null;
|
|
359
|
+
}
|
|
360
|
+
return null;
|
|
361
|
+
}
|
|
362
|
+
function isJsonRpcObject(value) {
|
|
363
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
364
|
+
}
|
|
365
|
+
function getMessageId(message) {
|
|
366
|
+
const id = message["id"];
|
|
367
|
+
if (typeof id === "number" || typeof id === "string" || id === null)
|
|
368
|
+
return id;
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
function jsonRpcErrorToError(value) {
|
|
372
|
+
if (!isJsonRpcObject(value))
|
|
373
|
+
return new Error("JSON-RPC request failed");
|
|
374
|
+
const message = typeof value["message"] === "string" ? value["message"] : "JSON-RPC request failed";
|
|
375
|
+
const error = new Error(message);
|
|
376
|
+
if (typeof value["code"] === "number") {
|
|
377
|
+
error.name = `JsonRpcError(${value["code"]})`;
|
|
378
|
+
}
|
|
379
|
+
return error;
|
|
380
|
+
}
|
|
381
|
+
function toError(error) {
|
|
382
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// ../lsp-tools-mcp/dist/lsp/process.js
|
|
386
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
387
|
+
import { existsSync, statSync } from "node:fs";
|
|
388
|
+
import { delimiter, join } from "node:path";
|
|
389
|
+
function isMissingProcessError(error) {
|
|
390
|
+
if (!(error instanceof Error) || !("code" in error))
|
|
391
|
+
return false;
|
|
392
|
+
return error.code === "ESRCH";
|
|
393
|
+
}
|
|
394
|
+
function reportKillError(context, error) {
|
|
395
|
+
if (!isMissingProcessError(error)) {
|
|
396
|
+
reportBestEffortCleanupError(context, error);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
function validateCwd(cwd) {
|
|
400
|
+
try {
|
|
401
|
+
if (!existsSync(cwd)) {
|
|
402
|
+
return { valid: false, error: `Working directory does not exist: ${cwd}` };
|
|
403
|
+
}
|
|
404
|
+
const stats = statSync(cwd);
|
|
405
|
+
if (!stats.isDirectory()) {
|
|
406
|
+
return { valid: false, error: `Path is not a directory: ${cwd}` };
|
|
407
|
+
}
|
|
408
|
+
return { valid: true };
|
|
409
|
+
} catch (err) {
|
|
410
|
+
return {
|
|
411
|
+
valid: false,
|
|
412
|
+
error: `Cannot access working directory: ${cwd} (${err instanceof Error ? err.message : String(err)})`
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
function wrap(proc) {
|
|
417
|
+
const exitedPromise = new Promise((resolve) => {
|
|
418
|
+
proc.once("close", (code) => resolve(code ?? 0));
|
|
419
|
+
proc.once("error", () => resolve(1));
|
|
420
|
+
});
|
|
421
|
+
if (!proc.stdin || !proc.stdout || !proc.stderr) {
|
|
422
|
+
throw new LspProcessSpawnError("Spawned process is missing one of stdin/stdout/stderr pipes");
|
|
423
|
+
}
|
|
424
|
+
return {
|
|
425
|
+
stdin: proc.stdin,
|
|
426
|
+
stdout: proc.stdout,
|
|
427
|
+
stderr: proc.stderr,
|
|
428
|
+
get pid() {
|
|
429
|
+
return proc.pid ?? undefined;
|
|
430
|
+
},
|
|
431
|
+
get exitCode() {
|
|
432
|
+
return proc.exitCode;
|
|
433
|
+
},
|
|
434
|
+
get killed() {
|
|
435
|
+
return proc.killed;
|
|
436
|
+
},
|
|
437
|
+
exited: exitedPromise,
|
|
438
|
+
kill(signal) {
|
|
439
|
+
killProcessTree(proc, signal ?? "SIGTERM");
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
function killProcessTree(proc, signal) {
|
|
444
|
+
if (process.platform === "win32" && proc.pid) {
|
|
445
|
+
const result = spawnSync("taskkill", ["/pid", String(proc.pid), "/f", "/t"], { stdio: "ignore" });
|
|
446
|
+
if (!result.error && result.status === 0)
|
|
447
|
+
return;
|
|
448
|
+
if (result.error)
|
|
449
|
+
reportKillError("windows process tree kill", result.error);
|
|
450
|
+
}
|
|
451
|
+
if (process.platform !== "win32" && proc.pid) {
|
|
452
|
+
try {
|
|
453
|
+
process.kill(-proc.pid, signal);
|
|
454
|
+
return;
|
|
455
|
+
} catch (error) {
|
|
456
|
+
reportKillError("process group kill", error);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
try {
|
|
460
|
+
proc.kill(signal);
|
|
461
|
+
} catch (error) {
|
|
462
|
+
reportKillError("process kill", error);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
function isWindowsShellShim(command) {
|
|
466
|
+
const lowerCommand = command.toLowerCase();
|
|
467
|
+
return lowerCommand.endsWith(".cmd") || lowerCommand.endsWith(".bat");
|
|
468
|
+
}
|
|
469
|
+
function splitPath(pathValue, platform) {
|
|
470
|
+
const separator = platform === "win32" ? ";" : delimiter;
|
|
471
|
+
return pathValue.split(separator).filter(Boolean);
|
|
472
|
+
}
|
|
473
|
+
function getWindowsPathExtensions(env) {
|
|
474
|
+
const rawExtensions = env["PATHEXT"] ?? ".COM;.EXE;.BAT;.CMD";
|
|
475
|
+
const extensions = rawExtensions.split(";").map((extension) => extension.trim()).filter(Boolean).map((extension) => extension.startsWith(".") ? extension : `.${extension}`);
|
|
476
|
+
return [...new Set([...extensions, ".exe", ".cmd", ".bat", ""])];
|
|
477
|
+
}
|
|
478
|
+
function resolveWindowsCommand(command, env) {
|
|
479
|
+
const hasPathSeparator = command.includes("/") || command.includes("\\");
|
|
480
|
+
const pathValue = env["PATH"] ?? env["Path"] ?? "";
|
|
481
|
+
const baseDirectories = hasPathSeparator ? [""] : splitPath(pathValue, "win32");
|
|
482
|
+
const extensions = getWindowsPathExtensions(env);
|
|
483
|
+
for (const baseDirectory of baseDirectories) {
|
|
484
|
+
for (const extension of extensions) {
|
|
485
|
+
const candidate = baseDirectory ? join(baseDirectory, `${command}${extension}`) : `${command}${extension}`;
|
|
486
|
+
if (existsSync(candidate))
|
|
487
|
+
return candidate;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
return command;
|
|
491
|
+
}
|
|
492
|
+
function createSpawnCommand(command, platform = process.platform, commandProcessor = process.env["ComSpec"] ?? "cmd.exe", env = process.env) {
|
|
493
|
+
const [cmd, ...args] = command;
|
|
494
|
+
if (!cmd) {
|
|
495
|
+
throw new LspProcessSpawnError("[lsp] empty command");
|
|
496
|
+
}
|
|
497
|
+
if (platform !== "win32") {
|
|
498
|
+
return { command: cmd, args, shell: false };
|
|
499
|
+
}
|
|
500
|
+
const resolvedCommand = resolveWindowsCommand(cmd, env);
|
|
501
|
+
if (!isWindowsShellShim(resolvedCommand)) {
|
|
502
|
+
return { command: resolvedCommand, args, shell: false };
|
|
503
|
+
}
|
|
504
|
+
return {
|
|
505
|
+
command: commandProcessor,
|
|
506
|
+
args: ["/d", "/s", "/c", resolvedCommand, ...args],
|
|
507
|
+
shell: false
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
function spawnProcess(command, options) {
|
|
511
|
+
const cwdValidation = validateCwd(options.cwd);
|
|
512
|
+
if (!cwdValidation.valid) {
|
|
513
|
+
throw new LspInvalidPathError(`[lsp] ${cwdValidation.error}`);
|
|
514
|
+
}
|
|
515
|
+
const [cmd] = command;
|
|
516
|
+
if (!cmd) {
|
|
517
|
+
throw new LspProcessSpawnError("[lsp] empty command");
|
|
518
|
+
}
|
|
519
|
+
const preparedCommand = createSpawnCommand(command, process.platform, process.env["ComSpec"] ?? "cmd.exe", options.env);
|
|
520
|
+
const proc = spawn(preparedCommand.command, preparedCommand.args, {
|
|
521
|
+
cwd: options.cwd,
|
|
522
|
+
env: options.env,
|
|
523
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
524
|
+
windowsHide: true,
|
|
525
|
+
shell: preparedCommand.shell,
|
|
526
|
+
detached: process.platform !== "win32"
|
|
527
|
+
});
|
|
528
|
+
return wrap(proc);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// ../lsp-tools-mcp/dist/lsp/transport.js
|
|
532
|
+
function isRecord(value) {
|
|
533
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
534
|
+
}
|
|
535
|
+
function parseConfigurationItems(params) {
|
|
536
|
+
if (!isRecord(params) || !Array.isArray(params["items"]))
|
|
537
|
+
return [];
|
|
538
|
+
const items = [];
|
|
539
|
+
for (const item of params["items"]) {
|
|
540
|
+
if (!isRecord(item))
|
|
541
|
+
continue;
|
|
542
|
+
const section = item["section"];
|
|
543
|
+
items.push(section === undefined || typeof section !== "string" ? {} : { section });
|
|
544
|
+
}
|
|
545
|
+
return items;
|
|
546
|
+
}
|
|
547
|
+
function parseDiagnosticsParams(params) {
|
|
548
|
+
if (!isRecord(params) || typeof params["uri"] !== "string")
|
|
549
|
+
return null;
|
|
550
|
+
const diagnostics = Array.isArray(params["diagnostics"]) ? params["diagnostics"].filter(isDiagnostic) : [];
|
|
551
|
+
return { uri: params["uri"], diagnostics };
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
class LspClientTransport {
|
|
555
|
+
constructor(root, server) {
|
|
556
|
+
this.root = root;
|
|
557
|
+
this.server = server;
|
|
558
|
+
this.proc = null;
|
|
559
|
+
this.connection = null;
|
|
560
|
+
this.stderrBuffer = [];
|
|
561
|
+
this.processExited = false;
|
|
562
|
+
this.diagnosticsStore = new Map;
|
|
563
|
+
}
|
|
564
|
+
pid() {
|
|
565
|
+
return this.proc?.pid;
|
|
566
|
+
}
|
|
567
|
+
command() {
|
|
568
|
+
return [...this.server.command];
|
|
569
|
+
}
|
|
570
|
+
async start() {
|
|
571
|
+
const env = createLspSpawnEnv(this.root, {
|
|
572
|
+
...process.env,
|
|
573
|
+
...this.server.env
|
|
574
|
+
});
|
|
575
|
+
this.proc = spawnProcess(this.server.command, {
|
|
576
|
+
cwd: this.root,
|
|
577
|
+
env
|
|
578
|
+
});
|
|
579
|
+
this.startStderrReading();
|
|
580
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
581
|
+
if (this.proc.exitCode !== null) {
|
|
582
|
+
const stderr = this.stderrBuffer.join(`
|
|
583
|
+
`);
|
|
584
|
+
throw new LspProcessExitedError(this.server.id, this.root, this.proc.exitCode, stderr.slice(-2000));
|
|
585
|
+
}
|
|
586
|
+
this.connection = new JsonRpcConnection(this.proc.stdout, this.proc.stdin);
|
|
587
|
+
this.connection.onNotification("textDocument/publishDiagnostics", (params) => {
|
|
588
|
+
const diagnosticsParams = parseDiagnosticsParams(params);
|
|
589
|
+
if (diagnosticsParams?.uri) {
|
|
590
|
+
this.diagnosticsStore.set(diagnosticsParams.uri, diagnosticsParams.diagnostics);
|
|
591
|
+
}
|
|
592
|
+
});
|
|
593
|
+
this.connection.onRequest("workspace/configuration", (params) => {
|
|
594
|
+
const items = parseConfigurationItems(params);
|
|
595
|
+
return items.map((item) => {
|
|
596
|
+
if (item.section === "json")
|
|
597
|
+
return { validate: { enable: true } };
|
|
598
|
+
return {};
|
|
599
|
+
});
|
|
600
|
+
});
|
|
601
|
+
this.connection.onRequest("client/registerCapability", () => null);
|
|
602
|
+
this.connection.onRequest("window/workDoneProgress/create", () => null);
|
|
603
|
+
this.connection.onClose(() => {
|
|
604
|
+
this.processExited = true;
|
|
605
|
+
});
|
|
606
|
+
this.connection.onError((error) => {
|
|
607
|
+
reportBestEffortCleanupError("connection error notification", error);
|
|
608
|
+
});
|
|
609
|
+
this.connection.listen();
|
|
610
|
+
}
|
|
611
|
+
startStderrReading() {
|
|
612
|
+
if (!this.proc)
|
|
613
|
+
return;
|
|
614
|
+
this.proc.stderr.setEncoding("utf-8");
|
|
615
|
+
this.proc.stderr.on("data", (chunk) => {
|
|
616
|
+
this.stderrBuffer.push(chunk);
|
|
617
|
+
if (this.stderrBuffer.length > 100) {
|
|
618
|
+
this.stderrBuffer.shift();
|
|
619
|
+
}
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
isConnectionClosedError(error) {
|
|
623
|
+
if (!(error instanceof Error)) {
|
|
624
|
+
return false;
|
|
625
|
+
}
|
|
626
|
+
const code = "code" in error && typeof error.code === "string" ? error.code : undefined;
|
|
627
|
+
return code === "ERR_STREAM_DESTROYED" || /connection closed|connection is disposed|stream was destroyed/i.test(error.message);
|
|
628
|
+
}
|
|
629
|
+
async sendRequest(method, ...args) {
|
|
630
|
+
if (!this.connection)
|
|
631
|
+
throw new Error("LSP client not started");
|
|
632
|
+
if (this.processExited || this.proc && this.proc.exitCode !== null) {
|
|
633
|
+
const stderrTail = this.stderrBuffer.slice(-10).join(`
|
|
634
|
+
`);
|
|
635
|
+
throw new LspProcessExitedError(this.server.id, this.root, this.proc?.exitCode ?? null, stderrTail || undefined);
|
|
636
|
+
}
|
|
637
|
+
let timeoutHandle = null;
|
|
638
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
639
|
+
timeoutHandle = setTimeout(() => {
|
|
640
|
+
const stderrTail = this.stderrBuffer.slice(-5).join(`
|
|
641
|
+
`);
|
|
642
|
+
reject(new LspRequestTimeoutError(method, stderrTail || undefined));
|
|
643
|
+
}, REQUEST_TIMEOUT_MS);
|
|
644
|
+
});
|
|
645
|
+
try {
|
|
646
|
+
const requestPromise = args.length === 0 ? this.connection.sendRequest(method) : this.connection.sendRequest(method, args[0]);
|
|
647
|
+
const result = await Promise.race([requestPromise, timeoutPromise]);
|
|
648
|
+
if (timeoutHandle !== null)
|
|
649
|
+
clearTimeout(timeoutHandle);
|
|
650
|
+
return result;
|
|
651
|
+
} catch (error) {
|
|
652
|
+
if (timeoutHandle !== null)
|
|
653
|
+
clearTimeout(timeoutHandle);
|
|
654
|
+
if (this.processExited || this.proc && this.proc.exitCode !== null) {
|
|
655
|
+
throw new LspProcessExitedError(this.server.id, this.root, this.proc?.exitCode ?? null, this.stderrBuffer.slice(-10).join(`
|
|
656
|
+
`) || undefined);
|
|
657
|
+
}
|
|
658
|
+
if (this.isConnectionClosedError(error)) {
|
|
659
|
+
throw new LspConnectionClosedError(this.server.id, this.root, error.message);
|
|
660
|
+
}
|
|
661
|
+
throw error;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
async sendNotification(method, ...args) {
|
|
665
|
+
if (!this.connection)
|
|
666
|
+
return;
|
|
667
|
+
if (this.processExited || this.proc && this.proc.exitCode !== null)
|
|
668
|
+
return;
|
|
669
|
+
try {
|
|
670
|
+
if (args.length === 0) {
|
|
671
|
+
await this.connection.sendNotification(method);
|
|
672
|
+
} else {
|
|
673
|
+
await this.connection.sendNotification(method, args[0]);
|
|
674
|
+
}
|
|
675
|
+
} catch (error) {
|
|
676
|
+
if (this.isConnectionClosedError(error)) {
|
|
677
|
+
throw new LspConnectionClosedError(this.server.id, this.root, error.message);
|
|
678
|
+
}
|
|
679
|
+
throw error;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
isAlive() {
|
|
683
|
+
return this.proc !== null && !this.processExited && this.proc.exitCode === null;
|
|
684
|
+
}
|
|
685
|
+
async stop() {
|
|
686
|
+
if (this.connection) {
|
|
687
|
+
try {
|
|
688
|
+
await this.sendRequest("shutdown");
|
|
689
|
+
} catch (error) {
|
|
690
|
+
reportBestEffortCleanupError("shutdown request", error);
|
|
691
|
+
}
|
|
692
|
+
try {
|
|
693
|
+
await this.sendNotification("exit");
|
|
694
|
+
} catch (error) {
|
|
695
|
+
reportBestEffortCleanupError("exit notification", error);
|
|
696
|
+
}
|
|
697
|
+
try {
|
|
698
|
+
this.connection.dispose();
|
|
699
|
+
} catch (error) {
|
|
700
|
+
reportBestEffortCleanupError("connection dispose", error);
|
|
701
|
+
}
|
|
702
|
+
this.connection = null;
|
|
703
|
+
}
|
|
704
|
+
const proc = this.proc;
|
|
705
|
+
if (proc) {
|
|
706
|
+
this.proc = null;
|
|
707
|
+
let exitedBeforeTimeout = false;
|
|
708
|
+
try {
|
|
709
|
+
proc.kill();
|
|
710
|
+
let timeoutId;
|
|
711
|
+
const timeoutPromise = new Promise((resolve) => {
|
|
712
|
+
timeoutId = setTimeout(resolve, STOP_HARD_KILL_TIMEOUT_MS);
|
|
713
|
+
});
|
|
714
|
+
await Promise.race([
|
|
715
|
+
proc.exited.then(() => {
|
|
716
|
+
exitedBeforeTimeout = true;
|
|
717
|
+
}).finally(() => {
|
|
718
|
+
if (timeoutId)
|
|
719
|
+
clearTimeout(timeoutId);
|
|
720
|
+
}),
|
|
721
|
+
timeoutPromise
|
|
722
|
+
]);
|
|
723
|
+
if (!exitedBeforeTimeout) {
|
|
724
|
+
try {
|
|
725
|
+
proc.kill("SIGKILL");
|
|
726
|
+
await Promise.race([
|
|
727
|
+
proc.exited,
|
|
728
|
+
new Promise((resolve) => setTimeout(resolve, STOP_SIGKILL_GRACE_MS))
|
|
729
|
+
]);
|
|
730
|
+
} catch (error) {
|
|
731
|
+
reportBestEffortCleanupError("hard process kill", error);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
} catch (error) {
|
|
735
|
+
reportBestEffortCleanupError("process stop", error);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
this.processExited = true;
|
|
739
|
+
this.diagnosticsStore.clear();
|
|
740
|
+
}
|
|
741
|
+
getStoredDiagnostics(uri) {
|
|
742
|
+
return this.diagnosticsStore.get(uri) ?? [];
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
function createLspSpawnEnv(_root, input) {
|
|
746
|
+
return { ...input };
|
|
747
|
+
}
|
|
748
|
+
function isDiagnostic(value) {
|
|
749
|
+
return isRecord(value) && isRange(value["range"]) && typeof value["message"] === "string";
|
|
750
|
+
}
|
|
751
|
+
function isRange(value) {
|
|
752
|
+
return isRecord(value) && isPosition(value["start"]) && isPosition(value["end"]);
|
|
753
|
+
}
|
|
754
|
+
function isPosition(value) {
|
|
755
|
+
return isRecord(value) && typeof value["line"] === "number" && typeof value["character"] === "number";
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// ../lsp-tools-mcp/dist/lsp/connection.js
|
|
759
|
+
var INITIALIZE_SETTLE_MS = 300;
|
|
760
|
+
|
|
761
|
+
class LspClientConnection extends LspClientTransport {
|
|
762
|
+
async initialize() {
|
|
763
|
+
const rootUri = pathToFileURL(this.root).href;
|
|
764
|
+
await this.sendRequest("initialize", {
|
|
765
|
+
processId: process.pid,
|
|
766
|
+
rootUri,
|
|
767
|
+
rootPath: this.root,
|
|
768
|
+
workspaceFolders: [{ uri: rootUri, name: "workspace" }],
|
|
769
|
+
capabilities: {
|
|
770
|
+
textDocument: {
|
|
771
|
+
hover: { contentFormat: ["markdown", "plaintext"] },
|
|
772
|
+
definition: { linkSupport: true },
|
|
773
|
+
references: {},
|
|
774
|
+
documentSymbol: { hierarchicalDocumentSymbolSupport: true },
|
|
775
|
+
publishDiagnostics: {},
|
|
776
|
+
rename: {
|
|
777
|
+
prepareSupport: true,
|
|
778
|
+
prepareSupportDefaultBehavior: 1,
|
|
779
|
+
honorsChangeAnnotations: true
|
|
780
|
+
},
|
|
781
|
+
codeAction: {
|
|
782
|
+
codeActionLiteralSupport: {
|
|
783
|
+
codeActionKind: {
|
|
784
|
+
valueSet: [
|
|
785
|
+
"quickfix",
|
|
786
|
+
"refactor",
|
|
787
|
+
"refactor.extract",
|
|
788
|
+
"refactor.inline",
|
|
789
|
+
"refactor.rewrite",
|
|
790
|
+
"source",
|
|
791
|
+
"source.organizeImports",
|
|
792
|
+
"source.fixAll"
|
|
793
|
+
]
|
|
794
|
+
}
|
|
795
|
+
},
|
|
796
|
+
isPreferredSupport: true,
|
|
797
|
+
disabledSupport: true,
|
|
798
|
+
dataSupport: true,
|
|
799
|
+
resolveSupport: {
|
|
800
|
+
properties: ["edit", "command"]
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
},
|
|
804
|
+
workspace: {
|
|
805
|
+
symbol: {},
|
|
806
|
+
workspaceFolders: true,
|
|
807
|
+
configuration: true,
|
|
808
|
+
applyEdit: true,
|
|
809
|
+
workspaceEdit: {
|
|
810
|
+
documentChanges: true
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
},
|
|
814
|
+
initializationOptions: this.server.initialization
|
|
815
|
+
});
|
|
816
|
+
await this.sendNotification("initialized");
|
|
817
|
+
await this.sendNotification("workspace/didChangeConfiguration", {
|
|
818
|
+
settings: { json: { validate: { enable: true } } }
|
|
819
|
+
});
|
|
820
|
+
await new Promise((r) => setTimeout(r, INITIALIZE_SETTLE_MS));
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
// ../lsp-tools-mcp/dist/lsp/language-mappings.js
|
|
825
|
+
var SYMBOL_KIND_MAP = {
|
|
826
|
+
1: "File",
|
|
827
|
+
2: "Module",
|
|
828
|
+
3: "Namespace",
|
|
829
|
+
4: "Package",
|
|
830
|
+
5: "Class",
|
|
831
|
+
6: "Method",
|
|
832
|
+
7: "Property",
|
|
833
|
+
8: "Field",
|
|
834
|
+
9: "Constructor",
|
|
835
|
+
10: "Enum",
|
|
836
|
+
11: "Interface",
|
|
837
|
+
12: "Function",
|
|
838
|
+
13: "Variable",
|
|
839
|
+
14: "Constant",
|
|
840
|
+
15: "String",
|
|
841
|
+
16: "Number",
|
|
842
|
+
17: "Boolean",
|
|
843
|
+
18: "Array",
|
|
844
|
+
19: "Object",
|
|
845
|
+
20: "Key",
|
|
846
|
+
21: "Null",
|
|
847
|
+
22: "EnumMember",
|
|
848
|
+
23: "Struct",
|
|
849
|
+
24: "Event",
|
|
850
|
+
25: "Operator",
|
|
851
|
+
26: "TypeParameter"
|
|
852
|
+
};
|
|
853
|
+
var SEVERITY_MAP = {
|
|
854
|
+
1: "error",
|
|
855
|
+
2: "warning",
|
|
856
|
+
3: "information",
|
|
857
|
+
4: "hint"
|
|
858
|
+
};
|
|
859
|
+
var EXT_TO_LANG = {
|
|
860
|
+
".abap": "abap",
|
|
861
|
+
".bat": "bat",
|
|
862
|
+
".bib": "bibtex",
|
|
863
|
+
".bibtex": "bibtex",
|
|
864
|
+
".clj": "clojure",
|
|
865
|
+
".cljs": "clojure",
|
|
866
|
+
".cljc": "clojure",
|
|
867
|
+
".edn": "clojure",
|
|
868
|
+
".coffee": "coffeescript",
|
|
869
|
+
".c": "c",
|
|
870
|
+
".cpp": "cpp",
|
|
871
|
+
".cxx": "cpp",
|
|
872
|
+
".cc": "cpp",
|
|
873
|
+
".c++": "cpp",
|
|
874
|
+
".cs": "csharp",
|
|
875
|
+
".css": "css",
|
|
876
|
+
".d": "d",
|
|
877
|
+
".pas": "pascal",
|
|
878
|
+
".pascal": "pascal",
|
|
879
|
+
".diff": "diff",
|
|
880
|
+
".patch": "diff",
|
|
881
|
+
".dart": "dart",
|
|
882
|
+
".dockerfile": "dockerfile",
|
|
883
|
+
".ex": "elixir",
|
|
884
|
+
".exs": "elixir",
|
|
885
|
+
".erl": "erlang",
|
|
886
|
+
".hrl": "erlang",
|
|
887
|
+
".fs": "fsharp",
|
|
888
|
+
".fsi": "fsharp",
|
|
889
|
+
".fsx": "fsharp",
|
|
890
|
+
".fsscript": "fsharp",
|
|
891
|
+
".gitcommit": "git-commit",
|
|
892
|
+
".gitrebase": "git-rebase",
|
|
893
|
+
".go": "go",
|
|
894
|
+
".groovy": "groovy",
|
|
895
|
+
".gleam": "gleam",
|
|
896
|
+
".hbs": "handlebars",
|
|
897
|
+
".handlebars": "handlebars",
|
|
898
|
+
".hs": "haskell",
|
|
899
|
+
".html": "html",
|
|
900
|
+
".htm": "html",
|
|
901
|
+
".ini": "ini",
|
|
902
|
+
".java": "java",
|
|
903
|
+
".jl": "julia",
|
|
904
|
+
".js": "javascript",
|
|
905
|
+
".jsx": "javascriptreact",
|
|
906
|
+
".json": "json",
|
|
907
|
+
".jsonc": "jsonc",
|
|
908
|
+
".tex": "latex",
|
|
909
|
+
".latex": "latex",
|
|
910
|
+
".less": "less",
|
|
911
|
+
".lua": "lua",
|
|
912
|
+
".makefile": "makefile",
|
|
913
|
+
makefile: "makefile",
|
|
914
|
+
".md": "markdown",
|
|
915
|
+
".markdown": "markdown",
|
|
916
|
+
".m": "objective-c",
|
|
917
|
+
".mm": "objective-cpp",
|
|
918
|
+
".pl": "perl",
|
|
919
|
+
".pm": "perl",
|
|
920
|
+
".pm6": "perl6",
|
|
921
|
+
".php": "php",
|
|
922
|
+
".ps1": "powershell",
|
|
923
|
+
".psm1": "powershell",
|
|
924
|
+
".pug": "jade",
|
|
925
|
+
".jade": "jade",
|
|
926
|
+
".py": "python",
|
|
927
|
+
".pyi": "python",
|
|
928
|
+
".r": "r",
|
|
929
|
+
".cshtml": "razor",
|
|
930
|
+
".razor": "razor",
|
|
931
|
+
".rb": "ruby",
|
|
932
|
+
".rake": "ruby",
|
|
933
|
+
".gemspec": "ruby",
|
|
934
|
+
".ru": "ruby",
|
|
935
|
+
".erb": "erb",
|
|
936
|
+
".html.erb": "erb",
|
|
937
|
+
".js.erb": "erb",
|
|
938
|
+
".css.erb": "erb",
|
|
939
|
+
".json.erb": "erb",
|
|
940
|
+
".rs": "rust",
|
|
941
|
+
".scss": "scss",
|
|
942
|
+
".sass": "sass",
|
|
943
|
+
".scala": "scala",
|
|
944
|
+
".shader": "shaderlab",
|
|
945
|
+
".sh": "shellscript",
|
|
946
|
+
".bash": "shellscript",
|
|
947
|
+
".zsh": "shellscript",
|
|
948
|
+
".ksh": "shellscript",
|
|
949
|
+
".sql": "sql",
|
|
950
|
+
".svelte": "svelte",
|
|
951
|
+
".swift": "swift",
|
|
952
|
+
".ts": "typescript",
|
|
953
|
+
".tsx": "typescriptreact",
|
|
954
|
+
".mts": "typescript",
|
|
955
|
+
".cts": "typescript",
|
|
956
|
+
".mtsx": "typescriptreact",
|
|
957
|
+
".ctsx": "typescriptreact",
|
|
958
|
+
".xml": "xml",
|
|
959
|
+
".xsl": "xsl",
|
|
960
|
+
".yaml": "yaml",
|
|
961
|
+
".yml": "yaml",
|
|
962
|
+
".mjs": "javascript",
|
|
963
|
+
".cjs": "javascript",
|
|
964
|
+
".vue": "vue",
|
|
965
|
+
".zig": "zig",
|
|
966
|
+
".zon": "zig",
|
|
967
|
+
".astro": "astro",
|
|
968
|
+
".ml": "ocaml",
|
|
969
|
+
".mli": "ocaml",
|
|
970
|
+
".tf": "terraform",
|
|
971
|
+
".tfvars": "terraform-vars",
|
|
972
|
+
".hcl": "hcl",
|
|
973
|
+
".nix": "nix",
|
|
974
|
+
".typ": "typst",
|
|
975
|
+
".typc": "typst",
|
|
976
|
+
".ets": "typescript",
|
|
977
|
+
".lhs": "haskell",
|
|
978
|
+
".kt": "kotlin",
|
|
979
|
+
".kts": "kotlin",
|
|
980
|
+
".prisma": "prisma",
|
|
981
|
+
".h": "c",
|
|
982
|
+
".hpp": "cpp",
|
|
983
|
+
".hh": "cpp",
|
|
984
|
+
".hxx": "cpp",
|
|
985
|
+
".h++": "cpp",
|
|
986
|
+
".objc": "objective-c",
|
|
987
|
+
".objcpp": "objective-cpp",
|
|
988
|
+
".fish": "fish",
|
|
989
|
+
".graphql": "graphql",
|
|
990
|
+
".gql": "graphql"
|
|
991
|
+
};
|
|
992
|
+
function getLanguageId(ext) {
|
|
993
|
+
return EXT_TO_LANG[ext] ?? "plaintext";
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
// ../lsp-tools-mcp/dist/lsp/client.js
|
|
997
|
+
var POST_OPEN_DELAY_MS = 1000;
|
|
998
|
+
var POST_DIAGNOSTICS_WAIT_MS = 500;
|
|
999
|
+
|
|
1000
|
+
class LspClient extends LspClientConnection {
|
|
1001
|
+
constructor() {
|
|
1002
|
+
super(...arguments);
|
|
1003
|
+
this.openedFiles = new Set;
|
|
1004
|
+
this.documentVersions = new Map;
|
|
1005
|
+
this.lastSyncedText = new Map;
|
|
1006
|
+
this.diagnosticPullErrors = [];
|
|
1007
|
+
}
|
|
1008
|
+
getDiagnosticPullErrors() {
|
|
1009
|
+
return this.diagnosticPullErrors;
|
|
1010
|
+
}
|
|
1011
|
+
async openFile(filePath) {
|
|
1012
|
+
const absPath = resolve(contextCwd(), filePath);
|
|
1013
|
+
const uri = pathToFileURL2(absPath).href;
|
|
1014
|
+
const text = readFileSync(absPath, "utf-8");
|
|
1015
|
+
if (!this.openedFiles.has(absPath)) {
|
|
1016
|
+
const ext = effectiveExtension(absPath);
|
|
1017
|
+
const languageId = getLanguageId(ext);
|
|
1018
|
+
const version = 1;
|
|
1019
|
+
await this.sendNotification("textDocument/didOpen", {
|
|
1020
|
+
textDocument: {
|
|
1021
|
+
uri,
|
|
1022
|
+
languageId,
|
|
1023
|
+
version,
|
|
1024
|
+
text
|
|
1025
|
+
}
|
|
1026
|
+
});
|
|
1027
|
+
this.openedFiles.add(absPath);
|
|
1028
|
+
this.documentVersions.set(uri, version);
|
|
1029
|
+
this.lastSyncedText.set(uri, text);
|
|
1030
|
+
await new Promise((r) => setTimeout(r, POST_OPEN_DELAY_MS));
|
|
1031
|
+
return;
|
|
1032
|
+
}
|
|
1033
|
+
const prevText = this.lastSyncedText.get(uri);
|
|
1034
|
+
if (prevText === text) {
|
|
1035
|
+
return;
|
|
1036
|
+
}
|
|
1037
|
+
const nextVersion = (this.documentVersions.get(uri) ?? 1) + 1;
|
|
1038
|
+
this.documentVersions.set(uri, nextVersion);
|
|
1039
|
+
this.lastSyncedText.set(uri, text);
|
|
1040
|
+
await this.sendNotification("textDocument/didChange", {
|
|
1041
|
+
textDocument: { uri, version: nextVersion },
|
|
1042
|
+
contentChanges: [{ text }]
|
|
1043
|
+
});
|
|
1044
|
+
await this.sendNotification("textDocument/didSave", {
|
|
1045
|
+
textDocument: { uri },
|
|
1046
|
+
text
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
async definition(filePath, line, character) {
|
|
1050
|
+
const absPath = resolve(contextCwd(), filePath);
|
|
1051
|
+
await this.openFile(absPath);
|
|
1052
|
+
return this.sendRequest("textDocument/definition", {
|
|
1053
|
+
textDocument: { uri: pathToFileURL2(absPath).href },
|
|
1054
|
+
position: { line: line - 1, character }
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
async references(filePath, line, character, includeDeclaration = true) {
|
|
1058
|
+
const absPath = resolve(contextCwd(), filePath);
|
|
1059
|
+
await this.openFile(absPath);
|
|
1060
|
+
return this.sendRequest("textDocument/references", {
|
|
1061
|
+
textDocument: { uri: pathToFileURL2(absPath).href },
|
|
1062
|
+
position: { line: line - 1, character },
|
|
1063
|
+
context: { includeDeclaration }
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
async documentSymbols(filePath) {
|
|
1067
|
+
const absPath = resolve(contextCwd(), filePath);
|
|
1068
|
+
await this.openFile(absPath);
|
|
1069
|
+
return this.sendRequest("textDocument/documentSymbol", {
|
|
1070
|
+
textDocument: { uri: pathToFileURL2(absPath).href }
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
async workspaceSymbols(query) {
|
|
1074
|
+
return this.sendRequest("workspace/symbol", { query });
|
|
1075
|
+
}
|
|
1076
|
+
isUnsupportedDiagnosticPullError(error) {
|
|
1077
|
+
if (!(error instanceof Error))
|
|
1078
|
+
return false;
|
|
1079
|
+
const code = "code" in error && typeof error.code === "number" ? error.code : undefined;
|
|
1080
|
+
if (code === -32601)
|
|
1081
|
+
return true;
|
|
1082
|
+
return /unsupported|not supported|method not found|unknown request/i.test(error.message);
|
|
1083
|
+
}
|
|
1084
|
+
async diagnostics(filePath) {
|
|
1085
|
+
const absPath = resolve(contextCwd(), filePath);
|
|
1086
|
+
const uri = pathToFileURL2(absPath).href;
|
|
1087
|
+
await this.openFile(absPath);
|
|
1088
|
+
await new Promise((r) => setTimeout(r, POST_DIAGNOSTICS_WAIT_MS));
|
|
1089
|
+
try {
|
|
1090
|
+
const result = await this.sendRequest("textDocument/diagnostic", {
|
|
1091
|
+
textDocument: { uri }
|
|
1092
|
+
});
|
|
1093
|
+
if (result.items) {
|
|
1094
|
+
return { items: result.items };
|
|
1095
|
+
}
|
|
1096
|
+
} catch (error) {
|
|
1097
|
+
if (!this.isUnsupportedDiagnosticPullError(error)) {
|
|
1098
|
+
this.diagnosticPullErrors.push(error instanceof Error ? error : new Error(String(error)));
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
return { items: this.getStoredDiagnostics(uri) };
|
|
1102
|
+
}
|
|
1103
|
+
async prepareRename(filePath, line, character) {
|
|
1104
|
+
const absPath = resolve(contextCwd(), filePath);
|
|
1105
|
+
await this.openFile(absPath);
|
|
1106
|
+
return this.sendRequest("textDocument/prepareRename", {
|
|
1107
|
+
textDocument: { uri: pathToFileURL2(absPath).href },
|
|
1108
|
+
position: { line: line - 1, character }
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
async rename(filePath, line, character, newName) {
|
|
1112
|
+
const absPath = resolve(contextCwd(), filePath);
|
|
1113
|
+
await this.openFile(absPath);
|
|
1114
|
+
return this.sendRequest("textDocument/rename", {
|
|
1115
|
+
textDocument: { uri: pathToFileURL2(absPath).href },
|
|
1116
|
+
position: { line: line - 1, character },
|
|
1117
|
+
newName
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
// ../lsp-tools-mcp/dist/lsp/process-signal-cleanup.js
|
|
1123
|
+
function installProcessSignalCleanup(cleanup) {
|
|
1124
|
+
const signals = process.platform === "win32" ? ["SIGINT", "SIGTERM", "SIGBREAK"] : ["SIGINT", "SIGTERM"];
|
|
1125
|
+
const handler = () => {
|
|
1126
|
+
cleanup().catch((error) => {
|
|
1127
|
+
reportBestEffortCleanupError("signal cleanup", error);
|
|
1128
|
+
});
|
|
1129
|
+
};
|
|
1130
|
+
for (const signal of signals) {
|
|
1131
|
+
process.on(signal, handler);
|
|
1132
|
+
}
|
|
1133
|
+
return () => {
|
|
1134
|
+
for (const signal of signals) {
|
|
1135
|
+
process.removeListener(signal, handler);
|
|
1136
|
+
}
|
|
1137
|
+
};
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
// ../lsp-tools-mcp/dist/lsp/manager.js
|
|
1141
|
+
async function stopClientBestEffort(client) {
|
|
1142
|
+
try {
|
|
1143
|
+
await client.stop();
|
|
1144
|
+
} catch (error) {
|
|
1145
|
+
reportBestEffortCleanupError("client stop", error);
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
function awaitWithSignal(promise, signal) {
|
|
1149
|
+
if (!signal)
|
|
1150
|
+
return promise;
|
|
1151
|
+
return new Promise((resolve2, reject) => {
|
|
1152
|
+
let settled = false;
|
|
1153
|
+
const onAbort = () => {
|
|
1154
|
+
if (settled)
|
|
1155
|
+
return;
|
|
1156
|
+
settled = true;
|
|
1157
|
+
reject(new DOMException("Aborted", "AbortError"));
|
|
1158
|
+
};
|
|
1159
|
+
if (signal.aborted) {
|
|
1160
|
+
onAbort();
|
|
1161
|
+
return;
|
|
1162
|
+
}
|
|
1163
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
1164
|
+
promise.then((value) => {
|
|
1165
|
+
if (settled)
|
|
1166
|
+
return;
|
|
1167
|
+
settled = true;
|
|
1168
|
+
signal.removeEventListener("abort", onAbort);
|
|
1169
|
+
resolve2(value);
|
|
1170
|
+
}, (err) => {
|
|
1171
|
+
if (settled)
|
|
1172
|
+
return;
|
|
1173
|
+
settled = true;
|
|
1174
|
+
signal.removeEventListener("abort", onAbort);
|
|
1175
|
+
reject(err);
|
|
1176
|
+
});
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
class LspManager {
|
|
1181
|
+
constructor(options = {}) {
|
|
1182
|
+
this.clients = new Map;
|
|
1183
|
+
this.reaperHandle = null;
|
|
1184
|
+
this.signalDisposer = null;
|
|
1185
|
+
this.disposed = false;
|
|
1186
|
+
this.idleTimeoutMs = options.idleTimeoutMs ?? IDLE_TIMEOUT_MS;
|
|
1187
|
+
this.initTimeoutMs = options.initTimeoutMs ?? INIT_TIMEOUT_MS;
|
|
1188
|
+
this.reaperIntervalMs = options.reaperIntervalMs ?? REAPER_INTERVAL_MS;
|
|
1189
|
+
this.clientFactory = options.clientFactory ?? ((root, server) => new LspClient(root, server));
|
|
1190
|
+
this.now = options.now ?? (() => Date.now());
|
|
1191
|
+
this.startReaper();
|
|
1192
|
+
this.signalDisposer = installProcessSignalCleanup(() => this.stopAll());
|
|
1193
|
+
}
|
|
1194
|
+
startReaper() {
|
|
1195
|
+
if (this.reaperHandle)
|
|
1196
|
+
return;
|
|
1197
|
+
this.reaperHandle = setInterval(() => {
|
|
1198
|
+
this.reapStale();
|
|
1199
|
+
}, this.reaperIntervalMs);
|
|
1200
|
+
if (typeof this.reaperHandle.unref === "function") {
|
|
1201
|
+
this.reaperHandle.unref();
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
getKey(root, serverId) {
|
|
1205
|
+
return `${root}::${serverId}`;
|
|
1206
|
+
}
|
|
1207
|
+
reapStale() {
|
|
1208
|
+
const t = this.now();
|
|
1209
|
+
for (const [key, managed] of this.clients) {
|
|
1210
|
+
if (managed.isInitializing && managed.initializingSince !== null && t - managed.initializingSince > this.initTimeoutMs) {
|
|
1211
|
+
stopClientBestEffort(managed.client);
|
|
1212
|
+
this.clients.delete(key);
|
|
1213
|
+
continue;
|
|
1214
|
+
}
|
|
1215
|
+
if (!managed.isInitializing && managed.refCount === 0 && managed.pendingWaiters === 0 && t - managed.lastUsedAt > this.idleTimeoutMs) {
|
|
1216
|
+
stopClientBestEffort(managed.client);
|
|
1217
|
+
this.clients.delete(key);
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
async tryDeleteIfOrphaned(key, managed) {
|
|
1222
|
+
if (managed.refCount === 0 && managed.pendingWaiters === 0 && !managed.isInitializing && this.clients.get(key) === managed) {
|
|
1223
|
+
this.clients.delete(key);
|
|
1224
|
+
await stopClientBestEffort(managed.client);
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
async getClient(root, server, signal) {
|
|
1228
|
+
if (this.disposed) {
|
|
1229
|
+
throw new Error("LspManager has been disposed");
|
|
1230
|
+
}
|
|
1231
|
+
signal?.throwIfAborted();
|
|
1232
|
+
const key = this.getKey(root, server.id);
|
|
1233
|
+
let managed = this.clients.get(key);
|
|
1234
|
+
if (managed) {
|
|
1235
|
+
const t = this.now();
|
|
1236
|
+
if (managed.isInitializing && managed.initializingSince !== null && t - managed.initializingSince > this.initTimeoutMs) {
|
|
1237
|
+
await stopClientBestEffort(managed.client);
|
|
1238
|
+
this.clients.delete(key);
|
|
1239
|
+
managed = undefined;
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
if (managed) {
|
|
1243
|
+
if (managed.initPromise) {
|
|
1244
|
+
managed.pendingWaiters++;
|
|
1245
|
+
try {
|
|
1246
|
+
await awaitWithSignal(managed.initPromise, signal);
|
|
1247
|
+
} catch (err) {
|
|
1248
|
+
managed.pendingWaiters--;
|
|
1249
|
+
await this.tryDeleteIfOrphaned(key, managed);
|
|
1250
|
+
throw err;
|
|
1251
|
+
}
|
|
1252
|
+
managed.pendingWaiters--;
|
|
1253
|
+
}
|
|
1254
|
+
if (signal?.aborted) {
|
|
1255
|
+
await this.tryDeleteIfOrphaned(key, managed);
|
|
1256
|
+
signal.throwIfAborted();
|
|
1257
|
+
}
|
|
1258
|
+
if (!managed.client.isAlive()) {
|
|
1259
|
+
await stopClientBestEffort(managed.client);
|
|
1260
|
+
this.clients.delete(key);
|
|
1261
|
+
return this.getClient(root, server, signal);
|
|
1262
|
+
}
|
|
1263
|
+
managed.refCount++;
|
|
1264
|
+
managed.lastUsedAt = this.now();
|
|
1265
|
+
return managed.client;
|
|
1266
|
+
}
|
|
1267
|
+
const client = this.clientFactory(root, server);
|
|
1268
|
+
const initStartedAt = this.now();
|
|
1269
|
+
const initPromise = (async () => {
|
|
1270
|
+
await client.start();
|
|
1271
|
+
await client.initialize();
|
|
1272
|
+
})();
|
|
1273
|
+
const newManaged = {
|
|
1274
|
+
client,
|
|
1275
|
+
refCount: 0,
|
|
1276
|
+
pendingWaiters: 1,
|
|
1277
|
+
lastUsedAt: initStartedAt,
|
|
1278
|
+
initPromise,
|
|
1279
|
+
isInitializing: true,
|
|
1280
|
+
initializingSince: initStartedAt
|
|
1281
|
+
};
|
|
1282
|
+
this.clients.set(key, newManaged);
|
|
1283
|
+
try {
|
|
1284
|
+
await awaitWithSignal(initPromise, signal);
|
|
1285
|
+
} catch (err) {
|
|
1286
|
+
newManaged.pendingWaiters--;
|
|
1287
|
+
if (this.clients.get(key) === newManaged) {
|
|
1288
|
+
this.clients.delete(key);
|
|
1289
|
+
}
|
|
1290
|
+
await stopClientBestEffort(client);
|
|
1291
|
+
throw err;
|
|
1292
|
+
}
|
|
1293
|
+
newManaged.pendingWaiters--;
|
|
1294
|
+
newManaged.isInitializing = false;
|
|
1295
|
+
newManaged.initializingSince = null;
|
|
1296
|
+
newManaged.initPromise = null;
|
|
1297
|
+
if (signal?.aborted) {
|
|
1298
|
+
await this.tryDeleteIfOrphaned(key, newManaged);
|
|
1299
|
+
signal.throwIfAborted();
|
|
1300
|
+
}
|
|
1301
|
+
newManaged.refCount++;
|
|
1302
|
+
newManaged.lastUsedAt = this.now();
|
|
1303
|
+
return client;
|
|
1304
|
+
}
|
|
1305
|
+
releaseClient(root, serverId) {
|
|
1306
|
+
const key = this.getKey(root, serverId);
|
|
1307
|
+
const managed = this.clients.get(key);
|
|
1308
|
+
if (managed && managed.refCount > 0) {
|
|
1309
|
+
managed.refCount--;
|
|
1310
|
+
managed.lastUsedAt = this.now();
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
invalidateClient(root, serverId, client) {
|
|
1314
|
+
const key = this.getKey(root, serverId);
|
|
1315
|
+
const managed = this.clients.get(key);
|
|
1316
|
+
if (!managed)
|
|
1317
|
+
return;
|
|
1318
|
+
if (client && managed.client !== client)
|
|
1319
|
+
return;
|
|
1320
|
+
this.clients.delete(key);
|
|
1321
|
+
stopClientBestEffort(managed.client);
|
|
1322
|
+
}
|
|
1323
|
+
warmupClient(root, server) {
|
|
1324
|
+
if (this.disposed)
|
|
1325
|
+
return;
|
|
1326
|
+
const key = this.getKey(root, server.id);
|
|
1327
|
+
if (this.clients.has(key))
|
|
1328
|
+
return;
|
|
1329
|
+
const client = this.clientFactory(root, server);
|
|
1330
|
+
const initStartedAt = this.now();
|
|
1331
|
+
const initPromise = (async () => {
|
|
1332
|
+
await client.start();
|
|
1333
|
+
await client.initialize();
|
|
1334
|
+
})();
|
|
1335
|
+
const managed = {
|
|
1336
|
+
client,
|
|
1337
|
+
refCount: 0,
|
|
1338
|
+
pendingWaiters: 0,
|
|
1339
|
+
lastUsedAt: initStartedAt,
|
|
1340
|
+
initPromise,
|
|
1341
|
+
isInitializing: true,
|
|
1342
|
+
initializingSince: initStartedAt
|
|
1343
|
+
};
|
|
1344
|
+
this.clients.set(key, managed);
|
|
1345
|
+
initPromise.then(() => {
|
|
1346
|
+
managed.isInitializing = false;
|
|
1347
|
+
managed.initializingSince = null;
|
|
1348
|
+
managed.initPromise = null;
|
|
1349
|
+
managed.lastUsedAt = this.now();
|
|
1350
|
+
}, () => {
|
|
1351
|
+
if (this.clients.get(key) === managed) {
|
|
1352
|
+
this.clients.delete(key);
|
|
1353
|
+
}
|
|
1354
|
+
stopClientBestEffort(client);
|
|
1355
|
+
});
|
|
1356
|
+
}
|
|
1357
|
+
isServerInitializing(root, serverId) {
|
|
1358
|
+
const managed = this.clients.get(this.getKey(root, serverId));
|
|
1359
|
+
return managed?.isInitializing ?? false;
|
|
1360
|
+
}
|
|
1361
|
+
getSnapshot() {
|
|
1362
|
+
const snapshots = [];
|
|
1363
|
+
for (const [key, managed] of this.clients) {
|
|
1364
|
+
const [root, serverId] = key.split("::");
|
|
1365
|
+
snapshots.push({
|
|
1366
|
+
root,
|
|
1367
|
+
serverId,
|
|
1368
|
+
refCount: managed.refCount,
|
|
1369
|
+
pendingWaiters: managed.pendingWaiters,
|
|
1370
|
+
lastUsedAt: managed.lastUsedAt,
|
|
1371
|
+
isInitializing: managed.isInitializing,
|
|
1372
|
+
alive: managed.client.isAlive(),
|
|
1373
|
+
command: managed.client.command()
|
|
1374
|
+
});
|
|
1375
|
+
}
|
|
1376
|
+
return snapshots;
|
|
1377
|
+
}
|
|
1378
|
+
hasClient(root, serverId) {
|
|
1379
|
+
return this.clients.has(this.getKey(root, serverId));
|
|
1380
|
+
}
|
|
1381
|
+
clientCount() {
|
|
1382
|
+
return this.clients.size;
|
|
1383
|
+
}
|
|
1384
|
+
async stopAll() {
|
|
1385
|
+
this.disposed = true;
|
|
1386
|
+
if (this.reaperHandle) {
|
|
1387
|
+
clearInterval(this.reaperHandle);
|
|
1388
|
+
this.reaperHandle = null;
|
|
1389
|
+
}
|
|
1390
|
+
if (this.signalDisposer) {
|
|
1391
|
+
this.signalDisposer();
|
|
1392
|
+
this.signalDisposer = null;
|
|
1393
|
+
}
|
|
1394
|
+
const stopPromises = [];
|
|
1395
|
+
for (const managed of this.clients.values()) {
|
|
1396
|
+
stopPromises.push(stopClientBestEffort(managed.client));
|
|
1397
|
+
}
|
|
1398
|
+
this.clients.clear();
|
|
1399
|
+
await Promise.allSettled(stopPromises);
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
var _defaultInstance = null;
|
|
1403
|
+
function getLspManager() {
|
|
1404
|
+
if (!_defaultInstance) {
|
|
1405
|
+
_defaultInstance = new LspManager;
|
|
1406
|
+
}
|
|
1407
|
+
return _defaultInstance;
|
|
1408
|
+
}
|
|
1409
|
+
async function disposeDefaultLspManager() {
|
|
1410
|
+
if (_defaultInstance) {
|
|
1411
|
+
const m = _defaultInstance;
|
|
1412
|
+
_defaultInstance = null;
|
|
1413
|
+
await m.stopAll();
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
// ../lsp-tools-mcp/dist/lsp/server-install-state.js
|
|
1418
|
+
import { existsSync as existsSync2, mkdirSync, readFileSync as readFileSync2, renameSync, writeFileSync } from "node:fs";
|
|
1419
|
+
import { homedir } from "node:os";
|
|
1420
|
+
import { dirname, isAbsolute, join as join2 } from "node:path";
|
|
1421
|
+
function getInstallDecisionsPath() {
|
|
1422
|
+
const override = contextEnv("LSP_TOOLS_MCP_INSTALL_DECISIONS");
|
|
1423
|
+
if (!override)
|
|
1424
|
+
return join2(homedir(), ".codex", "lsp-install-decisions.json");
|
|
1425
|
+
return isAbsolute(override) ? override : join2(homedir(), override);
|
|
1426
|
+
}
|
|
1427
|
+
function loadInstallDecisions() {
|
|
1428
|
+
const path = getInstallDecisionsPath();
|
|
1429
|
+
if (!existsSync2(path))
|
|
1430
|
+
return {};
|
|
1431
|
+
try {
|
|
1432
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
1433
|
+
return isInstallDecisions(parsed) ? parsed : {};
|
|
1434
|
+
} catch {
|
|
1435
|
+
return {};
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
function loadInstallDecision(serverId) {
|
|
1439
|
+
return loadInstallDecisions()[serverId];
|
|
1440
|
+
}
|
|
1441
|
+
function recordInstallDecision(serverId, decision, decidedAt = new Date().toISOString()) {
|
|
1442
|
+
const decisions = loadInstallDecisions();
|
|
1443
|
+
decisions[serverId] = { decision, decidedAt };
|
|
1444
|
+
writeInstallDecisions(decisions);
|
|
1445
|
+
}
|
|
1446
|
+
function isInstallDecision(value) {
|
|
1447
|
+
return value === "declined" || value === "allowed";
|
|
1448
|
+
}
|
|
1449
|
+
function writeInstallDecisions(decisions) {
|
|
1450
|
+
const path = getInstallDecisionsPath();
|
|
1451
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
1452
|
+
const tmpPath = `${path}.tmp`;
|
|
1453
|
+
writeFileSync(tmpPath, `${JSON.stringify(decisions, null, 2)}
|
|
1454
|
+
`, "utf8");
|
|
1455
|
+
renameSync(tmpPath, path);
|
|
1456
|
+
}
|
|
1457
|
+
function isInstallDecisions(value) {
|
|
1458
|
+
return isRecord2(value) && Object.values(value).every(isInstallDecisionRecord);
|
|
1459
|
+
}
|
|
1460
|
+
function isInstallDecisionRecord(value) {
|
|
1461
|
+
if (!isRecord2(value))
|
|
1462
|
+
return false;
|
|
1463
|
+
return isInstallDecision(value["decision"]) && typeof value["decidedAt"] === "string";
|
|
1464
|
+
}
|
|
1465
|
+
function isRecord2(value) {
|
|
1466
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
// ../lsp-tools-mcp/dist/lsp/config-loader.js
|
|
1470
|
+
import { existsSync as existsSync3, readFileSync as readFileSync3 } from "node:fs";
|
|
1471
|
+
import { homedir as homedir2 } from "node:os";
|
|
1472
|
+
import { delimiter as delimiter2, isAbsolute as isAbsolute2, join as join3 } from "node:path";
|
|
1473
|
+
|
|
1474
|
+
// ../lsp-tools-mcp/dist/lsp/server-definitions.js
|
|
1475
|
+
var LSP_INSTALL_HINTS = {
|
|
1476
|
+
typescript: "npm install -g typescript-language-server typescript",
|
|
1477
|
+
deno: "Install Deno from https://deno.land",
|
|
1478
|
+
vue: "npm install -g @vue/language-server",
|
|
1479
|
+
eslint: "npm install -g vscode-langservers-extracted",
|
|
1480
|
+
oxlint: "npm install -g oxlint",
|
|
1481
|
+
biome: "npm install -g @biomejs/biome",
|
|
1482
|
+
gopls: "go install golang.org/x/tools/gopls@latest",
|
|
1483
|
+
"ruby-lsp": "gem install ruby-lsp",
|
|
1484
|
+
basedpyright: "pip install basedpyright",
|
|
1485
|
+
pyright: "pip install pyright",
|
|
1486
|
+
ty: "pip install ty",
|
|
1487
|
+
ruff: "pip install ruff",
|
|
1488
|
+
"elixir-ls": "See https://github.com/elixir-lsp/elixir-ls",
|
|
1489
|
+
zls: "See https://github.com/zigtools/zls",
|
|
1490
|
+
csharp: "dotnet tool install -g csharp-ls",
|
|
1491
|
+
fsharp: "dotnet tool install -g fsautocomplete",
|
|
1492
|
+
"sourcekit-lsp": "Included with Xcode or Swift toolchain",
|
|
1493
|
+
rust: "Install rust-analyzer and ensure it is in PATH. If using rustup: rustup component add rust-analyzer. " + "If rust-analyzer exits while loading rust-src: rustup component remove rust-src && rustup component add rust-src.",
|
|
1494
|
+
clangd: "See https://clangd.llvm.org/installation",
|
|
1495
|
+
svelte: "npm install -g svelte-language-server",
|
|
1496
|
+
astro: "npm install -g @astrojs/language-server",
|
|
1497
|
+
"bash-ls": "npm install -g bash-language-server",
|
|
1498
|
+
jdtls: "See https://github.com/eclipse-jdtls/eclipse.jdt.ls",
|
|
1499
|
+
"yaml-ls": "npm install -g yaml-language-server",
|
|
1500
|
+
"lua-ls": "See https://github.com/LuaLS/lua-language-server",
|
|
1501
|
+
php: "npm install -g intelephense",
|
|
1502
|
+
dart: "Included with Dart SDK",
|
|
1503
|
+
"terraform-ls": "See https://github.com/hashicorp/terraform-ls",
|
|
1504
|
+
terraform: "See https://github.com/hashicorp/terraform-ls",
|
|
1505
|
+
prisma: "npm install -g prisma",
|
|
1506
|
+
"ocaml-lsp": "opam install ocaml-lsp-server",
|
|
1507
|
+
texlab: "See https://github.com/latex-lsp/texlab",
|
|
1508
|
+
dockerfile: "npm install -g dockerfile-language-server-nodejs",
|
|
1509
|
+
gleam: "See https://gleam.run/getting-started/installing/",
|
|
1510
|
+
"clojure-lsp": "See https://clojure-lsp.io/installation/",
|
|
1511
|
+
nixd: "nix profile install nixpkgs#nixd",
|
|
1512
|
+
tinymist: "See https://github.com/Myriad-Dreamin/tinymist",
|
|
1513
|
+
"haskell-language-server": "ghcup install hls",
|
|
1514
|
+
bash: "npm install -g bash-language-server",
|
|
1515
|
+
"kotlin-ls": "See https://github.com/Kotlin/kotlin-lsp",
|
|
1516
|
+
julials: `julia -e 'using Pkg; Pkg.add("LanguageServer")'`,
|
|
1517
|
+
razor: "Razor runs through the Roslyn language server (cohosting). " + "Install: dotnet tool install -g roslyn-language-server --prerelease (requires v5.8.0+). See https://github.com/dotnet/razor"
|
|
1518
|
+
};
|
|
1519
|
+
var BUILTIN_SERVERS = {
|
|
1520
|
+
typescript: {
|
|
1521
|
+
command: ["typescript-language-server", "--stdio"],
|
|
1522
|
+
extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts"]
|
|
1523
|
+
},
|
|
1524
|
+
deno: { command: ["deno", "lsp"], extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs"] },
|
|
1525
|
+
vue: { command: ["vue-language-server", "--stdio"], extensions: [".vue"] },
|
|
1526
|
+
eslint: {
|
|
1527
|
+
command: ["vscode-eslint-language-server", "--stdio"],
|
|
1528
|
+
extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts", ".vue"]
|
|
1529
|
+
},
|
|
1530
|
+
oxlint: {
|
|
1531
|
+
command: ["oxlint", "--lsp"],
|
|
1532
|
+
extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts", ".vue", ".astro", ".svelte"]
|
|
1533
|
+
},
|
|
1534
|
+
biome: {
|
|
1535
|
+
command: ["biome", "lsp-proxy", "--stdio"],
|
|
1536
|
+
extensions: [
|
|
1537
|
+
".ts",
|
|
1538
|
+
".tsx",
|
|
1539
|
+
".js",
|
|
1540
|
+
".jsx",
|
|
1541
|
+
".mjs",
|
|
1542
|
+
".cjs",
|
|
1543
|
+
".mts",
|
|
1544
|
+
".cts",
|
|
1545
|
+
".json",
|
|
1546
|
+
".jsonc",
|
|
1547
|
+
".vue",
|
|
1548
|
+
".astro",
|
|
1549
|
+
".svelte",
|
|
1550
|
+
".css",
|
|
1551
|
+
".graphql",
|
|
1552
|
+
".gql",
|
|
1553
|
+
".html"
|
|
1554
|
+
]
|
|
1555
|
+
},
|
|
1556
|
+
gopls: { command: ["gopls"], extensions: [".go"] },
|
|
1557
|
+
"ruby-lsp": {
|
|
1558
|
+
command: ["rubocop", "--lsp"],
|
|
1559
|
+
extensions: [".rb", ".rake", ".gemspec", ".ru"]
|
|
1560
|
+
},
|
|
1561
|
+
basedpyright: {
|
|
1562
|
+
command: ["basedpyright-langserver", "--stdio"],
|
|
1563
|
+
extensions: [".py", ".pyi"]
|
|
1564
|
+
},
|
|
1565
|
+
pyright: { command: ["pyright-langserver", "--stdio"], extensions: [".py", ".pyi"] },
|
|
1566
|
+
ty: { command: ["ty", "server"], extensions: [".py", ".pyi"] },
|
|
1567
|
+
ruff: { command: ["ruff", "server"], extensions: [".py", ".pyi"] },
|
|
1568
|
+
"elixir-ls": { command: ["elixir-ls"], extensions: [".ex", ".exs"] },
|
|
1569
|
+
zls: { command: ["zls"], extensions: [".zig", ".zon"] },
|
|
1570
|
+
csharp: { command: ["csharp-ls"], extensions: [".cs"] },
|
|
1571
|
+
fsharp: { command: ["fsautocomplete"], extensions: [".fs", ".fsi", ".fsx", ".fsscript"] },
|
|
1572
|
+
"sourcekit-lsp": { command: ["sourcekit-lsp"], extensions: [".swift", ".objc", ".objcpp"] },
|
|
1573
|
+
rust: { command: ["rust-analyzer"], extensions: [".rs"] },
|
|
1574
|
+
clangd: {
|
|
1575
|
+
command: ["clangd", "--background-index", "--clang-tidy"],
|
|
1576
|
+
extensions: [".c", ".cpp", ".cc", ".cxx", ".c++", ".h", ".hpp", ".hh", ".hxx", ".h++"]
|
|
1577
|
+
},
|
|
1578
|
+
svelte: { command: ["svelteserver", "--stdio"], extensions: [".svelte"] },
|
|
1579
|
+
astro: { command: ["astro-ls", "--stdio"], extensions: [".astro"] },
|
|
1580
|
+
bash: {
|
|
1581
|
+
command: ["bash-language-server", "start"],
|
|
1582
|
+
extensions: [".sh", ".bash", ".zsh", ".ksh"]
|
|
1583
|
+
},
|
|
1584
|
+
"bash-ls": {
|
|
1585
|
+
command: ["bash-language-server", "start"],
|
|
1586
|
+
extensions: [".sh", ".bash", ".zsh", ".ksh"]
|
|
1587
|
+
},
|
|
1588
|
+
jdtls: { command: ["jdtls"], extensions: [".java"] },
|
|
1589
|
+
"yaml-ls": { command: ["yaml-language-server", "--stdio"], extensions: [".yaml", ".yml"] },
|
|
1590
|
+
"lua-ls": { command: ["lua-language-server"], extensions: [".lua"] },
|
|
1591
|
+
php: { command: ["intelephense", "--stdio"], extensions: [".php"] },
|
|
1592
|
+
dart: { command: ["dart", "language-server", "--lsp"], extensions: [".dart"] },
|
|
1593
|
+
terraform: { command: ["terraform-ls", "serve"], extensions: [".tf", ".tfvars"] },
|
|
1594
|
+
"terraform-ls": { command: ["terraform-ls", "serve"], extensions: [".tf", ".tfvars"] },
|
|
1595
|
+
prisma: { command: ["prisma", "language-server"], extensions: [".prisma"] },
|
|
1596
|
+
"ocaml-lsp": { command: ["ocamllsp"], extensions: [".ml", ".mli"] },
|
|
1597
|
+
texlab: { command: ["texlab"], extensions: [".tex", ".bib"] },
|
|
1598
|
+
dockerfile: { command: ["docker-langserver", "--stdio"], extensions: [".dockerfile"] },
|
|
1599
|
+
gleam: { command: ["gleam", "lsp"], extensions: [".gleam"] },
|
|
1600
|
+
"clojure-lsp": {
|
|
1601
|
+
command: ["clojure-lsp", "listen"],
|
|
1602
|
+
extensions: [".clj", ".cljs", ".cljc", ".edn"]
|
|
1603
|
+
},
|
|
1604
|
+
nixd: { command: ["nixd"], extensions: [".nix"] },
|
|
1605
|
+
tinymist: { command: ["tinymist"], extensions: [".typ", ".typc"] },
|
|
1606
|
+
"haskell-language-server": {
|
|
1607
|
+
command: ["haskell-language-server-wrapper", "--lsp"],
|
|
1608
|
+
extensions: [".hs", ".lhs"]
|
|
1609
|
+
},
|
|
1610
|
+
"kotlin-ls": { command: ["kotlin-lsp"], extensions: [".kt", ".kts"] },
|
|
1611
|
+
julials: {
|
|
1612
|
+
command: ["julia", "--startup-file=no", "--history-file=no", "-e", "using LanguageServer; runserver()"],
|
|
1613
|
+
extensions: [".jl"]
|
|
1614
|
+
},
|
|
1615
|
+
razor: {
|
|
1616
|
+
command: ["roslyn-language-server", "--stdio"],
|
|
1617
|
+
extensions: [".razor", ".cshtml"]
|
|
1618
|
+
}
|
|
1619
|
+
};
|
|
1620
|
+
|
|
1621
|
+
// ../lsp-tools-mcp/dist/lsp/config-loader.js
|
|
1622
|
+
function resolveProjectConfigPath(path) {
|
|
1623
|
+
return isAbsolute2(path) ? path : join3(contextCwd(), path);
|
|
1624
|
+
}
|
|
1625
|
+
function getProjectConfigPaths() {
|
|
1626
|
+
const projectOverride = contextEnv("LSP_TOOLS_MCP_PROJECT_CONFIG");
|
|
1627
|
+
if (projectOverride) {
|
|
1628
|
+
return projectOverride.split(delimiter2).filter(Boolean).map(resolveProjectConfigPath);
|
|
1629
|
+
}
|
|
1630
|
+
return [join3(contextCwd(), ".codex", "lsp-client.json")];
|
|
1631
|
+
}
|
|
1632
|
+
function getUserConfigPath() {
|
|
1633
|
+
const userOverride = contextEnv("LSP_TOOLS_MCP_USER_CONFIG");
|
|
1634
|
+
if (!userOverride)
|
|
1635
|
+
return join3(homedir2(), ".codex", "lsp-client.json");
|
|
1636
|
+
return isAbsolute2(userOverride) ? userOverride : join3(homedir2(), userOverride);
|
|
1637
|
+
}
|
|
1638
|
+
function loadJsonFile(path) {
|
|
1639
|
+
if (!existsSync3(path))
|
|
1640
|
+
return null;
|
|
1641
|
+
try {
|
|
1642
|
+
const parsed = JSON.parse(readFileSync3(path, "utf-8"));
|
|
1643
|
+
return isConfigJson(parsed) ? parsed : null;
|
|
1644
|
+
} catch {
|
|
1645
|
+
return null;
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
function loadAllConfigs() {
|
|
1649
|
+
const configs = new Map;
|
|
1650
|
+
const project = loadFirstJsonFile(getProjectConfigPaths());
|
|
1651
|
+
if (project)
|
|
1652
|
+
configs.set("project", project);
|
|
1653
|
+
const user = loadJsonFile(getUserConfigPath());
|
|
1654
|
+
if (user)
|
|
1655
|
+
configs.set("user", user);
|
|
1656
|
+
return configs;
|
|
1657
|
+
}
|
|
1658
|
+
function loadFirstJsonFile(paths) {
|
|
1659
|
+
for (const path of paths) {
|
|
1660
|
+
const config = loadJsonFile(path);
|
|
1661
|
+
if (config)
|
|
1662
|
+
return config;
|
|
1663
|
+
}
|
|
1664
|
+
return null;
|
|
1665
|
+
}
|
|
1666
|
+
function getMergedServers() {
|
|
1667
|
+
const configs = loadAllConfigs();
|
|
1668
|
+
const servers = [];
|
|
1669
|
+
const disabled = new Set;
|
|
1670
|
+
const seen = new Set;
|
|
1671
|
+
const sources = ["project", "user"];
|
|
1672
|
+
for (const source of sources) {
|
|
1673
|
+
const config = configs.get(source);
|
|
1674
|
+
if (!config?.lsp)
|
|
1675
|
+
continue;
|
|
1676
|
+
for (const [id, rawEntry] of Object.entries(config.lsp)) {
|
|
1677
|
+
const entry = parseLspEntry(rawEntry);
|
|
1678
|
+
if (!entry)
|
|
1679
|
+
continue;
|
|
1680
|
+
if (entry.disabled) {
|
|
1681
|
+
disabled.add(id);
|
|
1682
|
+
continue;
|
|
1683
|
+
}
|
|
1684
|
+
if (seen.has(id))
|
|
1685
|
+
continue;
|
|
1686
|
+
const server = createServerFromEntry(id, entry, source);
|
|
1687
|
+
if (!server)
|
|
1688
|
+
continue;
|
|
1689
|
+
servers.push(server);
|
|
1690
|
+
seen.add(id);
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
for (const [id, config] of Object.entries(BUILTIN_SERVERS)) {
|
|
1694
|
+
if (disabled.has(id) || seen.has(id))
|
|
1695
|
+
continue;
|
|
1696
|
+
servers.push({
|
|
1697
|
+
id,
|
|
1698
|
+
command: config.command,
|
|
1699
|
+
extensions: config.extensions,
|
|
1700
|
+
priority: -100,
|
|
1701
|
+
source: "builtin"
|
|
1702
|
+
});
|
|
1703
|
+
}
|
|
1704
|
+
return servers.sort((a, b) => {
|
|
1705
|
+
if (a.source !== b.source) {
|
|
1706
|
+
const order = {
|
|
1707
|
+
project: 0,
|
|
1708
|
+
user: 1,
|
|
1709
|
+
builtin: 2
|
|
1710
|
+
};
|
|
1711
|
+
return order[a.source] - order[b.source];
|
|
1712
|
+
}
|
|
1713
|
+
return b.priority - a.priority;
|
|
1714
|
+
});
|
|
1715
|
+
}
|
|
1716
|
+
function createServerFromEntry(id, entry, source) {
|
|
1717
|
+
const builtin = BUILTIN_SERVERS[id];
|
|
1718
|
+
if (source === "project") {
|
|
1719
|
+
if (!builtin)
|
|
1720
|
+
return null;
|
|
1721
|
+
const server2 = createServer({
|
|
1722
|
+
id,
|
|
1723
|
+
command: builtin.command,
|
|
1724
|
+
extensions: entry.extensions ?? builtin.extensions,
|
|
1725
|
+
priority: entry.priority ?? 0,
|
|
1726
|
+
source
|
|
1727
|
+
});
|
|
1728
|
+
if (entry.initialization !== undefined) {
|
|
1729
|
+
server2.initialization = entry.initialization;
|
|
1730
|
+
}
|
|
1731
|
+
return server2;
|
|
1732
|
+
}
|
|
1733
|
+
if (entry.command && entry.extensions) {
|
|
1734
|
+
const server2 = createServer({
|
|
1735
|
+
id,
|
|
1736
|
+
command: entry.command,
|
|
1737
|
+
extensions: entry.extensions,
|
|
1738
|
+
priority: entry.priority ?? 0,
|
|
1739
|
+
source
|
|
1740
|
+
});
|
|
1741
|
+
applyOptionalServerFields(server2, entry);
|
|
1742
|
+
return server2;
|
|
1743
|
+
}
|
|
1744
|
+
if (!builtin)
|
|
1745
|
+
return null;
|
|
1746
|
+
const server = createServer({
|
|
1747
|
+
id,
|
|
1748
|
+
command: entry.command ?? builtin.command,
|
|
1749
|
+
extensions: entry.extensions ?? builtin.extensions,
|
|
1750
|
+
priority: entry.priority ?? 0,
|
|
1751
|
+
source
|
|
1752
|
+
});
|
|
1753
|
+
applyOptionalServerFields(server, entry);
|
|
1754
|
+
return server;
|
|
1755
|
+
}
|
|
1756
|
+
function createServer(input) {
|
|
1757
|
+
const server = {
|
|
1758
|
+
id: input.id,
|
|
1759
|
+
command: input.command,
|
|
1760
|
+
extensions: input.extensions,
|
|
1761
|
+
priority: input.priority,
|
|
1762
|
+
source: input.source
|
|
1763
|
+
};
|
|
1764
|
+
if (input.env !== undefined) {
|
|
1765
|
+
server.env = input.env;
|
|
1766
|
+
}
|
|
1767
|
+
if (input.initialization !== undefined) {
|
|
1768
|
+
server.initialization = input.initialization;
|
|
1769
|
+
}
|
|
1770
|
+
return server;
|
|
1771
|
+
}
|
|
1772
|
+
function applyOptionalServerFields(server, entry) {
|
|
1773
|
+
if (entry.env !== undefined) {
|
|
1774
|
+
server.env = entry.env;
|
|
1775
|
+
}
|
|
1776
|
+
if (entry.initialization !== undefined) {
|
|
1777
|
+
server.initialization = entry.initialization;
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
function isConfigJson(value) {
|
|
1781
|
+
if (!isRecord3(value))
|
|
1782
|
+
return false;
|
|
1783
|
+
const lsp = value["lsp"];
|
|
1784
|
+
return lsp === undefined || isRecord3(lsp);
|
|
1785
|
+
}
|
|
1786
|
+
function parseLspEntry(value) {
|
|
1787
|
+
return isLspEntry(value) ? value : null;
|
|
1788
|
+
}
|
|
1789
|
+
function isLspEntry(value) {
|
|
1790
|
+
if (!isRecord3(value))
|
|
1791
|
+
return false;
|
|
1792
|
+
const disabled = value["disabled"];
|
|
1793
|
+
const command = value["command"];
|
|
1794
|
+
const extensions = value["extensions"];
|
|
1795
|
+
const priority = value["priority"];
|
|
1796
|
+
const env = value["env"];
|
|
1797
|
+
const initialization = value["initialization"];
|
|
1798
|
+
return (disabled === undefined || typeof disabled === "boolean") && (command === undefined || isStringArray(command)) && (extensions === undefined || isStringArray(extensions)) && (priority === undefined || typeof priority === "number") && (env === undefined || isStringRecord(env)) && (initialization === undefined || isRecord3(initialization));
|
|
1799
|
+
}
|
|
1800
|
+
function isStringArray(value) {
|
|
1801
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
1802
|
+
}
|
|
1803
|
+
function isStringRecord(value) {
|
|
1804
|
+
return isRecord3(value) && Object.values(value).every((item) => typeof item === "string");
|
|
1805
|
+
}
|
|
1806
|
+
function isRecord3(value) {
|
|
1807
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1808
|
+
}
|
|
1809
|
+
function getDisabledServerIds() {
|
|
1810
|
+
const configs = loadAllConfigs();
|
|
1811
|
+
const disabled = new Set;
|
|
1812
|
+
for (const config of configs.values()) {
|
|
1813
|
+
if (!config.lsp)
|
|
1814
|
+
continue;
|
|
1815
|
+
for (const [id, rawEntry] of Object.entries(config.lsp)) {
|
|
1816
|
+
const entry = parseLspEntry(rawEntry);
|
|
1817
|
+
if (!entry)
|
|
1818
|
+
continue;
|
|
1819
|
+
if (entry.disabled)
|
|
1820
|
+
disabled.add(id);
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
return disabled;
|
|
1824
|
+
}
|
|
1825
|
+
|
|
1826
|
+
// ../lsp-tools-mcp/dist/lsp/server-installation.js
|
|
1827
|
+
import { existsSync as existsSync4 } from "node:fs";
|
|
1828
|
+
import { delimiter as delimiter3, join as join4 } from "node:path";
|
|
1829
|
+
function isServerInstalled(command, _workingDirectory) {
|
|
1830
|
+
if (command.length === 0)
|
|
1831
|
+
return false;
|
|
1832
|
+
const [cmd] = command;
|
|
1833
|
+
if (!cmd)
|
|
1834
|
+
return false;
|
|
1835
|
+
if (cmd.includes("/") || cmd.includes("\\")) {
|
|
1836
|
+
if (existsSync4(cmd))
|
|
1837
|
+
return true;
|
|
1838
|
+
}
|
|
1839
|
+
const isWindows = process.platform === "win32";
|
|
1840
|
+
let exts = [""];
|
|
1841
|
+
if (isWindows) {
|
|
1842
|
+
const pathExt = process.env["PATHEXT"] ?? "";
|
|
1843
|
+
if (pathExt) {
|
|
1844
|
+
const systemExts = pathExt.split(";").filter(Boolean);
|
|
1845
|
+
exts = [...new Set([...exts, ...systemExts, ".exe", ".cmd", ".bat", ".ps1"])];
|
|
1846
|
+
} else {
|
|
1847
|
+
exts = ["", ".exe", ".cmd", ".bat", ".ps1"];
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
let pathEnv = process.env["PATH"] ?? "";
|
|
1851
|
+
if (isWindows && !pathEnv) {
|
|
1852
|
+
pathEnv = process.env["Path"] ?? "";
|
|
1853
|
+
}
|
|
1854
|
+
const paths = pathEnv.split(delimiter3);
|
|
1855
|
+
for (const p of paths) {
|
|
1856
|
+
for (const suffix of exts) {
|
|
1857
|
+
if (existsSync4(join4(p, cmd + suffix))) {
|
|
1858
|
+
return true;
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
if (cmd === "node")
|
|
1863
|
+
return true;
|
|
1864
|
+
return false;
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
// ../lsp-tools-mcp/dist/lsp/server-resolution.js
|
|
1868
|
+
function findServerForExtension(ext) {
|
|
1869
|
+
const servers = getMergedServers();
|
|
1870
|
+
for (const server of servers) {
|
|
1871
|
+
if (server.extensions.includes(ext) && isServerInstalled(server.command)) {
|
|
1872
|
+
const resolvedServer = {
|
|
1873
|
+
id: server.id,
|
|
1874
|
+
command: server.command,
|
|
1875
|
+
extensions: server.extensions,
|
|
1876
|
+
priority: server.priority
|
|
1877
|
+
};
|
|
1878
|
+
if (server.env !== undefined) {
|
|
1879
|
+
return {
|
|
1880
|
+
status: "found",
|
|
1881
|
+
server: {
|
|
1882
|
+
...resolvedServer,
|
|
1883
|
+
env: server.env,
|
|
1884
|
+
...server.initialization === undefined ? {} : { initialization: server.initialization }
|
|
1885
|
+
}
|
|
1886
|
+
};
|
|
1887
|
+
}
|
|
1888
|
+
return {
|
|
1889
|
+
status: "found",
|
|
1890
|
+
server: {
|
|
1891
|
+
...resolvedServer,
|
|
1892
|
+
...server.initialization === undefined ? {} : { initialization: server.initialization }
|
|
1893
|
+
}
|
|
1894
|
+
};
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
for (const server of servers) {
|
|
1898
|
+
if (server.extensions.includes(ext)) {
|
|
1899
|
+
const installHint = LSP_INSTALL_HINTS[server.id] ?? `Install '${server.command[0]}' and ensure it's in your PATH`;
|
|
1900
|
+
return {
|
|
1901
|
+
status: "not_installed",
|
|
1902
|
+
server: {
|
|
1903
|
+
id: server.id,
|
|
1904
|
+
command: server.command,
|
|
1905
|
+
extensions: server.extensions
|
|
1906
|
+
},
|
|
1907
|
+
installHint
|
|
1908
|
+
};
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
const availableServers = [...new Set(servers.map((s) => s.id))];
|
|
1912
|
+
return {
|
|
1913
|
+
status: "not_configured",
|
|
1914
|
+
extension: ext,
|
|
1915
|
+
availableServers
|
|
1916
|
+
};
|
|
1917
|
+
}
|
|
1918
|
+
function getAllServers() {
|
|
1919
|
+
const servers = getMergedServers();
|
|
1920
|
+
const disabled = getDisabledServerIds();
|
|
1921
|
+
const result = [];
|
|
1922
|
+
const seen = new Set;
|
|
1923
|
+
for (const server of servers) {
|
|
1924
|
+
if (seen.has(server.id))
|
|
1925
|
+
continue;
|
|
1926
|
+
result.push({
|
|
1927
|
+
id: server.id,
|
|
1928
|
+
installed: isServerInstalled(server.command),
|
|
1929
|
+
extensions: server.extensions,
|
|
1930
|
+
disabled: false,
|
|
1931
|
+
source: server.source,
|
|
1932
|
+
priority: server.priority
|
|
1933
|
+
});
|
|
1934
|
+
seen.add(server.id);
|
|
1935
|
+
}
|
|
1936
|
+
for (const id of disabled) {
|
|
1937
|
+
if (seen.has(id))
|
|
1938
|
+
continue;
|
|
1939
|
+
const builtin = BUILTIN_SERVERS[id];
|
|
1940
|
+
result.push({
|
|
1941
|
+
id,
|
|
1942
|
+
installed: builtin ? isServerInstalled(builtin.command) : false,
|
|
1943
|
+
extensions: builtin?.extensions ?? [],
|
|
1944
|
+
disabled: true,
|
|
1945
|
+
source: "disabled",
|
|
1946
|
+
priority: 0
|
|
1947
|
+
});
|
|
1948
|
+
}
|
|
1949
|
+
return result;
|
|
1950
|
+
}
|
|
1951
|
+
|
|
1952
|
+
// ../lsp-tools-mcp/dist/lsp/client-wrapper.js
|
|
1953
|
+
var WORKSPACE_MARKERS = [".git", "package.json", "pyproject.toml", "Cargo.toml", "go.mod", "pom.xml", "build.gradle"];
|
|
1954
|
+
function isDirectoryPath(filePath) {
|
|
1955
|
+
try {
|
|
1956
|
+
return statSync2(filePath).isDirectory();
|
|
1957
|
+
} catch {
|
|
1958
|
+
return false;
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
function findWorkspaceRoot(filePath) {
|
|
1962
|
+
const abs = resolve2(contextCwd(), filePath);
|
|
1963
|
+
let dir = abs;
|
|
1964
|
+
if (!isDirectoryPath(dir)) {
|
|
1965
|
+
dir = dirname2(dir);
|
|
1966
|
+
}
|
|
1967
|
+
let prevDir = "";
|
|
1968
|
+
while (dir !== prevDir) {
|
|
1969
|
+
for (const marker of WORKSPACE_MARKERS) {
|
|
1970
|
+
if (existsSync5(join5(dir, marker))) {
|
|
1971
|
+
return dir;
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
prevDir = dir;
|
|
1975
|
+
dir = dirname2(dir);
|
|
1976
|
+
}
|
|
1977
|
+
return dirname2(abs);
|
|
1978
|
+
}
|
|
1979
|
+
function formatServerLookupError(result) {
|
|
1980
|
+
if (result.status === "not_installed") {
|
|
1981
|
+
return formatNotInstalled(result);
|
|
1982
|
+
}
|
|
1983
|
+
return [
|
|
1984
|
+
`No LSP server configured for extension: ${result.extension}`,
|
|
1985
|
+
"",
|
|
1986
|
+
`Available servers: ${result.availableServers.slice(0, 10).join(", ")}${result.availableServers.length > 10 ? "..." : ""}`,
|
|
1987
|
+
"",
|
|
1988
|
+
"Configure a custom server in '.codex/lsp-client.json':",
|
|
1989
|
+
" {",
|
|
1990
|
+
' "lsp": {',
|
|
1991
|
+
' "my-server": {',
|
|
1992
|
+
' "command": ["my-lsp", "--stdio"],',
|
|
1993
|
+
` "extensions": ["${result.extension}"]`,
|
|
1994
|
+
" }",
|
|
1995
|
+
" }",
|
|
1996
|
+
" }"
|
|
1997
|
+
].join(`
|
|
1998
|
+
`);
|
|
1999
|
+
}
|
|
2000
|
+
function formatNotInstalled(result) {
|
|
2001
|
+
const { server, installHint } = result;
|
|
2002
|
+
const extensions = server.extensions.join(", ");
|
|
2003
|
+
const decision = loadInstallDecision(server.id)?.decision;
|
|
2004
|
+
if (decision === "declined") {
|
|
2005
|
+
return `LSP server '${server.id}' (${extensions}) is NOT INSTALLED; user previously declined installation — proceed without LSP.`;
|
|
2006
|
+
}
|
|
2007
|
+
const header = [
|
|
2008
|
+
`LSP server '${server.id}' for ${extensions} is NOT INSTALLED.`,
|
|
2009
|
+
"",
|
|
2010
|
+
`Command not found: ${server.command[0]}`,
|
|
2011
|
+
""
|
|
2012
|
+
];
|
|
2013
|
+
if (decision === "allowed") {
|
|
2014
|
+
return [
|
|
2015
|
+
...header,
|
|
2016
|
+
"The user has pre-authorized LSP installation. Run the install command, then retry this tool:",
|
|
2017
|
+
` ${installHint}`
|
|
2018
|
+
].join(`
|
|
2019
|
+
`);
|
|
2020
|
+
}
|
|
2021
|
+
return [
|
|
2022
|
+
...header,
|
|
2023
|
+
"To install, run:",
|
|
2024
|
+
` ${installHint}`,
|
|
2025
|
+
"",
|
|
2026
|
+
"ACTION REQUIRED — ASK THE USER whether to install this LSP server.",
|
|
2027
|
+
"- If the user agrees: run the install command above, then retry this tool.",
|
|
2028
|
+
"- If the user declines, OR has NOT explicitly asked for LSP installation:",
|
|
2029
|
+
` call lsp_install_decision { server_id: "${server.id}", decision: "declined" },`,
|
|
2030
|
+
" then ignore this message and proceed WITHOUT LSP."
|
|
2031
|
+
].join(`
|
|
2032
|
+
`);
|
|
2033
|
+
}
|
|
2034
|
+
var READ_ONLY_RETRY_TOOLS = new Set([
|
|
2035
|
+
"diagnostics",
|
|
2036
|
+
"definition",
|
|
2037
|
+
"references",
|
|
2038
|
+
"documentSymbols",
|
|
2039
|
+
"workspaceSymbols",
|
|
2040
|
+
"prepareRename"
|
|
2041
|
+
]);
|
|
2042
|
+
async function withLspClient(filePath, fn, toolName, options = {}) {
|
|
2043
|
+
const absPath = resolve2(contextCwd(), filePath);
|
|
2044
|
+
if (isDirectoryPath(absPath)) {
|
|
2045
|
+
throw new LspInvalidPathError("Directory paths are not supported by this LSP tool. " + "Use lsp.diagnostics with a directory path for directory diagnostics.");
|
|
2046
|
+
}
|
|
2047
|
+
const ext = effectiveExtension(absPath);
|
|
2048
|
+
const result = findServerForExtension(ext);
|
|
2049
|
+
if (result.status !== "found") {
|
|
2050
|
+
throw new LspServerLookupError(formatServerLookupError(result));
|
|
2051
|
+
}
|
|
2052
|
+
const server = result.server;
|
|
2053
|
+
const root = findWorkspaceRoot(absPath);
|
|
2054
|
+
const manager = options.manager ?? getLspManager();
|
|
2055
|
+
const acquireAndCall = async (allowRetry) => {
|
|
2056
|
+
const client = await manager.getClient(root, server, options.signal);
|
|
2057
|
+
try {
|
|
2058
|
+
return await fn(client, root);
|
|
2059
|
+
} catch (err) {
|
|
2060
|
+
if (allowRetry && READ_ONLY_RETRY_TOOLS.has(toolName) && isLspDeadConnectionError(err)) {
|
|
2061
|
+
manager.invalidateClient(root, server.id, client);
|
|
2062
|
+
return acquireAndCall(false);
|
|
2063
|
+
}
|
|
2064
|
+
if (err instanceof LspRequestTimeoutError) {
|
|
2065
|
+
if (manager.isServerInitializing(root, server.id)) {
|
|
2066
|
+
throw new LspServerInitializingError(err);
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
throw err;
|
|
2070
|
+
} finally {
|
|
2071
|
+
manager.releaseClient(root, server.id);
|
|
2072
|
+
}
|
|
2073
|
+
};
|
|
2074
|
+
return acquireAndCall(true);
|
|
2075
|
+
}
|
|
2076
|
+
|
|
2077
|
+
// ../lsp-tools-mcp/dist/lsp/directory-diagnostics.js
|
|
2078
|
+
import { existsSync as existsSync6, lstatSync, readdirSync } from "node:fs";
|
|
2079
|
+
import { join as join6, resolve as resolve3 } from "node:path";
|
|
2080
|
+
|
|
2081
|
+
// ../lsp-tools-mcp/dist/lsp/formatters.js
|
|
2082
|
+
import { fileURLToPath } from "node:url";
|
|
2083
|
+
var DIAGNOSTIC_SEVERITY_FILTERS = {
|
|
2084
|
+
error: 1,
|
|
2085
|
+
warning: 2,
|
|
2086
|
+
information: 3,
|
|
2087
|
+
hint: 4
|
|
2088
|
+
};
|
|
2089
|
+
function uriToPath(uri) {
|
|
2090
|
+
return fileURLToPath(uri);
|
|
2091
|
+
}
|
|
2092
|
+
function formatLocation(loc) {
|
|
2093
|
+
if ("targetUri" in loc) {
|
|
2094
|
+
const uri2 = uriToPath(loc.targetUri);
|
|
2095
|
+
const line2 = loc.targetRange.start.line + 1;
|
|
2096
|
+
const char2 = loc.targetRange.start.character;
|
|
2097
|
+
return `${uri2}:${line2}:${char2}`;
|
|
2098
|
+
}
|
|
2099
|
+
const uri = uriToPath(loc.uri);
|
|
2100
|
+
const line = loc.range.start.line + 1;
|
|
2101
|
+
const char = loc.range.start.character;
|
|
2102
|
+
return `${uri}:${line}:${char}`;
|
|
2103
|
+
}
|
|
2104
|
+
function formatSymbolKind(kind) {
|
|
2105
|
+
return SYMBOL_KIND_MAP[kind] ?? `Unknown(${kind})`;
|
|
2106
|
+
}
|
|
2107
|
+
function formatSeverity(severity) {
|
|
2108
|
+
if (!severity)
|
|
2109
|
+
return "unknown";
|
|
2110
|
+
return SEVERITY_MAP[severity] ?? `unknown(${severity})`;
|
|
2111
|
+
}
|
|
2112
|
+
function formatDocumentSymbol(symbol, indent = 0) {
|
|
2113
|
+
const prefix = " ".repeat(indent);
|
|
2114
|
+
const kind = formatSymbolKind(symbol.kind);
|
|
2115
|
+
const line = symbol.range.start.line + 1;
|
|
2116
|
+
let result = `${prefix}${symbol.name} (${kind}) - line ${line}`;
|
|
2117
|
+
if (symbol.children && symbol.children.length > 0) {
|
|
2118
|
+
for (const child of symbol.children) {
|
|
2119
|
+
result += `
|
|
2120
|
+
${formatDocumentSymbol(child, indent + 1)}`;
|
|
2121
|
+
}
|
|
2122
|
+
}
|
|
2123
|
+
return result;
|
|
2124
|
+
}
|
|
2125
|
+
function formatSymbolInfo(symbol) {
|
|
2126
|
+
const kind = formatSymbolKind(symbol.kind);
|
|
2127
|
+
const loc = formatLocation(symbol.location);
|
|
2128
|
+
const container = symbol.containerName ? ` (in ${symbol.containerName})` : "";
|
|
2129
|
+
return `${symbol.name} (${kind})${container} - ${loc}`;
|
|
2130
|
+
}
|
|
2131
|
+
function formatDiagnostic(diag) {
|
|
2132
|
+
const severity = formatSeverity(diag.severity);
|
|
2133
|
+
const line = diag.range.start.line + 1;
|
|
2134
|
+
const char = diag.range.start.character;
|
|
2135
|
+
const source = diag.source ? `[${diag.source}]` : "";
|
|
2136
|
+
const code = diag.code ? ` (${diag.code})` : "";
|
|
2137
|
+
return `${severity}${source}${code} at ${line}:${char}: ${diag.message}`;
|
|
2138
|
+
}
|
|
2139
|
+
function filterDiagnosticsBySeverity(diagnostics, severityFilter) {
|
|
2140
|
+
if (!severityFilter || severityFilter === "all") {
|
|
2141
|
+
return diagnostics;
|
|
2142
|
+
}
|
|
2143
|
+
const targetSeverity = DIAGNOSTIC_SEVERITY_FILTERS[severityFilter];
|
|
2144
|
+
return diagnostics.filter((d) => d.severity === targetSeverity);
|
|
2145
|
+
}
|
|
2146
|
+
function formatPrepareRenameResult(result) {
|
|
2147
|
+
if (!result)
|
|
2148
|
+
return "Cannot rename at this position";
|
|
2149
|
+
if ("defaultBehavior" in result) {
|
|
2150
|
+
return result.defaultBehavior ? "Rename supported (using default behavior)" : "Cannot rename at this position";
|
|
2151
|
+
}
|
|
2152
|
+
if ("range" in result && result.range) {
|
|
2153
|
+
const startLine = result.range.start.line + 1;
|
|
2154
|
+
const startChar = result.range.start.character;
|
|
2155
|
+
const endLine = result.range.end.line + 1;
|
|
2156
|
+
const endChar = result.range.end.character;
|
|
2157
|
+
const placeholder = result.placeholder ? ` (current: "${result.placeholder}")` : "";
|
|
2158
|
+
return `Rename available at ${startLine}:${startChar}-${endLine}:${endChar}${placeholder}`;
|
|
2159
|
+
}
|
|
2160
|
+
if ("start" in result && "end" in result) {
|
|
2161
|
+
const startLine = result.start.line + 1;
|
|
2162
|
+
const startChar = result.start.character;
|
|
2163
|
+
const endLine = result.end.line + 1;
|
|
2164
|
+
const endChar = result.end.character;
|
|
2165
|
+
return `Rename available at ${startLine}:${startChar}-${endLine}:${endChar}`;
|
|
2166
|
+
}
|
|
2167
|
+
return "Cannot rename at this position";
|
|
2168
|
+
}
|
|
2169
|
+
function formatApplyResult(result) {
|
|
2170
|
+
const lines = [];
|
|
2171
|
+
if (result.success) {
|
|
2172
|
+
lines.push(`Applied ${result.totalEdits} edit(s) to ${result.filesModified.length} file(s):`);
|
|
2173
|
+
for (const file of result.filesModified) {
|
|
2174
|
+
lines.push(` - ${file}`);
|
|
2175
|
+
}
|
|
2176
|
+
} else {
|
|
2177
|
+
lines.push("Failed to apply some changes:");
|
|
2178
|
+
for (const err of result.errors) {
|
|
2179
|
+
lines.push(` Error: ${err}`);
|
|
2180
|
+
}
|
|
2181
|
+
if (result.filesModified.length > 0) {
|
|
2182
|
+
lines.push(`Successfully modified: ${result.filesModified.join(", ")}`);
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
return lines.join(`
|
|
2186
|
+
`);
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2189
|
+
// ../lsp-tools-mcp/dist/lsp/directory-diagnostics.js
|
|
2190
|
+
var SKIP_DIRECTORIES = new Set(["node_modules", ".git", "dist", "build", ".next", "out"]);
|
|
2191
|
+
function collectFilesWithExtension(dir, extension, maxFiles) {
|
|
2192
|
+
const files = [];
|
|
2193
|
+
function walk(currentDir) {
|
|
2194
|
+
if (files.length >= maxFiles)
|
|
2195
|
+
return;
|
|
2196
|
+
let entries = [];
|
|
2197
|
+
try {
|
|
2198
|
+
entries = readdirSync(currentDir);
|
|
2199
|
+
} catch {
|
|
2200
|
+
return;
|
|
2201
|
+
}
|
|
2202
|
+
for (const entry of entries) {
|
|
2203
|
+
if (files.length >= maxFiles)
|
|
2204
|
+
return;
|
|
2205
|
+
const fullPath = join6(currentDir, entry);
|
|
2206
|
+
let stat;
|
|
2207
|
+
try {
|
|
2208
|
+
stat = lstatSync(fullPath);
|
|
2209
|
+
} catch {
|
|
2210
|
+
continue;
|
|
2211
|
+
}
|
|
2212
|
+
if (!stat || stat.isSymbolicLink())
|
|
2213
|
+
continue;
|
|
2214
|
+
if (stat.isDirectory()) {
|
|
2215
|
+
if (!SKIP_DIRECTORIES.has(entry)) {
|
|
2216
|
+
walk(fullPath);
|
|
2217
|
+
}
|
|
2218
|
+
} else if (stat.isFile() && effectiveExtension(fullPath) === extension) {
|
|
2219
|
+
files.push(fullPath);
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
walk(dir);
|
|
2224
|
+
return files;
|
|
2225
|
+
}
|
|
2226
|
+
async function aggregateDiagnosticsForDirectory(directory, extension, severity, maxFiles = DEFAULT_MAX_DIRECTORY_FILES) {
|
|
2227
|
+
if (!extension.startsWith(".")) {
|
|
2228
|
+
throw new LspInvalidPathError(`Extension must start with a dot (e.g., ".ts", not "${extension}"). Use ".${extension}" instead.`);
|
|
2229
|
+
}
|
|
2230
|
+
const absDir = resolve3(contextCwd(), directory);
|
|
2231
|
+
if (!existsSync6(absDir)) {
|
|
2232
|
+
throw new LspInvalidPathError(`Directory does not exist: ${absDir}`);
|
|
2233
|
+
}
|
|
2234
|
+
const serverResult = findServerForExtension(extension);
|
|
2235
|
+
if (serverResult.status !== "found") {
|
|
2236
|
+
throw new LspServerLookupError(formatServerLookupError(serverResult));
|
|
2237
|
+
}
|
|
2238
|
+
const server = serverResult.server;
|
|
2239
|
+
const allFiles = collectFilesWithExtension(absDir, extension, maxFiles + 1);
|
|
2240
|
+
const wasCapped = allFiles.length > maxFiles;
|
|
2241
|
+
const filesToProcess = allFiles.slice(0, maxFiles);
|
|
2242
|
+
if (filesToProcess.length === 0) {
|
|
2243
|
+
return [
|
|
2244
|
+
`Directory: ${absDir}`,
|
|
2245
|
+
`Extension: ${extension}`,
|
|
2246
|
+
"Files scanned: 0",
|
|
2247
|
+
`No files found with extension "${extension}".`
|
|
2248
|
+
].join(`
|
|
2249
|
+
`);
|
|
2250
|
+
}
|
|
2251
|
+
const root = findWorkspaceRoot(absDir);
|
|
2252
|
+
const manager = getLspManager();
|
|
2253
|
+
const allDiagnostics = [];
|
|
2254
|
+
const fileErrors = [];
|
|
2255
|
+
const client = await manager.getClient(root, server);
|
|
2256
|
+
try {
|
|
2257
|
+
for (const file of filesToProcess) {
|
|
2258
|
+
try {
|
|
2259
|
+
const result = await client.diagnostics(file);
|
|
2260
|
+
const filtered = filterDiagnosticsBySeverity(result.items, severity);
|
|
2261
|
+
allDiagnostics.push(...filtered.map((diagnostic) => ({
|
|
2262
|
+
filePath: file,
|
|
2263
|
+
diagnostic
|
|
2264
|
+
})));
|
|
2265
|
+
} catch (e) {
|
|
2266
|
+
fileErrors.push({
|
|
2267
|
+
file,
|
|
2268
|
+
error: e instanceof Error ? e.message : String(e)
|
|
2269
|
+
});
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
} finally {
|
|
2273
|
+
manager.releaseClient(root, server.id);
|
|
2274
|
+
}
|
|
2275
|
+
const displayDiagnostics = allDiagnostics.slice(0, DEFAULT_MAX_DIAGNOSTICS);
|
|
2276
|
+
const wasDiagCapped = allDiagnostics.length > DEFAULT_MAX_DIAGNOSTICS;
|
|
2277
|
+
const lines = [
|
|
2278
|
+
`Directory: ${absDir}`,
|
|
2279
|
+
`Extension: ${extension}`,
|
|
2280
|
+
`Files scanned: ${filesToProcess.length}${wasCapped ? ` (capped at ${maxFiles})` : ""}`,
|
|
2281
|
+
`Files with errors: ${fileErrors.length}`,
|
|
2282
|
+
`Total diagnostics: ${allDiagnostics.length}`
|
|
2283
|
+
];
|
|
2284
|
+
if (fileErrors.length > 0) {
|
|
2285
|
+
lines.push("", "File processing errors:");
|
|
2286
|
+
for (const { file, error } of fileErrors) {
|
|
2287
|
+
lines.push(` ${file}: ${error}`);
|
|
2288
|
+
}
|
|
2289
|
+
}
|
|
2290
|
+
if (displayDiagnostics.length > 0) {
|
|
2291
|
+
lines.push("");
|
|
2292
|
+
for (const { filePath, diagnostic } of displayDiagnostics) {
|
|
2293
|
+
lines.push(`${filePath}: ${formatDiagnostic(diagnostic)}`);
|
|
2294
|
+
}
|
|
2295
|
+
if (wasDiagCapped) {
|
|
2296
|
+
lines.push("", `... (${allDiagnostics.length - DEFAULT_MAX_DIAGNOSTICS} more diagnostics not shown)`);
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
return lines.join(`
|
|
2300
|
+
`);
|
|
2301
|
+
}
|
|
2302
|
+
|
|
2303
|
+
// ../lsp-tools-mcp/dist/lsp/infer-extension.js
|
|
2304
|
+
import { lstatSync as lstatSync2, readdirSync as readdirSync2 } from "node:fs";
|
|
2305
|
+
import { join as join7 } from "node:path";
|
|
2306
|
+
var SKIP_DIRECTORIES2 = new Set(["node_modules", ".git", "dist", "build", ".next", "out"]);
|
|
2307
|
+
var MAX_SCAN_ENTRIES = 500;
|
|
2308
|
+
function inferExtensionFromDirectory(directory) {
|
|
2309
|
+
const extensionCounts = new Map;
|
|
2310
|
+
let scanned = 0;
|
|
2311
|
+
function walk(dir) {
|
|
2312
|
+
if (scanned >= MAX_SCAN_ENTRIES)
|
|
2313
|
+
return;
|
|
2314
|
+
let entries;
|
|
2315
|
+
try {
|
|
2316
|
+
entries = readdirSync2(dir);
|
|
2317
|
+
} catch {
|
|
2318
|
+
return;
|
|
2319
|
+
}
|
|
2320
|
+
for (const entry of entries) {
|
|
2321
|
+
if (scanned >= MAX_SCAN_ENTRIES)
|
|
2322
|
+
return;
|
|
2323
|
+
const fullPath = join7(dir, entry);
|
|
2324
|
+
let stat;
|
|
2325
|
+
try {
|
|
2326
|
+
stat = lstatSync2(fullPath);
|
|
2327
|
+
} catch {
|
|
2328
|
+
continue;
|
|
2329
|
+
}
|
|
2330
|
+
if (stat.isSymbolicLink())
|
|
2331
|
+
continue;
|
|
2332
|
+
scanned++;
|
|
2333
|
+
if (stat.isDirectory()) {
|
|
2334
|
+
if (!SKIP_DIRECTORIES2.has(entry)) {
|
|
2335
|
+
walk(fullPath);
|
|
2336
|
+
}
|
|
2337
|
+
} else if (stat.isFile()) {
|
|
2338
|
+
const ext = effectiveExtension(fullPath);
|
|
2339
|
+
if (ext && ext in EXT_TO_LANG) {
|
|
2340
|
+
extensionCounts.set(ext, (extensionCounts.get(ext) ?? 0) + 1);
|
|
2341
|
+
}
|
|
2342
|
+
}
|
|
2343
|
+
}
|
|
2344
|
+
}
|
|
2345
|
+
walk(directory);
|
|
2346
|
+
if (extensionCounts.size === 0)
|
|
2347
|
+
return null;
|
|
2348
|
+
let maxExt = "";
|
|
2349
|
+
let maxCount = 0;
|
|
2350
|
+
for (const [ext, count] of extensionCounts) {
|
|
2351
|
+
if (count > maxCount) {
|
|
2352
|
+
maxCount = count;
|
|
2353
|
+
maxExt = ext;
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
return maxExt || null;
|
|
2357
|
+
}
|
|
2358
|
+
|
|
2359
|
+
// ../lsp-tools-mcp/dist/lsp/workspace-edit.js
|
|
2360
|
+
import { existsSync as existsSync7, readFileSync as readFileSync4, realpathSync, unlinkSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
2361
|
+
import { dirname as dirname3, isAbsolute as isAbsolute3, relative, resolve as resolve4 } from "node:path";
|
|
2362
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
2363
|
+
function errorMessage(error) {
|
|
2364
|
+
return error instanceof Error ? error.message : String(error);
|
|
2365
|
+
}
|
|
2366
|
+
function isPathInsideWorkspace(filePath, workspaceRoot) {
|
|
2367
|
+
const relativePath = relative(workspaceRoot, filePath);
|
|
2368
|
+
return relativePath === "" || !relativePath.startsWith("..") && !isAbsolute3(relativePath);
|
|
2369
|
+
}
|
|
2370
|
+
function realpathForValidation(filePath) {
|
|
2371
|
+
if (existsSync7(filePath))
|
|
2372
|
+
return realpathSync(filePath);
|
|
2373
|
+
const parent = dirname3(filePath);
|
|
2374
|
+
return resolve4(realpathSync(parent), relative(parent, filePath));
|
|
2375
|
+
}
|
|
2376
|
+
function uriToWorkspacePath(uri, workspaceRoot) {
|
|
2377
|
+
let filePath;
|
|
2378
|
+
try {
|
|
2379
|
+
filePath = fileURLToPath2(uri);
|
|
2380
|
+
} catch (error) {
|
|
2381
|
+
return { success: false, error: `non-file URI ${uri}: ${errorMessage(error)}` };
|
|
2382
|
+
}
|
|
2383
|
+
let validatedPath;
|
|
2384
|
+
try {
|
|
2385
|
+
validatedPath = realpathForValidation(filePath);
|
|
2386
|
+
} catch (error) {
|
|
2387
|
+
return { success: false, error: `${filePath}: ${errorMessage(error)}` };
|
|
2388
|
+
}
|
|
2389
|
+
if (!isPathInsideWorkspace(validatedPath, workspaceRoot)) {
|
|
2390
|
+
return { success: false, error: `${filePath}: outside workspace ${workspaceRoot}` };
|
|
2391
|
+
}
|
|
2392
|
+
return { success: true, path: filePath };
|
|
2393
|
+
}
|
|
2394
|
+
function applyTextEditsToFile(filePath, edits) {
|
|
2395
|
+
try {
|
|
2396
|
+
const content = readFileSync4(filePath, "utf-8");
|
|
2397
|
+
const lines = content.split(`
|
|
2398
|
+
`);
|
|
2399
|
+
const sortedEdits = [...edits].sort((a, b) => {
|
|
2400
|
+
if (b.range.start.line !== a.range.start.line) {
|
|
2401
|
+
return b.range.start.line - a.range.start.line;
|
|
2402
|
+
}
|
|
2403
|
+
return b.range.start.character - a.range.start.character;
|
|
2404
|
+
});
|
|
2405
|
+
for (const edit of sortedEdits) {
|
|
2406
|
+
const startLine = edit.range.start.line;
|
|
2407
|
+
const startChar = edit.range.start.character;
|
|
2408
|
+
const endLine = edit.range.end.line;
|
|
2409
|
+
const endChar = edit.range.end.character;
|
|
2410
|
+
if (startLine === endLine) {
|
|
2411
|
+
const line = lines[startLine] ?? "";
|
|
2412
|
+
lines[startLine] = line.substring(0, startChar) + edit.newText + line.substring(endChar);
|
|
2413
|
+
} else {
|
|
2414
|
+
const firstLine = lines[startLine] ?? "";
|
|
2415
|
+
const lastLine = lines[endLine] ?? "";
|
|
2416
|
+
const newContent = firstLine.substring(0, startChar) + edit.newText + lastLine.substring(endChar);
|
|
2417
|
+
lines.splice(startLine, endLine - startLine + 1, ...newContent.split(`
|
|
2418
|
+
`));
|
|
2419
|
+
}
|
|
2420
|
+
}
|
|
2421
|
+
writeFileSync2(filePath, lines.join(`
|
|
2422
|
+
`), "utf-8");
|
|
2423
|
+
return { success: true, editCount: edits.length };
|
|
2424
|
+
} catch (err) {
|
|
2425
|
+
return {
|
|
2426
|
+
success: false,
|
|
2427
|
+
editCount: 0,
|
|
2428
|
+
error: err instanceof Error ? err.message : String(err)
|
|
2429
|
+
};
|
|
2430
|
+
}
|
|
2431
|
+
}
|
|
2432
|
+
function applyWorkspaceEdit(edit, options = {}) {
|
|
2433
|
+
if (!edit) {
|
|
2434
|
+
return { success: false, filesModified: [], totalEdits: 0, errors: ["No edit provided"] };
|
|
2435
|
+
}
|
|
2436
|
+
const result = { success: true, filesModified: [], totalEdits: 0, errors: [] };
|
|
2437
|
+
const workspaceRoot = realpathSync(options.workspaceRoot ?? contextCwd());
|
|
2438
|
+
if (edit.changes) {
|
|
2439
|
+
for (const [uri, edits] of Object.entries(edit.changes)) {
|
|
2440
|
+
const validatedPath = uriToWorkspacePath(uri, workspaceRoot);
|
|
2441
|
+
if (!validatedPath.success) {
|
|
2442
|
+
result.success = false;
|
|
2443
|
+
result.errors.push(validatedPath.error);
|
|
2444
|
+
continue;
|
|
2445
|
+
}
|
|
2446
|
+
const applyResult = applyTextEditsToFile(validatedPath.path, edits);
|
|
2447
|
+
if (applyResult.success) {
|
|
2448
|
+
result.filesModified.push(validatedPath.path);
|
|
2449
|
+
result.totalEdits += applyResult.editCount;
|
|
2450
|
+
} else {
|
|
2451
|
+
result.success = false;
|
|
2452
|
+
result.errors.push(`${validatedPath.path}: ${applyResult.error}`);
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
if (edit.documentChanges) {
|
|
2457
|
+
for (const change of edit.documentChanges) {
|
|
2458
|
+
if (!("kind" in change)) {
|
|
2459
|
+
const validatedPath = uriToWorkspacePath(change.textDocument.uri, workspaceRoot);
|
|
2460
|
+
if (!validatedPath.success) {
|
|
2461
|
+
result.success = false;
|
|
2462
|
+
result.errors.push(validatedPath.error);
|
|
2463
|
+
continue;
|
|
2464
|
+
}
|
|
2465
|
+
const applyResult = applyTextEditsToFile(validatedPath.path, change.edits);
|
|
2466
|
+
if (applyResult.success) {
|
|
2467
|
+
result.filesModified.push(validatedPath.path);
|
|
2468
|
+
result.totalEdits += applyResult.editCount;
|
|
2469
|
+
} else {
|
|
2470
|
+
result.success = false;
|
|
2471
|
+
result.errors.push(`${validatedPath.path}: ${applyResult.error}`);
|
|
2472
|
+
}
|
|
2473
|
+
continue;
|
|
2474
|
+
}
|
|
2475
|
+
if (change.kind === "create") {
|
|
2476
|
+
try {
|
|
2477
|
+
const validatedPath = uriToWorkspacePath(change.uri, workspaceRoot);
|
|
2478
|
+
if (!validatedPath.success) {
|
|
2479
|
+
result.success = false;
|
|
2480
|
+
result.errors.push(`Create ${change.uri}: ${validatedPath.error}`);
|
|
2481
|
+
continue;
|
|
2482
|
+
}
|
|
2483
|
+
writeFileSync2(validatedPath.path, "", "utf-8");
|
|
2484
|
+
result.filesModified.push(validatedPath.path);
|
|
2485
|
+
} catch (err) {
|
|
2486
|
+
result.success = false;
|
|
2487
|
+
result.errors.push(`Create ${change.uri}: ${String(err)}`);
|
|
2488
|
+
}
|
|
2489
|
+
} else if (change.kind === "rename") {
|
|
2490
|
+
try {
|
|
2491
|
+
const oldPath = uriToWorkspacePath(change.oldUri, workspaceRoot);
|
|
2492
|
+
const newPath = uriToWorkspacePath(change.newUri, workspaceRoot);
|
|
2493
|
+
if (!oldPath.success || !newPath.success) {
|
|
2494
|
+
const error = oldPath.success ? newPath.success ? "invalid URI" : newPath.error : oldPath.error;
|
|
2495
|
+
result.success = false;
|
|
2496
|
+
result.errors.push(`Rename ${change.oldUri}: ${error}`);
|
|
2497
|
+
continue;
|
|
2498
|
+
}
|
|
2499
|
+
const content = readFileSync4(oldPath.path, "utf-8");
|
|
2500
|
+
writeFileSync2(newPath.path, content, "utf-8");
|
|
2501
|
+
unlinkSync(oldPath.path);
|
|
2502
|
+
result.filesModified.push(newPath.path);
|
|
2503
|
+
} catch (err) {
|
|
2504
|
+
result.success = false;
|
|
2505
|
+
result.errors.push(`Rename ${change.oldUri}: ${String(err)}`);
|
|
2506
|
+
}
|
|
2507
|
+
} else if (change.kind === "delete") {
|
|
2508
|
+
try {
|
|
2509
|
+
const validatedPath = uriToWorkspacePath(change.uri, workspaceRoot);
|
|
2510
|
+
if (!validatedPath.success) {
|
|
2511
|
+
result.success = false;
|
|
2512
|
+
result.errors.push(`Delete ${change.uri}: ${validatedPath.error}`);
|
|
2513
|
+
continue;
|
|
2514
|
+
}
|
|
2515
|
+
unlinkSync(validatedPath.path);
|
|
2516
|
+
result.filesModified.push(validatedPath.path);
|
|
2517
|
+
} catch (err) {
|
|
2518
|
+
result.success = false;
|
|
2519
|
+
result.errors.push(`Delete ${change.uri}: ${String(err)}`);
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
return result;
|
|
2525
|
+
}
|
|
2526
|
+
|
|
2527
|
+
// ../lsp-tools-mcp/dist/lsp/startup-failure.js
|
|
2528
|
+
var RUST_SRC_REPAIR_MESSAGE = [
|
|
2529
|
+
"rust-analyzer exited while loading Rust standard library sources.",
|
|
2530
|
+
"",
|
|
2531
|
+
"Repair rust-src for the active toolchain:",
|
|
2532
|
+
" rustup component remove rust-src",
|
|
2533
|
+
" rustup component add rust-src"
|
|
2534
|
+
];
|
|
2535
|
+
function errorMessage2(error) {
|
|
2536
|
+
return error instanceof Error ? error.message : String(error);
|
|
2537
|
+
}
|
|
2538
|
+
function formatKnownLspStartupFailure(error) {
|
|
2539
|
+
if (!(error instanceof LspProcessExitedError))
|
|
2540
|
+
return null;
|
|
2541
|
+
if (error.serverId !== "rust")
|
|
2542
|
+
return null;
|
|
2543
|
+
const details = error.stderrTail ?? error.message;
|
|
2544
|
+
const lowerDetails = details.toLowerCase();
|
|
2545
|
+
const isRustSrcFailure = lowerDetails.includes("rust-src") && (lowerDetails.includes("failed to install component") || lowerDetails.includes("detected conflict") || lowerDetails.includes("can't load standard library") || lowerDetails.includes("try installing") || lowerDetails.includes("sysroot"));
|
|
2546
|
+
if (!isRustSrcFailure)
|
|
2547
|
+
return null;
|
|
2548
|
+
return [...RUST_SRC_REPAIR_MESSAGE, "", "Original stderr tail:", details].join(`
|
|
2549
|
+
`);
|
|
2550
|
+
}
|
|
2551
|
+
function handleMissingDependencyError(error) {
|
|
2552
|
+
const knownStartupFailure = formatKnownLspStartupFailure(error);
|
|
2553
|
+
if (knownStartupFailure)
|
|
2554
|
+
return knownStartupFailure;
|
|
2555
|
+
const message = errorMessage2(error);
|
|
2556
|
+
return message.includes("NOT INSTALLED") || message.includes("No LSP server configured") ? message : null;
|
|
2557
|
+
}
|
|
2558
|
+
|
|
2559
|
+
// ../lsp-tools-mcp/dist/missing-dependency-result.js
|
|
2560
|
+
function missingDependencyResult(error, details) {
|
|
2561
|
+
const message = handleMissingDependencyError(error);
|
|
2562
|
+
if (!message)
|
|
2563
|
+
return null;
|
|
2564
|
+
return {
|
|
2565
|
+
content: [{ type: "text", text: message }],
|
|
2566
|
+
details: {
|
|
2567
|
+
...details,
|
|
2568
|
+
error: message,
|
|
2569
|
+
errorKind: "missing_dependency"
|
|
2570
|
+
}
|
|
2571
|
+
};
|
|
2572
|
+
}
|
|
2573
|
+
|
|
2574
|
+
// ../lsp-tools-mcp/dist/tools.js
|
|
2575
|
+
var objectSchema = (properties, required = []) => ({
|
|
2576
|
+
type: "object",
|
|
2577
|
+
properties,
|
|
2578
|
+
required
|
|
2579
|
+
});
|
|
2580
|
+
function text(text2, details, isError = false) {
|
|
2581
|
+
return { content: [{ type: "text", text: text2 }], details, isError };
|
|
2582
|
+
}
|
|
2583
|
+
function isRecord4(value) {
|
|
2584
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2585
|
+
}
|
|
2586
|
+
function requireString(params, key) {
|
|
2587
|
+
const value = params[key];
|
|
2588
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
2589
|
+
throw new Error(`Missing required string parameter '${key}'`);
|
|
2590
|
+
}
|
|
2591
|
+
return value;
|
|
2592
|
+
}
|
|
2593
|
+
function optionalString(params, key) {
|
|
2594
|
+
const value = params[key];
|
|
2595
|
+
return typeof value === "string" ? value : undefined;
|
|
2596
|
+
}
|
|
2597
|
+
function requireNumber(params, key) {
|
|
2598
|
+
const value = params[key];
|
|
2599
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
2600
|
+
throw new Error(`Missing required number parameter '${key}'`);
|
|
2601
|
+
}
|
|
2602
|
+
return value;
|
|
2603
|
+
}
|
|
2604
|
+
function optionalNumber(params, key) {
|
|
2605
|
+
const value = params[key];
|
|
2606
|
+
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
2607
|
+
}
|
|
2608
|
+
function optionalBoolean(params, key) {
|
|
2609
|
+
const value = params[key];
|
|
2610
|
+
return typeof value === "boolean" ? value : undefined;
|
|
2611
|
+
}
|
|
2612
|
+
function isSeverityFilter(value) {
|
|
2613
|
+
return value === "error" || value === "warning" || value === "information" || value === "hint" || value === "all";
|
|
2614
|
+
}
|
|
2615
|
+
function severityFilter(params) {
|
|
2616
|
+
const value = params["severity"];
|
|
2617
|
+
if (isSeverityFilter(value))
|
|
2618
|
+
return value;
|
|
2619
|
+
return "all";
|
|
2620
|
+
}
|
|
2621
|
+
function clientOptions(signal) {
|
|
2622
|
+
return signal === undefined ? {} : { signal };
|
|
2623
|
+
}
|
|
2624
|
+
function asDiagnosticArray(result) {
|
|
2625
|
+
if (!result)
|
|
2626
|
+
return [];
|
|
2627
|
+
if (Array.isArray(result))
|
|
2628
|
+
return result;
|
|
2629
|
+
return result.items ?? [];
|
|
2630
|
+
}
|
|
2631
|
+
function isDocumentSymbol(symbol) {
|
|
2632
|
+
return "range" in symbol;
|
|
2633
|
+
}
|
|
2634
|
+
async function executeLspStatus() {
|
|
2635
|
+
const servers = getAllServers();
|
|
2636
|
+
const snapshots = getLspManager().getSnapshot();
|
|
2637
|
+
const installed = servers.filter((server) => server.installed && !server.disabled);
|
|
2638
|
+
const configuredLines = servers.map((server) => {
|
|
2639
|
+
const state = server.disabled ? "disabled" : server.installed ? "installed" : "missing";
|
|
2640
|
+
return `- ${server.id}: ${state}; source=${server.source}; extensions=${server.extensions.join(", ")}`;
|
|
2641
|
+
});
|
|
2642
|
+
const activeLines = snapshots.map((snapshot) => {
|
|
2643
|
+
const state = snapshot.alive ? snapshot.isInitializing ? "initializing" : "alive" : "dead";
|
|
2644
|
+
return `- ${snapshot.serverId}: ${state}; root=${snapshot.root}; refs=${snapshot.refCount}`;
|
|
2645
|
+
});
|
|
2646
|
+
const lines = [
|
|
2647
|
+
`Configured LSP servers: ${servers.length}`,
|
|
2648
|
+
`Installed LSP servers: ${installed.length}`,
|
|
2649
|
+
"",
|
|
2650
|
+
...configuredLines,
|
|
2651
|
+
"",
|
|
2652
|
+
`Active LSP clients: ${snapshots.length}`,
|
|
2653
|
+
...activeLines
|
|
2654
|
+
];
|
|
2655
|
+
return text(lines.join(`
|
|
2656
|
+
`), { servers, snapshots });
|
|
2657
|
+
}
|
|
2658
|
+
async function executeLspDiagnostics(params, signal) {
|
|
2659
|
+
const filePath = requireString(params, "filePath");
|
|
2660
|
+
const severity = severityFilter(params);
|
|
2661
|
+
try {
|
|
2662
|
+
const absPath = resolve5(contextCwd(), filePath);
|
|
2663
|
+
if (isDirectoryPath(absPath)) {
|
|
2664
|
+
const extension = inferExtensionFromDirectory(absPath);
|
|
2665
|
+
if (!extension) {
|
|
2666
|
+
const message = `No supported source files found in directory: ${absPath}`;
|
|
2667
|
+
const details3 = {
|
|
2668
|
+
filePath,
|
|
2669
|
+
severity,
|
|
2670
|
+
mode: "directory",
|
|
2671
|
+
diagnostics: [],
|
|
2672
|
+
totalDiagnostics: 0,
|
|
2673
|
+
truncated: false,
|
|
2674
|
+
error: message,
|
|
2675
|
+
errorKind: "no_files"
|
|
2676
|
+
};
|
|
2677
|
+
return text(message, details3);
|
|
2678
|
+
}
|
|
2679
|
+
const output2 = await aggregateDiagnosticsForDirectory(absPath, extension, severity);
|
|
2680
|
+
const details2 = {
|
|
2681
|
+
filePath,
|
|
2682
|
+
severity,
|
|
2683
|
+
mode: "directory",
|
|
2684
|
+
diagnostics: [],
|
|
2685
|
+
totalDiagnostics: 0,
|
|
2686
|
+
truncated: false
|
|
2687
|
+
};
|
|
2688
|
+
return text(output2, details2);
|
|
2689
|
+
}
|
|
2690
|
+
const result = await withLspClient(filePath, async (client) => client.diagnostics(filePath), "diagnostics", clientOptions(signal));
|
|
2691
|
+
const diagnostics = filterDiagnosticsBySeverity(asDiagnosticArray(result), severity);
|
|
2692
|
+
const total = diagnostics.length;
|
|
2693
|
+
const truncated = total > DEFAULT_MAX_DIAGNOSTICS;
|
|
2694
|
+
const limited = truncated ? diagnostics.slice(0, DEFAULT_MAX_DIAGNOSTICS) : diagnostics;
|
|
2695
|
+
const output = total === 0 ? "No diagnostics found" : [
|
|
2696
|
+
...truncated ? [`Found ${total} diagnostics (showing first ${DEFAULT_MAX_DIAGNOSTICS}):`] : [],
|
|
2697
|
+
...limited.map(formatDiagnostic)
|
|
2698
|
+
].join(`
|
|
2699
|
+
`);
|
|
2700
|
+
const details = {
|
|
2701
|
+
filePath,
|
|
2702
|
+
severity,
|
|
2703
|
+
mode: "file",
|
|
2704
|
+
diagnostics: diagnostics.map((diagnostic) => ({ file: absPath, diagnostic })),
|
|
2705
|
+
totalDiagnostics: total,
|
|
2706
|
+
truncated
|
|
2707
|
+
};
|
|
2708
|
+
return text(output, details);
|
|
2709
|
+
} catch (error) {
|
|
2710
|
+
const missingDependency = missingDependencyResult(error, {
|
|
2711
|
+
filePath,
|
|
2712
|
+
severity,
|
|
2713
|
+
mode: "file",
|
|
2714
|
+
diagnostics: [],
|
|
2715
|
+
totalDiagnostics: 0,
|
|
2716
|
+
truncated: false
|
|
2717
|
+
});
|
|
2718
|
+
if (missingDependency)
|
|
2719
|
+
return missingDependency;
|
|
2720
|
+
throw error;
|
|
2721
|
+
}
|
|
2722
|
+
}
|
|
2723
|
+
async function executeLspGotoDefinition(params, signal) {
|
|
2724
|
+
const filePath = requireString(params, "filePath");
|
|
2725
|
+
const line = requireNumber(params, "line");
|
|
2726
|
+
const character = requireNumber(params, "character");
|
|
2727
|
+
try {
|
|
2728
|
+
const result = await withLspClient(filePath, async (client) => client.definition(filePath, line, character), "definition", clientOptions(signal));
|
|
2729
|
+
const locations = !result ? [] : Array.isArray(result) ? result : [result];
|
|
2730
|
+
const details = { filePath, line, character, locations };
|
|
2731
|
+
if (locations.length === 0)
|
|
2732
|
+
return text("No definition found", details);
|
|
2733
|
+
return text(locations.map(formatLocation).join(`
|
|
2734
|
+
`), details);
|
|
2735
|
+
} catch (error) {
|
|
2736
|
+
const missingDependency = missingDependencyResult(error, {
|
|
2737
|
+
filePath,
|
|
2738
|
+
line,
|
|
2739
|
+
character,
|
|
2740
|
+
locations: []
|
|
2741
|
+
});
|
|
2742
|
+
if (missingDependency)
|
|
2743
|
+
return missingDependency;
|
|
2744
|
+
throw error;
|
|
2745
|
+
}
|
|
2746
|
+
}
|
|
2747
|
+
async function executeLspFindReferences(params, signal) {
|
|
2748
|
+
const filePath = requireString(params, "filePath");
|
|
2749
|
+
const line = requireNumber(params, "line");
|
|
2750
|
+
const character = requireNumber(params, "character");
|
|
2751
|
+
const includeDeclaration = optionalBoolean(params, "includeDeclaration") ?? true;
|
|
2752
|
+
try {
|
|
2753
|
+
const result = await withLspClient(filePath, async (client) => client.references(filePath, line, character, includeDeclaration), "references", clientOptions(signal));
|
|
2754
|
+
const references = Array.isArray(result) ? result : [];
|
|
2755
|
+
const total = references.length;
|
|
2756
|
+
const truncated = total > DEFAULT_MAX_REFERENCES;
|
|
2757
|
+
const limited = truncated ? references.slice(0, DEFAULT_MAX_REFERENCES) : references;
|
|
2758
|
+
const details = {
|
|
2759
|
+
filePath,
|
|
2760
|
+
line,
|
|
2761
|
+
character,
|
|
2762
|
+
references,
|
|
2763
|
+
totalReferences: total,
|
|
2764
|
+
truncated
|
|
2765
|
+
};
|
|
2766
|
+
if (total === 0)
|
|
2767
|
+
return text("No references found", details);
|
|
2768
|
+
const output = [
|
|
2769
|
+
...truncated ? [`Found ${total} references (showing first ${DEFAULT_MAX_REFERENCES}):`] : [],
|
|
2770
|
+
...limited.map(formatLocation)
|
|
2771
|
+
].join(`
|
|
2772
|
+
`);
|
|
2773
|
+
return text(output, details);
|
|
2774
|
+
} catch (error) {
|
|
2775
|
+
const missingDependency = missingDependencyResult(error, {
|
|
2776
|
+
filePath,
|
|
2777
|
+
line,
|
|
2778
|
+
character,
|
|
2779
|
+
references: [],
|
|
2780
|
+
totalReferences: 0,
|
|
2781
|
+
truncated: false
|
|
2782
|
+
});
|
|
2783
|
+
if (missingDependency)
|
|
2784
|
+
return missingDependency;
|
|
2785
|
+
throw error;
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
async function executeLspSymbols(params, signal) {
|
|
2789
|
+
const filePath = requireString(params, "filePath");
|
|
2790
|
+
const rawScope = optionalString(params, "scope") ?? "document";
|
|
2791
|
+
const scope = rawScope === "workspace" ? "workspace" : "document";
|
|
2792
|
+
const limit = Math.min(optionalNumber(params, "limit") ?? DEFAULT_MAX_SYMBOLS, DEFAULT_MAX_SYMBOLS);
|
|
2793
|
+
try {
|
|
2794
|
+
if (scope === "workspace") {
|
|
2795
|
+
const query = optionalString(params, "query");
|
|
2796
|
+
if (!query) {
|
|
2797
|
+
const message = "Error: 'query' is required for workspace scope";
|
|
2798
|
+
return text(message, {
|
|
2799
|
+
filePath,
|
|
2800
|
+
scope,
|
|
2801
|
+
symbols: [],
|
|
2802
|
+
totalSymbols: 0,
|
|
2803
|
+
truncated: false,
|
|
2804
|
+
error: message,
|
|
2805
|
+
errorKind: "missing_query"
|
|
2806
|
+
});
|
|
2807
|
+
}
|
|
2808
|
+
const symbols2 = await withLspClient(filePath, async (client) => client.workspaceSymbols(query), "workspaceSymbols", clientOptions(signal));
|
|
2809
|
+
return formatSymbolsResult(filePath, scope, symbols2, limit, query);
|
|
2810
|
+
}
|
|
2811
|
+
const symbols = await withLspClient(filePath, async (client) => client.documentSymbols(filePath), "documentSymbols", clientOptions(signal));
|
|
2812
|
+
return formatSymbolsResult(filePath, scope, symbols, limit);
|
|
2813
|
+
} catch (error) {
|
|
2814
|
+
const query = optionalString(params, "query");
|
|
2815
|
+
const missingDependency = missingDependencyResult(error, {
|
|
2816
|
+
filePath,
|
|
2817
|
+
scope,
|
|
2818
|
+
symbols: [],
|
|
2819
|
+
totalSymbols: 0,
|
|
2820
|
+
truncated: false,
|
|
2821
|
+
...query === undefined ? {} : { query }
|
|
2822
|
+
});
|
|
2823
|
+
if (missingDependency)
|
|
2824
|
+
return missingDependency;
|
|
2825
|
+
throw error;
|
|
2826
|
+
}
|
|
2827
|
+
}
|
|
2828
|
+
function formatSymbolsResult(filePath, scope, symbols, limit, query) {
|
|
2829
|
+
const total = symbols.length;
|
|
2830
|
+
const truncated = total > limit;
|
|
2831
|
+
const limited = truncated ? symbols.slice(0, limit) : symbols;
|
|
2832
|
+
const details = {
|
|
2833
|
+
filePath,
|
|
2834
|
+
scope,
|
|
2835
|
+
symbols,
|
|
2836
|
+
totalSymbols: total,
|
|
2837
|
+
truncated,
|
|
2838
|
+
...query === undefined ? {} : { query }
|
|
2839
|
+
};
|
|
2840
|
+
if (total === 0)
|
|
2841
|
+
return text("No symbols found", details);
|
|
2842
|
+
const lines = [];
|
|
2843
|
+
if (truncated)
|
|
2844
|
+
lines.push(`Found ${total} symbols (showing first ${limit}):`);
|
|
2845
|
+
const documentSymbols = limited.filter(isDocumentSymbol);
|
|
2846
|
+
if (documentSymbols.length === limited.length) {
|
|
2847
|
+
lines.push(...documentSymbols.map((symbol) => formatDocumentSymbol(symbol)));
|
|
2848
|
+
} else {
|
|
2849
|
+
lines.push(...limited.filter((symbol) => !isDocumentSymbol(symbol)).map(formatSymbolInfo));
|
|
2850
|
+
}
|
|
2851
|
+
return text(lines.join(`
|
|
2852
|
+
`), details);
|
|
2853
|
+
}
|
|
2854
|
+
async function executeLspPrepareRename(params, signal) {
|
|
2855
|
+
const filePath = requireString(params, "filePath");
|
|
2856
|
+
const line = requireNumber(params, "line");
|
|
2857
|
+
const character = requireNumber(params, "character");
|
|
2858
|
+
try {
|
|
2859
|
+
const result = await withLspClient(filePath, async (client) => client.prepareRename(filePath, line, character), "prepareRename", clientOptions(signal));
|
|
2860
|
+
const details = { filePath, line, character, result };
|
|
2861
|
+
return text(formatPrepareRenameResult(result), details);
|
|
2862
|
+
} catch (error) {
|
|
2863
|
+
const missingDependency = missingDependencyResult(error, {
|
|
2864
|
+
filePath,
|
|
2865
|
+
line,
|
|
2866
|
+
character,
|
|
2867
|
+
result: null
|
|
2868
|
+
});
|
|
2869
|
+
if (missingDependency)
|
|
2870
|
+
return missingDependency;
|
|
2871
|
+
throw error;
|
|
2872
|
+
}
|
|
2873
|
+
}
|
|
2874
|
+
async function executeLspRename(params, signal) {
|
|
2875
|
+
const filePath = requireString(params, "filePath");
|
|
2876
|
+
const line = requireNumber(params, "line");
|
|
2877
|
+
const character = requireNumber(params, "character");
|
|
2878
|
+
const newName = requireString(params, "newName");
|
|
2879
|
+
try {
|
|
2880
|
+
const edit = await withLspClient(filePath, async (client, workspaceRoot) => ({
|
|
2881
|
+
edit: await client.rename(filePath, line, character, newName),
|
|
2882
|
+
workspaceRoot
|
|
2883
|
+
}), "rename", clientOptions(signal));
|
|
2884
|
+
const apply = applyWorkspaceEdit(edit.edit, { workspaceRoot: edit.workspaceRoot });
|
|
2885
|
+
const details = { filePath, line, character, newName, apply, edit: edit.edit };
|
|
2886
|
+
return text(formatApplyResult(apply), details, !apply.success);
|
|
2887
|
+
} catch (error) {
|
|
2888
|
+
const missingDependency = missingDependencyResult(error, {
|
|
2889
|
+
filePath,
|
|
2890
|
+
line,
|
|
2891
|
+
character,
|
|
2892
|
+
newName,
|
|
2893
|
+
apply: null,
|
|
2894
|
+
edit: null
|
|
2895
|
+
});
|
|
2896
|
+
if (missingDependency)
|
|
2897
|
+
return missingDependency;
|
|
2898
|
+
throw error;
|
|
2899
|
+
}
|
|
2900
|
+
}
|
|
2901
|
+
async function executeLspInstallDecision(params) {
|
|
2902
|
+
const serverId = requireString(params, "server_id");
|
|
2903
|
+
const decision = params["decision"];
|
|
2904
|
+
if (!isInstallDecision(decision)) {
|
|
2905
|
+
return text(`Invalid decision '${String(decision)}'. Expected "declined" or "allowed".`, { serverId, errorKind: "invalid_decision" }, true);
|
|
2906
|
+
}
|
|
2907
|
+
const serverIds = [...new Set(getMergedServers().map((server) => server.id))];
|
|
2908
|
+
if (!serverIds.includes(serverId)) {
|
|
2909
|
+
const preview = serverIds.slice(0, 20).join(", ");
|
|
2910
|
+
return text(`Unknown LSP server '${serverId}'. Known servers: ${preview}${serverIds.length > 20 ? "..." : ""}`, { serverId, errorKind: "unknown_server" }, true);
|
|
2911
|
+
}
|
|
2912
|
+
recordInstallDecision(serverId, decision);
|
|
2913
|
+
return text(`Recorded install decision for '${serverId}': ${decision}. ${decisionFollowUp(decision)}`, {
|
|
2914
|
+
serverId,
|
|
2915
|
+
decision
|
|
2916
|
+
});
|
|
2917
|
+
}
|
|
2918
|
+
function decisionFollowUp(decision) {
|
|
2919
|
+
return decision === "declined" ? "Future LSP lookups for this server stay quiet; proceed without LSP." : "Future LSP lookups keep install instructions without asking the user.";
|
|
2920
|
+
}
|
|
2921
|
+
async function executeLspTool(name, params, signal) {
|
|
2922
|
+
const tool = LSP_MCP_TOOLS.find((candidate) => matchesToolName(candidate, name));
|
|
2923
|
+
if (!tool)
|
|
2924
|
+
throw new Error(`Unknown LSP tool: ${name}`);
|
|
2925
|
+
return tool.execute(params, signal);
|
|
2926
|
+
}
|
|
2927
|
+
function matchesToolName(tool, name) {
|
|
2928
|
+
return tool.name === name || (tool.aliases?.includes(name) ?? false);
|
|
2929
|
+
}
|
|
2930
|
+
function coerceToolArguments(value) {
|
|
2931
|
+
return isRecord4(value) ? value : {};
|
|
2932
|
+
}
|
|
2933
|
+
var LSP_MCP_TOOLS = [
|
|
2934
|
+
{
|
|
2935
|
+
name: "status",
|
|
2936
|
+
aliases: ["lsp_status"],
|
|
2937
|
+
title: "LSP Status",
|
|
2938
|
+
description: "List configured and active LSP servers without starting a new language server.",
|
|
2939
|
+
inputSchema: objectSchema({}),
|
|
2940
|
+
execute: executeLspStatus
|
|
2941
|
+
},
|
|
2942
|
+
{
|
|
2943
|
+
name: "diagnostics",
|
|
2944
|
+
aliases: ["lsp_diagnostics"],
|
|
2945
|
+
title: "LSP Diagnostics",
|
|
2946
|
+
description: "Get errors, warnings, and hints for a source file or directory.",
|
|
2947
|
+
inputSchema: objectSchema({
|
|
2948
|
+
filePath: { type: "string", description: "File or directory path to check." },
|
|
2949
|
+
severity: {
|
|
2950
|
+
type: "string",
|
|
2951
|
+
enum: ["error", "warning", "information", "hint", "all"],
|
|
2952
|
+
description: "Severity filter. Defaults to all."
|
|
2953
|
+
}
|
|
2954
|
+
}, ["filePath"]),
|
|
2955
|
+
execute: executeLspDiagnostics
|
|
2956
|
+
},
|
|
2957
|
+
{
|
|
2958
|
+
name: "goto_definition",
|
|
2959
|
+
aliases: ["lsp_goto_definition"],
|
|
2960
|
+
title: "LSP Goto Definition",
|
|
2961
|
+
description: "Find where a symbol is defined.",
|
|
2962
|
+
inputSchema: objectSchema({
|
|
2963
|
+
filePath: { type: "string", description: "Source file containing the symbol." },
|
|
2964
|
+
line: { type: "number", description: "1-based line number." },
|
|
2965
|
+
character: { type: "number", description: "0-based column." }
|
|
2966
|
+
}, ["filePath", "line", "character"]),
|
|
2967
|
+
execute: executeLspGotoDefinition
|
|
2968
|
+
},
|
|
2969
|
+
{
|
|
2970
|
+
name: "find_references",
|
|
2971
|
+
aliases: ["lsp_find_references"],
|
|
2972
|
+
title: "LSP Find References",
|
|
2973
|
+
description: "Find references of a symbol across the workspace.",
|
|
2974
|
+
inputSchema: objectSchema({
|
|
2975
|
+
filePath: { type: "string", description: "Source file containing the symbol." },
|
|
2976
|
+
line: { type: "number", description: "1-based line number." },
|
|
2977
|
+
character: { type: "number", description: "0-based column." },
|
|
2978
|
+
includeDeclaration: { type: "boolean", description: "Include the declaration. Defaults to true." }
|
|
2979
|
+
}, ["filePath", "line", "character"]),
|
|
2980
|
+
execute: executeLspFindReferences
|
|
2981
|
+
},
|
|
2982
|
+
{
|
|
2983
|
+
name: "symbols",
|
|
2984
|
+
aliases: ["lsp_symbols"],
|
|
2985
|
+
title: "LSP Symbols",
|
|
2986
|
+
description: "List document symbols or search workspace symbols.",
|
|
2987
|
+
inputSchema: objectSchema({
|
|
2988
|
+
filePath: { type: "string", description: "File path used as LSP context." },
|
|
2989
|
+
scope: {
|
|
2990
|
+
type: "string",
|
|
2991
|
+
enum: ["document", "workspace"],
|
|
2992
|
+
description: "Use document for file outline or workspace for project-wide search."
|
|
2993
|
+
},
|
|
2994
|
+
query: { type: "string", description: "Workspace symbol query." },
|
|
2995
|
+
limit: { type: "number", description: "Maximum number of symbols to return." }
|
|
2996
|
+
}, ["filePath", "scope"]),
|
|
2997
|
+
execute: executeLspSymbols
|
|
2998
|
+
},
|
|
2999
|
+
{
|
|
3000
|
+
name: "prepare_rename",
|
|
3001
|
+
aliases: ["lsp_prepare_rename"],
|
|
3002
|
+
title: "LSP Prepare Rename",
|
|
3003
|
+
description: "Check whether a symbol can be renamed at a position.",
|
|
3004
|
+
inputSchema: objectSchema({
|
|
3005
|
+
filePath: { type: "string", description: "Source file path." },
|
|
3006
|
+
line: { type: "number", description: "1-based line number." },
|
|
3007
|
+
character: { type: "number", description: "0-based column." }
|
|
3008
|
+
}, ["filePath", "line", "character"]),
|
|
3009
|
+
execute: executeLspPrepareRename
|
|
3010
|
+
},
|
|
3011
|
+
{
|
|
3012
|
+
name: "rename",
|
|
3013
|
+
aliases: ["lsp_rename"],
|
|
3014
|
+
title: "LSP Rename",
|
|
3015
|
+
description: "Rename a symbol across the workspace and apply the returned workspace edit.",
|
|
3016
|
+
inputSchema: objectSchema({
|
|
3017
|
+
filePath: { type: "string", description: "Source file path." },
|
|
3018
|
+
line: { type: "number", description: "1-based line number." },
|
|
3019
|
+
character: { type: "number", description: "0-based column." },
|
|
3020
|
+
newName: { type: "string", description: "New symbol name." }
|
|
3021
|
+
}, ["filePath", "line", "character", "newName"]),
|
|
3022
|
+
execute: executeLspRename
|
|
3023
|
+
},
|
|
3024
|
+
{
|
|
3025
|
+
name: "install_decision",
|
|
3026
|
+
aliases: ["lsp_install_decision"],
|
|
3027
|
+
title: "LSP Install Decision",
|
|
3028
|
+
description: "Record whether the user allowed or declined installing a missing LSP server. Record 'declined' when the user declines, or has not explicitly asked for LSP installation, to silence future prompts.",
|
|
3029
|
+
inputSchema: objectSchema({
|
|
3030
|
+
server_id: {
|
|
3031
|
+
type: "string",
|
|
3032
|
+
description: "The LSP server id from the not-installed message (e.g. 'rust')."
|
|
3033
|
+
},
|
|
3034
|
+
decision: {
|
|
3035
|
+
type: "string",
|
|
3036
|
+
enum: ["declined", "allowed"],
|
|
3037
|
+
description: "'declined' silences future prompts; 'allowed' pre-authorizes installation."
|
|
3038
|
+
}
|
|
3039
|
+
}, ["server_id", "decision"]),
|
|
3040
|
+
execute: executeLspInstallDecision
|
|
3041
|
+
}
|
|
3042
|
+
];
|
|
3043
|
+
|
|
3044
|
+
// ../lsp-tools-mcp/dist/mcp.js
|
|
3045
|
+
var SERVER_NAME = "lsp";
|
|
3046
|
+
var SERVER_VERSION = "0.1.0";
|
|
3047
|
+
async function handleLspMcpRequest(input) {
|
|
3048
|
+
if (!isRecord5(input)) {
|
|
3049
|
+
return errorResponse(null, -32600, "Invalid Request");
|
|
3050
|
+
}
|
|
3051
|
+
const id = jsonRpcId(input["id"]);
|
|
3052
|
+
const method = input["method"];
|
|
3053
|
+
if (method === "notifications/initialized")
|
|
3054
|
+
return;
|
|
3055
|
+
if (method === "ping")
|
|
3056
|
+
return successResponse(id, {});
|
|
3057
|
+
if (method === "initialize") {
|
|
3058
|
+
const protocolVersion = requestedProtocolVersion(input["params"]);
|
|
3059
|
+
return successResponse(id, {
|
|
3060
|
+
capabilities: { tools: { listChanged: false } },
|
|
3061
|
+
serverInfo: { name: SERVER_NAME, version: SERVER_VERSION },
|
|
3062
|
+
protocolVersion
|
|
3063
|
+
});
|
|
3064
|
+
}
|
|
3065
|
+
if (method === "tools/list") {
|
|
3066
|
+
return successResponse(id, { tools: LSP_MCP_TOOLS.map(describeTool) });
|
|
3067
|
+
}
|
|
3068
|
+
if (method === "tools/call") {
|
|
3069
|
+
return handleToolCall(id, input["params"]);
|
|
3070
|
+
}
|
|
3071
|
+
return errorResponse(id, -32601, `Method not found: ${String(method)}`);
|
|
3072
|
+
}
|
|
3073
|
+
async function handleToolCall(id, params) {
|
|
3074
|
+
if (!isRecord5(params) || typeof params["name"] !== "string") {
|
|
3075
|
+
return errorResponse(id, -32602, "tools/call requires params.name");
|
|
3076
|
+
}
|
|
3077
|
+
try {
|
|
3078
|
+
const result = await executeLspTool(params["name"], coerceToolArguments(params["arguments"]));
|
|
3079
|
+
return successResponse(id, {
|
|
3080
|
+
content: result.content,
|
|
3081
|
+
isError: result.isError ?? false,
|
|
3082
|
+
details: result.details
|
|
3083
|
+
});
|
|
3084
|
+
} catch (error) {
|
|
3085
|
+
return successResponse(id, {
|
|
3086
|
+
content: [{ type: "text", text: messageFromError(error) }],
|
|
3087
|
+
isError: true
|
|
3088
|
+
});
|
|
3089
|
+
}
|
|
3090
|
+
}
|
|
3091
|
+
function describeTool(tool) {
|
|
3092
|
+
return {
|
|
3093
|
+
name: tool.name,
|
|
3094
|
+
title: tool.title,
|
|
3095
|
+
description: tool.description,
|
|
3096
|
+
inputSchema: tool.inputSchema
|
|
3097
|
+
};
|
|
3098
|
+
}
|
|
3099
|
+
function successResponse(id, result) {
|
|
3100
|
+
return { jsonrpc: "2.0", id, result };
|
|
3101
|
+
}
|
|
3102
|
+
function errorResponse(id, code, message, data) {
|
|
3103
|
+
return { jsonrpc: "2.0", id, error: data === undefined ? { code, message } : { code, message, data } };
|
|
3104
|
+
}
|
|
3105
|
+
function requestedProtocolVersion(params) {
|
|
3106
|
+
if (!isRecord5(params) || typeof params["protocolVersion"] !== "string")
|
|
3107
|
+
return "2024-11-05";
|
|
3108
|
+
return params["protocolVersion"];
|
|
3109
|
+
}
|
|
3110
|
+
function jsonRpcId(value) {
|
|
3111
|
+
return typeof value === "string" || typeof value === "number" || value === null ? value : null;
|
|
3112
|
+
}
|
|
3113
|
+
function isRecord5(value) {
|
|
3114
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3115
|
+
}
|
|
3116
|
+
function messageFromError(error) {
|
|
3117
|
+
return error instanceof Error ? error.message : String(error);
|
|
3118
|
+
}
|
|
3119
|
+
|
|
3120
|
+
// src/daemon-client.ts
|
|
3121
|
+
import { connect as connect2 } from "node:net";
|
|
3122
|
+
|
|
3123
|
+
// src/ensure-daemon.ts
|
|
3124
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
3125
|
+
import { closeSync as closeSync2, existsSync as existsSync8, mkdirSync as mkdirSync3, openSync as openSync2 } from "node:fs";
|
|
3126
|
+
import { connect } from "node:net";
|
|
3127
|
+
import { dirname as dirname5 } from "node:path";
|
|
3128
|
+
import { execPath } from "node:process";
|
|
3129
|
+
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
3130
|
+
|
|
3131
|
+
// src/lock.ts
|
|
3132
|
+
import { closeSync, mkdirSync as mkdirSync2, openSync, readFileSync as readFileSync5, unlinkSync as unlinkSync2, writeSync } from "node:fs";
|
|
3133
|
+
import { dirname as dirname4 } from "node:path";
|
|
3134
|
+
function isProcessAlive(pid) {
|
|
3135
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
3136
|
+
return false;
|
|
3137
|
+
try {
|
|
3138
|
+
process.kill(pid, 0);
|
|
3139
|
+
return true;
|
|
3140
|
+
} catch (error) {
|
|
3141
|
+
return error.code === "EPERM";
|
|
3142
|
+
}
|
|
3143
|
+
}
|
|
3144
|
+
function readLockPid(lockPath) {
|
|
3145
|
+
try {
|
|
3146
|
+
const pid = Number.parseInt(readFileSync5(lockPath, "utf8").trim(), 10);
|
|
3147
|
+
return Number.isInteger(pid) ? pid : null;
|
|
3148
|
+
} catch {
|
|
3149
|
+
return null;
|
|
3150
|
+
}
|
|
3151
|
+
}
|
|
3152
|
+
function tryAcquireLock(lockPath, ownerPid = process.pid) {
|
|
3153
|
+
mkdirSync2(dirname4(lockPath), { recursive: true });
|
|
3154
|
+
for (let attempt = 0;attempt < 2; attempt += 1) {
|
|
3155
|
+
const handle = writeLockFile(lockPath, ownerPid);
|
|
3156
|
+
if (handle)
|
|
3157
|
+
return handle;
|
|
3158
|
+
if (!reapStaleLock(lockPath))
|
|
3159
|
+
return null;
|
|
3160
|
+
}
|
|
3161
|
+
return null;
|
|
3162
|
+
}
|
|
3163
|
+
function writeLockFile(lockPath, ownerPid) {
|
|
3164
|
+
try {
|
|
3165
|
+
const fd = openSync(lockPath, "wx");
|
|
3166
|
+
writeSync(fd, `${ownerPid}
|
|
3167
|
+
`);
|
|
3168
|
+
closeSync(fd);
|
|
3169
|
+
return { release: () => unlinkQuietly(lockPath) };
|
|
3170
|
+
} catch (error) {
|
|
3171
|
+
if (error.code === "EEXIST")
|
|
3172
|
+
return null;
|
|
3173
|
+
throw error;
|
|
3174
|
+
}
|
|
3175
|
+
}
|
|
3176
|
+
function reapStaleLock(lockPath) {
|
|
3177
|
+
const pid = readLockPid(lockPath);
|
|
3178
|
+
if (pid !== null && isProcessAlive(pid))
|
|
3179
|
+
return false;
|
|
3180
|
+
unlinkQuietly(lockPath);
|
|
3181
|
+
return true;
|
|
3182
|
+
}
|
|
3183
|
+
function unlinkQuietly(path) {
|
|
3184
|
+
try {
|
|
3185
|
+
unlinkSync2(path);
|
|
3186
|
+
} catch (error) {}
|
|
3187
|
+
}
|
|
3188
|
+
|
|
3189
|
+
// src/ensure-daemon.ts
|
|
3190
|
+
var PROBE_TIMEOUT_MS = 500;
|
|
3191
|
+
var DEFAULT_READY_TIMEOUT_MS = 5000;
|
|
3192
|
+
var DEFAULT_POLL_INTERVAL_MS = 100;
|
|
3193
|
+
|
|
3194
|
+
class DaemonUnreachableError extends Error {
|
|
3195
|
+
constructor(socketPath) {
|
|
3196
|
+
super(`LSP daemon did not become reachable at ${socketPath}`);
|
|
3197
|
+
this.name = "DaemonUnreachableError";
|
|
3198
|
+
}
|
|
3199
|
+
}
|
|
3200
|
+
async function ensureDaemonRunning(paths, deps = defaultEnsureDaemonDeps(), options = {}) {
|
|
3201
|
+
const readyTimeoutMs = options.readyTimeoutMs ?? DEFAULT_READY_TIMEOUT_MS;
|
|
3202
|
+
const pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
3203
|
+
if (await deps.probe(paths.socket))
|
|
3204
|
+
return;
|
|
3205
|
+
const lock = deps.acquireLock(paths.lock);
|
|
3206
|
+
if (!lock) {
|
|
3207
|
+
await waitUntilReachable(paths.socket, deps, readyTimeoutMs, pollIntervalMs);
|
|
3208
|
+
return;
|
|
3209
|
+
}
|
|
3210
|
+
try {
|
|
3211
|
+
if (await deps.probe(paths.socket))
|
|
3212
|
+
return;
|
|
3213
|
+
deps.cleanupStaleSocket(paths.socket);
|
|
3214
|
+
deps.spawnDaemon(paths);
|
|
3215
|
+
await waitUntilReachable(paths.socket, deps, readyTimeoutMs, pollIntervalMs);
|
|
3216
|
+
} finally {
|
|
3217
|
+
lock.release();
|
|
3218
|
+
}
|
|
3219
|
+
}
|
|
3220
|
+
async function waitUntilReachable(socketPath, deps, readyTimeoutMs, pollIntervalMs) {
|
|
3221
|
+
const deadline = deps.now() + readyTimeoutMs;
|
|
3222
|
+
for (;; ) {
|
|
3223
|
+
if (await deps.probe(socketPath))
|
|
3224
|
+
return;
|
|
3225
|
+
if (deps.now() >= deadline)
|
|
3226
|
+
throw new DaemonUnreachableError(socketPath);
|
|
3227
|
+
await deps.sleep(pollIntervalMs);
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
3230
|
+
function probeSocket(socketPath, timeoutMs = PROBE_TIMEOUT_MS) {
|
|
3231
|
+
return new Promise((resolve6) => {
|
|
3232
|
+
const socket = connect(socketPath);
|
|
3233
|
+
const finish = (ok) => {
|
|
3234
|
+
socket.destroy();
|
|
3235
|
+
resolve6(ok);
|
|
3236
|
+
};
|
|
3237
|
+
const timer = setTimeout(() => finish(false), timeoutMs);
|
|
3238
|
+
timer.unref?.();
|
|
3239
|
+
socket.once("connect", () => {
|
|
3240
|
+
clearTimeout(timer);
|
|
3241
|
+
finish(true);
|
|
3242
|
+
});
|
|
3243
|
+
socket.once("error", () => {
|
|
3244
|
+
clearTimeout(timer);
|
|
3245
|
+
finish(false);
|
|
3246
|
+
});
|
|
3247
|
+
});
|
|
3248
|
+
}
|
|
3249
|
+
function spawnDaemonProcess(paths) {
|
|
3250
|
+
mkdirSync3(dirname5(paths.log), { recursive: true });
|
|
3251
|
+
const logFd = openSync2(paths.log, "a");
|
|
3252
|
+
try {
|
|
3253
|
+
const cliPath = fileURLToPath3(new URL("./cli.js", import.meta.url));
|
|
3254
|
+
const child = spawn2(execPath, [cliPath, "daemon"], {
|
|
3255
|
+
detached: true,
|
|
3256
|
+
stdio: ["ignore", logFd, logFd]
|
|
3257
|
+
});
|
|
3258
|
+
child.unref();
|
|
3259
|
+
} finally {
|
|
3260
|
+
closeSync2(logFd);
|
|
3261
|
+
}
|
|
3262
|
+
}
|
|
3263
|
+
function defaultEnsureDaemonDeps() {
|
|
3264
|
+
return {
|
|
3265
|
+
probe: (socketPath) => probeSocket(socketPath),
|
|
3266
|
+
acquireLock: (lockPath) => tryAcquireLock(lockPath),
|
|
3267
|
+
cleanupStaleSocket: (socketPath) => {
|
|
3268
|
+
if (existsSync8(socketPath))
|
|
3269
|
+
unlinkQuietly(socketPath);
|
|
3270
|
+
},
|
|
3271
|
+
spawnDaemon: (paths) => spawnDaemonProcess(paths),
|
|
3272
|
+
sleep: (ms) => new Promise((resolve6) => {
|
|
3273
|
+
const timer = setTimeout(resolve6, ms);
|
|
3274
|
+
timer.unref?.();
|
|
3275
|
+
}),
|
|
3276
|
+
now: () => Date.now()
|
|
3277
|
+
};
|
|
3278
|
+
}
|
|
3279
|
+
|
|
3280
|
+
// src/paths.ts
|
|
3281
|
+
import { createHash } from "node:crypto";
|
|
3282
|
+
import { createRequire } from "node:module";
|
|
3283
|
+
import { homedir as homedir3, tmpdir } from "node:os";
|
|
3284
|
+
import { join as join8 } from "node:path";
|
|
3285
|
+
var requireFromHere = createRequire(import.meta.url);
|
|
3286
|
+
var MAX_SOCKET_PATH_LENGTH = 100;
|
|
3287
|
+
function resolveDaemonVersion(requireFn = requireFromHere) {
|
|
3288
|
+
for (const candidate of ["./package.json", "../package.json"]) {
|
|
3289
|
+
try {
|
|
3290
|
+
const pkg = requireFn(candidate);
|
|
3291
|
+
if (typeof pkg.version === "string" && pkg.version.length > 0)
|
|
3292
|
+
return pkg.version;
|
|
3293
|
+
} catch {}
|
|
3294
|
+
}
|
|
3295
|
+
return "0";
|
|
3296
|
+
}
|
|
3297
|
+
function daemonBaseDir(env = process.env) {
|
|
3298
|
+
const explicit = env["CODEX_LSP_DAEMON_DIR"]?.trim();
|
|
3299
|
+
if (explicit)
|
|
3300
|
+
return explicit;
|
|
3301
|
+
const pluginData = env["PLUGIN_DATA"]?.trim();
|
|
3302
|
+
if (pluginData)
|
|
3303
|
+
return join8(pluginData, "daemon");
|
|
3304
|
+
const codexHome = env["CODEX_HOME"]?.trim();
|
|
3305
|
+
const home = codexHome && codexHome.length > 0 ? codexHome : join8(homedir3(), ".codex");
|
|
3306
|
+
return join8(home, "codex-lsp", "daemon");
|
|
3307
|
+
}
|
|
3308
|
+
function daemonPaths(env = process.env, version = resolveDaemonVersion()) {
|
|
3309
|
+
const dir = join8(daemonBaseDir(env), `v${version}`);
|
|
3310
|
+
return {
|
|
3311
|
+
version,
|
|
3312
|
+
dir,
|
|
3313
|
+
socket: resolveSocketPath(dir, version),
|
|
3314
|
+
lock: join8(dir, "daemon.lock"),
|
|
3315
|
+
pid: join8(dir, "daemon.pid"),
|
|
3316
|
+
log: join8(dir, "daemon.log")
|
|
3317
|
+
};
|
|
3318
|
+
}
|
|
3319
|
+
function resolveSocketPath(dir, version) {
|
|
3320
|
+
const digest = createHash("sha256").update(dir).digest("hex").slice(0, 16);
|
|
3321
|
+
if (process.platform === "win32") {
|
|
3322
|
+
return `\\\\.\\pipe\\omo-lsp-${version}-${digest}`;
|
|
3323
|
+
}
|
|
3324
|
+
const natural = join8(dir, "daemon.sock");
|
|
3325
|
+
if (natural.length < MAX_SOCKET_PATH_LENGTH)
|
|
3326
|
+
return natural;
|
|
3327
|
+
return join8(tmpdir(), `omo-lsp-${version}-${digest}.sock`);
|
|
3328
|
+
}
|
|
3329
|
+
|
|
3330
|
+
// src/request-routing.ts
|
|
3331
|
+
var CONTEXT_KEY = "_context";
|
|
3332
|
+
function extractRequestContext(raw) {
|
|
3333
|
+
if (!isRecord6(raw) || raw["method"] !== "tools/call")
|
|
3334
|
+
return { input: raw, context: undefined };
|
|
3335
|
+
const params = raw["params"];
|
|
3336
|
+
if (!isRecord6(params))
|
|
3337
|
+
return { input: raw, context: undefined };
|
|
3338
|
+
const args = params["arguments"];
|
|
3339
|
+
if (!isRecord6(args))
|
|
3340
|
+
return { input: raw, context: undefined };
|
|
3341
|
+
const context = parseContext(args[CONTEXT_KEY]);
|
|
3342
|
+
if (!context)
|
|
3343
|
+
return { input: raw, context: undefined };
|
|
3344
|
+
const cleanedArgs = { ...args };
|
|
3345
|
+
delete cleanedArgs[CONTEXT_KEY];
|
|
3346
|
+
const cleaned = { ...raw, params: { ...params, arguments: cleanedArgs } };
|
|
3347
|
+
return { input: cleaned, context };
|
|
3348
|
+
}
|
|
3349
|
+
function handleDaemonMessage(raw) {
|
|
3350
|
+
const { input, context } = extractRequestContext(raw);
|
|
3351
|
+
if (context)
|
|
3352
|
+
return runWithRequestContext(context, () => handleLspMcpRequest(input));
|
|
3353
|
+
return handleLspMcpRequest(input);
|
|
3354
|
+
}
|
|
3355
|
+
function parseContext(value) {
|
|
3356
|
+
if (!isRecord6(value))
|
|
3357
|
+
return;
|
|
3358
|
+
const context = {};
|
|
3359
|
+
const cwd = value["cwd"];
|
|
3360
|
+
if (typeof cwd === "string")
|
|
3361
|
+
context.cwd = cwd;
|
|
3362
|
+
const env = value["env"];
|
|
3363
|
+
if (isStringRecord2(env))
|
|
3364
|
+
context.env = env;
|
|
3365
|
+
return context.cwd === undefined && context.env === undefined ? undefined : context;
|
|
3366
|
+
}
|
|
3367
|
+
function isRecord6(value) {
|
|
3368
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3369
|
+
}
|
|
3370
|
+
function isStringRecord2(value) {
|
|
3371
|
+
return isRecord6(value) && Object.values(value).every((item) => typeof item === "string");
|
|
3372
|
+
}
|
|
3373
|
+
|
|
3374
|
+
// src/socket-jsonrpc.ts
|
|
3375
|
+
function encodeJsonLine(message) {
|
|
3376
|
+
return `${JSON.stringify(message)}
|
|
3377
|
+
`;
|
|
3378
|
+
}
|
|
3379
|
+
function createLineDecoder(onMessage, onParseError) {
|
|
3380
|
+
let buffer = "";
|
|
3381
|
+
return {
|
|
3382
|
+
push(chunk) {
|
|
3383
|
+
buffer += typeof chunk === "string" ? chunk : chunk.toString("utf8");
|
|
3384
|
+
let index = buffer.indexOf(`
|
|
3385
|
+
`);
|
|
3386
|
+
while (index !== -1) {
|
|
3387
|
+
const raw = buffer.slice(0, index).trim();
|
|
3388
|
+
buffer = buffer.slice(index + 1);
|
|
3389
|
+
if (raw.length > 0) {
|
|
3390
|
+
try {
|
|
3391
|
+
onMessage(JSON.parse(raw));
|
|
3392
|
+
} catch (error) {
|
|
3393
|
+
onParseError?.(raw, error);
|
|
3394
|
+
}
|
|
3395
|
+
}
|
|
3396
|
+
index = buffer.indexOf(`
|
|
3397
|
+
`);
|
|
3398
|
+
}
|
|
3399
|
+
}
|
|
3400
|
+
};
|
|
3401
|
+
}
|
|
3402
|
+
|
|
3403
|
+
// src/daemon-client.ts
|
|
3404
|
+
var DEFAULT_REQUEST_TIMEOUT_MS = 30000;
|
|
3405
|
+
var REQUEST_ID = 1;
|
|
3406
|
+
|
|
3407
|
+
class DaemonRequestError extends Error {
|
|
3408
|
+
requestWritten;
|
|
3409
|
+
constructor(message, requestWritten) {
|
|
3410
|
+
super(message);
|
|
3411
|
+
this.name = "DaemonRequestError";
|
|
3412
|
+
this.requestWritten = requestWritten;
|
|
3413
|
+
}
|
|
3414
|
+
}
|
|
3415
|
+
async function callToolViaDaemon(name, args, options = {}) {
|
|
3416
|
+
const paths = options.paths ?? daemonPaths();
|
|
3417
|
+
const ensure = options.ensure ?? ensureDaemonRunning;
|
|
3418
|
+
const timeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
3419
|
+
const requestArgs = withContext(args, options.context);
|
|
3420
|
+
let lastError;
|
|
3421
|
+
for (let attempt = 0;attempt < 2; attempt += 1) {
|
|
3422
|
+
try {
|
|
3423
|
+
await ensure(paths);
|
|
3424
|
+
return await sendToolCall(paths.socket, name, requestArgs, timeoutMs);
|
|
3425
|
+
} catch (error) {
|
|
3426
|
+
lastError = error;
|
|
3427
|
+
if (error instanceof DaemonRequestError && error.requestWritten)
|
|
3428
|
+
break;
|
|
3429
|
+
}
|
|
3430
|
+
}
|
|
3431
|
+
return daemonUnreachableResult(paths, lastError);
|
|
3432
|
+
}
|
|
3433
|
+
function callDiagnosticsViaDaemon(filePath, options = {}) {
|
|
3434
|
+
return callToolViaDaemon("diagnostics", { filePath, severity: "error" }, options);
|
|
3435
|
+
}
|
|
3436
|
+
var FORWARDED_ENV_KEYS = [
|
|
3437
|
+
"LSP_TOOLS_MCP_PROJECT_CONFIG",
|
|
3438
|
+
"LSP_TOOLS_MCP_USER_CONFIG",
|
|
3439
|
+
"LSP_TOOLS_MCP_INSTALL_DECISIONS"
|
|
3440
|
+
];
|
|
3441
|
+
function currentRequestContext(env = process.env) {
|
|
3442
|
+
const forwarded = {};
|
|
3443
|
+
for (const key of FORWARDED_ENV_KEYS) {
|
|
3444
|
+
const value = env[key];
|
|
3445
|
+
if (value !== undefined)
|
|
3446
|
+
forwarded[key] = value;
|
|
3447
|
+
}
|
|
3448
|
+
return { cwd: process.cwd(), env: forwarded };
|
|
3449
|
+
}
|
|
3450
|
+
function withContext(args, context) {
|
|
3451
|
+
if (!context || context.cwd === undefined && context.env === undefined)
|
|
3452
|
+
return args;
|
|
3453
|
+
return { ...args, [CONTEXT_KEY]: context };
|
|
3454
|
+
}
|
|
3455
|
+
function daemonUnreachableResult(paths, error) {
|
|
3456
|
+
const text2 = [
|
|
3457
|
+
`LSP daemon unreachable: ${errorText(error)}.`,
|
|
3458
|
+
"The MCP server is a thin proxy and never runs language servers in-process.",
|
|
3459
|
+
`Socket: ${paths.socket}`,
|
|
3460
|
+
`Logs: ${paths.log}`,
|
|
3461
|
+
"The daemon is auto-started on demand and will be retried on the next request."
|
|
3462
|
+
].join(`
|
|
3463
|
+
`);
|
|
3464
|
+
return { content: [{ type: "text", text: text2 }], isError: true };
|
|
3465
|
+
}
|
|
3466
|
+
function sendToolCall(socketPath, name, args, timeoutMs) {
|
|
3467
|
+
return new Promise((resolve6, reject) => {
|
|
3468
|
+
const socket = connect2(socketPath);
|
|
3469
|
+
let settled = false;
|
|
3470
|
+
let requestWritten = false;
|
|
3471
|
+
const finish = (run) => {
|
|
3472
|
+
if (settled)
|
|
3473
|
+
return;
|
|
3474
|
+
settled = true;
|
|
3475
|
+
clearTimeout(timer);
|
|
3476
|
+
socket.destroy();
|
|
3477
|
+
run();
|
|
3478
|
+
};
|
|
3479
|
+
const timer = setTimeout(() => finish(() => reject(new DaemonRequestError("daemon request timed out", requestWritten))), timeoutMs);
|
|
3480
|
+
timer.unref();
|
|
3481
|
+
const decoder = createLineDecoder((message) => {
|
|
3482
|
+
const result = toToolResult(message);
|
|
3483
|
+
if (result)
|
|
3484
|
+
finish(() => resolve6(result));
|
|
3485
|
+
else
|
|
3486
|
+
finish(() => reject(new DaemonRequestError("invalid daemon response", requestWritten)));
|
|
3487
|
+
});
|
|
3488
|
+
socket.once("connect", () => {
|
|
3489
|
+
requestWritten = true;
|
|
3490
|
+
socket.write(encodeJsonLine({ jsonrpc: "2.0", id: REQUEST_ID, method: "tools/call", params: { name, arguments: args } }));
|
|
3491
|
+
});
|
|
3492
|
+
socket.on("data", (chunk) => decoder.push(chunk));
|
|
3493
|
+
socket.once("error", (error) => finish(() => reject(new DaemonRequestError(error.message, requestWritten))));
|
|
3494
|
+
socket.once("close", () => finish(() => reject(new DaemonRequestError("daemon connection closed", requestWritten))));
|
|
3495
|
+
});
|
|
3496
|
+
}
|
|
3497
|
+
function toToolResult(message) {
|
|
3498
|
+
if (!isRecord7(message) || message["id"] !== REQUEST_ID)
|
|
3499
|
+
return null;
|
|
3500
|
+
const result = message["result"];
|
|
3501
|
+
if (!isRecord7(result) || !Array.isArray(result["content"]))
|
|
3502
|
+
return null;
|
|
3503
|
+
return {
|
|
3504
|
+
content: result["content"],
|
|
3505
|
+
isError: result["isError"] === true,
|
|
3506
|
+
details: result["details"]
|
|
3507
|
+
};
|
|
3508
|
+
}
|
|
3509
|
+
function isRecord7(value) {
|
|
3510
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3511
|
+
}
|
|
3512
|
+
function errorText(error) {
|
|
3513
|
+
return error instanceof Error ? error.message : String(error);
|
|
3514
|
+
}
|
|
3515
|
+
|
|
3516
|
+
// src/proxy.ts
|
|
3517
|
+
async function runMcpStdioProxy(options = {}) {
|
|
3518
|
+
const input = options.input ?? process.stdin;
|
|
3519
|
+
const output = options.output ?? process.stdout;
|
|
3520
|
+
const paths = options.paths ?? daemonPaths();
|
|
3521
|
+
const context = options.context ?? currentRequestContext();
|
|
3522
|
+
const callOptions = { paths, context, ...options.ensure ? { ensure: options.ensure } : {} };
|
|
3523
|
+
const lines = createInterface({ input, crlfDelay: Number.POSITIVE_INFINITY });
|
|
3524
|
+
for await (const line of lines) {
|
|
3525
|
+
if (!line.trim())
|
|
3526
|
+
continue;
|
|
3527
|
+
try {
|
|
3528
|
+
const response = await handleLine(line, callOptions);
|
|
3529
|
+
if (response)
|
|
3530
|
+
output.write(`${JSON.stringify(response)}
|
|
3531
|
+
`);
|
|
3532
|
+
} catch (error) {
|
|
3533
|
+
process.stderr.write(`[lsp-daemon] proxy error: ${error instanceof Error ? error.message : String(error)}
|
|
3534
|
+
`);
|
|
3535
|
+
}
|
|
3536
|
+
}
|
|
3537
|
+
}
|
|
3538
|
+
async function handleLine(line, callOptions) {
|
|
3539
|
+
let parsed;
|
|
3540
|
+
try {
|
|
3541
|
+
parsed = JSON.parse(line);
|
|
3542
|
+
} catch (error) {
|
|
3543
|
+
return parseErrorResponse(error);
|
|
3544
|
+
}
|
|
3545
|
+
const toolCall = asToolCall(parsed);
|
|
3546
|
+
if (!toolCall)
|
|
3547
|
+
return handleLspMcpRequest(parsed);
|
|
3548
|
+
const result = await callToolViaDaemon(toolCall.name, toolCall.args, callOptions);
|
|
3549
|
+
return {
|
|
3550
|
+
jsonrpc: "2.0",
|
|
3551
|
+
id: toolCall.id,
|
|
3552
|
+
result: { content: result.content, isError: result.isError ?? false, details: result.details }
|
|
3553
|
+
};
|
|
3554
|
+
}
|
|
3555
|
+
function asToolCall(parsed) {
|
|
3556
|
+
if (!isRecord8(parsed) || parsed["method"] !== "tools/call")
|
|
3557
|
+
return null;
|
|
3558
|
+
const params = parsed["params"];
|
|
3559
|
+
if (!isRecord8(params) || typeof params["name"] !== "string")
|
|
3560
|
+
return null;
|
|
3561
|
+
const args = params["arguments"];
|
|
3562
|
+
return { id: jsonRpcId2(parsed["id"]), name: params["name"], args: isRecord8(args) ? args : {} };
|
|
3563
|
+
}
|
|
3564
|
+
function jsonRpcId2(value) {
|
|
3565
|
+
return typeof value === "string" || typeof value === "number" || value === null ? value : null;
|
|
3566
|
+
}
|
|
3567
|
+
function parseErrorResponse(error) {
|
|
3568
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3569
|
+
return { jsonrpc: "2.0", id: null, error: { code: -32700, message: "Parse error", data: message } };
|
|
3570
|
+
}
|
|
3571
|
+
function isRecord8(value) {
|
|
3572
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3573
|
+
}
|
|
3574
|
+
|
|
3575
|
+
// src/daemon-server.ts
|
|
3576
|
+
import { mkdirSync as mkdirSync4, writeFileSync as writeFileSync3 } from "node:fs";
|
|
3577
|
+
import { createServer as createServer2 } from "node:net";
|
|
3578
|
+
import { join as join9 } from "node:path";
|
|
3579
|
+
var DEFAULT_IDLE_SHUTDOWN_MS = 30 * 60000;
|
|
3580
|
+
var DEFAULT_IDLE_CHECK_INTERVAL_MS = 60000;
|
|
3581
|
+
async function startDaemonServer(paths, options = {}) {
|
|
3582
|
+
const idleShutdownMs = options.idleShutdownMs ?? DEFAULT_IDLE_SHUTDOWN_MS;
|
|
3583
|
+
const idleCheckIntervalMs = options.idleCheckIntervalMs ?? DEFAULT_IDLE_CHECK_INTERVAL_MS;
|
|
3584
|
+
mkdirSync4(paths.dir, { recursive: true });
|
|
3585
|
+
unlinkQuietly(paths.socket);
|
|
3586
|
+
const connections = new Set;
|
|
3587
|
+
let lastActiveAt = Date.now();
|
|
3588
|
+
const touch = () => {
|
|
3589
|
+
lastActiveAt = Date.now();
|
|
3590
|
+
};
|
|
3591
|
+
const server = createServer2((socket) => {
|
|
3592
|
+
connections.add(socket);
|
|
3593
|
+
touch();
|
|
3594
|
+
const decoder = createLineDecoder((message) => {
|
|
3595
|
+
touch();
|
|
3596
|
+
respond(socket, message);
|
|
3597
|
+
});
|
|
3598
|
+
socket.on("data", (chunk) => decoder.push(chunk));
|
|
3599
|
+
socket.on("error", () => socket.destroy());
|
|
3600
|
+
socket.on("close", () => {
|
|
3601
|
+
connections.delete(socket);
|
|
3602
|
+
touch();
|
|
3603
|
+
});
|
|
3604
|
+
});
|
|
3605
|
+
server.on("error", (error) => logServerError(error));
|
|
3606
|
+
const endpointPath = join9(paths.dir, "daemon.endpoint");
|
|
3607
|
+
await listen(server, paths.socket);
|
|
3608
|
+
writeFileSync3(paths.pid, `${process.pid}
|
|
3609
|
+
`);
|
|
3610
|
+
writeFileSync3(endpointPath, paths.socket);
|
|
3611
|
+
let closed = false;
|
|
3612
|
+
const close = async () => {
|
|
3613
|
+
if (closed)
|
|
3614
|
+
return;
|
|
3615
|
+
closed = true;
|
|
3616
|
+
clearInterval(idleTimer);
|
|
3617
|
+
for (const socket of connections)
|
|
3618
|
+
socket.destroy();
|
|
3619
|
+
connections.clear();
|
|
3620
|
+
await closeServer(server);
|
|
3621
|
+
unlinkQuietly(paths.socket);
|
|
3622
|
+
unlinkQuietly(paths.pid);
|
|
3623
|
+
unlinkQuietly(endpointPath);
|
|
3624
|
+
await disposeDefaultLspManager();
|
|
3625
|
+
};
|
|
3626
|
+
const idleTimer = setInterval(() => {
|
|
3627
|
+
if (connections.size > 0)
|
|
3628
|
+
return;
|
|
3629
|
+
if (getLspManager().clientCount() > 0) {
|
|
3630
|
+
touch();
|
|
3631
|
+
return;
|
|
3632
|
+
}
|
|
3633
|
+
if (Date.now() - lastActiveAt < idleShutdownMs)
|
|
3634
|
+
return;
|
|
3635
|
+
if (options.onIdleShutdown) {
|
|
3636
|
+
options.onIdleShutdown();
|
|
3637
|
+
return;
|
|
3638
|
+
}
|
|
3639
|
+
close().then(() => process.exit(0));
|
|
3640
|
+
}, idleCheckIntervalMs);
|
|
3641
|
+
idleTimer.unref();
|
|
3642
|
+
installSignalHandlers(close);
|
|
3643
|
+
return { server, close };
|
|
3644
|
+
}
|
|
3645
|
+
async function respond(socket, message) {
|
|
3646
|
+
try {
|
|
3647
|
+
const response = await handleDaemonMessage(message);
|
|
3648
|
+
if (response && socket.writable)
|
|
3649
|
+
socket.write(encodeJsonLine(response));
|
|
3650
|
+
} catch (error) {
|
|
3651
|
+
logServerError(error);
|
|
3652
|
+
}
|
|
3653
|
+
}
|
|
3654
|
+
function listen(server, socketPath) {
|
|
3655
|
+
return new Promise((resolve6, reject) => {
|
|
3656
|
+
const onError = (error) => reject(error);
|
|
3657
|
+
server.once("error", onError);
|
|
3658
|
+
server.listen(socketPath, () => {
|
|
3659
|
+
server.removeListener("error", onError);
|
|
3660
|
+
resolve6();
|
|
3661
|
+
});
|
|
3662
|
+
});
|
|
3663
|
+
}
|
|
3664
|
+
function closeServer(server) {
|
|
3665
|
+
return new Promise((resolve6) => server.close(() => resolve6()));
|
|
3666
|
+
}
|
|
3667
|
+
function installSignalHandlers(close) {
|
|
3668
|
+
const handler = () => {
|
|
3669
|
+
close().then(() => process.exit(0));
|
|
3670
|
+
};
|
|
3671
|
+
process.once("SIGTERM", handler);
|
|
3672
|
+
process.once("SIGINT", handler);
|
|
3673
|
+
}
|
|
3674
|
+
function logServerError(error) {
|
|
3675
|
+
const message = error instanceof Error ? error.stack ?? error.message : String(error);
|
|
3676
|
+
process.stderr.write(`[lsp-daemon] ${message}
|
|
3677
|
+
`);
|
|
3678
|
+
}
|
|
3679
|
+
|
|
3680
|
+
// src/run-daemon.ts
|
|
3681
|
+
async function runDaemon() {
|
|
3682
|
+
process.on("uncaughtException", (error) => logNonFatal("uncaughtException", error));
|
|
3683
|
+
process.on("unhandledRejection", (reason) => logNonFatal("unhandledRejection", reason));
|
|
3684
|
+
await startDaemonServer(daemonPaths());
|
|
3685
|
+
}
|
|
3686
|
+
function logNonFatal(kind, error) {
|
|
3687
|
+
const message = error instanceof Error ? error.stack ?? error.message : String(error);
|
|
3688
|
+
process.stderr.write(`[lsp-daemon] ${kind}: ${message}
|
|
3689
|
+
`);
|
|
3690
|
+
}
|
|
3691
|
+
|
|
3692
|
+
// src/cli.ts
|
|
3693
|
+
async function main() {
|
|
3694
|
+
const [command = "mcp"] = argv.slice(2);
|
|
3695
|
+
if (command === "daemon") {
|
|
3696
|
+
await runDaemon();
|
|
3697
|
+
return;
|
|
3698
|
+
}
|
|
3699
|
+
if (command === "mcp") {
|
|
3700
|
+
await runMcpStdioProxy();
|
|
3701
|
+
return;
|
|
3702
|
+
}
|
|
3703
|
+
stderr.write(`Usage: omo-lsp-daemon [mcp | daemon]
|
|
3704
|
+
`);
|
|
3705
|
+
process.exitCode = 2;
|
|
3706
|
+
}
|
|
3707
|
+
main().catch((error) => {
|
|
3708
|
+
stderr.write(`${error instanceof Error ? error.stack ?? error.message : String(error)}
|
|
3709
|
+
`);
|
|
3710
|
+
process.exitCode = 1;
|
|
3711
|
+
});
|