@ai-devkit/agent-manager 0.44.1 → 0.45.1

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.
@@ -0,0 +1,302 @@
1
+ import { spawn } from "node:child_process";
2
+ import { constants } from "node:fs";
3
+ import { access as fsAccess, chmod, mkdtemp, rm, stat as fsStat, writeFile } from "node:fs/promises";
4
+ import os from "node:os";
5
+ import path from "node:path";
6
+ import { AntigravityCliError, classifyAntigravityExitFailure, fetchAntigravityRemoteCapacity, isSupportedAntigravityVersion, parseAntigravityUsageReport, parseAntigravityVersion } from "../providers/antigravity.js";
7
+ import { resolveAntigravityOAuthCredential } from "../../harnesses/antigravity/credentials.js";
8
+ const DEFAULT_USAGE_TIMEOUT_MS = 90_000;
9
+ const DEFAULT_VERSION_TIMEOUT_MS = 3_000;
10
+ const DEFAULT_MAX_OUTPUT_BYTES = 1024 * 1024;
11
+ const VERSION_MAX_OUTPUT_BYTES = 64 * 1024;
12
+ const KILL_GRACE_MS = 200;
13
+ const FAILING_LAUNCHER_SCRIPT = "#!/bin/sh\nexit 1\n";
14
+ let versionCache = null;
15
+ export function resetAntigravityVersionCache() {
16
+ versionCache = null;
17
+ }
18
+ async function isExecutable(target, checkAccess) {
19
+ try {
20
+ if (checkAccess) {
21
+ await checkAccess(target);
22
+ } else {
23
+ await fsAccess(target, constants.X_OK);
24
+ }
25
+ return true;
26
+ } catch {
27
+ return false;
28
+ }
29
+ }
30
+ async function resolveAntigravityBinary(options) {
31
+ const env = options.env ?? process.env;
32
+ if (Object.hasOwn(env, "ANTIGRAVITY_CLI_PATH") && env.ANTIGRAVITY_CLI_PATH !== undefined) {
33
+ const override = env.ANTIGRAVITY_CLI_PATH.trim();
34
+ if (!override || !await isExecutable(override, options.access)) {
35
+ throw new AntigravityCliError("executable_not_found", "agy executable not found");
36
+ }
37
+ return override;
38
+ }
39
+ const pathValue = options.path ?? env.PATH ?? "";
40
+ const home = env.HOME ?? os.homedir();
41
+ const candidates = [
42
+ ...pathValue.split(path.delimiter).filter(Boolean).map((dir)=>path.join(dir, "agy")),
43
+ path.join(home, ".local", "bin", "agy"),
44
+ "/opt/homebrew/bin/agy",
45
+ "/usr/local/bin/agy"
46
+ ];
47
+ const seen = new Set();
48
+ for (const candidate of candidates){
49
+ if (seen.has(candidate)) continue;
50
+ seen.add(candidate);
51
+ if (await isExecutable(candidate, options.access)) return candidate;
52
+ }
53
+ throw new AntigravityCliError("executable_not_found", "agy executable not found");
54
+ }
55
+ function signalProcessTree(pid, signal) {
56
+ if (!pid) return;
57
+ if (process.platform !== "win32") {
58
+ try {
59
+ process.kill(-pid, signal);
60
+ return;
61
+ } catch {
62
+ // Fall back to signaling the direct child PID.
63
+ }
64
+ }
65
+ try {
66
+ process.kill(pid, signal);
67
+ } catch {
68
+ // Process already exited.
69
+ }
70
+ }
71
+ function defaultExec(options) {
72
+ return new Promise((resolve, reject)=>{
73
+ const child = spawn(options.command, [
74
+ ...options.args
75
+ ], {
76
+ cwd: options.cwd,
77
+ env: options.env,
78
+ detached: process.platform !== "win32",
79
+ stdio: [
80
+ "ignore",
81
+ "pipe",
82
+ "pipe"
83
+ ]
84
+ });
85
+ const stdoutChunks = [];
86
+ const stderrChunks = [];
87
+ let stdoutBytes = 0;
88
+ let stderrBytes = 0;
89
+ let timedOut = false;
90
+ let outputTooLarge = false;
91
+ let settled = false;
92
+ let killTimer = null;
93
+ const terminate = ()=>{
94
+ signalProcessTree(child.pid, "SIGTERM");
95
+ if (!killTimer) {
96
+ killTimer = setTimeout(()=>{
97
+ signalProcessTree(child.pid, "SIGKILL");
98
+ }, KILL_GRACE_MS);
99
+ killTimer.unref();
100
+ }
101
+ };
102
+ const finish = (error, exitCode = null)=>{
103
+ if (settled) return;
104
+ settled = true;
105
+ clearTimeout(timer);
106
+ if (killTimer) clearTimeout(killTimer);
107
+ signalProcessTree(child.pid, "SIGTERM");
108
+ if (error) {
109
+ reject(error);
110
+ } else {
111
+ resolve({
112
+ exitCode,
113
+ stdout: Buffer.concat(stdoutChunks).toString("utf8"),
114
+ stderr: Buffer.concat(stderrChunks).toString("utf8"),
115
+ timedOut,
116
+ outputTooLarge
117
+ });
118
+ }
119
+ };
120
+ const timer = setTimeout(()=>{
121
+ timedOut = true;
122
+ terminate();
123
+ }, options.timeoutMs);
124
+ timer.unref();
125
+ child.stdout.on("data", (chunk)=>{
126
+ if (outputTooLarge) return;
127
+ stdoutBytes += chunk.length;
128
+ if (stdoutBytes > options.maxOutputBytes) {
129
+ outputTooLarge = true;
130
+ terminate();
131
+ return;
132
+ }
133
+ stdoutChunks.push(chunk);
134
+ });
135
+ child.stderr.on("data", (chunk)=>{
136
+ if (outputTooLarge) return;
137
+ stderrBytes += chunk.length;
138
+ if (stderrBytes > options.maxOutputBytes) {
139
+ outputTooLarge = true;
140
+ terminate();
141
+ return;
142
+ }
143
+ stderrChunks.push(chunk);
144
+ });
145
+ child.once("error", ()=>{
146
+ finish(new AntigravityCliError("launch_failed", "agy failed to launch"));
147
+ });
148
+ child.once("close", (code)=>{
149
+ finish(undefined, code);
150
+ });
151
+ });
152
+ }
153
+ async function readBinaryStat(binaryPath, statFn) {
154
+ try {
155
+ const info = statFn ? await statFn(binaryPath) : await fsStat(binaryPath);
156
+ return {
157
+ size: info.size,
158
+ mtimeMs: info.mtimeMs,
159
+ ino: info.ino
160
+ };
161
+ } catch {
162
+ return null;
163
+ }
164
+ }
165
+ async function resolveAntigravityVersion(binaryPath, cwd, env, options) {
166
+ const binaryStat = await readBinaryStat(binaryPath, options.stat);
167
+ if (binaryStat && versionCache && versionCache.binaryPath === binaryPath && versionCache.size === binaryStat.size && versionCache.mtimeMs === binaryStat.mtimeMs && versionCache.ino === binaryStat.ino) {
168
+ return versionCache.version;
169
+ }
170
+ const exec = options.exec ?? defaultExec;
171
+ const result = await exec({
172
+ command: binaryPath,
173
+ args: [
174
+ "--version"
175
+ ],
176
+ cwd,
177
+ env,
178
+ timeoutMs: options.versionTimeoutMs ?? DEFAULT_VERSION_TIMEOUT_MS,
179
+ maxOutputBytes: VERSION_MAX_OUTPUT_BYTES
180
+ });
181
+ if (result.timedOut || result.outputTooLarge || result.exitCode !== 0) {
182
+ return null;
183
+ }
184
+ const parsed = parseAntigravityVersion(`${result.stdout}\n${result.stderr}`);
185
+ if (parsed && binaryStat) {
186
+ versionCache = {
187
+ binaryPath,
188
+ size: binaryStat.size,
189
+ mtimeMs: binaryStat.mtimeMs,
190
+ ino: binaryStat.ino,
191
+ version: parsed
192
+ };
193
+ }
194
+ return parsed;
195
+ }
196
+ async function createProbeSandbox() {
197
+ const dir = await mkdtemp(path.join(os.tmpdir(), "ai-devkit-agy-"));
198
+ await chmod(dir, 0o700);
199
+ for (const stubName of [
200
+ "open",
201
+ "xdg-open"
202
+ ]){
203
+ const stubPath = path.join(dir, stubName);
204
+ await writeFile(stubPath, FAILING_LAUNCHER_SCRIPT, {
205
+ encoding: "utf8",
206
+ mode: 0o700
207
+ });
208
+ await chmod(stubPath, 0o700);
209
+ }
210
+ return dir;
211
+ }
212
+ function buildProbeEnv(baseEnv, sandboxDir) {
213
+ const existingPath = baseEnv.PATH ?? "";
214
+ return {
215
+ ...baseEnv,
216
+ AGY_CLI_DISABLE_AUTO_UPDATE: "true",
217
+ PATH: existingPath ? `${sandboxDir}${path.delimiter}${existingPath}` : sandboxDir,
218
+ BROWSER: path.join(sandboxDir, "open")
219
+ };
220
+ }
221
+ function antigravityReport(snapshot, checkedAt) {
222
+ return {
223
+ harness: "antigravity",
224
+ provider: "antigravity",
225
+ generatedAt: checkedAt,
226
+ ...snapshot
227
+ };
228
+ }
229
+ export async function probeAntigravityCapacity(options) {
230
+ const oauthCredential = await resolveAntigravityOAuthCredential(options);
231
+ if (oauthCredential) {
232
+ try {
233
+ const snapshot = await fetchAntigravityRemoteCapacity(oauthCredential, {
234
+ fetch: options.fetch,
235
+ timeoutMs: options.remoteTimeoutMs
236
+ });
237
+ return antigravityReport(snapshot, options.checkedAt);
238
+ } catch {
239
+ // Fall back to the local agy CLI print report if remote OAuth fails.
240
+ }
241
+ }
242
+ const binaryPath = await resolveAntigravityBinary(options);
243
+ const sandboxDir = await createProbeSandbox();
244
+ try {
245
+ const childEnv = buildProbeEnv(options.env ?? process.env, sandboxDir);
246
+ const version = await resolveAntigravityVersion(binaryPath, sandboxDir, childEnv, options);
247
+ if (!version || !isSupportedAntigravityVersion(version)) {
248
+ throw new AntigravityCliError("unsupported_version", "agy CLI >= 1.1.11 is required for quota reporting");
249
+ }
250
+ const timeoutMs = options.timeoutMs ?? DEFAULT_USAGE_TIMEOUT_MS;
251
+ const printTimeoutSec = Math.max(1, Math.ceil(timeoutMs / 1000));
252
+ const exec = options.exec ?? defaultExec;
253
+ const result = await exec({
254
+ command: binaryPath,
255
+ args: [
256
+ "-p",
257
+ "/usage",
258
+ "--output-format",
259
+ "json",
260
+ "--print-timeout",
261
+ `${printTimeoutSec}s`
262
+ ],
263
+ cwd: sandboxDir,
264
+ env: childEnv,
265
+ timeoutMs,
266
+ maxOutputBytes: options.maxOutputBytes ?? DEFAULT_MAX_OUTPUT_BYTES
267
+ });
268
+ if (result.timedOut) {
269
+ throw new AntigravityCliError("timed_out", "Antigravity CLI quota probe timed out");
270
+ }
271
+ if (result.outputTooLarge) {
272
+ throw new AntigravityCliError("output_too_large", "Antigravity CLI usage report exceeded output limit");
273
+ }
274
+ if (result.exitCode !== 0) {
275
+ const classified = classifyAntigravityExitFailure(result.exitCode ?? 1, result.stderr);
276
+ if (classified.kind === "authentication_required") {
277
+ return antigravityReport({
278
+ authenticated: false,
279
+ available: "unknown",
280
+ windows: [],
281
+ creditsRemaining: null
282
+ }, options.checkedAt);
283
+ }
284
+ throw classified;
285
+ }
286
+ let parsedJson;
287
+ try {
288
+ parsedJson = JSON.parse(result.stdout);
289
+ } catch {
290
+ throw new Error("Antigravity CLI usage report is not valid JSON");
291
+ }
292
+ const snapshot = parseAntigravityUsageReport(parsedJson);
293
+ return antigravityReport(snapshot, options.checkedAt);
294
+ } finally{
295
+ await rm(sandboxDir, {
296
+ recursive: true,
297
+ force: true
298
+ });
299
+ }
300
+ }
301
+
302
+ //# sourceMappingURL=antigravity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/capacity/sources/antigravity.ts"],"sourcesContent":["import { spawn } from \"node:child_process\";\nimport { constants } from \"node:fs\";\nimport {\n access as fsAccess,\n chmod,\n mkdtemp,\n rm,\n stat as fsStat,\n writeFile,\n} from \"node:fs/promises\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport {\n AntigravityCliError,\n classifyAntigravityExitFailure,\n fetchAntigravityRemoteCapacity,\n isSupportedAntigravityVersion,\n parseAntigravityUsageReport,\n parseAntigravityVersion,\n type AntigravityVersion,\n} from \"../providers/antigravity.js\";\nimport {\n resolveAntigravityOAuthCredential,\n type AntigravityCredentialOptions,\n} from \"../../harnesses/antigravity/credentials.js\";\nimport type { CapacityReport } from \"../types.js\";\n\nconst DEFAULT_USAGE_TIMEOUT_MS = 90_000;\nconst DEFAULT_VERSION_TIMEOUT_MS = 3_000;\nconst DEFAULT_MAX_OUTPUT_BYTES = 1024 * 1024;\nconst VERSION_MAX_OUTPUT_BYTES = 64 * 1024;\nconst KILL_GRACE_MS = 200;\nconst FAILING_LAUNCHER_SCRIPT = \"#!/bin/sh\\nexit 1\\n\";\n\nexport type AntigravityBinaryStat = {\n size: number;\n mtimeMs: number;\n ino: number;\n};\n\nexport type AntigravityExecResult = {\n exitCode: number | null;\n stdout: string;\n stderr: string;\n timedOut?: boolean;\n outputTooLarge?: boolean;\n};\n\nexport type AntigravityExecOptions = {\n command: string;\n args: readonly string[];\n cwd: string;\n env: NodeJS.ProcessEnv;\n timeoutMs: number;\n maxOutputBytes: number;\n};\n\nexport type AntigravityCapacityOptions = AntigravityCredentialOptions & {\n path?: string;\n access?: (target: string) => Promise<void>;\n stat?: (target: string) => Promise<AntigravityBinaryStat>;\n exec?: (options: AntigravityExecOptions) => Promise<AntigravityExecResult>;\n fetch?: typeof globalThis.fetch;\n timeoutMs?: number;\n versionTimeoutMs?: number;\n remoteTimeoutMs?: number;\n maxOutputBytes?: number;\n};\n\nexport type AntigravityProbeOptions = AntigravityCapacityOptions & {\n checkedAt: string;\n};\n\ntype CachedVersion = {\n binaryPath: string;\n size: number;\n mtimeMs: number;\n ino: number;\n version: AntigravityVersion;\n};\n\nlet versionCache: CachedVersion | null = null;\n\nexport function resetAntigravityVersionCache(): void {\n versionCache = null;\n}\n\nasync function isExecutable(\n target: string,\n checkAccess?: (target: string) => Promise<void>,\n): Promise<boolean> {\n try {\n if (checkAccess) {\n await checkAccess(target);\n } else {\n await fsAccess(target, constants.X_OK);\n }\n return true;\n } catch {\n return false;\n }\n}\n\nasync function resolveAntigravityBinary(options: AntigravityProbeOptions): Promise<string> {\n const env = options.env ?? process.env;\n if (Object.hasOwn(env, \"ANTIGRAVITY_CLI_PATH\") && env.ANTIGRAVITY_CLI_PATH !== undefined) {\n const override = env.ANTIGRAVITY_CLI_PATH.trim();\n if (!override || !(await isExecutable(override, options.access))) {\n throw new AntigravityCliError(\"executable_not_found\", \"agy executable not found\");\n }\n return override;\n }\n\n const pathValue = options.path ?? env.PATH ?? \"\";\n const home = env.HOME ?? os.homedir();\n const candidates = [\n ...pathValue\n .split(path.delimiter)\n .filter(Boolean)\n .map((dir) => path.join(dir, \"agy\")),\n path.join(home, \".local\", \"bin\", \"agy\"),\n \"/opt/homebrew/bin/agy\",\n \"/usr/local/bin/agy\",\n ];\n\n const seen = new Set<string>();\n for (const candidate of candidates) {\n if (seen.has(candidate)) continue;\n seen.add(candidate);\n if (await isExecutable(candidate, options.access)) return candidate;\n }\n\n throw new AntigravityCliError(\"executable_not_found\", \"agy executable not found\");\n}\n\nfunction signalProcessTree(pid: number | undefined, signal: NodeJS.Signals): void {\n if (!pid) return;\n if (process.platform !== \"win32\") {\n try {\n process.kill(-pid, signal);\n return;\n } catch {\n // Fall back to signaling the direct child PID.\n }\n }\n try {\n process.kill(pid, signal);\n } catch {\n // Process already exited.\n }\n}\n\nfunction defaultExec(options: AntigravityExecOptions): Promise<AntigravityExecResult> {\n return new Promise((resolve, reject) => {\n const child = spawn(options.command, [...options.args], {\n cwd: options.cwd,\n env: options.env,\n detached: process.platform !== \"win32\",\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n });\n\n const stdoutChunks: Buffer[] = [];\n const stderrChunks: Buffer[] = [];\n let stdoutBytes = 0;\n let stderrBytes = 0;\n let timedOut = false;\n let outputTooLarge = false;\n let settled = false;\n let killTimer: NodeJS.Timeout | null = null;\n\n const terminate = () => {\n signalProcessTree(child.pid, \"SIGTERM\");\n if (!killTimer) {\n killTimer = setTimeout(() => {\n signalProcessTree(child.pid, \"SIGKILL\");\n }, KILL_GRACE_MS);\n killTimer.unref();\n }\n };\n\n const finish = (error?: Error, exitCode: number | null = null) => {\n if (settled) return;\n settled = true;\n clearTimeout(timer);\n if (killTimer) clearTimeout(killTimer);\n signalProcessTree(child.pid, \"SIGTERM\");\n if (error) {\n reject(error);\n } else {\n resolve({\n exitCode,\n stdout: Buffer.concat(stdoutChunks).toString(\"utf8\"),\n stderr: Buffer.concat(stderrChunks).toString(\"utf8\"),\n timedOut,\n outputTooLarge,\n });\n }\n };\n\n const timer = setTimeout(() => {\n timedOut = true;\n terminate();\n }, options.timeoutMs);\n timer.unref();\n\n child.stdout.on(\"data\", (chunk: Buffer) => {\n if (outputTooLarge) return;\n stdoutBytes += chunk.length;\n if (stdoutBytes > options.maxOutputBytes) {\n outputTooLarge = true;\n terminate();\n return;\n }\n stdoutChunks.push(chunk);\n });\n\n child.stderr.on(\"data\", (chunk: Buffer) => {\n if (outputTooLarge) return;\n stderrBytes += chunk.length;\n if (stderrBytes > options.maxOutputBytes) {\n outputTooLarge = true;\n terminate();\n return;\n }\n stderrChunks.push(chunk);\n });\n\n child.once(\"error\", () => {\n finish(new AntigravityCliError(\"launch_failed\", \"agy failed to launch\"));\n });\n\n child.once(\"close\", (code) => {\n finish(undefined, code);\n });\n });\n}\n\nasync function readBinaryStat(\n binaryPath: string,\n statFn?: (target: string) => Promise<AntigravityBinaryStat>,\n): Promise<AntigravityBinaryStat | null> {\n try {\n const info = statFn ? await statFn(binaryPath) : await fsStat(binaryPath);\n return { size: info.size, mtimeMs: info.mtimeMs, ino: info.ino };\n } catch {\n return null;\n }\n}\n\nasync function resolveAntigravityVersion(\n binaryPath: string,\n cwd: string,\n env: NodeJS.ProcessEnv,\n options: AntigravityProbeOptions,\n): Promise<AntigravityVersion | null> {\n const binaryStat = await readBinaryStat(binaryPath, options.stat);\n if (\n binaryStat &&\n versionCache &&\n versionCache.binaryPath === binaryPath &&\n versionCache.size === binaryStat.size &&\n versionCache.mtimeMs === binaryStat.mtimeMs &&\n versionCache.ino === binaryStat.ino\n ) {\n return versionCache.version;\n }\n\n const exec = options.exec ?? defaultExec;\n const result = await exec({\n command: binaryPath,\n args: [\"--version\"],\n cwd,\n env,\n timeoutMs: options.versionTimeoutMs ?? DEFAULT_VERSION_TIMEOUT_MS,\n maxOutputBytes: VERSION_MAX_OUTPUT_BYTES,\n });\n\n if (result.timedOut || result.outputTooLarge || result.exitCode !== 0) {\n return null;\n }\n\n const parsed = parseAntigravityVersion(`${result.stdout}\\n${result.stderr}`);\n if (parsed && binaryStat) {\n versionCache = {\n binaryPath,\n size: binaryStat.size,\n mtimeMs: binaryStat.mtimeMs,\n ino: binaryStat.ino,\n version: parsed,\n };\n }\n return parsed;\n}\n\nasync function createProbeSandbox(): Promise<string> {\n const dir = await mkdtemp(path.join(os.tmpdir(), \"ai-devkit-agy-\"));\n await chmod(dir, 0o700);\n for (const stubName of [\"open\", \"xdg-open\"]) {\n const stubPath = path.join(dir, stubName);\n await writeFile(stubPath, FAILING_LAUNCHER_SCRIPT, { encoding: \"utf8\", mode: 0o700 });\n await chmod(stubPath, 0o700);\n }\n return dir;\n}\n\nfunction buildProbeEnv(baseEnv: NodeJS.ProcessEnv, sandboxDir: string): NodeJS.ProcessEnv {\n const existingPath = baseEnv.PATH ?? \"\";\n return {\n ...baseEnv,\n AGY_CLI_DISABLE_AUTO_UPDATE: \"true\",\n PATH: existingPath ? `${sandboxDir}${path.delimiter}${existingPath}` : sandboxDir,\n BROWSER: path.join(sandboxDir, \"open\"),\n };\n}\n\nfunction antigravityReport(\n snapshot: Omit<CapacityReport, \"harness\" | \"provider\" | \"generatedAt\">,\n checkedAt: string,\n): CapacityReport {\n return {\n harness: \"antigravity\",\n provider: \"antigravity\",\n generatedAt: checkedAt,\n ...snapshot,\n };\n}\n\nexport async function probeAntigravityCapacity(\n options: AntigravityProbeOptions,\n): Promise<CapacityReport> {\n const oauthCredential = await resolveAntigravityOAuthCredential(options);\n if (oauthCredential) {\n try {\n const snapshot = await fetchAntigravityRemoteCapacity(oauthCredential, {\n fetch: options.fetch,\n timeoutMs: options.remoteTimeoutMs,\n });\n return antigravityReport(snapshot, options.checkedAt);\n } catch {\n // Fall back to the local agy CLI print report if remote OAuth fails.\n }\n }\n\n const binaryPath = await resolveAntigravityBinary(options);\n const sandboxDir = await createProbeSandbox();\n\n try {\n const childEnv = buildProbeEnv(options.env ?? process.env, sandboxDir);\n const version = await resolveAntigravityVersion(binaryPath, sandboxDir, childEnv, options);\n if (!version || !isSupportedAntigravityVersion(version)) {\n throw new AntigravityCliError(\n \"unsupported_version\",\n \"agy CLI >= 1.1.11 is required for quota reporting\",\n );\n }\n\n const timeoutMs = options.timeoutMs ?? DEFAULT_USAGE_TIMEOUT_MS;\n const printTimeoutSec = Math.max(1, Math.ceil(timeoutMs / 1000));\n const exec = options.exec ?? defaultExec;\n const result = await exec({\n command: binaryPath,\n args: [\"-p\", \"/usage\", \"--output-format\", \"json\", \"--print-timeout\", `${printTimeoutSec}s`],\n cwd: sandboxDir,\n env: childEnv,\n timeoutMs,\n maxOutputBytes: options.maxOutputBytes ?? DEFAULT_MAX_OUTPUT_BYTES,\n });\n\n if (result.timedOut) {\n throw new AntigravityCliError(\"timed_out\", \"Antigravity CLI quota probe timed out\");\n }\n if (result.outputTooLarge) {\n throw new AntigravityCliError(\n \"output_too_large\",\n \"Antigravity CLI usage report exceeded output limit\",\n );\n }\n if (result.exitCode !== 0) {\n const classified = classifyAntigravityExitFailure(result.exitCode ?? 1, result.stderr);\n if (classified.kind === \"authentication_required\") {\n return antigravityReport(\n {\n authenticated: false,\n available: \"unknown\",\n windows: [],\n creditsRemaining: null,\n },\n options.checkedAt,\n );\n }\n throw classified;\n }\n\n let parsedJson: unknown;\n try {\n parsedJson = JSON.parse(result.stdout);\n } catch {\n throw new Error(\"Antigravity CLI usage report is not valid JSON\");\n }\n\n const snapshot = parseAntigravityUsageReport(parsedJson);\n return antigravityReport(snapshot, options.checkedAt);\n } finally {\n await rm(sandboxDir, { recursive: true, force: true });\n }\n}\n"],"names":["spawn","constants","access","fsAccess","chmod","mkdtemp","rm","stat","fsStat","writeFile","os","path","AntigravityCliError","classifyAntigravityExitFailure","fetchAntigravityRemoteCapacity","isSupportedAntigravityVersion","parseAntigravityUsageReport","parseAntigravityVersion","resolveAntigravityOAuthCredential","DEFAULT_USAGE_TIMEOUT_MS","DEFAULT_VERSION_TIMEOUT_MS","DEFAULT_MAX_OUTPUT_BYTES","VERSION_MAX_OUTPUT_BYTES","KILL_GRACE_MS","FAILING_LAUNCHER_SCRIPT","versionCache","resetAntigravityVersionCache","isExecutable","target","checkAccess","X_OK","resolveAntigravityBinary","options","env","process","Object","hasOwn","ANTIGRAVITY_CLI_PATH","undefined","override","trim","pathValue","PATH","home","HOME","homedir","candidates","split","delimiter","filter","Boolean","map","dir","join","seen","Set","candidate","has","add","signalProcessTree","pid","signal","platform","kill","defaultExec","Promise","resolve","reject","child","command","args","cwd","detached","stdio","stdoutChunks","stderrChunks","stdoutBytes","stderrBytes","timedOut","outputTooLarge","settled","killTimer","terminate","setTimeout","unref","finish","error","exitCode","clearTimeout","timer","stdout","Buffer","concat","toString","stderr","timeoutMs","on","chunk","length","maxOutputBytes","push","once","code","readBinaryStat","binaryPath","statFn","info","size","mtimeMs","ino","resolveAntigravityVersion","binaryStat","version","exec","result","versionTimeoutMs","parsed","createProbeSandbox","tmpdir","stubName","stubPath","encoding","mode","buildProbeEnv","baseEnv","sandboxDir","existingPath","AGY_CLI_DISABLE_AUTO_UPDATE","BROWSER","antigravityReport","snapshot","checkedAt","harness","provider","generatedAt","probeAntigravityCapacity","oauthCredential","fetch","remoteTimeoutMs","childEnv","printTimeoutSec","Math","max","ceil","classified","kind","authenticated","available","windows","creditsRemaining","parsedJson","JSON","parse","Error","recursive","force"],"mappings":"AAAA,SAASA,KAAK,QAAQ,qBAAqB;AAC3C,SAASC,SAAS,QAAQ,UAAU;AACpC,SACEC,UAAUC,QAAQ,EAClBC,KAAK,EACLC,OAAO,EACPC,EAAE,EACFC,QAAQC,MAAM,EACdC,SAAS,QACJ,mBAAmB;AAC1B,OAAOC,QAAQ,UAAU;AACzB,OAAOC,UAAU,YAAY;AAC7B,SACEC,mBAAmB,EACnBC,8BAA8B,EAC9BC,8BAA8B,EAC9BC,6BAA6B,EAC7BC,2BAA2B,EAC3BC,uBAAuB,QAElB,8BAA8B;AACrC,SACEC,iCAAiC,QAE5B,6CAA6C;AAGpD,MAAMC,2BAA2B;AACjC,MAAMC,6BAA6B;AACnC,MAAMC,2BAA2B,OAAO;AACxC,MAAMC,2BAA2B,KAAK;AACtC,MAAMC,gBAAgB;AACtB,MAAMC,0BAA0B;AAiDhC,IAAIC,eAAqC;AAEzC,OAAO,SAASC;IACdD,eAAe;AACjB;AAEA,eAAeE,aACbC,MAAc,EACdC,WAA+C;IAE/C,IAAI;QACF,IAAIA,aAAa;YACf,MAAMA,YAAYD;QACpB,OAAO;YACL,MAAMzB,SAASyB,QAAQ3B,UAAU6B,IAAI;QACvC;QACA,OAAO;IACT,EAAE,OAAM;QACN,OAAO;IACT;AACF;AAEA,eAAeC,yBAAyBC,OAAgC;IACtE,MAAMC,MAAMD,QAAQC,GAAG,IAAIC,QAAQD,GAAG;IACtC,IAAIE,OAAOC,MAAM,CAACH,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H,QAAQmG,SAAS;YAErB;YACA,MAAMa;QACR;QAEA,IAAIM;QACJ,IAAI;YACFA,aAAaC,KAAKC,KAAK,CAACtC,OAAOxB,MAAM;QACvC,EAAE,OAAM;YACN,MAAM,IAAI+D,MAAM;QAClB;QAEA,MAAMvB,WAAWlH,4BAA4BsI;QAC7C,OAAOrB,kBAAkBC,UAAUlG,QAAQmG,SAAS;IACtD,SAAU;QACR,MAAM7H,GAAGuH,YAAY;YAAE6B,WAAW;YAAMC,OAAO;QAAK;IACtD;AACF"}
@@ -28,6 +28,7 @@ export interface DurableAgentBase {
28
28
  name: string;
29
29
  mode: typeof AGENT_MODES.DURABLE;
30
30
  cwd: string;
31
+ sessionFilePath?: string | null;
31
32
  state: DurableAgentState;
32
33
  sessionHealth: DurableSessionHealth;
33
34
  createdAt: string;
@@ -1 +1 @@
1
- {"version":3,"file":"DurableAgent.d.ts","sourceRoot":"","sources":["../../src/durable/DurableAgent.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,SAAS,GAAG,UAAU,CAAC;AACjE,MAAM,MAAM,oBAAoB,GAAG,eAAe,GAAG,SAAS,GAAG,SAAS,GAAG,UAAU,CAAC;AACxF,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,QAAQ,GAAG,aAAa,CAAC;AACtE,MAAM,MAAM,gBAAgB,GACxB,oBAAoB,GACpB,oBAAoB,GACpB,YAAY,GACZ,aAAa,GACb,mBAAmB,GACnB,qBAAqB,GACrB,gBAAgB,CAAC;AAErB,eAAO,MAAM,WAAW;;;CAGd,CAAC;AAEX,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;IACjC,SAAS,EAAE,MAAM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IACtD,QAAQ,EAAE,IAAI,CAAC;IACf,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,MAAM,YAAY,GAAG,kBAAkB,GAAG,iBAAiB,GAAG,cAAc,CAAC;AAEnF,qBAAa,iBAAkB,SAAQ,KAAK;aAGxB,IAAI,EAAE,MAAM;gBAD5B,OAAO,EAAE,MAAM,EACC,IAAI,EAAE,MAAM;CAK/B;AAED,qBAAa,qBAAsB,SAAQ,iBAAiB;aAExC,OAAO,EAAE,MAAM;gBAAf,OAAO,EAAE,MAAM,EAC/B,SAAS,EAAE,MAAM;CAKpB;AAED,qBAAa,yBAA0B,SAAQ,iBAAiB;aAClC,SAAS,EAAE,MAAM;gBAAjB,SAAS,EAAE,MAAM;CAI9C;AAED,qBAAa,2BAA4B,SAAQ,iBAAiB;gBACpD,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,6BAA8B,SAAQ,iBAAiB;aACtC,SAAS,EAAE,MAAM;gBAAjB,SAAS,EAAE,MAAM;CAI9C;AAED,qBAAa,gBAAiB,SAAQ,iBAAiB;gBACzC,OAAO,EAAE,MAAM,EAAE,IAAI,SAAwB;CAI1D;AAED,MAAM,MAAM,mBAAmB,GAC3B,gBAAgB,GAChB,eAAe,GACf,wBAAwB,GACxB,mBAAmB,GACnB,sBAAsB,GACtB,uBAAuB,GACvB,uBAAuB,CAAC;AAE5B,qBAAa,eAAgB,SAAQ,iBAAiB;gBACxC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB;CAIvD;AAED,qBAAa,YAAa,SAAQ,iBAAiB;gBACrC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,gBAA+B;CAInE"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/durable/DurableAgent.ts"],"sourcesContent":["export type DurableAgentState = \"ready\" | \"running\" | \"degraded\";\nexport type DurableSessionHealth = \"uninitialized\" | \"healthy\" | \"unknown\" | \"mismatch\";\nexport type DurableRunStatus = \"succeeded\" | \"failed\" | \"interrupted\";\nexport type PiPrintErrorCode =\n | \"PI_CLI_UNAVAILABLE\"\n | \"PI_CLI_UNSUPPORTED\"\n | \"PI_PROCESS\"\n | \"PI_PROTOCOL\"\n | \"PI_RESULT_MISSING\"\n | \"PI_SESSION_MISMATCH\"\n | \"PI_UNSUPPORTED\";\n\nexport const AGENT_MODES = {\n INTERACTIVE: \"interactive\",\n DURABLE: \"durable\",\n} as const;\n\nexport interface ProcessIdentity {\n pid: number;\n startedAt: string;\n}\n\nexport interface DurableActiveRun {\n token: string;\n owner: ProcessIdentity;\n provider: ProcessIdentity | null;\n startedAt: string;\n}\n\nexport interface DurableLastResult {\n status: DurableRunStatus;\n completedAt: string;\n exitCode: number | null;\n summary: string;\n}\n\nexport type DurableProvider = \"claude\" | \"codex\" | \"pi\";\n\nexport interface DurableAgentBase {\n id: string;\n name: string;\n mode: typeof AGENT_MODES.DURABLE;\n cwd: string;\n state: DurableAgentState;\n sessionHealth: DurableSessionHealth;\n createdAt: string;\n updatedAt: string;\n lastActiveAt: string | null;\n lastResult: DurableLastResult | null;\n activeRun: DurableActiveRun | null;\n}\n\nexport interface ClaudeDurableAgent extends DurableAgentBase {\n provider: \"claude\";\n providerSessionId: string;\n}\n\nexport interface CodexDurableAgent extends DurableAgentBase {\n provider: \"codex\";\n providerSessionId: string | null;\n}\n\nexport interface PiDurableAgent extends DurableAgentBase {\n provider: \"pi\";\n providerSessionId: string;\n}\n\nexport type DurableAgent = ClaudeDurableAgent | CodexDurableAgent | PiDurableAgent;\n\nexport class DurableAgentError extends Error {\n constructor(\n message: string,\n public readonly code: string,\n ) {\n super(message);\n this.name = \"DurableAgentError\";\n }\n}\n\nexport class DurableAgentBusyError extends DurableAgentError {\n constructor(\n public readonly agentId: string,\n agentName: string,\n ) {\n super(`Durable agent \"${agentName}\" is busy.`, \"DURABLE_AGENT_BUSY\");\n this.name = \"DurableAgentBusyError\";\n }\n}\n\nexport class DurableAgentNotFoundError extends DurableAgentError {\n constructor(public readonly reference: string) {\n super(`Durable agent \"${reference}\" was not found.`, \"DURABLE_AGENT_NOT_FOUND\");\n this.name = \"DurableAgentNotFoundError\";\n }\n}\n\nexport class DurableAgentRepositoryError extends DurableAgentError {\n constructor(message: string) {\n super(message, \"DURABLE_AGENT_REPOSITORY\");\n this.name = \"DurableAgentRepositoryError\";\n }\n}\n\nexport class DurableAgentNameConflictError extends DurableAgentError {\n constructor(public readonly agentName: string) {\n super(`Durable agent name \"${agentName}\" is already in use.`, \"DURABLE_AGENT_NAME_CONFLICT\");\n this.name = \"DurableAgentNameConflictError\";\n }\n}\n\nexport class ClaudePrintError extends DurableAgentError {\n constructor(message: string, code = \"CLAUDE_PRINT_FAILED\") {\n super(message, code);\n this.name = \"ClaudePrintError\";\n }\n}\n\nexport type CodexPrintErrorCode =\n | \"CODEX_PROTOCOL\"\n | \"CODEX_PROCESS\"\n | \"CODEX_SESSION_MISMATCH\"\n | \"CODEX_UNSUPPORTED\"\n | \"CODEX_RESULT_MISSING\"\n | \"CODEX_CLI_UNSUPPORTED\"\n | \"CODEX_CLI_UNAVAILABLE\";\n\nexport class CodexPrintError extends DurableAgentError {\n constructor(message: string, code: CodexPrintErrorCode) {\n super(message, code);\n this.name = \"CodexPrintError\";\n }\n}\n\nexport class PiPrintError extends DurableAgentError {\n constructor(message: string, code: PiPrintErrorCode = \"PI_PROCESS\") {\n super(message, code);\n this.name = \"PiPrintError\";\n }\n}\n"],"names":["AGENT_MODES","INTERACTIVE","DURABLE","DurableAgentError","Error","message","code","name","DurableAgentBusyError","agentId","agentName","DurableAgentNotFoundError","reference","DurableAgentRepositoryError","DurableAgentNameConflictError","ClaudePrintError","CodexPrintError","PiPrintError"],"mappings":"AAYA,OAAO,MAAMA,cAAc;IACzBC,aAAa;IACbC,SAAS;AACX,EAAW;AAsDX,OAAO,MAAMC,0BAA0BC;;IACrC,YACEC,OAAe,EACf,AAAgBC,IAAY,CAC5B;QACA,KAAK,CAACD,eAFUC,OAAAA;QAGhB,IAAI,CAACC,IAAI,GAAG;IACd;AACF;AAEA,OAAO,MAAMC,8BAA8BL;;IACzC,YACE,AAAgBM,OAAe,EAC/BC,SAAiB,CACjB;QACA,KAAK,CAAC,CAAC,eAAe,EAAEA,UAAU,UAAU,CAAC,EAAE,4BAH/BD,UAAAA;QAIhB,IAAI,CAACF,IAAI,GAAG;IACd;AACF;AAEA,OAAO,MAAMI,kCAAkCR;;IAC7C,YAAY,AAAgBS,SAAiB,CAAE;QAC7C,KAAK,CAAC,CAAC,eAAe,EAAEA,UAAU,gBAAgB,CAAC,EAAE,iCAD3BA,YAAAA;QAE1B,IAAI,CAACL,IAAI,GAAG;IACd;AACF;AAEA,OAAO,MAAMM,oCAAoCV;IAC/C,YAAYE,OAAe,CAAE;QAC3B,KAAK,CAACA,SAAS;QACf,IAAI,CAACE,IAAI,GAAG;IACd;AACF;AAEA,OAAO,MAAMO,sCAAsCX;;IACjD,YAAY,AAAgBO,SAAiB,CAAE;QAC7C,KAAK,CAAC,CAAC,oBAAoB,EAAEA,UAAU,oBAAoB,CAAC,EAAE,qCADpCA,YAAAA;QAE1B,IAAI,CAACH,IAAI,GAAG;IACd;AACF;AAEA,OAAO,MAAMQ,yBAAyBZ;IACpC,YAAYE,OAAe,EAAEC,OAAO,qBAAqB,CAAE;QACzD,KAAK,CAACD,SAASC;QACf,IAAI,CAACC,IAAI,GAAG;IACd;AACF;AAWA,OAAO,MAAMS,wBAAwBb;IACnC,YAAYE,OAAe,EAAEC,IAAyB,CAAE;QACtD,KAAK,CAACD,SAASC;QACf,IAAI,CAACC,IAAI,GAAG;IACd;AACF;AAEA,OAAO,MAAMU,qBAAqBd;IAChC,YAAYE,OAAe,EAAEC,OAAyB,YAAY,CAAE;QAClE,KAAK,CAACD,SAASC;QACf,IAAI,CAACC,IAAI,GAAG;IACd;AACF"}
1
+ {"version":3,"sources":["../../src/durable/DurableAgent.ts"],"sourcesContent":["export type DurableAgentState = \"ready\" | \"running\" | \"degraded\";\nexport type DurableSessionHealth = \"uninitialized\" | \"healthy\" | \"unknown\" | \"mismatch\";\nexport type DurableRunStatus = \"succeeded\" | \"failed\" | \"interrupted\";\nexport type PiPrintErrorCode =\n | \"PI_CLI_UNAVAILABLE\"\n | \"PI_CLI_UNSUPPORTED\"\n | \"PI_PROCESS\"\n | \"PI_PROTOCOL\"\n | \"PI_RESULT_MISSING\"\n | \"PI_SESSION_MISMATCH\"\n | \"PI_UNSUPPORTED\";\n\nexport const AGENT_MODES = {\n INTERACTIVE: \"interactive\",\n DURABLE: \"durable\",\n} as const;\n\nexport interface ProcessIdentity {\n pid: number;\n startedAt: string;\n}\n\nexport interface DurableActiveRun {\n token: string;\n owner: ProcessIdentity;\n provider: ProcessIdentity | null;\n startedAt: string;\n}\n\nexport interface DurableLastResult {\n status: DurableRunStatus;\n completedAt: string;\n exitCode: number | null;\n summary: string;\n}\n\nexport type DurableProvider = \"claude\" | \"codex\" | \"pi\";\n\nexport interface DurableAgentBase {\n id: string;\n name: string;\n mode: typeof AGENT_MODES.DURABLE;\n cwd: string;\n sessionFilePath?: string | null;\n state: DurableAgentState;\n sessionHealth: DurableSessionHealth;\n createdAt: string;\n updatedAt: string;\n lastActiveAt: string | null;\n lastResult: DurableLastResult | null;\n activeRun: DurableActiveRun | null;\n}\n\nexport interface ClaudeDurableAgent extends DurableAgentBase {\n provider: \"claude\";\n providerSessionId: string;\n}\n\nexport interface CodexDurableAgent extends DurableAgentBase {\n provider: \"codex\";\n providerSessionId: string | null;\n}\n\nexport interface PiDurableAgent extends DurableAgentBase {\n provider: \"pi\";\n providerSessionId: string;\n}\n\nexport type DurableAgent = ClaudeDurableAgent | CodexDurableAgent | PiDurableAgent;\n\nexport class DurableAgentError extends Error {\n constructor(\n message: string,\n public readonly code: string,\n ) {\n super(message);\n this.name = \"DurableAgentError\";\n }\n}\n\nexport class DurableAgentBusyError extends DurableAgentError {\n constructor(\n public readonly agentId: string,\n agentName: string,\n ) {\n super(`Durable agent \"${agentName}\" is busy.`, \"DURABLE_AGENT_BUSY\");\n this.name = \"DurableAgentBusyError\";\n }\n}\n\nexport class DurableAgentNotFoundError extends DurableAgentError {\n constructor(public readonly reference: string) {\n super(`Durable agent \"${reference}\" was not found.`, \"DURABLE_AGENT_NOT_FOUND\");\n this.name = \"DurableAgentNotFoundError\";\n }\n}\n\nexport class DurableAgentRepositoryError extends DurableAgentError {\n constructor(message: string) {\n super(message, \"DURABLE_AGENT_REPOSITORY\");\n this.name = \"DurableAgentRepositoryError\";\n }\n}\n\nexport class DurableAgentNameConflictError extends DurableAgentError {\n constructor(public readonly agentName: string) {\n super(`Durable agent name \"${agentName}\" is already in use.`, \"DURABLE_AGENT_NAME_CONFLICT\");\n this.name = \"DurableAgentNameConflictError\";\n }\n}\n\nexport class ClaudePrintError extends DurableAgentError {\n constructor(message: string, code = \"CLAUDE_PRINT_FAILED\") {\n super(message, code);\n this.name = \"ClaudePrintError\";\n }\n}\n\nexport type CodexPrintErrorCode =\n | \"CODEX_PROTOCOL\"\n | \"CODEX_PROCESS\"\n | \"CODEX_SESSION_MISMATCH\"\n | \"CODEX_UNSUPPORTED\"\n | \"CODEX_RESULT_MISSING\"\n | \"CODEX_CLI_UNSUPPORTED\"\n | \"CODEX_CLI_UNAVAILABLE\";\n\nexport class CodexPrintError extends DurableAgentError {\n constructor(message: string, code: CodexPrintErrorCode) {\n super(message, code);\n this.name = \"CodexPrintError\";\n }\n}\n\nexport class PiPrintError extends DurableAgentError {\n constructor(message: string, code: PiPrintErrorCode = \"PI_PROCESS\") {\n super(message, code);\n this.name = \"PiPrintError\";\n }\n}\n"],"names":["AGENT_MODES","INTERACTIVE","DURABLE","DurableAgentError","Error","message","code","name","DurableAgentBusyError","agentId","agentName","DurableAgentNotFoundError","reference","DurableAgentRepositoryError","DurableAgentNameConflictError","ClaudePrintError","CodexPrintError","PiPrintError"],"mappings":"AAYA,OAAO,MAAMA,cAAc;IACzBC,aAAa;IACbC,SAAS;AACX,EAAW;AAuDX,OAAO,MAAMC,0BAA0BC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,11 @@
1
+ export type AntigravityOAuthCredential = {
2
+ accessToken: string;
3
+ projectId: string | null;
4
+ };
5
+ export type AntigravityCredentialOptions = {
6
+ env?: NodeJS.ProcessEnv;
7
+ now?: () => Date;
8
+ readFile?: (target: string, encoding: BufferEncoding) => Promise<string>;
9
+ };
10
+ export declare function resolveAntigravityOAuthCredential(options?: AntigravityCredentialOptions): Promise<AntigravityOAuthCredential | null>;
11
+ //# sourceMappingURL=credentials.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../../src/harnesses/antigravity/credentials.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,0BAA0B,GAAG;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;IACjB,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CAC1E,CAAC;AAwEF,wBAAsB,iCAAiC,CACrD,OAAO,GAAE,4BAAiC,GACzC,OAAO,CAAC,0BAA0B,GAAG,IAAI,CAAC,CA+B5C"}
@@ -0,0 +1,83 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ const EXPIRY_SAFETY_WINDOW_MS = 60_000;
5
+ function record(value) {
6
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
7
+ }
8
+ function nonEmptyText(value) {
9
+ if (typeof value !== "string") return null;
10
+ const trimmed = value.trim();
11
+ return trimmed.length > 0 ? trimmed : null;
12
+ }
13
+ function parseExpiryMs(value) {
14
+ if (typeof value === "number" && Number.isFinite(value)) {
15
+ return value > 1e12 ? value : value * 1000;
16
+ }
17
+ const text = nonEmptyText(value);
18
+ if (!text) return null;
19
+ const parsed = Date.parse(text);
20
+ return Number.isNaN(parsed) ? null : parsed;
21
+ }
22
+ function isExpired(expiryValue, nowMs) {
23
+ const expiryMs = parseExpiryMs(expiryValue);
24
+ if (expiryMs === null) return false;
25
+ return expiryMs - nowMs <= EXPIRY_SAFETY_WINDOW_MS;
26
+ }
27
+ function parseCredentialPayload(raw, nowMs) {
28
+ let parsed;
29
+ try {
30
+ parsed = JSON.parse(raw);
31
+ } catch {
32
+ return null;
33
+ }
34
+ const root = record(parsed);
35
+ if (!root) return null;
36
+ const nestedToken = record(root.token);
37
+ const accessToken = nonEmptyText(nestedToken?.access_token ?? nestedToken?.accessToken ?? root.access_token ?? root.accessToken);
38
+ if (!accessToken) return null;
39
+ const expiry = nestedToken?.expiry ?? nestedToken?.expiry_date ?? nestedToken?.expiryDate ?? root.expiry ?? root.expiry_date ?? root.expiryDate;
40
+ if (isExpired(expiry, nowMs)) return null;
41
+ const projectId = nonEmptyText(root.project_id ?? root.projectID ?? root.projectId);
42
+ return {
43
+ accessToken,
44
+ projectId
45
+ };
46
+ }
47
+ async function readCredentialFile(filePath, nowMs, read) {
48
+ try {
49
+ const raw = await read(filePath, "utf8");
50
+ return parseCredentialPayload(raw, nowMs);
51
+ } catch {
52
+ return null;
53
+ }
54
+ }
55
+ export async function resolveAntigravityOAuthCredential(options = {}) {
56
+ const env = options.env ?? process.env;
57
+ const nowMs = (options.now?.() ?? new Date()).getTime();
58
+ const envAccessToken = nonEmptyText(env.ANTIGRAVITY_ACCESS_TOKEN);
59
+ if (envAccessToken) {
60
+ return {
61
+ accessToken: envAccessToken,
62
+ projectId: nonEmptyText(env.ANTIGRAVITY_PROJECT_ID)
63
+ };
64
+ }
65
+ const envCredentialsJson = nonEmptyText(env.ANTIGRAVITY_OAUTH_CREDENTIALS_JSON);
66
+ if (envCredentialsJson) {
67
+ const fromJson = parseCredentialPayload(envCredentialsJson, nowMs);
68
+ if (fromJson) return fromJson;
69
+ }
70
+ const home = nonEmptyText(env.HOME) ?? os.homedir();
71
+ const read = options.readFile ?? readFile;
72
+ const candidateFiles = [
73
+ path.join(home, ".gemini", "antigravity-cli", "antigravity-oauth-token"),
74
+ path.join(home, ".codexbar", "antigravity", "oauth_creds.json")
75
+ ];
76
+ for (const filePath of candidateFiles){
77
+ const credential = await readCredentialFile(filePath, nowMs, read);
78
+ if (credential) return credential;
79
+ }
80
+ return null;
81
+ }
82
+
83
+ //# sourceMappingURL=credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/harnesses/antigravity/credentials.ts"],"sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport os from \"node:os\";\nimport path from \"node:path\";\n\nconst EXPIRY_SAFETY_WINDOW_MS = 60_000;\n\ntype UnknownRecord = Record<string, unknown>;\n\nexport type AntigravityOAuthCredential = {\n accessToken: string;\n projectId: string | null;\n};\n\nexport type AntigravityCredentialOptions = {\n env?: NodeJS.ProcessEnv;\n now?: () => Date;\n readFile?: (target: string, encoding: BufferEncoding) => Promise<string>;\n};\n\nfunction record(value: unknown): UnknownRecord | null {\n return value !== null && typeof value === \"object\" && !Array.isArray(value)\n ? (value as UnknownRecord)\n : null;\n}\n\nfunction nonEmptyText(value: unknown): string | null {\n if (typeof value !== \"string\") return null;\n const trimmed = value.trim();\n return trimmed.length > 0 ? trimmed : null;\n}\n\nfunction parseExpiryMs(value: unknown): number | null {\n if (typeof value === \"number\" && Number.isFinite(value)) {\n return value > 1e12 ? value : value * 1000;\n }\n const text = nonEmptyText(value);\n if (!text) return null;\n const parsed = Date.parse(text);\n return Number.isNaN(parsed) ? null : parsed;\n}\n\nfunction isExpired(expiryValue: unknown, nowMs: number): boolean {\n const expiryMs = parseExpiryMs(expiryValue);\n if (expiryMs === null) return false;\n return expiryMs - nowMs <= EXPIRY_SAFETY_WINDOW_MS;\n}\n\nfunction parseCredentialPayload(raw: string, nowMs: number): AntigravityOAuthCredential | null {\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch {\n return null;\n }\n const root = record(parsed);\n if (!root) return null;\n\n const nestedToken = record(root.token);\n const accessToken = nonEmptyText(\n nestedToken?.access_token ?? nestedToken?.accessToken ?? root.access_token ?? root.accessToken,\n );\n if (!accessToken) return null;\n\n const expiry =\n nestedToken?.expiry ??\n nestedToken?.expiry_date ??\n nestedToken?.expiryDate ??\n root.expiry ??\n root.expiry_date ??\n root.expiryDate;\n if (isExpired(expiry, nowMs)) return null;\n\n const projectId = nonEmptyText(root.project_id ?? root.projectID ?? root.projectId);\n return { accessToken, projectId };\n}\n\nasync function readCredentialFile(\n filePath: string,\n nowMs: number,\n read: (target: string, encoding: BufferEncoding) => Promise<string>,\n): Promise<AntigravityOAuthCredential | null> {\n try {\n const raw = await read(filePath, \"utf8\");\n return parseCredentialPayload(raw, nowMs);\n } catch {\n return null;\n }\n}\n\nexport async function resolveAntigravityOAuthCredential(\n options: AntigravityCredentialOptions = {},\n): Promise<AntigravityOAuthCredential | null> {\n const env = options.env ?? process.env;\n const nowMs = (options.now?.() ?? new Date()).getTime();\n\n const envAccessToken = nonEmptyText(env.ANTIGRAVITY_ACCESS_TOKEN);\n if (envAccessToken) {\n return {\n accessToken: envAccessToken,\n projectId: nonEmptyText(env.ANTIGRAVITY_PROJECT_ID),\n };\n }\n\n const envCredentialsJson = nonEmptyText(env.ANTIGRAVITY_OAUTH_CREDENTIALS_JSON);\n if (envCredentialsJson) {\n const fromJson = parseCredentialPayload(envCredentialsJson, nowMs);\n if (fromJson) return fromJson;\n }\n\n const home = nonEmptyText(env.HOME) ?? os.homedir();\n const read = options.readFile ?? readFile;\n const candidateFiles = [\n path.join(home, \".gemini\", \"antigravity-cli\", \"antigravity-oauth-token\"),\n path.join(home, \".codexbar\", \"antigravity\", \"oauth_creds.json\"),\n ];\n\n for (const filePath of candidateFiles) {\n const credential = await readCredentialFile(filePath, nowMs, read);\n if (credential) return credential;\n }\n\n return null;\n}\n"],"names":["readFile","os","path","EXPIRY_SAFETY_WINDOW_MS","record","value","Array","isArray","nonEmptyText","trimmed","trim","length","parseExpiryMs","Number","isFinite","text","parsed","Date","parse","isNaN","isExpired","expiryValue","nowMs","expiryMs","parseCredentialPayload","raw","JSON","root","nestedToken","token","accessToken","access_token","expiry","expiry_date","expiryDate","projectId","project_id","projectID","readCredentialFile","filePath","read","resolveAntigravityOAuthCredential","options","env","process","now","getTime","envAccessToken","ANTIGRAVITY_ACCESS_TOKEN","ANTIGRAVITY_PROJECT_ID","envCredentialsJson","ANTIGRAVITY_OAUTH_CREDENTIALS_JSON","fromJson","home","HOME","homedir","candidateFiles","join","credential"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,mBAAmB;AAC5C,OAAOC,QAAQ,UAAU;AACzB,OAAOC,UAAU,YAAY;AAE7B,MAAMC,0BAA0B;AAehC,SAASC,OAAOC,KAAc;IAC5B,OAAOA,UAAU,QAAQ,OAAOA,UAAU,YAAY,CAACC,MAAMC,OAAO,CAACF,SAChEA,QACD;AACN;AAEA,SAASG,aAAaH,KAAc;IAClC,IAAI,OAAOA,UAAU,UAAU,OAAO;IACtC,MAAMI,UAAUJ,MAAMK,IAAI;IAC1B,OAAOD,QAAQE,MAAM,GAAG,IAAIF,UAAU;AACxC;AAEA,SAASG,cAAcP,KAAc;IACnC,IAAI,OAAOA,UAAU,YAAYQ,OAAOC,QAAQ,CAACT,QAAQ;QACvD,OAAOA,QAAQ,OAAOA,QAAQA,QAAQ;IACxC;IACA,MAAMU,OAAOP,aAAaH;IAC1B,IAAI,CAACU,MAAM,OAAO;IAClB,MAAMC,SAASC,KAAKC,KAAK,CAACH;IAC1B,OAAOF,OAAOM,KAAK,CAACH,UAAU,OAAOA;AACvC;AAEA,SAASI,UAAUC,WAAoB,EAAEC,KAAa;IACpD,MAAMC,WAAWX,cAAcS;IAC/B,IAAIE,aAAa,MAAM,OAAO;IAC9B,OAAOA,WAAWD,SAASnB;AAC7B;AAEA,SAASqB,uBAAuBC,GAAW,EAAEH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8B,UAAU,OAAOA;IACvB;IAEA,MAAMC,OAAO7C,aAAamC,IAAIW,IAAI,KAAKrD,GAAGsD,OAAO;IACjD,MAAMf,OAAOE,QAAQ1C,QAAQ,IAAIA;IACjC,MAAMwD,iBAAiB;QACrBtD,KAAKuD,IAAI,CAACJ,MAAM,WAAW,mBAAmB;QAC9CnD,KAAKuD,IAAI,CAACJ,MAAM,aAAa,eAAe;KAC7C;IAED,KAAK,MAAMd,YAAYiB,eAAgB;QACrC,MAAME,aAAa,MAAMpB,mBAAmBC,UAAUjB,OAAOkB;QAC7D,IAAIkB,YAAY,OAAOA;IACzB;IAEA,OAAO;AACT"}
@@ -20,8 +20,9 @@ export interface PiProcessSessionMatches {
20
20
  * and only their head (<= 64 KiB) is read for session id and cwd;
21
21
  * - heads are cached per file (dev/ino/size) across calls on one instance;
22
22
  * - a project dir whose scan matched none of its processes is skipped until
23
- * its mtime changes (a session file was added or removed) or a process it
24
- * has not seen needs it.
23
+ * its mtime changes, its jsonl count changes (when mtime is in the current
24
+ * second — directory mtimes are often second-granular), or a process it has
25
+ * not seen needs it.
25
26
  *
26
27
  * Reuse one instance across refreshes to benefit from the caches.
27
28
  */
@@ -1 +1 @@
1
- {"version":3,"file":"PiSessionLocator.d.ts","sourceRoot":"","sources":["../../../src/harnesses/pi/PiSessionLocator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAA4B,KAAK,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAErF,OAAO,EAML,KAAK,WAAW,EACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAEL,eAAe,EAEhB,MAAM,sBAAsB,CAAC;AAG9B,MAAM,WAAW,uBAAuB;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,uBAAuB;IACtC,aAAa,EAAE,WAAW,EAAE,CAAC;IAC7B,QAAQ,EAAE,WAAW,EAAE,CAAC;CACz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AAM,WAAW,uBAAuB;IACtC,aAAa,EAAE,WAAW,EAAE,CAAC;IAC7B,QAAQ,EAAE,WAAW,EAAE,CAAC;CACzB;AA4BD;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,gBAAgB;IAQzB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAPzB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiC;IACvD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAmC;IAC/D,OAAO,CAAC,UAAU,CAAK;gBAGrB,OAAO,GAAE,uBAA4B,EACpB,MAAM,GAAE,eAAuC;IAKlE,qBAAqB,CAAC,SAAS,EAAE,WAAW,EAAE,GAAG,uBAAuB;IAoBxE;;;;OAIG;IACH,oBAAoB,CAAC,SAAS,GAAE,WAAW,EAAO,GAAG,WAAW,EAAE;IAIlE,8BAA8B,IAAI,MAAM,EAAE;IAI1C,8BAA8B,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE;IAS3D;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;IAiDzB,OAAO,CAAC,sBAAsB;IAmC9B,sFAAsF;IACtF,OAAO,CAAC,QAAQ;IA2BhB,2FAA2F;IAC3F,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,qBAAqB;IAY7B,OAAO,CAAC,UAAU;IAMlB,OAAO,CAAC,iBAAiB;IAQzB,OAAO,CAAC,iBAAiB;IAezB,OAAO,CAAC,gBAAgB;CAIzB"}
@@ -16,8 +16,9 @@ import { homeDir } from "../shared.js";
16
16
  * and only their head (<= 64 KiB) is read for session id and cwd;
17
17
  * - heads are cached per file (dev/ino/size) across calls on one instance;
18
18
  * - a project dir whose scan matched none of its processes is skipped until
19
- * its mtime changes (a session file was added or removed) or a process it
20
- * has not seen needs it.
19
+ * its mtime changes, its jsonl count changes (when mtime is in the current
20
+ * second — directory mtimes are often second-granular), or a process it has
21
+ * not seen needs it.
21
22
  *
22
23
  * Reuse one instance across refreshes to benefit from the caches.
23
24
  */ export class PiSessionLocator {
@@ -107,11 +108,16 @@ import { homeDir } from "../shared.js";
107
108
  // An unmatched process never held a session, so dropping one cannot free
108
109
  // a session for another; only a dir change or an unseen process can.
109
110
  const unchanged = noMatch !== undefined && noMatch.dirMtimeMs === scan.dirMtimeMs && scan.processes.every((proc)=>noMatch.processKeys.has(processKey(proc)));
110
- if (unchanged) {
111
- scans.delete(projectDir);
112
- } else {
111
+ if (!unchanged) {
113
112
  this.noMatchDirs.delete(projectDir);
113
+ continue;
114
+ }
115
+ const ambiguousMtimeSecond = Math.floor(scan.dirMtimeMs / 1000) === Math.floor(Date.now() / 1000);
116
+ if (ambiguousMtimeSecond && listJsonl(projectDir).length !== noMatch.jsonlCount) {
117
+ this.noMatchDirs.delete(projectDir);
118
+ continue;
114
119
  }
120
+ scans.delete(projectDir);
115
121
  }
116
122
  return scans;
117
123
  }
@@ -120,7 +126,9 @@ import { homeDir } from "../shared.js";
120
126
  for (const [projectDir, scan] of scans){
121
127
  const cwd = scan.processes[0]?.cwd ?? "";
122
128
  const startTimes = scan.processes.map((proc)=>proc.startTime?.getTime() ?? 0);
123
- for (const fileName of listJsonl(projectDir)){
129
+ const fileNames = listJsonl(projectDir);
130
+ scan.jsonlCount = fileNames.length;
131
+ for (const fileName of fileNames){
124
132
  const filePath = path.join(projectDir, fileName);
125
133
  const stat = safeStat(filePath);
126
134
  if (!stat?.isFile()) continue;
@@ -170,6 +178,7 @@ import { homeDir } from "../shared.js";
170
178
  if (scan.processes.some((proc)=>matchedPids.has(proc.pid))) continue;
171
179
  this.noMatchDirs.set(projectDir, {
172
180
  dirMtimeMs: scan.dirMtimeMs,
181
+ jsonlCount: scan.jsonlCount ?? listJsonl(projectDir).length,
173
182
  processKeys: new Set(scan.processes.map(processKey))
174
183
  });
175
184
  }