agentix-cli 0.142.0 → 0.143.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{App-VHAMAS4I.js → App-UTDCBFZI.js} +2 -2
- package/dist/{ChatApp-Y7HOL45K.js → ChatApp-7P22XAL2.js} +2 -2
- package/dist/{absorb-eval-VHACXZ3H.js → absorb-eval-EGO6JJOV.js} +2 -2
- package/dist/{agent-M7ID5U3U.js → agent-AI6LNZV2.js} +2 -2
- package/dist/{board-dashboard-VHUZMYOV.js → board-dashboard-ZKN5Y3GJ.js} +320 -268
- package/dist/board-dashboard-ZKN5Y3GJ.js.map +1 -0
- package/dist/{chunk-5SEUBOUH.js → chunk-3WBOWXAN.js} +2 -2
- package/dist/{chunk-JH6C2Y5D.js → chunk-5BXAKMYK.js} +2 -2
- package/dist/{chunk-GPCBOXZM.js → chunk-6CTQPGBR.js} +2 -2
- package/dist/{chunk-EMA67BJ5.js → chunk-7H6HDN3K.js} +2 -2
- package/dist/{chunk-3E4AEZ2J.js → chunk-AJUWIBLV.js} +2 -2
- package/dist/{chunk-WEHEI3JO.js → chunk-DKLVB5L6.js} +5 -5
- package/dist/{chunk-WEHEI3JO.js.map → chunk-DKLVB5L6.js.map} +1 -1
- package/dist/{chunk-7H7LUBPC.js → chunk-ERG5OUKH.js} +2 -2
- package/dist/{chunk-UF4OTZ7D.js → chunk-GB4YT5IG.js} +270 -269
- package/dist/chunk-GB4YT5IG.js.map +1 -0
- package/dist/{chunk-KEBTFUOZ.js → chunk-HPQ3AAG3.js} +2 -2
- package/dist/{chunk-NFI4BCCO.js → chunk-IABJLTZN.js} +2 -2
- package/dist/chunk-K22XMF6M.js +62 -0
- package/dist/chunk-K22XMF6M.js.map +1 -0
- package/dist/{chunk-ZWL44UJS.js → chunk-L4RCA3OC.js} +2 -2
- package/dist/{chunk-QTS7MHIA.js → chunk-MFUN3ZS3.js} +2 -2
- package/dist/{chunk-SLJFY2AQ.js → chunk-N2HLL25P.js} +2 -2
- package/dist/{chunk-TFNBUHRW.js → chunk-NYWIN4BW.js} +2 -2
- package/dist/{chunk-25XO6P7W.js → chunk-O2CYERSX.js} +2 -2
- package/dist/{chunk-2TLOZN7P.js → chunk-OMO7UTWW.js} +2 -2
- package/dist/{chunk-S6QUFAHD.js → chunk-PYI7ZAU3.js} +2 -2
- package/dist/{chunk-S6QUFAHD.js.map → chunk-PYI7ZAU3.js.map} +1 -1
- package/dist/{chunk-7Y3FEIX7.js → chunk-QVPBSV5Z.js} +2 -2
- package/dist/{chunk-B5744ATM.js → chunk-RB5W3FVO.js} +2 -2
- package/dist/{chunk-S3LWGPNZ.js → chunk-SDSSRNSU.js} +3 -3
- package/dist/{chunk-3NKCOZQO.js → chunk-THWDSPX4.js} +2 -2
- package/dist/{chunk-6YPJVGYF.js → chunk-WY5ZOEOE.js} +2 -2
- package/dist/{chunk-MLLMBE2W.js → chunk-XWHD2Z3Z.js} +2 -2
- package/dist/{chunk-6PJKKLKV.js → chunk-YVNGPYXN.js} +52 -52
- package/dist/chunk-YVNGPYXN.js.map +1 -0
- package/dist/{chunk-IFUN332M.js → chunk-YYPTXXCJ.js} +2 -2
- package/dist/cli.js +1 -1
- package/dist/{client-ISQF24N5.js → client-E66ELJK7.js} +2 -2
- package/dist/{config-Z64VWERV.js → config-3C3Z7VKG.js} +2 -2
- package/dist/{config-mutate-YZ3IH6CJ.js → config-mutate-QBDKJNHA.js} +2 -2
- package/dist/config-mutator-ZI3SQIUN.js +2 -0
- package/dist/{contributions-FQGIRD44.js → contributions-L5XZJ3DP.js} +2 -2
- package/dist/{doctor-FMW2SSCN.js → doctor-3ZUFSE6R.js} +2 -2
- package/dist/{follow-up-tool-I7PPM2R5.js → follow-up-tool-6OCQUSC3.js} +2 -2
- package/dist/{hub-Z3X4LWMI.js → hub-MOQRSVCQ.js} +2 -2
- package/dist/index.d.ts +169 -55
- package/dist/index.js +1 -1
- package/dist/{program-I7WCAMBP.js → program-AR6F763U.js} +218 -216
- package/dist/program-AR6F763U.js.map +1 -0
- package/dist/{promote-7YUBVKRC.js → promote-ZGJEPCBE.js} +2 -2
- package/dist/{query-TMALX5BE.js → query-JLTHESIZ.js} +2 -2
- package/dist/{query-settings-3PEV5GIH.js → query-settings-GMEL3EKR.js} +2 -2
- package/dist/{registry-6ZIBMOZQ.js → registry-MFD3XJBR.js} +2 -2
- package/dist/{request-planner-GLNHHQXA.js → request-planner-4ORFYSAT.js} +2 -2
- package/dist/{review-candidates-DJXNTOG6.js → review-candidates-77NDFTGM.js} +2 -2
- package/dist/{routing-YWP2AF56.js → routing-3FL3KYPJ.js} +2 -2
- package/dist/schedule-tool-5KJMXBRZ.js +2 -0
- package/dist/{scheduler-HK362U53.js → scheduler-QLL7ZHYW.js} +2 -2
- package/dist/{seat-4PPUZXFN.js → seat-RBKONP63.js} +2 -2
- package/dist/{select-ULCUVM7N.js → select-MOUDR6PQ.js} +2 -2
- package/dist/{set-enabled-G4PLW5WK.js → set-enabled-JKYF3QIA.js} +2 -2
- package/dist/tool-C4JNMTEF.js +6 -0
- package/dist/tool-C4JNMTEF.js.map +1 -0
- package/dist/{tool-KGOC2NUZ.js → tool-Y3ZTSZGE.js} +2 -2
- package/dist/{wiki-32G6TGCI.js → wiki-3FSSLQAE.js} +2 -2
- package/dist/wiki-enrich-HQWXZRID.js +2 -0
- package/package.json +1 -1
- package/dist/board-dashboard-VHUZMYOV.js.map +0 -1
- package/dist/chunk-6PJKKLKV.js.map +0 -1
- package/dist/chunk-JYPXNH4C.js +0 -54
- package/dist/chunk-JYPXNH4C.js.map +0 -1
- package/dist/chunk-UF4OTZ7D.js.map +0 -1
- package/dist/config-mutator-3HTNXOPU.js +0 -2
- package/dist/program-I7WCAMBP.js.map +0 -1
- package/dist/schedule-tool-4O4XWGVA.js +0 -2
- package/dist/tool-CBDT7TAG.js +0 -6
- package/dist/tool-CBDT7TAG.js.map +0 -1
- package/dist/wiki-enrich-XBRY4ZRD.js +0 -2
- /package/dist/{App-VHAMAS4I.js.map → App-UTDCBFZI.js.map} +0 -0
- /package/dist/{ChatApp-Y7HOL45K.js.map → ChatApp-7P22XAL2.js.map} +0 -0
- /package/dist/{absorb-eval-VHACXZ3H.js.map → absorb-eval-EGO6JJOV.js.map} +0 -0
- /package/dist/{agent-M7ID5U3U.js.map → agent-AI6LNZV2.js.map} +0 -0
- /package/dist/{chunk-5SEUBOUH.js.map → chunk-3WBOWXAN.js.map} +0 -0
- /package/dist/{chunk-JH6C2Y5D.js.map → chunk-5BXAKMYK.js.map} +0 -0
- /package/dist/{chunk-GPCBOXZM.js.map → chunk-6CTQPGBR.js.map} +0 -0
- /package/dist/{chunk-EMA67BJ5.js.map → chunk-7H6HDN3K.js.map} +0 -0
- /package/dist/{chunk-3E4AEZ2J.js.map → chunk-AJUWIBLV.js.map} +0 -0
- /package/dist/{chunk-7H7LUBPC.js.map → chunk-ERG5OUKH.js.map} +0 -0
- /package/dist/{chunk-KEBTFUOZ.js.map → chunk-HPQ3AAG3.js.map} +0 -0
- /package/dist/{chunk-NFI4BCCO.js.map → chunk-IABJLTZN.js.map} +0 -0
- /package/dist/{chunk-ZWL44UJS.js.map → chunk-L4RCA3OC.js.map} +0 -0
- /package/dist/{chunk-QTS7MHIA.js.map → chunk-MFUN3ZS3.js.map} +0 -0
- /package/dist/{chunk-SLJFY2AQ.js.map → chunk-N2HLL25P.js.map} +0 -0
- /package/dist/{chunk-TFNBUHRW.js.map → chunk-NYWIN4BW.js.map} +0 -0
- /package/dist/{chunk-25XO6P7W.js.map → chunk-O2CYERSX.js.map} +0 -0
- /package/dist/{chunk-2TLOZN7P.js.map → chunk-OMO7UTWW.js.map} +0 -0
- /package/dist/{chunk-7Y3FEIX7.js.map → chunk-QVPBSV5Z.js.map} +0 -0
- /package/dist/{chunk-B5744ATM.js.map → chunk-RB5W3FVO.js.map} +0 -0
- /package/dist/{chunk-S3LWGPNZ.js.map → chunk-SDSSRNSU.js.map} +0 -0
- /package/dist/{chunk-3NKCOZQO.js.map → chunk-THWDSPX4.js.map} +0 -0
- /package/dist/{chunk-6YPJVGYF.js.map → chunk-WY5ZOEOE.js.map} +0 -0
- /package/dist/{chunk-MLLMBE2W.js.map → chunk-XWHD2Z3Z.js.map} +0 -0
- /package/dist/{chunk-IFUN332M.js.map → chunk-YYPTXXCJ.js.map} +0 -0
- /package/dist/{client-ISQF24N5.js.map → client-E66ELJK7.js.map} +0 -0
- /package/dist/{config-Z64VWERV.js.map → config-3C3Z7VKG.js.map} +0 -0
- /package/dist/{config-mutate-YZ3IH6CJ.js.map → config-mutate-QBDKJNHA.js.map} +0 -0
- /package/dist/{config-mutator-3HTNXOPU.js.map → config-mutator-ZI3SQIUN.js.map} +0 -0
- /package/dist/{contributions-FQGIRD44.js.map → contributions-L5XZJ3DP.js.map} +0 -0
- /package/dist/{doctor-FMW2SSCN.js.map → doctor-3ZUFSE6R.js.map} +0 -0
- /package/dist/{follow-up-tool-I7PPM2R5.js.map → follow-up-tool-6OCQUSC3.js.map} +0 -0
- /package/dist/{hub-Z3X4LWMI.js.map → hub-MOQRSVCQ.js.map} +0 -0
- /package/dist/{promote-7YUBVKRC.js.map → promote-ZGJEPCBE.js.map} +0 -0
- /package/dist/{query-TMALX5BE.js.map → query-JLTHESIZ.js.map} +0 -0
- /package/dist/{query-settings-3PEV5GIH.js.map → query-settings-GMEL3EKR.js.map} +0 -0
- /package/dist/{registry-6ZIBMOZQ.js.map → registry-MFD3XJBR.js.map} +0 -0
- /package/dist/{request-planner-GLNHHQXA.js.map → request-planner-4ORFYSAT.js.map} +0 -0
- /package/dist/{review-candidates-DJXNTOG6.js.map → review-candidates-77NDFTGM.js.map} +0 -0
- /package/dist/{routing-YWP2AF56.js.map → routing-3FL3KYPJ.js.map} +0 -0
- /package/dist/{schedule-tool-4O4XWGVA.js.map → schedule-tool-5KJMXBRZ.js.map} +0 -0
- /package/dist/{scheduler-HK362U53.js.map → scheduler-QLL7ZHYW.js.map} +0 -0
- /package/dist/{seat-4PPUZXFN.js.map → seat-RBKONP63.js.map} +0 -0
- /package/dist/{select-ULCUVM7N.js.map → select-MOUDR6PQ.js.map} +0 -0
- /package/dist/{set-enabled-G4PLW5WK.js.map → set-enabled-JKYF3QIA.js.map} +0 -0
- /package/dist/{tool-KGOC2NUZ.js.map → tool-Y3ZTSZGE.js.map} +0 -0
- /package/dist/{wiki-32G6TGCI.js.map → wiki-3FSSLQAE.js.map} +0 -0
- /package/dist/{wiki-enrich-XBRY4ZRD.js.map → wiki-enrich-HQWXZRID.js.map} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import{a as
|
|
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]),l=a.status??a.run?.status;if(l){s=l;break}}return{workflowId:r,status:s,at:e}}catch{return null}}var
|
|
3
|
-
`),
|
|
4
|
-
`).pop()?.slice(0,300)||"no output";async function
|
|
5
|
-
`,{mode:384}),
|
|
1
|
+
import{a as Ie}from"./chunk-GTJIKXDB.js";import{q as nn}from"./chunk-S2GAEH2F.js";import{a as w}from"./chunk-7LN4VKDU.js";import{a as re}from"./chunk-IMLAPB7G.js";import{f as sn,g as _e,i as V,j as q,l as on}from"./chunk-AKWBDCMU.js";import{t as en,u as tn}from"./chunk-N2HLL25P.js";import{b as rn}from"./chunk-YMX3QCV7.js";import{a as Kt,b as Jt,d as Yt}from"./chunk-Y4CYQV7G.js";import{a as Vt,b as qt}from"./chunk-SHEUCITK.js";import{d as Zt,e as Qt}from"./chunk-AQASR6KR.js";import{X as Ft,Z as ne,_ as Ae,aa as Re,b as $e}from"./chunk-THWDSPX4.js";import{g as Bt,h as Ht,i as zt,k as Xt,l as Gt}from"./chunk-WY5ZOEOE.js";import{q as Ut}from"./chunk-NYWIN4BW.js";import{a as Wt,b as jt}from"./chunk-QVPBSV5Z.js";import{Ba as ve,I as It,Ia as Nt,J as Et,Ja as Ot,K as Tt,L as Ct,P as te,Q as Dt,R as Pt,Ra as Mt,S as Lt,T as xe,n as ee,o as Rt,p as _t,q as ii}from"./chunk-K22XMF6M.js";import{a as ke,h as si}from"./chunk-BRK6M6LA.js";import{f as Se,n as oi}from"./chunk-UIBUZ2N3.js";import{existsSync as ai,readdirSync as li,readFileSync as ci,statSync as ui}from"fs";import{resolve as di}from"path";function an(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)??[],l=a.filter(f=>n-f.at<=r),c=a.filter(f=>n-f.at>r&&n-f.at<=r*2),u=l.filter(f=>f.status==="failed").length,d=a.filter(f=>f.status==="paused").length,p=a.length?Math.max(...a.map(f=>f.at)):null,g=a.length?c.length>0&&l.length===0?"dormant":l.length>0&&u*2>=l.length?"failing":l.length>0?"active":"quiet":"never";return{id:o.id,name:o.name||o.id,state:g,lastRunAt:p,recent:l.length,prior:c.length,failed:u,paused:d}}).sort((o,a)=>{let l={dormant:0,failing:1,active:2,quiet:3,never:4};return l[o.state]-l[a.state]||(a.lastRunAt??0)-(o.lastRunAt??0)})}var ie=new Map;function Fa(t,e=1e3){if(!ai(t))return[];let n=li(t).filter(s=>s.endsWith(".jsonl")).map(s=>{let o=di(t,s);return{path:o,mtime:ui(o).mtimeMs}}).sort((s,o)=>o.mtime-s.mtime).slice(0,e),i=new Set(n.map(s=>s.path));for(let s of ie.keys())i.has(s)||ie.delete(s);let r=[];for(let{path:s,mtime:o}of n){let a=ie.get(s);if(a&&a.mtime===o){a.summary&&r.push(a.summary);continue}let l=pi(s,o);ie.set(s,{mtime:o,summary:l}),l&&r.push(l)}return r}function pi(t,e){try{let n=ci(t,"utf-8").split(`
|
|
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]),l=a.status??a.run?.status;if(l){s=l;break}}return{workflowId:r,status:s,at:e}}catch{return null}}var gi={failStreak:3,disabledDays:30,missedFires:2,graceMs:15*6e4},k={routines:200,summary:160,filters:6,filterValue:60,text:120},fi=(t,e,n)=>{try{return Ut(t,e,n)}catch{return null}},ln=864e5;function Ha(t){let e=t.now??Date.now(),n={...gi,...t.thresholds},i=t.nextFire??fi,r=[];for(let a of t.crons){let l=t.cronRuns.get(a.id)??[],c=a.timezone||"UTC",u=l.map(g=>({at:Date.parse(g.startedAt),status:g.status})),d=l[0],p={id:`cron:${a.id}`,source:"cron",kind:"schedule",name:$(a.id,k.text),trigger:{schedule:$(a.schedule,k.text),timezone:c},agent:a.agent||null,enabled:a.enabled,state:a.enabled?"enabled":"disabled",nextRunAt:a.enabled?Ee(a.nextRun)??Ee(i(a.schedule,new Date(e),c)):null,lastRun:d?{at:d.startedAt,status:d.status,summary:ki(d.status==="success"?void 0:d.errorSummary,k.summary)}:null,lastSuccessAt:l.find(g=>g.status==="success")?.startedAt??null,consecutiveFailures:cn(u),sampledRuns:l.length,flags:[],attention:null};p.flags=un(p,u,a.schedule,c,null,e,n,i),r.push(dn(p))}let s=new Map(an(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 l=o.get(a.workflowId);l?l.push(a):o.set(a.workflowId,[a])}for(let a of t.workflows){let l=a.nodes.find(I=>I.type.startsWith("trigger."));if(!l||l.type!=="trigger.cron"&&l.type!=="trigger.hook")continue;let c=l.config??{},u=a.state||"active",d=u==="active",p=(o.get(a.id)??[]).slice().sort((I,we)=>we.at-I.at),g=p.map(I=>({at:I.at,status:yi(I.status)})),f=g[0],h=l.type==="trigger.cron",y=typeof c.spec=="string"?c.spec:"",C=typeof c.timezone=="string"?c.timezone:"UTC",M={id:`workflow:${a.id}`,source:"workflow",kind:h?"schedule":"event",name:$(a.title||a.id,k.text),trigger:h?{schedule:$(y,k.text),timezone:C}:{event:$(typeof c.event=="string"?c.event:"",k.text),filters:wi(c.filter,a)},agent:bi(a),enabled:d,state:u,nextRunAt:h&&d&&y?Ee(i(y,new Date(e),C)):null,lastRun:f?{at:new Date(f.at).toISOString(),status:f.status}:null,lastSuccessAt:(()=>{let I=g.find(we=>we.status==="success");return I?new Date(I.at).toISOString():null})(),consecutiveFailures:cn(g),sampledRuns:p.length,flags:[],attention:null},Q=Date.parse(a.updated||a.created||"");M.flags=h?un(M,g,y,C,Number.isFinite(Q)?Q:null,e,n,i):mi(M,s.get(a.id)?.state==="dormant",Number.isFinite(Q)?Q:null,e,n),r.push(dn(M))}return r.sort(hi).slice(0,k.routines)}function cn(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 un(t,e,n,i,r,s,o,a){let l=[],c=e.length?e[0].at:null;if(!t.enabled){let p=gn(c,r,s,o);return p&&l.push(p),l}if(t.consecutiveFailures>=o.failStreak&&l.push({reason:"failing",detail:`${t.consecutiveFailures} failed attempts in a row`}),c===null)return l.push({reason:"never-ran",detail:"No persisted attempt"}),l;let u=new Date(c),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&&l.push({reason:"overdue",detail:`No attempt since ${new Date(c).toISOString()}; ${o.missedFires} scheduled fires missed`}),l}function mi(t,e,n,i,r){let s=[],o=t.lastRun?Date.parse(t.lastRun.at):null;if(!t.enabled){let a=gn(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 gn(t,e,n,i){let r=Math.max(t??0,e??0);return r&&n-r<i.disabledDays*ln?null:{reason:"disabled-long",detail:r?`Disabled; no activity for ${Math.floor((n-r)/ln)} days`:"Disabled and never ran"}}function dn(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 pn={critical:0,warning:1,info:2};function hi(t,e){let n=t.attention?pn[t.attention]:3,i=e.attention?pn[e.attention]:3;return n-i||Number(e.enabled)-Number(t.enabled)||t.name.localeCompare(e.name)}function yi(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 bi(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 wi(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 Ee(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 ki(t,e){return t===void 0?void 0:$(t,e)}import{mkdirSync as Si,readFileSync as xi,renameSync as vi,writeFileSync as $i}from"fs";import{resolve as Ai}from"path";function fn(t){return Ai(_e(t),"_state.json")}function A(t){try{let e=JSON.parse(xi(fn(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 B(t,e){Si(_e(t),{recursive:!0});let n=fn(t),i=`${n}.${process.pid}.tmp`;$i(i,JSON.stringify(e,null,2)+`
|
|
3
|
+
`),vi(i,n)}function mn(t,e,n,i=Date.now()){let r=A(t),s={};for(let[o,a]of Object.entries(r.snoozed))Date.parse(a)>i&&(s[o]=a);s[e]=n.toISOString(),B(t,{...r,snoozed:s})}function Ja(t,e){B(t,{...A(t),lastDigest:e})}function hn(t,e,n,i=Date.now()){let r=A(t),s=new Set(n),o={};for(let[l,c]of Object.entries(r.popped??{}))s.has(l)&&(o[l]=c);o[e]=new Date(i).toISOString();let a=(r.wanted??[]).filter(l=>l!==e&&s.has(l));B(t,{...r,popped:o,wanted:a})}function yn(t,e){let n=A(t);B(t,{...n,wanted:[...(n.wanted??[]).filter(i=>i!==e),e]})}function Ya(t,e=Date.now()){B(t,{...A(t),popped:{},passAt:new Date(e).toISOString()})}import{existsSync as H,readdirSync as Fi,readFileSync as Vi}from"fs";import{resolve as R}from"path";import{randomBytes as kn}from"crypto";import{existsSync as _i,mkdirSync as Ii,readdirSync as Ei,readFileSync as Ti,renameSync as Sn,unlinkSync as Ci,writeFileSync as Di}from"fs";import{resolve as xn}from"path";function bn(t){return[...t.account?["--account",t.account]:[],...t.store?["--store",t.store]:[]]}var Ri=t=>t.trim().split(`
|
|
4
|
+
`).pop()?.slice(0,300)||"no output";async function wn(t,e,n,i=Ie){let r=await i(t.bin,[...bn(t),"send","text","--to",e,"--message",n,"--no-preview"],{timeoutMs:6e4});return r.code===0?{ok:!0}:{ok:!1,error:`wacli send failed: ${Ri(r.stderr||r.stdout)}`}}async function el(t,e,n,i,r=Ie){return(await r(t.bin,[...bn(t),"--read-only","media","download","--chat",e,"--id",n,"--output",i],{timeoutMs:12e4})).code===0}var Pi=2e3,Li=t=>wn(t.wacli,t.to,t.text);function Te(t){return xn(t,".agentx","whatsapp-triage","drafts")}var Ni=t=>/^[a-z0-9-]{8,64}$/.test(t),se=(t,e)=>xn(Te(t),`${e}.json`);function vn(t,e){Ii(Te(t),{recursive:!0});let n=se(t,e.id),i=`${n}.${process.pid}.tmp`;Di(i,JSON.stringify(e,null,2)+`
|
|
5
|
+
`,{mode:384}),Sn(i,n)}function ol(t,e,n=Date.now()){let i=e.text.trim().slice(0,Pi);if(!i)throw new Error("empty draft");let r={...e,text:i,id:`${n.toString(36)}-${kn(4).toString("hex")}`,status:"pending",created_at:new Date(n).toISOString()};return vn(t,r),r}function oe(t,e){if(!Ni(e))return null;try{return JSON.parse(Ti(se(t,e),"utf-8"))}catch{return null}}function $n(t,e){let n=Te(t);return _i(n)?Ei(n).filter(i=>i.endsWith(".json")).map(i=>oe(t,i.slice(0,-5))).filter(i=>!!i&&(!e||i.status===e)).sort((i,r)=>i.created_at.localeCompare(r.created_at)):[]}async function An(t,e,n,i={}){let r=oe(t,e);if(!r||r.status!=="pending")return{ok:!1,error:`no reply draft "${e}" is waiting`};let s=`${se(t,e)}.${process.pid}.${kn(3).toString("hex")}.claim`;try{Sn(se(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??Li)(r).catch(l=>({ok:!1,error:String(l?.message??l)}));a.ok?o.status="sent":(o.status="failed",o.error=a.error)}vn(t,o);try{Ci(s)}catch{}return o.status==="failed"?{ok:!1,error:o.error??"send failed"}:{ok:!0,draft:o}}oi();xe();xe();var cl=["done","skipped"],Oi=1e3;function Mi(t){t.exec(`
|
|
6
6
|
CREATE TABLE IF NOT EXISTS request_plans (
|
|
7
7
|
request_id TEXT PRIMARY KEY,
|
|
8
8
|
created_by TEXT NOT NULL,
|
|
@@ -50,9 +50,9 @@ import{a as Re}from"./chunk-GTJIKXDB.js";import{q as Kt}from"./chunk-S2GAEH2F.js
|
|
|
50
50
|
FOREIGN KEY (request_id) REFERENCES request_plans(request_id) ON DELETE CASCADE
|
|
51
51
|
);
|
|
52
52
|
CREATE INDEX IF NOT EXISTS idx_request_plan_events ON request_plan_events(request_id, at);
|
|
53
|
-
`)}function
|
|
53
|
+
`)}function _n(t){return!!t.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'request_plans'").get()}function Ce(t){return{requestId:t.request_id,createdBy:t.created_by,createdAt:t.created_at,state:t.state,finishedAt:t.finished_at??null,notifiedAt:t.notified_at??null}}function Rn(t){return{requestId:t.request_id,idx:t.idx,name:t.name,kind:t.kind,agentId:t.agent_id,doneWhen:t.done_when,state:t.state,needsApproval:!!t.needs_approval,approval:t.approval,cardId:t.card_id??null,message:t.message??null,toChannel:t.to_channel??null,toChat:t.to_chat??null,toAccount:t.to_account??null,checkUrl:t.check_url??null,checkContains:t.check_contains??null,stallMinutes:t.stall_minutes??null,evidence:t.evidence??null,note:t.note??null,dispatchedAt:t.dispatched_at??null,updatedAt:t.updated_at,nudges:t.nudges,lastNudgeAt:t.last_nudge_at??null,notifiedAt:t.notified_at??null}}var Wi={state:"state",approval:"approval",cardId:"card_id",message:"message",evidence:"evidence",note:"note",dispatchedAt:"dispatched_at",updatedAt:"updated_at",nudges:"nudges",lastNudgeAt:"last_nudge_at",notifiedAt:"notified_at"},ae=class{constructor(e){this.db=e;Mi(e)}create(e,n,i,r){let s=this.db.prepare("INSERT INTO request_plans (request_id, created_by, created_at, state) VALUES (?, ?, ?, 'active')"),o=this.db.prepare(`INSERT INTO request_plan_steps (request_id, idx, name, kind, agent_id, done_when, state, needs_approval, message,
|
|
54
54
|
to_channel, to_chat, to_account, check_url, check_contains, stall_minutes, dispatched_at, updated_at)
|
|
55
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`);this.db.transaction(()=>{s.run(e,n,r),i.forEach((a,l)=>{let c=l===0,u=c&&a.agentId===n&&a.kind!=="message";o.run(e,l+1,a.name,a.kind,a.agentId,a.doneWhen,c?"active":"pending",a.needsApproval?1:0,a.message??null,a.toChannel??null,a.toChat??null,a.toAccount??null,a.checkUrl??null,a.checkContains??null,a.stallMinutes??null,u?r:null,r)}),this.event(e,null,"created",`${i.length} steps, written by ${n}`,r)})()}get(e){let n=this.db.prepare("SELECT * FROM request_plans WHERE request_id = ?").get(e);return n?Ee(n):null}steps(e){return this.db.prepare("SELECT * FROM request_plan_steps WHERE request_id = ? ORDER BY idx").all(e).map(wn)}step(e,n){let i=this.db.prepare("SELECT * FROM request_plan_steps WHERE request_id = ? AND idx = ?").get(e,n);return i?wn(i):null}listActive(){return this.db.prepare("SELECT * FROM request_plans WHERE state = 'active' ORDER BY created_at, rowid").all().map(Ee)}updateStep(e,n,i){let r=[],s=[];for(let[o,a]of Object.entries(i)){let l=Ti[o];!l||a===void 0||(r.push(`${l} = ?`),s.push(typeof a=="boolean"?a?1:0:a))}r.length&&this.db.prepare(`UPDATE request_plan_steps SET ${r.join(", ")} WHERE request_id = ? AND idx = ?`).run(...s,e,n)}finish(e,n,i){return this.db.prepare("UPDATE request_plans SET state = ?, finished_at = ? WHERE request_id = ? AND state = 'active'").run(n,i,e).changes>0}markNotified(e,n){this.db.prepare("UPDATE request_plans SET notified_at = ? WHERE request_id = ?").run(n,e)}awaitingSummary(){return this.db.prepare("SELECT * FROM request_plans WHERE state = 'done' AND notified_at IS NULL ORDER BY finished_at").all().map(Ee)}event(e,n,i,r,s){this.db.prepare("INSERT INTO request_plan_events (request_id, step, at, kind, detail) VALUES (?, ?, ?, ?, ?)").run(e,n,s,i,r.replace(/\s+/g," ").trim().slice(0,Ii))}events(e,n=200){return this.db.prepare("SELECT request_id, step, at, kind, detail FROM request_plan_events WHERE request_id = ? ORDER BY at, rowid LIMIT ?").all(e,n).map(i=>({requestId:i.request_id,step:i.step??null,at:i.at,kind:i.kind,detail:i.detail}))}},Za=$t;import{existsSync as Ci,readFileSync as Di}from"fs";Tt();Yr();function xn(t){let e=Ct(t),n={};if(Ci(e))try{n=It(JSON.parse(Di(e,"utf-8")))}catch{n={}}let i=xe.safeParse(n?.requests);return i.success?i.data:xe.parse(void 0)}async function il(t,e={}){let n=(t.channels??[]).filter(i=>!we.has(i.toLowerCase().split("@")[0]));return n.length?{success:!1,error:`unknown channel ${n.map(i=>`"${i}"`).join(", ")}: use ${[...we].join(", ")}`}:Dt(i=>{let r=i.requests??={};for(let s of["enabled","channels","from","staleAfterHours","retentionDays"])t[s]!==void 0&&(r[s]=t[s]);if(t.plans){let s=r.plans??={};for(let o of["enabled","stallMinutes","maxNudges","approveKinds","disabledAgents"])t.plans[o]!==void 0&&(s[o]=t.plans[o])}},{configPath:e.configPath,reload:e.reload})}var $n=["card","schedule","memory","wiki","whatsapp","request"],Li=280;function N(t,e=Li){let n=t.replace(/\s+/g," ").trim();return n.length>e?`${n.slice(0,e-1)}\u2026`:n}function Te(t){if(t.configPath)return R(t.configPath);let e=[R(t.root,"agentx.json"),R(t.root,".agentx","config.json")];return e.find(n=>H(n))??e[0]}function Ce(t){return t.wikiDir?R(t.wikiDir):R(t.root,".agentx","wiki")}function Oi(t){return q(t.root,"pending").map(Mi)}function Mi(t){return{key:`card:${t.id}`,kind:"card",title:t.title,ask:t.ask,yes:`tell ${t.raised_by} yes`,no:`tell ${t.raised_by} no`,recommend:t.recommend,if_silent:t.if_silent,expires:t.expires,...t.source?{source:t.source}:{},raised_by:t.raised_by,...t.node?{node:t.node}:{},created_at:t.created_at,...t.choices?{choices:t.choices,more:`agentx approvals popup card:${t.id}`}:{},...t.draft?{draft:t.draft}:{},...t.context||t.draft?{detail:N([t.context,t.draft?`Suggested message: ${t.draft}`:""].filter(Boolean).join(" \xB7 "))}:{}}}function ji(t){let e=Te(t);if(!H(e))return[];let n;try{n=JSON.parse(Ni(e,"utf-8"))}catch{return[]}let i=new Date(t.now??Date.now()),r=[];for(let[s,o]of Object.entries(n?.crons??{})){let a=o?.approval;if(!a||a.action!=="create"&&a.action!=="delete")continue;let l=o.timezone||"UTC",c=o.schedule?Mt(o.schedule):"",u=o.schedule?`${c.charAt(0).toLowerCase()}${c.slice(1)} (${o.schedule})`:"no schedule",d=String(o.prompt??o.command??""),p=a.action==="create";r.push({key:`schedule:${s}`,kind:"schedule",title:p?`New schedule "${s}" for ${o.agent??"an agent"}`:`Delete schedule "${s}"`,ask:p?`Let ${o.agent??"the agent"} run this ${u}?`:`Remove the schedule "${s}" (${u})?`,yes:p?"enable it":"remove it",no:p?"drop the request":"keep the schedule",raised_by:String(a.requestedBy??"unknown"),created_at:String(a.requestedAt??""),detail:N(`${d}${p&&o.schedule?` \xB7 first run ${Wt(jt(o.schedule,l,i),l)}`:""}`),more:"agentx schedule list"})}return r}function An(t){let e=R(t,".agentx","memory");return H(e)?Pi(e).filter(n=>n.endsWith(".jsonl")).map(n=>n.slice(0,-6)).sort():[]}function Wi(t){let e=An(t.root);if(e.length===0)return[];let n=new Se(t.root),i=[];for(let r of e)for(let s of n.held(r))i.push({key:`memory:${r}/${s.id}`,kind:"memory",title:`Fact ${r} learned from ${s.source.channel}`,ask:`Let ${r} use this fact in its prompts?`,yes:"use it",no:"keep it out for good",raised_by:r,created_at:s.createdAt,detail:N(s.content),more:`agentx memory facts held --agent ${r}`});return i}function Fi(t){let e=t.sources.filter(n=>n.failure);return e.length?e.map(n=>`Recurring failure: ${n.agentId}'s ${n.failure.tool} fails with "${n.failure.errorClass}" in ${n.occurrences??1} sessions (${n.failure.runs} runs).`).join(" "):`${t.sources.length} source(s)${t.occurrences>1?`, seen in ${t.occurrences} sessions`:""}.`}function Ui(t){return zt(Ce(t),"pending").map(e=>{let n=e.evidence;return{key:`wiki:${e.id}`,kind:"wiki",title:e.article.title,ask:e.replaces?`Update "${e.article.path}" in the shared wiki?`:`Add "${e.article.path}" to the shared wiki?`,yes:"write the article",no:"decline it",raised_by:n.agents.join(", ")||"wiki promote",created_at:e.createdAt,detail:N(`${Fi(n)} ${e.article.content}`),more:`agentx wiki proposals show ${e.id}`}})}function Vi(t){return bn(t.root,"pending").map(e=>({key:`whatsapp:${e.id}`,kind:"whatsapp",title:`WhatsApp reply to ${e.chat_name||e.to}`,ask:`Send this to ${e.chat_name||e.to}? "${e.text}"`,yes:"send it on WhatsApp",no:"drop the draft",raised_by:e.agent,created_at:e.created_at,detail:N(`${e.triage}: ${e.summary}`),more:"agentx whatsapp triage log"}))}function z(t){if(t.requests)return t.requests;if(R(t.root)!==process.cwd()||!H(R(t.root,".agentx","db.sqlite")))return null;let e=ke({quiet:!0});if(!e)return null;let n=Sn.get(e);return!n&&!At(e)?null:(n||Sn.set(e,n=new Rt(e)),n)}var Sn=new WeakMap;function wl(t){if(t.plans)return t.plans;if(t.requests||R(t.root)!==process.cwd()||!H(R(t.root,".agentx","db.sqlite")))return null;let e=ke({quiet:!0});if(!e||!kn(e))return null;let n=vn.get(e);return n||vn.set(e,n=new oe(e)),n}var vn=new WeakMap;function qi(t){let e=z(t);return e?e.listByState("needs_attention").map(n=>({key:`request:${n.id}`,kind:"request",title:`Request not finished: ${N(n.text,80)}`,ask:`Ask ${n.agentId} to pick it up again?`,yes:`hand it back to ${n.agentId}`,no:"drop the request",raised_by:n.agentId,created_at:new Date(n.createdAt).toISOString(),detail:N(`${n.attentionReason??"It needs attention"}. Asked on ${n.channel}: ${n.text}`),more:`agentx requests show ${n.id}`})):[]}var Rn={card:Oi,schedule:ji,memory:Wi,wiki:Ui,whatsapp:Vi,request:qi};function Bi(t,e){let n=t.expires?Date.parse(t.expires):1/0,i=e.expires?Date.parse(e.expires):1/0;return n!==i?n-i:(Date.parse(t.created_at)||0)-(Date.parse(e.created_at)||0)}function kl(t,e={}){let n=t.now??Date.now(),{snoozed:i}=A(t.root),r=[],s=[],o=0;for(let a of e.kinds??$n){let l;try{l=Rn[a](t)}catch(c){s.push({kind:a,error:String(c?.message??c).slice(0,200)});continue}for(let c of l){let u=i[c.key];if(u&&Date.parse(u)>n){if(!e.includeSnoozed){o++;continue}c.snoozed_until=u}r.push(c)}}return r.sort(Bi),{items:r,snoozed:o,errors:s}}function Hi(t){let e=t.indexOf(":");if(e<=0)return null;let n=t.slice(0,e),i=t.slice(e+1);return!$n.includes(n)||!i?null:{kind:n,ref:i}}function zi(t,e,n){switch(e){case"card":return V(t.root,n)?.status==="pending";case"wiki":return Ht(Ce(t),n)?.status==="pending";case"whatsapp":return se(t.root,n)?.status==="pending";default:return Rn[e](t).some(i=>i.key===`${e}:${n}`)}}async function _n(t,e,n,i={}){let r=Hi(e);if(!r)return{ok:!1,error:`unknown item "${e}": use a key from \`agentx approvals list\``};let{kind:s,ref:o}=r,a=t.now??Date.now(),l=i.by??"operator";if(n==="later"){if(!zi(t,s,o))return{ok:!1,error:`nothing waiting for "${e}"`};let u=i.laterHours&&i.laterHours>0?i.laterHours:24,d=new Date(a+u*36e5);return ln(t.root,e,d,a),{ok:!0,message:`${e} put off until ${d.toISOString()}`}}let c=n==="yes";switch(s){case"card":{let u=Zt(t.root,o,c?"yes":"no",{by:l,note:i.note,now:a,choice:i.choice,text:i.text});return u.ok?{ok:!0,message:`${e}: ${u.card.raised_by} will be told ${c?"yes":"no"}${u.card.choice?` (${u.card.choice})`:""}`}:u}case"schedule":{let u=await(c?Ft:Ut)(o,{configPath:Te(t),reload:t.reload});return u.success?{ok:!0,message:u.message}:{ok:!1,error:u.message}}case"memory":{let u=o.indexOf("/");if(u<=0)return{ok:!1,error:"memory keys look like memory:<agent>/<fact-id>"};let d=o.slice(0,u),p=o.slice(u+1);if(!An(t.root).includes(d))return{ok:!1,error:`no memory for agent "${d}"`};let g=new Se(t.root);return g.held(d).some(f=>f.id===p)?(g.review(d,p,c?"approved":"rejected",l),{ok:!0,message:`${e} ${c?"approved: the agent may use it":"rejected: it stays out of prompts"}`}):{ok:!1,error:`fact "${p}" isn't waiting for review`}}case"wiki":{let u=Ce(t),d=c?Xt(u,o,{by:l,force:i.force,now:a}):Gt(u,o,{by:l,reason:i.note,now:a});return d.ok?{ok:!0,message:c?`${d.proposal.article.path} written to the shared wiki`:`${e} rejected`}:d}case"whatsapp":{let u=await yn(t.root,o,c?"yes":"no",{by:l,now:a,send:t.sendWhatsApp});return u.ok?{ok:!0,message:c?`${e}: sent to ${u.draft.chat_name||u.draft.to}`:`${e}: dropped, nothing sent`}:u}case"request":{let u=z(t),d=u?.get(o);return!u||!d||d.state!=="needs_attention"?{ok:!1,error:`nothing waiting for "${e}"`}:c?xn(Te(t)).enabled?(u.requestPickup(o,a),{ok:!0,message:`${e}: ${d.agentId} will be asked to pick it up again`}):{ok:!1,error:"Requests are off, so nothing would hand it back. Turn them on (agentx requests settings --enabled on), or answer no to drop it."}:(u.close(o,"dropped",i.note?.trim()||`dropped by ${l}`,a),{ok:!0,message:`${e}: dropped`})}}}var In=new Set(["127.0.0.1","::1","::ffff:127.0.0.1"]);function Sl(t){return t==="/api/memory"||t.startsWith("/api/memory/")||t==="/approvals"||t.startsWith("/approvals/")||t==="/requests"||t.startsWith("/requests/")||t==="/watchers"||t.startsWith("/watchers/")||t==="/follow-up"||t.startsWith("/follow-up/")||t==="/events/recent"||/^\/agents\/[^/]+\/events$/.test(t)||t==="/a2a/delegations"||t.startsWith("/a2a/delegations/")||t==="/traces"||t.startsWith("/traces/")||t==="/voice/history"||t.startsWith("/voice/history/")||t==="/voice/transcribe"||t==="/voice/speak"||t==="/app-files"||t==="/calls"||t.startsWith("/calls/")||t==="/webrtc/camera"||t.startsWith("/webrtc/camera/")||t==="/mesh/guests"||t.startsWith("/mesh/guests/")||t==="/wiki/agents"||t==="/wiki/entries"||t==="/wiki/articles"||t==="/wiki/article"||t==="/wiki/notes"||t==="/api/wiki/curate"||t==="/api/wiki/curate/restore"||t==="/api/signals/stopped"||t.startsWith("/api/signals/stopped/")||t==="/api/review-gate/reviews"}function vl(t){return t==="/reload"||t==="/api/processes/kill"||t==="/send"||t==="/send/agent"||t==="/send/contact"||t==="/mesh/announce"||t==="/voice/settings"||t==="/voice/preview"||/^\/api\/tasks\/[^/]+\/(cancel|followup)$/.test(t)||/^\/mesh\/guests\/[^/]+\/(pause|resume|end|update)$/.test(t)||/^\/crons\/[^/]+\/enabled$/.test(t)||/^\/workflow-runs\/[^/]+\/cancel$/.test(t)||t==="/api/signals/stop"||t==="/api/signals/resume"||t==="/api/signals/drop"||t==="/api/review-gate/replay"}function $l(t){return In.has(t)}function Al(t){if(t.foreignBrowser)return{allowed:!1,reason:"foreign-browser-origin"};if(t.enforcementDisabled)return{allowed:!0,reason:"disabled"};if(In.has(t.remoteAddress))return{allowed:!0,reason:"loopback"};if(t.acceptedTokens.size===0)return{allowed:!0,reason:"no-tokens-configured"};let e=t.authorizationHeader||"",n=e.startsWith("Bearer ")?e.slice(7).trim():"";return n&&t.acceptedTokens.has(n)?{allowed:!0,reason:"token"}:{allowed:!1,reason:"missing-or-invalid-token"}}function Rl(t,e=process.env){let n=new Set;e.MESH_TOKEN&&n.add(e.MESH_TOKEN);for(let i of t.mesh?.peers||[])i.token&&n.add(i.token);return n}function _l(t,e,n=process.env){let i=s=>s.replace(/\/+$/,"");return(e===i(t.daemonUrl)?t.token:t.daemons.find(s=>i(s.url)===e)?.token)||n.MESH_TOKEN||void 0}function ae(t){return(Array.isArray(t)?t[0]:t)?.trim()??""}function Xi(t){try{return new URL(t).host.toLowerCase()}catch{return null}}function Gi(t=process.env){return new Set((t.AGENTX_ALLOWED_ORIGINS||"").split(",").map(e=>e.trim().replace(/\/+$/,"").toLowerCase()).filter(Boolean))}function El(t,e=Gi()){let n=ae(t.origin);if(n){if(e.has(n.replace(/\/+$/,"").toLowerCase()))return"same-origin";let r=Xi(n),s=[ae(t.host),ae(t["x-forwarded-host"])].filter(Boolean).map(o=>o.toLowerCase());return r&&s.includes(r)?"same-origin":"foreign"}let i=ae(t["sec-fetch-site"]).toLowerCase();return i==="cross-site"||i==="same-site"?"foreign":"none"}function Tl(t){let e=(t||"GET").toUpperCase();return e!=="GET"&&e!=="HEAD"}import{existsSync as Qn,mkdirSync as vs,readFileSync as $s,renameSync as As,writeFileSync as Rs}from"fs";import{homedir as _s}from"os";import{dirname as Is,join as Es}from"path";import{execFile as ss,execFileSync as os}from"child_process";import{execFileSync as Ki}from"child_process";import{existsSync as Tn,mkdirSync as Ji,readdirSync as Yi,readFileSync as Cn,renameSync as Zi,writeFileSync as Qi}from"fs";import{homedir as Dn}from"os";import{join as Pe}from"path";var S="siri:",Pn="com.apple.ttsbundle.gryphon-neural_",Nn=t=>!!t&&t.startsWith(Pn),es=["/usr/bin/say","/usr/bin/defaults","/usr/bin/plutil"],ts=()=>{try{return Ki("/usr/bin/defaults",["read","com.apple.Accessibility"],{stdio:"ignore",timeout:5e3}),!0}catch{return!1}},De;function Ne(t={}){let e=t.platform!==void 0||t.exists!==void 0||t.prefDomain!==void 0;if(!e&&De!==void 0)return De;let{platform:n=process.platform,exists:i=Tn,prefDomain:r=ts}=t,s=n==="darwin"&&es.every(o=>i(o))&&r();return e||(De=s),s}var Ln=["/System/Library/AssetsV2/com_apple_MobileAsset_Trial_Siri_SiriTextToSpeech/purpose_auto","/System/Library/AssetsV2/com_apple_MobileAsset_UAF_Siri_TextToSpeech/purpose_auto"],On={aaron:"male",damon:"male",daniel:"male",pierre:"male",samer:"male",arthur:"male",gordon:"male",martin:"male",nora:"female",simone:"female",marie:"female",soha:"female",martha:"female",catherine:"female",helena:"female",nicky:"female"},Le=t=>On[t.toLowerCase()]??null;function le(t){let e=/^com\.apple\.ttsbundle\.gryphon-neural_([a-z]+)_([a-z]{2}-[A-Z]{2})_premium$/.exec(t);return e?{name:e[1],locale:e[2]}:null}var ns=/com\.apple\.siri\.tts\.voice\.([a-z]{2})_([A-Z]{2})\.([a-z]+)\.neural\.premium/g;function rs(t){let e=new Map;for(let n of t)for(let[,i,r,s]of n.matchAll(ns)){let o=`${i}-${r}`,a=`${Pn}${s}_${o}_premium`;e.has(a)||e.set(a,{id:a,name:s[0].toUpperCase()+s.slice(1),locale:o,quality:"premium",gender:On[s]??null,siri:!0})}return[...e.values()]}function ce(t=Ln,e={}){if(!Ne(e))return[];let n=[];for(let i of t){let r;try{r=Yi(i)}catch{continue}for(let s of r)try{n.push(Cn(Pe(i,s,"Info.plist"),"latin1"))}catch{}}return rs(n)}var En=`#!/bin/sh
|
|
55
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`);this.db.transaction(()=>{s.run(e,n,r),i.forEach((a,l)=>{let c=l===0,u=c&&a.agentId===n&&a.kind!=="message";o.run(e,l+1,a.name,a.kind,a.agentId,a.doneWhen,c?"active":"pending",a.needsApproval?1:0,a.message??null,a.toChannel??null,a.toChat??null,a.toAccount??null,a.checkUrl??null,a.checkContains??null,a.stallMinutes??null,u?r:null,r)}),this.event(e,null,"created",`${i.length} steps, written by ${n}`,r)})()}get(e){let n=this.db.prepare("SELECT * FROM request_plans WHERE request_id = ?").get(e);return n?Ce(n):null}steps(e){return this.db.prepare("SELECT * FROM request_plan_steps WHERE request_id = ? ORDER BY idx").all(e).map(Rn)}step(e,n){let i=this.db.prepare("SELECT * FROM request_plan_steps WHERE request_id = ? AND idx = ?").get(e,n);return i?Rn(i):null}listActive(){return this.db.prepare("SELECT * FROM request_plans WHERE state = 'active' ORDER BY created_at, rowid").all().map(Ce)}updateStep(e,n,i){let r=[],s=[];for(let[o,a]of Object.entries(i)){let l=Wi[o];!l||a===void 0||(r.push(`${l} = ?`),s.push(typeof a=="boolean"?a?1:0:a))}r.length&&this.db.prepare(`UPDATE request_plan_steps SET ${r.join(", ")} WHERE request_id = ? AND idx = ?`).run(...s,e,n)}finish(e,n,i){return this.db.prepare("UPDATE request_plans SET state = ?, finished_at = ? WHERE request_id = ? AND state = 'active'").run(n,i,e).changes>0}markNotified(e,n){this.db.prepare("UPDATE request_plans SET notified_at = ? WHERE request_id = ?").run(n,e)}awaitingSummary(){return this.db.prepare("SELECT * FROM request_plans WHERE state = 'done' AND notified_at IS NULL ORDER BY finished_at").all().map(Ce)}event(e,n,i,r,s){this.db.prepare("INSERT INTO request_plan_events (request_id, step, at, kind, detail) VALUES (?, ?, ?, ?, ?)").run(e,n,s,i,r.replace(/\s+/g," ").trim().slice(0,Oi))}events(e,n=200){return this.db.prepare("SELECT request_id, step, at, kind, detail FROM request_plan_events WHERE request_id = ? ORDER BY at, rowid LIMIT ?").all(e,n).map(i=>({requestId:i.request_id,step:i.step??null,at:i.at,kind:i.kind,detail:i.detail}))}},ul=Dt;import{existsSync as ji,readFileSync as Ui}from"fs";Mt();si();function In(t){let e=Wt(t),n={};if(ji(e))try{n=Nt(JSON.parse(Ui(e,"utf-8")))}catch{n={}}let i=ve.safeParse(n?.requests);return i.success?i.data:ve.parse(void 0)}async function hl(t,e={}){let n=(t.channels??[]).filter(i=>!ke.has(i.toLowerCase().split("@")[0]));return n.length?{success:!1,error:`unknown channel ${n.map(i=>`"${i}"`).join(", ")}: use ${[...ke].join(", ")}`}:jt(i=>{let r=i.requests??={};for(let s of["enabled","channels","from","staleAfterHours","retentionDays"])t[s]!==void 0&&(r[s]=t[s]);if(t.plans){let s=r.plans??={};for(let o of["enabled","stallMinutes","maxNudges","approveKinds","disabledAgents"])t.plans[o]!==void 0&&(s[o]=t.plans[o])}if(t.checkers){let s=r.checkers??={};for(let o of["enabled","checkEveryMinutes"])t.checkers[o]!==void 0&&(s[o]=t.checkers[o])}},{configPath:e.configPath,reload:e.reload})}var Cn=["card","schedule","memory","wiki","whatsapp","request"],qi=280;function L(t,e=qi){let n=t.replace(/\s+/g," ").trim();return n.length>e?`${n.slice(0,e-1)}\u2026`:n}function De(t){if(t.configPath)return R(t.configPath);let e=[R(t.root,"agentx.json"),R(t.root,".agentx","config.json")];return e.find(n=>H(n))??e[0]}function Pe(t){return t.wikiDir?R(t.wikiDir):R(t.root,".agentx","wiki")}function Bi(t){return q(t.root,"pending").map(Hi)}function Hi(t){return{key:`card:${t.id}`,kind:"card",title:t.title,ask:t.ask,yes:`tell ${t.raised_by} yes`,no:`tell ${t.raised_by} no`,recommend:t.recommend,if_silent:t.if_silent,expires:t.expires,...t.source?{source:t.source}:{},raised_by:t.raised_by,...t.node?{node:t.node}:{},created_at:t.created_at,...t.choices?{choices:t.choices,more:`agentx approvals popup card:${t.id}`}:{},...t.draft?{draft:t.draft}:{},...t.context||t.draft?{detail:L([t.context,t.draft?`Suggested message: ${t.draft}`:""].filter(Boolean).join(" \xB7 "))}:{}}}function zi(t){let e=De(t);if(!H(e))return[];let n;try{n=JSON.parse(Vi(e,"utf-8"))}catch{return[]}let i=new Date(t.now??Date.now()),r=[];for(let[s,o]of Object.entries(n?.crons??{})){let a=o?.approval;if(!a||a.action!=="create"&&a.action!=="delete")continue;let l=o.timezone||"UTC",c=o.schedule?Bt(o.schedule):"",u=o.schedule?`${c.charAt(0).toLowerCase()}${c.slice(1)} (${o.schedule})`:"no schedule",d=String(o.prompt??o.command??""),p=a.action==="create";r.push({key:`schedule:${s}`,kind:"schedule",title:p?`New schedule "${s}" for ${o.agent??"an agent"}`:`Delete schedule "${s}"`,ask:p?`Let ${o.agent??"the agent"} run this ${u}?`:`Remove the schedule "${s}" (${u})?`,yes:p?"enable it":"remove it",no:p?"drop the request":"keep the schedule",raised_by:String(a.requestedBy??"unknown"),created_at:String(a.requestedAt??""),detail:L(`${d}${p&&o.schedule?` \xB7 first run ${zt(Ht(o.schedule,l,i),l)}`:""}`),more:"agentx schedule list"})}return r}function Dn(t){let e=R(t,".agentx","memory");return H(e)?Fi(e).filter(n=>n.endsWith(".jsonl")).map(n=>n.slice(0,-6)).sort():[]}function Xi(t){let e=Dn(t.root);if(e.length===0)return[];let n=new $e(t.root),i=[];for(let r of e)for(let s of n.held(r))i.push({key:`memory:${r}/${s.id}`,kind:"memory",title:`Fact ${r} learned from ${s.source.channel}`,ask:`Let ${r} use this fact in its prompts?`,yes:"use it",no:"keep it out for good",raised_by:r,created_at:s.createdAt,detail:L(s.content),more:`agentx memory facts held --agent ${r}`});return i}function Gi(t){let e=t.sources.filter(n=>n.failure);return e.length?e.map(n=>`Recurring failure: ${n.agentId}'s ${n.failure.tool} fails with "${n.failure.errorClass}" in ${n.occurrences??1} sessions (${n.failure.runs} runs).`).join(" "):`${t.sources.length} source(s)${t.occurrences>1?`, seen in ${t.occurrences} sessions`:""}.`}function Ki(t){return Qt(Pe(t),"pending").map(e=>{let n=e.evidence;return{key:`wiki:${e.id}`,kind:"wiki",title:e.article.title,ask:e.replaces?`Update "${e.article.path}" in the shared wiki?`:`Add "${e.article.path}" to the shared wiki?`,yes:"write the article",no:"decline it",raised_by:n.agents.join(", ")||"wiki promote",created_at:e.createdAt,detail:L(`${Gi(n)} ${e.article.content}`),more:`agentx wiki proposals show ${e.id}`}})}function Ji(t){return $n(t.root,"pending").map(e=>({key:`whatsapp:${e.id}`,kind:"whatsapp",title:`WhatsApp reply to ${e.chat_name||e.to}`,ask:`Send this to ${e.chat_name||e.to}? "${e.text}"`,yes:"send it on WhatsApp",no:"drop the draft",raised_by:e.agent,created_at:e.created_at,detail:L(`${e.triage}: ${e.summary}`),more:"agentx whatsapp triage log"}))}function z(t){if(t.requests)return t.requests;if(R(t.root)!==process.cwd()||!H(R(t.root,".agentx","db.sqlite")))return null;let e=Se({quiet:!0});if(!e)return null;let n=En.get(e);return!n&&!Pt(e)?null:(n||En.set(e,n=new Lt(e)),n)}var En=new WeakMap;function Cl(t){if(t.plans)return t.plans;if(t.requests||R(t.root)!==process.cwd()||!H(R(t.root,".agentx","db.sqlite")))return null;let e=Se({quiet:!0});if(!e||!_n(e))return null;let n=Tn.get(e);return n||Tn.set(e,n=new ae(e)),n}var Tn=new WeakMap;function Yi(t){let e=z(t);return e?e.listByState("needs_attention").map(n=>({key:`request:${n.id}`,kind:"request",title:`Request not finished: ${L(n.text,80)}`,ask:`Ask ${n.agentId} to pick it up again?`,yes:`hand it back to ${n.agentId}`,no:"drop the request",raised_by:n.agentId,created_at:new Date(n.createdAt).toISOString(),detail:L(`${n.attentionReason??"It needs attention"}. Asked on ${n.channel}: ${n.text}`),more:`agentx requests show ${n.id}`})):[]}var Pn={card:Bi,schedule:zi,memory:Xi,wiki:Ki,whatsapp:Ji,request:Yi};function Zi(t,e){let n=t.expires?Date.parse(t.expires):1/0,i=e.expires?Date.parse(e.expires):1/0;return n!==i?n-i:(Date.parse(t.created_at)||0)-(Date.parse(e.created_at)||0)}function Dl(t,e={}){let n=t.now??Date.now(),{snoozed:i}=A(t.root),r=[],s=[],o=0;for(let a of e.kinds??Cn){let l;try{l=Pn[a](t)}catch(c){s.push({kind:a,error:String(c?.message??c).slice(0,200)});continue}for(let c of l){let u=i[c.key];if(u&&Date.parse(u)>n){if(!e.includeSnoozed){o++;continue}c.snoozed_until=u}r.push(c)}}return r.sort(Zi),{items:r,snoozed:o,errors:s}}function Qi(t){let e=t.indexOf(":");if(e<=0)return null;let n=t.slice(0,e),i=t.slice(e+1);return!Cn.includes(n)||!i?null:{kind:n,ref:i}}function es(t,e,n){switch(e){case"card":return V(t.root,n)?.status==="pending";case"wiki":return Zt(Pe(t),n)?.status==="pending";case"whatsapp":return oe(t.root,n)?.status==="pending";default:return Pn[e](t).some(i=>i.key===`${e}:${n}`)}}async function Ln(t,e,n,i={}){let r=Qi(e);if(!r)return{ok:!1,error:`unknown item "${e}": use a key from \`agentx approvals list\``};let{kind:s,ref:o}=r,a=t.now??Date.now(),l=i.by??"operator";if(n==="later"){if(!es(t,s,o))return{ok:!1,error:`nothing waiting for "${e}"`};let u=i.laterHours&&i.laterHours>0?i.laterHours:24,d=new Date(a+u*36e5);return mn(t.root,e,d,a),{ok:!0,message:`${e} put off until ${d.toISOString()}`}}let c=n==="yes";switch(s){case"card":{let u=on(t.root,o,c?"yes":"no",{by:l,note:i.note,now:a,choice:i.choice,text:i.text});return u.ok?{ok:!0,message:`${e}: ${u.card.raised_by} will be told ${c?"yes":"no"}${u.card.choice?` (${u.card.choice})`:""}`}:u}case"schedule":{let u=await(c?Xt:Gt)(o,{configPath:De(t),reload:t.reload});return u.success?{ok:!0,message:u.message}:{ok:!1,error:u.message}}case"memory":{let u=o.indexOf("/");if(u<=0)return{ok:!1,error:"memory keys look like memory:<agent>/<fact-id>"};let d=o.slice(0,u),p=o.slice(u+1);if(!Dn(t.root).includes(d))return{ok:!1,error:`no memory for agent "${d}"`};let g=new $e(t.root);return g.held(d).some(f=>f.id===p)?(g.review(d,p,c?"approved":"rejected",l),{ok:!0,message:`${e} ${c?"approved: the agent may use it":"rejected: it stays out of prompts"}`}):{ok:!1,error:`fact "${p}" isn't waiting for review`}}case"wiki":{let u=Pe(t),d=c?en(u,o,{by:l,force:i.force,now:a}):tn(u,o,{by:l,reason:i.note,now:a});return d.ok?{ok:!0,message:c?`${d.proposal.article.path} written to the shared wiki`:`${e} rejected`}:d}case"whatsapp":{let u=await An(t.root,o,c?"yes":"no",{by:l,now:a,send:t.sendWhatsApp});return u.ok?{ok:!0,message:c?`${e}: sent to ${u.draft.chat_name||u.draft.to}`:`${e}: dropped, nothing sent`}:u}case"request":{let u=z(t),d=u?.get(o);return!u||!d||d.state!=="needs_attention"?{ok:!1,error:`nothing waiting for "${e}"`}:c?In(De(t)).enabled?(u.requestPickup(o,a),{ok:!0,message:`${e}: ${d.agentId} will be asked to pick it up again`}):{ok:!1,error:"Requests are off, so nothing would hand it back. Turn them on (agentx requests settings --enabled on), or answer no to drop it."}:(u.close(o,"dropped",i.note?.trim()||`dropped by ${l}`,a),{ok:!0,message:`${e}: dropped`})}}}var Nn=new Set(["127.0.0.1","::1","::ffff:127.0.0.1"]);function Ll(t){return t==="/api/memory"||t.startsWith("/api/memory/")||t==="/approvals"||t.startsWith("/approvals/")||t==="/requests"||t.startsWith("/requests/")||t==="/watchers"||t.startsWith("/watchers/")||t==="/follow-up"||t.startsWith("/follow-up/")||t==="/events/recent"||/^\/agents\/[^/]+\/events$/.test(t)||t==="/a2a/delegations"||t.startsWith("/a2a/delegations/")||t==="/traces"||t.startsWith("/traces/")||t==="/voice/history"||t.startsWith("/voice/history/")||t==="/voice/transcribe"||t==="/voice/speak"||t==="/app-files"||t==="/calls"||t.startsWith("/calls/")||t==="/webrtc/camera"||t.startsWith("/webrtc/camera/")||t==="/mesh/guests"||t.startsWith("/mesh/guests/")||t==="/wiki/agents"||t==="/wiki/entries"||t==="/wiki/articles"||t==="/wiki/article"||t==="/wiki/notes"||t==="/api/wiki/curate"||t==="/api/wiki/curate/restore"||t==="/api/signals/stopped"||t.startsWith("/api/signals/stopped/")||t==="/api/review-gate/reviews"}function Nl(t){return t==="/reload"||t==="/api/processes/kill"||t==="/send"||t==="/send/agent"||t==="/send/contact"||t==="/mesh/announce"||t==="/voice/settings"||t==="/voice/preview"||/^\/api\/tasks\/[^/]+\/(cancel|followup)$/.test(t)||/^\/mesh\/guests\/[^/]+\/(pause|resume|end|update)$/.test(t)||/^\/crons\/[^/]+\/enabled$/.test(t)||/^\/workflow-runs\/[^/]+\/cancel$/.test(t)||t==="/api/signals/stop"||t==="/api/signals/resume"||t==="/api/signals/drop"||t==="/api/review-gate/replay"}function Ol(t){return Nn.has(t)}function Ml(t){if(t.foreignBrowser)return{allowed:!1,reason:"foreign-browser-origin"};if(t.enforcementDisabled)return{allowed:!0,reason:"disabled"};if(Nn.has(t.remoteAddress))return{allowed:!0,reason:"loopback"};if(t.acceptedTokens.size===0)return{allowed:!0,reason:"no-tokens-configured"};let e=t.authorizationHeader||"",n=e.startsWith("Bearer ")?e.slice(7).trim():"";return n&&t.acceptedTokens.has(n)?{allowed:!0,reason:"token"}:{allowed:!1,reason:"missing-or-invalid-token"}}function Wl(t,e=process.env){let n=new Set;e.MESH_TOKEN&&n.add(e.MESH_TOKEN);for(let i of t.mesh?.peers||[])i.token&&n.add(i.token);return n}function jl(t,e,n=process.env){let i=s=>s.replace(/\/+$/,"");return(e===i(t.daemonUrl)?t.token:t.daemons.find(s=>i(s.url)===e)?.token)||n.MESH_TOKEN||void 0}function le(t){return(Array.isArray(t)?t[0]:t)?.trim()??""}function ts(t){try{return new URL(t).host.toLowerCase()}catch{return null}}function ns(t=process.env){return new Set((t.AGENTX_ALLOWED_ORIGINS||"").split(",").map(e=>e.trim().replace(/\/+$/,"").toLowerCase()).filter(Boolean))}function Fl(t,e=ns()){let n=le(t.origin);if(n){if(e.has(n.replace(/\/+$/,"").toLowerCase()))return"same-origin";let r=ts(n),s=[le(t.host),le(t["x-forwarded-host"])].filter(Boolean).map(o=>o.toLowerCase());return r&&s.includes(r)?"same-origin":"foreign"}let i=le(t["sec-fetch-site"]).toLowerCase();return i==="cross-site"||i==="same-site"?"foreign":"none"}function Vl(t){let e=(t||"GET").toUpperCase();return e!=="GET"&&e!=="HEAD"}import{existsSync as or,mkdirSync as Cs,readFileSync as Ds,renameSync as Ps,writeFileSync as Ls}from"fs";import{homedir as Ns}from"os";import{dirname as Os,join as Ms}from"path";import{execFile as gs,execFileSync as fs}from"child_process";import{execFileSync as rs}from"child_process";import{existsSync as Mn,mkdirSync as is,readdirSync as ss,readFileSync as Wn,renameSync as os,writeFileSync as as}from"fs";import{homedir as jn}from"os";import{join as Ne}from"path";var x="siri:",Un="com.apple.ttsbundle.gryphon-neural_",Fn=t=>!!t&&t.startsWith(Un),ls=["/usr/bin/say","/usr/bin/defaults","/usr/bin/plutil"],cs=()=>{try{return rs("/usr/bin/defaults",["read","com.apple.Accessibility"],{stdio:"ignore",timeout:5e3}),!0}catch{return!1}},Le;function Oe(t={}){let e=t.platform!==void 0||t.exists!==void 0||t.prefDomain!==void 0;if(!e&&Le!==void 0)return Le;let{platform:n=process.platform,exists:i=Mn,prefDomain:r=cs}=t,s=n==="darwin"&&ls.every(o=>i(o))&&r();return e||(Le=s),s}var Vn=["/System/Library/AssetsV2/com_apple_MobileAsset_Trial_Siri_SiriTextToSpeech/purpose_auto","/System/Library/AssetsV2/com_apple_MobileAsset_UAF_Siri_TextToSpeech/purpose_auto"],qn={aaron:"male",damon:"male",daniel:"male",pierre:"male",samer:"male",arthur:"male",gordon:"male",martin:"male",nora:"female",simone:"female",marie:"female",soha:"female",martha:"female",catherine:"female",helena:"female",nicky:"female"},Me=t=>qn[t.toLowerCase()]??null;function ce(t){let e=/^com\.apple\.ttsbundle\.gryphon-neural_([a-z]+)_([a-z]{2}-[A-Z]{2})_premium$/.exec(t);return e?{name:e[1],locale:e[2]}:null}var us=/com\.apple\.siri\.tts\.voice\.([a-z]{2})_([A-Z]{2})\.([a-z]+)\.neural\.premium/g;function ds(t){let e=new Map;for(let n of t)for(let[,i,r,s]of n.matchAll(us)){let o=`${i}-${r}`,a=`${Un}${s}_${o}_premium`;e.has(a)||e.set(a,{id:a,name:s[0].toUpperCase()+s.slice(1),locale:o,quality:"premium",gender:qn[s]??null,siri:!0})}return[...e.values()]}function ue(t=Vn,e={}){if(!Oe(e))return[];let n=[];for(let i of t){let r;try{r=ss(i)}catch{continue}for(let s of r)try{n.push(Wn(Ne(i,s,"Info.plist"),"latin1"))}catch{}}return ds(n)}var On=`#!/bin/sh
|
|
56
56
|
# Written by agentx; shared by the daemon and AgentX Voice. Do not edit.
|
|
57
57
|
# siri-say.sh [voice] < text speak one line. A Siri voice id switches
|
|
58
58
|
# the OS default for it; any other id is
|
|
@@ -64,7 +64,7 @@ D=com.apple.Accessibility K=SpokenContentDefaultVoiceSelectionsByLanguage
|
|
|
64
64
|
dir="$HOME/.agentx/voice" lock="$HOME/.agentx/voice/siri.lock" saved="$HOME/.agentx/voice/siri-saved.plist"
|
|
65
65
|
stops="$dir/stop"
|
|
66
66
|
read_s=\${AGENTX_SAY_READ_S:-5} stale_s=\${AGENTX_SAY_STALE_S:-30} max_s=\${AGENTX_SAY_MAX_S:-300}
|
|
67
|
-
assets=\${AGENTX_SIRI_ASSET_DIRS:-"${
|
|
67
|
+
assets=\${AGENTX_SIRI_ASSET_DIRS:-"${Vn.join(" ")}"}
|
|
68
68
|
if [ "$1" = --stop ]; then
|
|
69
69
|
mkdir -p "$dir" || exit 1
|
|
70
70
|
# Queued lines see this change and drop. The owner's trap stops say,
|
|
@@ -157,32 +157,32 @@ wait "$say_pid"
|
|
|
157
157
|
status=$?
|
|
158
158
|
say_pid=
|
|
159
159
|
finish $status
|
|
160
|
-
`,
|
|
160
|
+
`,ps=(t=jn())=>Ne(t,".agentx","voice","siri-say.sh");function Bn(t=jn()){let e=ps(t);return Mn(e)&&Wn(e,"utf8")===On||(is(Ne(t,".agentx","voice"),{recursive:!0}),as(`${e}.tmp`,On,{mode:493}),os(`${e}.tmp`,e)),e}var Hn=`ObjC.import("AVFoundation")
|
|
161
161
|
const vs = $.AVSpeechSynthesisVoice.speechVoices, out = []
|
|
162
162
|
for (let i = 0; i < vs.count; i++) {
|
|
163
163
|
const v = vs.objectAtIndex(i)
|
|
164
164
|
out.push([v.identifier.js, v.name.js, v.language.js, Number(v.quality), Number(v.gender)].join("\\t"))
|
|
165
165
|
}
|
|
166
|
-
out.join("\\n")`,
|
|
167
|
-
`)){let[i,r,s,o,a]=n.split(" ");!i||!r||!s||i.includes(".siri_")||i.startsWith("com.apple.speech.synthesis.voice.")&&!
|
|
168
|
-
`)[0]}`),
|
|
169
|
-
`),
|
|
170
|
-
${
|
|
166
|
+
out.join("\\n")`,ms=new Set(["Fred","Kathy","Ralph","Junior"]),hs={Flo:"female",Sandy:"female",Shelley:"female",Grandma:"female",Kathy:"female",Eddy:"male",Reed:"male",Rocko:"male",Grandpa:"male",Fred:"male",Ralph:"male",Junior:"male"};function zn(t){let e=[];for(let n of t.split(`
|
|
167
|
+
`)){let[i,r,s,o,a]=n.split(" ");!i||!r||!s||i.includes(".siri_")||i.startsWith("com.apple.speech.synthesis.voice.")&&!ms.has(r)||e.push({id:i,name:r,locale:s,quality:o==="3"?"premium":o==="2"?"enhanced":"standard",gender:a==="1"?"male":a==="2"?"female":hs[r]??null})}return e}var ys=10*60*1e3,Yl=60*1e3,W=null,We=!1;function je(t=Date.now(),e=ys){if(process.platform!=="darwin")return[];if(W)t-W.at>e&&!We&&(We=!0,gs("osascript",["-l","JavaScript","-e",Hn],{timeout:1e4},(n,i)=>{We=!1,n||(W={at:Date.now(),voices:[...zn(String(i)),...ue()]})}));else try{W={at:t,voices:[...zn(fs("osascript",["-l","JavaScript","-e",Hn],{encoding:"utf8",timeout:1e4})),...ue()]}}catch(n){Ue(`[voice] could not list system voices: ${String(n?.message??n).split(`
|
|
168
|
+
`)[0]}`),W={at:t,voices:ue()}}return W.voices}var Ue=t=>process.stderr.write(t+`
|
|
169
|
+
`),de=new Set;function Zl(t){Ue=t}function N(t,e){de.has(t)||(de.add(t),Ue(e))}function Kn(t){for(let e of de)t(e)&&de.delete(e)}var Jn=()=>{};function Ql(t){Jn=t}function Yn(t){try{Jn(t)}catch(e){N("missing-hook",`[voice] missing-voice check failed: ${e?.message??e}`)}}var bs={premium:3,enhanced:2,standard:1},ws=new Set(["Grandma","Grandpa"]);function Xn(t){let e=t.id.startsWith("com.apple.voice.")?2:t.id.startsWith("com.apple.eloquence.")&&!ws.has(t.name)?1:0;return bs[t.quality]*10+e}var j=t=>t.toLowerCase().split(/[-_]/)[0],Gn=t=>t.id.startsWith("com.apple.voice.");function Fe(t,e,n,i=new Set){let r=X(t.filter(a=>!a.siri&&j(a.locale)===j(e)),e);if(r.some(Gn)&&(r=r.filter(Gn)),n==="female"||n==="male"){let a=r.filter(l=>l.gender===n);a.length&&(r=a)}if(!r.length)return null;let s=r.filter(a=>a.quality===r[0].quality),o=new Set([...i].map(a=>a.toLowerCase()));return s.find(a=>!o.has(a.name.toLowerCase()))??s[0]}function X(t,e="en"){let n=e.toLowerCase().replace("_","-"),i=j(e),r=t.filter(s=>j(s.locale)===i);return(r.length?r:t).slice().sort((s,o)=>Xn(o)-Xn(s)||+(o.locale.toLowerCase()===n)-+(s.locale.toLowerCase()===n)||s.name.localeCompare(o.name)||s.locale.localeCompare(o.locale))}function G(t,e,n="en"){let i=t.trim();if(!i)return null;let r=e.find(c=>c.id===i);if(r)return r;if(i.toLowerCase().startsWith(x)){let c=i.slice(x.length).trim().toLowerCase(),u=X(e.filter(p=>p.siri&&p.name.toLowerCase()===c),n)[0];if(u||!c)return u??null;let d=G(c,e.filter(p=>j(p.locale)===j(n)),n);return d&&N(`siri:${c}`,`[voice] Siri voice "${c}" is not installed; speaking with ${d.name} (${d.locale}) instead.`),d}e=e.filter(c=>!c.siri);let s=/^(.+?)\s*\((premium|enhanced)\)$/i.exec(i),o=(s?s[1]:i.replace(/\s*\(.*\)\s*$/,"")).trim().toLowerCase(),a=X(e.filter(c=>c.name.toLowerCase()===o),n);return(s?a.find(c=>c.quality===s[2].toLowerCase()):void 0)??a[0]??null}function Zn(t,e,n=new Set){let i=new Map;if(!e.length)return i;let r=new Set([...n].map(o=>o.toLowerCase())),s="female";for(let o of t){let a=o.gender==="female"||o.gender==="male",l=a?o.gender:s,c=e.filter(d=>!r.has(d.name.toLowerCase())),u=c.find(d=>d.gender===l)??(a?e.find(d=>d.gender===l):void 0)??c[0]??e[i.size%e.length];i.set(o.id,u),r.add(u.name.toLowerCase()),a||(s=s==="female"?"male":"female")}return i}Rt();var Ve="system",ks=t=>t.trim().toLowerCase()===Ve,Ss="21m00Tcm4TlvDq8ikWAM";function qe(t,e,n={},i=je()){let r=e[t],s=r?.name||t,o=r?.voice,a=He(e,n,i).get(t)??null,l=As(t,o?.system,o?.gender,n,i);return{agentId:t,name:s,provider:o?.provider??n.provider??"system",elevenlabsVoiceId:o?.elevenlabsVoiceId||null,systemVoice:a?.id??null,systemVoiceName:a?ge(a):null,systemByLanguage:l,fallback:(n.fallback??"system")==="system",gender:o?.gender??null,style:o?.style||null,intro:o?.intro||_s(s,r?.systemPrompt),...o?.rate?{rate:o.rate}:{},...o?.priority?{priority:o.priority}:{}}}var ge=t=>`${t.name}${t.siri?" (Siri)":t.quality==="standard"?"":` (${t.quality[0].toUpperCase()}${t.quality.slice(1)})`} ${t.locale}`;function xs(t,e,n,i){if(!e||!n.length)return null;let r=G(e,n,i);return r||(N(`${t}:${e}`,`[voice] ${t}: system voice "${e}" is not installed; using the next choice. Run \`agentx voice list\` to see installed voices.`),Yn(e)),r}function nr(t,e){let n=t.trim();if(n.toLowerCase().startsWith(x))return{locale:e,gender:Me(n.slice(x.length).trim())};let i=ce(n);return i?{locale:i.locale,gender:Me(i.name)}:{locale:/^com\.apple\.voice\.[a-z]+\.([a-z]{2}-[A-Z]{2})\./.exec(n)?.[1]??e,gender:null}}var rr=t=>t.toLowerCase().split(/[-_]/)[0],Qn=(t,e)=>typeof t=="string"?t:t?.[rr(e)];function pe(t,e,n,i){if(e!==void 0)return ks(e)?null:xs(t,e,n,i)??void 0}var Be=(t,e)=>!t||!t.gender||t.gender==="neutral"||!e||e==="neutral"||t.gender===e;function vs(t,e,n,i=new Set){let r=e.locale??"en",s=new Map,o=[],a=pe("voice.system",Qn(e.system,r),n,r),l=()=>new Set([...i,...[...s.values()].flatMap(u=>u?[u.name]:[])]);for(let u of t){let d=Qn(u.system,r),p=pe(u.id,d,n,r),g=p!==void 0?p:d!==void 0&&n.length?$s(u,d,r,a,n,l()):a!==void 0&&Be(a,u.gender)?a:void 0;g!==void 0?s.set(u.id,g):o.push({id:u.id,gender:u.gender??null})}let c=l();for(let[u,d]of Zn(o,X(n.filter(p=>!p.siri),r),c))s.set(u,d);return s}function $s(t,e,n,i,r,s){for(let a of t.fallbacks??[]){let l=pe(`${t.id}.fallbacks`,a,r,n);if(l!==void 0)return l}if(i!==void 0&&Be(i,t.gender))return i;let o=nr(e,n);return Fe(r,o.locale,t.gender??o.gender,s)??void 0}function As(t,e,n,i,r){if(typeof e=="string")return{};let s={},o=(a,l,c)=>{if(!(!l||typeof l=="string"))for(let[u,d]of Object.entries(l)){let p=pe(`${a}.${u}`,d,r,u);p===void 0&&r.length&&(p=Fe(r,u,n??nr(d,u).gender)??void 0),p!==void 0&&c(p)&&(s[rr(u)]=p)}};return o("voice.system",i.system,a=>Be(a,n)),o(t,e,()=>!0),s}function ic(t,e){let n=e?ee(e):null;if(!n||!(n in t.systemByLanguage))return t;let i=t.systemByLanguage[n];return{...t,systemVoice:i?.id??null,systemVoiceName:i?ge(i):null}}function He(t,e={},n=je()){let i=Object.entries(t).map(([r,s])=>({id:r,system:s.voice?.system,gender:s.voice?.gender,fallbacks:s.voice?.fallbacks}));return vs(i,e,n)}function ze(t,e){let n={provider:t.provider,elevenlabs:Rs(e,t.elevenlabsVoiceId),system:t.systemVoice,fallback:t.fallback},i=Object.entries(t.systemByLanguage??{});return i.length&&(n.languages=Object.fromEntries(i.map(([r,s])=>[r,s?.id??null]))),t.rate&&t.rate!==1&&(n.rate=t.rate),t.priority&&t.priority!=="normal"&&(n.priority=t.priority),n}function Rs(t,e){return t||e||process.env.AGENTX_VOICE_ID||Ss}function _s(t,e){let n=(e??"").split(/(?<=\.)\s/)[0]??"",i=/^You are (.+?)\.?$/i.exec(n.trim());if(!i)return`Hello, this is ${t}.`;let r=i[1].replace(/\s*\([^)]*\)/g,"").trim(),[s,...o]=r.split(/,\s*/),a=o.join(", ");return a&&s.toLowerCase()===t.toLowerCase()?`Hello, this is ${t}, ${a}.`:!/^an? /i.test(r)&&r.toLowerCase().includes(t.toLowerCase())?`Hello, this is ${r}.`:`Hello, this is ${t}, ${r}.`}var Is=8*60*60*1e3,Es=500,er=class{constructor(e=Is){this.gapMs=e}lastSpoke=new Map;needsIntro(e,n,i=Date.now()){let r=this.lastSpoke.get(tr(e,n));return r===void 0||i-r>this.gapMs}spoke(e,n,i=Date.now()){let r=tr(e,n);this.lastSpoke.delete(r),this.lastSpoke.set(r,i),this.lastSpoke.size>Es&&this.lastSpoke.delete(this.lastSpoke.keys().next().value)}},tr=(t,e)=>`${t}\0${e}`;function ir(t,e){let n=t.style?` Your speaking manner: ${t.style}.`:"";return e?`[VOICE INTRO] This is your first spoken exchange with this person in a while. Open with one short sentence introducing yourself in your own manner, along the lines of "${t.intro}", then answer.${n}`:"[VOICE CASUAL] You have already introduced yourself in this voice conversation. Do not introduce yourself or greet again; talk casually, like a colleague in the same office."+n}function sc(t,e,n,i={}){let r=e[t],s=qe(t,e,i),o=(r?.systemPrompt??"").split(/\n\s*\n/)[0].slice(0,600).trim();return{agentId:t,name:s.name,voice:ze(s),persona:o||`You are ${s.name}.`,introLine:ir(s,n)}}var Ts="[VOICE MODE] This question arrived by voice and your reply will be spoken aloud by a TTS engine. Answer in two or three short sentences. Plain language, no markdown, no code blocks, no bullet points, no URLs. Speak conversationally.";function oc(t){let e=t;if(e?.channel!=="voice"||!e.voice||typeof e.voice!="object")return;let n=s=>typeof s=="string"?s.replace(/\s+/g," ").slice(0,200):"",i=n(e.voice.intro),r={agentId:"",name:"",provider:"system",elevenlabsVoiceId:null,systemVoice:null,systemVoiceName:null,systemByLanguage:{},fallback:!0,gender:null,style:n(e.voice.style)||null,intro:i||"Hello."};return`${Ts}
|
|
170
|
+
${ir(r,e.voice.introduce===!0&&!!i)}`}var Ws="System Settings \u203A Accessibility \u203A Spoken Content \u203A System voice \u203A Manage Voices",ar=(t=Ns())=>Ms(t,".agentx","voice","health.json");function js(t,e,n){let i=t.trim();if(!i||i.toLowerCase()===Ve)return!0;if(i.toLowerCase().startsWith(x)){let r=i.slice(x.length).trim().toLowerCase();return e.some(s=>s.siri&&s.name.toLowerCase()===r)}return G(i,e,n)!==null}function Us(t){let e=t.voice?.locale??"en",n=[],i=(r,s)=>{if(typeof s=="string")n.push({owner:r,name:s,locale:e,perLanguage:!1});else for(let[o,a]of Object.entries(s??{}))n.push({owner:r,name:a,locale:o,perLanguage:!0})};i("voice.system",t.voice?.system);for(let[r,s]of Object.entries(t.agents))(s.voice?.provider??t.voice?.provider??"system")!=="system"&&t.voice?.fallback==="none"||i(r,s.voice?.system);return n}function Fs(t,e){if(!e.length)return[];let n=new Map,i;for(let{owner:r,name:s,locale:o,perLanguage:a}of Us(t)){if(js(s,e,o))continue;i??=He(t.agents,t.voice,e);let l=n.get(s)??{voice:s,agents:[],speaksWith:{}};l.agents.includes(r)||l.agents.push(r);let c=i.get(r);r!=="voice.system"&&!a&&(l.speaksWith[r]=c?ge(c):"the OS default voice"),n.set(s,l)}return[...n.values()]}function Xe(t){let e=ce(t);if(e)return`Siri ${e.name[0].toUpperCase()}${e.name.slice(1)} (${e.locale})`;if(t.toLowerCase().startsWith(x)){let n=t.slice(x.length).trim();return`Siri ${n[0]?.toUpperCase()??""}${n.slice(1)}`}return t}function Vs(t){let e=t.map(n=>{let i=n.agents.map(r=>n.speaksWith[r]?`${r} (now ${n.speaksWith[r]})`:r).join(", ");return`\u2022 ${Xe(n.voice)}: ${i}`});return{title:t.length===1?"AgentX: a voice is not installed":`AgentX: ${t.length} voices are not installed`,message:`${e.join(`
|
|
171
171
|
`)}
|
|
172
|
-
Reinstall in ${
|
|
173
|
-
`),
|
|
174
|
-
`),
|
|
175
|
-
`)}};function
|
|
176
|
-
`):[]}writeMd(e){let n=
|
|
177
|
-
`))}async listOpen(e){if(this.store.exists())return this.store.list().filter(s=>s.status!=="done"&&(!s.assignee||s.assignee.toLowerCase()===e.toLowerCase())).map(s=>this.toWorkItem(s));let n=this.readMd(),i=[];for(let r=0;r<n.length;r++){let s=n[r].match(
|
|
178
|
-
`);for(let o=0;o<s.length;o++){let a=s[o].match(
|
|
179
|
-
`);n.status==="done"&&o[r]&&(o[r]=o[r].replace(/- \[ \]/,"- [x]"),
|
|
180
|
-
`)))}},Qe=class{constructor(e,n,i,r,s){this.host=e;this.token=n;this.projects=i;this.agentUsernames=r;this.log=s}type="gitlab";capabilities={listAll:!0,create:!0,transition:!0,labels:!0,search:!0};usernameToAgent(e){for(let[n,i]of Object.entries(this.agentUsernames))if(i.some(r=>r.toLowerCase()===e.toLowerCase()))return n}mapIssue(e,n){let i=e.references?.full?.split("#")[0]||n,r=[],s;Array.isArray(e.labels)&&(e.labels.length&&typeof e.labels[0]=="object"?(s=e.labels.map(c=>({name:c.name,color:c.color,text_color:c.text_color})),r=s.map(c=>c.name)):r=e.labels);let a=(Array.isArray(e.assignees)&&e.assignees.length?e.assignees:e.assignee?[e.assignee]:[]).map(c=>({username:c.username,name:c.name,avatarUrl:c.avatar_url})),l=a[0]?.username;return{id:`gitlab:${i}:issue:${e.iid}`,title:e.title,description:e.description||void 0,assignee:l?this.usernameToAgent(l)||l:void 0,assignees:a,url:e.web_url,priority:e.weight??99,estimatedSeconds:e.time_stats?.time_estimate||void 0,labels:r,labelDetails:s,updatedAt:e.updated_at,state:e.state==="closed"?"closed":"opened",milestone:e.milestone?.title||void 0}}async api(e,n={}){let i=await fetch(`${this.host}/api/v4${e}`,{...n,headers:{"PRIVATE-TOKEN":this.token,"Content-Type":"application/json",...n.headers||{}}});if(!i.ok)throw new Error(`GitLab ${i.status}: ${await i.text().catch(()=>"")}`);return i.json()}async listOpen(e){let n=this.agentUsernames[e]||[];if(!n.length)return[];let i=[],r=this.projects.length?this.projects:["__ALL__"];for(let s of n)for(let o of r)try{let a=`assignee_username=${encodeURIComponent(s)}&state=opened&scope=all&per_page=20`,l=o==="__ALL__"?`/issues?${a}`:`/projects/${encodeURIComponent(o)}/issues?${a}`,c=await this.api(l);for(let u of c){let d=this.mapIssue(u,o);d.assignee=e,i.push(d)}}catch(a){this.log(`[business] GitLab listOpen failed for ${s} on ${o}: ${a.message}`)}return i}async claim(e,n){let{project:i,iid:r,type:s}=this.parseId(n),o=`/projects/${encodeURIComponent(i)}/${s==="issue"?"issues":"merge_requests"}/${r}?add_labels=Doing&remove_labels=To Do`;try{await this.api(o,{method:"PUT"})}catch(a){this.log(`[business] claim label update failed: ${a.message}`)}}async report(e,n){let{project:i,iid:r,type:s}=this.parseId(e),o=s==="issue"?"issues":"merge_requests";if(n.timeSeconds&&n.timeSeconds>0){let a=Math.max(1,Math.round(n.timeSeconds/60)),l=a>=60?`${Math.floor(a/60)}h${a%60?` ${a%60}m`:""}`:`${a}m`;try{await this.api(`/projects/${encodeURIComponent(i)}/${o}/${r}/add_spent_time?duration=${encodeURIComponent(l)}`,{method:"POST"})}catch(c){this.log(`[business] add_spent_time failed: ${c.message}`)}}if(n.status==="done")try{await this.api(`/projects/${encodeURIComponent(i)}/${o}/${r}?add_labels=Done&remove_labels=Doing`,{method:"PUT"})}catch(a){this.log(`[business] done label update failed: ${a.message}`)}else if(n.status==="blocked")try{await this.api(`/projects/${encodeURIComponent(i)}/${o}/${r}?add_labels=Blocked`,{method:"PUT"})}catch(a){this.log(`[business] blocked label update failed: ${a.message}`)}if(n.note)try{await this.api(`/projects/${encodeURIComponent(i)}/${o}/${r}/notes`,{method:"POST",body:JSON.stringify({body:n.note})})}catch(a){this.log(`[business] report note failed: ${a.message}`)}}async listAll(e={}){let n=e.sinceDays??30,i=new Date(Date.now()-n*24*36e5).toISOString(),r=new URLSearchParams,s=e.state??"opened";r.set("state",s),r.set("updated_after",i),r.set("scope","all"),r.set("per_page","100"),r.set("with_labels_details","true"),r.set("order_by","updated_at"),r.set("sort","desc"),e.labels?.length&&r.set("labels",e.labels.join(",")),e.milestone&&r.set("milestone",e.milestone),e.search&&r.set("search",e.search);let o=this.projects.length?this.projects:["__ALL__"],a=[];for(let c of o)try{let u=c==="__ALL__"?`/issues?${r.toString()}`:`/projects/${encodeURIComponent(c)}/issues?${r.toString()}`,d=await this.api(u);for(let p of d)a.push(this.mapIssue(p,c))}catch(u){this.log(`[business] GitLab listAll failed on ${c}: ${u.message}`)}let l=a;if(e.notLabels?.length){let c=new Set(e.notLabels);l=l.filter(u=>!(u.labels||[]).some(d=>c.has(d)))}if(e.withoutScopedPrefix){let c=e.withoutScopedPrefix+"::";l=l.filter(u=>!(u.labels||[]).some(d=>d.startsWith(c)))}return l}async setState(e,n){let{project:i,iid:r,type:s}=this.parseId(e),o=s==="issue"?"issues":"merge_requests";await this.api(`/projects/${encodeURIComponent(i)}/${o}/${r}?state_event=${n}`,{method:"PUT"})}async getItem(e){let{project:n,iid:i}=this.parseId(e);try{let r=await this.api(`/projects/${encodeURIComponent(n)}/issues/${i}?with_labels_details=true`);return{...this.mapIssue(r,n),descriptionHtml:r.description_html||void 0,createdAt:r.created_at,author:r.author?{username:r.author.username,name:r.author.name,avatarUrl:r.author.avatar_url}:void 0,allLabels:Array.isArray(r.labels)?typeof r.labels[0]=="object"?r.labels.map(o=>o.name):r.labels:[]}}catch(r){return this.log(`[board] GitLab getItem failed for ${e}: ${r.message}`),null}}async updateItem(e,n){let{project:i,iid:r}=this.parseId(e),s;n.assigneeUsernames&&(s=(await Promise.all(n.assigneeUsernames.map(async u=>{try{let d=await this.api(`/users?username=${encodeURIComponent(u)}`);return Array.isArray(d)&&d[0]?.id?d[0].id:null}catch{return null}}))).filter(u=>typeof u=="number"));let o;if(n.milestoneTitle!==void 0)if(n.milestoneTitle===null||n.milestoneTitle==="")o=0;else try{let c=await this.api(`/projects/${encodeURIComponent(i)}/milestones?title=${encodeURIComponent(n.milestoneTitle)}`);Array.isArray(c)&&c[0]?.id&&(o=c[0].id)}catch(c){this.log(`[board] milestone lookup failed for "${n.milestoneTitle}": ${c.message}`)}let a={};n.title!==void 0&&(a.title=n.title),n.description!==void 0&&(a.description=n.description),n.labels!==void 0&&(a.labels=n.labels.join(",")),n.addLabels?.length&&(a.add_labels=n.addLabels.join(",")),n.removeLabels?.length&&(a.remove_labels=n.removeLabels.join(",")),s!==void 0&&(a.assignee_ids=s),o!==void 0&&(a.milestone_id=o);let l=await this.api(`/projects/${encodeURIComponent(i)}/issues/${r}`,{method:"PUT",body:JSON.stringify(a)});return this.mapIssue(l,i)}async listMembers(){let e=new Map;for(let n of this.projects)try{let i=await this.api(`/projects/${encodeURIComponent(n)}/members/all?per_page=100`);for(let r of i)r.username&&!e.has(r.username)&&e.set(r.username,{username:r.username,name:r.name,avatarUrl:r.avatar_url})}catch(i){this.log(`[board] listMembers failed for ${n}: ${i.message}`)}return[...e.values()].sort((n,i)=>n.username.localeCompare(i.username))}async listMilestones(){let e=new Map;for(let i of this.projects)try{let r=await this.api(`/projects/${encodeURIComponent(i)}/milestones?per_page=100`);for(let s of r)s.title&&!e.has(s.title)&&e.set(s.title,{id:s.id,title:s.title,state:s.state,dueDate:s.due_date})}catch(r){this.log(`[board] listMilestones failed for ${i}: ${r.message}`)}let n=[...e.values()];return n.sort((i,r)=>i.state!==r.state?i.state==="active"?-1:1:i.title.localeCompare(r.title)),n}async create(e){let n=e.projectHint||this.projects[0];if(!n)throw new Error("GitLabWorkSource.create requires projectHint or configured projects");let i,r=e.assigneeUsernames?.length?e.assigneeUsernames:e.assignee?(this.agentUsernames[e.assignee]||[]).slice(0,1):[];r.length&&(i=(await Promise.all(r.map(async c=>{try{let u=await this.api(`/users?username=${encodeURIComponent(c)}`);return Array.isArray(u)&&u[0]?.id?u[0].id:null}catch(u){return this.log(`[board] user lookup failed for ${c}: ${u.message}`),null}}))).filter(c=>typeof c=="number"));let s;if(e.milestoneTitle)try{let l=await this.api(`/projects/${encodeURIComponent(n)}/milestones?title=${encodeURIComponent(e.milestoneTitle)}`);Array.isArray(l)&&l[0]?.id&&(s=l[0].id)}catch(l){this.log(`[board] milestone lookup failed for "${e.milestoneTitle}": ${l.message}`)}let o={title:e.title,description:e.description,labels:(e.labels||[]).join(",")};i?.length&&(o.assignee_ids=i),s!==void 0&&(o.milestone_id=s);let a=await this.api(`/projects/${encodeURIComponent(n)}/issues`,{method:"POST",body:JSON.stringify(o)});return this.mapIssue(a,n)}async transition(e,n,i){await this.transitionMany(e,n?[n]:[],i?[i]:[])}async transitionMany(e,n,i){let{project:r,iid:s,type:o}=this.parseId(e),a=o==="issue"?"issues":"merge_requests",l=new URLSearchParams;n.length&&l.set("add_labels",n.join(",")),i.length&&l.set("remove_labels",i.join(",")),l.toString()&&await this.api(`/projects/${encodeURIComponent(r)}/${a}/${s}?${l.toString()}`,{method:"PUT"})}parseId(e){let i=e.replace(/^gitlab:/,"").split(":"),r=i.pop(),s=i.pop()==="mr"?"mr":"issue";return{project:i.join(":"),type:s,iid:r}}};function gc(t,e,n){let i=t.workSource;switch(i.type){case"backlog":return new Ye(i.path,e,n);case"wiki":return new Ze(i.path,i.glob);case"gitlab":{let r=e.channels.gitlab;if(!r?.token)throw new Error("business.workSource.type=gitlab requires channels.gitlab.token");let s={};for(let a of r.agentMappings)a.gitlabUsernames.length&&(s[a.agentId]=a.gitlabUsernames);let o=i.projects.length?i.projects:r.routes.map(a=>a.project);return new Qe(r.host,r.token,o,s,n)}}}var et="unmapped";function tt(t,e=[]){if(!t)return et;let n=e.find(r=>r.id===t);if(n?.client)return n.client;let i=t.indexOf("/");return i>0?t.slice(0,i):t}function Ks(t){let e=new Map,n=t.projects??[],i=t.orgChart??{};for(let s of n)s.pm&&(e.has(s.pm)||e.set(s.pm,tt(s.id,n)));let r=(s,o=new Set)=>{if(e.has(s))return e.get(s);if(o.has(s))return;o.add(s);let a=i[s]?.reportsTo;if(!a)return;let l=r(a,o);return l&&e.set(s,l),l};for(let s of Object.keys(i))r(s);return e}function Js(t,e,n=[]){if(!n.length)return;let i=n.filter(r=>!r.channel||r.channel===t);return i.find(r=>r.chatId&&e.chatId&&r.chatId===e.chatId)??i.find(r=>r.username&&e.username&&r.username===e.username)??i.find(r=>r.senderId&&e.senderId&&r.senderId===e.senderId)??i.find(r=>r.channel&&!r.chatId&&!r.username&&!r.senderId)}function mc(t,e){let n=Js(t.channel,{chatId:t.chatId,username:t.username},e.contactMap);if(n)return n.client;if(t.project)return tt(t.project,e.projects);if(t.agentId){let i=Ks(e).get(t.agentId);if(i)return i}return et}function hc(t,e){let n=String(t||"").split(":");if(n.length<3)return{agentId:e};let[i,r,...s]=n,o=s.join(":"),a={agentId:e||i,channel:r};return r==="gitlab"||r==="github"?a.project=o.split(":")[0]:r==="cron"||r==="api"||(a.chatId=o.split("@")[0]),a}var Ys=t=>t===et?"internal":"client";function Zs(t,e){let n=e.clients?.[t];return{id:t,name:n?.name||t,kind:n?.kind??Ys(t),respondWithinMinutes:Qs(n?.respondWithin),standing:n?.standing??[],declared:!!n}}function bc(t){let e=new Set;for(let n of t.projects??[])e.add(tt(n.id,t.projects));for(let n of t.contactMap??[])e.add(n.client);for(let n of Object.keys(t.clients??{}))e.add(n);return[...e].sort().map(n=>Zs(n,t))}function Qs(t){let e=/^(\d+)\s*([mhd])$/.exec(String(t??"").trim());if(!e)return;let n=Number(e[1]);return e[2]==="m"?n:e[2]==="h"?n*60:n*1440}var eo=/(^|\n)[ \t]*```[ \t]*agentx:ui[ \t]*\r?\n/i,to=/(^|\n)[ \t]*```[ \t]*agentx:ui[ \t]*\r?\n([\s\S]*?)\r?\n[ \t]*```[ \t]*(?=\n|$)/gi;function ar(t){if(!t||!t.includes("agentx:ui"))return{cleanText:t};let e=[...t.matchAll(to)];if(e.length===0)return{cleanText:t};let n=e[e.length-1],i=n[2],r=no(i);if(!r)return{cleanText:t};let s=n.index??0,o=n[1]??"";return{cleanText:(t.slice(0,s)+o+t.slice(s+n[0].length)).trim(),ui:r}}function wc(t){if(!t||!t.includes("agentx:ui"))return t;let e=eo.exec(t);return e?t.slice(0,e.index).trimEnd():t}function no(t){let e;try{e=JSON.parse(t)}catch{return null}if(!e||typeof e!="object")return null;let n={};if(Array.isArray(e.buttons)){let i=[],r=[],s=[];for(let o of e.buttons)!o||typeof o.label!="string"||(typeof o.url=="string"&&/^https?:\/\//i.test(o.url)?i.push({label:o.label,url:o.url}):typeof o.reply=="string"&&o.reply.trim()?r.push({label:o.label,reply:o.reply.trim()}):o.action!=null&&s.push(o.label));i.length&&(n.buttons=i),r.length&&(n.replies=r),s.length&&(n.skippedActions=s)}if(e.poll&&typeof e.poll=="object"){let i=e.poll.question,r=e.poll.options;typeof i=="string"&&i.trim()&&Array.isArray(r)&&r.filter(s=>typeof s=="string").length>=2&&(n.poll={question:i,options:r.filter(s=>typeof s=="string"),multiple:e.poll.multiple===!0})}if(e.media&&typeof e.media=="object"){let{type:i,url:r,caption:s}=e.media;["image","document","audio","video"].includes(i)&&typeof r=="string"&&r&&(n.media={type:i,url:r,...typeof s=="string"?{caption:s}:{}})}if(Array.isArray(e.quickReplies)){let i=e.quickReplies.filter(r=>typeof r=="string"&&r.trim()).map(r=>r.trim());i.length&&(n.quickReplies=i)}return!n.buttons&&!n.poll&&!n.media&&!n.quickReplies&&!n.replies&&!n.skippedActions?null:n}function xc(t,e){let n=`${e}/call?to=${encodeURIComponent(t.from)}&callId=${encodeURIComponent(t.callId)}`;return t.reason==="camera"?`\u{1F4F7} ${t.from} is sharing a phone camera \u2014 tap to watch: ${n}&watch=1`:`\u{1F4DE} ${t.from} is calling \u2014 tap to join: ${n}`}var ro=5*6e4;function D(t){return t.toLowerCase().replace(/[^a-z0-9]/g,"")}var lr=class{subs=new Set;log;forwarder;localName;allowedCallers;pending=new Map;cleanupTimer;ringHandler;recentRings=new Map;constructor(e,n=[],i=console.error.bind(console,"[webrtc]")){this.localName=e,this.allowedCallers=new Set(n.map(D)),this.log=i,this.cleanupTimer=setInterval(()=>this.cleanupExpired(),1e4)}pendingKey(e,n){return`${e}|${D(n)}`}cleanupExpired(){let e=Date.now();for(let[n,i]of this.pending){let r=i.filter(s=>s.expiresAt>e);r.length===0?this.pending.delete(n):r.length!==i.length&&this.pending.set(n,r)}for(let[n,i]of this.recentRings)i<=e&&this.recentRings.delete(n)}setForwarder(e){this.forwarder=e}setRingHandler(e){this.ringHandler=e}subscribe(e,n,i){return this.addSubscriber(e,n,{kind:"sse",res:i})}subscribeInternal(e,n,i){return this.addSubscriber(e,n,{kind:"callback",deliver:i})}addSubscriber(e,n,i){let r={callId:e,recipient:n,sink:i};this.subs.add(r);let s=i.kind==="sse"?"sse":"internal";this.log(`subscribe[${s}] call=${e} as=${n} (${this.subs.size} total)`);let o=this.pendingKey(e,n),a=this.pending.get(o);if(a&&a.length){let l=Date.now(),c=a.filter(u=>u.expiresAt>l);for(let{signal:u}of c)this.deliverTo(r,u);this.pending.delete(o),c.length&&this.log(`flushed ${c.length} buffered signal(s) to new subscriber call=${e} as=${n}`)}return()=>{this.subs.delete(r),this.log(`unsubscribe[${s}] call=${e} as=${n} (${this.subs.size} remaining)`)}}deliverTo(e,n){try{return e.sink.kind==="sse"?e.sink.res.write(`event: signal
|
|
172
|
+
Reinstall in ${Ws}. Agents switch back on their own once it is installed.`}}function qs(t=ar()){if(!or(t))return null;try{let e=JSON.parse(Ds(t,"utf8"));return e&&Array.isArray(e.missing)?e:null}catch{return null}}function Bs(t,e){Cs(Os(t),{recursive:!0}),Ls(`${t}.tmp`,JSON.stringify(e,null,2)+`
|
|
173
|
+
`),Ps(`${t}.tmp`,t)}var sr=class{constructor(e){this.deps=e}running=!1;missingNow=!1;hasMissing(){return this.missingNow}async check(e,n,i=new Date){if(this.running||!n.length)return null;this.running=!0;try{let r=this.deps.file??ar(),s=new Map((qs(r)?.missing??[]).map(d=>[d.voice,d])),o=Fs(e,n),a=o.map(d=>({...d,since:s.get(d.voice)?.since??i.toISOString(),...s.get(d.voice)?.notifiedAt?{notifiedAt:s.get(d.voice).notifiedAt}:{}})),l=[...s.keys()].filter(d=>!o.some(p=>p.voice===d));for(let d of l)this.deps.log(`[voice] ${Xe(d)} is installed again; its agents speak with it again`);l.length&&Kn(d=>l.some(p=>d===p||d.endsWith(`:${p}`)));let c=a.filter(d=>!d.notifiedAt);if(c.length){let{title:d,message:p}=Vs(c);try{await this.deps.notify(d,p);for(let g of c)g.notifiedAt=i.toISOString();this.deps.log(`[voice] told the owner: ${c.map(g=>Xe(g.voice)).join(", ")} not installed`)}catch(g){this.deps.log(`[voice] could not send the missing-voice notice: ${g?.message??g}`)}}this.missingNow=a.length>0;let u={checkedAt:i.toISOString(),missing:a};return(!or(r)||JSON.stringify(a)!==JSON.stringify([...s.values()]))&&Bs(r,u),u}finally{this.running=!1}}};import{readFileSync as Ke,writeFileSync as gr,existsSync as Je,readdirSync as Qs,statSync as eo}from"fs";import{resolve as Ye,join as to}from"path";import{existsSync as lr,mkdirSync as Hs,readFileSync as zs,writeFileSync as cr}from"fs";import{dirname as Xs,resolve as ur}from"path";import{z as m}from"zod";var Gs=m.object({type:m.enum(["gitlab","github"]),host:m.string().optional(),project:m.string(),iid:m.number().int().positive(),url:m.string()}),Ks=m.object({id:m.string(),title:m.string(),description:m.string().optional(),assignee:m.string().optional(),labels:m.array(m.string()).default([]),milestone:m.string().optional(),status:m.enum(["todo","doing","blocked","done"]).default("todo"),priority:m.number().int().optional(),estimatedSeconds:m.number().int().optional(),source:Gs.optional(),importedAt:m.string().optional(),createdAt:m.string(),updatedAt:m.string(),blocker:m.string().optional(),doneNote:m.string().optional()}),Js=m.object({version:m.literal(1),items:m.array(Ks).default([])}),fe=class{constructor(e){this.path=e}jsonPath(){return ur(process.cwd(),this.path).replace(/\.md$/i,".json")}mdPath(){return ur(process.cwd(),this.path).replace(/\.json$/i,".md")}exists(){return lr(this.jsonPath())}load(){let e=this.jsonPath();if(!lr(e))return{version:1,items:[]};let n=zs(e,"utf-8");try{return Js.parse(JSON.parse(n))}catch(i){throw new Error(`Backlog file invalid (${e}): ${i.message}`)}}save(e){let n=this.jsonPath();Hs(Xs(n),{recursive:!0}),cr(n,JSON.stringify(e,null,2)+`
|
|
174
|
+
`),cr(this.mdPath(),this.toMarkdown(e))}list(){return this.load().items}findById(e){return this.list().find(n=>n.id===e)}add(e){let n=this.load();if(n.items.some(s=>s.id===e.id))throw new Error(`backlog item ${e.id} already exists`);let i=new Date().toISOString(),r={...e,labels:e.labels??[],status:e.status??"todo",createdAt:e.createdAt??i,updatedAt:i};return n.items.push(r),this.save(n),r}addMany(e){let n=this.load(),i=new Set(n.items.map(o=>o.id)),r=new Date().toISOString(),s=[];for(let o of e){if(i.has(o.id))continue;let a={...o,labels:o.labels??[],status:o.status??"todo",createdAt:o.createdAt??r,updatedAt:r};n.items.push(a),s.push(a),i.add(a.id)}return s.length&&this.save(n),s}update(e,n){let i=this.load(),r=i.items.findIndex(o=>o.id===e);if(r<0)throw new Error(`backlog item ${e} not found`);let s={...i.items[r],...n,id:i.items[r].id,createdAt:i.items[r].createdAt,updatedAt:new Date().toISOString()};return i.items[r]=s,this.save(i),s}remove(e){let n=this.load(),i=n.items.length;return n.items=n.items.filter(r=>r.id!==e),n.items.length===i?!1:(this.save(n),!0)}toMarkdown(e){let n=["# Backlog","","_Generated from `backlog.json`. Do not edit by hand \u2014 use `agentx backlog` commands._",""],i={doing:[],blocked:[],todo:[],done:[]};for(let s of e.items)i[s.status].push(s);let r=[["doing","Doing"],["blocked","Blocked"],["todo","To Do"],["done","Done"]];for(let[s,o]of r)if(i[s].length){n.push(`## ${o}`,"");for(let a of i[s]){let l=s==="done"?"x":" ",c=a.assignee?`@${a.assignee} `:"",u=a.estimatedSeconds?` [time: ${Math.round(a.estimatedSeconds/60)}m]`:"",d=a.source?` (${a.source.type}: ${a.source.project}#${a.source.iid})`:"";n.push(`- [${l}] ${c}${a.title}${u}${d}`),a.source?.url&&n.push(` - <${a.source.url}>`),a.labels.length&&n.push(` - labels: ${a.labels.join(", ")}`),a.milestone&&n.push(` - milestone: ${a.milestone}`),a.blocker&&n.push(` - BLOCKED: ${a.blocker}`)}n.push("")}return n.join(`
|
|
175
|
+
`)}};function bc(t){return`${t.type}:${t.project}:${t.iid}`}function dr(t,e,n){let i=[];if(e.type==="gitlab"){let r=n.channels.gitlab?.agentMappings??[];for(let s of t){let o=r.find(a=>a.agentId===s);o?.gitlabUsernames?.length?i.push(o.gitlabUsernames[0]):i.push(s)}}else if(e.type==="github"){let r=n.channels.github?.agentMappings??[];for(let s of t){let o=r.find(a=>a.agentId===s);o?.githubUsernames?.length?i.push(o.githubUsernames[0]):i.push(s)}}return i}async function Ge(t,e,n,i=()=>{}){return t.source?t.source.type==="gitlab"?Ys(t.source,e,n,i):t.source.type==="github"?Zs(t.source,e,n,i):{ok:!1,error:`unknown source.type ${t.source.type}`,attempts:[]}:{ok:!0,attempts:[]}}async function Ys(t,e,n,i){let r=n.channels.gitlab,s=r?.token,o=r?.host||(t.host?`https://${t.host}`:void 0);if(!s||!o)return{ok:!1,error:"gitlab token/host not configured",attempts:[]};let a=[],l=async(g,f={})=>fetch(`${o}/api/v4${g}`,{...f,headers:{"PRIVATE-TOKEN":s,"Content-Type":"application/json",...f.headers||{}}}),c=encodeURIComponent(t.project),u;e.assigneeUsernames!==void 0&&(u=(await Promise.all(e.assigneeUsernames.map(async f=>{try{let h=await fetch(`${o}/api/v4/users?username=${encodeURIComponent(f)}`,{headers:{"PRIVATE-TOKEN":s}});if(!h.ok)return null;let y=await h.json();return Array.isArray(y)&&y[0]?.id?y[0].id:null}catch{return null}}))).filter(f=>typeof f=="number"));let d;if(e.milestoneTitle!==void 0)if(e.milestoneTitle===null||e.milestoneTitle==="")d=0;else try{let g=await l(`/projects/${c}/milestones?title=${encodeURIComponent(e.milestoneTitle)}`);if(g.ok){let f=await g.json();Array.isArray(f)&&f[0]?.id&&(d=f[0].id)}}catch(g){i(`[backlog-sync] milestone lookup failed: ${g.message}`)}let p={};if(e.title!==void 0&&(p.title=e.title),e.description!==void 0&&(p.description=e.description),e.labels!==void 0&&(p.labels=e.labels.join(",")),e.addLabels?.length&&(p.add_labels=e.addLabels.join(",")),e.removeLabels?.length&&(p.remove_labels=e.removeLabels.join(",")),u!==void 0&&(p.assignee_ids=u),d!==void 0&&(p.milestone_id=d),e.state&&(p.state_event=e.state==="closed"?"close":"reopen"),Object.keys(p).length)try{let g=await l(`/projects/${c}/issues/${t.iid}`,{method:"PUT",body:JSON.stringify(p)});if(a.push({kind:"PUT issue",ok:g.ok,status:g.status}),!g.ok){let f=await g.text().catch(()=>"");return{ok:!1,attempts:a,error:`PUT issue ${g.status}: ${f.slice(0,200)}`,url:t.url}}}catch(g){return a.push({kind:"PUT issue",ok:!1,error:g.message}),{ok:!1,attempts:a,error:g.message,url:t.url}}if(e.note)try{let g=await l(`/projects/${c}/issues/${t.iid}/notes`,{method:"POST",body:JSON.stringify({body:e.note})});a.push({kind:"POST note",ok:g.ok,status:g.status})}catch(g){a.push({kind:"POST note",ok:!1,error:g.message})}return{ok:a.every(g=>g.ok),attempts:a,url:t.url}}async function Zs(t,e,n,i){let s=n.channels.github?.token;if(!s)return{ok:!1,error:"github token not configured",attempts:[]};let o=[],a=async(p,g={})=>fetch(`https://api.github.com${p}`,{...g,headers:{Authorization:`Bearer ${s}`,Accept:"application/vnd.github+json","X-GitHub-Api-Version":"2022-11-28",...g.headers||{}}}),l=t.project,c;if(e.milestoneTitle!==void 0)if(e.milestoneTitle===null||e.milestoneTitle==="")c=null;else try{let p=await a(`/repos/${l}/milestones?state=all&per_page=100`);if(p.ok){let g=await p.json(),f=Array.isArray(g)?g.find(h=>h.title===e.milestoneTitle):null;f?.number&&(c=f.number)}}catch(p){i(`[backlog-sync] github milestone lookup failed: ${p.message}`)}let u;if(e.labels!==void 0)u=e.labels;else if(e.addLabels?.length||e.removeLabels?.length)try{let p=await a(`/repos/${l}/issues/${t.iid}`);if(p.ok){let g=await p.json(),f=Array.isArray(g.labels)?g.labels.map(y=>typeof y=="string"?y:y.name):[],h=new Set([...f,...e.addLabels??[]]);for(let y of e.removeLabels??[])h.delete(y);u=[...h]}}catch(p){i(`[backlog-sync] github label fetch failed: ${p.message}`)}let d={};if(e.title!==void 0&&(d.title=e.title),e.description!==void 0&&(d.body=e.description),u!==void 0&&(d.labels=u),e.assigneeUsernames!==void 0&&(d.assignees=e.assigneeUsernames),c!==void 0&&(d.milestone=c),e.state&&(d.state=e.state),Object.keys(d).length)try{let p=await a(`/repos/${l}/issues/${t.iid}`,{method:"PATCH",body:JSON.stringify(d)});if(o.push({kind:"PATCH issue",ok:p.ok,status:p.status}),!p.ok){let g=await p.text().catch(()=>"");return{ok:!1,attempts:o,error:`PATCH issue ${p.status}: ${g.slice(0,200)}`,url:t.url}}}catch(p){return o.push({kind:"PATCH issue",ok:!1,error:p.message}),{ok:!1,attempts:o,error:p.message,url:t.url}}if(e.note)try{let p=await a(`/repos/${l}/issues/${t.iid}/comments`,{method:"POST",body:JSON.stringify({body:e.note})});o.push({kind:"POST comment",ok:p.ok,status:p.status})}catch(p){o.push({kind:"POST comment",ok:!1,error:p.message})}return{ok:o.every(p=>p.ok),attempts:o,url:t.url}}var Ze=/^(\s*)-\s*\[( |x|X)\]\s*(.*)$/,me=/@([a-z0-9_-]+)/i,pr=/\[time:\s*([0-9hm\s]+)\]/i;function no(t){let e=t.match(/(\d+)\s*h/i),n=t.match(/(\d+)\s*m/i);return(e?parseInt(e[1],10)*3600:0)+(n?parseInt(n[1],10)*60:0)}var Qe=class{constructor(e,n,i=()=>{}){this.path=e;this.daemon=n;this.log=i;this.store=new fe(this.path)}type="backlog";capabilities={listAll:!0,create:!1,transition:!1,labels:!0,search:!1};store;getStore(){return this.store}readMd(){let e=Ye(process.cwd(),this.path);return Je(e)?Ke(e,"utf-8").split(`
|
|
176
|
+
`):[]}writeMd(e){let n=Ye(process.cwd(),this.path);gr(n,e.join(`
|
|
177
|
+
`))}async listOpen(e){if(this.store.exists())return this.store.list().filter(s=>s.status!=="done"&&(!s.assignee||s.assignee.toLowerCase()===e.toLowerCase())).map(s=>this.toWorkItem(s));let n=this.readMd(),i=[];for(let r=0;r<n.length;r++){let s=n[r].match(Ze);if(!s||s[2].toLowerCase()==="x")continue;let a=s[3],l=a.match(me);if(l&&l[1].toLowerCase()!==e.toLowerCase())continue;let c=a.match(pr),u=a.replace(me,"").replace(pr,"").trim();i.push({id:`backlog:${r}`,title:u||`Task at line ${r+1}`,assignee:l?l[1]:void 0,estimatedSeconds:c?no(c[1]):void 0,priority:r})}return i}async listAll(e={}){return this.store.exists()?this.store.list().map(n=>this.toWorkItem(n)):[]}async claim(e,n){if(!this.store.exists())return;let i=this.store.findById(n);if(!i)return;let r=this.store.update(n,{assignee:i.assignee||e,status:"doing"});if(r.source&&this.daemon){let s=dr([r.assignee||e],r.source,this.daemon);Ge(r,{assigneeUsernames:s,addLabels:["Doing"],removeLabels:["To Do"]},this.daemon,this.log).catch(o=>this.log(`[backlog-sync] claim failed for ${n}: ${o?.message??o}`))}}async report(e,n){if(this.store.exists()&&this.store.findById(e)){let a={};n.status==="done"?a.status="done":n.status==="blocked"?(a.status="blocked",a.blocker=n.blocker||n.note||void 0):n.status==="in-progress"&&(a.status="doing"),n.timeSeconds&&(a.estimatedSeconds=n.timeSeconds);let l=this.store.update(e,a);if(l.source&&this.daemon){let c={};n.status==="done"?(c.addLabels=["Done"],c.removeLabels=["Doing"]):n.status==="blocked"&&(c.addLabels=["Blocked"]),n.note&&(c.note=n.note),Object.keys(c).length&&Ge(l,c,this.daemon,this.log).catch(u=>this.log(`[backlog-sync] report failed for ${e}: ${u?.message??u}`))}return}if(!e.startsWith("backlog:"))throw new Error(`not a backlog id: ${e}`);let i=parseInt(e.slice(8),10),r=this.readMd(),s=r[i];if(!s)throw new Error(`backlog line ${i} missing`);if(!s.match(Ze))throw new Error(`backlog line ${i} not a checkbox`);if(n.status==="done"){r[i]=s.replace(/- \[ \]/,"- [x]");let a=n.timeSeconds?` <!-- done by agent, ${Math.round(n.timeSeconds/60)}m -->`:" <!-- done by agent -->";r.splice(i+1,0,a)}else n.status==="blocked"?r.splice(i+1,0,` <!-- BLOCKED: ${n.blocker||n.note||"?"} -->`):n.note&&r.splice(i+1,0,` <!-- ${n.note.replace(/-->/g,"\u2014 >")} -->`);this.writeMd(r)}toWorkItem(e){let n={todo:"todo",doing:"doing",blocked:"onhold",done:"done"}[e.status];return{id:e.id,title:e.title,description:e.description,assignee:e.assignee,estimatedSeconds:e.estimatedSeconds,priority:e.priority,labels:e.labels,stage:n,milestone:e.milestone,url:e.source?.url,updatedAt:e.updatedAt,state:e.status==="done"?"closed":"opened"}}},et=class{constructor(e,n){this.root=e;this.glob=n}type="wiki";capabilities={listAll:!1,create:!1,transition:!1,labels:!1,search:!1};walk(e,n){if(Je(e))for(let i of Qs(e)){let r=to(e,i);eo(r).isDirectory()?this.walk(r,n):i.endsWith(".md")&&n.push(r)}}async listOpen(e){let n=[];this.walk(Ye(process.cwd(),this.root),n);let i=[];for(let r of n){let s=Ke(r,"utf-8").split(`
|
|
178
|
+
`);for(let o=0;o<s.length;o++){let a=s[o].match(Ze);if(!a||a[2].toLowerCase()==="x")continue;let l=a[3].match(me);!l||l[1].toLowerCase()!==e.toLowerCase()||i.push({id:`wiki:${r}:${o}`,title:a[3].replace(me,"").trim(),assignee:l[1],priority:o})}}return i}async claim(){}async report(e,n){let i=e.split(":"),r=parseInt(i[i.length-1],10),s=i.slice(1,-1).join(":");if(!Je(s))return;let o=Ke(s,"utf-8").split(`
|
|
179
|
+
`);n.status==="done"&&o[r]&&(o[r]=o[r].replace(/- \[ \]/,"- [x]"),gr(s,o.join(`
|
|
180
|
+
`)))}},tt=class{constructor(e,n,i,r,s){this.host=e;this.token=n;this.projects=i;this.agentUsernames=r;this.log=s}type="gitlab";capabilities={listAll:!0,create:!0,transition:!0,labels:!0,search:!0};usernameToAgent(e){for(let[n,i]of Object.entries(this.agentUsernames))if(i.some(r=>r.toLowerCase()===e.toLowerCase()))return n}mapIssue(e,n){let i=e.references?.full?.split("#")[0]||n,r=[],s;Array.isArray(e.labels)&&(e.labels.length&&typeof e.labels[0]=="object"?(s=e.labels.map(c=>({name:c.name,color:c.color,text_color:c.text_color})),r=s.map(c=>c.name)):r=e.labels);let a=(Array.isArray(e.assignees)&&e.assignees.length?e.assignees:e.assignee?[e.assignee]:[]).map(c=>({username:c.username,name:c.name,avatarUrl:c.avatar_url})),l=a[0]?.username;return{id:`gitlab:${i}:issue:${e.iid}`,title:e.title,description:e.description||void 0,assignee:l?this.usernameToAgent(l)||l:void 0,assignees:a,url:e.web_url,priority:e.weight??99,estimatedSeconds:e.time_stats?.time_estimate||void 0,labels:r,labelDetails:s,updatedAt:e.updated_at,state:e.state==="closed"?"closed":"opened",milestone:e.milestone?.title||void 0}}async api(e,n={}){let i=await fetch(`${this.host}/api/v4${e}`,{...n,headers:{"PRIVATE-TOKEN":this.token,"Content-Type":"application/json",...n.headers||{}}});if(!i.ok)throw new Error(`GitLab ${i.status}: ${await i.text().catch(()=>"")}`);return i.json()}async listOpen(e){let n=this.agentUsernames[e]||[];if(!n.length)return[];let i=[],r=this.projects.length?this.projects:["__ALL__"];for(let s of n)for(let o of r)try{let a=`assignee_username=${encodeURIComponent(s)}&state=opened&scope=all&per_page=20`,l=o==="__ALL__"?`/issues?${a}`:`/projects/${encodeURIComponent(o)}/issues?${a}`,c=await this.api(l);for(let u of c){let d=this.mapIssue(u,o);d.assignee=e,i.push(d)}}catch(a){this.log(`[business] GitLab listOpen failed for ${s} on ${o}: ${a.message}`)}return i}async claim(e,n){let{project:i,iid:r,type:s}=this.parseId(n),o=`/projects/${encodeURIComponent(i)}/${s==="issue"?"issues":"merge_requests"}/${r}?add_labels=Doing&remove_labels=To Do`;try{await this.api(o,{method:"PUT"})}catch(a){this.log(`[business] claim label update failed: ${a.message}`)}}async report(e,n){let{project:i,iid:r,type:s}=this.parseId(e),o=s==="issue"?"issues":"merge_requests";if(n.timeSeconds&&n.timeSeconds>0){let a=Math.max(1,Math.round(n.timeSeconds/60)),l=a>=60?`${Math.floor(a/60)}h${a%60?` ${a%60}m`:""}`:`${a}m`;try{await this.api(`/projects/${encodeURIComponent(i)}/${o}/${r}/add_spent_time?duration=${encodeURIComponent(l)}`,{method:"POST"})}catch(c){this.log(`[business] add_spent_time failed: ${c.message}`)}}if(n.status==="done")try{await this.api(`/projects/${encodeURIComponent(i)}/${o}/${r}?add_labels=Done&remove_labels=Doing`,{method:"PUT"})}catch(a){this.log(`[business] done label update failed: ${a.message}`)}else if(n.status==="blocked")try{await this.api(`/projects/${encodeURIComponent(i)}/${o}/${r}?add_labels=Blocked`,{method:"PUT"})}catch(a){this.log(`[business] blocked label update failed: ${a.message}`)}if(n.note)try{await this.api(`/projects/${encodeURIComponent(i)}/${o}/${r}/notes`,{method:"POST",body:JSON.stringify({body:n.note})})}catch(a){this.log(`[business] report note failed: ${a.message}`)}}async listAll(e={}){let n=e.sinceDays??30,i=new Date(Date.now()-n*24*36e5).toISOString(),r=new URLSearchParams,s=e.state??"opened";r.set("state",s),r.set("updated_after",i),r.set("scope","all"),r.set("per_page","100"),r.set("with_labels_details","true"),r.set("order_by","updated_at"),r.set("sort","desc"),e.labels?.length&&r.set("labels",e.labels.join(",")),e.milestone&&r.set("milestone",e.milestone),e.search&&r.set("search",e.search);let o=this.projects.length?this.projects:["__ALL__"],a=[];for(let c of o)try{let u=c==="__ALL__"?`/issues?${r.toString()}`:`/projects/${encodeURIComponent(c)}/issues?${r.toString()}`,d=await this.api(u);for(let p of d)a.push(this.mapIssue(p,c))}catch(u){this.log(`[business] GitLab listAll failed on ${c}: ${u.message}`)}let l=a;if(e.notLabels?.length){let c=new Set(e.notLabels);l=l.filter(u=>!(u.labels||[]).some(d=>c.has(d)))}if(e.withoutScopedPrefix){let c=e.withoutScopedPrefix+"::";l=l.filter(u=>!(u.labels||[]).some(d=>d.startsWith(c)))}return l}async setState(e,n){let{project:i,iid:r,type:s}=this.parseId(e),o=s==="issue"?"issues":"merge_requests";await this.api(`/projects/${encodeURIComponent(i)}/${o}/${r}?state_event=${n}`,{method:"PUT"})}async getItem(e){let{project:n,iid:i}=this.parseId(e);try{let r=await this.api(`/projects/${encodeURIComponent(n)}/issues/${i}?with_labels_details=true`);return{...this.mapIssue(r,n),descriptionHtml:r.description_html||void 0,createdAt:r.created_at,author:r.author?{username:r.author.username,name:r.author.name,avatarUrl:r.author.avatar_url}:void 0,allLabels:Array.isArray(r.labels)?typeof r.labels[0]=="object"?r.labels.map(o=>o.name):r.labels:[]}}catch(r){return this.log(`[board] GitLab getItem failed for ${e}: ${r.message}`),null}}async updateItem(e,n){let{project:i,iid:r}=this.parseId(e),s;n.assigneeUsernames&&(s=(await Promise.all(n.assigneeUsernames.map(async u=>{try{let d=await this.api(`/users?username=${encodeURIComponent(u)}`);return Array.isArray(d)&&d[0]?.id?d[0].id:null}catch{return null}}))).filter(u=>typeof u=="number"));let o;if(n.milestoneTitle!==void 0)if(n.milestoneTitle===null||n.milestoneTitle==="")o=0;else try{let c=await this.api(`/projects/${encodeURIComponent(i)}/milestones?title=${encodeURIComponent(n.milestoneTitle)}`);Array.isArray(c)&&c[0]?.id&&(o=c[0].id)}catch(c){this.log(`[board] milestone lookup failed for "${n.milestoneTitle}": ${c.message}`)}let a={};n.title!==void 0&&(a.title=n.title),n.description!==void 0&&(a.description=n.description),n.labels!==void 0&&(a.labels=n.labels.join(",")),n.addLabels?.length&&(a.add_labels=n.addLabels.join(",")),n.removeLabels?.length&&(a.remove_labels=n.removeLabels.join(",")),s!==void 0&&(a.assignee_ids=s),o!==void 0&&(a.milestone_id=o);let l=await this.api(`/projects/${encodeURIComponent(i)}/issues/${r}`,{method:"PUT",body:JSON.stringify(a)});return this.mapIssue(l,i)}async listMembers(){let e=new Map;for(let n of this.projects)try{let i=await this.api(`/projects/${encodeURIComponent(n)}/members/all?per_page=100`);for(let r of i)r.username&&!e.has(r.username)&&e.set(r.username,{username:r.username,name:r.name,avatarUrl:r.avatar_url})}catch(i){this.log(`[board] listMembers failed for ${n}: ${i.message}`)}return[...e.values()].sort((n,i)=>n.username.localeCompare(i.username))}async listMilestones(){let e=new Map;for(let i of this.projects)try{let r=await this.api(`/projects/${encodeURIComponent(i)}/milestones?per_page=100`);for(let s of r)s.title&&!e.has(s.title)&&e.set(s.title,{id:s.id,title:s.title,state:s.state,dueDate:s.due_date})}catch(r){this.log(`[board] listMilestones failed for ${i}: ${r.message}`)}let n=[...e.values()];return n.sort((i,r)=>i.state!==r.state?i.state==="active"?-1:1:i.title.localeCompare(r.title)),n}async create(e){let n=e.projectHint||this.projects[0];if(!n)throw new Error("GitLabWorkSource.create requires projectHint or configured projects");let i,r=e.assigneeUsernames?.length?e.assigneeUsernames:e.assignee?(this.agentUsernames[e.assignee]||[]).slice(0,1):[];r.length&&(i=(await Promise.all(r.map(async c=>{try{let u=await this.api(`/users?username=${encodeURIComponent(c)}`);return Array.isArray(u)&&u[0]?.id?u[0].id:null}catch(u){return this.log(`[board] user lookup failed for ${c}: ${u.message}`),null}}))).filter(c=>typeof c=="number"));let s;if(e.milestoneTitle)try{let l=await this.api(`/projects/${encodeURIComponent(n)}/milestones?title=${encodeURIComponent(e.milestoneTitle)}`);Array.isArray(l)&&l[0]?.id&&(s=l[0].id)}catch(l){this.log(`[board] milestone lookup failed for "${e.milestoneTitle}": ${l.message}`)}let o={title:e.title,description:e.description,labels:(e.labels||[]).join(",")};i?.length&&(o.assignee_ids=i),s!==void 0&&(o.milestone_id=s);let a=await this.api(`/projects/${encodeURIComponent(n)}/issues`,{method:"POST",body:JSON.stringify(o)});return this.mapIssue(a,n)}async transition(e,n,i){await this.transitionMany(e,n?[n]:[],i?[i]:[])}async transitionMany(e,n,i){let{project:r,iid:s,type:o}=this.parseId(e),a=o==="issue"?"issues":"merge_requests",l=new URLSearchParams;n.length&&l.set("add_labels",n.join(",")),i.length&&l.set("remove_labels",i.join(",")),l.toString()&&await this.api(`/projects/${encodeURIComponent(r)}/${a}/${s}?${l.toString()}`,{method:"PUT"})}parseId(e){let i=e.replace(/^gitlab:/,"").split(":"),r=i.pop(),s=i.pop()==="mr"?"mr":"issue";return{project:i.join(":"),type:s,iid:r}}};function Ac(t,e,n){let i=t.workSource;switch(i.type){case"backlog":return new Qe(i.path,e,n);case"wiki":return new et(i.path,i.glob);case"gitlab":{let r=e.channels.gitlab;if(!r?.token)throw new Error("business.workSource.type=gitlab requires channels.gitlab.token");let s={};for(let a of r.agentMappings)a.gitlabUsernames.length&&(s[a.agentId]=a.gitlabUsernames);let o=i.projects.length?i.projects:r.routes.map(a=>a.project);return new tt(r.host,r.token,o,s,n)}}}var nt="unmapped";function rt(t,e=[]){if(!t)return nt;let n=e.find(r=>r.id===t);if(n?.client)return n.client;let i=t.indexOf("/");return i>0?t.slice(0,i):t}function ro(t){let e=new Map,n=t.projects??[],i=t.orgChart??{};for(let s of n)s.pm&&(e.has(s.pm)||e.set(s.pm,rt(s.id,n)));let r=(s,o=new Set)=>{if(e.has(s))return e.get(s);if(o.has(s))return;o.add(s);let a=i[s]?.reportsTo;if(!a)return;let l=r(a,o);return l&&e.set(s,l),l};for(let s of Object.keys(i))r(s);return e}function io(t,e,n=[]){if(!n.length)return;let i=n.filter(r=>!r.channel||r.channel===t);return i.find(r=>r.chatId&&e.chatId&&r.chatId===e.chatId)??i.find(r=>r.username&&e.username&&r.username===e.username)??i.find(r=>r.senderId&&e.senderId&&r.senderId===e.senderId)??i.find(r=>r.channel&&!r.chatId&&!r.username&&!r.senderId)}function _c(t,e){let n=io(t.channel,{chatId:t.chatId,username:t.username},e.contactMap);if(n)return n.client;if(t.project)return rt(t.project,e.projects);if(t.agentId){let i=ro(e).get(t.agentId);if(i)return i}return nt}function Ic(t,e){let n=String(t||"").split(":");if(n.length<3)return{agentId:e};let[i,r,...s]=n,o=s.join(":"),a={agentId:e||i,channel:r};return r==="gitlab"||r==="github"?a.project=o.split(":")[0]:r==="cron"||r==="api"||(a.chatId=o.split("@")[0]),a}var so=t=>t===nt?"internal":"client";function oo(t,e){let n=e.clients?.[t];return{id:t,name:n?.name||t,kind:n?.kind??so(t),respondWithinMinutes:ao(n?.respondWithin),standing:n?.standing??[],declared:!!n}}function Ec(t){let e=new Set;for(let n of t.projects??[])e.add(rt(n.id,t.projects));for(let n of t.contactMap??[])e.add(n.client);for(let n of Object.keys(t.clients??{}))e.add(n);return[...e].sort().map(n=>oo(n,t))}function ao(t){let e=/^(\d+)\s*([mhd])$/.exec(String(t??"").trim());if(!e)return;let n=Number(e[1]);return e[2]==="m"?n:e[2]==="h"?n*60:n*1440}var lo=/(^|\n)[ \t]*```[ \t]*agentx:ui[ \t]*\r?\n/i,co=/(^|\n)[ \t]*```[ \t]*agentx:ui[ \t]*\r?\n([\s\S]*?)\r?\n[ \t]*```[ \t]*(?=\n|$)/gi;function fr(t){if(!t||!t.includes("agentx:ui"))return{cleanText:t};let e=[...t.matchAll(co)];if(e.length===0)return{cleanText:t};let n=e[e.length-1],i=n[2],r=uo(i);if(!r)return{cleanText:t};let s=n.index??0,o=n[1]??"";return{cleanText:(t.slice(0,s)+o+t.slice(s+n[0].length)).trim(),ui:r}}function Cc(t){if(!t||!t.includes("agentx:ui"))return t;let e=lo.exec(t);return e?t.slice(0,e.index).trimEnd():t}function uo(t){let e;try{e=JSON.parse(t)}catch{return null}if(!e||typeof e!="object")return null;let n={};if(Array.isArray(e.buttons)){let i=[],r=[],s=[];for(let o of e.buttons)!o||typeof o.label!="string"||(typeof o.url=="string"&&/^https?:\/\//i.test(o.url)?i.push({label:o.label,url:o.url}):typeof o.reply=="string"&&o.reply.trim()?r.push({label:o.label,reply:o.reply.trim()}):o.action!=null&&s.push(o.label));i.length&&(n.buttons=i),r.length&&(n.replies=r),s.length&&(n.skippedActions=s)}if(e.poll&&typeof e.poll=="object"){let i=e.poll.question,r=e.poll.options;typeof i=="string"&&i.trim()&&Array.isArray(r)&&r.filter(s=>typeof s=="string").length>=2&&(n.poll={question:i,options:r.filter(s=>typeof s=="string"),multiple:e.poll.multiple===!0})}if(e.media&&typeof e.media=="object"){let{type:i,url:r,caption:s}=e.media;["image","document","audio","video"].includes(i)&&typeof r=="string"&&r&&(n.media={type:i,url:r,...typeof s=="string"?{caption:s}:{}})}if(Array.isArray(e.quickReplies)){let i=e.quickReplies.filter(r=>typeof r=="string"&&r.trim()).map(r=>r.trim());i.length&&(n.quickReplies=i)}return!n.buttons&&!n.poll&&!n.media&&!n.quickReplies&&!n.replies&&!n.skippedActions?null:n}function Pc(t,e){let n=`${e}/call?to=${encodeURIComponent(t.from)}&callId=${encodeURIComponent(t.callId)}`;return t.reason==="camera"?`\u{1F4F7} ${t.from} is sharing a phone camera \u2014 tap to watch: ${n}&watch=1`:`\u{1F4DE} ${t.from} is calling \u2014 tap to join: ${n}`}var po=5*6e4;function D(t){return t.toLowerCase().replace(/[^a-z0-9]/g,"")}var mr=class{subs=new Set;log;forwarder;localName;allowedCallers;pending=new Map;cleanupTimer;ringHandler;recentRings=new Map;constructor(e,n=[],i=console.error.bind(console,"[webrtc]")){this.localName=e,this.allowedCallers=new Set(n.map(D)),this.log=i,this.cleanupTimer=setInterval(()=>this.cleanupExpired(),1e4)}pendingKey(e,n){return`${e}|${D(n)}`}cleanupExpired(){let e=Date.now();for(let[n,i]of this.pending){let r=i.filter(s=>s.expiresAt>e);r.length===0?this.pending.delete(n):r.length!==i.length&&this.pending.set(n,r)}for(let[n,i]of this.recentRings)i<=e&&this.recentRings.delete(n)}setForwarder(e){this.forwarder=e}setRingHandler(e){this.ringHandler=e}subscribe(e,n,i){return this.addSubscriber(e,n,{kind:"sse",res:i})}subscribeInternal(e,n,i){return this.addSubscriber(e,n,{kind:"callback",deliver:i})}addSubscriber(e,n,i){let r={callId:e,recipient:n,sink:i};this.subs.add(r);let s=i.kind==="sse"?"sse":"internal";this.log(`subscribe[${s}] call=${e} as=${n} (${this.subs.size} total)`);let o=this.pendingKey(e,n),a=this.pending.get(o);if(a&&a.length){let l=Date.now(),c=a.filter(u=>u.expiresAt>l);for(let{signal:u}of c)this.deliverTo(r,u);this.pending.delete(o),c.length&&this.log(`flushed ${c.length} buffered signal(s) to new subscriber call=${e} as=${n}`)}return()=>{this.subs.delete(r),this.log(`unsubscribe[${s}] call=${e} as=${n} (${this.subs.size} remaining)`)}}deliverTo(e,n){try{return e.sink.kind==="sse"?e.sink.res.write(`event: signal
|
|
181
181
|
data: ${JSON.stringify(n)}
|
|
182
182
|
|
|
183
|
-
`):e.sink.deliver(n),!0}catch{return!1}}async handleOutgoing(e){let n=D(e.to);if(n===D(this.localName)||this.hasSubscriberFor(e.callId,n))return this.fanOut(e),{ok:!0};if(!this.forwarder)return{ok:!1,error:"mesh forwarder not wired"};let r=await this.forwarder(e.to,e);return r?{ok:r}:{ok:!1,error:`forward to "${e.to}" failed`}}hasSubscriberFor(e,n){for(let i of this.subs)if(i.callId===e&&D(i.recipient)===n)return!0;return!1}handleIncoming(e){if((e.kind==="offer"||e.kind==="ring")&&this.allowedCallers.size>0&&!this.allowedCallers.has(D(e.from)))return this.log(`reject inbound ${e.kind} from "${e.from}": not in allowedCallers`),{ok:!1,error:"caller not allowed"};if(e.kind==="ring"){let i=Date.now(),r=this.recentRings.get(e.callId);if(r&&r>i)return this.log(`dedup ring for call=${e.callId} (already notified)`),{ok:!0};if(this.recentRings.set(e.callId,i+
|
|
183
|
+
`):e.sink.deliver(n),!0}catch{return!1}}async handleOutgoing(e){let n=D(e.to);if(n===D(this.localName)||this.hasSubscriberFor(e.callId,n))return this.fanOut(e),{ok:!0};if(!this.forwarder)return{ok:!1,error:"mesh forwarder not wired"};let r=await this.forwarder(e.to,e);return r?{ok:r}:{ok:!1,error:`forward to "${e.to}" failed`}}hasSubscriberFor(e,n){for(let i of this.subs)if(i.callId===e&&D(i.recipient)===n)return!0;return!1}handleIncoming(e){if((e.kind==="offer"||e.kind==="ring")&&this.allowedCallers.size>0&&!this.allowedCallers.has(D(e.from)))return this.log(`reject inbound ${e.kind} from "${e.from}": not in allowedCallers`),{ok:!1,error:"caller not allowed"};if(e.kind==="ring"){let i=Date.now(),r=this.recentRings.get(e.callId);if(r&&r>i)return this.log(`dedup ring for call=${e.callId} (already notified)`),{ok:!0};if(this.recentRings.set(e.callId,i+po),this.ringHandler)try{this.ringHandler(e)}catch(s){this.log(`ringHandler threw: ${s.message}`)}else this.log(`ring received for call=${e.callId} but no handler wired`);return{ok:!0}}if(this.fanOut(e)===0){let i=this.pendingKey(e.callId,e.to),r=this.pending.get(i)||[];r.push({signal:e,expiresAt:Date.now()+3e4}),this.pending.set(i,r),this.log(`buffered ${e.kind} for call=${e.callId} to=${e.to} (no subscriber yet, ${r.length} pending)`)}return{ok:!0}}fanOut(e){let n=0,i=D(e.to);for(let r of this.subs)r.callId===e.callId&&D(r.recipient)===i&&(this.deliverTo(r,e)?n++:this.subs.delete(r));return n}get subscriberCount(){return this.subs.size}shutdown(){this.cleanupTimer&&clearInterval(this.cleanupTimer);for(let e of this.subs)if(e.sink.kind==="sse")try{e.sink.res.end()}catch{}this.subs.clear(),this.pending.clear()}};xe();Tt();var Mc=["owner","agent","person"],go=36e5,fo=t=>Ct.includes(t.state);function hr(t){return e=>!t||t.get(e)?.state!=="active"?null:t.steps(e).find(n=>n.state==="active")?.agentId??null}function it(t,e){return t.state==="waiting_owner"?{group:"owner",who:te}:t.promise&&t.owedTo&&t.owedTo!==te&&!e.isAgent(t.owedTo)?{group:"person",who:t.owedTo}:t.state==="needs_attention"?{group:"owner",who:te}:{group:"agent",who:e.activeStepAgent?.(t.id)??t.agentId}}function st(t,e,n){return fo(t)?t.state==="needs_attention"?t.attentionReason??"needs attention":t.dueAt!==null?n>t.dueAt?`past its due time (${mo(t.dueAt)})`:null:n-t.updatedAt>e*go?`no activity for ${e} h or more`:null:null}function Wc(t,e,n,i){let r={owner:[],agent:[],person:[]};for(let s of t){let o=st(s,e,n);if(!o)continue;let{group:a,who:l}=it(s,i);r[a].push({request:s,group:a,who:l,why:o})}return r}function jc(t,e){return t==="owner"?"you":t==="agent"?`agent ${e}`:`${e} (outside person)`}var mo=t=>new Date(t).toISOString().slice(0,16).replace("T"," ")+" UTC";function Uc(t){if(t==null||t==="")return;let e=typeof t=="number"?t:typeof t=="string"?Date.parse(t.trim()):NaN;return!Number.isFinite(e)||e<=0?"due must be an ISO date (2030-01-31T17:00:00Z) or epoch milliseconds":e}function Fc(t){return e=>It(e,t())}var ho=10;async function Vc(t,e,n){let i=t.dueForCheck(n.now-n.everyMinutes*6e4,ho),r=0;return await Promise.all(i.map(async s=>{t.markChecked(s.id,s.verifyState,s.verifyDetail??"",n.now);let o=await e(s.closeWhen,s).catch(a=>({verdict:"unverifiable",detail:String(a?.message??a)}));if(o.verdict==="met"){t.closeVerified(s.id,o.detail,n.now)&&(r++,n.log(`[requests] ${s.id} closed by its check: ${o.detail}`));return}t.markChecked(s.id,o.verdict==="unverifiable"?"unverified":s.verifyState==="failed"?"failed":null,o.detail,n.now)})),{checked:i.length,closed:r}}var yo={perClient:5,global:10,windowMs:10*60*1e3,lockoutMs:5*60*1e3},yr=class{constructor(e=yo,n=Date.now){this.opts=e;this.now=n}clients=new Map;all={failures:[],lockedUntil:0};retryAfter(e){let n=this.now(),i=Math.max(this.all.lockedUntil,this.clients.get(e)?.lockedUntil??0);return i>n?Math.ceil((i-n)/1e3):0}fail(e){let n=this.clients.get(e);n||this.clients.set(e,n={failures:[],lockedUntil:0}),this.bump(n,this.opts.perClient),this.bump(this.all,this.opts.global)}succeed(e){this.clients.delete(e)}bump(e,n){let i=this.now();e.failures=e.failures.filter(r=>i-r<this.opts.windowMs),e.failures.push(i),e.failures.length>=n&&(e.lockedUntil=i+this.opts.lockoutMs)}},bo="That code didn't work. Check it, or run agentx app pair for a new one.",wo=400;async function Hc(t,e){let n=Date.now(),i=e.log??(c=>console.log(c)),r=t.socket.remoteAddress||"unknown",s=e.limiter.retryAfter(r);if(s>0)return i(`[app] pair-code refused from ${r}: locked out for ${s}s more`),{status:429,body:{error:"too many attempts",retryAfter:s},retryAfter:s};let o=null;try{o=(await rn(t,1024)).code}catch{}let a=e.codes.redeem(o),l=a?e.verify(a.token):null;return await ko(n,e.minMs??wo),!a||!l?(e.limiter.fail(r),i(`[app] pair-code failed from ${r}`),{status:401,body:{error:bo}}):(e.limiter.succeed(r),i(`[app] pair-code paired ${a.tokenId} (${l}) from ${r}`),{status:200,body:{device:l},token:a.token})}async function ko(t,e){let n=t+e-Date.now();n>0&&await new Promise(i=>setTimeout(i,n))}Tt();var So=200,br=4e3;function xo(t){return t.replace(/```[\s\S]*?```/g," ").replace(/!?\[([^\]]*)\]\([^)]*\)/g,"$1").replace(/^\s{0,3}(#{1,6}|>|[-*+]|\d+[.)])\s+/gm,"").replace(/[*_~`]+/g,"").replace(/\s+/g," ").trim()}function ot(t,e=So){let n=xo(t);if(n.length<=e)return n;let i=n.slice(0,e),r=Math.max(i.lastIndexOf(". "),i.lastIndexOf("? "),i.lastIndexOf("! "));return r>e/2?i.slice(0,r+1):`${i.slice(0,e-1).trimEnd()}\u2026`}function Jc(t,e,n,i){let r=n?.get(t.id),s=i?st(t,i.staleAfterHours,i.now):null,o=e.lastAnswer(t.id),a=o&&o.text.length>br?`${o.text.slice(0,br)}
|
|
184
184
|
|
|
185
|
-
\u2026`:
|
|
185
|
+
\u2026`:o?.text;return{...t,summary:ot(t.text),textHtml:re(t.text),why:t.state==="waiting_owner"?t.question:t.state==="needs_attention"?t.attentionReason:null,ownerNoteHtml:t.ownerNote?re(t.ownerNote):null,lastAnswer:o?{agentId:o.agentId,at:o.at,html:re(a)}:null,loop:t.promise||t.dueAt!==null||t.closeWhen?{owedTo:t.owedTo,promise:t.promise,dueAt:t.dueAt,check:t.closeWhen?Et(t.closeWhen):null,verifyState:t.verifyState,verifyDetail:t.verifyDetail}:null,stall:i&&s?{...it(t,{isAgent:i.isAgent,activeStepAgent:hr(n)}),why:s}:null,plan:r?{state:r.state,steps:n.steps(t.id).map(l=>({idx:l.idx,name:l.name,kind:l.kind,agentId:l.agentId,state:l.state,approval:l.needsApproval?l.approval:null,evidence:l.evidence,note:l.note,nudges:l.nudges}))}:null}}import{execFile as Uo}from"child_process";import{mkdtempSync as Po,rmSync as Lo,writeFileSync as No}from"fs";import{tmpdir as Oo}from"os";import{join as vr}from"path";import{randomBytes as vo}from"crypto";var E={top:8,side:32,bottom:60},at={height:56,keep:52},wr=`
|
|
186
186
|
:root {
|
|
187
187
|
--ac-paper: #fafaf9; --ac-soft: #f4f4f2; --ac-edge: #e9e9e6;
|
|
188
188
|
--ac-text: #0b1413; --ac-muted: #4a5856; --ac-subtle: #7c8987;
|
|
@@ -311,16 +311,16 @@ button.primary:hover:not(:disabled) { transform: translateY(-1px); background: v
|
|
|
311
311
|
button.primary:disabled { opacity: .55; cursor: not-allowed; }
|
|
312
312
|
kbd { font: 11px var(--ac-mono); color: var(--ac-subtle); }
|
|
313
313
|
button.primary kbd { color: inherit; opacity: .7; }
|
|
314
|
-
`;var
|
|
314
|
+
`;var kr=t=>t.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"}),Sr=t=>`${t.getDate()} ${t.toLocaleDateString("en-US",{month:"short"})}`;function $o(t,e){let n=new Date(t);return Number.isNaN(n.getTime())?"":`since ${n.toDateString()===new Date(e).toDateString()?kr(n):Sr(n)}`}function Ao(t,e){let n=new Date(t),i=n.getTime()-e<6*864e5;return[n.toLocaleDateString("en-US",{weekday:"short"}),...i?[]:[Sr(n)],kr(n)].join(" ")}function Ro(t){let e=t.trim().split(/[\s_-]+/).filter(Boolean);return(e.length>1?e[0][0]+e[1][0]:t.trim().slice(0,1)).toUpperCase()}function _o(t){let e=(t.recommend??"").trim(),n=e.toLowerCase(),i=t.choices??[],r=-1;if(i.forEach((o,a)=>{!n.startsWith(o.toLowerCase())||!/^\s*($|[:,.;–—-](\s|$))/.test(e.slice(o.length))||(r<0||o.length>i[r].length)&&(r=a)}),r<0)return{index:r,why:e};let s=e.slice(i[r].length).replace(/^[\s:,.;–—-]+/,"");return{index:r,why:s.slice(0,1).toUpperCase()+s.slice(1)}}function Io(t){return t.origin?.kind==="request"?"Hand it back":t.draft?"Send":t.choices?.length?"Choose":"Yes"}var lt=t=>`<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${t}</svg>`,Eo=lt('<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>'),To=lt('<path d="m6 15 6-6 6 6"/>'),Co=lt('<rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/>');function xr(t,e={}){let n=e.now??Date.now(),i=e.from||t.raised_by,r=vo(12).toString("base64"),s=t.choices??[],o=t.origin?.kind==="reminder",a=t.origin?.kind==="request",l=_o(t),c=s.map((p,g)=>`<button class="opt" role="radio" aria-checked="false" data-i="${g}"><span class="n">${g+1}</span><span class="t">${w(p)}</span>${g===l.index?'<i class="dot"></i>':""}</button>`).join(""),u=t.recommend?`<span class="rec"><i class="dot"></i>${w(i)} recommends</span>`:"",d={choices:s,draft:t.draft??"",placeholder:Jt,chime:e.sound==="chime",volume:Math.min(1,Math.max(0,e.volume??.4)),theme:e.theme??"system",pick:e.pick&&e.pick<=s.length?e.pick-1:l.index};return`<!doctype html>
|
|
315
315
|
<html lang="en"><head><meta charset="utf-8">
|
|
316
316
|
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; script-src 'nonce-${r}'">
|
|
317
317
|
<title>AgentX</title>
|
|
318
|
-
<style>${
|
|
318
|
+
<style>${wr}</style></head>
|
|
319
319
|
<body><div class="wrap"><main class="card${e.still?" still":""}">
|
|
320
|
-
<div class="head" title="Drag to move"><span class="avatar">${w(
|
|
321
|
-
<div class="who"><b>${w(i)}</b><span>${w(
|
|
320
|
+
<div class="head" title="Drag to move"><span class="avatar">${w(Ro(i))}</span>
|
|
321
|
+
<div class="who"><b>${w(i)}</b><span>${w($o(t.created_at,n))}</span></div>
|
|
322
322
|
<span class="kind${o?"":" decision"}">${o?"Reminder":a?"Request":"Decision"}</span>
|
|
323
|
-
<button class="fold" id="fold" title="Shrink" aria-label="Shrink the card" aria-expanded="true">${
|
|
323
|
+
<button class="fold" id="fold" title="Shrink" aria-label="Shrink the card" aria-expanded="true">${To}</button></div>
|
|
324
324
|
<div class="body"><h1 dir="auto">${w(t.title)}</h1>
|
|
325
325
|
${t.context?`<p class="context" dir="auto">${w(t.context)}</p>`:""}
|
|
326
326
|
<p class="ask" dir="auto">${w(t.ask)}</p>
|
|
@@ -329,15 +329,15 @@ ${c?`<div class="options" role="radiogroup">${c}</div>`:""}
|
|
|
329
329
|
${l.why?`<p class="why" dir="auto">${w(l.why)}</p>`:""}
|
|
330
330
|
${t.draft?`<div class="label-row" id="msg"><span class="label">Message</span><span class="edited"><i class="dot"></i>Edited</span><button class="reset" id="reset">Reset</button></div>
|
|
331
331
|
<textarea id="text" dir="auto" rows="2" spellcheck="true"></textarea>`:""}
|
|
332
|
-
<div class="notes"><div>${
|
|
333
|
-
<div>${
|
|
332
|
+
<div class="notes"><div>${Eo}<span>${a?"It stays in Open requests on the Approvals page until you close it.":`If you don't answer by ${w(Ao(t.expires,n))}: ${w(t.if_silent)}.`}</span></div>
|
|
333
|
+
<div>${Co}<span>Nothing goes out until you click.</span></div></div>
|
|
334
334
|
</div><div class="foot"><button class="btn later" id="later">Not now<kbd>esc</kbd></button>
|
|
335
335
|
<button class="btn" id="no">${a?"Drop":"No"}</button>
|
|
336
|
-
<button class="btn primary" id="yes">${
|
|
336
|
+
<button class="btn primary" id="yes">${Io(t)}<kbd>\u2318\u21A9</kbd></button></div>
|
|
337
337
|
</main></div>
|
|
338
338
|
<script type="application/json" id="data">${JSON.stringify(d).replace(/</g,"\\u003c")}</script>
|
|
339
|
-
<script nonce="${r}">${
|
|
340
|
-
</body></html>`}var
|
|
339
|
+
<script nonce="${r}">${Do}</script>
|
|
340
|
+
</body></html>`}var Do=`
|
|
341
341
|
(function () {
|
|
342
342
|
var d = JSON.parse(document.getElementById("data").textContent);
|
|
343
343
|
var root = document.documentElement;
|
|
@@ -426,10 +426,10 @@ ${t.draft?`<div class="label-row" id="msg"><span class="label">Message</span><sp
|
|
|
426
426
|
});
|
|
427
427
|
} catch (e) {}
|
|
428
428
|
})();
|
|
429
|
-
`;var
|
|
429
|
+
`;var Mo=440,Wo=`
|
|
430
430
|
ObjC.import("Cocoa"); ObjC.import("WebKit")
|
|
431
431
|
function run(argv) {
|
|
432
|
-
var path = argv[0], side = ${E.side}, gripTop = ${E.top}, gripEnd = ${E.top+
|
|
432
|
+
var path = argv[0], side = ${E.side}, gripTop = ${E.top}, gripEnd = ${E.top+at.height}, keep = ${at.keep}, w = Number(argv[1]) + 2 * side, h = 420, secs = Number(argv[2]), capture = argv[3] || ""
|
|
433
433
|
var app = $.NSApplication.sharedApplication
|
|
434
434
|
app.setActivationPolicy($.NSApplicationActivationPolicyAccessory)
|
|
435
435
|
ObjC.registerSubclass({ name: "AgentXCardView", superclass: "WKWebView", methods: {
|
|
@@ -499,21 +499,21 @@ function run(argv) {
|
|
|
499
499
|
}
|
|
500
500
|
function gone(why) { return JSON.stringify({ action: "dismiss", why: why }) }
|
|
501
501
|
function quoted(s) { return "'" + String(s).replace(/'/g, "'\\\\''") + "'" }
|
|
502
|
-
`;function
|
|
503
|
-
`).pop()??"",i;try{i=JSON.parse(n)}catch{return{action:"dismiss"}}if(i?.action==="no")return{action:"no"};if(i?.action==="dismiss"&&
|
|
504
|
-
`).trim():"",!o||o.length>
|
|
505
|
-
`),n[n.length-1],String(i),...r!==void 0?[r]:[]])}function
|
|
506
|
-
`);return n<0?{button:e,text:""}:{button:e.slice(0,n),text:e.slice(n+1)}}function
|
|
502
|
+
`;function jo(t,e){let n=t.trim().split(`
|
|
503
|
+
`).pop()??"",i;try{i=JSON.parse(n)}catch{return{action:"dismiss"}}if(i?.action==="no")return{action:"no"};if(i?.action==="dismiss"&&Ar.includes(i.why))return{action:"dismiss",why:i.why};if(i?.action!=="yes")return{action:"dismiss"};let r=e.choices??[],s;if(r.length){if(typeof i.choice!="string"||!r.includes(i.choice))return{action:"dismiss"};s=i.choice}let o;return e.draft&&(o=typeof i.text=="string"?i.text.replace(/\r\n?/g,`
|
|
504
|
+
`).trim():"",!o||o.length>Kt.text)?{action:"dismiss"}:{action:"yes",...s?{choice:s}:{},...o?{text:o}:{}}}async function $r(t,e,n){let i=Math.max(10,Math.round(e.timeoutSeconds)),r=Po(vr(Oo(),"agentx-card-"));try{let s=vr(r,"card.html");No(s,xr(t,{...e,still:!!e.capture}),{mode:384});let o=["-l","JavaScript","-e",Wo,s,String(Mo),String(i),...e.capture?[e.capture]:[]],a=await n("/usr/bin/osascript",o,(i+10)*1e3);return a.ok?jo(a.stdout,t):null}finally{Lo(r,{recursive:!0,force:!0})}}var Ar=["not now","timed out","closed"],Fo=(t,e,n)=>new Promise(i=>{try{Uo(t,e,{timeout:n},(r,s)=>i({ok:!r,stdout:String(s??"")}))}catch{i({ok:!1,stdout:""})}}),Rr=160,ct=15e3;function _r(t){let e=(t.say||t.title).replace(/\s+/g," ").trim();return e.length>Rr?e.slice(0,Rr):e}async function Vo(t,e,n,i,r){let s=e.sound==="chime"?i?"":"Glass":e.sound,o=s?nn(s):null;if(o&&await n("/usr/bin/afplay",["-v",String(Math.min(1,Math.max(0,e.volume))),o],ct),!!e.speak)if(r){let a;await Promise.race([r(_r(t)),new Promise(l=>{a=setTimeout(l,ct)})]),clearTimeout(a)}else{let a=e.voice&&/^[\w .()-]+$/.test(e.voice)?["-v",e.voice]:[];await n("/usr/bin/say",[...a,"--",_r(t)],ct)}}function Tr(t,e){return[...t.flatMap(n=>["-e",n]),...e]}function qo(t,e,n){return Tr(["on run argv","activate","set opts to items 3 thru -1 of argv",'set pick to choose from list opts with title (item 1 of argv) with prompt (item 2 of argv) OK button name "Next" cancel button name "Not now"','if pick is false then return ""',"return item 1 of pick","end run"],[t,e,...n])}function Ir(t,e,n,i,r){return Tr(["on run argv","activate","set AppleScript's text item delimiters to linefeed","set btns to text items of (item 3 of argv)","set secs to (item 5 of argv) as integer","if (count of argv) > 5 then","set r to display dialog (item 2 of argv) with title (item 1 of argv) default answer (item 6 of argv) buttons btns default button (item 4 of argv) giving up after secs","else","set r to display dialog (item 2 of argv) with title (item 1 of argv) buttons btns default button (item 4 of argv) giving up after secs","end if",'if gave up of r then return ""',"if (count of argv) > 5 then return (button returned of r) & linefeed & (text returned of r)","return button returned of r","end run"],[t,e,n.join(`
|
|
505
|
+
`),n[n.length-1],String(i),...r!==void 0?[r]:[]])}function Er(t){let e=t.replace(/\n$/,"");if(!e)return null;let n=e.indexOf(`
|
|
506
|
+
`);return n<0?{button:e,text:""}:{button:e.slice(0,n),text:e.slice(n+1)}}function ut(t){return[t.ask,t.recommend?`Recommended: ${t.recommend}`:"",`From ${t.raised_by}`].filter(Boolean).join(`
|
|
507
507
|
|
|
508
|
-
`)}async function
|
|
508
|
+
`)}async function Cr(t,e,n={}){let i=n.run??Fo,r=(e.style??"card")==="card",s=Vo(t,e,i,r,n.speak).catch(()=>{});if(r){let o=await $r(t,{timeoutSeconds:e.timeoutSeconds,sound:e.sound,volume:e.volume,theme:e.theme,from:n.from,capture:n.capture,pick:n.pick},i).catch(()=>null);if(o)return o}return await s,Bo(t,e,i)}async function Bo(t,e,n){let i=Math.max(10,Math.round(e.timeoutSeconds)),r=(i+5)*1e3,s=`${t.raised_by}: ${t.title}`,o;if(t.choices?.length){let c=await n("/usr/bin/osascript",qo(s,ut(t),t.choices),r);if(o=c.stdout.replace(/\n$/,""),!c.ok||!t.choices.includes(o))return{action:"dismiss"};if(!t.draft)return{action:"yes",choice:o}}if(t.draft){let c=o?`${o}
|
|
509
509
|
|
|
510
|
-
Message (edit it if you like):`:`${
|
|
510
|
+
Message (edit it if you like):`:`${ut(t)}
|
|
511
511
|
|
|
512
|
-
Message (edit it if you like):`,d=await n("/usr/bin/osascript",
|
|
513
|
-
`)[0]}); Siri voices will not switch`),null}}var
|
|
514
|
-
`).pop()?.slice(0,160)??""}`))})})}import{mkdtemp as
|
|
515
|
-
`)[0].slice(0,200);l.push(`${c}: ${d}`),o.log(`[voice] phone transcription with ${c} failed: ${d}`)}return[502,{error:"Speech to text failed on this computer.",detail:l.join("; ")}]}function
|
|
516
|
-
`)[0].slice(0,160)}`),u("ElevenLabs could not speak this answer.",502)}}function
|
|
512
|
+
Message (edit it if you like):`,d=await n("/usr/bin/osascript",Ir(s,c,o?["Cancel","Send"]:["Not now","No","Send"],i,Yt(t.draft,o)),r),p=d.ok?Er(d.stdout):null;if(p?.button==="Send"){let g=p.text.trim();return g?{action:"yes",...o?{choice:o}:{},text:g}:{action:"dismiss"}}return p?.button==="No"?{action:"no"}:{action:"dismiss"}}let a=await n("/usr/bin/osascript",Ir(s,ut(t),["Not now","No","Yes"],i),r),l=a.ok?Er(a.stdout):null;return l?.button==="Yes"?{action:"yes"}:l?.button==="No"?{action:"no"}:{action:"dismiss"}}var pt=24*36e5,dt=!1,Ho=10*6e4,Dr=-1/0;function Pr(t){let e=t.now??Date.now(),{popped:n={},snoozed:i,passAt:r,wanted:s=[]}=A(t.root),o=r?Date.parse(r):NaN,a=q(t.root,"pending").filter(c=>Date.parse(c.expires)>e),l=a.find(c=>s.includes(`card:${c.id}`));if(l)return l;for(let c of a){let u=`card:${c.id}`;if(n[u])continue;let d=i[u];if(d&&Date.parse(d)>e)continue;let p=Date.parse(c.created_at);if(!(e-p>pt&&!(p<=o)))return c}return null}function Lr(t){try{return z(t)?.listByState("needs_attention")??[]}catch{return[]}}function zo(t){let e=t.now??Date.now(),{popped:n={},snoozed:i}=A(t.root);return Lr(t).find(r=>{let s=`request:${r.id}`,o=i[s];return!n[s]&&!(o&&Date.parse(o)>e)&&e-r.updatedAt<=pt})??null}function Xo(t,e){return{id:t.id,title:ot(t.text,sn.title),context:t.attentionReason??"It is not finished and nothing is retrying it.",ask:`Hand it back to ${t.agentId}, or drop it?`,say:"A request you made is not finished.",recommend:"",if_silent:"keep",expires:new Date(e+pt).toISOString(),raised_by:t.agentId,created_at:new Date(t.createdAt).toISOString(),status:"pending",origin:{kind:"request",id:t.id}}}async function vu(t){let{ctx:e,settings:n,log:i}=t;if(!n.enabled||(t.platform??process.platform)!=="darwin")return"off";if(dt)return"busy";let r=Pr(e)?null:zo(e),s=r?Xo(r,e.now??Date.now()):Pr(e);if(!s)return"none";let o=(t.focus??Vt)();if(o.active)return"held";dt=!0;let a=`${r?"request":"card"}:${s.id}`;try{let l=[...q(e.root,"pending").map(h=>`card:${h.id}`),...Lr(e).map(h=>`request:${h.id}`)];hn(e.root,a,l,e.now),i(`[approvals] popup: showing ${a} from ${s.raised_by}`);let c=e.now??Date.now(),u=!!r&&c-Dr<Ho;r&&n.speak&&(Dr=c);let d=t.agentName?.(s.raised_by)??(s.node?`${s.raised_by} on ${s.node}`:void 0),p=await(t.show??Cr)(s,u?{...n,speak:!1}:n,{from:d,speak:t.speak});if(p.action==="dismiss")return i(`[approvals] popup: ${a} left waiting: ${p.why??"no answer"} (${qt(o)} when shown)`),"shown";if(!(r?z(e)?.get(r.id)?.state==="needs_attention":V(e.root,s.id)?.status==="pending"))return i(`[approvals] popup: ${a} was answered elsewhere; popup answer ignored`),"shown";let f=await Ln(e,a,p.action,{by:"operator (popup)",...p.action==="yes"?{choice:p.choice,text:p.text}:{}});return i(f.ok?`[approvals] popup: ${f.message}`:`[approvals] popup: ${a} not recorded: ${f.error}`),"shown"}catch(l){return i(`[approvals] popup failed for ${a}: ${l?.message??l}`),"shown"}finally{dt=!1}}function $u(t,e,n){if(!n)return{ok:!1,error:"the Mac popup is off; turn it on with `agentx approvals settings --popup on`"};let i=e.startsWith("card:")?V(t.root,e.slice(5)):null;return i?i.status!=="pending"?{ok:!1,error:`${e} is already ${i.status}`}:(yn(t.root,e),{ok:!0,message:`${e} will show on the Mac within a minute`}):{ok:!1,error:`no card "${e}"; the popup shows decision cards only`}}import{closeSync as K,createReadStream as Go,fstatSync as Ko,openSync as Jo,realpathSync as Nr}from"fs";import{isAbsolute as Yo,resolve as Or,sep as Mr}from"path";var Tu="/app-files",Zo=/^[A-Za-z0-9_.:-]{1,64}$/;function Qo(t,e,n=process.cwd()){if(!e||e.length>ne.pathChars||e.includes("\0"))return{ok:!1,status:400,error:"bad file path"};if(e.split(/[\\/]/).includes(".."))return{ok:!1,status:403,error:`the path leaves the workspace: copy the file into ${Re}/ first`};if(!Ae(e))return{ok:!1,status:415,error:"this type of file is not served"};let i;try{i=Nr(Or(n,t))}catch{return{ok:!1,status:404,error:"the agent's workspace is missing"}}let r;try{r=Nr(Yo(e)?e:Or(i,e))}catch{return{ok:!1,status:404,error:"file not found"}}if(!r.startsWith(i+Mr))return{ok:!1,status:403,error:`the file is outside the agent's workspace: copy it into ${Re}/ first`};let s=Ae(r);return s?{ok:!0,path:r,...s}:{ok:!1,status:415,error:"this type of file is not served"}}function ea(t,e){let n=t.replace(/[^\x20-\x7e]/g,"_").replace(/["\\;]/g,"_").slice(0,120)||"file";return`${e==="file"?"attachment":"inline"}; filename="${n}"; filename*=UTF-8''${encodeURIComponent(t.slice(0,120))}`}function ta(t,e,n){return{"Content-Type":t,"Content-Disposition":ea(e,n),"X-Content-Type-Options":"nosniff","Content-Security-Policy":"default-src 'none'; img-src 'self'; media-src 'self'; sandbox","Cache-Control":"private, max-age=3600","Accept-Ranges":"bytes"}}function na(t,e){let n=/^bytes=(\d*)-(\d*)$/.exec(String(t||"").trim());if(!n||!n[1]&&!n[2])return null;let i,r;return n[1]?(i=Number(n[1]),r=n[2]?Math.min(Number(n[2]),e-1):e-1):(i=Math.max(0,e-Number(n[2])),r=e-1),i>r||i>=e?"unsatisfiable":{start:i,end:r}}function Cu(t,e,n,i){let r=(C,M)=>{e.writeHead(C,{"Content-Type":"application/json","Cache-Control":"no-store","X-Content-Type-Options":"nosniff"}),e.end(JSON.stringify(M))};if(t.method!=="GET"&&t.method!=="HEAD")return r(405,{error:"GET only"});let s=n.searchParams.get("agent")||"",o=n.searchParams.get("file")||"";if(!Zo.test(s))return r(400,{error:"bad agent id"});let a=i.workspaceOf(s);if(!a)return r(404,{error:`no agent "${s}" on this computer`});let l=Qo(a,o,i.cwd);if(!l.ok)return i.log?.(`[app-files] refused ${JSON.stringify(o.slice(0,200))} from ${s}: ${l.error}`),r(l.status,{error:l.error});let c;try{c=Jo(l.path,"r")}catch{return r(404,{error:"file not found"})}let u;try{let C=Ko(c);if(!C.isFile())return K(c),r(404,{error:"not a file"});u=C.size}catch{return K(c),r(404,{error:"file not found"})}if(u>ne.bytes)return K(c),r(413,{error:`the file is larger than ${ne.bytes/1024/1024} MB`});let d=l.path.split(Mr).pop()||"file",p=ta(l.mime,d,l.kind),g=na(t.headers.range,u);if(g==="unsatisfiable"){K(c),e.writeHead(416,{...p,"Content-Range":`bytes */${u}`}),e.end();return}let{start:f,end:h}=g??{start:0,end:u-1};if(e.writeHead(g?206:200,{...p,"Content-Length":String(u?h-f+1:0),...g?{"Content-Range":`bytes ${f}-${h}/${u}`}:{}}),t.method==="HEAD"||u===0){K(c),e.end();return}let y=Go("",{fd:c,start:f,end:h,autoClose:!0});y.on("error",()=>e.destroy()),e.on("close",()=>y.destroy()),y.pipe(e)}import{spawn as J}from"child_process";import{readFileSync as ra,writeFileSync as ia}from"fs";import{tmpdir as sa}from"os";import{join as oa}from"path";Rt();var Wr=t=>t&&t!==1?Math.round(175*t):null,he=t=>t&&t!==1?Math.min(1.2,Math.max(.7,t)):null;function aa(){if(process.env.ELEVENLABS_API_KEY)return process.env.ELEVENLABS_API_KEY;for(let t of[`${process.env.HOME}/.elevenlabs/key`,`${process.env.HOME}/.agentx/elevenlabs-key.txt`])try{let e=ra(t,"utf8").trim();if(e)return e}catch{}return null}function Uu(t=aa()){let e=0;return async(n,i)=>{if(n.voice.provider==="system")return null;if(!t){if(n.voice.fallback)return null;throw new Error("ElevenLabs is the voice provider but no key is set")}try{let r=await fetch(`https://api.elevenlabs.io/v1/text-to-speech/${n.voice.elevenlabs}/stream?output_format=mp3_44100_128`,{method:"POST",headers:{"xi-api-key":t,"Content-Type":"application/json"},body:JSON.stringify({text:n.text,model_id:"eleven_flash_v2_5",...he(n.voice.rate)?{voice_settings:{speed:he(n.voice.rate)}}:{}}),signal:i});if(!r.ok)throw new Error(`ElevenLabs ${r.status}: ${(await r.text()).slice(0,160)}`);let s=oa(sa(),`agentx-say-${process.pid}-${++e}.mp3`);return ia(s,Buffer.from(await r.arrayBuffer())),s}catch(r){if(i.aborted||!n.voice.fallback)throw r;return N(`elevenlabs:${String(r?.message??r).slice(0,40)}`,`[voice] ElevenLabs failed (${String(r?.message??r).slice(0,160)}); speaking with the system voice`),null}}}function jr(t,e){let n=t.languages&&ee(e);return n&&t.languages&&n in t.languages?t.languages[n]:t.system}var la=(t,e="")=>{let n=jr(t,e),i=Wr(t.rate);return[...n&&!Fn(n)?["-v",n]:[],...i?["-r",String(i)]:[]]};function ca(t,e,n){if(!n)return["say",la(t,e)];let i=jr(t,e);return["/bin/sh",[n,...i?[i]:[]]]}function Fu(t){let e=t.split(/\s+/).filter(Boolean).length;return Math.min(300,5+Math.floor(e*6/10))*1e3}function Vu(t=gt()){if(t)try{J("/bin/sh",[t,"--stop"],{stdio:"ignore"}).on("error",()=>{})}catch{}}function qu(t=gt()){if(t)try{J("/bin/sh",[t,"--restore"],{stdio:"ignore"}).on("error",()=>{})}catch{}}function gt(t={},e){if(!Oe(t))return null;try{return Bn(e)}catch(n){return N("siri-say",`[voice] could not write the Siri voice script (${String(n?.message??n).split(`
|
|
513
|
+
`)[0]}); Siri voices will not switch`),null}}var Bu=(t,e)=>{if(!t){let[n,i]=ca(e.voice,e.text,gt()),r=Wr(e.voice.rate),s=r?{...process.env,AGENTX_SAY_RATE:String(r)}:process.env,o=J(n,i,{stdio:["pipe","ignore","ignore"],env:s});return o.stdin?.on("error",()=>{}),o.stdin?.end(e.text),o}return process.platform==="darwin"?J("afplay",[t],{stdio:"ignore"}):J("mpg123",["-q",t],{stdio:"ignore"})};import{spawn as Ur}from"child_process";import{accessSync as ua,constants as da,readFileSync as Fr}from"fs";import{homedir as pa}from"os";import{basename as U,delimiter as Vr,dirname as ga,extname as fa,join as ft}from"path";var P={ms:2*60*1e3,bitsPerSecond:64e3,bytes:2*1024*1024};function qr(t){let e=Array.isArray(t)?t[0]:t;return!e||!/^\d{1,9}$/.test(e.trim())?{status:400,error:"Say how long the recording is (X-Audio-Duration-Ms)."}:Number(e)>P.ms+2e3?{status:413,error:ht()}:null}var ht=()=>`The recording is longer than ${P.ms/6e4} minutes.`,ma={"audio/webm":"webm","video/webm":"webm","audio/ogg":"ogg","audio/mp4":"m4a","video/mp4":"m4a","audio/x-m4a":"m4a","audio/aac":"aac","audio/mpeg":"mp3","audio/wav":"wav","audio/x-wav":"wav","audio/wave":"wav"};function Br(t){let e=String(t||"").split(";")[0].trim().toLowerCase();return ma[e]??null}function Hr(t,e){let n=[];return t!=="local"&&e.key&&n.push("elevenlabs"),e.ffmpeg&&(e.mlx?n.push("mlx-whisper"):e.whisper&&n.push("whisper")),n}function yt(t,e){return t==="local"&&e.key&&!e.ffmpeg?"Speech to text is set to local, and this computer has no ffmpeg.":(e.mlx||e.whisper)&&!e.ffmpeg?"This computer has Whisper but no ffmpeg to read the recording.":"Add an ElevenLabs key on this computer, or install mlx-whisper and ffmpeg."}function mt(t,e,n=process.env.PATH??""){let i=pa(),r=[ft(i,".local","bin"),"/opt/homebrew/bin","/usr/local/bin",...n.split(Vr).filter(Boolean)];for(let s of[e,...r.map(o=>ft(o,t))])if(s)try{return ua(s,da.X_OK),s}catch{}return null}function Ju(t){return{key:t,mlx:mt("mlx_whisper",process.env.AGENTX_MLX_WHISPER),whisper:mt("whisper",process.env.AGENTX_WHISPER),ffmpeg:ha()}}var ha=()=>mt("ffmpeg",process.env.AGENTX_FFMPEG);async function zr(t,e){return e?ya(t,e):null}async function ya(t,e){let n=String(P.ms/1e3+5);try{let r=[...(await ba(e,["-nostdin","-hide_banner","-t",n,"-i",t,"-f","null","-"],3e4)).matchAll(/time=(\d+):(\d+):(\d+(?:\.\d+)?)/g)],s=r[r.length-1];return s?Number(s[1])*3600+Number(s[2])*60+Number(s[3]):null}catch{return null}}async function Xr(t,e,n,i){let r=new FormData;r.set("model_id",process.env.AGENTX_STT_MODEL||"scribe_v1"),r.set("file",new Blob([Fr(t)],{type:e}),U(t));let s=await fetch("https://api.elevenlabs.io/v1/speech-to-text",{method:"POST",headers:{"xi-api-key":n},body:r,signal:i??AbortSignal.timeout(6e4)});if(!s.ok)throw new Error(`ElevenLabs ${s.status}: ${(await s.text().catch(()=>"")).slice(0,160)}`);let o=await s.json();if(typeof o.text!="string")throw new Error("ElevenLabs returned no text");return o.text.trim()}async function Gr(t,e,n,i,r){let s=t==="mlx-whisper"?["--model",process.env.AGENTX_MLX_MODEL||"mlx-community/whisper-large-v3-turbo","--output-format","txt","--output-dir",r,n]:[n,"--model",process.env.AGENTX_WHISPER_MODEL||"base","--output_format","txt","--output_dir",r,"--fp16","False"],o={...process.env,PATH:`${ga(i)}${Vr}${process.env.PATH??""}`};await wa(e,s,12e4,o);try{return Fr(ft(r,U(n,fa(n))+".txt"),"utf8").trim()}catch{throw new Error(`${t} wrote no transcript`)}}function ba(t,e,n){return new Promise((i,r)=>{let s=Ur(t,e,{stdio:["ignore","ignore","pipe"]}),o="",a=setTimeout(()=>{s.kill("SIGKILL"),r(new Error(`${U(t)} took too long`))},n);s.stderr.on("data",l=>{o=(o+l).slice(-8192)}),s.on("error",l=>{clearTimeout(a),r(l)}),s.on("exit",l=>{clearTimeout(a),l===0?i(o):r(new Error(`${U(t)} exited ${l}`))})})}function wa(t,e,n,i=process.env){return new Promise((r,s)=>{let o=Ur(t,e,{stdio:["ignore","pipe","pipe"],env:i}),a="",l="",c=setTimeout(()=>{o.kill("SIGKILL"),s(new Error(`${U(t)} took longer than ${n/1e3}s`))},n);o.stdout.on("data",u=>{a.length<4096&&(a+=u)}),o.stderr.on("data",u=>{l.length<4096&&(l+=u)}),o.on("error",u=>{clearTimeout(c),s(u)}),o.on("exit",u=>{clearTimeout(c),u===0?r(a):s(new Error(`${U(t)} exited ${u}: ${l.trim().split(`
|
|
514
|
+
`).pop()?.slice(0,160)??""}`))})})}import{mkdtemp as ka,rm as Sa,writeFile as xa}from"fs/promises";import{tmpdir as va}from"os";import{join as Kr}from"path";ii();var $a=64*1024,Aa=2,bt=0;function ad(t){return t==="/voice/transcribe"||t==="/voice/speak"}async function ld(t,e,n,i){return t.method!=="POST"?b(e,405,{error:"POST"}):n==="/voice/transcribe"?Ra(t,e,i):Ea(t,e,i)}async function Ra(t,e,n){let i=String(t.headers["content-type"]||""),r=Br(i);if(!r)return b(e,415,{error:"Send the recording as audio (webm, mp4, ogg, mp3 or wav)."});let s=qr(t.headers["x-audio-duration-ms"]);if(s)return t.resume(),b(e,s.status,{error:s.error});let o=await Jr(t,P.bytes);if(!o)return b(e,413,{error:Da()});if(!o.length)return b(e,400,{error:"The recording is empty."});if(bt>=Aa)return b(e,429,{error:"This computer is already writing down other recordings. Try again in a moment."});let a=n.stt(),l=n.host(),c=Hr(a,l);if(!l.ffmpeg&&!n.allowUnmeasured?.()){let d=n.nodeName?`on ${n.nodeName}`:"on this computer",p=c.length?"":" "+yt(a,l);return b(e,503,{error:"Voice input isn't set up on this computer.",hint:`Install ffmpeg ${d} for voice input from the phone.${p}`,setup:!1})}if(!c.length)return b(e,503,{error:"Voice input isn't set up on this computer.",hint:yt(a,l),setup:!1});bt++;let u;try{let d=await ka(Kr(va(),"agentx-phone-voice-"));try{u=await _a(d,`speech.${r}`,o,i,l,c,n)}finally{await Sa(d,{recursive:!0,force:!0}).catch(()=>{})}}finally{bt--}b(e,u[0],u[1])}async function _a(t,e,n,i,r,s,o){let a=Kr(t,e);if(await xa(a,n,{mode:384}),r.ffmpeg){let c=await(o.measure??zr)(a,r.ffmpeg);if(c==null)return[422,{error:"This computer couldn't read the recording. Try again."}];if(c*1e3>P.ms+2e3)return[413,{error:ht()}]}let l=[];for(let c of s)try{let u=await Ia(c,a,i,r,t,o);return o.log(`[voice] phone recording transcribed with ${c} (${Math.round(n.length/1024)} KB)`),u?[200,{text:u,engine:c}]:[422,{error:"No words were heard. Hold the orb and speak, then let go.",engine:c}]}catch(u){let d=String(u?.message??u).split(`
|
|
515
|
+
`)[0].slice(0,200);l.push(`${c}: ${d}`),o.log(`[voice] phone transcription with ${c} failed: ${d}`)}return[502,{error:"Speech to text failed on this computer.",detail:l.join("; ")}]}function Ia(t,e,n,i,r,s){let o=s.engines?.[t];if(o)return o(e,n,i,r);if(t==="elevenlabs")return Xr(e,n,i.key);let a=t==="mlx-whisper"?i.mlx:i.whisper;return Gr(t,a,e,i.ffmpeg,r)}async function Ea(t,e,n){let i=await Jr(t,$a);if(!i)return b(e,413,{error:"request too large"});let r;try{r=JSON.parse(i.toString("utf8")||"{}")}catch{return b(e,400,{error:"expected JSON"})}let s=typeof r?.agent=="string"?r.agent:"",o=typeof r?.peer=="string"&&r.peer?r.peer:void 0;if(!s)return b(e,400,{error:"agent is required"});let a=Ta(typeof r?.text=="string"?r.text:"",n.spokenMaxChars?.());if(!a)return b(e,422,{error:"Nothing in this answer can be said aloud."});let l=n.pronounce?n.pronounce(a):a,c=n.voiceOf(s,o);if(!c)return b(e,404,{error:`Unknown agent: ${s}`});let u=(p,g=200)=>b(e,g,{fallback:"browser",reason:p,text:l});if(c.provider!=="elevenlabs")return u("This agent speaks with a system voice, which only plays on the computer.");let d=n.elevenLabsKey();if(!d)return u("No ElevenLabs key is set on this computer.");try{let p=await(n.synth??Ca)(d,c,l);e.writeHead(200,{"Content-Type":"audio/mpeg","Content-Length":p.length,"Cache-Control":"no-store","X-Spoken-Chars":String(l.length)}),e.end(p)}catch(p){return n.log(`[voice] phone answer synthesis failed: ${String(p?.message??p).split(`
|
|
516
|
+
`)[0].slice(0,160)}`),u("ElevenLabs could not speak this answer.",502)}}function Ta(t,e){let n=fr(Ft(t).text).cleanText.replace(/!\[[^\]\n]*\]\([^)\n]*\)/g,"");return _t(n,e)}async function Ca(t,e,n){let i=he(e.rate),r=await fetch(`https://api.elevenlabs.io/v1/text-to-speech/${encodeURIComponent(e.elevenlabs)}?output_format=mp3_44100_128`,{method:"POST",headers:{"xi-api-key":t,"Content-Type":"application/json"},body:JSON.stringify({text:n,model_id:"eleven_flash_v2_5",...i?{voice_settings:{speed:i}}:{}}),signal:AbortSignal.timeout(6e4)});if(!r.ok)throw new Error(`ElevenLabs ${r.status}: ${(await r.text().catch(()=>"")).slice(0,160)}`);return Buffer.from(await r.arrayBuffer())}var Da=()=>`The recording is larger than ${P.bytes/1024/1024} MB, more than ${P.ms/6e4} minutes of speech.`;function cd(t,e,n,i){if(e)return i.speakerOn(e,t,!1)?.voice??null;let r=n.agents??{};return r[t]?ze(qe(t,r,n.voice)):null}function Jr(t,e){return Number(t.headers["content-length"])>e?(t.resume(),Promise.resolve(null)):new Promise((n,i)=>{let r=[],s=0;t.on("data",o=>{if(!(s>e)){if(s+=o.length,s>e){r.length=0,n(null);return}r.push(o)}}),t.on("end",()=>{s<=e&&n(Buffer.concat(r))}),t.on("error",i)})}function b(t,e,n){t.writeHead(e,{"Content-Type":"application/json","Cache-Control":"no-store"}),t.end(JSON.stringify(n))}import{existsSync as v,readFileSync as xt,writeFileSync as vt,mkdirSync as ye,readdirSync as St,rmSync as Pa,statSync as _}from"fs";import{resolve as Yr,relative as La,dirname as $t,join as O,extname as Y,basename as At}from"path";var S=200*1024,Zr=new Set([".md",".markdown",".txt"]),F=new Set([".md",".markdown",".txt",".json",".jsonc",".yaml",".yml",".toml",".sh",".bash",".zsh",".py",".js",".mjs",".ts",".tsx",".jsx",".css",".html",".lock",".cfg",".ini",".env",".gitignore"]),Na=6,Oa=new Set(["CLAUDE.md","SOUL.md","IDENTITY.md","PERSONA.md","AGENT.md","BOOTSTRAP.md"]);function T(t,e){if(!t)throw new Error("Agent workspace is not configured.");let n=Yr(t);if(v(n)||ye(n,{recursive:!0}),!e||e.startsWith("/")||e.match(/^[a-zA-Z]:/))throw new Error(`Path must be relative to the workspace: ${e}`);let i=Yr(n,e);if(La(n,i).startsWith(".."))throw new Error(`Path escapes the workspace: ${e}`);return i}function Qr(t){let e=Y(t).toLowerCase();if(!Zr.has(e))throw new Error(`Only text files (.md, .markdown, .txt) can be edited from the admin panel (got ${e}).`)}function wt(t,e){let n=t.split(/\r?\n/).find(i=>i.trim().startsWith("#"));return n&&n.replace(/^#+\s*/,"").trim().slice(0,120)||e}function gd(t){let e=T(t,"."),n=[],i=new Set,r=[];try{r=St(e)}catch{}for(let a of Oa){let l=O(e,a);if(v(l)&&_(l).isFile()){let c=_(l).size,u=c>0&&c<S?kt(l):"";n.push({path:a,title:wt(u,a),size:c,exists:!0}),i.add(a)}else n.push({path:a,title:a,size:0,exists:!1}),i.add(a)}for(let a of r){if(i.has(a))continue;let l=O(e,a);try{let c=_(l);if(!c.isFile()||!Zr.has(Y(a).toLowerCase()))continue;let u=c.size>0&&c.size<S?kt(l):"";n.push({path:a,title:wt(u,a),size:c.size,exists:!0})}catch{}}let s=[],o=O(e,".claude","skills");if(v(o))try{for(let a of St(o)){let l=O(o,a),c;try{c=_(l)}catch{continue}if(!c.isDirectory())continue;let u=O(l,"SKILL.md");if(!v(u))continue;let d=_(u),p=d.size<S?kt(u):"";s.push({slug:a,title:wt(p,a),size:d.size,path:`.claude/skills/${a}/SKILL.md`})}}catch{}return s.sort((a,l)=>a.slug.localeCompare(l.slug)),{identity:n,skills:s,workspace:e}}function kt(t){try{return xt(t,"utf-8")}catch{return""}}function fd(t,e){let n=T(t,e);if(Qr(n),!v(n))return{path:e,content:""};if(_(n).size>S)throw new Error(`File is too large to edit in the admin panel (> ${S/1024} KB).`);return{path:e,content:xt(n,"utf-8")}}function md(t,e,n){let i=T(t,e);Qr(i);let r=Buffer.from(n,"utf-8");if(r.length>S)throw new Error(`File too large (${r.length} > ${S} bytes).`);return ye($t(i),{recursive:!0}),vt(i,r),{path:e,bytes:r.length}}function hd(t,e,n={}){if(!/^[a-z0-9][a-z0-9_-]*$/.test(e))throw new Error("Skill slug must be lowercase (letters, digits, -, _) and start with a letter or digit.");let i=`.claude/skills/${e}/SKILL.md`,r=T(t,i);if(v(r))throw new Error(`Skill "${e}" already exists.`);ye($t(r),{recursive:!0});let s=n.content?.trim()?n.content:Ma(e,n.title);return vt(r,s),{slug:e,path:i}}function yd(t,e){if(!/^[a-z0-9][a-z0-9_-]*$/.test(e))throw new Error(`Invalid skill slug: ${e}`);let n=T(t,`.claude/skills/${e}`);if(!v(n))throw new Error(`Skill "${e}" not found.`);if(!_(n).isDirectory())throw new Error(`Skill path is not a directory: ${e}`);return Pa(n,{recursive:!0,force:!0}),{slug:e}}function bd(t,e){if(!/^[a-z0-9][a-z0-9_-]*$/.test(e))throw new Error(`Invalid skill slug: ${e}`);let n=T(t,`.claude/skills/${e}`);if(!v(n))throw new Error(`Skill "${e}" not found.`);let i=[];return r(n,"",0,i),i.sort((s,o)=>s.kind!==o.kind?s.kind==="dir"?-1:1:s.path.localeCompare(o.path)),i;function r(s,o,a,l){if(a>Na)return;let c=[];try{c=St(s)}catch{return}for(let u of c){if(u==="node_modules"||u===".git")continue;let d=O(s,u),p=o?`${o}/${u}`:u,g;try{g=_(d)}catch{continue}if(g.isDirectory())l.push({path:`${p}/`,kind:"dir",size:0,editable:!1}),r(d,p,a+1,l);else if(g.isFile()){let f=Y(u).toLowerCase(),h=F.has(f)||F.has(u.toLowerCase());l.push({path:p,kind:"file",size:g.size,editable:h&&g.size<S})}}}}function wd(t,e,n){if(!/^[a-z0-9][a-z0-9_-]*$/.test(e))throw new Error(`Invalid skill slug: ${e}`);if(!n||n.includes(".."))throw new Error(`Invalid file path: ${n}`);let i=T(t,`.claude/skills/${e}/${n}`);if(!v(i)||!_(i).isFile())throw new Error(`File not found: ${n}`);let r=Y(i).toLowerCase(),s=At(i).toLowerCase();if(!F.has(r)&&!F.has(s))throw new Error(`File type not editable: ${n}`);if(_(i).size>S)throw new Error(`File too large to edit (> ${S/1024} KB): ${n}`);return{path:n,content:xt(i,"utf-8")}}function kd(t,e,n,i){if(!/^[a-z0-9][a-z0-9_-]*$/.test(e))throw new Error(`Invalid skill slug: ${e}`);if(!n||n.includes(".."))throw new Error(`Invalid file path: ${n}`);let r=T(t,`.claude/skills/${e}/${n}`),s=Y(r).toLowerCase(),o=At(r).toLowerCase();if(!F.has(s)&&!F.has(o))throw new Error(`File type not editable: ${n}`);let a=Buffer.from(i,"utf-8");if(a.length>S)throw new Error(`File too large (${a.length} > ${S} bytes).`);return ye($t(r),{recursive:!0}),vt(r,a),{path:n,bytes:a.length}}function Sd(t,e){if(!/^[a-z0-9][a-z0-9_-]*$/.test(e))throw new Error(`Invalid skill slug: ${e}`);let n=T(t,`.claude/skills/${e}`);if(!v(n))throw new Error(`Skill "${e}" not found.`);let i=r=>v(O(n,r));return i("pnpm-lock.yaml")?{manager:"pnpm",file:"pnpm-lock.yaml",command:"pnpm install"}:i("yarn.lock")?{manager:"yarn",file:"yarn.lock",command:"yarn install"}:i("package.json")?{manager:"npm",file:"package.json",command:"npm install"}:i("requirements.txt")?{manager:"pip",file:"requirements.txt",command:"pip install -r requirements.txt"}:i("Gemfile")?{manager:"bundle",file:"Gemfile",command:"bundle install"}:{manager:null,file:null,command:null}}function Ma(t,e){return`# ${e?.trim()||t}
|
|
517
517
|
|
|
518
518
|
Describe what this skill does and when the agent should use it. Keep it under ~5 lines \u2014 the agent reads this to decide whether to invoke the skill.
|
|
519
519
|
|
|
@@ -526,7 +526,7 @@ Document the arguments, commands, or files the skill expects. Example:
|
|
|
526
526
|
|
|
527
527
|
\`\`\`bash
|
|
528
528
|
# Example invocation
|
|
529
|
-
claude-code ${
|
|
529
|
+
claude-code ${At(t)} --arg value
|
|
530
530
|
\`\`\`
|
|
531
|
-
`}
|
|
532
|
-
//# sourceMappingURL=chunk-
|
|
531
|
+
`}Mt();var ei={maxPixels:12e5,timeoutMs:5e3,intervalMs:100,changeThreshold:.015,stableMs:400,regions:{},buffer:{enabled:!1,seconds:10,fps:2,region:"screen",maxPixels:3e5}};function ti(t){return{...ei,...t??{},regions:{...t?.regions??{}},buffer:{...ei.buffer,...t?.buffer??{}}}}function $d(t){try{return ti(Ot(t).screen)}catch{return ti(void 0)}}var Wa=/^[a-z][\w-]*$/,ni=["window","screen","menubar","notifications"];function Z(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 be=(t,e)=>Z(t,e,n=>Number.isInteger(n)&&n>0,"a whole number above 0");function ri(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 Ad(t,e){let n={...t??{}};if("maxPixels"in e&&(n.maxPixels=be(e.maxPixels,"maxPixels")),"timeoutMs"in e&&(n.timeoutMs=be(e.timeoutMs,"timeoutMs")),"intervalMs"in e&&(n.intervalMs=be(e.intervalMs,"intervalMs")),"stableMs"in e&&(n.stableMs=Z(e.stableMs,"stableMs",r=>Number.isInteger(r)&&r>=0,"a whole number, 0 or more")),"changeThreshold"in e&&(n.changeThreshold=Z(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(!Wa.test(s))throw new Error(`region name "${s}" must be lowercase letters, digits, - or _`);o===null?delete r[s]:r[s]=ri(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=Z(r.seconds,"buffer.seconds",o=>o>0&&o<=120,"above 0 and at most 120")),"fps"in r&&(s.fps=Z(r.fps,"buffer.fps",o=>o>0&&o<=10,"above 0 and at most 10")),"maxPixels"in r&&(s.maxPixels=be(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&&!ni.includes(i)&&!n.regions?.[i])try{ri(i)}catch{throw new Error(`buffer.region "${i}" is not a region \u2014 use ${[...ni,...Object.keys(n.regions??{})].join(", ")}, or x,y,w,h`)}return n}export{an as a,Fa as b,rt as c,ro as d,io as e,_c as f,Ic as g,Ec as h,fr as i,Cc as j,Pc as k,D as l,mr as m,k as n,Ha as o,el as p,Li as q,ol as r,An as s,A as t,Ja as u,Ya as v,cl as w,ae as x,ul as y,In as z,hl as A,z as B,Cl as C,Dl as D,Ln as E,Mc as F,hr as G,it as H,Wc as I,jc as J,mo as K,Uc as L,Fc as M,Vc as N,yr as O,Hc as P,ot as Q,Jc as R,Cr as S,vu as T,$u as U,Tu as V,ta as W,Cu as X,Ll as Y,Nl as Z,Ol as _,Ml as $,Wl as aa,jl as ba,Fl as ca,Vl as da,Yl as ea,je as fa,Zl as ga,Ql as ha,X as ia,G as ja,aa as ka,Uu as la,Fu as ma,Vu as na,qu as oa,gt as pa,Bu as qa,Ve as ra,qe as sa,ge as ta,vs as ua,As as va,ic as wa,He as xa,ze as ya,Rs as za,_s as Aa,er as Ba,ir as Ca,sc as Da,Ts as Ea,oc as Fa,Ws as Ga,Fs as Ha,Xe as Ia,qs as Ja,sr as Ka,P as La,qr as Ma,Br as Na,Hr as Oa,Ju as Pa,ha as Qa,Xr as Ra,Gr as Sa,ad as Ta,ld as Ua,Da as Va,cd as Wa,Jr as Xa,fe as Ya,bc as Za,dr as _a,Ge as $a,tt as ab,Ac as bb,gd as cb,fd as db,md as eb,hd as fb,yd as gb,bd as hb,wd as ib,kd as jb,Sd as kb,ei as lb,ti as mb,$d as nb,ni as ob,Ad as pb};
|
|
532
|
+
//# sourceMappingURL=chunk-YVNGPYXN.js.map
|