@cortexkit/opencode-antigravity-auth 3.0.28 → 3.0.30

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 (179) hide show
  1. package/dist/cli.js +689 -183
  2. package/dist/cli.js.map +4 -4
  3. package/dist/cli.meta.json +131 -68
  4. package/dist/index.js +844 -199
  5. package/dist/index.js.map +4 -4
  6. package/dist/index.meta.json +173 -76
  7. package/dist/server.js +855 -213
  8. package/dist/server.js.map +4 -4
  9. package/dist/server.meta.json +1 -1
  10. package/dist/src/cli.d.ts +1 -0
  11. package/dist/src/cli.d.ts.map +1 -1
  12. package/dist/src/cli.js +22 -2
  13. package/dist/src/cli.js.map +1 -1
  14. package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +12 -0
  15. package/dist/src/common-auth-embedded/claustrum/consumer.js +36 -0
  16. package/dist/src/common-auth-embedded/claustrum/custody.d.ts +16 -4
  17. package/dist/src/common-auth-embedded/claustrum/custody.js +74 -9
  18. package/dist/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
  19. package/dist/src/common-auth-embedded/claustrum/hub.js +8 -0
  20. package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -0
  21. package/dist/src/common-auth-embedded/claustrum/roster.d.ts +2 -0
  22. package/dist/src/common-auth-embedded/claustrum/roster.js +2 -0
  23. package/dist/src/common-auth-embedded/claustrum/usage.d.ts +41 -0
  24. package/dist/src/common-auth-embedded/claustrum/usage.js +145 -0
  25. package/dist/src/common-auth-embedded/commands/builtins.d.ts +5 -0
  26. package/dist/src/common-auth-embedded/commands/builtins.js +38 -0
  27. package/dist/src/common-auth-embedded/fs/private-files.d.ts +5 -0
  28. package/dist/src/common-auth-embedded/fs/private-files.js +7 -0
  29. package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +142 -47
  30. package/dist/src/common-auth-embedded/fs/with-lock.js +2 -5
  31. package/dist/src/common-auth-embedded/limits/activity.d.ts +26 -0
  32. package/dist/src/common-auth-embedded/limits/axes.d.ts +63 -0
  33. package/dist/src/common-auth-embedded/limits/decide.d.ts +141 -0
  34. package/dist/src/common-auth-embedded/limits/duration.d.ts +8 -0
  35. package/dist/src/common-auth-embedded/limits/families.d.ts +57 -0
  36. package/dist/src/common-auth-embedded/limits/marker.d.ts +64 -0
  37. package/dist/src/common-auth-embedded/limits/request-history.d.ts +77 -0
  38. package/dist/src/common-auth-embedded/limits/scope.d.ts +12 -0
  39. package/dist/src/common-auth-embedded/limits/signal.d.ts +41 -0
  40. package/dist/src/common-auth-embedded/limits/terminal.d.ts +52 -0
  41. package/dist/src/common-auth-embedded/limits/wake.d.ts +21 -0
  42. package/dist/src/common-auth-embedded/limits/wording.d.ts +25 -0
  43. package/dist/src/common-auth-embedded/opencode2/index.d.ts +1 -1
  44. package/dist/src/common-auth-embedded/opencode2/install.d.ts +2 -2
  45. package/dist/src/common-auth-embedded/opencode2/install.js +161 -18
  46. package/dist/src/common-auth-embedded/opencode2/types.d.ts +95 -9
  47. package/dist/src/common-auth-embedded/routing/admission.d.ts +7 -2
  48. package/dist/src/common-auth-embedded/routing/admission.js +17 -7
  49. package/dist/src/common-auth-embedded/routing-accessor/handle.js +10 -0
  50. package/dist/src/common-auth-embedded/routing-accessor/index.d.ts +13 -3
  51. package/dist/src/common-auth-embedded/routing-accessor/index.js +11 -10
  52. package/dist/src/common-auth-embedded/rpc/port-file.d.ts +12 -3
  53. package/dist/src/common-auth-embedded/rpc/port-file.js +46 -4
  54. package/dist/src/common-auth-embedded/source-output.json +254 -118
  55. package/dist/src/common-auth-embedded/store/attribution.js +3 -2
  56. package/dist/src/common-auth-embedded/store/errors.d.ts +1 -1
  57. package/dist/src/common-auth-embedded/store/hooks.d.ts +5 -1
  58. package/dist/src/common-auth-embedded/store/hooks.js +20 -5
  59. package/dist/src/common-auth-embedded/store/index.d.ts +1 -0
  60. package/dist/src/common-auth-embedded/store/limits-namespace.d.ts +7 -0
  61. package/dist/src/common-auth-embedded/store/limits-namespace.js +34 -0
  62. package/dist/src/common-auth-embedded/store/pool.d.ts +10 -1
  63. package/dist/src/common-auth-embedded/store/pool.js +2 -0
  64. package/dist/src/common-auth-embedded/store/provider-state.js +5 -5
  65. package/dist/src/common-auth-embedded/store/refresh.js +1 -1
  66. package/dist/src/common-auth-embedded/store/schema.js +9 -4
  67. package/dist/src/common-auth-embedded/store/settings.d.ts +2 -0
  68. package/dist/src/common-auth-embedded/store/settings.js +11 -4
  69. package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
  70. package/dist/src/plugin/shared/request-services.d.ts +14 -18
  71. package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
  72. package/dist/src/plugin/shared/request-services.js +127 -7
  73. package/dist/src/plugin/shared/request-services.js.map +1 -1
  74. package/dist/src/runtime-layout.d.ts +9 -2
  75. package/dist/src/runtime-layout.d.ts.map +1 -1
  76. package/dist/src/runtime-layout.js +8 -8
  77. package/dist/src/runtime-layout.js.map +1 -1
  78. package/dist/src/setup.d.ts.map +1 -1
  79. package/dist/src/setup.js +29 -40
  80. package/dist/src/setup.js.map +1 -1
  81. package/dist/tui-build-map.json +9 -9
  82. package/dist/tui-ga-build-map.json +1 -1
  83. package/dist/types/src/cli.d.ts +1 -0
  84. package/dist/types/src/cli.d.ts.map +1 -1
  85. package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +12 -0
  86. package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +16 -4
  87. package/dist/types/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
  88. package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -0
  89. package/dist/types/src/common-auth-embedded/claustrum/roster.d.ts +2 -0
  90. package/dist/types/src/common-auth-embedded/claustrum/usage.d.ts +41 -0
  91. package/dist/types/src/common-auth-embedded/commands/builtins.d.ts +5 -0
  92. package/dist/types/src/common-auth-embedded/limits/activity.d.ts +26 -0
  93. package/dist/types/src/common-auth-embedded/limits/axes.d.ts +63 -0
  94. package/dist/types/src/common-auth-embedded/limits/decide.d.ts +141 -0
  95. package/dist/types/src/common-auth-embedded/limits/duration.d.ts +8 -0
  96. package/dist/types/src/common-auth-embedded/limits/families.d.ts +57 -0
  97. package/dist/types/src/common-auth-embedded/limits/marker.d.ts +64 -0
  98. package/dist/types/src/common-auth-embedded/limits/request-history.d.ts +77 -0
  99. package/dist/types/src/common-auth-embedded/limits/scope.d.ts +12 -0
  100. package/dist/types/src/common-auth-embedded/limits/signal.d.ts +41 -0
  101. package/dist/types/src/common-auth-embedded/limits/terminal.d.ts +52 -0
  102. package/dist/types/src/common-auth-embedded/limits/wake.d.ts +21 -0
  103. package/dist/types/src/common-auth-embedded/limits/wording.d.ts +25 -0
  104. package/dist/types/src/common-auth-embedded/opencode2/index.d.ts +1 -1
  105. package/dist/types/src/common-auth-embedded/opencode2/install.d.ts +2 -2
  106. package/dist/types/src/common-auth-embedded/opencode2/types.d.ts +95 -9
  107. package/dist/types/src/common-auth-embedded/routing/admission.d.ts +7 -2
  108. package/dist/types/src/common-auth-embedded/routing-accessor/index.d.ts +13 -3
  109. package/dist/types/src/common-auth-embedded/store/errors.d.ts +1 -1
  110. package/dist/types/src/common-auth-embedded/store/hooks.d.ts +5 -1
  111. package/dist/types/src/common-auth-embedded/store/index.d.ts +1 -0
  112. package/dist/types/src/common-auth-embedded/store/limits-namespace.d.ts +7 -0
  113. package/dist/types/src/common-auth-embedded/store/pool.d.ts +10 -1
  114. package/dist/types/src/common-auth-embedded/store/settings.d.ts +2 -0
  115. package/dist/types/src/plugin/shared/request-services.d.ts +14 -18
  116. package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
  117. package/dist/types/src/runtime-layout.d.ts +9 -2
  118. package/dist/types/src/runtime-layout.d.ts.map +1 -1
  119. package/dist/types/src/setup.d.ts.map +1 -1
  120. package/package.json +2 -2
  121. package/src/common-auth-embedded/claustrum/consumer.d.ts +12 -0
  122. package/src/common-auth-embedded/claustrum/consumer.js +36 -0
  123. package/src/common-auth-embedded/claustrum/custody.d.ts +16 -4
  124. package/src/common-auth-embedded/claustrum/custody.js +74 -9
  125. package/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
  126. package/src/common-auth-embedded/claustrum/hub.js +8 -0
  127. package/src/common-auth-embedded/claustrum/index.d.ts +1 -0
  128. package/src/common-auth-embedded/claustrum/roster.d.ts +2 -0
  129. package/src/common-auth-embedded/claustrum/roster.js +2 -0
  130. package/src/common-auth-embedded/claustrum/usage.d.ts +41 -0
  131. package/src/common-auth-embedded/claustrum/usage.js +145 -0
  132. package/src/common-auth-embedded/commands/builtins.d.ts +5 -0
  133. package/src/common-auth-embedded/commands/builtins.js +38 -0
  134. package/src/common-auth-embedded/fs/private-files.d.ts +5 -0
  135. package/src/common-auth-embedded/fs/private-files.js +7 -0
  136. package/src/common-auth-embedded/fs/refresh-file-lock.js +142 -47
  137. package/src/common-auth-embedded/fs/with-lock.js +2 -5
  138. package/src/common-auth-embedded/limits/activity.d.ts +26 -0
  139. package/src/common-auth-embedded/limits/axes.d.ts +63 -0
  140. package/src/common-auth-embedded/limits/decide.d.ts +141 -0
  141. package/src/common-auth-embedded/limits/duration.d.ts +8 -0
  142. package/src/common-auth-embedded/limits/families.d.ts +57 -0
  143. package/src/common-auth-embedded/limits/marker.d.ts +64 -0
  144. package/src/common-auth-embedded/limits/request-history.d.ts +77 -0
  145. package/src/common-auth-embedded/limits/scope.d.ts +12 -0
  146. package/src/common-auth-embedded/limits/signal.d.ts +41 -0
  147. package/src/common-auth-embedded/limits/terminal.d.ts +52 -0
  148. package/src/common-auth-embedded/limits/wake.d.ts +21 -0
  149. package/src/common-auth-embedded/limits/wording.d.ts +25 -0
  150. package/src/common-auth-embedded/opencode2/index.d.ts +1 -1
  151. package/src/common-auth-embedded/opencode2/install.d.ts +2 -2
  152. package/src/common-auth-embedded/opencode2/install.js +161 -18
  153. package/src/common-auth-embedded/opencode2/types.d.ts +95 -9
  154. package/src/common-auth-embedded/routing/admission.d.ts +7 -2
  155. package/src/common-auth-embedded/routing/admission.js +17 -7
  156. package/src/common-auth-embedded/routing-accessor/handle.js +10 -0
  157. package/src/common-auth-embedded/routing-accessor/index.d.ts +13 -3
  158. package/src/common-auth-embedded/routing-accessor/index.js +11 -10
  159. package/src/common-auth-embedded/rpc/port-file.d.ts +12 -3
  160. package/src/common-auth-embedded/rpc/port-file.js +46 -4
  161. package/src/common-auth-embedded/source-output.json +254 -118
  162. package/src/common-auth-embedded/store/attribution.js +3 -2
  163. package/src/common-auth-embedded/store/errors.d.ts +1 -1
  164. package/src/common-auth-embedded/store/hooks.d.ts +5 -1
  165. package/src/common-auth-embedded/store/hooks.js +20 -5
  166. package/src/common-auth-embedded/store/index.d.ts +1 -0
  167. package/src/common-auth-embedded/store/limits-namespace.d.ts +7 -0
  168. package/src/common-auth-embedded/store/limits-namespace.js +34 -0
  169. package/src/common-auth-embedded/store/pool.d.ts +10 -1
  170. package/src/common-auth-embedded/store/pool.js +2 -0
  171. package/src/common-auth-embedded/store/provider-state.js +5 -5
  172. package/src/common-auth-embedded/store/refresh.js +1 -1
  173. package/src/common-auth-embedded/store/schema.js +9 -4
  174. package/src/common-auth-embedded/store/settings.d.ts +2 -0
  175. package/src/common-auth-embedded/store/settings.js +11 -4
  176. package/src/tui-compiled/common-auth-embedded/fs/private-files.js +7 -0
  177. package/src/tui-compiled/common-auth-embedded/rpc/port-file.js +46 -4
  178. package/src/tui-raw/common-auth-embedded/fs/private-files.js +7 -0
  179. package/src/tui-raw/common-auth-embedded/rpc/port-file.js +46 -4
