anyray-connect 0.11.152 → 0.11.153

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
@@ -5,7 +5,7 @@ var PR="http://localhost:8787",rs="anyray-placeholder",xe=e=>{let t=e?.trim();re
5
5
  `,{mode:384})}catch(a){throw await Br(e,{recursive:!0,force:!0}).catch(()=>{}),a}return async()=>{try{JSON.parse(await ss(t,"utf-8")).nonce===r&&await Br(e,{recursive:!0,force:!0})}catch{}}}catch(a){if(a.code!=="EEXIST")throw a}if(!(await rO(e).catch(()=>!1)&&await Br(e,{recursive:!0,force:!0}).then(()=>!0).catch(()=>!1))){if(Date.now()>=n)throw new Error("connect profile is busy; retry the command");await new Promise(a=>setTimeout(a,eO))}}},Lg=async e=>{let t=Object.fromEntries(Object.entries(e).filter(([,o])=>o!==void 0)),n=await Mo(),r=`${n}.${process.pid}.${qR++}.tmp`;await hc(r,`${JSON.stringify(t,null,2)}
6
6
  `,{mode:384}),await $u(r,384);try{await he(r,n)}catch(o){throw await Br(r,{force:!0}).catch(()=>{}),o}},oe=async e=>{let t=await Dg();try{await Lg(e)}finally{await t()}},Ng=async e=>{let t=await Dg();try{let n=await L(),{next:r,result:o}=e(n);return r&&await Lg(r),o}finally{await t()}},Nu=["clientKey","clientKeyExpiresAt","enrolledCert","enrolledCertExpiry","enrolledCertLifetimeMs","enrolledTokenHash"],_g="ssoLink",Fu=async()=>{let e=await L();return Nu.some(t=>e[t]!==void 0)?!0:await We()!==void 0},yc=async()=>{let e=await L(),t=Nu.some(a=>e[a]!==void 0),n=e[_g]!==void 0,r=e.byoUpstream!==void 0,o=await We()!==void 0;if(!t&&!n&&!r&&!o)return!1;if(t||n||r){let a={...e};for(let s of Nu)delete a[s];delete a[_g],delete a.byoUpstream,delete a.anyrayFleetManaged,await oe(a)}if(await is(),await We())throw new Error(`could not remove the dev key from ${ee()}`);return!0},$g=["fallback-bundle.enc","fallback-key","fallback-usage-queue.jsonl"],gc=async()=>{let e=ee();for(let t of $g)await Br(Pn(e,t),{force:!0}).catch(()=>{})},Bu=async()=>{let e=ee(),t=[];for(let n of $g){let r=Pn(e,n);try{await ZR(r),t.push(r)}catch{}}return t},rr=async(e,t,n=!1)=>{let r=await L(),o=new Set(r.managedTools??[]),a=new Set(r.revertedTools??[]),s=r.offboardedAt;for(let h of e){let m=h.status==="configured"||h.status==="queued";!t&&m&&(o.add(h.id),a.delete(h.id),s=void 0),t&&(h.status==="reverted"||h.status==="queued")&&(o.delete(h.id),a.add(h.id))}n&&o.clear();let i=[...o].sort(),c=[...r.managedTools??[]].sort(),l=[...a].sort(),d=[...r.revertedTools??[]].sort();if(i.length===c.length&&i.every((h,m)=>h===c[m])&&r.revertedTools!=null&&l.length===d.length&&l.every((h,m)=>h===d[m])&&s===r.offboardedAt)return;let{offboardedAt:f,...p}=r;await oe({...p,...s!==void 0?{offboardedAt:s}:{},managedTools:i,revertedTools:l})},wc=async(e=new Date().toISOString())=>{await oe({...await L(),offboardedAt:e})};var Fo=e=>pO(e).replace(/\\/g,"/").toLowerCase(),Hu=(e=process.platform)=>e==="win32"?"anyray-connect.exe":"anyray-connect",ls=e=>`${e}.source`,Wg=e=>/(^|\/)_npx(\/|$)/.test(Fo(e)),Gu=e=>/(^|\/)node_modules\/anyray-connect\/dist\/index\.js$/.test(Fo(e)),ju=e=>{let t=Fo(e),n=[uO(),"/tmp","/private/tmp","/var/folders","/private/var/folders"].map(Fo);return Wg(t)||n.some(r=>t===r||t.startsWith(`${r}/`))},yt=()=>({execPath:process.execPath,scriptPath:process.argv[1]}),ds=e=>/[\\/](node|node\.exe)$/i.test(e),or=(e=yt())=>ds(e.execPath)&&e.scriptPath?e.scriptPath:e.execPath,Ug=e=>{try{let t=Fg(e);return t.isFile()?t.size:void 0}catch{return}},Vu=e=>{let t=Ge(e);if(Uo(t)==="versions")return t;let n=Ge(t);return Uo(n)==="versions"?n:void 0},kc=(e,t)=>t!==void 0&&(Ge(e)===t||Ge(Ge(e))===t),fO=e=>{let t=Vu(e);if(!t)return;let n=Ie(Ge(t),"bin",Hu());try{let r=cs(n);return r===cs(e)||kc(r,cs(t))?n:void 0}catch{return}},Bo=(e=ee(),t=process.platform)=>{let n=Ie(e,"bin",Hu(t));try{let r=cs(n),o=cs(Ie(e,"versions"));if(kc(r,o))return n;if(t==="win32"){let a=aO(ls(n),"utf8").trim();if(!/^[0-9A-Za-z.-]+$/.test(a))return;let s=Ug(Ie(o,a,Hu(t)))??Ug(Ie(o,a));if(s!==void 0&&s===Fg(n).size)return n}}catch{return}},Wr=(e=yt())=>{let t=or(e),n=Gu(t)||Zu(t)?Bo():void 0;return fO(e.execPath)??n??t},Hg=(e=yt())=>Wr(e)!==or(e),pn=(e,t=yt())=>{let n=Wr(t);return ds(t.execPath)&&t.scriptPath!==void 0&&n===or(t)?{command:t.execPath,args:[n,...e],entryPath:n}:{command:n,args:e,entryPath:n}},Kg=(e=yt())=>{let t=Wr(e);return!ds(e.execPath)&&!ju(t)?Ge(t):Ie(ee(),"bin")},bc=async e=>{try{return await sO(e),!0}catch{return!1}},hO=async e=>{let t=await cO(e),n=Ge(t),r=Ge(n),o=Ie(r,"package.json"),a=await Ku(o,"utf8"),s=JSON.parse(a);if(typeof s.version!="string"||!/^[0-9A-Za-z][0-9A-Za-z.-]*$/.test(s.version))throw new Error("published package has no safe version");if(!await bc(Ie(n,"index.js")))throw new Error("published package is missing dist/index.js");return{root:r,dist:n,packageJson:o,version:s.version}},mO=async(e,t)=>{let n=t;for(;;){let r=Ie(n,"node_modules",e);if(await bc(Ie(r,"package.json")))return r;let o=Ge(n);if(o===n)return;n=o}},yO=async(e,t)=>{let n=new Set,r=[e];for(;r.length>0;){let o=r.shift(),a=JSON.parse(await Ku(Ie(o,"package.json"),"utf8"));for(let s of Object.keys(a.dependencies??{})){if(n.has(s))continue;n.add(s);let i=await mO(s,o);if(!i)throw new Error(`runtime dependency "${s}" is not installed`);await Bg(i,Ie(t,s),{recursive:!0}),r.push(i)}}},gO=async(e=yt())=>{let t=Bo();if(t)return{command:t,args:[],entryPath:t};if(!ds(e.execPath)||!e.scriptPath)return{command:e.execPath,args:[],entryPath:e.execPath};let n=await hO(e.scriptPath);await Ct();let r=Ie(ee(),"bin",`connect-runtime-${n.version}`),o=Ie(r,"dist","index.js");if(!await bc(o)){let a=`${r}.stage-${process.pid}-${Date.now()}`;await Wu(a,{recursive:!0,force:!0}),await Mg(a,{recursive:!0,mode:448});try{await Bg(n.dist,Ie(a,"dist"),{recursive:!0}),await dO(Ie(a,"package.json"),await Ku(n.packageJson),{mode:384}),await yO(n.root,Ie(a,"node_modules")),await Mg(Ge(r),{recursive:!0,mode:448});try{await lO(a,r)}catch(s){if(!await bc(o))throw s}}finally{await Wu(a,{recursive:!0,force:!0})}}return{command:e.execPath,args:[o],entryPath:o}},Yu=/^connect-runtime-(?!.*\.stage-)[0-9A-Za-z][0-9A-Za-z.-]*$/,wO=e=>{let t=Uo(Ge(Ge(e)));return Yu.test(t)?t:void 0},Zu=(e,t=ee())=>{let n=Ge(Ge(e));return Fo(Ge(n))===Fo(Ie(t,"bin"))&&Yu.test(Uo(n))&&Uo(Ge(e))==="dist"&&Uo(e)==="index.js"},Cc=async(e=yt())=>{let t=Ie(ee(),"bin"),n=wO(or(e)),r=[];for(let o of await iO(t).catch(()=>[])){if(!Yu.test(o)||o===n)continue;let a=Ie(t,o);await Wu(a,{recursive:!0,force:!0}).then(()=>!0,()=>!1)&&r.push(a)}return r},Gg=async(e,t=yt())=>{let n=or(t);if(!ds(t.execPath)||!Wg(n)||Bo())return;let r=await gO(t),o=oO(r.command,[...r.args,...e],{stdio:"inherit",env:process.env});if(o.error)throw o.error;return o.status??1};var Ju=e=>/^[A-Za-z0-9_./:=-]+$/.test(e)?e:`"${e.replace(/"/g,'\\"')}"`,us=(e,t)=>[e,...t].map(Ju).join(" "),Tn=(e,t={})=>({...t.matcher!==void 0?{matcher:t.matcher}:{},hooks:[{type:"command",command:e,...t.timeout!==void 0?{timeout:t.timeout}:{},...t.async!==void 0?{async:t.async}:{}}]}),ar=(e,t)=>{if(e===null||typeof e!="object")return!1;let n=e.hooks;return Array.isArray(n)&&n.some(r=>r!==null&&typeof r=="object"&&typeof r.command=="string"&&r.command.includes(t))},Ac=(e,t,n,r,o="append")=>{let a=e.hooks??{},i=(Array.isArray(a[t])?a[t]:[]).filter(c=>!ar(c,n));a[t]=o==="prepend"?[r,...i]:[...i,r],e.hooks=a},Wo=(e,t,n)=>{let r=e.hooks;if(!r||!Array.isArray(r[t]))return!1;let o=r[t],a=o.filter(s=>!ar(s,n));return a.length===o.length?!1:(a.length?r[t]=a:delete r[t],Object.keys(r).length===0&&delete e.hooks,!0)},Xu=e=>{let t=e.hooks;if(!t)return!1;let n=!1;for(let[r,o]of Object.entries(t)){if(!Array.isArray(o))continue;let a=o.filter(s=>!ar(s,"__anyray-"));a.length!==o.length&&(n=!0,a.length?t[r]=a:delete t[r])}return n&&Object.keys(t).length===0&&delete e.hooks,n};var Xe="__anyray-hook",jg="__anyray-codex-hook",sr="__anyray-prompt-hook",Vg="__anyray-shell-pretool",qu="__anyray-shell-run",Yg="__anyray-read-pretool",ir="__anyray-refresh",ps=(e,t=[])=>{let{command:n,args:r}=pn([e,...t]);return{command:n,args:r}},Dt=(e,t=[])=>{let n=ps(e,t);return[n.command,...n.args].map(Ju).join(" ")},vc=(e,t,n=[])=>typeof e=="string"&&e.trim()===Dt(t,n),Zg=()=>Dt("print-key"),Re=()=>Wr(),je=ju,le=()=>!je(Re()),Hr=async()=>{if(!le())return!1;try{return await bO(Re()),!0}catch{return!1}},cr="__anyray-mcp-server",Ve=e=>ps(cr,[e]),kO=(e,t)=>Array.isArray(e)&&e.length===t.length&&e.every((n,r)=>n===t[r]),Sc=(e,t)=>{if(!e||typeof e!="object"||Array.isArray(e))return!1;let n=e,r=Ve(t);return n.command===r.command&&kO(n.args,r.args)},zt=(e,t)=>{if(!e||typeof e!="object"||Array.isArray(e))return!1;let n=e;if(typeof n.command!="string"||!Array.isArray(n.args)||!n.args.every(o=>typeof o=="string"))return!1;let r=n.args;return(r.length===2||r.length===3)&&r.at(-2)===cr&&r.at(-1)===t};var X=(e,t)=>e.authMode==="subscription"?!0:e.authMode==="placeholder"?!1:e.seat?.[t]??!1,de=e=>{let t=Object.entries(e).filter(([,n])=>n);if(t.length!==0)return JSON.stringify(Object.fromEntries(t))};var Kr=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN","ANTHROPIC_CUSTOM_HEADERS","ENABLE_TOOL_SEARCH","_CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL"],Jg=["ENABLE_TOOL_SEARCH","_CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL"],Ec=[...Kr,"CLAUDE_CODE_MAX_CONTEXT_TOKENS","CLAUDE_CODE_USE_BEDROCK","CLAUDE_CODE_USE_VERTEX"],CO=(e,t,n,r)=>{let o=[];return(t||r)&&(o.push("x-anyray-provider: anthropic"),o.push("x-anyray-auth-mode: passthrough"),r&&o.push(`x-anyray-custom-host: ${r}`),n&&o.push(`x-anyray-api-key: ${n}`)),e&&o.push(`x-anyray-metadata: ${e}`),o.join(`
7
7
  `)},fn=(e,t={})=>{let n=e.byoUpstream,r=!n&&X(e,"anthropic"),o=de({...e.metadata,tool:e.metadata.tool??"claude-code"}),a=t.includeClientKey!==!1&&!((r||n)&&e.viaLocalProxy),s=t.includeAuthToken!==!1,{contextWindowTokens:i}=t,c=CO(o,r,a?e.clientKey:void 0,n?.url);return{env:{ANTHROPIC_BASE_URL:e.anthropicBaseUrl,...c?{ANTHROPIC_CUSTOM_HEADERS:c}:{},...n&&s?{ANTHROPIC_AUTH_TOKEN:n.key}:{},...r||n||!s?{}:{ANTHROPIC_AUTH_TOKEN:e.clientKey??e.placeholderKey},...n?{}:{ENABLE_TOOL_SEARCH:"true"},...n?{}:{_CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL:"1"},...i!==void 0?{CLAUDE_CODE_MAX_CONTEXT_TOKENS:String(i)}:{}},subscription:r,byoUpstream:!!n,meta:o,headers:c}};import{z as zu}from"zod";var AO=5e3,vO=1e3,SO=1e8,EO=zu.object({modelContext:zu.object({contextTokens:zu.number().int().min(vO).max(SO)}).optional()}),Xg=e=>{let t=e.model;if(typeof t!="string")return;let n=t.trim();return n.length>0?n:void 0},qg=async(e,t,n,r={})=>{if(!t||!n)return;let o=r.timeoutMs??AO,a=new AbortController,s=setTimeout(()=>a.abort(),o);try{let i=`${e}/connect/policy?model=${encodeURIComponent(n)}`,c=await fetch(i,{method:"GET",headers:{"x-anyray-api-key":t},signal:a.signal});if(!c.ok)return;let l=EO.safeParse(await c.json());return l.success?l.data.modelContext?.contextTokens:void 0}catch{return}finally{clearTimeout(s)}};var xO=1e6,fs="[1m]",IO=e=>{let t=e.trim().toLowerCase();return!(t.startsWith("claude-")||t.split(/[/.]/).some(r=>r.startsWith("claude-")))},zg=(e,t)=>!e||t===void 0?{}:IO(e)?{envTokens:t}:t<xO?{}:e.toLowerCase().endsWith(fs)?{}:{model:`${e}${fs}`},Qg=(e,t)=>{if(!(!e||!e.toLowerCase().endsWith(fs))&&typeof t=="string"&&!t.trim().toLowerCase().endsWith(fs))return e.slice(0,-fs.length)};import{platform as RO}from"node:os";var Lt=(e=RO())=>{switch(e){case"darwin":return"/Library/Application Support/ClaudeCode/managed-settings.json";case"win32":return"C:\\Program Files\\ClaudeCode\\managed-settings.json";default:return"/etc/claude-code/managed-settings.json"}};var Dn=[{name:"CLAUDE_CODE_USE_BEDROCK",cloud:"AWS Bedrock"},{name:"CLAUDE_CODE_USE_VERTEX",cloud:"Google Vertex AI"}],xc=e=>typeof e=="string"&&e.trim()!=="",OO=(e,t)=>typeof e[t]=="string"&&!xc(e[t]),ew=e=>{let t=e.env;return t&&typeof t=="object"&&!Array.isArray(t)?t:{}},_O=()=>F(Lt()).catch(()=>({})),tw=async(e={})=>{let t=e.env??process.env,n=ew(e.userSettings??{}),r=ew(await(e.readManaged??_O)().catch(()=>({}))),o=[];for(let{name:a,cloud:s}of Dn)xc(r[a])?o.push({name:a,cloud:s,kind:"managed",source:`managed settings (${Lt()})`,repairable:!1}):xc(n[a])?o.push({name:a,cloud:s,kind:"userSettings",source:"~/.claude/settings.json env block",repairable:!0}):!OO(n,a)&&xc(t[a])&&o.push({name:a,cloud:s,kind:"shell",source:"shell environment",repairable:!0});return o},Qu=e=>`${e.name} is set (${e.source}) \u2014 Claude Code sends requests straight to ${e.cloud} and ignores the gateway routing written here, so none of its traffic reaches Anyray until that setting is removed`,ep=e=>"Fix: remove the setting where it is set"+(e.some(t=>t.kind==="managed")?" (the managed settings file is IT-owned \u2014 ask your admin)":"")+", then restart Claude Code. The gateway can serve Bedrock/Vertex itself once its provider is configured \u2014 see the Bedrock page in the Anyray docs.",nw=e=>`Disabled direct ${e.cloud} mode: ${e.name} was set (${e.source}), which would bypass the gateway route entirely \u2014 pinned it empty in settings.json (the env block outranks shell exports, and '' is Claude Code's documented unset). Delete the original setting to drop the pin.`;var PO=Dn.map(e=>e.name),TO=Ec.filter(e=>!PO.includes(e)),rw=e=>typeof e=="string"&&e.trim()!=="",ow=e=>{let t=e.env;return t&&typeof t=="object"&&!Array.isArray(t)?t:{}},DO=(e,t,n)=>{if(typeof e!="string"||typeof t!="string")return!1;let r=o=>n?o.trim().replace(/\/+$/,""):o.trim();return r(e)===r(t)},LO=e=>{if(typeof e=="string")try{return new URL(e.trim()).origin}catch{return}},tp=()=>F(Lt()).catch(()=>({})),aw=tp,NO=e=>{let t=e.hooks;if(!t||typeof t!="object"||Array.isArray(t))return!1;let n=t.PostToolUse;return Array.isArray(n)&&n.some(r=>ar(r,Xe))},sw=async(e={})=>{let t=await(e.readManaged??aw)().catch(()=>({}));return t.disableAllHooks===!0?{state:"disabled"}:t.allowManagedHooksOnly===!0&&!NO(t)?{state:"restricted_dropping_ours"}:{state:"fine"}},Ic=e=>e.state==="disabled"?`disableAllHooks is true in managed settings (${Lt()}) \u2014 Claude Code skips every hook and the status line, including Anyray's savings hook`:e.state==="restricted_dropping_ours"?`allowManagedHooksOnly is true in managed settings (${Lt()}), but that file does not carry the Anyray PostToolUse hook \u2014 Claude Code silently drops the user-scope hook Connect installed`:"Claude Code managed hook policy allows the Anyray hook lane",Rc=e=>e.state==="disabled"?"Fix: ask the MDM owner to drop `disableAllHooks`, then restart Claude Code. Connect never overrides machine policy.":e.state==="restricted_dropping_ours"?"Fix: ask the MDM owner to drop `allowManagedHooksOnly`, or add the Anyray hooks to the managed file. `anyray-connect managed --print --sso <link> --bin <path>` emits the credential-free block; then restart Claude Code.":"No action required.",iw=async(e={})=>{let t=ow(e.userSettings??{}),n=ow(await(e.readManaged??aw)().catch(()=>({}))),r=[];for(let o of TO){if(!rw(n[o])||!rw(t[o]))continue;let a=o==="ANTHROPIC_BASE_URL";if(DO(n[o],t[o],a))continue;let s=a?LO(n[o]):void 0;r.push({name:o,source:`managed settings (${Lt()})`,routing:a,...s?{managedOrigin:s}:{}})}return r},cw=e=>e.routing?`${e.name} is set to a different value (${e.source}), which outranks the routing written in settings.json \u2014 Claude Code sends its traffic to ${e.managedOrigin??"that endpoint"} instead, so none of it reaches Anyray until the managed value changes`:`${e.name} is set to a different value (${e.source}), which outranks the value written in settings.json \u2014 Claude Code uses the managed one, so the behavior this key controls is not the one connect configured`,lw=e=>"Fix: the managed settings file is IT-owned \u2014 ask your admin to "+(e.some(t=>t.routing)?"point it at the Anyray gateway (`anyray-connect managed --print` emits the block to deploy) or drop the key so per-user setup governs":"drop the key so per-user setup governs")+", then restart Claude Code.";import{homedir as $O}from"node:os";import{join as MO}from"node:path";import{readFile as UO}from"node:fs/promises";var ot=e=>!!e.keyRefreshEnabled;var FO=400,dw=async()=>{try{let e=MO($O(),".claude","settings.json"),n=JSON.parse(await UO(e,"utf-8"))?.env,r=n?.ANTHROPIC_BASE_URL;if(!r)return null;let o=new URL(r).origin,a=n?.ANTHROPIC_CUSTOM_HEADERS??"",s=l=>{for(let d of a.split(`
8
- `)){let u=d.indexOf(":");if(u>0&&d.slice(0,u).trim().toLowerCase()===l)return d.slice(u+1).trim()}},i=s("x-anyray-api-key"),c=n?.ANTHROPIC_AUTH_TOKEN;return{origin:o,metadata:s("x-anyray-metadata"),apiKey:i||(c?.startsWith("ark_")?c:void 0)}}catch{return null}},uw=async()=>{try{let e=await L();return e.gateway?{origin:new URL(e.gateway).origin,metadata:de({user:e.name,team:e.team}),apiKey:e.clientKey}:null}catch{return null}},at=async(e="auto")=>e==="profile"?uw():e==="claude"?dw():await dw()??await uw(),Oc=async(e={})=>{let t=e.readTarget??at,n=e.loadProfile??L,r;try{r=await n()}catch{return"unreadable"}if(!r.gateway)return"unreadable";let o;try{o=await t("claude")}catch{return"unreadable"}if(!o)return"missing";let a=new Set;try{a.add(new URL(r.gateway).origin)}catch{return"unreadable"}return ot(r)&&r.fallbackPort&&a.add(`http://${mt}:${r.fallbackPort}`),a.has(o.origin)?"owned":"foreign"},Qt=e=>{let t={"content-type":"application/json"};return e.metadata&&(t["x-anyray-metadata"]=e.metadata),e.apiKey&&(t["x-anyray-api-key"]=e.apiKey),t},_c=async(e,t,n,r)=>{if(!e)return;let o=new AbortController,a=setTimeout(()=>o.abort(),FO);try{await fetch(`${e.origin}/connect/hook-savings`,{method:"POST",headers:Qt(e),body:JSON.stringify({source:t,...r?{tool:r}:{},...n}),signal:o.signal})}catch{}finally{clearTimeout(a)}};var Ln=()=>Tc(Pc(),".claude","settings.json"),hs=()=>Tc(Pc(),".claude.json"),BO=Ec,lr="anyray",WO=()=>({type:"stdio",...Ve("claude"),alwaysLoad:!0}),Gr=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),HO=e=>{if("mcpServers"in e&&!Gr(e.mcpServers))return"conflict";let t=Gr(e.mcpServers)?{...e.mcpServers}:{},n=t[lr];return n!==void 0&&!zt(n,"claude")?"conflict":(t[lr]=WO(),e.mcpServers=t,"installed")},pw=e=>{let t=e.mcpServers;return!t||!(lr in t)||!zt(t[lr],"claude")?!1:(delete t[lr],Object.keys(t).length===0&&delete e.mcpServers,!0)},KO=e=>{Ac(e,"PostToolUse",Xe,Tn(Dt(Xe),{matcher:"*"})),Ac(e,"UserPromptSubmit",sr,Tn(Dt(sr)))},GO=e=>{Ac(e,"SessionStart",ir,Tn(Dt(ir),{async:!0}))},mw=e=>Wo(e,"SessionStart",ir),fw=e=>{let t=Wo(e,"PostToolUse",Xe),n=Wo(e,"UserPromptSubmit",sr),r=mw(e);return t||n||r},jO="print-key",VO=e=>e.includes("anyray-connect")||e.includes("connect-runtime")||e.includes(Re()),jr=e=>{let t=e.apiKeyHelper;if(typeof t!="string")return!1;let n=t.trim().split(/\s+/);return n[n.length-1]===jO&&VO(t)},YO=async(e,t)=>{let n=(await Fr(e)).env,r=n&&typeof n=="object"&&!Array.isArray(n)?n:{},o=[];for(let a of BO){let s=r[a];typeof s=="string"?(t[a]=s,o.push(a)):delete t[a]}return o},ZO=e=>typeof e.apiKeyHelper=="string"&&!jr(e),yw=async e=>{let t=await tp(),n=async()=>t,[r,o,a]=await Promise.all([tw({userSettings:e,readManaged:n}),iw({userSettings:e,readManaged:n}).catch(()=>[]),sw({readManaged:n})]);return{directOverrides:r,managedOverrides:o,hookPolicy:a}},hw=async e=>{let{directOverrides:t,managedOverrides:n,hookPolicy:r}=await yw(e),o=ep(t),a=lw(n);return{routingOverrides:[...t.map(i=>({problem:Qu(i),fix:i.repairable?"Fix: run `anyray-connect doctor --repair` (or re-run `anyray-connect`) \u2014 apply disables this switch by pinning it empty in settings.json.":o,repairable:i.repairable})),...n.map(i=>({problem:cw(i),fix:a,repairable:!1,bypass:i.routing}))],claudeCodeHookPolicy:r.state}},dr={id:"claude-code",title:"Claude Code",automatic:!0,async detect(){let e=Tc(Pc(),".claude"),t=await R(e);return{installed:t,detail:t?Ln():"no ~/.claude directory"}},async apply(e,t){let n=Ln(),r=await F(n),o=Xg(r),a=await qg(e.origin,e.clientKey,o),s=zg(o,a),{env:i,subscription:c,byoUpstream:l,meta:d,headers:u}=fn(e,{contextWindowTokens:s.envTokens}),{directOverrides:f,hookPolicy:p}=await yw(r),h=f.filter(I=>!I.repairable),m=f.filter(I=>I.repairable),w=[...h.map(I=>`WARNING: ${Qu(I)}.`),...h.length?[ep(h)]:[],...p.state==="fine"?[]:[`WARNING: ${Ic(p)}.`,Rc(p)],...m.map(I=>nw(I)),`${n} \u2192 env.ANTHROPIC_BASE_URL = ${e.anthropicBaseUrl}`,l?`BYO-upstream mode: your personal upstream key passes through the gateway to ${e.byoUpstream.url} (never the org key).${e.clientKey?" Your personal gateway key rides x-anyray-api-key.":""}`:c?`Subscription mode: Claude Code keeps your seat sign-in; its OAuth token passes through the gateway (never stored).${e.clientKey?" Your personal gateway key rides x-anyray-api-key.":""}`:e.clientKey?"Auth: personal gateway key (not shown here; see below for where it lives)":"Auth: placeholder token (gateway swaps in the server-held key)",`Attribution: ${d??"(none)"}`,...l?[]:["Restored on-demand MCP tool loading (env.ENABLE_TOOL_SEARCH) that Claude Code otherwise disables behind a non-first-party gateway. Deferred servers stay out of context until used; the first-party AnyRay retrieval server stays always loaded so capability is visible per request."],...s.envTokens!==void 0?[`Context window: env.CLAUDE_CODE_MAX_CONTEXT_TOKENS = ${s.envTokens} \u2014 your model's real window, so Claude Code stops budgeting the 200k it assumes behind any custom base URL.`]:[],...s.model!==void 0?[`Context window: model = ${s.model} \u2014 same model, its long-context variant. Claude Code ignores CLAUDE_CODE_MAX_CONTEXT_TOKENS for claude-* ids, so the [1m] alias is what actually gets you your ${a} window back instead of the 200k it assumes behind any custom base URL. A --model flag on your launch command, or picking a model in-app, overrides this \u2014 add [1m] there too (quote it in zsh).`]:[],"Claude Code settings.json routing covers the CLI and VS Code extension. Claude Desktop is separate: its verified macOS automatic setup supports either the Claude Code subscription-backed Gateway lane or API billing; other Desktop lanes fail closed or use the documented API setup.","Restart Claude Code (or open a new session) to pick up the change."];if(t.dryRun)return{status:"configured",messages:w};s.model!==void 0&&(r.model=s.model);let g=r.env??{};r.env={...g,...i};let y=r.env;for(let{name:I}of Dn)m.some(P=>P.name===I)?y[I]="":y[I]===""&&(process.env[I]??"").trim()===""&&delete y[I];if(u||delete y.ANTHROPIC_CUSTOM_HEADERS,c&&(g.ANTHROPIC_AUTH_TOKEN&&w.push("Removed env.ANTHROPIC_AUTH_TOKEN \u2014 it would override your subscription sign-in."),delete y.ANTHROPIC_AUTH_TOKEN),l)for(let I of Jg)delete y[I];let b=!!e.clientKey,A=le(),v=ZO(r);!c&&!l&&b&&A&&!v?(r.apiKeyHelper=Zg(),y.ANTHROPIC_AUTH_TOKEN="",w.push("Installed an apiKeyHelper that reprints a fresh gateway key on demand \u2014 Claude Code refreshes it at startup and on any 401, so an idle session no longer 401s (no re-enrollment).")):jr(r)&&delete r.apiKeyHelper,v&&!c&&!l&&b&&A&&w.push("Kept your existing apiKeyHelper; your gateway key stays in ANTHROPIC_AUTH_TOKEN (Anyray auto-refresh via the helper is off)."),(c||l)&&b&&A?(GO(r),w.push("Installed a SessionStart hook that refreshes your gateway key each session, so an idle subscription session no longer needs re-enrollment.")):mw(r),le()?(KO(r),w.push("Installed a PostToolUse hook (trims oversized tool outputs, cache-safe) and a UserPromptSubmit hook (beacons oversized pasted-data prompts) \u2014 both content-free.")):(fw(r),w.push(`Skipped the Anyray hooks \u2014 anyray-connect is running from a temporary path (${Re()}). Re-run via the installer (it persists the binary under ~/.anyray/bin) or a global install to enable cache-safe trimming and paste-savings beacons.`)),await J(n,r);let x=[n],C=hs();try{let I=await F(C),P=!1;le()?HO(I)==="conflict"?w.push(`MCP name conflict in ${C}: mcpServers.${lr} is not owned by Anyray Connect, so it was left untouched.`):(P=!0,w.push("Registered the Anyray retrieval MCP server (anyray_retrieve) for explicit recovery of stashed context \u2014 always loaded so retrieval capability is visible on every request.")):P=pw(I),P&&(await J(C,I),x.push(C))}catch(I){w.push(`Could not register the Anyray MCP server in ${C} (${I instanceof Error?I.message:String(I)}); retrieval via anyray_retrieve is unavailable until this is fixed.`)}return{status:"configured",messages:w,changedFiles:x}},skillsDir(){return Tc(Pc(),".claude","skills")},async watchPaths(){return[Ln(),hs()]},async pointsAt(e){let t=Ln();if(!await R(t))return!1;try{let o=(await F(t)).env?.ANTHROPIC_BASE_URL;return typeof o=="string"&&o.replace(/\/+$/,"")===e}catch{return!1}},async runtimeDiagnostics(){let e=await F(Ln()).catch(()=>({}));return hw(e)},async routingOverrides(){let e=await F(Ln()).catch(()=>({}));return(await hw(e)).routingOverrides},async mcpStatus(){let e=hs();if(!await R(e))return{registered:!1,command:null};try{let r=(await F(e)).mcpServers?.[lr];return!r||!zt(r,"claude")?{registered:!1,command:null}:{registered:!0,command:typeof r.command=="string"?r.command:null}}catch{return{registered:!1,command:null}}},async integrationStatus(){let e,t=!0,n=Ln();if(!await R(n))e="missing";else try{let s=await F(n);if(s.hooks===void 0)e="missing";else if(!Gr(s.hooks))e="unreadable";else{let i=s.hooks.PostToolUse;e=i===void 0?"missing":Array.isArray(i)?i.some(c=>ar(c,Xe))?"owned":"missing":"unreadable",e==="owned"&&Array.isArray(i)&&(t=i.some(c=>ar(c,Xe)&&Gr(c)&&Array.isArray(c.hooks)&&c.hooks.some(l=>Gr(l)&&vc(l.command,Xe))))}}catch{e="unreadable"}let r,o=!0,a=hs();if(!await R(a))r="missing";else try{let s=await F(a);if(s.mcpServers===void 0)r="missing";else if(!Gr(s.mcpServers))r="unreadable";else{let i=s.mcpServers[lr];r=i===void 0?"missing":zt(i,"claude")?"owned":"foreign",r==="owned"&&(o=Sc(i,"claude"))}}catch{r="unreadable"}return{hook_registration:e,mcp_registration:r,hook_binary:t&&o&&await Hr()?"owned":"missing",beacon_target:await Oc().catch(()=>"unreadable")}},async inferenceAuthLanes(){try{let e=await F(Ln()),t=Gr(e.env)?e.env:{},n=typeof t.ANTHROPIC_CUSTOM_HEADERS=="string"?t.ANTHROPIC_CUSTOM_HEADERS:"";if(/^x-anyray-custom-host:/m.test(n))return["byo"];if(/^x-anyray-auth-mode:\s*passthrough$/m.test(n))return["subscription"];if(typeof t.ANTHROPIC_AUTH_TOKEN=="string"||typeof e.apiKeyHelper=="string")return["api_key"]}catch{}return["unknown"]},async revert(e){let t=Ln();if(!await R(t))return{status:"not-found",messages:["nothing to revert"]};if(e.dryRun)return{status:"reverted",messages:[`would remove Anyray keys from ${t}`]};let n=await F(t),r=n.env,o=fw(n),a=jr(n);a&&delete n.apiKeyHelper;let s=r?await YO(t,r):[],i=Qg(typeof n.model=="string"?n.model:void 0,(await Fr(t)).model);i!==void 0&&(n.model=i),r&&Object.keys(r).length===0&&delete n.env,(r||o||a||i!==void 0)&&await J(t,n,{backup:!1});let c=[`removed Anyray keys from ${t}`];i!==void 0&&c.push(`Put model back to ${i} \u2014 dropped the [1m] alias Anyray added for your context window.`),o&&c.push("Removed the Anyray PostToolUse, UserPromptSubmit, and SessionStart hooks."),a&&c.push("Removed the Anyray apiKeyHelper."),s.length&&c.push(`Put back the ${s.join(" and ")} you had set before Anyray.`);let l=hs();try{let d=await F(l);pw(d)&&(await J(l,d,{backup:!1}),c.push("Removed the Anyray retrieval MCP server (anyray_retrieve)."))}catch{}return await se(t),{status:"reverted",messages:c,changedFiles:[t]}}};var we="0.11.152";var hn=e=>{let{command:t,args:n}=pn([e]);return{command:t,args:n}},ur=()=>Wr();import{homedir as gw,userInfo as JO}from"node:os";var ms=()=>{try{return gw()!==JO().homedir}catch{return!1}},Ho=e=>[`Skipped ${e} \u2014 HOME (${gw()}) is not this account's home directory.`,"The OS registers a per-user service against the account, not against HOME, so","one installed from here would point at a path the real login session cannot use."];var gt=(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,Vr=(e=process.env)=>gt(e)!==null,At=e=>e==="codespaces"||e==="devcontainer",pr=e=>{switch(e){case"codespaces":return"a GitHub Codespace";case"devcontainer":return"a dev container";case"ssh":return"an SSH session"}};var ap="__anyray-fallback-proxy",ws="ai.anyray.connect.fallback",fr="anyray-fallback",Aw=ws,ke=8785,bs=60,sp="x-anyray-local",ip=()=>hn(ap),ww=ur,Lc=async(e=ke)=>{let t=n=>new Promise(r=>{let o=zO();o.once("error",()=>r(!1)),o.listen(n,"127.0.0.1",()=>o.close(()=>r(!0)))});for(let n=e;n<e+20;n++)if(await t(n))return n;return e},be=async(e,t=1500)=>{let n=new AbortController,r=setTimeout(()=>n.abort(),t);try{let o=await fetch(`http://127.0.0.1:${e}/__anyray/health`,{signal:n.signal});return o.ok?await o.json():null}catch{return null}finally{clearTimeout(r)}},Vo=()=>jo(gs(),"Library","LaunchAgents",`${Aw}.plist`),ks=()=>jo(gs(),".anyray","logs"),ys=()=>jo(ks(),"connect-daemon.log"),vw=async(e,t=1048576)=>{await kw(e).then(r=>r.size,()=>0)>t&&await qO(e).catch(()=>{})},Yo=()=>jo(gs(),".config","systemd","user",`${fr}.service`),np=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),Cs=(e=ip())=>{let{command:t,args:n}=e,r=[t,...n].map(o=>` <string>${np(o)}</string>`).join(`
8
+ `)){let u=d.indexOf(":");if(u>0&&d.slice(0,u).trim().toLowerCase()===l)return d.slice(u+1).trim()}},i=s("x-anyray-api-key"),c=n?.ANTHROPIC_AUTH_TOKEN;return{origin:o,metadata:s("x-anyray-metadata"),apiKey:i||(c?.startsWith("ark_")?c:void 0)}}catch{return null}},uw=async()=>{try{let e=await L();return e.gateway?{origin:new URL(e.gateway).origin,metadata:de({user:e.name,team:e.team}),apiKey:e.clientKey}:null}catch{return null}},at=async(e="auto")=>e==="profile"?uw():e==="claude"?dw():await dw()??await uw(),Oc=async(e={})=>{let t=e.readTarget??at,n=e.loadProfile??L,r;try{r=await n()}catch{return"unreadable"}if(!r.gateway)return"unreadable";let o;try{o=await t("claude")}catch{return"unreadable"}if(!o)return"missing";let a=new Set;try{a.add(new URL(r.gateway).origin)}catch{return"unreadable"}return ot(r)&&r.fallbackPort&&a.add(`http://${mt}:${r.fallbackPort}`),a.has(o.origin)?"owned":"foreign"},Qt=e=>{let t={"content-type":"application/json"};return e.metadata&&(t["x-anyray-metadata"]=e.metadata),e.apiKey&&(t["x-anyray-api-key"]=e.apiKey),t},_c=async(e,t,n,r)=>{if(!e)return;let o=new AbortController,a=setTimeout(()=>o.abort(),FO);try{await fetch(`${e.origin}/connect/hook-savings`,{method:"POST",headers:Qt(e),body:JSON.stringify({source:t,...r?{tool:r}:{},...n}),signal:o.signal})}catch{}finally{clearTimeout(a)}};var Ln=()=>Tc(Pc(),".claude","settings.json"),hs=()=>Tc(Pc(),".claude.json"),BO=Ec,lr="anyray",WO=()=>({type:"stdio",...Ve("claude"),alwaysLoad:!0}),Gr=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),HO=e=>{if("mcpServers"in e&&!Gr(e.mcpServers))return"conflict";let t=Gr(e.mcpServers)?{...e.mcpServers}:{},n=t[lr];return n!==void 0&&!zt(n,"claude")?"conflict":(t[lr]=WO(),e.mcpServers=t,"installed")},pw=e=>{let t=e.mcpServers;return!t||!(lr in t)||!zt(t[lr],"claude")?!1:(delete t[lr],Object.keys(t).length===0&&delete e.mcpServers,!0)},KO=e=>{Ac(e,"PostToolUse",Xe,Tn(Dt(Xe),{matcher:"*"})),Ac(e,"UserPromptSubmit",sr,Tn(Dt(sr)))},GO=e=>{Ac(e,"SessionStart",ir,Tn(Dt(ir),{async:!0}))},mw=e=>Wo(e,"SessionStart",ir),fw=e=>{let t=Wo(e,"PostToolUse",Xe),n=Wo(e,"UserPromptSubmit",sr),r=mw(e);return t||n||r},jO="print-key",VO=e=>e.includes("anyray-connect")||e.includes("connect-runtime")||e.includes(Re()),jr=e=>{let t=e.apiKeyHelper;if(typeof t!="string")return!1;let n=t.trim().split(/\s+/);return n[n.length-1]===jO&&VO(t)},YO=async(e,t)=>{let n=(await Fr(e)).env,r=n&&typeof n=="object"&&!Array.isArray(n)?n:{},o=[];for(let a of BO){let s=r[a];typeof s=="string"?(t[a]=s,o.push(a)):delete t[a]}return o},ZO=e=>typeof e.apiKeyHelper=="string"&&!jr(e),yw=async e=>{let t=await tp(),n=async()=>t,[r,o,a]=await Promise.all([tw({userSettings:e,readManaged:n}),iw({userSettings:e,readManaged:n}).catch(()=>[]),sw({readManaged:n})]);return{directOverrides:r,managedOverrides:o,hookPolicy:a}},hw=async e=>{let{directOverrides:t,managedOverrides:n,hookPolicy:r}=await yw(e),o=ep(t),a=lw(n);return{routingOverrides:[...t.map(i=>({problem:Qu(i),fix:i.repairable?"Fix: run `anyray-connect doctor --repair` (or re-run `anyray-connect`) \u2014 apply disables this switch by pinning it empty in settings.json.":o,repairable:i.repairable})),...n.map(i=>({problem:cw(i),fix:a,repairable:!1,bypass:i.routing}))],claudeCodeHookPolicy:r.state}},dr={id:"claude-code",title:"Claude Code",automatic:!0,async detect(){let e=Tc(Pc(),".claude"),t=await R(e);return{installed:t,detail:t?Ln():"no ~/.claude directory"}},async apply(e,t){let n=Ln(),r=await F(n),o=Xg(r),a=await qg(e.origin,e.clientKey,o),s=zg(o,a),{env:i,subscription:c,byoUpstream:l,meta:d,headers:u}=fn(e,{contextWindowTokens:s.envTokens}),{directOverrides:f,hookPolicy:p}=await yw(r),h=f.filter(I=>!I.repairable),m=f.filter(I=>I.repairable),w=[...h.map(I=>`WARNING: ${Qu(I)}.`),...h.length?[ep(h)]:[],...p.state==="fine"?[]:[`WARNING: ${Ic(p)}.`,Rc(p)],...m.map(I=>nw(I)),`${n} \u2192 env.ANTHROPIC_BASE_URL = ${e.anthropicBaseUrl}`,l?`BYO-upstream mode: your personal upstream key passes through the gateway to ${e.byoUpstream.url} (never the org key).${e.clientKey?" Your personal gateway key rides x-anyray-api-key.":""}`:c?`Subscription mode: Claude Code keeps your seat sign-in; its OAuth token passes through the gateway (never stored).${e.clientKey?" Your personal gateway key rides x-anyray-api-key.":""}`:e.clientKey?"Auth: personal gateway key (not shown here; see below for where it lives)":"Auth: placeholder token (gateway swaps in the server-held key)",`Attribution: ${d??"(none)"}`,...l?[]:["Restored on-demand MCP tool loading (env.ENABLE_TOOL_SEARCH) that Claude Code otherwise disables behind a non-first-party gateway. Deferred servers stay out of context until used; the first-party AnyRay retrieval server stays always loaded so capability is visible per request."],...s.envTokens!==void 0?[`Context window: env.CLAUDE_CODE_MAX_CONTEXT_TOKENS = ${s.envTokens} \u2014 your model's real window, so Claude Code stops budgeting the 200k it assumes behind any custom base URL.`]:[],...s.model!==void 0?[`Context window: model = ${s.model} \u2014 same model, its long-context variant. Claude Code ignores CLAUDE_CODE_MAX_CONTEXT_TOKENS for claude-* ids, so the [1m] alias is what actually gets you your ${a} window back instead of the 200k it assumes behind any custom base URL. A --model flag on your launch command, or picking a model in-app, overrides this \u2014 add [1m] there too (quote it in zsh).`]:[],"Claude Code settings.json routing covers the CLI and VS Code extension. Claude Desktop is separate: its verified macOS automatic setup supports either the Claude Code subscription-backed Gateway lane or API billing; other Desktop lanes fail closed or use the documented API setup.","Restart Claude Code (or open a new session) to pick up the change."];if(t.dryRun)return{status:"configured",messages:w};s.model!==void 0&&(r.model=s.model);let g=r.env??{};r.env={...g,...i};let y=r.env;for(let{name:I}of Dn)m.some(P=>P.name===I)?y[I]="":y[I]===""&&(process.env[I]??"").trim()===""&&delete y[I];if(u||delete y.ANTHROPIC_CUSTOM_HEADERS,c&&(g.ANTHROPIC_AUTH_TOKEN&&w.push("Removed env.ANTHROPIC_AUTH_TOKEN \u2014 it would override your subscription sign-in."),delete y.ANTHROPIC_AUTH_TOKEN),l)for(let I of Jg)delete y[I];let b=!!e.clientKey,A=le(),v=ZO(r);!c&&!l&&b&&A&&!v?(r.apiKeyHelper=Zg(),y.ANTHROPIC_AUTH_TOKEN="",w.push("Installed an apiKeyHelper that reprints a fresh gateway key on demand \u2014 Claude Code refreshes it at startup and on any 401, so an idle session no longer 401s (no re-enrollment).")):jr(r)&&delete r.apiKeyHelper,v&&!c&&!l&&b&&A&&w.push("Kept your existing apiKeyHelper; your gateway key stays in ANTHROPIC_AUTH_TOKEN (Anyray auto-refresh via the helper is off)."),(c||l)&&b&&A?(GO(r),w.push("Installed a SessionStart hook that refreshes your gateway key each session, so an idle subscription session no longer needs re-enrollment.")):mw(r),le()?(KO(r),w.push("Installed a PostToolUse hook (trims oversized tool outputs, cache-safe) and a UserPromptSubmit hook (beacons oversized pasted-data prompts) \u2014 both content-free.")):(fw(r),w.push(`Skipped the Anyray hooks \u2014 anyray-connect is running from a temporary path (${Re()}). Re-run via the installer (it persists the binary under ~/.anyray/bin) or a global install to enable cache-safe trimming and paste-savings beacons.`)),await J(n,r);let x=[n],C=hs();try{let I=await F(C),P=!1;le()?HO(I)==="conflict"?w.push(`MCP name conflict in ${C}: mcpServers.${lr} is not owned by Anyray Connect, so it was left untouched.`):(P=!0,w.push("Registered the Anyray retrieval MCP server (anyray_retrieve) for explicit recovery of stashed context \u2014 always loaded so retrieval capability is visible on every request.")):P=pw(I),P&&(await J(C,I),x.push(C))}catch(I){w.push(`Could not register the Anyray MCP server in ${C} (${I instanceof Error?I.message:String(I)}); retrieval via anyray_retrieve is unavailable until this is fixed.`)}return{status:"configured",messages:w,changedFiles:x}},skillsDir(){return Tc(Pc(),".claude","skills")},async watchPaths(){return[Ln(),hs()]},async pointsAt(e){let t=Ln();if(!await R(t))return!1;try{let o=(await F(t)).env?.ANTHROPIC_BASE_URL;return typeof o=="string"&&o.replace(/\/+$/,"")===e}catch{return!1}},async runtimeDiagnostics(){let e=await F(Ln()).catch(()=>({}));return hw(e)},async routingOverrides(){let e=await F(Ln()).catch(()=>({}));return(await hw(e)).routingOverrides},async mcpStatus(){let e=hs();if(!await R(e))return{registered:!1,command:null};try{let r=(await F(e)).mcpServers?.[lr];return!r||!zt(r,"claude")?{registered:!1,command:null}:{registered:!0,command:typeof r.command=="string"?r.command:null}}catch{return{registered:!1,command:null}}},async integrationStatus(){let e,t=!0,n=Ln();if(!await R(n))e="missing";else try{let s=await F(n);if(s.hooks===void 0)e="missing";else if(!Gr(s.hooks))e="unreadable";else{let i=s.hooks.PostToolUse;e=i===void 0?"missing":Array.isArray(i)?i.some(c=>ar(c,Xe))?"owned":"missing":"unreadable",e==="owned"&&Array.isArray(i)&&(t=i.some(c=>ar(c,Xe)&&Gr(c)&&Array.isArray(c.hooks)&&c.hooks.some(l=>Gr(l)&&vc(l.command,Xe))))}}catch{e="unreadable"}let r,o=!0,a=hs();if(!await R(a))r="missing";else try{let s=await F(a);if(s.mcpServers===void 0)r="missing";else if(!Gr(s.mcpServers))r="unreadable";else{let i=s.mcpServers[lr];r=i===void 0?"missing":zt(i,"claude")?"owned":"foreign",r==="owned"&&(o=Sc(i,"claude"))}}catch{r="unreadable"}return{hook_registration:e,mcp_registration:r,hook_binary:t&&o&&await Hr()?"owned":"missing",beacon_target:await Oc().catch(()=>"unreadable")}},async inferenceAuthLanes(){try{let e=await F(Ln()),t=Gr(e.env)?e.env:{},n=typeof t.ANTHROPIC_CUSTOM_HEADERS=="string"?t.ANTHROPIC_CUSTOM_HEADERS:"";if(/^x-anyray-custom-host:/m.test(n))return["byo"];if(/^x-anyray-auth-mode:\s*passthrough$/m.test(n))return["subscription"];if(typeof t.ANTHROPIC_AUTH_TOKEN=="string"||typeof e.apiKeyHelper=="string")return["api_key"]}catch{}return["unknown"]},async revert(e){let t=Ln();if(!await R(t))return{status:"not-found",messages:["nothing to revert"]};if(e.dryRun)return{status:"reverted",messages:[`would remove Anyray keys from ${t}`]};let n=await F(t),r=n.env,o=fw(n),a=jr(n);a&&delete n.apiKeyHelper;let s=r?await YO(t,r):[],i=Qg(typeof n.model=="string"?n.model:void 0,(await Fr(t)).model);i!==void 0&&(n.model=i),r&&Object.keys(r).length===0&&delete n.env,(r||o||a||i!==void 0)&&await J(t,n,{backup:!1});let c=[`removed Anyray keys from ${t}`];i!==void 0&&c.push(`Put model back to ${i} \u2014 dropped the [1m] alias Anyray added for your context window.`),o&&c.push("Removed the Anyray PostToolUse, UserPromptSubmit, and SessionStart hooks."),a&&c.push("Removed the Anyray apiKeyHelper."),s.length&&c.push(`Put back the ${s.join(" and ")} you had set before Anyray.`);let l=hs();try{let d=await F(l);pw(d)&&(await J(l,d,{backup:!1}),c.push("Removed the Anyray retrieval MCP server (anyray_retrieve)."))}catch{}return await se(t),{status:"reverted",messages:c,changedFiles:[t]}}};var we="0.11.153";var hn=e=>{let{command:t,args:n}=pn([e]);return{command:t,args:n}},ur=()=>Wr();import{homedir as gw,userInfo as JO}from"node:os";var ms=()=>{try{return gw()!==JO().homedir}catch{return!1}},Ho=e=>[`Skipped ${e} \u2014 HOME (${gw()}) is not this account's home directory.`,"The OS registers a per-user service against the account, not against HOME, so","one installed from here would point at a path the real login session cannot use."];var gt=(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,Vr=(e=process.env)=>gt(e)!==null,At=e=>e==="codespaces"||e==="devcontainer",pr=e=>{switch(e){case"codespaces":return"a GitHub Codespace";case"devcontainer":return"a dev container";case"ssh":return"an SSH session"}};var ap="__anyray-fallback-proxy",ws="ai.anyray.connect.fallback",fr="anyray-fallback",Aw=ws,ke=8785,bs=60,sp="x-anyray-local",ip=()=>hn(ap),ww=ur,Lc=async(e=ke)=>{let t=n=>new Promise(r=>{let o=zO();o.once("error",()=>r(!1)),o.listen(n,"127.0.0.1",()=>o.close(()=>r(!0)))});for(let n=e;n<e+20;n++)if(await t(n))return n;return e},be=async(e,t=1500)=>{let n=new AbortController,r=setTimeout(()=>n.abort(),t);try{let o=await fetch(`http://127.0.0.1:${e}/__anyray/health`,{signal:n.signal});return o.ok?await o.json():null}catch{return null}finally{clearTimeout(r)}},Vo=()=>jo(gs(),"Library","LaunchAgents",`${Aw}.plist`),ks=()=>jo(gs(),".anyray","logs"),ys=()=>jo(ks(),"connect-daemon.log"),vw=async(e,t=1048576)=>{await kw(e).then(r=>r.size,()=>0)>t&&await qO(e).catch(()=>{})},Yo=()=>jo(gs(),".config","systemd","user",`${fr}.service`),np=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),Cs=(e=ip())=>{let{command:t,args:n}=e,r=[t,...n].map(o=>` <string>${np(o)}</string>`).join(`
9
9
  `);return`<?xml version="1.0" encoding="UTF-8"?>
10
10
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
11
11
  <plist version="1.0">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anyray-connect",
3
- "version": "0.11.152",
3
+ "version": "0.11.153",
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": {