agentix-cli 0.163.0 → 0.165.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/README.md +18 -13
- package/dist/{App-VEMBGGIU.js → App-4PQX4N6S.js} +2 -2
- package/dist/{ChatApp-YDIXGL6D.js → ChatApp-NHB5VPUE.js} +2 -2
- package/dist/{absorb-eval-Z33YVMFY.js → absorb-eval-PWLEKRFA.js} +2 -2
- package/dist/{agent-2X54W337.js → agent-USWAFKWO.js} +2 -2
- package/dist/{board-dashboard-7WLAFGOS.js → board-dashboard-ICXWFJF7.js} +608 -407
- package/dist/board-dashboard-ICXWFJF7.js.map +1 -0
- package/dist/{chunk-FW6OJ27C.js → chunk-343WTR6F.js} +2 -2
- package/dist/{chunk-UXUMH5SD.js → chunk-3S2BNZHX.js} +2 -2
- package/dist/{chunk-RE36JAQN.js → chunk-6JFGNRC3.js} +6 -6
- package/dist/{chunk-ITIW4UUJ.js → chunk-6JKFJM2D.js} +2 -2
- package/dist/{chunk-HEGRUOSS.js → chunk-AM2DYH7Y.js} +2 -2
- package/dist/{chunk-SCEQJFQO.js → chunk-AU3VT7BD.js} +20 -7
- package/dist/{chunk-SCEQJFQO.js.map → chunk-AU3VT7BD.js.map} +1 -1
- package/dist/{chunk-6S2S5LFZ.js → chunk-BRNAE6ET.js} +2 -2
- package/dist/{chunk-VYGFBGUM.js → chunk-C65BZPUE.js} +2 -2
- package/dist/{chunk-F2ECPRGJ.js → chunk-CLHIE4UW.js} +57 -50
- package/dist/chunk-CLHIE4UW.js.map +1 -0
- package/dist/{chunk-CHJNHMPD.js → chunk-CR55SCRE.js} +2 -2
- package/dist/{chunk-V2ZJMO63.js → chunk-DLTJCOEN.js} +2 -2
- package/dist/{chunk-EZXLWMXC.js → chunk-EGCWS56X.js} +2 -2
- package/dist/{chunk-XNXKB2VI.js → chunk-EJFJBYDJ.js} +2 -2
- package/dist/{chunk-CU532CD7.js → chunk-FJJBXYJ5.js} +6 -6
- package/dist/{chunk-FJW4KZO7.js → chunk-H4DQGVUG.js} +2 -2
- package/dist/{chunk-YG34COEO.js → chunk-HGQKZKXL.js} +2 -2
- package/dist/{chunk-MTQMBPYO.js → chunk-I53O35TO.js} +2 -2
- package/dist/{chunk-JABZOVMR.js → chunk-IMERQYQ6.js} +2 -2
- package/dist/{chunk-7PN7VPTC.js → chunk-JCOLQ6MO.js} +2 -2
- package/dist/{chunk-6QZKQUAT.js → chunk-JTFCU5LH.js} +2 -2
- package/dist/{chunk-OBHWGBDW.js → chunk-K7ZUE7SG.js} +2 -2
- package/dist/{chunk-SZ3CRNX4.js → chunk-KDDCIOS7.js} +3 -3
- package/dist/{chunk-ZZR7FOZ7.js → chunk-KKOULF3I.js} +2 -2
- package/dist/chunk-KKOULF3I.js.map +1 -0
- package/dist/{chunk-MWNCS57L.js → chunk-LUOW2YHY.js} +2 -2
- package/dist/{chunk-FUGLS3A3.js → chunk-MK3H5LQT.js} +2 -2
- package/dist/{chunk-MCMEJVJC.js → chunk-MYEEWFXP.js} +2 -2
- package/dist/{chunk-GWAITHGZ.js → chunk-QLN4W2KV.js} +2 -2
- package/dist/{chunk-6TURWSMN.js → chunk-QUFIUXMQ.js} +2 -2
- package/dist/chunk-QUFIUXMQ.js.map +1 -0
- package/dist/{chunk-VCUN55AE.js → chunk-TW2PBGYA.js} +2 -2
- package/dist/{chunk-YFNV7LAG.js → chunk-UD3WIY2B.js} +3 -3
- package/dist/{chunk-J3LMELJC.js → chunk-UY64KKNE.js} +2 -2
- package/dist/{chunk-Q6JWDH7G.js → chunk-Z5JVYKVH.js} +2 -2
- package/dist/cli.js +1 -1
- package/dist/{client-2QZHCEB5.js → client-3JLER5ZO.js} +2 -2
- package/dist/{config-KELRDI3A.js → config-HHNGJKVW.js} +2 -2
- package/dist/{config-mutate-T2WXFS2S.js → config-mutate-CP2TIY2J.js} +2 -2
- package/dist/config-mutator-ZSW4PTO5.js +2 -0
- package/dist/{contributions-EH776JXB.js → contributions-6M3TIP57.js} +2 -2
- package/dist/{doctor-IHA2USIQ.js → doctor-TOLXE6QQ.js} +2 -2
- package/dist/{follow-up-tool-BTV6CBTA.js → follow-up-tool-Q44GNGWF.js} +2 -2
- package/dist/{hub-NMD7O3DF.js → hub-H4AW5H7E.js} +2 -2
- package/dist/index.d.ts +25 -0
- package/dist/index.js +1 -1
- package/dist/model-call-HMVMUAXS.js +2 -0
- package/dist/{processes-GRS7BSIU.js → processes-QZWODHBX.js} +2 -2
- package/dist/{program-XHOUH5DX.js → program-YJGGF5BS.js} +241 -241
- package/dist/program-YJGGF5BS.js.map +1 -0
- package/dist/{promote-HX4RGNLX.js → promote-JLFDSQFH.js} +2 -2
- package/dist/{query-E5LWOH4B.js → query-KNZ3EMHA.js} +2 -2
- package/dist/{query-settings-ST5C4FPH.js → query-settings-XRNZOOWV.js} +3 -3
- package/dist/{registry-MMZJDIXY.js → registry-EHLXMVUV.js} +2 -2
- package/dist/{request-planner-RWRMDI3J.js → request-planner-T5GKPGQT.js} +2 -2
- package/dist/{review-candidates-WJ537GUT.js → review-candidates-HSKH2UGT.js} +2 -2
- package/dist/{rotation-memo-2G6N3VF3.js → rotation-memo-6RP4Z3S5.js} +2 -2
- package/dist/{routing-HQ5R7WP6.js → routing-C66W2E3P.js} +2 -2
- package/dist/schedule-tool-3Z45TBN6.js +2 -0
- package/dist/{scheduler-UELETH3W.js → scheduler-TZJJGRAE.js} +2 -2
- package/dist/{seat-ARUEPPYV.js → seat-OSYVYKBK.js} +2 -2
- package/dist/{select-JQLDW6BF.js → select-I5JLTJKJ.js} +2 -2
- package/dist/{set-enabled-FB5V5DR7.js → set-enabled-Q5EPYA33.js} +2 -2
- package/dist/{tool-7JZ4UIJV.js → tool-SM3FPKK6.js} +2 -2
- package/dist/{tool-ZJCEBWLR.js → tool-ZDGA6CTA.js} +2 -2
- package/dist/wiki-NAE25PMF.js +2 -0
- package/dist/wiki-enrich-3XXN4XCV.js +2 -0
- package/dist/workspace-env-UOK5MMKD.js +2 -0
- package/package.json +1 -1
- package/dist/board-dashboard-7WLAFGOS.js.map +0 -1
- package/dist/chunk-6TURWSMN.js.map +0 -1
- package/dist/chunk-F2ECPRGJ.js.map +0 -1
- package/dist/chunk-ZZR7FOZ7.js.map +0 -1
- package/dist/config-mutator-PLOFE6IA.js +0 -2
- package/dist/model-call-J7JATTMW.js +0 -2
- package/dist/program-XHOUH5DX.js.map +0 -1
- package/dist/schedule-tool-CVDIKLDN.js +0 -2
- package/dist/wiki-MMSBP2XP.js +0 -2
- package/dist/wiki-enrich-CBXIMFOD.js +0 -2
- package/dist/workspace-env-ROH45HXN.js +0 -2
- /package/dist/{App-VEMBGGIU.js.map → App-4PQX4N6S.js.map} +0 -0
- /package/dist/{ChatApp-YDIXGL6D.js.map → ChatApp-NHB5VPUE.js.map} +0 -0
- /package/dist/{absorb-eval-Z33YVMFY.js.map → absorb-eval-PWLEKRFA.js.map} +0 -0
- /package/dist/{agent-2X54W337.js.map → agent-USWAFKWO.js.map} +0 -0
- /package/dist/{chunk-FW6OJ27C.js.map → chunk-343WTR6F.js.map} +0 -0
- /package/dist/{chunk-UXUMH5SD.js.map → chunk-3S2BNZHX.js.map} +0 -0
- /package/dist/{chunk-RE36JAQN.js.map → chunk-6JFGNRC3.js.map} +0 -0
- /package/dist/{chunk-ITIW4UUJ.js.map → chunk-6JKFJM2D.js.map} +0 -0
- /package/dist/{chunk-HEGRUOSS.js.map → chunk-AM2DYH7Y.js.map} +0 -0
- /package/dist/{chunk-6S2S5LFZ.js.map → chunk-BRNAE6ET.js.map} +0 -0
- /package/dist/{chunk-VYGFBGUM.js.map → chunk-C65BZPUE.js.map} +0 -0
- /package/dist/{chunk-CHJNHMPD.js.map → chunk-CR55SCRE.js.map} +0 -0
- /package/dist/{chunk-V2ZJMO63.js.map → chunk-DLTJCOEN.js.map} +0 -0
- /package/dist/{chunk-EZXLWMXC.js.map → chunk-EGCWS56X.js.map} +0 -0
- /package/dist/{chunk-XNXKB2VI.js.map → chunk-EJFJBYDJ.js.map} +0 -0
- /package/dist/{chunk-CU532CD7.js.map → chunk-FJJBXYJ5.js.map} +0 -0
- /package/dist/{chunk-FJW4KZO7.js.map → chunk-H4DQGVUG.js.map} +0 -0
- /package/dist/{chunk-YG34COEO.js.map → chunk-HGQKZKXL.js.map} +0 -0
- /package/dist/{chunk-MTQMBPYO.js.map → chunk-I53O35TO.js.map} +0 -0
- /package/dist/{chunk-JABZOVMR.js.map → chunk-IMERQYQ6.js.map} +0 -0
- /package/dist/{chunk-7PN7VPTC.js.map → chunk-JCOLQ6MO.js.map} +0 -0
- /package/dist/{chunk-6QZKQUAT.js.map → chunk-JTFCU5LH.js.map} +0 -0
- /package/dist/{chunk-OBHWGBDW.js.map → chunk-K7ZUE7SG.js.map} +0 -0
- /package/dist/{chunk-SZ3CRNX4.js.map → chunk-KDDCIOS7.js.map} +0 -0
- /package/dist/{chunk-MWNCS57L.js.map → chunk-LUOW2YHY.js.map} +0 -0
- /package/dist/{chunk-FUGLS3A3.js.map → chunk-MK3H5LQT.js.map} +0 -0
- /package/dist/{chunk-MCMEJVJC.js.map → chunk-MYEEWFXP.js.map} +0 -0
- /package/dist/{chunk-GWAITHGZ.js.map → chunk-QLN4W2KV.js.map} +0 -0
- /package/dist/{chunk-VCUN55AE.js.map → chunk-TW2PBGYA.js.map} +0 -0
- /package/dist/{chunk-YFNV7LAG.js.map → chunk-UD3WIY2B.js.map} +0 -0
- /package/dist/{chunk-J3LMELJC.js.map → chunk-UY64KKNE.js.map} +0 -0
- /package/dist/{chunk-Q6JWDH7G.js.map → chunk-Z5JVYKVH.js.map} +0 -0
- /package/dist/{client-2QZHCEB5.js.map → client-3JLER5ZO.js.map} +0 -0
- /package/dist/{config-KELRDI3A.js.map → config-HHNGJKVW.js.map} +0 -0
- /package/dist/{config-mutate-T2WXFS2S.js.map → config-mutate-CP2TIY2J.js.map} +0 -0
- /package/dist/{config-mutator-PLOFE6IA.js.map → config-mutator-ZSW4PTO5.js.map} +0 -0
- /package/dist/{contributions-EH776JXB.js.map → contributions-6M3TIP57.js.map} +0 -0
- /package/dist/{doctor-IHA2USIQ.js.map → doctor-TOLXE6QQ.js.map} +0 -0
- /package/dist/{follow-up-tool-BTV6CBTA.js.map → follow-up-tool-Q44GNGWF.js.map} +0 -0
- /package/dist/{hub-NMD7O3DF.js.map → hub-H4AW5H7E.js.map} +0 -0
- /package/dist/{model-call-J7JATTMW.js.map → model-call-HMVMUAXS.js.map} +0 -0
- /package/dist/{processes-GRS7BSIU.js.map → processes-QZWODHBX.js.map} +0 -0
- /package/dist/{promote-HX4RGNLX.js.map → promote-JLFDSQFH.js.map} +0 -0
- /package/dist/{query-E5LWOH4B.js.map → query-KNZ3EMHA.js.map} +0 -0
- /package/dist/{query-settings-ST5C4FPH.js.map → query-settings-XRNZOOWV.js.map} +0 -0
- /package/dist/{registry-MMZJDIXY.js.map → registry-EHLXMVUV.js.map} +0 -0
- /package/dist/{request-planner-RWRMDI3J.js.map → request-planner-T5GKPGQT.js.map} +0 -0
- /package/dist/{review-candidates-WJ537GUT.js.map → review-candidates-HSKH2UGT.js.map} +0 -0
- /package/dist/{rotation-memo-2G6N3VF3.js.map → rotation-memo-6RP4Z3S5.js.map} +0 -0
- /package/dist/{routing-HQ5R7WP6.js.map → routing-C66W2E3P.js.map} +0 -0
- /package/dist/{schedule-tool-CVDIKLDN.js.map → schedule-tool-3Z45TBN6.js.map} +0 -0
- /package/dist/{scheduler-UELETH3W.js.map → scheduler-TZJJGRAE.js.map} +0 -0
- /package/dist/{seat-ARUEPPYV.js.map → seat-OSYVYKBK.js.map} +0 -0
- /package/dist/{select-JQLDW6BF.js.map → select-I5JLTJKJ.js.map} +0 -0
- /package/dist/{set-enabled-FB5V5DR7.js.map → set-enabled-Q5EPYA33.js.map} +0 -0
- /package/dist/{tool-7JZ4UIJV.js.map → tool-SM3FPKK6.js.map} +0 -0
- /package/dist/{tool-ZJCEBWLR.js.map → tool-ZDGA6CTA.js.map} +0 -0
- /package/dist/{wiki-MMSBP2XP.js.map → wiki-NAE25PMF.js.map} +0 -0
- /package/dist/{wiki-enrich-CBXIMFOD.js.map → wiki-enrich-3XXN4XCV.js.map} +0 -0
- /package/dist/{workspace-env-ROH45HXN.js.map → workspace-env-UOK5MMKD.js.map} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as He,b as w,c as z,d as qe,e as pe,f as ue,g as M,h as ge,i as O,j as U,n as Fe,o as Ke,p as Ge,q as Je}from"./chunk-XVTD6I34.js";import{e as Be,i as je}from"./chunk-QAWKN2N4.js";import{b as ce}from"./chunk-MTX4UPNB.js";import{a as X,b as Le}from"./chunk-TW2PBGYA.js";import{c as Ue,d as le,e as P,f as de,g as q}from"./chunk-AU3VT7BD.js";import{kb as Oe,ma as Me}from"./chunk-KDDCIOS7.js";import{a as We}from"./chunk-VUEQ4SL5.js";import{a as Te}from"./chunk-IMLAPB7G.js";import{c as De,e as _e}from"./chunk-LQE73AZR.js";import{b as Ne}from"./chunk-MRIVENBY.js";import{n as se,p as ze}from"./chunk-LQS27HSV.js";import{b as Y}from"./chunk-2VDO2HEK.js";import{O as J}from"./chunk-MYEEWFXP.js";import{a as H,b as G}from"./chunk-C65BZPUE.js";import{a as Re}from"./chunk-CR55SCRE.js";import{c as Ie,d as Ee}from"./chunk-OWNQ2FD4.js";import{a as Pe}from"./chunk-ROLSSYXE.js";import{a as Ce}from"./chunk-QUFIUXMQ.js";import{Ia as Ae,Pa as Lt,Y as ae,Z as $e,fa as Ut,gb as oe,jb as j,kb as Se,tb as ie}from"./chunk-KKOULF3I.js";import{existsSync as F,readFileSync as Ve,writeFileSync as Qe,appendFileSync as Ht,mkdirSync as qt}from"fs";import{dirname as Ft,resolve as N}from"path";import{fileURLToPath as Kt}from"url";import{hostname as Gt}from"os";import{spawn as Jt}from"child_process";function Ye(e,t){let n=e.configExists?e.agentCount===0?"Add your first agent":"Add another agent":"Set up your team",r=`<header class="ax-topbar">
|
|
2
2
|
<div class="ax-topbar__left">
|
|
3
3
|
<div class="ax-brand">
|
|
4
4
|
<span class="ax-brand__mark">AX</span>
|
|
@@ -41,7 +41,7 @@ import{a as Be,b as k,c as z,d as je,e as pe,f as ue,g as M,h as ge,i as O,j as
|
|
|
41
41
|
${le("Skip, I'll do it later",{onclick:"window.location.href='/live'"})}
|
|
42
42
|
</footer>
|
|
43
43
|
</form>
|
|
44
|
-
</div>`;return
|
|
44
|
+
</div>`;return Ue({title:"AgentX \u2014 Setup",activeTab:"custom",subtitle:"Setup",customHeader:r,noMain:!0,body:d,css:Bt,scripts:jt})}var Bt=`
|
|
45
45
|
/* Pre-dashboard topbar variant \u2014 no tab nav, the pills are the only chrome. */
|
|
46
46
|
.ax-topbar__right a.ax-skip {
|
|
47
47
|
padding: 4px 10px; border: 1px solid var(--ax-border-2); border-radius: 4px;
|
|
@@ -98,7 +98,7 @@ import{a as Be,b as k,c as z,d as je,e as pe,f as ue,g as M,h as ge,i as O,j as
|
|
|
98
98
|
.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); }
|
|
99
99
|
.ax-startd { margin-top: 14px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
|
|
100
100
|
.ax-startd__status { color: var(--ax-text-2); font-size: var(--ax-fs-sm); }
|
|
101
|
-
.ax-startd__status a { color: var(--ax-accent); }`,
|
|
101
|
+
.ax-startd__status a { color: var(--ax-accent); }`,jt=`<script>
|
|
102
102
|
document.getElementById('enableTelegram').addEventListener('change', (e) => {
|
|
103
103
|
document.getElementById('telegramFields').classList.toggle('is-show', e.target.checked);
|
|
104
104
|
});
|
|
@@ -172,16 +172,16 @@ document.getElementById('wizard').addEventListener('submit', async (e) => {
|
|
|
172
172
|
btn.disabled = false; btn.textContent = 'Save and continue';
|
|
173
173
|
}
|
|
174
174
|
});
|
|
175
|
-
</script>`;ie();function
|
|
175
|
+
</script>`;ie();function Ze(e=process.cwd()){let t=N(e,"agentx.json");if(!F(t))return{configExists:!1,agentCount:0,channelCount:0};try{let n=JSON.parse(Ve(t,"utf-8")),r=n.agents?Object.keys(n.agents).length:0,a=n.channels?Object.values(n.channels).filter(o=>o&&o.enabled).length:0;return{configExists:!0,agentCount:r,channelCount:a,nodeName:n.node?.name}}catch{return{configExists:!1,agentCount:0,channelCount:0}}}function Yt(e,t=process.cwd(),n={}){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 r=Xt(e.agent.triggerWords);if(r.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=N(t,"agentx.json"),o=N(t,".env"),i=N(t,"agents",e.agent.id),s=Ze(t);qt(i,{recursive:!0});let l=N(i,"CLAUDE.md");if(!F(l)){let g=e.agent.personality?.trim()||`You are ${e.agent.name}, an assistant on the ${e.nodeName} team.`;Qe(l,`# ${e.agent.name}
|
|
176
176
|
|
|
177
|
-
${
|
|
178
|
-
`)}let
|
|
179
|
-
`));return}if(a.length>0){let o=r.endsWith(`
|
|
177
|
+
${g}
|
|
178
|
+
`)}let d=e.telegram?`TG_${e.agent.id.toUpperCase()}_BOT_TOKEN`:void 0,c;if(s.configExists)c=X(m=>{if(m.node=m.node||{},m.node.name||(m.node.name=e.nodeName),m.node.id||(m.node.id=et(e.nodeName)||"team"),m.node.bind||(m.node.bind="127.0.0.1:18800"),m.node.defaultAgent=m.node.defaultAgent||e.agent.id,m.providers=m.providers||{},m.providers.claude||(m.providers.claude={apiKey:"${ANTHROPIC_API_KEY}"}),m.agents=m.agents||{},m.agents[e.agent.id])throw new Error(`Agent "${e.agent.id}" already exists.`);return m.agents[e.agent.id]=tt(e,i,r),e.telegram&&(m.channels=m.channels||{},m.channels.telegram=m.channels.telegram||{enabled:!0,accounts:{},policy:{dm:"pair",group:"mention-required"}},m.channels.telegram.enabled=!0,m.channels.telegram.accounts=m.channels.telegram.accounts||{},m.channels.telegram.accounts[e.telegram.accountId]=nt(e,d)),{summary:`added agent "${e.agent.id}"`+(e.telegram?" + telegram account":"")}},{configPath:a}).backupPath;else{let g=Vt(e,i,r,d,n);Le(g,{configPath:a})}Qt(o,e,d);let f=[];return(e.anthropicApiKey||!F(N(t,".env")))&&f.push("Double-check the API keys in .env"),e.agent.tier==="claude-code"&&f.push("Run claude --version to confirm Claude Code is installed (needed for the claude-code engine)"),e.agent.tier==="codex-cli"&&f.push("Run codex --version to confirm Codex CLI is installed (needed for the codex-cli engine)"),e.agent.tier==="opencode"&&f.push("Run opencode --version to confirm OpenCode is installed and authenticated"),f.push("Start the daemon: agentx daemon start"),f.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:f,backupPath:c}}function Xt(e){return(e||"").split(/[,\s]+/).map(t=>t.trim()).filter(Boolean).filter((t,n,r)=>r.indexOf(t)===n)}function et(e){return(e||"").toLowerCase().replace(/[^a-z0-9-]+/g,"-").replace(/^-+|-+$/g,"")}function Vt(e,t,n,r,a={}){let o=et(e.nodeName)||"team",i=a.daemonPort??18800,s={node:{id:o,name:e.nodeName,bind:`127.0.0.1:${i}`,defaultAgent:e.agent.id},providers:{claude:{apiKey:"${ANTHROPIC_API_KEY}"}},agents:{[e.agent.id]:tt(e,t,n)},channels:{},crons:{},mesh:{enabled:!1,peers:[],discovery:"static",healthCheck:{interval:60,timeout:10}},dashboard:{enabled:!0,port:a.dashboardPort??4202,bind:"127.0.0.1",daemonUrl:`http://localhost:${i}`},boards:[]};return e.telegram&&r?s.channels.telegram={enabled:!0,accounts:{[e.telegram.accountId]:nt(e,r)},policy:{dm:"pair",group:"mention-required"}}:s.channels.telegram={enabled:!1,accounts:{},policy:{dm:"pair",group:"mention-required"}},s}function tt(e,t,n){let r={name:e.agent.name,workspace:t,tier:e.agent.tier,mentions:n,maxConcurrent:2,permissionMode:"default"};return e.agent.model&&(r.model=e.agent.model),e.agent.provider&&(r.provider=e.agent.provider),e.agent.personality?.trim()&&(r.systemPrompt=e.agent.personality.trim().slice(0,400)),r}function nt(e,t){return e.telegram?.botUsername,{token:"${"+t+"}",agentBinding:e.agent.id}}function Qt(e,t,n){let r=F(e)?Ve(e,"utf-8"):"",a=[];if(t.anthropicApiKey&&!r.includes("ANTHROPIC_API_KEY=")&&a.push(`ANTHROPIC_API_KEY=${t.anthropicApiKey}`),t.telegram&&n&&!r.includes(`${n}=`)&&a.push(`${n}=${t.telegram.botToken}`),!F(e)){Qe(e,[...["# AgentX environment variables","# (Never commit this file \u2014 it contains secrets.)",""],...a,""].join(`
|
|
179
|
+
`),{mode:384});return}if(a.length>0){let o=r.endsWith(`
|
|
180
180
|
`)?"":`
|
|
181
|
-
`;
|
|
181
|
+
`;Ht(e,o+a.join(`
|
|
182
182
|
`)+`
|
|
183
|
-
`)}}function
|
|
184
|
-
`,{mode:384}),Xt(n,this.path)}add(t,n){return this.locked(()=>this.addUnlocked(t,n))}addUnlocked(t,n){let r=this.editable();if(!r.ok)return r;let a=r.pins;if(a.filter(i=>!this.shadowed(i)).length+this.fixed.length>=n)return{ok:!1,status:409,error:`You already have ${n} pinned pages, the most allowed (app.pins.max). Remove one first.`};if([...this.fixed,...a].some(i=>i.label.toLowerCase()===t.label.toLowerCase()))return{ok:!1,status:409,error:`You already have a button called ${t.label}.`};if(this.fixed.some(i=>i.url===t.url))return{ok:!1,status:409,error:"This page is already a button, set in agentx.json (app.pins.pages)."};let o={id:`pin_${nn(6).toString("hex")}`,...t,createdAt:new Date(this.now()).toISOString()};return a.push(o),this.write(a),{ok:!0,pin:o}}rename(t,n){return this.locked(()=>this.renameUnlocked(t,n))}renameUnlocked(t,n){if(this.isFixed(t))return{ok:!1,status:409,error:rt};let r=this.editable();if(!r.ok)return r;let a=r.pins,o=a.find(i=>i.id===t);return o?[...this.fixed,...a].some(i=>i.id!==t&&i.label.toLowerCase()===n.toLowerCase())?{ok:!1,status:409,error:`You already have a button called ${n}.`}:(o.label=n,this.write(a),{ok:!0,pin:o}):{ok:!1,status:404,error:"No such pinned page."}}remove(t){return this.locked(()=>this.removeUnlocked(t))}removeUnlocked(t){if(this.isFixed(t))return{ok:!1,status:409,error:rt};let n=this.editable();if(!n.ok)return n;let r=n.pins.filter(a=>a.id!==t);return r.length===n.pins.length?{ok:!1,status:404,error:"No such pinned page."}:(this.write(r),{ok:!0})}};function $r(e,t){let n=e.app.pins;return{store:new me(an(t,n.file),Date.now,sn(n.pages)),max:n.max}}async function Ar(e,t,n,r,a){if(n!=="/api/app/pins"&&!n.startsWith("/api/app/pins/"))return!1;let o=n.slice(13);if(r==="GET"&&o==="")return R(t,200,{pins:a.store.list(),max:a.max});if(r!=="POST")return R(t,404,{error:"not found"});let i;try{i=await Y(e,4096)}catch(l){return R(t,400,{error:l.message})}let s=typeof i.id=="string"?i.id:"";if(o==="/add"){let l=ln(i);if(!l.ok)return R(t,400,{error:l.error});let d=a.store.add(l.value,a.max);return d.ok?R(t,200,{ok:!0,pin:d.pin}):R(t,d.status,{error:d.error})}if(o==="/rename"){let l=V(i.label);if(!l.ok)return R(t,400,{error:l.error});let d=a.store.rename(s,l.value);return d.ok?R(t,200,{ok:!0,pin:d.pin}):R(t,d.status,{error:d.error})}if(o==="/remove"){let l=a.store.remove(s);return l.ok?R(t,200,{ok:!0}):R(t,l.status,{error:l.error})}return R(t,404,{error:"not found"})}function R(e,t,n){return e.writeHead(t,{"Content-Type":"application/json","Cache-Control":"no-store"}),e.end(JSON.stringify(n)),!0}import{existsSync as at,readFileSync as ot}from"fs";ie();function dn(e){let t=H(e),n={};if(at(t))try{n=j(JSON.parse(ot(t,"utf-8")))}catch{n={}}let r=oe.safeParse(n?.approvals);return r.success?r.data:oe.parse(void 0)}function Rr(e){let t=H(e),n={};if(at(t))try{n=j(JSON.parse(ot(t,"utf-8")))}catch{n={}}return Ne({desk:n?.notifications?.desk,popupEnabled:!!dn(e).popup?.enabled})}function Tr(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 Dr(e,t={}){return K(n=>{let r=n.approvals??={};if(e.defaultExpiryDays!==void 0&&(r.defaultExpiryDays=e.defaultExpiryDays),e.maxExpiryDays!==void 0&&(r.maxExpiryDays=e.maxExpiryDays),e.laterHours!==void 0&&(r.laterHours=e.laterHours),e.notifyAgent!==void 0&&(r.notifyAgent=e.notifyAgent),e.forwardTo===null)delete r.forwardTo;else if(e.forwardTo!==void 0){let d=Array.isArray(n.mesh?.peers)?n.mesh.peers:[];if(!d.some(c=>c.name===e.forwardTo))throw new Error(`"${e.forwardTo}" is not in mesh.peers${d.length?` (known: ${d.map(c=>c.name).join(", ")})`:""}; pair the machines first`);r.forwardTo=e.forwardTo}let a=r.digest??={};e.digestEnabled!==void 0&&(a.enabled=e.digestEnabled),e.digestTime!==void 0&&(a.time=e.digestTime),e.digestTimezone===null?delete a.timezone:e.digestTimezone!==void 0&&(a.timezone=e.digestTimezone),e.destination===null?delete a.destination:e.destination!==void 0&&(a.destination=e.destination);let o=r.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 i=r.checkin??={};if(e.checkinEnabled!==void 0&&(i.enabled=e.checkinEnabled),e.checkinTimes!==void 0&&(i.times=e.checkinTimes),e.checkinDailyAt!==void 0&&(i.dailyAt=e.checkinDailyAt),e.checkinLists!==void 0&&(i.lists=e.checkinLists),e.checkinAgent===null?delete i.agent:e.checkinAgent!==void 0&&(i.agent=e.checkinAgent),e.deskPhone!==void 0||e.deskComputer!==void 0){let d=(n.notifications??={}).desk??={};e.deskPhone!==void 0&&(d.phone=e.deskPhone),e.deskComputer!==void 0&&(d.computer=e.deskComputer)}let s=r.defaultExpiryDays??3,l=r.maxExpiryDays??30;if(s>l)throw new Error(`defaultExpiryDays (${s}) can't be more than maxExpiryDays (${l})`)},{configPath:t.configPath,reload:t.reload})}import{createServer as hn}from"http";var Q=class{peers;cache=new Map;ttl=3e4;constructor(t){this.peers=t.map(n=>({...n,url:n.url.replace(/\/$/,"")}))}async getRemoteAgents(){let t=[];return await Promise.all(this.peers.map(async n=>{try{let r=await this.fetchJson(`${n.url}/wiki/agents`);n.nodeId=r.nodeId;for(let a of r.agents||[])(a.totalEntries>0||a.totalArticles>0)&&t.push({...a,nodeId:r.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,r){try{let a=await this.fetchJson(`${t}/wiki/article?agent=${encodeURIComponent(n)}&path=${encodeURIComponent(r)}`);return{meta:{title:a.title,tags:a.tags||[],owner:a.owner,access:"public",created:a.created,lastUpdated:a.lastUpdated,sources:a.sources||[]},content:a.content,path:a.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 r=this.peers.find(i=>t.startsWith(`${i.url}/`))?.token,a=await fetch(t,{headers:r?{Authorization:`Bearer ${r}`}:{},signal:AbortSignal.timeout(5e3)});if(!a.ok)throw new Error(`HTTP ${a.status}`);let o=await a.json();return this.cache.set(t,{data:o,ts:Date.now()}),o}};var it=864e5;function he(e){let t=new Map;for(let n of e.entities.values()){let r=t.get(n.type)??[];r.push(n),t.set(n.type,r)}return t}function ve(e,t){if(t.type==="event")return t.date||t.updated;let n=Be(e,t,new Set(["event"]))[0],r=t.updated||t.date;return n&&n.date>r?n.date:r}function st(e,t,n=Date.now()){let r=[],a=new Date(n+14*it).toISOString().slice(0,10),o=new Date(n).toISOString().slice(0,10);for(let s of t){let l=s.statements.find(c=>c.property==="due"&&/^\d{4}-\d{2}-\d{2}/.test(c.value)),d=s.statements.some(c=>c.property==="fulfilled_by")||s.statements.some(c=>c.property==="status"&&/^(fulfilled|done|paid|filed)$/i.test(c.value));s.statements.some(c=>c.property==="status"&&/^late$/i.test(c.value))?r.push({e:s,chip:"late",why:"marked late"}):l&&!d&&l.value<o?r.push({e:s,chip:"late",why:`was due ${l.value}`}):l&&!d&&l.value<=a?r.push({e:s,chip:"due",why:`due ${l.value}`}):s.statements.some(c=>c.status==="proposed")?r.push({e:s,chip:"proposed",why:"statements wait for confirmation"}):s.type==="event"&&s.importanceProposed&&s.importanceProposed!==s.importance?r.push({e:s,chip:"proposed",why:`proposed as ${s.importanceProposed}; the owner decides`}):s.type==="event"&&s.importance==="major"&&s.date&&n-Date.parse(s.date)<=30*it&&r.push({e:s,chip:"major",why:`major event ${s.date}`})}let i={late:0,due:1,major:2,proposed:3};return r.sort((s,l)=>i[s.chip]-i[l.chip])}function Z(e,t,n="",r){return`<div class="ox-row"><span class="ox-ic">${je(e.ontology,t.type)}</span><div class="t"><a href="${ue(t.id)}">${k(t.title)}</a><div class="ox-sub">${k(r??`${pe(e.ontology,t.type).toLowerCase()} \xB7 ${ve(e,t)}`)}</div></div><div class="r">${n}</div></div>`}function lt(e,t){let n=t.slice(0,6).map(r=>Z(e,r.e,`<span class="ox-st ${r.chip}">${r.chip}</span>`,r.why)).join("");return`<section class="ox-card"><div class="ox-card-h"><h2>Needs attention</h2><span class="note">${t.length}</span></div>${n||'<div class="ox-empty">Nothing waits on a person.</div>'}</section>`}function cn(e){return e.length?`<div class="ox-err"><b>ontology.yaml has ${e.length} problem${e.length===1?"":"s"}</b> \u2014 the defaults are used where they apply. <a href="/ontology">See them</a></div>`:""}function dt(e,t){let n=he(e),r=`<div class="ox-bar">${M([])}</div>`;r+=`<div class="ox-head"><div class="ox-avatar">${z("home")}</div><div><h1>Wiki</h1><p>${e.entities.size} things, merged from every agent's pages and typed by the <a href="/ontology">ontology</a>. <a href="/agents">Agent wikis</a> \xB7 <a href="/entries">raw entries</a></p></div></div>`,r+=cn(t),r+='<div class="ox-grid3">';for(let o of e.ontology.pillars){let i=e.ontology.types.filter(d=>d.pillar===o.id),s=i.reduce((d,c)=>d+(n.get(c.id)?.length??0),0),l=i.filter(d=>n.get(d.id)?.length).map(d=>`${d.plural??d.label} ${n.get(d.id).length}`).join(" \xB7 ");r+=`<a class="ox-card" href="/p/${encodeURIComponent(o.id)}" style="color:inherit"><div class="ox-card-h"><span class="ox-ic">${z(o.icon)}</span><h2>${k(o.label)}</h2><span class="zin">${s}</span></div><div class="ox-sub" style="white-space:normal">${k(o.description??"")}</div><div class="ox-sub" style="margin-top:6px;white-space:normal">${k(l||"nothing yet")}</div></a>`}r+='</div><div class="ox-grid2">';let a=(n.get("event")??[]).filter(o=>o.importance!=="minor").sort((o,i)=>i.date.localeCompare(o.date)).slice(0,8);return r+='<section class="ox-card"><div class="ox-card-h"><h2>Recent events</h2><span class="note">major and normal</span><a class="zin" href="/p/events">all (Z1) \u2192</a></div>'+(a.map(o=>`<div class="ox-ev"><span class="d">${k(o.date)}</span><span class="ox-st ${o.importance}">${o.importance}</span><a href="${ue(o.id)}">${k(o.title)}</a></div>`).join("")||'<div class="ox-empty">No events yet.</div>')+"</section>",r+=lt(e,st(e,[...e.entities.values()])),r+="</div>",U("Wiki",O(e,{home:!0}),r)}function ct(e,t,n){let r=e.ontology.pillars.find(c=>c.id===t);if(!r)return null;let a=he(e),o=e.ontology.types.filter(c=>c.pillar===r.id),i=o.find(c=>c.id===n)??o.find(c=>a.get(c.id)?.length)??o[0],s=`<div class="ox-bar">${M([{label:r.label}])}${ge(1)}</div>`;s+=`<div class="ox-head"><div class="ox-avatar">${z(r.icon)}</div><div><h1>${k(r.label)}</h1><p>${k(r.description??"")}</p></div></div>`,s+=`<nav class="ox-tabs">${o.map(c=>`<a class="${c.id===i?.id?"on":""}" href="/p/${encodeURIComponent(r.id)}?kind=${encodeURIComponent(c.id)}">${k(c.plural??c.label)}<small>${a.get(c.id)?.length??0}</small></a>`).join("")}</nav>`;let l=i?(a.get(i.id)??[]).map(c=>({e:c,at:ve(e,c)})).sort((c,m)=>m.at.localeCompare(c.at)):[];s+='<div class="ox-grid2">',s+=`<section class="ox-card"><div class="ox-card-h"><h2>${k(i?.plural??i?.label??"")}</h2><span class="note">${l.length} \xB7 most active first</span>`+(i?`<a class="zin" href="/p/${encodeURIComponent(r.id)}/${encodeURIComponent(i.id)}">open list (Z3) \u2192</a>`:"")+"</div>"+(l.slice(0,5).map(({e:c,at:m})=>Z(e,c,c.type==="event"?`<span class="ox-st ${c.importance}">${c.importance}</span>`:"",`${He(c,90)||pe(e.ontology,c.type).toLowerCase()} \xB7 ${m}`)).join("")||`<div class="ox-empty">No ${k((i?.plural??"pages").toLowerCase())} yet.</div>`)+"</section>";let d=o.flatMap(c=>a.get(c.id)??[]);return s+=lt(e,st(e,d)),s+="</div>",U(r.label,O(e,{pillar:r.id}),s)}function pt(e,t,n,r,a){let o=a&&Ee.includes(a)?a:null,i=e.ontology.pillars.find(g=>g.id===t),s=e.ontology.types.find(g=>g.id===n&&g.pillar===t);if(!i||!s)return null;let l=[...e.entities.values()].filter(g=>g.type===s.id);o&&(l=l.filter(g=>g.importance===o));let d=l.map(g=>({e:g,at:ve(e,g)})).sort((g,f)=>f.at.localeCompare(g.at)),c=50,m=Math.max(1,Math.ceil(d.length/c)),p=`/p/${encodeURIComponent(i.id)}/${encodeURIComponent(s.id)}`,w=`<div class="ox-bar">${M([{label:i.label,href:`/p/${encodeURIComponent(i.id)}`},{label:s.plural??s.label}])}${ge(3)}</div>`;if(w+=`<div class="ox-head"><div class="ox-avatar">${z(s.icon)}</div><div><h1>${k(s.plural??s.label)}</h1><p>${d.length} page${d.length===1?"":"s"}${o?` \xB7 ${k(o)} only`:""}</p></div></div>`,s.id==="event"&&(w+=`<nav class="ox-tabs">${["","major","normal","minor"].map(g=>`<a class="${(o??"")===g?"on":""}" href="${p}${g?`?importance=${g}`:""}">${g||"all"}</a>`).join("")}</nav>`),w+='<section class="ox-card" style="margin-top:16px">'+(d.slice((r-1)*c,r*c).map(({e:g,at:f})=>Z(e,g,g.type==="event"?`<span class="ox-st ${g.importance}">${g.importance}</span>`:"",`${f} \xB7 ${g.pages.map(C=>C.agentId).filter((C,x,b)=>b.indexOf(C)===x).join(", ")}`)).join("")||'<div class="ox-empty">None.</div>')+"</section>",m>1){let g=o?`importance=${o}&`:"";w+=`<div class="ox-pager">${r>1?`<a href="${p}?${g}page=${r-1}">\u2190 previous</a>`:""}<span>page ${r} of ${m}</span>${r<m?`<a href="${p}?${g}page=${r+1}">next \u2192</a>`:""}</div>`}return U(s.plural??s.label,O(e,{pillar:i.id}),w)}function ut(e,t){let n=t.trim().toLowerCase(),r=[];if(n)for(let o of e.entities.values()){let i=o.title.toLowerCase(),s=i===n?100:i.startsWith(n)?60:i.includes(n)?40:0;!s&&o.pages.some(l=>l.article.content.toLowerCase().includes(n))&&(s=10),s&&r.push({e:o,s})}r.sort((o,i)=>i.s-o.s||i.e.updated.localeCompare(o.e.updated));let a=`<div class="ox-bar">${M([{label:"Search"}])}</div>`;return a+=`<div class="ox-head"><div class="ox-avatar">${z("search")}</div><div><h1>${n?`\u201C${k(t)}\u201D`:"Search"}</h1><p>${r.length} match${r.length===1?"":"es"}</p></div></div>`,a+=`<section class="ox-card">${r.slice(0,60).map(({e:o})=>Z(e,o)).join("")||'<div class="ox-empty">No page matches.</div>'}</section>`,U(`Search: ${t}`,O(e,{}),a,"",t)}function gt(e,t,n){let r=e.ontology,a=he(e),o=`<div class="ox-bar">${M([{label:"Ontology"}])}</div>`;o+=`<div class="ox-head"><div class="ox-avatar">${z("steps")}</div><div><h1>Ontology</h1><p>${n?`Read from ${k(n)}`:"Built-in defaults. Run <code>agentx wiki ontology init</code> to write an ontology.yaml you can edit."}</p></div></div>`,t.length&&(o+=`<div class="ox-err"><b>Problems</b><ul>${t.map(i=>`<li>${k(i)}</li>`).join("")}</ul></div>`),o+=`<section class="ox-card"><div class="ox-card-h"><h2>Types</h2><span class="note">${r.types.length}</span></div>`;for(let i of r.types){let s=r.pillars.find(l=>l.id===i.pillar);o+=`<div class="ox-row"><span class="ox-ic">${z(i.icon)}</span><div class="t"><span class="l">${k(i.label)} <span class="ox-sub">${k(i.id)}</span></span><div class="ox-sub">${k(s?.label??i.pillar)} \xB7 lens: ${k((i.lens??[]).map(l=>l.title??l.panel).join(" \u2192 "))}</div></div><div class="r"><span class="ox-chip">${a.get(i.id)?.length??0}</span></div></div>`}o+=`</section><section class="ox-card" style="margin-top:16px"><div class="ox-card-h"><h2>Relations</h2><span class="note">${r.properties.length}</span></div>`;for(let i of r.properties)o+=`<div class="ox-kv"><span class="k">${k(i.id)}</span><span>${k(i.label)}${i.inverse?` \xB7 inverse: ${k(i.inverse)}`:""}${i.wikidata?` <span class="ox-sub">${k(i.wikidata)}</span>`:""}</span></div>`;return o+=`</section><section class="ox-card" style="margin-top:16px"><div class="ox-card-h"><h2>Event importance</h2></div><div class="ox-kv"><span class="k">default</span><span>${k(r.importance.default)}</span></div><div class="ox-kv"><span class="k">major set by</span><span>${k(r.importance.major_set_by)}</span></div><div class="ox-kv"><span class="k">roll-up</span><span>${r.importance.rollup.min} minor events in ${r.importance.rollup.days} days</span></div></section>`,U("Ontology",O(e,{}),o)}var ee=class{constructor(t,n){this.hub=t;this.wikiDir=n}cache=new Le;pageAt(t){if(!t.startsWith("/e/"))return null;let{ontology:n}=ce(this.wikiDir),a=this.cache.get(this.hub,n).entities.get(t.split("/").filter(Boolean)[1]??"")?.pages[0];return a?{agentId:a.agentId,path:a.article.path,title:a.article.meta.title}:null}handle(t,n){if(!(t==="/"||t===""||t.startsWith("/p/")||t.startsWith("/e/")||t==="/find"||t==="/ontology"))return null;let{ontology:r,errors:a,file:o}=ce(this.wikiDir),i=Ue(this.wikiDir,this.hub.listAgents([]),r.agent_names),s=this.cache.get(this.hub,r,i),l=Math.max(1,Number(n.get("page"))||1);if(t==="/"||t==="")return dt(s,a);if(t==="/find")return ut(s,n.get("q")??"");if(t==="/ontology")return gt(s,a,o);let d=t.split("/").filter(Boolean);if(d[0]==="p")return d.length===2?ct(s,d[1],n.get("kind")):d.length===3?pt(s,d[1],d[2],l,n.get("importance")):null;let c=s.entities.get(d[1]??"");if(!c)return null;let m={g:s,readEntries:p=>this.hub.getSharedStore().readEntries(p),versions:(p,w)=>this.hub.getAgentWiki(p).getVersions(w)};return d.length===2?qe(m,c):d.length===3?Fe(m,c,d[2],l):d.length===4&&d[2]==="s"?Ge(m,c,Number(d[3])):null}};var pn=`
|
|
183
|
+
`)}}function $r(e,t){let n=Ze(),r=n.nodeName||Gt().replace(/\.local$/,""),a=Ye(n,r);t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(a)}async function Ar(e,t){let n="";await new Promise(a=>{e.on("data",o=>{n+=o}),e.on("end",()=>a())});let r;try{r=JSON.parse(n)}catch{t.writeHead(400,{"Content-Type":"application/json"}),t.end(JSON.stringify({error:"Invalid JSON"}));return}try{let a=Yt(r);t.writeHead(200,{"Content-Type":"application/json"}),t.end(JSON.stringify(a))}catch(a){t.writeHead(400,{"Content-Type":"application/json"}),t.end(JSON.stringify({error:a.message||"wizard failed"}))}}async function Sr(e,t){t.setHeader("Content-Type","application/json");let n;try{n=Se().node?.bind||"127.0.0.1:18800"}catch(i){t.writeHead(400),t.end(JSON.stringify({ok:!1,error:`Config validation failed: ${i.message}`}));return}let r=`http://${n.replace(/^0\.0\.0\.0/,"127.0.0.1")}`;if(await Xe(r)){t.writeHead(200),t.end(JSON.stringify({ok:!0,url:r,alreadyRunning:!0}));return}let a=process.argv[1]||N(Ft(Kt(import.meta.url)),"cli.js");try{Jt(process.execPath,[a,"daemon","start"],{detached:!0,stdio:"ignore",cwd:process.cwd()}).unref()}catch(i){t.writeHead(500),t.end(JSON.stringify({ok:!1,error:`Failed to spawn daemon: ${i.message}`,manualUrl:r}));return}let o=Date.now()+12e3;for(;Date.now()<o;)if(await new Promise(i=>setTimeout(i,400)),await Xe(r)){t.writeHead(200),t.end(JSON.stringify({ok:!0,url:r,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:r}))}async function Xe(e){try{let t=await fetch(e,{method:"GET",signal:AbortSignal.timeout(800)});return t.status>0&&t.status<600}catch{return!1}}import{mkdirSync as Zt,readFileSync as en,renameSync as tn,writeFileSync as nn}from"fs";import{dirname as rn,isAbsolute as an,resolve as on}from"path";import{createHash as sn,randomBytes as ln}from"crypto";var Dr=".agentx/app-pins.json",_r=12,rt=40,at=2e3,dn=/^pin_[a-z0-9]{6,32}$/;function cn(e,t){return an(t)?t:on(e,t)}function V(e){let t=typeof e=="string"?e.trim().replace(/\s+/g," "):"";return t?/[\p{Cc}\p{Cf}]/u.test(t)?{ok:!1,error:"Use only letters, numbers, spaces and punctuation in the name."}:[...t].length>rt?{ok:!1,error:`Keep the name under ${rt} characters.`}:{ok:!0,value:t}:{ok:!1,error:"Give the button a name."}}function fe(e){let t=typeof e=="string"?e.trim():"";if(!t)return{ok:!1,error:"Give the page's address."};if(t.length>at)return{ok:!1,error:`Keep the address under ${at} characters.`};let n;try{n=new URL(t)}catch{return{ok:!1,error:"That is not a web address. It should start with https://"}}return n.protocol!=="https:"||!n.hostname?{ok:!1,error:"Only https:// pages can be pinned."}:n.username||n.password?{ok:!1,error:"Leave the user name and password out of the address."}:{ok:!0,value:n.href}}function pn(e){return`cfg_${sn("sha256").update(e).digest("hex").slice(0,12)}`}function un(e){let t=[];for(let n of e){let r=V(n.label),a=fe(n.url);!r.ok||!a.ok||t.some(o=>o.url===a.value||o.label.toLowerCase()===r.value.toLowerCase())||t.push({id:pn(a.value),label:r.value,url:a.value,source:"config"})}return t}var ot="This button is set in agentx.json (app.pins.pages). Change or remove it there.";function gn(e){let t=V(e.label);if(!t.ok)return t;let n=fe(e.url);return n.ok?{ok:!0,value:{label:t.value,url:n.value}}:n}var me=class{constructor(t,n=Date.now,r=[]){this.path=t;this.now=n;this.fixed=r}list(){return[...this.fixed,...this.load().pins.filter(t=>!this.shadowed(t))]}shadowed(t){return this.fixed.some(n=>n.url===t.url||n.label.toLowerCase()===t.label.toLowerCase())}isFixed(t){return this.fixed.some(n=>n.id===t)}load(){let t;try{t=en(this.path,"utf-8")}catch(o){return{pins:[],damaged:o?.code!=="ENOENT"}}let n;try{n=JSON.parse(t)}catch{return{pins:[],damaged:!0}}let r=Array.isArray(n?.pins)?n.pins:[],a=r.filter(o=>{let i=o;return!!i&&typeof i.id=="string"&&dn.test(i.id)&&V(i.label).ok&&fe(i.url).ok});return{pins:a,damaged:!Array.isArray(n?.pins)||a.length!==r.length}}locked(t){try{return Ee(this.path,t,{what:"The pinned pages file"})}catch(n){if(n instanceof Ie)return{ok:!1,status:409,error:n.message};throw n}}editable(){let{pins:t,damaged:n}=this.load();return n?{ok:!1,status:409,error:`The pinned pages file (${this.path}) can't be read. Fix or remove it on the computer, then try again.`}:{ok:!0,pins:t}}write(t){Zt(rn(this.path),{recursive:!0});let n=`${this.path}.${process.pid}.tmp`;nn(n,JSON.stringify({pins:t},null,2)+`
|
|
184
|
+
`,{mode:384}),tn(n,this.path)}add(t,n){return this.locked(()=>this.addUnlocked(t,n))}addUnlocked(t,n){let r=this.editable();if(!r.ok)return r;let a=r.pins;if(a.filter(i=>!this.shadowed(i)).length+this.fixed.length>=n)return{ok:!1,status:409,error:`You already have ${n} pinned pages, the most allowed (app.pins.max). Remove one first.`};if([...this.fixed,...a].some(i=>i.label.toLowerCase()===t.label.toLowerCase()))return{ok:!1,status:409,error:`You already have a button called ${t.label}.`};if(this.fixed.some(i=>i.url===t.url))return{ok:!1,status:409,error:"This page is already a button, set in agentx.json (app.pins.pages)."};let o={id:`pin_${ln(6).toString("hex")}`,...t,createdAt:new Date(this.now()).toISOString()};return a.push(o),this.write(a),{ok:!0,pin:o}}rename(t,n){return this.locked(()=>this.renameUnlocked(t,n))}renameUnlocked(t,n){if(this.isFixed(t))return{ok:!1,status:409,error:ot};let r=this.editable();if(!r.ok)return r;let a=r.pins,o=a.find(i=>i.id===t);return o?[...this.fixed,...a].some(i=>i.id!==t&&i.label.toLowerCase()===n.toLowerCase())?{ok:!1,status:409,error:`You already have a button called ${n}.`}:(o.label=n,this.write(a),{ok:!0,pin:o}):{ok:!1,status:404,error:"No such pinned page."}}remove(t){return this.locked(()=>this.removeUnlocked(t))}removeUnlocked(t){if(this.isFixed(t))return{ok:!1,status:409,error:ot};let n=this.editable();if(!n.ok)return n;let r=n.pins.filter(a=>a.id!==t);return r.length===n.pins.length?{ok:!1,status:404,error:"No such pinned page."}:(this.write(r),{ok:!0})}};function zr(e,t){let n=e.app.pins;return{store:new me(cn(t,n.file),Date.now,un(n.pages)),max:n.max}}async function Nr(e,t,n,r,a){if(n!=="/api/app/pins"&&!n.startsWith("/api/app/pins/"))return!1;let o=n.slice(13);if(r==="GET"&&o==="")return R(t,200,{pins:a.store.list(),max:a.max});if(r!=="POST")return R(t,404,{error:"not found"});let i;try{i=await Y(e,4096)}catch(l){return R(t,400,{error:l.message})}let s=typeof i.id=="string"?i.id:"";if(o==="/add"){let l=gn(i);if(!l.ok)return R(t,400,{error:l.error});let d=a.store.add(l.value,a.max);return d.ok?R(t,200,{ok:!0,pin:d.pin}):R(t,d.status,{error:d.error})}if(o==="/rename"){let l=V(i.label);if(!l.ok)return R(t,400,{error:l.error});let d=a.store.rename(s,l.value);return d.ok?R(t,200,{ok:!0,pin:d.pin}):R(t,d.status,{error:d.error})}if(o==="/remove"){let l=a.store.remove(s);return l.ok?R(t,200,{ok:!0}):R(t,l.status,{error:l.error})}return R(t,404,{error:"not found"})}function R(e,t,n){return e.writeHead(t,{"Content-Type":"application/json","Cache-Control":"no-store"}),e.end(JSON.stringify(n)),!0}import{existsSync as it,readFileSync as st}from"fs";ie();function mn(e){let t=H(e),n={};if(it(t))try{n=j(JSON.parse(st(t,"utf-8")))}catch{n={}}let r=oe.safeParse(n?.approvals);return r.success?r.data:oe.parse(void 0)}function Br(e){let t=H(e),n={};if(it(t))try{n=j(JSON.parse(st(t,"utf-8")))}catch{n={}}return Me({desk:n?.notifications?.desk,popupEnabled:!!mn(e).popup?.enabled})}function jr(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 Hr(e,t={}){return G(n=>{let r=n.approvals??={};if(e.defaultExpiryDays!==void 0&&(r.defaultExpiryDays=e.defaultExpiryDays),e.maxExpiryDays!==void 0&&(r.maxExpiryDays=e.maxExpiryDays),e.laterHours!==void 0&&(r.laterHours=e.laterHours),e.notifyAgent!==void 0&&(r.notifyAgent=e.notifyAgent),e.forwardTo===null)delete r.forwardTo;else if(e.forwardTo!==void 0){let d=Array.isArray(n.mesh?.peers)?n.mesh.peers:[];if(!d.some(c=>c.name===e.forwardTo))throw new Error(`"${e.forwardTo}" is not in mesh.peers${d.length?` (known: ${d.map(c=>c.name).join(", ")})`:""}; pair the machines first`);r.forwardTo=e.forwardTo}let a=r.digest??={};e.digestEnabled!==void 0&&(a.enabled=e.digestEnabled),e.digestTime!==void 0&&(a.time=e.digestTime),e.digestTimezone===null?delete a.timezone:e.digestTimezone!==void 0&&(a.timezone=e.digestTimezone),e.destination===null?delete a.destination:e.destination!==void 0&&(a.destination=e.destination);let o=r.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 i=r.checkin??={};if(e.checkinEnabled!==void 0&&(i.enabled=e.checkinEnabled),e.checkinTimes!==void 0&&(i.times=e.checkinTimes),e.checkinDailyAt!==void 0&&(i.dailyAt=e.checkinDailyAt),e.checkinLists!==void 0&&(i.lists=e.checkinLists),e.checkinAgent===null?delete i.agent:e.checkinAgent!==void 0&&(i.agent=e.checkinAgent),e.deskPhone!==void 0||e.deskComputer!==void 0){let d=(n.notifications??={}).desk??={};e.deskPhone!==void 0&&(d.phone=e.deskPhone),e.deskComputer!==void 0&&(d.computer=e.deskComputer)}let s=r.defaultExpiryDays??3,l=r.maxExpiryDays??30;if(s>l)throw new Error(`defaultExpiryDays (${s}) can't be more than maxExpiryDays (${l})`)},{configPath:t.configPath,reload:t.reload})}import{createServer as kn}from"http";var Q=class{peers;cache=new Map;ttl=3e4;constructor(t){this.peers=t.map(n=>({...n,url:n.url.replace(/\/$/,"")}))}async getRemoteAgents(){let t=[];return await Promise.all(this.peers.map(async n=>{try{let r=await this.fetchJson(`${n.url}/wiki/agents`);n.nodeId=r.nodeId;for(let a of r.agents||[])(a.totalEntries>0||a.totalArticles>0)&&t.push({...a,nodeId:r.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,r){try{let a=await this.fetchJson(`${t}/wiki/article?agent=${encodeURIComponent(n)}&path=${encodeURIComponent(r)}`);return{meta:{title:a.title,tags:a.tags||[],owner:a.owner,access:"public",created:a.created,lastUpdated:a.lastUpdated,sources:a.sources||[]},content:a.content,path:a.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 r=this.peers.find(i=>t.startsWith(`${i.url}/`))?.token,a=await fetch(t,{headers:r?{Authorization:`Bearer ${r}`}:{},signal:AbortSignal.timeout(5e3)});if(!a.ok)throw new Error(`HTTP ${a.status}`);let o=await a.json();return this.cache.set(t,{data:o,ts:Date.now()}),o}};var lt=864e5;function he(e){let t=new Map;for(let n of e.entities.values()){let r=t.get(n.type)??[];r.push(n),t.set(n.type,r)}return t}function ve(e,t){if(t.type==="event")return t.date||t.updated;let n=He(e,t,new Set(["event"]))[0],r=t.updated||t.date;return n&&n.date>r?n.date:r}function dt(e,t,n=Date.now()){let r=[],a=new Date(n+14*lt).toISOString().slice(0,10),o=new Date(n).toISOString().slice(0,10);for(let s of t){let l=s.statements.find(c=>c.property==="due"&&/^\d{4}-\d{2}-\d{2}/.test(c.value)),d=s.statements.some(c=>c.property==="fulfilled_by")||s.statements.some(c=>c.property==="status"&&/^(fulfilled|done|paid|filed)$/i.test(c.value));s.statements.some(c=>c.property==="status"&&/^late$/i.test(c.value))?r.push({e:s,chip:"late",why:"marked late"}):l&&!d&&l.value<o?r.push({e:s,chip:"late",why:`was due ${l.value}`}):l&&!d&&l.value<=a?r.push({e:s,chip:"due",why:`due ${l.value}`}):s.statements.some(c=>c.status==="proposed")?r.push({e:s,chip:"proposed",why:"statements wait for confirmation"}):s.type==="event"&&s.importanceProposed&&s.importanceProposed!==s.importance?r.push({e:s,chip:"proposed",why:`proposed as ${s.importanceProposed}; the owner decides`}):s.type==="event"&&s.importance==="major"&&s.date&&n-Date.parse(s.date)<=30*lt&&r.push({e:s,chip:"major",why:`major event ${s.date}`})}let i={late:0,due:1,major:2,proposed:3};return r.sort((s,l)=>i[s.chip]-i[l.chip])}function Z(e,t,n="",r){return`<div class="ox-row"><span class="ox-ic">${qe(e.ontology,t.type)}</span><div class="t"><a href="${ue(t.id)}">${w(t.title)}</a><div class="ox-sub">${w(r??`${pe(e.ontology,t.type).toLowerCase()} \xB7 ${ve(e,t)}`)}</div></div><div class="r">${n}</div></div>`}function ct(e,t){let n=t.slice(0,6).map(r=>Z(e,r.e,`<span class="ox-st ${r.chip}">${r.chip}</span>`,r.why)).join("");return`<section class="ox-card"><div class="ox-card-h"><h2>Needs attention</h2><span class="note">${t.length}</span></div>${n||'<div class="ox-empty">Nothing waits on a person.</div>'}</section>`}function fn(e){return e.length?`<div class="ox-err"><b>ontology.yaml has ${e.length} problem${e.length===1?"":"s"}</b> \u2014 the defaults are used where they apply. <a href="/ontology">See them</a></div>`:""}function pt(e,t){let n=he(e),r=`<div class="ox-bar">${M([])}</div>`;r+=`<div class="ox-head"><div class="ox-avatar">${z("home")}</div><div><h1>Wiki</h1><p>${e.entities.size} things, merged from every agent's pages and typed by the <a href="/ontology">ontology</a>. <a href="/agents">Agent wikis</a> \xB7 <a href="/entries">raw entries</a></p></div></div>`,r+=fn(t),r+='<div class="ox-grid3">';for(let o of e.ontology.pillars){let i=e.ontology.types.filter(d=>d.pillar===o.id),s=i.reduce((d,c)=>d+(n.get(c.id)?.length??0),0),l=i.filter(d=>n.get(d.id)?.length).map(d=>`${d.plural??d.label} ${n.get(d.id).length}`).join(" \xB7 ");r+=`<a class="ox-card" href="/p/${encodeURIComponent(o.id)}" style="color:inherit"><div class="ox-card-h"><span class="ox-ic">${z(o.icon)}</span><h2>${w(o.label)}</h2><span class="zin">${s}</span></div><div class="ox-sub" style="white-space:normal">${w(o.description??"")}</div><div class="ox-sub" style="margin-top:6px;white-space:normal">${w(l||"nothing yet")}</div></a>`}r+='</div><div class="ox-grid2">';let a=(n.get("event")??[]).filter(o=>o.importance!=="minor").sort((o,i)=>i.date.localeCompare(o.date)).slice(0,8);return r+='<section class="ox-card"><div class="ox-card-h"><h2>Recent events</h2><span class="note">major and normal</span><a class="zin" href="/p/events">all (Z1) \u2192</a></div>'+(a.map(o=>`<div class="ox-ev"><span class="d">${w(o.date)}</span><span class="ox-st ${o.importance}">${o.importance}</span><a href="${ue(o.id)}">${w(o.title)}</a></div>`).join("")||'<div class="ox-empty">No events yet.</div>')+"</section>",r+=ct(e,dt(e,[...e.entities.values()])),r+="</div>",U("Wiki",O(e,{home:!0}),r)}function ut(e,t,n){let r=e.ontology.pillars.find(c=>c.id===t);if(!r)return null;let a=he(e),o=e.ontology.types.filter(c=>c.pillar===r.id),i=o.find(c=>c.id===n)??o.find(c=>a.get(c.id)?.length)??o[0],s=`<div class="ox-bar">${M([{label:r.label}])}${ge(1)}</div>`;s+=`<div class="ox-head"><div class="ox-avatar">${z(r.icon)}</div><div><h1>${w(r.label)}</h1><p>${w(r.description??"")}</p></div></div>`,s+=`<nav class="ox-tabs">${o.map(c=>`<a class="${c.id===i?.id?"on":""}" href="/p/${encodeURIComponent(r.id)}?kind=${encodeURIComponent(c.id)}">${w(c.plural??c.label)}<small>${a.get(c.id)?.length??0}</small></a>`).join("")}</nav>`;let l=i?(a.get(i.id)??[]).map(c=>({e:c,at:ve(e,c)})).sort((c,f)=>f.at.localeCompare(c.at)):[];s+='<div class="ox-grid2">',s+=`<section class="ox-card"><div class="ox-card-h"><h2>${w(i?.plural??i?.label??"")}</h2><span class="note">${l.length} \xB7 most active first</span>`+(i?`<a class="zin" href="/p/${encodeURIComponent(r.id)}/${encodeURIComponent(i.id)}">open list (Z3) \u2192</a>`:"")+"</div>"+(l.slice(0,5).map(({e:c,at:f})=>Z(e,c,c.type==="event"?`<span class="ox-st ${c.importance}">${c.importance}</span>`:"",`${Fe(c,90)||pe(e.ontology,c.type).toLowerCase()} \xB7 ${f}`)).join("")||`<div class="ox-empty">No ${w((i?.plural??"pages").toLowerCase())} yet.</div>`)+"</section>";let d=o.flatMap(c=>a.get(c.id)??[]);return s+=ct(e,dt(e,d)),s+="</div>",U(r.label,O(e,{pillar:r.id}),s)}function gt(e,t,n,r,a){let o=a&&Pe.includes(a)?a:null,i=e.ontology.pillars.find(u=>u.id===t),s=e.ontology.types.find(u=>u.id===n&&u.pillar===t);if(!i||!s)return null;let l=[...e.entities.values()].filter(u=>u.type===s.id);o&&(l=l.filter(u=>u.importance===o));let d=l.map(u=>({e:u,at:ve(e,u)})).sort((u,h)=>h.at.localeCompare(u.at)),c=50,f=Math.max(1,Math.ceil(d.length/c)),g=`/p/${encodeURIComponent(i.id)}/${encodeURIComponent(s.id)}`,m=`<div class="ox-bar">${M([{label:i.label,href:`/p/${encodeURIComponent(i.id)}`},{label:s.plural??s.label}])}${ge(3)}</div>`;if(m+=`<div class="ox-head"><div class="ox-avatar">${z(s.icon)}</div><div><h1>${w(s.plural??s.label)}</h1><p>${d.length} page${d.length===1?"":"s"}${o?` \xB7 ${w(o)} only`:""}</p></div></div>`,s.id==="event"&&(m+=`<nav class="ox-tabs">${["","major","normal","minor"].map(u=>`<a class="${(o??"")===u?"on":""}" href="${g}${u?`?importance=${u}`:""}">${u||"all"}</a>`).join("")}</nav>`),m+='<section class="ox-card" style="margin-top:16px">'+(d.slice((r-1)*c,r*c).map(({e:u,at:h})=>Z(e,u,u.type==="event"?`<span class="ox-st ${u.importance}">${u.importance}</span>`:"",`${h} \xB7 ${u.pages.map(C=>C.agentId).filter((C,y,x)=>x.indexOf(C)===y).join(", ")}`)).join("")||'<div class="ox-empty">None.</div>')+"</section>",f>1){let u=o?`importance=${o}&`:"";m+=`<div class="ox-pager">${r>1?`<a href="${g}?${u}page=${r-1}">\u2190 previous</a>`:""}<span>page ${r} of ${f}</span>${r<f?`<a href="${g}?${u}page=${r+1}">next \u2192</a>`:""}</div>`}return U(s.plural??s.label,O(e,{pillar:i.id}),m)}function mt(e,t){let n=t.trim().toLowerCase(),r=[];if(n)for(let o of e.entities.values()){let i=o.title.toLowerCase(),s=i===n?100:i.startsWith(n)?60:i.includes(n)?40:0;!s&&o.pages.some(l=>l.article.content.toLowerCase().includes(n))&&(s=10),s&&r.push({e:o,s})}r.sort((o,i)=>i.s-o.s||i.e.updated.localeCompare(o.e.updated));let a=`<div class="ox-bar">${M([{label:"Search"}])}</div>`;return a+=`<div class="ox-head"><div class="ox-avatar">${z("search")}</div><div><h1>${n?`\u201C${w(t)}\u201D`:"Search"}</h1><p>${r.length} match${r.length===1?"":"es"}</p></div></div>`,a+=`<section class="ox-card">${r.slice(0,60).map(({e:o})=>Z(e,o)).join("")||'<div class="ox-empty">No page matches.</div>'}</section>`,U(`Search: ${t}`,O(e,{}),a,"",t)}function ft(e,t,n){let r=e.ontology,a=he(e),o=`<div class="ox-bar">${M([{label:"Ontology"}])}</div>`;o+=`<div class="ox-head"><div class="ox-avatar">${z("steps")}</div><div><h1>Ontology</h1><p>${n?`Read from ${w(n)}`:"Built-in defaults. Run <code>agentx wiki ontology init</code> to write an ontology.yaml you can edit."}</p></div></div>`,t.length&&(o+=`<div class="ox-err"><b>Problems</b><ul>${t.map(i=>`<li>${w(i)}</li>`).join("")}</ul></div>`),o+=`<section class="ox-card"><div class="ox-card-h"><h2>Types</h2><span class="note">${r.types.length}</span></div>`;for(let i of r.types){let s=r.pillars.find(l=>l.id===i.pillar);o+=`<div class="ox-row"><span class="ox-ic">${z(i.icon)}</span><div class="t"><span class="l">${w(i.label)} <span class="ox-sub">${w(i.id)}</span></span><div class="ox-sub">${w(s?.label??i.pillar)} \xB7 lens: ${w((i.lens??[]).map(l=>l.title??l.panel).join(" \u2192 "))}</div></div><div class="r"><span class="ox-chip">${a.get(i.id)?.length??0}</span></div></div>`}o+=`</section><section class="ox-card" style="margin-top:16px"><div class="ox-card-h"><h2>Relations</h2><span class="note">${r.properties.length}</span></div>`;for(let i of r.properties)o+=`<div class="ox-kv"><span class="k">${w(i.id)}</span><span>${w(i.label)}${i.inverse?` \xB7 inverse: ${w(i.inverse)}`:""}${i.wikidata?` <span class="ox-sub">${w(i.wikidata)}</span>`:""}</span></div>`;return o+=`</section><section class="ox-card" style="margin-top:16px"><div class="ox-card-h"><h2>Event importance</h2></div><div class="ox-kv"><span class="k">default</span><span>${w(r.importance.default)}</span></div><div class="ox-kv"><span class="k">major set by</span><span>${w(r.importance.major_set_by)}</span></div><div class="ox-kv"><span class="k">roll-up</span><span>${r.importance.rollup.min} minor events in ${r.importance.rollup.days} days</span></div></section>`,U("Ontology",O(e,{}),o)}var ee=class{constructor(t,n){this.hub=t;this.wikiDir=n}cache=new je;pageAt(t){if(!t.startsWith("/e/"))return null;let{ontology:n}=ce(this.wikiDir),a=this.cache.get(this.hub,n).entities.get(t.split("/").filter(Boolean)[1]??"")?.pages[0];return a?{agentId:a.agentId,path:a.article.path,title:a.article.meta.title}:null}handle(t,n){if(!(t==="/"||t===""||t.startsWith("/p/")||t.startsWith("/e/")||t==="/find"||t==="/ontology"))return null;let{ontology:r,errors:a,file:o}=ce(this.wikiDir),i=Be(this.wikiDir,this.hub.listAgents([]),r.agent_names),s=this.cache.get(this.hub,r,i),l=Math.max(1,Number(n.get("page"))||1);if(t==="/"||t==="")return pt(s,a);if(t==="/find")return mt(s,n.get("q")??"");if(t==="/ontology")return ft(s,a,o);let d=t.split("/").filter(Boolean);if(d[0]==="p")return d.length===2?ut(s,d[1],n.get("kind")):d.length===3?gt(s,d[1],d[2],l,n.get("importance")):null;let c=s.entities.get(d[1]??"");if(!c)return null;let f={g:s,readEntries:g=>this.hub.getSharedStore().readEntries(g),versions:(g,m)=>this.hub.getAgentWiki(g).getVersions(m)};return d.length===2?Ke(f,c):d.length===3?Ge(f,c,d[2],l):d.length===4&&d[2]==="s"?Je(f,c,Number(d[3])):null}};var hn=`
|
|
185
185
|
.wc-root{--wc-bg:#fff;--wc-ink:#1b1f1e;--wc-muted:#5d6664;--wc-edge:#d9dedc;--wc-soft:#f3f5f4;--wc-accent:#2f6fde;--wc-on-accent:#fff;--wc-add:#e6f4ea;--wc-add-ink:#1e6b34;--wc-del:#fbe9e9;--wc-del-ink:#9b2c2c;
|
|
186
186
|
font:14px/1.45 'IBM Plex Sans',system-ui,-apple-system,sans-serif;color:var(--wc-ink)}
|
|
187
187
|
[data-theme=dark] .wc-root{--wc-bg:#181c1b;--wc-ink:#e9eeec;--wc-muted:#a3adab;--wc-edge:#2c3331;--wc-soft:#1f2422;--wc-accent:#6b9cff;--wc-on-accent:#0b1020;--wc-add:#173823;--wc-add-ink:#9be3b0;--wc-del:#3b1d1d;--wc-del-ink:#f3a9a9}
|
|
@@ -220,7 +220,7 @@ ${m}
|
|
|
220
220
|
@keyframes wc-blink{0%{content:''}25%{content:'.'}50%{content:'..'}75%{content:'\u2026'}}
|
|
221
221
|
@media (max-width:600px){.wc-panel{right:8px;left:8px;bottom:80px;width:auto;max-height:calc(100vh - 100px)}.wc-fab{right:14px;bottom:14px}}
|
|
222
222
|
@media (prefers-reduced-motion:reduce){.wc-dots::after{animation:none;content:'\u2026'}}
|
|
223
|
-
`,
|
|
223
|
+
`,vn=`
|
|
224
224
|
(function(){
|
|
225
225
|
var root=document.getElementById('wc-root'); if(!root) return;
|
|
226
226
|
var cfg=JSON.parse(document.getElementById('wc-data').textContent);
|
|
@@ -288,20 +288,20 @@ ${m}
|
|
|
288
288
|
api('GET',q()).then(function(state){if(state.enabled===false)return;fab.hidden=false;
|
|
289
289
|
try{if(sessionStorage.getItem(openKey))setOpen(true)}catch(e){}}).catch(function(){});
|
|
290
290
|
})();
|
|
291
|
-
`,
|
|
291
|
+
`,bn='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 12a8 8 0 0 1-11.6 7.1L4 20l1-4.6A8 8 0 1 1 21 12z"/><path d="M12 8.5l.9 2.1 2.1.9-2.1.9-.9 2.1-.9-2.1-2.1-.9 2.1-.9z"/></svg>';function xn(e){return e.replace(/[&<>"']/g,t=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[t])}function yn(e,t="/api/wiki/curate",n){let r=JSON.stringify({agent:e.agentId,path:e.path,title:e.title,endpoint:t,...n?{token:n}:{}}).replace(/</g,"\\u003c");return`<style>${hn}</style>
|
|
292
292
|
<div class="wc-root" id="wc-root">
|
|
293
|
-
<button class="wc-fab" type="button" hidden aria-label="Ask an agent to curate this page" aria-expanded="false" aria-controls="wc-panel" title="Curate this page">${
|
|
293
|
+
<button class="wc-fab" type="button" hidden aria-label="Ask an agent to curate this page" aria-expanded="false" aria-controls="wc-panel" title="Curate this page">${bn}</button>
|
|
294
294
|
<section class="wc-panel" id="wc-panel" role="dialog" aria-label="Curate this page" hidden>
|
|
295
|
-
<div class="wc-head"><div><h2>Curate this page</h2><p class="wc-sub">${
|
|
295
|
+
<div class="wc-head"><div><h2>Curate this page</h2><p class="wc-sub">${xn(e.title)}</p></div><button class="wc-x" type="button" aria-label="Close">\xD7</button></div>
|
|
296
296
|
<div class="wc-log" aria-live="polite"></div>
|
|
297
297
|
<form class="wc-form"><textarea rows="2" aria-label="Instruction for the agent" placeholder="What should change on this page?"></textarea><button class="wc-send" type="submit">Send</button></form>
|
|
298
298
|
</section>
|
|
299
299
|
</div>
|
|
300
300
|
<script type="application/json" id="wc-data">${r}</script>
|
|
301
|
-
<script>${
|
|
302
|
-
</body>`):e+a}function
|
|
301
|
+
<script>${vn}</script>`}function ht(e,t,n,r){let a=yn(t,n,r);return e.includes("</body>")?e.replace(/<\/body>(?![\s\S]*<\/body>)/,()=>`${a}
|
|
302
|
+
</body>`):e+a}function p(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function wn(e){return e.replace(/<!--\s*tags?:[^>]*-->\s*\n?/gi,"")}function vt(e,t){return`<a href="${t?`/agent/${encodeURIComponent(t)}/tag/${encodeURIComponent(e)}`:`/tag/${encodeURIComponent(e)}`}" class="tag">${p(e)}</a>`}function W(e,t){return(e||[]).map(n=>vt(n,t)).join(" ")}function $n(e,t){if(!e)return;let n=t.get(e);if(n)return n;let r=new Set(t.values());if(r.has(e))return e;let a=e.endsWith(".md")?e:`${e}.md`;if(r.has(a))return a;let o=e.toLowerCase();for(let[i,s]of t)if(i.toLowerCase()===o)return s}function te(e,t,n=""){return Te(wn(e),{wikilink:(r,a)=>{let o=$n(r,t);return o?`<a href="${n}/article/${encodeURIComponent(o)}" class="wikilink">${a}</a>`:`<a href="${n}/search?q=${encodeURIComponent(r)}" class="wikilink broken" title="Not found \u2014 click to search">${a}</a>`}})}var An=`<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
303
303
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
304
|
-
<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">`,
|
|
304
|
+
<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">`,Sn=`
|
|
305
305
|
:root {
|
|
306
306
|
--bg: #FAF8F3;
|
|
307
307
|
--bg-raised: #FFFFFF;
|
|
@@ -773,9 +773,9 @@ tr:hover td { background: var(--bg-hover); }
|
|
|
773
773
|
<head>
|
|
774
774
|
<meta charset="utf-8">
|
|
775
775
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
776
|
-
<title>${
|
|
777
|
-
${
|
|
778
|
-
<style>${
|
|
776
|
+
<title>${p(e)} \u2014 AgentX Wiki</title>
|
|
777
|
+
${An}
|
|
778
|
+
<style>${Sn}</style>
|
|
779
779
|
<script>(function(){try{var t=localStorage.getItem('wiki-theme');if(t)document.documentElement.setAttribute('data-theme',t)}catch(e){}})();</script>
|
|
780
780
|
</head>
|
|
781
781
|
<body>
|
|
@@ -787,7 +787,7 @@ tr:hover td { background: var(--bg-hover); }
|
|
|
787
787
|
</a>
|
|
788
788
|
<form class="topbar-search" action="/search" method="get">
|
|
789
789
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="7"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
|
|
790
|
-
<input type="search" name="q" placeholder="Search every wiki\u2026" value="${
|
|
790
|
+
<input type="search" name="q" placeholder="Search every wiki\u2026" value="${p(r)}" autocomplete="off" />
|
|
791
791
|
<kbd>\u2318K</kbd>
|
|
792
792
|
</form>
|
|
793
793
|
<div class="topbar-tools">
|
|
@@ -820,43 +820,50 @@ tr:hover td { background: var(--bg-hover); }
|
|
|
820
820
|
})();
|
|
821
821
|
</script>
|
|
822
822
|
</body>
|
|
823
|
-
</html>`}function be(e){let t=new Map;for(let n of e){let r=n.path.includes("/")?n.path.split("/").slice(0,-1).join("/"):"/",a=t.get(r)||[];a.push(n),t.set(r,a)}return new Map([...t].sort((n,r)=>n[0].localeCompare(r[0])))}function xe(e){return e==="/"?"Root":e.split("/").pop().replace(/-/g," ")}function T(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 r of e){let a=`/agent/${encodeURIComponent(r.agentId)}`;n+='<div class="nav-section">',n+=`<a class="nav-agent-header" href="${a}">`,n+=`<span class="name">${
|
|
823
|
+
</html>`}function be(e){let t=new Map;for(let n of e){let r=n.path.includes("/")?n.path.split("/").slice(0,-1).join("/"):"/",a=t.get(r)||[];a.push(n),t.set(r,a)}return new Map([...t].sort((n,r)=>n[0].localeCompare(r[0])))}function xe(e){return e==="/"?"Root":e.split("/").pop().replace(/-/g," ")}function T(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 r of e){let a=`/agent/${encodeURIComponent(r.agentId)}`;n+='<div class="nav-section">',n+=`<a class="nav-agent-header" href="${a}">`,n+=`<span class="name">${p(r.agentId)}</span>`,n+=`<span class="badge">${r.totalArticles}</span>`,n+="</a>",n+='<div class="nav-agent-children">';let o=be(r.articles);for(let[i,s]of o){n+=`<div class="nav-agent-type-label">${xe(i)}</div>`;for(let l of s){let c=`${r.agentId}/${l.path}`===t;n+=`<a class="nav-item${c?" active":""}" href="${a}/article/${encodeURIComponent(l.path)}">${p(l.title)}</a>`}}n+="</div>",n+="</div>"}return n}function Cn(e,t,n){let r=t||e.summary(),o=e.getSharedStore().listEntries().length,i=r.reduce((c,f)=>c+f.totalArticles,0),s=r.reduce((c,f)=>c+f.unabsorbed,0),l=new Set((n||[]).map(c=>c.agentId)),d=`<div class="page-head">
|
|
824
824
|
<div>
|
|
825
825
|
<h1>AgentX Wiki</h1>
|
|
826
826
|
<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>
|
|
827
827
|
</div>
|
|
828
|
-
</div>`;if(d+='<div class="stat-strip">',d+=`<div class="stat-cell"><div class="label">Agents</div><div class="number">${r.length}</div></div>`,d+=`<div class="stat-cell"><div class="label">Articles</div><div class="number">${i}</div></div>`,d+=`<div class="stat-cell"><div class="label">Raw entries</div><div class="number">${o}</div></div>`,s>0&&(d+=`<div class="stat-cell"><div class="label">Unabsorbed</div><div class="number">${s}</div></div>`),n&&n.length>0){let c=new Set(n.map(
|
|
828
|
+
</div>`;if(d+='<div class="stat-strip">',d+=`<div class="stat-cell"><div class="label">Agents</div><div class="number">${r.length}</div></div>`,d+=`<div class="stat-cell"><div class="label">Articles</div><div class="number">${i}</div></div>`,d+=`<div class="stat-cell"><div class="label">Raw entries</div><div class="number">${o}</div></div>`,s>0&&(d+=`<div class="stat-cell"><div class="label">Unabsorbed</div><div class="number">${s}</div></div>`),n&&n.length>0){let c=new Set(n.map(f=>f.nodeId));d+=`<div class="stat-cell"><div class="label">Mesh nodes</div><div class="number">${c.size}</div></div>`}d+="</div>",d+='<div class="section-head"><h2>Agent wikis</h2></div>',d+='<div class="agent-grid">';for(let c of r){let f=c.unabsorbed>0?`<span class="tag" style="color:var(--warn);background:color-mix(in oklch, var(--warn) 12%, transparent)">${c.unabsorbed} unabsorbed</span>`:'<span class="tag" style="color:var(--ok);background:color-mix(in oklch, var(--ok) 12%, transparent)">up to date</span>',m=l.has(c.agentId)&&!e.listAgents().includes(c.agentId)?' <span class="tag" style="color:var(--cool);background:var(--cool-soft)">remote</span>':"";if(d+='<div class="agent-card">',d+=`<h3><a href="/agent/${encodeURIComponent(c.agentId)}">${p(c.agentId)}</a>${m}</h3>`,d+=`<div class="agent-stats">
|
|
829
829
|
<span><strong>${c.totalArticles}</strong> articles</span>
|
|
830
830
|
<span><strong>${c.totalEntries}</strong> entries</span>
|
|
831
|
-
${
|
|
832
|
-
</div>`,c.articles.length>0){d+='<div class="article-list">';for(let
|
|
833
|
-
<div class="meta-line">${
|
|
834
|
-
<p>${
|
|
835
|
-
</div>`}let
|
|
836
|
-
<span class="kind">${
|
|
837
|
-
<span class="article">${
|
|
838
|
-
<span class="msg">${
|
|
839
|
-
</div>`;l+="</div>"}return S(t,T(r,t),l)}function
|
|
831
|
+
${f}
|
|
832
|
+
</div>`,c.articles.length>0){d+='<div class="article-list">';for(let u of c.articles.slice(0,6)){let h=W((u.tags||[]).slice(0,2),c.agentId);d+=`<div class="article-row">${h} <a class="article-title" href="/agent/${encodeURIComponent(c.agentId)}/article/${encodeURIComponent(u.path)}">${p(u.title)}</a></div>`}c.articles.length>6&&(d+=`<div class="article-row"><a class="article-title" style="color:var(--muted)" href="/agent/${encodeURIComponent(c.agentId)}">+ ${c.articles.length-6} more \u2192</a></div>`),d+="</div>"}d+="</div>"}return d+="</div>",S("Hub",T(r),d)}function In(e,t,n){let r=n||e.summary(),a=r.find(g=>g.agentId===t);if(!a)return S("Not Found",T(r),"<h1>Agent not found</h1>");let o=a.peerUrl!==void 0,i=e.getAgentEntries(t),s=a.articles||[],l=`<nav class="breadcrumb"><a href="/">Hub</a> <span class="sep">/</span> <span class="current">${p(t)}</span></nav>`;if(l+=`<div class="page-head"><div><h1>${p(t)}</h1>`,o&&(l+=`<p class="page-sub"><span class="tag" style="color:var(--cool);background:var(--cool-soft)">remote @ ${p(a.nodeId)}</span></p>`),l+="</div></div>",l+='<div class="stat-strip">',l+=`<div class="stat-cell"><div class="label">Articles</div><div class="number">${a.totalArticles}</div></div>`,l+=`<div class="stat-cell"><div class="label">Entries</div><div class="number">${a.totalEntries}</div></div>`,l+=`<div class="stat-cell"><div class="label">Unabsorbed</div><div class="number">${a.unabsorbed}</div></div>`,l+="</div>",s.length>0){l+='<div class="section-head"><h2>Articles</h2><span class="mono" style="font-size:12px;color:var(--muted)">'+s.length+" total</span></div>";let g=be(s);for(let[m,u]of g){l+=`<h3 class="display" style="font-size:17px;color:var(--muted);font-weight:500;margin:20px 0 8px">${xe(m)}</h3>`,l+='<div class="agent-card" style="padding:4px 14px"><div class="article-list">';for(let h of u)l+=`<div class="article-row">${W((h.tags||[]).slice(0,3),t)} <a class="article-title" href="/agent/${encodeURIComponent(t)}/article/${encodeURIComponent(h.path)}">${p(h.title)}</a></div>`;l+="</div></div>"}}let d=i.slice(-5).reverse();if(d.length>0){l+='<div class="section-head"><h2>Recent entries</h2><a class="btn ghost" href="/entries">See all \u2192</a></div>';for(let g of d)l+=`<div class="entry-card">
|
|
833
|
+
<div class="meta-line">${g.date} \xB7 via ${p(g.source)} \xB7 <code>${p(g.id)}</code></div>
|
|
834
|
+
<p>${p(g.content.slice(0,300))}${g.content.length>300?"\u2026":""}</p>
|
|
835
|
+
</div>`}let f=e.getAgentWiki(t).lint();if(f.length>0){l+=`<div class="section-head"><h2>Health issues</h2><span class="mono" style="font-size:12px;color:var(--warn)">${f.length}</span></div>`,l+='<div class="health-list">';for(let g of f)l+=`<div class="health-row">
|
|
836
|
+
<span class="kind">${p(g.type)}</span>
|
|
837
|
+
<span class="article">${p(g.article)}</span>
|
|
838
|
+
<span class="msg">${p(g.message)}</span>
|
|
839
|
+
</div>`;l+="</div>"}return S(t,T(r,t),l)}function En(e,t,n,r){let a=e.getAgentWiki(t),o=a.readArticle(n);if(!o)return null;let i=r||e.summary(),s=a.rebuildIndex(),l=new Map;for(let m of s.articles)l.set(m.title,m.path);let d=`/agent/${encodeURIComponent(t)}`,f=a.buildBacklinks()[o.meta.title]||[],g=`<nav class="breadcrumb"><a href="/">Hub</a> <span class="sep">/</span> <a href="${d}">${p(t)}</a> <span class="sep">/</span> <span class="current">${p(o.meta.title)}</span></nav>`;if(g+=`<article class="prose"><h1>${p(o.meta.title)}</h1>`,g+='<dl class="meta">',o.meta.type&&(g+=`<dt>Type</dt><dd>${vt(o.meta.type,t)}</dd>`),o.meta.tags?.length&&(g+=`<dt>Tags</dt><dd>${W(o.meta.tags,t)}</dd>`),o.meta.owner&&(g+=`<dt>Owner</dt><dd>${p(o.meta.owner)}</dd>`),g+=`<dt>Created</dt><dd>${p(o.meta.created||"\u2014")}</dd>`,g+=`<dt>Updated</dt><dd>${p(o.meta.lastUpdated||"\u2014")}</dd>`,o.meta.sources?.length&&(g+=`<dt>Sources</dt><dd>${o.meta.sources.length} entries</dd>`),g+="</dl>",g+=te(o.content,l,d),f.length>0){g+='<div class="backlinks"><h4>Pages that link here</h4><ul>';for(let m of f){let u=a.readArticle(m);g+=`<li><a href="${d}/article/${encodeURIComponent(m)}">${p(u?.meta.title||m)}</a></li>`}g+="</ul></div>"}return g+="</article>",S(o.meta.title,T(i,`${t}/${n}`),g)}function Pn(e,t){let n=t||e.summary(),a=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 i=new Map;for(let s of a){let l=i.get(s.date)||[];l.push(s),i.set(s.date,l)}for(let[s,l]of[...i].reverse()){o+=`<div class="section-head"><h2>${s}</h2><span class="mono" style="font-size:12px;color:var(--muted)">${l.length} entries</span></div>`;for(let d of l)o+=`<div class="entry-card">
|
|
840
840
|
<div class="meta-line">
|
|
841
|
-
<a href="/agent/${encodeURIComponent(d.agentId)}">${
|
|
842
|
-
\xB7 via ${
|
|
841
|
+
<a href="/agent/${encodeURIComponent(d.agentId)}">${p(d.agentId)}</a>
|
|
842
|
+
\xB7 via ${p(d.source)} \xB7 <code>${p(d.id)}</code>
|
|
843
843
|
</div>
|
|
844
|
-
<p>${
|
|
845
|
-
</div>`}return S("All Entries",T(n),o)}function
|
|
846
|
-
<div class="meta-line">${
|
|
847
|
-
<h3><a href="${
|
|
848
|
-
<p>${
|
|
849
|
-
</div>`)}o+=d.length}}return a+=i.join(""),o===0&&(a+='<p style="color:var(--muted);margin-top:24px">No matching articles found.</p>'),S(`Search: ${t}`,T(r),a,t)}function
|
|
850
|
-
<div class="meta-line">${
|
|
851
|
-
<h3><a href="${c}/article/${encodeURIComponent(d.path)}">${
|
|
852
|
-
</div>`}o+=l.length}}return o===0&&(a+=`<p style="color:var(--muted);margin-top:24px">No articles tagged <code>${
|
|
853
|
-
<div class="meta-line">${
|
|
854
|
-
<h3><a href="${s}/article/${encodeURIComponent(d.path)}">${
|
|
855
|
-
</div>`;return S(`${t} \xB7 ${n}`,T(a),l)}function L(e,t,n){let r=e.rebuildIndex(),a=be(r.articles.map(i=>({title:i.title,path:i.path,tags:i.tags}))),o='<div class="nav-section">';o+=`<div class="nav-section-title">${u(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[i,s]of a){o+='<div class="nav-section">',o+=`<div class="nav-section-title">${xe(i)}</div>`;for(let l of s){let d=l.path===n;o+=`<a class="nav-item${d?" active":""}" href="/article/${encodeURIComponent(l.path)}">${u(l.title)}</a>`}o+="</div>"}return o}function En(e){let{wikiDir:t,agentFilter:n,peers:r=[],mode:a="graph",pathPrefix:o=""}=e,i=o.replace(/\/+$/,""),s=new Pe(t,void 0,a),l=new ee(s,t),d=r.length>0?new Q(r):null;return async(c,m)=>{let p=new URL(c.url||"/","http://localhost"),w=decodeURIComponent(p.pathname),g=i&&w.startsWith(i)?w.slice(i.length)||"/":w,f=null,C=200;try{if(g.startsWith("/remote/")&&d){let x=g.slice(8).split("/article/");if(x.length===2){let[b,v]=x,h=b.indexOf("/"),$=decodeURIComponent(b.slice(0,h)),y=b.slice(h+1),A=await d.getRemoteArticle($,y,v);if(A){let _=await d.getRemoteAgents(),G=[...s.summary(),..._.map(E=>({...E,agentId:`${E.agentId} @${E.nodeId}`}))],I=`<div class="breadcrumb"><a href="/">Hub</a> / <span class="tag">remote</span> ${u(y)} @ ${u($)}</div>`;I+=`<h1>${u(A.meta.title)}</h1>`,I+='<dl class="meta">',I+=`<dt>Tags</dt><dd>${(A.meta.tags||[]).map(E=>`<span class="tag">${E}</span>`).join(" ")}</dd>`,I+=`<dt>Owner</dt><dd>${u(A.meta.owner)}</dd>`,I+=`<dt>Source</dt><dd><span class="tag">remote</span> ${u($)}</dd>`,I+=`<dt>Updated</dt><dd>${A.meta.lastUpdated}</dd>`,I+="</dl>";let D=new Map;I+=te(A.content,D),f=S(A.meta.title,T(G),I)}}}if(!f&&n){let x=s.getAgentWiki(n);if(g==="/"||g===""){let b=x.rebuildIndex(),v=s.getAgentEntries(n),h=`<h1>${u(n)}</h1>`;if(h+='<div class="stats">',h+=`<div class="stat-card"><div class="number">${b.articles.length}</div><div class="label">Articles</div></div>`,h+=`<div class="stat-card"><div class="number">${v.length}</div><div class="label">Entries</div></div>`,h+="</div>",b.articles.length>0){h+="<h2>Articles</h2><table><tr><th>Title</th><th>Type</th><th>Updated</th></tr>";for(let $ of b.articles)h+=`<tr><td><a href="/article/${encodeURIComponent($.path)}">${u($.title)}</a></td><td><span class="tag">${($.tags||[]).slice(0,3).join(", ")}</span></td><td>${$.lastUpdated||""}</td></tr>`;h+="</table>"}f=S(n,L(x,n),h)}else if(g.startsWith("/article/")){let b=g.slice(9),v=x.readArticle(b);if(v){let h=x.rebuildIndex(),$=new Map;for(let A of h.articles)$.set(A.title,A.path);let y=`<h1>${u(v.meta.title)}</h1>`;y+='<dl class="meta">',y+=`<dt>Tags</dt><dd>${(v.meta.tags||[]).map(A=>`<span class="tag">${A}</span>`).join(" ")}</dd>`,y+=`<dt>Updated</dt><dd>${v.meta.lastUpdated}</dd>`,v.meta.sources?.length&&(y+=`<dt>Sources</dt><dd>${v.meta.sources.length} entries</dd>`),y+="</dl>",y+=te(v.content,$),f=S(v.meta.title,L(x,n,b),y)}}else if(g==="/lint"){let b=x.lint(),v="<h1>Health Check</h1>";if(b.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 h of b)v+=`<tr><td><span class="tag">${h.type}</span></td><td>${u(h.article)}</td><td>${u(h.message)}</td></tr>`;v+="</table>"}f=S("Health Check",L(x,n),v)}else if(g==="/search"){let b=p.searchParams.get("q")||"",v=await x.findRelevantReranked(b,void 0,20),h=`<h1>Search: "${u(b)}"</h1>`;for(let $ of v)h+=`<div class="entry-card"><h3><a href="/article/${encodeURIComponent($.path)}">${u($.meta.title)}</a></h3><p>${u($.content.slice(0,200))}...</p></div>`;v.length===0&&(h+="<p>No results.</p>"),f=S(`Search: ${b}`,L(x,n),h)}else if(g.startsWith("/tag/")){let b=decodeURIComponent(g.slice(5)),v=x.findByTags([b],void 0,100),h=`<h1>Tag: <a class="tag" href="#">${u(b)}</a></h1>`;h+=`<p>${v.length} article${v.length===1?"":"s"} tagged <code>${u(b)}</code></p>`;for(let $ of v)h+=`<div class="entry-card"><h3><a href="/article/${encodeURIComponent($.path)}">${u($.meta.title)}</a></h3><div class="meta-line">${N(($.meta.tags||[]).slice(0,6))}</div></div>`;v.length===0&&(h+="<p>No articles with this tag.</p>"),f=S(`Tag: ${b}`,L(x,n),h)}}else if(!f&&(f=l.handle(g,p.searchParams))===null){let x=d?await d.getRemoteAgents():[],b=s.summary(),v=new Map(b.map(y=>[y.agentId,y])),h=[],$=new Set;for(let y of b){let A=x.find(_=>_.agentId===y.agentId);A&&A.totalArticles>y.totalArticles?h.push({...A,totalEntries:Math.max(y.totalEntries,A.totalEntries),unabsorbed:Math.max(y.unabsorbed,A.unabsorbed)}):h.push(y),$.add(y.agentId)}for(let y of x)$.has(y.agentId)||(h.push(y),$.add(y.agentId));if(g==="/agents")f=kn(s,h,x);else if(g==="/entries")f=An(s,h);else if(g==="/search")f=Sn(s,p.searchParams.get("q")||"",h);else if(g.startsWith("/tag/"))f=Cn(s,decodeURIComponent(g.slice(5)),h);else if(g.match(/^\/agent\/[^/]+\/tag\/.+/)){let y=g.match(/^\/agent\/([^/]+)\/tag\/(.+)$/);f=In(s,decodeURIComponent(y[1]),decodeURIComponent(y[2]),h)}else if(g.startsWith("/agent/")){let y=g.slice(7),A=y.indexOf("/article/");if(A===-1)f=wn(s,y,h);else{let _=y.slice(0,A),G=y.slice(A+9);if(f=$n(s,_,G,h),!f&&d){let I=x.find(D=>D.agentId===_);if(I){let D=await d.getRemoteArticle(I.peerUrl,_,G);if(D){let E=`<div class="breadcrumb"><a href="/">Hub</a> / <span class="tag">remote @ ${u(I.nodeId)}</span> / ${u(_)}</div>`;E+=`<h1>${u(D.meta.title)}</h1>`,E+='<dl class="meta">',E+=`<dt>Tags</dt><dd>${(D.meta.tags||[]).map(_t=>`<span class="tag">${_t}</span>`).join(" ")}</dd>`,E+=`<dt>Source</dt><dd><span class="tag">remote</span> ${u(I.nodeId)}</dd>`,E+=`<dt>Updated</dt><dd>${D.meta.lastUpdated}</dd>`,E+="</dl>",E+=te(D.content,new Map),f=S(D.meta.title,T(h),E)}}}}}}if(!f){C=404;let x=n?L(s.getAgentWiki(n),n):T(s.summary());f=S("Not Found",x,"<h1>Page not found</h1>")}}catch(x){C=500,f=S("Error","",`<h1>Error</h1><pre>${u(x.message)}</pre>`)}if(C===200&&e.curator){let x=Pn(s,l,g,n);x&&(f=mt(f,x,e.curatorEndpoint,e.curatorToken?.()))}m.writeHead(C,{"Content-Type":"text/html; charset=utf-8"}),m.end(i?Rn(f,i):f)}}function Pn(e,t,n,r){let a,o;if(r&&n.startsWith("/article/"))a=r,o=n.slice(9);else if(!r&&n.startsWith("/agent/")){let l=n.match(/^\/agent\/([^/]+)\/article\/(.+)$/);l&&(a=l[1],o=l[2])}else if(!r)return t.pageAt(n);if(!a||!o||!e.listAgents([]).includes(a))return null;let i=e.getAgentWiki(a);if(!ze(i.baseDir,o))return null;let s=i.readArticle(o);return s?{agentId:a,path:o,title:s.meta.title}:null}function Rn(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 ea(e,t=4200,n,r=[],a="graph"){let o=En({wikiDir:e,agentFilter:n,peers:r,mode:a});hn((s,l)=>{o(s,l)}).listen(t)}import{existsSync as Tn,readFileSync as Dn}from"fs";ie();function ia(e){let t=H(e),n={};if(Tn(t))try{n=j(JSON.parse(Dn(t,"utf-8")))}catch{n={}}let r=n?.workflows?.required??{},a={};for(let[o,i]of Object.entries(r.agents??{}))typeof i=="boolean"&&(a[o]=i);return{enabled:typeof r.enabled=="boolean"?r.enabled:J.enabled,agents:a,exemptQuestions:typeof r.exemptQuestions=="boolean"?r.exemptQuestions:J.exemptQuestions,retentionDays:Number.isInteger(r.retentionDays)&&r.retentionDays>=0?r.retentionDays:J.retentionDays,engine:n?.workflows?.enabled===!0}}async function sa(e,t={}){return e.retentionDays!==void 0&&!(Number.isInteger(e.retentionDays)&&e.retentionDays>=0&&e.retentionDays<=3650)?{success:!1,error:"retentionDays is a whole number of days from 0 to 3650"}:e.agent&&!/^[A-Za-z0-9_.@-]{1,80}$/.test(e.agent.id)?{success:!1,error:`"${e.agent.id}" is not an agent id`}:K(n=>{let r=n.workflows??={},a=r.required??={};if(e.enabled!==void 0&&(a.enabled=e.enabled),e.exemptQuestions!==void 0&&(a.exemptQuestions=e.exemptQuestions),e.retentionDays!==void 0&&(a.retentionDays=e.retentionDays),e.agent){let o=a.agents??={};e.agent.value===null?delete o[e.agent.id]:o[e.agent.id]=e.agent.value}(e.enabled===!0||e.agent?.value===!0)&&(r.enabled=!0)},{configPath:t.configPath,reload:t.reload})}import{existsSync as wt,readdirSync as Wn}from"fs";import{join as $t}from"path";import{join as _n}from"path";function ht(e){return/^[\w@%+=:,./-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function B(e){return(t,n)=>`cd ${ht(n)} && npx -y skills add ${ht(t)} -a ${e} -y`}var ne={tier:"claude-code",skillDirs:e=>[_n(e,".claude","skills")],addSkillCommand:B("claude-code"),instructionsFile:"CLAUDE.md"};import{join as zn}from"path";var vt={tier:"codex-cli",skillDirs:e=>[zn(e,".agents","skills")],addSkillCommand:B("codex"),instructionsFile:"AGENTS.md"};import{join as ye}from"path";var bt={tier:"opencode",skillDirs:e=>[ye(e,".agents","skills"),ye(e,".opencode","skills"),ye(e,".claude","skills")],addSkillCommand:B("opencode"),instructionsFile:"AGENTS.md"};import{join as ke}from"path";var xt=e=>({...ne,tier:e,skillDirs:t=>[ke(t,".claude","skills"),ke(t,".skills"),ke(t,"skills")]}),yt=xt("sdk"),kt=xt("orchestrator");var Nn={"claude-code":ne,"codex-cli":vt,opencode:bt,sdk:yt,orchestrator:kt};function At(e){return Nn[e??"claude-code"]??null}function Ea(e,t){return At(e)?.skillDirs(t)[0]??null}function Pa(e,t){let n=new Map;for(let r of At(e)?.skillDirs(t)??[])if(wt(r))for(let a of Wn(r))a.startsWith(".")||n.has(a)||wt($t(r,a,"SKILL.md"))&&n.set(a,$t(r,a));return[...n].map(([r,a])=>({name:r,dir:a})).sort((r,a)=>r.name.localeCompare(a.name))}zt();function Da(e,t,n=20){return e.prepare(`SELECT task_id, agent_id, channel, chat_id, status, started_at, finished_at, message_preview
|
|
844
|
+
<p>${p(d.content.slice(0,400))}${d.content.length>400?"\u2026":""}</p>
|
|
845
|
+
</div>`}return S("All Entries",T(n),o)}function Rn(e,t,n){let r=n||e.summary(),a='<nav class="breadcrumb"><a href="/">Hub</a> <span class="sep">/</span> <span class="current">Search</span></nav>';a+=`<div class="page-head"><div><h1>\u201C${p(t)}\u201D</h1><p class="page-sub">Full-text search across every agent's wiki.</p></div></div>`;let o=0,i=[];for(let s of r){let d=e.getAgentWiki(s.agentId).findRelevant(t,void 0,10);if(d.length>0){i.push(`<div class="section-head"><h2>${p(s.agentId)}</h2><span class="mono" style="font-size:12px;color:var(--muted)">${d.length} match${d.length===1?"":"es"}</span></div>`);for(let c of d){let f=`/agent/${encodeURIComponent(s.agentId)}`;i.push(`<div class="entry-card">
|
|
846
|
+
<div class="meta-line">${W((c.meta.tags||[]).slice(0,3),s.agentId)}</div>
|
|
847
|
+
<h3><a href="${f}/article/${encodeURIComponent(c.path)}">${p(c.meta.title)}</a></h3>
|
|
848
|
+
<p>${p(c.content.slice(0,240))}\u2026</p>
|
|
849
|
+
</div>`)}o+=d.length}}return a+=i.join(""),o===0&&(a+='<p style="color:var(--muted);margin-top:24px">No matching articles found.</p>'),S(`Search: ${t}`,T(r),a,t)}function Tn(e,t,n){let r=n||e.summary(),a='<nav class="breadcrumb"><a href="/">Hub</a> <span class="sep">/</span> <span class="current">Tag</span></nav>';a+=`<div class="page-head"><div><h1>${p(t)}</h1><p class="page-sub">All articles tagged <span class="tag">${p(t)}</span>, across every agent.</p></div></div>`;let o=0;for(let i of r){let s;try{s=e.getAgentWiki(i.agentId)}catch{continue}let l=s.findByTags([t],void 0,100);if(l.length!==0){a+=`<div class="section-head"><h2>${p(i.agentId)}</h2><span class="mono" style="font-size:12px;color:var(--muted)">${l.length}</span></div>`;for(let d of l){let c=`/agent/${encodeURIComponent(i.agentId)}`;a+=`<div class="entry-card">
|
|
850
|
+
<div class="meta-line">${W((d.meta.tags||[]).slice(0,6),i.agentId)}</div>
|
|
851
|
+
<h3><a href="${c}/article/${encodeURIComponent(d.path)}">${p(d.meta.title)}</a></h3>
|
|
852
|
+
</div>`}o+=l.length}}return o===0&&(a+=`<p style="color:var(--muted);margin-top:24px">No articles tagged <code>${p(t)}</code>.</p>`),S(`Tag: ${t}`,T(r),a)}function Dn(e,t,n,r){let a=r||e.summary(),o;try{o=e.getAgentWiki(t)}catch{return S(`Tag: ${n}`,T(a),`<h1>Agent not found: ${p(t)}</h1>`)}let i=o.findByTags([n],void 0,100),s=`/agent/${encodeURIComponent(t)}`,l=`<nav class="breadcrumb"><a href="/">Hub</a> <span class="sep">/</span> <a href="${s}">${p(t)}</a> <span class="sep">/</span> <span class="current">${p(n)}</span></nav>`;l+=`<div class="page-head"><div><h1>${p(n)}</h1><p class="page-sub">${i.length} article${i.length===1?"":"s"} tagged <code>${p(n)}</code> in <b>${p(t)}</b>.</p></div></div>`;for(let d of i)l+=`<div class="entry-card">
|
|
853
|
+
<div class="meta-line">${W((d.meta.tags||[]).slice(0,6),t)}</div>
|
|
854
|
+
<h3><a href="${s}/article/${encodeURIComponent(d.path)}">${p(d.meta.title)}</a></h3>
|
|
855
|
+
</div>`;return S(`${t} \xB7 ${n}`,T(a),l)}function L(e,t,n){let r=e.rebuildIndex(),a=be(r.articles.map(i=>({title:i.title,path:i.path,tags:i.tags}))),o='<div class="nav-section">';o+=`<div class="nav-section-title">${p(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[i,s]of a){o+='<div class="nav-section">',o+=`<div class="nav-section-title">${xe(i)}</div>`;for(let l of s){let d=l.path===n;o+=`<a class="nav-item${d?" active":""}" href="/article/${encodeURIComponent(l.path)}">${p(l.title)}</a>`}o+="</div>"}return o}function _n(e){let{wikiDir:t,agentFilter:n,peers:r=[],mode:a="graph",pathPrefix:o=""}=e,i=o.replace(/\/+$/,""),s=new Re(t,void 0,a),l=new ee(s,t),d=r.length>0?new Q(r):null;return async(c,f)=>{let g=new URL(c.url||"/","http://localhost"),m=decodeURIComponent(g.pathname),u=i&&m.startsWith(i)?m.slice(i.length)||"/":m,h=null,C=200;try{if(u.startsWith("/remote/")&&d){let y=u.slice(8).split("/article/");if(y.length===2){let[x,b]=y,v=x.indexOf("/"),$=decodeURIComponent(x.slice(0,v)),k=x.slice(v+1),A=await d.getRemoteArticle($,k,b);if(A){let _=await d.getRemoteAgents(),K=[...s.summary(),..._.map(E=>({...E,agentId:`${E.agentId} @${E.nodeId}`}))],I=`<div class="breadcrumb"><a href="/">Hub</a> / <span class="tag">remote</span> ${p(k)} @ ${p($)}</div>`;I+=`<h1>${p(A.meta.title)}</h1>`,I+='<dl class="meta">',I+=`<dt>Tags</dt><dd>${(A.meta.tags||[]).map(E=>`<span class="tag">${E}</span>`).join(" ")}</dd>`,I+=`<dt>Owner</dt><dd>${p(A.meta.owner)}</dd>`,I+=`<dt>Source</dt><dd><span class="tag">remote</span> ${p($)}</dd>`,I+=`<dt>Updated</dt><dd>${A.meta.lastUpdated}</dd>`,I+="</dl>";let D=new Map;I+=te(A.content,D),h=S(A.meta.title,T(K),I)}}}if(!h&&n){let y=s.getAgentWiki(n);if(u==="/"||u===""){let x=y.rebuildIndex(),b=s.getAgentEntries(n),v=`<h1>${p(n)}</h1>`;if(v+='<div class="stats">',v+=`<div class="stat-card"><div class="number">${x.articles.length}</div><div class="label">Articles</div></div>`,v+=`<div class="stat-card"><div class="number">${b.length}</div><div class="label">Entries</div></div>`,v+="</div>",x.articles.length>0){v+="<h2>Articles</h2><table><tr><th>Title</th><th>Type</th><th>Updated</th></tr>";for(let $ of x.articles)v+=`<tr><td><a href="/article/${encodeURIComponent($.path)}">${p($.title)}</a></td><td><span class="tag">${($.tags||[]).slice(0,3).join(", ")}</span></td><td>${$.lastUpdated||""}</td></tr>`;v+="</table>"}h=S(n,L(y,n),v)}else if(u.startsWith("/article/")){let x=u.slice(9),b=y.readArticle(x);if(b){let v=y.rebuildIndex(),$=new Map;for(let A of v.articles)$.set(A.title,A.path);let k=`<h1>${p(b.meta.title)}</h1>`;k+='<dl class="meta">',k+=`<dt>Tags</dt><dd>${(b.meta.tags||[]).map(A=>`<span class="tag">${A}</span>`).join(" ")}</dd>`,k+=`<dt>Updated</dt><dd>${b.meta.lastUpdated}</dd>`,b.meta.sources?.length&&(k+=`<dt>Sources</dt><dd>${b.meta.sources.length} entries</dd>`),k+="</dl>",k+=te(b.content,$),h=S(b.meta.title,L(y,n,x),k)}}else if(u==="/lint"){let x=y.lint(),b="<h1>Health Check</h1>";if(x.length===0)b+='<p style="color:green;">No issues.</p>';else{b+="<table><tr><th>Type</th><th>Article</th><th>Issue</th></tr>";for(let v of x)b+=`<tr><td><span class="tag">${v.type}</span></td><td>${p(v.article)}</td><td>${p(v.message)}</td></tr>`;b+="</table>"}h=S("Health Check",L(y,n),b)}else if(u==="/search"){let x=g.searchParams.get("q")||"",b=await y.findRelevantReranked(x,void 0,20),v=`<h1>Search: "${p(x)}"</h1>`;for(let $ of b)v+=`<div class="entry-card"><h3><a href="/article/${encodeURIComponent($.path)}">${p($.meta.title)}</a></h3><p>${p($.content.slice(0,200))}...</p></div>`;b.length===0&&(v+="<p>No results.</p>"),h=S(`Search: ${x}`,L(y,n),v)}else if(u.startsWith("/tag/")){let x=decodeURIComponent(u.slice(5)),b=y.findByTags([x],void 0,100),v=`<h1>Tag: <a class="tag" href="#">${p(x)}</a></h1>`;v+=`<p>${b.length} article${b.length===1?"":"s"} tagged <code>${p(x)}</code></p>`;for(let $ of b)v+=`<div class="entry-card"><h3><a href="/article/${encodeURIComponent($.path)}">${p($.meta.title)}</a></h3><div class="meta-line">${W(($.meta.tags||[]).slice(0,6))}</div></div>`;b.length===0&&(v+="<p>No articles with this tag.</p>"),h=S(`Tag: ${x}`,L(y,n),v)}}else if(!h&&(h=l.handle(u,g.searchParams))===null){let y=d?await d.getRemoteAgents():[],x=s.summary(),b=new Map(x.map(k=>[k.agentId,k])),v=[],$=new Set;for(let k of x){let A=y.find(_=>_.agentId===k.agentId);A&&A.totalArticles>k.totalArticles?v.push({...A,totalEntries:Math.max(k.totalEntries,A.totalEntries),unabsorbed:Math.max(k.unabsorbed,A.unabsorbed)}):v.push(k),$.add(k.agentId)}for(let k of y)$.has(k.agentId)||(v.push(k),$.add(k.agentId));if(u==="/agents")h=Cn(s,v,y);else if(u==="/entries")h=Pn(s,v);else if(u==="/search")h=Rn(s,g.searchParams.get("q")||"",v);else if(u.startsWith("/tag/"))h=Tn(s,decodeURIComponent(u.slice(5)),v);else if(u.match(/^\/agent\/[^/]+\/tag\/.+/)){let k=u.match(/^\/agent\/([^/]+)\/tag\/(.+)$/);h=Dn(s,decodeURIComponent(k[1]),decodeURIComponent(k[2]),v)}else if(u.startsWith("/agent/")){let k=u.slice(7),A=k.indexOf("/article/");if(A===-1)h=In(s,k,v);else{let _=k.slice(0,A),K=k.slice(A+9);if(h=En(s,_,K,v),!h&&d){let I=y.find(D=>D.agentId===_);if(I){let D=await d.getRemoteArticle(I.peerUrl,_,K);if(D){let E=`<div class="breadcrumb"><a href="/">Hub</a> / <span class="tag">remote @ ${p(I.nodeId)}</span> / ${p(_)}</div>`;E+=`<h1>${p(D.meta.title)}</h1>`,E+='<dl class="meta">',E+=`<dt>Tags</dt><dd>${(D.meta.tags||[]).map(Ot=>`<span class="tag">${Ot}</span>`).join(" ")}</dd>`,E+=`<dt>Source</dt><dd><span class="tag">remote</span> ${p(I.nodeId)}</dd>`,E+=`<dt>Updated</dt><dd>${D.meta.lastUpdated}</dd>`,E+="</dl>",E+=te(D.content,new Map),h=S(D.meta.title,T(v),E)}}}}}}if(!h){C=404;let y=n?L(s.getAgentWiki(n),n):T(s.summary());h=S("Not Found",y,"<h1>Page not found</h1>")}}catch(y){C=500,h=S("Error","",`<h1>Error</h1><pre>${p(y.message)}</pre>`)}if(C===200&&e.curator){let y=zn(s,l,u,n);y&&(h=ht(h,y,e.curatorEndpoint,e.curatorToken?.()))}f.writeHead(C,{"Content-Type":"text/html; charset=utf-8"}),f.end(i?Nn(h,i):h)}}function zn(e,t,n,r){let a,o;if(r&&n.startsWith("/article/"))a=r,o=n.slice(9);else if(!r&&n.startsWith("/agent/")){let l=n.match(/^\/agent\/([^/]+)\/article\/(.+)$/);l&&(a=l[1],o=l[2])}else if(!r)return t.pageAt(n);if(!a||!o||!e.listAgents([]).includes(a))return null;let i=e.getAgentWiki(a);if(!Ne(i.baseDir,o))return null;let s=i.readArticle(o);return s?{agentId:a,path:o,title:s.meta.title}:null}function Nn(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 pa(e,t=4200,n,r=[],a="graph"){let o=_n({wikiDir:e,agentFilter:n,peers:r,mode:a});kn((s,l)=>{o(s,l)}).listen(t)}import{existsSync as Wn,readFileSync as Mn}from"fs";ie();function va(e){let t=H(e),n={};if(Wn(t))try{n=j(JSON.parse(Mn(t,"utf-8")))}catch{n={}}let r=n?.workflows?.required??{},a={};for(let[o,i]of Object.entries(r.agents??{}))typeof i=="boolean"&&(a[o]=i);return{enabled:typeof r.enabled=="boolean"?r.enabled:J.enabled,agents:a,exemptQuestions:typeof r.exemptQuestions=="boolean"?r.exemptQuestions:J.exemptQuestions,retentionDays:Number.isInteger(r.retentionDays)&&r.retentionDays>=0?r.retentionDays:J.retentionDays,engine:n?.workflows?.enabled===!0}}async function ba(e,t={}){return e.retentionDays!==void 0&&!(Number.isInteger(e.retentionDays)&&e.retentionDays>=0&&e.retentionDays<=3650)?{success:!1,error:"retentionDays is a whole number of days from 0 to 3650"}:e.agent&&!/^[A-Za-z0-9_.@-]{1,80}$/.test(e.agent.id)?{success:!1,error:`"${e.agent.id}" is not an agent id`}:G(n=>{let r=n.workflows??={},a=r.required??={};if(e.enabled!==void 0&&(a.enabled=e.enabled),e.exemptQuestions!==void 0&&(a.exemptQuestions=e.exemptQuestions),e.retentionDays!==void 0&&(a.retentionDays=e.retentionDays),e.agent){let o=a.agents??={};e.agent.value===null?delete o[e.agent.id]:o[e.agent.id]=e.agent.value}(e.enabled===!0||e.agent?.value===!0)&&(r.enabled=!0)},{configPath:t.configPath,reload:t.reload})}var On={"claude-code":{bin:"claude",login:"Install Claude Code (https://claude.com/claude-code) and run `claude` once to log in"},"codex-cli":{bin:"codex",login:"Install Codex CLI and run `codex login`"},opencode:{bin:"opencode",login:"Install OpenCode and run `opencode auth login`"}};function Un(e){if(typeof e!="string")return null;let t=e.match(/^\$\{(\w+)\}$/);return t?t[1]:null}function ya(e){let t=e.rawConfig?.agents?.[e.agentId];if(!t)return{ready:!1,hint:`No agent "${e.agentId}" in agentx.json.`};let n=String(t.tier||""),r=On[n];if(r)return e.hasBinary(r.bin)?e.cliLoggedIn?.(r.bin)===!1?{ready:!1,need:"cli",cli:r.bin,hint:`${r.bin} is installed but not logged in. In a terminal, run \`${r.bin}\` once and log in, then press Check again.`}:{ready:!0}:{ready:!1,need:"cli",cli:r.bin,hint:`${r.login}, then press Check again.`};if(n==="sdk"||n==="orchestrator"){let a=t.provider||(n==="sdk"?"claude":"claude-code"),o=e.rawConfig?.providers?.[a];if(n==="orchestrator"&&!(o&&"apiKey"in o))return{ready:!0};let i=o?.apiKey,s=Un(i);return s?e.env[s]||e.dotenv[s]?{ready:!0}:{ready:!1,need:"key",envVar:s,hint:`Paste an API key for "${a}". It is saved to .env as ${s} on this computer only.`}:typeof i=="string"&&i.trim()?{ready:!0}:{ready:!1,hint:`Set providers.${a}.apiKey in agentx.json.`}}return{ready:!0}}import{appendFileSync as Ln,existsSync as bt,readFileSync as xt,writeFileSync as Bn}from"fs";function jn(e){return bt(e)?Object.fromEntries(Ce(xt(e,"utf-8"))):{}}function Aa(e,t,n){if(!/^[A-Z_][A-Z0-9_]*$/.test(t))throw new Error(`not an environment variable name: ${t}`);if(!n||/[\r\n]/.test(n))throw new Error("the value must be one non-empty line");if(jn(e)[t])return!1;if(!bt(e))return Bn(e,`# AgentX environment variables
|
|
856
|
+
# (Never commit this file: it contains secrets.)
|
|
857
|
+
|
|
858
|
+
${t}=${n}
|
|
859
|
+
`,{mode:384}),!0;let r=xt(e,"utf-8"),a=r===""||r.endsWith(`
|
|
860
|
+
`)?"":`
|
|
861
|
+
`;return Ln(e,`${a}${t}=${n}
|
|
862
|
+
`),!0}import{execFileSync as Hn}from"child_process";function Ea(e){if(e!=="claude")return null;let t=Oe(e);if(!t)return null;try{let n=Hn(t,["auth","status"],{encoding:"utf-8",timeout:1e4,stdio:["ignore","pipe","ignore"]});return yt(n)}catch(n){return typeof n?.stdout=="string"?yt(n.stdout):null}}function yt(e){try{let t=JSON.parse(e);return typeof t?.loggedIn=="boolean"?t.loggedIn:null}catch{return null}}import{existsSync as It,readdirSync as Kn}from"fs";import{join as Et}from"path";import{join as qn}from"path";function kt(e){return/^[\w@%+=:,./-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function B(e){return(t,n)=>`cd ${kt(n)} && npx -y skills add ${kt(t)} -a ${e} -y`}var ne={tier:"claude-code",skillDirs:e=>[qn(e,".claude","skills")],addSkillCommand:B("claude-code"),instructionsFile:"CLAUDE.md"};import{join as Fn}from"path";var wt={tier:"codex-cli",skillDirs:e=>[Fn(e,".agents","skills")],addSkillCommand:B("codex"),instructionsFile:"AGENTS.md"};import{join as ye}from"path";var $t={tier:"opencode",skillDirs:e=>[ye(e,".agents","skills"),ye(e,".opencode","skills"),ye(e,".claude","skills")],addSkillCommand:B("opencode"),instructionsFile:"AGENTS.md"};import{join as ke}from"path";var At=e=>({...ne,tier:e,skillDirs:t=>[ke(t,".claude","skills"),ke(t,".skills"),ke(t,"skills")]}),St=At("sdk"),Ct=At("orchestrator");var Gn={"claude-code":ne,"codex-cli":wt,opencode:$t,sdk:St,orchestrator:Ct};function Pt(e){return Gn[e??"claude-code"]??null}function Ya(e,t){return Pt(e)?.skillDirs(t)[0]??null}function Xa(e,t){let n=new Map;for(let r of Pt(e)?.skillDirs(t)??[])if(It(r))for(let a of Kn(r))a.startsWith(".")||n.has(a)||It(Et(r,a,"SKILL.md"))&&n.set(a,Et(r,a));return[...n].map(([r,a])=>({name:r,dir:a})).sort((r,a)=>r.name.localeCompare(a.name))}Ut();function Za(e,t,n=20){return e.prepare(`SELECT task_id, agent_id, channel, chat_id, status, started_at, finished_at, message_preview
|
|
856
863
|
FROM task_traces
|
|
857
864
|
WHERE person = ? AND (channel IS NULL OR channel != 'a2a')
|
|
858
|
-
ORDER BY started_at DESC, rowid DESC LIMIT ?`).all(t,Math.max(1,Math.min(n,500))).map(a=>({taskId:a.task_id,agentId:a.agent_id,channel:a.channel,chatId:a.chat_id,status:a.status,startedAt:a.started_at,finishedAt:a.finished_at??null,messagePreview:a.message_preview}))}function
|
|
865
|
+
ORDER BY started_at DESC, rowid DESC LIMIT ?`).all(t,Math.max(1,Math.min(n,500))).map(a=>({taskId:a.task_id,agentId:a.agent_id,channel:a.channel,chatId:a.chat_id,status:a.status,startedAt:a.started_at,finishedAt:a.finished_at??null,messagePreview:a.message_preview}))}function Jn(e){return e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'requests'").get()?e.prepare("PRAGMA table_info(requests)").all().some(r=>r.name==="person"):!1}function Rt(e,t,n,r,...a){return Jn(e)?e.prepare(`SELECT id, state, channel, agent_id, text, created_at FROM requests
|
|
859
866
|
WHERE person = ? AND state IN (${n.map(()=>"?").join(",")})
|
|
860
|
-
${r}`).all(t,...n,...a).map(i=>({id:i.id,state:i.state,channel:i.channel,agentId:i.agent_id,text:i.text,createdAt:i.created_at})):[]}function
|
|
861
|
-
`)}var
|
|
862
|
-
//# sourceMappingURL=chunk-
|
|
867
|
+
${r}`).all(t,...n,...a).map(i=>({id:i.id,state:i.state,channel:i.channel,agentId:i.agent_id,text:i.text,createdAt:i.created_at})):[]}function eo(e,t){return Rt(e,t,ae,"ORDER BY created_at")}function to(e,t,n=50){return Rt(e,t,[...ae,...$e],"ORDER BY created_at DESC, rowid DESC LIMIT ?",Math.max(1,Math.min(n,500)))}Lt();var we="member:",Yn=90,Xn="members",Vn="tailscale-user-login",Qn=400,Zn=60*60*1e3;function er(e){let t=e.scopes.find(n=>n.startsWith(we));return t?t.slice(we.length):null}function Dt(e,t){if(!e)return null;let n=t.verify(e),r=n?er(n):null;return n&&r?{rec:n,personId:r}:null}function lo(e,t){let n=e.people().find(s=>s.id===t);if(!n)return{ok:!1,error:`No person "${t}". Add them first: agentx people add ${t} --name "\u2026"`};let{token:r,record:a}=e.tokens.create({name:`${n.name} (machine not paired yet)`,scopes:[`${we}${n.id}`],expiresInDays:Yn}),{code:o,expiresAt:i}=e.codes.create({token:r,tokenId:a.id,name:n.id});return e.members.log({person:n.id,device:a.id,event:"invited"}),{ok:!0,code:o,expiresAt:i,tokenId:a.id,person:n}}var tr=Math.round(De/6e4);function nr(e){return e==="client"?"Your project":"My work"}function co(e){let t=nr(e.person.role),n=e.person.role==="client"?`I use AgentX to keep track of the work I do for you. It has a page for you, "${t}": what you asked us for, and where each request stands.`:`I use AgentX to give our AI agents their jobs. It has a page for you, "${t}": what you asked the agents for, and where each request stands.`;return[`Hi ${e.person.name},`,"",n,"","To open it:","1. Accept the Tailscale share I sent you. Tailscale is a small program that connects your computer to mine, privately.",`2. Open ${e.origin.replace(/\/+$/,"")}/member in Edge or Chrome, give your computer a name and type this code: ${_e(e.code)}`,` The code works once, for ${tr} minutes. If it has stopped working, tell me and I will send you a new one.`,"","I then approve your machine, and the page opens by itself."].join(`
|
|
868
|
+
`)}var rr="The private network says someone else is connecting from this machine. Ask the person who invited you for a new code.",ar="Too many machines are waiting for the owner's answer. Try again later.",Tt="That code didn't work. Check it, or ask the person who invited you for a new one.",_t=(e,t)=>{let n=e.headers[t];return(Array.isArray(n)?n[0]:n||"").trim()};function zt(e){let t=e.socket?.remoteAddress||"";return t==="127.0.0.1"||t==="::1"||t==="::ffff:127.0.0.1"}function or(e){if(!zt(e))return null;let t=_t(e,Vn).toLowerCase();return t?t.slice(0,80):null}function ir(e){let t=e.socket?.remoteAddress||"unknown";if(!zt(e))return t;let n=_t(e,"x-forwarded-for").split(",").pop().trim();return/^[0-9a-fA-F:.]{2,45}$/.test(n)?n:t}function sr(e){return typeof e=="string"?e.replace(/[^\p{L}\p{N} ._'()-]/gu," ").replace(/\s+/g," ").trim().slice(0,60):""}function lr(e){return e.identities.map(Ae).filter(t=>!!t&&t.channel==="tailscale").map(t=>t.value)}async function po(e,t){let n=Date.now(),r=t.now??Date.now,a=t.log??(b=>console.log(b)),o=ir(e),i=t.limiter.retryAfter(o);if(i>0)return a(`[member] pair-code refused from ${o}: locked out for ${i}s more`),{status:429,body:{error:"too many attempts",retryAfter:i},retryAfter:i};let s=null,l="";try{let b=await Y(e,2048);s=b.code,l=sr(b.machine)}catch{}let d=t.codes.redeem(s),c=d?Dt(d.token,t.tokens):null;if(await cr(n,t.minMs??Qn),!d||!c)return t.limiter.fail(o),a(`[member] pair-code failed from ${o}`),{status:401,body:{error:Tt}};t.limiter.succeed(o);let{rec:f,personId:g}=c,m=t.people().find(b=>b.id===g);if(!m)return t.tokens.revoke(f.id),t.members.log({person:g,device:f.id,event:"refused",address:o,detail:"person no longer listed"}),a(`[member] pair-code for ${g} refused from ${o}: person no longer listed`),{status:403,body:{error:Tt}};let u=or(e),h=lr(m);if(h.length&&(!u||!h.includes(u)))return t.tokens.revoke(f.id),t.members.log({person:g,device:f.id,event:"refused",address:o,detail:`network login ${u??"missing"}; expected ${h.join(" or ")}`}),a(`[member] ${g}: pairing from ${o} refused: the network says "${u??"nobody"}", expected ${h.join(" or ")}`),{status:403,body:{error:rr}};let C=l||"Unnamed machine",y=m.name.slice(0,40),x=ze(t.root,{title:`New machine for ${y}`,ask:`From ${o}, ${u?`network login ${u}`:"no network login reported"}. Machine name, as typed there: "${C}". 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:Xn},{now:r()});return x.ok?(t.members.add({tokenId:f.id,personId:g,name:C,state:"pending",cardId:x.card.id,address:o,...u?{network:u}:{},createdAt:new Date(r()).toISOString()}),t.members.log({person:g,device:f.id,event:"paired",address:o,detail:C}),a(`[member] ${g} paired "${C}" from ${o}; waiting for the owner (card ${x.card.id})`),{status:200,body:{person:g,name:C,state:"pending"},token:d.token}):(t.tokens.revoke(f.id),t.members.log({person:g,device:f.id,event:"refused",address:o,detail:x.error}),a(`[member] ${g}: pairing from ${o} refused: ${x.error}`),{status:503,body:{error:ar}})}var re="this machine is not paired",dr="waiting for the owner to approve this machine";function Nt(e){return e?e.status==="decided"?e.verdict??null:e.status==="expired"?"no":null:null}function uo(e,t){return t.state==="pending"&&t.cardId?Nt(se(e,t.cardId)):null}function go(e,t,n){let r=t.now??Date.now,a=t.log??(c=>console.log(c)),o=Dt(e,t.tokens);if(!o)return{ok:!1,status:401,error:re};let{rec:i,personId:s}=o,l=t.members.byToken(i.id);if(!l||l.state==="removed"||l.personId!==s)return{ok:!1,status:401,error:re};if(t.people&&!t.people().some(c=>c.id===s))return Wt(t,i.id,"person no longer listed"),a(`[member] ${s}: "${l.name}" ended: person no longer listed`),{ok:!1,status:401,error:re};if(l.state==="pending"){let c=l.cardId?se(t.root,l.cardId):null,f=Nt(c);if(f==="yes")l=t.members.update(i.id,{state:"active",approvedAt:new Date(r()).toISOString()})??l,t.members.log({person:s,device:i.id,event:"approved",detail:c?.decided_by}),a(`[member] ${s}: "${l.name}" approved`);else if(f==="no"){let g=c?.status==="expired"?"the owner did not answer in time":"the owner said no";return t.tokens.revoke(i.id),t.members.update(i.id,{state:"removed",removedAt:new Date(r()).toISOString(),removedReason:g}),t.members.log({person:s,device:i.id,event:"refused",detail:g}),a(`[member] ${s}: "${l.name}" refused: ${g}`),{ok:!1,status:401,error:re}}else return{ok:!1,status:403,error:dr,waiting:!0}}let d=l.lastSeenAt?Date.parse(l.lastSeenAt):0;return n&&(r()-d>=Zn||l.lastAddress!==n)&&(l=t.members.update(i.id,{lastSeenAt:new Date(r()).toISOString(),lastAddress:n})??l,t.members.log({person:s,device:i.id,event:"signed-in",address:n})),{ok:!0,device:l,personId:s,rec:i}}function Wt(e,t,n="removed by the owner"){let r=e.members.byToken(t);if(!r)return null;e.tokens.revoke(t);let a=e.members.update(t,{state:"removed",removedAt:new Date((e.now??Date.now)()).toISOString(),removedReason:n});return e.members.log({person:r.personId,device:t,event:"removed",detail:n}),a}function mo(e,t){return e.members.devices(t).filter(n=>n.state!=="removed").map(n=>Wt(e,n.tokenId,"person removed by the owner")).filter(n=>!!n)}async function cr(e,t){let n=e+t-Date.now();n>0&&await new Promise(r=>setTimeout(r,n))}var Mt=["gitlab","github"];function pr(e,t,n){let r=String(t||"").trim().toLowerCase();if(!Mt.includes(r))throw new Error(`Request status works on ${Mt.join(" and ")}, not on "${t}".`);e.requestStatus=e.requestStatus&&typeof e.requestStatus=="object"?e.requestStatus:{};let a=Array.isArray(e.requestStatus.channels)?e.requestStatus.channels.map(o=>String(o).toLowerCase()):[];return e.requestStatus.channels=n?[...new Set([...a,r])]:a.filter(o=>o!==r),`request status on ${r} is ${n?"on":"off"}`}function vo(e){return Array.isArray(e?.requestStatus?.channels)?e.requestStatus.channels.map(t=>String(t).toLowerCase()):[]}function bo(e){let{summary:t}=X(n=>pr(n,e?.channel,!!e?.enabled));return{summary:t}}function yo(e){return new Set(Object.entries(e).filter(([,t])=>t?.wiki?.absorb?.enabled===!1).map(([t])=>t))}function ko(e,t){return t.only?{agents:[t.only],skipped:[]}:{agents:e.filter(n=>!t.off.has(n)),skipped:e.filter(n=>t.off.has(n))}}function wo(e,t){return`absorb is off for this agent (agents.${e}.wiki.absorb.enabled); skipped.${e===t?" It reads the wiki notes inbox, so the inbox was not read.":""} Use --agent ${e} to run it anyway.`}function $o(e,t){if(t){if(!e.wiki?.absorb)return;delete e.wiki.absorb.enabled,Object.keys(e.wiki.absorb).length===0&&delete e.wiki.absorb,Object.keys(e.wiki).length===0&&delete e.wiki;return}e.wiki??={},e.wiki.absorb??={},e.wiki.absorb.enabled=!1}var ur="https://ntfy.sh";function So(e){return{enabled:!!e?.enabled,server:e?.server||ur,topicSet:!!e?.topic,tokenSet:!!e?.token}}function Co(e,t){let n={...e??{}};if("enabled"in t&&(n.enabled=!!t.enabled),"server"in t){let r=String(t.server).trim().replace(/\/+$/,"");if(!/^https?:\/\/\S+$/.test(r))throw new Error("ntfy server must be an http(s) URL");n.server=r}if("topic"in t){let r=String(t.topic).trim();if(!r)throw new Error("ntfy topic cannot be empty");n.topic=r}if("token"in t){let r=String(t.token??"").trim();r?n.token=r:delete n.token}if(n.enabled&&!n.topic)throw new Error("set a topic before enabling ntfy");return n}export{Ze as a,Yt as b,$r as c,Ar as d,Sr as e,ya as f,jn as g,Aa as h,Ea as i,Dr as j,_r as k,cn as l,gn as m,me as n,zr as o,Nr as p,Pt as q,Ya as r,Xa as s,mn as t,Br as u,jr as v,Hr as w,Za as x,eo as y,to as z,Yn as A,lo as B,tr as C,nr as D,co as E,ir as F,po as G,uo as H,go as I,Wt as J,mo as K,Mt as L,pr as M,vo as N,bo as O,yo as P,ko as Q,wo as R,$o as S,So as T,Co as U,_n as V,pa as W,va as X,ba as Y};
|
|
869
|
+
//# sourceMappingURL=chunk-CLHIE4UW.js.map
|