@cortexkit/anthropic-auth-core 1.22.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/accounts.d.ts +52 -8
- package/dist/cachekeep.d.ts +27 -1
- package/dist/cch.d.ts +11 -1
- package/dist/claude-code.d.ts +23 -1
- package/dist/claustrum-enrollment.d.ts +72 -0
- package/dist/claustrum-scoped-roster.d.ts +27 -0
- package/dist/claustrum-scoped-runtime.d.ts +31 -0
- package/dist/claustrum-scoped.d.ts +53 -0
- package/dist/claustrum.d.ts +16 -82
- package/dist/commands/account.d.ts +38 -11
- package/dist/constants.d.ts +3 -2
- package/dist/custom-headers.d.ts +3 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +29700 -31
- package/dist/internal-types/LICENSE +21 -0
- package/dist/internal-types/commands/builtins.d.ts +71 -0
- package/dist/internal-types/commands/index.d.ts +10 -0
- package/dist/internal-types/commands/menu.d.ts +61 -0
- package/dist/internal-types/commands/model.d.ts +238 -0
- package/dist/internal-types/commands/pi.d.ts +23 -0
- package/dist/internal-types/commands/seam.d.ts +72 -0
- package/dist/internal-types/fs/refresh-file-lock.d.ts +33 -0
- package/dist/internal-types/logger/capture-sink.d.ts +14 -0
- package/dist/internal-types/logger/engine.d.ts +100 -0
- package/dist/internal-types/logger/index.d.ts +6 -0
- package/dist/internal-types/logger/redact.d.ts +11 -0
- package/dist/internal-types/pi-slot/index.d.ts +3 -0
- package/dist/internal-types/pi-slot/slot.d.ts +49 -0
- package/dist/internal-types/quota/codec.d.ts +11 -0
- package/dist/internal-types/quota/format.d.ts +46 -0
- package/dist/internal-types/quota/index.d.ts +10 -0
- package/dist/internal-types/quota/map.d.ts +63 -0
- package/dist/internal-types/quota/merge.d.ts +48 -0
- package/dist/internal-types/quota/projection.d.ts +64 -0
- package/dist/internal-types/store/attribution.d.ts +28 -0
- package/dist/internal-types/store/errors.d.ts +55 -0
- package/dist/internal-types/store/hooks.d.ts +12 -0
- package/dist/internal-types/store/identity.d.ts +39 -0
- package/dist/internal-types/store/index.d.ts +21 -0
- package/dist/internal-types/store/mutate.d.ts +189 -0
- package/dist/internal-types/store/pool.d.ts +196 -0
- package/dist/internal-types/store/provider-state.d.ts +131 -0
- package/dist/internal-types/store/publication.d.ts +47 -0
- package/dist/internal-types/store/pull.d.ts +36 -0
- package/dist/internal-types/store/refresh-lock.d.ts +63 -0
- package/dist/internal-types/store/refresh.d.ts +72 -0
- package/dist/internal-types/store/rows.d.ts +313 -0
- package/dist/internal-types/store/runtime.d.ts +36 -0
- package/dist/internal-types/store/schema.d.ts +443 -0
- package/dist/internal-types/store/settings.d.ts +63 -0
- package/dist/internal-types/store/torn.d.ts +78 -0
- package/dist/migration-source.d.ts +33 -0
- package/dist/model-remap.d.ts +27 -0
- package/dist/models.d.ts +60 -0
- package/dist/native-account-runtime.d.ts +121 -0
- package/dist/native-account-view.d.ts +126 -0
- package/dist/native-command-effects.d.ts +59 -0
- package/dist/native-credential-validation.d.ts +42 -0
- package/dist/native-custody-activation.d.ts +45 -0
- package/dist/native-custody.d.ts +114 -0
- package/dist/native-enrollment-authority.d.ts +2 -0
- package/dist/native-host-auth-read.d.ts +3 -0
- package/dist/native-host-auth-write.d.ts +51 -0
- package/dist/native-host-auth.d.ts +12 -0
- package/dist/native-local-credential-service.d.ts +76 -0
- package/dist/native-local-runtime-readers.d.ts +22 -0
- package/dist/native-lock-observer.d.ts +12 -0
- package/dist/native-menu-executor.d.ts +243 -0
- package/dist/native-menu-model.d.ts +142 -0
- package/dist/native-migration-proof.d.ts +28 -0
- package/dist/native-migration-source.d.ts +47 -0
- package/dist/native-migration.d.ts +66 -0
- package/dist/native-quota-codec.d.ts +32 -0
- package/dist/native-refresh-coordinator.d.ts +240 -0
- package/dist/native-roster-seed.d.ts +115 -0
- package/dist/native-runtime-registry.d.ts +19 -0
- package/dist/native-runtime.d.ts +204 -0
- package/dist/native-transient-account.d.ts +38 -0
- package/dist/native-ui.d.ts +45 -0
- package/dist/native-usage-publication.d.ts +11 -0
- package/dist/native-vault-admission.d.ts +8 -0
- package/dist/native-vault-connection.d.ts +33 -0
- package/dist/native-vault-paths.d.ts +13 -0
- package/dist/native-vault-runtime.d.ts +102 -0
- package/dist/native-vault-seed.d.ts +16 -0
- package/dist/oauth-profile.d.ts +2 -1
- package/dist/pool-authority.d.ts +159 -0
- package/dist/pool-binding.d.ts +32 -0
- package/dist/pool-paths.d.ts +21 -0
- package/dist/pool-store.d.ts +32 -0
- package/dist/prime.d.ts +11 -3
- package/dist/provider-error.d.ts +139 -0
- package/dist/quota-header-feed.d.ts +13 -0
- package/dist/quota-manager.d.ts +30 -5
- package/dist/relay.d.ts +22 -1
- package/dist/request-history.d.ts +34 -0
- package/dist/sse.d.ts +81 -0
- package/dist/sticky-routing.d.ts +29 -0
- package/package.json +9 -3
- package/dist/accounts.js +0 -3330
- package/dist/auth.js +0 -182
- package/dist/cache1h.js +0 -97
- package/dist/cachekeep-registry.js +0 -124
- package/dist/cachekeep.js +0 -578
- package/dist/cch.js +0 -127
- package/dist/claude-code.js +0 -388
- package/dist/claustrum.js +0 -529
- package/dist/commands/account.js +0 -239
- package/dist/constants.js +0 -82
- package/dist/dump.js +0 -616
- package/dist/fast.js +0 -66
- package/dist/json.js +0 -10
- package/dist/killswitch.js +0 -132
- package/dist/logger.js +0 -286
- package/dist/logging.js +0 -59
- package/dist/mid-conversation-output-config.js +0 -89
- package/dist/models.js +0 -141
- package/dist/network-errors.js +0 -27
- package/dist/oauth-profile.js +0 -54
- package/dist/pkce.js +0 -17
- package/dist/prime.js +0 -823
- package/dist/provider.js +0 -0
- package/dist/quota-header-feed.js +0 -279
- package/dist/quota-headers.js +0 -121
- package/dist/quota-manager.js +0 -805
- package/dist/quotas.js +0 -141
- package/dist/relay.js +0 -1243
- package/dist/routing.js +0 -94
- package/dist/start.js +0 -29
- package/dist/sticky-routing.js +0 -523
- package/dist/thinking-binding.js +0 -54
- package/dist/token-fingerprint.js +0 -8
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class NativeHostAuthError extends Error {
|
|
2
|
+
readonly code: 'invalid-source' | 'supervised-auth-snapshot';
|
|
3
|
+
constructor(code: 'invalid-source' | 'supervised-auth-snapshot');
|
|
4
|
+
}
|
|
5
|
+
export declare function hasSupervisedAuthContentSnapshot(env: NodeJS.ProcessEnv): boolean;
|
|
6
|
+
export declare function requireNoSupervisedAuthContentSnapshot(env: NodeJS.ProcessEnv): void;
|
|
7
|
+
export interface NativeHostAuthEntryInspection {
|
|
8
|
+
readonly kind: 'absent' | 'oauth' | 'api' | 'api_key' | 'activation';
|
|
9
|
+
readonly digest: string;
|
|
10
|
+
}
|
|
11
|
+
/** Inspect parsed host auth only; path safety, consent and writes belong to callers. */
|
|
12
|
+
export declare function inspectNativeHostAuthEntry(host: 'opencode' | 'pi', hostAuth: unknown): Readonly<NativeHostAuthEntryInspection>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { type NativeLocalExternalPolicy } from './native-local-runtime-readers.ts';
|
|
2
|
+
import { type NativeRefreshCoordinatorOptions, type NativeRefreshObservation, type NativeRefreshRequest, type NativeRefreshResult, type NativeRefreshSubject } from './native-refresh-coordinator.ts';
|
|
3
|
+
import { type NativeLocalFailureAttribution, type NativeLocalFailurePolicy } from './native-runtime.ts';
|
|
4
|
+
import type { NativePoolPaths } from './pool-paths.ts';
|
|
5
|
+
/** A failure that can be recorded for a single credential. */
|
|
6
|
+
export type NativeLocalAttributedFailure = Exclude<NativeLocalFailureAttribution, {
|
|
7
|
+
kind: 'none';
|
|
8
|
+
}>;
|
|
9
|
+
/**
|
|
10
|
+
* Everything the failure policy may use. Both values are frozen copies taken
|
|
11
|
+
* from the coordinator's report before any lock wait. They describe the
|
|
12
|
+
* credential version the failed operation used, not the pool row or runtime
|
|
13
|
+
* entry as they are now.
|
|
14
|
+
*/
|
|
15
|
+
export interface NativeLocalFailurePolicyInput {
|
|
16
|
+
readonly observation: NativeRefreshObservation;
|
|
17
|
+
readonly attribution: NativeLocalAttributedFailure;
|
|
18
|
+
}
|
|
19
|
+
export interface NativeLocalCredentialServiceOptions {
|
|
20
|
+
/** Storage resolved by resolveNativePoolPaths. The service keeps its own copy. */
|
|
21
|
+
readonly paths: NativePoolPaths;
|
|
22
|
+
/** Recheck host custody for this observation. Already consumed successors may finish their durable reconciliation; unconsumed work must still have local authority. */
|
|
23
|
+
readonly publicationGuard: (observation: NativeRefreshObservation) => Promise<boolean>;
|
|
24
|
+
/**
|
|
25
|
+
* Decide without I/O whether local OAuth mode, the account and its quota
|
|
26
|
+
* allow the operation. Credential-validation evidence is checked separately.
|
|
27
|
+
*/
|
|
28
|
+
readonly externalPolicy: (subject: NativeRefreshSubject) => NativeLocalExternalPolicy;
|
|
29
|
+
/**
|
|
30
|
+
* Choose when a recorded failure was observed and when its credential may
|
|
31
|
+
* be retried. The service calls this once per attributable failure report,
|
|
32
|
+
* including each failed attempt of the coordinator's bounded retry loop.
|
|
33
|
+
*
|
|
34
|
+
* The coordinator reads the stored retry deadline again before each further
|
|
35
|
+
* attempt. A nextRetryAt later than the current clock therefore stops that
|
|
36
|
+
* loop: the next attempt is refused as 'refresh-backoff' and the result no
|
|
37
|
+
* longer carries the provider failure. Return nextRetryAt equal to checkedAt
|
|
38
|
+
* to record the failure without delaying the coordinator's own retries.
|
|
39
|
+
* The service never adds retries or a retry schedule of its own, and it does
|
|
40
|
+
* not treat an attempt number as proof that the failure is final.
|
|
41
|
+
*/
|
|
42
|
+
readonly failurePolicy: (input: NativeLocalFailurePolicyInput) => NativeLocalFailurePolicy;
|
|
43
|
+
/** Clock for expiry, stored retry deadlines and pool writes; defaults to Date.now. */
|
|
44
|
+
readonly now?: () => number;
|
|
45
|
+
/** Token-exchange function; defaults to the Claude OAuth refresh endpoint. */
|
|
46
|
+
readonly refreshToken?: NativeRefreshCoordinatorOptions['refreshToken'];
|
|
47
|
+
/** Account lookup for new access; defaults to the Claude Code identity lookup. */
|
|
48
|
+
readonly resolveIdentity?: NativeRefreshCoordinatorOptions['resolveIdentity'];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Hosts receive an access token only after its Claude account has been checked.
|
|
52
|
+
* That check can be reused while the refresh token, access token, expiry and
|
|
53
|
+
* stored refresh timestamp have not changed.
|
|
54
|
+
*/
|
|
55
|
+
export interface NativeLocalCredentialService {
|
|
56
|
+
authorize(request: NativeRefreshRequest): Promise<NativeRefreshResult>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Authorize local OAuth only after offline migration commits the pool as the
|
|
60
|
+
* credential authority. Creating this service neither imports credentials nor
|
|
61
|
+
* completes migration. Authority is checked before the coordinator starts and
|
|
62
|
+
* again before any access token is returned. The coordinator owns exchange,
|
|
63
|
+
* account lookup, bounded retries and the final validation check; it refuses
|
|
64
|
+
* API-key rows.
|
|
65
|
+
*
|
|
66
|
+
* Successful account checks record validation for the exact credential version.
|
|
67
|
+
* An existing runtime entry with no account UUID loses its unproven metadata,
|
|
68
|
+
* but keeps the clear timestamps that prevent older errors from returning.
|
|
69
|
+
* Known-account entries keep their metadata; a missing entry can be created
|
|
70
|
+
* only when the observation captured that absence before the provider call.
|
|
71
|
+
* Attributed failures record their credential version and caller retry policy.
|
|
72
|
+
* Writers recheck credential versions, bindings and clear timestamps under
|
|
73
|
+
* pool/runtime locks. A write fault prevents credentials from being returned,
|
|
74
|
+
* but cannot undo a token exchange or file replacement already committed.
|
|
75
|
+
*/
|
|
76
|
+
export declare function createNativeLocalCredentialService(options: NativeLocalCredentialServiceOptions): NativeLocalCredentialService;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { NativeRefreshHooks, NativeRefreshRestriction, NativeRefreshSubject } from './native-refresh-coordinator.ts';
|
|
2
|
+
import type { NativePoolPaths } from './pool-paths.ts';
|
|
3
|
+
/** Host adapters supply mode, account and quota policy for local OAuth authorization and refresh. */
|
|
4
|
+
export type NativeLocalExternalPolicy = Exclude<NativeRefreshRestriction, {
|
|
5
|
+
credentialFingerprint: string;
|
|
6
|
+
}>;
|
|
7
|
+
export interface NativeLocalRuntimeReadersOptions {
|
|
8
|
+
paths: NativePoolPaths;
|
|
9
|
+
/**
|
|
10
|
+
* Decide whether local OAuth mode, the account and quota allow the operation
|
|
11
|
+
* without I/O. Credential-validation evidence is checked separately.
|
|
12
|
+
*/
|
|
13
|
+
externalPolicy: (subject: NativeRefreshSubject) => NativeLocalExternalPolicy;
|
|
14
|
+
/** Return the current time to evaluate stored retry deadlines; tests can supply a fixed clock. */
|
|
15
|
+
now?: () => number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Provide restriction and validation reads for NativeRefreshCoordinator without
|
|
19
|
+
* retrieving credentials or writing files. Host adapters separately provide
|
|
20
|
+
* runtime publication and account selection.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createNativeLocalRuntimeReaders(options: NativeLocalRuntimeReadersOptions): Pick<NativeRefreshHooks, 'readRestrictions' | 'readAdmission'>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Diagnostic evidence, not an ownership assertion or a control hook. */
|
|
2
|
+
export type NativeLockEvent = {
|
|
3
|
+
type: 'acquired' | 'released' | 'contended';
|
|
4
|
+
name: string;
|
|
5
|
+
path: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Diagnostics cannot decide whether a lock owner refreshes or saves a token.
|
|
9
|
+
* Consume returned rejections without awaiting: an observer may never settle.
|
|
10
|
+
* With no observer, leave the producer callback absent and allocate no wrapper.
|
|
11
|
+
*/
|
|
12
|
+
export declare function nativeLockObserver(observer: ((event: NativeLockEvent) => void) | undefined): ((event: NativeLockEvent) => void) | undefined;
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { type NativeMenuActionId, type NativeMenuCacheMode, type NativeMenuCustodyMode, type NativeMenuHost, type NativeMenuLogLevel, type NativeMenuParameterId, type NativeMenuRefusalCode, type NativeMenuRoutingMode } from './native-menu-model.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Typed input checking and safety gating for native menu actions.
|
|
4
|
+
*
|
|
5
|
+
* The menu model in native-menu-model.ts only describes actions. This module
|
|
6
|
+
* checks the values a menu collected against that description and the
|
|
7
|
+
* existing command parsers' rules, applies the safety rules (headless refusal,
|
|
8
|
+
* confirmation, session requirement, cancellation before dispatch), and then
|
|
9
|
+
* hands one validated request to a host-provided capability. The capability
|
|
10
|
+
* performs the real effect; this module performs no I/O, retries, or
|
|
11
|
+
* background work, and it does not render a menu or collect input.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* One killswitch threshold row. The fields match the `/claude-killswitch set`
|
|
15
|
+
* entries, but `account` is taken as structured data, not command text.
|
|
16
|
+
*/
|
|
17
|
+
export type NativeMenuKillswitchEntry = {
|
|
18
|
+
/**
|
|
19
|
+
* An opaque account ID, passed on exactly as given, or the `main` / `all`
|
|
20
|
+
* selector. Native route IDs such as `vault:oauth:...` contain colons, so a
|
|
21
|
+
* menu that collects entries as text must keep the IDs whole rather than
|
|
22
|
+
* split them with the legacy command's `account:fh,sd` delimiters.
|
|
23
|
+
*/
|
|
24
|
+
readonly account: string;
|
|
25
|
+
/** Five-hour remaining-percent threshold. */
|
|
26
|
+
readonly fh: number;
|
|
27
|
+
/** Seven-day remaining-percent threshold. */
|
|
28
|
+
readonly sd: number;
|
|
29
|
+
/** Optional model-scoped remaining-percent threshold. */
|
|
30
|
+
readonly scoped?: number;
|
|
31
|
+
};
|
|
32
|
+
/** Values for an action that takes no parameters: no key is accepted. */
|
|
33
|
+
export type NativeMenuNoValues = {
|
|
34
|
+
readonly [key: string]: never;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* The values each action accepts. Optional inputs may be left out or sent as
|
|
38
|
+
* `null`, which is how a menu reports an input left empty.
|
|
39
|
+
*/
|
|
40
|
+
export type NativeMenuActionValues = {
|
|
41
|
+
readonly enable: {
|
|
42
|
+
readonly id: string;
|
|
43
|
+
};
|
|
44
|
+
readonly disable: {
|
|
45
|
+
readonly id: string;
|
|
46
|
+
};
|
|
47
|
+
readonly remove: {
|
|
48
|
+
readonly id: string;
|
|
49
|
+
};
|
|
50
|
+
readonly 'move-up': {
|
|
51
|
+
readonly id: string;
|
|
52
|
+
};
|
|
53
|
+
readonly 'move-down': {
|
|
54
|
+
readonly id: string;
|
|
55
|
+
};
|
|
56
|
+
readonly 'reset-backoff': NativeMenuNoValues;
|
|
57
|
+
readonly 'enrollment-reset': NativeMenuNoValues;
|
|
58
|
+
readonly 'add-apikey': {
|
|
59
|
+
readonly apiKey: string;
|
|
60
|
+
readonly label?: string | null;
|
|
61
|
+
readonly baseURL?: string | null;
|
|
62
|
+
readonly authHeader?: 'authorization-bearer' | 'x-api-key' | null;
|
|
63
|
+
};
|
|
64
|
+
readonly 'add-oauth-start': NativeMenuNoValues;
|
|
65
|
+
readonly 'add-oauth-finish': {
|
|
66
|
+
readonly code: string;
|
|
67
|
+
readonly label?: string | null;
|
|
68
|
+
};
|
|
69
|
+
readonly 'custody-mode': {
|
|
70
|
+
readonly mode: NativeMenuCustodyMode;
|
|
71
|
+
};
|
|
72
|
+
readonly 'vault-disconnect': NativeMenuNoValues;
|
|
73
|
+
readonly 'quota-refresh': NativeMenuNoValues;
|
|
74
|
+
readonly 'routing-mode': {
|
|
75
|
+
readonly mode: NativeMenuRoutingMode;
|
|
76
|
+
};
|
|
77
|
+
readonly 'routing-reset': NativeMenuNoValues;
|
|
78
|
+
readonly 'killswitch-on': NativeMenuNoValues;
|
|
79
|
+
readonly 'killswitch-off': NativeMenuNoValues;
|
|
80
|
+
readonly 'killswitch-set': {
|
|
81
|
+
readonly entries: readonly NativeMenuKillswitchEntry[];
|
|
82
|
+
};
|
|
83
|
+
readonly 'cache-on': NativeMenuNoValues;
|
|
84
|
+
readonly 'cache-off': NativeMenuNoValues;
|
|
85
|
+
readonly 'cache-mode': {
|
|
86
|
+
readonly mode: NativeMenuCacheMode;
|
|
87
|
+
};
|
|
88
|
+
readonly 'cachekeep-always': NativeMenuNoValues;
|
|
89
|
+
readonly 'cachekeep-off': NativeMenuNoValues;
|
|
90
|
+
readonly 'cachekeep-window': {
|
|
91
|
+
readonly startHour: number;
|
|
92
|
+
readonly endHour: number;
|
|
93
|
+
};
|
|
94
|
+
readonly 'cachekeep-subagents': {
|
|
95
|
+
readonly enabled: 'on' | 'off';
|
|
96
|
+
};
|
|
97
|
+
readonly 'dump-on': NativeMenuNoValues;
|
|
98
|
+
readonly 'dump-off': NativeMenuNoValues;
|
|
99
|
+
readonly 'logging-level': {
|
|
100
|
+
readonly level: NativeMenuLogLevel;
|
|
101
|
+
};
|
|
102
|
+
readonly 'fast-on': NativeMenuNoValues;
|
|
103
|
+
readonly 'fast-off': NativeMenuNoValues;
|
|
104
|
+
readonly 'prime-on': NativeMenuNoValues;
|
|
105
|
+
readonly 'prime-off': NativeMenuNoValues;
|
|
106
|
+
readonly 'start-fire': NativeMenuNoValues;
|
|
107
|
+
};
|
|
108
|
+
/** A menu request as the shared UI hands it over, before any checking. */
|
|
109
|
+
export type NativeMenuRequest = {
|
|
110
|
+
[Id in NativeMenuActionId]: NativeMenuActionValues[Id] extends NativeMenuNoValues ? {
|
|
111
|
+
readonly action: Id;
|
|
112
|
+
readonly values?: NativeMenuActionValues[Id];
|
|
113
|
+
} : {
|
|
114
|
+
readonly action: Id;
|
|
115
|
+
readonly values: NativeMenuActionValues[Id];
|
|
116
|
+
};
|
|
117
|
+
}[NativeMenuActionId];
|
|
118
|
+
/**
|
|
119
|
+
* Actions whose effect belongs to one conversation: routing reset clears that
|
|
120
|
+
* session's sticky assignment, lane start fires inside that session, and the
|
|
121
|
+
* OAuth start/finish pair keeps its pending sign-in state per session.
|
|
122
|
+
*/
|
|
123
|
+
export type NativeMenuSessionActionId = 'routing-reset' | 'start-fire' | 'add-oauth-start' | 'add-oauth-finish';
|
|
124
|
+
/**
|
|
125
|
+
* Custody changes are offline setup steps, and vault disconnect goes through
|
|
126
|
+
* the host's own disconnect capability, so neither is dispatched.
|
|
127
|
+
*/
|
|
128
|
+
export type NativeMenuDispatchActionId = Exclude<NativeMenuActionId, 'custody-mode' | 'vault-disconnect'>;
|
|
129
|
+
/** Checked values: empty optional inputs are left out instead of `null`. */
|
|
130
|
+
export type NativeMenuDispatchValues<Id extends NativeMenuDispatchActionId> = {
|
|
131
|
+
readonly [Key in keyof NativeMenuActionValues[Id]]: Exclude<NativeMenuActionValues[Id][Key], null>;
|
|
132
|
+
};
|
|
133
|
+
/** A fully checked request, the only thing a host capability receives. */
|
|
134
|
+
export type NativeMenuDispatchRequest = {
|
|
135
|
+
[Id in NativeMenuDispatchActionId]: {
|
|
136
|
+
readonly action: Id;
|
|
137
|
+
readonly values: NativeMenuDispatchValues<Id>;
|
|
138
|
+
} & (Id extends NativeMenuSessionActionId ? {
|
|
139
|
+
readonly sessionId: string;
|
|
140
|
+
} : {
|
|
141
|
+
readonly sessionId?: never;
|
|
142
|
+
});
|
|
143
|
+
}[NativeMenuDispatchActionId];
|
|
144
|
+
export type NativeMenuDispatchOptions = {
|
|
145
|
+
/** The caller's signal, passed on so a long capability may stop early. */
|
|
146
|
+
readonly signal?: AbortSignal;
|
|
147
|
+
};
|
|
148
|
+
/** What the host capability reports after it ran. */
|
|
149
|
+
export type NativeMenuCapabilityOutcome = {
|
|
150
|
+
readonly ok: boolean;
|
|
151
|
+
readonly text: string;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* The host capability that performs the real effect for a checked request.
|
|
155
|
+
* It must accept every dispatchable action; a callback written for only some
|
|
156
|
+
* actions does not satisfy this type.
|
|
157
|
+
*/
|
|
158
|
+
export type NativeMenuDispatch = (request: NativeMenuDispatchRequest, options: NativeMenuDispatchOptions) => Promise<NativeMenuCapabilityOutcome>;
|
|
159
|
+
export type NativeMenuExecutorOptions = {
|
|
160
|
+
readonly host: NativeMenuHost;
|
|
161
|
+
readonly dispatch: NativeMenuDispatch;
|
|
162
|
+
/**
|
|
163
|
+
* Ends this host's vault enrollment. Without it the executor does not offer
|
|
164
|
+
* vault-disconnect and refuses it as unsupported.
|
|
165
|
+
*/
|
|
166
|
+
readonly disconnectVault?: NativeVaultDisconnect;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* What a host's vault disconnect reports. `disconnected`: the host is back in
|
|
170
|
+
* local custody. `idle`: no active enrollment remains; Pi's saved sign-in may
|
|
171
|
+
* still have been restored. `busy`: another process holds the enrollment lock
|
|
172
|
+
* and disconnect could not finish. `conflict`:
|
|
173
|
+
* the host's stored sign-in could not be restored without overwriting one it
|
|
174
|
+
* already has, so both were kept and the enrollment remains.
|
|
175
|
+
*/
|
|
176
|
+
export type NativeVaultDisconnectResult = 'disconnected' | 'idle' | 'busy' | 'conflict';
|
|
177
|
+
/** The host capability that disconnects this host from the vault. */
|
|
178
|
+
export type NativeVaultDisconnect = (options: NativeMenuDispatchOptions) => Promise<NativeVaultDisconnectResult>;
|
|
179
|
+
/** Facts about the invocation that the safety rules depend on. */
|
|
180
|
+
export type NativeMenuExecutionContext = {
|
|
181
|
+
/** False when no person can answer prompts (a headless or scripted run). */
|
|
182
|
+
readonly interactive: boolean;
|
|
183
|
+
/**
|
|
184
|
+
* The host's credential custody, read just before this request. Under
|
|
185
|
+
* claustrum custody the vault owns every account, so actions listed in
|
|
186
|
+
* NATIVE_MENU_LOCAL_CUSTODY_ACTION_IDS are refused before dispatch. Under
|
|
187
|
+
* local custody there is no enrollment to end, so vault disconnect is
|
|
188
|
+
* refused. There is no default: a context without a valid mode is refused.
|
|
189
|
+
*/
|
|
190
|
+
readonly custodyMode: NativeMenuCustodyMode;
|
|
191
|
+
/** True once the person confirmed an action that requires confirmation. */
|
|
192
|
+
readonly confirmed?: boolean;
|
|
193
|
+
/** The conversation the request came from, when the host has one. */
|
|
194
|
+
readonly sessionId?: string;
|
|
195
|
+
readonly signal?: AbortSignal;
|
|
196
|
+
};
|
|
197
|
+
export type NativeMenuExecutorRefusalCode = NativeMenuRefusalCode | 'invalid-request' | 'invalid-context' | 'unsupported-action' | 'unknown-parameter' | 'missing-parameter' | 'invalid-parameter' | 'confirmation-required' | 'session-required' | 'aborted'
|
|
198
|
+
/** The host is connected to the vault, which owns its accounts. */
|
|
199
|
+
| 'vault-managed'
|
|
200
|
+
/** The host is not connected to the vault, so there is nothing to end. */
|
|
201
|
+
| 'vault-not-connected';
|
|
202
|
+
export type NativeMenuExecutionResult = {
|
|
203
|
+
/** The capability ran; `ok` and `text` are what it reported. */
|
|
204
|
+
readonly status: 'executed';
|
|
205
|
+
readonly action: NativeMenuDispatchActionId;
|
|
206
|
+
readonly ok: boolean;
|
|
207
|
+
readonly text: string;
|
|
208
|
+
} | {
|
|
209
|
+
/**
|
|
210
|
+
* The capability was called but threw, rejected, or returned something
|
|
211
|
+
* unreadable. Whether its effect happened is unknown.
|
|
212
|
+
*/
|
|
213
|
+
readonly status: 'failed';
|
|
214
|
+
readonly action: NativeMenuDispatchActionId | 'vault-disconnect';
|
|
215
|
+
readonly code: 'execution-failed' | 'invalid-outcome';
|
|
216
|
+
} | {
|
|
217
|
+
/** The host's disconnect capability ran and reported this result. */
|
|
218
|
+
readonly status: 'disconnect';
|
|
219
|
+
readonly action: 'vault-disconnect';
|
|
220
|
+
readonly result: NativeVaultDisconnectResult;
|
|
221
|
+
} | {
|
|
222
|
+
/** Offline custody setup steps; nothing was changed. */
|
|
223
|
+
readonly status: 'guidance';
|
|
224
|
+
readonly action: 'custody-mode';
|
|
225
|
+
readonly mode: NativeMenuCustodyMode;
|
|
226
|
+
readonly instructions: readonly string[];
|
|
227
|
+
} | {
|
|
228
|
+
/** Nothing was dispatched. */
|
|
229
|
+
readonly status: 'refused';
|
|
230
|
+
readonly code: NativeMenuExecutorRefusalCode;
|
|
231
|
+
readonly action?: NativeMenuActionId;
|
|
232
|
+
readonly parameter?: NativeMenuParameterId;
|
|
233
|
+
};
|
|
234
|
+
export type NativeMenuExecutor = {
|
|
235
|
+
readonly execute: (request: NativeMenuRequest, context: NativeMenuExecutionContext) => Promise<NativeMenuExecutionResult>;
|
|
236
|
+
};
|
|
237
|
+
/**
|
|
238
|
+
* Creates an executor for one host. The host's available actions and their
|
|
239
|
+
* safety rules come from the native menu model; `dispatch` and
|
|
240
|
+
* `disconnectVault` are captured once and called only with fully checked
|
|
241
|
+
* requests.
|
|
242
|
+
*/
|
|
243
|
+
export declare function createNativeMenuExecutor(options: NativeMenuExecutorOptions): NativeMenuExecutor;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/** Public menu metadata only; host adapters collect input and apply commands. */
|
|
2
|
+
export declare const NATIVE_MENU_GROUP_IDS: readonly ["Accounts", "Quota", "Routing", "Limits", "Cache", "Diagnostics", "Extras"];
|
|
3
|
+
export type NativeMenuGroupId = (typeof NATIVE_MENU_GROUP_IDS)[number];
|
|
4
|
+
/** OpenCode 1 and OpenCode 2 share this action profile; host integration is separate. */
|
|
5
|
+
export type NativeMenuHost = 'opencode' | 'pi';
|
|
6
|
+
export type NativeMenuCommandId = 'account' | 'quota' | 'routing' | 'killswitch' | 'cache' | 'cachekeep' | 'dump' | 'logging' | 'fast' | 'prime' | 'start';
|
|
7
|
+
export type NativeMenuRefusalCode = 'interactive-required' | 'offline-required';
|
|
8
|
+
export type NativeMenuCustodyMode = 'local' | 'claustrum';
|
|
9
|
+
export type NativeMenuRoutingMode = 'main-first' | 'fallback-first' | 'sticky-balanced';
|
|
10
|
+
export type NativeMenuCacheMode = 'explicit' | 'automatic' | 'hybrid';
|
|
11
|
+
export type NativeMenuLogLevel = 'error' | 'warn' | 'info' | 'debug' | 'trace';
|
|
12
|
+
export type NativeMenuParameterId = 'id' | 'apiKey' | 'label' | 'baseURL' | 'authHeader' | 'code' | 'mode' | 'entries' | 'startHour' | 'endHour' | 'enabled' | 'level';
|
|
13
|
+
export type NativeMenuChoiceParameter<Id extends NativeMenuParameterId = NativeMenuParameterId, Choice extends string = string> = {
|
|
14
|
+
readonly id: Id;
|
|
15
|
+
readonly kind: 'choice';
|
|
16
|
+
readonly required: boolean;
|
|
17
|
+
readonly choices: readonly Choice[];
|
|
18
|
+
};
|
|
19
|
+
/** Identifiers describe inputs, not the inputs' values or credential objects. */
|
|
20
|
+
export type NativeMenuParameter = {
|
|
21
|
+
readonly id: 'id';
|
|
22
|
+
readonly kind: 'account-id';
|
|
23
|
+
readonly required: true;
|
|
24
|
+
} | {
|
|
25
|
+
readonly id: 'apiKey' | 'label' | 'baseURL' | 'code';
|
|
26
|
+
readonly kind: 'text';
|
|
27
|
+
readonly required: boolean;
|
|
28
|
+
readonly protectedEntry: boolean;
|
|
29
|
+
} | NativeMenuChoiceParameter<'mode', NativeMenuCustodyMode> | NativeMenuChoiceParameter<'mode', NativeMenuRoutingMode> | NativeMenuChoiceParameter<'mode', NativeMenuCacheMode> | NativeMenuChoiceParameter<'authHeader', 'authorization-bearer' | 'x-api-key'> | NativeMenuChoiceParameter<'enabled', 'on' | 'off'> | NativeMenuChoiceParameter<'level', NativeMenuLogLevel> | {
|
|
30
|
+
readonly id: 'startHour' | 'endHour';
|
|
31
|
+
readonly kind: 'number';
|
|
32
|
+
readonly required: true;
|
|
33
|
+
} | {
|
|
34
|
+
readonly id: 'entries';
|
|
35
|
+
readonly kind: 'limit-entries';
|
|
36
|
+
readonly required: true;
|
|
37
|
+
readonly fields: readonly ['account', 'fh', 'sd', 'scoped?'];
|
|
38
|
+
};
|
|
39
|
+
export type NativeMenuActionId = 'enable' | 'disable' | 'remove' | 'move-up' | 'move-down' | 'reset-backoff' | 'enrollment-reset' | 'add-apikey' | 'add-oauth-start' | 'add-oauth-finish' | 'custody-mode' | 'vault-disconnect' | 'quota-refresh' | 'routing-mode' | 'routing-reset' | 'killswitch-on' | 'killswitch-off' | 'killswitch-set' | 'cache-on' | 'cache-off' | 'cache-mode' | 'cachekeep-always' | 'cachekeep-off' | 'cachekeep-window' | 'cachekeep-subagents' | 'dump-on' | 'dump-off' | 'logging-level' | 'fast-on' | 'fast-off' | 'prime-on' | 'prime-off' | 'start-fire';
|
|
40
|
+
type DestructiveId = 'remove' | 'enrollment-reset' | 'vault-disconnect';
|
|
41
|
+
type InteractiveId = 'add-apikey' | 'add-oauth-start' | 'add-oauth-finish' | 'custody-mode' | 'vault-disconnect';
|
|
42
|
+
type ActionSafety<Id extends NativeMenuActionId> = (Id extends DestructiveId ? {
|
|
43
|
+
readonly destructive: true;
|
|
44
|
+
readonly confirm: string;
|
|
45
|
+
} : {
|
|
46
|
+
readonly destructive: false;
|
|
47
|
+
readonly confirm?: never;
|
|
48
|
+
}) & (Id extends InteractiveId ? {
|
|
49
|
+
readonly interactive: true;
|
|
50
|
+
readonly headlessRefusal: NativeMenuRefusalCode;
|
|
51
|
+
} : {
|
|
52
|
+
readonly interactive: false;
|
|
53
|
+
readonly headlessRefusal?: never;
|
|
54
|
+
});
|
|
55
|
+
export type NativeMenuAction = {
|
|
56
|
+
[Id in NativeMenuActionId]: {
|
|
57
|
+
readonly id: Id;
|
|
58
|
+
readonly label: string;
|
|
59
|
+
} & ActionSafety<Id> & (Id extends 'custody-mode' ? {
|
|
60
|
+
readonly kind: 'setup-guidance';
|
|
61
|
+
readonly command: 'account';
|
|
62
|
+
readonly group: 'Accounts';
|
|
63
|
+
readonly parameters: readonly [
|
|
64
|
+
NativeMenuChoiceParameter<'mode', NativeMenuCustodyMode>
|
|
65
|
+
];
|
|
66
|
+
readonly offlineRequired: true;
|
|
67
|
+
readonly setupInstructions: readonly string[];
|
|
68
|
+
} : Id extends 'vault-disconnect' ? {
|
|
69
|
+
/**
|
|
70
|
+
* Ends this host's vault enrollment through the host's own
|
|
71
|
+
* disconnect capability, never through the account dispatch.
|
|
72
|
+
*/
|
|
73
|
+
readonly kind: 'vault-disconnect';
|
|
74
|
+
readonly command: 'account';
|
|
75
|
+
readonly group: 'Accounts';
|
|
76
|
+
readonly parameters: readonly [];
|
|
77
|
+
} : {
|
|
78
|
+
readonly kind: 'action';
|
|
79
|
+
readonly command: NativeMenuCommandId;
|
|
80
|
+
readonly group: NativeMenuGroupId;
|
|
81
|
+
readonly parameters: readonly NativeMenuParameter[];
|
|
82
|
+
});
|
|
83
|
+
}[NativeMenuActionId];
|
|
84
|
+
export type NativeMenuStatus = {
|
|
85
|
+
readonly kind: 'status';
|
|
86
|
+
readonly id: `${Exclude<NativeMenuCommandId, 'start'>}-status`;
|
|
87
|
+
readonly command: Exclude<NativeMenuCommandId, 'start'>;
|
|
88
|
+
readonly group: NativeMenuGroupId;
|
|
89
|
+
readonly label: string;
|
|
90
|
+
};
|
|
91
|
+
export type NativeMenuGroup = {
|
|
92
|
+
readonly id: NativeMenuGroupId;
|
|
93
|
+
readonly actions: readonly NativeMenuAction[];
|
|
94
|
+
readonly statuses: readonly NativeMenuStatus[];
|
|
95
|
+
};
|
|
96
|
+
export type NativeMenuModel = {
|
|
97
|
+
readonly host: NativeMenuHost;
|
|
98
|
+
readonly groups: readonly NativeMenuGroup[];
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Actions offered only under local custody. Most write accounts or credentials
|
|
102
|
+
* held by this host: sign-in, API-key additions, removal and reordering.
|
|
103
|
+
* Enrollment reset repairs a terminal enrollment ceremony, and custody setup
|
|
104
|
+
* guidance describes connecting through offline setup; neither has a use
|
|
105
|
+
* while the host is enrolled. Under claustrum custody the vault is the only
|
|
106
|
+
* account authority, so these actions are left out of the menu and refused if
|
|
107
|
+
* a request for one still arrives. They return once the host is disconnected
|
|
108
|
+
* from the vault and back in local custody.
|
|
109
|
+
*/
|
|
110
|
+
export declare const NATIVE_MENU_LOCAL_CUSTODY_ACTION_IDS: readonly ["remove", "move-up", "move-down", "enrollment-reset", "add-apikey", "add-oauth-start", "add-oauth-finish", "custody-mode"];
|
|
111
|
+
export type NativeMenuLocalCustodyActionId = (typeof NATIVE_MENU_LOCAL_CUSTODY_ACTION_IDS)[number];
|
|
112
|
+
/** True for an action offered only while the host is in local custody. */
|
|
113
|
+
export declare function isNativeMenuLocalCustodyAction(id: NativeMenuActionId): id is NativeMenuLocalCustodyActionId;
|
|
114
|
+
/**
|
|
115
|
+
* When the host uses its local credential pool, hide vault-disconnect because
|
|
116
|
+
* no vault enrollment needs to end. Offer disconnect when enrollment grants
|
|
117
|
+
* this host access to the vault, or when that enrollment cannot be read so a
|
|
118
|
+
* person can recover from damaged enrollment files.
|
|
119
|
+
*/
|
|
120
|
+
export declare const NATIVE_MENU_VAULT_CUSTODY_ACTION_IDS: readonly ["vault-disconnect"];
|
|
121
|
+
export type NativeMenuVaultCustodyActionId = (typeof NATIVE_MENU_VAULT_CUSTODY_ACTION_IDS)[number];
|
|
122
|
+
/** True for actions shown when this host obtains credentials from the vault instead of its local pool. */
|
|
123
|
+
export declare function isNativeMenuVaultCustodyAction(id: NativeMenuActionId): id is NativeMenuVaultCustodyActionId;
|
|
124
|
+
/**
|
|
125
|
+
* Every action the host supports under either custody mode, in menu order.
|
|
126
|
+
* Request checking uses this list so it can recognise an action the current
|
|
127
|
+
* custody mode no longer offers and refuse it by name.
|
|
128
|
+
*/
|
|
129
|
+
export declare function listNativeMenuActions(host: NativeMenuHost): readonly NativeMenuAction[];
|
|
130
|
+
/**
|
|
131
|
+
* Stable frozen metadata, with no current settings or credential material.
|
|
132
|
+
* Returns the actions the host offers under the given custody mode: local
|
|
133
|
+
* custody leaves out NATIVE_MENU_VAULT_CUSTODY_ACTION_IDS, and claustrum
|
|
134
|
+
* custody leaves out NATIVE_MENU_LOCAL_CUSTODY_ACTION_IDS. Local custody means
|
|
135
|
+
* this host keeps its own accounts; claustrum custody means the host is
|
|
136
|
+
* enrolled in the vault, which owns its accounts. The mode is required so no
|
|
137
|
+
* caller can fall back to the full action set by omission and offer local
|
|
138
|
+
* credential changes (sign-in, API keys, removal, reordering) to a host
|
|
139
|
+
* enrolled in the vault.
|
|
140
|
+
*/
|
|
141
|
+
export declare function getNativeMenuModel(host: NativeMenuHost, custody: NativeMenuCustodyMode): NativeMenuModel;
|
|
142
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { PoolRow, StoredCredential } from "./internal-types/store/index.js";
|
|
2
|
+
export declare class NativeMigrationProofError extends Error {
|
|
3
|
+
readonly code = "prepared-proof-refused";
|
|
4
|
+
constructor();
|
|
5
|
+
}
|
|
6
|
+
/** Credential-derived digests belong only in the owner-only migration journal. */
|
|
7
|
+
export interface NativeMigrationRowProof {
|
|
8
|
+
id: string;
|
|
9
|
+
credentialEpoch: number;
|
|
10
|
+
identity: string | null;
|
|
11
|
+
stamp: 'bound';
|
|
12
|
+
credentialDigest: string;
|
|
13
|
+
}
|
|
14
|
+
export interface NativeMigrationPreparedProof {
|
|
15
|
+
version: 1;
|
|
16
|
+
rows: NativeMigrationRowProof[];
|
|
17
|
+
runtimeDigest: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function requireNativeMigrationDataObject(value: unknown): asserts value is Record<string, unknown>;
|
|
20
|
+
/** Copy inert JSON before decoding; never invoke a getter, proxy trap or toJSON. */
|
|
21
|
+
export declare function captureNativeMigrationJson(value: unknown): unknown;
|
|
22
|
+
export declare function nativeMigrationCanonicalJson(value: unknown): string;
|
|
23
|
+
export declare function nativeMigrationDigest(value: unknown): string;
|
|
24
|
+
/** Fixed-order, complete public descriptor; absence is different from a value. */
|
|
25
|
+
export declare function nativeMigrationCredentialDigest(credential: StoredCredential): string;
|
|
26
|
+
export declare function captureNativeMigrationPreparedProof(rows: readonly PoolRow[], runtimeProjection: unknown): NativeMigrationPreparedProof;
|
|
27
|
+
export declare function decodeNativeMigrationPreparedProof(input: unknown): NativeMigrationPreparedProof;
|
|
28
|
+
export declare function requireNativeMigrationPreparedProof(proof: NativeMigrationPreparedProof | null, rows: readonly PoolRow[], runtimeProjection: unknown): void;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type PoolCredential, type PoolRow } from "./internal-types/store/index.js";
|
|
2
|
+
import { type NativeQuotaMap } from './native-quota-codec.ts';
|
|
3
|
+
import type { NativeRosterSeedLegacyRow, NativeVaultRosterSeed } from './native-roster-seed.ts';
|
|
4
|
+
import { type NativeRuntimeState } from './native-runtime.ts';
|
|
5
|
+
import type { NativePoolPaths } from './pool-paths.ts';
|
|
6
|
+
export declare class NativeMigrationProjectionError extends Error {
|
|
7
|
+
readonly code = "invalid-migration-source";
|
|
8
|
+
constructor();
|
|
9
|
+
}
|
|
10
|
+
export interface NativeMigrationAccount {
|
|
11
|
+
id: string;
|
|
12
|
+
enabled: boolean;
|
|
13
|
+
identity?: string;
|
|
14
|
+
label?: string;
|
|
15
|
+
credential?: PoolCredential;
|
|
16
|
+
quota?: NativeQuotaMap;
|
|
17
|
+
runtime: Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
export interface NativeMigrationProjection {
|
|
20
|
+
accounts: NativeMigrationAccount[];
|
|
21
|
+
settings: Record<string, unknown>;
|
|
22
|
+
mainRouteId: string;
|
|
23
|
+
custodyRows: NativeRosterSeedLegacyRow[];
|
|
24
|
+
custodyPrimary?: {
|
|
25
|
+
credentialId: string;
|
|
26
|
+
accountIdentity: string;
|
|
27
|
+
};
|
|
28
|
+
disabledAccountIdentities: string[];
|
|
29
|
+
relay?: {
|
|
30
|
+
token: string;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export interface NativeMigrationSourceInput {
|
|
34
|
+
host: 'opencode' | 'pi';
|
|
35
|
+
storageId: string;
|
|
36
|
+
configDigest: string | null;
|
|
37
|
+
config: unknown;
|
|
38
|
+
state: unknown;
|
|
39
|
+
hostAuth: unknown;
|
|
40
|
+
}
|
|
41
|
+
export declare function validateNativeMigrationSettings(settings: Record<string, unknown>): void;
|
|
42
|
+
/** Deterministic projection of captured JSON, without invoking legacy loaders or callbacks. */
|
|
43
|
+
export declare function projectNativeMigrationSource(input: NativeMigrationSourceInput): NativeMigrationProjection;
|
|
44
|
+
/** Ignore lastRefreshedAt here: adding an OAuth row generates it, so it is not source data. */
|
|
45
|
+
export declare function requireNativeMigrationSourceRows(projection: NativeMigrationProjection, rows: readonly PoolRow[], checkQuota?: boolean): void;
|
|
46
|
+
/** Use row.credentialEpoch to associate imported quota and errors with the stored credentials. The store’s internal integrity hash is not a public account version. */
|
|
47
|
+
export declare function projectNativeMigrationRuntime(paths: NativePoolPaths, projection: NativeMigrationProjection, rows: readonly PoolRow[], seed?: NativeVaultRosterSeed): NativeRuntimeState;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type PoolRow } from "./internal-types/store/index.js";
|
|
2
|
+
import type { NativeCustodyInventory } from './native-custody.ts';
|
|
3
|
+
import { type NativeHostAuthWriteHooks } from './native-host-auth-write.ts';
|
|
4
|
+
import { type NativeRosterSeedInput, type NativeVaultRosterSeed } from './native-roster-seed.ts';
|
|
5
|
+
import { type NativeRuntimeState } from './native-runtime.ts';
|
|
6
|
+
import { type NativeMigrationJournal } from './pool-authority.ts';
|
|
7
|
+
import { type NativePoolPaths } from './pool-paths.ts';
|
|
8
|
+
import { createNativePoolStore } from './pool-store.ts';
|
|
9
|
+
export declare class NativeMigrationError extends Error {
|
|
10
|
+
readonly code: 'invalid-source' | 'unsafe-source' | 'consent-required' | 'primary-unverified' | 'migration-busy' | 'ownership-lost' | 'retirement-refused';
|
|
11
|
+
constructor(code: 'invalid-source' | 'unsafe-source' | 'consent-required' | 'primary-unverified' | 'migration-busy' | 'ownership-lost' | 'retirement-refused');
|
|
12
|
+
}
|
|
13
|
+
export interface NativeMigrationCustody {
|
|
14
|
+
/** Use the host’s approved Claustrum token and account-list permission to discover accounts; never open the vault’s credential files. */
|
|
15
|
+
discover: () => Promise<NativeCustodyInventory>;
|
|
16
|
+
/** Use publishNativeVaultRosterSeed to verify that this controller still owns the migration journal lock before replacing the account list. */
|
|
17
|
+
publishSeed: (paths: NativePoolPaths, input: NativeRosterSeedInput, options: {
|
|
18
|
+
assertOwned: () => Promise<void>;
|
|
19
|
+
}) => Promise<NativeVaultRosterSeed>;
|
|
20
|
+
/** Use publishNativeVaultRuntimeSeed to match metadata to its vault account while holding the account-list and migration-journal locks. */
|
|
21
|
+
publishRuntimeSeed: (paths: NativePoolPaths, state: NativeRuntimeState, options: {
|
|
22
|
+
assertOwned: () => Promise<void>;
|
|
23
|
+
}) => Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export interface NativeMigrationOptions {
|
|
26
|
+
paths: NativePoolPaths;
|
|
27
|
+
/** Keep the configured config and state paths so the reader rejects either file if it is a symbolic link. */
|
|
28
|
+
legacyConfigPath?: string;
|
|
29
|
+
legacyStatePath?: string;
|
|
30
|
+
host: 'opencode' | 'pi';
|
|
31
|
+
hostAuthPath: string;
|
|
32
|
+
routingSourcePath: string;
|
|
33
|
+
routingDestinationPath: string;
|
|
34
|
+
env: NodeJS.ProcessEnv;
|
|
35
|
+
processFence: () => Promise<void>;
|
|
36
|
+
removePiAnthropicAuth: boolean;
|
|
37
|
+
custody?: NativeMigrationCustody;
|
|
38
|
+
preflight?: NativeMigrationPreflight;
|
|
39
|
+
/**
|
|
40
|
+
* Offline setup sets requestVaultActivation when the user explicitly chose vault custody. It
|
|
41
|
+
* applies only when no journal exists yet; it keeps the pool unauthorized
|
|
42
|
+
* after this migration commits until runNativeCustodyActivation commits.
|
|
43
|
+
*/
|
|
44
|
+
requestVaultActivation?: boolean;
|
|
45
|
+
}
|
|
46
|
+
/** Result of read-only checks for the selected storage and host. Contains no account data or credential digests. */
|
|
47
|
+
export interface NativeMigrationPreflight {
|
|
48
|
+
readonly storageId: string;
|
|
49
|
+
readonly host: 'opencode' | 'pi';
|
|
50
|
+
}
|
|
51
|
+
export interface NativeMigrationHooks {
|
|
52
|
+
/** Test hook for interruptions and lease loss. Receives step labels, never credentials or their digests. */
|
|
53
|
+
onStep?: (step: string) => Promise<void>;
|
|
54
|
+
hostWrite?: NativeHostAuthWriteHooks;
|
|
55
|
+
store?: Pick<Parameters<typeof createNativePoolStore>[0], 'onStep' | 'onLockStep'>;
|
|
56
|
+
}
|
|
57
|
+
/** Preflight is read-only so setup can validate all selected hosts before any begin. */
|
|
58
|
+
export declare function prepareNativeMigration(input: NativeMigrationOptions): Promise<NativeMigrationPreflight>;
|
|
59
|
+
export declare function releaseNativeMigrationPreflight(token: NativeMigrationPreflight): void;
|
|
60
|
+
/**
|
|
61
|
+
* The public, secret-free state recorded alongside account credential digests for recovery checks:
|
|
62
|
+
* runtime metadata, settings, account flags and quota, and the vault roster.
|
|
63
|
+
*/
|
|
64
|
+
export declare function importedRuntimeProjection(paths: NativePoolPaths, store: ReturnType<typeof createNativePoolStore>, rows: PoolRow[]): Promise<unknown>;
|
|
65
|
+
/** Offline, crash-forward transaction. Native serving never calls this controller. */
|
|
66
|
+
export declare function runNativeMigration(input: NativeMigrationOptions, hooks?: NativeMigrationHooks): Promise<NativeMigrationJournal>;
|