agentix-cli 0.84.0 → 0.86.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.
Files changed (103) hide show
  1. package/dist/{App-HNQCK3BB.js → App-NLEBAGQK.js} +2 -2
  2. package/dist/{ChatApp-XPCAL4FP.js → ChatApp-JN2WJ7ZK.js} +2 -2
  3. package/dist/{agent-TRQTWNYE.js → agent-QORMJHWT.js} +2 -2
  4. package/dist/{board-dashboard-R5NMATZ3.js → board-dashboard-YG3MBOXP.js} +257 -257
  5. package/dist/board-dashboard-YG3MBOXP.js.map +1 -0
  6. package/dist/{chunk-3D3B4NQ7.js → chunk-5PEOSZ44.js} +2 -2
  7. package/dist/{chunk-Y3C37PF5.js → chunk-ANJ2BO7D.js} +2 -2
  8. package/dist/{chunk-OFV34UZY.js → chunk-AXW5U32B.js} +2 -2
  9. package/dist/{chunk-AYHVNISD.js → chunk-CZ4CWVDE.js} +2 -2
  10. package/dist/{chunk-H4EGM4L7.js → chunk-DTXI7LEI.js} +2 -2
  11. package/dist/{chunk-H4EGM4L7.js.map → chunk-DTXI7LEI.js.map} +1 -1
  12. package/dist/{chunk-ZL7RKS6H.js → chunk-FORTAGGM.js} +161 -161
  13. package/dist/chunk-FORTAGGM.js.map +1 -0
  14. package/dist/{chunk-ZVUEJXCY.js → chunk-FRWV3XOV.js} +2 -2
  15. package/dist/{chunk-QA4RTSKI.js → chunk-GO57OXET.js} +2 -2
  16. package/dist/{chunk-WABEHPU5.js → chunk-KK6HPN3U.js} +2 -2
  17. package/dist/{chunk-FATAHJG3.js → chunk-M457SOS3.js} +2 -2
  18. package/dist/{chunk-JU3RIJDW.js → chunk-NNAMMKT7.js} +2 -2
  19. package/dist/{chunk-WDASUG6A.js → chunk-NY7ZZGT3.js} +3 -3
  20. package/dist/{chunk-WDASUG6A.js.map → chunk-NY7ZZGT3.js.map} +1 -1
  21. package/dist/{chunk-3VP3UWNT.js → chunk-QIJOGYK5.js} +2 -2
  22. package/dist/{chunk-5DUPIMOI.js → chunk-RLSRENAO.js} +2 -2
  23. package/dist/chunk-SPSICIEA.js +5 -0
  24. package/dist/{chunk-ZJJJM7AR.js.map → chunk-SPSICIEA.js.map} +1 -1
  25. package/dist/{chunk-6NE2GLO6.js → chunk-TICACOQG.js} +2 -2
  26. package/dist/{chunk-4GNAOJ7P.js → chunk-VQVN3VSJ.js} +2 -2
  27. package/dist/{chunk-DA2NTRUR.js → chunk-WBJLVFBW.js} +2 -2
  28. package/dist/{chunk-MABFDA3G.js → chunk-WLKQFYUM.js} +2 -2
  29. package/dist/{chunk-CDC76MRL.js → chunk-YK6VYYHC.js} +2 -2
  30. package/dist/{chunk-XL7WTOP5.js → chunk-YSV53UFR.js} +5 -5
  31. package/dist/cli.js +1 -1
  32. package/dist/{client-4YL2RDDT.js → client-5Z4IVYAH.js} +2 -2
  33. package/dist/config-2SRJEOO7.js +2 -0
  34. package/dist/config-mutator-RKEMP53O.js +2 -0
  35. package/dist/{doctor-BHL44USQ.js → doctor-UKWJO3TG.js} +2 -2
  36. package/dist/index.js +1 -1
  37. package/dist/index.js.map +1 -1
  38. package/dist/{program-G7R64P7A.js → program-PUG7P7TC.js} +192 -175
  39. package/dist/program-PUG7P7TC.js.map +1 -0
  40. package/dist/{promote-ANCV5DLK.js → promote-3R56RJQD.js} +2 -2
  41. package/dist/{query-DA65EPSF.js → query-6ZTEUTKC.js} +2 -2
  42. package/dist/{registry-77K6WP3H.js → registry-KJZDXHKL.js} +2 -2
  43. package/dist/{request-planner-IARLBD4R.js → request-planner-JFES5YW2.js} +2 -2
  44. package/dist/{review-candidates-3PML6UYA.js → review-candidates-OR375PHS.js} +2 -2
  45. package/dist/{routing-2LKQW4XD.js → routing-W2E52LYP.js} +2 -2
  46. package/dist/schedule-tool-XZL5AKFB.js +2 -0
  47. package/dist/scheduler-BOQJMSJE.js +2 -0
  48. package/dist/{seat-U4O3OOOZ.js → seat-GAS7YKQA.js} +2 -2
  49. package/dist/{select-ORDHPTI7.js → select-UYFJH4V5.js} +2 -2
  50. package/dist/{set-enabled-4RHEXIE4.js → set-enabled-PFMELM3V.js} +2 -2
  51. package/dist/{tool-T4IYBXOT.js → tool-BGEHMLJ3.js} +2 -2
  52. package/dist/{tool-ZFXAIC4V.js → tool-W4NSPPXO.js} +2 -2
  53. package/dist/web/activity-graph.global.js +26 -16
  54. package/dist/web/activity-graph.global.js.map +1 -1
  55. package/dist/wiki-L5FJ5RYE.js +2 -0
  56. package/package.json +3 -2
  57. package/dist/board-dashboard-R5NMATZ3.js.map +0 -1
  58. package/dist/chunk-ZJJJM7AR.js +0 -5
  59. package/dist/chunk-ZL7RKS6H.js.map +0 -1
  60. package/dist/config-HY6CPDFH.js +0 -2
  61. package/dist/config-mutator-AKAUM6Q6.js +0 -2
  62. package/dist/program-G7R64P7A.js.map +0 -1
  63. package/dist/schedule-tool-P6AGRN5F.js +0 -2
  64. package/dist/scheduler-TJHXFDNW.js +0 -2
  65. package/dist/wiki-2EMSGMLC.js +0 -2
  66. /package/dist/{App-HNQCK3BB.js.map → App-NLEBAGQK.js.map} +0 -0
  67. /package/dist/{ChatApp-XPCAL4FP.js.map → ChatApp-JN2WJ7ZK.js.map} +0 -0
  68. /package/dist/{agent-TRQTWNYE.js.map → agent-QORMJHWT.js.map} +0 -0
  69. /package/dist/{chunk-3D3B4NQ7.js.map → chunk-5PEOSZ44.js.map} +0 -0
  70. /package/dist/{chunk-Y3C37PF5.js.map → chunk-ANJ2BO7D.js.map} +0 -0
  71. /package/dist/{chunk-OFV34UZY.js.map → chunk-AXW5U32B.js.map} +0 -0
  72. /package/dist/{chunk-AYHVNISD.js.map → chunk-CZ4CWVDE.js.map} +0 -0
  73. /package/dist/{chunk-ZVUEJXCY.js.map → chunk-FRWV3XOV.js.map} +0 -0
  74. /package/dist/{chunk-QA4RTSKI.js.map → chunk-GO57OXET.js.map} +0 -0
  75. /package/dist/{chunk-WABEHPU5.js.map → chunk-KK6HPN3U.js.map} +0 -0
  76. /package/dist/{chunk-FATAHJG3.js.map → chunk-M457SOS3.js.map} +0 -0
  77. /package/dist/{chunk-JU3RIJDW.js.map → chunk-NNAMMKT7.js.map} +0 -0
  78. /package/dist/{chunk-3VP3UWNT.js.map → chunk-QIJOGYK5.js.map} +0 -0
  79. /package/dist/{chunk-5DUPIMOI.js.map → chunk-RLSRENAO.js.map} +0 -0
  80. /package/dist/{chunk-6NE2GLO6.js.map → chunk-TICACOQG.js.map} +0 -0
  81. /package/dist/{chunk-4GNAOJ7P.js.map → chunk-VQVN3VSJ.js.map} +0 -0
  82. /package/dist/{chunk-DA2NTRUR.js.map → chunk-WBJLVFBW.js.map} +0 -0
  83. /package/dist/{chunk-MABFDA3G.js.map → chunk-WLKQFYUM.js.map} +0 -0
  84. /package/dist/{chunk-CDC76MRL.js.map → chunk-YK6VYYHC.js.map} +0 -0
  85. /package/dist/{chunk-XL7WTOP5.js.map → chunk-YSV53UFR.js.map} +0 -0
  86. /package/dist/{client-4YL2RDDT.js.map → client-5Z4IVYAH.js.map} +0 -0
  87. /package/dist/{config-HY6CPDFH.js.map → config-2SRJEOO7.js.map} +0 -0
  88. /package/dist/{config-mutator-AKAUM6Q6.js.map → config-mutator-RKEMP53O.js.map} +0 -0
  89. /package/dist/{doctor-BHL44USQ.js.map → doctor-UKWJO3TG.js.map} +0 -0
  90. /package/dist/{promote-ANCV5DLK.js.map → promote-3R56RJQD.js.map} +0 -0
  91. /package/dist/{query-DA65EPSF.js.map → query-6ZTEUTKC.js.map} +0 -0
  92. /package/dist/{registry-77K6WP3H.js.map → registry-KJZDXHKL.js.map} +0 -0
  93. /package/dist/{request-planner-IARLBD4R.js.map → request-planner-JFES5YW2.js.map} +0 -0
  94. /package/dist/{review-candidates-3PML6UYA.js.map → review-candidates-OR375PHS.js.map} +0 -0
  95. /package/dist/{routing-2LKQW4XD.js.map → routing-W2E52LYP.js.map} +0 -0
  96. /package/dist/{schedule-tool-P6AGRN5F.js.map → schedule-tool-XZL5AKFB.js.map} +0 -0
  97. /package/dist/{scheduler-TJHXFDNW.js.map → scheduler-BOQJMSJE.js.map} +0 -0
  98. /package/dist/{seat-U4O3OOOZ.js.map → seat-GAS7YKQA.js.map} +0 -0
  99. /package/dist/{select-ORDHPTI7.js.map → select-UYFJH4V5.js.map} +0 -0
  100. /package/dist/{set-enabled-4RHEXIE4.js.map → set-enabled-PFMELM3V.js.map} +0 -0
  101. /package/dist/{tool-T4IYBXOT.js.map → tool-BGEHMLJ3.js.map} +0 -0
  102. /package/dist/{tool-ZFXAIC4V.js.map → tool-W4NSPPXO.js.map} +0 -0
  103. /package/dist/{wiki-2EMSGMLC.js.map → wiki-L5FJ5RYE.js.map} +0 -0
