@cortexkit/opencode-anthropic-auth 1.23.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 (82) hide show
  1. package/README.md +239 -195
  2. package/dist/cli-failure.d.ts +69 -0
  3. package/dist/cli.d.ts +14 -9
  4. package/dist/cli.js +98 -76
  5. package/dist/custody-dimensions.d.ts +7 -24
  6. package/dist/custody-mode.d.ts +29 -169
  7. package/dist/effort-history.d.ts +6 -1
  8. package/dist/index-1jkyhgyr.js +2 -0
  9. package/dist/{index-8y2t4mwz.js → index-2arfb1y3.js} +1 -1
  10. package/dist/{index-0jfsxyn9.js → index-4ya27n12.js} +1 -1
  11. package/dist/index-aaajxwzd.js +2 -0
  12. package/dist/index-ae3fq4n6.js +42 -0
  13. package/dist/{index-xzbhzz0a.js → index-fds0s2j4.js} +2 -2
  14. package/dist/index-nngmvczq.js +450 -0
  15. package/dist/index-pn597b6f.js +2 -0
  16. package/dist/{index-1gr8v4fn.js → index-rqync0pc.js} +1 -1
  17. package/dist/index.js +1 -38
  18. package/dist/native-command.d.ts +19 -0
  19. package/dist/rpc/notifications.d.ts +2 -1
  20. package/dist/rpc/port-file.js +1 -1
  21. package/dist/rpc/protocol.d.ts +8 -4
  22. package/dist/rpc/protocol.js +1 -1
  23. package/dist/rpc/rpc-client.d.ts +2 -0
  24. package/dist/rpc/rpc-client.js +1 -1
  25. package/dist/rpc/rpc-dir.js +1 -1
  26. package/dist/rpc/rpc-server.d.ts +5 -1
  27. package/dist/setup/command.d.ts +12 -0
  28. package/dist/setup/command.test.d.ts +1 -0
  29. package/dist/setup/native-activation.d.ts +29 -0
  30. package/dist/setup/native-enrollment.d.ts +26 -0
  31. package/dist/setup/native-enrollment.test.d.ts +1 -0
  32. package/dist/setup/native-local.d.ts +20 -0
  33. package/dist/setup/native-login.d.ts +3 -0
  34. package/dist/setup/native-paths.d.ts +15 -0
  35. package/dist/setup/native-paths.test.d.ts +1 -0
  36. package/dist/setup/pi.d.ts +13 -3
  37. package/dist/setup/process-fence.d.ts +7 -1
  38. package/dist/setup/process-fence.test.d.ts +1 -0
  39. package/dist/sidebar-state.js +1 -1
  40. package/dist/tui/command-dialogs.d.ts +5 -0
  41. package/dist/tui-preferences.js +2 -2
  42. package/dist/v2/activation.d.ts +7 -0
  43. package/dist/v2/adapter.d.ts +276 -0
  44. package/dist/v2/install.d.ts +13 -0
  45. package/dist/v2/lifecycle.d.ts +8 -0
  46. package/dist/v2/menu-contract.d.ts +8 -0
  47. package/dist/v2/menu.d.ts +10 -0
  48. package/dist/v2/models.d.ts +6 -0
  49. package/dist/v2/ownership.d.ts +11 -0
  50. package/dist/v2/prime.d.ts +12 -0
  51. package/dist/v2/rpc.d.ts +50 -0
  52. package/dist/v2/server.d.ts +8 -0
  53. package/dist/v2/server.js +4 -0
  54. package/dist/v2/setup.d.ts +58 -0
  55. package/dist/v2/source.d.ts +41 -0
  56. package/dist/v2/tui.d.ts +13 -0
  57. package/dist/v2/tui.js +2 -0
  58. package/dist/v2/wire.d.ts +36 -0
  59. package/package.json +20 -5
  60. package/src/rpc/notifications.ts +9 -2
  61. package/src/rpc/protocol.ts +8 -7
  62. package/src/rpc/rpc-client.ts +17 -0
  63. package/src/rpc/rpc-server.ts +20 -3
  64. package/src/tui/command-dialogs.tsx +264 -0
  65. package/src/tui/entry.mjs +44 -18
  66. package/src/tui-compiled/rpc/protocol.ts +8 -7
  67. package/src/tui-compiled/rpc/rpc-client.ts +17 -0
  68. package/src/tui-compiled/tui/command-dialogs.tsx +315 -76
  69. package/src/tui-compiled/tui.tsx +24 -7
  70. package/src/tui.tsx +37 -9
  71. package/dist/claustrum-enrollment-registry.d.ts +0 -4
  72. package/dist/custody-enrollment.d.ts +0 -14
  73. package/dist/custody-live.d.ts +0 -111
  74. package/dist/custody-manifest-watcher.d.ts +0 -16
  75. package/dist/index-1fq7h6yd.js +0 -430
  76. package/dist/index-797pmamn.js +0 -2
  77. package/dist/index-a5d6v3ba.js +0 -5
  78. package/dist/index-n96q8pks.js +0 -2
  79. package/dist/index-xxhyhp98.js +0 -2
  80. package/dist/index-z7gfdyv3.js +0 -1
  81. package/dist/local-login.d.ts +0 -64
  82. package/dist/logger-kk9vyem9.js +0 -1
