@cortexkit/opencode-antigravity-auth 3.0.22 → 3.0.24
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 +321 -204
- package/dist/cli.js.map +4 -4
- package/dist/cli.meta.json +68 -43
- package/dist/index.js +547 -351
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +75 -50
- package/dist/server.js +690 -386
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/auth-method-labels.d.ts +1 -0
- package/dist/src/auth-method-labels.d.ts.map +1 -1
- package/dist/src/auth-method-labels.js +1 -0
- package/dist/src/auth-method-labels.js.map +1 -1
- package/dist/src/ga/server/auth.d.ts.map +1 -1
- package/dist/src/ga/server/auth.js +63 -21
- package/dist/src/ga/server/auth.js.map +1 -1
- package/dist/src/ga/server/pool-login.d.ts +4 -0
- package/dist/src/ga/server/pool-login.d.ts.map +1 -1
- package/dist/src/ga/server/pool-login.js +22 -1
- package/dist/src/ga/server/pool-login.js.map +1 -1
- package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/src/plugin/ga-location-services.js +42 -4
- package/dist/src/plugin/ga-location-services.js.map +1 -1
- package/dist/src/plugin/shared/request-services.d.ts +3 -0
- package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/src/plugin/shared/request-services.js +17 -3
- package/dist/src/plugin/shared/request-services.js.map +1 -1
- package/dist/src/plugin/shared/vault-routing.d.ts +6 -3
- package/dist/src/plugin/shared/vault-routing.d.ts.map +1 -1
- package/dist/src/plugin/shared/vault-routing.js +12 -12
- package/dist/src/plugin/shared/vault-routing.js.map +1 -1
- package/dist/src/runtime-layout.d.ts.map +1 -1
- package/dist/src/runtime-layout.js +14 -3
- package/dist/src/runtime-layout.js.map +1 -1
- package/dist/src/setup.d.ts.map +1 -1
- package/dist/src/setup.js +38 -4
- package/dist/src/setup.js.map +1 -1
- package/dist/src/vault-folder.d.ts.map +1 -1
- package/dist/src/vault-folder.js +51 -14
- package/dist/src/vault-folder.js.map +1 -1
- package/dist/src/version-fence.d.ts +5 -0
- package/dist/src/version-fence.d.ts.map +1 -1
- package/dist/src/version-fence.js +64 -7
- package/dist/src/version-fence.js.map +1 -1
- package/dist/types/src/auth-method-labels.d.ts +1 -0
- package/dist/types/src/auth-method-labels.d.ts.map +1 -1
- package/dist/types/src/ga/server/auth.d.ts.map +1 -1
- package/dist/types/src/ga/server/pool-login.d.ts +4 -0
- package/dist/types/src/ga/server/pool-login.d.ts.map +1 -1
- package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/request-services.d.ts +3 -0
- package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/vault-routing.d.ts +6 -3
- package/dist/types/src/plugin/shared/vault-routing.d.ts.map +1 -1
- package/dist/types/src/runtime-layout.d.ts.map +1 -1
- package/dist/types/src/setup.d.ts.map +1 -1
- package/dist/types/src/vault-folder.d.ts.map +1 -1
- package/dist/types/src/version-fence.d.ts +5 -0
- package/dist/types/src/version-fence.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -1626,10 +1626,10 @@ async function privateDirectory(path2) {
|
|
|
1626
1626
|
if (errno(error) !== "EEXIST")
|
|
1627
1627
|
throw error;
|
|
1628
1628
|
}
|
|
1629
|
-
const
|
|
1630
|
-
if (!
|
|
1629
|
+
const stat14 = await lstat2(path2);
|
|
1630
|
+
if (!stat14.isDirectory() || stat14.isSymbolicLink())
|
|
1631
1631
|
throw new AccountMigrationError("successor directory is not a regular directory");
|
|
1632
|
-
privateMode(
|
|
1632
|
+
privateMode(stat14.mode, 448);
|
|
1633
1633
|
if (windowsPrivateFiles)
|
|
1634
1634
|
await verifySafeDirectory(path2);
|
|
1635
1635
|
if (!sameFilesystemPath(await realpath(path2), path2))
|
|
@@ -6375,7 +6375,7 @@ function writeConsoleLog(level, ...args) {
|
|
|
6375
6375
|
}
|
|
6376
6376
|
function createLogger(module) {
|
|
6377
6377
|
const service = `antigravity.${module}`;
|
|
6378
|
-
const
|
|
6378
|
+
const log9 = (level, message, extra) => {
|
|
6379
6379
|
if (_sink) {
|
|
6380
6380
|
try {
|
|
6381
6381
|
_sink({ service, level, message, extra });
|
|
@@ -6389,10 +6389,10 @@ function createLogger(module) {
|
|
|
6389
6389
|
}
|
|
6390
6390
|
};
|
|
6391
6391
|
return {
|
|
6392
|
-
debug: (message, extra) =>
|
|
6393
|
-
info: (message, extra) =>
|
|
6394
|
-
warn: (message, extra) =>
|
|
6395
|
-
error: (message, extra) =>
|
|
6392
|
+
debug: (message, extra) => log9("debug", message, extra),
|
|
6393
|
+
info: (message, extra) => log9("info", message, extra),
|
|
6394
|
+
warn: (message, extra) => log9("warn", message, extra),
|
|
6395
|
+
error: (message, extra) => log9("error", message, extra)
|
|
6396
6396
|
};
|
|
6397
6397
|
}
|
|
6398
6398
|
var ENV_CONSOLE_LOG, _sink;
|
|
@@ -21423,13 +21423,13 @@ async function safeRead(path2, privateFile = false, afterReadCheck) {
|
|
|
21423
21423
|
let file;
|
|
21424
21424
|
try {
|
|
21425
21425
|
file = await open7(path2, constants2.O_RDONLY | constants2.O_NOFOLLOW);
|
|
21426
|
-
const
|
|
21427
|
-
if (!
|
|
21426
|
+
const stat14 = await file.stat();
|
|
21427
|
+
if (!stat14.isFile() || privateFile && (stat14.mode & 511) !== 384) {
|
|
21428
21428
|
throw new PiSlotError("unsafe-path");
|
|
21429
21429
|
}
|
|
21430
21430
|
await afterReadCheck?.(path2);
|
|
21431
21431
|
const current = await lstat5(path2);
|
|
21432
|
-
if (!current.isFile() || current.dev !==
|
|
21432
|
+
if (!current.isFile() || current.dev !== stat14.dev || current.ino !== stat14.ino) {
|
|
21433
21433
|
throw new PiSlotError("unsafe-path");
|
|
21434
21434
|
}
|
|
21435
21435
|
const bytes = await file.readFile();
|
|
@@ -23802,8 +23802,8 @@ var init_process_heartbeat = __esm({
|
|
|
23802
23802
|
});
|
|
23803
23803
|
|
|
23804
23804
|
// src/version-fence.ts
|
|
23805
|
-
import { readdir as readdir2, readFile as readFile9 } from "node:fs/promises";
|
|
23806
|
-
import { homedir as homedir3 } from "node:os";
|
|
23805
|
+
import { readdir as readdir2, readFile as readFile9, stat as stat8, unlink as unlink9 } from "node:fs/promises";
|
|
23806
|
+
import { homedir as homedir3, uptime } from "node:os";
|
|
23807
23807
|
import { join as join12 } from "node:path";
|
|
23808
23808
|
function defaultStateHome() {
|
|
23809
23809
|
return process.env.XDG_STATE_HOME || join12(homedir3(), ".local", "state");
|
|
@@ -23886,13 +23886,18 @@ async function readProcessRecord(path2, pid) {
|
|
|
23886
23886
|
return { kind: "gone" };
|
|
23887
23887
|
return { kind: "unreadable" };
|
|
23888
23888
|
}
|
|
23889
|
+
let startedAt;
|
|
23889
23890
|
try {
|
|
23890
23891
|
const value = JSON.parse(text2);
|
|
23892
|
+
if (isRecord9(value) && typeof value.startedAt === "number" && Number.isFinite(value.startedAt))
|
|
23893
|
+
startedAt = value.startedAt;
|
|
23891
23894
|
if (value !== null && typeof value === "object" && value.pid === pid && typeof value.version === "string") {
|
|
23892
23895
|
const layouts = value.layouts;
|
|
23893
23896
|
const stores = value.stores;
|
|
23894
23897
|
return {
|
|
23895
23898
|
kind: "ok",
|
|
23899
|
+
text: text2,
|
|
23900
|
+
startedAt,
|
|
23896
23901
|
version: value.version,
|
|
23897
23902
|
...isRecord9(layouts) ? { layouts } : {},
|
|
23898
23903
|
...isRecord9(stores) ? { stores } : {}
|
|
@@ -23900,14 +23905,45 @@ async function readProcessRecord(path2, pid) {
|
|
|
23900
23905
|
}
|
|
23901
23906
|
} catch {
|
|
23902
23907
|
}
|
|
23903
|
-
return { kind: "unreadable" };
|
|
23908
|
+
return { kind: "unreadable", text: text2, startedAt };
|
|
23904
23909
|
}
|
|
23905
23910
|
function isRecord9(value) {
|
|
23906
23911
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
23907
23912
|
}
|
|
23913
|
+
function bootTime(options) {
|
|
23914
|
+
try {
|
|
23915
|
+
return (options.now ?? Date.now)() - (options.uptimeSeconds ?? uptime)() * 1e3;
|
|
23916
|
+
} catch {
|
|
23917
|
+
return Number.NaN;
|
|
23918
|
+
}
|
|
23919
|
+
}
|
|
23920
|
+
async function staleRecord(path2, record3, boot, heartbeat) {
|
|
23921
|
+
if (record3.text === void 0 || !Number.isFinite(boot)) return false;
|
|
23922
|
+
let start = heartbeat ? record3.startedAt : void 0;
|
|
23923
|
+
if (start === void 0) {
|
|
23924
|
+
try {
|
|
23925
|
+
start = (await stat8(path2)).mtimeMs;
|
|
23926
|
+
} catch {
|
|
23927
|
+
return false;
|
|
23928
|
+
}
|
|
23929
|
+
}
|
|
23930
|
+
if (!Number.isFinite(start) || !(start < boot - BOOT_TIME_MARGIN_MS))
|
|
23931
|
+
return false;
|
|
23932
|
+
if (heartbeat) {
|
|
23933
|
+
try {
|
|
23934
|
+
if (await readFile9(path2, "utf8") === record3.text) {
|
|
23935
|
+
await unlink9(path2);
|
|
23936
|
+
log5.debug("Removed stale pre-boot heartbeat", { path: path2 });
|
|
23937
|
+
}
|
|
23938
|
+
} catch {
|
|
23939
|
+
}
|
|
23940
|
+
}
|
|
23941
|
+
return true;
|
|
23942
|
+
}
|
|
23908
23943
|
async function versionFenceOpen(options) {
|
|
23909
23944
|
const isAlive = options.isAlive ?? pidAlive;
|
|
23910
23945
|
const self = options.selfPid ?? process.pid;
|
|
23946
|
+
const boot = bootTime(options);
|
|
23911
23947
|
const blockers = /* @__PURE__ */ new Map();
|
|
23912
23948
|
const block = (entry) => {
|
|
23913
23949
|
const key = entry.pid === "unknown" ? `dir:${entry.detail}` : entry.pid;
|
|
@@ -23930,7 +23966,8 @@ async function versionFenceOpen(options) {
|
|
|
23930
23966
|
const path2 = join12(heartbeatDir, name);
|
|
23931
23967
|
const heartbeat = await readProcessRecord(path2, pid);
|
|
23932
23968
|
if (heartbeat.kind === "gone") continue;
|
|
23933
|
-
|
|
23969
|
+
const live = alive(pid);
|
|
23970
|
+
if (await staleRecord(path2, heartbeat, boot, true) || !live) continue;
|
|
23934
23971
|
if (heartbeat.kind === "unreadable") {
|
|
23935
23972
|
block({ pid, version: "unknown", detail: path2 });
|
|
23936
23973
|
continue;
|
|
@@ -23964,6 +24001,7 @@ async function versionFenceOpen(options) {
|
|
|
23964
24001
|
const path2 = join12(dir, name);
|
|
23965
24002
|
const port = await readProcessRecord(path2, pid);
|
|
23966
24003
|
if (port.kind === "gone") continue;
|
|
24004
|
+
if (await staleRecord(path2, port, boot, false)) continue;
|
|
23967
24005
|
const version = port.kind === "ok" ? port.version : "unknown";
|
|
23968
24006
|
const order = compareVersions(version, options.currentVersion);
|
|
23969
24007
|
if (order === void 0 || order < 0)
|
|
@@ -23976,9 +24014,109 @@ async function versionFenceOpen(options) {
|
|
|
23976
24014
|
blockers: [...blockers.values()].sort((a, b) => rank(a) - rank(b))
|
|
23977
24015
|
};
|
|
23978
24016
|
}
|
|
24017
|
+
var log5, BOOT_TIME_MARGIN_MS;
|
|
23979
24018
|
var init_version_fence = __esm({
|
|
23980
24019
|
"src/version-fence.ts"() {
|
|
23981
24020
|
"use strict";
|
|
24021
|
+
init_logger4();
|
|
24022
|
+
log5 = createLogger4("version-fence");
|
|
24023
|
+
BOOT_TIME_MARGIN_MS = 3e5;
|
|
24024
|
+
}
|
|
24025
|
+
});
|
|
24026
|
+
|
|
24027
|
+
// src/vault-folder.ts
|
|
24028
|
+
var vault_folder_exports = {};
|
|
24029
|
+
__export(vault_folder_exports, {
|
|
24030
|
+
__resetVaultFoldersForTest: () => __resetVaultFoldersForTest,
|
|
24031
|
+
currentVaultFolder: () => currentVaultFolder,
|
|
24032
|
+
prepareVaultFolder: () => prepareVaultFolder
|
|
24033
|
+
});
|
|
24034
|
+
import { isAbsolute as isAbsolute3 } from "node:path";
|
|
24035
|
+
function vaultOverride(accountFile) {
|
|
24036
|
+
const kept = refusals.get(overrideRefusalKey);
|
|
24037
|
+
if (kept) return { accountFile, vaultDir: kept.stateDir, refusal: kept };
|
|
24038
|
+
const vaultDir = process.env[OVERRIDE];
|
|
24039
|
+
if (!vaultDir) return void 0;
|
|
24040
|
+
if (isAbsolute3(vaultDir)) return { accountFile, vaultDir };
|
|
24041
|
+
const refusal3 = new RuntimeLayoutRefusal(
|
|
24042
|
+
vaultDir,
|
|
24043
|
+
"relative-vault-dir",
|
|
24044
|
+
`antigravity-auth cannot start: ${OVERRIDE} must be an absolute path. Correct it and restart OpenCode.`
|
|
24045
|
+
);
|
|
24046
|
+
refusals.set(overrideRefusalKey, refusal3);
|
|
24047
|
+
return { accountFile, vaultDir, refusal: refusal3 };
|
|
24048
|
+
}
|
|
24049
|
+
function locationKey() {
|
|
24050
|
+
const location = runtimeLayoutLocation();
|
|
24051
|
+
return `${location.stateHomeDir}\0${location.key}`;
|
|
24052
|
+
}
|
|
24053
|
+
function __resetVaultFoldersForTest() {
|
|
24054
|
+
refusals.clear();
|
|
24055
|
+
}
|
|
24056
|
+
async function prepareVaultFolder(options) {
|
|
24057
|
+
const { accountFile } = options;
|
|
24058
|
+
const override = vaultOverride(accountFile);
|
|
24059
|
+
if (override?.refusal) return override;
|
|
24060
|
+
const key = locationKey();
|
|
24061
|
+
const kept = refusals.get(key);
|
|
24062
|
+
if (kept)
|
|
24063
|
+
return override ? { ...override, refusal: kept } : refused(accountFile, kept);
|
|
24064
|
+
const log9 = options.log ?? createLogger4("runtime-layout");
|
|
24065
|
+
const version = options.version ?? await pluginPackageVersion().catch(() => "unknown");
|
|
24066
|
+
try {
|
|
24067
|
+
if (override) {
|
|
24068
|
+
await ensurePrivateDirectory2(override.vaultDir);
|
|
24069
|
+
} else
|
|
24070
|
+
await prepareRuntimeLayout({
|
|
24071
|
+
version,
|
|
24072
|
+
accountFile,
|
|
24073
|
+
log: log9,
|
|
24074
|
+
...options.layoutLockWaitMs === void 0 ? {} : { layoutLockWaitMs: options.layoutLockWaitMs }
|
|
24075
|
+
});
|
|
24076
|
+
if (options.accountStore !== false)
|
|
24077
|
+
await prepareAccountStore({ version, log: log9 });
|
|
24078
|
+
} catch (error) {
|
|
24079
|
+
const refusal3 = error instanceof RuntimeLayoutRefusal ? error : new RuntimeLayoutRefusal(
|
|
24080
|
+
override?.vaultDir ?? runtimeLayoutLocation().stateHomeDir,
|
|
24081
|
+
error instanceof Error ? error.name : typeof error
|
|
24082
|
+
);
|
|
24083
|
+
if (!refusals.has(key)) {
|
|
24084
|
+
refusals.set(key, refusal3);
|
|
24085
|
+
log9.warn(refusal3.message, {
|
|
24086
|
+
stateDir: refusal3.stateDir,
|
|
24087
|
+
errorClass: refusal3.errorClass
|
|
24088
|
+
});
|
|
24089
|
+
}
|
|
24090
|
+
return override ? { ...override, refusal: refusals.get(key) ?? refusal3 } : refused(accountFile, refusals.get(key) ?? refusal3);
|
|
24091
|
+
}
|
|
24092
|
+
return override ?? { accountFile, vaultDir: getVaultDir(accountFile) };
|
|
24093
|
+
}
|
|
24094
|
+
function currentVaultFolder(accountFile) {
|
|
24095
|
+
const override = vaultOverride(accountFile);
|
|
24096
|
+
if (override?.refusal) return override;
|
|
24097
|
+
const kept = refusals.get(locationKey());
|
|
24098
|
+
return kept ? override ? { ...override, refusal: kept } : refused(accountFile, kept) : override ?? { accountFile, vaultDir: getVaultDir(accountFile) };
|
|
24099
|
+
}
|
|
24100
|
+
function refused(accountFile, refusal3) {
|
|
24101
|
+
return { accountFile, vaultDir: getVaultDir(accountFile), refusal: refusal3 };
|
|
24102
|
+
}
|
|
24103
|
+
var refusalsKey, globalState2, refusals, OVERRIDE, overrideRefusalKey;
|
|
24104
|
+
var init_vault_folder = __esm({
|
|
24105
|
+
"src/vault-folder.ts"() {
|
|
24106
|
+
"use strict";
|
|
24107
|
+
init_private_files2();
|
|
24108
|
+
init_logger4();
|
|
24109
|
+
init_process_heartbeat();
|
|
24110
|
+
init_runtime_layout();
|
|
24111
|
+
init_runtime_paths();
|
|
24112
|
+
refusalsKey = /* @__PURE__ */ Symbol.for(
|
|
24113
|
+
"@cortexkit/antigravity-auth/vault-folder-refusals"
|
|
24114
|
+
);
|
|
24115
|
+
globalState2 = globalThis;
|
|
24116
|
+
refusals = globalState2[refusalsKey] ?? /* @__PURE__ */ new Map();
|
|
24117
|
+
globalState2[refusalsKey] = refusals;
|
|
24118
|
+
OVERRIDE = "OPENCODE_ANTIGRAVITY_AUTH_VAULT_DIR";
|
|
24119
|
+
overrideRefusalKey = "invalid-vault-dir-override";
|
|
23982
24120
|
}
|
|
23983
24121
|
});
|
|
23984
24122
|
|
|
@@ -24009,8 +24147,8 @@ import {
|
|
|
24009
24147
|
readFile as readFile10,
|
|
24010
24148
|
rename as rename10,
|
|
24011
24149
|
rmdir as rmdir2,
|
|
24012
|
-
stat as
|
|
24013
|
-
unlink as
|
|
24150
|
+
stat as stat9,
|
|
24151
|
+
unlink as unlink10
|
|
24014
24152
|
} from "node:fs/promises";
|
|
24015
24153
|
import { basename as basename4, dirname as dirname15, join as join13, resolve as resolve15 } from "node:path";
|
|
24016
24154
|
function refusalMessage(stateDir, errorClass2) {
|
|
@@ -24065,10 +24203,10 @@ function errorFile(error) {
|
|
|
24065
24203
|
...typeof stage === "string" && stage ? { stage } : {}
|
|
24066
24204
|
};
|
|
24067
24205
|
}
|
|
24068
|
-
function logCleanupFailure(location,
|
|
24206
|
+
function logCleanupFailure(location, log9, step, error) {
|
|
24069
24207
|
logOnce(
|
|
24070
24208
|
`${location.key}\0cleanup`,
|
|
24071
|
-
() =>
|
|
24209
|
+
() => log9.warn(
|
|
24072
24210
|
"antigravity-auth could not finish removing its old vault files from OpenCode's config folder; it tries again at the next start",
|
|
24073
24211
|
{
|
|
24074
24212
|
configDir: location.configDir,
|
|
@@ -24097,13 +24235,13 @@ function prepareRuntimeLayout(options) {
|
|
|
24097
24235
|
return run;
|
|
24098
24236
|
}
|
|
24099
24237
|
async function decide(location, options) {
|
|
24100
|
-
const
|
|
24238
|
+
const log9 = options.log ?? createLogger4("runtime-layout");
|
|
24101
24239
|
const stateDir = location.stateHomeDir;
|
|
24102
24240
|
const markerPath = join13(stateDir, RUNTIME_LAYOUT_MARKER_FILE);
|
|
24103
24241
|
const files = layoutFiles(location, options.accountFile);
|
|
24104
24242
|
const fence = options.fence ?? defaultFence(options.version);
|
|
24105
24243
|
const stateHome = async () => {
|
|
24106
|
-
await settleVault(location, options, "state-home",
|
|
24244
|
+
await settleVault(location, options, "state-home", log9);
|
|
24107
24245
|
return "state-home";
|
|
24108
24246
|
};
|
|
24109
24247
|
let marker = await readMarker(markerPath, stateDir, files.vault.old);
|
|
@@ -24114,7 +24252,7 @@ async function decide(location, options) {
|
|
|
24114
24252
|
join13(stateDir, RUNTIME_LAYOUT_MANIFEST_FILE)
|
|
24115
24253
|
).catch(() => true);
|
|
24116
24254
|
if (!manifestLeft) {
|
|
24117
|
-
await settleVault(location, options, "state-home",
|
|
24255
|
+
await settleVault(location, options, "state-home", log9);
|
|
24118
24256
|
return stateHome();
|
|
24119
24257
|
}
|
|
24120
24258
|
}
|
|
@@ -24126,7 +24264,7 @@ async function decide(location, options) {
|
|
|
24126
24264
|
RUNTIME_LAYOUT_LOCK_NAME,
|
|
24127
24265
|
markerPath,
|
|
24128
24266
|
options.layoutLockWaitMs ?? LAYOUT_LOCK_WAIT_MS,
|
|
24129
|
-
|
|
24267
|
+
log9
|
|
24130
24268
|
);
|
|
24131
24269
|
} catch (error) {
|
|
24132
24270
|
marker = await readMarker(markerPath, stateDir, files.vault.old);
|
|
@@ -24146,7 +24284,7 @@ async function decide(location, options) {
|
|
|
24146
24284
|
const legacy = async () => {
|
|
24147
24285
|
try {
|
|
24148
24286
|
await lock.assertOwned();
|
|
24149
|
-
await settleVault(location, options, "legacy",
|
|
24287
|
+
await settleVault(location, options, "legacy", log9);
|
|
24150
24288
|
} catch (error) {
|
|
24151
24289
|
throw new RuntimeLayoutRefusal(stateDir, errorClass(error));
|
|
24152
24290
|
}
|
|
@@ -24160,20 +24298,20 @@ async function decide(location, options) {
|
|
|
24160
24298
|
if (!marker.oldFilesRemoved && !aliased)
|
|
24161
24299
|
await finishOldFiles(location, files, markerPath, marker, lock, {
|
|
24162
24300
|
fence,
|
|
24163
|
-
log:
|
|
24301
|
+
log: log9,
|
|
24164
24302
|
steps: options.steps,
|
|
24165
24303
|
oldSignatureCache: options.oldSignatureCacheFile ?? legacySignatureCacheFile()
|
|
24166
24304
|
});
|
|
24167
24305
|
else if (marker.oldFilesRemoved) {
|
|
24168
24306
|
await refuseReappearedFiles(location, files);
|
|
24169
|
-
await removeLeftoverManifest(location, lock, options.steps,
|
|
24307
|
+
await removeLeftoverManifest(location, lock, options.steps, log9);
|
|
24170
24308
|
}
|
|
24171
24309
|
return await stateHome();
|
|
24172
24310
|
}
|
|
24173
24311
|
if (aliased) {
|
|
24174
24312
|
logOnce(
|
|
24175
24313
|
`${location.key}\0aliased`,
|
|
24176
|
-
() =>
|
|
24314
|
+
() => log9.warn(
|
|
24177
24315
|
"antigravity-auth keeps its vault files in OpenCode's config folder: its state folder is that same folder",
|
|
24178
24316
|
{ configDir: location.configDir, stateDir }
|
|
24179
24317
|
)
|
|
@@ -24182,14 +24320,14 @@ async function decide(location, options) {
|
|
|
24182
24320
|
}
|
|
24183
24321
|
const gate = await fence();
|
|
24184
24322
|
if (!gate.open) {
|
|
24185
|
-
logDeferral(location, gate.blockers,
|
|
24323
|
+
logDeferral(location, gate.blockers, log9);
|
|
24186
24324
|
return await legacy();
|
|
24187
24325
|
}
|
|
24188
24326
|
let markerStarted = false;
|
|
24189
24327
|
try {
|
|
24190
24328
|
const outcome = await moveFiles(location, files, markerPath, lock, {
|
|
24191
24329
|
fence,
|
|
24192
|
-
log:
|
|
24330
|
+
log: log9,
|
|
24193
24331
|
steps: options.steps,
|
|
24194
24332
|
destinationPrivate: options.destinationPrivate ?? defaultDestinationPrivate,
|
|
24195
24333
|
oldSignatureCache: options.oldSignatureCacheFile ?? legacySignatureCacheFile(),
|
|
@@ -24198,13 +24336,13 @@ async function decide(location, options) {
|
|
|
24198
24336
|
}
|
|
24199
24337
|
});
|
|
24200
24338
|
if (outcome.kind === "deferred") {
|
|
24201
|
-
logDeferral(location, outcome.blockers,
|
|
24339
|
+
logDeferral(location, outcome.blockers, log9);
|
|
24202
24340
|
return await legacy();
|
|
24203
24341
|
}
|
|
24204
24342
|
if (outcome.kind === "refused") {
|
|
24205
24343
|
logOnce(
|
|
24206
24344
|
`${location.key}\0refused`,
|
|
24207
|
-
() =>
|
|
24345
|
+
() => log9.warn(
|
|
24208
24346
|
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",
|
|
24209
24347
|
{ reason: outcome.reason, paths: outcome.paths, stateDir }
|
|
24210
24348
|
)
|
|
@@ -24212,7 +24350,7 @@ async function decide(location, options) {
|
|
|
24212
24350
|
return await legacy();
|
|
24213
24351
|
}
|
|
24214
24352
|
if (outcome.moved)
|
|
24215
|
-
|
|
24353
|
+
log9.info(
|
|
24216
24354
|
"antigravity-auth moved its vault files out of OpenCode's config folder",
|
|
24217
24355
|
{ from: files.vault.old, to: files.vault.next }
|
|
24218
24356
|
);
|
|
@@ -24223,7 +24361,7 @@ async function decide(location, options) {
|
|
|
24223
24361
|
return await stateHome();
|
|
24224
24362
|
logOnce(
|
|
24225
24363
|
`${location.key}\0failed`,
|
|
24226
|
-
() =>
|
|
24364
|
+
() => log9.warn(
|
|
24227
24365
|
"antigravity-auth's vault files stay in OpenCode's config folder: moving them failed; the move is tried again at the next start",
|
|
24228
24366
|
{
|
|
24229
24367
|
configDir: location.configDir,
|
|
@@ -24252,8 +24390,12 @@ async function settleVault(location, options, layout, _log) {
|
|
|
24252
24390
|
}
|
|
24253
24391
|
async function localAccountStoreAuthorized() {
|
|
24254
24392
|
const location = runtimeLayoutLocation();
|
|
24393
|
+
const folder = process.env.OPENCODE_ANTIGRAVITY_AUTH_VAULT_DIR ? (await Promise.resolve().then(() => (init_vault_folder(), vault_folder_exports))).currentVaultFolder(
|
|
24394
|
+
accountFileForVault(location.configDir)
|
|
24395
|
+
) : void 0;
|
|
24396
|
+
if (folder?.refusal) return false;
|
|
24255
24397
|
const claustrum = await loadCommonAuthClaustrum();
|
|
24256
|
-
const vaultDir = decidedRuntimeLayout(location) === "state-home" ? stateHomeVaultDir(location) : legacyVaultDir(accountFileForVault(location.configDir));
|
|
24398
|
+
const vaultDir = folder ? folder.vaultDir : decidedRuntimeLayout(location) === "state-home" ? stateHomeVaultDir(location) : legacyVaultDir(accountFileForVault(location.configDir));
|
|
24257
24399
|
return await enrollmentAuthority2(
|
|
24258
24400
|
claustrum.hostEnrollmentPaths({
|
|
24259
24401
|
stateDir: vaultDir,
|
|
@@ -24268,7 +24410,7 @@ async function prepareAccountStore(options) {
|
|
|
24268
24410
|
if (!await localAccountStoreAuthorized()) return void 0;
|
|
24269
24411
|
const decided = decidedAccountStoreAnchor(location);
|
|
24270
24412
|
if (decided) return decided;
|
|
24271
|
-
const
|
|
24413
|
+
const log9 = options.log ?? createLogger4("runtime-layout");
|
|
24272
24414
|
const runKey = `${location.stateHomeDir}\0${location.key}`;
|
|
24273
24415
|
let run = processState.storeRuns.get(runKey);
|
|
24274
24416
|
if (!run) {
|
|
@@ -24279,12 +24421,12 @@ async function prepareAccountStore(options) {
|
|
|
24279
24421
|
RUNTIME_LAYOUT_LOCK_NAME,
|
|
24280
24422
|
join13(location.stateHomeDir, RUNTIME_LAYOUT_MARKER_FILE),
|
|
24281
24423
|
options.layoutLockWaitMs ?? LAYOUT_LOCK_WAIT_MS,
|
|
24282
|
-
|
|
24424
|
+
log9
|
|
24283
24425
|
);
|
|
24284
24426
|
try {
|
|
24285
24427
|
await lock.assertOwned();
|
|
24286
24428
|
if (!await localAccountStoreAuthorized()) return void 0;
|
|
24287
|
-
return await settleAccountStore(location, options,
|
|
24429
|
+
return await settleAccountStore(location, options, log9);
|
|
24288
24430
|
} finally {
|
|
24289
24431
|
await lock.release();
|
|
24290
24432
|
}
|
|
@@ -24295,20 +24437,20 @@ async function prepareAccountStore(options) {
|
|
|
24295
24437
|
}
|
|
24296
24438
|
return run;
|
|
24297
24439
|
}
|
|
24298
|
-
async function settleAccountStore(location, options,
|
|
24440
|
+
async function settleAccountStore(location, options, log9) {
|
|
24299
24441
|
const decided = decidedAccountStoreAnchor(location);
|
|
24300
24442
|
if (decided) return decided;
|
|
24301
|
-
const anchor = await decideAccountStore(location, options,
|
|
24443
|
+
const anchor = await decideAccountStore(location, options, log9);
|
|
24302
24444
|
setAccountStoreAnchor(location, anchor);
|
|
24303
24445
|
return anchor;
|
|
24304
24446
|
}
|
|
24305
|
-
async function decideAccountStore(location, options,
|
|
24306
|
-
const keepConfig = () => recordAnchor(location, options, "config",
|
|
24447
|
+
async function decideAccountStore(location, options, log9) {
|
|
24448
|
+
const keepConfig = () => recordAnchor(location, options, "config", log9);
|
|
24307
24449
|
if (processHasOlderGeneration()) {
|
|
24308
24450
|
logOnce(
|
|
24309
24451
|
"older-generation-account-store",
|
|
24310
24452
|
() => showLog(
|
|
24311
|
-
|
|
24453
|
+
log9,
|
|
24312
24454
|
"antigravity-auth keeps the account store in OpenCode's config folder until OpenCode restarts, because an older version of the plugin ran in this process.",
|
|
24313
24455
|
{ accountStore: "config" }
|
|
24314
24456
|
)
|
|
@@ -24322,7 +24464,7 @@ async function decideAccountStore(location, options, log8) {
|
|
|
24322
24464
|
if (!sameSpelling(forward.legacyPath, stateAnchor)) {
|
|
24323
24465
|
logOnce(
|
|
24324
24466
|
`${location.key}\0store-forward-elsewhere`,
|
|
24325
|
-
() =>
|
|
24467
|
+
() => log9.warn(
|
|
24326
24468
|
"the account store moved to another folder than this process resolved; check XDG_STATE_HOME",
|
|
24327
24469
|
{ movedTo: forward.legacyPath, expected: stateAnchor }
|
|
24328
24470
|
)
|
|
@@ -24333,9 +24475,9 @@ async function decideAccountStore(location, options, log8) {
|
|
|
24333
24475
|
options,
|
|
24334
24476
|
configAnchor,
|
|
24335
24477
|
stateAnchor,
|
|
24336
|
-
|
|
24478
|
+
log9
|
|
24337
24479
|
);
|
|
24338
|
-
return recordAnchor(location, options, "state-home",
|
|
24480
|
+
return recordAnchor(location, options, "state-home", log9);
|
|
24339
24481
|
}
|
|
24340
24482
|
if (decidedRuntimeLayout(location) === "legacy") return keepConfig();
|
|
24341
24483
|
const configStore = await presentAccountStore(configAnchor);
|
|
@@ -24347,9 +24489,9 @@ async function decideAccountStore(location, options, log8) {
|
|
|
24347
24489
|
`antigravity-auth cannot start: two account stores exist, one at ${configAnchor} and one at ${stateAnchor}, and neither is marked as moved. Keep the one you want and move the other one aside, then restart OpenCode.`
|
|
24348
24490
|
);
|
|
24349
24491
|
}
|
|
24350
|
-
if (stateStore) return recordAnchor(location, options, "state-home",
|
|
24492
|
+
if (stateStore) return recordAnchor(location, options, "state-home", log9);
|
|
24351
24493
|
if (configStore) {
|
|
24352
|
-
if (!await storeMovePathResolves(stateAnchor, location,
|
|
24494
|
+
if (!await storeMovePathResolves(stateAnchor, location, log9))
|
|
24353
24495
|
return keepConfig();
|
|
24354
24496
|
return moveStore(
|
|
24355
24497
|
location,
|
|
@@ -24357,21 +24499,21 @@ async function decideAccountStore(location, options, log8) {
|
|
|
24357
24499
|
configAnchor,
|
|
24358
24500
|
stateAnchor,
|
|
24359
24501
|
false,
|
|
24360
|
-
|
|
24502
|
+
log9,
|
|
24361
24503
|
false
|
|
24362
24504
|
);
|
|
24363
24505
|
}
|
|
24364
|
-
if (await storeArtefacts(stateAnchor) > 0 && !await abandonUnpublishedStore(location, stateAnchor,
|
|
24506
|
+
if (await storeArtefacts(stateAnchor) > 0 && !await abandonUnpublishedStore(location, stateAnchor, log9))
|
|
24365
24507
|
return keepConfig();
|
|
24366
|
-
if (!await storeMovePathResolves(stateAnchor, location,
|
|
24508
|
+
if (!await storeMovePathResolves(stateAnchor, location, log9))
|
|
24367
24509
|
return keepConfig();
|
|
24368
|
-
return initializeStore(location, options, stateAnchor,
|
|
24510
|
+
return initializeStore(location, options, stateAnchor, log9);
|
|
24369
24511
|
}
|
|
24370
|
-
function showLog(
|
|
24371
|
-
if (
|
|
24372
|
-
else
|
|
24512
|
+
function showLog(log9, message, meta) {
|
|
24513
|
+
if (log9.log) log9.log(message, meta);
|
|
24514
|
+
else log9.info(message, meta);
|
|
24373
24515
|
}
|
|
24374
|
-
async function recordAnchor(location, options, anchor,
|
|
24516
|
+
async function recordAnchor(location, options, anchor, log9) {
|
|
24375
24517
|
try {
|
|
24376
24518
|
await recordProcessAnchor({
|
|
24377
24519
|
key: location.key,
|
|
@@ -24383,32 +24525,32 @@ async function recordAnchor(location, options, anchor, log8) {
|
|
|
24383
24525
|
}
|
|
24384
24526
|
if (anchor === "state-home")
|
|
24385
24527
|
showLog(
|
|
24386
|
-
|
|
24528
|
+
log9,
|
|
24387
24529
|
"antigravity-auth keeps its account store in its state folder",
|
|
24388
24530
|
{ accountStore: anchor }
|
|
24389
24531
|
);
|
|
24390
24532
|
return anchor;
|
|
24391
24533
|
}
|
|
24392
|
-
async function storeMovePathResolves(stateAnchor, location,
|
|
24534
|
+
async function storeMovePathResolves(stateAnchor, location, log9) {
|
|
24393
24535
|
if (folderResolvesToItself(
|
|
24394
24536
|
join13(location.stateHomeDir, "antigravity-accounts.json")
|
|
24395
24537
|
))
|
|
24396
24538
|
return true;
|
|
24397
24539
|
logOnce(
|
|
24398
24540
|
`${location.key}\0store-linked-path`,
|
|
24399
|
-
() =>
|
|
24541
|
+
() => log9.warn(ACCOUNT_STORE_LINKED_PATH_MESSAGE, {
|
|
24400
24542
|
accountStore: stateAnchor,
|
|
24401
24543
|
stateFolder: location.stateHomeDir
|
|
24402
24544
|
})
|
|
24403
24545
|
);
|
|
24404
24546
|
return false;
|
|
24405
24547
|
}
|
|
24406
|
-
async function storeFenceOpen(location, options,
|
|
24548
|
+
async function storeFenceOpen(location, options, log9) {
|
|
24407
24549
|
const gate = await (options.storeFence ?? defaultStoreFence(options.version))();
|
|
24408
24550
|
if (gate.open) return true;
|
|
24409
24551
|
logOnce(
|
|
24410
24552
|
`${location.key}\0store-version-fence`,
|
|
24411
|
-
() =>
|
|
24553
|
+
() => log9.info(ACCOUNT_STORE_DEFERRED_MESSAGE, {
|
|
24412
24554
|
configDir: location.configDir,
|
|
24413
24555
|
blockers: gate.blockers
|
|
24414
24556
|
})
|
|
@@ -24435,7 +24577,7 @@ async function storeArtefacts(anchor) {
|
|
|
24435
24577
|
(name) => name === store || name.startsWith(`${pool}.store.`) || name.startsWith(pool) && name.endsWith(".tmp")
|
|
24436
24578
|
).length;
|
|
24437
24579
|
}
|
|
24438
|
-
async function abandonUnpublishedStore(location, stateAnchor,
|
|
24580
|
+
async function abandonUnpublishedStore(location, stateAnchor, log9) {
|
|
24439
24581
|
const store = await loadCommonAuthStoreModules();
|
|
24440
24582
|
const binding = await readAccountStoreBinding(stateAnchor, store, Date.now);
|
|
24441
24583
|
if (binding.status === "bound") return false;
|
|
@@ -24444,9 +24586,9 @@ async function abandonUnpublishedStore(location, stateAnchor, log8) {
|
|
|
24444
24586
|
await rename10(folder, archived).catch((error) => {
|
|
24445
24587
|
if (error.code !== "ENOENT") throw error;
|
|
24446
24588
|
});
|
|
24447
|
-
await
|
|
24589
|
+
await unlink10(accountStorePointerPath(stateAnchor)).catch(() => {
|
|
24448
24590
|
});
|
|
24449
|
-
|
|
24591
|
+
log9.info(
|
|
24450
24592
|
"antigravity-auth set an unfinished account store aside before starting its move again",
|
|
24451
24593
|
{ configDir: location.configDir, archived }
|
|
24452
24594
|
);
|
|
@@ -24468,9 +24610,9 @@ async function runStoreMove(input) {
|
|
|
24468
24610
|
return { status: "pending", reason: outcome.reason };
|
|
24469
24611
|
return { status: "cancelled" };
|
|
24470
24612
|
}
|
|
24471
|
-
async function moveStore(location, options, source, target, back,
|
|
24472
|
-
const keepConfig = () => recordAnchor(location, options, "config",
|
|
24473
|
-
if (!await storeFenceOpen(location, options,
|
|
24613
|
+
async function moveStore(location, options, source, target, back, log9, forwarded) {
|
|
24614
|
+
const keepConfig = () => recordAnchor(location, options, "config", log9);
|
|
24615
|
+
if (!await storeFenceOpen(location, options, log9)) return keepConfig();
|
|
24474
24616
|
try {
|
|
24475
24617
|
const result = await (options.relocate ?? runStoreMove)({
|
|
24476
24618
|
source,
|
|
@@ -24480,7 +24622,7 @@ async function moveStore(location, options, source, target, back, log8, forwarde
|
|
|
24480
24622
|
if (result.status !== "completed") {
|
|
24481
24623
|
logOnce(
|
|
24482
24624
|
`${location.key}\0store-move-unfinished`,
|
|
24483
|
-
() =>
|
|
24625
|
+
() => log9.info(ACCOUNT_STORE_DEFERRED_MESSAGE, {
|
|
24484
24626
|
configDir: location.configDir,
|
|
24485
24627
|
reason: result.status === "pending" ? result.reason : result.status
|
|
24486
24628
|
})
|
|
@@ -24488,14 +24630,14 @@ async function moveStore(location, options, source, target, back, log8, forwarde
|
|
|
24488
24630
|
return forwarded ? "state-home" : keepConfig();
|
|
24489
24631
|
}
|
|
24490
24632
|
showLog(
|
|
24491
|
-
|
|
24633
|
+
log9,
|
|
24492
24634
|
"antigravity-auth moved the account store out of OpenCode's config folder",
|
|
24493
24635
|
{ from: source, to: target, generation: result.id }
|
|
24494
24636
|
);
|
|
24495
24637
|
} catch (error) {
|
|
24496
24638
|
logOnce(
|
|
24497
24639
|
`${location.key}\0store-move-failed`,
|
|
24498
|
-
() =>
|
|
24640
|
+
() => log9.warn(
|
|
24499
24641
|
"antigravity-auth's account store stays in OpenCode's config folder: moving it failed; the move is tried again at the next start",
|
|
24500
24642
|
{
|
|
24501
24643
|
configDir: location.configDir,
|
|
@@ -24506,9 +24648,9 @@ async function moveStore(location, options, source, target, back, log8, forwarde
|
|
|
24506
24648
|
);
|
|
24507
24649
|
return forwarded ? "state-home" : keepConfig();
|
|
24508
24650
|
}
|
|
24509
|
-
return recordAnchor(location, options, "state-home",
|
|
24651
|
+
return recordAnchor(location, options, "state-home", log9);
|
|
24510
24652
|
}
|
|
24511
|
-
async function resumeForwardedStore(location, options, configAnchor, stateAnchor,
|
|
24653
|
+
async function resumeForwardedStore(location, options, configAnchor, stateAnchor, log9) {
|
|
24512
24654
|
const store = await loadCommonAuthStoreModules();
|
|
24513
24655
|
const binding = await readAccountStoreBinding(stateAnchor, store, Date.now);
|
|
24514
24656
|
if (binding.status === "bound") return;
|
|
@@ -24519,13 +24661,13 @@ async function resumeForwardedStore(location, options, configAnchor, stateAnchor
|
|
|
24519
24661
|
configAnchor,
|
|
24520
24662
|
stateAnchor,
|
|
24521
24663
|
false,
|
|
24522
|
-
|
|
24664
|
+
log9,
|
|
24523
24665
|
true
|
|
24524
24666
|
);
|
|
24525
24667
|
} catch (error) {
|
|
24526
24668
|
logOnce(
|
|
24527
24669
|
`${location.key}\0store-resume-failed`,
|
|
24528
|
-
() =>
|
|
24670
|
+
() => log9.warn(
|
|
24529
24671
|
"antigravity-auth's account store is still moving; it could not be finished at this start",
|
|
24530
24672
|
{
|
|
24531
24673
|
configDir: location.configDir,
|
|
@@ -24536,9 +24678,9 @@ async function resumeForwardedStore(location, options, configAnchor, stateAnchor
|
|
|
24536
24678
|
);
|
|
24537
24679
|
}
|
|
24538
24680
|
}
|
|
24539
|
-
async function initializeStore(location, options, stateAnchor,
|
|
24540
|
-
const keepConfig = () => recordAnchor(location, options, "config",
|
|
24541
|
-
if (!await storeFenceOpen(location, options,
|
|
24681
|
+
async function initializeStore(location, options, stateAnchor, log9) {
|
|
24682
|
+
const keepConfig = () => recordAnchor(location, options, "config", log9);
|
|
24683
|
+
if (!await storeFenceOpen(location, options, log9)) return keepConfig();
|
|
24542
24684
|
try {
|
|
24543
24685
|
const store = await loadCommonAuthStoreModules();
|
|
24544
24686
|
const created = await initializeFreshAccountStore(store, {
|
|
@@ -24551,7 +24693,7 @@ async function initializeStore(location, options, stateAnchor, log8) {
|
|
|
24551
24693
|
} catch (error) {
|
|
24552
24694
|
logOnce(
|
|
24553
24695
|
`${location.key}\0store-init-failed`,
|
|
24554
|
-
() =>
|
|
24696
|
+
() => log9.warn(
|
|
24555
24697
|
"antigravity-auth's account store stays in OpenCode's config folder: creating it in its state folder failed; it is tried again at the next start",
|
|
24556
24698
|
{
|
|
24557
24699
|
configDir: location.configDir,
|
|
@@ -24563,13 +24705,13 @@ async function initializeStore(location, options, stateAnchor, log8) {
|
|
|
24563
24705
|
return keepConfig();
|
|
24564
24706
|
}
|
|
24565
24707
|
showLog(
|
|
24566
|
-
|
|
24708
|
+
log9,
|
|
24567
24709
|
"antigravity-auth created its account store in its state folder",
|
|
24568
24710
|
{
|
|
24569
24711
|
accountStore: stateAnchor
|
|
24570
24712
|
}
|
|
24571
24713
|
);
|
|
24572
|
-
return recordAnchor(location, options, "state-home",
|
|
24714
|
+
return recordAnchor(location, options, "state-home", log9);
|
|
24573
24715
|
}
|
|
24574
24716
|
async function writeStateHomeStoreForward(id, stateAnchor, configAnchor = legacyAccountFile(runtimeLayoutLocation().configDir)) {
|
|
24575
24717
|
const forward = {
|
|
@@ -24584,10 +24726,10 @@ async function writeStateHomeStoreForward(id, stateAnchor, configAnchor = legacy
|
|
|
24584
24726
|
durability: "file-only-on-windows"
|
|
24585
24727
|
});
|
|
24586
24728
|
}
|
|
24587
|
-
function logDeferral(location, blockers,
|
|
24729
|
+
function logDeferral(location, blockers, log9) {
|
|
24588
24730
|
logOnce(
|
|
24589
24731
|
`${location.key}\0deferred`,
|
|
24590
|
-
() =>
|
|
24732
|
+
() => log9.info(RUNTIME_LAYOUT_DEFERRED_MESSAGE, {
|
|
24591
24733
|
configDir: location.configDir,
|
|
24592
24734
|
blockers
|
|
24593
24735
|
})
|
|
@@ -24636,7 +24778,7 @@ async function moveFiles(location, files, markerPath, layoutLock, input) {
|
|
|
24636
24778
|
for (const path2 of listed) {
|
|
24637
24779
|
if (wanted.has(path2)) continue;
|
|
24638
24780
|
await layoutLock.assertOwned();
|
|
24639
|
-
await
|
|
24781
|
+
await unlink10(path2).catch((error) => {
|
|
24640
24782
|
if (error.code !== "ENOENT") throw error;
|
|
24641
24783
|
});
|
|
24642
24784
|
}
|
|
@@ -24745,13 +24887,13 @@ async function finishOldFiles(location, files, markerPath, marker, layoutLock, i
|
|
|
24745
24887
|
if (done) await removeOldVaultFolder(files, layoutLock, input.steps);
|
|
24746
24888
|
}
|
|
24747
24889
|
}
|
|
24748
|
-
async function removeLeftoverManifest(location, layoutLock, steps,
|
|
24890
|
+
async function removeLeftoverManifest(location, layoutLock, steps, log9) {
|
|
24749
24891
|
try {
|
|
24750
24892
|
await removeManifestOwned(location.stateHomeDir, layoutLock, steps);
|
|
24751
24893
|
} catch (error) {
|
|
24752
24894
|
logOnce(
|
|
24753
24895
|
`${location.key}\0manifest`,
|
|
24754
|
-
() =>
|
|
24896
|
+
() => log9.warn(
|
|
24755
24897
|
`antigravity-auth could not remove ${RUNTIME_LAYOUT_MANIFEST_FILE} from its state folder; it tries again at the next start`,
|
|
24756
24898
|
{ stateDir: location.stateHomeDir, errorClass: errorClass(error) }
|
|
24757
24899
|
)
|
|
@@ -24771,16 +24913,16 @@ async function removeOldVaultFolder(files, layoutLock, steps) {
|
|
|
24771
24913
|
} catch {
|
|
24772
24914
|
}
|
|
24773
24915
|
}
|
|
24774
|
-
async function removeOldSignatureCache(location, path2, layoutLock, steps,
|
|
24916
|
+
async function removeOldSignatureCache(location, path2, layoutLock, steps, log9) {
|
|
24775
24917
|
try {
|
|
24776
24918
|
if (!await exists2(path2)) return;
|
|
24777
24919
|
await beforeRemove(path2, layoutLock, steps);
|
|
24778
|
-
await
|
|
24920
|
+
await unlink10(path2);
|
|
24779
24921
|
} catch (error) {
|
|
24780
24922
|
if (error?.code === "ENOENT") return;
|
|
24781
24923
|
logOnce(
|
|
24782
24924
|
`${location.key}\0signature-cache`,
|
|
24783
|
-
() =>
|
|
24925
|
+
() => log9.warn(
|
|
24784
24926
|
"antigravity-auth could not remove its old signature cache from OpenCode's config folder; it is no longer used and can be deleted",
|
|
24785
24927
|
{ path: path2, errorClass: errorClass(error) }
|
|
24786
24928
|
)
|
|
@@ -24791,7 +24933,7 @@ async function beforeRemove(path2, layoutLock, steps) {
|
|
|
24791
24933
|
await steps?.beforeRemove?.(path2);
|
|
24792
24934
|
await layoutLock.assertOwned();
|
|
24793
24935
|
}
|
|
24794
|
-
async function takeDataLocks(files,
|
|
24936
|
+
async function takeDataLocks(files, log9) {
|
|
24795
24937
|
const locks = [];
|
|
24796
24938
|
try {
|
|
24797
24939
|
if (await exists2(files.vault.old))
|
|
@@ -24801,7 +24943,7 @@ async function takeDataLocks(files, log8) {
|
|
|
24801
24943
|
lock.name,
|
|
24802
24944
|
join13(files.vault.old, lock.file),
|
|
24803
24945
|
lock.waitMs,
|
|
24804
|
-
|
|
24946
|
+
log9
|
|
24805
24947
|
)
|
|
24806
24948
|
);
|
|
24807
24949
|
return locks;
|
|
@@ -24865,6 +25007,7 @@ async function isVaultShapedKeptState(files) {
|
|
|
24865
25007
|
return vaultShape && proposedName === OPENCODE_VAULT_ENROLLMENT_NAME;
|
|
24866
25008
|
}
|
|
24867
25009
|
async function removeMovedVaultStateLeftover(vaultDir, accountFile) {
|
|
25010
|
+
if (process.env.OPENCODE_ANTIGRAVITY_AUTH_VAULT_DIR) return;
|
|
24868
25011
|
const location = runtimeLayoutLocation();
|
|
24869
25012
|
const files = layoutFiles(location, accountFile);
|
|
24870
25013
|
if (resolve15(vaultDir) !== resolve15(files.vault.next)) return;
|
|
@@ -24877,7 +25020,7 @@ async function removeMovedVaultStateLeftover(vaultDir, accountFile) {
|
|
|
24877
25020
|
if (!marker?.oldDir || marker.oldDir !== location.key) return;
|
|
24878
25021
|
const leftover = vaultStateFile(files).old;
|
|
24879
25022
|
if (!await isVaultShapedKeptState(files)) return;
|
|
24880
|
-
await
|
|
25023
|
+
await unlink10(leftover).catch((error) => {
|
|
24881
25024
|
if (error.code !== "ENOENT") throw error;
|
|
24882
25025
|
});
|
|
24883
25026
|
await rmdir2(files.vault.old).catch(() => {
|
|
@@ -24923,7 +25066,7 @@ async function physicalAliases(location, files) {
|
|
|
24923
25066
|
async function samePhysical(a, b) {
|
|
24924
25067
|
const id = async (path2) => {
|
|
24925
25068
|
try {
|
|
24926
|
-
const info = await
|
|
25069
|
+
const info = await stat9(path2, { bigint: true });
|
|
24927
25070
|
return info.ino === 0n ? void 0 : `${info.dev}:${info.ino}`;
|
|
24928
25071
|
} catch (error) {
|
|
24929
25072
|
const code2 = error.code;
|
|
@@ -25013,7 +25156,7 @@ async function unlinkIfIdentical(file, stateDir, guard) {
|
|
|
25013
25156
|
if (!same) throw credentialConflict(stateDir, file);
|
|
25014
25157
|
await guard();
|
|
25015
25158
|
try {
|
|
25016
|
-
await
|
|
25159
|
+
await unlink10(file.old);
|
|
25017
25160
|
return true;
|
|
25018
25161
|
} catch (error) {
|
|
25019
25162
|
if (error.code === "ENOENT") return true;
|
|
@@ -25126,7 +25269,7 @@ async function writeManifest(stateDir, paths) {
|
|
|
25126
25269
|
);
|
|
25127
25270
|
}
|
|
25128
25271
|
async function removeManifest(stateDir) {
|
|
25129
|
-
await
|
|
25272
|
+
await unlink10(join13(stateDir, RUNTIME_LAYOUT_MANIFEST_FILE)).catch(
|
|
25130
25273
|
(error) => {
|
|
25131
25274
|
if (error.code !== "ENOENT") throw error;
|
|
25132
25275
|
}
|
|
@@ -25150,7 +25293,7 @@ async function ensureOwnerOnlyDir(path2) {
|
|
|
25150
25293
|
await mkdir12(path2, { recursive: true, mode: 448 });
|
|
25151
25294
|
await chmod4(path2, 448);
|
|
25152
25295
|
}
|
|
25153
|
-
async function takeLock(name, path2, waitMs,
|
|
25296
|
+
async function takeLock(name, path2, waitMs, log9) {
|
|
25154
25297
|
const fs3 = await loadCommonAuthFs();
|
|
25155
25298
|
const started = performance.now();
|
|
25156
25299
|
let announced = false;
|
|
@@ -25175,7 +25318,7 @@ async function takeLock(name, path2, waitMs, log8) {
|
|
|
25175
25318
|
);
|
|
25176
25319
|
if (!announced && waited >= LOCK_WAIT_NOTICE_MS) {
|
|
25177
25320
|
announced = true;
|
|
25178
|
-
|
|
25321
|
+
log9.info(
|
|
25179
25322
|
`antigravity-auth is waiting up to ${Math.round(waitMs / 1e3)} s for the ${name} lock at ${path2}.${lockHolderText(name)}`,
|
|
25180
25323
|
{ lock: name, path: path2 }
|
|
25181
25324
|
);
|
|
@@ -25188,7 +25331,7 @@ function lockHolderText(name) {
|
|
|
25188
25331
|
}
|
|
25189
25332
|
async function exists2(path2) {
|
|
25190
25333
|
try {
|
|
25191
|
-
await
|
|
25334
|
+
await stat9(path2);
|
|
25192
25335
|
return true;
|
|
25193
25336
|
} catch (error) {
|
|
25194
25337
|
const code2 = error.code;
|
|
@@ -25196,7 +25339,7 @@ async function exists2(path2) {
|
|
|
25196
25339
|
throw error;
|
|
25197
25340
|
}
|
|
25198
25341
|
}
|
|
25199
|
-
var RUNTIME_LAYOUT_LOCK_NAME, RUNTIME_LAYOUT_MANIFEST_FILE, VAULT_ENROLLMENT_STATE_FILE, VAULT_ENROLLMENT_TOKEN_FILE, VAULT_FILE_NAMES, LOCK_TTL_MS, DATA_LOCKS, LAYOUT_LOCK_WAIT_MS, LOCK_RETRY_MS, LOCK_WAIT_NOTICE_MS, MARKER_READ_ATTEMPTS, MARKER_READ_RETRY_MS, SHARING_RETRY_DELAYS_MS, SHARING_RETRY_BUDGET_MS, RUNTIME_LAYOUT_DEFERRED_MESSAGE, ACCOUNT_STORE_DEFERRED_MESSAGE, ACCOUNT_STORE_LINKED_PATH_MESSAGE, RuntimeLayoutRefusal, stateKey2,
|
|
25342
|
+
var RUNTIME_LAYOUT_LOCK_NAME, RUNTIME_LAYOUT_MANIFEST_FILE, VAULT_ENROLLMENT_STATE_FILE, VAULT_ENROLLMENT_TOKEN_FILE, VAULT_FILE_NAMES, LOCK_TTL_MS, DATA_LOCKS, LAYOUT_LOCK_WAIT_MS, LOCK_RETRY_MS, LOCK_WAIT_NOTICE_MS, MARKER_READ_ATTEMPTS, MARKER_READ_RETRY_MS, SHARING_RETRY_DELAYS_MS, SHARING_RETRY_BUDGET_MS, RUNTIME_LAYOUT_DEFERRED_MESSAGE, ACCOUNT_STORE_DEFERRED_MESSAGE, ACCOUNT_STORE_LINKED_PATH_MESSAGE, RuntimeLayoutRefusal, stateKey2, globalState3, processState, LayoutMoveError, OldVaultFileKeptError, SHA256_HEX2;
|
|
25200
25343
|
var init_runtime_layout = __esm({
|
|
25201
25344
|
"src/runtime-layout.ts"() {
|
|
25202
25345
|
"use strict";
|
|
@@ -25253,8 +25396,8 @@ var init_runtime_layout = __esm({
|
|
|
25253
25396
|
errorClass;
|
|
25254
25397
|
};
|
|
25255
25398
|
stateKey2 = /* @__PURE__ */ Symbol.for("@cortexkit/antigravity-auth/runtime-layout-runs");
|
|
25256
|
-
|
|
25257
|
-
processState =
|
|
25399
|
+
globalState3 = globalThis;
|
|
25400
|
+
processState = globalState3[stateKey2] ?? {
|
|
25258
25401
|
runs: /* @__PURE__ */ new Map(),
|
|
25259
25402
|
storeRuns: /* @__PURE__ */ new Map(),
|
|
25260
25403
|
logged: /* @__PURE__ */ new Set()
|
|
@@ -25262,7 +25405,7 @@ var init_runtime_layout = __esm({
|
|
|
25262
25405
|
processState.runs ??= /* @__PURE__ */ new Map();
|
|
25263
25406
|
processState.storeRuns ??= /* @__PURE__ */ new Map();
|
|
25264
25407
|
processState.logged ??= /* @__PURE__ */ new Set();
|
|
25265
|
-
|
|
25408
|
+
globalState3[stateKey2] = processState;
|
|
25266
25409
|
LayoutMoveError = class extends Error {
|
|
25267
25410
|
constructor(code2, message) {
|
|
25268
25411
|
super(message);
|
|
@@ -25323,7 +25466,7 @@ async function ensureGitignore(configDir) {
|
|
|
25323
25466
|
`,
|
|
25324
25467
|
"utf-8"
|
|
25325
25468
|
);
|
|
25326
|
-
|
|
25469
|
+
log6.info("Created .gitignore in config directory");
|
|
25327
25470
|
} else {
|
|
25328
25471
|
const suffix = content.endsWith("\n") ? "" : "\n";
|
|
25329
25472
|
await fs.appendFile(
|
|
@@ -25332,12 +25475,12 @@ async function ensureGitignore(configDir) {
|
|
|
25332
25475
|
`,
|
|
25333
25476
|
"utf-8"
|
|
25334
25477
|
);
|
|
25335
|
-
|
|
25478
|
+
log6.info("Updated .gitignore with missing entries", {
|
|
25336
25479
|
added: missingEntries
|
|
25337
25480
|
});
|
|
25338
25481
|
}
|
|
25339
25482
|
} catch (error) {
|
|
25340
|
-
|
|
25483
|
+
log6.warn("Failed to update .gitignore with account storage entries", {
|
|
25341
25484
|
error: String(error)
|
|
25342
25485
|
});
|
|
25343
25486
|
}
|
|
@@ -25372,21 +25515,21 @@ function migrateLegacyWindowsConfig() {
|
|
|
25372
25515
|
mkdirSync(newConfigDir, { recursive: true });
|
|
25373
25516
|
try {
|
|
25374
25517
|
renameSync3(legacyPath, newPath);
|
|
25375
|
-
|
|
25518
|
+
log6.info("Migrated Windows config via rename", {
|
|
25376
25519
|
from: legacyPath,
|
|
25377
25520
|
to: newPath
|
|
25378
25521
|
});
|
|
25379
25522
|
} catch {
|
|
25380
25523
|
copyFileSync(legacyPath, newPath);
|
|
25381
25524
|
unlinkSync(legacyPath);
|
|
25382
|
-
|
|
25525
|
+
log6.info("Migrated Windows config via copy+delete", {
|
|
25383
25526
|
from: legacyPath,
|
|
25384
25527
|
to: newPath
|
|
25385
25528
|
});
|
|
25386
25529
|
}
|
|
25387
25530
|
return true;
|
|
25388
25531
|
} catch (error) {
|
|
25389
|
-
|
|
25532
|
+
log6.warn("Failed to migrate legacy Windows config, will use legacy path", {
|
|
25390
25533
|
legacyPath,
|
|
25391
25534
|
newPath,
|
|
25392
25535
|
error: String(error)
|
|
@@ -25419,7 +25562,7 @@ function getStoragePathWithMigration() {
|
|
|
25419
25562
|
);
|
|
25420
25563
|
const anchored = resolveWindowsAccountAnchor(newPath, legacyPath);
|
|
25421
25564
|
if (resolve16(anchored).toLowerCase() !== resolve16(newPath).toLowerCase() && !existsSync3(accountStorePointerPath(resolve16(anchored)))) {
|
|
25422
|
-
|
|
25565
|
+
log6.info("Using legacy Windows config path (migration failed)", {
|
|
25423
25566
|
legacyPath,
|
|
25424
25567
|
newPath
|
|
25425
25568
|
});
|
|
@@ -25563,14 +25706,14 @@ async function loadAccounts() {
|
|
|
25563
25706
|
await ensureGitignore(dirname16(path2));
|
|
25564
25707
|
return loadAccountStorage(path2);
|
|
25565
25708
|
}
|
|
25566
|
-
var
|
|
25709
|
+
var log6, GITIGNORE_ENTRIES, LegacyAccountPoolRetiredError, MIGRATE_COMMAND, UNMIGRATED_ACCOUNT_MESSAGE, ROLLBACK_COMMAND;
|
|
25567
25710
|
var init_storage = __esm({
|
|
25568
25711
|
"src/plugin/storage.ts"() {
|
|
25569
25712
|
"use strict";
|
|
25570
25713
|
init_dist();
|
|
25571
25714
|
init_runtime_paths();
|
|
25572
25715
|
init_logger4();
|
|
25573
|
-
|
|
25716
|
+
log6 = createLogger4("storage");
|
|
25574
25717
|
GITIGNORE_ENTRIES = [
|
|
25575
25718
|
"antigravity-accounts.json",
|
|
25576
25719
|
"antigravity-accounts.json.*.tmp",
|
|
@@ -26382,15 +26525,15 @@ function getLegacyLogger() {
|
|
|
26382
26525
|
}
|
|
26383
26526
|
function createLogger4(module) {
|
|
26384
26527
|
let channel3;
|
|
26385
|
-
const
|
|
26528
|
+
const log9 = (level, message, extra) => {
|
|
26386
26529
|
channel3 ??= getLegacyLogger().createLogger(module);
|
|
26387
26530
|
channel3[level](message, extra);
|
|
26388
26531
|
};
|
|
26389
26532
|
return {
|
|
26390
|
-
debug: (message, extra) =>
|
|
26391
|
-
info: (message, extra) =>
|
|
26392
|
-
warn: (message, extra) =>
|
|
26393
|
-
error: (message, extra) =>
|
|
26533
|
+
debug: (message, extra) => log9("debug", message, extra),
|
|
26534
|
+
info: (message, extra) => log9("info", message, extra),
|
|
26535
|
+
warn: (message, extra) => log9("warn", message, extra),
|
|
26536
|
+
error: (message, extra) => log9("error", message, extra)
|
|
26394
26537
|
};
|
|
26395
26538
|
}
|
|
26396
26539
|
var ENV_CONSOLE_LOG2, LOG_LEVEL_FROM_OPERATOR, legacyClient, legacyLogger;
|
|
@@ -26594,7 +26737,7 @@ init_storage();
|
|
|
26594
26737
|
// src/plugin/token.ts
|
|
26595
26738
|
init_dist();
|
|
26596
26739
|
init_logger4();
|
|
26597
|
-
var
|
|
26740
|
+
var log7 = createLogger4("token");
|
|
26598
26741
|
function parseOAuthErrorPayload(text2) {
|
|
26599
26742
|
if (!text2) {
|
|
26600
26743
|
return {};
|
|
@@ -26667,13 +26810,13 @@ async function exchangeRefreshToken(refreshToken, now) {
|
|
|
26667
26810
|
const details = [code2, description ?? errorText3].filter(Boolean).join(": ");
|
|
26668
26811
|
const baseMessage = `Antigravity token refresh failed (${response.status} ${response.statusText})`;
|
|
26669
26812
|
const message = details ? `${baseMessage} - ${details}` : baseMessage;
|
|
26670
|
-
|
|
26813
|
+
log7.warn("Token refresh failed", {
|
|
26671
26814
|
status: response.status,
|
|
26672
26815
|
code: code2,
|
|
26673
26816
|
details
|
|
26674
26817
|
});
|
|
26675
26818
|
if (code2 === "invalid_grant") {
|
|
26676
|
-
|
|
26819
|
+
log7.warn(
|
|
26677
26820
|
"Google revoked the stored refresh token - reauthentication required"
|
|
26678
26821
|
);
|
|
26679
26822
|
invalidateProjectContextCache(refreshToken);
|
|
@@ -26715,7 +26858,7 @@ async function refreshAccessToken(auth, _client, _providerId) {
|
|
|
26715
26858
|
if (error instanceof AntigravityTokenRefreshError) {
|
|
26716
26859
|
throw error;
|
|
26717
26860
|
}
|
|
26718
|
-
|
|
26861
|
+
log7.error("Unexpected token refresh error", { error: String(error) });
|
|
26719
26862
|
return void 0;
|
|
26720
26863
|
}
|
|
26721
26864
|
}
|
|
@@ -26732,7 +26875,7 @@ init_dist();
|
|
|
26732
26875
|
// src/plugin/quota.ts
|
|
26733
26876
|
init_logger4();
|
|
26734
26877
|
init_dist();
|
|
26735
|
-
var
|
|
26878
|
+
var log8 = createLogger4("quota");
|
|
26736
26879
|
async function checkAccountsQuotaWith(accounts, fetchAccountQuota) {
|
|
26737
26880
|
const manager = createQuotaManager({
|
|
26738
26881
|
fetchAccountQuota,
|
|
@@ -26866,7 +27009,7 @@ function makeFetchAccountQuota(client, providerId, fetchVia) {
|
|
|
26866
27009
|
let rotatedRefresh;
|
|
26867
27010
|
if (purpose === "advisory") {
|
|
26868
27011
|
if (accessTokenExpired(auth)) {
|
|
26869
|
-
|
|
27012
|
+
log8.debug("advisory-quota-skipped-refresh-needed");
|
|
26870
27013
|
return {
|
|
26871
27014
|
index,
|
|
26872
27015
|
email: account.email,
|
|
@@ -26878,7 +27021,7 @@ function makeFetchAccountQuota(client, providerId, fetchVia) {
|
|
|
26878
27021
|
const managedProjectId = parts.managedProjectId ?? account.managedProjectId;
|
|
26879
27022
|
const projectId = managedProjectId ?? parts.projectId ?? account.projectId;
|
|
26880
27023
|
if (!projectId) {
|
|
26881
|
-
|
|
27024
|
+
log8.debug("advisory-quota-skipped-project-needed");
|
|
26882
27025
|
return {
|
|
26883
27026
|
index,
|
|
26884
27027
|
email: account.email,
|
|
@@ -26900,7 +27043,7 @@ function makeFetchAccountQuota(client, providerId, fetchVia) {
|
|
|
26900
27043
|
{ timeoutMs: extra.timeoutMs }
|
|
26901
27044
|
);
|
|
26902
27045
|
},
|
|
26903
|
-
logger:
|
|
27046
|
+
logger: log8
|
|
26904
27047
|
}),
|
|
26905
27048
|
signal
|
|
26906
27049
|
);
|
|
@@ -26957,7 +27100,7 @@ function makeFetchAccountQuota(client, providerId, fetchVia) {
|
|
|
26957
27100
|
managedProjectId,
|
|
26958
27101
|
projectId: projectContext.effectiveProjectId,
|
|
26959
27102
|
fetchVia,
|
|
26960
|
-
logger:
|
|
27103
|
+
logger: log8
|
|
26961
27104
|
});
|
|
26962
27105
|
quotaResult = payloads.quota;
|
|
26963
27106
|
if (quotaResult.error) throw new Error(quotaResult.error);
|
|
@@ -27336,6 +27479,7 @@ import { join as join22, resolve as resolve20 } from "node:path";
|
|
|
27336
27479
|
// src/auth-method-labels.ts
|
|
27337
27480
|
var OPENCODE2_POOL_AUTH_LABEL = "Google (antigravity-auth pool, browser)";
|
|
27338
27481
|
var OPENCODE2_VAULT_AUTH_LABEL = "Use approved Antigravity vault";
|
|
27482
|
+
var OPENCODE2_POOL_RECONNECT_LABEL = "Use existing local Antigravity pool";
|
|
27339
27483
|
|
|
27340
27484
|
// src/common-auth-embedded/auth-menu/ansi.js
|
|
27341
27485
|
var ANSI2 = {
|
|
@@ -27576,8 +27720,8 @@ async function select2(terminal, items, options) {
|
|
|
27576
27720
|
// src/common-auth-embedded/claustrum/enrollment.js
|
|
27577
27721
|
import { createHash as createHash12, randomBytes as randomBytes3, randomUUID as randomUUID15 } from "node:crypto";
|
|
27578
27722
|
import { constants as fsConstants2 } from "node:fs";
|
|
27579
|
-
import { chmod as chmod5, mkdir as mkdir14, open as open10, readFile as readFile12, realpath as realpath4, rename as rename12, stat as
|
|
27580
|
-
import { basename as basename5, dirname as dirname19, extname as extname2, isAbsolute as
|
|
27723
|
+
import { chmod as chmod5, mkdir as mkdir14, open as open10, readFile as readFile12, realpath as realpath4, rename as rename12, stat as stat11, unlink as unlink11 } from "node:fs/promises";
|
|
27724
|
+
import { basename as basename5, dirname as dirname19, extname as extname2, isAbsolute as isAbsolute4, join as join18, resolve as resolve19 } from "node:path";
|
|
27581
27725
|
import { ClaustrumCredentialError as ClaustrumCredentialError5, ClaustrumClient as ClaustrumWireClient2, writeEnrollmentTokenFile as writeEnrollmentTokenFile2 } from "@cortexkit/claustrum-client";
|
|
27582
27726
|
|
|
27583
27727
|
// src/common-auth-embedded/fs/file-read-cache.js
|
|
@@ -27650,7 +27794,7 @@ init_private_files2();
|
|
|
27650
27794
|
// src/common-auth-embedded/fs/refresh-file-lock.js
|
|
27651
27795
|
init_private_files2();
|
|
27652
27796
|
import { randomUUID as randomUUID14 } from "node:crypto";
|
|
27653
|
-
import { lstat as lstat8, mkdir as mkdir13, open as open9, readFile as readFile11, rename as rename11, rm as rm6, stat as
|
|
27797
|
+
import { lstat as lstat8, mkdir as mkdir13, open as open9, readFile as readFile11, rename as rename11, rm as rm6, stat as stat10 } from "node:fs/promises";
|
|
27654
27798
|
import { dirname as dirname18, join as join17 } from "node:path";
|
|
27655
27799
|
|
|
27656
27800
|
// src/common-auth-embedded/fs/with-lock.js
|
|
@@ -27904,7 +28048,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
27904
28048
|
};
|
|
27905
28049
|
}
|
|
27906
28050
|
try {
|
|
27907
|
-
const current = await
|
|
28051
|
+
const current = await stat10(lockPath);
|
|
27908
28052
|
const legacyExpiry = Number.isFinite(expiresAt) ? expiresAt : current.mtimeMs + options.ttlMs;
|
|
27909
28053
|
if (legacyExpiry > now())
|
|
27910
28054
|
return { status: "live" };
|
|
@@ -27971,7 +28115,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
27971
28115
|
if (!sameMarkerDirectory2(created, current))
|
|
27972
28116
|
return false;
|
|
27973
28117
|
try {
|
|
27974
|
-
await
|
|
28118
|
+
await stat10(evictOwnerPath);
|
|
27975
28119
|
return true;
|
|
27976
28120
|
} catch (error) {
|
|
27977
28121
|
if (error.code !== "ENOENT")
|
|
@@ -28023,7 +28167,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
28023
28167
|
async function recoverStaleEvictionMarker() {
|
|
28024
28168
|
let evictStat;
|
|
28025
28169
|
try {
|
|
28026
|
-
evictStat = await
|
|
28170
|
+
evictStat = await stat10(evictPath);
|
|
28027
28171
|
} catch (error) {
|
|
28028
28172
|
if (error.code === "ENOENT")
|
|
28029
28173
|
return "missing";
|
|
@@ -28041,7 +28185,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
28041
28185
|
if (evictStat.mtimeMs + EVICT_TTL > now()) {
|
|
28042
28186
|
let hasOwner = true;
|
|
28043
28187
|
try {
|
|
28044
|
-
await
|
|
28188
|
+
await stat10(evictOwnerPath);
|
|
28045
28189
|
} catch (error) {
|
|
28046
28190
|
if (error.code === "ENOENT")
|
|
28047
28191
|
hasOwner = false;
|
|
@@ -28443,9 +28587,9 @@ function getClaustrumEnrollmentPaths2(tokenPath) {
|
|
|
28443
28587
|
}
|
|
28444
28588
|
function hostEnrollmentPaths2(input) {
|
|
28445
28589
|
const override = input.override?.trim();
|
|
28446
|
-
if (override && !
|
|
28590
|
+
if (override && !isAbsolute4(override) && !input.cwd)
|
|
28447
28591
|
throw new ClaustrumConsumerError2("invalid-state", "A relative Claustrum enrollment override needs a base directory");
|
|
28448
|
-
const tokenPath = override ?
|
|
28592
|
+
const tokenPath = override ? isAbsolute4(override) ? override : resolve19(input.cwd, override) : join18(input.stateDir, `${input.host}-enrollment.json`);
|
|
28449
28593
|
return getClaustrumEnrollmentPaths2(tokenPath);
|
|
28450
28594
|
}
|
|
28451
28595
|
function isRecord10(value) {
|
|
@@ -28630,7 +28774,7 @@ async function refuseWritableAncestor2(parent, options = {}) {
|
|
|
28630
28774
|
}
|
|
28631
28775
|
let privateGroup;
|
|
28632
28776
|
for (; ; ) {
|
|
28633
|
-
const metadata = await
|
|
28777
|
+
const metadata = await stat11(component).catch(() => void 0);
|
|
28634
28778
|
if (metadata && (metadata.mode & 18) !== 0 && (metadata.mode & 512) === 0) {
|
|
28635
28779
|
if (privateGroup === void 0) {
|
|
28636
28780
|
privateGroup = gid !== void 0 && await isPrivateGroup2(uid, gid, options);
|
|
@@ -28659,7 +28803,7 @@ async function ensureClaustrumPrivateDirectory2(directory, options = {}, what =
|
|
|
28659
28803
|
return;
|
|
28660
28804
|
}
|
|
28661
28805
|
await mkdir14(directory, { recursive: true, mode: 448 });
|
|
28662
|
-
const metadata = await
|
|
28806
|
+
const metadata = await stat11(directory);
|
|
28663
28807
|
const uid = process.geteuid?.();
|
|
28664
28808
|
if (uid !== void 0 && metadata.uid !== uid) {
|
|
28665
28809
|
throw new ClaustrumConsumerError2("unsafe-file", `Claustrum ${what} must be owned by the current user`);
|
|
@@ -28695,7 +28839,7 @@ async function writeStateAtomic2(path2, state, ancestorOptions = {}) {
|
|
|
28695
28839
|
await descriptor?.close().catch(() => {
|
|
28696
28840
|
});
|
|
28697
28841
|
if (created)
|
|
28698
|
-
await
|
|
28842
|
+
await unlink11(temporary).catch(() => {
|
|
28699
28843
|
});
|
|
28700
28844
|
}
|
|
28701
28845
|
}
|
|
@@ -28922,7 +29066,7 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
28922
29066
|
}
|
|
28923
29067
|
if (refusal3.code === UNSUPPORTED_ENROLLMENT_CODE2) {
|
|
28924
29068
|
await lock.assertOwned();
|
|
28925
|
-
await
|
|
29069
|
+
await unlink11(this.#paths.statePath).catch((cause) => {
|
|
28926
29070
|
if (cause.code !== "ENOENT")
|
|
28927
29071
|
throw cause;
|
|
28928
29072
|
});
|
|
@@ -29012,7 +29156,7 @@ async function resetClaustrumEnrollmentState2(paths, proposedName) {
|
|
|
29012
29156
|
if (state.phase === "pending")
|
|
29013
29157
|
return "refused-pending";
|
|
29014
29158
|
await lock.assertOwned();
|
|
29015
|
-
await
|
|
29159
|
+
await unlink11(paths.statePath);
|
|
29016
29160
|
return "reset";
|
|
29017
29161
|
} finally {
|
|
29018
29162
|
await lock.release();
|
|
@@ -29248,7 +29392,7 @@ function setupPaths(io = {}) {
|
|
|
29248
29392
|
}
|
|
29249
29393
|
|
|
29250
29394
|
// src/common-auth-embedded/setup/detect.js
|
|
29251
|
-
function
|
|
29395
|
+
function stat12(path2, kind) {
|
|
29252
29396
|
try {
|
|
29253
29397
|
return statSync5(path2)[kind]();
|
|
29254
29398
|
} catch {
|
|
@@ -29257,12 +29401,12 @@ function stat11(path2, kind) {
|
|
|
29257
29401
|
}
|
|
29258
29402
|
var defaultSetupFileSystem = {
|
|
29259
29403
|
exists: existsSync6,
|
|
29260
|
-
isFile: (path2) =>
|
|
29261
|
-
isDirectory: (path2) =>
|
|
29404
|
+
isFile: (path2) => stat12(path2, "isFile"),
|
|
29405
|
+
isDirectory: (path2) => stat12(path2, "isDirectory"),
|
|
29262
29406
|
isExecutable(path2) {
|
|
29263
29407
|
try {
|
|
29264
29408
|
accessSync(path2, constants3.X_OK);
|
|
29265
|
-
return
|
|
29409
|
+
return stat12(path2, "isFile");
|
|
29266
29410
|
} catch {
|
|
29267
29411
|
return false;
|
|
29268
29412
|
}
|
|
@@ -29968,7 +30112,7 @@ import { applyEdits, createScanner, findNodeAtLocation, modify, parse as parse2,
|
|
|
29968
30112
|
|
|
29969
30113
|
// src/common-auth-embedded/setup/config-write.js
|
|
29970
30114
|
import { randomUUID as randomUUID16 } from "node:crypto";
|
|
29971
|
-
import { mkdir as mkdir15, open as open11, rename as rename13, stat as
|
|
30115
|
+
import { mkdir as mkdir15, open as open11, rename as rename13, stat as stat13, unlink as unlink12 } from "node:fs/promises";
|
|
29972
30116
|
import { basename as basename6, dirname as dirname20, join as join20 } from "node:path";
|
|
29973
30117
|
import { setTimeout as delay2 } from "node:timers/promises";
|
|
29974
30118
|
async function writeHostConfigAtomic(file, content, options = {}) {
|
|
@@ -29978,7 +30122,7 @@ async function writeHostConfigAtomic(file, content, options = {}) {
|
|
|
29978
30122
|
let mode;
|
|
29979
30123
|
if (!windows) {
|
|
29980
30124
|
try {
|
|
29981
|
-
mode = (await
|
|
30125
|
+
mode = (await stat13(file)).mode & 4095;
|
|
29982
30126
|
} catch (error) {
|
|
29983
30127
|
if (error.code !== "ENOENT")
|
|
29984
30128
|
throw error;
|
|
@@ -30014,7 +30158,7 @@ async function writeHostConfigAtomic(file, content, options = {}) {
|
|
|
30014
30158
|
}
|
|
30015
30159
|
} finally {
|
|
30016
30160
|
if (created)
|
|
30017
|
-
await
|
|
30161
|
+
await unlink12(stage).catch(() => {
|
|
30018
30162
|
});
|
|
30019
30163
|
}
|
|
30020
30164
|
}
|
|
@@ -30415,63 +30559,7 @@ function nativeOpenCodeAuthPath(env3 = process.env, home = homedir7()) {
|
|
|
30415
30559
|
// src/setup.ts
|
|
30416
30560
|
init_vault_custody();
|
|
30417
30561
|
init_runtime_paths();
|
|
30418
|
-
|
|
30419
|
-
// src/vault-folder.ts
|
|
30420
|
-
init_logger4();
|
|
30421
|
-
init_process_heartbeat();
|
|
30422
|
-
init_runtime_layout();
|
|
30423
|
-
init_runtime_paths();
|
|
30424
|
-
var refusalsKey = /* @__PURE__ */ Symbol.for(
|
|
30425
|
-
"@cortexkit/antigravity-auth/vault-folder-refusals"
|
|
30426
|
-
);
|
|
30427
|
-
var globalState3 = globalThis;
|
|
30428
|
-
var refusals = globalState3[refusalsKey] ?? /* @__PURE__ */ new Map();
|
|
30429
|
-
globalState3[refusalsKey] = refusals;
|
|
30430
|
-
function locationKey() {
|
|
30431
|
-
const location = runtimeLayoutLocation();
|
|
30432
|
-
return `${location.stateHomeDir}\0${location.key}`;
|
|
30433
|
-
}
|
|
30434
|
-
async function prepareVaultFolder(options) {
|
|
30435
|
-
const { accountFile } = options;
|
|
30436
|
-
const key = locationKey();
|
|
30437
|
-
const kept = refusals.get(key);
|
|
30438
|
-
if (kept) return refused(accountFile, kept);
|
|
30439
|
-
const log8 = options.log ?? createLogger4("runtime-layout");
|
|
30440
|
-
const version = options.version ?? await pluginPackageVersion().catch(() => "unknown");
|
|
30441
|
-
try {
|
|
30442
|
-
await prepareRuntimeLayout({
|
|
30443
|
-
version,
|
|
30444
|
-
accountFile,
|
|
30445
|
-
log: log8,
|
|
30446
|
-
...options.layoutLockWaitMs === void 0 ? {} : { layoutLockWaitMs: options.layoutLockWaitMs }
|
|
30447
|
-
});
|
|
30448
|
-
if (options.accountStore !== false)
|
|
30449
|
-
await prepareAccountStore({ version, log: log8 });
|
|
30450
|
-
} catch (error) {
|
|
30451
|
-
const refusal3 = error instanceof RuntimeLayoutRefusal ? error : new RuntimeLayoutRefusal(
|
|
30452
|
-
runtimeLayoutLocation().stateHomeDir,
|
|
30453
|
-
error instanceof Error ? error.name : typeof error
|
|
30454
|
-
);
|
|
30455
|
-
if (!refusals.has(key)) {
|
|
30456
|
-
refusals.set(key, refusal3);
|
|
30457
|
-
log8.warn(refusal3.message, {
|
|
30458
|
-
stateDir: refusal3.stateDir,
|
|
30459
|
-
errorClass: refusal3.errorClass
|
|
30460
|
-
});
|
|
30461
|
-
}
|
|
30462
|
-
return refused(accountFile, refusals.get(key) ?? refusal3);
|
|
30463
|
-
}
|
|
30464
|
-
return { accountFile, vaultDir: getVaultDir(accountFile) };
|
|
30465
|
-
}
|
|
30466
|
-
function currentVaultFolder(accountFile) {
|
|
30467
|
-
const kept = refusals.get(locationKey());
|
|
30468
|
-
return kept ? refused(accountFile, kept) : { accountFile, vaultDir: getVaultDir(accountFile) };
|
|
30469
|
-
}
|
|
30470
|
-
function refused(accountFile, refusal3) {
|
|
30471
|
-
return { accountFile, vaultDir: getVaultDir(accountFile), refusal: refusal3 };
|
|
30472
|
-
}
|
|
30473
|
-
|
|
30474
|
-
// src/setup.ts
|
|
30562
|
+
init_vault_folder();
|
|
30475
30563
|
var PI_PLACEHOLDER_KEY = "antigravity-vault-custody";
|
|
30476
30564
|
async function storePresent(anchor) {
|
|
30477
30565
|
return await pathPresent(accountStorePointerPath(anchor)) || await pathPresent(anchor);
|
|
@@ -30625,6 +30713,7 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
30625
30713
|
}
|
|
30626
30714
|
};
|
|
30627
30715
|
let openCodeLogin;
|
|
30716
|
+
let hasLocalPool = false;
|
|
30628
30717
|
const manifest = JSON.parse(
|
|
30629
30718
|
await readFile13(new URL("../package.json", import.meta.url), "utf8")
|
|
30630
30719
|
);
|
|
@@ -30680,7 +30769,23 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
30680
30769
|
},
|
|
30681
30770
|
signInLocal: async (host, context) => {
|
|
30682
30771
|
await assertLocal(host, context);
|
|
30683
|
-
if (host === "opencode" && context.opencodeGeneration === "2")
|
|
30772
|
+
if (host === "opencode" && context.opencodeGeneration === "2") {
|
|
30773
|
+
if (!forceLogin) {
|
|
30774
|
+
try {
|
|
30775
|
+
const source2 = await deps.accountStore.read(
|
|
30776
|
+
deps.accountStore.legacyPath()
|
|
30777
|
+
);
|
|
30778
|
+
const candidateAccounts = source2.kind === "store" ? source2.accounts : source2.kind === "legacy" ? (await deps.loadAccounts())?.accounts ?? [] : [];
|
|
30779
|
+
if (candidateAccounts.some(
|
|
30780
|
+
(account) => account.enabled !== false && account.accountIneligible !== true && account.verificationRequired !== true && typeof account.refreshToken === "string" && account.refreshToken.length > 0
|
|
30781
|
+
)) {
|
|
30782
|
+
hasLocalPool = true;
|
|
30783
|
+
}
|
|
30784
|
+
} catch {
|
|
30785
|
+
}
|
|
30786
|
+
}
|
|
30787
|
+
return;
|
|
30788
|
+
}
|
|
30684
30789
|
const slot = (await nativeAuth(host, context))[provider(host)];
|
|
30685
30790
|
const source = host === "opencode" ? await deps.accountStore.read(deps.accountStore.legacyPath()) : void 0;
|
|
30686
30791
|
if (source?.kind === "unavailable") throw new Error(source.reason);
|
|
@@ -30692,6 +30797,11 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
30692
30797
|
`Using existing local Antigravity login for ${host}.
|
|
30693
30798
|
`
|
|
30694
30799
|
);
|
|
30800
|
+
if (host === "opencode" && accounts.some(
|
|
30801
|
+
(account) => account.enabled !== false && account.accountIneligible !== true && account.verificationRequired !== true && typeof account.refreshToken === "string" && account.refreshToken.length > 0
|
|
30802
|
+
)) {
|
|
30803
|
+
hasLocalPool = true;
|
|
30804
|
+
}
|
|
30695
30805
|
if (host === "opencode" && claustrum.classifyHostSlot(slot, provider(host)) !== "login") {
|
|
30696
30806
|
const account = accounts[0];
|
|
30697
30807
|
await writeNativeSlot(
|
|
@@ -30722,7 +30832,10 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
30722
30832
|
host,
|
|
30723
30833
|
context
|
|
30724
30834
|
);
|
|
30725
|
-
if (host === "opencode")
|
|
30835
|
+
if (host === "opencode") {
|
|
30836
|
+
openCodeLogin = result;
|
|
30837
|
+
hasLocalPool = true;
|
|
30838
|
+
}
|
|
30726
30839
|
},
|
|
30727
30840
|
beforeRegister: async (host, mode, context) => {
|
|
30728
30841
|
const needsOpenCode2 = host === "opencode" && context.opencodeGeneration !== "1";
|
|
@@ -30746,7 +30859,10 @@ Setup has not completed the OpenCode 2 native Google connection.
|
|
|
30746
30859
|
},
|
|
30747
30860
|
context
|
|
30748
30861
|
);
|
|
30749
|
-
if (needsOpenCode2)
|
|
30862
|
+
if (needsOpenCode2)
|
|
30863
|
+
nativeNextStep(
|
|
30864
|
+
hasLocalPool ? OPENCODE2_POOL_RECONNECT_LABEL : OPENCODE2_POOL_AUTH_LABEL
|
|
30865
|
+
);
|
|
30750
30866
|
return;
|
|
30751
30867
|
}
|
|
30752
30868
|
if (await authority(host) !== "vault")
|
|
@@ -30840,6 +30956,7 @@ async function runPluginSetup(argv, deps, migrateOpenCode, io = {}) {
|
|
|
30840
30956
|
}
|
|
30841
30957
|
|
|
30842
30958
|
// src/cli.ts
|
|
30959
|
+
init_vault_folder();
|
|
30843
30960
|
var HELP = `Usage: antigravity-auth <command> [options]
|
|
30844
30961
|
|
|
30845
30962
|
Commands:
|