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
@@ -21,6 +21,24 @@ var realTimerProvider = {
21
21
  setTimeout: (callback, delayMs) => setTimeout(callback, delayMs),
22
22
  clearTimeout: (handle) => clearTimeout(handle)
23
23
  };
24
+ function repeatEvery(timers, intervalMs, tick) {
25
+ let handle = null;
26
+ const arm = () => {
27
+ handle = timers.setTimeout(() => {
28
+ tick();
29
+ if (handle !== null)
30
+ arm();
31
+ }, intervalMs);
32
+ if (typeof handle.unref === "function")
33
+ handle.unref();
34
+ };
35
+ arm();
36
+ return () => {
37
+ if (handle !== null)
38
+ timers.clearTimeout(handle);
39
+ handle = null;
40
+ };
41
+ }
24
42
 
25
43
  // ../lsp-core/src/lsp/constants.ts
26
44
  var DEFAULT_MAX_REFERENCES = 200;
@@ -2770,30 +2788,54 @@ function abortError2(signal) {
2770
2788
  return error;
2771
2789
  }
2772
2790
 
2773
- // ../lsp-core/src/lsp/process-signal-cleanup.ts
2774
- function installProcessSignalCleanup(cleanup) {
2775
- const signals = process.platform === "win32" ? ["SIGINT", "SIGTERM", "SIGBREAK"] : ["SIGINT", "SIGTERM"];
2776
- const handler = () => {
2777
- cleanup().catch((error) => {
2778
- reportBestEffortCleanupError("signal cleanup", error);
2779
- });
2780
- };
2781
- for (const signal of signals) {
2782
- process.on(signal, handler);
2783
- }
2784
- return () => {
2785
- for (const signal of signals) {
2786
- process.removeListener(signal, handler);
2787
- }
2788
- };
2791
+ // ../lsp-core/src/lsp/client-key.ts
2792
+ function lspClientKey(root, server) {
2793
+ return JSON.stringify([root, server.id, server.command]);
2789
2794
  }
2790
2795
 
2791
- // ../lsp-core/src/lsp/manager.ts
2792
- async function stopClientBestEffort(client) {
2793
- try {
2794
- await client.stop();
2795
- } catch (error) {
2796
- reportBestEffortCleanupError("client stop", error);
2796
+ // ../lsp-core/src/lsp/client-startup.ts
2797
+ class ClientStartups {
2798
+ constructor(now, discard) {
2799
+ this.now = now;
2800
+ this.discard = discard;
2801
+ }
2802
+ begin(request) {
2803
+ const { client } = request;
2804
+ const startedAt = this.now();
2805
+ const initPromise = (async () => {
2806
+ await client.start();
2807
+ await client.initialize();
2808
+ })();
2809
+ const managed = {
2810
+ ...request,
2811
+ refCount: 0,
2812
+ pendingWaiters: 0,
2813
+ lastUsedAt: startedAt,
2814
+ initPromise,
2815
+ isInitializing: true,
2816
+ initializingSince: startedAt
2817
+ };
2818
+ initPromise.then(() => {
2819
+ managed.isInitializing = false;
2820
+ managed.initializingSince = null;
2821
+ managed.initPromise = null;
2822
+ managed.lastUsedAt = this.now();
2823
+ }, () => this.discard(managed));
2824
+ return managed;
2825
+ }
2826
+ async wait(managed, initPromise, signal) {
2827
+ managed.pendingWaiters++;
2828
+ try {
2829
+ await awaitWithSignal(initPromise, signal);
2830
+ } catch (error) {
2831
+ this.detach(managed);
2832
+ throw error;
2833
+ }
2834
+ }
2835
+ detach(managed) {
2836
+ managed.pendingWaiters--;
2837
+ if (managed.pendingWaiters === 0 && managed.refCount === 0 && managed.heldByWaiters)
2838
+ this.discard(managed);
2797
2839
  }
2798
2840
  }
2799
2841
  function awaitWithSignal(promise, signal) {
@@ -2828,36 +2870,50 @@ function awaitWithSignal(promise, signal) {
2828
2870
  });
2829
2871
  }
2830
2872
 
2873
+ // ../lsp-core/src/lsp/process-signal-cleanup.ts
2874
+ function installProcessSignalCleanup(cleanup) {
2875
+ const signals = process.platform === "win32" ? ["SIGINT", "SIGTERM", "SIGBREAK"] : ["SIGINT", "SIGTERM"];
2876
+ const handler = () => {
2877
+ cleanup().catch((error) => {
2878
+ reportBestEffortCleanupError("signal cleanup", error);
2879
+ });
2880
+ };
2881
+ for (const signal of signals) {
2882
+ process.on(signal, handler);
2883
+ }
2884
+ return () => {
2885
+ for (const signal of signals) {
2886
+ process.removeListener(signal, handler);
2887
+ }
2888
+ };
2889
+ }
2890
+
2891
+ // ../lsp-core/src/lsp/manager.ts
2892
+ async function stopClientBestEffort(client) {
2893
+ try {
2894
+ await client.stop();
2895
+ } catch (error) {
2896
+ reportBestEffortCleanupError("client stop", error);
2897
+ }
2898
+ }
2899
+
2831
2900
  class LspManager {
2832
2901
  constructor(options = {}) {
2833
2902
  this.clients = new Map;
2834
2903
  this.pendingStops = new Map;
2835
2904
  this.respawnBudgets = new Map;
2836
- this.reaperHandle = null;
2837
2905
  this.signalDisposer = null;
2838
2906
  this.disposed = false;
2839
2907
  this.idleTimeoutMs = options.idleTimeoutMs ?? IDLE_TIMEOUT_MS;
2840
2908
  this.initTimeoutMs = options.initTimeoutMs ?? INIT_TIMEOUT_MS;
2841
2909
  this.maxResidentClients = options.maxResidentClients ?? MAX_RESIDENT_CLIENTS;
2842
- this.reaperIntervalMs = options.reaperIntervalMs ?? REAPER_INTERVAL_MS;
2843
2910
  this.clientFactory = options.clientFactory ?? ((root, server) => new LspClient(root, server));
2844
2911
  this.now = options.now ?? (() => Date.now());
2845
- this.startReaper();
2912
+ this.startups = new ClientStartups(this.now, (managed) => this.discard(managed));
2913
+ const reaperIntervalMs = options.reaperIntervalMs ?? REAPER_INTERVAL_MS;
2914
+ this.stopReaper = repeatEvery(options.timers ?? realTimerProvider, reaperIntervalMs, () => this.reapStale());
2846
2915
  this.signalDisposer = installProcessSignalCleanup(() => this.stopAll());
2847
2916
  }
2848
- startReaper() {
2849
- if (this.reaperHandle)
2850
- return;
2851
- this.reaperHandle = setInterval(() => {
2852
- this.reapStale();
2853
- }, this.reaperIntervalMs);
2854
- if (typeof this.reaperHandle.unref === "function") {
2855
- this.reaperHandle.unref();
2856
- }
2857
- }
2858
- getKey(root, serverId) {
2859
- return `${root}::${serverId}`;
2860
- }
2861
2917
  tombstoneStop(key, client) {
2862
2918
  const stop = stopClientBestEffort(client);
2863
2919
  this.pendingStops.set(key, stop);
@@ -2893,18 +2949,15 @@ class LspManager {
2893
2949
  budget.deadGenerations = 0;
2894
2950
  budget.exhaustedAt = null;
2895
2951
  }
2952
+ startupExpired(managed, t) {
2953
+ return managed.isInitializing && managed.initializingSince !== null && t - managed.initializingSince > this.initTimeoutMs;
2954
+ }
2896
2955
  reapStale() {
2897
2956
  const t = this.now();
2898
- for (const [key, managed] of this.clients) {
2899
- if (managed.isInitializing && managed.initializingSince !== null && t - managed.initializingSince > this.initTimeoutMs) {
2900
- this.clients.delete(key);
2901
- this.tombstoneStop(key, managed.client);
2902
- continue;
2903
- }
2904
- if (!managed.isInitializing && managed.refCount === 0 && managed.pendingWaiters === 0 && t - managed.lastUsedAt > this.idleTimeoutMs) {
2905
- this.clients.delete(key);
2906
- this.tombstoneStop(key, managed.client);
2907
- }
2957
+ for (const managed of [...this.clients.values()]) {
2958
+ const idle = !managed.isInitializing && managed.refCount === 0 && managed.pendingWaiters === 0 && t - managed.lastUsedAt > this.idleTimeoutMs;
2959
+ if (idle || this.startupExpired(managed, t))
2960
+ this.discard(managed);
2908
2961
  }
2909
2962
  }
2910
2963
  evictForAdmission() {
@@ -2912,152 +2965,96 @@ class LspManager {
2912
2965
  const victim = this.leastRecentlyUsedIdleClient();
2913
2966
  if (!victim)
2914
2967
  return;
2915
- this.clients.delete(victim.key);
2916
- this.tombstoneStop(victim.key, victim.managed.client);
2968
+ this.discard(victim);
2917
2969
  }
2918
2970
  }
2919
2971
  leastRecentlyUsedIdleClient() {
2920
2972
  let candidate = null;
2921
- for (const [key, managed] of this.clients) {
2973
+ for (const managed of this.clients.values()) {
2922
2974
  if (managed.refCount > 0 || managed.pendingWaiters > 0 || managed.isInitializing)
2923
2975
  continue;
2924
- if (candidate === null || managed.lastUsedAt < candidate.managed.lastUsedAt) {
2925
- candidate = { key, managed };
2926
- }
2976
+ if (candidate === null || managed.lastUsedAt < candidate.lastUsedAt)
2977
+ candidate = managed;
2927
2978
  }
2928
2979
  return candidate;
2929
2980
  }
2930
- async tryDeleteIfOrphaned(key, managed) {
2931
- if (managed.refCount === 0 && managed.pendingWaiters === 0 && !managed.isInitializing && this.clients.get(key) === managed) {
2932
- this.clients.delete(key);
2933
- await this.tombstoneStop(key, managed.client);
2934
- }
2981
+ discard(managed) {
2982
+ if (this.clients.get(managed.key) !== managed)
2983
+ return;
2984
+ this.clients.delete(managed.key);
2985
+ this.tombstoneStop(managed.key, managed.client);
2935
2986
  }
2936
2987
  async getClient(root, server, signal) {
2937
- if (this.disposed) {
2938
- throw new Error("LspManager has been disposed");
2939
- }
2940
- signal?.throwIfAborted();
2941
- const key = this.getKey(root, server.id);
2988
+ const key = lspClientKey(root, server);
2942
2989
  for (;; ) {
2943
- const pendingStop = this.pendingStops.get(key);
2944
- if (pendingStop === undefined)
2945
- break;
2946
- await awaitWithSignal(pendingStop, signal);
2990
+ if (this.disposed) {
2991
+ throw new Error("LspManager has been disposed");
2992
+ }
2947
2993
  signal?.throwIfAborted();
2948
- }
2949
- if (this.disposed) {
2950
- throw new Error("LspManager has been disposed");
2951
- }
2952
- let managed = this.clients.get(key);
2953
- if (managed) {
2954
- const t = this.now();
2955
- if (managed.isInitializing && managed.initializingSince !== null && t - managed.initializingSince > this.initTimeoutMs) {
2956
- this.clients.delete(key);
2957
- await this.tombstoneStop(key, managed.client);
2958
- managed = undefined;
2994
+ const pendingStop = this.pendingStops.get(key);
2995
+ if (pendingStop !== undefined) {
2996
+ await awaitWithSignal(pendingStop, signal);
2997
+ continue;
2959
2998
  }
2960
- }
2961
- if (managed) {
2962
- if (managed.initPromise) {
2963
- managed.pendingWaiters++;
2964
- try {
2965
- await awaitWithSignal(managed.initPromise, signal);
2966
- } catch (err) {
2967
- managed.pendingWaiters--;
2968
- await this.tryDeleteIfOrphaned(key, managed);
2969
- throw err;
2999
+ let managed = this.clients.get(key);
3000
+ if (managed !== undefined && this.startupExpired(managed, this.now())) {
3001
+ this.discard(managed);
3002
+ continue;
3003
+ }
3004
+ if (managed === undefined) {
3005
+ this.evictForAdmission();
3006
+ this.ensureRespawnAllowed(key, root, server.id);
3007
+ managed = this.startClient(key, root, server, true);
3008
+ }
3009
+ const { initPromise } = managed;
3010
+ if (initPromise !== null) {
3011
+ await this.startups.wait(managed, initPromise, signal);
3012
+ if (signal?.aborted) {
3013
+ this.startups.detach(managed);
3014
+ signal.throwIfAborted();
2970
3015
  }
2971
3016
  managed.pendingWaiters--;
2972
3017
  }
2973
- if (signal?.aborted) {
2974
- await this.tryDeleteIfOrphaned(key, managed);
2975
- signal.throwIfAborted();
2976
- }
3018
+ if (this.clients.get(key) !== managed)
3019
+ continue;
2977
3020
  if (!managed.client.isAlive()) {
2978
3021
  this.recordDeadGeneration(key);
2979
- if (this.clients.get(key) === managed) {
2980
- this.clients.delete(key);
2981
- }
2982
- await this.tombstoneStop(key, managed.client);
2983
- return this.getClient(root, server, signal);
3022
+ this.discard(managed);
3023
+ continue;
2984
3024
  }
2985
3025
  this.markHealthyGeneration(key);
2986
3026
  managed.refCount++;
2987
3027
  managed.lastUsedAt = this.now();
2988
3028
  return managed.client;
2989
3029
  }
2990
- this.evictForAdmission();
2991
- this.ensureRespawnAllowed(key, root, server.id);
3030
+ }
3031
+ startClient(key, root, server, heldByWaiters) {
2992
3032
  const client = this.clientFactory(root, server);
2993
- const initStartedAt = this.now();
2994
- const initPromise = (async () => {
2995
- await client.start();
2996
- await client.initialize();
2997
- })();
2998
- const newManaged = {
2999
- client,
3000
- refCount: 0,
3001
- pendingWaiters: 1,
3002
- lastUsedAt: initStartedAt,
3003
- initPromise,
3004
- isInitializing: true,
3005
- initializingSince: initStartedAt
3006
- };
3007
- this.clients.set(key, newManaged);
3008
- try {
3009
- await awaitWithSignal(initPromise, signal);
3010
- } catch (err) {
3011
- newManaged.pendingWaiters--;
3012
- if (this.clients.get(key) === newManaged) {
3013
- this.clients.delete(key);
3014
- }
3015
- await this.tombstoneStop(key, client);
3016
- throw err;
3017
- }
3018
- newManaged.pendingWaiters--;
3019
- newManaged.isInitializing = false;
3020
- newManaged.initializingSince = null;
3021
- newManaged.initPromise = null;
3022
- if (signal?.aborted) {
3023
- await this.tryDeleteIfOrphaned(key, newManaged);
3024
- signal.throwIfAborted();
3025
- }
3026
- if (!client.isAlive()) {
3027
- this.recordDeadGeneration(key);
3028
- if (this.clients.get(key) === newManaged) {
3029
- this.clients.delete(key);
3030
- }
3031
- await this.tombstoneStop(key, client);
3032
- return this.getClient(root, server, signal);
3033
- }
3034
- this.markHealthyGeneration(key);
3035
- newManaged.refCount++;
3036
- newManaged.lastUsedAt = this.now();
3037
- return client;
3033
+ const managed = this.startups.begin({ key, root, serverId: server.id, client, heldByWaiters });
3034
+ this.clients.set(key, managed);
3035
+ return managed;
3038
3036
  }
3039
- releaseClient(root, serverId) {
3040
- const key = this.getKey(root, serverId);
3041
- const managed = this.clients.get(key);
3037
+ releaseClient(root, server, client) {
3038
+ const managed = this.clients.get(lspClientKey(root, server));
3039
+ if (client !== undefined && managed?.client !== client)
3040
+ return;
3042
3041
  if (managed && managed.refCount > 0) {
3043
3042
  managed.refCount--;
3044
3043
  managed.lastUsedAt = this.now();
3045
3044
  }
3046
3045
  }
3047
- invalidateClient(root, serverId, client) {
3048
- const key = this.getKey(root, serverId);
3049
- const managed = this.clients.get(key);
3046
+ invalidateClient(root, server, client) {
3047
+ const managed = this.clients.get(lspClientKey(root, server));
3050
3048
  if (!managed)
3051
3049
  return;
3052
3050
  if (client && managed.client !== client)
3053
3051
  return;
3054
- this.clients.delete(key);
3055
- this.tombstoneStop(key, managed.client);
3052
+ this.discard(managed);
3056
3053
  }
3057
3054
  warmupClient(root, server) {
3058
3055
  if (this.disposed)
3059
3056
  return;
3060
- const key = this.getKey(root, server.id);
3057
+ const key = lspClientKey(root, server);
3061
3058
  if (this.clients.has(key) || this.pendingStops.has(key))
3062
3059
  return;
3063
3060
  this.evictForAdmission();
@@ -3066,45 +3063,18 @@ class LspManager {
3066
3063
  } catch {
3067
3064
  return;
3068
3065
  }
3069
- const client = this.clientFactory(root, server);
3070
- const initStartedAt = this.now();
3071
- const initPromise = (async () => {
3072
- await client.start();
3073
- await client.initialize();
3074
- })();
3075
- const managed = {
3076
- client,
3077
- refCount: 0,
3078
- pendingWaiters: 0,
3079
- lastUsedAt: initStartedAt,
3080
- initPromise,
3081
- isInitializing: true,
3082
- initializingSince: initStartedAt
3083
- };
3084
- this.clients.set(key, managed);
3085
- initPromise.then(() => {
3086
- managed.isInitializing = false;
3087
- managed.initializingSince = null;
3088
- managed.initPromise = null;
3089
- managed.lastUsedAt = this.now();
3090
- }, () => {
3091
- if (this.clients.get(key) === managed) {
3092
- this.clients.delete(key);
3093
- }
3094
- this.tombstoneStop(key, client);
3095
- });
3066
+ this.startClient(key, root, server, false);
3096
3067
  }
3097
- isServerInitializing(root, serverId) {
3098
- const managed = this.clients.get(this.getKey(root, serverId));
3068
+ isServerInitializing(root, server) {
3069
+ const managed = this.clients.get(lspClientKey(root, server));
3099
3070
  return managed?.isInitializing ?? false;
3100
3071
  }
3101
3072
  getSnapshot() {
3102
3073
  const snapshots = [];
3103
- for (const [key, managed] of this.clients) {
3104
- const [root, serverId] = key.split("::");
3074
+ for (const managed of this.clients.values()) {
3105
3075
  snapshots.push({
3106
- root,
3107
- serverId,
3076
+ root: managed.root,
3077
+ serverId: managed.serverId,
3108
3078
  refCount: managed.refCount,
3109
3079
  pendingWaiters: managed.pendingWaiters,
3110
3080
  lastUsedAt: managed.lastUsedAt,
@@ -3115,18 +3085,15 @@ class LspManager {
3115
3085
  }
3116
3086
  return snapshots;
3117
3087
  }
3118
- hasClient(root, serverId) {
3119
- return this.clients.has(this.getKey(root, serverId));
3088
+ hasClient(root, server) {
3089
+ return this.clients.has(lspClientKey(root, server));
3120
3090
  }
3121
3091
  clientCount() {
3122
3092
  return this.clients.size;
3123
3093
  }
3124
3094
  async stopAll() {
3125
3095
  this.disposed = true;
3126
- if (this.reaperHandle) {
3127
- clearInterval(this.reaperHandle);
3128
- this.reaperHandle = null;
3129
- }
3096
+ this.stopReaper();
3130
3097
  if (this.signalDisposer) {
3131
3098
  this.signalDisposer();
3132
3099
  this.signalDisposer = null;