@arcforge/axon 1.0.11 → 1.0.13

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/index.js +1 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -792,7 +792,7 @@ ${s.stack??""}`}),!1}),()=>{if(n.value){let a=n.value,r=(a.stack??"").split(`
792
792
  ${gn.stack??""}`}),!Ye)Ye=!0,queueMicrotask(()=>Kh(Kt,"layout"));return!1}};I=je;let ke=g2e("div",i);ke.layoutProps={...ke.layoutProps,width:"100%",height:"100%",scrollableY:!0};let{createApp:Me}=qyt(i,()=>{D=ke,k()}),$e=()=>{if(Le.updateContainerSize(n.width,n.height),A)A.invalidateAllSnapshots();if(D){if(f4.markResizeDirty(D),D._renderDirty=!0,n.forceFullRedraw(),je(D))n.render()}};n.on("resize",$e);let fe=()=>{if(D)hA(D);k()};n.on("drain",fe),cb("vterm:component:build",{mode:s.length>0?c.size>0||r?.name!=="AppRoot"?"layout":"router":"entry"});let se=Me(r);cb("vterm:app:create");let ge=YG.ref(process.env.PWD??process.cwd());se.provide(TY,ge);let he=YG.ref(!0),pt=null;async function st(){try{return await new Promise((nt,Kt)=>{let _e=nb("net").createConnection({host:"1.1.1.1",port:53});_e.setTimeout(2000),_e.on("connect",()=>{_e.destroy(),nt()}),_e.on("error",Kt),_e.on("timeout",()=>{_e.destroy(),Kt(Error("timeout"))})}),!0}catch{return!1}}async function Dn(){he.value=await st(),pt=setInterval(async()=>{let nt=await st();if(nt!==he.value)he.value=nt},5000)}Dn(),se.provide(NY,he),se.provide(I5,n),se.provide(Mq,oe),se.provide(g8,K),se.provide(IY,X),se.provide(QY,Z),se.provide(FY,{getTheme:fWe,setTheme:gWe});let qe=new Set,We={add:(nt)=>{return qe.add(nt),()=>qe.delete(nt)},run:async()=>{for(let nt of qe)if(await nt()===!1)return!1;return!0}};se.provide(LY,We);let Ot=async()=>{if(!await We.run())return;if(cb("vterm:shutdown"),pt)clearInterval(pt);try{await wt.unmount()}catch{try{n.cleanup()}catch{}}finally{process.exit(0)}};se.provide(SY,Ot),se.provide(jY,async()=>{if(t.onReload)try{await t.onReload()}catch(nt){let Kt=nt instanceof Error?nt:Error(String(nt));jy({t:Date.now(),level:"error",source:"vterm",msg:`[vterm] Hot reload handler threw: ${Kt.message}
793
793
  ${Kt.stack??""}`}),Kh(nt,"reload")}});let Xt=new Map;if(se.provide(MPe,Xt),se.provide(qPe,t.store||{}),se.provide("vterm-layouts",c),b)for(let[nt,Kt]of Object.entries(b))se.provide(nt,Kt);if(s.length>0){let nt=qc(se,s,{notFoundComponent:u});if(e.onMiddleware)await e.onMiddleware(nt,s);if(await nt.push(nt.currentPath.value),A&&p){let Kt=nt.currentRoute?.value;Ve=p(nt.currentPath.value,Kt?.params??{},Kt?.query??{}),Be=!0}YG.watch(nt.currentPath,(Kt)=>{if(A&&p){if(Ve)A.invalidateBufferSnapshot(Ve);let gn=nt.currentRoute?.value;Ve=p(Kt,gn?.params??{},gn?.query??{}),Be=!0}if(D)D._renderDirty=!0;n.forceFullRedraw()})}let Vt=[/^Failed to resolve component:/,/^injection "[^"]*" not found\./],gt=new Map,un=5000;se.config.warnHandler=(nt,Kt,gn)=>{if(Vt.some((me)=>me.test(nt)))return;let _e=Date.now(),ye=gt.get(nt);if(ye!==void 0&&_e-ye<un)return;gt.set(nt,_e),jy({t:_e,level:"warn",source:"userland",msg:`[Vue warn] ${nt}${gn?`
794
794
  ${gn}`:""}`})},se.config.performance=!1,se.config.compilerOptions.isCustomElement=()=>!0,se.config.errorHandler=(nt,Kt,gn)=>{Kh(nt,`vue:${gn}`)};let Mn=(nt)=>{if(Hh.value===null)Kh(nt,"uncaughtException")},tt=(nt)=>{if(Hh.value===null)Kh(nt,"unhandledRejection")};process.on("uncaughtException",Mn),process.on("unhandledRejection",tt),cb("vterm:app:mount"),se.mount(ke),await new Promise((nt)=>queueMicrotask(nt)),oe(),cb("vterm:boot:complete",{durationMs:Date.now()-(d??Date.now())});let wt={screen:n,app:se,snapshot:CSa(n),async unmount(){if(NPe(),process.off("uncaughtException",Mn),process.off("unhandledRejection",tt),n.off("resize",$e),n.off("drain",fe),N!==null)clearTimeout(N),N=null;for(let nt of Xt.values())await nt.close();se.unmount(),n.cleanup(),n.destroy()},render(){oe()}};if(n.key(g,Ot),t.onMounted)try{t.onMounted(wt)}catch(nt){Kh(nt,"onMounted")}return wt}async function w2e(e){let t=Date.now(),{entry:n,layout:a,highlight:r,ui:i}=e;if(cb("vterm:boot",{cwd:process.cwd()}),EPe(),TPe(),cb("vterm:console:capture"),r)mWe(r);cb("vterm:highlight:config",{theme:r?.theme});let s=new $0e,c=new q0e({inputParser:s,alternateScreen:!0,hideCursor:!0,cursor:i?.cursor,width:e.dimensions?.width,height:e.dimensions?.height});c.initialize(),cb("vterm:driver:init",{width:c.width,height:c.height});let u={};if(e.styles?.length)for(let y of e.styles){if(!y||typeof y!=="object"||Array.isArray(y))continue;Object.assign(u,y)}let A=typeof a==="object"&&a!==null?a:null,p=e.routes??[],d=e.layouts instanceof Map?e.layouts:new Map;cb("vterm:routes:load",{count:p.length,paths:p.map((y)=>y.path??y.name??"?")});let g=e.errorPage??jb.defineComponent({name:"VTermError",setup(){return()=>jb.h("div",{style:{color:"red",padding:"1",display:"flex",flexDirection:"column"}},[jb.h("p",{style:{color:"brightred"}},"Runtime Error"),jb.h("p",{style:{color:"white"}},String(Hh.value?.message??Hh.value??"Unknown error")),jb.h("p",{style:{color:"yellow"}},String(Hh.value?.stack?.split(`
