@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.
Files changed (133) hide show
  1. package/README.md +2 -0
  2. package/dist/accounts.d.ts +52 -8
  3. package/dist/cachekeep.d.ts +27 -1
  4. package/dist/cch.d.ts +11 -1
  5. package/dist/claude-code.d.ts +23 -1
  6. package/dist/claustrum-enrollment.d.ts +72 -0
  7. package/dist/claustrum-scoped-roster.d.ts +27 -0
  8. package/dist/claustrum-scoped-runtime.d.ts +31 -0
  9. package/dist/claustrum-scoped.d.ts +53 -0
  10. package/dist/claustrum.d.ts +16 -82
  11. package/dist/commands/account.d.ts +38 -11
  12. package/dist/constants.d.ts +3 -2
  13. package/dist/custom-headers.d.ts +3 -0
  14. package/dist/index.d.ts +50 -0
  15. package/dist/index.js +29700 -31
  16. package/dist/internal-types/LICENSE +21 -0
  17. package/dist/internal-types/commands/builtins.d.ts +71 -0
  18. package/dist/internal-types/commands/index.d.ts +10 -0
  19. package/dist/internal-types/commands/menu.d.ts +61 -0
  20. package/dist/internal-types/commands/model.d.ts +238 -0
  21. package/dist/internal-types/commands/pi.d.ts +23 -0
  22. package/dist/internal-types/commands/seam.d.ts +72 -0
  23. package/dist/internal-types/fs/refresh-file-lock.d.ts +33 -0
  24. package/dist/internal-types/logger/capture-sink.d.ts +14 -0
  25. package/dist/internal-types/logger/engine.d.ts +100 -0
  26. package/dist/internal-types/logger/index.d.ts +6 -0
  27. package/dist/internal-types/logger/redact.d.ts +11 -0
  28. package/dist/internal-types/pi-slot/index.d.ts +3 -0
  29. package/dist/internal-types/pi-slot/slot.d.ts +49 -0
  30. package/dist/internal-types/quota/codec.d.ts +11 -0
  31. package/dist/internal-types/quota/format.d.ts +46 -0
  32. package/dist/internal-types/quota/index.d.ts +10 -0
  33. package/dist/internal-types/quota/map.d.ts +63 -0
  34. package/dist/internal-types/quota/merge.d.ts +48 -0
  35. package/dist/internal-types/quota/projection.d.ts +64 -0
  36. package/dist/internal-types/store/attribution.d.ts +28 -0
  37. package/dist/internal-types/store/errors.d.ts +55 -0
  38. package/dist/internal-types/store/hooks.d.ts +12 -0
  39. package/dist/internal-types/store/identity.d.ts +39 -0
  40. package/dist/internal-types/store/index.d.ts +21 -0
  41. package/dist/internal-types/store/mutate.d.ts +189 -0
  42. package/dist/internal-types/store/pool.d.ts +196 -0
  43. package/dist/internal-types/store/provider-state.d.ts +131 -0
  44. package/dist/internal-types/store/publication.d.ts +47 -0
  45. package/dist/internal-types/store/pull.d.ts +36 -0
  46. package/dist/internal-types/store/refresh-lock.d.ts +63 -0
  47. package/dist/internal-types/store/refresh.d.ts +72 -0
  48. package/dist/internal-types/store/rows.d.ts +313 -0
  49. package/dist/internal-types/store/runtime.d.ts +36 -0
  50. package/dist/internal-types/store/schema.d.ts +443 -0
  51. package/dist/internal-types/store/settings.d.ts +63 -0
  52. package/dist/internal-types/store/torn.d.ts +78 -0
  53. package/dist/migration-source.d.ts +33 -0
  54. package/dist/model-remap.d.ts +27 -0
  55. package/dist/models.d.ts +60 -0
  56. package/dist/native-account-runtime.d.ts +121 -0
  57. package/dist/native-account-view.d.ts +126 -0
  58. package/dist/native-command-effects.d.ts +59 -0
  59. package/dist/native-credential-validation.d.ts +42 -0
  60. package/dist/native-custody-activation.d.ts +45 -0
  61. package/dist/native-custody.d.ts +114 -0
  62. package/dist/native-enrollment-authority.d.ts +2 -0
  63. package/dist/native-host-auth-read.d.ts +3 -0
  64. package/dist/native-host-auth-write.d.ts +51 -0
  65. package/dist/native-host-auth.d.ts +12 -0
  66. package/dist/native-local-credential-service.d.ts +76 -0
  67. package/dist/native-local-runtime-readers.d.ts +22 -0
  68. package/dist/native-lock-observer.d.ts +12 -0
  69. package/dist/native-menu-executor.d.ts +243 -0
  70. package/dist/native-menu-model.d.ts +142 -0
  71. package/dist/native-migration-proof.d.ts +28 -0
  72. package/dist/native-migration-source.d.ts +47 -0
  73. package/dist/native-migration.d.ts +66 -0
  74. package/dist/native-quota-codec.d.ts +32 -0
  75. package/dist/native-refresh-coordinator.d.ts +240 -0
  76. package/dist/native-roster-seed.d.ts +115 -0
  77. package/dist/native-runtime-registry.d.ts +19 -0
  78. package/dist/native-runtime.d.ts +204 -0
  79. package/dist/native-transient-account.d.ts +38 -0
  80. package/dist/native-ui.d.ts +45 -0
  81. package/dist/native-usage-publication.d.ts +11 -0
  82. package/dist/native-vault-admission.d.ts +8 -0
  83. package/dist/native-vault-connection.d.ts +33 -0
  84. package/dist/native-vault-paths.d.ts +13 -0
  85. package/dist/native-vault-runtime.d.ts +102 -0
  86. package/dist/native-vault-seed.d.ts +16 -0
  87. package/dist/oauth-profile.d.ts +2 -1
  88. package/dist/pool-authority.d.ts +159 -0
  89. package/dist/pool-binding.d.ts +32 -0
  90. package/dist/pool-paths.d.ts +21 -0
  91. package/dist/pool-store.d.ts +32 -0
  92. package/dist/prime.d.ts +11 -3
  93. package/dist/provider-error.d.ts +139 -0
  94. package/dist/quota-header-feed.d.ts +13 -0
  95. package/dist/quota-manager.d.ts +30 -5
  96. package/dist/relay.d.ts +22 -1
  97. package/dist/request-history.d.ts +34 -0
  98. package/dist/sse.d.ts +81 -0
  99. package/dist/sticky-routing.d.ts +29 -0
  100. package/package.json +9 -3
  101. package/dist/accounts.js +0 -3330
  102. package/dist/auth.js +0 -182
  103. package/dist/cache1h.js +0 -97
  104. package/dist/cachekeep-registry.js +0 -124
  105. package/dist/cachekeep.js +0 -578
  106. package/dist/cch.js +0 -127
  107. package/dist/claude-code.js +0 -388
  108. package/dist/claustrum.js +0 -529
  109. package/dist/commands/account.js +0 -239
  110. package/dist/constants.js +0 -82
  111. package/dist/dump.js +0 -616
  112. package/dist/fast.js +0 -66
  113. package/dist/json.js +0 -10
  114. package/dist/killswitch.js +0 -132
  115. package/dist/logger.js +0 -286
  116. package/dist/logging.js +0 -59
  117. package/dist/mid-conversation-output-config.js +0 -89
  118. package/dist/models.js +0 -141
  119. package/dist/network-errors.js +0 -27
  120. package/dist/oauth-profile.js +0 -54
  121. package/dist/pkce.js +0 -17
  122. package/dist/prime.js +0 -823
  123. package/dist/provider.js +0 -0
  124. package/dist/quota-header-feed.js +0 -279
  125. package/dist/quota-headers.js +0 -121
  126. package/dist/quota-manager.js +0 -805
  127. package/dist/quotas.js +0 -141
  128. package/dist/relay.js +0 -1243
  129. package/dist/routing.js +0 -94
  130. package/dist/start.js +0 -29
  131. package/dist/sticky-routing.js +0 -523
  132. package/dist/thinking-binding.js +0 -54
  133. package/dist/token-fingerprint.js +0 -8
