@cortexkit/anthropic-auth-core 2.11.3 → 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.
@@ -61,6 +61,12 @@ export declare function defaultPreNArtifactLocations(env?: NodeJS.ProcessEnv, ho
61
61
  * read or parsed blocks too. A record from before this boot is stale even
62
62
  * if its pid has been reused; missing or untrustworthy times keep blocking.
63
63
  */
64
- export declare function preNArtifactBlockers(locations: PreNArtifactLocations, pidAlive?: (pid: number) => boolean, clock?: Pick<HolderLiveness, 'now' | 'uptime'>): Promise<FenceBlocker[]>;
64
+ export declare function preNArtifactBlockers(locations: PreNArtifactLocations, pidAlive?: (pid: number) => boolean, clock?: Pick<HolderLiveness, 'now' | 'uptime'>,
65
+ /**
66
+ * When set, a stamped artifact counts as older too unless this accepts its
67
+ * `writer.release`: its writer may be a release below a later fence's
68
+ * floor whose holder registration is still pending.
69
+ */
70
+ acceptsRelease?: (release: unknown) => boolean): Promise<FenceBlocker[]>;
65
71
  /** One line naming a blocker, for the log. */
66
72
  export declare function describeFenceBlocker(blocker: FenceBlocker): string;
@@ -80,6 +80,8 @@ export interface NativeAccountRuntime {
80
80
  getSettingsStatus?(): NativeRuntimeSettingsStatus | undefined;
81
81
  /** Hosts call after startup and committed menu writes; watches use the same deduplicated hook. */
82
82
  applySettingsEffects?(): void;
83
+ /** Await at instance start and before every /claude action, never on requests. */
84
+ prepareSettingsAction?(): Promise<void>;
83
85
  /** Last completed read, without disk I/O or credential/quota work. */
84
86
  peek?(): NativeAccountSnapshot | undefined;
85
87
  authorizeLocal(routeId: string, options?: NativeLocalAuthorizeOptions): Promise<NativeRefreshResult>;
@@ -38,6 +38,11 @@ export interface NativeMigrationSourceInput {
38
38
  state: unknown;
39
39
  hostAuth: unknown;
40
40
  }
41
+ /** Keep credential-transfer settings separate from settings routed after commit. */
42
+ export declare function splitNativeMigrationSettings(settings: Record<string, unknown>): {
43
+ moved: Record<string, unknown>;
44
+ retained: Record<string, unknown>;
45
+ };
41
46
  export declare function validateNativeMigrationSettings(settings: Record<string, unknown>): void;
42
47
  /** Deterministic projection of captured JSON, without invoking legacy loaders or callbacks. */
43
48
  export declare function projectNativeMigrationSource(input: NativeMigrationSourceInput): NativeMigrationProjection;
@@ -11,6 +11,11 @@ export declare class NativeMigrationError extends Error {
11
11
  readonly code: 'invalid-source' | 'unsafe-source' | 'consent-required' | 'primary-unverified' | 'migration-busy' | 'ownership-lost' | 'pool-populated' | 'host-login-present' | 'settings-changed' | 'retirement-refused';
12
12
  constructor(code: 'invalid-source' | 'unsafe-source' | 'consent-required' | 'primary-unverified' | 'migration-busy' | 'ownership-lost' | 'pool-populated' | 'host-login-present' | 'settings-changed' | 'retirement-refused');
13
13
  }
14
+ /** Credential commit succeeded; keep its source until setup can save settings. */
15
+ export declare class NativeSetupSettingsWriteError extends Error {
16
+ readonly code = "setup-settings-write-failed";
17
+ constructor();
18
+ }
14
19
  export interface NativeMigrationCustody {
15
20
  /** Use the host’s approved Claustrum token and account-list permission to discover accounts; never open the vault’s credential files. */
16
21
  discover: () => Promise<NativeCustodyInventory>;
@@ -43,6 +48,16 @@ export interface NativeMigrationOptions {
43
48
  * after this migration commits until runNativeCustodyActivation commits.
44
49
  */
45
50
  requestVaultActivation?: boolean;
51
+ /**
52
+ * Opt into deferred settings routing: moved fields are excluded from credential
53
+ * import. Called after commit, outside the pool locks, before source retirement.
54
+ * Setup adapters must always supply this hook when using the settings writer.
55
+ * Without it, the existing credential/settings migration contract is unchanged.
56
+ */
57
+ writeSetupSettings?: (settings: Readonly<Record<string, unknown>>) => Promise<{
58
+ outcome: 'saved' | 'refused' | 'failed';
59
+ reason?: string;
60
+ }>;
46
61
  }
47
62
  /** Result of read-only checks for the selected storage and host. Contains no account data or credential digests. */
48
63
  export interface NativeMigrationPreflight {
@@ -1,13 +1,32 @@
1
1
  import type { SettingsEdit } from "./internal-types/settings/index.js";
2
2
  import type { AccountStorage } from './accounts.ts';
3
3
  import { type SettingsKey } from './settings-definition.ts';
4
- import { type SettingsMode } from './settings-mode.ts';
4
+ import { type SettingsMode, type SettingsModeOptions } from './settings-mode.ts';
5
5
  import type { SettingsHost } from './settings-paths.ts';
6
- import type { SettingsFileStatus, SettingsService, SettingsValues } from './settings-service.ts';
6
+ import type { SettingsFileStatus, SettingsService, SettingsUpdateOptions, SettingsValues } from './settings-service.ts';
7
+ import type { SettingsProtectionFallback } from './settings-start.ts';
7
8
  export interface NativeRuntimeSettingsOptions {
8
9
  settingsService?: SettingsService;
9
10
  /** Return the cached settings mode; this callback must not read the filesystem. */
10
11
  settingsMode?: () => SettingsMode;
12
+ settingsAuthority?: {
13
+ options?: SettingsModeOptions;
14
+ /** Schedule a background authority check and return its cancellation function. */
15
+ schedule?: (callback: () => Promise<void>, delayMs: number) => () => void;
16
+ };
17
+ /**
18
+ * From `startSettings` when the file is in charge but its service could not
19
+ * open: requests overlay the fallback's protection on the legacy record,
20
+ * menu writes are refused, and the authority timer and menu actions try to
21
+ * open the service again until it replaces the fallback.
22
+ */
23
+ settingsFallback?: SettingsProtectionFallback;
24
+ /**
25
+ * From `startSettings` in legacy mode when the service could not open: the
26
+ * authority timer and menu actions open it again off the request path, so a
27
+ * move another host publishes later is still noticed.
28
+ */
29
+ settingsReopen?: () => Promise<SettingsService | undefined>;
11
30
  }
12
31
  export interface NativeRuntimeSettingsStatus {
13
32
  file: SettingsFileStatus;
@@ -19,9 +38,8 @@ export interface NativeRuntimeSettingsStatus {
19
38
  }
20
39
  /**
21
40
  * Project policy settings from memory, retaining a service reference until close.
22
- * The host releases its own reference and checks off the request path whether
23
- * the user file exists or a marker records a completed settings migration, then
24
- * updates the cached legacy/user-file mode.
41
+ * The host awaits prepareAction at instance start and before every menu action.
42
+ * Watches and a background timer also check authority; requests use memory only.
25
43
  */
26
44
  export declare function createNativeRuntimeSettings(options: NativeRuntimeSettingsOptions & {
27
45
  host: SettingsHost;
@@ -34,8 +52,21 @@ export declare function createNativeRuntimeSettings(options: NativeRuntimeSettin
34
52
  status: () => NativeRuntimeSettingsStatus | undefined;
35
53
  applyEffects: () => void;
36
54
  file: () => string | undefined;
55
+ prepareAction(): Promise<void>;
56
+ /** The settings file while the protection fallback is in use, else undefined. */
57
+ fallbackFile: () => string | undefined;
58
+ /**
59
+ * Called under the legacy store's locks by a write that chose the legacy
60
+ * store: true when the user file became authoritative meanwhile (a move
61
+ * published while the write waited for those locks), so the write must
62
+ * leave the legacy store alone and go to the user file instead. A watch,
63
+ * the timer or another action may already have adopted the file while
64
+ * the write waited; that counts as lost too.
65
+ */
66
+ legacyAuthorityLost(): Promise<boolean>;
37
67
  /** Recheck authority on the menu path before choosing a write target. */
38
68
  prepareWrite(): Promise<SettingsService | undefined>;
39
- update(edits: readonly SettingsEdit[], before: Record<string, unknown>): Promise<void>;
40
- close: () => Promise<void> | undefined;
69
+ legacyWriteCommitted(source: string, stored: Record<string, unknown>): Promise<void>;
70
+ update(edits: readonly SettingsEdit[], before: Record<string, unknown>, planned?: Pick<SettingsUpdateOptions, 'expectedSource' | 'expectMissing'>): Promise<void>;
71
+ close: () => Promise<void>;
41
72
  };
@@ -1,6 +1,6 @@
1
1
  import type { SettingsEdit } from "./internal-types/settings/index.js";
2
2
  import type { SettingsHost } from './settings-paths.ts';
3
- import { type SettingsGeneration } from './settings-service.ts';
3
+ import { type SettingsGeneration, type SettingsValues } from './settings-service.ts';
4
4
  type Settings = Record<string, unknown>;
5
5
  interface StoreChange {
6
6
  path: string[];
@@ -11,7 +11,36 @@ export declare function planNativeSettingsWrite(before: Settings, after: Setting
11
11
  edits: SettingsEdit[];
12
12
  storeChanges: StoreChange[];
13
13
  refusal: string | undefined;
14
+ /**
15
+ * What a floor-list edit was planned from: the file text, or a missing
16
+ * file. The write is refused as busy if the file is no longer that.
17
+ */
18
+ floorsFrom: {
19
+ status: 'missing';
20
+ } | {
21
+ status: 'ready';
22
+ source: string;
23
+ } | undefined;
14
24
  };
25
+ /**
26
+ * The acting host's floor-list edit, as a pure function of the file it
27
+ * finds: the parsed document, or a missing file, which starts from the list
28
+ * a recreation carries. Only the acting host's entries for the changed
29
+ * accounts change; a `both` entry for such an account is split first so the
30
+ * other host keeps its floor. Returns undefined when the list is unchanged.
31
+ *
32
+ * common-auth 0.48 can't run this under its write lock, so the caller plans
33
+ * from a generation and the service refuses the write if the file changed
34
+ * since (see `SettingsUpdateOptions.expectedSource`); that leaves a small
35
+ * window before the lock. common-auth 0.49's planned update will pass this
36
+ * function the document read under the lock, closing it.
37
+ */
38
+ export declare function planSettingsAccountFloors(current: {
39
+ status: 'missing';
40
+ } | {
41
+ status: 'ready';
42
+ document: unknown;
43
+ }, changes: ReadonlyMap<string, Record<string, unknown> | undefined>, host: SettingsHost, recreation: SettingsValues['killswitch_account_floors']): SettingsEdit | undefined;
15
44
  /** Apply only store-held deltas to a fresh legacy record, never the resolved settings projection. */
16
45
  export declare function applyNativeStoreSettingsChanges(stored: Settings, changes: readonly StoreChange[]): Settings;
17
46
  /** Old releases only understand booleans in these legacy fields. */
@@ -0,0 +1,39 @@
1
+ import { type SettingsKey } from './settings-definition.ts';
2
+ import { type SettingsModeOptions } from './settings-mode.ts';
3
+ import { type SettingsHost, type SettingsPathOptions, type SettingsPaths } from './settings-paths.ts';
4
+ import { type SettingsProtectionRecovery } from './settings-service.ts';
5
+ export interface NativeSetupSettingsDifference {
6
+ key: SettingsKey;
7
+ account?: string;
8
+ legacy: unknown;
9
+ file: unknown;
10
+ note?: string;
11
+ }
12
+ export interface NativeSetupSettingsResult {
13
+ target: 'legacy-store' | 'user-file';
14
+ outcome: 'saved' | 'refused' | 'failed';
15
+ reason?: string;
16
+ skipped: SettingsKey[];
17
+ differing: NativeSetupSettingsDifference[];
18
+ }
19
+ export interface NativeSetupSettingsOptions extends SettingsPathOptions {
20
+ host: SettingsHost;
21
+ /** Raw legacy fields captured before retirement, never a resolved settings record. */
22
+ settings: Record<string, unknown>;
23
+ source: string;
24
+ paths?: SettingsPaths;
25
+ authority?: SettingsModeOptions;
26
+ /** Use the acting host's selected local or vault store and its normal writer lock. */
27
+ writeLegacySettings: (settings: Record<string, unknown>) => Promise<void>;
28
+ /** Startup recovery; readLegacyProtection reads this host's active local or vault settings store. */
29
+ protection?: SettingsProtectionRecovery;
30
+ log?: {
31
+ warn(message: string): void;
32
+ };
33
+ }
34
+ /**
35
+ * Called only after credential commit, while hosts are stopped. Decide authority
36
+ * once per attempt (including resume), never run startup's one-time settings
37
+ * migration, and fill only missing user-file values. Legacy writes receive raw legacy fields, not a projection.
38
+ */
39
+ export declare function writeNativeSetupSettings(options: NativeSetupSettingsOptions): Promise<NativeSetupSettingsResult>;
@@ -0,0 +1,8 @@
1
+ import type { SettingsKey } from './settings-definition.ts';
2
+ import type { SettingsHost } from './settings-paths.ts';
3
+ import type { SettingsValues } from './settings-service.ts';
4
+ /** Only explicitly stored moved fields warrant a not-imported diagnostic. */
5
+ export declare function holdsMovedSettings(stored: unknown): boolean;
6
+ /** Compare account floors for this host only; list order and the peer's entries do not decide its values. */
7
+ export declare function differingLegacySettings(legacy: Partial<SettingsValues>, resolved: SettingsValues, host: SettingsHost): SettingsKey[];
8
+ export declare function settingsNotImportedText(source: string, target: string, differing?: readonly SettingsKey[]): string;
@@ -0,0 +1,25 @@
1
+ import type { SettingsHost } from './settings-paths.ts';
2
+ import { SETTINGS_PROTECTION_KEYS, type SettingsFileLevels, type SettingsLevelEdit, type SettingsProtectionValues } from './settings-service.ts';
3
+ type ProtectionKey = (typeof SETTINGS_PROTECTION_KEYS)[number];
4
+ /**
5
+ * The import a host owes the settings file when its legacy store was never
6
+ * imported: for each protection key the file sets for this host no value of
7
+ * its own (fill-only), the host's legacy value where it protects more than
8
+ * what the host now resolves from the file. A pure function of the host's
9
+ * legacy set, its resolved set and the file's explicit levels.
10
+ *
11
+ * `edits` writes those values at the host's own level; account floors need
12
+ * no level, since each list entry names its host. common-auth 0.48 cannot
13
+ * write a level, so until 0.49 the caller refuses to adopt the file when
14
+ * `keys` is not empty and only applies `edits` once it can.
15
+ */
16
+ export declare function planSettingsHostImport(input: {
17
+ host: SettingsHost;
18
+ legacy: SettingsProtectionValues;
19
+ resolved: SettingsProtectionValues;
20
+ fileLevels: SettingsFileLevels;
21
+ }): {
22
+ keys: ProtectionKey[];
23
+ edits: SettingsLevelEdit[];
24
+ };
25
+ export {};
@@ -1,6 +1,6 @@
1
1
  import { type OwnerOnlyOptions } from './owner-only.ts';
2
2
  import { type PathResolutionOptions } from './path-options.ts';
3
- import type { SettingsPaths } from './settings-paths.ts';
3
+ import type { SettingsHost, SettingsPaths } from './settings-paths.ts';
4
4
  export type SettingsMode = 'separate' | 'user-file' | 'legacy';
5
5
  /** Injectable filesystem operations for authority checks and marker publication. */
6
6
  export interface SettingsModeFs {
@@ -18,5 +18,19 @@ export interface SettingsModeOptions extends PathResolutionOptions {
18
18
  export declare function hasSettingsMoveMarker(target: string, options?: SettingsModeOptions): Promise<boolean>;
19
19
  /** Publish once after a completed move or a usable hand-made file is found. */
20
20
  export declare function writeSettingsMoveMarker(target: string, options?: SettingsModeOptions): Promise<void>;
21
+ /** Where `host` records that its legacy store's protection is in the file. */
22
+ export declare function settingsImportRecordPath(target: string, host: SettingsHost): string;
23
+ /**
24
+ * Whether `host`'s legacy store was imported into the file, or proved to
25
+ * hold nothing the file lacks. It confers no authority: only the file or
26
+ * its `.moved` marker decide which source is in charge.
27
+ */
28
+ export declare function hasSettingsImportRecord(target: string, host: SettingsHost, options?: SettingsModeOptions): Promise<boolean>;
29
+ /**
30
+ * Record once that `host`'s store was imported. Write it only after the
31
+ * import completed (or proved there was nothing to import), never before
32
+ * the file is published. It holds no settings values.
33
+ */
34
+ export declare function writeSettingsImportRecord(target: string, host: SettingsHost, options?: SettingsModeOptions): Promise<void>;
21
35
  /** Startup/menu/watch/timer work only: request readers consume the cached mode. */
22
36
  export declare function resolveSettingsMode(paths: Pick<SettingsPaths, 'target' | 'separate'>, options?: SettingsModeOptions): Promise<SettingsMode>;
@@ -24,7 +24,12 @@ export interface SettingsMoveFenceOptions extends PathResolutionOptions {
24
24
  /** A failed or still-pending registration prevents only this settings move. */
25
25
  registration: Pick<NativeHolderRegistration, 'status'> | undefined;
26
26
  floor?: string;
27
- self?: Pick<HolderEntry, 'pid' | 'incarnation'>;
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'>>;
28
33
  liveness?: HolderLiveness;
29
34
  artifacts?: PreNArtifactLocations;
30
35
  /** Tests inject holder sets without consulting the installed package release. */
@@ -14,9 +14,11 @@ export interface SettingsMoveStartupOptions extends SettingsMoveSourcesOptions {
14
14
  export interface SettingsMoveStartupResult {
15
15
  paths: SettingsPaths;
16
16
  mode: SettingsMode;
17
- /** Legacy mode still needs the user-file watch to detect another host's move. */
17
+ /** Legacy mode still needs watch callbacks and timer checks for a peer's move. */
18
18
  mayOpenService: boolean;
19
- outcome: MoveOutcome | 'marker-present' | 'source-unavailable';
19
+ outcome: MoveOutcome | 'marker-present' | 'source-unavailable'
20
+ /** The file is in charge, but this host's legacy store protects more. */
21
+ | 'import-refused';
20
22
  move?: MoveResult;
21
23
  }
22
24
  /**
@@ -43,6 +43,8 @@ export interface SettingsMoveSourceOptions {
43
43
  log?: {
44
44
  warn: (message: string) => void;
45
45
  };
46
+ /** Read-only authority comparisons must not consume the move's diagnostics. */
47
+ quiet?: boolean;
46
48
  }
47
49
  /** Parse legacy JSON, validating each moved field independently under the mover's locks. */
48
50
  export declare function readSettingsMoveSource(text: string, options: SettingsMoveSourceOptions): Partial<SettingsValues>;
@@ -2,6 +2,7 @@ import type { MoveSource } from "./internal-types/settings/index.js";
2
2
  import { readNativeEnrollmentMode } from './native-enrollment-authority.ts';
3
3
  import { type NativePoolPaths } from './pool-paths.ts';
4
4
  import { type SettingsHost, type SettingsPathOptions, type SettingsPaths } from './settings-paths.ts';
5
+ import type { SettingsProtectionValues } from './settings-service.ts';
5
6
  export interface SettingsMoveSourcesOptions extends SettingsPathOptions {
6
7
  host: SettingsHost;
7
8
  paths?: SettingsPaths;
@@ -13,6 +14,8 @@ export interface SettingsMoveSourcesOptions extends SettingsPathOptions {
13
14
  log?: {
14
15
  warn: (message: string) => void;
15
16
  };
17
+ /** Inspect existing sources without seeding a vault or changing legacy state. */
18
+ inspectOnly?: boolean;
16
19
  }
17
20
  export type SettingsMoveSourcesResult = {
18
21
  status: 'ready';
@@ -24,9 +27,30 @@ export type SettingsMoveSourcesResult = {
24
27
  status: 'unavailable';
25
28
  sources: [];
26
29
  host: SettingsHost;
27
- reason: 'custody-unreadable' | 'seeding-failed' | 'paths-unreadable';
30
+ reason: 'custody-unreadable' | 'seeding-failed' | 'paths-unreadable' | 'vault-unseeded';
28
31
  cause: unknown;
29
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>;
30
54
  /**
31
55
  * Prepare the common-auth mover's sources, not a startup or authority decision.
32
56
  * An unavailable own source must keep this start in legacy mode; the caller logs
@@ -1,8 +1,14 @@
1
1
  import type { AccountStorage } from './accounts.ts';
2
2
  import type { SettingsKey } from './settings-definition.ts';
3
3
  import type { SettingsHost } from './settings-paths.ts';
4
- import type { SettingsGeneration } from './settings-service.ts';
4
+ import type { SettingsGeneration, SettingsProtectionValues } from './settings-service.ts';
5
5
  /** Presence is captured with the resolved generation, never by reading the file on a request. */
6
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>;
7
13
  export declare function resolveSettingsRecord(stored: AccountStorage, generation: SettingsGeneration | undefined, host: SettingsHost, model?: string): AccountStorage;
8
14
  export declare function resolveSettingsRecord(stored: Record<string, unknown>, generation: SettingsGeneration | undefined, host: SettingsHost, model?: string): Record<string, unknown>;
@@ -14,12 +14,37 @@ export declare class SettingsRecreationRefusal extends Error {
14
14
  export interface SettingsUpdateOptions {
15
15
  /** Only menu writes and setup with a <target>.moved marker and no user file may create it. */
16
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;
17
35
  }
18
36
  export interface SettingsProtectionRecovery {
19
37
  /** Return only this host's complete set; missing or corrupt copies return undefined or throw. */
20
38
  readAppliedCopy?: (host: SettingsHost) => Promise<SettingsProtectionValues | undefined>;
21
39
  /** Read this runtime's local or vault settings store, as selected by its current enrollment mode. */
22
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>;
23
48
  }
24
49
  export interface SettingsContextValues {
25
50
  readonly noModel: SettingsValues;
@@ -69,6 +94,8 @@ export interface SettingsService {
69
94
  status(): SettingsFileStatus;
70
95
  /** Effects are awaited in publication order; unsubscribe before disposing a host. */
71
96
  watch(listener: SettingsChangeListener): () => void;
97
+ /** Every underlying user-file watch callback, even if resolved values stay identical. */
98
+ onFileEvent?(listener: () => void): () => void;
72
99
  refresh(): Promise<void>;
73
100
  update(edits: readonly SettingsEdit[], host: SettingsHost, options?: SettingsUpdateOptions): Promise<UpdateResult>;
74
101
  dispose(): Promise<void>;
@@ -91,9 +118,98 @@ export interface SettingsServiceOptions {
91
118
  schedule?: (callback: () => void, delayMs: number) => () => void;
92
119
  };
93
120
  }
94
- /** Carry only the writer's account floors; vault routes apply to both hosts after recreation. */
95
- export declare function settingsProtectionForRecreation(values: SettingsProtectionValues, host: SettingsHost): SettingsProtectionValues;
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[];
96
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
+ }>;
97
213
  /** One lease per plugin instance; no handle, reads or watch for a separate install. */
98
214
  export declare function openSettingsService(options: SettingsServiceOptions): Promise<SettingsService | undefined>;
99
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>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/anthropic-auth-core",
3
- "version": "2.11.3",
3
+ "version": "2.11.4",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",