@@ -1,4 +1,4 @@
1
- import{b as C}from"./chunk-CECHWYJ2.js";import{a as L,b as _,c as R,d as j,e as M,j as I}from"./chunk-3VP3UWNT.js";import{v as x,w as O}from"./chunk-DA2NTRUR.js";import{c as A,d as D}from"./chunk-QOYAX2FT.js";import{readFileSync as y,writeFileSync as b,appendFileSync as P,existsSync as w,mkdirSync as $,readdirSync as v,statSync as B}from"fs";import{resolve as u,join as N,relative as k,dirname as U}from"path";O();var T=class{baseDir;rawDir;log;constructor(t=u(process.cwd(),".agentx/wiki"),e=console.error.bind(console,"[wiki]")){this.baseDir=t,this.rawDir=u(t,"raw/entries"),this.log=e,$(this.rawDir,{recursive:!0}),$(u(t,"raw"),{recursive:!0}),this.ensureSchema()}canRead(t,e){return t.access==="public"?!0:e?!!(t.owner===e||t.access==="shared"&&t.sharedWith?.includes(e)):!1}canWrite(t,e){return t.owner===e}addEntry(t){let e=`${t.date}_${t.id}.md`,r=u(this.rawDir,e),n=["---",`id: ${t.id}`,`date: ${t.date}`,`agent: ${t.agentId}`,`source: ${t.source}`];if(t.sourceContext&&n.push(`context: ${t.sourceContext}`),t.meta)for(let[a,s]of Object.entries(t.meta))n.push(`${a}: ${JSON.stringify(s)}`);return n.push("---","",t.content),b(r,n.join(`
1
+ import{b as C}from"./chunk-CECHWYJ2.js";import{a as L,b as _,c as R,d as j,e as M,j as I}from"./chunk-QIJOGYK5.js";import{v as x,w as O}from"./chunk-WBJLVFBW.js";import{c as A,d as D}from"./chunk-QOYAX2FT.js";import{readFileSync as y,writeFileSync as b,appendFileSync as P,existsSync as w,mkdirSync as $,readdirSync as v,statSync as B}from"fs";import{resolve as u,join as N,relative as k,dirname as U}from"path";O();var T=class{baseDir;rawDir;log;constructor(t=u(process.cwd(),".agentx/wiki"),e=console.error.bind(console,"[wiki]")){this.baseDir=t,this.rawDir=u(t,"raw/entries"),this.log=e,$(this.rawDir,{recursive:!0}),$(u(t,"raw"),{recursive:!0}),this.ensureSchema()}canRead(t,e){return t.access==="public"?!0:e?!!(t.owner===e||t.access==="shared"&&t.sharedWith?.includes(e)):!1}canWrite(t,e){return t.owner===e}addEntry(t){let e=`${t.date}_${t.id}.md`,r=u(this.rawDir,e),n=["---",`id: ${t.id}`,`date: ${t.date}`,`agent: ${t.agentId}`,`source: ${t.source}`];if(t.sourceContext&&n.push(`context: ${t.sourceContext}`),t.meta)for(let[a,s]of Object.entries(t.meta))n.push(`${a}: ${JSON.stringify(s)}`);return n.push("---","",t.content),b(r,n.join(`
2
2
  `)),this.appendLog("ingest",`${t.id} from ${t.agentId} via ${t.source}`),e}listEntries(t){if(!w(this.rawDir))return[];let e=v(this.rawDir).filter(n=>n.endsWith(".md")).sort(),r=[];for(let n of e){let a=y(u(this.rawDir,n),"utf-8"),s=this.parseEntry(a,n);s&&(t?.agentId&&s.agentId!==t.agentId||t?.after&&s.date<t.after||t?.before&&s.date>t.before||r.push(s))}return r}parseEntry(t,e){let r=t.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);if(!r)return null;let n=r[1],a=r[2].trim(),s=c=>n.match(new RegExp(`^${c}:\\s*(.+)$`,"m"))?.[1]?.trim()||"",o=new Set(["id","date","agent","source","context"]),i={};for(let c of n.split(`
3
3
  `)){let l=c.match(/^(\w+):\s*(.+)$/);if(!(!l||o.has(l[1])))try{i[l[1]]=JSON.parse(l[2])}catch{i[l[1]]=l[2].trim()}}return{id:s("id")||e.replace(".md",""),date:s("date"),agentId:s("agent"),source:s("source"),sourceContext:s("context")||void 0,content:a,meta:Object.keys(i).length>0?i:void 0}}writeArticle(t,e,r,n){let a=this.readArticle(t);if(a&&!this.canWrite(a.meta,n))return this.log(`Permission denied: "${n}" cannot write "${t}" (owner: ${a.meta.owner})`),!1;e.type&&!C(e.type)&&(this.log(`Dropping invalid article type "${e.type}" for "${t}" \u2014 enum is [person, project, place, concept, event, decision, pattern]`),e={...e,type:void 0});let s=u(this.baseDir,t);a&&this.saveVersion(t,s),$(U(s),{recursive:!0});let o=["---",`title: "${e.title}"`];e.type&&o.push(`type: ${e.type}`),e.related?.length&&o.push(`related: [${e.related.map(c=>`"${c}"`).join(", ")}]`),o.push(`tags: [${(e.tags||[]).map(c=>`"${c}"`).join(", ")}]`,`owner: ${e.owner}`,`access: ${e.access}`),e.sharedWith?.length&&o.push(`shared_with: [${e.sharedWith.map(c=>`"${c}"`).join(", ")}]`),o.push(`created: ${e.created}`,`last_updated: ${e.lastUpdated}`,`sources: [${e.sources.map(c=>`"${c}"`).join(", ")}]`),e.graphPath?.length&&o.push(`graph_path: [${e.graphPath.map(c=>`"${c}"`).join(", ")}]`),o.push("---","",r),b(s,o.join(`
4
4
  `));let i=a?"update":"create";return this.appendLog(i,`${e.title} [${(e.tags||[]).slice(0,5).join(", ")}] by ${n} at ${t}`),!0}saveVersion(t,e){try{if(!w(e))return;let r=y(e,"utf-8"),n=new Date().toISOString().replace(/[:.]/g,"-"),a=u(this.baseDir,"_versions",t.replace(/\.md$/,""));$(a,{recursive:!0}),b(u(a,`${n}.md`),r)}catch{}}getVersions(t){let e=u(this.baseDir,"_versions",t.replace(/\.md$/,""));if(!w(e))return[];try{return v(e).filter(r=>r.endsWith(".md")).sort().reverse().map(r=>({timestamp:r.replace(/\.md$/,"").replace(/-/g,(n,a)=>a<19?a===10?"T":a===13||a===16?":":"-":n),path:u(e,r)}))}catch{return[]}}restoreVersion(t,e){let n=this.getVersions(t).find(a=>a.timestamp.startsWith(e));if(!n)return!1;try{let a=y(n.path,"utf-8"),s=u(this.baseDir,t);return this.saveVersion(t,s),b(s,a),this.appendLog("restore",`${t} restored to ${e}`),!0}catch{return!1}}readArticle(t){let e=u(this.baseDir,t);if(!w(e))return null;let r=y(e,"utf-8");return this.parseArticle(r,t)}readArticleAs(t,e){let r=this.readArticle(t);return!r||!this.canRead(r.meta,e)?null:r}parseArticle(t,e){let r=t.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);if(!r)return null;let n=r[1],a=r[2].trim(),s=m=>n.match(new RegExp(`^${m}:\\s*(.+)$`,"m"))?.[1]?.trim().replace(/^"(.*)"$/,"$1")||"",o=m=>{let h=n.match(new RegExp(`^${m}:\\s*\\[(.*)\\]$`,"m"));return h?h[1].split(",").map(f=>f.trim().replace(/^"(.*)"$/,"$1")).filter(Boolean):[]},i=s("type")||s("kind"),l=new Set(["person","project","place","concept","event","decision","pattern"]).has(i)?i:void 0,p=o("tags").filter((m,h,f)=>m&&f.indexOf(m)===h),d=o("related"),g=o("graph_path");return{meta:{title:s("title"),type:l,related:d.length?d:void 0,tags:p,owner:s("owner"),access:s("access")||"public",sharedWith:o("shared_with"),created:s("created"),lastUpdated:s("last_updated"),sources:o("sources"),graphPath:g.length?g:void 0},content:a,path:e}}listCache=new Map;listArticles(t){let e=[],r=[];this.walkDir(this.baseDir,(o,i)=>{if(!o.endsWith(".md"))return;let c=k(this.baseDir,o);c.startsWith("raw/")||c.startsWith("_")||(e.push(c),r.push(`${c}:${i?.mtimeMs??"?"}:${i?.size??"?"}`))});let n=r.join("|"),a=this.listCache.get(t);if(a&&a.signature===n)return a.articles.slice();let s=[];for(let o of e){let i=this.readArticle(o);i&&this.canRead(i.meta,t)&&s.push(i)}return this.listCache.set(t,{signature:n,articles:s}),s.slice()}search(t,e,r=10){let n=t.toLowerCase(),a=[];if(this.walkDir(this.baseDir,d=>{if(!d.endsWith(".md"))return;let g=k(this.baseDir,d);if(g.startsWith("raw/")||g.startsWith("_"))return;let m=this.readArticle(g);!m||!this.canRead(m.meta,e)||a.push(m)}),a.length===0)return[];let s=a.map(d=>d.content),o=u(this.baseDir,"_bm25_cache.json"),i=D(s,o),c=A(t,i),l=new Map(c.map(d=>[d.docIndex,d.score]));return a.map((d,g)=>{let m=l.get(g)??0;return d.meta.title.toLowerCase().includes(n)&&(m+=10),d.meta.tags?.some(h=>h.toLowerCase().includes(n))&&(m+=5),{article:d,score:m}}).filter(d=>d.score>0).sort((d,g)=>g.score-d.score).slice(0,r).map(d=>d.article)}async findRelevantReranked(t,e,r=10,n={}){let a=Math.max(r,n.shortlist??_),s=this.findRelevant(t,e,a);if(s.length<2)return s.slice(0,r);let o=s.map((l,p)=>({id:`c${p}`,title:l.meta.title||`(untitled ${p})`,tags:l.meta.tags,excerpt:l.content})),i=await x(L,R({query:t,candidates:o,excerptChars:n.excerptChars}),j(o),{incumbent:{best:o[0].id},features:{agent:e??"unknown"}});return!i||i.mode!=="active"?s.slice(0,r):M(i.answers,o).ranked.map(l=>s[Number(l.slice(1))]).filter(l=>!!l).slice(0,r)}findRelevant(t,e,r=3,n,a={graph:.6,bm25:.4}){let s=[];if(this.walkDir(this.baseDir,h=>{if(!h.endsWith(".md"))return;let f=k(this.baseDir,h);if(f.startsWith("raw/")||f.startsWith("_"))return;let W=this.readArticle(f);!W||!this.canRead(W.meta,e)||s.push(W)}),s.length===0)return[];let o=s.map(h=>`${h.meta.title} ${(h.meta.tags||[]).join(" ")} ${h.content}`),i=u(this.baseDir,"_bm25_relevance_cache.json"),c=D(o,i),l=A(t,c),p=l.reduce((h,f)=>Math.max(h,f.score),0)||1,d=new Map(l.map(h=>[h.docIndex,h.score/p])),g=!!(n&&n.length>0);return s.map((h,f)=>{let W=d.get(f)??0,S=0;g&&h.meta.graphPath?.length&&(S=I(n,h.meta.graphPath));let E=g?a.graph*S+a.bm25*W:W;return{article:h,score:E}}).filter(h=>h.score>0).sort((h,f)=>f.score-h.score).slice(0,r).map(h=>h.article)}buildContext(t,e=4e3){if(t.length===0)return"";let r=["[Wiki Knowledge]"],n=0;for(let a of t){let s=`
@@ -102,4 +102,4 @@ We use GitLab for version control.
102
102
  There are ${e.length} unprocessed entries. Read each, understand what it means, and create or update wiki articles.
103
103
 
104
104
  ${r}`}walkDir(t,e){if(w(t))for(let r of v(t)){let n=N(t,r),a=B(n);a.isDirectory()?this.walkDir(n,e):e(n,a)}}};export{T as a};
105
- //# sourceMappingURL=chunk-3D3B4NQ7.js.map
105
+ //# sourceMappingURL=chunk-5PEOSZ44.js.map
@@ -1,2 +1,2 @@
1
- import{a as o}from"./chunk-3D3B4NQ7.js";import{resolve as a}from"path";import{existsSync as d,readdirSync as c,mkdirSync as l}from"fs";var g=class{baseDir;agentsDir;mode;sharedStore;agentStores=new Map;log;constructor(t=a(process.cwd(),".agentx/wiki"),e=console.error.bind(console,"[wiki-hub]"),r="graph"){this.baseDir=t,this.agentsDir=a(t,"agents"),this.mode=r,this.log=e,l(this.agentsDir,{recursive:!0}),this.sharedStore=new o(t,e)}getMode(){return this.mode}getAgentWiki(t){let e=`${t}:${this.mode}`;if(this.agentStores.has(e))return this.agentStores.get(e);let r=a(this.agentsDir,t,this.mode),i=new o(r,this.log);return this.agentStores.set(e,i),i}getBaseDir(){return this.baseDir}getSharedStore(){return this.sharedStore}listAgents(){let t=new Set,e=this.sharedStore.listEntries();for(let r of e)t.add(r.agentId);if(d(this.agentsDir))for(let r of c(this.agentsDir))!r.startsWith("_")&&!r.startsWith(".")&&t.add(r);return[...t].sort()}getAgentEntries(t){return this.sharedStore.listEntries({agentId:t})}getUnabsorbedEntries(t){let e=this.getAgentWiki(t),r=this.getAgentEntries(t),i=new Set,n=e.rebuildIndex();for(let s of n.articles)if(s.sources)for(let h of s.sources)i.add(h);return r.filter(s=>!i.has(s.id))}summary(){return this.listAgents().map(e=>{let r=this.getAgentEntries(e),n=this.getAgentWiki(e).rebuildIndex(),s=this.getUnabsorbedEntries(e);return{agentId:e,totalEntries:r.length,totalArticles:n.articles.length,unabsorbed:s.length,articles:n.articles}})}};export{g as a};
2
- //# sourceMappingURL=chunk-Y3C37PF5.js.map
1
+ import{a as o}from"./chunk-5PEOSZ44.js";import{resolve as a}from"path";import{existsSync as d,readdirSync as c,mkdirSync as l}from"fs";var g=class{baseDir;agentsDir;mode;sharedStore;agentStores=new Map;log;constructor(t=a(process.cwd(),".agentx/wiki"),e=console.error.bind(console,"[wiki-hub]"),r="graph"){this.baseDir=t,this.agentsDir=a(t,"agents"),this.mode=r,this.log=e,l(this.agentsDir,{recursive:!0}),this.sharedStore=new o(t,e)}getMode(){return this.mode}getAgentWiki(t){let e=`${t}:${this.mode}`;if(this.agentStores.has(e))return this.agentStores.get(e);let r=a(this.agentsDir,t,this.mode),i=new o(r,this.log);return this.agentStores.set(e,i),i}getBaseDir(){return this.baseDir}getSharedStore(){return this.sharedStore}listAgents(){let t=new Set,e=this.sharedStore.listEntries();for(let r of e)t.add(r.agentId);if(d(this.agentsDir))for(let r of c(this.agentsDir))!r.startsWith("_")&&!r.startsWith(".")&&t.add(r);return[...t].sort()}getAgentEntries(t){return this.sharedStore.listEntries({agentId:t})}getUnabsorbedEntries(t){let e=this.getAgentWiki(t),r=this.getAgentEntries(t),i=new Set,n=e.rebuildIndex();for(let s of n.articles)if(s.sources)for(let h of s.sources)i.add(h);return r.filter(s=>!i.has(s.id))}summary(){return this.listAgents().map(e=>{let r=this.getAgentEntries(e),n=this.getAgentWiki(e).rebuildIndex(),s=this.getUnabsorbedEntries(e);return{agentId:e,totalEntries:r.length,totalArticles:n.articles.length,unabsorbed:s.length,articles:n.articles}})}};export{g as a};
2
+ //# sourceMappingURL=chunk-ANJ2BO7D.js.map
@@ -1,5 +1,5 @@
1
- import{aa as m,da as b}from"./chunk-QA4RTSKI.js";b();function w(t){let e=typeof t.node=="string"?t.node:"",n=typeof t.token=="string"?t.token:"";if(!e||!n)try{let o=m(t.config);e||(e=o.dashboard?.daemonUrl||""),n||(n=o.dashboard?.token||"")}catch{}return e||(e="http://localhost:18800"),{baseUrl:e.replace(/\/+$/,""),token:n}}async function d(t,e,n){let o={Accept:"application/json"};t.token&&(o.Authorization=`Bearer ${t.token}`);let r=await fetch(`${t.baseUrl}${e}`,{headers:o,signal:n});if(!r.ok)throw new Error(`GET ${e} \u2192 HTTP ${r.status}`);return await r.json()}function R(t,e){return d(t,"/agents",e)}async function S(t,e){return(await d(t,"/api/processes",e)).processes??[]}function P(t,e){return d(t,"/crons",e)}async function h(t,e,n,o){let r={Accept:"application/json","Content-Type":"application/json"};t.token&&(r.Authorization=`Bearer ${t.token}`);let s=await fetch(`${t.baseUrl}${e}`,{method:"POST",headers:r,body:JSON.stringify(n),signal:o}),a=await s.text(),i;try{i=a?JSON.parse(a):{}}catch{i={raw:a}}if(!s.ok)throw new Error(i?.error||`POST ${e} \u2192 HTTP ${s.status}`);return i}function A(t,e,n="tui"){return h(t,"/api/processes/kill",{...e,reason:n})}function C(t,e,n,o){return h(t,"/task",{agent:e,message:n,context:o??{channel:"tui",chatId:"tui:operator"}})}async function $(t,e,n,o={}){let r={Accept:"text/event-stream","Content-Type":"application/json"};t.token&&(r.Authorization=`Bearer ${t.token}`);let s=await fetch(`${t.baseUrl}/task`,{method:"POST",headers:r,body:JSON.stringify({agent:e,message:n,stream:!0,context:{channel:o.channel??"chat-cli",chatId:o.chatId??"chat-cli:operator"}}),signal:o.signal});if(!s.ok||!s.body){let g=await s.text().catch(()=>"");throw new Error(`POST /task (stream) \u2192 HTTP ${s.status}${g?`: ${g.slice(0,200)}`:""}`)}let a=s.body.getReader(),i=new TextDecoder,u={content:""},c="";try{for(;;){let{done:g,value:p}=await a.read();if(g)break;c+=i.decode(p,{stream:!0});let l;for(;(l=c.indexOf(`
1
+ import{ca as m,fa as b}from"./chunk-GO57OXET.js";b();function w(t){let e=typeof t.node=="string"?t.node:"",n=typeof t.token=="string"?t.token:"";if(!e||!n)try{let o=m(t.config);e||(e=o.dashboard?.daemonUrl||""),n||(n=o.dashboard?.token||"")}catch{}return e||(e="http://localhost:18800"),{baseUrl:e.replace(/\/+$/,""),token:n}}async function d(t,e,n){let o={Accept:"application/json"};t.token&&(o.Authorization=`Bearer ${t.token}`);let r=await fetch(`${t.baseUrl}${e}`,{headers:o,signal:n});if(!r.ok)throw new Error(`GET ${e} \u2192 HTTP ${r.status}`);return await r.json()}function R(t,e){return d(t,"/agents",e)}async function S(t,e){return(await d(t,"/api/processes",e)).processes??[]}function P(t,e){return d(t,"/crons",e)}async function h(t,e,n,o){let r={Accept:"application/json","Content-Type":"application/json"};t.token&&(r.Authorization=`Bearer ${t.token}`);let s=await fetch(`${t.baseUrl}${e}`,{method:"POST",headers:r,body:JSON.stringify(n),signal:o}),a=await s.text(),i;try{i=a?JSON.parse(a):{}}catch{i={raw:a}}if(!s.ok)throw new Error(i?.error||`POST ${e} \u2192 HTTP ${s.status}`);return i}function A(t,e,n="tui"){return h(t,"/api/processes/kill",{...e,reason:n})}function C(t,e,n,o){return h(t,"/task",{agent:e,message:n,context:o??{channel:"tui",chatId:"tui:operator"}})}async function $(t,e,n,o={}){let r={Accept:"text/event-stream","Content-Type":"application/json"};t.token&&(r.Authorization=`Bearer ${t.token}`);let s=await fetch(`${t.baseUrl}/task`,{method:"POST",headers:r,body:JSON.stringify({agent:e,message:n,stream:!0,context:{channel:o.channel??"chat-cli",chatId:o.chatId??"chat-cli:operator"}}),signal:o.signal});if(!s.ok||!s.body){let g=await s.text().catch(()=>"");throw new Error(`POST /task (stream) \u2192 HTTP ${s.status}${g?`: ${g.slice(0,200)}`:""}`)}let a=s.body.getReader(),i=new TextDecoder,u={content:""},c="";try{for(;;){let{done:g,value:p}=await a.read();if(g)break;c+=i.decode(p,{stream:!0});let l;for(;(l=c.indexOf(`
2
2
 
3
3
  `))>=0;){let k=c.slice(0,l);c=c.slice(l+2);let f=x(k);f&&T(f,o,u)}}}finally{try{a.releaseLock()}catch{}}return u}function T(t,e,n){let{event:o,data:r}=t;switch(o){case"text":r?.text&&(n.content+=r.text,e.onText?.(r.text));break;case"thinking":r?.text&&e.onThinking?.(r.text);break;case"tool":e.onTool?.(r);break;case"done":typeof r?.content=="string"&&(n.content=r.content),n.usage=r?.usage,n.duration=r?.duration;break;case"error":n.error=r?.error,n.errorKind=r?.errorKind;break}}function x(t){let e="message",n="";for(let r of t.split(`
4
4
  `))r.startsWith("event: ")?e=r.slice(7).trim():r.startsWith("data: ")&&(n=r.slice(6));if(!n)return null;let o;try{o=JSON.parse(n)}catch{o=n}return{event:e,data:o}}export{w as a,R as b,S as c,P as d,A as e,C as f,$ as g};
5
- //# sourceMappingURL=chunk-OFV34UZY.js.map
5
+ //# sourceMappingURL=chunk-AXW5U32B.js.map
@@ -1,4 +1,4 @@
1
- import{a as j,b as O,c as T,d as D,e as _,j as N}from"./chunk-3VP3UWNT.js";import{b as R}from"./chunk-2GIDVZ4H.js";import{v as C,w as I}from"./chunk-DA2NTRUR.js";import{b as v,c as W}from"./chunk-QOYAX2FT.js";import{readFileSync as Y,existsSync as B}from"fs";I();import{resolve as x}from"path";import{execSync as L}from"child_process";async function nt(n,a,o,t={}){let u=t.selectorModel??"haiku",g=t.synthModel??"sonnet",l=t.maxCandidates??3,r=t.maxHops??2,s=t.maxArticles??8,h=t.timeoutMs??6e4,p=t.log??console.error.bind(console,"[wiki-query]"),m=t.messagePath?.length?t.messagePath:void 0,w=t.graphWeight??$,i=x(a.baseDir,"_index.md");if(!B(i))return A("no-catalog",n,"No _index.md found \u2014 run `agentx wiki status` to rebuild.");let e=Y(i,"utf-8"),d=Date.now(),f=[],y="";try{let c=await G(n,a,o,l,m,w);c?(f=c,y=`[wiki-rerank seat] ${c.map(k=>k.title).join(" | ")}`):(y=await Q(q(n,e,l,m),u,h),f=K(y))}catch(c){return p("selector failed:",c?.message),{...A("error",n,`Selector: ${c?.message||"unknown"}`),trace:{selectorMs:Date.now()-d,synthesisMs:0,selectorOutput:y}}}let S=Date.now()-d;if(f.length===0)return{...A("no-candidates",n,"Selector returned no candidates."),trace:{selectorMs:S,synthesisMs:0,selectorOutput:y}};let b=F(f,a,o,r,s);if(b.length===0)return{...A("no-candidates",n,"Candidates did not resolve to readable articles."),candidates:f,trace:{selectorMs:S,synthesisMs:0,selectorOutput:y}};let M=Date.now(),P="";try{P=await Q(J(n,b),g,h*2)}catch(c){return p("synthesis failed:",c?.message),{...A("error",n,`Synthesis: ${c?.message||"unknown"}`),candidates:f,walked:b.map(k=>({title:k.meta.title,path:k.path,type:k.meta.type,hop:k.hop??0})),trace:{selectorMs:S,synthesisMs:Date.now()-M,selectorOutput:y}}}let E=Date.now()-M;return{answer:P.trim(),citations:b.map(c=>({title:c.meta.title,path:c.path,type:c.meta.type})),candidates:f,walked:b.map(c=>({title:c.meta.title,path:c.path,type:c.meta.type,hop:c.hop??0})),status:"ok",trace:{selectorMs:S,synthesisMs:E,selectorOutput:y}}}function A(n,a,o){return{answer:"",citations:[],candidates:[],walked:[],status:n,error:o}}function F(n,a,o,t,u){let g=new Map;for(let s of a.listArticles(o||""))g.set(s.meta.title.toLowerCase(),s.path);let l=new Map,r=[];for(let s of n)l.has(s.path)||r.push({path:s.path,hop:0});for(;r.length&&l.size<u;){let s=r.shift();if(l.has(s.path)||s.hop>t)continue;let h=o?a.readArticleAs(s.path,o):a.readArticle(s.path);if(h&&(l.set(s.path,{...h,hop:s.hop}),!(s.hop>=t)))for(let p of h.meta.related||[]){let m=g.get(p.toLowerCase());m&&!l.has(m)&&r.push({path:m,hop:s.hop+1})}}return Array.from(l.values())}async function G(n,a,o,t,u,g=$){try{let r=(a.rebuildIndex().articles??[]).filter(i=>i.path&&!i.path.includes("/_versions/"));if(r.length<2)return null;let h=H(n,r,u,g).slice(0,O).map(i=>({id:`k${i}`,title:r[i].title||r[i].path,tags:r[i].tags,excerpt:[r[i].type?`type: ${r[i].type}`:"",(r[i].related??[]).length?`related: ${(r[i].related??[]).join(", ")}`:"",(r[i].graphPath??[]).length?`graph: ${(r[i].graphPath??[]).join(" \u203A ")}`:""].filter(Boolean).join(" \xB7 ")})),p=await C(j,T({query:n,candidates:h,excerptChars:300}),D(h),{features:{agent:o??"unknown",stage:"catalog-selector"}});if(!p||p.mode!=="active")return null;let w=_(p.answers,h).ranked.slice(0,t).map(i=>r[Number(i.slice(1))]).filter(Boolean).map(i=>({title:i.title,path:i.path}));return w.length>0?w:null}catch{return null}}var $=.6;function H(n,a,o,t=$){let u=a.map(e=>[e.title,(e.tags??[]).join(" "),(e.related??[]).join(" ")].join(" ")),g=W(n,v(u)),l=g.reduce((e,d)=>Math.max(e,d.score),0),r=new Map(g.map(e=>[e.docIndex,l>0?e.score/l:0])),s=!!o?.length,h=e=>s&&e.graphPath?.length?N(o,e.graphPath):0,p=(e,d)=>d.score-e.score||e.i-d.i,m=a.map((e,d)=>({i:d,score:(r.get(d)??0)*(1+t*h(e))})).filter(e=>r.has(e.i)).sort(p),w=a.map((e,d)=>({i:d,score:h(e)})).filter(e=>!r.has(e.i)&&e.score>0).sort(p),i=[...m,...w].map(e=>e.i);for(let e=0;e<a.length;e++)i.includes(e)||i.push(e);return i}function q(n,a,o,t){let u=t?.length?`
1
+ import{a as j,b as O,c as T,d as D,e as _,j as N}from"./chunk-QIJOGYK5.js";import{b as R}from"./chunk-2GIDVZ4H.js";import{v as C,w as I}from"./chunk-WBJLVFBW.js";import{b as v,c as W}from"./chunk-QOYAX2FT.js";import{readFileSync as Y,existsSync as B}from"fs";I();import{resolve as x}from"path";import{execSync as L}from"child_process";async function nt(n,a,o,t={}){let u=t.selectorModel??"haiku",g=t.synthModel??"sonnet",l=t.maxCandidates??3,r=t.maxHops??2,s=t.maxArticles??8,h=t.timeoutMs??6e4,p=t.log??console.error.bind(console,"[wiki-query]"),m=t.messagePath?.length?t.messagePath:void 0,w=t.graphWeight??$,i=x(a.baseDir,"_index.md");if(!B(i))return A("no-catalog",n,"No _index.md found \u2014 run `agentx wiki status` to rebuild.");let e=Y(i,"utf-8"),d=Date.now(),f=[],y="";try{let c=await G(n,a,o,l,m,w);c?(f=c,y=`[wiki-rerank seat] ${c.map(k=>k.title).join(" | ")}`):(y=await Q(q(n,e,l,m),u,h),f=K(y))}catch(c){return p("selector failed:",c?.message),{...A("error",n,`Selector: ${c?.message||"unknown"}`),trace:{selectorMs:Date.now()-d,synthesisMs:0,selectorOutput:y}}}let S=Date.now()-d;if(f.length===0)return{...A("no-candidates",n,"Selector returned no candidates."),trace:{selectorMs:S,synthesisMs:0,selectorOutput:y}};let b=F(f,a,o,r,s);if(b.length===0)return{...A("no-candidates",n,"Candidates did not resolve to readable articles."),candidates:f,trace:{selectorMs:S,synthesisMs:0,selectorOutput:y}};let M=Date.now(),P="";try{P=await Q(J(n,b),g,h*2)}catch(c){return p("synthesis failed:",c?.message),{...A("error",n,`Synthesis: ${c?.message||"unknown"}`),candidates:f,walked:b.map(k=>({title:k.meta.title,path:k.path,type:k.meta.type,hop:k.hop??0})),trace:{selectorMs:S,synthesisMs:Date.now()-M,selectorOutput:y}}}let E=Date.now()-M;return{answer:P.trim(),citations:b.map(c=>({title:c.meta.title,path:c.path,type:c.meta.type})),candidates:f,walked:b.map(c=>({title:c.meta.title,path:c.path,type:c.meta.type,hop:c.hop??0})),status:"ok",trace:{selectorMs:S,synthesisMs:E,selectorOutput:y}}}function A(n,a,o){return{answer:"",citations:[],candidates:[],walked:[],status:n,error:o}}function F(n,a,o,t,u){let g=new Map;for(let s of a.listArticles(o||""))g.set(s.meta.title.toLowerCase(),s.path);let l=new Map,r=[];for(let s of n)l.has(s.path)||r.push({path:s.path,hop:0});for(;r.length&&l.size<u;){let s=r.shift();if(l.has(s.path)||s.hop>t)continue;let h=o?a.readArticleAs(s.path,o):a.readArticle(s.path);if(h&&(l.set(s.path,{...h,hop:s.hop}),!(s.hop>=t)))for(let p of h.meta.related||[]){let m=g.get(p.toLowerCase());m&&!l.has(m)&&r.push({path:m,hop:s.hop+1})}}return Array.from(l.values())}async function G(n,a,o,t,u,g=$){try{let r=(a.rebuildIndex().articles??[]).filter(i=>i.path&&!i.path.includes("/_versions/"));if(r.length<2)return null;let h=H(n,r,u,g).slice(0,O).map(i=>({id:`k${i}`,title:r[i].title||r[i].path,tags:r[i].tags,excerpt:[r[i].type?`type: ${r[i].type}`:"",(r[i].related??[]).length?`related: ${(r[i].related??[]).join(", ")}`:"",(r[i].graphPath??[]).length?`graph: ${(r[i].graphPath??[]).join(" \u203A ")}`:""].filter(Boolean).join(" \xB7 ")})),p=await C(j,T({query:n,candidates:h,excerptChars:300}),D(h),{features:{agent:o??"unknown",stage:"catalog-selector"}});if(!p||p.mode!=="active")return null;let w=_(p.answers,h).ranked.slice(0,t).map(i=>r[Number(i.slice(1))]).filter(Boolean).map(i=>({title:i.title,path:i.path}));return w.length>0?w:null}catch{return null}}var $=.6;function H(n,a,o,t=$){let u=a.map(e=>[e.title,(e.tags??[]).join(" "),(e.related??[]).join(" ")].join(" ")),g=W(n,v(u)),l=g.reduce((e,d)=>Math.max(e,d.score),0),r=new Map(g.map(e=>[e.docIndex,l>0?e.score/l:0])),s=!!o?.length,h=e=>s&&e.graphPath?.length?N(o,e.graphPath):0,p=(e,d)=>d.score-e.score||e.i-d.i,m=a.map((e,d)=>({i:d,score:(r.get(d)??0)*(1+t*h(e))})).filter(e=>r.has(e.i)).sort(p),w=a.map((e,d)=>({i:d,score:h(e)})).filter(e=>!r.has(e.i)&&e.score>0).sort(p),i=[...m,...w].map(e=>e.i);for(let e=0;e<a.length;e++)i.includes(e)||i.push(e);return i}function q(n,a,o,t){let u=t?.length?`
2
2
  ## Intent
3
3
 
4
4
  The request was classified under the intent-graph path "${t.join(" \u203A ")}". Prefer articles filed under the same branch when their titles are equally plausible.
@@ -46,4 +46,4 @@ ${o}
46
46
  Answer the question in 2\u20136 sentences. Cite articles by their title in square brackets like [Article Title]. If the articles do not answer the question, say so plainly (do not invent). Prefer concrete facts over hedging.
47
47
 
48
48
  Output ONLY the answer \u2014 no preamble, no "here is my answer:", no markdown fencing.`}function K(n){let a=n.match(/\[[\s\S]*?\]/);if(!a)return[];try{let o=JSON.parse(a[0]);return Array.isArray(o)?o.filter(t=>t&&typeof t.title=="string"&&typeof t.path=="string").map(t=>({title:t.title,path:t.path})):[]}catch{return[]}}async function Q(n,a,o){let{writeFileSync:t,mkdirSync:u,rmSync:g}=await import("fs"),{tmpdir:l}=await import("os"),r=x(l(),`agentx-wiki-query-${process.pid}`);u(r,{recursive:!0});let s=x(r,`prompt-${Date.now()}.txt`);t(s,n);try{let h=`cat '${s}' | claude -p - --output-format json --max-turns 1 --model ${a} --disallowedTools "Bash Read Write Edit Glob Grep Agent WebSearch WebFetch NotebookEdit"`,p=L(h,{env:R({...process.env}),encoding:"utf-8",timeout:o,maxBuffer:4*1024*1024});try{let m=JSON.parse(p);return String(m.result||m.content||"")}catch{return p}}finally{try{g(s,{force:!0})}catch{}}}export{nt as a,$ as b,H as c};
49
- //# sourceMappingURL=chunk-AYHVNISD.js.map
49
+ //# sourceMappingURL=chunk-CZ4CWVDE.js.map
@@ -1,4 +1,4 @@
1
- import{a as Se}from"./chunk-GTJIKXDB.js";import{a as w}from"./chunk-CL53UVOF.js";import{q as Wt}from"./chunk-S2GAEH2F.js";import{t as jt,u as Vt}from"./chunk-4GNAOJ7P.js";import{d as Ot,e as Nt}from"./chunk-AQASR6KR.js";import{c as xe,e as B,f as U,h as Ft}from"./chunk-XIYWXCNU.js";import{A as ke,b as be,v as At,x as Q,y as we}from"./chunk-ZVUEJXCY.js";import{a as Pt,b as Lt,d as Mt}from"./chunk-Y4CYQV7G.js";import{a as It,b as Rt}from"./chunk-SHEUCITK.js";import{g as _t,h as Ct,i as Dt,k as Et,l as Tt}from"./chunk-5DUPIMOI.js";import{q as $t}from"./chunk-6NE2GLO6.js";import{a as St,b as vt}from"./chunk-ZJJJM7AR.js";import{$ as wt,U as ye,aa as kt,da as xt,m as Z,n as gt,o as mt,p as Tr,u as yt,v as bt,w as Mr}from"./chunk-QA4RTSKI.js";import{a as ht,i as Lr}from"./chunk-PN6XHTG5.js";import{a as he,h as Pr}from"./chunk-BRK6M6LA.js";import{existsSync as Or,readdirSync as Nr,readFileSync as jr,statSync as Vr}from"fs";import{resolve as Wr}from"path";function Bt(t,e,n=Date.now(),i=7){let r=i*864e5,s=new Map;for(let o of e){let a=s.get(o.workflowId);a?a.push(o):s.set(o.workflowId,[o])}return t.map(o=>{let a=s.get(o.id)??[],c=a.filter(g=>n-g.at<=r),l=a.filter(g=>n-g.at>r&&n-g.at<=r*2),u=c.filter(g=>g.status==="failed").length,d=a.filter(g=>g.status==="paused").length,p=a.length?Math.max(...a.map(g=>g.at)):null,f=a.length?l.length>0&&c.length===0?"dormant":c.length>0&&u*2>=c.length?"failing":c.length>0?"active":"quiet":"never";return{id:o.id,name:o.name||o.id,state:f,lastRunAt:p,recent:c.length,prior:l.length,failed:u,paused:d}}).sort((o,a)=>{let c={dormant:0,failing:1,active:2,quiet:3,never:4};return c[o.state]-c[a.state]||(a.lastRunAt??0)-(o.lastRunAt??0)})}var ee=new Map;function ra(t,e=1e3){if(!Or(t))return[];let n=Nr(t).filter(s=>s.endsWith(".jsonl")).map(s=>{let o=Wr(t,s);return{path:o,mtime:Vr(o).mtimeMs}}).sort((s,o)=>o.mtime-s.mtime).slice(0,e),i=new Set(n.map(s=>s.path));for(let s of ee.keys())i.has(s)||ee.delete(s);let r=[];for(let{path:s,mtime:o}of n){let a=ee.get(s);if(a&&a.mtime===o){a.summary&&r.push(a.summary);continue}let c=Fr(s,o);ee.set(s,{mtime:o,summary:c}),c&&r.push(c)}return r}function Fr(t,e){try{let n=jr(t,"utf-8").split(`
1
+ import{a as Se}from"./chunk-GTJIKXDB.js";import{a as w}from"./chunk-CL53UVOF.js";import{q as Wt}from"./chunk-S2GAEH2F.js";import{t as jt,u as Vt}from"./chunk-VQVN3VSJ.js";import{d as Ot,e as Nt}from"./chunk-AQASR6KR.js";import{c as xe,e as B,f as U,h as Ft}from"./chunk-XIYWXCNU.js";import{A as ke,b as be,v as At,x as Q,y as we}from"./chunk-FRWV3XOV.js";import{a as Pt,b as Lt,d as Mt}from"./chunk-Y4CYQV7G.js";import{a as It,b as Rt}from"./chunk-SHEUCITK.js";import{g as _t,h as Ct,i as Dt,k as Et,l as Tt}from"./chunk-RLSRENAO.js";import{q as $t}from"./chunk-TICACOQG.js";import{a as St,b as vt}from"./chunk-SPSICIEA.js";import{W as ye,ba as wt,ca as kt,fa as xt,m as Z,n as gt,o as mt,p as Tr,u as yt,v as bt,w as Mr}from"./chunk-GO57OXET.js";import{a as ht,i as Lr}from"./chunk-PN6XHTG5.js";import{a as he,h as Pr}from"./chunk-BRK6M6LA.js";import{existsSync as Or,readdirSync as Nr,readFileSync as jr,statSync as Vr}from"fs";import{resolve as Wr}from"path";function Bt(t,e,n=Date.now(),i=7){let r=i*864e5,s=new Map;for(let o of e){let a=s.get(o.workflowId);a?a.push(o):s.set(o.workflowId,[o])}return t.map(o=>{let a=s.get(o.id)??[],c=a.filter(g=>n-g.at<=r),l=a.filter(g=>n-g.at>r&&n-g.at<=r*2),u=c.filter(g=>g.status==="failed").length,d=a.filter(g=>g.status==="paused").length,p=a.length?Math.max(...a.map(g=>g.at)):null,f=a.length?l.length>0&&c.length===0?"dormant":c.length>0&&u*2>=c.length?"failing":c.length>0?"active":"quiet":"never";return{id:o.id,name:o.name||o.id,state:f,lastRunAt:p,recent:c.length,prior:l.length,failed:u,paused:d}}).sort((o,a)=>{let c={dormant:0,failing:1,active:2,quiet:3,never:4};return c[o.state]-c[a.state]||(a.lastRunAt??0)-(o.lastRunAt??0)})}var ee=new Map;function ra(t,e=1e3){if(!Or(t))return[];let n=Nr(t).filter(s=>s.endsWith(".jsonl")).map(s=>{let o=Wr(t,s);return{path:o,mtime:Vr(o).mtimeMs}}).sort((s,o)=>o.mtime-s.mtime).slice(0,e),i=new Set(n.map(s=>s.path));for(let s of ee.keys())i.has(s)||ee.delete(s);let r=[];for(let{path:s,mtime:o}of n){let a=ee.get(s);if(a&&a.mtime===o){a.summary&&r.push(a.summary);continue}let c=Fr(s,o);ee.set(s,{mtime:o,summary:c}),c&&r.push(c)}return r}function Fr(t,e){try{let n=jr(t,"utf-8").split(`
2
2
  `).filter(Boolean);if(!n.length)return null;let i=JSON.parse(n[0]),r=i.run?.workflowId;if(!r)return null;let s=i.run?.status??"unknown";for(let o=n.length-1;o>=0;o--){let a=JSON.parse(n[o]),c=a.status??a.run?.status;if(c){s=c;break}}return{workflowId:r,status:s,at:e}}catch{return null}}var Br={failStreak:3,disabledDays:30,missedFires:2,graceMs:15*6e4},k={routines:200,summary:160,filters:6,filterValue:60,text:120},Ur=(t,e,n)=>{try{return $t(t,e,n)}catch{return null}},Ut=864e5;function aa(t){let e=t.now??Date.now(),n={...Br,...t.thresholds},i=t.nextFire??Ur,r=[];for(let a of t.crons){let c=t.cronRuns.get(a.id)??[],l=a.timezone||"UTC",u=c.map(f=>({at:Date.parse(f.startedAt),status:f.status})),d=c[0],p={id:`cron:${a.id}`,source:"cron",kind:"schedule",name:$(a.id,k.text),trigger:{schedule:$(a.schedule,k.text),timezone:l},agent:a.agent||null,enabled:a.enabled,state:a.enabled?"enabled":"disabled",nextRunAt:a.enabled?ve(a.nextRun)??ve(i(a.schedule,new Date(e),l)):null,lastRun:d?{at:d.startedAt,status:d.status,summary:Xr(d.status==="success"?void 0:d.errorSummary,k.summary)}:null,lastSuccessAt:c.find(f=>f.status==="success")?.startedAt??null,consecutiveFailures:zt(u),sampledRuns:c.length,flags:[],attention:null};p.flags=Ht(p,u,a.schedule,l,null,e,n,i),r.push(qt(p))}let s=new Map(Bt(t.workflows.map(a=>({id:a.id,name:a.title})),t.workflowRuns,e).map(a=>[a.id,a])),o=new Map;for(let a of t.workflowRuns){let c=o.get(a.workflowId);c?c.push(a):o.set(a.workflowId,[a])}for(let a of t.workflows){let c=a.nodes.find(I=>I.type.startsWith("trigger."));if(!c||c.type!=="trigger.cron"&&c.type!=="trigger.hook")continue;let l=c.config??{},u=a.state||"active",d=u==="active",p=(o.get(a.id)??[]).slice().sort((I,me)=>me.at-I.at),f=p.map(I=>({at:I.at,status:qr(I.status)})),g=f[0],h=c.type==="trigger.cron",y=typeof l.spec=="string"?l.spec:"",D=typeof l.timezone=="string"?l.timezone:"UTC",N={id:`workflow:${a.id}`,source:"workflow",kind:h?"schedule":"event",name:$(a.title||a.id,k.text),trigger:h?{schedule:$(y,k.text),timezone:D}:{event:$(typeof l.event=="string"?l.event:"",k.text),filters:Gr(l.filter,a)},agent:Kr(a),enabled:d,state:u,nextRunAt:h&&d&&y?ve(i(y,new Date(e),D)):null,lastRun:g?{at:new Date(g.at).toISOString(),status:g.status}:null,lastSuccessAt:(()=>{let I=f.find(me=>me.status==="success");return I?new Date(I.at).toISOString():null})(),consecutiveFailures:zt(f),sampledRuns:p.length,flags:[],attention:null},Y=Date.parse(a.updated||a.created||"");N.flags=h?Ht(N,f,y,D,Number.isFinite(Y)?Y:null,e,n,i):zr(N,s.get(a.id)?.state==="dormant",Number.isFinite(Y)?Y:null,e,n),r.push(qt(N))}return r.sort(Hr).slice(0,k.routines)}function zt(t){let e=0;for(let n of t)if(!(n.status==="running"||n.status==="paused"||n.status==="unknown"))if(n.status==="failed"||n.status==="timeout")e++;else break;return e}function Ht(t,e,n,i,r,s,o,a){let c=[],l=e.length?e[0].at:null;if(!t.enabled){let p=Gt(l,r,s,o);return p&&c.push(p),c}if(t.consecutiveFailures>=o.failStreak&&c.push({reason:"failing",detail:`${t.consecutiveFailures} failed attempts in a row`}),l===null)return c.push({reason:"never-ran",detail:"No persisted attempt"}),c;let u=new Date(l),d=null;for(let p=0;p<o.missedFires&&(d=a(n,u,i),!!d);p++)u=d;return d&&s>d.getTime()+o.graceMs&&c.push({reason:"overdue",detail:`No attempt since ${new Date(l).toISOString()}; ${o.missedFires} scheduled fires missed`}),c}function zr(t,e,n,i,r){let s=[],o=t.lastRun?Date.parse(t.lastRun.at):null;if(!t.enabled){let a=Gt(o,n,i,r);return a&&s.push(a),s}return t.consecutiveFailures>=r.failStreak&&s.push({reason:"failing",detail:`${t.consecutiveFailures} failed runs in a row`}),o===null?s.push({reason:"never-ran",detail:"No run recorded for this trigger"}):e&&s.push({reason:"dormant",detail:"Fired in the prior week, silent in the last one"}),s}function Gt(t,e,n,i){let r=Math.max(t??0,e??0);return r&&n-r<i.disabledDays*Ut?null:{reason:"disabled-long",detail:r?`Disabled; no activity for ${Math.floor((n-r)/Ut)} days`:"Disabled and never ran"}}function qt(t){let e=new Set(t.flags.map(n=>n.reason));return t.attention=e.has("failing")?"critical":e.has("overdue")||e.has("dormant")||e.has("never-ran")?"warning":e.has("disabled-long")?"info":null,t}var Kt={critical:0,warning:1,info:2};function Hr(t,e){let n=t.attention?Kt[t.attention]:3,i=e.attention?Kt[e.attention]:3;return n-i||Number(e.enabled)-Number(t.enabled)||t.name.localeCompare(e.name)}function qr(t){switch(t){case"completed":case"ok":return"success";case"failed":return"failed";case"timeout":return"timeout";case"canceled":return"canceled";case"running":return"running";case"paused":return"paused";default:return"unknown"}}function Kr(t){if(t.ownerAgent)return $(t.ownerAgent,k.text);let e=t.nodes.find(n=>n.type==="agent"&&typeof n.config?.agentId=="string"&&n.config.agentId);return e?$(String(e.config.agentId),k.text):null}function Gr(t,e){let n=[],i=e?.project;if(i&&n.push($(`project=${i}`,k.filterValue)),t&&typeof t=="object"&&!Array.isArray(t))for(let[r,s]of Object.entries(t)){let o=Array.isArray(s)?s.map(String):s==null?[]:[String(s)];o.length&&n.push($(`${r}=${o.join(",")}`,k.filterValue))}return n.slice(0,k.filters)}function ve(t){if(!t)return null;let e=t instanceof Date?t:new Date(t);return Number.isFinite(e.getTime())?e.toISOString():null}function $(t,e){return t.length<=e?t:t.slice(0,e-3)+"..."}function Xr(t,e){return t===void 0?void 0:$(t,e)}import{existsSync as re,readdirSync as fi,readFileSync as gi}from"fs";import{resolve as E}from"path";import{randomBytes as Yt}from"crypto";import{existsSync as Yr,mkdirSync as Zr,readdirSync as Qr,readFileSync as ei,renameSync as Zt,unlinkSync as ti,writeFileSync as ni}from"fs";import{resolve as Qt}from"path";function Xt(t){return[...t.account?["--account",t.account]:[],...t.store?["--store",t.store]:[]]}var Jr=t=>t.trim().split(`
3
3
  `).pop()?.slice(0,300)||"no output";async function Jt(t,e,n,i=Se){let r=await i(t.bin,[...Xt(t),"send","text","--to",e,"--message",n,"--no-preview"],{timeoutMs:6e4});return r.code===0?{ok:!0}:{ok:!1,error:`wacli send failed: ${Jr(r.stderr||r.stdout)}`}}async function ua(t,e,n,i,r=Se){return(await r(t.bin,[...Xt(t),"--read-only","media","download","--chat",e,"--id",n,"--output",i],{timeoutMs:12e4})).code===0}var ri=2e3,ii=t=>Jt(t.wacli,t.to,t.text);function $e(t){return Qt(t,".agentx","whatsapp-triage","drafts")}var si=t=>/^[a-z0-9-]{8,64}$/.test(t),te=(t,e)=>Qt($e(t),`${e}.json`);function en(t,e){Zr($e(t),{recursive:!0});let n=te(t,e.id),i=`${n}.${process.pid}.tmp`;ni(i,JSON.stringify(e,null,2)+`
4
4
  `,{mode:384}),Zt(i,n)}function ha(t,e,n=Date.now()){let i=e.text.trim().slice(0,ri);if(!i)throw new Error("empty draft");let r={...e,text:i,id:`${n.toString(36)}-${Yt(4).toString("hex")}`,status:"pending",created_at:new Date(n).toISOString()};return en(t,r),r}function ne(t,e){if(!si(e))return null;try{return JSON.parse(ei(te(t,e),"utf-8"))}catch{return null}}function tn(t,e){let n=$e(t);return Yr(n)?Qr(n).filter(i=>i.endsWith(".json")).map(i=>ne(t,i.slice(0,-5))).filter(i=>!!i&&(!e||i.status===e)).sort((i,r)=>i.created_at.localeCompare(r.created_at)):[]}async function nn(t,e,n,i={}){let r=ne(t,e);if(!r||r.status!=="pending")return{ok:!1,error:`no reply draft "${e}" is waiting`};let s=`${te(t,e)}.${process.pid}.${Yt(3).toString("hex")}.claim`;try{Zt(te(t,e),s)}catch{return{ok:!1,error:`reply draft "${e}" is already being decided`}}let o={...r,decided_by:i.by??"operator",decided_at:new Date(i.now??Date.now()).toISOString()};if(n==="no")o.status="rejected";else{let a=await(i.send??ii)(r).catch(c=>({ok:!1,error:String(c?.message??c)}));a.ok?o.status="sent":(o.status="failed",o.error=a.error)}en(t,o);try{ti(s)}catch{}return o.status==="failed"?{ok:!1,error:o.error??"send failed"}:{ok:!0,draft:o}}import{mkdirSync as oi,readFileSync as ai,renameSync as ci,writeFileSync as li}from"fs";import{resolve as ui}from"path";function rn(t){return ui(xe(t),"_state.json")}function R(t){try{let e=JSON.parse(ai(rn(t),"utf-8"));return{snoozed:e&&typeof e.snoozed=="object"&&e.snoozed?e.snoozed:{},...typeof e?.lastDigest=="string"?{lastDigest:e.lastDigest}:{},...e?.popped&&typeof e.popped=="object"?{popped:e.popped}:{},...typeof e?.passAt=="string"?{passAt:e.passAt}:{},...Array.isArray(e?.wanted)?{wanted:e.wanted.filter(n=>typeof n=="string")}:{}}}catch{return{snoozed:{}}}}function z(t,e){oi(xe(t),{recursive:!0});let n=rn(t),i=`${n}.${process.pid}.tmp`;li(i,JSON.stringify(e,null,2)+`
@@ -477,4 +477,4 @@ Document the arguments, commands, or files the skill expects. Example:
477
477
  claude-code ${ft(t)} --arg value
478
478
  \`\`\`
479
479
  `}xt();var _r={maxPixels:12e5,timeoutMs:5e3,intervalMs:100,changeThreshold:.015,stableMs:400,regions:{},buffer:{enabled:!1,seconds:10,fps:2,region:"screen",maxPixels:3e5}};function Cr(t){return{..._r,...t??{},regions:{...t?.regions??{}},buffer:{..._r.buffer,...t?.buffer??{}}}}function hu(t){try{return Cr(kt(t).screen)}catch{return Cr(void 0)}}var ea=/^[a-z][\w-]*$/,Dr=["window","screen","menubar","notifications"];function J(t,e,n,i){let r=Number(t);if(t===""||t===null||!Number.isFinite(r)||!n(r))throw new Error(`${e} must be ${i}`);return r}var ge=(t,e)=>J(t,e,n=>Number.isInteger(n)&&n>0,"a whole number above 0");function Er(t){let e=typeof t=="string"?t.split(",").map(Number):[t?.x,t?.y,t?.width,t?.height].map(Number);if(e.length!==4||!e.every(Number.isFinite)||e[2]<=0||e[3]<=0)throw new Error("a region is x,y,width,height in screen points, with width and height above 0");return{x:e[0],y:e[1],width:e[2],height:e[3]}}function yu(t,e){let n={...t??{}};if("maxPixels"in e&&(n.maxPixels=ge(e.maxPixels,"maxPixels")),"timeoutMs"in e&&(n.timeoutMs=ge(e.timeoutMs,"timeoutMs")),"intervalMs"in e&&(n.intervalMs=ge(e.intervalMs,"intervalMs")),"stableMs"in e&&(n.stableMs=J(e.stableMs,"stableMs",r=>Number.isInteger(r)&&r>=0,"a whole number, 0 or more")),"changeThreshold"in e&&(n.changeThreshold=J(e.changeThreshold,"changeThreshold",r=>r>=0&&r<=1,"between 0 and 1")),e.regions&&typeof e.regions=="object"){let r={...n.regions??{}};for(let[s,o]of Object.entries(e.regions)){if(!ea.test(s))throw new Error(`region name "${s}" must be lowercase letters, digits, - or _`);o===null?delete r[s]:r[s]=Er(o)}n.regions=r}if(e.buffer&&typeof e.buffer=="object"){let r=e.buffer,s={...n.buffer??{}};"enabled"in r&&(s.enabled=!!r.enabled),"seconds"in r&&(s.seconds=J(r.seconds,"buffer.seconds",o=>o>0&&o<=120,"above 0 and at most 120")),"fps"in r&&(s.fps=J(r.fps,"buffer.fps",o=>o>0&&o<=10,"above 0 and at most 10")),"maxPixels"in r&&(s.maxPixels=ge(r.maxPixels,"buffer.maxPixels")),"region"in r&&(s.region=String(r.region).trim()),n.buffer=s}let i=n.buffer?.region;if(i!==void 0&&!Dr.includes(i)&&!n.regions?.[i])try{Er(i)}catch{throw new Error(`buffer.region "${i}" is not a region \u2014 use ${[...Dr,...Object.keys(n.regions??{})].join(", ")}, or x,y,w,h`)}return n}export{Bt as a,ra as b,Je as c,Cs as d,Ds as e,Nc as f,jc as g,Vc as h,Gn as i,Fc as j,Uc as k,T as l,Xn as m,k as n,aa as o,ua as p,ii as q,ha as r,nn as s,R as t,xa as u,Sa as v,cn as w,_a as x,pn as y,Ba as z,gn as A,cr as B,ml as C,hl as D,Sl as E,yo as F,vl as G,za as H,Ha as I,qa as J,Ka as K,Ga as L,Xa as M,Ya as N,Za as O,ac as P,Te as Q,cc as R,lc as S,H as T,q as U,vo as V,Tl as W,Pl as X,Ll as Y,Ml as Z,tt as _,Ol as $,Me as aa,Oe as ba,le as ca,Xi as da,Yi as ea,gc as fa,je as ga,Ve as ha,Zi as ia,Qi as ja,Ln as ka,jn as la,mc as ma,ns as na,hc as oa,us as pa,fs as qa,We as ra,ms as sa,Vn as ta,P as ua,yr as va,br as wa,wr as xa,Bl as ya,To as za,xr as Aa,Sr as Ba,Ql as Ca,eu as Da,Go as Ea,tu as Fa,$r as Ga,ue as Ha,_c as Ia,Hn as Ja,Fe as Ka,Ge as La,Mc as Ma,su as Na,ou as Oa,au as Pa,cu as Qa,lu as Ra,uu as Sa,du as Ta,pu as Ua,fu as Va,_r as Wa,Cr as Xa,hu as Ya,Dr as Za,yu as _a};
480
- //# sourceMappingURL=chunk-H4EGM4L7.js.map
480
+ //# sourceMappingURL=chunk-DTXI7LEI.js.map