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
@@ -1,11 +1,11 @@
1
1
  // src/client.ts
2
- import { statSync as statSync6 } from "node:fs";
2
+ import { statSync as statSync7 } from "node:fs";
3
3
  import { isAbsolute as isAbsolute6 } from "node:path";
4
4
 
5
5
  // src/daemon-client.ts
6
6
  import { connect } from "node:net";
7
7
  import { homedir as homedir4 } from "node:os";
8
- import { join as join9 } from "node:path";
8
+ import { join as join10 } from "node:path";
9
9
  import { setTimeout as delay } from "node:timers/promises";
10
10
 
11
11
  // ../lsp-core/src/request-context.ts
@@ -1160,8 +1160,8 @@ function createIdleTimer(idleTimeoutMs, log, onTimeout) {
1160
1160
  };
1161
1161
  }
1162
1162
  // ../lsp-core/src/lsp/client-wrapper.ts
1163
- import { existsSync as existsSync11, realpathSync as realpathSync6, statSync as statSync4 } from "node:fs";
1164
- import { basename as basename3, dirname as dirname10, join as join5, resolve as resolve8 } from "node:path";
1163
+ import { existsSync as existsSync12, realpathSync as realpathSync7, statSync as statSync5 } from "node:fs";
1164
+ import { basename as basename3, dirname as dirname11, join as join6, resolve as resolve9 } from "node:path";
1165
1165
 
1166
1166
  // ../lsp-core/src/lsp/effective-extension.ts
1167
1167
  import { basename as basename2, extname } from "node:path";
@@ -1273,6 +1273,24 @@ var realTimerProvider = {
1273
1273
  setTimeout: (callback, delayMs) => setTimeout(callback, delayMs),
1274
1274
  clearTimeout: (handle) => clearTimeout(handle)
1275
1275
  };
1276
+ function repeatEvery(timers, intervalMs, tick) {
1277
+ let handle = null;
1278
+ const arm = () => {
1279
+ handle = timers.setTimeout(() => {
1280
+ tick();
1281
+ if (handle !== null)
1282
+ arm();
1283
+ }, intervalMs);
1284
+ if (typeof handle.unref === "function")
1285
+ handle.unref();
1286
+ };
1287
+ arm();
1288
+ return () => {
1289
+ if (handle !== null)
1290
+ timers.clearTimeout(handle);
1291
+ handle = null;
1292
+ };
1293
+ }
1276
1294
 
1277
1295
  // ../lsp-core/src/lsp/constants.ts
1278
1296
  var DEFAULT_MAX_REFERENCES = 200;
@@ -3935,30 +3953,54 @@ function abortError3(signal) {
3935
3953
  return error;
3936
3954
  }
3937
3955
 
