@cortexkit/anthropic-auth-core 2.11.2 → 2.11.4

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.
Files changed (51) hide show
  1. package/dist/accounts.d.ts +30 -16
  2. package/dist/cachekeep.d.ts +8 -5
  3. package/dist/holder-registry.d.ts +2 -0
  4. package/dist/index.d.ts +20 -2
  5. package/dist/index.js +9205 -3902
  6. package/dist/internal-types/claustrum/custody.d.ts +4 -0
  7. package/dist/internal-types/claustrum/index.d.ts +1 -1
  8. package/dist/internal-types/routing-accessor/index.d.ts +34 -9
  9. package/dist/internal-types/settings/define.d.ts +35 -0
  10. package/dist/internal-types/settings/descriptors.d.ts +97 -0
  11. package/dist/internal-types/settings/edit.d.ts +24 -0
  12. package/dist/internal-types/settings/handle.d.ts +30 -0
  13. package/dist/internal-types/settings/index.d.ts +10 -0
  14. package/dist/internal-types/settings/move.d.ts +76 -0
  15. package/dist/internal-types/settings/parse.d.ts +24 -0
  16. package/dist/internal-types/settings/paths.d.ts +12 -0
  17. package/dist/internal-types/settings/refusal.d.ts +7 -0
  18. package/dist/internal-types/settings/resolve.d.ts +15 -0
  19. package/dist/internal-types/settings/schema.d.ts +29 -0
  20. package/dist/internal-types/settings/snapshot.d.ts +24 -0
  21. package/dist/layout-fence.d.ts +7 -1
  22. package/dist/native-account-runtime.d.ts +24 -8
  23. package/dist/native-migration-source.d.ts +5 -0
  24. package/dist/native-migration.d.ts +15 -0
  25. package/dist/native-runtime-settings.d.ts +72 -0
  26. package/dist/native-settings-write.d.ts +48 -0
  27. package/dist/native-setup-settings.d.ts +39 -0
  28. package/dist/path-options.d.ts +16 -0
  29. package/dist/pool-paths.d.ts +2 -1
  30. package/dist/routing-relay.d.ts +6 -1
  31. package/dist/routing-wait.d.ts +14 -0
  32. package/dist/routing.d.ts +2 -2
  33. package/dist/settings-authority.d.ts +8 -0
  34. package/dist/settings-definition.d.ts +621 -0
  35. package/dist/settings-host-import.d.ts +25 -0
  36. package/dist/settings-mode.d.ts +36 -0
  37. package/dist/settings-move-fence.d.ts +49 -0
  38. package/dist/settings-move-map.d.ts +7 -0
  39. package/dist/settings-move-run.d.ts +31 -0
  40. package/dist/settings-move-source.d.ts +52 -0
  41. package/dist/settings-move-sources.d.ts +59 -0
  42. package/dist/settings-paths.d.ts +30 -0
  43. package/dist/settings-protection-copy.d.ts +12 -0
  44. package/dist/settings-protection-legacy.d.ts +22 -0
  45. package/dist/settings-record.d.ts +14 -0
  46. package/dist/settings-service.d.ts +215 -0
  47. package/dist/settings-start.d.ts +57 -0
  48. package/dist/settings-three-way.d.ts +5 -0
  49. package/dist/sticky-routing.d.ts +14 -0
  50. package/package.json +3 -2
  51. package/schema/anthropic-auth.schema.json +1081 -0
