@cortexkit/anthropic-auth-core 2.11.4 → 2.12.0
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 +1341 -767
- package/dist/internal-types/fs/canonical-file-path.d.ts +17 -0
- package/dist/internal-types/fs/index.d.ts +1 -0
- package/dist/internal-types/settings/edit.d.ts +1 -0
- package/dist/internal-types/settings/handle.d.ts +2 -1
- package/dist/internal-types/settings/index.d.ts +1 -0
- package/dist/internal-types/settings/update.d.ts +14 -0
- package/dist/native-runtime-settings.d.ts +16 -5
- package/dist/native-settings-write.d.ts +4 -16
- package/dist/settings-definition.d.ts +11 -0
- package/dist/settings-host-import.d.ts +18 -4
- package/dist/settings-mode.d.ts +22 -0
- package/dist/settings-move-run.d.ts +60 -1
- package/dist/settings-move-sources.d.ts +15 -6
- package/dist/settings-protection-copy.d.ts +7 -1
- package/dist/settings-service.d.ts +64 -37
- package/dist/settings-start.d.ts +46 -6
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1344,7 +1344,7 @@ import { ClaustrumCredentialError as ClaustrumCredentialError5 } from "@cortexki
|
|
|
1344
1344
|
import { createHash, randomBytes, randomUUID as randomUUID4 } from "node:crypto";
|
|
1345
1345
|
import { constants as fsConstants } from "node:fs";
|
|
1346
1346
|
import { chmod, mkdir as mkdir3, open as open4, readFile as readFile3, realpath, rename as rename4, stat as stat3, unlink as unlink3 } from "node:fs/promises";
|
|
1347
|
-
import { basename as
|
|
1347
|
+
import { basename as basename3, dirname as dirname6, extname, isAbsolute, join as join5, resolve as resolve8 } from "node:path";
|
|
1348
1348
|
import { ClaustrumCredentialError as ClaustrumCredentialError3, ClaustrumClient as ClaustrumWireClient, writeEnrollmentTokenFile } from "@cortexkit/claustrum-client";
|
|
1349
1349
|
|
|
1350
1350
|
// ../../node_modules/@cortexkit/common-auth/dist/fs/file-read-cache.js
|
|
@@ -1483,6 +1483,47 @@ async function syncJsonFile(path) {
|
|
|
1483
1483
|
await directory.close();
|
|
1484
1484
|
}
|
|
1485
1485
|
}
|
|
1486
|
+
// ../../node_modules/@cortexkit/common-auth/dist/fs/canonical-file-path.js
|
|
1487
|
+
import { basename, dirname as dirname4, join as join2, resolve as resolve5 } from "node:path";
|
|
1488
|
+
var maxSymlinkHops = 40;
|
|
1489
|
+
async function canonicalFilePath(file, fs) {
|
|
1490
|
+
let target = file;
|
|
1491
|
+
for (let hops = 0;; hops++) {
|
|
1492
|
+
target = join2(await fs.realpath(dirname4(target)), basename(target));
|
|
1493
|
+
let isSymlink;
|
|
1494
|
+
try {
|
|
1495
|
+
isSymlink = (await fs.lstat(target)).isSymbolicLink();
|
|
1496
|
+
} catch (error) {
|
|
1497
|
+
if (error.code === "ENOENT" && hops === 0)
|
|
1498
|
+
return target;
|
|
1499
|
+
throw error;
|
|
1500
|
+
}
|
|
1501
|
+
if (!isSymlink)
|
|
1502
|
+
return target;
|
|
1503
|
+
if (hops >= maxSymlinkHops)
|
|
1504
|
+
throw new Error("Too many file symlink hops");
|
|
1505
|
+
target = resolve5(dirname4(target), await fs.readlink(target));
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
function canonicalFilePathSync(file, fs) {
|
|
1509
|
+
let target = file;
|
|
1510
|
+
for (let hops = 0;; hops++) {
|
|
1511
|
+
target = join2(fs.realpathSync(dirname4(target)), basename(target));
|
|
1512
|
+
let isSymlink;
|
|
1513
|
+
try {
|
|
1514
|
+
isSymlink = fs.lstatSync(target).isSymbolicLink();
|
|
1515
|
+
} catch (error) {
|
|
1516
|
+
if (error.code === "ENOENT" && hops === 0)
|
|
1517
|
+
return target;
|
|
1518
|
+
throw error;
|
|
1519
|
+
}
|
|
1520
|
+
if (!isSymlink)
|
|
1521
|
+
return target;
|
|
1522
|
+
if (hops >= maxSymlinkHops)
|
|
1523
|
+
throw new Error("Too many file symlink hops");
|
|
1524
|
+
target = resolve5(dirname4(target), fs.readlinkSync(target));
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1486
1527
|
// ../../node_modules/@cortexkit/common-auth/dist/fs/lock-constants.js
|
|
1487
1528
|
var WRITER_LOCK_CONSTANTS = Object.freeze({
|
|
1488
1529
|
sidebar: Object.freeze({
|
|
@@ -1501,10 +1542,10 @@ var WRITER_LOCK_CONSTANTS = Object.freeze({
|
|
|
1501
1542
|
// ../../node_modules/@cortexkit/common-auth/dist/fs/refresh-file-lock.js
|
|
1502
1543
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
1503
1544
|
import { link, lstat as lstat3, mkdir as mkdir2, open as open3, readdir, readFile as readFile2, rename as rename3, rm as rm2, stat as stat2, unlink as unlink2 } from "node:fs/promises";
|
|
1504
|
-
import { basename, dirname as
|
|
1545
|
+
import { basename as basename2, dirname as dirname5, join as join4 } from "node:path";
|
|
1505
1546
|
|
|
1506
1547
|
// ../../node_modules/@cortexkit/common-auth/dist/fs/lock-record.js
|
|
1507
|
-
import { resolve as
|
|
1548
|
+
import { resolve as resolve6 } from "node:path";
|
|
1508
1549
|
class DisappearedLockRecordError extends Error {
|
|
1509
1550
|
path;
|
|
1510
1551
|
code = "ENOENT";
|
|
@@ -1514,10 +1555,10 @@ class DisappearedLockRecordError extends Error {
|
|
|
1514
1555
|
}
|
|
1515
1556
|
}
|
|
1516
1557
|
function isWindowsAccessDeniedRead(error, paths) {
|
|
1517
|
-
return error instanceof PrivateFileError && error.reason === "io-error" && error.win32Code === 5 && (error.stage === "read" || error.stage === "verify") && paths.some((path) =>
|
|
1558
|
+
return error instanceof PrivateFileError && error.reason === "io-error" && error.win32Code === 5 && (error.stage === "read" || error.stage === "verify") && paths.some((path) => resolve6(path) === error.path);
|
|
1518
1559
|
}
|
|
1519
1560
|
function isWindowsAccessDeniedCreate(error, paths, stage) {
|
|
1520
|
-
return error instanceof PrivateFileError && error.reason === "io-error" && error.win32Code === 5 && error.stage === stage && paths.some((path) =>
|
|
1561
|
+
return error instanceof PrivateFileError && error.reason === "io-error" && error.win32Code === 5 && error.stage === stage && paths.some((path) => resolve6(path) === error.path);
|
|
1521
1562
|
}
|
|
1522
1563
|
async function readLockRecord(path, read) {
|
|
1523
1564
|
try {
|
|
@@ -1536,7 +1577,7 @@ async function readLockRecord(path, read) {
|
|
|
1536
1577
|
}
|
|
1537
1578
|
|
|
1538
1579
|
// ../../node_modules/@cortexkit/common-auth/dist/fs/with-lock.js
|
|
1539
|
-
import { join as
|
|
1580
|
+
import { join as join3, resolve as resolve7 } from "node:path";
|
|
1540
1581
|
function lockPathFor(target, name) {
|
|
1541
1582
|
return `${target}.${name}.lock`;
|
|
1542
1583
|
}
|
|
@@ -1559,8 +1600,8 @@ class LockOwnershipError extends Error {
|
|
|
1559
1600
|
}
|
|
1560
1601
|
}
|
|
1561
1602
|
function isChangingLockRecord(error, target, name) {
|
|
1562
|
-
const path =
|
|
1563
|
-
const paths = [path,
|
|
1603
|
+
const path = resolve7(lockPathFor(target, name));
|
|
1604
|
+
const paths = [path, join3(path, "owner.json")];
|
|
1564
1605
|
return (isWindowsSharingViolation(error) || isWindowsAccessDeniedRead(error, paths)) && (error.stage === "read" || error.stage === "verify") && paths.includes(error.path) || windowsPrivateFiles && (isWindowsAccessDeniedCreate(error, [path], "create") || isWindowsAccessDeniedCreate(error, [`${path}.evicting`], "directory-create"));
|
|
1565
1606
|
}
|
|
1566
1607
|
async function withLock(target, options, fn) {
|
|
@@ -1603,7 +1644,7 @@ async function withLock(target, options, fn) {
|
|
|
1603
1644
|
timeoutMs: options.timeoutMs
|
|
1604
1645
|
});
|
|
1605
1646
|
}
|
|
1606
|
-
await new Promise((
|
|
1647
|
+
await new Promise((resolve8) => setTimeout(resolve8, Math.min(25, Math.ceil(remaining))));
|
|
1607
1648
|
}
|
|
1608
1649
|
}
|
|
1609
1650
|
|
|
@@ -1713,14 +1754,14 @@ async function readStagedOwner(path) {
|
|
|
1713
1754
|
return { identity: before, expiresAt };
|
|
1714
1755
|
}
|
|
1715
1756
|
async function sweepAbandonedStaging(lockPath, ttlMs, now) {
|
|
1716
|
-
const directory =
|
|
1717
|
-
const lockName =
|
|
1757
|
+
const directory = dirname5(lockPath);
|
|
1758
|
+
const lockName = basename2(lockPath);
|
|
1718
1759
|
const hooks = stagingSweepTestHooks;
|
|
1719
1760
|
const names = await (hooks?.readdir ?? readdir)(directory);
|
|
1720
1761
|
const candidates = names.filter((name) => isStagingName(name, lockName)).slice(0, STAGING_SWEEP_MAX_CANDIDATES);
|
|
1721
1762
|
const marginMs = Math.max(Number.isFinite(ttlMs) ? ttlMs : 0, STAGING_SWEEP_MIN_AGE_MS);
|
|
1722
1763
|
for (const name of candidates) {
|
|
1723
|
-
const path =
|
|
1764
|
+
const path = join4(directory, name);
|
|
1724
1765
|
try {
|
|
1725
1766
|
if (now() - (await lstat3(path)).mtimeMs < marginMs)
|
|
1726
1767
|
continue;
|
|
@@ -1764,7 +1805,7 @@ function acquireRefreshFileLock(options) {
|
|
|
1764
1805
|
}
|
|
1765
1806
|
async function acquireRefreshFileLockWithClock(options) {
|
|
1766
1807
|
const lockPath = lockPathFor(options.path, options.name);
|
|
1767
|
-
const legacyOwnerPath =
|
|
1808
|
+
const legacyOwnerPath = join4(lockPath, "owner.json");
|
|
1768
1809
|
const ownerId = randomUUID3();
|
|
1769
1810
|
const now = options.now ?? Date.now;
|
|
1770
1811
|
let renewTimer = null;
|
|
@@ -1772,8 +1813,8 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
1772
1813
|
let releaseConfirmed = false;
|
|
1773
1814
|
let loss;
|
|
1774
1815
|
let resolveLoss;
|
|
1775
|
-
const lostPromise = new Promise((
|
|
1776
|
-
resolveLoss =
|
|
1816
|
+
const lostPromise = new Promise((resolve8) => {
|
|
1817
|
+
resolveLoss = resolve8;
|
|
1777
1818
|
});
|
|
1778
1819
|
function notifyTimerStep(event) {
|
|
1779
1820
|
try {
|
|
@@ -1805,7 +1846,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
1805
1846
|
let terminalIOError;
|
|
1806
1847
|
let renewalInFlight = null;
|
|
1807
1848
|
const evictPath = `${lockPath}.evicting`;
|
|
1808
|
-
const evictOwnerPath =
|
|
1849
|
+
const evictOwnerPath = join4(evictPath, "owner.json");
|
|
1809
1850
|
const evictOwnerId = randomUUID3();
|
|
1810
1851
|
const EVICT_TTL = 5000;
|
|
1811
1852
|
const MAX_STEAL_ATTEMPTS = 8;
|
|
@@ -1907,7 +1948,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
1907
1948
|
}
|
|
1908
1949
|
async function tryAcquire() {
|
|
1909
1950
|
if (windowsPrivateFiles)
|
|
1910
|
-
await ensurePrivateDirectory(
|
|
1951
|
+
await ensurePrivateDirectory(dirname5(lockPath));
|
|
1911
1952
|
try {
|
|
1912
1953
|
await createLease();
|
|
1913
1954
|
return true;
|
|
@@ -1917,9 +1958,9 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
1917
1958
|
return false;
|
|
1918
1959
|
if (code === "ENOENT") {
|
|
1919
1960
|
if (windowsPrivateFiles)
|
|
1920
|
-
await ensurePrivateDirectory(
|
|
1961
|
+
await ensurePrivateDirectory(dirname5(lockPath));
|
|
1921
1962
|
else
|
|
1922
|
-
await mkdir2(
|
|
1963
|
+
await mkdir2(dirname5(lockPath), { recursive: true });
|
|
1923
1964
|
try {
|
|
1924
1965
|
await createLease();
|
|
1925
1966
|
return true;
|
|
@@ -1933,7 +1974,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
1933
1974
|
}
|
|
1934
1975
|
}
|
|
1935
1976
|
async function backoff() {
|
|
1936
|
-
await new Promise((
|
|
1977
|
+
await new Promise((resolve8) => setTimeout(resolve8, Math.floor(Math.random() * 4)));
|
|
1937
1978
|
}
|
|
1938
1979
|
async function readLockState(notifyReady = true) {
|
|
1939
1980
|
if (notifyReady && options.onStep)
|
|
@@ -2025,7 +2066,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
2025
2066
|
const remainingMs = deadline - performance.now();
|
|
2026
2067
|
if (remainingMs <= 0)
|
|
2027
2068
|
throw original;
|
|
2028
|
-
await new Promise((
|
|
2069
|
+
await new Promise((resolve8) => setTimeout(resolve8, Math.min(delayMs, remainingMs)));
|
|
2029
2070
|
if (performance.now() >= deadline)
|
|
2030
2071
|
throw original;
|
|
2031
2072
|
delayMs = Math.min(delayMs * 2, 50);
|
|
@@ -2525,7 +2566,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
2525
2566
|
const remainingMs = deadline - performance.now();
|
|
2526
2567
|
if (remainingMs <= 0)
|
|
2527
2568
|
break;
|
|
2528
|
-
await new Promise((
|
|
2569
|
+
await new Promise((resolve8) => setTimeout(resolve8, Math.min(delayMs, remainingMs)));
|
|
2529
2570
|
if (windowsPrivateFiles && performance.now() >= deadline)
|
|
2530
2571
|
break;
|
|
2531
2572
|
delayMs = Math.min(delayMs * 2, 50);
|
|
@@ -2693,9 +2734,9 @@ function connectClaustrumEnrollmentClient(options) {
|
|
|
2693
2734
|
}
|
|
2694
2735
|
function getClaustrumEnrollmentPaths(tokenPath) {
|
|
2695
2736
|
const extension = extname(tokenPath) || ".json";
|
|
2696
|
-
const stem =
|
|
2737
|
+
const stem = basename3(tokenPath, extname(tokenPath));
|
|
2697
2738
|
return {
|
|
2698
|
-
statePath:
|
|
2739
|
+
statePath: join5(dirname6(tokenPath), `${stem}-state${extension}`),
|
|
2699
2740
|
tokenPath
|
|
2700
2741
|
};
|
|
2701
2742
|
}
|
|
@@ -2703,7 +2744,7 @@ function hostEnrollmentPaths(input) {
|
|
|
2703
2744
|
const override = input.override?.trim();
|
|
2704
2745
|
if (override && !isAbsolute(override) && !input.cwd)
|
|
2705
2746
|
throw new ClaustrumConsumerError("invalid-state", "A relative Claustrum enrollment override needs a base directory");
|
|
2706
|
-
const tokenPath = override ? isAbsolute(override) ? override :
|
|
2747
|
+
const tokenPath = override ? isAbsolute(override) ? override : resolve8(input.cwd, override) : join5(input.stateDir, `${input.host}-enrollment.json`);
|
|
2707
2748
|
return getClaustrumEnrollmentPaths(tokenPath);
|
|
2708
2749
|
}
|
|
2709
2750
|
function isRecord(value) {
|
|
@@ -2809,7 +2850,7 @@ function parseSecretJson(text) {
|
|
|
2809
2850
|
async function readBoundedJson(path) {
|
|
2810
2851
|
if (windowsPrivateFiles) {
|
|
2811
2852
|
try {
|
|
2812
|
-
await ensurePrivateDirectory(
|
|
2853
|
+
await ensurePrivateDirectory(dirname6(path));
|
|
2813
2854
|
const text = await readPrivateText(path, true);
|
|
2814
2855
|
if (Buffer.byteLength(text) > ENROLLMENT_FILE_MAX_BYTES) {
|
|
2815
2856
|
throw new ClaustrumConsumerError("unsafe-file", "Claustrum enrollment file is too large");
|
|
@@ -2909,7 +2950,7 @@ async function refuseWritableAncestor(parent, options = {}) {
|
|
|
2909
2950
|
throw new ClaustrumConsumerError("unsafe-file", `Claustrum enrollment path has a writable ancestor: ${component}. Another user could replace it. Run: chmod g-w,o-w ${component}`);
|
|
2910
2951
|
}
|
|
2911
2952
|
}
|
|
2912
|
-
const next =
|
|
2953
|
+
const next = dirname6(component);
|
|
2913
2954
|
if (next === component)
|
|
2914
2955
|
return;
|
|
2915
2956
|
component = next;
|
|
@@ -2938,7 +2979,7 @@ async function ensureClaustrumPrivateDirectory(directory, options = {}, what = "
|
|
|
2938
2979
|
await chmod(directory, 448);
|
|
2939
2980
|
}
|
|
2940
2981
|
async function writeStateAtomic(path, state, ancestorOptions = {}) {
|
|
2941
|
-
const parent =
|
|
2982
|
+
const parent = dirname6(path);
|
|
2942
2983
|
await ensureClaustrumPrivateDirectory(parent, ancestorOptions);
|
|
2943
2984
|
await refuseWritableAncestor(parent, ancestorOptions);
|
|
2944
2985
|
const bytes = `${JSON.stringify(state)}
|
|
@@ -2948,7 +2989,7 @@ async function writeStateAtomic(path, state, ancestorOptions = {}) {
|
|
|
2948
2989
|
}
|
|
2949
2990
|
if (windowsPrivateFiles)
|
|
2950
2991
|
return writePrivateAtomic(path, bytes);
|
|
2951
|
-
const temporary =
|
|
2992
|
+
const temporary = join5(parent, `.${basename3(path)}.${process.pid}.${randomUUID4()}.tmp`);
|
|
2952
2993
|
let descriptor;
|
|
2953
2994
|
let created = false;
|
|
2954
2995
|
try {
|
|
@@ -3126,7 +3167,7 @@ class ClaustrumEnrollmentManager {
|
|
|
3126
3167
|
return statusFromState(blocked);
|
|
3127
3168
|
}
|
|
3128
3169
|
async reconcile() {
|
|
3129
|
-
await ensureClaustrumPrivateDirectory(
|
|
3170
|
+
await ensureClaustrumPrivateDirectory(dirname6(this.#paths.statePath), this.#ancestorOptions);
|
|
3130
3171
|
const lock = await acquireRefreshFileLock({
|
|
3131
3172
|
name: "ceremony",
|
|
3132
3173
|
path: this.#paths.statePath,
|
|
@@ -3279,8 +3320,8 @@ class ClaustrumEnrollmentManager {
|
|
|
3279
3320
|
await writeStateAtomic(this.#paths.statePath, denied, this.#ancestorOptions);
|
|
3280
3321
|
return statusFromState(denied);
|
|
3281
3322
|
}
|
|
3282
|
-
await ensureClaustrumPrivateDirectory(
|
|
3283
|
-
await refuseWritableAncestor(
|
|
3323
|
+
await ensureClaustrumPrivateDirectory(dirname6(this.#paths.tokenPath), this.#ancestorOptions);
|
|
3324
|
+
await refuseWritableAncestor(dirname6(this.#paths.tokenPath), this.#ancestorOptions);
|
|
3284
3325
|
await this.#writeTokenFile(this.#paths.tokenPath, {
|
|
3285
3326
|
token: outcome.token,
|
|
3286
3327
|
token_generation: outcome.tokenGeneration
|
|
@@ -3317,7 +3358,7 @@ class ClaustrumEnrollmentManager {
|
|
|
3317
3358
|
}
|
|
3318
3359
|
}
|
|
3319
3360
|
async function resetClaustrumEnrollmentState(paths, proposedName) {
|
|
3320
|
-
await ensureClaustrumPrivateDirectory(
|
|
3361
|
+
await ensureClaustrumPrivateDirectory(dirname6(paths.statePath));
|
|
3321
3362
|
const lock = await acquireRefreshFileLock({
|
|
3322
3363
|
name: "ceremony",
|
|
3323
3364
|
path: paths.statePath,
|
|
@@ -3355,7 +3396,7 @@ async function removeIfPresent(path) {
|
|
|
3355
3396
|
}
|
|
3356
3397
|
}
|
|
3357
3398
|
async function disconnectClaustrumEnrollment(paths, proposedName) {
|
|
3358
|
-
await ensureClaustrumPrivateDirectory(
|
|
3399
|
+
await ensureClaustrumPrivateDirectory(dirname6(paths.statePath));
|
|
3359
3400
|
const lock = await acquireRefreshFileLock({
|
|
3360
3401
|
name: "ceremony",
|
|
3361
3402
|
path: paths.statePath,
|
|
@@ -3411,10 +3452,10 @@ async function drainShutdown(pending, onTimeout) {
|
|
|
3411
3452
|
try {
|
|
3412
3453
|
await Promise.race([
|
|
3413
3454
|
drained,
|
|
3414
|
-
new Promise((
|
|
3455
|
+
new Promise((resolve9) => {
|
|
3415
3456
|
timer = setTimeout(() => {
|
|
3416
3457
|
expired = true;
|
|
3417
|
-
|
|
3458
|
+
resolve9();
|
|
3418
3459
|
}, 2000);
|
|
3419
3460
|
})
|
|
3420
3461
|
]);
|
|
@@ -4155,7 +4196,7 @@ class ClaustrumScopedCustody {
|
|
|
4155
4196
|
}
|
|
4156
4197
|
#receiptBackoff(delay, signal) {
|
|
4157
4198
|
this.#check(signal);
|
|
4158
|
-
return new Promise((
|
|
4199
|
+
return new Promise((resolve9, reject) => {
|
|
4159
4200
|
const abort = () => {
|
|
4160
4201
|
this.#clearTimeout(timer);
|
|
4161
4202
|
signal.removeEventListener("abort", abort);
|
|
@@ -4163,7 +4204,7 @@ class ClaustrumScopedCustody {
|
|
|
4163
4204
|
};
|
|
4164
4205
|
const timer = this.#setTimeout(() => {
|
|
4165
4206
|
signal.removeEventListener("abort", abort);
|
|
4166
|
-
|
|
4207
|
+
resolve9();
|
|
4167
4208
|
}, delay);
|
|
4168
4209
|
timer.unref?.();
|
|
4169
4210
|
signal.addEventListener("abort", abort, { once: true });
|
|
@@ -4386,7 +4427,7 @@ class ClaustrumScopedCustody {
|
|
|
4386
4427
|
}
|
|
4387
4428
|
|
|
4388
4429
|
// ../../node_modules/@cortexkit/common-auth/dist/claustrum/quota-writer.js
|
|
4389
|
-
import { resolve as
|
|
4430
|
+
import { resolve as resolve10 } from "node:path";
|
|
4390
4431
|
|
|
4391
4432
|
// ../../node_modules/@cortexkit/common-auth/dist/quota/commit-interval.js
|
|
4392
4433
|
var QUOTA_COMMIT_INTERVAL_MS = 30000;
|
|
@@ -4945,7 +4986,7 @@ function quotaFields(publication, witness = "") {
|
|
|
4945
4986
|
// ../../node_modules/@cortexkit/common-auth/dist/claustrum/roster.js
|
|
4946
4987
|
import { createHash as createHash2 } from "node:crypto";
|
|
4947
4988
|
import { stat as stat4 } from "node:fs/promises";
|
|
4948
|
-
import { resolve as
|
|
4989
|
+
import { resolve as resolve9 } from "node:path";
|
|
4949
4990
|
|
|
4950
4991
|
// ../../node_modules/@cortexkit/common-auth/dist/claustrum/interlock.js
|
|
4951
4992
|
function matches(entry, credentialId, accountIdentity) {
|
|
@@ -5388,16 +5429,16 @@ function applyVaultQuota(current, input) {
|
|
|
5388
5429
|
}
|
|
5389
5430
|
var pendingDiscoveries = new Map;
|
|
5390
5431
|
function forgetPendingVaultDiscovery(path) {
|
|
5391
|
-
pendingDiscoveries.delete(
|
|
5432
|
+
pendingDiscoveries.delete(resolve9(path));
|
|
5392
5433
|
}
|
|
5393
5434
|
function isVaultRosterLockRefusal(path, error) {
|
|
5394
|
-
const target =
|
|
5435
|
+
const target = resolve9(path);
|
|
5395
5436
|
if (error instanceof ClaustrumConsumerError)
|
|
5396
5437
|
return error.kind === "roster-busy";
|
|
5397
5438
|
if (error instanceof LockContentionError || error instanceof LockOwnershipError)
|
|
5398
|
-
return
|
|
5439
|
+
return resolve9(error.details.target) === target;
|
|
5399
5440
|
if (error instanceof PrivateFileError) {
|
|
5400
|
-
const failed =
|
|
5441
|
+
const failed = resolve9(error.path);
|
|
5401
5442
|
return [WRITE_LOCK.name, DISCOVERY_LEASE.name].some((name) => {
|
|
5402
5443
|
const lock = lockPathFor(target, name);
|
|
5403
5444
|
return failed === lock || failed.startsWith(`${lock}.`);
|
|
@@ -5458,7 +5499,7 @@ async function refreshVaultRoster(options) {
|
|
|
5458
5499
|
throw new ClaustrumConsumerError("roster-busy", "Claustrum account discovery is already in progress");
|
|
5459
5500
|
return persisted;
|
|
5460
5501
|
}
|
|
5461
|
-
const key =
|
|
5502
|
+
const key = resolve9(options.path);
|
|
5462
5503
|
const listedOver = options.listedOver;
|
|
5463
5504
|
let discovered;
|
|
5464
5505
|
try {
|
|
@@ -5521,7 +5562,7 @@ var writers = new Map;
|
|
|
5521
5562
|
var logger = createLogger("claustrum");
|
|
5522
5563
|
var COALESCE_MS = 100;
|
|
5523
5564
|
function writerFor(path, clock = quotaCommitTimer) {
|
|
5524
|
-
const key =
|
|
5565
|
+
const key = resolve10(path);
|
|
5525
5566
|
let writer = writers.get(key);
|
|
5526
5567
|
if (!writer) {
|
|
5527
5568
|
writer = {
|
|
@@ -5585,7 +5626,7 @@ function orderedFields(pending) {
|
|
|
5585
5626
|
return [...pending.values()].flatMap((account) => [...account.values()]).sort((a, b) => a.order - b.order);
|
|
5586
5627
|
}
|
|
5587
5628
|
function pendingVaultQuota(path, roster) {
|
|
5588
|
-
const writer = writers.get(
|
|
5629
|
+
const writer = writers.get(resolve10(path));
|
|
5589
5630
|
if (writer) {
|
|
5590
5631
|
for (const field of orderedFields(writer.pending)) {
|
|
5591
5632
|
if (field.priorReading)
|
|
@@ -5596,7 +5637,7 @@ function pendingVaultQuota(path, roster) {
|
|
|
5596
5637
|
return roster;
|
|
5597
5638
|
}
|
|
5598
5639
|
function hasPendingVaultQuota(path) {
|
|
5599
|
-
return !!writers.get(
|
|
5640
|
+
return !!writers.get(resolve10(path))?.pending.size;
|
|
5600
5641
|
}
|
|
5601
5642
|
function schedule(writer, delay) {
|
|
5602
5643
|
if (writer.running || writer.timer || !writer.pending.size || writer.abort.signal.aborted)
|
|
@@ -5661,7 +5702,7 @@ function flush(writer) {
|
|
|
5661
5702
|
return writer.running;
|
|
5662
5703
|
}
|
|
5663
5704
|
async function drainVaultQuota(path, timeoutMs = 1000) {
|
|
5664
|
-
const key =
|
|
5705
|
+
const key = resolve10(path);
|
|
5665
5706
|
const writer = writers.get(key);
|
|
5666
5707
|
if (!writer)
|
|
5667
5708
|
return;
|
|
@@ -5773,7 +5814,7 @@ class ClaustrumConsumer {
|
|
|
5773
5814
|
this.#shutdown.signal,
|
|
5774
5815
|
...signal ? [signal] : []
|
|
5775
5816
|
]);
|
|
5776
|
-
return new Promise((
|
|
5817
|
+
return new Promise((resolve11, reject) => {
|
|
5777
5818
|
const cleanup = () => {
|
|
5778
5819
|
combined.signal.removeEventListener("abort", abort);
|
|
5779
5820
|
combined.dispose();
|
|
@@ -5788,7 +5829,7 @@ class ClaustrumConsumer {
|
|
|
5788
5829
|
if (combined.signal.aborted)
|
|
5789
5830
|
reject(combined.signal.reason);
|
|
5790
5831
|
else
|
|
5791
|
-
|
|
5832
|
+
resolve11(value);
|
|
5792
5833
|
}, (error) => {
|
|
5793
5834
|
cleanup();
|
|
5794
5835
|
reject(error);
|
|
@@ -6416,7 +6457,7 @@ class ClaustrumConsumer {
|
|
|
6416
6457
|
import { createHash as createHash3 } from "node:crypto";
|
|
6417
6458
|
import { channel as channel2 } from "node:diagnostics_channel";
|
|
6418
6459
|
import { readdir as readdir2, stat as stat5 } from "node:fs/promises";
|
|
6419
|
-
import { dirname as
|
|
6460
|
+
import { dirname as dirname7, join as join6, resolve as resolve11 } from "node:path";
|
|
6420
6461
|
var sharedRosters = new Map;
|
|
6421
6462
|
var FILE_ID = /^[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
6422
6463
|
var WINDOWS_DEVICE = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\.|$)/;
|
|
@@ -6480,12 +6521,12 @@ function unreachableConnect2() {
|
|
|
6480
6521
|
return new ClaustrumUnreachableError;
|
|
6481
6522
|
}
|
|
6482
6523
|
function untilAborted(pending, signal) {
|
|
6483
|
-
return new Promise((
|
|
6524
|
+
return new Promise((resolve12, reject) => {
|
|
6484
6525
|
const abort = () => reject(signal.reason);
|
|
6485
6526
|
signal.addEventListener("abort", abort, { once: true });
|
|
6486
6527
|
pending.then((value) => {
|
|
6487
6528
|
signal.removeEventListener("abort", abort);
|
|
6488
|
-
|
|
6529
|
+
resolve12(value);
|
|
6489
6530
|
}, (error) => {
|
|
6490
6531
|
signal.removeEventListener("abort", abort);
|
|
6491
6532
|
reject(error);
|
|
@@ -6532,13 +6573,13 @@ class ClaustrumDiscoveryHub {
|
|
|
6532
6573
|
this.#options = options;
|
|
6533
6574
|
this.#logger = options.logger ?? createLogger("claustrum");
|
|
6534
6575
|
this.#warnShutdown = shutdownWarning(this.#logger, this.#shutdown.signal);
|
|
6535
|
-
this.#generationDirectory =
|
|
6576
|
+
this.#generationDirectory = join6(options.stateDir, "rosters", hostGeneration);
|
|
6536
6577
|
this.#key = rosterFingerprint(options, providers);
|
|
6537
|
-
const directory =
|
|
6578
|
+
const directory = join6(this.#generationDirectory, this.#key);
|
|
6538
6579
|
for (const provider of providers)
|
|
6539
6580
|
this.#members.set(provider, {
|
|
6540
6581
|
provider,
|
|
6541
|
-
path:
|
|
6582
|
+
path: join6(directory, `${provider}.json`),
|
|
6542
6583
|
closed: false
|
|
6543
6584
|
});
|
|
6544
6585
|
}
|
|
@@ -6613,7 +6654,7 @@ class ClaustrumDiscoveryHub {
|
|
|
6613
6654
|
};
|
|
6614
6655
|
const { consumer, hooks } = createHubMember(port, consumerOptions);
|
|
6615
6656
|
entry.hooks = hooks;
|
|
6616
|
-
const path =
|
|
6657
|
+
const path = resolve11(entry.path);
|
|
6617
6658
|
const subscribers = sharedRosters.get(path) ?? new Set;
|
|
6618
6659
|
const install = (roster) => {
|
|
6619
6660
|
if (entry.closed || this.#active !== true || !this.#current || !this.#live(this.#current) || !hooks.roster() || this.#collides(hooks, roster))
|
|
@@ -6644,7 +6685,7 @@ class ClaustrumDiscoveryHub {
|
|
|
6644
6685
|
return;
|
|
6645
6686
|
entry.seen = JSON.stringify(decodedVaultRoster(roster));
|
|
6646
6687
|
entry.hooks?.install(roster);
|
|
6647
|
-
for (const install of sharedRosters.get(
|
|
6688
|
+
for (const install of sharedRosters.get(resolve11(entry.path)) ?? []) {
|
|
6648
6689
|
if (!this.#live(generation))
|
|
6649
6690
|
return;
|
|
6650
6691
|
if (install !== entry.receiveRoster)
|
|
@@ -7080,19 +7121,19 @@ class ClaustrumDiscoveryHub {
|
|
|
7080
7121
|
}
|
|
7081
7122
|
async#ensureRosterDirectories() {
|
|
7082
7123
|
for (const directory of [
|
|
7083
|
-
|
|
7124
|
+
dirname7(this.#generationDirectory),
|
|
7084
7125
|
this.#generationDirectory,
|
|
7085
|
-
|
|
7126
|
+
join6(this.#generationDirectory, this.#key)
|
|
7086
7127
|
])
|
|
7087
7128
|
await ensureClaustrumPrivateDirectory(directory, {}, "roster directory");
|
|
7088
7129
|
}
|
|
7089
7130
|
async#seed(entry) {
|
|
7090
7131
|
const name = `${entry.provider}.json`;
|
|
7091
|
-
const candidates = [
|
|
7132
|
+
const candidates = [join6(this.#generationDirectory, name)];
|
|
7092
7133
|
try {
|
|
7093
7134
|
for (const key of await readdir2(this.#generationDirectory))
|
|
7094
7135
|
if (key !== this.#key && FINGERPRINT.test(key))
|
|
7095
|
-
candidates.push(
|
|
7136
|
+
candidates.push(join6(this.#generationDirectory, key, name));
|
|
7096
7137
|
} catch {}
|
|
7097
7138
|
let newest;
|
|
7098
7139
|
for (const path of candidates) {
|
|
@@ -7585,8 +7626,8 @@ async function askRouting(input) {
|
|
|
7585
7626
|
return;
|
|
7586
7627
|
const requested = input.deadlineMs ?? 1500;
|
|
7587
7628
|
const deadlineMs = Number.isNaN(requested) ? 1500 : Math.min(2000, Math.max(1, requested));
|
|
7588
|
-
const expired = new Promise((
|
|
7589
|
-
timer = setTimeout(() =>
|
|
7629
|
+
const expired = new Promise((resolve12) => {
|
|
7630
|
+
timer = setTimeout(() => resolve12(undefined), deadlineMs);
|
|
7590
7631
|
timer.unref();
|
|
7591
7632
|
});
|
|
7592
7633
|
const request2 = {
|
|
@@ -7923,7 +7964,7 @@ async function select(terminal, items, options) {
|
|
|
7923
7964
|
writeLine("");
|
|
7924
7965
|
renderedLines = lines;
|
|
7925
7966
|
};
|
|
7926
|
-
return new Promise((
|
|
7967
|
+
return new Promise((resolve12) => {
|
|
7927
7968
|
const wasRaw = stdin.isRaw ?? false;
|
|
7928
7969
|
const cleanup = () => {
|
|
7929
7970
|
if (cleaned)
|
|
@@ -7942,7 +7983,7 @@ async function select(terminal, items, options) {
|
|
|
7942
7983
|
};
|
|
7943
7984
|
const finish = (value) => {
|
|
7944
7985
|
cleanup();
|
|
7945
|
-
|
|
7986
|
+
resolve12(value);
|
|
7946
7987
|
};
|
|
7947
7988
|
const onSignal = () => finish(null);
|
|
7948
7989
|
const onKey = (data) => {
|
|
@@ -7982,7 +8023,7 @@ async function select(terminal, items, options) {
|
|
|
7982
8023
|
stdin.setRawMode(true);
|
|
7983
8024
|
} catch {
|
|
7984
8025
|
cleanup();
|
|
7985
|
-
|
|
8026
|
+
resolve12(null);
|
|
7986
8027
|
return;
|
|
7987
8028
|
}
|
|
7988
8029
|
stdin.resume();
|
|
@@ -8044,7 +8085,7 @@ class ByteTail {
|
|
|
8044
8085
|
}
|
|
8045
8086
|
var defaultCommandRunner = {
|
|
8046
8087
|
run(file, args, options = {}) {
|
|
8047
|
-
return new Promise((
|
|
8088
|
+
return new Promise((resolve12) => {
|
|
8048
8089
|
const started = performance.now();
|
|
8049
8090
|
const timeoutMs = options.timeoutMs ?? 15000;
|
|
8050
8091
|
const stderr = new ByteTail;
|
|
@@ -8062,7 +8103,7 @@ var defaultCommandRunner = {
|
|
|
8062
8103
|
stdio: ["ignore", "pipe", "pipe"]
|
|
8063
8104
|
});
|
|
8064
8105
|
} catch {
|
|
8065
|
-
|
|
8106
|
+
resolve12({
|
|
8066
8107
|
exitCode: 1,
|
|
8067
8108
|
stdout: "",
|
|
8068
8109
|
stderr: "",
|
|
@@ -8097,7 +8138,7 @@ var defaultCommandRunner = {
|
|
|
8097
8138
|
settled = true;
|
|
8098
8139
|
if (timer)
|
|
8099
8140
|
clearTimeout(timer);
|
|
8100
|
-
|
|
8141
|
+
resolve12({
|
|
8101
8142
|
exitCode: spawnError ? 1 : outputExceeded ? 1 : code ?? 1,
|
|
8102
8143
|
stdout: Buffer.concat(stdout, stdoutLength).toString("utf8"),
|
|
8103
8144
|
stderr: stderr.toString(),
|
|
@@ -8264,7 +8305,7 @@ function setupEnrollment(error) {
|
|
|
8264
8305
|
import { accessSync, constants, existsSync as existsSync2, readFileSync, realpathSync, statSync as statSync2 } from "node:fs";
|
|
8265
8306
|
import { mkdtemp, rm as rm3 } from "node:fs/promises";
|
|
8266
8307
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
8267
|
-
import { join as
|
|
8308
|
+
import { join as join7 } from "node:path";
|
|
8268
8309
|
import { parse } from "jsonc-parser";
|
|
8269
8310
|
|
|
8270
8311
|
// ../../node_modules/@cortexkit/common-auth/dist/setup/paths.js
|
|
@@ -8433,7 +8474,7 @@ async function detectHosts(plugin, io = {}) {
|
|
|
8433
8474
|
return null;
|
|
8434
8475
|
let root;
|
|
8435
8476
|
try {
|
|
8436
|
-
root = await mkdtemp(
|
|
8477
|
+
root = await mkdtemp(join7(tmpdir2(), "common-auth-setup-version-"));
|
|
8437
8478
|
const probeEnv = {
|
|
8438
8479
|
...env,
|
|
8439
8480
|
HOME: root,
|
|
@@ -9045,11 +9086,11 @@ import { applyEdits, createScanner, findNodeAtLocation, modify, parse as parse2,
|
|
|
9045
9086
|
// ../../node_modules/@cortexkit/common-auth/dist/setup/config-write.js
|
|
9046
9087
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
9047
9088
|
import { mkdir as mkdir4, open as open5, rename as rename5, stat as stat7, unlink as unlink4 } from "node:fs/promises";
|
|
9048
|
-
import { basename as
|
|
9089
|
+
import { basename as basename4, dirname as dirname8, join as join8 } from "node:path";
|
|
9049
9090
|
import { setTimeout as delay2 } from "node:timers/promises";
|
|
9050
9091
|
async function writeHostConfigAtomic(file, content, options = {}) {
|
|
9051
9092
|
const windows = (options.platform ?? process.platform) === "win32";
|
|
9052
|
-
const parent =
|
|
9093
|
+
const parent = dirname8(file);
|
|
9053
9094
|
await mkdir4(parent, { recursive: true });
|
|
9054
9095
|
let mode;
|
|
9055
9096
|
if (!windows) {
|
|
@@ -9060,7 +9101,7 @@ async function writeHostConfigAtomic(file, content, options = {}) {
|
|
|
9060
9101
|
throw error;
|
|
9061
9102
|
}
|
|
9062
9103
|
}
|
|
9063
|
-
const stage =
|
|
9104
|
+
const stage = join8(parent, `.${basename4(file)}.${(options.stageName ?? randomUUID5)()}.tmp`);
|
|
9064
9105
|
let created = false;
|
|
9065
9106
|
try {
|
|
9066
9107
|
const handle = await open5(stage, "wx", mode ?? 438);
|
|
@@ -9500,7 +9541,7 @@ import { join as join13 } from "node:path";
|
|
|
9500
9541
|
import { readdirSync, statSync as statSync3 } from "node:fs";
|
|
9501
9542
|
import * as fs from "node:fs/promises";
|
|
9502
9543
|
import { tmpdir as tmpdir3, userInfo } from "node:os";
|
|
9503
|
-
import { join as
|
|
9544
|
+
import { join as join9 } from "node:path";
|
|
9504
9545
|
function errorCode(error) {
|
|
9505
9546
|
return error && typeof error === "object" && "code" in error && typeof error.code === "string" ? error.code : "unknown";
|
|
9506
9547
|
}
|
|
@@ -9528,7 +9569,7 @@ function listSubcTempConnectionFiles(dir) {
|
|
|
9528
9569
|
if (!name.startsWith(CLAUSTRUM_TEMP_PREFIX) || !name.endsWith(CLAUSTRUM_TEMP_SUFFIX)) {
|
|
9529
9570
|
continue;
|
|
9530
9571
|
}
|
|
9531
|
-
const candidate =
|
|
9572
|
+
const candidate = join9(dir, name);
|
|
9532
9573
|
if (safeIsFile(candidate))
|
|
9533
9574
|
matches2.push(candidate);
|
|
9534
9575
|
}
|
|
@@ -9538,13 +9579,13 @@ function listSubcTempConnectionFiles(dir) {
|
|
|
9538
9579
|
function findExistingClaustrumConnectionPath(env = process.env) {
|
|
9539
9580
|
const runtime = env.XDG_RUNTIME_DIR?.trim();
|
|
9540
9581
|
if (runtime) {
|
|
9541
|
-
const candidate =
|
|
9582
|
+
const candidate = join9(runtime, PRODUCTION_CLAUSTRUM_CONNECTION_FILE_NAME);
|
|
9542
9583
|
if (safeIsFile(candidate))
|
|
9543
9584
|
return candidate;
|
|
9544
9585
|
}
|
|
9545
9586
|
const home = env.HOME?.trim();
|
|
9546
9587
|
if (home) {
|
|
9547
|
-
const candidate =
|
|
9588
|
+
const candidate = join9(home, ".local", "share", "cortexkit", "run", PRODUCTION_CLAUSTRUM_CONNECTION_FILE_NAME);
|
|
9548
9589
|
if (safeIsFile(candidate))
|
|
9549
9590
|
return candidate;
|
|
9550
9591
|
}
|
|
@@ -9563,11 +9604,11 @@ function getDefaultClaustrumConnectionPath(env = process.env) {
|
|
|
9563
9604
|
return existing;
|
|
9564
9605
|
const runtime = env.XDG_RUNTIME_DIR?.trim();
|
|
9565
9606
|
if (runtime && (process.platform !== "darwin" || safeIsFile(runtime))) {
|
|
9566
|
-
return
|
|
9607
|
+
return join9(runtime, PRODUCTION_CLAUSTRUM_CONNECTION_FILE_NAME);
|
|
9567
9608
|
}
|
|
9568
9609
|
if (process.platform === "darwin") {
|
|
9569
9610
|
const home = env.HOME?.trim() || userInfo().homedir;
|
|
9570
|
-
return
|
|
9611
|
+
return join9(home, ".local", "share", "cortexkit", "run", PRODUCTION_CLAUSTRUM_CONNECTION_FILE_NAME);
|
|
9571
9612
|
}
|
|
9572
9613
|
const uid = process.getuid?.() ?? userInfo().uid;
|
|
9573
9614
|
return `/run/user/${uid}/${PRODUCTION_CLAUSTRUM_CONNECTION_FILE_NAME}`;
|
|
@@ -10178,7 +10219,7 @@ function raceWithSignal(signal, operation) {
|
|
|
10178
10219
|
return operation();
|
|
10179
10220
|
if (signal.aborted)
|
|
10180
10221
|
return Promise.reject(signal.reason);
|
|
10181
|
-
return new Promise((
|
|
10222
|
+
return new Promise((resolve12, reject) => {
|
|
10182
10223
|
const aborted = () => reject(signal.reason);
|
|
10183
10224
|
signal.addEventListener("abort", aborted, { once: true });
|
|
10184
10225
|
const finish = () => signal.removeEventListener("abort", aborted);
|
|
@@ -10190,7 +10231,7 @@ function raceWithSignal(signal, operation) {
|
|
|
10190
10231
|
if (signal.aborted)
|
|
10191
10232
|
reject(signal.reason);
|
|
10192
10233
|
else
|
|
10193
|
-
|
|
10234
|
+
resolve12(value);
|
|
10194
10235
|
}, (error) => {
|
|
10195
10236
|
finish();
|
|
10196
10237
|
reject(signal.aborted ? signal.reason : error);
|
|
@@ -10279,7 +10320,7 @@ async function refreshClaudeOAuthToken(input) {
|
|
|
10279
10320
|
try {
|
|
10280
10321
|
if (attempt > 0) {
|
|
10281
10322
|
const delay3 = baseDelayMs * 2 ** (attempt - 1);
|
|
10282
|
-
await new Promise((
|
|
10323
|
+
await new Promise((resolve12) => setTimeoutImpl(resolve12, delay3));
|
|
10283
10324
|
}
|
|
10284
10325
|
const signal = auxiliaryRequestSignal();
|
|
10285
10326
|
const response = await raceWithSignal(signal, () => fetchImpl(TOKEN_URL, {
|
|
@@ -10560,22 +10601,24 @@ function isOverrideKeyAllowed(overrides, key) {
|
|
|
10560
10601
|
return overrides.model === true;
|
|
10561
10602
|
}
|
|
10562
10603
|
// ../../node_modules/@cortexkit/common-auth/dist/settings/handle.js
|
|
10563
|
-
import { join as join11, resolve as
|
|
10604
|
+
import { join as join11, resolve as resolve13 } from "node:path";
|
|
10564
10605
|
|
|
10565
10606
|
// ../../node_modules/@cortexkit/common-auth/dist/tui-prefs/watcher.js
|
|
10566
|
-
import { readFileSync as readFileSync2, realpathSync as realpathSync2, statSync as statSync4, watch } from "node:fs";
|
|
10607
|
+
import { lstatSync, readFileSync as readFileSync2, readlinkSync, realpathSync as realpathSync2, statSync as statSync4, watch } from "node:fs";
|
|
10567
10608
|
import { readFile as readFile5, stat as stat8 } from "node:fs/promises";
|
|
10568
|
-
import { basename as
|
|
10609
|
+
import { basename as basename5, dirname as dirname9, join as join10, resolve as resolve12 } from "node:path";
|
|
10569
10610
|
import { clearTimeout as clearTimeout2, setTimeout as setTimeout2 } from "node:timers";
|
|
10611
|
+
var pathFsDefaults = { lstatSync, readlinkSync, realpathSync: realpathSync2 };
|
|
10612
|
+
var pathFs = { ...pathFsDefaults };
|
|
10570
10613
|
function canonicalPath(file) {
|
|
10571
|
-
const path =
|
|
10614
|
+
const path = resolve12(file);
|
|
10572
10615
|
if (windowsPrivateFiles)
|
|
10573
10616
|
return path;
|
|
10574
10617
|
try {
|
|
10575
|
-
return
|
|
10618
|
+
return canonicalFilePathSync(path, pathFs);
|
|
10576
10619
|
} catch {
|
|
10577
|
-
const parent =
|
|
10578
|
-
return parent === path ? path :
|
|
10620
|
+
const parent = dirname9(path);
|
|
10621
|
+
return parent === path ? path : join10(canonicalPath(parent), basename5(path));
|
|
10579
10622
|
}
|
|
10580
10623
|
}
|
|
10581
10624
|
function identity2(info, settings) {
|
|
@@ -10592,11 +10635,11 @@ function watchFile(file, onChange, options, settings) {
|
|
|
10592
10635
|
const key = Symbol.for(settings ? "cortexkit.common-auth.settings.watchers.v1" : "cortexkit.common-auth.tui-prefs.watchers.v1");
|
|
10593
10636
|
const registry = globals[key] ?? new Map;
|
|
10594
10637
|
globals[key] = registry;
|
|
10595
|
-
const path = settings ?
|
|
10638
|
+
const path = settings ? resolve12(file) : canonicalPath(file);
|
|
10596
10639
|
const shared = registry.get(path);
|
|
10597
10640
|
if (shared)
|
|
10598
10641
|
return shared.subscribe(onChange);
|
|
10599
|
-
const name =
|
|
10642
|
+
const name = basename5(path);
|
|
10600
10643
|
const read = windowsPrivateFiles && !settings ? (file2) => readPrivateText(file2) : options.fs?.readFile ?? ((file2) => readFile5(file2, "utf8"));
|
|
10601
10644
|
const probe = options.fs?.stat ?? stat8;
|
|
10602
10645
|
let timer = null;
|
|
@@ -10672,7 +10715,7 @@ function watchFile(file, onChange, options, settings) {
|
|
|
10672
10715
|
};
|
|
10673
10716
|
let watcher = null;
|
|
10674
10717
|
try {
|
|
10675
|
-
watcher = (options.watchDirectory ?? watch)(
|
|
10718
|
+
watcher = (options.watchDirectory ?? watch)(dirname9(path), (_event, filename) => {
|
|
10676
10719
|
const eventName = filename?.toString();
|
|
10677
10720
|
const isOurs = eventName === name || eventName?.startsWith(`${name}.`) && eventName.endsWith(".tmp");
|
|
10678
10721
|
if (eventName != null && !isOurs)
|
|
@@ -10724,6 +10767,7 @@ var defaults = {
|
|
|
10724
10767
|
readFile: fs2.readFile,
|
|
10725
10768
|
stat: fs2.stat,
|
|
10726
10769
|
lstat: fs2.lstat,
|
|
10770
|
+
readlink: fs2.readlink,
|
|
10727
10771
|
realpath: fs2.realpath,
|
|
10728
10772
|
open: fs2.open,
|
|
10729
10773
|
rename: fs2.rename,
|
|
@@ -10977,7 +11021,7 @@ function buildSettingsSnapshot(definition, file, parsed) {
|
|
|
10977
11021
|
}
|
|
10978
11022
|
|
|
10979
11023
|
// ../../node_modules/@cortexkit/common-auth/dist/settings/update.js
|
|
10980
|
-
import {
|
|
11024
|
+
import { dirname as dirname10 } from "node:path";
|
|
10981
11025
|
|
|
10982
11026
|
// ../../node_modules/@cortexkit/common-auth/dist/settings/edit.js
|
|
10983
11027
|
import { isDeepStrictEqual } from "node:util";
|
|
@@ -11032,7 +11076,10 @@ function descriptorAtPath(descriptor, path) {
|
|
|
11032
11076
|
}
|
|
11033
11077
|
return current;
|
|
11034
11078
|
}
|
|
11035
|
-
function destination(declaration, setting, value, { host, model }) {
|
|
11079
|
+
function destination(declaration, setting, value, { host, model }, level) {
|
|
11080
|
+
if (level !== undefined) {
|
|
11081
|
+
return level === "default" && !isJsonObject(value) ? [setting] : [setting, level];
|
|
11082
|
+
}
|
|
11036
11083
|
if (declaration.overrides !== undefined && isJsonObject(value)) {
|
|
11037
11084
|
if (declaration.overrides.model && model !== undefined && model !== "default" && model !== "opencode" && model !== "pi" && Object.hasOwn(value, model)) {
|
|
11038
11085
|
return [setting, model];
|
|
@@ -11062,6 +11109,19 @@ function checkPath(parsed, path) {
|
|
|
11062
11109
|
invalid2();
|
|
11063
11110
|
}
|
|
11064
11111
|
}
|
|
11112
|
+
function preservePlainDefault(parsed, setting) {
|
|
11113
|
+
const node = parsed.tree && findNodeAtLocation2(parsed.tree, [setting]);
|
|
11114
|
+
if (!node)
|
|
11115
|
+
invalid2();
|
|
11116
|
+
const value = parsed.text.slice(node.offset, node.offset + node.length);
|
|
11117
|
+
return parseForEdit(applyEdits2(parsed.text, [
|
|
11118
|
+
{
|
|
11119
|
+
offset: node.offset,
|
|
11120
|
+
length: node.length,
|
|
11121
|
+
content: `{ "default": ${value} }`
|
|
11122
|
+
}
|
|
11123
|
+
]));
|
|
11124
|
+
}
|
|
11065
11125
|
function removeMember(text, tree, path) {
|
|
11066
11126
|
const property = tree && findNodeAtLocation2(tree, path)?.parent;
|
|
11067
11127
|
const parent = property?.parent;
|
|
@@ -11136,6 +11196,16 @@ function applySettingsEdits(definition, source, edits, context) {
|
|
|
11136
11196
|
if (!Object.hasOwn(definition.settings, edit.setting))
|
|
11137
11197
|
invalid2();
|
|
11138
11198
|
const declaration = definition.settings[edit.setting];
|
|
11199
|
+
if (edit.level !== undefined) {
|
|
11200
|
+
if (edit.path !== undefined)
|
|
11201
|
+
invalid2();
|
|
11202
|
+
if (edit.level === "default") {
|
|
11203
|
+
if (declaration.overrides === undefined)
|
|
11204
|
+
invalid2();
|
|
11205
|
+
} else if (edit.level !== "opencode" && edit.level !== "pi" || !declaration.overrides?.host) {
|
|
11206
|
+
invalid2();
|
|
11207
|
+
}
|
|
11208
|
+
}
|
|
11139
11209
|
if (edit.path !== undefined && declaration.value.kind !== "object" && declaration.value.kind !== "record")
|
|
11140
11210
|
invalid2();
|
|
11141
11211
|
const descriptor = descriptorAtPath(declaration.value, edit.path ?? []);
|
|
@@ -11147,7 +11217,19 @@ function applySettingsEdits(definition, source, edits, context) {
|
|
|
11147
11217
|
const units = [];
|
|
11148
11218
|
for (const edit of edits) {
|
|
11149
11219
|
const declaration = definition.settings[edit.setting];
|
|
11150
|
-
|
|
11220
|
+
if (edit.level !== undefined && edit.level !== "default" && !isJsonObject(working.value[edit.setting])) {
|
|
11221
|
+
if (edit.remove === true)
|
|
11222
|
+
continue;
|
|
11223
|
+
if (Object.hasOwn(working.value, edit.setting)) {
|
|
11224
|
+
working = preservePlainDefault(working, edit.setting);
|
|
11225
|
+
}
|
|
11226
|
+
for (const unit of units) {
|
|
11227
|
+
if (unit.path.length === 1 && unit.path[0] === edit.setting) {
|
|
11228
|
+
unit.path.push("default");
|
|
11229
|
+
}
|
|
11230
|
+
}
|
|
11231
|
+
}
|
|
11232
|
+
const base = edit.path !== undefined ? [edit.setting] : destination(declaration, edit.setting, working.value[edit.setting], context, edit.level);
|
|
11151
11233
|
const path = [...base, ...edit.path ?? []];
|
|
11152
11234
|
checkPath(working, path);
|
|
11153
11235
|
units.push(resolutionUnit(declaration.value, base, edit.path ?? []));
|
|
@@ -11293,21 +11375,8 @@ function unavailable(file, cause) {
|
|
|
11293
11375
|
}
|
|
11294
11376
|
async function writeTarget(file) {
|
|
11295
11377
|
try {
|
|
11296
|
-
return await
|
|
11378
|
+
return await canonicalFilePath(file, SettingsFs);
|
|
11297
11379
|
} catch (error) {
|
|
11298
|
-
if (error.code !== "ENOENT")
|
|
11299
|
-
unavailable(file, error);
|
|
11300
|
-
try {
|
|
11301
|
-
await SettingsFs.lstat(file);
|
|
11302
|
-
} catch (lstatError) {
|
|
11303
|
-
if (lstatError.code !== "ENOENT")
|
|
11304
|
-
unavailable(file, lstatError);
|
|
11305
|
-
try {
|
|
11306
|
-
return join10(await SettingsFs.realpath(dirname9(file)), basename5(file));
|
|
11307
|
-
} catch (parentError) {
|
|
11308
|
-
unavailable(file, parentError);
|
|
11309
|
-
}
|
|
11310
|
-
}
|
|
11311
11380
|
unavailable(file, error);
|
|
11312
11381
|
}
|
|
11313
11382
|
}
|
|
@@ -11315,7 +11384,7 @@ async function updateSettings(definition, options, edits, context) {
|
|
|
11315
11384
|
if (options.separateInstall) {
|
|
11316
11385
|
throw new SettingsRefusal("settings-unavailable", "Settings are unavailable for a separate install");
|
|
11317
11386
|
}
|
|
11318
|
-
const folder =
|
|
11387
|
+
const folder = dirname10(options.file);
|
|
11319
11388
|
try {
|
|
11320
11389
|
if (!options.createMissing)
|
|
11321
11390
|
await SettingsFs.stat(folder);
|
|
@@ -11363,6 +11432,16 @@ async function updateSettings(definition, options, edits, context) {
|
|
|
11363
11432
|
if (Number.isInteger(version) && version > 1) {
|
|
11364
11433
|
throw new SettingsRefusal("settings-newer-version", "Settings were written by a newer version");
|
|
11365
11434
|
}
|
|
11435
|
+
if (typeof edits === "function") {
|
|
11436
|
+
const planned = edits(deepFreeze(missing ? { status: "missing" } : {
|
|
11437
|
+
status: "ready",
|
|
11438
|
+
document: structuredClone(parsed.value)
|
|
11439
|
+
}));
|
|
11440
|
+
if (planned !== null && (typeof planned === "object" || typeof planned === "function") && "then" in planned && typeof planned.then === "function") {
|
|
11441
|
+
throw new SettingsRefusal("settings-invalid-value", "Settings update plans must be synchronous");
|
|
11442
|
+
}
|
|
11443
|
+
edits = planned;
|
|
11444
|
+
}
|
|
11366
11445
|
if (!parsed.tree) {
|
|
11367
11446
|
source = `${parsed.hasBom ? "\uFEFF" : ""}// ${definition.plugin} settings
|
|
11368
11447
|
{
|
|
@@ -11412,7 +11491,7 @@ function reportedEntries() {
|
|
|
11412
11491
|
}
|
|
11413
11492
|
function openSettings(definition, options) {
|
|
11414
11493
|
options = { createMissing: false, lockTimeoutMs: 2000, ...options };
|
|
11415
|
-
const userPath =
|
|
11494
|
+
const userPath = resolve13(options.file);
|
|
11416
11495
|
const cacheOptions = {
|
|
11417
11496
|
followSymlinks: true,
|
|
11418
11497
|
stat: (path) => SettingsFs.stat(path),
|
|
@@ -11426,7 +11505,7 @@ function openSettings(definition, options) {
|
|
|
11426
11505
|
const projectSequences = new Map;
|
|
11427
11506
|
let sequence = 0;
|
|
11428
11507
|
const committedSequences = new Map;
|
|
11429
|
-
const projectPath = (project) =>
|
|
11508
|
+
const projectPath = (project) => resolve13(join11(project, ".cortexkit", `${definition.plugin}.jsonc`));
|
|
11430
11509
|
const windows = process.platform === "win32";
|
|
11431
11510
|
const windowsSeen = new Map;
|
|
11432
11511
|
const unreadFile = {
|
|
@@ -11539,7 +11618,7 @@ function openSettings(definition, options) {
|
|
|
11539
11618
|
if (projects.get(path)?.status === "missing") {
|
|
11540
11619
|
const source = options.legacyProject?.(project);
|
|
11541
11620
|
if (source) {
|
|
11542
|
-
selected =
|
|
11621
|
+
selected = resolve13(source.path);
|
|
11543
11622
|
await load({ kind: "legacy-project", path: selected }, (text) => source.read(text));
|
|
11544
11623
|
}
|
|
11545
11624
|
}
|
|
@@ -11591,7 +11670,7 @@ function openSettings(definition, options) {
|
|
|
11591
11670
|
}
|
|
11592
11671
|
// ../../node_modules/@cortexkit/common-auth/dist/settings/move.js
|
|
11593
11672
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
11594
|
-
import { basename as basename6, dirname as
|
|
11673
|
+
import { basename as basename6, dirname as dirname11, join as join12, resolve as resolve14 } from "node:path";
|
|
11595
11674
|
import { isDeepStrictEqual as isDeepStrictEqual2 } from "node:util";
|
|
11596
11675
|
|
|
11597
11676
|
// ../../node_modules/@cortexkit/common-auth/dist/store/refresh-lock.js
|
|
@@ -11659,7 +11738,7 @@ async function acquirePoolLock(spec, defaults2, env) {
|
|
|
11659
11738
|
});
|
|
11660
11739
|
}
|
|
11661
11740
|
const jitter = Math.floor(Math.random() * (options.retryMs + 1));
|
|
11662
|
-
await new Promise((
|
|
11741
|
+
await new Promise((resolve14) => setTimeout(resolve14, Math.min(options.retryMs + jitter, remaining)));
|
|
11663
11742
|
}
|
|
11664
11743
|
}
|
|
11665
11744
|
function definedOnly(spec) {
|
|
@@ -11808,9 +11887,9 @@ function merge(options, legacy, mapped, result) {
|
|
|
11808
11887
|
async function removeStaleTemps(target) {
|
|
11809
11888
|
const prefix = `${basename6(target)}.move-`;
|
|
11810
11889
|
const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.tmp$/i;
|
|
11811
|
-
for (const name of await SettingsFs.readdir(
|
|
11890
|
+
for (const name of await SettingsFs.readdir(dirname11(target))) {
|
|
11812
11891
|
if (name.startsWith(prefix) && uuid.test(name.slice(prefix.length))) {
|
|
11813
|
-
await SettingsFs.unlink(join12(
|
|
11892
|
+
await SettingsFs.unlink(join12(dirname11(target), name));
|
|
11814
11893
|
}
|
|
11815
11894
|
}
|
|
11816
11895
|
}
|
|
@@ -11886,7 +11965,7 @@ ${JSON.stringify(document, null, 2)}
|
|
|
11886
11965
|
}
|
|
11887
11966
|
if (process.platform !== "win32") {
|
|
11888
11967
|
try {
|
|
11889
|
-
const folder = await SettingsFs.open(
|
|
11968
|
+
const folder = await SettingsFs.open(dirname11(target), "r");
|
|
11890
11969
|
try {
|
|
11891
11970
|
await folder.sync();
|
|
11892
11971
|
} finally {
|
|
@@ -11916,7 +11995,7 @@ async function moveSettingsOnce(options) {
|
|
|
11916
11995
|
return emptyResult("done-already");
|
|
11917
11996
|
if (!await options.fence())
|
|
11918
11997
|
return emptyResult("fence-closed");
|
|
11919
|
-
const folder =
|
|
11998
|
+
const folder = dirname11(options.target);
|
|
11920
11999
|
if (process.platform === "win32")
|
|
11921
12000
|
await ensurePrivateDirectory(folder);
|
|
11922
12001
|
else
|
|
@@ -11930,13 +12009,13 @@ async function moveSettingsOnce(options) {
|
|
|
11930
12009
|
const seen = new Map;
|
|
11931
12010
|
for (const source of options.sources) {
|
|
11932
12011
|
for (const spec of source.locks) {
|
|
11933
|
-
const path =
|
|
12012
|
+
const path = resolve14(spec.path);
|
|
11934
12013
|
const names = seen.get(path) ?? new Set;
|
|
11935
12014
|
if (names.has(spec.name))
|
|
11936
12015
|
continue;
|
|
11937
12016
|
names.add(spec.name);
|
|
11938
12017
|
seen.set(path, names);
|
|
11939
|
-
const lockFolder =
|
|
12018
|
+
const lockFolder = dirname11(lockPathFor(spec.path, spec.name));
|
|
11940
12019
|
if (!await exists(lockFolder)) {
|
|
11941
12020
|
skipped.add(lockFolder);
|
|
11942
12021
|
continue;
|
|
@@ -12432,7 +12511,7 @@ async function acquireRefreshFileLock2(options) {
|
|
|
12432
12511
|
const EVICT_TTL = 5000;
|
|
12433
12512
|
const MAX_STEAL_ATTEMPTS = 8;
|
|
12434
12513
|
async function backoff() {
|
|
12435
|
-
await new Promise((
|
|
12514
|
+
await new Promise((resolve15) => setTimeout(resolve15, Math.floor(Math.random() * 4)));
|
|
12436
12515
|
}
|
|
12437
12516
|
async function lockIsLive() {
|
|
12438
12517
|
try {
|
|
@@ -14900,11 +14979,11 @@ import {
|
|
|
14900
14979
|
import { homedir as homedir5 } from "node:os";
|
|
14901
14980
|
import {
|
|
14902
14981
|
basename as basename8,
|
|
14903
|
-
dirname as
|
|
14982
|
+
dirname as dirname14,
|
|
14904
14983
|
extname as extname2,
|
|
14905
14984
|
isAbsolute as isAbsolute3,
|
|
14906
14985
|
join as join16,
|
|
14907
|
-
resolve as
|
|
14986
|
+
resolve as resolve15
|
|
14908
14987
|
} from "node:path";
|
|
14909
14988
|
import {
|
|
14910
14989
|
ClaustrumCredentialError as ClaustrumCredentialError7,
|
|
@@ -14925,7 +15004,7 @@ function parseJsonRedacted(text) {
|
|
|
14925
15004
|
|
|
14926
15005
|
// src/owner-only.ts
|
|
14927
15006
|
import { lstat as lstat5 } from "node:fs/promises";
|
|
14928
|
-
import { dirname as
|
|
15007
|
+
import { dirname as dirname12 } from "node:path";
|
|
14929
15008
|
import { types as utilTypes2 } from "node:util";
|
|
14930
15009
|
async function windowsBackend(options) {
|
|
14931
15010
|
if ((options.platform ?? process.platform) !== "win32")
|
|
@@ -15032,13 +15111,13 @@ async function ensureWindowsOwnerOnlyDirectory(path2, options = {}) {
|
|
|
15032
15111
|
async function ancestors(directory) {
|
|
15033
15112
|
if (await exists2(directory))
|
|
15034
15113
|
return safe(directory);
|
|
15035
|
-
const parent =
|
|
15114
|
+
const parent = dirname12(directory);
|
|
15036
15115
|
if (parent === directory)
|
|
15037
15116
|
throw refused("safe-parent", "io-error");
|
|
15038
15117
|
await ancestors(parent);
|
|
15039
15118
|
await create(directory);
|
|
15040
15119
|
}
|
|
15041
|
-
await ancestors(
|
|
15120
|
+
await ancestors(dirname12(path2));
|
|
15042
15121
|
if (await exists2(path2))
|
|
15043
15122
|
await privateDirectory(path2);
|
|
15044
15123
|
else
|
|
@@ -15312,13 +15391,13 @@ function getClaustrumEnrollmentPaths2(tokenPath) {
|
|
|
15312
15391
|
const extension = extname2(tokenPath) || ".json";
|
|
15313
15392
|
const stem = basename8(tokenPath, extname2(tokenPath));
|
|
15314
15393
|
return {
|
|
15315
|
-
statePath: join16(
|
|
15394
|
+
statePath: join16(dirname14(tokenPath), `${stem}-state${extension}`),
|
|
15316
15395
|
tokenPath
|
|
15317
15396
|
};
|
|
15318
15397
|
}
|
|
15319
15398
|
function getHostClaustrumEnrollmentPaths(host, env = process.env, cwd = process.cwd()) {
|
|
15320
15399
|
const configured = env[`${host.toUpperCase()}_ANTHROPIC_AUTH_CLAUSTRUM_ENROLLMENT_FILE`]?.trim();
|
|
15321
|
-
const tokenPath = configured ? isAbsolute3(configured) ? configured :
|
|
15400
|
+
const tokenPath = configured ? isAbsolute3(configured) ? configured : resolve15(cwd, configured) : join16(anthropicAuthStateRoot({
|
|
15322
15401
|
xdgStateHome: env.XDG_STATE_HOME,
|
|
15323
15402
|
home: homedir5(),
|
|
15324
15403
|
acceptRelative: true
|
|
@@ -15433,9 +15512,7 @@ async function readBoundedJson2(path2, ownership = {}) {
|
|
|
15433
15512
|
await descriptor.close();
|
|
15434
15513
|
}
|
|
15435
15514
|
}
|
|
15436
|
-
async function refuseWritableAncestor2(parent, ownership = {}, metadataAt = (path2) => stat11(path2)
|
|
15437
|
-
return;
|
|
15438
|
-
})) {
|
|
15515
|
+
async function refuseWritableAncestor2(parent, ownership = {}, metadataAt = (path2) => stat11(path2)) {
|
|
15439
15516
|
const safe = await isSafeWindowsParent(parent, ownership);
|
|
15440
15517
|
if (safe === true)
|
|
15441
15518
|
return;
|
|
@@ -15444,22 +15521,31 @@ async function refuseWritableAncestor2(parent, ownership = {}, metadataAt = (pat
|
|
|
15444
15521
|
let component;
|
|
15445
15522
|
try {
|
|
15446
15523
|
component = await realpath4(parent);
|
|
15447
|
-
} catch {
|
|
15448
|
-
|
|
15524
|
+
} catch (error) {
|
|
15525
|
+
if (error.code === "ENOENT")
|
|
15526
|
+
return;
|
|
15527
|
+
throw new Error("Claustrum enrollment path has an unsafe writable ancestor");
|
|
15449
15528
|
}
|
|
15450
15529
|
for (;; ) {
|
|
15451
|
-
|
|
15530
|
+
let metadata;
|
|
15531
|
+
try {
|
|
15532
|
+
metadata = await metadataAt(component);
|
|
15533
|
+
} catch (error) {
|
|
15534
|
+
if (error.code !== "ENOENT") {
|
|
15535
|
+
throw new Error("Claustrum enrollment path has an unsafe writable ancestor");
|
|
15536
|
+
}
|
|
15537
|
+
}
|
|
15452
15538
|
if (metadata && (metadata.mode & 18) !== 0 && (metadata.mode & 512) === 0) {
|
|
15453
15539
|
throw new Error("Claustrum enrollment path has an unsafe writable ancestor");
|
|
15454
15540
|
}
|
|
15455
|
-
const next =
|
|
15541
|
+
const next = dirname14(component);
|
|
15456
15542
|
if (next === component)
|
|
15457
15543
|
return;
|
|
15458
15544
|
component = next;
|
|
15459
15545
|
}
|
|
15460
15546
|
}
|
|
15461
15547
|
async function writeStateAtomic2(path2, state, beforeRename) {
|
|
15462
|
-
const parent =
|
|
15548
|
+
const parent = dirname14(path2);
|
|
15463
15549
|
await mkdir7(parent, { recursive: true, mode: 448 });
|
|
15464
15550
|
await refuseWritableAncestor2(parent);
|
|
15465
15551
|
const bytes = `${JSON.stringify(state)}
|
|
@@ -15486,7 +15572,7 @@ async function writeStateAtomic2(path2, state, beforeRename) {
|
|
|
15486
15572
|
}
|
|
15487
15573
|
}
|
|
15488
15574
|
async function writeTokenAtomic(path2, value, writeTokenFile, beforeRename) {
|
|
15489
|
-
const staged = join16(
|
|
15575
|
+
const staged = join16(dirname14(path2), `.${basename8(path2)}.${process.pid}.${randomUUID10()}.tmp`);
|
|
15490
15576
|
try {
|
|
15491
15577
|
await writeTokenFile(staged, value);
|
|
15492
15578
|
await beforeRename();
|
|
@@ -15535,7 +15621,7 @@ async function readClaustrumEnrollmentStatus2(paths, proposedName = CLAUSTRUM_OP
|
|
|
15535
15621
|
};
|
|
15536
15622
|
}
|
|
15537
15623
|
async function readClaustrumEnrollmentToken2(tokenPath) {
|
|
15538
|
-
await refuseWritableAncestor2(tokenPath);
|
|
15624
|
+
await refuseWritableAncestor2(dirname14(tokenPath));
|
|
15539
15625
|
const value = await readBoundedJson2(tokenPath);
|
|
15540
15626
|
if (value === undefined)
|
|
15541
15627
|
throw new Error("Claustrum enrollment is not configured");
|
|
@@ -15590,7 +15676,7 @@ class ClaustrumEnrollmentManager2 {
|
|
|
15590
15676
|
return resetClaustrumEnrollmentState2(this.#paths, this.#proposedName);
|
|
15591
15677
|
}
|
|
15592
15678
|
async reconcile() {
|
|
15593
|
-
await mkdir7(
|
|
15679
|
+
await mkdir7(dirname14(this.#paths.statePath), {
|
|
15594
15680
|
recursive: true,
|
|
15595
15681
|
mode: 448
|
|
15596
15682
|
});
|
|
@@ -15754,7 +15840,7 @@ class ClaustrumEnrollmentManager2 {
|
|
|
15754
15840
|
}
|
|
15755
15841
|
}
|
|
15756
15842
|
async function resetClaustrumEnrollmentState2(paths, proposedName) {
|
|
15757
|
-
await mkdir7(
|
|
15843
|
+
await mkdir7(dirname14(paths.statePath), { recursive: true, mode: 448 });
|
|
15758
15844
|
const lock = await acquireRefreshFileLock2({
|
|
15759
15845
|
name: "ceremony",
|
|
15760
15846
|
path: paths.statePath,
|
|
@@ -15915,8 +16001,8 @@ function createNativeCustody(options) {
|
|
|
15915
16001
|
let stopped = false;
|
|
15916
16002
|
let inner;
|
|
15917
16003
|
let finish = () => {};
|
|
15918
|
-
const ended = new Promise((
|
|
15919
|
-
finish =
|
|
16004
|
+
const ended = new Promise((resolve16) => {
|
|
16005
|
+
finish = resolve16;
|
|
15920
16006
|
});
|
|
15921
16007
|
const failed = (error) => stopped || closed2 || error instanceof NativeCustodyError ? { kind: "stopped" } : classifyVaultFailure(error) === "unreachable" ? { kind: "transport_lost", error: new ClaustrumUnreachableError } : { kind: "ended" };
|
|
15922
16008
|
Promise.resolve().then(connection).then((owned) => {
|
|
@@ -17061,7 +17147,7 @@ import {
|
|
|
17061
17147
|
writeFile as writeFile2
|
|
17062
17148
|
} from "node:fs/promises";
|
|
17063
17149
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
17064
|
-
import { join as join17, resolve as
|
|
17150
|
+
import { join as join17, resolve as resolve16 } from "node:path";
|
|
17065
17151
|
var CLAUDE_DUMP_COMMAND_NAME = "claude-dump";
|
|
17066
17152
|
var DUMP_STATUS_TITLE = "## Claude Dump Status";
|
|
17067
17153
|
var DUMP_ENABLED_TITLE = "## Claude Dump Enabled";
|
|
@@ -17107,7 +17193,7 @@ function getDumpMaxBytes() {
|
|
|
17107
17193
|
return Number.isFinite(configured) && configured >= 0 ? Math.floor(configured) : DEFAULT_DUMP_MAX_BYTES;
|
|
17108
17194
|
}
|
|
17109
17195
|
function isConfiguredDumpDirectory(path2) {
|
|
17110
|
-
return
|
|
17196
|
+
return resolve16(path2) === resolve16(getDumpDirectory());
|
|
17111
17197
|
}
|
|
17112
17198
|
function isDumpArtifactFileName(name) {
|
|
17113
17199
|
const stem = name.replace(DUMP_ARTIFACT_SUFFIX_PATTERN, "");
|
|
@@ -17164,7 +17250,7 @@ async function sweepDumpDirectory(options) {
|
|
|
17164
17250
|
const dumpDirStats = await lstat6(dumpDir);
|
|
17165
17251
|
if (dumpDirStats.isSymbolicLink())
|
|
17166
17252
|
return emptyResult2;
|
|
17167
|
-
const protectedPaths = new Set((options.protectedPaths ?? []).map((path2) =>
|
|
17253
|
+
const protectedPaths = new Set((options.protectedPaths ?? []).map((path2) => resolve16(path2)));
|
|
17168
17254
|
const entries = await readdir4(dumpDir, { withFileTypes: true });
|
|
17169
17255
|
const files = [];
|
|
17170
17256
|
await Promise.all(entries.map(async (entry) => {
|
|
@@ -17202,7 +17288,7 @@ async function sweepDumpDirectory(options) {
|
|
|
17202
17288
|
};
|
|
17203
17289
|
const partials = files.filter((file) => file.partial).sort((left, right) => left.mtimeMs - right.mtimeMs || left.path.localeCompare(right.path));
|
|
17204
17290
|
for (const file of partials) {
|
|
17205
|
-
if (protectedPaths.has(
|
|
17291
|
+
if (protectedPaths.has(resolve16(file.path)))
|
|
17206
17292
|
continue;
|
|
17207
17293
|
if (now - file.mtimeMs < partialStaleMs)
|
|
17208
17294
|
continue;
|
|
@@ -17226,7 +17312,7 @@ async function sweepDumpDirectory(options) {
|
|
|
17226
17312
|
break;
|
|
17227
17313
|
if (now - group.newestMtimeMs < minAgeMs)
|
|
17228
17314
|
continue;
|
|
17229
|
-
if (group.files.some((file) => protectedPaths.has(
|
|
17315
|
+
if (group.files.some((file) => protectedPaths.has(resolve16(file.path)))) {
|
|
17230
17316
|
continue;
|
|
17231
17317
|
}
|
|
17232
17318
|
for (const file of group.files)
|
|
@@ -19064,8 +19150,8 @@ function createProviderErrorResponseScope(secrets, mode) {
|
|
|
19064
19150
|
wrappedBodies: 0
|
|
19065
19151
|
};
|
|
19066
19152
|
let resolveSettled = () => {};
|
|
19067
|
-
const settled = new Promise((
|
|
19068
|
-
resolveSettled =
|
|
19153
|
+
const settled = new Promise((resolve17) => {
|
|
19154
|
+
resolveSettled = resolve17;
|
|
19069
19155
|
});
|
|
19070
19156
|
let retired = false;
|
|
19071
19157
|
let used = false;
|
|
@@ -20752,7 +20838,7 @@ import {
|
|
|
20752
20838
|
} from "node:fs/promises";
|
|
20753
20839
|
import { tmpdir as tmpdir6 } from "node:os";
|
|
20754
20840
|
import * as nodePath3 from "node:path";
|
|
20755
|
-
import { dirname as
|
|
20841
|
+
import { dirname as dirname21, join as join25 } from "node:path";
|
|
20756
20842
|
|
|
20757
20843
|
// src/holder-registry.ts
|
|
20758
20844
|
import { execFile } from "node:child_process";
|
|
@@ -20760,7 +20846,7 @@ import { randomUUID as randomUUID17 } from "node:crypto";
|
|
|
20760
20846
|
import { readFileSync as readFileSync3 } from "node:fs";
|
|
20761
20847
|
import { lstat as lstat13, mkdir as mkdir11, readFile as readFile13 } from "node:fs/promises";
|
|
20762
20848
|
import { uptime } from "node:os";
|
|
20763
|
-
import { basename as basename13, dirname as
|
|
20849
|
+
import { basename as basename13, dirname as dirname20, join as join24 } from "node:path";
|
|
20764
20850
|
|
|
20765
20851
|
// src/native-lock-observer.ts
|
|
20766
20852
|
import { AsyncLocalStorage as AsyncLocalStorage3 } from "node:async_hooks";
|
|
@@ -20803,16 +20889,17 @@ function observeNativeLocks(acquire, observer) {
|
|
|
20803
20889
|
|
|
20804
20890
|
// src/native-vault-paths.ts
|
|
20805
20891
|
import { createHash as createHash18 } from "node:crypto";
|
|
20806
|
-
import { basename as basename12, dirname as
|
|
20892
|
+
import { basename as basename12, dirname as dirname18, join as join21 } from "node:path";
|
|
20807
20893
|
|
|
20808
20894
|
// src/pool-paths.ts
|
|
20809
20895
|
import { createHash as createHash17 } from "node:crypto";
|
|
20810
|
-
import
|
|
20896
|
+
import * as fsPromises from "node:fs/promises";
|
|
20897
|
+
import { basename as basename11, dirname as dirname17, join as join20 } from "node:path";
|
|
20811
20898
|
|
|
20812
20899
|
// src/sticky-routing.ts
|
|
20813
20900
|
import { createHash as createHash16, randomUUID as randomUUID15 } from "node:crypto";
|
|
20814
20901
|
import { mkdir as mkdir10, readFile as readFile10, rename as rename12, rm as rm6, stat as stat12, writeFile as writeFile3 } from "node:fs/promises";
|
|
20815
|
-
import { basename as basename10, dirname as
|
|
20902
|
+
import { basename as basename10, dirname as dirname16, join as join19 } from "node:path";
|
|
20816
20903
|
|
|
20817
20904
|
// src/native-vault-seed.ts
|
|
20818
20905
|
import { lstat as lstat8, readFile as readFile9 } from "node:fs/promises";
|
|
@@ -23564,11 +23651,11 @@ class PoolQuotaWriter {
|
|
|
23564
23651
|
const left = deadline - performance.now();
|
|
23565
23652
|
if (left <= 0)
|
|
23566
23653
|
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);
|
|
23567
|
-
await new Promise((
|
|
23654
|
+
await new Promise((resolve17) => {
|
|
23568
23655
|
const done = () => {
|
|
23569
23656
|
clearTimeout(timer);
|
|
23570
23657
|
this.wake.delete(done);
|
|
23571
|
-
|
|
23658
|
+
resolve17();
|
|
23572
23659
|
};
|
|
23573
23660
|
const timer = setTimeout(done, left);
|
|
23574
23661
|
this.wake.add(done);
|
|
@@ -24693,7 +24780,7 @@ var nativeQuotaCodec = {
|
|
|
24693
24780
|
import { randomUUID as randomUUID14 } from "node:crypto";
|
|
24694
24781
|
import { constants as constants2 } from "node:fs";
|
|
24695
24782
|
import { lstat as lstat7, mkdir as mkdir9, open as open9, rename as rename11, rm as rm5 } from "node:fs/promises";
|
|
24696
|
-
import { basename as basename9, dirname as
|
|
24783
|
+
import { basename as basename9, dirname as dirname15, isAbsolute as isAbsolute4, join as join18 } from "node:path";
|
|
24697
24784
|
import { types as utilTypes5 } from "node:util";
|
|
24698
24785
|
|
|
24699
24786
|
// src/pool-binding.ts
|
|
@@ -24897,7 +24984,7 @@ async function renameWithWindowsSharingRetry(from, to, options = {}, beforeRetry
|
|
|
24897
24984
|
return "published";
|
|
24898
24985
|
}
|
|
24899
24986
|
const now = options.now ?? (() => performance.now());
|
|
24900
|
-
const sleep = options.sleep ?? ((ms) => new Promise((
|
|
24987
|
+
const sleep = options.sleep ?? ((ms) => new Promise((resolve17) => setTimeout(resolve17, ms)));
|
|
24901
24988
|
const start = now();
|
|
24902
24989
|
let original;
|
|
24903
24990
|
try {
|
|
@@ -25288,7 +25375,7 @@ async function writeNativeRuntimeOutcome(path2, storageId, change, hooks, firstI
|
|
|
25288
25375
|
return (publication2.rename ?? rename11)(from, to);
|
|
25289
25376
|
};
|
|
25290
25377
|
try {
|
|
25291
|
-
await mkdir9(
|
|
25378
|
+
await mkdir9(dirname15(path2), { recursive: true, mode: 448 });
|
|
25292
25379
|
return await withLock2(path2, {
|
|
25293
25380
|
name: "native-runtime",
|
|
25294
25381
|
ttlMs: 1e4,
|
|
@@ -25303,7 +25390,7 @@ async function writeNativeRuntimeOutcome(path2, storageId, change, hooks, firstI
|
|
|
25303
25390
|
assertTransitions(current, next, firstIdentity);
|
|
25304
25391
|
const bytes = `${JSON.stringify(next, null, 2)}
|
|
25305
25392
|
`;
|
|
25306
|
-
const stage = join18(
|
|
25393
|
+
const stage = join18(dirname15(path2), `${basename9(path2)}.native-runtime.${randomUUID14()}.partial`);
|
|
25307
25394
|
let ownsStage = false;
|
|
25308
25395
|
try {
|
|
25309
25396
|
const nativeCreated = await createWindowsOwnerOnly(stage, bytes);
|
|
@@ -26888,7 +26975,7 @@ function stickyRetainRetryHeaders(upstream, now = Date.now()) {
|
|
|
26888
26975
|
function getStickyRoutingStatePath(accountStoragePath) {
|
|
26889
26976
|
const name = basename10(accountStoragePath);
|
|
26890
26977
|
const stem = name.endsWith(".json") ? name.slice(0, -5) : name;
|
|
26891
|
-
return join19(
|
|
26978
|
+
return join19(dirname16(accountStoragePath), `${stem}-routing-state.json`);
|
|
26892
26979
|
}
|
|
26893
26980
|
function stickyRetryAfterWithJitter(sessionId, retryAfterSeconds) {
|
|
26894
26981
|
const hash2 = createHash16("sha256").update(sessionId).digest().readUInt32BE(0);
|
|
@@ -26963,7 +27050,7 @@ class StickySessionRouter {
|
|
|
26963
27050
|
const observer = nativeLockObserver(this.options.onLockEvent);
|
|
26964
27051
|
const event = { name: "write", path: this.options.path, detached };
|
|
26965
27052
|
observer?.({ ...event, type: "acquiring" });
|
|
26966
|
-
await mkdir10(
|
|
27053
|
+
await mkdir10(dirname16(this.options.path), { recursive: true, mode: 448 });
|
|
26967
27054
|
const deadline = performance.now() + STICKY_ROUTING_LOCK_WAIT_MS;
|
|
26968
27055
|
while (true) {
|
|
26969
27056
|
const lock = await acquireRefreshFileLock2({
|
|
@@ -26989,7 +27076,7 @@ class StickySessionRouter {
|
|
|
26989
27076
|
if (!wait || performance.now() >= deadline) {
|
|
26990
27077
|
throw new Error("Timed out acquiring sticky routing state lock");
|
|
26991
27078
|
}
|
|
26992
|
-
await new Promise((
|
|
27079
|
+
await new Promise((resolve17) => setTimeout(resolve17, STICKY_ROUTING_LOCK_POLL_MS));
|
|
26993
27080
|
}
|
|
26994
27081
|
}
|
|
26995
27082
|
recoverLocalPins() {
|
|
@@ -27371,17 +27458,20 @@ class StickySessionRouter {
|
|
|
27371
27458
|
|
|
27372
27459
|
// src/pool-paths.ts
|
|
27373
27460
|
function stateLayoutOfPaths(paths) {
|
|
27374
|
-
const dir =
|
|
27375
|
-
return dir ===
|
|
27461
|
+
const dir = dirname17(paths.runtime);
|
|
27462
|
+
return dir === dirname17(paths.legacyState) ? LEGACY_STATE_LAYOUT : { kind: "state-home", dir };
|
|
27376
27463
|
}
|
|
27377
27464
|
function resolveLocalRoutingDestination(host, paths, env) {
|
|
27378
27465
|
return (host === "opencode" ? env.OPENCODE_ANTHROPIC_AUTH_ROUTING_STATE_FILE : env.PI_ANTHROPIC_AUTH_ROUTING_STATE_FILE) || getStickyRoutingStatePath(paths.config);
|
|
27379
27466
|
}
|
|
27380
27467
|
async function canonicalPath2(path2, options = {}) {
|
|
27381
|
-
const { paths, realpath: realpath5 } = resolvePathOptions(options);
|
|
27468
|
+
const { paths, platform, realpath: realpath5 } = resolvePathOptions(options);
|
|
27382
27469
|
const absolute = paths.resolve(path2);
|
|
27383
27470
|
try {
|
|
27384
|
-
return await realpath5(absolute)
|
|
27471
|
+
return platform === "win32" ? await realpath5(absolute) : await canonicalFilePath(absolute, {
|
|
27472
|
+
...fsPromises,
|
|
27473
|
+
realpath: realpath5
|
|
27474
|
+
});
|
|
27385
27475
|
} catch (error) {
|
|
27386
27476
|
if (!(error instanceof Error) || !("code" in error) || error.code !== "ENOENT") {
|
|
27387
27477
|
throw error;
|
|
@@ -27393,7 +27483,7 @@ async function canonicalPath2(path2, options = {}) {
|
|
|
27393
27483
|
return paths.join(await canonicalPath2(parent, options), paths.basename(absolute));
|
|
27394
27484
|
}
|
|
27395
27485
|
function sibling(path2, legacyName, name, suffix) {
|
|
27396
|
-
return basename11(path2) === legacyName ? join20(
|
|
27486
|
+
return basename11(path2) === legacyName ? join20(dirname17(path2), name) : `${path2}.${suffix}.json`;
|
|
27397
27487
|
}
|
|
27398
27488
|
async function resolveNativePoolPaths(legacyConfig = getAccountStoragePath(), legacyState = getAccountStatePath(legacyConfig), layout) {
|
|
27399
27489
|
const [sourceConfig, sourceState] = await Promise.all([
|
|
@@ -27443,7 +27533,7 @@ async function resolveNativePoolPaths(legacyConfig = getAccountStoragePath(), le
|
|
|
27443
27533
|
|
|
27444
27534
|
// src/native-vault-paths.ts
|
|
27445
27535
|
function sibling2(path2, expected, name, suffix) {
|
|
27446
|
-
return basename12(path2) === expected ? join21(
|
|
27536
|
+
return basename12(path2) === expected ? join21(dirname18(path2), name) : path2.replace(/(?:\.json)?$/, `.${suffix}.json`);
|
|
27447
27537
|
}
|
|
27448
27538
|
function nativeVaultPaths(local, layout = stateLayoutOfPaths(local)) {
|
|
27449
27539
|
const config = sibling2(local.legacyConfig, "anthropic-auth.json", "anthropic-auth-vault-settings.json", "vault-settings");
|
|
@@ -27487,7 +27577,7 @@ import { lstat as lstat12 } from "node:fs/promises";
|
|
|
27487
27577
|
|
|
27488
27578
|
// src/state-home-serving-guard.ts
|
|
27489
27579
|
import { lstat as lstat11 } from "node:fs/promises";
|
|
27490
|
-
import { dirname as
|
|
27580
|
+
import { dirname as dirname19, join as join23 } from "node:path";
|
|
27491
27581
|
|
|
27492
27582
|
// src/state-layout-errors.ts
|
|
27493
27583
|
var RESTORE_LEGACY_COMMAND = "npx @cortexkit/opencode-anthropic-auth setup --restore-legacy";
|
|
@@ -27680,7 +27770,7 @@ class StateLayoutLockStack {
|
|
|
27680
27770
|
name: spec.name,
|
|
27681
27771
|
timeoutMs
|
|
27682
27772
|
});
|
|
27683
|
-
await new Promise((
|
|
27773
|
+
await new Promise((resolve17) => setTimeout(resolve17, Math.min(remaining, POOL_LOCK_DEFAULTS.retryMs + Math.floor(Math.random() * 25))));
|
|
27684
27774
|
}
|
|
27685
27775
|
}
|
|
27686
27776
|
async assertAll() {
|
|
@@ -27949,9 +28039,9 @@ function isLayoutRecordStage(name, attempt) {
|
|
|
27949
28039
|
|
|
27950
28040
|
// src/state-home-serving-guard.ts
|
|
27951
28041
|
function stateHomeServingFiles(paths) {
|
|
27952
|
-
const oldDir =
|
|
28042
|
+
const oldDir = dirname19(paths.legacyState);
|
|
27953
28043
|
return {
|
|
27954
|
-
sub:
|
|
28044
|
+
sub: dirname19(paths.runtime),
|
|
27955
28045
|
oldPoolState: join23(oldDir, STATE_HOME_FILE_NAMES.localPoolState),
|
|
27956
28046
|
newPoolState: paths.state,
|
|
27957
28047
|
oldJournal: join23(oldDir, STATE_HOME_FILE_NAMES.journal),
|
|
@@ -28285,8 +28375,8 @@ function nativeHolderDatasetFiles(paths) {
|
|
|
28285
28375
|
}
|
|
28286
28376
|
function isDestinationShapedDirectory(dir) {
|
|
28287
28377
|
const name = basename13(dir);
|
|
28288
|
-
const parent =
|
|
28289
|
-
return (name === "opencode" || /^opencode-[0-9a-f]{16}$/.test(name)) && basename13(parent) === "anthropic-auth" && basename13(
|
|
28378
|
+
const parent = dirname20(dir);
|
|
28379
|
+
return (name === "opencode" || /^opencode-[0-9a-f]{16}$/.test(name)) && basename13(parent) === "anthropic-auth" && basename13(dirname20(parent)) === "cortexkit";
|
|
28290
28380
|
}
|
|
28291
28381
|
function openCodeHolderKind(env = process.env) {
|
|
28292
28382
|
return env.OPENCODE_ANTHROPIC_AUTH_FILE?.trim() || env.OPENCODE_ANTHROPIC_AUTH_STATE_FILE?.trim() ? "explicit" : "legacy";
|
|
@@ -28348,10 +28438,10 @@ async function linuxIncarnation(pid) {
|
|
|
28348
28438
|
}
|
|
28349
28439
|
}
|
|
28350
28440
|
function macosIncarnation(pid) {
|
|
28351
|
-
return new Promise((
|
|
28441
|
+
return new Promise((resolve17) => {
|
|
28352
28442
|
execFile("ps", ["-o", "lstart=", "-p", String(pid)], { env: { ...process.env, TZ: "UTC0" }, timeout: 5000 }, (error, stdout) => {
|
|
28353
28443
|
const text5 = String(stdout ?? "").trim();
|
|
28354
|
-
|
|
28444
|
+
resolve17(error || !text5 ? null : text5);
|
|
28355
28445
|
});
|
|
28356
28446
|
});
|
|
28357
28447
|
}
|
|
@@ -28412,7 +28502,7 @@ async function readHolderFile(path2) {
|
|
|
28412
28502
|
try {
|
|
28413
28503
|
const info = await lstat13(path2);
|
|
28414
28504
|
if (!info.isFile() || info.size > HOLDER_FILE_MAX_BYTES)
|
|
28415
|
-
throw new HolderRegistrationError("malformed",
|
|
28505
|
+
throw new HolderRegistrationError("malformed", dirname20(path2));
|
|
28416
28506
|
text5 = await readFile13(path2, "utf8");
|
|
28417
28507
|
} catch (error) {
|
|
28418
28508
|
if (error.code === "ENOENT")
|
|
@@ -28423,10 +28513,10 @@ async function readHolderFile(path2) {
|
|
|
28423
28513
|
try {
|
|
28424
28514
|
value = parseJsonRedacted(text5);
|
|
28425
28515
|
} catch (cause) {
|
|
28426
|
-
throw new HolderRegistrationError("malformed",
|
|
28516
|
+
throw new HolderRegistrationError("malformed", dirname20(path2), cause);
|
|
28427
28517
|
}
|
|
28428
28518
|
if (!isRecord14(value) || value.version !== 1 || !Array.isArray(value.entries))
|
|
28429
|
-
throw new HolderRegistrationError("malformed",
|
|
28519
|
+
throw new HolderRegistrationError("malformed", dirname20(path2));
|
|
28430
28520
|
return { entries: value.entries };
|
|
28431
28521
|
}
|
|
28432
28522
|
async function exists3(path2) {
|
|
@@ -28448,9 +28538,9 @@ async function isManagedDirectory(dir) {
|
|
|
28448
28538
|
}
|
|
28449
28539
|
async function assertUnmanagedInjectedPaths(paths) {
|
|
28450
28540
|
if (stateLayoutOfPaths(paths).kind === "state-home")
|
|
28451
|
-
throw new HolderRegistrationError("managed-folder",
|
|
28541
|
+
throw new HolderRegistrationError("managed-folder", dirname20(paths.runtime));
|
|
28452
28542
|
const dirs = [
|
|
28453
|
-
...new Set(nativeHolderDatasetFiles(paths).map((file) =>
|
|
28543
|
+
...new Set(nativeHolderDatasetFiles(paths).map((file) => dirname20(file)))
|
|
28454
28544
|
].sort();
|
|
28455
28545
|
for (const dir of dirs)
|
|
28456
28546
|
if (isDestinationShapedDirectory(dir) || await isManagedDirectory(dir))
|
|
@@ -28492,7 +28582,7 @@ async function ensureHolderDirectory(dir, ownerOnly = {}) {
|
|
|
28492
28582
|
await ensureWindowsOwnerOnlyDirectory(dir, ownerOnly);
|
|
28493
28583
|
}
|
|
28494
28584
|
async function publishEntry(holderFile, entry2, options, mandatory) {
|
|
28495
|
-
const dir =
|
|
28585
|
+
const dir = dirname20(holderFile);
|
|
28496
28586
|
if (mandatory)
|
|
28497
28587
|
await ensureHolderDirectory(dir, options.ownerOnly);
|
|
28498
28588
|
await withNativeLock(holderFile, {
|
|
@@ -28550,7 +28640,7 @@ async function buildEntry(options) {
|
|
|
28550
28640
|
let identity5 = null;
|
|
28551
28641
|
if (options.kind === "legacy") {
|
|
28552
28642
|
try {
|
|
28553
|
-
identity5 = configFolderIdentity(
|
|
28643
|
+
identity5 = configFolderIdentity(dirname20(options.paths.legacyConfig)) ?? null;
|
|
28554
28644
|
} catch {
|
|
28555
28645
|
identity5 = null;
|
|
28556
28646
|
}
|
|
@@ -28569,7 +28659,7 @@ async function buildEntry(options) {
|
|
|
28569
28659
|
}
|
|
28570
28660
|
async function registerNativePoolHolder(options) {
|
|
28571
28661
|
const entry2 = await buildEntry(options);
|
|
28572
|
-
const dirs = [...new Set(entry2.files.map((file) =>
|
|
28662
|
+
const dirs = [...new Set(entry2.files.map((file) => dirname20(file)))].sort();
|
|
28573
28663
|
const holderFiles = dirs.map((dir) => join24(dir, HOLDER_FILE_NAME));
|
|
28574
28664
|
const done = {
|
|
28575
28665
|
status: "registered",
|
|
@@ -28607,16 +28697,16 @@ function warnRegistrationFailure(dir, error) {
|
|
|
28607
28697
|
});
|
|
28608
28698
|
}
|
|
28609
28699
|
function registrationAttempt(options, entry2, mandatory) {
|
|
28610
|
-
const dirs = [...new Set(entry2.files.map((file) =>
|
|
28700
|
+
const dirs = [...new Set(entry2.files.map((file) => dirname20(file)))].sort();
|
|
28611
28701
|
const holderFiles = dirs.map((dir) => join24(dir, HOLDER_FILE_NAME));
|
|
28612
28702
|
return async () => {
|
|
28613
28703
|
let complete = true;
|
|
28614
28704
|
for (const holderFile of holderFiles) {
|
|
28615
28705
|
if (published.has(registrationKey(holderFile, entry2)))
|
|
28616
28706
|
continue;
|
|
28617
|
-
const dir =
|
|
28707
|
+
const dir = dirname20(holderFile);
|
|
28618
28708
|
try {
|
|
28619
|
-
if (!mandatory && !await anyExists(entry2.files.filter((file) =>
|
|
28709
|
+
if (!mandatory && !await anyExists(entry2.files.filter((file) => dirname20(file) === dir))) {
|
|
28620
28710
|
complete = false;
|
|
28621
28711
|
continue;
|
|
28622
28712
|
}
|
|
@@ -28637,8 +28727,8 @@ function retryInBackground(attempt, options) {
|
|
|
28637
28727
|
let timer;
|
|
28638
28728
|
let closed2 = false;
|
|
28639
28729
|
let settle = () => {};
|
|
28640
|
-
const settled = new Promise((
|
|
28641
|
-
settle =
|
|
28730
|
+
const settled = new Promise((resolve17) => {
|
|
28731
|
+
settle = resolve17;
|
|
28642
28732
|
});
|
|
28643
28733
|
const schedule2 = () => {
|
|
28644
28734
|
if (closed2)
|
|
@@ -28792,7 +28882,7 @@ class CacheKeepSessionRegistry {
|
|
|
28792
28882
|
await rm7(filePath, { force: true });
|
|
28793
28883
|
continue;
|
|
28794
28884
|
}
|
|
28795
|
-
const directory =
|
|
28885
|
+
const directory = dirname21(filePath);
|
|
28796
28886
|
if (!await ensureWindowsOwnerOnlyDirectory(directory, this.options.ownerOnly)) {
|
|
28797
28887
|
await mkdir12(directory, { recursive: true, mode: 448 });
|
|
28798
28888
|
}
|
|
@@ -30385,13 +30475,16 @@ function messageThreadCachePrefix(body, messageIndex, blockIndex, betas) {
|
|
|
30385
30475
|
...message,
|
|
30386
30476
|
content
|
|
30387
30477
|
});
|
|
30478
|
+
const outputConfig = isBody(body.output_config) ? { ...body.output_config } : body.output_config;
|
|
30479
|
+
if (isBody(outputConfig))
|
|
30480
|
+
delete outputConfig.effort;
|
|
30388
30481
|
const system = Array.isArray(body.system) ? body.system.filter((block) => !(typeof block?.text === "string" && block.text.startsWith("x-anthropic-billing-header:"))).map(withoutOwnCache) : body.system;
|
|
30389
30482
|
return hash4(canonicalValue({
|
|
30390
30483
|
model: body.model,
|
|
30391
30484
|
speed: body.speed,
|
|
30392
30485
|
betas,
|
|
30393
30486
|
thinking: body.thinking,
|
|
30394
|
-
output_config:
|
|
30487
|
+
output_config: outputConfig,
|
|
30395
30488
|
tool_choice: body.tool_choice,
|
|
30396
30489
|
context_management: body.context_management,
|
|
30397
30490
|
fallbacks: body.fallbacks,
|
|
@@ -31321,7 +31414,7 @@ function remapRequestBodyModel(parsed) {
|
|
|
31321
31414
|
}
|
|
31322
31415
|
// src/native-account-runtime.ts
|
|
31323
31416
|
import { randomUUID as randomUUID23 } from "node:crypto";
|
|
31324
|
-
import { resolve as
|
|
31417
|
+
import { resolve as resolve21 } from "node:path";
|
|
31325
31418
|
|
|
31326
31419
|
// src/native-account-view.ts
|
|
31327
31420
|
import { types as types2 } from "node:util";
|
|
@@ -31842,13 +31935,13 @@ function logCommittedNativeAccountAdded(account) {
|
|
|
31842
31935
|
}
|
|
31843
31936
|
|
|
31844
31937
|
// src/native-vault-invalidation.ts
|
|
31845
|
-
import { resolve as
|
|
31938
|
+
import { resolve as resolve17 } from "node:path";
|
|
31846
31939
|
var holders = new Set;
|
|
31847
31940
|
function watchNativeVaultAuthority(holder) {
|
|
31848
31941
|
const held = {
|
|
31849
31942
|
...holder,
|
|
31850
|
-
roster:
|
|
31851
|
-
tokenPath:
|
|
31943
|
+
roster: resolve17(holder.roster),
|
|
31944
|
+
tokenPath: resolve17(holder.tokenPath)
|
|
31852
31945
|
};
|
|
31853
31946
|
holders.add(held);
|
|
31854
31947
|
return () => {
|
|
@@ -31857,12 +31950,12 @@ function watchNativeVaultAuthority(holder) {
|
|
|
31857
31950
|
}
|
|
31858
31951
|
function retainNativeVaultRoster(path2, roster) {
|
|
31859
31952
|
for (const holder of holders)
|
|
31860
|
-
if (holder.roster ===
|
|
31953
|
+
if (holder.roster === resolve17(path2))
|
|
31861
31954
|
holder.retain(roster);
|
|
31862
31955
|
}
|
|
31863
31956
|
function closeNativeVaultAuthority(tokenPath) {
|
|
31864
31957
|
for (const holder of holders)
|
|
31865
|
-
if (holder.tokenPath ===
|
|
31958
|
+
if (holder.tokenPath === resolve17(tokenPath) && !holder.isHosted?.())
|
|
31866
31959
|
holder.close();
|
|
31867
31960
|
}
|
|
31868
31961
|
|
|
@@ -32190,12 +32283,12 @@ async function joinNativePoolWrite(paths, signals, check, onLockEvent) {
|
|
|
32190
32283
|
function pause(ms, signals) {
|
|
32191
32284
|
if (signals.some((signal) => signal.aborted))
|
|
32192
32285
|
return Promise.resolve();
|
|
32193
|
-
return new Promise((
|
|
32286
|
+
return new Promise((resolve18) => {
|
|
32194
32287
|
const wake = () => {
|
|
32195
32288
|
clearTimeout(timer);
|
|
32196
32289
|
for (const signal of signals)
|
|
32197
32290
|
signal.removeEventListener("abort", wake);
|
|
32198
|
-
|
|
32291
|
+
resolve18();
|
|
32199
32292
|
};
|
|
32200
32293
|
const timer = setTimeout(wake, ms);
|
|
32201
32294
|
for (const signal of signals)
|
|
@@ -32451,7 +32544,7 @@ function createNativeRefreshCoordinator(options) {
|
|
|
32451
32544
|
name: spec.name,
|
|
32452
32545
|
timeoutMs: POOL_LOCK_DEFAULTS.timeoutMs
|
|
32453
32546
|
});
|
|
32454
|
-
await new Promise((
|
|
32547
|
+
await new Promise((resolve18) => setTimeout(resolve18, Math.min(POOL_LOCK_DEFAULTS.retryMs, remaining)));
|
|
32455
32548
|
}
|
|
32456
32549
|
}
|
|
32457
32550
|
async function run(job, request2) {
|
|
@@ -33869,13 +33962,13 @@ function createPublisher() {
|
|
|
33869
33962
|
pending.set(key, batch);
|
|
33870
33963
|
let stopWaiting = () => {};
|
|
33871
33964
|
const result = run(async () => {
|
|
33872
|
-
await new Promise((
|
|
33965
|
+
await new Promise((resolve18) => setTimeout(resolve18, 0));
|
|
33873
33966
|
stopWaiting();
|
|
33874
33967
|
signal?.throwIfAborted();
|
|
33875
33968
|
pending.delete(key);
|
|
33876
33969
|
return write(batch.patch);
|
|
33877
33970
|
});
|
|
33878
|
-
batch.result = signal ? new Promise((
|
|
33971
|
+
batch.result = signal ? new Promise((resolve18, reject) => {
|
|
33879
33972
|
const abort = () => {
|
|
33880
33973
|
if (pending.get(key) === batch)
|
|
33881
33974
|
pending.delete(key);
|
|
@@ -33883,7 +33976,7 @@ function createPublisher() {
|
|
|
33883
33976
|
};
|
|
33884
33977
|
stopWaiting = () => signal.removeEventListener("abort", abort);
|
|
33885
33978
|
signal.addEventListener("abort", abort, { once: true });
|
|
33886
|
-
result.then(
|
|
33979
|
+
result.then(resolve18, reject).finally(stopWaiting);
|
|
33887
33980
|
if (signal.aborted)
|
|
33888
33981
|
abort();
|
|
33889
33982
|
}) : result;
|
|
@@ -34000,8 +34093,8 @@ async function waitForNativeUsageDrain(work) {
|
|
|
34000
34093
|
try {
|
|
34001
34094
|
await Promise.race([
|
|
34002
34095
|
work,
|
|
34003
|
-
new Promise((
|
|
34004
|
-
timer = setTimeout(
|
|
34096
|
+
new Promise((resolve18) => {
|
|
34097
|
+
timer = setTimeout(resolve18, ADVISORY_SHUTDOWN_GRACE_MS);
|
|
34005
34098
|
})
|
|
34006
34099
|
]);
|
|
34007
34100
|
} finally {
|
|
@@ -34033,7 +34126,7 @@ function createNativeUsagePublisher(channel3) {
|
|
|
34033
34126
|
hasPending: () => pending.size > 0,
|
|
34034
34127
|
observe: observe2,
|
|
34035
34128
|
publish(write) {
|
|
34036
|
-
observe2(new Promise((
|
|
34129
|
+
observe2(new Promise((resolve18) => setTimeout(resolve18, 0)).then(() => write(shutdown.signal)));
|
|
34037
34130
|
},
|
|
34038
34131
|
drain,
|
|
34039
34132
|
close() {
|
|
@@ -34154,7 +34247,7 @@ class NativeQuotaObservations extends Map {
|
|
|
34154
34247
|
}
|
|
34155
34248
|
|
|
34156
34249
|
// src/native-runtime-registry.ts
|
|
34157
|
-
import { resolve as
|
|
34250
|
+
import { resolve as resolve18 } from "node:path";
|
|
34158
34251
|
var identities = new WeakMap;
|
|
34159
34252
|
var nextIdentity = 0;
|
|
34160
34253
|
function nativeRuntimeOptionIdentity(value) {
|
|
@@ -34184,14 +34277,14 @@ function nativeRuntimeStorageKey(options) {
|
|
|
34184
34277
|
"runtime",
|
|
34185
34278
|
"journal",
|
|
34186
34279
|
"roster"
|
|
34187
|
-
].map((field) =>
|
|
34188
|
-
|
|
34189
|
-
|
|
34190
|
-
|
|
34280
|
+
].map((field) => resolve18(paths[field])),
|
|
34281
|
+
resolve18(enrollment.tokenPath),
|
|
34282
|
+
resolve18(enrollment.statePath),
|
|
34283
|
+
resolve18(connection)
|
|
34191
34284
|
]);
|
|
34192
34285
|
}
|
|
34193
34286
|
function nativeRuntimeConnectionFile(host, env) {
|
|
34194
|
-
return
|
|
34287
|
+
return resolve18(resolveClaustrumConnectionPath(host === "pi" ? env.PI_ANTHROPIC_AUTH_CLAUSTRUM_CONNECTION_FILE : undefined, host === "pi" ? {
|
|
34195
34288
|
...env,
|
|
34196
34289
|
OPENCODE_ANTHROPIC_AUTH_CLAUSTRUM_CONNECTION_FILE: undefined
|
|
34197
34290
|
} : env));
|
|
@@ -34234,7 +34327,7 @@ class NativeRuntimeRegistry {
|
|
|
34234
34327
|
import { isDeepStrictEqual as isDeepStrictEqual4 } from "node:util";
|
|
34235
34328
|
|
|
34236
34329
|
// src/settings-definition.ts
|
|
34237
|
-
import { resolve as
|
|
34330
|
+
import { resolve as resolve19 } from "node:path";
|
|
34238
34331
|
var user = { hosts: "both", project: "user-only" };
|
|
34239
34332
|
var host = { ...user, overrides: { host: true } };
|
|
34240
34333
|
var model = { ...user, overrides: { host: true, model: true } };
|
|
@@ -34506,16 +34599,22 @@ var SETTINGS_THREE_WAY_READERS = {
|
|
|
34506
34599
|
]
|
|
34507
34600
|
};
|
|
34508
34601
|
function malformedSettingsText(file) {
|
|
34509
|
-
return `Cannot write settings to "${
|
|
34602
|
+
return `Cannot write settings to "${resolve19(file)}": the settings file is malformed or contains duplicate keys. Edit the file to fix it before trying again.`;
|
|
34510
34603
|
}
|
|
34511
34604
|
function refusedSettingsWriteText(key, file) {
|
|
34512
|
-
return `Cannot remove setting "${key}" from "${
|
|
34605
|
+
return `Cannot remove setting "${key}" from "${resolve19(file)}": a lower level would still supply a value. Edit the settings file to set the value you want.`;
|
|
34513
34606
|
}
|
|
34514
34607
|
function refusedSettingsRecreationText(file) {
|
|
34515
|
-
return `Cannot recreate settings file "${
|
|
34608
|
+
return `Cannot recreate settings file "${resolve19(file)}": protection settings are unknown. Edit the settings file to set them before trying again.`;
|
|
34516
34609
|
}
|
|
34517
34610
|
function invalidSettingsWriteText(key, file) {
|
|
34518
|
-
return `Cannot write setting "${key}" to "${
|
|
34611
|
+
return `Cannot write setting "${key}" to "${resolve19(file)}": the existing value is invalid. Edit the settings file to set a valid value.`;
|
|
34612
|
+
}
|
|
34613
|
+
function settingsCheckPendingText(file) {
|
|
34614
|
+
return `Settings were not changed: ${file ? `the settings file "${resolve19(file)}"` : "the settings file"} is still being checked against this host's settings. Try again shortly.`;
|
|
34615
|
+
}
|
|
34616
|
+
function settingsFileUnusableText(problem, file) {
|
|
34617
|
+
return `Settings were not changed: ${file ? `the settings file "${resolve19(file)}"` : "the settings file"} ${problem}. Fix the file to change settings.`;
|
|
34519
34618
|
}
|
|
34520
34619
|
var SETTINGS_WRITE_FAILURES = {
|
|
34521
34620
|
"settings-unparseable": {
|
|
@@ -34524,25 +34623,25 @@ var SETTINGS_WRITE_FAILURES = {
|
|
|
34524
34623
|
},
|
|
34525
34624
|
"settings-newer-version": {
|
|
34526
34625
|
outcome: "refused",
|
|
34527
|
-
text: (file) => `Cannot write settings to "${
|
|
34626
|
+
text: (file) => `Cannot write settings to "${resolve19(file)}": the file uses a newer settings version. Update the plugin or edit the settings file before trying again.`
|
|
34528
34627
|
},
|
|
34529
34628
|
"settings-invalid-value": {
|
|
34530
34629
|
outcome: "refused",
|
|
34531
|
-
text: (file) => `Cannot write settings to "${
|
|
34630
|
+
text: (file) => `Cannot write settings to "${resolve19(file)}": the requested setting value is invalid. Edit the settings file to set a valid value.`
|
|
34532
34631
|
},
|
|
34533
34632
|
"settings-busy": {
|
|
34534
34633
|
outcome: "failed",
|
|
34535
|
-
text: (file) => `Could not write settings to "${
|
|
34634
|
+
text: (file) => `Could not write settings to "${resolve19(file)}": the settings file is busy. Try again after the other settings write finishes.`
|
|
34536
34635
|
},
|
|
34537
34636
|
"settings-unavailable": {
|
|
34538
34637
|
outcome: "failed",
|
|
34539
|
-
text: (file) => `Could not write settings to "${
|
|
34638
|
+
text: (file) => `Could not write settings to "${resolve19(file)}": the settings file is unavailable. Check its folder and permissions before trying again.`
|
|
34540
34639
|
}
|
|
34541
34640
|
};
|
|
34542
34641
|
|
|
34543
34642
|
// src/settings-service.ts
|
|
34544
34643
|
import { readFile as readFile16 } from "node:fs/promises";
|
|
34545
|
-
import { resolve as
|
|
34644
|
+
import { resolve as resolve20 } from "node:path";
|
|
34546
34645
|
import { parse as parse4 } from "jsonc-parser";
|
|
34547
34646
|
|
|
34548
34647
|
// src/settings-protection-copy.ts
|
|
@@ -34591,12 +34690,23 @@ async function readCopy(file) {
|
|
|
34591
34690
|
return record13(copy) ? copy : {};
|
|
34592
34691
|
}
|
|
34593
34692
|
async function readSettingsProtectionCopy(file, host2) {
|
|
34693
|
+
let text5;
|
|
34594
34694
|
try {
|
|
34595
|
-
|
|
34596
|
-
|
|
34597
|
-
|
|
34598
|
-
|
|
34695
|
+
text5 = await readFile15(`${file}.applied.json`, "utf8");
|
|
34696
|
+
} catch (error) {
|
|
34697
|
+
if (error.code === "ENOENT")
|
|
34698
|
+
return;
|
|
34699
|
+
throw error;
|
|
34599
34700
|
}
|
|
34701
|
+
const copy = JSON.parse(text5);
|
|
34702
|
+
if (!record13(copy))
|
|
34703
|
+
throw new Error("The applied protection copy is not a host map");
|
|
34704
|
+
if (!Object.hasOwn(copy, host2))
|
|
34705
|
+
return;
|
|
34706
|
+
const entry2 = copy[host2];
|
|
34707
|
+
if (!validEntry(entry2))
|
|
34708
|
+
throw new Error("The applied protection copy entry is invalid");
|
|
34709
|
+
return entry2.values;
|
|
34600
34710
|
}
|
|
34601
34711
|
async function writeSettingsProtectionCopy(file, host2, entry2, lockTimeoutMs = 5000, publicationOptions = {}) {
|
|
34602
34712
|
if (!validEntry(entry2))
|
|
@@ -34660,6 +34770,15 @@ class SettingsRecreationRefusal extends Error {
|
|
|
34660
34770
|
this.name = "SettingsRecreationRefusal";
|
|
34661
34771
|
}
|
|
34662
34772
|
}
|
|
34773
|
+
|
|
34774
|
+
class SettingsAdoptionRefusal extends Error {
|
|
34775
|
+
file;
|
|
34776
|
+
constructor(file) {
|
|
34777
|
+
super(settingsCheckPendingText(file));
|
|
34778
|
+
this.file = file;
|
|
34779
|
+
this.name = "SettingsAdoptionRefusal";
|
|
34780
|
+
}
|
|
34781
|
+
}
|
|
34663
34782
|
var keys4 = Object.keys(settingsDefinition.settings);
|
|
34664
34783
|
var hosts = ["opencode", "pi"];
|
|
34665
34784
|
var modelIds = new Set(CLAUDE_MODEL_CAPABILITIES.map((row) => row.id));
|
|
@@ -34691,7 +34810,7 @@ function fileObject(source2) {
|
|
|
34691
34810
|
const raw = parse4(text5, errors, { allowTrailingComma: true });
|
|
34692
34811
|
return !errors.length && raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
|
|
34693
34812
|
}
|
|
34694
|
-
function
|
|
34813
|
+
function settingsFileLevels(raw) {
|
|
34695
34814
|
return Object.fromEntries(keys4.filter((key) => Object.hasOwn(raw, key)).map((key) => {
|
|
34696
34815
|
const declaration = settingsDefinition.settings[key];
|
|
34697
34816
|
const value = raw[key];
|
|
@@ -34770,19 +34889,34 @@ function settingsRecreationFloors(values, host2) {
|
|
|
34770
34889
|
const floors = edits.find((edit) => edit.setting === "killswitch_account_floors")?.value;
|
|
34771
34890
|
return floors ?? [];
|
|
34772
34891
|
}
|
|
34773
|
-
function planSettingsFileRecreation(writer, peer
|
|
34892
|
+
function planSettingsFileRecreation(writer, peer) {
|
|
34774
34893
|
if (writer.rung === 3)
|
|
34775
34894
|
return { refused: "own-unknown" };
|
|
34776
|
-
if (peer.none
|
|
34895
|
+
if (peer.none)
|
|
34777
34896
|
return { edits: settingsRecreationForWriter(writer.values, writer.host) };
|
|
34778
|
-
|
|
34779
|
-
|
|
34780
|
-
|
|
34781
|
-
return { edits: plan.edits };
|
|
34897
|
+
if (peer.rung === 3)
|
|
34898
|
+
return { refused: "peer-unknown" };
|
|
34899
|
+
return { edits: planSettingsRecreation(writer, peer).edits };
|
|
34782
34900
|
}
|
|
34783
34901
|
function planSettingsMenuWrite(current, edits, carry) {
|
|
34784
34902
|
return current.status === "missing" ? [...carry(), ...edits] : edits;
|
|
34785
34903
|
}
|
|
34904
|
+
function settingsFileProblem(generation, host2) {
|
|
34905
|
+
if (generation.status === "missing")
|
|
34906
|
+
return;
|
|
34907
|
+
if (generation.status === "unparseable")
|
|
34908
|
+
return "can't be parsed";
|
|
34909
|
+
if (generation.status === "unreadable")
|
|
34910
|
+
return "can't be read";
|
|
34911
|
+
if (generation.protection[host2].usable)
|
|
34912
|
+
return;
|
|
34913
|
+
if (generation.source !== undefined && /^[\x20\t\r\n]*$/.test(generation.source.replace(/^\uFEFF/, "")))
|
|
34914
|
+
return "is empty";
|
|
34915
|
+
const invalid3 = generation.report.find((entry2) => SETTINGS_PROTECTION_KEYS.some((key) => key === entry2.keyPath[0]));
|
|
34916
|
+
if (invalid3)
|
|
34917
|
+
return `has an invalid value for ${invalid3.keyPath[0]}`;
|
|
34918
|
+
return "is from a newer or unknown settings version";
|
|
34919
|
+
}
|
|
34786
34920
|
function mostRestrictiveSettingsProtection() {
|
|
34787
34921
|
return {
|
|
34788
34922
|
...protection(defaults2()),
|
|
@@ -34884,6 +35018,9 @@ class SharedSettingsService {
|
|
|
34884
35018
|
lastGoodProtection(host2) {
|
|
34885
35019
|
return this.lastGood.get(host2);
|
|
34886
35020
|
}
|
|
35021
|
+
recordLastGood(host2, values) {
|
|
35022
|
+
this.lastGood.set(host2, values);
|
|
35023
|
+
}
|
|
34887
35024
|
watch(listener) {
|
|
34888
35025
|
this.listeners.add(listener);
|
|
34889
35026
|
return () => {
|
|
@@ -35046,7 +35183,7 @@ class SharedSettingsService {
|
|
|
35046
35183
|
candidate: {
|
|
35047
35184
|
file: this.file,
|
|
35048
35185
|
source: source2,
|
|
35049
|
-
fileLevels:
|
|
35186
|
+
fileLevels: settingsFileLevels(raw),
|
|
35050
35187
|
status,
|
|
35051
35188
|
contexts,
|
|
35052
35189
|
report: report2,
|
|
@@ -35171,10 +35308,6 @@ class SharedSettingsService {
|
|
|
35171
35308
|
id: (prior?.id ?? 0) + 1
|
|
35172
35309
|
});
|
|
35173
35310
|
this.current = generation;
|
|
35174
|
-
for (const host2 of hosts) {
|
|
35175
|
-
if (generation.protection[host2].usable)
|
|
35176
|
-
this.lastGood.set(host2, generation.protection[host2].values);
|
|
35177
|
-
}
|
|
35178
35311
|
logReports(generation.report);
|
|
35179
35312
|
for (const listener of this.listeners) {
|
|
35180
35313
|
if (this.closed)
|
|
@@ -35191,37 +35324,43 @@ class SharedSettingsService {
|
|
|
35191
35324
|
}
|
|
35192
35325
|
}
|
|
35193
35326
|
}
|
|
35194
|
-
async update(edits, host2, options, applied, peerProtection = async () => ({
|
|
35327
|
+
async update(edits, host2, options, applied, mayChangeFile, peerProtection = async () => ({
|
|
35195
35328
|
values: mostRestrictiveSettingsProtection(),
|
|
35196
35329
|
rung: 3
|
|
35197
35330
|
})) {
|
|
35198
|
-
if (!edits.length)
|
|
35331
|
+
if (typeof edits !== "function" && !edits.length)
|
|
35199
35332
|
return { outcome: "unchanged" };
|
|
35200
|
-
const
|
|
35333
|
+
const peer = host2 === "opencode" ? "pi" : "opencode";
|
|
35334
|
+
const other = options.createMissing ? await peerProtection(peer) : undefined;
|
|
35201
35335
|
let carried;
|
|
35202
|
-
if (missing2 && options.createMissing) {
|
|
35203
|
-
if (applied.rung === 3)
|
|
35204
|
-
throw new SettingsRecreationRefusal(this.file);
|
|
35205
|
-
const peer = host2 === "opencode" ? "pi" : "opencode";
|
|
35206
|
-
const floorEdit = edits.find((edit) => edit.setting === "killswitch_account_floors" && ("value" in edit));
|
|
35207
|
-
const writerValues = floorEdit && "value" in floorEdit ? {
|
|
35208
|
-
...applied.values,
|
|
35209
|
-
killswitch_account_floors: floorEdit.value
|
|
35210
|
-
} : applied.values;
|
|
35211
|
-
const plan = planSettingsFileRecreation({ host: host2, values: writerValues, rung: applied.rung }, { host: peer, ...await peerProtection(peer) }, options.hostsStopped);
|
|
35212
|
-
if ("refused" in plan)
|
|
35213
|
-
throw new SettingsRecreationRefusal(this.file);
|
|
35214
|
-
carried = Object.fromEntries(plan.edits.map((edit) => [edit.setting, edit.value]));
|
|
35215
|
-
edits = planSettingsMenuWrite({ status: "missing" }, edits.filter((edit) => edit !== floorEdit), () => plan.edits.map(({ setting, value }) => ({ setting, value })));
|
|
35216
|
-
}
|
|
35217
|
-
if (options.createMissing || options.expectedSource !== undefined || options.expectMissing) {
|
|
35218
|
-
const now = await this.bytes();
|
|
35219
|
-
const changed2 = options.expectedSource !== undefined ? now.status !== "ready" || now.bytes.toString("utf8") !== options.expectedSource : options.expectMissing ? now.status !== "missing" : now.status === "missing" !== missing2;
|
|
35220
|
-
if (changed2)
|
|
35221
|
-
throw new SettingsRefusal("settings-busy", "Settings changed while the write was planned");
|
|
35222
|
-
}
|
|
35223
35336
|
const handle = options.createMissing ? this.options.dependencies?.open?.(this.openOptions(true)) ?? openSettings(settingsDefinition, this.openOptions(true)) : this.handle;
|
|
35224
|
-
const result = await handle.update(
|
|
35337
|
+
const result = await handle.update((current) => {
|
|
35338
|
+
if (current.status !== "missing" && !options.importing && !mayChangeFile())
|
|
35339
|
+
throw new SettingsAdoptionRefusal(this.file);
|
|
35340
|
+
let carry;
|
|
35341
|
+
if (current.status === "missing") {
|
|
35342
|
+
const plan = planSettingsFileRecreation({ host: host2, values: applied.values, rung: applied.rung }, {
|
|
35343
|
+
host: peer,
|
|
35344
|
+
...other ?? {
|
|
35345
|
+
values: mostRestrictiveSettingsProtection(),
|
|
35346
|
+
rung: 3
|
|
35347
|
+
}
|
|
35348
|
+
});
|
|
35349
|
+
if ("refused" in plan)
|
|
35350
|
+
throw new SettingsRecreationRefusal(this.file);
|
|
35351
|
+
carry = plan.edits;
|
|
35352
|
+
carried = {};
|
|
35353
|
+
for (const edit of carry) {
|
|
35354
|
+
if (edit.level) {
|
|
35355
|
+
const levels = carried[edit.setting];
|
|
35356
|
+
carried[edit.setting] = { ...levels, [edit.level]: edit.value };
|
|
35357
|
+
} else
|
|
35358
|
+
carried[edit.setting] = edit.value;
|
|
35359
|
+
}
|
|
35360
|
+
}
|
|
35361
|
+
const menu = typeof edits === "function" ? edits(current, carry) : edits;
|
|
35362
|
+
return carry ? [...carry, ...menu] : menu;
|
|
35363
|
+
}, { host: host2 });
|
|
35225
35364
|
if (carried && result.outcome === "updated") {
|
|
35226
35365
|
recreatedFiles.add(this.file);
|
|
35227
35366
|
const identity5 = `recreated:${this.file}`;
|
|
@@ -35272,11 +35411,38 @@ class SettingsProtectionLease {
|
|
|
35272
35411
|
unsaved;
|
|
35273
35412
|
cancelRetry;
|
|
35274
35413
|
closed = false;
|
|
35414
|
+
sawAdoption = false;
|
|
35275
35415
|
constructor(shared, recovery = {}, options) {
|
|
35276
35416
|
this.shared = shared;
|
|
35277
35417
|
this.recovery = recovery;
|
|
35278
35418
|
this.options = options;
|
|
35279
35419
|
}
|
|
35420
|
+
adopted() {
|
|
35421
|
+
return this.options?.adopted?.() ?? false;
|
|
35422
|
+
}
|
|
35423
|
+
mayChangeFile() {
|
|
35424
|
+
return !this.options?.host || this.adopted();
|
|
35425
|
+
}
|
|
35426
|
+
noteAdoption() {
|
|
35427
|
+
if (!this.current || !this.options?.host || !this.adopted())
|
|
35428
|
+
return;
|
|
35429
|
+
this.recordLastGood(this.current);
|
|
35430
|
+
this.persist(this.current);
|
|
35431
|
+
}
|
|
35432
|
+
recordLastGood(generation) {
|
|
35433
|
+
const host2 = this.options?.host;
|
|
35434
|
+
if (!host2 || !this.adopted())
|
|
35435
|
+
return;
|
|
35436
|
+
if (!this.sawAdoption) {
|
|
35437
|
+
this.sawAdoption = true;
|
|
35438
|
+
const adopted = this.current?.protection[host2];
|
|
35439
|
+
if (adopted?.usable && adopted.rung === 0)
|
|
35440
|
+
this.shared.recordLastGood(host2, adopted.values);
|
|
35441
|
+
}
|
|
35442
|
+
const set = generation.protection[host2];
|
|
35443
|
+
if (set.usable && set.rung === 0)
|
|
35444
|
+
this.shared.recordLastGood(host2, set.values);
|
|
35445
|
+
}
|
|
35280
35446
|
async close() {
|
|
35281
35447
|
this.closed = true;
|
|
35282
35448
|
this.cancelRetry?.();
|
|
@@ -35286,7 +35452,7 @@ class SettingsProtectionLease {
|
|
|
35286
35452
|
}
|
|
35287
35453
|
persist(generation) {
|
|
35288
35454
|
const host2 = this.options?.host;
|
|
35289
|
-
if (!host2 || this.closed)
|
|
35455
|
+
if (!host2 || this.closed || !this.adopted())
|
|
35290
35456
|
return;
|
|
35291
35457
|
const set = generation.protection[host2];
|
|
35292
35458
|
if (!set.usable || set.rung !== 0)
|
|
@@ -35363,28 +35529,30 @@ class SettingsProtectionLease {
|
|
|
35363
35529
|
const good = this.shared.lastGoodProtection(host2);
|
|
35364
35530
|
if (good)
|
|
35365
35531
|
return { values: good, rung: 1 };
|
|
35366
|
-
|
|
35367
|
-
for (const [rung, read] of [
|
|
35368
|
-
[
|
|
35369
|
-
1,
|
|
35370
|
-
this.recovery.readAppliedCopy ?? ((peer) => readSettingsProtectionCopy(this.shared.file, peer))
|
|
35371
|
-
],
|
|
35372
|
-
[2, this.recovery.readPeerLegacyProtection]
|
|
35373
|
-
]) {
|
|
35374
|
-
try {
|
|
35375
|
-
const values = await read?.(host2);
|
|
35376
|
-
if (values)
|
|
35377
|
-
return { values, rung };
|
|
35378
|
-
} catch {
|
|
35379
|
-
unreadable = true;
|
|
35380
|
-
}
|
|
35381
|
-
}
|
|
35382
|
-
return {
|
|
35532
|
+
const unknown = (unreadable) => ({
|
|
35383
35533
|
values: mostRestrictiveSettingsProtection(),
|
|
35384
35534
|
rung: 3,
|
|
35385
|
-
unreadable
|
|
35386
|
-
|
|
35387
|
-
|
|
35535
|
+
unreadable
|
|
35536
|
+
});
|
|
35537
|
+
const readCopy2 = this.recovery.readAppliedCopy ?? ((peer) => readSettingsProtectionCopy(this.shared.file, peer));
|
|
35538
|
+
try {
|
|
35539
|
+
const values = await readCopy2(host2);
|
|
35540
|
+
if (values)
|
|
35541
|
+
return { values, rung: 1 };
|
|
35542
|
+
} catch {
|
|
35543
|
+
return unknown(true);
|
|
35544
|
+
}
|
|
35545
|
+
const readLegacy = this.recovery.readPeerLegacyProtection;
|
|
35546
|
+
if (!readLegacy)
|
|
35547
|
+
return unknown(false);
|
|
35548
|
+
try {
|
|
35549
|
+
const values = await readLegacy(host2);
|
|
35550
|
+
if (values)
|
|
35551
|
+
return { values, rung: 2 };
|
|
35552
|
+
} catch {
|
|
35553
|
+
return unknown(true);
|
|
35554
|
+
}
|
|
35555
|
+
return { ...unknown(false), none: true };
|
|
35388
35556
|
}
|
|
35389
35557
|
async logMissing(generation) {
|
|
35390
35558
|
const host2 = this.options?.host;
|
|
@@ -35399,21 +35567,26 @@ class SettingsProtectionLease {
|
|
|
35399
35567
|
logged.add(key);
|
|
35400
35568
|
const next = "refused" in plan ? `Menu writes that change settings are refused until the file is recreated by hand, because ${{
|
|
35401
35569
|
"own-unknown": `${host2}'s protection settings could not be recovered`,
|
|
35402
|
-
"peer-unknown": `the protection settings of ${peer} are unknown
|
|
35403
|
-
"peer-differs": `${peer} applies different protection settings`
|
|
35570
|
+
"peer-unknown": `the protection settings of ${peer} are unknown`
|
|
35404
35571
|
}[plan.refused]}.` : "A menu write will recreate it.";
|
|
35405
35572
|
logger2.warn("settings", `Settings file is missing at "${generation.file}"; non-protection settings use schema defaults. ${next}`);
|
|
35406
35573
|
}
|
|
35407
35574
|
async recover(host2) {
|
|
35408
|
-
const
|
|
35409
|
-
if (
|
|
35410
|
-
|
|
35411
|
-
|
|
35412
|
-
|
|
35413
|
-
|
|
35575
|
+
const own = host2 === this.options?.host;
|
|
35576
|
+
if (!own || this.adopted()) {
|
|
35577
|
+
const good = this.shared.lastGoodProtection(host2);
|
|
35578
|
+
if (good)
|
|
35579
|
+
return { values: good, rung: 1 };
|
|
35580
|
+
}
|
|
35581
|
+
if (own && this.adopted()) {
|
|
35582
|
+
const previous = this.current?.protection[host2];
|
|
35583
|
+
if (previous)
|
|
35584
|
+
return previous.rung === 0 ? { values: previous.values, rung: 1 } : previous;
|
|
35585
|
+
}
|
|
35414
35586
|
return recoverSettingsProtection(this.shared.file, host2, this.recovery, this.options?.host);
|
|
35415
35587
|
}
|
|
35416
35588
|
async apply(generation) {
|
|
35589
|
+
this.recordLastGood(generation);
|
|
35417
35590
|
if (hosts.every((host2) => generation.protection[host2].usable)) {
|
|
35418
35591
|
this.current = generation;
|
|
35419
35592
|
this.persist(generation);
|
|
@@ -35465,6 +35638,7 @@ function referenceCountedSettingsService(service) {
|
|
|
35465
35638
|
status: () => use().status(),
|
|
35466
35639
|
refresh: () => use().refresh(),
|
|
35467
35640
|
update: (edits, host2, options) => use().update(edits, host2, options),
|
|
35641
|
+
noteAdoption: () => use().noteAdoption?.(),
|
|
35468
35642
|
watch(listener) {
|
|
35469
35643
|
const unsubscribe = use().watch(listener);
|
|
35470
35644
|
const stop = () => {
|
|
@@ -35500,7 +35674,7 @@ function referenceCountedSettingsService(service) {
|
|
|
35500
35674
|
async function openSettingsService(options) {
|
|
35501
35675
|
if (options.separateInstall)
|
|
35502
35676
|
return;
|
|
35503
|
-
const file =
|
|
35677
|
+
const file = resolve20(options.file);
|
|
35504
35678
|
let shared = services.get(file);
|
|
35505
35679
|
if (!shared) {
|
|
35506
35680
|
shared = new SharedSettingsService(file, options);
|
|
@@ -35580,7 +35754,11 @@ async function openSettingsService(options) {
|
|
|
35580
35754
|
return stop;
|
|
35581
35755
|
},
|
|
35582
35756
|
refresh: () => use().refresh(),
|
|
35583
|
-
update: (edits, host2, options2 = {}) => use().update(edits, host2, options2, lease.snapshot().protection[host2], (peer) => lease.peerProtection(peer)),
|
|
35757
|
+
update: (edits, host2, options2 = {}) => use().update(edits, host2, options2, lease.snapshot().protection[host2], () => lease.mayChangeFile(), (peer) => lease.peerProtection(peer)),
|
|
35758
|
+
noteAdoption() {
|
|
35759
|
+
use();
|
|
35760
|
+
lease.noteAdoption();
|
|
35761
|
+
},
|
|
35584
35762
|
dispose
|
|
35585
35763
|
});
|
|
35586
35764
|
}
|
|
@@ -35896,6 +36074,20 @@ async function resolveSettingsMode(paths, options = {}) {
|
|
|
35896
36074
|
return "user-file";
|
|
35897
36075
|
return await hasSettingsMoveMarker(paths.target, options) ? "user-file" : "legacy";
|
|
35898
36076
|
}
|
|
36077
|
+
var adoptionChecks = new WeakMap;
|
|
36078
|
+
function setSettingsAdoptionCheck(service, check) {
|
|
36079
|
+
adoptionChecks.set(service, check);
|
|
36080
|
+
}
|
|
36081
|
+
function getSettingsAdoptionCheck(service) {
|
|
36082
|
+
return service ? adoptionChecks.get(service) : undefined;
|
|
36083
|
+
}
|
|
36084
|
+
var pendingImports = new WeakSet;
|
|
36085
|
+
function markSettingsImportPending(service) {
|
|
36086
|
+
pendingImports.add(service);
|
|
36087
|
+
}
|
|
36088
|
+
function isSettingsImportPending(service) {
|
|
36089
|
+
return service ? pendingImports.has(service) : false;
|
|
36090
|
+
}
|
|
35899
36091
|
|
|
35900
36092
|
// src/settings-record.ts
|
|
35901
36093
|
function settingsFileSets(generation, key, host2, model2) {
|
|
@@ -36033,9 +36225,12 @@ function resolveSettingsRecord(stored, generation, host2, model2) {
|
|
|
36033
36225
|
// src/native-runtime-settings.ts
|
|
36034
36226
|
function createNativeRuntimeSettings(options) {
|
|
36035
36227
|
const env = options.env ?? process.env;
|
|
36228
|
+
let adoption = getSettingsAdoptionCheck(options.settingsService);
|
|
36229
|
+
const startedPending = isSettingsImportPending(options.settingsService);
|
|
36036
36230
|
let service = options.settingsService?.retain();
|
|
36037
36231
|
let fallback = service ? undefined : options.settingsFallback;
|
|
36038
36232
|
let reopenLegacy = service || fallback ? undefined : options.settingsReopen;
|
|
36233
|
+
const quickRetries = [...reopenLegacy?.retryDelaysMs ?? []];
|
|
36039
36234
|
let probedMode;
|
|
36040
36235
|
const mode = () => probedMode ?? options.settingsMode?.() ?? "user-file";
|
|
36041
36236
|
let effects;
|
|
@@ -36045,8 +36240,20 @@ function createNativeRuntimeSettings(options) {
|
|
|
36045
36240
|
let cancelCheck;
|
|
36046
36241
|
let loggedLateWrite = false;
|
|
36047
36242
|
let writes = 0;
|
|
36048
|
-
|
|
36049
|
-
|
|
36243
|
+
let importPending = startedPending;
|
|
36244
|
+
let pinned;
|
|
36245
|
+
const generation = () => {
|
|
36246
|
+
if (!service || !(userAuthority || mode() === "user-file") || mode() === "separate")
|
|
36247
|
+
return;
|
|
36248
|
+
const current = service.snapshot();
|
|
36249
|
+
if (!importPending)
|
|
36250
|
+
return current;
|
|
36251
|
+
if (current.status === "missing")
|
|
36252
|
+
pinned = current;
|
|
36253
|
+
return pinned;
|
|
36254
|
+
};
|
|
36255
|
+
const heldByCheck = () => importPending && generation() !== undefined && service?.snapshot().status !== "missing";
|
|
36256
|
+
function resolve21(stored, model2) {
|
|
36050
36257
|
if (fallback && mode() !== "separate")
|
|
36051
36258
|
return overlaySettingsProtection(stored, fallback.values, options.host);
|
|
36052
36259
|
return resolveSettingsRecord(stored, generation(), options.host, model2);
|
|
@@ -36054,7 +36261,7 @@ function createNativeRuntimeSettings(options) {
|
|
|
36054
36261
|
function applyEffects() {
|
|
36055
36262
|
if (!generation())
|
|
36056
36263
|
return;
|
|
36057
|
-
const settings =
|
|
36264
|
+
const settings = resolve21({ version: 1, accounts: [] });
|
|
36058
36265
|
const next = captureNativeSettingsEffectFields(settings);
|
|
36059
36266
|
const level = parseLogLevel(next.logLevel) ?? parseLogLevel(env.OPENCODE_ANTHROPIC_AUTH_LOG_LEVEL) ?? "info";
|
|
36060
36267
|
const committed = { ...settings, logging: { level } };
|
|
@@ -36092,16 +36299,27 @@ function createNativeRuntimeSettings(options) {
|
|
|
36092
36299
|
return checking;
|
|
36093
36300
|
if (closed2 || !service || mode() === "separate")
|
|
36094
36301
|
return Promise.resolve();
|
|
36302
|
+
const current = service;
|
|
36095
36303
|
checking = (async () => {
|
|
36096
|
-
if (userAuthority)
|
|
36304
|
+
if (userAuthority && !importPending)
|
|
36097
36305
|
return;
|
|
36098
|
-
if (await resolveSettingsMode({ target:
|
|
36306
|
+
if (!userAuthority && await resolveSettingsMode({ target: current.file, separate: mode() === "separate" }, options.settingsAuthority?.options) !== "user-file")
|
|
36099
36307
|
return;
|
|
36100
36308
|
if (refresh)
|
|
36101
|
-
await
|
|
36309
|
+
await current.refresh();
|
|
36310
|
+
const adopted = adoption ? await adoption(current) : true;
|
|
36311
|
+
if (!adopted)
|
|
36312
|
+
return;
|
|
36313
|
+
if (closed2 || service !== current)
|
|
36314
|
+
return;
|
|
36315
|
+
importPending = adopted === "pending";
|
|
36316
|
+
if (!importPending)
|
|
36317
|
+
pinned = undefined;
|
|
36102
36318
|
userAuthority = true;
|
|
36103
|
-
|
|
36104
|
-
|
|
36319
|
+
if (!importPending) {
|
|
36320
|
+
cancelCheck?.();
|
|
36321
|
+
cancelCheck = undefined;
|
|
36322
|
+
}
|
|
36105
36323
|
if (!writes)
|
|
36106
36324
|
applyEffects();
|
|
36107
36325
|
})().finally(() => {
|
|
@@ -36122,21 +36340,31 @@ function createNativeRuntimeSettings(options) {
|
|
|
36122
36340
|
userAuthority = false;
|
|
36123
36341
|
fallback = undefined;
|
|
36124
36342
|
if (found === "legacy")
|
|
36125
|
-
reopenLegacy = current.reopen;
|
|
36343
|
+
reopenLegacy = current.reopenLegacy ?? current.reopen;
|
|
36126
36344
|
}
|
|
36127
36345
|
}
|
|
36128
36346
|
const before = fallback;
|
|
36129
|
-
const
|
|
36347
|
+
const legacy = before ? undefined : reopenLegacy;
|
|
36348
|
+
const open13 = before?.reopen ?? legacy;
|
|
36130
36349
|
if (!open13)
|
|
36131
36350
|
return;
|
|
36132
36351
|
const next = await open13();
|
|
36133
|
-
if (!next)
|
|
36352
|
+
if (!next) {
|
|
36353
|
+
if (legacy && reopenLegacy === legacy && legacy.separate?.()) {
|
|
36354
|
+
probedMode = "separate";
|
|
36355
|
+
reopenLegacy = undefined;
|
|
36356
|
+
userAuthority = false;
|
|
36357
|
+
}
|
|
36134
36358
|
return;
|
|
36359
|
+
}
|
|
36135
36360
|
if (closed2 || service || fallback !== before) {
|
|
36136
36361
|
await next.dispose();
|
|
36137
36362
|
return;
|
|
36138
36363
|
}
|
|
36139
36364
|
service = next;
|
|
36365
|
+
adoption = getSettingsAdoptionCheck(next);
|
|
36366
|
+
importPending = before?.importPending?.() ?? false;
|
|
36367
|
+
pinned = undefined;
|
|
36140
36368
|
fallback = undefined;
|
|
36141
36369
|
reopenLegacy = undefined;
|
|
36142
36370
|
subscribe(next);
|
|
@@ -36146,13 +36374,14 @@ function createNativeRuntimeSettings(options) {
|
|
|
36146
36374
|
function scheduleCheck() {
|
|
36147
36375
|
if (closed2 || mode() === "separate")
|
|
36148
36376
|
return;
|
|
36149
|
-
if (!fallback && !reopenLegacy && (!service || userAuthority))
|
|
36377
|
+
if (!fallback && !reopenLegacy && (!service || userAuthority && !importPending))
|
|
36150
36378
|
return;
|
|
36151
|
-
const schedule2 = options.settingsAuthority?.schedule ?? ((callback,
|
|
36152
|
-
const timer = setTimeout(() => void callback(),
|
|
36379
|
+
const schedule2 = options.settingsAuthority?.schedule ?? ((callback, delayMs2) => {
|
|
36380
|
+
const timer = setTimeout(() => void callback(), delayMs2);
|
|
36153
36381
|
timer.unref?.();
|
|
36154
36382
|
return () => clearTimeout(timer);
|
|
36155
36383
|
});
|
|
36384
|
+
const delayMs = !service && quickRetries.shift() || 60000;
|
|
36156
36385
|
cancelCheck = schedule2(async () => {
|
|
36157
36386
|
cancelCheck = undefined;
|
|
36158
36387
|
try {
|
|
@@ -36163,7 +36392,7 @@ function createNativeRuntimeSettings(options) {
|
|
|
36163
36392
|
} catch {} finally {
|
|
36164
36393
|
scheduleCheck();
|
|
36165
36394
|
}
|
|
36166
|
-
},
|
|
36395
|
+
}, delayMs);
|
|
36167
36396
|
}
|
|
36168
36397
|
let unwatch;
|
|
36169
36398
|
let unonFileEvent;
|
|
@@ -36185,7 +36414,7 @@ function createNativeRuntimeSettings(options) {
|
|
|
36185
36414
|
ready = Promise.resolve();
|
|
36186
36415
|
});
|
|
36187
36416
|
return {
|
|
36188
|
-
resolve:
|
|
36417
|
+
resolve: resolve21,
|
|
36189
36418
|
status,
|
|
36190
36419
|
applyEffects,
|
|
36191
36420
|
file: () => generation()?.file,
|
|
@@ -36195,12 +36424,19 @@ function createNativeRuntimeSettings(options) {
|
|
|
36195
36424
|
await recheck();
|
|
36196
36425
|
},
|
|
36197
36426
|
fallbackFile: () => fallback?.file,
|
|
36427
|
+
checkingFile: () => service && (!generation() || heldByCheck()) ? service.file : undefined,
|
|
36428
|
+
checkingRefusal() {
|
|
36429
|
+
const file = service?.file;
|
|
36430
|
+
const current = service?.snapshot();
|
|
36431
|
+
const problem = current && current.status !== "missing" ? settingsFileProblem(current, options.host) : undefined;
|
|
36432
|
+
return problem ? settingsFileUnusableText(problem, file) : settingsCheckPendingText(file);
|
|
36433
|
+
},
|
|
36198
36434
|
async legacyAuthorityLost() {
|
|
36199
36435
|
if (!service || mode() === "separate")
|
|
36200
36436
|
return false;
|
|
36201
36437
|
if (userAuthority)
|
|
36202
36438
|
return true;
|
|
36203
|
-
return await resolveSettingsMode({ target: service.file, separate:
|
|
36439
|
+
return await resolveSettingsMode({ target: service.file, separate: mode() === "separate" }, options.settingsAuthority?.options) === "user-file";
|
|
36204
36440
|
},
|
|
36205
36441
|
async prepareWrite() {
|
|
36206
36442
|
if (mode() === "separate")
|
|
@@ -36210,7 +36446,7 @@ function createNativeRuntimeSettings(options) {
|
|
|
36210
36446
|
return;
|
|
36211
36447
|
await ready;
|
|
36212
36448
|
await recheck();
|
|
36213
|
-
return generation() ? service : undefined;
|
|
36449
|
+
return generation() && !heldByCheck() ? service : undefined;
|
|
36214
36450
|
},
|
|
36215
36451
|
async legacyWriteCommitted(source2, stored) {
|
|
36216
36452
|
if (loggedLateWrite || !service)
|
|
@@ -36233,20 +36469,23 @@ function createNativeRuntimeSettings(options) {
|
|
|
36233
36469
|
loggedLateWrite = true;
|
|
36234
36470
|
logger2.warn("settings", settingsNotImportedText(source2, service.file, differing));
|
|
36235
36471
|
},
|
|
36236
|
-
async update(edits, before
|
|
36472
|
+
async update(edits, before) {
|
|
36237
36473
|
if (!service)
|
|
36238
36474
|
throw new Error("Settings service is not available");
|
|
36239
36475
|
writes++;
|
|
36240
36476
|
let changed2 = false;
|
|
36241
36477
|
try {
|
|
36242
36478
|
changed2 = (await service.update(edits, options.host, {
|
|
36243
|
-
createMissing: true
|
|
36244
|
-
...planned
|
|
36479
|
+
createMissing: true
|
|
36245
36480
|
})).outcome === "updated";
|
|
36246
36481
|
} finally {
|
|
36247
36482
|
writes--;
|
|
36248
36483
|
}
|
|
36249
|
-
|
|
36484
|
+
if (importPending) {
|
|
36485
|
+
await checking?.catch(() => {});
|
|
36486
|
+
await recheck(false).catch(() => {});
|
|
36487
|
+
}
|
|
36488
|
+
const next = resolve21(before);
|
|
36250
36489
|
const withLevel = (settings) => ({
|
|
36251
36490
|
...settings,
|
|
36252
36491
|
logging: {
|
|
@@ -36277,7 +36516,6 @@ function sectionLevel(settings) {
|
|
|
36277
36516
|
// src/native-settings-write.ts
|
|
36278
36517
|
import { existsSync as existsSync4 } from "node:fs";
|
|
36279
36518
|
import { isDeepStrictEqual as isDeepStrictEqual5 } from "node:util";
|
|
36280
|
-
import { parse as parse5 } from "jsonc-parser";
|
|
36281
36519
|
var paths = {
|
|
36282
36520
|
routing_mode: ["routing", "mode"],
|
|
36283
36521
|
max_same_account_wait: ["routing", "maxSameAccountWait"],
|
|
@@ -36431,7 +36669,7 @@ function planNativeSettingsWrite(before, after, generation, host2) {
|
|
|
36431
36669
|
edits,
|
|
36432
36670
|
storeChanges,
|
|
36433
36671
|
refusal: undefined,
|
|
36434
|
-
|
|
36672
|
+
update: undefined
|
|
36435
36673
|
};
|
|
36436
36674
|
if (!edits.length && !accounts.length && !storeChanges.length)
|
|
36437
36675
|
return plan;
|
|
@@ -36440,14 +36678,14 @@ function planNativeSettingsWrite(before, after, generation, host2) {
|
|
|
36440
36678
|
plan.refusal = malformedSettingsText(generation.file);
|
|
36441
36679
|
return plan;
|
|
36442
36680
|
}
|
|
36443
|
-
if (present && generation.status === "unreadable" && (accounts.length || edits.some((
|
|
36681
|
+
if (present && generation.status === "unreadable" && (accounts.length || edits.some((edit) => edit.remove))) {
|
|
36444
36682
|
plan.refusal = SETTINGS_WRITE_FAILURES["settings-unavailable"].text(generation.file);
|
|
36445
36683
|
return plan;
|
|
36446
36684
|
}
|
|
36447
|
-
for (const [index,
|
|
36448
|
-
if (!
|
|
36685
|
+
for (const [index, edit] of [...edits.entries()].reverse()) {
|
|
36686
|
+
if (!edit.remove)
|
|
36449
36687
|
continue;
|
|
36450
|
-
const key2 =
|
|
36688
|
+
const key2 = edit.setting;
|
|
36451
36689
|
const levels = present && generation.fileLevels[key2] || [];
|
|
36452
36690
|
if (levels.includes(host2) && levels.includes("default")) {
|
|
36453
36691
|
plan.refusal = refusedSettingsWriteText(key2, generation.file);
|
|
@@ -36463,17 +36701,12 @@ function planNativeSettingsWrite(before, after, generation, host2) {
|
|
|
36463
36701
|
plan.refusal = invalidSettingsWriteText(key, generation.file);
|
|
36464
36702
|
return plan;
|
|
36465
36703
|
}
|
|
36466
|
-
const
|
|
36467
|
-
|
|
36468
|
-
|
|
36469
|
-
|
|
36470
|
-
|
|
36471
|
-
|
|
36472
|
-
} : { status: "missing" }, new Map(accounts.map((account) => [account, nextAccounts.get(account)])), host2, settingsRecreationFloors(generation.protection[host2].values, host2));
|
|
36473
|
-
if (edit) {
|
|
36474
|
-
edits.push(edit);
|
|
36475
|
-
plan.floorsFrom = floorsFrom;
|
|
36476
|
-
}
|
|
36704
|
+
const floorChanges = new Map(accounts.map((account) => [account, nextAccounts.get(account)]));
|
|
36705
|
+
plan.update = (current, carry) => {
|
|
36706
|
+
const carried = carry?.find((edit2) => edit2.setting === key)?.value;
|
|
36707
|
+
const edit = planSettingsAccountFloors(current, floorChanges, host2, carried ?? settingsRecreationFloors(generation.protection[host2].values, host2));
|
|
36708
|
+
return edit ? [...edits, edit] : edits;
|
|
36709
|
+
};
|
|
36477
36710
|
return plan;
|
|
36478
36711
|
}
|
|
36479
36712
|
function planSettingsAccountFloors(current, changes2, host2, recreation) {
|
|
@@ -36954,8 +37187,8 @@ function validateNativeVaultRosterSeed(existing, input) {
|
|
|
36954
37187
|
// src/quota-manager.ts
|
|
36955
37188
|
var nativeSetTimeout = globalThis.setTimeout;
|
|
36956
37189
|
function pauseOnRealTimer(ms) {
|
|
36957
|
-
return new Promise((
|
|
36958
|
-
const id2 = nativeSetTimeout(
|
|
37190
|
+
return new Promise((resolve21) => {
|
|
37191
|
+
const id2 = nativeSetTimeout(resolve21, ms);
|
|
36959
37192
|
if (typeof id2 === "object" && "unref" in id2)
|
|
36960
37193
|
id2.unref();
|
|
36961
37194
|
});
|
|
@@ -38723,7 +38956,7 @@ function recencyOnly(patch) {
|
|
|
38723
38956
|
return keys5.length === 1 && keys5[0] === "lastUsed" && typeof patch.lastUsed === "number";
|
|
38724
38957
|
}
|
|
38725
38958
|
function waitFor(pending, signal) {
|
|
38726
|
-
return new Promise((
|
|
38959
|
+
return new Promise((resolve21, reject) => {
|
|
38727
38960
|
const abort = () => {
|
|
38728
38961
|
cleanup2();
|
|
38729
38962
|
reject(signal.reason);
|
|
@@ -38732,7 +38965,7 @@ function waitFor(pending, signal) {
|
|
|
38732
38965
|
signal.addEventListener("abort", abort, { once: true });
|
|
38733
38966
|
pending.then((value) => {
|
|
38734
38967
|
cleanup2();
|
|
38735
|
-
signal.aborted ? reject(signal.reason) :
|
|
38968
|
+
signal.aborted ? reject(signal.reason) : resolve21(value);
|
|
38736
38969
|
}, (error) => {
|
|
38737
38970
|
cleanup2();
|
|
38738
38971
|
reject(error);
|
|
@@ -39360,7 +39593,7 @@ class PersistentRelaySession {
|
|
|
39360
39593
|
return;
|
|
39361
39594
|
if (this.connecting)
|
|
39362
39595
|
return await this.connecting;
|
|
39363
|
-
this.connecting = new Promise((
|
|
39596
|
+
this.connecting = new Promise((resolve21, reject) => {
|
|
39364
39597
|
const url = toWebSocketUrl(this.config.url, this.config.token);
|
|
39365
39598
|
const parsed = new URL(url);
|
|
39366
39599
|
parsed.searchParams.set("affinity", this.affinity);
|
|
@@ -39382,7 +39615,7 @@ class PersistentRelaySession {
|
|
|
39382
39615
|
if (message.type === "ready") {
|
|
39383
39616
|
this.timers.clearTimeout(timeout);
|
|
39384
39617
|
this.serverState = message.state;
|
|
39385
|
-
|
|
39618
|
+
resolve21();
|
|
39386
39619
|
return;
|
|
39387
39620
|
}
|
|
39388
39621
|
this.handleMessage(message);
|
|
@@ -39434,15 +39667,15 @@ class PersistentRelaySession {
|
|
|
39434
39667
|
const sentAt = perfNowMs();
|
|
39435
39668
|
let resolveDone;
|
|
39436
39669
|
let rejectDone;
|
|
39437
|
-
const done = new Promise((
|
|
39438
|
-
resolveDone =
|
|
39670
|
+
const done = new Promise((resolve21, reject) => {
|
|
39671
|
+
resolveDone = resolve21;
|
|
39439
39672
|
rejectDone = reject;
|
|
39440
39673
|
});
|
|
39441
|
-
const response = new Promise((
|
|
39674
|
+
const response = new Promise((resolve21, reject) => {
|
|
39442
39675
|
const pending = {
|
|
39443
39676
|
payload,
|
|
39444
39677
|
bodyText,
|
|
39445
|
-
resolve:
|
|
39678
|
+
resolve: resolve21,
|
|
39446
39679
|
reject,
|
|
39447
39680
|
streamDone: false,
|
|
39448
39681
|
accepted: false,
|
|
@@ -40560,8 +40793,9 @@ async function resolveSettingsPaths(host2, options = {}) {
|
|
|
40560
40793
|
// src/native-account-runtime.ts
|
|
40561
40794
|
var sharedAccounts = new NativeRuntimeRegistry;
|
|
40562
40795
|
function acquireNativeAccountRuntime(options) {
|
|
40796
|
+
const settingsFile = options.settingsService?.file ?? options.settingsFile;
|
|
40563
40797
|
const key = JSON.stringify([
|
|
40564
|
-
|
|
40798
|
+
settingsFile === "" ? null : resolve21(settingsFile ?? getSettingsFilePath({ env: options.vault?.env })),
|
|
40565
40799
|
nativeVaultRuntimeKey({
|
|
40566
40800
|
...options.vault,
|
|
40567
40801
|
paths: options.paths,
|
|
@@ -41008,7 +41242,7 @@ function buildNativeAccountRuntime(options, env, runtimeSettings) {
|
|
|
41008
41242
|
const { mode, paths: paths3, store: store2 } = await selectedStorage();
|
|
41009
41243
|
for (let attempt = 0;attempt < 4; attempt++) {
|
|
41010
41244
|
if (attempt)
|
|
41011
|
-
await new Promise((
|
|
41245
|
+
await new Promise((resolve22) => setTimeout(resolve22, 10));
|
|
41012
41246
|
const settings = await store2.readSettings();
|
|
41013
41247
|
if (settings.status !== "ready")
|
|
41014
41248
|
throw new NativeRuntimeError("publication-refused");
|
|
@@ -41381,8 +41615,8 @@ function buildNativeAccountRuntime(options, env, runtimeSettings) {
|
|
|
41381
41615
|
if (plan.refusal)
|
|
41382
41616
|
return { settings: before, outcome: "refused", reason: plan.refusal };
|
|
41383
41617
|
try {
|
|
41384
|
-
if (plan.edits.length) {
|
|
41385
|
-
await runtimeSettings.update(plan.
|
|
41618
|
+
if (plan.edits.length || plan.update) {
|
|
41619
|
+
await runtimeSettings.update(plan.update ?? plan.edits, before);
|
|
41386
41620
|
}
|
|
41387
41621
|
} catch (error) {
|
|
41388
41622
|
if (error instanceof SettingsRecreationRefusal)
|
|
@@ -41391,6 +41625,14 @@ function buildNativeAccountRuntime(options, env, runtimeSettings) {
|
|
|
41391
41625
|
outcome: "refused",
|
|
41392
41626
|
reason: error.message
|
|
41393
41627
|
};
|
|
41628
|
+
if (error instanceof SettingsAdoptionRefusal) {
|
|
41629
|
+
await service.refresh().catch(() => {});
|
|
41630
|
+
return {
|
|
41631
|
+
settings: runtimeSettings.resolve(stored.settings),
|
|
41632
|
+
outcome: "refused",
|
|
41633
|
+
reason: runtimeSettings.checkingRefusal()
|
|
41634
|
+
};
|
|
41635
|
+
}
|
|
41394
41636
|
const failure = error instanceof SettingsRefusal ? SETTINGS_WRITE_FAILURES[error.code] : SETTINGS_WRITE_FAILURES["settings-unavailable"];
|
|
41395
41637
|
return {
|
|
41396
41638
|
settings: runtimeSettings.resolve(stored.settings),
|
|
@@ -41428,7 +41670,11 @@ function buildNativeAccountRuntime(options, env, runtimeSettings) {
|
|
|
41428
41670
|
if (redirected) {
|
|
41429
41671
|
await runtimeSettings.prepareAction();
|
|
41430
41672
|
if (!await runtimeSettings.prepareWrite())
|
|
41431
|
-
|
|
41673
|
+
return {
|
|
41674
|
+
settings: runtimeSettings.resolve(result.settings),
|
|
41675
|
+
outcome: "refused",
|
|
41676
|
+
reason: runtimeSettings.checkingRefusal()
|
|
41677
|
+
};
|
|
41432
41678
|
return runtime2.updateSettings(mutator);
|
|
41433
41679
|
}
|
|
41434
41680
|
if (result.outcome === "updated" && captured.before)
|
|
@@ -41855,7 +42101,7 @@ function relayGeneration(input) {
|
|
|
41855
42101
|
// src/native-host-auth-write.ts
|
|
41856
42102
|
import { randomUUID as randomUUID24 } from "node:crypto";
|
|
41857
42103
|
import { lstat as lstat18, open as open13, rename as rename14, unlink as unlink9 } from "node:fs/promises";
|
|
41858
|
-
import { dirname as
|
|
42104
|
+
import { dirname as dirname22, isAbsolute as isAbsolute6, join as join27 } from "node:path";
|
|
41859
42105
|
class NativeHostAuthWriteError extends Error {
|
|
41860
42106
|
code;
|
|
41861
42107
|
effect;
|
|
@@ -41916,7 +42162,7 @@ async function writeNativeHostAuth(input, hooks = {}) {
|
|
|
41916
42162
|
const removingFile = host2 === "pi" && Object.keys(next).length === 0;
|
|
41917
42163
|
const outcome = Object.freeze(host2 === "pi" ? { status: "removed", file: removingFile ? "unlinked" : "replaced" } : { status: snapshot.data === undefined ? "created" : "replaced" });
|
|
41918
42164
|
if (!removingFile) {
|
|
41919
|
-
stage = join27(
|
|
42165
|
+
stage = join27(dirname22(authPath), `.native-host-auth-write.${randomUUID24()}.tmp`);
|
|
41920
42166
|
const bytes = `${JSON.stringify(next, null, 2)}
|
|
41921
42167
|
`;
|
|
41922
42168
|
const nativeCreated = await createWindowsOwnerOnly(stage, bytes);
|
|
@@ -41977,7 +42223,7 @@ async function writeNativeHostAuth(input, hooks = {}) {
|
|
|
41977
42223
|
// src/native-migration.ts
|
|
41978
42224
|
import { createHash as createHash25 } from "node:crypto";
|
|
41979
42225
|
import { lstat as lstat19, mkdir as mkdir15, unlink as unlink10 } from "node:fs/promises";
|
|
41980
|
-
import { dirname as
|
|
42226
|
+
import { dirname as dirname23, isAbsolute as isAbsolute7 } from "node:path";
|
|
41981
42227
|
class NativeMigrationError extends Error {
|
|
41982
42228
|
code;
|
|
41983
42229
|
constructor(code) {
|
|
@@ -42762,7 +43008,7 @@ async function runNativeMigration(input, hooks = {}) {
|
|
|
42762
43008
|
refuse3();
|
|
42763
43009
|
await step("before:host");
|
|
42764
43010
|
await recheck();
|
|
42765
|
-
await mkdir15(
|
|
43011
|
+
await mkdir15(dirname23(operation.hostAuthPath), {
|
|
42766
43012
|
recursive: true,
|
|
42767
43013
|
mode: 448
|
|
42768
43014
|
});
|
|
@@ -43489,8 +43735,8 @@ async function runNativeCustodyActivation(options, hooks = {}) {
|
|
|
43489
43735
|
}
|
|
43490
43736
|
async function commitMode(paths2, routingPath, plan, context) {
|
|
43491
43737
|
let openGate = () => {};
|
|
43492
|
-
const gate = new Promise((
|
|
43493
|
-
openGate =
|
|
43738
|
+
const gate = new Promise((resolve22) => {
|
|
43739
|
+
openGate = resolve22;
|
|
43494
43740
|
});
|
|
43495
43741
|
let leases;
|
|
43496
43742
|
let scope;
|
|
@@ -44532,12 +44778,235 @@ function nativeCacheKeepAlways(settings) {
|
|
|
44532
44778
|
}
|
|
44533
44779
|
// src/native-setup-settings.ts
|
|
44534
44780
|
import { isDeepStrictEqual as isDeepStrictEqual6 } from "node:util";
|
|
44535
|
-
import { parse as
|
|
44781
|
+
import { parse as parse5 } from "jsonc-parser";
|
|
44782
|
+
|
|
44783
|
+
// src/settings-host-import.ts
|
|
44784
|
+
var KILLSWITCH_FLOOR_KEYS = new Set([
|
|
44785
|
+
"killswitch_default_five_hour",
|
|
44786
|
+
"killswitch_default_seven_day",
|
|
44787
|
+
"killswitch_default_scoped"
|
|
44788
|
+
]);
|
|
44789
|
+
var ranks = {
|
|
44790
|
+
quota_fail_closed_on_unknown_quota: { off: 0, default: 1, on: 2 },
|
|
44791
|
+
max_same_account_wait: { cache: 0, "15m": 1, off: 2 }
|
|
44792
|
+
};
|
|
44793
|
+
function settingsProtectionStricter(key, legacy, file) {
|
|
44794
|
+
if (typeof legacy === "boolean")
|
|
44795
|
+
return legacy && file === false;
|
|
44796
|
+
if (typeof legacy === "number")
|
|
44797
|
+
return typeof file === "number" && legacy > file;
|
|
44798
|
+
const rank = ranks[key];
|
|
44799
|
+
if (!rank || typeof legacy !== "string" || typeof file !== "string")
|
|
44800
|
+
return false;
|
|
44801
|
+
return (rank[legacy] ?? 0) > (rank[file] ?? 0);
|
|
44802
|
+
}
|
|
44803
|
+
function planSettingsHostImport(input) {
|
|
44804
|
+
const { host: host2, legacy, resolved } = input;
|
|
44805
|
+
const keys5 = [];
|
|
44806
|
+
const edits = [];
|
|
44807
|
+
for (const key of SETTINGS_PROTECTION_KEYS) {
|
|
44808
|
+
if (key === "killswitch_account_floors")
|
|
44809
|
+
continue;
|
|
44810
|
+
if (input.fileLevels[key]?.includes(host2))
|
|
44811
|
+
continue;
|
|
44812
|
+
if (!legacy.killswitch_enabled && KILLSWITCH_FLOOR_KEYS.has(key))
|
|
44813
|
+
continue;
|
|
44814
|
+
if (!settingsProtectionStricter(key, legacy[key], resolved[key]))
|
|
44815
|
+
continue;
|
|
44816
|
+
keys5.push(key);
|
|
44817
|
+
edits.push({ setting: key, level: host2, value: legacy[key] });
|
|
44818
|
+
}
|
|
44819
|
+
const covered = new Set(resolved.killswitch_account_floors.filter((entry2) => entry2.host === host2 || entry2.host === "both").map((entry2) => entry2.account));
|
|
44820
|
+
const missing3 = legacy.killswitch_account_floors.filter((entry2) => legacy.killswitch_enabled && (entry2.host === host2 || entry2.host === "both") && !covered.has(entry2.account) && (entry2.five_hour > resolved.killswitch_default_five_hour || entry2.seven_day > resolved.killswitch_default_seven_day || entry2.scoped > resolved.killswitch_default_scoped));
|
|
44821
|
+
if (missing3.length) {
|
|
44822
|
+
keys5.push("killswitch_account_floors");
|
|
44823
|
+
edits.push({
|
|
44824
|
+
setting: "killswitch_account_floors",
|
|
44825
|
+
value: [
|
|
44826
|
+
...resolved.killswitch_account_floors,
|
|
44827
|
+
...missing3.map((entry2) => ({ ...entry2, host: host2 }))
|
|
44828
|
+
]
|
|
44829
|
+
});
|
|
44830
|
+
}
|
|
44831
|
+
return { keys: keys5, edits };
|
|
44832
|
+
}
|
|
44833
|
+
|
|
44834
|
+
// src/settings-protection-legacy.ts
|
|
44835
|
+
function legacySettingsProtection(settings, host2, mode = "local") {
|
|
44836
|
+
const storage = {
|
|
44837
|
+
version: 1,
|
|
44838
|
+
accounts: [],
|
|
44839
|
+
...nativeAccountSettings(settings)
|
|
44840
|
+
};
|
|
44841
|
+
const main = getKillswitchThresholdsForAccount(storage);
|
|
44842
|
+
const minimum = getQuotaMinimumRemainingThresholds(storage);
|
|
44843
|
+
return {
|
|
44844
|
+
killswitch_enabled: isKillswitchEnabled(storage),
|
|
44845
|
+
killswitch_default_five_hour: main.five_hour,
|
|
44846
|
+
killswitch_default_seven_day: main.seven_day,
|
|
44847
|
+
killswitch_default_scoped: main.scoped,
|
|
44848
|
+
killswitch_account_floors: Object.keys(storage.killswitch?.accounts ?? {}).map((account) => ({
|
|
44849
|
+
account,
|
|
44850
|
+
host: mode === "claustrum" ? "both" : host2,
|
|
44851
|
+
...getKillswitchThresholdsForAccount(storage, account)
|
|
44852
|
+
})),
|
|
44853
|
+
quota_minimum_remaining_five_hour: minimum.five_hour,
|
|
44854
|
+
quota_minimum_remaining_seven_day: minimum.seven_day,
|
|
44855
|
+
quota_minimum_remaining_scoped: normalizeKillswitchThresholds(storage.quota?.minimumRemaining).scoped,
|
|
44856
|
+
quota_fail_closed_on_unknown_quota: toThreeWay(storage.quota?.failClosedOnUnknownQuota),
|
|
44857
|
+
max_same_account_wait: {
|
|
44858
|
+
"0": "off",
|
|
44859
|
+
"15": "15m",
|
|
44860
|
+
max: "cache"
|
|
44861
|
+
}[getMaxSameAccountWait(storage)]
|
|
44862
|
+
};
|
|
44863
|
+
}
|
|
44864
|
+
async function readLegacySettingsProtection(options) {
|
|
44865
|
+
try {
|
|
44866
|
+
const mode = await (options.readMode ?? readNativeEnrollmentMode)(options.host, options.env ?? process.env);
|
|
44867
|
+
if (mode === "claustrum")
|
|
44868
|
+
await options.initializeVaultSettings();
|
|
44869
|
+
const store = mode === "claustrum" ? options.vaultStore : options.localStore;
|
|
44870
|
+
const read = await store.readSettings();
|
|
44871
|
+
if (read.status !== "ready")
|
|
44872
|
+
return;
|
|
44873
|
+
return legacySettingsProtection(read.settings, options.host, mode);
|
|
44874
|
+
} catch {
|
|
44875
|
+
return;
|
|
44876
|
+
}
|
|
44877
|
+
}
|
|
44878
|
+
|
|
44879
|
+
// src/native-setup-settings.ts
|
|
44536
44880
|
var thresholds = ({ five_hour, seven_day, scoped }) => ({
|
|
44537
44881
|
five_hour,
|
|
44538
44882
|
seven_day,
|
|
44539
44883
|
scoped
|
|
44540
44884
|
});
|
|
44885
|
+
var protectionKeys = new Set(SETTINGS_PROTECTION_KEYS);
|
|
44886
|
+
var SETUP_WRITE_ATTEMPTS = 3;
|
|
44887
|
+
|
|
44888
|
+
class SetupProtectionChanged extends Error {
|
|
44889
|
+
}
|
|
44890
|
+
function record16(value) {
|
|
44891
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
44892
|
+
}
|
|
44893
|
+
function documentOf(generation) {
|
|
44894
|
+
const raw = generation.source ? parse5(generation.source.replace(/^\uFEFF/, ""), [], {
|
|
44895
|
+
allowTrailingComma: true
|
|
44896
|
+
}) : {};
|
|
44897
|
+
return record16(raw) ? raw : {};
|
|
44898
|
+
}
|
|
44899
|
+
function carriedProtection(carry, host2) {
|
|
44900
|
+
const values = {};
|
|
44901
|
+
for (const edit of carry)
|
|
44902
|
+
if (!edit.level || edit.level === "default")
|
|
44903
|
+
values[edit.setting] = edit.value;
|
|
44904
|
+
for (const edit of carry)
|
|
44905
|
+
if (edit.level === host2)
|
|
44906
|
+
values[edit.setting] = edit.value;
|
|
44907
|
+
return values;
|
|
44908
|
+
}
|
|
44909
|
+
function planSetupEdits(input) {
|
|
44910
|
+
const { host: host2, values, legacy, current, snapshot } = input;
|
|
44911
|
+
const missing3 = current.status === "missing";
|
|
44912
|
+
const document = current.status === "ready" && record16(current.document) ? current.document : {};
|
|
44913
|
+
let resolved;
|
|
44914
|
+
if (missing3)
|
|
44915
|
+
resolved = input.carry ? carriedProtection(input.carry, host2) : snapshot.protection[host2].values;
|
|
44916
|
+
else {
|
|
44917
|
+
const expected = snapshot.status === "ready" ? documentOf(snapshot) : {};
|
|
44918
|
+
if (snapshot.status !== "ready" || SETTINGS_PROTECTION_KEYS.some((key) => !isDeepStrictEqual6(document[key], expected[key])))
|
|
44919
|
+
throw new SetupProtectionChanged;
|
|
44920
|
+
resolved = snapshot.protection[host2].values;
|
|
44921
|
+
}
|
|
44922
|
+
const levels = missing3 ? {} : settingsFileLevels(document);
|
|
44923
|
+
const held2 = (key) => {
|
|
44924
|
+
const value = document[key];
|
|
44925
|
+
if (!record16(value))
|
|
44926
|
+
return value;
|
|
44927
|
+
return value[levels[key]?.includes(host2) ? host2 : "default"];
|
|
44928
|
+
};
|
|
44929
|
+
const fill = (key, value) => ({
|
|
44930
|
+
setting: key,
|
|
44931
|
+
value,
|
|
44932
|
+
...host2 === "pi" ? { level: "pi" } : {}
|
|
44933
|
+
});
|
|
44934
|
+
const edits = [];
|
|
44935
|
+
const skips = [];
|
|
44936
|
+
const skip = (key, legacyValue, heldValue, account) => skips.push({
|
|
44937
|
+
key,
|
|
44938
|
+
legacy: legacyValue,
|
|
44939
|
+
held: heldValue,
|
|
44940
|
+
...account === undefined ? {} : { account },
|
|
44941
|
+
carried: missing3
|
|
44942
|
+
});
|
|
44943
|
+
const imported = planSettingsHostImport({
|
|
44944
|
+
host: host2,
|
|
44945
|
+
legacy,
|
|
44946
|
+
resolved,
|
|
44947
|
+
fileLevels: levels
|
|
44948
|
+
});
|
|
44949
|
+
const dropFloors = !legacy.killswitch_enabled && (resolved.killswitch_enabled || ["opencode", "pi"].some((each) => snapshot.protection[each].values.killswitch_enabled));
|
|
44950
|
+
const filled2 = new Set;
|
|
44951
|
+
for (const key of Object.keys(values)) {
|
|
44952
|
+
if (key === "killswitch_account_floors")
|
|
44953
|
+
continue;
|
|
44954
|
+
const value = values[key];
|
|
44955
|
+
const keyLevels = levels[key] ?? [];
|
|
44956
|
+
if (dropFloors && KILLSWITCH_FLOOR_KEYS.has(key))
|
|
44957
|
+
skip(key, value, resolved[key]);
|
|
44958
|
+
else if (!keyLevels.length && !(missing3 && protectionKeys.has(key))) {
|
|
44959
|
+
filled2.add(key);
|
|
44960
|
+
edits.push(fill(key, value));
|
|
44961
|
+
} else if (protectionKeys.has(key)) {
|
|
44962
|
+
if (!imported.keys.includes(key))
|
|
44963
|
+
skip(key, value, missing3 ? resolved[key] : held2(key));
|
|
44964
|
+
} else if (keyLevels.includes("default") || keyLevels.includes(host2))
|
|
44965
|
+
skip(key, value, held2(key));
|
|
44966
|
+
else {
|
|
44967
|
+
filled2.add(key);
|
|
44968
|
+
edits.push(fill(key, value));
|
|
44969
|
+
}
|
|
44970
|
+
}
|
|
44971
|
+
for (const edit of imported.edits)
|
|
44972
|
+
if (edit.setting !== "killswitch_account_floors" && !filled2.has(edit.setting))
|
|
44973
|
+
edits.push(edit);
|
|
44974
|
+
const floorsKey = "killswitch_account_floors";
|
|
44975
|
+
const legacyFloors = values[floorsKey];
|
|
44976
|
+
if (legacyFloors === undefined)
|
|
44977
|
+
return { edits, skips };
|
|
44978
|
+
const own = (entry2) => entry2.host === host2 || entry2.host === "both";
|
|
44979
|
+
if (missing3) {
|
|
44980
|
+
const carriedFloors = resolved.killswitch_account_floors;
|
|
44981
|
+
const importedFloors = imported.edits.find((edit) => edit.setting === floorsKey)?.value;
|
|
44982
|
+
const appended2 = new Set((importedFloors ?? []).slice(carriedFloors.length).map((entry2) => entry2.account));
|
|
44983
|
+
if (importedFloors)
|
|
44984
|
+
edits.push({ setting: floorsKey, value: importedFloors });
|
|
44985
|
+
if (!legacyFloors.length)
|
|
44986
|
+
skip(floorsKey, [], []);
|
|
44987
|
+
for (const entry2 of legacyFloors) {
|
|
44988
|
+
if (appended2.has(entry2.account))
|
|
44989
|
+
continue;
|
|
44990
|
+
const kept = carriedFloors.find((existing) => existing.account === entry2.account && own(existing));
|
|
44991
|
+
skip(floorsKey, thresholds(entry2), kept && thresholds(kept), entry2.account);
|
|
44992
|
+
}
|
|
44993
|
+
return { edits, skips };
|
|
44994
|
+
}
|
|
44995
|
+
const floors = document[floorsKey] ?? [];
|
|
44996
|
+
if (!Array.isArray(floors))
|
|
44997
|
+
throw new SettingsRefusal("settings-invalid-value", "Account floors are not a list");
|
|
44998
|
+
const appended = [];
|
|
44999
|
+
for (const entry2 of legacyFloors) {
|
|
45000
|
+
const kept = floors.find((existing) => existing.account === entry2.account && own(existing));
|
|
45001
|
+
if (kept || dropFloors)
|
|
45002
|
+
skip(floorsKey, thresholds(entry2), kept && thresholds(kept), entry2.account);
|
|
45003
|
+
else
|
|
45004
|
+
appended.push({ ...entry2, host: host2 });
|
|
45005
|
+
}
|
|
45006
|
+
if (appended.length)
|
|
45007
|
+
edits.push({ setting: floorsKey, value: [...floors, ...appended] });
|
|
45008
|
+
return { edits, skips };
|
|
45009
|
+
}
|
|
44541
45010
|
async function writeNativeSetupSettings(options) {
|
|
44542
45011
|
const paths2 = options.paths ?? await resolveSettingsPaths(options.host, options);
|
|
44543
45012
|
const mode = await resolveSettingsMode(paths2, options.authority);
|
|
@@ -44554,6 +45023,7 @@ async function writeNativeSetupSettings(options) {
|
|
|
44554
45023
|
logger2.warn("settings", message);
|
|
44555
45024
|
};
|
|
44556
45025
|
let service;
|
|
45026
|
+
let committing = false;
|
|
44557
45027
|
try {
|
|
44558
45028
|
validateNativeMigrationSettings(options.settings);
|
|
44559
45029
|
const { moved } = splitNativeMigrationSettings(options.settings);
|
|
@@ -44565,7 +45035,8 @@ async function writeNativeSetupSettings(options) {
|
|
|
44565
45035
|
service = await openSettingsService({
|
|
44566
45036
|
file: paths2.target,
|
|
44567
45037
|
host: options.host,
|
|
44568
|
-
protection: options.protection
|
|
45038
|
+
protection: options.protection,
|
|
45039
|
+
adopted: () => committing
|
|
44569
45040
|
});
|
|
44570
45041
|
if (!service)
|
|
44571
45042
|
throw new Error("Settings service did not open");
|
|
@@ -44591,92 +45062,84 @@ async function writeNativeSetupSettings(options) {
|
|
|
44591
45062
|
path: options.source,
|
|
44592
45063
|
log: { warn }
|
|
44593
45064
|
});
|
|
44594
|
-
const
|
|
44595
|
-
allowTrailingComma: true
|
|
44596
|
-
}) ?? {} : {};
|
|
44597
|
-
const edits = [];
|
|
44598
|
-
const skip = (key, legacy, held2, account) => {
|
|
45065
|
+
const skip = ({ key, legacy: legacy2, held: held2, account, carried }) => {
|
|
44599
45066
|
if (!result.skipped.includes(key)) {
|
|
44600
45067
|
result.skipped.push(key);
|
|
44601
|
-
warn(`Setup skipped setting "${key}" in "${paths2.target}": ${
|
|
45068
|
+
warn(`Setup skipped setting "${key}" in "${paths2.target}": ${carried ? "the carried protection set" : "the user settings file"} already supplies it for ${options.host}.`);
|
|
44602
45069
|
}
|
|
44603
|
-
if (!isDeepStrictEqual6(
|
|
45070
|
+
if (!isDeepStrictEqual6(legacy2, held2))
|
|
44604
45071
|
result.differing.push({
|
|
44605
45072
|
key,
|
|
44606
45073
|
...account === undefined ? {} : { account },
|
|
44607
|
-
legacy,
|
|
45074
|
+
legacy: legacy2,
|
|
44608
45075
|
file: held2
|
|
44609
45076
|
});
|
|
44610
45077
|
};
|
|
44611
|
-
|
|
44612
|
-
|
|
44613
|
-
|
|
44614
|
-
|
|
44615
|
-
|
|
44616
|
-
|
|
44617
|
-
|
|
44618
|
-
|
|
44619
|
-
|
|
44620
|
-
|
|
44621
|
-
|
|
44622
|
-
|
|
44623
|
-
|
|
44624
|
-
|
|
44625
|
-
|
|
44626
|
-
}
|
|
44627
|
-
|
|
44628
|
-
|
|
44629
|
-
|
|
44630
|
-
|
|
44631
|
-
|
|
44632
|
-
|
|
44633
|
-
|
|
44634
|
-
|
|
44635
|
-
const appended = [];
|
|
44636
|
-
for (const entry2 of values[key] ?? []) {
|
|
44637
|
-
const held2 = floors.find((existing) => existing.account === entry2.account && (existing.host === options.host || existing.host === "both"));
|
|
44638
|
-
if (held2) {
|
|
44639
|
-
skip(key, thresholds(entry2), thresholds(held2), entry2.account);
|
|
44640
|
-
} else
|
|
44641
|
-
appended.push({ ...entry2, host: options.host });
|
|
45078
|
+
const legacy = legacySettingsProtection(moved, options.host);
|
|
45079
|
+
if (!missing3 && values.killswitch_account_floors !== undefined && generation.report.some((entry2) => entry2.keyPath[0] === "killswitch_account_floors"))
|
|
45080
|
+
return {
|
|
45081
|
+
...result,
|
|
45082
|
+
outcome: "refused",
|
|
45083
|
+
reason: invalidSettingsWriteText("killswitch_account_floors", paths2.target)
|
|
45084
|
+
};
|
|
45085
|
+
let skips = [];
|
|
45086
|
+
try {
|
|
45087
|
+
const initial = planSetupEdits({
|
|
45088
|
+
host: options.host,
|
|
45089
|
+
values,
|
|
45090
|
+
legacy,
|
|
45091
|
+
current: missing3 ? { status: "missing" } : { status: "ready", document: documentOf(generation) },
|
|
45092
|
+
snapshot: generation
|
|
45093
|
+
});
|
|
45094
|
+
skips = initial.skips;
|
|
45095
|
+
const lease = service;
|
|
45096
|
+
const adopt = () => {
|
|
45097
|
+
committing = true;
|
|
45098
|
+
try {
|
|
45099
|
+
lease.noteAdoption?.();
|
|
45100
|
+
} finally {
|
|
45101
|
+
committing = false;
|
|
44642
45102
|
}
|
|
44643
|
-
|
|
44644
|
-
|
|
44645
|
-
|
|
44646
|
-
|
|
44647
|
-
|
|
44648
|
-
|
|
44649
|
-
|
|
44650
|
-
|
|
44651
|
-
|
|
44652
|
-
|
|
44653
|
-
|
|
44654
|
-
|
|
44655
|
-
|
|
44656
|
-
|
|
44657
|
-
|
|
44658
|
-
|
|
44659
|
-
|
|
44660
|
-
|
|
44661
|
-
|
|
44662
|
-
|
|
44663
|
-
|
|
44664
|
-
|
|
45103
|
+
};
|
|
45104
|
+
const write = initial.edits.length > 0 || missing3 && Object.keys(values).length > 0;
|
|
45105
|
+
if (!write && !missing3 && service.snapshot().id === generation.id)
|
|
45106
|
+
adopt();
|
|
45107
|
+
else if (write || !missing3) {
|
|
45108
|
+
for (let attempt = 1;; attempt++) {
|
|
45109
|
+
const snapshot = service.snapshot();
|
|
45110
|
+
try {
|
|
45111
|
+
const written = await service.update((current, carry) => {
|
|
45112
|
+
const plan2 = planSetupEdits({
|
|
45113
|
+
host: options.host,
|
|
45114
|
+
values,
|
|
45115
|
+
legacy,
|
|
45116
|
+
current,
|
|
45117
|
+
carry,
|
|
45118
|
+
snapshot
|
|
45119
|
+
});
|
|
45120
|
+
skips = plan2.skips;
|
|
45121
|
+
return plan2.edits;
|
|
45122
|
+
}, options.host, { createMissing: missing3, importing: true });
|
|
45123
|
+
if (written.outcome === "updated")
|
|
45124
|
+
adopt();
|
|
45125
|
+
else if (service.snapshot().id === snapshot.id)
|
|
45126
|
+
adopt();
|
|
45127
|
+
else
|
|
45128
|
+
throw new SetupProtectionChanged;
|
|
45129
|
+
break;
|
|
45130
|
+
} catch (error) {
|
|
45131
|
+
if (!(error instanceof SetupProtectionChanged))
|
|
45132
|
+
throw error;
|
|
45133
|
+
if (attempt >= SETUP_WRITE_ATTEMPTS)
|
|
45134
|
+
throw new SettingsRefusal("settings-busy", "Protection settings kept changing during setup");
|
|
45135
|
+
await service.refresh();
|
|
45136
|
+
}
|
|
44665
45137
|
}
|
|
44666
45138
|
}
|
|
45139
|
+
} finally {
|
|
45140
|
+
for (const entry2 of skips)
|
|
45141
|
+
skip(entry2);
|
|
44667
45142
|
}
|
|
44668
|
-
if (edits.length)
|
|
44669
|
-
await service.update(edits, options.host, {
|
|
44670
|
-
createMissing: missing3,
|
|
44671
|
-
hostsStopped: true
|
|
44672
|
-
});
|
|
44673
|
-
else if (missing3 && Object.keys(values).length)
|
|
44674
|
-
await service.update([
|
|
44675
|
-
{
|
|
44676
|
-
setting: "killswitch_enabled",
|
|
44677
|
-
value: generation.protection[options.host].values.killswitch_enabled
|
|
44678
|
-
}
|
|
44679
|
-
], options.host, { createMissing: true, hostsStopped: true });
|
|
44680
45143
|
return result;
|
|
44681
45144
|
} catch (error) {
|
|
44682
45145
|
if (error instanceof SettingsRecreationRefusal)
|
|
@@ -45389,11 +45852,11 @@ async function refreshForRequest(runtime2, ready) {
|
|
|
45389
45852
|
break;
|
|
45390
45853
|
if (combined.aborted)
|
|
45391
45854
|
break;
|
|
45392
|
-
await new Promise((
|
|
45855
|
+
await new Promise((resolve22) => {
|
|
45393
45856
|
const finish = () => {
|
|
45394
45857
|
clearTimeout(pause2);
|
|
45395
45858
|
combined.removeEventListener("abort", finish);
|
|
45396
|
-
|
|
45859
|
+
resolve22();
|
|
45397
45860
|
};
|
|
45398
45861
|
const pause2 = setTimeout(finish, 25);
|
|
45399
45862
|
combined.addEventListener("abort", finish, { once: true });
|
|
@@ -45409,16 +45872,16 @@ async function refreshForRequest(runtime2, ready) {
|
|
|
45409
45872
|
function waitForRequest(pending, signal) {
|
|
45410
45873
|
if (!signal)
|
|
45411
45874
|
return pending;
|
|
45412
|
-
return new Promise((
|
|
45875
|
+
return new Promise((resolve22, reject) => {
|
|
45413
45876
|
const abort = () => reject(signal.reason);
|
|
45414
45877
|
signal.addEventListener("abort", abort, { once: true });
|
|
45415
|
-
pending.then(
|
|
45878
|
+
pending.then(resolve22, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
45416
45879
|
if (signal.aborted)
|
|
45417
45880
|
abort();
|
|
45418
45881
|
});
|
|
45419
45882
|
}
|
|
45420
45883
|
// src/native-vault-connection.ts
|
|
45421
|
-
import { dirname as
|
|
45884
|
+
import { dirname as dirname25, join as join28, resolve as resolve23 } from "node:path";
|
|
45422
45885
|
// ../../node_modules/@cortexkit/common-auth/dist/opencode2/integration.js
|
|
45423
45886
|
var PLACEHOLDER_PREFIX = "common-auth-placeholder";
|
|
45424
45887
|
var PLACEHOLDER_LIFETIME_MS = 365 * 24 * 60 * 60 * 1000;
|
|
@@ -45429,7 +45892,7 @@ function placeholderSecret(integrationID) {
|
|
|
45429
45892
|
import { createHash as createHash26 } from "node:crypto";
|
|
45430
45893
|
import { constants as constants5 } from "node:fs";
|
|
45431
45894
|
import { lstat as lstat20, mkdir as mkdir17, open as open14, unlink as unlink11 } from "node:fs/promises";
|
|
45432
|
-
import { dirname as
|
|
45895
|
+
import { dirname as dirname24, resolve as resolve22 } from "node:path";
|
|
45433
45896
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
45434
45897
|
|
|
45435
45898
|
// ../../node_modules/@cortexkit/common-auth/dist/pi-slot/lock.js
|
|
@@ -45832,8 +46295,8 @@ function createPiSlot(options, onStep, hooks) {
|
|
|
45832
46295
|
if (!provider || !options.authPath || !options.stashPath || !placeholderKey || placeholderKey.startsWith("!") || placeholderKey.includes("$") || !Number.isFinite(timeout) || timeout < 0) {
|
|
45833
46296
|
throw new PiSlotError("invalid-options");
|
|
45834
46297
|
}
|
|
45835
|
-
const authPath =
|
|
45836
|
-
const stashPath =
|
|
46298
|
+
const authPath = resolve22(options.authPath);
|
|
46299
|
+
const stashPath = resolve22(options.stashPath);
|
|
45837
46300
|
if (authPath === stashPath || stashPath === `${authPath}.lock`) {
|
|
45838
46301
|
throw new PiSlotError("invalid-options");
|
|
45839
46302
|
}
|
|
@@ -45866,9 +46329,9 @@ function createPiSlot(options, onStep, hooks) {
|
|
|
45866
46329
|
};
|
|
45867
46330
|
try {
|
|
45868
46331
|
if (windowsPrivateFiles)
|
|
45869
|
-
await ensurePrivateDirectory(
|
|
46332
|
+
await ensurePrivateDirectory(dirname24(authPath));
|
|
45870
46333
|
else
|
|
45871
|
-
await mkdir17(
|
|
46334
|
+
await mkdir17(dirname24(authPath), { recursive: true, mode: 448 });
|
|
45872
46335
|
const deadline = Date.now() + timeout;
|
|
45873
46336
|
let retry = 0;
|
|
45874
46337
|
while (!release2) {
|
|
@@ -45908,7 +46371,7 @@ function createPiSlot(options, onStep, hooks) {
|
|
|
45908
46371
|
async function deleteStash(assertLock) {
|
|
45909
46372
|
assertLock();
|
|
45910
46373
|
await unlink11(stashPath);
|
|
45911
|
-
await syncDir(
|
|
46374
|
+
await syncDir(dirname24(stashPath));
|
|
45912
46375
|
onStep?.("stash-deleted");
|
|
45913
46376
|
}
|
|
45914
46377
|
return {
|
|
@@ -45928,10 +46391,10 @@ function createPiSlot(options, onStep, hooks) {
|
|
|
45928
46391
|
throw new PiSlotError("conflict");
|
|
45929
46392
|
if (!stash) {
|
|
45930
46393
|
if (windowsPrivateFiles)
|
|
45931
|
-
await ensurePrivateDirectory(
|
|
46394
|
+
await ensurePrivateDirectory(dirname24(stashPath));
|
|
45932
46395
|
else {
|
|
45933
|
-
await mkdir17(
|
|
45934
|
-
const dir = await lstat20(
|
|
46396
|
+
await mkdir17(dirname24(stashPath), { recursive: true, mode: 448 });
|
|
46397
|
+
const dir = await lstat20(dirname24(stashPath));
|
|
45935
46398
|
if (!dir.isDirectory() || (dir.mode & 511) !== 448)
|
|
45936
46399
|
throw new PiSlotError("unsafe-path");
|
|
45937
46400
|
}
|
|
@@ -45971,8 +46434,8 @@ function createPiSlot(options, onStep, hooks) {
|
|
|
45971
46434
|
// src/native-vault-connection.ts
|
|
45972
46435
|
function nativePiAuthSlotPaths(options) {
|
|
45973
46436
|
return {
|
|
45974
|
-
authPath:
|
|
45975
|
-
stashPath: join28(
|
|
46437
|
+
authPath: resolve23(options.authPath),
|
|
46438
|
+
stashPath: join28(dirname25(getHostClaustrumEnrollmentPaths("pi", options.env).tokenPath), "pi-auth-slot", "anthropic.json"),
|
|
45976
46439
|
provider: "anthropic",
|
|
45977
46440
|
placeholderKey: placeholderSecret("anthropic")
|
|
45978
46441
|
};
|
|
@@ -46107,10 +46570,10 @@ function createAnthropicOAuthFetch(options = {}) {
|
|
|
46107
46570
|
}
|
|
46108
46571
|
// src/prime.ts
|
|
46109
46572
|
import { createHash as createHash27 } from "node:crypto";
|
|
46110
|
-
import
|
|
46573
|
+
import * as fs4 from "node:fs";
|
|
46111
46574
|
import { mkdir as mkdir18, readdir as readdir7, rm as rm10, stat as stat14, writeFile as writeFile6 } from "node:fs/promises";
|
|
46112
46575
|
import { tmpdir as tmpdir8 } from "node:os";
|
|
46113
|
-
import { join as join29, resolve as
|
|
46576
|
+
import { join as join29, resolve as resolve24 } from "node:path";
|
|
46114
46577
|
var CLAUDE_PRIME_COMMAND_NAME = "claude-prime";
|
|
46115
46578
|
var PRIME_TICK_MS = 60000;
|
|
46116
46579
|
var PRIME_DUE_OFFSET_MS = 60000;
|
|
@@ -46301,10 +46764,15 @@ function defaultMarkerDir() {
|
|
|
46301
46764
|
return join29(tmpdir8(), "opencode-anthropic-auth", "prime");
|
|
46302
46765
|
}
|
|
46303
46766
|
function primeStorageFingerprint(storagePath) {
|
|
46304
|
-
const absolutePath =
|
|
46767
|
+
const absolutePath = resolve24(storagePath);
|
|
46305
46768
|
let canonicalPath3;
|
|
46306
46769
|
try {
|
|
46307
|
-
|
|
46770
|
+
if (process.platform === "win32") {
|
|
46771
|
+
canonicalPath3 = fs4.realpathSync(absolutePath);
|
|
46772
|
+
} else {
|
|
46773
|
+
fs4.lstatSync(absolutePath);
|
|
46774
|
+
canonicalPath3 = canonicalFilePathSync(absolutePath, fs4);
|
|
46775
|
+
}
|
|
46308
46776
|
} catch (error) {
|
|
46309
46777
|
if (error.code !== "ENOENT")
|
|
46310
46778
|
throw error;
|
|
@@ -47026,9 +47494,9 @@ class QuotaHeaderFeedRegistry {
|
|
|
47026
47494
|
await this.reapStaleSiblingLeases(directory);
|
|
47027
47495
|
let entries = {};
|
|
47028
47496
|
try {
|
|
47029
|
-
const
|
|
47030
|
-
if (
|
|
47031
|
-
entries =
|
|
47497
|
+
const record17 = JSON.parse(await readFile17(this.filePath, "utf8"));
|
|
47498
|
+
if (record17.version === QUOTA_HEADER_FEED_SCHEMA_VERSION && record17.entries && typeof record17.entries === "object")
|
|
47499
|
+
entries = record17.entries;
|
|
47032
47500
|
} catch {}
|
|
47033
47501
|
entries[accountKey] = cleanEntry;
|
|
47034
47502
|
const tempPath = `${this.filePath}.${randomUUID25()}.tmp`;
|
|
@@ -47082,10 +47550,10 @@ class QuotaHeaderFeedRegistry {
|
|
|
47082
47550
|
const newest = new Map;
|
|
47083
47551
|
await Promise.all(names2.map(async (name) => {
|
|
47084
47552
|
try {
|
|
47085
|
-
const
|
|
47086
|
-
if (
|
|
47553
|
+
const record17 = JSON.parse(await readFile17(join30(directory, name), "utf8"));
|
|
47554
|
+
if (record17.version !== QUOTA_HEADER_FEED_SCHEMA_VERSION || !record17.entries || typeof record17.entries !== "object")
|
|
47087
47555
|
return;
|
|
47088
|
-
for (const [accountKey, candidate] of Object.entries(
|
|
47556
|
+
for (const [accountKey, candidate] of Object.entries(record17.entries)) {
|
|
47089
47557
|
if (!candidate || typeof candidate !== "object" || candidate.schema_version !== QUOTA_HEADER_FEED_SCHEMA_VERSION || candidate.provider !== "anthropic" || !validIdentity(candidate))
|
|
47090
47558
|
continue;
|
|
47091
47559
|
const observed = candidate.observed_at_ms;
|
|
@@ -47263,7 +47731,7 @@ function buildClaudeQuotaSummary(input) {
|
|
|
47263
47731
|
}
|
|
47264
47732
|
// src/request-gzip.ts
|
|
47265
47733
|
import { mkdir as mkdir20, readFile as readFile18, rename as rename16, rm as rm12, writeFile as writeFile8 } from "node:fs/promises";
|
|
47266
|
-
import { basename as basename14, dirname as
|
|
47734
|
+
import { basename as basename14, dirname as dirname26, join as join31 } from "node:path";
|
|
47267
47735
|
import { promisify as promisify2 } from "node:util";
|
|
47268
47736
|
import { gzip as gzip2 } from "node:zlib";
|
|
47269
47737
|
var gzipAsync = promisify2(gzip2);
|
|
@@ -47387,7 +47855,7 @@ class RequestGzipLatch {
|
|
|
47387
47855
|
return;
|
|
47388
47856
|
const temporary = `${this.path}.${process.pid}.tmp`;
|
|
47389
47857
|
try {
|
|
47390
|
-
await mkdir20(
|
|
47858
|
+
await mkdir20(dirname26(this.path), { recursive: true });
|
|
47391
47859
|
await writeFile8(temporary, `${JSON.stringify({ latchedAt: this.now(), status })}
|
|
47392
47860
|
`, { mode: 384 });
|
|
47393
47861
|
await rename16(temporary, this.path);
|
|
@@ -47411,7 +47879,7 @@ function getRequestGzipLatchPath(accountStoragePath, layout = LEGACY_STATE_LAYOU
|
|
|
47411
47879
|
return stateHomeFilePaths(layout.dir).requestGzip;
|
|
47412
47880
|
const name = basename14(accountStoragePath);
|
|
47413
47881
|
const stem = name.endsWith(".json") ? name.slice(0, -5) : name;
|
|
47414
|
-
return join31(
|
|
47882
|
+
return join31(dirname26(accountStoragePath), `${stem}-request-gzip.json`);
|
|
47415
47883
|
}
|
|
47416
47884
|
async function decideRequestGzip(options) {
|
|
47417
47885
|
if (!CLAUDE_CODE_GZIPS_REQUEST_BODIES)
|
|
@@ -47480,13 +47948,13 @@ function isInvalidJsonBody(text6) {
|
|
|
47480
47948
|
}
|
|
47481
47949
|
if (!parsed || typeof parsed !== "object")
|
|
47482
47950
|
return false;
|
|
47483
|
-
const
|
|
47484
|
-
const error =
|
|
47485
|
-
if (
|
|
47951
|
+
const record17 = parsed;
|
|
47952
|
+
const error = record17.error;
|
|
47953
|
+
if (record17.type === "error" && error && typeof error === "object" && typeof error.type === "string" && typeof error.message === "string") {
|
|
47486
47954
|
const message = error.message;
|
|
47487
47955
|
return INVALID_JSON_MESSAGES.some((prefix) => message.startsWith(prefix));
|
|
47488
47956
|
}
|
|
47489
|
-
return typeof
|
|
47957
|
+
return typeof record17.error === "string" && record17.reason === "bad_json" && BAD_JSON_TEXT.test(record17.error);
|
|
47490
47958
|
}
|
|
47491
47959
|
async function classifyGzipRejection(response) {
|
|
47492
47960
|
const { status } = response;
|
|
@@ -47856,7 +48324,7 @@ function startRoutingWait(input) {
|
|
|
47856
48324
|
// src/layout-fence.ts
|
|
47857
48325
|
import { open as open15, readdir as readdir9 } from "node:fs/promises";
|
|
47858
48326
|
import { homedir as homedir7 } from "node:os";
|
|
47859
|
-
import { basename as basename15, join as join32, resolve as
|
|
48327
|
+
import { basename as basename15, join as join32, resolve as resolve25 } from "node:path";
|
|
47860
48328
|
var STATE_PATH_OVERRIDE_VARIABLES = [
|
|
47861
48329
|
"OPENCODE_ANTHROPIC_AUTH_FILE",
|
|
47862
48330
|
"OPENCODE_ANTHROPIC_AUTH_STATE_FILE",
|
|
@@ -47906,8 +48374,8 @@ async function holderFenceBlockers(input) {
|
|
|
47906
48374
|
}
|
|
47907
48375
|
for (const value of contents?.entries ?? []) {
|
|
47908
48376
|
const life = holderEntryLiveness(value);
|
|
47909
|
-
const
|
|
47910
|
-
const listed = Array.isArray(
|
|
48377
|
+
const record17 = value;
|
|
48378
|
+
const listed = Array.isArray(record17?.files) ? record17.files.filter((file) => typeof file === "string") : undefined;
|
|
47911
48379
|
if (!life || !listed) {
|
|
47912
48380
|
blockers.push({
|
|
47913
48381
|
kind: "holder",
|
|
@@ -47927,7 +48395,7 @@ async function holderFenceBlockers(input) {
|
|
|
47927
48395
|
kind: "holder",
|
|
47928
48396
|
holderFile,
|
|
47929
48397
|
pid: life.pid,
|
|
47930
|
-
role: typeof
|
|
48398
|
+
role: typeof record17.role === "string" ? record17.role : null,
|
|
47931
48399
|
file: overlap
|
|
47932
48400
|
});
|
|
47933
48401
|
}
|
|
@@ -47943,7 +48411,7 @@ function defaultPreNArtifactLocations(env = process.env, home = homedir7()) {
|
|
|
47943
48411
|
const rpcOverride = env.OPENCODE_ANTHROPIC_AUTH_RPC_DIR?.trim();
|
|
47944
48412
|
return {
|
|
47945
48413
|
rpcRoots: [join32(root, "rpc")],
|
|
47946
|
-
rpcDirs: rpcOverride ? [
|
|
48414
|
+
rpcDirs: rpcOverride ? [resolve25(rpcOverride)] : [],
|
|
47947
48415
|
cacheKeepDirs: [
|
|
47948
48416
|
...new Set([
|
|
47949
48417
|
getDefaultCacheKeepRegistryDirectory("opencode", env),
|
|
@@ -48010,10 +48478,10 @@ async function preNArtifactBlockers(locations, pidAlive2 = defaultLiveness2.pidA
|
|
|
48010
48478
|
if (!/^port-\d+\.json$/.test(name))
|
|
48011
48479
|
continue;
|
|
48012
48480
|
const path2 = join32(dir, name);
|
|
48013
|
-
const
|
|
48014
|
-
if (
|
|
48481
|
+
const record17 = await readArtifact(path2, blockers);
|
|
48482
|
+
if (record17 === undefined || exempt(record17.value))
|
|
48015
48483
|
continue;
|
|
48016
|
-
const { value, startedAt } =
|
|
48484
|
+
const { value, startedAt } = record17;
|
|
48017
48485
|
const pid = value.pid;
|
|
48018
48486
|
if (typeof pid !== "number" || !Number.isSafeInteger(pid) || pid <= 0) {
|
|
48019
48487
|
blockers.push({ kind: "artifact-scan", path: path2, reason: "invalid" });
|
|
@@ -48029,11 +48497,11 @@ async function preNArtifactBlockers(locations, pidAlive2 = defaultLiveness2.pidA
|
|
|
48029
48497
|
if (!match)
|
|
48030
48498
|
continue;
|
|
48031
48499
|
const path2 = join32(dir, name);
|
|
48032
|
-
const
|
|
48033
|
-
if (
|
|
48500
|
+
const record17 = await readArtifact(path2, blockers);
|
|
48501
|
+
if (record17 === undefined || exempt(record17.value))
|
|
48034
48502
|
continue;
|
|
48035
48503
|
const pid = Number(match[1]);
|
|
48036
|
-
if (!recordPredatesBoot(
|
|
48504
|
+
if (!recordPredatesBoot(record17.startedAt, clock) && pidAlive2(pid))
|
|
48037
48505
|
blockers.push({ kind: "pre-n-artifact", artifact: path2, pid });
|
|
48038
48506
|
}
|
|
48039
48507
|
}
|
|
@@ -48227,11 +48695,15 @@ function mapSettingsMoveSources(sources2) {
|
|
|
48227
48695
|
pi: []
|
|
48228
48696
|
};
|
|
48229
48697
|
let accountSource;
|
|
48698
|
+
const live = sources2.some(killswitchOn);
|
|
48230
48699
|
for (const [source2, legacy] of sources2.entries()) {
|
|
48231
48700
|
if (!legacy.present)
|
|
48232
48701
|
continue;
|
|
48702
|
+
const dropFloors = live && !killswitchOn(legacy);
|
|
48233
48703
|
const values = legacy.value;
|
|
48234
48704
|
for (const [setting, value] of Object.entries(values)) {
|
|
48705
|
+
if (dropFloors && (KILLSWITCH_FLOOR_KEYS.has(setting) || setting === "killswitch_account_floors"))
|
|
48706
|
+
continue;
|
|
48235
48707
|
if (setting === "killswitch_account_floors") {
|
|
48236
48708
|
accountSource ??= source2;
|
|
48237
48709
|
floors[legacy.host] = values.killswitch_account_floors ?? [];
|
|
@@ -48239,6 +48711,7 @@ function mapSettingsMoveSources(sources2) {
|
|
|
48239
48711
|
entries.push({ source: source2, setting, value });
|
|
48240
48712
|
}
|
|
48241
48713
|
}
|
|
48714
|
+
entries.push(...keepImplicitProtection(sources2, entries));
|
|
48242
48715
|
if (accountSource !== undefined) {
|
|
48243
48716
|
const pi = new Map(floors.pi.map((entry2) => [entry2.account, entry2]));
|
|
48244
48717
|
const accounts = floors.opencode.map((entry2) => {
|
|
@@ -48258,102 +48731,40 @@ function mapSettingsMoveSources(sources2) {
|
|
|
48258
48731
|
}
|
|
48259
48732
|
return { entries, unmapped: [] };
|
|
48260
48733
|
}
|
|
48261
|
-
|
|
48262
|
-
|
|
48263
|
-
|
|
48264
|
-
// src/settings-host-import.ts
|
|
48265
|
-
var ranks = {
|
|
48266
|
-
quota_fail_closed_on_unknown_quota: { off: 0, default: 1, on: 2 },
|
|
48267
|
-
max_same_account_wait: { cache: 0, "15m": 1, off: 2 }
|
|
48268
|
-
};
|
|
48269
|
-
function stricter(key, legacy, file) {
|
|
48270
|
-
if (typeof legacy === "boolean")
|
|
48271
|
-
return legacy && file === false;
|
|
48272
|
-
if (typeof legacy === "number")
|
|
48273
|
-
return typeof file === "number" && legacy > file;
|
|
48274
|
-
const rank = ranks[key];
|
|
48275
|
-
if (!rank || typeof legacy !== "string" || typeof file !== "string")
|
|
48734
|
+
function killswitchOn(legacy) {
|
|
48735
|
+
if (!legacy.present)
|
|
48276
48736
|
return false;
|
|
48277
|
-
return (
|
|
48737
|
+
return (legacy.value.killswitch_enabled ?? legacySettingsProtection({}, legacy.host).killswitch_enabled) === true;
|
|
48278
48738
|
}
|
|
48279
|
-
function
|
|
48280
|
-
const
|
|
48281
|
-
const
|
|
48282
|
-
|
|
48283
|
-
for (const key of SETTINGS_PROTECTION_KEYS) {
|
|
48284
|
-
if (key === "killswitch_account_floors")
|
|
48285
|
-
continue;
|
|
48286
|
-
if (input.fileLevels[key]?.includes(host2))
|
|
48739
|
+
function keepImplicitProtection(sources2, entries) {
|
|
48740
|
+
const added = [];
|
|
48741
|
+
for (const setting of SETTINGS_PROTECTION_KEYS) {
|
|
48742
|
+
if (setting === "killswitch_account_floors")
|
|
48287
48743
|
continue;
|
|
48288
|
-
|
|
48744
|
+
const inherited = entries.filter((entry2) => entry2.setting === setting).sort((a, b) => a.source - b.source)[0];
|
|
48745
|
+
if (!inherited)
|
|
48289
48746
|
continue;
|
|
48290
|
-
|
|
48291
|
-
|
|
48292
|
-
|
|
48293
|
-
|
|
48294
|
-
|
|
48295
|
-
|
|
48296
|
-
|
|
48297
|
-
|
|
48298
|
-
setting
|
|
48299
|
-
|
|
48300
|
-
|
|
48301
|
-
...missing3.map((entry2) => ({ ...entry2, host: host2 }))
|
|
48302
|
-
]
|
|
48303
|
-
});
|
|
48747
|
+
for (const [source2, legacy] of sources2.entries()) {
|
|
48748
|
+
if (!legacy.present)
|
|
48749
|
+
continue;
|
|
48750
|
+
if (entries.some((entry2) => entry2.source === source2 && entry2.setting === setting))
|
|
48751
|
+
continue;
|
|
48752
|
+
const implicit = legacySettingsProtection({}, legacy.host)[setting];
|
|
48753
|
+
if (KILLSWITCH_FLOOR_KEYS.has(setting) && !killswitchOn(legacy))
|
|
48754
|
+
continue;
|
|
48755
|
+
if (settingsProtectionStricter(setting, implicit, inherited.value))
|
|
48756
|
+
added.push({ source: source2, setting, value: implicit });
|
|
48757
|
+
}
|
|
48304
48758
|
}
|
|
48305
|
-
return
|
|
48759
|
+
return added;
|
|
48306
48760
|
}
|
|
48761
|
+
// src/settings-move-run.ts
|
|
48762
|
+
import { readFile as readFile20 } from "node:fs/promises";
|
|
48763
|
+
import { isDeepStrictEqual as isDeepStrictEqual7 } from "node:util";
|
|
48764
|
+
import { parse as parse6 } from "jsonc-parser";
|
|
48307
48765
|
|
|
48308
48766
|
// src/settings-move-sources.ts
|
|
48309
48767
|
import { lstat as lstat22, readFile as readFile19 } from "node:fs/promises";
|
|
48310
|
-
|
|
48311
|
-
// src/settings-protection-legacy.ts
|
|
48312
|
-
function legacySettingsProtection(settings, host2, mode = "local") {
|
|
48313
|
-
const storage = {
|
|
48314
|
-
version: 1,
|
|
48315
|
-
accounts: [],
|
|
48316
|
-
...nativeAccountSettings(settings)
|
|
48317
|
-
};
|
|
48318
|
-
const main = getKillswitchThresholdsForAccount(storage);
|
|
48319
|
-
const minimum = getQuotaMinimumRemainingThresholds(storage);
|
|
48320
|
-
return {
|
|
48321
|
-
killswitch_enabled: isKillswitchEnabled(storage),
|
|
48322
|
-
killswitch_default_five_hour: main.five_hour,
|
|
48323
|
-
killswitch_default_seven_day: main.seven_day,
|
|
48324
|
-
killswitch_default_scoped: main.scoped,
|
|
48325
|
-
killswitch_account_floors: Object.keys(storage.killswitch?.accounts ?? {}).map((account) => ({
|
|
48326
|
-
account,
|
|
48327
|
-
host: mode === "claustrum" ? "both" : host2,
|
|
48328
|
-
...getKillswitchThresholdsForAccount(storage, account)
|
|
48329
|
-
})),
|
|
48330
|
-
quota_minimum_remaining_five_hour: minimum.five_hour,
|
|
48331
|
-
quota_minimum_remaining_seven_day: minimum.seven_day,
|
|
48332
|
-
quota_minimum_remaining_scoped: normalizeKillswitchThresholds(storage.quota?.minimumRemaining).scoped,
|
|
48333
|
-
quota_fail_closed_on_unknown_quota: toThreeWay(storage.quota?.failClosedOnUnknownQuota),
|
|
48334
|
-
max_same_account_wait: {
|
|
48335
|
-
"0": "off",
|
|
48336
|
-
"15": "15m",
|
|
48337
|
-
max: "cache"
|
|
48338
|
-
}[getMaxSameAccountWait(storage)]
|
|
48339
|
-
};
|
|
48340
|
-
}
|
|
48341
|
-
async function readLegacySettingsProtection(options) {
|
|
48342
|
-
try {
|
|
48343
|
-
const mode = await (options.readMode ?? readNativeEnrollmentMode)(options.host, options.env ?? process.env);
|
|
48344
|
-
if (mode === "claustrum")
|
|
48345
|
-
await options.initializeVaultSettings();
|
|
48346
|
-
const store = mode === "claustrum" ? options.vaultStore : options.localStore;
|
|
48347
|
-
const read = await store.readSettings();
|
|
48348
|
-
if (read.status !== "ready")
|
|
48349
|
-
return;
|
|
48350
|
-
return legacySettingsProtection(read.settings, options.host, mode);
|
|
48351
|
-
} catch {
|
|
48352
|
-
return;
|
|
48353
|
-
}
|
|
48354
|
-
}
|
|
48355
|
-
|
|
48356
|
-
// src/settings-move-sources.ts
|
|
48357
48768
|
var loggedSkips = new Set;
|
|
48358
48769
|
async function peerStoreAbsent(host2, store, options) {
|
|
48359
48770
|
try {
|
|
@@ -48398,9 +48809,13 @@ async function peerLayout(host2, options) {
|
|
|
48398
48809
|
throw new Error("The peer state layout transition is unfinished");
|
|
48399
48810
|
}
|
|
48400
48811
|
async function readPeerLegacySettingsProtection(options) {
|
|
48812
|
+
if (await hasPrivateSettingsConfigHome(options))
|
|
48813
|
+
throw new Error("A move under a private config home reads only its own store, so the peer store is unknown");
|
|
48401
48814
|
const paths2 = await resolveSettingsPaths(options.host, options);
|
|
48402
|
-
|
|
48403
|
-
|
|
48815
|
+
for (const key of ["account", "state"])
|
|
48816
|
+
if (await canonicalPath2(paths2.own[key], options) !== await canonicalPath2(paths2.defaults[options.host][key], options))
|
|
48817
|
+
throw new Error("The peer path overrides set here leave its store unknown");
|
|
48818
|
+
const explicitTarget = paths2.sourceRule === "own";
|
|
48404
48819
|
const store = paths2.defaults[options.host];
|
|
48405
48820
|
const mode = await (options.readMode ?? readNativeEnrollmentMode)(options.host, enrollmentEnv(options));
|
|
48406
48821
|
const pool = await resolveNativePoolPaths(store.account, store.state, await peerLayout(options.host, options));
|
|
@@ -48409,7 +48824,7 @@ async function readPeerLegacySettingsProtection(options) {
|
|
|
48409
48824
|
try {
|
|
48410
48825
|
text6 = await readFile19(selected.config, "utf8");
|
|
48411
48826
|
} catch (error) {
|
|
48412
|
-
if (error.code === "ENOENT" && mode === "local")
|
|
48827
|
+
if (error.code === "ENOENT" && mode === "local" && !explicitTarget)
|
|
48413
48828
|
return;
|
|
48414
48829
|
throw error;
|
|
48415
48830
|
}
|
|
@@ -48548,6 +48963,55 @@ async function prepareSettingsMoveSources(options) {
|
|
|
48548
48963
|
}
|
|
48549
48964
|
|
|
48550
48965
|
// src/settings-move-run.ts
|
|
48966
|
+
async function importSettingsHostStore(options, service, warn, retry) {
|
|
48967
|
+
const { host: host2, paths: paths2 } = options;
|
|
48968
|
+
const authority = { ...options, ...options.authority };
|
|
48969
|
+
const generation = service.snapshot();
|
|
48970
|
+
if (await hasSettingsImportRecord(paths2.target, host2, authority))
|
|
48971
|
+
return "adopt";
|
|
48972
|
+
if (generation.status === "missing")
|
|
48973
|
+
return "pending";
|
|
48974
|
+
if (generation.status !== "ready" || !generation.protection[host2].usable) {
|
|
48975
|
+
warn(`Settings file ${paths2.target} is not used by ${host2} yet: it is empty, unreadable or holds invalid protection settings, so ${host2}'s legacy settings can't be checked against it. ${host2} keeps its legacy settings until the file can be checked.`);
|
|
48976
|
+
return "retry";
|
|
48977
|
+
}
|
|
48978
|
+
let legacy;
|
|
48979
|
+
try {
|
|
48980
|
+
legacy = await readOwnLegacySettingsProtection({ ...options, paths: paths2 });
|
|
48981
|
+
} catch {
|
|
48982
|
+
warn(`Settings file ${paths2.target} is not used by ${host2} yet: its legacy settings could not be read to check them against the file. ${host2} keeps its legacy settings and checks again ${retry}.`);
|
|
48983
|
+
return "unknown";
|
|
48984
|
+
}
|
|
48985
|
+
if (service.snapshot().id !== generation.id) {
|
|
48986
|
+
warn(`Settings file ${paths2.target} is not used by ${host2} yet: it changed while ${host2}'s legacy settings were being checked against it. ${host2} keeps its legacy settings and checks again ${retry}.`);
|
|
48987
|
+
return "retry";
|
|
48988
|
+
}
|
|
48989
|
+
const plan2 = legacy ? planSettingsHostImport({
|
|
48990
|
+
host: host2,
|
|
48991
|
+
legacy,
|
|
48992
|
+
resolved: generation.protection[host2].values,
|
|
48993
|
+
fileLevels: generation.fileLevels
|
|
48994
|
+
}) : { keys: [], edits: [] };
|
|
48995
|
+
if (plan2.keys.length) {
|
|
48996
|
+
const expected = generation.source?.trim() ? parse6(generation.source.replace(/^\uFEFF/, ""), [], {
|
|
48997
|
+
allowTrailingComma: true
|
|
48998
|
+
}) : {};
|
|
48999
|
+
try {
|
|
49000
|
+
await service.update((current) => {
|
|
49001
|
+
if (current.status !== "ready" || SETTINGS_PROTECTION_KEYS.some((key) => !isDeepStrictEqual7(current.document[key], expected[key])))
|
|
49002
|
+
throw new SettingsRefusal("settings-busy", "Protection changed before import");
|
|
49003
|
+
return plan2.edits;
|
|
49004
|
+
}, host2, { importing: true });
|
|
49005
|
+
} catch {
|
|
49006
|
+
warn(`Settings file ${paths2.target} is not used by ${host2}: writing its legacy protection for ${plan2.keys.join(", ")} failed. ${host2} keeps its legacy settings and will retry the import ${retry}.`);
|
|
49007
|
+
return "refused";
|
|
49008
|
+
}
|
|
49009
|
+
}
|
|
49010
|
+
try {
|
|
49011
|
+
await writeSettingsImportRecord(paths2.target, host2, authority);
|
|
49012
|
+
} catch {}
|
|
49013
|
+
return "adopt";
|
|
49014
|
+
}
|
|
48551
49015
|
async function runSettingsMoveAtStartup(options) {
|
|
48552
49016
|
const paths2 = options.paths ?? await resolveSettingsPaths(options.host, options);
|
|
48553
49017
|
const authority = { ...options, ...options.authority };
|
|
@@ -48571,21 +49035,30 @@ async function runSettingsMoveAtStartup(options) {
|
|
|
48571
49035
|
});
|
|
48572
49036
|
const startOnFile = async (outcome2, move2) => {
|
|
48573
49037
|
const marked = await hasSettingsMoveMarker(paths2.target, authority);
|
|
48574
|
-
const service = await openSettingsService({
|
|
49038
|
+
const service = await openSettingsService({
|
|
49039
|
+
file: paths2.target,
|
|
49040
|
+
adopted: () => false
|
|
49041
|
+
});
|
|
48575
49042
|
if (!service)
|
|
48576
49043
|
throw new Error("Settings service did not open");
|
|
49044
|
+
let importPending = false;
|
|
48577
49045
|
try {
|
|
48578
49046
|
const generation = service.snapshot();
|
|
48579
|
-
if (!marked && generation.status === "ready") {
|
|
49047
|
+
if (!marked && generation.status === "ready" && generation.protection[options.host].usable) {
|
|
48580
49048
|
try {
|
|
48581
49049
|
await writeSettingsMoveMarker(paths2.target, authority);
|
|
48582
49050
|
} catch {
|
|
48583
49051
|
warn(`Could not write settings move marker ${paths2.target}.moved.`);
|
|
48584
49052
|
}
|
|
48585
49053
|
}
|
|
48586
|
-
const
|
|
48587
|
-
if (
|
|
48588
|
-
return
|
|
49054
|
+
const imported = await importSettingsHostStore({ ...options, paths: paths2 }, service, warn, "at the next start");
|
|
49055
|
+
if (imported === "refused")
|
|
49056
|
+
return result("legacy", "import-refused");
|
|
49057
|
+
if (imported === "unknown")
|
|
49058
|
+
return result("legacy", "import-unknown");
|
|
49059
|
+
if (imported === "retry")
|
|
49060
|
+
return result("legacy", "import-pending");
|
|
49061
|
+
importPending = imported === "pending";
|
|
48589
49062
|
if (generation.status !== "missing") {
|
|
48590
49063
|
const prepared2 = await prepareSettingsMoveSources({
|
|
48591
49064
|
...options,
|
|
@@ -48613,35 +49086,10 @@ async function runSettingsMoveAtStartup(options) {
|
|
|
48613
49086
|
} finally {
|
|
48614
49087
|
await service.dispose();
|
|
48615
49088
|
}
|
|
48616
|
-
return
|
|
48617
|
-
|
|
48618
|
-
|
|
48619
|
-
|
|
48620
|
-
if (generation.status !== "ready" || !generation.protection[host2].usable)
|
|
48621
|
-
return;
|
|
48622
|
-
if (await hasSettingsImportRecord(paths2.target, host2, authority))
|
|
48623
|
-
return;
|
|
48624
|
-
let legacy;
|
|
48625
|
-
try {
|
|
48626
|
-
legacy = await readOwnLegacySettingsProtection({ ...options, paths: paths2 });
|
|
48627
|
-
} catch {
|
|
48628
|
-
return;
|
|
48629
|
-
}
|
|
48630
|
-
const resolved = service.resolve(host2);
|
|
48631
|
-
const plan2 = legacy ? planSettingsHostImport({
|
|
48632
|
-
host: host2,
|
|
48633
|
-
legacy,
|
|
48634
|
-
resolved: Object.fromEntries(SETTINGS_PROTECTION_KEYS.map((key) => [key, resolved[key]])),
|
|
48635
|
-
fileLevels: generation.fileLevels
|
|
48636
|
-
}) : { keys: [], edits: [] };
|
|
48637
|
-
if (plan2.keys.length) {
|
|
48638
|
-
warn(`Settings file ${paths2.target} is not used by ${host2}: its legacy settings protect more for ${plan2.keys.join(", ")}. ${host2} keeps its legacy settings; set these for ${host2} in the settings file to start using it.`);
|
|
48639
|
-
return result("legacy", "import-refused");
|
|
48640
|
-
}
|
|
48641
|
-
try {
|
|
48642
|
-
await writeSettingsImportRecord(paths2.target, host2, authority);
|
|
48643
|
-
} catch {}
|
|
48644
|
-
return;
|
|
49089
|
+
return {
|
|
49090
|
+
...result("user-file", outcome2 ?? (marked ? "marker-present" : "done-already"), move2),
|
|
49091
|
+
...importPending ? { importPending: true } : {}
|
|
49092
|
+
};
|
|
48645
49093
|
};
|
|
48646
49094
|
if (paths2.separate)
|
|
48647
49095
|
return result("separate", "separate-install");
|
|
@@ -48721,51 +49169,162 @@ async function runSettingsMoveAtStartup(options) {
|
|
|
48721
49169
|
return result(mode, move.outcome, move);
|
|
48722
49170
|
}
|
|
48723
49171
|
// src/settings-start.ts
|
|
49172
|
+
var PREFLIGHT_RETRY_DELAYS_MS = [2000, 5000, 15000];
|
|
48724
49173
|
var warned3 = false;
|
|
48725
49174
|
function __resetSettingsStartWarningForTest() {
|
|
48726
49175
|
warned3 = false;
|
|
48727
49176
|
}
|
|
48728
49177
|
async function startSettings(options) {
|
|
49178
|
+
const preflight = async () => {
|
|
49179
|
+
const mode2 = await (options.readMode ?? readNativeEnrollmentMode)(options.host, options.env);
|
|
49180
|
+
if (mode2 === "local") {
|
|
49181
|
+
const stores = options.paths?.own ?? getSettingsStorePaths(options.host, options);
|
|
49182
|
+
const paths3 = options.ownPoolPaths ?? await resolveNativePoolPaths(stores.account, stores.state);
|
|
49183
|
+
await requireNativePoolAuthority(paths3);
|
|
49184
|
+
}
|
|
49185
|
+
};
|
|
49186
|
+
let refused2 = false;
|
|
49187
|
+
try {
|
|
49188
|
+
await preflight();
|
|
49189
|
+
} catch {
|
|
49190
|
+
refused2 = true;
|
|
49191
|
+
}
|
|
49192
|
+
const passPreflight = async () => {
|
|
49193
|
+
if (!refused2)
|
|
49194
|
+
return;
|
|
49195
|
+
await preflight();
|
|
49196
|
+
refused2 = false;
|
|
49197
|
+
};
|
|
48729
49198
|
const move = options.start?.move ?? runSettingsMoveAtStartup;
|
|
48730
49199
|
const open16 = options.start?.open ?? openSettingsService;
|
|
49200
|
+
let adopted = false;
|
|
48731
49201
|
const serviceOptions = (file2) => ({
|
|
48732
49202
|
file: file2,
|
|
48733
49203
|
host: options.host,
|
|
48734
49204
|
protection: options.protection,
|
|
48735
|
-
lockTimeoutMs: options.lockTimeoutMs
|
|
49205
|
+
lockTimeoutMs: options.lockTimeoutMs,
|
|
49206
|
+
adopted: () => adopted
|
|
48736
49207
|
});
|
|
49208
|
+
let paths2;
|
|
49209
|
+
const resolvePaths = async () => {
|
|
49210
|
+
paths2 ??= options.paths ?? await resolveSettingsPaths(options.host, options);
|
|
49211
|
+
return paths2;
|
|
49212
|
+
};
|
|
49213
|
+
const logged3 = new Set;
|
|
49214
|
+
const warnOnce = (message) => {
|
|
49215
|
+
if (logged3.has(message))
|
|
49216
|
+
return;
|
|
49217
|
+
logged3.add(message);
|
|
49218
|
+
if (options.log)
|
|
49219
|
+
options.log.warn(message);
|
|
49220
|
+
else
|
|
49221
|
+
logger2.warn("settings", message);
|
|
49222
|
+
};
|
|
49223
|
+
const adopt = async (service) => {
|
|
49224
|
+
const outcome2 = await importSettingsHostStore({ ...options, paths: await resolvePaths() }, service, warnOnce, "at its next settings check");
|
|
49225
|
+
if (outcome2 === "pending")
|
|
49226
|
+
return "pending";
|
|
49227
|
+
if (outcome2 !== "adopt")
|
|
49228
|
+
return false;
|
|
49229
|
+
adopted = true;
|
|
49230
|
+
service.noteAdoption?.();
|
|
49231
|
+
return true;
|
|
49232
|
+
};
|
|
49233
|
+
const track = (service) => {
|
|
49234
|
+
if (service)
|
|
49235
|
+
setSettingsAdoptionCheck(service, adopt);
|
|
49236
|
+
return service;
|
|
49237
|
+
};
|
|
48737
49238
|
let file = "";
|
|
48738
49239
|
let moved = false;
|
|
48739
|
-
|
|
48740
|
-
|
|
48741
|
-
|
|
48742
|
-
|
|
48743
|
-
|
|
48744
|
-
|
|
48745
|
-
|
|
48746
|
-
|
|
48747
|
-
|
|
48748
|
-
|
|
48749
|
-
|
|
48750
|
-
|
|
48751
|
-
|
|
48752
|
-
|
|
49240
|
+
if (!refused2) {
|
|
49241
|
+
try {
|
|
49242
|
+
const started = await move(options);
|
|
49243
|
+
file = started.paths.target;
|
|
49244
|
+
paths2 = started.paths;
|
|
49245
|
+
moved = started.mode === "user-file";
|
|
49246
|
+
adopted = moved && !started.importPending;
|
|
49247
|
+
if (!started.mayOpenService)
|
|
49248
|
+
return { mode: started.mode, file };
|
|
49249
|
+
const service = track(await open16(serviceOptions(file)));
|
|
49250
|
+
if (!service)
|
|
49251
|
+
return { mode: started.mode, file };
|
|
49252
|
+
if (started.importPending)
|
|
49253
|
+
markSettingsImportPending(service);
|
|
49254
|
+
return { mode: started.mode, file, service };
|
|
49255
|
+
} catch {
|
|
49256
|
+
if (!warned3) {
|
|
49257
|
+
warned3 = true;
|
|
49258
|
+
logger2.warn("settings", "Settings startup failed; protection settings use their last applied values until the settings file can be opened.");
|
|
49259
|
+
}
|
|
48753
49260
|
}
|
|
48754
49261
|
}
|
|
48755
|
-
const
|
|
49262
|
+
const openService = async () => {
|
|
48756
49263
|
if (!file)
|
|
48757
49264
|
return;
|
|
48758
49265
|
try {
|
|
48759
|
-
return await open16(serviceOptions(file));
|
|
49266
|
+
return track(await open16(serviceOptions(file)));
|
|
48760
49267
|
} catch {
|
|
48761
49268
|
return;
|
|
48762
49269
|
}
|
|
48763
49270
|
};
|
|
48764
49271
|
const probe2 = async () => {
|
|
48765
|
-
const
|
|
48766
|
-
file =
|
|
48767
|
-
return resolveSettingsMode(
|
|
49272
|
+
const resolved = await resolvePaths();
|
|
49273
|
+
file = resolved.target;
|
|
49274
|
+
return resolveSettingsMode(resolved, { ...options, ...options.authority });
|
|
49275
|
+
};
|
|
49276
|
+
const reopenLegacy = async () => {
|
|
49277
|
+
try {
|
|
49278
|
+
await passPreflight();
|
|
49279
|
+
} catch {
|
|
49280
|
+
return;
|
|
49281
|
+
}
|
|
49282
|
+
return openService();
|
|
48768
49283
|
};
|
|
49284
|
+
let importPending = false;
|
|
49285
|
+
const reopenOnFile = async () => {
|
|
49286
|
+
try {
|
|
49287
|
+
await passPreflight();
|
|
49288
|
+
} catch {
|
|
49289
|
+
return;
|
|
49290
|
+
}
|
|
49291
|
+
const service = await openService();
|
|
49292
|
+
if (!service)
|
|
49293
|
+
return;
|
|
49294
|
+
try {
|
|
49295
|
+
const adoption = await adopt(service);
|
|
49296
|
+
if (adoption) {
|
|
49297
|
+
importPending = adoption === "pending";
|
|
49298
|
+
return service;
|
|
49299
|
+
}
|
|
49300
|
+
} catch {}
|
|
49301
|
+
await service.dispose();
|
|
49302
|
+
return;
|
|
49303
|
+
};
|
|
49304
|
+
if (refused2) {
|
|
49305
|
+
if (options.paths?.separate)
|
|
49306
|
+
return { mode: "separate", file: options.paths.target };
|
|
49307
|
+
try {
|
|
49308
|
+
file = options.paths?.target ?? getSettingsFilePath(options);
|
|
49309
|
+
} catch {}
|
|
49310
|
+
let separate = false;
|
|
49311
|
+
const reopenAfterPreflight = Object.assign(async () => {
|
|
49312
|
+
if (separate)
|
|
49313
|
+
return;
|
|
49314
|
+
try {
|
|
49315
|
+
await passPreflight();
|
|
49316
|
+
const resolved = await resolvePaths();
|
|
49317
|
+
file = resolved.target;
|
|
49318
|
+
separate = resolved.separate;
|
|
49319
|
+
} catch {
|
|
49320
|
+
return;
|
|
49321
|
+
}
|
|
49322
|
+
if (separate)
|
|
49323
|
+
return;
|
|
49324
|
+
return openService();
|
|
49325
|
+
}, { retryDelaysMs: PREFLIGHT_RETRY_DELAYS_MS, separate: () => separate });
|
|
49326
|
+
return { mode: "legacy", file, reopen: reopenAfterPreflight };
|
|
49327
|
+
}
|
|
48769
49328
|
let mode = "user-file";
|
|
48770
49329
|
let unknown = false;
|
|
48771
49330
|
if (!moved) {
|
|
@@ -48782,7 +49341,7 @@ async function startSettings(options) {
|
|
|
48782
49341
|
}
|
|
48783
49342
|
}
|
|
48784
49343
|
if (mode === "legacy")
|
|
48785
|
-
return { mode, file, reopen };
|
|
49344
|
+
return { mode, file, reopen: reopenLegacy };
|
|
48786
49345
|
if (mode !== "user-file")
|
|
48787
49346
|
return { mode, file };
|
|
48788
49347
|
const recovered = await recoverSettingsProtection(file, options.host, options.protection, file ? options.host : undefined);
|
|
@@ -48795,8 +49354,9 @@ async function startSettings(options) {
|
|
|
48795
49354
|
},
|
|
48796
49355
|
rung: recovered.rung,
|
|
48797
49356
|
values: recovered.values,
|
|
48798
|
-
reopen,
|
|
48799
|
-
|
|
49357
|
+
reopen: reopenOnFile,
|
|
49358
|
+
importPending: () => importPending,
|
|
49359
|
+
...unknown ? { reopenLegacy, resolveAuthority: probe2 } : {}
|
|
48800
49360
|
}
|
|
48801
49361
|
};
|
|
48802
49362
|
}
|
|
@@ -48835,12 +49395,12 @@ function executeLaneStartCommand(input) {
|
|
|
48835
49395
|
// src/state-layout-decision.ts
|
|
48836
49396
|
import { mkdir as mkdir21, readdir as readdir11 } from "node:fs/promises";
|
|
48837
49397
|
import { homedir as homedir9 } from "node:os";
|
|
48838
|
-
import { basename as basename17, dirname as
|
|
49398
|
+
import { basename as basename17, dirname as dirname28, join as join35 } from "node:path";
|
|
48839
49399
|
|
|
48840
49400
|
// src/state-layout-move.ts
|
|
48841
49401
|
import { randomUUID as randomUUID27 } from "node:crypto";
|
|
48842
49402
|
import { lstat as lstat23, readdir as readdir10, readFile as readFile21, stat as stat16, unlink as unlink12 } from "node:fs/promises";
|
|
48843
|
-
import { basename as basename16, dirname as
|
|
49403
|
+
import { basename as basename16, dirname as dirname27, join as join33, sep as sep2 } from "node:path";
|
|
48844
49404
|
var ACCOUNT_FILE = "anthropic-auth.json";
|
|
48845
49405
|
var ACCOUNT_STATE_FILE = "anthropic-auth-state.json";
|
|
48846
49406
|
var LAYOUT_LOCK_NAME = "runtime-layout";
|
|
@@ -48920,7 +49480,7 @@ async function acquireHolderLock(ctx, holderFile, timeoutMs) {
|
|
|
48920
49480
|
} catch (error) {
|
|
48921
49481
|
if (error instanceof LockContentionError)
|
|
48922
49482
|
throw error;
|
|
48923
|
-
throw new HolderRegistrationError("unavailable",
|
|
49483
|
+
throw new HolderRegistrationError("unavailable", dirname27(holderFile), error);
|
|
48924
49484
|
}
|
|
48925
49485
|
}
|
|
48926
49486
|
async function acquireHolderLocks(dataset, ctx) {
|
|
@@ -49104,14 +49664,14 @@ async function drainCoalescedWrites(dataset) {
|
|
|
49104
49664
|
await drainVaultQuota(dataset.oldVault.roster);
|
|
49105
49665
|
forgetRelocationObservations();
|
|
49106
49666
|
}
|
|
49107
|
-
function relocationTombstone(
|
|
49667
|
+
function relocationTombstone(record17) {
|
|
49108
49668
|
return `${JSON.stringify({
|
|
49109
49669
|
version: 0,
|
|
49110
|
-
relocatedTo:
|
|
49111
|
-
stateRoot:
|
|
49112
|
-
identity:
|
|
49113
|
-
attempt:
|
|
49114
|
-
by:
|
|
49670
|
+
relocatedTo: record17.sub,
|
|
49671
|
+
stateRoot: record17.stateRoot,
|
|
49672
|
+
identity: record17.identity,
|
|
49673
|
+
attempt: record17.attempt,
|
|
49674
|
+
by: record17.by
|
|
49115
49675
|
})}
|
|
49116
49676
|
`;
|
|
49117
49677
|
}
|
|
@@ -49148,17 +49708,17 @@ async function removeOwnStaging(path2) {
|
|
|
49148
49708
|
throw error;
|
|
49149
49709
|
}
|
|
49150
49710
|
}
|
|
49151
|
-
function recordFilesProblem(
|
|
49152
|
-
if (
|
|
49153
|
-
return `it lists ${
|
|
49711
|
+
function recordFilesProblem(record17, dataset) {
|
|
49712
|
+
if (record17.files.length !== dataset.slots.length)
|
|
49713
|
+
return `it lists ${record17.files.length} files, not ${dataset.slots.length}`;
|
|
49154
49714
|
for (const slot of dataset.slots) {
|
|
49155
|
-
const file =
|
|
49715
|
+
const file = record17.files.find((candidate) => candidate.role === slot.role);
|
|
49156
49716
|
if (!file)
|
|
49157
49717
|
return `it has no ${slot.role} entry`;
|
|
49158
49718
|
if (file.from !== slot.from || file.to !== slot.to)
|
|
49159
49719
|
return `its ${slot.role} entry names ${file.from} and ${file.to}, not ${slot.from} and ${slot.to}`;
|
|
49160
49720
|
}
|
|
49161
|
-
for (const file of
|
|
49721
|
+
for (const file of record17.restore?.files ?? []) {
|
|
49162
49722
|
const slot = dataset.slots.find((candidate) => candidate.role === file.role);
|
|
49163
49723
|
if (!slot || file.from !== slot.from || file.to !== slot.to)
|
|
49164
49724
|
return `its restore lists ${file.from} and ${file.to} for ${file.role}`;
|
|
@@ -49194,7 +49754,7 @@ async function movePreconditionFailure(dataset, platform) {
|
|
|
49194
49754
|
if (platform !== "win32" && typeof process.getuid === "function" && info.uid !== process.getuid())
|
|
49195
49755
|
return `${path2} belongs to another user`;
|
|
49196
49756
|
}
|
|
49197
|
-
if (
|
|
49757
|
+
if (dirname27(slot.from) !== dataset.oldDir || basename16(slot.from) !== basename16(slot.configured))
|
|
49198
49758
|
return `${slot.configured} resolves to ${slot.from}, not to a file of its own in the config folder`;
|
|
49199
49759
|
const fromExists = await exists5(slot.from);
|
|
49200
49760
|
anyOld ||= fromExists;
|
|
@@ -49275,15 +49835,15 @@ async function owned2(ctx, step, expect) {
|
|
|
49275
49835
|
if (outcome2 === "skipped")
|
|
49276
49836
|
throw new Error(`anthropic-auth stopped: ${step.kind === "rename" ? step.to : step.path} changed while it was being replaced`);
|
|
49277
49837
|
}
|
|
49278
|
-
async function rollbackPreparing(
|
|
49279
|
-
const { attempt } =
|
|
49838
|
+
async function rollbackPreparing(record17, dataset, ctx) {
|
|
49839
|
+
const { attempt } = record17;
|
|
49280
49840
|
const slot = (role) => {
|
|
49281
|
-
const found =
|
|
49841
|
+
const found = record17.files.find((file) => file.role === role);
|
|
49282
49842
|
if (!found)
|
|
49283
49843
|
throw new StateLayoutRollbackRefused(dataset.sub, `no ${role} entry`);
|
|
49284
49844
|
return found;
|
|
49285
49845
|
};
|
|
49286
|
-
if (
|
|
49846
|
+
if (record17.barriers.journal === "present") {
|
|
49287
49847
|
const journal = slot("journal");
|
|
49288
49848
|
const moving = movingJournalPath(journal.from, attempt);
|
|
49289
49849
|
const movingThere = await exists5(moving);
|
|
@@ -49298,7 +49858,7 @@ async function rollbackPreparing(record16, dataset, ctx) {
|
|
|
49298
49858
|
await stateLayoutStep(ctx, "rollback:journal");
|
|
49299
49859
|
for (const role of ["localRuntime", "vaultRuntime"]) {
|
|
49300
49860
|
const file = slot(role);
|
|
49301
|
-
const original =
|
|
49861
|
+
const original = record17.barriers[role].original;
|
|
49302
49862
|
await removeOwnStaging(relocatingPath(file.from, attempt));
|
|
49303
49863
|
const found = await tombstoneAttempt(file.from);
|
|
49304
49864
|
if (found !== undefined && found !== attempt)
|
|
@@ -49327,7 +49887,7 @@ async function rollbackPreparing(record16, dataset, ctx) {
|
|
|
49327
49887
|
}
|
|
49328
49888
|
await ctx.fs.syncDirectory(dataset.oldDir);
|
|
49329
49889
|
await stateLayoutStep(ctx, "rollback:old-dir-flushed");
|
|
49330
|
-
for (const file of
|
|
49890
|
+
for (const file of record17.files) {
|
|
49331
49891
|
await removeOwnStaging(relocatingPath(file.to, attempt));
|
|
49332
49892
|
if (file.sha256 === null)
|
|
49333
49893
|
continue;
|
|
@@ -49345,7 +49905,7 @@ async function rollbackPreparing(record16, dataset, ctx) {
|
|
|
49345
49905
|
await ctx.fs.syncDirectory(dataset.sub);
|
|
49346
49906
|
await stateLayoutStep(ctx, "rollback:sub-flushed");
|
|
49347
49907
|
const rolledBack = {
|
|
49348
|
-
...
|
|
49908
|
+
...record17,
|
|
49349
49909
|
phase: "rolled-back",
|
|
49350
49910
|
rolledBackAt: ctx.now()
|
|
49351
49911
|
};
|
|
@@ -49357,19 +49917,19 @@ async function rollbackPreparing(record16, dataset, ctx) {
|
|
|
49357
49917
|
forgetRelocationObservations();
|
|
49358
49918
|
return rolledBack;
|
|
49359
49919
|
}
|
|
49360
|
-
async function cleanupOldCopies(
|
|
49920
|
+
async function cleanupOldCopies(record17, dataset, ctx) {
|
|
49361
49921
|
const kept = [];
|
|
49362
49922
|
const conflict = [];
|
|
49363
49923
|
const publish2 = (next2) => publishStateLayoutRecord(next2, {
|
|
49364
49924
|
assertLeases: () => ctx.stack.assertAll(),
|
|
49365
49925
|
expect: expectRecord(dataset.sub, {
|
|
49366
49926
|
phase: "committed",
|
|
49367
|
-
attempt:
|
|
49927
|
+
attempt: record17.attempt
|
|
49368
49928
|
})
|
|
49369
49929
|
}, ctx.fs);
|
|
49370
49930
|
const outcome2 = () => {
|
|
49371
49931
|
const next2 = {
|
|
49372
|
-
...
|
|
49932
|
+
...record17,
|
|
49373
49933
|
cleanup: conflict.length ? "conflict" : kept.length ? "kept" : "done",
|
|
49374
49934
|
...kept.length ? { kept: [...kept] } : {},
|
|
49375
49935
|
...conflict.length ? { conflict: [...conflict] } : {}
|
|
@@ -49385,16 +49945,16 @@ async function cleanupOldCopies(record16, dataset, ctx) {
|
|
|
49385
49945
|
return stateLayoutConflict(first?.old ?? dataset.oldPaths.state, first?.new ?? dataset.newPaths.state, cause);
|
|
49386
49946
|
};
|
|
49387
49947
|
try {
|
|
49388
|
-
const journalSlot =
|
|
49948
|
+
const journalSlot = record17.files.find((file) => file.role === "journal");
|
|
49389
49949
|
if (journalSlot && await exists5(journalSlot.from))
|
|
49390
49950
|
conflict.push({ old: journalSlot.from, new: journalSlot.to });
|
|
49391
49951
|
for (const role of RELOCATION_ROLES) {
|
|
49392
49952
|
if (role === "localRuntime" || role === "vaultRuntime")
|
|
49393
49953
|
continue;
|
|
49394
|
-
const file =
|
|
49954
|
+
const file = record17.files.find((candidate) => candidate.role === role);
|
|
49395
49955
|
if (!file)
|
|
49396
49956
|
continue;
|
|
49397
|
-
const path2 = role === "journal" ? movingJournalPath(file.from,
|
|
49957
|
+
const path2 = role === "journal" ? movingJournalPath(file.from, record17.attempt) : file.from;
|
|
49398
49958
|
await ctx.stack.assertAll();
|
|
49399
49959
|
const credential2 = CREDENTIAL_AUTHORITY_ROLES.includes(role);
|
|
49400
49960
|
let digest3;
|
|
@@ -49556,8 +50116,8 @@ async function moveDataset(dataset, ctx, checkArtifacts) {
|
|
|
49556
50116
|
logger2.error("state-layout", "anthropic-auth could not move its state; keeping the old folder", {
|
|
49557
50117
|
reason
|
|
49558
50118
|
});
|
|
49559
|
-
const
|
|
49560
|
-
return { status: "rolled-back", reason, record:
|
|
50119
|
+
const record17 = await rollbackAfterFailure(preparing, dataset, ctx);
|
|
50120
|
+
return { status: "rolled-back", reason, record: record17 };
|
|
49561
50121
|
}
|
|
49562
50122
|
const committed = {
|
|
49563
50123
|
...preparing,
|
|
@@ -49578,8 +50138,8 @@ async function moveDataset(dataset, ctx, checkArtifacts) {
|
|
|
49578
50138
|
await syncCommitted(dataset, ctx);
|
|
49579
50139
|
} else if (onDisk?.phase === "preparing" && onDisk.attempt === attempt) {
|
|
49580
50140
|
const reason = error instanceof Error ? error.message : String(error);
|
|
49581
|
-
const
|
|
49582
|
-
return { status: "rolled-back", reason, record:
|
|
50141
|
+
const record17 = await rollbackAfterFailure(preparing, dataset, ctx);
|
|
50142
|
+
return { status: "rolled-back", reason, record: record17 };
|
|
49583
50143
|
} else
|
|
49584
50144
|
throw error;
|
|
49585
50145
|
}
|
|
@@ -49632,10 +50192,10 @@ function refused2(message, paths2 = [], cause) {
|
|
|
49632
50192
|
logger2.error("state-layout", message, { code: "restore-refused", paths: paths2 });
|
|
49633
50193
|
return new StateLayoutRefusalError("restore-refused", message, paths2, cause);
|
|
49634
50194
|
}
|
|
49635
|
-
function requireRestoreDetail(
|
|
49636
|
-
const restore =
|
|
50195
|
+
function requireRestoreDetail(record17) {
|
|
50196
|
+
const restore = record17.restore;
|
|
49637
50197
|
if (!restore?.attempt || !restore.files || !restore.runtimes)
|
|
49638
|
-
throw refused2(`${layoutRecordPath(
|
|
50198
|
+
throw refused2(`${layoutRecordPath(record17.sub)} records an unfinished restore without the files it moved, so anthropic-auth can't finish it.`, [layoutRecordPath(record17.sub)]);
|
|
49639
50199
|
return {
|
|
49640
50200
|
...restore,
|
|
49641
50201
|
attempt: restore.attempt,
|
|
@@ -49696,9 +50256,9 @@ async function syncObservedRestoreRecord(dataset, ctx) {
|
|
|
49696
50256
|
throw new StateLayoutRefusalError("unsafe", `anthropic-auth could not make ${path2} durable, so it won't finish restoring its state; run ${RESTORE_LEGACY_COMMAND} again.`, [path2], error);
|
|
49697
50257
|
}
|
|
49698
50258
|
}
|
|
49699
|
-
async function finishRestoreRetirement(
|
|
49700
|
-
const restore = requireRestoreDetail(
|
|
49701
|
-
const kept = [...
|
|
50259
|
+
async function finishRestoreRetirement(record17, dataset, ctx) {
|
|
50260
|
+
const restore = requireRestoreDetail(record17);
|
|
50261
|
+
const kept = [...record17.restore?.kept ?? []];
|
|
49702
50262
|
for (const file of restore.files) {
|
|
49703
50263
|
try {
|
|
49704
50264
|
const digest3 = await digestFile(file.to);
|
|
@@ -49723,7 +50283,7 @@ async function finishRestoreRetirement(record16, dataset, ctx) {
|
|
|
49723
50283
|
await ctx.fs.syncDirectory(dataset.sub);
|
|
49724
50284
|
await stateLayoutStep(ctx, "restore:sub-flushed");
|
|
49725
50285
|
const done2 = {
|
|
49726
|
-
...
|
|
50286
|
+
...record17,
|
|
49727
50287
|
restore: { ...restore, cleanup: "done", ...kept.length ? { kept } : {} }
|
|
49728
50288
|
};
|
|
49729
50289
|
await publishStateLayoutRecord(done2, {
|
|
@@ -49734,13 +50294,13 @@ async function finishRestoreRetirement(record16, dataset, ctx) {
|
|
|
49734
50294
|
forgetRelocationObservations();
|
|
49735
50295
|
return done2;
|
|
49736
50296
|
}
|
|
49737
|
-
async function discardAbandonedRestore(
|
|
49738
|
-
const restore = requireRestoreDetail(
|
|
50297
|
+
async function discardAbandonedRestore(record17, dataset, ctx) {
|
|
50298
|
+
const restore = requireRestoreDetail(record17);
|
|
49739
50299
|
for (const file of restore.files)
|
|
49740
50300
|
if (await exists5(file.staging))
|
|
49741
50301
|
await owned2(ctx, { kind: "unlink", path: file.staging }, expectPresent(file.staging));
|
|
49742
50302
|
await ctx.fs.syncDirectory(dataset.oldDir);
|
|
49743
|
-
const { restore: _abandoned, ...move } =
|
|
50303
|
+
const { restore: _abandoned, ...move } = record17;
|
|
49744
50304
|
const committed = { ...move, phase: "committed" };
|
|
49745
50305
|
await publishStateLayoutRecord(committed, {
|
|
49746
50306
|
assertLeases: () => ctx.stack.assertAll(),
|
|
@@ -49750,8 +50310,8 @@ async function discardAbandonedRestore(record16, dataset, ctx) {
|
|
|
49750
50310
|
forgetRelocationObservations();
|
|
49751
50311
|
return committed;
|
|
49752
50312
|
}
|
|
49753
|
-
async function classifyStagedRestore(
|
|
49754
|
-
const restore = requireRestoreDetail(
|
|
50313
|
+
async function classifyStagedRestore(record17, dataset) {
|
|
50314
|
+
const restore = requireRestoreDetail(record17);
|
|
49755
50315
|
const problems = [];
|
|
49756
50316
|
const listed = (role) => restore.files.find((file) => file.role === role);
|
|
49757
50317
|
const isStaged = async (file) => {
|
|
@@ -49811,7 +50371,7 @@ async function classifyStagedRestore(record16, dataset) {
|
|
|
49811
50371
|
if (!file)
|
|
49812
50372
|
continue;
|
|
49813
50373
|
const staged = await isStaged(file);
|
|
49814
|
-
if (staged && tombstone ===
|
|
50374
|
+
if (staged && tombstone === record17.attempt)
|
|
49815
50375
|
barriers.push({
|
|
49816
50376
|
role,
|
|
49817
50377
|
action: { kind: "rename", file, over: "tombstone" }
|
|
@@ -49823,7 +50383,7 @@ async function classifyStagedRestore(record16, dataset) {
|
|
|
49823
50383
|
problems.push(`${file.staging} is missing, so ${legacy} can't be restored`);
|
|
49824
50384
|
else
|
|
49825
50385
|
problems.push(`${legacy} is no longer this move's tombstone while ${file.staging} still waits to replace it`);
|
|
49826
|
-
} else if (tombstone ===
|
|
50386
|
+
} else if (tombstone === record17.attempt)
|
|
49827
50387
|
barriers.push({
|
|
49828
50388
|
role,
|
|
49829
50389
|
action: { kind: "unlink-tombstone", path: legacy }
|
|
@@ -49842,36 +50402,36 @@ async function classifyStagedRestore(record16, dataset) {
|
|
|
49842
50402
|
}
|
|
49843
50403
|
return { data, barriers, problems };
|
|
49844
50404
|
}
|
|
49845
|
-
async function act(action,
|
|
50405
|
+
async function act(action, record17, ctx) {
|
|
49846
50406
|
if (action.kind === "none")
|
|
49847
50407
|
return;
|
|
49848
50408
|
if (action.kind === "unlink-tombstone") {
|
|
49849
|
-
await owned2(ctx, { kind: "unlink", path: action.path }, expectTombstone(action.path,
|
|
50409
|
+
await owned2(ctx, { kind: "unlink", path: action.path }, expectTombstone(action.path, record17.attempt));
|
|
49850
50410
|
return;
|
|
49851
50411
|
}
|
|
49852
50412
|
const { file, over } = action;
|
|
49853
|
-
const target2 = over === "absent" ? expectAbsent(file.from) : over === "present" ? expectPresent(file.from) : expectTombstone(file.from,
|
|
50413
|
+
const target2 = over === "absent" ? expectAbsent(file.from) : over === "present" ? expectPresent(file.from) : expectTombstone(file.from, record17.attempt);
|
|
49854
50414
|
await owned2(ctx, { kind: "rename", from: file.staging, to: file.from }, both(expectDigest(file.staging, file.sha256), target2));
|
|
49855
50415
|
}
|
|
49856
|
-
async function finishStagedRestore(
|
|
49857
|
-
const restore = requireRestoreDetail(
|
|
49858
|
-
const plan2 = await classifyStagedRestore(
|
|
50416
|
+
async function finishStagedRestore(record17, dataset, ctx) {
|
|
50417
|
+
const restore = requireRestoreDetail(record17);
|
|
50418
|
+
const plan2 = await classifyStagedRestore(record17, dataset);
|
|
49859
50419
|
if (plan2.problems.length)
|
|
49860
50420
|
throw refused2(`anthropic-auth can't finish restoring its state to ${dataset.oldDir}: ${plan2.problems.join("; ")}. Then run ${RESTORE_LEGACY_COMMAND} again.`, [dataset.oldDir]);
|
|
49861
50421
|
for (const { role, action } of plan2.data) {
|
|
49862
|
-
await act(action,
|
|
50422
|
+
await act(action, record17, ctx);
|
|
49863
50423
|
await stateLayoutStep(ctx, `restore:placed:${role}`);
|
|
49864
50424
|
}
|
|
49865
50425
|
await ctx.fs.syncDirectory(dataset.oldDir);
|
|
49866
50426
|
await stateLayoutStep(ctx, "restore:data-flushed");
|
|
49867
50427
|
for (const { role, action } of plan2.barriers) {
|
|
49868
|
-
await act(action,
|
|
50428
|
+
await act(action, record17, ctx);
|
|
49869
50429
|
await stateLayoutStep(ctx, `restore:placed:${role}`);
|
|
49870
50430
|
}
|
|
49871
50431
|
await ctx.fs.syncDirectory(dataset.oldDir);
|
|
49872
50432
|
await stateLayoutStep(ctx, "restore:barriers-flushed");
|
|
49873
50433
|
const restored = {
|
|
49874
|
-
...
|
|
50434
|
+
...record17,
|
|
49875
50435
|
phase: "restored",
|
|
49876
50436
|
restore: { ...restore, cleanup: "pending" }
|
|
49877
50437
|
};
|
|
@@ -49883,15 +50443,15 @@ async function finishStagedRestore(record16, dataset, ctx) {
|
|
|
49883
50443
|
forgetRelocationObservations();
|
|
49884
50444
|
return finishRestoreRetirement(restored, dataset, ctx);
|
|
49885
50445
|
}
|
|
49886
|
-
async function newRestoreProblems(
|
|
50446
|
+
async function newRestoreProblems(record17, dataset, options) {
|
|
49887
50447
|
const problems = [];
|
|
49888
|
-
if (
|
|
50448
|
+
if (record17.cleanup === "pending")
|
|
49889
50449
|
problems.push("the move has not finished removing the old copies; start OpenCode with anthropic-auth once and close it again");
|
|
49890
|
-
if (
|
|
49891
|
-
for (const pair of
|
|
50450
|
+
if (record17.cleanup === "conflict")
|
|
50451
|
+
for (const pair of record17.conflict ?? [])
|
|
49892
50452
|
problems.push(`two copies of the account state exist (${pair.old} and ${pair.new}); keep the one you trust and move the other out of both folders`);
|
|
49893
|
-
if (
|
|
49894
|
-
for (const path2 of
|
|
50453
|
+
if (record17.cleanup === "kept") {
|
|
50454
|
+
for (const path2 of record17.kept ?? [])
|
|
49895
50455
|
if (await exists5(path2))
|
|
49896
50456
|
problems.push(`${path2} changed after the move and was kept; move it aside or delete it`);
|
|
49897
50457
|
}
|
|
@@ -49901,20 +50461,20 @@ async function newRestoreProblems(record16, dataset, options) {
|
|
|
49901
50461
|
problems.push(`${describeFenceBlocker(blocker)} is still running`);
|
|
49902
50462
|
for (const slot of dataset.slots) {
|
|
49903
50463
|
if (slot.role === "localRuntime" || slot.role === "vaultRuntime") {
|
|
49904
|
-
if (await tombstoneAttempt(slot.from) !==
|
|
50464
|
+
if (await tombstoneAttempt(slot.from) !== record17.attempt)
|
|
49905
50465
|
problems.push(`${slot.from} is no longer the marker the move left there; move it aside`);
|
|
49906
50466
|
continue;
|
|
49907
50467
|
}
|
|
49908
50468
|
if (await exists5(slot.from))
|
|
49909
50469
|
problems.push(`${slot.from} came back after the move; move it aside or delete it`);
|
|
49910
50470
|
}
|
|
49911
|
-
const moving = movingJournalPath(dataset.oldPaths.journal,
|
|
50471
|
+
const moving = movingJournalPath(dataset.oldPaths.journal, record17.attempt);
|
|
49912
50472
|
if (await exists5(moving))
|
|
49913
50473
|
problems.push(`${moving} is still there; move it aside or delete it`);
|
|
49914
50474
|
return problems;
|
|
49915
50475
|
}
|
|
49916
|
-
async function startRestore(
|
|
49917
|
-
const problems = await newRestoreProblems(
|
|
50476
|
+
async function startRestore(record17, dataset, ctx, options) {
|
|
50477
|
+
const problems = await newRestoreProblems(record17, dataset, options);
|
|
49918
50478
|
if (problems.length)
|
|
49919
50479
|
throw refused2(`anthropic-auth can't restore its state to ${dataset.oldDir} yet: ${problems.join("; ")}. Then run ${RESTORE_LEGACY_COMMAND} again.`, [dataset.oldDir, dataset.sub]);
|
|
49920
50480
|
const attempt = randomUUID28();
|
|
@@ -49938,7 +50498,7 @@ async function startRestore(record16, dataset, ctx, options) {
|
|
|
49938
50498
|
}
|
|
49939
50499
|
const listed = (role) => files.some((file) => file.role === role);
|
|
49940
50500
|
const restoring = {
|
|
49941
|
-
...
|
|
50501
|
+
...record17,
|
|
49942
50502
|
phase: "restoring",
|
|
49943
50503
|
restore: {
|
|
49944
50504
|
attempt,
|
|
@@ -49956,7 +50516,7 @@ async function startRestore(record16, dataset, ctx, options) {
|
|
|
49956
50516
|
const current = await readStateLayoutRecord(dataset.sub).catch(() => {
|
|
49957
50517
|
return;
|
|
49958
50518
|
});
|
|
49959
|
-
return current?.phase === "committed" && current.attempt ===
|
|
50519
|
+
return current?.phase === "committed" && current.attempt === record17.attempt ? undefined : "layout.json is no longer the committed move";
|
|
49960
50520
|
}
|
|
49961
50521
|
}, ctx.fs);
|
|
49962
50522
|
await stateLayoutStep(ctx, "restore:restoring-written");
|
|
@@ -49981,11 +50541,11 @@ async function startRestore(record16, dataset, ctx, options) {
|
|
|
49981
50541
|
await stateLayoutStep(ctx, "restore:staged-written");
|
|
49982
50542
|
return finishStagedRestore(staged, dataset, ctx);
|
|
49983
50543
|
}
|
|
49984
|
-
function requireRecordMatches(
|
|
50544
|
+
function requireRecordMatches(record17, dataset) {
|
|
49985
50545
|
const path2 = layoutRecordPath(dataset.sub);
|
|
49986
|
-
if (
|
|
49987
|
-
throw new StateLayoutRefusalError("other-dataset", `${path2} belongs to another config folder (${
|
|
49988
|
-
const problem = recordFilesProblem(
|
|
50546
|
+
if (record17.identity !== dataset.identity || record17.oldDir !== dataset.oldDir || record17.sub !== dataset.sub || record17.storageIds.local !== dataset.storageIds.local || record17.storageIds.vault !== dataset.storageIds.vault)
|
|
50547
|
+
throw new StateLayoutRefusalError("other-dataset", `${path2} belongs to another config folder (${record17.oldDir}), not ${dataset.oldDir}. Check OPENCODE_CONFIG_DIR and any symlink to the config folder.`, [path2, record17.oldDir, dataset.oldDir]);
|
|
50548
|
+
const problem = recordFilesProblem(record17, dataset);
|
|
49989
50549
|
if (problem)
|
|
49990
50550
|
throw new StateLayoutRefusalError("marker-unreadable", `anthropic-auth can't use ${path2}: ${problem}.`, [path2]);
|
|
49991
50551
|
}
|
|
@@ -49997,12 +50557,12 @@ async function readRecord(sub) {
|
|
|
49997
50557
|
throw new StateLayoutRefusalError("marker-unreadable", `anthropic-auth can't read ${path2}, which records where its state is, so it won't restore anything. Restore the file from a backup or ask for help; do not delete the state folder.`, [path2], error);
|
|
49998
50558
|
}
|
|
49999
50559
|
}
|
|
50000
|
-
function finished(
|
|
50001
|
-
if (
|
|
50560
|
+
function finished(record17) {
|
|
50561
|
+
if (record17 === undefined)
|
|
50002
50562
|
return "anthropic-auth has not moved this state out of the config folder";
|
|
50003
|
-
if (
|
|
50563
|
+
if (record17.phase === "rolled-back")
|
|
50004
50564
|
return "the move of this state was undone before it finished";
|
|
50005
|
-
if (
|
|
50565
|
+
if (record17.phase === "restored" && record17.restore?.cleanup === "done")
|
|
50006
50566
|
return "this state was already restored to the config folder";
|
|
50007
50567
|
return;
|
|
50008
50568
|
}
|
|
@@ -50067,32 +50627,32 @@ async function restoreLegacyLayout(options = {}) {
|
|
|
50067
50627
|
}
|
|
50068
50628
|
await stateLayoutStep(ctx, "restore:locks-held");
|
|
50069
50629
|
for (let round = 0;round < 3; round++) {
|
|
50070
|
-
const
|
|
50071
|
-
const done2 = finished(
|
|
50072
|
-
if (done2 || !
|
|
50630
|
+
const record17 = await readRecord(sub);
|
|
50631
|
+
const done2 = finished(record17);
|
|
50632
|
+
if (done2 || !record17)
|
|
50073
50633
|
return { status: "not-moved", reason: done2 ?? "" };
|
|
50074
|
-
requireRecordMatches(
|
|
50634
|
+
requireRecordMatches(record17, dataset);
|
|
50075
50635
|
let result;
|
|
50076
|
-
switch (
|
|
50636
|
+
switch (record17.phase) {
|
|
50077
50637
|
case "preparing":
|
|
50078
50638
|
throw refused2(`A move of anthropic-auth's state for ${dataset.oldDir} did not finish. Start OpenCode with anthropic-auth once to undo it; there is then nothing to restore.`, [layoutRecordPath(sub)]);
|
|
50079
50639
|
case "restoring":
|
|
50080
|
-
await discardAbandonedRestore(
|
|
50640
|
+
await discardAbandonedRestore(record17, dataset, ctx);
|
|
50081
50641
|
continue;
|
|
50082
50642
|
case "committed":
|
|
50083
|
-
result = await startRestore(
|
|
50643
|
+
result = await startRestore(record17, dataset, ctx, options);
|
|
50084
50644
|
break;
|
|
50085
50645
|
case "restore-staged": {
|
|
50086
50646
|
await syncObservedRestoreRecord(dataset, ctx);
|
|
50087
50647
|
const problems = await holderProblems(join34(dataset.sub, HOLDER_FILE_NAME), options.liveness, true);
|
|
50088
50648
|
if (problems.length)
|
|
50089
50649
|
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]);
|
|
50090
|
-
result = await finishStagedRestore(
|
|
50650
|
+
result = await finishStagedRestore(record17, dataset, ctx);
|
|
50091
50651
|
break;
|
|
50092
50652
|
}
|
|
50093
50653
|
default:
|
|
50094
50654
|
await syncObservedRestoreRecord(dataset, ctx);
|
|
50095
|
-
result = await finishRestoreRetirement(
|
|
50655
|
+
result = await finishRestoreRetirement(record17, dataset, ctx);
|
|
50096
50656
|
}
|
|
50097
50657
|
return {
|
|
50098
50658
|
status: "restored",
|
|
@@ -50150,13 +50710,13 @@ function configIdentity(configDir) {
|
|
|
50150
50710
|
refuse5("io-failed", `anthropic-auth can't resolve its config folder ${configDir}: ${errorMessage(error)}`, [configDir], error);
|
|
50151
50711
|
}
|
|
50152
50712
|
}
|
|
50153
|
-
function noMoveRecord(
|
|
50154
|
-
return
|
|
50713
|
+
function noMoveRecord(record17) {
|
|
50714
|
+
return record17 === undefined || record17.phase === "rolled-back" || record17.phase === "restored" && record17.restore?.cleanup === "done";
|
|
50155
50715
|
}
|
|
50156
|
-
function requireRecordMatches2(
|
|
50157
|
-
if (
|
|
50158
|
-
refuse5("other-dataset", `${layoutRecordPath(dataset.sub)} belongs to another config folder (${
|
|
50159
|
-
const problem = recordFilesProblem(
|
|
50716
|
+
function requireRecordMatches2(record17, dataset) {
|
|
50717
|
+
if (record17.identity !== dataset.identity || record17.oldDir !== dataset.oldDir || record17.sub !== dataset.sub || record17.storageIds.local !== dataset.storageIds.local || record17.storageIds.vault !== dataset.storageIds.vault)
|
|
50718
|
+
refuse5("other-dataset", `${layoutRecordPath(dataset.sub)} belongs to another config folder (${record17.oldDir}), not ${dataset.oldDir}. Check OPENCODE_CONFIG_DIR and any symlink to the config folder.`, [layoutRecordPath(dataset.sub), record17.oldDir, dataset.oldDir]);
|
|
50719
|
+
const problem = recordFilesProblem(record17, dataset);
|
|
50160
50720
|
if (problem)
|
|
50161
50721
|
markerUnreadable(dataset.sub, new Error(problem));
|
|
50162
50722
|
}
|
|
@@ -50178,7 +50738,7 @@ async function preflightExistingAuthority(paths2, host2, env) {
|
|
|
50178
50738
|
for (const runtime2 of [paths2.runtime, vault.runtime])
|
|
50179
50739
|
if (await readRelocationPointer(runtime2))
|
|
50180
50740
|
return;
|
|
50181
|
-
for (const dir of new Set(nativeHolderDatasetFiles(paths2).map(
|
|
50741
|
+
for (const dir of new Set(nativeHolderDatasetFiles(paths2).map(dirname28)))
|
|
50182
50742
|
if (await readConfigDirMarker(dir) || await readStateLayoutMarker(dir))
|
|
50183
50743
|
return;
|
|
50184
50744
|
await requireNativePoolAuthority(paths2);
|
|
@@ -50190,24 +50750,24 @@ async function preflightOpenCodeAuthority(configDir, env, home) {
|
|
|
50190
50750
|
const identity5 = configIdentity(configDir);
|
|
50191
50751
|
if (identity5 !== undefined) {
|
|
50192
50752
|
const target2 = stateHomeTargetFor(identity5, { env, home });
|
|
50193
|
-
const
|
|
50194
|
-
if (
|
|
50753
|
+
const record17 = await readRecord2(target2.dir);
|
|
50754
|
+
if (record17?.phase === "committed") {
|
|
50195
50755
|
const dataset = await resolveRelocationDataset({
|
|
50196
50756
|
configDir,
|
|
50197
50757
|
identity: identity5,
|
|
50198
50758
|
stateRoot: target2.stateRoot,
|
|
50199
50759
|
sub: await canonicalPath2(target2.dir)
|
|
50200
50760
|
});
|
|
50201
|
-
requireRecordMatches2(
|
|
50761
|
+
requireRecordMatches2(record17, dataset);
|
|
50202
50762
|
await requireNativePoolAuthority(dataset.newPaths);
|
|
50203
50763
|
return;
|
|
50204
50764
|
}
|
|
50205
|
-
if (!noMoveRecord(
|
|
50765
|
+
if (!noMoveRecord(record17))
|
|
50206
50766
|
return;
|
|
50207
50767
|
}
|
|
50208
50768
|
}
|
|
50209
50769
|
const config = env.OPENCODE_ANTHROPIC_AUTH_FILE?.trim() || join35(configDir, ACCOUNT_FILE2);
|
|
50210
|
-
const state = env.OPENCODE_ANTHROPIC_AUTH_STATE_FILE?.trim() || (config.endsWith(ACCOUNT_FILE2) ? join35(
|
|
50770
|
+
const state = env.OPENCODE_ANTHROPIC_AUTH_STATE_FILE?.trim() || (config.endsWith(ACCOUNT_FILE2) ? join35(dirname28(config), ACCOUNT_STATE_FILE2) : `${config}.state.json`);
|
|
50211
50771
|
await preflightExistingAuthority(await resolveNativePoolPaths(config, state, LEGACY_STATE_LAYOUT), "opencode", env);
|
|
50212
50772
|
}
|
|
50213
50773
|
async function registerHeld(holderFile, paths2, kind, identity5, options, ctx) {
|
|
@@ -50225,7 +50785,7 @@ async function registerHeld(holderFile, paths2, kind, identity5, options, ctx) {
|
|
|
50225
50785
|
assertOwned: () => ctx.stack.assertAll()
|
|
50226
50786
|
});
|
|
50227
50787
|
} catch (error) {
|
|
50228
|
-
throw error instanceof HolderRegistrationError ? error : new HolderRegistrationError("unavailable",
|
|
50788
|
+
throw error instanceof HolderRegistrationError ? error : new HolderRegistrationError("unavailable", dirname28(holderFile), error);
|
|
50229
50789
|
}
|
|
50230
50790
|
}
|
|
50231
50791
|
function deferLegacyRegistration(paths2, dir, options, error) {
|
|
@@ -50243,7 +50803,11 @@ function deferLegacyRegistration(paths2, dir, options, error) {
|
|
|
50243
50803
|
async function registerLegacyHeld(oldDir, paths2, identity5, options, ctx) {
|
|
50244
50804
|
try {
|
|
50245
50805
|
await registerHeld(join35(oldDir, HOLDER_FILE_NAME), paths2, "legacy", identity5, options, ctx);
|
|
50246
|
-
return
|
|
50806
|
+
return {
|
|
50807
|
+
status: "registered",
|
|
50808
|
+
settled: Promise.resolve(),
|
|
50809
|
+
close() {}
|
|
50810
|
+
};
|
|
50247
50811
|
} catch (error) {
|
|
50248
50812
|
if (unmovedRegistrationPolicy(options) === "mandatory")
|
|
50249
50813
|
throw error;
|
|
@@ -50262,10 +50826,10 @@ function chooseLegacy(paths2, reasons2, log3, registration) {
|
|
|
50262
50826
|
};
|
|
50263
50827
|
}
|
|
50264
50828
|
async function admitHeld(dataset, options, ctx, moved, allowPendingCleanup) {
|
|
50265
|
-
const
|
|
50266
|
-
if (
|
|
50829
|
+
const record17 = await readRecord2(dataset.sub);
|
|
50830
|
+
if (record17?.phase !== "committed" || !allowPendingCleanup && record17.cleanup === "pending")
|
|
50267
50831
|
return "changed";
|
|
50268
|
-
requireRecordMatches2(
|
|
50832
|
+
requireRecordMatches2(record17, dataset);
|
|
50269
50833
|
const conflict = await checkStateHomeServing(stateHomeServingFiles(dataset.newPaths));
|
|
50270
50834
|
if (conflict) {
|
|
50271
50835
|
logger2.error("state-layout", conflict.message, {
|
|
@@ -50274,11 +50838,11 @@ async function admitHeld(dataset, options, ctx, moved, allowPendingCleanup) {
|
|
|
50274
50838
|
});
|
|
50275
50839
|
throw conflict;
|
|
50276
50840
|
}
|
|
50277
|
-
await warnReappearedMetadata(
|
|
50841
|
+
await warnReappearedMetadata(record17);
|
|
50278
50842
|
await registerHeld(join35(dataset.sub, HOLDER_FILE_NAME), dataset.newPaths, "state-home", dataset.identity, options, ctx);
|
|
50279
50843
|
const layout = { kind: "state-home", dir: dataset.sub };
|
|
50280
50844
|
recordProcessStateLayout(dataset.oldPaths.legacyConfig, layout);
|
|
50281
|
-
return { kind: "state-home", layout, dataset, record:
|
|
50845
|
+
return { kind: "state-home", layout, dataset, record: record17, moved };
|
|
50282
50846
|
}
|
|
50283
50847
|
async function admitFast(dataset, options, ctx) {
|
|
50284
50848
|
try {
|
|
@@ -50324,12 +50888,12 @@ async function readPointers(dataset) {
|
|
|
50324
50888
|
}
|
|
50325
50889
|
async function legacyHeld(dataset, options, ctx, reasons2, log3 = true) {
|
|
50326
50890
|
const pointed = await readPointers(dataset);
|
|
50327
|
-
const
|
|
50328
|
-
if (
|
|
50329
|
-
requireRecordMatches2(
|
|
50330
|
-
if (pointed && noMoveRecord(
|
|
50891
|
+
const record17 = await readRecord2(dataset.sub);
|
|
50892
|
+
if (record17)
|
|
50893
|
+
requireRecordMatches2(record17, dataset);
|
|
50894
|
+
if (pointed && noMoveRecord(record17))
|
|
50331
50895
|
markerUnreadable(dataset.sub);
|
|
50332
|
-
if (pointed || !noMoveRecord(
|
|
50896
|
+
if (pointed || !noMoveRecord(record17))
|
|
50333
50897
|
return "changed";
|
|
50334
50898
|
const registration = await registerLegacyHeld(dataset.oldDir, dataset.oldPaths, dataset.identity, options, ctx);
|
|
50335
50899
|
return chooseLegacy(dataset.oldPaths, reasons2, log3, registration);
|
|
@@ -50347,7 +50911,7 @@ async function oldFolderTransition(old, recordedMovingJournal) {
|
|
|
50347
50911
|
}
|
|
50348
50912
|
let names2;
|
|
50349
50913
|
try {
|
|
50350
|
-
names2 = await readdir11(
|
|
50914
|
+
names2 = await readdir11(dirname28(journal));
|
|
50351
50915
|
} catch (error) {
|
|
50352
50916
|
if (error?.code === "ENOENT")
|
|
50353
50917
|
return false;
|
|
@@ -50368,10 +50932,10 @@ async function recordedMovingJournal(journal, identity5, options) {
|
|
|
50368
50932
|
env: options.env ?? process.env,
|
|
50369
50933
|
home: options.home ?? homedir9()
|
|
50370
50934
|
});
|
|
50371
|
-
const
|
|
50372
|
-
if (
|
|
50935
|
+
const record17 = await readStateLayoutRecord(await canonicalPath2(target2.dir));
|
|
50936
|
+
if (record17?.barriers.journal !== "present")
|
|
50373
50937
|
return;
|
|
50374
|
-
return movingJournalPath(journal,
|
|
50938
|
+
return movingJournalPath(journal, record17.attempt);
|
|
50375
50939
|
} catch {
|
|
50376
50940
|
return;
|
|
50377
50941
|
}
|
|
@@ -50408,12 +50972,12 @@ function stateFolderUnreadable(dir, cause) {
|
|
|
50408
50972
|
async function decideOpenCodeStateLayout(options) {
|
|
50409
50973
|
const env = options.env ?? process.env;
|
|
50410
50974
|
const home = options.home ?? homedir9();
|
|
50411
|
-
const
|
|
50975
|
+
const fs5 = options.fs ?? defaultStateLayoutFs();
|
|
50412
50976
|
const configDir = getOpenCodeConfigDir(env, home);
|
|
50413
50977
|
if (options.requireExistingAuthority)
|
|
50414
50978
|
await preflightOpenCodeAuthority(configDir, env, home);
|
|
50415
50979
|
const newContext = () => ({
|
|
50416
|
-
fs:
|
|
50980
|
+
fs: fs5,
|
|
50417
50981
|
stack: new StateLayoutLockStack(options.onLockEvent),
|
|
50418
50982
|
release: anthropicAuthRelease(),
|
|
50419
50983
|
now: options.now ?? Date.now,
|
|
@@ -50423,7 +50987,7 @@ async function decideOpenCodeStateLayout(options) {
|
|
|
50423
50987
|
});
|
|
50424
50988
|
if (isExplicit(env)) {
|
|
50425
50989
|
const legacyConfig = env.OPENCODE_ANTHROPIC_AUTH_FILE?.trim() || join35(configDir, ACCOUNT_FILE2);
|
|
50426
|
-
const legacyState = env.OPENCODE_ANTHROPIC_AUTH_STATE_FILE?.trim() || (legacyConfig.endsWith(ACCOUNT_FILE2) ? join35(
|
|
50990
|
+
const legacyState = env.OPENCODE_ANTHROPIC_AUTH_STATE_FILE?.trim() || (legacyConfig.endsWith(ACCOUNT_FILE2) ? join35(dirname28(legacyConfig), ACCOUNT_STATE_FILE2) : `${legacyConfig}.state.json`);
|
|
50427
50991
|
const paths2 = await resolveNativePoolPaths(legacyConfig, legacyState, LEGACY_STATE_LAYOUT);
|
|
50428
50992
|
const registration = await registerNativePoolHolder({
|
|
50429
50993
|
paths: paths2,
|
|
@@ -50497,20 +51061,20 @@ async function decideOpenCodeStateLayout(options) {
|
|
|
50497
51061
|
refuse5("other-dataset", `${sub} holds anthropic-auth state for ${marker.identity}, not for ${target2.identity}. Check OPENCODE_CONFIG_DIR and any symlink to the config folder.`, [sub, marker.identity, target2.identity]);
|
|
50498
51062
|
const pointed = await readPointers(dataset);
|
|
50499
51063
|
for (let round = 0;round < 3; round++) {
|
|
50500
|
-
const
|
|
50501
|
-
if (
|
|
50502
|
-
requireRecordMatches2(
|
|
50503
|
-
if (pointed && noMoveRecord(
|
|
51064
|
+
const record17 = await readRecord2(sub);
|
|
51065
|
+
if (record17)
|
|
51066
|
+
requireRecordMatches2(record17, dataset);
|
|
51067
|
+
if (pointed && noMoveRecord(record17))
|
|
50504
51068
|
markerUnreadable(sub);
|
|
50505
|
-
if (
|
|
51069
|
+
if (record17?.phase === "restore-staged")
|
|
50506
51070
|
restoreUnfinished(dataset.oldDir);
|
|
50507
|
-
if (
|
|
51071
|
+
if (record17?.phase === "committed" && (record17.cleanup === "done" || record17.cleanup === "kept")) {
|
|
50508
51072
|
const admitted = await admitFast(dataset, options, newContext());
|
|
50509
51073
|
if (admitted !== "changed")
|
|
50510
51074
|
return admitted;
|
|
50511
51075
|
continue;
|
|
50512
51076
|
}
|
|
50513
|
-
if ((overrides.length || neverMove.length || !moveEnabled) && noMoveRecord(
|
|
51077
|
+
if ((overrides.length || neverMove.length || !moveEnabled) && noMoveRecord(record17)) {
|
|
50514
51078
|
const ctx = newContext();
|
|
50515
51079
|
const reasons2 = stayReasons.length ? stayReasons : [RELOCATION_MOVE_DISABLED_REASON];
|
|
50516
51080
|
try {
|
|
@@ -50538,7 +51102,7 @@ async function decideOpenCodeStateLayout(options) {
|
|
|
50538
51102
|
}
|
|
50539
51103
|
break;
|
|
50540
51104
|
}
|
|
50541
|
-
await ensureSubfolder(sub,
|
|
51105
|
+
await ensureSubfolder(sub, fs5);
|
|
50542
51106
|
for (let round = 0;round < 4; round++) {
|
|
50543
51107
|
const ctx = newContext();
|
|
50544
51108
|
try {
|
|
@@ -50551,8 +51115,8 @@ async function decideOpenCodeStateLayout(options) {
|
|
|
50551
51115
|
} catch (error) {
|
|
50552
51116
|
if (!(error instanceof LockContentionError))
|
|
50553
51117
|
refuse5("io-failed", `anthropic-auth can't take the layout lock beside ${layoutRecordPath(sub)}: ${errorMessage(error)}`, [layoutRecordPath(sub)], error);
|
|
50554
|
-
const
|
|
50555
|
-
if (
|
|
51118
|
+
const record17 = await readRecord2(sub);
|
|
51119
|
+
if (record17?.phase === "committed" && (record17.cleanup === "done" || record17.cleanup === "kept")) {
|
|
50556
51120
|
const admitted = await admitFast(dataset, options, newContext());
|
|
50557
51121
|
if (admitted !== "changed")
|
|
50558
51122
|
return admitted;
|
|
@@ -50574,7 +51138,7 @@ async function decideOpenCodeStateLayout(options) {
|
|
|
50574
51138
|
}
|
|
50575
51139
|
busy(dataset.configDir);
|
|
50576
51140
|
}
|
|
50577
|
-
async function ensureSubfolder(sub,
|
|
51141
|
+
async function ensureSubfolder(sub, fs5) {
|
|
50578
51142
|
try {
|
|
50579
51143
|
if (process.platform === "win32") {
|
|
50580
51144
|
await ensureWindowsOwnerOnlyDirectory(sub);
|
|
@@ -50583,9 +51147,9 @@ async function ensureSubfolder(sub, fs4) {
|
|
|
50583
51147
|
const created = await mkdir21(sub, { recursive: true, mode: 448 });
|
|
50584
51148
|
if (created === undefined)
|
|
50585
51149
|
return;
|
|
50586
|
-
for (let dir =
|
|
50587
|
-
await
|
|
50588
|
-
if (dir ===
|
|
51150
|
+
for (let dir = dirname28(sub);; dir = dirname28(dir)) {
|
|
51151
|
+
await fs5.syncDirectory(dir);
|
|
51152
|
+
if (dir === dirname28(created) || dir === dirname28(dir))
|
|
50589
51153
|
break;
|
|
50590
51154
|
}
|
|
50591
51155
|
} catch (error) {
|
|
@@ -50595,36 +51159,36 @@ async function ensureSubfolder(sub, fs4) {
|
|
|
50595
51159
|
}
|
|
50596
51160
|
}
|
|
50597
51161
|
async function underLayoutLock(dataset, options, ctx, overrides, neverMove) {
|
|
50598
|
-
const
|
|
50599
|
-
if (
|
|
50600
|
-
requireRecordMatches2(
|
|
50601
|
-
if (
|
|
51162
|
+
const record17 = await readRecord2(dataset.sub);
|
|
51163
|
+
if (record17)
|
|
51164
|
+
requireRecordMatches2(record17, dataset);
|
|
51165
|
+
if (record17?.phase === "restore-staged")
|
|
50602
51166
|
restoreUnfinished(dataset.oldDir);
|
|
50603
|
-
if (
|
|
51167
|
+
if (record17?.phase === "restoring" || record17?.phase === "restored" && record17.restore?.cleanup !== "done") {
|
|
50604
51168
|
if (overrides.length)
|
|
50605
51169
|
refuse5("restore-unfinished", `A restore of anthropic-auth's state for ${dataset.oldDir} did not finish; start anthropic-auth without path overrides (${overrides.join(", ")}), or run ${RESTORE_LEGACY_COMMAND} again.`, [layoutRecordPath(dataset.sub)]);
|
|
50606
51170
|
await acquireHolderLocks(dataset, ctx);
|
|
50607
|
-
if (
|
|
50608
|
-
await discardAbandonedRestore(
|
|
51171
|
+
if (record17.phase === "restoring")
|
|
51172
|
+
await discardAbandonedRestore(record17, dataset, ctx);
|
|
50609
51173
|
else {
|
|
50610
51174
|
await syncObservedRestoreRecord(dataset, ctx);
|
|
50611
|
-
await finishRestoreRetirement(
|
|
51175
|
+
await finishRestoreRetirement(record17, dataset, ctx);
|
|
50612
51176
|
}
|
|
50613
51177
|
return "again";
|
|
50614
51178
|
}
|
|
50615
|
-
if (
|
|
51179
|
+
if (record17?.phase === "committed") {
|
|
50616
51180
|
try {
|
|
50617
51181
|
await syncCommitted(dataset, ctx);
|
|
50618
51182
|
} catch (error) {
|
|
50619
51183
|
refuse5("unsafe", `anthropic-auth could not make the move of its state to ${dataset.sub} durable, so it won't use either copy.`, [layoutRecordPath(dataset.sub)], error);
|
|
50620
51184
|
}
|
|
50621
51185
|
await acquireHolderLocks(dataset, ctx);
|
|
50622
|
-
if ((
|
|
51186
|
+
if ((record17.cleanup === "pending" || record17.cleanup === "conflict") && !overrides.length) {
|
|
50623
51187
|
const mark = ctx.stack.size;
|
|
50624
51188
|
try {
|
|
50625
51189
|
await drainCoalescedWrites(dataset);
|
|
50626
51190
|
await acquireDataLocks(dataset, ctx);
|
|
50627
|
-
await cleanupOldCopies(
|
|
51191
|
+
await cleanupOldCopies(record17, dataset, ctx);
|
|
50628
51192
|
} catch (error) {
|
|
50629
51193
|
if (error instanceof StateLayoutCrash)
|
|
50630
51194
|
throw error;
|
|
@@ -50638,13 +51202,13 @@ async function underLayoutLock(dataset, options, ctx, overrides, neverMove) {
|
|
|
50638
51202
|
const admitted2 = await admitHeld(dataset, options, ctx, false, true);
|
|
50639
51203
|
return admitted2 === "changed" ? "again" : admitted2;
|
|
50640
51204
|
}
|
|
50641
|
-
if (
|
|
51205
|
+
if (record17?.phase === "preparing") {
|
|
50642
51206
|
if (overrides.length)
|
|
50643
51207
|
refuse5("unsafe", `A move of anthropic-auth's state for ${dataset.oldDir} did not finish; start anthropic-auth without path overrides (${overrides.join(", ")}) to finish it.`, [layoutRecordPath(dataset.sub)]);
|
|
50644
51208
|
await acquireHolderLocks(dataset, ctx);
|
|
50645
51209
|
await drainCoalescedWrites(dataset);
|
|
50646
51210
|
await acquireDataLocks(dataset, ctx);
|
|
50647
|
-
await rollbackPreparing(
|
|
51211
|
+
await rollbackPreparing(record17, dataset, ctx);
|
|
50648
51212
|
return "again";
|
|
50649
51213
|
}
|
|
50650
51214
|
const stay = async (reasons2, log3 = true) => {
|
|
@@ -50986,8 +51550,13 @@ export {
|
|
|
50986
51550
|
settingsRecreationFloors,
|
|
50987
51551
|
settingsMoveHolderFiles,
|
|
50988
51552
|
settingsImportRecordPath,
|
|
51553
|
+
settingsFileUnusableText,
|
|
50989
51554
|
settingsFileSets,
|
|
51555
|
+
settingsFileProblem,
|
|
51556
|
+
settingsFileLevels,
|
|
50990
51557
|
settingsDefinition,
|
|
51558
|
+
settingsCheckPendingText,
|
|
51559
|
+
setSettingsAdoptionCheck,
|
|
50991
51560
|
setRelocationMoveEnabledForTests,
|
|
50992
51561
|
setLogLevel2 as setLogLevel,
|
|
50993
51562
|
setFastModeEnabled,
|
|
@@ -51170,6 +51739,7 @@ export {
|
|
|
51170
51739
|
mergeHeaderQuotaSnapshot,
|
|
51171
51740
|
mergeHeaderQuotaForPersistence,
|
|
51172
51741
|
mergeAnthropicBetas,
|
|
51742
|
+
markSettingsImportPending,
|
|
51173
51743
|
mapSettingsMoveSources,
|
|
51174
51744
|
malformedSettingsText,
|
|
51175
51745
|
logger2 as logger,
|
|
@@ -51188,6 +51758,7 @@ export {
|
|
|
51188
51758
|
isTerminatedSseFrame,
|
|
51189
51759
|
isStateLayoutRefusalCode,
|
|
51190
51760
|
isSseCandidateFrame,
|
|
51761
|
+
isSettingsImportPending,
|
|
51191
51762
|
isServerFallbackUsageMarker,
|
|
51192
51763
|
isSeparateSettingsInstall,
|
|
51193
51764
|
isSecretKey,
|
|
@@ -51231,6 +51802,7 @@ export {
|
|
|
51231
51802
|
isApiKeyAccount,
|
|
51232
51803
|
invalidSettingsWriteText,
|
|
51233
51804
|
inspectNativeHostAuthEntry,
|
|
51805
|
+
importSettingsHostStore,
|
|
51234
51806
|
hostRetryResponse,
|
|
51235
51807
|
hostRetryHeaders,
|
|
51236
51808
|
homeDefaultConfigDir,
|
|
@@ -51250,6 +51822,7 @@ export {
|
|
|
51250
51822
|
getStickyRoutingStatePath,
|
|
51251
51823
|
getSettingsStorePaths,
|
|
51252
51824
|
getSettingsFilePath,
|
|
51825
|
+
getSettingsAdoptionCheck,
|
|
51253
51826
|
getScopedQuotaWindowForModel,
|
|
51254
51827
|
getRoutingMode,
|
|
51255
51828
|
getRequestGzipLatchPath,
|
|
@@ -51464,6 +52037,7 @@ export {
|
|
|
51464
52037
|
StateLayoutFileError,
|
|
51465
52038
|
SseFrameTooLargeError,
|
|
51466
52039
|
SettingsRecreationRefusal,
|
|
52040
|
+
SettingsAdoptionRefusal,
|
|
51467
52041
|
SessionCacheActivity,
|
|
51468
52042
|
STICKY_ROUTING_MAIN_ACCOUNT_ID,
|
|
51469
52043
|
STICKY_ROUTING_ASSIGNMENT_TTL_MS,
|