3938
- // ../lsp-core/src/lsp/process-signal-cleanup.ts
3939
- function installProcessSignalCleanup(cleanup) {
3940
- const signals = process.platform === "win32" ? ["SIGINT", "SIGTERM", "SIGBREAK"] : ["SIGINT", "SIGTERM"];
3941
- const handler = () => {
3942
- cleanup().catch((error) => {
3943
- reportBestEffortCleanupError("signal cleanup", error);
3944
- });
3945
- };
3946
- for (const signal of signals) {
3947
- process.on(signal, handler);
3948
- }
3949
- return () => {
3950
- for (const signal of signals) {
3951
- process.removeListener(signal, handler);
3952
- }
3953
- };
3956
+ // ../lsp-core/src/lsp/client-key.ts
3957
+ function lspClientKey(root, server) {
3958
+ return JSON.stringify([root, server.id, server.command]);
3954
3959
  }
3955
3960
 
3956
- // ../lsp-core/src/lsp/manager.ts
3957
- async function stopClientBestEffort(client) {
3958
- try {
3959
- await client.stop();
3960
- } catch (error) {
3961
- reportBestEffortCleanupError("client stop", error);
3961
+ // ../lsp-core/src/lsp/client-startup.ts
3962
+ class ClientStartups {
3963
+ constructor(now, discard) {
3964
+ this.now = now;
3965
+ this.discard = discard;
3966
+ }
3967
+ begin(request) {
3968
+ const { client } = request;
3969
+ const startedAt = this.now();
3970
+ const initPromise = (async () => {
3971
+ await client.start();
3972
+ await client.initialize();
3973
+ })();
3974
+ const managed = {
3975
+ ...request,
3976
+ refCount: 0,
3977
+ pendingWaiters: 0,
3978
+ lastUsedAt: startedAt,
3979
+ initPromise,
3980
+ isInitializing: true,
3981
+ initializingSince: startedAt
3982
+ };
3983
+ initPromise.then(() => {
3984
+ managed.isInitializing = false;
3985
+ managed.initializingSince = null;
3986
+ managed.initPromise = null;
3987
+ managed.lastUsedAt = this.now();
3988
+ }, () => this.discard(managed));
3989
+ return managed;
3990
+ }
3991
+ async wait(managed, initPromise, signal) {
3992
+ managed.pendingWaiters++;
3993
+ try {
3994
+ await awaitWithSignal2(initPromise, signal);
3995
+ } catch (error) {
3996
+ this.detach(managed);
3997
+ throw error;
3998
+ }
3999
+ }
4000
+ detach(managed) {
4001
+ managed.pendingWaiters--;
4002
+ if (managed.pendingWaiters === 0 && managed.refCount === 0 && managed.heldByWaiters)
4003
+ this.discard(managed);
3962
4004
  }
3963
4005
  }
3964
4006
  function awaitWithSignal2(promise, signal) {
@@ -3993,36 +4035,50 @@ function awaitWithSignal2(promise, signal) {
3993
4035
  });
3994
4036
  }
3995
4037
 
4038
+ // ../lsp-core/src/lsp/process-signal-cleanup.ts
4039
+ function installProcessSignalCleanup(cleanup) {
4040
+ const signals = process.platform === "win32" ? ["SIGINT", "SIGTERM", "SIGBREAK"] : ["SIGINT", "SIGTERM"];
4041
+ const handler = () => {
4042
+ cleanup().catch((error) => {
4043
+ reportBestEffortCleanupError("signal cleanup", error);
4044
+ });
4045
+ };
4046
+ for (const signal of signals) {
4047
+ process.on(signal, handler);
4048
+ }
4049
+ return () => {
4050
+ for (const signal of signals) {
4051
+ process.removeListener(signal, handler);
4052
+ }
4053
+ };
4054
+ }
4055
+
4056
+ // ../lsp-core/src/lsp/manager.ts
4057
+ async function stopClientBestEffort(client) {
4058
+ try {
4059
+ await client.stop();
4060
+ } catch (error) {
4061
+ reportBestEffortCleanupError("client stop", error);
4062
+ }
4063
+ }
4064
+
3996
4065
  class LspManager {
3997
4066
  constructor(options = {}) {
3998
4067
  this.clients = new Map;
3999
4068
  this.pendingStops = new Map;
4000
4069
  this.respawnBudgets = new Map;
4001
- this.reaperHandle = null;
4002
4070
  this.signalDisposer = null;
4003
4071
  this.disposed = false;
4004
4072
  this.idleTimeoutMs = options.idleTimeoutMs ?? IDLE_TIMEOUT_MS;
4005
4073
  this.initTimeoutMs = options.initTimeoutMs ?? INIT_TIMEOUT_MS;
4006
4074
  this.maxResidentClients = options.maxResidentClients ?? MAX_RESIDENT_CLIENTS;
4007
- this.reaperIntervalMs = options.reaperIntervalMs ?? REAPER_INTERVAL_MS;
4008
4075
  this.clientFactory = options.clientFactory ?? ((root, server) => new LspClient(root, server));
4009
4076
  this.now = options.now ?? (() => Date.now());
4010
- this.startReaper();
4077
+ this.startups = new ClientStartups(this.now, (managed) => this.discard(managed));
4078
+ const reaperIntervalMs = options.reaperIntervalMs ?? REAPER_INTERVAL_MS;
4079
+ this.stopReaper = repeatEvery(options.timers ?? realTimerProvider, reaperIntervalMs, () => this.reapStale());
4011
4080
  this.signalDisposer = installProcessSignalCleanup(() => this.stopAll());
4012
4081
  }
4013
- startReaper() {
4014
- if (this.reaperHandle)
4015
- return;
4016
- this.reaperHandle = setInterval(() => {
4017
- this.reapStale();
4018
- }, this.reaperIntervalMs);
4019
- if (typeof this.reaperHandle.unref === "function") {
4020
- this.reaperHandle.unref();
4021
- }
4022
- }
4023
- getKey(root, serverId) {
4024
- return `${root}::${serverId}`;
4025
- }
4026
4082
  tombstoneStop(key, client) {
4027
4083
  const stop = stopClientBestEffort(client);
4028
4084
  this.pendingStops.set(key, stop);
@@ -4058,18 +4114,15 @@ class LspManager {
4058
4114
  budget.deadGenerations = 0;
4059
4115
  budget.exhaustedAt = null;
4060
4116
  }
4117
+ startupExpired(managed, t) {
4118
+ return managed.isInitializing && managed.initializingSince !== null && t - managed.initializingSince > this.initTimeoutMs;
4119
+ }
4061
4120
  reapStale() {
4062
4121
  const t = this.now();
4063
- for (const [key, managed] of this.clients) {
4064
- if (managed.isInitializing && managed.initializingSince !== null && t - managed.initializingSince > this.initTimeoutMs) {
4065
- this.clients.delete(key);
4066
- this.tombstoneStop(key, managed.client);
4067
- continue;
4068
- }
4069
- if (!managed.isInitializing && managed.refCount === 0 && managed.pendingWaiters === 0 && t - managed.lastUsedAt > this.idleTimeoutMs) {
4070
- this.clients.delete(key);
4071
- this.tombstoneStop(key, managed.client);
4072
- }
4122
+ for (const managed of [...this.clients.values()]) {
4123
+ const idle = !managed.isInitializing && managed.refCount === 0 && managed.pendingWaiters === 0 && t - managed.lastUsedAt > this.idleTimeoutMs;
4124
+ if (idle || this.startupExpired(managed, t))
4125
+ this.discard(managed);
4073
4126
  }
4074
4127
  }
4075
4128
  evictForAdmission() {
@@ -4077,152 +4130,96 @@ class LspManager {
4077
4130
  const victim = this.leastRecentlyUsedIdleClient();
4078
4131
  if (!victim)
4079
4132
  return;
4080
- this.clients.delete(victim.key);
4081
- this.tombstoneStop(victim.key, victim.managed.client);
4133
+ this.discard(victim);
4082
4134
  }
4083
4135
  }
4084
4136
  leastRecentlyUsedIdleClient() {
4085
4137
  let candidate = null;
4086
- for (const [key, managed] of this.clients) {
4138
+ for (const managed of this.clients.values()) {
4087
4139
  if (managed.refCount > 0 || managed.pendingWaiters > 0 || managed.isInitializing)
4088
4140
  continue;
4089
- if (candidate === null || managed.lastUsedAt < candidate.managed.lastUsedAt) {
4090
- candidate = { key, managed };
4091
- }
4141
+ if (candidate === null || managed.lastUsedAt < candidate.lastUsedAt)
4142
+ candidate = managed;
4092
4143
  }
4093
4144
  return candidate;
4094
4145
  }
4095
- async tryDeleteIfOrphaned(key, managed) {
4096
- if (managed.refCount === 0 && managed.pendingWaiters === 0 && !managed.isInitializing && this.clients.get(key) === managed) {
4097
- this.clients.delete(key);
4098
- await this.tombstoneStop(key, managed.client);
4099
- }
4146
+ discard(managed) {
4147
+ if (this.clients.get(managed.key) !== managed)
4148
+ return;
4149
+ this.clients.delete(managed.key);
4150
+ this.tombstoneStop(managed.key, managed.client);
4100
4151
  }
4101
4152
  async getClient(root, server, signal) {
4102
- if (this.disposed) {
4103
- throw new Error("LspManager has been disposed");
4104
- }
4105
- signal?.throwIfAborted();
4106
- const key = this.getKey(root, server.id);
4153
+ const key = lspClientKey(root, server);
4107
4154
  for (;; ) {
4108
- const pendingStop = this.pendingStops.get(key);
4109
- if (pendingStop === undefined)
4110
- break;
4111
- await awaitWithSignal2(pendingStop, signal);
4155
+ if (this.disposed) {
4156
+ throw new Error("LspManager has been disposed");
4157
+ }
4112
4158
  signal?.throwIfAborted();
4113
- }
4114
- if (this.disposed) {
4115
- throw new Error("LspManager has been disposed");
4116
- }
4117
- let managed = this.clients.get(key);
4118
- if (managed) {
4119
- const t = this.now();
4120
- if (managed.isInitializing && managed.initializingSince !== null && t - managed.initializingSince > this.initTimeoutMs) {
4121
- this.clients.delete(key);
4122
- await this.tombstoneStop(key, managed.client);
4123
- managed = undefined;
4159
+ const pendingStop = this.pendingStops.get(key);
4160
+ if (pendingStop !== undefined) {
4161
+ await awaitWithSignal2(pendingStop, signal);
4162
+ continue;
4124
4163
  }
4125
- }
4126
- if (managed) {
4127
- if (managed.initPromise) {
4128
- managed.pendingWaiters++;
4129
- try {
4130
- await awaitWithSignal2(managed.initPromise, signal);
4131
- } catch (err) {
4132
- managed.pendingWaiters--;
4133
- await this.tryDeleteIfOrphaned(key, managed);
4134
- throw err;
4164
+ let managed = this.clients.get(key);
4165
+ if (managed !== undefined && this.startupExpired(managed, this.now())) {
4166
+ this.discard(managed);
4167
+ continue;
4168
+ }
4169
+ if (managed === undefined) {
4170
+ this.evictForAdmission();
4171
+ this.ensureRespawnAllowed(key, root, server.id);
4172
+ managed = this.startClient(key, root, server, true);
4173
+ }
4174
+ const { initPromise } = managed;
4175
+ if (initPromise !== null) {
4176
+ await this.startups.wait(managed, initPromise, signal);
4177
+ if (signal?.aborted) {
4178
+ this.startups.detach(managed);
4179
+ signal.throwIfAborted();
4135
4180
  }
4136
4181
  managed.pendingWaiters--;
4137
4182
  }
4138
- if (signal?.aborted) {
4139
- await this.tryDeleteIfOrphaned(key, managed);
4140
- signal.throwIfAborted();
4141
- }
4183
+ if (this.clients.get(key) !== managed)
4184
+ continue;
4142
4185
  if (!managed.client.isAlive()) {
4143
4186
  this.recordDeadGeneration(key);
4144
- if (this.clients.get(key) === managed) {
4145
- this.clients.delete(key);
4146
- }
4147
- await this.tombstoneStop(key, managed.client);
4148
- return this.getClient(root, server, signal);
4187
+ this.discard(managed);
4188
+ continue;
4149
4189
  }
4150
4190
  this.markHealthyGeneration(key);
4151
4191
  managed.refCount++;
4152
4192
  managed.lastUsedAt = this.now();
4153
4193
  return managed.client;
4154
4194
  }
4155
- this.evictForAdmission();
4156
- this.ensureRespawnAllowed(key, root, server.id);
4195
+ }
4196
+ startClient(key, root, server, heldByWaiters) {
4157
4197
  const client = this.clientFactory(root, server);
4158
- const initStartedAt = this.now();
4159
- const initPromise = (async () => {
4160
- await client.start();
4161
- await client.initialize();
4162
- })();
4163
- const newManaged = {
4164
- client,
4165
- refCount: 0,
4166
- pendingWaiters: 1,
4167
- lastUsedAt: initStartedAt,
4168
- initPromise,
4169
- isInitializing: true,
4170
- initializingSince: initStartedAt
4171
- };
4172
- this.clients.set(key, newManaged);
4173
- try {
4174
- await awaitWithSignal2(initPromise, signal);
4175
- } catch (err) {
4176
- newManaged.pendingWaiters--;
4177
- if (this.clients.get(key) === newManaged) {
4178
- this.clients.delete(key);
4179
- }
4180
- await this.tombstoneStop(key, client);
4181
- throw err;
4182
- }
4183
- newManaged.pendingWaiters--;
4184
- newManaged.isInitializing = false;
4185
- newManaged.initializingSince = null;
4186
- newManaged.initPromise = null;
4187
- if (signal?.aborted) {
4188
- await this.tryDeleteIfOrphaned(key, newManaged);
4189
- signal.throwIfAborted();
4190
- }
4191
- if (!client.isAlive()) {
4192
- this.recordDeadGeneration(key);
4193
- if (this.clients.get(key) === newManaged) {
4194
- this.clients.delete(key);
4195
- }
4196
- await this.tombstoneStop(key, client);
4197
- return this.getClient(root, server, signal);
4198
- }
4199
- this.markHealthyGeneration(key);
4200
- newManaged.refCount++;
4201
- newManaged.lastUsedAt = this.now();
4202
- return client;
4198
+ const managed = this.startups.begin({ key, root, serverId: server.id, client, heldByWaiters });
4199
+ this.clients.set(key, managed);
4200
+ return managed;
4203
4201
  }
4204
- releaseClient(root, serverId) {
4205
- const key = this.getKey(root, serverId);
4206
- const managed = this.clients.get(key);
4202
+ releaseClient(root, server, client) {
4203
+ const managed = this.clients.get(lspClientKey(root, server));
4204
+ if (client !== undefined && managed?.client !== client)
4205
+ return;
4207
4206
  if (managed && managed.refCount > 0) {
4208
4207
  managed.refCount--;
4209
4208
  managed.lastUsedAt = this.now();
4210
4209
  }
4211
4210
  }
4212
- invalidateClient(root, serverId, client) {
4213
- const key = this.getKey(root, serverId);
4214
- const managed = this.clients.get(key);
4211
+ invalidateClient(root, server, client) {
4212
+ const managed = this.clients.get(lspClientKey(root, server));
4215
4213
  if (!managed)
4216
4214
  return;
4217
4215
  if (client && managed.client !== client)
4218
4216
  return;
4219
- this.clients.delete(key);
4220
- this.tombstoneStop(key, managed.client);
4217
+ this.discard(managed);
4221
4218
  }
4222
4219
  warmupClient(root, server) {
4223
4220
  if (this.disposed)
4224
4221
  return;
4225
- const key = this.getKey(root, server.id);
4222
+ const key = lspClientKey(root, server);
4226
4223
  if (this.clients.has(key) || this.pendingStops.has(key))
4227
4224
  return;
4228
4225
  this.evictForAdmission();
@@ -4231,45 +4228,18 @@ class LspManager {
4231
4228
  } catch {
4232
4229
  return;
4233
4230
  }
4234
- const client = this.clientFactory(root, server);
4235
- const initStartedAt = this.now();
4236
- const initPromise = (async () => {
4237
- await client.start();
4238
- await client.initialize();
4239
- })();
4240
- const managed = {
4241
- client,
4242
- refCount: 0,
4243
- pendingWaiters: 0,
4244
- lastUsedAt: initStartedAt,
4245
- initPromise,
4246
- isInitializing: true,
4247
- initializingSince: initStartedAt
4248
- };
4249
- this.clients.set(key, managed);
4250
- initPromise.then(() => {
4251
- managed.isInitializing = false;
4252
- managed.initializingSince = null;
4253
- managed.initPromise = null;
4254
- managed.lastUsedAt = this.now();
4255
- }, () => {
4256
- if (this.clients.get(key) === managed) {
4257
- this.clients.delete(key);
4258
- }
4259
- this.tombstoneStop(key, client);
4260
- });
4231
+ this.startClient(key, root, server, false);
4261
4232
  }
4262
- isServerInitializing(root, serverId) {
4263
- const managed = this.clients.get(this.getKey(root, serverId));
4233
+ isServerInitializing(root, server) {
4234
+ const managed = this.clients.get(lspClientKey(root, server));
4264
4235
  return managed?.isInitializing ?? false;
4265
4236
  }
4266
4237
  getSnapshot() {
4267
4238
  const snapshots = [];
4268
- for (const [key, managed] of this.clients) {
4269
- const [root, serverId] = key.split("::");
4239
+ for (const managed of this.clients.values()) {
4270
4240
  snapshots.push({
4271
- root,
4272
- serverId,
4241
+ root: managed.root,
4242
+ serverId: managed.serverId,
4273
4243
  refCount: managed.refCount,
4274
4244
  pendingWaiters: managed.pendingWaiters,
4275
4245
  lastUsedAt: managed.lastUsedAt,
@@ -4280,18 +4250,15 @@ class LspManager {
4280
4250
  }
4281
4251
  return snapshots;
4282
4252
  }
4283
- hasClient(root, serverId) {
4284
- return this.clients.has(this.getKey(root, serverId));
4253
+ hasClient(root, server) {
4254
+ return this.clients.has(lspClientKey(root, server));
4285
4255
  }
4286
4256
  clientCount() {
4287
4257
  return this.clients.size;
4288
4258
  }
4289
4259
  async stopAll() {
4290
4260
  this.disposed = true;
4291
- if (this.reaperHandle) {
4292
- clearInterval(this.reaperHandle);
4293
- this.reaperHandle = null;
4294
- }
4261
+ this.stopReaper();
4295
4262
  if (this.signalDisposer) {
4296
4263
  this.signalDisposer();
4297
4264
  this.signalDisposer = null;
@@ -4660,6 +4627,7 @@ function getMergedServers() {
4660
4627
  extensions: config.extensions,
4661
4628
  priority: -100,
4662
4629
  source: "builtin",
4630
+ inheritsBuiltinCommand: true,
4663
4631
  ...config.initialization === undefined ? {} : { initialization: config.initialization }
4664
4632
  });
4665
4633
  }
@@ -4685,8 +4653,11 @@ function createServerFromEntry(id, entry, source) {
4685
4653
  command: builtin.command,
4686
4654
  extensions: entry.extensions ?? builtin.extensions,
4687
4655
  priority: entry.priority ?? 0,
4688
- source
4656
+ source,
4657
+ inheritsBuiltinCommand: true
4689
4658
  });
4659
+ if (entry.initialization !== undefined)
4660
+ server.configuredInitialization = entry.initialization;
4690
4661
  const initialization = mergeInitialization(builtin.initialization, entry.initialization);
4691
4662
  if (initialization !== undefined) {
4692
4663
  server.initialization = initialization;
@@ -4699,7 +4670,8 @@ function createServerFromEntry(id, entry, source) {
4699
4670
  command: entry.command,
4700
4671
  extensions: entry.extensions,
4701
4672
  priority: entry.priority ?? 0,
4702
- source
4673
+ source,
4674
+ inheritsBuiltinCommand: false
4703
4675
  });
4704
4676
  applyOptionalServerFields(server, entry);
4705
4677
  return server;
@@ -4711,7 +4683,8 @@ function createServerFromEntry(id, entry, source) {
4711
4683
  command: entry.command ?? builtin.command,
4712
4684
  extensions: entry.extensions ?? builtin.extensions,
4713
4685
  priority: entry.priority ?? 0,
4714
- source
4686
+ source,
4687
+ inheritsBuiltinCommand: entry.command === undefined
4715
4688
  });
4716
4689
  applyOptionalServerFields(server, entry);
4717
4690
  const builtinInitialization = entry.command === undefined ? builtin.initialization : undefined;
@@ -4734,7 +4707,8 @@ function createServer(input) {
4734
4707
  command: input.command,
4735
4708
  extensions: input.extensions,
4736
4709
  priority: input.priority,
4737
- source: input.source
4710
+ source: input.source,
4711
+ inheritsBuiltinCommand: input.inheritsBuiltinCommand
4738
4712
  };
4739
4713
  if (input.env !== undefined) {
4740
4714
  server.env = input.env;
@@ -4750,6 +4724,7 @@ function applyOptionalServerFields(server, entry) {
4750
4724
  }
4751
4725
  if (entry.initialization !== undefined) {
4752
4726
  server.initialization = entry.initialization;
4727
+ server.configuredInitialization = entry.initialization;
4753
4728
  }
4754
4729
  }
4755
4730
  function isConfigJson(value) {
@@ -4841,14 +4816,24 @@ function readHead(path) {
4841
4816
  }
4842
4817
  }
4843
4818
 
4819
+ // ../lsp-core/src/lsp/native-typescript.ts
4820
+ import { existsSync as existsSync11, realpathSync as realpathSync6, statSync as statSync4 } from "node:fs";
4821
+ import { dirname as dirname10, join as join5, resolve as resolve8 } from "node:path";
4822
+
4844
4823
  // ../lsp-core/src/lsp/server-installation.ts
4845
4824
  import { existsSync as existsSync10 } from "node:fs";
4846
4825
  import { delimiter as delimiter3, dirname as dirname9, isAbsolute as isAbsolute5, join as join4, resolve as resolve7 } from "node:path";
4826
+ var NODE_PROJECT_MARKERS = [
4827
+ "package.json",
4828
+ "bun.lock",
4829
+ "bun.lockb",
4830
+ "package-lock.json",
4831
+ "yarn.lock",
4832
+ "pnpm-lock.yaml"
4833
+ ];
4834
+ var NODE_LOCAL_BIN_DIR = join4("node_modules", ".bin");
4847
4835
  var LOCAL_BIN_RULES = [
4848
- {
4849
- markers: ["package.json", "bun.lock", "bun.lockb", "package-lock.json", "yarn.lock", "pnpm-lock.yaml"],
4850
- binDirs: [join4("node_modules", ".bin")]
4851
- },
4836
+ { markers: NODE_PROJECT_MARKERS, binDirs: [NODE_LOCAL_BIN_DIR] },
4852
4837
  {
4853
4838
  markers: [
4854
4839
  "pyproject.toml",
@@ -4976,6 +4961,57 @@ function isServerInstalled(command, workingDirectory, options = {}) {
4976
4961
  return resolveServerBinary(command, workingDirectory, options) !== null;
4977
4962
  }
4978
4963
 
4964
+ // ../lsp-core/src/lsp/native-typescript.ts
4965
+ function nativeTypescriptSearchDirectory(targetPath, workingDirectory) {
4966
+ try {
4967
+ const session = realpathSync6(workingDirectory);
4968
+ if (targetPath === undefined)
4969
+ return session;
4970
+ const target = canonicalizeExistingOrNearestAncestor(resolve8(workingDirectory, targetPath));
4971
+ if (!isPathInside(session, target))
4972
+ return session;
4973
+ return statSync4(target, { throwIfNoEntry: false })?.isDirectory() === true ? target : dirname10(target);
4974
+ } catch {
4975
+ return workingDirectory;
4976
+ }
4977
+ }
4978
+ function nativeTypescriptCommand(server, searchDirectory) {
4979
+ if (server.id !== "typescript" || !server.inheritsBuiltinCommand)
4980
+ return null;
4981
+ const found = findProjectTsc(searchDirectory);
4982
+ if (found === null)
4983
+ return null;
4984
+ const speaksLsp = !existsSync11(join5(found.packageDir, "lib", "tsserver.js"));
4985
+ return speaksLsp ? [found.tsc, "--lsp", "--stdio"] : null;
4986
+ }
4987
+ function findProjectTsc(searchDirectory) {
4988
+ const suffixes = executableSuffixes(process.platform, undefined);
4989
+ let current = searchDirectory;
4990
+ for (;; ) {
4991
+ if (NODE_PROJECT_MARKERS.some((marker) => probe(join5(current, marker)))) {
4992
+ const binDir = join5(current, NODE_LOCAL_BIN_DIR);
4993
+ const tsc = probeWithSuffixes(binDir, "tsc", suffixes);
4994
+ const packageDir = join5(binDir, "..", "typescript");
4995
+ if (tsc !== null && isRealDirectory(binDir) && existsSync11(join5(packageDir, "package.json"))) {
4996
+ return { tsc, packageDir };
4997
+ }
4998
+ }
4999
+ if (probe(join5(current, ".git")))
5000
+ return null;
5001
+ const parent = dirname10(current);
5002
+ if (parent === current)
5003
+ return null;
5004
+ current = parent;
5005
+ }
5006
+ }
5007
+ function isRealDirectory(directory) {
5008
+ try {
5009
+ return realpathSync6(directory) === directory;
5010
+ } catch {
5011
+ return false;
5012
+ }
5013
+ }
5014
+
4979
5015
  // ../lsp-core/src/lsp/server-resolution.ts
4980
5016
  function withResolvedCommand(command, binaryPath) {
4981
5017
  return [binaryPath, ...command.slice(1)];
@@ -4984,12 +5020,27 @@ function usesBuiltinCommand(id, command) {
4984
5020
  const builtin = BUILTIN_SERVERS[id]?.command;
4985
5021
  return builtin !== undefined && builtin.length === command.length && builtin.every((part, index) => part === command[index]);
4986
5022
  }
4987
- function findServerForExtension(ext) {
5023
+ function findServerForExtension(ext, targetPath) {
4988
5024
  const servers = getMergedServers();
4989
5025
  const workingDirectory = contextCwd();
5026
+ const searchDirectory = nativeTypescriptSearchDirectory(targetPath, workingDirectory);
4990
5027
  for (const server of servers) {
4991
5028
  if (!server.extensions.includes(ext))
4992
5029
  continue;
5030
+ const nativeTypescript = nativeTypescriptCommand(server, searchDirectory);
5031
+ if (nativeTypescript !== null) {
5032
+ return {
5033
+ status: "found",
5034
+ server: {
5035
+ id: server.id,
5036
+ command: withHostJsRuntime(server.id, nativeTypescript),
5037
+ extensions: server.extensions,
5038
+ priority: server.priority,
5039
+ ...server.env === undefined ? {} : { env: server.env },
5040
+ ...server.configuredInitialization === undefined ? {} : { initialization: server.configuredInitialization }
5041
+ }
5042
+ };
5043
+ }
4993
5044
  const binaryPath = resolveServerBinary(server.command, workingDirectory);
4994
5045
  if (binaryPath !== null) {
4995
5046
  const resolvedServer = {
@@ -5042,6 +5093,7 @@ function getAllServers() {
5042
5093
  const servers = getMergedServers();
5043
5094
  const disabled = getDisabledServerIds();
5044
5095
  const workingDirectory = contextCwd();
5096
+ const nativeSearchDirectory = nativeTypescriptSearchDirectory(undefined, workingDirectory);
5045
5097
  const result = [];
5046
5098
  const seen = new Set;
5047
5099
  for (const server of servers) {
@@ -5049,7 +5101,7 @@ function getAllServers() {
5049
5101
  continue;
5050
5102
  result.push({
5051
5103
  id: server.id,
5052
- installed: isServerInstalled(server.command, workingDirectory),
5104
+ installed: isServerInstalled(server.command, workingDirectory) || nativeTypescriptCommand(server, nativeSearchDirectory) !== null,
5053
5105
  extensions: server.extensions,
5054
5106
  disabled: false,
5055
5107
  source: server.source,
@@ -5076,7 +5128,7 @@ function getAllServers() {
5076
5128
  // ../lsp-core/src/lsp/client-wrapper.ts
5077
5129
  function isDirectoryPath(filePath) {
5078
5130
  try {
5079
- return statSync4(filePath).isDirectory();
5131
+ return statSync5(filePath).isDirectory();
5080
5132
  } catch {
5081
5133
  return false;
5082
5134
  }
@@ -5086,7 +5138,7 @@ function findWorkspaceRoot(filePath) {
5086
5138
  const abs = resolveReadablePathInsideContext(filePath);
5087
5139
  let dir = abs;
5088
5140
  if (!isDirectoryPath(dir)) {
5089
- dir = dirname10(dir);
5141
+ dir = dirname11(dir);
5090
5142
  }
5091
5143
  if (!isPathInside(cwd, abs))
5092
5144
  return findWorkspaceRootOutsideContext(dir);
@@ -5095,7 +5147,7 @@ function findWorkspaceRoot(filePath) {
5095
5147
  while (isPathInside(cwd, dir)) {
5096
5148
  const canonicalDir = existingDirectoryInsideContext(dir, cwd);
5097
5149
  if (canonicalDir !== undefined) {
5098
- if (existsSync11(join5(dir, GIT_WORKSPACE_MARKER))) {
5150
+ if (existsSync12(join6(dir, GIT_WORKSPACE_MARKER))) {
5099
5151
  return canonicalDir;
5100
5152
  }
5101
5153
  if (nearestPackageRoot === undefined && hasProjectWorkspaceMarker(dir)) {
@@ -5104,16 +5156,16 @@ function findWorkspaceRoot(filePath) {
5104
5156
  }
5105
5157
  if (dir === cwd)
5106
5158
  break;
5107
- dir = dirname10(dir);
5159
+ dir = dirname11(dir);
5108
5160
  }
5109
5161
  return nearestPackageRoot ?? fallbackRoot;
5110
5162
  }
5111
5163
  function hasProjectWorkspaceMarker(directory) {
5112
- return PROJECT_WORKSPACE_MARKERS.some((marker) => existsSync11(join5(directory, marker)));
5164
+ return PROJECT_WORKSPACE_MARKERS.some((marker) => existsSync12(join6(directory, marker)));
5113
5165
  }
5114
5166
  function resolveReadablePathInsideContext(filePath) {
5115
5167
  const cwd = contextCwd();
5116
- const abs = resolve8(cwd, filePath);
5168
+ const abs = resolve9(cwd, filePath);
5117
5169
  if (isPathInside(cwd, abs))
5118
5170
  return abs;
5119
5171
  const rebased = rebaseThroughCanonicalAncestor(abs, cwd);
@@ -5134,12 +5186,12 @@ function rebaseThroughCanonicalAncestor(path, cwd) {
5134
5186
  let current = path;
5135
5187
  const suffix = [];
5136
5188
  while (true) {
5137
- if (existsSync11(current)) {
5138
- const canonical = realpathSync6(current);
5189
+ if (existsSync12(current)) {
5190
+ const canonical = realpathSync7(current);
5139
5191
  if (isPathInside(cwd, canonical))
5140
- return suffix.length === 0 ? canonical : join5(canonical, ...suffix);
5192
+ return suffix.length === 0 ? canonical : join6(canonical, ...suffix);
5141
5193
  }
5142
- const parent = dirname10(current);
5194
+ const parent = dirname11(current);
5143
5195
  if (parent === current)
5144
5196
  return;
5145
5197
  suffix.unshift(basename3(current));
@@ -5147,10 +5199,10 @@ function rebaseThroughCanonicalAncestor(path, cwd) {
5147
5199
  }
5148
5200
  }
5149
5201
  function existingDirectoryInsideContext(directory, cwd) {
5150
- if (!existsSync11(directory))
5202
+ if (!existsSync12(directory))
5151
5203
  return;
5152
- const canonical = realpathSync6(directory);
5153
- if (!statSync4(canonical).isDirectory())
5204
+ const canonical = realpathSync7(directory);
5205
+ if (!statSync5(canonical).isDirectory())
5154
5206
  return;
5155
5207
  return isPathInside(cwd, canonical) ? canonical : undefined;
5156
5208
  }
@@ -5162,7 +5214,7 @@ function nearestExistingDirectoryInsideContext(directory, cwd) {
5162
5214
  return canonical;
5163
5215
  if (current === cwd)
5164
5216
  return;
5165
- current = dirname10(current);
5217
+ current = dirname11(current);
5166
5218
  }
5167
5219
  return;
5168
5220
  }
@@ -5262,7 +5314,7 @@ async function withLspClient(filePath, fn, toolName, options = {}) {
5262
5314
  throw new LspInvalidPathError("Directory paths are not supported by this LSP tool. " + "Use lsp.diagnostics with a directory path for directory diagnostics.");
5263
5315
  }
5264
5316
  const ext = effectiveExtension(absPath);
5265
- const result = findServerForExtension(ext);
5317
+ const result = findServerForExtension(ext, absPath);
5266
5318
  if (result.status !== "found") {
5267
5319
  throw new LspServerLookupError(formatServerLookupError(result), result);
5268
5320
  }
@@ -5275,25 +5327,153 @@ async function withLspClient(filePath, fn, toolName, options = {}) {
5275
5327
  return await fn(client, root, absPath);
5276
5328
  } catch (err) {
5277
5329
  if (allowRetry && READ_ONLY_TOOLS.has(toolName) && isLspDeadConnectionError(err)) {
5278
- manager.invalidateClient(root, server.id, client);
5330
+ manager.invalidateClient(root, server, client);
5279
5331
  return acquireAndCall(false);
5280
5332
  }
5281
5333
  if (err instanceof LspRequestTimeoutError) {
5282
- if (manager.isServerInitializing(root, server.id)) {
5334
+ if (manager.isServerInitializing(root, server)) {
5283
5335
  throw new LspServerInitializingError(err);
5284
5336
  }
5285
5337
  }
5286
5338
  throw err;
5287
5339
  } finally {
5288
- manager.releaseClient(root, server.id);
5340
+ manager.releaseClient(root, server, client);
5289
5341
  }
5290
5342
  };
5291
5343
  return acquireAndCall(true);
5292
5344
  }
5293
5345
 
5294
5346
  // ../lsp-core/src/lsp/directory-diagnostics.ts
5295
- import { existsSync as existsSync12, lstatSync as lstatSync5, readdirSync as readdirSync3 } from "node:fs";
5296
- import { join as join6, resolve as resolve9 } from "node:path";
5347
+ import { existsSync as existsSync13, lstatSync as lstatSync5, readdirSync as readdirSync3 } from "node:fs";
5348
+ import { join as join7, resolve as resolve10 } from "node:path";
5349
+
5350
+ // ../lsp-core/src/lsp/directory-group-scan.ts
5351
+ async function scanServedGroups(options) {
5352
+ const { groups, signal } = options;
5353
+ const limit = Math.max(1, options.maxConcurrency);
5354
+ const fileSlots = createSlots(limit);
5355
+ let nextGroup = 0;
5356
+ let startedGroups = 0;
5357
+ let firstError;
5358
+ const runners = Array.from({ length: Math.min(limit, groups.length) }, async () => {
5359
+ for (;; ) {
5360
+ if (signal?.aborted)
5361
+ return;
5362
+ const group = groups[nextGroup];
5363
+ nextGroup += 1;
5364
+ if (group === undefined)
5365
+ return;
5366
+ let client;
5367
+ try {
5368
+ client = await acquireWithinInitTimeout(options, group);
5369
+ } catch (error) {
5370
+ if (signal?.aborted)
5371
+ return;
5372
+ firstError ??= error;
5373
+ options.onGroupUnavailable(group, error instanceof Error ? error.message : String(error));
5374
+ continue;
5375
+ }
5376
+ startedGroups += 1;
5377
+ try {
5378
+ await Promise.all(group.files.map(async (file) => {
5379
+ const release = await fileSlots.acquire();
5380
+ try {
5381
+ if (!signal?.aborted)
5382
+ await options.checkFile(client, file);
5383
+ } finally {
5384
+ release();
5385
+ }
5386
+ }));
5387
+ } finally {
5388
+ options.manager.releaseClient(group.root, group.server, client);
5389
+ }
5390
+ }
5391
+ });
5392
+ await Promise.all(runners);
5393
+ signal?.throwIfAborted();
5394
+ if (startedGroups === 0 && firstError !== undefined)
5395
+ throw firstError;
5396
+ }
5397
+ async function acquireWithinInitTimeout(options, group) {
5398
+ const { signal } = options;
5399
+ const timers = options.timers ?? realTimerProvider;
5400
+ const controller = new AbortController;
5401
+ const forwardAbort = () => controller.abort(signal?.reason);
5402
+ signal?.addEventListener("abort", forwardAbort, { once: true });
5403
+ if (signal?.aborted)
5404
+ forwardAbort();
5405
+ let timedOut = false;
5406
+ const timer = timers.setTimeout(() => {
5407
+ timedOut = true;
5408
+ controller.abort();
5409
+ }, INIT_TIMEOUT_MS);
5410
+ try {
5411
+ return await options.manager.getClient(group.root, group.server, controller.signal);
5412
+ } catch (error) {
5413
+ if (timedOut && signal?.aborted !== true) {
5414
+ throw new Error(`${group.server.id} did not start within ${INIT_TIMEOUT_MS}ms`);
5415
+ }
5416
+ throw error;
5417
+ } finally {
5418
+ timers.clearTimeout(timer);
5419
+ signal?.removeEventListener("abort", forwardAbort);
5420
+ }
5421
+ }
5422
+ function createSlots(limit) {
5423
+ let free = limit;
5424
+ const waiting = [];
5425
+ const release = () => {
5426
+ const next = waiting.shift();
5427
+ if (next === undefined)
5428
+ free += 1;
5429
+ else
5430
+ next();
5431
+ };
5432
+ return {
5433
+ acquire() {
5434
+ if (free > 0) {
5435
+ free -= 1;
5436
+ return Promise.resolve(release);
5437
+ }
5438
+ return new Promise((resolve) => waiting.push(() => resolve(release)));
5439
+ }
5440
+ };
5441
+ }
5442
+
5443
+ // ../lsp-core/src/lsp/directory-server-groups.ts
5444
+ import { dirname as dirname12 } from "node:path";
5445
+ function groupFilesByClient(files, extension, fixed = {}) {
5446
+ const byDirectory = new Map;
5447
+ const served = new Map;
5448
+ const unserved = new Map;
5449
+ for (const file of files) {
5450
+ const directory = dirname12(file);
5451
+ let resolution = byDirectory.get(directory);
5452
+ if (resolution === undefined) {
5453
+ resolution = resolveDirectory(directory, extension, fixed);
5454
+ byDirectory.set(directory, resolution);
5455
+ }
5456
+ if (resolution.kind === "served") {
5457
+ const group = served.get(resolution.key) ?? { root: resolution.root, server: resolution.server, files: [] };
5458
+ group.files.push(file);
5459
+ served.set(resolution.key, group);
5460
+ } else {
5461
+ const group = unserved.get(resolution.key) ?? { lookup: resolution.lookup, files: [] };
5462
+ group.files.push(file);
5463
+ unserved.set(resolution.key, group);
5464
+ }
5465
+ }
5466
+ return { served: [...served.values()], unserved: [...unserved.values()] };
5467
+ }
5468
+ function resolveDirectory(directory, extension, fixed) {
5469
+ const lookup = fixed.server === undefined ? findServerForExtension(extension, directory) : { status: "found", server: fixed.server };
5470
+ if (lookup.status !== "found") {
5471
+ const serverId = lookup.status === "not_installed" ? lookup.server.id : "";
5472
+ return { kind: "unserved", key: JSON.stringify([lookup.status, serverId]), lookup };
5473
+ }
5474
+ const root = fixed.workspaceRoot ?? findWorkspaceRoot(directory);
5475
+ return { kind: "served", key: lspClientKey(root, lookup.server), root, server: lookup.server };
5476
+ }
5297
5477
 
5298
5478
  // ../lsp-core/src/lsp/formatters.ts
5299
5479
  import { fileURLToPath as fileURLToPath3 } from "node:url";
@@ -5423,7 +5603,7 @@ function collectFilesWithExtension(dir, extension, maxFiles) {
5423
5603
  for (const entry of entries) {
5424
5604
  if (files.length >= maxFiles)
5425
5605
  return;
5426
- const fullPath = join6(currentDir, entry);
5606
+ const fullPath = join7(currentDir, entry);
5427
5607
  let stat;
5428
5608
  try {
5429
5609
  stat = lstatSync5(fullPath);
@@ -5448,15 +5628,10 @@ async function aggregateDiagnosticsForDirectory(directory, extension, severity,
5448
5628
  if (!extension.startsWith(".")) {
5449
5629
  throw new LspInvalidPathError(`Extension must start with a dot (e.g., ".ts", not "${extension}"). Use ".${extension}" instead.`);
5450
5630
  }
5451
- const absDir = resolve9(options.workspaceRoot ?? contextCwd(), directory);
5452
- if (!existsSync12(absDir)) {
5631
+ const absDir = resolve10(options.workspaceRoot ?? contextCwd(), directory);
5632
+ if (!existsSync13(absDir)) {
5453
5633
  throw new LspInvalidPathError(`Directory does not exist: ${absDir}`);
5454
5634
  }
5455
- const serverResult = options.server === undefined ? findServerForExtension(extension) : { status: "found", server: options.server };
5456
- if (serverResult.status !== "found") {
5457
- throw new LspServerLookupError(formatServerLookupError(serverResult));
5458
- }
5459
- const server = serverResult.server;
5460
5635
  const allFiles = (options.listFiles ?? collectFilesWithExtension)(absDir, extension, maxFiles + 1);
5461
5636
  const wasCapped = allFiles.length > maxFiles;
5462
5637
  const filesToProcess = allFiles.slice(0, maxFiles);
@@ -5470,42 +5645,43 @@ async function aggregateDiagnosticsForDirectory(directory, extension, severity,
5470
5645
  `);
5471
5646
  return { output, totalDiagnostics: 0, fileFailures: [] };
5472
5647
  }
5473
- const root = options.workspaceRoot ?? findWorkspaceRoot(absDir);
5648
+ const groups = groupFilesByClient(filesToProcess, extension, {
5649
+ ...options.server === undefined ? {} : { server: options.server },
5650
+ ...options.workspaceRoot === undefined ? {} : { workspaceRoot: options.workspaceRoot }
5651
+ });
5652
+ const firstUnserved = groups.unserved[0];
5653
+ if (groups.served.length === 0 && firstUnserved !== undefined) {
5654
+ throw new LspServerLookupError(formatServerLookupError(firstUnserved.lookup));
5655
+ }
5474
5656
  const manager = options.manager ?? getLspManager();
5475
5657
  const allDiagnostics = [];
5476
5658
  const fileErrors = [];
5477
5659
  const maxConcurrency = Math.max(1, options.maxConcurrency ?? DIRECTORY_DIAGNOSTICS_MAX_CONCURRENCY);
5660
+ for (const group of groups.unserved) {
5661
+ const error = formatServerLookupError(group.lookup).split(`
5662
+ `)[0] ?? "No LSP server";
5663
+ fileErrors.push(...group.files.map((file) => ({ file, error })));
5664
+ }
5478
5665
  options.signal?.throwIfAborted();
5479
- const client = await manager.getClient(root, server, options.signal);
5480
- try {
5481
- let nextIndex = 0;
5482
- const workers = Array.from({ length: Math.min(maxConcurrency, filesToProcess.length) }, async () => {
5483
- for (;; ) {
5484
- if (options.signal?.aborted)
5485
- return;
5486
- const file = filesToProcess[nextIndex];
5487
- nextIndex += 1;
5488
- if (file === undefined)
5489
- return;
5490
- try {
5491
- const result = await client.diagnostics(file, options.signal);
5492
- const filtered = filterDiagnosticsBySeverity(result.items, severity);
5493
- allDiagnostics.push(...filtered.map((diagnostic) => ({
5494
- filePath: file,
5495
- diagnostic
5496
- })));
5497
- } catch (e) {
5498
- fileErrors.push({
5499
- file,
5500
- error: e instanceof Error ? e.message : String(e)
5501
- });
5502
- }
5666
+ await scanServedGroups({
5667
+ manager,
5668
+ groups: groups.served,
5669
+ maxConcurrency,
5670
+ ...options.signal === undefined ? {} : { signal: options.signal },
5671
+ ...options.timers === undefined ? {} : { timers: options.timers },
5672
+ onGroupUnavailable: (group, error) => {
5673
+ fileErrors.push(...group.files.map((file) => ({ file, error })));
5674
+ },
5675
+ checkFile: async (client, file) => {
5676
+ try {
5677
+ const result = await client.diagnostics(file, options.signal);
5678
+ const filtered = filterDiagnosticsBySeverity(result.items, severity);
5679
+ allDiagnostics.push(...filtered.map((diagnostic) => ({ filePath: file, diagnostic })));
5680
+ } catch (e) {
5681
+ fileErrors.push({ file, error: e instanceof Error ? e.message : String(e) });
5503
5682
  }
5504
- });
5505
- await Promise.all(workers);
5506
- } finally {
5507
- manager.releaseClient(root, server.id);
5508
- }
5683
+ }
5684
+ });
5509
5685
  const displayDiagnostics = allDiagnostics.slice(0, DEFAULT_MAX_DIAGNOSTICS);
5510
5686
  const wasDiagCapped = allDiagnostics.length > DEFAULT_MAX_DIAGNOSTICS;
5511
5687
  const lines = [
@@ -5536,7 +5712,7 @@ async function aggregateDiagnosticsForDirectory(directory, extension, severity,
5536
5712
 
5537
5713
  // ../lsp-core/src/lsp/infer-extension.ts
5538
5714
  import { lstatSync as lstatSync6, readdirSync as readdirSync4 } from "node:fs";
5539
- import { join as join7 } from "node:path";
5715
+ import { join as join8 } from "node:path";
5540
5716
  var SKIP_DIRECTORIES2 = new Set(["node_modules", ".git", "dist", "build", ".next", "out"]);
5541
5717
  var MAX_SCAN_ENTRIES = 500;
5542
5718
  function inferExtensionFromDirectory(directory) {
@@ -5554,7 +5730,7 @@ function inferExtensionFromDirectory(directory) {
5554
5730
  for (const entry of entries) {
5555
5731
  if (scanned >= MAX_SCAN_ENTRIES)
5556
5732
  return;
5557
- const fullPath = join7(dir, entry);
5733
+ const fullPath = join8(dir, entry);
5558
5734
  let stat;
5559
5735
  try {
5560
5736
  stat = lstatSync6(fullPath);
@@ -5673,7 +5849,7 @@ function missingDependencyAvailability(error) {
5673
5849
  }
5674
5850
 
5675
5851
  // ../lsp-core/src/lsp/bun-command-output.ts
5676
- import { resolve as resolve10 } from "node:path";
5852
+ import { resolve as resolve11 } from "node:path";
5677
5853
  var TSC_LINE = /^(.+?)\((\d+),(\d+)\): (error|warning|message) (TS\d+): (.*)$/;
5678
5854
  var TSC_SEVERITY = { error: 1, warning: 2, message: 3 };
5679
5855
  function parseBunCheckOutput(stdout, cwd) {
@@ -5684,7 +5860,7 @@ function parseBunCheckOutput(stdout, cwd) {
5684
5860
  const [, path, lineNumber, column, severity, code, message] = match;
5685
5861
  const start = { line: Number(lineNumber) - 1, character: Number(column) - 1 };
5686
5862
  results.push({
5687
- file: resolve10(cwd, path ?? ""),
5863
+ file: resolve11(cwd, path ?? ""),
5688
5864
  diagnostic: {
5689
5865
  range: { start, end: start },
5690
5866
  severity: TSC_SEVERITY[severity ?? "error"] ?? 1,
@@ -5743,9 +5919,9 @@ function parseBunLintJson(stdout) {
5743
5919
 
5744
5920
  // ../lsp-core/src/lsp/bun-project-checks.ts
5745
5921
  import { spawn as spawn3 } from "node:child_process";
5746
- import { existsSync as existsSync13, mkdtempSync, readFileSync as readFileSync6, rmSync as rmSync2, statSync as statSync5, writeFileSync as writeFileSync3 } from "node:fs";
5922
+ import { existsSync as existsSync14, mkdtempSync, readFileSync as readFileSync6, rmSync as rmSync2, statSync as statSync6, writeFileSync as writeFileSync3 } from "node:fs";
5747
5923
  import { homedir as homedir3, tmpdir as tmpdir2 } from "node:os";
5748
- import { dirname as dirname11, join as join8, resolve as resolve11 } from "node:path";
5924
+ import { dirname as dirname13, join as join9, resolve as resolve12 } from "node:path";
5749
5925
  var BUN_LOCKFILES = ["bun.lock", "bun.lockb", "bunfig.toml"];
5750
5926
  var RUNNABLE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".cts", ".cjs", ".js", ".mjs", ".mts"];
5751
5927
  var BIN_SUFFIXES = process.platform === "win32" ? [".exe", ".bunx", ".cmd", ""] : [""];
@@ -5754,18 +5930,18 @@ var UNFORMATTED_PROBE = `const a=1
5754
5930
  `;
5755
5931
  var probeCache = new Map;
5756
5932
  function findBunProjectRoot(start, home = homedir3()) {
5757
- const stopAt = resolve11(home);
5758
- let dir = resolve11(start);
5933
+ const stopAt = resolve12(home);
5934
+ let dir = resolve12(start);
5759
5935
  for (;; ) {
5760
5936
  if (dir === stopAt)
5761
5937
  return;
5762
- if (BUN_LOCKFILES.some((name) => existsSync13(join8(dir, name))))
5938
+ if (BUN_LOCKFILES.some((name) => existsSync14(join9(dir, name))))
5763
5939
  return dir;
5764
- if (packageManagerIsBun(join8(dir, "package.json")))
5940
+ if (packageManagerIsBun(join9(dir, "package.json")))
5765
5941
  return dir;
5766
- if (existsSync13(join8(dir, ".git")))
5942
+ if (existsSync14(join9(dir, ".git")))
5767
5943
  return;
5768
- const parent = dirname11(dir);
5944
+ const parent = dirname13(dir);
5769
5945
  if (parent === dir)
5770
5946
  return;
5771
5947
  dir = parent;
@@ -5777,7 +5953,7 @@ function packageManagerIsBun(packageJsonPath) {
5777
5953
  return typeof packageManager === "string" && packageManager.startsWith("bun@");
5778
5954
  }
5779
5955
  function readJsonObject(path) {
5780
- if (!existsSync13(path))
5956
+ if (!existsSync14(path))
5781
5957
  return;
5782
5958
  try {
5783
5959
  const parsed = JSON.parse(readFileSync6(path, "utf8"));
@@ -5788,14 +5964,14 @@ function readJsonObject(path) {
5788
5964
  }
5789
5965
  function isFile(path) {
5790
5966
  try {
5791
- return statSync5(path).isFile();
5967
+ return statSync6(path).isFile();
5792
5968
  } catch {
5793
5969
  return false;
5794
5970
  }
5795
5971
  }
5796
5972
  function isDirectory(path) {
5797
5973
  try {
5798
- return statSync5(path).isDirectory();
5974
+ return statSync6(path).isDirectory();
5799
5975
  } catch {
5800
5976
  return false;
5801
5977
  }
@@ -5803,35 +5979,35 @@ function isDirectory(path) {
5803
5979
  function projectShadowsBunCommand(command, cwd) {
5804
5980
  const packageJsonDir = nearestPackageJsonDir(cwd);
5805
5981
  if (packageJsonDir !== undefined) {
5806
- const scripts = readJsonObject(join8(packageJsonDir, "package.json"))?.["scripts"];
5982
+ const scripts = readJsonObject(join9(packageJsonDir, "package.json"))?.["scripts"];
5807
5983
  if (scripts !== null && typeof scripts === "object" && typeof scripts[command] === "string") {
5808
5984
  return true;
5809
5985
  }
5810
5986
  }
5811
5987
  if (command === "check")
5812
5988
  return false;
5813
- const base = join8(cwd, command);
5989
+ const base = join9(cwd, command);
5814
5990
  if (isFile(base) || RUNNABLE_EXTENSIONS.some((extension) => isFile(`${base}${extension}`)))
5815
5991
  return true;
5816
- if (isDirectory(base) && (isFile(join8(base, "package.json")) || RUNNABLE_EXTENSIONS.some((extension) => isFile(join8(base, `index${extension}`))))) {
5992
+ if (isDirectory(base) && (isFile(join9(base, "package.json")) || RUNNABLE_EXTENSIONS.some((extension) => isFile(join9(base, `index${extension}`))))) {
5817
5993
  return true;
5818
5994
  }
5819
- let dir = resolve11(cwd);
5995
+ let dir = resolve12(cwd);
5820
5996
  for (;; ) {
5821
- if (BIN_SUFFIXES.some((suffix) => existsSync13(join8(dir, "node_modules", ".bin", `${command}${suffix}`))))
5997
+ if (BIN_SUFFIXES.some((suffix) => existsSync14(join9(dir, "node_modules", ".bin", `${command}${suffix}`))))
5822
5998
  return true;
5823
- const parent = dirname11(dir);
5999
+ const parent = dirname13(dir);
5824
6000
  if (parent === dir)
5825
6001
  return false;
5826
6002
  dir = parent;
5827
6003
  }
5828
6004
  }
5829
6005
  function nearestPackageJsonDir(start) {
5830
- let dir = resolve11(start);
6006
+ let dir = resolve12(start);
5831
6007
  for (;; ) {
5832
- if (existsSync13(join8(dir, "package.json")))
6008
+ if (existsSync14(join9(dir, "package.json")))
5833
6009
  return dir;
5834
- const parent = dirname11(dir);
6010
+ const parent = dirname13(dir);
5835
6011
  if (parent === dir)
5836
6012
  return;
5837
6013
  dir = parent;
@@ -5839,7 +6015,7 @@ function nearestPackageJsonDir(start) {
5839
6015
  }
5840
6016
  function binaryIdentity(bunPath) {
5841
6017
  try {
5842
- const stats = statSync5(bunPath);
6018
+ const stats = statSync6(bunPath);
5843
6019
  return `${stats.mtimeMs}:${stats.size}`;
5844
6020
  } catch {
5845
6021
  return "missing";
@@ -5859,7 +6035,7 @@ function bunHasCommand(bunPath, command, timeoutMs = PROBE_TIMEOUT_MS2) {
5859
6035
  return probe;
5860
6036
  }
5861
6037
  async function probeOnce(bunPath, command, timeoutMs) {
5862
- const emptyDir = mkdtempSync(join8(tmpdir2(), "omo-bun-probe-"));
6038
+ const emptyDir = mkdtempSync(join9(tmpdir2(), "omo-bun-probe-"));
5863
6039
  const timeout = AbortSignal.timeout(timeoutMs);
5864
6040
  try {
5865
6041
  const help = await runBunCommand(bunPath, [command, "--help"], emptyDir, timeout);
@@ -5869,7 +6045,7 @@ async function probeOnce(bunPath, command, timeoutMs) {
5869
6045
  return false;
5870
6046
  if (command !== "format")
5871
6047
  return true;
5872
- const probeFile = join8(emptyDir, "probe.ts");
6048
+ const probeFile = join9(emptyDir, "probe.ts");
5873
6049
  writeFileSync3(probeFile, UNFORMATTED_PROBE);
5874
6050
  const write = await runBunCommand(bunPath, ["format", "--write", "probe.ts"], emptyDir, timeout);
5875
6051
  if (write.exitCode === null)
@@ -6814,9 +6990,9 @@ function currentRequestContext(env = process.env) {
6814
6990
  const home = env["HOME"] ?? homedir4();
6815
6991
  return parseLspRequestContext({
6816
6992
  cwd,
6817
- projectConfigPaths: [join9(cwd, ".codex", "lsp-client.json")],
6818
- userConfigPath: join9(home, ".codex", "lsp-client.json"),
6819
- installDecisionsPath: join9(home, ".codex", "lsp-install-decisions.json"),
6993
+ projectConfigPaths: [join10(cwd, ".codex", "lsp-client.json")],
6994
+ userConfigPath: join10(home, ".codex", "lsp-client.json"),
6995
+ installDecisionsPath: join10(home, ".codex", "lsp-install-decisions.json"),
6820
6996
  capabilities: { installDecisionTool: true }
6821
6997
  });
6822
6998
  }
@@ -6985,7 +7161,7 @@ function resolveDaemonRuntime2(env, defaults) {
6985
7161
  if (!isAbsolute6(cliOverride)) {
6986
7162
  throw new InvalidRuntimeOverrideError2("cli_must_be_absolute", `${OMO_LSP_DAEMON_CLI2} must be an absolute path to an existing regular file`);
6987
7163
  }
6988
- const stat = statSync6(cliOverride, { throwIfNoEntry: false });
7164
+ const stat = statSync7(cliOverride, { throwIfNoEntry: false });
6989
7165
  if (!stat) {
6990
7166
  throw new InvalidRuntimeOverrideError2("cli_not_found", `${OMO_LSP_DAEMON_CLI2} points to a missing file`);
6991
7167
  }