@@ -1,36 +1,19 @@
1
- import { type AccountStorage, type ClaustrumCredential, type CustodyHandleManifest, type CustodyHandleResolution, type CustodyStatusState, type OAuthAccount } from '@cortexkit/anthropic-auth-core';
2
- type CustodyDimensionsDeps = {
3
- getCache: () => {
4
- peek: (handle: string) => ClaustrumCredential | undefined;
5
- } | null | undefined;
6
- now: () => number;
7
- resolveAccountCustodyHandle: (account: OAuthAccount, storage: AccountStorage) => CustodyHandleResolution;
8
- usableAccessToken: (credential: ClaustrumCredential | undefined, now: number) => string | undefined;
9
- hasIdentityMismatch: (account: OAuthAccount, credential: ClaustrumCredential | undefined) => boolean;
10
- isBlocked: (accountId: string) => boolean;
11
- isReauth: (accountId: string) => boolean;
12
- getManifest: () => CustodyHandleManifest | undefined;
13
- };
14
- export declare function fallbackCustodyDimensions(storage: AccountStorage | null, deps: Pick<CustodyDimensionsDeps, 'getCache' | 'now' | 'resolveAccountCustodyHandle' | 'usableAccessToken'> & {
15
- construction?: boolean;
16
- }): {
17
- fallbacks: "R" | "T";
18
- evidence: "V" | "unknown";
19
- } | {
1
+ import { type AccountStorage, type CustodyStatusState } from '@cortexkit/anthropic-auth-core';
2
+ /** Only the enrolled scoped roster can establish vault ownership. */
3
+ export declare function isFallbackAccountVaultServed(accountId: string, storage: AccountStorage | null): boolean;
4
+ export declare function fallbackCustodyDimensions(storage: AccountStorage | null): {
20
5
  fallbacks: 'M';
21
- evidence: "N" | "unknown";
6
+ evidence: 'N';
22
7
  } | {
23
8
  fallbacks: "R" | "T";
24
- evidence: "N" | "V";
9
+ evidence: 'V';
25
10
  };
26
11
  export declare function mainCustodyDimension(auth: {
27
12
  type: string;
28
13
  access?: string;
29
14
  refresh?: string;
30
15
  }): "R" | "T" | "X";
31
- export declare function isFallbackAccountVaultServed(accountId: string, storage: AccountStorage | null, deps: Pick<CustodyDimensionsDeps, 'getCache' | 'now' | 'resolveAccountCustodyHandle' | 'usableAccessToken' | 'hasIdentityMismatch' | 'isBlocked'>): boolean;
32
16
  export declare function custodyStateFor(account: {
33
17
  id: string;
34
18
  role: 'main' | 'fallback';
35
- }, storage: AccountStorage | null, deps: CustodyDimensionsDeps, vaultServed?: boolean): CustodyStatusState;
36
- export {};
19
+ }, storage: AccountStorage | null): CustodyStatusState;
@@ -1,186 +1,46 @@
1
- type ModeDimension = 'L' | 'C';
2
- type MainDimension = 'R' | 'T' | 'X';
3
- type FallbackDimension = 'R' | 'T' | 'M';
4
- type EvidenceDimension = 'V' | 'N' | 'unknown';
5
- type Lock = {
6
- release: () => Promise<void>;
7
- };
8
- export declare const OPENCODE_MAIN_OAUTH_REFRESH_LOCK = "opencode-main-oauth-refresh";
9
- export declare const CUSTODY_PREFLIGHT_MIN_TTL_MS: number;
10
- export type CustodyCacheCredential = {
11
- credentialId?: string;
12
- recordVersion: number;
13
- access: string;
14
- refresh: string;
15
- expiresAt: number | null;
16
- state: 'usable' | 'revoked' | 'reauth' | 'timeout';
17
- };
18
- export type ClaustrumTakeoverPlan = {
19
- accounts: Array<{
20
- id: string;
21
- label: string;
22
- handle: string;
23
- credentialId: string;
24
- recordVersion: number;
25
- bindingPersisted: boolean;
26
- localAuthFingerprint: string;
27
- cacheCredential: CustodyCacheCredential;
28
- }>;
29
- toJSON: () => unknown;
30
- toString: () => string;
31
- };
32
- export type CustodyPreflightRefusalReason = 'TAKEOVER_INCOMPLETE_MAIN_REAL' | 'TAKEOVER_INCOMPLETE_MAIN_BINDING' | 'binding_missing' | 'credential_revoked' | 'credential_reauth' | 'credential_timeout' | 'credential_unusable' | 'credential_identity_mismatch' | 'divergence_fenced' | 'TAKEOVER_INCOMPLETE_MAIN_SLOT' | 'local_credential_unavailable';
33
- export type CustodyPreflightRefusal = {
34
- label: string;
35
- reason: CustodyPreflightRefusalReason;
36
- guidance?: string;
37
- };
38
- export type MainCustodyRefusal = 'cold' | 'reauth' | 'takeover-incomplete' | 'identity-mismatch';
39
- export declare class CustodyPreflightRefusedError extends Error {
40
- readonly accountId: string;
41
- readonly reason: CustodyPreflightRefusalReason;
42
- readonly refusals: CustodyPreflightRefusal[];
43
- readonly code = "custody_preflight_refused";
44
- constructor(accountId: string, reason: CustodyPreflightRefusalReason, refusals?: CustodyPreflightRefusal[]);
45
- toJSON(): {
46
- ok: boolean;
47
- code: string;
48
- accountId: string;
49
- reason: CustodyPreflightRefusalReason;
50
- refusals: CustodyPreflightRefusal[];
51
- };
52
- }
53
1
  export declare class CustodyStateMismatchError extends Error {
54
2
  readonly verdict: string;
55
3
  readonly dimensions: {
56
- mode: ModeDimension;
57
- main: MainDimension;
58
- fallbacks: FallbackDimension;
59
- evidence: EvidenceDimension;
4
+ mode: 'L' | 'C';
5
+ main: 'R' | 'T' | 'X';
6
+ fallbacks: 'R' | 'T' | 'M';
7
+ evidence: 'V' | 'N';
60
8
  };
61
9
  readonly code = "custody_state_mismatch";
62
10
  constructor(verdict: string, dimensions: {
63
- mode: ModeDimension;
64
- main: MainDimension;
65
- fallbacks: FallbackDimension;
66
- evidence: EvidenceDimension;
11
+ mode: 'L' | 'C';
12
+ main: 'R' | 'T' | 'X';
13
+ fallbacks: 'R' | 'T' | 'M';
14
+ evidence: 'V' | 'N';
67
15
  });
68
16
  toJSON(): {
69
17
  code: string;
70
18
  verdict: string;
71
19
  dimensions: {
72
- mode: ModeDimension;
73
- main: MainDimension;
74
- fallbacks: FallbackDimension;
75
- evidence: EvidenceDimension;
20
+ mode: 'L' | 'C';
21
+ main: 'R' | 'T' | 'X';
22
+ fallbacks: 'R' | 'T' | 'M';
23
+ evidence: 'V' | 'N';
76
24
  };
77
25
  };
78
26
  }
