@duckmind/dm-darwin-x64 0.67.1 → 0.67.3

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 (784) hide show
  1. package/README.md +2 -2
  2. package/dm +2 -2
  3. package/extensions/.dm-extensions.json +147 -32
  4. package/extensions/dm-lens/clients/actionable-warnings.js +12 -4
  5. package/extensions/dm-lens/clients/advisory-provenance.js +11 -10
  6. package/extensions/dm-lens/clients/agent-nudge.js +1 -1
  7. package/extensions/dm-lens/clients/analysis-root.js +75 -34
  8. package/extensions/dm-lens/clients/bash-file-access.js +550 -123
  9. package/extensions/dm-lens/clients/blocker-freshness.js +202 -19
  10. package/extensions/dm-lens/clients/blocker-past-eof.js +3 -1
  11. package/extensions/dm-lens/clients/bounded-telemetry.js +3 -0
  12. package/extensions/dm-lens/clients/cache-manager.js +22 -1
  13. package/extensions/dm-lens/clients/cache-observability.js +278 -17
  14. package/extensions/dm-lens/clients/cargo-manifest.js +8 -12
  15. package/extensions/dm-lens/clients/cascade-format.js +162 -19
  16. package/extensions/dm-lens/clients/codebase-model.js +2 -2
  17. package/extensions/dm-lens/clients/config-locations.js +1 -8
  18. package/extensions/dm-lens/clients/content-stamp.js +16 -0
  19. package/extensions/dm-lens/clients/context-injection-ledger.js +160 -0
  20. package/extensions/dm-lens/clients/deferred-runner-blockers.js +46 -6
  21. package/extensions/dm-lens/clients/degradation-ledger.js +21 -1
  22. package/extensions/dm-lens/clients/deps/ast-grep-napi.js +10 -0
  23. package/extensions/dm-lens/clients/diagnostic-dispositions.js +28 -12
  24. package/extensions/dm-lens/clients/disk-change-consumers.js +312 -0
  25. package/extensions/dm-lens/clients/disk-change-subscribers.js +197 -0
  26. package/extensions/dm-lens/clients/disk-changes.js +168 -0
  27. package/extensions/dm-lens/clients/dispatch/auxiliary-lsp.js +10 -6
  28. package/extensions/dm-lens/clients/dispatch/dispatcher.js +300 -61
  29. package/extensions/dm-lens/clients/dispatch/fact-store.js +2 -8
  30. package/extensions/dm-lens/clients/dispatch/facts/function-facts.js +87 -94
  31. package/extensions/dm-lens/clients/dispatch/finding-policy.js +25 -1
  32. package/extensions/dm-lens/clients/dispatch/indent-detect.js +1 -1
  33. package/extensions/dm-lens/clients/dispatch/integration.js +349 -135
  34. package/extensions/dm-lens/clients/dispatch/lane-copies.js +23 -0
  35. package/extensions/dm-lens/clients/dispatch/pending-runner-findings.js +3 -0
  36. package/extensions/dm-lens/clients/dispatch/pre-edit-seed.js +57 -0
  37. package/extensions/dm-lens/clients/dispatch/rule-id-normalize.js +6 -1
  38. package/extensions/dm-lens/clients/dispatch/rules/high-complexity.js +2 -17
  39. package/extensions/dm-lens/clients/dispatch/rules/high-fan-out.js +1 -9
  40. package/extensions/dm-lens/clients/dispatch/runner-context.js +9 -10
  41. package/extensions/dm-lens/clients/dispatch/runners/ast-grep-literal-anchors.js +58 -0
  42. package/extensions/dm-lens/clients/dispatch/runners/ast-grep-napi.js +59 -14
  43. package/extensions/dm-lens/clients/dispatch/runners/biome-check.js +9 -18
  44. package/extensions/dm-lens/clients/dispatch/runners/cue-vet.js +11 -21
  45. package/extensions/dm-lens/clients/dispatch/runners/dart-analyze.js +1 -1
  46. package/extensions/dm-lens/clients/dispatch/runners/detekt.js +4 -3
  47. package/extensions/dm-lens/clients/dispatch/runners/dotnet-build.js +15 -6
  48. package/extensions/dm-lens/clients/dispatch/runners/fish-indent.js +59 -5
  49. package/extensions/dm-lens/clients/dispatch/runners/gleam-check.js +9 -19
  50. package/extensions/dm-lens/clients/dispatch/runners/go-vet.js +2 -2
  51. package/extensions/dm-lens/clients/dispatch/runners/golangci-lint.js +17 -1
  52. package/extensions/dm-lens/clients/dispatch/runners/helm-lint.js +8 -5
  53. package/extensions/dm-lens/clients/dispatch/runners/helm-render.js +1 -1
  54. package/extensions/dm-lens/clients/dispatch/runners/ktlint.js +27 -5
  55. package/extensions/dm-lens/clients/dispatch/runners/lsp.js +91 -30
  56. package/extensions/dm-lens/clients/dispatch/runners/oxlint.js +9 -18
  57. package/extensions/dm-lens/clients/dispatch/runners/shellcheck.js +11 -20
  58. package/extensions/dm-lens/clients/dispatch/runners/shfmt.js +7 -0
  59. package/extensions/dm-lens/clients/dispatch/runners/taplo.js +2 -1
  60. package/extensions/dm-lens/clients/dispatch/runners/tree-sitter.js +29 -16
  61. package/extensions/dm-lens/clients/dispatch/runners/utils/availability-policy.js +32 -4
  62. package/extensions/dm-lens/clients/dispatch/runners/utils/candidate-probe.js +8 -0
  63. package/extensions/dm-lens/clients/dispatch/runners/utils/diagnostic-parsers.js +2 -1
  64. package/extensions/dm-lens/clients/dispatch/runners/utils/runner-helpers.js +1 -1
  65. package/extensions/dm-lens/clients/dispatch/runners/utils/tool-failure.js +9 -18
  66. package/extensions/dm-lens/clients/dispatch/runners/vale.js +2 -16
  67. package/extensions/dm-lens/clients/dispatch/types.js +45 -0
  68. package/extensions/dm-lens/clients/dispatch/utils/lsp-diagnostics.js +2 -1
  69. package/extensions/dm-lens/clients/ephemeral-root.js +10 -20
  70. package/extensions/dm-lens/clients/file-kinds.js +6 -2
  71. package/extensions/dm-lens/clients/file-mutation-queue.js +4 -8
  72. package/extensions/dm-lens/clients/file-utils.js +167 -28
  73. package/extensions/dm-lens/clients/finding-delivery-gate.js +15 -1
  74. package/extensions/dm-lens/clients/finding-identity.js +56 -0
  75. package/extensions/dm-lens/clients/fix-run-restore.js +10 -0
  76. package/extensions/dm-lens/clients/format-service.js +23 -5
  77. package/extensions/dm-lens/clients/formatters.js +33 -25
  78. package/extensions/dm-lens/clients/git-guard.js +516 -85
  79. package/extensions/dm-lens/clients/govulncheck-client.js +8 -0
  80. package/extensions/dm-lens/clients/grammar-source.js +39 -5
  81. package/extensions/dm-lens/clients/gzip-stage-write.js +99 -18
  82. package/extensions/dm-lens/clients/inline-blocker-fields.js +1 -1
  83. package/extensions/dm-lens/clients/installer/index.js +83 -85
  84. package/extensions/dm-lens/clients/installer/managed-tool-refresh.js +211 -8
  85. package/extensions/dm-lens/clients/instance-reaper.js +19 -8
  86. package/extensions/dm-lens/clients/instance-registry.js +12 -0
  87. package/extensions/dm-lens/clients/jscpd-client.js +20 -4
  88. package/extensions/dm-lens/clients/language-profile.js +8 -7
  89. package/extensions/dm-lens/clients/language-registry.js +45 -4
  90. package/extensions/dm-lens/clients/latency-logger.js +10 -2
  91. package/extensions/dm-lens/clients/lens-config.js +14 -4
  92. package/extensions/dm-lens/clients/lens-engine.js +10 -2
  93. package/extensions/dm-lens/clients/lens-flag-registry.js +19 -3
  94. package/extensions/dm-lens/clients/line-alignment.js +200 -0
  95. package/extensions/dm-lens/clients/lsp/capabilities.js +2 -2
  96. package/extensions/dm-lens/clients/lsp/cascade-tier.js +148 -38
  97. package/extensions/dm-lens/clients/lsp/client-registry.js +906 -0
  98. package/extensions/dm-lens/clients/lsp/client.js +413 -108
  99. package/extensions/dm-lens/clients/lsp/config.js +151 -47
  100. package/extensions/dm-lens/clients/lsp/content-limits.js +2 -2
  101. package/extensions/dm-lens/clients/lsp/content-scan.js +69 -0
  102. package/extensions/dm-lens/clients/lsp/created-import-targets.js +134 -0
  103. package/extensions/dm-lens/clients/lsp/diagnostic-binding.js +34 -0
  104. package/extensions/dm-lens/clients/lsp/document-drift.js +63 -15
  105. package/extensions/dm-lens/clients/lsp/edits.js +109 -26
  106. package/extensions/dm-lens/clients/lsp/environment-gap.js +186 -0
  107. package/extensions/dm-lens/clients/lsp/file-server-match.js +26 -0
  108. package/extensions/dm-lens/clients/lsp/implicit-scope.js +208 -0
  109. package/extensions/dm-lens/clients/lsp/index.js +574 -916
  110. package/extensions/dm-lens/clients/lsp/inferred-project.js +37 -15
  111. package/extensions/dm-lens/clients/lsp/jvm-runtime.js +15 -9
  112. package/extensions/dm-lens/clients/lsp/language.js +8 -1
  113. package/extensions/dm-lens/clients/lsp/launch.js +93 -43
  114. package/extensions/dm-lens/clients/lsp/lombok.js +0 -13
  115. package/extensions/dm-lens/clients/lsp/path-utils.js +2 -0
  116. package/extensions/dm-lens/clients/lsp/position-encoding.js +0 -7
  117. package/extensions/dm-lens/clients/lsp/server-config-files.js +11 -0
  118. package/extensions/dm-lens/clients/lsp/server-traits.js +8 -2
  119. package/extensions/dm-lens/clients/lsp/server.js +273 -76
  120. package/extensions/dm-lens/clients/lsp/session-roots.js +38 -3
  121. package/extensions/dm-lens/clients/lsp/wait-policy/strategies.js +87 -5
  122. package/extensions/dm-lens/clients/lsp/watch-queue.js +23 -2
  123. package/extensions/dm-lens/clients/lsp/workspace-diagnostics-cache.js +183 -47
  124. package/extensions/dm-lens/clients/lsp/workspace-diagnostics-session.js +35 -0
  125. package/extensions/dm-lens/clients/lsp-mutation.js +1 -1
  126. package/extensions/dm-lens/clients/mcp/analyze.js +51 -13
  127. package/extensions/dm-lens/clients/mcp/ipc.js +24 -1
  128. package/extensions/dm-lens/clients/mcp/session.js +2 -7
  129. package/extensions/dm-lens/clients/memory-sampler.js +19 -1
  130. package/extensions/dm-lens/clients/metrics-history.js +16 -29
  131. package/extensions/dm-lens/clients/mutating-tool.js +4 -2
  132. package/extensions/dm-lens/clients/mutation-attribution.js +1 -4
  133. package/extensions/dm-lens/clients/observed-mutation.js +7 -1
  134. package/extensions/dm-lens/clients/opaque-mutation-scan.js +273 -59
  135. package/extensions/dm-lens/clients/opengrep-client.js +6 -1
  136. package/extensions/dm-lens/clients/opengrep-config.js +10 -5
  137. package/extensions/dm-lens/clients/opengrep-rule-pack.js +19 -0
  138. package/extensions/dm-lens/clients/out-of-band-changes.js +342 -0
  139. package/extensions/dm-lens/clients/package-manager.js +51 -62
  140. package/extensions/dm-lens/clients/package-root.js +8 -12
  141. package/extensions/dm-lens/clients/partial-edit-apply.js +8 -4
  142. package/extensions/dm-lens/clients/path-birth.js +58 -0
  143. package/extensions/dm-lens/clients/path-utils.js +145 -23
  144. package/extensions/dm-lens/clients/persist-worker-stats.js +8 -0
  145. package/extensions/dm-lens/clients/persistent-reverify.js +2 -1
  146. package/extensions/dm-lens/clients/pipeline.js +248 -35
  147. package/extensions/dm-lens/clients/probe-home-state.js +6 -0
  148. package/extensions/dm-lens/clients/project-changes.js +9 -3
  149. package/extensions/dm-lens/clients/project-diagnostics/fresh-fetch.js +1 -1
  150. package/extensions/dm-lens/clients/project-diagnostics/scanner.js +4 -2
  151. package/extensions/dm-lens/clients/project-lens-config.js +4 -6
  152. package/extensions/dm-lens/clients/project-root-markers.js +8 -0
  153. package/extensions/dm-lens/clients/project-snapshot-persist-worker.js +26 -8
  154. package/extensions/dm-lens/clients/project-snapshot.js +36 -10
  155. package/extensions/dm-lens/clients/python-environment.js +239 -12
  156. package/extensions/dm-lens/clients/read-guard-tool-lines.js +2 -8
  157. package/extensions/dm-lens/clients/read-guard.js +130 -43
  158. package/extensions/dm-lens/clients/review-graph/builder.js +102 -19
  159. package/extensions/dm-lens/clients/review-graph/git-identity.js +7 -2
  160. package/extensions/dm-lens/clients/review-graph/import-resolvers.js +9 -0
  161. package/extensions/dm-lens/clients/review-graph/tsconfig-paths.js +35 -2
  162. package/extensions/dm-lens/clients/ruff-client.js +0 -2
  163. package/extensions/dm-lens/clients/rules-scanner.js +0 -43
  164. package/extensions/dm-lens/clients/runtime-agent-end.js +37 -6
  165. package/extensions/dm-lens/clients/runtime-coordinator.js +177 -31
  166. package/extensions/dm-lens/clients/runtime-session.js +106 -66
  167. package/extensions/dm-lens/clients/runtime-tool-call.js +162 -65
  168. package/extensions/dm-lens/clients/runtime-tool-result.js +634 -147
  169. package/extensions/dm-lens/clients/runtime-turn.js +472 -150
  170. package/extensions/dm-lens/clients/rust-client.js +11 -13
  171. package/extensions/dm-lens/clients/safe-spawn.js +149 -17
  172. package/extensions/dm-lens/clients/sanitize.js +0 -169
  173. package/extensions/dm-lens/clients/search-read-registration.js +22 -4
  174. package/extensions/dm-lens/clients/session-lifecycle.js +44 -1
  175. package/extensions/dm-lens/clients/session-repository.js +119 -0
  176. package/extensions/dm-lens/clients/session-scope.js +1 -1
  177. package/extensions/dm-lens/clients/session-start-observability.js +12 -0
  178. package/extensions/dm-lens/clients/session-state-store.js +6 -1
  179. package/extensions/dm-lens/clients/sg-runner.js +5 -8
  180. package/extensions/dm-lens/clients/sgconfig.js +7 -14
  181. package/extensions/dm-lens/clients/single-flight.js +1 -0
  182. package/extensions/dm-lens/clients/source-filter.js +19 -16
  183. package/extensions/dm-lens/clients/source-walker.js +21 -3
  184. package/extensions/dm-lens/clients/startup-scan.js +18 -23
  185. package/extensions/dm-lens/clients/test-runner-client.js +21 -27
  186. package/extensions/dm-lens/clients/test-runner-delivery.js +2 -10
  187. package/extensions/dm-lens/clients/tool-config.js +24 -4
  188. package/extensions/dm-lens/clients/tool-cwd.js +11 -9
  189. package/extensions/dm-lens/clients/tool-policy.js +1 -8
  190. package/extensions/dm-lens/clients/tool-set-policy.js +32 -3
  191. package/extensions/dm-lens/clients/tree-sitter-client.js +70 -24
  192. package/extensions/dm-lens/clients/tree-sitter-query-loader.js +13 -1
  193. package/extensions/dm-lens/clients/tree-sitter-symbol-extractor.js +81 -56
  194. package/extensions/dm-lens/clients/warm-attach.js +33 -8
  195. package/extensions/dm-lens/clients/widget-state.js +48 -31
  196. package/extensions/dm-lens/clients/word-index-logger.js +3 -0
  197. package/extensions/dm-lens/clients/word-index.js +15 -2
  198. package/extensions/dm-lens/clients/workspace-topology.js +10 -8
  199. package/extensions/dm-lens/config/biome/core.jsonc +3 -3
  200. package/extensions/dm-lens/config/dependency-cruiser-eager-allowlist.json +1 -0
  201. package/extensions/dm-lens/dist/clients/actionable-warnings.js +8 -4
  202. package/extensions/dm-lens/dist/clients/advisory-provenance.js +11 -10
  203. package/extensions/dm-lens/dist/clients/agent-nudge.js +1 -1
  204. package/extensions/dm-lens/dist/clients/analysis-root.js +67 -34
  205. package/extensions/dm-lens/dist/clients/bash-file-access.js +550 -123
  206. package/extensions/dm-lens/dist/clients/blocker-freshness.js +195 -19
  207. package/extensions/dm-lens/dist/clients/blocker-past-eof.js +3 -1
  208. package/extensions/dm-lens/dist/clients/bounded-telemetry.js +3 -0
  209. package/extensions/dm-lens/dist/clients/cache-manager.js +22 -1
  210. package/extensions/dm-lens/dist/clients/cache-observability.js +275 -17
  211. package/extensions/dm-lens/dist/clients/cargo-manifest.js +8 -12
  212. package/extensions/dm-lens/dist/clients/cascade-format.js +160 -19
  213. package/extensions/dm-lens/dist/clients/codebase-model.js +2 -2
  214. package/extensions/dm-lens/dist/clients/config-locations.js +2 -8
  215. package/extensions/dm-lens/dist/clients/content-stamp.js +16 -0
  216. package/extensions/dm-lens/dist/clients/context-injection-ledger.js +157 -0
  217. package/extensions/dm-lens/dist/clients/deferred-runner-blockers.js +46 -6
  218. package/extensions/dm-lens/dist/clients/degradation-ledger.js +18 -1
  219. package/extensions/dm-lens/dist/clients/deps/ast-grep-napi.js +10 -0
  220. package/extensions/dm-lens/dist/clients/diagnostic-dispositions.js +28 -12
  221. package/extensions/dm-lens/dist/clients/disk-change-consumers.js +312 -0
  222. package/extensions/dm-lens/dist/clients/disk-change-subscribers.js +191 -0
  223. package/extensions/dm-lens/dist/clients/disk-changes.js +165 -0
  224. package/extensions/dm-lens/dist/clients/dispatch/auxiliary-lsp.js +10 -6
  225. package/extensions/dm-lens/dist/clients/dispatch/dispatcher.js +284 -61
  226. package/extensions/dm-lens/dist/clients/dispatch/fact-store.js +2 -8
  227. package/extensions/dm-lens/dist/clients/dispatch/facts/function-facts.js +87 -94
  228. package/extensions/dm-lens/dist/clients/dispatch/finding-policy.js +25 -1
  229. package/extensions/dm-lens/dist/clients/dispatch/indent-detect.js +1 -1
  230. package/extensions/dm-lens/dist/clients/dispatch/integration.js +333 -137
  231. package/extensions/dm-lens/dist/clients/dispatch/lane-copies.js +23 -0
  232. package/extensions/dm-lens/dist/clients/dispatch/pending-runner-findings.js +3 -0
  233. package/extensions/dm-lens/dist/clients/dispatch/pre-edit-seed.js +57 -0
  234. package/extensions/dm-lens/dist/clients/dispatch/rule-id-normalize.js +6 -1
  235. package/extensions/dm-lens/dist/clients/dispatch/rules/high-complexity.js +2 -17
  236. package/extensions/dm-lens/dist/clients/dispatch/rules/high-fan-out.js +1 -9
  237. package/extensions/dm-lens/dist/clients/dispatch/runner-context.js +5 -10
  238. package/extensions/dm-lens/dist/clients/dispatch/runners/ast-grep-literal-anchors.js +58 -0
  239. package/extensions/dm-lens/dist/clients/dispatch/runners/ast-grep-napi.js +59 -14
  240. package/extensions/dm-lens/dist/clients/dispatch/runners/biome-check.js +9 -18
  241. package/extensions/dm-lens/dist/clients/dispatch/runners/cue-vet.js +11 -21
  242. package/extensions/dm-lens/dist/clients/dispatch/runners/dart-analyze.js +1 -1
  243. package/extensions/dm-lens/dist/clients/dispatch/runners/detekt.js +4 -3
  244. package/extensions/dm-lens/dist/clients/dispatch/runners/dotnet-build.js +12 -6
  245. package/extensions/dm-lens/dist/clients/dispatch/runners/fish-indent.js +59 -5
  246. package/extensions/dm-lens/dist/clients/dispatch/runners/gleam-check.js +9 -19
  247. package/extensions/dm-lens/dist/clients/dispatch/runners/go-vet.js +2 -2
  248. package/extensions/dm-lens/dist/clients/dispatch/runners/golangci-lint.js +17 -1
  249. package/extensions/dm-lens/dist/clients/dispatch/runners/helm-lint.js +8 -5
  250. package/extensions/dm-lens/dist/clients/dispatch/runners/helm-render.js +1 -1
  251. package/extensions/dm-lens/dist/clients/dispatch/runners/ktlint.js +27 -5
  252. package/extensions/dm-lens/dist/clients/dispatch/runners/lsp.js +79 -30
  253. package/extensions/dm-lens/dist/clients/dispatch/runners/oxlint.js +9 -18
  254. package/extensions/dm-lens/dist/clients/dispatch/runners/shellcheck.js +11 -20
  255. package/extensions/dm-lens/dist/clients/dispatch/runners/shfmt.js +7 -0
  256. package/extensions/dm-lens/dist/clients/dispatch/runners/taplo.js +2 -1
  257. package/extensions/dm-lens/dist/clients/dispatch/runners/tree-sitter.js +29 -16
  258. package/extensions/dm-lens/dist/clients/dispatch/runners/utils/availability-policy.js +32 -4
  259. package/extensions/dm-lens/dist/clients/dispatch/runners/utils/candidate-probe.js +5 -0
  260. package/extensions/dm-lens/dist/clients/dispatch/runners/utils/diagnostic-parsers.js +2 -1
  261. package/extensions/dm-lens/dist/clients/dispatch/runners/utils/runner-helpers.js +1 -1
  262. package/extensions/dm-lens/dist/clients/dispatch/runners/utils/tool-failure.js +9 -19
  263. package/extensions/dm-lens/dist/clients/dispatch/runners/vale.js +2 -16
  264. package/extensions/dm-lens/dist/clients/dispatch/types.js +45 -0
  265. package/extensions/dm-lens/dist/clients/dispatch/utils/lsp-diagnostics.js +2 -1
  266. package/extensions/dm-lens/dist/clients/ephemeral-root.js +8 -20
  267. package/extensions/dm-lens/dist/clients/file-kinds.js +6 -2
  268. package/extensions/dm-lens/dist/clients/file-mutation-queue.js +4 -8
  269. package/extensions/dm-lens/dist/clients/file-utils.js +163 -29
  270. package/extensions/dm-lens/dist/clients/finding-delivery-gate.js +15 -1
  271. package/extensions/dm-lens/dist/clients/finding-identity.js +56 -0
  272. package/extensions/dm-lens/dist/clients/fix-run-restore.js +10 -0
  273. package/extensions/dm-lens/dist/clients/format-service.js +23 -5
  274. package/extensions/dm-lens/dist/clients/formatters.js +25 -25
  275. package/extensions/dm-lens/dist/clients/git-guard.js +507 -85
  276. package/extensions/dm-lens/dist/clients/govulncheck-client.js +5 -0
  277. package/extensions/dm-lens/dist/clients/grammar-source.js +39 -5
  278. package/extensions/dm-lens/dist/clients/gzip-stage-write.js +99 -18
  279. package/extensions/dm-lens/dist/clients/inline-blocker-fields.js +1 -1
  280. package/extensions/dm-lens/dist/clients/installer/index.js +76 -83
  281. package/extensions/dm-lens/dist/clients/installer/managed-tool-refresh.js +208 -9
  282. package/extensions/dm-lens/dist/clients/instance-reaper.js +19 -8
  283. package/extensions/dm-lens/dist/clients/instance-registry.js +12 -0
  284. package/extensions/dm-lens/dist/clients/jscpd-client.js +15 -4
  285. package/extensions/dm-lens/dist/clients/language-profile.js +3 -7
  286. package/extensions/dm-lens/dist/clients/language-registry.js +45 -4
  287. package/extensions/dm-lens/dist/clients/latency-logger.js +10 -2
  288. package/extensions/dm-lens/dist/clients/lens-config.js +12 -4
  289. package/extensions/dm-lens/dist/clients/lens-engine.js +10 -3
  290. package/extensions/dm-lens/dist/clients/lens-flag-registry.js +19 -3
  291. package/extensions/dm-lens/dist/clients/line-alignment.js +200 -0
  292. package/extensions/dm-lens/dist/clients/lsp/capabilities.js +2 -2
  293. package/extensions/dm-lens/dist/clients/lsp/cascade-tier.js +148 -38
  294. package/extensions/dm-lens/dist/clients/lsp/client-registry.js +877 -0
  295. package/extensions/dm-lens/dist/clients/lsp/client.js +398 -109
  296. package/extensions/dm-lens/dist/clients/lsp/config.js +147 -47
  297. package/extensions/dm-lens/dist/clients/lsp/content-limits.js +2 -2
  298. package/extensions/dm-lens/dist/clients/lsp/content-scan.js +69 -0
  299. package/extensions/dm-lens/dist/clients/lsp/created-import-targets.js +134 -0
  300. package/extensions/dm-lens/dist/clients/lsp/diagnostic-binding.js +34 -0
  301. package/extensions/dm-lens/dist/clients/lsp/document-drift.js +63 -15
  302. package/extensions/dm-lens/dist/clients/lsp/edits.js +104 -26
  303. package/extensions/dm-lens/dist/clients/lsp/environment-gap.js +186 -0
  304. package/extensions/dm-lens/dist/clients/lsp/file-server-match.js +26 -0
  305. package/extensions/dm-lens/dist/clients/lsp/implicit-scope.js +205 -0
  306. package/extensions/dm-lens/dist/clients/lsp/index.js +547 -894
  307. package/extensions/dm-lens/dist/clients/lsp/inferred-project.js +34 -15
  308. package/extensions/dm-lens/dist/clients/lsp/jvm-runtime.js +15 -9
  309. package/extensions/dm-lens/dist/clients/lsp/language.js +4 -1
  310. package/extensions/dm-lens/dist/clients/lsp/launch.js +85 -43
  311. package/extensions/dm-lens/dist/clients/lsp/lombok.js +0 -13
  312. package/extensions/dm-lens/dist/clients/lsp/path-utils.js +1 -1
  313. package/extensions/dm-lens/dist/clients/lsp/position-encoding.js +0 -7
  314. package/extensions/dm-lens/dist/clients/lsp/server-config-files.js +11 -0
  315. package/extensions/dm-lens/dist/clients/lsp/server-traits.js +8 -2
  316. package/extensions/dm-lens/dist/clients/lsp/server.js +267 -80
  317. package/extensions/dm-lens/dist/clients/lsp/session-roots.js +34 -3
  318. package/extensions/dm-lens/dist/clients/lsp/wait-policy/strategies.js +85 -5
  319. package/extensions/dm-lens/dist/clients/lsp/watch-queue.js +23 -2
  320. package/extensions/dm-lens/dist/clients/lsp/workspace-diagnostics-cache.js +172 -47
  321. package/extensions/dm-lens/dist/clients/lsp/workspace-diagnostics-session.js +35 -0
  322. package/extensions/dm-lens/dist/clients/lsp-mutation.js +1 -1
  323. package/extensions/dm-lens/dist/clients/mcp/analyze.js +51 -14
  324. package/extensions/dm-lens/dist/clients/mcp/ipc.js +24 -1
  325. package/extensions/dm-lens/dist/clients/mcp/session.js +2 -7
  326. package/extensions/dm-lens/dist/clients/memory-sampler.js +19 -1
  327. package/extensions/dm-lens/dist/clients/metrics-history.js +16 -29
  328. package/extensions/dm-lens/dist/clients/mutating-tool.js +4 -2
  329. package/extensions/dm-lens/dist/clients/mutation-attribution.js +1 -4
  330. package/extensions/dm-lens/dist/clients/observed-mutation.js +7 -1
  331. package/extensions/dm-lens/dist/clients/opaque-mutation-scan.js +260 -59
  332. package/extensions/dm-lens/dist/clients/opengrep-client.js +6 -1
  333. package/extensions/dm-lens/dist/clients/opengrep-config.js +10 -5
  334. package/extensions/dm-lens/dist/clients/opengrep-rule-pack.js +19 -0
  335. package/extensions/dm-lens/dist/clients/out-of-band-changes.js +329 -0
  336. package/extensions/dm-lens/dist/clients/package-manager.js +36 -62
  337. package/extensions/dm-lens/dist/clients/package-root.js +8 -12
  338. package/extensions/dm-lens/dist/clients/partial-edit-apply.js +8 -4
  339. package/extensions/dm-lens/dist/clients/path-birth.js +58 -0
  340. package/extensions/dm-lens/dist/clients/path-utils.js +142 -23
  341. package/extensions/dm-lens/dist/clients/persist-worker-stats.js +8 -0
  342. package/extensions/dm-lens/dist/clients/persistent-reverify.js +2 -1
  343. package/extensions/dm-lens/dist/clients/pipeline.js +229 -35
  344. package/extensions/dm-lens/dist/clients/probe-home-state.js +6 -0
  345. package/extensions/dm-lens/dist/clients/project-changes.js +9 -3
  346. package/extensions/dm-lens/dist/clients/project-diagnostics/fresh-fetch.js +1 -1
  347. package/extensions/dm-lens/dist/clients/project-diagnostics/scanner.js +4 -2
  348. package/extensions/dm-lens/dist/clients/project-lens-config.js +4 -6
  349. package/extensions/dm-lens/dist/clients/project-root-markers.js +8 -0
  350. package/extensions/dm-lens/dist/clients/project-snapshot-persist-worker.js +26 -8
  351. package/extensions/dm-lens/dist/clients/project-snapshot.js +33 -11
  352. package/extensions/dm-lens/dist/clients/python-environment.js +239 -13
  353. package/extensions/dm-lens/dist/clients/read-guard-tool-lines.js +2 -8
  354. package/extensions/dm-lens/dist/clients/read-guard.js +127 -39
  355. package/extensions/dm-lens/dist/clients/review-graph/builder.js +94 -22
  356. package/extensions/dm-lens/dist/clients/review-graph/git-identity.js +7 -2
  357. package/extensions/dm-lens/dist/clients/review-graph/import-resolvers.js +9 -0
  358. package/extensions/dm-lens/dist/clients/review-graph/tsconfig-paths.js +35 -2
  359. package/extensions/dm-lens/dist/clients/ruff-client.js +0 -2
  360. package/extensions/dm-lens/dist/clients/rules-scanner.js +0 -43
  361. package/extensions/dm-lens/dist/clients/runtime-agent-end.js +37 -6
  362. package/extensions/dm-lens/dist/clients/runtime-coordinator.js +168 -31
  363. package/extensions/dm-lens/dist/clients/runtime-session.js +103 -65
  364. package/extensions/dm-lens/dist/clients/runtime-tool-call.js +155 -64
  365. package/extensions/dm-lens/dist/clients/runtime-tool-result.js +586 -148
  366. package/extensions/dm-lens/dist/clients/runtime-turn.js +450 -152
  367. package/extensions/dm-lens/dist/clients/rust-client.js +11 -13
  368. package/extensions/dm-lens/dist/clients/safe-spawn.js +144 -17
  369. package/extensions/dm-lens/dist/clients/sanitize.js +0 -169
  370. package/extensions/dm-lens/dist/clients/search-read-registration.js +20 -4
  371. package/extensions/dm-lens/dist/clients/session-lifecycle.js +41 -1
  372. package/extensions/dm-lens/dist/clients/session-repository.js +113 -0
  373. package/extensions/dm-lens/dist/clients/session-scope.js +1 -1
  374. package/extensions/dm-lens/dist/clients/session-start-observability.js +12 -0
  375. package/extensions/dm-lens/dist/clients/session-state-store.js +6 -1
  376. package/extensions/dm-lens/dist/clients/sg-runner.js +5 -8
  377. package/extensions/dm-lens/dist/clients/sgconfig.js +7 -14
  378. package/extensions/dm-lens/dist/clients/single-flight.js +1 -0
  379. package/extensions/dm-lens/dist/clients/source-filter.js +19 -16
  380. package/extensions/dm-lens/dist/clients/source-walker.js +21 -3
  381. package/extensions/dm-lens/dist/clients/startup-scan.js +14 -23
  382. package/extensions/dm-lens/dist/clients/test-runner-client.js +17 -28
  383. package/extensions/dm-lens/dist/clients/test-runner-delivery.js +2 -10
  384. package/extensions/dm-lens/dist/clients/tool-config.js +24 -4
  385. package/extensions/dm-lens/dist/clients/tool-cwd.js +10 -9
  386. package/extensions/dm-lens/dist/clients/tool-policy.js +1 -8
  387. package/extensions/dm-lens/dist/clients/tool-set-policy.js +32 -3
  388. package/extensions/dm-lens/dist/clients/tree-sitter-client.js +69 -25
  389. package/extensions/dm-lens/dist/clients/tree-sitter-query-loader.js +13 -1
  390. package/extensions/dm-lens/dist/clients/tree-sitter-symbol-extractor.js +81 -56
  391. package/extensions/dm-lens/dist/clients/warm-attach.js +31 -9
  392. package/extensions/dm-lens/dist/clients/widget-state.js +48 -31
  393. package/extensions/dm-lens/dist/clients/word-index-logger.js +3 -0
  394. package/extensions/dm-lens/dist/clients/word-index.js +11 -2
  395. package/extensions/dm-lens/dist/clients/workspace-topology.js +10 -4
  396. package/extensions/dm-lens/dist/index.js +315 -144
  397. package/extensions/dm-lens/dist/mcp/analyze-cli.js +1 -1
  398. package/extensions/dm-lens/dist/mcp/cli.js +1 -1
  399. package/extensions/dm-lens/dist/mcp/server.js +16 -14
  400. package/extensions/dm-lens/dist/mcp/worker.js +1 -1
  401. package/extensions/dm-lens/dist/scripts/lib/process-scan.mjs +1 -1
  402. package/extensions/dm-lens/dist/tools/activate-tools.js +3 -2
  403. package/extensions/dm-lens/dist/tools/ast-grep-outline.js +6 -4
  404. package/extensions/dm-lens/dist/tools/ast-grep-replace.js +17 -10
  405. package/extensions/dm-lens/dist/tools/ast-grep-search.js +22 -19
  406. package/extensions/dm-lens/dist/tools/lens-diagnostic-mark.js +3 -3
  407. package/extensions/dm-lens/dist/tools/lens-diagnostics.js +245 -70
  408. package/extensions/dm-lens/dist/tools/lsp-diagnostics.js +276 -77
  409. package/extensions/dm-lens/dist/tools/lsp-navigation.js +152 -100
  410. package/extensions/dm-lens/dist/tools/module-report.js +2 -1
  411. package/extensions/dm-lens/dist/tools/shared.js +16 -2
  412. package/extensions/dm-lens/index.js +336 -141
  413. package/extensions/dm-lens/mcp/analyze-cli.js +1 -1
  414. package/extensions/dm-lens/mcp/cli.js +1 -1
  415. package/extensions/dm-lens/mcp/server.js +16 -13
  416. package/extensions/dm-lens/mcp/worker.js +1 -1
  417. package/extensions/dm-lens/package.json +1 -1
  418. package/extensions/dm-lens/rules/ast-grep-rules/rule-tests/no-return-value-in-generator-test.yml +17 -0
  419. package/extensions/dm-lens/rules/ast-grep-rules/rule-tests/no-sql-in-code-execute-js-test.yml +86 -0
  420. package/extensions/dm-lens/rules/ast-grep-rules/rule-tests/no-sql-in-code-execute-test.yml +86 -0
  421. package/extensions/dm-lens/rules/ast-grep-rules/rule-tests/unchecked-numeric-parse-python-test.yml +15 -0
  422. package/extensions/dm-lens/rules/ast-grep-rules/rules/no-return-value-in-generator.yml +9 -4
  423. package/extensions/dm-lens/rules/ast-grep-rules/rules/no-sql-in-code-execute-js.yml +119 -0
  424. package/extensions/dm-lens/rules/ast-grep-rules/rules/no-sql-in-code-execute.yml +119 -0
  425. package/extensions/dm-lens/rules/ast-grep-rules/rules/unchecked-numeric-parse-python.yml +13 -2
  426. package/extensions/dm-lens/rules/rule-catalog.json +25 -1
  427. package/extensions/dm-lens/scripts/lib/process-scan.mjs +1 -1
  428. package/extensions/dm-lens/skills/{pi-lens-ast-grep → dm-lens-ast-grep}/SKILL.md +1 -1
  429. package/extensions/dm-lens/tools/activate-tools.js +3 -2
  430. package/extensions/dm-lens/tools/ast-grep-outline.js +6 -4
  431. package/extensions/dm-lens/tools/ast-grep-replace.js +17 -10
  432. package/extensions/dm-lens/tools/ast-grep-search.js +27 -19
  433. package/extensions/dm-lens/tools/lens-diagnostic-mark.js +3 -3
  434. package/extensions/dm-lens/tools/lens-diagnostics.js +260 -68
  435. package/extensions/dm-lens/tools/lsp-diagnostics.js +303 -76
  436. package/extensions/dm-lens/tools/lsp-navigation.js +168 -102
  437. package/extensions/dm-lens/tools/module-report.js +2 -1
  438. package/extensions/dm-lens/tools/shared.js +16 -2
  439. package/extensions/dm-mcp-adapter/.github/workflows/ci.yml +82 -0
  440. package/extensions/dm-mcp-adapter/THIRD_PARTY_NOTICES.md +1 -1
  441. package/extensions/dm-mcp-adapter/VISION.md +94 -0
  442. package/extensions/dm-mcp-adapter/agent-dir.js +2 -2
  443. package/extensions/dm-mcp-adapter/bearer-command-resolver.js +5 -3
  444. package/extensions/dm-mcp-adapter/bench/server-memory.mjs +432 -0
  445. package/extensions/dm-mcp-adapter/bench/session.js +105 -0
  446. package/extensions/dm-mcp-adapter/bench/token-cost/data.mjs +231 -0
  447. package/extensions/dm-mcp-adapter/bench/token-cost/run.mjs +190 -0
  448. package/extensions/dm-mcp-adapter/bench/token-cost/server.mjs +109 -0
  449. package/extensions/dm-mcp-adapter/cli.js +55 -100
  450. package/extensions/dm-mcp-adapter/codemode-bridge.js +92 -0
  451. package/extensions/dm-mcp-adapter/commands.js +143 -26
  452. package/extensions/dm-mcp-adapter/config.js +303 -78
  453. package/extensions/dm-mcp-adapter/conformance/baseline-client.yml +22 -0
  454. package/extensions/dm-mcp-adapter/conformance/driver.js +200 -0
  455. package/extensions/dm-mcp-adapter/conformance/driver.sh +24 -0
  456. package/extensions/dm-mcp-adapter/conformance/run.sh +130 -0
  457. package/extensions/dm-mcp-adapter/deferred-tool-surface.js +69 -0
  458. package/extensions/dm-mcp-adapter/direct-tool-surface.js +96 -72
  459. package/extensions/dm-mcp-adapter/direct-tools.js +76 -53
  460. package/extensions/dm-mcp-adapter/dist/agent-dir.js +2 -2
  461. package/extensions/dm-mcp-adapter/dist/bearer-command-resolver.js +5 -3
  462. package/extensions/dm-mcp-adapter/dist/config.js +304 -55
  463. package/extensions/dm-mcp-adapter/dist/elicitation-handler.js +4 -0
  464. package/extensions/dm-mcp-adapter/dist/extraction-settings.js +43 -0
  465. package/extensions/dm-mcp-adapter/dist/mcp-probe.js +1 -1
  466. package/extensions/dm-mcp-adapter/dist/mcp-tasks.js +46 -7
  467. package/extensions/dm-mcp-adapter/dist/metadata-cache.js +93 -5
  468. package/extensions/dm-mcp-adapter/dist/output-shape.js +1 -1
  469. package/extensions/dm-mcp-adapter/dist/project-server-trust.js +108 -20
  470. package/extensions/dm-mcp-adapter/dist/request-headers-command.js +17 -1
  471. package/extensions/dm-mcp-adapter/dist/runtime-owner.js +7 -6
  472. package/extensions/dm-mcp-adapter/dist/sampling-handler.js +8 -2
  473. package/extensions/dm-mcp-adapter/dist/script-tools.js +72 -0
  474. package/extensions/dm-mcp-adapter/dist/semantic-settings.js +51 -0
  475. package/extensions/dm-mcp-adapter/dist/server-log.js +19 -0
  476. package/extensions/dm-mcp-adapter/dist/server-manager.js +62 -21
  477. package/extensions/dm-mcp-adapter/dist/task-entries.js +60 -0
  478. package/extensions/dm-mcp-adapter/dist/task-jobs.js +259 -0
  479. package/extensions/dm-mcp-adapter/dist/types.js +7 -0
  480. package/extensions/dm-mcp-adapter/dist/utils.js +33 -7
  481. package/extensions/dm-mcp-adapter/dm-host-tool-context.js +0 -0
  482. package/extensions/dm-mcp-adapter/elicitation-handler.js +4 -0
  483. package/extensions/dm-mcp-adapter/error-signal.js +12 -1
  484. package/extensions/dm-mcp-adapter/executor-accounts.js +192 -0
  485. package/extensions/dm-mcp-adapter/executor-app-tools.js +61 -0
  486. package/extensions/dm-mcp-adapter/executor-catalog.js +157 -0
  487. package/extensions/dm-mcp-adapter/executor-pauses.js +105 -0
  488. package/extensions/dm-mcp-adapter/extraction-settings.js +43 -0
  489. package/extensions/dm-mcp-adapter/extraction.js +396 -0
  490. package/extensions/dm-mcp-adapter/host-html-template.js +1 -1
  491. package/extensions/dm-mcp-adapter/host-managed.js +24 -5
  492. package/extensions/dm-mcp-adapter/index.js +761 -76
  493. package/extensions/dm-mcp-adapter/init.js +235 -11
  494. package/extensions/dm-mcp-adapter/jev-semantic-search.js +161 -0
  495. package/extensions/dm-mcp-adapter/mcp-code.js +12 -11
  496. package/extensions/dm-mcp-adapter/mcp-keyring-helper.cjs +1 -1
  497. package/extensions/dm-mcp-adapter/mcp-output-guard.js +7 -0
  498. package/extensions/dm-mcp-adapter/mcp-panel.js +23 -21
  499. package/extensions/dm-mcp-adapter/mcp-probe.js +1 -1
  500. package/extensions/dm-mcp-adapter/mcp-status.js +2 -1
  501. package/extensions/dm-mcp-adapter/mcp-tasks.js +46 -7
  502. package/extensions/dm-mcp-adapter/metadata-cache.js +93 -5
  503. package/extensions/dm-mcp-adapter/namespace-tools.js +12 -4
  504. package/extensions/dm-mcp-adapter/output-shape.js +1 -1
  505. package/extensions/dm-mcp-adapter/package.json +1 -1
  506. package/extensions/dm-mcp-adapter/pi-mcp.mp4 +0 -0
  507. package/extensions/dm-mcp-adapter/pi-signin-import.js +1 -1
  508. package/extensions/dm-mcp-adapter/project-server-trust.js +108 -20
  509. package/extensions/dm-mcp-adapter/proxy-modes.js +320 -110
  510. package/extensions/dm-mcp-adapter/request-headers-command.js +17 -1
  511. package/extensions/dm-mcp-adapter/runtime-owner.js +7 -6
  512. package/extensions/dm-mcp-adapter/sampling-handler.js +8 -2
  513. package/extensions/dm-mcp-adapter/script-tool-save.js +251 -0
  514. package/extensions/dm-mcp-adapter/script-tool-surface.js +100 -0
  515. package/extensions/dm-mcp-adapter/script-tools.js +72 -0
  516. package/extensions/dm-mcp-adapter/semantic-search.js +176 -50
  517. package/extensions/dm-mcp-adapter/semantic-settings.js +51 -0
  518. package/extensions/dm-mcp-adapter/server-log.js +19 -0
  519. package/extensions/dm-mcp-adapter/server-manager.js +64 -21
  520. package/extensions/dm-mcp-adapter/task-entries.js +60 -0
  521. package/extensions/dm-mcp-adapter/task-jobs.js +263 -0
  522. package/extensions/dm-mcp-adapter/tool-approval.js +49 -2
  523. package/extensions/dm-mcp-adapter/tool-metadata.js +70 -3
  524. package/extensions/dm-mcp-adapter/tool-registrar.js +8 -1
  525. package/extensions/dm-mcp-adapter/tool-result-renderer.js +10 -6
  526. package/extensions/dm-mcp-adapter/types.js +7 -0
  527. package/extensions/dm-mcp-adapter/ui-server.js +24 -18
  528. package/extensions/dm-mcp-adapter/ui-session.js +3 -3
  529. package/extensions/dm-mcp-adapter/upgrade-notice.js +42 -0
  530. package/extensions/dm-mcp-adapter/utils.js +33 -7
  531. package/extensions/dm-ponytail/extensions/ponytail.mjs +11 -3
  532. package/extensions/dm-ponytail/hooks/band/board.js +524 -0
  533. package/extensions/dm-ponytail/hooks/band/logo.js +2 -0
  534. package/extensions/dm-ponytail/hooks/band/metrics.js +238 -0
  535. package/extensions/dm-ponytail/hooks/band/register.js +532 -0
  536. package/extensions/dm-ponytail/hooks/claude-band.json +6 -0
  537. package/extensions/dm-ponytail/hooks/claude-codex-hooks.json +6 -6
  538. package/extensions/dm-ponytail/hooks/copilot-hooks.json +6 -6
  539. package/extensions/dm-ponytail/hooks/cursor-hooks.json +2 -2
  540. package/extensions/dm-ponytail/hooks/ponytail-activate.js +105 -70
  541. package/extensions/dm-ponytail/hooks/ponytail-band-import.js +308 -0
  542. package/extensions/dm-ponytail/hooks/ponytail-config.js +4 -0
  543. package/extensions/dm-ponytail/hooks/ponytail-instructions.js +1 -1
  544. package/extensions/dm-ponytail/hooks/ponytail-map.js +7 -3
  545. package/extensions/dm-ponytail/hooks/ponytail-mode-tracker.js +41 -4
  546. package/extensions/dm-ponytail/hooks/ponytail-runtime.js +11 -8
  547. package/extensions/dm-ponytail/pi-extension/index.js +11 -3
  548. package/extensions/dm-ponytail/skills/ponytail/SKILL.md +1 -1
  549. package/extensions/dm-ponytail/skills/ponytail-debt/SKILL.md +4 -5
  550. package/extensions/dm-ponytail/skills/ponytail-gain/SKILL.md +0 -1
  551. package/extensions/dm-ponytail/skills/ponytail-help/SKILL.md +6 -0
  552. package/extensions/dm-skills-manager/package.json +1 -1
  553. package/extensions/dm-subagents/VISION.md +98 -0
  554. package/extensions/dm-subagents/agents/evidence-auditor.md +1 -0
  555. package/extensions/dm-subagents/agents/oracle.md +1 -0
  556. package/extensions/dm-subagents/agents/reviewer.md +1 -0
  557. package/extensions/dm-subagents/package.json +2 -1
  558. package/extensions/dm-subagents/scripts/build-package.mjs +128 -0
  559. package/extensions/dm-subagents/skills/council-mode/SKILL.md +1 -4
  560. package/extensions/dm-subagents/skills/dm-subagents/SKILL.md +130 -106
  561. package/extensions/dm-subagents/skills/dm-subagents/references/execution-controls.md +4 -3
  562. package/extensions/dm-subagents/skills/dm-subagents/references/orchestration.md +124 -0
  563. package/extensions/dm-subagents/skills/dm-subagents/references/prompting-and-roles.md +96 -295
  564. package/extensions/dm-subagents/src/agents/agent-management.js +14 -19
  565. package/extensions/dm-subagents/src/agents/agent-memory.js +2 -1
  566. package/extensions/dm-subagents/src/agents/agent-serializer.js +1 -2
  567. package/extensions/dm-subagents/src/agents/agents.js +7 -8
  568. package/extensions/dm-subagents/src/agents/frontmatter.js +34 -16
  569. package/extensions/dm-subagents/src/agents/skills.js +1 -1
  570. package/extensions/dm-subagents/src/api/background-work.js +8 -5
  571. package/extensions/dm-subagents/src/api/external-runs.js +3 -4
  572. package/extensions/dm-subagents/src/extension/active-runs-prompt.js +20 -0
  573. package/extensions/dm-subagents/src/extension/config.js +12 -0
  574. package/extensions/dm-subagents/src/extension/declaration-pinning.js +20 -3
  575. package/extensions/dm-subagents/src/extension/herdr-dm-bridge.js +24 -12
  576. package/extensions/dm-subagents/src/extension/index.js +125 -20
  577. package/extensions/dm-subagents/src/extension/public-execution.js +3 -0
  578. package/extensions/dm-subagents/src/extension/reply-workflow-script.js +3 -2
  579. package/extensions/dm-subagents/src/extension/rpc.js +5 -3
  580. package/extensions/dm-subagents/src/extension/schemas.js +6 -5
  581. package/extensions/dm-subagents/src/extension/subagent-guide.js +1 -2
  582. package/extensions/dm-subagents/src/extension/tool-activation.js +60 -26
  583. package/extensions/dm-subagents/src/extension/tool-description.js +2 -2
  584. package/extensions/dm-subagents/src/extension/upgrade-notice.js +5 -1
  585. package/extensions/dm-subagents/src/intercom/native-supervisor-channel.js +143 -15
  586. package/extensions/dm-subagents/src/missions/actions.js +4 -1
  587. package/extensions/dm-subagents/src/missions/lifecycle.js +32 -8
  588. package/extensions/dm-subagents/src/missions/store.js +1 -0
  589. package/extensions/dm-subagents/src/runs/background/active-async-capacity.js +15 -9
  590. package/extensions/dm-subagents/src/runs/background/async-execution.js +30 -16
  591. package/extensions/dm-subagents/src/runs/background/async-job-tracker.js +12 -3
  592. package/extensions/dm-subagents/src/runs/background/async-resume.js +5 -3
  593. package/extensions/dm-subagents/src/runs/background/async-status-snapshot.js +4 -2
  594. package/extensions/dm-subagents/src/runs/background/async-status.js +32 -10
  595. package/extensions/dm-subagents/src/runs/background/auto-drain.js +2 -1
  596. package/extensions/dm-subagents/src/runs/background/await-async-run.js +2 -7
  597. package/extensions/dm-subagents/src/runs/background/boot-id.js +36 -0
  598. package/extensions/dm-subagents/src/runs/background/chain-root-attachment.js +4 -4
  599. package/extensions/dm-subagents/src/runs/background/index-segment.js +1 -1
  600. package/extensions/dm-subagents/src/runs/background/inspect-rpc.js +17 -3
  601. package/extensions/dm-subagents/src/runs/background/interrupted-elsewhere.js +55 -0
  602. package/extensions/dm-subagents/src/runs/background/notify.js +98 -10
  603. package/extensions/dm-subagents/src/runs/background/result-delivery-ownership.js +20 -22
  604. package/extensions/dm-subagents/src/runs/background/result-files.js +9 -6
  605. package/extensions/dm-subagents/src/runs/background/result-watcher.js +32 -17
  606. package/extensions/dm-subagents/src/runs/background/resume-guidance.js +2 -1
  607. package/extensions/dm-subagents/src/runs/background/retained-children.js +1 -1
  608. package/extensions/dm-subagents/src/runs/background/run-child-session.js +40 -21
  609. package/extensions/dm-subagents/src/runs/background/run-status.js +12 -5
  610. package/extensions/dm-subagents/src/runs/background/runner-aliases.js +7 -5
  611. package/extensions/dm-subagents/src/runs/background/runner-child-launch.js +1 -2
  612. package/extensions/dm-subagents/src/runs/background/stale-run-reconciler.js +89 -21
  613. package/extensions/dm-subagents/src/runs/background/subagent-runner-bootstrap.js +2 -0
  614. package/extensions/dm-subagents/src/runs/background/subagent-runner.js +190 -244
  615. package/extensions/dm-subagents/src/runs/background/subagent-wait.js +5 -2
  616. package/extensions/dm-subagents/src/runs/background/terminal-run-index.js +39 -4
  617. package/extensions/dm-subagents/src/runs/background/wait-subscriptions.js +5 -1
  618. package/extensions/dm-subagents/src/runs/background/workflow-terminal-proof.js +28 -2
  619. package/extensions/dm-subagents/src/runs/foreground/async-dismiss-action.js +2 -1
  620. package/extensions/dm-subagents/src/runs/foreground/async-steering-action.js +21 -7
  621. package/extensions/dm-subagents/src/runs/foreground/async-stop-action.js +10 -8
  622. package/extensions/dm-subagents/src/runs/foreground/command-action.js +2 -1
  623. package/extensions/dm-subagents/src/runs/foreground/execution.js +107 -66
  624. package/extensions/dm-subagents/src/runs/foreground/foreground-history.js +111 -32
  625. package/extensions/dm-subagents/src/runs/foreground/prompt-audit.js +2 -2
  626. package/extensions/dm-subagents/src/runs/foreground/subagent-executor.js +377 -126
  627. package/extensions/dm-subagents/src/runs/shared/async-status-projection.js +18 -1
  628. package/extensions/dm-subagents/src/runs/shared/child-commands.js +7 -1
  629. package/extensions/dm-subagents/src/runs/shared/child-runtime-config.js +1 -0
  630. package/extensions/dm-subagents/src/runs/shared/child-session.js +184 -65
  631. package/extensions/dm-subagents/src/runs/shared/child-tool-plan.js +14 -3
  632. package/extensions/dm-subagents/src/runs/shared/dm-spawn.js +71 -25
  633. package/extensions/dm-subagents/src/runs/shared/external-cli-runner.js +2 -1
  634. package/extensions/dm-subagents/src/runs/shared/herdr-connection.js +20 -10
  635. package/extensions/dm-subagents/src/runs/shared/herdr-external-adapters.js +1 -1
  636. package/extensions/dm-subagents/src/runs/shared/herdr-machine.js +50 -8
  637. package/extensions/dm-subagents/src/runs/shared/herdr-pane-host.js +212 -0
  638. package/extensions/dm-subagents/src/runs/shared/herdr-placed-run.js +47 -503
  639. package/extensions/dm-subagents/src/runs/shared/local-machine-access.js +29 -0
  640. package/extensions/dm-subagents/src/runs/shared/long-running-guard.js +70 -17
  641. package/extensions/dm-subagents/src/runs/shared/model-resolution.js +7 -1
  642. package/extensions/dm-subagents/src/runs/shared/nested-events.js +2 -0
  643. package/extensions/dm-subagents/src/runs/shared/orca-progress-tabs.js +2 -24
  644. package/extensions/dm-subagents/src/runs/shared/parallel-handoff.js +9 -6
  645. package/extensions/dm-subagents/src/runs/shared/partial-output.js +5 -0
  646. package/extensions/dm-subagents/src/runs/shared/placed-run-owner.js +157 -0
  647. package/extensions/dm-subagents/src/runs/shared/placement-host.js +166 -0
  648. package/extensions/dm-subagents/src/runs/shared/rex-machine.js +75 -0
  649. package/extensions/dm-subagents/src/runs/shared/rex-pane-host.js +306 -0
  650. package/extensions/dm-subagents/src/runs/shared/run-ownership.js +7 -0
  651. package/extensions/dm-subagents/src/runs/shared/single-output.js +29 -6
  652. package/extensions/dm-subagents/src/runs/shared/structured-output.js +1 -0
  653. package/extensions/dm-subagents/src/runs/shared/subagent-control.js +2 -1
  654. package/extensions/dm-subagents/src/runs/shared/subagent-prompt-runtime.js +177 -17
  655. package/extensions/dm-subagents/src/runs/shared/tool-budget.js +1 -1
  656. package/extensions/dm-subagents/src/shared/accessible-dir.js +1 -1
  657. package/extensions/dm-subagents/src/shared/child-transcript.js +1 -1
  658. package/extensions/dm-subagents/src/shared/completion-owner.js +1 -0
  659. package/extensions/dm-subagents/src/shared/dm-declarations.js +36 -1
  660. package/extensions/dm-subagents/src/shared/dm-safeguards.js +1 -1
  661. package/extensions/dm-subagents/src/shared/dm-settlement.js +2 -0
  662. package/extensions/dm-subagents/src/shared/extension-context.js +3 -0
  663. package/extensions/dm-subagents/src/shared/file-lease.js +4 -1
  664. package/extensions/dm-subagents/src/shared/fork-context.js +21 -8
  665. package/extensions/dm-subagents/src/shared/parent-wake.js +6 -11
  666. package/extensions/dm-subagents/src/shared/provider-diagnostics.js +59 -0
  667. package/extensions/dm-subagents/src/shared/session-identity.js +24 -0
  668. package/extensions/dm-subagents/src/shared/session-succession.js +18 -0
  669. package/extensions/dm-subagents/src/shared/types.js +5 -4
  670. package/extensions/dm-subagents/src/shared/utils.js +13 -0
  671. package/extensions/dm-subagents/src/slash/delegation-adapters.js +8 -1
  672. package/extensions/dm-subagents/src/slash/prompt-template-bridge.js +2 -1
  673. package/extensions/dm-subagents/src/slash/slash-commands.js +6 -4
  674. package/extensions/dm-subagents/src/slash/subagents-admin.js +3 -2
  675. package/extensions/dm-subagents/src/tui/dm-mouse-region.js +9 -1
  676. package/extensions/dm-subagents/src/tui/fleet-layout.js +19 -0
  677. package/extensions/dm-subagents/src/tui/fleet-status.js +20 -3
  678. package/extensions/dm-subagents/src/tui/fleet-viewport.js +59 -0
  679. package/extensions/dm-subagents/src/tui/fleet.js +92 -69
  680. package/extensions/dm-subagents/src/tui/render.js +45 -19
  681. package/extensions/dm-subagents/src/tui/subagent-messages.js +1 -0
  682. package/extensions/dm-subagents/src/watchdog/change-signature.js +1 -3
  683. package/extensions/dm-subagents/src/watchdog/diff-tool.js +7 -3
  684. package/extensions/dm-subagents/src/watchdog/permission-arbiter.js +15 -6
  685. package/extensions/dm-subagents/src/watchdog/register-main.js +10 -9
  686. package/extensions/dm-subagents/src/watchdog/review.js +9 -1
  687. package/extensions/dm-subagents/src/watchdog/runtime.js +3 -5
  688. package/extensions/dm-subagents/src/workflows/scripted-workflow.js +33 -6
  689. package/extensions/dm-subagents/src/workflows/structured-workflow-scripts.js +21 -8
  690. package/extensions/dm-subagents/src/workflows/workflow-auto-resume.js +81 -0
  691. package/extensions/dm-subagents/src/workflows/workflow-child-summary.js +18 -2
  692. package/extensions/dm-subagents/src/workflows/workflow-launch-record.js +45 -0
  693. package/extensions/dm-subagents/src/workflows/workflow-resources.js +2 -2
  694. package/extensions/dm-subagents/src/workflows/workflow-resume-claim.js +171 -0
  695. package/extensions/dm-subagents/src/workflows/workflow-resume.js +88 -0
  696. package/extensions/dm-subagents/src/workflows/workflow-reuse.js +72 -3
  697. package/extensions/dm-subagents/src/workflows/workflow-revival.js +1 -1
  698. package/extensions/dm-subagents/src/workflows/workflow-stop-cause.js +5 -0
  699. package/extensions/dm-web-access/.github/workflows/test.yml +28 -0
  700. package/extensions/dm-web-access/anysearch.js +3 -3
  701. package/extensions/dm-web-access/bocha.js +3 -3
  702. package/extensions/dm-web-access/brave-rate-limit.js +2 -2
  703. package/extensions/dm-web-access/brave.js +5 -10
  704. package/extensions/dm-web-access/brightdata-unlocker.js +2 -2
  705. package/extensions/dm-web-access/brightdata.js +3 -3
  706. package/extensions/dm-web-access/ceramic.js +2 -2
  707. package/extensions/dm-web-access/chrome-cookies.js +1 -1
  708. package/extensions/dm-web-access/claim-judge.js +147 -0
  709. package/extensions/dm-web-access/content-find.js +1 -1
  710. package/extensions/dm-web-access/credential-source.js +42 -5
  711. package/extensions/dm-web-access/curator-page.js +8 -2
  712. package/extensions/dm-web-access/curator-server.js +6 -0
  713. package/extensions/dm-web-access/deepseek.js +331 -0
  714. package/extensions/dm-web-access/duckduckgo-rate-limit.js +75 -0
  715. package/extensions/dm-web-access/duckduckgo.js +49 -43
  716. package/extensions/dm-web-access/endpoint-pdf-extract.js +30 -77
  717. package/extensions/dm-web-access/eval/claim-judge.mjs +96 -0
  718. package/extensions/dm-web-access/eval/field-extract.mjs +84 -0
  719. package/extensions/dm-web-access/eval/fixtures/claims-calibration.json +1026 -0
  720. package/extensions/dm-web-access/eval/fixtures/claims-holdout.json +896 -0
  721. package/extensions/dm-web-access/eval/fixtures/claims-sibling-holdout.json +226 -0
  722. package/extensions/dm-web-access/eval/fixtures/extract-calibration.json +12 -0
  723. package/extensions/dm-web-access/eval/fixtures/extract-holdout.json +172 -0
  724. package/extensions/dm-web-access/eval/fixtures/offtopic-calibration.json +103 -0
  725. package/extensions/dm-web-access/eval/fixtures/offtopic-holdout.json +307 -0
  726. package/extensions/dm-web-access/eval/offtopic-judge.mjs +66 -0
  727. package/extensions/dm-web-access/evidence/CONTRACT-EVIDENCE.md +496 -0
  728. package/extensions/dm-web-access/evidence/contract-probe.mjs +127 -0
  729. package/extensions/dm-web-access/exa.js +42 -4
  730. package/extensions/dm-web-access/extract.js +110 -19
  731. package/extensions/dm-web-access/fetch-params.js +12 -3
  732. package/extensions/dm-web-access/field-extract.js +324 -0
  733. package/extensions/dm-web-access/gemini-adc.js +47 -1
  734. package/extensions/dm-web-access/gemini-api.js +11 -0
  735. package/extensions/dm-web-access/gemini-search.js +204 -196
  736. package/extensions/dm-web-access/github-extract.js +1 -1
  737. package/extensions/dm-web-access/github-issue-pr.js +6 -6
  738. package/extensions/dm-web-access/index.js +159 -112
  739. package/extensions/dm-web-access/jina-search.js +6 -4
  740. package/extensions/dm-web-access/kagi.js +4 -4
  741. package/extensions/dm-web-access/keenable.js +2 -2
  742. package/extensions/dm-web-access/linkup.js +160 -0
  743. package/extensions/dm-web-access/mistral-search.js +4 -4
  744. package/extensions/dm-web-access/ninerouter.js +100 -0
  745. package/extensions/dm-web-access/offtopic-judge.js +56 -0
  746. package/extensions/dm-web-access/ollama.js +4 -4
  747. package/extensions/dm-web-access/openai-search.js +32 -12
  748. package/extensions/dm-web-access/package.json +1 -1
  749. package/extensions/dm-web-access/page-query.js +7 -4
  750. package/extensions/dm-web-access/parallel.js +6 -7
  751. package/extensions/dm-web-access/pdf-extract.js +1 -3
  752. package/extensions/dm-web-access/perplexity.js +6 -5
  753. package/extensions/dm-web-access/querit.js +3 -3
  754. package/extensions/dm-web-access/query-rewrite.js +32 -8
  755. package/extensions/dm-web-access/scripts/dm-extensions-dist.js +16 -0
  756. package/extensions/dm-web-access/scripts/publish.js +38 -0
  757. package/extensions/dm-web-access/search1api.js +3 -3
  758. package/extensions/dm-web-access/searchinfinity.js +3 -3
  759. package/extensions/dm-web-access/searxng.js +2 -1
  760. package/extensions/dm-web-access/serpapi.js +6 -5
  761. package/extensions/dm-web-access/serpbase.js +4 -4
  762. package/extensions/dm-web-access/serpdive.js +3 -3
  763. package/extensions/dm-web-access/serper.js +5 -4
  764. package/extensions/dm-web-access/serply.js +2 -2
  765. package/extensions/dm-web-access/source-check.js +22 -14
  766. package/extensions/dm-web-access/ssrf-protection.js +29 -4
  767. package/extensions/dm-web-access/summary-model-scope.js +11 -1
  768. package/extensions/dm-web-access/summary-review.js +36 -43
  769. package/extensions/dm-web-access/tool-activation.js +11 -2
  770. package/extensions/dm-web-access/upgrade-notice.js +41 -0
  771. package/extensions/dm-web-access/utils.js +51 -3
  772. package/extensions/dm-web-access/valyu.js +3 -3
  773. package/extensions/dm-web-access/video-extract.js +3 -2
  774. package/extensions/dm-web-access/web-tool-core.js +161 -51
  775. package/extensions/dm-web-access/xai-search.js +44 -9
  776. package/extensions/dm-web-access/xcrawl.js +3 -3
  777. package/extensions/dm-web-access/you.js +2 -2
  778. package/package.json +4 -4
  779. package/extensions/dm-web-access/dist/index.js +0 -28396
  780. package/extensions/dm-web-access/dist/mcp-cli.js +0 -28185
  781. /package/extensions/dm-lens/skills/{pi-lens-lsp-navigation → dm-lens-lsp-navigation}/SKILL.md +0 -0
  782. /package/extensions/dm-lens/skills/{pi-lens-write-ast-grep-rule → dm-lens-write-ast-grep-rule}/SKILL.md +0 -0
  783. /package/extensions/dm-lens/skills/{pi-lens-write-ast-grep-rule → dm-lens-write-ast-grep-rule}/reference.md +0 -0
  784. /package/extensions/dm-lens/skills/{pi-lens-write-tree-sitter-rule → dm-lens-write-tree-sitter-rule}/SKILL.md +0 -0
