oh-my-opencode 5.1.82 → 5.1.84

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 (150) hide show
  1. package/dist/cli/cli-program.d.ts +3 -0
  2. package/dist/cli/index.js +202 -193
  3. package/dist/cli-node/index.js +202 -193
  4. package/dist/index.js +28 -22
  5. package/dist/skills/browser/SKILL.md +97 -91
  6. package/dist/skills/browser/references/commands.md +88 -26
  7. package/dist/skills/browser/references/desktop.md +21 -0
  8. package/dist/skills/browser/references/install.md +18 -0
  9. package/dist/skills/browser/references/owned-engine/README.md +5 -2
  10. package/dist/skills/browser/references/owned-engine/frames-and-humans.md +7 -2
  11. package/dist/skills/browser/references/owned-engine/network.md +4 -3
  12. package/dist/skills/browser/references/recipes/1password.md +4 -2
  13. package/dist/skills/browser/runtime/omowright/index.js +7 -7
  14. package/dist/skills/browser/runtime/omowright/manifest.json +4 -4
  15. package/dist/skills/debugging/references/tools/browser-qa.md +1 -1
  16. package/dist/skills/programming/SKILL.md +51 -320
  17. package/dist/skills/programming/references/go/README.md +1 -0
  18. package/dist/skills/programming/references/python/README.md +21 -3
  19. package/dist/skills/programming/references/python/error-handling.md +14 -0
  20. package/dist/skills/programming/references/rust/README.md +5 -1
  21. package/dist/skills/programming/references/typescript/README.md +9 -3
  22. package/dist/skills/programming/references/typescript/error-handling.md +18 -0
  23. package/dist/skills/ultimate-browsing/SKILL.md +1 -1
  24. package/dist/skills/visual-qa/references/browser-setup.md +5 -5
  25. package/dist/tui.js +16 -16
  26. package/package.json +14 -14
  27. package/packages/lsp-core/src/lsp/client-key.ts +14 -0
  28. package/packages/lsp-core/src/lsp/client-startup.ts +139 -0
  29. package/packages/lsp-core/src/lsp/client-wrapper.ts +4 -4
  30. package/packages/lsp-core/src/lsp/config-loader.ts +15 -0
  31. package/packages/lsp-core/src/lsp/directory-diagnostics-group-scan.test.ts +388 -0
  32. package/packages/lsp-core/src/lsp/directory-diagnostics-mixed-typescript.test.ts +124 -0
  33. package/packages/lsp-core/src/lsp/directory-diagnostics.test.ts +4 -4
  34. package/packages/lsp-core/src/lsp/directory-diagnostics.ts +38 -41
  35. package/packages/lsp-core/src/lsp/directory-group-scan.ts +124 -0
  36. package/packages/lsp-core/src/lsp/directory-server-groups.ts +84 -0
  37. package/packages/lsp-core/src/lsp/manager-acquisition.test.ts +115 -0
  38. package/packages/lsp-core/src/lsp/manager-lifecycle.test.ts +9 -9
  39. package/packages/lsp-core/src/lsp/manager-max-clients.test.ts +41 -16
  40. package/packages/lsp-core/src/lsp/manager-reaping.test.ts +119 -0
  41. package/packages/lsp-core/src/lsp/manager-test-support.ts +108 -0
  42. package/packages/lsp-core/src/lsp/manager.ts +80 -249
  43. package/packages/lsp-core/src/lsp/native-typescript.ts +88 -0
  44. package/packages/lsp-core/src/lsp/server-installation.ts +15 -7
  45. package/packages/lsp-core/src/lsp/server-resolution-typescript-native.test.ts +327 -0
  46. package/packages/lsp-core/src/lsp/server-resolution.ts +28 -2
  47. package/packages/lsp-core/src/lsp/timer-provider.ts +17 -0
  48. package/packages/lsp-core/src/lsp/typescript-project-test-support.ts +52 -0
  49. package/packages/lsp-daemon/dist/cli.js +486 -310
  50. package/packages/lsp-daemon/dist/client.js +472 -296
  51. package/packages/lsp-daemon/dist/index.js +476 -300
  52. package/packages/lsp-tools-mcp/dist/cli.js +467 -291
  53. package/packages/lsp-tools-mcp/dist/lsp/manager.js +160 -193
  54. package/packages/lsp-tools-mcp/dist/mcp.js +467 -291
  55. package/packages/lsp-tools-mcp/dist/tools.js +467 -291
  56. package/packages/omo-codex/plugin/.codex-plugin/plugin.json +1 -1
  57. package/packages/omo-codex/plugin/components/bootstrap/dist/cli.js +2 -2
  58. package/packages/omo-codex/plugin/components/bootstrap/hooks/hooks.json +1 -1
  59. package/packages/omo-codex/plugin/components/bootstrap/package.json +1 -1
  60. package/packages/omo-codex/plugin/components/comment-checker/hooks/hooks.json +1 -1
  61. package/packages/omo-codex/plugin/components/comment-checker/package.json +1 -1
  62. package/packages/omo-codex/plugin/components/git-bash/hooks/hooks.json +2 -2
  63. package/packages/omo-codex/plugin/components/git-bash/package.json +1 -1
  64. package/packages/omo-codex/plugin/components/lazycodex-executor-verify/hooks/hooks.json +1 -1
  65. package/packages/omo-codex/plugin/components/lazycodex-executor-verify/package.json +1 -1
  66. package/packages/omo-codex/plugin/components/lsp/dist/.omo-runtime-manifest.json +3 -3
  67. package/packages/omo-codex/plugin/components/lsp/dist/cli.js +478 -313
  68. package/packages/omo-codex/plugin/components/lsp/hooks/hooks.json +2 -2
  69. package/packages/omo-codex/plugin/components/lsp/package.json +1 -1
  70. package/packages/omo-codex/plugin/components/rules/hooks/hooks.json +4 -4
  71. package/packages/omo-codex/plugin/components/rules/package.json +1 -1
  72. package/packages/omo-codex/plugin/components/teammode/hooks/hooks.json +1 -1
  73. package/packages/omo-codex/plugin/components/teammode/package.json +1 -1
  74. package/packages/omo-codex/plugin/components/telemetry/dist/cli.js +8711 -172
  75. package/packages/omo-codex/plugin/components/telemetry/dist/posthog.js +8660 -121
  76. package/packages/omo-codex/plugin/components/telemetry/hooks/hooks.json +1 -1
  77. package/packages/omo-codex/plugin/components/telemetry/package.json +1 -1
  78. package/packages/omo-codex/plugin/components/telemetry/src/posthog.ts +5 -0
  79. package/packages/omo-codex/plugin/components/telemetry/tsconfig.json +2 -2
  80. package/packages/omo-codex/plugin/components/ultrawork/hooks/hooks.json +1 -1
  81. package/packages/omo-codex/plugin/components/ultrawork/package.json +1 -1
  82. package/packages/omo-codex/plugin/components/ulw-execute-continuation/hooks/hooks.json +1 -1
  83. package/packages/omo-codex/plugin/components/ulw-execute-continuation/package.json +1 -1
  84. package/packages/omo-codex/plugin/components/ulw-loop/hooks/hooks.json +5 -5
  85. package/packages/omo-codex/plugin/components/ulw-loop/package.json +1 -1
  86. package/packages/omo-codex/plugin/hooks/post-compact-resetting-git-bash-mcp-reminder.json +1 -1
  87. package/packages/omo-codex/plugin/hooks/post-compact-resetting-lsp-diagnostics-cache.json +1 -1
  88. package/packages/omo-codex/plugin/hooks/post-compact-resetting-project-rule-cache.json +1 -1
  89. package/packages/omo-codex/plugin/hooks/post-tool-use-checking-comments.json +1 -1
  90. package/packages/omo-codex/plugin/hooks/post-tool-use-checking-lsp-diagnostics.json +1 -1
  91. package/packages/omo-codex/plugin/hooks/post-tool-use-checking-thread-title-hygiene.json +1 -1
  92. package/packages/omo-codex/plugin/hooks/post-tool-use-matching-project-rules.json +1 -1
  93. package/packages/omo-codex/plugin/hooks/post-tool-use-recording-spawn-admission.json +1 -1
  94. package/packages/omo-codex/plugin/hooks/pre-tool-use-enforcing-unlimited-goal-budget.json +1 -1
  95. package/packages/omo-codex/plugin/hooks/pre-tool-use-guarding-ulw-loop-spawns.json +1 -1
  96. package/packages/omo-codex/plugin/hooks/pre-tool-use-recommending-git-bash-mcp.json +1 -1
  97. package/packages/omo-codex/plugin/hooks/session-start-checking-auto-update.json +1 -1
  98. package/packages/omo-codex/plugin/hooks/session-start-checking-bootstrap-provisioning.json +1 -1
  99. package/packages/omo-codex/plugin/hooks/session-start-loading-project-rules.json +1 -1
  100. package/packages/omo-codex/plugin/hooks/session-start-recording-session-telemetry.json +1 -1
  101. package/packages/omo-codex/plugin/hooks/stop-checking-ulw-execute-continuation.json +1 -1
  102. package/packages/omo-codex/plugin/hooks/stop-checking-ulw-loop-resume.json +1 -1
  103. package/packages/omo-codex/plugin/hooks/subagent-stop-verifying-lazycodex-executor-evidence.json +1 -1
  104. package/packages/omo-codex/plugin/hooks/user-prompt-submit-checking-ultrawork-trigger.json +1 -1
  105. package/packages/omo-codex/plugin/hooks/user-prompt-submit-checking-ulw-loop-steering.json +1 -1
  106. package/packages/omo-codex/plugin/hooks/user-prompt-submit-loading-project-rules.json +1 -1
  107. package/packages/omo-codex/plugin/package-lock.json +12 -12
  108. package/packages/omo-codex/plugin/package.json +1 -1
  109. package/packages/omo-codex/plugin/shared/src/config-loader.ts +15 -1
  110. package/packages/omo-codex/plugin/skills/browser/SKILL.md +97 -91
  111. package/packages/omo-codex/plugin/skills/browser/references/commands.md +88 -26
  112. package/packages/omo-codex/plugin/skills/browser/references/desktop.md +21 -0
  113. package/packages/omo-codex/plugin/skills/browser/references/install.md +18 -0
  114. package/packages/omo-codex/plugin/skills/browser/references/owned-engine/README.md +5 -2
  115. package/packages/omo-codex/plugin/skills/browser/references/owned-engine/frames-and-humans.md +7 -2
  116. package/packages/omo-codex/plugin/skills/browser/references/owned-engine/network.md +4 -3
  117. package/packages/omo-codex/plugin/skills/browser/references/recipes/1password.md +4 -2
  118. package/packages/omo-codex/plugin/skills/browser/runtime/omowright/index.js +7 -7
  119. package/packages/omo-codex/plugin/skills/browser/runtime/omowright/manifest.json +4 -4
  120. package/packages/omo-codex/plugin/skills/debugging/references/tools/browser-qa.md +1 -1
  121. package/packages/omo-codex/plugin/skills/programming/SKILL.md +51 -320
  122. package/packages/omo-codex/plugin/skills/programming/references/go/README.md +1 -0
  123. package/packages/omo-codex/plugin/skills/programming/references/python/README.md +21 -3
  124. package/packages/omo-codex/plugin/skills/programming/references/python/error-handling.md +14 -0
  125. package/packages/omo-codex/plugin/skills/programming/references/rust/README.md +5 -1
  126. package/packages/omo-codex/plugin/skills/programming/references/typescript/README.md +9 -3
  127. package/packages/omo-codex/plugin/skills/programming/references/typescript/error-handling.md +18 -0
  128. package/packages/omo-codex/plugin/skills/ultimate-browsing/SKILL.md +1 -1
  129. package/packages/omo-codex/plugin/skills/visual-qa/references/browser-setup.md +5 -5
  130. package/packages/omo-codex/scripts/install-dist/install-local.mjs +21189 -20653
  131. package/packages/shared-skills/skills/browser/SKILL.md +97 -91
  132. package/packages/shared-skills/skills/browser/references/commands.md +88 -26
  133. package/packages/shared-skills/skills/browser/references/desktop.md +21 -0
  134. package/packages/shared-skills/skills/browser/references/install.md +18 -0
  135. package/packages/shared-skills/skills/browser/references/owned-engine/README.md +5 -2
  136. package/packages/shared-skills/skills/browser/references/owned-engine/frames-and-humans.md +7 -2
  137. package/packages/shared-skills/skills/browser/references/owned-engine/network.md +4 -3
  138. package/packages/shared-skills/skills/browser/references/recipes/1password.md +4 -2
  139. package/packages/shared-skills/skills/browser/runtime/omowright/index.js +7 -7
  140. package/packages/shared-skills/skills/browser/runtime/omowright/manifest.json +4 -4
  141. package/packages/shared-skills/skills/debugging/references/tools/browser-qa.md +1 -1
  142. package/packages/shared-skills/skills/programming/SKILL.md +51 -320
  143. package/packages/shared-skills/skills/programming/references/go/README.md +1 -0
  144. package/packages/shared-skills/skills/programming/references/python/README.md +21 -3
  145. package/packages/shared-skills/skills/programming/references/python/error-handling.md +14 -0
  146. package/packages/shared-skills/skills/programming/references/rust/README.md +5 -1
  147. package/packages/shared-skills/skills/programming/references/typescript/README.md +9 -3
  148. package/packages/shared-skills/skills/programming/references/typescript/error-handling.md +18 -0
  149. package/packages/shared-skills/skills/ultimate-browsing/SKILL.md +1 -1
  150. package/packages/shared-skills/skills/visual-qa/references/browser-setup.md +5 -5