@@ -12,6 +12,14 @@ export interface AskRoutingInput<Candidate extends RoutingCandidate = RoutingCan
12
12
  candidates: readonly Candidate[];
13
13
  /** Defaults to 500 ms, clamped to 1–2000 ms. */
14
14
  deadlineMs?: number;
15
+ /**
16
+ * Longest same-account hold, in seconds, that routing may advise. The
17
+ * holdWaitMaxS helper from `./limits` caps it by the setting and the current
18
+ * account's cache expiry, returning 0 when there is no accepted prompt cache
19
+ * worth waiting for. Fractions are floored and negatives become 0. Omit it to leave
20
+ * routing's default cap in force.
21
+ */
22
+ holdWaitMaxS?: number;
15
23
  }
16
24
  export interface RoutingHold {
17
25
  /** Uncapped advice from routing. The plugin must apply its own hold cap. */
@@ -39,9 +47,11 @@ export type ReportRoutingInput = RoutingReportIdentity & ({
39
47
  /** The exhausted quota window; keep scoped quota groups in `pool`. */
40
48
  window: '5h' | '7d';
41
49
  /**
42
- * Scoped quota group, such as `non-gemini`.
43
- * Must be a non-empty string without `:`. Omit to block the whole
44
- * account; include to block only this pool.
50
+ * Scoped quota group, such as Antigravity's `3p` or `gemini`.
51
+ * Must match `^[a-z0-9._-]{1,64}$`. Routing compares names exactly, so
52
+ * callers must lowercase names from elsewhere (e.g. `Fable` to `fable`).
53
+ * Names are never rewritten here. Omit or pass `undefined` to block the
54
+ * whole account; include to block only this pool.
45
55
  */
46
56
  pool?: string;
47
57
  /** Optional reset time in epoch milliseconds. */
@@ -1,16 +1,9 @@
1
1
  // Optional THALAMUS routing for vault mode only. Account ids here are vault
2
2
  // account ids; local pool rows are not known to the routing engine.
3
+ import { routingHandle } from './handle.js';
3
4
  function isObject(value) {
4
5
  return typeof value === 'object' && value !== null;
5
6
  }
6
- function routingHandle(sessionId) {
7
- // The bridge can load after the auth plugin, so never cache the accessor.
8
- const routing = Reflect.get(globalThis, Symbol.for('cortexkit.routing'));
9
- if (typeof routing !== 'function')
10
- return undefined;
11
- const handle = routing(sessionId);
12
- return isObject(handle) ? handle : undefined;
13
- }
14
7
  function selectionFor(answer, candidates) {
15
8
  if (!isObject(answer))
16
9
  return undefined;
@@ -56,7 +49,15 @@ export async function askRouting(input) {
56
49
  timer = setTimeout(() => resolve(undefined), deadlineMs);
57
50
  timer.unref();
58
51
  });
59
- const pending = accountFor.call(handle, { provider: input.provider, modelId: input.modelId }, { deadlineMs });
52
+ const request = {
53
+ provider: input.provider,
54
+ modelId: input.modelId,
55
+ };
56
+ const cap = input.holdWaitMaxS;
57
+ if (typeof cap === 'number' && Number.isFinite(cap)) {
58
+ request.hold_wait_max_s = Math.max(0, Math.floor(cap));
59
+ }
60
+ const pending = accountFor.call(handle, request, { deadlineMs });
60
61
  if (!isObject(pending) || typeof pending.then !== 'function')
61
62
  return undefined;
62
63
  const answer = await Promise.race([pending, expired]);
@@ -100,7 +101,7 @@ export function reportRouting(input) {
100
101
  return;
101
102
  // An undefined pool means the whole account, as an omitted one does.
102
103
  if (pool !== undefined &&
103
- (typeof pool !== 'string' || pool.length === 0 || pool.includes(':')))
104
+ (typeof pool !== 'string' || !/^[a-z0-9._-]{1,64}$/.test(pool)))
104
105
  return;
105
106
  payload = {
106
107
  ...identity,
@@ -5,6 +5,11 @@ export interface PortFileEntry {
5
5
  pid: number;
6
6
  startedAt: number;
7
7
  }
8
+ interface PortFileClock {
9
+ /** Internal clock seams for deterministic boot-time checks. */
10
+ now?: () => number;
11
+ uptime?: () => number;
12
+ }
8
13
  export declare function createManagedRpcStateDirPredicate(directoryPrefix: string): (name: string) => boolean;
9
14
  export declare function isManagedRpcStateDir(name: string, directoryPrefix: string): boolean;
10
15
  export declare function getRpcDir(rpcRoot: string, directoryPrefix: string, projectDirectory: string): string;
@@ -18,8 +23,11 @@ export declare function writePortFile(dir: string, entry: {
18
23
  /** Test seam for forcing staging-name collisions; defaults to randomUUID. */
19
24
  stageName?: () => string;
20
25
  }): Promise<string>;
21
- export declare function sweepRpcState(root: string, activeDir: string, isManagedDir: (name: string) => boolean, log?: RpcLogChannel): Promise<void>;
22
- export interface DiscoverPortFileOptions {
26
+ export declare function sweepRpcState(root: string, activeDir: string, isManagedDir: (name: string) => boolean, log?: RpcLogChannel, options?: PortFileClock & {
27
+ /** Internal seam for replacing a stale record before its identity recheck. */
28
+ beforeRemove?: (path: string) => void | Promise<void>;
29
+ }): Promise<void>;
30
+ export interface DiscoverPortFileOptions extends PortFileClock {
23
31
  /**
24
32
  * Return only the expected PID's entry, or null; never fall back to
25
33
  * another live server. Without an expected PID nothing matches, so the
@@ -29,5 +37,6 @@ export interface DiscoverPortFileOptions {
29
37
  exactPid?: boolean;
30
38
  }
31
39
  /** Internal cache validation: probe only the selected file and its PID. */
32
- export declare function portFileIdentity(dir: string, entry: PortFileEntry): Promise<string | null>;
40
+ export declare function portFileIdentity(dir: string, entry: PortFileEntry, options?: PortFileClock): Promise<string | null>;
33
41
  export declare function discoverPortFile(dir: string, expectedPid?: number, options?: DiscoverPortFileOptions): Promise<PortFileEntry | null>;
42
+ export {};
@@ -1,7 +1,36 @@
1
1
  import { createHash, randomUUID } from 'node:crypto';
2
2
  import { chmod, mkdir, open, readdir, rename, rmdir, stat, unlink, } from 'node:fs/promises';
3
+ import { uptime } from 'node:os';
3
4
  import { join, resolve } from 'node:path';
4
5
  import { ensurePrivateDirectory, PrivateFileError, readPrivateText, verifyPrivate, windowsPrivateFiles, writePrivateAtomic, } from '../fs/private-files.js';
6
+ function staleBefore(clock) {
7
+ // A five-minute margin favors keeping a live record when clocks are uncertain.
8
+ return (clock.now ?? Date.now)() - (clock.uptime ?? uptime)() * 1000 - 300_000;
9
+ }
10
+ function isStalePortFile(entry, info, cutoff) {
11
+ const time = entry.startedAt === undefined ? info?.mtimeMs : entry.startedAt;
12
+ return typeof time === 'number' && Number.isFinite(time) && time < cutoff;
13
+ }
14
+ async function removeStalePortFile(path, raw, info, beforeRemove) {
15
+ if (!info)
16
+ return;
17
+ await beforeRemove?.(path);
18
+ try {
19
+ // A live PID may have replaced its old record while the sweep was reading it.
20
+ const current = await readPrivateText(path);
21
+ const identity = await stat(path);
22
+ if (current === raw &&
23
+ identity.dev === info.dev &&
24
+ identity.ino === info.ino &&
25
+ identity.mtimeMs === info.mtimeMs &&
26
+ identity.size === info.size)
27
+ await unlink(path).catch(() => { });
28
+ }
29
+ catch (error) {
30
+ if (error instanceof PrivateFileError && error.code !== 'ENOENT')
31
+ throw error;
32
+ }
33
+ }
5
34
  /**
6
35
  * A PID a liveness probe may address. `process.kill(0 | negative, 0)` signals
7
36
  * a process group rather than a process, and an unsafe integer cannot name a
@@ -117,7 +146,8 @@ export async function writePortFile(dir, entry, options = {}) {
117
146
  throw error;
118
147
  }
119
148
  }
120
- export async function sweepRpcState(root, activeDir, isManagedDir, log) {
149
+ export async function sweepRpcState(root, activeDir, isManagedDir, log, options = {}) {
150
+ const cutoff = staleBefore(options);
121
151
  let projectDirs;
122
152
  try {
123
153
  projectDirs = await readdir(root, { withFileTypes: true });
@@ -146,6 +176,7 @@ export async function sweepRpcState(root, activeDir, isManagedDir, log) {
146
176
  if (!name.startsWith('port-') || !name.endsWith('.json'))
147
177
  continue;
148
178
  const portFile = join(dir, name);
179
+ const info = await stat(portFile).catch(() => undefined);
149
180
  let raw;
150
181
  try {
151
182
  raw = await readPrivateText(portFile);
@@ -172,13 +203,16 @@ export async function sweepRpcState(root, activeDir, isManagedDir, log) {
172
203
  const entry = parsed;
173
204
  if (!pidAlive(entry.pid))
174
205
  await unlink(portFile).catch(() => { });
206
+ else if (isStalePortFile(entry, info, cutoff))
207
+ await removeStalePortFile(portFile, raw, info, options.beforeRemove);
175
208
  }
176
209
  if (resolve(dir) !== active)
177
210
  await rmdir(dir).catch(() => { });
178
211
  }
179
212
  }
180
213
  /** Internal cache validation: probe only the selected file and its PID. */
181
- export async function portFileIdentity(dir, entry) {
214
+ export async function portFileIdentity(dir, entry, options = {}) {
215
+ const cutoff = staleBefore(options);
182
216
  if (!pidAlive(entry.pid))
183
217
  return null;
184
218
  const path = join(resolve(dir), `port-${entry.pid}.json`);
@@ -186,6 +220,8 @@ export async function portFileIdentity(dir, entry) {
186
220
  if (windowsPrivateFiles)
187
221
  await verifyPrivate(path, 'file');
188
222
  const info = await stat(path);
223
+ if (isStalePortFile(entry, info, cutoff))
224
+ return null;
189
225
  return `${path}:${info.dev}:${info.ino}:${info.mtimeMs}:${info.size}`;
190
226
  }
191
227
  catch (error) {
@@ -195,6 +231,7 @@ export async function portFileIdentity(dir, entry) {
195
231
  }
196
232
  }
197
233
  export async function discoverPortFile(dir, expectedPid, options = {}) {
234
+ const cutoff = staleBefore(options);
198
235
  let names;
199
236
  try {
200
237
  if (windowsPrivateFiles)
@@ -213,8 +250,13 @@ export async function discoverPortFile(dir, expectedPid, options = {}) {
213
250
  try {
214
251
  const parsed = JSON.parse(await readPrivateText(join(dir, name)));
215
252
  if (isUsablePortFileEntry(parsed, name)) {
216
- if (pidAlive(parsed.pid))
217
- live.push(parsed);
253
+ if (pidAlive(parsed.pid)) {
254
+ const info = parsed.startedAt === undefined
255
+ ? await stat(join(dir, name)).catch(() => undefined)
256
+ : undefined;
257
+ if (!isStalePortFile(parsed, info, cutoff))
258
+ live.push(parsed);
259
+ }
218
260
  else
219
261
  await unlink(join(dir, name)).catch(() => { });
220
262
  }