@@ -1,19 +1,20 @@
1
1
  import { CASCADE_DIAGNOSTICS_TTL_MS } from "../cascade-types.js";
2
2
  import * as nodeFs from "node:fs";
3
3
  import fs from "node:fs/promises";
4
+ import os from "node:os";
4
5
  import path from "node:path";
5
6
  import { pathToFileURL, URL } from "node:url";
6
7
  import { BoundedFifoMap } from "../bounded-cache.js";
8
+ import { CONTENT_HASH_MAX_BYTES, stampContentBytes } from "../content-stamp.js";
9
+ import { FILE_CHANGED, FILE_CREATED, watchedTypeForOpen } from "./watch-queue.js";
10
+ import { noteWorkspaceFilesChangedOnDisk, workspaceFileCreatedAtFor } from "./workspace-diagnostics-session.js";
11
+ import { emitCreatedImportScanRollupAtSessionEnd, goPackageFilesToAnnounce, importTargetsToAnnounce } from "./created-import-targets.js";
7
12
  import { getProjectIgnoreMatcher, isExcludedDirName } from "../file-utils.js";
8
- import { recordLsp } from "../widget-state.js";
9
13
  import { applyAuxiliarySuppressions } from "../dispatch/auxiliary-lsp.js";
10
14
  import { detectFileRole } from "../file-role.js";
