@cortexkit/anthropic-auth-core 2.4.7 → 2.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -1,6 +1,104 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
3
3
|
|
|
4
|
+
// ../../node_modules/@cortexkit/common-auth/dist/routing-accessor/index.js
|
|
5
|
+
function isObject(value) {
|
|
6
|
+
return typeof value === "object" && value !== null;
|
|
7
|
+
}
|
|
8
|
+
function routingHandle(sessionId) {
|
|
9
|
+
const routing = Reflect.get(globalThis, Symbol.for("cortexkit.routing"));
|
|
10
|
+
if (typeof routing !== "function")
|
|
11
|
+
return;
|
|
12
|
+
const handle = routing(sessionId);
|
|
13
|
+
return isObject(handle) ? handle : undefined;
|
|
14
|
+
}
|
|
15
|
+
function selectionFor(answer, candidates) {
|
|
16
|
+
if (!isObject(answer))
|
|
17
|
+
return;
|
|
18
|
+
const accountId = answer.account_id;
|
|
19
|
+
const credentialId = answer.credential_id;
|
|
20
|
+
if (typeof accountId !== "string")
|
|
21
|
+
return;
|
|
22
|
+
if (credentialId !== undefined && typeof credentialId !== "string") {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const candidate = candidates.find((route) => route.accountId === accountId && (credentialId === undefined || route.credentialId === credentialId));
|
|
26
|
+
if (!candidate)
|
|
27
|
+
return;
|
|
28
|
+
const hold = answer.hold;
|
|
29
|
+
const retryAfterMs = isObject(hold) ? hold.retry_after_ms : undefined;
|
|
30
|
+
if (typeof retryAfterMs === "number" && Number.isFinite(retryAfterMs) && retryAfterMs >= 0) {
|
|
31
|
+
return { candidate, hold: { retry_after_ms: retryAfterMs } };
|
|
32
|
+
}
|
|
33
|
+
return { candidate };
|
|
34
|
+
}
|
|
35
|
+
async function askRouting(input) {
|
|
36
|
+
let timer;
|
|
37
|
+
try {
|
|
38
|
+
const handle = routingHandle(input.sessionId);
|
|
39
|
+
if (!handle)
|
|
40
|
+
return;
|
|
41
|
+
const accountFor = handle.accountFor;
|
|
42
|
+
if (typeof accountFor !== "function")
|
|
43
|
+
return;
|
|
44
|
+
const requested = input.deadlineMs ?? 500;
|
|
45
|
+
const deadlineMs = Number.isNaN(requested) ? 500 : Math.min(2000, Math.max(1, requested));
|
|
46
|
+
const expired = new Promise((resolve) => {
|
|
47
|
+
timer = setTimeout(() => resolve(undefined), deadlineMs);
|
|
48
|
+
timer.unref();
|
|
49
|
+
});
|
|
50
|
+
const pending = accountFor.call(handle, { provider: input.provider, modelId: input.modelId }, { deadlineMs });
|
|
51
|
+
if (!isObject(pending) || typeof pending.then !== "function")
|
|
52
|
+
return;
|
|
53
|
+
const answer = await Promise.race([pending, expired]);
|
|
54
|
+
return selectionFor(answer, input.candidates);
|
|
55
|
+
} catch {
|
|
56
|
+
return;
|
|
57
|
+
} finally {
|
|
58
|
+
clearTimeout(timer);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function reportRouting(input) {
|
|
62
|
+
try {
|
|
63
|
+
const handle = routingHandle(input.sessionId);
|
|
64
|
+
if (!handle)
|
|
65
|
+
return;
|
|
66
|
+
const report = handle.report;
|
|
67
|
+
if (typeof report !== "function")
|
|
68
|
+
return;
|
|
69
|
+
const identity = {
|
|
70
|
+
account_id: input.accountId,
|
|
71
|
+
...input.credentialId !== undefined ? { credential_id: input.credentialId } : {}
|
|
72
|
+
};
|
|
73
|
+
let payload;
|
|
74
|
+
switch (input.outcome) {
|
|
75
|
+
case "served":
|
|
76
|
+
payload = { ...identity, outcome: "served", headers: input.headers };
|
|
77
|
+
break;
|
|
78
|
+
case "exhausted": {
|
|
79
|
+
const { window, pool } = input;
|
|
80
|
+
if (window !== "5h" && window !== "7d")
|
|
81
|
+
return;
|
|
82
|
+
if (pool !== undefined && (typeof pool !== "string" || pool.length === 0 || pool.includes(":")))
|
|
83
|
+
return;
|
|
84
|
+
payload = {
|
|
85
|
+
...identity,
|
|
86
|
+
outcome: "exhausted",
|
|
87
|
+
window,
|
|
88
|
+
...pool ? { pool } : {},
|
|
89
|
+
...input.resetsAt !== undefined ? { resets_at: input.resetsAt } : {}
|
|
90
|
+
};
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
default:
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const pending = report.call(handle, payload);
|
|
97
|
+
if (isObject(pending) && typeof pending.then === "function") {
|
|
98
|
+
Promise.resolve(pending).catch(() => {});
|
|
99
|
+
}
|
|
100
|
+
} catch {}
|
|
101
|
+
}
|
|
4
102
|
// ../../node_modules/@cortexkit/common-auth/dist/auth-menu/ansi.js
|
|
5
103
|
var ANSI = {
|
|
6
104
|
hide: "\x1B[?25l",
|
|
@@ -241,7 +339,7 @@ async function select(terminal, items, options) {
|
|
|
241
339
|
import { createHash, randomBytes, randomUUID as randomUUID4 } from "node:crypto";
|
|
242
340
|
import { constants as fsConstants } from "node:fs";
|
|
243
341
|
import { chmod, mkdir as mkdir3, open as open3, readFile as readFile3, realpath, rename as rename4, stat as stat2, unlink as unlink2 } from "node:fs/promises";
|
|
244
|
-
import { basename, dirname as dirname4, extname, isAbsolute, join as
|
|
342
|
+
import { basename, dirname as dirname4, extname, isAbsolute, join as join4, resolve as resolve4 } from "node:path";
|
|
245
343
|
import { ClaustrumCredentialError, ClaustrumClient as ClaustrumWireClient, writeEnrollmentTokenFile } from "@cortexkit/claustrum-client";
|
|
246
344
|
|
|
247
345
|
// ../../node_modules/@cortexkit/common-auth/dist/fs/file-read-cache.js
|
|
@@ -688,9 +786,10 @@ var WRITER_LOCK_CONSTANTS = Object.freeze({
|
|
|
688
786
|
// ../../node_modules/@cortexkit/common-auth/dist/fs/refresh-file-lock.js
|
|
689
787
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
690
788
|
import { lstat as lstat3, mkdir as mkdir2, open as open2, readFile as readFile2, rename as rename3, rm as rm2, stat } from "node:fs/promises";
|
|
691
|
-
import { dirname as dirname3, join as
|
|
789
|
+
import { dirname as dirname3, join as join3 } from "node:path";
|
|
692
790
|
|
|
693
791
|
// ../../node_modules/@cortexkit/common-auth/dist/fs/with-lock.js
|
|
792
|
+
import { join as join2, resolve as resolve3 } from "node:path";
|
|
694
793
|
function lockPathFor(target, name) {
|
|
695
794
|
return `${target}.${name}.lock`;
|
|
696
795
|
}
|
|
@@ -712,18 +811,33 @@ class LockOwnershipError extends Error {
|
|
|
712
811
|
this.details = details;
|
|
713
812
|
}
|
|
714
813
|
}
|
|
814
|
+
function isChangingLockRead(error, target, name) {
|
|
815
|
+
if (!windowsPrivateFiles || !(error instanceof PrivateFileError) || error.reason !== "io-error" || error.win32Code !== 32 && error.win32Code !== 303 || error.stage !== "read" && error.stage !== "verify")
|
|
816
|
+
return false;
|
|
817
|
+
const path = resolve3(lockPathFor(target, name));
|
|
818
|
+
return error.path === path || error.path === join2(path, "owner.json");
|
|
819
|
+
}
|
|
715
820
|
async function withLock(target, options, fn) {
|
|
716
821
|
const started = performance.now();
|
|
717
822
|
for (;; ) {
|
|
718
823
|
options.signal?.throwIfAborted();
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
824
|
+
let lock;
|
|
825
|
+
let changingReadError;
|
|
826
|
+
try {
|
|
827
|
+
lock = await acquireRefreshFileLock({
|
|
828
|
+
path: target,
|
|
829
|
+
name: options.name,
|
|
830
|
+
ttlMs: options.ttlMs,
|
|
831
|
+
renew: options.renew ?? false,
|
|
832
|
+
...options.onStep ? { onStep: options.onStep } : {},
|
|
833
|
+
...options.onRenewalTimer ? { onRenewalTimer: options.onRenewalTimer } : {}
|
|
834
|
+
});
|
|
835
|
+
} catch (error) {
|
|
836
|
+
if (!isChangingLockRead(error, target, options.name))
|
|
837
|
+
throw error;
|
|
838
|
+
lock = null;
|
|
839
|
+
changingReadError = error;
|
|
840
|
+
}
|
|
727
841
|
if (lock) {
|
|
728
842
|
try {
|
|
729
843
|
options.signal?.throwIfAborted();
|
|
@@ -734,13 +848,15 @@ async function withLock(target, options, fn) {
|
|
|
734
848
|
}
|
|
735
849
|
const remaining = options.timeoutMs - (performance.now() - started);
|
|
736
850
|
if (remaining <= 0) {
|
|
851
|
+
if (changingReadError)
|
|
852
|
+
throw changingReadError;
|
|
737
853
|
throw new LockContentionError({
|
|
738
854
|
target,
|
|
739
855
|
name: options.name,
|
|
740
856
|
timeoutMs: options.timeoutMs
|
|
741
857
|
});
|
|
742
858
|
}
|
|
743
|
-
await new Promise((
|
|
859
|
+
await new Promise((resolve4) => setTimeout(resolve4, Math.min(25, Math.ceil(remaining))));
|
|
744
860
|
}
|
|
745
861
|
}
|
|
746
862
|
|
|
@@ -789,7 +905,7 @@ function acquireRefreshFileLock(options) {
|
|
|
789
905
|
}
|
|
790
906
|
async function acquireRefreshFileLockWithClock(options) {
|
|
791
907
|
const lockPath = lockPathFor(options.path, options.name);
|
|
792
|
-
const legacyOwnerPath =
|
|
908
|
+
const legacyOwnerPath = join3(lockPath, "owner.json");
|
|
793
909
|
const ownerId = randomUUID3();
|
|
794
910
|
const now = options.now ?? Date.now;
|
|
795
911
|
let renewTimer = null;
|
|
@@ -797,8 +913,8 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
797
913
|
let releaseConfirmed = false;
|
|
798
914
|
let loss;
|
|
799
915
|
let resolveLoss;
|
|
800
|
-
const lostPromise = new Promise((
|
|
801
|
-
resolveLoss =
|
|
916
|
+
const lostPromise = new Promise((resolve4) => {
|
|
917
|
+
resolveLoss = resolve4;
|
|
802
918
|
});
|
|
803
919
|
function notifyTimerStep(event) {
|
|
804
920
|
try {
|
|
@@ -830,7 +946,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
830
946
|
let terminalIOError;
|
|
831
947
|
let renewalInFlight = null;
|
|
832
948
|
const evictPath = `${lockPath}.evicting`;
|
|
833
|
-
const evictOwnerPath =
|
|
949
|
+
const evictOwnerPath = join3(evictPath, "owner.json");
|
|
834
950
|
const evictOwnerId = randomUUID3();
|
|
835
951
|
const EVICT_TTL = 5000;
|
|
836
952
|
const MAX_STEAL_ATTEMPTS = 8;
|
|
@@ -955,7 +1071,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
955
1071
|
}
|
|
956
1072
|
}
|
|
957
1073
|
async function backoff() {
|
|
958
|
-
await new Promise((
|
|
1074
|
+
await new Promise((resolve4) => setTimeout(resolve4, Math.floor(Math.random() * 4)));
|
|
959
1075
|
}
|
|
960
1076
|
async function readLockState(notifyReady = true) {
|
|
961
1077
|
if (notifyReady && options.onStep)
|
|
@@ -1439,7 +1555,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
1439
1555
|
const remainingMs = deadline - performance.now();
|
|
1440
1556
|
if (remainingMs <= 0)
|
|
1441
1557
|
break;
|
|
1442
|
-
await new Promise((
|
|
1558
|
+
await new Promise((resolve4) => setTimeout(resolve4, Math.min(delayMs, remainingMs)));
|
|
1443
1559
|
delayMs = Math.min(delayMs * 2, 50);
|
|
1444
1560
|
}
|
|
1445
1561
|
if (windowsPrivateFiles)
|
|
@@ -1496,7 +1612,7 @@ function getClaustrumEnrollmentPaths(tokenPath) {
|
|
|
1496
1612
|
const extension = extname(tokenPath) || ".json";
|
|
1497
1613
|
const stem = basename(tokenPath, extname(tokenPath));
|
|
1498
1614
|
return {
|
|
1499
|
-
statePath:
|
|
1615
|
+
statePath: join4(dirname4(tokenPath), `${stem}-state${extension}`),
|
|
1500
1616
|
tokenPath
|
|
1501
1617
|
};
|
|
1502
1618
|
}
|
|
@@ -1504,7 +1620,7 @@ function hostEnrollmentPaths(input) {
|
|
|
1504
1620
|
const override = input.override?.trim();
|
|
1505
1621
|
if (override && !isAbsolute(override) && !input.cwd)
|
|
1506
1622
|
throw new ClaustrumConsumerError("invalid-state", "A relative Claustrum enrollment override needs a base directory");
|
|
1507
|
-
const tokenPath = override ? isAbsolute(override) ? override :
|
|
1623
|
+
const tokenPath = override ? isAbsolute(override) ? override : resolve4(input.cwd, override) : join4(input.stateDir, `${input.host}-enrollment.json`);
|
|
1508
1624
|
return getClaustrumEnrollmentPaths(tokenPath);
|
|
1509
1625
|
}
|
|
1510
1626
|
function isRecord(value) {
|
|
@@ -1740,7 +1856,7 @@ async function writeStateAtomic(path, state, ancestorOptions = {}) {
|
|
|
1740
1856
|
}
|
|
1741
1857
|
if (windowsPrivateFiles)
|
|
1742
1858
|
return writePrivateAtomic(path, bytes);
|
|
1743
|
-
const temporary =
|
|
1859
|
+
const temporary = join4(parent, `.${basename(path)}.${process.pid}.${randomUUID4()}.tmp`);
|
|
1744
1860
|
let descriptor;
|
|
1745
1861
|
let created = false;
|
|
1746
1862
|
try {
|
|
@@ -2241,7 +2357,7 @@ class ByteTail {
|
|
|
2241
2357
|
}
|
|
2242
2358
|
var defaultCommandRunner = {
|
|
2243
2359
|
run(file, args, options = {}) {
|
|
2244
|
-
return new Promise((
|
|
2360
|
+
return new Promise((resolve5) => {
|
|
2245
2361
|
const started = performance.now();
|
|
2246
2362
|
const timeoutMs = options.timeoutMs ?? 15000;
|
|
2247
2363
|
const stderr = new ByteTail;
|
|
@@ -2259,7 +2375,7 @@ var defaultCommandRunner = {
|
|
|
2259
2375
|
stdio: ["ignore", "pipe", "pipe"]
|
|
2260
2376
|
});
|
|
2261
2377
|
} catch {
|
|
2262
|
-
|
|
2378
|
+
resolve5({
|
|
2263
2379
|
exitCode: 1,
|
|
2264
2380
|
stdout: "",
|
|
2265
2381
|
stderr: "",
|
|
@@ -2294,7 +2410,7 @@ var defaultCommandRunner = {
|
|
|
2294
2410
|
settled = true;
|
|
2295
2411
|
if (timer)
|
|
2296
2412
|
clearTimeout(timer);
|
|
2297
|
-
|
|
2413
|
+
resolve5({
|
|
2298
2414
|
exitCode: spawnError ? 1 : outputExceeded ? 1 : code ?? 1,
|
|
2299
2415
|
stdout: Buffer.concat(stdout, stdoutLength).toString("utf8"),
|
|
2300
2416
|
stderr: stderr.toString(),
|
|
@@ -2388,7 +2504,7 @@ function setupEnrollment(error) {
|
|
|
2388
2504
|
import { accessSync, constants, existsSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
2389
2505
|
import { mkdtemp, rm as rm3 } from "node:fs/promises";
|
|
2390
2506
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
2391
|
-
import { join as
|
|
2507
|
+
import { join as join5 } from "node:path";
|
|
2392
2508
|
import { parse } from "jsonc-parser";
|
|
2393
2509
|
|
|
2394
2510
|
// ../../node_modules/@cortexkit/common-auth/dist/setup/paths.js
|
|
@@ -2557,7 +2673,7 @@ async function detectHosts(plugin, io = {}) {
|
|
|
2557
2673
|
return null;
|
|
2558
2674
|
let root;
|
|
2559
2675
|
try {
|
|
2560
|
-
root = await mkdtemp(
|
|
2676
|
+
root = await mkdtemp(join5(tmpdir2(), "common-auth-setup-version-"));
|
|
2561
2677
|
const probeEnv = {
|
|
2562
2678
|
...env,
|
|
2563
2679
|
HOME: root,
|
|
@@ -3151,7 +3267,7 @@ import { applyEdits, createScanner, findNodeAtLocation, modify, parse as parse2,
|
|
|
3151
3267
|
// ../../node_modules/@cortexkit/common-auth/dist/setup/config-write.js
|
|
3152
3268
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
3153
3269
|
import { mkdir as mkdir4, open as open4, rename as rename5, stat as stat4, unlink as unlink3 } from "node:fs/promises";
|
|
3154
|
-
import { basename as basename2, dirname as dirname5, join as
|
|
3270
|
+
import { basename as basename2, dirname as dirname5, join as join6 } from "node:path";
|
|
3155
3271
|
import { setTimeout as delay2 } from "node:timers/promises";
|
|
3156
3272
|
async function writeHostConfigAtomic(file, content, options = {}) {
|
|
3157
3273
|
const windows = (options.platform ?? process.platform) === "win32";
|
|
@@ -3166,7 +3282,7 @@ async function writeHostConfigAtomic(file, content, options = {}) {
|
|
|
3166
3282
|
throw error;
|
|
3167
3283
|
}
|
|
3168
3284
|
}
|
|
3169
|
-
const stage =
|
|
3285
|
+
const stage = join6(parent, `.${basename2(file)}.${(options.stageName ?? randomUUID5)()}.tmp`);
|
|
3170
3286
|
let created = false;
|
|
3171
3287
|
try {
|
|
3172
3288
|
const handle = await open4(stage, "wx", mode ?? 438);
|
|
@@ -3583,13 +3699,13 @@ ${write.content}`);
|
|
|
3583
3699
|
import { createHash as createHash2, randomUUID as randomUUID6 } from "node:crypto";
|
|
3584
3700
|
import { mkdir as mkdir5, readFile as readFile5, rename as rename6, rm as rm4, stat as stat5, writeFile } from "node:fs/promises";
|
|
3585
3701
|
import { homedir as homedir2 } from "node:os";
|
|
3586
|
-
import { dirname as dirname6, join as
|
|
3702
|
+
import { dirname as dirname6, join as join8 } from "node:path";
|
|
3587
3703
|
|
|
3588
3704
|
// src/claustrum.ts
|
|
3589
3705
|
import { readdirSync, statSync as statSync2 } from "node:fs";
|
|
3590
3706
|
import * as fs from "node:fs/promises";
|
|
3591
3707
|
import { tmpdir as tmpdir3, userInfo } from "node:os";
|
|
3592
|
-
import { join as
|
|
3708
|
+
import { join as join7 } from "node:path";
|
|
3593
3709
|
function errorCode(error) {
|
|
3594
3710
|
return error && typeof error === "object" && "code" in error && typeof error.code === "string" ? error.code : "unknown";
|
|
3595
3711
|
}
|
|
@@ -3617,7 +3733,7 @@ function listSubcTempConnectionFiles(dir) {
|
|
|
3617
3733
|
if (!name.startsWith(CLAUSTRUM_TEMP_PREFIX) || !name.endsWith(CLAUSTRUM_TEMP_SUFFIX)) {
|
|
3618
3734
|
continue;
|
|
3619
3735
|
}
|
|
3620
|
-
const candidate =
|
|
3736
|
+
const candidate = join7(dir, name);
|
|
3621
3737
|
if (safeIsFile(candidate))
|
|
3622
3738
|
matches.push(candidate);
|
|
3623
3739
|
}
|
|
@@ -3627,13 +3743,13 @@ function listSubcTempConnectionFiles(dir) {
|
|
|
3627
3743
|
function findExistingClaustrumConnectionPath(env = process.env) {
|
|
3628
3744
|
const runtime = env.XDG_RUNTIME_DIR?.trim();
|
|
3629
3745
|
if (runtime) {
|
|
3630
|
-
const candidate =
|
|
3746
|
+
const candidate = join7(runtime, PRODUCTION_CLAUSTRUM_CONNECTION_FILE_NAME);
|
|
3631
3747
|
if (safeIsFile(candidate))
|
|
3632
3748
|
return candidate;
|
|
3633
3749
|
}
|
|
3634
3750
|
const home = env.HOME?.trim();
|
|
3635
3751
|
if (home) {
|
|
3636
|
-
const candidate =
|
|
3752
|
+
const candidate = join7(home, ".local", "share", "cortexkit", "run", PRODUCTION_CLAUSTRUM_CONNECTION_FILE_NAME);
|
|
3637
3753
|
if (safeIsFile(candidate))
|
|
3638
3754
|
return candidate;
|
|
3639
3755
|
}
|
|
@@ -3652,11 +3768,11 @@ function getDefaultClaustrumConnectionPath(env = process.env) {
|
|
|
3652
3768
|
return existing;
|
|
3653
3769
|
const runtime = env.XDG_RUNTIME_DIR?.trim();
|
|
3654
3770
|
if (runtime && (process.platform !== "darwin" || safeIsFile(runtime))) {
|
|
3655
|
-
return
|
|
3771
|
+
return join7(runtime, PRODUCTION_CLAUSTRUM_CONNECTION_FILE_NAME);
|
|
3656
3772
|
}
|
|
3657
3773
|
if (process.platform === "darwin") {
|
|
3658
3774
|
const home = env.HOME?.trim() || userInfo().homedir;
|
|
3659
|
-
return
|
|
3775
|
+
return join7(home, ".local", "share", "cortexkit", "run", PRODUCTION_CLAUSTRUM_CONNECTION_FILE_NAME);
|
|
3660
3776
|
}
|
|
3661
3777
|
const uid = process.getuid?.() ?? userInfo().uid;
|
|
3662
3778
|
return `/run/user/${uid}/${PRODUCTION_CLAUSTRUM_CONNECTION_FILE_NAME}`;
|
|
@@ -4252,7 +4368,7 @@ async function refreshClaudeOAuthToken(input) {
|
|
|
4252
4368
|
try {
|
|
4253
4369
|
if (attempt > 0) {
|
|
4254
4370
|
const delay3 = baseDelayMs * 2 ** (attempt - 1);
|
|
4255
|
-
await new Promise((
|
|
4371
|
+
await new Promise((resolve5) => setTimeoutImpl(resolve5, delay3));
|
|
4256
4372
|
}
|
|
4257
4373
|
const response = await fetchImpl(TOKEN_URL, {
|
|
4258
4374
|
method: "POST",
|
|
@@ -4444,16 +4560,16 @@ function getOpenCodeConfigDir(env = process.env, home = homedir2()) {
|
|
|
4444
4560
|
if (env.OPENCODE_CONFIG_DIR?.trim()) {
|
|
4445
4561
|
return env.OPENCODE_CONFIG_DIR.trim();
|
|
4446
4562
|
}
|
|
4447
|
-
return
|
|
4563
|
+
return join8(env.XDG_CONFIG_HOME || join8(home, ".config"), "opencode");
|
|
4448
4564
|
}
|
|
4449
4565
|
function getAccountStoragePath() {
|
|
4450
|
-
return process.env.OPENCODE_ANTHROPIC_AUTH_FILE?.trim() ||
|
|
4566
|
+
return process.env.OPENCODE_ANTHROPIC_AUTH_FILE?.trim() || join8(getOpenCodeConfigDir(), ACCOUNT_FILE_NAME);
|
|
4451
4567
|
}
|
|
4452
4568
|
function getAccountStatePath(configPath = getAccountStoragePath()) {
|
|
4453
4569
|
const explicit = process.env.OPENCODE_ANTHROPIC_AUTH_STATE_FILE?.trim();
|
|
4454
4570
|
if (explicit)
|
|
4455
4571
|
return explicit;
|
|
4456
|
-
return configPath.endsWith(ACCOUNT_FILE_NAME) ?
|
|
4572
|
+
return configPath.endsWith(ACCOUNT_FILE_NAME) ? join8(dirname6(configPath), ACCOUNT_STATE_FILE_NAME) : `${configPath}.state.json`;
|
|
4457
4573
|
}
|
|
4458
4574
|
function createEmptyStorage() {
|
|
4459
4575
|
return {
|
|
@@ -4581,7 +4697,7 @@ function getClaustrumMode(storage) {
|
|
|
4581
4697
|
async function acquireRefreshFileLock2(options) {
|
|
4582
4698
|
const accountPath = options.path ?? getAccountStoragePath();
|
|
4583
4699
|
const lockPath = `${accountPath}.${options.name}.lock`;
|
|
4584
|
-
const legacyOwnerPath =
|
|
4700
|
+
const legacyOwnerPath = join8(lockPath, "owner.json");
|
|
4585
4701
|
const ownerId = randomUUID6();
|
|
4586
4702
|
const now = Date.now;
|
|
4587
4703
|
let renewTimer = null;
|
|
@@ -4635,12 +4751,12 @@ async function acquireRefreshFileLock2(options) {
|
|
|
4635
4751
|
let acquired = await tryAcquire();
|
|
4636
4752
|
if (!acquired) {
|
|
4637
4753
|
const evictPath = `${lockPath}.evicting`;
|
|
4638
|
-
const evictOwnerPath =
|
|
4754
|
+
const evictOwnerPath = join8(evictPath, "owner.json");
|
|
4639
4755
|
const evictOwnerId = randomUUID6();
|
|
4640
4756
|
const EVICT_TTL = 5000;
|
|
4641
4757
|
const MAX_STEAL_ATTEMPTS = 8;
|
|
4642
4758
|
async function backoff() {
|
|
4643
|
-
await new Promise((
|
|
4759
|
+
await new Promise((resolve5) => setTimeout(resolve5, Math.floor(Math.random() * 4)));
|
|
4644
4760
|
}
|
|
4645
4761
|
async function lockIsLive() {
|
|
4646
4762
|
try {
|
|
@@ -5985,7 +6101,7 @@ import {
|
|
|
5985
6101
|
writeFile as writeFile2
|
|
5986
6102
|
} from "node:fs/promises";
|
|
5987
6103
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
5988
|
-
import { join as
|
|
6104
|
+
import { join as join10, resolve as resolve5 } from "node:path";
|
|
5989
6105
|
|
|
5990
6106
|
// src/json.ts
|
|
5991
6107
|
function parseJsonRedacted(text) {
|
|
@@ -6256,7 +6372,7 @@ var DUMP_USAGE_TITLE = "## Claude Dump Usage";
|
|
|
6256
6372
|
var DUMP_USAGE = "Usage: `/claude-dump`, `/claude-dump on`, or `/claude-dump off`.";
|
|
6257
6373
|
var DUMP_DIR_ENV = "OPENCODE_ANTHROPIC_AUTH_DUMP_DIR";
|
|
6258
6374
|
var DUMP_MAX_BYTES_ENV = "OPENCODE_ANTHROPIC_AUTH_DUMP_MAX_BYTES";
|
|
6259
|
-
var DEFAULT_DUMP_DIR =
|
|
6375
|
+
var DEFAULT_DUMP_DIR = join10(tmpdir5(), "opencode-anthropic-auth-dumps");
|
|
6260
6376
|
var DEFAULT_DUMP_MAX_BYTES = 512 * 1024 * 1024;
|
|
6261
6377
|
var DUMP_SWEEP_INTERVAL_MS = 5 * 60 * 1000;
|
|
6262
6378
|
var DUMP_SWEEP_NEWNESS_FLOOR_MS = 60 * 1000;
|
|
@@ -6293,7 +6409,7 @@ function getDumpMaxBytes() {
|
|
|
6293
6409
|
return Number.isFinite(configured) && configured >= 0 ? Math.floor(configured) : DEFAULT_DUMP_MAX_BYTES;
|
|
6294
6410
|
}
|
|
6295
6411
|
function isConfiguredDumpDirectory(path2) {
|
|
6296
|
-
return
|
|
6412
|
+
return resolve5(path2) === resolve5(getDumpDirectory());
|
|
6297
6413
|
}
|
|
6298
6414
|
function isDumpArtifactFileName(name) {
|
|
6299
6415
|
const stem = name.replace(DUMP_ARTIFACT_SUFFIX_PATTERN, "");
|
|
@@ -6350,7 +6466,7 @@ async function sweepDumpDirectory(options) {
|
|
|
6350
6466
|
const dumpDirStats = await lstat4(dumpDir);
|
|
6351
6467
|
if (dumpDirStats.isSymbolicLink())
|
|
6352
6468
|
return emptyResult;
|
|
6353
|
-
const protectedPaths = new Set((options.protectedPaths ?? []).map((path2) =>
|
|
6469
|
+
const protectedPaths = new Set((options.protectedPaths ?? []).map((path2) => resolve5(path2)));
|
|
6354
6470
|
const entries = await readdir(dumpDir, { withFileTypes: true });
|
|
6355
6471
|
const files = [];
|
|
6356
6472
|
await Promise.all(entries.map(async (entry) => {
|
|
@@ -6359,7 +6475,7 @@ async function sweepDumpDirectory(options) {
|
|
|
6359
6475
|
const partial = isDumpPartialFileName(entry.name);
|
|
6360
6476
|
if (!partial && !isDumpArtifactFileName(entry.name))
|
|
6361
6477
|
return;
|
|
6362
|
-
const path2 =
|
|
6478
|
+
const path2 = join10(dumpDir, entry.name);
|
|
6363
6479
|
try {
|
|
6364
6480
|
const stats = await lstat4(path2);
|
|
6365
6481
|
if (!stats.isFile() || stats.isSymbolicLink())
|
|
@@ -6388,7 +6504,7 @@ async function sweepDumpDirectory(options) {
|
|
|
6388
6504
|
};
|
|
6389
6505
|
const partials = files.filter((file) => file.partial).sort((left, right) => left.mtimeMs - right.mtimeMs || left.path.localeCompare(right.path));
|
|
6390
6506
|
for (const file of partials) {
|
|
6391
|
-
if (protectedPaths.has(
|
|
6507
|
+
if (protectedPaths.has(resolve5(file.path)))
|
|
6392
6508
|
continue;
|
|
6393
6509
|
if (now - file.mtimeMs < partialStaleMs)
|
|
6394
6510
|
continue;
|
|
@@ -6412,7 +6528,7 @@ async function sweepDumpDirectory(options) {
|
|
|
6412
6528
|
break;
|
|
6413
6529
|
if (now - group.newestMtimeMs < minAgeMs)
|
|
6414
6530
|
continue;
|
|
6415
|
-
if (group.files.some((file) => protectedPaths.has(
|
|
6531
|
+
if (group.files.some((file) => protectedPaths.has(resolve5(file.path)))) {
|
|
6416
6532
|
continue;
|
|
6417
6533
|
}
|
|
6418
6534
|
for (const file of group.files)
|
|
@@ -6564,7 +6680,7 @@ async function loadLatestDumpBody(input) {
|
|
|
6564
6680
|
const candidates = names.map((name) => ({ name, tag: dumpBodyTagForAffinity(name, affinity) })).filter((candidate) => candidate.tag !== undefined).sort((a, b) => b.name.localeCompare(a.name));
|
|
6565
6681
|
for (const candidate of candidates) {
|
|
6566
6682
|
try {
|
|
6567
|
-
const path2 =
|
|
6683
|
+
const path2 = join10(dumpDir, candidate.name);
|
|
6568
6684
|
const metadataPath = path2.replace(/\.body\.json$/, ".meta.json");
|
|
6569
6685
|
if (!(await lstat4(path2)).isFile())
|
|
6570
6686
|
continue;
|
|
@@ -6691,7 +6807,7 @@ async function dumpRequest(input) {
|
|
|
6691
6807
|
const tagSegment = dumpTagSegment(input.tag);
|
|
6692
6808
|
const id = `${new Date().toISOString().replace(/[:.]/g, "-")}-${String(nextDumpId).padStart(6, "0")}-${dumpFileSessionSegment(affinity, 80 - tagSegment.length)}${tagSegment}-${dumpRequestSegment(input)}`;
|
|
6693
6809
|
const dumpDir = getDumpDirectory();
|
|
6694
|
-
const prefix =
|
|
6810
|
+
const prefix = join10(dumpDir, id);
|
|
6695
6811
|
const files = {
|
|
6696
6812
|
body: `${prefix}.body.json`,
|
|
6697
6813
|
metadata: `${prefix}.meta.json`,
|
|
@@ -7034,7 +7150,7 @@ function classifyVaultFailure(error) {
|
|
|
7034
7150
|
}
|
|
7035
7151
|
|
|
7036
7152
|
// ../../node_modules/@cortexkit/common-auth/dist/claustrum/insula.js
|
|
7037
|
-
import { resolve as
|
|
7153
|
+
import { resolve as resolve6 } from "node:path";
|
|
7038
7154
|
import { storeIdentity } from "@cortexkit/claustrum-client";
|
|
7039
7155
|
import { SubcClient } from "@cortexkit/subc-client";
|
|
7040
7156
|
|
|
@@ -7555,6 +7671,8 @@ class InsulaQuotaSource {
|
|
|
7555
7671
|
...typeof entry.source === "string" && { source: entry.source }
|
|
7556
7672
|
}
|
|
7557
7673
|
};
|
|
7674
|
+
if (entry.stale !== undefined && (!record(entry.stale) || entry.stale.class !== "local_source_unavailable"))
|
|
7675
|
+
return { miss: "upstream-failed", reading };
|
|
7558
7676
|
return now >= fetchedAt + MAX_AGE || entry.stale !== undefined ? { miss: "stale", reading } : { reading };
|
|
7559
7677
|
}
|
|
7560
7678
|
if (this.#completeProviders.has(provider))
|
|
@@ -7566,8 +7684,8 @@ class InsulaQuotaSource {
|
|
|
7566
7684
|
}
|
|
7567
7685
|
function acquireInsulaQuotaSource(transport, tokenPath) {
|
|
7568
7686
|
const key = JSON.stringify([
|
|
7569
|
-
|
|
7570
|
-
|
|
7687
|
+
resolve6(transport.connectionFile),
|
|
7688
|
+
resolve6(tokenPath)
|
|
7571
7689
|
]);
|
|
7572
7690
|
let shared = sources.get(key);
|
|
7573
7691
|
if (!shared) {
|
|
@@ -7593,7 +7711,7 @@ import { ClaustrumCredentialError as ClaustrumCredentialError4 } from "@cortexki
|
|
|
7593
7711
|
// ../../node_modules/@cortexkit/common-auth/dist/logger/engine.js
|
|
7594
7712
|
import { appendFileSync as appendFileSync2, chmodSync, existsSync as existsSync3, renameSync as renameSync2, statSync as statSync4 } from "node:fs";
|
|
7595
7713
|
import { open as open5 } from "node:fs/promises";
|
|
7596
|
-
import { dirname as dirname7, resolve as
|
|
7714
|
+
import { dirname as dirname7, resolve as resolve7 } from "node:path";
|
|
7597
7715
|
var ORDER = {
|
|
7598
7716
|
error: 0,
|
|
7599
7717
|
warn: 1,
|
|
@@ -7651,7 +7769,7 @@ async function openWindowsFile(sink, file) {
|
|
|
7651
7769
|
return sink.handle;
|
|
7652
7770
|
}
|
|
7653
7771
|
async function flushWindowsFile(sink, file, text) {
|
|
7654
|
-
file =
|
|
7772
|
+
file = resolve7(file);
|
|
7655
7773
|
try {
|
|
7656
7774
|
if (sink.file !== file)
|
|
7657
7775
|
await closeWindowsFile(sink);
|
|
@@ -7898,6 +8016,7 @@ function combineAbortSignals(signals) {
|
|
|
7898
8016
|
}
|
|
7899
8017
|
|
|
7900
8018
|
// ../../node_modules/@cortexkit/common-auth/dist/claustrum/custody.js
|
|
8019
|
+
import { channel } from "node:diagnostics_channel";
|
|
7901
8020
|
import { ClaustrumCredentialError as ClaustrumCredentialError3 } from "@cortexkit/claustrum-client";
|
|
7902
8021
|
|
|
7903
8022
|
// ../../node_modules/@cortexkit/common-auth/dist/claustrum/host-slot.js
|
|
@@ -7926,10 +8045,10 @@ async function drainShutdown(pending, onTimeout) {
|
|
|
7926
8045
|
try {
|
|
7927
8046
|
await Promise.race([
|
|
7928
8047
|
drained,
|
|
7929
|
-
new Promise((
|
|
8048
|
+
new Promise((resolve8) => {
|
|
7930
8049
|
timer = setTimeout(() => {
|
|
7931
8050
|
expired = true;
|
|
7932
|
-
|
|
8051
|
+
resolve8();
|
|
7933
8052
|
}, 2000);
|
|
7934
8053
|
})
|
|
7935
8054
|
]);
|
|
@@ -7957,6 +8076,7 @@ function scopedRetryReason(served, current) {
|
|
|
7957
8076
|
return "rotated";
|
|
7958
8077
|
}
|
|
7959
8078
|
var defaultLogger = createLogger("claustrum");
|
|
8079
|
+
var phaseDiagnostics = channel("common-auth.claustrum.phases");
|
|
7960
8080
|
function decideScopedRetryAfter401(site, served, current, logger2 = defaultLogger) {
|
|
7961
8081
|
const retry = isScopedCredentialRotation(served, current);
|
|
7962
8082
|
logger2.debug("scoped 401 re-authorized", {
|
|
@@ -8156,6 +8276,11 @@ class ClaustrumScopedCustody {
|
|
|
8156
8276
|
}
|
|
8157
8277
|
async#token(signal) {
|
|
8158
8278
|
this.#check(signal);
|
|
8279
|
+
if (phaseDiagnostics.hasSubscribers)
|
|
8280
|
+
phaseDiagnostics.publish({
|
|
8281
|
+
logger: this.#logger,
|
|
8282
|
+
phase: "token read begin"
|
|
8283
|
+
});
|
|
8159
8284
|
const pending = this.#readToken();
|
|
8160
8285
|
this.#tokenReads.add(pending);
|
|
8161
8286
|
let value;
|
|
@@ -8163,6 +8288,11 @@ class ClaustrumScopedCustody {
|
|
|
8163
8288
|
value = await pending;
|
|
8164
8289
|
} finally {
|
|
8165
8290
|
this.#tokenReads.delete(pending);
|
|
8291
|
+
if (phaseDiagnostics.hasSubscribers)
|
|
8292
|
+
phaseDiagnostics.publish({
|
|
8293
|
+
logger: this.#logger,
|
|
8294
|
+
phase: "token read end"
|
|
8295
|
+
});
|
|
8166
8296
|
}
|
|
8167
8297
|
this.#check(signal);
|
|
8168
8298
|
if (!/^[0-9a-f]{64}$/.test(value.token) || !Number.isSafeInteger(value.token_generation) || value.token_generation < 1) {
|
|
@@ -8218,11 +8348,22 @@ class ClaustrumScopedCustody {
|
|
|
8218
8348
|
this.#kept.clear();
|
|
8219
8349
|
throw error;
|
|
8220
8350
|
}
|
|
8351
|
+
if (phaseDiagnostics.hasSubscribers)
|
|
8352
|
+
phaseDiagnostics.publish({
|
|
8353
|
+
logger: this.#logger,
|
|
8354
|
+
phase: "list scoped begin"
|
|
8355
|
+
});
|
|
8221
8356
|
try {
|
|
8222
8357
|
inventory = await this.#call(() => this.#client.listScoped(token), signal);
|
|
8223
8358
|
} catch (error) {
|
|
8224
8359
|
this.listFailed(error);
|
|
8225
8360
|
throw error;
|
|
8361
|
+
} finally {
|
|
8362
|
+
if (phaseDiagnostics.hasSubscribers)
|
|
8363
|
+
phaseDiagnostics.publish({
|
|
8364
|
+
logger: this.#logger,
|
|
8365
|
+
phase: "list scoped end"
|
|
8366
|
+
});
|
|
8226
8367
|
}
|
|
8227
8368
|
const skipped = [];
|
|
8228
8369
|
const refused = [];
|
|
@@ -8523,7 +8664,7 @@ class ClaustrumScopedCustody {
|
|
|
8523
8664
|
}
|
|
8524
8665
|
|
|
8525
8666
|
// ../../node_modules/@cortexkit/common-auth/dist/claustrum/quota-writer.js
|
|
8526
|
-
import { resolve as
|
|
8667
|
+
import { resolve as resolve9 } from "node:path";
|
|
8527
8668
|
|
|
8528
8669
|
// ../../node_modules/@cortexkit/common-auth/dist/quota/commit-interval.js
|
|
8529
8670
|
var QUOTA_COMMIT_INTERVAL_MS = 30000;
|
|
@@ -8852,7 +8993,7 @@ function displayOrder(left, right) {
|
|
|
8852
8993
|
return left.label < right.label ? -1 : left.label > right.label ? 1 : 0;
|
|
8853
8994
|
}
|
|
8854
8995
|
function quotaWindowParts(quota, options) {
|
|
8855
|
-
const { windows, age } = scopedWindowParts(quota, options);
|
|
8996
|
+
const { windows, age } = scopedWindowParts(quota, options, true);
|
|
8856
8997
|
const parts = windows.map(({ part }) => part);
|
|
8857
8998
|
return age === undefined ? { windows: parts } : { windows: parts, age };
|
|
8858
8999
|
}
|
|
@@ -8863,25 +9004,36 @@ function withShortNames(windows) {
|
|
|
8863
9004
|
}
|
|
8864
9005
|
return windows;
|
|
8865
9006
|
}
|
|
8866
|
-
function
|
|
9007
|
+
function hasWindowReading(limit) {
|
|
9008
|
+
return Number.isFinite(limit.remainingPercent) && Number.isFinite(limit.checkedAt);
|
|
9009
|
+
}
|
|
9010
|
+
function scopedWindowParts(quota, options, includeUnknown = false) {
|
|
8867
9011
|
if (!quota)
|
|
8868
9012
|
return { windows: [] };
|
|
8869
9013
|
const { now } = options;
|
|
8870
|
-
const readings = quota.limits.filter((limit) => limit.kind === "reading" &&
|
|
9014
|
+
const readings = quota.limits.filter((limit) => limit.kind === "reading" && (includeUnknown || hasWindowReading(limit))).sort(displayOrder);
|
|
8871
9015
|
const windows = readings.map((limit) => {
|
|
8872
|
-
const
|
|
9016
|
+
const part = hasWindowReading(limit) ? {
|
|
9017
|
+
kind: "window",
|
|
9018
|
+
reading: "known",
|
|
9019
|
+
name: quotaWindowName(limit),
|
|
9020
|
+
short: "",
|
|
9021
|
+
figure: percentLeft(limit.remainingPercent),
|
|
9022
|
+
remainingPercent: clampPercent2(limit.remainingPercent),
|
|
9023
|
+
checkedAt: limit.checkedAt,
|
|
9024
|
+
...resetDetails(limit.resetsAt, limit.checkedAt, now)
|
|
9025
|
+
} : {
|
|
9026
|
+
kind: "window",
|
|
9027
|
+
reading: "unknown",
|
|
9028
|
+
name: quotaWindowName(limit),
|
|
9029
|
+
short: "",
|
|
9030
|
+
figure: "no reading",
|
|
9031
|
+
resetSinceReading: false
|
|
9032
|
+
};
|
|
8873
9033
|
return {
|
|
8874
9034
|
scope: limit.scope,
|
|
8875
9035
|
...limit.windowMinutes === undefined ? {} : { windowMinutes: limit.windowMinutes },
|
|
8876
|
-
part
|
|
8877
|
-
kind: "window",
|
|
8878
|
-
name: quotaWindowName(limit),
|
|
8879
|
-
short: "",
|
|
8880
|
-
figure: percentLeft(limit.remainingPercent ?? 0),
|
|
8881
|
-
remainingPercent,
|
|
8882
|
-
checkedAt: limit.checkedAt,
|
|
8883
|
-
...resetDetails(limit.resetsAt, limit.checkedAt, now)
|
|
8884
|
-
}
|
|
9036
|
+
part
|
|
8885
9037
|
};
|
|
8886
9038
|
});
|
|
8887
9039
|
const budget = quota.budget;
|
|
@@ -8893,6 +9045,7 @@ function scopedWindowParts(quota, options) {
|
|
|
8893
9045
|
spent: budget.reached,
|
|
8894
9046
|
part: {
|
|
8895
9047
|
kind: "budget",
|
|
9048
|
+
reading: "known",
|
|
8896
9049
|
name: "credits",
|
|
8897
9050
|
short: "",
|
|
8898
9051
|
figure,
|
|
@@ -8903,8 +9056,9 @@ function scopedWindowParts(quota, options) {
|
|
|
8903
9056
|
});
|
|
8904
9057
|
}
|
|
8905
9058
|
withShortNames(windows);
|
|
8906
|
-
|
|
8907
|
-
|
|
9059
|
+
const readingTimes = windows.flatMap(({ part }) => part.reading === "known" && part.checkedAt !== undefined ? [part.checkedAt] : []);
|
|
9060
|
+
if (readingTimes.length > 0) {
|
|
9061
|
+
const age = now - Math.min(...readingTimes);
|
|
8908
9062
|
if (age > (options.staleAfterMs ?? QUOTA_STALE_AFTER_MS)) {
|
|
8909
9063
|
return { windows, age: `checked ${shortSpan(age)} ago` };
|
|
8910
9064
|
}
|
|
@@ -9004,13 +9158,13 @@ function narrowTextParts(quota, options) {
|
|
|
9004
9158
|
function quotaTextParts(quota, options) {
|
|
9005
9159
|
if (options.form === "narrow")
|
|
9006
9160
|
return narrowTextParts(quota, options);
|
|
9007
|
-
const
|
|
9161
|
+
const { windows, age } = scopedWindowParts(quota, options);
|
|
9008
9162
|
const full = (options.form ?? "full") === "full";
|
|
9009
|
-
const text =
|
|
9163
|
+
const text = windows.map(({ part }) => {
|
|
9010
9164
|
const reset = full && part.resetIn ? `, resets ${part.resetIn}` : "";
|
|
9011
9165
|
return `${part.kind === "budget" ? "" : `${part.name} `}${part.figure}${reset}`;
|
|
9012
9166
|
});
|
|
9013
|
-
return
|
|
9167
|
+
return age === undefined ? text : [...text, age];
|
|
9014
9168
|
}
|
|
9015
9169
|
function formatQuota(quota, options) {
|
|
9016
9170
|
const parts = quotaTextParts(quota, options);
|
|
@@ -9069,7 +9223,7 @@ function quotaFields(publication, witness = "") {
|
|
|
9069
9223
|
// ../../node_modules/@cortexkit/common-auth/dist/claustrum/roster.js
|
|
9070
9224
|
import { createHash as createHash5 } from "node:crypto";
|
|
9071
9225
|
import { stat as stat6 } from "node:fs/promises";
|
|
9072
|
-
import { resolve as
|
|
9226
|
+
import { resolve as resolve8 } from "node:path";
|
|
9073
9227
|
|
|
9074
9228
|
// ../../node_modules/@cortexkit/common-auth/dist/claustrum/interlock.js
|
|
9075
9229
|
function matches(entry, credentialId, accountIdentity) {
|
|
@@ -9494,16 +9648,16 @@ function applyVaultQuota(current, input) {
|
|
|
9494
9648
|
}
|
|
9495
9649
|
var pendingDiscoveries = new Map;
|
|
9496
9650
|
function forgetPendingVaultDiscovery(path2) {
|
|
9497
|
-
pendingDiscoveries.delete(
|
|
9651
|
+
pendingDiscoveries.delete(resolve8(path2));
|
|
9498
9652
|
}
|
|
9499
9653
|
function isVaultRosterLockRefusal(path2, error) {
|
|
9500
|
-
const target =
|
|
9654
|
+
const target = resolve8(path2);
|
|
9501
9655
|
if (error instanceof ClaustrumConsumerError)
|
|
9502
9656
|
return error.kind === "roster-busy";
|
|
9503
9657
|
if (error instanceof LockContentionError || error instanceof LockOwnershipError)
|
|
9504
|
-
return
|
|
9658
|
+
return resolve8(error.details.target) === target;
|
|
9505
9659
|
if (error instanceof PrivateFileError) {
|
|
9506
|
-
const failed =
|
|
9660
|
+
const failed = resolve8(error.path);
|
|
9507
9661
|
return [WRITE_LOCK.name, DISCOVERY_LEASE.name].some((name) => {
|
|
9508
9662
|
const lock = lockPathFor(target, name);
|
|
9509
9663
|
return failed === lock || failed.startsWith(`${lock}.`);
|
|
@@ -9564,7 +9718,7 @@ async function refreshVaultRoster(options) {
|
|
|
9564
9718
|
throw new ClaustrumConsumerError("roster-busy", "Claustrum account discovery is already in progress");
|
|
9565
9719
|
return persisted;
|
|
9566
9720
|
}
|
|
9567
|
-
const key =
|
|
9721
|
+
const key = resolve8(options.path);
|
|
9568
9722
|
const listedOver = options.listedOver;
|
|
9569
9723
|
let discovered;
|
|
9570
9724
|
try {
|
|
@@ -9627,7 +9781,7 @@ var writers = new Map;
|
|
|
9627
9781
|
var logger2 = createLogger("claustrum");
|
|
9628
9782
|
var COALESCE_MS = 100;
|
|
9629
9783
|
function writerFor(path2, clock = quotaCommitTimer) {
|
|
9630
|
-
const key =
|
|
9784
|
+
const key = resolve9(path2);
|
|
9631
9785
|
let writer = writers.get(key);
|
|
9632
9786
|
if (!writer) {
|
|
9633
9787
|
writer = {
|
|
@@ -9691,7 +9845,7 @@ function orderedFields(pending) {
|
|
|
9691
9845
|
return [...pending.values()].flatMap((account) => [...account.values()]).sort((a, b) => a.order - b.order);
|
|
9692
9846
|
}
|
|
9693
9847
|
function pendingVaultQuota(path2, roster) {
|
|
9694
|
-
const writer = writers.get(
|
|
9848
|
+
const writer = writers.get(resolve9(path2));
|
|
9695
9849
|
if (writer) {
|
|
9696
9850
|
for (const field of orderedFields(writer.pending)) {
|
|
9697
9851
|
if (field.priorReading)
|
|
@@ -9702,7 +9856,7 @@ function pendingVaultQuota(path2, roster) {
|
|
|
9702
9856
|
return roster;
|
|
9703
9857
|
}
|
|
9704
9858
|
function hasPendingVaultQuota(path2) {
|
|
9705
|
-
return !!writers.get(
|
|
9859
|
+
return !!writers.get(resolve9(path2))?.pending.size;
|
|
9706
9860
|
}
|
|
9707
9861
|
function schedule(writer, delay3) {
|
|
9708
9862
|
if (writer.running || writer.timer || !writer.pending.size || writer.abort.signal.aborted)
|
|
@@ -9767,7 +9921,7 @@ function flush2(writer) {
|
|
|
9767
9921
|
return writer.running;
|
|
9768
9922
|
}
|
|
9769
9923
|
async function drainVaultQuota(path2, timeoutMs = 1000) {
|
|
9770
|
-
const key =
|
|
9924
|
+
const key = resolve9(path2);
|
|
9771
9925
|
const writer = writers.get(key);
|
|
9772
9926
|
if (!writer)
|
|
9773
9927
|
return;
|
|
@@ -9877,7 +10031,7 @@ class ClaustrumConsumer {
|
|
|
9877
10031
|
this.#shutdown.signal,
|
|
9878
10032
|
...signal ? [signal] : []
|
|
9879
10033
|
]);
|
|
9880
|
-
return new Promise((
|
|
10034
|
+
return new Promise((resolve10, reject) => {
|
|
9881
10035
|
const cleanup = () => {
|
|
9882
10036
|
combined.signal.removeEventListener("abort", abort);
|
|
9883
10037
|
combined.dispose();
|
|
@@ -9892,7 +10046,7 @@ class ClaustrumConsumer {
|
|
|
9892
10046
|
if (combined.signal.aborted)
|
|
9893
10047
|
reject(combined.signal.reason);
|
|
9894
10048
|
else
|
|
9895
|
-
|
|
10049
|
+
resolve10(value);
|
|
9896
10050
|
}, (error) => {
|
|
9897
10051
|
cleanup();
|
|
9898
10052
|
reject(error);
|
|
@@ -10493,8 +10647,9 @@ class ClaustrumConsumer {
|
|
|
10493
10647
|
}
|
|
10494
10648
|
// ../../node_modules/@cortexkit/common-auth/dist/claustrum/hub.js
|
|
10495
10649
|
import { createHash as createHash6 } from "node:crypto";
|
|
10650
|
+
import { channel as channel2 } from "node:diagnostics_channel";
|
|
10496
10651
|
import { readdir as readdir2, stat as stat7 } from "node:fs/promises";
|
|
10497
|
-
import { dirname as dirname8, join as
|
|
10652
|
+
import { dirname as dirname8, join as join11, resolve as resolve10 } from "node:path";
|
|
10498
10653
|
var sharedRosters = new Map;
|
|
10499
10654
|
var FILE_ID = /^[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
10500
10655
|
var WINDOWS_DEVICE = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\.|$)/;
|
|
@@ -10558,12 +10713,12 @@ function unreachableConnect2() {
|
|
|
10558
10713
|
return new ClaustrumUnreachableError;
|
|
10559
10714
|
}
|
|
10560
10715
|
function untilAborted(pending, signal) {
|
|
10561
|
-
return new Promise((
|
|
10716
|
+
return new Promise((resolve11, reject) => {
|
|
10562
10717
|
const abort = () => reject(signal.reason);
|
|
10563
10718
|
signal.addEventListener("abort", abort, { once: true });
|
|
10564
10719
|
pending.then((value) => {
|
|
10565
10720
|
signal.removeEventListener("abort", abort);
|
|
10566
|
-
|
|
10721
|
+
resolve11(value);
|
|
10567
10722
|
}, (error) => {
|
|
10568
10723
|
signal.removeEventListener("abort", abort);
|
|
10569
10724
|
reject(error);
|
|
@@ -10609,13 +10764,13 @@ class ClaustrumDiscoveryHub {
|
|
|
10609
10764
|
this.#options = options;
|
|
10610
10765
|
this.#logger = options.logger ?? createLogger("claustrum");
|
|
10611
10766
|
this.#warnShutdown = shutdownWarning(this.#logger, this.#shutdown.signal);
|
|
10612
|
-
this.#generationDirectory =
|
|
10767
|
+
this.#generationDirectory = join11(options.stateDir, "rosters", hostGeneration);
|
|
10613
10768
|
this.#key = rosterFingerprint(options, providers);
|
|
10614
|
-
const directory =
|
|
10769
|
+
const directory = join11(this.#generationDirectory, this.#key);
|
|
10615
10770
|
for (const provider of providers)
|
|
10616
10771
|
this.#members.set(provider, {
|
|
10617
10772
|
provider,
|
|
10618
|
-
path:
|
|
10773
|
+
path: join11(directory, `${provider}.json`),
|
|
10619
10774
|
closed: false
|
|
10620
10775
|
});
|
|
10621
10776
|
}
|
|
@@ -10690,7 +10845,7 @@ class ClaustrumDiscoveryHub {
|
|
|
10690
10845
|
};
|
|
10691
10846
|
const { consumer, hooks } = createHubMember(port, consumerOptions);
|
|
10692
10847
|
entry.hooks = hooks;
|
|
10693
|
-
const path2 =
|
|
10848
|
+
const path2 = resolve10(entry.path);
|
|
10694
10849
|
const subscribers = sharedRosters.get(path2) ?? new Set;
|
|
10695
10850
|
const install = (roster) => {
|
|
10696
10851
|
if (entry.closed || this.#active !== true || !this.#current || !this.#live(this.#current) || !hooks.roster() || this.#collides(hooks, roster))
|
|
@@ -10721,7 +10876,7 @@ class ClaustrumDiscoveryHub {
|
|
|
10721
10876
|
return;
|
|
10722
10877
|
entry.seen = JSON.stringify(decodedVaultRoster(roster));
|
|
10723
10878
|
entry.hooks?.install(roster);
|
|
10724
|
-
for (const install of sharedRosters.get(
|
|
10879
|
+
for (const install of sharedRosters.get(resolve10(entry.path)) ?? []) {
|
|
10725
10880
|
if (!this.#live(generation))
|
|
10726
10881
|
return;
|
|
10727
10882
|
if (install !== entry.receiveRoster)
|
|
@@ -11090,7 +11245,24 @@ class ClaustrumDiscoveryHub {
|
|
|
11090
11245
|
throw closed("Claustrum hub member has no base view");
|
|
11091
11246
|
if (base instanceof Error)
|
|
11092
11247
|
throw base;
|
|
11093
|
-
|
|
11248
|
+
let seed;
|
|
11249
|
+
if (!base.file) {
|
|
11250
|
+
const phaseDiagnostics2 = channel2("common-auth.claustrum.phases");
|
|
11251
|
+
if (phaseDiagnostics2.hasSubscribers)
|
|
11252
|
+
phaseDiagnostics2.publish({
|
|
11253
|
+
logger: this.#logger,
|
|
11254
|
+
phase: `seed read ${entry.provider} begin`
|
|
11255
|
+
});
|
|
11256
|
+
try {
|
|
11257
|
+
seed = await this.#seed(entry);
|
|
11258
|
+
} finally {
|
|
11259
|
+
if (phaseDiagnostics2.hasSubscribers)
|
|
11260
|
+
phaseDiagnostics2.publish({
|
|
11261
|
+
logger: this.#logger,
|
|
11262
|
+
phase: `seed read ${entry.provider} end`
|
|
11263
|
+
});
|
|
11264
|
+
}
|
|
11265
|
+
}
|
|
11094
11266
|
const roster = await refreshVaultRoster({
|
|
11095
11267
|
path: entry.path,
|
|
11096
11268
|
custody: { discover: async () => share },
|
|
@@ -11108,17 +11280,17 @@ class ClaustrumDiscoveryHub {
|
|
|
11108
11280
|
for (const directory of [
|
|
11109
11281
|
dirname8(this.#generationDirectory),
|
|
11110
11282
|
this.#generationDirectory,
|
|
11111
|
-
|
|
11283
|
+
join11(this.#generationDirectory, this.#key)
|
|
11112
11284
|
])
|
|
11113
11285
|
await ensureClaustrumPrivateDirectory(directory, {}, "roster directory");
|
|
11114
11286
|
}
|
|
11115
11287
|
async#seed(entry) {
|
|
11116
11288
|
const name = `${entry.provider}.json`;
|
|
11117
|
-
const candidates = [
|
|
11289
|
+
const candidates = [join11(this.#generationDirectory, name)];
|
|
11118
11290
|
try {
|
|
11119
11291
|
for (const key of await readdir2(this.#generationDirectory))
|
|
11120
11292
|
if (key !== this.#key && FINGERPRINT.test(key))
|
|
11121
|
-
candidates.push(
|
|
11293
|
+
candidates.push(join11(this.#generationDirectory, key, name));
|
|
11122
11294
|
} catch {}
|
|
11123
11295
|
let newest;
|
|
11124
11296
|
for (const path2 of candidates) {
|
|
@@ -11358,8 +11530,8 @@ import {
|
|
|
11358
11530
|
dirname as dirname11,
|
|
11359
11531
|
extname as extname2,
|
|
11360
11532
|
isAbsolute as isAbsolute3,
|
|
11361
|
-
join as
|
|
11362
|
-
resolve as
|
|
11533
|
+
join as join13,
|
|
11534
|
+
resolve as resolve11
|
|
11363
11535
|
} from "node:path";
|
|
11364
11536
|
import {
|
|
11365
11537
|
ClaustrumCredentialError as ClaustrumCredentialError5,
|
|
@@ -11756,13 +11928,13 @@ function getClaustrumEnrollmentPaths2(tokenPath) {
|
|
|
11756
11928
|
const extension = extname2(tokenPath) || ".json";
|
|
11757
11929
|
const stem = basename4(tokenPath, extname2(tokenPath));
|
|
11758
11930
|
return {
|
|
11759
|
-
statePath:
|
|
11931
|
+
statePath: join13(dirname11(tokenPath), `${stem}-state${extension}`),
|
|
11760
11932
|
tokenPath
|
|
11761
11933
|
};
|
|
11762
11934
|
}
|
|
11763
11935
|
function getHostClaustrumEnrollmentPaths(host, env = process.env, cwd = process.cwd()) {
|
|
11764
11936
|
const configured = env[`${host.toUpperCase()}_ANTHROPIC_AUTH_CLAUSTRUM_ENROLLMENT_FILE`]?.trim();
|
|
11765
|
-
const tokenPath = configured ? isAbsolute3(configured) ? configured :
|
|
11937
|
+
const tokenPath = configured ? isAbsolute3(configured) ? configured : resolve11(cwd, configured) : join13(anthropicAuthStateRoot({
|
|
11766
11938
|
xdgStateHome: env.XDG_STATE_HOME,
|
|
11767
11939
|
home: homedir4(),
|
|
11768
11940
|
acceptRelative: true
|
|
@@ -11911,7 +12083,7 @@ async function writeStateAtomic2(path2, state, beforeRename) {
|
|
|
11911
12083
|
if (Buffer.byteLength(bytes) > ENROLLMENT_FILE_MAX_BYTES2) {
|
|
11912
12084
|
throw new Error("Claustrum enrollment state is too large");
|
|
11913
12085
|
}
|
|
11914
|
-
const temporary =
|
|
12086
|
+
const temporary = join13(parent, `.${basename4(path2)}.${process.pid}.${randomUUID8()}.tmp`);
|
|
11915
12087
|
let descriptor;
|
|
11916
12088
|
try {
|
|
11917
12089
|
const nativeCreated = await createWindowsOwnerOnly(temporary, bytes);
|
|
@@ -11930,7 +12102,7 @@ async function writeStateAtomic2(path2, state, beforeRename) {
|
|
|
11930
12102
|
}
|
|
11931
12103
|
}
|
|
11932
12104
|
async function writeTokenAtomic(path2, value, writeTokenFile, beforeRename) {
|
|
11933
|
-
const staged =
|
|
12105
|
+
const staged = join13(dirname11(path2), `.${basename4(path2)}.${process.pid}.${randomUUID8()}.tmp`);
|
|
11934
12106
|
try {
|
|
11935
12107
|
await writeTokenFile(staged, value);
|
|
11936
12108
|
await beforeRename();
|
|
@@ -12314,8 +12486,8 @@ function createNativeCustody(options) {
|
|
|
12314
12486
|
let stopped = false;
|
|
12315
12487
|
let inner;
|
|
12316
12488
|
let finish = () => {};
|
|
12317
|
-
const ended = new Promise((
|
|
12318
|
-
finish =
|
|
12489
|
+
const ended = new Promise((resolve12) => {
|
|
12490
|
+
finish = resolve12;
|
|
12319
12491
|
});
|
|
12320
12492
|
const failed = (error) => stopped || closed2 || error instanceof NativeCustodyError ? { kind: "stopped" } : classifyVaultFailure(error) === "unreachable" ? { kind: "transport_lost", error: new ClaustrumUnreachableError } : { kind: "ended" };
|
|
12321
12493
|
Promise.resolve().then(connection).then((owned) => {
|
|
@@ -13975,8 +14147,8 @@ function createProviderErrorResponseScope(secrets, mode) {
|
|
|
13975
14147
|
wrappedBodies: 0
|
|
13976
14148
|
};
|
|
13977
14149
|
let resolveSettled = () => {};
|
|
13978
|
-
const settled = new Promise((
|
|
13979
|
-
resolveSettled =
|
|
14150
|
+
const settled = new Promise((resolve12) => {
|
|
14151
|
+
resolveSettled = resolve12;
|
|
13980
14152
|
});
|
|
13981
14153
|
let retired = false;
|
|
13982
14154
|
let used = false;
|
|
@@ -14834,14 +15006,14 @@ import {
|
|
|
14834
15006
|
writeFile as writeFile4
|
|
14835
15007
|
} from "node:fs/promises";
|
|
14836
15008
|
import { tmpdir as tmpdir6 } from "node:os";
|
|
14837
|
-
import { join as
|
|
15009
|
+
import { join as join21 } from "node:path";
|
|
14838
15010
|
|
|
14839
15011
|
// src/holder-registry.ts
|
|
14840
15012
|
import { execFile } from "node:child_process";
|
|
14841
15013
|
import { randomUUID as randomUUID14 } from "node:crypto";
|
|
14842
15014
|
import { readFileSync as readFileSync2 } from "node:fs";
|
|
14843
15015
|
import { lstat as lstat12, mkdir as mkdir10, readFile as readFile11 } from "node:fs/promises";
|
|
14844
|
-
import { basename as basename9, dirname as dirname17, join as
|
|
15016
|
+
import { basename as basename9, dirname as dirname17, join as join20 } from "node:path";
|
|
14845
15017
|
|
|
14846
15018
|
// src/native-lock-observer.ts
|
|
14847
15019
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
@@ -14884,17 +15056,17 @@ function observeNativeLocks(acquire, observer) {
|
|
|
14884
15056
|
|
|
14885
15057
|
// src/native-vault-paths.ts
|
|
14886
15058
|
import { createHash as createHash18 } from "node:crypto";
|
|
14887
|
-
import { basename as basename8, dirname as dirname15, join as
|
|
15059
|
+
import { basename as basename8, dirname as dirname15, join as join17 } from "node:path";
|
|
14888
15060
|
|
|
14889
15061
|
// src/pool-paths.ts
|
|
14890
15062
|
import { createHash as createHash17 } from "node:crypto";
|
|
14891
15063
|
import { realpath as realpath3 } from "node:fs/promises";
|
|
14892
|
-
import { basename as basename7, dirname as dirname14, join as
|
|
15064
|
+
import { basename as basename7, dirname as dirname14, join as join16, resolve as resolve12 } from "node:path";
|
|
14893
15065
|
|
|
14894
15066
|
// src/sticky-routing.ts
|
|
14895
15067
|
import { createHash as createHash16, randomUUID as randomUUID12 } from "node:crypto";
|
|
14896
15068
|
import { mkdir as mkdir9, readFile as readFile8, rename as rename11, rm as rm6, stat as stat9, writeFile as writeFile3 } from "node:fs/promises";
|
|
14897
|
-
import { basename as basename6, dirname as dirname13, join as
|
|
15069
|
+
import { basename as basename6, dirname as dirname13, join as join15 } from "node:path";
|
|
14898
15070
|
|
|
14899
15071
|
// src/native-vault-seed.ts
|
|
14900
15072
|
import { lstat as lstat7, readFile as readFile7 } from "node:fs/promises";
|
|
@@ -15065,7 +15237,7 @@ async function acquirePoolLock(spec, defaults, env) {
|
|
|
15065
15237
|
});
|
|
15066
15238
|
}
|
|
15067
15239
|
const jitter = Math.floor(Math.random() * (options.retryMs + 1));
|
|
15068
|
-
await new Promise((
|
|
15240
|
+
await new Promise((resolve12) => setTimeout(resolve12, Math.min(options.retryMs + jitter, remaining)));
|
|
15069
15241
|
}
|
|
15070
15242
|
}
|
|
15071
15243
|
function definedOnly(spec) {
|
|
@@ -17707,11 +17879,11 @@ class PoolQuotaWriter {
|
|
|
17707
17879
|
const left = deadline - performance.now();
|
|
17708
17880
|
if (left <= 0)
|
|
17709
17881
|
throw refusal("pull", id, "lock-contention", `pool quota queue for ${id} is full (${POOL_QUOTA_QUEUE_LIMIT} readings) and the store locks stayed held`, true);
|
|
17710
|
-
await new Promise((
|
|
17882
|
+
await new Promise((resolve12) => {
|
|
17711
17883
|
const done = () => {
|
|
17712
17884
|
clearTimeout(timer);
|
|
17713
17885
|
this.wake.delete(done);
|
|
17714
|
-
|
|
17886
|
+
resolve12();
|
|
17715
17887
|
};
|
|
17716
17888
|
const timer = setTimeout(done, left);
|
|
17717
17889
|
this.wake.add(done);
|
|
@@ -18823,7 +18995,7 @@ var nativeQuotaCodec = {
|
|
|
18823
18995
|
import { randomUUID as randomUUID11 } from "node:crypto";
|
|
18824
18996
|
import { constants as constants2 } from "node:fs";
|
|
18825
18997
|
import { lstat as lstat6, mkdir as mkdir8, open as open8, rename as rename10, rm as rm5 } from "node:fs/promises";
|
|
18826
|
-
import { basename as basename5, dirname as dirname12, isAbsolute as isAbsolute4, join as
|
|
18998
|
+
import { basename as basename5, dirname as dirname12, isAbsolute as isAbsolute4, join as join14 } from "node:path";
|
|
18827
18999
|
import { types as utilTypes5 } from "node:util";
|
|
18828
19000
|
|
|
18829
19001
|
// src/pool-binding.ts
|
|
@@ -19027,7 +19199,7 @@ async function renameWithWindowsSharingRetry(from, to, options = {}, beforeRetry
|
|
|
19027
19199
|
return "published";
|
|
19028
19200
|
}
|
|
19029
19201
|
const now = options.now ?? (() => performance.now());
|
|
19030
|
-
const sleep = options.sleep ?? ((ms) => new Promise((
|
|
19202
|
+
const sleep = options.sleep ?? ((ms) => new Promise((resolve12) => setTimeout(resolve12, ms)));
|
|
19031
19203
|
const start = now();
|
|
19032
19204
|
let original;
|
|
19033
19205
|
try {
|
|
@@ -19394,7 +19566,7 @@ async function writeNativeRuntimeOutcome(path2, storageId, change, hooks, firstI
|
|
|
19394
19566
|
assertTransitions(current, next, firstIdentity);
|
|
19395
19567
|
const bytes = `${JSON.stringify(next, null, 2)}
|
|
19396
19568
|
`;
|
|
19397
|
-
const stage =
|
|
19569
|
+
const stage = join14(dirname12(path2), `${basename5(path2)}.native-runtime.${randomUUID11()}.partial`);
|
|
19398
19570
|
let ownsStage = false;
|
|
19399
19571
|
try {
|
|
19400
19572
|
const nativeCreated = await createWindowsOwnerOnly(stage, bytes);
|
|
@@ -20871,7 +21043,7 @@ function stickyRetainRetryHeaders(upstream, now = Date.now()) {
|
|
|
20871
21043
|
function getStickyRoutingStatePath(accountStoragePath) {
|
|
20872
21044
|
const name = basename6(accountStoragePath);
|
|
20873
21045
|
const stem = name.endsWith(".json") ? name.slice(0, -5) : name;
|
|
20874
|
-
return
|
|
21046
|
+
return join15(dirname13(accountStoragePath), `${stem}-routing-state.json`);
|
|
20875
21047
|
}
|
|
20876
21048
|
function stickyRetryAfterWithJitter(sessionId, retryAfterSeconds) {
|
|
20877
21049
|
const hash2 = createHash16("sha256").update(sessionId).digest().readUInt32BE(0);
|
|
@@ -20972,7 +21144,7 @@ class StickySessionRouter {
|
|
|
20972
21144
|
if (!wait || performance.now() >= deadline) {
|
|
20973
21145
|
throw new Error("Timed out acquiring sticky routing state lock");
|
|
20974
21146
|
}
|
|
20975
|
-
await new Promise((
|
|
21147
|
+
await new Promise((resolve12) => setTimeout(resolve12, STICKY_ROUTING_LOCK_POLL_MS));
|
|
20976
21148
|
}
|
|
20977
21149
|
}
|
|
20978
21150
|
recoverLocalPins() {
|
|
@@ -21343,7 +21515,7 @@ function resolveLocalRoutingDestination(host, paths, env) {
|
|
|
21343
21515
|
return (host === "opencode" ? env.OPENCODE_ANTHROPIC_AUTH_ROUTING_STATE_FILE : env.PI_ANTHROPIC_AUTH_ROUTING_STATE_FILE) || getStickyRoutingStatePath(paths.config);
|
|
21344
21516
|
}
|
|
21345
21517
|
async function canonicalPath(path2) {
|
|
21346
|
-
const absolute =
|
|
21518
|
+
const absolute = resolve12(path2);
|
|
21347
21519
|
try {
|
|
21348
21520
|
return await realpath3(absolute);
|
|
21349
21521
|
} catch (error) {
|
|
@@ -21354,10 +21526,10 @@ async function canonicalPath(path2) {
|
|
|
21354
21526
|
const parent = dirname14(absolute);
|
|
21355
21527
|
if (parent === absolute)
|
|
21356
21528
|
return absolute;
|
|
21357
|
-
return
|
|
21529
|
+
return join16(await canonicalPath(parent), basename7(absolute));
|
|
21358
21530
|
}
|
|
21359
21531
|
function sibling(path2, legacyName, name, suffix) {
|
|
21360
|
-
return basename7(path2) === legacyName ?
|
|
21532
|
+
return basename7(path2) === legacyName ? join16(dirname14(path2), name) : `${path2}.${suffix}.json`;
|
|
21361
21533
|
}
|
|
21362
21534
|
async function resolveNativePoolPaths(legacyConfig = getAccountStoragePath(), legacyState = getAccountStatePath(legacyConfig), layout) {
|
|
21363
21535
|
const [sourceConfig, sourceState] = await Promise.all([
|
|
@@ -21407,7 +21579,7 @@ async function resolveNativePoolPaths(legacyConfig = getAccountStoragePath(), le
|
|
|
21407
21579
|
|
|
21408
21580
|
// src/native-vault-paths.ts
|
|
21409
21581
|
function sibling2(path2, expected, name, suffix) {
|
|
21410
|
-
return basename8(path2) === expected ?
|
|
21582
|
+
return basename8(path2) === expected ? join17(dirname15(path2), name) : path2.replace(/(?:\.json)?$/, `.${suffix}.json`);
|
|
21411
21583
|
}
|
|
21412
21584
|
function nativeVaultPaths(local, layout = stateLayoutOfPaths(local)) {
|
|
21413
21585
|
const config = sibling2(local.legacyConfig, "anthropic-auth.json", "anthropic-auth-vault-settings.json", "vault-settings");
|
|
@@ -21451,7 +21623,7 @@ import { lstat as lstat11 } from "node:fs/promises";
|
|
|
21451
21623
|
|
|
21452
21624
|
// src/state-home-serving-guard.ts
|
|
21453
21625
|
import { lstat as lstat10 } from "node:fs/promises";
|
|
21454
|
-
import { dirname as dirname16, join as
|
|
21626
|
+
import { dirname as dirname16, join as join19 } from "node:path";
|
|
21455
21627
|
|
|
21456
21628
|
// src/state-layout-errors.ts
|
|
21457
21629
|
var RESTORE_LEGACY_COMMAND = "npx @cortexkit/opencode-anthropic-auth setup --restore-legacy";
|
|
@@ -21644,7 +21816,7 @@ class StateLayoutLockStack {
|
|
|
21644
21816
|
name: spec.name,
|
|
21645
21817
|
timeoutMs
|
|
21646
21818
|
});
|
|
21647
|
-
await new Promise((
|
|
21819
|
+
await new Promise((resolve13) => setTimeout(resolve13, Math.min(remaining, POOL_LOCK_DEFAULTS.retryMs + Math.floor(Math.random() * 25))));
|
|
21648
21820
|
}
|
|
21649
21821
|
}
|
|
21650
21822
|
async assertAll() {
|
|
@@ -21679,7 +21851,7 @@ class StateLayoutLockStack {
|
|
|
21679
21851
|
// src/state-layout-record.ts
|
|
21680
21852
|
import { randomUUID as randomUUID13 } from "node:crypto";
|
|
21681
21853
|
import { lstat as lstat9, readFile as readFile10, unlink as unlink6 } from "node:fs/promises";
|
|
21682
|
-
import { join as
|
|
21854
|
+
import { join as join18 } from "node:path";
|
|
21683
21855
|
var RELOCATION_ROLES = [
|
|
21684
21856
|
"localPoolState",
|
|
21685
21857
|
"journal",
|
|
@@ -21858,7 +22030,7 @@ function parseRestore(value, phase) {
|
|
|
21858
22030
|
};
|
|
21859
22031
|
}
|
|
21860
22032
|
function layoutRecordPath(sub) {
|
|
21861
|
-
return
|
|
22033
|
+
return join18(sub, STATE_HOME_FILE_NAMES.layoutMarker);
|
|
21862
22034
|
}
|
|
21863
22035
|
function movingJournalPath(journal, attempt) {
|
|
21864
22036
|
return `${journal}.moving-${attempt}`;
|
|
@@ -21916,11 +22088,11 @@ function stateHomeServingFiles(paths) {
|
|
|
21916
22088
|
const oldDir = dirname16(paths.legacyState);
|
|
21917
22089
|
return {
|
|
21918
22090
|
sub: dirname16(paths.runtime),
|
|
21919
|
-
oldPoolState:
|
|
22091
|
+
oldPoolState: join19(oldDir, STATE_HOME_FILE_NAMES.localPoolState),
|
|
21920
22092
|
newPoolState: paths.state,
|
|
21921
|
-
oldJournal:
|
|
22093
|
+
oldJournal: join19(oldDir, STATE_HOME_FILE_NAMES.journal),
|
|
21922
22094
|
newJournal: paths.journal,
|
|
21923
|
-
oldMetadata: METADATA_ROLES.map((role) =>
|
|
22095
|
+
oldMetadata: METADATA_ROLES.map((role) => join19(oldDir, STATE_HOME_FILE_NAMES[role]))
|
|
21924
22096
|
};
|
|
21925
22097
|
}
|
|
21926
22098
|
var METADATA_ROLES = [
|
|
@@ -22045,14 +22217,14 @@ function guardIoFailure(sub, error) {
|
|
|
22045
22217
|
return error instanceof StateLayoutRefusalError ? error : stateLayoutIoFailure(`check the state of ${sub}`, [sub], error);
|
|
22046
22218
|
}
|
|
22047
22219
|
function markerRefusal(sub, cause) {
|
|
22048
|
-
const path2 =
|
|
22220
|
+
const path2 = join19(sub, STATE_HOME_FILE_NAMES.layoutMarker);
|
|
22049
22221
|
return new StateLayoutRefusalError("marker-unreadable", `anthropic-auth can't read ${path2}, which records where its state is, so it stopped using that state. Restore the file from a backup or ask for help; do not delete the state folder.`, [path2], cause);
|
|
22050
22222
|
}
|
|
22051
22223
|
var reported = new Set;
|
|
22052
22224
|
var observations = new Map;
|
|
22053
22225
|
var probe;
|
|
22054
22226
|
function createStateHomeServingGuard(files) {
|
|
22055
|
-
const marker =
|
|
22227
|
+
const marker = join19(files.sub, STATE_HOME_FILE_NAMES.layoutMarker);
|
|
22056
22228
|
const dataset = JSON.stringify(files);
|
|
22057
22229
|
function report(refusal2) {
|
|
22058
22230
|
if (refusal2 && !reported.has(refusal2.message)) {
|
|
@@ -22312,10 +22484,10 @@ async function linuxIncarnation(pid) {
|
|
|
22312
22484
|
}
|
|
22313
22485
|
}
|
|
22314
22486
|
function macosIncarnation(pid) {
|
|
22315
|
-
return new Promise((
|
|
22487
|
+
return new Promise((resolve13) => {
|
|
22316
22488
|
execFile("ps", ["-o", "lstart=", "-p", String(pid)], { env: { ...process.env, TZ: "UTC0" }, timeout: 5000 }, (error, stdout) => {
|
|
22317
22489
|
const text5 = String(stdout ?? "").trim();
|
|
22318
|
-
|
|
22490
|
+
resolve13(error || !text5 ? null : text5);
|
|
22319
22491
|
});
|
|
22320
22492
|
});
|
|
22321
22493
|
}
|
|
@@ -22399,7 +22571,7 @@ async function anyExists(paths) {
|
|
|
22399
22571
|
return false;
|
|
22400
22572
|
}
|
|
22401
22573
|
async function isManagedDirectory(dir) {
|
|
22402
|
-
return await exists2(
|
|
22574
|
+
return await exists2(join20(dir, STATE_HOME_FILE_NAMES.configDirMarker)) || await exists2(join20(dir, STATE_HOME_FILE_NAMES.layoutMarker));
|
|
22403
22575
|
}
|
|
22404
22576
|
async function assertUnmanagedInjectedPaths(paths) {
|
|
22405
22577
|
if (stateLayoutOfPaths(paths).kind === "state-home")
|
|
@@ -22518,7 +22690,7 @@ async function buildEntry(options) {
|
|
|
22518
22690
|
async function registerNativePoolHolder(options) {
|
|
22519
22691
|
const entry2 = await buildEntry(options);
|
|
22520
22692
|
const dirs = [...new Set(entry2.files.map((file) => dirname17(file)))].sort();
|
|
22521
|
-
const holderFiles = dirs.map((dir) =>
|
|
22693
|
+
const holderFiles = dirs.map((dir) => join20(dir, HOLDER_FILE_NAME));
|
|
22522
22694
|
const done = {
|
|
22523
22695
|
status: "registered",
|
|
22524
22696
|
settled: Promise.resolve(),
|
|
@@ -22556,7 +22728,7 @@ function warnRegistrationFailure(dir, error) {
|
|
|
22556
22728
|
}
|
|
22557
22729
|
function registrationAttempt(options, entry2, mandatory) {
|
|
22558
22730
|
const dirs = [...new Set(entry2.files.map((file) => dirname17(file)))].sort();
|
|
22559
|
-
const holderFiles = dirs.map((dir) =>
|
|
22731
|
+
const holderFiles = dirs.map((dir) => join20(dir, HOLDER_FILE_NAME));
|
|
22560
22732
|
return async () => {
|
|
22561
22733
|
let complete = true;
|
|
22562
22734
|
for (const holderFile of holderFiles) {
|
|
@@ -22585,8 +22757,8 @@ function retryInBackground(attempt, options) {
|
|
|
22585
22757
|
let timer;
|
|
22586
22758
|
let closed2 = false;
|
|
22587
22759
|
let settle = () => {};
|
|
22588
|
-
const settled = new Promise((
|
|
22589
|
-
settle =
|
|
22760
|
+
const settled = new Promise((resolve13) => {
|
|
22761
|
+
settle = resolve13;
|
|
22590
22762
|
});
|
|
22591
22763
|
const schedule2 = () => {
|
|
22592
22764
|
if (closed2)
|
|
@@ -22655,7 +22827,7 @@ function isExpiredRecord(record8, now, leaseMs) {
|
|
|
22655
22827
|
return record8.updatedAt <= now && now - record8.updatedAt > leaseMs;
|
|
22656
22828
|
}
|
|
22657
22829
|
function getDefaultCacheKeepRegistryDirectory(scope) {
|
|
22658
|
-
return
|
|
22830
|
+
return join21(tmpdir6(), "opencode-anthropic-auth", "cachekeep-sessions", scope);
|
|
22659
22831
|
}
|
|
22660
22832
|
|
|
22661
22833
|
class CacheKeepSessionRegistry {
|
|
@@ -22666,7 +22838,7 @@ class CacheKeepSessionRegistry {
|
|
|
22666
22838
|
constructor(options) {
|
|
22667
22839
|
this.options = options;
|
|
22668
22840
|
const instanceId = options.instanceId ?? `${process.pid}-${randomUUID15()}`;
|
|
22669
|
-
this.filePath =
|
|
22841
|
+
this.filePath = join21(options.directory, `${instanceId}.json`);
|
|
22670
22842
|
}
|
|
22671
22843
|
publish(sessions) {
|
|
22672
22844
|
const snapshot = sessions.map((session) => ({ ...session }));
|
|
@@ -22707,7 +22879,7 @@ class CacheKeepSessionRegistry {
|
|
|
22707
22879
|
}
|
|
22708
22880
|
const records = await Promise.all(names.map(async (name) => {
|
|
22709
22881
|
try {
|
|
22710
|
-
const raw = await readFile12(
|
|
22882
|
+
const raw = await readFile12(join21(this.options.directory, name), "utf8");
|
|
22711
22883
|
return normalizeRecord(JSON.parse(raw));
|
|
22712
22884
|
} catch {
|
|
22713
22885
|
return;
|
|
@@ -22749,7 +22921,7 @@ class CacheKeepSessionRegistry {
|
|
|
22749
22921
|
return;
|
|
22750
22922
|
}
|
|
22751
22923
|
await Promise.all(names.map(async (name) => {
|
|
22752
|
-
const recordPath =
|
|
22924
|
+
const recordPath = join21(this.options.directory, name);
|
|
22753
22925
|
if (recordPath === this.filePath)
|
|
22754
22926
|
return;
|
|
22755
22927
|
let initialRecord;
|
|
@@ -24229,13 +24401,13 @@ function logCommittedNativeAccountAdded(account) {
|
|
|
24229
24401
|
}
|
|
24230
24402
|
|
|
24231
24403
|
// src/native-vault-invalidation.ts
|
|
24232
|
-
import { resolve as
|
|
24404
|
+
import { resolve as resolve13 } from "node:path";
|
|
24233
24405
|
var holders = new Set;
|
|
24234
24406
|
function watchNativeVaultAuthority(holder) {
|
|
24235
24407
|
const held = {
|
|
24236
24408
|
...holder,
|
|
24237
|
-
roster:
|
|
24238
|
-
tokenPath:
|
|
24409
|
+
roster: resolve13(holder.roster),
|
|
24410
|
+
tokenPath: resolve13(holder.tokenPath)
|
|
24239
24411
|
};
|
|
24240
24412
|
holders.add(held);
|
|
24241
24413
|
return () => {
|
|
@@ -24244,12 +24416,12 @@ function watchNativeVaultAuthority(holder) {
|
|
|
24244
24416
|
}
|
|
24245
24417
|
function retainNativeVaultRoster(path2, roster) {
|
|
24246
24418
|
for (const holder of holders)
|
|
24247
|
-
if (holder.roster ===
|
|
24419
|
+
if (holder.roster === resolve13(path2))
|
|
24248
24420
|
holder.retain(roster);
|
|
24249
24421
|
}
|
|
24250
24422
|
function closeNativeVaultAuthority(tokenPath) {
|
|
24251
24423
|
for (const holder of holders)
|
|
24252
|
-
if (holder.tokenPath ===
|
|
24424
|
+
if (holder.tokenPath === resolve13(tokenPath))
|
|
24253
24425
|
holder.close();
|
|
24254
24426
|
}
|
|
24255
24427
|
|
|
@@ -24558,12 +24730,12 @@ async function joinNativePoolWrite(paths, signals, check, onLockEvent) {
|
|
|
24558
24730
|
function pause(ms, signals) {
|
|
24559
24731
|
if (signals.some((signal) => signal.aborted))
|
|
24560
24732
|
return Promise.resolve();
|
|
24561
|
-
return new Promise((
|
|
24733
|
+
return new Promise((resolve14) => {
|
|
24562
24734
|
const wake = () => {
|
|
24563
24735
|
clearTimeout(timer);
|
|
24564
24736
|
for (const signal of signals)
|
|
24565
24737
|
signal.removeEventListener("abort", wake);
|
|
24566
|
-
|
|
24738
|
+
resolve14();
|
|
24567
24739
|
};
|
|
24568
24740
|
const timer = setTimeout(wake, ms);
|
|
24569
24741
|
for (const signal of signals)
|
|
@@ -24819,7 +24991,7 @@ function createNativeRefreshCoordinator(options) {
|
|
|
24819
24991
|
name: spec.name,
|
|
24820
24992
|
timeoutMs: POOL_LOCK_DEFAULTS.timeoutMs
|
|
24821
24993
|
});
|
|
24822
|
-
await new Promise((
|
|
24994
|
+
await new Promise((resolve14) => setTimeout(resolve14, Math.min(POOL_LOCK_DEFAULTS.retryMs, remaining)));
|
|
24823
24995
|
}
|
|
24824
24996
|
}
|
|
24825
24997
|
async function run(job, request) {
|
|
@@ -26214,7 +26386,7 @@ function createPublisher() {
|
|
|
26214
26386
|
const batch = { patch, result: Promise.resolve(false) };
|
|
26215
26387
|
pending.set(key, batch);
|
|
26216
26388
|
batch.result = run(async () => {
|
|
26217
|
-
await new Promise((
|
|
26389
|
+
await new Promise((resolve14) => setTimeout(resolve14, 0));
|
|
26218
26390
|
pending.delete(key);
|
|
26219
26391
|
return write(batch.patch);
|
|
26220
26392
|
});
|
|
@@ -26317,18 +26489,18 @@ function classifySafeErrorForLog(error) {
|
|
|
26317
26489
|
} catch {}
|
|
26318
26490
|
return { name, code };
|
|
26319
26491
|
}
|
|
26320
|
-
function logPublicationFailure(
|
|
26492
|
+
function logPublicationFailure(channel3, error) {
|
|
26321
26493
|
let level = "warn";
|
|
26322
26494
|
try {
|
|
26323
26495
|
if (usagePublicationRefusalIsFatal(error))
|
|
26324
26496
|
level = "error";
|
|
26325
26497
|
} catch {}
|
|
26326
|
-
logger[level](
|
|
26498
|
+
logger[level](channel3, "Account usage publication unavailable", classifySafeErrorForLog(error));
|
|
26327
26499
|
}
|
|
26328
|
-
function createNativeUsagePublisher(
|
|
26500
|
+
function createNativeUsagePublisher(channel3) {
|
|
26329
26501
|
const pending = new Set;
|
|
26330
26502
|
const observe2 = (write) => {
|
|
26331
|
-
const work = write.then(() => {}, (error) => logPublicationFailure(
|
|
26503
|
+
const work = write.then(() => {}, (error) => logPublicationFailure(channel3, error));
|
|
26332
26504
|
pending.add(work);
|
|
26333
26505
|
work.then(() => pending.delete(work), () => pending.delete(work));
|
|
26334
26506
|
return work;
|
|
@@ -26336,7 +26508,7 @@ function createNativeUsagePublisher(channel) {
|
|
|
26336
26508
|
return {
|
|
26337
26509
|
observe: observe2,
|
|
26338
26510
|
publish(write) {
|
|
26339
|
-
observe2(new Promise((
|
|
26511
|
+
observe2(new Promise((resolve14) => setTimeout(resolve14, 0)).then(write));
|
|
26340
26512
|
},
|
|
26341
26513
|
async drain() {
|
|
26342
26514
|
while (pending.size)
|
|
@@ -26423,7 +26595,7 @@ class NativeQuotaObservations extends Map {
|
|
|
26423
26595
|
}
|
|
26424
26596
|
|
|
26425
26597
|
// src/native-runtime-registry.ts
|
|
26426
|
-
import { resolve as
|
|
26598
|
+
import { resolve as resolve14 } from "node:path";
|
|
26427
26599
|
var identities = new WeakMap;
|
|
26428
26600
|
var nextIdentity = 0;
|
|
26429
26601
|
function nativeRuntimeOptionIdentity(value) {
|
|
@@ -26452,14 +26624,14 @@ function nativeRuntimeStorageKey(options) {
|
|
|
26452
26624
|
"runtime",
|
|
26453
26625
|
"journal",
|
|
26454
26626
|
"roster"
|
|
26455
|
-
].map((field) =>
|
|
26456
|
-
|
|
26457
|
-
|
|
26458
|
-
|
|
26627
|
+
].map((field) => resolve14(paths[field])),
|
|
26628
|
+
resolve14(enrollment.tokenPath),
|
|
26629
|
+
resolve14(enrollment.statePath),
|
|
26630
|
+
resolve14(connection)
|
|
26459
26631
|
]);
|
|
26460
26632
|
}
|
|
26461
26633
|
function nativeRuntimeConnectionFile(host, env) {
|
|
26462
|
-
return
|
|
26634
|
+
return resolve14(resolveClaustrumConnectionPath(host === "pi" ? env.PI_ANTHROPIC_AUTH_CLAUSTRUM_CONNECTION_FILE : undefined, host === "pi" ? {
|
|
26463
26635
|
...env,
|
|
26464
26636
|
OPENCODE_ANTHROPIC_AUTH_CLAUSTRUM_CONNECTION_FILE: undefined
|
|
26465
26637
|
} : env));
|
|
@@ -26934,8 +27106,8 @@ function validateNativeVaultRosterSeed(existing, input) {
|
|
|
26934
27106
|
// src/quota-manager.ts
|
|
26935
27107
|
var nativeSetTimeout = globalThis.setTimeout;
|
|
26936
27108
|
function pauseOnRealTimer(ms) {
|
|
26937
|
-
return new Promise((
|
|
26938
|
-
const id2 = nativeSetTimeout(
|
|
27109
|
+
return new Promise((resolve15) => {
|
|
27110
|
+
const id2 = nativeSetTimeout(resolve15, ms);
|
|
26939
27111
|
if (typeof id2 === "object" && "unref" in id2)
|
|
26940
27112
|
id2.unref();
|
|
26941
27113
|
});
|
|
@@ -28539,7 +28711,7 @@ function recencyOnly(patch) {
|
|
|
28539
28711
|
return keys4.length === 1 && keys4[0] === "lastUsed" && typeof patch.lastUsed === "number";
|
|
28540
28712
|
}
|
|
28541
28713
|
function waitFor(pending, signal) {
|
|
28542
|
-
return new Promise((
|
|
28714
|
+
return new Promise((resolve15, reject) => {
|
|
28543
28715
|
const abort = () => {
|
|
28544
28716
|
cleanup2();
|
|
28545
28717
|
reject(signal.reason);
|
|
@@ -28548,7 +28720,7 @@ function waitFor(pending, signal) {
|
|
|
28548
28720
|
signal.addEventListener("abort", abort, { once: true });
|
|
28549
28721
|
pending.then((value) => {
|
|
28550
28722
|
cleanup2();
|
|
28551
|
-
signal.aborted ? reject(signal.reason) :
|
|
28723
|
+
signal.aborted ? reject(signal.reason) : resolve15(value);
|
|
28552
28724
|
}, (error) => {
|
|
28553
28725
|
cleanup2();
|
|
28554
28726
|
reject(error);
|
|
@@ -29159,7 +29331,7 @@ class PersistentRelaySession {
|
|
|
29159
29331
|
return;
|
|
29160
29332
|
if (this.connecting)
|
|
29161
29333
|
return await this.connecting;
|
|
29162
|
-
this.connecting = new Promise((
|
|
29334
|
+
this.connecting = new Promise((resolve15, reject) => {
|
|
29163
29335
|
const url = toWebSocketUrl(this.config.url, this.config.token);
|
|
29164
29336
|
const parsed = new URL(url);
|
|
29165
29337
|
parsed.searchParams.set("affinity", this.affinity);
|
|
@@ -29181,7 +29353,7 @@ class PersistentRelaySession {
|
|
|
29181
29353
|
if (message.type === "ready") {
|
|
29182
29354
|
this.timers.clearTimeout(timeout);
|
|
29183
29355
|
this.serverState = message.state;
|
|
29184
|
-
|
|
29356
|
+
resolve15();
|
|
29185
29357
|
return;
|
|
29186
29358
|
}
|
|
29187
29359
|
this.handleMessage(message);
|
|
@@ -29233,15 +29405,15 @@ class PersistentRelaySession {
|
|
|
29233
29405
|
const sentAt = perfNowMs();
|
|
29234
29406
|
let resolveDone;
|
|
29235
29407
|
let rejectDone;
|
|
29236
|
-
const done = new Promise((
|
|
29237
|
-
resolveDone =
|
|
29408
|
+
const done = new Promise((resolve15, reject) => {
|
|
29409
|
+
resolveDone = resolve15;
|
|
29238
29410
|
rejectDone = reject;
|
|
29239
29411
|
});
|
|
29240
|
-
const response = new Promise((
|
|
29412
|
+
const response = new Promise((resolve15, reject) => {
|
|
29241
29413
|
const pending = {
|
|
29242
29414
|
payload,
|
|
29243
29415
|
bodyText,
|
|
29244
|
-
resolve:
|
|
29416
|
+
resolve: resolve15,
|
|
29245
29417
|
reject,
|
|
29246
29418
|
streamDone: false,
|
|
29247
29419
|
accepted: false,
|
|
@@ -30654,7 +30826,7 @@ function createNativeAccountRuntime(options) {
|
|
|
30654
30826
|
const { mode, paths: paths2, store: store2 } = await selectedStorage();
|
|
30655
30827
|
for (let attempt = 0;attempt < 4; attempt++) {
|
|
30656
30828
|
if (attempt)
|
|
30657
|
-
await new Promise((
|
|
30829
|
+
await new Promise((resolve15) => setTimeout(resolve15, 10));
|
|
30658
30830
|
const settings = await store2.readSettings();
|
|
30659
30831
|
if (settings.status !== "ready")
|
|
30660
30832
|
throw new NativeRuntimeError("publication-refused");
|
|
@@ -31386,7 +31558,7 @@ function relayGeneration(input) {
|
|
|
31386
31558
|
// src/native-host-auth-write.ts
|
|
31387
31559
|
import { randomUUID as randomUUID18 } from "node:crypto";
|
|
31388
31560
|
import { lstat as lstat14, open as open11, rename as rename13, unlink as unlink7 } from "node:fs/promises";
|
|
31389
|
-
import { dirname as dirname18, isAbsolute as isAbsolute6, join as
|
|
31561
|
+
import { dirname as dirname18, isAbsolute as isAbsolute6, join as join22 } from "node:path";
|
|
31390
31562
|
class NativeHostAuthWriteError extends Error {
|
|
31391
31563
|
code;
|
|
31392
31564
|
effect;
|
|
@@ -31447,7 +31619,7 @@ async function writeNativeHostAuth(input, hooks = {}) {
|
|
|
31447
31619
|
const removingFile = host === "pi" && Object.keys(next).length === 0;
|
|
31448
31620
|
const outcome = Object.freeze(host === "pi" ? { status: "removed", file: removingFile ? "unlinked" : "replaced" } : { status: snapshot.data === undefined ? "created" : "replaced" });
|
|
31449
31621
|
if (!removingFile) {
|
|
31450
|
-
stage =
|
|
31622
|
+
stage = join22(dirname18(authPath), `.native-host-auth-write.${randomUUID18()}.tmp`);
|
|
31451
31623
|
const bytes = `${JSON.stringify(next, null, 2)}
|
|
31452
31624
|
`;
|
|
31453
31625
|
const nativeCreated = await createWindowsOwnerOnly(stage, bytes);
|
|
@@ -32987,8 +33159,8 @@ async function runNativeCustodyActivation(options, hooks = {}) {
|
|
|
32987
33159
|
}
|
|
32988
33160
|
async function commitMode(paths, routingPath, plan, context) {
|
|
32989
33161
|
let openGate = () => {};
|
|
32990
|
-
const gate = new Promise((
|
|
32991
|
-
openGate =
|
|
33162
|
+
const gate = new Promise((resolve15) => {
|
|
33163
|
+
openGate = resolve15;
|
|
32992
33164
|
});
|
|
32993
33165
|
let leases;
|
|
32994
33166
|
let scope;
|
|
@@ -34690,11 +34862,11 @@ async function refreshForRequest(runtime2, ready) {
|
|
|
34690
34862
|
break;
|
|
34691
34863
|
if (combined.aborted)
|
|
34692
34864
|
break;
|
|
34693
|
-
await new Promise((
|
|
34865
|
+
await new Promise((resolve15) => {
|
|
34694
34866
|
const finish = () => {
|
|
34695
34867
|
clearTimeout(pause2);
|
|
34696
34868
|
combined.removeEventListener("abort", finish);
|
|
34697
|
-
|
|
34869
|
+
resolve15();
|
|
34698
34870
|
};
|
|
34699
34871
|
const pause2 = setTimeout(finish, 25);
|
|
34700
34872
|
combined.addEventListener("abort", finish, { once: true });
|
|
@@ -34710,16 +34882,16 @@ async function refreshForRequest(runtime2, ready) {
|
|
|
34710
34882
|
function waitForRequest(pending, signal) {
|
|
34711
34883
|
if (!signal)
|
|
34712
34884
|
return pending;
|
|
34713
|
-
return new Promise((
|
|
34885
|
+
return new Promise((resolve15, reject) => {
|
|
34714
34886
|
const abort = () => reject(signal.reason);
|
|
34715
34887
|
signal.addEventListener("abort", abort, { once: true });
|
|
34716
|
-
pending.then(
|
|
34888
|
+
pending.then(resolve15, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
34717
34889
|
if (signal.aborted)
|
|
34718
34890
|
abort();
|
|
34719
34891
|
});
|
|
34720
34892
|
}
|
|
34721
34893
|
// src/native-vault-connection.ts
|
|
34722
|
-
import { dirname as dirname21, join as
|
|
34894
|
+
import { dirname as dirname21, join as join23, resolve as resolve16 } from "node:path";
|
|
34723
34895
|
// ../../node_modules/@cortexkit/common-auth/dist/opencode2/integration.js
|
|
34724
34896
|
var PLACEHOLDER_PREFIX = "common-auth-placeholder";
|
|
34725
34897
|
var PLACEHOLDER_LIFETIME_MS = 365 * 24 * 60 * 60 * 1000;
|
|
@@ -34733,7 +34905,7 @@ var MAX_RETRY_HOLD_MS = 20 * 60 * 1000;
|
|
|
34733
34905
|
import { createHash as createHash24 } from "node:crypto";
|
|
34734
34906
|
import { constants as constants4 } from "node:fs";
|
|
34735
34907
|
import { lstat as lstat16, mkdir as mkdir14, open as open12, unlink as unlink9 } from "node:fs/promises";
|
|
34736
|
-
import { dirname as dirname20, resolve as
|
|
34908
|
+
import { dirname as dirname20, resolve as resolve15 } from "node:path";
|
|
34737
34909
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
34738
34910
|
|
|
34739
34911
|
// ../../node_modules/@cortexkit/common-auth/dist/pi-slot/lock.js
|
|
@@ -35136,8 +35308,8 @@ function createPiSlot(options, onStep, hooks) {
|
|
|
35136
35308
|
if (!provider || !options.authPath || !options.stashPath || !placeholderKey || placeholderKey.startsWith("!") || placeholderKey.includes("$") || !Number.isFinite(timeout) || timeout < 0) {
|
|
35137
35309
|
throw new PiSlotError("invalid-options");
|
|
35138
35310
|
}
|
|
35139
|
-
const authPath =
|
|
35140
|
-
const stashPath =
|
|
35311
|
+
const authPath = resolve15(options.authPath);
|
|
35312
|
+
const stashPath = resolve15(options.stashPath);
|
|
35141
35313
|
if (authPath === stashPath || stashPath === `${authPath}.lock`) {
|
|
35142
35314
|
throw new PiSlotError("invalid-options");
|
|
35143
35315
|
}
|
|
@@ -35275,8 +35447,8 @@ function createPiSlot(options, onStep, hooks) {
|
|
|
35275
35447
|
// src/native-vault-connection.ts
|
|
35276
35448
|
function nativePiAuthSlotPaths(options) {
|
|
35277
35449
|
return {
|
|
35278
|
-
authPath:
|
|
35279
|
-
stashPath:
|
|
35450
|
+
authPath: resolve16(options.authPath),
|
|
35451
|
+
stashPath: join23(dirname21(getHostClaustrumEnrollmentPaths("pi", options.env).tokenPath), "pi-auth-slot", "anthropic.json"),
|
|
35280
35452
|
provider: "anthropic",
|
|
35281
35453
|
placeholderKey: placeholderSecret("anthropic")
|
|
35282
35454
|
};
|
|
@@ -35403,7 +35575,7 @@ import { createHash as createHash25 } from "node:crypto";
|
|
|
35403
35575
|
import { realpathSync as realpathSync3 } from "node:fs";
|
|
35404
35576
|
import { mkdir as mkdir15, readdir as readdir4, rm as rm8, stat as stat11, writeFile as writeFile5 } from "node:fs/promises";
|
|
35405
35577
|
import { tmpdir as tmpdir7 } from "node:os";
|
|
35406
|
-
import { join as
|
|
35578
|
+
import { join as join24, resolve as resolve17 } from "node:path";
|
|
35407
35579
|
var CLAUDE_PRIME_COMMAND_NAME = "claude-prime";
|
|
35408
35580
|
var PRIME_TICK_MS = 60000;
|
|
35409
35581
|
var PRIME_DUE_OFFSET_MS = 60000;
|
|
@@ -35591,10 +35763,10 @@ function buildPrimeRequestBody() {
|
|
|
35591
35763
|
return JSON.parse(JSON.stringify(PRIME_REQUEST_BODY));
|
|
35592
35764
|
}
|
|
35593
35765
|
function defaultMarkerDir() {
|
|
35594
|
-
return
|
|
35766
|
+
return join24(tmpdir7(), "opencode-anthropic-auth", "prime");
|
|
35595
35767
|
}
|
|
35596
35768
|
function primeStorageFingerprint(storagePath) {
|
|
35597
|
-
const absolutePath =
|
|
35769
|
+
const absolutePath = resolve17(storagePath);
|
|
35598
35770
|
let canonicalPath2;
|
|
35599
35771
|
try {
|
|
35600
35772
|
canonicalPath2 = realpathSync3(absolutePath);
|
|
@@ -35606,19 +35778,19 @@ function primeStorageFingerprint(storagePath) {
|
|
|
35606
35778
|
return createHash25("sha256").update(canonicalPath2).digest("hex").slice(0, 12);
|
|
35607
35779
|
}
|
|
35608
35780
|
function primeMarkerNamespaceDir(markerDir, storagePath) {
|
|
35609
|
-
return
|
|
35781
|
+
return join24(markerDir, primeStorageFingerprint(storagePath));
|
|
35610
35782
|
}
|
|
35611
35783
|
function primeAccountMarkerDir(markerDir, storagePath, accountFingerprint) {
|
|
35612
35784
|
if (!/^[a-f0-9]{12,}$/i.test(accountFingerprint)) {
|
|
35613
35785
|
throw new Error("Prime account fingerprint must be a hexadecimal digest");
|
|
35614
35786
|
}
|
|
35615
|
-
return
|
|
35787
|
+
return join24(primeMarkerNamespaceDir(markerDir, storagePath), accountFingerprint.toLowerCase().slice(0, 12));
|
|
35616
35788
|
}
|
|
35617
35789
|
function primeMarkerPath(markerDir, accountId2, resetsAtEpochMs) {
|
|
35618
|
-
return
|
|
35790
|
+
return join24(markerDir, `${encodeURIComponent(accountId2)}-${resetsAtEpochMs}`);
|
|
35619
35791
|
}
|
|
35620
35792
|
function primeBootstrapMarkerPath(markerDir, accountId2) {
|
|
35621
|
-
return
|
|
35793
|
+
return join24(markerDir, `${encodeURIComponent(accountId2)}-bootstrap`);
|
|
35622
35794
|
}
|
|
35623
35795
|
function primeAccountLabel(id2, fallback) {
|
|
35624
35796
|
if (id2 === "main")
|
|
@@ -36060,7 +36232,7 @@ class PrimeManager {
|
|
|
36060
36232
|
let swept = 0;
|
|
36061
36233
|
for (const entry2 of entries) {
|
|
36062
36234
|
try {
|
|
36063
|
-
const path2 =
|
|
36235
|
+
const path2 = join24(dir, entry2);
|
|
36064
36236
|
const s = await stat11(path2);
|
|
36065
36237
|
if (s.isDirectory()) {
|
|
36066
36238
|
swept += await this.sweepMarkerDirectory(path2, now);
|
|
@@ -36095,11 +36267,11 @@ import {
|
|
|
36095
36267
|
writeFile as writeFile6
|
|
36096
36268
|
} from "node:fs/promises";
|
|
36097
36269
|
import { tmpdir as tmpdir8 } from "node:os";
|
|
36098
|
-
import { join as
|
|
36270
|
+
import { join as join25 } from "node:path";
|
|
36099
36271
|
var QUOTA_HEADER_FEED_SCHEMA_VERSION = 3;
|
|
36100
36272
|
var QUOTA_HEADER_FEED_LEASE_MS = 180000;
|
|
36101
36273
|
function getDefaultQuotaHeaderFeedDirectory() {
|
|
36102
|
-
return process.env.OPENCODE_ANTHROPIC_AUTH_QUOTA_FEED_DIR ??
|
|
36274
|
+
return process.env.OPENCODE_ANTHROPIC_AUTH_QUOTA_FEED_DIR ?? join25(tmpdir8(), "opencode-anthropic-auth", "quota-header-feed");
|
|
36103
36275
|
}
|
|
36104
36276
|
function configuredAnthropicOAuthAccountCount(input) {
|
|
36105
36277
|
const fallbackCount = input.storage?.accounts.filter(isOAuthAccount).length ?? 0;
|
|
@@ -36258,7 +36430,7 @@ class QuotaHeaderFeedRegistry {
|
|
|
36258
36430
|
constructor(options = {}) {
|
|
36259
36431
|
this.options = options;
|
|
36260
36432
|
const instanceId = options.instanceId ?? `${process.pid}-${randomUUID19()}`;
|
|
36261
|
-
this.filePath =
|
|
36433
|
+
this.filePath = join25(options.directory ?? getDefaultQuotaHeaderFeedDirectory(), `${instanceId}.json`);
|
|
36262
36434
|
}
|
|
36263
36435
|
publish(entry2) {
|
|
36264
36436
|
const { accountKey, quota: quota2 } = entry2;
|
|
@@ -36319,7 +36491,7 @@ class QuotaHeaderFeedRegistry {
|
|
|
36319
36491
|
return;
|
|
36320
36492
|
}
|
|
36321
36493
|
await Promise.all(names2.filter((name) => /^\d+-[0-9a-f-]+\.json$/i.test(name)).map(async (name) => {
|
|
36322
|
-
const path2 =
|
|
36494
|
+
const path2 = join25(directory, name);
|
|
36323
36495
|
if (path2 === this.filePath)
|
|
36324
36496
|
return;
|
|
36325
36497
|
try {
|
|
@@ -36348,7 +36520,7 @@ class QuotaHeaderFeedRegistry {
|
|
|
36348
36520
|
const newest = new Map;
|
|
36349
36521
|
await Promise.all(names2.map(async (name) => {
|
|
36350
36522
|
try {
|
|
36351
|
-
const record9 = JSON.parse(await readFile13(
|
|
36523
|
+
const record9 = JSON.parse(await readFile13(join25(directory, name), "utf8"));
|
|
36352
36524
|
if (record9.version !== QUOTA_HEADER_FEED_SCHEMA_VERSION || !record9.entries || typeof record9.entries !== "object")
|
|
36353
36525
|
return;
|
|
36354
36526
|
for (const [accountKey, candidate] of Object.entries(record9.entries)) {
|
|
@@ -36529,7 +36701,7 @@ function buildClaudeQuotaSummary(input) {
|
|
|
36529
36701
|
}
|
|
36530
36702
|
// src/request-gzip.ts
|
|
36531
36703
|
import { mkdir as mkdir17, readFile as readFile14, rename as rename15, rm as rm10, writeFile as writeFile7 } from "node:fs/promises";
|
|
36532
|
-
import { basename as basename10, dirname as dirname22, join as
|
|
36704
|
+
import { basename as basename10, dirname as dirname22, join as join26 } from "node:path";
|
|
36533
36705
|
import { promisify } from "node:util";
|
|
36534
36706
|
import { gzip } from "node:zlib";
|
|
36535
36707
|
var gzipAsync = promisify(gzip);
|
|
@@ -36675,7 +36847,7 @@ function getRequestGzipLatch(path2) {
|
|
|
36675
36847
|
function getRequestGzipLatchPath(accountStoragePath) {
|
|
36676
36848
|
const name = basename10(accountStoragePath);
|
|
36677
36849
|
const stem = name.endsWith(".json") ? name.slice(0, -5) : name;
|
|
36678
|
-
return
|
|
36850
|
+
return join26(dirname22(accountStoragePath), `${stem}-request-gzip.json`);
|
|
36679
36851
|
}
|
|
36680
36852
|
async function decideRequestGzip(options) {
|
|
36681
36853
|
if (!CLAUDE_CODE_GZIPS_REQUEST_BODIES)
|
|
@@ -36992,12 +37164,12 @@ function executeLaneStartCommand(input) {
|
|
|
36992
37164
|
// src/state-layout-decision.ts
|
|
36993
37165
|
import { mkdir as mkdir18, readdir as readdir8 } from "node:fs/promises";
|
|
36994
37166
|
import { homedir as homedir7 } from "node:os";
|
|
36995
|
-
import { basename as basename13, dirname as dirname24, join as
|
|
37167
|
+
import { basename as basename13, dirname as dirname24, join as join30 } from "node:path";
|
|
36996
37168
|
|
|
36997
37169
|
// src/layout-fence.ts
|
|
36998
37170
|
import { readdir as readdir6, readFile as readFile15 } from "node:fs/promises";
|
|
36999
37171
|
import { homedir as homedir5 } from "node:os";
|
|
37000
|
-
import { basename as basename11, join as
|
|
37172
|
+
import { basename as basename11, join as join27, resolve as resolve18 } from "node:path";
|
|
37001
37173
|
var STATE_PATH_OVERRIDE_VARIABLES = [
|
|
37002
37174
|
"OPENCODE_ANTHROPIC_AUTH_FILE",
|
|
37003
37175
|
"OPENCODE_ANTHROPIC_AUTH_STATE_FILE",
|
|
@@ -37033,7 +37205,7 @@ async function holderFenceBlockers(input) {
|
|
|
37033
37205
|
const files = new Set(input.files);
|
|
37034
37206
|
const blockers = [];
|
|
37035
37207
|
for (const dir of [...new Set(input.directories)].sort()) {
|
|
37036
|
-
const holderFile =
|
|
37208
|
+
const holderFile = join27(dir, HOLDER_FILE_NAME);
|
|
37037
37209
|
let contents;
|
|
37038
37210
|
try {
|
|
37039
37211
|
contents = await readHolderFile(holderFile);
|
|
@@ -37083,8 +37255,8 @@ function defaultPreNArtifactLocations(env = process.env, home = homedir5()) {
|
|
|
37083
37255
|
});
|
|
37084
37256
|
const rpcOverride = env.OPENCODE_ANTHROPIC_AUTH_RPC_DIR?.trim();
|
|
37085
37257
|
return {
|
|
37086
|
-
rpcRoots: [
|
|
37087
|
-
rpcDirs: rpcOverride ? [
|
|
37258
|
+
rpcRoots: [join27(root, "rpc")],
|
|
37259
|
+
rpcDirs: rpcOverride ? [resolve18(rpcOverride)] : [],
|
|
37088
37260
|
cacheKeepDirs: [
|
|
37089
37261
|
...new Set([
|
|
37090
37262
|
getDefaultCacheKeepRegistryDirectory("opencode"),
|
|
@@ -37133,12 +37305,12 @@ async function preNArtifactBlockers(locations, pidAlive2 = defaultLiveness2.pidA
|
|
|
37133
37305
|
const portDirs = [...locations.rpcDirs];
|
|
37134
37306
|
for (const root of locations.rpcRoots)
|
|
37135
37307
|
for (const name of await listDir(root, blockers))
|
|
37136
|
-
portDirs.push(
|
|
37308
|
+
portDirs.push(join27(root, name));
|
|
37137
37309
|
for (const dir of [...new Set(portDirs)]) {
|
|
37138
37310
|
for (const name of await listDir(dir, blockers)) {
|
|
37139
37311
|
if (!/^port-\d+\.json$/.test(name))
|
|
37140
37312
|
continue;
|
|
37141
|
-
const path2 =
|
|
37313
|
+
const path2 = join27(dir, name);
|
|
37142
37314
|
const value = await readArtifact(path2, blockers);
|
|
37143
37315
|
if (value === undefined || stamped(value))
|
|
37144
37316
|
continue;
|
|
@@ -37156,7 +37328,7 @@ async function preNArtifactBlockers(locations, pidAlive2 = defaultLiveness2.pidA
|
|
|
37156
37328
|
const match = /^(\d+)-.+\.json$/.exec(name);
|
|
37157
37329
|
if (!match)
|
|
37158
37330
|
continue;
|
|
37159
|
-
const path2 =
|
|
37331
|
+
const path2 = join27(dir, name);
|
|
37160
37332
|
const value = await readArtifact(path2, blockers);
|
|
37161
37333
|
if (value === undefined || stamped(value))
|
|
37162
37334
|
continue;
|
|
@@ -37185,13 +37357,13 @@ function describeFenceBlocker(blocker) {
|
|
|
37185
37357
|
// src/state-layout-move.ts
|
|
37186
37358
|
import { randomUUID as randomUUID20 } from "node:crypto";
|
|
37187
37359
|
import { lstat as lstat18, readdir as readdir7, readFile as readFile16, stat as stat13, unlink as unlink10 } from "node:fs/promises";
|
|
37188
|
-
import { basename as basename12, dirname as dirname23, join as
|
|
37360
|
+
import { basename as basename12, dirname as dirname23, join as join28, sep as sep2 } from "node:path";
|
|
37189
37361
|
var ACCOUNT_FILE = "anthropic-auth.json";
|
|
37190
37362
|
var ACCOUNT_STATE_FILE = "anthropic-auth-state.json";
|
|
37191
37363
|
var LAYOUT_LOCK_NAME = "runtime-layout";
|
|
37192
37364
|
var LAYOUT_LOCK_TIMEOUT_MS = 120000;
|
|
37193
37365
|
async function resolveLegacyDatasetFiles(configDir) {
|
|
37194
|
-
const oldPaths = await resolveNativePoolPaths(
|
|
37366
|
+
const oldPaths = await resolveNativePoolPaths(join28(configDir, ACCOUNT_FILE), join28(configDir, ACCOUNT_STATE_FILE), { kind: "legacy" });
|
|
37195
37367
|
return {
|
|
37196
37368
|
oldDir: await canonicalPath(configDir),
|
|
37197
37369
|
oldPaths,
|
|
@@ -37199,8 +37371,8 @@ async function resolveLegacyDatasetFiles(configDir) {
|
|
|
37199
37371
|
};
|
|
37200
37372
|
}
|
|
37201
37373
|
async function resolveRelocationDataset(input) {
|
|
37202
|
-
const legacyConfig =
|
|
37203
|
-
const legacyState =
|
|
37374
|
+
const legacyConfig = join28(input.configDir, ACCOUNT_FILE);
|
|
37375
|
+
const legacyState = join28(input.configDir, ACCOUNT_STATE_FILE);
|
|
37204
37376
|
const { oldDir, oldPaths, oldVault } = await resolveLegacyDatasetFiles(input.configDir);
|
|
37205
37377
|
const stateHome = { kind: "state-home", dir: input.sub };
|
|
37206
37378
|
const newPaths = await resolveNativePoolPaths(legacyConfig, legacyState, stateHome);
|
|
@@ -37229,7 +37401,7 @@ async function resolveRelocationDataset(input) {
|
|
|
37229
37401
|
role,
|
|
37230
37402
|
from: pairs[role][0],
|
|
37231
37403
|
to: pairs[role][1],
|
|
37232
|
-
configured:
|
|
37404
|
+
configured: join28(input.configDir, STATE_HOME_FILE_NAMES[role])
|
|
37233
37405
|
})),
|
|
37234
37406
|
storageIds: { local: oldPaths.storageId, vault: oldVault.storageId }
|
|
37235
37407
|
};
|
|
@@ -37251,8 +37423,8 @@ function errorCode6(error) {
|
|
|
37251
37423
|
}
|
|
37252
37424
|
function transitionHolderFiles(dataset) {
|
|
37253
37425
|
return [
|
|
37254
|
-
|
|
37255
|
-
|
|
37426
|
+
join28(dataset.oldDir, HOLDER_FILE_NAME),
|
|
37427
|
+
join28(dataset.sub, HOLDER_FILE_NAME)
|
|
37256
37428
|
].sort();
|
|
37257
37429
|
}
|
|
37258
37430
|
async function acquireHolderLock(ctx, holderFile, timeoutMs) {
|
|
@@ -37269,7 +37441,7 @@ async function acquireHolderLock(ctx, holderFile, timeoutMs) {
|
|
|
37269
37441
|
}
|
|
37270
37442
|
}
|
|
37271
37443
|
async function acquireHolderLocks(dataset, ctx) {
|
|
37272
|
-
const oldHolders =
|
|
37444
|
+
const oldHolders = join28(dataset.oldDir, HOLDER_FILE_NAME);
|
|
37273
37445
|
for (const file of transitionHolderFiles(dataset)) {
|
|
37274
37446
|
if (file === oldHolders)
|
|
37275
37447
|
await stateLayoutStep(ctx, "old-holders-locking");
|
|
@@ -37685,7 +37857,7 @@ async function rollbackPreparing(record9, dataset, ctx) {
|
|
|
37685
37857
|
}
|
|
37686
37858
|
for (const name of await readdir7(dataset.sub))
|
|
37687
37859
|
if (isLayoutRecordStage(name, attempt))
|
|
37688
|
-
await removeOwnStaging(
|
|
37860
|
+
await removeOwnStaging(join28(dataset.sub, name));
|
|
37689
37861
|
await stateLayoutStep(ctx, "rollback:destination-removed");
|
|
37690
37862
|
await ctx.fs.syncDirectory(dataset.sub);
|
|
37691
37863
|
await stateLayoutStep(ctx, "rollback:sub-flushed");
|
|
@@ -37799,7 +37971,7 @@ async function moveDataset(dataset, ctx, checkArtifacts) {
|
|
|
37799
37971
|
});
|
|
37800
37972
|
const sha = (role) => files.find((file) => file.role === role)?.sha256 ?? null;
|
|
37801
37973
|
await ctx.stack.assertAll();
|
|
37802
|
-
const configDirPath =
|
|
37974
|
+
const configDirPath = join28(dataset.sub, STATE_HOME_FILE_NAMES.configDirMarker);
|
|
37803
37975
|
if (!await exists3(configDirPath)) {
|
|
37804
37976
|
const stage = `${configDirPath}.${attempt}.tmp`;
|
|
37805
37977
|
await createOwnerOnlyFile(ctx.fs, stage, Buffer.from(`${JSON.stringify({ version: 1, identity: dataset.identity })}
|
|
@@ -37810,7 +37982,7 @@ async function moveDataset(dataset, ctx, checkArtifacts) {
|
|
|
37810
37982
|
await removeOwnStaging(stage);
|
|
37811
37983
|
}
|
|
37812
37984
|
}
|
|
37813
|
-
const holderFile =
|
|
37985
|
+
const holderFile = join28(dataset.sub, HOLDER_FILE_NAME);
|
|
37814
37986
|
if (!await exists3(holderFile))
|
|
37815
37987
|
await writeJsonAtomic(holderFile, { version: 1, entries: [] }, {
|
|
37816
37988
|
beforeRename: () => ctx.stack.assertAll(),
|
|
@@ -37964,7 +38136,7 @@ async function rollbackAfterFailure(preparing, dataset, ctx) {
|
|
|
37964
38136
|
import { randomUUID as randomUUID21 } from "node:crypto";
|
|
37965
38137
|
import { readFile as readFile17 } from "node:fs/promises";
|
|
37966
38138
|
import { homedir as homedir6 } from "node:os";
|
|
37967
|
-
import { join as
|
|
38139
|
+
import { join as join29 } from "node:path";
|
|
37968
38140
|
var DATA_ROLES = [
|
|
37969
38141
|
"localPoolState",
|
|
37970
38142
|
"localRoster",
|
|
@@ -38240,7 +38412,7 @@ async function newRestoreProblems(record9, dataset, options) {
|
|
|
38240
38412
|
if (await exists3(path2))
|
|
38241
38413
|
problems.push(`${path2} changed after the move and was kept; move it aside or delete it`);
|
|
38242
38414
|
}
|
|
38243
|
-
problems.push(...await holderProblems(
|
|
38415
|
+
problems.push(...await holderProblems(join29(dataset.sub, HOLDER_FILE_NAME), options.liveness, true), ...await holderProblems(join29(dataset.oldDir, HOLDER_FILE_NAME), options.liveness, false));
|
|
38244
38416
|
const artifacts = options.artifacts ?? defaultPreNArtifactLocations(options.env ?? process.env, options.home ?? homedir6());
|
|
38245
38417
|
for (const blocker of await preNArtifactBlockers(artifacts, options.liveness?.pidAlive))
|
|
38246
38418
|
problems.push(`${describeFenceBlocker(blocker)} is still running`);
|
|
@@ -38429,7 +38601,7 @@ async function restoreLegacyLayout(options = {}) {
|
|
|
38429
38601
|
break;
|
|
38430
38602
|
case "restore-staged": {
|
|
38431
38603
|
await syncObservedRestoreRecord(dataset, ctx);
|
|
38432
|
-
const problems = await holderProblems(
|
|
38604
|
+
const problems = await holderProblems(join29(dataset.sub, HOLDER_FILE_NAME), options.liveness, true);
|
|
38433
38605
|
if (problems.length)
|
|
38434
38606
|
throw refused2(`anthropic-auth can't finish restoring its state to ${dataset.oldDir}: ${problems.join("; ")}. Close them, then run ${RESTORE_LEGACY_COMMAND} again.`, [dataset.sub]);
|
|
38435
38607
|
result = await finishStagedRestore(record9, dataset, ctx);
|
|
@@ -38544,7 +38716,7 @@ function deferLegacyRegistration(paths, dir, options, error) {
|
|
|
38544
38716
|
}
|
|
38545
38717
|
async function registerLegacyHeld(oldDir, paths, identity3, options, ctx) {
|
|
38546
38718
|
try {
|
|
38547
|
-
await registerHeld(
|
|
38719
|
+
await registerHeld(join30(oldDir, HOLDER_FILE_NAME), paths, "legacy", identity3, options, ctx);
|
|
38548
38720
|
return;
|
|
38549
38721
|
} catch (error) {
|
|
38550
38722
|
if (unmovedRegistrationPolicy(options) === "mandatory")
|
|
@@ -38577,14 +38749,14 @@ async function admitHeld(dataset, options, ctx, moved, allowPendingCleanup) {
|
|
|
38577
38749
|
throw conflict;
|
|
38578
38750
|
}
|
|
38579
38751
|
await warnReappearedMetadata(record9);
|
|
38580
|
-
await registerHeld(
|
|
38752
|
+
await registerHeld(join30(dataset.sub, HOLDER_FILE_NAME), dataset.newPaths, "state-home", dataset.identity, options, ctx);
|
|
38581
38753
|
const layout = { kind: "state-home", dir: dataset.sub };
|
|
38582
38754
|
recordProcessStateLayout(dataset.oldPaths.legacyConfig, layout);
|
|
38583
38755
|
return { kind: "state-home", layout, dataset, record: record9, moved };
|
|
38584
38756
|
}
|
|
38585
38757
|
async function admitFast(dataset, options, ctx) {
|
|
38586
38758
|
try {
|
|
38587
|
-
await acquireHolderLock(ctx,
|
|
38759
|
+
await acquireHolderLock(ctx, join30(dataset.sub, HOLDER_FILE_NAME), ctx.holderLockTimeoutMs);
|
|
38588
38760
|
} catch (error) {
|
|
38589
38761
|
if (error instanceof LockContentionError)
|
|
38590
38762
|
busy(dataset.configDir, error);
|
|
@@ -38692,7 +38864,7 @@ async function legacyWhileMoveOff(configDir, identity3, options, ctx, stayReason
|
|
|
38692
38864
|
await stateLayoutStep(ctx, "old-holders-locking");
|
|
38693
38865
|
let lockFailure;
|
|
38694
38866
|
try {
|
|
38695
|
-
await acquireHolderLock(ctx,
|
|
38867
|
+
await acquireHolderLock(ctx, join30(old.oldDir, HOLDER_FILE_NAME), ctx.holderLockTimeoutMs);
|
|
38696
38868
|
} catch (error) {
|
|
38697
38869
|
lockFailure = { error };
|
|
38698
38870
|
}
|
|
@@ -38722,8 +38894,8 @@ async function decideOpenCodeStateLayout(options) {
|
|
|
38722
38894
|
holderLockTimeoutMs: options.timeouts?.holderMs
|
|
38723
38895
|
});
|
|
38724
38896
|
if (isExplicit(env)) {
|
|
38725
|
-
const legacyConfig = env.OPENCODE_ANTHROPIC_AUTH_FILE?.trim() ||
|
|
38726
|
-
const legacyState = env.OPENCODE_ANTHROPIC_AUTH_STATE_FILE?.trim() || (legacyConfig.endsWith(ACCOUNT_FILE2) ?
|
|
38897
|
+
const legacyConfig = env.OPENCODE_ANTHROPIC_AUTH_FILE?.trim() || join30(configDir, ACCOUNT_FILE2);
|
|
38898
|
+
const legacyState = env.OPENCODE_ANTHROPIC_AUTH_STATE_FILE?.trim() || (legacyConfig.endsWith(ACCOUNT_FILE2) ? join30(dirname24(legacyConfig), ACCOUNT_STATE_FILE2) : `${legacyConfig}.state.json`);
|
|
38727
38899
|
const paths = await resolveNativePoolPaths(legacyConfig, legacyState, LEGACY_STATE_LAYOUT);
|
|
38728
38900
|
const registration = await registerNativePoolHolder({
|
|
38729
38901
|
paths,
|
|
@@ -38746,7 +38918,7 @@ async function decideOpenCodeStateLayout(options) {
|
|
|
38746
38918
|
} catch (error) {
|
|
38747
38919
|
if (unmovedRegistrationPolicy(options) === "mandatory")
|
|
38748
38920
|
throw new HolderRegistrationError("unavailable", configDir, error);
|
|
38749
|
-
const paths = await resolveNativePoolPaths(
|
|
38921
|
+
const paths = await resolveNativePoolPaths(join30(configDir, ACCOUNT_FILE2), join30(configDir, ACCOUNT_STATE_FILE2), LEGACY_STATE_LAYOUT);
|
|
38750
38922
|
return chooseLegacy(paths, [reason], true, deferLegacyRegistration(paths, configDir, options, error));
|
|
38751
38923
|
}
|
|
38752
38924
|
identity3 = configIdentity(configDir);
|
|
@@ -38816,7 +38988,7 @@ async function decideOpenCodeStateLayout(options) {
|
|
|
38816
38988
|
try {
|
|
38817
38989
|
await stateLayoutStep(ctx, "old-holders-locking");
|
|
38818
38990
|
try {
|
|
38819
|
-
await acquireHolderLock(ctx,
|
|
38991
|
+
await acquireHolderLock(ctx, join30(dataset.oldDir, HOLDER_FILE_NAME), ctx.holderLockTimeoutMs);
|
|
38820
38992
|
} catch (error) {
|
|
38821
38993
|
if (unmovedRegistrationPolicy(options) === "mandatory")
|
|
38822
38994
|
throw error;
|
|
@@ -39248,6 +39420,7 @@ export {
|
|
|
39248
39420
|
requireNoSupervisedAuthContentSnapshot,
|
|
39249
39421
|
requireAnthropicOAuthOrigin,
|
|
39250
39422
|
requestGzipPadding,
|
|
39423
|
+
reportRouting,
|
|
39251
39424
|
renameWithWindowsSharingRetry,
|
|
39252
39425
|
remapRequestBodyModel,
|
|
39253
39426
|
remapModelId,
|
|
@@ -39558,6 +39731,7 @@ export {
|
|
|
39558
39731
|
assertNotCustodyTombstone,
|
|
39559
39732
|
assertNoMeaningfulTrailingAssistant,
|
|
39560
39733
|
assertHostsStopped,
|
|
39734
|
+
askRouting,
|
|
39561
39735
|
applyTurnEndNotes,
|
|
39562
39736
|
applyThinkingBindingControls,
|
|
39563
39737
|
applyMidConversationOutputConfig,
|