@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.
- package/dist/cli.js +689 -183
- package/dist/cli.js.map +4 -4
- package/dist/cli.meta.json +131 -68
- package/dist/index.js +844 -199
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +173 -76
- package/dist/server.js +855 -213
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/cli.d.ts +1 -0
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/cli.js +22 -2
- package/dist/src/cli.js.map +1 -1
- package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +12 -0
- package/dist/src/common-auth-embedded/claustrum/consumer.js +36 -0
- package/dist/src/common-auth-embedded/claustrum/custody.d.ts +16 -4
- package/dist/src/common-auth-embedded/claustrum/custody.js +74 -9
- package/dist/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
- package/dist/src/common-auth-embedded/claustrum/hub.js +8 -0
- package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -0
- package/dist/src/common-auth-embedded/claustrum/roster.d.ts +2 -0
- package/dist/src/common-auth-embedded/claustrum/roster.js +2 -0
- package/dist/src/common-auth-embedded/claustrum/usage.d.ts +41 -0
- package/dist/src/common-auth-embedded/claustrum/usage.js +145 -0
- package/dist/src/common-auth-embedded/commands/builtins.d.ts +5 -0
- package/dist/src/common-auth-embedded/commands/builtins.js +38 -0
- package/dist/src/common-auth-embedded/fs/private-files.d.ts +5 -0
- package/dist/src/common-auth-embedded/fs/private-files.js +7 -0
- package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +142 -47
- package/dist/src/common-auth-embedded/fs/with-lock.js +2 -5
- package/dist/src/common-auth-embedded/limits/activity.d.ts +26 -0
- package/dist/src/common-auth-embedded/limits/axes.d.ts +63 -0
- package/dist/src/common-auth-embedded/limits/decide.d.ts +141 -0
- package/dist/src/common-auth-embedded/limits/duration.d.ts +8 -0
- package/dist/src/common-auth-embedded/limits/families.d.ts +57 -0
- package/dist/src/common-auth-embedded/limits/marker.d.ts +64 -0
- package/dist/src/common-auth-embedded/limits/request-history.d.ts +77 -0
- package/dist/src/common-auth-embedded/limits/scope.d.ts +12 -0
- package/dist/src/common-auth-embedded/limits/signal.d.ts +41 -0
- package/dist/src/common-auth-embedded/limits/terminal.d.ts +52 -0
- package/dist/src/common-auth-embedded/limits/wake.d.ts +21 -0
- package/dist/src/common-auth-embedded/limits/wording.d.ts +25 -0
- package/dist/src/common-auth-embedded/opencode2/index.d.ts +1 -1
- package/dist/src/common-auth-embedded/opencode2/install.d.ts +2 -2
- package/dist/src/common-auth-embedded/opencode2/install.js +161 -18
- package/dist/src/common-auth-embedded/opencode2/types.d.ts +95 -9
- package/dist/src/common-auth-embedded/routing/admission.d.ts +7 -2
- package/dist/src/common-auth-embedded/routing/admission.js +17 -7
- package/dist/src/common-auth-embedded/routing-accessor/handle.js +10 -0
- package/dist/src/common-auth-embedded/routing-accessor/index.d.ts +13 -3
- package/dist/src/common-auth-embedded/routing-accessor/index.js +11 -10
- package/dist/src/common-auth-embedded/rpc/port-file.d.ts +12 -3
- package/dist/src/common-auth-embedded/rpc/port-file.js +46 -4
- package/dist/src/common-auth-embedded/source-output.json +254 -118
- package/dist/src/common-auth-embedded/store/attribution.js +3 -2
- package/dist/src/common-auth-embedded/store/errors.d.ts +1 -1
- package/dist/src/common-auth-embedded/store/hooks.d.ts +5 -1
- package/dist/src/common-auth-embedded/store/hooks.js +20 -5
- package/dist/src/common-auth-embedded/store/index.d.ts +1 -0
- package/dist/src/common-auth-embedded/store/limits-namespace.d.ts +7 -0
- package/dist/src/common-auth-embedded/store/limits-namespace.js +34 -0
- package/dist/src/common-auth-embedded/store/pool.d.ts +10 -1
- package/dist/src/common-auth-embedded/store/pool.js +2 -0
- package/dist/src/common-auth-embedded/store/provider-state.js +5 -5
- package/dist/src/common-auth-embedded/store/refresh.js +1 -1
- package/dist/src/common-auth-embedded/store/schema.js +9 -4
- package/dist/src/common-auth-embedded/store/settings.d.ts +2 -0
- package/dist/src/common-auth-embedded/store/settings.js +11 -4
- package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
- package/dist/src/plugin/shared/request-services.d.ts +14 -18
- package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/src/plugin/shared/request-services.js +127 -7
- package/dist/src/plugin/shared/request-services.js.map +1 -1
- package/dist/src/runtime-layout.d.ts +9 -2
- package/dist/src/runtime-layout.d.ts.map +1 -1
- package/dist/src/runtime-layout.js +8 -8
- package/dist/src/runtime-layout.js.map +1 -1
- package/dist/src/setup.d.ts.map +1 -1
- package/dist/src/setup.js +29 -40
- package/dist/src/setup.js.map +1 -1
- package/dist/tui-build-map.json +9 -9
- package/dist/tui-ga-build-map.json +1 -1
- package/dist/types/src/cli.d.ts +1 -0
- package/dist/types/src/cli.d.ts.map +1 -1
- package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +12 -0
- package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +16 -4
- package/dist/types/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
- package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -0
- package/dist/types/src/common-auth-embedded/claustrum/roster.d.ts +2 -0
- package/dist/types/src/common-auth-embedded/claustrum/usage.d.ts +41 -0
- package/dist/types/src/common-auth-embedded/commands/builtins.d.ts +5 -0
- package/dist/types/src/common-auth-embedded/limits/activity.d.ts +26 -0
- package/dist/types/src/common-auth-embedded/limits/axes.d.ts +63 -0
- package/dist/types/src/common-auth-embedded/limits/decide.d.ts +141 -0
- package/dist/types/src/common-auth-embedded/limits/duration.d.ts +8 -0
- package/dist/types/src/common-auth-embedded/limits/families.d.ts +57 -0
- package/dist/types/src/common-auth-embedded/limits/marker.d.ts +64 -0
- package/dist/types/src/common-auth-embedded/limits/request-history.d.ts +77 -0
- package/dist/types/src/common-auth-embedded/limits/scope.d.ts +12 -0
- package/dist/types/src/common-auth-embedded/limits/signal.d.ts +41 -0
- package/dist/types/src/common-auth-embedded/limits/terminal.d.ts +52 -0
- package/dist/types/src/common-auth-embedded/limits/wake.d.ts +21 -0
- package/dist/types/src/common-auth-embedded/limits/wording.d.ts +25 -0
- package/dist/types/src/common-auth-embedded/opencode2/index.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/opencode2/install.d.ts +2 -2
- package/dist/types/src/common-auth-embedded/opencode2/types.d.ts +95 -9
- package/dist/types/src/common-auth-embedded/routing/admission.d.ts +7 -2
- package/dist/types/src/common-auth-embedded/routing-accessor/index.d.ts +13 -3
- package/dist/types/src/common-auth-embedded/store/errors.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/store/hooks.d.ts +5 -1
- package/dist/types/src/common-auth-embedded/store/index.d.ts +1 -0
- package/dist/types/src/common-auth-embedded/store/limits-namespace.d.ts +7 -0
- package/dist/types/src/common-auth-embedded/store/pool.d.ts +10 -1
- package/dist/types/src/common-auth-embedded/store/settings.d.ts +2 -0
- package/dist/types/src/plugin/shared/request-services.d.ts +14 -18
- package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/types/src/runtime-layout.d.ts +9 -2
- package/dist/types/src/runtime-layout.d.ts.map +1 -1
- package/dist/types/src/setup.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/common-auth-embedded/claustrum/consumer.d.ts +12 -0
- package/src/common-auth-embedded/claustrum/consumer.js +36 -0
- package/src/common-auth-embedded/claustrum/custody.d.ts +16 -4
- package/src/common-auth-embedded/claustrum/custody.js +74 -9
- package/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
- package/src/common-auth-embedded/claustrum/hub.js +8 -0
- package/src/common-auth-embedded/claustrum/index.d.ts +1 -0
- package/src/common-auth-embedded/claustrum/roster.d.ts +2 -0
- package/src/common-auth-embedded/claustrum/roster.js +2 -0
- package/src/common-auth-embedded/claustrum/usage.d.ts +41 -0
- package/src/common-auth-embedded/claustrum/usage.js +145 -0
- package/src/common-auth-embedded/commands/builtins.d.ts +5 -0
- package/src/common-auth-embedded/commands/builtins.js +38 -0
- package/src/common-auth-embedded/fs/private-files.d.ts +5 -0
- package/src/common-auth-embedded/fs/private-files.js +7 -0
- package/src/common-auth-embedded/fs/refresh-file-lock.js +142 -47
- package/src/common-auth-embedded/fs/with-lock.js +2 -5
- package/src/common-auth-embedded/limits/activity.d.ts +26 -0
- package/src/common-auth-embedded/limits/axes.d.ts +63 -0
- package/src/common-auth-embedded/limits/decide.d.ts +141 -0
- package/src/common-auth-embedded/limits/duration.d.ts +8 -0
- package/src/common-auth-embedded/limits/families.d.ts +57 -0
- package/src/common-auth-embedded/limits/marker.d.ts +64 -0
- package/src/common-auth-embedded/limits/request-history.d.ts +77 -0
- package/src/common-auth-embedded/limits/scope.d.ts +12 -0
- package/src/common-auth-embedded/limits/signal.d.ts +41 -0
- package/src/common-auth-embedded/limits/terminal.d.ts +52 -0
- package/src/common-auth-embedded/limits/wake.d.ts +21 -0
- package/src/common-auth-embedded/limits/wording.d.ts +25 -0
- package/src/common-auth-embedded/opencode2/index.d.ts +1 -1
- package/src/common-auth-embedded/opencode2/install.d.ts +2 -2
- package/src/common-auth-embedded/opencode2/install.js +161 -18
- package/src/common-auth-embedded/opencode2/types.d.ts +95 -9
- package/src/common-auth-embedded/routing/admission.d.ts +7 -2
- package/src/common-auth-embedded/routing/admission.js +17 -7
- package/src/common-auth-embedded/routing-accessor/handle.js +10 -0
- package/src/common-auth-embedded/routing-accessor/index.d.ts +13 -3
- package/src/common-auth-embedded/routing-accessor/index.js +11 -10
- package/src/common-auth-embedded/rpc/port-file.d.ts +12 -3
- package/src/common-auth-embedded/rpc/port-file.js +46 -4
- package/src/common-auth-embedded/source-output.json +254 -118
- package/src/common-auth-embedded/store/attribution.js +3 -2
- package/src/common-auth-embedded/store/errors.d.ts +1 -1
- package/src/common-auth-embedded/store/hooks.d.ts +5 -1
- package/src/common-auth-embedded/store/hooks.js +20 -5
- package/src/common-auth-embedded/store/index.d.ts +1 -0
- package/src/common-auth-embedded/store/limits-namespace.d.ts +7 -0
- package/src/common-auth-embedded/store/limits-namespace.js +34 -0
- package/src/common-auth-embedded/store/pool.d.ts +10 -1
- package/src/common-auth-embedded/store/pool.js +2 -0
- package/src/common-auth-embedded/store/provider-state.js +5 -5
- package/src/common-auth-embedded/store/refresh.js +1 -1
- package/src/common-auth-embedded/store/schema.js +9 -4
- package/src/common-auth-embedded/store/settings.d.ts +2 -0
- package/src/common-auth-embedded/store/settings.js +11 -4
- package/src/tui-compiled/common-auth-embedded/fs/private-files.js +7 -0
- package/src/tui-compiled/common-auth-embedded/rpc/port-file.js +46 -4
- package/src/tui-raw/common-auth-embedded/fs/private-files.js +7 -0
- 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 `
|
|
43
|
-
* Must
|
|
44
|
-
*
|
|
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
|
|
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' ||
|
|
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
|
|
22
|
-
|
|
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
|
-
|
|
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
|
}
|