79
- export declare class CustodyLockBusyError extends Error {
80
- readonly lockName: string;
81
- readonly code = "lock_busy";
82
- constructor(lockName: string);
83
- }
84
- type PreflightRoute = {
85
- id: string;
86
- label?: string;
87
- enabled?: boolean;
88
- type: string;
89
- local?: unknown;
90
- };
91
- type PreflightBinding = {
92
- accountId: string;
93
- label: string;
94
- handle: string;
95
- credentialId: string;
96
- source?: 'manifest' | 'legacy';
97
- };
98
- export type PreflightClaustrumTakeoverInput = {
99
- now: number;
100
- storage: {
101
- refresh?: {
102
- refreshBeforeExpiryMinutes?: number;
103
- };
104
- claustrumDivergence?: Record<string, {
105
- minimumRecordVersion: number;
106
- observedAt?: number;
107
- }>;
108
- } | null;
109
- main: Pick<PreflightRoute, 'id' | 'label' | 'enabled'>;
110
- fallbacks: PreflightRoute[];
111
- hostAuth: {
112
- get: () => unknown | Promise<unknown>;
113
- };
114
- bindings: PreflightBinding[];
115
- cache: {
116
- get: (handle: string, options: {
117
- minTtlMs: number;
118
- }) => Promise<CustodyCacheCredential | {
119
- state: string;
120
- expiresAt?: number;
121
- }>;
122
- };
123
- debug?: (message: string) => void;
124
- };
125
- export declare function preflightClaustrumTakeover(input: PreflightClaustrumTakeoverInput): Promise<ClaustrumTakeoverPlan>;
27
+ /**
28
+ * Check custody independently from account availability. Modes L/C mean local
29
+ * and Claustrum vault. Main R/T/X means a real login, inert tombstone, or no
30
+ * recognized OAuth marker; fallback R/T/M means local rows, token-free vault
31
+ * inventory, or missing roster. Evidence V/N means verified or unavailable.
32
+ * Local mode still requires completed migration and local account rows. Vault
33
+ * mode requires enrollment authority, the host marker and a readable roster,
34
+ * not an active primary. Each request separately authorizes its chosen account;
35
+ * the marker enables the provider but cannot authenticate it. Ordinary OpenCode
36
+ * API-key authentication remains outside this OAuth custody check.
37
+ */
126
38
  export declare function reconcileCustodyStartup(input: {
127
- mode: ModeDimension;
128
- main: MainDimension;
129
- fallbacks: FallbackDimension;
130
- evidence: EvidenceDimension;
131
- } | {
132
- mode: ModeDimension;
133
- mainSlot: 'unknown';
134
- fallbacks: FallbackDimension;
135
- evidence: EvidenceDimension;
39
+ mode: 'L' | 'C';
40
+ main: 'R' | 'T' | 'X';
41
+ fallbacks: 'R' | 'T' | 'M';
42
+ evidence: 'V' | 'N';
43
+ authority?: 'committed' | 'retired';
136
44
  }): {
137
- verdict: string;
138
- provisional?: boolean;
139
- };
140
- export declare function acquireCustodyTransitionLocks(input: {
141
- storagePath: string;
142
- manifestPath: string;
143
- fallbackAccountIds: string[];
144
- acquireTransition: (input: {
145
- name: 'claustrum-mode-transition';
146
- path: string;
147
- }) => Promise<Lock | null>;
148
- acquireManifest: (input: {
149
- path: string;
150
- }) => Promise<Lock | null>;
151
- acquireRefresh: (input: {
152
- name: string;
153
- path: string;
154
- }) => Promise<Lock | null>;
155
- }): Promise<{
156
- release: () => Promise<void>;
157
- }>;
158
- export declare class CustodyTransitionError extends Error {
159
- readonly stage: 'reverify_fingerprint' | 'write_manifest' | 'write_sidecar' | 'readback' | 'mode_commit' | 'post_commit_readback';
160
- readonly accountId?: string | undefined;
161
- readonly guidance?: string | undefined;
162
- readonly code = "custody_transition_failed";
163
- constructor(stage: 'reverify_fingerprint' | 'write_manifest' | 'write_sidecar' | 'readback' | 'mode_commit' | 'post_commit_readback', accountId?: string | undefined, guidance?: string | undefined);
164
- toJSON(): {
165
- code: string;
166
- stage: "mode_commit" | "post_commit_readback" | "readback" | "reverify_fingerprint" | "write_manifest" | "write_sidecar";
167
- accountId: string | undefined;
168
- guidance: string | undefined;
169
- };
170
- }
171
- export type ExecuteClaustrumTakeoverDeps = {
172
- locks: Parameters<typeof acquireCustodyTransitionLocks>[0];
173
- getLocalAuth: (accountId: string) => Promise<unknown>;
174
- isCommitted: (plan: ClaustrumTakeoverPlan) => Promise<boolean>;
175
- writeManifestBindings: (plan: ClaustrumTakeoverPlan) => Promise<void>;
176
- writeSidecarAccount: (account: ClaustrumTakeoverPlan['accounts'][number]) => Promise<void>;
177
- verifyTarget: (plan: ClaustrumTakeoverPlan) => Promise<boolean>;
178
- verifyCommitted: (plan: ClaustrumTakeoverPlan) => Promise<boolean>;
179
- setMode: (mode: 'claustrum' | 'local') => Promise<'changed' | 'unchanged'>;
45
+ verdict: 'LOCAL_SERVE' | 'CLAUSTRUM_SERVE';
180
46
  };
