agentix-cli 0.86.0 → 0.88.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{App-NLEBAGQK.js → App-BSGDYHRD.js} +2 -2
- package/dist/{ChatApp-JN2WJ7ZK.js → ChatApp-K57DBCDT.js} +2 -2
- package/dist/{agent-QORMJHWT.js → agent-6MTUM5DR.js} +2 -2
- package/dist/{board-dashboard-YG3MBOXP.js → board-dashboard-MHMXII6V.js} +414 -220
- package/dist/board-dashboard-MHMXII6V.js.map +1 -0
- package/dist/{chunk-YK6VYYHC.js → chunk-2FLVU2QW.js} +2 -2
- package/dist/{chunk-GO57OXET.js → chunk-54VYZE7A.js} +10 -10
- package/dist/{chunk-GO57OXET.js.map → chunk-54VYZE7A.js.map} +1 -1
- package/dist/{chunk-CZ4CWVDE.js → chunk-7ADEEHZQ.js} +2 -2
- package/dist/{chunk-AXW5U32B.js → chunk-7K5SJJUI.js} +2 -2
- package/dist/{chunk-5PEOSZ44.js → chunk-7OEFPYQJ.js} +2 -2
- package/dist/{chunk-VQVN3VSJ.js → chunk-7QDAGGOD.js} +2 -2
- package/dist/{chunk-CPXZWVKN.js → chunk-BFY4D4RH.js} +2 -2
- package/dist/{chunk-RLSRENAO.js → chunk-BOENB3IK.js} +2 -2
- package/dist/{chunk-NY7ZZGT3.js → chunk-BUELCBBV.js} +27 -27
- package/dist/{chunk-NY7ZZGT3.js.map → chunk-BUELCBBV.js.map} +1 -1
- package/dist/{chunk-KK6HPN3U.js → chunk-C3VCIEZS.js} +6 -6
- package/dist/chunk-C3VCIEZS.js.map +1 -0
- package/dist/{chunk-CL53UVOF.js → chunk-DWZYVYZS.js} +2 -2
- package/dist/chunk-DWZYVYZS.js.map +1 -0
- package/dist/{chunk-WBJLVFBW.js → chunk-ECCPLASB.js} +2 -2
- package/dist/{chunk-WLKQFYUM.js → chunk-EUXF2GJY.js} +2 -2
- package/dist/{chunk-QIJOGYK5.js → chunk-HOXHUFZB.js} +2 -2
- package/dist/{chunk-TICACOQG.js → chunk-HQWMWSSE.js} +2 -2
- package/dist/{chunk-SPSICIEA.js → chunk-I6HCIQCQ.js} +2 -2
- package/dist/{chunk-FRWV3XOV.js → chunk-KIXDJEGA.js} +2 -2
- package/dist/{chunk-FORTAGGM.js → chunk-L6BO76GK.js} +161 -161
- package/dist/chunk-L6BO76GK.js.map +1 -0
- package/dist/{chunk-NNAMMKT7.js → chunk-MZQ5PCLA.js} +2 -2
- package/dist/{chunk-ANJ2BO7D.js → chunk-N4HFUAPN.js} +2 -2
- package/dist/{chunk-O5U5NVLR.js → chunk-OAA7TNB6.js} +2 -2
- package/dist/{chunk-YSV53UFR.js → chunk-TNR7AI4H.js} +5 -5
- package/dist/{chunk-DTXI7LEI.js → chunk-X2F3AVGR.js} +2 -2
- package/dist/{chunk-M457SOS3.js → chunk-XVDASTUX.js} +2 -2
- package/dist/cli.js +1 -1
- package/dist/{client-5Z4IVYAH.js → client-UKLOVDZB.js} +2 -2
- package/dist/config-WUDWHRT6.js +2 -0
- package/dist/config-mutator-UPLM7KGO.js +2 -0
- package/dist/{doctor-UKWJO3TG.js → doctor-COAIIKLV.js} +2 -2
- package/dist/index.js +1 -1
- package/dist/processes-TXEWMXXJ.js +2 -0
- package/dist/{program-PUG7P7TC.js → program-VX4XZAE6.js} +14 -14
- package/dist/{promote-3R56RJQD.js → promote-B7FGHUFA.js} +2 -2
- package/dist/{query-6ZTEUTKC.js → query-ZSVAGGSM.js} +2 -2
- package/dist/{registry-KJZDXHKL.js → registry-4DWWYWDR.js} +2 -2
- package/dist/{request-planner-JFES5YW2.js → request-planner-DSXXT75B.js} +2 -2
- package/dist/{review-candidates-OR375PHS.js → review-candidates-34S6R3DJ.js} +2 -2
- package/dist/{routing-W2E52LYP.js → routing-HWGNYIF3.js} +2 -2
- package/dist/schedule-tool-JLIS2GQU.js +2 -0
- package/dist/scheduler-F6NRVZ7W.js +2 -0
- package/dist/{seat-GAS7YKQA.js → seat-OQZY3CW7.js} +2 -2
- package/dist/{select-UYFJH4V5.js → select-BBTWL7FN.js} +2 -2
- package/dist/{set-enabled-PFMELM3V.js → set-enabled-OC3YT4D4.js} +2 -2
- package/dist/{tool-BGEHMLJ3.js → tool-P4AHNZ5O.js} +2 -2
- package/dist/{tool-W4NSPPXO.js → tool-R36FDI6E.js} +2 -2
- package/dist/wiki-5E4AGLKY.js +2 -0
- package/package.json +1 -1
- package/dist/board-dashboard-YG3MBOXP.js.map +0 -1
- package/dist/chunk-CL53UVOF.js.map +0 -1
- package/dist/chunk-FORTAGGM.js.map +0 -1
- package/dist/chunk-KK6HPN3U.js.map +0 -1
- package/dist/config-2SRJEOO7.js +0 -2
- package/dist/config-mutator-RKEMP53O.js +0 -2
- package/dist/processes-5EXCTSD5.js +0 -2
- package/dist/schedule-tool-XZL5AKFB.js +0 -2
- package/dist/scheduler-BOQJMSJE.js +0 -2
- package/dist/wiki-L5FJ5RYE.js +0 -2
- /package/dist/{App-NLEBAGQK.js.map → App-BSGDYHRD.js.map} +0 -0
- /package/dist/{ChatApp-JN2WJ7ZK.js.map → ChatApp-K57DBCDT.js.map} +0 -0
- /package/dist/{agent-QORMJHWT.js.map → agent-6MTUM5DR.js.map} +0 -0
- /package/dist/{chunk-YK6VYYHC.js.map → chunk-2FLVU2QW.js.map} +0 -0
- /package/dist/{chunk-CZ4CWVDE.js.map → chunk-7ADEEHZQ.js.map} +0 -0
- /package/dist/{chunk-AXW5U32B.js.map → chunk-7K5SJJUI.js.map} +0 -0
- /package/dist/{chunk-5PEOSZ44.js.map → chunk-7OEFPYQJ.js.map} +0 -0
- /package/dist/{chunk-VQVN3VSJ.js.map → chunk-7QDAGGOD.js.map} +0 -0
- /package/dist/{chunk-CPXZWVKN.js.map → chunk-BFY4D4RH.js.map} +0 -0
- /package/dist/{chunk-RLSRENAO.js.map → chunk-BOENB3IK.js.map} +0 -0
- /package/dist/{chunk-WBJLVFBW.js.map → chunk-ECCPLASB.js.map} +0 -0
- /package/dist/{chunk-WLKQFYUM.js.map → chunk-EUXF2GJY.js.map} +0 -0
- /package/dist/{chunk-QIJOGYK5.js.map → chunk-HOXHUFZB.js.map} +0 -0
- /package/dist/{chunk-TICACOQG.js.map → chunk-HQWMWSSE.js.map} +0 -0
- /package/dist/{chunk-SPSICIEA.js.map → chunk-I6HCIQCQ.js.map} +0 -0
- /package/dist/{chunk-FRWV3XOV.js.map → chunk-KIXDJEGA.js.map} +0 -0
- /package/dist/{chunk-NNAMMKT7.js.map → chunk-MZQ5PCLA.js.map} +0 -0
- /package/dist/{chunk-ANJ2BO7D.js.map → chunk-N4HFUAPN.js.map} +0 -0
- /package/dist/{chunk-O5U5NVLR.js.map → chunk-OAA7TNB6.js.map} +0 -0
- /package/dist/{chunk-YSV53UFR.js.map → chunk-TNR7AI4H.js.map} +0 -0
- /package/dist/{chunk-DTXI7LEI.js.map → chunk-X2F3AVGR.js.map} +0 -0
- /package/dist/{chunk-M457SOS3.js.map → chunk-XVDASTUX.js.map} +0 -0
- /package/dist/{client-5Z4IVYAH.js.map → client-UKLOVDZB.js.map} +0 -0
- /package/dist/{config-2SRJEOO7.js.map → config-WUDWHRT6.js.map} +0 -0
- /package/dist/{config-mutator-RKEMP53O.js.map → config-mutator-UPLM7KGO.js.map} +0 -0
- /package/dist/{doctor-UKWJO3TG.js.map → doctor-COAIIKLV.js.map} +0 -0
- /package/dist/{processes-5EXCTSD5.js.map → processes-TXEWMXXJ.js.map} +0 -0
- /package/dist/{program-PUG7P7TC.js.map → program-VX4XZAE6.js.map} +0 -0
- /package/dist/{promote-3R56RJQD.js.map → promote-B7FGHUFA.js.map} +0 -0
- /package/dist/{query-6ZTEUTKC.js.map → query-ZSVAGGSM.js.map} +0 -0
- /package/dist/{registry-KJZDXHKL.js.map → registry-4DWWYWDR.js.map} +0 -0
- /package/dist/{request-planner-JFES5YW2.js.map → request-planner-DSXXT75B.js.map} +0 -0
- /package/dist/{review-candidates-OR375PHS.js.map → review-candidates-34S6R3DJ.js.map} +0 -0
- /package/dist/{routing-W2E52LYP.js.map → routing-HWGNYIF3.js.map} +0 -0
- /package/dist/{schedule-tool-XZL5AKFB.js.map → schedule-tool-JLIS2GQU.js.map} +0 -0
- /package/dist/{scheduler-BOQJMSJE.js.map → scheduler-F6NRVZ7W.js.map} +0 -0
- /package/dist/{seat-GAS7YKQA.js.map → seat-OQZY3CW7.js.map} +0 -0
- /package/dist/{select-UYFJH4V5.js.map → select-BBTWL7FN.js.map} +0 -0
- /package/dist/{set-enabled-PFMELM3V.js.map → set-enabled-OC3YT4D4.js.map} +0 -0
- /package/dist/{tool-BGEHMLJ3.js.map → tool-P4AHNZ5O.js.map} +0 -0
- /package/dist/{tool-W4NSPPXO.js.map → tool-R36FDI6E.js.map} +0 -0
- /package/dist/{wiki-L5FJ5RYE.js.map → wiki-5E4AGLKY.js.map} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as j,b as O,c as T,d as D,e as _,j as N}from"./chunk-
|
|
1
|
+
import{a as j,b as O,c as T,d as D,e as _,j as N}from"./chunk-HOXHUFZB.js";import{b as R}from"./chunk-2GIDVZ4H.js";import{v as C,w as I}from"./chunk-ECCPLASB.js";import{b as v,c as W}from"./chunk-QOYAX2FT.js";import{readFileSync as Y,existsSync as B}from"fs";I();import{resolve as x}from"path";import{execSync as L}from"child_process";async function nt(n,a,o,t={}){let u=t.selectorModel??"haiku",g=t.synthModel??"sonnet",l=t.maxCandidates??3,r=t.maxHops??2,s=t.maxArticles??8,h=t.timeoutMs??6e4,p=t.log??console.error.bind(console,"[wiki-query]"),m=t.messagePath?.length?t.messagePath:void 0,w=t.graphWeight??$,i=x(a.baseDir,"_index.md");if(!B(i))return A("no-catalog",n,"No _index.md found \u2014 run `agentx wiki status` to rebuild.");let e=Y(i,"utf-8"),d=Date.now(),f=[],y="";try{let c=await G(n,a,o,l,m,w);c?(f=c,y=`[wiki-rerank seat] ${c.map(k=>k.title).join(" | ")}`):(y=await Q(q(n,e,l,m),u,h),f=K(y))}catch(c){return p("selector failed:",c?.message),{...A("error",n,`Selector: ${c?.message||"unknown"}`),trace:{selectorMs:Date.now()-d,synthesisMs:0,selectorOutput:y}}}let S=Date.now()-d;if(f.length===0)return{...A("no-candidates",n,"Selector returned no candidates."),trace:{selectorMs:S,synthesisMs:0,selectorOutput:y}};let b=F(f,a,o,r,s);if(b.length===0)return{...A("no-candidates",n,"Candidates did not resolve to readable articles."),candidates:f,trace:{selectorMs:S,synthesisMs:0,selectorOutput:y}};let M=Date.now(),P="";try{P=await Q(J(n,b),g,h*2)}catch(c){return p("synthesis failed:",c?.message),{...A("error",n,`Synthesis: ${c?.message||"unknown"}`),candidates:f,walked:b.map(k=>({title:k.meta.title,path:k.path,type:k.meta.type,hop:k.hop??0})),trace:{selectorMs:S,synthesisMs:Date.now()-M,selectorOutput:y}}}let E=Date.now()-M;return{answer:P.trim(),citations:b.map(c=>({title:c.meta.title,path:c.path,type:c.meta.type})),candidates:f,walked:b.map(c=>({title:c.meta.title,path:c.path,type:c.meta.type,hop:c.hop??0})),status:"ok",trace:{selectorMs:S,synthesisMs:E,selectorOutput:y}}}function A(n,a,o){return{answer:"",citations:[],candidates:[],walked:[],status:n,error:o}}function F(n,a,o,t,u){let g=new Map;for(let s of a.listArticles(o||""))g.set(s.meta.title.toLowerCase(),s.path);let l=new Map,r=[];for(let s of n)l.has(s.path)||r.push({path:s.path,hop:0});for(;r.length&&l.size<u;){let s=r.shift();if(l.has(s.path)||s.hop>t)continue;let h=o?a.readArticleAs(s.path,o):a.readArticle(s.path);if(h&&(l.set(s.path,{...h,hop:s.hop}),!(s.hop>=t)))for(let p of h.meta.related||[]){let m=g.get(p.toLowerCase());m&&!l.has(m)&&r.push({path:m,hop:s.hop+1})}}return Array.from(l.values())}async function G(n,a,o,t,u,g=$){try{let r=(a.rebuildIndex().articles??[]).filter(i=>i.path&&!i.path.includes("/_versions/"));if(r.length<2)return null;let h=H(n,r,u,g).slice(0,O).map(i=>({id:`k${i}`,title:r[i].title||r[i].path,tags:r[i].tags,excerpt:[r[i].type?`type: ${r[i].type}`:"",(r[i].related??[]).length?`related: ${(r[i].related??[]).join(", ")}`:"",(r[i].graphPath??[]).length?`graph: ${(r[i].graphPath??[]).join(" \u203A ")}`:""].filter(Boolean).join(" \xB7 ")})),p=await C(j,T({query:n,candidates:h,excerptChars:300}),D(h),{features:{agent:o??"unknown",stage:"catalog-selector"}});if(!p||p.mode!=="active")return null;let w=_(p.answers,h).ranked.slice(0,t).map(i=>r[Number(i.slice(1))]).filter(Boolean).map(i=>({title:i.title,path:i.path}));return w.length>0?w:null}catch{return null}}var $=.6;function H(n,a,o,t=$){let u=a.map(e=>[e.title,(e.tags??[]).join(" "),(e.related??[]).join(" ")].join(" ")),g=W(n,v(u)),l=g.reduce((e,d)=>Math.max(e,d.score),0),r=new Map(g.map(e=>[e.docIndex,l>0?e.score/l:0])),s=!!o?.length,h=e=>s&&e.graphPath?.length?N(o,e.graphPath):0,p=(e,d)=>d.score-e.score||e.i-d.i,m=a.map((e,d)=>({i:d,score:(r.get(d)??0)*(1+t*h(e))})).filter(e=>r.has(e.i)).sort(p),w=a.map((e,d)=>({i:d,score:h(e)})).filter(e=>!r.has(e.i)&&e.score>0).sort(p),i=[...m,...w].map(e=>e.i);for(let e=0;e<a.length;e++)i.includes(e)||i.push(e);return i}function q(n,a,o,t){let u=t?.length?`
|
|
2
2
|
## Intent
|
|
3
3
|
|
|
4
4
|
The request was classified under the intent-graph path "${t.join(" \u203A ")}". Prefer articles filed under the same branch when their titles are equally plausible.
|
|
@@ -46,4 +46,4 @@ ${o}
|
|
|
46
46
|
Answer the question in 2\u20136 sentences. Cite articles by their title in square brackets like [Article Title]. If the articles do not answer the question, say so plainly (do not invent). Prefer concrete facts over hedging.
|
|
47
47
|
|
|
48
48
|
Output ONLY the answer \u2014 no preamble, no "here is my answer:", no markdown fencing.`}function K(n){let a=n.match(/\[[\s\S]*?\]/);if(!a)return[];try{let o=JSON.parse(a[0]);return Array.isArray(o)?o.filter(t=>t&&typeof t.title=="string"&&typeof t.path=="string").map(t=>({title:t.title,path:t.path})):[]}catch{return[]}}async function Q(n,a,o){let{writeFileSync:t,mkdirSync:u,rmSync:g}=await import("fs"),{tmpdir:l}=await import("os"),r=x(l(),`agentx-wiki-query-${process.pid}`);u(r,{recursive:!0});let s=x(r,`prompt-${Date.now()}.txt`);t(s,n);try{let h=`cat '${s}' | claude -p - --output-format json --max-turns 1 --model ${a} --disallowedTools "Bash Read Write Edit Glob Grep Agent WebSearch WebFetch NotebookEdit"`,p=L(h,{env:R({...process.env}),encoding:"utf-8",timeout:o,maxBuffer:4*1024*1024});try{let m=JSON.parse(p);return String(m.result||m.content||"")}catch{return p}}finally{try{g(s,{force:!0})}catch{}}}export{nt as a,$ as b,H as c};
|
|
49
|
-
//# sourceMappingURL=chunk-
|
|
49
|
+
//# sourceMappingURL=chunk-7ADEEHZQ.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{da as m,ga as b}from"./chunk-54VYZE7A.js";b();function w(t){let e=typeof t.node=="string"?t.node:"",n=typeof t.token=="string"?t.token:"";if(!e||!n)try{let o=m(t.config);e||(e=o.dashboard?.daemonUrl||""),n||(n=o.dashboard?.token||"")}catch{}return e||(e="http://localhost:18800"),{baseUrl:e.replace(/\/+$/,""),token:n}}async function d(t,e,n){let o={Accept:"application/json"};t.token&&(o.Authorization=`Bearer ${t.token}`);let r=await fetch(`${t.baseUrl}${e}`,{headers:o,signal:n});if(!r.ok)throw new Error(`GET ${e} \u2192 HTTP ${r.status}`);return await r.json()}function R(t,e){return d(t,"/agents",e)}async function S(t,e){return(await d(t,"/api/processes",e)).processes??[]}function P(t,e){return d(t,"/crons",e)}async function h(t,e,n,o){let r={Accept:"application/json","Content-Type":"application/json"};t.token&&(r.Authorization=`Bearer ${t.token}`);let s=await fetch(`${t.baseUrl}${e}`,{method:"POST",headers:r,body:JSON.stringify(n),signal:o}),a=await s.text(),i;try{i=a?JSON.parse(a):{}}catch{i={raw:a}}if(!s.ok)throw new Error(i?.error||`POST ${e} \u2192 HTTP ${s.status}`);return i}function A(t,e,n="tui"){return h(t,"/api/processes/kill",{...e,reason:n})}function C(t,e,n,o){return h(t,"/task",{agent:e,message:n,context:o??{channel:"tui",chatId:"tui:operator"}})}async function $(t,e,n,o={}){let r={Accept:"text/event-stream","Content-Type":"application/json"};t.token&&(r.Authorization=`Bearer ${t.token}`);let s=await fetch(`${t.baseUrl}/task`,{method:"POST",headers:r,body:JSON.stringify({agent:e,message:n,stream:!0,context:{channel:o.channel??"chat-cli",chatId:o.chatId??"chat-cli:operator"}}),signal:o.signal});if(!s.ok||!s.body){let g=await s.text().catch(()=>"");throw new Error(`POST /task (stream) \u2192 HTTP ${s.status}${g?`: ${g.slice(0,200)}`:""}`)}let a=s.body.getReader(),i=new TextDecoder,u={content:""},c="";try{for(;;){let{done:g,value:p}=await a.read();if(g)break;c+=i.decode(p,{stream:!0});let l;for(;(l=c.indexOf(`
|
|
2
2
|
|
|
3
3
|
`))>=0;){let k=c.slice(0,l);c=c.slice(l+2);let f=x(k);f&&T(f,o,u)}}}finally{try{a.releaseLock()}catch{}}return u}function T(t,e,n){let{event:o,data:r}=t;switch(o){case"text":r?.text&&(n.content+=r.text,e.onText?.(r.text));break;case"thinking":r?.text&&e.onThinking?.(r.text);break;case"tool":e.onTool?.(r);break;case"done":typeof r?.content=="string"&&(n.content=r.content),n.usage=r?.usage,n.duration=r?.duration;break;case"error":n.error=r?.error,n.errorKind=r?.errorKind;break}}function x(t){let e="message",n="";for(let r of t.split(`
|
|
4
4
|
`))r.startsWith("event: ")?e=r.slice(7).trim():r.startsWith("data: ")&&(n=r.slice(6));if(!n)return null;let o;try{o=JSON.parse(n)}catch{o=n}return{event:e,data:o}}export{w as a,R as b,S as c,P as d,A as e,C as f,$ as g};
|
|
5
|
-
//# sourceMappingURL=chunk-
|
|
5
|
+
//# sourceMappingURL=chunk-7K5SJJUI.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{b as C}from"./chunk-CECHWYJ2.js";import{a as L,b as _,c as R,d as j,e as M,j as I}from"./chunk-
|
|
1
|
+
import{b as C}from"./chunk-CECHWYJ2.js";import{a as L,b as _,c as R,d as j,e as M,j as I}from"./chunk-HOXHUFZB.js";import{v as x,w as O}from"./chunk-ECCPLASB.js";import{c as A,d as D}from"./chunk-QOYAX2FT.js";import{readFileSync as y,writeFileSync as b,appendFileSync as P,existsSync as w,mkdirSync as $,readdirSync as v,statSync as B}from"fs";import{resolve as u,join as N,relative as k,dirname as U}from"path";O();var T=class{baseDir;rawDir;log;constructor(t=u(process.cwd(),".agentx/wiki"),e=console.error.bind(console,"[wiki]")){this.baseDir=t,this.rawDir=u(t,"raw/entries"),this.log=e,$(this.rawDir,{recursive:!0}),$(u(t,"raw"),{recursive:!0}),this.ensureSchema()}canRead(t,e){return t.access==="public"?!0:e?!!(t.owner===e||t.access==="shared"&&t.sharedWith?.includes(e)):!1}canWrite(t,e){return t.owner===e}addEntry(t){let e=`${t.date}_${t.id}.md`,r=u(this.rawDir,e),n=["---",`id: ${t.id}`,`date: ${t.date}`,`agent: ${t.agentId}`,`source: ${t.source}`];if(t.sourceContext&&n.push(`context: ${t.sourceContext}`),t.meta)for(let[a,s]of Object.entries(t.meta))n.push(`${a}: ${JSON.stringify(s)}`);return n.push("---","",t.content),b(r,n.join(`
|
|
2
2
|
`)),this.appendLog("ingest",`${t.id} from ${t.agentId} via ${t.source}`),e}listEntries(t){if(!w(this.rawDir))return[];let e=v(this.rawDir).filter(n=>n.endsWith(".md")).sort(),r=[];for(let n of e){let a=y(u(this.rawDir,n),"utf-8"),s=this.parseEntry(a,n);s&&(t?.agentId&&s.agentId!==t.agentId||t?.after&&s.date<t.after||t?.before&&s.date>t.before||r.push(s))}return r}parseEntry(t,e){let r=t.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);if(!r)return null;let n=r[1],a=r[2].trim(),s=c=>n.match(new RegExp(`^${c}:\\s*(.+)$`,"m"))?.[1]?.trim()||"",o=new Set(["id","date","agent","source","context"]),i={};for(let c of n.split(`
|
|
3
3
|
`)){let l=c.match(/^(\w+):\s*(.+)$/);if(!(!l||o.has(l[1])))try{i[l[1]]=JSON.parse(l[2])}catch{i[l[1]]=l[2].trim()}}return{id:s("id")||e.replace(".md",""),date:s("date"),agentId:s("agent"),source:s("source"),sourceContext:s("context")||void 0,content:a,meta:Object.keys(i).length>0?i:void 0}}writeArticle(t,e,r,n){let a=this.readArticle(t);if(a&&!this.canWrite(a.meta,n))return this.log(`Permission denied: "${n}" cannot write "${t}" (owner: ${a.meta.owner})`),!1;e.type&&!C(e.type)&&(this.log(`Dropping invalid article type "${e.type}" for "${t}" \u2014 enum is [person, project, place, concept, event, decision, pattern]`),e={...e,type:void 0});let s=u(this.baseDir,t);a&&this.saveVersion(t,s),$(U(s),{recursive:!0});let o=["---",`title: "${e.title}"`];e.type&&o.push(`type: ${e.type}`),e.related?.length&&o.push(`related: [${e.related.map(c=>`"${c}"`).join(", ")}]`),o.push(`tags: [${(e.tags||[]).map(c=>`"${c}"`).join(", ")}]`,`owner: ${e.owner}`,`access: ${e.access}`),e.sharedWith?.length&&o.push(`shared_with: [${e.sharedWith.map(c=>`"${c}"`).join(", ")}]`),o.push(`created: ${e.created}`,`last_updated: ${e.lastUpdated}`,`sources: [${e.sources.map(c=>`"${c}"`).join(", ")}]`),e.graphPath?.length&&o.push(`graph_path: [${e.graphPath.map(c=>`"${c}"`).join(", ")}]`),o.push("---","",r),b(s,o.join(`
|
|
4
4
|
`));let i=a?"update":"create";return this.appendLog(i,`${e.title} [${(e.tags||[]).slice(0,5).join(", ")}] by ${n} at ${t}`),!0}saveVersion(t,e){try{if(!w(e))return;let r=y(e,"utf-8"),n=new Date().toISOString().replace(/[:.]/g,"-"),a=u(this.baseDir,"_versions",t.replace(/\.md$/,""));$(a,{recursive:!0}),b(u(a,`${n}.md`),r)}catch{}}getVersions(t){let e=u(this.baseDir,"_versions",t.replace(/\.md$/,""));if(!w(e))return[];try{return v(e).filter(r=>r.endsWith(".md")).sort().reverse().map(r=>({timestamp:r.replace(/\.md$/,"").replace(/-/g,(n,a)=>a<19?a===10?"T":a===13||a===16?":":"-":n),path:u(e,r)}))}catch{return[]}}restoreVersion(t,e){let n=this.getVersions(t).find(a=>a.timestamp.startsWith(e));if(!n)return!1;try{let a=y(n.path,"utf-8"),s=u(this.baseDir,t);return this.saveVersion(t,s),b(s,a),this.appendLog("restore",`${t} restored to ${e}`),!0}catch{return!1}}readArticle(t){let e=u(this.baseDir,t);if(!w(e))return null;let r=y(e,"utf-8");return this.parseArticle(r,t)}readArticleAs(t,e){let r=this.readArticle(t);return!r||!this.canRead(r.meta,e)?null:r}parseArticle(t,e){let r=t.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);if(!r)return null;let n=r[1],a=r[2].trim(),s=m=>n.match(new RegExp(`^${m}:\\s*(.+)$`,"m"))?.[1]?.trim().replace(/^"(.*)"$/,"$1")||"",o=m=>{let h=n.match(new RegExp(`^${m}:\\s*\\[(.*)\\]$`,"m"));return h?h[1].split(",").map(f=>f.trim().replace(/^"(.*)"$/,"$1")).filter(Boolean):[]},i=s("type")||s("kind"),l=new Set(["person","project","place","concept","event","decision","pattern"]).has(i)?i:void 0,p=o("tags").filter((m,h,f)=>m&&f.indexOf(m)===h),d=o("related"),g=o("graph_path");return{meta:{title:s("title"),type:l,related:d.length?d:void 0,tags:p,owner:s("owner"),access:s("access")||"public",sharedWith:o("shared_with"),created:s("created"),lastUpdated:s("last_updated"),sources:o("sources"),graphPath:g.length?g:void 0},content:a,path:e}}listCache=new Map;listArticles(t){let e=[],r=[];this.walkDir(this.baseDir,(o,i)=>{if(!o.endsWith(".md"))return;let c=k(this.baseDir,o);c.startsWith("raw/")||c.startsWith("_")||(e.push(c),r.push(`${c}:${i?.mtimeMs??"?"}:${i?.size??"?"}`))});let n=r.join("|"),a=this.listCache.get(t);if(a&&a.signature===n)return a.articles.slice();let s=[];for(let o of e){let i=this.readArticle(o);i&&this.canRead(i.meta,t)&&s.push(i)}return this.listCache.set(t,{signature:n,articles:s}),s.slice()}search(t,e,r=10){let n=t.toLowerCase(),a=[];if(this.walkDir(this.baseDir,d=>{if(!d.endsWith(".md"))return;let g=k(this.baseDir,d);if(g.startsWith("raw/")||g.startsWith("_"))return;let m=this.readArticle(g);!m||!this.canRead(m.meta,e)||a.push(m)}),a.length===0)return[];let s=a.map(d=>d.content),o=u(this.baseDir,"_bm25_cache.json"),i=D(s,o),c=A(t,i),l=new Map(c.map(d=>[d.docIndex,d.score]));return a.map((d,g)=>{let m=l.get(g)??0;return d.meta.title.toLowerCase().includes(n)&&(m+=10),d.meta.tags?.some(h=>h.toLowerCase().includes(n))&&(m+=5),{article:d,score:m}}).filter(d=>d.score>0).sort((d,g)=>g.score-d.score).slice(0,r).map(d=>d.article)}async findRelevantReranked(t,e,r=10,n={}){let a=Math.max(r,n.shortlist??_),s=this.findRelevant(t,e,a);if(s.length<2)return s.slice(0,r);let o=s.map((l,p)=>({id:`c${p}`,title:l.meta.title||`(untitled ${p})`,tags:l.meta.tags,excerpt:l.content})),i=await x(L,R({query:t,candidates:o,excerptChars:n.excerptChars}),j(o),{incumbent:{best:o[0].id},features:{agent:e??"unknown"}});return!i||i.mode!=="active"?s.slice(0,r):M(i.answers,o).ranked.map(l=>s[Number(l.slice(1))]).filter(l=>!!l).slice(0,r)}findRelevant(t,e,r=3,n,a={graph:.6,bm25:.4}){let s=[];if(this.walkDir(this.baseDir,h=>{if(!h.endsWith(".md"))return;let f=k(this.baseDir,h);if(f.startsWith("raw/")||f.startsWith("_"))return;let W=this.readArticle(f);!W||!this.canRead(W.meta,e)||s.push(W)}),s.length===0)return[];let o=s.map(h=>`${h.meta.title} ${(h.meta.tags||[]).join(" ")} ${h.content}`),i=u(this.baseDir,"_bm25_relevance_cache.json"),c=D(o,i),l=A(t,c),p=l.reduce((h,f)=>Math.max(h,f.score),0)||1,d=new Map(l.map(h=>[h.docIndex,h.score/p])),g=!!(n&&n.length>0);return s.map((h,f)=>{let W=d.get(f)??0,S=0;g&&h.meta.graphPath?.length&&(S=I(n,h.meta.graphPath));let E=g?a.graph*S+a.bm25*W:W;return{article:h,score:E}}).filter(h=>h.score>0).sort((h,f)=>f.score-h.score).slice(0,r).map(h=>h.article)}buildContext(t,e=4e3){if(t.length===0)return"";let r=["[Wiki Knowledge]"],n=0;for(let a of t){let s=`
|
|
@@ -102,4 +102,4 @@ We use GitLab for version control.
|
|
|
102
102
|
There are ${e.length} unprocessed entries. Read each, understand what it means, and create or update wiki articles.
|
|
103
103
|
|
|
104
104
|
${r}`}walkDir(t,e){if(w(t))for(let r of v(t)){let n=N(t,r),a=B(n);a.isDirectory()?this.walkDir(n,e):e(n,a)}}};export{T as a};
|
|
105
|
-
//# sourceMappingURL=chunk-
|
|
105
|
+
//# sourceMappingURL=chunk-7OEFPYQJ.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{q as _,r as W}from"./chunk-2AXFYDWF.js";import{b as Y,c as I,d as O}from"./chunk-AQASR6KR.js";import{b as F}from"./chunk-DP7RTNDM.js";import{a as E}from"./chunk-
|
|
1
|
+
import{q as _,r as W}from"./chunk-2AXFYDWF.js";import{b as Y,c as I,d as O}from"./chunk-AQASR6KR.js";import{b as F}from"./chunk-DP7RTNDM.js";import{a as E}from"./chunk-7OEFPYQJ.js";import{b as L}from"./chunk-CECHWYJ2.js";import{createHash as ee}from"crypto";import{existsSync as H,readdirSync as te,readFileSync as re,writeFileSync as ne}from"fs";import{resolve as P}from"path";function be(n,r,s,t,o,i,c=""){return Z(r,s,t,o,i,c)}function Z(n,r,s,t,o,i=""){let c=r?`
|
|
2
2
|
## Worldview
|
|
3
3
|
|
|
4
4
|
${r}
|
|
@@ -240,4 +240,4 @@ ${g}`}var x="memory-promoter",oe=["project","reference","feedback"],K="_memory-p
|
|
|
240
240
|
Re-emit the FULL corrected JSON object \u2014 same structure, fixed issues, valid JSON only.`:n,y=await t(`${a}/task`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agent:r.viaAgent,message:h,freshSession:s===null,context:{channel:"api",chatId:r.chatId??"memory-promote"}}),signal:i.signal});if(!y.ok){let f=await y.text().catch(()=>"");throw new Error(`agent /task ${y.status}: ${f.slice(0,500)}`)}let w=await y.json();if(w.error)throw new Error(`agent reported error: ${w.error}`);let b=String(w.content??"").trim();if(!b)throw new Error("agent returned empty content");return b}if(!r.model)throw new Error("callPromotionLlm: viaAgent or model is required");let p=process.env.ANTHROPIC_API_KEY;if(!p)throw new Error("ANTHROPIC_API_KEY not set; use --via <agentId> instead");let u=[{role:"user",content:n}];s&&(u.push({role:"assistant",content:"(previous attempt; will retry with corrections)"}),u.push({role:"user",content:`Your previous response failed validation: ${s}
|
|
241
241
|
Re-emit the FULL corrected JSON object.`}));let g=await t(me,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":p,"anthropic-version":ge},body:JSON.stringify({model:r.model,max_tokens:8e3,messages:u}),signal:i.signal});if(!g.ok){let a=await g.text().catch(()=>"");throw new Error(`anthropic API ${g.status}: ${a.slice(0,500)}`)}let l=await g.json(),e=(Array.isArray(l.content)?l.content:[]).filter(a=>a?.type==="text").map(a=>a.text).join(`
|
|
242
242
|
`).trim();if(!e)throw new Error("anthropic API returned no text content");return e}finally{clearTimeout(c)}}async function Se(n={}){let r=n.wikiDir??P(process.cwd(),".agentx","wiki"),s=n.memoryRoot??P(process.cwd(),".agentx"),t=n.log??(()=>{}),o=n.now??Date.now(),i={candidates:[],clusters:[],proposed:[],skipped:[],gaps:[],warnings:[],errors:[],dryRun:!n.commit},c=new E(r,(...m)=>t(m.map(String).join(" "))),p=c.rebuildIndex(),u=z(r),g=[...ce(s),...n.extraCandidates??[]];if(i.candidates=de(g,p,u,{types:n.types,sinceMs:n.sinceMs,agentFilter:n.agentFilter,now:o,max:n.max}),i.candidates.length===0)return t("no unpromoted memories in window"),i;if(i.clusters=le(i.candidates),i.dryRun)return i;let l=p.articles.map(m=>({title:m.title,path:m.path,type:m.type})),d=c.getWorldview()??"",e=n.budgetTokens??ue,a=i.clusters,h=D(x,a,l,d);for(;R(h)>e&&a.length>1;)a=a.slice(0,-1),h=D(x,a,l,d);if(R(h)>e)return i.errors.push(`judge prompt (~${R(h)} tokens) exceeds the ${e}-token budget even with one cluster`),i;a.length<i.clusters.length&&i.warnings.push(`token budget: judged ${a.length} of ${i.clusters.length} clusters; the rest wait for the next run`);let y=a.flatMap(m=>m.candidates),w=new Set(y.map(m=>m.stamp)),b=n.chatId??`memory-promote-${new Date(o).toISOString().slice(0,10)}`,f=B(await G(h,{...n,chatId:b}),w);if("error"in f&&(t(`parse failed (${f.error}) \u2014 retrying with feedback`),f=B(await G(h,{...n,chatId:b},f.error),w)),"error"in f)return i.errors.push(`LLM response unusable after retry: ${f.error}`),i;i.warnings.push(...f.warnings),i.gaps=f.gaps;let v=new Date(o).toISOString(),k=[],T=new Map(y.map(m=>[m.stamp,m]));for(let m of f.articles){let A=c.readArticle(m.path);if(A&&!c.canWrite(A.meta,x)){i.errors.push(`write denied for "${m.path}" (owned by ${A.meta.owner??"?"})`);continue}let M=fe(m.promotedFrom,T),S={id:Y(o,m.path),createdAt:v,status:"pending",article:m,evidence:M,...A?{replaces:{lastUpdated:A.meta.lastUpdated,contentHash:V(A.content)}}:{}};I(r,S),i.proposed.push({id:S.id,path:m.path,title:m.title,type:m.type,stamps:m.promotedFrom,agents:M.agents,occurrences:M.occurrences});for(let X of m.promotedFrom)k.push({stamp:X,decision:"proposed",article:m.path,proposal:S.id,at:v})}for(let m of f.skipped)k.push({stamp:m.stamp,decision:"skipped",reason:m.reason,at:v}),i.skipped.push(m);return k.length&&C(r,k),i}var ue=6e4;function R(n){return Math.ceil(n.length/4)}function V(n){return ee("sha256").update(n).digest("hex").slice(0,16)}var he=600;function ye(n){return n.startsWith("review:")?"review":n.startsWith(j)?"failure":"memory"}function fe(n,r){let s=[];for(let t of n){let o=r.get(t);o&&s.push({stamp:t,kind:ye(t),agentId:o.agentId,type:o.memory.type,name:o.memory.name,description:o.memory.description,...o.occurrences?{occurrences:o.occurrences}:{},...o.sessions?.length?{sessions:o.sessions}:{},...o.tasks?.length?{tasks:o.tasks}:{},...o.failure?{failure:o.failure}:{},...o.memory.author?{author:o.memory.author}:{},...o.memory.taskId?{taskId:o.memory.taskId}:{},updatedAt:o.memory.updatedAt,excerpt:o.memory.body.slice(0,he)})}return{agents:[...new Set(s.map(t=>t.agentId))].sort(),occurrences:Math.max(1,...s.map(t=>t.occurrences??1)),sources:s}}function Ee(n,r,s={}){let t=O(n,r);if(!t)return{ok:!1,error:`no proposal "${r}"`};if(t.status!=="pending")return{ok:!1,error:`proposal "${r}" is already ${t.status}`};let o=s.log??(()=>{}),i=new E(n,(...a)=>o(a.map(String).join(" "))),{article:c}=t,p=i.readArticle(c.path);if(!s.force){if(p&&!t.replaces)return{ok:!1,error:`"${c.path}" was created after this proposal; review it, then approve with --force`};if(p&&t.replaces&&V(p.content)!==t.replaces.contentHash)return{ok:!1,error:`"${c.path}" changed since this proposal; review it, then approve with --force`}}let u=s.now??Date.now(),g=new Date(u).toISOString().slice(0,10);if(!i.writeArticle(c.path,{title:c.title,type:L(c.type)?c.type:void 0,related:c.related,tags:c.tags,owner:x,access:"public",created:p?.meta.created??g,lastUpdated:g,sources:ae(p?.meta.sources,c.promotedFrom)},c.content,x))return{ok:!1,error:`write denied for "${c.path}" (owned by ${p?.meta.owner??"?"})`};let d=new Date(u).toISOString();C(n,c.promotedFrom.map(a=>({stamp:a,decision:"promoted",article:c.path,proposal:r,at:d}))),i.rebuildIndex();let e={...t,status:"approved",decidedBy:s.by??"operator",decidedAt:d};return I(n,e),{ok:!0,proposal:e}}function Oe(n,r,s={}){let t=O(n,r);if(!t)return{ok:!1,error:`no proposal "${r}"`};if(t.status!=="pending")return{ok:!1,error:`proposal "${r}" is already ${t.status}`};let o=new Date(s.now??Date.now()).toISOString();C(n,t.article.promotedFrom.map(c=>({stamp:c,decision:"rejected",article:t.article.path,proposal:r,reason:s.reason,at:o})));let i={...t,status:"rejected",decidedBy:s.by??"operator",decidedAt:o,...s.reason?{reason:s.reason}:{}};return I(n,i),{ok:!0,proposal:i}}export{be as a,x as b,oe as c,K as d,q as e,ie as f,$ as g,ae as h,ce as i,z as j,C as k,le as l,B as m,de as n,G as o,Se as p,R as q,ye as r,fe as s,Ee as t,Oe as u};
|
|
243
|
-
//# sourceMappingURL=chunk-
|
|
243
|
+
//# sourceMappingURL=chunk-7QDAGGOD.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{d as e}from"./chunk-
|
|
1
|
+
import{d as e}from"./chunk-OAA7TNB6.js";function i(t={}){let r=`<div class="ax-proc__kpis" id="proc-kpis" hidden></div>
|
|
2
2
|
<div class="ax-proc__root">
|
|
3
3
|
<aside class="ax-proc__list">
|
|
4
4
|
<header>
|
|
@@ -253,4 +253,4 @@ import{d as e}from"./chunk-O5U5NVLR.js";function i(t={}){let r=`<div class="ax-p
|
|
|
253
253
|
setInterval(refresh, 5000);
|
|
254
254
|
})();
|
|
255
255
|
`;export{i as a};
|
|
256
|
-
//# sourceMappingURL=chunk-
|
|
256
|
+
//# sourceMappingURL=chunk-BFY4D4RH.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{q as p}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{q as p}from"./chunk-HQWMWSSE.js";import{b as i,c as u,d as l,e as c}from"./chunk-I6HCIQCQ.js";import d from"cronstrue";var f=Intl.DateTimeFormat().resolvedOptions().timeZone,m=600,E='Try: "every morning at 9", "weekdays at 6pm", "every 15 minutes", "every monday at 10am", "1st of every month at noon", "daily at 9:30am", "every hour"',g=/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;function w(e){return g.test(e)}function x(e){try{return new Intl.DateTimeFormat("en-US",{timeZone:e}),!0}catch{return!1}}function $(e){return e?e.split(",").map(r=>r.trim().toLowerCase()).filter(r=>r==="log"||r==="notify"||r==="disable"):["log"]}function S(e){let r=[...e.onError??["log"]];e.notify&&!r.includes("notify")&&r.push("notify");let t={enabled:e.enabled??!0,schedule:e.parsed.cron,timezone:e.timezone||f,agent:e.agent,prompt:e.prompt,timeout:e.timeout??m,onError:r};return e.model&&(t.model=e.model),e.notify&&(t.notify=e.notify),e.createdBy&&(t.createdBy=e.createdBy),e.approval&&(t.approval=e.approval),t}function P(e){try{return d.toString(e,{use24HourTimeFormat:!1})}catch{return e}}function T(e,r,t=new Date){try{return p(e,t,r)}catch{return null}}function A(e,r){if(!e)return"unknown (no match within a year)";try{return`${new Intl.DateTimeFormat("en-GB",{timeZone:r,weekday:"short",day:"2-digit",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit",hour12:!1}).format(e)} (${r})`}catch{return e.toISOString()}}function h(e){return e?.approval?.action==="create"}async function D(e,r={}){let t="",o=await i(n=>{let a=l(n,`crons.${e}`);if(!a)throw new Error(`cron "${e}" not found`);let s=a.approval;if(!s)throw new Error(`cron "${e}" has no pending request`);s.action==="create"?(delete a.approval,a.enabled=!0,t=`${e} approved and enabled (requested by ${s.requestedBy})`):(c(n,`crons.${e}`),t=`${e} deletion approved; job removed (requested by ${s.requestedBy})`)},{configPath:r.configPath,reload:r.reload});return o.success?{success:!0,message:t,result:o}:{success:!1,message:o.error||"failed",result:o}}async function I(e,r={}){let t="",o=await i(n=>{let a=l(n,`crons.${e}`);if(!a)throw new Error(`cron "${e}" not found`);let s=a.approval;if(!s)throw new Error(`cron "${e}" has no pending request`);s.action==="create"?(c(n,`crons.${e}`),t=`${e} rejected; pending job removed`):(delete a.approval,t=`${e} deletion rejected; job kept`)},{configPath:r.configPath,reload:r.reload});return o.success?{success:!0,message:t,result:o}:{success:!1,message:o.error||"failed",result:o}}async function O(e,r,t={}){return i(o=>{let n=l(o,`crons.${e}`);if(!n)throw new Error(`cron "${e}" not found`);if(r&&h(n))throw new Error(`cron "${e}" is awaiting approval; run \`agentx schedule approve ${e}\``);u(o,`crons.${e}.enabled`,r)},{configPath:t.configPath,reload:t.reload})}export{f as a,E as b,w as c,x as d,$ as e,S as f,P as g,T as h,A as i,h as j,D as k,I as l,O as m};
|
|
2
|
+
//# sourceMappingURL=chunk-BOENB3IK.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{c as
|
|
2
|
-
`,l=n+".tmp";
|
|
3
|
-
`,"utf-8"),{file:n}}async function
|
|
1
|
+
import{c as de,d as le,e as K,f as E,g as Y,h as D}from"./chunk-OAA7TNB6.js";import{a as se}from"./chunk-DWZYVYZS.js";import{e as j,g as oe,n as ie,p as J}from"./chunk-XIYWXCNU.js";import{a as ae,b as re}from"./chunk-I6HCIQCQ.js";import{a as ne}from"./chunk-N4HFUAPN.js";import{L as ee,S as ze,aa as q,ca as te,da as U,ga as F,s as L,t as Z,w as Pe}from"./chunk-54VYZE7A.js";import{existsSync as M,readFileSync as he,writeFileSync as ve,appendFileSync as Ue,mkdirSync as We}from"fs";import{dirname as Oe,resolve as P}from"path";import{fileURLToPath as Be}from"url";import{hostname as He}from"os";import{spawn as Le}from"child_process";F();import{existsSync as pe,readFileSync as ce,writeFileSync as G,copyFileSync as _e}from"fs";import{resolve as ge}from"path";function W(e,t={}){let n=t.configPath||ge(process.cwd(),"agentx.json");if(!pe(n))throw new Error(`agentx.json not found at ${n}`);let a=JSON.parse(ce(n,"utf-8")),r=e(a),o=typeof r=="string"?{summary:r}:r,s=JSON.stringify(a,null,2)+`
|
|
2
|
+
`,l=n+".tmp";G(l,s,"utf-8");try{JSON.parse(ce(l,"utf-8"))}catch(p){throw new Error(`config did not round-trip cleanly: ${p.message}`)}let i;return t.skipBackup||(i=`${n}.bak.${Date.now()}`,_e(n,i)),G(n,s,"utf-8"),t.skipReload||De().catch(()=>{}),{summary:o.summary,payload:o.payload,backupPath:i}}function me(e,t={}){let n=t.configPath||ge(process.cwd(),"agentx.json");if(pe(n)&&!t.overwrite)throw new Error(`agentx.json already exists at ${n}. Pass overwrite=true to replace it.`);return G(n,JSON.stringify(e,null,2)+`
|
|
3
|
+
`,"utf-8"),{file:n}}async function De(){try{let t=U().dashboard.daemonUrl?.replace(/\/+$/,"")||"http://127.0.0.1:18800";await fetch(`${t}/reload`,{method:"POST"}).catch(()=>null)}catch{}}function ue(e,t){let n=e.configExists?e.agentCount===0?"Add your first agent":"Add another agent":"Set up your team",a=`<header class="ax-topbar">
|
|
4
4
|
<div class="ax-topbar__left">
|
|
5
5
|
<div class="ax-brand">
|
|
6
6
|
<span class="ax-brand__mark">AX</span>
|
|
@@ -16,7 +16,7 @@ import{c as se,d as de,e as J,f as E,g as K,h as D}from"./chunk-O5U5NVLR.js";imp
|
|
|
16
16
|
<button data-theme-opt="light">Light</button>
|
|
17
17
|
</div>
|
|
18
18
|
</div>
|
|
19
|
-
</header>`,r=D(1,"Team basics",E({name:"nodeName",label:"Team name",hint:"(what you'd call this AgentX install)",value:t,placeholder:"My Team",required:!0})),o=D(2,"First agent",
|
|
19
|
+
</header>`,r=D(1,"Team basics",E({name:"nodeName",label:"Team name",hint:"(what you'd call this AgentX install)",value:t,placeholder:"My Team",required:!0})),o=D(2,"First agent",Y([E({name:"agentName",label:"Agent name",value:"Assistant",placeholder:"Support Bot",required:!0}),E({name:"agentId",label:"Agent id",hint:"(lowercase, no spaces)",value:"assistant",pattern:"[a-z0-9][a-z0-9_-]*",required:!0})])+E({name:"triggerWords",label:"Trigger words",hint:"(comma or space separated \u2014 e.g. <code>@support, support</code>)",value:"@assistant, assistant",required:!0})+Y([E({name:"tier",label:"AI engine",type:"select",options:[{value:"claude-code",label:"Claude Code (recommended)",selected:!0},{value:"codex-cli",label:"Codex CLI"},{value:"opencode",label:"OpenCode CLI"},{value:"sdk",label:"Anthropic API (BYO key)"},{value:"orchestrator",label:"Orchestrator (any provider)"}]}),E({name:"model",label:"Model",hint:"(optional)",value:"claude-sonnet-4-6",placeholder:"claude-sonnet-4-6"})])+E({name:"personality",label:"Personality / instructions",hint:"(optional \u2014 what this agent does, in plain English)",type:"textarea",placeholder:"You are a support agent for Acme Co. Answer customer questions about our product, be friendly, keep replies short."})),s=D(3,"First channel",`
|
|
20
20
|
<label class="ax-toggle"><input type="checkbox" id="enableTelegram" /> Connect Telegram now</label>
|
|
21
21
|
<div class="ax-optional" id="telegramFields">
|
|
22
22
|
${E({name:"telegramAccountId",label:"Account id",hint:"(a label you choose \u2014 e.g. <code>support</code>)",value:"default"})}
|
|
@@ -26,7 +26,7 @@ import{c as se,d as de,e as J,f as E,g as K,h as D}from"./chunk-O5U5NVLR.js";imp
|
|
|
26
26
|
`),l=D(4,"Anthropic API key",E({name:"anthropicApiKey",label:"API key",hint:"(optional \u2014 skip if you're using Claude Code)",type:"password",placeholder:"sk-ant-\u2026",extraAttrs:'autocomplete="off"'})+`<div class="ax-hint-block">
|
|
27
27
|
The key is stored in <code>.env</code> as <code>ANTHROPIC_API_KEY</code> and used to authenticate requests to Anthropic. Keep it private.
|
|
28
28
|
</div>`),i=e.configExists?`<div class="ax-banner">Existing install: <b>${e.agentCount}</b> agent(s), <b>${e.channelCount}</b> channel(s) already configured. This wizard will add to it.</div>`:"",p=`<div class="ax-wizard">
|
|
29
|
-
<h1 class="ax-wizard__h1">${
|
|
29
|
+
<h1 class="ax-wizard__h1">${se(n)}</h1>
|
|
30
30
|
<p class="ax-wizard__lead">Fill in the basics below. We'll write <code>agentx.json</code>, set up a folder for your first agent, and point you at the next step.</p>
|
|
31
31
|
|
|
32
32
|
${i}
|
|
@@ -39,11 +39,11 @@ import{c as se,d as de,e as J,f as E,g as K,h as D}from"./chunk-O5U5NVLR.js";imp
|
|
|
39
39
|
${s}
|
|
40
40
|
${l}
|
|
41
41
|
<footer class="ax-actions">
|
|
42
|
-
${
|
|
43
|
-
${
|
|
42
|
+
${K("Save and continue",{type:"submit",primary:!0,id:"submitBtn"})}
|
|
43
|
+
${K("Skip, I'll do it later",{onclick:"window.location.href='/live'"})}
|
|
44
44
|
</footer>
|
|
45
45
|
</form>
|
|
46
|
-
</div>`;return
|
|
46
|
+
</div>`;return le({title:"AgentX \u2014 Setup",activeTab:"custom",subtitle:"Setup",customHeader:a,noMain:!0,body:p,css:Me,scripts:Ne})}var Me=`
|
|
47
47
|
/* Pre-dashboard topbar variant \u2014 no tab nav, the pills are the only chrome. */
|
|
48
48
|
.ax-topbar__right a.ax-skip {
|
|
49
49
|
padding: 4px 10px; border: 1px solid var(--ax-border-2); border-radius: 4px;
|
|
@@ -100,7 +100,7 @@ import{c as se,d as de,e as J,f as E,g as K,h as D}from"./chunk-O5U5NVLR.js";imp
|
|
|
100
100
|
.ax-next-steps code { background: var(--ax-surface-2); padding: 1px 6px; border-radius: 3px; color: var(--ax-text); font-family: var(--ax-mono); font-size: var(--ax-fs-sm); }
|
|
101
101
|
.ax-startd { margin-top: 14px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
|
|
102
102
|
.ax-startd__status { color: var(--ax-text-2); font-size: var(--ax-fs-sm); }
|
|
103
|
-
.ax-startd__status a { color: var(--ax-accent); }`,
|
|
103
|
+
.ax-startd__status a { color: var(--ax-accent); }`,Ne=`<script>
|
|
104
104
|
document.getElementById('enableTelegram').addEventListener('change', (e) => {
|
|
105
105
|
document.getElementById('telegramFields').classList.toggle('is-show', e.target.checked);
|
|
106
106
|
});
|
|
@@ -174,17 +174,17 @@ document.getElementById('wizard').addEventListener('submit', async (e) => {
|
|
|
174
174
|
btn.disabled = false; btn.textContent = 'Save and continue';
|
|
175
175
|
}
|
|
176
176
|
});
|
|
177
|
-
</script>`;
|
|
177
|
+
</script>`;F();function be(e=process.cwd()){let t=P(e,"agentx.json");if(!M(t))return{configExists:!1,agentCount:0,channelCount:0};try{let n=JSON.parse(he(t,"utf-8")),a=n.agents?Object.keys(n.agents).length:0,r=n.channels?Object.values(n.channels).filter(o=>o&&o.enabled).length:0;return{configExists:!0,agentCount:a,channelCount:r,nodeName:n.node?.name}}catch{return{configExists:!1,agentCount:0,channelCount:0}}}function qe(e,t=process.cwd()){if(!e.nodeName?.trim())throw new Error("Team name is required.");if(!e.agent?.id?.trim())throw new Error("Agent id is required.");if(!/^[a-z0-9][a-z0-9_-]*$/.test(e.agent.id))throw new Error("Agent id must be lowercase (letters, digits, -, _) and start with a letter or digit.");if(!e.agent.name?.trim())throw new Error("Agent name is required.");let n=Fe(e.agent.triggerWords);if(n.length===0)throw new Error("At least one trigger word is required.");if(e.agent.tier!=="claude-code"&&e.agent.tier!=="codex-cli"&&e.agent.tier!=="opencode"&&e.agent.tier!=="sdk"&&e.agent.tier!=="orchestrator")throw new Error("AI engine must be claude-code, codex-cli, opencode, sdk, or orchestrator.");let a=P(t,"agentx.json"),r=P(t,".env"),o=P(t,"agents",e.agent.id),s=be(t);We(o,{recursive:!0});let l=P(o,"CLAUDE.md");if(!M(l)){let f=e.agent.personality?.trim()||`You are ${e.agent.name}, an assistant on the ${e.nodeName} team.`;ve(l,`# ${e.agent.name}
|
|
178
178
|
|
|
179
179
|
${f}
|
|
180
|
-
`)}let i=e.telegram?`TG_${e.agent.id.toUpperCase()}_BOT_TOKEN`:void 0,p;if(s.configExists)p=W(d=>{if(d.node=d.node||{},d.node.name||(d.node.name=e.nodeName),d.node.id||(d.node.id=
|
|
180
|
+
`)}let i=e.telegram?`TG_${e.agent.id.toUpperCase()}_BOT_TOKEN`:void 0,p;if(s.configExists)p=W(d=>{if(d.node=d.node||{},d.node.name||(d.node.name=e.nodeName),d.node.id||(d.node.id=xe(e.nodeName)||"team"),d.node.bind||(d.node.bind="127.0.0.1:18800"),d.node.defaultAgent=d.node.defaultAgent||e.agent.id,d.providers=d.providers||{},d.providers.claude||(d.providers.claude={apiKey:"${ANTHROPIC_API_KEY}"}),d.agents=d.agents||{},d.agents[e.agent.id])throw new Error(`Agent "${e.agent.id}" already exists.`);return d.agents[e.agent.id]=ye(e,o,n),e.telegram&&(d.channels=d.channels||{},d.channels.telegram=d.channels.telegram||{enabled:!0,accounts:{},policy:{dm:"pair",group:"mention-required"}},d.channels.telegram.enabled=!0,d.channels.telegram.accounts=d.channels.telegram.accounts||{},d.channels.telegram.accounts[e.telegram.accountId]=ke(e,i)),{summary:`added agent "${e.agent.id}"`+(e.telegram?" + telegram account":"")}},{configPath:a}).backupPath;else{let f=je(e,o,n,i);me(f,{configPath:a})}Je(r,e,i);let g=[];return(e.anthropicApiKey||!M(P(t,".env")))&&g.push("Double-check the API keys in .env"),e.agent.tier==="claude-code"&&g.push("Run claude --version to confirm Claude Code is installed (needed for the claude-code engine)"),e.agent.tier==="codex-cli"&&g.push("Run codex --version to confirm Codex CLI is installed (needed for the codex-cli engine)"),e.agent.tier==="opencode"&&g.push("Run opencode --version to confirm OpenCode is installed and authenticated"),g.push("Start the daemon: agentx daemon start"),g.push("Open the dashboard: http://127.0.0.1:4202"),{summary:s.configExists?`Added agent "${e.agent.id}" to your team.`:`Initialized your team with first agent "${e.agent.id}".`,nextSteps:g,backupPath:p}}function Fe(e){return(e||"").split(/[,\s]+/).map(t=>t.trim()).filter(Boolean).filter((t,n,a)=>a.indexOf(t)===n)}function xe(e){return(e||"").toLowerCase().replace(/[^a-z0-9-]+/g,"-").replace(/^-+|-+$/g,"")}function je(e,t,n,a){let o={node:{id:xe(e.nodeName)||"team",name:e.nodeName,bind:"127.0.0.1:18800",defaultAgent:e.agent.id},providers:{claude:{apiKey:"${ANTHROPIC_API_KEY}"}},agents:{[e.agent.id]:ye(e,t,n)},channels:{},crons:{},mesh:{enabled:!1,peers:[],discovery:"static",healthCheck:{interval:60,timeout:10}},dashboard:{enabled:!0,port:4202,bind:"127.0.0.1",daemonUrl:"http://localhost:18800"},boards:[]};return e.telegram&&a?o.channels.telegram={enabled:!0,accounts:{[e.telegram.accountId]:ke(e,a)},policy:{dm:"pair",group:"mention-required"}}:o.channels.telegram={enabled:!1,accounts:{},policy:{dm:"pair",group:"mention-required"}},o}function ye(e,t,n){let a={name:e.agent.name,workspace:t,tier:e.agent.tier,mentions:n,maxConcurrent:2,permissionMode:"default"};return e.agent.model&&(a.model=e.agent.model),e.agent.personality?.trim()&&(a.systemPrompt=e.agent.personality.trim().slice(0,400)),a}function ke(e,t){return e.telegram?.botUsername,{token:"${"+t+"}",agentBinding:e.agent.id}}function Je(e,t,n){let a=M(e)?he(e,"utf-8"):"",r=[];if(t.anthropicApiKey&&!a.includes("ANTHROPIC_API_KEY=")&&r.push(`ANTHROPIC_API_KEY=${t.anthropicApiKey}`),t.telegram&&n&&!a.includes(`${n}=`)&&r.push(`${n}=${t.telegram.botToken}`),!M(e)){ve(e,[...["# AgentX environment variables","# (Never commit this file \u2014 it contains secrets.)",""],...r,""].join(`
|
|
181
181
|
`));return}if(r.length>0){let o=a.endsWith(`
|
|
182
182
|
`)?"":`
|
|
183
|
-
`;
|
|
183
|
+
`;Ue(e,o+r.join(`
|
|
184
184
|
`)+`
|
|
185
|
-
`)}}function
|
|
185
|
+
`)}}function Bt(e,t){let n=be(),a=n.nodeName||He().replace(/\.local$/,""),r=ue(n,a);t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(r)}async function Ht(e,t){let n="";await new Promise(r=>{e.on("data",o=>{n+=o}),e.on("end",()=>r())});let a;try{a=JSON.parse(n)}catch{t.writeHead(400,{"Content-Type":"application/json"}),t.end(JSON.stringify({error:"Invalid JSON"}));return}try{let r=qe(a);t.writeHead(200,{"Content-Type":"application/json"}),t.end(JSON.stringify(r))}catch(r){t.writeHead(400,{"Content-Type":"application/json"}),t.end(JSON.stringify({error:r.message||"wizard failed"}))}}async function Lt(e,t){t.setHeader("Content-Type","application/json");let n;try{n=U().node?.bind||"127.0.0.1:18800"}catch(s){t.writeHead(400),t.end(JSON.stringify({ok:!1,error:`Config validation failed: ${s.message}`}));return}let a=`http://${n.replace(/^0\.0\.0\.0/,"127.0.0.1")}`;if(await fe(a)){t.writeHead(200),t.end(JSON.stringify({ok:!0,url:a,alreadyRunning:!0}));return}let r=process.argv[1]||P(Oe(Be(import.meta.url)),"cli.js");try{Le(process.execPath,[r,"daemon","start"],{detached:!0,stdio:"ignore",cwd:process.cwd()}).unref()}catch(s){t.writeHead(500),t.end(JSON.stringify({ok:!1,error:`Failed to spawn daemon: ${s.message}`,manualUrl:a}));return}let o=Date.now()+12e3;for(;Date.now()<o;)if(await new Promise(s=>setTimeout(s,400)),await fe(a)){t.writeHead(200),t.end(JSON.stringify({ok:!0,url:a,alreadyRunning:!1}));return}t.writeHead(504),t.end(JSON.stringify({ok:!1,error:"Daemon spawn succeeded but never bound the port within 12s \u2014 check `agentx daemon status` and the dotfile log for errors.",manualUrl:a}))}async function fe(e){try{let t=await fetch(e,{method:"GET",signal:AbortSignal.timeout(800)});return t.status>0&&t.status<600}catch{return!1}}import{existsSync as Ke,readFileSync as Ye}from"fs";F();function Kt(e){let t=ae(e),n={};if(Ke(t))try{n=te(JSON.parse(Ye(t,"utf-8")))}catch{n={}}let a=q.safeParse(n?.approvals);return a.success?a.data:q.parse(void 0)}function Yt(e){let t=e.indexOf(":");return t<=0||t===e.length-1?null:{channel:e.slice(0,t).trim(),chatId:e.slice(t+1).trim()}}async function Gt(e,t={}){return re(n=>{let a=n.approvals??={};e.defaultExpiryDays!==void 0&&(a.defaultExpiryDays=e.defaultExpiryDays),e.maxExpiryDays!==void 0&&(a.maxExpiryDays=e.maxExpiryDays),e.laterHours!==void 0&&(a.laterHours=e.laterHours),e.notifyAgent!==void 0&&(a.notifyAgent=e.notifyAgent);let r=a.digest??={};e.digestEnabled!==void 0&&(r.enabled=e.digestEnabled),e.digestTime!==void 0&&(r.time=e.digestTime),e.digestTimezone===null?delete r.timezone:e.digestTimezone!==void 0&&(r.timezone=e.digestTimezone),e.destination===null?delete r.destination:e.destination!==void 0&&(r.destination=e.destination);let o=a.popup??={};e.popupEnabled!==void 0&&(o.enabled=e.popupEnabled),e.popupSpeak!==void 0&&(o.speak=e.popupSpeak),e.popupVoice===null?delete o.voice:e.popupVoice!==void 0&&(o.voice=e.popupVoice),e.popupSound!==void 0&&(o.sound=e.popupSound),e.popupTimeoutSeconds!==void 0&&(o.timeoutSeconds=e.popupTimeoutSeconds),e.popupStyle!==void 0&&(o.style=e.popupStyle),e.popupTheme!==void 0&&(o.theme=e.popupTheme);let s=a.checkin??={};e.checkinEnabled!==void 0&&(s.enabled=e.checkinEnabled),e.checkinTimes!==void 0&&(s.times=e.checkinTimes),e.checkinDailyAt!==void 0&&(s.dailyAt=e.checkinDailyAt),e.checkinLists!==void 0&&(s.lists=e.checkinLists),e.checkinAgent===null?delete s.agent:e.checkinAgent!==void 0&&(s.agent=e.checkinAgent);let l=a.defaultExpiryDays??3,i=a.maxExpiryDays??30;if(l>i)throw new Error(`defaultExpiryDays (${l}) can't be more than maxExpiryDays (${i})`)},{configPath:t.configPath,reload:t.reload})}import{createServer as Ge}from"http";var O=class{peers;cache=new Map;ttl=3e4;constructor(t){this.peers=t.map(n=>({url:n.replace(/\/$/,"")}))}async getRemoteAgents(){let t=[];return await Promise.all(this.peers.map(async n=>{try{let a=await this.fetchJson(`${n.url}/wiki/agents`);n.nodeId=a.nodeId;for(let r of a.agents||[])(r.totalEntries>0||r.totalArticles>0)&&t.push({...r,nodeId:a.nodeId,peerUrl:n.url})}catch{}})),t}async getRemoteArticles(t,n){try{return(await this.fetchJson(`${t}/wiki/articles?agent=${encodeURIComponent(n)}`)).articles||[]}catch{return[]}}async getRemoteArticle(t,n,a){try{let r=await this.fetchJson(`${t}/wiki/article?agent=${encodeURIComponent(n)}&path=${encodeURIComponent(a)}`);return{meta:{title:r.title,tags:r.tags||[],owner:r.owner,access:"public",created:r.created,lastUpdated:r.lastUpdated,sources:r.sources||[]},content:r.content,path:r.path}}catch{return null}}async fetchJson(t){let n=this.cache.get(t);if(n&&Date.now()-n.ts<this.ttl)return n.data;let a=await fetch(t,{signal:AbortSignal.timeout(5e3)});if(!a.ok)throw new Error(`HTTP ${a.status}`);let r=await a.json();return this.cache.set(t,{data:r,ts:Date.now()}),r}};function c(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function Xe(e){return e.replace(/<!--\s*tags?:[^>]*-->\s*\n?/gi,"")}function we(e,t){return`<a href="${t?`/agent/${encodeURIComponent(t)}/tag/${encodeURIComponent(e)}`:`/tag/${encodeURIComponent(e)}`}" class="tag">${c(e)}</a>`}function z(e,t){return(e||[]).map(n=>we(n,t)).join(" ")}function Ve(e,t){if(!e)return;let n=t.get(e);if(n)return n;let a=new Set(t.values());if(a.has(e))return e;let r=e.endsWith(".md")?e:`${e}.md`;if(a.has(r))return r;let o=e.toLowerCase();for(let[s,l]of t)if(s.toLowerCase()===o)return l}function B(e,t,n=""){return de(Xe(e),{wikilink:(a,r)=>{let o=Ve(a,t);return o?`<a href="${n}/article/${encodeURIComponent(o)}" class="wikilink">${r}</a>`:`<a href="${n}/search?q=${encodeURIComponent(a)}" class="wikilink broken" title="Not found \u2014 click to search">${r}</a>`}})}var Qe=`<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
186
186
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
187
|
-
<link href="https://fonts.googleapis.com/css2?family=Newsreader:ital,opsz,wght@0,6..72,300..600;1,6..72,300..600&family=Inter+Tight:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">`,
|
|
187
|
+
<link href="https://fonts.googleapis.com/css2?family=Newsreader:ital,opsz,wght@0,6..72,300..600;1,6..72,300..600&family=Inter+Tight:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">`,Ze=`
|
|
188
188
|
:root {
|
|
189
189
|
--bg: #FAF8F3;
|
|
190
190
|
--bg-raised: #FFFFFF;
|
|
@@ -657,8 +657,8 @@ tr:hover td { background: var(--bg-hover); }
|
|
|
657
657
|
<meta charset="utf-8">
|
|
658
658
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
659
659
|
<title>${c(e)} \u2014 AgentX Wiki</title>
|
|
660
|
-
${
|
|
661
|
-
<style>${
|
|
660
|
+
${Qe}
|
|
661
|
+
<style>${Ze}</style>
|
|
662
662
|
<script>(function(){try{var t=localStorage.getItem('wiki-theme');if(t)document.documentElement.setAttribute('data-theme',t)}catch(e){}})();</script>
|
|
663
663
|
</head>
|
|
664
664
|
<body>
|
|
@@ -703,7 +703,7 @@ tr:hover td { background: var(--bg-hover); }
|
|
|
703
703
|
})();
|
|
704
704
|
</script>
|
|
705
705
|
</body>
|
|
706
|
-
</html>`}function
|
|
706
|
+
</html>`}function X(e){let t=new Map;for(let n of e){let a=n.path.includes("/")?n.path.split("/").slice(0,-1).join("/"):"/",r=t.get(a)||[];r.push(n),t.set(a,r)}return new Map([...t].sort((n,a)=>n[0].localeCompare(a[0])))}function V(e){return e==="/"?"Root":e.split("/").pop().replace(/-/g," ")}function C(e,t){let n='<div class="nav-section">';n+=`<a class="nav-item${t?"":" active"}" href="/">Home</a>`,n+='<a class="nav-item" href="/entries">All entries</a>',n+="</div>";for(let a of e){let r=`/agent/${encodeURIComponent(a.agentId)}`;n+='<div class="nav-section">',n+=`<a class="nav-agent-header" href="${r}">`,n+=`<span class="name">${c(a.agentId)}</span>`,n+=`<span class="badge">${a.totalArticles}</span>`,n+="</a>",n+='<div class="nav-agent-children">';let o=X(a.articles);for(let[s,l]of o){n+=`<div class="nav-agent-type-label">${V(s)}</div>`;for(let i of l){let g=`${a.agentId}/${i.path}`===t;n+=`<a class="nav-item${g?" active":""}" href="${r}/article/${encodeURIComponent(i.path)}">${c(i.title)}</a>`}}n+="</div>",n+="</div>"}return n}function et(e,t,n){let a=t||e.summary(),o=e.getSharedStore().listEntries().length,s=a.reduce((g,f)=>g+f.totalArticles,0),l=a.reduce((g,f)=>g+f.unabsorbed,0),i=new Set((n||[]).map(g=>g.agentId)),p=`<div class="page-head">
|
|
707
707
|
<div>
|
|
708
708
|
<h1>AgentX Wiki</h1>
|
|
709
709
|
<p class="page-sub">Agent-owned institutional knowledge, typed and cross-referenced. Everything here compiles from raw conversation entries through the nightly absorb pass.</p>
|
|
@@ -712,33 +712,33 @@ tr:hover td { background: var(--bg-hover); }
|
|
|
712
712
|
<span><strong>${g.totalArticles}</strong> articles</span>
|
|
713
713
|
<span><strong>${g.totalEntries}</strong> entries</span>
|
|
714
714
|
${f}
|
|
715
|
-
</div>`,g.articles.length>0){p+='<div class="article-list">';for(let u of g.articles.slice(0,6)){let A=z((u.tags||[]).slice(0,2),g.agentId);p+=`<div class="article-row">${A} <a class="article-title" href="/agent/${encodeURIComponent(g.agentId)}/article/${encodeURIComponent(u.path)}">${c(u.title)}</a></div>`}g.articles.length>6&&(p+=`<div class="article-row"><a class="article-title" style="color:var(--muted)" href="/agent/${encodeURIComponent(g.agentId)}">+ ${g.articles.length-6} more \u2192</a></div>`),p+="</div>"}p+="</div>"}return p+="</div>",$("Hub",C(a),p)}function
|
|
715
|
+
</div>`,g.articles.length>0){p+='<div class="article-list">';for(let u of g.articles.slice(0,6)){let A=z((u.tags||[]).slice(0,2),g.agentId);p+=`<div class="article-row">${A} <a class="article-title" href="/agent/${encodeURIComponent(g.agentId)}/article/${encodeURIComponent(u.path)}">${c(u.title)}</a></div>`}g.articles.length>6&&(p+=`<div class="article-row"><a class="article-title" style="color:var(--muted)" href="/agent/${encodeURIComponent(g.agentId)}">+ ${g.articles.length-6} more \u2192</a></div>`),p+="</div>"}p+="</div>"}return p+="</div>",$("Hub",C(a),p)}function tt(e,t,n){let a=n||e.summary(),r=a.find(d=>d.agentId===t);if(!r)return $("Not Found",C(a),"<h1>Agent not found</h1>");let o=r.peerUrl!==void 0,s=e.getAgentEntries(t),l=r.articles||[],i=`<nav class="breadcrumb"><a href="/">Hub</a> <span class="sep">/</span> <span class="current">${c(t)}</span></nav>`;if(i+=`<div class="page-head"><div><h1>${c(t)}</h1>`,o&&(i+=`<p class="page-sub"><span class="tag" style="color:var(--cool);background:var(--cool-soft)">remote @ ${c(r.nodeId)}</span></p>`),i+="</div></div>",i+='<div class="stat-strip">',i+=`<div class="stat-cell"><div class="label">Articles</div><div class="number">${r.totalArticles}</div></div>`,i+=`<div class="stat-cell"><div class="label">Entries</div><div class="number">${r.totalEntries}</div></div>`,i+=`<div class="stat-cell"><div class="label">Unabsorbed</div><div class="number">${r.unabsorbed}</div></div>`,i+="</div>",l.length>0){i+='<div class="section-head"><h2>Articles</h2><span class="mono" style="font-size:12px;color:var(--muted)">'+l.length+" total</span></div>";let d=X(l);for(let[h,u]of d){i+=`<h3 class="display" style="font-size:17px;color:var(--muted);font-weight:500;margin:20px 0 8px">${V(h)}</h3>`,i+='<div class="agent-card" style="padding:4px 14px"><div class="article-list">';for(let A of u)i+=`<div class="article-row">${z((A.tags||[]).slice(0,3),t)} <a class="article-title" href="/agent/${encodeURIComponent(t)}/article/${encodeURIComponent(A.path)}">${c(A.title)}</a></div>`;i+="</div></div>"}}let p=s.slice(-5).reverse();if(p.length>0){i+='<div class="section-head"><h2>Recent entries</h2><a class="btn ghost" href="/entries">See all \u2192</a></div>';for(let d of p)i+=`<div class="entry-card">
|
|
716
716
|
<div class="meta-line">${d.date} \xB7 via ${c(d.source)} \xB7 <code>${c(d.id)}</code></div>
|
|
717
717
|
<p>${c(d.content.slice(0,300))}${d.content.length>300?"\u2026":""}</p>
|
|
718
718
|
</div>`}let f=e.getAgentWiki(t).lint();if(f.length>0){i+=`<div class="section-head"><h2>Health issues</h2><span class="mono" style="font-size:12px;color:var(--warn)">${f.length}</span></div>`,i+='<div class="health-list">';for(let d of f)i+=`<div class="health-row">
|
|
719
719
|
<span class="kind">${c(d.type)}</span>
|
|
720
720
|
<span class="article">${c(d.article)}</span>
|
|
721
721
|
<span class="msg">${c(d.message)}</span>
|
|
722
|
-
</div>`;i+="</div>"}return $(t,C(a,t),i)}function
|
|
722
|
+
</div>`;i+="</div>"}return $(t,C(a,t),i)}function nt(e,t,n,a){let r=e.getAgentWiki(t),o=r.readArticle(n);if(!o)return null;let s=a||e.summary(),l=r.rebuildIndex(),i=new Map;for(let h of l.articles)i.set(h.title,h.path);let p=`/agent/${encodeURIComponent(t)}`,f=r.buildBacklinks()[o.meta.title]||[],d=`<nav class="breadcrumb"><a href="/">Hub</a> <span class="sep">/</span> <a href="${p}">${c(t)}</a> <span class="sep">/</span> <span class="current">${c(o.meta.title)}</span></nav>`;if(d+=`<article class="prose"><h1>${c(o.meta.title)}</h1>`,d+='<dl class="meta">',o.meta.type&&(d+=`<dt>Type</dt><dd>${we(o.meta.type,t)}</dd>`),o.meta.tags?.length&&(d+=`<dt>Tags</dt><dd>${z(o.meta.tags,t)}</dd>`),o.meta.owner&&(d+=`<dt>Owner</dt><dd>${c(o.meta.owner)}</dd>`),d+=`<dt>Created</dt><dd>${c(o.meta.created||"\u2014")}</dd>`,d+=`<dt>Updated</dt><dd>${c(o.meta.lastUpdated||"\u2014")}</dd>`,o.meta.sources?.length&&(d+=`<dt>Sources</dt><dd>${o.meta.sources.length} entries</dd>`),d+="</dl>",d+=B(o.content,i,p),f.length>0){d+='<div class="backlinks"><h4>Pages that link here</h4><ul>';for(let h of f){let u=r.readArticle(h);d+=`<li><a href="${p}/article/${encodeURIComponent(h)}">${c(u?.meta.title||h)}</a></li>`}d+="</ul></div>"}return d+="</article>",$(o.meta.title,C(s,`${t}/${n}`),d)}function at(e,t){let n=t||e.summary(),r=e.getSharedStore().listEntries(),o='<nav class="breadcrumb"><a href="/">Hub</a> <span class="sep">/</span> <span class="current">Entries</span></nav>';o+='<div class="page-head"><div><h1>All raw entries</h1><p class="page-sub">Every conversation line that the ingest pipeline captured. Absorb compiles these into typed articles nightly.</p></div></div>';let s=new Map;for(let l of r){let i=s.get(l.date)||[];i.push(l),s.set(l.date,i)}for(let[l,i]of[...s].reverse()){o+=`<div class="section-head"><h2>${l}</h2><span class="mono" style="font-size:12px;color:var(--muted)">${i.length} entries</span></div>`;for(let p of i)o+=`<div class="entry-card">
|
|
723
723
|
<div class="meta-line">
|
|
724
724
|
<a href="/agent/${encodeURIComponent(p.agentId)}">${c(p.agentId)}</a>
|
|
725
725
|
\xB7 via ${c(p.source)} \xB7 <code>${c(p.id)}</code>
|
|
726
726
|
</div>
|
|
727
727
|
<p>${c(p.content.slice(0,400))}${p.content.length>400?"\u2026":""}</p>
|
|
728
|
-
</div>`}return $("All Entries",C(n),o)}function
|
|
728
|
+
</div>`}return $("All Entries",C(n),o)}function rt(e,t,n){let a=n||e.summary(),r='<nav class="breadcrumb"><a href="/">Hub</a> <span class="sep">/</span> <span class="current">Search</span></nav>';r+=`<div class="page-head"><div><h1>\u201C${c(t)}\u201D</h1><p class="page-sub">Full-text search across every agent's wiki.</p></div></div>`;let o=0,s=[];for(let l of a){let p=e.getAgentWiki(l.agentId).findRelevant(t,void 0,10);if(p.length>0){s.push(`<div class="section-head"><h2>${c(l.agentId)}</h2><span class="mono" style="font-size:12px;color:var(--muted)">${p.length} match${p.length===1?"":"es"}</span></div>`);for(let g of p){let f=`/agent/${encodeURIComponent(l.agentId)}`;s.push(`<div class="entry-card">
|
|
729
729
|
<div class="meta-line">${z((g.meta.tags||[]).slice(0,3),l.agentId)}</div>
|
|
730
730
|
<h3><a href="${f}/article/${encodeURIComponent(g.path)}">${c(g.meta.title)}</a></h3>
|
|
731
731
|
<p>${c(g.content.slice(0,240))}\u2026</p>
|
|
732
|
-
</div>`)}o+=p.length}}return r+=s.join(""),o===0&&(r+='<p style="color:var(--muted);margin-top:24px">No matching articles found.</p>'),$(`Search: ${t}`,C(a),r,t)}function
|
|
732
|
+
</div>`)}o+=p.length}}return r+=s.join(""),o===0&&(r+='<p style="color:var(--muted);margin-top:24px">No matching articles found.</p>'),$(`Search: ${t}`,C(a),r,t)}function ot(e,t,n){let a=n||e.summary(),r='<nav class="breadcrumb"><a href="/">Hub</a> <span class="sep">/</span> <span class="current">Tag</span></nav>';r+=`<div class="page-head"><div><h1>${c(t)}</h1><p class="page-sub">All articles tagged <span class="tag">${c(t)}</span>, across every agent.</p></div></div>`;let o=0;for(let s of a){let l;try{l=e.getAgentWiki(s.agentId)}catch{continue}let i=l.findByTags([t],void 0,100);if(i.length!==0){r+=`<div class="section-head"><h2>${c(s.agentId)}</h2><span class="mono" style="font-size:12px;color:var(--muted)">${i.length}</span></div>`;for(let p of i){let g=`/agent/${encodeURIComponent(s.agentId)}`;r+=`<div class="entry-card">
|
|
733
733
|
<div class="meta-line">${z((p.meta.tags||[]).slice(0,6),s.agentId)}</div>
|
|
734
734
|
<h3><a href="${g}/article/${encodeURIComponent(p.path)}">${c(p.meta.title)}</a></h3>
|
|
735
|
-
</div>`}o+=i.length}}return o===0&&(r+=`<p style="color:var(--muted);margin-top:24px">No articles tagged <code>${c(t)}</code>.</p>`),$(`Tag: ${t}`,C(a),r)}function
|
|
735
|
+
</div>`}o+=i.length}}return o===0&&(r+=`<p style="color:var(--muted);margin-top:24px">No articles tagged <code>${c(t)}</code>.</p>`),$(`Tag: ${t}`,C(a),r)}function it(e,t,n,a){let r=a||e.summary(),o;try{o=e.getAgentWiki(t)}catch{return $(`Tag: ${n}`,C(r),`<h1>Agent not found: ${c(t)}</h1>`)}let s=o.findByTags([n],void 0,100),l=`/agent/${encodeURIComponent(t)}`,i=`<nav class="breadcrumb"><a href="/">Hub</a> <span class="sep">/</span> <a href="${l}">${c(t)}</a> <span class="sep">/</span> <span class="current">${c(n)}</span></nav>`;i+=`<div class="page-head"><div><h1>${c(n)}</h1><p class="page-sub">${s.length} article${s.length===1?"":"s"} tagged <code>${c(n)}</code> in <b>${c(t)}</b>.</p></div></div>`;for(let p of s)i+=`<div class="entry-card">
|
|
736
736
|
<div class="meta-line">${z((p.meta.tags||[]).slice(0,6),t)}</div>
|
|
737
737
|
<h3><a href="${l}/article/${encodeURIComponent(p.path)}">${c(p.meta.title)}</a></h3>
|
|
738
|
-
</div>`;return $(`${t} \xB7 ${n}`,C(r),i)}function _(e,t,n){let a=e.rebuildIndex(),r=
|
|
738
|
+
</div>`;return $(`${t} \xB7 ${n}`,C(r),i)}function _(e,t,n){let a=e.rebuildIndex(),r=X(a.articles.map(s=>({title:s.title,path:s.path,tags:s.tags}))),o='<div class="nav-section">';o+=`<div class="nav-section-title">${c(t)}</div>`,o+=`<a class="nav-item${n?"":" active"}" href="/">Home</a>`,o+='<a class="nav-item" href="/lint">Health check</a>',o+="</div>";for(let[s,l]of r){o+='<div class="nav-section">',o+=`<div class="nav-section-title">${V(s)}</div>`;for(let i of l){let p=i.path===n;o+=`<a class="nav-item${p?" active":""}" href="/article/${encodeURIComponent(i.path)}">${c(i.title)}</a>`}o+="</div>"}return o}function st(e){let{wikiDir:t,agentFilter:n,peerUrls:a=[],mode:r="graph",pathPrefix:o=""}=e,s=o.replace(/\/+$/,""),l=new ne(t,void 0,r),i=a.length>0?new O(a):null;return async(p,g)=>{let f=new URL(p.url||"/","http://localhost"),d=decodeURIComponent(f.pathname),h=s&&d.startsWith(s)?d.slice(s.length)||"/":d,u=null,A=200;try{if(h.startsWith("/remote/")&&i){let x=h.slice(8).split("/article/");if(x.length===2){let[y,v]=x,m=y.indexOf("/"),k=decodeURIComponent(y.slice(0,m)),b=y.slice(m+1),w=await i.getRemoteArticle(k,b,v);if(w){let R=await i.getRemoteAgents(),N=[...l.summary(),...R.map(I=>({...I,agentId:`${I.agentId} @${I.nodeId}`}))],S=`<div class="breadcrumb"><a href="/">Hub</a> / <span class="tag">remote</span> ${c(b)} @ ${c(k)}</div>`;S+=`<h1>${c(w.meta.title)}</h1>`,S+='<dl class="meta">',S+=`<dt>Tags</dt><dd>${(w.meta.tags||[]).map(I=>`<span class="tag">${I}</span>`).join(" ")}</dd>`,S+=`<dt>Owner</dt><dd>${c(w.meta.owner)}</dd>`,S+=`<dt>Source</dt><dd><span class="tag">remote</span> ${c(k)}</dd>`,S+=`<dt>Updated</dt><dd>${w.meta.lastUpdated}</dd>`,S+="</dl>";let T=new Map;S+=B(w.content,T),u=$(w.meta.title,C(N),S)}}}if(!u&&n){let x=l.getAgentWiki(n);if(h==="/"||h===""){let y=x.rebuildIndex(),v=l.getAgentEntries(n),m=`<h1>${c(n)}</h1>`;if(m+='<div class="stats">',m+=`<div class="stat-card"><div class="number">${y.articles.length}</div><div class="label">Articles</div></div>`,m+=`<div class="stat-card"><div class="number">${v.length}</div><div class="label">Entries</div></div>`,m+="</div>",y.articles.length>0){m+="<h2>Articles</h2><table><tr><th>Title</th><th>Type</th><th>Updated</th></tr>";for(let k of y.articles)m+=`<tr><td><a href="/article/${encodeURIComponent(k.path)}">${c(k.title)}</a></td><td><span class="tag">${(k.tags||[]).slice(0,3).join(", ")}</span></td><td>${k.lastUpdated||""}</td></tr>`;m+="</table>"}u=$(n,_(x,n),m)}else if(h.startsWith("/article/")){let y=h.slice(9),v=x.readArticle(y);if(v){let m=x.rebuildIndex(),k=new Map;for(let w of m.articles)k.set(w.title,w.path);let b=`<h1>${c(v.meta.title)}</h1>`;b+='<dl class="meta">',b+=`<dt>Tags</dt><dd>${(v.meta.tags||[]).map(w=>`<span class="tag">${w}</span>`).join(" ")}</dd>`,b+=`<dt>Updated</dt><dd>${v.meta.lastUpdated}</dd>`,v.meta.sources?.length&&(b+=`<dt>Sources</dt><dd>${v.meta.sources.length} entries</dd>`),b+="</dl>",b+=B(v.content,k),u=$(v.meta.title,_(x,n,y),b)}}else if(h==="/lint"){let y=x.lint(),v="<h1>Health Check</h1>";if(y.length===0)v+='<p style="color:green;">No issues.</p>';else{v+="<table><tr><th>Type</th><th>Article</th><th>Issue</th></tr>";for(let m of y)v+=`<tr><td><span class="tag">${m.type}</span></td><td>${c(m.article)}</td><td>${c(m.message)}</td></tr>`;v+="</table>"}u=$("Health Check",_(x,n),v)}else if(h==="/search"){let y=f.searchParams.get("q")||"",v=await x.findRelevantReranked(y,void 0,20),m=`<h1>Search: "${c(y)}"</h1>`;for(let k of v)m+=`<div class="entry-card"><h3><a href="/article/${encodeURIComponent(k.path)}">${c(k.meta.title)}</a></h3><p>${c(k.content.slice(0,200))}...</p></div>`;v.length===0&&(m+="<p>No results.</p>"),u=$(`Search: ${y}`,_(x,n),m)}else if(h.startsWith("/tag/")){let y=decodeURIComponent(h.slice(5)),v=x.findByTags([y],void 0,100),m=`<h1>Tag: <a class="tag" href="#">${c(y)}</a></h1>`;m+=`<p>${v.length} article${v.length===1?"":"s"} tagged <code>${c(y)}</code></p>`;for(let k of v)m+=`<div class="entry-card"><h3><a href="/article/${encodeURIComponent(k.path)}">${c(k.meta.title)}</a></h3><div class="meta-line">${z((k.meta.tags||[]).slice(0,6))}</div></div>`;v.length===0&&(m+="<p>No articles with this tag.</p>"),u=$(`Tag: ${y}`,_(x,n),m)}}else{let x=i?await i.getRemoteAgents():[],y=l.summary(),v=new Map(y.map(b=>[b.agentId,b])),m=[],k=new Set;for(let b of y){let w=x.find(R=>R.agentId===b.agentId);w&&w.totalArticles>b.totalArticles?m.push({...w,totalEntries:Math.max(b.totalEntries,w.totalEntries),unabsorbed:Math.max(b.unabsorbed,w.unabsorbed)}):m.push(b),k.add(b.agentId)}for(let b of x)k.has(b.agentId)||(m.push(b),k.add(b.agentId));if(h==="/"||h==="")u=et(l,m,x);else if(h==="/entries")u=at(l,m);else if(h==="/search")u=rt(l,f.searchParams.get("q")||"",m);else if(h.startsWith("/tag/"))u=ot(l,decodeURIComponent(h.slice(5)),m);else if(h.match(/^\/agent\/[^/]+\/tag\/.+/)){let b=h.match(/^\/agent\/([^/]+)\/tag\/(.+)$/);u=it(l,decodeURIComponent(b[1]),decodeURIComponent(b[2]),m)}else if(h.startsWith("/agent/")){let b=h.slice(7),w=b.indexOf("/article/");if(w===-1)u=tt(l,b,m);else{let R=b.slice(0,w),N=b.slice(w+9);if(u=nt(l,R,N,m),!u&&i){let S=x.find(T=>T.agentId===R);if(S){let T=await i.getRemoteArticle(S.peerUrl,R,N);if(T){let I=`<div class="breadcrumb"><a href="/">Hub</a> / <span class="tag">remote @ ${c(S.nodeId)}</span> / ${c(R)}</div>`;I+=`<h1>${c(T.meta.title)}</h1>`,I+='<dl class="meta">',I+=`<dt>Tags</dt><dd>${(T.meta.tags||[]).map(Re=>`<span class="tag">${Re}</span>`).join(" ")}</dd>`,I+=`<dt>Source</dt><dd><span class="tag">remote</span> ${c(S.nodeId)}</dd>`,I+=`<dt>Updated</dt><dd>${T.meta.lastUpdated}</dd>`,I+="</dl>",I+=B(T.content,new Map),u=$(T.meta.title,C(m),I)}}}}}}if(!u){A=404;let x=n?_(l.getAgentWiki(n),n):C(l.summary());u=$("Not Found",x,"<h1>Page not found</h1>")}}catch(x){A=500,u=$("Error","",`<h1>Error</h1><pre>${c(x.message)}</pre>`)}g.writeHead(A,{"Content-Type":"text/html; charset=utf-8"}),g.end(s?dt(u,s):u)}}function dt(e,t){e=e.replace(/(\s(?:href|action)=")\/(?!\/)/g,`$1${t}/`),e=e.replace(new RegExp(`(${t})${t}/`,"g"),`${t}/`);let n=`<a href="/admin" style="position:fixed;top:10px;right:14px;z-index:9999;padding:5px 11px;background:rgba(0,0,0,0.55);color:#fff;font:12px/1.2 'IBM Plex Sans',system-ui,sans-serif;text-decoration:none;border-radius:6px;border:1px solid rgba(255,255,255,0.18);backdrop-filter:blur(6px)">\u2190 Dashboard</a>`;return e=e.replace(/<body([^>]*)>/,`<body$1>${n}`),e}function nn(e,t=4200,n,a=[],r="graph"){let o=st({wikiDir:e,agentFilter:n,peerUrls:a,mode:r});Ge((l,i)=>{o(l,i)}).listen(t)}Pe();function on(e,t,n=20){return e.prepare(`SELECT task_id, agent_id, channel, chat_id, status, started_at, message_preview
|
|
739
739
|
FROM task_traces
|
|
740
740
|
WHERE person = ? AND (channel IS NULL OR channel != 'a2a')
|
|
741
|
-
ORDER BY started_at DESC LIMIT ?`).all(t,Math.max(1,Math.min(n,500))).map(r=>({taskId:r.task_id,agentId:r.agent_id,channel:r.channel,chatId:r.chat_id,status:r.status,startedAt:r.started_at,messagePreview:r.message_preview}))}function
|
|
742
|
-
WHERE person = ? AND state IN (${
|
|
743
|
-
|
|
744
|
-
//# sourceMappingURL=chunk-
|
|
741
|
+
ORDER BY started_at DESC LIMIT ?`).all(t,Math.max(1,Math.min(n,500))).map(r=>({taskId:r.task_id,agentId:r.agent_id,channel:r.channel,chatId:r.chat_id,status:r.status,startedAt:r.started_at,messagePreview:r.message_preview}))}function lt(e){return e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'requests'").get()?e.prepare("PRAGMA table_info(requests)").all().some(a=>a.name==="person"):!1}function $e(e,t,n,a,...r){return lt(e)?e.prepare(`SELECT id, state, channel, agent_id, text, created_at FROM requests
|
|
742
|
+
WHERE person = ? AND state IN (${n.map(()=>"?").join(",")})
|
|
743
|
+
${a}`).all(t,...n,...r).map(s=>({id:s.id,state:s.state,channel:s.channel,agentId:s.agent_id,text:s.text,createdAt:s.created_at})):[]}function sn(e,t){return $e(e,t,L,"ORDER BY created_at")}function dn(e,t,n=50){return $e(e,t,[...L,...Z],"ORDER BY created_at DESC, rowid DESC LIMIT ?",Math.max(1,Math.min(n,500)))}ze();var Q="member:",ct=90,pt="members",gt="tailscale-user-login",mt=400,ut=60*60*1e3;function ft(e){let t=e.scopes.find(n=>n.startsWith(Q));return t?t.slice(Q.length):null}function Ae(e,t){if(!e)return null;let n=t.verify(e),a=n?ft(n):null;return n&&a?{rec:n,personId:a}:null}function un(e,t){let n=e.people().find(l=>l.id===t);if(!n)return{ok:!1,error:`No person "${t}". Add them first: agentx people add ${t} --name "\u2026"`};let{token:a,record:r}=e.tokens.create({name:`${n.name} (machine not paired yet)`,scopes:[`${Q}${n.id}`],expiresInDays:ct}),{code:o,expiresAt:s}=e.codes.create({token:a,tokenId:r.id,name:n.id});return e.members.log({person:n.id,device:r.id,event:"invited"}),{ok:!0,code:o,expiresAt:s,tokenId:r.id,person:n}}var ht="The private network says someone else is connecting from this machine. Ask the owner for a new code.",vt="Too many machines are waiting for the owner's answer. Try again later.",Se=(e,t)=>{let n=e.headers[t];return(Array.isArray(n)?n[0]:n||"").trim()};function Ie(e){let t=e.socket?.remoteAddress||"";return t==="127.0.0.1"||t==="::1"||t==="::ffff:127.0.0.1"}function bt(e){if(!Ie(e))return null;let t=Se(e,gt).toLowerCase();return t?t.slice(0,80):null}function xt(e){let t=e.socket?.remoteAddress||"unknown";if(!Ie(e))return t;let n=Se(e,"x-forwarded-for").split(",").pop().trim();return/^[0-9a-fA-F:.]{2,45}$/.test(n)?n:t}function yt(e){return typeof e=="string"?e.replace(/[^\p{L}\p{N} ._'()-]/gu," ").replace(/\s+/g," ").trim().slice(0,60):""}function kt(e){return e.identities.map(ee).filter(t=>!!t&&t.channel==="tailscale").map(t=>t.value)}async function fn(e,t){let n=Date.now(),a=t.now??Date.now,r=t.log??(m=>console.log(m)),o=xt(e),s=t.limiter.retryAfter(o);if(s>0)return r(`[member] pair-code refused from ${o}: locked out for ${s}s more`),{status:429,body:{error:"too many attempts",retryAfter:s},retryAfter:s};let l=null,i="";try{let m=await ie(e,2048);l=m.code,i=yt(m.machine)}catch{}let p=t.codes.redeem(l),g=p?Ae(p.token,t.tokens):null;if(await $t(n,t.minMs??mt),!p||!g)return t.limiter.fail(o),r(`[member] pair-code failed from ${o}`),{status:401,body:{error:J}};t.limiter.succeed(o);let{rec:f,personId:d}=g,h=t.people().find(m=>m.id===d);if(!h)return t.tokens.revoke(f.id),t.members.log({person:d,device:f.id,event:"refused",address:o,detail:"person no longer listed"}),r(`[member] pair-code for ${d} refused from ${o}: person no longer listed`),{status:403,body:{error:J}};let u=bt(e),A=kt(h);if(A.length&&(!u||!A.includes(u)))return t.tokens.revoke(f.id),t.members.log({person:d,device:f.id,event:"refused",address:o,detail:`network login ${u??"missing"}; expected ${A.join(" or ")}`}),r(`[member] ${d}: pairing from ${o} refused: the network says "${u??"nobody"}", expected ${A.join(" or ")}`),{status:403,body:{error:ht}};let x=i||"Unnamed machine",y=h.name.slice(0,40),v=oe(t.root,{title:`New machine for ${y}`,ask:`From ${o}, ${u?`network login ${u}`:"no network login reported"}. Machine name, as typed there: "${x}". Let it see ${y}'s own work?`,recommend:`Yes if ${y} told you they just paired this machine. No if you did not expect it.`,if_silent:"discard",raised_by:pt},{now:a()});return v.ok?(t.members.add({tokenId:f.id,personId:d,name:x,state:"pending",cardId:v.card.id,address:o,...u?{network:u}:{},createdAt:new Date(a()).toISOString()}),t.members.log({person:d,device:f.id,event:"paired",address:o,detail:x}),r(`[member] ${d} paired "${x}" from ${o}; waiting for the owner (card ${v.card.id})`),{status:200,body:{person:d,name:x,state:"pending"},token:p.token}):(t.tokens.revoke(f.id),t.members.log({person:d,device:f.id,event:"refused",address:o,detail:v.error}),r(`[member] ${d}: pairing from ${o} refused: ${v.error}`),{status:503,body:{error:vt}})}var H="this machine is not paired",wt="waiting for the owner to approve this machine";function Ee(e){return e?e.status==="decided"?e.verdict??null:e.status==="expired"?"no":null:null}function hn(e,t){return t.state==="pending"&&t.cardId?Ee(j(e,t.cardId)):null}function vn(e,t,n){let a=t.now??Date.now,r=t.log??(g=>console.log(g)),o=Ae(e,t.tokens);if(!o)return{ok:!1,status:401,error:H};let{rec:s,personId:l}=o,i=t.members.byToken(s.id);if(!i||i.state==="removed"||i.personId!==l)return{ok:!1,status:401,error:H};if(t.people&&!t.people().some(g=>g.id===l))return Ce(t,s.id,"person no longer listed"),r(`[member] ${l}: "${i.name}" ended: person no longer listed`),{ok:!1,status:401,error:H};if(i.state==="pending"){let g=i.cardId?j(t.root,i.cardId):null,f=Ee(g);if(f==="yes")i=t.members.update(s.id,{state:"active",approvedAt:new Date(a()).toISOString()})??i,t.members.log({person:l,device:s.id,event:"approved",detail:g?.decided_by}),r(`[member] ${l}: "${i.name}" approved`);else if(f==="no"){let d=g?.status==="expired"?"the owner did not answer in time":"the owner said no";return t.tokens.revoke(s.id),t.members.update(s.id,{state:"removed",removedAt:new Date(a()).toISOString(),removedReason:d}),t.members.log({person:l,device:s.id,event:"refused",detail:d}),r(`[member] ${l}: "${i.name}" refused: ${d}`),{ok:!1,status:401,error:H}}else return{ok:!1,status:403,error:wt,waiting:!0}}let p=i.lastSeenAt?Date.parse(i.lastSeenAt):0;return n&&(a()-p>=ut||i.lastAddress!==n)&&(i=t.members.update(s.id,{lastSeenAt:new Date(a()).toISOString(),lastAddress:n})??i,t.members.log({person:l,device:s.id,event:"signed-in",address:n})),{ok:!0,device:i,personId:l,rec:s}}function Ce(e,t,n="removed by the owner"){let a=e.members.byToken(t);if(!a)return null;e.tokens.revoke(t);let r=e.members.update(t,{state:"removed",removedAt:new Date((e.now??Date.now)()).toISOString(),removedReason:n});return e.members.log({person:a.personId,device:t,event:"removed",detail:n}),r}function bn(e,t){return e.members.devices(t).filter(n=>n.state!=="removed").map(n=>Ce(e,n.tokenId,"person removed by the owner")).filter(n=>!!n)}async function $t(e,t){let n=e+t-Date.now();n>0&&await new Promise(a=>setTimeout(a,n))}var Te=["gitlab","github"];function At(e,t,n){let a=String(t||"").trim().toLowerCase();if(!Te.includes(a))throw new Error(`Request status works on ${Te.join(" and ")}, not on "${t}".`);e.requestStatus=e.requestStatus&&typeof e.requestStatus=="object"?e.requestStatus:{};let r=Array.isArray(e.requestStatus.channels)?e.requestStatus.channels.map(o=>String(o).toLowerCase()):[];return e.requestStatus.channels=n?[...new Set([...r,a])]:r.filter(o=>o!==a),`request status on ${a} is ${n?"on":"off"}`}function kn(e){return Array.isArray(e?.requestStatus?.channels)?e.requestStatus.channels.map(t=>String(t).toLowerCase()):[]}function wn(e){let{summary:t}=W(n=>At(n,e?.channel,!!e?.enabled));return{summary:t}}var St="https://ntfy.sh";function An(e){return{enabled:!!e?.enabled,server:e?.server||St,topicSet:!!e?.topic,tokenSet:!!e?.token}}function Sn(e,t){let n={...e??{}};if("enabled"in t&&(n.enabled=!!t.enabled),"server"in t){let a=String(t.server).trim().replace(/\/+$/,"");if(!/^https?:\/\/\S+$/.test(a))throw new Error("ntfy server must be an http(s) URL");n.server=a}if("topic"in t){let a=String(t.topic).trim();if(!a)throw new Error("ntfy topic cannot be empty");n.topic=a}if("token"in t){let a=String(t.token??"").trim();a?n.token=a:delete n.token}if(n.enabled&&!n.topic)throw new Error("set a topic before enabling ntfy");return n}export{W as a,be as b,Bt as c,Ht as d,Lt as e,Kt as f,Yt as g,Gt as h,on as i,sn as j,dn as k,ct as l,un as m,xt as n,fn as o,hn as p,vn as q,Ce as r,bn as s,Te as t,At as u,kn as v,wn as w,An as x,Sn as y,st as z,nn as A};
|
|
744
|
+
//# sourceMappingURL=chunk-BUELCBBV.js.map
|