@cortexkit/opencode-anthropic-auth 2.7.2 → 2.7.3
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 +4 -4
- package/dist/index-r16saahs.js +45 -0
- package/dist/index.js +1 -1
- package/dist/transform.d.ts +1 -0
- package/dist/v2/server.js +6 -6
- package/package.json +4 -4
- package/dist/index-bnnddf9n.js +0 -45
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{B as k3}from"./index-qqs4ec18.js";import{D as A4,E as _4,F as X7,G as G7,H as Q7,I as W7,J as I4}from"./index-k6303ymz.js";import{la as K4,ma as WJ,na as u3}from"./index-n8xr16kr.js";var H$=WJ((Oq,Y4)=>{var Y$={to($,Z){if(!Z)return`\x1B[${$+1}G`;return`\x1B[${Z+1};${$+1}H`},move($,Z){let J="";if($<0)J+=`\x1B[${-$}D`;else if($>0)J+=`\x1B[${$}C`;if(Z<0)J+=`\x1B[${-Z}A`;else if(Z>0)J+=`\x1B[${Z}B`;return J},up:($=1)=>`\x1B[${$}A`,down:($=1)=>`\x1B[${$}B`,forward:($=1)=>`\x1B[${$}C`,backward:($=1)=>`\x1B[${$}D`,nextLine:($=1)=>"\x1B[E".repeat($),prevLine:($=1)=>"\x1B[F".repeat($),left:"\x1B[G",hide:"\x1B[?25l",show:"\x1B[?25h",save:"\x1B7",restore:"\x1B8"},YJ={up:($=1)=>"\x1B[S".repeat($),down:($=1)=>"\x1B[T".repeat($)},HJ={screen:"\x1B[2J",up:($=1)=>"\x1B[1J".repeat($),down:($=1)=>"\x1B[J".repeat($),line:"\x1B[2K",lineEnd:"\x1B[K",lineStart:"\x1B[1K",lines($){let Z="";for(let J=0;J<$;J++)Z+=this.line+(J<$-1?Y$.up():"");if($)Z+=Y$.left;return Z}};Y4.exports={cursor:Y$,scroll:YJ,erase:HJ,beep:"\x07"}});import{stdin as eJ,stdout as $z}from"node:process";import{createInterface as Zz}from"node:readline/promises";import{authorize as Jz,createNativeAccountRuntime as zz,decideOpenCodeStateLayoutOnce as Xz,exchange as Gz,formatNativeAccountState as Qz,generateRelayToken as Wz,getAccountStoragePath as Yz,isValidApiBaseURL as Hz,readNativeEnrollmentMode as Uz,resolveNativePoolPaths as Kz,WORKER_SCRIPT as qz}from"@cortexkit/anthropic-auth-core";import{randomUUID as O5}from"node:crypto";import{constants as V3}from"node:fs";import{lstat as A5,mkdir as _5,open as I5}from"node:fs/promises";import{homedir as R5}from"node:os";import{isAbsolute as S5,join as O7}from"node:path";import{types as s9}from"node:util";import{anthropicAuthStateRoot as T5,createProviderErrorRedactor as A7,createWindowsOwnerOnly as k5,ensureWindowsOwnerOnlyDirectory as E5,formatLogLine as b5,HOLDER_REGISTRATION_ERROR_MESSAGES as f5,isOwnerOnly as x5,isSecretKey as y5,isStateLayoutRefusalCode as g5,NativeMigrationError as v5,NativePiAuthSlotError as h5,PRIVATE_FILES_UNAVAILABLE_MESSAGE as _7,RELOCATED_MESSAGE as m5,STATE_LAYOUT_REFUSAL_CODES as w5,STATE_LAYOUT_REFUSAL_PUBLIC_MESSAGES as u5,setupEnrollment as c5,stateLayoutRefusalPublicMessage as p5}from"@cortexkit/anthropic-auth-core";import{readFile as q5}from"node:fs/promises";import{assertHostsStopped as F5,createNativeAccountRuntime as B5,discoverNativeVaultInventory as V5,inspectNativeHostAuthEntry as u9,NativePiAuthSlotError as j5,nativePiAuthSlotPaths as M5,openNativePiAuthSlot as p9,readNativeEnrollmentMode as D5,requireNoSupervisedAuthContentSnapshot as N5}from"@cortexkit/anthropic-auth-core";import{dirname as u6}from"node:path";import{CLAUSTRUM_OPENCODE_ENROLLMENT_NAME as c6,CLAUSTRUM_PI_ENROLLMENT_NAME as p6,getHostClaustrumEnrollmentPaths as e2,resolveClaustrumConnectionPath as d6}from"@cortexkit/anthropic-auth-core";import{writeEnrollmentTokenFile as OW}from"@cortexkit/claustrum-client";import{ClaustrumClient as ZW}from"@cortexkit/claustrum-client";import{ClaustrumCredentialError as b4}from"@cortexkit/claustrum-client";import{SocketClosedError as f4,SocketTimeoutError as x4,SubcCallError as y4}from"@cortexkit/subc-client";class O extends Error{kind;constructor($,Z){super(Z);this.name="ClaustrumConsumerError",this.kind=$}}var g3=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 p extends O{constructor(){super("unavailable","Claustrum scoped operation unavailable");this.name="ClaustrumUnreachableError"}}function Y0($){if($ instanceof p||$ instanceof f4||$ instanceof x4)return"unreachable";let Z=$ instanceof b4||$ instanceof y4?$.code:$ instanceof Error&&("code"in $)?$.code:void 0;if(typeof Z!=="string"||!Object.hasOwn(g3,Z))return"answered";return g3[Z]}import{resolve as P$}from"node:path";import{storeIdentity as Ez}from"@cortexkit/claustrum-client";import{SubcClient as fz}from"@cortexkit/subc-client";var r0=300000,i1=300000,v3=1000;class S1{#$;#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 o1{#$;#Z;#X;#Q=!1;constructor($,Z){this.#$=$,this.#Z=Z}get running(){return this.#X}request(){if(this.#X)return this.#Q=!0,this.#X;return this.#X=(async()=>{do{this.#Q=!1;try{await this.#$()}catch($){this.#Z($)}}while(this.#Q)})().finally(()=>{this.#X=void 0}),this.#X}}class r1{#$;#Z=new S1;#X;#Q="polling";#G;#W;#z=!1;#J;#V=!1;#Y=0;constructor($){this.#$=$,this.#X=new o1(async()=>{let Z=this.#V;if(this.#V=!1,Z||this.#J!==this.#$.view())await this.#$.discover(this.#J??"")},(Z)=>{if(!this.#z)this.#$.onError?.(Z)})}get mode(){return this.#Q}start(){if(this.#z||this.#G||this.#W)return;if(typeof this.#$.client.watchScoped!=="function"){this.#H("fallback","client-without-watch");return}this.#F(!1)}stop(){if(this.#z)return;if(this.#z=!0,this.#W)(this.#$.clearTimeoutImpl??clearTimeout)(this.#W);this.#W=void 0;let $=this.#G;this.#G=void 0,$?.handle.stop()}#H($,Z){if(this.#Q===$)return;this.#Q=$,this.#$.logger?.debug("claustrum vault watch",{mode:$,reason:Z}),this.#$.onMode?.($)}#U($,Z){this.#W=(this.#$.setTimeoutImpl??setTimeout)(()=>{if(this.#W=void 0,!this.#z)Z()},$),this.#W.unref?.()}async#F($){let Z;try{Z=await this.#$.enrollmentToken()}catch(Q){if(this.#z)return;this.#$.onError?.(Q),this.#B("token-unreadable");return}let J=this.#$.client.watchScoped;if(this.#z||this.#G||!J)return;this.#Z.restart(),this.#V=$;let z,X;try{X=J.call(this.#$.client,(Q)=>{if(this.#z||!z||this.#G!==z)return;if(z.notices++,z.notices===1)this.#$.onReachable?.(),z.acceptedAt=(this.#$.now??Date.now)(),this.#H("watching","accepted");if(!this.#Z.continuous(Q))this.#V=!0;this.#J=Q.view,this.#X.request()},{enrollmentToken:Z})}catch(Q){this.#$.onError?.(Q),this.#B("watch-failed");return}z={handle:X,notices:0},this.#G=z,this.#H("polling",$?"resubscribing":"opening");let G=z;X.closed.then((Q)=>this.#K(G,Q),(Q)=>this.#K(G,{kind:"transport_lost",error:Q}))}#K($,Z){if(this.#z||this.#G!==$)return;if(this.#G=void 0,Z.kind==="stopped")return;if(Z.kind==="transport_lost")this.#$.onTransportLost?.();if(Z.kind==="unsupported"){this.#H("fallback","vault-without-watch");return}if(Z.kind==="refused"){this.#B("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.#Y=0;let z=Math.min(1000*2**Math.min(this.#Y,16),300000);this.#Y++,this.#H("polling","resubscribing"),this.#U(z,()=>void this.#F(!0));return}this.#B(Z.kind)}#B($){this.#H("fallback",$),this.#U(300000,()=>void this.#F(!1))}}var e1=60000,C$=4*e1,g4=2*e1,h3=new Map,t1=new Map;function t0($){return typeof $==="object"&&$!==null&&!Array.isArray($)}function v4($){let Z;try{Z=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode($))}catch{return}if(!t0(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 h4($){return $ instanceof Error&&"code"in $&&typeof $.code==="string"?$.code:void 0}class O${transport;key;#$=[];#Z=!1;#X=new Set;#Q=new Map;#G=new o1(async()=>{try{let $=await this.transport.getUsage();if(!t0($)||!Array.isArray($.result)||$.error!==void 0)throw Error("unavailable insula usage");this.#$=$.result.filter((Z)=>t0(Z)&&typeof Z.provider==="string"),this.#Z=this.#$.length===$.result.length&&($.completeProviders===void 0||Array.isArray($.completeProviders)&&$.completeProviders.every((Z)=>typeof Z==="string")),this.#X=new Set(this.#Z&&Array.isArray($.completeProviders)?$.completeProviders:[]);for(let Z of this.#X)this.#Q.delete(Z)}catch{this.#$=[],this.#Z=!1,this.#X.clear()}},()=>{});#W=new S1;#z="polling";#J=0;#V=0;#Y=new Map;#H;#U;#F={};#K=0;constructor($,Z){this.transport=$,this.key=Z}refresh($){if(this.#G.running)return this.#G.running;if(this.#z==="watching")return Promise.resolve();for(let[J,z]of t1)if($-z>=e1)t1.delete(J);let Z=t1.get(this.key);if(Z!==void 0&&$-Z<e1)return Promise.resolve();return t1.set(this.key,$),this.#G.request()}watchMode(){return this.#z}watch($={}){this.#J++;let Z=$.provider;if(Z===void 0)this.#V++;else this.#Y.set(Z,(this.#Y.get(Z)??0)+1);if(this.#J===1)this.#F=$,this.#C();let J=!1;return()=>{if(J)return;if(J=!0,Z===void 0)this.#V--;else{let z=(this.#Y.get(Z)??1)-1;if(z>0)this.#Y.set(Z,z);else this.#Y.delete(Z)}if(--this.#J===0)this.#B()}}#B(){if(this.#U)(this.#F.clearTimeoutImpl??clearTimeout)(this.#U);this.#U=void 0;let $=this.#H;this.#H=void 0,$?.handle?.stop(),this.#z="polling"}#D($){this.#U=(this.#F.setTimeoutImpl??setTimeout)(()=>{if(this.#U=void 0,this.#J>0&&!this.#H)this.#C()},$),this.#U.unref?.()}#C(){let $=this.transport.watchUsage;if(!$){this.#z="fallback";return}this.#z="polling",this.#W.restart();let Z={notices:0};this.#H=Z;let J;try{J=$.call(this.transport,(z)=>this.#P(Z,z))}catch(z){this.#O(Z,z);return}Z.handle=J,J.closed.then(()=>this.#O(Z,void 0),(z)=>this.#O(Z,z))}#P($,Z){if(this.#H!==$)return;if($.notices++,$.notices===1)this.#z="watching";if($.notices===2)this.#K=0;let J=v4(Z);if(!J)this.#W.restart();if(!(J?this.#W.continuous(J):!1)||J?.provider===void 0||this.#V>0||this.#Y.has(J.provider))this.#G.request()}#O($,Z){if(this.#H!==$)return;this.#H=void 0;let J=h4(Z);if(J==="unknown_method"||J==="usage_watch_limit"){this.#z="fallback";return}if($.notices>0){let z=Math.min(v3*2**Math.min(this.#K,16),i1);this.#K++,this.#z="polling",this.#D(z);return}if(this.#z="fallback",this.#G.request(),Z===void 0||Y0(Z)==="unreachable")this.#D(i1)}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||!t0(z.usage))continue;let X=typeof z.fetchedAt==="string"?Date.parse(z.fetchedAt):Number.NaN;if(!Number.isFinite(X)||J-X>=C$)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(!t0(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&&(!t0(z.stale)||z.stale.class!=="local_source_unavailable"))return{miss:"upstream-failed",reading:W};return J>=Q+C$||z.stale!==void 0?{miss:"stale",reading:W}:{reading:W}}if(this.#X.has($))return{miss:"absent"};let G=this.#Q.get($)??J;return this.#Q.set($,G),{miss:J-G>=g4?"unreachable":"cold"}}}function m3($,Z){let J=JSON.stringify([P$($.connectionFile),P$(Z)]),z=h3.get(J);if(!z)z={source:new O$($,J),refs:0},h3.set(J,z);z.refs++;let X=!1;return{source:z.source,release(){if(X)return;if(X=!0,--z.refs===0)h3.delete(J)}}}import{ClaustrumCredentialError as QW}from"@cortexkit/claustrum-client";import{appendFileSync as r4,chmodSync as t4,existsSync as p3,renameSync as x$,statSync as e4}from"node:fs";import{open as $8}from"node:fs/promises";import{dirname as Z8,resolve as J8}from"node:path";import{randomUUID as R$}from"node:crypto";import{lstat as S$,readFile as T$,rename as m4,unlink as A$}from"node:fs/promises";import{tmpdir as w4}from"node:os";import{dirname as C0,join as u4,resolve as $0}from"node:path";var _=process.platform==="win32",_$=new Set;function w3($){if($?.reason==="io-error"){if($.win32Code===2||$.win32Code===3)return"ENOENT";if($.win32Code===80||$.win32Code===183)return"EEXIST"}return $?.code??"ERR_PRIVATE_FILE"}var I$;var k$="native-addon-unavailable";function E$($){return Object.assign(Error("Windows private-files native addon is unavailable",{cause:$}),{code:"ERR_PRIVATE_FILES_UNAVAILABLE",reason:k$})}function c4($,Z){return Z instanceof $.PrivateFilesUnavailableError||Z?.code==="ERR_PRIVATE_FILES_UNAVAILABLE"}async function p4($){try{await $.verifyPrivatePath(u4(w4(),`.common-auth-private-files-probe-${R$()}`),"file")}catch(Z){if(c4($,Z))throw E$(Z)}}function e0(){return I$??=import("@cortexkit/private-files").then(async($)=>{if(_)await p4($);return $},($)=>{throw _?E$($):$}),I$}class w 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}: ${$} (${k$}). 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.`:`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=w3(z),this.win32Code=z?.win32Code,this.reason=z?.reason}}function $3($){return _&&$ instanceof w&&$.reason==="io-error"&&($.win32Code===32||$.win32Code===303)}async function t($,Z,J){try{return await J()}catch(z){if(z instanceof w)throw z;throw new w($,Z,z)}}var d4;async function j0($,Z){$=$0($),Z??=d4,await t($,"safe-parent",async()=>{let J=await(await e0()).verifySafeParent($,Z);if(J.ok===!1){if(J.reason==="io-error"||J.reason==="wrong-kind")await S$($);throw new w(J.level??J.path,"safe-parent",{...J,code:"ERR_PRIVATE_FILES_SECURITY"})}})}async function n($,Z,J=!1){if($=$0($),Z==="directory")return j0($);await t($,"verify",async()=>{let z=await e0(),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 j0(C0($)),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&&!_$.has($))_$.add($),process.emitWarning(`Private permissions tightened: ${$}. This object may have been readable before; rotate credentials if needed.`,"PrivateFileMigration")})}async function H0($,Z=!1,J){$=$0($),await t($,"directory",async()=>{let z=await e0();try{return await S$($),await j0($,J)}catch(G){if(w3(G)!=="ENOENT")throw G}let X=C0($);if(X===$)throw Object.assign(Error("Missing root"),{code:"ENOENT"});await H0(X,!1,J);try{await z.createOwnerOnly($,{kind:"dir"})}catch(G){if(w3(G)!=="EEXIST")throw G}await j0($,J)})}async function X0($,Z=!1){if(!_)return T$($,"utf8");return(await l4($,Z)).toString("utf8")}async function l4($,Z=!1){if(!_)return T$($);if($=$0($),Z)await j0(C0($)),await n($,"file",!0);return t($,"read",async()=>(await e0()).readOwnerOnly($))}async function $1($,Z){await j0(C0($0($))),await t($,"create",async()=>{await(await e0()).createPrivateFile($0($),Z)})}async function b$($){await j0(C0($0($))),await t($,"directory-create",async()=>{await(await e0()).createOwnerOnly($0($),{kind:"dir"})})}async function c3($,Z,J={}){$=$0($),Z=$0(Z);let z=J.now??(()=>performance.now()),X=z(),G=J.deadline??1/0,Q,W=[0,10,20,40,80,100],Y,U=0;for(let K of W){let D=Math.min(Q??1/0,G);if(z()>=D)break;if(K)await(J.sleep??((L)=>new Promise((C)=>setTimeout(C,L))))(Math.min(K,Math.max(0,D-z())));if(z()>=D)break;let B=z();if(await J.beforeRename?.(),Q!==void 0)Q+=z()-B;if(z()>=G)break;U++;try{return await(J.rename??m4)($,Z),{attempts:U,elapsedMs:z()-X}}catch(L){Y??=L;let C=L;if(!(C.win32Code!==void 0?C.win32Code===32||C.win32Code===33:["EBUSY","EPERM","EACCES"].includes(C.code??"")&&!C.reason))break;Q??=z()+500}}let H=new w(Z,"rename",Y??Object.assign(Error("Publication deadline expired"),{code:"ETIMEDOUT"}));throw H.attempts=U,H.elapsedMs=z()-X,H}async function Z1($,Z,J={}){$=$0($),await H0(C0($));try{await n($,"file",!0)}catch(U){if(U.code!=="ENOENT")throw U}let z=$0(J.stagePath??`${$}.${R$()}.tmp`);if(C0(z)!==C0($))throw new w($,"stage-directory",{code:"EXDEV"});let X=!1,G=!1,Q={attempts:0,elapsedMs:0},W="stage-create",Y=(U)=>{try{J.onOutcome?.({path:$,stage:U?.stage??"published",published:G,fileDurable:G,durabilityConfirmed:!1,attempts:U?.attempts??Q.attempts,elapsedMs:U?.elapsedMs??Q.elapsedMs,...U&&{code:U.code,win32Code:U.win32Code}})}catch{}};try{if(await $1(z,Z),X=!0,W="before-rename",Q=await c3(z,$,J),X=!1,G=!0,W="published-callback",J.onRenamed?.(),W="published-verify",await n($,"file"),J.durable&&J.durability!=="file-only-on-windows")throw new w($,"directory-sync-unsupported",{code:"ENOTSUP"});Y()}catch(U){let H=U instanceof w?U:new w($,W,U);if(H.published=G,H.fileDurable=G,G)Object.assign(H,Q);if(X){try{await A$(z)}catch{H.orphanPath=z}X=!1}throw Y(H),H}finally{if(X)await A$(z).catch(()=>{})}}var a4=/^(authorization|x-api-key|cookie|set-cookie|refresh|access|token)$/i,s4=/\b(Bearer\s+[\w.-]+|sk-[\w-]+|eyJ[\w.-]+)\b|ckh_[A-Za-z0-9_-]{20,}/g;function n4($){return $ instanceof Error||Object.prototype.toString.call($)==="[object Error]"}function J1($={}){let Z=[s4,...$.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 a4.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 U of["code","status","cause"])if(Q[U]!==void 0)W.push([U,Q[U]]);let Y=new Set(W.map(([U])=>U));for(let U of Object.entries(G))if(!Y.has(U[0]))W.push(U);return W}function X(G,Q,W,Y=0){if(typeof G==="string")return Z.reduce((U,H)=>U.replace(H,"***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((K)=>X(K,Q,W,Y));let U=n4(G);if(U&&Y>=8)return"[Truncated]";let H=U?Y+1:Y;return Object.fromEntries((U?z(G):Object.entries(G)).map(([K,D])=>[K,Q&&J(K)?"***REDACTED***":X(D,Q,W,H)]))}finally{W.delete(G)}}return{redact:(G)=>X(G,!0,new WeakSet),redactStrings:(G)=>X(G,!1,new WeakSet)}}var f$=J1(),i4=f$.redact,o4=f$.redactStrings;var Z3={error:0,warn:1,info:2,debug:3,trace:4},g$=5242880,v$=3;function d3($){try{t4($,384)}catch{}}function z8($){try{if(!(p3($)&&e4($).size>=g$))return;for(let J=v$-1;J>=1;J--)if(p3(`${$}.${J}`)){let z=`${$}.${J+1}`;x$(`${$}.${J}`,z),d3(z)}let Z=`${$}.1`;x$($,Z),d3(Z)}catch{}}async function M0($){let{file:Z,handle:J}=$;if($.file=void 0,$.handle=void 0,Z&&J)await t(Z,"log-close",()=>J.close())}async function y$($,Z){await H0(Z8(Z));try{await n(Z,"file",!0)}catch(J){if(J.code!=="ENOENT")throw J;try{await $1(Z,"")}catch(z){if(z.code!=="EEXIST")throw z;await n(Z,"file",!0)}}return $.handle=await t(Z,"log-open",()=>$8(Z,"a")),$.file=Z,$.handle}async function X8($,Z,J){Z=J8(Z);try{if($.file!==Z)await M0($);let z=$.handle??await y$($,Z);if((await t(Z,"log-stat",()=>z.stat())).size>=g$){await M0($);for(let G=v$-1;G>=0;G--){let Q=G===0?Z:`${Z}.${G}`,W=`${Z}.${G+1}`;try{await n(Q,"file",!0)}catch(Y){if(Y.code==="ENOENT")continue;throw Y}try{await n(W,"file",!0)}catch(Y){if(Y.code!=="ENOENT")throw Y}await c3(Q,W),await n(W,"file")}z=await y$($,Z)}await t(Z,"log-append",()=>z.appendFile(J,"utf8"))}catch(z){throw await M0($).catch(()=>{}),z}}function G8($){try{return` ${JSON.stringify($)}`}catch{return" [unserializable]"}}function Q8($){let Z,J,z,X=J1(),G,Q=[],W,Y=Promise.resolve(),U,H={};function K(F){let q=Y.then(F);return Y=q.catch((j)=>{U=j}),q}function D(F){if(_&&F.file!==Z)K(()=>M0(H)).catch(()=>{});Z=F.file,J=F.level,X=J1(F),G=F.captureSink}function B(F){if(F===void 0||F in Z3)z=F}function L(){if(Z===void 0)return;return(typeof Z==="function"?Z():Z)||void 0}function C(){if(z)return z;let F=typeof J==="function"?J():J;if(F&&F in Z3)return F;return"info"}function A(F=!0){if(W)clearTimeout(W),W=void 0;if(!Q.length){if(_)return K(async()=>{if(F)await M0(H);if(U)throw U});return}let q;try{q=L()}catch{if(Q=[],_&&F)return K(()=>M0(H));return}let j=Q.join("");if(Q=[],!q){if(_&&F)return K(()=>M0(H));return}if(_)return K(async()=>{try{await X8(H,q,j)}finally{if(F)await M0(H)}});try{if(z8(q),p3(q))d3(q);r4(q,j,{encoding:"utf8",mode:384})}catch{}}function I(){if(!W)W=setTimeout(()=>{W=void 0;let F=A(!1);if(F instanceof Promise)F.catch(()=>{})},500)}function T(F,q,j,P){if(Z===void 0&&G===void 0)return;try{if(Z3[q]>Z3[C()])return;let g=X.redactStrings(j),E;try{E=X.redact(P)}catch{E="[unserializable]"}let v=`[${new Date().toISOString()}] ${q.toUpperCase()} [${F}] ${g}`+(P===void 0?"":G8(E))+`
|
|
2
|
+
import{B as k3}from"./index-qqs4ec18.js";import{D as A4,E as _4,F as X7,G as G7,H as Q7,I as W7,J as I4}from"./index-k6303ymz.js";import{la as K4,ma as WJ,na as u3}from"./index-n8xr16kr.js";var H$=WJ((Aq,Y4)=>{var Y$={to($,Z){if(!Z)return`\x1B[${$+1}G`;return`\x1B[${Z+1};${$+1}H`},move($,Z){let J="";if($<0)J+=`\x1B[${-$}D`;else if($>0)J+=`\x1B[${$}C`;if(Z<0)J+=`\x1B[${-Z}A`;else if(Z>0)J+=`\x1B[${Z}B`;return J},up:($=1)=>`\x1B[${$}A`,down:($=1)=>`\x1B[${$}B`,forward:($=1)=>`\x1B[${$}C`,backward:($=1)=>`\x1B[${$}D`,nextLine:($=1)=>"\x1B[E".repeat($),prevLine:($=1)=>"\x1B[F".repeat($),left:"\x1B[G",hide:"\x1B[?25l",show:"\x1B[?25h",save:"\x1B7",restore:"\x1B8"},YJ={up:($=1)=>"\x1B[S".repeat($),down:($=1)=>"\x1B[T".repeat($)},HJ={screen:"\x1B[2J",up:($=1)=>"\x1B[1J".repeat($),down:($=1)=>"\x1B[J".repeat($),line:"\x1B[2K",lineEnd:"\x1B[K",lineStart:"\x1B[1K",lines($){let Z="";for(let J=0;J<$;J++)Z+=this.line+(J<$-1?Y$.up():"");if($)Z+=Y$.left;return Z}};Y4.exports={cursor:Y$,scroll:YJ,erase:HJ,beep:"\x07"}});import{stdin as eJ,stdout as $z}from"node:process";import{createInterface as Zz}from"node:readline/promises";import{authorize as Jz,createNativeAccountRuntime as zz,decideOpenCodeStateLayoutOnce as Xz,exchange as Gz,formatNativeAccountState as Qz,generateRelayToken as Wz,getAccountStoragePath as Yz,isValidApiBaseURL as Hz,readNativeEnrollmentMode as Uz,resolveNativePoolPaths as Kz,WORKER_SCRIPT as qz}from"@cortexkit/anthropic-auth-core";import{randomUUID as O5}from"node:crypto";import{constants as V3}from"node:fs";import{lstat as A5,mkdir as _5,open as I5}from"node:fs/promises";import{homedir as R5}from"node:os";import{isAbsolute as S5,join as O7}from"node:path";import{types as s9}from"node:util";import{anthropicAuthStateRoot as T5,createProviderErrorRedactor as A7,createWindowsOwnerOnly as k5,ensureWindowsOwnerOnlyDirectory as E5,formatLogLine as b5,HOLDER_REGISTRATION_ERROR_MESSAGES as f5,isOwnerOnly as x5,isSecretKey as y5,isStateLayoutRefusalCode as g5,NativeMigrationError as v5,NativePiAuthSlotError as h5,PRIVATE_FILES_UNAVAILABLE_MESSAGE as _7,RELOCATED_MESSAGE as m5,STATE_LAYOUT_REFUSAL_CODES as w5,STATE_LAYOUT_REFUSAL_PUBLIC_MESSAGES as u5,setupEnrollment as c5,stateLayoutRefusalPublicMessage as p5}from"@cortexkit/anthropic-auth-core";import{readFile as q5}from"node:fs/promises";import{assertHostsStopped as F5,createNativeAccountRuntime as B5,discoverNativeVaultInventory as V5,inspectNativeHostAuthEntry as u9,NativePiAuthSlotError as j5,nativePiAuthSlotPaths as M5,openNativePiAuthSlot as p9,readNativeEnrollmentMode as D5,requireNoSupervisedAuthContentSnapshot as N5}from"@cortexkit/anthropic-auth-core";import{dirname as u6}from"node:path";import{CLAUSTRUM_OPENCODE_ENROLLMENT_NAME as c6,CLAUSTRUM_PI_ENROLLMENT_NAME as p6,getHostClaustrumEnrollmentPaths as e2,resolveClaustrumConnectionPath as d6}from"@cortexkit/anthropic-auth-core";import{ClaustrumCredentialError as OW,writeEnrollmentTokenFile as AW}from"@cortexkit/claustrum-client";import{ClaustrumClient as ZW}from"@cortexkit/claustrum-client";import{ClaustrumCredentialError as b4}from"@cortexkit/claustrum-client";import{SocketClosedError as f4,SocketTimeoutError as x4,SubcCallError as y4}from"@cortexkit/subc-client";class O extends Error{kind;constructor($,Z){super(Z);this.name="ClaustrumConsumerError",this.kind=$}}var g3=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 p extends O{constructor(){super("unavailable","Claustrum scoped operation unavailable");this.name="ClaustrumUnreachableError"}}function Y0($){if($ instanceof p||$ instanceof f4||$ instanceof x4)return"unreachable";let Z=$ instanceof b4||$ instanceof y4?$.code:$ instanceof Error&&("code"in $)?$.code:void 0;if(typeof Z!=="string"||!Object.hasOwn(g3,Z))return"answered";return g3[Z]}import{resolve as P$}from"node:path";import{storeIdentity as Ez}from"@cortexkit/claustrum-client";import{SubcClient as fz}from"@cortexkit/subc-client";var r0=300000,i1=300000,v3=1000;class S1{#$;#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 o1{#$;#Z;#X;#Q=!1;constructor($,Z){this.#$=$,this.#Z=Z}get running(){return this.#X}request(){if(this.#X)return this.#Q=!0,this.#X;return this.#X=(async()=>{do{this.#Q=!1;try{await this.#$()}catch($){this.#Z($)}}while(this.#Q)})().finally(()=>{this.#X=void 0}),this.#X}}class r1{#$;#Z=new S1;#X;#Q="polling";#G;#W;#z=!1;#J;#V=!1;#Y=0;constructor($){this.#$=$,this.#X=new o1(async()=>{let Z=this.#V;if(this.#V=!1,Z||this.#J!==this.#$.view())await this.#$.discover(this.#J??"")},(Z)=>{if(!this.#z)this.#$.onError?.(Z)})}get mode(){return this.#Q}start(){if(this.#z||this.#G||this.#W)return;if(typeof this.#$.client.watchScoped!=="function"){this.#H("fallback","client-without-watch");return}this.#F(!1)}stop(){if(this.#z)return;if(this.#z=!0,this.#W)(this.#$.clearTimeoutImpl??clearTimeout)(this.#W);this.#W=void 0;let $=this.#G;this.#G=void 0,$?.handle.stop()}#H($,Z){if(this.#Q===$)return;this.#Q=$,this.#$.logger?.debug("claustrum vault watch",{mode:$,reason:Z}),this.#$.onMode?.($)}#U($,Z){this.#W=(this.#$.setTimeoutImpl??setTimeout)(()=>{if(this.#W=void 0,!this.#z)Z()},$),this.#W.unref?.()}async#F($){let Z;try{Z=await this.#$.enrollmentToken()}catch(Q){if(this.#z)return;this.#$.onError?.(Q),this.#B("token-unreadable");return}let J=this.#$.client.watchScoped;if(this.#z||this.#G||!J)return;this.#Z.restart(),this.#V=$;let z,X;try{X=J.call(this.#$.client,(Q)=>{if(this.#z||!z||this.#G!==z)return;if(z.notices++,z.notices===1)this.#$.onReachable?.(),z.acceptedAt=(this.#$.now??Date.now)(),this.#H("watching","accepted");if(!this.#Z.continuous(Q))this.#V=!0;this.#J=Q.view,this.#X.request()},{enrollmentToken:Z})}catch(Q){this.#$.onError?.(Q),this.#B("watch-failed");return}z={handle:X,notices:0},this.#G=z,this.#H("polling",$?"resubscribing":"opening");let G=z;X.closed.then((Q)=>this.#K(G,Q),(Q)=>this.#K(G,{kind:"transport_lost",error:Q}))}#K($,Z){if(this.#z||this.#G!==$)return;if(this.#G=void 0,Z.kind==="stopped")return;if(Z.kind==="transport_lost")this.#$.onTransportLost?.();if(Z.kind==="unsupported"){this.#H("fallback","vault-without-watch");return}if(Z.kind==="refused"){this.#B("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.#Y=0;let z=Math.min(1000*2**Math.min(this.#Y,16),300000);this.#Y++,this.#H("polling","resubscribing"),this.#U(z,()=>void this.#F(!0));return}this.#B(Z.kind)}#B($){this.#H("fallback",$),this.#U(300000,()=>void this.#F(!1))}}var e1=60000,C$=4*e1,g4=2*e1,h3=new Map,t1=new Map;function t0($){return typeof $==="object"&&$!==null&&!Array.isArray($)}function v4($){let Z;try{Z=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode($))}catch{return}if(!t0(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 h4($){return $ instanceof Error&&"code"in $&&typeof $.code==="string"?$.code:void 0}class O${transport;key;#$=[];#Z=!1;#X=new Set;#Q=new Map;#G=new o1(async()=>{try{let $=await this.transport.getUsage();if(!t0($)||!Array.isArray($.result)||$.error!==void 0)throw Error("unavailable insula usage");this.#$=$.result.filter((Z)=>t0(Z)&&typeof Z.provider==="string"),this.#Z=this.#$.length===$.result.length&&($.completeProviders===void 0||Array.isArray($.completeProviders)&&$.completeProviders.every((Z)=>typeof Z==="string")),this.#X=new Set(this.#Z&&Array.isArray($.completeProviders)?$.completeProviders:[]);for(let Z of this.#X)this.#Q.delete(Z)}catch{this.#$=[],this.#Z=!1,this.#X.clear()}},()=>{});#W=new S1;#z="polling";#J=0;#V=0;#Y=new Map;#H;#U;#F={};#K=0;constructor($,Z){this.transport=$,this.key=Z}refresh($){if(this.#G.running)return this.#G.running;if(this.#z==="watching")return Promise.resolve();for(let[J,z]of t1)if($-z>=e1)t1.delete(J);let Z=t1.get(this.key);if(Z!==void 0&&$-Z<e1)return Promise.resolve();return t1.set(this.key,$),this.#G.request()}watchMode(){return this.#z}watch($={}){this.#J++;let Z=$.provider;if(Z===void 0)this.#V++;else this.#Y.set(Z,(this.#Y.get(Z)??0)+1);if(this.#J===1)this.#F=$,this.#C();let J=!1;return()=>{if(J)return;if(J=!0,Z===void 0)this.#V--;else{let z=(this.#Y.get(Z)??1)-1;if(z>0)this.#Y.set(Z,z);else this.#Y.delete(Z)}if(--this.#J===0)this.#B()}}#B(){if(this.#U)(this.#F.clearTimeoutImpl??clearTimeout)(this.#U);this.#U=void 0;let $=this.#H;this.#H=void 0,$?.handle?.stop(),this.#z="polling"}#D($){this.#U=(this.#F.setTimeoutImpl??setTimeout)(()=>{if(this.#U=void 0,this.#J>0&&!this.#H)this.#C()},$),this.#U.unref?.()}#C(){let $=this.transport.watchUsage;if(!$){this.#z="fallback";return}this.#z="polling",this.#W.restart();let Z={notices:0};this.#H=Z;let J;try{J=$.call(this.transport,(z)=>this.#P(Z,z))}catch(z){this.#O(Z,z);return}Z.handle=J,J.closed.then(()=>this.#O(Z,void 0),(z)=>this.#O(Z,z))}#P($,Z){if(this.#H!==$)return;if($.notices++,$.notices===1)this.#z="watching";if($.notices===2)this.#K=0;let J=v4(Z);if(!J)this.#W.restart();if(!(J?this.#W.continuous(J):!1)||J?.provider===void 0||this.#V>0||this.#Y.has(J.provider))this.#G.request()}#O($,Z){if(this.#H!==$)return;this.#H=void 0;let J=h4(Z);if(J==="unknown_method"||J==="usage_watch_limit"){this.#z="fallback";return}if($.notices>0){let z=Math.min(v3*2**Math.min(this.#K,16),i1);this.#K++,this.#z="polling",this.#D(z);return}if(this.#z="fallback",this.#G.request(),Z===void 0||Y0(Z)==="unreachable")this.#D(i1)}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||!t0(z.usage))continue;let X=typeof z.fetchedAt==="string"?Date.parse(z.fetchedAt):Number.NaN;if(!Number.isFinite(X)||J-X>=C$)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(!t0(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&&(!t0(z.stale)||z.stale.class!=="local_source_unavailable"))return{miss:"upstream-failed",reading:W};return J>=Q+C$||z.stale!==void 0?{miss:"stale",reading:W}:{reading:W}}if(this.#X.has($))return{miss:"absent"};let G=this.#Q.get($)??J;return this.#Q.set($,G),{miss:J-G>=g4?"unreachable":"cold"}}}function m3($,Z){let J=JSON.stringify([P$($.connectionFile),P$(Z)]),z=h3.get(J);if(!z)z={source:new O$($,J),refs:0},h3.set(J,z);z.refs++;let X=!1;return{source:z.source,release(){if(X)return;if(X=!0,--z.refs===0)h3.delete(J)}}}import{ClaustrumCredentialError as QW}from"@cortexkit/claustrum-client";import{appendFileSync as r4,chmodSync as t4,existsSync as p3,renameSync as x$,statSync as e4}from"node:fs";import{open as $8}from"node:fs/promises";import{dirname as Z8,resolve as J8}from"node:path";import{randomUUID as R$}from"node:crypto";import{lstat as S$,readFile as T$,rename as m4,unlink as A$}from"node:fs/promises";import{tmpdir as w4}from"node:os";import{dirname as C0,join as u4,resolve as $0}from"node:path";var _=process.platform==="win32",_$=new Set;function w3($){if($?.reason==="io-error"){if($.win32Code===2||$.win32Code===3)return"ENOENT";if($.win32Code===80||$.win32Code===183)return"EEXIST"}return $?.code??"ERR_PRIVATE_FILE"}var I$;var k$="native-addon-unavailable";function E$($){return Object.assign(Error("Windows private-files native addon is unavailable",{cause:$}),{code:"ERR_PRIVATE_FILES_UNAVAILABLE",reason:k$})}function c4($,Z){return Z instanceof $.PrivateFilesUnavailableError||Z?.code==="ERR_PRIVATE_FILES_UNAVAILABLE"}async function p4($){try{await $.verifyPrivatePath(u4(w4(),`.common-auth-private-files-probe-${R$()}`),"file")}catch(Z){if(c4($,Z))throw E$(Z)}}function e0(){return I$??=import("@cortexkit/private-files").then(async($)=>{if(_)await p4($);return $},($)=>{throw _?E$($):$}),I$}class w 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}: ${$} (${k$}). 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.`:`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=w3(z),this.win32Code=z?.win32Code,this.reason=z?.reason}}function $3($){return _&&$ instanceof w&&$.reason==="io-error"&&($.win32Code===32||$.win32Code===303)}async function t($,Z,J){try{return await J()}catch(z){if(z instanceof w)throw z;throw new w($,Z,z)}}var d4;async function j0($,Z){$=$0($),Z??=d4,await t($,"safe-parent",async()=>{let J=await(await e0()).verifySafeParent($,Z);if(J.ok===!1){if(J.reason==="io-error"||J.reason==="wrong-kind")await S$($);throw new w(J.level??J.path,"safe-parent",{...J,code:"ERR_PRIVATE_FILES_SECURITY"})}})}async function n($,Z,J=!1){if($=$0($),Z==="directory")return j0($);await t($,"verify",async()=>{let z=await e0(),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 j0(C0($)),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&&!_$.has($))_$.add($),process.emitWarning(`Private permissions tightened: ${$}. This object may have been readable before; rotate credentials if needed.`,"PrivateFileMigration")})}async function H0($,Z=!1,J){$=$0($),await t($,"directory",async()=>{let z=await e0();try{return await S$($),await j0($,J)}catch(G){if(w3(G)!=="ENOENT")throw G}let X=C0($);if(X===$)throw Object.assign(Error("Missing root"),{code:"ENOENT"});await H0(X,!1,J);try{await z.createOwnerOnly($,{kind:"dir"})}catch(G){if(w3(G)!=="EEXIST")throw G}await j0($,J)})}async function X0($,Z=!1){if(!_)return T$($,"utf8");return(await l4($,Z)).toString("utf8")}async function l4($,Z=!1){if(!_)return T$($);if($=$0($),Z)await j0(C0($)),await n($,"file",!0);return t($,"read",async()=>(await e0()).readOwnerOnly($))}async function $1($,Z){await j0(C0($0($))),await t($,"create",async()=>{await(await e0()).createPrivateFile($0($),Z)})}async function b$($){await j0(C0($0($))),await t($,"directory-create",async()=>{await(await e0()).createOwnerOnly($0($),{kind:"dir"})})}async function c3($,Z,J={}){$=$0($),Z=$0(Z);let z=J.now??(()=>performance.now()),X=z(),G=J.deadline??1/0,Q,W=[0,10,20,40,80,100],Y,U=0;for(let K of W){let D=Math.min(Q??1/0,G);if(z()>=D)break;if(K)await(J.sleep??((L)=>new Promise((C)=>setTimeout(C,L))))(Math.min(K,Math.max(0,D-z())));if(z()>=D)break;let B=z();if(await J.beforeRename?.(),Q!==void 0)Q+=z()-B;if(z()>=G)break;U++;try{return await(J.rename??m4)($,Z),{attempts:U,elapsedMs:z()-X}}catch(L){Y??=L;let C=L;if(!(C.win32Code!==void 0?C.win32Code===32||C.win32Code===33:["EBUSY","EPERM","EACCES"].includes(C.code??"")&&!C.reason))break;Q??=z()+500}}let H=new w(Z,"rename",Y??Object.assign(Error("Publication deadline expired"),{code:"ETIMEDOUT"}));throw H.attempts=U,H.elapsedMs=z()-X,H}async function Z1($,Z,J={}){$=$0($),await H0(C0($));try{await n($,"file",!0)}catch(U){if(U.code!=="ENOENT")throw U}let z=$0(J.stagePath??`${$}.${R$()}.tmp`);if(C0(z)!==C0($))throw new w($,"stage-directory",{code:"EXDEV"});let X=!1,G=!1,Q={attempts:0,elapsedMs:0},W="stage-create",Y=(U)=>{try{J.onOutcome?.({path:$,stage:U?.stage??"published",published:G,fileDurable:G,durabilityConfirmed:!1,attempts:U?.attempts??Q.attempts,elapsedMs:U?.elapsedMs??Q.elapsedMs,...U&&{code:U.code,win32Code:U.win32Code}})}catch{}};try{if(await $1(z,Z),X=!0,W="before-rename",Q=await c3(z,$,J),X=!1,G=!0,W="published-callback",J.onRenamed?.(),W="published-verify",await n($,"file"),J.durable&&J.durability!=="file-only-on-windows")throw new w($,"directory-sync-unsupported",{code:"ENOTSUP"});Y()}catch(U){let H=U instanceof w?U:new w($,W,U);if(H.published=G,H.fileDurable=G,G)Object.assign(H,Q);if(X){try{await A$(z)}catch{H.orphanPath=z}X=!1}throw Y(H),H}finally{if(X)await A$(z).catch(()=>{})}}var a4=/^(authorization|x-api-key|cookie|set-cookie|refresh|access|token)$/i,s4=/\b(Bearer\s+[\w.-]+|sk-[\w-]+|eyJ[\w.-]+)\b|ckh_[A-Za-z0-9_-]{20,}/g;function n4($){return $ instanceof Error||Object.prototype.toString.call($)==="[object Error]"}function J1($={}){let Z=[s4,...$.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 a4.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 U of["code","status","cause"])if(Q[U]!==void 0)W.push([U,Q[U]]);let Y=new Set(W.map(([U])=>U));for(let U of Object.entries(G))if(!Y.has(U[0]))W.push(U);return W}function X(G,Q,W,Y=0){if(typeof G==="string")return Z.reduce((U,H)=>U.replace(H,"***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((K)=>X(K,Q,W,Y));let U=n4(G);if(U&&Y>=8)return"[Truncated]";let H=U?Y+1:Y;return Object.fromEntries((U?z(G):Object.entries(G)).map(([K,D])=>[K,Q&&J(K)?"***REDACTED***":X(D,Q,W,H)]))}finally{W.delete(G)}}return{redact:(G)=>X(G,!0,new WeakSet),redactStrings:(G)=>X(G,!1,new WeakSet)}}var f$=J1(),i4=f$.redact,o4=f$.redactStrings;var Z3={error:0,warn:1,info:2,debug:3,trace:4},g$=5242880,v$=3;function d3($){try{t4($,384)}catch{}}function z8($){try{if(!(p3($)&&e4($).size>=g$))return;for(let J=v$-1;J>=1;J--)if(p3(`${$}.${J}`)){let z=`${$}.${J+1}`;x$(`${$}.${J}`,z),d3(z)}let Z=`${$}.1`;x$($,Z),d3(Z)}catch{}}async function M0($){let{file:Z,handle:J}=$;if($.file=void 0,$.handle=void 0,Z&&J)await t(Z,"log-close",()=>J.close())}async function y$($,Z){await H0(Z8(Z));try{await n(Z,"file",!0)}catch(J){if(J.code!=="ENOENT")throw J;try{await $1(Z,"")}catch(z){if(z.code!=="EEXIST")throw z;await n(Z,"file",!0)}}return $.handle=await t(Z,"log-open",()=>$8(Z,"a")),$.file=Z,$.handle}async function X8($,Z,J){Z=J8(Z);try{if($.file!==Z)await M0($);let z=$.handle??await y$($,Z);if((await t(Z,"log-stat",()=>z.stat())).size>=g$){await M0($);for(let G=v$-1;G>=0;G--){let Q=G===0?Z:`${Z}.${G}`,W=`${Z}.${G+1}`;try{await n(Q,"file",!0)}catch(Y){if(Y.code==="ENOENT")continue;throw Y}try{await n(W,"file",!0)}catch(Y){if(Y.code!=="ENOENT")throw Y}await c3(Q,W),await n(W,"file")}z=await y$($,Z)}await t(Z,"log-append",()=>z.appendFile(J,"utf8"))}catch(z){throw await M0($).catch(()=>{}),z}}function G8($){try{return` ${JSON.stringify($)}`}catch{return" [unserializable]"}}function Q8($){let Z,J,z,X=J1(),G,Q=[],W,Y=Promise.resolve(),U,H={};function K(F){let q=Y.then(F);return Y=q.catch((j)=>{U=j}),q}function D(F){if(_&&F.file!==Z)K(()=>M0(H)).catch(()=>{});Z=F.file,J=F.level,X=J1(F),G=F.captureSink}function B(F){if(F===void 0||F in Z3)z=F}function L(){if(Z===void 0)return;return(typeof Z==="function"?Z():Z)||void 0}function C(){if(z)return z;let F=typeof J==="function"?J():J;if(F&&F in Z3)return F;return"info"}function A(F=!0){if(W)clearTimeout(W),W=void 0;if(!Q.length){if(_)return K(async()=>{if(F)await M0(H);if(U)throw U});return}let q;try{q=L()}catch{if(Q=[],_&&F)return K(()=>M0(H));return}let j=Q.join("");if(Q=[],!q){if(_&&F)return K(()=>M0(H));return}if(_)return K(async()=>{try{await X8(H,q,j)}finally{if(F)await M0(H)}});try{if(z8(q),p3(q))d3(q);r4(q,j,{encoding:"utf8",mode:384})}catch{}}function I(){if(!W)W=setTimeout(()=>{W=void 0;let F=A(!1);if(F instanceof Promise)F.catch(()=>{})},500)}function T(F,q,j,P){if(Z===void 0&&G===void 0)return;try{if(Z3[q]>Z3[C()])return;let g=X.redactStrings(j),E;try{E=X.redact(P)}catch{E="[unserializable]"}let v=`[${new Date().toISOString()}] ${q.toUpperCase()} [${F}] ${g}`+(P===void 0?"":G8(E))+`
|
|
3
3
|
`;try{G?.({channel:F,level:q,message:g,data:E})}catch{}if(Z===void 0)return;if(Q.push(v),Q.length>=50){let J0=A(!1);if(J0 instanceof Promise)J0.catch(()=>{})}else I()}catch{}}function m(F){return{error:(q,j)=>T(F,"error",q,j),warn:(q,j)=>T(F,"warn",q,j),info:(q,j)=>T(F,"info",q,j),debug:(q,j)=>T(F,"debug",q,j),trace:(q,j)=>T(F,"trace",q,j)}}function u(){if(_)K(()=>M0(H)).catch(()=>{});if(U=void 0,Q=[],W)clearTimeout(W),W=void 0;Z=void 0,J=void 0,z=void 0,X=J1(),G=void 0}if($)D($);return{configure:D,createLogger:m,setLogLevel:B,flushLogs:A,reset:u}}var W8=Q8();function U0($){return W8.createLogger($)}function E0($){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 d8}from"node:diagnostics_channel";import{ClaustrumCredentialError as V2}from"@cortexkit/claustrum-client";import{createHash as T8,randomBytes as k8,randomUUID as E8}from"node:crypto";import{constants as r$}from"node:fs";import{chmod as b8,mkdir as f8,open as Z2,readFile as o3,realpath as x8,rename as y8,stat as J2,unlink as t3}from"node:fs/promises";import{basename as g8,dirname as g0,extname as wX,isAbsolute as uX,join as v8,resolve as cX}from"node:path";import{ClaustrumCredentialError as h8,ClaustrumClient as dX,writeEnrollmentTokenFile as m8}from"@cortexkit/claustrum-client";import{lstat as Y8,stat as H8}from"node:fs/promises";import{resolve as U8}from"node:path";async function K8($,Z){try{let J=await(Z?H8($):Y8($));return J.isFile()?J:void 0}catch(J){return J.code==="ENOENT"?"absent":void 0}}function q8($,Z){if($==="absent"||Z==="absent")return $===Z;return $.dev===Z.dev&&$.ino===Z.ino&&$.size===Z.size&&$.mtimeMs===Z.mtimeMs&&$.ctimeMs===Z.ctimeMs}class b0{#$;#Z=new Map;constructor($={}){this.#$=$.followSymlinks??!1}async read($,Z,J){let z=$.map((U)=>U8(U)),X=JSON.stringify(z),G=await Promise.all(z.map((U)=>K8(U,this.#$))),Q=G.every((U)=>U!==void 0)?G:void 0,W=this.#Z.get(X);if(Q&&W&&Q.every((U,H)=>{let K=W.identities[H];return K!==void 0&&q8(U,K)}))return J?.(Q),W.value;this.#Z.delete(X);let Y=await Z(z);if(Q){if(this.#Z.size>=64){let U=this.#Z.keys().next().value;if(U!==void 0)this.#Z.delete(U)}this.#Z.set(X,{identities:Q,value:Y})}return Y}}import{randomUUID as h$}from"node:crypto";import{mkdir as F8,open as m$,rename as B8,rm as V8}from"node:fs/promises";import{dirname as w$}from"node:path";class J3 extends Error{constructor($){super("file or directory sync failed",{cause:$});this.name="AtomicSyncError"}}async function z1($,Z,J={}){await u$($,Z,J)}async function u$($,Z,J,z){if(_)return Z1($,J.serialize?J.serialize(Z):`${JSON.stringify(Z,null,2)}
|
|
4
4
|
`,{beforeRename:J.beforeRename,stagePath:`${$}.${(J.stageName??h$)()}.tmp`,onRenamed:z,durable:J.durable,durability:J.durability,onOutcome:J.onOutcome});await F8(w$($),{recursive:!0});let X=`${$}.${(J.stageName??h$)()}.tmp`,G,Q=!1;try{if(G=await m$(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 J3(W)}if(await G.close(),G=void 0,await J.beforeRename?.(),await B8(X,$),Q=!1,z?.(),J.durable){let W=await m$(w$($),"r");try{await W.sync()}catch(Y){throw new J3(Y)}finally{await W.close()}}}finally{if(await G?.close().catch(()=>{}),Q)await V8(X,{force:!0}).catch(()=>{})}}var j8=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 k1}from"node:crypto";import{link as L8,lstat as G1,mkdir as c$,open as n3,readFile as p$,rename as d$,rm as Q1,stat as T1}from"node:fs/promises";import{dirname as a3,join as l$}from"node:path";import{join as M8,resolve as D8}from"node:path";function X1($,Z){return`${$}.${Z}.lock`}class O0 extends Error{details;constructor($){super(`Timed out acquiring ${$.name} lock for ${$.target}`);this.name="LockContentionError",this.details=$}}class D0 extends Error{details;constructor($){super(`Lost ${$.name} lock for ${$.target}`);this.name="LockOwnershipError",this.details=$}}function N8($,Z,J){if(!$3($)||$.stage!=="read"&&$.stage!=="verify")return!1;let z=D8(X1(Z,J));return $.path===z||$.path===M8(z,"owner.json")}async function l3($,Z,J){let z=performance.now();for(;;){Z.signal?.throwIfAborted();let X,G;try{X=await N0({path:$,name:Z.name,ttlMs:Z.ttlMs,renew:Z.renew??!1,...Z.onStep?{onStep:Z.onStep}:{},...Z.onRenewalTimer?{onRenewalTimer:Z.onRenewalTimer}:{}})}catch(W){if(!N8(W,$,Z.name))throw W;X=null,G=W}if(X)try{return Z.signal?.throwIfAborted(),await J(X)}finally{await X.release(Z.signal)}let Q=Z.timeoutMs-(performance.now()-z);if(Q<=0){if(G)throw G;throw new O0({target:$,name:Z.name,timeoutMs:Z.timeoutMs})}await new Promise((W)=>setTimeout(W,Math.min(25,Math.ceil(Q))))}}var W1;async function P8($,Z){let J=`${$}.${k1()}.tmp`,z;try{z=await n3(J,"wx",384);try{if(W1?.beforeWrite)await W1.beforeWrite(J);await z.writeFile(Z,"utf8")}finally{await z.close()}try{if(W1?.beforeLink)await W1.beforeLink(J,$);await L8(J,$)}catch(X){let G=X.code;if(G!=="EPERM"&&G!=="ENOTSUP"&&G!=="EOPNOTSUPP"&&G!=="EXDEV")throw X;await s$($,Z)}}finally{if(z)await Q1(J,{force:!0}).catch(()=>{})}}async function s$($,Z){let J=await n3($,"wx",384),z;try{z=await J.stat()}catch{z=void 0}try{if(W1?.beforeWrite)await W1.beforeWrite($);await J.writeFile(Z,"utf8")}catch(X){try{let G=await G1($).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 C8=globalThis.setTimeout.bind(globalThis),O8=globalThis.clearTimeout.bind(globalThis);function n$($){let Z=$?.code;return Z==="ENOENT"||!_&&(Z==="EINVAL"||Z==="ENOTDIR")}var a$;function s3($,Z){if($.dev!==Z.dev||$.ino!==Z.ino)return!1;if($.ino===0&&$.birthtimeMs!==Z.birthtimeMs)return!1;return!0}var A8=1000;function N0($){return _8({...$,now:Date.now})}async function _8($){let Z=X1($.path,$.name),J=l$(Z,"owner.json"),z=k1(),X=$.now??Date.now,G=null,Q=!1,W=!1,Y,U,H=new Promise((V)=>{U=V});function K(V){try{let M=$.onRenewalTimer?.(V);if(M&&(typeof M==="object"||typeof M==="function")&&"then"in M&&typeof M.then==="function")Promise.resolve(M).catch(()=>{})}catch{}}function D(){if(!G)return;O8(G),G=null,K("cancelled")}function B(V,M){if(Y||Q)return;Y=Object.freeze({reason:V,expectedOwnerId:z,...typeof M?.ownerId==="string"?{observedOwnerId:M.ownerId}:{},...typeof M?.expiresAt==="number"?{observedExpiresAt:M.expiresAt}:{}}),D(),U(Y)}let L,C=null,A=`${Z}.evicting`,I=l$(A,"owner.json"),T=k1(),m=5000,u=8;async function F(){if(_)try{return JSON.parse(await X0(Z,!0))}catch(V){if(V.code!=="EISDIR"&&V.reason!=="wrong-kind")throw V;return await n(Z,"directory",!0),JSON.parse(await X0(J,!0))}try{return JSON.parse(await p$(Z,"utf8"))}catch(V){if(V.code!=="EISDIR")throw V;return JSON.parse(await p$(J,"utf8"))}}async function q(){if(_){let R=await F(),S=Number(R?.expiresAt)-X();await Z1(Z,`${JSON.stringify({ownerId:z,expiresAt:X()+$.ttlMs})}
|
|
@@ -21,7 +21,7 @@ Please quit all OpenCode, LiteCode, and Pi processes before running setup.`);thi
|
|
|
21
21
|
`,W.ownership),B=D.path;if(B===void 0){let L={error:P7(Q,U),saveError:P7(D.error,U)};try{(W.stderr??((A)=>process.stderr.write(A)))(`CLI failure metadata: ${JSON.stringify(L)}
|
|
22
22
|
`)}catch{}}return B===void 0?`${H} failed (${Z}). Details could not be saved to a private diagnostics file.`:`${H} failed (${Z}). Details were written to ${B}`}async function a0($,Z,J,z=[],X={}){let G=c1(Z);if(G!==void 0)return G;let Q=UZ(Z);return FZ($,`${$}/unexpected-error`,J,z,{},()=>({text:[...Q?[`step: ${Q.step}`,`exitCode: ${Q.exitCode}`,`signal: ${Q.signal}`]:[],...x7(Z,0),...Q?[`stderrTail:
|
|
23
23
|
${Q.stderrTail}`]:[]].join(`
|
|
24
|
-
`),keep:"head"}),Z,X)}import{assertHostsStopped as yJ,createProcessFence as R4,decideOpenCodeStateLayoutOnce as gJ,decidePiStateLayout as vJ,isVaultHosted as hJ,NativePiAuthSlotError as mJ,openNativePiAuthSlot as wJ,publishNativeEmptyInit as uJ,readNativeEnrollmentMode as cJ,releaseNativeMigrationPreflight as pJ,requireNoSupervisedAuthContentSnapshot as dJ,restoreLegacyLayout as lJ,runSetup as aJ,StateLayoutRefusalError as sJ,setupUsage as nJ,VAULT_HOST_CONNECT_REFUSAL as iJ}from"@cortexkit/anthropic-auth-core";import{AsyncLocalStorage as y7}from"node:async_hooks";var
|
|
24
|
+
`),keep:"head"}),Z,X)}import{assertHostsStopped as yJ,createProcessFence as R4,decideOpenCodeStateLayoutOnce as gJ,decidePiStateLayout as vJ,isVaultHosted as hJ,NativePiAuthSlotError as mJ,openNativePiAuthSlot as wJ,publishNativeEmptyInit as uJ,readNativeEnrollmentMode as cJ,releaseNativeMigrationPreflight as pJ,requireNoSupervisedAuthContentSnapshot as dJ,restoreLegacyLayout as lJ,runSetup as aJ,StateLayoutRefusalError as sJ,setupUsage as nJ,VAULT_HOST_CONNECT_REFUSAL as iJ}from"@cortexkit/anthropic-auth-core";import{AsyncLocalStorage as y7}from"node:async_hooks";var UY=new y7,KY=new y7;var g7=Object.freeze({ttlMs:1e4,timeoutMs:15000,retryMs:50,renew:!0});var L1="commonAuthPool";var yZ=Object.freeze(["version","accounts",L1]);var OU=new b0;var k={hide:"\x1B[?25l",show:"\x1B[?25h",up:($=1)=>`\x1B[${$}A`,clearLine:"\x1B[2K",clearScreen:"\x1B[2J",moveTo:($,Z)=>`\x1B[${$};${Z}H`,cyan:"\x1B[36m",green:"\x1B[32m",red:"\x1B[31m",dim:"\x1B[2m",reset:"\x1B[0m"};function z$($){let Z=$.toString(),J=[];for(let z=0;z<Z.length;){let X=Z[z];if(X==="\x1B"){let G=Z.slice(z,z+3),Q=G[1]==="["||G[1]==="O"?G[2]:void 0;if(Q&&"ABCD".includes(Q)){let Y={A:"up",B:"down",C:"right",D:"left"}[Q];if(Y)J.push(Y);z+=3}else if(z+1===Z.length){if(z===0)J.push("escape-start");z+=1}else if((Z[z+1]==="["||Z[z+1]==="O")&&z+2>=Z.length)break;else z+=1;continue}if(X==="\r"||X===`
|
|
25
25
|
`)J.push("enter");else if(X==="\x03")J.push("escape");else if(X&&X>=" ")J.push("char");z+=1}return J}var a7=`${String.fromCharCode(27)}\\[[0-9;]*m`,gZ=new RegExp(a7,"g"),vZ=new RegExp(`^${a7}`);function s7($){return $.replace(gZ,"")}function s0($,Z){if(Z<=0)return"";if(s7($).length<=Z)return $;let J=Z>=3?"...":".".repeat(Z),z=Math.max(0,Z-J.length),X="",G=0,Q=0;while(G<$.length&&Q<z){if($[G]==="\x1B"){let W=$.slice(G).match(vZ);if(W){X+=W[0],G+=W[0].length;continue}}X+=$[G],G+=1,Q+=1}return X.includes("\x1B[")?`${X}${k.reset}${J}`:X+J}function O1($){return $.input.isTTY===!0}var hZ=50;function mZ($){if($==="red")return k.red;if($==="cyan")return k.cyan;return""}async function L3($,Z,J){if(!O1($))throw Error("Interactive select requires a TTY terminal");if(Z.length===0)throw Error("No menu items provided");let{input:z,output:X,signals:G}=$,Q=0,W=null,Y=!1,U=0,H=()=>{let K=X.columns??80,D=X.rows??24,B=U;if(J.clearScreen)X.write(k.clearScreen+k.moveTo(1,1));else if(B>0)X.write(k.up(B));let L=0,C=(q)=>{X.write(`${k.clearLine}${q}
|
|
26
26
|
`),L+=1},A=J.lines??[],I=1+(J.subtitle?3:0)+A.length+(A.length?1:0),T=Math.max(1,Math.min(Z.length,D-I-2-1)),m=Math.max(0,Math.min(Q-Math.floor(T/2),Math.max(0,Z.length-T))),u=Z.slice(m,m+T);if(C(`${k.dim}┌ ${k.reset}${s0(J.message,Math.max(1,K-4))}`),J.subtitle)C(`${k.dim}│${k.reset}`),C(`${k.cyan}◆${k.reset} ${s0(J.subtitle,Math.max(1,K-4))}`),C("");for(let q of A)C(`${k.cyan}│${k.reset} ${s0(q,Math.max(1,K-4))}`);if(A.length)C(`${k.cyan}│${k.reset}`);for(let q=0;q<u.length;q++){let j=u[q];if(!j)continue;let P=m+q===Q,g=mZ(j.color),E=g?`${P?"":k.dim}${g}${j.label}${k.reset}`:P?j.label:`${k.dim}${j.label}${k.reset}`;if(j.hint)E+=` ${k.dim}${j.hint}${k.reset}`;E=s0(E,Math.max(1,K-8)),C(P?`${k.cyan}│${k.reset} ${k.green}●${k.reset} ${E}`:`${k.cyan}│${k.reset} ${k.dim}○${k.reset} ${E}`)}let F=u.length<Z.length?` (${m+1}-${m+u.length}/${Z.length})`:"";C(`${k.cyan}│${k.reset} ${k.dim}${s0(`Up/Down to select | Enter: confirm | Esc: back${F}`,Math.max(1,K-6))}${k.reset}`),C(`${k.cyan}└${k.reset}`);for(let q=L;q<B;q++)C("");U=L};return new Promise((K)=>{let D=z.isRaw??!1,B=()=>{if(Y)return;if(Y=!0,W)clearTimeout(W);z.removeListener("data",A);try{z.setRawMode(D),z.pause(),X.write(k.show)}catch{}G?.removeListener("SIGINT",C),G?.removeListener("SIGTERM",C)},L=(I)=>{B(),K(I)},C=()=>L(null),A=(I)=>{for(let T of z$(I)){if(Y)break;if(W)clearTimeout(W),W=null;switch(T){case"up":Q=(Q-1+Z.length)%Z.length,H();break;case"down":Q=(Q+1)%Z.length,H();break;case"enter":L(Z[Q]?.value??null);break;case"escape":L(null);break;case"escape-start":W=setTimeout(()=>L(null),hZ);break;default:break}}};G?.once("SIGINT",C),G?.once("SIGTERM",C);try{z.setRawMode(!0)}catch{B(),K(null);return}z.resume(),X.write(k.hide),H(),z.on("data",A)})}async function P3($,Z,J=!1){if(!O1($))return!1;return await L3($,J?[{label:"Yes",value:!0},{label:"No",value:!1}]:[{label:"No",value:!1},{label:"Yes",value:!0}],{message:Z})??!1}import{execFile as lZ}from"node:child_process";import{promisify as aZ}from"node:util";var sZ=aZ(lZ),X$={async run($,Z,J={}){try{let z={...process.env,...J.env};delete z.CORTEXKIT_VAULT_HOST;let{stdout:X,stderr:G}=await sZ($,Z,{env:z,timeout:J.timeoutMs??15000,maxBuffer:10485760});return{exitCode:0,stdout:typeof X==="string"?X:String(X),stderr:typeof G==="string"?G:String(G)}}catch(z){let X=z;return{exitCode:typeof X?.code==="number"?X.code:1,signal:typeof X?.signal==="string"?X.signal:null,...typeof X?.syscall==="string"&&(X.syscall==="spawn"||X.syscall.startsWith("spawn "))?{spawnError:!0}:{},stdout:typeof X?.stdout==="string"?X.stdout:X?.stdout!=null?String(X.stdout):"",stderr:typeof X?.stderr==="string"?X.stderr:X?.stderr!=null?String(X.stderr):String(X?.message??z)}}}};import{styleText as R3}from"node:util";import{stdout as UJ,stdin as KJ}from"node:process";import qJ from"node:readline";var n7=(()=>{let $=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return(Z)=>{let J=0;$.lastIndex=0;while($.test(Z))J+=1;return Z.length-J}})(),i7=($)=>{return $===12288||$>=65281&&$<=65376||$>=65504&&$<=65510},o7=($)=>{return $===8987||$===9001||$>=12272&&$<=12287||$>=12289&&$<=12350||$>=12441&&$<=12543||$>=12549&&$<=12591||$>=12593&&$<=12686||$>=12688&&$<=12771||$>=12783&&$<=12830||$>=12832&&$<=12871||$>=12880&&$<=19903||$>=65040&&$<=65049||$>=65072&&$<=65106||$>=65108&&$<=65126||$>=65128&&$<=65131||$>=127488&&$<=127490||$>=127504&&$<=127547||$>=127552&&$<=127560||$>=131072&&$<=196605||$>=196608&&$<=262141};var nZ=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,iZ=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,r7=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,oZ=/\t{1,1000}/y,t7=/[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu,rZ=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,tZ=/\p{M}+/gu,eZ={limit:1/0,ellipsis:""},e7=($,Z={},J={})=>{let z=Z.limit??1/0,X=Z.ellipsis??"",G=Z?.ellipsisWidth??(X?e7(X,eZ,J).width:0),Q=0,W=J.controlWidth??0,Y=J.tabWidth??8,U=J.emojiWidth??2,H=2,K=J.regularWidth??1,D=J.wideWidth??2,B=[[rZ,K],[nZ,0],[iZ,W],[oZ,Y],[t7,U],[r7,D]],L=0,C=0,A=$.length,I=0,T=!1,m=A,u=Math.max(0,z-G),F=0,q=0,j=0,P=0;$:while(!0){if(q>F||C>=A&&C>L){let g=$.slice(F,q)||$.slice(L,C);I=0;for(let E of g.replaceAll(tZ,"")){let v=E.codePointAt(0)||0;if(i7(v))P=2;else if(o7(v))P=D;else P=K;if(j+P>u)m=Math.min(m,Math.max(F,L)+I);if(j+P>z){T=!0;break $}I+=E.length,j+=P}F=q=0}if(C>=A)break $;for(let g=0,E=B.length;g<E;g++){let[v,J0]=B[g];if(v.lastIndex=C,v.test($)){if(I=v===r7?n7($.slice(C,v.lastIndex)):v===t7?1:v.lastIndex-C,P=I*J0,j+P>u)m=Math.min(m,C+Math.floor((u-j)/J0));if(j+P>z){T=!0;break $}j+=P,F=L,q=C,C=L=v.lastIndex;continue $}}C+=1}return{width:T?u:j,index:T?m:A,truncated:T,ellipsed:T&&z>=G}},$4=e7;var $J={limit:1/0,ellipsis:"",ellipsisWidth:0},ZJ=($,Z={})=>{return $4($,$J,Z).width},F0=ZJ;var C3="\x1B",G4="",JJ=39,Q$="\x07",Q4="[",zJ="]",W4="m",W$=`${zJ}8;;`,Z4=new RegExp(`(?:\\${Q4}(?<code>\\d+)m|\\${W$}(?<uri>.*)${Q$})`,"y"),J4=($)=>{if($>=30&&$<=37)return 39;if($>=90&&$<=97)return 39;if($>=40&&$<=47)return 49;if($>=100&&$<=107)return 49;if($===1||$===2)return 22;if($===3)return 23;if($===4)return 24;if($===7)return 27;if($===8)return 28;if($===9)return 29;if($===0)return 0;return},z4=($)=>`${C3}${Q4}${$}${W4}`,X4=($)=>`${C3}${W$}${$}${Q$}`,G$=($,Z,J)=>{let z=Z[Symbol.iterator](),X=!1,G=!1,Q=$.at(-1),W=Q===void 0?0:F0(Q),Y=z.next(),U=z.next(),H=0;while(!Y.done){let K=Y.value,D=F0(K);if(W+D<=J)$[$.length-1]+=K;else $.push(K),W=0;if(K===C3||K===G4)X=!0,G=Z.startsWith(W$,H+1);if(X){if(G){if(K===Q$)X=!1,G=!1}else if(K===W4)X=!1}else if(W+=D,W===J&&!U.done)$.push(""),W=0;Y=U,U=z.next(),H+=K.length}if(Q=$.at(-1),!W&&Q!==void 0&&Q.length&&$.length>1)$[$.length-2]+=$.pop()},XJ=($)=>{let Z=$.split(" "),J=Z.length;while(J){if(F0(Z[J-1]))break;J--}if(J===Z.length)return $;return Z.slice(0,J).join(" ")+Z.slice(J).join("")},GJ=($,Z,J={})=>{if(J.trim!==!1&&$.trim()==="")return"";let z="",X,G,Q=$.split(" "),W=[""],Y=0;for(let K=0;K<Q.length;K++){let D=Q[K];if(J.trim!==!1){let L=W.at(-1)??"",C=L.trimStart();if(L.length!==C.length)W[W.length-1]=C,Y=F0(C)}if(K!==0){if(Y>=Z&&(J.wordWrap===!1||J.trim===!1))W.push(""),Y=0;if(Y||J.trim===!1)W[W.length-1]+=" ",Y++}let B=F0(D);if(J.hard&&B>Z){let L=Z-Y,C=1+Math.floor((B-L-1)/Z);if(Math.floor((B-1)/Z)<C)W.push("");G$(W,D,Z),Y=F0(W.at(-1)??"");continue}if(Y+B>Z&&Y&&B){if(J.wordWrap===!1&&Y<Z){G$(W,D,Z),Y=F0(W.at(-1)??"");continue}W.push(""),Y=0}if(Y+B>Z&&J.wordWrap===!1){G$(W,D,Z),Y=F0(W.at(-1)??"");continue}W[W.length-1]+=D,Y+=B}if(J.trim!==!1)W=W.map((K)=>XJ(K));let U=W.join(`
|
|
27
27
|
`),H=!1;for(let K=0;K<U.length;K++){let D=U[K];if(z+=D,!H){if(H=D>="\uD800"&&D<="\uDBFF",H)continue}else H=!1;if(D===C3||D===G4){Z4.lastIndex=K+1;let L=Z4.exec(U)?.groups;if(L?.code!==void 0){let C=Number.parseFloat(L.code);X=C===JJ?void 0:C}else if(L?.uri!==void 0)G=L.uri.length===0?void 0:L.uri}if(U[K+1]===`
|
|
@@ -30,7 +30,7 @@ ${Q.stderrTail}`]:[]].join(`
|
|
|
30
30
|
`)}var Z0=K4(H$(),1);function K$($,Z,J){if(!J.some((Q)=>!Q.disabled))return $;let z=$+Z,X=Math.max(J.length-1,0),G=z<0?X:z>X?0:z;return J[G]?.disabled?K$(G,Z<0?-1:1,J):G}function A3($,Z,J,z){let X=z.split(`
|
|
31
31
|
`),G=0,Q=$;for(let Y of X){if(Q<=Y.length)break;Q-=Y.length+1,G++}for(G=Math.max(0,Math.min(X.length-1,G+J)),Q=Math.min(Q,X[G].length)+Z;Q<0&&G>0;)G--,Q+=X[G].length+1;for(;Q>X[G].length&&G<X.length-1;)Q-=X[G].length+1,G++;Q=Math.max(0,Math.min(X[G].length,Q));let W=0;for(let Y=0;Y<G;Y++)W+=X[Y].length+1;return W+Q}var FJ=["up","down","left","right","space","enter","cancel"],BJ=["January","February","March","April","May","June","July","August","September","October","November","December"],Q0={actions:new Set(FJ),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["\x03","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"},withGuide:!0,accessible:void 0,date:{monthNames:[...BJ],messages:{required:"Please enter a valid date",invalidMonth:"There are only 12 months in a year",invalidDay:($,Z)=>`There are only ${$} days in ${Z}`,afterMin:($)=>`Date must be on or after ${$.toISOString().slice(0,10)}`,beforeMax:($)=>`Date must be on or before ${$.toISOString().slice(0,10)}`}}};function VJ($){if($!==void 0)return $;if(Q0.accessible!==void 0)return Q0.accessible;let Z=process.env.ACCESSIBLE;return Z!==void 0&&Z!==""&&Z!=="0"&&Z!=="false"}function q4($,Z){if(typeof $=="string")return Q0.aliases.get($)===Z;for(let J of $)if(J!==void 0&&q4(J,Z))return!0;return!1}function jJ($,Z){if($===Z)return;let J=$.split(`
|
|
32
32
|
`),z=Z.split(`
|
|
33
|
-
`),X=Math.max(J.length,z.length),G=[];for(let Q=0;Q<X;Q++)J[Q]!==z[Q]&&G.push(Q);return{lines:G,numLinesBefore:J.length,numLinesAfter:z.length,numLines:X}}var
|
|
33
|
+
`),X=Math.max(J.length,z.length),G=[];for(let Q=0;Q<X;Q++)J[Q]!==z[Q]&&G.push(Q);return{lines:G,numLinesBefore:J.length,numLinesAfter:z.length,numLines:X}}var Tq=globalThis.process.platform.startsWith("win"),S3=Symbol("clack:cancel");function T3($){return $===S3}function _3($,Z){let J=$;J.isTTY&&J.setRawMode(Z)}var F4=($)=>("rows"in $)&&typeof $.rows=="number"?$.rows:20;function B4($,Z){if("~standard"in $){let J=$["~standard"].validate(Z);return J instanceof Promise?J.then((z)=>z.issues?.at(0)?.message):J.issues?.at(0)?.message}return $(Z)}class A1{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame="";_subscribers=new Map;_cursor=0;state="initial";error="";value;userInput="";get accessible(){return VJ(this.opts.accessible)}constructor($,Z=!0){let{input:J=KJ,output:z=UJ,render:X,signal:G,...Q}=$;this.opts=Q,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=X.bind(this),this._track=Z,this._abortSignal=G,this.input=J,this.output=z}unsubscribe(){this._subscribers.clear()}setSubscriber($,Z){let J=this._subscribers.get($)??[];J.push(Z),this._subscribers.set($,J)}on($,Z){this.setSubscriber($,{cb:Z})}once($,Z){this.setSubscriber($,{cb:Z,once:!0})}emit($,...Z){let J=this._subscribers.get($)??[],z=[];for(let X of J)X.cb(...Z),X.once&&z.push(()=>J.splice(J.indexOf(X),1));for(let X of z)X()}prompt(){return new Promise(($)=>{if(this._abortSignal){if(this._abortSignal.aborted)return this.state="cancel",this.close(),$(S3);this._abortSignal.addEventListener("abort",()=>{this.state="cancel",this.close()},{once:!0})}this.rl=qJ.createInterface({input:this.input,tabSize:2,prompt:"",escapeCodeTimeout:50,terminal:!0}),this.rl.prompt(),this.opts.initialUserInput!==void 0&&this._setUserInput(this.opts.initialUserInput,!0),this.input.on("keypress",this.onKeypress),_3(this.input,!0),this.output.on("resize",this.render),this.render(),this.once("submit",()=>{this.output.write(Z0.cursor.show),this.output.off("resize",this.render),_3(this.input,!1),$(this.value)}),this.once("cancel",()=>{this.output.write(Z0.cursor.show),this.output.off("resize",this.render),_3(this.input,!1),$(S3)})})}_isActionKey($,Z){return $==="\t"}_shouldSubmit($,Z){return!0}_setValue($){this.value=$,this.emit("value",this.value)}_setUserInput($,Z){this.userInput=$??"",this.emit("userInput",this.userInput),Z&&this._track&&this.rl&&(this.rl.write(this.userInput),this._cursor=this.rl.cursor)}_clearUserInput(){this.rl?.write(null,{ctrl:!0,name:"u"}),this._setUserInput("")}async onKeypress($,Z){if(this.state!=="validating"){if(this._track&&Z.name!=="return"&&(Z.name&&this._isActionKey($,Z)&&this.rl?.write(null,{ctrl:!0,name:"h"}),this._cursor=this.rl?.cursor??0,this._setUserInput(this.rl?.line)),this.state==="error"&&(this.state="active"),Z?.name&&(!this._track&&Q0.aliases.has(Z.name)&&this.emit("cursor",Q0.aliases.get(Z.name)),Q0.actions.has(Z.name)&&this.emit("cursor",Z.name)),$&&($.toLowerCase()==="y"||$.toLowerCase()==="n")&&this.emit("confirm",$.toLowerCase()==="y"),this.emit("key",$,Z),Z?.name==="return"&&this._shouldSubmit($,Z)){if(this.opts.validate){let J=B4(this.opts.validate,this.value),z;J instanceof Promise?(this.state="validating",this.render(),z=await J):z=J,z&&(this.error=z instanceof Error?z.message:z,this.state="error",this.rl?.write(this.userInput))}this.state!=="error"&&(this.state="submit")}q4([$,Z?.name,Z?.sequence],"cancel")&&(this.state="cancel"),(this.state==="submit"||this.state==="cancel")&&this.emit("finalize"),this.render(),(this.state==="submit"||this.state==="cancel")&&this.close()}}close(){this.input.unpipe(),this.input.removeListener("keypress",this.onKeypress),this.output.write(`
|
|
34
34
|
`),_3(this.input,!1),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){let $=O3(this._prevFrame,process.stdout.columns,{hard:!0,trim:!1}).split(`
|
|
35
35
|
`).length-1;this.output.write(Z0.cursor.move(-999,$*-1))}render(){let $=O3(this._render(this)??"",process.stdout.columns,{hard:!0,trim:!1});if($!==this._prevFrame){if(this.state==="initial")this.output.write(Z0.cursor.hide);else{let Z=jJ(this._prevFrame,$),J=F4(this.output);if(this.restoreCursor(),Z){let z=Math.max(0,Z.numLinesAfter-J),X=Math.max(0,Z.numLinesBefore-J),G=Z.lines.find((Q)=>Q>=z);if(G===void 0){this._prevFrame=$;return}if(Z.lines.length===1){this.output.write(Z0.cursor.move(0,G-X)),this.output.write(Z0.erase.lines(1));let Q=$.split(`
|
|
36
36
|
`);this.output.write(Q[G]),this._prevFrame=$,this.output.write(Z0.cursor.move(0,Q.length-G-1));return}else if(Z.lines.length>1){if(z<X)G=z;else{let W=G-X;W>0&&this.output.write(Z0.cursor.move(0,W))}this.output.write(Z0.erase.down());let Q=$.split(`
|
|
@@ -40,7 +40,7 @@ ${Q.stderrTail}`]:[]].join(`
|
|
|
40
40
|
${z}`:`${Z}${R3("inverse",J)}${z}`}get cursor(){return this._cursor}#X($){if(this.userInput.length===0){this._setUserInput($);return}this._setUserInput(this.userInput.slice(0,this.cursor)+$+this.userInput.slice(this.cursor))}#Q($){let Z=this.value??"";switch($){case"up":this._cursor=A3(this._cursor,0,-1,Z);return;case"down":this._cursor=A3(this._cursor,0,1,Z);return;case"left":this._cursor=A3(this._cursor,-1,0,Z);return;case"right":this._cursor=A3(this._cursor,1,0,Z);return}}_shouldSubmit($,Z){if(this.#Z)return this.focused==="submit"?!0:(this.#X(`
|
|
41
41
|
`),this._cursor++,!1);let J=this.#$;return this.#$=!0,J&&this.cursor===this.userInput.length?(this.userInput[this.cursor-1]===`
|
|
42
42
|
`&&(this._setUserInput(this.userInput.slice(0,this.cursor-1)+this.userInput.slice(this.cursor)),this._cursor--),!0):(this.#X(`
|
|
43
|
-
`),this._cursor++,!1)}constructor($){let Z=$.initialUserInput??$.initialValue;super({...$,initialUserInput:Z},!1),Z!==void 0&&(this._cursor=Z.length),this.#Z=$.showSubmit??!1,this.on("key",(J,z)=>{if(z?.name&&_J.has(z.name)){this.#$=!1,this.#Q(z.name);return}if(J==="\t"&&this.#Z){this.focused=this.focused==="editor"?"submit":"editor";return}if(z?.name!=="return"){if(this.#$=!1,z?.name==="backspace"&&this.cursor>0){this._setUserInput(this.userInput.slice(0,this.cursor-1)+this.userInput.slice(this.cursor)),this._cursor--;return}if(z?.name==="delete"&&this.cursor<this.userInput.length){this._setUserInput(this.userInput.slice(0,this.cursor)+this.userInput.slice(this.cursor+1));return}J&&(this.#Z&&this.focused==="submit"&&(this.focused="editor"),this.#X(J??""),this._cursor++)}}),this.on("userInput",(J)=>{this._setValue(J)}),this.on("finalize",()=>{this.value||(this.value=$.defaultValue),this.value===void 0&&(this.value="")})}}class F$ extends A1{get userInputWithCursor(){if(this.state==="submit")return this.userInput;let $=this.userInput;if(this.cursor>=$.length)return`${this.userInput}█`;let Z=$.slice(0,this.cursor),J=$.slice(this.cursor,this.cursor+1),z=$.slice(this.cursor+1);return`${Z}${R3("inverse",J)}${z}`}get cursor(){return this._cursor}constructor($){super({...$,initialUserInput:$.initialUserInput??$.initialValue}),this.on("userInput",(Z)=>{this._setValue(Z)}),this.on("finalize",()=>{this.value||(this.value=$.defaultValue),this.value===void 0&&(this.value="")})}}import{styleText as x,stripVTControlCharacters as
|
|
43
|
+
`),this._cursor++,!1)}constructor($){let Z=$.initialUserInput??$.initialValue;super({...$,initialUserInput:Z},!1),Z!==void 0&&(this._cursor=Z.length),this.#Z=$.showSubmit??!1,this.on("key",(J,z)=>{if(z?.name&&_J.has(z.name)){this.#$=!1,this.#Q(z.name);return}if(J==="\t"&&this.#Z){this.focused=this.focused==="editor"?"submit":"editor";return}if(z?.name!=="return"){if(this.#$=!1,z?.name==="backspace"&&this.cursor>0){this._setUserInput(this.userInput.slice(0,this.cursor-1)+this.userInput.slice(this.cursor)),this._cursor--;return}if(z?.name==="delete"&&this.cursor<this.userInput.length){this._setUserInput(this.userInput.slice(0,this.cursor)+this.userInput.slice(this.cursor+1));return}J&&(this.#Z&&this.focused==="submit"&&(this.focused="editor"),this.#X(J??""),this._cursor++)}}),this.on("userInput",(J)=>{this._setValue(J)}),this.on("finalize",()=>{this.value||(this.value=$.defaultValue),this.value===void 0&&(this.value="")})}}class F$ extends A1{get userInputWithCursor(){if(this.state==="submit")return this.userInput;let $=this.userInput;if(this.cursor>=$.length)return`${this.userInput}█`;let Z=$.slice(0,this.cursor),J=$.slice(this.cursor,this.cursor+1),z=$.slice(this.cursor+1);return`${Z}${R3("inverse",J)}${z}`}get cursor(){return this._cursor}constructor($){super({...$,initialUserInput:$.initialUserInput??$.initialValue}),this.on("userInput",(Z)=>{this._setValue(Z)}),this.on("finalize",()=>{this.value||(this.value=$.defaultValue),this.value===void 0&&(this.value="")})}}import{styleText as x,stripVTControlCharacters as cq}from"node:util";import W0 from"node:process";var N4=K4(H$(),1);function IJ(){if(W0.platform!=="win32")return W0.env.TERM!=="linux";return Boolean(W0.env.CI)||Boolean(W0.env.WT_SESSION)||Boolean(W0.env.TERMINUS_SUBLIME)||W0.env.ConEmuTask==="{cmd::Cmder}"||W0.env.TERM_PROGRAM==="Terminus-Sublime"||W0.env.TERM_PROGRAM==="vscode"||W0.env.TERM==="xterm-256color"||W0.env.TERM==="alacritty"||W0.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var RJ=IJ();var y=($,Z)=>RJ?$:Z,D4=y("◆","*"),SJ=y("■","x"),TJ=y("▲","x"),kJ=y("◇","o"),aq=y("┌","T"),n0=y("│","|"),B$=y("└","—"),sq=y("┐","T"),nq=y("┘","—"),iq=y("●",">"),oq=y("○"," "),rq=y("◻","[•]"),tq=y("◼","[+]"),eq=y("◻","[ ]"),$F=y("▪","•"),ZF=y("─","-"),JF=y("╮","+"),zF=y("├","+"),XF=y("╯","+"),GF=y("╰","+"),QF=y("╭","+"),WF=y("●","•"),YF=y("◆","*"),HF=y("▲","!"),UF=y("■","x"),EJ=($)=>{switch($){case"initial":case"active":return x("cyan",D4);case"cancel":return x("red",SJ);case"error":return x("yellow",TJ);case"submit":return x("green",kJ);case"validating":return x("dim",D4)}};var KF=[`${x("dim","↑/↓")} to navigate`,`${x("dim","Space:")} select`,`${x("dim","Enter:")} confirm`];var qF={light:y("─","-"),heavy:y("━","="),block:y("█","#")};var FF=[`${x("dim","↑/↓")} to navigate`,`${x("dim","Enter:")} confirm`];var BF=`${x("gray",n0)} `;var L4=($)=>new F$({validate:$.validate,placeholder:$.placeholder,defaultValue:$.defaultValue,initialValue:$.initialValue,output:$.output,signal:$.signal,input:$.input,render(){let Z=$?.withGuide??Q0.withGuide,J=`${`${Z?`${x("gray",n0)}
|
|
44
44
|
`:""}${EJ(this.state)} `}${$.message}
|
|
45
45
|
`,z=$.placeholder&&$.placeholder.length>0?x("inverse",$.placeholder[0])+x("dim",$.placeholder.slice(1)):x(["inverse","hidden"],"_"),X=this.userInput?this.userInputWithCursor:z,G=this.value??"";switch(this.state){case"validating":{let Q=Z?`${x("cyan",n0)} `:"",W=Z?x("cyan",B$):"",Y=x("dim",X),U=x("dim","Validating...");return`${J}${Q}${Y}
|
|
46
46
|
${W} ${U}
|