@cortexkit/opencode-anthropic-auth 2.16.4 → 2.16.5
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-bhd1rmy4.js → index-1x1mncm7.js} +1 -1
- package/dist/{index-39xzvbey.js → index-3fd62zrt.js} +1 -1
- package/dist/{index-rzb1rq84.js → index-7wda3e19.js} +2 -2
- package/dist/{index-txrrjz4d.js → index-aptr1edk.js} +1 -1
- package/dist/{index-23g20dt0.js → index-j3256ry3.js} +1 -1
- package/dist/{index-ct4m3d80.js → index-mrbp5svf.js} +1 -1
- package/dist/index-r5psch9p.js +47 -0
- package/dist/{index-6q2f3m0v.js → index-sby24dy7.js} +1 -1
- package/dist/{index-yrce651f.js → index-xvwrzpd4.js} +1 -1
- package/dist/index.js +1 -1
- package/dist/rpc/port-file.js +1 -1
- package/dist/rpc/protocol.js +1 -1
- package/dist/rpc/rpc-client.js +1 -1
- package/dist/rpc/rpc-dir.js +1 -1
- package/dist/server-fallback.d.ts +13 -0
- package/dist/sidebar-state.js +1 -1
- package/dist/tui-preferences.js +1 -1
- package/dist/v2/server.js +11 -11
- package/dist/v2/tui.js +1 -1
- package/dist/v2/wire.d.ts +3 -1
- package/package.json +2 -2
- package/dist/index-9d7k6v9w.js +0 -47
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{D as c3}from"./index-23g20dt0.js";import{F as r6,G as t6,H as T8,I as k8,J as E8,K as b8,L as e6}from"./index-yrce651f.js";import{na as $9}from"./index-39xzvbey.js";import{stdin as xz,stdout as yz}from"node:process";import{createInterface as vz}from"node:readline/promises";import{authorize as gz,createNativeAccountRuntime as wz,decideOpenCodeStateLayoutOnce as mz,exchange as hz,formatNativeAccountState as uz,generateRelayToken as cz,getAccountStoragePath as pz,isValidApiBaseURL as dz,readNativeEnrollmentMode as lz,resolveNativePoolPaths as az,WORKER_SCRIPT as sz}from"@cortexkit/anthropic-auth-core";import{randomUUID as p$}from"node:crypto";import{constants as _3}from"node:fs";import{lstat as d$,mkdir as l$,open as a$}from"node:fs/promises";import{homedir as s$}from"node:os";import{isAbsolute as n$,join as p8}from"node:path";import{types as X7}from"node:util";import{anthropicAuthStateRoot as i$,createProviderErrorRedactor as d8,createWindowsOwnerOnly as o$,ensureWindowsOwnerOnlyDirectory as r$,formatLogLine as t$,HOLDER_REGISTRATION_ERROR_MESSAGES as e$,isOwnerOnly as $Z,isSecretKey as ZZ,isStateLayoutRefusalCode as JZ,NativeMigrationError as zZ,NativePiAuthSlotError as XZ,PRIVATE_FILES_UNAVAILABLE_MESSAGE as l8,RELOCATED_MESSAGE as GZ,STATE_LAYOUT_REFUSAL_CODES as QZ,STATE_LAYOUT_REFUSAL_PUBLIC_MESSAGES as WZ,setupEnrollment as YZ,stateLayoutRefusalPublicMessage as HZ}from"@cortexkit/anthropic-auth-core";import{readFile as x$}from"node:fs/promises";import{assertHostsStopped as y$,createNativeAccountRuntime as v$,discoverNativeVaultInventory as g$,inspectNativeHostAuthEntry as r9,openNativePiAuthSlot as e9,readNativeEnrollmentMode as w$,requireNoSupervisedAuthContentSnapshot as m$}from"@cortexkit/anthropic-auth-core";import{dirname as C$}from"node:path";import{CLAUSTRUM_OPENCODE_ENROLLMENT_NAME as _$,CLAUSTRUM_PI_ENROLLMENT_NAME as I$,getHostClaustrumEnrollmentPaths as C8,resolveClaustrumConnectionPath as R$}from"@cortexkit/anthropic-auth-core";import{writeEnrollmentTokenFile as BY}from"@cortexkit/claustrum-client";import{ClaustrumClient as aW}from"@cortexkit/claustrum-client";import{ClaustrumCredentialError as G5}from"@cortexkit/claustrum-client";import{SocketClosedError as Q5,SocketTimeoutError as W5,SubcCallError as Y5}from"@cortexkit/subc-client";class A extends Error{kind;constructor($,Z){super(Z);this.name="ClaustrumConsumerError",this.kind=$}}var i3=Object.freeze({ECONNREFUSED:"unreachable",ENOENT:"unreachable",ECONNRESET:"unreachable",EPIPE:"unreachable",ETIMEDOUT:"unreachable",transport_error:"unreachable",unavailable:"unreachable",timeout:"unreachable",route_closed:"unreachable",route_busy:"unreachable",daemon_draining:"unreachable",connection_closed:"unreachable",connection_dropped:"unreachable",request_deadline:"unreachable",deadline_exceeded_no_drop_observed:"unreachable",module_reloading:"unreachable",module_warming:"unreachable",target_unavailable:"unreachable",module_timeout:"unreachable",invalid_response:"answered",invalid_record_version:"answered",invalid_expiry:"answered",invalid_status:"answered",invalid_params:"answered",ttl_unsatisfiable:"answered",not_found:"answered",enrollment_revoked:"answered",enrollment_invalid:"answered",grant_denied:"answered",credential_unavailable:"answered",needs_reauth:"answered",declined:"answered",disabled:"answered",identity_changed:"answered",closed:"answered",client_closed:"answered",pending_exists:"answered",pending_queue_full:"answered",already_consumed:"answered",superseded:"answered",stale_generation:"answered",missing_identity:"answered",invalid_control_body:"answered",unknown_module:"answered",module_removed:"answered",capability_denied:"answered",unknown_channel:"unreachable",stale_route_epoch:"unreachable",capability_forbidden:"answered",capability_unprovided:"answered",capability_ambiguous:"answered",invalid_capability_identifier:"answered",binary_body_required:"answered",binary_call_requires_call_binary:"answered",corr_exhausted:"answered",late_route_cleanup_failed:"answered",reverse_request_capability_not_declared:"answered",stale_route_handle:"answered",reverse_request_unhandled:"answered",handler_error:"answered",health_error:"answered",duplicate_module_id:"answered",route_rejected:"answered",lock_busy:"answered",owner_invalid:"answered",renewal_failed:"answered",unsupported_platform:"answered",EACCES:"answered",EPERM:"answered",ERR_PRIVATE_FILES_SECURITY:"answered"});class u extends A{reason;constructor($){super("unavailable","Claustrum vault could not be reached");if(this.name="ClaustrumUnreachableError",$==="host-accessor-missing"||$==="host-accessor-failed")this.reason=$}}function J0($){if($ instanceof u||$ instanceof Q5||$ instanceof W5)return"unreachable";let Z=$ instanceof G5||$ instanceof Y5?$.code:$ instanceof Error&&("code"in $)?$.code:void 0;if(typeof Z!=="string"||!Object.hasOwn(i3,Z))return"answered";return i3[Z]}import{resolve as v7}from"node:path";import{storeIdentity as qX}from"@cortexkit/claustrum-client";import{SubcClient as BX}from"@cortexkit/subc-client";var z1=300000,X3=300000,o3=1000;class f1{#$;#Z=0;restart(){this.#Z=0}continuous($){let Z=$.kind==="changed"&&$.seq===this.#Z+1&&(this.#$===void 0||$.epoch===this.#$);return this.#$=$.epoch,this.#Z=$.seq,Z}}class G3{#$;#Z;#z;#W=!1;constructor($,Z){this.#$=$,this.#Z=Z}get running(){return this.#z}request(){if(this.#z)return this.#W=!0,this.#z;return this.#z=(async()=>{do{this.#W=!1;try{await this.#$()}catch($){this.#Z($)}}while(this.#W)})().finally(()=>{this.#z=void 0}),this.#z}}class Q3{#$;#Z=new f1;#z;#W="polling";#G;#Q;#X=!1;#J;#U=!1;#H=0;constructor($){this.#$=$,this.#z=new G3(async()=>{let Z=this.#U;if(this.#U=!1,Z||this.#J!==this.#$.view())await this.#$.discover(this.#J??"")},(Z)=>{if(!this.#X)this.#$.onError?.(Z)})}get mode(){return this.#W}start(){if(this.#X||this.#G||this.#Q)return;if(typeof this.#$.client.watchScoped!=="function"){this.#q("fallback","client-without-watch");return}this.#N(!1)}stop(){if(this.#X)return;if(this.#X=!0,this.#Q)(this.#$.clearTimeoutImpl??clearTimeout)(this.#Q);this.#Q=void 0;let $=this.#G;this.#G=void 0,$?.handle.stop()}#q($,Z){if(this.#W===$)return;this.#W=$,this.#$.logger?.debug("claustrum vault watch",{mode:$,reason:Z}),this.#$.onMode?.($)}#B($,Z){this.#Q=(this.#$.setTimeoutImpl??setTimeout)(()=>{if(this.#Q=void 0,!this.#X)Z()},$),this.#Q.unref?.()}async#N($){let Z;try{Z=await this.#$.enrollmentToken()}catch(Q){if(this.#X)return;this.#$.onError?.(Q),this.#L("token-unreadable");return}let J=this.#$.client.watchScoped;if(this.#X||this.#G||!J)return;this.#Z.restart(),this.#U=$;let z,X;try{X=J.call(this.#$.client,(Q)=>{if(this.#X||!z||this.#G!==z)return;if(z.notices++,z.notices===1)this.#$.onReachable?.(),z.acceptedAt=(this.#$.now??Date.now)(),this.#q("watching","accepted");if(!this.#Z.continuous(Q))this.#U=!0;this.#J=Q.view,this.#z.request()},{enrollmentToken:Z})}catch(Q){this.#$.onError?.(Q),this.#L("watch-failed");return}z={handle:X,notices:0},this.#G=z,this.#q("polling",$?"resubscribing":"opening");let G=z;X.closed.then((Q)=>this.#Y(G,Q),(Q)=>this.#Y(G,{kind:"transport_lost",error:Q}))}#Y($,Z){if(this.#X||this.#G!==$)return;if(this.#G=void 0,Z.kind==="stopped")return;if(Z.kind==="transport_lost")this.#$.onTransportLost?.();if(Z.kind==="unsupported"){this.#q("fallback","vault-without-watch");return}if(Z.kind==="refused"){this.#L("refused");try{this.#$.onRefused(Z.error)}catch(J){this.#$.onError?.(J)}return}if($.notices>0){let J=(this.#$.now??Date.now)();if($.acceptedAt!==void 0&&J-$.acceptedAt>=300000)this.#H=0;let z=Math.min(1000*2**Math.min(this.#H,16),300000);this.#H++,this.#q("polling","resubscribing"),this.#B(z,()=>void this.#N(!0));return}this.#L(Z.kind)}#L($){this.#q("fallback",$),this.#B(300000,()=>void this.#N(!1))}}var Y3=60000,g7=4*Y3,H5=2*Y3,r3=new Map,W3=new Map;function X1($){return typeof $==="object"&&$!==null&&!Array.isArray($)}function K5($){let Z;try{Z=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode($))}catch{return}if(!X1(Z)||typeof Z.kind!=="string"||typeof Z.epoch!=="string"||Z.epoch.length===0||typeof Z.seq!=="number"||!Number.isSafeInteger(Z.seq)||Z.seq<1||Z.provider!==void 0&&typeof Z.provider!=="string")return;return{kind:Z.kind,epoch:Z.epoch,seq:Z.seq,...typeof Z.provider==="string"&&{provider:Z.provider}}}function U5($){return $ instanceof Error&&"code"in $&&typeof $.code==="string"?$.code:void 0}class w7{transport;key;#$=[];#Z=!1;#z=new Set;#W=new Map;#G=new G3(async()=>{try{let $=await this.transport.getUsage();if(!X1($)||!Array.isArray($.result)||$.error!==void 0)throw Error("unavailable insula usage");this.#$=$.result.filter((Z)=>X1(Z)&&typeof Z.provider==="string"),this.#Z=this.#$.length===$.result.length&&($.completeProviders===void 0||Array.isArray($.completeProviders)&&$.completeProviders.every((Z)=>typeof Z==="string")),this.#z=new Set(this.#Z&&Array.isArray($.completeProviders)?$.completeProviders:[]);for(let Z of this.#z)this.#W.delete(Z)}catch{this.#$=[],this.#Z=!1,this.#z.clear()}},()=>{});#Q=new f1;#X="polling";#J=0;#U=0;#H=new Map;#q;#B;#N={};#Y=0;constructor($,Z){this.transport=$,this.key=Z}refresh($){if(this.#G.running)return this.#G.running;if(this.#X==="watching")return Promise.resolve();for(let[J,z]of W3)if($-z>=Y3)W3.delete(J);let Z=W3.get(this.key);if(Z!==void 0&&$-Z<Y3)return Promise.resolve();return W3.set(this.key,$),this.#G.request()}watchMode(){return this.#X}watch($={}){this.#J++;let Z=$.provider;if(Z===void 0)this.#U++;else this.#H.set(Z,(this.#H.get(Z)??0)+1);if(this.#J===1)this.#N=$,this.#O();let J=!1;return()=>{if(J)return;if(J=!0,Z===void 0)this.#U--;else{let z=(this.#H.get(Z)??1)-1;if(z>0)this.#H.set(Z,z);else this.#H.delete(Z)}if(--this.#J===0)this.#L()}}#L(){if(this.#B)(this.#N.clearTimeoutImpl??clearTimeout)(this.#B);this.#B=void 0;let $=this.#q;this.#q=void 0,$?.handle?.stop(),this.#X="polling"}#j($){this.#B=(this.#N.setTimeoutImpl??setTimeout)(()=>{if(this.#B=void 0,this.#J>0&&!this.#q)this.#O()},$),this.#B.unref?.()}#O(){let $=this.transport.watchUsage;if(!$){this.#X="fallback";return}this.#X="polling",this.#Q.restart();let Z={notices:0};this.#q=Z;let J;try{J=$.call(this.transport,(z)=>this.#A(Z,z))}catch(z){this.#_(Z,z);return}Z.handle=J,J.closed.then(()=>this.#_(Z,void 0),(z)=>this.#_(Z,z))}#A($,Z){if(this.#q!==$)return;if($.notices++,$.notices===1)this.#X="watching";if($.notices===2)this.#Y=0;let J=K5(Z);if(!J)this.#Q.restart();if(!(J?this.#Q.continuous(J):!1)||J?.provider===void 0||this.#U>0||this.#H.has(J.provider))this.#G.request()}#_($,Z){if(this.#q!==$)return;this.#q=void 0;let J=U5(Z);if(J==="unknown_method"||J==="usage_watch_limit"){this.#X="fallback";return}if($.notices>0){let z=Math.min(o3*2**Math.min(this.#Y,16),X3);this.#Y++,this.#X="polling",this.#j(z);return}if(this.#X="fallback",this.#G.request(),Z===void 0||J0(Z)==="unreachable")this.#j(X3)}current($,Z,J){for(let z of this.#$){if(z.provider!==$||typeof z.account!=="string"||z.account.trim()!==Z)continue;if(z.stale!==void 0||z.errorClass!==void 0||!X1(z.usage))continue;let X=typeof z.fetchedAt==="string"?Date.parse(z.fetchedAt):Number.NaN;if(!Number.isFinite(X)||J-X>=g7)continue;return{entry:z,context:{fetchedAt:X,...typeof z.source==="string"&&{source:z.source}}}}return}lookup($,Z,J){if(!this.#Z)return{miss:"unreachable"};let z=this.#$.find((Q)=>Q.provider===$&&typeof Q.account==="string"&&Q.account.trim()===Z),X=(z??this.#$.find((Q)=>Q.provider===$&&Q.account===void 0&&Q.errorClass!==void 0))?.errorClass;if(X==="upstream_failed")return{miss:"upstream-failed"};if(X==="credential_absent"||X==="credential_unusable"||X==="credential_rejected")return{miss:"credential"};if(X!==void 0)return{miss:"unreachable"};if(z){let Q=typeof z.fetchedAt==="string"?Date.parse(z.fetchedAt):Number.NaN;if(!X1(z.usage)||!Number.isFinite(Q))return{miss:"unreachable"};let W={entry:z,context:{fetchedAt:Q,...typeof z.source==="string"&&{source:z.source}}};if(z.stale!==void 0&&(!X1(z.stale)||z.stale.class!=="local_source_unavailable"))return{miss:"upstream-failed",reading:W};return J>=Q+g7||z.stale!==void 0?{miss:"stale",reading:W}:{reading:W}}if(this.#z.has($))return{miss:"absent"};let G=this.#W.get($)??J;return this.#W.set($,G),{miss:J-G>=H5?"unreachable":"cold"}}}function t3($,Z){let J=JSON.stringify([v7($.connectionFile),v7(Z)]),z=r3.get(J);if(!z)z={source:new w7($,J),refs:0},r3.set(J,z);z.refs++;let X=!1;return{source:z.source,release(){if(X)return;if(X=!0,--z.refs===0)r3.delete(J)}}}import{ClaustrumCredentialError as rW}from"@cortexkit/claustrum-client";import{appendFileSync as _5,chmodSync as I5,existsSync as J9,renameSync as i7,statSync as R5}from"node:fs";import{open as S5}from"node:fs/promises";import{dirname as T5,resolve as k5}from"node:path";import{randomUUID as c7}from"node:crypto";import{lstat as p7,readFile as d7,rename as q5,unlink as m7}from"node:fs/promises";import{tmpdir as F5}from"node:os";import{dirname as I0,join as B5,resolve as z0}from"node:path";var I=process.platform==="win32",h7=new Set;function e3($){if($?.reason==="io-error"){if($.win32Code===2||$.win32Code===3)return"ENOENT";if($.win32Code===80||$.win32Code===183)return"EEXIST"}return $?.code??"ERR_PRIVATE_FILE"}var u7;var j5="native-addon-unavailable";function l7($){return Object.assign(Error("Windows private-files native addon could not be loaded",{cause:$}),{code:"ERR_PRIVATE_FILES_UNAVAILABLE",reason:j5})}function V5($,Z){return Z instanceof $.PrivateFilesUnavailableError||Z?.code==="ERR_PRIVATE_FILES_UNAVAILABLE"}async function M5($){try{await $.verifyPrivatePath(B5(F5(),`.common-auth-private-files-probe-${c7()}`),"file")}catch(Z){if(V5($,Z))throw l7(Z)}}function G1(){return u7??=import("@cortexkit/private-files").then(async($)=>{if(I)await M5($);return $},($)=>{throw I?l7($):$}),u7}function a7($){return $?.reason==="io-error"&&($.win32Code===32||$.win32Code===303)}class h extends Error{path;stage;code;win32Code;reason;published=!1;durabilityConfirmed=!1;fileDurable=!1;attempts=0;elapsedMs=0;orphanPath;constructor($,Z,J){let z=J;super(z?.code==="ERR_PRIVATE_FILES_UNAVAILABLE"?`Private file refused at ${Z}: ${$}. The Windows native addon of @cortexkit/private-files could not be loaded, so owner-only access cannot be enforced and nothing was read or written. Reinstall the plugin so the private-files Windows prebuild for this architecture is present; Windows has no safe fallback to permission bits.`:a7(z)?`Private file busy at ${Z}: ${$}. Another process was replacing or deleting this file at the same moment (Windows error ${z.win32Code}).`:`Private file refused at ${Z}: ${$} (${z?.reason??z?.code??"io-error"}). Keep this file in a folder that only you, the system or administrators can change, such as a folder in your home directory. If other users could read the file before, sign in again to replace the credentials it held. On Windows the file must also be on a local drive that keeps Windows file permissions, such as NTFS.`,{cause:J});this.path=$,this.stage=Z,this.name="PrivateFileError",this.code=e3(z),this.win32Code=z?.win32Code,this.reason=z?.reason}}function x1($){return I&&$ instanceof h&&a7($)}async function t($,Z,J){try{return await J()}catch(z){if(z instanceof h)throw z;throw new h($,Z,z)}}var D5;async function M0($,Z){$=z0($),Z??=D5,await t($,"safe-parent",async()=>{let J=await(await G1()).verifySafeParent($,Z);if(J.ok===!1){if(J.reason==="io-error"||J.reason==="wrong-kind")await p7($);throw new h(J.level??J.path,"safe-parent",{...J,code:"ERR_PRIVATE_FILES_SECURITY"})}})}async function s($,Z,J=!1){if($=z0($),Z==="directory")return M0($);await t($,"verify",async()=>{let z=await G1(),X=await z.verifyOwnerOnly($),G=!1;if(!X.ok){let{reason:Q}=X.refusal;if(Q==="io-error")await z.verifyPrivatePath($,Z);if(J&&[z.EXTRA_ACE,z.NOT_PROTECTED,z.NULL_DACL,z.EMPTY_DACL].includes(Q))await M0(I0($)),await z.securePrivatePath($,Z),G=!0;else throw Object.assign(Error("Owner-only verification refused"),{reason:Q,code:"ERR_PRIVATE_FILES_SECURITY"})}if(await z.verifyPrivatePath($,Z),G&&!h7.has($))h7.add($),process.emitWarning(`Private permissions tightened: ${$}. This object may have been readable before; rotate credentials if needed.`,"PrivateFileMigration")})}async function U0($,Z=!1,J){$=z0($),await t($,"directory",async()=>{let z=await G1();try{return await p7($),await M0($,J)}catch(G){if(e3(G)!=="ENOENT")throw G}let X=I0($);if(X===$)throw Object.assign(Error("Missing root"),{code:"ENOENT"});await U0(X,!1,J);try{await z.createOwnerOnly($,{kind:"dir"})}catch(G){if(e3(G)!=="EEXIST")throw G}await M0($,J)})}async function G0($,Z=!1){if(!I)return d7($,"utf8");return(await N5($,Z)).toString("utf8")}async function N5($,Z=!1){if(!I)return d7($);if($=z0($),Z)await M0(I0($)),await s($,"file",!0);return t($,"read",async()=>(await G1()).readOwnerOnly($))}async function Q1($,Z){await M0(I0(z0($))),await t($,"create",async()=>{await(await G1()).createPrivateFile(z0($),Z)})}async function s7($){await M0(I0(z0($))),await t($,"directory-create",async()=>{await(await G1()).createOwnerOnly(z0($),{kind:"dir"})})}async function Z9($,Z,J={}){$=z0($),Z=z0(Z);let z=J.now??(()=>performance.now()),X=z(),G=J.deadline??1/0,Q,W=[0,10,20,40,80,100],Y,K=0;for(let H of W){let F=Math.min(Q??1/0,G);if(z()>=F)break;if(H)await(J.sleep??((M)=>new Promise((P)=>setTimeout(P,M))))(Math.min(H,Math.max(0,F-z())));if(z()>=F)break;let B=z();if(await J.beforeRename?.(),Q!==void 0)Q+=z()-B;if(z()>=G)break;K++;try{return await(J.rename??q5)($,Z),{attempts:K,elapsedMs:z()-X}}catch(M){Y??=M;let P=M;if(!(P.win32Code!==void 0?P.win32Code===32||P.win32Code===33:["EBUSY","EPERM","EACCES"].includes(P.code??"")&&!P.reason))break;Q??=z()+500}}let q=new h(Z,"rename",Y??Object.assign(Error("Publication deadline expired"),{code:"ETIMEDOUT"}));throw q.attempts=K,q.elapsedMs=z()-X,q}async function W1($,Z,J={}){$=z0($),await U0(I0($));try{await s($,"file",!0)}catch(K){if(K.code!=="ENOENT")throw K}let z=z0(J.stagePath??`${$}.${c7()}.tmp`);if(I0(z)!==I0($))throw new h($,"stage-directory",{code:"EXDEV"});let X=!1,G=!1,Q={attempts:0,elapsedMs:0},W="stage-create",Y=(K)=>{try{J.onOutcome?.({path:$,stage:K?.stage??"published",published:G,fileDurable:G,durabilityConfirmed:!1,attempts:K?.attempts??Q.attempts,elapsedMs:K?.elapsedMs??Q.elapsedMs,...K&&{code:K.code,win32Code:K.win32Code}})}catch{}};try{if(await Q1(z,Z),X=!0,W="before-rename",Q=await Z9(z,$,J),X=!1,G=!0,W="published-callback",J.onRenamed?.(),W="published-verify",await s($,"file"),J.durable&&J.durability!=="file-only-on-windows")throw new h($,"directory-sync-unsupported",{code:"ENOTSUP"});Y()}catch(K){let q=K instanceof h?K:new h($,W,K);if(q.published=G,q.fileDurable=G,G)Object.assign(q,Q);if(X){try{await m7(z)}catch{q.orphanPath=z}X=!1}throw Y(q),q}finally{if(X)await m7(z).catch(()=>{})}}var L5=/^(authorization|x-api-key|cookie|set-cookie|refresh|access|token)$/i,P5=/\b(Bearer\s+[\w.-]+|sk-[\w-]+|eyJ[\w.-]+)\b|ckh_[A-Za-z0-9_-]{20,}/g;function O5($){return $ instanceof Error||Object.prototype.toString.call($)==="[object Error]"}function Y1($={}){let Z=[P5,...$.extraValuePatterns??[]].map((G)=>new RegExp(G.source,G.flags.includes("g")?G.flags:`${G.flags}g`));function J(G){let Q=G.toLowerCase().replace(/[-_]/g,"");return L5.test(G)||Q.includes("apikey")||Q.endsWith("secret")||Q.endsWith("password")||Q.endsWith("token")&&!Q.endsWith("tokens")||!!$.extraSecretKeys?.(Q)}function z(G){let Q=G,W=[["name",G.name],["message",G.message],["stack",G.stack]];for(let K of["code","status","cause"])if(Q[K]!==void 0)W.push([K,Q[K]]);let Y=new Set(W.map(([K])=>K));for(let K of Object.entries(G))if(!Y.has(K[0]))W.push(K);return W}function X(G,Q,W,Y=0){if(typeof G==="string")return Z.reduce((K,q)=>K.replace(q,"***REDACTED***"),G);if(!G||typeof G!=="object")return G;if(W.has(G))return"[Circular]";W.add(G);try{if(Array.isArray(G))return G.map((H)=>X(H,Q,W,Y));let K=O5(G);if(K&&Y>=8)return"[Truncated]";let q=K?Y+1:Y;return Object.fromEntries((K?z(G):Object.entries(G)).map(([H,F])=>[H,Q&&J(H)?"***REDACTED***":X(F,Q,W,q)]))}finally{W.delete(G)}}return{redact:(G)=>X(G,!0,new WeakSet),redactStrings:(G)=>X(G,!1,new WeakSet)}}var n7=Y1(),A5=n7.redact,C5=n7.redactStrings;var H3={error:0,warn:1,info:2,debug:3,trace:4},r7=5242880,t7=3;function z9($){try{I5($,384)}catch{}}function E5($){try{if(!(J9($)&&R5($).size>=r7))return;for(let J=t7-1;J>=1;J--)if(J9(`${$}.${J}`)){let z=`${$}.${J+1}`;i7(`${$}.${J}`,z),z9(z)}let Z=`${$}.1`;i7($,Z),z9(Z)}catch{}}async function D0($){let{file:Z,handle:J}=$;if($.file=void 0,$.handle=void 0,Z&&J)await t(Z,"log-close",()=>J.close())}async function o7($,Z){await U0(T5(Z));try{await s(Z,"file",!0)}catch(J){if(J.code!=="ENOENT")throw J;try{await Q1(Z,"")}catch(z){if(z.code!=="EEXIST")throw z;await s(Z,"file",!0)}}return $.handle=await t(Z,"log-open",()=>S5(Z,"a")),$.file=Z,$.handle}async function b5($,Z,J){Z=k5(Z);try{if($.file!==Z)await D0($);let z=$.handle??await o7($,Z);if((await t(Z,"log-stat",()=>z.stat())).size>=r7){await D0($);for(let G=t7-1;G>=0;G--){let Q=G===0?Z:`${Z}.${G}`,W=`${Z}.${G+1}`;try{await s(Q,"file",!0)}catch(Y){if(Y.code==="ENOENT")continue;throw Y}try{await s(W,"file",!0)}catch(Y){if(Y.code!=="ENOENT")throw Y}await Z9(Q,W),await s(W,"file")}z=await o7($,Z)}await t(Z,"log-append",()=>z.appendFile(J,"utf8"))}catch(z){throw await D0($).catch(()=>{}),z}}function f5($){try{return` ${JSON.stringify($)}`}catch{return" [unserializable]"}}function x5($){let Z,J,z,X=Y1(),G,Q=[],W,Y=Promise.resolve(),K,q={};function H(V){let U=Y.then(V);return Y=U.catch((N)=>{K=N}),U}function F(V){if(I&&V.file!==Z)H(()=>D0(q)).catch(()=>{});Z=V.file,J=V.level,X=Y1(V),G=V.captureSink}function B(V){if(V===void 0||V in H3)z=V}function M(){if(Z===void 0)return;return(typeof Z==="function"?Z():Z)||void 0}function P(){if(z)return z;let V=typeof J==="function"?J():J;if(V&&V in H3)return V;return"info"}function O(V=!0){if(W)clearTimeout(W),W=void 0;if(!Q.length){if(I)return H(async()=>{if(V)await D0(q);if(K)throw K});return}let U;try{U=M()}catch{if(Q=[],I&&V)return H(()=>D0(q));return}let N=Q.join("");if(Q=[],!U){if(I&&V)return H(()=>D0(q));return}if(I)return H(async()=>{try{await b5(q,U,N)}finally{if(V)await D0(q)}});try{if(E5(U),J9(U))z9(U);_5(U,N,{encoding:"utf8",mode:384})}catch{}}function _(){if(!W)W=setTimeout(()=>{W=void 0;let V=O(!1);if(V instanceof Promise)V.catch(()=>{})},500)}function T(V,U,N,C){if(Z===void 0&&G===void 0)return;try{if(H3[U]>H3[P()])return;let v=X.redactStrings(N),E;try{E=X.redact(C)}catch{E="[unserializable]"}let g=`[${new Date().toISOString()}] ${U.toUpperCase()} [${V}] ${v}`+(C===void 0?"":f5(E))+`
|
|
2
|
+
import{E as c3}from"./index-j3256ry3.js";import{G as r6,H as t6,I as T8,J as k8,K as E8,L as b8,M as e6}from"./index-xvwrzpd4.js";import{oa as $9}from"./index-3fd62zrt.js";import{stdin as xz,stdout as yz}from"node:process";import{createInterface as vz}from"node:readline/promises";import{authorize as gz,createNativeAccountRuntime as wz,decideOpenCodeStateLayoutOnce as mz,exchange as hz,formatNativeAccountState as uz,generateRelayToken as cz,getAccountStoragePath as pz,isValidApiBaseURL as dz,readNativeEnrollmentMode as lz,resolveNativePoolPaths as az,WORKER_SCRIPT as sz}from"@cortexkit/anthropic-auth-core";import{randomUUID as p$}from"node:crypto";import{constants as _3}from"node:fs";import{lstat as d$,mkdir as l$,open as a$}from"node:fs/promises";import{homedir as s$}from"node:os";import{isAbsolute as n$,join as p8}from"node:path";import{types as X7}from"node:util";import{anthropicAuthStateRoot as i$,createProviderErrorRedactor as d8,createWindowsOwnerOnly as o$,ensureWindowsOwnerOnlyDirectory as r$,formatLogLine as t$,HOLDER_REGISTRATION_ERROR_MESSAGES as e$,isOwnerOnly as $Z,isSecretKey as ZZ,isStateLayoutRefusalCode as JZ,NativeMigrationError as zZ,NativePiAuthSlotError as XZ,PRIVATE_FILES_UNAVAILABLE_MESSAGE as l8,RELOCATED_MESSAGE as GZ,STATE_LAYOUT_REFUSAL_CODES as QZ,STATE_LAYOUT_REFUSAL_PUBLIC_MESSAGES as WZ,setupEnrollment as YZ,stateLayoutRefusalPublicMessage as HZ}from"@cortexkit/anthropic-auth-core";import{readFile as x$}from"node:fs/promises";import{assertHostsStopped as y$,createNativeAccountRuntime as v$,discoverNativeVaultInventory as g$,inspectNativeHostAuthEntry as r9,openNativePiAuthSlot as e9,readNativeEnrollmentMode as w$,requireNoSupervisedAuthContentSnapshot as m$}from"@cortexkit/anthropic-auth-core";import{dirname as C$}from"node:path";import{CLAUSTRUM_OPENCODE_ENROLLMENT_NAME as _$,CLAUSTRUM_PI_ENROLLMENT_NAME as I$,getHostClaustrumEnrollmentPaths as C8,resolveClaustrumConnectionPath as R$}from"@cortexkit/anthropic-auth-core";import{writeEnrollmentTokenFile as BY}from"@cortexkit/claustrum-client";import{ClaustrumClient as aW}from"@cortexkit/claustrum-client";import{ClaustrumCredentialError as G5}from"@cortexkit/claustrum-client";import{SocketClosedError as Q5,SocketTimeoutError as W5,SubcCallError as Y5}from"@cortexkit/subc-client";class A extends Error{kind;constructor($,Z){super(Z);this.name="ClaustrumConsumerError",this.kind=$}}var i3=Object.freeze({ECONNREFUSED:"unreachable",ENOENT:"unreachable",ECONNRESET:"unreachable",EPIPE:"unreachable",ETIMEDOUT:"unreachable",transport_error:"unreachable",unavailable:"unreachable",timeout:"unreachable",route_closed:"unreachable",route_busy:"unreachable",daemon_draining:"unreachable",connection_closed:"unreachable",connection_dropped:"unreachable",request_deadline:"unreachable",deadline_exceeded_no_drop_observed:"unreachable",module_reloading:"unreachable",module_warming:"unreachable",target_unavailable:"unreachable",module_timeout:"unreachable",invalid_response:"answered",invalid_record_version:"answered",invalid_expiry:"answered",invalid_status:"answered",invalid_params:"answered",ttl_unsatisfiable:"answered",not_found:"answered",enrollment_revoked:"answered",enrollment_invalid:"answered",grant_denied:"answered",credential_unavailable:"answered",needs_reauth:"answered",declined:"answered",disabled:"answered",identity_changed:"answered",closed:"answered",client_closed:"answered",pending_exists:"answered",pending_queue_full:"answered",already_consumed:"answered",superseded:"answered",stale_generation:"answered",missing_identity:"answered",invalid_control_body:"answered",unknown_module:"answered",module_removed:"answered",capability_denied:"answered",unknown_channel:"unreachable",stale_route_epoch:"unreachable",capability_forbidden:"answered",capability_unprovided:"answered",capability_ambiguous:"answered",invalid_capability_identifier:"answered",binary_body_required:"answered",binary_call_requires_call_binary:"answered",corr_exhausted:"answered",late_route_cleanup_failed:"answered",reverse_request_capability_not_declared:"answered",stale_route_handle:"answered",reverse_request_unhandled:"answered",handler_error:"answered",health_error:"answered",duplicate_module_id:"answered",route_rejected:"answered",lock_busy:"answered",owner_invalid:"answered",renewal_failed:"answered",unsupported_platform:"answered",EACCES:"answered",EPERM:"answered",ERR_PRIVATE_FILES_SECURITY:"answered"});class u extends A{reason;constructor($){super("unavailable","Claustrum vault could not be reached");if(this.name="ClaustrumUnreachableError",$==="host-accessor-missing"||$==="host-accessor-failed")this.reason=$}}function J0($){if($ instanceof u||$ instanceof Q5||$ instanceof W5)return"unreachable";let Z=$ instanceof G5||$ instanceof Y5?$.code:$ instanceof Error&&("code"in $)?$.code:void 0;if(typeof Z!=="string"||!Object.hasOwn(i3,Z))return"answered";return i3[Z]}import{resolve as v7}from"node:path";import{storeIdentity as qX}from"@cortexkit/claustrum-client";import{SubcClient as BX}from"@cortexkit/subc-client";var z1=300000,X3=300000,o3=1000;class f1{#$;#Z=0;restart(){this.#Z=0}continuous($){let Z=$.kind==="changed"&&$.seq===this.#Z+1&&(this.#$===void 0||$.epoch===this.#$);return this.#$=$.epoch,this.#Z=$.seq,Z}}class G3{#$;#Z;#z;#W=!1;constructor($,Z){this.#$=$,this.#Z=Z}get running(){return this.#z}request(){if(this.#z)return this.#W=!0,this.#z;return this.#z=(async()=>{do{this.#W=!1;try{await this.#$()}catch($){this.#Z($)}}while(this.#W)})().finally(()=>{this.#z=void 0}),this.#z}}class Q3{#$;#Z=new f1;#z;#W="polling";#G;#Q;#X=!1;#J;#U=!1;#H=0;constructor($){this.#$=$,this.#z=new G3(async()=>{let Z=this.#U;if(this.#U=!1,Z||this.#J!==this.#$.view())await this.#$.discover(this.#J??"")},(Z)=>{if(!this.#X)this.#$.onError?.(Z)})}get mode(){return this.#W}start(){if(this.#X||this.#G||this.#Q)return;if(typeof this.#$.client.watchScoped!=="function"){this.#q("fallback","client-without-watch");return}this.#N(!1)}stop(){if(this.#X)return;if(this.#X=!0,this.#Q)(this.#$.clearTimeoutImpl??clearTimeout)(this.#Q);this.#Q=void 0;let $=this.#G;this.#G=void 0,$?.handle.stop()}#q($,Z){if(this.#W===$)return;this.#W=$,this.#$.logger?.debug("claustrum vault watch",{mode:$,reason:Z}),this.#$.onMode?.($)}#B($,Z){this.#Q=(this.#$.setTimeoutImpl??setTimeout)(()=>{if(this.#Q=void 0,!this.#X)Z()},$),this.#Q.unref?.()}async#N($){let Z;try{Z=await this.#$.enrollmentToken()}catch(Q){if(this.#X)return;this.#$.onError?.(Q),this.#L("token-unreadable");return}let J=this.#$.client.watchScoped;if(this.#X||this.#G||!J)return;this.#Z.restart(),this.#U=$;let z,X;try{X=J.call(this.#$.client,(Q)=>{if(this.#X||!z||this.#G!==z)return;if(z.notices++,z.notices===1)this.#$.onReachable?.(),z.acceptedAt=(this.#$.now??Date.now)(),this.#q("watching","accepted");if(!this.#Z.continuous(Q))this.#U=!0;this.#J=Q.view,this.#z.request()},{enrollmentToken:Z})}catch(Q){this.#$.onError?.(Q),this.#L("watch-failed");return}z={handle:X,notices:0},this.#G=z,this.#q("polling",$?"resubscribing":"opening");let G=z;X.closed.then((Q)=>this.#Y(G,Q),(Q)=>this.#Y(G,{kind:"transport_lost",error:Q}))}#Y($,Z){if(this.#X||this.#G!==$)return;if(this.#G=void 0,Z.kind==="stopped")return;if(Z.kind==="transport_lost")this.#$.onTransportLost?.();if(Z.kind==="unsupported"){this.#q("fallback","vault-without-watch");return}if(Z.kind==="refused"){this.#L("refused");try{this.#$.onRefused(Z.error)}catch(J){this.#$.onError?.(J)}return}if($.notices>0){let J=(this.#$.now??Date.now)();if($.acceptedAt!==void 0&&J-$.acceptedAt>=300000)this.#H=0;let z=Math.min(1000*2**Math.min(this.#H,16),300000);this.#H++,this.#q("polling","resubscribing"),this.#B(z,()=>void this.#N(!0));return}this.#L(Z.kind)}#L($){this.#q("fallback",$),this.#B(300000,()=>void this.#N(!1))}}var Y3=60000,g7=4*Y3,H5=2*Y3,r3=new Map,W3=new Map;function X1($){return typeof $==="object"&&$!==null&&!Array.isArray($)}function K5($){let Z;try{Z=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode($))}catch{return}if(!X1(Z)||typeof Z.kind!=="string"||typeof Z.epoch!=="string"||Z.epoch.length===0||typeof Z.seq!=="number"||!Number.isSafeInteger(Z.seq)||Z.seq<1||Z.provider!==void 0&&typeof Z.provider!=="string")return;return{kind:Z.kind,epoch:Z.epoch,seq:Z.seq,...typeof Z.provider==="string"&&{provider:Z.provider}}}function U5($){return $ instanceof Error&&"code"in $&&typeof $.code==="string"?$.code:void 0}class w7{transport;key;#$=[];#Z=!1;#z=new Set;#W=new Map;#G=new G3(async()=>{try{let $=await this.transport.getUsage();if(!X1($)||!Array.isArray($.result)||$.error!==void 0)throw Error("unavailable insula usage");this.#$=$.result.filter((Z)=>X1(Z)&&typeof Z.provider==="string"),this.#Z=this.#$.length===$.result.length&&($.completeProviders===void 0||Array.isArray($.completeProviders)&&$.completeProviders.every((Z)=>typeof Z==="string")),this.#z=new Set(this.#Z&&Array.isArray($.completeProviders)?$.completeProviders:[]);for(let Z of this.#z)this.#W.delete(Z)}catch{this.#$=[],this.#Z=!1,this.#z.clear()}},()=>{});#Q=new f1;#X="polling";#J=0;#U=0;#H=new Map;#q;#B;#N={};#Y=0;constructor($,Z){this.transport=$,this.key=Z}refresh($){if(this.#G.running)return this.#G.running;if(this.#X==="watching")return Promise.resolve();for(let[J,z]of W3)if($-z>=Y3)W3.delete(J);let Z=W3.get(this.key);if(Z!==void 0&&$-Z<Y3)return Promise.resolve();return W3.set(this.key,$),this.#G.request()}watchMode(){return this.#X}watch($={}){this.#J++;let Z=$.provider;if(Z===void 0)this.#U++;else this.#H.set(Z,(this.#H.get(Z)??0)+1);if(this.#J===1)this.#N=$,this.#O();let J=!1;return()=>{if(J)return;if(J=!0,Z===void 0)this.#U--;else{let z=(this.#H.get(Z)??1)-1;if(z>0)this.#H.set(Z,z);else this.#H.delete(Z)}if(--this.#J===0)this.#L()}}#L(){if(this.#B)(this.#N.clearTimeoutImpl??clearTimeout)(this.#B);this.#B=void 0;let $=this.#q;this.#q=void 0,$?.handle?.stop(),this.#X="polling"}#j($){this.#B=(this.#N.setTimeoutImpl??setTimeout)(()=>{if(this.#B=void 0,this.#J>0&&!this.#q)this.#O()},$),this.#B.unref?.()}#O(){let $=this.transport.watchUsage;if(!$){this.#X="fallback";return}this.#X="polling",this.#Q.restart();let Z={notices:0};this.#q=Z;let J;try{J=$.call(this.transport,(z)=>this.#A(Z,z))}catch(z){this.#_(Z,z);return}Z.handle=J,J.closed.then(()=>this.#_(Z,void 0),(z)=>this.#_(Z,z))}#A($,Z){if(this.#q!==$)return;if($.notices++,$.notices===1)this.#X="watching";if($.notices===2)this.#Y=0;let J=K5(Z);if(!J)this.#Q.restart();if(!(J?this.#Q.continuous(J):!1)||J?.provider===void 0||this.#U>0||this.#H.has(J.provider))this.#G.request()}#_($,Z){if(this.#q!==$)return;this.#q=void 0;let J=U5(Z);if(J==="unknown_method"||J==="usage_watch_limit"){this.#X="fallback";return}if($.notices>0){let z=Math.min(o3*2**Math.min(this.#Y,16),X3);this.#Y++,this.#X="polling",this.#j(z);return}if(this.#X="fallback",this.#G.request(),Z===void 0||J0(Z)==="unreachable")this.#j(X3)}current($,Z,J){for(let z of this.#$){if(z.provider!==$||typeof z.account!=="string"||z.account.trim()!==Z)continue;if(z.stale!==void 0||z.errorClass!==void 0||!X1(z.usage))continue;let X=typeof z.fetchedAt==="string"?Date.parse(z.fetchedAt):Number.NaN;if(!Number.isFinite(X)||J-X>=g7)continue;return{entry:z,context:{fetchedAt:X,...typeof z.source==="string"&&{source:z.source}}}}return}lookup($,Z,J){if(!this.#Z)return{miss:"unreachable"};let z=this.#$.find((Q)=>Q.provider===$&&typeof Q.account==="string"&&Q.account.trim()===Z),X=(z??this.#$.find((Q)=>Q.provider===$&&Q.account===void 0&&Q.errorClass!==void 0))?.errorClass;if(X==="upstream_failed")return{miss:"upstream-failed"};if(X==="credential_absent"||X==="credential_unusable"||X==="credential_rejected")return{miss:"credential"};if(X!==void 0)return{miss:"unreachable"};if(z){let Q=typeof z.fetchedAt==="string"?Date.parse(z.fetchedAt):Number.NaN;if(!X1(z.usage)||!Number.isFinite(Q))return{miss:"unreachable"};let W={entry:z,context:{fetchedAt:Q,...typeof z.source==="string"&&{source:z.source}}};if(z.stale!==void 0&&(!X1(z.stale)||z.stale.class!=="local_source_unavailable"))return{miss:"upstream-failed",reading:W};return J>=Q+g7||z.stale!==void 0?{miss:"stale",reading:W}:{reading:W}}if(this.#z.has($))return{miss:"absent"};let G=this.#W.get($)??J;return this.#W.set($,G),{miss:J-G>=H5?"unreachable":"cold"}}}function t3($,Z){let J=JSON.stringify([v7($.connectionFile),v7(Z)]),z=r3.get(J);if(!z)z={source:new w7($,J),refs:0},r3.set(J,z);z.refs++;let X=!1;return{source:z.source,release(){if(X)return;if(X=!0,--z.refs===0)r3.delete(J)}}}import{ClaustrumCredentialError as rW}from"@cortexkit/claustrum-client";import{appendFileSync as _5,chmodSync as I5,existsSync as J9,renameSync as i7,statSync as R5}from"node:fs";import{open as S5}from"node:fs/promises";import{dirname as T5,resolve as k5}from"node:path";import{randomUUID as c7}from"node:crypto";import{lstat as p7,readFile as d7,rename as q5,unlink as m7}from"node:fs/promises";import{tmpdir as F5}from"node:os";import{dirname as I0,join as B5,resolve as z0}from"node:path";var I=process.platform==="win32",h7=new Set;function e3($){if($?.reason==="io-error"){if($.win32Code===2||$.win32Code===3)return"ENOENT";if($.win32Code===80||$.win32Code===183)return"EEXIST"}return $?.code??"ERR_PRIVATE_FILE"}var u7;var j5="native-addon-unavailable";function l7($){return Object.assign(Error("Windows private-files native addon could not be loaded",{cause:$}),{code:"ERR_PRIVATE_FILES_UNAVAILABLE",reason:j5})}function V5($,Z){return Z instanceof $.PrivateFilesUnavailableError||Z?.code==="ERR_PRIVATE_FILES_UNAVAILABLE"}async function M5($){try{await $.verifyPrivatePath(B5(F5(),`.common-auth-private-files-probe-${c7()}`),"file")}catch(Z){if(V5($,Z))throw l7(Z)}}function G1(){return u7??=import("@cortexkit/private-files").then(async($)=>{if(I)await M5($);return $},($)=>{throw I?l7($):$}),u7}function a7($){return $?.reason==="io-error"&&($.win32Code===32||$.win32Code===303)}class h extends Error{path;stage;code;win32Code;reason;published=!1;durabilityConfirmed=!1;fileDurable=!1;attempts=0;elapsedMs=0;orphanPath;constructor($,Z,J){let z=J;super(z?.code==="ERR_PRIVATE_FILES_UNAVAILABLE"?`Private file refused at ${Z}: ${$}. The Windows native addon of @cortexkit/private-files could not be loaded, so owner-only access cannot be enforced and nothing was read or written. Reinstall the plugin so the private-files Windows prebuild for this architecture is present; Windows has no safe fallback to permission bits.`:a7(z)?`Private file busy at ${Z}: ${$}. Another process was replacing or deleting this file at the same moment (Windows error ${z.win32Code}).`:`Private file refused at ${Z}: ${$} (${z?.reason??z?.code??"io-error"}). Keep this file in a folder that only you, the system or administrators can change, such as a folder in your home directory. If other users could read the file before, sign in again to replace the credentials it held. On Windows the file must also be on a local drive that keeps Windows file permissions, such as NTFS.`,{cause:J});this.path=$,this.stage=Z,this.name="PrivateFileError",this.code=e3(z),this.win32Code=z?.win32Code,this.reason=z?.reason}}function x1($){return I&&$ instanceof h&&a7($)}async function t($,Z,J){try{return await J()}catch(z){if(z instanceof h)throw z;throw new h($,Z,z)}}var D5;async function M0($,Z){$=z0($),Z??=D5,await t($,"safe-parent",async()=>{let J=await(await G1()).verifySafeParent($,Z);if(J.ok===!1){if(J.reason==="io-error"||J.reason==="wrong-kind")await p7($);throw new h(J.level??J.path,"safe-parent",{...J,code:"ERR_PRIVATE_FILES_SECURITY"})}})}async function s($,Z,J=!1){if($=z0($),Z==="directory")return M0($);await t($,"verify",async()=>{let z=await G1(),X=await z.verifyOwnerOnly($),G=!1;if(!X.ok){let{reason:Q}=X.refusal;if(Q==="io-error")await z.verifyPrivatePath($,Z);if(J&&[z.EXTRA_ACE,z.NOT_PROTECTED,z.NULL_DACL,z.EMPTY_DACL].includes(Q))await M0(I0($)),await z.securePrivatePath($,Z),G=!0;else throw Object.assign(Error("Owner-only verification refused"),{reason:Q,code:"ERR_PRIVATE_FILES_SECURITY"})}if(await z.verifyPrivatePath($,Z),G&&!h7.has($))h7.add($),process.emitWarning(`Private permissions tightened: ${$}. This object may have been readable before; rotate credentials if needed.`,"PrivateFileMigration")})}async function U0($,Z=!1,J){$=z0($),await t($,"directory",async()=>{let z=await G1();try{return await p7($),await M0($,J)}catch(G){if(e3(G)!=="ENOENT")throw G}let X=I0($);if(X===$)throw Object.assign(Error("Missing root"),{code:"ENOENT"});await U0(X,!1,J);try{await z.createOwnerOnly($,{kind:"dir"})}catch(G){if(e3(G)!=="EEXIST")throw G}await M0($,J)})}async function G0($,Z=!1){if(!I)return d7($,"utf8");return(await N5($,Z)).toString("utf8")}async function N5($,Z=!1){if(!I)return d7($);if($=z0($),Z)await M0(I0($)),await s($,"file",!0);return t($,"read",async()=>(await G1()).readOwnerOnly($))}async function Q1($,Z){await M0(I0(z0($))),await t($,"create",async()=>{await(await G1()).createPrivateFile(z0($),Z)})}async function s7($){await M0(I0(z0($))),await t($,"directory-create",async()=>{await(await G1()).createOwnerOnly(z0($),{kind:"dir"})})}async function Z9($,Z,J={}){$=z0($),Z=z0(Z);let z=J.now??(()=>performance.now()),X=z(),G=J.deadline??1/0,Q,W=[0,10,20,40,80,100],Y,K=0;for(let H of W){let F=Math.min(Q??1/0,G);if(z()>=F)break;if(H)await(J.sleep??((M)=>new Promise((P)=>setTimeout(P,M))))(Math.min(H,Math.max(0,F-z())));if(z()>=F)break;let B=z();if(await J.beforeRename?.(),Q!==void 0)Q+=z()-B;if(z()>=G)break;K++;try{return await(J.rename??q5)($,Z),{attempts:K,elapsedMs:z()-X}}catch(M){Y??=M;let P=M;if(!(P.win32Code!==void 0?P.win32Code===32||P.win32Code===33:["EBUSY","EPERM","EACCES"].includes(P.code??"")&&!P.reason))break;Q??=z()+500}}let q=new h(Z,"rename",Y??Object.assign(Error("Publication deadline expired"),{code:"ETIMEDOUT"}));throw q.attempts=K,q.elapsedMs=z()-X,q}async function W1($,Z,J={}){$=z0($),await U0(I0($));try{await s($,"file",!0)}catch(K){if(K.code!=="ENOENT")throw K}let z=z0(J.stagePath??`${$}.${c7()}.tmp`);if(I0(z)!==I0($))throw new h($,"stage-directory",{code:"EXDEV"});let X=!1,G=!1,Q={attempts:0,elapsedMs:0},W="stage-create",Y=(K)=>{try{J.onOutcome?.({path:$,stage:K?.stage??"published",published:G,fileDurable:G,durabilityConfirmed:!1,attempts:K?.attempts??Q.attempts,elapsedMs:K?.elapsedMs??Q.elapsedMs,...K&&{code:K.code,win32Code:K.win32Code}})}catch{}};try{if(await Q1(z,Z),X=!0,W="before-rename",Q=await Z9(z,$,J),X=!1,G=!0,W="published-callback",J.onRenamed?.(),W="published-verify",await s($,"file"),J.durable&&J.durability!=="file-only-on-windows")throw new h($,"directory-sync-unsupported",{code:"ENOTSUP"});Y()}catch(K){let q=K instanceof h?K:new h($,W,K);if(q.published=G,q.fileDurable=G,G)Object.assign(q,Q);if(X){try{await m7(z)}catch{q.orphanPath=z}X=!1}throw Y(q),q}finally{if(X)await m7(z).catch(()=>{})}}var L5=/^(authorization|x-api-key|cookie|set-cookie|refresh|access|token)$/i,P5=/\b(Bearer\s+[\w.-]+|sk-[\w-]+|eyJ[\w.-]+)\b|ckh_[A-Za-z0-9_-]{20,}/g;function O5($){return $ instanceof Error||Object.prototype.toString.call($)==="[object Error]"}function Y1($={}){let Z=[P5,...$.extraValuePatterns??[]].map((G)=>new RegExp(G.source,G.flags.includes("g")?G.flags:`${G.flags}g`));function J(G){let Q=G.toLowerCase().replace(/[-_]/g,"");return L5.test(G)||Q.includes("apikey")||Q.endsWith("secret")||Q.endsWith("password")||Q.endsWith("token")&&!Q.endsWith("tokens")||!!$.extraSecretKeys?.(Q)}function z(G){let Q=G,W=[["name",G.name],["message",G.message],["stack",G.stack]];for(let K of["code","status","cause"])if(Q[K]!==void 0)W.push([K,Q[K]]);let Y=new Set(W.map(([K])=>K));for(let K of Object.entries(G))if(!Y.has(K[0]))W.push(K);return W}function X(G,Q,W,Y=0){if(typeof G==="string")return Z.reduce((K,q)=>K.replace(q,"***REDACTED***"),G);if(!G||typeof G!=="object")return G;if(W.has(G))return"[Circular]";W.add(G);try{if(Array.isArray(G))return G.map((H)=>X(H,Q,W,Y));let K=O5(G);if(K&&Y>=8)return"[Truncated]";let q=K?Y+1:Y;return Object.fromEntries((K?z(G):Object.entries(G)).map(([H,F])=>[H,Q&&J(H)?"***REDACTED***":X(F,Q,W,q)]))}finally{W.delete(G)}}return{redact:(G)=>X(G,!0,new WeakSet),redactStrings:(G)=>X(G,!1,new WeakSet)}}var n7=Y1(),A5=n7.redact,C5=n7.redactStrings;var H3={error:0,warn:1,info:2,debug:3,trace:4},r7=5242880,t7=3;function z9($){try{I5($,384)}catch{}}function E5($){try{if(!(J9($)&&R5($).size>=r7))return;for(let J=t7-1;J>=1;J--)if(J9(`${$}.${J}`)){let z=`${$}.${J+1}`;i7(`${$}.${J}`,z),z9(z)}let Z=`${$}.1`;i7($,Z),z9(Z)}catch{}}async function D0($){let{file:Z,handle:J}=$;if($.file=void 0,$.handle=void 0,Z&&J)await t(Z,"log-close",()=>J.close())}async function o7($,Z){await U0(T5(Z));try{await s(Z,"file",!0)}catch(J){if(J.code!=="ENOENT")throw J;try{await Q1(Z,"")}catch(z){if(z.code!=="EEXIST")throw z;await s(Z,"file",!0)}}return $.handle=await t(Z,"log-open",()=>S5(Z,"a")),$.file=Z,$.handle}async function b5($,Z,J){Z=k5(Z);try{if($.file!==Z)await D0($);let z=$.handle??await o7($,Z);if((await t(Z,"log-stat",()=>z.stat())).size>=r7){await D0($);for(let G=t7-1;G>=0;G--){let Q=G===0?Z:`${Z}.${G}`,W=`${Z}.${G+1}`;try{await s(Q,"file",!0)}catch(Y){if(Y.code==="ENOENT")continue;throw Y}try{await s(W,"file",!0)}catch(Y){if(Y.code!=="ENOENT")throw Y}await Z9(Q,W),await s(W,"file")}z=await o7($,Z)}await t(Z,"log-append",()=>z.appendFile(J,"utf8"))}catch(z){throw await D0($).catch(()=>{}),z}}function f5($){try{return` ${JSON.stringify($)}`}catch{return" [unserializable]"}}function x5($){let Z,J,z,X=Y1(),G,Q=[],W,Y=Promise.resolve(),K,q={};function H(V){let U=Y.then(V);return Y=U.catch((N)=>{K=N}),U}function F(V){if(I&&V.file!==Z)H(()=>D0(q)).catch(()=>{});Z=V.file,J=V.level,X=Y1(V),G=V.captureSink}function B(V){if(V===void 0||V in H3)z=V}function M(){if(Z===void 0)return;return(typeof Z==="function"?Z():Z)||void 0}function P(){if(z)return z;let V=typeof J==="function"?J():J;if(V&&V in H3)return V;return"info"}function O(V=!0){if(W)clearTimeout(W),W=void 0;if(!Q.length){if(I)return H(async()=>{if(V)await D0(q);if(K)throw K});return}let U;try{U=M()}catch{if(Q=[],I&&V)return H(()=>D0(q));return}let N=Q.join("");if(Q=[],!U){if(I&&V)return H(()=>D0(q));return}if(I)return H(async()=>{try{await b5(q,U,N)}finally{if(V)await D0(q)}});try{if(E5(U),J9(U))z9(U);_5(U,N,{encoding:"utf8",mode:384})}catch{}}function _(){if(!W)W=setTimeout(()=>{W=void 0;let V=O(!1);if(V instanceof Promise)V.catch(()=>{})},500)}function T(V,U,N,C){if(Z===void 0&&G===void 0)return;try{if(H3[U]>H3[P()])return;let v=X.redactStrings(N),E;try{E=X.redact(C)}catch{E="[unserializable]"}let g=`[${new Date().toISOString()}] ${U.toUpperCase()} [${V}] ${v}`+(C===void 0?"":f5(E))+`
|
|
3
3
|
`;try{G?.({channel:V,level:U,message:v,data:E})}catch{}if(Z===void 0)return;if(Q.push(g),Q.length>=50){let $0=O(!1);if($0 instanceof Promise)$0.catch(()=>{})}else _()}catch{}}function w(V){return{error:(U,N)=>T(V,"error",U,N),warn:(U,N)=>T(V,"warn",U,N),info:(U,N)=>T(V,"info",U,N),debug:(U,N)=>T(V,"debug",U,N),trace:(U,N)=>T(V,"trace",U,N)}}function c(){if(I)H(()=>D0(q)).catch(()=>{});if(K=void 0,Q=[],W)clearTimeout(W),W=void 0;Z=void 0,J=void 0,z=void 0,X=Y1(),G=void 0}if($)F($);return{configure:F,createLogger:w,setLogLevel:B,flushLogs:O,reset:c}}var y5=x5();function X0($){return y5.createLogger($)}function v0($){let Z=new AbortController,J=[],z=!1,X=()=>{if(z)return;z=!0;for(let{source:W,listener:Y}of J)W.removeEventListener("abort",Y);J.length=0},G=(W)=>{if(z||Z.signal.aborted)return;Z.abort(W),X()},Q=$.find((W)=>W.aborted);if(Q)return Z.abort(Q.reason),{signal:Z.signal,dispose:X};for(let W of $){if(Z.signal.aborted)break;let Y=()=>G(W.reason);if(J.push({source:W,listener:Y}),W.addEventListener("abort",Y,{once:!0}),W.aborted)G(W.reason)}return{signal:Z.signal,dispose:X}}import{channel as R2}from"node:diagnostics_channel";import{ClaustrumCredentialError as N9}from"@cortexkit/claustrum-client";import{createHash as F2,randomBytes as B2,randomUUID as j2}from"node:crypto";import{constants as V4}from"node:fs";import{chmod as V2,mkdir as M2,open as P4,readFile as H9,realpath as D2,rename as N2,stat as O4,unlink as U9}from"node:fs/promises";import{basename as L2,dirname as u0,extname as EG,isAbsolute as bG,join as P2,resolve as fG}from"node:path";import{ClaustrumCredentialError as A4,ClaustrumClient as yG,writeEnrollmentTokenFile as O2}from"@cortexkit/claustrum-client";import{lstat as v5,stat as g5}from"node:fs/promises";import{resolve as w5}from"node:path";async function m5($,Z){try{let J=await Z($);return J.isFile()?J:void 0}catch(J){return J.code==="ENOENT"?"absent":void 0}}function h5($,Z){if($==="absent"||Z==="absent")return $===Z;return $.dev===Z.dev&&$.ino===Z.ino&&$.size===Z.size&&$.mtimeMs===Z.mtimeMs&&$.ctimeMs===Z.ctimeMs}class g0{#$;#Z=new Map;constructor($={}){this.#$=$.followSymlinks?(Z)=>($.stat??g5)(Z):(Z)=>($.lstat??v5)(Z)}async read($,Z,J){let z=$.map((K)=>w5(K)),X=JSON.stringify(z),G=await Promise.all(z.map((K)=>m5(K,this.#$))),Q=G.every((K)=>K!==void 0)?G:void 0,W=this.#Z.get(X);if(Q&&W&&Q.every((K,q)=>{let H=W.identities[q];return H!==void 0&&h5(K,H)}))return J?.(Q),W.value;this.#Z.delete(X);let Y=await Z(z);if(Q){if(this.#Z.size>=64){let K=this.#Z.keys().next().value;if(K!==void 0)this.#Z.delete(K)}this.#Z.set(X,{identities:Q,value:Y})}return Y}}import{randomUUID as e7}from"node:crypto";import{mkdir as u5,open as $4,rename as c5,rm as p5}from"node:fs/promises";import{dirname as Z4}from"node:path";class K3 extends Error{constructor($){super("file or directory sync failed",{cause:$});this.name="AtomicSyncError"}}async function H1($,Z,J={}){await J4($,Z,J)}async function J4($,Z,J,z){if(I)return W1($,J.serialize?J.serialize(Z):`${JSON.stringify(Z,null,2)}
|
|
4
4
|
`,{beforeRename:J.beforeRename,stagePath:`${$}.${(J.stageName??e7)()}.tmp`,onRenamed:z,durable:J.durable,durability:J.durability,onOutcome:J.onOutcome});await u5(Z4($),{recursive:!0});let X=`${$}.${(J.stageName??e7)()}.tmp`,G,Q=!1;try{if(G=await $4(X,"wx",384),Q=!0,await G.writeFile(J.serialize?J.serialize(Z):`${JSON.stringify(Z,null,2)}
|
|
5
5
|
`,"utf8"),await G.chmod(384),J.durable)try{await G.sync()}catch(W){throw new K3(W)}if(await G.close(),G=void 0,await J.beforeRename?.(),await c5(X,$),Q=!1,z?.(),J.durable){let W=await $4(Z4($),"r");try{await W.sync()}catch(Y){throw new K3(Y)}finally{await W.close()}}}finally{if(await G?.close().catch(()=>{}),Q)await p5(X,{force:!0}).catch(()=>{})}}var d5=Object.freeze({sidebar:Object.freeze({name:"sidebar-write",ttlMs:1e4,timeoutMs:15000,renew:!0}),preferences:Object.freeze({name:"preferences",ttlMs:1e4,timeoutMs:2000,renew:!0})});import{randomUUID as g1}from"node:crypto";import{link as n5,lstat as S0,mkdir as X4,open as q3,readdir as i5,readFile as G4,rename as Q4,rm as q1,stat as v1,unlink as o5}from"node:fs/promises";import{basename as r5,dirname as U3,join as Q9}from"node:path";import{resolve as z4}from"node:path";class y1 extends Error{path;code="ENOENT";constructor($,Z){super(`Lock record disappeared: ${$}`,{cause:Z});this.path=$}}function w0($,Z){return $ instanceof h&&$.reason==="io-error"&&$.win32Code===5&&($.stage==="read"||$.stage==="verify")&&Z.some((J)=>z4(J)===$.path)}function K1($,Z,J){return $ instanceof h&&$.reason==="io-error"&&$.win32Code===5&&$.stage===J&&Z.some((z)=>z4(z)===$.path)}async function q0($,Z){try{return await Z()}catch(J){if(!w0(J,[$]))throw J;try{return await Z()}catch(z){if(z.code==="ENOENT")throw new y1($,J);throw J}}}import{join as l5,resolve as a5}from"node:path";function U1($,Z){return`${$}.${Z}.lock`}class R0 extends Error{details;constructor($){super(`Timed out acquiring ${$.name} lock for ${$.target}`);this.name="LockContentionError",this.details=$}}class N0 extends Error{details;constructor($){super(`Lost ${$.name} lock for ${$.target}`);this.name="LockOwnershipError",this.details=$}}function s5($,Z,J){let z=a5(U1(Z,J)),X=[z,l5(z,"owner.json")];return(x1($)||w0($,X))&&($.stage==="read"||$.stage==="verify")&&X.includes($.path)||I&&(K1($,[z],"create")||K1($,[`${z}.evicting`],"directory-create"))}async function X9($,Z,J){let z=performance.now(),X;for(;;){Z.signal?.throwIfAborted();let G;try{G=await L0({path:$,name:Z.name,ttlMs:Z.ttlMs,renew:Z.renew??!1,...Z.onStep?{onStep:Z.onStep}:{},...Z.onRenewalTimer?{onRenewalTimer:Z.onRenewalTimer}:{}}),X=void 0}catch(W){if(!s5(W,$,Z.name))throw W;G=null,X??=W}if(G)try{return Z.signal?.throwIfAborted(),await J(G)}finally{await G.release(Z.signal)}let Q=Z.timeoutMs-(performance.now()-z);if(Q<=0){if(X)throw X;throw new R0({target:$,name:Z.name,timeoutMs:Z.timeoutMs})}await new Promise((W)=>setTimeout(W,Math.min(25,Math.ceil(Q))))}}var F1;async function t5($,Z){let J=`${$}.${g1()}.tmp`,z;try{z=await q3(J,"wx",384);try{if(F1?.beforeWrite)await F1.beforeWrite(J);await z.writeFile(Z,"utf8")}finally{await z.close()}try{if(F1?.beforeLink)await F1.beforeLink(J,$);await n5(J,$)}catch(X){let G=X.code;if(G!=="EPERM"&&G!=="ENOTSUP"&&G!=="EOPNOTSUPP"&&G!=="EXDEV")throw X;await U4($,Z)}}finally{if(z)await q1(J,{force:!0}).catch(()=>{})}}async function U4($,Z){let J=await q3($,"wx",384),z;try{z=await J.stat()}catch{z=void 0}try{if(F1?.beforeWrite)await F1.beforeWrite($);await J.writeFile(Z,"utf8")}catch(X){try{let G=await S0($).catch(()=>{return});if(z&&G&&G.dev===z.dev&&G.ino===z.ino)await q1($,{force:!0}).catch(()=>{})}catch{}throw X}finally{await J.close()}}var q4=/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,e5=600000,$2=256,Z2=4096,W4=new Set,Y4=new Set,J2;function z2($,Z){let J=`${Z}.`,z=".tmp";if(!$.startsWith(J)||!$.endsWith(".tmp"))return!1;return q4.test($.slice(J.length,-4))}function F4($,Z){return $.dev===Z.dev&&$.ino===Z.ino&&$.size===Z.size&&$.mtimeMs===Z.mtimeMs&&$.birthtimeMs===Z.birthtimeMs}async function H4($){let Z=await S0($);if(!Z.isFile()||Z.isSymbolicLink())return;if(Z.size>Z2)return;let J=await q3($,"r"),z;try{if(!F4(Z,await J.stat()))return;z=await J.readFile("utf8")}finally{await J.close()}let X;try{X=JSON.parse(z)}catch{return}if(!X||typeof X!=="object"||Array.isArray(X))return;let G=Object.keys(X).sort();if(G.length!==2||G[0]!=="expiresAt"||G[1]!=="ownerId")return;let{ownerId:Q,expiresAt:W}=X;if(typeof Q!=="string"||!q4.test(Q))return;if(typeof W!=="number"||!Number.isFinite(W))return;return{identity:Z,expiresAt:W}}async function X2($,Z,J){let z=U3($),X=r5($),G=J2,W=(await(G?.readdir??i5)(z)).filter((K)=>z2(K,X)).slice(0,$2),Y=Math.max(Number.isFinite(Z)?Z:0,e5);for(let K of W){let q=Q9(z,K);try{if(J()-(await S0(q)).mtimeMs<Y)continue;let H=await H4(q);if(!H||!(H.expiresAt<J()-Y))continue;if(G?.beforeUnlink)await G.beforeUnlink(q);let F=await H4(q);if(!F||!F4(H.identity,F.identity)||!(F.expiresAt<J()-Y))continue;await(G?.unlink??o5)(q)}catch{}}}function G2($,Z,J){if(W4.has($))return;W4.add($);let z=Promise.resolve().then(()=>X2($,Z,J)).catch(()=>{});Y4.add(z),z.finally(()=>Y4.delete(z))}var Q2=globalThis.setTimeout.bind(globalThis),W2=globalThis.clearTimeout.bind(globalThis);function B4($){let Z=$?.code;return Z==="ENOENT"||!I&&(Z==="EINVAL"||Z==="ENOTDIR")}var K4;function G9($,Z){if($.dev!==Z.dev||$.ino!==Z.ino)return!1;if($.ino===0&&$.birthtimeMs!==Z.birthtimeMs)return!1;return!0}var Y2=1000;function L0($){return H2({...$,now:Date.now})}async function H2($){let Z=U1($.path,$.name),J=Q9(Z,"owner.json"),z=g1(),X=$.now??Date.now,G=null,Q=!1,W=!1,Y,K,q=new Promise((j)=>{K=j});function H(j){try{let D=$.onRenewalTimer?.(j);if(D&&(typeof D==="object"||typeof D==="function")&&"then"in D&&typeof D.then==="function")Promise.resolve(D).catch(()=>{})}catch{}}function F(){if(!G)return;W2(G),G=null,H("cancelled")}function B(j,D){if(Y||Q)return;Y=Object.freeze({reason:j,expectedOwnerId:z,...typeof D?.ownerId==="string"?{observedOwnerId:D.ownerId}:{},...typeof D?.expiresAt==="number"?{observedExpiresAt:D.expiresAt}:{}}),F(),K(Y)}let M,P=null,O=`${Z}.evicting`,_=Q9(O,"owner.json"),T=g1(),w=5000,c=8;function V(j){return I&&(K1(j,[Z],"create")||K1(j,[O],"directory-create"))}async function U(){if(I)try{return JSON.parse(await q0(Z,()=>G0(Z,!0)))}catch(j){if(j.code!=="EISDIR"&&j.reason!=="wrong-kind")throw j;return await q0(Z,()=>s(Z,"directory",!0)),JSON.parse(await q0(J,()=>G0(J,!0)))}try{return JSON.parse(await G4(Z,"utf8"))}catch(j){if(j.code!=="EISDIR")throw j;return JSON.parse(await G4(J,"utf8"))}}async function N(){if(I){let R=await U(),S=Number(R?.expiresAt)-X();await W1(Z,`${JSON.stringify({ownerId:z,expiresAt:X()+$.ttlMs})}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import{randomUUID as E}from"node:crypto";import{mkdir as g,readFile as y,rename as S,rm as O,rmdir as w,stat as D,unlink as m,writeFile as b}from"node:fs/promises";import{tmpdir as d}from"node:os";import{dirname as v,join as f}from"node:path";import{formatQuota as c,isQuotaStale as s,logger as C,quotaDisplayProjection as I,quotaWindowParts as u,resolveClaudeModelCapabilities as i}from"@cortexkit/anthropic-auth-core";var n="OPENCODE_ANTHROPIC_AUTH_SIDEBAR_STATE_FILE",l=f(d(),"opencode-anthropic-auth"),o=f(l,"sidebar-state.json");function P(){return process.env[n]||o}var H={main:{quota:null},fallbacks:[],route:"main",relay:null,fastMode:!1,lastUpdated:0};function Q(J){return J!==null&&typeof J==="object"&&!Array.isArray(J)}function z(J){return typeof J==="number"&&Number.isFinite(J)}function r(J){if(!Q(J))return;let Z=Number(J.count),V=Number(J.inputTokens),X=Number(J.outputTokens),x=Number(J.since);if(![Z,V,X,x].every(Number.isFinite)||Z<0||V<0||X<0||x<0)return;return{count:Math.floor(Z),inputTokens:Math.floor(V),outputTokens:Math.floor(X),since:Math.floor(x)}}function a(J){if(!Q(J))return;if(typeof J.id!=="string"||!J.id.trim())return;if(typeof J.label!=="string"||!J.label.trim())return;let Z={id:J.id.trim(),label:J.label.trim()};if(J.nextDueAt===null)Z.nextDueAt=null;else if(z(J.nextDueAt))Z.nextDueAt=J.nextDueAt;if(J.lastPrimedAt===null)Z.lastPrimedAt=null;else if(z(J.lastPrimedAt))Z.lastPrimedAt=J.lastPrimedAt;if(J.lastResult==="ok"||J.lastResult==="error"||J.lastResult==="skipped")Z.lastResult=J.lastResult;let V=r(J.usage);if(V)Z.usage=V;if(z(J.estimatedCostUsd))Z.estimatedCostUsd=J.estimatedCostUsd;return Z}function t(J){if(!Q(J))return;if(typeof J.enabled!=="boolean")return;let Z=Array.isArray(J.accounts)?J.accounts.map(a).filter((V)=>V!=null):[];return{enabled:J.enabled,accounts:Z}}function q(J){if(!Q(J))return;let Z=Number(J.usedPercent),V=Number(J.remainingPercent);if(!Number.isFinite(Z)||!Number.isFinite(V))return;return{usedPercent:Z,remainingPercent:V,...typeof J.resetsAt==="string"&&{resetsAt:J.resetsAt},...z(J.checkedAt)&&{checkedAt:J.checkedAt}}}function R(J){if(!Q(J))return null;let Z={};if(z(J.checkedAt))Z.checkedAt=J.checkedAt;let V=q(J.five_hour),X=q(J.seven_day);if(V)Z.five_hour=V;if(X)Z.seven_day=X;if(Array.isArray(J.scoped)){let x=J.scoped.map((Y)=>{if(!Q(Y))return;let G=q(Y);if(!G)return;if(typeof Y.id!=="string"||!Y.id.trim())return;if(typeof Y.title!=="string"||!Y.title.trim())return;if(typeof Y.modelName!=="string"||!Y.modelName.trim())return;let $=typeof Y.modelId==="string"&&Y.modelId.trim()?Y.modelId.trim():void 0;return{...G,id:Y.id.trim(),title:Y.title.trim(),...$&&{modelId:$},modelName:Y.modelName.trim()}}).filter((Y)=>Y!=null);Z.scoped=x}if(Q(J.extraUsage)){let x=A(J.extraUsage.used),Y=A(J.extraUsage.limit);if(x&&Y&&typeof J.extraUsage.exhausted==="boolean")Z.extraUsage={used:x,limit:Y,...typeof J.extraUsage.utilizationPercent==="number"&&Number.isFinite(J.extraUsage.utilizationPercent)&&{utilizationPercent:J.extraUsage.utilizationPercent},...typeof J.extraUsage.severity==="string"&&{severity:J.extraUsage.severity},exhausted:J.extraUsage.exhausted}}if(typeof J.bindingWindow==="string"&&J.bindingWindow.trim())Z.bindingWindow=J.bindingWindow.trim();if(typeof J.fallbackAdvised==="boolean")Z.fallbackAdvised=J.fallbackAdvised;return Object.keys(Z).length?Z:null}function A(J){if(!Q(J))return;if(!Number.isInteger(J.amountMinor)||typeof J.currency!=="string"||!/^[A-Za-z]{3}$/.test(J.currency.trim())||!Number.isInteger(J.exponent)||J.exponent<0||J.exponent>20)return;return{amountMinor:J.amountMinor,currency:J.currency.trim(),exponent:J.exponent}}function k(J){if(!Q(J))return{...H};let Z={quota:null};if(Q(J.main)){let $=J.main;if(Z.quota=R($.quota),typeof $.enabled==="boolean")Z.enabled=$.enabled;if(typeof $.stateLine==="string")Z.stateLine=$.stateLine;if($.quotaDated===!0)Z.quotaDated=!0;if(typeof $.tierLabel==="string"&&$.tierLabel.trim())Z.tierLabel=$.tierLabel.trim();if(typeof $.quotaBackedOff==="boolean")Z.quotaBackedOff=$.quotaBackedOff;if(z($.quotaBackoffUntil))Z.quotaBackoffUntil=$.quotaBackoffUntil;if(typeof $.refreshBackedOff==="boolean")Z.refreshBackedOff=$.refreshBackedOff;if(z($.refreshBackoffUntil))Z.refreshBackoffUntil=$.refreshBackoffUntil}let V=Array.isArray(J.fallbacks)?J.fallbacks.filter(Q).filter(($)=>typeof $.id==="string").map(($)=>({id:$.id,...typeof $.label==="string"&&{label:$.label},quota:R($.quota),enabled:typeof $.enabled==="boolean"?$.enabled:!1,...typeof $.stateLine==="string"&&{stateLine:$.stateLine},...$.quotaDated===!0&&{quotaDated:!0},needsReauth:typeof $.needsReauth==="boolean"?$.needsReauth:!1,...$.vaultReauth===!0&&{vaultReauth:!0},...$.vaultServed===!0&&{vaultServed:!0},...typeof $.custodyState==="string"&&{custodyState:$.custodyState},...typeof $.tierLabel==="string"&&$.tierLabel.trim()&&{tierLabel:$.tierLabel.trim()}})):[],X=null;if(Q(J.relay)){let $=J.relay;if(typeof $.enabled==="boolean"&&typeof $.transport==="string")X={enabled:$.enabled,transport:$.transport}}let x;if(Q(J.cacheKeep)){let $=J.cacheKeep;if(typeof $.enabled==="boolean")x={enabled:$.enabled,...typeof $.window==="string"&&{window:$.window},...z($.trackedSessions)&&{trackedSessions:$.trackedSessions}}}let Y=Array.isArray(J.fableRecoveries)?J.fableRecoveries.filter(Q).flatMap(($)=>{if(typeof $.sessionId!=="string"||$.mode!=="opus"&&$.mode!=="fable"&&$.mode!=="server"||typeof $.remaining!=="number"||!Number.isFinite($.remaining)||typeof $.changedAt!=="number"||!Number.isFinite($.changedAt))return[];return[{sessionId:$.sessionId,mode:$.mode,remaining:Math.max(0,Math.floor($.remaining)),changedAt:$.changedAt,...typeof $.requestedModelId==="string"&&{requestedModelId:$.requestedModelId},...typeof $.targetModelId==="string"&&{targetModelId:$.targetModelId}}]}):[],G=t(J.prime);return{main:Z,fallbacks:V,...typeof J.activeId==="string"&&{activeId:J.activeId},route:typeof J.route==="string"?J.route:H.route,relay:X,fastMode:typeof J.fastMode==="boolean"?J.fastMode:H.fastMode,...x&&{cacheKeep:x},...G&&{prime:G},...Y.length>0&&{fableRecoveries:Y},lastUpdated:z(J.lastUpdated)?J.lastUpdated:0}}var W=Promise.resolve(),e=1000,JJ=2000,ZJ=5,$J=15,M=new Map;function WJ(J,Z=P()){if(J)M.set(Z,J);else M.delete(Z)}function U(J){return M.get(J)}var p=null;function UJ(J){p=J}function qJ(){return p}function VJ(J){return new Promise((Z)=>setTimeout(Z,J))}async function F(J){let Z=`${J}.lock`,V=U(J),X=V?.lockBudgetMs??e,x=V?.lockRetryMinMs??ZJ,Y=V?.lockRetryMaxMs??$J,G=Date.now()+X;while(!0){try{await g(Z);let K=E(),j=f(Z,K);return await b(j,"",{encoding:"utf8",mode:384,flag:"wx"}),await V?.onLockAcquired?.(Z),{ownsLock:async()=>{try{return await D(j),!0}catch{return!1}},release:async()=>{try{await m(j)}catch{return}await V?.beforeReleaseDirectoryRemoval?.(Z),await w(Z).catch(()=>{})}}}catch(K){if(K.code!=="EEXIST")return C.trace("sidebar","state lock unavailable; write skipped",{stateFile:J,error:K instanceof Error?K.message:String(K)}),null}try{let K=await D(Z);if(Date.now()-K.mtimeMs>JJ){await V?.afterStaleLockStat?.(Z);let j=`${Z}.evict-${process.pid}-${E()}`;try{await S(Z,j)}catch(N){if(N.code==="ENOENT")continue;throw N}await V?.onStaleLockClaimed?.(Z),await O(j,{recursive:!0,force:!0}).catch(()=>{});continue}}catch(K){if(K.code==="ENOENT")continue;return C.trace("sidebar","state lock inspection failed; write skipped",{stateFile:J,error:K instanceof Error?K.message:String(K)}),null}let $=G-Date.now();if($<=0)return C.warn("sidebar","lock budget exhausted, write skipped",{stateFile:J,budgetMs:X}),null;let B=x+Math.floor(Math.random()*(Y-x+1));await VJ(Math.min(B,$))}}async function LJ(J){return(await F(J))?.release??null}async function XJ(J,Z,V){let X=U(J),x=`${J}.${process.pid}.${E()}.tmp`;await b(x,JSON.stringify(Z),{encoding:"utf8",mode:384});try{if(!await V())return C.trace("sidebar","state lock lost before rename; write aborted",{stateFile:J}),await O(x,{force:!0}).catch(()=>{}),"lock-lost-before-rename";if(await X?.beforeRename?.(J,x),!await V())return C.trace("sidebar","state lock lost before rename; write aborted",{stateFile:J}),await O(x,{force:!0}).catch(()=>{}),"lock-lost-before-rename";if(await S(x,J),await U(J)?.afterRename?.(J),!await V())return"lock-lost-after-rename";return"written"}catch(Y){throw await O(x,{force:!0}).catch(()=>{}),Y}}async function T(J=P()){try{let Z=await y(J,"utf8");return k(JSON.parse(Z))}catch{return H}}async function EJ(J,Z=P(),V={}){return W=W.then(async()=>{await g(v(Z),{recursive:!0});for(let X=0;X<2;X++){let x=X===1,Y=await F(Z);if(!Y){if(x)C.warn("sidebar","post-rename repair lock unavailable; write skipped",{stateFile:Z});return}let G=J,$;try{if(V.routingAuthoritative===!1){let B=await T(Z),K=await V.resolvePreservedRouting?.(B);if(K){let j=K.state??J;G={...j,activeId:K.activeId,route:K.route,lastUpdated:Math.max(j.lastUpdated,B.lastUpdated)}}await U(Z)?.afterMergeRead?.(Z)}else if(x){let B=await T(Z);G={...B,activeId:J.activeId,route:J.route,relay:J.relay,fastMode:J.fastMode,cacheKeep:J.cacheKeep,lastUpdated:Math.max(B.lastUpdated,J.lastUpdated)}}G=k(G),$=await XJ(Z,G,Y.ownsLock)}finally{await Y.release()}if($==="lock-lost-after-rename"){if(x){C.warn("sidebar","post-rename repair lost lock; write skipped",{stateFile:Z});return}C.warn("sidebar","state lock lost after rename; repairing write",{stateFile:Z});continue}if($==="lock-lost-before-rename")return;V.onRoutingResolved?.({activeId:G.activeId,route:G.route});return}}).catch(()=>{V.onError?.()}),W}async function MJ(){return W}function YJ(J){let Z=J.activeId;if(Z&&Z!=="main"){let V=J.fallbacks?.find((X)=>X.enabled&&X.id===Z);if(V)return{id:V.id,name:V.label??V.id,quota:V.quota,...V.stateLine&&{stateLine:V.stateLine,quotaDated:V.quotaDated}}}return{id:"main",name:"main",quota:J.main?.quota??null,...J.main?.stateLine&&{stateLine:J.main.stateLine,quotaDated:J.main.quotaDated}}}function L(J){let Z=i(J);if(Z?.id==="claude-fable-5-2"||Z?.id==="claude-mythos-5-2")return Z.name.replace(/^Claude /,"");if(J==="claude-mythos-5-1"||J?.startsWith("claude-mythos-5-1-"))return"Mythos 5.1";if(J==="claude-fable-5-1"||J?.startsWith("claude-fable-5-1-"))return"Fable 5.1";if(J==="claude-fable-5"||J?.startsWith("claude-fable-5-"))return"Fable 5";if(J==="claude-opus-5-5"||J?.startsWith("claude-opus-5-5-"))return"Opus 5.5";if(J==="claude-opus-5"||J?.startsWith("claude-opus-5-"))return"Opus 5";if(J==="claude-opus-4-8"||J?.startsWith("claude-opus-4-8-"))return"Opus 4.8";return J??"Fable 5"}function h(J){return new Date(J).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function xJ(J){if(J===0)return"0";if(J<0.0001)return J.toExponential(2);return J.toFixed(Math.min(6,Math.max(0,4)))}function fJ(J,Z=Date.now()){if(J.lastResult==="error")return{text:"err",hasError:!0};if(J.lastResult==="skipped")return{text:"skip",hasError:!1};if(J.nextDueAt&&J.nextDueAt>Z)return{text:h(J.nextDueAt),hasError:!1};if(J.lastPrimedAt)return{text:`primed ${h(J.lastPrimedAt)} ✓`,hasError:!1};if(J.usage?.count)return{text:`✓ ${J.usage.count} ≈ $${xJ(J.estimatedCostUsd??0)}`,hasError:!1};return{text:"—",hasError:!1}}function PJ(J,Z){let V=J.fableRecoveries?.find((X)=>X.sessionId===Z);if(!V)return;if(V.mode==="fable")return`${L(V.requestedModelId)} · restored`;if(V.mode==="server")return`${L(V.requestedModelId)}→${L(V.targetModelId)} · safety`;return`Opus 4.8 · ${V.remaining} left`}function _J(J,Z=10){if(Z<=0)return"";let V=J;if(Bun.stringWidth(V)>Z){V="";for(let X of J){if(Bun.stringWidth(V+X)>Z-1)break;V+=X}V+="…"}return V+" ".repeat(Math.max(0,Z-Bun.stringWidth(V)))}function GJ(J,Z=Date.now()){let V=J?.scoped??[];if(!V.length)return[];let{windows:X}=u(I({scoped:V},Z),{now:Z});return V.map((x)=>X.find((Y)=>Y.kind==="window"&&Y.name===x.title)?.short||x.title)}function DJ(J,Z=Date.now()){return Math.max(2,...J.flatMap((V)=>GJ(V,Z).map((X)=>Bun.stringWidth(X))))}var KJ=3;function RJ(J){let{width:Z,labelWidth:V,barWidth:X,figure:x,reset:Y}=J,G={barCells:X,reset:Y||void 0};if(Z===void 0)return G;let $=(j)=>V+1+(j.barCells>0?j.barCells+1:0)+Bun.stringWidth(x)+(j.reset?1+Bun.stringWidth(j.reset):0),B=Math.min(KJ,X),K=[G];for(let j=X;j>=B;j--)K.push({barCells:j});return K.find((j)=>$(j)<=Z)??{barCells:B}}function AJ(J,Z,V,X,x){if(!J||J.state==="on-pace")return null;let Y=x!==void 0&&x<=0,G=V==="now"||V==="0m"?"<1m":V,$=`${J.state} ${Math.round(Math.abs(J.deltaPercent))}%`,B=Y?X?`used up · resets in ${X}`:"used up":G?`${$} · out in ${G}`:`${$} · lasts to reset`;if(Z===void 0||Bun.stringWidth(B)<=Z)return B;if(Z<=0)return"";let K="";for(let j of B){if(Bun.stringWidth(K+j)>Z-1)break;K+=j}return`${K.trimEnd()}…`}function TJ(J,Z=Date.now()){let V=J?.five_hour?.usedPercent??null,X=J?.seven_day?.usedPercent??null,x=J?.scoped??[],Y=x.map(($)=>$.usedPercent);if(!J||V==null&&X==null&&x.length===0&&!J.extraUsage)return{fiveHourUsedPercent:V,sevenDayUsedPercent:X,scopedUsedPercents:Y,text:null,stale:!1};let G=I(J,Z);return{fiveHourUsedPercent:V,sevenDayUsedPercent:X,scopedUsedPercents:Y,text:c(G,{now:Z,form:"narrow"}),stale:s(G,{now:Z})}}function hJ(J,Z=!0){let V=J.activeId===void 0?void 0:YJ(J).id;return[{id:"main",name:"main",quota:J.main?.quota??null,quotaDated:J.main?.quotaDated,active:V==="main",blocked:J.main?.enabled===!1||Boolean(J.main?.stateLine)},...Z?(J.fallbacks??[]).filter((X)=>X.enabled||X.custodyState&&X.custodyState!=="off").map((X)=>({id:X.id,name:X.label??X.id,quota:X.quota,quotaDated:X.quotaDated,active:V===X.id,blocked:!X.enabled||Boolean(X.stateLine)||X.needsReauth||X.vaultReauth===!0||X.custodyState!=null&&X.custodyState!=="off"&&X.custodyState!=="on-vault-served"})):[]]}var gJ=18000000,SJ=604800000,jJ=300000,BJ=0.01,QJ=1;function bJ(J,Z,V){if(!J.resetsAt)return null;let X=new Date(J.resetsAt).getTime();if(!Number.isFinite(X))return null;let x=X-Z,Y=V-x;if(Y<jJ)return null;if(Y<Z*BJ)return null;if(Y>=Z)return null;let G=J.usedPercent,$=Math.min(Math.max(Y/Z*100,0),100),B=G-$,K=Math.abs(B)<QJ?"on-pace":B>0?"deficit":"reserve",j=null;if(G>0){let N=Y*100/G,_=x+N;if(_<X)j=new Date(_).toISOString()}return{pacePercent:$,deltaPercent:B,state:K,runsOutAt:j}}
|
|
2
|
-
export{P as
|
|
2
|
+
export{P as N,H as O,k as P,WJ as Q,UJ as R,qJ as S,LJ as T,T as U,EJ as V,MJ as W,YJ as X,L as Y,h as Z,xJ as _,fJ as $,PJ as aa,_J as ba,GJ as ca,DJ as da,KJ as ea,RJ as fa,AJ as ga,TJ as ha,hJ as ia,gJ as ja,SJ as ka,bJ as la};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import{createRequire as a}from"node:module";var c=a(import.meta.url);
|
|
2
|
-
export{c as
|
|
2
|
+
export{c as oa};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
2
|
-
export{F as
|
|
1
|
+
import{P as M}from"./index-1x1mncm7.js";import{logger as R}from"@cortexkit/anthropic-auth-core";var K=(f)=>f!==null&&typeof f==="object"&&!Array.isArray(f),X=(f)=>K(f)&&typeof f.sessionId==="string"&&f.sessionId.length>0,U=(f)=>{if(!X(f)||!K(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&&(!K(f.values)||!Object.values(f.values).every((j)=>j===null||typeof j==="string"||typeof j==="boolean"||typeof j==="number"&&Number.isFinite(j))))return!1;return!0};function H(f){return{"~standard":{version:1,vendor:"cortexkit-native",validate:(j)=>f(j)?{value:j}:{issues:[{message:"Invalid native menu payload"}]}}}}var A=(f)=>K(f)&&f.command==="claude"&&K(f.menu)&&f.menu.command==="claude"&&typeof f.menu.title==="string"&&Array.isArray(f.menu.sections),V=(f)=>K(f)&&f.command==="claude"&&typeof f.ok==="boolean"&&typeof f.text==="string"&&(f.authorizationUrl===void 0||typeof f.authorizationUrl==="string")&&K(f.menu)&&Array.isArray(f.menu.sections),L=!1,$=(f,j,B=new Set)=>{if(f===null||typeof f==="string"||typeof f==="boolean")return f;if(typeof f==="number"&&Number.isFinite(f))return f;if(typeof f==="object"&&f!==null&&!B.has(f)){if(B.add(f),Array.isArray(f)){let Q=Array.from(f,(D,G)=>$(D,`${j}[${G}]`,B)??null);return B.delete(f),Q}if(Object.getPrototypeOf(f)===Object.prototype||Object.getPrototypeOf(f)===null){let Q=Object.fromEntries(Object.entries(f).flatMap(([D,G])=>{let W=$(G,`${j}.${D}`,B);return W===void 0?[]:[[D,W]]}));return B.delete(f),Q}B.delete(f)}if(!L)L=!0,R.warn("sidebar","Dropped non-JSON sidebar field",{path:j});return},E={"~standard":{version:1,vendor:"cortexkit-native",validate:(f)=>{let j=M(f);return{value:$(j,"sidebar")}}}},F={id:"cortexkit-anthropic-native",methods:{open:{input:H(X),output:H(A)},apply:{input:H(U),output:H(V)},sidebar:{input:H(X),output:E}},events:{opened:{schema:H((f)=>X(f)&&A(f.payload))},notification:{schema:H((f)=>X(f)&&typeof f.message==="string"&&["info","warning","error"].includes(String(f.kind)))}}};async function T(f,j,B){let Q=new AbortController,D=(q)=>({sessionId:q,notify(Y,Z="info"){G.events.emit("notification",{sessionId:q,message:Y,kind:Z}).catch(()=>{})}}),G=await f.rpc.register(F,{open:(q)=>j.open(D(q.sessionId)),apply:(q)=>j.apply(q,D(q.sessionId)),sidebar:(q)=>B.readSidebar(q.sessionId)}),W;try{W=await f.command.transform((q)=>q.add({name:"claude",description:"Native Claude accounts and settings",async execute(Y){let Z=await j.open(D(Y.sessionID));await G.events.emit("opened",{sessionId:Y.sessionID,payload:Z})}}))}catch(q){throw await G.dispose(),q}let P=(async()=>{try{for await(let q of f.event.subscribe({signal:Q.signal}))if(q.type==="session.deleted")B.forgetSession(q.data.sessionID)}catch{}})(),z=!1;return{async dispose(){if(z)return;z=!0,Q.abort(),await Promise.all([G.dispose(),W.dispose(),P])}}}
|
|
2
|
+
export{F as A,T as B};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import{mkdir as L,readdir as M,readFile as N,rename as O,unlink as Q,writeFile as R}from"node:fs/promises";import{join as J}from"node:path";import{writerStamp as T}from"@cortexkit/anthropic-auth-core";function U(q){try{return process.kill(q,0),!0}catch(z){return z.code==="EPERM"}}var V={mkdir:async(q)=>{await L(q,{recursive:!0})},write:(q,z)=>R(q,z,{encoding:"utf8",mode:384}),rename:O,sleep:(q)=>new Promise((z)=>setTimeout(z,q))};async function Z(q,z,E={}){let C={...V,...E},G={...z,startedAt:Date.now(),writer:T()},H=J(q,`port-${z.pid}.json`),B=`${H}.${process.pid}.tmp`;for(let D=1;;D++){await C.mkdir(q);try{return await C.write(B,JSON.stringify(G)),await C.rename(B,H),H}catch(K){if(K.code!=="ENOENT"||D>=5)throw K;await C.sleep(25)}}}async function _(q,z){let E;try{E=await M(q)}catch{return null}let C=[];for(let B of E){if(!B.startsWith("port-")||!B.endsWith(".json"))continue;try{let D=JSON.parse(await N(J(q,B),"utf8"));if(Number.isFinite(D.port))if(U(D.pid))C.push(D);else Q(J(q,B)).catch(()=>{})}catch{}}if(C.length===0)return null;let G=z&&z>=1?C.filter((B)=>B.pid===z):[];return(G.length>0?G:C).sort((B,D)=>D.startedAt-B.startedAt)[0]??null}
|
|
2
|
-
export{Z as
|
|
2
|
+
export{Z as ma,_ as na};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
var b="native-claude-oauth",f="Claude Pro / Max (native account pool)",j='In OpenCode, sign in to Anthropic with "Claude Pro / Max (native account pool)".',k="native-claude-vault";
|
|
2
|
-
export{b as
|
|
2
|
+
export{b as C,f as D,j as E,k as F};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createHash as F}from"node:crypto";import{homedir as G,tmpdir as U}from"node:os";import{join as w,resolve as J}from"node:path";import{anthropicAuthStateRoot as K}from"@cortexkit/anthropic-auth-core";var L="OPENCODE_ANTHROPIC_AUTH_RPC_DIR";function Y(b){let q=process.env[L]?.trim();if(q)return J(b,q);let z=F("sha256").update(b).digest("hex").slice(0,16);return w(O(),z)}function O(){let b=K({xdgStateHome:process.env.XDG_STATE_HOME,home:G(),acceptRelative:!0});return w(b,"rpc")}export{U as
|
|
1
|
+
import{createHash as F}from"node:crypto";import{homedir as G,tmpdir as U}from"node:os";import{join as w,resolve as J}from"node:path";import{anthropicAuthStateRoot as K}from"@cortexkit/anthropic-auth-core";var L="OPENCODE_ANTHROPIC_AUTH_RPC_DIR";function Y(b){let q=process.env[L]?.trim();if(q)return J(b,q);let z=F("sha256").update(b).digest("hex").slice(0,16);return w(O(),z)}function O(){let b=K({xdgStateHome:process.env.XDG_STATE_HOME,home:G(),acceptRelative:!0});return w(b,"rpc")}export{U as x,Y as y,O as z};
|