@cortexkit/anthropic-auth-core 2.11.3 → 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.
@@ -0,0 +1,17 @@
1
+ import type * as syncFs from 'node:fs';
2
+ import type * as fs from 'node:fs/promises';
3
+ type FilePathFs = Pick<typeof fs, 'lstat' | 'readlink' | 'realpath'>;
4
+ type FilePathSyncFs = Pick<typeof syncFs, 'lstatSync' | 'readlinkSync' | 'realpathSync'>;
5
+ /**
6
+ * Canonical path of a file that other processes may replace by write-and-rename.
7
+ *
8
+ * On Linux, Bun's realpath on such a file can answer "<file> (deleted)" (Bun
9
+ * 1.3) or ENOENT (Bun 1.4) during the rename. So this resolves the folder with
10
+ * realpath and appends the name, then follows a file symlink one readlink hop at
11
+ * a time, at most 40 hops. A missing file resolves to its would-be path; a
12
+ * dangling link or a loop throws. Pass `node:fs/promises` (or a test double).
13
+ */
14
+ export declare function canonicalFilePath(file: string, fs: FilePathFs): Promise<string>;
15
+ /** Synchronous counterpart of canonicalFilePath; pass `node:fs`. */
16
+ export declare function canonicalFilePathSync(file: string, fs: FilePathSyncFs): string;
17
+ export {};
@@ -1,5 +1,6 @@
1
1
  export type { AtomicWriteOptions } from './atomic-write.js';
2
2
  export { writeJsonAtomic } from './atomic-write.js';
3
+ export { canonicalFilePath, canonicalFilePathSync, } from './canonical-file-path.js';
3
4
  export { WRITER_LOCK_CONSTANTS } from './lock-constants.js';
4
5
  export type { PrivateWriteOutcome } from './private-files.js';
5
6
  export { PrivateFileError } from './private-files.js';
@@ -2,6 +2,7 @@ import type { SettingsDefinition } from './define.js';
2
2
  export type SettingsEdit = {
3
3
  setting: string;
4
4
  path?: readonly string[];
5
+ level?: 'default' | 'opencode' | 'pi';
5
6
  } & ({
6
7
  value: unknown;
7
8
  remove?: never;
@@ -4,6 +4,7 @@ import { type ValueOf } from './descriptors.js';
4
4
  import type { SettingsEdit, UpdateResult } from './edit.js';
5
5
  import { type GetOptions } from './resolve.js';
6
6
  import { type ReportEntry } from './snapshot.js';
7
+ import { type SettingsUpdatePlan } from './update.js';
7
8
  export interface LegacyProjectSource {
8
9
  readonly path: string;
9
10
  read(text: string): unknown;
@@ -22,7 +23,7 @@ export interface SettingsHandle<S extends Readonly<Record<string, SettingDeclara
22
23
  }): Promise<void>;
23
24
  get<K extends keyof S & string>(name: K, options: GetOptions): Promise<ValueOf<S[K]['value']>>;
24
25
  report(): ReportEntry[];
25
- update(edits: readonly SettingsEdit[], options: Pick<GetOptions, 'host' | 'model'>): Promise<UpdateResult>;
26
+ update(edits: readonly SettingsEdit[] | SettingsUpdatePlan, options: Pick<GetOptions, 'host' | 'model'>): Promise<UpdateResult>;
26
27
  watch(onChange: () => void): () => void;
27
28
  }
28
29
  /** Internal test hook; not part of the settings package exports. */
@@ -8,3 +8,4 @@ export { SETTINGS_REFUSAL_CODES, SettingsRefusal, type SettingsRefusalCode, } fr
8
8
  export type { GetOptions } from './resolve.js';
9
9
  export { settingsJsonSchema } from './schema.js';
10
10
  export type { ReportEntry, ReportReason } from './snapshot.js';
