@cortexkit/opencode-antigravity-auth 3.0.21 → 3.0.23
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 +565 -444
- package/dist/cli.js.map +4 -4
- package/dist/cli.meta.json +99 -49
- package/dist/index.js +1151 -656
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +156 -56
- package/dist/server.js +1180 -680
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +2 -2
- package/dist/src/common-auth-embedded/fs/with-lock.js +37 -10
- package/dist/src/common-auth-embedded/quota/format.d.ts +9 -4
- package/dist/src/common-auth-embedded/quota/format.js +45 -26
- package/dist/src/common-auth-embedded/quota-sidebar/index.tsx +56 -32
- package/dist/src/common-auth-embedded/routing-accessor/index.d.ts +62 -0
- package/dist/src/common-auth-embedded/routing-accessor/index.js +128 -0
- package/dist/src/common-auth-embedded/source-output.json +42 -22
- package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
- package/dist/src/plugin/index.d.ts.map +1 -1
- package/dist/src/plugin/index.js +2 -0
- package/dist/src/plugin/index.js.map +1 -1
- package/dist/src/plugin/request.d.ts.map +1 -1
- package/dist/src/plugin/request.js +1 -0
- package/dist/src/plugin/request.js.map +1 -1
- package/dist/src/plugin/shared/request-services.d.ts +6 -0
- package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/src/plugin/shared/request-services.js +89 -2
- package/dist/src/plugin/shared/request-services.js.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.js +4 -0
- package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
- package/dist/src/plugin/shared/vault-routing-purpose.d.ts +12 -0
- package/dist/src/plugin/shared/vault-routing-purpose.d.ts.map +1 -0
- package/dist/src/plugin/shared/vault-routing-purpose.js +18 -0
- package/dist/src/plugin/shared/vault-routing-purpose.js.map +1 -0
- package/dist/src/plugin/shared/vault-routing.d.ts +39 -0
- package/dist/src/plugin/shared/vault-routing.d.ts.map +1 -0
- package/dist/src/plugin/shared/vault-routing.js +213 -0
- package/dist/src/plugin/shared/vault-routing.js.map +1 -0
- package/dist/src/plugin/types.d.ts +1 -0
- package/dist/src/plugin/types.d.ts.map +1 -1
- package/dist/src/runtime-layout.d.ts.map +1 -1
- package/dist/src/runtime-layout.js +14 -3
- package/dist/src/runtime-layout.js.map +1 -1
- package/dist/src/tui/sidebar-frame.d.ts.map +1 -1
- package/dist/src/tui/sidebar-frame.js +18 -16
- package/dist/src/tui/sidebar-frame.js.map +1 -1
- package/dist/src/vault-folder.d.ts.map +1 -1
- package/dist/src/vault-folder.js +51 -14
- package/dist/src/vault-folder.js.map +1 -1
- package/dist/src/version-fence.d.ts +5 -0
- package/dist/src/version-fence.d.ts.map +1 -1
- package/dist/src/version-fence.js +64 -7
- package/dist/src/version-fence.js.map +1 -1
- package/dist/tui-build-map.json +13 -13
- package/dist/tui-ga-build-map.json +13 -13
- package/dist/types/src/common-auth-embedded/quota/format.d.ts +9 -4
- package/dist/types/src/common-auth-embedded/routing-accessor/index.d.ts +62 -0
- package/dist/types/src/plugin/index.d.ts.map +1 -1
- package/dist/types/src/plugin/request.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/request-services.d.ts +6 -0
- package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/vault-routing-purpose.d.ts +12 -0
- package/dist/types/src/plugin/shared/vault-routing-purpose.d.ts.map +1 -0
- package/dist/types/src/plugin/shared/vault-routing.d.ts +39 -0
- package/dist/types/src/plugin/shared/vault-routing.d.ts.map +1 -0
- package/dist/types/src/plugin/types.d.ts +1 -0
- package/dist/types/src/plugin/types.d.ts.map +1 -1
- package/dist/types/src/runtime-layout.d.ts.map +1 -1
- package/dist/types/src/vault-folder.d.ts.map +1 -1
- package/dist/types/src/version-fence.d.ts +5 -0
- package/dist/types/src/version-fence.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/common-auth-embedded/fs/refresh-file-lock.js +2 -2
- package/src/common-auth-embedded/fs/with-lock.js +37 -10
- package/src/common-auth-embedded/quota/format.d.ts +9 -4
- package/src/common-auth-embedded/quota/format.js +45 -26
- package/src/common-auth-embedded/quota-sidebar/index.tsx +56 -32
- package/src/common-auth-embedded/routing-accessor/index.d.ts +62 -0
- package/src/common-auth-embedded/routing-accessor/index.js +128 -0
- package/src/common-auth-embedded/source-output.json +42 -22
- package/src/tui-compiled/common-auth-embedded/quota/format.js +45 -26
- package/src/tui-compiled/common-auth-embedded/quota-sidebar/index.js +165 -148
- package/src/tui-compiled/tui/sidebar-frame.js +17 -16
- package/src/tui-ga-compiled/shared/aef2402f8fc342f0-format.js +45 -26
- package/src/tui-ga-compiled/shared/ced204104a639c9c-sidebar-frame.js +17 -16
- package/src/tui-ga-compiled/shared/e4ec36f367492969-index.js +165 -148
- package/src/tui-ga-raw/shared/aef2402f8fc342f0-format.js +45 -26
- package/src/tui-ga-raw/shared/ced204104a639c9c-sidebar-frame.tsx +21 -19
- package/src/tui-ga-raw/shared/e4ec36f367492969-index.tsx +56 -32
- package/src/tui-raw/common-auth-embedded/quota/format.js +45 -26
- package/src/tui-raw/common-auth-embedded/quota-sidebar/index.tsx +56 -32
- package/src/tui-raw/tui/sidebar-frame.tsx +21 -19
package/dist/index.js
CHANGED
|
@@ -1628,10 +1628,10 @@ async function privateDirectory(path5) {
|
|
|
1628
1628
|
if (errno(error) !== "EEXIST")
|
|
1629
1629
|
throw error;
|
|
1630
1630
|
}
|
|
1631
|
-
const
|
|
1632
|
-
if (!
|
|
1631
|
+
const stat16 = await lstat2(path5);
|
|
1632
|
+
if (!stat16.isDirectory() || stat16.isSymbolicLink())
|
|
1633
1633
|
throw new AccountMigrationError("successor directory is not a regular directory");
|
|
1634
|
-
privateMode(
|
|
1634
|
+
privateMode(stat16.mode, 448);
|
|
1635
1635
|
if (windowsPrivateFiles)
|
|
1636
1636
|
await verifySafeDirectory(path5);
|
|
1637
1637
|
if (!sameFilesystemPath(await realpath(path5), path5))
|
|
@@ -7751,7 +7751,7 @@ async function rmEvictingDir(evictingPath) {
|
|
|
7751
7751
|
});
|
|
7752
7752
|
}
|
|
7753
7753
|
async function sleep(ms) {
|
|
7754
|
-
await new Promise((
|
|
7754
|
+
await new Promise((resolve27) => setTimeout(resolve27, ms));
|
|
7755
7755
|
}
|
|
7756
7756
|
async function acquireFencedFileLock(options) {
|
|
7757
7757
|
const lockPath = `${options.path}.${options.name}.lock`;
|
|
@@ -7867,8 +7867,8 @@ function buildLock(lockPath, evictingPath, ownerId, options, now) {
|
|
|
7867
7867
|
let released = false;
|
|
7868
7868
|
let lost = false;
|
|
7869
7869
|
let lostResolve = null;
|
|
7870
|
-
let lostPromise = new Promise((
|
|
7871
|
-
lostResolve =
|
|
7870
|
+
let lostPromise = new Promise((resolve27) => {
|
|
7871
|
+
lostResolve = resolve27;
|
|
7872
7872
|
});
|
|
7873
7873
|
const markLost = () => {
|
|
7874
7874
|
if (lost)
|
|
@@ -7878,9 +7878,9 @@ function buildLock(lockPath, evictingPath, ownerId, options, now) {
|
|
|
7878
7878
|
clearInterval(renewTimer);
|
|
7879
7879
|
renewTimer = null;
|
|
7880
7880
|
}
|
|
7881
|
-
const
|
|
7881
|
+
const resolve27 = lostResolve;
|
|
7882
7882
|
lostResolve = null;
|
|
7883
|
-
|
|
7883
|
+
resolve27?.();
|
|
7884
7884
|
};
|
|
7885
7885
|
const setupRenew = () => {
|
|
7886
7886
|
if (options.renew === false)
|
|
@@ -8083,7 +8083,7 @@ function writeConsoleLog(level, ...args) {
|
|
|
8083
8083
|
}
|
|
8084
8084
|
function createLogger(module) {
|
|
8085
8085
|
const service = `antigravity.${module}`;
|
|
8086
|
-
const
|
|
8086
|
+
const log17 = (level, message, extra) => {
|
|
8087
8087
|
if (_sink) {
|
|
8088
8088
|
try {
|
|
8089
8089
|
_sink({ service, level, message, extra });
|
|
@@ -8097,10 +8097,10 @@ function createLogger(module) {
|
|
|
8097
8097
|
}
|
|
8098
8098
|
};
|
|
8099
8099
|
return {
|
|
8100
|
-
debug: (message, extra) =>
|
|
8101
|
-
info: (message, extra) =>
|
|
8102
|
-
warn: (message, extra) =>
|
|
8103
|
-
error: (message, extra) =>
|
|
8100
|
+
debug: (message, extra) => log17("debug", message, extra),
|
|
8101
|
+
info: (message, extra) => log17("info", message, extra),
|
|
8102
|
+
warn: (message, extra) => log17("warn", message, extra),
|
|
8103
|
+
error: (message, extra) => log17("error", message, extra)
|
|
8104
8104
|
};
|
|
8105
8105
|
}
|
|
8106
8106
|
var ENV_CONSOLE_LOG, _sink;
|
|
@@ -8503,7 +8503,7 @@ async function saveAccountStorageReplace(path5, incoming) {
|
|
|
8503
8503
|
return mutateAccountStorage(path5, () => incoming);
|
|
8504
8504
|
}
|
|
8505
8505
|
async function clearAccountStorage(path5) {
|
|
8506
|
-
const sleep5 = (ms) => new Promise((
|
|
8506
|
+
const sleep5 = (ms) => new Promise((resolve27) => setTimeout(resolve27, ms));
|
|
8507
8507
|
const lock = await acquireWithRetry(path5, sleep5);
|
|
8508
8508
|
try {
|
|
8509
8509
|
await assertLegacyAccountStorageWritable(path5);
|
|
@@ -8551,7 +8551,7 @@ var init_account_storage = __esm({
|
|
|
8551
8551
|
}
|
|
8552
8552
|
};
|
|
8553
8553
|
RETRY_DELAYS_MS = [100, 200, 400, 800, 1e3];
|
|
8554
|
-
DEFAULT_SLEEP = (ms) => new Promise((
|
|
8554
|
+
DEFAULT_SLEEP = (ms) => new Promise((resolve27) => setTimeout(resolve27, ms));
|
|
8555
8555
|
DEFAULT_BUILD_BACKUP_PATH = (path5, now) => `${path5}.corrupt-${now.toISOString().replace(/[:.]/g, "-")}`;
|
|
8556
8556
|
}
|
|
8557
8557
|
});
|
|
@@ -9753,8 +9753,8 @@ var init_account_manager = __esm({
|
|
|
9753
9753
|
await this.saveInFlight;
|
|
9754
9754
|
return;
|
|
9755
9755
|
}
|
|
9756
|
-
return new Promise((
|
|
9757
|
-
this.savePromiseResolvers.push({ resolve:
|
|
9756
|
+
return new Promise((resolve27, reject) => {
|
|
9757
|
+
this.savePromiseResolvers.push({ resolve: resolve27, reject });
|
|
9758
9758
|
});
|
|
9759
9759
|
}
|
|
9760
9760
|
async dispose() {
|
|
@@ -9797,8 +9797,8 @@ var init_account_manager = __esm({
|
|
|
9797
9797
|
reject(error);
|
|
9798
9798
|
throw error;
|
|
9799
9799
|
}
|
|
9800
|
-
for (const { resolve:
|
|
9801
|
-
|
|
9800
|
+
for (const { resolve: resolve27 } of resolvers)
|
|
9801
|
+
resolve27();
|
|
9802
9802
|
}
|
|
9803
9803
|
async executeSave() {
|
|
9804
9804
|
this.savePending = false;
|
|
@@ -9812,16 +9812,16 @@ var init_account_manager = __esm({
|
|
|
9812
9812
|
}
|
|
9813
9813
|
try {
|
|
9814
9814
|
await this.saveToDisk();
|
|
9815
|
-
for (const { resolve:
|
|
9816
|
-
|
|
9815
|
+
for (const { resolve: resolve27 } of resolvers) {
|
|
9816
|
+
resolve27();
|
|
9817
9817
|
}
|
|
9818
9818
|
} catch (error) {
|
|
9819
9819
|
if (isStorageLockContention(error)) {
|
|
9820
9820
|
this.onDiagnostic?.("Skipped account-state persist due to storage lock contention", {
|
|
9821
9821
|
error: String(error)
|
|
9822
9822
|
});
|
|
9823
|
-
for (const { resolve:
|
|
9824
|
-
|
|
9823
|
+
for (const { resolve: resolve27 } of resolvers) {
|
|
9824
|
+
resolve27();
|
|
9825
9825
|
}
|
|
9826
9826
|
return;
|
|
9827
9827
|
}
|
|
@@ -10310,7 +10310,7 @@ function getHttpsProxy(url) {
|
|
|
10310
10310
|
}
|
|
10311
10311
|
}
|
|
10312
10312
|
function waitForHead(socket, timeoutMs, onTimeout) {
|
|
10313
|
-
return new Promise((
|
|
10313
|
+
return new Promise((resolve27, reject) => {
|
|
10314
10314
|
let buffer = Buffer3.alloc(0);
|
|
10315
10315
|
const timeout = setTimeout(() => {
|
|
10316
10316
|
onTimeout();
|
|
@@ -10333,7 +10333,7 @@ function waitForHead(socket, timeoutMs, onTimeout) {
|
|
|
10333
10333
|
return;
|
|
10334
10334
|
const head = buffer.subarray(0, marker).toString("latin1");
|
|
10335
10335
|
const leftover = buffer.subarray(marker + 4);
|
|
10336
|
-
cleanup2(() =>
|
|
10336
|
+
cleanup2(() => resolve27({ head, leftover }));
|
|
10337
10337
|
};
|
|
10338
10338
|
socket.on("data", onData);
|
|
10339
10339
|
socket.once("error", onError);
|
|
@@ -10347,7 +10347,7 @@ async function connectViaProxy(proxyUrl, targetUrl, timeoutMs, signal, onDebug)
|
|
|
10347
10347
|
port: Number(proxyUrl.port || DEFAULT_PROXY_PORT),
|
|
10348
10348
|
signal: signal ?? void 0
|
|
10349
10349
|
});
|
|
10350
|
-
await new Promise((
|
|
10350
|
+
await new Promise((resolve27, reject) => {
|
|
10351
10351
|
const timeout = setTimeout(() => {
|
|
10352
10352
|
onDebug?.(`agy transport proxy connect timeout after ${timeoutMs}ms`);
|
|
10353
10353
|
proxySocket.destroy();
|
|
@@ -10356,7 +10356,7 @@ async function connectViaProxy(proxyUrl, targetUrl, timeoutMs, signal, onDebug)
|
|
|
10356
10356
|
const cleanup2 = () => clearTimeout(timeout);
|
|
10357
10357
|
proxySocket.once("connect", () => {
|
|
10358
10358
|
cleanup2();
|
|
10359
|
-
|
|
10359
|
+
resolve27();
|
|
10360
10360
|
});
|
|
10361
10361
|
proxySocket.once("error", (error) => {
|
|
10362
10362
|
cleanup2();
|
|
@@ -10381,7 +10381,7 @@ Host: ${targetHost}:${targetPort}\r
|
|
|
10381
10381
|
if (leftover.length > 0) {
|
|
10382
10382
|
proxySocket.unshift(leftover);
|
|
10383
10383
|
}
|
|
10384
|
-
return await new Promise((
|
|
10384
|
+
return await new Promise((resolve27, reject) => {
|
|
10385
10385
|
const tlsOptions = {
|
|
10386
10386
|
socket: proxySocket,
|
|
10387
10387
|
servername: targetHost,
|
|
@@ -10396,7 +10396,7 @@ Host: ${targetHost}:${targetPort}\r
|
|
|
10396
10396
|
const cleanup2 = () => clearTimeout(timeout);
|
|
10397
10397
|
tlsSocket.once("secureConnect", () => {
|
|
10398
10398
|
cleanup2();
|
|
10399
|
-
|
|
10399
|
+
resolve27(tlsSocket);
|
|
10400
10400
|
});
|
|
10401
10401
|
tlsSocket.once("error", (error) => {
|
|
10402
10402
|
cleanup2();
|
|
@@ -10405,7 +10405,7 @@ Host: ${targetHost}:${targetPort}\r
|
|
|
10405
10405
|
});
|
|
10406
10406
|
}
|
|
10407
10407
|
async function connectDirect(targetUrl, timeoutMs, signal, onDebug) {
|
|
10408
|
-
return await new Promise((
|
|
10408
|
+
return await new Promise((resolve27, reject) => {
|
|
10409
10409
|
const tlsOptions = {
|
|
10410
10410
|
host: targetUrl.hostname,
|
|
10411
10411
|
port: Number(targetUrl.port || DEFAULT_HTTPS_PORT),
|
|
@@ -10421,7 +10421,7 @@ async function connectDirect(targetUrl, timeoutMs, signal, onDebug) {
|
|
|
10421
10421
|
const cleanup2 = () => clearTimeout(timeout);
|
|
10422
10422
|
socket.once("secureConnect", () => {
|
|
10423
10423
|
cleanup2();
|
|
10424
|
-
|
|
10424
|
+
resolve27(socket);
|
|
10425
10425
|
});
|
|
10426
10426
|
socket.once("error", (error) => {
|
|
10427
10427
|
cleanup2();
|
|
@@ -11434,7 +11434,7 @@ function displayOrder(left, right) {
|
|
|
11434
11434
|
return left.label < right.label ? -1 : left.label > right.label ? 1 : 0;
|
|
11435
11435
|
}
|
|
11436
11436
|
function quotaWindowParts(quota, options) {
|
|
11437
|
-
const { windows: windows2, age } = scopedWindowParts(quota, options);
|
|
11437
|
+
const { windows: windows2, age } = scopedWindowParts(quota, options, true);
|
|
11438
11438
|
const parts = windows2.map(({ part }) => part);
|
|
11439
11439
|
return age === void 0 ? { windows: parts } : { windows: parts, age };
|
|
11440
11440
|
}
|
|
@@ -11445,25 +11445,36 @@ function withShortNames(windows2) {
|
|
|
11445
11445
|
}
|
|
11446
11446
|
return windows2;
|
|
11447
11447
|
}
|
|
11448
|
-
function
|
|
11448
|
+
function hasWindowReading(limit) {
|
|
11449
|
+
return Number.isFinite(limit.remainingPercent) && Number.isFinite(limit.checkedAt);
|
|
11450
|
+
}
|
|
11451
|
+
function scopedWindowParts(quota, options, includeUnknown = false) {
|
|
11449
11452
|
if (!quota)
|
|
11450
11453
|
return { windows: [] };
|
|
11451
11454
|
const { now } = options;
|
|
11452
|
-
const readings = quota.limits.filter((limit) => limit.kind === "reading" &&
|
|
11455
|
+
const readings = quota.limits.filter((limit) => limit.kind === "reading" && (includeUnknown || hasWindowReading(limit))).sort(displayOrder);
|
|
11453
11456
|
const windows2 = readings.map((limit) => {
|
|
11454
|
-
const
|
|
11457
|
+
const part = hasWindowReading(limit) ? {
|
|
11458
|
+
kind: "window",
|
|
11459
|
+
reading: "known",
|
|
11460
|
+
name: quotaWindowName(limit),
|
|
11461
|
+
short: "",
|
|
11462
|
+
figure: percentLeft(limit.remainingPercent),
|
|
11463
|
+
remainingPercent: clampPercent(limit.remainingPercent),
|
|
11464
|
+
checkedAt: limit.checkedAt,
|
|
11465
|
+
...resetDetails(limit.resetsAt, limit.checkedAt, now)
|
|
11466
|
+
} : {
|
|
11467
|
+
kind: "window",
|
|
11468
|
+
reading: "unknown",
|
|
11469
|
+
name: quotaWindowName(limit),
|
|
11470
|
+
short: "",
|
|
11471
|
+
figure: "no reading",
|
|
11472
|
+
resetSinceReading: false
|
|
11473
|
+
};
|
|
11455
11474
|
return {
|
|
11456
11475
|
scope: limit.scope,
|
|
11457
11476
|
...limit.windowMinutes === void 0 ? {} : { windowMinutes: limit.windowMinutes },
|
|
11458
|
-
part
|
|
11459
|
-
kind: "window",
|
|
11460
|
-
name: quotaWindowName(limit),
|
|
11461
|
-
short: "",
|
|
11462
|
-
figure: percentLeft(limit.remainingPercent ?? 0),
|
|
11463
|
-
remainingPercent,
|
|
11464
|
-
checkedAt: limit.checkedAt,
|
|
11465
|
-
...resetDetails(limit.resetsAt, limit.checkedAt, now)
|
|
11466
|
-
}
|
|
11477
|
+
part
|
|
11467
11478
|
};
|
|
11468
11479
|
});
|
|
11469
11480
|
const budget = quota.budget;
|
|
@@ -11475,6 +11486,7 @@ function scopedWindowParts(quota, options) {
|
|
|
11475
11486
|
spent: budget.reached,
|
|
11476
11487
|
part: {
|
|
11477
11488
|
kind: "budget",
|
|
11489
|
+
reading: "known",
|
|
11478
11490
|
name: "credits",
|
|
11479
11491
|
short: "",
|
|
11480
11492
|
figure,
|
|
@@ -11485,8 +11497,9 @@ function scopedWindowParts(quota, options) {
|
|
|
11485
11497
|
});
|
|
11486
11498
|
}
|
|
11487
11499
|
withShortNames(windows2);
|
|
11488
|
-
|
|
11489
|
-
|
|
11500
|
+
const readingTimes = windows2.flatMap(({ part }) => part.reading === "known" && part.checkedAt !== void 0 ? [part.checkedAt] : []);
|
|
11501
|
+
if (readingTimes.length > 0) {
|
|
11502
|
+
const age = now - Math.min(...readingTimes);
|
|
11490
11503
|
if (age > (options.staleAfterMs ?? QUOTA_STALE_AFTER_MS)) {
|
|
11491
11504
|
return { windows: windows2, age: `checked ${shortSpan(age)} ago` };
|
|
11492
11505
|
}
|
|
@@ -11585,13 +11598,13 @@ function narrowTextParts(quota, options) {
|
|
|
11585
11598
|
function quotaTextParts(quota, options) {
|
|
11586
11599
|
if (options.form === "narrow")
|
|
11587
11600
|
return narrowTextParts(quota, options);
|
|
11588
|
-
const
|
|
11601
|
+
const { windows: windows2, age } = scopedWindowParts(quota, options);
|
|
11589
11602
|
const full = (options.form ?? "full") === "full";
|
|
11590
|
-
const text2 =
|
|
11603
|
+
const text2 = windows2.map(({ part }) => {
|
|
11591
11604
|
const reset = full && part.resetIn ? `, resets ${part.resetIn}` : "";
|
|
11592
11605
|
return `${part.kind === "budget" ? "" : `${part.name} `}${part.figure}${reset}`;
|
|
11593
11606
|
});
|
|
11594
|
-
return
|
|
11607
|
+
return age === void 0 ? text2 : [...text2, age];
|
|
11595
11608
|
}
|
|
11596
11609
|
function formatQuota(quota, options) {
|
|
11597
11610
|
const parts = quotaTextParts(quota, options);
|
|
@@ -12494,8 +12507,8 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
12494
12507
|
let releaseConfirmed = false;
|
|
12495
12508
|
let loss;
|
|
12496
12509
|
let resolveLoss;
|
|
12497
|
-
const lostPromise = new Promise((
|
|
12498
|
-
resolveLoss =
|
|
12510
|
+
const lostPromise = new Promise((resolve27) => {
|
|
12511
|
+
resolveLoss = resolve27;
|
|
12499
12512
|
});
|
|
12500
12513
|
function notifyTimerStep(event) {
|
|
12501
12514
|
try {
|
|
@@ -12656,7 +12669,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
12656
12669
|
}
|
|
12657
12670
|
}
|
|
12658
12671
|
async function backoff() {
|
|
12659
|
-
await new Promise((
|
|
12672
|
+
await new Promise((resolve27) => setTimeout(resolve27, Math.floor(Math.random() * 4)));
|
|
12660
12673
|
}
|
|
12661
12674
|
async function readLockState(notifyReady = true) {
|
|
12662
12675
|
if (notifyReady && options.onStep)
|
|
@@ -13146,7 +13159,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13146
13159
|
const remainingMs = deadline - performance.now();
|
|
13147
13160
|
if (remainingMs <= 0)
|
|
13148
13161
|
break;
|
|
13149
|
-
await new Promise((
|
|
13162
|
+
await new Promise((resolve27) => setTimeout(resolve27, Math.min(delayMs, remainingMs)));
|
|
13150
13163
|
delayMs = Math.min(delayMs * 2, 50);
|
|
13151
13164
|
}
|
|
13152
13165
|
if (windowsPrivateFiles)
|
|
@@ -13169,21 +13182,37 @@ var init_refresh_file_lock = __esm({
|
|
|
13169
13182
|
});
|
|
13170
13183
|
|
|
13171
13184
|
// ../core/dist/common-auth-embedded/fs/with-lock.js
|
|
13185
|
+
import { join as join6, resolve as resolve3 } from "node:path";
|
|
13172
13186
|
function lockPathFor(target, name) {
|
|
13173
13187
|
return `${target}.${name}.lock`;
|
|
13174
13188
|
}
|
|
13189
|
+
function isChangingLockRead(error, target, name) {
|
|
13190
|
+
if (!windowsPrivateFiles || !(error instanceof PrivateFileError) || error.reason !== "io-error" || error.win32Code !== 32 && error.win32Code !== 303 || error.stage !== "read" && error.stage !== "verify")
|
|
13191
|
+
return false;
|
|
13192
|
+
const path5 = resolve3(lockPathFor(target, name));
|
|
13193
|
+
return error.path === path5 || error.path === join6(path5, "owner.json");
|
|
13194
|
+
}
|
|
13175
13195
|
async function withLock(target, options, fn) {
|
|
13176
13196
|
const started = performance.now();
|
|
13177
13197
|
for (; ; ) {
|
|
13178
13198
|
options.signal?.throwIfAborted();
|
|
13179
|
-
|
|
13180
|
-
|
|
13181
|
-
|
|
13182
|
-
|
|
13183
|
-
|
|
13184
|
-
|
|
13185
|
-
|
|
13186
|
-
|
|
13199
|
+
let lock;
|
|
13200
|
+
let changingReadError;
|
|
13201
|
+
try {
|
|
13202
|
+
lock = await acquireRefreshFileLock({
|
|
13203
|
+
path: target,
|
|
13204
|
+
name: options.name,
|
|
13205
|
+
ttlMs: options.ttlMs,
|
|
13206
|
+
renew: options.renew ?? false,
|
|
13207
|
+
...options.onStep ? { onStep: options.onStep } : {},
|
|
13208
|
+
...options.onRenewalTimer ? { onRenewalTimer: options.onRenewalTimer } : {}
|
|
13209
|
+
});
|
|
13210
|
+
} catch (error) {
|
|
13211
|
+
if (!isChangingLockRead(error, target, options.name))
|
|
13212
|
+
throw error;
|
|
13213
|
+
lock = null;
|
|
13214
|
+
changingReadError = error;
|
|
13215
|
+
}
|
|
13187
13216
|
if (lock) {
|
|
13188
13217
|
try {
|
|
13189
13218
|
options.signal?.throwIfAborted();
|
|
@@ -13194,19 +13223,22 @@ async function withLock(target, options, fn) {
|
|
|
13194
13223
|
}
|
|
13195
13224
|
const remaining = options.timeoutMs - (performance.now() - started);
|
|
13196
13225
|
if (remaining <= 0) {
|
|
13226
|
+
if (changingReadError)
|
|
13227
|
+
throw changingReadError;
|
|
13197
13228
|
throw new LockContentionError({
|
|
13198
13229
|
target,
|
|
13199
13230
|
name: options.name,
|
|
13200
13231
|
timeoutMs: options.timeoutMs
|
|
13201
13232
|
});
|
|
13202
13233
|
}
|
|
13203
|
-
await new Promise((
|
|
13234
|
+
await new Promise((resolve27) => setTimeout(resolve27, Math.min(25, Math.ceil(remaining))));
|
|
13204
13235
|
}
|
|
13205
13236
|
}
|
|
13206
13237
|
var LockContentionError, LockOwnershipError;
|
|
13207
13238
|
var init_with_lock = __esm({
|
|
13208
13239
|
"../core/dist/common-auth-embedded/fs/with-lock.js"() {
|
|
13209
13240
|
"use strict";
|
|
13241
|
+
init_private_files();
|
|
13210
13242
|
init_refresh_file_lock();
|
|
13211
13243
|
LockContentionError = class extends Error {
|
|
13212
13244
|
details;
|
|
@@ -13319,7 +13351,7 @@ async function acquirePoolLock(spec, defaults, env3) {
|
|
|
13319
13351
|
});
|
|
13320
13352
|
}
|
|
13321
13353
|
const jitter = Math.floor(Math.random() * (options.retryMs + 1));
|
|
13322
|
-
await new Promise((
|
|
13354
|
+
await new Promise((resolve27) => setTimeout(resolve27, Math.min(options.retryMs + jitter, remaining)));
|
|
13323
13355
|
}
|
|
13324
13356
|
}
|
|
13325
13357
|
function definedOnly(spec) {
|
|
@@ -16163,7 +16195,7 @@ var init_redact = __esm({
|
|
|
16163
16195
|
// ../core/dist/common-auth-embedded/logger/engine.js
|
|
16164
16196
|
import { appendFileSync, chmodSync, existsSync, renameSync, statSync } from "node:fs";
|
|
16165
16197
|
import { open as open5 } from "node:fs/promises";
|
|
16166
|
-
import { dirname as dirname8, resolve as
|
|
16198
|
+
import { dirname as dirname8, resolve as resolve4 } from "node:path";
|
|
16167
16199
|
function chmodPrivate(path5) {
|
|
16168
16200
|
try {
|
|
16169
16201
|
chmodSync(path5, 384);
|
|
@@ -16214,7 +16246,7 @@ async function openWindowsFile(sink, file) {
|
|
|
16214
16246
|
return sink.handle;
|
|
16215
16247
|
}
|
|
16216
16248
|
async function flushWindowsFile(sink, file, text2) {
|
|
16217
|
-
file =
|
|
16249
|
+
file = resolve4(file);
|
|
16218
16250
|
try {
|
|
16219
16251
|
if (sink.file !== file)
|
|
16220
16252
|
await closeWindowsFile(sink);
|
|
@@ -16590,11 +16622,11 @@ var init_quota_writer = __esm({
|
|
|
16590
16622
|
const left = deadline - performance.now();
|
|
16591
16623
|
if (left <= 0)
|
|
16592
16624
|
throw refusal2("pull", id, "lock-contention", `pool quota queue for ${id} is full (${POOL_QUOTA_QUEUE_LIMIT} readings) and the store locks stayed held`, true);
|
|
16593
|
-
await new Promise((
|
|
16625
|
+
await new Promise((resolve27) => {
|
|
16594
16626
|
const done = () => {
|
|
16595
16627
|
clearTimeout(timer);
|
|
16596
16628
|
this.wake.delete(done);
|
|
16597
|
-
|
|
16629
|
+
resolve27();
|
|
16598
16630
|
};
|
|
16599
16631
|
const timer = setTimeout(done, left);
|
|
16600
16632
|
this.wake.add(done);
|
|
@@ -16987,7 +17019,7 @@ var init_refresh = __esm({
|
|
|
16987
17019
|
|
|
16988
17020
|
// ../core/dist/common-auth-embedded/fs/file-read-cache.js
|
|
16989
17021
|
import { lstat as lstat4 } from "node:fs/promises";
|
|
16990
|
-
import { resolve as
|
|
17022
|
+
import { resolve as resolve5 } from "node:path";
|
|
16991
17023
|
async function identity(path5) {
|
|
16992
17024
|
try {
|
|
16993
17025
|
const metadata = await lstat4(path5);
|
|
@@ -17008,7 +17040,7 @@ var init_file_read_cache = __esm({
|
|
|
17008
17040
|
FileReadCache = class {
|
|
17009
17041
|
#entries = /* @__PURE__ */ new Map();
|
|
17010
17042
|
async read(paths, read, validateHit) {
|
|
17011
|
-
const resolvedPaths = paths.map((path5) =>
|
|
17043
|
+
const resolvedPaths = paths.map((path5) => resolve5(path5));
|
|
17012
17044
|
const key = JSON.stringify(resolvedPaths);
|
|
17013
17045
|
const probed = await Promise.all(resolvedPaths.map(identity));
|
|
17014
17046
|
const identities = probed.every((entry) => entry !== void 0) ? probed : void 0;
|
|
@@ -19365,7 +19397,7 @@ async function select(terminal, items, options) {
|
|
|
19365
19397
|
writeLine("");
|
|
19366
19398
|
renderedLines = lines;
|
|
19367
19399
|
};
|
|
19368
|
-
return new Promise((
|
|
19400
|
+
return new Promise((resolve27) => {
|
|
19369
19401
|
const wasRaw = stdin.isRaw ?? false;
|
|
19370
19402
|
const cleanup2 = () => {
|
|
19371
19403
|
if (cleaned)
|
|
@@ -19385,7 +19417,7 @@ async function select(terminal, items, options) {
|
|
|
19385
19417
|
};
|
|
19386
19418
|
const finish = (value) => {
|
|
19387
19419
|
cleanup2();
|
|
19388
|
-
|
|
19420
|
+
resolve27(value);
|
|
19389
19421
|
};
|
|
19390
19422
|
const onSignal = () => finish(null);
|
|
19391
19423
|
const onKey = (data) => {
|
|
@@ -19425,7 +19457,7 @@ async function select(terminal, items, options) {
|
|
|
19425
19457
|
stdin.setRawMode(true);
|
|
19426
19458
|
} catch {
|
|
19427
19459
|
cleanup2();
|
|
19428
|
-
|
|
19460
|
+
resolve27(null);
|
|
19429
19461
|
return;
|
|
19430
19462
|
}
|
|
19431
19463
|
stdin.resume();
|
|
@@ -20267,7 +20299,7 @@ var init_watch = __esm({
|
|
|
20267
20299
|
});
|
|
20268
20300
|
|
|
20269
20301
|
// ../core/dist/common-auth-embedded/claustrum/insula.js
|
|
20270
|
-
import { resolve as
|
|
20302
|
+
import { resolve as resolve6 } from "node:path";
|
|
20271
20303
|
import { storeIdentity } from "@cortexkit/claustrum-client";
|
|
20272
20304
|
import { SubcClient } from "@cortexkit/subc-client";
|
|
20273
20305
|
function insulaUsageTransport(options) {
|
|
@@ -20395,8 +20427,8 @@ function refusalCode(error) {
|
|
|
20395
20427
|
}
|
|
20396
20428
|
function acquireInsulaQuotaSource(transport, tokenPath) {
|
|
20397
20429
|
const key = JSON.stringify([
|
|
20398
|
-
|
|
20399
|
-
|
|
20430
|
+
resolve6(transport.connectionFile),
|
|
20431
|
+
resolve6(tokenPath)
|
|
20400
20432
|
]);
|
|
20401
20433
|
let shared3 = sources.get(key);
|
|
20402
20434
|
if (!shared3) {
|
|
@@ -20710,7 +20742,7 @@ var init_any_signal = __esm({
|
|
|
20710
20742
|
import { createHash as createHash6, randomBytes as randomBytes4, randomUUID as randomUUID12 } from "node:crypto";
|
|
20711
20743
|
import { constants as fsConstants } from "node:fs";
|
|
20712
20744
|
import { chmod as chmod2, mkdir as mkdir8, open as open6, readFile as readFile6, realpath as realpath3, rename as rename7, stat as stat4, unlink as unlink6 } from "node:fs/promises";
|
|
20713
|
-
import { basename as basename3, dirname as dirname9, extname, isAbsolute as isAbsolute2, join as
|
|
20745
|
+
import { basename as basename3, dirname as dirname9, extname, isAbsolute as isAbsolute2, join as join7, resolve as resolve7 } from "node:path";
|
|
20714
20746
|
import { ClaustrumCredentialError as ClaustrumCredentialError2, ClaustrumClient as ClaustrumWireClient, writeEnrollmentTokenFile } from "@cortexkit/claustrum-client";
|
|
20715
20747
|
function classifyEnrollmentError(error) {
|
|
20716
20748
|
if (!(error instanceof ClaustrumCredentialError2))
|
|
@@ -20736,7 +20768,7 @@ function getClaustrumEnrollmentPaths(tokenPath) {
|
|
|
20736
20768
|
const extension = extname(tokenPath) || ".json";
|
|
20737
20769
|
const stem = basename3(tokenPath, extname(tokenPath));
|
|
20738
20770
|
return {
|
|
20739
|
-
statePath:
|
|
20771
|
+
statePath: join7(dirname9(tokenPath), `${stem}-state${extension}`),
|
|
20740
20772
|
tokenPath
|
|
20741
20773
|
};
|
|
20742
20774
|
}
|
|
@@ -20744,7 +20776,7 @@ function hostEnrollmentPaths(input2) {
|
|
|
20744
20776
|
const override = input2.override?.trim();
|
|
20745
20777
|
if (override && !isAbsolute2(override) && !input2.cwd)
|
|
20746
20778
|
throw new ClaustrumConsumerError("invalid-state", "A relative Claustrum enrollment override needs a base directory");
|
|
20747
|
-
const tokenPath = override ? isAbsolute2(override) ? override :
|
|
20779
|
+
const tokenPath = override ? isAbsolute2(override) ? override : resolve7(input2.cwd, override) : join7(input2.stateDir, `${input2.host}-enrollment.json`);
|
|
20748
20780
|
return getClaustrumEnrollmentPaths(tokenPath);
|
|
20749
20781
|
}
|
|
20750
20782
|
function isRecord6(value) {
|
|
@@ -20977,7 +21009,7 @@ async function writeStateAtomic(path5, state, ancestorOptions = {}) {
|
|
|
20977
21009
|
}
|
|
20978
21010
|
if (windowsPrivateFiles)
|
|
20979
21011
|
return writePrivateAtomic(path5, bytes);
|
|
20980
|
-
const temporary =
|
|
21012
|
+
const temporary = join7(parent, `.${basename3(path5)}.${process.pid}.${randomUUID12()}.tmp`);
|
|
20981
21013
|
let descriptor;
|
|
20982
21014
|
let created = false;
|
|
20983
21015
|
try {
|
|
@@ -21473,10 +21505,10 @@ async function drainShutdown(pending, onTimeout) {
|
|
|
21473
21505
|
try {
|
|
21474
21506
|
await Promise.race([
|
|
21475
21507
|
drained,
|
|
21476
|
-
new Promise((
|
|
21508
|
+
new Promise((resolve27) => {
|
|
21477
21509
|
timer = setTimeout(() => {
|
|
21478
21510
|
expired = true;
|
|
21479
|
-
|
|
21511
|
+
resolve27();
|
|
21480
21512
|
}, 2e3);
|
|
21481
21513
|
})
|
|
21482
21514
|
]);
|
|
@@ -22246,7 +22278,7 @@ var init_interlock = __esm({
|
|
|
22246
22278
|
// ../core/dist/common-auth-embedded/claustrum/roster.js
|
|
22247
22279
|
import { createHash as createHash7 } from "node:crypto";
|
|
22248
22280
|
import { stat as stat5 } from "node:fs/promises";
|
|
22249
|
-
import { resolve as
|
|
22281
|
+
import { resolve as resolve8 } from "node:path";
|
|
22250
22282
|
function vaultRosterSeed(roster) {
|
|
22251
22283
|
return {
|
|
22252
22284
|
declined: roster.declined.map((entry) => ({ ...entry })),
|
|
@@ -22633,16 +22665,16 @@ function applyVaultQuota(current, input2) {
|
|
|
22633
22665
|
};
|
|
22634
22666
|
}
|
|
22635
22667
|
function forgetPendingVaultDiscovery(path5) {
|
|
22636
|
-
pendingDiscoveries.delete(
|
|
22668
|
+
pendingDiscoveries.delete(resolve8(path5));
|
|
22637
22669
|
}
|
|
22638
22670
|
function isVaultRosterLockRefusal(path5, error) {
|
|
22639
|
-
const target =
|
|
22671
|
+
const target = resolve8(path5);
|
|
22640
22672
|
if (error instanceof ClaustrumConsumerError)
|
|
22641
22673
|
return error.kind === "roster-busy";
|
|
22642
22674
|
if (error instanceof LockContentionError || error instanceof LockOwnershipError)
|
|
22643
|
-
return
|
|
22675
|
+
return resolve8(error.details.target) === target;
|
|
22644
22676
|
if (error instanceof PrivateFileError) {
|
|
22645
|
-
const failed =
|
|
22677
|
+
const failed = resolve8(error.path);
|
|
22646
22678
|
return [WRITE_LOCK.name, DISCOVERY_LEASE.name].some((name) => {
|
|
22647
22679
|
const lock = lockPathFor(target, name);
|
|
22648
22680
|
return failed === lock || failed.startsWith(`${lock}.`);
|
|
@@ -22703,7 +22735,7 @@ async function refreshVaultRoster(options) {
|
|
|
22703
22735
|
throw new ClaustrumConsumerError("roster-busy", "Claustrum account discovery is already in progress");
|
|
22704
22736
|
return persisted;
|
|
22705
22737
|
}
|
|
22706
|
-
const key =
|
|
22738
|
+
const key = resolve8(options.path);
|
|
22707
22739
|
const listedOver = options.listedOver;
|
|
22708
22740
|
let discovered;
|
|
22709
22741
|
try {
|
|
@@ -22823,9 +22855,9 @@ var init_roster = __esm({
|
|
|
22823
22855
|
});
|
|
22824
22856
|
|
|
22825
22857
|
// ../core/dist/common-auth-embedded/claustrum/quota-writer.js
|
|
22826
|
-
import { resolve as
|
|
22858
|
+
import { resolve as resolve9 } from "node:path";
|
|
22827
22859
|
function writerFor(path5, clock2 = quotaCommitTimer) {
|
|
22828
|
-
const key =
|
|
22860
|
+
const key = resolve9(path5);
|
|
22829
22861
|
let writer = writers.get(key);
|
|
22830
22862
|
if (!writer) {
|
|
22831
22863
|
writer = {
|
|
@@ -22889,7 +22921,7 @@ function orderedFields(pending) {
|
|
|
22889
22921
|
return [...pending.values()].flatMap((account) => [...account.values()]).sort((a, b) => a.order - b.order);
|
|
22890
22922
|
}
|
|
22891
22923
|
function pendingVaultQuota(path5, roster) {
|
|
22892
|
-
const writer = writers.get(
|
|
22924
|
+
const writer = writers.get(resolve9(path5));
|
|
22893
22925
|
if (writer) {
|
|
22894
22926
|
for (const field of orderedFields(writer.pending)) {
|
|
22895
22927
|
if (field.priorReading)
|
|
@@ -22900,7 +22932,7 @@ function pendingVaultQuota(path5, roster) {
|
|
|
22900
22932
|
return roster;
|
|
22901
22933
|
}
|
|
22902
22934
|
function hasPendingVaultQuota(path5) {
|
|
22903
|
-
return !!writers.get(
|
|
22935
|
+
return !!writers.get(resolve9(path5))?.pending.size;
|
|
22904
22936
|
}
|
|
22905
22937
|
function schedule(writer, delay3) {
|
|
22906
22938
|
if (writer.running || writer.timer || !writer.pending.size || writer.abort.signal.aborted)
|
|
@@ -22965,7 +22997,7 @@ function flush(writer) {
|
|
|
22965
22997
|
return writer.running;
|
|
22966
22998
|
}
|
|
22967
22999
|
async function drainVaultQuota(path5, timeoutMs = 1e3) {
|
|
22968
|
-
const key =
|
|
23000
|
+
const key = resolve9(path5);
|
|
22969
23001
|
const writer = writers.get(key);
|
|
22970
23002
|
if (!writer)
|
|
22971
23003
|
return;
|
|
@@ -23110,7 +23142,7 @@ var init_consumer = __esm({
|
|
|
23110
23142
|
this.#shutdown.signal,
|
|
23111
23143
|
...signal ? [signal] : []
|
|
23112
23144
|
]);
|
|
23113
|
-
return new Promise((
|
|
23145
|
+
return new Promise((resolve27, reject) => {
|
|
23114
23146
|
const cleanup2 = () => {
|
|
23115
23147
|
combined.signal.removeEventListener("abort", abort);
|
|
23116
23148
|
combined.dispose();
|
|
@@ -23125,7 +23157,7 @@ var init_consumer = __esm({
|
|
|
23125
23157
|
if (combined.signal.aborted)
|
|
23126
23158
|
reject(combined.signal.reason);
|
|
23127
23159
|
else
|
|
23128
|
-
|
|
23160
|
+
resolve27(value);
|
|
23129
23161
|
}, (error) => {
|
|
23130
23162
|
cleanup2();
|
|
23131
23163
|
reject(error);
|
|
@@ -23839,7 +23871,7 @@ var init_consumer = __esm({
|
|
|
23839
23871
|
import { createHash as createHash8 } from "node:crypto";
|
|
23840
23872
|
import { channel as channel2 } from "node:diagnostics_channel";
|
|
23841
23873
|
import { readdir, stat as stat6 } from "node:fs/promises";
|
|
23842
|
-
import { dirname as dirname10, join as
|
|
23874
|
+
import { dirname as dirname10, join as join8, resolve as resolve10 } from "node:path";
|
|
23843
23875
|
function canonicalJson3(value, path5 = /* @__PURE__ */ new Set()) {
|
|
23844
23876
|
if (value === null)
|
|
23845
23877
|
return "null";
|
|
@@ -23900,12 +23932,12 @@ function unreachableConnect2() {
|
|
|
23900
23932
|
return new ClaustrumUnreachableError();
|
|
23901
23933
|
}
|
|
23902
23934
|
function untilAborted(pending, signal) {
|
|
23903
|
-
return new Promise((
|
|
23935
|
+
return new Promise((resolve27, reject) => {
|
|
23904
23936
|
const abort = () => reject(signal.reason);
|
|
23905
23937
|
signal.addEventListener("abort", abort, { once: true });
|
|
23906
23938
|
pending.then((value) => {
|
|
23907
23939
|
signal.removeEventListener("abort", abort);
|
|
23908
|
-
|
|
23940
|
+
resolve27(value);
|
|
23909
23941
|
}, (error) => {
|
|
23910
23942
|
signal.removeEventListener("abort", abort);
|
|
23911
23943
|
reject(error);
|
|
@@ -23975,13 +24007,13 @@ var init_hub = __esm({
|
|
|
23975
24007
|
this.#options = options;
|
|
23976
24008
|
this.#logger = options.logger ?? createLogger2("claustrum");
|
|
23977
24009
|
this.#warnShutdown = shutdownWarning(this.#logger, this.#shutdown.signal);
|
|
23978
|
-
this.#generationDirectory =
|
|
24010
|
+
this.#generationDirectory = join8(options.stateDir, "rosters", hostGeneration);
|
|
23979
24011
|
this.#key = rosterFingerprint(options, providers);
|
|
23980
|
-
const directory =
|
|
24012
|
+
const directory = join8(this.#generationDirectory, this.#key);
|
|
23981
24013
|
for (const provider2 of providers)
|
|
23982
24014
|
this.#members.set(provider2, {
|
|
23983
24015
|
provider: provider2,
|
|
23984
|
-
path:
|
|
24016
|
+
path: join8(directory, `${provider2}.json`),
|
|
23985
24017
|
closed: false
|
|
23986
24018
|
});
|
|
23987
24019
|
}
|
|
@@ -24062,7 +24094,7 @@ var init_hub = __esm({
|
|
|
24062
24094
|
};
|
|
24063
24095
|
const { consumer, hooks } = createHubMember(port, consumerOptions);
|
|
24064
24096
|
entry.hooks = hooks;
|
|
24065
|
-
const path5 =
|
|
24097
|
+
const path5 = resolve10(entry.path);
|
|
24066
24098
|
const subscribers = sharedRosters.get(path5) ?? /* @__PURE__ */ new Set();
|
|
24067
24099
|
const install = (roster) => {
|
|
24068
24100
|
if (entry.closed || this.#active !== true || !this.#current || !this.#live(this.#current) || !hooks.roster() || this.#collides(hooks, roster))
|
|
@@ -24093,7 +24125,7 @@ var init_hub = __esm({
|
|
|
24093
24125
|
return;
|
|
24094
24126
|
entry.seen = JSON.stringify(decodedVaultRoster(roster));
|
|
24095
24127
|
entry.hooks?.install(roster);
|
|
24096
|
-
for (const install of sharedRosters.get(
|
|
24128
|
+
for (const install of sharedRosters.get(resolve10(entry.path)) ?? []) {
|
|
24097
24129
|
if (!this.#live(generation))
|
|
24098
24130
|
return;
|
|
24099
24131
|
if (install !== entry.receiveRoster)
|
|
@@ -24549,7 +24581,7 @@ var init_hub = __esm({
|
|
|
24549
24581
|
for (const directory of [
|
|
24550
24582
|
dirname10(this.#generationDirectory),
|
|
24551
24583
|
this.#generationDirectory,
|
|
24552
|
-
|
|
24584
|
+
join8(this.#generationDirectory, this.#key)
|
|
24553
24585
|
])
|
|
24554
24586
|
await ensureClaustrumPrivateDirectory(directory, {}, "roster directory");
|
|
24555
24587
|
}
|
|
@@ -24561,11 +24593,11 @@ var init_hub = __esm({
|
|
|
24561
24593
|
*/
|
|
24562
24594
|
async #seed(entry) {
|
|
24563
24595
|
const name = `${entry.provider}.json`;
|
|
24564
|
-
const candidates = [
|
|
24596
|
+
const candidates = [join8(this.#generationDirectory, name)];
|
|
24565
24597
|
try {
|
|
24566
24598
|
for (const key of await readdir(this.#generationDirectory))
|
|
24567
24599
|
if (key !== this.#key && FINGERPRINT.test(key))
|
|
24568
|
-
candidates.push(
|
|
24600
|
+
candidates.push(join8(this.#generationDirectory, key, name));
|
|
24569
24601
|
} catch {
|
|
24570
24602
|
}
|
|
24571
24603
|
let newest;
|
|
@@ -25138,7 +25170,7 @@ var init_lock = __esm({
|
|
|
25138
25170
|
import { createHash as createHash9 } from "node:crypto";
|
|
25139
25171
|
import { constants as constants2 } from "node:fs";
|
|
25140
25172
|
import { lstat as lstat5, mkdir as mkdir10, open as open7, unlink as unlink7 } from "node:fs/promises";
|
|
25141
|
-
import { dirname as dirname11, resolve as
|
|
25173
|
+
import { dirname as dirname11, resolve as resolve11 } from "node:path";
|
|
25142
25174
|
import { setTimeout as sleep2 } from "node:timers/promises";
|
|
25143
25175
|
function rootSpans(text2) {
|
|
25144
25176
|
let i = text2.indexOf("{") + 1;
|
|
@@ -25235,13 +25267,13 @@ async function safeRead(path5, privateFile = false, afterReadCheck) {
|
|
|
25235
25267
|
let file;
|
|
25236
25268
|
try {
|
|
25237
25269
|
file = await open7(path5, constants2.O_RDONLY | constants2.O_NOFOLLOW);
|
|
25238
|
-
const
|
|
25239
|
-
if (!
|
|
25270
|
+
const stat16 = await file.stat();
|
|
25271
|
+
if (!stat16.isFile() || privateFile && (stat16.mode & 511) !== 384) {
|
|
25240
25272
|
throw new PiSlotError("unsafe-path");
|
|
25241
25273
|
}
|
|
25242
25274
|
await afterReadCheck?.(path5);
|
|
25243
25275
|
const current = await lstat5(path5);
|
|
25244
|
-
if (!current.isFile() || current.dev !==
|
|
25276
|
+
if (!current.isFile() || current.dev !== stat16.dev || current.ino !== stat16.ino) {
|
|
25245
25277
|
throw new PiSlotError("unsafe-path");
|
|
25246
25278
|
}
|
|
25247
25279
|
const bytes = await file.readFile();
|
|
@@ -25339,8 +25371,8 @@ function createPiSlot(options, onStep, hooks) {
|
|
|
25339
25371
|
if (!provider2 || !options.authPath || !options.stashPath || !placeholderKey || placeholderKey.startsWith("!") || placeholderKey.includes("$") || !Number.isFinite(timeout) || timeout < 0) {
|
|
25340
25372
|
throw new PiSlotError("invalid-options");
|
|
25341
25373
|
}
|
|
25342
|
-
const authPath =
|
|
25343
|
-
const stashPath =
|
|
25374
|
+
const authPath = resolve11(options.authPath);
|
|
25375
|
+
const stashPath = resolve11(options.stashPath);
|
|
25344
25376
|
if (authPath === stashPath || stashPath === `${authPath}.lock`) {
|
|
25345
25377
|
throw new PiSlotError("invalid-options");
|
|
25346
25378
|
}
|
|
@@ -25773,15 +25805,15 @@ var init_model_types = __esm({
|
|
|
25773
25805
|
|
|
25774
25806
|
// ../core/dist/pi-paths.js
|
|
25775
25807
|
import { homedir } from "node:os";
|
|
25776
|
-
import { dirname as dirname12, join as
|
|
25808
|
+
import { dirname as dirname12, join as join9 } from "node:path";
|
|
25777
25809
|
function getPiConfigDir() {
|
|
25778
|
-
return process.env.PI_AGENT_DIR?.trim() ||
|
|
25810
|
+
return process.env.PI_AGENT_DIR?.trim() || join9(homedir(), ".pi", "agent");
|
|
25779
25811
|
}
|
|
25780
25812
|
function getPiAntigravityAuthFile() {
|
|
25781
|
-
return process.env.PI_ANTIGRAVITY_AUTH_FILE?.trim() ||
|
|
25813
|
+
return process.env.PI_ANTIGRAVITY_AUTH_FILE?.trim() || join9(getPiConfigDir(), "antigravity-accounts.json");
|
|
25782
25814
|
}
|
|
25783
25815
|
function getPiAntigravityVaultDir() {
|
|
25784
|
-
return
|
|
25816
|
+
return join9(dirname12(getPiAntigravityAuthFile()), "antigravity-auth-vault");
|
|
25785
25817
|
}
|
|
25786
25818
|
var init_pi_paths = __esm({
|
|
25787
25819
|
"../core/dist/pi-paths.js"() {
|
|
@@ -25963,8 +25995,8 @@ function getDefaultTierId(allowedTiers) {
|
|
|
25963
25995
|
return allowedTiers[0]?.id;
|
|
25964
25996
|
}
|
|
25965
25997
|
function wait(ms) {
|
|
25966
|
-
return new Promise((
|
|
25967
|
-
setTimeout(
|
|
25998
|
+
return new Promise((resolve27) => {
|
|
25999
|
+
setTimeout(resolve27, ms);
|
|
25968
26000
|
});
|
|
25969
26001
|
}
|
|
25970
26002
|
function extractManagedProjectId(payload) {
|
|
@@ -28286,12 +28318,12 @@ var init_vault_provider_state = __esm({
|
|
|
28286
28318
|
function untilAborted2(pending, signal) {
|
|
28287
28319
|
if (!signal)
|
|
28288
28320
|
return pending;
|
|
28289
|
-
return new Promise((
|
|
28321
|
+
return new Promise((resolve27, reject) => {
|
|
28290
28322
|
const abort = () => reject(signal.reason);
|
|
28291
28323
|
signal.addEventListener("abort", abort, { once: true });
|
|
28292
28324
|
if (signal.aborted)
|
|
28293
28325
|
abort();
|
|
28294
|
-
pending.then(
|
|
28326
|
+
pending.then(resolve27, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
28295
28327
|
});
|
|
28296
28328
|
}
|
|
28297
28329
|
async function resolveClaustrumConnectionPath(explicit) {
|
|
@@ -28662,7 +28694,7 @@ function getAntigravityVersionResolution() {
|
|
|
28662
28694
|
return lastResolution ?? { version: getAntigravityVersion(), source: "fallback" };
|
|
28663
28695
|
}
|
|
28664
28696
|
async function initAntigravityVersion() {
|
|
28665
|
-
const
|
|
28697
|
+
const log17 = createLogger("version");
|
|
28666
28698
|
const fallback = getAntigravityVersion();
|
|
28667
28699
|
let version;
|
|
28668
28700
|
let source;
|
|
@@ -28676,15 +28708,15 @@ async function initAntigravityVersion() {
|
|
|
28676
28708
|
} else {
|
|
28677
28709
|
source = "fallback";
|
|
28678
28710
|
setAntigravityVersion(fallback);
|
|
28679
|
-
|
|
28711
|
+
log17.info("version-fetch-failed", { fallback });
|
|
28680
28712
|
lastResolution = { version: fallback, source };
|
|
28681
28713
|
return lastResolution;
|
|
28682
28714
|
}
|
|
28683
28715
|
}
|
|
28684
28716
|
if (version !== fallback) {
|
|
28685
|
-
|
|
28717
|
+
log17.info("version-updated", { version, source, previous: fallback });
|
|
28686
28718
|
} else {
|
|
28687
|
-
|
|
28719
|
+
log17.debug("version-unchanged", { version, source });
|
|
28688
28720
|
}
|
|
28689
28721
|
setAntigravityVersion(version);
|
|
28690
28722
|
lastResolution = { version, source };
|
|
@@ -28765,7 +28797,7 @@ var init_capture_sink2 = __esm({
|
|
|
28765
28797
|
import { randomUUID as randomUUID13 } from "node:crypto";
|
|
28766
28798
|
import { lstat as lstat6, readFile as readFile8, rename as rename8, unlink as unlink8 } from "node:fs/promises";
|
|
28767
28799
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
28768
|
-
import { dirname as dirname13, join as
|
|
28800
|
+
import { dirname as dirname13, join as join10, resolve as resolve12 } from "node:path";
|
|
28769
28801
|
function ioCode2(detail) {
|
|
28770
28802
|
if (detail?.reason === "io-error") {
|
|
28771
28803
|
if (detail.win32Code === 2 || detail.win32Code === 3)
|
|
@@ -28786,7 +28818,7 @@ function isUnavailable2(api, error) {
|
|
|
28786
28818
|
}
|
|
28787
28819
|
async function assertNativeAddonLoads2(api) {
|
|
28788
28820
|
try {
|
|
28789
|
-
await api.verifyPrivatePath(
|
|
28821
|
+
await api.verifyPrivatePath(join10(tmpdir2(), `.common-auth-private-files-probe-${randomUUID13()}`), "file");
|
|
28790
28822
|
} catch (error) {
|
|
28791
28823
|
if (isUnavailable2(api, error))
|
|
28792
28824
|
throw privateFilesUnavailable2(error);
|
|
@@ -28812,7 +28844,7 @@ async function privateOperation2(path5, stage, operation) {
|
|
|
28812
28844
|
}
|
|
28813
28845
|
}
|
|
28814
28846
|
async function verifySafeDirectory2(path5, options) {
|
|
28815
|
-
path5 =
|
|
28847
|
+
path5 = resolve12(path5);
|
|
28816
28848
|
options ??= safeParentOptionsForTest2;
|
|
28817
28849
|
await privateOperation2(path5, "safe-parent", async () => {
|
|
28818
28850
|
const result = await (await loadBackend2()).verifySafeParent(path5, options);
|
|
@@ -28827,7 +28859,7 @@ async function verifySafeDirectory2(path5, options) {
|
|
|
28827
28859
|
});
|
|
28828
28860
|
}
|
|
28829
28861
|
async function verifyPrivate2(path5, kind, migrate = false) {
|
|
28830
|
-
path5 =
|
|
28862
|
+
path5 = resolve12(path5);
|
|
28831
28863
|
if (kind === "directory")
|
|
28832
28864
|
return verifySafeDirectory2(path5);
|
|
28833
28865
|
await privateOperation2(path5, "verify", async () => {
|
|
@@ -28862,7 +28894,7 @@ async function verifyPrivate2(path5, kind, migrate = false) {
|
|
|
28862
28894
|
});
|
|
28863
28895
|
}
|
|
28864
28896
|
async function ensurePrivateDirectory2(path5, _migrate = false, options) {
|
|
28865
|
-
path5 =
|
|
28897
|
+
path5 = resolve12(path5);
|
|
28866
28898
|
await privateOperation2(path5, "directory", async () => {
|
|
28867
28899
|
const api = await loadBackend2();
|
|
28868
28900
|
try {
|
|
@@ -28893,7 +28925,7 @@ async function readPrivateText2(path5, migrate = false) {
|
|
|
28893
28925
|
async function readPrivateBuffer2(path5, migrate = false) {
|
|
28894
28926
|
if (!windowsPrivateFiles2)
|
|
28895
28927
|
return readFile8(path5);
|
|
28896
|
-
path5 =
|
|
28928
|
+
path5 = resolve12(path5);
|
|
28897
28929
|
if (migrate) {
|
|
28898
28930
|
await verifySafeDirectory2(dirname13(path5));
|
|
28899
28931
|
await verifyPrivate2(path5, "file", true);
|
|
@@ -28901,20 +28933,20 @@ async function readPrivateBuffer2(path5, migrate = false) {
|
|
|
28901
28933
|
return privateOperation2(path5, "read", async () => (await loadBackend2()).readOwnerOnly(path5));
|
|
28902
28934
|
}
|
|
28903
28935
|
async function createPrivateBytes2(path5, bytes) {
|
|
28904
|
-
await verifySafeDirectory2(dirname13(
|
|
28936
|
+
await verifySafeDirectory2(dirname13(resolve12(path5)));
|
|
28905
28937
|
await privateOperation2(path5, "create", async () => {
|
|
28906
|
-
await (await loadBackend2()).createPrivateFile(
|
|
28938
|
+
await (await loadBackend2()).createPrivateFile(resolve12(path5), bytes);
|
|
28907
28939
|
});
|
|
28908
28940
|
}
|
|
28909
28941
|
async function createPrivateDirectoryExclusive2(path5) {
|
|
28910
|
-
await verifySafeDirectory2(dirname13(
|
|
28942
|
+
await verifySafeDirectory2(dirname13(resolve12(path5)));
|
|
28911
28943
|
await privateOperation2(path5, "directory-create", async () => {
|
|
28912
|
-
await (await loadBackend2()).createOwnerOnly(
|
|
28944
|
+
await (await loadBackend2()).createOwnerOnly(resolve12(path5), { kind: "dir" });
|
|
28913
28945
|
});
|
|
28914
28946
|
}
|
|
28915
28947
|
async function replaceWindowsFile2(from, to, options = {}) {
|
|
28916
|
-
from =
|
|
28917
|
-
to =
|
|
28948
|
+
from = resolve12(from);
|
|
28949
|
+
to = resolve12(to);
|
|
28918
28950
|
const now = options.now ?? (() => performance.now());
|
|
28919
28951
|
const start = now();
|
|
28920
28952
|
const leaseDeadline = options.deadline ?? Infinity;
|
|
@@ -28957,7 +28989,7 @@ async function replaceWindowsFile2(from, to, options = {}) {
|
|
|
28957
28989
|
throw error;
|
|
28958
28990
|
}
|
|
28959
28991
|
async function writePrivateAtomic2(path5, bytes, options = {}) {
|
|
28960
|
-
path5 =
|
|
28992
|
+
path5 = resolve12(path5);
|
|
28961
28993
|
await ensurePrivateDirectory2(dirname13(path5));
|
|
28962
28994
|
try {
|
|
28963
28995
|
await verifyPrivate2(path5, "file", true);
|
|
@@ -28965,7 +28997,7 @@ async function writePrivateAtomic2(path5, bytes, options = {}) {
|
|
|
28965
28997
|
if (error.code !== "ENOENT")
|
|
28966
28998
|
throw error;
|
|
28967
28999
|
}
|
|
28968
|
-
const stage =
|
|
29000
|
+
const stage = resolve12(options.stagePath ?? `${path5}.${randomUUID13()}.tmp`);
|
|
28969
29001
|
if (dirname13(stage) !== dirname13(path5))
|
|
28970
29002
|
throw new PrivateFileError2(path5, "stage-directory", { code: "EXDEV" });
|
|
28971
29003
|
let created = false;
|
|
@@ -29131,7 +29163,7 @@ var init_redact2 = __esm({
|
|
|
29131
29163
|
// src/common-auth-embedded/logger/engine.js
|
|
29132
29164
|
import { appendFileSync as appendFileSync2, chmodSync as chmodSync2, existsSync as existsSync2, renameSync as renameSync2, statSync as statSync3 } from "node:fs";
|
|
29133
29165
|
import { open as open8 } from "node:fs/promises";
|
|
29134
|
-
import { dirname as dirname14, resolve as
|
|
29166
|
+
import { dirname as dirname14, resolve as resolve13 } from "node:path";
|
|
29135
29167
|
function chmodPrivate2(path5) {
|
|
29136
29168
|
try {
|
|
29137
29169
|
chmodSync2(path5, 384);
|
|
@@ -29182,7 +29214,7 @@ async function openWindowsFile2(sink, file) {
|
|
|
29182
29214
|
return sink.handle;
|
|
29183
29215
|
}
|
|
29184
29216
|
async function flushWindowsFile2(sink, file, text2) {
|
|
29185
|
-
file =
|
|
29217
|
+
file = resolve13(file);
|
|
29186
29218
|
try {
|
|
29187
29219
|
if (sink.file !== file)
|
|
29188
29220
|
await closeWindowsFile2(sink);
|
|
@@ -29467,6 +29499,10 @@ function createVaultRequestCredentials(source, onAdmitted) {
|
|
|
29467
29499
|
const issued = /* @__PURE__ */ new WeakMap();
|
|
29468
29500
|
return {
|
|
29469
29501
|
domain: "vault",
|
|
29502
|
+
routingCandidate: (row) => ({
|
|
29503
|
+
accountId: row.route.accountIdentity,
|
|
29504
|
+
credentialId: row.route.credentialId
|
|
29505
|
+
}),
|
|
29470
29506
|
...source.retryAfter401 && {
|
|
29471
29507
|
retryAfter401(served, current, site) {
|
|
29472
29508
|
const original = issued.get(served);
|
|
@@ -29978,7 +30014,7 @@ var init_vault_insula_quota = __esm({
|
|
|
29978
30014
|
|
|
29979
30015
|
// src/plugin/vault-custody.ts
|
|
29980
30016
|
import { chmod as chmod3, mkdir as mkdir11, readFile as readFile9, stat as stat8 } from "node:fs/promises";
|
|
29981
|
-
import { join as
|
|
30017
|
+
import { join as join11 } from "node:path";
|
|
29982
30018
|
async function enrollmentFilesIdentity(paths) {
|
|
29983
30019
|
const takenAt = performance.now();
|
|
29984
30020
|
let coarse = process.platform === "win32";
|
|
@@ -30002,9 +30038,9 @@ function openCodeVaultPaths(vaultDir) {
|
|
|
30002
30038
|
const dir = vaultDir;
|
|
30003
30039
|
return {
|
|
30004
30040
|
dir,
|
|
30005
|
-
modeFile:
|
|
30006
|
-
rosterFile:
|
|
30007
|
-
stateFile:
|
|
30041
|
+
modeFile: join11(dir, "opencode-mode.json"),
|
|
30042
|
+
rosterFile: join11(dir, "opencode-roster.json"),
|
|
30043
|
+
stateFile: join11(dir, "opencode-state.json")
|
|
30008
30044
|
};
|
|
30009
30045
|
}
|
|
30010
30046
|
async function ensureVaultDir(dir) {
|
|
@@ -30241,11 +30277,11 @@ function createOpenCodeVaultCustody(options) {
|
|
|
30241
30277
|
].join("\n");
|
|
30242
30278
|
const waitForApproval = async () => {
|
|
30243
30279
|
while (!closed2) {
|
|
30244
|
-
await new Promise((
|
|
30280
|
+
await new Promise((resolve27) => {
|
|
30245
30281
|
const done = () => {
|
|
30246
30282
|
clearTimeout(timer);
|
|
30247
30283
|
cancelWait = void 0;
|
|
30248
|
-
|
|
30284
|
+
resolve27();
|
|
30249
30285
|
};
|
|
30250
30286
|
const timer = setTimeout(done, 2e3);
|
|
30251
30287
|
timer.unref?.();
|
|
@@ -30632,20 +30668,20 @@ import { randomUUID as randomUUID14 } from "node:crypto";
|
|
|
30632
30668
|
import { realpathSync, rmSync } from "node:fs";
|
|
30633
30669
|
import { chmod as chmod4, mkdir as mkdir12, readFile as readFile10, rename as rename9, rm as rm5, writeFile as writeFile3 } from "node:fs/promises";
|
|
30634
30670
|
import { homedir as homedir2 } from "node:os";
|
|
30635
|
-
import { join as
|
|
30671
|
+
import { join as join12, resolve as resolve14 } from "node:path";
|
|
30636
30672
|
function processHeartbeatDir() {
|
|
30637
|
-
const base = process.env.XDG_STATE_HOME ||
|
|
30638
|
-
return
|
|
30673
|
+
const base = process.env.XDG_STATE_HOME || join12(homedir2(), ".local", "state");
|
|
30674
|
+
return join12(base, "cortexkit", "antigravity-auth", "processes");
|
|
30639
30675
|
}
|
|
30640
30676
|
function processHeartbeatPath(pid = process.pid, dir = processHeartbeatDir()) {
|
|
30641
|
-
return
|
|
30677
|
+
return join12(dir, `${pid}.json`);
|
|
30642
30678
|
}
|
|
30643
30679
|
function processConfigFolderKey() {
|
|
30644
30680
|
const folder = getConfigDir();
|
|
30645
30681
|
try {
|
|
30646
30682
|
return realpathSync.native(folder);
|
|
30647
30683
|
} catch {
|
|
30648
|
-
return
|
|
30684
|
+
return resolve14(folder);
|
|
30649
30685
|
}
|
|
30650
30686
|
}
|
|
30651
30687
|
function processHasOlderGeneration() {
|
|
@@ -30881,17 +30917,17 @@ var init_process_heartbeat = __esm({
|
|
|
30881
30917
|
});
|
|
30882
30918
|
|
|
30883
30919
|
// src/version-fence.ts
|
|
30884
|
-
import { readdir as readdir2, readFile as readFile11 } from "node:fs/promises";
|
|
30885
|
-
import { homedir as homedir3 } from "node:os";
|
|
30886
|
-
import { join as
|
|
30920
|
+
import { readdir as readdir2, readFile as readFile11, stat as stat9, unlink as unlink9 } from "node:fs/promises";
|
|
30921
|
+
import { homedir as homedir3, uptime } from "node:os";
|
|
30922
|
+
import { join as join13 } from "node:path";
|
|
30887
30923
|
function defaultStateHome() {
|
|
30888
|
-
return process.env.XDG_STATE_HOME ||
|
|
30924
|
+
return process.env.XDG_STATE_HOME || join13(homedir3(), ".local", "state");
|
|
30889
30925
|
}
|
|
30890
30926
|
function processHeartbeatDir2(stateHome = defaultStateHome()) {
|
|
30891
|
-
return
|
|
30927
|
+
return join13(stateHome, "cortexkit", "antigravity-auth", "processes");
|
|
30892
30928
|
}
|
|
30893
30929
|
function rpcStateRoot(stateHome = defaultStateHome()) {
|
|
30894
|
-
return
|
|
30930
|
+
return join13(stateHome, "cortexkit", "antigravity-auth", "rpc");
|
|
30895
30931
|
}
|
|
30896
30932
|
function isRpcProjectDir(name) {
|
|
30897
30933
|
return /^[0-9a-f]{16}$/.test(name);
|
|
@@ -30965,13 +31001,18 @@ async function readProcessRecord(path5, pid) {
|
|
|
30965
31001
|
return { kind: "gone" };
|
|
30966
31002
|
return { kind: "unreadable" };
|
|
30967
31003
|
}
|
|
31004
|
+
let startedAt;
|
|
30968
31005
|
try {
|
|
30969
31006
|
const value = JSON.parse(text2);
|
|
31007
|
+
if (isRecord10(value) && typeof value.startedAt === "number" && Number.isFinite(value.startedAt))
|
|
31008
|
+
startedAt = value.startedAt;
|
|
30970
31009
|
if (value !== null && typeof value === "object" && value.pid === pid && typeof value.version === "string") {
|
|
30971
31010
|
const layouts = value.layouts;
|
|
30972
31011
|
const stores = value.stores;
|
|
30973
31012
|
return {
|
|
30974
31013
|
kind: "ok",
|
|
31014
|
+
text: text2,
|
|
31015
|
+
startedAt,
|
|
30975
31016
|
version: value.version,
|
|
30976
31017
|
...isRecord10(layouts) ? { layouts } : {},
|
|
30977
31018
|
...isRecord10(stores) ? { stores } : {}
|
|
@@ -30979,14 +31020,45 @@ async function readProcessRecord(path5, pid) {
|
|
|
30979
31020
|
}
|
|
30980
31021
|
} catch {
|
|
30981
31022
|
}
|
|
30982
|
-
return { kind: "unreadable" };
|
|
31023
|
+
return { kind: "unreadable", text: text2, startedAt };
|
|
30983
31024
|
}
|
|
30984
31025
|
function isRecord10(value) {
|
|
30985
31026
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
30986
31027
|
}
|
|
31028
|
+
function bootTime(options) {
|
|
31029
|
+
try {
|
|
31030
|
+
return (options.now ?? Date.now)() - (options.uptimeSeconds ?? uptime)() * 1e3;
|
|
31031
|
+
} catch {
|
|
31032
|
+
return Number.NaN;
|
|
31033
|
+
}
|
|
31034
|
+
}
|
|
31035
|
+
async function staleRecord(path5, record3, boot, heartbeat) {
|
|
31036
|
+
if (record3.text === void 0 || !Number.isFinite(boot)) return false;
|
|
31037
|
+
let start = heartbeat ? record3.startedAt : void 0;
|
|
31038
|
+
if (start === void 0) {
|
|
31039
|
+
try {
|
|
31040
|
+
start = (await stat9(path5)).mtimeMs;
|
|
31041
|
+
} catch {
|
|
31042
|
+
return false;
|
|
31043
|
+
}
|
|
31044
|
+
}
|
|
31045
|
+
if (!Number.isFinite(start) || !(start < boot - BOOT_TIME_MARGIN_MS))
|
|
31046
|
+
return false;
|
|
31047
|
+
if (heartbeat) {
|
|
31048
|
+
try {
|
|
31049
|
+
if (await readFile11(path5, "utf8") === record3.text) {
|
|
31050
|
+
await unlink9(path5);
|
|
31051
|
+
log5.debug("Removed stale pre-boot heartbeat", { path: path5 });
|
|
31052
|
+
}
|
|
31053
|
+
} catch {
|
|
31054
|
+
}
|
|
31055
|
+
}
|
|
31056
|
+
return true;
|
|
31057
|
+
}
|
|
30987
31058
|
async function versionFenceOpen(options) {
|
|
30988
31059
|
const isAlive = options.isAlive ?? pidAlive;
|
|
30989
31060
|
const self = options.selfPid ?? process.pid;
|
|
31061
|
+
const boot = bootTime(options);
|
|
30990
31062
|
const blockers = /* @__PURE__ */ new Map();
|
|
30991
31063
|
const block = (entry) => {
|
|
30992
31064
|
const key = entry.pid === "unknown" ? `dir:${entry.detail}` : entry.pid;
|
|
@@ -31006,10 +31078,11 @@ async function versionFenceOpen(options) {
|
|
|
31006
31078
|
for (const name of heartbeats.ok ? heartbeats.names : []) {
|
|
31007
31079
|
const pid = pidFrom(name, /^(\d+)\.json$/);
|
|
31008
31080
|
if (pid === void 0 || pid === self) continue;
|
|
31009
|
-
const path5 =
|
|
31081
|
+
const path5 = join13(heartbeatDir, name);
|
|
31010
31082
|
const heartbeat = await readProcessRecord(path5, pid);
|
|
31011
31083
|
if (heartbeat.kind === "gone") continue;
|
|
31012
|
-
|
|
31084
|
+
const live = alive(pid);
|
|
31085
|
+
if (await staleRecord(path5, heartbeat, boot, true) || !live) continue;
|
|
31013
31086
|
if (heartbeat.kind === "unreadable") {
|
|
31014
31087
|
block({ pid, version: "unknown", detail: path5 });
|
|
31015
31088
|
continue;
|
|
@@ -31030,7 +31103,7 @@ async function versionFenceOpen(options) {
|
|
|
31030
31103
|
block({ pid: "unknown", version: "unknown", detail: projects.error });
|
|
31031
31104
|
for (const project2 of projects.ok ? projects.names : []) {
|
|
31032
31105
|
if (!isRpcProjectDir(project2)) continue;
|
|
31033
|
-
const dir =
|
|
31106
|
+
const dir = join13(rpcRoot, project2);
|
|
31034
31107
|
const ports = await list2(dir);
|
|
31035
31108
|
if (!ports.ok) {
|
|
31036
31109
|
if (ports.code === "ENOTDIR") continue;
|
|
@@ -31040,9 +31113,10 @@ async function versionFenceOpen(options) {
|
|
|
31040
31113
|
for (const name of ports.names) {
|
|
31041
31114
|
const pid = pidFrom(name, /^port-(\d+)\.json$/);
|
|
31042
31115
|
if (pid === void 0 || pid === self || !alive(pid)) continue;
|
|
31043
|
-
const path5 =
|
|
31116
|
+
const path5 = join13(dir, name);
|
|
31044
31117
|
const port = await readProcessRecord(path5, pid);
|
|
31045
31118
|
if (port.kind === "gone") continue;
|
|
31119
|
+
if (await staleRecord(path5, port, boot, false)) continue;
|
|
31046
31120
|
const version = port.kind === "ok" ? port.version : "unknown";
|
|
31047
31121
|
const order = compareVersions(version, options.currentVersion);
|
|
31048
31122
|
if (order === void 0 || order < 0)
|
|
@@ -31055,9 +31129,109 @@ async function versionFenceOpen(options) {
|
|
|
31055
31129
|
blockers: [...blockers.values()].sort((a, b) => rank(a) - rank(b))
|
|
31056
31130
|
};
|
|
31057
31131
|
}
|
|
31132
|
+
var log5, BOOT_TIME_MARGIN_MS;
|
|
31058
31133
|
var init_version_fence = __esm({
|
|
31059
31134
|
"src/version-fence.ts"() {
|
|
31060
31135
|
"use strict";
|
|
31136
|
+
init_logger4();
|
|
31137
|
+
log5 = createLogger4("version-fence");
|
|
31138
|
+
BOOT_TIME_MARGIN_MS = 3e5;
|
|
31139
|
+
}
|
|
31140
|
+
});
|
|
31141
|
+
|
|
31142
|
+
// src/vault-folder.ts
|
|
31143
|
+
var vault_folder_exports = {};
|
|
31144
|
+
__export(vault_folder_exports, {
|
|
31145
|
+
__resetVaultFoldersForTest: () => __resetVaultFoldersForTest,
|
|
31146
|
+
currentVaultFolder: () => currentVaultFolder,
|
|
31147
|
+
prepareVaultFolder: () => prepareVaultFolder
|
|
31148
|
+
});
|
|
31149
|
+
import { isAbsolute as isAbsolute3 } from "node:path";
|
|
31150
|
+
function vaultOverride(accountFile) {
|
|
31151
|
+
const kept = refusals.get(overrideRefusalKey);
|
|
31152
|
+
if (kept) return { accountFile, vaultDir: kept.stateDir, refusal: kept };
|
|
31153
|
+
const vaultDir = process.env[OVERRIDE];
|
|
31154
|
+
if (!vaultDir) return void 0;
|
|
31155
|
+
if (isAbsolute3(vaultDir)) return { accountFile, vaultDir };
|
|
31156
|
+
const refusal3 = new RuntimeLayoutRefusal(
|
|
31157
|
+
vaultDir,
|
|
31158
|
+
"relative-vault-dir",
|
|
31159
|
+
`antigravity-auth cannot start: ${OVERRIDE} must be an absolute path. Correct it and restart OpenCode.`
|
|
31160
|
+
);
|
|
31161
|
+
refusals.set(overrideRefusalKey, refusal3);
|
|
31162
|
+
return { accountFile, vaultDir, refusal: refusal3 };
|
|
31163
|
+
}
|
|
31164
|
+
function locationKey() {
|
|
31165
|
+
const location = runtimeLayoutLocation();
|
|
31166
|
+
return `${location.stateHomeDir}\0${location.key}`;
|
|
31167
|
+
}
|
|
31168
|
+
function __resetVaultFoldersForTest() {
|
|
31169
|
+
refusals.clear();
|
|
31170
|
+
}
|
|
31171
|
+
async function prepareVaultFolder(options) {
|
|
31172
|
+
const { accountFile } = options;
|
|
31173
|
+
const override = vaultOverride(accountFile);
|
|
31174
|
+
if (override?.refusal) return override;
|
|
31175
|
+
const key = locationKey();
|
|
31176
|
+
const kept = refusals.get(key);
|
|
31177
|
+
if (kept)
|
|
31178
|
+
return override ? { ...override, refusal: kept } : refused(accountFile, kept);
|
|
31179
|
+
const log17 = options.log ?? createLogger4("runtime-layout");
|
|
31180
|
+
const version = options.version ?? await pluginPackageVersion().catch(() => "unknown");
|
|
31181
|
+
try {
|
|
31182
|
+
if (override) {
|
|
31183
|
+
await ensurePrivateDirectory2(override.vaultDir);
|
|
31184
|
+
} else
|
|
31185
|
+
await prepareRuntimeLayout({
|
|
31186
|
+
version,
|
|
31187
|
+
accountFile,
|
|
31188
|
+
log: log17,
|
|
31189
|
+
...options.layoutLockWaitMs === void 0 ? {} : { layoutLockWaitMs: options.layoutLockWaitMs }
|
|
31190
|
+
});
|
|
31191
|
+
if (options.accountStore !== false)
|
|
31192
|
+
await prepareAccountStore({ version, log: log17 });
|
|
31193
|
+
} catch (error) {
|
|
31194
|
+
const refusal3 = error instanceof RuntimeLayoutRefusal ? error : new RuntimeLayoutRefusal(
|
|
31195
|
+
override?.vaultDir ?? runtimeLayoutLocation().stateHomeDir,
|
|
31196
|
+
error instanceof Error ? error.name : typeof error
|
|
31197
|
+
);
|
|
31198
|
+
if (!refusals.has(key)) {
|
|
31199
|
+
refusals.set(key, refusal3);
|
|
31200
|
+
log17.warn(refusal3.message, {
|
|
31201
|
+
stateDir: refusal3.stateDir,
|
|
31202
|
+
errorClass: refusal3.errorClass
|
|
31203
|
+
});
|
|
31204
|
+
}
|
|
31205
|
+
return override ? { ...override, refusal: refusals.get(key) ?? refusal3 } : refused(accountFile, refusals.get(key) ?? refusal3);
|
|
31206
|
+
}
|
|
31207
|
+
return override ?? { accountFile, vaultDir: getVaultDir(accountFile) };
|
|
31208
|
+
}
|
|
31209
|
+
function currentVaultFolder(accountFile) {
|
|
31210
|
+
const override = vaultOverride(accountFile);
|
|
31211
|
+
if (override?.refusal) return override;
|
|
31212
|
+
const kept = refusals.get(locationKey());
|
|
31213
|
+
return kept ? override ? { ...override, refusal: kept } : refused(accountFile, kept) : override ?? { accountFile, vaultDir: getVaultDir(accountFile) };
|
|
31214
|
+
}
|
|
31215
|
+
function refused(accountFile, refusal3) {
|
|
31216
|
+
return { accountFile, vaultDir: getVaultDir(accountFile), refusal: refusal3 };
|
|
31217
|
+
}
|
|
31218
|
+
var refusalsKey, globalState2, refusals, OVERRIDE, overrideRefusalKey;
|
|
31219
|
+
var init_vault_folder = __esm({
|
|
31220
|
+
"src/vault-folder.ts"() {
|
|
31221
|
+
"use strict";
|
|
31222
|
+
init_private_files2();
|
|
31223
|
+
init_logger4();
|
|
31224
|
+
init_process_heartbeat();
|
|
31225
|
+
init_runtime_layout();
|
|
31226
|
+
init_runtime_paths();
|
|
31227
|
+
refusalsKey = /* @__PURE__ */ Symbol.for(
|
|
31228
|
+
"@cortexkit/antigravity-auth/vault-folder-refusals"
|
|
31229
|
+
);
|
|
31230
|
+
globalState2 = globalThis;
|
|
31231
|
+
refusals = globalState2[refusalsKey] ?? /* @__PURE__ */ new Map();
|
|
31232
|
+
globalState2[refusalsKey] = refusals;
|
|
31233
|
+
OVERRIDE = "OPENCODE_ANTIGRAVITY_AUTH_VAULT_DIR";
|
|
31234
|
+
overrideRefusalKey = "invalid-vault-dir-override";
|
|
31061
31235
|
}
|
|
31062
31236
|
});
|
|
31063
31237
|
|
|
@@ -31088,10 +31262,10 @@ import {
|
|
|
31088
31262
|
readFile as readFile12,
|
|
31089
31263
|
rename as rename10,
|
|
31090
31264
|
rmdir as rmdir2,
|
|
31091
|
-
stat as
|
|
31092
|
-
unlink as
|
|
31265
|
+
stat as stat10,
|
|
31266
|
+
unlink as unlink10
|
|
31093
31267
|
} from "node:fs/promises";
|
|
31094
|
-
import { basename as basename4, dirname as dirname15, join as
|
|
31268
|
+
import { basename as basename4, dirname as dirname15, join as join14, resolve as resolve15 } from "node:path";
|
|
31095
31269
|
function refusalMessage(stateDir, errorClass2) {
|
|
31096
31270
|
if (errorClass2 === "ERR_PRIVATE_FILES_SECURITY")
|
|
31097
31271
|
return `antigravity-auth cannot start: ${stateDir} is not a folder only your user can access, or it is a link, so the plugin will not use it (${errorClass2}). Replace it with a plain folder of your own, then restart OpenCode.`;
|
|
@@ -31144,10 +31318,10 @@ function errorFile(error) {
|
|
|
31144
31318
|
...typeof stage === "string" && stage ? { stage } : {}
|
|
31145
31319
|
};
|
|
31146
31320
|
}
|
|
31147
|
-
function logCleanupFailure(location,
|
|
31321
|
+
function logCleanupFailure(location, log17, step, error) {
|
|
31148
31322
|
logOnce(
|
|
31149
31323
|
`${location.key}\0cleanup`,
|
|
31150
|
-
() =>
|
|
31324
|
+
() => log17.warn(
|
|
31151
31325
|
"antigravity-auth could not finish removing its old vault files from OpenCode's config folder; it tries again at the next start",
|
|
31152
31326
|
{
|
|
31153
31327
|
configDir: location.configDir,
|
|
@@ -31176,13 +31350,13 @@ function prepareRuntimeLayout(options) {
|
|
|
31176
31350
|
return run;
|
|
31177
31351
|
}
|
|
31178
31352
|
async function decide(location, options) {
|
|
31179
|
-
const
|
|
31353
|
+
const log17 = options.log ?? createLogger4("runtime-layout");
|
|
31180
31354
|
const stateDir = location.stateHomeDir;
|
|
31181
|
-
const markerPath =
|
|
31355
|
+
const markerPath = join14(stateDir, RUNTIME_LAYOUT_MARKER_FILE);
|
|
31182
31356
|
const files = layoutFiles(location, options.accountFile);
|
|
31183
31357
|
const fence = options.fence ?? defaultFence(options.version);
|
|
31184
31358
|
const stateHome = async () => {
|
|
31185
|
-
await settleVault(location, options, "state-home",
|
|
31359
|
+
await settleVault(location, options, "state-home", log17);
|
|
31186
31360
|
return "state-home";
|
|
31187
31361
|
};
|
|
31188
31362
|
let marker = await readMarker(markerPath, stateDir, files.vault.old);
|
|
@@ -31190,10 +31364,10 @@ async function decide(location, options) {
|
|
|
31190
31364
|
if (marker?.oldFilesRemoved) {
|
|
31191
31365
|
await refuseReappearedFiles(location, files);
|
|
31192
31366
|
const manifestLeft = await exists2(
|
|
31193
|
-
|
|
31367
|
+
join14(stateDir, RUNTIME_LAYOUT_MANIFEST_FILE)
|
|
31194
31368
|
).catch(() => true);
|
|
31195
31369
|
if (!manifestLeft) {
|
|
31196
|
-
await settleVault(location, options, "state-home",
|
|
31370
|
+
await settleVault(location, options, "state-home", log17);
|
|
31197
31371
|
return stateHome();
|
|
31198
31372
|
}
|
|
31199
31373
|
}
|
|
@@ -31205,7 +31379,7 @@ async function decide(location, options) {
|
|
|
31205
31379
|
RUNTIME_LAYOUT_LOCK_NAME,
|
|
31206
31380
|
markerPath,
|
|
31207
31381
|
options.layoutLockWaitMs ?? LAYOUT_LOCK_WAIT_MS,
|
|
31208
|
-
|
|
31382
|
+
log17
|
|
31209
31383
|
);
|
|
31210
31384
|
} catch (error) {
|
|
31211
31385
|
marker = await readMarker(markerPath, stateDir, files.vault.old);
|
|
@@ -31225,7 +31399,7 @@ async function decide(location, options) {
|
|
|
31225
31399
|
const legacy = async () => {
|
|
31226
31400
|
try {
|
|
31227
31401
|
await lock.assertOwned();
|
|
31228
|
-
await settleVault(location, options, "legacy",
|
|
31402
|
+
await settleVault(location, options, "legacy", log17);
|
|
31229
31403
|
} catch (error) {
|
|
31230
31404
|
throw new RuntimeLayoutRefusal(stateDir, errorClass(error));
|
|
31231
31405
|
}
|
|
@@ -31239,20 +31413,20 @@ async function decide(location, options) {
|
|
|
31239
31413
|
if (!marker.oldFilesRemoved && !aliased)
|
|
31240
31414
|
await finishOldFiles(location, files, markerPath, marker, lock, {
|
|
31241
31415
|
fence,
|
|
31242
|
-
log:
|
|
31416
|
+
log: log17,
|
|
31243
31417
|
steps: options.steps,
|
|
31244
31418
|
oldSignatureCache: options.oldSignatureCacheFile ?? legacySignatureCacheFile()
|
|
31245
31419
|
});
|
|
31246
31420
|
else if (marker.oldFilesRemoved) {
|
|
31247
31421
|
await refuseReappearedFiles(location, files);
|
|
31248
|
-
await removeLeftoverManifest(location, lock, options.steps,
|
|
31422
|
+
await removeLeftoverManifest(location, lock, options.steps, log17);
|
|
31249
31423
|
}
|
|
31250
31424
|
return await stateHome();
|
|
31251
31425
|
}
|
|
31252
31426
|
if (aliased) {
|
|
31253
31427
|
logOnce(
|
|
31254
31428
|
`${location.key}\0aliased`,
|
|
31255
|
-
() =>
|
|
31429
|
+
() => log17.warn(
|
|
31256
31430
|
"antigravity-auth keeps its vault files in OpenCode's config folder: its state folder is that same folder",
|
|
31257
31431
|
{ configDir: location.configDir, stateDir }
|
|
31258
31432
|
)
|
|
@@ -31261,14 +31435,14 @@ async function decide(location, options) {
|
|
|
31261
31435
|
}
|
|
31262
31436
|
const gate = await fence();
|
|
31263
31437
|
if (!gate.open) {
|
|
31264
|
-
logDeferral(location, gate.blockers,
|
|
31438
|
+
logDeferral(location, gate.blockers, log17);
|
|
31265
31439
|
return await legacy();
|
|
31266
31440
|
}
|
|
31267
31441
|
let markerStarted = false;
|
|
31268
31442
|
try {
|
|
31269
31443
|
const outcome = await moveFiles(location, files, markerPath, lock, {
|
|
31270
31444
|
fence,
|
|
31271
|
-
log:
|
|
31445
|
+
log: log17,
|
|
31272
31446
|
steps: options.steps,
|
|
31273
31447
|
destinationPrivate: options.destinationPrivate ?? defaultDestinationPrivate,
|
|
31274
31448
|
oldSignatureCache: options.oldSignatureCacheFile ?? legacySignatureCacheFile(),
|
|
@@ -31277,13 +31451,13 @@ async function decide(location, options) {
|
|
|
31277
31451
|
}
|
|
31278
31452
|
});
|
|
31279
31453
|
if (outcome.kind === "deferred") {
|
|
31280
|
-
logDeferral(location, outcome.blockers,
|
|
31454
|
+
logDeferral(location, outcome.blockers, log17);
|
|
31281
31455
|
return await legacy();
|
|
31282
31456
|
}
|
|
31283
31457
|
if (outcome.kind === "refused") {
|
|
31284
31458
|
logOnce(
|
|
31285
31459
|
`${location.key}\0refused`,
|
|
31286
|
-
() =>
|
|
31460
|
+
() => log17.warn(
|
|
31287
31461
|
outcome.reason === "destination-not-private" ? "antigravity-auth keeps its vault files in OpenCode's config folder: the vault folder in its state folder already exists and is not private to your user. It was left unchanged; remove it if it holds nothing you need, then restart OpenCode." : "antigravity-auth keeps its vault files in OpenCode's config folder: it will not move them",
|
|
31288
31462
|
{ reason: outcome.reason, paths: outcome.paths, stateDir }
|
|
31289
31463
|
)
|
|
@@ -31291,7 +31465,7 @@ async function decide(location, options) {
|
|
|
31291
31465
|
return await legacy();
|
|
31292
31466
|
}
|
|
31293
31467
|
if (outcome.moved)
|
|
31294
|
-
|
|
31468
|
+
log17.info(
|
|
31295
31469
|
"antigravity-auth moved its vault files out of OpenCode's config folder",
|
|
31296
31470
|
{ from: files.vault.old, to: files.vault.next }
|
|
31297
31471
|
);
|
|
@@ -31302,7 +31476,7 @@ async function decide(location, options) {
|
|
|
31302
31476
|
return await stateHome();
|
|
31303
31477
|
logOnce(
|
|
31304
31478
|
`${location.key}\0failed`,
|
|
31305
|
-
() =>
|
|
31479
|
+
() => log17.warn(
|
|
31306
31480
|
"antigravity-auth's vault files stay in OpenCode's config folder: moving them failed; the move is tried again at the next start",
|
|
31307
31481
|
{
|
|
31308
31482
|
configDir: location.configDir,
|
|
@@ -31331,8 +31505,12 @@ async function settleVault(location, options, layout, _log) {
|
|
|
31331
31505
|
}
|
|
31332
31506
|
async function localAccountStoreAuthorized() {
|
|
31333
31507
|
const location = runtimeLayoutLocation();
|
|
31508
|
+
const folder = process.env.OPENCODE_ANTIGRAVITY_AUTH_VAULT_DIR ? (await Promise.resolve().then(() => (init_vault_folder(), vault_folder_exports))).currentVaultFolder(
|
|
31509
|
+
accountFileForVault(location.configDir)
|
|
31510
|
+
) : void 0;
|
|
31511
|
+
if (folder?.refusal) return false;
|
|
31334
31512
|
const claustrum = await loadCommonAuthClaustrum();
|
|
31335
|
-
const vaultDir = decidedRuntimeLayout(location) === "state-home" ? stateHomeVaultDir(location) : legacyVaultDir(accountFileForVault(location.configDir));
|
|
31513
|
+
const vaultDir = folder ? folder.vaultDir : decidedRuntimeLayout(location) === "state-home" ? stateHomeVaultDir(location) : legacyVaultDir(accountFileForVault(location.configDir));
|
|
31336
31514
|
return await enrollmentAuthority2(
|
|
31337
31515
|
claustrum.hostEnrollmentPaths({
|
|
31338
31516
|
stateDir: vaultDir,
|
|
@@ -31347,7 +31525,7 @@ async function prepareAccountStore(options) {
|
|
|
31347
31525
|
if (!await localAccountStoreAuthorized()) return void 0;
|
|
31348
31526
|
const decided = decidedAccountStoreAnchor(location);
|
|
31349
31527
|
if (decided) return decided;
|
|
31350
|
-
const
|
|
31528
|
+
const log17 = options.log ?? createLogger4("runtime-layout");
|
|
31351
31529
|
const runKey = `${location.stateHomeDir}\0${location.key}`;
|
|
31352
31530
|
let run = processState.storeRuns.get(runKey);
|
|
31353
31531
|
if (!run) {
|
|
@@ -31356,14 +31534,14 @@ async function prepareAccountStore(options) {
|
|
|
31356
31534
|
await ensureOwnerOnlyDir(location.stateHomeDir);
|
|
31357
31535
|
const lock = await takeLock(
|
|
31358
31536
|
RUNTIME_LAYOUT_LOCK_NAME,
|
|
31359
|
-
|
|
31537
|
+
join14(location.stateHomeDir, RUNTIME_LAYOUT_MARKER_FILE),
|
|
31360
31538
|
options.layoutLockWaitMs ?? LAYOUT_LOCK_WAIT_MS,
|
|
31361
|
-
|
|
31539
|
+
log17
|
|
31362
31540
|
);
|
|
31363
31541
|
try {
|
|
31364
31542
|
await lock.assertOwned();
|
|
31365
31543
|
if (!await localAccountStoreAuthorized()) return void 0;
|
|
31366
|
-
return await settleAccountStore(location, options,
|
|
31544
|
+
return await settleAccountStore(location, options, log17);
|
|
31367
31545
|
} finally {
|
|
31368
31546
|
await lock.release();
|
|
31369
31547
|
}
|
|
@@ -31374,20 +31552,20 @@ async function prepareAccountStore(options) {
|
|
|
31374
31552
|
}
|
|
31375
31553
|
return run;
|
|
31376
31554
|
}
|
|
31377
|
-
async function settleAccountStore(location, options,
|
|
31555
|
+
async function settleAccountStore(location, options, log17) {
|
|
31378
31556
|
const decided = decidedAccountStoreAnchor(location);
|
|
31379
31557
|
if (decided) return decided;
|
|
31380
|
-
const anchor = await decideAccountStore(location, options,
|
|
31558
|
+
const anchor = await decideAccountStore(location, options, log17);
|
|
31381
31559
|
setAccountStoreAnchor(location, anchor);
|
|
31382
31560
|
return anchor;
|
|
31383
31561
|
}
|
|
31384
|
-
async function decideAccountStore(location, options,
|
|
31385
|
-
const keepConfig = () => recordAnchor(location, options, "config",
|
|
31562
|
+
async function decideAccountStore(location, options, log17) {
|
|
31563
|
+
const keepConfig = () => recordAnchor(location, options, "config", log17);
|
|
31386
31564
|
if (processHasOlderGeneration()) {
|
|
31387
31565
|
logOnce(
|
|
31388
31566
|
"older-generation-account-store",
|
|
31389
31567
|
() => showLog(
|
|
31390
|
-
|
|
31568
|
+
log17,
|
|
31391
31569
|
"antigravity-auth keeps the account store in OpenCode's config folder until OpenCode restarts, because an older version of the plugin ran in this process.",
|
|
31392
31570
|
{ accountStore: "config" }
|
|
31393
31571
|
)
|
|
@@ -31401,7 +31579,7 @@ async function decideAccountStore(location, options, log16) {
|
|
|
31401
31579
|
if (!sameSpelling(forward.legacyPath, stateAnchor)) {
|
|
31402
31580
|
logOnce(
|
|
31403
31581
|
`${location.key}\0store-forward-elsewhere`,
|
|
31404
|
-
() =>
|
|
31582
|
+
() => log17.warn(
|
|
31405
31583
|
"the account store moved to another folder than this process resolved; check XDG_STATE_HOME",
|
|
31406
31584
|
{ movedTo: forward.legacyPath, expected: stateAnchor }
|
|
31407
31585
|
)
|
|
@@ -31412,9 +31590,9 @@ async function decideAccountStore(location, options, log16) {
|
|
|
31412
31590
|
options,
|
|
31413
31591
|
configAnchor,
|
|
31414
31592
|
stateAnchor,
|
|
31415
|
-
|
|
31593
|
+
log17
|
|
31416
31594
|
);
|
|
31417
|
-
return recordAnchor(location, options, "state-home",
|
|
31595
|
+
return recordAnchor(location, options, "state-home", log17);
|
|
31418
31596
|
}
|
|
31419
31597
|
if (decidedRuntimeLayout(location) === "legacy") return keepConfig();
|
|
31420
31598
|
const configStore = await presentAccountStore(configAnchor);
|
|
@@ -31426,9 +31604,9 @@ async function decideAccountStore(location, options, log16) {
|
|
|
31426
31604
|
`antigravity-auth cannot start: two account stores exist, one at ${configAnchor} and one at ${stateAnchor}, and neither is marked as moved. Keep the one you want and move the other one aside, then restart OpenCode.`
|
|
31427
31605
|
);
|
|
31428
31606
|
}
|
|
31429
|
-
if (stateStore) return recordAnchor(location, options, "state-home",
|
|
31607
|
+
if (stateStore) return recordAnchor(location, options, "state-home", log17);
|
|
31430
31608
|
if (configStore) {
|
|
31431
|
-
if (!await storeMovePathResolves(stateAnchor, location,
|
|
31609
|
+
if (!await storeMovePathResolves(stateAnchor, location, log17))
|
|
31432
31610
|
return keepConfig();
|
|
31433
31611
|
return moveStore(
|
|
31434
31612
|
location,
|
|
@@ -31436,21 +31614,21 @@ async function decideAccountStore(location, options, log16) {
|
|
|
31436
31614
|
configAnchor,
|
|
31437
31615
|
stateAnchor,
|
|
31438
31616
|
false,
|
|
31439
|
-
|
|
31617
|
+
log17,
|
|
31440
31618
|
false
|
|
31441
31619
|
);
|
|
31442
31620
|
}
|
|
31443
|
-
if (await storeArtefacts(stateAnchor) > 0 && !await abandonUnpublishedStore(location, stateAnchor,
|
|
31621
|
+
if (await storeArtefacts(stateAnchor) > 0 && !await abandonUnpublishedStore(location, stateAnchor, log17))
|
|
31444
31622
|
return keepConfig();
|
|
31445
|
-
if (!await storeMovePathResolves(stateAnchor, location,
|
|
31623
|
+
if (!await storeMovePathResolves(stateAnchor, location, log17))
|
|
31446
31624
|
return keepConfig();
|
|
31447
|
-
return initializeStore(location, options, stateAnchor,
|
|
31625
|
+
return initializeStore(location, options, stateAnchor, log17);
|
|
31448
31626
|
}
|
|
31449
|
-
function showLog(
|
|
31450
|
-
if (
|
|
31451
|
-
else
|
|
31627
|
+
function showLog(log17, message, meta) {
|
|
31628
|
+
if (log17.log) log17.log(message, meta);
|
|
31629
|
+
else log17.info(message, meta);
|
|
31452
31630
|
}
|
|
31453
|
-
async function recordAnchor(location, options, anchor,
|
|
31631
|
+
async function recordAnchor(location, options, anchor, log17) {
|
|
31454
31632
|
try {
|
|
31455
31633
|
await recordProcessAnchor({
|
|
31456
31634
|
key: location.key,
|
|
@@ -31462,32 +31640,32 @@ async function recordAnchor(location, options, anchor, log16) {
|
|
|
31462
31640
|
}
|
|
31463
31641
|
if (anchor === "state-home")
|
|
31464
31642
|
showLog(
|
|
31465
|
-
|
|
31643
|
+
log17,
|
|
31466
31644
|
"antigravity-auth keeps its account store in its state folder",
|
|
31467
31645
|
{ accountStore: anchor }
|
|
31468
31646
|
);
|
|
31469
31647
|
return anchor;
|
|
31470
31648
|
}
|
|
31471
|
-
async function storeMovePathResolves(stateAnchor, location,
|
|
31649
|
+
async function storeMovePathResolves(stateAnchor, location, log17) {
|
|
31472
31650
|
if (folderResolvesToItself(
|
|
31473
|
-
|
|
31651
|
+
join14(location.stateHomeDir, "antigravity-accounts.json")
|
|
31474
31652
|
))
|
|
31475
31653
|
return true;
|
|
31476
31654
|
logOnce(
|
|
31477
31655
|
`${location.key}\0store-linked-path`,
|
|
31478
|
-
() =>
|
|
31656
|
+
() => log17.warn(ACCOUNT_STORE_LINKED_PATH_MESSAGE, {
|
|
31479
31657
|
accountStore: stateAnchor,
|
|
31480
31658
|
stateFolder: location.stateHomeDir
|
|
31481
31659
|
})
|
|
31482
31660
|
);
|
|
31483
31661
|
return false;
|
|
31484
31662
|
}
|
|
31485
|
-
async function storeFenceOpen(location, options,
|
|
31663
|
+
async function storeFenceOpen(location, options, log17) {
|
|
31486
31664
|
const gate = await (options.storeFence ?? defaultStoreFence(options.version))();
|
|
31487
31665
|
if (gate.open) return true;
|
|
31488
31666
|
logOnce(
|
|
31489
31667
|
`${location.key}\0store-version-fence`,
|
|
31490
|
-
() =>
|
|
31668
|
+
() => log17.info(ACCOUNT_STORE_DEFERRED_MESSAGE, {
|
|
31491
31669
|
configDir: location.configDir,
|
|
31492
31670
|
blockers: gate.blockers
|
|
31493
31671
|
})
|
|
@@ -31514,7 +31692,7 @@ async function storeArtefacts(anchor) {
|
|
|
31514
31692
|
(name) => name === store || name.startsWith(`${pool}.store.`) || name.startsWith(pool) && name.endsWith(".tmp")
|
|
31515
31693
|
).length;
|
|
31516
31694
|
}
|
|
31517
|
-
async function abandonUnpublishedStore(location, stateAnchor,
|
|
31695
|
+
async function abandonUnpublishedStore(location, stateAnchor, log17) {
|
|
31518
31696
|
const store = await loadCommonAuthStoreModules();
|
|
31519
31697
|
const binding = await readAccountStoreBinding(stateAnchor, store, Date.now);
|
|
31520
31698
|
if (binding.status === "bound") return false;
|
|
@@ -31523,9 +31701,9 @@ async function abandonUnpublishedStore(location, stateAnchor, log16) {
|
|
|
31523
31701
|
await rename10(folder, archived).catch((error) => {
|
|
31524
31702
|
if (error.code !== "ENOENT") throw error;
|
|
31525
31703
|
});
|
|
31526
|
-
await
|
|
31704
|
+
await unlink10(accountStorePointerPath(stateAnchor)).catch(() => {
|
|
31527
31705
|
});
|
|
31528
|
-
|
|
31706
|
+
log17.info(
|
|
31529
31707
|
"antigravity-auth set an unfinished account store aside before starting its move again",
|
|
31530
31708
|
{ configDir: location.configDir, archived }
|
|
31531
31709
|
);
|
|
@@ -31547,9 +31725,9 @@ async function runStoreMove(input2) {
|
|
|
31547
31725
|
return { status: "pending", reason: outcome.reason };
|
|
31548
31726
|
return { status: "cancelled" };
|
|
31549
31727
|
}
|
|
31550
|
-
async function moveStore(location, options, source, target, back,
|
|
31551
|
-
const keepConfig = () => recordAnchor(location, options, "config",
|
|
31552
|
-
if (!await storeFenceOpen(location, options,
|
|
31728
|
+
async function moveStore(location, options, source, target, back, log17, forwarded) {
|
|
31729
|
+
const keepConfig = () => recordAnchor(location, options, "config", log17);
|
|
31730
|
+
if (!await storeFenceOpen(location, options, log17)) return keepConfig();
|
|
31553
31731
|
try {
|
|
31554
31732
|
const result = await (options.relocate ?? runStoreMove)({
|
|
31555
31733
|
source,
|
|
@@ -31559,7 +31737,7 @@ async function moveStore(location, options, source, target, back, log16, forward
|
|
|
31559
31737
|
if (result.status !== "completed") {
|
|
31560
31738
|
logOnce(
|
|
31561
31739
|
`${location.key}\0store-move-unfinished`,
|
|
31562
|
-
() =>
|
|
31740
|
+
() => log17.info(ACCOUNT_STORE_DEFERRED_MESSAGE, {
|
|
31563
31741
|
configDir: location.configDir,
|
|
31564
31742
|
reason: result.status === "pending" ? result.reason : result.status
|
|
31565
31743
|
})
|
|
@@ -31567,14 +31745,14 @@ async function moveStore(location, options, source, target, back, log16, forward
|
|
|
31567
31745
|
return forwarded ? "state-home" : keepConfig();
|
|
31568
31746
|
}
|
|
31569
31747
|
showLog(
|
|
31570
|
-
|
|
31748
|
+
log17,
|
|
31571
31749
|
"antigravity-auth moved the account store out of OpenCode's config folder",
|
|
31572
31750
|
{ from: source, to: target, generation: result.id }
|
|
31573
31751
|
);
|
|
31574
31752
|
} catch (error) {
|
|
31575
31753
|
logOnce(
|
|
31576
31754
|
`${location.key}\0store-move-failed`,
|
|
31577
|
-
() =>
|
|
31755
|
+
() => log17.warn(
|
|
31578
31756
|
"antigravity-auth's account store stays in OpenCode's config folder: moving it failed; the move is tried again at the next start",
|
|
31579
31757
|
{
|
|
31580
31758
|
configDir: location.configDir,
|
|
@@ -31585,9 +31763,9 @@ async function moveStore(location, options, source, target, back, log16, forward
|
|
|
31585
31763
|
);
|
|
31586
31764
|
return forwarded ? "state-home" : keepConfig();
|
|
31587
31765
|
}
|
|
31588
|
-
return recordAnchor(location, options, "state-home",
|
|
31766
|
+
return recordAnchor(location, options, "state-home", log17);
|
|
31589
31767
|
}
|
|
31590
|
-
async function resumeForwardedStore(location, options, configAnchor, stateAnchor,
|
|
31768
|
+
async function resumeForwardedStore(location, options, configAnchor, stateAnchor, log17) {
|
|
31591
31769
|
const store = await loadCommonAuthStoreModules();
|
|
31592
31770
|
const binding = await readAccountStoreBinding(stateAnchor, store, Date.now);
|
|
31593
31771
|
if (binding.status === "bound") return;
|
|
@@ -31598,13 +31776,13 @@ async function resumeForwardedStore(location, options, configAnchor, stateAnchor
|
|
|
31598
31776
|
configAnchor,
|
|
31599
31777
|
stateAnchor,
|
|
31600
31778
|
false,
|
|
31601
|
-
|
|
31779
|
+
log17,
|
|
31602
31780
|
true
|
|
31603
31781
|
);
|
|
31604
31782
|
} catch (error) {
|
|
31605
31783
|
logOnce(
|
|
31606
31784
|
`${location.key}\0store-resume-failed`,
|
|
31607
|
-
() =>
|
|
31785
|
+
() => log17.warn(
|
|
31608
31786
|
"antigravity-auth's account store is still moving; it could not be finished at this start",
|
|
31609
31787
|
{
|
|
31610
31788
|
configDir: location.configDir,
|
|
@@ -31615,9 +31793,9 @@ async function resumeForwardedStore(location, options, configAnchor, stateAnchor
|
|
|
31615
31793
|
);
|
|
31616
31794
|
}
|
|
31617
31795
|
}
|
|
31618
|
-
async function initializeStore(location, options, stateAnchor,
|
|
31619
|
-
const keepConfig = () => recordAnchor(location, options, "config",
|
|
31620
|
-
if (!await storeFenceOpen(location, options,
|
|
31796
|
+
async function initializeStore(location, options, stateAnchor, log17) {
|
|
31797
|
+
const keepConfig = () => recordAnchor(location, options, "config", log17);
|
|
31798
|
+
if (!await storeFenceOpen(location, options, log17)) return keepConfig();
|
|
31621
31799
|
try {
|
|
31622
31800
|
const store = await loadCommonAuthStoreModules();
|
|
31623
31801
|
const created = await initializeFreshAccountStore(store, {
|
|
@@ -31630,7 +31808,7 @@ async function initializeStore(location, options, stateAnchor, log16) {
|
|
|
31630
31808
|
} catch (error) {
|
|
31631
31809
|
logOnce(
|
|
31632
31810
|
`${location.key}\0store-init-failed`,
|
|
31633
|
-
() =>
|
|
31811
|
+
() => log17.warn(
|
|
31634
31812
|
"antigravity-auth's account store stays in OpenCode's config folder: creating it in its state folder failed; it is tried again at the next start",
|
|
31635
31813
|
{
|
|
31636
31814
|
configDir: location.configDir,
|
|
@@ -31642,13 +31820,13 @@ async function initializeStore(location, options, stateAnchor, log16) {
|
|
|
31642
31820
|
return keepConfig();
|
|
31643
31821
|
}
|
|
31644
31822
|
showLog(
|
|
31645
|
-
|
|
31823
|
+
log17,
|
|
31646
31824
|
"antigravity-auth created its account store in its state folder",
|
|
31647
31825
|
{
|
|
31648
31826
|
accountStore: stateAnchor
|
|
31649
31827
|
}
|
|
31650
31828
|
);
|
|
31651
|
-
return recordAnchor(location, options, "state-home",
|
|
31829
|
+
return recordAnchor(location, options, "state-home", log17);
|
|
31652
31830
|
}
|
|
31653
31831
|
async function writeStateHomeStoreForward(id, stateAnchor, configAnchor = legacyAccountFile(runtimeLayoutLocation().configDir)) {
|
|
31654
31832
|
const forward = {
|
|
@@ -31663,10 +31841,10 @@ async function writeStateHomeStoreForward(id, stateAnchor, configAnchor = legacy
|
|
|
31663
31841
|
durability: "file-only-on-windows"
|
|
31664
31842
|
});
|
|
31665
31843
|
}
|
|
31666
|
-
function logDeferral(location, blockers,
|
|
31844
|
+
function logDeferral(location, blockers, log17) {
|
|
31667
31845
|
logOnce(
|
|
31668
31846
|
`${location.key}\0deferred`,
|
|
31669
|
-
() =>
|
|
31847
|
+
() => log17.info(RUNTIME_LAYOUT_DEFERRED_MESSAGE, {
|
|
31670
31848
|
configDir: location.configDir,
|
|
31671
31849
|
blockers
|
|
31672
31850
|
})
|
|
@@ -31715,7 +31893,7 @@ async function moveFiles(location, files, markerPath, layoutLock, input2) {
|
|
|
31715
31893
|
for (const path5 of listed) {
|
|
31716
31894
|
if (wanted.has(path5)) continue;
|
|
31717
31895
|
await layoutLock.assertOwned();
|
|
31718
|
-
await
|
|
31896
|
+
await unlink10(path5).catch((error) => {
|
|
31719
31897
|
if (error.code !== "ENOENT") throw error;
|
|
31720
31898
|
});
|
|
31721
31899
|
}
|
|
@@ -31824,13 +32002,13 @@ async function finishOldFiles(location, files, markerPath, marker, layoutLock, i
|
|
|
31824
32002
|
if (done) await removeOldVaultFolder(files, layoutLock, input2.steps);
|
|
31825
32003
|
}
|
|
31826
32004
|
}
|
|
31827
|
-
async function removeLeftoverManifest(location, layoutLock, steps,
|
|
32005
|
+
async function removeLeftoverManifest(location, layoutLock, steps, log17) {
|
|
31828
32006
|
try {
|
|
31829
32007
|
await removeManifestOwned(location.stateHomeDir, layoutLock, steps);
|
|
31830
32008
|
} catch (error) {
|
|
31831
32009
|
logOnce(
|
|
31832
32010
|
`${location.key}\0manifest`,
|
|
31833
|
-
() =>
|
|
32011
|
+
() => log17.warn(
|
|
31834
32012
|
`antigravity-auth could not remove ${RUNTIME_LAYOUT_MANIFEST_FILE} from its state folder; it tries again at the next start`,
|
|
31835
32013
|
{ stateDir: location.stateHomeDir, errorClass: errorClass(error) }
|
|
31836
32014
|
)
|
|
@@ -31838,7 +32016,7 @@ async function removeLeftoverManifest(location, layoutLock, steps, log16) {
|
|
|
31838
32016
|
}
|
|
31839
32017
|
}
|
|
31840
32018
|
async function removeManifestOwned(stateDir, layoutLock, steps) {
|
|
31841
|
-
const path5 =
|
|
32019
|
+
const path5 = join14(stateDir, RUNTIME_LAYOUT_MANIFEST_FILE);
|
|
31842
32020
|
if (!await exists2(path5)) return;
|
|
31843
32021
|
await beforeRemove(path5, layoutLock, steps);
|
|
31844
32022
|
await removeManifest(stateDir);
|
|
@@ -31850,16 +32028,16 @@ async function removeOldVaultFolder(files, layoutLock, steps) {
|
|
|
31850
32028
|
} catch {
|
|
31851
32029
|
}
|
|
31852
32030
|
}
|
|
31853
|
-
async function removeOldSignatureCache(location, path5, layoutLock, steps,
|
|
32031
|
+
async function removeOldSignatureCache(location, path5, layoutLock, steps, log17) {
|
|
31854
32032
|
try {
|
|
31855
32033
|
if (!await exists2(path5)) return;
|
|
31856
32034
|
await beforeRemove(path5, layoutLock, steps);
|
|
31857
|
-
await
|
|
32035
|
+
await unlink10(path5);
|
|
31858
32036
|
} catch (error) {
|
|
31859
32037
|
if (error?.code === "ENOENT") return;
|
|
31860
32038
|
logOnce(
|
|
31861
32039
|
`${location.key}\0signature-cache`,
|
|
31862
|
-
() =>
|
|
32040
|
+
() => log17.warn(
|
|
31863
32041
|
"antigravity-auth could not remove its old signature cache from OpenCode's config folder; it is no longer used and can be deleted",
|
|
31864
32042
|
{ path: path5, errorClass: errorClass(error) }
|
|
31865
32043
|
)
|
|
@@ -31870,7 +32048,7 @@ async function beforeRemove(path5, layoutLock, steps) {
|
|
|
31870
32048
|
await steps?.beforeRemove?.(path5);
|
|
31871
32049
|
await layoutLock.assertOwned();
|
|
31872
32050
|
}
|
|
31873
|
-
async function takeDataLocks(files,
|
|
32051
|
+
async function takeDataLocks(files, log17) {
|
|
31874
32052
|
const locks = [];
|
|
31875
32053
|
try {
|
|
31876
32054
|
if (await exists2(files.vault.old))
|
|
@@ -31878,9 +32056,9 @@ async function takeDataLocks(files, log16) {
|
|
|
31878
32056
|
locks.push(
|
|
31879
32057
|
await takeLock(
|
|
31880
32058
|
lock.name,
|
|
31881
|
-
|
|
32059
|
+
join14(files.vault.old, lock.file),
|
|
31882
32060
|
lock.waitMs,
|
|
31883
|
-
|
|
32061
|
+
log17
|
|
31884
32062
|
)
|
|
31885
32063
|
);
|
|
31886
32064
|
return locks;
|
|
@@ -31905,8 +32083,8 @@ function sha256(bytes) {
|
|
|
31905
32083
|
}
|
|
31906
32084
|
function vaultStateFile(files) {
|
|
31907
32085
|
return {
|
|
31908
|
-
old:
|
|
31909
|
-
next:
|
|
32086
|
+
old: join14(files.vault.old, VAULT_ENROLLMENT_STATE_FILE),
|
|
32087
|
+
next: join14(files.vault.next, VAULT_ENROLLMENT_STATE_FILE)
|
|
31910
32088
|
};
|
|
31911
32089
|
}
|
|
31912
32090
|
async function keepableVaultState(files, present5) {
|
|
@@ -31944,19 +32122,20 @@ async function isVaultShapedKeptState(files) {
|
|
|
31944
32122
|
return vaultShape && proposedName === OPENCODE_VAULT_ENROLLMENT_NAME;
|
|
31945
32123
|
}
|
|
31946
32124
|
async function removeMovedVaultStateLeftover(vaultDir, accountFile) {
|
|
32125
|
+
if (process.env.OPENCODE_ANTIGRAVITY_AUTH_VAULT_DIR) return;
|
|
31947
32126
|
const location = runtimeLayoutLocation();
|
|
31948
32127
|
const files = layoutFiles(location, accountFile);
|
|
31949
|
-
if (
|
|
32128
|
+
if (resolve15(vaultDir) !== resolve15(files.vault.next)) return;
|
|
31950
32129
|
const stateDir = location.stateHomeDir;
|
|
31951
32130
|
const marker = await readMarker(
|
|
31952
|
-
|
|
32131
|
+
join14(stateDir, RUNTIME_LAYOUT_MARKER_FILE),
|
|
31953
32132
|
stateDir,
|
|
31954
32133
|
files.vault.old
|
|
31955
32134
|
);
|
|
31956
32135
|
if (!marker?.oldDir || marker.oldDir !== location.key) return;
|
|
31957
32136
|
const leftover = vaultStateFile(files).old;
|
|
31958
32137
|
if (!await isVaultShapedKeptState(files)) return;
|
|
31959
|
-
await
|
|
32138
|
+
await unlink10(leftover).catch((error) => {
|
|
31960
32139
|
if (error.code !== "ENOENT") throw error;
|
|
31961
32140
|
});
|
|
31962
32141
|
await rmdir2(files.vault.old).catch(() => {
|
|
@@ -31978,13 +32157,13 @@ async function vaultFiles(dir) {
|
|
|
31978
32157
|
}
|
|
31979
32158
|
async function presentOldFiles(files) {
|
|
31980
32159
|
return (await vaultFiles(files.vault.old)).map((name) => ({
|
|
31981
|
-
old:
|
|
31982
|
-
next:
|
|
32160
|
+
old: join14(files.vault.old, name),
|
|
32161
|
+
next: join14(files.vault.next, name)
|
|
31983
32162
|
}));
|
|
31984
32163
|
}
|
|
31985
32164
|
async function destinationFiles(files) {
|
|
31986
32165
|
return (await vaultFiles(files.vault.next)).map(
|
|
31987
|
-
(name) =>
|
|
32166
|
+
(name) => join14(files.vault.next, name)
|
|
31988
32167
|
);
|
|
31989
32168
|
}
|
|
31990
32169
|
async function physicalAliases(location, files) {
|
|
@@ -31993,7 +32172,7 @@ async function physicalAliases(location, files) {
|
|
|
31993
32172
|
[files.vault.old, files.vault.next]
|
|
31994
32173
|
];
|
|
31995
32174
|
for (const name of VAULT_FILE_NAMES)
|
|
31996
|
-
pairs.push([
|
|
32175
|
+
pairs.push([join14(files.vault.old, name), join14(files.vault.next, name)]);
|
|
31997
32176
|
const aliased = [];
|
|
31998
32177
|
for (const [old, next] of pairs)
|
|
31999
32178
|
if (await samePhysical(old, next)) aliased.push(old);
|
|
@@ -32002,7 +32181,7 @@ async function physicalAliases(location, files) {
|
|
|
32002
32181
|
async function samePhysical(a, b) {
|
|
32003
32182
|
const id = async (path5) => {
|
|
32004
32183
|
try {
|
|
32005
|
-
const info = await
|
|
32184
|
+
const info = await stat10(path5, { bigint: true });
|
|
32006
32185
|
return info.ino === 0n ? void 0 : `${info.dev}:${info.ino}`;
|
|
32007
32186
|
} catch (error) {
|
|
32008
32187
|
const code2 = error.code;
|
|
@@ -32092,7 +32271,7 @@ async function unlinkIfIdentical(file, stateDir, guard) {
|
|
|
32092
32271
|
if (!same) throw credentialConflict(stateDir, file);
|
|
32093
32272
|
await guard();
|
|
32094
32273
|
try {
|
|
32095
|
-
await
|
|
32274
|
+
await unlink10(file.old);
|
|
32096
32275
|
return true;
|
|
32097
32276
|
} catch (error) {
|
|
32098
32277
|
if (error.code === "ENOENT") return true;
|
|
@@ -32105,11 +32284,11 @@ async function unlinkIfIdentical(file, stateDir, guard) {
|
|
|
32105
32284
|
async function refuseReappearedFiles(location, files) {
|
|
32106
32285
|
const keptState = vaultStateFile(files).old;
|
|
32107
32286
|
for (const name of await vaultFiles(files.vault.old)) {
|
|
32108
|
-
const old =
|
|
32287
|
+
const old = join14(files.vault.old, name);
|
|
32109
32288
|
if (old === keptState && await isVaultShapedKeptState(files)) continue;
|
|
32110
32289
|
throw credentialConflict(location.stateHomeDir, {
|
|
32111
32290
|
old,
|
|
32112
|
-
next:
|
|
32291
|
+
next: join14(files.vault.next, name)
|
|
32113
32292
|
});
|
|
32114
32293
|
}
|
|
32115
32294
|
}
|
|
@@ -32151,13 +32330,13 @@ async function assertOwnFolder(location, marker, files) {
|
|
|
32151
32330
|
const stateDir = location.stateHomeDir;
|
|
32152
32331
|
if (marker?.oldDir !== void 0 && marker.oldDir !== location.key)
|
|
32153
32332
|
throw foreignMarker(
|
|
32154
|
-
|
|
32333
|
+
join14(stateDir, RUNTIME_LAYOUT_MARKER_FILE),
|
|
32155
32334
|
location.key,
|
|
32156
32335
|
files.vault.old
|
|
32157
32336
|
);
|
|
32158
32337
|
let text2;
|
|
32159
32338
|
try {
|
|
32160
|
-
text2 = await readFile12(
|
|
32339
|
+
text2 = await readFile12(join14(stateDir, RUNTIME_CONFIG_DIR_NOTE_FILE), "utf8");
|
|
32161
32340
|
} catch (error) {
|
|
32162
32341
|
const code2 = error.code;
|
|
32163
32342
|
if (code2 === "ENOENT" || code2 === "ENOTDIR") return;
|
|
@@ -32171,7 +32350,7 @@ async function assertOwnFolder(location, marker, files) {
|
|
|
32171
32350
|
if (owner !== location.key) throw foreignFolder(stateDir, location.key);
|
|
32172
32351
|
}
|
|
32173
32352
|
async function writeOwnerNote(location) {
|
|
32174
|
-
const path5 =
|
|
32353
|
+
const path5 = join14(location.stateHomeDir, RUNTIME_CONFIG_DIR_NOTE_FILE);
|
|
32175
32354
|
if (await exists2(path5)) return;
|
|
32176
32355
|
await writePrivateText(
|
|
32177
32356
|
path5,
|
|
@@ -32182,7 +32361,7 @@ async function writeOwnerNote(location) {
|
|
|
32182
32361
|
async function readManifest(stateDir) {
|
|
32183
32362
|
let text2;
|
|
32184
32363
|
try {
|
|
32185
|
-
text2 = await readFile12(
|
|
32364
|
+
text2 = await readFile12(join14(stateDir, RUNTIME_LAYOUT_MANIFEST_FILE), "utf8");
|
|
32186
32365
|
} catch (error) {
|
|
32187
32366
|
if (error.code === "ENOENT") return /* @__PURE__ */ new Set();
|
|
32188
32367
|
throw error;
|
|
@@ -32199,13 +32378,13 @@ async function readManifest(stateDir) {
|
|
|
32199
32378
|
}
|
|
32200
32379
|
async function writeManifest(stateDir, paths) {
|
|
32201
32380
|
await writePrivateText(
|
|
32202
|
-
|
|
32381
|
+
join14(stateDir, RUNTIME_LAYOUT_MANIFEST_FILE),
|
|
32203
32382
|
`${JSON.stringify({ version: 1, files: paths }, null, 2)}
|
|
32204
32383
|
`
|
|
32205
32384
|
);
|
|
32206
32385
|
}
|
|
32207
32386
|
async function removeManifest(stateDir) {
|
|
32208
|
-
await
|
|
32387
|
+
await unlink10(join14(stateDir, RUNTIME_LAYOUT_MANIFEST_FILE)).catch(
|
|
32209
32388
|
(error) => {
|
|
32210
32389
|
if (error.code !== "ENOENT") throw error;
|
|
32211
32390
|
}
|
|
@@ -32229,7 +32408,7 @@ async function ensureOwnerOnlyDir(path5) {
|
|
|
32229
32408
|
await mkdir13(path5, { recursive: true, mode: 448 });
|
|
32230
32409
|
await chmod5(path5, 448);
|
|
32231
32410
|
}
|
|
32232
|
-
async function takeLock(name, path5, waitMs,
|
|
32411
|
+
async function takeLock(name, path5, waitMs, log17) {
|
|
32233
32412
|
const fs5 = await loadCommonAuthFs();
|
|
32234
32413
|
const started = performance.now();
|
|
32235
32414
|
let announced = false;
|
|
@@ -32254,7 +32433,7 @@ async function takeLock(name, path5, waitMs, log16) {
|
|
|
32254
32433
|
);
|
|
32255
32434
|
if (!announced && waited >= LOCK_WAIT_NOTICE_MS) {
|
|
32256
32435
|
announced = true;
|
|
32257
|
-
|
|
32436
|
+
log17.info(
|
|
32258
32437
|
`antigravity-auth is waiting up to ${Math.round(waitMs / 1e3)} s for the ${name} lock at ${path5}.${lockHolderText(name)}`,
|
|
32259
32438
|
{ lock: name, path: path5 }
|
|
32260
32439
|
);
|
|
@@ -32267,7 +32446,7 @@ function lockHolderText(name) {
|
|
|
32267
32446
|
}
|
|
32268
32447
|
async function exists2(path5) {
|
|
32269
32448
|
try {
|
|
32270
|
-
await
|
|
32449
|
+
await stat10(path5);
|
|
32271
32450
|
return true;
|
|
32272
32451
|
} catch (error) {
|
|
32273
32452
|
const code2 = error.code;
|
|
@@ -32275,7 +32454,7 @@ async function exists2(path5) {
|
|
|
32275
32454
|
throw error;
|
|
32276
32455
|
}
|
|
32277
32456
|
}
|
|
32278
|
-
var RUNTIME_LAYOUT_LOCK_NAME, RUNTIME_LAYOUT_MANIFEST_FILE, VAULT_ENROLLMENT_STATE_FILE, VAULT_ENROLLMENT_TOKEN_FILE, VAULT_FILE_NAMES, LOCK_TTL_MS, DATA_LOCKS, LAYOUT_LOCK_WAIT_MS, LOCK_RETRY_MS, LOCK_WAIT_NOTICE_MS, MARKER_READ_ATTEMPTS, MARKER_READ_RETRY_MS, SHARING_RETRY_DELAYS_MS, SHARING_RETRY_BUDGET_MS, RUNTIME_LAYOUT_DEFERRED_MESSAGE, ACCOUNT_STORE_DEFERRED_MESSAGE, ACCOUNT_STORE_LINKED_PATH_MESSAGE, RuntimeLayoutRefusal, stateKey2,
|
|
32457
|
+
var RUNTIME_LAYOUT_LOCK_NAME, RUNTIME_LAYOUT_MANIFEST_FILE, VAULT_ENROLLMENT_STATE_FILE, VAULT_ENROLLMENT_TOKEN_FILE, VAULT_FILE_NAMES, LOCK_TTL_MS, DATA_LOCKS, LAYOUT_LOCK_WAIT_MS, LOCK_RETRY_MS, LOCK_WAIT_NOTICE_MS, MARKER_READ_ATTEMPTS, MARKER_READ_RETRY_MS, SHARING_RETRY_DELAYS_MS, SHARING_RETRY_BUDGET_MS, RUNTIME_LAYOUT_DEFERRED_MESSAGE, ACCOUNT_STORE_DEFERRED_MESSAGE, ACCOUNT_STORE_LINKED_PATH_MESSAGE, RuntimeLayoutRefusal, stateKey2, globalState3, processState, LayoutMoveError, OldVaultFileKeptError, SHA256_HEX2;
|
|
32279
32458
|
var init_runtime_layout = __esm({
|
|
32280
32459
|
"src/runtime-layout.ts"() {
|
|
32281
32460
|
"use strict";
|
|
@@ -32332,8 +32511,8 @@ var init_runtime_layout = __esm({
|
|
|
32332
32511
|
errorClass;
|
|
32333
32512
|
};
|
|
32334
32513
|
stateKey2 = /* @__PURE__ */ Symbol.for("@cortexkit/antigravity-auth/runtime-layout-runs");
|
|
32335
|
-
|
|
32336
|
-
processState =
|
|
32514
|
+
globalState3 = globalThis;
|
|
32515
|
+
processState = globalState3[stateKey2] ?? {
|
|
32337
32516
|
runs: /* @__PURE__ */ new Map(),
|
|
32338
32517
|
storeRuns: /* @__PURE__ */ new Map(),
|
|
32339
32518
|
logged: /* @__PURE__ */ new Set()
|
|
@@ -32341,7 +32520,7 @@ var init_runtime_layout = __esm({
|
|
|
32341
32520
|
processState.runs ??= /* @__PURE__ */ new Map();
|
|
32342
32521
|
processState.storeRuns ??= /* @__PURE__ */ new Map();
|
|
32343
32522
|
processState.logged ??= /* @__PURE__ */ new Set();
|
|
32344
|
-
|
|
32523
|
+
globalState3[stateKey2] = processState;
|
|
32345
32524
|
LayoutMoveError = class extends Error {
|
|
32346
32525
|
constructor(code2, message) {
|
|
32347
32526
|
super(message);
|
|
@@ -32374,9 +32553,9 @@ import {
|
|
|
32374
32553
|
writeFileSync
|
|
32375
32554
|
} from "node:fs";
|
|
32376
32555
|
import { homedir as homedir4 } from "node:os";
|
|
32377
|
-
import { dirname as dirname16, join as
|
|
32556
|
+
import { dirname as dirname16, join as join15, resolve as resolve16 } from "node:path";
|
|
32378
32557
|
async function ensureGitignore(configDir) {
|
|
32379
|
-
const gitignorePath =
|
|
32558
|
+
const gitignorePath = join15(configDir, ".gitignore");
|
|
32380
32559
|
try {
|
|
32381
32560
|
let content;
|
|
32382
32561
|
let existingLines = [];
|
|
@@ -32402,7 +32581,7 @@ async function ensureGitignore(configDir) {
|
|
|
32402
32581
|
`,
|
|
32403
32582
|
"utf-8"
|
|
32404
32583
|
);
|
|
32405
|
-
|
|
32584
|
+
log6.info("Created .gitignore in config directory");
|
|
32406
32585
|
} else {
|
|
32407
32586
|
const suffix = content.endsWith("\n") ? "" : "\n";
|
|
32408
32587
|
await fs.appendFile(
|
|
@@ -32411,19 +32590,19 @@ async function ensureGitignore(configDir) {
|
|
|
32411
32590
|
`,
|
|
32412
32591
|
"utf-8"
|
|
32413
32592
|
);
|
|
32414
|
-
|
|
32593
|
+
log6.info("Updated .gitignore with missing entries", {
|
|
32415
32594
|
added: missingEntries
|
|
32416
32595
|
});
|
|
32417
32596
|
}
|
|
32418
32597
|
} catch (error) {
|
|
32419
|
-
|
|
32598
|
+
log6.warn("Failed to update .gitignore with account storage entries", {
|
|
32420
32599
|
error: String(error)
|
|
32421
32600
|
});
|
|
32422
32601
|
}
|
|
32423
32602
|
}
|
|
32424
32603
|
function getLegacyWindowsConfigDir() {
|
|
32425
|
-
return
|
|
32426
|
-
process.env.APPDATA ||
|
|
32604
|
+
return join15(
|
|
32605
|
+
process.env.APPDATA || join15(homedir4(), "AppData", "Roaming"),
|
|
32427
32606
|
"opencode"
|
|
32428
32607
|
);
|
|
32429
32608
|
}
|
|
@@ -32431,15 +32610,15 @@ function getConfigDir() {
|
|
|
32431
32610
|
if (process.env.OPENCODE_CONFIG_DIR) {
|
|
32432
32611
|
return process.env.OPENCODE_CONFIG_DIR;
|
|
32433
32612
|
}
|
|
32434
|
-
const xdgConfig2 = process.env.XDG_CONFIG_HOME ||
|
|
32435
|
-
return
|
|
32613
|
+
const xdgConfig2 = process.env.XDG_CONFIG_HOME || join15(homedir4(), ".config");
|
|
32614
|
+
return join15(xdgConfig2, "opencode");
|
|
32436
32615
|
}
|
|
32437
32616
|
function migrateLegacyWindowsConfig() {
|
|
32438
32617
|
if (process.platform !== "win32") {
|
|
32439
32618
|
return false;
|
|
32440
32619
|
}
|
|
32441
|
-
const newPath =
|
|
32442
|
-
const legacyPath =
|
|
32620
|
+
const newPath = join15(getConfigDir(), "antigravity-accounts.json");
|
|
32621
|
+
const legacyPath = join15(
|
|
32443
32622
|
getLegacyWindowsConfigDir(),
|
|
32444
32623
|
"antigravity-accounts.json"
|
|
32445
32624
|
);
|
|
@@ -32451,21 +32630,21 @@ function migrateLegacyWindowsConfig() {
|
|
|
32451
32630
|
mkdirSync(newConfigDir, { recursive: true });
|
|
32452
32631
|
try {
|
|
32453
32632
|
renameSync3(legacyPath, newPath);
|
|
32454
|
-
|
|
32633
|
+
log6.info("Migrated Windows config via rename", {
|
|
32455
32634
|
from: legacyPath,
|
|
32456
32635
|
to: newPath
|
|
32457
32636
|
});
|
|
32458
32637
|
} catch {
|
|
32459
32638
|
copyFileSync(legacyPath, newPath);
|
|
32460
32639
|
unlinkSync(legacyPath);
|
|
32461
|
-
|
|
32640
|
+
log6.info("Migrated Windows config via copy+delete", {
|
|
32462
32641
|
from: legacyPath,
|
|
32463
32642
|
to: newPath
|
|
32464
32643
|
});
|
|
32465
32644
|
}
|
|
32466
32645
|
return true;
|
|
32467
32646
|
} catch (error) {
|
|
32468
|
-
|
|
32647
|
+
log6.warn("Failed to migrate legacy Windows config, will use legacy path", {
|
|
32469
32648
|
legacyPath,
|
|
32470
32649
|
newPath,
|
|
32471
32650
|
error: String(error)
|
|
@@ -32474,8 +32653,8 @@ function migrateLegacyWindowsConfig() {
|
|
|
32474
32653
|
}
|
|
32475
32654
|
}
|
|
32476
32655
|
function resolveWindowsAccountAnchor(newPath, legacyPath) {
|
|
32477
|
-
const standard =
|
|
32478
|
-
const legacy =
|
|
32656
|
+
const standard = resolve16(newPath);
|
|
32657
|
+
const legacy = resolve16(legacyPath);
|
|
32479
32658
|
if (standard.toLowerCase() === legacy.toLowerCase()) return newPath;
|
|
32480
32659
|
const standardPointer = existsSync3(accountStorePointerPath(standard));
|
|
32481
32660
|
const legacyPointer = existsSync3(accountStorePointerPath(legacy));
|
|
@@ -32489,16 +32668,16 @@ function resolveWindowsAccountAnchor(newPath, legacyPath) {
|
|
|
32489
32668
|
return newPath;
|
|
32490
32669
|
}
|
|
32491
32670
|
function getStoragePathWithMigration() {
|
|
32492
|
-
const newPath =
|
|
32671
|
+
const newPath = join15(getConfigDir(), "antigravity-accounts.json");
|
|
32493
32672
|
if (process.platform === "win32") {
|
|
32494
32673
|
migrateLegacyWindowsConfig();
|
|
32495
|
-
const legacyPath =
|
|
32674
|
+
const legacyPath = join15(
|
|
32496
32675
|
getLegacyWindowsConfigDir(),
|
|
32497
32676
|
"antigravity-accounts.json"
|
|
32498
32677
|
);
|
|
32499
32678
|
const anchored = resolveWindowsAccountAnchor(newPath, legacyPath);
|
|
32500
|
-
if (
|
|
32501
|
-
|
|
32679
|
+
if (resolve16(anchored).toLowerCase() !== resolve16(newPath).toLowerCase() && !existsSync3(accountStorePointerPath(resolve16(anchored)))) {
|
|
32680
|
+
log6.info("Using legacy Windows config path (migration failed)", {
|
|
32502
32681
|
legacyPath,
|
|
32503
32682
|
newPath
|
|
32504
32683
|
});
|
|
@@ -32511,20 +32690,20 @@ function stateHomeStoragePath() {
|
|
|
32511
32690
|
return stateHomeAccountFile(runtimeLayoutLocation());
|
|
32512
32691
|
}
|
|
32513
32692
|
function accountFileForVault(configDir = getConfigDir()) {
|
|
32514
|
-
const configured =
|
|
32693
|
+
const configured = join15(configDir, "antigravity-accounts.json");
|
|
32515
32694
|
if (process.platform !== "win32") return configured;
|
|
32516
32695
|
const legacyDir = getLegacyWindowsConfigDir();
|
|
32517
|
-
if (
|
|
32696
|
+
if (resolve16(configDir).toLowerCase() === resolve16(legacyDir).toLowerCase())
|
|
32518
32697
|
return configured;
|
|
32519
|
-
const configuredVault =
|
|
32520
|
-
const legacyVault =
|
|
32698
|
+
const configuredVault = join15(configDir, "antigravity-auth-vault");
|
|
32699
|
+
const legacyVault = join15(legacyDir, "antigravity-auth-vault");
|
|
32521
32700
|
const configuredPresent = existsSync3(configuredVault);
|
|
32522
32701
|
const legacyPresent = existsSync3(legacyVault);
|
|
32523
32702
|
if (configuredPresent && legacyPresent)
|
|
32524
32703
|
throw new Error(
|
|
32525
32704
|
`Two vault folders exist: ${configuredVault} and ${legacyVault}. Keep one vault enrollment before restarting OpenCode.`
|
|
32526
32705
|
);
|
|
32527
|
-
return legacyPresent ?
|
|
32706
|
+
return legacyPresent ? join15(legacyDir, "antigravity-accounts.json") : configured;
|
|
32528
32707
|
}
|
|
32529
32708
|
async function prepareLocalAccountStore() {
|
|
32530
32709
|
if (!decidedRuntimeLayout(runtimeLayoutLocation())) return;
|
|
@@ -32539,13 +32718,13 @@ function getStoragePath() {
|
|
|
32539
32718
|
if (anchor === "config") return getStoragePathWithMigration();
|
|
32540
32719
|
const location = runtimeLayoutLocation();
|
|
32541
32720
|
if (decidedRuntimeLayout(location))
|
|
32542
|
-
return
|
|
32721
|
+
return join15(location.configDir, "antigravity-accounts.json");
|
|
32543
32722
|
const configPath = getStoragePathWithMigration();
|
|
32544
32723
|
return readForwardedAccountStore(configPath)?.legacyPath ?? configPath;
|
|
32545
32724
|
}
|
|
32546
32725
|
async function assertLegacyPoolInUse(legacyPath) {
|
|
32547
32726
|
try {
|
|
32548
|
-
await assertLegacyAccountStorageWritable(
|
|
32727
|
+
await assertLegacyAccountStorageWritable(resolve16(legacyPath));
|
|
32549
32728
|
} catch (error) {
|
|
32550
32729
|
throw new LegacyAccountPoolRetiredError(legacyPath, { cause: error });
|
|
32551
32730
|
}
|
|
@@ -32563,7 +32742,7 @@ function refusalMessage2(admission) {
|
|
|
32563
32742
|
async function bindingOf(options) {
|
|
32564
32743
|
if (options.legacyPath === void 0) await prepareLocalAccountStore();
|
|
32565
32744
|
const now = options.now ?? (() => Date.now());
|
|
32566
|
-
const legacyPath =
|
|
32745
|
+
const legacyPath = resolve16(options.legacyPath ?? getStoragePath());
|
|
32567
32746
|
return {
|
|
32568
32747
|
legacyPath,
|
|
32569
32748
|
now,
|
|
@@ -32632,7 +32811,7 @@ async function openAccountStore(options) {
|
|
|
32632
32811
|
async function initializeFreshAccountStoreFor(modules, options = {}) {
|
|
32633
32812
|
if (options.legacyPath === void 0) await prepareLocalAccountStore();
|
|
32634
32813
|
return initializeFreshAccountStore(modules, {
|
|
32635
|
-
legacyPath:
|
|
32814
|
+
legacyPath: resolve16(options.legacyPath ?? getStoragePath()),
|
|
32636
32815
|
now: options.now ?? (() => Date.now())
|
|
32637
32816
|
});
|
|
32638
32817
|
}
|
|
@@ -32666,18 +32845,18 @@ async function clearAccounts() {
|
|
|
32666
32845
|
} catch (error) {
|
|
32667
32846
|
const code2 = error.code;
|
|
32668
32847
|
if (code2 !== "ENOENT") {
|
|
32669
|
-
|
|
32848
|
+
log6.error("Failed to clear account storage", { error: String(error) });
|
|
32670
32849
|
}
|
|
32671
32850
|
}
|
|
32672
32851
|
}
|
|
32673
|
-
var
|
|
32852
|
+
var log6, mutateAccountStorage2, GITIGNORE_ENTRIES, LegacyAccountPoolRetiredError, MIGRATE_COMMAND, UNMIGRATED_ACCOUNT_MESSAGE, ROLLBACK_COMMAND;
|
|
32674
32853
|
var init_storage = __esm({
|
|
32675
32854
|
"src/plugin/storage.ts"() {
|
|
32676
32855
|
"use strict";
|
|
32677
32856
|
init_dist();
|
|
32678
32857
|
init_runtime_paths();
|
|
32679
32858
|
init_logger4();
|
|
32680
|
-
|
|
32859
|
+
log6 = createLogger4("storage");
|
|
32681
32860
|
mutateAccountStorage2 = async (path5, mutate) => {
|
|
32682
32861
|
await assertLegacyPoolInUse(path5);
|
|
32683
32862
|
return mutateAccountStorage(path5, mutate);
|
|
@@ -32710,12 +32889,12 @@ var init_storage = __esm({
|
|
|
32710
32889
|
import { createHash as createHash12 } from "node:crypto";
|
|
32711
32890
|
import { existsSync as existsSync4, promises as fs2, readFileSync as readFileSync2, realpathSync as realpathSync2 } from "node:fs";
|
|
32712
32891
|
import { homedir as homedir5 } from "node:os";
|
|
32713
|
-
import { dirname as dirname17, join as
|
|
32892
|
+
import { dirname as dirname17, join as join16, resolve as resolve17 } from "node:path";
|
|
32714
32893
|
function configDirIdentity(path5) {
|
|
32715
32894
|
try {
|
|
32716
32895
|
return realpathSync2.native(path5);
|
|
32717
32896
|
} catch {
|
|
32718
|
-
return
|
|
32897
|
+
return resolve17(path5);
|
|
32719
32898
|
}
|
|
32720
32899
|
}
|
|
32721
32900
|
function decisionKey(location) {
|
|
@@ -32723,18 +32902,18 @@ function decisionKey(location) {
|
|
|
32723
32902
|
}
|
|
32724
32903
|
function runtimeLayoutLocation(configDir = getConfigDir()) {
|
|
32725
32904
|
const stateHome = defaultStateHome();
|
|
32726
|
-
const homeConfig =
|
|
32905
|
+
const homeConfig = join16(homedir5(), ".config", "opencode");
|
|
32727
32906
|
const cacheKey = `${configDir}\0${homeConfig}\0${stateHome}`;
|
|
32728
32907
|
const cached = shared2.locations.get(cacheKey);
|
|
32729
32908
|
if (cached && shared2.decisions.has(decisionKey(cached))) return cached;
|
|
32730
32909
|
const key = configDirIdentity(configDir);
|
|
32731
32910
|
if (cached && cached.key === key) return cached;
|
|
32732
32911
|
const isDefaultConfigDir = key === configDirIdentity(homeConfig);
|
|
32733
|
-
const root =
|
|
32912
|
+
const root = join16(stateHome, "cortexkit", "antigravity-auth");
|
|
32734
32913
|
const location = {
|
|
32735
32914
|
key,
|
|
32736
32915
|
configDir,
|
|
32737
|
-
stateHomeDir: isDefaultConfigDir ?
|
|
32916
|
+
stateHomeDir: isDefaultConfigDir ? join16(root, "opencode") : join16(
|
|
32738
32917
|
root,
|
|
32739
32918
|
`opencode-${createHash12("sha256").update(key).digest("hex").slice(0, 16)}`
|
|
32740
32919
|
),
|
|
@@ -32756,49 +32935,49 @@ function decidedAccountStoreAnchor(location) {
|
|
|
32756
32935
|
return shared2.storeAnchors.get(`${location.stateHomeDir}\0${location.key}`);
|
|
32757
32936
|
}
|
|
32758
32937
|
function currentRuntimeLayout(location = runtimeLayoutLocation()) {
|
|
32759
|
-
return decidedRuntimeLayout(location) ?? (existsSync4(
|
|
32938
|
+
return decidedRuntimeLayout(location) ?? (existsSync4(join16(location.stateHomeDir, RUNTIME_LAYOUT_MARKER_FILE)) ? "state-home" : "legacy");
|
|
32760
32939
|
}
|
|
32761
32940
|
function legacyWindowsConfigDir() {
|
|
32762
|
-
return
|
|
32763
|
-
process.env.APPDATA ||
|
|
32941
|
+
return join16(
|
|
32942
|
+
process.env.APPDATA || join16(homedir5(), "AppData", "Roaming"),
|
|
32764
32943
|
"opencode"
|
|
32765
32944
|
);
|
|
32766
32945
|
}
|
|
32767
32946
|
function pluginStateDir() {
|
|
32768
|
-
return
|
|
32947
|
+
return join16(defaultStateHome(), "cortexkit", "antigravity-auth");
|
|
32769
32948
|
}
|
|
32770
32949
|
function stateHomeSignatureCacheFile() {
|
|
32771
|
-
return
|
|
32950
|
+
return join16(pluginStateDir(), SIGNATURE_CACHE_FILE_NAME);
|
|
32772
32951
|
}
|
|
32773
32952
|
function legacySignatureCacheFile() {
|
|
32774
|
-
const configHome = process.platform === "win32" ? legacyWindowsConfigDir() :
|
|
32775
|
-
process.env.XDG_CONFIG_HOME ||
|
|
32953
|
+
const configHome = process.platform === "win32" ? legacyWindowsConfigDir() : join16(
|
|
32954
|
+
process.env.XDG_CONFIG_HOME || join16(homedir5(), ".config"),
|
|
32776
32955
|
"opencode"
|
|
32777
32956
|
);
|
|
32778
|
-
return
|
|
32957
|
+
return join16(configHome, SIGNATURE_CACHE_FILE_NAME);
|
|
32779
32958
|
}
|
|
32780
32959
|
function stateHomeLogsDir() {
|
|
32781
|
-
return
|
|
32960
|
+
return join16(pluginStateDir(), "logs");
|
|
32782
32961
|
}
|
|
32783
32962
|
function legacyAccountFile(configDir = getConfigDir()) {
|
|
32784
|
-
const standard =
|
|
32963
|
+
const standard = join16(configDir, ACCOUNT_FILE_NAME);
|
|
32785
32964
|
if (process.platform !== "win32") return standard;
|
|
32786
32965
|
return resolveWindowsAccountAnchor(
|
|
32787
32966
|
standard,
|
|
32788
|
-
|
|
32967
|
+
join16(legacyWindowsConfigDir(), ACCOUNT_FILE_NAME)
|
|
32789
32968
|
);
|
|
32790
32969
|
}
|
|
32791
32970
|
function legacyVaultDir(accountFile) {
|
|
32792
|
-
return
|
|
32971
|
+
return join16(dirname17(accountFile), VAULT_DIR_NAME);
|
|
32793
32972
|
}
|
|
32794
32973
|
function stateHomeVaultDir(location) {
|
|
32795
|
-
return
|
|
32974
|
+
return join16(location.stateHomeDir, VAULT_DIR_NAME);
|
|
32796
32975
|
}
|
|
32797
32976
|
function accountStorePointerPath2(accountFile) {
|
|
32798
32977
|
return `${accountFile}${ACCOUNT_STORE_POINTER_SUFFIX}`;
|
|
32799
32978
|
}
|
|
32800
32979
|
function stateHomeAccountFile(location) {
|
|
32801
|
-
return
|
|
32980
|
+
return join16(realPathOrSelf(location.stateHomeDir), ACCOUNT_FILE_NAME);
|
|
32802
32981
|
}
|
|
32803
32982
|
function realPathOrSelf(path5) {
|
|
32804
32983
|
try {
|
|
@@ -33042,7 +33221,7 @@ import {
|
|
|
33042
33221
|
statSync as statSync4,
|
|
33043
33222
|
unlinkSync as unlinkSync2
|
|
33044
33223
|
} from "node:fs";
|
|
33045
|
-
import { join as
|
|
33224
|
+
import { join as join17 } from "node:path";
|
|
33046
33225
|
import { env } from "node:process";
|
|
33047
33226
|
function getLogsDir(customLogDir) {
|
|
33048
33227
|
const logsDir = customLogDir || stateHomeLogsDir();
|
|
@@ -33061,9 +33240,9 @@ function createLogFilePath(customLogDir) {
|
|
|
33061
33240
|
const logsDir = getLogsDir(requestedLogDir(customLogDir));
|
|
33062
33241
|
cleanupOldLogs(logsDir, 25);
|
|
33063
33242
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
33064
|
-
let candidate =
|
|
33243
|
+
let candidate = join17(logsDir, `antigravity-debug-${timestamp}.log`);
|
|
33065
33244
|
for (let suffix = 2; liveLogFilePaths.has(candidate); suffix++) {
|
|
33066
|
-
candidate =
|
|
33245
|
+
candidate = join17(logsDir, `antigravity-debug-${timestamp}-${suffix}.log`);
|
|
33067
33246
|
}
|
|
33068
33247
|
return candidate;
|
|
33069
33248
|
}
|
|
@@ -33071,7 +33250,7 @@ function cleanupOldLogs(logsDir, maxFiles) {
|
|
|
33071
33250
|
try {
|
|
33072
33251
|
const files = readdirSync(logsDir).filter(
|
|
33073
33252
|
(file) => file.startsWith("antigravity-debug-") && file.endsWith(".log")
|
|
33074
|
-
).map((file) =>
|
|
33253
|
+
).map((file) => join17(logsDir, file));
|
|
33075
33254
|
if (files.length <= maxFiles) {
|
|
33076
33255
|
return;
|
|
33077
33256
|
}
|
|
@@ -33168,13 +33347,13 @@ function closeDebugStream(state) {
|
|
|
33168
33347
|
state.logWriter = () => {
|
|
33169
33348
|
};
|
|
33170
33349
|
if (state.logFilePath) liveLogFilePaths.delete(state.logFilePath);
|
|
33171
|
-
return new Promise((
|
|
33172
|
-
current.once("close", () =>
|
|
33173
|
-
current.once("error", () =>
|
|
33350
|
+
return new Promise((resolve27) => {
|
|
33351
|
+
current.once("close", () => resolve27());
|
|
33352
|
+
current.once("error", () => resolve27());
|
|
33174
33353
|
try {
|
|
33175
33354
|
current.end();
|
|
33176
33355
|
} catch {
|
|
33177
|
-
|
|
33356
|
+
resolve27();
|
|
33178
33357
|
}
|
|
33179
33358
|
});
|
|
33180
33359
|
}
|
|
@@ -33439,13 +33618,13 @@ function closeDebugLog() {
|
|
|
33439
33618
|
if (!state || !current) return Promise.resolve();
|
|
33440
33619
|
state.logStream = null;
|
|
33441
33620
|
if (state.logFilePath) liveLogFilePaths.delete(state.logFilePath);
|
|
33442
|
-
return new Promise((
|
|
33443
|
-
current.once("close", () =>
|
|
33444
|
-
current.once("error", () =>
|
|
33621
|
+
return new Promise((resolve27) => {
|
|
33622
|
+
current.once("close", () => resolve27());
|
|
33623
|
+
current.once("error", () => resolve27());
|
|
33445
33624
|
try {
|
|
33446
33625
|
current.end();
|
|
33447
33626
|
} catch {
|
|
33448
|
-
|
|
33627
|
+
resolve27();
|
|
33449
33628
|
}
|
|
33450
33629
|
});
|
|
33451
33630
|
}
|
|
@@ -33621,15 +33800,15 @@ function initLogger3(client) {
|
|
|
33621
33800
|
}
|
|
33622
33801
|
function createLogger4(module) {
|
|
33623
33802
|
let channel3;
|
|
33624
|
-
const
|
|
33803
|
+
const log17 = (level, message, extra) => {
|
|
33625
33804
|
channel3 ??= getLegacyLogger().createLogger(module);
|
|
33626
33805
|
channel3[level](message, extra);
|
|
33627
33806
|
};
|
|
33628
33807
|
return {
|
|
33629
|
-
debug: (message, extra) =>
|
|
33630
|
-
info: (message, extra) =>
|
|
33631
|
-
warn: (message, extra) =>
|
|
33632
|
-
error: (message, extra) =>
|
|
33808
|
+
debug: (message, extra) => log17("debug", message, extra),
|
|
33809
|
+
info: (message, extra) => log17("info", message, extra),
|
|
33810
|
+
warn: (message, extra) => log17("warn", message, extra),
|
|
33811
|
+
error: (message, extra) => log17("error", message, extra)
|
|
33633
33812
|
};
|
|
33634
33813
|
}
|
|
33635
33814
|
var ENV_CONSOLE_LOG2, LOG_LEVEL_FROM_OPERATOR, legacyClient, legacyLogger;
|
|
@@ -33656,13 +33835,13 @@ var init_logger4 = __esm({
|
|
|
33656
33835
|
// src/plugin/index.ts
|
|
33657
33836
|
init_dist();
|
|
33658
33837
|
import { createHash as createHash23, randomUUID as randomUUID21 } from "node:crypto";
|
|
33659
|
-
import { join as
|
|
33838
|
+
import { join as join39, resolve as resolve26 } from "node:path";
|
|
33660
33839
|
|
|
33661
33840
|
// src/cli.ts
|
|
33662
33841
|
init_dist();
|
|
33663
33842
|
import { execFile } from "node:child_process";
|
|
33664
33843
|
import { realpathSync as realpathSync4 } from "node:fs";
|
|
33665
|
-
import { resolve as
|
|
33844
|
+
import { resolve as resolve21 } from "node:path";
|
|
33666
33845
|
import { createInterface } from "node:readline/promises";
|
|
33667
33846
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
33668
33847
|
import { promisify } from "node:util";
|
|
@@ -33904,7 +34083,7 @@ init_atomic_write();
|
|
|
33904
34083
|
init_file_lock();
|
|
33905
34084
|
import { chmodSync as chmodSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync3 } from "node:fs";
|
|
33906
34085
|
import { homedir as homedir6 } from "node:os";
|
|
33907
|
-
import { dirname as dirname18, join as
|
|
34086
|
+
import { dirname as dirname18, join as join18 } from "node:path";
|
|
33908
34087
|
|
|
33909
34088
|
// ../../node_modules/.bun/xdg-basedir@5.1.0/node_modules/xdg-basedir/index.js
|
|
33910
34089
|
import os from "os";
|
|
@@ -33963,8 +34142,8 @@ async function emitMergeStep(step) {
|
|
|
33963
34142
|
function getSidebarStateFile() {
|
|
33964
34143
|
const override = process.env[SIDEBAR_STATE_ENV];
|
|
33965
34144
|
if (override && override.trim().length > 0) return override;
|
|
33966
|
-
const base = xdgState ??
|
|
33967
|
-
return
|
|
34145
|
+
const base = xdgState ?? join18(homedir6(), ".local", "state");
|
|
34146
|
+
return join18(base, SIDEBAR_STATE_DIR, SIDEBAR_STATE_FILENAME);
|
|
33968
34147
|
}
|
|
33969
34148
|
function readSidebarState(path5 = getSidebarStateFile()) {
|
|
33970
34149
|
let raw;
|
|
@@ -34313,7 +34492,7 @@ function drainSidebarWrites() {
|
|
|
34313
34492
|
return sidebarWriteChain;
|
|
34314
34493
|
}
|
|
34315
34494
|
async function sleep3(ms) {
|
|
34316
|
-
await new Promise((
|
|
34495
|
+
await new Promise((resolve27) => setTimeout(resolve27, ms));
|
|
34317
34496
|
}
|
|
34318
34497
|
async function acquireSidebarLockWithRetry(stateFile) {
|
|
34319
34498
|
const start = Date.now();
|
|
@@ -34465,7 +34644,7 @@ init_storage();
|
|
|
34465
34644
|
// src/plugin/token.ts
|
|
34466
34645
|
init_dist();
|
|
34467
34646
|
init_logger4();
|
|
34468
|
-
var
|
|
34647
|
+
var log7 = createLogger4("token");
|
|
34469
34648
|
function parseOAuthErrorPayload(text2) {
|
|
34470
34649
|
if (!text2) {
|
|
34471
34650
|
return {};
|
|
@@ -34548,13 +34727,13 @@ async function exchangeRefreshToken(refreshToken, now) {
|
|
|
34548
34727
|
const details = [code2, description ?? errorText3].filter(Boolean).join(": ");
|
|
34549
34728
|
const baseMessage = `Antigravity token refresh failed (${response.status} ${response.statusText})`;
|
|
34550
34729
|
const message = details ? `${baseMessage} - ${details}` : baseMessage;
|
|
34551
|
-
|
|
34730
|
+
log7.warn("Token refresh failed", {
|
|
34552
34731
|
status: response.status,
|
|
34553
34732
|
code: code2,
|
|
34554
34733
|
details
|
|
34555
34734
|
});
|
|
34556
34735
|
if (code2 === "invalid_grant") {
|
|
34557
|
-
|
|
34736
|
+
log7.warn(
|
|
34558
34737
|
"Google revoked the stored refresh token - reauthentication required"
|
|
34559
34738
|
);
|
|
34560
34739
|
invalidateProjectContextCache(refreshToken);
|
|
@@ -34610,7 +34789,7 @@ async function refreshAccessToken(auth, _client, _providerId) {
|
|
|
34610
34789
|
if (error instanceof AntigravityTokenRefreshError) {
|
|
34611
34790
|
throw error;
|
|
34612
34791
|
}
|
|
34613
|
-
|
|
34792
|
+
log7.error("Unexpected token refresh error", { error: String(error) });
|
|
34614
34793
|
return void 0;
|
|
34615
34794
|
}
|
|
34616
34795
|
}
|
|
@@ -34737,7 +34916,7 @@ init_dist();
|
|
|
34737
34916
|
// src/plugin/quota.ts
|
|
34738
34917
|
init_logger4();
|
|
34739
34918
|
init_dist();
|
|
34740
|
-
var
|
|
34919
|
+
var log8 = createLogger4("quota");
|
|
34741
34920
|
function createOpenCodeQuotaManager(client, providerId = ANTIGRAVITY_PROVIDER_ID, options = {}) {
|
|
34742
34921
|
const fetchPoolFileQuota = makeFetchAccountQuota(
|
|
34743
34922
|
client,
|
|
@@ -34928,7 +35107,7 @@ async function pushSidebarQuotaSnapshot(getAccounts, backoffUntil = 0, getActive
|
|
|
34928
35107
|
);
|
|
34929
35108
|
} catch (error) {
|
|
34930
35109
|
;
|
|
34931
|
-
(options.logger ??
|
|
35110
|
+
(options.logger ?? log8).debug("sidebar-quota-write-failed", {
|
|
34932
35111
|
error: String(error)
|
|
34933
35112
|
});
|
|
34934
35113
|
}
|
|
@@ -35165,14 +35344,14 @@ var LocalQuotaGrantStaleError = class extends Error {
|
|
|
35165
35344
|
name = "LocalQuotaGrantStaleError";
|
|
35166
35345
|
};
|
|
35167
35346
|
function untilQuotaAborted(pending, signal) {
|
|
35168
|
-
return new Promise((
|
|
35347
|
+
return new Promise((resolve27, reject) => {
|
|
35169
35348
|
const abort = () => reject(signal.reason);
|
|
35170
35349
|
if (signal.aborted) abort();
|
|
35171
35350
|
else signal.addEventListener("abort", abort, { once: true });
|
|
35172
35351
|
void pending.then(
|
|
35173
35352
|
(value) => {
|
|
35174
35353
|
signal.removeEventListener("abort", abort);
|
|
35175
|
-
|
|
35354
|
+
resolve27(value);
|
|
35176
35355
|
},
|
|
35177
35356
|
(error) => {
|
|
35178
35357
|
signal.removeEventListener("abort", abort);
|
|
@@ -35294,7 +35473,7 @@ function makeFetchAccountQuota(client, providerId, fetchVia) {
|
|
|
35294
35473
|
let rotatedRefresh;
|
|
35295
35474
|
if (purpose === "advisory") {
|
|
35296
35475
|
if (accessTokenExpired(auth)) {
|
|
35297
|
-
|
|
35476
|
+
log8.debug("advisory-quota-skipped-refresh-needed");
|
|
35298
35477
|
return {
|
|
35299
35478
|
index,
|
|
35300
35479
|
email: account.email,
|
|
@@ -35306,7 +35485,7 @@ function makeFetchAccountQuota(client, providerId, fetchVia) {
|
|
|
35306
35485
|
const managedProjectId = parts.managedProjectId ?? account.managedProjectId;
|
|
35307
35486
|
const projectId = managedProjectId ?? parts.projectId ?? account.projectId;
|
|
35308
35487
|
if (!projectId) {
|
|
35309
|
-
|
|
35488
|
+
log8.debug("advisory-quota-skipped-project-needed");
|
|
35310
35489
|
return {
|
|
35311
35490
|
index,
|
|
35312
35491
|
email: account.email,
|
|
@@ -35328,7 +35507,7 @@ function makeFetchAccountQuota(client, providerId, fetchVia) {
|
|
|
35328
35507
|
{ timeoutMs: extra.timeoutMs }
|
|
35329
35508
|
);
|
|
35330
35509
|
},
|
|
35331
|
-
logger:
|
|
35510
|
+
logger: log8
|
|
35332
35511
|
}),
|
|
35333
35512
|
signal
|
|
35334
35513
|
);
|
|
@@ -35385,7 +35564,7 @@ function makeFetchAccountQuota(client, providerId, fetchVia) {
|
|
|
35385
35564
|
managedProjectId,
|
|
35386
35565
|
projectId: projectContext.effectiveProjectId,
|
|
35387
35566
|
fetchVia,
|
|
35388
|
-
logger:
|
|
35567
|
+
logger: log8
|
|
35389
35568
|
});
|
|
35390
35569
|
quotaResult = payloads.quota;
|
|
35391
35570
|
if (quotaResult.error) throw new Error(quotaResult.error);
|
|
@@ -35793,12 +35972,12 @@ async function startOAuthListener({
|
|
|
35793
35972
|
let resolveCallback;
|
|
35794
35973
|
let rejectCallback;
|
|
35795
35974
|
let timeoutHandle;
|
|
35796
|
-
const callbackPromise = new Promise((
|
|
35975
|
+
const callbackPromise = new Promise((resolve27, reject) => {
|
|
35797
35976
|
resolveCallback = (url) => {
|
|
35798
35977
|
if (settled) return;
|
|
35799
35978
|
settled = true;
|
|
35800
35979
|
if (timeoutHandle) clearTimeout(timeoutHandle);
|
|
35801
|
-
|
|
35980
|
+
resolve27(url);
|
|
35802
35981
|
};
|
|
35803
35982
|
rejectCallback = (error) => {
|
|
35804
35983
|
if (settled) return;
|
|
@@ -35957,7 +36136,7 @@ async function startOAuthListener({
|
|
|
35957
36136
|
});
|
|
35958
36137
|
});
|
|
35959
36138
|
const bindAddress = getBindAddress();
|
|
35960
|
-
await new Promise((
|
|
36139
|
+
await new Promise((resolve27, reject) => {
|
|
35961
36140
|
const handleError = (error) => {
|
|
35962
36141
|
server.off("error", handleError);
|
|
35963
36142
|
if (error.code === "EADDRINUSE") {
|
|
@@ -35973,7 +36152,7 @@ async function startOAuthListener({
|
|
|
35973
36152
|
server.once("error", handleError);
|
|
35974
36153
|
server.listen(port, bindAddress, () => {
|
|
35975
36154
|
server.off("error", handleError);
|
|
35976
|
-
|
|
36155
|
+
resolve27();
|
|
35977
36156
|
});
|
|
35978
36157
|
});
|
|
35979
36158
|
server.on("error", (error) => {
|
|
@@ -35981,7 +36160,7 @@ async function startOAuthListener({
|
|
|
35981
36160
|
});
|
|
35982
36161
|
return {
|
|
35983
36162
|
waitForCallback: () => callbackPromise,
|
|
35984
|
-
close: () => new Promise((
|
|
36163
|
+
close: () => new Promise((resolve27, reject) => {
|
|
35985
36164
|
server.close((error) => {
|
|
35986
36165
|
if (error && error.code !== "ERR_SERVER_NOT_RUNNING") {
|
|
35987
36166
|
reject(error);
|
|
@@ -35990,7 +36169,7 @@ async function startOAuthListener({
|
|
|
35990
36169
|
if (!settled) {
|
|
35991
36170
|
rejectCallback(new Error("OAuth listener closed before callback"));
|
|
35992
36171
|
}
|
|
35993
|
-
|
|
36172
|
+
resolve27();
|
|
35994
36173
|
});
|
|
35995
36174
|
})
|
|
35996
36175
|
};
|
|
@@ -36009,7 +36188,7 @@ init_runtime_paths();
|
|
|
36009
36188
|
// src/setup.ts
|
|
36010
36189
|
init_dist();
|
|
36011
36190
|
import { lstat as lstat9, readFile as readFile16 } from "node:fs/promises";
|
|
36012
|
-
import { join as
|
|
36191
|
+
import { join as join24, resolve as resolve20 } from "node:path";
|
|
36013
36192
|
|
|
36014
36193
|
// src/auth-method-labels.ts
|
|
36015
36194
|
var OPENCODE2_POOL_AUTH_LABEL = "Google (antigravity-auth pool, browser)";
|
|
@@ -36181,7 +36360,7 @@ async function select2(terminal, items, options) {
|
|
|
36181
36360
|
writeLine("");
|
|
36182
36361
|
renderedLines = lines;
|
|
36183
36362
|
};
|
|
36184
|
-
return new Promise((
|
|
36363
|
+
return new Promise((resolve27) => {
|
|
36185
36364
|
const wasRaw = stdin.isRaw ?? false;
|
|
36186
36365
|
const cleanup2 = () => {
|
|
36187
36366
|
if (cleaned)
|
|
@@ -36201,7 +36380,7 @@ async function select2(terminal, items, options) {
|
|
|
36201
36380
|
};
|
|
36202
36381
|
const finish = (value) => {
|
|
36203
36382
|
cleanup2();
|
|
36204
|
-
|
|
36383
|
+
resolve27(value);
|
|
36205
36384
|
};
|
|
36206
36385
|
const onSignal = () => finish(null);
|
|
36207
36386
|
const onKey = (data) => {
|
|
@@ -36241,7 +36420,7 @@ async function select2(terminal, items, options) {
|
|
|
36241
36420
|
stdin.setRawMode(true);
|
|
36242
36421
|
} catch {
|
|
36243
36422
|
cleanup2();
|
|
36244
|
-
|
|
36423
|
+
resolve27(null);
|
|
36245
36424
|
return;
|
|
36246
36425
|
}
|
|
36247
36426
|
stdin.resume();
|
|
@@ -36254,13 +36433,13 @@ async function select2(terminal, items, options) {
|
|
|
36254
36433
|
// src/common-auth-embedded/claustrum/enrollment.js
|
|
36255
36434
|
import { createHash as createHash13, randomBytes as randomBytes5, randomUUID as randomUUID17 } from "node:crypto";
|
|
36256
36435
|
import { constants as fsConstants2 } from "node:fs";
|
|
36257
|
-
import { chmod as chmod6, mkdir as mkdir15, open as open10, readFile as readFile14, realpath as realpath4, rename as rename12, stat as
|
|
36258
|
-
import { basename as basename5, dirname as dirname20, extname as extname2, isAbsolute as
|
|
36436
|
+
import { chmod as chmod6, mkdir as mkdir15, open as open10, readFile as readFile14, realpath as realpath4, rename as rename12, stat as stat12, unlink as unlink11 } from "node:fs/promises";
|
|
36437
|
+
import { basename as basename5, dirname as dirname20, extname as extname2, isAbsolute as isAbsolute4, join as join20, resolve as resolve19 } from "node:path";
|
|
36259
36438
|
import { ClaustrumCredentialError as ClaustrumCredentialError5, ClaustrumClient as ClaustrumWireClient2, writeEnrollmentTokenFile as writeEnrollmentTokenFile2 } from "@cortexkit/claustrum-client";
|
|
36260
36439
|
|
|
36261
36440
|
// src/common-auth-embedded/fs/file-read-cache.js
|
|
36262
36441
|
import { lstat as lstat7 } from "node:fs/promises";
|
|
36263
|
-
import { resolve as
|
|
36442
|
+
import { resolve as resolve18 } from "node:path";
|
|
36264
36443
|
async function identity2(path5) {
|
|
36265
36444
|
try {
|
|
36266
36445
|
const metadata = await lstat7(path5);
|
|
@@ -36277,7 +36456,7 @@ function sameIdentity2(left, right) {
|
|
|
36277
36456
|
var FileReadCache2 = class {
|
|
36278
36457
|
#entries = /* @__PURE__ */ new Map();
|
|
36279
36458
|
async read(paths, read, validateHit) {
|
|
36280
|
-
const resolvedPaths = paths.map((path5) =>
|
|
36459
|
+
const resolvedPaths = paths.map((path5) => resolve18(path5));
|
|
36281
36460
|
const key = JSON.stringify(resolvedPaths);
|
|
36282
36461
|
const probed = await Promise.all(resolvedPaths.map(identity2));
|
|
36283
36462
|
const identities = probed.every((entry) => entry !== void 0) ? probed : void 0;
|
|
@@ -36328,10 +36507,11 @@ init_private_files2();
|
|
|
36328
36507
|
// src/common-auth-embedded/fs/refresh-file-lock.js
|
|
36329
36508
|
init_private_files2();
|
|
36330
36509
|
import { randomUUID as randomUUID16 } from "node:crypto";
|
|
36331
|
-
import { lstat as lstat8, mkdir as mkdir14, open as open9, readFile as readFile13, rename as rename11, rm as rm6, stat as
|
|
36332
|
-
import { dirname as dirname19, join as
|
|
36510
|
+
import { lstat as lstat8, mkdir as mkdir14, open as open9, readFile as readFile13, rename as rename11, rm as rm6, stat as stat11 } from "node:fs/promises";
|
|
36511
|
+
import { dirname as dirname19, join as join19 } from "node:path";
|
|
36333
36512
|
|
|
36334
36513
|
// src/common-auth-embedded/fs/with-lock.js
|
|
36514
|
+
init_private_files2();
|
|
36335
36515
|
function lockPathFor2(target, name) {
|
|
36336
36516
|
return `${target}.${name}.lock`;
|
|
36337
36517
|
}
|
|
@@ -36389,7 +36569,7 @@ function acquireRefreshFileLock2(options) {
|
|
|
36389
36569
|
}
|
|
36390
36570
|
async function acquireRefreshFileLockWithClock2(options) {
|
|
36391
36571
|
const lockPath = lockPathFor2(options.path, options.name);
|
|
36392
|
-
const legacyOwnerPath =
|
|
36572
|
+
const legacyOwnerPath = join19(lockPath, "owner.json");
|
|
36393
36573
|
const ownerId = randomUUID16();
|
|
36394
36574
|
const now = options.now ?? Date.now;
|
|
36395
36575
|
let renewTimer = null;
|
|
@@ -36397,8 +36577,8 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
36397
36577
|
let releaseConfirmed = false;
|
|
36398
36578
|
let loss;
|
|
36399
36579
|
let resolveLoss;
|
|
36400
|
-
const lostPromise = new Promise((
|
|
36401
|
-
resolveLoss =
|
|
36580
|
+
const lostPromise = new Promise((resolve27) => {
|
|
36581
|
+
resolveLoss = resolve27;
|
|
36402
36582
|
});
|
|
36403
36583
|
function notifyTimerStep(event) {
|
|
36404
36584
|
try {
|
|
@@ -36432,7 +36612,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
36432
36612
|
let terminalIOError;
|
|
36433
36613
|
let renewalInFlight = null;
|
|
36434
36614
|
const evictPath = `${lockPath}.evicting`;
|
|
36435
|
-
const evictOwnerPath =
|
|
36615
|
+
const evictOwnerPath = join19(evictPath, "owner.json");
|
|
36436
36616
|
const evictOwnerId = randomUUID16();
|
|
36437
36617
|
const EVICT_TTL = 5e3;
|
|
36438
36618
|
const MAX_STEAL_ATTEMPTS = 8;
|
|
@@ -36559,7 +36739,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
36559
36739
|
}
|
|
36560
36740
|
}
|
|
36561
36741
|
async function backoff() {
|
|
36562
|
-
await new Promise((
|
|
36742
|
+
await new Promise((resolve27) => setTimeout(resolve27, Math.floor(Math.random() * 4)));
|
|
36563
36743
|
}
|
|
36564
36744
|
async function readLockState(notifyReady = true) {
|
|
36565
36745
|
if (notifyReady && options.onStep)
|
|
@@ -36581,7 +36761,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
36581
36761
|
};
|
|
36582
36762
|
}
|
|
36583
36763
|
try {
|
|
36584
|
-
const current = await
|
|
36764
|
+
const current = await stat11(lockPath);
|
|
36585
36765
|
const legacyExpiry = Number.isFinite(expiresAt) ? expiresAt : current.mtimeMs + options.ttlMs;
|
|
36586
36766
|
if (legacyExpiry > now())
|
|
36587
36767
|
return { status: "live" };
|
|
@@ -36648,7 +36828,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
36648
36828
|
if (!sameMarkerDirectory2(created, current))
|
|
36649
36829
|
return false;
|
|
36650
36830
|
try {
|
|
36651
|
-
await
|
|
36831
|
+
await stat11(evictOwnerPath);
|
|
36652
36832
|
return true;
|
|
36653
36833
|
} catch (error) {
|
|
36654
36834
|
if (error.code !== "ENOENT")
|
|
@@ -36700,7 +36880,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
36700
36880
|
async function recoverStaleEvictionMarker() {
|
|
36701
36881
|
let evictStat;
|
|
36702
36882
|
try {
|
|
36703
|
-
evictStat = await
|
|
36883
|
+
evictStat = await stat11(evictPath);
|
|
36704
36884
|
} catch (error) {
|
|
36705
36885
|
if (error.code === "ENOENT")
|
|
36706
36886
|
return "missing";
|
|
@@ -36718,7 +36898,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
36718
36898
|
if (evictStat.mtimeMs + EVICT_TTL > now()) {
|
|
36719
36899
|
let hasOwner = true;
|
|
36720
36900
|
try {
|
|
36721
|
-
await
|
|
36901
|
+
await stat11(evictOwnerPath);
|
|
36722
36902
|
} catch (error) {
|
|
36723
36903
|
if (error.code === "ENOENT")
|
|
36724
36904
|
hasOwner = false;
|
|
@@ -37049,7 +37229,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
37049
37229
|
const remainingMs = deadline - performance.now();
|
|
37050
37230
|
if (remainingMs <= 0)
|
|
37051
37231
|
break;
|
|
37052
|
-
await new Promise((
|
|
37232
|
+
await new Promise((resolve27) => setTimeout(resolve27, Math.min(delayMs, remainingMs)));
|
|
37053
37233
|
delayMs = Math.min(delayMs * 2, 50);
|
|
37054
37234
|
}
|
|
37055
37235
|
if (windowsPrivateFiles2)
|
|
@@ -37114,15 +37294,15 @@ function getClaustrumEnrollmentPaths2(tokenPath) {
|
|
|
37114
37294
|
const extension = extname2(tokenPath) || ".json";
|
|
37115
37295
|
const stem = basename5(tokenPath, extname2(tokenPath));
|
|
37116
37296
|
return {
|
|
37117
|
-
statePath:
|
|
37297
|
+
statePath: join20(dirname20(tokenPath), `${stem}-state${extension}`),
|
|
37118
37298
|
tokenPath
|
|
37119
37299
|
};
|
|
37120
37300
|
}
|
|
37121
37301
|
function hostEnrollmentPaths2(input2) {
|
|
37122
37302
|
const override = input2.override?.trim();
|
|
37123
|
-
if (override && !
|
|
37303
|
+
if (override && !isAbsolute4(override) && !input2.cwd)
|
|
37124
37304
|
throw new ClaustrumConsumerError2("invalid-state", "A relative Claustrum enrollment override needs a base directory");
|
|
37125
|
-
const tokenPath = override ?
|
|
37305
|
+
const tokenPath = override ? isAbsolute4(override) ? override : resolve19(input2.cwd, override) : join20(input2.stateDir, `${input2.host}-enrollment.json`);
|
|
37126
37306
|
return getClaustrumEnrollmentPaths2(tokenPath);
|
|
37127
37307
|
}
|
|
37128
37308
|
function isRecord11(value) {
|
|
@@ -37307,7 +37487,7 @@ async function refuseWritableAncestor2(parent, options = {}) {
|
|
|
37307
37487
|
}
|
|
37308
37488
|
let privateGroup;
|
|
37309
37489
|
for (; ; ) {
|
|
37310
|
-
const metadata = await
|
|
37490
|
+
const metadata = await stat12(component).catch(() => void 0);
|
|
37311
37491
|
if (metadata && (metadata.mode & 18) !== 0 && (metadata.mode & 512) === 0) {
|
|
37312
37492
|
if (privateGroup === void 0) {
|
|
37313
37493
|
privateGroup = gid !== void 0 && await isPrivateGroup2(uid, gid, options);
|
|
@@ -37336,7 +37516,7 @@ async function ensureClaustrumPrivateDirectory2(directory, options = {}, what =
|
|
|
37336
37516
|
return;
|
|
37337
37517
|
}
|
|
37338
37518
|
await mkdir15(directory, { recursive: true, mode: 448 });
|
|
37339
|
-
const metadata = await
|
|
37519
|
+
const metadata = await stat12(directory);
|
|
37340
37520
|
const uid = process.geteuid?.();
|
|
37341
37521
|
if (uid !== void 0 && metadata.uid !== uid) {
|
|
37342
37522
|
throw new ClaustrumConsumerError2("unsafe-file", `Claustrum ${what} must be owned by the current user`);
|
|
@@ -37355,7 +37535,7 @@ async function writeStateAtomic2(path5, state, ancestorOptions = {}) {
|
|
|
37355
37535
|
}
|
|
37356
37536
|
if (windowsPrivateFiles2)
|
|
37357
37537
|
return writePrivateAtomic2(path5, bytes);
|
|
37358
|
-
const temporary =
|
|
37538
|
+
const temporary = join20(parent, `.${basename5(path5)}.${process.pid}.${randomUUID17()}.tmp`);
|
|
37359
37539
|
let descriptor;
|
|
37360
37540
|
let created = false;
|
|
37361
37541
|
try {
|
|
@@ -37372,7 +37552,7 @@ async function writeStateAtomic2(path5, state, ancestorOptions = {}) {
|
|
|
37372
37552
|
await descriptor?.close().catch(() => {
|
|
37373
37553
|
});
|
|
37374
37554
|
if (created)
|
|
37375
|
-
await
|
|
37555
|
+
await unlink11(temporary).catch(() => {
|
|
37376
37556
|
});
|
|
37377
37557
|
}
|
|
37378
37558
|
}
|
|
@@ -37599,7 +37779,7 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
37599
37779
|
}
|
|
37600
37780
|
if (refusal3.code === UNSUPPORTED_ENROLLMENT_CODE2) {
|
|
37601
37781
|
await lock.assertOwned();
|
|
37602
|
-
await
|
|
37782
|
+
await unlink11(this.#paths.statePath).catch((cause) => {
|
|
37603
37783
|
if (cause.code !== "ENOENT")
|
|
37604
37784
|
throw cause;
|
|
37605
37785
|
});
|
|
@@ -37689,7 +37869,7 @@ async function resetClaustrumEnrollmentState2(paths, proposedName) {
|
|
|
37689
37869
|
if (state.phase === "pending")
|
|
37690
37870
|
return "refused-pending";
|
|
37691
37871
|
await lock.assertOwned();
|
|
37692
|
-
await
|
|
37872
|
+
await unlink11(paths.statePath);
|
|
37693
37873
|
return "reset";
|
|
37694
37874
|
} finally {
|
|
37695
37875
|
await lock.release();
|
|
@@ -37750,7 +37930,7 @@ var ByteTail = class {
|
|
|
37750
37930
|
};
|
|
37751
37931
|
var defaultCommandRunner = {
|
|
37752
37932
|
run(file, args, options = {}) {
|
|
37753
|
-
return new Promise((
|
|
37933
|
+
return new Promise((resolve27) => {
|
|
37754
37934
|
const started = performance.now();
|
|
37755
37935
|
const timeoutMs = options.timeoutMs ?? 15e3;
|
|
37756
37936
|
const stderr = new ByteTail();
|
|
@@ -37768,7 +37948,7 @@ var defaultCommandRunner = {
|
|
|
37768
37948
|
stdio: ["ignore", "pipe", "pipe"]
|
|
37769
37949
|
});
|
|
37770
37950
|
} catch {
|
|
37771
|
-
|
|
37951
|
+
resolve27({
|
|
37772
37952
|
exitCode: 1,
|
|
37773
37953
|
stdout: "",
|
|
37774
37954
|
stderr: "",
|
|
@@ -37803,7 +37983,7 @@ var defaultCommandRunner = {
|
|
|
37803
37983
|
settled = true;
|
|
37804
37984
|
if (timer)
|
|
37805
37985
|
clearTimeout(timer);
|
|
37806
|
-
|
|
37986
|
+
resolve27({
|
|
37807
37987
|
exitCode: spawnError ? 1 : outputExceeded ? 1 : code2 ?? 1,
|
|
37808
37988
|
stdout: Buffer.concat(stdout, stdoutLength).toString("utf8"),
|
|
37809
37989
|
stderr: stderr.toString(),
|
|
@@ -37890,7 +38070,7 @@ function recordSetupEnrollment(failure2, enrollment) {
|
|
|
37890
38070
|
import { accessSync, constants as constants3, existsSync as existsSync6, readFileSync as readFileSync5, realpathSync as realpathSync3, statSync as statSync5 } from "node:fs";
|
|
37891
38071
|
import { mkdtemp, rm as rm7 } from "node:fs/promises";
|
|
37892
38072
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
37893
|
-
import { join as
|
|
38073
|
+
import { join as join21 } from "node:path";
|
|
37894
38074
|
import { parse } from "jsonc-parser";
|
|
37895
38075
|
|
|
37896
38076
|
// src/common-auth-embedded/setup/paths.js
|
|
@@ -37925,7 +38105,7 @@ function setupPaths(io = {}) {
|
|
|
37925
38105
|
}
|
|
37926
38106
|
|
|
37927
38107
|
// src/common-auth-embedded/setup/detect.js
|
|
37928
|
-
function
|
|
38108
|
+
function stat13(path5, kind) {
|
|
37929
38109
|
try {
|
|
37930
38110
|
return statSync5(path5)[kind]();
|
|
37931
38111
|
} catch {
|
|
@@ -37934,12 +38114,12 @@ function stat12(path5, kind) {
|
|
|
37934
38114
|
}
|
|
37935
38115
|
var defaultSetupFileSystem = {
|
|
37936
38116
|
exists: existsSync6,
|
|
37937
|
-
isFile: (path5) =>
|
|
37938
|
-
isDirectory: (path5) =>
|
|
38117
|
+
isFile: (path5) => stat13(path5, "isFile"),
|
|
38118
|
+
isDirectory: (path5) => stat13(path5, "isDirectory"),
|
|
37939
38119
|
isExecutable(path5) {
|
|
37940
38120
|
try {
|
|
37941
38121
|
accessSync(path5, constants3.X_OK);
|
|
37942
|
-
return
|
|
38122
|
+
return stat13(path5, "isFile");
|
|
37943
38123
|
} catch {
|
|
37944
38124
|
return false;
|
|
37945
38125
|
}
|
|
@@ -38061,7 +38241,7 @@ async function detectHosts(plugin, io = {}) {
|
|
|
38061
38241
|
return null;
|
|
38062
38242
|
let root;
|
|
38063
38243
|
try {
|
|
38064
|
-
root = await mkdtemp(
|
|
38244
|
+
root = await mkdtemp(join21(tmpdir3(), "common-auth-setup-version-"));
|
|
38065
38245
|
const probeEnv = {
|
|
38066
38246
|
...env3,
|
|
38067
38247
|
HOME: root,
|
|
@@ -38645,8 +38825,8 @@ import { applyEdits, createScanner, findNodeAtLocation, modify, parse as parse2,
|
|
|
38645
38825
|
|
|
38646
38826
|
// src/common-auth-embedded/setup/config-write.js
|
|
38647
38827
|
import { randomUUID as randomUUID18 } from "node:crypto";
|
|
38648
|
-
import { mkdir as mkdir16, open as open11, rename as rename13, stat as
|
|
38649
|
-
import { basename as basename6, dirname as dirname21, join as
|
|
38828
|
+
import { mkdir as mkdir16, open as open11, rename as rename13, stat as stat14, unlink as unlink12 } from "node:fs/promises";
|
|
38829
|
+
import { basename as basename6, dirname as dirname21, join as join22 } from "node:path";
|
|
38650
38830
|
import { setTimeout as delay2 } from "node:timers/promises";
|
|
38651
38831
|
async function writeHostConfigAtomic(file, content, options = {}) {
|
|
38652
38832
|
const windows2 = (options.platform ?? process.platform) === "win32";
|
|
@@ -38655,13 +38835,13 @@ async function writeHostConfigAtomic(file, content, options = {}) {
|
|
|
38655
38835
|
let mode;
|
|
38656
38836
|
if (!windows2) {
|
|
38657
38837
|
try {
|
|
38658
|
-
mode = (await
|
|
38838
|
+
mode = (await stat14(file)).mode & 4095;
|
|
38659
38839
|
} catch (error) {
|
|
38660
38840
|
if (error.code !== "ENOENT")
|
|
38661
38841
|
throw error;
|
|
38662
38842
|
}
|
|
38663
38843
|
}
|
|
38664
|
-
const stage =
|
|
38844
|
+
const stage = join22(parent, `.${basename6(file)}.${(options.stageName ?? randomUUID18)()}.tmp`);
|
|
38665
38845
|
let created = false;
|
|
38666
38846
|
try {
|
|
38667
38847
|
const handle = await open11(stage, "wx", mode ?? 438);
|
|
@@ -38691,7 +38871,7 @@ async function writeHostConfigAtomic(file, content, options = {}) {
|
|
|
38691
38871
|
}
|
|
38692
38872
|
} finally {
|
|
38693
38873
|
if (created)
|
|
38694
|
-
await
|
|
38874
|
+
await unlink12(stage).catch(() => {
|
|
38695
38875
|
});
|
|
38696
38876
|
}
|
|
38697
38877
|
}
|
|
@@ -39081,11 +39261,11 @@ init_storage();
|
|
|
39081
39261
|
init_dist();
|
|
39082
39262
|
import { readFile as readFile15 } from "node:fs/promises";
|
|
39083
39263
|
import { homedir as homedir8 } from "node:os";
|
|
39084
|
-
import { join as
|
|
39264
|
+
import { join as join23 } from "node:path";
|
|
39085
39265
|
var V1_VAULT_ACTIVATION_LABEL = "Activate approved Antigravity vault";
|
|
39086
39266
|
function nativeOpenCodeAuthPath(env3 = process.env, home = homedir8()) {
|
|
39087
|
-
return
|
|
39088
|
-
env3.XDG_DATA_HOME ||
|
|
39267
|
+
return join23(
|
|
39268
|
+
env3.XDG_DATA_HOME || join23(home, ".local", "share"),
|
|
39089
39269
|
"opencode",
|
|
39090
39270
|
"auth.json"
|
|
39091
39271
|
);
|
|
@@ -39133,63 +39313,7 @@ function createV1VaultActivationMethod(input2) {
|
|
|
39133
39313
|
// src/setup.ts
|
|
39134
39314
|
init_vault_custody();
|
|
39135
39315
|
init_runtime_paths();
|
|
39136
|
-
|
|
39137
|
-
// src/vault-folder.ts
|
|
39138
|
-
init_logger4();
|
|
39139
|
-
init_process_heartbeat();
|
|
39140
|
-
init_runtime_layout();
|
|
39141
|
-
init_runtime_paths();
|
|
39142
|
-
var refusalsKey = /* @__PURE__ */ Symbol.for(
|
|
39143
|
-
"@cortexkit/antigravity-auth/vault-folder-refusals"
|
|
39144
|
-
);
|
|
39145
|
-
var globalState3 = globalThis;
|
|
39146
|
-
var refusals = globalState3[refusalsKey] ?? /* @__PURE__ */ new Map();
|
|
39147
|
-
globalState3[refusalsKey] = refusals;
|
|
39148
|
-
function locationKey() {
|
|
39149
|
-
const location = runtimeLayoutLocation();
|
|
39150
|
-
return `${location.stateHomeDir}\0${location.key}`;
|
|
39151
|
-
}
|
|
39152
|
-
async function prepareVaultFolder(options) {
|
|
39153
|
-
const { accountFile } = options;
|
|
39154
|
-
const key = locationKey();
|
|
39155
|
-
const kept = refusals.get(key);
|
|
39156
|
-
if (kept) return refused(accountFile, kept);
|
|
39157
|
-
const log16 = options.log ?? createLogger4("runtime-layout");
|
|
39158
|
-
const version = options.version ?? await pluginPackageVersion().catch(() => "unknown");
|
|
39159
|
-
try {
|
|
39160
|
-
await prepareRuntimeLayout({
|
|
39161
|
-
version,
|
|
39162
|
-
accountFile,
|
|
39163
|
-
log: log16,
|
|
39164
|
-
...options.layoutLockWaitMs === void 0 ? {} : { layoutLockWaitMs: options.layoutLockWaitMs }
|
|
39165
|
-
});
|
|
39166
|
-
if (options.accountStore !== false)
|
|
39167
|
-
await prepareAccountStore({ version, log: log16 });
|
|
39168
|
-
} catch (error) {
|
|
39169
|
-
const refusal3 = error instanceof RuntimeLayoutRefusal ? error : new RuntimeLayoutRefusal(
|
|
39170
|
-
runtimeLayoutLocation().stateHomeDir,
|
|
39171
|
-
error instanceof Error ? error.name : typeof error
|
|
39172
|
-
);
|
|
39173
|
-
if (!refusals.has(key)) {
|
|
39174
|
-
refusals.set(key, refusal3);
|
|
39175
|
-
log16.warn(refusal3.message, {
|
|
39176
|
-
stateDir: refusal3.stateDir,
|
|
39177
|
-
errorClass: refusal3.errorClass
|
|
39178
|
-
});
|
|
39179
|
-
}
|
|
39180
|
-
return refused(accountFile, refusals.get(key) ?? refusal3);
|
|
39181
|
-
}
|
|
39182
|
-
return { accountFile, vaultDir: getVaultDir(accountFile) };
|
|
39183
|
-
}
|
|
39184
|
-
function currentVaultFolder(accountFile) {
|
|
39185
|
-
const kept = refusals.get(locationKey());
|
|
39186
|
-
return kept ? refused(accountFile, kept) : { accountFile, vaultDir: getVaultDir(accountFile) };
|
|
39187
|
-
}
|
|
39188
|
-
function refused(accountFile, refusal3) {
|
|
39189
|
-
return { accountFile, vaultDir: getVaultDir(accountFile), refusal: refusal3 };
|
|
39190
|
-
}
|
|
39191
|
-
|
|
39192
|
-
// src/setup.ts
|
|
39316
|
+
init_vault_folder();
|
|
39193
39317
|
var PI_PLACEHOLDER_KEY = "antigravity-vault-custody";
|
|
39194
39318
|
async function storePresent(anchor) {
|
|
39195
39319
|
return await pathPresent(accountStorePointerPath(anchor)) || await pathPresent(anchor);
|
|
@@ -39206,7 +39330,7 @@ function openCodeVaultDir(accountFile) {
|
|
|
39206
39330
|
return folder.vaultDir;
|
|
39207
39331
|
}
|
|
39208
39332
|
function nativeAuthPath(host, context) {
|
|
39209
|
-
return host === "opencode" ? nativeOpenCodeAuthPath() :
|
|
39333
|
+
return host === "opencode" ? nativeOpenCodeAuthPath() : join24(context.piAgentDir, "auth.json");
|
|
39210
39334
|
}
|
|
39211
39335
|
function provider(host) {
|
|
39212
39336
|
return host === "opencode" ? OPENCODE_VAULT_PROVIDER : ANTIGRAVITY_PROVIDER_ID;
|
|
@@ -39262,7 +39386,7 @@ async function writeNativeSlot(host, slot, context, expectedAuthority = "local")
|
|
|
39262
39386
|
beforeRename: async () => {
|
|
39263
39387
|
await assertSetupHostsStopped();
|
|
39264
39388
|
const claustrum = await loadCommonAuthClaustrum();
|
|
39265
|
-
const stateDir = host === "opencode" ? openCodeVaultDir(
|
|
39389
|
+
const stateDir = host === "opencode" ? openCodeVaultDir(resolve20(accountFileForVault())) : getPiAntigravityVaultDir();
|
|
39266
39390
|
if (await claustrum.enrollmentAuthority(
|
|
39267
39391
|
claustrum.hostEnrollmentPaths({ stateDir, host }),
|
|
39268
39392
|
`antigravity-auth-${host}`
|
|
@@ -39300,7 +39424,7 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
39300
39424
|
// `beforeSignIn`, which may move it after this plugin is built.
|
|
39301
39425
|
paths: {
|
|
39302
39426
|
get stateDir() {
|
|
39303
|
-
return openCodeVaultDir(
|
|
39427
|
+
return openCodeVaultDir(resolve20(accountFileForVault()));
|
|
39304
39428
|
},
|
|
39305
39429
|
host: "opencode"
|
|
39306
39430
|
}
|
|
@@ -39317,7 +39441,7 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
39317
39441
|
const assertLocal = async (host, context) => {
|
|
39318
39442
|
if (host === "opencode")
|
|
39319
39443
|
return assertLocalOpenCodeLogin(
|
|
39320
|
-
|
|
39444
|
+
resolve20(accountFileForVault()),
|
|
39321
39445
|
context.opencodeGeneration
|
|
39322
39446
|
);
|
|
39323
39447
|
if (await authority(host) !== "local")
|
|
@@ -39333,7 +39457,7 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
39333
39457
|
const { openPiSlot: openPiSlot2 } = await loadCommonAuthPiSlot();
|
|
39334
39458
|
if ((await openPiSlot2({
|
|
39335
39459
|
authPath: nativeAuthPath(host, context),
|
|
39336
|
-
stashPath:
|
|
39460
|
+
stashPath: join24(piDir, "google-login-stash.json"),
|
|
39337
39461
|
provider: ANTIGRAVITY_PROVIDER_ID,
|
|
39338
39462
|
placeholderKey: PI_PLACEHOLDER_KEY
|
|
39339
39463
|
}).inspect()).slot === "placeholder")
|
|
@@ -39373,7 +39497,7 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
39373
39497
|
const { openPiSlot: openPiSlot2 } = await loadCommonAuthPiSlot();
|
|
39374
39498
|
const inspection = await openPiSlot2({
|
|
39375
39499
|
authPath: nativeAuthPath("pi", context),
|
|
39376
|
-
stashPath:
|
|
39500
|
+
stashPath: join24(piDir, "google-login-stash.json"),
|
|
39377
39501
|
provider: ANTIGRAVITY_PROVIDER_ID,
|
|
39378
39502
|
placeholderKey: PI_PLACEHOLDER_KEY
|
|
39379
39503
|
}).inspect();
|
|
@@ -39492,7 +39616,7 @@ Setup has not completed the OpenCode 2 native Google connection.
|
|
|
39492
39616
|
await assertSetupHostsStopped();
|
|
39493
39617
|
await openPiSlot2({
|
|
39494
39618
|
authPath: nativeAuthPath(host, context),
|
|
39495
|
-
stashPath:
|
|
39619
|
+
stashPath: join24(piDir, "google-login-stash.json"),
|
|
39496
39620
|
provider: ANTIGRAVITY_PROVIDER_ID,
|
|
39497
39621
|
placeholderKey: PI_PLACEHOLDER_KEY
|
|
39498
39622
|
}).enterVault();
|
|
@@ -39558,6 +39682,7 @@ async function runPluginSetup(argv, deps, migrateOpenCode, io = {}) {
|
|
|
39558
39682
|
}
|
|
39559
39683
|
|
|
39560
39684
|
// src/cli.ts
|
|
39685
|
+
init_vault_folder();
|
|
39561
39686
|
var HELP = `Usage: antigravity-auth <command> [options]
|
|
39562
39687
|
|
|
39563
39688
|
Commands:
|
|
@@ -39947,7 +40072,7 @@ async function runCliProcess(argv, deps) {
|
|
|
39947
40072
|
...deps,
|
|
39948
40073
|
prepareVaultFolder: deps.prepareVaultFolder ?? (async (options) => {
|
|
39949
40074
|
const folder = await prepareVaultFolder({
|
|
39950
|
-
accountFile:
|
|
40075
|
+
accountFile: resolve21(accountFileForVault()),
|
|
39951
40076
|
...options
|
|
39952
40077
|
});
|
|
39953
40078
|
if (folder.refusal) throw folder.refusal;
|
|
@@ -39993,11 +40118,11 @@ function createDefaultCliDependencies() {
|
|
|
39993
40118
|
);
|
|
39994
40119
|
if (host !== "pi")
|
|
39995
40120
|
await assertLocalOpenCodeLogin(
|
|
39996
|
-
|
|
40121
|
+
resolve21(accountFileForVault()),
|
|
39997
40122
|
context?.opencodeGeneration
|
|
39998
40123
|
);
|
|
39999
40124
|
const repository = host === "pi" ? void 0 : await prepareCliLoginStore(
|
|
40000
|
-
|
|
40125
|
+
resolve21(getStoragePath()),
|
|
40001
40126
|
context?.opencodeGeneration
|
|
40002
40127
|
);
|
|
40003
40128
|
try {
|
|
@@ -40013,7 +40138,7 @@ function createDefaultCliDependencies() {
|
|
|
40013
40138
|
}
|
|
40014
40139
|
if (host === "opencode") await assertSetupHostsStopped();
|
|
40015
40140
|
await assertLocalOpenCodeLogin(
|
|
40016
|
-
|
|
40141
|
+
resolve21(accountFileForVault()),
|
|
40017
40142
|
context?.opencodeGeneration
|
|
40018
40143
|
);
|
|
40019
40144
|
await persistCliStoreLogin(
|
|
@@ -40033,7 +40158,7 @@ function createDefaultCliDependencies() {
|
|
|
40033
40158
|
};
|
|
40034
40159
|
}
|
|
40035
40160
|
async function prepareCliLoginStore(legacyPath, generation) {
|
|
40036
|
-
await assertLocalOpenCodeLogin(
|
|
40161
|
+
await assertLocalOpenCodeLogin(resolve21(accountFileForVault()), generation);
|
|
40037
40162
|
const modules = await loadCommonAuthStoreModules();
|
|
40038
40163
|
const options = {
|
|
40039
40164
|
legacyPath,
|
|
@@ -40158,7 +40283,7 @@ async function readAccountStore(legacyPath) {
|
|
|
40158
40283
|
function createDefaultAccountStoreOperations() {
|
|
40159
40284
|
const offline = { processesStopped: true };
|
|
40160
40285
|
return {
|
|
40161
|
-
legacyPath: () =>
|
|
40286
|
+
legacyPath: () => resolve21(
|
|
40162
40287
|
decidedAccountStoreAnchor(runtimeLayoutLocation()) ? getStoragePath() : discoveredAccountFile()
|
|
40163
40288
|
),
|
|
40164
40289
|
migrate: async (legacyPath) => createAccountMigrationFactory(await loadCommonAuthStoreModules())({
|
|
@@ -40189,7 +40314,7 @@ function createDefaultAccountStoreOperations() {
|
|
|
40189
40314
|
};
|
|
40190
40315
|
}
|
|
40191
40316
|
function samePath(left, right) {
|
|
40192
|
-
return process.platform === "win32" ?
|
|
40317
|
+
return process.platform === "win32" ? resolve21(left).toLowerCase() === resolve21(right).toLowerCase() : resolve21(left) === resolve21(right);
|
|
40193
40318
|
}
|
|
40194
40319
|
function isCliEntry() {
|
|
40195
40320
|
if (import.meta.main !== void 0) return import.meta.main;
|
|
@@ -40368,8 +40493,8 @@ function getLocalDevPath(directory) {
|
|
|
40368
40493
|
}
|
|
40369
40494
|
function findPackageJsonUp(startPath) {
|
|
40370
40495
|
try {
|
|
40371
|
-
const
|
|
40372
|
-
let dir =
|
|
40496
|
+
const stat16 = fs4.statSync(startPath);
|
|
40497
|
+
let dir = stat16.isDirectory() ? startPath : path4.dirname(startPath);
|
|
40373
40498
|
for (let i = 0; i < 10; i++) {
|
|
40374
40499
|
const pkgPath = path4.join(dir, "package.json");
|
|
40375
40500
|
if (fs4.existsSync(pkgPath)) {
|
|
@@ -40679,16 +40804,16 @@ function isTuiConnected(sessionId) {
|
|
|
40679
40804
|
// src/rpc/rpc-dir.ts
|
|
40680
40805
|
import { createHash as createHash14 } from "node:crypto";
|
|
40681
40806
|
import { homedir as homedir10, tmpdir as tmpdir4 } from "node:os";
|
|
40682
|
-
import { isAbsolute as
|
|
40807
|
+
import { isAbsolute as isAbsolute5, join as join28, resolve as resolve22 } from "node:path";
|
|
40683
40808
|
var RPC_DIR_ENV = "ANTIGRAVITY_AUTH_RPC_DIR";
|
|
40684
40809
|
function getRpcDir(projectDirectory) {
|
|
40685
40810
|
const override = process.env[RPC_DIR_ENV]?.trim();
|
|
40686
40811
|
if (override) {
|
|
40687
|
-
return
|
|
40812
|
+
return isAbsolute5(override) ? override : resolve22(projectDirectory, override);
|
|
40688
40813
|
}
|
|
40689
|
-
const projectHash = createHash14("sha256").update(
|
|
40690
|
-
const stateHome = process.env.XDG_STATE_HOME ??
|
|
40691
|
-
return
|
|
40814
|
+
const projectHash = createHash14("sha256").update(resolve22(projectDirectory)).digest("hex").slice(0, 16);
|
|
40815
|
+
const stateHome = process.env.XDG_STATE_HOME ?? join28(homedir10(), ".local", "state");
|
|
40816
|
+
return join28(stateHome, "cortexkit", "antigravity-auth", "rpc", projectHash);
|
|
40692
40817
|
}
|
|
40693
40818
|
|
|
40694
40819
|
// src/common-auth-embedded/rpc/notifications.js
|
|
@@ -40699,8 +40824,8 @@ function isSessionId(value) {
|
|
|
40699
40824
|
// src/common-auth-embedded/rpc/port-file.js
|
|
40700
40825
|
init_private_files2();
|
|
40701
40826
|
import { createHash as createHash15, randomUUID as randomUUID19 } from "node:crypto";
|
|
40702
|
-
import { chmod as chmod7, mkdir as mkdir17, open as open12, readdir as readdir4, rename as rename14, rmdir as rmdir3, stat as
|
|
40703
|
-
import { join as
|
|
40827
|
+
import { chmod as chmod7, mkdir as mkdir17, open as open12, readdir as readdir4, rename as rename14, rmdir as rmdir3, stat as stat15, unlink as unlink13 } from "node:fs/promises";
|
|
40828
|
+
import { join as join29, resolve as resolve23 } from "node:path";
|
|
40704
40829
|
function isProbeablePid(pid) {
|
|
40705
40830
|
return typeof pid === "number" && Number.isSafeInteger(pid) && pid > 0;
|
|
40706
40831
|
}
|
|
@@ -40724,14 +40849,14 @@ function isUsablePortFileEntry(value, name) {
|
|
|
40724
40849
|
const { pid, port, token } = value;
|
|
40725
40850
|
return isProbeablePid(pid) && filenamePid(name) === pid && typeof port === "number" && Number.isInteger(port) && port >= 1 && port <= 65535 && typeof token === "string" && token.length > 0;
|
|
40726
40851
|
}
|
|
40727
|
-
async function removeCorruptPortFile(portFile,
|
|
40728
|
-
|
|
40729
|
-
await
|
|
40852
|
+
async function removeCorruptPortFile(portFile, log17) {
|
|
40853
|
+
log17?.debug("rpc corrupt port file", { pid: process.pid, portFile });
|
|
40854
|
+
await unlink13(portFile).catch(() => {
|
|
40730
40855
|
});
|
|
40731
40856
|
}
|
|
40732
40857
|
async function writePortFile(dir, entry, options = {}) {
|
|
40733
40858
|
const writeOnce = async () => {
|
|
40734
|
-
const target =
|
|
40859
|
+
const target = join29(dir, `port-${entry.pid}.json`);
|
|
40735
40860
|
if (windowsPrivateFiles2) {
|
|
40736
40861
|
await ensurePrivateDirectory2(dir, options.secureDir ?? false);
|
|
40737
40862
|
await options.beforeWrite?.();
|
|
@@ -40764,7 +40889,7 @@ async function writePortFile(dir, entry, options = {}) {
|
|
|
40764
40889
|
await handle?.close().catch(() => {
|
|
40765
40890
|
});
|
|
40766
40891
|
if (created)
|
|
40767
|
-
await
|
|
40892
|
+
await unlink13(tmp).catch(() => {
|
|
40768
40893
|
});
|
|
40769
40894
|
}
|
|
40770
40895
|
return target;
|
|
@@ -40778,7 +40903,7 @@ async function writePortFile(dir, entry, options = {}) {
|
|
|
40778
40903
|
throw error;
|
|
40779
40904
|
}
|
|
40780
40905
|
}
|
|
40781
|
-
async function sweepRpcState(root, activeDir, isManagedDir,
|
|
40906
|
+
async function sweepRpcState(root, activeDir, isManagedDir, log17) {
|
|
40782
40907
|
let projectDirs;
|
|
40783
40908
|
try {
|
|
40784
40909
|
projectDirs = await readdir4(root, { withFileTypes: true });
|
|
@@ -40787,12 +40912,12 @@ async function sweepRpcState(root, activeDir, isManagedDir, log16) {
|
|
|
40787
40912
|
return;
|
|
40788
40913
|
throw error;
|
|
40789
40914
|
}
|
|
40790
|
-
const active2 =
|
|
40915
|
+
const active2 = resolve23(activeDir);
|
|
40791
40916
|
for (const projectDir of projectDirs) {
|
|
40792
40917
|
if (!projectDir.isDirectory() || !isManagedDir(projectDir.name)) {
|
|
40793
40918
|
continue;
|
|
40794
40919
|
}
|
|
40795
|
-
const dir =
|
|
40920
|
+
const dir = join29(root, projectDir.name);
|
|
40796
40921
|
let names;
|
|
40797
40922
|
try {
|
|
40798
40923
|
names = await readdir4(dir);
|
|
@@ -40804,7 +40929,7 @@ async function sweepRpcState(root, activeDir, isManagedDir, log16) {
|
|
|
40804
40929
|
for (const name of names) {
|
|
40805
40930
|
if (!name.startsWith("port-") || !name.endsWith(".json"))
|
|
40806
40931
|
continue;
|
|
40807
|
-
const portFile =
|
|
40932
|
+
const portFile = join29(dir, name);
|
|
40808
40933
|
let raw;
|
|
40809
40934
|
try {
|
|
40810
40935
|
raw = await readPrivateText2(portFile);
|
|
@@ -40819,19 +40944,19 @@ async function sweepRpcState(root, activeDir, isManagedDir, log16) {
|
|
|
40819
40944
|
try {
|
|
40820
40945
|
parsed = JSON.parse(raw);
|
|
40821
40946
|
} catch {
|
|
40822
|
-
await removeCorruptPortFile(portFile,
|
|
40947
|
+
await removeCorruptPortFile(portFile, log17);
|
|
40823
40948
|
continue;
|
|
40824
40949
|
}
|
|
40825
40950
|
if (!isUsablePortFileEntry(parsed, name)) {
|
|
40826
|
-
await removeCorruptPortFile(portFile,
|
|
40951
|
+
await removeCorruptPortFile(portFile, log17);
|
|
40827
40952
|
continue;
|
|
40828
40953
|
}
|
|
40829
40954
|
const entry = parsed;
|
|
40830
40955
|
if (!pidAlive2(entry.pid))
|
|
40831
|
-
await
|
|
40956
|
+
await unlink13(portFile).catch(() => {
|
|
40832
40957
|
});
|
|
40833
40958
|
}
|
|
40834
|
-
if (
|
|
40959
|
+
if (resolve23(dir) !== active2)
|
|
40835
40960
|
await rmdir3(dir).catch(() => {
|
|
40836
40961
|
});
|
|
40837
40962
|
}
|
|
@@ -40843,9 +40968,9 @@ init_private_files2();
|
|
|
40843
40968
|
// src/common-auth-embedded/rpc/rpc-server.js
|
|
40844
40969
|
init_private_files2();
|
|
40845
40970
|
import { randomBytes as randomBytes6, timingSafeEqual } from "node:crypto";
|
|
40846
|
-
import { unlink as
|
|
40971
|
+
import { unlink as unlink14 } from "node:fs/promises";
|
|
40847
40972
|
import { createServer as createServer2 } from "node:http";
|
|
40848
|
-
import { join as
|
|
40973
|
+
import { join as join30 } from "node:path";
|
|
40849
40974
|
var RpcRequestError = class extends Error {
|
|
40850
40975
|
status;
|
|
40851
40976
|
constructor(status, message) {
|
|
@@ -40865,7 +40990,7 @@ var BodyTooLargeError = class extends Error {
|
|
|
40865
40990
|
}
|
|
40866
40991
|
};
|
|
40867
40992
|
function readBody(req) {
|
|
40868
|
-
return new Promise((
|
|
40993
|
+
return new Promise((resolve27, reject) => {
|
|
40869
40994
|
const tooLarge = (declaredOversize = false) => {
|
|
40870
40995
|
req.removeAllListeners("data");
|
|
40871
40996
|
req.on("data", () => {
|
|
@@ -40888,7 +41013,7 @@ function readBody(req) {
|
|
|
40888
41013
|
}
|
|
40889
41014
|
chunks.push(chunk);
|
|
40890
41015
|
});
|
|
40891
|
-
req.on("end", () =>
|
|
41016
|
+
req.on("end", () => resolve27(Buffer.concat(chunks).toString("utf8")));
|
|
40892
41017
|
req.on("error", reject);
|
|
40893
41018
|
});
|
|
40894
41019
|
}
|
|
@@ -40918,7 +41043,7 @@ function tokenOk(header, token) {
|
|
|
40918
41043
|
async function startRpcServer(options) {
|
|
40919
41044
|
if (typeof options.drain === "function" === (typeof options.drainAsync === "function"))
|
|
40920
41045
|
throw new TypeError("exactly one of drain or drainAsync must be provided");
|
|
40921
|
-
const
|
|
41046
|
+
const log17 = options.log ?? { warn() {
|
|
40922
41047
|
}, debug() {
|
|
40923
41048
|
} };
|
|
40924
41049
|
const token = randomBytes6(32).toString("hex");
|
|
@@ -41019,7 +41144,7 @@ async function startRpcServer(options) {
|
|
|
41019
41144
|
return json(400, { error: "session required" });
|
|
41020
41145
|
if (sessionId === void 0 && !warnedMissingNotificationSession) {
|
|
41021
41146
|
warnedMissingNotificationSession = true;
|
|
41022
|
-
|
|
41147
|
+
log17.warn("rpc notification drain missing session id", {
|
|
41023
41148
|
pid: process.pid
|
|
41024
41149
|
});
|
|
41025
41150
|
}
|
|
@@ -41028,7 +41153,7 @@ async function startRpcServer(options) {
|
|
|
41028
41153
|
try {
|
|
41029
41154
|
messages = await options.drainAsync(lastReceivedId, sessionId);
|
|
41030
41155
|
} catch (error) {
|
|
41031
|
-
|
|
41156
|
+
log17.warn("rpc notification drain failed", {
|
|
41032
41157
|
pid: process.pid,
|
|
41033
41158
|
error: error instanceof Error ? error.message : String(error)
|
|
41034
41159
|
});
|
|
@@ -41047,32 +41172,32 @@ async function startRpcServer(options) {
|
|
|
41047
41172
|
return json(404, { error: "unknown method" });
|
|
41048
41173
|
} catch (error) {
|
|
41049
41174
|
if (error instanceof RpcRequestError) {
|
|
41050
|
-
|
|
41175
|
+
log17.debug("rpc request refused", {
|
|
41051
41176
|
pid: process.pid,
|
|
41052
41177
|
status: error.status
|
|
41053
41178
|
});
|
|
41054
41179
|
return json(error.status, { error: error.message });
|
|
41055
41180
|
}
|
|
41056
41181
|
if (error instanceof ApplyDeadlineError) {
|
|
41057
|
-
|
|
41182
|
+
log17.warn("rpc apply deadline exceeded", {
|
|
41058
41183
|
pid: process.pid,
|
|
41059
41184
|
deadlineMs: options.applyDeadlineMs
|
|
41060
41185
|
});
|
|
41061
41186
|
return json(504, { error: "handler deadline exceeded" });
|
|
41062
41187
|
}
|
|
41063
|
-
|
|
41188
|
+
log17.warn("rpc request failed", {
|
|
41064
41189
|
pid: process.pid,
|
|
41065
41190
|
error: error instanceof Error ? error.message : String(error)
|
|
41066
41191
|
});
|
|
41067
41192
|
json(500, { error: "internal error" });
|
|
41068
41193
|
}
|
|
41069
41194
|
}
|
|
41070
|
-
const port = await new Promise((
|
|
41195
|
+
const port = await new Promise((resolve27, reject) => {
|
|
41071
41196
|
server.on("error", reject);
|
|
41072
41197
|
server.listen(0, "127.0.0.1", () => {
|
|
41073
41198
|
const addr = server.address();
|
|
41074
41199
|
if (addr && typeof addr === "object")
|
|
41075
|
-
|
|
41200
|
+
resolve27(addr.port);
|
|
41076
41201
|
else
|
|
41077
41202
|
reject(new Error("no port"));
|
|
41078
41203
|
});
|
|
@@ -41080,9 +41205,9 @@ async function startRpcServer(options) {
|
|
|
41080
41205
|
server.unref();
|
|
41081
41206
|
if (options.sweepRoot) {
|
|
41082
41207
|
try {
|
|
41083
|
-
await sweepRpcState(options.sweepRoot, options.dir, options.isManagedDir,
|
|
41208
|
+
await sweepRpcState(options.sweepRoot, options.dir, options.isManagedDir, log17);
|
|
41084
41209
|
} catch (error) {
|
|
41085
|
-
|
|
41210
|
+
log17.warn("rpc state sweep failed", {
|
|
41086
41211
|
pid: process.pid,
|
|
41087
41212
|
error: error instanceof Error ? error.message : String(error)
|
|
41088
41213
|
});
|
|
@@ -41090,32 +41215,32 @@ async function startRpcServer(options) {
|
|
|
41090
41215
|
}
|
|
41091
41216
|
try {
|
|
41092
41217
|
await writePortFile(options.dir, { port, token, pid: process.pid }, { secureDir: options.secureDir });
|
|
41093
|
-
|
|
41218
|
+
log17.debug("rpc server pid", {
|
|
41094
41219
|
pid: process.pid,
|
|
41095
41220
|
rpcPort: port
|
|
41096
41221
|
});
|
|
41097
41222
|
} catch (error) {
|
|
41098
|
-
await new Promise((
|
|
41223
|
+
await new Promise((resolve27) => server.close(() => resolve27()));
|
|
41099
41224
|
throw error;
|
|
41100
41225
|
}
|
|
41101
41226
|
return {
|
|
41102
41227
|
port,
|
|
41103
41228
|
token,
|
|
41104
41229
|
async stop() {
|
|
41105
|
-
await new Promise((
|
|
41230
|
+
await new Promise((resolve27) => {
|
|
41106
41231
|
server.closeAllConnections?.();
|
|
41107
|
-
server.close(() =>
|
|
41232
|
+
server.close(() => resolve27());
|
|
41108
41233
|
for (const socket of connections)
|
|
41109
41234
|
socket.destroy();
|
|
41110
41235
|
});
|
|
41111
|
-
const portFile =
|
|
41236
|
+
const portFile = join30(options.dir, `port-${process.pid}.json`);
|
|
41112
41237
|
const current = await readPrivateText2(portFile).then((raw) => JSON.parse(raw)).catch((error) => {
|
|
41113
41238
|
if (error instanceof PrivateFileError2 && error.code !== "ENOENT")
|
|
41114
41239
|
throw error;
|
|
41115
41240
|
return void 0;
|
|
41116
41241
|
});
|
|
41117
41242
|
if (current?.port === port && current.token === token)
|
|
41118
|
-
await
|
|
41243
|
+
await unlink14(portFile).catch(() => {
|
|
41119
41244
|
});
|
|
41120
41245
|
}
|
|
41121
41246
|
};
|
|
@@ -41190,6 +41315,9 @@ function parsePending(value) {
|
|
|
41190
41315
|
};
|
|
41191
41316
|
}
|
|
41192
41317
|
|
|
41318
|
+
// src/plugin/index.ts
|
|
41319
|
+
init_vault_folder();
|
|
41320
|
+
|
|
41193
41321
|
// src/plugin/account-access.ts
|
|
41194
41322
|
init_dist();
|
|
41195
41323
|
|
|
@@ -42196,7 +42324,7 @@ import { createInterface as createInterface2 } from "node:readline/promises";
|
|
|
42196
42324
|
// src/plugin/config/updater.ts
|
|
42197
42325
|
import { existsSync as existsSync9, mkdirSync as mkdirSync4, readFileSync as readFileSync8, writeFileSync as writeFileSync4 } from "node:fs";
|
|
42198
42326
|
import { homedir as homedir11 } from "node:os";
|
|
42199
|
-
import { dirname as dirname23, join as
|
|
42327
|
+
import { dirname as dirname23, join as join31 } from "node:path";
|
|
42200
42328
|
|
|
42201
42329
|
// src/plugin/model-registry.ts
|
|
42202
42330
|
init_dist();
|
|
@@ -42213,13 +42341,13 @@ function stripJsonCommentsAndTrailingCommas(json) {
|
|
|
42213
42341
|
).replace(/,(\s*[}\]])/g, "$1");
|
|
42214
42342
|
}
|
|
42215
42343
|
function getOpencodeConfigDir() {
|
|
42216
|
-
const xdgConfig2 = process.env.XDG_CONFIG_HOME ||
|
|
42217
|
-
return
|
|
42344
|
+
const xdgConfig2 = process.env.XDG_CONFIG_HOME || join31(homedir11(), ".config");
|
|
42345
|
+
return join31(xdgConfig2, "opencode");
|
|
42218
42346
|
}
|
|
42219
42347
|
function getOpencodeConfigPath() {
|
|
42220
42348
|
const configDir = getOpencodeConfigDir();
|
|
42221
|
-
const jsoncPath =
|
|
42222
|
-
const jsonPath =
|
|
42349
|
+
const jsoncPath = join31(configDir, OPENCODE_JSONC_FILENAME);
|
|
42350
|
+
const jsonPath = join31(configDir, OPENCODE_JSON_FILENAME);
|
|
42223
42351
|
if (existsSync9(jsoncPath)) {
|
|
42224
42352
|
return jsoncPath;
|
|
42225
42353
|
}
|
|
@@ -42478,7 +42606,7 @@ async function select3(items, options) {
|
|
|
42478
42606
|
}
|
|
42479
42607
|
renderedLines = linesWritten;
|
|
42480
42608
|
};
|
|
42481
|
-
return new Promise((
|
|
42609
|
+
return new Promise((resolve27) => {
|
|
42482
42610
|
const wasRaw = stdin.isRaw ?? false;
|
|
42483
42611
|
const cleanup2 = () => {
|
|
42484
42612
|
if (isCleanedUp) return;
|
|
@@ -42499,11 +42627,11 @@ async function select3(items, options) {
|
|
|
42499
42627
|
};
|
|
42500
42628
|
const onSignal = () => {
|
|
42501
42629
|
cleanup2();
|
|
42502
|
-
|
|
42630
|
+
resolve27(null);
|
|
42503
42631
|
};
|
|
42504
42632
|
const finishWithValue = (value) => {
|
|
42505
42633
|
cleanup2();
|
|
42506
|
-
|
|
42634
|
+
resolve27(value);
|
|
42507
42635
|
};
|
|
42508
42636
|
const findNextSelectable = (from, direction) => {
|
|
42509
42637
|
if (items.length === 0) return from;
|
|
@@ -42549,7 +42677,7 @@ async function select3(items, options) {
|
|
|
42549
42677
|
stdin.setRawMode(true);
|
|
42550
42678
|
} catch {
|
|
42551
42679
|
cleanup2();
|
|
42552
|
-
|
|
42680
|
+
resolve27(null);
|
|
42553
42681
|
return;
|
|
42554
42682
|
}
|
|
42555
42683
|
stdin.resume();
|
|
@@ -43239,10 +43367,10 @@ function toV1AuthCallbackResult(result) {
|
|
|
43239
43367
|
};
|
|
43240
43368
|
}
|
|
43241
43369
|
var MAX_OAUTH_ACCOUNTS = 10;
|
|
43242
|
-
var
|
|
43243
|
-
async function reportPersistenceFailure(error, client,
|
|
43370
|
+
var log9 = createLogger4("oauth-methods");
|
|
43371
|
+
async function reportPersistenceFailure(error, client, log17) {
|
|
43244
43372
|
const message = error instanceof AccountStorageUnreadableError ? `Account storage at ${error.details.path} is unreadable (${error.details.reason}: ${error.details.detail}).${error.details.backupPath ? ` A backup was written to ${error.details.backupPath}. Repair or remove the existing file before retrying.` : " A backup could not be written; repair or remove the existing file before retrying."}` : error instanceof Error ? error.message : String(error);
|
|
43245
|
-
|
|
43373
|
+
log17.error("OAuth login persistence failed; aborting login", {
|
|
43246
43374
|
error: message
|
|
43247
43375
|
});
|
|
43248
43376
|
try {
|
|
@@ -44079,7 +44207,7 @@ ${verifyUrl}
|
|
|
44079
44207
|
}
|
|
44080
44208
|
});
|
|
44081
44209
|
} catch (storeError) {
|
|
44082
|
-
|
|
44210
|
+
log9.error(
|
|
44083
44211
|
"Failed to update stored Antigravity OAuth credentials",
|
|
44084
44212
|
{ error: String(storeError) }
|
|
44085
44213
|
);
|
|
@@ -44104,7 +44232,7 @@ ${verifyUrl}
|
|
|
44104
44232
|
}
|
|
44105
44233
|
});
|
|
44106
44234
|
} catch (storeError) {
|
|
44107
|
-
|
|
44235
|
+
log9.error(
|
|
44108
44236
|
"Failed to clear stored Antigravity OAuth credentials",
|
|
44109
44237
|
{ error: String(storeError) }
|
|
44110
44238
|
);
|
|
@@ -44145,7 +44273,7 @@ Re-authenticating ${refreshEmail || "account"}...
|
|
|
44145
44273
|
}
|
|
44146
44274
|
});
|
|
44147
44275
|
} catch (storeError) {
|
|
44148
|
-
|
|
44276
|
+
log9.error(
|
|
44149
44277
|
"Failed to clear stored Antigravity OAuth credentials",
|
|
44150
44278
|
{ error: String(storeError) }
|
|
44151
44279
|
);
|
|
@@ -44484,7 +44612,7 @@ ${authorization2.url}
|
|
|
44484
44612
|
return await reportPersistenceFailure(
|
|
44485
44613
|
persistError,
|
|
44486
44614
|
client,
|
|
44487
|
-
|
|
44615
|
+
log9
|
|
44488
44616
|
);
|
|
44489
44617
|
}
|
|
44490
44618
|
const newTotal = existingCount + 1;
|
|
@@ -44528,7 +44656,7 @@ ${authorization2.url}
|
|
|
44528
44656
|
try {
|
|
44529
44657
|
await persistAccountPool2([result], false);
|
|
44530
44658
|
} catch (persistError) {
|
|
44531
|
-
return await reportPersistenceFailure(persistError, client,
|
|
44659
|
+
return await reportPersistenceFailure(persistError, client, log9);
|
|
44532
44660
|
}
|
|
44533
44661
|
const newTotal = existingCount + 1;
|
|
44534
44662
|
const toastMessage = existingCount > 0 ? `Added account${result.email ? ` (${result.email})` : ""} - ${newTotal} total` : `Authenticated${result.email ? ` (${result.email})` : ""}`;
|
|
@@ -44691,7 +44819,7 @@ init_logger4();
|
|
|
44691
44819
|
|
|
44692
44820
|
// src/plugin/refresh-queue.ts
|
|
44693
44821
|
init_logger4();
|
|
44694
|
-
var
|
|
44822
|
+
var log10 = createLogger4("refresh-queue");
|
|
44695
44823
|
var DEFAULT_PROACTIVE_REFRESH_CONFIG = {
|
|
44696
44824
|
enabled: true,
|
|
44697
44825
|
bufferSeconds: 1800,
|
|
@@ -44731,7 +44859,7 @@ var ProactiveRefreshQueue = class {
|
|
|
44731
44859
|
"ProactiveRefreshQueue needs a host client or explicit dependencies"
|
|
44732
44860
|
);
|
|
44733
44861
|
}
|
|
44734
|
-
this.log =
|
|
44862
|
+
this.log = log10;
|
|
44735
44863
|
this.refresh = (auth) => refreshAccessToken(auth, client, providerId);
|
|
44736
44864
|
}
|
|
44737
44865
|
this.config = {
|
|
@@ -44961,7 +45089,7 @@ import {
|
|
|
44961
45089
|
writeFileSync as writeFileSync5
|
|
44962
45090
|
} from "node:fs";
|
|
44963
45091
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
44964
|
-
import { dirname as dirname24, join as
|
|
45092
|
+
import { dirname as dirname24, join as join32 } from "node:path";
|
|
44965
45093
|
function getSignatureCacheFilePath() {
|
|
44966
45094
|
return stateHomeSignatureCacheFile();
|
|
44967
45095
|
}
|
|
@@ -45245,7 +45373,7 @@ var SignatureCache = class {
|
|
|
45245
45373
|
last_write: now
|
|
45246
45374
|
}
|
|
45247
45375
|
};
|
|
45248
|
-
const tmpPath =
|
|
45376
|
+
const tmpPath = join32(
|
|
45249
45377
|
tmpdir5(),
|
|
45250
45378
|
`antigravity-cache-${Date.now()}-${Math.random().toString(36).slice(2)}.tmp`
|
|
45251
45379
|
);
|
|
@@ -45315,7 +45443,7 @@ init_runtime_paths();
|
|
|
45315
45443
|
init_logger4();
|
|
45316
45444
|
import { existsSync as existsSync11, readFileSync as readFileSync11, realpathSync as realpathSync5 } from "node:fs";
|
|
45317
45445
|
import { homedir as homedir12 } from "node:os";
|
|
45318
|
-
import { basename as basename7, dirname as dirname25, join as
|
|
45446
|
+
import { basename as basename7, dirname as dirname25, join as join33, resolve as resolve24 } from "node:path";
|
|
45319
45447
|
|
|
45320
45448
|
// src/plugin/config/schema.ts
|
|
45321
45449
|
import { z } from "zod";
|
|
@@ -45810,16 +45938,16 @@ function getConfigDir2() {
|
|
|
45810
45938
|
if (process.env.OPENCODE_CONFIG_DIR) {
|
|
45811
45939
|
return process.env.OPENCODE_CONFIG_DIR;
|
|
45812
45940
|
}
|
|
45813
|
-
const xdgConfig2 = process.env.XDG_CONFIG_HOME ||
|
|
45814
|
-
return
|
|
45941
|
+
const xdgConfig2 = process.env.XDG_CONFIG_HOME || join33(homedir12(), ".config");
|
|
45942
|
+
return join33(xdgConfig2, "opencode");
|
|
45815
45943
|
}
|
|
45816
45944
|
function getUserConfigPath() {
|
|
45817
|
-
return
|
|
45945
|
+
return join33(getConfigDir2(), "antigravity.json");
|
|
45818
45946
|
}
|
|
45819
45947
|
function getProjectConfigPath(directory) {
|
|
45820
|
-
return
|
|
45948
|
+
return join33(directory, ".opencode", "antigravity.json");
|
|
45821
45949
|
}
|
|
45822
|
-
function loadConfigFile(path5,
|
|
45950
|
+
function loadConfigFile(path5, log17) {
|
|
45823
45951
|
try {
|
|
45824
45952
|
if (!existsSync11(path5)) {
|
|
45825
45953
|
return null;
|
|
@@ -45828,7 +45956,7 @@ function loadConfigFile(path5, log16) {
|
|
|
45828
45956
|
const rawConfig = JSON.parse(content);
|
|
45829
45957
|
const result = AntigravityConfigSchema.partial().safeParse(rawConfig);
|
|
45830
45958
|
if (!result.success) {
|
|
45831
|
-
|
|
45959
|
+
log17.warn("Config validation error", {
|
|
45832
45960
|
path: path5,
|
|
45833
45961
|
issues: result.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join(", ")
|
|
45834
45962
|
});
|
|
@@ -45837,9 +45965,9 @@ function loadConfigFile(path5, log16) {
|
|
|
45837
45965
|
return result.data;
|
|
45838
45966
|
} catch (error) {
|
|
45839
45967
|
if (error instanceof SyntaxError) {
|
|
45840
|
-
|
|
45968
|
+
log17.warn("Invalid JSON in config file", { path: path5, error: error.message });
|
|
45841
45969
|
} else {
|
|
45842
|
-
|
|
45970
|
+
log17.warn("Failed to load config file", { path: path5, error: String(error) });
|
|
45843
45971
|
}
|
|
45844
45972
|
return null;
|
|
45845
45973
|
}
|
|
@@ -45858,27 +45986,27 @@ function mergeConfigs(base, override) {
|
|
|
45858
45986
|
function loadConfig(directory) {
|
|
45859
45987
|
return loadConfigWithLogger(directory, legacyLog);
|
|
45860
45988
|
}
|
|
45861
|
-
function loadConfigWithLogger(directory,
|
|
45989
|
+
function loadConfigWithLogger(directory, log17) {
|
|
45862
45990
|
let config = structuredClone(DEFAULT_CONFIG);
|
|
45863
45991
|
const userConfigPath = getUserConfigPath();
|
|
45864
|
-
const userConfig = loadConfigFile(userConfigPath,
|
|
45992
|
+
const userConfig = loadConfigFile(userConfigPath, log17);
|
|
45865
45993
|
if (userConfig) {
|
|
45866
45994
|
config = mergeConfigs(config, userConfig);
|
|
45867
45995
|
}
|
|
45868
45996
|
const projectConfigPath = getProjectConfigPath(directory);
|
|
45869
|
-
const projectConfig = loadConfigFile(projectConfigPath,
|
|
45997
|
+
const projectConfig = loadConfigFile(projectConfigPath, log17);
|
|
45870
45998
|
if (projectConfig) {
|
|
45871
45999
|
config = mergeConfigs(config, projectConfig);
|
|
45872
46000
|
}
|
|
45873
46001
|
return config;
|
|
45874
46002
|
}
|
|
45875
46003
|
function canonicalizeOwnedPath(path5) {
|
|
45876
|
-
const absolute =
|
|
46004
|
+
const absolute = resolve24(path5);
|
|
45877
46005
|
const missing = [];
|
|
45878
46006
|
let current = absolute;
|
|
45879
46007
|
for (; ; ) {
|
|
45880
46008
|
try {
|
|
45881
|
-
return
|
|
46009
|
+
return join33(realpathSync5(current), ...missing.reverse());
|
|
45882
46010
|
} catch {
|
|
45883
46011
|
const parent = dirname25(current);
|
|
45884
46012
|
if (parent === current) return absolute;
|
|
@@ -46184,9 +46312,9 @@ function clearSignatureCache(sessionId) {
|
|
|
46184
46312
|
// src/plugin/image-saver.ts
|
|
46185
46313
|
import { chmodSync as chmodSync4, existsSync as existsSync12, mkdirSync as mkdirSync6, writeFileSync as writeFileSync6 } from "node:fs";
|
|
46186
46314
|
import { homedir as homedir13 } from "node:os";
|
|
46187
|
-
import { join as
|
|
46315
|
+
import { join as join34 } from "node:path";
|
|
46188
46316
|
function getImageOutputDir(outputDir) {
|
|
46189
|
-
const resolved = outputDir ??
|
|
46317
|
+
const resolved = outputDir ?? join34(homedir13(), ".opencode", "generated-images");
|
|
46190
46318
|
if (!existsSync12(resolved)) {
|
|
46191
46319
|
mkdirSync6(resolved, { recursive: true, mode: 448 });
|
|
46192
46320
|
}
|
|
@@ -46209,7 +46337,7 @@ function generateImageFilename(mimeType) {
|
|
|
46209
46337
|
function saveImageToDisk(base64Data, mimeType, outputDir) {
|
|
46210
46338
|
try {
|
|
46211
46339
|
const resolvedOutputDir = getImageOutputDir(outputDir);
|
|
46212
|
-
const filePath =
|
|
46340
|
+
const filePath = join34(resolvedOutputDir, generateImageFilename(mimeType));
|
|
46213
46341
|
writeFileSync6(filePath, Buffer.from(base64Data, "base64"), { mode: 384 });
|
|
46214
46342
|
chmodSync4(filePath, 384);
|
|
46215
46343
|
return filePath;
|
|
@@ -46650,10 +46778,10 @@ init_logging_utils();
|
|
|
46650
46778
|
import { createHash as createHash17 } from "node:crypto";
|
|
46651
46779
|
import { appendFileSync as appendFileSync4, mkdirSync as mkdirSync7, writeFileSync as writeFileSync7 } from "node:fs";
|
|
46652
46780
|
import { tmpdir as tmpdir6 } from "node:os";
|
|
46653
|
-
import { join as
|
|
46781
|
+
import { join as join35 } from "node:path";
|
|
46654
46782
|
var DUMP_STATUS_TITLE = "## Gemini Dump Status";
|
|
46655
46783
|
var DUMP_DIR_ENV = "OPENCODE_ANTIGRAVITY_GEMINI_DUMP_DIR";
|
|
46656
|
-
var DEFAULT_DUMP_DIR =
|
|
46784
|
+
var DEFAULT_DUMP_DIR = join35(tmpdir6(), "opencode-antigravity-gemini-dumps");
|
|
46657
46785
|
var DUMP_DIR_MODE = 448;
|
|
46658
46786
|
var DUMP_FILE_MODE = 384;
|
|
46659
46787
|
var nextDumpId = 0;
|
|
@@ -46807,7 +46935,7 @@ function writeGeminiDump(input2) {
|
|
|
46807
46935
|
nextDumpId += 1;
|
|
46808
46936
|
const id = `${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}-${String(nextDumpId).padStart(5, "0")}-${input2.streaming ? "stream" : "json"}`;
|
|
46809
46937
|
const dumpDir = getGeminiDumpDirectory();
|
|
46810
|
-
const prefix =
|
|
46938
|
+
const prefix = join35(dumpDir, id);
|
|
46811
46939
|
mkdirSync7(dumpDir, { recursive: true, mode: DUMP_DIR_MODE });
|
|
46812
46940
|
const context = {
|
|
46813
46941
|
id,
|
|
@@ -46898,21 +47026,21 @@ import {
|
|
|
46898
47026
|
unlinkSync as unlinkSync4,
|
|
46899
47027
|
writeFileSync as writeFileSync8
|
|
46900
47028
|
} from "node:fs";
|
|
46901
|
-
import { join as
|
|
47029
|
+
import { join as join37 } from "node:path";
|
|
46902
47030
|
|
|
46903
47031
|
// src/plugin/recovery/constants.ts
|
|
46904
47032
|
import { homedir as homedir14 } from "node:os";
|
|
46905
|
-
import { join as
|
|
47033
|
+
import { join as join36 } from "node:path";
|
|
46906
47034
|
function getXdgData() {
|
|
46907
47035
|
const platform = process.platform;
|
|
46908
47036
|
if (platform === "win32") {
|
|
46909
|
-
return process.env.APPDATA ||
|
|
47037
|
+
return process.env.APPDATA || join36(homedir14(), "AppData", "Roaming");
|
|
46910
47038
|
}
|
|
46911
|
-
return process.env.XDG_DATA_HOME ||
|
|
47039
|
+
return process.env.XDG_DATA_HOME || join36(homedir14(), ".local", "share");
|
|
46912
47040
|
}
|
|
46913
|
-
var OPENCODE_STORAGE =
|
|
46914
|
-
var MESSAGE_STORAGE =
|
|
46915
|
-
var PART_STORAGE =
|
|
47041
|
+
var OPENCODE_STORAGE = join36(getXdgData(), "opencode", "storage");
|
|
47042
|
+
var MESSAGE_STORAGE = join36(OPENCODE_STORAGE, "message");
|
|
47043
|
+
var PART_STORAGE = join36(OPENCODE_STORAGE, "part");
|
|
46916
47044
|
var THINKING_TYPES = /* @__PURE__ */ new Set([
|
|
46917
47045
|
"thinking",
|
|
46918
47046
|
"redacted_thinking",
|
|
@@ -46922,13 +47050,13 @@ var THINKING_TYPES = /* @__PURE__ */ new Set([
|
|
|
46922
47050
|
// src/plugin/recovery/storage.ts
|
|
46923
47051
|
function getMessageDir(sessionID) {
|
|
46924
47052
|
if (!existsSync13(MESSAGE_STORAGE)) return "";
|
|
46925
|
-
const directPath =
|
|
47053
|
+
const directPath = join37(MESSAGE_STORAGE, sessionID);
|
|
46926
47054
|
if (existsSync13(directPath)) {
|
|
46927
47055
|
return directPath;
|
|
46928
47056
|
}
|
|
46929
47057
|
try {
|
|
46930
47058
|
for (const dir of readdirSync2(MESSAGE_STORAGE)) {
|
|
46931
|
-
const sessionPath =
|
|
47059
|
+
const sessionPath = join37(MESSAGE_STORAGE, dir, sessionID);
|
|
46932
47060
|
if (existsSync13(sessionPath)) {
|
|
46933
47061
|
return sessionPath;
|
|
46934
47062
|
}
|
|
@@ -46945,7 +47073,7 @@ function readMessages(sessionID) {
|
|
|
46945
47073
|
for (const file of readdirSync2(messageDir)) {
|
|
46946
47074
|
if (!file.endsWith(".json")) continue;
|
|
46947
47075
|
try {
|
|
46948
|
-
const content = readFileSync12(
|
|
47076
|
+
const content = readFileSync12(join37(messageDir, file), "utf-8");
|
|
46949
47077
|
messages.push(JSON.parse(content));
|
|
46950
47078
|
} catch {
|
|
46951
47079
|
}
|
|
@@ -46961,14 +47089,14 @@ function readMessages(sessionID) {
|
|
|
46961
47089
|
});
|
|
46962
47090
|
}
|
|
46963
47091
|
function readParts(messageID) {
|
|
46964
|
-
const partDir =
|
|
47092
|
+
const partDir = join37(PART_STORAGE, messageID);
|
|
46965
47093
|
if (!existsSync13(partDir)) return [];
|
|
46966
47094
|
const parts = [];
|
|
46967
47095
|
try {
|
|
46968
47096
|
for (const file of readdirSync2(partDir)) {
|
|
46969
47097
|
if (!file.endsWith(".json")) continue;
|
|
46970
47098
|
try {
|
|
46971
|
-
const content = readFileSync12(
|
|
47099
|
+
const content = readFileSync12(join37(partDir, file), "utf-8");
|
|
46972
47100
|
parts.push(JSON.parse(content));
|
|
46973
47101
|
} catch {
|
|
46974
47102
|
}
|
|
@@ -47010,7 +47138,7 @@ function findMessagesWithOrphanThinking(sessionID) {
|
|
|
47010
47138
|
return result;
|
|
47011
47139
|
}
|
|
47012
47140
|
function prependThinkingPart(sessionID, messageID) {
|
|
47013
|
-
const partDir =
|
|
47141
|
+
const partDir = join37(PART_STORAGE, messageID);
|
|
47014
47142
|
try {
|
|
47015
47143
|
if (!existsSync13(partDir)) {
|
|
47016
47144
|
mkdirSync8(partDir, { recursive: true });
|
|
@@ -47025,7 +47153,7 @@ function prependThinkingPart(sessionID, messageID) {
|
|
|
47025
47153
|
synthetic: true
|
|
47026
47154
|
};
|
|
47027
47155
|
writeFileSync8(
|
|
47028
|
-
|
|
47156
|
+
join37(partDir, `${partId}.json`),
|
|
47029
47157
|
JSON.stringify(part, null, 2)
|
|
47030
47158
|
);
|
|
47031
47159
|
return true;
|
|
@@ -47034,14 +47162,14 @@ function prependThinkingPart(sessionID, messageID) {
|
|
|
47034
47162
|
}
|
|
47035
47163
|
}
|
|
47036
47164
|
function stripThinkingParts(messageID) {
|
|
47037
|
-
const partDir =
|
|
47165
|
+
const partDir = join37(PART_STORAGE, messageID);
|
|
47038
47166
|
if (!existsSync13(partDir)) return false;
|
|
47039
47167
|
let anyRemoved = false;
|
|
47040
47168
|
try {
|
|
47041
47169
|
for (const file of readdirSync2(partDir)) {
|
|
47042
47170
|
if (!file.endsWith(".json")) continue;
|
|
47043
47171
|
try {
|
|
47044
|
-
const filePath =
|
|
47172
|
+
const filePath = join37(partDir, file);
|
|
47045
47173
|
const content = readFileSync12(filePath, "utf-8");
|
|
47046
47174
|
const part = JSON.parse(content);
|
|
47047
47175
|
if (THINKING_TYPES.has(part.type)) {
|
|
@@ -47275,8 +47403,8 @@ function createSessionRecoveryHook(ctx, config) {
|
|
|
47275
47403
|
if (!sessionID) return false;
|
|
47276
47404
|
let assistantMsgID = info.id;
|
|
47277
47405
|
let msgs;
|
|
47278
|
-
const
|
|
47279
|
-
|
|
47406
|
+
const log17 = createLogger4("session-recovery");
|
|
47407
|
+
log17.debug("Recovery attempt started", {
|
|
47280
47408
|
errorType,
|
|
47281
47409
|
sessionID,
|
|
47282
47410
|
providedMsgID: assistantMsgID ?? "none"
|
|
@@ -47296,7 +47424,7 @@ function createSessionRecoveryHook(ctx, config) {
|
|
|
47296
47424
|
const m = msgs[i];
|
|
47297
47425
|
if (m && m.info?.role === "assistant" && m.info?.id) {
|
|
47298
47426
|
assistantMsgID = m.info.id;
|
|
47299
|
-
|
|
47427
|
+
log17.debug("Found assistant message ID from session messages", {
|
|
47300
47428
|
msgID: assistantMsgID,
|
|
47301
47429
|
msgIndex: i
|
|
47302
47430
|
});
|
|
@@ -47305,7 +47433,7 @@ function createSessionRecoveryHook(ctx, config) {
|
|
|
47305
47433
|
}
|
|
47306
47434
|
}
|
|
47307
47435
|
if (!assistantMsgID) {
|
|
47308
|
-
|
|
47436
|
+
log17.debug("No assistant message ID found, cannot recover");
|
|
47309
47437
|
return false;
|
|
47310
47438
|
}
|
|
47311
47439
|
if (processingErrors.has(assistantMsgID)) return false;
|
|
@@ -47349,7 +47477,7 @@ function createSessionRecoveryHook(ctx, config) {
|
|
|
47349
47477
|
}
|
|
47350
47478
|
return success;
|
|
47351
47479
|
} catch (err) {
|
|
47352
|
-
|
|
47480
|
+
log17.error("Recovery failed", { error: String(err) });
|
|
47353
47481
|
return false;
|
|
47354
47482
|
} finally {
|
|
47355
47483
|
processingErrors.delete(assistantMsgID);
|
|
@@ -47369,7 +47497,7 @@ function createSessionRecoveryHook(ctx, config) {
|
|
|
47369
47497
|
// src/plugin/request-helpers.ts
|
|
47370
47498
|
init_dist();
|
|
47371
47499
|
init_logger4();
|
|
47372
|
-
var
|
|
47500
|
+
var log11 = createLogger4("request-helpers");
|
|
47373
47501
|
var ANTIGRAVITY_PREVIEW_LINK = "https://goo.gle/enable-preview-features";
|
|
47374
47502
|
function appendDescriptionHint(schema, hint) {
|
|
47375
47503
|
if (!schema || typeof schema !== "object") {
|
|
@@ -47794,7 +47922,7 @@ function filterContentArray(contentArray, sessionId, getCachedSignatureFn, isCla
|
|
|
47794
47922
|
}
|
|
47795
47923
|
const existingSignature = item.signature || item.thoughtSignature;
|
|
47796
47924
|
const signatureInfo = existingSignature ? `foreign signature (${String(existingSignature).length} chars)` : "no signature";
|
|
47797
|
-
|
|
47925
|
+
log11.debug(
|
|
47798
47926
|
`Injecting plain text sentinel for last-message thinking block with ${signatureInfo}`
|
|
47799
47927
|
);
|
|
47800
47928
|
const sentinel2 = { text: "." };
|
|
@@ -48306,7 +48434,7 @@ function recursivelyParseJsonStrings(obj, skipParseKeys = SKIP_PARSE_KEYS, curre
|
|
|
48306
48434
|
if (lastBracket > 0) {
|
|
48307
48435
|
const cleaned = stripped.slice(0, lastBracket + 1);
|
|
48308
48436
|
const parsed = JSON.parse(cleaned);
|
|
48309
|
-
|
|
48437
|
+
log11.debug("Auto-corrected malformed JSON array", {
|
|
48310
48438
|
truncatedChars: stripped.length - cleaned.length
|
|
48311
48439
|
});
|
|
48312
48440
|
return recursivelyParseJsonStrings(parsed);
|
|
@@ -48320,7 +48448,7 @@ function recursivelyParseJsonStrings(obj, skipParseKeys = SKIP_PARSE_KEYS, curre
|
|
|
48320
48448
|
if (lastBrace > 0) {
|
|
48321
48449
|
const cleaned = stripped.slice(0, lastBrace + 1);
|
|
48322
48450
|
const parsed = JSON.parse(cleaned);
|
|
48323
|
-
|
|
48451
|
+
log11.debug("Auto-corrected malformed JSON object", {
|
|
48324
48452
|
truncatedChars: stripped.length - cleaned.length
|
|
48325
48453
|
});
|
|
48326
48454
|
return recursivelyParseJsonStrings(parsed);
|
|
@@ -48420,7 +48548,7 @@ function fixToolResponseGrouping(contents) {
|
|
|
48420
48548
|
if (orphanResp.functionResponse.name === "unknown_function" && expectedName) {
|
|
48421
48549
|
orphanResp.functionResponse.name = expectedName;
|
|
48422
48550
|
}
|
|
48423
|
-
|
|
48551
|
+
log11.debug("Auto-repaired tool ID mismatch", {
|
|
48424
48552
|
mappedFrom: matchedId,
|
|
48425
48553
|
mappedTo: expectedId,
|
|
48426
48554
|
functionName: expectedName
|
|
@@ -48440,7 +48568,7 @@ function fixToolResponseGrouping(contents) {
|
|
|
48440
48568
|
id: expectedId
|
|
48441
48569
|
}
|
|
48442
48570
|
};
|
|
48443
|
-
|
|
48571
|
+
log11.debug("Created placeholder response for missing tool", {
|
|
48444
48572
|
id: expectedId,
|
|
48445
48573
|
name: expectedName
|
|
48446
48574
|
});
|
|
@@ -48758,7 +48886,7 @@ function applyToolPairingFixes(payload, isClaude) {
|
|
|
48758
48886
|
);
|
|
48759
48887
|
payload.contents = fixToolResponseGrouping(contentsWithMatchedIds);
|
|
48760
48888
|
contentsFixed = true;
|
|
48761
|
-
|
|
48889
|
+
log11.debug("Applied tool pairing fixes to contents[]", {
|
|
48762
48890
|
originalLength: payload.contents.length
|
|
48763
48891
|
});
|
|
48764
48892
|
}
|
|
@@ -48767,7 +48895,7 @@ function applyToolPairingFixes(payload, isClaude) {
|
|
|
48767
48895
|
payload.messages
|
|
48768
48896
|
);
|
|
48769
48897
|
messagesFixed = true;
|
|
48770
|
-
|
|
48898
|
+
log11.debug("Applied tool pairing fixes to messages[]", {
|
|
48771
48899
|
originalLength: payload.messages.length
|
|
48772
48900
|
});
|
|
48773
48901
|
}
|
|
@@ -49006,7 +49134,7 @@ init_dist();
|
|
|
49006
49134
|
init_dist();
|
|
49007
49135
|
|
|
49008
49136
|
// src/plugin/request.ts
|
|
49009
|
-
var
|
|
49137
|
+
var log12 = createLogger4("request");
|
|
49010
49138
|
var PLUGIN_SESSION_ID = `-${crypto2.randomUUID()}`;
|
|
49011
49139
|
var DEFAULT_AGY_REQUEST_SESSION = createAgyRequestSessionContext("");
|
|
49012
49140
|
var sessionDisplayedThinkingHashes = /* @__PURE__ */ new Set();
|
|
@@ -49805,7 +49933,7 @@ var openCode1WireLocation = {
|
|
|
49805
49933
|
logAntigravityDebugResponse: (context, response, meta) => logAntigravityDebugResponse(context, response, meta),
|
|
49806
49934
|
logCacheStats: (model, cacheRead, cacheWrite, totalInput) => logCacheStats(model, cacheRead, cacheWrite, totalInput)
|
|
49807
49935
|
},
|
|
49808
|
-
logger:
|
|
49936
|
+
logger: log12,
|
|
49809
49937
|
sessionFingerprint: () => getSessionFingerprint(),
|
|
49810
49938
|
displayedThinkingHashes: sessionDisplayedThinkingHashes,
|
|
49811
49939
|
cacheStats: { last: null }
|
|
@@ -49848,6 +49976,7 @@ function prepareAntigravityRequestIn(wire, input2, init, accessToken, projectId,
|
|
|
49848
49976
|
headers.delete("x-parent-session-id");
|
|
49849
49977
|
headers.delete("x-opencode-session-id");
|
|
49850
49978
|
headers.delete("x-opencode-parent-session-id");
|
|
49979
|
+
headers.delete("x-antigravity-internal-request-purpose");
|
|
49851
49980
|
headers.delete("x-goog-user-project");
|
|
49852
49981
|
headers.delete("X-Goog-Api-Client");
|
|
49853
49982
|
headers.delete("Client-Metadata");
|
|
@@ -50811,10 +50940,10 @@ async function retainResponseLifetime(response, cancellation) {
|
|
|
50811
50940
|
cancellation.release();
|
|
50812
50941
|
throw error;
|
|
50813
50942
|
}
|
|
50814
|
-
let
|
|
50943
|
+
let resolve27 = () => {
|
|
50815
50944
|
};
|
|
50816
50945
|
const settled = new Promise((done) => {
|
|
50817
|
-
|
|
50946
|
+
resolve27 = done;
|
|
50818
50947
|
});
|
|
50819
50948
|
let stopping = false;
|
|
50820
50949
|
let finished = false;
|
|
@@ -50824,7 +50953,7 @@ async function retainResponseLifetime(response, cancellation) {
|
|
|
50824
50953
|
finished = true;
|
|
50825
50954
|
cancellation.signal.removeEventListener("abort", abort);
|
|
50826
50955
|
cancellation.release();
|
|
50827
|
-
|
|
50956
|
+
resolve27();
|
|
50828
50957
|
};
|
|
50829
50958
|
const abort = () => {
|
|
50830
50959
|
if (finished || stopping) return;
|
|
@@ -50893,8 +51022,8 @@ function createAfterHandoff(work, signals, onFailure) {
|
|
|
50893
51022
|
let running = false;
|
|
50894
51023
|
let resolveCompletion = () => {
|
|
50895
51024
|
};
|
|
50896
|
-
const completion = new Promise((
|
|
50897
|
-
resolveCompletion =
|
|
51025
|
+
const completion = new Promise((resolve27) => {
|
|
51026
|
+
resolveCompletion = resolve27;
|
|
50898
51027
|
});
|
|
50899
51028
|
const finish = () => {
|
|
50900
51029
|
if (finished) return;
|
|
@@ -50941,14 +51070,14 @@ function createAfterHandoff(work, signals, onFailure) {
|
|
|
50941
51070
|
};
|
|
50942
51071
|
}
|
|
50943
51072
|
function publishResponse(dispatch) {
|
|
50944
|
-
return new Promise((
|
|
51073
|
+
return new Promise((resolve27, reject) => {
|
|
50945
51074
|
let acknowledge;
|
|
50946
51075
|
void Promise.resolve().then(
|
|
50947
51076
|
() => dispatch((callback) => {
|
|
50948
51077
|
acknowledge = callback;
|
|
50949
51078
|
})
|
|
50950
51079
|
).then((response) => {
|
|
50951
|
-
|
|
51080
|
+
resolve27(response);
|
|
50952
51081
|
acknowledge?.();
|
|
50953
51082
|
}, reject);
|
|
50954
51083
|
});
|
|
@@ -50956,7 +51085,7 @@ function publishResponse(dispatch) {
|
|
|
50956
51085
|
|
|
50957
51086
|
// src/plugin/auth-loader.ts
|
|
50958
51087
|
init_storage();
|
|
50959
|
-
var
|
|
51088
|
+
var log13 = createLogger4("auth-loader");
|
|
50960
51089
|
function refreshTokenIdentity(refreshToken) {
|
|
50961
51090
|
return createHash18("sha256").update(refreshToken).digest("hex").slice(0, 16);
|
|
50962
51091
|
}
|
|
@@ -51103,7 +51232,7 @@ function createAuthLoader({
|
|
|
51103
51232
|
});
|
|
51104
51233
|
refreshQueue = deps.createStoreRefreshQueue(
|
|
51105
51234
|
{
|
|
51106
|
-
logger:
|
|
51235
|
+
logger: log13,
|
|
51107
51236
|
refreshToken: (_auth, account) => credentials.refresh(account)
|
|
51108
51237
|
},
|
|
51109
51238
|
queueConfig
|
|
@@ -51211,7 +51340,7 @@ function createAuthLoader({
|
|
|
51211
51340
|
}
|
|
51212
51341
|
if (opening.status === "ready") {
|
|
51213
51342
|
if (!isOAuthAuth(auth) && !readAuthority) {
|
|
51214
|
-
|
|
51343
|
+
log13.warn(
|
|
51215
51344
|
"The host holds no Antigravity sign-in; the account store is left untouched"
|
|
51216
51345
|
);
|
|
51217
51346
|
return {};
|
|
@@ -51224,7 +51353,7 @@ function createAuthLoader({
|
|
|
51224
51353
|
}
|
|
51225
51354
|
if (!usesPoolFile(opening)) {
|
|
51226
51355
|
const message = opening.status === "refused" || opening.status === "recovery-required" ? opening.message : "The Antigravity account store cannot be opened";
|
|
51227
|
-
|
|
51356
|
+
log13.error("Refusing to start: the account store cannot serve", {
|
|
51228
51357
|
message
|
|
51229
51358
|
});
|
|
51230
51359
|
try {
|
|
@@ -51241,7 +51370,7 @@ function createAuthLoader({
|
|
|
51241
51370
|
storedAccounts = await deps.loadAccounts();
|
|
51242
51371
|
} catch (error) {
|
|
51243
51372
|
if (error instanceof AccountStorageUnreadableError) {
|
|
51244
|
-
|
|
51373
|
+
log13.error("Refusing to start: account storage is unreadable", {
|
|
51245
51374
|
path: error.details.path,
|
|
51246
51375
|
reason: error.details.reason,
|
|
51247
51376
|
backupPath: error.details.backupPath
|
|
@@ -51273,12 +51402,12 @@ function createAuthLoader({
|
|
|
51273
51402
|
expires: auth.expires ?? 0
|
|
51274
51403
|
}
|
|
51275
51404
|
});
|
|
51276
|
-
|
|
51405
|
+
log13.info("Restored Antigravity OAuth auth from account storage", {
|
|
51277
51406
|
reason: drift.reason,
|
|
51278
51407
|
email: drift.account.email
|
|
51279
51408
|
});
|
|
51280
51409
|
} catch (error) {
|
|
51281
|
-
|
|
51410
|
+
log13.warn(
|
|
51282
51411
|
"Failed to restore Antigravity OAuth auth from account storage",
|
|
51283
51412
|
{ error: String(error) }
|
|
51284
51413
|
);
|
|
@@ -52745,15 +52874,15 @@ init_debug();
|
|
|
52745
52874
|
// src/plugin/dependencies.ts
|
|
52746
52875
|
init_dist();
|
|
52747
52876
|
import { homedir as homedir15 } from "node:os";
|
|
52748
|
-
import { join as
|
|
52877
|
+
import { join as join38 } from "node:path";
|
|
52749
52878
|
function defaultFilesystemRoots() {
|
|
52750
|
-
const xdgConfig2 = process.env.XDG_CONFIG_HOME ??
|
|
52751
|
-
const xdgState2 = process.env.XDG_STATE_HOME ??
|
|
52879
|
+
const xdgConfig2 = process.env.XDG_CONFIG_HOME ?? join38(homedir15(), ".config");
|
|
52880
|
+
const xdgState2 = process.env.XDG_STATE_HOME ?? join38(homedir15(), ".local", "state");
|
|
52752
52881
|
return {
|
|
52753
52882
|
projectRoot: process.cwd(),
|
|
52754
|
-
userConfigRoot:
|
|
52755
|
-
sidebarStateRoot:
|
|
52756
|
-
rpcRoot:
|
|
52883
|
+
userConfigRoot: join38(xdgConfig2, "opencode"),
|
|
52884
|
+
sidebarStateRoot: join38(xdgState2, "cortexkit", "antigravity-auth"),
|
|
52885
|
+
rpcRoot: join38(xdgState2, "cortexkit", "antigravity-auth", "rpc")
|
|
52757
52886
|
};
|
|
52758
52887
|
}
|
|
52759
52888
|
function resolvePluginDependencies(overrides = {}) {
|
|
@@ -52782,10 +52911,10 @@ function resolvePluginDependencies(overrides = {}) {
|
|
|
52782
52911
|
}
|
|
52783
52912
|
async function defaultSleep(ms, signal) {
|
|
52784
52913
|
if (ms <= 0) return;
|
|
52785
|
-
await new Promise((
|
|
52914
|
+
await new Promise((resolve27, reject) => {
|
|
52786
52915
|
const timer = setTimeout(() => {
|
|
52787
52916
|
signal?.removeEventListener("abort", onAbort);
|
|
52788
|
-
|
|
52917
|
+
resolve27();
|
|
52789
52918
|
}, ms);
|
|
52790
52919
|
timer.unref?.();
|
|
52791
52920
|
const onAbort = () => {
|
|
@@ -52906,6 +53035,107 @@ init_logger4();
|
|
|
52906
53035
|
// src/plugin/shared/request-services.ts
|
|
52907
53036
|
init_dist();
|
|
52908
53037
|
|
|
53038
|
+
// src/common-auth-embedded/routing-accessor/index.js
|
|
53039
|
+
function isObject2(value) {
|
|
53040
|
+
return typeof value === "object" && value !== null;
|
|
53041
|
+
}
|
|
53042
|
+
function routingHandle(sessionId) {
|
|
53043
|
+
const routing = Reflect.get(globalThis, /* @__PURE__ */ Symbol.for("cortexkit.routing"));
|
|
53044
|
+
if (typeof routing !== "function")
|
|
53045
|
+
return void 0;
|
|
53046
|
+
const handle = routing(sessionId);
|
|
53047
|
+
return isObject2(handle) ? handle : void 0;
|
|
53048
|
+
}
|
|
53049
|
+
function selectionFor(answer, candidates) {
|
|
53050
|
+
if (!isObject2(answer))
|
|
53051
|
+
return void 0;
|
|
53052
|
+
const accountId = answer.account_id;
|
|
53053
|
+
const credentialId = answer.credential_id;
|
|
53054
|
+
if (typeof accountId !== "string")
|
|
53055
|
+
return void 0;
|
|
53056
|
+
if (credentialId !== void 0 && typeof credentialId !== "string") {
|
|
53057
|
+
return void 0;
|
|
53058
|
+
}
|
|
53059
|
+
const candidate = candidates.find((route) => route.accountId === accountId && (credentialId === void 0 || route.credentialId === credentialId));
|
|
53060
|
+
if (!candidate)
|
|
53061
|
+
return void 0;
|
|
53062
|
+
const hold = answer.hold;
|
|
53063
|
+
const retryAfterMs = isObject2(hold) ? hold.retry_after_ms : void 0;
|
|
53064
|
+
if (typeof retryAfterMs === "number" && Number.isFinite(retryAfterMs) && retryAfterMs >= 0) {
|
|
53065
|
+
return { candidate, hold: { retry_after_ms: retryAfterMs } };
|
|
53066
|
+
}
|
|
53067
|
+
return { candidate };
|
|
53068
|
+
}
|
|
53069
|
+
async function askRouting(input2) {
|
|
53070
|
+
let timer;
|
|
53071
|
+
try {
|
|
53072
|
+
const handle = routingHandle(input2.sessionId);
|
|
53073
|
+
if (!handle)
|
|
53074
|
+
return void 0;
|
|
53075
|
+
const accountFor = handle.accountFor;
|
|
53076
|
+
if (typeof accountFor !== "function")
|
|
53077
|
+
return void 0;
|
|
53078
|
+
const requested = input2.deadlineMs ?? 500;
|
|
53079
|
+
const deadlineMs = Number.isNaN(requested) ? 500 : Math.min(2e3, Math.max(1, requested));
|
|
53080
|
+
const expired = new Promise((resolve27) => {
|
|
53081
|
+
timer = setTimeout(() => resolve27(void 0), deadlineMs);
|
|
53082
|
+
timer.unref();
|
|
53083
|
+
});
|
|
53084
|
+
const pending = accountFor.call(handle, { provider: input2.provider, modelId: input2.modelId }, { deadlineMs });
|
|
53085
|
+
if (!isObject2(pending) || typeof pending.then !== "function")
|
|
53086
|
+
return void 0;
|
|
53087
|
+
const answer = await Promise.race([pending, expired]);
|
|
53088
|
+
return selectionFor(answer, input2.candidates);
|
|
53089
|
+
} catch {
|
|
53090
|
+
return void 0;
|
|
53091
|
+
} finally {
|
|
53092
|
+
clearTimeout(timer);
|
|
53093
|
+
}
|
|
53094
|
+
}
|
|
53095
|
+
function reportRouting(input2) {
|
|
53096
|
+
try {
|
|
53097
|
+
const handle = routingHandle(input2.sessionId);
|
|
53098
|
+
if (!handle)
|
|
53099
|
+
return;
|
|
53100
|
+
const report = handle.report;
|
|
53101
|
+
if (typeof report !== "function")
|
|
53102
|
+
return;
|
|
53103
|
+
const identity3 = {
|
|
53104
|
+
account_id: input2.accountId,
|
|
53105
|
+
...input2.credentialId !== void 0 ? { credential_id: input2.credentialId } : {}
|
|
53106
|
+
};
|
|
53107
|
+
let payload;
|
|
53108
|
+
switch (input2.outcome) {
|
|
53109
|
+
case "served":
|
|
53110
|
+
payload = { ...identity3, outcome: "served", headers: input2.headers };
|
|
53111
|
+
break;
|
|
53112
|
+
case "exhausted": {
|
|
53113
|
+
const { window, pool } = input2;
|
|
53114
|
+
if (window !== "5h" && window !== "7d")
|
|
53115
|
+
return;
|
|
53116
|
+
if (pool !== void 0 && (typeof pool !== "string" || pool.length === 0 || pool.includes(":")))
|
|
53117
|
+
return;
|
|
53118
|
+
payload = {
|
|
53119
|
+
...identity3,
|
|
53120
|
+
outcome: "exhausted",
|
|
53121
|
+
window,
|
|
53122
|
+
...pool ? { pool } : {},
|
|
53123
|
+
...input2.resetsAt !== void 0 ? { resets_at: input2.resetsAt } : {}
|
|
53124
|
+
};
|
|
53125
|
+
break;
|
|
53126
|
+
}
|
|
53127
|
+
default:
|
|
53128
|
+
return;
|
|
53129
|
+
}
|
|
53130
|
+
const pending = report.call(handle, payload);
|
|
53131
|
+
if (isObject2(pending) && typeof pending.then === "function") {
|
|
53132
|
+
void Promise.resolve(pending).catch(() => {
|
|
53133
|
+
});
|
|
53134
|
+
}
|
|
53135
|
+
} catch {
|
|
53136
|
+
}
|
|
53137
|
+
}
|
|
53138
|
+
|
|
52909
53139
|
// src/plugin/errors.ts
|
|
52910
53140
|
var AntigravityKillswitchError = class extends Error {
|
|
52911
53141
|
family;
|
|
@@ -53371,7 +53601,7 @@ function throwIfAllKilled(input2) {
|
|
|
53371
53601
|
}
|
|
53372
53602
|
|
|
53373
53603
|
// src/plugin/session-context.ts
|
|
53374
|
-
import { resolve as
|
|
53604
|
+
import { resolve as resolve25 } from "node:path";
|
|
53375
53605
|
import { pathToFileURL } from "node:url";
|
|
53376
53606
|
var FALLBACK_SESSION_KEY = "__default__";
|
|
53377
53607
|
function extractOpenCodeSessionIdentity(headers) {
|
|
@@ -53385,7 +53615,7 @@ var AgySessionRegistry = class {
|
|
|
53385
53615
|
requestSessions;
|
|
53386
53616
|
parentSessionIds = /* @__PURE__ */ new Map();
|
|
53387
53617
|
constructor(directory, options = {}) {
|
|
53388
|
-
const workspaceUri = directory ? pathToFileURL(
|
|
53618
|
+
const workspaceUri = directory ? pathToFileURL(resolve25(directory)).href : "";
|
|
53389
53619
|
this.requestSessions = new AgyRequestSessionStore(workspaceUri, options);
|
|
53390
53620
|
}
|
|
53391
53621
|
getOrCreate(identity3) {
|
|
@@ -53437,6 +53667,190 @@ var AgySessionRegistry = class {
|
|
|
53437
53667
|
}
|
|
53438
53668
|
};
|
|
53439
53669
|
|
|
53670
|
+
// src/plugin/shared/vault-routing.ts
|
|
53671
|
+
function hasVaultRoutingAccessor() {
|
|
53672
|
+
try {
|
|
53673
|
+
return typeof Reflect.get(globalThis, /* @__PURE__ */ Symbol.for("cortexkit.routing")) === "function";
|
|
53674
|
+
} catch {
|
|
53675
|
+
return false;
|
|
53676
|
+
}
|
|
53677
|
+
}
|
|
53678
|
+
function routingQuotaScope(group, window) {
|
|
53679
|
+
const limitWindow = window === "5h" ? "five_hour" : window === "weekly" ? "seven_day" : void 0;
|
|
53680
|
+
return limitWindow ? { pool: group === "non-gemini" ? "3p" : group, limitWindow } : void 0;
|
|
53681
|
+
}
|
|
53682
|
+
function routingExhaustionFields(scope) {
|
|
53683
|
+
return {
|
|
53684
|
+
pool: scope.pool,
|
|
53685
|
+
window: scope.limitWindow === "five_hour" ? "5h" : "7d"
|
|
53686
|
+
};
|
|
53687
|
+
}
|
|
53688
|
+
function reportVaultExhaustion(input2, report = reportRouting) {
|
|
53689
|
+
if (!hasVaultRoutingAccessor() || input2.signal?.aborted || input2.status !== 429 || input2.reason !== "QUOTA_EXHAUSTED" || !Number.isFinite(input2.observedAt) || (input2.observedAt ?? 0) <= 0 || (input2.observedAt ?? Infinity) > Date.now())
|
|
53690
|
+
return;
|
|
53691
|
+
for (const window of input2.quota?.windows ?? []) {
|
|
53692
|
+
if (window.remainingFraction !== 0) continue;
|
|
53693
|
+
const scope = routingQuotaScope(input2.group, window.window);
|
|
53694
|
+
const resetsAt = Date.parse(window.resetTime);
|
|
53695
|
+
if (!scope || !Number.isFinite(resetsAt) || resetsAt <= Date.now()) continue;
|
|
53696
|
+
report({
|
|
53697
|
+
...input2.identity,
|
|
53698
|
+
outcome: "exhausted",
|
|
53699
|
+
...routingExhaustionFields(scope),
|
|
53700
|
+
resetsAt
|
|
53701
|
+
});
|
|
53702
|
+
}
|
|
53703
|
+
}
|
|
53704
|
+
var RATE_LIMIT_HEADERS = [
|
|
53705
|
+
"retry-after",
|
|
53706
|
+
"retry-after-ms",
|
|
53707
|
+
"ratelimit-limit",
|
|
53708
|
+
"ratelimit-remaining",
|
|
53709
|
+
"ratelimit-reset",
|
|
53710
|
+
"ratelimit-policy",
|
|
53711
|
+
"x-ratelimit-limit",
|
|
53712
|
+
"x-ratelimit-remaining",
|
|
53713
|
+
"x-ratelimit-reset",
|
|
53714
|
+
"x-ratelimit-limit-requests",
|
|
53715
|
+
"x-ratelimit-remaining-requests",
|
|
53716
|
+
"x-ratelimit-reset-requests",
|
|
53717
|
+
"x-ratelimit-limit-tokens",
|
|
53718
|
+
"x-ratelimit-remaining-tokens",
|
|
53719
|
+
"x-ratelimit-reset-tokens"
|
|
53720
|
+
];
|
|
53721
|
+
function streamFailure(value) {
|
|
53722
|
+
if (!value || typeof value !== "object") return false;
|
|
53723
|
+
if (Array.isArray(value)) return value.some(streamFailure);
|
|
53724
|
+
const event = value;
|
|
53725
|
+
return event.error != null || event.type === "error" || event.type === "response.failed" || event.status === "failed" || streamFailure(event.response);
|
|
53726
|
+
}
|
|
53727
|
+
function observeVaultUpstream(response, signal) {
|
|
53728
|
+
if (!hasVaultRoutingAccessor() || !response.ok || signal?.aborted)
|
|
53729
|
+
return void 0;
|
|
53730
|
+
let completed = false;
|
|
53731
|
+
return {
|
|
53732
|
+
response: observeBody(response, () => {
|
|
53733
|
+
completed = !signal?.aborted;
|
|
53734
|
+
}),
|
|
53735
|
+
completedSuccessfully: () => completed
|
|
53736
|
+
};
|
|
53737
|
+
}
|
|
53738
|
+
function observeVaultServed(identity3, response, signal, upstream) {
|
|
53739
|
+
if (!hasVaultRoutingAccessor() || !response.ok || signal?.aborted)
|
|
53740
|
+
return response;
|
|
53741
|
+
const report = () => {
|
|
53742
|
+
if (signal?.aborted || upstream && !upstream.completedSuccessfully() || !hasVaultRoutingAccessor())
|
|
53743
|
+
return;
|
|
53744
|
+
const headers = {};
|
|
53745
|
+
for (const name of RATE_LIMIT_HEADERS) {
|
|
53746
|
+
const value = response.headers.get(name);
|
|
53747
|
+
if (value !== null) headers[name] = value;
|
|
53748
|
+
}
|
|
53749
|
+
reportRouting({ ...identity3, outcome: "served", headers });
|
|
53750
|
+
};
|
|
53751
|
+
return observeBody(response, report);
|
|
53752
|
+
}
|
|
53753
|
+
function observeBody(response, complete) {
|
|
53754
|
+
if (!response.body) {
|
|
53755
|
+
complete();
|
|
53756
|
+
return response;
|
|
53757
|
+
}
|
|
53758
|
+
const sse = response.headers.get("content-type")?.includes("text/event-stream");
|
|
53759
|
+
const reader = response.body.getReader();
|
|
53760
|
+
const decoder = new TextDecoder();
|
|
53761
|
+
let pending = "";
|
|
53762
|
+
let failed = false;
|
|
53763
|
+
const inspect = (line) => {
|
|
53764
|
+
if (line.length > 1024 * 1024) {
|
|
53765
|
+
failed = true;
|
|
53766
|
+
return;
|
|
53767
|
+
}
|
|
53768
|
+
if (line.startsWith("event:") && line.slice(6).trim() === "error")
|
|
53769
|
+
failed = true;
|
|
53770
|
+
if (!line.startsWith("data:") || !/"(?:error|response.failed|failed)"/.test(line))
|
|
53771
|
+
return;
|
|
53772
|
+
try {
|
|
53773
|
+
failed ||= streamFailure(JSON.parse(line.slice(5)));
|
|
53774
|
+
} catch {
|
|
53775
|
+
failed = true;
|
|
53776
|
+
}
|
|
53777
|
+
};
|
|
53778
|
+
const body = new ReadableStream(
|
|
53779
|
+
{
|
|
53780
|
+
async pull(controller) {
|
|
53781
|
+
try {
|
|
53782
|
+
const chunk = await reader.read();
|
|
53783
|
+
if (chunk.done) {
|
|
53784
|
+
if (sse) inspect(pending + decoder.decode());
|
|
53785
|
+
else if (/"(?:error|response.failed|failed)"/.test(pending)) {
|
|
53786
|
+
try {
|
|
53787
|
+
failed ||= streamFailure(JSON.parse(pending + decoder.decode()));
|
|
53788
|
+
} catch {
|
|
53789
|
+
failed = true;
|
|
53790
|
+
}
|
|
53791
|
+
}
|
|
53792
|
+
if (!failed) complete();
|
|
53793
|
+
controller.close();
|
|
53794
|
+
reader.releaseLock();
|
|
53795
|
+
return;
|
|
53796
|
+
}
|
|
53797
|
+
if (!failed) {
|
|
53798
|
+
pending += decoder.decode(chunk.value, { stream: true });
|
|
53799
|
+
if (sse) {
|
|
53800
|
+
let newline = pending.indexOf("\n");
|
|
53801
|
+
while (newline >= 0) {
|
|
53802
|
+
inspect(pending.slice(0, newline));
|
|
53803
|
+
pending = pending.slice(newline + 1);
|
|
53804
|
+
newline = pending.indexOf("\n");
|
|
53805
|
+
}
|
|
53806
|
+
}
|
|
53807
|
+
if (pending.length > 1024 * 1024) {
|
|
53808
|
+
failed = true;
|
|
53809
|
+
pending = "";
|
|
53810
|
+
}
|
|
53811
|
+
}
|
|
53812
|
+
controller.enqueue(chunk.value);
|
|
53813
|
+
} catch (error) {
|
|
53814
|
+
failed = true;
|
|
53815
|
+
controller.error(error);
|
|
53816
|
+
reader.releaseLock();
|
|
53817
|
+
}
|
|
53818
|
+
},
|
|
53819
|
+
async cancel(reason) {
|
|
53820
|
+
failed = true;
|
|
53821
|
+
try {
|
|
53822
|
+
await reader.cancel(reason);
|
|
53823
|
+
} finally {
|
|
53824
|
+
reader.releaseLock();
|
|
53825
|
+
}
|
|
53826
|
+
}
|
|
53827
|
+
},
|
|
53828
|
+
{ highWaterMark: 0 }
|
|
53829
|
+
);
|
|
53830
|
+
const observed = new Response(body, {
|
|
53831
|
+
status: response.status,
|
|
53832
|
+
statusText: response.statusText,
|
|
53833
|
+
headers: response.headers
|
|
53834
|
+
});
|
|
53835
|
+
Object.defineProperties(observed, {
|
|
53836
|
+
url: { value: response.url },
|
|
53837
|
+
redirected: { value: response.redirected }
|
|
53838
|
+
});
|
|
53839
|
+
return observed;
|
|
53840
|
+
}
|
|
53841
|
+
|
|
53842
|
+
// src/plugin/shared/vault-routing-purpose.ts
|
|
53843
|
+
var VAULT_ROUTING_PURPOSE_HEADER = "x-antigravity-internal-request-purpose";
|
|
53844
|
+
function createVaultRoutingHeaders(providerId) {
|
|
53845
|
+
return async (input2, output2) => {
|
|
53846
|
+
if (input2.model.providerID !== providerId) return;
|
|
53847
|
+
output2.headers[VAULT_ROUTING_PURPOSE_HEADER] = input2.agent === "build" || input2.agent === "plan" ? "primary" : "auxiliary";
|
|
53848
|
+
};
|
|
53849
|
+
}
|
|
53850
|
+
function isPrimaryVaultRequest(kind, headers) {
|
|
53851
|
+
return kind === void 0 ? new Headers(headers).get(VAULT_ROUTING_PURPOSE_HEADER) === "primary" : kind === "primary";
|
|
53852
|
+
}
|
|
53853
|
+
|
|
53440
53854
|
// src/plugin/shared/request-services.ts
|
|
53441
53855
|
var FIRST_RETRY_DELAY_MS = 1e3;
|
|
53442
53856
|
function prepareAgyWireRequest(wire, request) {
|
|
@@ -53533,7 +53947,7 @@ function formatWaitTime(ms) {
|
|
|
53533
53947
|
return remainingMinutes > 0 ? `${hours}h ${remainingMinutes}m` : `${hours}h`;
|
|
53534
53948
|
}
|
|
53535
53949
|
function sleep4(ms, signal) {
|
|
53536
|
-
return new Promise((
|
|
53950
|
+
return new Promise((resolve27, reject) => {
|
|
53537
53951
|
if (signal?.aborted) {
|
|
53538
53952
|
reject(
|
|
53539
53953
|
signal.reason instanceof Error ? signal.reason : new Error("Aborted")
|
|
@@ -53542,7 +53956,7 @@ function sleep4(ms, signal) {
|
|
|
53542
53956
|
}
|
|
53543
53957
|
const timeout = setTimeout(() => {
|
|
53544
53958
|
cleanup2();
|
|
53545
|
-
|
|
53959
|
+
resolve27();
|
|
53546
53960
|
}, ms);
|
|
53547
53961
|
const onAbort = () => {
|
|
53548
53962
|
cleanup2();
|
|
@@ -53557,7 +53971,7 @@ function sleep4(ms, signal) {
|
|
|
53557
53971
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
53558
53972
|
});
|
|
53559
53973
|
}
|
|
53560
|
-
function createLocalQuotaRefresh(accountManager, quotaManager,
|
|
53974
|
+
function createLocalQuotaRefresh(accountManager, quotaManager, log17) {
|
|
53561
53975
|
return async function refreshQuotaAfterSuccess(account, intervalMinutes, signal) {
|
|
53562
53976
|
if (intervalMinutes <= 0) return;
|
|
53563
53977
|
const accountIndex = accountManager.getAccounts().indexOf(account);
|
|
@@ -53588,7 +54002,7 @@ function createLocalQuotaRefresh(accountManager, quotaManager, log16) {
|
|
|
53588
54002
|
accountManager.requestSaveToDisk();
|
|
53589
54003
|
}
|
|
53590
54004
|
} catch (err) {
|
|
53591
|
-
|
|
54005
|
+
log17.debug(
|
|
53592
54006
|
`quota-refresh-failed ${singleAccount ? quotaManager.hashedLogLabel("account", singleAccount) : `idx-${accountIndex}`}`,
|
|
53593
54007
|
{ error: String(err) }
|
|
53594
54008
|
);
|
|
@@ -53606,7 +54020,7 @@ function createRequestExecutor(deps) {
|
|
|
53606
54020
|
wire,
|
|
53607
54021
|
debug,
|
|
53608
54022
|
dump,
|
|
53609
|
-
logger:
|
|
54023
|
+
logger: log17,
|
|
53610
54024
|
trackers,
|
|
53611
54025
|
classifyAccessError,
|
|
53612
54026
|
notify,
|
|
@@ -53625,15 +54039,15 @@ function createRequestExecutor(deps) {
|
|
|
53625
54039
|
const reportVault401 = (admission, status) => {
|
|
53626
54040
|
if (!admission || status !== 401) return;
|
|
53627
54041
|
void Promise.resolve().then(() => admission.report401(status)).catch((error) => {
|
|
53628
|
-
|
|
54042
|
+
log17.debug("send-admission-401-report-failed", { error: String(error) });
|
|
53629
54043
|
});
|
|
53630
54044
|
};
|
|
53631
|
-
const
|
|
54045
|
+
const reportRouting2 = (sessionId, entry) => {
|
|
53632
54046
|
if (!onRouting) return;
|
|
53633
54047
|
try {
|
|
53634
54048
|
onRouting(sessionId, entry);
|
|
53635
54049
|
} catch (error) {
|
|
53636
|
-
|
|
54050
|
+
log17.debug("routing-report-failed", { sessionId, error: String(error) });
|
|
53637
54051
|
}
|
|
53638
54052
|
};
|
|
53639
54053
|
async function execute(input2, init, options, selectedCredentials, selectedProjectIds, deadline, waitPolicy) {
|
|
@@ -53764,7 +54178,7 @@ function createRequestExecutor(deps) {
|
|
|
53764
54178
|
const quietMode = config.quiet_mode;
|
|
53765
54179
|
const toastScope = config.toast_scope;
|
|
53766
54180
|
const showToast = async (message, variant2) => {
|
|
53767
|
-
|
|
54181
|
+
log17.debug("toast", {
|
|
53768
54182
|
message,
|
|
53769
54183
|
variant: variant2,
|
|
53770
54184
|
isChildSession: isChildRequest,
|
|
@@ -53773,7 +54187,7 @@ function createRequestExecutor(deps) {
|
|
|
53773
54187
|
if (quietMode) return;
|
|
53774
54188
|
if (abortSignal?.aborted) return;
|
|
53775
54189
|
if (toastScope === "root_only" && isChildRequest) {
|
|
53776
|
-
|
|
54190
|
+
log17.debug("toast-suppressed-child-session", {
|
|
53777
54191
|
message,
|
|
53778
54192
|
variant: variant2,
|
|
53779
54193
|
parentID: requestSessionIdentity.parentSessionId
|
|
@@ -53799,6 +54213,7 @@ function createRequestExecutor(deps) {
|
|
|
53799
54213
|
const maxWaitMs = (config.max_rate_limit_wait_seconds ?? 300) * 1e3;
|
|
53800
54214
|
let allAccountsBlockedAt;
|
|
53801
54215
|
const modelUnavailableIndexes = /* @__PURE__ */ new Set();
|
|
54216
|
+
let routingPlacementConsidered = false;
|
|
53802
54217
|
while (true) {
|
|
53803
54218
|
await assertAdmission();
|
|
53804
54219
|
checkAborted();
|
|
@@ -53845,7 +54260,7 @@ function createRequestExecutor(deps) {
|
|
|
53845
54260
|
});
|
|
53846
54261
|
} catch (error) {
|
|
53847
54262
|
if (error instanceof AntigravityKillswitchError) {
|
|
53848
|
-
|
|
54263
|
+
log17.warn("killswitch-all-excluded", {
|
|
53849
54264
|
family,
|
|
53850
54265
|
model,
|
|
53851
54266
|
threshold: error.thresholdPercent,
|
|
@@ -53870,7 +54285,7 @@ function createRequestExecutor(deps) {
|
|
|
53870
54285
|
pushDebug(
|
|
53871
54286
|
`model-unavailable: all ${candidates.length} eligible account(s) skipped`
|
|
53872
54287
|
);
|
|
53873
|
-
|
|
54288
|
+
log17.warn("model-unavailable-all-accounts", {
|
|
53874
54289
|
family,
|
|
53875
54290
|
model,
|
|
53876
54291
|
accounts: candidates.length
|
|
@@ -53882,6 +54297,11 @@ function createRequestExecutor(deps) {
|
|
|
53882
54297
|
}
|
|
53883
54298
|
}
|
|
53884
54299
|
const excludedIndexes = modelUnavailableIndexes.size === 0 ? killedIndexes : /* @__PURE__ */ new Set([...killedIndexes ?? [], ...modelUnavailableIndexes]);
|
|
54300
|
+
const routingPresent = credentials.domain === "vault" && hasVaultRoutingAccessor();
|
|
54301
|
+
const firstPlacement = routingPresent && !routingPlacementConsidered && accountSessionIdentity && !accountManager.getCurrentAccountForFamily(
|
|
54302
|
+
family,
|
|
54303
|
+
accountSessionIdentity
|
|
54304
|
+
);
|
|
53885
54305
|
let account = accountManager.getCurrentOrNextForFamily(
|
|
53886
54306
|
family,
|
|
53887
54307
|
model,
|
|
@@ -53892,6 +54312,50 @@ function createRequestExecutor(deps) {
|
|
|
53892
54312
|
accountSessionIdentity,
|
|
53893
54313
|
excludedIndexes
|
|
53894
54314
|
);
|
|
54315
|
+
if (account) {
|
|
54316
|
+
routingPlacementConsidered = true;
|
|
54317
|
+
if (firstPlacement && credentials.domain === "vault" && credentials.routingCandidate && model && isPrimaryVaultRequest(kind, init?.headers)) {
|
|
54318
|
+
const candidates = accountManager.getEnabledAccounts().filter(
|
|
54319
|
+
(row) => !excludedIndexes?.has(row.index) && !accountManager.isRateLimited(row, family, model) && !accountManager.isAccountCoolingDown(row) && !accountManager.isAccountOverSoftQuota(
|
|
54320
|
+
row,
|
|
54321
|
+
family,
|
|
54322
|
+
config.soft_quota_threshold_percent,
|
|
54323
|
+
softQuotaCacheTtlMs,
|
|
54324
|
+
model
|
|
54325
|
+
)
|
|
54326
|
+
).map((row) => ({
|
|
54327
|
+
...credentials.routingCandidate(row),
|
|
54328
|
+
index: row.index
|
|
54329
|
+
}));
|
|
54330
|
+
if (candidates.length > 0) {
|
|
54331
|
+
const answer = await deadline.wait(
|
|
54332
|
+
() => askRouting({
|
|
54333
|
+
sessionId: accountSessionIdentity.id,
|
|
54334
|
+
provider: "antigravity",
|
|
54335
|
+
modelId: model,
|
|
54336
|
+
candidates,
|
|
54337
|
+
deadlineMs: Math.min(500, deadline.remainingMs())
|
|
54338
|
+
})
|
|
54339
|
+
);
|
|
54340
|
+
checkAborted();
|
|
54341
|
+
if (answer && answer.candidate.index !== account.index) {
|
|
54342
|
+
account = accountManager.getCurrentOrNextForFamily(
|
|
54343
|
+
family,
|
|
54344
|
+
model,
|
|
54345
|
+
config.account_selection_strategy,
|
|
54346
|
+
config.pid_offset_enabled,
|
|
54347
|
+
config.soft_quota_threshold_percent,
|
|
54348
|
+
softQuotaCacheTtlMs,
|
|
54349
|
+
accountSessionIdentity,
|
|
54350
|
+
/* @__PURE__ */ new Set([
|
|
54351
|
+
...excludedIndexes ?? [],
|
|
54352
|
+
...accountManager.getAccounts().filter((row) => row.index !== answer.candidate.index).map((row) => row.index)
|
|
54353
|
+
])
|
|
54354
|
+
) ?? account;
|
|
54355
|
+
}
|
|
54356
|
+
}
|
|
54357
|
+
}
|
|
54358
|
+
}
|
|
53895
54359
|
if (account && eligibleIndexes !== null && !eligibleIndexes.has(account.index)) {
|
|
53896
54360
|
pushDebug(
|
|
53897
54361
|
`killswitch-excluded idx=${account.index} (precomputed eligible set)`
|
|
@@ -54060,7 +54524,7 @@ function createRequestExecutor(deps) {
|
|
|
54060
54524
|
await deadline.wait(() => credentials.saveToDisk());
|
|
54061
54525
|
} catch (error) {
|
|
54062
54526
|
checkAborted();
|
|
54063
|
-
|
|
54527
|
+
log17.error("Failed to persist project context", {
|
|
54064
54528
|
error: String(error)
|
|
54065
54529
|
});
|
|
54066
54530
|
}
|
|
@@ -54117,7 +54581,7 @@ function createRequestExecutor(deps) {
|
|
|
54117
54581
|
await deadline.wait(() => credentials.saveToDisk());
|
|
54118
54582
|
} catch (error) {
|
|
54119
54583
|
checkAborted();
|
|
54120
|
-
|
|
54584
|
+
log17.error("Failed to persist refreshed auth", {
|
|
54121
54585
|
error: String(error)
|
|
54122
54586
|
});
|
|
54123
54587
|
}
|
|
@@ -54126,14 +54590,14 @@ function createRequestExecutor(deps) {
|
|
|
54126
54590
|
if (credentials.isInvalidGrant(error)) {
|
|
54127
54591
|
const removed = credentials.removeAccount(account);
|
|
54128
54592
|
if (removed) {
|
|
54129
|
-
|
|
54593
|
+
log17.warn(
|
|
54130
54594
|
"Removed revoked account from pool - reauthenticate via `opencode auth login`"
|
|
54131
54595
|
);
|
|
54132
54596
|
try {
|
|
54133
54597
|
await deadline.wait(() => credentials.saveToDiskReplace());
|
|
54134
54598
|
} catch (persistError) {
|
|
54135
54599
|
checkAborted();
|
|
54136
|
-
|
|
54600
|
+
log17.error("Failed to persist revoked account removal", {
|
|
54137
54601
|
error: String(persistError)
|
|
54138
54602
|
});
|
|
54139
54603
|
}
|
|
@@ -54143,7 +54607,7 @@ function createRequestExecutor(deps) {
|
|
|
54143
54607
|
await deadline.wait(() => credentials.clearStoredAuth());
|
|
54144
54608
|
} catch (storeError) {
|
|
54145
54609
|
checkAborted();
|
|
54146
|
-
|
|
54610
|
+
log17.error(
|
|
54147
54611
|
"Failed to clear stored Antigravity OAuth credentials",
|
|
54148
54612
|
{
|
|
54149
54613
|
error: String(storeError)
|
|
@@ -54537,7 +55001,7 @@ function createRequestExecutor(deps) {
|
|
|
54537
55001
|
);
|
|
54538
55002
|
} catch (error) {
|
|
54539
55003
|
checkAborted();
|
|
54540
|
-
|
|
55004
|
+
log17.debug("send-admission-401-report-failed", {
|
|
54541
55005
|
error: String(error)
|
|
54542
55006
|
});
|
|
54543
55007
|
}
|
|
@@ -54551,7 +55015,7 @@ function createRequestExecutor(deps) {
|
|
|
54551
55015
|
strategy: config.account_selection_strategy,
|
|
54552
55016
|
updatedAt: Date.now()
|
|
54553
55017
|
};
|
|
54554
|
-
|
|
55018
|
+
reportRouting2(sessionKey, routingEntry);
|
|
54555
55019
|
}
|
|
54556
55020
|
if (response.status === 429 || response.status === 503 || response.status === 529) {
|
|
54557
55021
|
if (tokenConsumed) {
|
|
@@ -54586,6 +55050,26 @@ function createRequestExecutor(deps) {
|
|
|
54586
55050
|
reasonInfo.message,
|
|
54587
55051
|
response.status
|
|
54588
55052
|
);
|
|
55053
|
+
if (credentials.domain === "vault" && sendAdmission && sessionKey && hasVaultRoutingAccessor()) {
|
|
55054
|
+
const group = resolveQuotaGroup(
|
|
55055
|
+
family,
|
|
55056
|
+
model,
|
|
55057
|
+
account.cachedQuota
|
|
55058
|
+
);
|
|
55059
|
+
reportVaultExhaustion({
|
|
55060
|
+
identity: {
|
|
55061
|
+
sessionId: sessionKey,
|
|
55062
|
+
accountId: sendAdmission.accountIdentity,
|
|
55063
|
+
credentialId: sendAdmission.credentialId
|
|
55064
|
+
},
|
|
55065
|
+
status: response.status,
|
|
55066
|
+
reason: rateLimitReason,
|
|
55067
|
+
group,
|
|
55068
|
+
quota: account.cachedQuota?.[group],
|
|
55069
|
+
observedAt: account.cachedQuotaUpdatedAt,
|
|
55070
|
+
signal: abortSignal
|
|
55071
|
+
});
|
|
55072
|
+
}
|
|
54589
55073
|
if (rateLimitReason === "MODEL_CAPACITY_EXHAUSTED" || rateLimitReason === "SERVER_ERROR") {
|
|
54590
55074
|
totalCapacityRetries++;
|
|
54591
55075
|
if (isCapacityRetryBudgetExhausted(totalCapacityRetries)) {
|
|
@@ -54754,7 +55238,7 @@ function createRequestExecutor(deps) {
|
|
|
54754
55238
|
debug.logAntigravityDebugResponse(debugContext, response, {
|
|
54755
55239
|
note
|
|
54756
55240
|
});
|
|
54757
|
-
|
|
55241
|
+
log17.info("model-unavailable", {
|
|
54758
55242
|
accountIndex: account.index,
|
|
54759
55243
|
family,
|
|
54760
55244
|
model,
|
|
@@ -54923,9 +55407,10 @@ function createRequestExecutor(deps) {
|
|
|
54923
55407
|
const _emptyAttemptKeyClean = `${prepared.sessionId ?? "none"}:${prepared.effectiveModel ?? "unknown"}`;
|
|
54924
55408
|
retryState.clearEmptyResponseAttempts();
|
|
54925
55409
|
}
|
|
55410
|
+
const routingObservation = credentials.domain === "vault" && sendAdmission && sessionKey && response.ok && hasVaultRoutingAccessor() ? observeVaultUpstream(response, abortSignal) : void 0;
|
|
54926
55411
|
const transformedResponse = await deadline.wait(
|
|
54927
55412
|
() => wire.transformResponse(
|
|
54928
|
-
response,
|
|
55413
|
+
routingObservation?.response ?? response,
|
|
54929
55414
|
prepared.streaming,
|
|
54930
55415
|
debugContext,
|
|
54931
55416
|
prepared.requestedModel,
|
|
@@ -54997,7 +55482,16 @@ function createRequestExecutor(deps) {
|
|
|
54997
55482
|
const refresh = credentials.refreshQuotaAfterSuccess;
|
|
54998
55483
|
waitPolicy.quota = (signal) => refresh(account, config.quota_refresh_interval_minutes, signal);
|
|
54999
55484
|
}
|
|
55000
|
-
return
|
|
55485
|
+
return routingObservation && credentials.domain === "vault" && sendAdmission && sessionKey && hasVaultRoutingAccessor() && response.ok ? observeVaultServed(
|
|
55486
|
+
{
|
|
55487
|
+
sessionId: sessionKey,
|
|
55488
|
+
accountId: sendAdmission.accountIdentity,
|
|
55489
|
+
credentialId: sendAdmission.credentialId
|
|
55490
|
+
},
|
|
55491
|
+
transformedResponse,
|
|
55492
|
+
abortSignal,
|
|
55493
|
+
routingObservation
|
|
55494
|
+
) : transformedResponse;
|
|
55001
55495
|
} catch (error) {
|
|
55002
55496
|
if (error instanceof PreResponseTimeoutError) throw error;
|
|
55003
55497
|
checkAborted();
|
|
@@ -55199,11 +55693,11 @@ function createRequestExecutor(deps) {
|
|
|
55199
55693
|
cancellation.signal,
|
|
55200
55694
|
deps.preResponseClock
|
|
55201
55695
|
);
|
|
55202
|
-
|
|
55696
|
+
log17.debug("pre-response-start", { limitMs: PRE_RESPONSE_DEADLINE_MS });
|
|
55203
55697
|
const handoff = createAfterHandoff(
|
|
55204
55698
|
advisoryWork,
|
|
55205
55699
|
requestedSignal ? [requestedSignal, shutdown.signal] : [shutdown.signal],
|
|
55206
|
-
() =>
|
|
55700
|
+
() => log17.debug("post-response-advisory-work-failed")
|
|
55207
55701
|
);
|
|
55208
55702
|
const waitPolicy = {};
|
|
55209
55703
|
const selectedCredentials = /* @__PURE__ */ new Set();
|
|
@@ -55221,7 +55715,7 @@ function createRequestExecutor(deps) {
|
|
|
55221
55715
|
).catch((error) => {
|
|
55222
55716
|
cancellation.signal.throwIfAborted();
|
|
55223
55717
|
if (error instanceof PreResponseTimeoutError) {
|
|
55224
|
-
|
|
55718
|
+
log17.debug("pre-response-timeout", { reason: error.reason });
|
|
55225
55719
|
return waitPolicy.refusal?.() ?? preResponseTimeoutResponse();
|
|
55226
55720
|
}
|
|
55227
55721
|
throw error;
|
|
@@ -55428,7 +55922,7 @@ function parseDurationToMs(duration) {
|
|
|
55428
55922
|
|
|
55429
55923
|
// src/plugin/fetch-interceptor.ts
|
|
55430
55924
|
init_vault_request_credentials();
|
|
55431
|
-
var
|
|
55925
|
+
var log14 = createLogger4("fetch-interceptor");
|
|
55432
55926
|
var defaultAgyTransport = (url, init, options) => fetchWithAgyCliTransport(url, init, options);
|
|
55433
55927
|
var defaultFetchImpl = (input2, init) => globalThis.fetch(input2, init);
|
|
55434
55928
|
function poolFileCredentials(accountManager, client, providerId) {
|
|
@@ -55481,14 +55975,14 @@ function openCode1EngineCollaborators(common) {
|
|
|
55481
55975
|
// the engine calls.
|
|
55482
55976
|
debug: debug_exports,
|
|
55483
55977
|
dump: { dumpRequest: dumpGeminiRequest },
|
|
55484
|
-
logger:
|
|
55978
|
+
logger: log14,
|
|
55485
55979
|
classifyAccessError: extractAccountAccessErrorDetails,
|
|
55486
55980
|
notify: (message, variant) => client.tui.showToast({ body: { message, variant } }),
|
|
55487
55981
|
onRouting: common.onRouting ?? ((sessionId, entry) => {
|
|
55488
55982
|
void upsertSidebarActiveRouting(sessionId, entry, {
|
|
55489
55983
|
authoritative: true
|
|
55490
55984
|
}).catch((error) => {
|
|
55491
|
-
|
|
55985
|
+
log14.debug("sidebar-routing-upsert-failed", {
|
|
55492
55986
|
sessionId,
|
|
55493
55987
|
error: String(error)
|
|
55494
55988
|
});
|
|
@@ -55514,7 +56008,7 @@ function createFetchInterceptor(context) {
|
|
|
55514
56008
|
const refreshQuotaAfterSuccess = createLocalQuotaRefresh(
|
|
55515
56009
|
accountManager,
|
|
55516
56010
|
quotaManager,
|
|
55517
|
-
|
|
56011
|
+
log14
|
|
55518
56012
|
);
|
|
55519
56013
|
const executor = createRequestExecutor({
|
|
55520
56014
|
assertAdmission: context.assertAdmission,
|
|
@@ -55660,7 +56154,7 @@ init_logger4();
|
|
|
55660
56154
|
// src/plugin/search.ts
|
|
55661
56155
|
import crypto3 from "node:crypto";
|
|
55662
56156
|
init_logger4();
|
|
55663
|
-
var
|
|
56157
|
+
var log15 = createLogger4("search");
|
|
55664
56158
|
var sessionCounter = 0;
|
|
55665
56159
|
var sessionPrefix = `search-${Date.now().toString(36)}`;
|
|
55666
56160
|
function generateRequestId() {
|
|
@@ -55792,7 +56286,7 @@ ${urlList}`;
|
|
|
55792
56286
|
requestType: "agent"
|
|
55793
56287
|
};
|
|
55794
56288
|
const url = `${ANTIGRAVITY_ENDPOINT}/v1internal:generateContent`;
|
|
55795
|
-
|
|
56289
|
+
log15.debug("Executing search", {
|
|
55796
56290
|
query,
|
|
55797
56291
|
urlCount: urls?.length ?? 0,
|
|
55798
56292
|
thinking
|
|
@@ -55815,7 +56309,7 @@ ${urlList}`;
|
|
|
55815
56309
|
);
|
|
55816
56310
|
if (!response.ok) {
|
|
55817
56311
|
const errorText3 = await response.text();
|
|
55818
|
-
|
|
56312
|
+
log15.debug("Search API error", {
|
|
55819
56313
|
status: response.status,
|
|
55820
56314
|
error: errorText3
|
|
55821
56315
|
});
|
|
@@ -55828,14 +56322,14 @@ ${errorText3}
|
|
|
55828
56322
|
Please try again with a different query.`;
|
|
55829
56323
|
}
|
|
55830
56324
|
const data = await response.json();
|
|
55831
|
-
|
|
56325
|
+
log15.debug("Search response received", { hasResponse: !!data.response });
|
|
55832
56326
|
const result = parseSearchResponse(data);
|
|
55833
56327
|
const formatted = formatSearchResult(result);
|
|
55834
|
-
|
|
56328
|
+
log15.debug("Search response formatted", { resultLength: formatted.length });
|
|
55835
56329
|
return formatted;
|
|
55836
56330
|
} catch (error) {
|
|
55837
56331
|
const message = error instanceof Error ? error.message : String(error);
|
|
55838
|
-
|
|
56332
|
+
log15.debug("Search execution error", { error: message });
|
|
55839
56333
|
return `## Search Error
|
|
55840
56334
|
|
|
55841
56335
|
Failed to execute search: ${message}. Please try again with a different query.`;
|
|
@@ -55843,7 +56337,7 @@ Failed to execute search: ${message}. Please try again with a different query.`;
|
|
|
55843
56337
|
}
|
|
55844
56338
|
|
|
55845
56339
|
// src/plugin/google-search-tool.ts
|
|
55846
|
-
var
|
|
56340
|
+
var log16 = createLogger4("plugin");
|
|
55847
56341
|
function createGoogleSearchTool({
|
|
55848
56342
|
getAuth,
|
|
55849
56343
|
client,
|
|
@@ -55865,7 +56359,7 @@ function createGoogleSearchTool({
|
|
|
55865
56359
|
if (mayStartLocalWork && !await mayStartLocalWork()) {
|
|
55866
56360
|
return "Google Search is not available through local credentials while vault custody is active or unreadable.";
|
|
55867
56361
|
}
|
|
55868
|
-
|
|
56362
|
+
log16.debug("Google Search tool called", {
|
|
55869
56363
|
query: args.query,
|
|
55870
56364
|
urlCount: args.urls?.length ?? 0
|
|
55871
56365
|
});
|
|
@@ -56030,8 +56524,8 @@ function createPluginLifecycle(options) {
|
|
|
56030
56524
|
};
|
|
56031
56525
|
let failDisposal = () => {
|
|
56032
56526
|
};
|
|
56033
|
-
disposal = new Promise((
|
|
56034
|
-
finishDisposal =
|
|
56527
|
+
disposal = new Promise((resolve27, reject) => {
|
|
56528
|
+
finishDisposal = resolve27;
|
|
56035
56529
|
failDisposal = reject;
|
|
56036
56530
|
});
|
|
56037
56531
|
void (async () => {
|
|
@@ -56230,7 +56724,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
|
|
|
56230
56724
|
await drainSidebarWrites();
|
|
56231
56725
|
}
|
|
56232
56726
|
});
|
|
56233
|
-
const accountFile =
|
|
56727
|
+
const accountFile = resolve26(accountFileForVault());
|
|
56234
56728
|
const vaultFolder = await prepareVaultFolder({ accountFile });
|
|
56235
56729
|
const unavailableMessage = vaultFolder.refusal?.message ?? VAULT_ACCOUNT_REMEDY;
|
|
56236
56730
|
let vaultQuotaPoller;
|
|
@@ -56453,7 +56947,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
|
|
|
56453
56947
|
lifecycle.register(vaultQuotaPoller, "producer");
|
|
56454
56948
|
}
|
|
56455
56949
|
const operatorSettings = createOperatorSettingsController({
|
|
56456
|
-
projectConfigPath:
|
|
56950
|
+
projectConfigPath: join39(directory, ".opencode", "antigravity.json"),
|
|
56457
56951
|
// getUserConfigPath() already returns the full file path including
|
|
56458
56952
|
// 'antigravity.json' — do NOT join again or the path double-nests
|
|
56459
56953
|
// into <dir>/antigravity.json/antigravity.json.
|
|
@@ -56893,6 +57387,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
|
|
|
56893
57387
|
);
|
|
56894
57388
|
},
|
|
56895
57389
|
"command.execute.before": commandExecuteBefore,
|
|
57390
|
+
"chat.headers": createVaultRoutingHeaders(providerId),
|
|
56896
57391
|
event,
|
|
56897
57392
|
tool: { google_search: googleSearchTool },
|
|
56898
57393
|
auth: {
|