@cortexkit/opencode-antigravity-auth 3.0.13 → 3.0.14
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 +1865 -571
- package/dist/cli.js.map +4 -4
- package/dist/cli.meta.json +291 -52
- package/dist/index.js +2166 -751
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +326 -72
- package/dist/server.js +3898 -2452
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/__fixtures__/runtime-layout-process.d.ts +2 -0
- package/dist/src/__fixtures__/runtime-layout-process.d.ts.map +1 -0
- package/dist/src/__fixtures__/runtime-layout-process.js +88 -0
- package/dist/src/__fixtures__/runtime-layout-process.js.map +1 -0
- package/dist/src/cli.d.ts +17 -6
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/cli.js +26 -9
- package/dist/src/cli.js.map +1 -1
- package/dist/src/common-auth-embedded/claustrum/enrollment.d.ts +9 -0
- package/dist/src/common-auth-embedded/claustrum/enrollment.js +15 -8
- package/dist/src/common-auth-embedded/claustrum/hub.js +86 -42
- package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +16 -3
- package/dist/src/common-auth-embedded/setup/command.js +4 -49
- package/dist/src/common-auth-embedded/setup/flags.d.ts +50 -0
- package/dist/src/common-auth-embedded/setup/flags.js +123 -0
- package/dist/src/common-auth-embedded/setup/index.d.ts +1 -0
- package/dist/src/common-auth-embedded/setup/index.js +1 -0
- package/dist/src/common-auth-embedded/setup/types.d.ts +7 -1
- package/dist/src/common-auth-embedded/source-output.json +47 -31
- package/dist/src/ga/server/auth.d.ts.map +1 -1
- package/dist/src/ga/server/auth.js +7 -2
- package/dist/src/ga/server/auth.js.map +1 -1
- package/dist/src/ga/server/index.d.ts.map +1 -1
- package/dist/src/ga/server/index.js +18 -4
- package/dist/src/ga/server/index.js.map +1 -1
- package/dist/src/plugin/__fixtures__/controlled-timeouts.d.ts +7 -0
- package/dist/src/plugin/__fixtures__/controlled-timeouts.d.ts.map +1 -0
- package/dist/src/plugin/__fixtures__/controlled-timeouts.js +41 -0
- package/dist/src/plugin/__fixtures__/controlled-timeouts.js.map +1 -0
- package/dist/src/plugin/__fixtures__/release-model-ids.d.ts +2 -0
- package/dist/src/plugin/__fixtures__/release-model-ids.d.ts.map +1 -0
- package/dist/src/plugin/__fixtures__/release-model-ids.js +11 -0
- package/dist/src/plugin/__fixtures__/release-model-ids.js.map +1 -0
- package/dist/src/plugin/__fixtures__/verified-store.d.ts +3 -0
- package/dist/src/plugin/__fixtures__/verified-store.d.ts.map +1 -0
- package/dist/src/plugin/__fixtures__/verified-store.js +50 -0
- package/dist/src/plugin/__fixtures__/verified-store.js.map +1 -0
- package/dist/src/plugin/auth-loader.d.ts +7 -1
- package/dist/src/plugin/auth-loader.d.ts.map +1 -1
- package/dist/src/plugin/auth-loader.js +4 -4
- package/dist/src/plugin/auth-loader.js.map +1 -1
- package/dist/src/plugin/cache/signature-cache.d.ts +7 -1
- package/dist/src/plugin/cache/signature-cache.d.ts.map +1 -1
- package/dist/src/plugin/cache/signature-cache.js +10 -13
- package/dist/src/plugin/cache/signature-cache.js.map +1 -1
- package/dist/src/plugin/config/loader.d.ts +2 -1
- package/dist/src/plugin/config/loader.d.ts.map +1 -1
- package/dist/src/plugin/config/loader.js +4 -2
- package/dist/src/plugin/config/loader.js.map +1 -1
- package/dist/src/plugin/config/schema.js +1 -1
- package/dist/src/plugin/debug.d.ts.map +1 -1
- package/dist/src/plugin/debug.js +18 -19
- package/dist/src/plugin/debug.js.map +1 -1
- package/dist/src/plugin/errors.js +1 -1
- package/dist/src/plugin/errors.js.map +1 -1
- package/dist/src/plugin/ga-location-services.d.ts +1 -1
- package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/src/plugin/ga-location-services.js +50 -27
- package/dist/src/plugin/ga-location-services.js.map +1 -1
- package/dist/src/plugin/ga-shared-vault-custody.d.ts +19 -5
- package/dist/src/plugin/ga-shared-vault-custody.d.ts.map +1 -1
- package/dist/src/plugin/ga-shared-vault-custody.js +12 -4
- package/dist/src/plugin/ga-shared-vault-custody.js.map +1 -1
- package/dist/src/plugin/index.d.ts.map +1 -1
- package/dist/src/plugin/index.js +31 -9
- package/dist/src/plugin/index.js.map +1 -1
- package/dist/src/plugin/shared/source-sidebar.d.ts +6 -0
- package/dist/src/plugin/shared/source-sidebar.d.ts.map +1 -1
- package/dist/src/plugin/shared/source-sidebar.js +1 -1
- package/dist/src/plugin/shared/source-sidebar.js.map +1 -1
- package/dist/src/plugin/storage.d.ts +5 -2
- package/dist/src/plugin/storage.d.ts.map +1 -1
- package/dist/src/plugin/storage.js +5 -4
- package/dist/src/plugin/storage.js.map +1 -1
- package/dist/src/plugin/vault-custody.d.ts +29 -8
- package/dist/src/plugin/vault-custody.d.ts.map +1 -1
- package/dist/src/plugin/vault-custody.js +61 -10
- package/dist/src/plugin/vault-custody.js.map +1 -1
- package/dist/src/process-heartbeat.d.ts +22 -2
- package/dist/src/process-heartbeat.d.ts.map +1 -1
- package/dist/src/process-heartbeat.js +47 -10
- package/dist/src/process-heartbeat.js.map +1 -1
- package/dist/src/rpc/rpc-server.d.ts +8 -0
- package/dist/src/rpc/rpc-server.d.ts.map +1 -1
- package/dist/src/rpc/rpc-server.js +26 -1
- package/dist/src/rpc/rpc-server.js.map +1 -1
- package/dist/src/runtime-layout.d.ts +100 -0
- package/dist/src/runtime-layout.d.ts.map +1 -0
- package/dist/src/runtime-layout.js +1242 -0
- package/dist/src/runtime-layout.js.map +1 -0
- package/dist/src/runtime-paths.d.ts +132 -0
- package/dist/src/runtime-paths.d.ts.map +1 -0
- package/dist/src/runtime-paths.js +214 -0
- package/dist/src/runtime-paths.js.map +1 -0
- package/dist/src/setup.d.ts.map +1 -1
- package/dist/src/setup.js +30 -7
- package/dist/src/setup.js.map +1 -1
- package/dist/src/vault-folder.d.ts +38 -0
- package/dist/src/vault-folder.d.ts.map +1 -0
- package/dist/src/vault-folder.js +91 -0
- package/dist/src/vault-folder.js.map +1 -0
- package/dist/src/version-fence.d.ts +54 -0
- package/dist/src/version-fence.d.ts.map +1 -0
- package/dist/src/version-fence.js +254 -0
- package/dist/src/version-fence.js.map +1 -0
- package/dist/tui-build-map.json +1 -1
- package/dist/tui-ga-build-map.json +1 -1
- package/dist/types/src/cli.d.ts +17 -6
- package/dist/types/src/cli.d.ts.map +1 -1
- package/dist/types/src/common-auth-embedded/claustrum/enrollment.d.ts +9 -0
- package/dist/types/src/common-auth-embedded/setup/flags.d.ts +50 -0
- package/dist/types/src/common-auth-embedded/setup/index.d.ts +1 -0
- package/dist/types/src/common-auth-embedded/setup/types.d.ts +7 -1
- package/dist/types/src/ga/server/auth.d.ts.map +1 -1
- package/dist/types/src/ga/server/index.d.ts.map +1 -1
- package/dist/types/src/plugin/auth-loader.d.ts +7 -1
- package/dist/types/src/plugin/auth-loader.d.ts.map +1 -1
- package/dist/types/src/plugin/cache/signature-cache.d.ts +7 -1
- package/dist/types/src/plugin/cache/signature-cache.d.ts.map +1 -1
- package/dist/types/src/plugin/config/loader.d.ts +2 -1
- package/dist/types/src/plugin/config/loader.d.ts.map +1 -1
- package/dist/types/src/plugin/debug.d.ts.map +1 -1
- package/dist/types/src/plugin/ga-location-services.d.ts +1 -1
- package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/types/src/plugin/ga-shared-vault-custody.d.ts +19 -5
- package/dist/types/src/plugin/ga-shared-vault-custody.d.ts.map +1 -1
- package/dist/types/src/plugin/index.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/source-sidebar.d.ts +6 -0
- package/dist/types/src/plugin/shared/source-sidebar.d.ts.map +1 -1
- package/dist/types/src/plugin/storage.d.ts +5 -2
- package/dist/types/src/plugin/storage.d.ts.map +1 -1
- package/dist/types/src/plugin/vault-custody.d.ts +29 -8
- package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
- package/dist/types/src/process-heartbeat.d.ts +22 -2
- package/dist/types/src/process-heartbeat.d.ts.map +1 -1
- package/dist/types/src/rpc/rpc-server.d.ts +8 -0
- package/dist/types/src/rpc/rpc-server.d.ts.map +1 -1
- package/dist/types/src/runtime-layout.d.ts +100 -0
- package/dist/types/src/runtime-layout.d.ts.map +1 -0
- package/dist/types/src/runtime-paths.d.ts +132 -0
- package/dist/types/src/runtime-paths.d.ts.map +1 -0
- package/dist/types/src/setup.d.ts.map +1 -1
- package/dist/types/src/vault-folder.d.ts +38 -0
- package/dist/types/src/vault-folder.d.ts.map +1 -0
- package/dist/types/src/version-fence.d.ts +54 -0
- package/dist/types/src/version-fence.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/common-auth-embedded/claustrum/enrollment.d.ts +9 -0
- package/src/common-auth-embedded/claustrum/enrollment.js +15 -8
- package/src/common-auth-embedded/claustrum/hub.js +86 -42
- package/src/common-auth-embedded/fs/refresh-file-lock.js +16 -3
- package/src/common-auth-embedded/setup/command.js +4 -49
- package/src/common-auth-embedded/setup/flags.d.ts +50 -0
- package/src/common-auth-embedded/setup/flags.js +123 -0
- package/src/common-auth-embedded/setup/index.d.ts +1 -0
- package/src/common-auth-embedded/setup/index.js +1 -0
- package/src/common-auth-embedded/setup/types.d.ts +7 -1
- package/src/common-auth-embedded/source-output.json +47 -31
package/dist/cli.js
CHANGED
|
@@ -1184,8 +1184,8 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
1184
1184
|
let releaseConfirmed = false;
|
|
1185
1185
|
let loss;
|
|
1186
1186
|
let resolveLoss;
|
|
1187
|
-
const lostPromise = new Promise((
|
|
1188
|
-
resolveLoss =
|
|
1187
|
+
const lostPromise = new Promise((resolve20) => {
|
|
1188
|
+
resolveLoss = resolve20;
|
|
1189
1189
|
});
|
|
1190
1190
|
function notifyTimerStep(event) {
|
|
1191
1191
|
try {
|
|
@@ -1346,7 +1346,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
1346
1346
|
}
|
|
1347
1347
|
}
|
|
1348
1348
|
async function backoff() {
|
|
1349
|
-
await new Promise((
|
|
1349
|
+
await new Promise((resolve20) => setTimeout(resolve20, Math.floor(Math.random() * 4)));
|
|
1350
1350
|
}
|
|
1351
1351
|
async function readLockState(notifyReady = true) {
|
|
1352
1352
|
if (notifyReady && options.onStep)
|
|
@@ -1453,8 +1453,15 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
1453
1453
|
return "missing";
|
|
1454
1454
|
throw error;
|
|
1455
1455
|
}
|
|
1456
|
-
if (windowsPrivateFiles)
|
|
1457
|
-
|
|
1456
|
+
if (windowsPrivateFiles) {
|
|
1457
|
+
try {
|
|
1458
|
+
await verifyPrivate(evictPath, "directory", true);
|
|
1459
|
+
} catch (error) {
|
|
1460
|
+
if (error.code === "ENOENT")
|
|
1461
|
+
return "missing";
|
|
1462
|
+
throw error;
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1458
1465
|
if (evictStat.mtimeMs + EVICT_TTL > now())
|
|
1459
1466
|
return "fresh";
|
|
1460
1467
|
if (options.onStep)
|
|
@@ -1479,8 +1486,8 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
1479
1486
|
} catch (error) {
|
|
1480
1487
|
if (error.code === "EEXIST") {
|
|
1481
1488
|
if (windowsPrivateFiles) {
|
|
1482
|
-
await verifyPrivate(evictPath, "directory", true);
|
|
1483
1489
|
try {
|
|
1490
|
+
await verifyPrivate(evictPath, "directory", true);
|
|
1484
1491
|
await readPrivateText(evictOwnerPath, true);
|
|
1485
1492
|
} catch (ownerError) {
|
|
1486
1493
|
if (ownerError.code !== "ENOENT")
|
|
@@ -1821,7 +1828,7 @@ async function withLock(target, options, fn) {
|
|
|
1821
1828
|
timeoutMs: options.timeoutMs
|
|
1822
1829
|
});
|
|
1823
1830
|
}
|
|
1824
|
-
await new Promise((
|
|
1831
|
+
await new Promise((resolve20) => setTimeout(resolve20, Math.min(25, Math.ceil(remaining))));
|
|
1825
1832
|
}
|
|
1826
1833
|
}
|
|
1827
1834
|
var LockContentionError, LockOwnershipError;
|
|
@@ -1940,7 +1947,7 @@ async function acquirePoolLock(spec, defaults, env3) {
|
|
|
1940
1947
|
});
|
|
1941
1948
|
}
|
|
1942
1949
|
const jitter = Math.floor(Math.random() * (options.retryMs + 1));
|
|
1943
|
-
await new Promise((
|
|
1950
|
+
await new Promise((resolve20) => setTimeout(resolve20, Math.min(options.retryMs + jitter, remaining)));
|
|
1944
1951
|
}
|
|
1945
1952
|
}
|
|
1946
1953
|
function definedOnly(spec) {
|
|
@@ -5211,11 +5218,11 @@ var init_quota_writer = __esm({
|
|
|
5211
5218
|
const left = deadline - performance.now();
|
|
5212
5219
|
if (left <= 0)
|
|
5213
5220
|
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);
|
|
5214
|
-
await new Promise((
|
|
5221
|
+
await new Promise((resolve20) => {
|
|
5215
5222
|
const done = () => {
|
|
5216
5223
|
clearTimeout(timer);
|
|
5217
5224
|
this.wake.delete(done);
|
|
5218
|
-
|
|
5225
|
+
resolve20();
|
|
5219
5226
|
};
|
|
5220
5227
|
const timer = setTimeout(done, left);
|
|
5221
5228
|
this.wake.add(done);
|
|
@@ -6040,7 +6047,7 @@ function admit(input) {
|
|
|
6040
6047
|
const scope = input.scope ?? ALL_SCOPE;
|
|
6041
6048
|
const requiredLabels = input.requiredLabels ?? DEFAULT_REQUIRED_LABELS;
|
|
6042
6049
|
const excluded = [];
|
|
6043
|
-
const
|
|
6050
|
+
const refused2 = [];
|
|
6044
6051
|
const survivors = [];
|
|
6045
6052
|
for (const row of input.rows) {
|
|
6046
6053
|
const exclusion = exclusionFor(row.id, input, input.now);
|
|
@@ -6055,7 +6062,7 @@ function admit(input) {
|
|
|
6055
6062
|
const projection = projectQuota(row.quota, scope);
|
|
6056
6063
|
const refusal3 = judgeStageOne(row.id, projection, requiredLabels, input.now);
|
|
6057
6064
|
if (refusal3) {
|
|
6058
|
-
|
|
6065
|
+
refused2.push(refusal3);
|
|
6059
6066
|
continue;
|
|
6060
6067
|
}
|
|
6061
6068
|
survivors.push({ id: row.id, kind: row.kind, projection });
|
|
@@ -6073,16 +6080,16 @@ function admit(input) {
|
|
|
6073
6080
|
} else if (lastPath) {
|
|
6074
6081
|
admitted.push({ ...row, lastPath: true });
|
|
6075
6082
|
} else {
|
|
6076
|
-
|
|
6083
|
+
refused2.push({ id: row.id, stage: 2, reason: "budget-spent", ...reset });
|
|
6077
6084
|
}
|
|
6078
6085
|
}
|
|
6079
6086
|
const order = new Map(input.rows.map((row, index) => [row.id, index]));
|
|
6080
6087
|
const byInput = (left, right) => (order.get(left.id) ?? 0) - (order.get(right.id) ?? 0);
|
|
6081
|
-
|
|
6082
|
-
const pulls =
|
|
6088
|
+
refused2.sort(byInput);
|
|
6089
|
+
const pulls = refused2.filter((refusal3) => "pullRequested" in refusal3).map((refusal3) => refusal3.id);
|
|
6083
6090
|
for (const id of pulls)
|
|
6084
6091
|
input.requestPull?.(id);
|
|
6085
|
-
return { admitted, refused, excluded, pulls };
|
|
6092
|
+
return { admitted, refused: refused2, excluded, pulls };
|
|
6086
6093
|
}
|
|
6087
6094
|
var init_admission = __esm({
|
|
6088
6095
|
"../core/dist/common-auth-embedded/routing/admission.js"() {
|
|
@@ -6304,7 +6311,7 @@ function selectStickyCandidate(input) {
|
|
|
6304
6311
|
function routeSticky(input) {
|
|
6305
6312
|
const admission = admit(input);
|
|
6306
6313
|
const admitted = new Map(admission.admitted.map((row) => [row.id, row]));
|
|
6307
|
-
const
|
|
6314
|
+
const refusals2 = new Map(admission.refused.map((r) => [r.id, r]));
|
|
6308
6315
|
const excluded = new Set(admission.excluded.map((row) => row.id));
|
|
6309
6316
|
const validIds = new Set(input.rows.map((row) => row.id));
|
|
6310
6317
|
const pinValid = input.pin !== void 0 && isPinValid(input.pin, validIds, input.identities?.get(input.pin.accountId));
|
|
@@ -6322,7 +6329,7 @@ function routeSticky(input) {
|
|
|
6322
6329
|
};
|
|
6323
6330
|
}
|
|
6324
6331
|
}
|
|
6325
|
-
const pinRefusal = input.pin ?
|
|
6332
|
+
const pinRefusal = input.pin ? refusals2.get(input.pin.accountId) : void 0;
|
|
6326
6333
|
const pinMoves = pinValid && input.pin !== void 0 && input.refusedPinPolicy === "move-on-confirmed-exhaustion" && (input.killswitch?.get(input.pin.accountId) === false || pinRefusal?.reason === "exhausted" || pinRefusal?.reason === "budget-spent");
|
|
6327
6334
|
const reserveFor = (row) => {
|
|
6328
6335
|
const perRow = typeof input.rowReservePercent === "function" ? input.rowReservePercent(row) : input.rowReservePercent?.get(row.id);
|
|
@@ -6353,7 +6360,7 @@ function routeSticky(input) {
|
|
|
6353
6360
|
});
|
|
6354
6361
|
if (!selection)
|
|
6355
6362
|
break;
|
|
6356
|
-
const refusal3 =
|
|
6363
|
+
const refusal3 = refusals2.get(selection.accountId);
|
|
6357
6364
|
if (refusal3) {
|
|
6358
6365
|
refusedSelections.push(refusal3);
|
|
6359
6366
|
candidates = candidates.filter((candidate) => candidate.accountId !== selection.accountId);
|
|
@@ -7986,7 +7993,7 @@ async function select(terminal, items, options) {
|
|
|
7986
7993
|
writeLine("");
|
|
7987
7994
|
renderedLines = lines;
|
|
7988
7995
|
};
|
|
7989
|
-
return new Promise((
|
|
7996
|
+
return new Promise((resolve20) => {
|
|
7990
7997
|
const wasRaw = stdin.isRaw ?? false;
|
|
7991
7998
|
const cleanup2 = () => {
|
|
7992
7999
|
if (cleaned)
|
|
@@ -8006,7 +8013,7 @@ async function select(terminal, items, options) {
|
|
|
8006
8013
|
};
|
|
8007
8014
|
const finish = (value) => {
|
|
8008
8015
|
cleanup2();
|
|
8009
|
-
|
|
8016
|
+
resolve20(value);
|
|
8010
8017
|
};
|
|
8011
8018
|
const onSignal = () => finish(null);
|
|
8012
8019
|
const onKey = (data) => {
|
|
@@ -8046,7 +8053,7 @@ async function select(terminal, items, options) {
|
|
|
8046
8053
|
stdin.setRawMode(true);
|
|
8047
8054
|
} catch {
|
|
8048
8055
|
cleanup2();
|
|
8049
|
-
|
|
8056
|
+
resolve20(null);
|
|
8050
8057
|
return;
|
|
8051
8058
|
}
|
|
8052
8059
|
stdin.resume();
|
|
@@ -9019,20 +9026,20 @@ function acquireInsulaQuotaSource(transport, tokenPath) {
|
|
|
9019
9026
|
resolve5(transport.connectionFile),
|
|
9020
9027
|
resolve5(tokenPath)
|
|
9021
9028
|
]);
|
|
9022
|
-
let
|
|
9023
|
-
if (!
|
|
9024
|
-
|
|
9025
|
-
sources.set(key,
|
|
9029
|
+
let shared3 = sources.get(key);
|
|
9030
|
+
if (!shared3) {
|
|
9031
|
+
shared3 = { source: new InsulaQuotaSource(transport, key), refs: 0 };
|
|
9032
|
+
sources.set(key, shared3);
|
|
9026
9033
|
}
|
|
9027
|
-
|
|
9034
|
+
shared3.refs++;
|
|
9028
9035
|
let released = false;
|
|
9029
9036
|
return {
|
|
9030
|
-
source:
|
|
9037
|
+
source: shared3.source,
|
|
9031
9038
|
release() {
|
|
9032
9039
|
if (released)
|
|
9033
9040
|
return;
|
|
9034
9041
|
released = true;
|
|
9035
|
-
if (--
|
|
9042
|
+
if (--shared3.refs === 0)
|
|
9036
9043
|
sources.delete(key);
|
|
9037
9044
|
}
|
|
9038
9045
|
};
|
|
@@ -9253,12 +9260,12 @@ var init_insula = __esm({
|
|
|
9253
9260
|
if (!this.#available)
|
|
9254
9261
|
return { miss: "unreachable" };
|
|
9255
9262
|
const entry = this.#entries.find((value) => value.provider === provider2 && typeof value.account === "string" && value.account.trim() === accountId);
|
|
9256
|
-
const
|
|
9257
|
-
if (
|
|
9263
|
+
const errorClass2 = (entry ?? this.#entries.find((value) => value.provider === provider2 && value.account === void 0 && value.errorClass !== void 0))?.errorClass;
|
|
9264
|
+
if (errorClass2 === "upstream_failed")
|
|
9258
9265
|
return { miss: "upstream-failed" };
|
|
9259
|
-
if (
|
|
9266
|
+
if (errorClass2 === "credential_absent" || errorClass2 === "credential_unusable" || errorClass2 === "credential_rejected")
|
|
9260
9267
|
return { miss: "credential" };
|
|
9261
|
-
if (
|
|
9268
|
+
if (errorClass2 !== void 0)
|
|
9262
9269
|
return { miss: "unreachable" };
|
|
9263
9270
|
if (entry) {
|
|
9264
9271
|
const fetchedAt = typeof entry.fetchedAt === "string" ? Date.parse(entry.fetchedAt) : Number.NaN;
|
|
@@ -9571,7 +9578,7 @@ async function refuseWritableAncestor(parent, options = {}) {
|
|
|
9571
9578
|
throw new ClaustrumConsumerError("unsafe-file", `Claustrum enrollment parent refused: ${error.path} (${error.reason ?? error.code}). Use a folder that other users cannot write or replace.`);
|
|
9572
9579
|
}
|
|
9573
9580
|
}
|
|
9574
|
-
async function
|
|
9581
|
+
async function ensureClaustrumPrivateDirectory(directory, options = {}, what = "enrollment directory") {
|
|
9575
9582
|
if (windowsPrivateFiles) {
|
|
9576
9583
|
await ensurePrivateDirectory(directory, false, ancestorPolicyOptions(options));
|
|
9577
9584
|
return;
|
|
@@ -9580,14 +9587,14 @@ async function ensurePrivateDirectory2(directory, options = {}) {
|
|
|
9580
9587
|
const metadata = await stat4(directory);
|
|
9581
9588
|
const uid = process.geteuid?.();
|
|
9582
9589
|
if (uid !== void 0 && metadata.uid !== uid) {
|
|
9583
|
-
throw new ClaustrumConsumerError("unsafe-file",
|
|
9590
|
+
throw new ClaustrumConsumerError("unsafe-file", `Claustrum ${what} must be owned by the current user`);
|
|
9584
9591
|
}
|
|
9585
9592
|
if ((metadata.mode & 63) !== 0)
|
|
9586
9593
|
await chmod2(directory, 448);
|
|
9587
9594
|
}
|
|
9588
9595
|
async function writeStateAtomic(path2, state, ancestorOptions = {}) {
|
|
9589
9596
|
const parent = dirname9(path2);
|
|
9590
|
-
await
|
|
9597
|
+
await ensureClaustrumPrivateDirectory(parent, ancestorOptions);
|
|
9591
9598
|
await refuseWritableAncestor(parent, ancestorOptions);
|
|
9592
9599
|
const bytes = `${JSON.stringify(state)}
|
|
9593
9600
|
`;
|
|
@@ -9721,7 +9728,7 @@ function wrongConsumer() {
|
|
|
9721
9728
|
return new ClaustrumConsumerError("wrong-consumer", "Claustrum enrollment state belongs to a different consumer");
|
|
9722
9729
|
}
|
|
9723
9730
|
async function resetClaustrumEnrollmentState(paths, proposedName) {
|
|
9724
|
-
await
|
|
9731
|
+
await ensureClaustrumPrivateDirectory(dirname9(paths.statePath));
|
|
9725
9732
|
const lock = await acquireRefreshFileLock({
|
|
9726
9733
|
name: "ceremony",
|
|
9727
9734
|
path: paths.statePath,
|
|
@@ -9759,7 +9766,7 @@ async function removeIfPresent(path2) {
|
|
|
9759
9766
|
}
|
|
9760
9767
|
}
|
|
9761
9768
|
async function disconnectClaustrumEnrollment(paths, proposedName) {
|
|
9762
|
-
await
|
|
9769
|
+
await ensureClaustrumPrivateDirectory(dirname9(paths.statePath));
|
|
9763
9770
|
const lock = await acquireRefreshFileLock({
|
|
9764
9771
|
// The same lock as the ceremony, so a token written by a concurrent
|
|
9765
9772
|
// reconcile() can never land after this removes the files.
|
|
@@ -9855,7 +9862,7 @@ var init_enrollment = __esm({
|
|
|
9855
9862
|
return statusFromState(blocked);
|
|
9856
9863
|
}
|
|
9857
9864
|
async reconcile() {
|
|
9858
|
-
await
|
|
9865
|
+
await ensureClaustrumPrivateDirectory(dirname9(this.#paths.statePath), this.#ancestorOptions);
|
|
9859
9866
|
const lock = await acquireRefreshFileLock({
|
|
9860
9867
|
name: "ceremony",
|
|
9861
9868
|
path: this.#paths.statePath,
|
|
@@ -9978,7 +9985,7 @@ var init_enrollment = __esm({
|
|
|
9978
9985
|
await writeStateAtomic(this.#paths.statePath, denied, this.#ancestorOptions);
|
|
9979
9986
|
return statusFromState(denied);
|
|
9980
9987
|
}
|
|
9981
|
-
await
|
|
9988
|
+
await ensureClaustrumPrivateDirectory(dirname9(this.#paths.tokenPath), this.#ancestorOptions);
|
|
9982
9989
|
await refuseWritableAncestor(dirname9(this.#paths.tokenPath), this.#ancestorOptions);
|
|
9983
9990
|
await this.#writeTokenFile(this.#paths.tokenPath, {
|
|
9984
9991
|
token: outcome.token,
|
|
@@ -10092,10 +10099,10 @@ async function drainShutdown(pending, onTimeout) {
|
|
|
10092
10099
|
try {
|
|
10093
10100
|
await Promise.race([
|
|
10094
10101
|
drained,
|
|
10095
|
-
new Promise((
|
|
10102
|
+
new Promise((resolve20) => {
|
|
10096
10103
|
timer = setTimeout(() => {
|
|
10097
10104
|
expired = true;
|
|
10098
|
-
|
|
10105
|
+
resolve20();
|
|
10099
10106
|
}, 2e3);
|
|
10100
10107
|
})
|
|
10101
10108
|
]);
|
|
@@ -10402,7 +10409,7 @@ var init_custody = __esm({
|
|
|
10402
10409
|
throw error;
|
|
10403
10410
|
}
|
|
10404
10411
|
const skipped = [];
|
|
10405
|
-
const
|
|
10412
|
+
const refused2 = [];
|
|
10406
10413
|
let notMine = 0;
|
|
10407
10414
|
const candidates = [];
|
|
10408
10415
|
const counts = /* @__PURE__ */ new Map();
|
|
@@ -10413,7 +10420,7 @@ var init_custody = __esm({
|
|
|
10413
10420
|
continue;
|
|
10414
10421
|
}
|
|
10415
10422
|
if (classified.kind === "refused") {
|
|
10416
|
-
|
|
10423
|
+
refused2.push({
|
|
10417
10424
|
...row.id.trim() && { credentialId: row.id },
|
|
10418
10425
|
code: classified.code
|
|
10419
10426
|
});
|
|
@@ -10465,7 +10472,7 @@ var init_custody = __esm({
|
|
|
10465
10472
|
credentials: Object.freeze(credentials),
|
|
10466
10473
|
skipped: Object.freeze(skipped),
|
|
10467
10474
|
..."classify" in this.#family && {
|
|
10468
|
-
refused: Object.freeze(
|
|
10475
|
+
refused: Object.freeze(refused2),
|
|
10469
10476
|
notMine
|
|
10470
10477
|
},
|
|
10471
10478
|
...grantReach && { grantReach }
|
|
@@ -11692,7 +11699,7 @@ var init_consumer = __esm({
|
|
|
11692
11699
|
this.#shutdown.signal,
|
|
11693
11700
|
...signal ? [signal] : []
|
|
11694
11701
|
]);
|
|
11695
|
-
return new Promise((
|
|
11702
|
+
return new Promise((resolve20, reject) => {
|
|
11696
11703
|
const cleanup2 = () => {
|
|
11697
11704
|
combined.signal.removeEventListener("abort", abort);
|
|
11698
11705
|
combined.dispose();
|
|
@@ -11707,7 +11714,7 @@ var init_consumer = __esm({
|
|
|
11707
11714
|
if (combined.signal.aborted)
|
|
11708
11715
|
reject(combined.signal.reason);
|
|
11709
11716
|
else
|
|
11710
|
-
|
|
11717
|
+
resolve20(value);
|
|
11711
11718
|
}, (error) => {
|
|
11712
11719
|
cleanup2();
|
|
11713
11720
|
reject(error);
|
|
@@ -12396,7 +12403,7 @@ var init_consumer = __esm({
|
|
|
12396
12403
|
// ../core/dist/common-auth-embedded/claustrum/hub.js
|
|
12397
12404
|
import { createHash as createHash7 } from "node:crypto";
|
|
12398
12405
|
import { readdir, stat as stat6 } from "node:fs/promises";
|
|
12399
|
-
import { join as join7 } from "node:path";
|
|
12406
|
+
import { dirname as dirname10, join as join7 } from "node:path";
|
|
12400
12407
|
function canonicalJson3(value, path2 = /* @__PURE__ */ new Set()) {
|
|
12401
12408
|
if (value === null)
|
|
12402
12409
|
return "null";
|
|
@@ -12457,12 +12464,12 @@ function unreachableConnect2() {
|
|
|
12457
12464
|
return new ClaustrumUnreachableError();
|
|
12458
12465
|
}
|
|
12459
12466
|
function untilAborted(pending, signal) {
|
|
12460
|
-
return new Promise((
|
|
12467
|
+
return new Promise((resolve20, reject) => {
|
|
12461
12468
|
const abort = () => reject(signal.reason);
|
|
12462
12469
|
signal.addEventListener("abort", abort, { once: true });
|
|
12463
12470
|
pending.then((value) => {
|
|
12464
12471
|
signal.removeEventListener("abort", abort);
|
|
12465
|
-
|
|
12472
|
+
resolve20(value);
|
|
12466
12473
|
}, (error) => {
|
|
12467
12474
|
signal.removeEventListener("abort", abort);
|
|
12468
12475
|
reject(error);
|
|
@@ -12483,6 +12490,7 @@ var init_hub = __esm({
|
|
|
12483
12490
|
init_availability();
|
|
12484
12491
|
init_consumer();
|
|
12485
12492
|
init_custody();
|
|
12493
|
+
init_enrollment();
|
|
12486
12494
|
init_errors2();
|
|
12487
12495
|
init_roster();
|
|
12488
12496
|
init_shutdown();
|
|
@@ -12915,10 +12923,11 @@ var init_hub = __esm({
|
|
|
12915
12923
|
}
|
|
12916
12924
|
/**
|
|
12917
12925
|
* Read each member's base view, list once, then commit each member's share
|
|
12918
|
-
* of the listing to its roster
|
|
12919
|
-
*
|
|
12920
|
-
*
|
|
12921
|
-
*
|
|
12926
|
+
* of the listing to its roster (all members at once, each under its own
|
|
12927
|
+
* roster's locks), push it into the member, and retain the union. Each
|
|
12928
|
+
* publication step checks first that the generation it started in is
|
|
12929
|
+
* still current. A member that this list did not commit is marked pending,
|
|
12930
|
+
* so a later tick lists again.
|
|
12922
12931
|
*/
|
|
12923
12932
|
async #discover(run) {
|
|
12924
12933
|
if (!await this.#readAuthority())
|
|
@@ -12928,9 +12937,11 @@ var init_hub = __esm({
|
|
|
12928
12937
|
run.generation = generation;
|
|
12929
12938
|
if (!this.#live(generation))
|
|
12930
12939
|
return void 0;
|
|
12931
|
-
const
|
|
12932
|
-
|
|
12933
|
-
|
|
12940
|
+
const folders = await this.#ensureRosterDirectories().then(() => void 0, (error) => error instanceof Error ? error : new Error(String(error)));
|
|
12941
|
+
const bases = new Map(await Promise.all([...this.#members.values()].map(async (entry) => [
|
|
12942
|
+
entry,
|
|
12943
|
+
await readVaultRoster(entry.path).then((file) => file ? { file } : {}, (error) => error instanceof Error ? error : new Error(String(error)))
|
|
12944
|
+
])));
|
|
12934
12945
|
if (!this.#live(generation))
|
|
12935
12946
|
return void 0;
|
|
12936
12947
|
let inventory;
|
|
@@ -12944,40 +12955,21 @@ var init_hub = __esm({
|
|
|
12944
12955
|
this.#markPending(entry);
|
|
12945
12956
|
throw error;
|
|
12946
12957
|
}
|
|
12958
|
+
if (!this.#live(generation))
|
|
12959
|
+
return void 0;
|
|
12960
|
+
const members = this.#open();
|
|
12961
|
+
const commits = await Promise.all(members.map((entry) => entry.hooks && !entry.closed ? this.#commit(entry, entry.hooks, inventory, folders ?? bases.get(entry), generation) : void 0));
|
|
12962
|
+
if (!this.#live(generation))
|
|
12963
|
+
return void 0;
|
|
12947
12964
|
const errors = /* @__PURE__ */ new Map();
|
|
12948
12965
|
let complete = true;
|
|
12949
|
-
for (const entry of
|
|
12950
|
-
if (!this.#live(generation))
|
|
12951
|
-
return void 0;
|
|
12966
|
+
for (const [index, entry] of members.entries()) {
|
|
12952
12967
|
const hooks = entry.hooks;
|
|
12953
|
-
|
|
12968
|
+
const commit = commits[index];
|
|
12969
|
+
if (!hooks || !commit)
|
|
12954
12970
|
continue;
|
|
12955
|
-
|
|
12956
|
-
|
|
12957
|
-
credentials: inventory.credentials.filter((credential) => credential.member === entry.provider),
|
|
12958
|
-
skipped: inventory.skipped.filter((record3) => record3.member === entry.provider)
|
|
12959
|
-
};
|
|
12960
|
-
const base = bases.get(entry);
|
|
12961
|
-
let roster;
|
|
12962
|
-
try {
|
|
12963
|
-
if (!base)
|
|
12964
|
-
throw closed("Claustrum hub member has no base view");
|
|
12965
|
-
if (base instanceof Error)
|
|
12966
|
-
throw base;
|
|
12967
|
-
const seed = base.file ? void 0 : await this.#seed(entry);
|
|
12968
|
-
roster = await refreshVaultRoster({
|
|
12969
|
-
path: entry.path,
|
|
12970
|
-
custody: { discover: async () => share },
|
|
12971
|
-
// Generation g's commit checks that g is still current, not only
|
|
12972
|
-
// that vault mode is on, so off-then-on cannot let it into g+1.
|
|
12973
|
-
isActive: () => this.#live(generation) && this.#active === true,
|
|
12974
|
-
signal: generation.controller.signal,
|
|
12975
|
-
projection: () => ({ ...hooks.projection(), ...seed && { seed } }),
|
|
12976
|
-
listedOver: { view: base.file?.view }
|
|
12977
|
-
});
|
|
12978
|
-
} catch (error) {
|
|
12979
|
-
if (!this.#live(generation))
|
|
12980
|
-
return void 0;
|
|
12971
|
+
if ("error" in commit) {
|
|
12972
|
+
const { error } = commit;
|
|
12981
12973
|
complete = false;
|
|
12982
12974
|
this.#markPending(entry);
|
|
12983
12975
|
if (isVaultRosterLockRefusal(entry.path, error))
|
|
@@ -12988,6 +12980,7 @@ var init_hub = __esm({
|
|
|
12988
12980
|
errors.set(entry.provider, error);
|
|
12989
12981
|
continue;
|
|
12990
12982
|
}
|
|
12983
|
+
const { roster } = commit;
|
|
12991
12984
|
if (!this.#live(generation))
|
|
12992
12985
|
return void 0;
|
|
12993
12986
|
if (roster?.view !== inventory.view) {
|
|
@@ -13019,6 +13012,54 @@ var init_hub = __esm({
|
|
|
13019
13012
|
this.#discoveredAt = (this.#options.now ?? Date.now)();
|
|
13020
13013
|
return { errors };
|
|
13021
13014
|
}
|
|
13015
|
+
/**
|
|
13016
|
+
* Commit one member's share of `inventory` to its roster file over the
|
|
13017
|
+
* base view read before the list. Every failure is returned, not thrown,
|
|
13018
|
+
* so one member's failure leaves the other members' commits running.
|
|
13019
|
+
*/
|
|
13020
|
+
async #commit(entry, hooks, inventory, base, generation) {
|
|
13021
|
+
const share = {
|
|
13022
|
+
...inventory,
|
|
13023
|
+
credentials: inventory.credentials.filter((credential) => credential.member === entry.provider),
|
|
13024
|
+
skipped: inventory.skipped.filter((record3) => record3.member === entry.provider)
|
|
13025
|
+
};
|
|
13026
|
+
try {
|
|
13027
|
+
if (!base)
|
|
13028
|
+
throw closed("Claustrum hub member has no base view");
|
|
13029
|
+
if (base instanceof Error)
|
|
13030
|
+
throw base;
|
|
13031
|
+
const seed = base.file ? void 0 : await this.#seed(entry);
|
|
13032
|
+
const roster = await refreshVaultRoster({
|
|
13033
|
+
path: entry.path,
|
|
13034
|
+
custody: { discover: async () => share },
|
|
13035
|
+
// Generation g's commit checks that g is still current, not only
|
|
13036
|
+
// that vault mode is on, so off-then-on cannot let it into g+1.
|
|
13037
|
+
isActive: () => this.#live(generation) && this.#active === true,
|
|
13038
|
+
signal: generation.controller.signal,
|
|
13039
|
+
projection: () => ({ ...hooks.projection(), ...seed && { seed } }),
|
|
13040
|
+
listedOver: { view: base.file?.view }
|
|
13041
|
+
});
|
|
13042
|
+
return { roster };
|
|
13043
|
+
} catch (error) {
|
|
13044
|
+
return { error };
|
|
13045
|
+
}
|
|
13046
|
+
}
|
|
13047
|
+
/**
|
|
13048
|
+
* Create the roster folders under the state folder (`rosters`, this host
|
|
13049
|
+
* generation and this key) owner-only, as every other Claustrum private
|
|
13050
|
+
* folder is: 0700 on POSIX, tightening a folder an earlier release left
|
|
13051
|
+
* open, and private-files on Windows. Each is handled on its own so an
|
|
13052
|
+
* existing open parent is tightened too. Without this, the first roster
|
|
13053
|
+
* lock would create them with the process umask, usually 0755.
|
|
13054
|
+
*/
|
|
13055
|
+
async #ensureRosterDirectories() {
|
|
13056
|
+
for (const directory of [
|
|
13057
|
+
dirname10(this.#generationDirectory),
|
|
13058
|
+
this.#generationDirectory,
|
|
13059
|
+
join7(this.#generationDirectory, this.#key)
|
|
13060
|
+
])
|
|
13061
|
+
await ensureClaustrumPrivateDirectory(directory, {}, "roster directory");
|
|
13062
|
+
}
|
|
13022
13063
|
/**
|
|
13023
13064
|
* The preferences a member's first roster under this key starts from: the
|
|
13024
13065
|
* declines and order of the newest roster of the same host generation and
|
|
@@ -13588,7 +13629,7 @@ var init_lock = __esm({
|
|
|
13588
13629
|
import { createHash as createHash8 } from "node:crypto";
|
|
13589
13630
|
import { constants as constants2 } from "node:fs";
|
|
13590
13631
|
import { lstat as lstat4, mkdir as mkdir10, open as open7, unlink as unlink7 } from "node:fs/promises";
|
|
13591
|
-
import { dirname as
|
|
13632
|
+
import { dirname as dirname11, resolve as resolve9 } from "node:path";
|
|
13592
13633
|
import { setTimeout as sleep2 } from "node:timers/promises";
|
|
13593
13634
|
function rootSpans(text2) {
|
|
13594
13635
|
let i = text2.indexOf("{") + 1;
|
|
@@ -13685,13 +13726,13 @@ async function safeRead(path2, privateFile = false, afterReadCheck) {
|
|
|
13685
13726
|
let file;
|
|
13686
13727
|
try {
|
|
13687
13728
|
file = await open7(path2, constants2.O_RDONLY | constants2.O_NOFOLLOW);
|
|
13688
|
-
const
|
|
13689
|
-
if (!
|
|
13729
|
+
const stat13 = await file.stat();
|
|
13730
|
+
if (!stat13.isFile() || privateFile && (stat13.mode & 511) !== 384) {
|
|
13690
13731
|
throw new PiSlotError("unsafe-path");
|
|
13691
13732
|
}
|
|
13692
13733
|
await afterReadCheck?.(path2);
|
|
13693
13734
|
const current = await lstat4(path2);
|
|
13694
|
-
if (!current.isFile() || current.dev !==
|
|
13735
|
+
if (!current.isFile() || current.dev !== stat13.dev || current.ino !== stat13.ino) {
|
|
13695
13736
|
throw new PiSlotError("unsafe-path");
|
|
13696
13737
|
}
|
|
13697
13738
|
const bytes = await file.readFile();
|
|
@@ -13823,9 +13864,9 @@ function createPiSlot(options, onStep, hooks) {
|
|
|
13823
13864
|
};
|
|
13824
13865
|
try {
|
|
13825
13866
|
if (windowsPrivateFiles)
|
|
13826
|
-
await ensurePrivateDirectory(
|
|
13867
|
+
await ensurePrivateDirectory(dirname11(authPath));
|
|
13827
13868
|
else
|
|
13828
|
-
await mkdir10(
|
|
13869
|
+
await mkdir10(dirname11(authPath), { recursive: true, mode: 448 });
|
|
13829
13870
|
const deadline = Date.now() + timeout;
|
|
13830
13871
|
let retry = 0;
|
|
13831
13872
|
while (!release) {
|
|
@@ -13866,7 +13907,7 @@ function createPiSlot(options, onStep, hooks) {
|
|
|
13866
13907
|
async function deleteStash(assertLock) {
|
|
13867
13908
|
assertLock();
|
|
13868
13909
|
await unlink7(stashPath);
|
|
13869
|
-
await syncDir(
|
|
13910
|
+
await syncDir(dirname11(stashPath));
|
|
13870
13911
|
onStep?.("stash-deleted");
|
|
13871
13912
|
}
|
|
13872
13913
|
return {
|
|
@@ -13886,10 +13927,10 @@ function createPiSlot(options, onStep, hooks) {
|
|
|
13886
13927
|
throw new PiSlotError("conflict");
|
|
13887
13928
|
if (!stash) {
|
|
13888
13929
|
if (windowsPrivateFiles)
|
|
13889
|
-
await ensurePrivateDirectory(
|
|
13930
|
+
await ensurePrivateDirectory(dirname11(stashPath));
|
|
13890
13931
|
else {
|
|
13891
|
-
await mkdir10(
|
|
13892
|
-
const dir = await lstat4(
|
|
13932
|
+
await mkdir10(dirname11(stashPath), { recursive: true, mode: 448 });
|
|
13933
|
+
const dir = await lstat4(dirname11(stashPath));
|
|
13893
13934
|
if (!dir.isDirectory() || (dir.mode & 511) !== 448)
|
|
13894
13935
|
throw new PiSlotError("unsafe-path");
|
|
13895
13936
|
}
|
|
@@ -13959,8 +14000,8 @@ var init_pi_slot = __esm({
|
|
|
13959
14000
|
|
|
13960
14001
|
// src/cli.ts
|
|
13961
14002
|
import { execFile } from "node:child_process";
|
|
13962
|
-
import { realpathSync as
|
|
13963
|
-
import { resolve as
|
|
14003
|
+
import { realpathSync as realpathSync4 } from "node:fs";
|
|
14004
|
+
import { resolve as resolve19 } from "node:path";
|
|
13964
14005
|
import { createInterface } from "node:readline/promises";
|
|
13965
14006
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
13966
14007
|
import { promisify } from "node:util";
|
|
@@ -15170,10 +15211,10 @@ async function privateDirectory(path2) {
|
|
|
15170
15211
|
if (errno(error) !== "EEXIST")
|
|
15171
15212
|
throw error;
|
|
15172
15213
|
}
|
|
15173
|
-
const
|
|
15174
|
-
if (!
|
|
15214
|
+
const stat13 = await lstat(path2);
|
|
15215
|
+
if (!stat13.isDirectory() || stat13.isSymbolicLink())
|
|
15175
15216
|
throw new AccountMigrationError("successor directory is not a regular directory");
|
|
15176
|
-
privateMode(
|
|
15217
|
+
privateMode(stat13.mode, 448);
|
|
15177
15218
|
if (!sameFilesystemPath(await realpath(path2), path2))
|
|
15178
15219
|
throw new AccountMigrationError("successor directory traverses a symbolic link");
|
|
15179
15220
|
}
|
|
@@ -18802,7 +18843,7 @@ async function rmEvictingDir(evictingPath) {
|
|
|
18802
18843
|
});
|
|
18803
18844
|
}
|
|
18804
18845
|
async function sleep(ms) {
|
|
18805
|
-
await new Promise((
|
|
18846
|
+
await new Promise((resolve20) => setTimeout(resolve20, ms));
|
|
18806
18847
|
}
|
|
18807
18848
|
async function acquireFencedFileLock(options) {
|
|
18808
18849
|
const lockPath = `${options.path}.${options.name}.lock`;
|
|
@@ -18918,8 +18959,8 @@ function buildLock(lockPath, evictingPath, ownerId, options, now) {
|
|
|
18918
18959
|
let released = false;
|
|
18919
18960
|
let lost = false;
|
|
18920
18961
|
let lostResolve = null;
|
|
18921
|
-
let lostPromise = new Promise((
|
|
18922
|
-
lostResolve =
|
|
18962
|
+
let lostPromise = new Promise((resolve20) => {
|
|
18963
|
+
lostResolve = resolve20;
|
|
18923
18964
|
});
|
|
18924
18965
|
const markLost = () => {
|
|
18925
18966
|
if (lost)
|
|
@@ -18929,9 +18970,9 @@ function buildLock(lockPath, evictingPath, ownerId, options, now) {
|
|
|
18929
18970
|
clearInterval(renewTimer);
|
|
18930
18971
|
renewTimer = null;
|
|
18931
18972
|
}
|
|
18932
|
-
const
|
|
18973
|
+
const resolve20 = lostResolve;
|
|
18933
18974
|
lostResolve = null;
|
|
18934
|
-
|
|
18975
|
+
resolve20?.();
|
|
18935
18976
|
};
|
|
18936
18977
|
const setupRenew = () => {
|
|
18937
18978
|
if (options.renew === false)
|
|
@@ -19155,7 +19196,7 @@ var AccountStorageUnreadableError = class extends Error {
|
|
|
19155
19196
|
}
|
|
19156
19197
|
};
|
|
19157
19198
|
var RETRY_DELAYS_MS = [100, 200, 400, 800, 1e3];
|
|
19158
|
-
var DEFAULT_SLEEP = (ms) => new Promise((
|
|
19199
|
+
var DEFAULT_SLEEP = (ms) => new Promise((resolve20) => setTimeout(resolve20, ms));
|
|
19159
19200
|
var DEFAULT_BUILD_BACKUP_PATH = (path2, now) => `${path2}.corrupt-${now.toISOString().replace(/[:.]/g, "-")}`;
|
|
19160
19201
|
async function ensureSecurePermissions(path2) {
|
|
19161
19202
|
try {
|
|
@@ -19666,7 +19707,7 @@ function getHttpsProxy(url) {
|
|
|
19666
19707
|
}
|
|
19667
19708
|
}
|
|
19668
19709
|
function waitForHead(socket, timeoutMs, onTimeout) {
|
|
19669
|
-
return new Promise((
|
|
19710
|
+
return new Promise((resolve20, reject) => {
|
|
19670
19711
|
let buffer = Buffer2.alloc(0);
|
|
19671
19712
|
const timeout = setTimeout(() => {
|
|
19672
19713
|
onTimeout();
|
|
@@ -19689,7 +19730,7 @@ function waitForHead(socket, timeoutMs, onTimeout) {
|
|
|
19689
19730
|
return;
|
|
19690
19731
|
const head = buffer.subarray(0, marker).toString("latin1");
|
|
19691
19732
|
const leftover = buffer.subarray(marker + 4);
|
|
19692
|
-
cleanup2(() =>
|
|
19733
|
+
cleanup2(() => resolve20({ head, leftover }));
|
|
19693
19734
|
};
|
|
19694
19735
|
socket.on("data", onData);
|
|
19695
19736
|
socket.once("error", onError);
|
|
@@ -19703,7 +19744,7 @@ async function connectViaProxy(proxyUrl, targetUrl, timeoutMs, signal, onDebug)
|
|
|
19703
19744
|
port: Number(proxyUrl.port || DEFAULT_PROXY_PORT),
|
|
19704
19745
|
signal: signal ?? void 0
|
|
19705
19746
|
});
|
|
19706
|
-
await new Promise((
|
|
19747
|
+
await new Promise((resolve20, reject) => {
|
|
19707
19748
|
const timeout = setTimeout(() => {
|
|
19708
19749
|
onDebug?.(`agy transport proxy connect timeout after ${timeoutMs}ms`);
|
|
19709
19750
|
proxySocket.destroy();
|
|
@@ -19712,7 +19753,7 @@ async function connectViaProxy(proxyUrl, targetUrl, timeoutMs, signal, onDebug)
|
|
|
19712
19753
|
const cleanup2 = () => clearTimeout(timeout);
|
|
19713
19754
|
proxySocket.once("connect", () => {
|
|
19714
19755
|
cleanup2();
|
|
19715
|
-
|
|
19756
|
+
resolve20();
|
|
19716
19757
|
});
|
|
19717
19758
|
proxySocket.once("error", (error) => {
|
|
19718
19759
|
cleanup2();
|
|
@@ -19737,7 +19778,7 @@ Host: ${targetHost}:${targetPort}\r
|
|
|
19737
19778
|
if (leftover.length > 0) {
|
|
19738
19779
|
proxySocket.unshift(leftover);
|
|
19739
19780
|
}
|
|
19740
|
-
return await new Promise((
|
|
19781
|
+
return await new Promise((resolve20, reject) => {
|
|
19741
19782
|
const tlsOptions = {
|
|
19742
19783
|
socket: proxySocket,
|
|
19743
19784
|
servername: targetHost,
|
|
@@ -19752,7 +19793,7 @@ Host: ${targetHost}:${targetPort}\r
|
|
|
19752
19793
|
const cleanup2 = () => clearTimeout(timeout);
|
|
19753
19794
|
tlsSocket.once("secureConnect", () => {
|
|
19754
19795
|
cleanup2();
|
|
19755
|
-
|
|
19796
|
+
resolve20(tlsSocket);
|
|
19756
19797
|
});
|
|
19757
19798
|
tlsSocket.once("error", (error) => {
|
|
19758
19799
|
cleanup2();
|
|
@@ -19761,7 +19802,7 @@ Host: ${targetHost}:${targetPort}\r
|
|
|
19761
19802
|
});
|
|
19762
19803
|
}
|
|
19763
19804
|
async function connectDirect(targetUrl, timeoutMs, signal, onDebug) {
|
|
19764
|
-
return await new Promise((
|
|
19805
|
+
return await new Promise((resolve20, reject) => {
|
|
19765
19806
|
const tlsOptions = {
|
|
19766
19807
|
host: targetUrl.hostname,
|
|
19767
19808
|
port: Number(targetUrl.port || DEFAULT_HTTPS_PORT),
|
|
@@ -19777,7 +19818,7 @@ async function connectDirect(targetUrl, timeoutMs, signal, onDebug) {
|
|
|
19777
19818
|
const cleanup2 = () => clearTimeout(timeout);
|
|
19778
19819
|
socket.once("secureConnect", () => {
|
|
19779
19820
|
cleanup2();
|
|
19780
|
-
|
|
19821
|
+
resolve20(socket);
|
|
19781
19822
|
});
|
|
19782
19823
|
socket.once("error", (error) => {
|
|
19783
19824
|
cleanup2();
|
|
@@ -20415,7 +20456,7 @@ function maskSensitiveIdentifier(value) {
|
|
|
20415
20456
|
|
|
20416
20457
|
// ../core/dist/pi-paths.js
|
|
20417
20458
|
import { homedir } from "node:os";
|
|
20418
|
-
import { dirname as
|
|
20459
|
+
import { dirname as dirname12, join as join8 } from "node:path";
|
|
20419
20460
|
function getPiConfigDir() {
|
|
20420
20461
|
return process.env.PI_AGENT_DIR?.trim() || join8(homedir(), ".pi", "agent");
|
|
20421
20462
|
}
|
|
@@ -20423,7 +20464,7 @@ function getPiAntigravityAuthFile() {
|
|
|
20423
20464
|
return process.env.PI_ANTIGRAVITY_AUTH_FILE?.trim() || join8(getPiConfigDir(), "antigravity-accounts.json");
|
|
20424
20465
|
}
|
|
20425
20466
|
function getPiAntigravityVaultDir() {
|
|
20426
|
-
return join8(
|
|
20467
|
+
return join8(dirname12(getPiAntigravityAuthFile()), "antigravity-auth-vault");
|
|
20427
20468
|
}
|
|
20428
20469
|
|
|
20429
20470
|
// ../core/dist/project.js
|
|
@@ -20450,8 +20491,8 @@ function getDefaultTierId(allowedTiers) {
|
|
|
20450
20491
|
return allowedTiers[0]?.id;
|
|
20451
20492
|
}
|
|
20452
20493
|
function wait(ms) {
|
|
20453
|
-
return new Promise((
|
|
20454
|
-
setTimeout(
|
|
20494
|
+
return new Promise((resolve20) => {
|
|
20495
|
+
setTimeout(resolve20, ms);
|
|
20455
20496
|
});
|
|
20456
20497
|
}
|
|
20457
20498
|
function extractManagedProjectId(payload) {
|
|
@@ -21280,13 +21321,13 @@ async function resolveClaustrumConnectionPath(explicit) {
|
|
|
21280
21321
|
// src/common-auth-embedded/logger/engine.js
|
|
21281
21322
|
import { appendFileSync as appendFileSync2, chmodSync as chmodSync2, existsSync as existsSync2, renameSync as renameSync2, statSync as statSync3 } from "node:fs";
|
|
21282
21323
|
import { open as open8 } from "node:fs/promises";
|
|
21283
|
-
import { dirname as
|
|
21324
|
+
import { dirname as dirname14, resolve as resolve11 } from "node:path";
|
|
21284
21325
|
|
|
21285
21326
|
// src/common-auth-embedded/fs/private-files.js
|
|
21286
21327
|
import { randomUUID as randomUUID11 } from "node:crypto";
|
|
21287
21328
|
import { lstat as lstat5, readFile as readFile7, rename as rename7, unlink as unlink8 } from "node:fs/promises";
|
|
21288
21329
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
21289
|
-
import { dirname as
|
|
21330
|
+
import { dirname as dirname13, join as join9, resolve as resolve10 } from "node:path";
|
|
21290
21331
|
var windowsPrivateFiles2 = process.platform === "win32";
|
|
21291
21332
|
var migrationNotices2 = /* @__PURE__ */ new Set();
|
|
21292
21333
|
function ioCode2(detail) {
|
|
@@ -21393,7 +21434,7 @@ async function verifyPrivate2(path2, kind, migrate = false) {
|
|
|
21393
21434
|
api.NULL_DACL,
|
|
21394
21435
|
api.EMPTY_DACL
|
|
21395
21436
|
].includes(reason)) {
|
|
21396
|
-
await verifySafeDirectory2(
|
|
21437
|
+
await verifySafeDirectory2(dirname13(path2));
|
|
21397
21438
|
await api.securePrivatePath(path2, kind);
|
|
21398
21439
|
repaired = true;
|
|
21399
21440
|
} else {
|
|
@@ -21410,7 +21451,7 @@ async function verifyPrivate2(path2, kind, migrate = false) {
|
|
|
21410
21451
|
}
|
|
21411
21452
|
});
|
|
21412
21453
|
}
|
|
21413
|
-
async function
|
|
21454
|
+
async function ensurePrivateDirectory2(path2, _migrate = false, options) {
|
|
21414
21455
|
path2 = resolve10(path2);
|
|
21415
21456
|
await privateOperation2(path2, "directory", async () => {
|
|
21416
21457
|
const api = await loadBackend2();
|
|
@@ -21421,10 +21462,10 @@ async function ensurePrivateDirectory3(path2, _migrate = false, options) {
|
|
|
21421
21462
|
if (ioCode2(error) !== "ENOENT")
|
|
21422
21463
|
throw error;
|
|
21423
21464
|
}
|
|
21424
|
-
const parent =
|
|
21465
|
+
const parent = dirname13(path2);
|
|
21425
21466
|
if (parent === path2)
|
|
21426
21467
|
throw Object.assign(new Error("Missing root"), { code: "ENOENT" });
|
|
21427
|
-
await
|
|
21468
|
+
await ensurePrivateDirectory2(parent, false, options);
|
|
21428
21469
|
try {
|
|
21429
21470
|
await api.createOwnerOnly(path2, { kind: "dir" });
|
|
21430
21471
|
} catch (error) {
|
|
@@ -21444,19 +21485,19 @@ async function readPrivateBuffer2(path2, migrate = false) {
|
|
|
21444
21485
|
return readFile7(path2);
|
|
21445
21486
|
path2 = resolve10(path2);
|
|
21446
21487
|
if (migrate) {
|
|
21447
|
-
await verifySafeDirectory2(
|
|
21488
|
+
await verifySafeDirectory2(dirname13(path2));
|
|
21448
21489
|
await verifyPrivate2(path2, "file", true);
|
|
21449
21490
|
}
|
|
21450
21491
|
return privateOperation2(path2, "read", async () => (await loadBackend2()).readOwnerOnly(path2));
|
|
21451
21492
|
}
|
|
21452
21493
|
async function createPrivateBytes2(path2, bytes) {
|
|
21453
|
-
await verifySafeDirectory2(
|
|
21494
|
+
await verifySafeDirectory2(dirname13(resolve10(path2)));
|
|
21454
21495
|
await privateOperation2(path2, "create", async () => {
|
|
21455
21496
|
await (await loadBackend2()).createPrivateFile(resolve10(path2), bytes);
|
|
21456
21497
|
});
|
|
21457
21498
|
}
|
|
21458
21499
|
async function createPrivateDirectoryExclusive2(path2) {
|
|
21459
|
-
await verifySafeDirectory2(
|
|
21500
|
+
await verifySafeDirectory2(dirname13(resolve10(path2)));
|
|
21460
21501
|
await privateOperation2(path2, "directory-create", async () => {
|
|
21461
21502
|
await (await loadBackend2()).createOwnerOnly(resolve10(path2), { kind: "dir" });
|
|
21462
21503
|
});
|
|
@@ -21507,7 +21548,7 @@ async function replaceWindowsFile2(from, to, options = {}) {
|
|
|
21507
21548
|
}
|
|
21508
21549
|
async function writePrivateAtomic2(path2, bytes, options = {}) {
|
|
21509
21550
|
path2 = resolve10(path2);
|
|
21510
|
-
await
|
|
21551
|
+
await ensurePrivateDirectory2(dirname13(path2));
|
|
21511
21552
|
try {
|
|
21512
21553
|
await verifyPrivate2(path2, "file", true);
|
|
21513
21554
|
} catch (error) {
|
|
@@ -21515,7 +21556,7 @@ async function writePrivateAtomic2(path2, bytes, options = {}) {
|
|
|
21515
21556
|
throw error;
|
|
21516
21557
|
}
|
|
21517
21558
|
const stage = resolve10(options.stagePath ?? `${path2}.${randomUUID11()}.tmp`);
|
|
21518
|
-
if (
|
|
21559
|
+
if (dirname13(stage) !== dirname13(path2))
|
|
21519
21560
|
throw new PrivateFileError2(path2, "stage-directory", { code: "EXDEV" });
|
|
21520
21561
|
let created = false;
|
|
21521
21562
|
let published = false;
|
|
@@ -21680,7 +21721,7 @@ async function closeWindowsFile2(sink) {
|
|
|
21680
21721
|
await privateOperation2(file, "log-close", () => handle.close());
|
|
21681
21722
|
}
|
|
21682
21723
|
async function openWindowsFile2(sink, file) {
|
|
21683
|
-
await
|
|
21724
|
+
await ensurePrivateDirectory2(dirname14(file));
|
|
21684
21725
|
try {
|
|
21685
21726
|
await verifyPrivate2(file, "file", true);
|
|
21686
21727
|
} catch (error) {
|
|
@@ -21932,130 +21973,14 @@ import {
|
|
|
21932
21973
|
statSync as statSync4,
|
|
21933
21974
|
unlinkSync as unlinkSync2
|
|
21934
21975
|
} from "node:fs";
|
|
21935
|
-
import {
|
|
21936
|
-
import { join as join11 } from "node:path";
|
|
21976
|
+
import { join as join13 } from "node:path";
|
|
21937
21977
|
import { env } from "node:process";
|
|
21938
21978
|
|
|
21939
|
-
// src/
|
|
21940
|
-
|
|
21941
|
-
|
|
21942
|
-
}
|
|
21943
|
-
|
|
21944
|
-
const trimmed = flag.trim();
|
|
21945
|
-
if (trimmed === "2" || trimmed === "verbose") return 2;
|
|
21946
|
-
if (trimmed === "1" || trimmed === "true") return 1;
|
|
21947
|
-
return 0;
|
|
21948
|
-
}
|
|
21949
|
-
function deriveDebugPolicy(input) {
|
|
21950
|
-
const envDebugFlag = input.envDebugFlag ?? "";
|
|
21951
|
-
const debugLevel = input.configDebug ? envDebugFlag === "2" || envDebugFlag === "verbose" ? 2 : 1 : parseDebugLevel(envDebugFlag);
|
|
21952
|
-
const debugEnabled = debugLevel >= 1;
|
|
21953
|
-
const verboseEnabled = debugLevel >= 2;
|
|
21954
|
-
const debugTuiEnabled = debugEnabled && (input.configDebugTui || isTruthyFlag2(input.envDebugTuiFlag));
|
|
21955
|
-
return {
|
|
21956
|
-
debugLevel,
|
|
21957
|
-
debugEnabled,
|
|
21958
|
-
debugTuiEnabled,
|
|
21959
|
-
verboseEnabled
|
|
21960
|
-
};
|
|
21961
|
-
}
|
|
21962
|
-
function formatAccountLabel(email, accountIndex) {
|
|
21963
|
-
return email || `Account ${accountIndex + 1}`;
|
|
21964
|
-
}
|
|
21965
|
-
function formatAccountContextLabel(email, accountIndex) {
|
|
21966
|
-
if (email) {
|
|
21967
|
-
return email;
|
|
21968
|
-
}
|
|
21969
|
-
if (accountIndex >= 0) {
|
|
21970
|
-
return `Account ${accountIndex + 1}`;
|
|
21971
|
-
}
|
|
21972
|
-
return "All accounts";
|
|
21973
|
-
}
|
|
21974
|
-
function formatErrorForLog(error) {
|
|
21975
|
-
if (error instanceof Error) {
|
|
21976
|
-
return error.stack ?? error.message;
|
|
21977
|
-
}
|
|
21978
|
-
try {
|
|
21979
|
-
return JSON.stringify(error);
|
|
21980
|
-
} catch {
|
|
21981
|
-
return String(error);
|
|
21982
|
-
}
|
|
21983
|
-
}
|
|
21984
|
-
function truncateTextForLog(text2, maxChars) {
|
|
21985
|
-
if (text2.length <= maxChars) {
|
|
21986
|
-
return text2;
|
|
21987
|
-
}
|
|
21988
|
-
return `${text2.slice(0, maxChars)}... (truncated ${text2.length - maxChars} chars)`;
|
|
21989
|
-
}
|
|
21990
|
-
function formatBodyPreviewForLog(body, maxChars) {
|
|
21991
|
-
if (body == null) {
|
|
21992
|
-
return void 0;
|
|
21993
|
-
}
|
|
21994
|
-
if (typeof body === "string") {
|
|
21995
|
-
return truncateTextForLog(body, maxChars);
|
|
21996
|
-
}
|
|
21997
|
-
if (body instanceof URLSearchParams) {
|
|
21998
|
-
return truncateTextForLog(body.toString(), maxChars);
|
|
21999
|
-
}
|
|
22000
|
-
if (typeof Blob !== "undefined" && body instanceof Blob) {
|
|
22001
|
-
return `[Blob size=${body.size}]`;
|
|
22002
|
-
}
|
|
22003
|
-
if (typeof FormData !== "undefined" && body instanceof FormData) {
|
|
22004
|
-
return "[FormData payload omitted]";
|
|
22005
|
-
}
|
|
22006
|
-
return `[${body.constructor?.name ?? typeof body} payload omitted]`;
|
|
22007
|
-
}
|
|
22008
|
-
function writeConsoleLog2(level, ...args) {
|
|
22009
|
-
switch (level) {
|
|
22010
|
-
case "debug":
|
|
22011
|
-
console.debug(...args);
|
|
22012
|
-
break;
|
|
22013
|
-
case "info":
|
|
22014
|
-
console.info(...args);
|
|
22015
|
-
break;
|
|
22016
|
-
case "warn":
|
|
22017
|
-
console.warn(...args);
|
|
22018
|
-
break;
|
|
22019
|
-
case "error":
|
|
22020
|
-
console.error(...args);
|
|
22021
|
-
break;
|
|
22022
|
-
}
|
|
22023
|
-
}
|
|
22024
|
-
function redactSensitive(value) {
|
|
22025
|
-
return maskSensitiveIdentifier(value);
|
|
22026
|
-
}
|
|
22027
|
-
var SENSITIVE_FIELD_PATTERN = /token|refresh|access|project|fingerprint|deviceId|sessionId|sessionToken|secret|password|apiKey|clientSecret/i;
|
|
22028
|
-
function redactSensitiveFields(value) {
|
|
22029
|
-
if (value == null) return value;
|
|
22030
|
-
if (Array.isArray(value)) return value.map(redactSensitiveFields);
|
|
22031
|
-
if (typeof value === "object") {
|
|
22032
|
-
const record3 = value;
|
|
22033
|
-
const redacted = {};
|
|
22034
|
-
for (const [key, entry] of Object.entries(record3)) {
|
|
22035
|
-
if (SENSITIVE_FIELD_PATTERN.test(key) && typeof entry === "string") {
|
|
22036
|
-
redacted[key] = redactSensitive(entry);
|
|
22037
|
-
} else {
|
|
22038
|
-
redacted[key] = redactSensitiveFields(entry);
|
|
22039
|
-
}
|
|
22040
|
-
}
|
|
22041
|
-
return redacted;
|
|
22042
|
-
}
|
|
22043
|
-
return value;
|
|
22044
|
-
}
|
|
22045
|
-
function redactJsonBodyString(body) {
|
|
22046
|
-
let parsed;
|
|
22047
|
-
try {
|
|
22048
|
-
parsed = JSON.parse(body);
|
|
22049
|
-
} catch {
|
|
22050
|
-
return body;
|
|
22051
|
-
}
|
|
22052
|
-
if (parsed == null || typeof parsed !== "object") return body;
|
|
22053
|
-
return JSON.stringify(redactSensitiveFields(parsed));
|
|
22054
|
-
}
|
|
22055
|
-
function redactBodyForLog(body) {
|
|
22056
|
-
if (typeof body === "string") return redactJsonBodyString(body);
|
|
22057
|
-
return body;
|
|
22058
|
-
}
|
|
21979
|
+
// src/runtime-paths.ts
|
|
21980
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
21981
|
+
import { existsSync as existsSync4, realpathSync } from "node:fs";
|
|
21982
|
+
import { homedir as homedir4 } from "node:os";
|
|
21983
|
+
import { dirname as dirname16, join as join12, resolve as resolve13 } from "node:path";
|
|
22059
21984
|
|
|
22060
21985
|
// src/plugin/storage.ts
|
|
22061
21986
|
import {
|
|
@@ -22070,16 +21995,14 @@ import {
|
|
|
22070
21995
|
writeFileSync
|
|
22071
21996
|
} from "node:fs";
|
|
22072
21997
|
import { homedir as homedir2 } from "node:os";
|
|
22073
|
-
import { dirname as
|
|
21998
|
+
import { dirname as dirname15, join as join10, resolve as resolve12 } from "node:path";
|
|
22074
21999
|
var log5 = createLogger4("storage");
|
|
22075
22000
|
var GITIGNORE_ENTRIES = [
|
|
22076
22001
|
"antigravity-accounts.json",
|
|
22077
22002
|
"antigravity-accounts.json.*.tmp",
|
|
22078
22003
|
// The account store's generation directories hold credential files; its
|
|
22079
22004
|
// pointer file names the current generation only.
|
|
22080
|
-
"antigravity-accounts.json.store*"
|
|
22081
|
-
"antigravity-signature-cache.json",
|
|
22082
|
-
"antigravity-logs/"
|
|
22005
|
+
"antigravity-accounts.json.store*"
|
|
22083
22006
|
];
|
|
22084
22007
|
async function ensureGitignore(configDir) {
|
|
22085
22008
|
const gitignorePath = join10(configDir, ".gitignore");
|
|
@@ -22127,45 +22050,6 @@ async function ensureGitignore(configDir) {
|
|
|
22127
22050
|
});
|
|
22128
22051
|
}
|
|
22129
22052
|
}
|
|
22130
|
-
function ensureGitignoreSync(configDir) {
|
|
22131
|
-
const gitignorePath = join10(configDir, ".gitignore");
|
|
22132
|
-
try {
|
|
22133
|
-
let content;
|
|
22134
|
-
let existingLines = [];
|
|
22135
|
-
if (existsSync3(gitignorePath)) {
|
|
22136
|
-
content = readFileSync(gitignorePath, "utf-8");
|
|
22137
|
-
existingLines = content.split("\n").map((line) => line.trim());
|
|
22138
|
-
} else {
|
|
22139
|
-
content = "";
|
|
22140
|
-
}
|
|
22141
|
-
const missingEntries = GITIGNORE_ENTRIES.filter(
|
|
22142
|
-
(entry) => !existingLines.includes(entry)
|
|
22143
|
-
);
|
|
22144
|
-
if (missingEntries.length === 0) {
|
|
22145
|
-
return;
|
|
22146
|
-
}
|
|
22147
|
-
if (content === "") {
|
|
22148
|
-
writeFileSync(gitignorePath, `${missingEntries.join("\n")}
|
|
22149
|
-
`, "utf-8");
|
|
22150
|
-
log5.info("Created .gitignore in config directory");
|
|
22151
|
-
} else {
|
|
22152
|
-
const suffix = content.endsWith("\n") ? "" : "\n";
|
|
22153
|
-
appendFileSync3(
|
|
22154
|
-
gitignorePath,
|
|
22155
|
-
`${suffix + missingEntries.join("\n")}
|
|
22156
|
-
`,
|
|
22157
|
-
"utf-8"
|
|
22158
|
-
);
|
|
22159
|
-
log5.info("Updated .gitignore with missing entries", {
|
|
22160
|
-
added: missingEntries
|
|
22161
|
-
});
|
|
22162
|
-
}
|
|
22163
|
-
} catch (error) {
|
|
22164
|
-
log5.warn("Failed to update .gitignore with account storage entries", {
|
|
22165
|
-
error: String(error)
|
|
22166
|
-
});
|
|
22167
|
-
}
|
|
22168
|
-
}
|
|
22169
22053
|
function getLegacyWindowsConfigDir() {
|
|
22170
22054
|
return join10(
|
|
22171
22055
|
process.env.APPDATA || join10(homedir2(), "AppData", "Roaming"),
|
|
@@ -22349,79 +22233,453 @@ function initializeFreshAccountStoreFor(modules, options = {}) {
|
|
|
22349
22233
|
async function loadAccounts() {
|
|
22350
22234
|
const path2 = getStoragePath();
|
|
22351
22235
|
await assertLegacyPoolInUse(path2);
|
|
22352
|
-
await ensureGitignore(
|
|
22236
|
+
await ensureGitignore(dirname15(path2));
|
|
22353
22237
|
return loadAccountStorage(path2);
|
|
22354
22238
|
}
|
|
22355
22239
|
|
|
22356
|
-
// src/
|
|
22357
|
-
|
|
22358
|
-
|
|
22359
|
-
|
|
22360
|
-
function
|
|
22361
|
-
|
|
22362
|
-
if (platform === "win32") {
|
|
22363
|
-
return join11(
|
|
22364
|
-
env.APPDATA || join11(homedir3(), "AppData", "Roaming"),
|
|
22365
|
-
"opencode"
|
|
22366
|
-
);
|
|
22367
|
-
}
|
|
22368
|
-
const xdgConfig2 = env.XDG_CONFIG_HOME || join11(homedir3(), ".config");
|
|
22369
|
-
return join11(xdgConfig2, "opencode");
|
|
22240
|
+
// src/version-fence.ts
|
|
22241
|
+
import { readdir as readdir2, readFile as readFile8 } from "node:fs/promises";
|
|
22242
|
+
import { homedir as homedir3 } from "node:os";
|
|
22243
|
+
import { join as join11 } from "node:path";
|
|
22244
|
+
function defaultStateHome() {
|
|
22245
|
+
return process.env.XDG_STATE_HOME || join11(homedir3(), ".local", "state");
|
|
22370
22246
|
}
|
|
22371
|
-
function
|
|
22372
|
-
|
|
22247
|
+
function processHeartbeatDir(stateHome = defaultStateHome()) {
|
|
22248
|
+
return join11(stateHome, "cortexkit", "antigravity-auth", "processes");
|
|
22249
|
+
}
|
|
22250
|
+
function rpcStateRoot(stateHome = defaultStateHome()) {
|
|
22251
|
+
return join11(stateHome, "cortexkit", "antigravity-auth", "rpc");
|
|
22252
|
+
}
|
|
22253
|
+
function isRpcProjectDir(name) {
|
|
22254
|
+
return /^[0-9a-f]{16}$/.test(name);
|
|
22255
|
+
}
|
|
22256
|
+
function pidAlive(pid) {
|
|
22373
22257
|
try {
|
|
22374
|
-
|
|
22375
|
-
|
|
22258
|
+
process.kill(pid, 0);
|
|
22259
|
+
return true;
|
|
22260
|
+
} catch (error) {
|
|
22261
|
+
return error.code === "EPERM";
|
|
22376
22262
|
}
|
|
22377
|
-
return logsDir;
|
|
22378
22263
|
}
|
|
22379
|
-
function
|
|
22380
|
-
const
|
|
22381
|
-
|
|
22382
|
-
|
|
22383
|
-
|
|
22384
|
-
|
|
22385
|
-
|
|
22264
|
+
function parseSemver(value) {
|
|
22265
|
+
const match = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z.-]+)?$/.exec(
|
|
22266
|
+
value.trim()
|
|
22267
|
+
);
|
|
22268
|
+
if (!match) return void 0;
|
|
22269
|
+
return {
|
|
22270
|
+
core: [Number(match[1]), Number(match[2]), Number(match[3])],
|
|
22271
|
+
pre: match[4] ? match[4].split(".") : []
|
|
22272
|
+
};
|
|
22273
|
+
}
|
|
22274
|
+
function compareVersions(a, b) {
|
|
22275
|
+
const left = parseSemver(a);
|
|
22276
|
+
const right = parseSemver(b);
|
|
22277
|
+
if (!left || !right) return void 0;
|
|
22278
|
+
for (let i = 0; i < 3; i++) {
|
|
22279
|
+
const diff = left.core[i] - right.core[i];
|
|
22280
|
+
if (diff !== 0) return Math.sign(diff);
|
|
22281
|
+
}
|
|
22282
|
+
if (left.pre.length === 0 || right.pre.length === 0)
|
|
22283
|
+
return Math.sign(right.pre.length - left.pre.length);
|
|
22284
|
+
for (let i = 0; i < Math.max(left.pre.length, right.pre.length); i++) {
|
|
22285
|
+
const x = left.pre[i];
|
|
22286
|
+
const y = right.pre[i];
|
|
22287
|
+
if (x === void 0) return -1;
|
|
22288
|
+
if (y === void 0) return 1;
|
|
22289
|
+
const xNumeric = /^\d+$/.test(x);
|
|
22290
|
+
const yNumeric = /^\d+$/.test(y);
|
|
22291
|
+
if (xNumeric && yNumeric) {
|
|
22292
|
+
const diff = Number(x) - Number(y);
|
|
22293
|
+
if (diff !== 0) return Math.sign(diff);
|
|
22294
|
+
} else if (xNumeric !== yNumeric) {
|
|
22295
|
+
return xNumeric ? -1 : 1;
|
|
22296
|
+
} else if (x !== y) {
|
|
22297
|
+
return x < y ? -1 : 1;
|
|
22298
|
+
}
|
|
22386
22299
|
}
|
|
22387
|
-
return
|
|
22300
|
+
return 0;
|
|
22388
22301
|
}
|
|
22389
|
-
function
|
|
22302
|
+
async function list2(dir) {
|
|
22390
22303
|
try {
|
|
22391
|
-
|
|
22392
|
-
|
|
22393
|
-
|
|
22394
|
-
if (
|
|
22395
|
-
|
|
22396
|
-
}
|
|
22397
|
-
const sortedFiles = files.map((file) => ({
|
|
22398
|
-
file,
|
|
22399
|
-
mtime: statSync4(file).mtimeMs
|
|
22400
|
-
})).sort((a, b) => b.mtime - a.mtime);
|
|
22401
|
-
for (let i = maxFiles; i < sortedFiles.length; i++) {
|
|
22402
|
-
const file = sortedFiles[i].file;
|
|
22403
|
-
if (liveLogFilePaths.has(file)) continue;
|
|
22404
|
-
try {
|
|
22405
|
-
unlinkSync2(file);
|
|
22406
|
-
} catch {
|
|
22407
|
-
}
|
|
22408
|
-
}
|
|
22409
|
-
} catch {
|
|
22304
|
+
return { ok: true, names: await readdir2(dir) };
|
|
22305
|
+
} catch (error) {
|
|
22306
|
+
const code2 = error.code;
|
|
22307
|
+
if (code2 === "ENOENT") return { ok: true, names: [] };
|
|
22308
|
+
return { ok: false, code: code2, error: `${dir}: ${String(error)}` };
|
|
22410
22309
|
}
|
|
22411
22310
|
}
|
|
22412
|
-
function
|
|
22413
|
-
|
|
22414
|
-
|
|
22415
|
-
|
|
22311
|
+
async function readProcessRecord(path2, pid) {
|
|
22312
|
+
let text2;
|
|
22313
|
+
try {
|
|
22314
|
+
text2 = await readFile8(path2, "utf8");
|
|
22315
|
+
} catch (error) {
|
|
22316
|
+
if (error.code === "ENOENT")
|
|
22317
|
+
return { kind: "gone" };
|
|
22318
|
+
return { kind: "unreadable" };
|
|
22416
22319
|
}
|
|
22417
22320
|
try {
|
|
22418
|
-
const
|
|
22419
|
-
|
|
22420
|
-
|
|
22421
|
-
|
|
22422
|
-
|
|
22423
|
-
|
|
22424
|
-
|
|
22321
|
+
const value = JSON.parse(text2);
|
|
22322
|
+
if (value !== null && typeof value === "object" && value.pid === pid && typeof value.version === "string") {
|
|
22323
|
+
const layouts = value.layouts;
|
|
22324
|
+
return {
|
|
22325
|
+
kind: "ok",
|
|
22326
|
+
version: value.version,
|
|
22327
|
+
...layouts !== null && typeof layouts === "object" && !Array.isArray(layouts) ? { layouts } : {}
|
|
22328
|
+
};
|
|
22329
|
+
}
|
|
22330
|
+
} catch {
|
|
22331
|
+
}
|
|
22332
|
+
return { kind: "unreadable" };
|
|
22333
|
+
}
|
|
22334
|
+
async function versionFenceOpen(options) {
|
|
22335
|
+
const isAlive = options.isAlive ?? pidAlive;
|
|
22336
|
+
const self = options.selfPid ?? process.pid;
|
|
22337
|
+
const blockers = /* @__PURE__ */ new Map();
|
|
22338
|
+
const block = (entry) => {
|
|
22339
|
+
const key = entry.pid === "unknown" ? `dir:${entry.detail}` : entry.pid;
|
|
22340
|
+
if (!blockers.has(key)) blockers.set(key, entry);
|
|
22341
|
+
};
|
|
22342
|
+
const alive = (pid) => {
|
|
22343
|
+
try {
|
|
22344
|
+
return isAlive(pid);
|
|
22345
|
+
} catch {
|
|
22346
|
+
return true;
|
|
22347
|
+
}
|
|
22348
|
+
};
|
|
22349
|
+
const pidFrom = (name, pattern) => {
|
|
22350
|
+
const match = pattern.exec(name);
|
|
22351
|
+
const pid = match ? Number(match[1]) : Number.NaN;
|
|
22352
|
+
return Number.isSafeInteger(pid) && pid >= 1 ? pid : void 0;
|
|
22353
|
+
};
|
|
22354
|
+
const heartbeatDir = processHeartbeatDir(options.stateHome);
|
|
22355
|
+
const heartbeats = await list2(heartbeatDir);
|
|
22356
|
+
if (!heartbeats.ok)
|
|
22357
|
+
block({ pid: "unknown", version: "unknown", detail: heartbeats.error });
|
|
22358
|
+
for (const name of heartbeats.ok ? heartbeats.names : []) {
|
|
22359
|
+
const pid = pidFrom(name, /^(\d+)\.json$/);
|
|
22360
|
+
if (pid === void 0 || pid === self) continue;
|
|
22361
|
+
const path2 = join11(heartbeatDir, name);
|
|
22362
|
+
const heartbeat = await readProcessRecord(path2, pid);
|
|
22363
|
+
if (heartbeat.kind === "gone") continue;
|
|
22364
|
+
if (!alive(pid)) continue;
|
|
22365
|
+
if (heartbeat.kind === "unreadable") {
|
|
22366
|
+
block({ pid, version: "unknown", detail: path2 });
|
|
22367
|
+
continue;
|
|
22368
|
+
}
|
|
22369
|
+
const order = compareVersions(heartbeat.version, options.currentVersion);
|
|
22370
|
+
if (order === void 0 || order < 0) {
|
|
22371
|
+
block({ pid, version: heartbeat.version, detail: path2 });
|
|
22372
|
+
continue;
|
|
22373
|
+
}
|
|
22374
|
+
if (options.layoutMove === true && (heartbeat.layouts === void 0 || Object.values(heartbeat.layouts).includes("legacy")))
|
|
22375
|
+
block({ pid, version: heartbeat.version, detail: path2 });
|
|
22376
|
+
}
|
|
22377
|
+
const rpcRoot = options.rpcDir ?? rpcStateRoot(options.stateHome);
|
|
22378
|
+
const projects = await list2(rpcRoot);
|
|
22379
|
+
if (!projects.ok)
|
|
22380
|
+
block({ pid: "unknown", version: "unknown", detail: projects.error });
|
|
22381
|
+
for (const project2 of projects.ok ? projects.names : []) {
|
|
22382
|
+
if (!isRpcProjectDir(project2)) continue;
|
|
22383
|
+
const dir = join11(rpcRoot, project2);
|
|
22384
|
+
const ports = await list2(dir);
|
|
22385
|
+
if (!ports.ok) {
|
|
22386
|
+
if (ports.code === "ENOTDIR") continue;
|
|
22387
|
+
block({ pid: "unknown", version: "unknown", detail: ports.error });
|
|
22388
|
+
continue;
|
|
22389
|
+
}
|
|
22390
|
+
for (const name of ports.names) {
|
|
22391
|
+
const pid = pidFrom(name, /^port-(\d+)\.json$/);
|
|
22392
|
+
if (pid === void 0 || pid === self || !alive(pid)) continue;
|
|
22393
|
+
const path2 = join11(dir, name);
|
|
22394
|
+
const port = await readProcessRecord(path2, pid);
|
|
22395
|
+
if (port.kind === "gone") continue;
|
|
22396
|
+
const version = port.kind === "ok" ? port.version : "unknown";
|
|
22397
|
+
const order = compareVersions(version, options.currentVersion);
|
|
22398
|
+
if (order === void 0 || order < 0)
|
|
22399
|
+
block({ pid, version, detail: path2 });
|
|
22400
|
+
}
|
|
22401
|
+
}
|
|
22402
|
+
const rank = (b) => b.pid === "unknown" ? Number.POSITIVE_INFINITY : b.pid;
|
|
22403
|
+
return blockers.size === 0 ? { open: true } : {
|
|
22404
|
+
open: false,
|
|
22405
|
+
blockers: [...blockers.values()].sort((a, b) => rank(a) - rank(b))
|
|
22406
|
+
};
|
|
22407
|
+
}
|
|
22408
|
+
|
|
22409
|
+
// src/runtime-paths.ts
|
|
22410
|
+
var RUNTIME_LAYOUT_MARKER_FILE = "layout.json";
|
|
22411
|
+
var RUNTIME_CONFIG_DIR_NOTE_FILE = "config-dir.json";
|
|
22412
|
+
var VAULT_DIR_NAME = "antigravity-auth-vault";
|
|
22413
|
+
var ACCOUNT_FILE_NAME = "antigravity-accounts.json";
|
|
22414
|
+
function configDirIdentity(path2) {
|
|
22415
|
+
try {
|
|
22416
|
+
return realpathSync.native(path2);
|
|
22417
|
+
} catch {
|
|
22418
|
+
return resolve13(path2);
|
|
22419
|
+
}
|
|
22420
|
+
}
|
|
22421
|
+
var decisionsKey = /* @__PURE__ */ Symbol.for("@cortexkit/antigravity-auth/runtime-layouts");
|
|
22422
|
+
var decisionState = globalThis;
|
|
22423
|
+
var shared = decisionState[decisionsKey] ?? {
|
|
22424
|
+
decisions: /* @__PURE__ */ new Map(),
|
|
22425
|
+
locations: /* @__PURE__ */ new Map()
|
|
22426
|
+
};
|
|
22427
|
+
decisionState[decisionsKey] = shared;
|
|
22428
|
+
function decisionKey(location) {
|
|
22429
|
+
return `${location.stateHomeDir}\0${location.key}`;
|
|
22430
|
+
}
|
|
22431
|
+
function runtimeLayoutLocation(configDir = getConfigDir()) {
|
|
22432
|
+
const stateHome = defaultStateHome();
|
|
22433
|
+
const homeConfig = join12(homedir4(), ".config", "opencode");
|
|
22434
|
+
const cacheKey = `${configDir}\0${homeConfig}\0${stateHome}`;
|
|
22435
|
+
const cached = shared.locations.get(cacheKey);
|
|
22436
|
+
if (cached && shared.decisions.has(decisionKey(cached))) return cached;
|
|
22437
|
+
const key = configDirIdentity(configDir);
|
|
22438
|
+
if (cached && cached.key === key) return cached;
|
|
22439
|
+
const isDefaultConfigDir = key === configDirIdentity(homeConfig);
|
|
22440
|
+
const root = join12(stateHome, "cortexkit", "antigravity-auth");
|
|
22441
|
+
const location = {
|
|
22442
|
+
key,
|
|
22443
|
+
configDir,
|
|
22444
|
+
stateHomeDir: isDefaultConfigDir ? join12(root, "opencode") : join12(
|
|
22445
|
+
root,
|
|
22446
|
+
`opencode-${createHash10("sha256").update(key).digest("hex").slice(0, 16)}`
|
|
22447
|
+
),
|
|
22448
|
+
isDefaultConfigDir
|
|
22449
|
+
};
|
|
22450
|
+
shared.locations.set(cacheKey, location);
|
|
22451
|
+
return location;
|
|
22452
|
+
}
|
|
22453
|
+
function setRuntimeLayout(location, layout) {
|
|
22454
|
+
shared.decisions.set(decisionKey(location), layout);
|
|
22455
|
+
}
|
|
22456
|
+
function decidedRuntimeLayout(location) {
|
|
22457
|
+
return shared.decisions.get(decisionKey(location));
|
|
22458
|
+
}
|
|
22459
|
+
function currentRuntimeLayout(location = runtimeLayoutLocation()) {
|
|
22460
|
+
return decidedRuntimeLayout(location) ?? (existsSync4(join12(location.stateHomeDir, RUNTIME_LAYOUT_MARKER_FILE)) ? "state-home" : "legacy");
|
|
22461
|
+
}
|
|
22462
|
+
function legacyWindowsConfigDir() {
|
|
22463
|
+
return join12(
|
|
22464
|
+
process.env.APPDATA || join12(homedir4(), "AppData", "Roaming"),
|
|
22465
|
+
"opencode"
|
|
22466
|
+
);
|
|
22467
|
+
}
|
|
22468
|
+
function pluginStateDir() {
|
|
22469
|
+
return join12(defaultStateHome(), "cortexkit", "antigravity-auth");
|
|
22470
|
+
}
|
|
22471
|
+
var SIGNATURE_CACHE_FILE_NAME = "antigravity-signature-cache.json";
|
|
22472
|
+
function legacySignatureCacheFile() {
|
|
22473
|
+
const configHome = process.platform === "win32" ? legacyWindowsConfigDir() : join12(
|
|
22474
|
+
process.env.XDG_CONFIG_HOME || join12(homedir4(), ".config"),
|
|
22475
|
+
"opencode"
|
|
22476
|
+
);
|
|
22477
|
+
return join12(configHome, SIGNATURE_CACHE_FILE_NAME);
|
|
22478
|
+
}
|
|
22479
|
+
function stateHomeLogsDir() {
|
|
22480
|
+
return join12(pluginStateDir(), "logs");
|
|
22481
|
+
}
|
|
22482
|
+
function legacyAccountFile(configDir = getConfigDir()) {
|
|
22483
|
+
const standard = join12(configDir, ACCOUNT_FILE_NAME);
|
|
22484
|
+
if (process.platform !== "win32" || existsSync4(standard)) return standard;
|
|
22485
|
+
const windows = join12(legacyWindowsConfigDir(), ACCOUNT_FILE_NAME);
|
|
22486
|
+
return existsSync4(windows) ? windows : standard;
|
|
22487
|
+
}
|
|
22488
|
+
function legacyVaultDir(accountFile) {
|
|
22489
|
+
return join12(dirname16(accountFile), VAULT_DIR_NAME);
|
|
22490
|
+
}
|
|
22491
|
+
function stateHomeVaultDir(location) {
|
|
22492
|
+
return join12(location.stateHomeDir, VAULT_DIR_NAME);
|
|
22493
|
+
}
|
|
22494
|
+
function getVaultDir(accountFile, configDir = getConfigDir()) {
|
|
22495
|
+
const location = runtimeLayoutLocation(configDir);
|
|
22496
|
+
return currentRuntimeLayout(location) === "state-home" ? stateHomeVaultDir(location) : legacyVaultDir(accountFile ?? legacyAccountFile(configDir));
|
|
22497
|
+
}
|
|
22498
|
+
|
|
22499
|
+
// src/plugin/logging-utils.ts
|
|
22500
|
+
function isTruthyFlag2(flag) {
|
|
22501
|
+
return flag === "1" || flag?.toLowerCase() === "true";
|
|
22502
|
+
}
|
|
22503
|
+
function parseDebugLevel(flag) {
|
|
22504
|
+
const trimmed = flag.trim();
|
|
22505
|
+
if (trimmed === "2" || trimmed === "verbose") return 2;
|
|
22506
|
+
if (trimmed === "1" || trimmed === "true") return 1;
|
|
22507
|
+
return 0;
|
|
22508
|
+
}
|
|
22509
|
+
function deriveDebugPolicy(input) {
|
|
22510
|
+
const envDebugFlag = input.envDebugFlag ?? "";
|
|
22511
|
+
const debugLevel = input.configDebug ? envDebugFlag === "2" || envDebugFlag === "verbose" ? 2 : 1 : parseDebugLevel(envDebugFlag);
|
|
22512
|
+
const debugEnabled = debugLevel >= 1;
|
|
22513
|
+
const verboseEnabled = debugLevel >= 2;
|
|
22514
|
+
const debugTuiEnabled = debugEnabled && (input.configDebugTui || isTruthyFlag2(input.envDebugTuiFlag));
|
|
22515
|
+
return {
|
|
22516
|
+
debugLevel,
|
|
22517
|
+
debugEnabled,
|
|
22518
|
+
debugTuiEnabled,
|
|
22519
|
+
verboseEnabled
|
|
22520
|
+
};
|
|
22521
|
+
}
|
|
22522
|
+
function formatAccountLabel(email, accountIndex) {
|
|
22523
|
+
return email || `Account ${accountIndex + 1}`;
|
|
22524
|
+
}
|
|
22525
|
+
function formatAccountContextLabel(email, accountIndex) {
|
|
22526
|
+
if (email) {
|
|
22527
|
+
return email;
|
|
22528
|
+
}
|
|
22529
|
+
if (accountIndex >= 0) {
|
|
22530
|
+
return `Account ${accountIndex + 1}`;
|
|
22531
|
+
}
|
|
22532
|
+
return "All accounts";
|
|
22533
|
+
}
|
|
22534
|
+
function formatErrorForLog(error) {
|
|
22535
|
+
if (error instanceof Error) {
|
|
22536
|
+
return error.stack ?? error.message;
|
|
22537
|
+
}
|
|
22538
|
+
try {
|
|
22539
|
+
return JSON.stringify(error);
|
|
22540
|
+
} catch {
|
|
22541
|
+
return String(error);
|
|
22542
|
+
}
|
|
22543
|
+
}
|
|
22544
|
+
function truncateTextForLog(text2, maxChars) {
|
|
22545
|
+
if (text2.length <= maxChars) {
|
|
22546
|
+
return text2;
|
|
22547
|
+
}
|
|
22548
|
+
return `${text2.slice(0, maxChars)}... (truncated ${text2.length - maxChars} chars)`;
|
|
22549
|
+
}
|
|
22550
|
+
function formatBodyPreviewForLog(body, maxChars) {
|
|
22551
|
+
if (body == null) {
|
|
22552
|
+
return void 0;
|
|
22553
|
+
}
|
|
22554
|
+
if (typeof body === "string") {
|
|
22555
|
+
return truncateTextForLog(body, maxChars);
|
|
22556
|
+
}
|
|
22557
|
+
if (body instanceof URLSearchParams) {
|
|
22558
|
+
return truncateTextForLog(body.toString(), maxChars);
|
|
22559
|
+
}
|
|
22560
|
+
if (typeof Blob !== "undefined" && body instanceof Blob) {
|
|
22561
|
+
return `[Blob size=${body.size}]`;
|
|
22562
|
+
}
|
|
22563
|
+
if (typeof FormData !== "undefined" && body instanceof FormData) {
|
|
22564
|
+
return "[FormData payload omitted]";
|
|
22565
|
+
}
|
|
22566
|
+
return `[${body.constructor?.name ?? typeof body} payload omitted]`;
|
|
22567
|
+
}
|
|
22568
|
+
function writeConsoleLog2(level, ...args) {
|
|
22569
|
+
switch (level) {
|
|
22570
|
+
case "debug":
|
|
22571
|
+
console.debug(...args);
|
|
22572
|
+
break;
|
|
22573
|
+
case "info":
|
|
22574
|
+
console.info(...args);
|
|
22575
|
+
break;
|
|
22576
|
+
case "warn":
|
|
22577
|
+
console.warn(...args);
|
|
22578
|
+
break;
|
|
22579
|
+
case "error":
|
|
22580
|
+
console.error(...args);
|
|
22581
|
+
break;
|
|
22582
|
+
}
|
|
22583
|
+
}
|
|
22584
|
+
function redactSensitive(value) {
|
|
22585
|
+
return maskSensitiveIdentifier(value);
|
|
22586
|
+
}
|
|
22587
|
+
var SENSITIVE_FIELD_PATTERN = /token|refresh|access|project|fingerprint|deviceId|sessionId|sessionToken|secret|password|apiKey|clientSecret/i;
|
|
22588
|
+
function redactSensitiveFields(value) {
|
|
22589
|
+
if (value == null) return value;
|
|
22590
|
+
if (Array.isArray(value)) return value.map(redactSensitiveFields);
|
|
22591
|
+
if (typeof value === "object") {
|
|
22592
|
+
const record3 = value;
|
|
22593
|
+
const redacted = {};
|
|
22594
|
+
for (const [key, entry] of Object.entries(record3)) {
|
|
22595
|
+
if (SENSITIVE_FIELD_PATTERN.test(key) && typeof entry === "string") {
|
|
22596
|
+
redacted[key] = redactSensitive(entry);
|
|
22597
|
+
} else {
|
|
22598
|
+
redacted[key] = redactSensitiveFields(entry);
|
|
22599
|
+
}
|
|
22600
|
+
}
|
|
22601
|
+
return redacted;
|
|
22602
|
+
}
|
|
22603
|
+
return value;
|
|
22604
|
+
}
|
|
22605
|
+
function redactJsonBodyString(body) {
|
|
22606
|
+
let parsed;
|
|
22607
|
+
try {
|
|
22608
|
+
parsed = JSON.parse(body);
|
|
22609
|
+
} catch {
|
|
22610
|
+
return body;
|
|
22611
|
+
}
|
|
22612
|
+
if (parsed == null || typeof parsed !== "object") return body;
|
|
22613
|
+
return JSON.stringify(redactSensitiveFields(parsed));
|
|
22614
|
+
}
|
|
22615
|
+
function redactBodyForLog(body) {
|
|
22616
|
+
if (typeof body === "string") return redactJsonBodyString(body);
|
|
22617
|
+
return body;
|
|
22618
|
+
}
|
|
22619
|
+
|
|
22620
|
+
// src/plugin/debug.ts
|
|
22621
|
+
var MAX_BODY_PREVIEW_CHARS = 12e3;
|
|
22622
|
+
var MAX_BODY_LOG_CHARS = 5e4;
|
|
22623
|
+
var liveLogFilePaths = /* @__PURE__ */ new Set();
|
|
22624
|
+
function getLogsDir(customLogDir) {
|
|
22625
|
+
const logsDir = customLogDir || stateHomeLogsDir();
|
|
22626
|
+
try {
|
|
22627
|
+
mkdirSync2(logsDir, { recursive: true, mode: 448 });
|
|
22628
|
+
} catch {
|
|
22629
|
+
}
|
|
22630
|
+
return logsDir;
|
|
22631
|
+
}
|
|
22632
|
+
function requestedLogDir(configLogDir) {
|
|
22633
|
+
const fromEnv = env.OPENCODE_ANTIGRAVITY_LOG_DIR;
|
|
22634
|
+
if (fromEnv && fromEnv.trim() !== "") return fromEnv;
|
|
22635
|
+
return configLogDir || void 0;
|
|
22636
|
+
}
|
|
22637
|
+
function createLogFilePath(customLogDir) {
|
|
22638
|
+
const logsDir = getLogsDir(requestedLogDir(customLogDir));
|
|
22639
|
+
cleanupOldLogs(logsDir, 25);
|
|
22640
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
22641
|
+
let candidate = join13(logsDir, `antigravity-debug-${timestamp}.log`);
|
|
22642
|
+
for (let suffix = 2; liveLogFilePaths.has(candidate); suffix++) {
|
|
22643
|
+
candidate = join13(logsDir, `antigravity-debug-${timestamp}-${suffix}.log`);
|
|
22644
|
+
}
|
|
22645
|
+
return candidate;
|
|
22646
|
+
}
|
|
22647
|
+
function cleanupOldLogs(logsDir, maxFiles) {
|
|
22648
|
+
try {
|
|
22649
|
+
const files = readdirSync(logsDir).filter(
|
|
22650
|
+
(file) => file.startsWith("antigravity-debug-") && file.endsWith(".log")
|
|
22651
|
+
).map((file) => join13(logsDir, file));
|
|
22652
|
+
if (files.length <= maxFiles) {
|
|
22653
|
+
return;
|
|
22654
|
+
}
|
|
22655
|
+
const sortedFiles = files.map((file) => ({
|
|
22656
|
+
file,
|
|
22657
|
+
mtime: statSync4(file).mtimeMs
|
|
22658
|
+
})).sort((a, b) => b.mtime - a.mtime);
|
|
22659
|
+
for (let i = maxFiles; i < sortedFiles.length; i++) {
|
|
22660
|
+
const file = sortedFiles[i].file;
|
|
22661
|
+
if (liveLogFilePaths.has(file)) continue;
|
|
22662
|
+
try {
|
|
22663
|
+
unlinkSync2(file);
|
|
22664
|
+
} catch {
|
|
22665
|
+
}
|
|
22666
|
+
}
|
|
22667
|
+
} catch {
|
|
22668
|
+
}
|
|
22669
|
+
}
|
|
22670
|
+
function createLogWriter(filePath) {
|
|
22671
|
+
if (!filePath) {
|
|
22672
|
+
return { writer: () => {
|
|
22673
|
+
}, stream: null };
|
|
22674
|
+
}
|
|
22675
|
+
try {
|
|
22676
|
+
const stream = createWriteStream(filePath, { flags: "a", mode: 384 });
|
|
22677
|
+
stream.on("error", () => {
|
|
22678
|
+
});
|
|
22679
|
+
liveLogFilePaths.add(filePath);
|
|
22680
|
+
return {
|
|
22681
|
+
stream,
|
|
22682
|
+
writer: (line) => {
|
|
22425
22683
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
22426
22684
|
const formatted = `[${timestamp}] ${line}`;
|
|
22427
22685
|
stream.write(`${formatted}
|
|
@@ -22462,9 +22720,6 @@ function createDebugState(config) {
|
|
|
22462
22720
|
const debugTuiEnabled = config.debug_tui || isTruthyFlag2(env.OPENCODE_ANTIGRAVITY_DEBUG_TUI);
|
|
22463
22721
|
const logFilePath = debugEnabled ? createLogFilePath(config.log_dir) : void 0;
|
|
22464
22722
|
const { writer: logWriter, stream: logStream } = createLogWriter(logFilePath);
|
|
22465
|
-
if (debugEnabled) {
|
|
22466
|
-
ensureGitignoreSync(getConfigDir2());
|
|
22467
|
-
}
|
|
22468
22723
|
return {
|
|
22469
22724
|
debugEnabled,
|
|
22470
22725
|
debugTuiEnabled,
|
|
@@ -22733,13 +22988,13 @@ function closeDebugLog() {
|
|
|
22733
22988
|
if (!state || !current) return Promise.resolve();
|
|
22734
22989
|
state.logStream = null;
|
|
22735
22990
|
if (state.logFilePath) liveLogFilePaths.delete(state.logFilePath);
|
|
22736
|
-
return new Promise((
|
|
22737
|
-
current.once("close", () =>
|
|
22738
|
-
current.once("error", () =>
|
|
22991
|
+
return new Promise((resolve20) => {
|
|
22992
|
+
current.once("close", () => resolve20());
|
|
22993
|
+
current.once("error", () => resolve20());
|
|
22739
22994
|
try {
|
|
22740
22995
|
current.end();
|
|
22741
22996
|
} catch {
|
|
22742
|
-
|
|
22997
|
+
resolve20();
|
|
22743
22998
|
}
|
|
22744
22999
|
});
|
|
22745
23000
|
}
|
|
@@ -23210,14 +23465,14 @@ async function fetchQuotaPayloads(options) {
|
|
|
23210
23465
|
};
|
|
23211
23466
|
}
|
|
23212
23467
|
function untilQuotaAborted(pending, signal) {
|
|
23213
|
-
return new Promise((
|
|
23468
|
+
return new Promise((resolve20, reject) => {
|
|
23214
23469
|
const abort = () => reject(signal.reason);
|
|
23215
23470
|
if (signal.aborted) abort();
|
|
23216
23471
|
else signal.addEventListener("abort", abort, { once: true });
|
|
23217
23472
|
void pending.then(
|
|
23218
23473
|
(value) => {
|
|
23219
23474
|
signal.removeEventListener("abort", abort);
|
|
23220
|
-
|
|
23475
|
+
resolve20(value);
|
|
23221
23476
|
},
|
|
23222
23477
|
(error) => {
|
|
23223
23478
|
signal.removeEventListener("abort", abort);
|
|
@@ -23425,16 +23680,16 @@ async function persistRotatedRefresh(client, providerId, auth) {
|
|
|
23425
23680
|
}
|
|
23426
23681
|
|
|
23427
23682
|
// src/plugin/server.ts
|
|
23428
|
-
import { existsSync as
|
|
23683
|
+
import { existsSync as existsSync5, readFileSync as readFileSync2 } from "node:fs";
|
|
23429
23684
|
import { createServer } from "node:http";
|
|
23430
23685
|
var redirectUri = new URL(ANTIGRAVITY_REDIRECT_URI);
|
|
23431
23686
|
var callbackPath = redirectUri.pathname || "/";
|
|
23432
23687
|
function isOrbStackDockerHost() {
|
|
23433
|
-
if (!
|
|
23688
|
+
if (!existsSync5("/.dockerenv")) {
|
|
23434
23689
|
return false;
|
|
23435
23690
|
}
|
|
23436
23691
|
try {
|
|
23437
|
-
if (
|
|
23692
|
+
if (existsSync5("/proc/version")) {
|
|
23438
23693
|
const version = readFileSync2("/proc/version", "utf8").toLowerCase();
|
|
23439
23694
|
if (version.includes("orbstack")) {
|
|
23440
23695
|
return true;
|
|
@@ -23444,14 +23699,14 @@ function isOrbStackDockerHost() {
|
|
|
23444
23699
|
if (hostname.startsWith("orbstack-") || hostname.endsWith(".orb") || hostname === "orbstack") {
|
|
23445
23700
|
return true;
|
|
23446
23701
|
}
|
|
23447
|
-
if (
|
|
23702
|
+
if (existsSync5("/etc/resolv.conf")) {
|
|
23448
23703
|
const resolv = readFileSync2("/etc/resolv.conf", "utf8");
|
|
23449
23704
|
if (resolv.includes("orb.local") || resolv.includes("orbstack")) {
|
|
23450
23705
|
return true;
|
|
23451
23706
|
}
|
|
23452
23707
|
}
|
|
23453
|
-
if (process.platform === "linux" &&
|
|
23454
|
-
if (
|
|
23708
|
+
if (process.platform === "linux" && existsSync5("/.dockerenv")) {
|
|
23709
|
+
if (existsSync5("/run/host-services")) {
|
|
23455
23710
|
return true;
|
|
23456
23711
|
}
|
|
23457
23712
|
}
|
|
@@ -23499,12 +23754,12 @@ async function startOAuthListener({
|
|
|
23499
23754
|
let resolveCallback;
|
|
23500
23755
|
let rejectCallback;
|
|
23501
23756
|
let timeoutHandle;
|
|
23502
|
-
const callbackPromise = new Promise((
|
|
23757
|
+
const callbackPromise = new Promise((resolve20, reject) => {
|
|
23503
23758
|
resolveCallback = (url) => {
|
|
23504
23759
|
if (settled) return;
|
|
23505
23760
|
settled = true;
|
|
23506
23761
|
if (timeoutHandle) clearTimeout(timeoutHandle);
|
|
23507
|
-
|
|
23762
|
+
resolve20(url);
|
|
23508
23763
|
};
|
|
23509
23764
|
rejectCallback = (error) => {
|
|
23510
23765
|
if (settled) return;
|
|
@@ -23663,7 +23918,7 @@ async function startOAuthListener({
|
|
|
23663
23918
|
});
|
|
23664
23919
|
});
|
|
23665
23920
|
const bindAddress = getBindAddress();
|
|
23666
|
-
await new Promise((
|
|
23921
|
+
await new Promise((resolve20, reject) => {
|
|
23667
23922
|
const handleError = (error) => {
|
|
23668
23923
|
server.off("error", handleError);
|
|
23669
23924
|
if (error.code === "EADDRINUSE") {
|
|
@@ -23679,7 +23934,7 @@ async function startOAuthListener({
|
|
|
23679
23934
|
server.once("error", handleError);
|
|
23680
23935
|
server.listen(port, bindAddress, () => {
|
|
23681
23936
|
server.off("error", handleError);
|
|
23682
|
-
|
|
23937
|
+
resolve20();
|
|
23683
23938
|
});
|
|
23684
23939
|
});
|
|
23685
23940
|
server.on("error", (error) => {
|
|
@@ -23687,7 +23942,7 @@ async function startOAuthListener({
|
|
|
23687
23942
|
});
|
|
23688
23943
|
return {
|
|
23689
23944
|
waitForCallback: () => callbackPromise,
|
|
23690
|
-
close: () => new Promise((
|
|
23945
|
+
close: () => new Promise((resolve20, reject) => {
|
|
23691
23946
|
server.close((error) => {
|
|
23692
23947
|
if (error && error.code !== "ERR_SERVER_NOT_RUNNING") {
|
|
23693
23948
|
reject(error);
|
|
@@ -23696,7 +23951,7 @@ async function startOAuthListener({
|
|
|
23696
23951
|
if (!settled) {
|
|
23697
23952
|
rejectCallback(new Error("OAuth listener closed before callback"));
|
|
23698
23953
|
}
|
|
23699
|
-
|
|
23954
|
+
resolve20();
|
|
23700
23955
|
});
|
|
23701
23956
|
})
|
|
23702
23957
|
};
|
|
@@ -23708,28 +23963,28 @@ async function startOAuthListener({
|
|
|
23708
23963
|
|
|
23709
23964
|
// src/process-heartbeat.ts
|
|
23710
23965
|
import { randomUUID as randomUUID13 } from "node:crypto";
|
|
23711
|
-
import { realpathSync, rmSync } from "node:fs";
|
|
23712
|
-
import { chmod as chmod3, mkdir as mkdir11, readFile as
|
|
23713
|
-
import { homedir as
|
|
23714
|
-
import { join as
|
|
23715
|
-
function
|
|
23716
|
-
const base = process.env.XDG_STATE_HOME ||
|
|
23717
|
-
return
|
|
23966
|
+
import { realpathSync as realpathSync2, rmSync } from "node:fs";
|
|
23967
|
+
import { chmod as chmod3, mkdir as mkdir11, readFile as readFile9, rename as rename8, rm as rm5, writeFile as writeFile3 } from "node:fs/promises";
|
|
23968
|
+
import { homedir as homedir5 } from "node:os";
|
|
23969
|
+
import { join as join14, resolve as resolve14 } from "node:path";
|
|
23970
|
+
function processHeartbeatDir2() {
|
|
23971
|
+
const base = process.env.XDG_STATE_HOME || join14(homedir5(), ".local", "state");
|
|
23972
|
+
return join14(base, "cortexkit", "antigravity-auth", "processes");
|
|
23718
23973
|
}
|
|
23719
|
-
function processHeartbeatPath(pid = process.pid, dir =
|
|
23720
|
-
return
|
|
23974
|
+
function processHeartbeatPath(pid = process.pid, dir = processHeartbeatDir2()) {
|
|
23975
|
+
return join14(dir, `${pid}.json`);
|
|
23721
23976
|
}
|
|
23722
23977
|
function processConfigFolderKey() {
|
|
23723
23978
|
const folder = getConfigDir();
|
|
23724
23979
|
try {
|
|
23725
|
-
return
|
|
23980
|
+
return realpathSync2.native(folder);
|
|
23726
23981
|
} catch {
|
|
23727
|
-
return
|
|
23982
|
+
return resolve14(folder);
|
|
23728
23983
|
}
|
|
23729
23984
|
}
|
|
23730
23985
|
var stateKey = /* @__PURE__ */ Symbol.for("cortexkit.antigravity-auth.process-heartbeat");
|
|
23731
23986
|
var globalState = globalThis;
|
|
23732
|
-
var
|
|
23987
|
+
var shared2 = globalState[stateKey] ?? {
|
|
23733
23988
|
owners: 0,
|
|
23734
23989
|
startedAt: void 0,
|
|
23735
23990
|
layouts: /* @__PURE__ */ new Map(),
|
|
@@ -23737,22 +23992,22 @@ var shared = globalState[stateKey] ?? {
|
|
|
23737
23992
|
writtenLayouts: void 0,
|
|
23738
23993
|
exitHookInstalled: false
|
|
23739
23994
|
};
|
|
23740
|
-
globalState[stateKey] =
|
|
23995
|
+
globalState[stateKey] = shared2;
|
|
23741
23996
|
function layoutsRecord() {
|
|
23742
|
-
return Object.fromEntries(
|
|
23997
|
+
return Object.fromEntries(shared2.layouts);
|
|
23743
23998
|
}
|
|
23744
23999
|
function holdsLegacyLayout() {
|
|
23745
|
-
for (const layout of
|
|
24000
|
+
for (const layout of shared2.layouts.values())
|
|
23746
24001
|
if (layout === "legacy") return true;
|
|
23747
24002
|
return false;
|
|
23748
24003
|
}
|
|
23749
24004
|
function installExitHook() {
|
|
23750
|
-
if (
|
|
23751
|
-
|
|
24005
|
+
if (shared2.exitHookInstalled) return;
|
|
24006
|
+
shared2.exitHookInstalled = true;
|
|
23752
24007
|
process.once("exit", () => {
|
|
23753
|
-
if (!
|
|
24008
|
+
if (!shared2.writtenPath) return;
|
|
23754
24009
|
try {
|
|
23755
|
-
rmSync(
|
|
24010
|
+
rmSync(shared2.writtenPath, { force: true });
|
|
23756
24011
|
} catch {
|
|
23757
24012
|
}
|
|
23758
24013
|
});
|
|
@@ -23780,27 +24035,27 @@ function errorText2(error) {
|
|
|
23780
24035
|
}
|
|
23781
24036
|
async function startProcessHeartbeat(input) {
|
|
23782
24037
|
const pid = input.pid ?? process.pid;
|
|
23783
|
-
const dir = input.dir ??
|
|
23784
|
-
|
|
23785
|
-
|
|
24038
|
+
const dir = input.dir ?? processHeartbeatDir2();
|
|
24039
|
+
shared2.startedAt ??= (input.now ?? Date.now)();
|
|
24040
|
+
shared2.owners++;
|
|
23786
24041
|
for (const [key, layout] of Object.entries(input.layouts ?? {}))
|
|
23787
|
-
|
|
24042
|
+
shared2.layouts.set(key, layout);
|
|
23788
24043
|
const target = processHeartbeatPath(pid, dir);
|
|
23789
24044
|
const layouts = layoutsRecord();
|
|
23790
24045
|
const signature = JSON.stringify(layouts);
|
|
23791
24046
|
let path2;
|
|
23792
|
-
if (
|
|
24047
|
+
if (shared2.writtenPath === target && shared2.writtenLayouts === signature) {
|
|
23793
24048
|
path2 = target;
|
|
23794
24049
|
} else {
|
|
23795
24050
|
try {
|
|
23796
24051
|
path2 = await writeHeartbeatFile(dir, {
|
|
23797
24052
|
pid,
|
|
23798
24053
|
version: input.version,
|
|
23799
|
-
startedAt:
|
|
24054
|
+
startedAt: shared2.startedAt,
|
|
23800
24055
|
layouts
|
|
23801
24056
|
});
|
|
23802
|
-
|
|
23803
|
-
|
|
24057
|
+
shared2.writtenPath = path2;
|
|
24058
|
+
shared2.writtenLayouts = signature;
|
|
23804
24059
|
installExitHook();
|
|
23805
24060
|
} catch (error) {
|
|
23806
24061
|
input.logger.warn("process heartbeat not written", {
|
|
@@ -23815,18 +24070,18 @@ async function startProcessHeartbeat(input) {
|
|
|
23815
24070
|
async release() {
|
|
23816
24071
|
if (released) return;
|
|
23817
24072
|
released = true;
|
|
23818
|
-
|
|
23819
|
-
if (
|
|
24073
|
+
shared2.owners = Math.max(0, shared2.owners - 1);
|
|
24074
|
+
if (shared2.owners > 0) return;
|
|
23820
24075
|
if (holdsLegacyLayout()) return;
|
|
23821
24076
|
await removeHeartbeatFile(input.logger);
|
|
23822
24077
|
}
|
|
23823
24078
|
};
|
|
23824
24079
|
}
|
|
23825
24080
|
async function removeHeartbeatFile(logger2) {
|
|
23826
|
-
const path2 =
|
|
24081
|
+
const path2 = shared2.writtenPath;
|
|
23827
24082
|
if (!path2) return;
|
|
23828
|
-
|
|
23829
|
-
|
|
24083
|
+
shared2.writtenPath = void 0;
|
|
24084
|
+
shared2.writtenLayouts = void 0;
|
|
23830
24085
|
await rm5(path2, { force: true }).catch((error) => {
|
|
23831
24086
|
logger2.warn("process heartbeat not removed", {
|
|
23832
24087
|
path: path2,
|
|
@@ -23837,9 +24092,24 @@ async function removeHeartbeatFile(logger2) {
|
|
|
23837
24092
|
async function removeProcessHeartbeat(logger2) {
|
|
23838
24093
|
await removeHeartbeatFile(logger2);
|
|
23839
24094
|
}
|
|
24095
|
+
async function recordProcessLayout(input) {
|
|
24096
|
+
shared2.layouts.set(input.key, input.layout);
|
|
24097
|
+
if (input.layout !== "legacy") return;
|
|
24098
|
+
shared2.startedAt ??= (input.now ?? Date.now)();
|
|
24099
|
+
const layouts = layoutsRecord();
|
|
24100
|
+
const path2 = await writeHeartbeatFile(input.dir ?? processHeartbeatDir2(), {
|
|
24101
|
+
pid: input.pid ?? process.pid,
|
|
24102
|
+
version: input.version,
|
|
24103
|
+
startedAt: shared2.startedAt,
|
|
24104
|
+
layouts
|
|
24105
|
+
});
|
|
24106
|
+
shared2.writtenPath = path2;
|
|
24107
|
+
shared2.writtenLayouts = JSON.stringify(layouts);
|
|
24108
|
+
installExitHook();
|
|
24109
|
+
}
|
|
23840
24110
|
var packageVersion;
|
|
23841
24111
|
function pluginPackageVersion() {
|
|
23842
|
-
packageVersion ??=
|
|
24112
|
+
packageVersion ??= readFile9(
|
|
23843
24113
|
new URL("../package.json", import.meta.url),
|
|
23844
24114
|
"utf8"
|
|
23845
24115
|
).then((text2) => JSON.parse(text2).version).catch((error) => {
|
|
@@ -23853,7 +24123,9 @@ async function startRuntimeProcessHeartbeat(logger2) {
|
|
|
23853
24123
|
let layouts = {};
|
|
23854
24124
|
try {
|
|
23855
24125
|
version = await pluginPackageVersion();
|
|
23856
|
-
layouts = {
|
|
24126
|
+
layouts = {
|
|
24127
|
+
[processConfigFolderKey()]: decidedRuntimeLayout(runtimeLayoutLocation()) ?? "legacy"
|
|
24128
|
+
};
|
|
23857
24129
|
} catch (error) {
|
|
23858
24130
|
logger2.warn("process heartbeat details unavailable", {
|
|
23859
24131
|
error: errorText2(error)
|
|
@@ -23866,8 +24138,8 @@ async function holdCliProcessHeartbeat(logger2) {
|
|
|
23866
24138
|
}
|
|
23867
24139
|
|
|
23868
24140
|
// src/setup.ts
|
|
23869
|
-
import { lstat as lstat7, readFile as
|
|
23870
|
-
import { join as
|
|
24141
|
+
import { lstat as lstat7, readFile as readFile13 } from "node:fs/promises";
|
|
24142
|
+
import { join as join21, resolve as resolve18 } from "node:path";
|
|
23871
24143
|
|
|
23872
24144
|
// src/auth-method-labels.ts
|
|
23873
24145
|
var OPENCODE2_POOL_AUTH_LABEL = "Google (antigravity-auth pool, browser)";
|
|
@@ -24039,7 +24311,7 @@ async function select2(terminal, items, options) {
|
|
|
24039
24311
|
writeLine("");
|
|
24040
24312
|
renderedLines = lines;
|
|
24041
24313
|
};
|
|
24042
|
-
return new Promise((
|
|
24314
|
+
return new Promise((resolve20) => {
|
|
24043
24315
|
const wasRaw = stdin.isRaw ?? false;
|
|
24044
24316
|
const cleanup2 = () => {
|
|
24045
24317
|
if (cleaned)
|
|
@@ -24059,7 +24331,7 @@ async function select2(terminal, items, options) {
|
|
|
24059
24331
|
};
|
|
24060
24332
|
const finish = (value) => {
|
|
24061
24333
|
cleanup2();
|
|
24062
|
-
|
|
24334
|
+
resolve20(value);
|
|
24063
24335
|
};
|
|
24064
24336
|
const onSignal = () => finish(null);
|
|
24065
24337
|
const onKey = (data) => {
|
|
@@ -24099,7 +24371,7 @@ async function select2(terminal, items, options) {
|
|
|
24099
24371
|
stdin.setRawMode(true);
|
|
24100
24372
|
} catch {
|
|
24101
24373
|
cleanup2();
|
|
24102
|
-
|
|
24374
|
+
resolve20(null);
|
|
24103
24375
|
return;
|
|
24104
24376
|
}
|
|
24105
24377
|
stdin.resume();
|
|
@@ -24110,15 +24382,15 @@ async function select2(terminal, items, options) {
|
|
|
24110
24382
|
}
|
|
24111
24383
|
|
|
24112
24384
|
// src/common-auth-embedded/claustrum/enrollment.js
|
|
24113
|
-
import { createHash as
|
|
24385
|
+
import { createHash as createHash11, randomBytes as randomBytes3, randomUUID as randomUUID15 } from "node:crypto";
|
|
24114
24386
|
import { constants as fsConstants2 } from "node:fs";
|
|
24115
|
-
import { chmod as chmod4, mkdir as mkdir13, open as open10, readFile as
|
|
24116
|
-
import { basename as basename4, dirname as
|
|
24387
|
+
import { chmod as chmod4, mkdir as mkdir13, open as open10, readFile as readFile11, realpath as realpath4, rename as rename10, stat as stat9, unlink as unlink9 } from "node:fs/promises";
|
|
24388
|
+
import { basename as basename4, dirname as dirname18, extname as extname2, isAbsolute as isAbsolute3, join as join16, resolve as resolve16 } from "node:path";
|
|
24117
24389
|
import { ClaustrumCredentialError as ClaustrumCredentialError5, ClaustrumClient as ClaustrumWireClient2, writeEnrollmentTokenFile as writeEnrollmentTokenFile2 } from "@cortexkit/claustrum-client";
|
|
24118
24390
|
|
|
24119
24391
|
// src/common-auth-embedded/fs/file-read-cache.js
|
|
24120
24392
|
import { lstat as lstat6 } from "node:fs/promises";
|
|
24121
|
-
import { resolve as
|
|
24393
|
+
import { resolve as resolve15 } from "node:path";
|
|
24122
24394
|
async function identity2(path2) {
|
|
24123
24395
|
try {
|
|
24124
24396
|
const metadata = await lstat6(path2);
|
|
@@ -24135,7 +24407,7 @@ function sameIdentity2(left, right) {
|
|
|
24135
24407
|
var FileReadCache2 = class {
|
|
24136
24408
|
#entries = /* @__PURE__ */ new Map();
|
|
24137
24409
|
async read(paths, read, validateHit) {
|
|
24138
|
-
const resolvedPaths = paths.map((path2) =>
|
|
24410
|
+
const resolvedPaths = paths.map((path2) => resolve15(path2));
|
|
24139
24411
|
const key = JSON.stringify(resolvedPaths);
|
|
24140
24412
|
const probed = await Promise.all(resolvedPaths.map(identity2));
|
|
24141
24413
|
const identities = probed.every((entry) => entry !== void 0) ? probed : void 0;
|
|
@@ -24179,8 +24451,8 @@ var WRITER_LOCK_CONSTANTS2 = Object.freeze({
|
|
|
24179
24451
|
|
|
24180
24452
|
// src/common-auth-embedded/fs/refresh-file-lock.js
|
|
24181
24453
|
import { randomUUID as randomUUID14 } from "node:crypto";
|
|
24182
|
-
import { mkdir as mkdir12, open as open9, readFile as
|
|
24183
|
-
import { dirname as
|
|
24454
|
+
import { mkdir as mkdir12, open as open9, readFile as readFile10, rename as rename9, rm as rm6, stat as stat8 } from "node:fs/promises";
|
|
24455
|
+
import { dirname as dirname17, join as join15 } from "node:path";
|
|
24184
24456
|
|
|
24185
24457
|
// src/common-auth-embedded/fs/with-lock.js
|
|
24186
24458
|
function lockPathFor2(target, name) {
|
|
@@ -24215,7 +24487,7 @@ function acquireRefreshFileLock2(options) {
|
|
|
24215
24487
|
}
|
|
24216
24488
|
async function acquireRefreshFileLockWithClock2(options) {
|
|
24217
24489
|
const lockPath = lockPathFor2(options.path, options.name);
|
|
24218
|
-
const legacyOwnerPath =
|
|
24490
|
+
const legacyOwnerPath = join15(lockPath, "owner.json");
|
|
24219
24491
|
const ownerId = randomUUID14();
|
|
24220
24492
|
const now = options.now ?? Date.now;
|
|
24221
24493
|
let renewTimer = null;
|
|
@@ -24223,8 +24495,8 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
24223
24495
|
let releaseConfirmed = false;
|
|
24224
24496
|
let loss;
|
|
24225
24497
|
let resolveLoss;
|
|
24226
|
-
const lostPromise = new Promise((
|
|
24227
|
-
resolveLoss =
|
|
24498
|
+
const lostPromise = new Promise((resolve20) => {
|
|
24499
|
+
resolveLoss = resolve20;
|
|
24228
24500
|
});
|
|
24229
24501
|
function notifyTimerStep(event) {
|
|
24230
24502
|
try {
|
|
@@ -24258,7 +24530,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
24258
24530
|
let terminalIOError;
|
|
24259
24531
|
let renewalInFlight = null;
|
|
24260
24532
|
const evictPath = `${lockPath}.evicting`;
|
|
24261
|
-
const evictOwnerPath =
|
|
24533
|
+
const evictOwnerPath = join15(evictPath, "owner.json");
|
|
24262
24534
|
const evictOwnerId = randomUUID14();
|
|
24263
24535
|
const EVICT_TTL = 5e3;
|
|
24264
24536
|
const MAX_STEAL_ATTEMPTS = 8;
|
|
@@ -24274,12 +24546,12 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
24274
24546
|
}
|
|
24275
24547
|
}
|
|
24276
24548
|
try {
|
|
24277
|
-
return JSON.parse(await
|
|
24549
|
+
return JSON.parse(await readFile10(lockPath, "utf8"));
|
|
24278
24550
|
} catch (error) {
|
|
24279
24551
|
const code2 = error.code;
|
|
24280
24552
|
if (code2 !== "EISDIR")
|
|
24281
24553
|
throw error;
|
|
24282
|
-
return JSON.parse(await
|
|
24554
|
+
return JSON.parse(await readFile10(legacyOwnerPath, "utf8"));
|
|
24283
24555
|
}
|
|
24284
24556
|
}
|
|
24285
24557
|
async function writeOwner() {
|
|
@@ -24359,7 +24631,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
24359
24631
|
}
|
|
24360
24632
|
async function tryAcquire() {
|
|
24361
24633
|
if (windowsPrivateFiles2)
|
|
24362
|
-
await
|
|
24634
|
+
await ensurePrivateDirectory2(dirname17(lockPath));
|
|
24363
24635
|
try {
|
|
24364
24636
|
await createLease();
|
|
24365
24637
|
return true;
|
|
@@ -24369,9 +24641,9 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
24369
24641
|
return false;
|
|
24370
24642
|
if (code2 === "ENOENT") {
|
|
24371
24643
|
if (windowsPrivateFiles2)
|
|
24372
|
-
await
|
|
24644
|
+
await ensurePrivateDirectory2(dirname17(lockPath));
|
|
24373
24645
|
else
|
|
24374
|
-
await mkdir12(
|
|
24646
|
+
await mkdir12(dirname17(lockPath), { recursive: true });
|
|
24375
24647
|
try {
|
|
24376
24648
|
await createLease();
|
|
24377
24649
|
return true;
|
|
@@ -24385,7 +24657,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
24385
24657
|
}
|
|
24386
24658
|
}
|
|
24387
24659
|
async function backoff() {
|
|
24388
|
-
await new Promise((
|
|
24660
|
+
await new Promise((resolve20) => setTimeout(resolve20, Math.floor(Math.random() * 4)));
|
|
24389
24661
|
}
|
|
24390
24662
|
async function readLockState(notifyReady = true) {
|
|
24391
24663
|
if (notifyReady && options.onStep)
|
|
@@ -24492,8 +24764,15 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
24492
24764
|
return "missing";
|
|
24493
24765
|
throw error;
|
|
24494
24766
|
}
|
|
24495
|
-
if (windowsPrivateFiles2)
|
|
24496
|
-
|
|
24767
|
+
if (windowsPrivateFiles2) {
|
|
24768
|
+
try {
|
|
24769
|
+
await verifyPrivate2(evictPath, "directory", true);
|
|
24770
|
+
} catch (error) {
|
|
24771
|
+
if (error.code === "ENOENT")
|
|
24772
|
+
return "missing";
|
|
24773
|
+
throw error;
|
|
24774
|
+
}
|
|
24775
|
+
}
|
|
24497
24776
|
if (evictStat.mtimeMs + EVICT_TTL > now())
|
|
24498
24777
|
return "fresh";
|
|
24499
24778
|
if (options.onStep)
|
|
@@ -24518,8 +24797,8 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
24518
24797
|
} catch (error) {
|
|
24519
24798
|
if (error.code === "EEXIST") {
|
|
24520
24799
|
if (windowsPrivateFiles2) {
|
|
24521
|
-
await verifyPrivate2(evictPath, "directory", true);
|
|
24522
24800
|
try {
|
|
24801
|
+
await verifyPrivate2(evictPath, "directory", true);
|
|
24523
24802
|
await readPrivateText2(evictOwnerPath, true);
|
|
24524
24803
|
} catch (ownerError) {
|
|
24525
24804
|
if (ownerError.code !== "ENOENT")
|
|
@@ -24869,7 +25148,7 @@ function getClaustrumEnrollmentPaths2(tokenPath) {
|
|
|
24869
25148
|
const extension = extname2(tokenPath) || ".json";
|
|
24870
25149
|
const stem = basename4(tokenPath, extname2(tokenPath));
|
|
24871
25150
|
return {
|
|
24872
|
-
statePath:
|
|
25151
|
+
statePath: join16(dirname18(tokenPath), `${stem}-state${extension}`),
|
|
24873
25152
|
tokenPath
|
|
24874
25153
|
};
|
|
24875
25154
|
}
|
|
@@ -24877,7 +25156,7 @@ function hostEnrollmentPaths2(input) {
|
|
|
24877
25156
|
const override = input.override?.trim();
|
|
24878
25157
|
if (override && !isAbsolute3(override) && !input.cwd)
|
|
24879
25158
|
throw new ClaustrumConsumerError2("invalid-state", "A relative Claustrum enrollment override needs a base directory");
|
|
24880
|
-
const tokenPath = override ? isAbsolute3(override) ? override :
|
|
25159
|
+
const tokenPath = override ? isAbsolute3(override) ? override : resolve16(input.cwd, override) : join16(input.stateDir, `${input.host}-enrollment.json`);
|
|
24881
25160
|
return getClaustrumEnrollmentPaths2(tokenPath);
|
|
24882
25161
|
}
|
|
24883
25162
|
function isRecord9(value) {
|
|
@@ -24974,7 +25253,7 @@ function parseSecretJson2(text2) {
|
|
|
24974
25253
|
async function readBoundedJson2(path2) {
|
|
24975
25254
|
if (windowsPrivateFiles2) {
|
|
24976
25255
|
try {
|
|
24977
|
-
await
|
|
25256
|
+
await ensurePrivateDirectory2(dirname18(path2));
|
|
24978
25257
|
const text2 = await readPrivateText2(path2, true);
|
|
24979
25258
|
if (Buffer.byteLength(text2) > ENROLLMENT_FILE_MAX_BYTES2) {
|
|
24980
25259
|
throw new ClaustrumConsumerError2("unsafe-file", "Claustrum enrollment file is too large");
|
|
@@ -25021,8 +25300,8 @@ function accountRecords2(text2, fields2) {
|
|
|
25021
25300
|
async function isPrivateGroup2(uid, gid, options) {
|
|
25022
25301
|
try {
|
|
25023
25302
|
const [passwdText, groupText] = await Promise.all([
|
|
25024
|
-
|
|
25025
|
-
|
|
25303
|
+
readFile11(options.passwdPath ?? "/etc/passwd", "utf8"),
|
|
25304
|
+
readFile11(options.groupPath ?? "/etc/group", "utf8")
|
|
25026
25305
|
]);
|
|
25027
25306
|
const users = accountRecords2(passwdText, 7);
|
|
25028
25307
|
const groups = accountRecords2(groupText, 4);
|
|
@@ -25044,7 +25323,7 @@ function ancestorPolicyOptions2(options) {
|
|
|
25044
25323
|
return void 0;
|
|
25045
25324
|
return {
|
|
25046
25325
|
fs: {
|
|
25047
|
-
readFile: (path2) =>
|
|
25326
|
+
readFile: (path2) => readFile11(path2 === "/etc/passwd" ? options.passwdPath ?? path2 : path2 === "/etc/group" ? options.groupPath ?? path2 : path2)
|
|
25048
25327
|
}
|
|
25049
25328
|
};
|
|
25050
25329
|
}
|
|
@@ -25071,7 +25350,7 @@ async function refuseWritableAncestor2(parent, options = {}) {
|
|
|
25071
25350
|
throw new ClaustrumConsumerError2("unsafe-file", `Claustrum enrollment path has a writable ancestor: ${component}. Another user could replace it. Run: chmod g-w,o-w ${component}`);
|
|
25072
25351
|
}
|
|
25073
25352
|
}
|
|
25074
|
-
const next =
|
|
25353
|
+
const next = dirname18(component);
|
|
25075
25354
|
if (next === component)
|
|
25076
25355
|
return;
|
|
25077
25356
|
component = next;
|
|
@@ -25085,23 +25364,23 @@ async function refuseWritableAncestor2(parent, options = {}) {
|
|
|
25085
25364
|
throw new ClaustrumConsumerError2("unsafe-file", `Claustrum enrollment parent refused: ${error.path} (${error.reason ?? error.code}). Use a folder that other users cannot write or replace.`);
|
|
25086
25365
|
}
|
|
25087
25366
|
}
|
|
25088
|
-
async function
|
|
25367
|
+
async function ensureClaustrumPrivateDirectory2(directory, options = {}, what = "enrollment directory") {
|
|
25089
25368
|
if (windowsPrivateFiles2) {
|
|
25090
|
-
await
|
|
25369
|
+
await ensurePrivateDirectory2(directory, false, ancestorPolicyOptions2(options));
|
|
25091
25370
|
return;
|
|
25092
25371
|
}
|
|
25093
25372
|
await mkdir13(directory, { recursive: true, mode: 448 });
|
|
25094
25373
|
const metadata = await stat9(directory);
|
|
25095
25374
|
const uid = process.geteuid?.();
|
|
25096
25375
|
if (uid !== void 0 && metadata.uid !== uid) {
|
|
25097
|
-
throw new ClaustrumConsumerError2("unsafe-file",
|
|
25376
|
+
throw new ClaustrumConsumerError2("unsafe-file", `Claustrum ${what} must be owned by the current user`);
|
|
25098
25377
|
}
|
|
25099
25378
|
if ((metadata.mode & 63) !== 0)
|
|
25100
25379
|
await chmod4(directory, 448);
|
|
25101
25380
|
}
|
|
25102
25381
|
async function writeStateAtomic2(path2, state, ancestorOptions = {}) {
|
|
25103
|
-
const parent =
|
|
25104
|
-
await
|
|
25382
|
+
const parent = dirname18(path2);
|
|
25383
|
+
await ensureClaustrumPrivateDirectory2(parent, ancestorOptions);
|
|
25105
25384
|
await refuseWritableAncestor2(parent, ancestorOptions);
|
|
25106
25385
|
const bytes = `${JSON.stringify(state)}
|
|
25107
25386
|
`;
|
|
@@ -25110,7 +25389,7 @@ async function writeStateAtomic2(path2, state, ancestorOptions = {}) {
|
|
|
25110
25389
|
}
|
|
25111
25390
|
if (windowsPrivateFiles2)
|
|
25112
25391
|
return writePrivateAtomic2(path2, bytes);
|
|
25113
|
-
const temporary =
|
|
25392
|
+
const temporary = join16(parent, `.${basename4(path2)}.${process.pid}.${randomUUID15()}.tmp`);
|
|
25114
25393
|
let descriptor;
|
|
25115
25394
|
let created = false;
|
|
25116
25395
|
try {
|
|
@@ -25264,7 +25543,7 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
25264
25543
|
return statusFromState2(blocked);
|
|
25265
25544
|
}
|
|
25266
25545
|
async reconcile() {
|
|
25267
|
-
await
|
|
25546
|
+
await ensureClaustrumPrivateDirectory2(dirname18(this.#paths.statePath), this.#ancestorOptions);
|
|
25268
25547
|
const lock = await acquireRefreshFileLock2({
|
|
25269
25548
|
name: "ceremony",
|
|
25270
25549
|
path: this.#paths.statePath,
|
|
@@ -25330,7 +25609,7 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
25330
25609
|
}
|
|
25331
25610
|
if (!state.requestId) {
|
|
25332
25611
|
try {
|
|
25333
|
-
const requestSecretHash =
|
|
25612
|
+
const requestSecretHash = createHash11("sha256").update(Buffer.from(state.requestSecret, "hex")).digest("hex");
|
|
25334
25613
|
const proposed = await this.#client.enrollPropose({
|
|
25335
25614
|
name: state.proposedName,
|
|
25336
25615
|
requestSecretHash
|
|
@@ -25387,8 +25666,8 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
25387
25666
|
await writeStateAtomic2(this.#paths.statePath, denied, this.#ancestorOptions);
|
|
25388
25667
|
return statusFromState2(denied);
|
|
25389
25668
|
}
|
|
25390
|
-
await
|
|
25391
|
-
await refuseWritableAncestor2(
|
|
25669
|
+
await ensureClaustrumPrivateDirectory2(dirname18(this.#paths.tokenPath), this.#ancestorOptions);
|
|
25670
|
+
await refuseWritableAncestor2(dirname18(this.#paths.tokenPath), this.#ancestorOptions);
|
|
25392
25671
|
await this.#writeTokenFile(this.#paths.tokenPath, {
|
|
25393
25672
|
token: outcome.token,
|
|
25394
25673
|
token_generation: outcome.tokenGeneration
|
|
@@ -25423,7 +25702,7 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
25423
25702
|
}
|
|
25424
25703
|
};
|
|
25425
25704
|
async function resetClaustrumEnrollmentState2(paths, proposedName) {
|
|
25426
|
-
await
|
|
25705
|
+
await ensureClaustrumPrivateDirectory2(dirname18(paths.statePath));
|
|
25427
25706
|
const lock = await acquireRefreshFileLock2({
|
|
25428
25707
|
name: "ceremony",
|
|
25429
25708
|
path: paths.statePath,
|
|
@@ -25502,7 +25781,7 @@ var ByteTail = class {
|
|
|
25502
25781
|
};
|
|
25503
25782
|
var defaultCommandRunner = {
|
|
25504
25783
|
run(file, args, options = {}) {
|
|
25505
|
-
return new Promise((
|
|
25784
|
+
return new Promise((resolve20) => {
|
|
25506
25785
|
const started = performance.now();
|
|
25507
25786
|
const timeoutMs = options.timeoutMs ?? 15e3;
|
|
25508
25787
|
const stderr = new ByteTail();
|
|
@@ -25520,7 +25799,7 @@ var defaultCommandRunner = {
|
|
|
25520
25799
|
stdio: ["ignore", "pipe", "pipe"]
|
|
25521
25800
|
});
|
|
25522
25801
|
} catch {
|
|
25523
|
-
|
|
25802
|
+
resolve20({
|
|
25524
25803
|
exitCode: 1,
|
|
25525
25804
|
stdout: "",
|
|
25526
25805
|
stderr: "",
|
|
@@ -25555,7 +25834,7 @@ var defaultCommandRunner = {
|
|
|
25555
25834
|
settled = true;
|
|
25556
25835
|
if (timer)
|
|
25557
25836
|
clearTimeout(timer);
|
|
25558
|
-
|
|
25837
|
+
resolve20({
|
|
25559
25838
|
exitCode: spawnError ? 1 : outputExceeded ? 1 : code2 ?? 1,
|
|
25560
25839
|
stdout: Buffer.concat(stdout, stdoutLength).toString("utf8"),
|
|
25561
25840
|
stderr: stderr.toString(),
|
|
@@ -25639,21 +25918,21 @@ function recordSetupEnrollment(failure, enrollment) {
|
|
|
25639
25918
|
}
|
|
25640
25919
|
|
|
25641
25920
|
// src/common-auth-embedded/setup/detect.js
|
|
25642
|
-
import { accessSync, constants as constants3, existsSync as
|
|
25921
|
+
import { accessSync, constants as constants3, existsSync as existsSync6, readFileSync as readFileSync3, realpathSync as realpathSync3, statSync as statSync5 } from "node:fs";
|
|
25643
25922
|
import { mkdtemp, rm as rm7 } from "node:fs/promises";
|
|
25644
25923
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
25645
|
-
import { join as
|
|
25924
|
+
import { join as join17 } from "node:path";
|
|
25646
25925
|
import { parse } from "jsonc-parser";
|
|
25647
25926
|
|
|
25648
25927
|
// src/common-auth-embedded/setup/paths.js
|
|
25649
|
-
import { homedir as
|
|
25928
|
+
import { homedir as homedir6 } from "node:os";
|
|
25650
25929
|
import { posix, win32 } from "node:path";
|
|
25651
25930
|
import { fileURLToPath } from "node:url";
|
|
25652
25931
|
function setupPaths(io = {}) {
|
|
25653
25932
|
const env3 = io.env ?? process.env;
|
|
25654
25933
|
const platform = io.platform ?? process.platform;
|
|
25655
25934
|
const path2 = platform === "win32" ? win32 : posix;
|
|
25656
|
-
const home = io.home ?? (platform === "win32" ? env3.USERPROFILE : env3.HOME) ??
|
|
25935
|
+
const home = io.home ?? (platform === "win32" ? env3.USERPROFILE : env3.HOME) ?? homedir6();
|
|
25657
25936
|
const cwd = io.cwd ?? process.cwd();
|
|
25658
25937
|
const absolute = (value) => path2.resolve(cwd, value);
|
|
25659
25938
|
const config = env3.OPENCODE_CONFIG_DIR?.trim();
|
|
@@ -25685,7 +25964,7 @@ function stat10(path2, kind) {
|
|
|
25685
25964
|
}
|
|
25686
25965
|
}
|
|
25687
25966
|
var defaultSetupFileSystem = {
|
|
25688
|
-
exists:
|
|
25967
|
+
exists: existsSync6,
|
|
25689
25968
|
isFile: (path2) => stat10(path2, "isFile"),
|
|
25690
25969
|
isDirectory: (path2) => stat10(path2, "isDirectory"),
|
|
25691
25970
|
isExecutable(path2) {
|
|
@@ -25697,7 +25976,7 @@ var defaultSetupFileSystem = {
|
|
|
25697
25976
|
}
|
|
25698
25977
|
},
|
|
25699
25978
|
readText: (path2) => readFileSync3(path2, "utf8"),
|
|
25700
|
-
realpath:
|
|
25979
|
+
realpath: realpathSync3
|
|
25701
25980
|
};
|
|
25702
25981
|
function findExecutableOnPath(name, io = {}) {
|
|
25703
25982
|
const { env: env3, platform, path: path2, cwd } = setupPaths(io);
|
|
@@ -25781,7 +26060,7 @@ function diskGeneration(file, io) {
|
|
|
25781
26060
|
function detectOpenCodeGeneration(io = {}) {
|
|
25782
26061
|
const first = findExecutableOnPath("opencode", io);
|
|
25783
26062
|
const second = findExecutableOnPath("opencode2", io);
|
|
25784
|
-
const
|
|
26063
|
+
const shared3 = first && second && launcherTarget(first, io) === launcherTarget(second, io);
|
|
25785
26064
|
const fs2 = io.fs ?? defaultSetupFileSystem;
|
|
25786
26065
|
const { path: path2, opencode } = setupPaths(io);
|
|
25787
26066
|
let inferred = "1";
|
|
@@ -25796,10 +26075,10 @@ function detectOpenCodeGeneration(io = {}) {
|
|
|
25796
26075
|
}
|
|
25797
26076
|
break;
|
|
25798
26077
|
}
|
|
25799
|
-
const generation = first ? diskGeneration(first, io) ?? (
|
|
25800
|
-
if (second && generation === "1" && !
|
|
26078
|
+
const generation = first ? diskGeneration(first, io) ?? (shared3 ? "2" : inferred) : null;
|
|
26079
|
+
if (second && generation === "1" && !shared3)
|
|
25801
26080
|
return "ambiguous";
|
|
25802
|
-
return second ||
|
|
26081
|
+
return second || shared3 ? "2" : generation ?? inferred;
|
|
25803
26082
|
}
|
|
25804
26083
|
async function detectHosts(plugin, io = {}) {
|
|
25805
26084
|
const fs2 = io.fs ?? defaultSetupFileSystem;
|
|
@@ -25813,7 +26092,7 @@ async function detectHosts(plugin, io = {}) {
|
|
|
25813
26092
|
return null;
|
|
25814
26093
|
let root;
|
|
25815
26094
|
try {
|
|
25816
|
-
root = await mkdtemp(
|
|
26095
|
+
root = await mkdtemp(join17(tmpdir3(), "common-auth-setup-version-"));
|
|
25817
26096
|
const probeEnv = {
|
|
25818
26097
|
...env3,
|
|
25819
26098
|
HOME: root,
|
|
@@ -26265,24 +26544,124 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
|
|
|
26265
26544
|
}
|
|
26266
26545
|
}
|
|
26267
26546
|
|
|
26268
|
-
// src/common-auth-embedded/setup/
|
|
26269
|
-
|
|
26270
|
-
|
|
26271
|
-
|
|
26272
|
-
|
|
26273
|
-
|
|
26274
|
-
|
|
26275
|
-
|
|
26276
|
-
|
|
26277
|
-
|
|
26278
|
-
|
|
26279
|
-
|
|
26280
|
-
|
|
26281
|
-
|
|
26282
|
-
|
|
26283
|
-
|
|
26284
|
-
|
|
26285
|
-
|
|
26547
|
+
// src/common-auth-embedded/setup/flags.js
|
|
26548
|
+
var UNAVAILABLE_HOST_MESSAGE = "Requested setup host is unknown or unavailable. Use --host=opencode or --host=pi with a detected host.";
|
|
26549
|
+
var SETUP_FLAGS = [
|
|
26550
|
+
{
|
|
26551
|
+
name: "--yes",
|
|
26552
|
+
key: "yes",
|
|
26553
|
+
description: "Run without questions and set up every found host. Does not choose the vault."
|
|
26554
|
+
},
|
|
26555
|
+
{
|
|
26556
|
+
name: "--dry-run",
|
|
26557
|
+
key: "dryRun",
|
|
26558
|
+
description: "Print what setup would do without changing anything."
|
|
26559
|
+
},
|
|
26560
|
+
{
|
|
26561
|
+
name: "--host",
|
|
26562
|
+
key: "hosts",
|
|
26563
|
+
values: ["opencode", "pi"],
|
|
26564
|
+
spaceForm: true,
|
|
26565
|
+
invalid: UNAVAILABLE_HOST_MESSAGE,
|
|
26566
|
+
description: "Set up only this host; repeat the flag for both. Also written --host=<host>."
|
|
26567
|
+
},
|
|
26568
|
+
{
|
|
26569
|
+
name: "--opencode",
|
|
26570
|
+
key: "opencode",
|
|
26571
|
+
values: ["1", "2", "both"],
|
|
26572
|
+
description: "Register for this OpenCode generation."
|
|
26573
|
+
},
|
|
26574
|
+
{
|
|
26575
|
+
name: "--claustrum",
|
|
26576
|
+
key: "claustrum",
|
|
26577
|
+
description: "Connect the hosts to the Claustrum vault."
|
|
26578
|
+
},
|
|
26579
|
+
{
|
|
26580
|
+
name: "--no-claustrum",
|
|
26581
|
+
key: "noClaustrum",
|
|
26582
|
+
description: "Do not offer the Claustrum vault; sign in locally."
|
|
26583
|
+
},
|
|
26584
|
+
{
|
|
26585
|
+
name: "--login",
|
|
26586
|
+
key: "login",
|
|
26587
|
+
description: "Sign in locally instead of using the Claustrum vault."
|
|
26588
|
+
},
|
|
26589
|
+
{
|
|
26590
|
+
name: "--enroll-only",
|
|
26591
|
+
key: "enrollOnly",
|
|
26592
|
+
description: "Only connect the hosts to the Claustrum vault; register nothing and migrate nothing."
|
|
26593
|
+
}
|
|
26594
|
+
];
|
|
26595
|
+
function unknownArgument(arg) {
|
|
26596
|
+
return new Error(`Unknown setup argument: ${arg}. Run the plugin's own setup --help to list the flags setup accepts.`);
|
|
26597
|
+
}
|
|
26598
|
+
function parseSetupFlags(argv) {
|
|
26599
|
+
const result = {
|
|
26600
|
+
yes: false,
|
|
26601
|
+
dryRun: false,
|
|
26602
|
+
claustrum: false,
|
|
26603
|
+
noClaustrum: false,
|
|
26604
|
+
login: false,
|
|
26605
|
+
enrollOnly: false,
|
|
26606
|
+
hosts: [],
|
|
26607
|
+
opencode: void 0
|
|
26608
|
+
};
|
|
26609
|
+
for (let index = 0; index < argv.length; index++) {
|
|
26610
|
+
const arg = argv[index];
|
|
26611
|
+
const equals = arg.indexOf("=");
|
|
26612
|
+
const name = equals === -1 ? arg : arg.slice(0, equals);
|
|
26613
|
+
const flag = SETUP_FLAGS.find((entry) => entry.name === name);
|
|
26614
|
+
if (!flag)
|
|
26615
|
+
throw unknownArgument(arg);
|
|
26616
|
+
if (!("values" in flag)) {
|
|
26617
|
+
if (equals !== -1)
|
|
26618
|
+
throw unknownArgument(arg);
|
|
26619
|
+
result[flag.key] = true;
|
|
26620
|
+
continue;
|
|
26621
|
+
}
|
|
26622
|
+
let value;
|
|
26623
|
+
if (equals !== -1)
|
|
26624
|
+
value = arg.slice(equals + 1);
|
|
26625
|
+
else if (flag.spaceForm)
|
|
26626
|
+
value = argv[++index];
|
|
26627
|
+
else
|
|
26628
|
+
throw unknownArgument(arg);
|
|
26629
|
+
if (value === void 0 || !flag.values.includes(value))
|
|
26630
|
+
throw flag.invalid ? new Error(flag.invalid) : unknownArgument(arg);
|
|
26631
|
+
if (flag.key === "hosts")
|
|
26632
|
+
result.hosts.push(value);
|
|
26633
|
+
else
|
|
26634
|
+
result.opencode = value;
|
|
26635
|
+
}
|
|
26636
|
+
if (result.claustrum && result.noClaustrum)
|
|
26637
|
+
throw new Error("--claustrum and --no-claustrum cannot be used together.");
|
|
26638
|
+
if (result.login && result.claustrum)
|
|
26639
|
+
throw new Error("--login and --claustrum cannot be used together.");
|
|
26640
|
+
if (result.enrollOnly && result.login)
|
|
26641
|
+
throw new Error("--enroll-only and --login cannot be used together.");
|
|
26642
|
+
if (result.enrollOnly && result.noClaustrum)
|
|
26643
|
+
throw new Error("--enroll-only and --no-claustrum cannot be used together.");
|
|
26644
|
+
return result;
|
|
26645
|
+
}
|
|
26646
|
+
|
|
26647
|
+
// src/common-auth-embedded/setup/prompts.js
|
|
26648
|
+
async function selectSetupHosts(terminal, found) {
|
|
26649
|
+
const selected = new Set(found);
|
|
26650
|
+
for (; ; ) {
|
|
26651
|
+
const choice = await select2(terminal, [
|
|
26652
|
+
...["opencode", "pi"].map((host) => ({
|
|
26653
|
+
value: host,
|
|
26654
|
+
label: `[${selected.has(host) ? "x" : " "}] ${host === "opencode" ? "OpenCode" : "Pi"}`,
|
|
26655
|
+
hint: found.includes(host) ? "found" : "not found"
|
|
26656
|
+
})),
|
|
26657
|
+
{ value: "done", label: "Continue with selected hosts" }
|
|
26658
|
+
], {
|
|
26659
|
+
message: "Select hosts to set up",
|
|
26660
|
+
subtitle: "Enter toggles a host; choose Continue when ready."
|
|
26661
|
+
});
|
|
26662
|
+
if (choice === null)
|
|
26663
|
+
return null;
|
|
26664
|
+
if (choice === "done")
|
|
26286
26665
|
return [...selected];
|
|
26287
26666
|
if (selected.has(choice))
|
|
26288
26667
|
selected.delete(choice);
|
|
@@ -26298,11 +26677,11 @@ import { applyEdits, createScanner, findNodeAtLocation, modify, parse as parse2,
|
|
|
26298
26677
|
// src/common-auth-embedded/setup/config-write.js
|
|
26299
26678
|
import { randomUUID as randomUUID16 } from "node:crypto";
|
|
26300
26679
|
import { mkdir as mkdir14, open as open11, rename as rename11, stat as stat11, unlink as unlink10 } from "node:fs/promises";
|
|
26301
|
-
import { basename as basename5, dirname as
|
|
26680
|
+
import { basename as basename5, dirname as dirname19, join as join18 } from "node:path";
|
|
26302
26681
|
import { setTimeout as delay2 } from "node:timers/promises";
|
|
26303
26682
|
async function writeHostConfigAtomic(file, content, options = {}) {
|
|
26304
26683
|
const windows = (options.platform ?? process.platform) === "win32";
|
|
26305
|
-
const parent =
|
|
26684
|
+
const parent = dirname19(file);
|
|
26306
26685
|
await mkdir14(parent, { recursive: true });
|
|
26307
26686
|
let mode;
|
|
26308
26687
|
if (!windows) {
|
|
@@ -26313,7 +26692,7 @@ async function writeHostConfigAtomic(file, content, options = {}) {
|
|
|
26313
26692
|
throw error;
|
|
26314
26693
|
}
|
|
26315
26694
|
}
|
|
26316
|
-
const stage =
|
|
26695
|
+
const stage = join18(parent, `.${basename5(file)}.${(options.stageName ?? randomUUID16)()}.tmp`);
|
|
26317
26696
|
let created = false;
|
|
26318
26697
|
try {
|
|
26319
26698
|
const handle = await open11(stage, "wx", mode ?? 438);
|
|
@@ -26469,8 +26848,8 @@ function planOpenCodeRegistration(plugin, generation, io = {}) {
|
|
|
26469
26848
|
const jsonc = path2.join(opencode, `${name}.jsonc`);
|
|
26470
26849
|
const json = path2.join(opencode, `${name}.json`);
|
|
26471
26850
|
const file = fs2.exists(jsonc) ? jsonc : fs2.exists(json) ? json : jsonc;
|
|
26472
|
-
const
|
|
26473
|
-
const before =
|
|
26851
|
+
const exists3 = fs2.exists(file);
|
|
26852
|
+
const before = exists3 ? fs2.readText(file) : `${JSON.stringify({ $schema: `https://opencode.ai/${name === "tui" ? "tui" : "config"}.json` }, null, 2)}
|
|
26474
26853
|
`;
|
|
26475
26854
|
const config = pluginConfig(before, key);
|
|
26476
26855
|
const existingLocalEntries = [];
|
|
@@ -26497,7 +26876,7 @@ function planOpenCodeRegistration(plugin, generation, io = {}) {
|
|
|
26497
26876
|
existingNpmEntries
|
|
26498
26877
|
};
|
|
26499
26878
|
const content = updatePluginConfig(before, key, plugin.packages.opencode, plugin.version);
|
|
26500
|
-
return { path: file, content, changed: !
|
|
26879
|
+
return { path: file, content, changed: !exists3 || content !== before };
|
|
26501
26880
|
});
|
|
26502
26881
|
}
|
|
26503
26882
|
async function registerOpenCode(writes, beforeWrite) {
|
|
@@ -26524,51 +26903,6 @@ async function registerPi(plugin, executable, io = {}) {
|
|
|
26524
26903
|
|
|
26525
26904
|
// src/common-auth-embedded/setup/command.js
|
|
26526
26905
|
var AMBIGUOUS_OPENCODE_MESSAGE = "Multiple OpenCode generations found. Choose --opencode=1|2|both before running noninteractive setup.";
|
|
26527
|
-
var UNAVAILABLE_HOST_MESSAGE = "Requested setup host is unknown or unavailable. Use --host=opencode or --host=pi with a detected host.";
|
|
26528
|
-
function flags(argv) {
|
|
26529
|
-
const result = {
|
|
26530
|
-
yes: false,
|
|
26531
|
-
dryRun: false,
|
|
26532
|
-
claustrum: false,
|
|
26533
|
-
noClaustrum: false,
|
|
26534
|
-
login: false,
|
|
26535
|
-
enrollOnly: false,
|
|
26536
|
-
hosts: [],
|
|
26537
|
-
opencode: void 0
|
|
26538
|
-
};
|
|
26539
|
-
for (const arg of argv) {
|
|
26540
|
-
if (arg === "--yes")
|
|
26541
|
-
result.yes = true;
|
|
26542
|
-
else if (arg === "--dry-run")
|
|
26543
|
-
result.dryRun = true;
|
|
26544
|
-
else if (arg === "--claustrum")
|
|
26545
|
-
result.claustrum = true;
|
|
26546
|
-
else if (arg === "--no-claustrum")
|
|
26547
|
-
result.noClaustrum = true;
|
|
26548
|
-
else if (arg === "--login")
|
|
26549
|
-
result.login = true;
|
|
26550
|
-
else if (arg === "--enroll-only")
|
|
26551
|
-
result.enrollOnly = true;
|
|
26552
|
-
else if (arg.startsWith("--host=")) {
|
|
26553
|
-
const host = arg.slice("--host=".length);
|
|
26554
|
-
if (host !== "opencode" && host !== "pi")
|
|
26555
|
-
throw new Error(UNAVAILABLE_HOST_MESSAGE);
|
|
26556
|
-
result.hosts.push(host);
|
|
26557
|
-
} else if (/^--opencode=(1|2|both)$/.test(arg))
|
|
26558
|
-
result.opencode = arg.slice("--opencode=".length);
|
|
26559
|
-
else
|
|
26560
|
-
throw new Error(`Unknown setup argument: ${arg}`);
|
|
26561
|
-
}
|
|
26562
|
-
if (result.claustrum && result.noClaustrum)
|
|
26563
|
-
throw new Error("--claustrum and --no-claustrum cannot be used together.");
|
|
26564
|
-
if (result.login && result.claustrum)
|
|
26565
|
-
throw new Error("--login and --claustrum cannot be used together.");
|
|
26566
|
-
if (result.enrollOnly && result.login)
|
|
26567
|
-
throw new Error("--enroll-only and --login cannot be used together.");
|
|
26568
|
-
if (result.enrollOnly && result.noClaustrum)
|
|
26569
|
-
throw new Error("--enroll-only and --no-claustrum cannot be used together.");
|
|
26570
|
-
return result;
|
|
26571
|
-
}
|
|
26572
26906
|
function validatePlugin(plugin) {
|
|
26573
26907
|
for (const pkg of Object.values(plugin.packages)) {
|
|
26574
26908
|
if (!/^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/.test(pkg))
|
|
@@ -26598,7 +26932,7 @@ async function enrollmentReport(plugin, hosts, recorded) {
|
|
|
26598
26932
|
return report;
|
|
26599
26933
|
}
|
|
26600
26934
|
async function runSetup(plugin, argv = [], io = {}) {
|
|
26601
|
-
const options =
|
|
26935
|
+
const options = parseSetupFlags(argv);
|
|
26602
26936
|
validatePlugin(plugin);
|
|
26603
26937
|
const terminal = io.terminal ?? processTerminal2();
|
|
26604
26938
|
const detection = await detectHosts(plugin, io);
|
|
@@ -26709,7 +27043,7 @@ async function runSetup(plugin, argv = [], io = {}) {
|
|
|
26709
27043
|
${write.content}`);
|
|
26710
27044
|
if (!options.enrollOnly && hosts.includes("pi"))
|
|
26711
27045
|
printLine2(terminal, `Would run ${detection.pi.executable} install npm:${plugin.packages.pi}@${plugin.version}`);
|
|
26712
|
-
if (!options.enrollOnly)
|
|
27046
|
+
if (!options.enrollOnly && plugin.migrate)
|
|
26713
27047
|
for (const host of hosts)
|
|
26714
27048
|
printLine2(terminal, `Would migrate ${host} using the plugin callback (provider-specific writes).`);
|
|
26715
27049
|
} else {
|
|
@@ -26747,7 +27081,7 @@ ${write.content}`);
|
|
|
26747
27081
|
else
|
|
26748
27082
|
await registerPi(plugin, detection.pi.executable, io);
|
|
26749
27083
|
await stopped();
|
|
26750
|
-
await plugin.migrate(host, context);
|
|
27084
|
+
await plugin.migrate?.(host, context);
|
|
26751
27085
|
}
|
|
26752
27086
|
} catch (error) {
|
|
26753
27087
|
if (enrollment.size === 0)
|
|
@@ -26772,31 +27106,921 @@ ${write.content}`);
|
|
|
26772
27106
|
}
|
|
26773
27107
|
|
|
26774
27108
|
// src/plugin/vault-activation.ts
|
|
26775
|
-
import { homedir as
|
|
26776
|
-
import { join as
|
|
26777
|
-
function nativeOpenCodeAuthPath(env3 = process.env, home =
|
|
26778
|
-
return
|
|
26779
|
-
env3.XDG_DATA_HOME ||
|
|
27109
|
+
import { homedir as homedir7 } from "node:os";
|
|
27110
|
+
import { join as join19 } from "node:path";
|
|
27111
|
+
function nativeOpenCodeAuthPath(env3 = process.env, home = homedir7()) {
|
|
27112
|
+
return join19(
|
|
27113
|
+
env3.XDG_DATA_HOME || join19(home, ".local", "share"),
|
|
26780
27114
|
"opencode",
|
|
26781
27115
|
"auth.json"
|
|
26782
27116
|
);
|
|
26783
27117
|
}
|
|
26784
27118
|
|
|
27119
|
+
// src/runtime-layout.ts
|
|
27120
|
+
import { createHash as createHash12 } from "node:crypto";
|
|
27121
|
+
import {
|
|
27122
|
+
chmod as chmod5,
|
|
27123
|
+
mkdir as mkdir15,
|
|
27124
|
+
readdir as readdir3,
|
|
27125
|
+
readFile as readFile12,
|
|
27126
|
+
rmdir as rmdir2,
|
|
27127
|
+
stat as stat12,
|
|
27128
|
+
unlink as unlink11
|
|
27129
|
+
} from "node:fs/promises";
|
|
27130
|
+
import { basename as basename6, dirname as dirname20, join as join20, resolve as resolve17 } from "node:path";
|
|
27131
|
+
var RUNTIME_LAYOUT_LOCK_NAME = "runtime-layout";
|
|
27132
|
+
var RUNTIME_LAYOUT_MANIFEST_FILE = "layout-moving.json";
|
|
27133
|
+
var VAULT_ENROLLMENT_STATE_FILE = "opencode-enrollment-state.json";
|
|
27134
|
+
var VAULT_ENROLLMENT_TOKEN_FILE = "opencode-enrollment.json";
|
|
27135
|
+
var VAULT_FILE_NAMES = [
|
|
27136
|
+
VAULT_ENROLLMENT_TOKEN_FILE,
|
|
27137
|
+
VAULT_ENROLLMENT_STATE_FILE,
|
|
27138
|
+
"opencode-roster.json",
|
|
27139
|
+
"opencode-state.json",
|
|
27140
|
+
"opencode-mode.json"
|
|
27141
|
+
];
|
|
27142
|
+
var LOCK_TTL_MS = 1e4;
|
|
27143
|
+
var DATA_LOCKS = [
|
|
27144
|
+
{ name: "ceremony", file: VAULT_ENROLLMENT_STATE_FILE, waitMs: 35e3 },
|
|
27145
|
+
{
|
|
27146
|
+
name: "claustrum-roster-write",
|
|
27147
|
+
file: "opencode-roster.json",
|
|
27148
|
+
waitMs: 15e3
|
|
27149
|
+
},
|
|
27150
|
+
{
|
|
27151
|
+
name: "antigravity-vault-state",
|
|
27152
|
+
file: "opencode-state.json",
|
|
27153
|
+
waitMs: 15e3
|
|
27154
|
+
}
|
|
27155
|
+
];
|
|
27156
|
+
var LAYOUT_LOCK_WAIT_MS = DATA_LOCKS.reduce((sum, lock) => sum + lock.waitMs, 0) + LOCK_TTL_MS;
|
|
27157
|
+
var LOCK_RETRY_MS = 50;
|
|
27158
|
+
var LOCK_WAIT_NOTICE_MS = 1e3;
|
|
27159
|
+
var MARKER_READ_ATTEMPTS = 5;
|
|
27160
|
+
var MARKER_READ_RETRY_MS = 50;
|
|
27161
|
+
var SHARING_RETRY_DELAYS_MS = [0, 10, 20, 40, 80, 100];
|
|
27162
|
+
var SHARING_RETRY_BUDGET_MS = 500;
|
|
27163
|
+
var RUNTIME_LAYOUT_DEFERRED_MESSAGE = "antigravity-auth keeps its vault files in OpenCode's config folder until every running OpenCode using it has restarted on this version.";
|
|
27164
|
+
var RuntimeLayoutRefusal = class extends Error {
|
|
27165
|
+
constructor(stateDir, errorClass2, message = refusalMessage2(stateDir, errorClass2)) {
|
|
27166
|
+
super(message);
|
|
27167
|
+
this.stateDir = stateDir;
|
|
27168
|
+
this.errorClass = errorClass2;
|
|
27169
|
+
this.name = "RuntimeLayoutRefusal";
|
|
27170
|
+
}
|
|
27171
|
+
stateDir;
|
|
27172
|
+
errorClass;
|
|
27173
|
+
};
|
|
27174
|
+
function refusalMessage2(stateDir, errorClass2) {
|
|
27175
|
+
if (errorClass2 === "ERR_PRIVATE_FILES_SECURITY")
|
|
27176
|
+
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.`;
|
|
27177
|
+
return `antigravity-auth cannot start: it could not settle where its vault files live in ${stateDir} (${errorClass2}). Check that this folder can be created and written by your user, then restart OpenCode.`;
|
|
27178
|
+
}
|
|
27179
|
+
function foreignFolder(stateDir, identity3) {
|
|
27180
|
+
return new RuntimeLayoutRefusal(
|
|
27181
|
+
stateDir,
|
|
27182
|
+
"foreign-folder",
|
|
27183
|
+
`antigravity-auth cannot start: ${stateDir} belongs to another OpenCode config folder, not ${identity3}. It was left untouched. Move it aside, then restart OpenCode.`
|
|
27184
|
+
);
|
|
27185
|
+
}
|
|
27186
|
+
function markerRemedy(markerPath, oldVaultDir) {
|
|
27187
|
+
return `Check that the old vault files are still in ${oldVaultDir}. If they are, delete ${markerPath}, then restart OpenCode; if they are not, keep ${dirname20(markerPath)} as it is.`;
|
|
27188
|
+
}
|
|
27189
|
+
function foreignMarker(markerPath, identity3, oldVaultDir) {
|
|
27190
|
+
return new RuntimeLayoutRefusal(
|
|
27191
|
+
dirname20(markerPath),
|
|
27192
|
+
"foreign-marker",
|
|
27193
|
+
`antigravity-auth cannot start: ${markerPath} belongs to another OpenCode config folder, not ${identity3}, so it cannot tell whether this folder's vault files were moved. ${markerRemedy(markerPath, oldVaultDir)}`
|
|
27194
|
+
);
|
|
27195
|
+
}
|
|
27196
|
+
function credentialConflict(stateDir, file) {
|
|
27197
|
+
return new RuntimeLayoutRefusal(
|
|
27198
|
+
stateDir,
|
|
27199
|
+
"credential-conflict",
|
|
27200
|
+
`antigravity-auth cannot start: vault files conflict between ${file.old} and ${file.next}. Keep the newer one, delete the other, then restart OpenCode.`
|
|
27201
|
+
);
|
|
27202
|
+
}
|
|
27203
|
+
var stateKey2 = /* @__PURE__ */ Symbol.for("@cortexkit/antigravity-auth/runtime-layout-runs");
|
|
27204
|
+
var globalState2 = globalThis;
|
|
27205
|
+
var processState = globalState2[stateKey2] ?? {
|
|
27206
|
+
runs: /* @__PURE__ */ new Map(),
|
|
27207
|
+
logged: /* @__PURE__ */ new Set()
|
|
27208
|
+
};
|
|
27209
|
+
globalState2[stateKey2] = processState;
|
|
27210
|
+
function logOnce(key, write) {
|
|
27211
|
+
if (processState.logged.has(key)) return;
|
|
27212
|
+
processState.logged.add(key);
|
|
27213
|
+
write();
|
|
27214
|
+
}
|
|
27215
|
+
function errorClass(error) {
|
|
27216
|
+
if (error instanceof RuntimeLayoutRefusal) return error.errorClass;
|
|
27217
|
+
const code2 = error?.code;
|
|
27218
|
+
if (typeof code2 === "string" && code2) return code2;
|
|
27219
|
+
return error instanceof Error ? error.name : typeof error;
|
|
27220
|
+
}
|
|
27221
|
+
function errorFile(error) {
|
|
27222
|
+
const { path: path2, stage } = error ?? {};
|
|
27223
|
+
return {
|
|
27224
|
+
...typeof path2 === "string" && path2 ? { file: basename6(path2) } : {},
|
|
27225
|
+
...typeof stage === "string" && stage ? { stage } : {}
|
|
27226
|
+
};
|
|
27227
|
+
}
|
|
27228
|
+
var LayoutMoveError = class extends Error {
|
|
27229
|
+
constructor(code2, message) {
|
|
27230
|
+
super(message);
|
|
27231
|
+
this.code = code2;
|
|
27232
|
+
this.name = "LayoutMoveError";
|
|
27233
|
+
}
|
|
27234
|
+
code;
|
|
27235
|
+
};
|
|
27236
|
+
var OldVaultFileKeptError = class extends LayoutMoveError {
|
|
27237
|
+
constructor(path2) {
|
|
27238
|
+
super("old-files-kept", `${path2} could not be removed`);
|
|
27239
|
+
this.path = path2;
|
|
27240
|
+
}
|
|
27241
|
+
path;
|
|
27242
|
+
};
|
|
27243
|
+
function logCleanupFailure(location, log8, step, error) {
|
|
27244
|
+
logOnce(
|
|
27245
|
+
`${location.key}\0cleanup`,
|
|
27246
|
+
() => log8.warn(
|
|
27247
|
+
"antigravity-auth could not finish removing its old vault files from OpenCode's config folder; it tries again at the next start",
|
|
27248
|
+
{
|
|
27249
|
+
configDir: location.configDir,
|
|
27250
|
+
step,
|
|
27251
|
+
errorClass: errorClass(error),
|
|
27252
|
+
...errorFile(error)
|
|
27253
|
+
}
|
|
27254
|
+
)
|
|
27255
|
+
);
|
|
27256
|
+
}
|
|
27257
|
+
function prepareRuntimeLayout(options) {
|
|
27258
|
+
const location = runtimeLayoutLocation();
|
|
27259
|
+
const decided = decidedRuntimeLayout(location);
|
|
27260
|
+
if (decided) return Promise.resolve(decided);
|
|
27261
|
+
const runKey = `${location.stateHomeDir}\0${location.key}`;
|
|
27262
|
+
let run = processState.runs.get(runKey);
|
|
27263
|
+
if (!run) {
|
|
27264
|
+
run = decide(location, options).catch((error) => {
|
|
27265
|
+
if (error instanceof RuntimeLayoutRefusal) throw error;
|
|
27266
|
+
throw new RuntimeLayoutRefusal(location.stateHomeDir, errorClass(error));
|
|
27267
|
+
}).finally(() => {
|
|
27268
|
+
processState.runs.delete(runKey);
|
|
27269
|
+
});
|
|
27270
|
+
processState.runs.set(runKey, run);
|
|
27271
|
+
}
|
|
27272
|
+
return run;
|
|
27273
|
+
}
|
|
27274
|
+
async function decide(location, options) {
|
|
27275
|
+
const log8 = options.log ?? createLogger4("runtime-layout");
|
|
27276
|
+
const stateDir = location.stateHomeDir;
|
|
27277
|
+
const markerPath = join20(stateDir, RUNTIME_LAYOUT_MARKER_FILE);
|
|
27278
|
+
const files = layoutFiles(location, options.accountFile);
|
|
27279
|
+
const fence = options.fence ?? defaultFence(options.version);
|
|
27280
|
+
const stateHome = async () => {
|
|
27281
|
+
await recordProcessLayout({
|
|
27282
|
+
key: location.key,
|
|
27283
|
+
layout: "state-home",
|
|
27284
|
+
version: options.version
|
|
27285
|
+
});
|
|
27286
|
+
setRuntimeLayout(location, "state-home");
|
|
27287
|
+
return "state-home";
|
|
27288
|
+
};
|
|
27289
|
+
let marker = await readMarker(markerPath, stateDir, files.vault.old);
|
|
27290
|
+
await assertOwnFolder(location, marker, files);
|
|
27291
|
+
if (marker?.oldFilesRemoved) {
|
|
27292
|
+
await refuseReappearedFiles(location, files);
|
|
27293
|
+
const manifestLeft = await exists2(
|
|
27294
|
+
join20(stateDir, RUNTIME_LAYOUT_MANIFEST_FILE)
|
|
27295
|
+
).catch(() => true);
|
|
27296
|
+
if (!manifestLeft) return stateHome();
|
|
27297
|
+
}
|
|
27298
|
+
const aliased = await samePhysical(location.configDir, stateDir);
|
|
27299
|
+
let layoutLock;
|
|
27300
|
+
try {
|
|
27301
|
+
if (!aliased) await ensureOwnerOnlyDir(stateDir);
|
|
27302
|
+
layoutLock = await takeLock(
|
|
27303
|
+
RUNTIME_LAYOUT_LOCK_NAME,
|
|
27304
|
+
markerPath,
|
|
27305
|
+
options.layoutLockWaitMs ?? LAYOUT_LOCK_WAIT_MS,
|
|
27306
|
+
log8
|
|
27307
|
+
);
|
|
27308
|
+
} catch (error) {
|
|
27309
|
+
marker = await readMarker(markerPath, stateDir, files.vault.old);
|
|
27310
|
+
if (marker) {
|
|
27311
|
+
if (marker.oldFilesRemoved) await refuseReappearedFiles(location, files);
|
|
27312
|
+
return stateHome();
|
|
27313
|
+
}
|
|
27314
|
+
if (error instanceof LayoutMoveError && error.code === "lock-timeout")
|
|
27315
|
+
throw new RuntimeLayoutRefusal(
|
|
27316
|
+
stateDir,
|
|
27317
|
+
"lock-timeout",
|
|
27318
|
+
`antigravity-auth cannot start: ${error.message} Try again, or restart OpenCode, once that OpenCode has finished the move.`
|
|
27319
|
+
);
|
|
27320
|
+
throw new RuntimeLayoutRefusal(stateDir, errorClass(error));
|
|
27321
|
+
}
|
|
27322
|
+
const lock = layoutLock;
|
|
27323
|
+
const legacy = async () => {
|
|
27324
|
+
try {
|
|
27325
|
+
await lock.assertOwned();
|
|
27326
|
+
await recordProcessLayout({
|
|
27327
|
+
key: location.key,
|
|
27328
|
+
layout: "legacy",
|
|
27329
|
+
version: options.version
|
|
27330
|
+
});
|
|
27331
|
+
} catch (error) {
|
|
27332
|
+
throw new RuntimeLayoutRefusal(stateDir, errorClass(error));
|
|
27333
|
+
}
|
|
27334
|
+
setRuntimeLayout(location, "legacy");
|
|
27335
|
+
return "legacy";
|
|
27336
|
+
};
|
|
27337
|
+
try {
|
|
27338
|
+
marker = await readMarker(markerPath, stateDir, files.vault.old);
|
|
27339
|
+
await assertOwnFolder(location, marker, files);
|
|
27340
|
+
if (!aliased) await writeOwnerNote(location);
|
|
27341
|
+
if (marker) {
|
|
27342
|
+
if (!marker.oldFilesRemoved && !aliased)
|
|
27343
|
+
await finishOldFiles(location, files, markerPath, marker, lock, {
|
|
27344
|
+
fence,
|
|
27345
|
+
log: log8,
|
|
27346
|
+
steps: options.steps,
|
|
27347
|
+
oldSignatureCache: options.oldSignatureCacheFile ?? legacySignatureCacheFile()
|
|
27348
|
+
});
|
|
27349
|
+
else if (marker.oldFilesRemoved) {
|
|
27350
|
+
await refuseReappearedFiles(location, files);
|
|
27351
|
+
await removeLeftoverManifest(location, lock, options.steps, log8);
|
|
27352
|
+
}
|
|
27353
|
+
return await stateHome();
|
|
27354
|
+
}
|
|
27355
|
+
if (aliased) {
|
|
27356
|
+
logOnce(
|
|
27357
|
+
`${location.key}\0aliased`,
|
|
27358
|
+
() => log8.warn(
|
|
27359
|
+
"antigravity-auth keeps its vault files in OpenCode's config folder: its state folder is that same folder",
|
|
27360
|
+
{ configDir: location.configDir, stateDir }
|
|
27361
|
+
)
|
|
27362
|
+
);
|
|
27363
|
+
return await legacy();
|
|
27364
|
+
}
|
|
27365
|
+
const gate = await fence();
|
|
27366
|
+
if (!gate.open) {
|
|
27367
|
+
logDeferral(location, gate.blockers, log8);
|
|
27368
|
+
return await legacy();
|
|
27369
|
+
}
|
|
27370
|
+
let markerStarted = false;
|
|
27371
|
+
try {
|
|
27372
|
+
const outcome = await moveFiles(location, files, markerPath, lock, {
|
|
27373
|
+
fence,
|
|
27374
|
+
log: log8,
|
|
27375
|
+
steps: options.steps,
|
|
27376
|
+
destinationPrivate: options.destinationPrivate ?? defaultDestinationPrivate,
|
|
27377
|
+
oldSignatureCache: options.oldSignatureCacheFile ?? legacySignatureCacheFile(),
|
|
27378
|
+
onMarker: () => {
|
|
27379
|
+
markerStarted = true;
|
|
27380
|
+
}
|
|
27381
|
+
});
|
|
27382
|
+
if (outcome.kind === "deferred") {
|
|
27383
|
+
logDeferral(location, outcome.blockers, log8);
|
|
27384
|
+
return await legacy();
|
|
27385
|
+
}
|
|
27386
|
+
if (outcome.kind === "refused") {
|
|
27387
|
+
logOnce(
|
|
27388
|
+
`${location.key}\0refused`,
|
|
27389
|
+
() => log8.warn(
|
|
27390
|
+
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",
|
|
27391
|
+
{ reason: outcome.reason, paths: outcome.paths, stateDir }
|
|
27392
|
+
)
|
|
27393
|
+
);
|
|
27394
|
+
return await legacy();
|
|
27395
|
+
}
|
|
27396
|
+
if (outcome.moved)
|
|
27397
|
+
log8.info(
|
|
27398
|
+
"antigravity-auth moved its vault files out of OpenCode's config folder",
|
|
27399
|
+
{ from: files.vault.old, to: files.vault.next }
|
|
27400
|
+
);
|
|
27401
|
+
return await stateHome();
|
|
27402
|
+
} catch (error) {
|
|
27403
|
+
if (error instanceof RuntimeLayoutRefusal) throw error;
|
|
27404
|
+
if (markerStarted && await readMarker(markerPath, stateDir, files.vault.old))
|
|
27405
|
+
return await stateHome();
|
|
27406
|
+
logOnce(
|
|
27407
|
+
`${location.key}\0failed`,
|
|
27408
|
+
() => log8.warn(
|
|
27409
|
+
"antigravity-auth's vault files stay in OpenCode's config folder: moving them failed; the move is tried again at the next start",
|
|
27410
|
+
{
|
|
27411
|
+
configDir: location.configDir,
|
|
27412
|
+
errorClass: errorClass(error),
|
|
27413
|
+
...errorFile(error)
|
|
27414
|
+
}
|
|
27415
|
+
)
|
|
27416
|
+
);
|
|
27417
|
+
return await legacy();
|
|
27418
|
+
}
|
|
27419
|
+
} finally {
|
|
27420
|
+
await lock.release().catch(() => {
|
|
27421
|
+
});
|
|
27422
|
+
}
|
|
27423
|
+
}
|
|
27424
|
+
function defaultFence(version) {
|
|
27425
|
+
return () => versionFenceOpen({ currentVersion: version, layoutMove: true });
|
|
27426
|
+
}
|
|
27427
|
+
function logDeferral(location, blockers, log8) {
|
|
27428
|
+
logOnce(
|
|
27429
|
+
`${location.key}\0deferred`,
|
|
27430
|
+
() => log8.info(RUNTIME_LAYOUT_DEFERRED_MESSAGE, {
|
|
27431
|
+
configDir: location.configDir,
|
|
27432
|
+
blockers
|
|
27433
|
+
})
|
|
27434
|
+
);
|
|
27435
|
+
}
|
|
27436
|
+
async function defaultDestinationPrivate(dir) {
|
|
27437
|
+
if (process.platform !== "win32") return true;
|
|
27438
|
+
if (!await exists2(dir)) return true;
|
|
27439
|
+
try {
|
|
27440
|
+
const { verifyPrivatePath } = await import("@cortexkit/private-files");
|
|
27441
|
+
await verifyPrivatePath(dir, "directory");
|
|
27442
|
+
return true;
|
|
27443
|
+
} catch {
|
|
27444
|
+
return false;
|
|
27445
|
+
}
|
|
27446
|
+
}
|
|
27447
|
+
async function moveFiles(location, files, markerPath, layoutLock, input) {
|
|
27448
|
+
const stateDir = location.stateHomeDir;
|
|
27449
|
+
const locks = await takeDataLocks(files, input.log);
|
|
27450
|
+
let oldVaultEmptied = false;
|
|
27451
|
+
try {
|
|
27452
|
+
const gate = await input.fence();
|
|
27453
|
+
if (!gate.open) return { kind: "deferred", blockers: gate.blockers };
|
|
27454
|
+
const aliases = await physicalAliases(location, files);
|
|
27455
|
+
if (aliases.length > 0)
|
|
27456
|
+
return { kind: "refused", reason: "same-physical-file", paths: aliases };
|
|
27457
|
+
const listed = await readManifest(stateDir);
|
|
27458
|
+
const foreign = (await destinationFiles(files)).filter(
|
|
27459
|
+
(path2) => !listed.has(path2)
|
|
27460
|
+
);
|
|
27461
|
+
if (foreign.length > 0)
|
|
27462
|
+
return { kind: "refused", reason: "destination-in-use", paths: foreign };
|
|
27463
|
+
if (!await input.destinationPrivate(files.vault.next))
|
|
27464
|
+
return {
|
|
27465
|
+
kind: "refused",
|
|
27466
|
+
reason: "destination-not-private",
|
|
27467
|
+
paths: [files.vault.next]
|
|
27468
|
+
};
|
|
27469
|
+
const present2 = await presentOldFiles(files);
|
|
27470
|
+
await layoutLock.assertOwned();
|
|
27471
|
+
await writeManifest(stateDir, [
|
|
27472
|
+
.../* @__PURE__ */ new Set([...listed, ...present2.map((file) => file.next)])
|
|
27473
|
+
]);
|
|
27474
|
+
await input.steps?.afterManifest?.();
|
|
27475
|
+
const wanted = new Set(present2.map((file) => file.next));
|
|
27476
|
+
for (const path2 of listed) {
|
|
27477
|
+
if (wanted.has(path2)) continue;
|
|
27478
|
+
await layoutLock.assertOwned();
|
|
27479
|
+
await unlink11(path2).catch((error) => {
|
|
27480
|
+
if (error.code !== "ENOENT") throw error;
|
|
27481
|
+
});
|
|
27482
|
+
}
|
|
27483
|
+
for (const file of present2) {
|
|
27484
|
+
await layoutLock.assertOwned();
|
|
27485
|
+
await copyVerified(file);
|
|
27486
|
+
}
|
|
27487
|
+
await input.steps?.afterCopy?.();
|
|
27488
|
+
await layoutLock.assertOwned();
|
|
27489
|
+
for (const lock of locks) await lock.assertOwned();
|
|
27490
|
+
const keptVaultState = await keepableVaultState(files, present2);
|
|
27491
|
+
const marker = {
|
|
27492
|
+
version: 1,
|
|
27493
|
+
oldDir: location.key,
|
|
27494
|
+
...keptVaultState ? { keptVaultState } : {}
|
|
27495
|
+
};
|
|
27496
|
+
input.onMarker();
|
|
27497
|
+
await writeMarker(markerPath, marker);
|
|
27498
|
+
await input.steps?.afterMarker?.();
|
|
27499
|
+
await layoutLock.assertOwned();
|
|
27500
|
+
try {
|
|
27501
|
+
await removeOldCopies(location, files, present2, layoutLock, {
|
|
27502
|
+
log: input.log,
|
|
27503
|
+
keptVaultState,
|
|
27504
|
+
steps: input.steps
|
|
27505
|
+
});
|
|
27506
|
+
} catch (error) {
|
|
27507
|
+
if (!(error instanceof OldVaultFileKeptError)) throw error;
|
|
27508
|
+
logCleanupFailure(location, input.log, "remove-old-copies", error);
|
|
27509
|
+
return { kind: "moved", moved: present2.length > 0 };
|
|
27510
|
+
}
|
|
27511
|
+
oldVaultEmptied = true;
|
|
27512
|
+
await removeOldSignatureCache(
|
|
27513
|
+
location,
|
|
27514
|
+
input.oldSignatureCache,
|
|
27515
|
+
layoutLock,
|
|
27516
|
+
input.steps,
|
|
27517
|
+
input.log
|
|
27518
|
+
);
|
|
27519
|
+
await layoutLock.assertOwned();
|
|
27520
|
+
await writeMarker(markerPath, { ...marker, oldFilesRemoved: true });
|
|
27521
|
+
await removeManifestOwned(stateDir, layoutLock, input.steps);
|
|
27522
|
+
return { kind: "moved", moved: present2.length > 0 };
|
|
27523
|
+
} finally {
|
|
27524
|
+
for (const lock of locks.reverse()) await lock.release().catch(() => {
|
|
27525
|
+
});
|
|
27526
|
+
if (oldVaultEmptied)
|
|
27527
|
+
await removeOldVaultFolder(files, layoutLock, input.steps);
|
|
27528
|
+
}
|
|
27529
|
+
}
|
|
27530
|
+
async function finishOldFiles(location, files, markerPath, marker, layoutLock, input) {
|
|
27531
|
+
let locks = [];
|
|
27532
|
+
let done = false;
|
|
27533
|
+
let step = "fence";
|
|
27534
|
+
try {
|
|
27535
|
+
if (!(await input.fence()).open) return;
|
|
27536
|
+
step = "data-locks";
|
|
27537
|
+
locks = await takeDataLocks(files, input.log);
|
|
27538
|
+
step = "fence";
|
|
27539
|
+
if (!(await input.fence()).open) return;
|
|
27540
|
+
step = "same-file-check";
|
|
27541
|
+
const aliases = await physicalAliases(location, files);
|
|
27542
|
+
if (aliases.length > 0) {
|
|
27543
|
+
logOnce(
|
|
27544
|
+
`${location.key}\0cleanup-aliased`,
|
|
27545
|
+
() => input.log.warn(
|
|
27546
|
+
"antigravity-auth leaves its old vault files in OpenCode's config folder: they are the same files as its new ones",
|
|
27547
|
+
{ paths: aliases }
|
|
27548
|
+
)
|
|
27549
|
+
);
|
|
27550
|
+
return;
|
|
27551
|
+
}
|
|
27552
|
+
step = "remove-old-copies";
|
|
27553
|
+
await layoutLock.assertOwned();
|
|
27554
|
+
await removeOldCopies(
|
|
27555
|
+
location,
|
|
27556
|
+
files,
|
|
27557
|
+
await presentOldFiles(files),
|
|
27558
|
+
layoutLock,
|
|
27559
|
+
{
|
|
27560
|
+
log: input.log,
|
|
27561
|
+
keptVaultState: marker.keptVaultState,
|
|
27562
|
+
steps: input.steps
|
|
27563
|
+
}
|
|
27564
|
+
);
|
|
27565
|
+
done = true;
|
|
27566
|
+
step = "signature-cache";
|
|
27567
|
+
await removeOldSignatureCache(
|
|
27568
|
+
location,
|
|
27569
|
+
input.oldSignatureCache,
|
|
27570
|
+
layoutLock,
|
|
27571
|
+
input.steps,
|
|
27572
|
+
input.log
|
|
27573
|
+
);
|
|
27574
|
+
step = "marker";
|
|
27575
|
+
await layoutLock.assertOwned();
|
|
27576
|
+
await writeMarker(markerPath, { ...marker, oldFilesRemoved: true });
|
|
27577
|
+
step = "manifest";
|
|
27578
|
+
await removeManifestOwned(location.stateHomeDir, layoutLock, input.steps);
|
|
27579
|
+
} catch (error) {
|
|
27580
|
+
if (error instanceof RuntimeLayoutRefusal) throw error;
|
|
27581
|
+
logCleanupFailure(location, input.log, step, error);
|
|
27582
|
+
} finally {
|
|
27583
|
+
for (const lock of locks.reverse()) await lock.release().catch(() => {
|
|
27584
|
+
});
|
|
27585
|
+
if (done) await removeOldVaultFolder(files, layoutLock, input.steps);
|
|
27586
|
+
}
|
|
27587
|
+
}
|
|
27588
|
+
async function removeLeftoverManifest(location, layoutLock, steps, log8) {
|
|
27589
|
+
try {
|
|
27590
|
+
await removeManifestOwned(location.stateHomeDir, layoutLock, steps);
|
|
27591
|
+
} catch (error) {
|
|
27592
|
+
logOnce(
|
|
27593
|
+
`${location.key}\0manifest`,
|
|
27594
|
+
() => log8.warn(
|
|
27595
|
+
`antigravity-auth could not remove ${RUNTIME_LAYOUT_MANIFEST_FILE} from its state folder; it tries again at the next start`,
|
|
27596
|
+
{ stateDir: location.stateHomeDir, errorClass: errorClass(error) }
|
|
27597
|
+
)
|
|
27598
|
+
);
|
|
27599
|
+
}
|
|
27600
|
+
}
|
|
27601
|
+
async function removeManifestOwned(stateDir, layoutLock, steps) {
|
|
27602
|
+
const path2 = join20(stateDir, RUNTIME_LAYOUT_MANIFEST_FILE);
|
|
27603
|
+
if (!await exists2(path2)) return;
|
|
27604
|
+
await beforeRemove(path2, layoutLock, steps);
|
|
27605
|
+
await removeManifest(stateDir);
|
|
27606
|
+
}
|
|
27607
|
+
async function removeOldVaultFolder(files, layoutLock, steps) {
|
|
27608
|
+
try {
|
|
27609
|
+
await beforeRemove(files.vault.old, layoutLock, steps);
|
|
27610
|
+
await rmdir2(files.vault.old);
|
|
27611
|
+
} catch {
|
|
27612
|
+
}
|
|
27613
|
+
}
|
|
27614
|
+
async function removeOldSignatureCache(location, path2, layoutLock, steps, log8) {
|
|
27615
|
+
try {
|
|
27616
|
+
if (!await exists2(path2)) return;
|
|
27617
|
+
await beforeRemove(path2, layoutLock, steps);
|
|
27618
|
+
await unlink11(path2);
|
|
27619
|
+
} catch (error) {
|
|
27620
|
+
if (error?.code === "ENOENT") return;
|
|
27621
|
+
logOnce(
|
|
27622
|
+
`${location.key}\0signature-cache`,
|
|
27623
|
+
() => log8.warn(
|
|
27624
|
+
"antigravity-auth could not remove its old signature cache from OpenCode's config folder; it is no longer used and can be deleted",
|
|
27625
|
+
{ path: path2, errorClass: errorClass(error) }
|
|
27626
|
+
)
|
|
27627
|
+
);
|
|
27628
|
+
}
|
|
27629
|
+
}
|
|
27630
|
+
async function beforeRemove(path2, layoutLock, steps) {
|
|
27631
|
+
await steps?.beforeRemove?.(path2);
|
|
27632
|
+
await layoutLock.assertOwned();
|
|
27633
|
+
}
|
|
27634
|
+
async function takeDataLocks(files, log8) {
|
|
27635
|
+
const locks = [];
|
|
27636
|
+
try {
|
|
27637
|
+
if (await exists2(files.vault.old))
|
|
27638
|
+
for (const lock of DATA_LOCKS)
|
|
27639
|
+
locks.push(
|
|
27640
|
+
await takeLock(
|
|
27641
|
+
lock.name,
|
|
27642
|
+
join20(files.vault.old, lock.file),
|
|
27643
|
+
lock.waitMs,
|
|
27644
|
+
log8
|
|
27645
|
+
)
|
|
27646
|
+
);
|
|
27647
|
+
return locks;
|
|
27648
|
+
} catch (error) {
|
|
27649
|
+
for (const lock of locks.reverse()) await lock.release().catch(() => {
|
|
27650
|
+
});
|
|
27651
|
+
throw error;
|
|
27652
|
+
}
|
|
27653
|
+
}
|
|
27654
|
+
function layoutFiles(location, accountFile) {
|
|
27655
|
+
return {
|
|
27656
|
+
vault: {
|
|
27657
|
+
old: legacyVaultDir(accountFile ?? legacyAccountFile(location.configDir)),
|
|
27658
|
+
next: stateHomeVaultDir(location)
|
|
27659
|
+
}
|
|
27660
|
+
};
|
|
27661
|
+
}
|
|
27662
|
+
var SHA256_HEX2 = /^[0-9a-f]{64}$/;
|
|
27663
|
+
function sha256(bytes) {
|
|
27664
|
+
return createHash12("sha256").update(bytes).digest("hex");
|
|
27665
|
+
}
|
|
27666
|
+
function vaultStateFile(files) {
|
|
27667
|
+
return {
|
|
27668
|
+
old: join20(files.vault.old, VAULT_ENROLLMENT_STATE_FILE),
|
|
27669
|
+
next: join20(files.vault.next, VAULT_ENROLLMENT_STATE_FILE)
|
|
27670
|
+
};
|
|
27671
|
+
}
|
|
27672
|
+
async function keepableVaultState(files, present2) {
|
|
27673
|
+
const state = vaultStateFile(files);
|
|
27674
|
+
if (!present2.some((file) => file.old === state.old)) return void 0;
|
|
27675
|
+
const bytes = await readFile12(state.next);
|
|
27676
|
+
let value;
|
|
27677
|
+
try {
|
|
27678
|
+
value = JSON.parse(bytes.toString("utf8"));
|
|
27679
|
+
} catch {
|
|
27680
|
+
return void 0;
|
|
27681
|
+
}
|
|
27682
|
+
const vaultMode = value?.phase === "approved" || value?.phase === "blocked" && value.errorCode === "missing_token";
|
|
27683
|
+
return vaultMode ? sha256(bytes) : void 0;
|
|
27684
|
+
}
|
|
27685
|
+
async function isVaultShapedKeptState(files) {
|
|
27686
|
+
const vault = files.vault.old;
|
|
27687
|
+
const present2 = await vaultFiles(vault);
|
|
27688
|
+
if (present2.includes(VAULT_ENROLLMENT_TOKEN_FILE)) return false;
|
|
27689
|
+
const claustrum = await loadCommonAuthClaustrum();
|
|
27690
|
+
let status;
|
|
27691
|
+
try {
|
|
27692
|
+
status = await claustrum.readClaustrumEnrollmentStatus(
|
|
27693
|
+
claustrum.hostEnrollmentPaths({
|
|
27694
|
+
stateDir: vault,
|
|
27695
|
+
host: OPENCODE_VAULT_HOST
|
|
27696
|
+
}),
|
|
27697
|
+
OPENCODE_VAULT_ENROLLMENT_NAME
|
|
27698
|
+
);
|
|
27699
|
+
} catch {
|
|
27700
|
+
return false;
|
|
27701
|
+
}
|
|
27702
|
+
const vaultShape = status.state === "approved" || status.state === "blocked" && status.code === "missing_token";
|
|
27703
|
+
const proposedName = "proposedName" in status ? status.proposedName : void 0;
|
|
27704
|
+
return vaultShape && proposedName === OPENCODE_VAULT_ENROLLMENT_NAME;
|
|
27705
|
+
}
|
|
27706
|
+
async function vaultFiles(dir) {
|
|
27707
|
+
let entries;
|
|
27708
|
+
try {
|
|
27709
|
+
entries = await readdir3(dir, { withFileTypes: true });
|
|
27710
|
+
} catch (error) {
|
|
27711
|
+
const code2 = error.code;
|
|
27712
|
+
if (code2 === "ENOENT" || code2 === "ENOTDIR") return [];
|
|
27713
|
+
throw error;
|
|
27714
|
+
}
|
|
27715
|
+
const allowed = new Set(VAULT_FILE_NAMES);
|
|
27716
|
+
return entries.filter((entry) => entry.isFile() && allowed.has(entry.name)).map((entry) => entry.name).sort(
|
|
27717
|
+
(a, b) => VAULT_FILE_NAMES.indexOf(a) - VAULT_FILE_NAMES.indexOf(b)
|
|
27718
|
+
);
|
|
27719
|
+
}
|
|
27720
|
+
async function presentOldFiles(files) {
|
|
27721
|
+
return (await vaultFiles(files.vault.old)).map((name) => ({
|
|
27722
|
+
old: join20(files.vault.old, name),
|
|
27723
|
+
next: join20(files.vault.next, name)
|
|
27724
|
+
}));
|
|
27725
|
+
}
|
|
27726
|
+
async function destinationFiles(files) {
|
|
27727
|
+
return (await vaultFiles(files.vault.next)).map(
|
|
27728
|
+
(name) => join20(files.vault.next, name)
|
|
27729
|
+
);
|
|
27730
|
+
}
|
|
27731
|
+
async function physicalAliases(location, files) {
|
|
27732
|
+
const pairs = [
|
|
27733
|
+
[location.configDir, location.stateHomeDir],
|
|
27734
|
+
[files.vault.old, files.vault.next]
|
|
27735
|
+
];
|
|
27736
|
+
for (const name of VAULT_FILE_NAMES)
|
|
27737
|
+
pairs.push([join20(files.vault.old, name), join20(files.vault.next, name)]);
|
|
27738
|
+
const aliased = [];
|
|
27739
|
+
for (const [old, next] of pairs)
|
|
27740
|
+
if (await samePhysical(old, next)) aliased.push(old);
|
|
27741
|
+
return aliased;
|
|
27742
|
+
}
|
|
27743
|
+
async function samePhysical(a, b) {
|
|
27744
|
+
const id = async (path2) => {
|
|
27745
|
+
try {
|
|
27746
|
+
const info = await stat12(path2, { bigint: true });
|
|
27747
|
+
return info.ino === 0n ? void 0 : `${info.dev}:${info.ino}`;
|
|
27748
|
+
} catch (error) {
|
|
27749
|
+
const code2 = error.code;
|
|
27750
|
+
if (code2 === "ENOENT" || code2 === "ENOTDIR") return void 0;
|
|
27751
|
+
throw error;
|
|
27752
|
+
}
|
|
27753
|
+
};
|
|
27754
|
+
const left = await id(a);
|
|
27755
|
+
return left !== void 0 && left === await id(b);
|
|
27756
|
+
}
|
|
27757
|
+
async function copyVerified(file) {
|
|
27758
|
+
const bytes = await readFile12(file.old);
|
|
27759
|
+
const text2 = bytes.toString("utf8");
|
|
27760
|
+
if (!Buffer.from(text2, "utf8").equals(bytes))
|
|
27761
|
+
throw new LayoutMoveError("not-utf8", `${file.old} is not UTF-8 text`);
|
|
27762
|
+
await writePrivateText(file.next, text2);
|
|
27763
|
+
if (!(await readFile12(file.next)).equals(bytes))
|
|
27764
|
+
throw new LayoutMoveError(
|
|
27765
|
+
"copy-mismatch",
|
|
27766
|
+
`${file.next} does not match ${file.old}`
|
|
27767
|
+
);
|
|
27768
|
+
}
|
|
27769
|
+
async function removeOldCopies(location, files, present2, layoutLock, input) {
|
|
27770
|
+
const kept = [];
|
|
27771
|
+
const keptState = vaultStateFile(files).old;
|
|
27772
|
+
const ordered = [
|
|
27773
|
+
...present2.filter((file) => file.old !== keptState),
|
|
27774
|
+
...present2.filter((file) => file.old === keptState)
|
|
27775
|
+
];
|
|
27776
|
+
for (const file of ordered) {
|
|
27777
|
+
await layoutLock.assertOwned();
|
|
27778
|
+
if (file.old === keptState) {
|
|
27779
|
+
if (await isVaultShapedKeptState(files)) {
|
|
27780
|
+
if (!await readable(file.next))
|
|
27781
|
+
throw credentialConflict(location.stateHomeDir, file);
|
|
27782
|
+
continue;
|
|
27783
|
+
}
|
|
27784
|
+
if (kept.length > 0) continue;
|
|
27785
|
+
if (input.keptVaultState && await sameBytes(file.old, file.next))
|
|
27786
|
+
continue;
|
|
27787
|
+
}
|
|
27788
|
+
if (!await unlinkIfIdentical(
|
|
27789
|
+
file,
|
|
27790
|
+
location.stateHomeDir,
|
|
27791
|
+
() => beforeRemove(file.old, layoutLock, input.steps)
|
|
27792
|
+
))
|
|
27793
|
+
kept.push(file.old);
|
|
27794
|
+
}
|
|
27795
|
+
const [first] = kept;
|
|
27796
|
+
if (first !== void 0) throw new OldVaultFileKeptError(first);
|
|
27797
|
+
}
|
|
27798
|
+
async function readable(path2) {
|
|
27799
|
+
try {
|
|
27800
|
+
await readFile12(path2);
|
|
27801
|
+
return true;
|
|
27802
|
+
} catch {
|
|
27803
|
+
return false;
|
|
27804
|
+
}
|
|
27805
|
+
}
|
|
27806
|
+
async function sameBytes(a, b) {
|
|
27807
|
+
try {
|
|
27808
|
+
return (await readFile12(a)).equals(await readFile12(b));
|
|
27809
|
+
} catch {
|
|
27810
|
+
return false;
|
|
27811
|
+
}
|
|
27812
|
+
}
|
|
27813
|
+
function isWindowsSharingError(error) {
|
|
27814
|
+
const code2 = error?.code;
|
|
27815
|
+
return process.platform === "win32" && (code2 === "EBUSY" || code2 === "EPERM" || code2 === "EACCES");
|
|
27816
|
+
}
|
|
27817
|
+
async function unlinkIfIdentical(file, stateDir, guard) {
|
|
27818
|
+
const started = performance.now();
|
|
27819
|
+
for (const delay3 of SHARING_RETRY_DELAYS_MS) {
|
|
27820
|
+
if (delay3 > 0) await new Promise((done) => setTimeout(done, delay3));
|
|
27821
|
+
let same;
|
|
27822
|
+
try {
|
|
27823
|
+
same = (await readFile12(file.old)).equals(await readFile12(file.next));
|
|
27824
|
+
} catch (error) {
|
|
27825
|
+
if (error.code === "ENOENT" && !await exists2(file.old))
|
|
27826
|
+
return true;
|
|
27827
|
+
if (isWindowsSharingError(error)) {
|
|
27828
|
+
if (performance.now() - started >= SHARING_RETRY_BUDGET_MS) return false;
|
|
27829
|
+
continue;
|
|
27830
|
+
}
|
|
27831
|
+
throw credentialConflict(stateDir, file);
|
|
27832
|
+
}
|
|
27833
|
+
if (!same) throw credentialConflict(stateDir, file);
|
|
27834
|
+
await guard();
|
|
27835
|
+
try {
|
|
27836
|
+
await unlink11(file.old);
|
|
27837
|
+
return true;
|
|
27838
|
+
} catch (error) {
|
|
27839
|
+
if (error.code === "ENOENT") return true;
|
|
27840
|
+
if (!isWindowsSharingError(error) || performance.now() - started >= SHARING_RETRY_BUDGET_MS)
|
|
27841
|
+
return false;
|
|
27842
|
+
}
|
|
27843
|
+
}
|
|
27844
|
+
return false;
|
|
27845
|
+
}
|
|
27846
|
+
async function refuseReappearedFiles(location, files) {
|
|
27847
|
+
const keptState = vaultStateFile(files).old;
|
|
27848
|
+
for (const name of await vaultFiles(files.vault.old)) {
|
|
27849
|
+
const old = join20(files.vault.old, name);
|
|
27850
|
+
if (old === keptState && await isVaultShapedKeptState(files)) continue;
|
|
27851
|
+
throw credentialConflict(location.stateHomeDir, {
|
|
27852
|
+
old,
|
|
27853
|
+
next: join20(files.vault.next, name)
|
|
27854
|
+
});
|
|
27855
|
+
}
|
|
27856
|
+
}
|
|
27857
|
+
async function readMarker(path2, stateDir, oldVaultDir) {
|
|
27858
|
+
let text2;
|
|
27859
|
+
let failure;
|
|
27860
|
+
for (let attempt = 0; attempt < MARKER_READ_ATTEMPTS; attempt++) {
|
|
27861
|
+
if (attempt > 0)
|
|
27862
|
+
await new Promise((done) => setTimeout(done, MARKER_READ_RETRY_MS));
|
|
27863
|
+
try {
|
|
27864
|
+
text2 = await readFile12(path2, "utf8");
|
|
27865
|
+
break;
|
|
27866
|
+
} catch (error) {
|
|
27867
|
+
const code2 = error.code;
|
|
27868
|
+
if (code2 === "ENOENT" || code2 === "ENOTDIR") return void 0;
|
|
27869
|
+
failure = error;
|
|
27870
|
+
}
|
|
27871
|
+
}
|
|
27872
|
+
if (text2 === void 0)
|
|
27873
|
+
throw new RuntimeLayoutRefusal(stateDir, errorClass(failure));
|
|
27874
|
+
try {
|
|
27875
|
+
const value = JSON.parse(text2);
|
|
27876
|
+
if (value && typeof value === "object" && !Array.isArray(value))
|
|
27877
|
+
return {
|
|
27878
|
+
version: 1,
|
|
27879
|
+
...typeof value.oldDir === "string" ? { oldDir: value.oldDir } : {},
|
|
27880
|
+
...value.oldFilesRemoved === true ? { oldFilesRemoved: true } : {},
|
|
27881
|
+
...typeof value.keptVaultState === "string" && SHA256_HEX2.test(value.keptVaultState) ? { keptVaultState: value.keptVaultState } : {}
|
|
27882
|
+
};
|
|
27883
|
+
} catch {
|
|
27884
|
+
}
|
|
27885
|
+
throw new RuntimeLayoutRefusal(
|
|
27886
|
+
stateDir,
|
|
27887
|
+
"malformed-marker",
|
|
27888
|
+
`antigravity-auth cannot start: ${path2} is malformed, so it cannot tell whether its vault files were moved. ${markerRemedy(path2, oldVaultDir)}`
|
|
27889
|
+
);
|
|
27890
|
+
}
|
|
27891
|
+
async function assertOwnFolder(location, marker, files) {
|
|
27892
|
+
const stateDir = location.stateHomeDir;
|
|
27893
|
+
if (marker?.oldDir !== void 0 && marker.oldDir !== location.key)
|
|
27894
|
+
throw foreignMarker(
|
|
27895
|
+
join20(stateDir, RUNTIME_LAYOUT_MARKER_FILE),
|
|
27896
|
+
location.key,
|
|
27897
|
+
files.vault.old
|
|
27898
|
+
);
|
|
27899
|
+
let text2;
|
|
27900
|
+
try {
|
|
27901
|
+
text2 = await readFile12(join20(stateDir, RUNTIME_CONFIG_DIR_NOTE_FILE), "utf8");
|
|
27902
|
+
} catch (error) {
|
|
27903
|
+
const code2 = error.code;
|
|
27904
|
+
if (code2 === "ENOENT" || code2 === "ENOTDIR") return;
|
|
27905
|
+
throw new RuntimeLayoutRefusal(stateDir, errorClass(error));
|
|
27906
|
+
}
|
|
27907
|
+
let owner;
|
|
27908
|
+
try {
|
|
27909
|
+
owner = JSON.parse(text2)?.configDir;
|
|
27910
|
+
} catch {
|
|
27911
|
+
}
|
|
27912
|
+
if (owner !== location.key) throw foreignFolder(stateDir, location.key);
|
|
27913
|
+
}
|
|
27914
|
+
async function writeOwnerNote(location) {
|
|
27915
|
+
const path2 = join20(location.stateHomeDir, RUNTIME_CONFIG_DIR_NOTE_FILE);
|
|
27916
|
+
if (await exists2(path2)) return;
|
|
27917
|
+
await writePrivateText(
|
|
27918
|
+
path2,
|
|
27919
|
+
`${JSON.stringify({ version: 1, configDir: location.key }, null, 2)}
|
|
27920
|
+
`
|
|
27921
|
+
);
|
|
27922
|
+
}
|
|
27923
|
+
async function readManifest(stateDir) {
|
|
27924
|
+
let text2;
|
|
27925
|
+
try {
|
|
27926
|
+
text2 = await readFile12(join20(stateDir, RUNTIME_LAYOUT_MANIFEST_FILE), "utf8");
|
|
27927
|
+
} catch (error) {
|
|
27928
|
+
if (error.code === "ENOENT") return /* @__PURE__ */ new Set();
|
|
27929
|
+
throw error;
|
|
27930
|
+
}
|
|
27931
|
+
try {
|
|
27932
|
+
const value = JSON.parse(text2);
|
|
27933
|
+
if (Array.isArray(value?.files))
|
|
27934
|
+
return new Set(
|
|
27935
|
+
value.files.filter((path2) => typeof path2 === "string")
|
|
27936
|
+
);
|
|
27937
|
+
} catch {
|
|
27938
|
+
}
|
|
27939
|
+
return /* @__PURE__ */ new Set();
|
|
27940
|
+
}
|
|
27941
|
+
async function writeManifest(stateDir, paths) {
|
|
27942
|
+
await writePrivateText(
|
|
27943
|
+
join20(stateDir, RUNTIME_LAYOUT_MANIFEST_FILE),
|
|
27944
|
+
`${JSON.stringify({ version: 1, files: paths }, null, 2)}
|
|
27945
|
+
`
|
|
27946
|
+
);
|
|
27947
|
+
}
|
|
27948
|
+
async function removeManifest(stateDir) {
|
|
27949
|
+
await unlink11(join20(stateDir, RUNTIME_LAYOUT_MANIFEST_FILE)).catch(
|
|
27950
|
+
(error) => {
|
|
27951
|
+
if (error.code !== "ENOENT") throw error;
|
|
27952
|
+
}
|
|
27953
|
+
);
|
|
27954
|
+
}
|
|
27955
|
+
async function writeMarker(path2, marker) {
|
|
27956
|
+
await writePrivateText(path2, `${JSON.stringify(marker, null, 2)}
|
|
27957
|
+
`);
|
|
27958
|
+
}
|
|
27959
|
+
async function writePrivateText(path2, text2) {
|
|
27960
|
+
await ensureOwnerOnlyDir(dirname20(path2));
|
|
27961
|
+
const fs2 = await loadCommonAuthFs();
|
|
27962
|
+
await fs2.writeJsonAtomic(path2, null, {
|
|
27963
|
+
serialize: () => text2,
|
|
27964
|
+
durable: true,
|
|
27965
|
+
durability: "file-only-on-windows"
|
|
27966
|
+
});
|
|
27967
|
+
}
|
|
27968
|
+
async function ensureOwnerOnlyDir(path2) {
|
|
27969
|
+
if (process.platform === "win32") return;
|
|
27970
|
+
await mkdir15(path2, { recursive: true, mode: 448 });
|
|
27971
|
+
await chmod5(path2, 448);
|
|
27972
|
+
}
|
|
27973
|
+
async function takeLock(name, path2, waitMs, log8) {
|
|
27974
|
+
const fs2 = await loadCommonAuthFs();
|
|
27975
|
+
const started = performance.now();
|
|
27976
|
+
let announced = false;
|
|
27977
|
+
for (; ; ) {
|
|
27978
|
+
let lock = null;
|
|
27979
|
+
try {
|
|
27980
|
+
lock = await fs2.acquireRefreshFileLock({
|
|
27981
|
+
name,
|
|
27982
|
+
path: path2,
|
|
27983
|
+
ttlMs: LOCK_TTL_MS,
|
|
27984
|
+
renew: true
|
|
27985
|
+
});
|
|
27986
|
+
} catch (error) {
|
|
27987
|
+
if (error.code !== "ENOENT") throw error;
|
|
27988
|
+
}
|
|
27989
|
+
if (lock) return lock;
|
|
27990
|
+
const waited = performance.now() - started;
|
|
27991
|
+
if (waited >= waitMs)
|
|
27992
|
+
throw new LayoutMoveError(
|
|
27993
|
+
"lock-timeout",
|
|
27994
|
+
`it waited ${Math.round(waitMs / 1e3)} s for the ${name} lock at ${path2}.${lockHolderText(name)}`
|
|
27995
|
+
);
|
|
27996
|
+
if (!announced && waited >= LOCK_WAIT_NOTICE_MS) {
|
|
27997
|
+
announced = true;
|
|
27998
|
+
log8.info(
|
|
27999
|
+
`antigravity-auth is waiting up to ${Math.round(waitMs / 1e3)} s for the ${name} lock at ${path2}.${lockHolderText(name)}`,
|
|
28000
|
+
{ lock: name, path: path2 }
|
|
28001
|
+
);
|
|
28002
|
+
}
|
|
28003
|
+
await new Promise((done) => setTimeout(done, LOCK_RETRY_MS));
|
|
28004
|
+
}
|
|
28005
|
+
}
|
|
28006
|
+
function lockHolderText(name) {
|
|
28007
|
+
return name === RUNTIME_LAYOUT_LOCK_NAME ? " Another OpenCode holds it while it decides where the vault files live or moves them; a lock left by one that crashed expires by itself." : " Another OpenCode holds it while it writes that vault file; a lock left by one that crashed expires by itself.";
|
|
28008
|
+
}
|
|
28009
|
+
async function exists2(path2) {
|
|
28010
|
+
try {
|
|
28011
|
+
await stat12(path2);
|
|
28012
|
+
return true;
|
|
28013
|
+
} catch (error) {
|
|
28014
|
+
const code2 = error.code;
|
|
28015
|
+
if (code2 === "ENOENT" || code2 === "ENOTDIR") return false;
|
|
28016
|
+
throw error;
|
|
28017
|
+
}
|
|
28018
|
+
}
|
|
28019
|
+
|
|
26785
28020
|
// src/plugin/vault-custody.ts
|
|
26786
|
-
import { dirname as dirname18, join as join18 } from "node:path";
|
|
26787
28021
|
var OPENCODE_VAULT_PROVIDER = "google";
|
|
26788
28022
|
var OPENCODE_VAULT_HOST = "opencode";
|
|
26789
28023
|
var OPENCODE_VAULT_ENROLLMENT_NAME = getAntigravityVaultEnrollmentName(OPENCODE_VAULT_HOST);
|
|
26790
|
-
var OPENCODE_VAULT_DIR_NAME = "antigravity-auth-vault";
|
|
26791
|
-
function openCodeVaultPaths(accountFile) {
|
|
26792
|
-
const dir = join18(dirname18(accountFile), OPENCODE_VAULT_DIR_NAME);
|
|
26793
|
-
return {
|
|
26794
|
-
dir,
|
|
26795
|
-
modeFile: join18(dir, "opencode-mode.json"),
|
|
26796
|
-
rosterFile: join18(dir, "opencode-roster.json"),
|
|
26797
|
-
stateFile: join18(dir, "opencode-state.json")
|
|
26798
|
-
};
|
|
26799
|
-
}
|
|
26800
28024
|
var LOCAL_MODE = Object.freeze({
|
|
26801
28025
|
version: 1,
|
|
26802
28026
|
mode: "local"
|
|
@@ -26806,10 +28030,64 @@ var CUSTODY_MODE = Object.freeze({
|
|
|
26806
28030
|
mode: "custody"
|
|
26807
28031
|
});
|
|
26808
28032
|
|
|
28033
|
+
// src/vault-folder.ts
|
|
28034
|
+
var refusalsKey = /* @__PURE__ */ Symbol.for(
|
|
28035
|
+
"@cortexkit/antigravity-auth/vault-folder-refusals"
|
|
28036
|
+
);
|
|
28037
|
+
var globalState3 = globalThis;
|
|
28038
|
+
var refusals = globalState3[refusalsKey] ?? /* @__PURE__ */ new Map();
|
|
28039
|
+
globalState3[refusalsKey] = refusals;
|
|
28040
|
+
function locationKey() {
|
|
28041
|
+
const location = runtimeLayoutLocation();
|
|
28042
|
+
return `${location.stateHomeDir}\0${location.key}`;
|
|
28043
|
+
}
|
|
28044
|
+
async function prepareVaultFolder(options) {
|
|
28045
|
+
const { accountFile } = options;
|
|
28046
|
+
const key = locationKey();
|
|
28047
|
+
const kept = refusals.get(key);
|
|
28048
|
+
if (kept) return refused(accountFile, kept);
|
|
28049
|
+
const log8 = options.log ?? createLogger4("runtime-layout");
|
|
28050
|
+
const version = options.version ?? await pluginPackageVersion().catch(() => "unknown");
|
|
28051
|
+
try {
|
|
28052
|
+
await prepareRuntimeLayout({
|
|
28053
|
+
version,
|
|
28054
|
+
accountFile,
|
|
28055
|
+
log: log8,
|
|
28056
|
+
...options.layoutLockWaitMs === void 0 ? {} : { layoutLockWaitMs: options.layoutLockWaitMs }
|
|
28057
|
+
});
|
|
28058
|
+
} catch (error) {
|
|
28059
|
+
const refusal3 = error instanceof RuntimeLayoutRefusal ? error : new RuntimeLayoutRefusal(
|
|
28060
|
+
runtimeLayoutLocation().stateHomeDir,
|
|
28061
|
+
error instanceof Error ? error.name : typeof error
|
|
28062
|
+
);
|
|
28063
|
+
if (!refusals.has(key)) {
|
|
28064
|
+
refusals.set(key, refusal3);
|
|
28065
|
+
log8.warn(refusal3.message, {
|
|
28066
|
+
stateDir: refusal3.stateDir,
|
|
28067
|
+
errorClass: refusal3.errorClass
|
|
28068
|
+
});
|
|
28069
|
+
}
|
|
28070
|
+
return refused(accountFile, refusals.get(key) ?? refusal3);
|
|
28071
|
+
}
|
|
28072
|
+
return { accountFile, vaultDir: getVaultDir(accountFile) };
|
|
28073
|
+
}
|
|
28074
|
+
function currentVaultFolder(accountFile) {
|
|
28075
|
+
const kept = refusals.get(locationKey());
|
|
28076
|
+
return kept ? refused(accountFile, kept) : { accountFile, vaultDir: getVaultDir(accountFile) };
|
|
28077
|
+
}
|
|
28078
|
+
function refused(accountFile, refusal3) {
|
|
28079
|
+
return { accountFile, vaultDir: getVaultDir(accountFile), refusal: refusal3 };
|
|
28080
|
+
}
|
|
28081
|
+
|
|
26809
28082
|
// src/setup.ts
|
|
26810
28083
|
var PI_PLACEHOLDER_KEY = "antigravity-vault-custody";
|
|
28084
|
+
function openCodeVaultDir(accountFile) {
|
|
28085
|
+
const folder = currentVaultFolder(accountFile);
|
|
28086
|
+
if (folder.refusal) throw folder.refusal;
|
|
28087
|
+
return folder.vaultDir;
|
|
28088
|
+
}
|
|
26811
28089
|
function nativeAuthPath(host, context) {
|
|
26812
|
-
return host === "opencode" ? nativeOpenCodeAuthPath() :
|
|
28090
|
+
return host === "opencode" ? nativeOpenCodeAuthPath() : join21(context.piAgentDir, "auth.json");
|
|
26813
28091
|
}
|
|
26814
28092
|
function provider(host) {
|
|
26815
28093
|
return host === "opencode" ? OPENCODE_VAULT_PROVIDER : ANTIGRAVITY_PROVIDER_ID;
|
|
@@ -26822,7 +28100,7 @@ async function readNativeAuth(path2) {
|
|
|
26822
28100
|
const info = await lstat7(path2);
|
|
26823
28101
|
if (!info.isFile() || info.nlink !== 1)
|
|
26824
28102
|
throw new Error("Native auth must be a regular, unaliased file.");
|
|
26825
|
-
const value = JSON.parse(await
|
|
28103
|
+
const value = JSON.parse(await readFile13(path2, "utf8"));
|
|
26826
28104
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
26827
28105
|
throw new Error("Native auth is invalid; refusing to replace it.");
|
|
26828
28106
|
return value;
|
|
@@ -26835,7 +28113,7 @@ async function assertLocalOpenCodeLogin(legacyPath, generation) {
|
|
|
26835
28113
|
const claustrum = await loadCommonAuthClaustrum();
|
|
26836
28114
|
if (await claustrum.enrollmentAuthority(
|
|
26837
28115
|
claustrum.hostEnrollmentPaths({
|
|
26838
|
-
stateDir:
|
|
28116
|
+
stateDir: openCodeVaultDir(legacyPath),
|
|
26839
28117
|
host: "opencode"
|
|
26840
28118
|
}),
|
|
26841
28119
|
OPENCODE_VAULT_ENROLLMENT_NAME
|
|
@@ -26865,7 +28143,7 @@ async function writeNativeSlot(host, slot, context, expectedAuthority = "local")
|
|
|
26865
28143
|
beforeRename: async () => {
|
|
26866
28144
|
await assertSetupHostsStopped();
|
|
26867
28145
|
const claustrum = await loadCommonAuthClaustrum();
|
|
26868
|
-
const stateDir = host === "opencode" ?
|
|
28146
|
+
const stateDir = host === "opencode" ? openCodeVaultDir(resolve18(getStoragePath())) : getPiAntigravityVaultDir();
|
|
26869
28147
|
if (await claustrum.enrollmentAuthority(
|
|
26870
28148
|
claustrum.hostEnrollmentPaths({ stateDir, host }),
|
|
26871
28149
|
`antigravity-auth-${host}`
|
|
@@ -26895,12 +28173,18 @@ async function persistPiSetupLogin(result, context) {
|
|
|
26895
28173
|
}
|
|
26896
28174
|
async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
26897
28175
|
const claustrum = await loadCommonAuthClaustrum();
|
|
26898
|
-
const opencode = openCodeVaultPaths(resolve16(getStoragePath()));
|
|
26899
28176
|
const piDir = getPiAntigravityVaultDir();
|
|
26900
28177
|
const hosts = {
|
|
26901
28178
|
opencode: {
|
|
26902
28179
|
name: OPENCODE_VAULT_ENROLLMENT_NAME,
|
|
26903
|
-
|
|
28180
|
+
// Read at each use: a real run settles the vault folder in
|
|
28181
|
+
// `beforeSignIn`, which may move it after this plugin is built.
|
|
28182
|
+
paths: {
|
|
28183
|
+
get stateDir() {
|
|
28184
|
+
return openCodeVaultDir(resolve18(getStoragePath()));
|
|
28185
|
+
},
|
|
28186
|
+
host: "opencode"
|
|
28187
|
+
}
|
|
26904
28188
|
},
|
|
26905
28189
|
pi: {
|
|
26906
28190
|
name: "antigravity-auth-pi",
|
|
@@ -26914,7 +28198,7 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
26914
28198
|
const assertLocal = async (host, context) => {
|
|
26915
28199
|
if (host === "opencode")
|
|
26916
28200
|
return assertLocalOpenCodeLogin(
|
|
26917
|
-
|
|
28201
|
+
resolve18(getStoragePath()),
|
|
26918
28202
|
context.opencodeGeneration
|
|
26919
28203
|
);
|
|
26920
28204
|
if (await authority(host) !== "local")
|
|
@@ -26930,7 +28214,7 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
26930
28214
|
const { openPiSlot: openPiSlot2 } = await loadCommonAuthPiSlot();
|
|
26931
28215
|
if ((await openPiSlot2({
|
|
26932
28216
|
authPath: nativeAuthPath(host, context),
|
|
26933
|
-
stashPath:
|
|
28217
|
+
stashPath: join21(piDir, "google-login-stash.json"),
|
|
26934
28218
|
provider: ANTIGRAVITY_PROVIDER_ID,
|
|
26935
28219
|
placeholderKey: PI_PLACEHOLDER_KEY
|
|
26936
28220
|
}).inspect()).slot === "placeholder")
|
|
@@ -26941,7 +28225,7 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
26941
28225
|
};
|
|
26942
28226
|
let openCodeLogin;
|
|
26943
28227
|
const manifest = JSON.parse(
|
|
26944
|
-
await
|
|
28228
|
+
await readFile13(new URL("../package.json", import.meta.url), "utf8")
|
|
26945
28229
|
);
|
|
26946
28230
|
return {
|
|
26947
28231
|
packages: {
|
|
@@ -26954,6 +28238,7 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
26954
28238
|
vault: { connectionFile: await resolveClaustrumConnectionPath(), hosts },
|
|
26955
28239
|
beforeSignIn: async (_host, context) => {
|
|
26956
28240
|
await assertSetupHostsStopped();
|
|
28241
|
+
if (context.hosts.includes("opencode")) await deps.prepareVaultFolder?.();
|
|
26957
28242
|
await deps.processHeartbeat?.();
|
|
26958
28243
|
for (const selected of context.hosts) {
|
|
26959
28244
|
if (context.mode === "local") {
|
|
@@ -26968,7 +28253,7 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
26968
28253
|
const { openPiSlot: openPiSlot2 } = await loadCommonAuthPiSlot();
|
|
26969
28254
|
const inspection = await openPiSlot2({
|
|
26970
28255
|
authPath: nativeAuthPath("pi", context),
|
|
26971
|
-
stashPath:
|
|
28256
|
+
stashPath: join21(piDir, "google-login-stash.json"),
|
|
26972
28257
|
provider: ANTIGRAVITY_PROVIDER_ID,
|
|
26973
28258
|
placeholderKey: PI_PLACEHOLDER_KEY
|
|
26974
28259
|
}).inspect();
|
|
@@ -27087,7 +28372,7 @@ Setup has not completed the OpenCode 2 native Google connection.
|
|
|
27087
28372
|
await assertSetupHostsStopped();
|
|
27088
28373
|
await openPiSlot2({
|
|
27089
28374
|
authPath: nativeAuthPath(host, context),
|
|
27090
|
-
stashPath:
|
|
28375
|
+
stashPath: join21(piDir, "google-login-stash.json"),
|
|
27091
28376
|
provider: ANTIGRAVITY_PROVIDER_ID,
|
|
27092
28377
|
placeholderKey: PI_PLACEHOLDER_KEY
|
|
27093
28378
|
}).enterVault();
|
|
@@ -27320,7 +28605,10 @@ async function runCli(argv, deps) {
|
|
|
27320
28605
|
return 0;
|
|
27321
28606
|
}
|
|
27322
28607
|
try {
|
|
27323
|
-
if (parsed.value.command !== "setup")
|
|
28608
|
+
if (parsed.value.command !== "setup") {
|
|
28609
|
+
if (parsed.value.command === "login") await deps.prepareVaultFolder?.();
|
|
28610
|
+
await deps.processHeartbeat?.();
|
|
28611
|
+
}
|
|
27324
28612
|
if (parsed.value.command === "setup") {
|
|
27325
28613
|
await runPluginSetup(
|
|
27326
28614
|
parsed.value.args,
|
|
@@ -27420,6 +28708,12 @@ async function runCliProcess(argv, deps) {
|
|
|
27420
28708
|
try {
|
|
27421
28709
|
return await runCli(argv, {
|
|
27422
28710
|
...deps,
|
|
28711
|
+
prepareVaultFolder: deps.prepareVaultFolder ?? (async () => {
|
|
28712
|
+
const folder = await prepareVaultFolder({
|
|
28713
|
+
accountFile: resolve19(getStoragePath())
|
|
28714
|
+
});
|
|
28715
|
+
if (folder.refusal) throw folder.refusal;
|
|
28716
|
+
}),
|
|
27423
28717
|
processHeartbeat: deps.processHeartbeat ?? (() => holdCliProcessHeartbeat(logger2))
|
|
27424
28718
|
});
|
|
27425
28719
|
} finally {
|
|
@@ -27459,7 +28753,7 @@ function createDefaultCliDependencies() {
|
|
|
27459
28753
|
throw new Error(
|
|
27460
28754
|
"Pi setup requires its detected native agent directory."
|
|
27461
28755
|
);
|
|
27462
|
-
const legacyPath =
|
|
28756
|
+
const legacyPath = resolve19(getStoragePath());
|
|
27463
28757
|
const repository = host === "pi" ? void 0 : await prepareCliLoginStore(legacyPath, context?.opencodeGeneration);
|
|
27464
28758
|
try {
|
|
27465
28759
|
return await performOAuthLogin(request, {
|
|
@@ -27619,7 +28913,7 @@ async function readAccountStore(legacyPath) {
|
|
|
27619
28913
|
function createDefaultAccountStoreOperations() {
|
|
27620
28914
|
const offline = { processesStopped: true };
|
|
27621
28915
|
return {
|
|
27622
|
-
legacyPath: () =>
|
|
28916
|
+
legacyPath: () => resolve19(getStoragePath()),
|
|
27623
28917
|
migrate: async (legacyPath) => createAccountMigrationFactory(await loadCommonAuthStoreModules())({
|
|
27624
28918
|
legacyPath,
|
|
27625
28919
|
offline,
|
|
@@ -27640,7 +28934,7 @@ function createDefaultAccountStoreOperations() {
|
|
|
27640
28934
|
function isCliEntry() {
|
|
27641
28935
|
if (import.meta.main !== void 0) return import.meta.main;
|
|
27642
28936
|
try {
|
|
27643
|
-
return !!process.argv[1] &&
|
|
28937
|
+
return !!process.argv[1] && realpathSync4(process.argv[1]) === fileURLToPath2(import.meta.url);
|
|
27644
28938
|
} catch {
|
|
27645
28939
|
return false;
|
|
27646
28940
|
}
|