11
+ export type { SettingsCurrent, SettingsUpdatePlan } from './update.js';
@@ -0,0 +1,14 @@
1
+ import type { SettingsDefinition } from './define.js';
2
+ import { type SettingsEdit, type UpdateResult } from './edit.js';
3
+ import type { OpenSettingsOptions } from './handle.js';
4
+ import type { GetOptions } from './resolve.js';
5
+ export type SettingsCurrent = {
6
+ readonly status: 'missing';
7
+ } | {
8
+ readonly status: 'ready';
9
+ readonly document: Readonly<Record<string, unknown>>;
10
+ };
11
+ /** Compute edits synchronously from an immutable copy read under the write lock. */
12
+ export type SettingsUpdatePlan = (current: SettingsCurrent) => readonly SettingsEdit[];
13
+ /** Lock the canonical user file so symlink aliases serialize the same edits. */
14
+ export declare function updateSettings(definition: SettingsDefinition, options: OpenSettingsOptions, edits: readonly SettingsEdit[] | SettingsUpdatePlan, context: Pick<GetOptions, 'host' | 'model'>): Promise<UpdateResult>;
@@ -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,31 @@
1
- import type { SettingsEdit } from "./internal-types/settings/index.js";
2
1
  import type { AccountStorage } from './accounts.ts';
3
2
  import { type SettingsKey } from './settings-definition.ts';
4
- import { type SettingsMode } from './settings-mode.ts';
3
+ import { type SettingsMode, type SettingsModeOptions } from './settings-mode.ts';
5
4
  import type { SettingsHost } from './settings-paths.ts';
6
- import type { SettingsFileStatus, SettingsService, SettingsValues } from './settings-service.ts';
5
+ import { type SettingsFileStatus, type SettingsService, type SettingsUpdate, type SettingsValues } from './settings-service.ts';
6
+ import type { SettingsProtectionFallback, SettingsReopen } from './settings-start.ts';
7
7
  export interface NativeRuntimeSettingsOptions {
8
8
  settingsService?: SettingsService;
9
9
  /** Return the cached settings mode; this callback must not read the filesystem. */
10
10
  settingsMode?: () => SettingsMode;
11
+ settingsAuthority?: {
12
+ options?: SettingsModeOptions;
13
+ /** Schedule a background authority check and return its cancellation function. */
14
+ schedule?: (callback: () => Promise<void>, delayMs: number) => () => void;
15
+ };
16
+ /**
17
+ * From `startSettings` when the file is in charge but its service could not
18
+ * open: requests overlay the fallback's protection on the legacy record,
19
+ * menu writes are refused, and the authority timer and menu actions try to
20
+ * open the service again until it replaces the fallback.
21
+ */
22
+ settingsFallback?: SettingsProtectionFallback;
23
+ /**
24
+ * From `startSettings` in legacy mode when the service could not open: the
25
+ * authority timer and menu actions open it again off the request path, so a
26
+ * move another host publishes later is still noticed.
27
+ */
28
+ settingsReopen?: SettingsReopen;
11
29
  }
