anyray-connect 0.11.247 → 0.11.248

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  var RU=Object.defineProperty;var F=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(r){throw n=[r],r}};var ww=(e,t)=>{for(var n in t)RU(e,n,{get:t[n],enumerable:!0})};var OU,ed,ME,_U,TU,He,Tr,jt,bw,PU,tf,lr,Fe,$e=F(()=>{"use strict";OU="http://localhost:8787",ed="anyray-placeholder",ME=/^ark_[A-Za-z0-9_-]{20,512}$/,_U="ark_svc_",TU=/^ark_svc_[A-Za-z0-9_-]{20,512}$/,He=e=>{let t=e?.trim();return!!(t&&ME.test(t))},Tr=e=>{let t=e?.trim();if(t){if(TU.test(t))return"service";if(!t.startsWith(_U))return ME.test(t)?"personal":void 0}},jt=e=>{let t=e.trim().replace(/\/+$/,"");return t=t.replace(/\/v1$/,""),t},bw=(e,t)=>e?.trim()||process.env[t]?.trim()||void 0,PU=new Set(["localhost","127.0.0.1","[::1]","::1","0.0.0.0"]),tf=e=>{try{let{protocol:t,hostname:n}=new URL(e);return t==="http:"&&!PU.has(n)}catch{return!1}},lr=e=>{let t=jt(e||process.env.ANYRAY_GATEWAY_URL||OU),n;try{n=new URL(t)}catch{throw new Error(`invalid gateway URL: "${t}" (expected e.g. http://localhost:8787)`)}if(n.protocol!=="http:"&&n.protocol!=="https:")throw new Error(`invalid gateway URL: "${t}" \u2014 must start with http:// or https://`);return t},Fe=(e={})=>{let t=lr(e.origin),n=e.placeholderKey?.trim()||ed,r=e.clientKey?.trim()||process.env.ANYRAY_CLIENT_KEY?.trim()||void 0,o={user:e.user?.trim()||void 0,team:e.team?.trim()||void 0,intent:bw(e.intent,"ANYRAY_METADATA_INTENT"),intentLabel:bw(e.intentLabel,"ANYRAY_METADATA_INTENT_LABEL"),session:bw(e.session,"ANYRAY_METADATA_SESSION")},a=e.subscription?"subscription":e.placeholder?"placeholder":e.seat?"auto":"placeholder";return{origin:t,anthropicBaseUrl:t,openaiBaseUrl:`${t}/v1`,placeholderKey:n,clientKey:r,keyKind:Tr(r),authMode:a,byoUpstream:e.byoUpstream,seat:a==="auto"?e.seat:void 0,metadata:o}}});var $E,GE,nf,rf=F(()=>{"use strict";$E="/connect/optimize-output",GE=e=>({matcher:"*",hooks:[{type:"http",url:`${e}${$E}`,timeout:2,headers:{"x-anyray-api-key":"$ANYRAY_CLIENT_KEY",Authorization:"Bearer $ANTHROPIC_AUTH_TOKEN"},allowedEnvVars:["ANYRAY_CLIENT_KEY","ANTHROPIC_AUTH_TOKEN"]}]}),nf=e=>{if(!e||typeof e!="object")return!1;let t=e;if(t.type!=="http"||typeof t.url!="string")return!1;try{let n=new URL(t.url);return["http:","https:"].includes(n.protocol)&&n.pathname===$E&&!n.search&&!n.hash}catch{return!1}}});import{randomUUID as NU}from"node:crypto";import{lstat as kw,open as LU,readFile as Cw,rename as of,rm as DU,writeFile as BU}from"node:fs/promises";import{platform as FE}from"node:os";var WE,MU,fa,fs,$U,Oe,nn=F(()=>{"use strict";WE=e=>e?.code==="ENOENT",MU=new Set(["EBUSY","EXDEV","ETXTBSY"]),fa=async(e,t=FE())=>{try{await e.sync()}catch(n){if(t!=="win32")throw n}},fs=class extends Error{recoveryCopy;code="ANYRAY_PUBLISH_CONFLICT";constructor(t){super("destination changed before publication"),this.recoveryCopy=t,this.name="PublishConflictError"}},$U=async(e,t,n={})=>{let r=await Cw(e),o;try{o=await Cw(t)}catch(s){if(!WE(s))throw s;await BU(t,r);return}let a=async s=>{let i=await LU(t,"r+");try{await i.write(s,0,s.length,0),await i.truncate(s.length),await fa(i)}finally{await i.close()}};try{if(await a(r),await n.corruptAfterWrite?.(t),!(await Cw(t)).equals(r))throw Object.assign(new Error("in-place publication did not persist"),{code:"EIO"})}catch(s){throw await a(o).catch(()=>{}),s}},Oe=async(e,t,n=FE(),r={})=>{let o=r.rename??of;if(n!=="win32"){try{await o(e,t)}catch(i){if(!MU.has(i?.code??""))throw i;await $U(e,t,r)}return}let a=`${t}.anyray-old-${process.pid}-${NU()}`,s=!1;try{let i=await kw(t);if(!i.isFile()&&!i.isSymbolicLink())throw new Error("refusing to replace a non-file destination");await of(t,a),s=!0}catch(i){if(!WE(i))throw i}if(s&&r.verifyDisplaced){let i=!1;try{i=await r.verifyDisplaced(a)}catch{i=!1}if(!i){let c=!1;try{await kw(t),c=!0}catch{c=!1}if(c)throw new fs(a);try{await o(a,t)}catch(l){let d=l?.code==="EEXIST";if(!d)try{await kw(t),d=!0}catch{d=!1}throw d?new fs(a):new Error(`destination changed before publication and could not be restored; recovery copy remains at ${a}`,{cause:l})}throw new fs}}try{await of(e,t)}catch(i){if(s)try{await of(a,t)}catch{throw new Error(`failed to publish file and restore the previous destination; recovery copy remains at ${a}`)}throw i}s&&await DU(a,{force:!0})}});import{writeFile as sf,readFile as nd,chmod as Sw,stat as Iw,mkdir as UE,rm as ms}from"node:fs/promises";import{AsyncLocalStorage as GU}from"node:async_hooks";import{randomUUID as FU}from"node:crypto";import{homedir as VE}from"node:os";import{join as hs}from"node:path";var q,cf,Ew,Le,lf,ht,rd,B,WU,HU,KE,UU,VU,af,KU,ZE,ZU,jU,td,Pr,xw,Yt,Aw,Re,Jt,vw,HE,Rw,df,ma,uf,te=F(()=>{"use strict";nn();q=()=>hs(VE(),".anyray"),cf=async()=>{let e=q();try{if((await Iw(e)).isDirectory())return hs(e,"connect.json")}catch{}return e},Ew=()=>hs(q(),"dev-key.pem"),Le=async()=>{let e=q(),t;try{if(!(await Iw(e)).isDirectory())t=await nd(e,"utf-8").catch(()=>{}),await ms(e,{force:!0});else return}catch{}if(await UE(e,{recursive:!0,mode:448}),t!==void 0){let n=hs(e,"connect.json");await sf(n,t,{mode:384}),await Sw(n,384)}},lf=async e=>{await Le();let t=Ew();await sf(t,e,{mode:384}),await Sw(t,384)},ht=async()=>{try{let e=await nd(Ew(),"utf-8");return e.trim()?e:void 0}catch{return}},rd=async()=>{await ms(Ew(),{force:!0}).catch(()=>{})},B=async()=>{try{let e=await nd(await cf(),"utf-8"),t=JSON.parse(e);return t===null||typeof t!="object"||Array.isArray(t)?{}:t}catch{return{}}},WU=0,HU=3e4,KE=5e3,UU=25,VU=()=>hs(VE(),".anyray-connect-profile.lock"),af=new GU,KU=e=>{try{return process.kill(e,0),!0}catch(t){return t.code==="EPERM"}},ZE=async e=>{let t=await nd(hs(e,"owner.json"),"utf-8").catch(()=>{}),n=await Iw(e,{bigint:!0});return{dev:n.dev,ino:n.ino,mtimeNs:n.mtimeNs,owner:t}},ZU=(e,t)=>e.dev===t.dev&&e.ino===t.ino&&e.mtimeNs===t.mtimeNs&&e.owner===t.owner,jU=async(e,t)=>{let n=await ZE(e);if(n.owner!==void 0)try{let o=JSON.parse(n.owner);if(typeof o.pid=="number"&&Number.isSafeInteger(o.pid)&&o.pid>0)return KU(o.pid)?void 0:n}catch{}let r=Number(n.mtimeNs/1000000n);return Date.now()-r>t?n:void 0},td=class extends Error{constructor(t){super(t),this.name="LockBusyError"}},Pr=async(e,t={},n={})=>{let r=t.waitMs??KE,o=t.staleMs??HU,a=hs(e,"owner.json"),s=Date.now()+r;for(;;){let i=FU();try{await UE(e,{mode:448});let l=`${a}.anyray-tmp-${process.pid}-${i}`;try{await sf(l,`${JSON.stringify({pid:process.pid,nonce:i})}
3
3
  `,{flag:"wx",mode:384}),await Oe(l,a)}catch(d){throw await ms(l,{force:!0}).catch(()=>{}),await ms(e,{recursive:!0,force:!0}).catch(()=>{}),d}return async()=>{try{JSON.parse(await nd(a,"utf-8")).nonce===i&&await ms(e,{recursive:!0,force:!0})}catch{}}}catch(l){if(l.code!=="EEXIST")throw l}let c=await jU(e,o).catch(()=>{});if(c){await n.beforeReclaim?.();let l=await ZE(e).catch(()=>{});if(l&&ZU(c,l)&&await ms(e,{recursive:!0,force:!0}).then(()=>!0).catch(()=>!1))continue}if(Date.now()>=s)throw new td(t.busyMessage??`${e} is busy; retry the command`);await new Promise(l=>setTimeout(l,UU))}},xw=(e=KE)=>Pr(VU(),{waitMs:e,busyMessage:"connect profile is busy; retry the command"}),Yt=async(e,t={})=>{if(af.getStore()===!0)return e();let n=await xw(t.waitMs);try{return await af.run(!0,e)}finally{await n()}},Aw=async e=>{let t=Object.fromEntries(Object.entries(e).filter(([,o])=>o!==void 0)),n=await cf(),r=`${n}.${process.pid}.${WU++}.tmp`;await sf(r,`${JSON.stringify(t,null,2)}
4
- `,{mode:384}),await Sw(r,384);try{await Oe(r,n)}catch(o){throw await ms(r,{force:!0}).catch(()=>{}),o}},Re=async e=>{if(af.getStore()===!0){await Aw(e);return}let t=await xw();try{await Aw(e)}finally{await t()}},Jt=async e=>{let t=async()=>{let r=await B(),{next:o,result:a}=e(r);return o&&await Aw(o),a};if(af.getStore()===!0)return t();let n=await xw();try{return await t()}finally{await n()}},vw=["clientKey","clientKeyExpiresAt","enrolledCert","enrolledCertExpiry","enrolledCertLifetimeMs","enrolledTokenHash"],HE="ssoLink",Rw=async()=>{let e=await B();return vw.some(t=>e[t]!==void 0)?!0:await ht()!==void 0},df=async()=>{let e=await B(),t=vw.some(a=>e[a]!==void 0),n=e[HE]!==void 0,r=e.byoUpstream!==void 0,o=await ht()!==void 0;if(t||n||r||e.managedEnrollmentDisabled!==!0){let a={...e};for(let s of vw)delete a[s];delete a[HE],delete a.byoUpstream,a.managedEnrollmentDisabled=!0,delete a.anyrayFleetManaged,await Re(a)}if(await rd(),await ht())throw new Error(`could not remove the dev key from ${q()}`);return t||n||r||o},ma=async(e,t,n=!1,r)=>{await Jt(o=>{let a=new Set(o.managedTools??[]),s=new Set(o.revertedTools??[]),i=new Set(o.blockedTools??[]),c=Array.isArray(o.selectedTools)?o.selectedTools:void 0,l=o.toolSelection,d=o.offboardedAt;for(let v of e){let R=v.status==="configured"||v.status==="queued"||v.status==="manual"&&v.landed===!0;!t&&R&&(a.add(v.id),s.delete(v.id),i.delete(v.id),d=void 0),!t&&v.refused===!0&&i.add(v.id),t&&(v.status==="reverted"||v.status==="queued")&&(a.delete(v.id),s.add(v.id),i.delete(v.id))}if(n&&(a.clear(),i.clear()),r){let v=r.namedToolIds??[];if(n)c=[];else if(t&&c){let R=new Set(c);for(let T of v)R.delete(T);c=[...R].sort()}else if(!t&&v.length>0){let R=new Set(r.knownToolIds),T=new Set((c??[]).filter(x=>R.has(x)));for(let x of v)R.has(x)&&T.add(x);c=[...T].sort()}t||(l=v.length>0?"explicit":"all")}let u=[...a].sort(),p=[...o.managedTools??[]].sort(),f=[...s].sort(),h=[...o.revertedTools??[]].sort(),m=[...i].sort(),g=[...o.blockedTools??[]].sort(),y=(v,R)=>v.length===R.length&&v.every((T,x)=>T===R[x]),w=c===void 0?o.selectedTools===void 0:o.selectedTools!==void 0&&y(c,o.selectedTools);if(y(u,p)&&o.revertedTools!=null&&y(f,h)&&y(m,g)&&w&&l===o.toolSelection&&d===o.offboardedAt)return{result:void 0};let{offboardedAt:A,...k}=o;return{next:{...k,...d!==void 0?{offboardedAt:d}:{},managedTools:u,revertedTools:f,blockedTools:m,selectedTools:c,toolSelection:l},result:void 0}})},uf=async(e=new Date().toISOString())=>{await Re({...await B(),offboardedAt:e})}});var Mn,vt,dr,Bi,$n=F(()=>{"use strict";Mn=(e=process.env)=>e.CODESPACES==="true"||e.CODESPACE_NAME?"codespaces":e.REMOTE_CONTAINERS==="true"||e.REMOTE_CONTAINERS_IPC||e.DEVCONTAINER?"devcontainer":e.SSH_CONNECTION||e.SSH_TTY?"ssh":null,vt=(e=process.env)=>Mn(e)!==null,dr=e=>e==="codespaces"||e==="devcontainer",Bi=e=>{switch(e){case"codespaces":return"a GitHub Codespace";case"devcontainer":return"a dev container";case"ssh":return"an SSH session"}}});var _e,Gn=F(()=>{"use strict";_e="0.11.247"});import{access as YU,chmod as JU,mkdir as Ow,open as Nw,readFile as e0,rm as ur,stat as jE,utimes as XU}from"node:fs/promises";import{createHash as Lw,randomUUID as t0}from"node:crypto";import{readFileSync as n0,statSync as YE}from"node:fs";import{dirname as Dw,join as zU}from"node:path";import{isDeepStrictEqual as Mi}from"node:util";var ha,r0,JE,qU,N,Z,Gi,XE,o0,ya,pf,se,a0,zE,QU,e1,s0,t1,od,_w,Tw,qE,n1,Pw,$i,r1,i0,c0,l0,ff,QE,mf,Io,fe,ye=F(()=>{"use strict";nn();ha=e=>`${e}.anyray-bak`,r0=async e=>{let t;try{t=await Nw(Dw(e),"r"),await t.sync()}catch(n){if(process.platform!=="win32")throw n}finally{await t?.close().catch(()=>{})}},JE=async(e,t)=>{let n,r;try{n=await Nw(e,"wx",384),await n.writeFile(t,"utf-8"),await fa(n)}catch(o){r=o}finally{await n?.close().catch(()=>{})}if(r)throw n&&await ur(e,{force:!0}).catch(()=>{}),r;await r0(e)},qU=async e=>{let t;try{t=await Nw(e,"r"),await fa(t)}finally{await t?.close().catch(()=>{})}await r0(e)},N=async e=>{try{return await YU(e),!0}catch{return!1}},Z=async e=>{if(!await N(e))return{};let t=await e0(e,"utf-8");if(!t.trim())return{};let n=JSON.parse(t);if(n===null||typeof n!="object"||Array.isArray(n))throw new Error(`${e} is not a JSON object`);return n},Gi=class extends Error{constructor(){super("repair deferred: configuration changed before publication")}},XE=e=>`${e.dev}:${e.ino}:${e.size}:${e.mtimeNs}:${e.ctimeNs}`,o0=e=>{try{let t=XE(YE(e,{bigint:!0})),n=n0(e),r=XE(YE(e,{bigint:!0}));if(t!==r)throw new Gi;return{raw:n.toString("utf8"),fingerprint:`${r}:${Lw("sha256").update(n).digest("hex")}`}}catch(t){if(t.code==="ENOENT")return{raw:"",fingerprint:"missing"};throw t}},ya=e=>{let{raw:t,fingerprint:n}=o0(e),r=t.trim()?JSON.parse(t):{};if(r===null||typeof r!="object"||Array.isArray(r))throw new Error("configuration is not a JSON object");return{value:r,fingerprint:n}},pf=async(e,t,n={})=>{for(let r=0;r<3;r++)try{let o=ya(e);if(n.requireExisting&&o.fingerprint==="missing")return"unchanged";let a=JSON.stringify(o.value);return t(o.value),JSON.stringify(o.value)===a?"unchanged":(await se(e,o.value,{backup:n.backup,expectedFingerprint:o.fingerprint}),"written")}catch(o){if(!(o instanceof Gi))throw o}return"repair deferred"},se=async(e,t,n={})=>{await Ow(Dw(e),{recursive:!0,mode:448});let r=ha(e);if(n.backup!==!1&&!await N(r)){let a=await N(e),s=a?await e0(e,"utf-8"):`{}
4
+ `,{mode:384}),await Sw(r,384);try{await Oe(r,n)}catch(o){throw await ms(r,{force:!0}).catch(()=>{}),o}},Re=async e=>{if(af.getStore()===!0){await Aw(e);return}let t=await xw();try{await Aw(e)}finally{await t()}},Jt=async e=>{let t=async()=>{let r=await B(),{next:o,result:a}=e(r);return o&&await Aw(o),a};if(af.getStore()===!0)return t();let n=await xw();try{return await t()}finally{await n()}},vw=["clientKey","clientKeyExpiresAt","enrolledCert","enrolledCertExpiry","enrolledCertLifetimeMs","enrolledTokenHash"],HE="ssoLink",Rw=async()=>{let e=await B();return vw.some(t=>e[t]!==void 0)?!0:await ht()!==void 0},df=async()=>{let e=await B(),t=vw.some(a=>e[a]!==void 0),n=e[HE]!==void 0,r=e.byoUpstream!==void 0,o=await ht()!==void 0;if(t||n||r||e.managedEnrollmentDisabled!==!0){let a={...e};for(let s of vw)delete a[s];delete a[HE],delete a.byoUpstream,a.managedEnrollmentDisabled=!0,delete a.anyrayFleetManaged,await Re(a)}if(await rd(),await ht())throw new Error(`could not remove the dev key from ${q()}`);return t||n||r||o},ma=async(e,t,n=!1,r)=>{await Jt(o=>{let a=new Set(o.managedTools??[]),s=new Set(o.revertedTools??[]),i=new Set(o.blockedTools??[]),c=Array.isArray(o.selectedTools)?o.selectedTools:void 0,l=o.toolSelection,d=o.offboardedAt;for(let v of e){let R=v.status==="configured"||v.status==="queued"||v.status==="manual"&&v.landed===!0;!t&&R&&(a.add(v.id),s.delete(v.id),i.delete(v.id),d=void 0),!t&&v.refused===!0&&i.add(v.id),t&&(v.status==="reverted"||v.status==="queued")&&(a.delete(v.id),s.add(v.id),i.delete(v.id))}if(n&&(a.clear(),i.clear()),r){let v=r.namedToolIds??[];if(n)c=[];else if(t&&c){let R=new Set(c);for(let T of v)R.delete(T);c=[...R].sort()}else if(!t&&v.length>0){let R=new Set(r.knownToolIds),T=new Set((c??[]).filter(x=>R.has(x)));for(let x of v)R.has(x)&&T.add(x);c=[...T].sort()}t||(l=v.length>0?"explicit":"all")}let u=[...a].sort(),p=[...o.managedTools??[]].sort(),f=[...s].sort(),h=[...o.revertedTools??[]].sort(),m=[...i].sort(),g=[...o.blockedTools??[]].sort(),y=(v,R)=>v.length===R.length&&v.every((T,x)=>T===R[x]),w=c===void 0?o.selectedTools===void 0:o.selectedTools!==void 0&&y(c,o.selectedTools);if(y(u,p)&&o.revertedTools!=null&&y(f,h)&&y(m,g)&&w&&l===o.toolSelection&&d===o.offboardedAt)return{result:void 0};let{offboardedAt:A,...k}=o;return{next:{...k,...d!==void 0?{offboardedAt:d}:{},managedTools:u,revertedTools:f,blockedTools:m,selectedTools:c,toolSelection:l},result:void 0}})},uf=async(e=new Date().toISOString())=>{await Re({...await B(),offboardedAt:e})}});var Mn,vt,dr,Bi,$n=F(()=>{"use strict";Mn=(e=process.env)=>e.CODESPACES==="true"||e.CODESPACE_NAME?"codespaces":e.REMOTE_CONTAINERS==="true"||e.REMOTE_CONTAINERS_IPC||e.DEVCONTAINER?"devcontainer":e.SSH_CONNECTION||e.SSH_TTY?"ssh":null,vt=(e=process.env)=>Mn(e)!==null,dr=e=>e==="codespaces"||e==="devcontainer",Bi=e=>{switch(e){case"codespaces":return"a GitHub Codespace";case"devcontainer":return"a dev container";case"ssh":return"an SSH session"}}});var _e,Gn=F(()=>{"use strict";_e="0.11.248"});import{access as YU,chmod as JU,mkdir as Ow,open as Nw,readFile as e0,rm as ur,stat as jE,utimes as XU}from"node:fs/promises";import{createHash as Lw,randomUUID as t0}from"node:crypto";import{readFileSync as n0,statSync as YE}from"node:fs";import{dirname as Dw,join as zU}from"node:path";import{isDeepStrictEqual as Mi}from"node:util";var ha,r0,JE,qU,N,Z,Gi,XE,o0,ya,pf,se,a0,zE,QU,e1,s0,t1,od,_w,Tw,qE,n1,Pw,$i,r1,i0,c0,l0,ff,QE,mf,Io,fe,ye=F(()=>{"use strict";nn();ha=e=>`${e}.anyray-bak`,r0=async e=>{let t;try{t=await Nw(Dw(e),"r"),await t.sync()}catch(n){if(process.platform!=="win32")throw n}finally{await t?.close().catch(()=>{})}},JE=async(e,t)=>{let n,r;try{n=await Nw(e,"wx",384),await n.writeFile(t,"utf-8"),await fa(n)}catch(o){r=o}finally{await n?.close().catch(()=>{})}if(r)throw n&&await ur(e,{force:!0}).catch(()=>{}),r;await r0(e)},qU=async e=>{let t;try{t=await Nw(e,"r"),await fa(t)}finally{await t?.close().catch(()=>{})}await r0(e)},N=async e=>{try{return await YU(e),!0}catch{return!1}},Z=async e=>{if(!await N(e))return{};let t=await e0(e,"utf-8");if(!t.trim())return{};let n=JSON.parse(t);if(n===null||typeof n!="object"||Array.isArray(n))throw new Error(`${e} is not a JSON object`);return n},Gi=class extends Error{constructor(){super("repair deferred: configuration changed before publication")}},XE=e=>`${e.dev}:${e.ino}:${e.size}:${e.mtimeNs}:${e.ctimeNs}`,o0=e=>{try{let t=XE(YE(e,{bigint:!0})),n=n0(e),r=XE(YE(e,{bigint:!0}));if(t!==r)throw new Gi;return{raw:n.toString("utf8"),fingerprint:`${r}:${Lw("sha256").update(n).digest("hex")}`}}catch(t){if(t.code==="ENOENT")return{raw:"",fingerprint:"missing"};throw t}},ya=e=>{let{raw:t,fingerprint:n}=o0(e),r=t.trim()?JSON.parse(t):{};if(r===null||typeof r!="object"||Array.isArray(r))throw new Error("configuration is not a JSON object");return{value:r,fingerprint:n}},pf=async(e,t,n={})=>{for(let r=0;r<3;r++)try{let o=ya(e);if(n.requireExisting&&o.fingerprint==="missing")return"unchanged";let a=JSON.stringify(o.value);return t(o.value),JSON.stringify(o.value)===a?"unchanged":(await se(e,o.value,{backup:n.backup,expectedFingerprint:o.fingerprint}),"written")}catch(o){if(!(o instanceof Gi))throw o}return"repair deferred"},se=async(e,t,n={})=>{await Ow(Dw(e),{recursive:!0,mode:448});let r=ha(e);if(n.backup!==!1&&!await N(r)){let a=await N(e),s=a?await e0(e,"utf-8"):`{}
5
5
  `;if(a||n.tombstoneAbsent!==!1)try{await JE(r,s)}catch(i){if(i.code!=="EEXIST")throw i}}let o=`${e}.anyray-tmp-${process.pid}-${t0()}`;try{if(await JE(o,`${JSON.stringify(t,null,2)}
6
6
  `),n.expectedFingerprint!==void 0){if(o0(e).fingerprint!==n.expectedFingerprint)throw new Gi;let a=n.expectedFingerprint.slice(n.expectedFingerprint.lastIndexOf(":")+1);try{await Oe(o,e,n.runtimePlatform,{verifyDisplaced:async s=>Lw("sha256").update(n0(s)).digest("hex")===a})}catch(s){throw s instanceof fs?new Gi:s}return}await Oe(o,e,n.runtimePlatform),await JU(e,384),await qU(e)}finally{await ur(o,{force:!0}).catch(()=>{})}},a0=1,zE=3e4,QU=5e3,e1=/^[a-f0-9]{64}$/,s0=e=>`${e}.pending`,t1=e=>`${e}.lock`,od=e=>{if(e===void 0)return"null";if(e===null||typeof e!="object")return JSON.stringify(e)??"null";if(Array.isArray(e))return`[${e.map(n=>od(n)).join(",")}]`;let t=e;return`{${Object.keys(t).sort().filter(n=>t[n]!==void 0).map(n=>`${JSON.stringify(n)}:${od(t[n])}`).join(",")}}`},_w=(e,t)=>({exists:e,sha256:Lw("sha256").update(od(t)).digest("hex")}),Tw=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),qE=e=>Tw(e)&&typeof e.exists=="boolean"&&typeof e.sha256=="string"&&e1.test(e.sha256),n1=e=>Tw(e)&&e.transactionVersion===a0&&qE(e.before)&&qE(e.after)&&Tw(e.journal),Pw=(e,t)=>e.exists===t.exists&&e.sha256===t.sha256,$i=async(e,t)=>{try{return await Z(e)}catch{throw new Error(`${t} is malformed; no configuration was changed`)}},r1=e=>{try{return process.kill(e,0),!0}catch(t){return t.code==="EPERM"}},i0=async e=>{let t=t1(e),n=zU(t,"owner.json");await Ow(Dw(t),{recursive:!0,mode:448});for(let r=0;r<2;r++){let o=t0();try{await Ow(t,{mode:448})}catch(s){if(s.code!=="EEXIST")throw s;let i=!1;try{let c=await $i(n,"ownership journal");if(typeof c.pid!="number"||!Number.isSafeInteger(c.pid)||c.pid<=0)throw new Error("lock owner is missing or invalid");let l=Date.now()-(await jE(n)).mtimeMs;i=!r1(c.pid)||l>zE}catch{try{i=Date.now()-(await jE(t)).mtimeMs>zE}catch{i=!1}}if(!i||r>0)throw new Error("ownership transaction already in progress");await ur(t,{recursive:!0,force:!0});continue}try{await se(n,{pid:process.pid,nonce:o,createdAt:Date.now()},{backup:!1})}catch(s){throw await ur(t,{recursive:!0,force:!0}).catch(()=>{}),s}let a=setInterval(()=>{(async()=>{try{if((await $i(n,"ownership journal")).nonce!==o)return;let i=new Date;await XU(n,i,i)}catch{}})()},QU);return a.unref(),async()=>{clearInterval(a);try{(await $i(n,"ownership journal")).nonce===o&&await ur(t,{recursive:!0,force:!0})}catch{}}}throw new Error("ownership transaction already in progress")},c0=async e=>{let t=await N(e),n={};if(t)try{n=await Z(e)}catch{throw new Error("configuration is malformed during ownership recovery; it was left unchanged")}return{exists:t,value:n,fingerprint:_w(t,n)}},l0=async(e,t)=>{let n=s0(t);if(!await N(n))return;let r=await $i(n,"prepared ownership transaction");if(!n1(r))throw new Error("prepared ownership transaction is invalid; no recovery write was attempted");let o=await c0(e),a=await N(t),s=await N(ha(e)),i=Pw(o.fingerprint,r.before),c=Pw(o.fingerprint,r.after),l=r.journal.fileExisted;if(c&&(a||l===!1||s)&&(!i||a||s)){await se(t,r.journal,{backup:!1}),await ur(n,{force:!0});return}if(i){await ur(n,{force:!0}),a||await fe(e);return}throw new Error("configuration changed during an interrupted ownership transaction; recovery files were preserved")},ff=async(e,t,n)=>{let r=await i0(t);try{return await l0(e,t),await n()}finally{await r()}},QE=async(e,t,n,r)=>{if(!await N(e)){if(n)throw new Error("journaled JSON rollback found a missing prior file");return}let a=await $i(e,"ownership journal");if(!(n&&Mi(a,t))){if(!Mi(a,r))throw new Error("journaled JSON rollback found a concurrent file edit");n?await se(e,t,{backup:!1}):await ur(e,{force:!0})}},mf=async(e,t={})=>{let{configPath:n,current:r,next:o,journalPath:a,journal:s,fileExisted:i}=e,c=await i0(a);try{await l0(n,a);let l=await c0(n),d=_w(i,r),u=await N(a),p=u?await $i(a,"ownership journal"):void 0,f=p&&typeof p.fileExisted=="boolean"?{...s,fileExisted:p.fileExisted}:s;if(!Pw(l.fingerprint,d)){if(Mi(l.value,o)&&p&&Mi(p,f))return;throw new Error("configuration changed before the ownership transaction acquired its lock; retry")}if(l.exists&&Mi(l.value,o)&&p&&Mi(p,f))return;let h=await N(ha(n));if(p?.fileExisted===!0&&!h)throw new Error("ownership backup is missing; configuration was left unchanged");if(h&&!p)throw new Error("an unjournaled ownership backup already exists; configuration was left unchanged");let m=s0(a),g={transactionVersion:a0,before:l.fingerprint,after:_w(!0,o),journal:f};await se(m,g,{backup:!1});try{await se(n,o,p?{backup:!1}:{tombstoneAbsent:!1}),await(t.writeJournal??se)(a,f,{backup:!1}),await ur(m,{force:!0})}catch(y){try{await QE(n,l.value,l.exists,o)}catch(w){throw new AggregateError([y,w],"ownership journal publication failed and config rollback was incomplete")}try{await QE(a,p??{},u,f),await ur(m,{force:!0}),!h&&!p&&await fe(n)}catch(w){throw new AggregateError([y,w],"ownership journal publication failed after config rollback")}throw y}}finally{await c()}},Io=async e=>{try{return await Z(ha(e))}catch{return{}}},fe=async e=>{await ur(ha(e),{force:!0}).catch(()=>{})}});var ad,d0,o1,u0,rn,Eo=F(()=>{"use strict";ad=e=>{let t=e.enrolledCert?.payload.keyTtlSeconds;return typeof t=="number"&&Number.isFinite(t)&&t>0?t*1e3:void 0},d0=new Set(["claude-code","codex","opencode","cursor","copilot","copilot-cli","claude-desktop","jetbrains","windsurf","omp"]),o1=10080*60*1e3,u0=(e,t,n=Date.now())=>{let r=[],o=ad(e);o!==void 0&&r.push(o);let a=Date.parse(t??e.clientKeyExpiresAt??"");Number.isFinite(a)&&r.push(a-n);let s=Date.parse(e.enrolledCertExpiry??e.enrolledCert?.payload.expiresAt??"");return Number.isFinite(s)&&r.push(s-n),r.length===0?!1:Math.min(...r)<=o1},rn=(e,t={},n=Date.now())=>{if(!e.enrolledCert)return!1;let o=(t.toolIds??e.managedTools??[]).some(a=>d0.has(a));return u0(e,t.keyExpiresAt,n)||!o}});import{delimiter as a1,dirname as s1}from"node:path";var Nr,ys,Cn,pr=F(()=>{"use strict";St();Nr=e=>{let{command:t,args:n}=Fn([e]);return{command:t,args:n}},ys=()=>gs(),Cn=(e="",t=process.env.PATH??"",n=hf(),r=gs())=>{let a=t.split(a1).filter(Boolean).some(s=>s===n)||s1(r)!==n?"anyray-connect":r;return e?`${a} ${e}`:a}});var Te,Fi=F(()=>{"use strict";Te=(e,t,n=0)=>{let r=e.indexOf(t,n);for(;r>=0;){let o=e.lastIndexOf(`
7
7
  `,r-1)+1,a=e.indexOf(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anyray-connect",
3
- "version": "0.11.247",
3
+ "version": "0.11.248",
4
4
  "description": "Anyray connect \u2014 points local coding tools (Claude Code, Cursor, Windsurf, SDKs) at the Anyray gateway through supported configuration and enrolled personal authentication.",
5
5
  "type": "module",
6
6
  "bin": {