11
15
  import { emitBounded } from "../bounded-telemetry.js";
12
16
  import { logLatency, phaseFinished, phaseStarted } from "../latency-logger.js";
13
- import { logSessionStart } from "../sessionstart-logger.js";
14
- import { incrementDegradationCount, recordDegradation, recordDegradationOnce } from "../degradation-ledger.js";
15
- import { assertInstallAllowed } from "../project-trust.js";
16
- import { isLspSpawnAllowedByTrust, projectTrustDenialReason } from "../project-trust.js";
17
+ import { incrementDegradationCount, recordDegradationOnce } from "../degradation-ledger.js";
17
18
  import { shouldPreferPullOnlyDiagnostics } from "../lsp-budget.js";
18
19
  import { sampleProcessTreeCpuPercent } from "../resource-sampler.js";
19
20
  import { bounded, withDeadline, withTimeout } from "../deadline-utils.js";
@@ -22,24 +23,22 @@ import { getAmbientAbortSignal } from "../safe-spawn.js";
22
23
  import { abortDeferredLspWork } from "../deferred-lsp-work.js";
23
24
  import { acquireWorkspaceSweepHold, clearWorkspaceSweepHoldForSessionStart } from "./workspace-sweep-hold.js";
24
25
  import { DocumentDriftTracker, fingerprintDocumentContent } from "./document-drift.js";
26
+ import { exceedsLspSyncLimits } from "./content-limits.js";
25
27
  import { captureAuxPublicationBacklog, markPendingAuxiliaryCoverage, napiFallbackCoveredSince } from "./pending-aux-coverage.js";
26
- import { isAtOrAboveHomeDir, isWindowsPath, normalizeMapKey, uriToPath } from "../path-utils.js";
28
+ import { isAtOrAboveHomeDir, normalizeMapKey, realpathOrResolve, uriToPath } from "../path-utils.js";
27
29
  import { recordLspMutation } from "../lsp-mutation.js";