181
- export declare function executeClaustrumTakeover(plan: ClaustrumTakeoverPlan, deps: ExecuteClaustrumTakeoverDeps): Promise<'changed' | 'unchanged'>;
182
- export declare function executeLocalExit(deps: {
183
- path?: string;
184
- setMode?: (mode: 'local') => Promise<'changed' | 'unchanged'>;
185
- }): Promise<"changed" | "unchanged">;
186
- export {};
@@ -13,7 +13,9 @@ export type OpenCodeEffortMarkerPlan = {
13
13
  messageId: string;
14
14
  };
15
15
  export declare class EffortMarkerCorrelationError extends Error {
16
- constructor(message: string);
16
+ readonly check: string;
17
+ readonly details: Record<string, unknown>;
18
+ constructor(message: string, check?: string, details?: Record<string, unknown>);
17
19
  }
18
20
  type OpenCodeMessageInfo = {
19
21
  id?: unknown;
@@ -49,6 +51,8 @@ export declare function applyOpenCodeEffortMarkers(body: Record<string, unknown>
49
51
  };
50
52
  export declare class OpenCodeEffortPlanTracker {
51
53
  private readonly plans;
54
+ private readonly history;
55
+ private readonly historyByMessage;
52
56
  record(plan: OpenCodeEffortMarkerPlan): void;
53
57
  clear(sessionId: string, messageId: string): void;
54
58
  markHeaders(input: {
@@ -57,6 +61,7 @@ export declare class OpenCodeEffortPlanTracker {
57
61
  headers: Record<string, string>;
58
62
  }): boolean;
59
63
  resolveHeader(value: string | undefined): OpenCodeEffortMarkerPlan | undefined;
64
+ private remember;
60
65
  private key;
61
66
  }
62
67
  export {};
@@ -0,0 +1,2 @@
1
+ var z=(f)=>f!==null&&typeof f==="object"&&!Array.isArray(f),G=(f)=>z(f)&&typeof f.sessionId==="string"&&f.sessionId.length>0,Z=(f)=>{if(!G(f)||!z(f)||f.command!=="claude"||typeof f.sectionId!=="string"||typeof f.actionId!=="string")return!1;if(f.itemId!==void 0&&typeof f.itemId!=="string")return!1;if(f.confirmed!==void 0&&typeof f.confirmed!=="boolean")return!1;if(f.values!==void 0&&(!z(f.values)||!Object.values(f.values).every((q)=>q===null||typeof q==="string"||typeof q==="boolean"||typeof q==="number"&&Number.isFinite(q))))return!1;return!0};function B(f){return{"~standard":{version:1,vendor:"cortexkit-native",validate:(q)=>f(q)?{value:q}:{issues:[{message:"Invalid native menu payload"}]}}}}var W=(f)=>z(f)&&f.command==="claude"&&z(f.menu)&&f.menu.command==="claude"&&typeof f.menu.title==="string"&&Array.isArray(f.menu.sections),$=(f)=>z(f)&&f.command==="claude"&&typeof f.ok==="boolean"&&typeof f.text==="string"&&z(f.menu)&&Array.isArray(f.menu.sections),A={id:"cortexkit-anthropic-native",methods:{open:{input:B(G),output:B(W)},apply:{input:B(Z),output:B($)}},events:{opened:{schema:B((f)=>G(f)&&W(f.payload))},notification:{schema:B((f)=>G(f)&&typeof f.message==="string"&&["info","warning","error"].includes(String(f.kind)))}}};async function L(f,q,X){let K=new AbortController,H=(j)=>({sessionId:j,notify(F,J="info"){D.events.emit("notification",{sessionId:j,message:F,kind:J}).catch(()=>{})}}),D=await f.rpc.register(A,{open:(j)=>q.open(H(j.sessionId)),apply:(j)=>q.apply(j,H(j.sessionId))}),Q;try{Q=await f.command.transform((j)=>j.add({name:"claude",description:"Native Claude accounts and settings",async execute(F){let J=await q.open(H(F.sessionID));await D.events.emit("opened",{sessionId:F.sessionID,payload:J})}}))}catch(j){throw await D.dispose(),j}let Y=(async()=>{try{for await(let j of f.event.subscribe({signal:K.signal}))if(j.type==="session.deleted")X.forgetSession(j.data.sessionID)}catch{}})(),S=!1;return{async dispose(){if(S)return;S=!0,K.abort(),await Promise.all([D.dispose(),Q.dispose(),Y])}}}
2
+ export{A as s,L as t};
@@ -1,2 +1,2 @@
1
1
  var t=["claude-account","claude-cache","claude-cachekeep","claude-prime","claude-start","claude-quota","claude-dump","claude-fast","claude-routing","claude-killswitch","claude-logging"];
2
- export{t as qh};
2
+ export{t as p};
@@ -1,2 +1,2 @@
1
1
  import{mkdir as l,readdir as u,readFile as c,rename as p,unlink as m,writeFile as d}from"node:fs/promises";import{join as a}from"node:path";function f(t){try{return process.kill(t,0),!0}catch(r){return r.code==="EPERM"}}async function b(t,r){await l(t,{recursive:!0});let s={...r,startedAt:Date.now()},e=a(t,`port-${r.pid}.json`),i=`${e}.${process.pid}.tmp`;return await d(i,JSON.stringify(s),{encoding:"utf8",mode:384}),await p(i,e),e}async function h(t,r){let s;try{s=await u(t)}catch{return null}let e=[];for(let n of s){if(!n.startsWith("port-")||!n.endsWith(".json"))continue;try{let o=JSON.parse(await c(a(t,n),"utf8"));if(Number.isFinite(o.port))if(f(o.pid))e.push(o);else m(a(t,n)).catch(()=>{})}catch{}}if(e.length===0)return null;let i=r&&r>=1?e.filter((n)=>n.pid===r):[];return(i.length>0?i:e).sort((n,o)=>o.startedAt-n.startedAt)[0]??null}
2
- export{b as oh,h as ph};
2
+ export{b as pe,h as qe};
@@ -0,0 +1,2 @@
1
+ import{createRequire as q}from"node:module";var j=Object.create;var{getPrototypeOf:k,defineProperty:i,getOwnPropertyNames:l}=Object;var m=Object.prototype.hasOwnProperty;function n(a){return this[a]}var o,p,r=(a,b,d)=>{var f=a!=null&&typeof a==="object";if(f){var g=b?o??=new WeakMap:p??=new WeakMap,h=g.get(a);if(h)return h}d=a!=null?j(k(a)):{};let c=b||!a||!a.__esModule?i(d,"default",{value:a,enumerable:!0}):d;for(let e of l(a))if(!m.call(c,e))i(c,e,{get:n.bind(a,e),enumerable:!0});if(f)g.set(a,c);return c};var s=(a,b)=>()=>(b||a((b={exports:{}}).exports,b),b.exports);var u=q(import.meta.url);
2
+ export{r as re,s as se,u as te};