@cortexkit/opencode-anthropic-auth 2.8.0 → 2.9.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/dist/cli.js +1 -1
- package/dist/index-s1efwnr3.js +45 -0
- package/dist/index.js +1 -1
- package/dist/v2/adapter.d.ts +2 -2
- package/dist/v2/server.js +9 -9
- package/package.json +2 -2
- package/src/rpc/rpc-server.ts +34 -3
- package/dist/index-m901y2pg.js +0 -45
package/dist/cli.js
CHANGED
|
@@ -52,7 +52,7 @@ ${W}`:""}`}default:{let Q=Z?`${x("cyan",n0)} `:"",W=Z?x("cyan",B$):"";return`${
|
|
|
52
52
|
${W}
|
|
53
53
|
`}}}}).prompt();import{authorize as bJ,exchange as fJ,resolveClaudeCodeIdentity as xJ}from"@cortexkit/anthropic-auth-core";async function P4($,Z={authorize:bJ,exchange:fJ,resolveClaudeCodeIdentity:xJ,text:L4,isCancel:T3,print:console.log}){let J=await Z.authorize("max");Z.print(`Claude sign-in for ${$==="pi"?"Pi":"OpenCode"}`),Z.print(J.url);let z=await Z.text({message:"Paste the Claude callback URL or authorization code:"});if(Z.isCancel(z))throw Error("Claude sign-in cancelled");let X=await Z.exchange(z,J.verifier,J.redirectUri,J.state);if(X.type!=="success")throw Error("Claude sign-in failed");let G=await Z.resolveClaudeCodeIdentity(X.access,void 0,void 0);if(!G.accountUuid)throw Error("Claude sign-in did not establish an account UUID");return{accountIdentity:G.accountUuid,credential:{type:"oauth",access:X.access,refresh:X.refresh,expires:X.expires}}}var C4='Warning: OpenCode holds a separate Anthropic OAuth login. Remove the separate OpenCode Anthropic login, then choose "Claude via credential vault". Setup has left that login unchanged.',oJ="npx @cortexkit/opencode-anthropic-auth setup",V$="--remove-pi-auth",E3="--restore-legacy",S4="-y",T4=["--help","-h"],O4=[{label:V$,description:"Agree in advance to move a stored Pi Anthropic login out of the way: into the local account pool, or aside privately for vault use (restored on disconnect)."},{label:E3,description:"Move anthropic-auth's state from the CortexKit state folder back into OpenCode's config folder, for example before going back to an older version. Close every OpenCode, OpenCode 2 server and Pi first. Use it on its own."},{label:S4,description:"Same as --yes."},{label:T4.join(", "),description:"Show this help."}];function rJ(){let $=Math.max(...O4.map((Z)=>Z.label.length));return[nJ({command:oJ}),"","Also accepted by this command:",...O4.map((Z)=>` ${Z.label.padEnd($)} ${Z.description}`),"","--login cannot be combined with --claustrum, or with --opencode=2: for OpenCode 2, sign in from OpenCode itself."].join(`
|
|
54
54
|
`)}function B0($,Z){let J=$.get(Z);if(!J)throw Error("Missing setup plan");return J}async function k4($=[],Z={}){let J={...Z.env??process.env},z=Z.terminal??{input:process.stdin,output:process.stdout,signals:process},X=(q)=>z.output.write(`${q}
|
|
55
|
-
`);if($.some((q)=>T4.includes(q)))return X(rJ()),0;if(hJ())return X(iJ),1;if($.includes(E3))return tJ($,Z,J,X);let G=$.filter((q)=>q!==V$).map((q)=>q===S4?"--yes":q),Q=G.includes("--login");if(Q&&G.includes("--claustrum"))return X("Local sign-in and vault setup are two separate choices. Use --login or --claustrum, not both."),1;if(Q&&G.includes("--opencode=2"))return X(k3),1;let W=Z.runner??X$,Y=Z.fence??R4(W,{platform:Z.platform}),U=Z.migrateLocal??V7,H=new Map,K=new Map,D=new Map,B=new Map,L=[],C=!1,A="setup-process-check",I=(q)=>({env:J,fence:Y,paths:D.get(q),removePiAnthropicAuth:B.get(q)??!1}),T=(q)=>({...I(q),runner:W});async function m(q){if(!q.hosts.includes("pi"))return;let j=B0(D,"pi");if((await m1("pi",j.hostAuthPath)).kind==="absent")return;{let v=await wJ({env:J,authPath:j.hostAuthPath}).inspect();if(v.slot==="placeholder"&&v.stash==="missing")throw new mJ("missing-stash");if(q.mode==="claustrum"){if(v.slot==="placeholder")return}}if($.includes(V$)){B.set("pi",!0);return}let g=q.mode==="claustrum"?"Pi has stored Anthropic authentication. Rerun with --remove-pi-auth to preserve it privately during vault use and restore it on disconnect.":"Pi has a stored Anthropic login. Rerun with --remove-pi-auth to move it into the native account pool.";if(G.includes("--yes")||!z.input.isTTY)throw new r(g);if(!await P3(z,q.mode==="claustrum"?"Move Pi authentication aside privately for vault use, then restore it on disconnect?":"Move the Pi Anthropic OAuth login into the native account pool and remove its stored copy?"))throw new r("Native account-pool setup cannot finish while the stored Pi OAuth token takes precedence.");B.set("pi",!0)}async function u(q,j){let P=B0(K,q);if(await cJ(q,J)!==(j?"claustrum":P.priorMode)||await w1(q,T(q))!==P.fingerprint)throw new r("Setup inputs changed. Rerun setup with all hosts stopped.")}let F={packages:{opencode:A4,pi:_4},version:await I4(),displayName:"CortexKit Anthropic Auth",slashCommand:"/claude",vault:{connectionFile:b9(J.PI_ANTHROPIC_AUTH_CLAUSTRUM_CONNECTION_FILE&&!J.OPENCODE_ANTHROPIC_AUTH_CLAUSTRUM_CONNECTION_FILE?"pi":"opencode",J),hosts:{opencode:{name:p0.opencode,paths:E9("opencode",J)},pi:{name:p0.pi,paths:E9("pi",J)}}},async beforeSignIn(q,j){if(A=j.mode==="claustrum"?"setup-activation":"cli-setup",!C){if(dJ(J),j.hosts.includes("opencode")){let P=await gJ({role:"setup",env:J});if(P.kind!=="state-home"&&P.registration)L.push(P.registration)}for(let P of j.hosts)D.set(P,await L0(P,J));if(await Y7([...D.values()]),j.hosts.includes("pi"))L.push((await vJ({paths:B0(D,"pi").paths,role:"setup"})).registration);if(j.mode==="claustrum"){let P=j.hosts.map((E)=>b9(E,J)),g=P[0];if(new Set(P).size!==1||!g)throw new r("Selected hosts use different vault connection files.");F.vault.connectionFile=g}if(j.mode==="local"&&Q&&j.hosts.includes("opencode")&&j.opencodeGeneration==="2")throw new r(k3);if(j.mode==="local"){await v9(j.hosts,J);for(let P of j.hosts)await l0(P,I(P))()}await m(j);for(let P of j.hosts)if(j.mode==="claustrum"){if(K.set(P,await(Z.vaultPreflight??D7)(P,{...T(P),inspectOpenCodeAuth:j.opencodeGeneration!=="2"})),B0(K,P).separateOpenCodeLogin)X(C4)}else H.set(P,await m9(P,I(P),P==="opencode"&&j.opencodeGeneration==="2"));C=!0}else if(j.mode==="claustrum")await u(q,!1);else await N1(B0(H,q),I(q))},async signInLocal(q){let j=B0(H,q);if(!Q){if(j.generation2)X(k3);return}if(await N1(j,I(q)),await U(q,{...I(q),login:Z.localLogin??P4,preflight:j.preflight,skipMigration:j.action==="skip",beforeCommit:()=>N1(j,I(q))}),j.fingerprint=await B3(j,J),j.notice)X(g9)},async beforeRegister(q,j){if(j==="local")await N1(B0(H,q),I(q));else await u(q,!0),await(Z.vaultActivate??N7)(q,T(q),B0(K,q)),B0(K,q).fingerprint=await w1(q,T(q))},async migrate(q,j){if(j.mode==="claustrum"){if(await u(q,!0),q===j.hosts.at(-1)&&K.get("opencode")?.separateOpenCodeLogin)X(C4);return}let P=B0(H,q);if(await N1(P,I(q)),Q)return;if(P.action==="migration")await U(q,{...I(q),preflight:P.preflight});else if(P.action==="empty-init")await uJ({paths:P.paths.paths,routingDestinationPath:P.paths.routingDestinationPath,env:J,processFence:l0(q,I(q))});else if(P.action==="skip"){if(await w9(P,I(q)),P.notice)X(g9)}P.fingerprint=await B3(P,J)}};try{return await aJ(F,G,{...Z,env:J,terminal:z,runner:W,fence:Y}),0}catch(q){let P=U7(q)??c1(q)??await a0(A,q,J);if(P)X(P);for(let{host:g,outcome:E}of b7(q)??[]){if(E!=="enrolled")continue;let v=g==="opencode"?"OpenCode":"Pi";X(`${v} stays connected to the vault. In ${v}, run /claude → Accounts → Disconnect from the vault to undo it. Or run setup again to finish connecting.`)}return 1}finally{for(let q of L)q.close();for(let q of H.values())if(q.preflight)pJ(q.preflight)}}async function tJ($,Z,J,z){if($.some((Q)=>Q!==E3))return z(`${E3} runs on its own; run it without other options.`),1;let X=Z.runner??X$,G=Z.fence??R4(X,{platform:Z.platform});try{await yJ(G,J)}catch(Q){let W=D1(Q)??c1(Q);return z(W??await a0("setup-process-check",Q,J)),1}try{let Q=await(Z.restoreLegacy??lJ)({env:J});if(Q.status==="not-moved")return z(`Nothing to restore: ${Q.reason}.`),0;z(`anthropic-auth's state is back in ${Q.oldDir}.`);for(let W of Q.kept)z(`${W} changed after it was copied back and was left in place; delete it once you have checked it.`);return 0}catch(Q){if(Q instanceof sJ)return z(Q.message),1;return z(c1(Q)??await a0("cli-setup",Q,J)),1}}async function _1($){if(process.env.OPENCODE_AUTH_CONTENT!==void 0)throw Error("Native account changes require offline setup without OPENCODE_AUTH_CONTENT");let Z=await Xz({role:"cli"}),J=await Kz(void 0,void 0,Z.layout),z=zz({paths:J,host:"opencode"});try{return await z.read(),await $(z)}finally{if(Z.kind!=="state-home")Z.registration?.close();await z.close()}}async function b3(){if(await Uz("opencode",process.env)!=="local")throw Error("Disconnect from the vault first.")}function E4(){console.log(`Usage:
|
|
55
|
+
`);if($.some((q)=>T4.includes(q)))return X(rJ()),0;if(hJ())return X(iJ),1;if($.includes(E3))return tJ($,Z,J,X);let G=$.filter((q)=>q!==V$).map((q)=>q===S4?"--yes":q),Q=G.includes("--login");if(Q&&G.includes("--claustrum"))return X("Local sign-in and vault setup are two separate choices. Use --login or --claustrum, not both."),1;if(Q&&G.includes("--opencode=2"))return X(k3),1;let W=Z.runner??X$,Y=Z.fence??R4(W,{platform:Z.platform}),U=Z.migrateLocal??V7,H=new Map,K=new Map,D=new Map,B=new Map,L=[],C=!1,A="setup-process-check",I=(q)=>({env:J,fence:Y,paths:D.get(q),removePiAnthropicAuth:B.get(q)??!1}),T=(q)=>({...I(q),runner:W});async function m(q){if(!q.hosts.includes("pi"))return;let j=B0(D,"pi");if((await m1("pi",j.hostAuthPath)).kind==="absent")return;{let v=await wJ({env:J,authPath:j.hostAuthPath}).inspect();if(v.slot==="placeholder"&&v.stash==="missing")throw new mJ("missing-stash");if(q.mode==="claustrum"){if(v.slot==="placeholder")return}}if($.includes(V$)){B.set("pi",!0);return}let g=q.mode==="claustrum"?"Pi has stored Anthropic authentication. Rerun with --remove-pi-auth to preserve it privately during vault use and restore it on disconnect.":"Pi has a stored Anthropic login. Rerun with --remove-pi-auth to move it into the native account pool.";if(G.includes("--yes")||!z.input.isTTY)throw new r(g);if(!await P3(z,q.mode==="claustrum"?"Move Pi authentication aside privately for vault use, then restore it on disconnect?":"Move the Pi Anthropic OAuth login into the native account pool and remove its stored copy?"))throw new r("Native account-pool setup cannot finish while the stored Pi OAuth token takes precedence.");B.set("pi",!0)}async function u(q,j){let P=B0(K,q);if(await cJ(q,J)!==(j?"claustrum":P.priorMode)||await w1(q,T(q))!==P.fingerprint)throw new r("Setup inputs changed. Rerun setup with all hosts stopped.")}let F={packages:{opencode:A4,pi:_4},version:await I4(),displayName:"CortexKit Anthropic Auth",slashCommand:"/claude",vault:{connectionFile:b9(J.PI_ANTHROPIC_AUTH_CLAUSTRUM_CONNECTION_FILE&&!J.OPENCODE_ANTHROPIC_AUTH_CLAUSTRUM_CONNECTION_FILE?"pi":"opencode",J),hosts:{opencode:{name:p0.opencode,paths:E9("opencode",J)},pi:{name:p0.pi,paths:E9("pi",J)}}},async beforeSignIn(q,j){if(A=j.mode==="claustrum"?"setup-activation":"cli-setup",!C){if(dJ(J),j.hosts.includes("opencode")){let P=await gJ({role:"setup",env:J});if(P.kind!=="state-home"&&P.registration)L.push(P.registration)}for(let P of j.hosts)D.set(P,await L0(P,J));if(await Y7([...D.values()]),j.hosts.includes("pi"))L.push((await vJ({paths:B0(D,"pi").paths,role:"setup"})).registration);if(j.mode==="claustrum"){let P=j.hosts.map((E)=>b9(E,J)),g=P[0];if(new Set(P).size!==1||!g)throw new r("Selected hosts use different vault connection files.");F.vault.connectionFile=g}if(j.mode==="local"&&Q&&j.hosts.includes("opencode")&&j.opencodeGeneration==="2")throw new r(k3);if(j.mode==="local"){await v9(j.hosts,J);for(let P of j.hosts)await l0(P,I(P))()}await m(j);for(let P of j.hosts)if(j.mode==="claustrum"){if(K.set(P,await(Z.vaultPreflight??D7)(P,{...T(P),inspectOpenCodeAuth:j.opencodeGeneration!=="2"})),B0(K,P).separateOpenCodeLogin)X(C4)}else H.set(P,await m9(P,I(P),P==="opencode"&&j.opencodeGeneration==="2"));C=!0}else if(j.mode==="claustrum")await u(q,!1);else await N1(B0(H,q),I(q))},async signInLocal(q){let j=B0(H,q);if(!Q){if(j.generation2)X(k3);return}if(await N1(j,I(q)),await U(q,{...I(q),login:Z.localLogin??P4,preflight:j.preflight,skipMigration:j.action==="skip",beforeCommit:()=>N1(j,I(q))}),j.fingerprint=await B3(j,J),j.notice)X(g9)},async beforeRegister(q,j){if(j==="local")await N1(B0(H,q),I(q));else await u(q,!0),await(Z.vaultActivate??N7)(q,T(q),B0(K,q)),B0(K,q).fingerprint=await w1(q,T(q))},async migrate(q,j){if(j.mode==="claustrum"){if(await u(q,!0),q===j.hosts.at(-1)&&K.get("opencode")?.separateOpenCodeLogin)X(C4);return}let P=B0(H,q);if(await N1(P,I(q)),Q)return;if(P.action==="migration")await U(q,{...I(q),preflight:P.preflight});else if(P.action==="empty-init")await uJ({paths:P.paths.paths,routingDestinationPath:P.paths.routingDestinationPath,env:J,processFence:l0(q,I(q))});else if(P.action==="skip"){if(await w9(P,I(q)),P.notice)X(g9)}P.fingerprint=await B3(P,J)}};try{return await aJ(F,G,{...Z,env:J,terminal:z,runner:W,fence:Y}),0}catch(q){let P=U7(q)??c1(q)??await a0(A,q,J);if(P)X(P);for(let{host:g,outcome:E}of b7(q)??[]){if(E!=="enrolled")continue;let v=g==="opencode"?"OpenCode":"Pi";X(`${v} stays connected to the vault. In ${v}, run /claude → Accounts → Disconnect from the vault to undo it. Or run setup again to finish connecting.`)}return 1}finally{for(let q of L)q.close();for(let q of H.values())if(q.preflight)pJ(q.preflight)}}async function tJ($,Z,J,z){if($.some((Q)=>Q!==E3))return z(`${E3} runs on its own; run it without other options.`),1;let X=Z.runner??X$,G=Z.fence??R4(X,{platform:Z.platform});try{await yJ(G,J)}catch(Q){let W=D1(Q)??c1(Q);return z(W??await a0("setup-process-check",Q,J)),1}try{let Q=await(Z.restoreLegacy??lJ)({env:J});if(Q.status==="not-moved")return z(`Nothing to restore: ${Q.reason}.`),0;z(`anthropic-auth's state is back in ${Q.oldDir}.`);for(let W of Q.kept)z(`${W} changed after it was copied back and was left in place; delete it once you have checked it.`);return 0}catch(Q){if(Q instanceof sJ)return z(Q.message),1;return z(c1(Q)??await a0("cli-setup",Q,J)),1}}async function _1($){if(process.env.OPENCODE_AUTH_CONTENT!==void 0)throw Error("Native account changes require offline setup without OPENCODE_AUTH_CONTENT");let Z=await Xz({role:"cli",requireExistingAuthority:!0}),J=await Kz(void 0,void 0,Z.layout),z=zz({paths:J,host:"opencode"});try{return await z.read(),await $(z)}finally{if(Z.kind!=="state-home")Z.registration?.close();await z.close()}}async function b3(){if(await Uz("opencode",process.env)!=="local")throw Error("Disconnect from the vault first.")}function E4(){console.log(`Usage:
|
|
56
56
|
opencode-anthropic-auth setup [--yes] [--dry-run]
|
|
57
57
|
opencode-anthropic-auth login [label]
|
|
58
58
|
opencode-anthropic-auth api add [label]
|