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