795
- `)[1]??""))])}}),f;if(p.length>0)f=A??jb.defineComponent({name:"AppRoot",setup(){return()=>jb.h($c)}});else{if(!n)throw Error("No entry component or routes provided to vterm()");f=typeof n==="string"?(()=>{throw Error(`vterm build error: entry must be a component object in production, got string "${n}"`)})():n}let b=f;return f=jb.defineComponent({name:"VTermRoot",setup(){return jb.onErrorCaptured((y)=>{return Kh(y,"component"),!1}),()=>Hh.value!==null?jb.h(g):jb.h(b)}}),Zyt({options:e,driver:c,inputParser:s,component:f,allStyles:u,routes:p,layoutsMap:d,notFoundComponent:e.notFoundComponent,bootStart:t})}var bi=ko(Eo(),1);import $0 from"fs";import Vyt from"path";import qs from"path";import Yyt from"os";function VG(e){let t=e?.root??qs.join(Yyt.homedir(),".capsuleer"),n=qs.join(t,"environment");return{root:t,manifest:qs.join(t,"manifest.json"),env:qs.join(t,"env.json"),environment:n,entrypoint:qs.join(n,"index.ts"),readyMarker:qs.join(n,".ready")}}function k2e(){let{existsSync:e}=nb("fs"),t=qs.join(qs.dirname(new URL(import.meta.url).pathname),"..",".."),n=qs.join(t,"node_modules",".bin","capsuleer");if(e(n))return n;return"capsuleer"}function GA(e,t){let n=t?.root??qs.join(Yyt.homedir(),".axon");if(!e)return{root:n,cache:qs.join(n,"cache"),activeProfile:qs.join(n,"active-profile.json")};let a=qs.join(n,"profiles",e);return{root:a,auth:qs.join(a,"auth.json"),settings:qs.join(a,"settings.json"),policy:qs.join(a,"policy.json"),credentials:qs.join(a,"credentials.json"),keybinds:qs.join(a,"keybinds.json"),themes:qs.join(a,"themes.json"),history:qs.join(a,"history.jsonl"),agents:{root:qs.join(a,"agents"),agent:(r)=>qs.join(a,"agents",r),config:(r)=>qs.join(a,"agents",r,"config.json"),policy:(r)=>qs.join(a,"agents",r,"policy.json"),store:(r,i,s)=>qs.join(a,"agents",r,"store",i,`${s}.json`),storeDir:(r,i)=>qs.join(a,"agents",r,"store",i),sessions:{root:(r)=>qs.join(a,"agents",r,"sessions"),index:(r)=>qs.join(a,"agents",r,"sessions","index.json"),session:(r,i)=>qs.join(a,"agents",r,"sessions",`${i}.jsonl`)},voice:{root:(r)=>qs.join(a,"agents",r,"voice"),index:(r)=>qs.join(a,"agents",r,"voice","index.json"),recording:(r,i)=>qs.join(a,"agents",r,"voice",`${i}.wav`)}},models:{root:qs.join(a,"models"),model:(r)=>qs.join(a,"models",r),sessions:{root:(r)=>qs.join(a,"models",r,"sessions"),index:(r)=>qs.join(a,"models",r,"sessions","index.json"),session:(r,i)=>qs.join(a,"models",r,"sessions",`${i}.jsonl`)}},cache:qs.join(n,"cache")}}function El(e,t,n){if(e)return;let a=Error(t);if(a.code="ASSERTION_FAILED",a.service="core/assert",a.recoverable=!1,a.actionable=!1,a.timestamp=Date.now(),console.error("[assert]",t),n)n(a)}function xSa(){return Date.now().toString(36)}var XG=Dt.ref([]),Xo={list:Dt.readonly(XG),push(e){XG.value.push({...e,id:xSa(),timestamp:Date.now()})},dismiss(e){XG.value=XG.value.filter((t)=>t.id!==e)},clear(){XG.value=[]}};function Xyt(e){let t=Dt.ref(!1),n=Dt.ref(0),a=null,r=!1;function i(D,I){if(D?.code==="ENOSPC"){if(!r)r=!0,Xo.push({kind:"error",title:"Disk Full",message:"Your disk is full \u2014 session history is not being saved. Free up space to restore normal operation.",source:"store",dismissable:!1})}else console.error(`[store] write failed (${I}):`,D)}function s(D){try{$0.mkdirSync(D,{recursive:!0})}catch(I){console.error("[store] failed to create directory:",D,I)}}function c(D,I){try{if(!$0.existsSync(D))return I;let x=$0.readFileSync(D,"utf-8");return JSON.parse(x)}catch(x){return console.warn("[store] failed to read JSON:",D,x),I}}function u(D,I){try{s(Vyt.dirname(D)),$0.writeFileSync(D,JSON.stringify(I,null,2),"utf-8")}catch(x){throw i(x,D),x}}function A(){return t.value&&a!==null}let p={list(){if(n.value,!A())return[];let D=a.agents.root,I=[];try{if(!$0.existsSync(D))return I;let x=$0.readdirSync(D);for(let k of x){let E=this.get(k);if(E)I.push(E)}}catch(x){console.error("[store] failed to list agents:",x)}return I},get(D){if(!A())return null;let I=a.agents.config(D);return c(I,null)},save(D){El(t.value,"store not ready"),El(a,"paths not initialized"),u(a.agents.config(D.name),D),n.value++},remove(D){El(t.value,"store not ready"),El(a,"paths not initialized");let I=a.agents.agent(D);try{if($0.existsSync(I))$0.rmSync(I,{recursive:!0})}catch(x){throw console.error("[store] failed to remove agent:",D,x),x}n.value++}},d={list(D,I){if(!A())return[];let x=I?a.agents.sessions.index:a.models.sessions.index;return c(x(D),[])},create(D){El(t.value,"store not ready"),El(a,"paths not initialized");let I=this.list(D.agentName,D.userOwned);if(!I.some((k)=>k.id===D.id)){I.push(D);let E=(D.userOwned?a.agents.sessions.index:a.models.sessions.index)(D.agentName);u(E,I)}},remove(D,I,x){El(t.value,"store not ready"),El(a,"paths not initialized");let k=this.list(D,I).filter((N)=>N.id!==x),B=(I?a.agents.sessions.index:a.models.sessions.index)(D);u(B,k);let T=(I?a.agents.sessions.session:a.models.sessions.session)(D,x);try{if($0.existsSync(T))$0.unlinkSync(T)}catch(N){console.error("[store] failed to remove session file:",T,N)}},appendEvent(D,I,x,k){El(t.value,"store not ready"),El(a,"paths not initialized");let B=(I?a.agents.sessions.session:a.models.sessions.session)(D,x);if(r)return;try{s(Vyt.dirname(B)),$0.appendFileSync(B,JSON.stringify(k)+`
795
+ `)[1]??""))])}}),f;if(p.length>0)f=A??jb.defineComponent({name:"AppRoot",setup(){return()=>jb.h($c)}});else{if(!n)throw Error("No entry component or routes provided to vterm()");f=typeof n==="string"?(()=>{throw Error(`vterm build error: entry must be a component object in production, got string "${n}"`)})():n}let b=f;return f=jb.defineComponent({name:"VTermRoot",setup(){return jb.onErrorCaptured((y)=>{return Kh(y,"component"),!1}),()=>Hh.value!==null?jb.h(g):jb.h(b)}}),Zyt({options:e,driver:c,inputParser:s,component:f,allStyles:u,routes:p,layoutsMap:d,notFoundComponent:e.notFoundComponent,bootStart:t})}var bi=ko(Eo(),1);import $0 from"fs";import Vyt from"path";import qs from"path";import Yyt from"os";function VG(e){let t=e?.root??qs.join(Yyt.homedir(),".capsuleer"),n=qs.join(t,"environment");return{root:t,manifest:qs.join(t,"manifest.json"),env:qs.join(t,"env.json"),environment:n,entrypoint:qs.join(n,"index.ts"),readyMarker:qs.join(n,".ready")}}function k2e(){let{existsSync:e}=nb("fs"),t=qs.dirname(new URL(import.meta.url).pathname),n=qs.join(t,"node_modules","@capsuleer","cli","bin","capsuleer.ts");if(e(n))return n;let a=qs.join(t,"node_modules",".bin","capsuleer");if(e(a))return a;return"capsuleer"}function GA(e,t){let n=t?.root??qs.join(Yyt.homedir(),".axon");if(!e)return{root:n,cache:qs.join(n,"cache"),activeProfile:qs.join(n,"active-profile.json")};let a=qs.join(n,"profiles",e);return{root:a,auth:qs.join(a,"auth.json"),settings:qs.join(a,"settings.json"),policy:qs.join(a,"policy.json"),credentials:qs.join(a,"credentials.json"),keybinds:qs.join(a,"keybinds.json"),themes:qs.join(a,"themes.json"),history:qs.join(a,"history.jsonl"),agents:{root:qs.join(a,"agents"),agent:(r)=>qs.join(a,"agents",r),config:(r)=>qs.join(a,"agents",r,"config.json"),policy:(r)=>qs.join(a,"agents",r,"policy.json"),store:(r,i,s)=>qs.join(a,"agents",r,"store",i,`${s}.json`),storeDir:(r,i)=>qs.join(a,"agents",r,"store",i),sessions:{root:(r)=>qs.join(a,"agents",r,"sessions"),index:(r)=>qs.join(a,"agents",r,"sessions","index.json"),session:(r,i)=>qs.join(a,"agents",r,"sessions",`${i}.jsonl`)},voice:{root:(r)=>qs.join(a,"agents",r,"voice"),index:(r)=>qs.join(a,"agents",r,"voice","index.json"),recording:(r,i)=>qs.join(a,"agents",r,"voice",`${i}.wav`)}},models:{root:qs.join(a,"models"),model:(r)=>qs.join(a,"models",r),sessions:{root:(r)=>qs.join(a,"models",r,"sessions"),index:(r)=>qs.join(a,"models",r,"sessions","index.json"),session:(r,i)=>qs.join(a,"models",r,"sessions",`${i}.jsonl`)}},cache:qs.join(n,"cache")}}function El(e,t,n){if(e)return;let a=Error(t);if(a.code="ASSERTION_FAILED",a.service="core/assert",a.recoverable=!1,a.actionable=!1,a.timestamp=Date.now(),console.error("[assert]",t),n)n(a)}function xSa(){return Date.now().toString(36)}var XG=Dt.ref([]),Xo={list:Dt.readonly(XG),push(e){XG.value.push({...e,id:xSa(),timestamp:Date.now()})},dismiss(e){XG.value=XG.value.filter((t)=>t.id!==e)},clear(){XG.value=[]}};function Xyt(e){let t=Dt.ref(!1),n=Dt.ref(0),a=null,r=!1;function i(D,I){if(D?.code==="ENOSPC"){if(!r)r=!0,Xo.push({kind:"error",title:"Disk Full",message:"Your disk is full \u2014 session history is not being saved. Free up space to restore normal operation.",source:"store",dismissable:!1})}else console.error(`[store] write failed (${I}):`,D)}function s(D){try{$0.mkdirSync(D,{recursive:!0})}catch(I){console.error("[store] failed to create directory:",D,I)}}function c(D,I){try{if(!$0.existsSync(D))return I;let x=$0.readFileSync(D,"utf-8");return JSON.parse(x)}catch(x){return console.warn("[store] failed to read JSON:",D,x),I}}function u(D,I){try{s(Vyt.dirname(D)),$0.writeFileSync(D,JSON.stringify(I,null,2),"utf-8")}catch(x){throw i(x,D),x}}function A(){return t.value&&a!==null}let p={list(){if(n.value,!A())return[];let D=a.agents.root,I=[];try{if(!$0.existsSync(D))return I;let x=$0.readdirSync(D);for(let k of x){let E=this.get(k);if(E)I.push(E)}}catch(x){console.error("[store] failed to list agents:",x)}return I},get(D){if(!A())return null;let I=a.agents.config(D);return c(I,null)},save(D){El(t.value,"store not ready"),El(a,"paths not initialized"),u(a.agents.config(D.name),D),n.value++},remove(D){El(t.value,"store not ready"),El(a,"paths not initialized");let I=a.agents.agent(D);try{if($0.existsSync(I))$0.rmSync(I,{recursive:!0})}catch(x){throw console.error("[store] failed to remove agent:",D,x),x}n.value++}},d={list(D,I){if(!A())return[];let x=I?a.agents.sessions.index:a.models.sessions.index;return c(x(D),[])},create(D){El(t.value,"store not ready"),El(a,"paths not initialized");let I=this.list(D.agentName,D.userOwned);if(!I.some((k)=>k.id===D.id)){I.push(D);let E=(D.userOwned?a.agents.sessions.index:a.models.sessions.index)(D.agentName);u(E,I)}},remove(D,I,x){El(t.value,"store not ready"),El(a,"paths not initialized");let k=this.list(D,I).filter((N)=>N.id!==x),B=(I?a.agents.sessions.index:a.models.sessions.index)(D);u(B,k);let T=(I?a.agents.sessions.session:a.models.sessions.session)(D,x);try{if($0.existsSync(T))$0.unlinkSync(T)}catch(N){console.error("[store] failed to remove session file:",T,N)}},appendEvent(D,I,x,k){El(t.value,"store not ready"),El(a,"paths not initialized");let B=(I?a.agents.sessions.session:a.models.sessions.session)(D,x);if(r)return;try{s(Vyt.dirname(B)),$0.appendFileSync(B,JSON.stringify(k)+`
796
796
  `,"utf-8")}catch(Q){throw i(Q,B),Q}},loadEvents(D,I,x){El(t.value,"store not ready"),El(a,"paths not initialized");let E=(I?a.agents.sessions.session:a.models.sessions.session)(D,x);try{if(!$0.existsSync(E))return[];return $0.readFileSync(E,"utf-8").trim().split(`
