@cortexkit/opencode-antigravity-auth 3.0.38 → 3.0.39
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/README.md +1 -1
- package/dist/cli.js +602 -320
- package/dist/cli.js.map +4 -4
- package/dist/cli.meta.json +100 -32
- package/dist/index.js +807 -384
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +115 -39
- package/dist/server.js +828 -398
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/common-auth-embedded/claustrum/availability.d.ts +7 -1
- package/dist/src/common-auth-embedded/claustrum/availability.js +9 -1
- package/dist/src/common-auth-embedded/claustrum/custody.d.ts +11 -2
- package/dist/src/common-auth-embedded/claustrum/custody.js +89 -31
- package/dist/src/common-auth-embedded/claustrum/enrollment.d.ts +4 -0
- package/dist/src/common-auth-embedded/claustrum/enrollment.js +33 -2
- package/dist/src/common-auth-embedded/claustrum/host.js +11 -7
- package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -1
- package/dist/src/common-auth-embedded/claustrum/index.js +1 -1
- package/dist/src/common-auth-embedded/fs/lock-record.js +55 -0
- package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +148 -92
- package/dist/src/common-auth-embedded/fs/with-lock.js +19 -13
- package/dist/src/common-auth-embedded/quota-sidebar/index.d.ts +2 -36
- package/dist/src/common-auth-embedded/quota-sidebar/index.tsx +49 -607
- package/dist/src/common-auth-embedded/routing-accessor/cache-policy.d.ts +3 -0
- package/dist/src/common-auth-embedded/routing-accessor/cache-policy.js +11 -0
- package/dist/src/common-auth-embedded/routing-accessor/index.d.ts +48 -5
- package/dist/src/common-auth-embedded/routing-accessor/index.js +136 -5
- package/dist/src/common-auth-embedded/setup/enroll.js +2 -1
- package/dist/src/common-auth-embedded/setup/types.d.ts +1 -0
- package/dist/src/common-auth-embedded/source-output.json +72 -64
- package/dist/src/ga/tui/host-ga.d.ts +20 -3
- package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
- package/dist/src/ga/tui/host-ga.js +102 -25
- package/dist/src/ga/tui/host-ga.js.map +1 -1
- package/dist/src/plugin/__fixtures__/release-model-ids.d.ts.map +1 -1
- package/dist/src/plugin/__fixtures__/release-model-ids.js +1 -0
- package/dist/src/plugin/__fixtures__/release-model-ids.js.map +1 -1
- package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
- package/dist/src/plugin/ga-location-services.d.ts +1 -0
- package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/src/plugin/ga-location-services.js +6 -0
- package/dist/src/plugin/ga-location-services.js.map +1 -1
- package/dist/src/plugin/request.d.ts.map +1 -1
- package/dist/src/plugin/request.js +3 -1
- package/dist/src/plugin/request.js.map +1 -1
- package/dist/src/setup.d.ts.map +1 -1
- package/dist/src/setup.js +2 -0
- package/dist/src/setup.js.map +1 -1
- package/dist/tui-build-map.json +19 -5
- package/dist/tui-ga-build-map.json +23 -9
- package/dist/types/src/common-auth-embedded/claustrum/availability.d.ts +7 -1
- package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +11 -2
- package/dist/types/src/common-auth-embedded/claustrum/enrollment.d.ts +4 -0
- package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/routing-accessor/cache-policy.d.ts +3 -0
- package/dist/types/src/common-auth-embedded/routing-accessor/index.d.ts +48 -5
- package/dist/types/src/common-auth-embedded/setup/types.d.ts +1 -0
- package/dist/types/src/plugin/ga-location-services.d.ts +1 -0
- package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/types/src/plugin/request.d.ts.map +1 -1
- package/dist/types/src/setup.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/common-auth-embedded/claustrum/availability.d.ts +7 -1
- package/src/common-auth-embedded/claustrum/availability.js +9 -1
- package/src/common-auth-embedded/claustrum/custody.d.ts +11 -2
- package/src/common-auth-embedded/claustrum/custody.js +89 -31
- package/src/common-auth-embedded/claustrum/enrollment.d.ts +4 -0
- package/src/common-auth-embedded/claustrum/enrollment.js +33 -2
- package/src/common-auth-embedded/claustrum/host.js +11 -7
- package/src/common-auth-embedded/claustrum/index.d.ts +1 -1
- package/src/common-auth-embedded/claustrum/index.js +1 -1
- package/src/common-auth-embedded/fs/lock-record.js +55 -0
- package/src/common-auth-embedded/fs/refresh-file-lock.js +148 -92
- package/src/common-auth-embedded/fs/with-lock.js +19 -13
- package/src/common-auth-embedded/quota-sidebar/index.d.ts +2 -36
- package/src/common-auth-embedded/quota-sidebar/index.tsx +49 -607
- package/src/common-auth-embedded/routing-accessor/cache-policy.d.ts +3 -0
- package/src/common-auth-embedded/routing-accessor/cache-policy.js +11 -0
- package/src/common-auth-embedded/routing-accessor/index.d.ts +48 -5
- package/src/common-auth-embedded/routing-accessor/index.js +136 -5
- package/src/common-auth-embedded/setup/enroll.js +2 -1
- package/src/common-auth-embedded/setup/types.d.ts +1 -0
- package/src/common-auth-embedded/source-output.json +72 -64
- package/src/tui-compiled/common-auth-embedded/quota-sidebar/index.js +36 -674
- package/src/tui-compiled/shared/a75d0d866c227b3f-index.js +678 -0
- package/src/tui-ga-compiled/host-ga.js +86 -26
- package/src/tui-ga-compiled/shared/a75d0d866c227b3f-index.js +678 -0
- package/src/tui-ga-compiled/shared/e4ec36f367492969-index.js +36 -674
- package/src/tui-ga-raw/host-ga.tsx +122 -25
- package/src/tui-ga-raw/shared/a75d0d866c227b3f-index.tsx +681 -0
- package/src/tui-ga-raw/shared/e4ec36f367492969-index.tsx +49 -607
- package/src/tui-raw/common-auth-embedded/quota-sidebar/index.tsx +49 -607
- package/src/tui-raw/shared/a75d0d866c227b3f-index.tsx +681 -0
package/dist/index.js
CHANGED
|
@@ -5933,6 +5933,8 @@ function getGemini38FlashAntigravityModel(tier) {
|
|
|
5933
5933
|
}
|
|
5934
5934
|
function getQuotaGroupForModel(modelId, hasArgonPool = false) {
|
|
5935
5935
|
const normalized = modelId.toLowerCase();
|
|
5936
|
+
if (isGeminiCarbonModel(normalized))
|
|
5937
|
+
return "gemini";
|
|
5936
5938
|
if (isGeminiArgonModel(normalized))
|
|
5937
5939
|
return hasArgonPool ? "gemini-argon" : void 0;
|
|
5938
5940
|
return QUOTA_GROUP_BY_MODEL_ID[normalized] ?? // Check Claude / GPT-OSS substrings BEFORE the `gemini` substring so
|
|
@@ -5945,6 +5947,19 @@ function getQuotaGroupForModel(modelId, hasArgonPool = false) {
|
|
|
5945
5947
|
function isGeminiArgonModel(model) {
|
|
5946
5948
|
return /^(?:antigravity-)?gemini-4-argon(?:-(?:low|medium|high))?$/.test(model.toLowerCase());
|
|
5947
5949
|
}
|
|
5950
|
+
function isGeminiCarbonModel(model) {
|
|
5951
|
+
return /^(?:antigravity-)?gemini-4-carbon(?:-(?:low|medium|high))?$/.test(model.toLowerCase());
|
|
5952
|
+
}
|
|
5953
|
+
function getGeminiCarbonAntigravityModel(tier) {
|
|
5954
|
+
return getTieredAntigravityModel({
|
|
5955
|
+
defaultModel: "gemini-4-carbon-medium",
|
|
5956
|
+
byTier: {
|
|
5957
|
+
low: "gemini-4-carbon-low",
|
|
5958
|
+
medium: "gemini-4-carbon-medium",
|
|
5959
|
+
high: "gemini-4-carbon-high"
|
|
5960
|
+
}
|
|
5961
|
+
}, tier);
|
|
5962
|
+
}
|
|
5948
5963
|
function getGeminiArgonAntigravityModel(tier) {
|
|
5949
5964
|
return getTieredAntigravityModel({
|
|
5950
5965
|
defaultModel: "gemini-4-argon-medium",
|
|
@@ -5967,6 +5982,33 @@ var init_model_registry = __esm({
|
|
|
5967
5982
|
DEFAULT_COST = { input: 0, output: 0 };
|
|
5968
5983
|
DEFAULT_OPTIONS = {};
|
|
5969
5984
|
AGY_NATIVE_MODEL_DEFINITIONS = {
|
|
5985
|
+
"gemini-4-carbon-low": {
|
|
5986
|
+
displayName: "Gemini 4 Carbon (Low)",
|
|
5987
|
+
maxTokens: 1048576,
|
|
5988
|
+
maxOutputTokens: 262144,
|
|
5989
|
+
model: "MODEL_PLACEHOLDER_M438",
|
|
5990
|
+
thinkingLevel: 1,
|
|
5991
|
+
thinkingBudget: -1,
|
|
5992
|
+
supportsThinking: true
|
|
5993
|
+
},
|
|
5994
|
+
"gemini-4-carbon-medium": {
|
|
5995
|
+
displayName: "Gemini 4 Carbon (Medium)",
|
|
5996
|
+
maxTokens: 1048576,
|
|
5997
|
+
maxOutputTokens: 262144,
|
|
5998
|
+
model: "MODEL_PLACEHOLDER_M437",
|
|
5999
|
+
thinkingLevel: 2,
|
|
6000
|
+
thinkingBudget: -1,
|
|
6001
|
+
supportsThinking: true
|
|
6002
|
+
},
|
|
6003
|
+
"gemini-4-carbon-high": {
|
|
6004
|
+
displayName: "Gemini 4 Carbon (High)",
|
|
6005
|
+
maxTokens: 1048576,
|
|
6006
|
+
maxOutputTokens: 262144,
|
|
6007
|
+
model: "MODEL_PLACEHOLDER_M427",
|
|
6008
|
+
thinkingLevel: 3,
|
|
6009
|
+
thinkingBudget: -1,
|
|
6010
|
+
supportsThinking: true
|
|
6011
|
+
},
|
|
5970
6012
|
"gemini-4-argon-low": {
|
|
5971
6013
|
displayName: "Gemini 4 Argon (Low)",
|
|
5972
6014
|
maxTokens: 1048576,
|
|
@@ -6105,6 +6147,17 @@ var init_model_registry = __esm({
|
|
|
6105
6147
|
high: { thinkingLevel: "high" }
|
|
6106
6148
|
}
|
|
6107
6149
|
}),
|
|
6150
|
+
"antigravity-gemini-4-carbon": defineModel("antigravity-gemini-4-carbon", {
|
|
6151
|
+
name: "Gemini 4 Carbon (Antigravity)",
|
|
6152
|
+
reasoning: true,
|
|
6153
|
+
limit: { context: 1048576, output: 262144 },
|
|
6154
|
+
modalities: DEFAULT_MODALITIES,
|
|
6155
|
+
variants: {
|
|
6156
|
+
low: { thinkingLevel: "low" },
|
|
6157
|
+
medium: { thinkingLevel: "medium" },
|
|
6158
|
+
high: { thinkingLevel: "high" }
|
|
6159
|
+
}
|
|
6160
|
+
}),
|
|
6108
6161
|
"antigravity-gemini-3.1-flash-image": defineModel("antigravity-gemini-3.1-flash-image", {
|
|
6109
6162
|
name: "Gemini 3.1 Flash Image (Antigravity)",
|
|
6110
6163
|
reasoning: false,
|
|
@@ -6152,6 +6205,9 @@ var init_model_registry = __esm({
|
|
|
6152
6205
|
})
|
|
6153
6206
|
};
|
|
6154
6207
|
RESOLVER_ALIASES = {
|
|
6208
|
+
"gemini-4-carbon-low": "gemini-4-carbon",
|
|
6209
|
+
"gemini-4-carbon-medium": "gemini-4-carbon",
|
|
6210
|
+
"gemini-4-carbon-high": "gemini-4-carbon",
|
|
6155
6211
|
"gemini-4-argon-low": "gemini-4-argon",
|
|
6156
6212
|
"gemini-4-argon-medium": "gemini-4-argon",
|
|
6157
6213
|
"gemini-4-argon-high": "gemini-4-argon",
|
|
@@ -6247,6 +6303,7 @@ var init_model_registry = __esm({
|
|
|
6247
6303
|
};
|
|
6248
6304
|
ANTIGRAVITY_OPENCODE_MODEL_IDS = [
|
|
6249
6305
|
"antigravity-gemini-4-argon",
|
|
6306
|
+
"antigravity-gemini-4-carbon",
|
|
6250
6307
|
"antigravity-gemini-3.8-flash",
|
|
6251
6308
|
"antigravity-gemini-3.1-flash-image",
|
|
6252
6309
|
"antigravity-claude-sonnet-5-5",
|
|
@@ -7883,7 +7940,7 @@ async function rmEvictingDir(evictingPath) {
|
|
|
7883
7940
|
});
|
|
7884
7941
|
}
|
|
7885
7942
|
async function sleep(ms) {
|
|
7886
|
-
await new Promise((
|
|
7943
|
+
await new Promise((resolve29) => setTimeout(resolve29, ms));
|
|
7887
7944
|
}
|
|
7888
7945
|
async function acquireFencedFileLock(options) {
|
|
7889
7946
|
const lockPath = `${options.path}.${options.name}.lock`;
|
|
@@ -7999,8 +8056,8 @@ function buildLock(lockPath, evictingPath, ownerId, options, now) {
|
|
|
7999
8056
|
let released = false;
|
|
8000
8057
|
let lost = false;
|
|
8001
8058
|
let lostResolve = null;
|
|
8002
|
-
let lostPromise = new Promise((
|
|
8003
|
-
lostResolve =
|
|
8059
|
+
let lostPromise = new Promise((resolve29) => {
|
|
8060
|
+
lostResolve = resolve29;
|
|
8004
8061
|
});
|
|
8005
8062
|
const markLost = () => {
|
|
8006
8063
|
if (lost)
|
|
@@ -8010,9 +8067,9 @@ function buildLock(lockPath, evictingPath, ownerId, options, now) {
|
|
|
8010
8067
|
clearInterval(renewTimer);
|
|
8011
8068
|
renewTimer = null;
|
|
8012
8069
|
}
|
|
8013
|
-
const
|
|
8070
|
+
const resolve29 = lostResolve;
|
|
8014
8071
|
lostResolve = null;
|
|
8015
|
-
|
|
8072
|
+
resolve29?.();
|
|
8016
8073
|
};
|
|
8017
8074
|
const setupRenew = () => {
|
|
8018
8075
|
if (options.renew === false)
|
|
@@ -8635,7 +8692,7 @@ async function saveAccountStorageReplace(path5, incoming) {
|
|
|
8635
8692
|
return mutateAccountStorage(path5, () => incoming);
|
|
8636
8693
|
}
|
|
8637
8694
|
async function clearAccountStorage(path5) {
|
|
8638
|
-
const sleep5 = (ms) => new Promise((
|
|
8695
|
+
const sleep5 = (ms) => new Promise((resolve29) => setTimeout(resolve29, ms));
|
|
8639
8696
|
const lock = await acquireWithRetry(path5, sleep5);
|
|
8640
8697
|
try {
|
|
8641
8698
|
await assertLegacyAccountStorageWritable(path5);
|
|
@@ -8683,7 +8740,7 @@ var init_account_storage = __esm({
|
|
|
8683
8740
|
}
|
|
8684
8741
|
};
|
|
8685
8742
|
RETRY_DELAYS_MS = [100, 200, 400, 800, 1e3];
|
|
8686
|
-
DEFAULT_SLEEP = (ms) => new Promise((
|
|
8743
|
+
DEFAULT_SLEEP = (ms) => new Promise((resolve29) => setTimeout(resolve29, ms));
|
|
8687
8744
|
DEFAULT_BUILD_BACKUP_PATH = (path5, now) => `${path5}.corrupt-${now.toISOString().replace(/[:.]/g, "-")}`;
|
|
8688
8745
|
}
|
|
8689
8746
|
});
|
|
@@ -9901,8 +9958,8 @@ var init_account_manager = __esm({
|
|
|
9901
9958
|
await this.saveInFlight;
|
|
9902
9959
|
return;
|
|
9903
9960
|
}
|
|
9904
|
-
return new Promise((
|
|
9905
|
-
this.savePromiseResolvers.push({ resolve:
|
|
9961
|
+
return new Promise((resolve29, reject) => {
|
|
9962
|
+
this.savePromiseResolvers.push({ resolve: resolve29, reject });
|
|
9906
9963
|
});
|
|
9907
9964
|
}
|
|
9908
9965
|
async dispose() {
|
|
@@ -9945,8 +10002,8 @@ var init_account_manager = __esm({
|
|
|
9945
10002
|
reject(error);
|
|
9946
10003
|
throw error;
|
|
9947
10004
|
}
|
|
9948
|
-
for (const { resolve:
|
|
9949
|
-
|
|
10005
|
+
for (const { resolve: resolve29 } of resolvers)
|
|
10006
|
+
resolve29();
|
|
9950
10007
|
}
|
|
9951
10008
|
async executeSave() {
|
|
9952
10009
|
this.savePending = false;
|
|
@@ -9960,16 +10017,16 @@ var init_account_manager = __esm({
|
|
|
9960
10017
|
}
|
|
9961
10018
|
try {
|
|
9962
10019
|
await this.saveToDisk();
|
|
9963
|
-
for (const { resolve:
|
|
9964
|
-
|
|
10020
|
+
for (const { resolve: resolve29 } of resolvers) {
|
|
10021
|
+
resolve29();
|
|
9965
10022
|
}
|
|
9966
10023
|
} catch (error) {
|
|
9967
10024
|
if (isStorageLockContention(error)) {
|
|
9968
10025
|
this.onDiagnostic?.("Skipped account-state persist due to storage lock contention", {
|
|
9969
10026
|
error: String(error)
|
|
9970
10027
|
});
|
|
9971
|
-
for (const { resolve:
|
|
9972
|
-
|
|
10028
|
+
for (const { resolve: resolve29 } of resolvers) {
|
|
10029
|
+
resolve29();
|
|
9973
10030
|
}
|
|
9974
10031
|
return;
|
|
9975
10032
|
}
|
|
@@ -10470,7 +10527,7 @@ function getHttpsProxy(url) {
|
|
|
10470
10527
|
}
|
|
10471
10528
|
}
|
|
10472
10529
|
function waitForHead(socket, timeoutMs, onTimeout) {
|
|
10473
|
-
return new Promise((
|
|
10530
|
+
return new Promise((resolve29, reject) => {
|
|
10474
10531
|
let buffer = Buffer3.alloc(0);
|
|
10475
10532
|
const timeout = setTimeout(() => {
|
|
10476
10533
|
onTimeout();
|
|
@@ -10493,7 +10550,7 @@ function waitForHead(socket, timeoutMs, onTimeout) {
|
|
|
10493
10550
|
return;
|
|
10494
10551
|
const head = buffer.subarray(0, marker).toString("latin1");
|
|
10495
10552
|
const leftover = buffer.subarray(marker + 4);
|
|
10496
|
-
cleanup2(() =>
|
|
10553
|
+
cleanup2(() => resolve29({ head, leftover }));
|
|
10497
10554
|
};
|
|
10498
10555
|
socket.on("data", onData);
|
|
10499
10556
|
socket.once("error", onError);
|
|
@@ -10507,7 +10564,7 @@ async function connectViaProxy(proxyUrl, targetUrl, timeoutMs, signal, onDebug)
|
|
|
10507
10564
|
port: Number(proxyUrl.port || DEFAULT_PROXY_PORT),
|
|
10508
10565
|
signal: signal ?? void 0
|
|
10509
10566
|
});
|
|
10510
|
-
await new Promise((
|
|
10567
|
+
await new Promise((resolve29, reject) => {
|
|
10511
10568
|
const timeout = setTimeout(() => {
|
|
10512
10569
|
onDebug?.(`agy transport proxy connect timeout after ${timeoutMs}ms`);
|
|
10513
10570
|
proxySocket.destroy();
|
|
@@ -10516,7 +10573,7 @@ async function connectViaProxy(proxyUrl, targetUrl, timeoutMs, signal, onDebug)
|
|
|
10516
10573
|
const cleanup2 = () => clearTimeout(timeout);
|
|
10517
10574
|
proxySocket.once("connect", () => {
|
|
10518
10575
|
cleanup2();
|
|
10519
|
-
|
|
10576
|
+
resolve29();
|
|
10520
10577
|
});
|
|
10521
10578
|
proxySocket.once("error", (error) => {
|
|
10522
10579
|
cleanup2();
|
|
@@ -10541,7 +10598,7 @@ Host: ${targetHost}:${targetPort}\r
|
|
|
10541
10598
|
if (leftover.length > 0) {
|
|
10542
10599
|
proxySocket.unshift(leftover);
|
|
10543
10600
|
}
|
|
10544
|
-
return await new Promise((
|
|
10601
|
+
return await new Promise((resolve29, reject) => {
|
|
10545
10602
|
const tlsOptions = {
|
|
10546
10603
|
socket: proxySocket,
|
|
10547
10604
|
servername: targetHost,
|
|
@@ -10556,7 +10613,7 @@ Host: ${targetHost}:${targetPort}\r
|
|
|
10556
10613
|
const cleanup2 = () => clearTimeout(timeout);
|
|
10557
10614
|
tlsSocket.once("secureConnect", () => {
|
|
10558
10615
|
cleanup2();
|
|
10559
|
-
|
|
10616
|
+
resolve29(tlsSocket);
|
|
10560
10617
|
});
|
|
10561
10618
|
tlsSocket.once("error", (error) => {
|
|
10562
10619
|
cleanup2();
|
|
@@ -10565,7 +10622,7 @@ Host: ${targetHost}:${targetPort}\r
|
|
|
10565
10622
|
});
|
|
10566
10623
|
}
|
|
10567
10624
|
async function connectDirect(targetUrl, timeoutMs, signal, onDebug) {
|
|
10568
|
-
return await new Promise((
|
|
10625
|
+
return await new Promise((resolve29, reject) => {
|
|
10569
10626
|
const tlsOptions = {
|
|
10570
10627
|
host: targetUrl.hostname,
|
|
10571
10628
|
port: Number(targetUrl.port || DEFAULT_HTTPS_PORT),
|
|
@@ -10581,7 +10638,7 @@ async function connectDirect(targetUrl, timeoutMs, signal, onDebug) {
|
|
|
10581
10638
|
const cleanup2 = () => clearTimeout(timeout);
|
|
10582
10639
|
socket.once("secureConnect", () => {
|
|
10583
10640
|
cleanup2();
|
|
10584
|
-
|
|
10641
|
+
resolve29(socket);
|
|
10585
10642
|
});
|
|
10586
10643
|
socket.once("error", (error) => {
|
|
10587
10644
|
cleanup2();
|
|
@@ -12658,6 +12715,45 @@ var init_atomic_write2 = __esm({
|
|
|
12658
12715
|
}
|
|
12659
12716
|
});
|
|
12660
12717
|
|
|
12718
|
+
// ../core/dist/common-auth-embedded/fs/lock-record.js
|
|
12719
|
+
import { resolve as resolve3 } from "node:path";
|
|
12720
|
+
function isWindowsAccessDeniedRead(error, paths) {
|
|
12721
|
+
return error instanceof PrivateFileError && error.reason === "io-error" && error.win32Code === 5 && (error.stage === "read" || error.stage === "verify") && paths.some((path5) => resolve3(path5) === error.path);
|
|
12722
|
+
}
|
|
12723
|
+
function isWindowsAccessDeniedCreate(error, paths, stage) {
|
|
12724
|
+
return error instanceof PrivateFileError && error.reason === "io-error" && error.win32Code === 5 && error.stage === stage && paths.some((path5) => resolve3(path5) === error.path);
|
|
12725
|
+
}
|
|
12726
|
+
async function readLockRecord(path5, read) {
|
|
12727
|
+
try {
|
|
12728
|
+
return await read();
|
|
12729
|
+
} catch (error) {
|
|
12730
|
+
if (!isWindowsAccessDeniedRead(error, [path5]))
|
|
12731
|
+
throw error;
|
|
12732
|
+
try {
|
|
12733
|
+
return await read();
|
|
12734
|
+
} catch (recheckError) {
|
|
12735
|
+
if (recheckError.code === "ENOENT")
|
|
12736
|
+
throw new DisappearedLockRecordError(path5, error);
|
|
12737
|
+
throw error;
|
|
12738
|
+
}
|
|
12739
|
+
}
|
|
12740
|
+
}
|
|
12741
|
+
var DisappearedLockRecordError;
|
|
12742
|
+
var init_lock_record = __esm({
|
|
12743
|
+
"../core/dist/common-auth-embedded/fs/lock-record.js"() {
|
|
12744
|
+
"use strict";
|
|
12745
|
+
init_private_files();
|
|
12746
|
+
DisappearedLockRecordError = class extends Error {
|
|
12747
|
+
path;
|
|
12748
|
+
code = "ENOENT";
|
|
12749
|
+
constructor(path5, cause) {
|
|
12750
|
+
super(`Lock record disappeared: ${path5}`, { cause });
|
|
12751
|
+
this.path = path5;
|
|
12752
|
+
}
|
|
12753
|
+
};
|
|
12754
|
+
}
|
|
12755
|
+
});
|
|
12756
|
+
|
|
12661
12757
|
// ../core/dist/common-auth-embedded/fs/refresh-file-lock.js
|
|
12662
12758
|
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
12663
12759
|
import { link as link2, lstat as lstat3, mkdir as mkdir7, open as open4, readFile as readFile5, rename as rename6, rm as rm4, stat as stat3 } from "node:fs/promises";
|
|
@@ -12740,8 +12836,8 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
12740
12836
|
let releaseConfirmed = false;
|
|
12741
12837
|
let loss;
|
|
12742
12838
|
let resolveLoss;
|
|
12743
|
-
const lostPromise = new Promise((
|
|
12744
|
-
resolveLoss =
|
|
12839
|
+
const lostPromise = new Promise((resolve29) => {
|
|
12840
|
+
resolveLoss = resolve29;
|
|
12745
12841
|
});
|
|
12746
12842
|
function notifyTimerStep(event) {
|
|
12747
12843
|
try {
|
|
@@ -12779,15 +12875,18 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
12779
12875
|
const evictOwnerId = randomUUID9();
|
|
12780
12876
|
const EVICT_TTL = 5e3;
|
|
12781
12877
|
const MAX_STEAL_ATTEMPTS = 8;
|
|
12878
|
+
function isChangingLockCreate(error) {
|
|
12879
|
+
return windowsPrivateFiles && (isWindowsAccessDeniedCreate(error, [lockPath], "create") || isWindowsAccessDeniedCreate(error, [evictPath], "directory-create"));
|
|
12880
|
+
}
|
|
12782
12881
|
async function readOwner() {
|
|
12783
12882
|
if (windowsPrivateFiles) {
|
|
12784
12883
|
try {
|
|
12785
|
-
return JSON.parse(await readPrivateText(lockPath, true));
|
|
12884
|
+
return JSON.parse(await readLockRecord(lockPath, () => readPrivateText(lockPath, true)));
|
|
12786
12885
|
} catch (error) {
|
|
12787
12886
|
if (error.code !== "EISDIR" && error.reason !== "wrong-kind")
|
|
12788
12887
|
throw error;
|
|
12789
|
-
await verifyPrivate(lockPath, "directory", true);
|
|
12790
|
-
return JSON.parse(await readPrivateText(legacyOwnerPath, true));
|
|
12888
|
+
await readLockRecord(lockPath, () => verifyPrivate(lockPath, "directory", true));
|
|
12889
|
+
return JSON.parse(await readLockRecord(legacyOwnerPath, () => readPrivateText(legacyOwnerPath, true)));
|
|
12791
12890
|
}
|
|
12792
12891
|
}
|
|
12793
12892
|
try {
|
|
@@ -12863,8 +12962,8 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
12863
12962
|
await options.onStep("lease-contention-read-ready");
|
|
12864
12963
|
try {
|
|
12865
12964
|
if (code2 === "EISDIR") {
|
|
12866
|
-
await verifyPrivate(lockPath, "directory", true);
|
|
12867
|
-
await readPrivateText(legacyOwnerPath, true);
|
|
12965
|
+
await readLockRecord(lockPath, () => verifyPrivate(lockPath, "directory", true));
|
|
12966
|
+
await readLockRecord(legacyOwnerPath, () => readPrivateText(legacyOwnerPath, true));
|
|
12868
12967
|
} else
|
|
12869
12968
|
await readOwner();
|
|
12870
12969
|
} catch (readError) {
|
|
@@ -12902,7 +13001,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
12902
13001
|
}
|
|
12903
13002
|
}
|
|
12904
13003
|
async function backoff() {
|
|
12905
|
-
await new Promise((
|
|
13004
|
+
await new Promise((resolve29) => setTimeout(resolve29, Math.floor(Math.random() * 4)));
|
|
12906
13005
|
}
|
|
12907
13006
|
async function readLockState(notifyReady = true) {
|
|
12908
13007
|
if (notifyReady && options.onStep)
|
|
@@ -12911,6 +13010,8 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
12911
13010
|
try {
|
|
12912
13011
|
owner = await readOwner();
|
|
12913
13012
|
} catch (error) {
|
|
13013
|
+
if (error instanceof DisappearedLockRecordError)
|
|
13014
|
+
return { status: "missing" };
|
|
12914
13015
|
if (windowsPrivateFiles && error.code !== "ENOENT")
|
|
12915
13016
|
throw error;
|
|
12916
13017
|
}
|
|
@@ -12958,7 +13059,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
12958
13059
|
}
|
|
12959
13060
|
async function ownsEvictionMarker() {
|
|
12960
13061
|
try {
|
|
12961
|
-
const owner = JSON.parse(await readPrivateText(evictOwnerPath, windowsPrivateFiles));
|
|
13062
|
+
const owner = JSON.parse(await readLockRecord(evictOwnerPath, () => readPrivateText(evictOwnerPath, windowsPrivateFiles)));
|
|
12962
13063
|
return owner?.ownerId === evictOwnerId;
|
|
12963
13064
|
} catch (error) {
|
|
12964
13065
|
if (windowsPrivateFiles && error.code !== "ENOENT")
|
|
@@ -12993,7 +13094,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
12993
13094
|
const remainingMs = deadline - performance.now();
|
|
12994
13095
|
if (remainingMs <= 0)
|
|
12995
13096
|
throw original;
|
|
12996
|
-
await new Promise((
|
|
13097
|
+
await new Promise((resolve29) => setTimeout(resolve29, Math.min(delayMs, remainingMs)));
|
|
12997
13098
|
if (performance.now() >= deadline)
|
|
12998
13099
|
throw original;
|
|
12999
13100
|
delayMs = Math.min(delayMs * 2, 50);
|
|
@@ -13097,7 +13198,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13097
13198
|
}
|
|
13098
13199
|
if (windowsPrivateFiles) {
|
|
13099
13200
|
try {
|
|
13100
|
-
await verifyPrivate(evictPath, "directory", true);
|
|
13201
|
+
await readLockRecord(evictPath, () => verifyPrivate(evictPath, "directory", true));
|
|
13101
13202
|
} catch (error) {
|
|
13102
13203
|
if (error.code === "ENOENT")
|
|
13103
13204
|
return "missing";
|
|
@@ -13152,8 +13253,8 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13152
13253
|
if (error.code === "EEXIST") {
|
|
13153
13254
|
if (windowsPrivateFiles) {
|
|
13154
13255
|
try {
|
|
13155
|
-
await verifyPrivate(evictPath, "directory", true);
|
|
13156
|
-
await readPrivateText(evictOwnerPath, true);
|
|
13256
|
+
await readLockRecord(evictPath, () => verifyPrivate(evictPath, "directory", true));
|
|
13257
|
+
await readLockRecord(evictOwnerPath, () => readPrivateText(evictOwnerPath, true));
|
|
13157
13258
|
} catch (ownerError) {
|
|
13158
13259
|
if (ownerError.code !== "ENOENT")
|
|
13159
13260
|
throw ownerError;
|
|
@@ -13174,7 +13275,11 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13174
13275
|
try {
|
|
13175
13276
|
await releaseEvictionMarker(deadline);
|
|
13176
13277
|
} catch (error) {
|
|
13177
|
-
if (isRetryableRemoval(actionError, lockPath)
|
|
13278
|
+
if ((isRetryableRemoval(actionError, lockPath) || isWindowsAccessDeniedRead(actionError, [
|
|
13279
|
+
lockPath,
|
|
13280
|
+
legacyOwnerPath,
|
|
13281
|
+
evictOwnerPath
|
|
13282
|
+
])) && (isRetryableRemoval(error, evictPath) || isWindowsAccessDeniedRead(error, [evictOwnerPath])))
|
|
13178
13283
|
throw actionError;
|
|
13179
13284
|
throw error;
|
|
13180
13285
|
}
|
|
@@ -13190,7 +13295,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13190
13295
|
try {
|
|
13191
13296
|
owner = await readOwner();
|
|
13192
13297
|
} catch (error) {
|
|
13193
|
-
if (windowsPrivateFiles)
|
|
13298
|
+
if (windowsPrivateFiles && !(error instanceof DisappearedLockRecordError))
|
|
13194
13299
|
throw error;
|
|
13195
13300
|
return;
|
|
13196
13301
|
}
|
|
@@ -13268,7 +13373,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13268
13373
|
await options.onStep("renewal-marker-unavailable");
|
|
13269
13374
|
}
|
|
13270
13375
|
} catch (error) {
|
|
13271
|
-
if (windowsPrivateFiles && error instanceof PrivateFileError) {
|
|
13376
|
+
if (windowsPrivateFiles && error instanceof PrivateFileError && !isChangingLockCreate(error)) {
|
|
13272
13377
|
terminalIOError = error;
|
|
13273
13378
|
recordLoss("renewal-failed");
|
|
13274
13379
|
shouldReschedule = false;
|
|
@@ -13314,72 +13419,90 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13314
13419
|
}
|
|
13315
13420
|
return null;
|
|
13316
13421
|
}
|
|
13317
|
-
let acquired =
|
|
13422
|
+
let acquired = false;
|
|
13423
|
+
let changingCreateError;
|
|
13424
|
+
try {
|
|
13425
|
+
acquired = await tryAcquire();
|
|
13426
|
+
} catch (error) {
|
|
13427
|
+
if (!isChangingLockCreate(error))
|
|
13428
|
+
throw error;
|
|
13429
|
+
changingCreateError = error;
|
|
13430
|
+
}
|
|
13318
13431
|
if (!acquired) {
|
|
13319
13432
|
for (let attempt = 0; attempt < MAX_STEAL_ATTEMPTS; attempt++) {
|
|
13320
|
-
acquired = await tryAcquire();
|
|
13321
|
-
if (acquired)
|
|
13322
|
-
break;
|
|
13323
|
-
const observed = await readLockState();
|
|
13324
|
-
if (observed.status === "live")
|
|
13325
|
-
return contended();
|
|
13326
|
-
if (observed.status === "missing")
|
|
13327
|
-
continue;
|
|
13328
|
-
if (options.onStep)
|
|
13329
|
-
await options.onStep("stale-lock-observed");
|
|
13330
|
-
try {
|
|
13331
|
-
if (!await tryAcquireEvictionMarker()) {
|
|
13332
|
-
await backoff();
|
|
13333
|
-
continue;
|
|
13334
|
-
}
|
|
13335
|
-
} catch (evictError) {
|
|
13336
|
-
const code2 = evictError.code;
|
|
13337
|
-
if (code2 !== "EEXIST")
|
|
13338
|
-
throw evictError;
|
|
13339
|
-
const recovered = await recoverStaleEvictionMarker();
|
|
13340
|
-
if (recovered === "fresh")
|
|
13341
|
-
return null;
|
|
13342
|
-
await backoff();
|
|
13343
|
-
continue;
|
|
13344
|
-
}
|
|
13345
13433
|
try {
|
|
13346
|
-
|
|
13347
|
-
if (
|
|
13434
|
+
acquired = await tryAcquire();
|
|
13435
|
+
if (acquired)
|
|
13436
|
+
break;
|
|
13437
|
+
const observed = await readLockState();
|
|
13438
|
+
if (observed.status === "live")
|
|
13348
13439
|
return contended();
|
|
13349
|
-
if (
|
|
13440
|
+
if (observed.status === "missing")
|
|
13350
13441
|
continue;
|
|
13351
|
-
if (!await ownsEvictionMarker())
|
|
13352
|
-
return null;
|
|
13353
13442
|
if (options.onStep)
|
|
13354
|
-
await options.onStep("stale-lock-
|
|
13355
|
-
|
|
13356
|
-
|
|
13357
|
-
|
|
13358
|
-
|
|
13443
|
+
await options.onStep("stale-lock-observed");
|
|
13444
|
+
try {
|
|
13445
|
+
if (!await tryAcquireEvictionMarker()) {
|
|
13446
|
+
await backoff();
|
|
13447
|
+
continue;
|
|
13448
|
+
}
|
|
13449
|
+
} catch (evictError) {
|
|
13450
|
+
const code2 = evictError.code;
|
|
13451
|
+
if (code2 !== "EEXIST")
|
|
13452
|
+
throw evictError;
|
|
13453
|
+
const recovered = await recoverStaleEvictionMarker();
|
|
13454
|
+
if (recovered === "fresh")
|
|
13455
|
+
return null;
|
|
13456
|
+
await backoff();
|
|
13359
13457
|
continue;
|
|
13360
|
-
await removeLeaseObject(lockPath);
|
|
13361
|
-
if (!await ownsEvictionMarker())
|
|
13362
|
-
return null;
|
|
13363
|
-
if (options.onStep)
|
|
13364
|
-
await options.onStep("stale-lock-removed");
|
|
13365
|
-
acquired = await tryAcquire();
|
|
13366
|
-
if (!acquired)
|
|
13367
|
-
return null;
|
|
13368
|
-
if (options.onStep)
|
|
13369
|
-
await options.onStep("stale-lock-recreated");
|
|
13370
|
-
if (!await ownsEvictionMarker()) {
|
|
13371
|
-
await relinquishLockAfterMarkerLoss();
|
|
13372
|
-
acquired = false;
|
|
13373
|
-
return null;
|
|
13374
13458
|
}
|
|
13375
|
-
|
|
13376
|
-
|
|
13377
|
-
|
|
13459
|
+
try {
|
|
13460
|
+
const confirmed = await readLockState();
|
|
13461
|
+
if (confirmed.status === "live")
|
|
13462
|
+
return contended();
|
|
13463
|
+
if (!sameStaleLock(observed.identity, confirmed))
|
|
13464
|
+
continue;
|
|
13465
|
+
if (!await ownsEvictionMarker())
|
|
13466
|
+
return null;
|
|
13467
|
+
if (options.onStep)
|
|
13468
|
+
await options.onStep("stale-lock-confirmed");
|
|
13469
|
+
if (!await ownsEvictionMarker())
|
|
13470
|
+
return null;
|
|
13471
|
+
const current = await readLockState(false);
|
|
13472
|
+
if (!sameStaleLock(observed.identity, current))
|
|
13473
|
+
continue;
|
|
13474
|
+
await removeLeaseObject(lockPath);
|
|
13475
|
+
if (!await ownsEvictionMarker())
|
|
13476
|
+
return null;
|
|
13477
|
+
if (options.onStep)
|
|
13478
|
+
await options.onStep("stale-lock-removed");
|
|
13479
|
+
acquired = await tryAcquire();
|
|
13480
|
+
if (!acquired)
|
|
13481
|
+
return null;
|
|
13482
|
+
if (options.onStep)
|
|
13483
|
+
await options.onStep("stale-lock-recreated");
|
|
13484
|
+
if (!await ownsEvictionMarker()) {
|
|
13485
|
+
await relinquishLockAfterMarkerLoss();
|
|
13486
|
+
acquired = false;
|
|
13487
|
+
return null;
|
|
13488
|
+
}
|
|
13489
|
+
break;
|
|
13490
|
+
} finally {
|
|
13491
|
+
await releaseEvictionMarker();
|
|
13492
|
+
}
|
|
13493
|
+
} catch (error) {
|
|
13494
|
+
if (!isChangingLockCreate(error))
|
|
13495
|
+
throw error;
|
|
13496
|
+
changingCreateError ??= error;
|
|
13497
|
+
await backoff();
|
|
13378
13498
|
}
|
|
13379
13499
|
}
|
|
13380
13500
|
}
|
|
13381
|
-
if (!acquired)
|
|
13501
|
+
if (!acquired) {
|
|
13502
|
+
if (changingCreateError)
|
|
13503
|
+
throw changingCreateError;
|
|
13382
13504
|
return null;
|
|
13505
|
+
}
|
|
13383
13506
|
scheduleRenewal();
|
|
13384
13507
|
return {
|
|
13385
13508
|
ownerId,
|
|
@@ -13417,6 +13540,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13417
13540
|
const deadline = performance.now() + EVICT_TTL + 1e3;
|
|
13418
13541
|
let delayMs = 5;
|
|
13419
13542
|
let removalError;
|
|
13543
|
+
let changingRecordError;
|
|
13420
13544
|
for (; ; ) {
|
|
13421
13545
|
try {
|
|
13422
13546
|
let removalConfirmed = false;
|
|
@@ -13442,6 +13566,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13442
13566
|
await removeLeaseObject(lockPath);
|
|
13443
13567
|
removalConfirmed = true;
|
|
13444
13568
|
}, deadline);
|
|
13569
|
+
changingRecordError = void 0;
|
|
13445
13570
|
if (markerAcquired) {
|
|
13446
13571
|
if (windowsPrivateFiles && !removalConfirmed)
|
|
13447
13572
|
throw new PrivateFileError(lockPath, "release-not-confirmed", {
|
|
@@ -13454,23 +13579,32 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13454
13579
|
return;
|
|
13455
13580
|
await recoverStaleEvictionMarker(deadline);
|
|
13456
13581
|
} catch (error) {
|
|
13457
|
-
|
|
13582
|
+
const changingRecord = windowsPrivateFiles && (isChangingLockCreate(error) || isWindowsAccessDeniedRead(error, [
|
|
13583
|
+
lockPath,
|
|
13584
|
+
legacyOwnerPath,
|
|
13585
|
+
evictPath,
|
|
13586
|
+
evictOwnerPath
|
|
13587
|
+
]));
|
|
13588
|
+
if (!isRetryableRemoval(error, lockPath) && !changingRecord) {
|
|
13458
13589
|
if (windowsPrivateFiles)
|
|
13459
13590
|
throw error;
|
|
13460
13591
|
return;
|
|
13461
13592
|
}
|
|
13462
|
-
|
|
13593
|
+
if (changingRecord)
|
|
13594
|
+
changingRecordError ??= error;
|
|
13595
|
+
else
|
|
13596
|
+
removalError ??= error;
|
|
13463
13597
|
}
|
|
13464
13598
|
const remainingMs = deadline - performance.now();
|
|
13465
13599
|
if (remainingMs <= 0)
|
|
13466
13600
|
break;
|
|
13467
|
-
await new Promise((
|
|
13601
|
+
await new Promise((resolve29) => setTimeout(resolve29, Math.min(delayMs, remainingMs)));
|
|
13468
13602
|
if (windowsPrivateFiles && performance.now() >= deadline)
|
|
13469
13603
|
break;
|
|
13470
13604
|
delayMs = Math.min(delayMs * 2, 50);
|
|
13471
13605
|
}
|
|
13472
13606
|
if (windowsPrivateFiles)
|
|
13473
|
-
throw removalError ?? new PrivateFileError(lockPath, "release-not-confirmed", {
|
|
13607
|
+
throw changingRecordError ?? removalError ?? new PrivateFileError(lockPath, "release-not-confirmed", {
|
|
13474
13608
|
code: "ETIMEDOUT"
|
|
13475
13609
|
});
|
|
13476
13610
|
}
|
|
@@ -13480,6 +13614,7 @@ var leaseCreationTestHooks, setRefreshLockRenewalTimeout, clearRefreshLockRenewa
|
|
|
13480
13614
|
var init_refresh_file_lock = __esm({
|
|
13481
13615
|
"../core/dist/common-auth-embedded/fs/refresh-file-lock.js"() {
|
|
13482
13616
|
"use strict";
|
|
13617
|
+
init_lock_record();
|
|
13483
13618
|
init_private_files();
|
|
13484
13619
|
init_with_lock();
|
|
13485
13620
|
setRefreshLockRenewalTimeout = globalThis.setTimeout.bind(globalThis);
|
|
@@ -13489,22 +13624,21 @@ var init_refresh_file_lock = __esm({
|
|
|
13489
13624
|
});
|
|
13490
13625
|
|
|
13491
13626
|
// ../core/dist/common-auth-embedded/fs/with-lock.js
|
|
13492
|
-
import { join as join6, resolve as
|
|
13627
|
+
import { join as join6, resolve as resolve4 } from "node:path";
|
|
13493
13628
|
function lockPathFor(target, name) {
|
|
13494
13629
|
return `${target}.${name}.lock`;
|
|
13495
13630
|
}
|
|
13496
|
-
function
|
|
13497
|
-
|
|
13498
|
-
|
|
13499
|
-
|
|
13500
|
-
return error.path === path5 || error.path === join6(path5, "owner.json");
|
|
13631
|
+
function isChangingLockRecord(error, target, name) {
|
|
13632
|
+
const path5 = resolve4(lockPathFor(target, name));
|
|
13633
|
+
const paths = [path5, join6(path5, "owner.json")];
|
|
13634
|
+
return (isWindowsSharingViolation(error) || isWindowsAccessDeniedRead(error, paths)) && (error.stage === "read" || error.stage === "verify") && paths.includes(error.path) || windowsPrivateFiles && (isWindowsAccessDeniedCreate(error, [path5], "create") || isWindowsAccessDeniedCreate(error, [`${path5}.evicting`], "directory-create"));
|
|
13501
13635
|
}
|
|
13502
13636
|
async function withLock(target, options, fn) {
|
|
13503
13637
|
const started = performance.now();
|
|
13638
|
+
let changingRecordError;
|
|
13504
13639
|
for (; ; ) {
|
|
13505
13640
|
options.signal?.throwIfAborted();
|
|
13506
13641
|
let lock;
|
|
13507
|
-
let changingReadError;
|
|
13508
13642
|
try {
|
|
13509
13643
|
lock = await acquireRefreshFileLock({
|
|
13510
13644
|
path: target,
|
|
@@ -13514,11 +13648,12 @@ async function withLock(target, options, fn) {
|
|
|
13514
13648
|
...options.onStep ? { onStep: options.onStep } : {},
|
|
13515
13649
|
...options.onRenewalTimer ? { onRenewalTimer: options.onRenewalTimer } : {}
|
|
13516
13650
|
});
|
|
13651
|
+
changingRecordError = void 0;
|
|
13517
13652
|
} catch (error) {
|
|
13518
|
-
if (!
|
|
13653
|
+
if (!isChangingLockRecord(error, target, options.name))
|
|
13519
13654
|
throw error;
|
|
13520
13655
|
lock = null;
|
|
13521
|
-
|
|
13656
|
+
changingRecordError ??= error;
|
|
13522
13657
|
}
|
|
13523
13658
|
if (lock) {
|
|
13524
13659
|
try {
|
|
@@ -13530,21 +13665,22 @@ async function withLock(target, options, fn) {
|
|
|
13530
13665
|
}
|
|
13531
13666
|
const remaining = options.timeoutMs - (performance.now() - started);
|
|
13532
13667
|
if (remaining <= 0) {
|
|
13533
|
-
if (
|
|
13534
|
-
throw
|
|
13668
|
+
if (changingRecordError)
|
|
13669
|
+
throw changingRecordError;
|
|
13535
13670
|
throw new LockContentionError({
|
|
13536
13671
|
target,
|
|
13537
13672
|
name: options.name,
|
|
13538
13673
|
timeoutMs: options.timeoutMs
|
|
13539
13674
|
});
|
|
13540
13675
|
}
|
|
13541
|
-
await new Promise((
|
|
13676
|
+
await new Promise((resolve29) => setTimeout(resolve29, Math.min(25, Math.ceil(remaining))));
|
|
13542
13677
|
}
|
|
13543
13678
|
}
|
|
13544
13679
|
var LockContentionError, LockOwnershipError;
|
|
13545
13680
|
var init_with_lock = __esm({
|
|
13546
13681
|
"../core/dist/common-auth-embedded/fs/with-lock.js"() {
|
|
13547
13682
|
"use strict";
|
|
13683
|
+
init_lock_record();
|
|
13548
13684
|
init_private_files();
|
|
13549
13685
|
init_refresh_file_lock();
|
|
13550
13686
|
LockContentionError = class extends Error {
|
|
@@ -13627,7 +13763,7 @@ async function acquirePoolLock(spec, defaults, env3) {
|
|
|
13627
13763
|
});
|
|
13628
13764
|
}
|
|
13629
13765
|
const jitter = Math.floor(Math.random() * (options.retryMs + 1));
|
|
13630
|
-
await new Promise((
|
|
13766
|
+
await new Promise((resolve29) => setTimeout(resolve29, Math.min(options.retryMs + jitter, remaining)));
|
|
13631
13767
|
}
|
|
13632
13768
|
}
|
|
13633
13769
|
function definedOnly(spec) {
|
|
@@ -16521,7 +16657,7 @@ var init_redact = __esm({
|
|
|
16521
16657
|
// ../core/dist/common-auth-embedded/logger/engine.js
|
|
16522
16658
|
import { appendFileSync, chmodSync, existsSync, renameSync, statSync } from "node:fs";
|
|
16523
16659
|
import { open as open5 } from "node:fs/promises";
|
|
16524
|
-
import { dirname as dirname8, resolve as
|
|
16660
|
+
import { dirname as dirname8, resolve as resolve5 } from "node:path";
|
|
16525
16661
|
function chmodPrivate(path5) {
|
|
16526
16662
|
try {
|
|
16527
16663
|
chmodSync(path5, 384);
|
|
@@ -16572,7 +16708,7 @@ async function openWindowsFile(sink, file) {
|
|
|
16572
16708
|
return sink.handle;
|
|
16573
16709
|
}
|
|
16574
16710
|
async function flushWindowsFile(sink, file, text2) {
|
|
16575
|
-
file =
|
|
16711
|
+
file = resolve5(file);
|
|
16576
16712
|
try {
|
|
16577
16713
|
if (sink.file !== file)
|
|
16578
16714
|
await closeWindowsFile(sink);
|
|
@@ -16948,11 +17084,11 @@ var init_quota_writer = __esm({
|
|
|
16948
17084
|
const left = deadline - performance.now();
|
|
16949
17085
|
if (left <= 0)
|
|
16950
17086
|
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);
|
|
16951
|
-
await new Promise((
|
|
17087
|
+
await new Promise((resolve29) => {
|
|
16952
17088
|
const done = () => {
|
|
16953
17089
|
clearTimeout(timer);
|
|
16954
17090
|
this.wake.delete(done);
|
|
16955
|
-
|
|
17091
|
+
resolve29();
|
|
16956
17092
|
};
|
|
16957
17093
|
const timer = setTimeout(done, left);
|
|
16958
17094
|
this.wake.add(done);
|
|
@@ -17345,7 +17481,7 @@ var init_refresh = __esm({
|
|
|
17345
17481
|
|
|
17346
17482
|
// ../core/dist/common-auth-embedded/fs/file-read-cache.js
|
|
17347
17483
|
import { lstat as lstat4, stat as stat4 } from "node:fs/promises";
|
|
17348
|
-
import { resolve as
|
|
17484
|
+
import { resolve as resolve6 } from "node:path";
|
|
17349
17485
|
async function identity(path5, followSymlinks) {
|
|
17350
17486
|
try {
|
|
17351
17487
|
const metadata = await (followSymlinks ? stat4(path5) : lstat4(path5));
|
|
@@ -17370,7 +17506,7 @@ var init_file_read_cache = __esm({
|
|
|
17370
17506
|
this.#followSymlinks = options.followSymlinks ?? false;
|
|
17371
17507
|
}
|
|
17372
17508
|
async read(paths, read, validateHit) {
|
|
17373
|
-
const resolvedPaths = paths.map((path5) =>
|
|
17509
|
+
const resolvedPaths = paths.map((path5) => resolve6(path5));
|
|
17374
17510
|
const key = JSON.stringify(resolvedPaths);
|
|
17375
17511
|
const probed = await Promise.all(resolvedPaths.map((path5) => identity(path5, this.#followSymlinks)));
|
|
17376
17512
|
const identities = probed.every((entry) => entry !== void 0) ? probed : void 0;
|
|
@@ -19559,9 +19695,17 @@ var init_availability = __esm({
|
|
|
19559
19695
|
ERR_PRIVATE_FILES_SECURITY: "answered"
|
|
19560
19696
|
});
|
|
19561
19697
|
ClaustrumUnreachableError = class extends ClaustrumConsumerError {
|
|
19562
|
-
|
|
19698
|
+
/**
|
|
19699
|
+
* Non-secret host connection diagnostic. A missing accessor can recover
|
|
19700
|
+
* once the host bridge installs; a failed accessor could not provide a client.
|
|
19701
|
+
* Other unreachable failures leave this unset. Never use adapter error text.
|
|
19702
|
+
*/
|
|
19703
|
+
reason;
|
|
19704
|
+
constructor(reason) {
|
|
19563
19705
|
super("unavailable", "Claustrum scoped operation unavailable");
|
|
19564
19706
|
this.name = "ClaustrumUnreachableError";
|
|
19707
|
+
if (reason === "host-accessor-missing" || reason === "host-accessor-failed")
|
|
19708
|
+
this.reason = reason;
|
|
19565
19709
|
}
|
|
19566
19710
|
};
|
|
19567
19711
|
}
|
|
@@ -19582,7 +19726,7 @@ function hostError(error) {
|
|
|
19582
19726
|
if (typeof value.code === "string" && (value.class === "transient" || value.class === "permanent" || value.class === "auth_required" || value.class === "context_overflow") && (value.action === "gone" || value.action === "reauth" || value.action === "retry" || value.action === "reduce_and_retry"))
|
|
19583
19727
|
return new ClaustrumCredentialError2(value.code, value.class, value.action);
|
|
19584
19728
|
if (value.name === "ClaustrumUnreachableError" || typeof value.code === "string" && classifyVaultFailure(Object.assign(new Error(), { code: value.code })) === "unreachable")
|
|
19585
|
-
return new ClaustrumUnreachableError();
|
|
19729
|
+
return new ClaustrumUnreachableError(value.reason === "host-accessor-missing" || value.reason === "host-accessor-failed" ? value.reason : void 0);
|
|
19586
19730
|
return error;
|
|
19587
19731
|
}
|
|
19588
19732
|
function call(operation) {
|
|
@@ -19648,14 +19792,15 @@ function connectVaultHost(pluginId) {
|
|
|
19648
19792
|
throw new ClaustrumUnreachableError();
|
|
19649
19793
|
try {
|
|
19650
19794
|
const accessor = globalThis[/* @__PURE__ */ Symbol.for("cortexkit.vault")];
|
|
19651
|
-
if (typeof accessor
|
|
19652
|
-
|
|
19653
|
-
|
|
19654
|
-
|
|
19655
|
-
|
|
19795
|
+
if (typeof accessor === "function") {
|
|
19796
|
+
const client = wrapHostClient(accessor(pluginId));
|
|
19797
|
+
hostClients.add(client);
|
|
19798
|
+
return client;
|
|
19799
|
+
}
|
|
19656
19800
|
} catch {
|
|
19657
|
-
throw new ClaustrumUnreachableError();
|
|
19801
|
+
throw new ClaustrumUnreachableError("host-accessor-failed");
|
|
19658
19802
|
}
|
|
19803
|
+
throw new ClaustrumUnreachableError("host-accessor-missing");
|
|
19659
19804
|
}
|
|
19660
19805
|
var VAULT_HOST_STATUS, VAULT_HOST_CONNECT_REFUSAL, hostClients;
|
|
19661
19806
|
var init_host = __esm({
|
|
@@ -19991,7 +20136,7 @@ async function select(terminal, items, options) {
|
|
|
19991
20136
|
writeLine("");
|
|
19992
20137
|
renderedLines = lines;
|
|
19993
20138
|
};
|
|
19994
|
-
return new Promise((
|
|
20139
|
+
return new Promise((resolve29) => {
|
|
19995
20140
|
const wasRaw = stdin.isRaw ?? false;
|
|
19996
20141
|
const cleanup2 = () => {
|
|
19997
20142
|
if (cleaned)
|
|
@@ -20011,7 +20156,7 @@ async function select(terminal, items, options) {
|
|
|
20011
20156
|
};
|
|
20012
20157
|
const finish = (value) => {
|
|
20013
20158
|
cleanup2();
|
|
20014
|
-
|
|
20159
|
+
resolve29(value);
|
|
20015
20160
|
};
|
|
20016
20161
|
const onSignal = () => finish(null);
|
|
20017
20162
|
const onKey = (data) => {
|
|
@@ -20051,7 +20196,7 @@ async function select(terminal, items, options) {
|
|
|
20051
20196
|
stdin.setRawMode(true);
|
|
20052
20197
|
} catch {
|
|
20053
20198
|
cleanup2();
|
|
20054
|
-
|
|
20199
|
+
resolve29(null);
|
|
20055
20200
|
return;
|
|
20056
20201
|
}
|
|
20057
20202
|
stdin.resume();
|
|
@@ -20787,7 +20932,7 @@ var init_watch = __esm({
|
|
|
20787
20932
|
});
|
|
20788
20933
|
|
|
20789
20934
|
// ../core/dist/common-auth-embedded/claustrum/insula.js
|
|
20790
|
-
import { resolve as
|
|
20935
|
+
import { resolve as resolve7 } from "node:path";
|
|
20791
20936
|
import { storeIdentity } from "@cortexkit/claustrum-client";
|
|
20792
20937
|
import { SubcClient } from "@cortexkit/subc-client";
|
|
20793
20938
|
function insulaUsageTransport(options) {
|
|
@@ -20915,8 +21060,8 @@ function refusalCode(error) {
|
|
|
20915
21060
|
}
|
|
20916
21061
|
function acquireInsulaQuotaSource(transport, tokenPath) {
|
|
20917
21062
|
const key = JSON.stringify([
|
|
20918
|
-
|
|
20919
|
-
|
|
21063
|
+
resolve7(transport.connectionFile),
|
|
21064
|
+
resolve7(tokenPath)
|
|
20920
21065
|
]);
|
|
20921
21066
|
let shared3 = sources.get(key);
|
|
20922
21067
|
if (!shared3) {
|
|
@@ -21230,7 +21375,7 @@ var init_any_signal = __esm({
|
|
|
21230
21375
|
import { createHash as createHash6, randomBytes as randomBytes4, randomUUID as randomUUID12 } from "node:crypto";
|
|
21231
21376
|
import { constants as fsConstants } from "node:fs";
|
|
21232
21377
|
import { chmod as chmod2, mkdir as mkdir8, open as open6, readFile as readFile6, realpath as realpath3, rename as rename7, stat as stat5, unlink as unlink6 } from "node:fs/promises";
|
|
21233
|
-
import { basename as basename3, dirname as dirname9, extname, isAbsolute as isAbsolute2, join as join7, resolve as
|
|
21378
|
+
import { basename as basename3, dirname as dirname9, extname, isAbsolute as isAbsolute2, join as join7, resolve as resolve8 } from "node:path";
|
|
21234
21379
|
import { ClaustrumCredentialError as ClaustrumCredentialError3, ClaustrumClient as ClaustrumWireClient, writeEnrollmentTokenFile } from "@cortexkit/claustrum-client";
|
|
21235
21380
|
function classifyEnrollmentError(error) {
|
|
21236
21381
|
if (!(error instanceof ClaustrumCredentialError3))
|
|
@@ -21249,6 +21394,10 @@ function enrollmentName(plugin, host) {
|
|
|
21249
21394
|
throw new ClaustrumConsumerError("invalid-state", "Claustrum enrollment names use lowercase letters, digits and dashes");
|
|
21250
21395
|
return `${plugin}-${host}`;
|
|
21251
21396
|
}
|
|
21397
|
+
function validEnrollmentDisplayName(displayName) {
|
|
21398
|
+
const length = Array.from(displayName).length;
|
|
21399
|
+
return length >= 1 && length <= 40 && !/[\p{Cc}\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069\u200b-\u200d\u2060\ufeff]/u.test(displayName);
|
|
21400
|
+
}
|
|
21252
21401
|
function connectClaustrumEnrollmentClient(options) {
|
|
21253
21402
|
return ClaustrumWireClient.connect(options);
|
|
21254
21403
|
}
|
|
@@ -21264,7 +21413,7 @@ function hostEnrollmentPaths(input2) {
|
|
|
21264
21413
|
const override = input2.override?.trim();
|
|
21265
21414
|
if (override && !isAbsolute2(override) && !input2.cwd)
|
|
21266
21415
|
throw new ClaustrumConsumerError("invalid-state", "A relative Claustrum enrollment override needs a base directory");
|
|
21267
|
-
const tokenPath = override ? isAbsolute2(override) ? override :
|
|
21416
|
+
const tokenPath = override ? isAbsolute2(override) ? override : resolve8(input2.cwd, override) : join7(input2.stateDir, `${input2.host}-enrollment.json`);
|
|
21268
21417
|
return getClaustrumEnrollmentPaths(tokenPath);
|
|
21269
21418
|
}
|
|
21270
21419
|
function isRecord6(value) {
|
|
@@ -21731,15 +21880,19 @@ var init_enrollment = __esm({
|
|
|
21731
21880
|
#client;
|
|
21732
21881
|
#paths;
|
|
21733
21882
|
#proposedName;
|
|
21883
|
+
#displayName;
|
|
21734
21884
|
#now;
|
|
21735
21885
|
#mintSecret;
|
|
21736
21886
|
#writeTokenFile;
|
|
21737
21887
|
#ancestorOptions;
|
|
21738
21888
|
constructor(options) {
|
|
21889
|
+
if (options.displayName !== void 0 && !validEnrollmentDisplayName(options.displayName))
|
|
21890
|
+
throw new ClaustrumConsumerError("invalid-state", "invalid Claustrum enrollment display name");
|
|
21739
21891
|
this.#ancestorOptions = options.ancestorOptions ?? {};
|
|
21740
21892
|
this.#client = options.client;
|
|
21741
21893
|
this.#paths = options.paths;
|
|
21742
21894
|
this.#proposedName = options.proposedName;
|
|
21895
|
+
this.#displayName = options.displayName;
|
|
21743
21896
|
this.#now = options.now ?? Date.now;
|
|
21744
21897
|
this.#mintSecret = options.mintSecret ?? (() => randomBytes4(32).toString("hex"));
|
|
21745
21898
|
this.#writeTokenFile = options.writeTokenFile ?? writeEnrollmentTokenFile;
|
|
@@ -21829,10 +21982,23 @@ var init_enrollment = __esm({
|
|
|
21829
21982
|
if (!state.requestId) {
|
|
21830
21983
|
try {
|
|
21831
21984
|
const requestSecretHash = createHash6("sha256").update(Buffer.from(state.requestSecret, "hex")).digest("hex");
|
|
21832
|
-
const
|
|
21985
|
+
const proposal = {
|
|
21833
21986
|
name: state.proposedName,
|
|
21834
21987
|
requestSecretHash
|
|
21835
|
-
}
|
|
21988
|
+
};
|
|
21989
|
+
let proposed;
|
|
21990
|
+
try {
|
|
21991
|
+
proposed = await this.#client.enrollPropose({
|
|
21992
|
+
...proposal,
|
|
21993
|
+
...this.#displayName !== void 0 && {
|
|
21994
|
+
displayName: this.#displayName
|
|
21995
|
+
}
|
|
21996
|
+
});
|
|
21997
|
+
} catch (error) {
|
|
21998
|
+
if (this.#displayName === void 0 || !(error instanceof ClaustrumCredentialError3) || error.code !== "invalid_params")
|
|
21999
|
+
throw error;
|
|
22000
|
+
proposed = await this.#client.enrollPropose(proposal);
|
|
22001
|
+
}
|
|
21836
22002
|
state = {
|
|
21837
22003
|
...state,
|
|
21838
22004
|
requestId: proposed.requestId,
|
|
@@ -21999,10 +22165,10 @@ async function drainShutdown(pending, onTimeout) {
|
|
|
21999
22165
|
try {
|
|
22000
22166
|
await Promise.race([
|
|
22001
22167
|
drained,
|
|
22002
|
-
new Promise((
|
|
22168
|
+
new Promise((resolve29) => {
|
|
22003
22169
|
timer = setTimeout(() => {
|
|
22004
22170
|
expired = true;
|
|
22005
|
-
|
|
22171
|
+
resolve29();
|
|
22006
22172
|
}, 2e3);
|
|
22007
22173
|
})
|
|
22008
22174
|
]);
|
|
@@ -22346,8 +22512,15 @@ var init_custody = __esm({
|
|
|
22346
22512
|
this.#warnShutdown = shutdownWarning(this.#logger);
|
|
22347
22513
|
this.#setTimeout = options.setTimeoutImpl ?? setTimeout;
|
|
22348
22514
|
this.#clearTimeout = options.clearTimeoutImpl ?? clearTimeout;
|
|
22515
|
+
const currentClient = () => this.#client;
|
|
22349
22516
|
this.#usage = new ScopedUsageReporter({
|
|
22350
|
-
client:
|
|
22517
|
+
client: {
|
|
22518
|
+
// Queued readings follow a replacement without losing client capability checks.
|
|
22519
|
+
get reportUsageScoped() {
|
|
22520
|
+
const client = currentClient();
|
|
22521
|
+
return client.reportUsageScoped?.bind(client);
|
|
22522
|
+
}
|
|
22523
|
+
},
|
|
22351
22524
|
owns: (id) => this.#usageServed.has(id),
|
|
22352
22525
|
token: async () => hasVaultHost() ? "" : checkedEnrollmentToken(await this.#readToken()),
|
|
22353
22526
|
logger: this.#logger,
|
|
@@ -22355,12 +22528,30 @@ var init_custody = __esm({
|
|
|
22355
22528
|
clearTimeout: this.#clearTimeout
|
|
22356
22529
|
});
|
|
22357
22530
|
}
|
|
22531
|
+
/**
|
|
22532
|
+
* Replace the connection to the same vault without discarding receipts or
|
|
22533
|
+
* their enrollment tokens. Open roster watches restart on the new client;
|
|
22534
|
+
* their existing handles remain usable. Passing the current client does nothing.
|
|
22535
|
+
* Neither client is closed here: the caller closes the old one, and custody's
|
|
22536
|
+
* close()/dispose() still closes the client it holds at shutdown.
|
|
22537
|
+
* While hosted, next must come from connectVaultHost, as in the constructor.
|
|
22538
|
+
*/
|
|
22539
|
+
replaceClient(next) {
|
|
22540
|
+
this.#check();
|
|
22541
|
+
if (next === this.#client)
|
|
22542
|
+
return;
|
|
22543
|
+
if (hasVaultHost() && !isVaultHostClient(next))
|
|
22544
|
+
throw new ClaustrumUnreachableError();
|
|
22545
|
+
this.#client = next;
|
|
22546
|
+
for (const watch of this.#watches)
|
|
22547
|
+
watch.restart();
|
|
22548
|
+
}
|
|
22358
22549
|
/** A watch losing its transport is the same outage as an unreachable read. */
|
|
22359
22550
|
transportLost(error) {
|
|
22360
22551
|
if (this.#closed || this.#outage)
|
|
22361
22552
|
return;
|
|
22362
22553
|
this.#outage = true;
|
|
22363
|
-
this.#outageError = error instanceof ClaustrumCredentialError5 ? error : new ClaustrumUnreachableError();
|
|
22554
|
+
this.#outageError = error instanceof ClaustrumCredentialError5 ? error : new ClaustrumUnreachableError(error instanceof ClaustrumUnreachableError ? error.reason : void 0);
|
|
22364
22555
|
this.#logger.warn("serving kept vault receipt", { reason: "unreachable" });
|
|
22365
22556
|
this.#scheduleProbe();
|
|
22366
22557
|
}
|
|
@@ -22458,7 +22649,7 @@ var init_custody = __esm({
|
|
|
22458
22649
|
if (error instanceof ClaustrumCredentialError5)
|
|
22459
22650
|
throw error;
|
|
22460
22651
|
if (classifyVaultFailure(error) === "unreachable")
|
|
22461
|
-
throw new ClaustrumUnreachableError();
|
|
22652
|
+
throw new ClaustrumUnreachableError(error instanceof ClaustrumUnreachableError ? error.reason : void 0);
|
|
22462
22653
|
throw new ClaustrumConsumerError("unavailable", "Claustrum scoped operation unavailable");
|
|
22463
22654
|
} finally {
|
|
22464
22655
|
removeAbortListener?.();
|
|
@@ -22674,7 +22865,7 @@ var init_custody = __esm({
|
|
|
22674
22865
|
if (kept.since === null)
|
|
22675
22866
|
kept.since = this.#now();
|
|
22676
22867
|
const attempt = Object.freeze(Object.defineProperty({ ...kept.attempt, fromKeptReceipt: true }, "accessToken", { value: kept.attempt.accessToken, enumerable: false }));
|
|
22677
|
-
this.#provenance.set(attempt, this.#provenance.get(kept.attempt) ?? { token
|
|
22868
|
+
this.#provenance.set(attempt, this.#provenance.get(kept.attempt) ?? { token });
|
|
22678
22869
|
this.#keptAttempts.set(attempt, routeId);
|
|
22679
22870
|
return attempt;
|
|
22680
22871
|
}
|
|
@@ -22735,15 +22926,15 @@ var init_custody = __esm({
|
|
|
22735
22926
|
recordVersion: served.recordVersion,
|
|
22736
22927
|
expiresAtMs
|
|
22737
22928
|
}, "accessToken", { value: accessToken, enumerable: false }));
|
|
22738
|
-
this.#provenance.set(attempt, { token
|
|
22929
|
+
this.#provenance.set(attempt, { token });
|
|
22739
22930
|
return attempt;
|
|
22740
22931
|
}
|
|
22741
22932
|
/**
|
|
22742
22933
|
* Report that a send this consumer actually made was rejected. Only a 401
|
|
22743
22934
|
* is reported (the vault refuses 429, 402 and 5xx reports), addressed by
|
|
22744
22935
|
* credential id with the exact record version that send was served, and
|
|
22745
|
-
* sent through the client
|
|
22746
|
-
* this custody did not issue is refused rather than reported.
|
|
22936
|
+
* sent through the current client with the enrollment token that authorized
|
|
22937
|
+
* it. A receipt this custody did not issue is refused rather than reported.
|
|
22747
22938
|
*/
|
|
22748
22939
|
async reportFailure(attempt, status, reporterSource) {
|
|
22749
22940
|
if (status !== 401)
|
|
@@ -22767,7 +22958,7 @@ var init_custody = __esm({
|
|
|
22767
22958
|
const pending = this.#reports.get(attempt);
|
|
22768
22959
|
if (pending)
|
|
22769
22960
|
return pending;
|
|
22770
|
-
const report = this.#call(() =>
|
|
22961
|
+
const report = this.#call(() => this.#client.reportAuthFailureScoped({
|
|
22771
22962
|
credentialId: attempt.credentialId,
|
|
22772
22963
|
enrollmentToken: provenance.token,
|
|
22773
22964
|
providerStatus: 401,
|
|
@@ -22808,34 +22999,64 @@ var init_custody = __esm({
|
|
|
22808
22999
|
*/
|
|
22809
23000
|
watchRoster(options) {
|
|
22810
23001
|
this.#check();
|
|
22811
|
-
const
|
|
22812
|
-
|
|
22813
|
-
|
|
22814
|
-
|
|
22815
|
-
|
|
22816
|
-
|
|
22817
|
-
|
|
22818
|
-
|
|
22819
|
-
|
|
22820
|
-
|
|
23002
|
+
const currentView = options.view ?? (() => this.#discoveredView);
|
|
23003
|
+
let discovering;
|
|
23004
|
+
let watch;
|
|
23005
|
+
const create = (resubscribed = false) => {
|
|
23006
|
+
const opened = new ScopedRosterWatch({
|
|
23007
|
+
client: this.#client,
|
|
23008
|
+
enrollmentToken: () => this.#token(),
|
|
23009
|
+
// Nothing observed the gap between clients, even if the view is unchanged.
|
|
23010
|
+
view: () => resubscribed ? void 0 : currentView(),
|
|
23011
|
+
discover: async (view) => {
|
|
23012
|
+
while (discovering)
|
|
23013
|
+
await discovering.catch(() => {
|
|
23014
|
+
});
|
|
23015
|
+
if (watch !== opened)
|
|
23016
|
+
return;
|
|
23017
|
+
resubscribed = false;
|
|
23018
|
+
discovering = Promise.resolve().then(() => options.onView(view));
|
|
23019
|
+
try {
|
|
23020
|
+
await discovering;
|
|
23021
|
+
} finally {
|
|
23022
|
+
discovering = void 0;
|
|
23023
|
+
}
|
|
23024
|
+
},
|
|
23025
|
+
onRefused: (error) => {
|
|
23026
|
+
this.listFailed(error);
|
|
23027
|
+
options.onRefused?.(error);
|
|
23028
|
+
},
|
|
23029
|
+
onTransportLost: () => this.transportLost(),
|
|
23030
|
+
onReachable: () => this.reachable(),
|
|
23031
|
+
onError: options.onError,
|
|
23032
|
+
onMode: options.onMode,
|
|
23033
|
+
logger: this.#logger,
|
|
23034
|
+
now: this.#now,
|
|
23035
|
+
setTimeoutImpl: this.#setTimeout,
|
|
23036
|
+
clearTimeoutImpl: this.#clearTimeout
|
|
23037
|
+
});
|
|
23038
|
+
return opened;
|
|
23039
|
+
};
|
|
23040
|
+
watch = create();
|
|
23041
|
+
const tracked = {
|
|
23042
|
+
restart: () => {
|
|
23043
|
+
const previousMode = watch.mode;
|
|
23044
|
+
watch.stop();
|
|
23045
|
+
watch = create(true);
|
|
23046
|
+
if (previousMode !== watch.mode)
|
|
23047
|
+
options.onMode?.(watch.mode);
|
|
23048
|
+
watch.start();
|
|
22821
23049
|
},
|
|
22822
|
-
|
|
22823
|
-
|
|
22824
|
-
|
|
22825
|
-
onMode: options.onMode,
|
|
22826
|
-
logger: this.#logger,
|
|
22827
|
-
now: this.#now,
|
|
22828
|
-
setTimeoutImpl: this.#setTimeout,
|
|
22829
|
-
clearTimeoutImpl: this.#clearTimeout
|
|
22830
|
-
});
|
|
22831
|
-
this.#watches.add(watch);
|
|
23050
|
+
stop: () => watch.stop()
|
|
23051
|
+
};
|
|
23052
|
+
this.#watches.add(tracked);
|
|
22832
23053
|
watch.start();
|
|
22833
23054
|
return {
|
|
22834
23055
|
get mode() {
|
|
22835
23056
|
return watch.mode;
|
|
22836
23057
|
},
|
|
22837
23058
|
close: () => {
|
|
22838
|
-
this.#watches.delete(
|
|
23059
|
+
this.#watches.delete(tracked);
|
|
22839
23060
|
watch.stop();
|
|
22840
23061
|
}
|
|
22841
23062
|
};
|
|
@@ -22975,7 +23196,7 @@ var init_interlock = __esm({
|
|
|
22975
23196
|
// ../core/dist/common-auth-embedded/claustrum/roster.js
|
|
22976
23197
|
import { createHash as createHash7 } from "node:crypto";
|
|
22977
23198
|
import { stat as stat6 } from "node:fs/promises";
|
|
22978
|
-
import { resolve as
|
|
23199
|
+
import { resolve as resolve9 } from "node:path";
|
|
22979
23200
|
function vaultRosterSeed(roster) {
|
|
22980
23201
|
return {
|
|
22981
23202
|
declined: roster.declined.map((entry) => ({ ...entry })),
|
|
@@ -23377,16 +23598,16 @@ function applyVaultQuota(current, input2) {
|
|
|
23377
23598
|
};
|
|
23378
23599
|
}
|
|
23379
23600
|
function forgetPendingVaultDiscovery(path5) {
|
|
23380
|
-
pendingDiscoveries.delete(
|
|
23601
|
+
pendingDiscoveries.delete(resolve9(path5));
|
|
23381
23602
|
}
|
|
23382
23603
|
function isVaultRosterLockRefusal(path5, error) {
|
|
23383
|
-
const target =
|
|
23604
|
+
const target = resolve9(path5);
|
|
23384
23605
|
if (error instanceof ClaustrumConsumerError)
|
|
23385
23606
|
return error.kind === "roster-busy";
|
|
23386
23607
|
if (error instanceof LockContentionError || error instanceof LockOwnershipError)
|
|
23387
|
-
return
|
|
23608
|
+
return resolve9(error.details.target) === target;
|
|
23388
23609
|
if (error instanceof PrivateFileError) {
|
|
23389
|
-
const failed =
|
|
23610
|
+
const failed = resolve9(error.path);
|
|
23390
23611
|
return [WRITE_LOCK.name, DISCOVERY_LEASE.name].some((name) => {
|
|
23391
23612
|
const lock = lockPathFor(target, name);
|
|
23392
23613
|
return failed === lock || failed.startsWith(`${lock}.`);
|
|
@@ -23447,7 +23668,7 @@ async function refreshVaultRoster(options) {
|
|
|
23447
23668
|
throw new ClaustrumConsumerError("roster-busy", "Claustrum account discovery is already in progress");
|
|
23448
23669
|
return persisted;
|
|
23449
23670
|
}
|
|
23450
|
-
const key =
|
|
23671
|
+
const key = resolve9(options.path);
|
|
23451
23672
|
const listedOver = options.listedOver;
|
|
23452
23673
|
let discovered;
|
|
23453
23674
|
try {
|
|
@@ -23571,9 +23792,9 @@ var init_roster = __esm({
|
|
|
23571
23792
|
});
|
|
23572
23793
|
|
|
23573
23794
|
// ../core/dist/common-auth-embedded/claustrum/quota-writer.js
|
|
23574
|
-
import { resolve as
|
|
23795
|
+
import { resolve as resolve10 } from "node:path";
|
|
23575
23796
|
function writerFor(path5, clock2 = quotaCommitTimer) {
|
|
23576
|
-
const key =
|
|
23797
|
+
const key = resolve10(path5);
|
|
23577
23798
|
let writer = writers.get(key);
|
|
23578
23799
|
if (!writer) {
|
|
23579
23800
|
writer = {
|
|
@@ -23637,7 +23858,7 @@ function orderedFields(pending) {
|
|
|
23637
23858
|
return [...pending.values()].flatMap((account) => [...account.values()]).sort((a, b) => a.order - b.order);
|
|
23638
23859
|
}
|
|
23639
23860
|
function pendingVaultQuota(path5, roster) {
|
|
23640
|
-
const writer = writers.get(
|
|
23861
|
+
const writer = writers.get(resolve10(path5));
|
|
23641
23862
|
if (writer) {
|
|
23642
23863
|
for (const field of orderedFields(writer.pending)) {
|
|
23643
23864
|
if (field.priorReading)
|
|
@@ -23648,7 +23869,7 @@ function pendingVaultQuota(path5, roster) {
|
|
|
23648
23869
|
return roster;
|
|
23649
23870
|
}
|
|
23650
23871
|
function hasPendingVaultQuota(path5) {
|
|
23651
|
-
return !!writers.get(
|
|
23872
|
+
return !!writers.get(resolve10(path5))?.pending.size;
|
|
23652
23873
|
}
|
|
23653
23874
|
function schedule(writer, delay3) {
|
|
23654
23875
|
if (writer.running || writer.timer || !writer.pending.size || writer.abort.signal.aborted)
|
|
@@ -23713,7 +23934,7 @@ function flush(writer) {
|
|
|
23713
23934
|
return writer.running;
|
|
23714
23935
|
}
|
|
23715
23936
|
async function drainVaultQuota(path5, timeoutMs = 1e3) {
|
|
23716
|
-
const key =
|
|
23937
|
+
const key = resolve10(path5);
|
|
23717
23938
|
const writer = writers.get(key);
|
|
23718
23939
|
if (!writer)
|
|
23719
23940
|
return;
|
|
@@ -23861,7 +24082,7 @@ var init_consumer = __esm({
|
|
|
23861
24082
|
this.#shutdown.signal,
|
|
23862
24083
|
...signal ? [signal] : []
|
|
23863
24084
|
]);
|
|
23864
|
-
return new Promise((
|
|
24085
|
+
return new Promise((resolve29, reject) => {
|
|
23865
24086
|
const cleanup2 = () => {
|
|
23866
24087
|
combined.signal.removeEventListener("abort", abort);
|
|
23867
24088
|
combined.dispose();
|
|
@@ -23876,7 +24097,7 @@ var init_consumer = __esm({
|
|
|
23876
24097
|
if (combined.signal.aborted)
|
|
23877
24098
|
reject(combined.signal.reason);
|
|
23878
24099
|
else
|
|
23879
|
-
|
|
24100
|
+
resolve29(value);
|
|
23880
24101
|
}, (error) => {
|
|
23881
24102
|
cleanup2();
|
|
23882
24103
|
reject(error);
|
|
@@ -24621,7 +24842,7 @@ var init_consumer = __esm({
|
|
|
24621
24842
|
import { createHash as createHash8 } from "node:crypto";
|
|
24622
24843
|
import { channel as channel2 } from "node:diagnostics_channel";
|
|
24623
24844
|
import { readdir, stat as stat7 } from "node:fs/promises";
|
|
24624
|
-
import { dirname as dirname10, join as join8, resolve as
|
|
24845
|
+
import { dirname as dirname10, join as join8, resolve as resolve11 } from "node:path";
|
|
24625
24846
|
function canonicalJson3(value, path5 = /* @__PURE__ */ new Set()) {
|
|
24626
24847
|
if (value === null)
|
|
24627
24848
|
return "null";
|
|
@@ -24682,12 +24903,12 @@ function unreachableConnect2() {
|
|
|
24682
24903
|
return new ClaustrumUnreachableError();
|
|
24683
24904
|
}
|
|
24684
24905
|
function untilAborted(pending, signal) {
|
|
24685
|
-
return new Promise((
|
|
24906
|
+
return new Promise((resolve29, reject) => {
|
|
24686
24907
|
const abort = () => reject(signal.reason);
|
|
24687
24908
|
signal.addEventListener("abort", abort, { once: true });
|
|
24688
24909
|
pending.then((value) => {
|
|
24689
24910
|
signal.removeEventListener("abort", abort);
|
|
24690
|
-
|
|
24911
|
+
resolve29(value);
|
|
24691
24912
|
}, (error) => {
|
|
24692
24913
|
signal.removeEventListener("abort", abort);
|
|
24693
24914
|
reject(error);
|
|
@@ -24845,7 +25066,7 @@ var init_hub = __esm({
|
|
|
24845
25066
|
};
|
|
24846
25067
|
const { consumer, hooks } = createHubMember(port, consumerOptions);
|
|
24847
25068
|
entry.hooks = hooks;
|
|
24848
|
-
const path5 =
|
|
25069
|
+
const path5 = resolve11(entry.path);
|
|
24849
25070
|
const subscribers = sharedRosters.get(path5) ?? /* @__PURE__ */ new Set();
|
|
24850
25071
|
const install = (roster) => {
|
|
24851
25072
|
if (entry.closed || this.#active !== true || !this.#current || !this.#live(this.#current) || !hooks.roster() || this.#collides(hooks, roster))
|
|
@@ -24876,7 +25097,7 @@ var init_hub = __esm({
|
|
|
24876
25097
|
return;
|
|
24877
25098
|
entry.seen = JSON.stringify(decodedVaultRoster(roster));
|
|
24878
25099
|
entry.hooks?.install(roster);
|
|
24879
|
-
for (const install of sharedRosters.get(
|
|
25100
|
+
for (const install of sharedRosters.get(resolve11(entry.path)) ?? []) {
|
|
24880
25101
|
if (!this.#live(generation))
|
|
24881
25102
|
return;
|
|
24882
25103
|
if (install !== entry.receiveRoster)
|
|
@@ -25679,6 +25900,7 @@ __export(claustrum_exports, {
|
|
|
25679
25900
|
reorderVaultRoster: () => reorderVaultRoster,
|
|
25680
25901
|
resetClaustrumEnrollmentState: () => resetClaustrumEnrollmentState,
|
|
25681
25902
|
resolveVaultPrimary: () => resolveVaultPrimary,
|
|
25903
|
+
validEnrollmentDisplayName: () => validEnrollmentDisplayName,
|
|
25682
25904
|
vaultAuthority: () => vaultAuthority,
|
|
25683
25905
|
vaultRosterSeed: () => vaultRosterSeed,
|
|
25684
25906
|
vaultRoutingRows: () => vaultRoutingRows
|
|
@@ -25935,7 +26157,7 @@ var init_lock = __esm({
|
|
|
25935
26157
|
import { createHash as createHash9 } from "node:crypto";
|
|
25936
26158
|
import { constants as constants2 } from "node:fs";
|
|
25937
26159
|
import { lstat as lstat5, mkdir as mkdir10, open as open7, unlink as unlink7 } from "node:fs/promises";
|
|
25938
|
-
import { dirname as dirname11, resolve as
|
|
26160
|
+
import { dirname as dirname11, resolve as resolve12 } from "node:path";
|
|
25939
26161
|
import { setTimeout as sleep2 } from "node:timers/promises";
|
|
25940
26162
|
function rootSpans(text2) {
|
|
25941
26163
|
let i = text2.indexOf("{") + 1;
|
|
@@ -26136,8 +26358,8 @@ function createPiSlot(options, onStep, hooks) {
|
|
|
26136
26358
|
if (!provider2 || !options.authPath || !options.stashPath || !placeholderKey || placeholderKey.startsWith("!") || placeholderKey.includes("$") || !Number.isFinite(timeout) || timeout < 0) {
|
|
26137
26359
|
throw new PiSlotError("invalid-options");
|
|
26138
26360
|
}
|
|
26139
|
-
const authPath =
|
|
26140
|
-
const stashPath =
|
|
26361
|
+
const authPath = resolve12(options.authPath);
|
|
26362
|
+
const stashPath = resolve12(options.stashPath);
|
|
26141
26363
|
if (authPath === stashPath || stashPath === `${authPath}.lock`) {
|
|
26142
26364
|
throw new PiSlotError("invalid-options");
|
|
26143
26365
|
}
|
|
@@ -26760,8 +26982,8 @@ function getDefaultTierId(allowedTiers) {
|
|
|
26760
26982
|
return allowedTiers[0]?.id;
|
|
26761
26983
|
}
|
|
26762
26984
|
function wait(ms) {
|
|
26763
|
-
return new Promise((
|
|
26764
|
-
setTimeout(
|
|
26985
|
+
return new Promise((resolve29) => {
|
|
26986
|
+
setTimeout(resolve29, ms);
|
|
26765
26987
|
});
|
|
26766
26988
|
}
|
|
26767
26989
|
function extractManagedProjectId(payload) {
|
|
@@ -27580,7 +27802,7 @@ function applyAgyNativeGenerationConfig(wireModel, generationConfig) {
|
|
|
27580
27802
|
generationConfig.maxOutputTokens = output2;
|
|
27581
27803
|
}
|
|
27582
27804
|
delete generationConfig.max_output_tokens;
|
|
27583
|
-
if (isGeminiArgonModel(wireModel) && native.thinkingLevel !== void 0) {
|
|
27805
|
+
if ((isGeminiArgonModel(wireModel) || isGeminiCarbonModel(wireModel)) && native.thinkingLevel !== void 0) {
|
|
27584
27806
|
generationConfig.thinkingConfig = {
|
|
27585
27807
|
includeThoughts: true,
|
|
27586
27808
|
thinkingLevel: ADAPTIVE_LEVELS[native.thinkingLevel]
|
|
@@ -28339,7 +28561,7 @@ var init_cross_model_sanitizer = __esm({
|
|
|
28339
28561
|
// ../core/dist/transform/model-resolver.js
|
|
28340
28562
|
function supportsThinkingTiers(model) {
|
|
28341
28563
|
const lower = model.toLowerCase();
|
|
28342
|
-
return isGeminiArgonModel(lower) || lower.includes("gemini-3") || lower.includes("gemini-2.5") || lower.includes("claude") && (lower.includes("thinking") || /^claude-(opus|sonnet)-5-5/.test(lower));
|
|
28564
|
+
return isGeminiArgonModel(lower) || isGeminiCarbonModel(lower) || lower.includes("gemini-3") || lower.includes("gemini-2.5") || lower.includes("claude") && (lower.includes("thinking") || /^claude-(opus|sonnet)-5-5/.test(lower));
|
|
28343
28565
|
}
|
|
28344
28566
|
function extractThinkingTierFromModel(model) {
|
|
28345
28567
|
if (!supportsThinkingTiers(model)) {
|
|
@@ -28399,9 +28621,10 @@ function resolveModelWithTier(requestedModel) {
|
|
|
28399
28621
|
const baseName = tier ? modelWithoutQuota.replace(TIER_REGEX, "") : modelWithoutQuota;
|
|
28400
28622
|
const isImageModel = IMAGE_GENERATION_MODELS.test(modelWithoutQuota);
|
|
28401
28623
|
const isArgon = isGeminiArgonModel(modelWithoutQuota);
|
|
28402
|
-
|
|
28624
|
+
const isCarbon = isGeminiCarbonModel(modelWithoutQuota);
|
|
28625
|
+
if (isArgon || isCarbon) {
|
|
28403
28626
|
return {
|
|
28404
|
-
actualModel: getGeminiArgonAntigravityModel(tier),
|
|
28627
|
+
actualModel: isCarbon ? getGeminiCarbonAntigravityModel(tier) : getGeminiArgonAntigravityModel(tier),
|
|
28405
28628
|
thinkingLevel: tier ?? "medium",
|
|
28406
28629
|
tier: tier ?? "medium",
|
|
28407
28630
|
isThinkingModel: true
|
|
@@ -29083,12 +29306,12 @@ var init_vault_provider_state = __esm({
|
|
|
29083
29306
|
function untilAborted2(pending, signal) {
|
|
29084
29307
|
if (!signal)
|
|
29085
29308
|
return pending;
|
|
29086
|
-
return new Promise((
|
|
29309
|
+
return new Promise((resolve29, reject) => {
|
|
29087
29310
|
const abort = () => reject(signal.reason);
|
|
29088
29311
|
signal.addEventListener("abort", abort, { once: true });
|
|
29089
29312
|
if (signal.aborted)
|
|
29090
29313
|
abort();
|
|
29091
|
-
pending.then(
|
|
29314
|
+
pending.then(resolve29, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
29092
29315
|
});
|
|
29093
29316
|
}
|
|
29094
29317
|
async function resolveClaustrumConnectionPath(explicit) {
|
|
@@ -29563,7 +29786,7 @@ var init_capture_sink2 = __esm({
|
|
|
29563
29786
|
import { randomUUID as randomUUID13 } from "node:crypto";
|
|
29564
29787
|
import { lstat as lstat6, readFile as readFile8, rename as rename8, unlink as unlink8 } from "node:fs/promises";
|
|
29565
29788
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
29566
|
-
import { dirname as dirname13, join as join10, resolve as
|
|
29789
|
+
import { dirname as dirname13, join as join10, resolve as resolve13 } from "node:path";
|
|
29567
29790
|
function ioCode2(detail) {
|
|
29568
29791
|
if (detail?.reason === "io-error") {
|
|
29569
29792
|
if (detail.win32Code === 2 || detail.win32Code === 3)
|
|
@@ -29613,7 +29836,7 @@ async function privateOperation2(path5, stage, operation) {
|
|
|
29613
29836
|
}
|
|
29614
29837
|
}
|
|
29615
29838
|
async function verifySafeDirectory2(path5, options) {
|
|
29616
|
-
path5 =
|
|
29839
|
+
path5 = resolve13(path5);
|
|
29617
29840
|
options ??= safeParentOptionsForTest2;
|
|
29618
29841
|
await privateOperation2(path5, "safe-parent", async () => {
|
|
29619
29842
|
const result = await (await loadBackend2()).verifySafeParent(path5, options);
|
|
@@ -29628,7 +29851,7 @@ async function verifySafeDirectory2(path5, options) {
|
|
|
29628
29851
|
});
|
|
29629
29852
|
}
|
|
29630
29853
|
async function verifyPrivate2(path5, kind, migrate = false) {
|
|
29631
|
-
path5 =
|
|
29854
|
+
path5 = resolve13(path5);
|
|
29632
29855
|
if (kind === "directory")
|
|
29633
29856
|
return verifySafeDirectory2(path5);
|
|
29634
29857
|
await privateOperation2(path5, "verify", async () => {
|
|
@@ -29663,7 +29886,7 @@ async function verifyPrivate2(path5, kind, migrate = false) {
|
|
|
29663
29886
|
});
|
|
29664
29887
|
}
|
|
29665
29888
|
async function ensurePrivateDirectory2(path5, _migrate = false, options) {
|
|
29666
|
-
path5 =
|
|
29889
|
+
path5 = resolve13(path5);
|
|
29667
29890
|
await privateOperation2(path5, "directory", async () => {
|
|
29668
29891
|
const api = await loadBackend2();
|
|
29669
29892
|
try {
|
|
@@ -29694,7 +29917,7 @@ async function readPrivateText2(path5, migrate = false) {
|
|
|
29694
29917
|
async function readPrivateBuffer2(path5, migrate = false) {
|
|
29695
29918
|
if (!windowsPrivateFiles2)
|
|
29696
29919
|
return readFile8(path5);
|
|
29697
|
-
path5 =
|
|
29920
|
+
path5 = resolve13(path5);
|
|
29698
29921
|
if (migrate) {
|
|
29699
29922
|
await verifySafeDirectory2(dirname13(path5));
|
|
29700
29923
|
await verifyPrivate2(path5, "file", true);
|
|
@@ -29702,20 +29925,20 @@ async function readPrivateBuffer2(path5, migrate = false) {
|
|
|
29702
29925
|
return privateOperation2(path5, "read", async () => (await loadBackend2()).readOwnerOnly(path5));
|
|
29703
29926
|
}
|
|
29704
29927
|
async function createPrivateBytes2(path5, bytes) {
|
|
29705
|
-
await verifySafeDirectory2(dirname13(
|
|
29928
|
+
await verifySafeDirectory2(dirname13(resolve13(path5)));
|
|
29706
29929
|
await privateOperation2(path5, "create", async () => {
|
|
29707
|
-
await (await loadBackend2()).createPrivateFile(
|
|
29930
|
+
await (await loadBackend2()).createPrivateFile(resolve13(path5), bytes);
|
|
29708
29931
|
});
|
|
29709
29932
|
}
|
|
29710
29933
|
async function createPrivateDirectoryExclusive2(path5) {
|
|
29711
|
-
await verifySafeDirectory2(dirname13(
|
|
29934
|
+
await verifySafeDirectory2(dirname13(resolve13(path5)));
|
|
29712
29935
|
await privateOperation2(path5, "directory-create", async () => {
|
|
29713
|
-
await (await loadBackend2()).createOwnerOnly(
|
|
29936
|
+
await (await loadBackend2()).createOwnerOnly(resolve13(path5), { kind: "dir" });
|
|
29714
29937
|
});
|
|
29715
29938
|
}
|
|
29716
29939
|
async function replaceWindowsFile2(from, to, options = {}) {
|
|
29717
|
-
from =
|
|
29718
|
-
to =
|
|
29940
|
+
from = resolve13(from);
|
|
29941
|
+
to = resolve13(to);
|
|
29719
29942
|
const now = options.now ?? (() => performance.now());
|
|
29720
29943
|
const start = now();
|
|
29721
29944
|
const leaseDeadline = options.deadline ?? Infinity;
|
|
@@ -29758,7 +29981,7 @@ async function replaceWindowsFile2(from, to, options = {}) {
|
|
|
29758
29981
|
throw error;
|
|
29759
29982
|
}
|
|
29760
29983
|
async function writePrivateAtomic2(path5, bytes, options = {}) {
|
|
29761
|
-
path5 =
|
|
29984
|
+
path5 = resolve13(path5);
|
|
29762
29985
|
await ensurePrivateDirectory2(dirname13(path5));
|
|
29763
29986
|
try {
|
|
29764
29987
|
await verifyPrivate2(path5, "file", true);
|
|
@@ -29766,7 +29989,7 @@ async function writePrivateAtomic2(path5, bytes, options = {}) {
|
|
|
29766
29989
|
if (error.code !== "ENOENT")
|
|
29767
29990
|
throw error;
|
|
29768
29991
|
}
|
|
29769
|
-
const stage =
|
|
29992
|
+
const stage = resolve13(options.stagePath ?? `${path5}.${randomUUID13()}.tmp`);
|
|
29770
29993
|
if (dirname13(stage) !== dirname13(path5))
|
|
29771
29994
|
throw new PrivateFileError2(path5, "stage-directory", { code: "EXDEV" });
|
|
29772
29995
|
let created = false;
|
|
@@ -29932,7 +30155,7 @@ var init_redact2 = __esm({
|
|
|
29932
30155
|
// src/common-auth-embedded/logger/engine.js
|
|
29933
30156
|
import { appendFileSync as appendFileSync2, chmodSync as chmodSync2, existsSync as existsSync2, renameSync as renameSync2, statSync as statSync3 } from "node:fs";
|
|
29934
30157
|
import { open as open8 } from "node:fs/promises";
|
|
29935
|
-
import { dirname as dirname14, resolve as
|
|
30158
|
+
import { dirname as dirname14, resolve as resolve14 } from "node:path";
|
|
29936
30159
|
function chmodPrivate2(path5) {
|
|
29937
30160
|
try {
|
|
29938
30161
|
chmodSync2(path5, 384);
|
|
@@ -29983,7 +30206,7 @@ async function openWindowsFile2(sink, file) {
|
|
|
29983
30206
|
return sink.handle;
|
|
29984
30207
|
}
|
|
29985
30208
|
async function flushWindowsFile2(sink, file, text2) {
|
|
29986
|
-
file =
|
|
30209
|
+
file = resolve14(file);
|
|
29987
30210
|
try {
|
|
29988
30211
|
if (sink.file !== file)
|
|
29989
30212
|
await closeWindowsFile2(sink);
|
|
@@ -30587,12 +30810,12 @@ function createVaultAccountPool(options) {
|
|
|
30587
30810
|
try {
|
|
30588
30811
|
return await Promise.race([
|
|
30589
30812
|
read.then(() => true),
|
|
30590
|
-
new Promise((
|
|
30813
|
+
new Promise((resolve29, reject) => {
|
|
30591
30814
|
const abort = () => reject(signal?.reason);
|
|
30592
30815
|
signal?.addEventListener("abort", abort, { once: true });
|
|
30593
30816
|
detachAbort = () => signal?.removeEventListener("abort", abort);
|
|
30594
30817
|
if (remaining !== void 0)
|
|
30595
|
-
cancelTimer2 = schedule2(() =>
|
|
30818
|
+
cancelTimer2 = schedule2(() => resolve29(false), remaining);
|
|
30596
30819
|
if (signal?.aborted) abort();
|
|
30597
30820
|
})
|
|
30598
30821
|
]);
|
|
@@ -31094,11 +31317,11 @@ function createOpenCodeVaultCustody(options) {
|
|
|
31094
31317
|
].join("\n");
|
|
31095
31318
|
const waitForApproval = async () => {
|
|
31096
31319
|
while (!closed2) {
|
|
31097
|
-
await new Promise((
|
|
31320
|
+
await new Promise((resolve29) => {
|
|
31098
31321
|
const done = () => {
|
|
31099
31322
|
clearTimeout(timer);
|
|
31100
31323
|
cancelWait = void 0;
|
|
31101
|
-
|
|
31324
|
+
resolve29();
|
|
31102
31325
|
};
|
|
31103
31326
|
const timer = setTimeout(done, 2e3);
|
|
31104
31327
|
timer.unref?.();
|
|
@@ -31498,7 +31721,7 @@ import { randomUUID as randomUUID14 } from "node:crypto";
|
|
|
31498
31721
|
import { realpathSync, rmSync } from "node:fs";
|
|
31499
31722
|
import { chmod as chmod4, mkdir as mkdir12, readFile as readFile10, rename as rename9, rm as rm5, writeFile as writeFile3 } from "node:fs/promises";
|
|
31500
31723
|
import { homedir as homedir2 } from "node:os";
|
|
31501
|
-
import { join as join12, resolve as
|
|
31724
|
+
import { join as join12, resolve as resolve15 } from "node:path";
|
|
31502
31725
|
function processHeartbeatDir() {
|
|
31503
31726
|
const base = process.env.XDG_STATE_HOME || join12(homedir2(), ".local", "state");
|
|
31504
31727
|
return join12(base, "cortexkit", "antigravity-auth", "processes");
|
|
@@ -31511,7 +31734,7 @@ function processConfigFolderKey() {
|
|
|
31511
31734
|
try {
|
|
31512
31735
|
return realpathSync.native(folder);
|
|
31513
31736
|
} catch {
|
|
31514
|
-
return
|
|
31737
|
+
return resolve15(folder);
|
|
31515
31738
|
}
|
|
31516
31739
|
}
|
|
31517
31740
|
function processHasOlderGeneration() {
|
|
@@ -32095,7 +32318,7 @@ import {
|
|
|
32095
32318
|
stat as stat11,
|
|
32096
32319
|
unlink as unlink10
|
|
32097
32320
|
} from "node:fs/promises";
|
|
32098
|
-
import { basename as basename4, dirname as dirname15, join as join14, resolve as
|
|
32321
|
+
import { basename as basename4, dirname as dirname15, join as join14, resolve as resolve16 } from "node:path";
|
|
32099
32322
|
function refusalMessage(stateDir, errorClass2) {
|
|
32100
32323
|
if (errorClass2 === "ERR_PRIVATE_FILES_SECURITY")
|
|
32101
32324
|
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.`;
|
|
@@ -32955,7 +33178,7 @@ async function removeMovedVaultStateLeftover(vaultDir, accountFile) {
|
|
|
32955
33178
|
if (process.env.OPENCODE_ANTIGRAVITY_AUTH_VAULT_DIR) return;
|
|
32956
33179
|
const location = runtimeLayoutLocation();
|
|
32957
33180
|
const files = layoutFiles(location, accountFile);
|
|
32958
|
-
if (
|
|
33181
|
+
if (resolve16(vaultDir) !== resolve16(files.vault.next)) return;
|
|
32959
33182
|
const stateDir = location.stateHomeDir;
|
|
32960
33183
|
const marker = await readMarker(
|
|
32961
33184
|
join14(stateDir, RUNTIME_LAYOUT_MARKER_FILE),
|
|
@@ -33384,7 +33607,7 @@ import {
|
|
|
33384
33607
|
writeFileSync
|
|
33385
33608
|
} from "node:fs";
|
|
33386
33609
|
import { homedir as homedir4 } from "node:os";
|
|
33387
|
-
import { dirname as dirname16, join as join15, resolve as
|
|
33610
|
+
import { dirname as dirname16, join as join15, resolve as resolve17 } from "node:path";
|
|
33388
33611
|
async function ensureGitignore(configDir) {
|
|
33389
33612
|
const gitignorePath = join15(configDir, ".gitignore");
|
|
33390
33613
|
try {
|
|
@@ -33484,8 +33707,8 @@ function migrateLegacyWindowsConfig() {
|
|
|
33484
33707
|
}
|
|
33485
33708
|
}
|
|
33486
33709
|
function resolveWindowsAccountAnchor(newPath, legacyPath) {
|
|
33487
|
-
const standard =
|
|
33488
|
-
const legacy =
|
|
33710
|
+
const standard = resolve17(newPath);
|
|
33711
|
+
const legacy = resolve17(legacyPath);
|
|
33489
33712
|
if (standard.toLowerCase() === legacy.toLowerCase()) return newPath;
|
|
33490
33713
|
const standardPointer = existsSync3(accountStorePointerPath(standard));
|
|
33491
33714
|
const legacyPointer = existsSync3(accountStorePointerPath(legacy));
|
|
@@ -33507,7 +33730,7 @@ function getStoragePathWithMigration() {
|
|
|
33507
33730
|
"antigravity-accounts.json"
|
|
33508
33731
|
);
|
|
33509
33732
|
const anchored = resolveWindowsAccountAnchor(newPath, legacyPath);
|
|
33510
|
-
if (
|
|
33733
|
+
if (resolve17(anchored).toLowerCase() !== resolve17(newPath).toLowerCase() && !existsSync3(accountStorePointerPath(resolve17(anchored)))) {
|
|
33511
33734
|
log6.info("Using legacy Windows config path (migration failed)", {
|
|
33512
33735
|
legacyPath,
|
|
33513
33736
|
newPath
|
|
@@ -33524,7 +33747,7 @@ function accountFileForVault(configDir = getConfigDir()) {
|
|
|
33524
33747
|
const configured = join15(configDir, "antigravity-accounts.json");
|
|
33525
33748
|
if (process.platform !== "win32") return configured;
|
|
33526
33749
|
const legacyDir = getLegacyWindowsConfigDir();
|
|
33527
|
-
if (
|
|
33750
|
+
if (resolve17(configDir).toLowerCase() === resolve17(legacyDir).toLowerCase())
|
|
33528
33751
|
return configured;
|
|
33529
33752
|
const configuredVault = join15(configDir, "antigravity-auth-vault");
|
|
33530
33753
|
const legacyVault = join15(legacyDir, "antigravity-auth-vault");
|
|
@@ -33555,7 +33778,7 @@ function getStoragePath() {
|
|
|
33555
33778
|
}
|
|
33556
33779
|
async function assertLegacyPoolInUse(legacyPath) {
|
|
33557
33780
|
try {
|
|
33558
|
-
await assertLegacyAccountStorageWritable(
|
|
33781
|
+
await assertLegacyAccountStorageWritable(resolve17(legacyPath));
|
|
33559
33782
|
} catch (error) {
|
|
33560
33783
|
throw new LegacyAccountPoolRetiredError(legacyPath, { cause: error });
|
|
33561
33784
|
}
|
|
@@ -33575,7 +33798,7 @@ function refusalMessage2(admission) {
|
|
|
33575
33798
|
async function bindingOf(options) {
|
|
33576
33799
|
if (options.legacyPath === void 0) await prepareLocalAccountStore();
|
|
33577
33800
|
const now = options.now ?? (() => Date.now());
|
|
33578
|
-
const legacyPath =
|
|
33801
|
+
const legacyPath = resolve17(options.legacyPath ?? getStoragePath());
|
|
33579
33802
|
return {
|
|
33580
33803
|
legacyPath,
|
|
33581
33804
|
now,
|
|
@@ -33644,7 +33867,7 @@ async function openAccountStore(options) {
|
|
|
33644
33867
|
async function initializeFreshAccountStoreFor(modules, options = {}) {
|
|
33645
33868
|
if (options.legacyPath === void 0) await prepareLocalAccountStore();
|
|
33646
33869
|
return initializeFreshAccountStore(modules, {
|
|
33647
|
-
legacyPath:
|
|
33870
|
+
legacyPath: resolve17(options.legacyPath ?? getStoragePath()),
|
|
33648
33871
|
now: options.now ?? (() => Date.now())
|
|
33649
33872
|
});
|
|
33650
33873
|
}
|
|
@@ -33722,12 +33945,12 @@ var init_storage = __esm({
|
|
|
33722
33945
|
import { createHash as createHash12 } from "node:crypto";
|
|
33723
33946
|
import { existsSync as existsSync4, promises as fs2, readFileSync as readFileSync2, realpathSync as realpathSync2 } from "node:fs";
|
|
33724
33947
|
import { homedir as homedir5 } from "node:os";
|
|
33725
|
-
import { dirname as dirname17, join as join16, resolve as
|
|
33948
|
+
import { dirname as dirname17, join as join16, resolve as resolve18 } from "node:path";
|
|
33726
33949
|
function configDirIdentity(path5) {
|
|
33727
33950
|
try {
|
|
33728
33951
|
return realpathSync2.native(path5);
|
|
33729
33952
|
} catch {
|
|
33730
|
-
return
|
|
33953
|
+
return resolve18(path5);
|
|
33731
33954
|
}
|
|
33732
33955
|
}
|
|
33733
33956
|
function decisionKey(location) {
|
|
@@ -34180,13 +34403,13 @@ function closeDebugStream(state) {
|
|
|
34180
34403
|
state.logWriter = () => {
|
|
34181
34404
|
};
|
|
34182
34405
|
if (state.logFilePath) liveLogFilePaths.delete(state.logFilePath);
|
|
34183
|
-
return new Promise((
|
|
34184
|
-
current.once("close", () =>
|
|
34185
|
-
current.once("error", () =>
|
|
34406
|
+
return new Promise((resolve29) => {
|
|
34407
|
+
current.once("close", () => resolve29());
|
|
34408
|
+
current.once("error", () => resolve29());
|
|
34186
34409
|
try {
|
|
34187
34410
|
current.end();
|
|
34188
34411
|
} catch {
|
|
34189
|
-
|
|
34412
|
+
resolve29();
|
|
34190
34413
|
}
|
|
34191
34414
|
});
|
|
34192
34415
|
}
|
|
@@ -34451,13 +34674,13 @@ function closeDebugLog() {
|
|
|
34451
34674
|
if (!state || !current) return Promise.resolve();
|
|
34452
34675
|
state.logStream = null;
|
|
34453
34676
|
if (state.logFilePath) liveLogFilePaths.delete(state.logFilePath);
|
|
34454
|
-
return new Promise((
|
|
34455
|
-
current.once("close", () =>
|
|
34456
|
-
current.once("error", () =>
|
|
34677
|
+
return new Promise((resolve29) => {
|
|
34678
|
+
current.once("close", () => resolve29());
|
|
34679
|
+
current.once("error", () => resolve29());
|
|
34457
34680
|
try {
|
|
34458
34681
|
current.end();
|
|
34459
34682
|
} catch {
|
|
34460
|
-
|
|
34683
|
+
resolve29();
|
|
34461
34684
|
}
|
|
34462
34685
|
});
|
|
34463
34686
|
}
|
|
@@ -34669,13 +34892,13 @@ var init_logger4 = __esm({
|
|
|
34669
34892
|
// src/plugin/index.ts
|
|
34670
34893
|
init_dist();
|
|
34671
34894
|
import { createHash as createHash24, randomUUID as randomUUID21 } from "node:crypto";
|
|
34672
|
-
import { join as join39, resolve as
|
|
34895
|
+
import { join as join39, resolve as resolve28 } from "node:path";
|
|
34673
34896
|
|
|
34674
34897
|
// src/cli.ts
|
|
34675
34898
|
init_dist();
|
|
34676
34899
|
import { execFile } from "node:child_process";
|
|
34677
34900
|
import { realpathSync as realpathSync4 } from "node:fs";
|
|
34678
|
-
import { resolve as
|
|
34901
|
+
import { resolve as resolve23 } from "node:path";
|
|
34679
34902
|
import { createInterface } from "node:readline/promises";
|
|
34680
34903
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
34681
34904
|
import { promisify } from "node:util";
|
|
@@ -35326,7 +35549,7 @@ function drainSidebarWrites() {
|
|
|
35326
35549
|
return sidebarWriteChain;
|
|
35327
35550
|
}
|
|
35328
35551
|
async function sleep3(ms) {
|
|
35329
|
-
await new Promise((
|
|
35552
|
+
await new Promise((resolve29) => setTimeout(resolve29, ms));
|
|
35330
35553
|
}
|
|
35331
35554
|
async function acquireSidebarLockWithRetry(stateFile) {
|
|
35332
35555
|
const start = Date.now();
|
|
@@ -36178,14 +36401,14 @@ var LocalQuotaGrantStaleError = class extends Error {
|
|
|
36178
36401
|
name = "LocalQuotaGrantStaleError";
|
|
36179
36402
|
};
|
|
36180
36403
|
function untilQuotaAborted(pending, signal) {
|
|
36181
|
-
return new Promise((
|
|
36404
|
+
return new Promise((resolve29, reject) => {
|
|
36182
36405
|
const abort = () => reject(signal.reason);
|
|
36183
36406
|
if (signal.aborted) abort();
|
|
36184
36407
|
else signal.addEventListener("abort", abort, { once: true });
|
|
36185
36408
|
void pending.then(
|
|
36186
36409
|
(value) => {
|
|
36187
36410
|
signal.removeEventListener("abort", abort);
|
|
36188
|
-
|
|
36411
|
+
resolve29(value);
|
|
36189
36412
|
},
|
|
36190
36413
|
(error) => {
|
|
36191
36414
|
signal.removeEventListener("abort", abort);
|
|
@@ -36806,12 +37029,12 @@ async function startOAuthListener({
|
|
|
36806
37029
|
let resolveCallback;
|
|
36807
37030
|
let rejectCallback;
|
|
36808
37031
|
let timeoutHandle;
|
|
36809
|
-
const callbackPromise = new Promise((
|
|
37032
|
+
const callbackPromise = new Promise((resolve29, reject) => {
|
|
36810
37033
|
resolveCallback = (url) => {
|
|
36811
37034
|
if (settled) return;
|
|
36812
37035
|
settled = true;
|
|
36813
37036
|
if (timeoutHandle) clearTimeout(timeoutHandle);
|
|
36814
|
-
|
|
37037
|
+
resolve29(url);
|
|
36815
37038
|
};
|
|
36816
37039
|
rejectCallback = (error) => {
|
|
36817
37040
|
if (settled) return;
|
|
@@ -36970,7 +37193,7 @@ async function startOAuthListener({
|
|
|
36970
37193
|
});
|
|
36971
37194
|
});
|
|
36972
37195
|
const bindAddress = getBindAddress();
|
|
36973
|
-
await new Promise((
|
|
37196
|
+
await new Promise((resolve29, reject) => {
|
|
36974
37197
|
const handleError = (error) => {
|
|
36975
37198
|
server.off("error", handleError);
|
|
36976
37199
|
if (error.code === "EADDRINUSE") {
|
|
@@ -36986,7 +37209,7 @@ async function startOAuthListener({
|
|
|
36986
37209
|
server.once("error", handleError);
|
|
36987
37210
|
server.listen(port, bindAddress, () => {
|
|
36988
37211
|
server.off("error", handleError);
|
|
36989
|
-
|
|
37212
|
+
resolve29();
|
|
36990
37213
|
});
|
|
36991
37214
|
});
|
|
36992
37215
|
server.on("error", (error) => {
|
|
@@ -36994,7 +37217,7 @@ async function startOAuthListener({
|
|
|
36994
37217
|
});
|
|
36995
37218
|
return {
|
|
36996
37219
|
waitForCallback: () => callbackPromise,
|
|
36997
|
-
close: () => new Promise((
|
|
37220
|
+
close: () => new Promise((resolve29, reject) => {
|
|
36998
37221
|
server.close((error) => {
|
|
36999
37222
|
if (error && error.code !== "ERR_SERVER_NOT_RUNNING") {
|
|
37000
37223
|
reject(error);
|
|
@@ -37003,7 +37226,7 @@ async function startOAuthListener({
|
|
|
37003
37226
|
if (!settled) {
|
|
37004
37227
|
rejectCallback(new Error("OAuth listener closed before callback"));
|
|
37005
37228
|
}
|
|
37006
|
-
|
|
37229
|
+
resolve29();
|
|
37007
37230
|
});
|
|
37008
37231
|
})
|
|
37009
37232
|
};
|
|
@@ -37022,7 +37245,7 @@ init_runtime_paths();
|
|
|
37022
37245
|
// src/setup.ts
|
|
37023
37246
|
init_dist();
|
|
37024
37247
|
import { lstat as lstat9, readFile as readFile16 } from "node:fs/promises";
|
|
37025
|
-
import { join as join24, resolve as
|
|
37248
|
+
import { join as join24, resolve as resolve22 } from "node:path";
|
|
37026
37249
|
|
|
37027
37250
|
// src/auth-method-labels.ts
|
|
37028
37251
|
var OPENCODE2_POOL_AUTH_LABEL = "Google (antigravity-auth pool, browser)";
|
|
@@ -37195,7 +37418,7 @@ async function select2(terminal, items, options) {
|
|
|
37195
37418
|
writeLine("");
|
|
37196
37419
|
renderedLines = lines;
|
|
37197
37420
|
};
|
|
37198
|
-
return new Promise((
|
|
37421
|
+
return new Promise((resolve29) => {
|
|
37199
37422
|
const wasRaw = stdin.isRaw ?? false;
|
|
37200
37423
|
const cleanup2 = () => {
|
|
37201
37424
|
if (cleaned)
|
|
@@ -37215,7 +37438,7 @@ async function select2(terminal, items, options) {
|
|
|
37215
37438
|
};
|
|
37216
37439
|
const finish = (value) => {
|
|
37217
37440
|
cleanup2();
|
|
37218
|
-
|
|
37441
|
+
resolve29(value);
|
|
37219
37442
|
};
|
|
37220
37443
|
const onSignal = () => finish(null);
|
|
37221
37444
|
const onKey = (data) => {
|
|
@@ -37255,7 +37478,7 @@ async function select2(terminal, items, options) {
|
|
|
37255
37478
|
stdin.setRawMode(true);
|
|
37256
37479
|
} catch {
|
|
37257
37480
|
cleanup2();
|
|
37258
|
-
|
|
37481
|
+
resolve29(null);
|
|
37259
37482
|
return;
|
|
37260
37483
|
}
|
|
37261
37484
|
stdin.resume();
|
|
@@ -37269,12 +37492,12 @@ async function select2(terminal, items, options) {
|
|
|
37269
37492
|
import { createHash as createHash13, randomBytes as randomBytes5, randomUUID as randomUUID17 } from "node:crypto";
|
|
37270
37493
|
import { constants as fsConstants2 } from "node:fs";
|
|
37271
37494
|
import { chmod as chmod6, mkdir as mkdir15, open as open10, readFile as readFile14, realpath as realpath4, rename as rename12, stat as stat14, unlink as unlink11 } from "node:fs/promises";
|
|
37272
|
-
import { basename as basename5, dirname as dirname20, extname as extname2, isAbsolute as isAbsolute4, join as join20, resolve as
|
|
37495
|
+
import { basename as basename5, dirname as dirname20, extname as extname2, isAbsolute as isAbsolute4, join as join20, resolve as resolve21 } from "node:path";
|
|
37273
37496
|
import { ClaustrumCredentialError as ClaustrumCredentialError9, ClaustrumClient as ClaustrumWireClient2, writeEnrollmentTokenFile as writeEnrollmentTokenFile2 } from "@cortexkit/claustrum-client";
|
|
37274
37497
|
|
|
37275
37498
|
// src/common-auth-embedded/fs/file-read-cache.js
|
|
37276
37499
|
import { lstat as lstat7, stat as stat12 } from "node:fs/promises";
|
|
37277
|
-
import { resolve as
|
|
37500
|
+
import { resolve as resolve19 } from "node:path";
|
|
37278
37501
|
async function identity2(path5, followSymlinks) {
|
|
37279
37502
|
try {
|
|
37280
37503
|
const metadata = await (followSymlinks ? stat12(path5) : lstat7(path5));
|
|
@@ -37295,7 +37518,7 @@ var FileReadCache2 = class {
|
|
|
37295
37518
|
this.#followSymlinks = options.followSymlinks ?? false;
|
|
37296
37519
|
}
|
|
37297
37520
|
async read(paths, read, validateHit) {
|
|
37298
|
-
const resolvedPaths = paths.map((path5) =>
|
|
37521
|
+
const resolvedPaths = paths.map((path5) => resolve19(path5));
|
|
37299
37522
|
const key = JSON.stringify(resolvedPaths);
|
|
37300
37523
|
const probed = await Promise.all(resolvedPaths.map((path5) => identity2(path5, this.#followSymlinks)));
|
|
37301
37524
|
const identities = probed.every((entry) => entry !== void 0) ? probed : void 0;
|
|
@@ -37344,11 +37567,46 @@ var WRITER_LOCK_CONSTANTS2 = Object.freeze({
|
|
|
37344
37567
|
init_private_files2();
|
|
37345
37568
|
|
|
37346
37569
|
// src/common-auth-embedded/fs/refresh-file-lock.js
|
|
37347
|
-
init_private_files2();
|
|
37348
37570
|
import { randomUUID as randomUUID16 } from "node:crypto";
|
|
37349
37571
|
import { link as link3, lstat as lstat8, mkdir as mkdir14, open as open9, readFile as readFile13, rename as rename11, rm as rm6, stat as stat13 } from "node:fs/promises";
|
|
37350
37572
|
import { dirname as dirname19, join as join19 } from "node:path";
|
|
37351
37573
|
|
|
37574
|
+
// src/common-auth-embedded/fs/lock-record.js
|
|
37575
|
+
init_private_files2();
|
|
37576
|
+
import { resolve as resolve20 } from "node:path";
|
|
37577
|
+
var DisappearedLockRecordError2 = class extends Error {
|
|
37578
|
+
path;
|
|
37579
|
+
code = "ENOENT";
|
|
37580
|
+
constructor(path5, cause) {
|
|
37581
|
+
super(`Lock record disappeared: ${path5}`, { cause });
|
|
37582
|
+
this.path = path5;
|
|
37583
|
+
}
|
|
37584
|
+
};
|
|
37585
|
+
function isWindowsAccessDeniedRead2(error, paths) {
|
|
37586
|
+
return error instanceof PrivateFileError2 && error.reason === "io-error" && error.win32Code === 5 && (error.stage === "read" || error.stage === "verify") && paths.some((path5) => resolve20(path5) === error.path);
|
|
37587
|
+
}
|
|
37588
|
+
function isWindowsAccessDeniedCreate2(error, paths, stage) {
|
|
37589
|
+
return error instanceof PrivateFileError2 && error.reason === "io-error" && error.win32Code === 5 && error.stage === stage && paths.some((path5) => resolve20(path5) === error.path);
|
|
37590
|
+
}
|
|
37591
|
+
async function readLockRecord2(path5, read) {
|
|
37592
|
+
try {
|
|
37593
|
+
return await read();
|
|
37594
|
+
} catch (error) {
|
|
37595
|
+
if (!isWindowsAccessDeniedRead2(error, [path5]))
|
|
37596
|
+
throw error;
|
|
37597
|
+
try {
|
|
37598
|
+
return await read();
|
|
37599
|
+
} catch (recheckError) {
|
|
37600
|
+
if (recheckError.code === "ENOENT")
|
|
37601
|
+
throw new DisappearedLockRecordError2(path5, error);
|
|
37602
|
+
throw error;
|
|
37603
|
+
}
|
|
37604
|
+
}
|
|
37605
|
+
}
|
|
37606
|
+
|
|
37607
|
+
// src/common-auth-embedded/fs/refresh-file-lock.js
|
|
37608
|
+
init_private_files2();
|
|
37609
|
+
|
|
37352
37610
|
// src/common-auth-embedded/fs/with-lock.js
|
|
37353
37611
|
init_private_files2();
|
|
37354
37612
|
function lockPathFor2(target, name) {
|
|
@@ -37447,8 +37705,8 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
37447
37705
|
let releaseConfirmed = false;
|
|
37448
37706
|
let loss;
|
|
37449
37707
|
let resolveLoss;
|
|
37450
|
-
const lostPromise = new Promise((
|
|
37451
|
-
resolveLoss =
|
|
37708
|
+
const lostPromise = new Promise((resolve29) => {
|
|
37709
|
+
resolveLoss = resolve29;
|
|
37452
37710
|
});
|
|
37453
37711
|
function notifyTimerStep(event) {
|
|
37454
37712
|
try {
|
|
@@ -37486,15 +37744,18 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
37486
37744
|
const evictOwnerId = randomUUID16();
|
|
37487
37745
|
const EVICT_TTL = 5e3;
|
|
37488
37746
|
const MAX_STEAL_ATTEMPTS = 8;
|
|
37747
|
+
function isChangingLockCreate(error) {
|
|
37748
|
+
return windowsPrivateFiles2 && (isWindowsAccessDeniedCreate2(error, [lockPath], "create") || isWindowsAccessDeniedCreate2(error, [evictPath], "directory-create"));
|
|
37749
|
+
}
|
|
37489
37750
|
async function readOwner() {
|
|
37490
37751
|
if (windowsPrivateFiles2) {
|
|
37491
37752
|
try {
|
|
37492
|
-
return JSON.parse(await readPrivateText2(lockPath, true));
|
|
37753
|
+
return JSON.parse(await readLockRecord2(lockPath, () => readPrivateText2(lockPath, true)));
|
|
37493
37754
|
} catch (error) {
|
|
37494
37755
|
if (error.code !== "EISDIR" && error.reason !== "wrong-kind")
|
|
37495
37756
|
throw error;
|
|
37496
|
-
await verifyPrivate2(lockPath, "directory", true);
|
|
37497
|
-
return JSON.parse(await readPrivateText2(legacyOwnerPath, true));
|
|
37757
|
+
await readLockRecord2(lockPath, () => verifyPrivate2(lockPath, "directory", true));
|
|
37758
|
+
return JSON.parse(await readLockRecord2(legacyOwnerPath, () => readPrivateText2(legacyOwnerPath, true)));
|
|
37498
37759
|
}
|
|
37499
37760
|
}
|
|
37500
37761
|
try {
|
|
@@ -37570,8 +37831,8 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
37570
37831
|
await options.onStep("lease-contention-read-ready");
|
|
37571
37832
|
try {
|
|
37572
37833
|
if (code2 === "EISDIR") {
|
|
37573
|
-
await verifyPrivate2(lockPath, "directory", true);
|
|
37574
|
-
await readPrivateText2(legacyOwnerPath, true);
|
|
37834
|
+
await readLockRecord2(lockPath, () => verifyPrivate2(lockPath, "directory", true));
|
|
37835
|
+
await readLockRecord2(legacyOwnerPath, () => readPrivateText2(legacyOwnerPath, true));
|
|
37575
37836
|
} else
|
|
37576
37837
|
await readOwner();
|
|
37577
37838
|
} catch (readError) {
|
|
@@ -37609,7 +37870,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
37609
37870
|
}
|
|
37610
37871
|
}
|
|
37611
37872
|
async function backoff() {
|
|
37612
|
-
await new Promise((
|
|
37873
|
+
await new Promise((resolve29) => setTimeout(resolve29, Math.floor(Math.random() * 4)));
|
|
37613
37874
|
}
|
|
37614
37875
|
async function readLockState(notifyReady = true) {
|
|
37615
37876
|
if (notifyReady && options.onStep)
|
|
@@ -37618,6 +37879,8 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
37618
37879
|
try {
|
|
37619
37880
|
owner = await readOwner();
|
|
37620
37881
|
} catch (error) {
|
|
37882
|
+
if (error instanceof DisappearedLockRecordError2)
|
|
37883
|
+
return { status: "missing" };
|
|
37621
37884
|
if (windowsPrivateFiles2 && error.code !== "ENOENT")
|
|
37622
37885
|
throw error;
|
|
37623
37886
|
}
|
|
@@ -37665,7 +37928,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
37665
37928
|
}
|
|
37666
37929
|
async function ownsEvictionMarker() {
|
|
37667
37930
|
try {
|
|
37668
|
-
const owner = JSON.parse(await readPrivateText2(evictOwnerPath, windowsPrivateFiles2));
|
|
37931
|
+
const owner = JSON.parse(await readLockRecord2(evictOwnerPath, () => readPrivateText2(evictOwnerPath, windowsPrivateFiles2)));
|
|
37669
37932
|
return owner?.ownerId === evictOwnerId;
|
|
37670
37933
|
} catch (error) {
|
|
37671
37934
|
if (windowsPrivateFiles2 && error.code !== "ENOENT")
|
|
@@ -37700,7 +37963,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
37700
37963
|
const remainingMs = deadline - performance.now();
|
|
37701
37964
|
if (remainingMs <= 0)
|
|
37702
37965
|
throw original;
|
|
37703
|
-
await new Promise((
|
|
37966
|
+
await new Promise((resolve29) => setTimeout(resolve29, Math.min(delayMs, remainingMs)));
|
|
37704
37967
|
if (performance.now() >= deadline)
|
|
37705
37968
|
throw original;
|
|
37706
37969
|
delayMs = Math.min(delayMs * 2, 50);
|
|
@@ -37804,7 +38067,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
37804
38067
|
}
|
|
37805
38068
|
if (windowsPrivateFiles2) {
|
|
37806
38069
|
try {
|
|
37807
|
-
await verifyPrivate2(evictPath, "directory", true);
|
|
38070
|
+
await readLockRecord2(evictPath, () => verifyPrivate2(evictPath, "directory", true));
|
|
37808
38071
|
} catch (error) {
|
|
37809
38072
|
if (error.code === "ENOENT")
|
|
37810
38073
|
return "missing";
|
|
@@ -37859,8 +38122,8 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
37859
38122
|
if (error.code === "EEXIST") {
|
|
37860
38123
|
if (windowsPrivateFiles2) {
|
|
37861
38124
|
try {
|
|
37862
|
-
await verifyPrivate2(evictPath, "directory", true);
|
|
37863
|
-
await readPrivateText2(evictOwnerPath, true);
|
|
38125
|
+
await readLockRecord2(evictPath, () => verifyPrivate2(evictPath, "directory", true));
|
|
38126
|
+
await readLockRecord2(evictOwnerPath, () => readPrivateText2(evictOwnerPath, true));
|
|
37864
38127
|
} catch (ownerError) {
|
|
37865
38128
|
if (ownerError.code !== "ENOENT")
|
|
37866
38129
|
throw ownerError;
|
|
@@ -37881,7 +38144,11 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
37881
38144
|
try {
|
|
37882
38145
|
await releaseEvictionMarker(deadline);
|
|
37883
38146
|
} catch (error) {
|
|
37884
|
-
if (isRetryableRemoval(actionError, lockPath)
|
|
38147
|
+
if ((isRetryableRemoval(actionError, lockPath) || isWindowsAccessDeniedRead2(actionError, [
|
|
38148
|
+
lockPath,
|
|
38149
|
+
legacyOwnerPath,
|
|
38150
|
+
evictOwnerPath
|
|
38151
|
+
])) && (isRetryableRemoval(error, evictPath) || isWindowsAccessDeniedRead2(error, [evictOwnerPath])))
|
|
37885
38152
|
throw actionError;
|
|
37886
38153
|
throw error;
|
|
37887
38154
|
}
|
|
@@ -37897,7 +38164,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
37897
38164
|
try {
|
|
37898
38165
|
owner = await readOwner();
|
|
37899
38166
|
} catch (error) {
|
|
37900
|
-
if (windowsPrivateFiles2)
|
|
38167
|
+
if (windowsPrivateFiles2 && !(error instanceof DisappearedLockRecordError2))
|
|
37901
38168
|
throw error;
|
|
37902
38169
|
return;
|
|
37903
38170
|
}
|
|
@@ -37975,7 +38242,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
37975
38242
|
await options.onStep("renewal-marker-unavailable");
|
|
37976
38243
|
}
|
|
37977
38244
|
} catch (error) {
|
|
37978
|
-
if (windowsPrivateFiles2 && error instanceof PrivateFileError2) {
|
|
38245
|
+
if (windowsPrivateFiles2 && error instanceof PrivateFileError2 && !isChangingLockCreate(error)) {
|
|
37979
38246
|
terminalIOError = error;
|
|
37980
38247
|
recordLoss("renewal-failed");
|
|
37981
38248
|
shouldReschedule = false;
|
|
@@ -38021,72 +38288,90 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
38021
38288
|
}
|
|
38022
38289
|
return null;
|
|
38023
38290
|
}
|
|
38024
|
-
let acquired =
|
|
38291
|
+
let acquired = false;
|
|
38292
|
+
let changingCreateError;
|
|
38293
|
+
try {
|
|
38294
|
+
acquired = await tryAcquire();
|
|
38295
|
+
} catch (error) {
|
|
38296
|
+
if (!isChangingLockCreate(error))
|
|
38297
|
+
throw error;
|
|
38298
|
+
changingCreateError = error;
|
|
38299
|
+
}
|
|
38025
38300
|
if (!acquired) {
|
|
38026
38301
|
for (let attempt = 0; attempt < MAX_STEAL_ATTEMPTS; attempt++) {
|
|
38027
|
-
acquired = await tryAcquire();
|
|
38028
|
-
if (acquired)
|
|
38029
|
-
break;
|
|
38030
|
-
const observed = await readLockState();
|
|
38031
|
-
if (observed.status === "live")
|
|
38032
|
-
return contended();
|
|
38033
|
-
if (observed.status === "missing")
|
|
38034
|
-
continue;
|
|
38035
|
-
if (options.onStep)
|
|
38036
|
-
await options.onStep("stale-lock-observed");
|
|
38037
38302
|
try {
|
|
38038
|
-
|
|
38039
|
-
|
|
38040
|
-
|
|
38041
|
-
|
|
38042
|
-
|
|
38043
|
-
const code2 = evictError.code;
|
|
38044
|
-
if (code2 !== "EEXIST")
|
|
38045
|
-
throw evictError;
|
|
38046
|
-
const recovered = await recoverStaleEvictionMarker();
|
|
38047
|
-
if (recovered === "fresh")
|
|
38048
|
-
return null;
|
|
38049
|
-
await backoff();
|
|
38050
|
-
continue;
|
|
38051
|
-
}
|
|
38052
|
-
try {
|
|
38053
|
-
const confirmed = await readLockState();
|
|
38054
|
-
if (confirmed.status === "live")
|
|
38303
|
+
acquired = await tryAcquire();
|
|
38304
|
+
if (acquired)
|
|
38305
|
+
break;
|
|
38306
|
+
const observed = await readLockState();
|
|
38307
|
+
if (observed.status === "live")
|
|
38055
38308
|
return contended();
|
|
38056
|
-
if (
|
|
38309
|
+
if (observed.status === "missing")
|
|
38057
38310
|
continue;
|
|
38058
|
-
if (!await ownsEvictionMarker())
|
|
38059
|
-
return null;
|
|
38060
38311
|
if (options.onStep)
|
|
38061
|
-
await options.onStep("stale-lock-
|
|
38062
|
-
|
|
38063
|
-
|
|
38064
|
-
|
|
38065
|
-
|
|
38312
|
+
await options.onStep("stale-lock-observed");
|
|
38313
|
+
try {
|
|
38314
|
+
if (!await tryAcquireEvictionMarker()) {
|
|
38315
|
+
await backoff();
|
|
38316
|
+
continue;
|
|
38317
|
+
}
|
|
38318
|
+
} catch (evictError) {
|
|
38319
|
+
const code2 = evictError.code;
|
|
38320
|
+
if (code2 !== "EEXIST")
|
|
38321
|
+
throw evictError;
|
|
38322
|
+
const recovered = await recoverStaleEvictionMarker();
|
|
38323
|
+
if (recovered === "fresh")
|
|
38324
|
+
return null;
|
|
38325
|
+
await backoff();
|
|
38066
38326
|
continue;
|
|
38067
|
-
await removeLeaseObject(lockPath);
|
|
38068
|
-
if (!await ownsEvictionMarker())
|
|
38069
|
-
return null;
|
|
38070
|
-
if (options.onStep)
|
|
38071
|
-
await options.onStep("stale-lock-removed");
|
|
38072
|
-
acquired = await tryAcquire();
|
|
38073
|
-
if (!acquired)
|
|
38074
|
-
return null;
|
|
38075
|
-
if (options.onStep)
|
|
38076
|
-
await options.onStep("stale-lock-recreated");
|
|
38077
|
-
if (!await ownsEvictionMarker()) {
|
|
38078
|
-
await relinquishLockAfterMarkerLoss();
|
|
38079
|
-
acquired = false;
|
|
38080
|
-
return null;
|
|
38081
38327
|
}
|
|
38082
|
-
|
|
38083
|
-
|
|
38084
|
-
|
|
38328
|
+
try {
|
|
38329
|
+
const confirmed = await readLockState();
|
|
38330
|
+
if (confirmed.status === "live")
|
|
38331
|
+
return contended();
|
|
38332
|
+
if (!sameStaleLock(observed.identity, confirmed))
|
|
38333
|
+
continue;
|
|
38334
|
+
if (!await ownsEvictionMarker())
|
|
38335
|
+
return null;
|
|
38336
|
+
if (options.onStep)
|
|
38337
|
+
await options.onStep("stale-lock-confirmed");
|
|
38338
|
+
if (!await ownsEvictionMarker())
|
|
38339
|
+
return null;
|
|
38340
|
+
const current = await readLockState(false);
|
|
38341
|
+
if (!sameStaleLock(observed.identity, current))
|
|
38342
|
+
continue;
|
|
38343
|
+
await removeLeaseObject(lockPath);
|
|
38344
|
+
if (!await ownsEvictionMarker())
|
|
38345
|
+
return null;
|
|
38346
|
+
if (options.onStep)
|
|
38347
|
+
await options.onStep("stale-lock-removed");
|
|
38348
|
+
acquired = await tryAcquire();
|
|
38349
|
+
if (!acquired)
|
|
38350
|
+
return null;
|
|
38351
|
+
if (options.onStep)
|
|
38352
|
+
await options.onStep("stale-lock-recreated");
|
|
38353
|
+
if (!await ownsEvictionMarker()) {
|
|
38354
|
+
await relinquishLockAfterMarkerLoss();
|
|
38355
|
+
acquired = false;
|
|
38356
|
+
return null;
|
|
38357
|
+
}
|
|
38358
|
+
break;
|
|
38359
|
+
} finally {
|
|
38360
|
+
await releaseEvictionMarker();
|
|
38361
|
+
}
|
|
38362
|
+
} catch (error) {
|
|
38363
|
+
if (!isChangingLockCreate(error))
|
|
38364
|
+
throw error;
|
|
38365
|
+
changingCreateError ??= error;
|
|
38366
|
+
await backoff();
|
|
38085
38367
|
}
|
|
38086
38368
|
}
|
|
38087
38369
|
}
|
|
38088
|
-
if (!acquired)
|
|
38370
|
+
if (!acquired) {
|
|
38371
|
+
if (changingCreateError)
|
|
38372
|
+
throw changingCreateError;
|
|
38089
38373
|
return null;
|
|
38374
|
+
}
|
|
38090
38375
|
scheduleRenewal();
|
|
38091
38376
|
return {
|
|
38092
38377
|
ownerId,
|
|
@@ -38124,6 +38409,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
38124
38409
|
const deadline = performance.now() + EVICT_TTL + 1e3;
|
|
38125
38410
|
let delayMs = 5;
|
|
38126
38411
|
let removalError;
|
|
38412
|
+
let changingRecordError;
|
|
38127
38413
|
for (; ; ) {
|
|
38128
38414
|
try {
|
|
38129
38415
|
let removalConfirmed = false;
|
|
@@ -38149,6 +38435,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
38149
38435
|
await removeLeaseObject(lockPath);
|
|
38150
38436
|
removalConfirmed = true;
|
|
38151
38437
|
}, deadline);
|
|
38438
|
+
changingRecordError = void 0;
|
|
38152
38439
|
if (markerAcquired) {
|
|
38153
38440
|
if (windowsPrivateFiles2 && !removalConfirmed)
|
|
38154
38441
|
throw new PrivateFileError2(lockPath, "release-not-confirmed", {
|
|
@@ -38161,23 +38448,32 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
38161
38448
|
return;
|
|
38162
38449
|
await recoverStaleEvictionMarker(deadline);
|
|
38163
38450
|
} catch (error) {
|
|
38164
|
-
|
|
38451
|
+
const changingRecord = windowsPrivateFiles2 && (isChangingLockCreate(error) || isWindowsAccessDeniedRead2(error, [
|
|
38452
|
+
lockPath,
|
|
38453
|
+
legacyOwnerPath,
|
|
38454
|
+
evictPath,
|
|
38455
|
+
evictOwnerPath
|
|
38456
|
+
]));
|
|
38457
|
+
if (!isRetryableRemoval(error, lockPath) && !changingRecord) {
|
|
38165
38458
|
if (windowsPrivateFiles2)
|
|
38166
38459
|
throw error;
|
|
38167
38460
|
return;
|
|
38168
38461
|
}
|
|
38169
|
-
|
|
38462
|
+
if (changingRecord)
|
|
38463
|
+
changingRecordError ??= error;
|
|
38464
|
+
else
|
|
38465
|
+
removalError ??= error;
|
|
38170
38466
|
}
|
|
38171
38467
|
const remainingMs = deadline - performance.now();
|
|
38172
38468
|
if (remainingMs <= 0)
|
|
38173
38469
|
break;
|
|
38174
|
-
await new Promise((
|
|
38470
|
+
await new Promise((resolve29) => setTimeout(resolve29, Math.min(delayMs, remainingMs)));
|
|
38175
38471
|
if (windowsPrivateFiles2 && performance.now() >= deadline)
|
|
38176
38472
|
break;
|
|
38177
38473
|
delayMs = Math.min(delayMs * 2, 50);
|
|
38178
38474
|
}
|
|
38179
38475
|
if (windowsPrivateFiles2)
|
|
38180
|
-
throw removalError ?? new PrivateFileError2(lockPath, "release-not-confirmed", {
|
|
38476
|
+
throw changingRecordError ?? removalError ?? new PrivateFileError2(lockPath, "release-not-confirmed", {
|
|
38181
38477
|
code: "ETIMEDOUT"
|
|
38182
38478
|
});
|
|
38183
38479
|
}
|
|
@@ -38317,6 +38613,10 @@ function classifyEnrollmentError2(error) {
|
|
|
38317
38613
|
disposition: error.action === "retry" ? "retry" : "terminal"
|
|
38318
38614
|
};
|
|
38319
38615
|
}
|
|
38616
|
+
function validEnrollmentDisplayName2(displayName) {
|
|
38617
|
+
const length = Array.from(displayName).length;
|
|
38618
|
+
return length >= 1 && length <= 40 && !/[\p{Cc}\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069\u200b-\u200d\u2060\ufeff]/u.test(displayName);
|
|
38619
|
+
}
|
|
38320
38620
|
function connectClaustrumEnrollmentClient2(options) {
|
|
38321
38621
|
return ClaustrumWireClient2.connect(options);
|
|
38322
38622
|
}
|
|
@@ -38332,7 +38632,7 @@ function hostEnrollmentPaths2(input2) {
|
|
|
38332
38632
|
const override = input2.override?.trim();
|
|
38333
38633
|
if (override && !isAbsolute4(override) && !input2.cwd)
|
|
38334
38634
|
throw new ClaustrumConsumerError2("invalid-state", "A relative Claustrum enrollment override needs a base directory");
|
|
38335
|
-
const tokenPath = override ? isAbsolute4(override) ? override :
|
|
38635
|
+
const tokenPath = override ? isAbsolute4(override) ? override : resolve21(input2.cwd, override) : join20(input2.stateDir, `${input2.host}-enrollment.json`);
|
|
38336
38636
|
return getClaustrumEnrollmentPaths2(tokenPath);
|
|
38337
38637
|
}
|
|
38338
38638
|
function isRecord11(value) {
|
|
@@ -38693,15 +38993,19 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
38693
38993
|
#client;
|
|
38694
38994
|
#paths;
|
|
38695
38995
|
#proposedName;
|
|
38996
|
+
#displayName;
|
|
38696
38997
|
#now;
|
|
38697
38998
|
#mintSecret;
|
|
38698
38999
|
#writeTokenFile;
|
|
38699
39000
|
#ancestorOptions;
|
|
38700
39001
|
constructor(options) {
|
|
39002
|
+
if (options.displayName !== void 0 && !validEnrollmentDisplayName2(options.displayName))
|
|
39003
|
+
throw new ClaustrumConsumerError2("invalid-state", "invalid Claustrum enrollment display name");
|
|
38701
39004
|
this.#ancestorOptions = options.ancestorOptions ?? {};
|
|
38702
39005
|
this.#client = options.client;
|
|
38703
39006
|
this.#paths = options.paths;
|
|
38704
39007
|
this.#proposedName = options.proposedName;
|
|
39008
|
+
this.#displayName = options.displayName;
|
|
38705
39009
|
this.#now = options.now ?? Date.now;
|
|
38706
39010
|
this.#mintSecret = options.mintSecret ?? (() => randomBytes5(32).toString("hex"));
|
|
38707
39011
|
this.#writeTokenFile = options.writeTokenFile ?? writeEnrollmentTokenFile2;
|
|
@@ -38791,10 +39095,23 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
38791
39095
|
if (!state.requestId) {
|
|
38792
39096
|
try {
|
|
38793
39097
|
const requestSecretHash = createHash13("sha256").update(Buffer.from(state.requestSecret, "hex")).digest("hex");
|
|
38794
|
-
const
|
|
39098
|
+
const proposal = {
|
|
38795
39099
|
name: state.proposedName,
|
|
38796
39100
|
requestSecretHash
|
|
38797
|
-
}
|
|
39101
|
+
};
|
|
39102
|
+
let proposed;
|
|
39103
|
+
try {
|
|
39104
|
+
proposed = await this.#client.enrollPropose({
|
|
39105
|
+
...proposal,
|
|
39106
|
+
...this.#displayName !== void 0 && {
|
|
39107
|
+
displayName: this.#displayName
|
|
39108
|
+
}
|
|
39109
|
+
});
|
|
39110
|
+
} catch (error) {
|
|
39111
|
+
if (this.#displayName === void 0 || !(error instanceof ClaustrumCredentialError9) || error.code !== "invalid_params")
|
|
39112
|
+
throw error;
|
|
39113
|
+
proposed = await this.#client.enrollPropose(proposal);
|
|
39114
|
+
}
|
|
38798
39115
|
state = {
|
|
38799
39116
|
...state,
|
|
38800
39117
|
requestId: proposed.requestId,
|
|
@@ -38965,7 +39282,7 @@ var ByteTail = class {
|
|
|
38965
39282
|
};
|
|
38966
39283
|
var defaultCommandRunner = {
|
|
38967
39284
|
run(file, args, options = {}) {
|
|
38968
|
-
return new Promise((
|
|
39285
|
+
return new Promise((resolve29) => {
|
|
38969
39286
|
const started = performance.now();
|
|
38970
39287
|
const timeoutMs = options.timeoutMs ?? 15e3;
|
|
38971
39288
|
const stderr = new ByteTail();
|
|
@@ -38983,7 +39300,7 @@ var defaultCommandRunner = {
|
|
|
38983
39300
|
stdio: ["ignore", "pipe", "pipe"]
|
|
38984
39301
|
});
|
|
38985
39302
|
} catch {
|
|
38986
|
-
|
|
39303
|
+
resolve29({
|
|
38987
39304
|
exitCode: 1,
|
|
38988
39305
|
stdout: "",
|
|
38989
39306
|
stderr: "",
|
|
@@ -39018,7 +39335,7 @@ var defaultCommandRunner = {
|
|
|
39018
39335
|
settled = true;
|
|
39019
39336
|
if (timer)
|
|
39020
39337
|
clearTimeout(timer);
|
|
39021
|
-
|
|
39338
|
+
resolve29({
|
|
39022
39339
|
exitCode: spawnError ? 1 : outputExceeded ? 1 : code2 ?? 1,
|
|
39023
39340
|
stdout: Buffer.concat(stdout, stdoutLength).toString("utf8"),
|
|
39024
39341
|
stderr: stderr.toString(),
|
|
@@ -39630,7 +39947,7 @@ function approveCommand(requestId, name) {
|
|
|
39630
39947
|
async function connectSetupHost(plugin, host, io, terminal, fence) {
|
|
39631
39948
|
if (hasVaultHost2())
|
|
39632
39949
|
throw new Error(VAULT_HOST_CONNECT_REFUSAL2);
|
|
39633
|
-
const { name, paths: input2 } = plugin.vault.hosts[host];
|
|
39950
|
+
const { name, displayName, paths: input2 } = plugin.vault.hosts[host];
|
|
39634
39951
|
const paths = hostEnrollmentPaths2(input2);
|
|
39635
39952
|
await fence();
|
|
39636
39953
|
const client = await (io.connect ?? connectClaustrumEnrollmentClient2)({
|
|
@@ -39644,6 +39961,7 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
|
|
|
39644
39961
|
try {
|
|
39645
39962
|
const manager = new ClaustrumEnrollmentManager2({
|
|
39646
39963
|
proposedName: name,
|
|
39964
|
+
displayName,
|
|
39647
39965
|
paths,
|
|
39648
39966
|
// Each tick of the wait below checks the fence once, just before
|
|
39649
39967
|
// reconcile proposes or polls. Checking again inside every vault call
|
|
@@ -40437,7 +40755,7 @@ async function writeNativeSlot(host, slot, context, expectedAuthority = "local")
|
|
|
40437
40755
|
beforeRename: async () => {
|
|
40438
40756
|
await assertSetupHostsStopped();
|
|
40439
40757
|
const claustrum = await loadCommonAuthClaustrum();
|
|
40440
|
-
const stateDir = host === "opencode" ? openCodeVaultDir(
|
|
40758
|
+
const stateDir = host === "opencode" ? openCodeVaultDir(resolve22(accountFileForVault())) : getPiAntigravityVaultDir();
|
|
40441
40759
|
if (await claustrum.vaultAuthority(
|
|
40442
40760
|
claustrum.hostEnrollmentPaths({ stateDir, host }),
|
|
40443
40761
|
`antigravity-auth-${host}`
|
|
@@ -40471,17 +40789,19 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
40471
40789
|
const hosts = {
|
|
40472
40790
|
opencode: {
|
|
40473
40791
|
name: OPENCODE_VAULT_ENROLLMENT_NAME,
|
|
40792
|
+
displayName: "Antigravity sign-in for OpenCode",
|
|
40474
40793
|
// Read at each use: a real run settles the vault folder in
|
|
40475
40794
|
// `beforeSignIn`, which may move it after this plugin is built.
|
|
40476
40795
|
paths: {
|
|
40477
40796
|
get stateDir() {
|
|
40478
|
-
return openCodeVaultDir(
|
|
40797
|
+
return openCodeVaultDir(resolve22(accountFileForVault()));
|
|
40479
40798
|
},
|
|
40480
40799
|
host: "opencode"
|
|
40481
40800
|
}
|
|
40482
40801
|
},
|
|
40483
40802
|
pi: {
|
|
40484
40803
|
name: "antigravity-auth-pi",
|
|
40804
|
+
displayName: "Antigravity sign-in for Pi",
|
|
40485
40805
|
paths: { stateDir: piDir, host: "pi" }
|
|
40486
40806
|
}
|
|
40487
40807
|
};
|
|
@@ -40492,7 +40812,7 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
40492
40812
|
const assertLocal = async (host, context) => {
|
|
40493
40813
|
if (host === "opencode")
|
|
40494
40814
|
return assertLocalOpenCodeLogin(
|
|
40495
|
-
|
|
40815
|
+
resolve22(accountFileForVault()),
|
|
40496
40816
|
context.opencodeGeneration
|
|
40497
40817
|
);
|
|
40498
40818
|
if (await authority(host) !== "local")
|
|
@@ -41152,7 +41472,7 @@ async function runCliProcess(argv, deps) {
|
|
|
41152
41472
|
...deps,
|
|
41153
41473
|
prepareVaultFolder: deps.prepareVaultFolder ?? (async (options) => {
|
|
41154
41474
|
const folder = await prepareVaultFolder({
|
|
41155
|
-
accountFile:
|
|
41475
|
+
accountFile: resolve23(accountFileForVault()),
|
|
41156
41476
|
...options
|
|
41157
41477
|
});
|
|
41158
41478
|
if (folder.refusal) throw folder.refusal;
|
|
@@ -41198,11 +41518,11 @@ function createDefaultCliDependencies() {
|
|
|
41198
41518
|
);
|
|
41199
41519
|
if (host !== "pi")
|
|
41200
41520
|
await assertLocalOpenCodeLogin(
|
|
41201
|
-
|
|
41521
|
+
resolve23(accountFileForVault()),
|
|
41202
41522
|
context?.opencodeGeneration
|
|
41203
41523
|
);
|
|
41204
41524
|
const repository = host === "pi" ? void 0 : await prepareCliLoginStore(
|
|
41205
|
-
|
|
41525
|
+
resolve23(getStoragePath()),
|
|
41206
41526
|
context?.opencodeGeneration
|
|
41207
41527
|
);
|
|
41208
41528
|
try {
|
|
@@ -41218,7 +41538,7 @@ function createDefaultCliDependencies() {
|
|
|
41218
41538
|
}
|
|
41219
41539
|
if (host === "opencode") await assertSetupHostsStopped();
|
|
41220
41540
|
await assertLocalOpenCodeLogin(
|
|
41221
|
-
|
|
41541
|
+
resolve23(accountFileForVault()),
|
|
41222
41542
|
context?.opencodeGeneration
|
|
41223
41543
|
);
|
|
41224
41544
|
await persistCliStoreLogin(
|
|
@@ -41238,7 +41558,7 @@ function createDefaultCliDependencies() {
|
|
|
41238
41558
|
};
|
|
41239
41559
|
}
|
|
41240
41560
|
async function prepareCliLoginStore(legacyPath, generation) {
|
|
41241
|
-
await assertLocalOpenCodeLogin(
|
|
41561
|
+
await assertLocalOpenCodeLogin(resolve23(accountFileForVault()), generation);
|
|
41242
41562
|
const modules = await loadCommonAuthStoreModules();
|
|
41243
41563
|
const options = {
|
|
41244
41564
|
legacyPath,
|
|
@@ -41383,7 +41703,7 @@ async function readAccountStore(legacyPath) {
|
|
|
41383
41703
|
function createDefaultAccountStoreOperations() {
|
|
41384
41704
|
const offline = { processesStopped: true };
|
|
41385
41705
|
return {
|
|
41386
|
-
legacyPath: () =>
|
|
41706
|
+
legacyPath: () => resolve23(
|
|
41387
41707
|
decidedAccountStoreAnchor(runtimeLayoutLocation()) ? getStoragePath() : discoveredAccountFile()
|
|
41388
41708
|
),
|
|
41389
41709
|
migrate: async (legacyPath) => createAccountMigrationFactory(await loadCommonAuthStoreModules())({
|
|
@@ -41414,7 +41734,7 @@ function createDefaultAccountStoreOperations() {
|
|
|
41414
41734
|
};
|
|
41415
41735
|
}
|
|
41416
41736
|
function samePath(left, right) {
|
|
41417
|
-
return process.platform === "win32" ?
|
|
41737
|
+
return process.platform === "win32" ? resolve23(left).toLowerCase() === resolve23(right).toLowerCase() : resolve23(left) === resolve23(right);
|
|
41418
41738
|
}
|
|
41419
41739
|
function isCliEntry() {
|
|
41420
41740
|
if (import.meta.main !== void 0) return import.meta.main;
|
|
@@ -41904,14 +42224,14 @@ function isTuiConnected(sessionId) {
|
|
|
41904
42224
|
// src/rpc/rpc-dir.ts
|
|
41905
42225
|
import { createHash as createHash14 } from "node:crypto";
|
|
41906
42226
|
import { homedir as homedir10, tmpdir as tmpdir4 } from "node:os";
|
|
41907
|
-
import { isAbsolute as isAbsolute5, join as join28, resolve as
|
|
42227
|
+
import { isAbsolute as isAbsolute5, join as join28, resolve as resolve24 } from "node:path";
|
|
41908
42228
|
var RPC_DIR_ENV = "ANTIGRAVITY_AUTH_RPC_DIR";
|
|
41909
42229
|
function getRpcDir(projectDirectory) {
|
|
41910
42230
|
const override = process.env[RPC_DIR_ENV]?.trim();
|
|
41911
42231
|
if (override) {
|
|
41912
|
-
return isAbsolute5(override) ? override :
|
|
42232
|
+
return isAbsolute5(override) ? override : resolve24(projectDirectory, override);
|
|
41913
42233
|
}
|
|
41914
|
-
const projectHash = createHash14("sha256").update(
|
|
42234
|
+
const projectHash = createHash14("sha256").update(resolve24(projectDirectory)).digest("hex").slice(0, 16);
|
|
41915
42235
|
const stateHome = process.env.XDG_STATE_HOME ?? join28(homedir10(), ".local", "state");
|
|
41916
42236
|
return join28(stateHome, "cortexkit", "antigravity-auth", "rpc", projectHash);
|
|
41917
42237
|
}
|
|
@@ -41926,7 +42246,7 @@ init_private_files2();
|
|
|
41926
42246
|
import { createHash as createHash15, randomUUID as randomUUID19 } from "node:crypto";
|
|
41927
42247
|
import { chmod as chmod7, mkdir as mkdir17, open as open12, readdir as readdir4, rename as rename14, rmdir as rmdir3, stat as stat17, unlink as unlink13 } from "node:fs/promises";
|
|
41928
42248
|
import { uptime as uptime2 } from "node:os";
|
|
41929
|
-
import { join as join29, resolve as
|
|
42249
|
+
import { join as join29, resolve as resolve25 } from "node:path";
|
|
41930
42250
|
function staleBefore(clock2) {
|
|
41931
42251
|
return (clock2.now ?? Date.now)() - (clock2.uptime ?? uptime2)() * 1e3 - 3e5;
|
|
41932
42252
|
}
|
|
@@ -42036,7 +42356,7 @@ async function sweepRpcState(root, activeDir, isManagedDir, log17, options = {})
|
|
|
42036
42356
|
return;
|
|
42037
42357
|
throw error;
|
|
42038
42358
|
}
|
|
42039
|
-
const active2 =
|
|
42359
|
+
const active2 = resolve25(activeDir);
|
|
42040
42360
|
for (const projectDir of projectDirs) {
|
|
42041
42361
|
if (!projectDir.isDirectory() || !isManagedDir(projectDir.name)) {
|
|
42042
42362
|
continue;
|
|
@@ -42083,7 +42403,7 @@ async function sweepRpcState(root, activeDir, isManagedDir, log17, options = {})
|
|
|
42083
42403
|
else if (isStalePortFile(entry, info, cutoff))
|
|
42084
42404
|
await removeStalePortFile(portFile, raw, info, options.beforeRemove);
|
|
42085
42405
|
}
|
|
42086
|
-
if (
|
|
42406
|
+
if (resolve25(dir) !== active2)
|
|
42087
42407
|
await rmdir3(dir).catch(() => {
|
|
42088
42408
|
});
|
|
42089
42409
|
}
|
|
@@ -42117,7 +42437,7 @@ var BodyTooLargeError = class extends Error {
|
|
|
42117
42437
|
}
|
|
42118
42438
|
};
|
|
42119
42439
|
function readBody(req) {
|
|
42120
|
-
return new Promise((
|
|
42440
|
+
return new Promise((resolve29, reject) => {
|
|
42121
42441
|
const tooLarge = (declaredOversize = false) => {
|
|
42122
42442
|
req.removeAllListeners("data");
|
|
42123
42443
|
req.on("data", () => {
|
|
@@ -42140,7 +42460,7 @@ function readBody(req) {
|
|
|
42140
42460
|
}
|
|
42141
42461
|
chunks.push(chunk);
|
|
42142
42462
|
});
|
|
42143
|
-
req.on("end", () =>
|
|
42463
|
+
req.on("end", () => resolve29(Buffer.concat(chunks).toString("utf8")));
|
|
42144
42464
|
req.on("error", reject);
|
|
42145
42465
|
});
|
|
42146
42466
|
}
|
|
@@ -42319,12 +42639,12 @@ async function startRpcServer(options) {
|
|
|
42319
42639
|
json(500, { error: "internal error" });
|
|
42320
42640
|
}
|
|
42321
42641
|
}
|
|
42322
|
-
const port = await new Promise((
|
|
42642
|
+
const port = await new Promise((resolve29, reject) => {
|
|
42323
42643
|
server.on("error", reject);
|
|
42324
42644
|
server.listen(0, "127.0.0.1", () => {
|
|
42325
42645
|
const addr = server.address();
|
|
42326
42646
|
if (addr && typeof addr === "object")
|
|
42327
|
-
|
|
42647
|
+
resolve29(addr.port);
|
|
42328
42648
|
else
|
|
42329
42649
|
reject(new Error("no port"));
|
|
42330
42650
|
});
|
|
@@ -42347,16 +42667,16 @@ async function startRpcServer(options) {
|
|
|
42347
42667
|
rpcPort: port
|
|
42348
42668
|
});
|
|
42349
42669
|
} catch (error) {
|
|
42350
|
-
await new Promise((
|
|
42670
|
+
await new Promise((resolve29) => server.close(() => resolve29()));
|
|
42351
42671
|
throw error;
|
|
42352
42672
|
}
|
|
42353
42673
|
return {
|
|
42354
42674
|
port,
|
|
42355
42675
|
token,
|
|
42356
42676
|
async stop() {
|
|
42357
|
-
await new Promise((
|
|
42677
|
+
await new Promise((resolve29) => {
|
|
42358
42678
|
server.closeAllConnections?.();
|
|
42359
|
-
server.close(() =>
|
|
42679
|
+
server.close(() => resolve29());
|
|
42360
42680
|
for (const socket of connections)
|
|
42361
42681
|
socket.destroy();
|
|
42362
42682
|
});
|
|
@@ -43733,7 +44053,7 @@ async function select3(items, options) {
|
|
|
43733
44053
|
}
|
|
43734
44054
|
renderedLines = linesWritten;
|
|
43735
44055
|
};
|
|
43736
|
-
return new Promise((
|
|
44056
|
+
return new Promise((resolve29) => {
|
|
43737
44057
|
const wasRaw = stdin.isRaw ?? false;
|
|
43738
44058
|
const cleanup2 = () => {
|
|
43739
44059
|
if (isCleanedUp) return;
|
|
@@ -43754,11 +44074,11 @@ async function select3(items, options) {
|
|
|
43754
44074
|
};
|
|
43755
44075
|
const onSignal = () => {
|
|
43756
44076
|
cleanup2();
|
|
43757
|
-
|
|
44077
|
+
resolve29(null);
|
|
43758
44078
|
};
|
|
43759
44079
|
const finishWithValue = (value) => {
|
|
43760
44080
|
cleanup2();
|
|
43761
|
-
|
|
44081
|
+
resolve29(value);
|
|
43762
44082
|
};
|
|
43763
44083
|
const findNextSelectable = (from, direction) => {
|
|
43764
44084
|
if (items.length === 0) return from;
|
|
@@ -43804,7 +44124,7 @@ async function select3(items, options) {
|
|
|
43804
44124
|
stdin.setRawMode(true);
|
|
43805
44125
|
} catch {
|
|
43806
44126
|
cleanup2();
|
|
43807
|
-
|
|
44127
|
+
resolve29(null);
|
|
43808
44128
|
return;
|
|
43809
44129
|
}
|
|
43810
44130
|
stdin.resume();
|
|
@@ -46570,7 +46890,7 @@ init_runtime_paths();
|
|
|
46570
46890
|
init_logger4();
|
|
46571
46891
|
import { existsSync as existsSync11, readFileSync as readFileSync11, realpathSync as realpathSync5 } from "node:fs";
|
|
46572
46892
|
import { homedir as homedir12 } from "node:os";
|
|
46573
|
-
import { basename as basename7, dirname as dirname25, join as join33, resolve as
|
|
46893
|
+
import { basename as basename7, dirname as dirname25, join as join33, resolve as resolve26 } from "node:path";
|
|
46574
46894
|
|
|
46575
46895
|
// src/plugin/config/schema.ts
|
|
46576
46896
|
import { z } from "zod";
|
|
@@ -47128,7 +47448,7 @@ function loadConfigWithLogger(directory, log17) {
|
|
|
47128
47448
|
return config;
|
|
47129
47449
|
}
|
|
47130
47450
|
function canonicalizeOwnedPath(path5) {
|
|
47131
|
-
const absolute =
|
|
47451
|
+
const absolute = resolve26(path5);
|
|
47132
47452
|
const missing = [];
|
|
47133
47453
|
let current = absolute;
|
|
47134
47454
|
for (; ; ) {
|
|
@@ -51013,7 +51333,7 @@ function stripUnsupportedAntigravityFields(payload) {
|
|
|
51013
51333
|
}
|
|
51014
51334
|
}
|
|
51015
51335
|
function configureAntigravityToolCalling(payload, wireModel) {
|
|
51016
|
-
if (isGeminiArgonModel(wireModel) || !Array.isArray(payload.tools) || payload.tools.length === 0) {
|
|
51336
|
+
if (isGeminiArgonModel(wireModel) || isGeminiCarbonModel(wireModel) || !Array.isArray(payload.tools) || payload.tools.length === 0) {
|
|
51017
51337
|
delete payload.toolConfig;
|
|
51018
51338
|
return;
|
|
51019
51339
|
}
|
|
@@ -51636,7 +51956,7 @@ function prepareAntigravityRequestIn(wire, input2, init, accessToken, projectId,
|
|
|
51636
51956
|
`[ThinkingResolution] rawModel=${rawModel} resolvedModel=${effectiveModel} resolvedTier=${tierThinkingLevel ?? "none"} variantLevel=${variantConfig?.thinkingLevel ?? "none"} variantBudget=${variantConfig?.thinkingBudget ?? "none"} providerOptions.google=${JSON.stringify(requestPayload.providerOptions?.google ?? null)} generationConfig.thinkingConfig=${JSON.stringify(rawGenerationConfig?.thinkingConfig ?? null)}`
|
|
51637
51957
|
);
|
|
51638
51958
|
delete requestPayload.providerOptions;
|
|
51639
|
-
if (variantConfig?.thinkingLevel && (isGemini3 || isGeminiArgonModel(effectiveModel) || getAgyNativeModel(effectiveModel)?.supportsAdaptiveThinking)) {
|
|
51959
|
+
if (variantConfig?.thinkingLevel && (isGemini3 || isGeminiArgonModel(effectiveModel) || isGeminiCarbonModel(effectiveModel) || getAgyNativeModel(effectiveModel)?.supportsAdaptiveThinking)) {
|
|
51640
51960
|
const variantModelBase = rawModel.replace(/-preview-customtools$/i, "").replace(/-preview$/i, "").replace(/-(minimal|low|medium|high)$/i, "");
|
|
51641
51961
|
const variantResolved = resolveAntigravityModel(
|
|
51642
51962
|
`${variantModelBase}-${variantConfig.thinkingLevel}`
|
|
@@ -52580,10 +52900,10 @@ async function retainResponseLifetime(response, cancellation) {
|
|
|
52580
52900
|
cancellation.release();
|
|
52581
52901
|
throw error;
|
|
52582
52902
|
}
|
|
52583
|
-
let
|
|
52903
|
+
let resolve29 = () => {
|
|
52584
52904
|
};
|
|
52585
52905
|
const settled = new Promise((done) => {
|
|
52586
|
-
|
|
52906
|
+
resolve29 = done;
|
|
52587
52907
|
});
|
|
52588
52908
|
let stopping = false;
|
|
52589
52909
|
let finished = false;
|
|
@@ -52593,7 +52913,7 @@ async function retainResponseLifetime(response, cancellation) {
|
|
|
52593
52913
|
finished = true;
|
|
52594
52914
|
cancellation.signal.removeEventListener("abort", abort);
|
|
52595
52915
|
cancellation.release();
|
|
52596
|
-
|
|
52916
|
+
resolve29();
|
|
52597
52917
|
};
|
|
52598
52918
|
const abort = () => {
|
|
52599
52919
|
if (finished || stopping) return;
|
|
@@ -52662,8 +52982,8 @@ function createAfterHandoff(work, signals, onFailure) {
|
|
|
52662
52982
|
let running = false;
|
|
52663
52983
|
let resolveCompletion = () => {
|
|
52664
52984
|
};
|
|
52665
|
-
const completion = new Promise((
|
|
52666
|
-
resolveCompletion =
|
|
52985
|
+
const completion = new Promise((resolve29) => {
|
|
52986
|
+
resolveCompletion = resolve29;
|
|
52667
52987
|
});
|
|
52668
52988
|
const finish = () => {
|
|
52669
52989
|
if (finished) return;
|
|
@@ -52710,14 +53030,14 @@ function createAfterHandoff(work, signals, onFailure) {
|
|
|
52710
53030
|
};
|
|
52711
53031
|
}
|
|
52712
53032
|
function publishResponse(dispatch) {
|
|
52713
|
-
return new Promise((
|
|
53033
|
+
return new Promise((resolve29, reject) => {
|
|
52714
53034
|
let acknowledge;
|
|
52715
53035
|
void Promise.resolve().then(
|
|
52716
53036
|
() => dispatch((callback) => {
|
|
52717
53037
|
acknowledge = callback;
|
|
52718
53038
|
})
|
|
52719
53039
|
).then((response) => {
|
|
52720
|
-
|
|
53040
|
+
resolve29(response);
|
|
52721
53041
|
acknowledge?.();
|
|
52722
53042
|
}, reject);
|
|
52723
53043
|
});
|
|
@@ -54551,10 +54871,10 @@ function resolvePluginDependencies(overrides = {}) {
|
|
|
54551
54871
|
}
|
|
54552
54872
|
async function defaultSleep(ms, signal) {
|
|
54553
54873
|
if (ms <= 0) return;
|
|
54554
|
-
await new Promise((
|
|
54874
|
+
await new Promise((resolve29, reject) => {
|
|
54555
54875
|
const timer = setTimeout(() => {
|
|
54556
54876
|
signal?.removeEventListener("abort", onAbort);
|
|
54557
|
-
|
|
54877
|
+
resolve29();
|
|
54558
54878
|
}, ms);
|
|
54559
54879
|
timer.unref?.();
|
|
54560
54880
|
const onAbort = () => {
|
|
@@ -54685,10 +55005,72 @@ function routingHandle(sessionId) {
|
|
|
54685
55005
|
return typeof handle === "object" && handle !== null ? handle : void 0;
|
|
54686
55006
|
}
|
|
54687
55007
|
|
|
55008
|
+
// src/common-auth-embedded/routing-accessor/cache-policy.js
|
|
55009
|
+
var CACHE_WARM_STOP_REASONS = [
|
|
55010
|
+
"cost-cap",
|
|
55011
|
+
"count-cap",
|
|
55012
|
+
"outside-hours",
|
|
55013
|
+
"session-ended",
|
|
55014
|
+
"unsupported"
|
|
55015
|
+
];
|
|
55016
|
+
function isCacheWarmStopReason(value) {
|
|
55017
|
+
return CACHE_WARM_STOP_REASONS.some((reason) => reason === value);
|
|
55018
|
+
}
|
|
55019
|
+
|
|
54688
55020
|
// src/common-auth-embedded/routing-accessor/index.js
|
|
54689
55021
|
function isObject2(value) {
|
|
54690
55022
|
return typeof value === "object" && value !== null;
|
|
54691
55023
|
}
|
|
55024
|
+
function isNonEmptyString(value) {
|
|
55025
|
+
return typeof value === "string" && value.length > 0;
|
|
55026
|
+
}
|
|
55027
|
+
function billingCache(value) {
|
|
55028
|
+
if (!isObject2(value) || Array.isArray(value))
|
|
55029
|
+
return;
|
|
55030
|
+
const { ttlMs, implicit, warming } = value;
|
|
55031
|
+
const cache = {};
|
|
55032
|
+
if (!(ttlMs !== void 0 && implicit !== void 0)) {
|
|
55033
|
+
if (typeof ttlMs === "number" && Number.isSafeInteger(ttlMs) && ttlMs > 0) {
|
|
55034
|
+
cache.ttl_ms = ttlMs;
|
|
55035
|
+
} else if (implicit === true) {
|
|
55036
|
+
cache.implicit = true;
|
|
55037
|
+
}
|
|
55038
|
+
}
|
|
55039
|
+
if (isObject2(warming) && !Array.isArray(warming)) {
|
|
55040
|
+
const { on, stopReason } = warming;
|
|
55041
|
+
if (typeof on === "boolean") {
|
|
55042
|
+
cache.warming = {
|
|
55043
|
+
on,
|
|
55044
|
+
...!on && isCacheWarmStopReason(stopReason) ? { stop_reason: stopReason } : {}
|
|
55045
|
+
};
|
|
55046
|
+
}
|
|
55047
|
+
}
|
|
55048
|
+
return Object.keys(cache).length > 0 ? cache : void 0;
|
|
55049
|
+
}
|
|
55050
|
+
function billingUsage(value) {
|
|
55051
|
+
if (!isObject2(value) || Array.isArray(value))
|
|
55052
|
+
return;
|
|
55053
|
+
const usage = {};
|
|
55054
|
+
for (const [inputKey, payloadKey] of [
|
|
55055
|
+
["input", "input"],
|
|
55056
|
+
["output", "output"],
|
|
55057
|
+
["cacheRead", "cache_read"],
|
|
55058
|
+
["cacheWrite", "cache_write"],
|
|
55059
|
+
["cacheWrite5m", "cache_write_5m"],
|
|
55060
|
+
["cacheWrite1h", "cache_write_1h"],
|
|
55061
|
+
["reasoning", "reasoning"]
|
|
55062
|
+
]) {
|
|
55063
|
+
const count3 = value[inputKey];
|
|
55064
|
+
if (typeof count3 === "number" && Number.isSafeInteger(count3) && count3 >= 0) {
|
|
55065
|
+
usage[payloadKey] = count3;
|
|
55066
|
+
}
|
|
55067
|
+
}
|
|
55068
|
+
const reasoningIncludedInOutput = value.reasoningIncludedInOutput;
|
|
55069
|
+
if (typeof reasoningIncludedInOutput === "boolean") {
|
|
55070
|
+
usage.reasoning_included_in_output = reasoningIncludedInOutput;
|
|
55071
|
+
}
|
|
55072
|
+
return Object.keys(usage).length > 0 ? usage : void 0;
|
|
55073
|
+
}
|
|
54692
55074
|
function selectionFor(answer, candidates) {
|
|
54693
55075
|
if (!isObject2(answer))
|
|
54694
55076
|
return void 0;
|
|
@@ -54720,8 +55102,8 @@ async function askRouting(input2) {
|
|
|
54720
55102
|
return void 0;
|
|
54721
55103
|
const requested = input2.deadlineMs ?? 500;
|
|
54722
55104
|
const deadlineMs = Number.isNaN(requested) ? 500 : Math.min(2e3, Math.max(1, requested));
|
|
54723
|
-
const expired = new Promise((
|
|
54724
|
-
timer = setTimeout(() =>
|
|
55105
|
+
const expired = new Promise((resolve29) => {
|
|
55106
|
+
timer = setTimeout(() => resolve29(void 0), deadlineMs);
|
|
54725
55107
|
timer.unref();
|
|
54726
55108
|
});
|
|
54727
55109
|
const request2 = {
|
|
@@ -54754,6 +55136,47 @@ function reportRouting(input2) {
|
|
|
54754
55136
|
let payload;
|
|
54755
55137
|
if ("kind" in input2) {
|
|
54756
55138
|
switch (input2.kind) {
|
|
55139
|
+
case "billing": {
|
|
55140
|
+
const { attemptId, requestKind, credentialId, provider: provider2, model, outcome, accountId, providerRequestId, providerResponseId, userMessageId, status, attempt, chargeBasis, usage: inputUsage, usageByModel: inputUsageByModel, cache: inputCache } = input2;
|
|
55141
|
+
if (!isNonEmptyString(attemptId) || !isNonEmptyString(credentialId) || !isNonEmptyString(provider2) || !isNonEmptyString(model) || requestKind !== "primary" && requestKind !== "title" && requestKind !== "compaction" && requestKind !== "generate" && requestKind !== "keep_warm" && requestKind !== "prime" || outcome !== "completed" && outcome !== "cut" && outcome !== "failed")
|
|
55142
|
+
return;
|
|
55143
|
+
const usage = billingUsage(inputUsage);
|
|
55144
|
+
const cache = billingCache(inputCache);
|
|
55145
|
+
const usageByModel = [];
|
|
55146
|
+
if (Array.isArray(inputUsageByModel)) {
|
|
55147
|
+
for (const entry of inputUsageByModel) {
|
|
55148
|
+
if (!isObject2(entry) || Array.isArray(entry))
|
|
55149
|
+
continue;
|
|
55150
|
+
const modelUsed = entry.modelUsed;
|
|
55151
|
+
if (!isNonEmptyString(modelUsed))
|
|
55152
|
+
continue;
|
|
55153
|
+
const modelUsage = billingUsage(entry.usage);
|
|
55154
|
+
if (!modelUsage)
|
|
55155
|
+
continue;
|
|
55156
|
+
usageByModel.push({ model_used: modelUsed, usage: modelUsage });
|
|
55157
|
+
}
|
|
55158
|
+
}
|
|
55159
|
+
payload = {
|
|
55160
|
+
kind: "billing",
|
|
55161
|
+
attempt_id: attemptId,
|
|
55162
|
+
request_kind: requestKind,
|
|
55163
|
+
credential_id: credentialId,
|
|
55164
|
+
provider: provider2,
|
|
55165
|
+
model,
|
|
55166
|
+
outcome,
|
|
55167
|
+
...isNonEmptyString(accountId) ? { account_id: accountId } : {},
|
|
55168
|
+
...isNonEmptyString(providerRequestId) ? { provider_request_id: providerRequestId } : {},
|
|
55169
|
+
...isNonEmptyString(providerResponseId) ? { provider_response_id: providerResponseId } : {},
|
|
55170
|
+
...isNonEmptyString(userMessageId) ? { user_message_id: userMessageId } : {},
|
|
55171
|
+
...typeof status === "number" && Number.isInteger(status) && status >= 0 ? { status } : {},
|
|
55172
|
+
...typeof attempt === "number" && Number.isInteger(attempt) && attempt >= 1 ? { attempt } : {},
|
|
55173
|
+
...chargeBasis === "subscription_included" || chargeBasis === "metered_api" ? { charge_basis: chargeBasis } : {},
|
|
55174
|
+
...usage ? { usage } : {},
|
|
55175
|
+
...usageByModel.length > 0 ? { usage_by_model: usageByModel } : {},
|
|
55176
|
+
...cache ? { cache } : {}
|
|
55177
|
+
};
|
|
55178
|
+
break;
|
|
55179
|
+
}
|
|
54757
55180
|
case "turn_notes_supported": {
|
|
54758
55181
|
const { model, supported } = input2;
|
|
54759
55182
|
if (typeof model !== "string" || model.length === 0 || typeof supported !== "boolean")
|
|
@@ -55281,7 +55704,7 @@ function throwIfAllKilled(input2) {
|
|
|
55281
55704
|
}
|
|
55282
55705
|
|
|
55283
55706
|
// src/plugin/session-context.ts
|
|
55284
|
-
import { resolve as
|
|
55707
|
+
import { resolve as resolve27 } from "node:path";
|
|
55285
55708
|
import { pathToFileURL } from "node:url";
|
|
55286
55709
|
var FALLBACK_SESSION_KEY = "__default__";
|
|
55287
55710
|
function extractOpenCodeSessionIdentity(headers) {
|
|
@@ -55295,7 +55718,7 @@ var AgySessionRegistry = class {
|
|
|
55295
55718
|
requestSessions;
|
|
55296
55719
|
parentSessionIds = /* @__PURE__ */ new Map();
|
|
55297
55720
|
constructor(directory, options = {}) {
|
|
55298
|
-
const workspaceUri = directory ? pathToFileURL(
|
|
55721
|
+
const workspaceUri = directory ? pathToFileURL(resolve27(directory)).href : "";
|
|
55299
55722
|
this.requestSessions = new AgyRequestSessionStore(workspaceUri, options);
|
|
55300
55723
|
}
|
|
55301
55724
|
getOrCreate(identity3) {
|
|
@@ -55611,7 +56034,7 @@ function formatWaitTime(ms) {
|
|
|
55611
56034
|
return remainingMinutes > 0 ? `${hours}h ${remainingMinutes}m` : `${hours}h`;
|
|
55612
56035
|
}
|
|
55613
56036
|
function sleep4(ms, signal) {
|
|
55614
|
-
return new Promise((
|
|
56037
|
+
return new Promise((resolve29, reject) => {
|
|
55615
56038
|
if (signal?.aborted) {
|
|
55616
56039
|
reject(
|
|
55617
56040
|
signal.reason instanceof Error ? signal.reason : new Error("Aborted")
|
|
@@ -55621,7 +56044,7 @@ function sleep4(ms, signal) {
|
|
|
55621
56044
|
const timerMs = Math.min(Math.max(0, Math.floor(ms)), 2147483647);
|
|
55622
56045
|
const timeout = setTimeout(() => {
|
|
55623
56046
|
cleanup2();
|
|
55624
|
-
|
|
56047
|
+
resolve29();
|
|
55625
56048
|
}, timerMs);
|
|
55626
56049
|
const onAbort = () => {
|
|
55627
56050
|
cleanup2();
|
|
@@ -58251,8 +58674,8 @@ function createPluginLifecycle(options) {
|
|
|
58251
58674
|
};
|
|
58252
58675
|
let failDisposal = () => {
|
|
58253
58676
|
};
|
|
58254
|
-
disposal = new Promise((
|
|
58255
|
-
finishDisposal =
|
|
58677
|
+
disposal = new Promise((resolve29, reject) => {
|
|
58678
|
+
finishDisposal = resolve29;
|
|
58256
58679
|
failDisposal = reject;
|
|
58257
58680
|
});
|
|
58258
58681
|
void (async () => {
|
|
@@ -58453,7 +58876,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
|
|
|
58453
58876
|
await drainSidebarWrites();
|
|
58454
58877
|
}
|
|
58455
58878
|
});
|
|
58456
|
-
const accountFile =
|
|
58879
|
+
const accountFile = resolve28(accountFileForVault());
|
|
58457
58880
|
const vaultFolder = await prepareVaultFolder({ accountFile });
|
|
58458
58881
|
const unavailableMessage = vaultFolder.refusal?.message ?? VAULT_ACCOUNT_REMEDY;
|
|
58459
58882
|
let vaultQuotaPoller;
|