package/README.md CHANGED
@@ -6,3 +6,5 @@ User-facing packages:
6
6
 
7
7
  - `@cortexkit/opencode-anthropic-auth` for OpenCode
8
8
  - `@cortexkit/pi-anthropic-auth` for Pi
9
+
10
+ Claude Haiku 5.5 (`claude-haiku-5-5`) has a 1M-token context window and 128K max output. Standard input/output rates are $0.10/$0.50 per million tokens; all rates increase fivefold above 100K total input, including cached tokens. Optional quota priming continues to send a minimal Haiku 4.5 request to start a new quota window.
@@ -1,5 +1,7 @@
1
+ import type { ProviderAccountUuid } from './claude-code.ts';
1
2
  import { type Cache1hMode } from './constants.ts';
2
3
  import { type LogLevel } from './logger.ts';
4
+ export type { ProviderAccountUuid } from './claude-code.ts';
3
5
  export declare const ACCOUNT_FILE_NAME = "anthropic-auth.json";
4
6
  export declare const ACCOUNT_STATE_FILE_NAME = "anthropic-auth-state.json";
5
7
  export declare const QUOTA_URL = "https://api.anthropic.com/api/oauth/usage";
@@ -18,7 +20,10 @@ export type AccountBase = {
18
20
  export type OAuthAccount = AccountBase & {
19
21
  type: 'oauth';
20
22
  authLineageId?: string;
21
- claustrumHandle?: string;
23
+ anthropicAccountUuid?: ProviderAccountUuid;
24
+ /** Non-secret scoped identity; never a capability handle or bearer token. */
25
+ claustrumScopedCredentialId?: string;
26
+ claustrumScopedState?: string;
22
27
  access?: string;
23
28
  refresh: string;
24
29
  expires?: number;
@@ -33,6 +38,10 @@ export type OAuthAccount = AccountBase & {
33
38
  */
34
39
  prime?: PrimeUsageCounters;
35
40
  };
41
+ export declare function hasNoLocalCredential(account: {
42
+ access?: unknown;
43
+ refresh?: unknown;
44
+ }): boolean;
36
45
  export type ApiKeyAccount = AccountBase & {
37
46
  type: 'api';
38
47
  apiKey?: string;
@@ -40,11 +49,21 @@ export type ApiKeyAccount = AccountBase & {
40
49
  authHeader?: 'authorization-bearer' | 'x-api-key';
41
50
  };
42
51
  export type FallbackAccount = OAuthAccount | ApiKeyAccount;
43
- export type ClaustrumAccountGate = {
44
- enabled?: boolean;
45
- };
52
+ export type ClaustrumMode = 'local' | 'claustrum';
46
53
  export type ClaustrumConfig = {
47
- accounts?: Record<string, ClaustrumAccountGate>;
54
+ mode?: ClaustrumMode;
55
+ /** Set by authoritative scoped discovery, not an authentication toggle. */
56
+ scopedRoster?: true;
57
+ /** Producer inventory cursor committed with the roster; never a bearer. */
58
+ rosterView?: string;
59
+ /** Authoritative, non-secret primary identity from scoped discovery. */
60
+ primaryAccount?: {
61
+ credentialId: string;
62
+ accountId: ProviderAccountUuid;
63
+ state: string;
64
+ };
65
+ /** Preserve explicit exclusions when a vaulted account disappears and returns. */
66
+ disabledAccountIdentities?: string[];
48
67
  };
49
68
  export declare function isOAuthAccount(account: FallbackAccount): account is OAuthAccount;
50
69
  export declare function isApiKeyAccount(account: FallbackAccount): account is ApiKeyAccount;
@@ -105,6 +124,7 @@ export type OAuthAccountProfile = {
105
124
  checkedAt: number;
106
125
  /** Stable account identity; tokenFingerprint remains loadable for legacy state. */
107
126
  accountIdentity?: string;
127
+ providerAccountUuid?: ProviderAccountUuid;
108
128
  tokenFingerprint?: string;
109
129
  };
110
130
  export type OAuthQuotaSnapshot = Partial<Record<QuotaWindowName, AccountQuotaWindow>> & {
@@ -244,10 +264,11 @@ export type AccountStorage = {
244
264
  * (to display the provider's real model costs).
245
265
  */
246
266
  export declare function isCostZeroingEnabled(storage: Pick<AccountStorage, 'costZeroing'>): boolean;
247
- export type AccountRuntimeEntry = Partial<Pick<OAuthAccount, 'access' | 'authLineageId' | 'claustrumHandle' | 'refresh' | 'expires' | 'lastUsed' | 'lastRefreshedAt' | 'lastRefreshError' | 'lastQuotaRefreshError' | 'quota' | 'profile' | 'prime'> & Pick<ApiKeyAccount, 'apiKey' | 'lastUsed'>>;
267
+ export type AccountRuntimeEntry = Partial<Pick<OAuthAccount, 'access' | 'authLineageId' | 'anthropicAccountUuid' | 'claustrumScopedCredentialId' | 'claustrumScopedState' | 'refresh' | 'expires' | 'lastUsed' | 'lastRefreshedAt' | 'lastRefreshError' | 'lastQuotaRefreshError' | 'quota' | 'profile' | 'prime'> & Pick<ApiKeyAccount, 'apiKey' | 'lastUsed'>>;
248
268
  export type AccountRuntimeState = {
249
269
  version: 1;
250
270
  main?: {
271
+ scopedAccountIdentity?: string;
251
272
  profile?: OAuthAccountProfile;
252
273
  profileToken?: string;
253
274
  quota?: OAuthQuotaSnapshot;
@@ -305,7 +326,8 @@ export declare function loadAccounts(path?: string): Promise<AccountStorage | nu
305
326
  export declare function quotaSnapshotCheckedAt(quota: OAuthQuotaSnapshot | undefined): number;
306
327
  export declare function quotaFieldSource(snapshot: OAuthQuotaSnapshot | undefined, field: QuotaFieldName): QuotaFieldSource | undefined;
307
328
  export declare function mergeHeaderQuotaForPersistence(existing: OAuthQuotaSnapshot | undefined, incoming: OAuthQuotaSnapshot): OAuthQuotaSnapshot;
308
- export declare function isClaustrumEnabledForAccount(storage: AccountStorage, accountId: string): boolean;
329
+ export declare function getClaustrumMode(storage: AccountStorage | null): ClaustrumMode;
330
+ export declare function setClaustrumModePersistent(mode: ClaustrumMode, path?: string): Promise<'changed' | 'unchanged'>;
309
331
  export interface SaveAccountsOptions {
310
332
  /** Account ids intentionally removed by this mutation. */
311
333
  removedAccountIds?: readonly string[];
@@ -313,6 +335,19 @@ export interface SaveAccountsOptions {
313
335
  preserveExistingAccountOrder?: boolean;
314
336
  }
315
337
  export declare function saveAccounts(storage: AccountStorage, path?: string, options?: SaveAccountsOptions): Promise<void>;
338
+ /** Read-modify-write account configuration under the existing config/state lock order.
339
+ * The callback is synchronous: network discovery must happen under its own outer
340
+ * lease, never while holding the config lock. Do not call another persistence API
341
+ * from the callback.
342
+ */
343
+ export declare function mutateAccountsPersistent<T>(path: string, mutate: (storage: AccountStorage) => {
344
+ storage: AccountStorage;
345
+ result: T;
346
+ options?: SaveAccountsOptions;
347
+ save?: boolean;
348
+ }, options?: {
349
+ assertAuthority?: () => Promise<void>;
350
+ }): Promise<T>;
316
351
  export declare function getOrCreateMainAccountId(path?: string, createId?: () => string): Promise<string>;
317
352
  export declare function saveAccountState(storage: AccountStorage, path?: string, scope?: AccountStateSaveScope): Promise<void>;
318
353
  export declare function saveOAuthProfileState(input: {
@@ -320,7 +355,6 @@ export declare function saveOAuthProfileState(input: {
320
355
  profile: OAuthAccountProfile | undefined;
321
356
  accountIdentity?: string;
322
357
  }, path?: string): Promise<boolean>;
323
- export declare function clearClaustrumRefreshErrorPersistent(accountId: string, handle: string, path?: string): Promise<boolean>;
324
358
  export declare function acquireRefreshFileLock(options: {
325
359
  name: string;
326
360
  ttlMs: number;
@@ -331,6 +365,7 @@ export declare function acquireRefreshFileLock(options: {
331
365
  onStep?: (step: 'stale-marker-stat' | 'stale-marker-claimed' | 'stale-lock-confirmed' | 'eviction-marker-acquired') => void | Promise<void>;
332
366
  }): Promise<{
333
367
  release: () => Promise<void>;
368
+ assertOwned: () => Promise<void>;
334
369
  } | null>;
335
370
  export declare function isCache1hPersistentlyEnabled(storage: AccountStorage | null): boolean;
336
371
  export declare function getCache1hPersistentMode(storage: AccountStorage | null): Cache1hMode;
@@ -459,6 +494,13 @@ export declare function fetchOAuthQuotaSnapshot(input: {
459
494
  now?: () => number;
460
495
  }): Promise<OAuthQuotaSnapshot>;
461
496
  export declare function upsertAccount(storage: AccountStorage, account: FallbackAccount): void;
497
+ export declare function persistFallbackQuotaHeaderPersistent(input: {
498
+ accountId: string;
499
+ authLineageId?: string;
500
+ quota: OAuthQuotaSnapshot;
501
+ anthropicAccountUuid?: ProviderAccountUuid;
502
+ }, path?: string): Promise<boolean>;
503
+ export declare function fallbackAccountUuidForLineage(account: OAuthAccount | undefined, authLineageId?: string): string | null;
462
504
  export declare function removeAccount(storage: AccountStorage, id: string): boolean;
463
505
  export declare function reorderAccounts(storage: AccountStorage, orderedIds: string[]): void;
464
506
  export declare function setAccountEnabled(storage: AccountStorage, id: string, enabled: boolean): boolean;
@@ -467,6 +509,7 @@ export declare class FallbackAccountManager {
467
509
  private readonly fetchImpl;
468
510
  private readonly configPath;
469
511
  private readonly refreshPromises;
512
+ private readonly custodyVerificationAccounts;
470
513
  private refreshTimer;
471
514
  private quotaTimer;
472
515
  readonly quotaManager: import('./quota-manager.ts').QuotaManager | null;
@@ -487,6 +530,7 @@ export declare class FallbackAccountManager {
487
530
  save(storage: AccountStorage, accountIds?: string[]): Promise<void>;
488
531
  startBackgroundRefresh(): Promise<void>;
489
532
  stopBackgroundRefresh(): void;
533
+ withAccountRefreshLock<T>(accountId: string, fn: () => Promise<T>): Promise<T>;
490
534
  getUsableFallbackAccounts(existingStorage?: AccountStorage | null, options?: {
491
535
  modelId?: string;
492
536
  }): Promise<OAuthAccount[]>;
@@ -76,8 +76,15 @@ export type CacheKeepTarget = {
76
76
  consecutiveFailures: number;
77
77
  dayKey: string;
78
78
  oauthAccountId?: string;
79
+ oauthAccountIdentity?: string;
80
+ accountStoragePath?: string;
79
81
  isSubagent: boolean;
80
82
  };
83
+ export type CacheKeepPrewarmAttempt = {
84
+ id: number;
85
+ /** One deadline covers credential authorization and the HTTP attempt. */
86
+ signal?: AbortSignal;
87
+ };
81
88
  export type CacheKeepPrewarmResult = {
82
89
  ok: true;
83
90
  usage?: {
@@ -96,6 +103,7 @@ export declare class CacheKeepManager {
96
103
  private readonly targets;
97
104
  private timer;
98
105
  private tickPromise;
106
+ private nextPrewarmAttemptId;
99
107
  constructor(options: {
100
108
  loadStorage: () => Promise<AccountStorage | null>;
101
109
  fetchImpl?: typeof fetch;
@@ -103,7 +111,16 @@ export declare class CacheKeepManager {
103
111
  prewarmTimeoutMs?: number;
104
112
  setIntervalImpl?: typeof globalThis.setInterval;
105
113
  clearIntervalImpl?: typeof globalThis.clearInterval;
106
- prepareHeaders?: (headers: Headers, target: CacheKeepTarget) => Promise<Headers> | Headers;
114
+ prepareHeaders?: (headers: Headers, target: CacheKeepTarget, attempt: CacheKeepPrewarmAttempt) => Promise<Headers | undefined> | Headers | undefined;
115
+ /** Optionally reauthorize a replayable prewarm after a genuine 401.
116
+ * Return headers only for a verified newer version of the same account;
117
+ * onResponse observes only the final physical attempt. */
118
+ retryOnUnauthorized?: (input: {
119
+ target: CacheKeepTarget;
120
+ headers: Headers;
121
+ bodyText: string;
122
+ attempt: CacheKeepPrewarmAttempt;
123
+ }) => Promise<Headers | undefined> | Headers | undefined;
107
124
  onTrackedSessionsChanged?: (sessions: readonly CacheKeepTrackedSession[]) => Promise<void> | void;
108
125
  prepareBody?: (bodyText: string, target: CacheKeepTarget) => string | Promise<string>;
109
126
  onResponse?: (input: {
@@ -112,6 +129,11 @@ export declare class CacheKeepManager {
112
129
  status: number;
113
130
  data: unknown;
114
131
  receivedAt: number;
132
+ attempt: CacheKeepPrewarmAttempt;
133
+ }) => void | Promise<void>;
134
+ onComplete?: (input: {
135
+ target: CacheKeepTarget;
136
+ attempt: CacheKeepPrewarmAttempt;
115
137
  }) => void | Promise<void>;
116
138
  });
117
139
  start(): void;
@@ -137,6 +159,8 @@ export declare class CacheKeepManager {
137
159
  storage: AccountStorage | null;
138
160
  cacheMode: string;
139
161
  oauthAccountId?: string;
162
+ oauthAccountIdentity?: string;
163
+ accountStoragePath?: string;
140
164
  isSubagent?: boolean;
141
165
  }): {
142
166
  tracked: boolean;
@@ -151,6 +175,8 @@ export declare class CacheKeepManager {
151
175
  headers: Headers;
152
176
  bodyText: string;
153
177
  oauthAccountId?: string;
178
+ oauthAccountIdentity?: string;
179
+ accountStoragePath?: string;
154
180
  isSubagent?: boolean;
155
181
  }): Promise<CacheKeepPrewarmResult>;
156
182
  tick(): Promise<void>;
package/dist/cch.d.ts CHANGED
@@ -1,3 +1,9 @@
1
+ export interface BillingLineageFields {
2
+ previousRequestId?: string;
3
+ promptId?: string;
4
+ }
5
+ export declare function isValidAnthropicRequestId(value: string): boolean;
6
+ export declare function isValidBillingPromptId(value: string): boolean;
1
7
  type Message = {
2
8
  role?: string;
3
9
  content?: string | Array<{
@@ -38,5 +44,9 @@ export declare function computeCcVersionSuffix(firstUserText: string, version?:
38
44
  * Build the billing header with a cch placeholder.
39
45
  * signRequestBody() must run after final request serialization to replace it.
40
46
  */
41
- export declare function buildBillingHeaderValue(messages: Message[], version: string | undefined, entrypoint: string, pinnedFirstUserText?: string): string;
47
+ export declare function buildBillingHeaderValue(messages: Message[], version: string | undefined, entrypoint: string, pinnedFirstUserText?: string, lineage?: BillingLineageFields): string;
48
+ /** Remove request-scoped Claude Code lineage from a billing header string. */
49
+ export declare function stripBillingLineageFields(value: string): string;
50
+ /** Remove request-scoped Claude Code lineage before reusing a request body. */
51
+ export declare function stripBillingLineageFromBody(body: unknown): number;
42
52
  export {};
@@ -1,13 +1,35 @@
1
+ export type ProviderAccountUuid = string & {
2
+ readonly __providerAccountUuid: unique symbol;
3
+ };
1
4
  export type ClaudeCodeIdentity = {
2
5
  deviceId: string;
3
6
  accountIdentity?: string;
4
- accountUuid?: string;
7
+ accountUuid?: ProviderAccountUuid;
5
8
  sessionId: string;
6
9
  };
7
10
  export declare function setBounded<K, V>(map: Map<K, V>, key: K, value: V, limit?: number): void;
8
11
  export declare function getClaudeCodeIdentity(seed: string): ClaudeCodeIdentity;
9
12
  export declare function resetClaudeCodeIdentityCachesForTest(): void;
13
+ /** Use the identity already verified by the credential custodian, without an
14
+ * additional bootstrap request carrying a previously authorized token. */
15
+ export declare function getClaudeCodeIdentityForVerifiedAccount(accountIdentity: string, accountUuid: ProviderAccountUuid): ClaudeCodeIdentity;
10
16
  export declare function resolveClaudeCodeIdentity(accessToken: string, model: string | undefined, accountIdentity: string | undefined): Promise<ClaudeCodeIdentity>;
17
+ /**
18
+ * The access value is not a Claude OAuth access token, so Claude cannot
19
+ * identify its account. Asking again will not help; only a new sign-in
20
+ * replaces it. The message never includes the rejected value.
21
+ */
22
+ export declare class ClaudeUnsupportedAccessError extends Error {
23
+ readonly code = "unsupported-access";
24
+ constructor();
25
+ }
26
+ /**
27
+ * Account lookup for credentials that must belong to a Claude account.
28
+ * Unlike resolveClaudeCodeIdentity, which returns an identity without an
29
+ * account UUID for any other access value, this rejects such a value with
30
+ * ClaudeUnsupportedAccessError before any network request.
31
+ */
32
+ export declare function resolveClaudeCodeAccountIdentity(accessToken: string, model: string | undefined, accountIdentity: string | undefined): Promise<ClaudeCodeIdentity>;
11
33
  export declare function buildClaudeCodeMetadataUserId(identity: ClaudeCodeIdentity): string | null;
12
34
  export declare function applyClaudeCodeMetadata(body: Record<string, unknown>, identity: ClaudeCodeIdentity): boolean;
13
35
  export declare const CLAUDE_CODE_FULL_AGENT_BETAS: readonly ['oauth-2025-04-20', 'interleaved-thinking-2025-05-14', 'thinking-token-count-2026-05-13', 'context-management-2025-06-27', 'prompt-caching-scope-2026-01-05', 'claude-code-20250219', 'advisor-tool-2026-03-01', 'advanced-tool-use-2025-11-20', 'mid-conversation-system-2026-04-07', 'effort-2025-11-24', 'fallback-credit-2026-06-01', 'extended-cache-ttl-2025-04-11', 'cache-diagnosis-2026-04-07'];
@@ -0,0 +1,72 @@
1
+ import { type ClaustrumClientOptions as ClaustrumEnrollmentClientOptions, type EnrollmentPollOutcome, type EnrollmentTokenFile, writeEnrollmentTokenFile } from '@cortexkit/claustrum-client';
2
+ export declare const CLAUSTRUM_OPENCODE_ENROLLMENT_NAME = "anthropic-auth-opencode";
3
+ export declare const CLAUSTRUM_PI_ENROLLMENT_NAME = "anthropic-auth-pi";
4
+ export interface ClaustrumEnrollmentClient {
5
+ enrollPropose(input: {
6
+ name: string;
7
+ requestSecretHash: string;
8
+ }): Promise<{
9
+ requestId: string;
10
+ }>;
11
+ enrollPoll(input: {
12
+ requestId: string;
13
+ requestSecret: string;
14
+ }): Promise<EnrollmentPollOutcome>;
15
+ }
16
+ export interface ClaustrumEnrollmentConnection extends ClaustrumEnrollmentClient {
17
+ close(): void;
18
+ }
19
+ export declare function connectClaustrumEnrollmentClient(options?: ClaustrumEnrollmentClientOptions): Promise<ClaustrumEnrollmentConnection>;
20
+ export type ClaustrumEnrollmentStatus = {
21
+ state: 'idle';
22
+ } | {
23
+ state: 'pending';
24
+ proposedName: string;
25
+ requestId?: string;
26
+ retryCode?: string;
27
+ } | {
28
+ state: 'approved';
29
+ proposedName: string;
30
+ approvedName?: string;
31
+ tokenGeneration: number;
32
+ } | {
33
+ state: 'denied';
34
+ proposedName: string;
35
+ } | {
36
+ state: 'blocked';
37
+ proposedName: string;
38
+ code: string;
39
+ } | {
40
+ state: 'unavailable';
41
+ proposedName: string;
42
+ code: string;
43
+ } | {
44
+ state: 'busy';
45
+ };
46
+ export interface ClaustrumEnrollmentPaths {
47
+ statePath: string;
48
+ tokenPath: string;
49
+ }
50
+ export declare function getClaustrumEnrollmentPaths(tokenPath: string): ClaustrumEnrollmentPaths;
51
+ /** Resolve the independently enrolled host's owner-only token and state paths. */
52
+ export declare function getHostClaustrumEnrollmentPaths(host: 'opencode' | 'pi', env?: NodeJS.ProcessEnv, cwd?: string): ClaustrumEnrollmentPaths;
53
+ export declare function readClaustrumEnrollmentStatus(paths: ClaustrumEnrollmentPaths, proposedName?: string): Promise<ClaustrumEnrollmentStatus>;
54
+ /** Read fresh bearer material for a scoped operation; never publish this value. */
55
+ export declare function readClaustrumEnrollmentToken(tokenPath: string): Promise<EnrollmentTokenFile>;
56
+ export declare class ClaustrumEnrollmentManager {
57
+ #private;
58
+ constructor(options: {
59
+ client: ClaustrumEnrollmentClient;
60
+ paths: ClaustrumEnrollmentPaths;
61
+ proposedName: string;
62
+ now?: () => number;
63
+ mintSecret?: () => string;
64
+ writeTokenFile?: typeof writeEnrollmentTokenFile;
65
+ });
66
+ status(): Promise<ClaustrumEnrollmentStatus>;
67
+ resetTerminal(): Promise<ClaustrumEnrollmentResetResult>;
68
+ reconcile(): Promise<ClaustrumEnrollmentStatus>;
69
+ }
70
+ export type ClaustrumEnrollmentResetResult = 'reset' | 'idle' | 'refused-pending' | 'refused-approved' | 'busy';
71
+ /** Reset local terminal metadata without connecting to the credential daemon. */
72
+ export declare function resetClaustrumEnrollmentState(paths: ClaustrumEnrollmentPaths, proposedName: string): Promise<ClaustrumEnrollmentResetResult>;
@@ -0,0 +1,27 @@
1
+ import { type AccountStorage, type OAuthAccount } from './accounts.js';
2
+ import type { ClaustrumScopedAccount, ClaustrumScopedCustody } from './claustrum-scoped.js';
3
+ export declare class ClaustrumRosterBusyError extends Error {
4
+ readonly code = "claustrum_roster_busy";
5
+ constructor();
6
+ }
7
+ export interface ClaustrumScopedRoster {
8
+ /** The vault's conventional default record; absent when only labeled accounts exist. */
9
+ primary?: ClaustrumScopedAccount;
10
+ accounts: readonly OAuthAccount[];
11
+ storage: AccountStorage;
12
+ view: string;
13
+ }
14
+ /** Pure identity projection; callers must serialize discovery before persisting it. */
15
+ export declare function projectClaustrumScopedRoster(storage: AccountStorage, rows: readonly ClaustrumScopedAccount[], view: string, now?: number): ClaustrumScopedRoster;
16
+ /**
17
+ * The lease covers LIST and commit, not just the file write: opaque view hashes
18
+ * cannot tell a delayed old response from a newer one. A lost lease is checked
19
+ * while holding the config lock, before any authoritative membership write.
20
+ * Neither local mode nor a failed list can publish an empty inventory.
21
+ */
22
+ export declare function refreshClaustrumScopedRoster(options: {
23
+ path: string;
24
+ custody: Pick<ClaustrumScopedCustody, 'discover'>;
25
+ signal?: AbortSignal;
26
+ now?: () => number;
27
+ }): Promise<ClaustrumScopedRoster | undefined>;
@@ -0,0 +1,31 @@
1
+ import { type ClaustrumClientOptions } from '@cortexkit/claustrum-client';
2
+ import { type ClaustrumScopedAttempt, type ClaustrumScopedClient } from './claustrum-scoped.js';
3
+ import { type ClaustrumScopedRoster } from './claustrum-scoped-roster.js';
4
+ export { ClaustrumCredentialError as ClaustrumScopedCredentialError } from '@cortexkit/claustrum-client';
5
+ export declare function connectClaustrumScopedClient(options?: ClaustrumClientOptions): Promise<ClaustrumScopedClient>;
6
+ /** Host-owned lifecycle for metadata discovery. Bearer material is never cached. */
7
+ export interface ClaustrumScopedRuntimeOptions {
8
+ storagePath: string;
9
+ tokenPath: string;
10
+ connect: () => Promise<ClaustrumScopedClient>;
11
+ /** Fired once per discovery change (including the initial snapshot),
12
+ * keyed by the inventory view digest. Repeat polls with an identical
13
+ * view do not notify. */
14
+ onRoster?: (roster: ClaustrumScopedRoster) => void;
15
+ onError?: () => void;
16
+ setTimeoutImpl?: typeof setTimeout;
17
+ clearTimeoutImpl?: typeof clearTimeout;
18
+ pollIntervalMs?: number;
19
+ }
20
+ export declare class ClaustrumScopedRuntime {
21
+ #private;
22
+ constructor(options: ClaustrumScopedRuntimeOptions);
23
+ snapshot(): ClaustrumScopedRoster | undefined;
24
+ refresh(): Promise<ClaustrumScopedRoster | undefined>;
25
+ start(): void;
26
+ authorize(routeId: string, signal?: AbortSignal): Promise<ClaustrumScopedAttempt>;
27
+ reportFailure(attempt: ClaustrumScopedAttempt, status: number, source: 'direct' | 'relay_status_field' | 'relay_message_parse'): Promise<void>;
28
+ fetchQuota(routeId: string, fetchImpl?: typeof fetch): Promise<import("./accounts.js").OAuthQuotaSnapshot>;
29
+ fetchProfile(routeId: string, fetchImpl?: typeof fetch, signal?: AbortSignal): Promise<import("./accounts.js").OAuthAccountProfile>;
30
+ close(): void;
31
+ }
@@ -0,0 +1,53 @@
1
+ import { type ClaustrumClient, type ClaustrumReporterSource, type EnrollmentTokenFile } from '@cortexkit/claustrum-client';
2
+ export type ClaustrumScopedClient = Pick<ClaustrumClient, 'listScoped' | 'getScoped' | 'reportAuthFailureScoped' | 'close'>;
3
+ export interface ClaustrumScopedIdentity {
4
+ readonly credentialId: string;
5
+ readonly accountId: string;
6
+ }
7
+ export interface ClaustrumScopedAccount extends ClaustrumScopedIdentity {
8
+ readonly state: string;
9
+ readonly email?: string;
10
+ readonly orgName?: string;
11
+ }
12
+ export interface ClaustrumScopedAttempt extends ClaustrumScopedIdentity {
13
+ /** Non-enumerable, memory-only bearer. Authorize again for every dispatch/retry. */
14
+ readonly accessToken: string;
15
+ readonly recordVersion: number;
16
+ readonly expiresAtMs: number;
17
+ }
18
+ /** Only a new version of the same account may replace an in-flight 401. */
19
+ export declare function isScopedCredentialRotation(served: ClaustrumScopedAttempt, current: ClaustrumScopedAttempt | undefined): current is ClaustrumScopedAttempt;
20
+ /** Send classes that retry once after a scoped 401, for diagnostics. */
21
+ export type ScopedRetrySite = 'model' | 'model-relay' | 'cachekeep' | 'prime' | 'quota-profile' | 'pi-model' | 'pi-model-relay' | 'pi-cachekeep';
22
+ /** Why a scoped 401 did or did not retry. Never carries credential material. */
23
+ export type ScopedRetryReason = 'rotated' | 'reauthorize-failed' | 'credential-changed' | 'account-changed' | 'version-unchanged';
24
+ /**
25
+ * Decide whether a request that got a 401 should retry with the freshly
26
+ * re-authorized receipt, and record the decision. The vault can refresh a
27
+ * credential between dispatch and the 401; this line is the consumer-side
28
+ * half of that timeline, pairing with the vault's refresh commit instant when
29
+ * a stale report has to be explained. Never logs credential material.
30
+ */
31
+ export declare function decideScopedRetryAfter401(site: ScopedRetrySite, served: ClaustrumScopedAttempt, current: ClaustrumScopedAttempt | undefined): current is ClaustrumScopedAttempt;
32
+ /**
33
+ * Shared OpenCode/Pi scoped read plane. There is intentionally no credential cache,
34
+ * handle fallback, or get single-flight: each outgoing attempt must be authorized
35
+ * by the daemon, including attempts made after a successful earlier request.
36
+ * Enrollment tokens are re-read per operation so operator reissue works on disk.
37
+ */
38
+ export declare class ClaustrumScopedCustody {
39
+ #private;
40
+ constructor(options: {
41
+ client: ClaustrumScopedClient;
42
+ tokenPath?: string;
43
+ readToken?: () => Promise<EnrollmentTokenFile>;
44
+ now?: () => number;
45
+ });
46
+ discover(signal?: AbortSignal): Promise<{
47
+ view: string;
48
+ accounts: readonly ClaustrumScopedAccount[];
49
+ }>;
50
+ authorize(identity: ClaustrumScopedIdentity, signal?: AbortSignal): Promise<ClaustrumScopedAttempt>;
51
+ reportFailure(attempt: ClaustrumScopedAttempt, status: number, reporterSource: ClaustrumReporterSource): Promise<void>;
52
+ close(): void;
53
+ }
@@ -1,4 +1,3 @@
1
- import { type BindIdentity, type CatalogEntry, type CloseRouteOptions, type ManagedCallOptions, type ManagedCloseRouteOptions, type RequestOptions, type RouteHandle, type RouteOpenOptions, type RouteTarget, SubcClient, type SubscribeOptions, type Subscription } from '@cortexkit/subc-client';
2
1
  export type ClaustrumEndpoint = {
3
2
  host: string;
4
3
  port: number;
@@ -16,10 +15,19 @@ export type ClaustrumDetection = {
16
15
  path: string;
17
16
  reason: string;
18
17
  };
19
- export declare function getDefaultClaustrumConnectionPath(): string;
20
- export declare function detectClaustrumConnection(path?: string): Promise<ClaustrumDetection>;
18
+ export declare const PRODUCTION_CLAUSTRUM_CONNECTION_FILE_NAME = "subc-connection.json";
19
+ export declare function findExistingClaustrumConnectionPath(env?: NodeJS.ProcessEnv): string | undefined;
20
+ export declare function getDefaultClaustrumConnectionPath(env?: NodeJS.ProcessEnv): string;
21
+ export declare function resolveClaustrumConnectionPath(explicit?: string, env?: NodeJS.ProcessEnv): string;
22
+ export declare function detectClaustrumConnection(explicitPath?: string): Promise<ClaustrumDetection>;
21
23
  export declare const CUSTODY_TOMBSTONE_PREFIX = "claustrum-tombstone:v1:";
22
24
  export declare function custodyTombstoneKey(provider: string): string;
25
+ export declare function custodyTombstoneOAuth(provider: string): {
26
+ type: 'oauth';
27
+ access: '';
28
+ refresh: string;
29
+ expires: 0;
30
+ };
23
31
  export declare function isCustodyTombstoneValue(value: unknown): value is string;
24
32
  export declare function isCustodyTombstoneOAuth(auth: unknown, provider: string): boolean;
25
33
  export declare class CustodyTombstoneRefreshError extends Error {
@@ -27,83 +35,9 @@ export declare class CustodyTombstoneRefreshError extends Error {
27
35
  readonly code = "custody_tombstone_refresh";
28
36
  constructor(provider: string);
29
37
  }
30
- export declare function assertNotCustodyTombstone(refreshToken: unknown, provider: string): void;
31
- export type CustodyHandleAccount = {
32
- label: string;
33
- handle: string;
34
- credentialId: string;
35
- };
36
- export type CustodyHandleManifest = {
37
- provider: string;
38
- serve: string;
39
- shape: string;
40
- accounts: CustodyHandleAccount[];
41
- };
42
- export declare function isValidCustodyHandle(value: unknown): value is string;
43
- export declare function readCustodyHandles(json: unknown, provider: string): CustodyHandleManifest;
44
- export type ClaustrumClientOptions = {
45
- connectionFile?: string;
46
- handshakeTimeoutMs?: number;
47
- connector?: ClaustrumConnector;
48
- };
49
- export type ClaustrumConnector = (options: {
50
- connectionFile: string;
51
- handshakeTimeoutMs?: number;
52
- }) => Promise<SubcClient>;
53
- export declare class ClaustrumClient {
54
- #private;
55
- private constructor();
56
- static connect(options?: ClaustrumClientOptions): Promise<ClaustrumClient>;
57
- catalogList(moduleId?: string): Promise<CatalogEntry[]>;
58
- routeOpen(target: RouteTarget, identity: BindIdentity, options?: Omit<RouteOpenOptions, 'consumerIdentity'>): Promise<RouteHandle>;
59
- request(handle: RouteHandle, body: unknown, options?: RequestOptions): Promise<unknown>;
60
- call<Response = unknown>(moduleId: string, method: string, params?: unknown, options?: Omit<ManagedCallOptions, 'consumerIdentity'>): Promise<Response>;
61
- subscribe(handle: RouteHandle, body: unknown, onEvent: (event: Uint8Array) => void, options?: SubscribeOptions): Subscription;
62
- closeRoute(handle: RouteHandle, options?: CloseRouteOptions): Promise<void>;
63
- closeManagedRoute(target: Extract<RouteTarget, {
64
- kind: 'management_surface' | 'tool_provider';
65
- }>, identity: BindIdentity, options?: Omit<ManagedCloseRouteOptions, 'consumerIdentity'>): Promise<void>;
66
- close(): void;
67
- }
68
- export declare function connectClaustrumClient(options?: ClaustrumClientOptions): Promise<ClaustrumClient>;
69
- export declare const CLAUSTRUM_MODULE_ID = "claustrum";
70
- export declare const DEFAULT_CLAUSTRUM_CREDENTIAL_MIN_TTL_MS = 120000;
71
- export declare const ERROR_CLASS_WIRE_SET: readonly ['transient', 'permanent', 'auth_required', 'context_overflow'];
72
- export type ClaustrumCredentialErrorClass = (typeof ERROR_CLASS_WIRE_SET)[number];
73
- export type ClaustrumCredentialErrorAction = 'gone' | 'reauth' | 'retry' | 'reduce_and_retry';
74
- export type ClaustrumCredential = {
75
- payload: string;
76
- expiresAtMs: number | null;
77
- recordVersion: number;
78
- projectId?: string;
79
- accountId?: string;
80
- };
81
- export type ClaustrumServedCredential = Pick<ClaustrumCredential, 'recordVersion'>;
82
- export type ClaustrumReporterSource = 'direct' | 'relay_status_field' | 'relay_message_parse';
83
- export declare class ClaustrumCredentialError extends Error {
84
- readonly code: string;
85
- readonly action: ClaustrumCredentialErrorAction;
86
- readonly errorClass: ClaustrumCredentialErrorClass;
87
- constructor(message: string, code: string, errorClass: ClaustrumCredentialErrorClass, action: ClaustrumCredentialErrorAction);
88
- }
89
- export type ClaustrumCredentialCacheOptions = {
90
- identity?: BindIdentity;
91
- now?: () => number;
92
- minTtlMs?: number;
93
- };
94
- export declare class ClaustrumCredentialCache {
95
- #private;
96
- constructor(client: ClaustrumClient, options?: ClaustrumCredentialCacheOptions);
97
- get(handle: string, minTtlMs?: number): Promise<ClaustrumCredential>;
98
- peek(handle: string): ClaustrumCredential | undefined;
99
- seedForTest(handle: string, credential: ClaustrumCredential): void;
100
- reduceMinTtlMs(): number;
101
- reportAuthFailure(handle: string, providerStatus: number, servedCredential: ClaustrumServedCredential, reporterSource?: ClaustrumReporterSource): Promise<void>;
102
- reportAuthFailure(handle: string, servedCredential: ClaustrumServedCredential, providerStatus?: number, reporterSource?: ClaustrumReporterSource): Promise<void>;
103
- invalidate(handle: string, recordVersion?: number): void;
104
- close(): void;
38
+ export declare class CustodyTombstoneLoginError extends Error {
39
+ readonly provider: string;
40
+ readonly code = "custody_tombstone_login";
41
+ constructor(provider: string);
105
42
  }
106
- export type ConnectClaustrumCredentialCacheOptions = ClaustrumClientOptions & ClaustrumCredentialCacheOptions & {
107
- enabled?: boolean;
108
- };
109
- export declare function connectClaustrumCredentialCache(options?: ConnectClaustrumCredentialCacheOptions): Promise<ClaustrumCredentialCache | null>;
43
+ export declare function assertNotCustodyTombstone(refreshToken: unknown, provider: string): void;