797
797
  `).filter(Boolean).map((T)=>JSON.parse(T))}catch(B){return console.error("[store] failed to load events:",E,B),[]}},updateMeta(D,I,x){El(t.value,"store not ready"),El(a,"paths not initialized");let k=this.list(D,I),E=k.findIndex((B)=>B.id===x.id);if(E>=0){k[E]=x;let Q=(I?a.agents.sessions.index:a.models.sessions.index)(D);u(Q,k)}}},g={themeId:"arc",selectedAgent:null,scrollback:1000,fontSize:14};return{ready:t,agents:p,sessions:d,settings:{get(){if(!A())return{...g};return c(a.settings,{...g})},set(D){El(t.value,"store not ready"),El(a,"paths not initialized"),u(a.settings,D)}},keybinds:{get(){if(!A())return{};return c(a.keybinds,{})},set(D){El(t.value,"store not ready"),El(a,"paths not initialized"),u(a.keybinds,D)}},credentials:{get(){if(!A())return{};return c(a.credentials,{})},set(D){El(t.value,"store not ready"),El(a,"paths not initialized"),u(a.credentials,D)},clear(){El(t.value,"store not ready"),El(a,"paths not initialized"),u(a.credentials,{})}},async init(D){a=GA(D,{root:e}),s(a.agents.root),s(a.models.root),t.value=!0},teardown(){t.value=!1,a=null}}}import UD from"fs";import ewt from"path";var vSa=300000,BSa=86400000;function twt(e){try{UD.mkdirSync(e,{recursive:!0})}catch(n){console.error("[cache] failed to create directory:",n)}let t=new Map;return{get(n,a,r){let i=r?.soft??vSa,s=r?.hard??BSa,c=ewt.join(e,`${n}.json`),u=Dt.ref(null),A=null,p=0;try{if(UD.existsSync(c)){let b=UD.readFileSync(c,"utf-8"),y=JSON.parse(b);A=y.data,p=y.timestamp,u.value=A}}catch(b){console.debug("[cache] failed to read:",n,b)}let d=Date.now(),g=p?d-p:1/0;if(!A||g>i){let b=`${n}:fetching`,y=t.get(b);if(!y)y=a().then((D)=>{try{let I={data:D,timestamp:d};UD.mkdirSync(e,{recursive:!0}),UD.writeFileSync(c,JSON.stringify(I),"utf-8")}catch(I){console.error("[cache] failed to write:",n,I)}return u.value=D,t.delete(b),D}).catch((D)=>{if(console.error("[cache] fetch failed:",n,D),A&&g>s)Xo.push({kind:"warning",title:"Stale Cache",message:`Using stale cache for ${n} (fetch failed)`,source:"cache",dismissable:!0}),u.value=A;t.delete(b)}),t.set(b,y);else y.then(()=>{try{if(UD.existsSync(c)){let D=UD.readFileSync(c,"utf-8"),I=JSON.parse(D);u.value=I.data}}catch(D){console.debug("[cache] failed to read after dedup:",n,D)}})}return u},invalidate(n){let a=ewt.join(e,`${n}.json`);try{if(UD.existsSync(a))UD.unlinkSync(a)}catch(r){console.error("[cache] failed to invalidate:",n,r)}}}}var Qae=typeof AXON_VERSION<"u"?AXON_VERSION:"0.0.0-dev",ESa="https://registry.npmjs.org/axon/latest",DSa="bun add -g axon@latest";function nwt(e){let t=Dt.ref(null),n=e??global.fetch,a=Qae==="0.0.0-dev";return{get currentVersion(){return Qae},get latestVersion(){return t.value},get hasUpdate(){if(a)return!1;if(!t.value)return!1;return t.value!==Qae},async check(){if(a)return;try{let r=await n(ESa);if(!r.ok)throw Error(`HTTP ${r.status}`);let s=(await r.json()).version;if(s&&s!==Qae)t.value=s,Xo.push({kind:"info",title:"Update Available",message:`Axon ${s} is available. Run: ${DSa}`,source:"updater",dismissable:!0,action:{label:"View Release",handler:async()=>{}}})}catch(r){console.debug("[updater] check failed:",r)}},reset(){t.value=null}}}function Pb(){return process.env.AXON_API_BASE??"https://axon.arclabs.it"}async function awt(e){let t=await fetch(`${Pb()}/api/auth/device/authorize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e?{hint:e}:{})});if(!t.ok)throw Error(`authorize failed: ${t.status}`);return await t.json()}async function rwt(e,t){let n=new URLSearchParams({device_code:e}),a=await fetch(`${Pb()}/api/auth/device/poll?${n}`,{method:"GET",signal:t});if(!a.ok)throw Error(`poll failed: ${a.status}`);return await a.json()}async function iwt(e){let t=await fetch(`${Pb()}/api/auth/refresh`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`}});if(!t.ok){let r=await t.text().catch(()=>"");throw Error(`refresh failed: ${t.status} ${r}`)}let n=await t.text(),a;try{a=JSON.parse(n)}catch{throw Error(`refresh returned invalid JSON (status ${t.status}): ${n.slice(0,200)}`)}return{accessToken:a.access_token||a.accessToken,user:a.user}}async function eU(e){let t=await fetch(`${Pb()}/api/users/me`,{method:"GET",headers:{Authorization:`Bearer ${e}`}});if(!t.ok)throw Error(`getMe failed: ${t.status}`);return(await t.json()).user}import Ym from"fs";import Aj from"path";function Fae(e){try{let t=e.split(".");if(t.length!==3)return console.warn("[auth] token is not a JWT, using 24h default"),Date.now()+86400000;let n=t[1],a=n+"=".repeat((4-n.length%4)%4),r=Buffer.from(a,"base64").toString("utf-8"),s=JSON.parse(r).exp;if(!s)return console.warn("[auth] JWT has no exp claim, using 24h default"),Date.now()+86400000;return s*1000}catch(t){return console.warn("[auth] failed to parse JWT:",t),Date.now()+86400000}}function C2e(e,t){try{let n=t.auth;if(!Ym.existsSync(n))return null;let a=Ym.readFileSync(n,"utf-8");return JSON.parse(a)}catch(n){return console.debug("[auth] failed to read auth record:",n),null}}function tU(e,t,n){try{let a=n.auth,r=Aj.dirname(a);Ym.mkdirSync(r,{recursive:!0}),Ym.writeFileSync(a,JSON.stringify(t,null,2),"utf-8")}catch(a){throw console.error("[auth] failed to write auth record:",a),a}}function owt(e){try{let t=e.activeProfile;if(!Ym.existsSync(t))return null;let n=Ym.readFileSync(t,"utf-8");return JSON.parse(n).userId||null}catch(t){return console.debug("[auth] failed to read active profile:",t),null}}function x2e(e,t){try{let n=t.activeProfile,a=Aj.dirname(n);Ym.mkdirSync(a,{recursive:!0}),Ym.writeFileSync(n,JSON.stringify({userId:e},null,2),"utf-8")}catch(n){throw console.error("[auth] failed to write active profile:",n),n}}function Sae(e){try{let t=Aj.join(e.root,"profiles");if(!Ym.existsSync(t))return[];let n=Ym.readdirSync(t,{withFileTypes:!0}),a=[];for(let r of n){if(!r.isDirectory())continue;let i=Aj.join(t,r.name,"auth.json");if(!Ym.existsSync(i))continue;try{let s=JSON.parse(Ym.readFileSync(i,"utf-8"));a.push({id:r.name,email:s.user.email})}catch{}}return a}catch(t){return console.error("[auth] failed to list profiles:",t),[]}}function swt(e){try{let t=e.activeProfile;if(Ym.existsSync(t))Ym.unlinkSync(t)}catch(t){console.error("[auth] failed to delete active profile:",t)}}function cwt(e,t){try{let n=Aj.join(t.root,"profiles"),a=Aj.join(n,e);if(Ym.existsSync(a))Ym.rmSync(a,{recursive:!0})}catch(n){throw console.error("[auth] failed to delete profile:",n),n}}var FSa=300000;function uwt(){let e=null,t=2147483647;function n(a){let r=Date.now(),i=a-FSa;if(i<=r)return 0;return Math.min(i-r,t)}return{start(a,r,i){this.stop();let s=a.expiresAt?.value;if(!s){console.warn("[auth] no expiresAt, skipping refresh timer");return}let c=n(s);e=setTimeout(()=>{(async()=>{try{let u=a.accessToken?.value;if(!u){console.warn("[auth] no token for refresh"),a.user.value=null;return}let A=await iwt(u);a.accessToken.value=A.accessToken;let p=Fae(A.accessToken);a.expiresAt.value=p;let d={accessToken:A.accessToken,expiresAt:p,user:A.user};tU(i,d,r),this.start(a,r,i)}catch(u){console.error("[auth] token refresh failed:",u),a.user.value=null,a.accessToken.value=null,Xo.push({kind:"error",title:"Session expired",message:"Your session has expired. Please log in again.",source:"auth",dismissable:!0})}})()},c)},stop(){if(e)clearTimeout(e),e=null}}}function es(e,t,n,a){return{code:e,message:t,service:n,recoverable:a?.recoverable??!0,timestamp:Date.now()}}var lwt=!0,Tae={voice:{visualizer:{minHz:120,maxHz:4000,bucketCount:96,noiseGate:0.05,sharpen:0.7,peakHold:0,rollingMaxDecay:0.7}},devAgents:[{name:"Helios (dev)",description:"Local dev agent",model:{id:"helios-dev",endpoint:"ws://localhost:3010",pathway:"api/chat"},userOwned:!1,devOnly:!0}]};function Mwt(e){let{paths:t,emitError:n,emit:a}=e,r=t;function i(E){return r(E)}function s(){return r()}let c=Dt.ref(null),u=Dt.ref(null),A=Dt.ref("idle"),p=Dt.ref(null),d=Dt.ref(null),g=uwt(),f=null,b=Dt.ref(null),y=Dt.ref([]);function D(E){if(n)n(E)}function I(E){if(!E){c.value=null,u.value=null,d.value=null;return}if(E.expiresAt<=Date.now()){c.value=null,u.value=null,d.value=null;return}c.value=E.user,u.value=E.accessToken,d.value=E.expiresAt}async function x(E,B=5){let Q=B*1000;while(A.value==="polling"){try{let T=await rwt(E,f?.signal);if(T.status==="approved"&&T.access_token&&T.user){A.value="approved",Xo.clear(),c.value=T.user,u.value=T.access_token;let N=Fae(T.access_token);d.value=N;let j={accessToken:T.access_token,expiresAt:N,user:T.user},O=i(T.user.id);tU(T.user.id,j,O);let $=s();x2e(T.user.id,$),y.value=Sae($),b.value=T.user.id,g.start({user:c,accessToken:u,expiresAt:d},O,T.user.id),f=null;return}}catch(T){if(T instanceof Error&&T.message.includes("abort")){f=null,A.value="idle";return}console.error("[auth] poll failed:",T),A.value="error";let N=es("DEVICE_POLL_FAILED","Device authorization polling failed","auth",{recoverable:!0});D(N);return}await new Promise((T)=>setTimeout(T,Q))}}return{user:c,accessToken:u,status:A,userCode:p,expiresAt:d,async init(){A.value="idle";let E=s();y.value=Sae(E);let B=owt(E);if(!B){c.value=null;return}let Q=i(B),T=C2e(B,Q);if(b.value=B,!T)return;if(T.expiresAt<=Date.now()){if(lwt)c.value=T.user,u.value=T.accessToken;try{let j=await eU(T.accessToken),O={accessToken:T.accessToken,expiresAt:Date.now()+86400000,user:j};tU(B,O,Q),I(O),g.start({user:c,accessToken:u,expiresAt:d},Q,B)}catch(j){console.error("[auth] session expired and server rejected token:",j),c.value=null,u.value=null,Xo.push({kind:"error",title:"Session expired",message:"Your session has expired. Please log in again.",source:"auth",dismissable:!0})}return}I(T),eU(T.accessToken).then((j)=>{c.value=j}).catch((j)=>{console.debug("[auth] background user refresh failed (OK, using stored):",j)}),g.start({user:c,accessToken:u,expiresAt:d},Q,B)},async startLogin(E){A.value="authorizing",f=new AbortController;try{let B=await awt(E);if(p.value=B.user_code,A.value="polling",B.verification_uri_complete){let Q=(await Promise.resolve().then(() => (Pwt(),jwt))).default;await Q(B.verification_uri_complete)}if(await x(B.device_code,B.interval),c.value)a?.({type:"axon:auth:login",userId:c.value.id})}catch(B){console.error("[auth] authorize failed:",B),A.value="error";let Q=es("DEVICE_AUTHORIZE_FAILED","Failed to start login process","auth",{recoverable:!0});D(Q)}},async logout(){let E=c.value?.id??null;g.stop(),f?.abort(),f=null,c.value=null,u.value=null,p.value=null,d.value=null,b.value=null,A.value="idle",swt(s()),a?.({type:"axon:auth:logout",userId:E})},async refreshUser(){if(!u.value)return;try{c.value=await eU(u.value)}catch{}},profiles:{list:y,active:Dt.computed(()=>b.value),async switch(E){a?.({type:"axon:auth:profile:switch",toUserId:E}),g.stop(),c.value=null,u.value=null,d.value=null;let B=i(E),Q=C2e(E,B);if(I(Q),b.value=E,Q){x2e(E,s());try{let T=await eU(Q.accessToken);c.value=T}catch(T){console.debug("[auth] background user refresh on switch failed:",T)}if(d.value)g.start({user:c,accessToken:u,expiresAt:d},B,E)}},async remove(E){if(E===b.value)throw es("CANNOT_REMOVE_ACTIVE_PROFILE","Cannot remove the active profile. Switch to another profile first.","auth",{recoverable:!0,actionable:!0});let B=s();cwt(E,B),y.value=Sae(B)}}}}import b4 from"fs";import qwt from"path";var iU=[{id:"arc",name:"Arc",shiki:"arcnight",ui:{primary:"#00B4D8",background:"#1e1e1e",textLight:"#e0e0e0",textDark:"#808080"}},{id:"dracula",name:"Dracula",shiki:"dracula",ui:{primary:"#BD93F9",background:"#282a36",textLight:"#f8f8f2",textDark:"#6272a4"}},{id:"nord",name:"Nord",shiki:"nord",ui:{primary:"#88C0D0",background:"#2e3440",textLight:"#eceff4",textDark:"#4c566a"}},{id:"monokai",name:"Monokai",shiki:"monokai",ui:{primary:"#A6E22E",background:"#272822",textLight:"#f8f8f2",textDark:"#75715e"}},{id:"github-light",name:"GitHub Light",shiki:"github-light",ui:{primary:"#0969DA",background:"#ffffff",textLight:"#24292f",textDark:"#57606a"}}],dj={themeId:"arc",selectedAgent:null,scrollback:1000,fontSize:14};function $wt(e){let t=e?.paths??GA,n=e?.emit,a=Dt.ref({...dj}),r=new Map,i=Dt.ref([]),s=null,c=dj.themeId;iU.forEach((b)=>{r.set(b.id,b)}),i.value=Array.from(r.values());function u(){i.value=Array.from(r.values())}async function A(b){try{let y=t(b);if(!b4.existsSync(y.settings))return{...dj};let D=b4.readFileSync(y.settings,"utf-8"),I=JSON.parse(D);return{...dj,...I}}catch(y){return console.error("[prefs] failed to read settings:",y),{...dj}}}function p(b,y){try{if(!b){console.warn("[prefs] writeSettings called without userId");return}let D=t(b),I=qwt.dirname(D.settings);b4.mkdirSync(I,{recursive:!0}),b4.writeFileSync(D.settings,JSON.stringify(y,null,2),"utf-8")}catch(D){throw console.error("[prefs] failed to write settings:",D),D}}async function d(b){try{let y=t(b);if(!b4.existsSync(y.themes))return[];let D=b4.readFileSync(y.themes,"utf-8");return JSON.parse(D)}catch(y){return console.error("[prefs] failed to read themes:",y),[]}}function g(b){try{let y=t(b),D=qwt.dirname(y.themes),I=Array.from(r.values()).filter((x)=>!iU.some((k)=>k.id===x.id));b4.mkdirSync(D,{recursive:!0}),b4.writeFileSync(y.themes,JSON.stringify(I,null,2),"utf-8")}catch(y){throw console.error("[prefs] failed to write themes:",y),y}}let f={theme:Dt.computed(()=>{let b=a.value.themeId,y=r.get(b);if(y)return y;return r.get("arc")||iU[0]}),settings:Dt.computed(()=>({...a.value})),async set(b,y){if(a.value[b]=y,s)p(s,a.value);n?.({type:"axon:prefs:set",key:b,value:y})},async setTheme(b){if(!r.get(b)){console.warn("[prefs] theme not found:",b);return}await f.set("themeId",b),c=b,n?.({type:"axon:prefs:theme",themeId:b})},previewTheme(b){if(!r.has(b))return;a.value={...a.value,themeId:b}},cancelThemePreview(){a.value={...a.value,themeId:c}},themes:{list:Dt.readonly(i),get(b){return r.get(b)},register(b){r.set(b.id,b),u()},async save(b){if(f.themes.register(b),s)g(s)},async remove(b){let y=iU.some((D)=>D.id===b);if(El(!y,`Cannot remove built-in theme: ${b}`),r.delete(b),u(),s)g(s)}},async init(b){s=b;let y=await A(b);a.value=y,c=y.themeId,(await d(b)).forEach((I)=>{f.themes.register(I)})},teardown(){s=null,a.value={...dj},r.clear(),iU.forEach((b)=>{r.set(b.id,b)}),u()}};return f}var Rwt="agent-registry";function G2e(e){let t=Dt.ref([]),n=Dt.ref(!1),a=Dt.ref(null);async function r(){let c=await fetch(`${Pb()}/api/agents`);if(!c.ok)throw Error(`Failed to fetch agent registry: ${c.statusText}`);return await c.json()}async function i(){try{n.value=!0,a.value=null;let c=e.get(Rwt,r);if(c.value!==null)t.value=c.value;await new Promise((u)=>{let A=setInterval(()=>{if(c.value!==null)t.value=c.value,clearInterval(A),u()},10);setTimeout(()=>{clearInterval(A),u()},5000)})}catch(c){let u=c instanceof Error?c.message:"Failed to load agent registry";a.value=u,console.error("[agent-registry] failed to load:",c),Xo.push({kind:"error",title:"Registry Load Failed",message:"Failed to load agent registry.",source:"registries",dismissable:!0})}finally{n.value=!1}}async function s(){try{e.invalidate(Rwt),await i()}catch(c){console.error("[agent-registry] failed to refresh:",c)}}return{list:Dt.readonly(t),isRefreshing:Dt.computed(()=>n.value),loadError:Dt.computed(()=>a.value),load:i,refresh:s}}var Owt="module-registry";function U2e(e){let t=Dt.ref([]),n=Dt.ref(""),a=Dt.ref(!1),r=Dt.computed(()=>{if(!n.value)return t.value;let p=n.value.toLowerCase();return t.value.filter((d)=>d.id.toLowerCase().includes(p)||d.description.toLowerCase().includes(p)||d.tags.some((g)=>g.toLowerCase().includes(p)))});async function i(){let p=await fetch(`${Pb()}/api/capsuleer/modules`);if(!p.ok)throw Error(`Failed to fetch module registry: ${p.statusText}`);return await p.json()}async function s(){try{a.value=!0;let p=e.get(Owt,i);if(p.value!==null)t.value=p.value;await new Promise((d)=>{let g=setInterval(()=>{if(p.value!==null)t.value=p.value,clearInterval(g),d()},10);setTimeout(()=>{clearInterval(g),d()},5000)})}catch(p){console.error("[module-registry] failed to load:",p),Xo.push({kind:"error",title:"Module Registry Load Failed",message:"Failed to load module registry.",source:"registries",dismissable:!0})}finally{a.value=!1}}async function c(){try{e.invalidate(Owt),await s()}catch(p){console.error("[module-registry] failed to refresh:",p)}}function u(p){n.value=p??""}async function A(p){try{let d=await fetch(`${Pb()}/api/capsuleer/modules/${p}`);if(!d.ok){if(d.status===404)return null;throw Error(`Failed to fetch module: ${d.statusText}`)}return await d.json()}catch(d){return console.error("[module-registry] failed to get module:",d),null}}return{list:Dt.readonly(r),isRefreshing:Dt.computed(()=>a.value),load:s,refresh:c,search:u,get:A}}var Gwt="model-registry";function Uwt(e){let t=Dt.ref([]),n=Dt.ref(!1),a=Dt.ref(null);async function r(){let c=await fetch(`${Pb()}/api/models`);if(!c.ok)throw Error(`Failed to fetch model registry: ${c.statusText}`);return await c.json()}async function i(){try{n.value=!0,a.value=null;let c=e.get(Gwt,r);if(c.value!==null)t.value=c.value;await new Promise((u)=>{let A=setInterval(()=>{if(c.value!==null)t.value=c.value,clearInterval(A),u()},10);setTimeout(()=>{clearInterval(A),u()},5000)})}catch(c){let u=c instanceof Error?c.message:"Failed to load model registry";a.value=u,console.error("[model-registry] failed to load:",c)}finally{n.value=!1}}async function s(){try{e.invalidate(Gwt),await i()}catch(c){console.error("[model-registry] failed to refresh:",c)}}return{list:Dt.readonly(t),isRefreshing:Dt.computed(()=>n.value),loadError:Dt.computed(()=>a.value),load:i,refresh:s}}import h4 from"fs";import zwt from"path";function Hwt(e){let t=e?.paths??VG;function n(a){let r=t({root:a});function i(){try{if(!h4.existsSync(r.manifest))return[];let p=h4.readFileSync(r.manifest,"utf-8");return JSON.parse(p)}catch(p){return console.error("[capsule] failed to load manifest:",p),[]}}function s(p){try{h4.mkdirSync(zwt.dirname(r.manifest),{recursive:!0}),h4.writeFileSync(r.manifest,JSON.stringify(p,null,2),"utf-8")}catch(d){throw console.error("[capsule] failed to save manifest:",d),d}}async function c(p,d){let f=await Bun.spawn(["bun","x","capsuleer",p,...d],{stdout:"inherit",stderr:"inherit"}).exited;if(f!==0)throw Error(`capsuleer exited with code ${f}`)}let u={list(){return i()},async install(p){try{Xo.push({kind:"info",title:"Installing Module",message:`Installing ${p}...`,source:"capsule",dismissable:!0}),await c("install",[p]),Xo.push({kind:"success",title:"Module Installed",message:`${p} installed successfully.`,source:"capsule",dismissable:!0})}catch(d){console.error("[capsule] install failed:",d);let g=es("CAPSULE_INSTALL_FAILED",`Failed to install module ${p}: ${d instanceof Error?d.message:"unknown error"}`,"capsule",{recoverable:!0});throw Xo.push({kind:"error",title:"Install Failed",message:`Failed to install ${p}.`,source:"capsule",dismissable:!0}),g}},async remove(p){try{Xo.push({kind:"info",title:"Removing Module",message:`Removing ${p}...`,source:"capsule",dismissable:!0}),await c("remove",[p]),Xo.push({kind:"success",title:"Module Removed",message:`${p} removed successfully.`,source:"capsule",dismissable:!0})}catch(d){console.error("[capsule] remove failed:",d);let g=es("CAPSULE_REMOVE_FAILED",`Failed to remove module ${p}: ${d instanceof Error?d.message:"unknown error"}`,"capsule",{recoverable:!0});throw Xo.push({kind:"error",title:"Remove Failed",message:`Failed to remove ${p}.`,source:"capsule",dismissable:!0}),g}}},A={get(){try{if(!h4.existsSync(r.env))return{};let p=h4.readFileSync(r.env,"utf-8");return JSON.parse(p)}catch(p){return console.error("[capsule] failed to read env:",p),{}}},async set(p,d){try{let g=A.get();g[p]=d,h4.mkdirSync(zwt.dirname(r.env),{recursive:!0}),h4.writeFileSync(r.env,JSON.stringify(g,null,2),"utf-8")}catch(g){throw console.error("[capsule] failed to set env:",g),g}}};return{modules:u,env:A}}return{blueprint:n(VG().root)}}import{existsSync as gTa,readFileSync as fTa,writeFileSync as bTa,rmSync as Kwt}from"fs";import{spawn as hTa}from"child_process";function Jwt(e){try{return fTa(e,"utf-8").trim()}catch{return null}}function Wwt(e){try{let{readFileSync:t,realpathSync:n}=nb("fs"),a=nb("path"),r=n(e),i=a.join(a.dirname(r),"..","package.json");return JSON.parse(t(i,"utf-8")).version??null}catch{return null}}function z2e(e={}){let t=VG(e.capsuleerRoot?{root:e.capsuleerRoot}:void 0),n=Dt.ref("idle"),a=Dt.ref(null),r=null;function i(){return Jwt(t.readyMarker)!==null}async function s(){let A=k2e();if(!gTa(A)&&A!=="capsuleer"){let d=`capsuleer binary not found at: ${A}. Try reinstalling Axon.`;throw Xo.push({kind:"error",title:"Capsuleer Setup Failed",message:d,source:"capsuleer",dismissable:!0}),Error(d)}Xo.push({kind:"info",title:"Setting Up Capsuleer",message:"Installing capsule environment...",source:"capsuleer",dismissable:!1}),await new Promise((d,g)=>{if(e.spawnInstall){e.spawnInstall().then(d).catch(g);return}let f=hTa(A,["env:install"],{stdio:["ignore","pipe","pipe"],env:{...process.env,NO_COLOR:"1"}}),b="";f.stdout?.on("data",(y)=>{let D=y.toString();for(let I of D.split(`
798
798
  `)){let x=I.trim();if(x)console.log("[capsuleer]",x)}}),f.stderr?.on("data",(y)=>{b+=y.toString()}),f.on("close",(y)=>{if(y===0)d();else{let D=/^(Resolving|Resolved,|Saved lockfile|[+\-]\s+\S+@|\d+ packages?)/,I=b.split(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcforge/axon",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "coding agent cli",
5
5
  "type": "module",
6
6
  "bin": {