28
- import { createLSPClient } from "./client.js";
29
- import { auxiliaryCoverageGap, auxiliaryPublicationEvidence, bindingStateLabel, composeBoundToCurrentDisk, createDiskBindingCache, hashDiagnosticContent, resolveTouchVerdict, touchCoverageGap } from "./diagnostic-binding.js";
30
- import { getServersForFileWithConfig, getServerInitOverride } from "./config.js";
31
- import { getSessionRootsForTelemetry, isOutsideAllSessionRoots } from "./session-roots.js";
32
- import { findLocalBinUpwards, isProjectLocalBinPath } from "../package-manager.js";
33
- import { resolveAnalysisRoot, resolveAnalysisRootPath } from "../analysis-root.js";
30
+ import { auxiliaryCoverageGap, auxiliaryPublicationEvidence, bindingStateLabel, composeBoundToCurrentDisk, createDiskBindingCache, hashDiagnosticContent, primaryUnavailableCause, resolveTouchVerdict, touchCoverageGap } from "./diagnostic-binding.js";
31
+ import { getServersForFileWithConfig } from "./config.js";
32
+ import { serverIdsForConfigFile } from "./server-config-files.js";
33
+ import { disabledPrimaries, getSessionRootsForTelemetry } from "./session-roots.js";
34
34
  import { configureLspServiceLifecycle, getOwnedLspService, peekOwnedLspService, resetOwnedLspService } from "./service-singleton.js";
35
35
  import { groupFilesByPrimaryServer, runPerServerGroups } from "./grouping.js";
36
36
  export { groupFilesByPrimaryServer, runPerServerGroups } from "./grouping.js";
37
- import { isEphemeralCheckoutRoot } from "../ephemeral-root.js";
37
+ import { BROKEN_BASE_COOLDOWN_MS, ClientRegistry } from "./client-registry.js";
38
+ export { getLspClientCeiling, getLspIdleEvictMs, getLspIdleEvictMsForRoot, mergeInitializationOptions } from "./client-registry.js";
38
39
  import { getLanguageId } from "./language.js";
39
40
  import { getReverseDepsFromIndex, loadReverseDependencyIndexFromSnapshot } from "../reverse-deps.js";
40
- import { isSameOrWithin } from "./server.js";
41
- import { refuseUntrustedLspExecution, withLspProjectCodePermission } from "./launch.js";
42
- import { enforceLspRootCeiling, getServerById, hasProjectBoundaryMarker, isDirectLspCommandTemporarilyUnavailable, resetClassicTsRepairGuard, resetLspLaunchAvailabilityGeneration, resolveLspServerCwd } from "./server.js";
41
+ import { declinesLooseFileRoot, getServerById, resetClassicTsRepairGuard, resetLspLaunchAvailabilityGeneration } from "./server.js";
43
42
  import { isAuxiliary, serverTraits } from "./server-traits.js";
44
43
  import { auxWaitBudgetMs, readEnvAuxGraceMs, DEFAULT_AUX_GRACE_CEILING_MS } from "./auxiliary-lifecycle.js";
45
44
  import { classifyCascadeWaitTier, classifyServerWaitTier, getStrategy } from "./wait-policy/index.js";
@@ -56,14 +55,13 @@ const AUX_WAIT_DEMOTION_THRESHOLD = 5;
56
55
  const AUX_WAIT_DEMOTION_RATIO = 0.9;
57
56
  const AUX_WAIT_REPROMOTION_THRESHOLD = 5;
58
57
  const AUX_WAIT_REPROMOTION_RATIO = 0.5;
59
- const ADOPTED_ROOT_CAP = 2;
60
- const ADOPTED_ROOT_IDLE_EVICT_MS = 60000;
61
58
  import { raceToCompletion } from "./aggregation.js";
62
- import { applyWorkspaceEdit, mergeWorkspaceTextEditsByPriority, summarizeWorkspaceEdit, validateWorkspaceEdit } from "./edits.js";
59
+ import { applyWorkspaceEdit, captureRenameExpectedContent, mergeWorkspaceTextEditsByPriority, summarizeWorkspaceEdit, validateWorkspaceEdit } from "./edits.js";
63
60
  import { buildScopeKey, createWorkspaceDiagnosticsCacheContext } from "./workspace-diagnostics-cache.js";
61
+ import { demoteInferredProjectDiagnostics } from "./inferred-project.js";
64
62
  import { attemptTsserverSyncDiagnostics } from "./tsserver-sync.js";
65
63
  import { isWarmAttached, tryWarmAttachedDiagnostics } from "../warm-attach.js";
66
- import { getSuccessfulLspSpawnDurationMs, recordSuccessfulLspSpawn } from "./spawn-history.js";
64
+ import { getSuccessfulLspSpawnDurationMs } from "./spawn-history.js";
67
65
  function destinationUriPreservingSpelling(oldUri, oldFilePath, newFilePath) {
68
66
  const canonical = pathToFileURL(newFilePath);
69
67
  try {
@@ -98,36 +96,10 @@ function destinationUriPreservingSpelling(oldUri, oldFilePath, newFilePath) {
98
96
  return canonical.href;
99
97
  }
100
98
  }
101
- function deepMergeObjects(base, override) {
102
- const result = { ...base };
103
- for (const [key, val] of Object.entries(override)) {
104
- if (val !== null && typeof val === "object" && !Array.isArray(val) && result[key] !== null && typeof result[key] === "object" && !Array.isArray(result[key])) {
105
- result[key] = deepMergeObjects(result[key], val);
106
- } else {
107
- result[key] = val;
108
- }
109
- }
110
- return result;
111
- }
112
- export function mergeInitializationOptions(base, override) {
113
- if (!override)
114
- return base;
115
- if (!base)
116
- return override;
117
- return deepMergeObjects(base, override);
118
- }
119
- const BROKEN_BASE_COOLDOWN_MS = 15000;
120
- const BROKEN_MAX_COOLDOWN_MS = 5 * 60000;
121
- const BROKEN_PERMANENT_AFTER = 5;
122
- const RUNTIME_EXIT_UPTIME_THRESHOLD_MS = 60000;
123
- const RUNTIME_EXIT_WINDOW_MS = 15 * 60000;
124
- const RUNTIME_EXIT_WINDOW_TRIP_COUNT = BROKEN_PERMANENT_AFTER;
125
- const RUNTIME_EXIT_WINDOW_UPTIME_CEILING_MS = 10 * 60000;
126
99
  const NOTIFY_BACKPRESSURE_BROKEN_AFTER = 3;
127
- const OPTIONAL_LSP_RETRY_COOLDOWN_MS = 5 * 60000;
128
- const OPTIONAL_LSP_SERVER_IDS = new Set;
129
100
  const NAV_CLIENT_WAIT_TIMEOUT_MS = Math.max(0, Number.parseInt(process.env.DM_LENS_LSP_NAV_CLIENT_WAIT_MS ?? "1500", 10) || 1500);
130
101
  const TOUCH_DEBOUNCE_MS = Math.max(0, Number.parseInt(process.env.DM_LENS_LSP_TOUCH_DEBOUNCE_MS ?? "1500", 10) || 1500);
102
+ const RECENT_TOUCH_CAP = 800;
131
103
  const SCOPED_DEPENDENCY_TOUCH_MAX = 32;
132
104
  const RENAME_NOTIFY_TIMEOUT_MS = Math.max(50, Number.parseInt(process.env.DM_LENS_LSP_RENAME_NOTIFY_TIMEOUT_MS ?? "1500", 10) || 1500);
133
105
  async function runRenameNotify(send, timeoutMs) {
@@ -143,31 +115,6 @@ async function runRenameNotify(send, timeoutMs) {
143
115
  };
144
116
  }
145
117
  }