@@ -0,0 +1,49 @@
1
+ import { type HolderEntry, type HolderFileContents, type HolderLiveness, type NativeHolderRegistration } from './holder-registry.ts';
2
+ import { type FenceBlocker, type PreNArtifactLocations } from './layout-fence.ts';
3
+ import { type PathResolutionOptions } from './path-options.ts';
4
+ /** The first release that serves settings from the shared user file. */
5
+ export declare const SETTINGS_MOVE_FIRST_RELEASE = "2.12.0";
6
+ export type SettingsMoveFenceBlocker = {
7
+ kind: 'registration';
8
+ reason: string;
9
+ } | {
10
+ kind: 'floor';
11
+ release: string;
12
+ } | {
13
+ kind: 'settings-holder';
14
+ holderFile: string;
15
+ pid: number | null;
16
+ release: string | null;
17
+ reason: 'unreadable' | 'release';
18
+ } | Extract<FenceBlocker, {
19
+ kind: 'holder-file' | 'pre-n-artifact' | 'artifact-scan';
20
+ }>;
21
+ export interface SettingsMoveFenceOptions extends PathResolutionOptions {
22
+ /** Every settings store the move will read, including overridden stores. */
23
+ stores: readonly string[];
24
+ /** A failed or still-pending registration prevents only this settings move. */
25
+ registration: Pick<NativeHolderRegistration, 'status'> | undefined;
26
+ floor?: string;
27
+ /**
28
+ * This code copy's own holder entry, the only one the fence ignores.
29
+ * `instance` defaults to this copy's; another copy of the code loaded in
30
+ * the same process is judged by its release like any other holder.
31
+ */
32
+ self?: Pick<HolderEntry, 'pid' | 'incarnation'> & Partial<Pick<HolderEntry, 'instance'>>;
33
+ liveness?: HolderLiveness;
34
+ artifacts?: PreNArtifactLocations;
35
+ /** Tests inject holder sets without consulting the installed package release. */
36
+ readHolders?: (path: string) => Promise<HolderFileContents | undefined>;
37
+ }
38
+ /** Check both hosts' standard holder folders as well as every move source's folder. */
39
+ export declare function settingsMoveHolderFiles(options: PathResolutionOptions & {
40
+ stores: readonly string[];
41
+ }): Promise<string[]>;
42
+ /**
43
+ * A closed fence is not a startup refusal: the caller keeps serving legacy settings.
44
+ * Any older live holder blocks, even when its file list shares no path with a move source.
45
+ */
46
+ export declare function checkSettingsMoveFence(options: SettingsMoveFenceOptions): Promise<{
47
+ open: boolean;
48
+ blockers: SettingsMoveFenceBlocker[];
49
+ }>;
@@ -0,0 +1,7 @@
1
+ import type { LegacySource, MapResult } from "./internal-types/settings/index.js";
2
+ /**
3
+ * Map validated readSettingsMoveSource results, with at most one source per host.
4
+ * OpenCode must precede Pi: common-auth uses the first source's value as default.
5
+ * Ordinary settings stay whole so common-auth can preserve each host's value.
6
+ */
7
+ export declare function mapSettingsMoveSources(sources: LegacySource[]): MapResult;
@@ -0,0 +1,31 @@
1
+ import { type MoveOutcome, type MoveResult, moveSettingsOnce } from "./internal-types/settings/index.js";
2
+ import { type SettingsMode, type SettingsModeOptions } from './settings-mode.ts';
3
+ import { type SettingsMoveFenceOptions } from './settings-move-fence.ts';
4
+ import { prepareSettingsMoveSources, type SettingsMoveSourcesOptions } from './settings-move-sources.ts';
5
+ import { type SettingsPaths } from './settings-paths.ts';
6
+ export interface SettingsMoveStartupOptions extends SettingsMoveSourcesOptions {
7
+ fence: Pick<SettingsMoveFenceOptions, 'registration' | 'floor' | 'self' | 'liveness' | 'artifacts' | 'readHolders'>;
8
+ authority?: Pick<SettingsModeOptions, 'fs' | 'ownership' | 'now'>;
9
+ dependencies?: {
10
+ prepareSources?: typeof prepareSettingsMoveSources;
11
+ move?: typeof moveSettingsOnce;
12
+ };
13
+ }
14
+ export interface SettingsMoveStartupResult {
15
+ paths: SettingsPaths;
16
+ mode: SettingsMode;
17
+ /** Legacy mode still needs watch callbacks and timer checks for a peer's move. */
18
+ mayOpenService: boolean;
19
+ outcome: MoveOutcome | 'marker-present' | 'source-unavailable'
20
+ /** The file is in charge, but this host's legacy store protects more. */
21
+ | 'import-refused';
22
+ move?: MoveResult;
23
+ }
24
+ /**
25
+ * Await once at host startup, before opening the settings service's first resolve.
26
+ * Menu, watch and timer authority checks must not call the mover or retry a failed
27
+ * attempt; a failed start keeps legacy settings until another host moves them or
28
+ * this host restarts. The setup command, run while hosts are stopped, uses
29
+ * authority checks only, never this entry point.
30
+ */
31
+ export declare function runSettingsMoveAtStartup(options: SettingsMoveStartupOptions): Promise<SettingsMoveStartupResult>;
@@ -0,0 +1,52 @@
1
+ import type { MoveSource } from "./internal-types/settings/index.js";
2
+ import type { SettingsHost } from './settings-paths.ts';
3
+ import { type SettingsValues } from './settings-service.ts';
4
+ /** Legacy paths by schema key; cache_keep_window combines the two named sibling hours. */
5
+ export declare const SETTINGS_MOVE_PATHS: {
6
+ readonly routing_mode: readonly ["routing", "mode"];
7
+ readonly max_same_account_wait: readonly ["routing", "maxSameAccountWait"];
8
+ readonly fallback_on: readonly ["fallbackOn"];
9
+ readonly refresh_enabled: readonly ["refresh", "enabled"];
10
+ readonly refresh_interval_minutes: readonly ["refresh", "intervalMinutes"];
11
+ readonly refresh_refresh_before_expiry_minutes: readonly ["refresh", "refreshBeforeExpiryMinutes"];
12
+ readonly quota_enabled: readonly ["quota", "enabled"];
13
+ readonly quota_check_interval_minutes: readonly ["quota", "checkIntervalMinutes"];
14
+ readonly quota_refresh_every_n_requests: readonly ["quota", "refreshEveryNRequests"];
15
+ readonly quota_minimum_remaining_five_hour: readonly ["quota", "minimumRemaining", "five_hour"];
16
+ readonly quota_minimum_remaining_seven_day: readonly ["quota", "minimumRemaining", "seven_day"];
17
+ readonly quota_minimum_remaining_scoped: readonly ["quota", "minimumRemaining", "scoped"];
18
+ readonly quota_fail_closed_on_unknown_quota: readonly ["quota", "failClosedOnUnknownQuota"];
19
+ readonly quota_show_toasts: readonly ["quota", "showToasts"];
20
+ readonly quota_header_feed_enabled: readonly ["quotaHeaderFeed", "enabled"];
21
+ readonly killswitch_enabled: readonly ["killswitch", "enabled"];
22
+ readonly killswitch_default_five_hour: readonly ["killswitch", "main", "five_hour"];
23
+ readonly killswitch_default_seven_day: readonly ["killswitch", "main", "seven_day"];
24
+ readonly killswitch_default_scoped: readonly ["killswitch", "main", "scoped"];
25
+ readonly killswitch_account_floors: readonly ["killswitch", "accounts"];
26
+ readonly claude_cache_enabled: readonly ["claudeCache", "enabled"];
27
+ readonly claude_cache_mode: readonly ["claudeCache", "mode"];
28
+ readonly cache_keep_enabled: readonly ["cacheKeep", "enabled"];
29
+ readonly cache_keep_always: readonly ["cacheKeep", "always"];
30
+ readonly cache_keep_window: readonly ["cacheKeep", "startHour", "endHour"];
31
+ readonly cache_keep_subagents: readonly ["cacheKeep", "subagents"];
32
+ readonly dump_enabled: readonly ["dump", "enabled"];
33
+ readonly prime_enabled: readonly ["prime", "enabled"];
34
+ readonly claude_fast_enabled: readonly ["claudeFast", "enabled"];
35
+ readonly cost_zeroing_enabled: readonly ["costZeroing", "enabled"];
36
+ readonly log_level: readonly ["logging", "level"];
37
+ readonly thinking_binding_prefix_mismatch_behavior: readonly ["thinkingBinding", "prefixMismatchBehavior"];
38
+ readonly turn_end_note_tools: readonly ["turnEndNote", "tools"];
39
+ };
40
+ export interface SettingsMoveSourceOptions {
41
+ host: SettingsHost;
42
+ path: string;
43
+ log?: {
44
+ warn: (message: string) => void;
45
+ };
46
+ /** Read-only authority comparisons must not consume the move's diagnostics. */
47
+ quiet?: boolean;
48
+ }
49
+ /** Parse legacy JSON, validating each moved field independently under the mover's locks. */
50
+ export declare function readSettingsMoveSource(text: string, options: SettingsMoveSourceOptions): Partial<SettingsValues>;
51
+ /** The common-auth mover supplies the bytes and keeps the source locks held. */
52
+ export declare function createSettingsMoveSource(options: SettingsMoveSourceOptions & Pick<MoveSource, 'locks'>): MoveSource;
@@ -0,0 +1,59 @@
1
+ import type { MoveSource } from "./internal-types/settings/index.js";
2
+ import { readNativeEnrollmentMode } from './native-enrollment-authority.ts';
3
+ import { type NativePoolPaths } from './pool-paths.ts';
4
+ import { type SettingsHost, type SettingsPathOptions, type SettingsPaths } from './settings-paths.ts';
5
+ import type { SettingsProtectionValues } from './settings-service.ts';
6
+ export interface SettingsMoveSourcesOptions extends SettingsPathOptions {
7
+ host: SettingsHost;
8
+ paths?: SettingsPaths;
9
+ /** The running host's already resolved paths retain its startup layout decision. */
10
+ ownPoolPaths?: NativePoolPaths;
11
+ /** Initialize only this runtime's vault settings, including first-read seeding. */
12
+ initializeVaultSettings: () => Promise<void>;
13
+ readMode?: typeof readNativeEnrollmentMode;
14
+ log?: {
15
+ warn: (message: string) => void;
16
+ };
17
+ /** Inspect existing sources without seeding a vault or changing legacy state. */
18
+ inspectOnly?: boolean;
19
+ }
20
+ export type SettingsMoveSourcesResult = {
21
+ status: 'ready';
22
+ sources: MoveSource[];
23
+ } | {
24
+ status: 'separate';
25
+ sources: [];
26
+ } | {
27
+ status: 'unavailable';
28
+ sources: [];
29
+ host: SettingsHost;
30
+ reason: 'custody-unreadable' | 'seeding-failed' | 'paths-unreadable' | 'vault-unseeded';
31
+ cause: unknown;
32
+ };
33
+ /**
34
+ * Read the other host's legacy protection for recreating a missing settings
35
+ * file: its default store, through its current custody and state layout,
36
+ * without seeding a vault, taking locks or writing anything. A local store
37
+ * that doesn't exist, or a separate install, returns undefined: that host
38
+ * has no set to keep. Anything that exists but can't be read, including an
39
+ * unreadable custody or layout and vault settings that were never seeded,
40
+ * throws, so the caller can tell an unknown set from a missing one.
41
+ */
42
+ export declare function readPeerLegacySettingsProtection(options: SettingsPathOptions & {
43
+ host: SettingsHost;
44
+ readMode?: typeof readNativeEnrollmentMode;
45
+ }): Promise<SettingsProtectionValues | undefined>;
46
+ /**
47
+ * Read this host's own legacy protection, through its current custody, to
48
+ * check whether a settings file it did not move holds it. Vault settings
49
+ * that were never seeded are read from the local store they would be seeded
50
+ * from. A store that doesn't exist returns undefined; anything that exists
51
+ * but can't be read throws. Takes no locks and writes nothing.
52
+ */
53
+ export declare function readOwnLegacySettingsProtection(options: SettingsMoveSourcesOptions): Promise<SettingsProtectionValues | undefined>;
54
+ /**
55
+ * Prepare the common-auth mover's sources, not a startup or authority decision.
56
+ * An unavailable own source must keep this start in legacy mode; the caller logs
57
+ * that result once and must not call the mover or publish a marker.
58
+ */
59
+ export declare function prepareSettingsMoveSources(options: SettingsMoveSourcesOptions): Promise<SettingsMoveSourcesResult>;
@@ -0,0 +1,30 @@
1
+ import { type PathResolutionOptions } from './path-options.ts';
2
+ export type SettingsHost = 'opencode' | 'pi';
3
+ export interface SettingsPathOptions extends PathResolutionOptions {
4
+ warn?: (message: string) => void;
5
+ }
6
+ export interface SettingsStorePaths {
7
+ account: string;
8
+ state: string;
9
+ }
10
+ export interface SettingsPaths {
11
+ /** The configured filename; retain it for watches and writes. */
12
+ target: string;
13
+ marker: string;
14
+ separate: boolean;
15
+ sourceRule: 'default' | 'own';
16
+ /** Only the acting process's stores, including its overrides. */
17
+ own: SettingsStorePaths;
18
+ /** Naming default sources does not read files from the other settings host. */
19
+ defaults: Record<SettingsHost, SettingsStorePaths>;
20
+ }
21
+ export declare function getSettingsFilePath(options?: SettingsPathOptions): string;
22
+ /** Pi's extension directory precedence, independent of OpenCode's overrides. */
23
+ export declare function getPiAgentDir(options?: PathResolutionOptions): string;
24
+ export declare function getSettingsStorePaths(host: SettingsHost, options?: PathResolutionOptions): SettingsStorePaths;
25
+ export declare function getDefaultSettingsStorePaths(host: SettingsHost, options?: PathResolutionOptions): SettingsStorePaths;
26
+ export declare function hasPrivateSettingsConfigHome(options?: PathResolutionOptions): Promise<boolean>;
27
+ /** Compare this host's account and state paths against its XDG-aware defaults. */
28
+ export declare function isSeparateSettingsInstall(host: SettingsHost, options?: SettingsPathOptions): Promise<boolean>;
29
+ /** Resolve once at startup; callers keep the result off the request path. */
30
+ export declare function resolveSettingsPaths(host: SettingsHost, options?: SettingsPathOptions): Promise<SettingsPaths>;
@@ -0,0 +1,12 @@
1
+ import { type PublicationOptions } from './publication-rename.ts';
2
+ import type { SettingsHost } from './settings-paths.ts';
3
+ import { type SettingsProtectionValues } from './settings-service.ts';
4
+ export interface SettingsProtectionCopyEntry {
5
+ /** Time the published generation was read, not when its detached write ran. */
6
+ readAt: number;
7
+ values: SettingsProtectionValues;
8
+ }
9
+ /** Missing or invalid host entries return no values, never a partial protection set. */
10
+ export declare function readSettingsProtectionCopy(file: string, host: SettingsHost): Promise<SettingsProtectionValues | undefined>;
11
+ /** Merge only the writer's host while holding the copy's cross-process lock. */
12
+ export declare function writeSettingsProtectionCopy(file: string, host: SettingsHost, entry: SettingsProtectionCopyEntry, lockTimeoutMs?: number, publicationOptions?: PublicationOptions): Promise<void>;
@@ -0,0 +1,22 @@
1
+ import type { createNativePoolStore } from './pool-store.ts';
2
+ import type { SettingsHost } from './settings-paths.ts';
3
+ import type { SettingsProtectionValues } from './settings-service.ts';
4
+ type EnrollmentMode = 'local' | 'claustrum';
5
+ type SettingsStore = Pick<ReturnType<typeof createNativePoolStore>, 'readSettings'>;
6
+ export interface LegacySettingsProtectionOptions {
7
+ host: SettingsHost;
8
+ env?: NodeJS.ProcessEnv;
9
+ localStore: SettingsStore;
10
+ vaultStore: SettingsStore;
11
+ /** Use the runtime's own vault initialization, including its one-time legacy seeding. */
12
+ initializeVaultSettings: () => Promise<void>;
13
+ readMode?: (host: SettingsHost, env: NodeJS.ProcessEnv) => Promise<EnrollmentMode>;
14
+ }
15
+ /** Preserve legacy reader behavior rather than validating an old store as a new settings file. */
16
+ export declare function legacySettingsProtection(settings: Record<string, unknown>, host: SettingsHost, mode?: EnrollmentMode): SettingsProtectionValues;
17
+ /**
18
+ * Read the store selected by this runtime's enrollment mode. An unreadable mode,
19
+ * failed vault initialization or unsuccessful store read returns no recovery values.
20
+ */
21
+ export declare function readLegacySettingsProtection(options: LegacySettingsProtectionOptions): Promise<SettingsProtectionValues | undefined>;
22
+ export {};
@@ -0,0 +1,14 @@
1
+ import type { AccountStorage } from './accounts.ts';
2
+ import type { SettingsKey } from './settings-definition.ts';
3
+ import type { SettingsHost } from './settings-paths.ts';
4
+ import type { SettingsGeneration, SettingsProtectionValues } from './settings-service.ts';
5
+ /** Presence is captured with the resolved generation, never by reading the file on a request. */
6
+ export declare function settingsFileSets(generation: SettingsGeneration, key: SettingsKey, host: SettingsHost, model?: string): boolean;
7
+ /**
8
+ * Overlay only the protection settings onto a legacy record, keeping every
9
+ * other stored setting: for a host whose settings file is in charge but
10
+ * whose settings service could not open.
11
+ */
12
+ export declare function overlaySettingsProtection(stored: Record<string, unknown>, values: SettingsProtectionValues, host: SettingsHost): Record<string, unknown>;
13
+ export declare function resolveSettingsRecord(stored: AccountStorage, generation: SettingsGeneration | undefined, host: SettingsHost, model?: string): AccountStorage;
14
+ export declare function resolveSettingsRecord(stored: Record<string, unknown>, generation: SettingsGeneration | undefined, host: SettingsHost, model?: string): Record<string, unknown>;
@@ -0,0 +1,215 @@
1
+ import { type OpenSettingsOptions, type ReportEntry, type SettingsEdit, type SettingsHandle, type UpdateResult, type ValueOf } from "./internal-types/settings/index.js";
2
+ import { type SettingsKey, settingsDefinition } from './settings-definition.ts';
3
+ import type { SettingsHost } from './settings-paths.ts';
4
+ import { writeSettingsProtectionCopy } from './settings-protection-copy.ts';
5
+ export type SettingsValues = {
6
+ [K in SettingsKey]: ValueOf<(typeof settingsDefinition.settings)[K]['value']>;
7
+ };
8
+ export declare const SETTINGS_PROTECTION_KEYS: readonly ["max_same_account_wait", "quota_minimum_remaining_five_hour", "quota_minimum_remaining_seven_day", "quota_minimum_remaining_scoped", "quota_fail_closed_on_unknown_quota", "killswitch_enabled", "killswitch_default_five_hour", "killswitch_default_seven_day", "killswitch_default_scoped", "killswitch_account_floors"];
9
+ export type SettingsProtectionValues = Pick<SettingsValues, (typeof SETTINGS_PROTECTION_KEYS)[number]>;
10
+ export type SettingsProtectionRung = 0 | 1 | 2 | 3;
11
+ export declare class SettingsRecreationRefusal extends Error {
12
+ constructor(file: string);
13
+ }
14
+ export interface SettingsUpdateOptions {
15
+ /** Only menu writes and setup with a <target>.moved marker and no user file may create it. */
16
+ createMissing?: boolean;
17
+ /**
18
+ * The file text the edits were planned from (a whole floor list). The write
19
+ * is refused as busy when the file no longer holds exactly this text.
20
+ */
21
+ expectedSource?: string;
22
+ /**
23
+ * The edits were planned from a missing file (a floor list started from
24
+ * the recreation's list). The write is refused as busy if a file exists.
25
+ */
26
+ expectMissing?: boolean;
27
+ /**
28
+ * Setup runs while every host is stopped. When the other host then has no
29
+ * recoverable protection set (no applied copy and no legacy store, rather
30
+ * than an unreadable one), recreation carries the writer's set instead of
31
+ * refusing. Running hosts never pass it: a running peer at the strictest
32
+ * set would be loosened.
33
+ */
34
+ hostsStopped?: boolean;
35
+ }
36
+ export interface SettingsProtectionRecovery {
37
+ /** Return only this host's complete set; missing or corrupt copies return undefined or throw. */
38
+ readAppliedCopy?: (host: SettingsHost) => Promise<SettingsProtectionValues | undefined>;
39
+ /** Read this runtime's local or vault settings store, as selected by its current enrollment mode. */
40
+ readLegacyProtection?: (host: SettingsHost) => Promise<SettingsProtectionValues | undefined>;
41
+ /**
42
+ * Read the other host's own legacy store through that host's current custody
43
+ * (see `readPeerLegacySettingsProtection`). Recreating a missing file uses it
44
+ * to learn the other host's protection; without it that host counts as
45
+ * having the strictest set.
46
+ */
47
+ readPeerLegacyProtection?: (host: SettingsHost) => Promise<SettingsProtectionValues | undefined>;
48
+ }
49
+ export interface SettingsContextValues {
50
+ readonly noModel: SettingsValues;
51
+ readonly models: Readonly<Record<string, SettingsValues>>;
52
+ }
53
+ /** Explicit file levels only; values and their validity remain common-auth's responsibility. */
54
+ export type SettingsFileLevels = Readonly<Partial<Record<SettingsKey, readonly string[]>>>;
55
+ export interface SettingsFileStatus {
56
+ readonly file: string;
57
+ readonly state: 'ready' | 'missing' | 'unparseable' | 'unreadable';
58
+ readonly missing: boolean;
59
+ readonly recreated: boolean;
60
+ readonly invalidKeys: readonly string[];
61
+ readonly ignoredModelKeys: readonly {
62
+ setting: SettingsKey;
63
+ model: string;
64
+ }[];
65
+ readonly duplicateKeys: readonly string[];
66
+ }
67
+ export interface SettingsGeneration {
68
+ readonly id: number;
69
+ /** Time the coherent file version was read; detached persistence retains this time. */
70
+ readonly readAt: number;
71
+ readonly file: string;
72
+ readonly status: 'ready' | 'missing' | 'unparseable' | 'unreadable';
73
+ /** Raw file text for inspecting override locations outside request handling; never log it. */
74
+ readonly source: string | undefined;
75
+ readonly fileLevels: SettingsFileLevels;
76
+ readonly contexts: Readonly<Record<SettingsHost, SettingsContextValues>>;
77
+ readonly report: readonly ReportEntry[];
78
+ readonly fileStatus: SettingsFileStatus;
79
+ /** Recover an unusable set as a whole from last-good values or startup recovery, never per key. */
80
+ readonly protection: Readonly<Record<SettingsHost, {
81
+ readonly usable: boolean;
82
+ readonly values: SettingsProtectionValues;
83
+ readonly rung: SettingsProtectionRung;
84
+ }>>;
85
+ }
86
+ export interface SettingsService {
87
+ readonly file: string;
88
+ /** An independently disposable reference; settings stay live until all references are disposed. */
89
+ retain(): SettingsService;
90
+ /** Synchronous, memory-only reads; unknown models use the no-model context. */
91
+ resolve(host: SettingsHost, model?: string): SettingsValues;
92
+ snapshot(): SettingsGeneration;
93
+ /** Secret-free diagnostics for status displays, with no filesystem work. */
94
+ status(): SettingsFileStatus;
95
+ /** Effects are awaited in publication order; unsubscribe before disposing a host. */
96
+ watch(listener: SettingsChangeListener): () => void;
97
+ /** Every underlying user-file watch callback, even if resolved values stay identical. */
98
+ onFileEvent?(listener: () => void): () => void;
99
+ refresh(): Promise<void>;
100
+ update(edits: readonly SettingsEdit[], host: SettingsHost, options?: SettingsUpdateOptions): Promise<UpdateResult>;
101
+ dispose(): Promise<void>;
102
+ }
103
+ export type SettingsChangeListener = (generation: SettingsGeneration) => void | Promise<void>;
104
+ type CoreSettingsHandle = SettingsHandle<typeof settingsDefinition.settings>;
105
+ export interface SettingsServiceOptions {
106
+ file: string;
107
+ /** Acting host: enables persistence and startup recovery of only its own copy set. */
108
+ host?: SettingsHost;
109
+ separateInstall?: boolean;
110
+ lockTimeoutMs?: number;
111
+ protection?: SettingsProtectionRecovery;
112
+ /** Dependency seams for deterministic file-race and no-I/O tests. */
113
+ dependencies?: {
114
+ open?: (options: OpenSettingsOptions) => CoreSettingsHandle;
115
+ readFile?: (file: string) => Promise<Uint8Array>;
116
+ writeAppliedCopy?: typeof writeSettingsProtectionCopy;
117
+ /** Schedule an off-request re-read; return a cancellation function. */
118
+ schedule?: (callback: () => void, delayMs: number) => () => void;
119
+ };
120
+ }
121
+ /** One host's whole protection set, as the recreation planner receives it. */
122
+ export interface SettingsRecreationSide {
123
+ host: SettingsHost;
124
+ values: SettingsProtectionValues;
125
+ }
126
+ /**
127
+ * A settings edit that names the override level it writes. common-auth 0.48
128
+ * has no `level`; 0.49 adds it, and only then can a recreation write a value
129
+ * for one host. Until then recreation accepts plans whose edits carry none.
130
+ */
131
+ export type SettingsLevelEdit = SettingsEdit & {
132
+ level?: 'default' | SettingsHost;
133
+ };
134
+ /**
135
+ * The protection edits for a recreated file, as a pure function of both
136
+ * hosts' whole sets, so each host resolves exactly its own set from the new
137
+ * file. A key both hosts agree on is one plain value. A key they disagree on
138
+ * is the writer's value at the default level, then the other host's value at
139
+ * that host's level. Floors are one list whose entries keep each host's tag;
140
+ * an entry becomes `both` only for a vault account whose floors are
141
+ * identical for the two hosts.
142
+ */
143
+ export declare function planSettingsRecreation(writer: SettingsRecreationSide, peer: SettingsRecreationSide): {
144
+ edits: SettingsLevelEdit[];
145
+ /**
146
+ * True when the other host resolves any protection value other than its
147
+ * account floors differently. Floors never set it: the one floor list
148
+ * carries each host's entries under that host's tag.
149
+ */
150
+ peerDiffers: boolean;
151
+ };
152
+ /**
153
+ * The protection edits for a recreation whose other host has no set of its
154
+ * own: the writer's values as plain values, its own account floors tagged
155
+ * with it, and its vault floors as `both`, since vault routes are shared.
156
+ */
157
+ export declare function settingsRecreationForWriter(values: SettingsProtectionValues, host: SettingsHost): SettingsLevelEdit[];
158
+ /**
159
+ * The floor list a recreation writes when the other host applies the same
160
+ * floors as `host`, which is the only case recreation accepts today.
161
+ */
162
+ export declare function settingsRecreationFloors(values: SettingsProtectionValues, host: SettingsHost): SettingsProtectionValues['killswitch_account_floors'];
163
+ /** One host's protection set and where it came from, for planning a recreation. */
164
+ export interface SettingsRecreationInput {
165
+ host: SettingsHost;
166
+ values: SettingsProtectionValues;
167
+ rung: SettingsProtectionRung;
168
+ /** A source exists but could not be read, so the set is unknown. */
169
+ unreadable?: boolean;
170
+ /**
171
+ * The host has no set at all: no applied copy and no legacy store (it never
172
+ * ran). Distinct from rung 3 without a reader, which is an unknown set.
173
+ */
174
+ none?: boolean;
175
+ }
176
+ export type SettingsRecreationRefusalReason = 'own-unknown' | 'peer-unknown' | 'peer-differs';
177
+ /**
178
+ * What a menu write that finds the file missing does, as a pure function of
179
+ * both hosts' sets: the protection edits it carries, or why it is refused.
180
+ * A peer with no set takes the writer's; so does one with no recoverable set
181
+ * when every host is stopped (setup). Otherwise both sets are planned
182
+ * together, and a peer whose non-floor values differ refuses, since the file
183
+ * cannot yet hold a value for one host alone (common-auth 0.48 has no level).
184
+ */
185
+ export declare function planSettingsFileRecreation(writer: SettingsRecreationInput, peer: SettingsRecreationInput, hostsStopped?: boolean): {
186
+ edits: SettingsLevelEdit[];
187
+ } | {
188
+ refused: SettingsRecreationRefusalReason;
189
+ };
190
+ /** The state of the user file a menu write found, as common-auth's planned update reports it. */
191
+ export type SettingsWriteState = {
192
+ status: 'missing';
193
+ } | {
194
+ status: 'ready';
195
+ };
196
+ /**
197
+ * The edits for one menu write, as a pure function of the file it finds:
198
+ * protection is carried only into a missing file, and an existing file keeps
199
+ * its own. `carry` throws when recreation must be refused.
200
+ */
201
+ export declare function planSettingsMenuWrite(current: SettingsWriteState, edits: readonly SettingsEdit[], carry: () => readonly SettingsEdit[]): readonly SettingsEdit[];
202
+ export declare function mostRestrictiveSettingsProtection(): SettingsProtectionValues;
203
+ /**
204
+ * Rungs 1-3 of the protection ladder, which need no open settings handle:
205
+ * the applied copy (by default read from disk only for the acting host),
206
+ * then the host's legacy store, then the strictest set. A source that can't
207
+ * be read is skipped whole; keys are never mixed across sources.
208
+ */
209
+ export declare function recoverSettingsProtection(file: string, host: SettingsHost, recovery?: SettingsProtectionRecovery, actingHost?: SettingsHost): Promise<{
210
+ values: SettingsProtectionValues;
211
+ rung: 1 | 2 | 3;
212
+ }>;
213
+ /** One lease per plugin instance; no handle, reads or watch for a separate install. */
214
+ export declare function openSettingsService(options: SettingsServiceOptions): Promise<SettingsService | undefined>;
215
+ export {};
@@ -0,0 +1,57 @@
1
+ import { type SettingsMode } from './settings-mode.ts';
2
+ import { runSettingsMoveAtStartup, type SettingsMoveStartupOptions } from './settings-move-run.ts';
3
+ import { type SettingsProtectionRecovery, type SettingsProtectionValues, type SettingsService, type SettingsServiceOptions } from './settings-service.ts';
4
+ export interface StartSettingsOptions extends SettingsMoveStartupOptions {
5
+ /** This host's recovery sources, shared by the service and the fallback. */
6
+ protection?: SettingsProtectionRecovery;
7
+ lockTimeoutMs?: number;
8
+ /** Test seams for the move and the service open. */
9
+ start?: {
10
+ move?: typeof runSettingsMoveAtStartup;
11
+ open?: (options: SettingsServiceOptions) => Promise<SettingsService | undefined>;
12
+ };
13
+ }
14
+ /**
15
+ * The settings file is in charge, but its service could not open. Protection
16
+ * comes from the ladder without an open handle (this host's applied copy,
17
+ * then its legacy store, then the strictest set); every other setting stays
18
+ * as the legacy store holds it.
19
+ */
20
+ export interface SettingsProtectionFallback {
21
+ readonly file: string;
22
+ readonly rung: 1 | 2 | 3;
23
+ readonly values: SettingsProtectionValues;
24
+ /** Off the request path: open the service again; undefined while it still fails. */
25
+ reopen(): Promise<SettingsService | undefined>;
26
+ /**
27
+ * Present only when startup could not tell which source is in charge and
28
+ * fell back to the file as a precaution. Off the request path, asks again;
29
+ * throws while the check still fails. A result other than 'user-file'
30
+ * means no move happened and the fallback should be dropped.
31
+ */
32
+ resolveAuthority?(): Promise<SettingsMode>;
33
+ }
34
+ export interface StartedSettings {
35
+ mode: SettingsMode;
36
+ /** The settings file; empty only when even its path could not be resolved. */
37
+ file: string;
38
+ /** Open in user-file mode, and in legacy mode to notice another host's move. */
39
+ service?: SettingsService;
40
+ /** Set instead of `service` when the file is in charge but could not open. */
41
+ fallback?: SettingsProtectionFallback;
42
+ /**
43
+ * Set in legacy mode when the service could not open: open it again off
44
+ * the request path, so a move another host publishes later is noticed.
45
+ */
46
+ reopen?: () => Promise<SettingsService | undefined>;
47
+ }
48
+ /** Tests only: let the next failed start log its one warning again. */
49
+ export declare function __resetSettingsStartWarningForTest(): void;
50
+ /**
51
+ * The one settings startup every host calls; it never throws. It runs the
52
+ * move, then opens the service. When either fails, a file that is (or may
53
+ * be) in charge gets the protection fallback, never plain legacy values,
54
+ * which may predate protection the user tightened in the file. Only a check
55
+ * that proves no move happened (no file, no marker) returns legacy mode.
56
+ */
57
+ export declare function startSettings(options: StartSettingsOptions): Promise<StartedSettings>;
@@ -0,0 +1,5 @@
1
+ export type ThreeWayBoolean = boolean | 'default' | 'on' | 'off';
2
+ /** Preserve each reader's legacy default when the setting is absent or default. */
3
+ export declare function readThreeWayBoolean(value: ThreeWayBoolean | undefined, absent: boolean): boolean;
4
+ /** Encode legacy booleans without choosing a reader-specific policy for absence. */
5
+ export declare function toThreeWay(value: ThreeWayBoolean | undefined): 'default' | 'on' | 'off';
@@ -59,6 +59,7 @@ export declare class StickyQuotaRetryCounter {
59
59
  constructor(maxSessions?: number);
60
60
  retain(sessionId: string, turnId: string, accountId: string): boolean;
61
61
  clear(sessionId: string): void;
62
+ attempt(sessionId: string): number | undefined;
62
63
  }