@@ -26,6 +26,24 @@ var realTimerProvider = {
26
26
  setTimeout: (callback, delayMs) => setTimeout(callback, delayMs),
27
27
  clearTimeout: (handle) => clearTimeout(handle)
28
28
  };
29
+ function repeatEvery(timers, intervalMs, tick) {
30
+ let handle = null;
31
+ const arm = () => {
32
+ handle = timers.setTimeout(() => {
33
+ tick();
34
+ if (handle !== null)
35
+ arm();
36
+ }, intervalMs);
37
+ if (typeof handle.unref === "function")
38
+ handle.unref();
39
+ };
40
+ arm();
41
+ return () => {
42
+ if (handle !== null)
43
+ timers.clearTimeout(handle);
44
+ handle = null;
45
+ };
46
+ }
29
47
 
30
48
  // ../lsp-core/src/lsp/constants.ts
31
49
  var DEFAULT_MAX_REFERENCES = 200;
@@ -2775,30 +2793,54 @@ function abortError2(signal) {
2775
2793
  return error;
2776
2794
  }
2777
2795
 
2778
- // ../lsp-core/src/lsp/process-signal-cleanup.ts
2779
- function installProcessSignalCleanup(cleanup) {
2780
- const signals = process.platform === "win32" ? ["SIGINT", "SIGTERM", "SIGBREAK"] : ["SIGINT", "SIGTERM"];
2781
- const handler = () => {
2782
- cleanup().catch((error) => {
2783
- reportBestEffortCleanupError("signal cleanup", error);
2784
- });
2785
- };
2786
- for (const signal of signals) {
2787
- process.on(signal, handler);
2788
- }
2789
- return () => {
2790
- for (const signal of signals) {
2791
- process.removeListener(signal, handler);
2792
- }
2793
- };
2796
+ // ../lsp-core/src/lsp/client-key.ts
2797
+ function lspClientKey(root, server) {
2798
+ return JSON.stringify([root, server.id, server.command]);
2794
2799
  }
2795
2800
 
2796
- // ../lsp-core/src/lsp/manager.ts
2797
- async function stopClientBestEffort(client) {
2798
- try {
2799
- await client.stop();
2800
- } catch (error) {
2801
- reportBestEffortCleanupError("client stop", error);
2801
+ // ../lsp-core/src/lsp/client-startup.ts
2802
+ class ClientStartups {
2803
+ constructor(now, discard) {
2804
+ this.now = now;
2805
+ this.discard = discard;
2806
+ }
2807
+ begin(request) {
2808
+ const { client } = request;
2809
+ const startedAt = this.now();
2810
+ const initPromise = (async () => {
2811
+ await client.start();
2812
+ await client.initialize();
2813
+ })();
2814
+ const managed = {
2815
+ ...request,
2816
+ refCount: 0,
2817
+ pendingWaiters: 0,
2818
+ lastUsedAt: startedAt,
2819
+ initPromise,
2820
+ isInitializing: true,
2821
+ initializingSince: startedAt
2822
+ };
2823
+ initPromise.then(() => {
2824
+ managed.isInitializing = false;
2825
+ managed.initializingSince = null;
2826
+ managed.initPromise = null;
2827
+ managed.lastUsedAt = this.now();
2828
+ }, () => this.discard(managed));
2829
+ return managed;
2830
+ }
2831
+ async wait(managed, initPromise, signal) {
2832
+ managed.pendingWaiters++;
2833
+ try {
2834
+ await awaitWithSignal(initPromise, signal);
2835
+ } catch (error) {
2836
+ this.detach(managed);
2837
+ throw error;
2838
+ }
2839
+ }
2840
+ detach(managed) {
2841
+ managed.pendingWaiters--;
2842
+ if (managed.pendingWaiters === 0 && managed.refCount === 0 && managed.heldByWaiters)
2843
+ this.discard(managed);
2802
2844
  }
2803
2845
  }
2804
2846
  function awaitWithSignal(promise, signal) {
@@ -2833,36 +2875,50 @@ function awaitWithSignal(promise, signal) {
2833
2875
  });
2834
2876
  }
2835
2877
 
2878
+ // ../lsp-core/src/lsp/process-signal-cleanup.ts
2879
+ function installProcessSignalCleanup(cleanup) {
2880
+ const signals = process.platform === "win32" ? ["SIGINT", "SIGTERM", "SIGBREAK"] : ["SIGINT", "SIGTERM"];
2881
+ const handler = () => {
2882
+ cleanup().catch((error) => {
2883
+ reportBestEffortCleanupError("signal cleanup", error);
2884
+ });
2885
+ };
2886
+ for (const signal of signals) {
2887
+ process.on(signal, handler);
2888
+ }
2889
+ return () => {
2890
+ for (const signal of signals) {
2891
+ process.removeListener(signal, handler);
2892
+ }
2893
+ };
2894
+ }
2895
+
2896
+ // ../lsp-core/src/lsp/manager.ts
2897
+ async function stopClientBestEffort(client) {
2898
+ try {
2899
+ await client.stop();
2900
+ } catch (error) {
2901
+ reportBestEffortCleanupError("client stop", error);
2902
+ }
2903
+ }
2904
+
2836
2905
  class LspManager {
2837
2906
  constructor(options = {}) {
2838
2907
  this.clients = new Map;
2839
2908
  this.pendingStops = new Map;
2840
2909
  this.respawnBudgets = new Map;
2841
- this.reaperHandle = null;
2842
2910
  this.signalDisposer = null;
2843
2911
  this.disposed = false;
2844
2912
  this.idleTimeoutMs = options.idleTimeoutMs ?? IDLE_TIMEOUT_MS;
2845
2913
  this.initTimeoutMs = options.initTimeoutMs ?? INIT_TIMEOUT_MS;
2846
2914
  this.maxResidentClients = options.maxResidentClients ?? MAX_RESIDENT_CLIENTS;
2847
- this.reaperIntervalMs = options.reaperIntervalMs ?? REAPER_INTERVAL_MS;
2848
2915
  this.clientFactory = options.clientFactory ?? ((root, server) => new LspClient(root, server));
2849
2916
  this.now = options.now ?? (() => Date.now());
2850
- this.startReaper();
2917
+ this.startups = new ClientStartups(this.now, (managed) => this.discard(managed));
2918
+ const reaperIntervalMs = options.reaperIntervalMs ?? REAPER_INTERVAL_MS;
2919
+ this.stopReaper = repeatEvery(options.timers ?? realTimerProvider, reaperIntervalMs, () => this.reapStale());
2851
2920
  this.signalDisposer = installProcessSignalCleanup(() => this.stopAll());
2852
2921
  }
2853
- startReaper() {
2854
- if (this.reaperHandle)
2855
- return;
2856
- this.reaperHandle = setInterval(() => {
2857
- this.reapStale();
2858
- }, this.reaperIntervalMs);
2859
- if (typeof this.reaperHandle.unref === "function") {
2860
- this.reaperHandle.unref();
2861
- }
2862
- }
2863
- getKey(root, serverId) {
2864
- return `${root}::${serverId}`;
2865
- }
2866
2922
  tombstoneStop(key, client) {
2867
2923
  const stop = stopClientBestEffort(client);
2868
2924
  this.pendingStops.set(key, stop);
@@ -2898,18 +2954,15 @@ class LspManager {
2898
2954
  budget.deadGenerations = 0;
2899
2955
  budget.exhaustedAt = null;
2900
2956
  }
2957
+ startupExpired(managed, t) {
2958
+ return managed.isInitializing && managed.initializingSince !== null && t - managed.initializingSince > this.initTimeoutMs;
2959
+ }
2901
2960
  reapStale() {
2902
2961
  const t = this.now();
2903
- for (const [key, managed] of this.clients) {
2904
- if (managed.isInitializing && managed.initializingSince !== null && t - managed.initializingSince > this.initTimeoutMs) {
2905
- this.clients.delete(key);
2906
- this.tombstoneStop(key, managed.client);
2907
- continue;
2908
- }
2909
- if (!managed.isInitializing && managed.refCount === 0 && managed.pendingWaiters === 0 && t - managed.lastUsedAt > this.idleTimeoutMs) {
2910
- this.clients.delete(key);
2911
- this.tombstoneStop(key, managed.client);
2912
- }
2962
+ for (const managed of [...this.clients.values()]) {
2963
+ const idle = !managed.isInitializing && managed.refCount === 0 && managed.pendingWaiters === 0 && t - managed.lastUsedAt > this.idleTimeoutMs;
2964
+ if (idle || this.startupExpired(managed, t))
2965
+ this.discard(managed);
2913
2966
  }
2914
2967
  }
2915
2968
  evictForAdmission() {
@@ -2917,152 +2970,96 @@ class LspManager {
2917
2970
  const victim = this.leastRecentlyUsedIdleClient();
2918
2971
  if (!victim)
2919
2972
  return;
2920
- this.clients.delete(victim.key);
2921
- this.tombstoneStop(victim.key, victim.managed.client);
2973
+ this.discard(victim);
2922
2974
  }
2923
2975
  }
2924
2976
  leastRecentlyUsedIdleClient() {
2925
2977
  let candidate = null;
2926
- for (const [key, managed] of this.clients) {
2978
+ for (const managed of this.clients.values()) {
2927
2979
  if (managed.refCount > 0 || managed.pendingWaiters > 0 || managed.isInitializing)
2928
2980
  continue;
2929
- if (candidate === null || managed.lastUsedAt < candidate.managed.lastUsedAt) {
2930
- candidate = { key, managed };
2931
- }
2981
+ if (candidate === null || managed.lastUsedAt < candidate.lastUsedAt)
2982
+ candidate = managed;
2932
2983
  }
2933
2984
  return candidate;
2934
2985
  }
2935
- async tryDeleteIfOrphaned(key, managed) {
2936
- if (managed.refCount === 0 && managed.pendingWaiters === 0 && !managed.isInitializing && this.clients.get(key) === managed) {
2937
- this.clients.delete(key);
2938
- await this.tombstoneStop(key, managed.client);
2939
- }
2986
+ discard(managed) {
2987
+ if (this.clients.get(managed.key) !== managed)
2988
+ return;
2989
+ this.clients.delete(managed.key);
2990
+ this.tombstoneStop(managed.key, managed.client);
2940
2991
  }
2941
2992
  async getClient(root, server, signal) {
2942
- if (this.disposed) {
2943
- throw new Error("LspManager has been disposed");
2944
- }
2945
- signal?.throwIfAborted();
2946
- const key = this.getKey(root, server.id);
2993
+ const key = lspClientKey(root, server);
2947
2994
  for (;; ) {
2948
- const pendingStop = this.pendingStops.get(key);
2949
- if (pendingStop === undefined)
2950
- break;
2951
- await awaitWithSignal(pendingStop, signal);
2995
+ if (this.disposed) {
2996
+ throw new Error("LspManager has been disposed");
2997
+ }
2952
2998
  signal?.throwIfAborted();
2953
- }
2954
- if (this.disposed) {
2955
- throw new Error("LspManager has been disposed");
2956
- }
2957
- let managed = this.clients.get(key);
2958
- if (managed) {
2959
- const t = this.now();
2960
- if (managed.isInitializing && managed.initializingSince !== null && t - managed.initializingSince > this.initTimeoutMs) {
2961
- this.clients.delete(key);
2962
- await this.tombstoneStop(key, managed.client);
2963
- managed = undefined;
2999
+ const pendingStop = this.pendingStops.get(key);
3000
+ if (pendingStop !== undefined) {
3001
+ await awaitWithSignal(pendingStop, signal);
3002
+ continue;
2964
3003
  }
2965
- }
2966
- if (managed) {
2967
- if (managed.initPromise) {
2968
- managed.pendingWaiters++;
2969
- try {
2970
- await awaitWithSignal(managed.initPromise, signal);
2971
- } catch (err) {
2972
- managed.pendingWaiters--;
2973
- await this.tryDeleteIfOrphaned(key, managed);
2974
- throw err;
3004
+ let managed = this.clients.get(key);
3005
+ if (managed !== undefined && this.startupExpired(managed, this.now())) {
3006
+ this.discard(managed);
3007
+ continue;
3008
+ }
3009
+ if (managed === undefined) {
3010
+ this.evictForAdmission();
3011
+ this.ensureRespawnAllowed(key, root, server.id);
3012
+ managed = this.startClient(key, root, server, true);
3013
+ }
3014
+ const { initPromise } = managed;
3015
+ if (initPromise !== null) {
3016
+ await this.startups.wait(managed, initPromise, signal);
3017
+ if (signal?.aborted) {
3018
+ this.startups.detach(managed);
3019
+ signal.throwIfAborted();
2975
3020
  }
2976
3021
  managed.pendingWaiters--;
2977
3022
  }
2978
- if (signal?.aborted) {
2979
- await this.tryDeleteIfOrphaned(key, managed);
2980
- signal.throwIfAborted();
2981
- }
3023
+ if (this.clients.get(key) !== managed)
3024
+ continue;
2982
3025
  if (!managed.client.isAlive()) {
2983
3026
  this.recordDeadGeneration(key);
2984
- if (this.clients.get(key) === managed) {
2985
- this.clients.delete(key);
2986
- }
2987
- await this.tombstoneStop(key, managed.client);
2988
- return this.getClient(root, server, signal);
3027
+ this.discard(managed);
3028
+ continue;
2989
3029
  }
2990
3030
  this.markHealthyGeneration(key);
2991
3031
  managed.refCount++;
2992
3032
  managed.lastUsedAt = this.now();
2993
3033
  return managed.client;
2994
3034
  }
2995
- this.evictForAdmission();
2996
- this.ensureRespawnAllowed(key, root, server.id);
3035
+ }
3036
+ startClient(key, root, server, heldByWaiters) {
2997
3037
  const client = this.clientFactory(root, server);
2998
- const initStartedAt = this.now();
2999
- const initPromise = (async () => {
3000
- await client.start();
3001
- await client.initialize();
3002
- })();
3003
- const newManaged = {
3004
- client,
3005
- refCount: 0,
3006
- pendingWaiters: 1,
3007
- lastUsedAt: initStartedAt,
3008
- initPromise,
3009
- isInitializing: true,
3010
- initializingSince: initStartedAt
3011
- };
3012
- this.clients.set(key, newManaged);
3013
- try {
3014
- await awaitWithSignal(initPromise, signal);
3015
- } catch (err) {
3016
- newManaged.pendingWaiters--;
3017
- if (this.clients.get(key) === newManaged) {
3018
- this.clients.delete(key);
3019
- }
3020
- await this.tombstoneStop(key, client);
3021
- throw err;
3022
- }
3023
- newManaged.pendingWaiters--;
3024
- newManaged.isInitializing = false;
3025
- newManaged.initializingSince = null;
3026
- newManaged.initPromise = null;
3027
- if (signal?.aborted) {
3028
- await this.tryDeleteIfOrphaned(key, newManaged);
3029
- signal.throwIfAborted();
3030
- }
3031
- if (!client.isAlive()) {
3032
- this.recordDeadGeneration(key);
3033
- if (this.clients.get(key) === newManaged) {
3034
- this.clients.delete(key);
3035
- }
3036
- await this.tombstoneStop(key, client);
3037
- return this.getClient(root, server, signal);
3038
- }
3039
- this.markHealthyGeneration(key);
3040
- newManaged.refCount++;
3041
- newManaged.lastUsedAt = this.now();
3042
- return client;
3043
- }
3044
- releaseClient(root, serverId) {
3045
- const key = this.getKey(root, serverId);
3046
- const managed = this.clients.get(key);
3038
+ const managed = this.startups.begin({ key, root, serverId: server.id, client, heldByWaiters });
3039
+ this.clients.set(key, managed);
3040
+ return managed;
3041
+ }
3042
+ releaseClient(root, server, client) {
3043
+ const managed = this.clients.get(lspClientKey(root, server));
3044
+ if (client !== undefined && managed?.client !== client)
3045
+ return;
3047
3046
  if (managed && managed.refCount > 0) {
3048
3047
  managed.refCount--;
3049
3048
  managed.lastUsedAt = this.now();
3050
3049
  }
3051
3050
  }
3052
- invalidateClient(root, serverId, client) {
3053
- const key = this.getKey(root, serverId);
3054
- const managed = this.clients.get(key);
3051
+ invalidateClient(root, server, client) {
3052
+ const managed = this.clients.get(lspClientKey(root, server));
3055
3053
  if (!managed)
3056
3054
  return;
3057
3055
  if (client && managed.client !== client)
3058
3056
  return;
3059
- this.clients.delete(key);
3060
- this.tombstoneStop(key, managed.client);
3057
+ this.discard(managed);
3061
3058
  }
3062
3059
  warmupClient(root, server) {
3063
3060
  if (this.disposed)
3064
3061
  return;
3065
- const key = this.getKey(root, server.id);
3062
+ const key = lspClientKey(root, server);
3066
3063
  if (this.clients.has(key) || this.pendingStops.has(key))
3067
3064
  return;
3068
3065
  this.evictForAdmission();
@@ -3071,45 +3068,18 @@ class LspManager {
3071
3068
  } catch {
3072
3069
  return;
3073
3070
  }
3074
- const client = this.clientFactory(root, server);
3075
- const initStartedAt = this.now();
3076
- const initPromise = (async () => {
3077
- await client.start();
3078
- await client.initialize();
3079
- })();
3080
- const managed = {
3081
- client,
3082
- refCount: 0,
3083
- pendingWaiters: 0,
3084
- lastUsedAt: initStartedAt,
3085
- initPromise,
3086
- isInitializing: true,
3087
- initializingSince: initStartedAt
3088
- };
3089
- this.clients.set(key, managed);
3090
- initPromise.then(() => {
3091
- managed.isInitializing = false;
3092
- managed.initializingSince = null;
3093
- managed.initPromise = null;
3094
- managed.lastUsedAt = this.now();
3095
- }, () => {
3096
- if (this.clients.get(key) === managed) {
3097
- this.clients.delete(key);
3098
- }
3099
- this.tombstoneStop(key, client);
3100
- });
3071
+ this.startClient(key, root, server, false);
3101
3072
  }
3102
- isServerInitializing(root, serverId) {
3103
- const managed = this.clients.get(this.getKey(root, serverId));
3073
+ isServerInitializing(root, server) {
3074
+ const managed = this.clients.get(lspClientKey(root, server));
3104
3075
  return managed?.isInitializing ?? false;
3105
3076
  }
3106
3077
  getSnapshot() {
3107
3078
  const snapshots = [];
3108
- for (const [key, managed] of this.clients) {
3109
- const [root, serverId] = key.split("::");
3079
+ for (const managed of this.clients.values()) {
3110
3080
  snapshots.push({
3111
- root,
3112
- serverId,
3081
+ root: managed.root,
3082
+ serverId: managed.serverId,
3113
3083
  refCount: managed.refCount,
3114
3084
  pendingWaiters: managed.pendingWaiters,
3115
3085
  lastUsedAt: managed.lastUsedAt,
@@ -3120,18 +3090,15 @@ class LspManager {
3120
3090
  }
3121
3091
  return snapshots;
3122
3092
  }
3123
- hasClient(root, serverId) {
3124
- return this.clients.has(this.getKey(root, serverId));
3093
+ hasClient(root, server) {
3094
+ return this.clients.has(lspClientKey(root, server));
3125
3095
  }
3126
3096
  clientCount() {
3127
3097
  return this.clients.size;
3128
3098
  }
3129
3099
  async stopAll() {
3130
3100
  this.disposed = true;
3131
- if (this.reaperHandle) {
3132
- clearInterval(this.reaperHandle);
3133
- this.reaperHandle = null;
3134
- }
3101
+ this.stopReaper();
3135
3102
  if (this.signalDisposer) {
3136
3103
  this.signalDisposer();
3137
3104
  this.signalDisposer = null;
@@ -3474,8 +3441,8 @@ function createIdleTimer(idleTimeoutMs, log, onTimeout) {
3474
3441
  };
3475
3442
  }
3476
3443
  // ../lsp-core/src/lsp/client-wrapper.ts
3477
- import { existsSync as existsSync10, realpathSync as realpathSync6, statSync as statSync3 } from "node:fs";
3478
- import { basename as basename3, dirname as dirname8, join as join5, resolve as resolve8 } from "node:path";
3444
+ import { existsSync as existsSync11, realpathSync as realpathSync7, statSync as statSync4 } from "node:fs";
3445
+ import { basename as basename3, dirname as dirname9, join as join6, resolve as resolve9 } from "node:path";
3479
3446
 
3480
3447
  // ../lsp-core/src/request-context.ts
3481
3448
  import { AsyncLocalStorage } from "node:async_hooks";
@@ -3993,6 +3960,7 @@ function getMergedServers() {
3993
3960
  extensions: config.extensions,
3994
3961
  priority: -100,
3995
3962
  source: "builtin",
3963
+ inheritsBuiltinCommand: true,
3996
3964
  ...config.initialization === undefined ? {} : { initialization: config.initialization }
3997
3965
  });
3998
3966
  }
@@ -4018,8 +3986,11 @@ function createServerFromEntry(id, entry, source) {
4018
3986
  command: builtin.command,
4019
3987
  extensions: entry.extensions ?? builtin.extensions,
4020
3988
  priority: entry.priority ?? 0,
4021
- source
3989
+ source,
3990
+ inheritsBuiltinCommand: true
4022
3991
  });
3992
+ if (entry.initialization !== undefined)
3993
+ server.configuredInitialization = entry.initialization;
4023
3994
  const initialization = mergeInitialization(builtin.initialization, entry.initialization);
4024
3995
  if (initialization !== undefined) {
4025
3996
  server.initialization = initialization;
@@ -4032,7 +4003,8 @@ function createServerFromEntry(id, entry, source) {
4032
4003
  command: entry.command,
4033
4004
  extensions: entry.extensions,
4034
4005
  priority: entry.priority ?? 0,
4035
- source
4006
+ source,
4007
+ inheritsBuiltinCommand: false
4036
4008
  });
4037
4009
  applyOptionalServerFields(server, entry);
4038
4010
  return server;
@@ -4044,7 +4016,8 @@ function createServerFromEntry(id, entry, source) {
4044
4016
  command: entry.command ?? builtin.command,
4045
4017
  extensions: entry.extensions ?? builtin.extensions,
4046
4018
  priority: entry.priority ?? 0,
4047
- source
4019
+ source,
4020
+ inheritsBuiltinCommand: entry.command === undefined
4048
4021
  });
4049
4022
  applyOptionalServerFields(server, entry);
4050
4023
  const builtinInitialization = entry.command === undefined ? builtin.initialization : undefined;
@@ -4067,7 +4040,8 @@ function createServer(input) {
4067
4040
  command: input.command,
4068
4041
  extensions: input.extensions,
4069
4042
  priority: input.priority,
4070
- source: input.source
4043
+ source: input.source,
4044
+ inheritsBuiltinCommand: input.inheritsBuiltinCommand
4071
4045
  };
4072
4046
  if (input.env !== undefined) {
4073
4047
  server.env = input.env;
@@ -4083,6 +4057,7 @@ function applyOptionalServerFields(server, entry) {
4083
4057
  }
4084
4058
  if (entry.initialization !== undefined) {
4085
4059
  server.initialization = entry.initialization;
4060
+ server.configuredInitialization = entry.initialization;
4086
4061
  }
4087
4062
  }
4088
4063
  function isConfigJson(value) {
@@ -4174,14 +4149,24 @@ function readHead(path) {
4174
4149
  }
4175
4150
  }
4176
4151
 
4152
+ // ../lsp-core/src/lsp/native-typescript.ts
4153
+ import { existsSync as existsSync10, realpathSync as realpathSync6, statSync as statSync3 } from "node:fs";
4154
+ import { dirname as dirname8, join as join5, resolve as resolve8 } from "node:path";
4155
+
4177
4156
  // ../lsp-core/src/lsp/server-installation.ts
4178
4157
  import { existsSync as existsSync9 } from "node:fs";
4179
4158
  import { delimiter as delimiter3, dirname as dirname7, isAbsolute as isAbsolute3, join as join4, resolve as resolve7 } from "node:path";
4159
+ var NODE_PROJECT_MARKERS = [
4160
+ "package.json",
4161
+ "bun.lock",
4162
+ "bun.lockb",
4163
+ "package-lock.json",
4164
+ "yarn.lock",
4165
+ "pnpm-lock.yaml"
4166
+ ];
4167
+ var NODE_LOCAL_BIN_DIR = join4("node_modules", ".bin");
4180
4168
  var LOCAL_BIN_RULES = [
4181
- {
4182
- markers: ["package.json", "bun.lock", "bun.lockb", "package-lock.json", "yarn.lock", "pnpm-lock.yaml"],
4183
- binDirs: [join4("node_modules", ".bin")]
4184
- },
4169
+ { markers: NODE_PROJECT_MARKERS, binDirs: [NODE_LOCAL_BIN_DIR] },
4185
4170
  {
4186
4171
  markers: [
4187
4172
  "pyproject.toml",
@@ -4309,6 +4294,57 @@ function isServerInstalled(command, workingDirectory, options = {}) {
4309
4294
  return resolveServerBinary(command, workingDirectory, options) !== null;
4310
4295
  }
4311
4296
 
4297
+ // ../lsp-core/src/lsp/native-typescript.ts
4298
+ function nativeTypescriptSearchDirectory(targetPath, workingDirectory) {
4299
+ try {
4300
+ const session = realpathSync6(workingDirectory);
4301
+ if (targetPath === undefined)
4302
+ return session;
4303
+ const target = canonicalizeExistingOrNearestAncestor(resolve8(workingDirectory, targetPath));
4304
+ if (!isPathInside(session, target))
4305
+ return session;
4306
+ return statSync3(target, { throwIfNoEntry: false })?.isDirectory() === true ? target : dirname8(target);
4307
+ } catch {
4308
+ return workingDirectory;
4309
+ }
4310
+ }
4311
+ function nativeTypescriptCommand(server, searchDirectory) {
4312
+ if (server.id !== "typescript" || !server.inheritsBuiltinCommand)
4313
+ return null;
4314
+ const found = findProjectTsc(searchDirectory);
4315
+ if (found === null)
4316
+ return null;
4317
+ const speaksLsp = !existsSync10(join5(found.packageDir, "lib", "tsserver.js"));
4318
+ return speaksLsp ? [found.tsc, "--lsp", "--stdio"] : null;
4319
+ }
4320
+ function findProjectTsc(searchDirectory) {
4321
+ const suffixes = executableSuffixes(process.platform, undefined);
4322
+ let current = searchDirectory;
4323
+ for (;; ) {
4324
+ if (NODE_PROJECT_MARKERS.some((marker) => probe(join5(current, marker)))) {
4325
+ const binDir = join5(current, NODE_LOCAL_BIN_DIR);
4326
+ const tsc = probeWithSuffixes(binDir, "tsc", suffixes);
4327
+ const packageDir = join5(binDir, "..", "typescript");
4328
+ if (tsc !== null && isRealDirectory(binDir) && existsSync10(join5(packageDir, "package.json"))) {
4329
+ return { tsc, packageDir };
4330
+ }
4331
+ }
4332
+ if (probe(join5(current, ".git")))
4333
+ return null;
4334
+ const parent = dirname8(current);
4335
+ if (parent === current)
4336
+ return null;
4337
+ current = parent;
4338
+ }
4339
+ }
4340
+ function isRealDirectory(directory) {
4341
+ try {
4342
+ return realpathSync6(directory) === directory;
4343
+ } catch {
4344
+ return false;
4345
+ }
4346
+ }
4347
+
4312
4348
  // ../lsp-core/src/lsp/server-resolution.ts
4313
4349
  function withResolvedCommand(command, binaryPath) {
4314
4350
  return [binaryPath, ...command.slice(1)];
@@ -4317,12 +4353,27 @@ function usesBuiltinCommand(id, command) {
4317
4353
  const builtin = BUILTIN_SERVERS[id]?.command;
4318
4354
  return builtin !== undefined && builtin.length === command.length && builtin.every((part, index) => part === command[index]);
4319
4355
  }
4320
- function findServerForExtension(ext) {
4356
+ function findServerForExtension(ext, targetPath) {
4321
4357
  const servers = getMergedServers();
4322
4358
  const workingDirectory = contextCwd();
4359
+ const searchDirectory = nativeTypescriptSearchDirectory(targetPath, workingDirectory);
4323
4360
  for (const server of servers) {
4324
4361
  if (!server.extensions.includes(ext))
4325
4362
  continue;
4363
+ const nativeTypescript = nativeTypescriptCommand(server, searchDirectory);
4364
+ if (nativeTypescript !== null) {
4365
+ return {
4366
+ status: "found",
4367
+ server: {
4368
+ id: server.id,
4369
+ command: withHostJsRuntime(server.id, nativeTypescript),
4370
+ extensions: server.extensions,
4371
+ priority: server.priority,
4372
+ ...server.env === undefined ? {} : { env: server.env },
4373
+ ...server.configuredInitialization === undefined ? {} : { initialization: server.configuredInitialization }
4374
+ }
4375
+ };
4376
+ }
4326
4377
  const binaryPath = resolveServerBinary(server.command, workingDirectory);
4327
4378
  if (binaryPath !== null) {
4328
4379
  const resolvedServer = {
@@ -4375,6 +4426,7 @@ function getAllServers() {
4375
4426
  const servers = getMergedServers();
4376
4427
  const disabled = getDisabledServerIds();
4377
4428
  const workingDirectory = contextCwd();
4429
+ const nativeSearchDirectory = nativeTypescriptSearchDirectory(undefined, workingDirectory);
4378
4430
  const result = [];
4379
4431
  const seen = new Set;
4380
4432
  for (const server of servers) {
@@ -4382,7 +4434,7 @@ function getAllServers() {
4382
4434
  continue;
4383
4435
  result.push({
4384
4436
  id: server.id,
4385
- installed: isServerInstalled(server.command, workingDirectory),
4437
+ installed: isServerInstalled(server.command, workingDirectory) || nativeTypescriptCommand(server, nativeSearchDirectory) !== null,
4386
4438
  extensions: server.extensions,
4387
4439
  disabled: false,
4388
4440
  source: server.source,
@@ -4409,7 +4461,7 @@ function getAllServers() {
4409
4461
  // ../lsp-core/src/lsp/client-wrapper.ts
4410
4462
  function isDirectoryPath(filePath) {
4411
4463
  try {
4412
- return statSync3(filePath).isDirectory();
4464
+ return statSync4(filePath).isDirectory();
4413
4465
  } catch {
4414
4466
  return false;
4415
4467
  }
@@ -4419,7 +4471,7 @@ function findWorkspaceRoot(filePath) {
4419
4471
  const abs = resolveReadablePathInsideContext(filePath);
4420
4472
  let dir = abs;
4421
4473
  if (!isDirectoryPath(dir)) {
4422
- dir = dirname8(dir);
4474
+ dir = dirname9(dir);
4423
4475
  }
4424
4476
  if (!isPathInside(cwd, abs))
4425
4477
  return findWorkspaceRootOutsideContext(dir);
@@ -4428,7 +4480,7 @@ function findWorkspaceRoot(filePath) {
4428
4480
  while (isPathInside(cwd, dir)) {
4429
4481
  const canonicalDir = existingDirectoryInsideContext(dir, cwd);
4430
4482
  if (canonicalDir !== undefined) {
4431
- if (existsSync10(join5(dir, GIT_WORKSPACE_MARKER))) {
4483
+ if (existsSync11(join6(dir, GIT_WORKSPACE_MARKER))) {
4432
4484
  return canonicalDir;
4433
4485
  }
4434
4486
  if (nearestPackageRoot === undefined && hasProjectWorkspaceMarker(dir)) {
@@ -4437,16 +4489,16 @@ function findWorkspaceRoot(filePath) {
4437
4489
  }
4438
4490
  if (dir === cwd)
4439
4491
  break;
4440
- dir = dirname8(dir);
4492
+ dir = dirname9(dir);
4441
4493
  }
4442
4494
  return nearestPackageRoot ?? fallbackRoot;
4443
4495
  }
4444
4496
  function hasProjectWorkspaceMarker(directory) {
4445
- return PROJECT_WORKSPACE_MARKERS.some((marker) => existsSync10(join5(directory, marker)));
4497
+ return PROJECT_WORKSPACE_MARKERS.some((marker) => existsSync11(join6(directory, marker)));
4446
4498
  }
4447
4499
  function resolveReadablePathInsideContext(filePath) {
4448
4500
  const cwd = contextCwd();
4449
- const abs = resolve8(cwd, filePath);
4501
+ const abs = resolve9(cwd, filePath);
4450
4502
  if (isPathInside(cwd, abs))
4451
4503
  return abs;
4452
4504
  const rebased = rebaseThroughCanonicalAncestor(abs, cwd);
@@ -4467,12 +4519,12 @@ function rebaseThroughCanonicalAncestor(path, cwd) {
4467
4519
  let current = path;
4468
4520
  const suffix = [];
4469
4521
  while (true) {
4470
- if (existsSync10(current)) {
4471
- const canonical = realpathSync6(current);
4522
+ if (existsSync11(current)) {
4523
+ const canonical = realpathSync7(current);
4472
4524
  if (isPathInside(cwd, canonical))
4473
- return suffix.length === 0 ? canonical : join5(canonical, ...suffix);
4525
+ return suffix.length === 0 ? canonical : join6(canonical, ...suffix);
4474
4526
  }
4475
- const parent = dirname8(current);
4527
+ const parent = dirname9(current);
4476
4528
  if (parent === current)
4477
4529
  return;
4478
4530
  suffix.unshift(basename3(current));
@@ -4480,10 +4532,10 @@ function rebaseThroughCanonicalAncestor(path, cwd) {
4480
4532
  }
4481
4533
  }
4482
4534
  function existingDirectoryInsideContext(directory, cwd) {
4483
- if (!existsSync10(directory))
4535
+ if (!existsSync11(directory))
4484
4536
  return;
4485
- const canonical = realpathSync6(directory);
4486
- if (!statSync3(canonical).isDirectory())
4537
+ const canonical = realpathSync7(directory);
4538
+ if (!statSync4(canonical).isDirectory())
4487
4539
  return;
4488
4540
  return isPathInside(cwd, canonical) ? canonical : undefined;
4489
4541
  }
@@ -4495,7 +4547,7 @@ function nearestExistingDirectoryInsideContext(directory, cwd) {
4495
4547
  return canonical;
4496
4548
  if (current === cwd)
4497
4549
  return;
4498
- current = dirname8(current);
4550
+ current = dirname9(current);
4499
4551
  }
4500
4552
  return;
4501
4553
  }
@@ -4595,7 +4647,7 @@ async function withLspClient(filePath, fn, toolName, options = {}) {
4595
4647
  throw new LspInvalidPathError("Directory paths are not supported by this LSP tool. " + "Use lsp.diagnostics with a directory path for directory diagnostics.");
4596
4648
  }
4597
4649
  const ext = effectiveExtension(absPath);
4598
- const result = findServerForExtension(ext);
4650
+ const result = findServerForExtension(ext, absPath);
4599
4651
  if (result.status !== "found") {
4600
4652
  throw new LspServerLookupError(formatServerLookupError(result), result);
4601
4653
  }
@@ -4608,25 +4660,153 @@ async function withLspClient(filePath, fn, toolName, options = {}) {
4608
4660
  return await fn(client, root, absPath);
4609
4661
  } catch (err) {
4610
4662
  if (allowRetry && READ_ONLY_TOOLS.has(toolName) && isLspDeadConnectionError(err)) {
4611
- manager.invalidateClient(root, server.id, client);
4663
+ manager.invalidateClient(root, server, client);
4612
4664
  return acquireAndCall(false);
4613
4665
  }
4614
4666
  if (err instanceof LspRequestTimeoutError) {
4615
- if (manager.isServerInitializing(root, server.id)) {
4667
+ if (manager.isServerInitializing(root, server)) {
4616
4668
  throw new LspServerInitializingError(err);
4617
4669
  }
4618
4670
  }
4619
4671
  throw err;
4620
4672
  } finally {
4621
- manager.releaseClient(root, server.id);
4673
+ manager.releaseClient(root, server, client);
4622
4674
  }
4623
4675
  };
4624
4676
  return acquireAndCall(true);
4625
4677
  }
4626
4678
 
4627
4679
  // ../lsp-core/src/lsp/directory-diagnostics.ts
4628
- import { existsSync as existsSync11, lstatSync as lstatSync4, readdirSync as readdirSync3 } from "node:fs";
4629
- import { join as join6, resolve as resolve9 } from "node:path";
4680
+ import { existsSync as existsSync12, lstatSync as lstatSync4, readdirSync as readdirSync3 } from "node:fs";
4681
+ import { join as join7, resolve as resolve10 } from "node:path";
4682
+
4683
+ // ../lsp-core/src/lsp/directory-group-scan.ts
4684
+ async function scanServedGroups(options) {
4685
+ const { groups, signal } = options;
4686
+ const limit = Math.max(1, options.maxConcurrency);
4687
+ const fileSlots = createSlots(limit);
4688
+ let nextGroup = 0;
4689
+ let startedGroups = 0;
4690
+ let firstError;
4691
+ const runners = Array.from({ length: Math.min(limit, groups.length) }, async () => {
4692
+ for (;; ) {
4693
+ if (signal?.aborted)
4694
+ return;
4695
+ const group = groups[nextGroup];
4696
+ nextGroup += 1;
4697
+ if (group === undefined)
4698
+ return;
4699
+ let client;
4700
+ try {
4701
+ client = await acquireWithinInitTimeout(options, group);
4702
+ } catch (error) {
4703
+ if (signal?.aborted)
4704
+ return;
4705
+ firstError ??= error;
4706
+ options.onGroupUnavailable(group, error instanceof Error ? error.message : String(error));
4707
+ continue;
4708
+ }
4709
+ startedGroups += 1;
4710
+ try {
4711
+ await Promise.all(group.files.map(async (file) => {
4712
+ const release = await fileSlots.acquire();
4713
+ try {
4714
+ if (!signal?.aborted)
4715
+ await options.checkFile(client, file);
4716
+ } finally {
4717
+ release();
4718
+ }
4719
+ }));
4720
+ } finally {
4721
+ options.manager.releaseClient(group.root, group.server, client);
4722
+ }
4723
+ }
4724
+ });
4725
+ await Promise.all(runners);
4726
+ signal?.throwIfAborted();
4727
+ if (startedGroups === 0 && firstError !== undefined)
4728
+ throw firstError;
4729
+ }
4730
+ async function acquireWithinInitTimeout(options, group) {
4731
+ const { signal } = options;
4732
+ const timers = options.timers ?? realTimerProvider;
4733
+ const controller = new AbortController;
4734
+ const forwardAbort = () => controller.abort(signal?.reason);
4735
+ signal?.addEventListener("abort", forwardAbort, { once: true });
4736
+ if (signal?.aborted)
4737
+ forwardAbort();
4738
+ let timedOut = false;
4739
+ const timer = timers.setTimeout(() => {
4740
+ timedOut = true;
4741
+ controller.abort();
4742
+ }, INIT_TIMEOUT_MS);
4743
+ try {
4744
+ return await options.manager.getClient(group.root, group.server, controller.signal);
4745
+ } catch (error) {
4746
+ if (timedOut && signal?.aborted !== true) {
4747
+ throw new Error(`${group.server.id} did not start within ${INIT_TIMEOUT_MS}ms`);
4748
+ }
4749
+ throw error;
4750
+ } finally {
4751
+ timers.clearTimeout(timer);
4752
+ signal?.removeEventListener("abort", forwardAbort);
4753
+ }
4754
+ }
4755
+ function createSlots(limit) {
4756
+ let free = limit;
4757
+ const waiting = [];
4758
+ const release = () => {
4759
+ const next = waiting.shift();
4760
+ if (next === undefined)
4761
+ free += 1;
4762
+ else
4763
+ next();
4764
+ };
4765
+ return {
4766
+ acquire() {
4767
+ if (free > 0) {
4768
+ free -= 1;
4769
+ return Promise.resolve(release);
4770
+ }
4771
+ return new Promise((resolve) => waiting.push(() => resolve(release)));
4772
+ }
4773
+ };
4774
+ }
4775
+
4776
+ // ../lsp-core/src/lsp/directory-server-groups.ts
4777
+ import { dirname as dirname10 } from "node:path";
4778
+ function groupFilesByClient(files, extension, fixed = {}) {
4779
+ const byDirectory = new Map;
4780
+ const served = new Map;
4781
+ const unserved = new Map;
4782
+ for (const file of files) {
4783
+ const directory = dirname10(file);
4784
+ let resolution = byDirectory.get(directory);
4785
+ if (resolution === undefined) {
4786
+ resolution = resolveDirectory(directory, extension, fixed);
4787
+ byDirectory.set(directory, resolution);
4788
+ }
4789
+ if (resolution.kind === "served") {
4790
+ const group = served.get(resolution.key) ?? { root: resolution.root, server: resolution.server, files: [] };
4791
+ group.files.push(file);
4792
+ served.set(resolution.key, group);
4793
+ } else {
4794
+ const group = unserved.get(resolution.key) ?? { lookup: resolution.lookup, files: [] };
4795
+ group.files.push(file);
4796
+ unserved.set(resolution.key, group);
4797
+ }
4798
+ }
4799
+ return { served: [...served.values()], unserved: [...unserved.values()] };
4800
+ }
4801
+ function resolveDirectory(directory, extension, fixed) {
4802
+ const lookup = fixed.server === undefined ? findServerForExtension(extension, directory) : { status: "found", server: fixed.server };
4803
+ if (lookup.status !== "found") {
4804
+ const serverId = lookup.status === "not_installed" ? lookup.server.id : "";
4805
+ return { kind: "unserved", key: JSON.stringify([lookup.status, serverId]), lookup };
4806
+ }
4807
+ const root = fixed.workspaceRoot ?? findWorkspaceRoot(directory);
4808
+ return { kind: "served", key: lspClientKey(root, lookup.server), root, server: lookup.server };
4809
+ }
4630
4810
 
4631
4811
  // ../lsp-core/src/lsp/formatters.ts
4632
4812
  import { fileURLToPath as fileURLToPath2 } from "node:url";
@@ -4756,7 +4936,7 @@ function collectFilesWithExtension(dir, extension, maxFiles) {
4756
4936
  for (const entry of entries) {
4757
4937
  if (files.length >= maxFiles)
4758
4938
  return;
4759
- const fullPath = join6(currentDir, entry);
4939
+ const fullPath = join7(currentDir, entry);
4760
4940
  let stat;
4761
4941
  try {
4762
4942
  stat = lstatSync4(fullPath);
@@ -4781,15 +4961,10 @@ async function aggregateDiagnosticsForDirectory(directory, extension, severity,
4781
4961
  if (!extension.startsWith(".")) {
4782
4962
  throw new LspInvalidPathError(`Extension must start with a dot (e.g., ".ts", not "${extension}"). Use ".${extension}" instead.`);
4783
4963
  }
4784
- const absDir = resolve9(options.workspaceRoot ?? contextCwd(), directory);
4785
- if (!existsSync11(absDir)) {
4964
+ const absDir = resolve10(options.workspaceRoot ?? contextCwd(), directory);
4965
+ if (!existsSync12(absDir)) {
4786
4966
  throw new LspInvalidPathError(`Directory does not exist: ${absDir}`);
4787
4967
  }
4788
- const serverResult = options.server === undefined ? findServerForExtension(extension) : { status: "found", server: options.server };
4789
- if (serverResult.status !== "found") {
4790
- throw new LspServerLookupError(formatServerLookupError(serverResult));
4791
- }
4792
- const server = serverResult.server;
4793
4968
  const allFiles = (options.listFiles ?? collectFilesWithExtension)(absDir, extension, maxFiles + 1);
4794
4969
  const wasCapped = allFiles.length > maxFiles;
4795
4970
  const filesToProcess = allFiles.slice(0, maxFiles);
@@ -4803,42 +4978,43 @@ async function aggregateDiagnosticsForDirectory(directory, extension, severity,
4803
4978
  `);
4804
4979
  return { output, totalDiagnostics: 0, fileFailures: [] };
4805
4980
  }
4806
- const root = options.workspaceRoot ?? findWorkspaceRoot(absDir);
4981
+ const groups = groupFilesByClient(filesToProcess, extension, {
4982
+ ...options.server === undefined ? {} : { server: options.server },
4983
+ ...options.workspaceRoot === undefined ? {} : { workspaceRoot: options.workspaceRoot }
4984
+ });
4985
+ const firstUnserved = groups.unserved[0];
4986
+ if (groups.served.length === 0 && firstUnserved !== undefined) {
4987
+ throw new LspServerLookupError(formatServerLookupError(firstUnserved.lookup));
4988
+ }
4807
4989
  const manager = options.manager ?? getLspManager();
4808
4990
  const allDiagnostics = [];
4809
4991
  const fileErrors = [];
4810
4992
  const maxConcurrency = Math.max(1, options.maxConcurrency ?? DIRECTORY_DIAGNOSTICS_MAX_CONCURRENCY);
4993
+ for (const group of groups.unserved) {
4994
+ const error = formatServerLookupError(group.lookup).split(`
4995
+ `)[0] ?? "No LSP server";
4996
+ fileErrors.push(...group.files.map((file) => ({ file, error })));
4997
+ }
4811
4998
  options.signal?.throwIfAborted();
4812
- const client = await manager.getClient(root, server, options.signal);
4813
- try {
4814
- let nextIndex = 0;
4815
- const workers = Array.from({ length: Math.min(maxConcurrency, filesToProcess.length) }, async () => {
4816
- for (;; ) {
4817
- if (options.signal?.aborted)
4818
- return;
4819
- const file = filesToProcess[nextIndex];
4820
- nextIndex += 1;
4821
- if (file === undefined)
4822
- return;
4823
- try {
4824
- const result = await client.diagnostics(file, options.signal);
4825
- const filtered = filterDiagnosticsBySeverity(result.items, severity);
4826
- allDiagnostics.push(...filtered.map((diagnostic) => ({
4827
- filePath: file,
4828
- diagnostic
4829
- })));
4830
- } catch (e) {
4831
- fileErrors.push({
4832
- file,
4833
- error: e instanceof Error ? e.message : String(e)
4834
- });
4835
- }
4999
+ await scanServedGroups({
5000
+ manager,
5001
+ groups: groups.served,
5002
+ maxConcurrency,
5003
+ ...options.signal === undefined ? {} : { signal: options.signal },
5004
+ ...options.timers === undefined ? {} : { timers: options.timers },
5005
+ onGroupUnavailable: (group, error) => {
5006
+ fileErrors.push(...group.files.map((file) => ({ file, error })));
5007
+ },
5008
+ checkFile: async (client, file) => {
5009
+ try {
5010
+ const result = await client.diagnostics(file, options.signal);
5011
+ const filtered = filterDiagnosticsBySeverity(result.items, severity);
5012
+ allDiagnostics.push(...filtered.map((diagnostic) => ({ filePath: file, diagnostic })));
5013
+ } catch (e) {
5014
+ fileErrors.push({ file, error: e instanceof Error ? e.message : String(e) });
4836
5015
  }
4837
- });
4838
- await Promise.all(workers);
4839
- } finally {
4840
- manager.releaseClient(root, server.id);
4841
- }
5016
+ }
5017
+ });
4842
5018
  const displayDiagnostics = allDiagnostics.slice(0, DEFAULT_MAX_DIAGNOSTICS);
4843
5019
  const wasDiagCapped = allDiagnostics.length > DEFAULT_MAX_DIAGNOSTICS;
4844
5020
  const lines = [
@@ -4869,7 +5045,7 @@ async function aggregateDiagnosticsForDirectory(directory, extension, severity,
4869
5045
 
4870
5046
  // ../lsp-core/src/lsp/infer-extension.ts
4871
5047
  import { lstatSync as lstatSync5, readdirSync as readdirSync4 } from "node:fs";
4872
- import { join as join7 } from "node:path";
5048
+ import { join as join8 } from "node:path";
4873
5049
  var SKIP_DIRECTORIES2 = new Set(["node_modules", ".git", "dist", "build", ".next", "out"]);
4874
5050
  var MAX_SCAN_ENTRIES = 500;
4875
5051
  function inferExtensionFromDirectory(directory) {
@@ -4887,7 +5063,7 @@ function inferExtensionFromDirectory(directory) {
4887
5063
  for (const entry of entries) {
4888
5064
  if (scanned >= MAX_SCAN_ENTRIES)
4889
5065
  return;
4890
- const fullPath = join7(dir, entry);
5066
+ const fullPath = join8(dir, entry);
4891
5067
  let stat;
4892
5068
  try {
4893
5069
  stat = lstatSync5(fullPath);
@@ -5006,7 +5182,7 @@ function missingDependencyAvailability(error) {
5006
5182
  }
5007
5183
 
5008
5184
  // ../lsp-core/src/lsp/bun-command-output.ts
5009
- import { resolve as resolve10 } from "node:path";
5185
+ import { resolve as resolve11 } from "node:path";
5010
5186
  var TSC_LINE = /^(.+?)\((\d+),(\d+)\): (error|warning|message) (TS\d+): (.*)$/;
5011
5187
  var TSC_SEVERITY = { error: 1, warning: 2, message: 3 };
5012
5188
  function parseBunCheckOutput(stdout, cwd) {
@@ -5017,7 +5193,7 @@ function parseBunCheckOutput(stdout, cwd) {
5017
5193
  const [, path, lineNumber, column, severity, code, message] = match;
5018
5194
  const start = { line: Number(lineNumber) - 1, character: Number(column) - 1 };
5019
5195
  results.push({
5020
- file: resolve10(cwd, path ?? ""),
5196
+ file: resolve11(cwd, path ?? ""),
5021
5197
  diagnostic: {
5022
5198
  range: { start, end: start },
5023
5199
  severity: TSC_SEVERITY[severity ?? "error"] ?? 1,
@@ -5076,9 +5252,9 @@ function parseBunLintJson(stdout) {
5076
5252
 
5077
5253
  // ../lsp-core/src/lsp/bun-project-checks.ts
5078
5254
  import { spawn as spawn2 } from "node:child_process";
5079
- import { existsSync as existsSync12, mkdtempSync, readFileSync as readFileSync5, rmSync as rmSync2, statSync as statSync4, writeFileSync as writeFileSync3 } from "node:fs";
5255
+ import { existsSync as existsSync13, mkdtempSync, readFileSync as readFileSync5, rmSync as rmSync2, statSync as statSync5, writeFileSync as writeFileSync3 } from "node:fs";
5080
5256
  import { homedir as homedir2, tmpdir } from "node:os";
5081
- import { dirname as dirname9, join as join8, resolve as resolve11 } from "node:path";
5257
+ import { dirname as dirname11, join as join9, resolve as resolve12 } from "node:path";
5082
5258
  var BUN_LOCKFILES = ["bun.lock", "bun.lockb", "bunfig.toml"];
5083
5259
  var RUNNABLE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".cts", ".cjs", ".js", ".mjs", ".mts"];
5084
5260
  var BIN_SUFFIXES = process.platform === "win32" ? [".exe", ".bunx", ".cmd", ""] : [""];
@@ -5087,18 +5263,18 @@ var UNFORMATTED_PROBE = `const a=1
5087
5263
  `;
5088
5264
  var probeCache = new Map;
5089
5265
  function findBunProjectRoot(start, home = homedir2()) {
5090
- const stopAt = resolve11(home);
5091
- let dir = resolve11(start);
5266
+ const stopAt = resolve12(home);
5267
+ let dir = resolve12(start);
5092
5268
  for (;; ) {
5093
5269
  if (dir === stopAt)
5094
5270
  return;
5095
- if (BUN_LOCKFILES.some((name) => existsSync12(join8(dir, name))))
5271
+ if (BUN_LOCKFILES.some((name) => existsSync13(join9(dir, name))))
5096
5272
  return dir;
5097
- if (packageManagerIsBun(join8(dir, "package.json")))
5273
+ if (packageManagerIsBun(join9(dir, "package.json")))
5098
5274
  return dir;
5099
- if (existsSync12(join8(dir, ".git")))
5275
+ if (existsSync13(join9(dir, ".git")))
5100
5276
  return;
5101
- const parent = dirname9(dir);
5277
+ const parent = dirname11(dir);
5102
5278
  if (parent === dir)
5103
5279
  return;
5104
5280
  dir = parent;
@@ -5110,7 +5286,7 @@ function packageManagerIsBun(packageJsonPath) {
5110
5286
  return typeof packageManager === "string" && packageManager.startsWith("bun@");
5111
5287
  }
5112
5288
  function readJsonObject(path) {
5113
- if (!existsSync12(path))
5289
+ if (!existsSync13(path))
5114
5290
  return;
5115
5291
  try {
5116
5292
  const parsed = JSON.parse(readFileSync5(path, "utf8"));
@@ -5121,14 +5297,14 @@ function readJsonObject(path) {
5121
5297
  }
5122
5298
  function isFile(path) {
5123
5299
  try {
5124
- return statSync4(path).isFile();
5300
+ return statSync5(path).isFile();
5125
5301
  } catch {
5126
5302
  return false;
5127
5303
  }
5128
5304
  }
5129
5305
  function isDirectory(path) {
5130
5306
  try {
5131
- return statSync4(path).isDirectory();
5307
+ return statSync5(path).isDirectory();
5132
5308
  } catch {
5133
5309
  return false;
5134
5310
  }
@@ -5136,35 +5312,35 @@ function isDirectory(path) {
5136
5312
  function projectShadowsBunCommand(command, cwd) {
5137
5313
  const packageJsonDir = nearestPackageJsonDir(cwd);
5138
5314
  if (packageJsonDir !== undefined) {
5139
- const scripts = readJsonObject(join8(packageJsonDir, "package.json"))?.["scripts"];
5315
+ const scripts = readJsonObject(join9(packageJsonDir, "package.json"))?.["scripts"];
5140
5316
  if (scripts !== null && typeof scripts === "object" && typeof scripts[command] === "string") {
5141
5317
  return true;
5142
5318
  }
5143
5319
  }
5144
5320
  if (command === "check")
5145
5321
  return false;
5146
- const base = join8(cwd, command);
5322
+ const base = join9(cwd, command);
5147
5323
  if (isFile(base) || RUNNABLE_EXTENSIONS.some((extension) => isFile(`${base}${extension}`)))
5148
5324
  return true;
5149
- if (isDirectory(base) && (isFile(join8(base, "package.json")) || RUNNABLE_EXTENSIONS.some((extension) => isFile(join8(base, `index${extension}`))))) {
5325
+ if (isDirectory(base) && (isFile(join9(base, "package.json")) || RUNNABLE_EXTENSIONS.some((extension) => isFile(join9(base, `index${extension}`))))) {
5150
5326
  return true;
5151
5327
  }
5152
- let dir = resolve11(cwd);
5328
+ let dir = resolve12(cwd);
5153
5329
  for (;; ) {
5154
- if (BIN_SUFFIXES.some((suffix) => existsSync12(join8(dir, "node_modules", ".bin", `${command}${suffix}`))))
5330
+ if (BIN_SUFFIXES.some((suffix) => existsSync13(join9(dir, "node_modules", ".bin", `${command}${suffix}`))))
5155
5331
  return true;
5156
- const parent = dirname9(dir);
5332
+ const parent = dirname11(dir);
5157
5333
  if (parent === dir)
5158
5334
  return false;
5159
5335
  dir = parent;
5160
5336
  }
5161
5337
  }
5162
5338
  function nearestPackageJsonDir(start) {
5163
- let dir = resolve11(start);
5339
+ let dir = resolve12(start);
5164
5340
  for (;; ) {
5165
- if (existsSync12(join8(dir, "package.json")))
5341
+ if (existsSync13(join9(dir, "package.json")))
5166
5342
  return dir;
5167
- const parent = dirname9(dir);
5343
+ const parent = dirname11(dir);
5168
5344
  if (parent === dir)
5169
5345
  return;
5170
5346
  dir = parent;
@@ -5172,7 +5348,7 @@ function nearestPackageJsonDir(start) {
5172
5348
  }
5173
5349
  function binaryIdentity(bunPath) {
5174
5350
  try {
5175
- const stats = statSync4(bunPath);
5351
+ const stats = statSync5(bunPath);
5176
5352
  return `${stats.mtimeMs}:${stats.size}`;
5177
5353
  } catch {
5178
5354
  return "missing";
@@ -5192,7 +5368,7 @@ function bunHasCommand(bunPath, command, timeoutMs = PROBE_TIMEOUT_MS) {
5192
5368
  return probe;
5193
5369
  }
5194
5370
  async function probeOnce(bunPath, command, timeoutMs) {
5195
- const emptyDir = mkdtempSync(join8(tmpdir(), "omo-bun-probe-"));
5371
+ const emptyDir = mkdtempSync(join9(tmpdir(), "omo-bun-probe-"));
5196
5372
  const timeout = AbortSignal.timeout(timeoutMs);
5197
5373
  try {
5198
5374
  const help = await runBunCommand(bunPath, [command, "--help"], emptyDir, timeout);
@@ -5202,7 +5378,7 @@ async function probeOnce(bunPath, command, timeoutMs) {
5202
5378
  return false;
5203
5379
  if (command !== "format")
5204
5380
  return true;
5205
- const probeFile = join8(emptyDir, "probe.ts");
5381
+ const probeFile = join9(emptyDir, "probe.ts");
5206
5382
  writeFileSync3(probeFile, UNFORMATTED_PROBE);
5207
5383
  const write = await runBunCommand(bunPath, ["format", "--write", "probe.ts"], emptyDir, timeout);
5208
5384
  if (write.exitCode === null)