146
- const DEFAULT_LSP_CLIENT_CEILING = 24;
147
- const DEFAULT_IDLE_EVICT_MS = 20 * 60000;
148
- const DEFAULT_EPHEMERAL_IDLE_EVICT_MS = 60000;
149
- export function getLspIdleEvictMs() {
150
- for (const name of [
151
- "DM_LENS_LSP_IDLE_EVICT_MS",
152
- "DM_LENS_TS_IDLE_EVICT_MS"
153
- ]) {
154
- const parsed = Number.parseInt(process.env[name] ?? "", 10);
155
- if (Number.isSafeInteger(parsed) && parsed > 0)
156
- return parsed;
157
- }
158
- return DEFAULT_IDLE_EVICT_MS;
159
- }
160
- function getEphemeralLspIdleEvictMs() {
161
- const parsed = Number.parseInt(process.env.DM_LENS_EPHEMERAL_LSP_IDLE_EVICT_MS ?? "", 10);
162
- return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : DEFAULT_EPHEMERAL_IDLE_EVICT_MS;
163
- }
164
- export function getLspIdleEvictMsForRoot(root) {
165
- return isEphemeralCheckoutRoot(root) ? getEphemeralLspIdleEvictMs() : getLspIdleEvictMs();
166
- }
167
- export function getLspClientCeiling() {
168
- const parsed = Number.parseInt(process.env.DM_LENS_LSP_CLIENT_CEILING ?? "", 10);
169
- return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : DEFAULT_LSP_CLIENT_CEILING;
170
- }
171
118
  function documentIsOpenOn(client, filePath) {
172
119
  const probe = client.isDocumentOpen;
173
120
  if (typeof probe !== "function")
@@ -214,6 +161,19 @@ const MAX_TOUCH_CANDIDATES = 8;
214
161
  const DIAGNOSTICS_SEMANTIC_SETTLE_THRESHOLD_MS = Math.max(0, Number.parseInt(process.env.DM_LENS_LSP_DIAGNOSTICS_SEMANTIC_THRESHOLD_MS ?? "250", 10) || 250);
215
162
  const DIAGNOSTICS_SEMANTIC_SETTLE_WAIT_MS = Math.max(0, Number.parseInt(process.env.DM_LENS_LSP_DIAGNOSTICS_SEMANTIC_SETTLE_MS ?? "400", 10) || 400);
216
163
  const EARLY_UNBLOCK_GRACE_MS = Math.max(0, Number.parseInt(process.env.DM_LENS_LSP_EARLY_UNBLOCK_GRACE_MS ?? "400", 10) || 400);
164
+ function unansweredPrimaries(spawned, resolvedPrimaryRoots, filePath) {
165
+ if (spawned.some((entry) => !isAuxiliary(entry.info)))
166
+ return { serverIds: [], disabledServerIds: [], cause: "unstarted" };
167
+ const { disabledServerIds, fallbackServerIds } = disabledPrimaries(filePath);
168
+ const serverIds = [
169
+ ...new Set([...resolvedPrimaryRoots.keys(), ...disabledServerIds])
170
+ ];
171
+ return {
172
+ serverIds,
173
+ disabledServerIds,
174
+ cause: primaryUnavailableCause(serverIds, disabledServerIds, fallbackServerIds)
175
+ };
176
+ }
217
177
  function mergeLspDiagnostics(diagnostics) {
218
178
  const merged = [];
219
179
  const seen = new Set;
@@ -233,6 +193,12 @@ function mergeLspDiagnostics(diagnostics) {
233
193
  function attributeDiagnostics(serverId, diagnostics) {
234
194
  return diagnostics.map((diagnostic) => ({ ...diagnostic, serverId }));
235
195
  }
196
+ const SWEEP_REASON_FOR_CAUSE = {
197
+ unstarted: "primary_unavailable",
198
+ either: "primary_unavailable",
199
+ disabled: "primary_disabled",
200
+ disabledFallback: "primary_disabled_fallback"
201
+ };
236
202
  export function createSweepIndexGate() {
237
203
  const seen = new Set;
238
204
  return {
@@ -286,7 +252,7 @@ function getMaxWorkspaceDiagnosticFiles() {
286
252
  }
287
253
  async function collectWorkspaceDiagnosticFiles(root, maxFiles = getMaxWorkspaceDiagnosticFiles(), signal, homeDir) {
288
254
  const files = [];
289
- if (isAtOrAboveHomeDir(root, homeDir))
255
+ if (isAtOrAboveHomeDir(realpathOrResolve(root), realpathOrResolve(homeDir ?? os.homedir())))
290
256
  return files;
291
257
  const ignoreMatcher = getProjectIgnoreMatcher(root);
292
258
  await ignoreMatcher.ensureTrackedIndex();
@@ -324,28 +290,29 @@ async function collectWorkspaceDiagnosticFiles(root, maxFiles = getMaxWorkspaceD
324
290
 
325
291
  export class LSPService {
326
292
  static MAX_SIBLING_ANNOUNCEMENTS = 1024;
327
- sessionCwd;
293
+ static MAX_UNHELD_STAMPS = 4096;
328
294
  state;
295
+ unheldStamps = new BoundedFifoMap(LSPService.MAX_UNHELD_STAMPS);
329
296
  siblingAnnouncementHashes = new BoundedFifoMap(LSPService.MAX_SIBLING_ANNOUNCEMENTS);
330
- workspaceProbeLogged = new Set;
331
- projectBoundaryCache = new Map;
332
- warmStartLogged = new Set;
333
- optionalFailureLogged = new Set;
334
- unavailableLogged = new Set;
335
- optionalDisabled = new Set;
336
297
  firstContactWaits = new Map;
337
298
  auxWaitPressureStreak = new Map;
338
299
  auxWaitFastAnswerStreak = new Map;
339
300
  demotedAuxiliaryServerIds = new Set;
340
301
  demotedAuxiliaryBudgets = new Map;
341
- lastSpawnVerdict = new Map;
342
- failureCounts = new Map;
343
- runtimeExitCounts = new Map;
344
- runtimeExitWindow = new Map;
345
- permanentlyBroken = new Set;
346
302
  lastKnownDiagnostics = new Map;
347
303
  lastKnownContentHash = new Map;
348
- documentDrift = new DocumentDriftTracker;
304
+ documentDrift = new DocumentDriftTracker({
305
+ holdsDocument: (filePath) => this.hasLiveClientHoldingDocument(filePath),
306
+ onCapOverflow: ({ tracked, cap }) => {
307
+ logLatency({
308
+ type: "phase",
309
+ phase: "lsp_document_drift_cap",
310
+ filePath: "",
311
+ durationMs: 0,
312
+ metadata: { tracked, cap }
313
+ });
314
+ }
315
+ });
349
316
  diskBindingCache = createDiskBindingCache();
350
317
  lastDiagnosticsHealth = new Map;
351
318
  recentTouches = new Map;
@@ -355,24 +322,34 @@ export class LSPService {
355
322
  outstandingAuxNotifyWrites = new Map;
356
323
  static MAX_NOTIFY_STALL_DEMOTIONS = 50;
357
324
  notifyStallDemotions = new BoundedFifoMap(LSPService.MAX_NOTIFY_STALL_DEMOTIONS);
358
- clientLastUsedAt = new Map;
359
- adoptedRootLastUsedAt = new Map;
360
- adoptedClientKeys = new Set;
361
- clientLeases = new Map;
362
- idleEvictionTimers = new Map;
363
- clientSpawnGate = Promise.resolve();
364
- isDestroyed = false;
365
325
  shutdownController = new AbortController;
366
- generationHandoff;
326
+ clientRegistry;
367
327
  constructor(generationHandoff, sessionCwd) {
368
- this.generationHandoff = generationHandoff;
369
- this.sessionCwd = sessionCwd;
328
+ this.clientRegistry = new ClientRegistry({
329
+ releaseNotifyWrite: (key) => this.releaseOutstandingAuxNotifyWrite(key),
330
+ forgetReadiness: (key) => this.forgetReadiness(key),
331
+ forgetNotifyBacklog: (key) => {
332
+ this.auxNotifyInflight.delete(key);
333
+ this.auxNotifyDrainLatencyEwma.delete(key);
334
+ },
335
+ clearStallDemotion: (key) => {
336
+ this.notifyStallDemotions.delete(key);
337
+ },
338
+ rearmFirstContact: (serverId) => {
339
+ this.state.diagnosticsPublished.delete(serverId);
340
+ this.state.diagnosticsUnsupported.delete(serverId);
341
+ this.firstContactWaits.delete(serverId);
342
+ },
343
+ noteDiagnosticsPublished: (serverId) => {
344
+ this.state.diagnosticsPublished.add(serverId);
345
+ }
346
+ }, generationHandoff, sessionCwd);
370
347
  this.state = {
371
- clients: new Map,
348
+ clients: this.clientRegistry.clients,
372
349
  servers: new Map,
373
- broken: new Map,
374
- inFlight: new Map,
375
- clientSpawnedAt: new Map,
350
+ broken: this.clientRegistry.broken,
351
+ inFlight: this.clientRegistry.inFlight,
352
+ clientSpawnedAt: this.clientRegistry.clientSpawnedAt,
376
353
  demonstratedReady: new Set,
377
354
  demonstratedCold: new Set,
378
355
  diagnosticsPublished: new Set,
@@ -426,120 +403,16 @@ export class LSPService {
426
403
  reason: "auxiliary produced five consecutive late answers below half its declared wait budget"
427
404
  });
428
405
  }
429
- analysisRootModeForFile(filePath) {
430
- const roots = getSessionRootsForTelemetry(128);
431
- if (this.sessionCwd)
432
- roots.push(this.sessionCwd);
433
- let adopted = false;
434
- for (const root of new Set(roots)) {
435
- const mode = resolveAnalysisRoot(filePath, root);
436
- if (mode === "session" || mode === "linked-worktree")
437
- return mode;
438
- adopted ||= mode === "adopted";
439
- }
440
- return adopted ? "adopted" : "none";
441
- }
442
- fileIsOutsideRegisteredRoots(filePath) {
443
- const roots = getSessionRootsForTelemetry(128);
444
- if (roots.length === 0)
445
- return isOutsideAllSessionRoots(filePath);
446
- return !roots.some((root) => isSameOrWithin(root, filePath));
447
- }
448
- admitAdoptedRoot(root, filePath) {
449
- if (this.analysisRootModeForFile(filePath) !== "adopted")
450
- return false;
451
- const normalized = normalizeMapKey(root);
452
- const liveRoots = new Set;
453
- for (const key of this.state.clients.keys()) {
454
- if (this.adoptedClientKeys.has(key))
455
- liveRoots.add(key.slice(key.indexOf(":") + 1));
456
- }
457
- for (const root of this.adoptedRootLastUsedAt.keys()) {
458
- if (!liveRoots.has(root))
459
- this.adoptedRootLastUsedAt.delete(root);
460
- }
461
- if (liveRoots.has(normalized)) {
462
- this.adoptedRootLastUsedAt.set(normalized, Date.now());
463
- return true;
464
- }
465
- if (this.adoptedRootLastUsedAt.size < ADOPTED_ROOT_CAP) {
466
- this.adoptedRootLastUsedAt.set(normalized, Date.now());
467
- return true;
468
- }
469
- this.adoptedRootLastUsedAt.set(normalized, Date.now());
470
- const victim = [...this.adoptedRootLastUsedAt.keys()].sort((a, b) => (this.adoptedRootLastUsedAt.get(a) ?? 0) - (this.adoptedRootLastUsedAt.get(b) ?? 0)).find((candidate) => candidate !== normalized);
471
- if (!victim)
472
- return true;
473
- this.adoptedRootLastUsedAt.delete(victim);
474
- for (const [key, client] of this.state.clients) {
475
- if (!this.adoptedClientKeys.has(key) || !key.endsWith(`:${victim}`))
476
- continue;
477
- if ((this.clientLeases.get(key) ?? 0) > 0)
478
- continue;
479
- this.retireClient(key);
480
- client.shutdown({ reason: "adopted-root-lru" }).catch(() => {});
481
- }
482
- incrementDegradationCount({
483
- kind: "lsp-adopted-root-evicted",
484
- subject: victim,
485
- reason: `adopted root cap ${ADOPTED_ROOT_CAP} evicted ${victim}`
486
- });
487
- return true;
488
- }
489
- async resolveServerRoot(server, filePath, onRootFailure) {
490
- const candidate = await resolveLspServerCwd(server, filePath, this.sessionCwd ?? process.cwd(), onRootFailure);
491
- if (!candidate)
492
- return;
493
- const mode = this.analysisRootModeForFile(filePath);
494
- if (mode === "adopted") {
495
- const classifierRoot = resolveAnalysisRootPath(filePath, this.sessionCwd ?? process.cwd());
496
- if (!classifierRoot || normalizeMapKey(classifierRoot) !== normalizeMapKey(candidate))
497
- return;
498
- }
499
- if (this.fileIsOutsideRegisteredRoots(filePath) && this.analysisRootModeForFile(filePath) !== "adopted")
500
- return;
501
- const root = enforceLspRootCeiling(candidate, process.cwd(), filePath);
502
- if (normalizeMapKey(root) === normalizeMapKey(process.cwd()))
503
- return root;
504
- const rootKey = normalizeMapKey(root);
505
- const prefix = `${server.id}:`;
506
- let nearestAncestor;
507
- for (const key of new Set([
508
- ...this.state.clients.keys(),
509
- ...this.state.inFlight.keys()
510
- ])) {
511
- if (!key.startsWith(prefix))
512
- continue;
513
- const ancestorKey = key.slice(prefix.length);
514
- const pathApi = isWindowsPath(ancestorKey) || isWindowsPath(rootKey) ? path.win32 : path;
515
- const relative = pathApi.relative(ancestorKey, rootKey);
516
- if (relative === "" || relative.startsWith("..") || pathApi.isAbsolute(relative)) {
517
- continue;
518
- }
519
- if (!nearestAncestor || ancestorKey.length > nearestAncestor.length) {
520
- nearestAncestor = ancestorKey;
521
- }
522
- }
523
- if (!nearestAncestor)
524
- return root;
525
- let boundary = this.projectBoundaryCache.get(rootKey);
526
- if (!boundary) {
527
- boundary = hasProjectBoundaryMarker(root);
528
- this.projectBoundaryCache.set(rootKey, boundary);
529
- }
530
- if (await boundary)
531
- return root;
532
- return this.state.clients.get(`${server.id}:${nearestAncestor}`)?.root ?? nearestAncestor;
533
- }
534
406
  checkDestroyed() {
535
- return this.isDestroyed;
407
+ return this.clientRegistry.checkDestroyed();
536
408
  }
537
409
  announceToSiblings(filePath, content, contentHash = this.hashContent(content)) {
538
410
  const normalizedPath = normalizeMapKey(filePath);
539
411
  if (this.siblingAnnouncementHashes.get(normalizedPath) === contentHash) {
540
412
  return Promise.resolve();
541
413
  }
542
- return Promise.all(getServersForFileWithConfig(filePath).map((server) => this.resolveServerRoot(server, filePath).then((root) => {
414
+ this.announceCreatedFiles([filePath]);
415
+ return Promise.all(getServersForFileWithConfig(filePath).map((server) => this.clientRegistry.resolveServerRoot(server, filePath).then((root) => {
543
416
  if (!root)
544
417
  return false;
545
418
  const ownKey = `${server.id}:${normalizeMapKey(root)}`;
@@ -560,121 +433,22 @@ export class LSPService {
560
433
  }
561
434
  return notified;
562
435
  }
563
- async withClientSpawnGate(operation) {
564
- const previous = this.clientSpawnGate;
565
- let release;
566
- this.clientSpawnGate = new Promise((resolve) => {
567
- release = resolve;
568
- });
569
- await previous;
570
- try {
571
- return await operation();
572
- } finally {
573
- release();
574
- }
575
- }
576
- async clientKeyFor(entry, filePath) {
577
- const root = await this.resolveServerRoot(entry.info, filePath);
578
- return root ? `${entry.info.id}:${normalizeMapKey(root)}` : undefined;
579
- }
580
- async acquireClientLease(entry, filePath) {
581
- const key = await this.clientKeyFor(entry, filePath);
582
- if (!key)
583
- return;
584
- return this.withClientSpawnGate(async () => {
585
- if (this.isDestroyed || this.state.clients.get(key) !== entry.client) {
586
- return;
587
- }
588
- this.clientLeases.set(key, (this.clientLeases.get(key) ?? 0) + 1);
589
- return key;
590
- });
591
- }
592
- async acquireClientLeases(entries, filePath) {
593
- const keys = await Promise.all(entries.map((entry) => this.clientKeyFor(entry, filePath)));
594
- if (keys.some((key) => key === undefined))
595
- return;
596
- const keyed = entries.map((entry, index) => [keys[index], entry]);
597
- return this.withClientSpawnGate(async () => {
598
- if (this.isDestroyed || keyed.some(([key, entry]) => this.state.clients.get(key) !== entry.client)) {
599
- return;
600
- }
601
- for (const [key] of keyed) {
602
- this.clientLeases.set(key, (this.clientLeases.get(key) ?? 0) + 1);
603
- }
604
- return keyed.map(([key, entry]) => ({ key, server: entry.info }));
605
- });
606
- }
607
- releaseClientLease(key, server) {
608
- const remaining = (this.clientLeases.get(key) ?? 1) - 1;
609
- if (remaining > 0) {
610
- this.clientLeases.set(key, remaining);
611
- return;
612
- }
613
- this.clientLeases.delete(key);
614
- if (this.state.clients.has(key)) {
615
- this.clientLastUsedAt.set(key, Date.now());
616
- this.scheduleIdleEviction(key, server);
617
- }
618
- }
619
436
  async withClientForFileUse(filePath, maxWaitMs, hardCapMs, use) {
620
- while (!this.isDestroyed) {
437
+ while (!this.checkDestroyed()) {
621
438
  const entry = await this.getClientForFile(filePath, maxWaitMs, hardCapMs);
622
439
  if (!entry)
623
440
  return;
624
- const leaseKey = await this.acquireClientLease(entry, filePath);
441
+ const leaseKey = await this.clientRegistry.acquireClientLease(entry, filePath);
625
442
  if (!leaseKey)
626
443
  continue;
627
444
  try {
628
445
  return await use(entry);
629
446
  } finally {
630
- this.releaseClientLease(leaseKey, entry.info);
447
+ this.clientRegistry.releaseClientLease(leaseKey, entry.info);
631
448
  }
632
449
  }
633
450
  return;
634
451
  }
635
- async makeCapacityForClient(key) {
636
- const occupiedKeys = new Set(this.state.inFlight.keys());
637
- for (const [clientKey, client] of this.state.clients) {
638
- if (client.isAlive())
639
- occupiedKeys.add(clientKey);
640
- }
641
- const occupied = occupiedKeys.size;
642
- if (occupied < getLspClientCeiling())
643
- return true;
644
- const idle = [...this.state.clients.entries()].filter(([candidateKey, client]) => candidateKey !== key && client.isAlive() && client.isBusy?.() !== true && (this.clientLeases.get(candidateKey) ?? 0) === 0).sort(([a], [b]) => (this.clientLastUsedAt.get(a) ?? this.state.clientSpawnedAt.get(a) ?? 0) - (this.clientLastUsedAt.get(b) ?? this.state.clientSpawnedAt.get(b) ?? 0));
645
- const victim = idle[0];
646
- if (!victim) {
647
- logSessionStart(`lsp client ceiling ${getLspClientCeiling()}: spawn declined; all clients are in use`);
648
- return false;
649
- }
650
- const [victimKey, victimClient] = victim;
651
- this.releaseOutstandingAuxNotifyWrite(victimKey);
652
- await victimClient.shutdown({ reason: "client_ceiling_lru" });
653
- this.retireClient(victimKey);
654
- logSessionStart(`lsp client ceiling ${getLspClientCeiling()}: evicted idle LRU ${victimKey}`);
655
- return true;
656
- }
657
- clearIdleEvictionTimer(key) {
658
- const timer = this.idleEvictionTimers.get(key);
659
- if (timer)
660
- clearTimeout(timer);
661
- this.idleEvictionTimers.delete(key);
662
- }
663
- retireClient(key) {
664
- this.releaseOutstandingAuxNotifyWrite(key);
665
- this.state.clients.delete(key);
666
- this.state.clientSpawnedAt.delete(key);
667
- this.forgetReadiness(key);
668
- this.clientLastUsedAt.delete(key);
669
- if (this.adoptedClientKeys.delete(key)) {
670
- const root = key.slice(key.indexOf(":") + 1);
671
- if (![...this.adoptedClientKeys].some((candidate) => candidate.endsWith(`:${root}`)))
672
- this.adoptedRootLastUsedAt.delete(root);
673
- }
674
- this.clearIdleEvictionTimer(key);
675
- this.auxNotifyInflight.delete(key);
676
- this.auxNotifyDrainLatencyEwma.delete(key);
677
- }
678
452
  releaseOutstandingAuxNotifyWrite(key, token) {
679
453
  const current = this.outstandingAuxNotifyWrites.get(key);
680
454
  if (!current || token !== undefined && current !== token)
@@ -683,82 +457,78 @@ export class LSPService {
683
457
  this.outstandingAuxNotifyWrites.delete(key);
684
458
  current.resolveSettled();
685
459
  }
686
- scheduleIdleEviction(key, server) {
687
- if (server.idleEviction !== "transparent" && !this.adoptedClientKeys.has(key))
688
- return;
689
- this.clearIdleEvictionTimer(key);
690
- const lastUsedAt = this.clientLastUsedAt.get(key) ?? Date.now();
691
- const root = key.slice(key.indexOf(":") + 1);
692
- const idleMs = this.adoptedClientKeys.has(key) ? ADOPTED_ROOT_IDLE_EVICT_MS : getLspIdleEvictMsForRoot(root);
693
- const timer = setTimeout(() => {
694
- this.idleEvictionTimers.delete(key);
695
- this.withClientSpawnGate(async () => {
696
- if (this.isDestroyed)
697
- return;
698
- const client = this.state.clients.get(key);
699
- if (!client?.isAlive())
700
- return;
701
- if (client.isBusy?.() === true || (this.clientLeases.get(key) ?? 0) > 0 || (this.clientLastUsedAt.get(key) ?? 0) !== lastUsedAt) {
702
- this.scheduleIdleEviction(key, server);
703
- return;
704
- }
705
- this.retireClient(key);
706
- try {
707
- await client.shutdown({ reason: "idle_eviction" });
708
- } catch {}
709
- logSessionStart(`lsp idle eviction: released ${key}`);
710
- recordDegradation({
711
- kind: "lsp-idle-eviction",
712
- subject: key,
713
- reason: "idle LSP client released to bound memory"
714
- });
715
- }).catch(() => {});
716
- }, idleMs);
717
- timer.unref?.();
718
- this.idleEvictionTimers.set(key, timer);
719
- }
720
- shouldSkipTouch(filePath, contentFingerprint, clientScope, waitForDiagnostics, spawned) {
460
+ shouldSkipTouch(filePath, sentContentHash, waitForDiagnostics, spawned) {
721
461
  if (waitForDiagnostics)
722
462
  return false;
723
463
  if (spawned.length === 0)
724
464
  return false;
725
- return spawned.every((entry) => this.shouldSkipNotify(filePath, contentFingerprint, clientScope, entry.info.id, entry.client));
465
+ return spawned.every((entry) => this.shouldSkipNotify(filePath, sentContentHash, entry.info.id, entry.client));
726
466
  }
727
- shouldSkipNotify(filePath, contentFingerprint, clientScope, serverId, client) {
467
+ shouldSkipNotify(filePath, sentContentHash, serverId, client) {
728
468
  if (TOUCH_DEBOUNCE_MS <= 0)
729
469
  return false;
730
- const previous = this.recentTouches.get(this.recentTouchKey(filePath, clientScope, serverId));
470
+ const previous = this.recentTouches.get(this.recentTouchKey(filePath, serverId));
731
471
  if (!previous)
732
472
  return false;
733
- const now = Date.now();
734
- if (now - previous.touchedAt > TOUCH_DEBOUNCE_MS)
735
- return false;
736
473
  if (previous.client.deref() !== client)
737
474
  return false;
738
- return previous.fingerprint === contentFingerprint();
475
+ if (workspaceFileCreatedAtFor((id) => id === client.serverId, (root) => root === client.root) >= previous.touchedAt) {
476
+ return false;
477
+ }
478
+ const sentContent = client.getSentContent?.(filePath);
479
+ if (sentContent === undefined || sentContent.hash !== sentContentHash) {
480
+ return false;
481
+ }
482
+ return client.hasNotifyInFlight?.(filePath) === false;
739
483
  }
740
- recentTouchKey(filePath, clientScope, serverId) {
741
- return `${normalizeMapKey(filePath)}:${clientScope}:${serverId}`;
484
+ saveDebouncedPush(filePath, entry, saved, sentContentHash, retryOnFailure = true) {
485
+ if (!saved)
486
+ return;
487
+ const previous = this.recentTouches.get(this.recentTouchKey(filePath, entry.info.id));
488
+ if (!previous || entry.client.getSentContent?.(filePath)?.savedHash === sentContentHash)
489
+ return;
490
+ if (entry.client.getSaveOptions?.() === undefined)
491
+ return;
492
+ const save = entry.client.notify.save;
493
+ if (!save)
494
+ return;
495
+ const recover = () => {
496
+ if (retryOnFailure) {
497
+ this.saveDebouncedPush(filePath, entry, true, sentContentHash, false);
498
+ return;
499
+ }
500
+ recordDegradationOnce({
501
+ kind: "lsp-did-save-recovery-exhausted",
502
+ subject: entry.info.id,
503
+ reason: "a standalone didSave and its one retry both sent nothing",
504
+ metadata: { filePath }
505
+ });
506
+ };
507
+ save.call(entry.client.notify, filePath, true).then((sent) => {
508
+ if (sent === false)
509
+ recover();
510
+ }, recover);
511
+ return entry.info.id;
742
512
  }
743
- markTouched(filePath, contentFingerprint, clientScope, serverId, client) {
744
- const key = this.recentTouchKey(filePath, clientScope, serverId);
745
- const now = Date.now();
513
+ recentTouchKey(filePath, serverId) {
514
+ return `${normalizeMapKey(filePath)}:${serverId}`;
515
+ }
516
+ markTouched(filePath, serverId, client) {
517
+ const key = this.recentTouchKey(filePath, serverId);
518
+ this.recentTouches.delete(key);
746
519
  this.recentTouches.set(key, {
747
- fingerprint: contentFingerprint,
748
- touchedAt: now,
749
- clientScope,
520
+ touchedAt: Date.now(),
750
521
  client: new WeakRef(client)
751
522
  });
752
- if (this.recentTouches.size > 800) {
753
- for (const [k, v] of this.recentTouches) {
754
- if (now - v.touchedAt > TOUCH_DEBOUNCE_MS) {
755
- this.recentTouches.delete(k);
756
- }
757
- }
523
+ while (this.recentTouches.size > RECENT_TOUCH_CAP) {
524
+ const oldest = this.recentTouches.keys().next();
525
+ if (oldest.done)
526
+ break;
527
+ this.recentTouches.delete(oldest.value);
758
528
  }
759
529
  }
760
530
  async demonstratedReadyKeyFor(server, filePath) {
761
- const root = await this.resolveServerRoot(server, filePath);
531
+ const root = await this.clientRegistry.resolveServerRoot(server, filePath);
762
532
  if (!root)
763
533
  return;
764
534
  return `${server.id}:${normalizeMapKey(root)}`;
@@ -772,9 +542,6 @@ export class LSPService {
772
542
  this.state.demonstratedReady.add(key);
773
543
  this.state.demonstratedCold.delete(key);
774
544
  }
775
- recordBreaker(key, reason) {
776
- recordDegradationOnce({ kind: "lsp-breaker", subject: key, reason });
777
- }
778
545
  recordNotifyWriteBackpressure(key, entry, filePath) {
779
546
  if (!key)
780
547
  return;
@@ -793,11 +560,11 @@ export class LSPService {
793
560
  async demoteNotifyStallCpuGuarded(key, entry, filePath, reason) {
794
561
  if (this.state.clients.get(key) !== entry.client)
795
562
  return;
796
- this.clearIdleEvictionTimer(key);
563
+ this.clientRegistry.clearIdleEvictionTimer(key);
797
564
  const verdict = await this.notifyStallCpuVerdict(entry);
798
565
  if (verdict.cpuVerdict === "busy") {
799
566
  if (this.state.clients.get(key) === entry.client) {
800
- this.scheduleIdleEviction(key, entry.info);
567
+ this.clientRegistry.scheduleIdleEviction(key, entry.info);
801
568
  }
802
569
  this.logNotifyStallCpuBusy(key, entry, filePath, 0, verdict);
803
570
  return;
@@ -852,10 +619,10 @@ export class LSPService {
852
619
  demoteForNotifyStall(key, entry, filePath, reason) {
853
620
  if (this.state.clients.get(key) !== entry.client)
854
621
  return;
855
- this.state.broken.set(key, Date.now() + BROKEN_BASE_COOLDOWN_MS);
622
+ this.clientRegistry.coolDown(key, BROKEN_BASE_COOLDOWN_MS);
856
623
  this.notifyStallDemotions.set(key, Date.now());
857
624
  entry.client.shutdown().catch(() => {});
858
- this.retireClient(key);
625
+ this.clientRegistry.retireClient(key);
859
626
  logLatency({
860
627
  type: "phase",
861
628
  phase: "lsp_notify_backpressure_broken",
@@ -1143,12 +910,13 @@ export class LSPService {
1143
910
  };
1144
911
  }
1145
912
  }
1146
- async brokenSkippedAuxiliaryServerIds(filePath, clientScope, options, spawned) {
913
+ async skippedAuxiliaryServerIds(filePath, clientScope, options, spawned) {
1147
914
  if (clientScope === "primary")
1148
- return [];
915
+ return { brokenSkippedServerIds: [], policySkippedServerIds: [] };
1149
916
  const enabledAuxiliaries = clientScope === "with-auxiliary" ? new Set(options.auxiliaryServerIds ?? []) : undefined;
1150
917
  const attached = new Set(spawned.map((entry) => entry.info.id));
1151
- const skipped = [];
918
+ const brokenSkippedServerIds = [];
919
+ const policySkippedServerIds = [];
1152
920
  for (const server of getServersForFileWithConfig(filePath)) {
1153
921
  if (!isAuxiliary(server))
1154
922
  continue;
@@ -1158,15 +926,20 @@ export class LSPService {
1158
926
  continue;
1159
927
  if (enabledAuxiliaries && !enabledAuxiliaries.has(server.id))
1160
928
  continue;
1161
- const key = await this.demonstratedReadyKeyFor(server, filePath);
1162
- if (!key)
929
+ const root = await this.clientRegistry.resolveServerRoot(server, filePath);
930
+ if (!root)
931
+ continue;
932
+ if (declinesLooseFileRoot(server, root)) {
933
+ policySkippedServerIds.push(server.id);
1163
934
  continue;
935
+ }
936
+ const key = `${server.id}:${normalizeMapKey(root)}`;
1164
937
  const brokenUntil = this.state.broken.get(key);
1165
- if (this.permanentlyBroken.has(key) || typeof brokenUntil === "number" && brokenUntil > Date.now()) {
1166
- skipped.push(server.id);
938
+ if (this.clientRegistry.permanentlyBroken.has(key) || typeof brokenUntil === "number" && brokenUntil > Date.now()) {
939
+ brokenSkippedServerIds.push(server.id);
1167
940
  }
1168
941
  }
1169
- return skipped;
942
+ return { brokenSkippedServerIds, policySkippedServerIds };
1170
943
  }
1171
944
  activeClientsForCwd(cwd, priorityServerIds = []) {
1172
945
  const normalizedCwd = normalizeMapKey(cwd);
@@ -1181,7 +954,7 @@ export class LSPService {
1181
954
  const sameOrNested = root === normalizedCwd || root.startsWith(`${normalizedCwd}/`) || normalizedCwd.startsWith(`${root}/`);
1182
955
  if (!sameOrNested)
1183
956
  continue;
1184
- entries.push({ serverId, client });
957
+ entries.push({ clientKey: key, serverId, client });
1185
958
  }
1186
959
  return entries.sort((a, b) => (priority.get(a.serverId) ?? Number.MAX_SAFE_INTEGER) - (priority.get(b.serverId) ?? Number.MAX_SAFE_INTEGER));
1187
960
  }
@@ -1195,9 +968,18 @@ export class LSPService {
1195
968
  }
1196
969
  return [...paths];
1197
970
  }
1198
- getTrackedContent(filePath, cwd) {
971
+ getTrackedContent(filePath, cwd, sourceClientKeys) {
1199
972
  const priorityServerIds = getServersForFileWithConfig(filePath).map((server) => server.id);
1200
- for (const { client } of this.activeClientsForCwd(cwd, priorityServerIds)) {
973
+ const clients = this.activeClientsForCwd(cwd, priorityServerIds);
974
+ if (sourceClientKeys !== undefined) {
975
+ const sourceSet = new Set(sourceClientKeys);
976
+ const sends = clients.filter(({ clientKey }) => sourceSet.has(clientKey)).flatMap(({ clientKey, client }) => {
977
+ const sent = client.getSentContent?.(filePath);
978
+ return sent === undefined ? [] : [{ ...sent, clientKey }];
979
+ });
980
+ return sends;
981
+ }
982
+ for (const { client } of clients) {
1201
983
  const sent = client.getSentContent?.(filePath);
1202
984
  if (sent !== undefined)
1203
985
  return sent;
@@ -1215,7 +997,7 @@ export class LSPService {
1215
997
  try {
1216
998
  return {
1217
999
  server,
1218
- root: await this.resolveServerRootOnce(server, filePath, rootMemo, (reason) => {
1000
+ root: await this.clientRegistry.resolveServerRootOnce(server, filePath, rootMemo, (reason) => {
1219
1001
  rootFailureReason = reason;
1220
1002
  }),
1221
1003
  reason: rootFailureReason
@@ -1262,7 +1044,7 @@ export class LSPService {
1262
1044
  const acquisition = {
1263
1045
  outcome: "declined"
1264
1046
  };
1265
- const spawned = await this.ensureClientForServer(filePath, server, resolvedRoots, noteSpawnInFlight, (reported) => {
1047
+ const spawned = await this.clientRegistry.ensureClientForServer(filePath, server, resolvedRoots, noteSpawnInFlight, (reported) => {
1266
1048
  acquisition.outcome = reported;
1267
1049
  }, rootMemo);
1268
1050
  if (spawned) {
@@ -1300,14 +1082,14 @@ export class LSPService {
1300
1082
  });
1301
1083
  }
1302
1084
  const unavailable = (await Promise.all(servers.map(async (server) => {
1303
- const root = await this.resolveServerRootOnce(server, filePath, rootMemo);
1085
+ const root = await this.clientRegistry.resolveServerRootOnce(server, filePath, rootMemo);
1304
1086
  return {
1305
1087
  server,
1306
1088
  key: `${server.id}:${root ? normalizeMapKey(root) : "<unresolved>"}`
1307
1089
  };
1308
- }))).filter(({ key }) => !this.unavailableLogged.has(key));
1090
+ }))).filter(({ key }) => !this.clientRegistry.unavailableLogged.has(key));
1309
1091
  for (const { key } of unavailable)
1310
- this.unavailableLogged.add(key);
1092
+ this.clientRegistry.unavailableLogged.add(key);
1311
1093
  if (unavailable.length === 0)
1312
1094
  return;
1313
1095
  logLatency({
@@ -1410,7 +1192,7 @@ export class LSPService {
1410
1192
  return { clients: [], serverCountAttempted: 0 };
1411
1193
  const rootedServers = (await Promise.all(servers.map(async (server) => ({
1412
1194
  server,
1413
- root: await this.resolveServerRoot(server, filePath)
1195
+ root: await this.clientRegistry.resolveServerRoot(server, filePath)
1414
1196
  })))).filter((entry) => entry.root !== undefined);
1415
1197
  for (const { server, root } of rootedServers)
1416
1198
  if (isAuxiliary(server))
@@ -1419,7 +1201,7 @@ export class LSPService {
1419
1201
  const acquisitions = new Map;
1420
1202
  const acquire = (server) => {
1421
1203
  serverCountAttempted += 1;
1422
- return this.ensureClientForServer(filePath, server, resolvedRoots);
1204
+ return this.clientRegistry.ensureClientForServer(filePath, server, resolvedRoots);
1423
1205
  };
1424
1206
  for (const { server } of rootedServers) {
1425
1207
  const preferred = server.fallbackFor ? acquisitions.get(server.fallbackFor) : undefined;
@@ -1440,7 +1222,7 @@ export class LSPService {
1440
1222
  const effectiveSignal = signal ?? getAmbientAbortSignal();
1441
1223
  const effectiveHook = hook ?? "tool_result_edit";
1442
1224
  const spawned = await Promise.all(servers.map(async (server) => {
1443
- const acquisition = this.ensureClientForServer(filePath, server, undefined, undefined, (reported) => onOutcome?.(server.id, reported), rootMemo);
1225
+ const acquisition = this.clientRegistry.ensureClientForServer(filePath, server, undefined, undefined, (reported) => onOutcome?.(server.id, reported), rootMemo);
1444
1226
  if (!maxWaitMs || maxWaitMs <= 0) {
1445
1227
  return acquisition;
1446
1228
  }
@@ -1459,7 +1241,7 @@ export class LSPService {
1459
1241
  const servers = getServersForFileWithConfig(filePath);
1460
1242
  const missed = [];
1461
1243
  for (const server of servers) {
1462
- const root = await this.resolveServerRoot(server, filePath);
1244
+ const root = await this.clientRegistry.resolveServerRoot(server, filePath);
1463
1245
  if (!root)
1464
1246
  continue;
1465
1247
  const key = `${server.id}:${normalizeMapKey(root)}`;
@@ -1491,7 +1273,7 @@ export class LSPService {
1491
1273
  for (const server of getServersForFileWithConfig(filePath)) {
1492
1274
  if (server.id !== serverId)
1493
1275
  continue;
1494
- const root = await this.resolveServerRoot(server, filePath);
1276
+ const root = await this.clientRegistry.resolveServerRoot(server, filePath);
1495
1277
  if (!root)
1496
1278
  continue;
1497
1279
  const key = `${server.id}:${normalizeMapKey(root)}`;
@@ -1509,7 +1291,7 @@ export class LSPService {
1509
1291
  for (const server of getServersForFileWithConfig(filePath)) {
1510
1292
  if (!serverIds.has(server.id) || out.has(server.id))
1511
1293
  continue;
1512
- const root = await this.resolveServerRoot(server, filePath);
1294
+ const root = await this.clientRegistry.resolveServerRoot(server, filePath);
1513
1295
  if (!root)
1514
1296
  continue;
1515
1297
  const key = `${server.id}:${normalizeMapKey(root)}`;
@@ -1538,7 +1320,7 @@ export class LSPService {
1538
1320
  for (const server of getServersForFileWithConfig(filePath)) {
1539
1321
  if (server.id !== serverId)
1540
1322
  continue;
1541
- const root = await this.resolveServerRoot(server, filePath);
1323
+ const root = await this.clientRegistry.resolveServerRoot(server, filePath);
1542
1324
  if (root === undefined)
1543
1325
  return;
1544
1326
  this.noteAuxiliaryLateAnswer(`${serverId}:${normalizeMapKey(root)}`, elapsedMs);
@@ -1549,12 +1331,213 @@ export class LSPService {
1549
1331
  if (this.checkDestroyed())
1550
1332
  return;
1551
1333
  for (const server of getServersForFileWithConfig(filePath)) {
1552
- const root = await this.resolveServerRoot(server, filePath);
1334
+ const root = await this.clientRegistry.resolveServerRoot(server, filePath);
1553
1335
  if (!root)
1554
1336
  continue;
1555
1337
  this.notifyLiveClientsForServer(server.id, filePath, type, `${server.id}:${normalizeMapKey(root)}`, true);
1556
1338
  }
1557
1339
  }
1340
+ notifyOutOfBandFileChanges(changes) {
1341
+ if (this.checkDestroyed() || changes.length === 0)
1342
+ return;
1343
+ for (const { filePath, type } of changes) {
1344
+ const serverIds = new Set([
1345
+ ...serverIdsForConfigFile(filePath) ?? [],
1346
+ ...getServersForFileWithConfig(filePath).map((server) => server.id)
1347
+ ]);
1348
+ for (const serverId of serverIds)
1349
+ this.notifyLiveClientsForServer(serverId, filePath, type, "", true);
1350
+ this.noteUnheldSent(filePath);
1351
+ }
1352
+ for (const client of this.state.clients.values())
1353
+ if (client.isAlive())
1354
+ client.notify.flushWatched?.();
1355
+ }
1356
+ noteUnheldSent(filePath) {
1357
+ const key = normalizeMapKey(filePath);
1358
+ let stat;
1359
+ try {
1360
+ stat = nodeFs.statSync(filePath, { throwIfNoEntry: false });
1361
+ } catch {
1362
+ stat = undefined;
1363
+ }
1364
+ if (stat === undefined) {
1365
+ this.unheldStamps.delete(key);
1366
+ return;
1367
+ }
1368
+ const seen = this.unheldStamps.get(key);
1369
+ if (seen?.size === stat.size && seen.mtimeMs === stat.mtimeMs)
1370
+ return;
1371
+ this.unheldStamps.set(key, { size: stat.size, mtimeMs: stat.mtimeMs });
1372
+ }
1373
+ async restartPrimaryClientsUnder(root) {
1374
+ if (this.checkDestroyed())
1375
+ return 0;
1376
+ return (await this.clientRegistry.restartPrimaryClientsUnder(root)).length;
1377
+ }
1378
+ livePrimaryClientRoots() {
1379
+ if (this.checkDestroyed())
1380
+ return [];
1381
+ return this.clientRegistry.livePrimaryClientRoots();
1382
+ }
1383
+ announceCreatedFiles(filePaths, importTargets = []) {
1384
+ if (this.checkDestroyed() || this.state.clients.size === 0)
1385
+ return;
1386
+ this.sendUnheldChanges(importTargets);
1387
+ const byServer = new Map;
1388
+ for (const filePath of [...filePaths, ...importTargets]) {
1389
+ let stat;
1390
+ try {
1391
+ stat = nodeFs.statSync(filePath);
1392
+ } catch {
1393
+ continue;
1394
+ }
1395
+ for (const server of getServersForFileWithConfig(filePath)) {
1396
+ const entries = byServer.get(server.id) ?? [];
1397
+ entries.push({ filePath, stat });
1398
+ byServer.set(server.id, entries);
1399
+ }
1400
+ }
1401
+ for (const [key, client] of this.state.clients) {
1402
+ if (!client.isAlive())
1403
+ continue;
1404
+ const entries = [...byServer].flatMap(([serverId, list]) => key.startsWith(`${serverId}:`) ? list : []);
1405
+ client.notify.announceCreated(entries);
1406
+ }
1407
+ }
1408
+ sendUnheldChanges(filePaths) {
1409
+ const changed = [];
1410
+ const at = Date.now();
1411
+ for (const filePath of filePaths) {
1412
+ let stat;
1413
+ try {
1414
+ stat = nodeFs.statSync(filePath);
1415
+ } catch {
1416
+ continue;
1417
+ }
1418
+ const servers = getServersForFileWithConfig(filePath);
1419
+ if (!this.unheldBytesMoved(filePath, stat, servers))
1420
+ continue;
1421
+ changed.push({ filePath, type: FILE_CHANGED });
1422
+ for (const client of this.liveClientsOf(servers, filePath))
1423
+ noteWorkspaceFilesChangedOnDisk(client.root, [normalizeMapKey(filePath)], at);
1424
+ }
1425
+ if (changed.length === 0)
1426
+ return;
1427
+ this.notifyOutOfBandFileChanges(changed);
1428
+ logLatency({
1429
+ type: "phase",
1430
+ phase: "lsp_unheld_dependency_changed",
1431
+ filePath: changed[0]?.filePath ?? "",
1432
+ durationMs: Date.now() - at,
1433
+ result: `changed:${changed.length}`,
1434
+ metadata: {
1435
+ changed: changed.length,
1436
+ paths: changed.slice(0, 5).map((change) => change.filePath)
1437
+ }
1438
+ });
1439
+ }
1440
+ unheldBytesMoved(filePath, stat, servers) {
1441
+ const live = this.liveClientsOf(servers, filePath);
1442
+ if (live.every((client) => client.holds))
1443
+ return false;
1444
+ const key = normalizeMapKey(filePath);
1445
+ const seen = this.unheldStamps.get(key);
1446
+ if (seen?.size === stat.size && seen.mtimeMs === stat.mtimeMs)
1447
+ return false;
1448
+ let stamp = { size: stat.size, mtimeMs: stat.mtimeMs };
1449
+ if (stat.size <= CONTENT_HASH_MAX_BYTES) {
1450
+ try {
1451
+ stamp = stampContentBytes(nodeFs.readFileSync(filePath), stat.mtimeMs);
1452
+ } catch (cause) {
1453
+ recordDegradationOnce({
1454
+ kind: "lsp-unheld-dependency-unreadable",
1455
+ subject: key,
1456
+ reason: `could not read a closed module to compare its bytes; a change of its stat is sent as a change: ${cause instanceof Error ? cause.message : String(cause)}`
1457
+ });
1458
+ }
1459
+ }
1460
+ this.unheldStamps.set(key, stamp);
1461
+ if (seen === undefined)
1462
+ return live.some((client) => watchedTypeForOpen(stat.mtimeMs, client.launchedAt) === FILE_CREATED);
1463
+ return seen.sha256 === undefined || seen.sha256 !== stamp.sha256;
1464
+ }
1465
+ liveClientsOf(servers, filePath) {
1466
+ const live = [];
1467
+ for (const [key, client] of this.state.clients) {
1468
+ if (!client.isAlive())
1469
+ continue;
1470
+ if (!servers.some((server) => key.startsWith(`${server.id}:`)))
1471
+ continue;
1472
+ live.push({
1473
+ root: client.root,
1474
+ launchedAt: this.clientRegistry.clientLaunchStartedAt.get(key) ?? 0,
1475
+ holds: documentIsOpenOn(client, filePath)
1476
+ });
1477
+ }
1478
+ return live;
1479
+ }
1480
+ async resyncHeldPrimaries(filePaths, drainMs) {
1481
+ let sent = 0;
1482
+ const sentTo = new Map;
1483
+ for (const filePath of filePaths) {
1484
+ if (this.checkDestroyed())
1485
+ break;
1486
+ const servers = getServersForFileWithConfig(filePath);
1487
+ const exclude = await this.serverIdsNotHoldingDocument(filePath);
1488
+ for (const server of servers)
1489
+ if (isAuxiliary(server))
1490
+ exclude.add(server.id);
1491
+ if (servers.every((server) => exclude.has(server.id)))
1492
+ continue;
1493
+ const readStamp = performance.now();
1494
+ let content;
1495
+ try {
1496
+ content = await fs.readFile(filePath, "utf8");
1497
+ } catch {
1498
+ continue;
1499
+ }
1500
+ await this.touchFile(filePath, content, {
1501
+ diagnostics: "none",
1502
+ source: "head_move_primary",
1503
+ clientScope: "all",
1504
+ excludeServerIds: exclude,
1505
+ readStamp
1506
+ });
1507
+ sent += 1;
1508
+ for (const server of servers) {
1509
+ if (exclude.has(server.id))
1510
+ continue;
1511
+ const root = await this.clientRegistry.resolveServerRoot(server, filePath);
1512
+ const key = root ? `${server.id}:${normalizeMapKey(root)}` : undefined;
1513
+ const client = key ? this.state.clients.get(key) : undefined;
1514
+ if (key && client) {
1515
+ const traits = serverTraits(server);
1516
+ const documents = sentTo.get(key)?.documents ?? [];
1517
+ documents.push({ filePath, content, readStamp });
1518
+ sentTo.set(key, {
1519
+ client,
1520
+ ordered: traits.replyOrdering === "single-task-ordered",
1521
+ rechecks: traits.resendRecheck === "rechecks",
1522
+ documents
1523
+ });
1524
+ }
1525
+ }
1526
+ }
1527
+ if (sentTo.size === 0)
1528
+ return { sent, drained: true };
1529
+ await Promise.all([...sentTo.values()].flatMap(({ client, rechecks, documents }) => (rechecks ? documents : []).slice(0, -1).map(({ filePath, content, readStamp }) => client.notify.open(filePath, content, getLanguageId(filePath) ?? "plaintext", undefined, undefined, undefined, readStamp))));
1530
+ const answers = await Promise.all([...sentTo.values()].map(async ({ client, ordered }) => {
1531
+ if (!ordered)
1532
+ return false;
1533
+ try {
1534
+ return await client.pingLiveness?.(drainMs) ?? true;
1535
+ } catch {
1536
+ return false;
1537
+ }
1538
+ }));
1539
+ return { sent, drained: answers.every(Boolean) };
1540
+ }
1558
1541
  async resyncGitChangedFiles(changedPaths, options = {}) {
1559
1542
  const dispositions = new Map;
1560
1543
  if (this.checkDestroyed() || changedPaths.length === 0) {
@@ -1565,7 +1548,7 @@ export class LSPService {
1565
1548
  for (const changedPath of changedPaths) {
1566
1549
  const resolved = path.resolve(changedPath);
1567
1550
  for (const server of getServersForFileWithConfig(resolved)) {
1568
- const root = await this.resolveServerRoot(server, resolved);
1551
+ const root = await this.clientRegistry.resolveServerRoot(server, resolved);
1569
1552
  if (!root)
1570
1553
  continue;
1571
1554
  const index = loadReverseDependencyIndexFromSnapshot({ cwd: root });
@@ -1580,7 +1563,21 @@ export class LSPService {
1580
1563
  const written = new Set(changed.values());
1581
1564
  this.documentDrift.enqueueResync(openTargets.filter((filePath) => !written.has(filePath)));
1582
1565
  this.documentDrift.enqueueResync(openTargets.filter((filePath) => written.has(filePath)), { saved: options.saved === true });
1583
- const pass = await this.sweepDocumentDrift({ force: true });
1566
+ let pass;
1567
+ let passes = 0;
1568
+ const reached = new Map;
1569
+ const waiting = (filePath) => {
1570
+ const disposition = reached.get(normalizeMapKey(filePath));
1571
+ return disposition === undefined || disposition === "deferred";
1572
+ };
1573
+ for (let n = 0;n < Math.max(1, options.maxPasses ?? 1); n++) {
1574
+ pass = await this.sweepDocumentDrift({ force: true });
1575
+ passes += 1;
1576
+ for (const [key, disposition] of pass?.queued ?? [])
1577
+ reached.set(key, disposition);
1578
+ if (!pass || !openTargets.some(waiting))
1579
+ break;
1580
+ }
1584
1581
  logLatency({
1585
1582
  type: "phase",
1586
1583
  phase: "lsp_external_change_resync",
@@ -1589,11 +1586,12 @@ export class LSPService {
1589
1586
  metadata: {
1590
1587
  changedCount: changedPaths.length,
1591
1588
  enqueued: openTargets.length,
1592
- deferred: pass?.deferred ?? this.documentDrift.pendingResyncCount
1589
+ deferred: pass?.deferred ?? this.documentDrift.pendingResyncCount,
1590
+ passes
1593
1591
  }
1594
1592
  });
1595
1593
  for (const [changedPath, resolved] of changed) {
1596
- dispositions.set(changedPath, openTargets.includes(resolved) ? pass?.queued.get(normalizeMapKey(resolved)) ?? "deferred" : "unheld");
1594
+ dispositions.set(changedPath, openTargets.includes(resolved) ? reached.get(normalizeMapKey(resolved)) ?? "deferred" : "unheld");
1597
1595
  }
1598
1596
  return dispositions;
1599
1597
  }
@@ -1602,6 +1600,8 @@ export class LSPService {
1602
1600
  return;
1603
1601
  return this.documentDrift.sweep({
1604
1602
  resync: async (filePath, content, _driftAgeMs, readStamp, saved) => {
1603
+ if (exceedsLspSyncLimits(content).tooLarge)
1604
+ return false;
1605
1605
  await this.touchFile(filePath, content, {
1606
1606
  diagnostics: "none",
1607
1607
  source: "drift_resync",
@@ -1612,7 +1612,6 @@ export class LSPService {
1612
1612
  });
1613
1613
  return this.documentDrift.peek(filePath)?.fingerprint === fingerprintDocumentContent(content);
1614
1614
  },
1615
- holdsDocument: (filePath) => this.hasLiveClientHoldingDocument(filePath),
1616
1615
  onDrift: (event) => {
1617
1616
  if (event.disposition === "unchanged" || event.disposition === "vanished" || event.disposition === "unheld") {
1618
1617
  return;
@@ -1652,7 +1651,7 @@ export class LSPService {
1652
1651
  async serverIdsNotHoldingDocument(filePath) {
1653
1652
  const exclude = new Set;
1654
1653
  for (const server of getServersForFileWithConfig(filePath)) {
1655
- const root = await this.resolveServerRoot(server, filePath);
1654
+ const root = await this.clientRegistry.resolveServerRoot(server, filePath);
1656
1655
  const existing = root ? this.state.clients.get(`${server.id}:${normalizeMapKey(root)}`) : undefined;
1657
1656
  if (existing?.isAlive() && documentIsOpenOn(existing, filePath))
1658
1657
  continue;
@@ -1674,366 +1673,6 @@ export class LSPService {
1674
1673
  }
1675
1674
  this.documentDrift.recordSynced(filePath, content, at, contentFingerprint?.() ?? fingerprintDocumentContent(content));
1676
1675
  }
1677
- noteSpawnVerdict(key, verdict) {
1678
- this.lastSpawnVerdict.set(key, verdict);
1679
- }
1680
- resolveServerRootOnce(server, filePath, memo, onRootFailure) {
1681
- if (!memo)
1682
- return this.resolveServerRoot(server, filePath, onRootFailure);
1683
- const pending = memo.get(server.id);
1684
- if (pending !== undefined)
1685
- return pending;
1686
- const started = this.resolveServerRoot(server, filePath, onRootFailure);
1687
- memo.set(server.id, started);
1688
- return started;
1689
- }
1690
- async ensureClientForServer(filePath, server, resolvedRoots, onSpawnInFlight, onOutcome, rootMemo) {
1691
- const handoff = this.generationHandoff;
1692
- if (handoff) {
1693
- await handoff;
1694
- if (this.generationHandoff === handoff) {
1695
- this.generationHandoff = undefined;
1696
- }
1697
- if (this.checkDestroyed())
1698
- return;
1699
- }
1700
- const root = await this.resolveServerRootOnce(server, filePath, rootMemo);
1701
- if (!root || this.checkDestroyed())
1702
- return;
1703
- if (!isAuxiliary(server)) {
1704
- resolvedRoots?.set(server.id, normalizeMapKey(root));
1705
- }
1706
- const allowInstall = this.shouldAllowInstall(server.id);
1707
- const normalizedRoot = normalizeMapKey(root);
1708
- const key = `${server.id}:${normalizedRoot}`;
1709
- const adopted = this.analysisRootModeForFile(filePath) === "adopted";
1710
- if (adopted) {
1711
- const localCommand = server.command ?? server.projectLocalCommand ?? server.availabilityKey;
1712
- const localBinary = localCommand ? path.isAbsolute(localCommand) ? isProjectLocalBinPath(localCommand, root) ? localCommand : undefined : findLocalBinUpwards(localCommand, root) : undefined;
1713
- if (localBinary) {
1714
- recordDegradationOnce({
1715
- kind: "lsp-registry-decision",
1716
- subject: `${server.id}:${normalizeMapKey(root)}`,
1717
- reason: "project-local LSP binary refused for adopted root"
1718
- });
1719
- return;
1720
- }
1721
- this.adoptedClientKeys.add(key);
1722
- if (!this.admitAdoptedRoot(root, filePath))
1723
- return;
1724
- }
1725
- const isOptionalServer = OPTIONAL_LSP_SERVER_IDS.has(server.id);
1726
- if (server.availabilityKey && isDirectLspCommandTemporarilyUnavailable(server.availabilityKey)) {
1727
- emitBounded("lsp_client_skipped_unavailable_command", `${server.availabilityKey}:${normalizeMapKey(filePath)}`, {
1728
- filePath,
1729
- durationMs: 0,
1730
- metadata: {
1731
- serverId: server.id,
1732
- command: server.availabilityKey
1733
- }
1734
- }, {
1735
- ledgerKind: "lsp-client-skipped-unavailable-command",
1736
- risingEdgePer: "identity",
1737
- reason: `command ${server.availabilityKey} temporarily unavailable`
1738
- });
1739
- return;
1740
- }
1741
- if (isOptionalServer && this.optionalDisabled.has(key)) {
1742
- return;
1743
- }
1744
- if (this.permanentlyBroken.has(key)) {
1745
- emitBounded("lsp_client_skipped_broken", `${server.id}:${normalizeMapKey(filePath)}`, {
1746
- filePath,
1747
- durationMs: 0,
1748
- metadata: {
1749
- serverId: server.id,
1750
- permanent: true
1751
- }
1752
- }, {
1753
- ledgerKind: "lsp-client-skipped-broken",
1754
- risingEdgePer: "identity",
1755
- reason: `${server.id} latched permanently broken`
1756
- });
1757
- return;
1758
- }
1759
- const existing = this.state.clients.get(key);
1760
- if (existing) {
1761
- if (existing.isAlive()) {
1762
- this.unavailableLogged.delete(key);
1763
- this.clientLastUsedAt.set(key, Date.now());
1764
- this.scheduleIdleEviction(key, server);
1765
- if (!this.warmStartLogged.has(key)) {
1766
- logSessionStart(`lsp warm-start ${server.id}: reused root=${root} file=${filePath}`);
1767
- this.warmStartLogged.add(key);
1768
- }
1769
- onOutcome?.("warm-reuse");
1770
- return { client: existing, info: server };
1771
- }
1772
- const spawnedAt = this.state.clientSpawnedAt.get(key);
1773
- const wasIntentional = existing.wasShutdownIntentional();
1774
- const exitedAt = existing.getExitedAt();
1775
- const uptimeMs = exitedAt != null && spawnedAt != null ? exitedAt - spawnedAt : spawnedAt != null ? Date.now() - spawnedAt : null;
1776
- logLatency({
1777
- type: "phase",
1778
- phase: "lsp_server_respawn",
1779
- filePath,
1780
- durationMs: 0,
1781
- metadata: {
1782
- serverId: server.id,
1783
- root,
1784
- uptimeMs,
1785
- intentional: wasIntentional
1786
- }
1787
- });
1788
- this.releaseOutstandingAuxNotifyWrite(key);
1789
- try {
1790
- await existing.shutdown();
1791
- } catch {}
1792
- this.retireClient(key);
1793
- this.state.broken.delete(key);
1794
- if (wasIntentional) {} else {
1795
- if (this.recordRuntimeExitWindow(key, exitedAt, uptimeMs)) {
1796
- const rate = `${RUNTIME_EXIT_WINDOW_TRIP_COUNT} deaths within ${Math.round(RUNTIME_EXIT_WINDOW_MS / 60000)}m`;
1797
- this.state.broken.set(key, Math.max(this.state.broken.get(key) ?? 0, Date.now() + (isOptionalServer ? OPTIONAL_LSP_RETRY_COOLDOWN_MS : BROKEN_MAX_COOLDOWN_MS)));
1798
- if (isOptionalServer) {
1799
- this.optionalDisabled.add(key);
1800
- this.runtimeExitWindow.delete(key);
1801
- logSessionStart(`lsp respawn ${server.id}: optional server cooled down (windowed-rate trip: ${rate})`);
1802
- } else {
1803
- this.permanentlyBroken.add(key);
1804
- this.recordBreaker(key, `windowed runtime-exit trip: ${rate}`);
1805
- logSessionStart(`lsp respawn ${server.id}: permanently disabled (windowed-rate trip: ${rate}, uptimeMs=${uptimeMs})`);
1806
- }
1807
- }
1808
- if (uptimeMs != null && uptimeMs < RUNTIME_EXIT_UPTIME_THRESHOLD_MS) {
1809
- const rCount = (this.runtimeExitCounts.get(key) ?? 0) + 1;
1810
- this.runtimeExitCounts.set(key, rCount);
1811
- const rCooldown = Math.min(BROKEN_BASE_COOLDOWN_MS * 2 ** (rCount - 1), BROKEN_MAX_COOLDOWN_MS);
1812
- this.state.broken.set(key, Date.now() + rCooldown);
1813
- if (!isOptionalServer && rCount >= BROKEN_PERMANENT_AFTER) {
1814
- this.permanentlyBroken.add(key);
1815
- this.recordBreaker(key, `permanently disabled after ${rCount} early post-init exits`);
1816
- logSessionStart(`lsp respawn ${server.id}: permanently disabled after ${rCount} early post-init exits (uptimeMs=${uptimeMs})`);
1817
- } else {
1818
- logSessionStart(`lsp respawn ${server.id}: early post-init exit ${rCount}/${BROKEN_PERMANENT_AFTER} (uptimeMs=${uptimeMs}), cooldown=${rCooldown}ms`);
1819
- }
1820
- } else {
1821
- this.runtimeExitCounts.delete(key);
1822
- const windowDeaths = this.runtimeExitWindow.get(key);
1823
- if (windowDeaths) {
1824
- const windowNow = exitedAt ?? Date.now();
1825
- if (!windowDeaths.some((t) => t >= windowNow - RUNTIME_EXIT_WINDOW_MS)) {
1826
- this.runtimeExitWindow.delete(key);
1827
- }
1828
- }
1829
- }
1830
- }
1831
- }
1832
- const brokenUntil = this.state.broken.get(key);
1833
- if (typeof brokenUntil === "number" && brokenUntil > Date.now()) {
1834
- emitBounded("lsp_client_skipped_broken", `${server.id}:${normalizeMapKey(filePath)}`, {
1835
- filePath,
1836
- durationMs: 0,
1837
- metadata: {
1838
- serverId: server.id,
1839
- retryInMs: Math.max(0, brokenUntil - Date.now())
1840
- }
1841
- }, {
1842
- ledgerKind: "lsp-client-skipped-broken",
1843
- risingEdgePer: "identity",
1844
- reason: `${server.id} in breaker cooldown`
1845
- });
1846
- return;
1847
- }
1848
- if (typeof brokenUntil === "number" && brokenUntil <= Date.now()) {
1849
- this.state.broken.delete(key);
1850
- if (isOptionalServer)
1851
- this.optionalDisabled.delete(key);
1852
- }
1853
- let startedSpawn = false;
1854
- let spawnPromise = this.state.inFlight.get(key);
1855
- if (!spawnPromise) {
1856
- const started = await this.withClientSpawnGate(async () => {
1857
- const raced = this.state.inFlight.get(key);
1858
- if (raced)
1859
- return { promise: raced, startedSpawn: false };
1860
- if (this.checkDestroyed())
1861
- return;
1862
- if (!await this.makeCapacityForClient(key))
1863
- return;
1864
- const promise = this.spawnClient(server, root, key, filePath, allowInstall);
1865
- this.state.inFlight.set(key, promise);
1866
- return { promise, startedSpawn: true };
1867
- });
1868
- if (!started)
1869
- return;
1870
- spawnPromise = started.promise;
1871
- startedSpawn = started.startedSpawn;
1872
- }
1873
- onSpawnInFlight?.(server.id);
1874
- try {
1875
- const spawned = await spawnPromise;
1876
- onOutcome?.(spawned ? startedSpawn ? "cold-spawn" : "cold-spawn-joined" : this.lastSpawnVerdict.get(key) === "failed" ? startedSpawn ? "spawn-failure" : "spawn-failure-joined" : "declined");
1877
- return spawned;
1878
- } catch (err) {
1879
- onOutcome?.("spawn-failure");
1880
- throw err;
1881
- } finally {
1882
- if (this.state.inFlight.get(key) === spawnPromise) {
1883
- this.state.inFlight.delete(key);
1884
- }
1885
- }
1886
- }
1887
- shouldAllowInstall(serverId) {
1888
- if (!assertInstallAllowed(`lsp install: ${serverId}`))
1889
- return false;
1890
- return process.env.DM_LENS_DISABLE_LSP_INSTALL !== "1";
1891
- }
1892
- async spawnClient(server, root, key, filePath, allowInstall) {
1893
- try {
1894
- if (server.executesProjectCode === true) {
1895
- refuseUntrustedLspExecution({
1896
- kind: "project-code-server",
1897
- serverId: server.id,
1898
- root
1899
- });
1900
- }
1901
- } catch (error) {
1902
- logSessionStart(`lsp spawn ${server.id}: refused — ${error instanceof Error ? error.message : String(error)}`);
1903
- this.noteSpawnVerdict(key, "failed");
1904
- return;
1905
- }
1906
- if (server.trustAllowed !== true && !isLspSpawnAllowedByTrust()) {
1907
- logSessionStart(`lsp spawn ${server.id}: refused — ${projectTrustDenialReason()}`);
1908
- this.noteSpawnVerdict(key, "declined");
1909
- return;
1910
- }
1911
- const isOptionalServer = OPTIONAL_LSP_SERVER_IDS.has(server.id);
1912
- const startedAt = Date.now();
1913
- logSessionStart(`lsp spawn ${server.id}: start root=${root} install=${allowInstall ? "enabled" : "disabled"} file=${filePath}`);
1914
- recordLsp(server.id, root, "spawn_start");
1915
- try {
1916
- const projectCodeAllowed = this.analysisRootModeForFile(filePath) !== "adopted";
1917
- const spawned = await withLspProjectCodePermission(projectCodeAllowed, () => server.spawn(root, {
1918
- allowInstall,
1919
- projectCodeAllowed,
1920
- sessionRoot: this.sessionCwd ?? process.cwd()
1921
- }));
1922
- if (this.isDestroyed) {
1923
- try {
1924
- spawned?.process?.process?.kill();
1925
- } catch {}
1926
- logSessionStart(`lsp spawn ${server.id}: aborted (service shut down mid-spawn)`);
1927
- this.noteSpawnVerdict(key, "declined");
1928
- return;
1929
- }
1930
- if (!spawned) {
1931
- logSessionStart(`lsp spawn ${server.id}: unavailable (${Date.now() - startedAt}ms)`);
1932
- recordLsp(server.id, root, "spawn_failed", Date.now() - startedAt);
1933
- if (!allowInstall) {
1934
- logSessionStart(`lsp spawn ${server.id}: unavailable with install disabled; temporary cooldown only`);
1935
- this.state.broken.set(key, Date.now() + BROKEN_BASE_COOLDOWN_MS);
1936
- this.noteSpawnVerdict(key, "declined");
1937
- return;
1938
- }
1939
- const uCount = (this.failureCounts.get(key) ?? 0) + 1;
1940
- this.failureCounts.set(key, uCount);
1941
- const uCooldown = Math.min(BROKEN_BASE_COOLDOWN_MS * 2 ** (uCount - 1), BROKEN_MAX_COOLDOWN_MS);
1942
- this.state.broken.set(key, Date.now() + uCooldown);
1943
- if (uCount >= BROKEN_PERMANENT_AFTER) {
1944
- this.permanentlyBroken.add(key);
1945
- this.recordBreaker(key, `permanently disabled after ${uCount} unavailable spawns`);
1946
- logSessionStart(`lsp spawn ${server.id}: permanently disabled after ${uCount} failures`);
1947
- }
1948
- this.noteSpawnVerdict(key, "failed");
1949
- return;
1950
- }
1951
- const override = getServerInitOverride(server.id, filePath);
1952
- const mergedInit = spawned.launchVariant === "classic" ? mergeInitializationOptions(override?.initializationOptions, spawned.initialization) : mergeInitializationOptions(spawned.initialization, override?.initializationOptions);
1953
- this.state.diagnosticsPublished.delete(server.id);
1954
- this.state.diagnosticsUnsupported.delete(server.id);
1955
- this.firstContactWaits.delete(server.id);
1956
- const client = await createLSPClient({
1957
- serverId: server.id,
1958
- process: spawned.process,
1959
- root,
1960
- sessionCwd: this.sessionCwd,
1961
- initialization: mergedInit,
1962
- initializeTimeoutMs: server.initializeTimeoutMs,
1963
- launchVariant: spawned.launchVariant,
1964
- onDiagnosticsPublished: (serverId) => {
1965
- this.state.diagnosticsPublished.add(serverId);
1966
- }
1967
- });
1968
- if (this.isDestroyed) {
1969
- client.shutdown({ fast: true }).catch(() => {});
1970
- logSessionStart(`lsp spawn ${server.id}: aborted (service shut down mid-initialize)`);
1971
- this.noteSpawnVerdict(key, "declined");
1972
- return;
1973
- }
1974
- const wsDiag = typeof client.getWorkspaceDiagnosticsSupport === "function" ? client.getWorkspaceDiagnosticsSupport() : {
1975
- advertised: false,
1976
- mode: "push-only",
1977
- diagnosticProviderKind: "unavailable"
1978
- };
1979
- this.state.clients.set(key, client);
1980
- this.forgetReadiness(key);
1981
- this.notifyStallDemotions.delete(key);
1982
- this.unavailableLogged.delete(key);
1983
- this.lastSpawnVerdict.delete(key);
1984
- this.state.clientSpawnedAt.set(key, Date.now());
1985
- this.clientLastUsedAt.set(key, Date.now());
1986
- this.scheduleIdleEviction(key, server);
1987
- this.failureCounts.delete(key);
1988
- if (isOptionalServer) {
1989
- this.optionalDisabled.delete(key);
1990
- this.optionalFailureLogged.delete(key);
1991
- }
1992
- logSessionStart(`lsp spawn ${server.id}: success source=${spawned.source ?? "unknown"} (${Date.now() - startedAt}ms)`);
1993
- const spawnDurationMs = Date.now() - startedAt;
1994
- recordLsp(server.id, root, "spawn_success", spawnDurationMs);
1995
- recordSuccessfulLspSpawn(server.id, spawnDurationMs);
1996
- logLatency({
1997
- type: "phase",
1998
- phase: "lsp_server_spawned",
1999
- filePath: root,
2000
- durationMs: spawnDurationMs,
2001
- metadata: {
2002
- serverId: server.id,
2003
- source: spawned.source ?? "unknown",
2004
- launchVariant: spawned.launchVariant ?? "default",
2005
- triggerFilePath: filePath
2006
- }
2007
- });
2008
- if (!this.workspaceProbeLogged.has(key)) {
2009
- logSessionStart(`lsp workspace-diag probe ${server.id}: advertised=${wsDiag.advertised} mode=${wsDiag.mode} provider=${wsDiag.diagnosticProviderKind}`);
2010
- this.workspaceProbeLogged.add(key);
2011
- }
2012
- return { client, info: server };
2013
- } catch (err) {
2014
- recordLsp(server.id, root, "spawn_failed", Date.now() - startedAt);
2015
- if (!isOptionalServer || !this.optionalFailureLogged.has(key)) {
2016
- logSessionStart(`lsp spawn ${server.id}: failed (${Date.now() - startedAt}ms) error=${err instanceof Error ? err.message : String(err)}`);
2017
- if (isOptionalServer) {
2018
- this.optionalFailureLogged.add(key);
2019
- }
2020
- }
2021
- const eCount = (this.failureCounts.get(key) ?? 0) + 1;
2022
- this.failureCounts.set(key, eCount);
2023
- const eCooldown = isOptionalServer ? OPTIONAL_LSP_RETRY_COOLDOWN_MS : Math.min(BROKEN_BASE_COOLDOWN_MS * 2 ** (eCount - 1), BROKEN_MAX_COOLDOWN_MS);
2024
- this.state.broken.set(key, Date.now() + eCooldown);
2025
- if (!isOptionalServer && eCount >= BROKEN_PERMANENT_AFTER) {
2026
- this.permanentlyBroken.add(key);
2027
- this.recordBreaker(key, `permanently disabled after ${eCount} spawn/initialize failures`);
2028
- logSessionStart(`lsp spawn ${server.id}: permanently disabled after ${eCount} failures`);
2029
- }
2030
- if (isOptionalServer) {
2031
- this.optionalDisabled.add(key);
2032
- }
2033
- this.noteSpawnVerdict(key, "failed");
2034
- return;
2035
- }
2036
- }
2037
1676
  async openFile(filePath, content, options) {
2038
1677
  if (this.checkDestroyed())
2039
1678
  return;
@@ -2139,6 +1778,8 @@ export class LSPService {
2139
1778
  }
2140
1779
  if (spawned.length === 0) {
2141
1780
  const failureKind = this.isSpawnInFlight(filePath, resolvedPrimaryRoots) ? "spawn_in_flight_budget_elapsed" : "no_clients_none_spawning";
1781
+ const unanswered = diagnosticsMode === "none" ? undefined : unansweredPrimaries(spawned, resolvedPrimaryRoots, filePath);
1782
+ const disabledPrimaryServerIds = unanswered?.disabledServerIds ?? [];
2142
1783
  logLatency({
2143
1784
  type: "phase",
2144
1785
  phase: "lsp_touch_file",
@@ -2153,12 +1794,30 @@ export class LSPService {
2153
1794
  maxClientWaitMs: options.maxClientWaitMs,
2154
1795
  failureKind,
2155
1796
  ...waitSkipReasons.size > 0 ? { reason: [...waitSkipReasons][0] } : {},
1797
+ ...disabledPrimaryServerIds.length > 0 && {
1798
+ disabledPrimaryServerIds
1799
+ },
2156
1800
  candidates: this.describeTouchCandidates(filePath, resolvedPrimaryRoots, attemptedAuxiliaryRoots)
2157
1801
  }
2158
1802
  });
1803
+ if (unanswered !== undefined && (disabledPrimaryServerIds.length > 0 || options.nameUnansweredPrimaries === true && unanswered.serverIds.length > 0)) {
1804
+ return {
1805
+ diags: [],
1806
+ ...resolveTouchVerdict({
1807
+ unavailablePrimaryServerIds: unanswered.serverIds,
1808
+ disabledPrimaryServerIds,
1809
+ primaryUnavailableCause: unanswered.cause,
1810
+ primaryNotifyWriteTimedOutServerIds: [],
1811
+ diagnosticsTimedOut: false,
1812
+ diagnosticsUnansweredServerIds: []
1813
+ })
1814
+ };
1815
+ }
2159
1816
  return;
2160
1817
  }
2161
- const leaseKeys = await this.acquireClientLeases(spawned, filePath);
1818
+ const unanswered = unansweredPrimaries(spawned, resolvedPrimaryRoots, filePath);
1819
+ const unavailablePrimaryServerIds = unanswered.serverIds;
1820
+ const leaseKeys = await this.clientRegistry.acquireClientLeases(spawned, filePath);
2162
1821
  if (!leaseKeys) {
2163
1822
  if (this.checkDestroyed()) {
2164
1823
  const primaryServerIds = spawned.filter((entry) => !isAuxiliary(entry.info)).map((entry) => entry.info.id);
@@ -2174,7 +1833,8 @@ export class LSPService {
2174
1833
  return this.touchFile(filePath, content, options);
2175
1834
  }
2176
1835
  try {
2177
- if (this.shouldSkipTouch(filePath, contentFingerprint, clientScope, diagnosticsMode !== "none", spawned)) {
1836
+ if (this.shouldSkipTouch(filePath, contentHash, diagnosticsMode !== "none", spawned)) {
1837
+ const savedServerIds = spawned.flatMap((entry) => this.saveDebouncedPush(filePath, entry, options.saved === true, contentHash) ?? []);
2178
1838
  logLatency({
2179
1839
  type: "phase",
2180
1840
  phase: "lsp_touch_file",
@@ -2187,15 +1847,17 @@ export class LSPService {
2187
1847
  source,
2188
1848
  failureKind: "success",
2189
1849
  skipped: true,
2190
- reason: "debounced_unchanged_content"
1850
+ reason: "debounced_unchanged_content",
1851
+ ...savedServerIds.length > 0 && { savedServerIds }
2191
1852
  }
2192
1853
  });
2193
1854
  return { diags: [] };
2194
1855
  }
2195
1856
  const languageId = getLanguageId(filePath) ?? "plaintext";
2196
1857
  const silent = options.silent ?? false;
2197
- const notifySkippedServerIds = new Set(spawned.filter((entry) => this.shouldSkipNotify(filePath, contentFingerprint, clientScope, entry.info.id, entry.client)).map((entry) => entry.info.id));
1858
+ const notifySkippedServerIds = new Set(spawned.filter((entry) => this.shouldSkipNotify(filePath, contentHash, entry.info.id, entry.client)).map((entry) => entry.info.id));
2198
1859
  const notifySkipped = spawned.length > 0 && notifySkippedServerIds.size === spawned.length;
1860
+ const savedServerIds = spawned.flatMap((entry) => notifySkippedServerIds.has(entry.info.id) ? this.saveDebouncedPush(filePath, entry, options.saved === true, contentHash) ?? [] : []);
2199
1861
  const readPathVersion = (client) => client.getDiagnosticsVersionForPath?.(filePath);
2200
1862
  const diagnosticBaselines = new Map(spawned.map((entry) => [entry.client, readPathVersion(entry.client)]));
2201
1863
  const markedAtMs = Date.now();
@@ -2218,6 +1880,7 @@ export class LSPService {
2218
1880
  return false;
2219
1881
  return auxPublishedThisContent.has(serverId) || bindingMatchesTouchContent(entry.client.getDiagnosticBinding?.(filePath));
2220
1882
  };
1883
+ const auxPublishedCount = (client, published) => published ? client.getDiagnostics?.(filePath)?.length ?? 0 : 0;
2221
1884
  const notifyWriteTimedOutServerIds = [];
2222
1885
  const notifyDeferredServerIds = [];
2223
1886
  const supersededServerIds = [];
@@ -2262,7 +1925,7 @@ export class LSPService {
2262
1925
  let rejected = false;
2263
1926
  try {
2264
1927
  const writeStartedAt = Date.now();
2265
- const writePromise = entry.client.notify.open(filePath, content, languageId, undefined, silent, options.saved === true, options.readStamp).then((sent) => sent !== false);
1928
+ const writePromise = entry.client.notify.open(filePath, content, languageId, undefined, silent, options.saved === true, options.readStamp, contentHash).then((sent) => sent !== false);
2266
1929
  if (gated && clientKey) {
2267
1930
  this.noteAuxNotifyIssued(clientKey, entry.client);
2268
1931
  }
@@ -2289,7 +1952,7 @@ export class LSPService {
2289
1952
  if (wrote === true) {
2290
1953
  if (clientKey)
2291
1954
  this.notifyWriteBackpressureStreak.delete(clientKey);
2292
- this.markTouched(filePath, contentFingerprint(), clientScope, entry.info.id, entry.client);
1955
+ this.markTouched(filePath, entry.info.id, entry.client);
2293
1956
  } else if (wrote === false) {
2294
1957
  supersededServerIds.push(entry.info.id);
2295
1958
  } else {
@@ -2565,14 +2228,16 @@ export class LSPService {
2565
2228
  const outcomes = await Promise.all(auxWaits.map(async (aux) => {
2566
2229
  const { budgetMs } = aux;
2567
2230
  if (aux.demoted) {
2231
+ const demotedPublished = auxiliaryPublicationEvidence({
2232
+ bindingMatchesContent: auxCoversThisContent(aux.serverId),
2233
+ baseline: aux.baseline,
2234
+ currentPathVersion: readPathVersion(aux.client)
2235
+ });
2568
2236
  return {
2569
2237
  serverId: aux.serverId,
2570
2238
  outcome: deferredResyncServerIds.has(aux.serverId) ? "deferred" : "demoted",
2571
- publishedThisContent: auxiliaryPublicationEvidence({
2572
- bindingMatchesContent: auxCoversThisContent(aux.serverId),
2573
- baseline: aux.baseline,
2574
- currentPathVersion: readPathVersion(aux.client)
2575
- }),
2239
+ publishedThisContent: demotedPublished,
2240
+ publishedCount: auxPublishedCount(aux.client, demotedPublished),
2576
2241
  budgetMs,
2577
2242
  elapsedMs: 0,
2578
2243
  elapsedSinceNotifyMs: 0
@@ -2607,6 +2272,7 @@ export class LSPService {
2607
2272
  serverId: aux.serverId,
2608
2273
  outcome,
2609
2274
  publishedThisContent: auxCoversThisContent(aux.serverId),
2275
+ publishedCount: auxPublishedCount(aux.client, publishedEvidence || auxCoversThisContent(aux.serverId)),
2610
2276
  budgetMs,
2611
2277
  elapsedMs,
2612
2278
  elapsedSinceNotifyMs: Date.now() - waitStartedAt
@@ -2709,6 +2375,7 @@ export class LSPService {
2709
2375
  serverId: entry.info.id,
2710
2376
  outcome: deferredResyncServerIds.has(entry.info.id) ? "deferred" : publishedEvidence ? "answered" : "silent",
2711
2377
  publishedThisContent: auxCoversThisContent(entry.info.id),
2378
+ publishedCount: auxPublishedCount(entry.client, publishedEvidence || auxCoversThisContent(entry.info.id)),
2712
2379
  budgetMs: timeoutFor(entry.client.serverId),
2713
2380
  elapsedMs: waitedMs,
2714
2381
  elapsedSinceNotifyMs: waitedMs
@@ -2868,28 +2535,39 @@ export class LSPService {
2868
2535
  } catch {}
2869
2536
  }
2870
2537
  const verdict = resolveTouchVerdict({
2538
+ unavailablePrimaryServerIds,
2539
+ disabledPrimaryServerIds: unanswered.disabledServerIds,
2540
+ primaryUnavailableCause: unanswered.cause,
2871
2541
  primaryNotifyWriteTimedOutServerIds,
2872
2542
  diagnosticsTimedOut,
2873
2543
  diagnosticsUnansweredServerIds: diagnosticsUnansweredPrimaryServerIds
2874
2544
  });
2875
2545
  const inconclusive = verdict.inconclusive;
2876
- const brokenSkippedServerIds = collected !== undefined ? await this.brokenSkippedAuxiliaryServerIds(filePath, clientScope, options, spawned) : [];
2546
+ const skippedAuxiliaries = collected !== undefined ? await this.skippedAuxiliaryServerIds(filePath, clientScope, options, spawned) : { brokenSkippedServerIds: [], policySkippedServerIds: [] };
2547
+ const brokenSkippedServerIds = skippedAuxiliaries.brokenSkippedServerIds;
2548
+ const policySkippedServerIds = skippedAuxiliaries.policySkippedServerIds;
2877
2549
  const auxNoAnswerServerIds = spawned.filter((entry) => isAuxiliary(entry.info) && (diagnosticsUnansweredServerIds.includes(entry.info.id) || notifyWriteTimedOutServerIds.includes(entry.info.id)) && !auxCoveredAtMerge.has(entry.info.id)).map((entry) => entry.info.id);
2878
2550
  const unconfirmedServerIds = [
2879
2551
  ...new Set([
2880
2552
  ...auxUnconfirmedServerIds ?? [],
2881
2553
  ...auxNoAnswerServerIds,
2882
2554
  ...uncoveredDeferredServerIds,
2883
- ...brokenSkippedServerIds
2555
+ ...brokenSkippedServerIds,
2556
+ ...policySkippedServerIds
2884
2557
  ])
2885
2558
  ].filter((serverId) => !auxCoveredAtMerge.has(serverId));
2886
2559
  const coverageGap = unconfirmedServerIds.length > 0;
2887
- if (brokenSkippedServerIds.length > 0 || uncoveredDeferredServerIds.length > 0 || auxNoAnswerServerIds.length > 0) {
2560
+ if (brokenSkippedServerIds.length > 0 || policySkippedServerIds.length > 0 || uncoveredDeferredServerIds.length > 0 || auxNoAnswerServerIds.length > 0) {
2561
+ const configFailureSuffix = (serverId) => {
2562
+ const failure = spawned.find((entry) => entry.info.id === serverId)?.client.getConfigLoadFailure?.();
2563
+ return failure ? ` (server reported: ${failure})` : "";
2564
+ };
2888
2565
  for (const serverId of unconfirmedServerIds) {
2889
2566
  const reasons = [
2890
2567
  brokenSkippedServerIds.includes(serverId) && "breaker skip",
2568
+ policySkippedServerIds.includes(serverId) && "root policy skip",
2891
2569
  uncoveredDeferredServerIds.includes(serverId) && "deferred resync",
2892
- auxNoAnswerServerIds.includes(serverId) && "no diagnostics answer"
2570
+ auxNoAnswerServerIds.includes(serverId) && `no diagnostics answer${configFailureSuffix(serverId)}`
2893
2571
  ].filter(Boolean);
2894
2572
  incrementDegradationCount({
2895
2573
  kind: "lsp-scanner-coverage-gap",
@@ -2906,6 +2584,9 @@ export class LSPService {
2906
2584
  ...brokenSkippedServerIds.length > 0 && {
2907
2585
  brokenSkippedServerIds
2908
2586
  },
2587
+ ...policySkippedServerIds.length > 0 && {
2588
+ policySkippedServerIds
2589
+ },
2909
2590
  ...uncoveredDeferredServerIds.length > 0 && {
2910
2591
  deferredResyncServerIds: uncoveredDeferredServerIds
2911
2592
  },
@@ -2947,6 +2628,12 @@ export class LSPService {
2947
2628
  result.inconclusiveServerIds = verdict.inconclusiveServerIds;
2948
2629
  }
2949
2630
  result.inconclusiveReason = verdict.inconclusiveReason;
2631
+ if (verdict.disabledPrimaryServerIds) {
2632
+ result.disabledPrimaryServerIds = verdict.disabledPrimaryServerIds;
2633
+ }
2634
+ if (verdict.primaryUnavailableCause) {
2635
+ result.primaryUnavailableCause = verdict.primaryUnavailableCause;
2636
+ }
2950
2637
  } else if (collected !== undefined && primaryDiagnosticsUnsupported) {
2951
2638
  if (unconfirmedServerIds.length > 0) {
2952
2639
  result.unconfirmedServerIds = [...unconfirmedServerIds];
@@ -2993,6 +2680,7 @@ export class LSPService {
2993
2680
  notifyWriteTimedOutServerIds
2994
2681
  },
2995
2682
  ...supersededServerIds.length > 0 && { supersededServerIds },
2683
+ ...savedServerIds.length > 0 && { savedServerIds },
2996
2684
  diagnosticsTimedOut,
2997
2685
  inconclusive,
2998
2686
  ...verdict.inconclusiveServerIds && {
@@ -3009,6 +2697,7 @@ export class LSPService {
3009
2697
  auxUnconfirmedServerIds
3010
2698
  },
3011
2699
  ...brokenSkippedServerIds.length > 0 && { brokenSkippedServerIds },
2700
+ ...policySkippedServerIds.length > 0 && { policySkippedServerIds },
3012
2701
  ...uncoveredDeferredServerIds.length > 0 && {
3013
2702
  deferredResyncServerIds: uncoveredDeferredServerIds
3014
2703
  },
@@ -3021,13 +2710,13 @@ export class LSPService {
3021
2710
  return result;
3022
2711
  } finally {
3023
2712
  for (const lease of leaseKeys)
3024
- this.releaseClientLease(lease.key, lease.server);
2713
+ this.clientRegistry.releaseClientLease(lease.key, lease.server);
3025
2714
  }
3026
2715
  }
3027
2716
  async findOutsideProjectRoot(filePath) {
3028
- if (!this.fileIsOutsideRegisteredRoots(filePath))
2717
+ if (!this.clientRegistry.fileIsOutsideRegisteredRoots(filePath))
3029
2718
  return;
3030
- if (this.analysisRootModeForFile(filePath) === "adopted")
2719
+ if (this.clientRegistry.analysisRootModeForFile(filePath) === "adopted")
3031
2720
  return;
3032
2721
  const candidates = await Promise.all(getServersForFileWithConfig(filePath).map((server) => server.root(filePath)));
3033
2722
  return candidates.find((candidate) => Boolean(candidate));
@@ -3063,7 +2752,7 @@ export class LSPService {
3063
2752
  }
3064
2753
  return this.lastKnownDiagnostics.get(normalizedKey);
3065
2754
  }
3066
- async getDiagnostics(filePath, diagnosticsMode = "full") {
2755
+ async getDiagnostics(filePath, diagnosticsMode = "full", excludeServerIds) {
3067
2756
  const normalizedPath = normalizeMapKey(filePath);
3068
2757
  const outsideRoot = await this.findOutsideProjectRoot(filePath);
3069
2758
  if (outsideRoot) {
@@ -3084,11 +2773,15 @@ export class LSPService {
3084
2773
  return [];
3085
2774
  }
3086
2775
  const startedAt = Date.now();
3087
- const candidateServerIds = getServersForFileWithConfig(filePath).map((s) => s.id);
3088
- const { clients: spawned, serverCountAttempted } = await this.getClientsForFile(filePath);
2776
+ const candidateServerIds = getServersForFileWithConfig(filePath).flatMap((s) => excludeServerIds?.has(s.id) ? [] : [s.id]);
2777
+ const resolvedPrimaryRoots = new Map;
2778
+ const { clients: spawned, serverCountAttempted } = await this.getClientsForFile(filePath, excludeServerIds, resolvedPrimaryRoots);
3089
2779
  if (spawned.length === 0) {
3090
- const stale = this.lastKnownDiagnostics.get(normalizedPath);
2780
+ const stored = this.lastKnownDiagnostics.get(normalizedPath);
2781
+ const stale = excludeServerIds !== undefined && excludeServerIds.size > 0 ? stored?.filter((diagnostic) => !excludeServerIds.has(diagnostic.serverId ?? "")) : stored;
3091
2782
  const failureKind = stale?.length ? "no_clients_stale" : "no_clients";
2783
+ const unanswered = unansweredPrimaries(spawned, resolvedPrimaryRoots, filePath);
2784
+ const unavailablePrimaryServerIds = unanswered.serverIds;
3092
2785
  this.lastDiagnosticsHealth.set(normalizedPath, {
3093
2786
  health: failureKind,
3094
2787
  failureKind,
@@ -3097,7 +2790,14 @@ export class LSPService {
3097
2790
  candidateServerIds,
3098
2791
  mergedCount: stale?.length ?? 0,
3099
2792
  dedupDroppedCount: 0,
3100
- checkedAt: new Date().toISOString()
2793
+ checkedAt: new Date().toISOString(),
2794
+ unavailablePrimaryServerIds,
2795
+ ...unanswered.disabledServerIds.length > 0 && {
2796
+ disabledPrimaryServerIds: unanswered.disabledServerIds
2797
+ },
2798
+ ...unavailablePrimaryServerIds.length > 0 && {
2799
+ primaryUnavailableCause: unanswered.cause
2800
+ }
3101
2801
  });
3102
2802
  logLatency({
3103
2803
  type: "phase",
@@ -3111,7 +2811,10 @@ export class LSPService {
3111
2811
  dedupDroppedCount: 0,
3112
2812
  failureKind,
3113
2813
  health: failureKind,
3114
- servers: []
2814
+ servers: [],
2815
+ ...unavailablePrimaryServerIds.length > 0 && {
2816
+ unavailablePrimaryServerIds
2817
+ }
3115
2818
  }
3116
2819
  });
3117
2820
  return stale ?? [];
@@ -3177,6 +2880,8 @@ export class LSPService {
3177
2880
  const rawCount = perServerFull.reduce((sum, entry) => sum + entry.diagnosticCount, 0);
3178
2881
  const serversWithDiagnostics = perServerFull.filter((entry) => entry.diagnosticCount > 0).length;
3179
2882
  const failureKind = merged.length === 0 ? "ok_empty" : "success";
2883
+ const unanswered = unansweredPrimaries(spawned, resolvedPrimaryRoots, filePath);
2884
+ const unavailablePrimaryServerIds = unanswered.serverIds;
3180
2885
  this.lastDiagnosticsHealth.set(normalizedPath, {
3181
2886
  health: failureKind === "success" ? "ok" : "ok_empty",
3182
2887
  failureKind,
@@ -3185,7 +2890,14 @@ export class LSPService {
3185
2890
  candidateServerIds,
3186
2891
  mergedCount: merged.length,
3187
2892
  dedupDroppedCount: rawCount - merged.length,
3188
- checkedAt: new Date().toISOString()
2893
+ checkedAt: new Date().toISOString(),
2894
+ unavailablePrimaryServerIds,
2895
+ ...unanswered.disabledServerIds.length > 0 && {
2896
+ disabledPrimaryServerIds: unanswered.disabledServerIds
2897
+ },
2898
+ ...unavailablePrimaryServerIds.length > 0 && {
2899
+ primaryUnavailableCause: unanswered.cause
2900
+ }
3189
2901
  });
3190
2902
  logLatency({
3191
2903
  type: "phase",
@@ -3206,7 +2918,10 @@ export class LSPService {
3206
2918
  id: entry.serverId,
3207
2919
  waitMs: entry.waitMs,
3208
2920
  diagnosticCount: entry.diagnosticCount
3209
- }))
2921
+ })),
2922
+ ...unavailablePrimaryServerIds.length > 0 && {
2923
+ unavailablePrimaryServerIds
2924
+ }
3210
2925
  }
3211
2926
  });
3212
2927
  if (merged.length > 0) {
@@ -3370,7 +3085,7 @@ export class LSPService {
3370
3085
  return { executed: false, reason: "lsp service destroyed" };
3371
3086
  }
3372
3087
  for (const server of getServersForFileWithConfig(filePath)) {
3373
- const root = await this.resolveServerRoot(server, filePath);
3088
+ const root = await this.clientRegistry.resolveServerRoot(server, filePath);
3374
3089
  if (!root)
3375
3090
  continue;
3376
3091
  const entry = this.state.clients.get(`${server.id}:${normalizeMapKey(root)}`);
@@ -3425,7 +3140,7 @@ export class LSPService {
3425
3140
  if (filePath) {
3426
3141
  const servers = getServersForFileWithConfig(filePath);
3427
3142
  for (const server of servers) {
3428
- const root = await this.resolveServerRoot(server, filePath);
3143
+ const root = await this.clientRegistry.resolveServerRoot(server, filePath);
3429
3144
  if (!root)
3430
3145
  continue;
3431
3146
  const client = this.state.clients.get(`${server.id}:${normalizeMapKey(root)}`);
@@ -3538,21 +3253,24 @@ export class LSPService {
3538
3253
  });
3539
3254
  return false;
3540
3255
  });
3541
- const willResults = await Promise.all(willRenameClients.map(async ({ serverId, client }) => {
3256
+ const renameRequestedAtMs = Date.now();
3257
+ const willResults = await Promise.all(willRenameClients.map(async ({ clientKey, serverId, client }) => {
3542
3258
  try {
3543
3259
  return {
3260
+ clientKey,
3544
3261
  serverId,
3545
- edit: await client.willRenameFiles(oldFilePath, newFilePath)
3262
+ edit: await client.willRenameFiles(oldFilePath, newFilePath),
3263
+ failed: false
3546
3264
  };
3547
3265
  } catch (err) {
3548
3266
  willRenameFailures.push({
3549
3267
  serverId,
3550
3268
  error: err instanceof Error ? err.message : String(err)
3551
3269
  });
3552
- return { serverId, edit: null };
3270
+ return { clientKey, serverId, edit: null, failed: true };
3553
3271
  }
3554
3272
  }));
3555
- const successfulWillResults = willResults.filter((result) => !willRenameFailures.some((failure) => failure.serverId === result.serverId));
3273
+ const successfulWillResults = willResults.filter((result) => !result.failed);
3556
3274
  if (willRenameClients.length > 0 && successfulWillResults.length === 0) {
3557
3275
  throw new Error(`workspace/willRenameFiles failed for all active LSP servers: ${willRenameFailures.map((failure) => `${failure.serverId}: ${failure.error}`).join("; ")}`);
3558
3276
  }
@@ -3573,7 +3291,9 @@ export class LSPService {
3573
3291
  try {
3574
3292
  applied = await applyWorkspaceEdit(merged.edit, cwd, {
3575
3293
  mutationContext: options.mutationContext,
3576
- observe: false
3294
+ observe: false,
3295
+ watchedFileSink: this,
3296
+ expectedContent: captureRenameExpectedContent(merged.edit, cwd, renameRequestedAtMs, (filePath, atCwd, sourceClientKeys) => sourceClientKeys === undefined ? this.getTrackedContent(filePath, atCwd) : this.getTrackedContent(filePath, atCwd, sourceClientKeys), undefined, merged.sourceClientKeys)
3577
3297
  });
3578
3298
  } catch (err) {
3579
3299
  if (options.mutationContext) {
@@ -3587,7 +3307,8 @@ export class LSPService {
3587
3307
  }
3588
3308
  throw err;
3589
3309
  }
3590
- const openDocuments = activeClients.filter(({ client }) => client.isDocumentOpen(oldFilePath)).map(({ serverId, client }) => ({
3310
+ const openDocuments = activeClients.filter(({ client }) => client.isDocumentOpen(oldFilePath)).map(({ clientKey, serverId, client }) => ({
3311
+ clientKey,
3591
3312
  serverId,
3592
3313
  client,
3593
3314
  oldUri: client.getDocumentUri(oldFilePath)
@@ -3656,7 +3377,7 @@ export class LSPService {
3656
3377
  newUri: pathToFileURL(newFilePath).href
3657
3378
  }
3658
3379
  ]
3659
- }, cwd, { observe: false });
3380
+ }, cwd, { observe: false, watchedFileSink: this });
3660
3381
  } catch (err) {
3661
3382
  if (options.mutationContext) {
3662
3383
  recordLspMutation(options.mutationContext, {
@@ -3669,7 +3390,7 @@ export class LSPService {
3669
3390
  const relOld = path.relative(cwd, oldFilePath).replace(/\\/g, "/") || path.basename(oldFilePath);
3670
3391
  const relNew = path.relative(cwd, newFilePath).replace(/\\/g, "/") || path.basename(newFilePath);
3671
3392
  const renameDescription = `Renamed ${relOld} → ${relNew}`;
3672
- await Promise.all(activeClients.map(async ({ serverId, client }) => {
3393
+ await Promise.all(activeClients.map(async ({ clientKey, serverId, client }) => {
3673
3394
  if (client.getOperationSupport().didRenameFiles !== true) {
3674
3395
  recordDegradationOnce({
3675
3396
  kind: "lsp-capability-skip",
@@ -3678,7 +3399,7 @@ export class LSPService {
3678
3399
  });
3679
3400
  return;
3680
3401
  }
3681
- const opened = openDocuments.find((entry) => entry.serverId === serverId);
3402
+ const opened = openDocuments.find((entry) => entry.clientKey === clientKey);
3682
3403
  const result = await runRenameNotify(() => opened?.oldUri ? client.didRenameFiles(oldFilePath, newFilePath, opened.oldUri, destinationUriPreservingSpelling(opened.oldUri, oldFilePath, newFilePath)) : client.didRenameFiles(oldFilePath, newFilePath), RENAME_NOTIFY_TIMEOUT_MS);
3683
3404
  if (!result.ok) {
3684
3405
  didRenameFailures.push({
@@ -3990,6 +3711,7 @@ export class LSPService {
3990
3711
  }));
3991
3712
  return !capped;
3992
3713
  };
3714
+ this.announceCreatedFiles([...files, ...goPackageFilesToAnnounce(files)], await importTargetsToAnnounce(root, files.filter((filePath) => !workspaceDiagnosticsCacheCtx.servesClean(filePath, workspaceSweepScopeKey)), (filePath, scope) => workspaceDiagnosticsCacheCtx.noteImportScope(filePath, scope)));
3993
3715
  const cachedResults = [];
3994
3716
  const filesToTouch = [];
3995
3717
  const writeIndexByPath = new Map;
@@ -4124,7 +3846,13 @@ export class LSPService {
4124
3846
  await this.ensureWarmForSweep(filePath, { signal });
4125
3847
  }
4126
3848
  const touchResult = attached?.available ? {
4127
- diags: attached.response.diagnostics,
3849
+ diags: attached.response.projectIdentity === undefined ? attached.response.diagnostics : await demoteInferredProjectDiagnostics(attached.response.diagnostics, {
3850
+ filePath,
3851
+ cwd,
3852
+ identityCache: new Map([
3853
+ [filePath, attached.response.projectIdentity]
3854
+ ])
3855
+ }),
4128
3856
  ...attached.response.unconfirmedServerIds !== undefined && {
4129
3857
  unconfirmedServerIds: attached.response.unconfirmedServerIds
4130
3858
  }
@@ -4144,7 +3872,7 @@ export class LSPService {
4144
3872
  const timedOut = touchResult === undefined || inconclusive || declinedOutsideRoot;
4145
3873
  if (timedOut)
4146
3874
  timedOutFiles += 1;
4147
- const unconfirmedReason = touchResult === undefined ? "budget" : declinedOutsideRoot ? "outside_project_root" : inconclusive ? "inconclusive" : undefined;
3875
+ const unconfirmedReason = touchResult === undefined ? "budget" : declinedOutsideRoot ? "outside_project_root" : inconclusive ? touchResult?.inconclusiveReason === "primary-unavailable" ? SWEEP_REASON_FOR_CAUSE[touchResult.primaryUnavailableCause ?? "unstarted"] : "inconclusive" : undefined;
4148
3876
  const rawBinding = touchResult?.binding;
4149
3877
  const filteredDiagnostics = diagnostics ? applyAuxiliarySuppressions(diagnostics, content, {
4150
3878
  fileRole: detectFileRole(filePath, content),
@@ -4245,12 +3973,13 @@ export class LSPService {
4245
3973
  }
4246
3974
  });
4247
3975
  for (const filePath of group.files) {
3976
+ const { disabledServerIds, fallbackServerIds } = disabledPrimaries(filePath);
4248
3977
  results.push({
4249
3978
  filePath,
4250
3979
  diagnostics: [],
4251
3980
  count: 0,
4252
3981
  timedOut: true,
4253
- unconfirmedReason: "inconclusive",
3982
+ unconfirmedReason: SWEEP_REASON_FOR_CAUSE[primaryUnavailableCause([...warmup.failedServerIds, ...disabledServerIds], disabledServerIds, fallbackServerIds)],
4254
3983
  skippedWarmupFailure: true
4255
3984
  });
4256
3985
  timedOutFiles += 1;
@@ -4397,7 +4126,7 @@ export class LSPService {
4397
4126
  return;
4398
4127
  }
4399
4128
  }
4400
- async getAllDiagnostics() {
4129
+ async getAllDiagnostics(excludeServerIds) {
4401
4130
  const all = new Map;
4402
4131
  const bindingsByPath = new Map;
4403
4132
  const now = Date.now();
@@ -4412,6 +4141,8 @@ export class LSPService {
4412
4141
  return true;
4413
4142
  }));
4414
4143
  client.pruneDiagnostics((filePath, ts) => !existingPaths.has(filePath) || now - ts > CASCADE_DIAGNOSTICS_TTL_MS);
4144
+ if (excludeServerIds?.has(client.serverId))
4145
+ continue;
4415
4146
  const clientDiags = client.getAllDiagnostics();
4416
4147
  for (const [filePath, entry] of clientDiags) {
4417
4148
  const attributed = attributeDiagnostics(client.serverId, entry.diags);
@@ -4444,13 +4175,6 @@ export class LSPService {
4444
4175
  supportsLSP(filePath) {
4445
4176
  return getServersForFileWithConfig(filePath).length > 0;
4446
4177
  }
4447
- isSpawnInFlight(_filePath, resolvedRoots = new Map) {
4448
- for (const [serverId, root] of resolvedRoots) {
4449
- if (this.state.inFlight.has(`${serverId}:${root}`))
4450
- return true;
4451
- }
4452
- return false;
4453
- }
4454
4178
  describeTouchCandidates(filePath, resolvedRoots, auxiliaryRoots = new Map) {
4455
4179
  const candidates = [];
4456
4180
  for (const server of getServersForFileWithConfig(filePath)) {
@@ -4483,28 +4207,12 @@ export class LSPService {
4483
4207
  const resetStartedAt = Date.now();
4484
4208
  if (this.checkDestroyed())
4485
4209
  return;
4486
- this.isDestroyed = true;
4210
+ this.clientRegistry.markDestroyed();
4487
4211
  this.shutdownController.abort();
4488
4212
  for (const [key, token] of this.outstandingAuxNotifyWrites) {
4489
4213
  this.releaseOutstandingAuxNotifyWrite(key, token);
4490
4214
  }
4491
- for (const key of this.idleEvictionTimers.keys()) {
4492
- this.clearIdleEvictionTimer(key);
4493
- }
4494
- if (!options.processExiting && this.state.inFlight.size > 0) {
4495
- const pending = Array.from(this.state.inFlight.values());
4496
- this.state.inFlight.clear();
4497
- const settled = await Promise.allSettled(pending);
4498
- for (const result of settled) {
4499
- if (result.status === "fulfilled" && result.value?.client) {
4500
- result.value.client.shutdown({ fast: true }).catch(() => {});
4501
- }
4502
- }
4503
- } else {
4504
- this.state.inFlight.clear();
4505
- }
4506
- const aliveClients = this.getAliveClientCount();
4507
- await Promise.allSettled(Array.from(this.state.clients.values(), (client) => Promise.resolve().then(() => client.shutdown(options))));
4215
+ const aliveClients = await this.clientRegistry.shutdownClients(options);
4508
4216
  logLatency({
4509
4217
  type: "phase",
4510
4218
  phase: "lsp_service_reset",
@@ -4518,10 +4226,8 @@ export class LSPService {
4518
4226
  processExiting: !!options.processExiting
4519
4227
  }
4520
4228
  });
4521
- this.state.clients.clear();
4522
- this.state.broken.clear();
4229
+ this.clientRegistry.clearAfterShutdown();
4523
4230
  this.firstContactWaits.clear();
4524
- this.lastSpawnVerdict.clear();
4525
4231
  for (const [key, token] of this.outstandingAuxNotifyWrites) {
4526
4232
  this.releaseOutstandingAuxNotifyWrite(key, token);
4527
4233
  }
@@ -4529,76 +4235,21 @@ export class LSPService {
4529
4235
  this.auxNotifyDrainLatencyEwma.clear();
4530
4236
  this.auxNotifyInflight.clear();
4531
4237
  this.documentDrift.clear();
4532
- this.workspaceProbeLogged.clear();
4533
- this.warmStartLogged.clear();
4534
4238
  }
4535
- getStatus() {
4536
- return Array.from(this.state.clients.entries()).map(([key, client]) => {
4537
- const [serverId, root] = key.split(":");
4538
- return {
4539
- serverId,
4540
- root,
4541
- connected: client.isAlive(),
4542
- pullFailureHistory: (client.getPullFailureHistory?.() ?? []).map((entry) => ({
4543
- ...entry,
4544
- message: entry.message.slice(0, 200)
4545
- }))
4546
- };
4547
- });
4239
+ isSpawnInFlight(filePath, resolvedRoots) {
4240
+ return this.clientRegistry.isSpawnInFlight(filePath, resolvedRoots);
4548
4241
  }
4549
- recordRuntimeExitWindow(key, exitedAt, uptimeMs) {
4550
- if (exitedAt == null || uptimeMs == null || uptimeMs > RUNTIME_EXIT_WINDOW_UPTIME_CEILING_MS) {
4551
- return false;
4552
- }
4553
- const deaths = this.runtimeExitWindow.get(key) ?? [];
4554
- deaths.push(exitedAt);
4555
- const windowRef = Math.max(...deaths);
4556
- const windowStart = windowRef - RUNTIME_EXIT_WINDOW_MS;
4557
- let pruned = deaths.filter((t) => t >= windowStart);
4558
- if (pruned.length > RUNTIME_EXIT_WINDOW_TRIP_COUNT) {
4559
- pruned = pruned.slice(pruned.length - RUNTIME_EXIT_WINDOW_TRIP_COUNT);
4560
- }
4561
- this.runtimeExitWindow.set(key, pruned);
4562
- return pruned.length >= RUNTIME_EXIT_WINDOW_TRIP_COUNT;
4242
+ getStatus() {
4243
+ return this.clientRegistry.getStatus();
4563
4244
  }
4564
4245
  getBrokenStatus() {
4565
- const keys = new Set([
4566
- ...this.state.broken.keys(),
4567
- ...this.permanentlyBroken
4568
- ]);
4569
- return [...keys].map((key) => {
4570
- const separator = key.indexOf(":");
4571
- return {
4572
- serverId: separator >= 0 ? key.slice(0, separator) : key,
4573
- root: separator >= 0 ? key.slice(separator + 1) : "",
4574
- failures: (this.failureCounts.get(key) ?? 0) + Math.max(this.runtimeExitCounts.get(key) ?? 0, this.runtimeExitWindow.get(key)?.length ?? 0),
4575
- permanentlyBroken: this.permanentlyBroken.has(key),
4576
- cooldownUntil: this.state.broken.get(key) ?? 0
4577
- };
4578
- });
4246
+ return this.clientRegistry.getBrokenStatus();
4579
4247
  }
4580
4248
  getAliveClientCount() {
4581
- let count = 0;
4582
- for (const client of this.state.clients.values()) {
4583
- if (client.isAlive())
4584
- count++;
4585
- }
4586
- return count;
4249
+ return this.clientRegistry.getAliveClientCount();
4587
4250
  }
4588
4251
  getAliveServerIds() {
4589
- const primary = [];
4590
- const aux = [];
4591
- const seen = new Set;
4592
- for (const client of this.state.clients.values()) {
4593
- if (!client.isAlive())
4594
- continue;
4595
- const id = client.serverId;
4596
- if (seen.has(id))
4597
- continue;
4598
- seen.add(id);
4599
- (isAuxiliary(getServerById(id)) ? aux : primary).push(id);
4600
- }
4601
- return [...primary, ...aux];
4252
+ return this.clientRegistry.getAliveServerIds();
4602
4253
  }
4603
4254
  }
4604
4255
  configureLspServiceLifecycle({
@@ -4632,6 +4283,8 @@ export function resetLSPService(options = {}) {
4632
4283
  resetClassicTsRepairGuard();
4633
4284
  clearWorkspaceSweepHoldForSessionStart();
4634
4285
  }
4286
+ if (options.reason === "session_shutdown")
4287
+ emitCreatedImportScanRollupAtSessionEnd();
4635
4288
  resetOwnedLspService(options);
4636
4289
  }
4637
4290
  export function __collectWorkspaceDiagnosticFilesForTest(root, maxFiles, signal, homeDir) {