63
64
  /**
64
65
  * Build the terminal response for a complete sticky quota pool that has no
@@ -181,6 +182,19 @@ export declare class StickySessionRouter {
181
182
  quotaCheckedAt: number;
182
183
  accountId: string;
183
184
  } | undefined;
185
+ /** Load the current pin without touching or publishing it. An unreadable pin
186
+ * omits the advisory hint; normal route resolution still validates its state. */
187
+ readAssignment(sessionId: string): Promise<{
188
+ /** Verified account UUID for a credential held by the vault. Pins using credentials stored by this host omit the field. */
189
+ accountIdentity?: string;
190
+ family: StickyRouteFamily;
191
+ affinityModelId?: string;
192
+ assignedAt: number;
193
+ lastSeenAt: number;
194
+ initialInputBytes: number;
195
+ quotaCheckedAt: number;
196
+ accountId: string;
197
+ } | undefined>;
184
198
  resolve(input: {
185
199
  sessionId: string;
186
200
  family: StickyRouteFamily;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/anthropic-auth-core",
3
- "version": "2.11.2",
3
+ "version": "2.11.4",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,6 +17,7 @@
17
17
  },
18
18
  "files": [
19
19
  "dist",
20
+ "schema/anthropic-auth.schema.json",
20
21
  "README.md",
21
22
  "LICENSE"
22
23
  ],
@@ -30,7 +31,7 @@
30
31
  "prepublishOnly": "bun run build"
31
32
  },
32
33
  "devDependencies": {
33
- "@cortexkit/common-auth": "0.47.0"
34
+ "@cortexkit/common-auth": "0.48.0"
34
35
  },
35
36
  "dependencies": {
36
37
  "@cortexkit/claustrum-client": "0.18.0",