12
30
  export interface NativeRuntimeSettingsStatus {
13
31
  file: SettingsFileStatus;
@@ -19,9 +37,8 @@ export interface NativeRuntimeSettingsStatus {
19
37
  }
20
38
  /**
21
39
  * 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.
40
+ * The host awaits prepareAction at instance start and before every menu action.
41
+ * Watches and a background timer also check authority; requests use memory only.
25
42
  */
26
43
  export declare function createNativeRuntimeSettings(options: NativeRuntimeSettingsOptions & {
27
44
  host: SettingsHost;
@@ -34,8 +51,33 @@ export declare function createNativeRuntimeSettings(options: NativeRuntimeSettin
34
51
  status: () => NativeRuntimeSettingsStatus | undefined;
35
52
  applyEffects: () => void;
36
53
  file: () => string | undefined;
54
+ prepareAction(): Promise<void>;
55
+ /** The settings file while the protection fallback is in use, else undefined. */
56
+ fallbackFile: () => string | undefined;
57
+ /**
58
+ * The settings file while it is open but this host does not use it yet
59
+ * (its import check has not passed), else undefined.
60
+ */
61
+ checkingFile: () => string | undefined;
62
+ /**
63
+ * Why a menu write is refused while `checkingFile` is set. A file that
64
+ * can't be used stays held until the user fixes it, so the text names its
65
+ * problem; any other hold (the check running, a busy lock, an unreadable
66
+ * legacy store) clears by itself.
67
+ */
68
+ checkingRefusal(): string;
69
+ /**
70
+ * Called under the legacy store's locks by a write that chose the legacy
71
+ * store: true when the user file became authoritative meanwhile (a move
72
+ * published while the write waited for those locks), so the write must
73
+ * leave the legacy store alone and go to the user file instead. A watch,
74
+ * the timer or another action may already have adopted the file while
75
+ * the write waited; that counts as lost too.
76
+ */
77
+ legacyAuthorityLost(): Promise<boolean>;
37
78
  /** Recheck authority on the menu path before choosing a write target. */
38
79
  prepareWrite(): Promise<SettingsService | undefined>;
39
- update(edits: readonly SettingsEdit[], before: Record<string, unknown>): Promise<void>;
40
- close: () => Promise<void> | undefined;
80
+ legacyWriteCommitted(source: string, stored: Record<string, unknown>): Promise<void>;
81
+ update(edits: SettingsUpdate, before: Record<string, unknown>): Promise<void>;
82
+ close: () => Promise<void>;
41
83
  };
@@ -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 SettingsUpdatePlan, type SettingsValues } from './settings-service.ts';
4
4
  type Settings = Record<string, unknown>;
5
5
  interface StoreChange {
6
6
  path: string[];
@@ -11,7 +11,24 @@ export declare function planNativeSettingsWrite(before: Settings, after: Setting
11
11
  edits: SettingsEdit[];
12
12
  storeChanges: StoreChange[];
13
13
  refusal: string | undefined;
14
+ update: SettingsUpdatePlan | undefined;
14
15
  };
16
+ /**
17
+ * The acting host's floor-list edit, as a pure function of the file it
18
+ * finds: the parsed document, or a missing file, which starts from the list
19
+ * a recreation carries. Only the acting host's entries for the changed
20
+ * accounts change; a `both` entry for such an account is split first so the
21
+ * other host keeps its floor. Returns undefined when the list is unchanged.
22
+ *
23
+ * The caller passes the document read under the settings writer lock, so
24
+ * concurrent writers retain each other's entries.
25
+ */
26
+ export declare function planSettingsAccountFloors(current: {
27
+ status: 'missing';
28
+ } | {
29
+ status: 'ready';
30
+ document: unknown;
31
+ }, changes: ReadonlyMap<string, Record<string, unknown> | undefined>, host: SettingsHost, recreation: SettingsValues['killswitch_account_floors']): SettingsEdit | undefined;
15
32
  /** Apply only store-held deltas to a fresh legacy record, never the resolved settings projection. */
16
33
  export declare function applyNativeStoreSettingsChanges(stored: Settings, changes: readonly StoreChange[]): Settings;
17
34
  /** 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;
@@ -596,6 +596,17 @@ export declare function malformedSettingsText(file: string): string;
596
596
  export declare function refusedSettingsWriteText(key: SettingsKey, file: string): string;
597
597
  export declare function refusedSettingsRecreationText(file: string): string;
598
598
  export declare function invalidSettingsWriteText(key: SettingsKey, file: string): string;
599
+ /**
600
+ * A menu write while this host still checks the settings file against its
601
+ * legacy settings before using it: neither source can take the write yet.
602
+ */
603
+ export declare function settingsCheckPendingText(file?: string): string;
604
+ /**
605
+ * A menu write while this host can't use the settings file until the user
606
+ * fixes it. `problem` says what is wrong in plain words, such as "is empty";
607
+ * it never quotes a value from the file.
608
+ */
609
+ export declare function settingsFileUnusableText(problem: string, file?: string): string;
599
610
  /** Only fixed, local text is shown; dependency errors can contain file contents. */
600
611
  export declare const SETTINGS_WRITE_FAILURES: {
601
612
  readonly 'settings-unparseable': {
@@ -0,0 +1,39 @@
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 killswitch's default floors. They hold accounts back only while the
6
+ * killswitch is on, so a host whose legacy killswitch was off contributes
7
+ * none of them.
8
+ */
9
+ export declare const KILLSWITCH_FLOOR_KEYS: ReadonlySet<string>;
10
+ /**
11
+ * True when `legacy` protects more than `file` for one scalar protection key.
12
+ * Both sides are effective values: an unset legacy key counts as the value
13
+ * its legacy reader returns (the killswitch floors 5/10/0, `default` for the
14
+ * unknown-quota policy, `15m` for the same-account wait), never as absent.
15
+ */
16
+ export declare function settingsProtectionStricter(key: ProtectionKey, legacy: unknown, file: unknown): boolean;
17
+ /**
18
+ * The import a host owes the settings file when its legacy store was never
19
+ * imported: for each protection key the file sets for this host no value of
20
+ * its own (fill-only), the host's legacy value where it protects more than
21
+ * what the host now resolves from the file. Killswitch floors count only
22
+ * when the host's legacy killswitch was on. A pure function of the host's
23
+ * legacy set, its resolved set and the file's explicit levels.
24
+ *
25
+ * `edits` writes those values at the host's own level; account floors need
26
+ * no level, since each list entry names its host. The caller verifies that
27
+ * the validated protection fields still match the document under the lock
28
+ * before returning these edits from its writer plan.
29
+ */
30
+ export declare function planSettingsHostImport(input: {
31
+ host: SettingsHost;
32
+ legacy: SettingsProtectionValues;
33
+ resolved: SettingsProtectionValues;
34
+ fileLevels: SettingsFileLevels;
35
+ }): {
36
+ keys: ProtectionKey[];
37
+ edits: SettingsLevelEdit[];
38
+ };
39
+ export {};
@@ -1,6 +1,7 @@
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
+ import type { SettingsService } from './settings-service.ts';
4
5
  export type SettingsMode = 'separate' | 'user-file' | 'legacy';
5
6
  /** Injectable filesystem operations for authority checks and marker publication. */
6
7
  export interface SettingsModeFs {
@@ -18,5 +19,40 @@ export interface SettingsModeOptions extends PathResolutionOptions {
18
19
  export declare function hasSettingsMoveMarker(target: string, options?: SettingsModeOptions): Promise<boolean>;
19
20
  /** Publish once after a completed move or a usable hand-made file is found. */
20
21
  export declare function writeSettingsMoveMarker(target: string, options?: SettingsModeOptions): Promise<void>;
22
+ /** Where `host` records that its legacy store's protection is in the file. */
23
+ export declare function settingsImportRecordPath(target: string, host: SettingsHost): string;
24
+ /**
25
+ * Whether `host`'s legacy store was imported into the file, or proved to
26
+ * hold nothing the file lacks. It confers no authority: only the file or
27
+ * its `.moved` marker decide which source is in charge.
28
+ */
29
+ export declare function hasSettingsImportRecord(target: string, host: SettingsHost, options?: SettingsModeOptions): Promise<boolean>;
30
+ /**
31
+ * Record once that `host`'s store was imported. Write it only after the
32
+ * import completed (or proved there was nothing to import), never before
33
+ * the file is published. It holds no settings values.
34
+ */
35
+ export declare function writeSettingsImportRecord(target: string, host: SettingsHost, options?: SettingsModeOptions): Promise<void>;
21
36
  /** Startup/menu/watch/timer work only: request readers consume the cached mode. */
22
37
  export declare function resolveSettingsMode(paths: Pick<SettingsPaths, 'target' | 'separate'>, options?: SettingsModeOptions): Promise<SettingsMode>;
38
+ /**
39
+ * Decides, off the request path, whether a running host may start using the
40
+ * settings file through `service` (its own handle on that file). It runs the
41
+ * host's import check, and returns false to keep the host's current
42
+ * authority and ask again at the next check. 'pending' lets the host use a
43
+ * missing file, whose protection comes from the host's own recovery, but
44
+ * the host must pass the check again before it uses a file that appears.
45
+ */
46
+ export type SettingsAdoptionCheck = (service: SettingsService) => Promise<boolean | 'pending'>;
47
+ /** Attach the check a runtime must pass before adopting the file `service` reads. */
48
+ export declare function setSettingsAdoptionCheck(service: object, check: SettingsAdoptionCheck): void;
49
+ /** The check attached to `service`, if any; read it before retaining the handle. */
50
+ export declare function getSettingsAdoptionCheck(service: object | undefined): SettingsAdoptionCheck | undefined;
51
+ /**
52
+ * Record that the host uses `service`'s missing file without having imported
53
+ * its legacy store, so its runtime runs the import check before it uses a
54
+ * file that appears.
55
+ */
56
+ export declare function markSettingsImportPending(service: object): void;
57
+ /** Whether `service` was marked; read it before retaining the handle. */
58
+ export declare function isSettingsImportPending(service: object | undefined): boolean;
@@ -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. */
@@ -3,6 +3,7 @@ import { type SettingsMode, type SettingsModeOptions } from './settings-mode.ts'
3
3
  import { type SettingsMoveFenceOptions } from './settings-move-fence.ts';
4
4
  import { prepareSettingsMoveSources, type SettingsMoveSourcesOptions } from './settings-move-sources.ts';
5
5
  import { type SettingsPaths } from './settings-paths.ts';
6
+ import { type SettingsService } from './settings-service.ts';
6
7
  export interface SettingsMoveStartupOptions extends SettingsMoveSourcesOptions {
7
8
  fence: Pick<SettingsMoveFenceOptions, 'registration' | 'floor' | 'self' | 'liveness' | 'artifacts' | 'readHolders'>;
8
9
  authority?: Pick<SettingsModeOptions, 'fs' | 'ownership' | 'now'>;
@@ -14,11 +15,71 @@ export interface SettingsMoveStartupOptions extends SettingsMoveSourcesOptions {
14
15
  export interface SettingsMoveStartupResult {
15
16
  paths: SettingsPaths;
16
17
  mode: SettingsMode;
17
- /** Legacy mode still needs the user-file watch to detect another host's move. */
18
+ /** Legacy mode still needs watch callbacks and timer checks for a peer's move. */
18
19
  mayOpenService: boolean;
19
- outcome: MoveOutcome | 'marker-present' | 'source-unavailable';
20
+ outcome: MoveOutcome | 'marker-present' | 'source-unavailable'
21
+ /** The file is in charge, but this host's legacy store protects more. */
22
+ | 'import-refused'
23
+ /**
24
+ * The file is in charge, but this host's legacy store could not be read
25
+ * to check it. The host stays legacy, and its runtime checks again.
26
+ */
27
+ | 'import-unknown'
28
+ /**
29
+ * The file is in charge, but this host's legacy store was never imported
30
+ * and the file can't be checked against it yet: it is empty, unparseable,
31
+ * unreadable, or holds an invalid protection value. The host stays
32
+ * legacy, and its runtime runs the import check again.
33
+ */
34
+ | 'import-pending';
20
35
  move?: MoveResult;
36
+ /**
37
+ * In user-file mode: the file is missing and this host's legacy store was
38
+ * never imported. The host uses the file (its protection comes from this
39
+ * host's own recovery while it is missing), but its runtime must pass the
40
+ * import check before it uses a file that appears.
41
+ */
42
+ importPending?: boolean;
21
43
  }
44
+ /** What a host's import check decided about using the settings file. */
45
+ export type SettingsHostImportOutcome =
46
+ /** The file holds this host's legacy protection. */
47
+ 'adopt'
48
+ /**
49
+ * The file is missing and this host's legacy store was never imported. The
50
+ * host may use the file's service now: while the file is missing, its
51
+ * protection comes from this host's applied copy or legacy store, and its
52
+ * own menu write recreates the file carrying that set. Once a file appears
53
+ * again, the host must pass this check before it uses that file's values.
54
+ */
55
+ | 'pending'
56
+ /**
57
+ * The file exists but can't be checked yet: it is empty, unparseable,
58
+ * unreadable, or holds an invalid protection value. Its protection would
59
+ * replace this host's legacy set as soon as it became usable, so the host
60
+ * keeps its legacy settings and runs the check again later.
61
+ */
62
+ | 'retry'
63
+ /** Writing the stricter legacy values failed or raced a protection change. */
64
+ | 'refused'
65
+ /** This host's legacy store could not be read, so its protection is unknown. */
66
+ | 'unknown';
67
+ /**
68
+ * The one check a host passes before it starts using a settings file it did
69
+ * not move itself, at startup and when a running legacy host notices the
70
+ * file later. A move under an explicit target imports only the mover's
71
+ * store, and a hand-made file imports none, so the host's legacy store may
72
+ * protect more than the file. For each protection key the file sets no value
73
+ * for this host, a stricter legacy value is written at the host's level
74
+ * first; then the host's import record is written.
75
+ *
76
+ * Never call it on the request path: it reads the legacy store and may write
77
+ * the file. `retry` ends the warnings and says when the check runs again.
78
+ */
79
+ export declare function importSettingsHostStore(options: SettingsMoveSourcesOptions & {
80
+ paths: SettingsPaths;
81
+ authority?: SettingsMoveStartupOptions['authority'];
82
+ }, service: SettingsService, warn: (message: string) => void, retry: string): Promise<SettingsHostImportOutcome>;
22
83
  /**
23
84
  * Await once at host startup, before opening the settings service's first resolve.
24
85
  * Menu, watch and timer authority checks must not call the mover or retry a failed
@@ -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,39 @@ 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, from the store a default-target move would read for it: its default
36
+ * store, through its current custody and state layout, without seeding a
37
+ * vault, taking locks or writing anything. Under the default target, a local
38
+ * store that doesn't exist returns undefined: that host never ran here and
39
+ * has no set to keep.
40
+ *
41
+ * Anything else that can't name or read the peer's set throws, so the
42
+ * caller treats it as unknown and never as "no set":
43
+ * - a store that exists but can't be read, including an unreadable custody
44
+ * or layout, and vault settings that were never seeded;
45
+ * - a private XDG_CONFIG_HOME, for which a move reads only its own store;
46
+ * - the peer's own path overrides set in this process, since the peer may
47
+ * run with them or without them;
48
+ * - under an explicit target, a default store that doesn't exist: a peer
49
+ * sharing that file may keep a private store this process can't see.
50
+ */
51
+ export declare function readPeerLegacySettingsProtection(options: SettingsPathOptions & {
52
+ host: SettingsHost;
53
+ readMode?: typeof readNativeEnrollmentMode;
54
+ }): Promise<SettingsProtectionValues | undefined>;
55
+ /**
56
+ * Read this host's own legacy protection, through its current custody, to
57
+ * check whether a settings file it did not move holds it. Vault settings
58
+ * that were never seeded are read from the local store they would be seeded
59
+ * from. A store that doesn't exist returns undefined; anything that exists
60
+ * but can't be read throws. Takes no locks and writes nothing.
61
+ */
62
+ export declare function readOwnLegacySettingsProtection(options: SettingsMoveSourcesOptions): Promise<SettingsProtectionValues | undefined>;
30
63
  /**
31
64
  * Prepare the common-auth mover's sources, not a startup or authority decision.
32
65
  * An unavailable own source must keep this start in legacy mode; the caller logs
@@ -6,7 +6,13 @@ export interface SettingsProtectionCopyEntry {
6
6
  readAt: number;
7
7
  values: SettingsProtectionValues;
8
8
  }
9
- /** Missing or invalid host entries return no values, never a partial protection set. */
9
+ /**
10
+ * This host's complete set from the applied copy. A copy file that doesn't
11
+ * exist, or one without an entry for this host, returns undefined: there is
12
+ * no saved set. A copy that exists but can't be read, isn't valid JSON, or
13
+ * holds an invalid entry for this host throws instead, so callers can tell an
14
+ * unknown set from an absent one. Never returns a partial protection set.
15
+ */
10
16
  export declare function readSettingsProtectionCopy(file: string, host: SettingsHost): Promise<SettingsProtectionValues | undefined>;
11
17
  /** Merge only the writer's host while holding the copy's cross-process lock. */
12
18
  export declare function writeSettingsProtectionCopy(file: string, host: SettingsHost, entry: SettingsProtectionCopyEntry, lockTimeoutMs?: number, publicationOptions?: PublicationOptions): Promise<void>;
@@ -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>;