@cortexkit/anthropic-auth-core 2.8.0 → 2.9.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 +61 -4
- package/dist/request-gzip.d.ts +3 -2
- package/dist/state-layout-decision.d.ts +8 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -41502,7 +41502,9 @@ function getRequestGzipLatch(path2) {
|
|
|
41502
41502
|
}
|
|
41503
41503
|
return latch;
|
|
41504
41504
|
}
|
|
41505
|
-
function getRequestGzipLatchPath(accountStoragePath) {
|
|
41505
|
+
function getRequestGzipLatchPath(accountStoragePath, layout = LEGACY_STATE_LAYOUT) {
|
|
41506
|
+
if (layout.kind === "state-home")
|
|
41507
|
+
return stateHomeFilePaths(layout.dir).requestGzip;
|
|
41506
41508
|
const name = basename10(accountStoragePath);
|
|
41507
41509
|
const stem = name.endsWith(".json") ? name.slice(0, -5) : name;
|
|
41508
41510
|
return join27(dirname23(accountStoragePath), `${stem}-request-gzip.json`);
|
|
@@ -43210,7 +43212,7 @@ async function restoreLegacyLayout(options = {}) {
|
|
|
43210
43212
|
// src/state-layout-decision.ts
|
|
43211
43213
|
var ACCOUNT_FILE2 = "anthropic-auth.json";
|
|
43212
43214
|
var ACCOUNT_STATE_FILE2 = "anthropic-auth-state.json";
|
|
43213
|
-
var RELOCATION_MOVE_ENABLED =
|
|
43215
|
+
var RELOCATION_MOVE_ENABLED = true;
|
|
43214
43216
|
var moveEnabledOverride;
|
|
43215
43217
|
function setRelocationMoveEnabledForTests(enabled) {
|
|
43216
43218
|
moveEnabledOverride = enabled;
|
|
@@ -43267,6 +43269,49 @@ async function readRecord2(sub) {
|
|
|
43267
43269
|
markerUnreadable(sub, error);
|
|
43268
43270
|
}
|
|
43269
43271
|
}
|
|
43272
|
+
async function readPreflightCustodyAuthority(host, env) {
|
|
43273
|
+
const authority = await vaultAuthority(getHostClaustrumEnrollmentPaths(host, env), `anthropic-auth-${host}`);
|
|
43274
|
+
return authority === "host" ? "vault" : authority;
|
|
43275
|
+
}
|
|
43276
|
+
async function preflightExistingAuthority(paths, host, env) {
|
|
43277
|
+
if (await readPreflightCustodyAuthority(host, env) !== "local")
|
|
43278
|
+
return;
|
|
43279
|
+
const vault = nativeVaultPaths(paths, LEGACY_STATE_LAYOUT);
|
|
43280
|
+
for (const runtime2 of [paths.runtime, vault.runtime])
|
|
43281
|
+
if (await readRelocationPointer(runtime2))
|
|
43282
|
+
return;
|
|
43283
|
+
for (const dir of new Set(nativeHolderDatasetFiles(paths).map(dirname25)))
|
|
43284
|
+
if (await readConfigDirMarker(dir) || await readStateLayoutMarker(dir))
|
|
43285
|
+
return;
|
|
43286
|
+
await requireNativePoolAuthority(paths);
|
|
43287
|
+
}
|
|
43288
|
+
async function preflightOpenCodeAuthority(configDir, env, home) {
|
|
43289
|
+
if (await readPreflightCustodyAuthority("opencode", env) !== "local")
|
|
43290
|
+
return;
|
|
43291
|
+
if (!isExplicit(env)) {
|
|
43292
|
+
const identity3 = configIdentity(configDir);
|
|
43293
|
+
if (identity3 !== undefined) {
|
|
43294
|
+
const target2 = stateHomeTargetFor(identity3, { env, home });
|
|
43295
|
+
const record12 = await readRecord2(target2.dir);
|
|
43296
|
+
if (record12?.phase === "committed") {
|
|
43297
|
+
const dataset = await resolveRelocationDataset({
|
|
43298
|
+
configDir,
|
|
43299
|
+
identity: identity3,
|
|
43300
|
+
stateRoot: target2.stateRoot,
|
|
43301
|
+
sub: await canonicalPath(target2.dir)
|
|
43302
|
+
});
|
|
43303
|
+
requireRecordMatches2(record12, dataset);
|
|
43304
|
+
await requireNativePoolAuthority(dataset.newPaths);
|
|
43305
|
+
return;
|
|
43306
|
+
}
|
|
43307
|
+
if (!noMoveRecord(record12))
|
|
43308
|
+
return;
|
|
43309
|
+
}
|
|
43310
|
+
}
|
|
43311
|
+
const config = env.OPENCODE_ANTHROPIC_AUTH_FILE?.trim() || join31(configDir, ACCOUNT_FILE2);
|
|
43312
|
+
const state = env.OPENCODE_ANTHROPIC_AUTH_STATE_FILE?.trim() || (config.endsWith(ACCOUNT_FILE2) ? join31(dirname25(config), ACCOUNT_STATE_FILE2) : `${config}.state.json`);
|
|
43313
|
+
await preflightExistingAuthority(await resolveNativePoolPaths(config, state, LEGACY_STATE_LAYOUT), "opencode", env);
|
|
43314
|
+
}
|
|
43270
43315
|
async function registerHeld(holderFile, paths, kind, identity3, options, ctx) {
|
|
43271
43316
|
const entry2 = await buildHolderEntry({
|
|
43272
43317
|
role: options.role,
|
|
@@ -43467,6 +43512,8 @@ async function decideOpenCodeStateLayout(options) {
|
|
|
43467
43512
|
const home = options.home ?? homedir8();
|
|
43468
43513
|
const fs3 = options.fs ?? defaultStateLayoutFs();
|
|
43469
43514
|
const configDir = getOpenCodeConfigDir(env, home);
|
|
43515
|
+
if (options.requireExistingAuthority)
|
|
43516
|
+
await preflightOpenCodeAuthority(configDir, env, home);
|
|
43470
43517
|
const newContext = () => ({
|
|
43471
43518
|
fs: fs3,
|
|
43472
43519
|
stack: new StateLayoutLockStack(options.onLockEvent),
|
|
@@ -43796,8 +43843,16 @@ function decisionKey(options) {
|
|
|
43796
43843
|
function decideOpenCodeStateLayoutOnce(options) {
|
|
43797
43844
|
const key = decisionKey(options);
|
|
43798
43845
|
const known = processDecisions.get(key);
|
|
43799
|
-
if (known)
|
|
43800
|
-
|
|
43846
|
+
if (known) {
|
|
43847
|
+
if (!options.requireExistingAuthority)
|
|
43848
|
+
return known;
|
|
43849
|
+
return known.then(async (decision2) => {
|
|
43850
|
+
const env = options.env ?? process.env;
|
|
43851
|
+
const home = options.home ?? homedir8();
|
|
43852
|
+
await preflightOpenCodeAuthority(getOpenCodeConfigDir(env, home), env, home);
|
|
43853
|
+
return decision2;
|
|
43854
|
+
});
|
|
43855
|
+
}
|
|
43801
43856
|
const decision = decideOpenCodeStateLayout(options);
|
|
43802
43857
|
processDecisions.set(key, decision);
|
|
43803
43858
|
decision.catch(() => {
|
|
@@ -43810,6 +43865,8 @@ function resetStateLayoutDecisionsForTests() {
|
|
|
43810
43865
|
processDecisions.clear();
|
|
43811
43866
|
}
|
|
43812
43867
|
async function decidePiStateLayout(options) {
|
|
43868
|
+
if (options.requireExistingAuthority)
|
|
43869
|
+
await preflightExistingAuthority(options.paths, "pi", options.env ?? process.env);
|
|
43813
43870
|
const registration = await registerNativePoolHolder({
|
|
43814
43871
|
paths: options.paths,
|
|
43815
43872
|
role: options.role,
|
package/dist/request-gzip.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type StateLayout } from './state-layout-paths.ts';
|
|
1
2
|
/** Claude Code's own opt-out: `0`/`false` turns gzip off, `1`/`true` forces it. */
|
|
2
3
|
export declare const GZIP_REQUEST_BODIES_ENV = "CLAUDE_CODE_GZIP_REQUEST_BODIES";
|
|
3
4
|
/** How long a persisted latch keeps gzip off. */
|
|
@@ -43,8 +44,8 @@ export declare class RequestGzipLatch {
|
|
|
43
44
|
}
|
|
44
45
|
/** One latch per storage path, shared by every send path in this process. */
|
|
45
46
|
export declare function getRequestGzipLatch(path?: string): RequestGzipLatch;
|
|
46
|
-
/** The latch
|
|
47
|
-
export declare function getRequestGzipLatchPath(accountStoragePath: string): string;
|
|
47
|
+
/** The advisory latch starts empty in state-home; legacy and Pi keep their account-file sibling. */
|
|
48
|
+
export declare function getRequestGzipLatchPath(accountStoragePath: string, layout?: StateLayout): string;
|
|
48
49
|
/** Decide, in Claude Code's order, whether this request body goes out gzipped. */
|
|
49
50
|
export declare function decideRequestGzip(options: {
|
|
50
51
|
url: string | URL;
|
|
@@ -16,7 +16,7 @@ import { type StateLayoutRecord } from './state-layout-record.ts';
|
|
|
16
16
|
* checks, and the mandatory state-home registration. The release that ships
|
|
17
17
|
* the move turns it on.
|
|
18
18
|
*/
|
|
19
|
-
export declare const RELOCATION_MOVE_ENABLED =
|
|
19
|
+
export declare const RELOCATION_MOVE_ENABLED = true;
|
|
20
20
|
/** Turn the move on or off for this process, or back to the default; tests only. */
|
|
21
21
|
export declare function setRelocationMoveEnabledForTests(enabled: boolean | undefined): void;
|
|
22
22
|
/**
|
|
@@ -41,6 +41,8 @@ export interface DecideStateLayoutOptions {
|
|
|
41
41
|
role: HolderRole;
|
|
42
42
|
env?: NodeJS.ProcessEnv;
|
|
43
43
|
home?: string;
|
|
44
|
+
/** Read-only local migration check before registration; offline setup omits it. */
|
|
45
|
+
requireExistingAuthority?: boolean;
|
|
44
46
|
/** Filesystem seam; `node:fs` for this platform otherwise. */
|
|
45
47
|
fs?: StateLayoutFs;
|
|
46
48
|
liveness?: HolderLiveness;
|
|
@@ -91,6 +93,8 @@ export type StateLayoutDecision = {
|
|
|
91
93
|
* neither copy may be served safely; the process must then do no pool I/O
|
|
92
94
|
* for the dataset. `RelocatedError` is never thrown here: a dataset moved by
|
|
93
95
|
* a newer version of the same layout rules is served from its new folder.
|
|
96
|
+
* With `requireExistingAuthority`, an unmigrated local dataset refuses with
|
|
97
|
+
* `NativeAuthorityError` before locks, registration or relocation writes.
|
|
94
98
|
*/
|
|
95
99
|
export declare function decideOpenCodeStateLayout(options: DecideStateLayoutOptions): Promise<StateLayoutDecision>;
|
|
96
100
|
/**
|
|
@@ -112,6 +116,9 @@ export declare function resetStateLayoutDecisionsForTests(): void;
|
|
|
112
116
|
export declare function decidePiStateLayout(options: {
|
|
113
117
|
paths: NativePoolPaths;
|
|
114
118
|
role: HolderRole;
|
|
119
|
+
env?: NodeJS.ProcessEnv;
|
|
120
|
+
/** Read-only local migration check before registration; offline setup omits it. */
|
|
121
|
+
requireExistingAuthority?: boolean;
|
|
115
122
|
onLockEvent?: (event: NativeLockEvent) => void;
|
|
116
123
|
liveness?: HolderLiveness;
|
|
117
124
|
lockTimeoutMs?: number;
|