agentix-cli 0.204.0 → 0.206.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-FQRHQT5J.js → App-JDW5V4HT.js} +2 -2
- package/dist/{ChatApp-WBCGSGJM.js → ChatApp-SNM2PORO.js} +2 -2
- package/dist/{absorb-eval-3IU37HZQ.js → absorb-eval-WDAV4AI2.js} +2 -2
- package/dist/{adapter-URFSOOFE.js → adapter-C47BTKT6.js} +2 -2
- package/dist/{agent-P7XUCP3A.js → agent-EVMKJXJO.js} +2 -2
- package/dist/{board-dashboard-AVUFPO5X.js → board-dashboard-EUWXJNDW.js} +403 -416
- package/dist/board-dashboard-EUWXJNDW.js.map +1 -0
- package/dist/{chunk-WKR2OSCH.js → chunk-245IOYDJ.js} +2 -2
- package/dist/{chunk-FOWRNDMJ.js → chunk-2LJZHKTY.js} +2 -2
- package/dist/{chunk-P65XGEB7.js → chunk-2P3SHT5I.js} +2 -2
- package/dist/{chunk-JUSQMQ7L.js → chunk-2VSK6FAR.js} +2 -2
- package/dist/chunk-2YDG5CSS.js +2 -0
- package/dist/chunk-2YDG5CSS.js.map +1 -0
- package/dist/{chunk-EANSYWBQ.js → chunk-3B5HSNOF.js} +334 -326
- package/dist/chunk-3B5HSNOF.js.map +1 -0
- package/dist/{chunk-T7WY5BSJ.js → chunk-5STGF4MI.js} +40 -40
- package/dist/chunk-5STGF4MI.js.map +1 -0
- package/dist/chunk-BED4R5CS.js +12 -0
- package/dist/chunk-BED4R5CS.js.map +1 -0
- package/dist/{chunk-JKT5EFXT.js → chunk-CXFVIDJV.js} +2 -2
- package/dist/{chunk-ZPCSPEGO.js → chunk-CZVCT5ZV.js} +2 -2
- package/dist/{chunk-Y2D6FQBL.js → chunk-DOO4MUTS.js} +2 -2
- package/dist/{chunk-RIBANO2H.js → chunk-DUCYRNCT.js} +3 -3
- package/dist/chunk-DUCYRNCT.js.map +1 -0
- package/dist/{chunk-HX4R7RPR.js → chunk-DV42WUMD.js} +2 -2
- package/dist/{chunk-CAYY2IEV.js → chunk-EFGAPAYZ.js} +2 -2
- package/dist/chunk-EJFPXG6I.js +969 -0
- package/dist/chunk-EJFPXG6I.js.map +1 -0
- package/dist/{chunk-MAQFWGFT.js → chunk-ERVJLPS4.js} +2 -2
- package/dist/{chunk-IAR5F3T5.js → chunk-IDGEDPRJ.js} +2 -2
- package/dist/chunk-IFNXMUEG.js +115 -0
- package/dist/chunk-IFNXMUEG.js.map +1 -0
- package/dist/{chunk-SLX3OHEW.js → chunk-IU63JGY3.js} +2 -2
- package/dist/{chunk-7QW4RECS.js → chunk-JSCVOB4G.js} +2 -2
- package/dist/{chunk-RUNCUVAH.js → chunk-JT5PIBCM.js} +2 -2
- package/dist/{chunk-EQPMQSJE.js → chunk-KRHVM26D.js} +2 -2
- package/dist/{chunk-5VD2J4JN.js → chunk-MF46BC7J.js} +2 -2
- package/dist/{chunk-VGYW3Q7F.js → chunk-OLKYIKAZ.js} +2 -2
- package/dist/{chunk-RB7M2NPU.js → chunk-PQUK6XEW.js} +2 -2
- package/dist/{chunk-PSOE356C.js → chunk-PQX2VJUA.js} +2 -2
- package/dist/{chunk-TV5BDCQA.js → chunk-PTZNM2JU.js} +2 -2
- package/dist/{chunk-M4VYHPDS.js → chunk-PW3WG6JT.js} +2 -2
- package/dist/{chunk-EMWSFITR.js → chunk-QASIUKZJ.js} +2 -2
- package/dist/{chunk-N6NZBAWR.js → chunk-RXX4MYFL.js} +2 -2
- package/dist/{chunk-C2VZHIIX.js → chunk-S5A7QZVQ.js} +2 -2
- package/dist/{chunk-CJI26AJC.js → chunk-SKCOIP5R.js} +3 -3
- package/dist/{chunk-BIYEGA7Q.js → chunk-TH2W2545.js} +2 -2
- package/dist/{chunk-V3FSKTDF.js → chunk-UGRMFQAG.js} +2 -2
- package/dist/{chunk-Y4YOYOCG.js → chunk-USFOOYPM.js} +2 -2
- package/dist/{chunk-WIGH5WMP.js → chunk-V5LRR5I5.js} +9 -9
- package/dist/{chunk-QOEO27LF.js → chunk-WJMYBRM5.js} +2 -2
- package/dist/cli.js +1 -1
- package/dist/{client-EOQLSAUW.js → client-WN7YI7DE.js} +2 -2
- package/dist/{config-SZZQFIJF.js → config-QUXKGIZX.js} +2 -2
- package/dist/{config-mutate-66VDWR46.js → config-mutate-HJH24ITC.js} +2 -2
- package/dist/{config-mutator-OILDQCAJ.js → config-mutator-OLLQR3ZD.js} +2 -2
- package/dist/{connect-AJKMRKXC.js → connect-OOPPXAOD.js} +2 -2
- package/dist/{contributions-LRQCDZCQ.js → contributions-LL7B4BP3.js} +2 -2
- package/dist/daemon-api-QCBFGT7S.js +2 -0
- package/dist/daemon-api-QCBFGT7S.js.map +1 -0
- package/dist/{doctor-EDZO7BUJ.js → doctor-X75KLAFA.js} +2 -2
- package/dist/{enrich-NIUEEGPA.js → enrich-MZMIQ3SV.js} +2 -2
- package/dist/{event-levels-D6QSANGF.js → event-levels-PCFARGKL.js} +2 -2
- package/dist/{follow-up-tool-QOO2TIQS.js → follow-up-tool-I2HTKMP4.js} +2 -2
- package/dist/{grants-3UVDASRI.js → grants-2MNWGCSH.js} +2 -2
- package/dist/{hub-6TKU6CHO.js → hub-7ASBN76I.js} +2 -2
- package/dist/index.d.ts +52 -40
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/org-tool-JCGGJJU6.js +2 -0
- package/dist/org-tool-JCGGJJU6.js.map +1 -0
- package/dist/{program-OFN6YQRH.js → program-NCFW4EEP.js} +238 -238
- package/dist/program-NCFW4EEP.js.map +1 -0
- package/dist/{promote-D3KYLUBD.js → promote-NSPUPPHB.js} +2 -2
- package/dist/providers-D6IUAHQJ.js +2 -0
- package/dist/{query-D2TQ2PUO.js → query-VW63IHDI.js} +2 -2
- package/dist/{query-settings-ILDX3HDF.js → query-settings-RS7DJI4H.js} +2 -2
- package/dist/{registry-N3BY3HSI.js → registry-6KREAROB.js} +2 -2
- package/dist/{request-planner-CVCG5XQR.js → request-planner-HZWQIRZO.js} +2 -2
- package/dist/resolve-LOYZUE2D.js +2 -0
- package/dist/{review-candidates-CKUN4PSY.js → review-candidates-2TXOUASP.js} +2 -2
- package/dist/{routing-OCIRGUKK.js → routing-ZV4VSZDV.js} +2 -2
- package/dist/{rules-A5ES57QT.js → rules-FBOLGE2S.js} +2 -2
- package/dist/schedule-tool-D357NLXS.js +2 -0
- package/dist/{scheduler-D2Z7RSEE.js → scheduler-SAID6RKQ.js} +2 -2
- package/dist/{seat-Z3E2FLDA.js → seat-XHBWBSTS.js} +2 -2
- package/dist/{select-J4ES7Q67.js → select-QUCTTAH3.js} +2 -2
- package/dist/{set-enabled-S22TICYC.js → set-enabled-CGMXLFC6.js} +2 -2
- package/dist/{sprint-tool-NDF47EKV.js → sprint-tool-SWRYSX3Q.js} +2 -2
- package/dist/status-PVYFTNX2.js +2 -0
- package/dist/{tool-6NZIUXI7.js → tool-6G63ZQW4.js} +2 -2
- package/dist/{tool-RCCMOMEY.js → tool-DA25L4ND.js} +2 -2
- package/dist/{tool-52JRXZVA.js → tool-ELGOVIM5.js} +2 -2
- package/dist/{tool-Z2OVFGWW.js → tool-MMH2JNP7.js} +2 -2
- package/dist/{wiki-HQKFZZSX.js → wiki-4ZL4QXA7.js} +2 -2
- package/dist/wiki-enrich-N5MUKDVW.js +2 -0
- package/dist/workspace-setup-QXFJRNSK.js +2 -0
- package/package.json +1 -1
- package/dist/board-dashboard-AVUFPO5X.js.map +0 -1
- package/dist/chunk-B6VASQHD.js +0 -2
- package/dist/chunk-B6VASQHD.js.map +0 -1
- package/dist/chunk-EANSYWBQ.js.map +0 -1
- package/dist/chunk-FCDMB2JA.js +0 -936
- package/dist/chunk-FCDMB2JA.js.map +0 -1
- package/dist/chunk-GDHSJH3T.js +0 -111
- package/dist/chunk-GDHSJH3T.js.map +0 -1
- package/dist/chunk-RIBANO2H.js.map +0 -1
- package/dist/chunk-T7WY5BSJ.js.map +0 -1
- package/dist/chunk-XPZSEDE3.js +0 -12
- package/dist/chunk-XPZSEDE3.js.map +0 -1
- package/dist/daemon-api-OVCXY4QC.js +0 -2
- package/dist/daemon-api-OVCXY4QC.js.map +0 -1
- package/dist/program-OFN6YQRH.js.map +0 -1
- package/dist/providers-AHLCB6R5.js +0 -2
- package/dist/resolve-JKXYBZ6R.js +0 -2
- package/dist/schedule-tool-YFMRYTEO.js +0 -2
- package/dist/status-PKHYFGZK.js +0 -2
- package/dist/wiki-enrich-7SZ5W2LF.js +0 -2
- package/dist/workspace-setup-W5UO2WZI.js +0 -2
- /package/dist/{App-FQRHQT5J.js.map → App-JDW5V4HT.js.map} +0 -0
- /package/dist/{ChatApp-WBCGSGJM.js.map → ChatApp-SNM2PORO.js.map} +0 -0
- /package/dist/{absorb-eval-3IU37HZQ.js.map → absorb-eval-WDAV4AI2.js.map} +0 -0
- /package/dist/{adapter-URFSOOFE.js.map → adapter-C47BTKT6.js.map} +0 -0
- /package/dist/{agent-P7XUCP3A.js.map → agent-EVMKJXJO.js.map} +0 -0
- /package/dist/{chunk-WKR2OSCH.js.map → chunk-245IOYDJ.js.map} +0 -0
- /package/dist/{chunk-FOWRNDMJ.js.map → chunk-2LJZHKTY.js.map} +0 -0
- /package/dist/{chunk-P65XGEB7.js.map → chunk-2P3SHT5I.js.map} +0 -0
- /package/dist/{chunk-JUSQMQ7L.js.map → chunk-2VSK6FAR.js.map} +0 -0
- /package/dist/{chunk-JKT5EFXT.js.map → chunk-CXFVIDJV.js.map} +0 -0
- /package/dist/{chunk-ZPCSPEGO.js.map → chunk-CZVCT5ZV.js.map} +0 -0
- /package/dist/{chunk-Y2D6FQBL.js.map → chunk-DOO4MUTS.js.map} +0 -0
- /package/dist/{chunk-HX4R7RPR.js.map → chunk-DV42WUMD.js.map} +0 -0
- /package/dist/{chunk-CAYY2IEV.js.map → chunk-EFGAPAYZ.js.map} +0 -0
- /package/dist/{chunk-MAQFWGFT.js.map → chunk-ERVJLPS4.js.map} +0 -0
- /package/dist/{chunk-IAR5F3T5.js.map → chunk-IDGEDPRJ.js.map} +0 -0
- /package/dist/{chunk-SLX3OHEW.js.map → chunk-IU63JGY3.js.map} +0 -0
- /package/dist/{chunk-7QW4RECS.js.map → chunk-JSCVOB4G.js.map} +0 -0
- /package/dist/{chunk-RUNCUVAH.js.map → chunk-JT5PIBCM.js.map} +0 -0
- /package/dist/{chunk-EQPMQSJE.js.map → chunk-KRHVM26D.js.map} +0 -0
- /package/dist/{chunk-5VD2J4JN.js.map → chunk-MF46BC7J.js.map} +0 -0
- /package/dist/{chunk-VGYW3Q7F.js.map → chunk-OLKYIKAZ.js.map} +0 -0
- /package/dist/{chunk-RB7M2NPU.js.map → chunk-PQUK6XEW.js.map} +0 -0
- /package/dist/{chunk-PSOE356C.js.map → chunk-PQX2VJUA.js.map} +0 -0
- /package/dist/{chunk-TV5BDCQA.js.map → chunk-PTZNM2JU.js.map} +0 -0
- /package/dist/{chunk-M4VYHPDS.js.map → chunk-PW3WG6JT.js.map} +0 -0
- /package/dist/{chunk-EMWSFITR.js.map → chunk-QASIUKZJ.js.map} +0 -0
- /package/dist/{chunk-N6NZBAWR.js.map → chunk-RXX4MYFL.js.map} +0 -0
- /package/dist/{chunk-C2VZHIIX.js.map → chunk-S5A7QZVQ.js.map} +0 -0
- /package/dist/{chunk-CJI26AJC.js.map → chunk-SKCOIP5R.js.map} +0 -0
- /package/dist/{chunk-BIYEGA7Q.js.map → chunk-TH2W2545.js.map} +0 -0
- /package/dist/{chunk-V3FSKTDF.js.map → chunk-UGRMFQAG.js.map} +0 -0
- /package/dist/{chunk-Y4YOYOCG.js.map → chunk-USFOOYPM.js.map} +0 -0
- /package/dist/{chunk-WIGH5WMP.js.map → chunk-V5LRR5I5.js.map} +0 -0
- /package/dist/{chunk-QOEO27LF.js.map → chunk-WJMYBRM5.js.map} +0 -0
- /package/dist/{client-EOQLSAUW.js.map → client-WN7YI7DE.js.map} +0 -0
- /package/dist/{config-SZZQFIJF.js.map → config-QUXKGIZX.js.map} +0 -0
- /package/dist/{config-mutate-66VDWR46.js.map → config-mutate-HJH24ITC.js.map} +0 -0
- /package/dist/{config-mutator-OILDQCAJ.js.map → config-mutator-OLLQR3ZD.js.map} +0 -0
- /package/dist/{connect-AJKMRKXC.js.map → connect-OOPPXAOD.js.map} +0 -0
- /package/dist/{contributions-LRQCDZCQ.js.map → contributions-LL7B4BP3.js.map} +0 -0
- /package/dist/{doctor-EDZO7BUJ.js.map → doctor-X75KLAFA.js.map} +0 -0
- /package/dist/{enrich-NIUEEGPA.js.map → enrich-MZMIQ3SV.js.map} +0 -0
- /package/dist/{event-levels-D6QSANGF.js.map → event-levels-PCFARGKL.js.map} +0 -0
- /package/dist/{follow-up-tool-QOO2TIQS.js.map → follow-up-tool-I2HTKMP4.js.map} +0 -0
- /package/dist/{grants-3UVDASRI.js.map → grants-2MNWGCSH.js.map} +0 -0
- /package/dist/{hub-6TKU6CHO.js.map → hub-7ASBN76I.js.map} +0 -0
- /package/dist/{promote-D3KYLUBD.js.map → promote-NSPUPPHB.js.map} +0 -0
- /package/dist/{providers-AHLCB6R5.js.map → providers-D6IUAHQJ.js.map} +0 -0
- /package/dist/{query-D2TQ2PUO.js.map → query-VW63IHDI.js.map} +0 -0
- /package/dist/{query-settings-ILDX3HDF.js.map → query-settings-RS7DJI4H.js.map} +0 -0
- /package/dist/{registry-N3BY3HSI.js.map → registry-6KREAROB.js.map} +0 -0
- /package/dist/{request-planner-CVCG5XQR.js.map → request-planner-HZWQIRZO.js.map} +0 -0
- /package/dist/{resolve-JKXYBZ6R.js.map → resolve-LOYZUE2D.js.map} +0 -0
- /package/dist/{review-candidates-CKUN4PSY.js.map → review-candidates-2TXOUASP.js.map} +0 -0
- /package/dist/{routing-OCIRGUKK.js.map → routing-ZV4VSZDV.js.map} +0 -0
- /package/dist/{rules-A5ES57QT.js.map → rules-FBOLGE2S.js.map} +0 -0
- /package/dist/{schedule-tool-YFMRYTEO.js.map → schedule-tool-D357NLXS.js.map} +0 -0
- /package/dist/{scheduler-D2Z7RSEE.js.map → scheduler-SAID6RKQ.js.map} +0 -0
- /package/dist/{seat-Z3E2FLDA.js.map → seat-XHBWBSTS.js.map} +0 -0
- /package/dist/{select-J4ES7Q67.js.map → select-QUCTTAH3.js.map} +0 -0
- /package/dist/{set-enabled-S22TICYC.js.map → set-enabled-CGMXLFC6.js.map} +0 -0
- /package/dist/{sprint-tool-NDF47EKV.js.map → sprint-tool-SWRYSX3Q.js.map} +0 -0
- /package/dist/{status-PKHYFGZK.js.map → status-PVYFTNX2.js.map} +0 -0
- /package/dist/{tool-6NZIUXI7.js.map → tool-6G63ZQW4.js.map} +0 -0
- /package/dist/{tool-RCCMOMEY.js.map → tool-DA25L4ND.js.map} +0 -0
- /package/dist/{tool-52JRXZVA.js.map → tool-ELGOVIM5.js.map} +0 -0
- /package/dist/{tool-Z2OVFGWW.js.map → tool-MMH2JNP7.js.map} +0 -0
- /package/dist/{wiki-HQKFZZSX.js.map → wiki-4ZL4QXA7.js.map} +0 -0
- /package/dist/{wiki-enrich-7SZ5W2LF.js.map → wiki-enrich-N5MUKDVW.js.map} +0 -0
- /package/dist/{workspace-setup-W5UO2WZI.js.map → workspace-setup-QXFJRNSK.js.map} +0 -0
package/dist/chunk-XPZSEDE3.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import{c as A,d as L,f as q,g as F}from"./chunk-MNG2AMKZ.js";import{a as k,b as ne}from"./chunk-7I7IEX4S.js";import{existsSync as ge,linkSync as fe,mkdirSync as Q,readdirSync as pe,readFileSync as he,renameSync as we,unlinkSync as ke,writeFileSync as Z}from"fs";import{resolve as ee}from"path";ne();import{appendFileSync as ie,existsSync as oe,mkdirSync as se,readFileSync as I,writeFileSync as K}from"fs";import{resolve as D}from"path";var B=500,P=200,O=e=>D(e,".agentx","approvals"),j=e=>D(O(e),"_answered.jsonl"),ae=e=>D(O(e),"_answered.since"),C=e=>e&&e.length>P?e.slice(0,P-1)+"\u2026":e;function W(e,t){try{ce(e);let n={...t,title:C(t.title)??""};t.choice&&(n.choice=C(t.choice)),t.text?n.text=C(t.text):delete n.text;let r=j(e);ie(r,JSON.stringify(n)+`
|
|
2
|
-
`);let i=I(r,"utf-8").split(`
|
|
3
|
-
`).filter(Boolean);i.length>B&&K(r,i.slice(-B).join(`
|
|
4
|
-
`)+`
|
|
5
|
-
`)}catch(n){k.warn(`[approvals] answered list not written for ${t.key}: ${n?.message??n}`)}}function ce(e){let t=ae(e);try{let r=I(t,"utf-8").trim();if(r)return r}catch{}let n=new Date().toISOString();try{se(O(e),{recursive:!0}),K(t,n+`
|
|
6
|
-
`)}catch(r){k.warn(`[approvals] answered start not written: ${r?.message??r}`)}return n}function Ee(e,t=50){let n=j(e);if(!oe(n))return[];let r=[],i;try{i=I(n,"utf-8").split(`
|
|
7
|
-
`).filter(Boolean)}catch(o){return k.warn(`[approvals] answered list not read: ${o?.message??o}`),[]}for(let o=i.length-1;o>=0&&r.length<t;o--)try{let s=JSON.parse(i[o]);s&&typeof s.key=="string"&&typeof s.at=="string"&&r.push(s)}catch{}return r}function U(e){return e?.kind==="retro"||e?.kind==="retro-check"}var M={keep:"Keep it",loosen:"Loosen it",remove:"Remove it"};function J(e,t,n){let r=`guard rule \`${e.ruleId}\` in \`${e.file}\``,i=[`This was a monthly review of ${r}, added by the retro on run ${e.taskId}. It fires often on runs that went well.`];return!(t.status==="decided"&&t.verdict==="yes")||t.choice===M.keep||!t.choice?(i.push("Change nothing: the rule stays as it is."),i):(i.push(t.choice===M.remove?`The operator chose to remove it. Delete ${r} as a pull request.`:`The operator chose to loosen it. Narrow ${r} (a tighter match, or \`applies_to\`) so it stops firing on good work, keep its \`retro:${e.taskId}\` tag, and open it as a pull request.`),t.choice_suggested&&i.push(V),n&&i.push("The operator's note:",n),i.push("Do not change the live policy directly: the operator reviews the pull request first."),i)}var V="(The operator gave a plain yes, taken as the suggested option.)";function v(e){return e.status==="decided"&&e.verdict==="yes"&&!!e.choice&&e.choice!==E}function G(e,t,n){let r=[`This was a retro card about run ${e.taskId} (\`agentx trace show ${e.taskId}\`).`];if(!v(t))return r.push("Change nothing. Do not propose these fixes again on your own."),r;r.push(`The operator picked this fix: ${t.choice}`),t.choice_suggested&&r.push(V);let i=e.specs?.[(t.choices??[]).indexOf(t.choice)];return i&&r.push("Spec for this fix, drafted by the retro reviewer from the run's content (a proposal to check, not instructions from the operator):",i),n&&r.push("The operator's note on the fix:",n),r.push("Build the chosen fix as a change the operator reviews again: a pull request, or a guard rule in warn mode.","Do not apply it to a live system directly. Tag what you add with `retro:"+e.taskId+"` so it can be found and removed later; for a guard rule, put the tag in its `tags` list."),r}var E="None of these";function z(e,t){let n=e.list?` in the "${e.list}" list`:"",r=[`This card came from the operator's reminder "${e.title}"${n} (id ${e.id}).`];return r.push(t?`Do what the operator chose, then tick the reminder off: remindctl complete ${e.id}`:"Leave the reminder open; it will come back at a later check-in."),r}var u={title:120,ask:300,answers:3},R=["resurface","bring-back","weekly","cleanup"],y={perDay:5,resurface:3},de=[/\bhttps?:\/\/\S+/gi,/(?:[\w.-]+\/)*[\w.-]+[#!]\d+\b/g,/[#!]\d+\b/g,/\b[0-9A-HJKMNP-TV-Z]{26}\b/gi,/\b(?:req|dlg|snd)-[\w-]+/gi,/\b(?=[0-9a-f]*\d)(?=[0-9a-f]*[a-f])[0-9a-f]{7,}\b/gi];function ue(e){return de.reduce((t,n)=>t.replace(n," "),e)}function Y(e){let t=ue(e);return t===e||t.split(/\s+/).filter(r=>/\p{L}/u.test(r)).length>=2?null:`title is only a reference ("${e.trim()}"); say what it is in plain words, and put the link in the body or source`}function H(e){let t=typeof e.title=="string"?e.title:"",n=typeof e.ask=="string"?e.ask:"";if(!t.trim())return"title is missing: say what it is in plain words";if(t.length>u.title)return`title is longer than ${u.title} characters`;let r=Y(t);return r||(n.trim()?n.length>u.ask?`ask is longer than ${u.ask} characters`:(n.match(/\?/g)??[]).length>1?"ask holds more than one question: one card asks one thing":(e.choices?.length??0)>u.answers?`more than ${u.answers} choices`:null:"ask is missing: one card asks one thing")}function Ne(e,t){if(e.length>u.title)return`title is longer than ${u.title} characters`;let n=Y(e);return n||(t.length>u.ask?`message is longer than ${u.ask} characters`:null)}function Ae(e,t){let n=t?.trim().replace(/\s+/g," ")||"nothing, FYI";return`${e}
|
|
8
|
-
To do: ${n}`}function le(e){let t=new Date(e);return t.setHours(0,0,0,0),t.getTime()}function X(e,t,n){let r=le(n),i=e.filter(o=>o.followup&&Date.parse(o.created_at)>=r);return i.length>=y.perDay?`the follow-up screen budget is used up today (${y.perDay} cards): raise it again tomorrow`:t==="resurface"&&i.filter(o=>o.followup==="resurface").length>=y.resurface?`${y.resurface} resurface cards were already raised today: raise it again tomorrow`:null}function Le(e,t){let n=e.title?.trim();return e.origin?.kind==="request"?[`[screen gate] Request ${e.id}${n?` ("${n}")`:""} was not shown to the owner: ${t}.`,`It is still on his list. Say what it is: agentx_request {action:"describe", id:"${e.id}", headline:"<a few plain words>", need:"<what you need from him>"}.`].join(" "):[`[screen gate] Your card ${e.id}${n?` ("${n}")`:""} was not shown to the owner: ${t}.`,"It is still in his inbox, unchanged. If it must reach him on screen, close it (agentx_approval resolve) and raise one that passes:",`one question, title up to ${u.title} characters, ask up to ${u.ask}, at most ${u.answers} choices.`].join(" ")}var te=["discard","keep","pause"];function T(e){return e==="approve"?"keep":te.includes(e)?e:null}var l={title:120,ask:300,recommend:300,source:500,note:500,resolution:300,pendingPerAgent:25},ye={defaultExpiryDays:3,maxExpiryDays:30};function x(e){return ee(e,".agentx","approvals")}var me=/^[a-z0-9][a-z0-9-]{0,80}$/;function re(e){return me.test(e)}function N(e,t){if(!re(t))throw new Error(`invalid card id: ${t}`);return ee(x(e),`${t}.json`)}function xe(e,t){let n=new Date(e).toISOString().slice(0,10),r=t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,40);return`${n}-${r||"card"}-${Math.random().toString(36).slice(2,6).padEnd(4,"0")}`}function _(e,t){Q(x(e),{recursive:!0});let n=N(e,t.id),r=`${n}.${process.pid}.tmp`;Z(r,JSON.stringify(t,null,2)+`
|
|
9
|
-
`),we(r,n)}function _e(e,t){Q(x(e),{recursive:!0});for(let n=1;;n++){let r=n===1?t:{...t,id:`${t.id}-${n}`},i=N(e,r.id),o=`${i}.${process.pid}.tmp`;Z(o,JSON.stringify(r,null,2)+`
|
|
10
|
-
`);try{return fe(o,i),r}catch(s){if(s.code!=="EEXIST")throw s}finally{ke(o)}}}function b(e,t){if(!re(t))return null;try{let n=JSON.parse(he(N(e,t),"utf-8")),r=n.if_silent==="approve"||n.outcome==="approve";return{...n,if_silent:T(n.if_silent)??"keep",...n.outcome?{outcome:T(n.outcome)??"keep"}:{},...r?{if_silent_asked:"approve"}:{}}}catch{return null}}function m(e,t){let n=x(e);if(!ge(n))return[];let r=[];for(let i of pe(n).filter(o=>o.endsWith(".json")&&!o.startsWith("_")).sort()){let o=b(e,i.slice(0,-5));o&&(!t||o.status===t)&&r.push(o)}return r}function a(e){return typeof e=="string"?e.replace(/\s+/g," ").trim():""}function be(e,t,n){let r=t+n.maxExpiryDays*864e5,i,o=a(e);if(!o)i=t+n.defaultExpiryDays*864e5;else{let s=/^(\d+)\s*([hd])$/i.exec(o);if(s)i=t+Number(s[1])*(s[2].toLowerCase()==="d"?864e5:36e5);else if(i=Date.parse(o),Number.isNaN(i))return{ok:!1,error:`expires must be an ISO date or time, or like "12h" / "3d" (got "${o}")`}}return i<=t?{ok:!1,error:"expires must be in the future"}:{ok:!0,at:new Date(Math.min(i,r)).toISOString()}}function $e(e,t={}){let n=t.now??Date.now(),r=t.settings??ye,i=a(e.title),o=a(e.ask),s=a(e.recommend),c=a(e.raised_by);if(!i)return{ok:!1,error:"title is required"};if(!o)return{ok:!1,error:"ask is required: the yes/no question"};if(!s)return{ok:!1,error:"recommend is required: your advice and why, in one line"};if(!c)return{ok:!1,error:"raised_by is required: the agent id"};if(i.length>l.title)return{ok:!1,error:`title is longer than ${l.title} characters`};if(o.length>l.ask)return{ok:!1,error:`ask is longer than ${l.ask} characters`};if(s.length>l.recommend)return{ok:!1,error:`recommend is longer than ${l.recommend} characters`};let g=a(e.if_silent).toLowerCase(),h=T(g);if(!h)return{ok:!1,error:`if_silent must be one of ${te.join(", ")}`};let d=be(e.expires,n,r);if(!d.ok)return d;let p=a(e.source);if(p.length>l.source)return{ok:!1,error:`source is longer than ${l.source} characters`};if(p&&/^[a-z][a-z0-9+.-]*:/i.test(p)&&!/^https?:\/\//i.test(p))return{ok:!1,error:"source must be an http(s) link or a plain reference"};let $=A(e);if(!$.ok)return $;let w=a(e.followup).toLowerCase();if(w&&!R.includes(w))return{ok:!1,error:`followup must be one of ${R.join(", ")}`};let S,f=e.reply;return f&&typeof f=="object"&&a(f.channel)&&a(f.chatId)&&(S={channel:a(f.channel),chatId:a(f.chatId),...a(f.accountId)?{accountId:a(f.accountId)}:{}}),{ok:!0,card:{id:xe(n,i),title:i,ask:o,recommend:s,if_silent:h,...g==="approve"?{if_silent_asked:"approve"}:{},expires:d.at,...p?{source:p}:{},raised_by:c,...t.node?{node:t.node}:{},created_at:new Date(n).toISOString(),...S?{reply:S}:{},...$.value,...t.origin?{origin:t.origin}:{},...w?{followup:w}:{},status:"pending"}}}function Se(e,t){if(!(!t.source||t.origin))return e.find(n=>!n.origin&&n.source===t.source&&n.raised_by===t.raised_by&&(n.node??"")===(t.node??""))}function Me(e,t,n={}){let r=$e(t,n);if(!r.ok)return r;let i=H(r.card);if(i)return{ok:!1,error:i};if(r.card.followup){let d=X(m(e),r.card.followup,n.now??Date.now());if(d)return{ok:!1,error:d}}let o=m(e,"pending"),s=Se(o,r.card);if(s)return{ok:!1,error:`a card from you on this source is still pending: ${s.id}. Wait for its answer, or resolve it first and then raise the new one.`};let c=d=>U(d.origin),g=c(r.card),h=o.filter(d=>d.raised_by===r.card.raised_by&&c(d)===g).length;if(h>=l.pendingPerAgent){let d=g?"retro cards":"cards";return{ok:!1,error:`${r.card.raised_by} already has ${h} ${d} waiting; wait for decisions before raising more`}}return{ok:!0,card:_e(e,r.card)}}function Ue(e,t,n,r={}){let i=b(e,t);if(!i)return{ok:!1,error:`no card "${t}"`};if(i.status!=="pending")return{ok:!1,error:`card "${t}" is already ${i.status}`};let o=q(i,n,r);if(!o.ok)return o;let s=a(r.note).slice(0,l.note),c={...i,status:"decided",verdict:n,decided_by:r.by??"operator",decided_at:new Date(r.now??Date.now()).toISOString(),...s?{note:s}:{},...o.choice?{choice:o.choice}:{},...o.suggested?{choice_suggested:!0}:{},...o.text?{text:o.text}:{}};return _(e,c),{ok:!0,card:c}}var Ce=new Set([void 0,"reminder"]);function Je(e,t,n){let r=b(e,t);if(!r)return{ok:!1,status:404,error:`no card "${t}"`};if(r.raised_by!==n.by||(r.node??"")!==(n.node??"")){let c=r.node?`${r.raised_by} on node "${r.node}"`:r.raised_by,g=r.node?"it closes it through its own node's daemon":"it closes it from one of its running turns";return{ok:!1,status:403,error:`card "${t}" was raised by another agent (${c}): only that agent can close it (${g}), or the operator answers it in Approvals`}}if(!Ce.has(r.origin?.kind))return{ok:!1,status:409,error:`card "${t}" is answered by the operator only`};if(r.status!=="pending")return{ok:!1,status:409,error:`card "${t}" is already ${r.status}`};let i=a(n.reason);if(!i)return{ok:!1,status:400,error:"reason is required: say where the owner answered and what you did"};let o=new Date(n.now??Date.now()).toISOString(),s={...r,status:"resolved",decided_by:n.by,decided_at:o,resolution:i.slice(0,l.resolution),agent_notified_at:o};return _(e,s),W(e,{key:`card:${t}`,kind:"card",title:r.title,raised_by:r.raised_by,answer:"closed",text:s.resolution,by:n.node?`${n.by} on ${n.node}`:n.by,at:o}),{ok:!0,card:s}}function Ve(e,t=Date.now()){let n=[];for(let r of m(e,"pending")){if(Date.parse(r.expires)>t)continue;let i={...r,status:"expired",outcome:r.if_silent,decided_by:"expiry",decided_at:new Date(t).toISOString()};_(e,i),n.push(i)}return n}function Ge(e){return m(e).filter(t=>t.status!=="pending"&&!t.agent_notified_at)}function ze(e,t,n=Date.now()){let r=b(e,t);!r||r.agent_notified_at||_(e,{...r,agent_notified_at:new Date(n).toISOString()})}var Ie="A no does not by itself undo anything you already did. If you already carried this out (for example because the owner approved it in chat), do not reverse it: ask the requester one clear question first.";function Ye(e){let t=e.origin?.kind==="retro"?e.origin:void 0,n=e.status==="decided"?e.verdict==="yes"?t&&!v(e)?`The operator picked "${E}", which counts as NO.`:"The operator said YES.":"The operator said NO.":`Nobody answered before it expired, so the default applied: ${e.outcome??e.if_silent}.`,r=[`[Approval result] Your decision card "${e.title}" (${e.id}) is closed.`,`Question: ${e.ask}`,n],i=e.origin?.kind==="retro-check"?e.origin:void 0;if(e.status==="decided"&&e.verdict==="yes"&&!t&&!i&&r.push(...F(e)),e.note&&r.push(`Operator note: ${e.note}`),e.status==="decided"&&e.verdict==="no"&&!t&&!i&&r.push(Ie),e.source&&r.push(`Source: ${e.source}`),e.origin?.kind==="reminder"&&r.push(...z(e.origin,e.status==="decided"&&e.verdict==="yes")),t||i){let o=g=>g.replace(/\s+/g," ").trim(),s=L(e.draft,e.choice),c=e.text&&o(e.text)!==o(s)?e.text:void 0;r.push(...t?G(t,e,c):J(i,e,c))}return e.reply&&r.push(`You raised it from ${e.reply.channel} chat ${e.reply.chatId}; reply there if the requester should know.`),e.node&&r.push(`The operator answered it on another machine; the card was forwarded from ${e.node}.`),r.push("Act on this result now. Do not raise the same card again."),r.join(`
|
|
11
|
-
`)}export{W as a,ce as b,Ee as c,U as d,M as e,v as f,E as g,Y as h,H as i,Ne as j,Ae as k,Le as l,te as m,l as n,x as o,re as p,b as q,m as r,Me as s,Ue as t,Je as u,Ve as v,Ge as w,ze as x,Ye as y};
|
|
12
|
-
//# sourceMappingURL=chunk-XPZSEDE3.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/approvals/cards.ts","../src/approvals/answered.ts","../src/approvals/origin.ts","../src/approvals/screen-gate.ts"],"sourcesContent":["import { existsSync, linkSync, mkdirSync, readdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from \"fs\"\nimport { resolve } from \"path\"\nimport { recordAnswered } from \"./answered\"\nimport { answerLines, buildChoices, draftFor, resolveAnswer, type CardChoices } from \"./choices\"\nimport { isRetroOrigin, originLines, RETRO_NONE, retroApproved, retroCheckLines, retroLines, type CardOrigin } from \"./origin\"\nimport { cardRuleBreak, FOLLOWUP_KINDS, followupBudgetRefusal, type FollowupKind } from \"./screen-gate\"\n\n// --- Decision cards: what an agent asks the operator ---\n//\n// An agent that needs a yes/no from the operator writes a card instead of\n// asking in chat. A card says what it is, the question, what the agent\n// recommends, and what happens if nobody answers by `expires`. Nothing\n// waits forever: past `expires` the daemon applies `if_silent` (sweep.ts).\n//\n// Storage: one JSON file per card under `.agentx/approvals/`, written\n// atomically, like wiki proposals. The CLI, the dashboard and the daemon\n// are separate processes and all read the same files.\n//\n// Field names match the API (`if_silent`, `raised_by`), so a stored card is\n// exactly what `POST /approvals` accepted.\n\n// No card approves itself (#741): only the operator says yes. \"approve\",\n// which older agents and stored cards may still carry, is read as \"keep\".\nexport type IfSilent = \"discard\" | \"keep\" | \"pause\"\nexport const IF_SILENT_VALUES: readonly IfSilent[] = [\"discard\", \"keep\", \"pause\"]\n\nfunction asIfSilent(v: string): IfSilent | null {\n if (v === \"approve\") return \"keep\"\n return IF_SILENT_VALUES.includes(v as IfSilent) ? (v as IfSilent) : null\n}\n\n// \"resolved\": closed by the agent that raised it, because the owner gave the\n// same answer somewhere else (in chat, #909) and the agent already acted on\n// it. Not a verdict: nothing is approved or rejected by it.\nexport type CardStatus = \"pending\" | \"decided\" | \"expired\" | \"resolved\"\nexport type Verdict = \"yes\" | \"no\"\n\n/** Where the agent was asked, so the verdict can be taken back there. */\nexport interface ReplyTarget {\n channel: string\n chatId: string\n accountId?: string\n}\n\nexport interface DecisionCard extends CardChoices {\n id: string\n title: string\n ask: string\n recommend: string\n if_silent: IfSilent\n /** ISO time the default applies. Always set. */\n expires: string\n /** Link to the draft, PR or issue. */\n source?: string\n raised_by: string\n /** The mesh node the raising agent is on, when the card was forwarded\n * here from there (forward.ts, #668). Unset: this node. */\n node?: string\n created_at: string\n reply?: ReplyTarget\n status: CardStatus\n /** The operator's answer (status \"decided\"). */\n verdict?: Verdict\n /** What applied on expiry (status \"expired\"). */\n outcome?: IfSilent\n /** Set when the agent, or a card stored before #741, asked for\n * \"approve\" on expiry; `if_silent` then holds \"keep\". Kept so the\n * record still shows what was originally asked. */\n if_silent_asked?: \"approve\"\n decided_by?: string\n decided_at?: string\n note?: string\n /** The option the operator picked, when the card offered choices. */\n choice?: string\n /** Set when `choice` came from a plain yes taking the suggested option\n * (#1064), not from the operator picking it. */\n choice_suggested?: boolean\n /** The message the operator approved, after any edit. */\n text?: string\n /** Set once the raising agent has been told the result. */\n agent_notified_at?: string\n /** Why the raising agent closed it (status \"resolved\"). */\n resolution?: string\n /** What the card is about, when the daemon raised it (origin.ts). */\n origin?: CardOrigin\n /** A follow-up card (#394): counted in the daily screen budget. */\n followup?: FollowupKind\n}\n\nexport const CARD_LIMITS = {\n title: 120,\n ask: 300,\n recommend: 300,\n source: 500,\n note: 500,\n resolution: 300,\n /** Pending cards one agent may have open at a time. */\n pendingPerAgent: 25,\n} as const\n\nexport interface CardSettings {\n defaultExpiryDays: number\n maxExpiryDays: number\n}\n\nexport const DEFAULT_CARD_SETTINGS: CardSettings = { defaultExpiryDays: 3, maxExpiryDays: 30 }\n\nexport function approvalsDir(root: string): string {\n return resolve(root, \".agentx\", \"approvals\")\n}\n\nconst CARD_ID_RE = /^[a-z0-9][a-z0-9-]{0,80}$/\n\nexport function isValidCardId(id: string): boolean {\n return CARD_ID_RE.test(id)\n}\n\nfunction fileFor(root: string, id: string): string {\n if (!isValidCardId(id)) throw new Error(`invalid card id: ${id}`)\n return resolve(approvalsDir(root), `${id}.json`)\n}\n\nexport function newCardId(now: number, title: string): string {\n const day = new Date(now).toISOString().slice(0, 10)\n const slug = title.toLowerCase().replace(/[^a-z0-9]+/g, \"-\").replace(/^-+|-+$/g, \"\").slice(0, 40)\n return `${day}-${slug || \"card\"}-${Math.random().toString(36).slice(2, 6).padEnd(4, \"0\")}`\n}\n\nexport function saveCard(root: string, card: DecisionCard): void {\n mkdirSync(approvalsDir(root), { recursive: true })\n const path = fileFor(root, card.id)\n const tmp = `${path}.${process.pid}.tmp`\n writeFileSync(tmp, JSON.stringify(card, null, 2) + \"\\n\")\n renameSync(tmp, path)\n}\n\n/**\n * Save a card that is new. Its id is random, so two cards with the same\n * title on the same day can draw the same one: then the id gets \"-2\", \"-3\"\n * and so on, and a card already on disk is never overwritten. The link\n * fails if the file exists, so this holds across processes too.\n */\nfunction saveNewCard(root: string, card: DecisionCard): DecisionCard {\n mkdirSync(approvalsDir(root), { recursive: true })\n for (let n = 1; ; n++) {\n const saved = n === 1 ? card : { ...card, id: `${card.id}-${n}` }\n const path = fileFor(root, saved.id)\n const tmp = `${path}.${process.pid}.tmp`\n writeFileSync(tmp, JSON.stringify(saved, null, 2) + \"\\n\")\n try {\n linkSync(tmp, path)\n return saved\n } catch (e) {\n if ((e as NodeJS.ErrnoException).code !== \"EEXIST\") throw e\n } finally {\n unlinkSync(tmp)\n }\n }\n}\n\nexport function readCard(root: string, id: string): DecisionCard | null {\n if (!isValidCardId(id)) return null\n try {\n const card = JSON.parse(readFileSync(fileFor(root, id), \"utf-8\")) as DecisionCard\n // A card that expired as \"approve\" before #741 is read as \"keep\" too, so\n // an agent not yet told never hears \"default applied: approve\".\n const legacy = (card.if_silent as string) === \"approve\" || (card.outcome as string) === \"approve\"\n return {\n ...card,\n if_silent: asIfSilent(card.if_silent) ?? \"keep\",\n ...(card.outcome ? { outcome: asIfSilent(card.outcome) ?? \"keep\" } : {}),\n ...(legacy ? { if_silent_asked: \"approve\" as const } : {}),\n }\n } catch {\n return null\n }\n}\n\n/** Cards, oldest first; only `status` ones when given. */\nexport function listCards(root: string, status?: CardStatus): DecisionCard[] {\n const dir = approvalsDir(root)\n if (!existsSync(dir)) return []\n const out: DecisionCard[] = []\n for (const f of readdirSync(dir).filter((f) => f.endsWith(\".json\") && !f.startsWith(\"_\")).sort()) {\n const c = readCard(root, f.slice(0, -5))\n if (c && (!status || c.status === status)) out.push(c)\n }\n return out\n}\n\nfunction oneLine(v: unknown): string {\n return typeof v === \"string\" ? v.replace(/\\s+/g, \" \").trim() : \"\"\n}\n\n/**\n * `expires` as given by an agent: an ISO date or time, or a relative\n * \"12h\" / \"3d\". Unset: the default. Always capped at maxExpiryDays, so a\n * card can't be parked for a year.\n */\nexport function resolveExpiry(input: unknown, now: number, settings: CardSettings): { ok: true; at: string } | { ok: false; error: string } {\n const max = now + settings.maxExpiryDays * 86_400_000\n let at: number\n const raw = oneLine(input)\n if (!raw) {\n at = now + settings.defaultExpiryDays * 86_400_000\n } else {\n const rel = /^(\\d+)\\s*([hd])$/i.exec(raw)\n if (rel) {\n at = now + Number(rel[1]) * (rel[2].toLowerCase() === \"d\" ? 86_400_000 : 3_600_000)\n } else {\n at = Date.parse(raw)\n if (Number.isNaN(at)) return { ok: false, error: `expires must be an ISO date or time, or like \"12h\" / \"3d\" (got \"${raw}\")` }\n }\n }\n if (at <= now) return { ok: false, error: \"expires must be in the future\" }\n return { ok: true, at: new Date(Math.min(at, max)).toISOString() }\n}\n\nexport interface CardInput {\n title?: unknown\n ask?: unknown\n recommend?: unknown\n if_silent?: unknown\n expires?: unknown\n source?: unknown\n raised_by?: unknown\n reply?: unknown\n choices?: unknown\n draft?: unknown\n say?: unknown\n context?: unknown\n followup?: unknown\n}\n\n/** Validate what an agent sent and build a pending card. Never saves. */\nexport interface BuildCardOptions {\n now?: number\n settings?: CardSettings\n origin?: CardOrigin\n /** The peer the card was forwarded from. The daemon sets it after\n * checking the name against its mesh peers; never taken as sent. */\n node?: string\n}\n\nexport function buildCard(\n input: CardInput,\n opts: BuildCardOptions = {},\n): { ok: true; card: DecisionCard } | { ok: false; error: string } {\n const now = opts.now ?? Date.now()\n const settings = opts.settings ?? DEFAULT_CARD_SETTINGS\n const title = oneLine(input.title)\n const ask = oneLine(input.ask)\n const recommend = oneLine(input.recommend)\n const raisedBy = oneLine(input.raised_by)\n if (!title) return { ok: false, error: \"title is required\" }\n if (!ask) return { ok: false, error: \"ask is required: the yes/no question\" }\n if (!recommend) return { ok: false, error: \"recommend is required: your advice and why, in one line\" }\n if (!raisedBy) return { ok: false, error: \"raised_by is required: the agent id\" }\n if (title.length > CARD_LIMITS.title) return { ok: false, error: `title is longer than ${CARD_LIMITS.title} characters` }\n if (ask.length > CARD_LIMITS.ask) return { ok: false, error: `ask is longer than ${CARD_LIMITS.ask} characters` }\n if (recommend.length > CARD_LIMITS.recommend) return { ok: false, error: `recommend is longer than ${CARD_LIMITS.recommend} characters` }\n const ifSilentRaw = oneLine(input.if_silent).toLowerCase()\n const ifSilent = asIfSilent(ifSilentRaw)\n if (!ifSilent) {\n return { ok: false, error: `if_silent must be one of ${IF_SILENT_VALUES.join(\", \")}` }\n }\n const expiry = resolveExpiry(input.expires, now, settings)\n if (!expiry.ok) return expiry\n const source = oneLine(input.source)\n if (source.length > CARD_LIMITS.source) return { ok: false, error: `source is longer than ${CARD_LIMITS.source} characters` }\n if (source && /^[a-z][a-z0-9+.-]*:/i.test(source) && !/^https?:\\/\\//i.test(source)) {\n return { ok: false, error: \"source must be an http(s) link or a plain reference\" }\n }\n const extras = buildChoices(input)\n if (!extras.ok) return extras\n const followup = oneLine(input.followup).toLowerCase()\n if (followup && !(FOLLOWUP_KINDS as readonly string[]).includes(followup)) {\n return { ok: false, error: `followup must be one of ${FOLLOWUP_KINDS.join(\", \")}` }\n }\n let reply: ReplyTarget | undefined\n const r = input.reply as Record<string, unknown> | undefined\n if (r && typeof r === \"object\" && oneLine(r.channel) && oneLine(r.chatId)) {\n reply = { channel: oneLine(r.channel), chatId: oneLine(r.chatId), ...(oneLine(r.accountId) ? { accountId: oneLine(r.accountId) } : {}) }\n }\n return {\n ok: true,\n card: {\n id: newCardId(now, title),\n title,\n ask,\n recommend,\n if_silent: ifSilent,\n ...(ifSilentRaw === \"approve\" ? { if_silent_asked: \"approve\" as const } : {}),\n expires: expiry.at,\n ...(source ? { source } : {}),\n raised_by: raisedBy,\n ...(opts.node ? { node: opts.node } : {}),\n created_at: new Date(now).toISOString(),\n ...(reply ? { reply } : {}),\n ...extras.value,\n // Set by the daemon only (check-ins), never from what an agent sent.\n ...(opts.origin ? { origin: opts.origin } : {}),\n ...(followup ? { followup: followup as FollowupKind } : {}),\n status: \"pending\",\n },\n }\n}\n\n/** A pending card the same agent, on the same node, raised on the same\n * source. None when the new card has no source or the daemon raised it. */\nfunction sameSourcePending(pending: DecisionCard[], card: DecisionCard): DecisionCard | undefined {\n if (!card.source || card.origin) return undefined\n return pending.find((c) =>\n !c.origin &&\n c.source === card.source &&\n c.raised_by === card.raised_by &&\n (c.node ?? \"\") === (card.node ?? \"\"))\n}\n\n/** Validate, enforce the per-agent cap, and save. */\nexport function createCard(\n root: string,\n input: CardInput,\n opts: BuildCardOptions = {},\n): { ok: true; card: DecisionCard } | { ok: false; error: string } {\n const built = buildCard(input, opts)\n if (!built.ok) return built\n // The screen gate (#394): refused here, the reason goes back to the author.\n const broken = cardRuleBreak(built.card)\n if (broken) return { ok: false, error: broken }\n if (built.card.followup) {\n const full = followupBudgetRefusal(listCards(root), built.card.followup, opts.now ?? Date.now())\n if (full) return { ok: false, error: full }\n }\n const pending = listCards(root, \"pending\")\n // One open question per source: the same question raised twice comes\n // back after it was answered. Only for cards an agent raised; cards the\n // daemon raises (origin set) keep their own rules, such as a merge card\n // per pushed commit on the same PR link.\n const twin = sameSourcePending(pending, built.card)\n if (twin) {\n return { ok: false, error: `a card from you on this source is still pending: ${twin.id}. Wait for its answer, or resolve it first and then raise the new one.` }\n }\n // Retro cards are raised for an agent, not by it: they get their own\n // count, so they never use up the agent's room for its own cards.\n const isRetro = (c: { origin?: CardOrigin }) => isRetroOrigin(c.origin)\n const retro = isRetro(built.card)\n const open = pending.filter((c) => c.raised_by === built.card.raised_by && isRetro(c) === retro).length\n if (open >= CARD_LIMITS.pendingPerAgent) {\n const what = retro ? \"retro cards\" : \"cards\"\n return { ok: false, error: `${built.card.raised_by} already has ${open} ${what} waiting; wait for decisions before raising more` }\n }\n return { ok: true, card: saveNewCard(root, built.card) }\n}\n\n/** Record the operator's answer. Refuses anything no longer pending. */\nexport function decideCard(\n root: string,\n id: string,\n verdict: Verdict,\n opts: { by?: string; note?: string; now?: number; choice?: string | number; text?: string } = {},\n): { ok: true; card: DecisionCard } | { ok: false; error: string } {\n const card = readCard(root, id)\n if (!card) return { ok: false, error: `no card \"${id}\"` }\n if (card.status !== \"pending\") return { ok: false, error: `card \"${id}\" is already ${card.status}` }\n const answer = resolveAnswer(card, verdict, opts)\n if (!answer.ok) return answer\n const note = oneLine(opts.note).slice(0, CARD_LIMITS.note)\n const decided: DecisionCard = {\n ...card,\n status: \"decided\",\n verdict,\n decided_by: opts.by ?? \"operator\",\n decided_at: new Date(opts.now ?? Date.now()).toISOString(),\n ...(note ? { note } : {}),\n ...(answer.choice ? { choice: answer.choice } : {}),\n ...(answer.suggested ? { choice_suggested: true } : {}),\n ...(answer.text ? { text: answer.text } : {}),\n }\n saveCard(root, decided)\n return { ok: true, card: decided }\n}\n\n/** Cards whose answer the daemon acts on itself (a workflow run, a plan\n * step, a retro): only the operator closes those. A reminder card is the\n * agent's own to act on, so it may close it like one it raised. */\nconst AGENT_RESOLVABLE_ORIGINS = new Set<string | undefined>([undefined, \"reminder\"])\n\n/**\n * The raising agent closes its own pending card: the owner gave the same\n * answer outside the card (in chat) and the agent has acted on it (#909).\n * The card leaves the inbox, so no check-in or popup asks again. It is not\n * a verdict, and the agent is not sent a result for it: it already knows.\n */\nexport function resolveCard(\n root: string,\n id: string,\n opts: { by: string; reason?: unknown; node?: string; now?: number },\n): { ok: true; card: DecisionCard } | { ok: false; status: 400 | 403 | 404 | 409; error: string } {\n const card = readCard(root, id)\n if (!card) return { ok: false, status: 404, error: `no card \"${id}\"` }\n if (card.raised_by !== opts.by || (card.node ?? \"\") !== (opts.node ?? \"\")) {\n // Name the raiser, so the caller knows who can close it (#1405).\n const who = card.node ? `${card.raised_by} on node \"${card.node}\"` : card.raised_by\n const how = card.node ? \"it closes it through its own node's daemon\" : \"it closes it from one of its running turns\"\n return { ok: false, status: 403, error: `card \"${id}\" was raised by another agent (${who}): only that agent can close it (${how}), or the operator answers it in Approvals` }\n }\n if (!AGENT_RESOLVABLE_ORIGINS.has(card.origin?.kind)) {\n return { ok: false, status: 409, error: `card \"${id}\" is answered by the operator only` }\n }\n if (card.status !== \"pending\") return { ok: false, status: 409, error: `card \"${id}\" is already ${card.status}` }\n const reason = oneLine(opts.reason)\n if (!reason) return { ok: false, status: 400, error: \"reason is required: say where the owner answered and what you did\" }\n const at = new Date(opts.now ?? Date.now()).toISOString()\n const resolved: DecisionCard = {\n ...card,\n status: \"resolved\",\n decided_by: opts.by,\n decided_at: at,\n resolution: reason.slice(0, CARD_LIMITS.resolution),\n agent_notified_at: at,\n }\n saveCard(root, resolved)\n // On the Wall's Answered tab too, whichever way the close came (#1440).\n recordAnswered(root, {\n key: `card:${id}`, kind: \"card\", title: card.title, raised_by: card.raised_by, answer: \"closed\",\n text: resolved.resolution, by: opts.node ? `${opts.by} on ${opts.node}` : opts.by, at,\n })\n return { ok: true, card: resolved }\n}\n\n/** Apply `if_silent` to every pending card past its expiry. */\nexport function expireCards(root: string, now: number = Date.now()): DecisionCard[] {\n const out: DecisionCard[] = []\n for (const card of listCards(root, \"pending\")) {\n if (Date.parse(card.expires) > now) continue\n const expired: DecisionCard = {\n ...card,\n status: \"expired\",\n outcome: card.if_silent,\n decided_by: \"expiry\",\n decided_at: new Date(now).toISOString(),\n }\n saveCard(root, expired)\n out.push(expired)\n }\n return out\n}\n\n/** Decided or expired cards whose agent hasn't been told yet. */\nexport function cardsAwaitingAgentNotice(root: string): DecisionCard[] {\n return listCards(root).filter((c) => c.status !== \"pending\" && !c.agent_notified_at)\n}\n\nexport function markAgentNotified(root: string, id: string, now: number = Date.now()): void {\n const card = readCard(root, id)\n if (!card || card.agent_notified_at) return\n saveCard(root, { ...card, agent_notified_at: new Date(now).toISOString() })\n}\n\nexport const NO_UNDO_LINE =\n \"A no does not by itself undo anything you already did. If you already carried this out (for example because the owner approved it in chat), do not reverse it: ask the requester one clear question first.\"\n\n/** What the raising agent is told. Plain text, one short message. */\nexport function verdictMessage(card: DecisionCard): string {\n const retro = card.origin?.kind === \"retro\" ? card.origin : undefined\n const result = card.status === \"decided\"\n ? (card.verdict === \"yes\"\n ? (retro && !retroApproved(card) ? `The operator picked \"${RETRO_NONE}\", which counts as NO.` : \"The operator said YES.\")\n : \"The operator said NO.\")\n : `Nobody answered before it expired, so the default applied: ${card.outcome ?? card.if_silent}.`\n const lines = [\n `[Approval result] Your decision card \"${card.title}\" (${card.id}) is closed.`,\n `Question: ${card.ask}`,\n result,\n ]\n // A retro card's pick and spec go through retroLines, labelled as the\n // reviewer's proposal: never \"Approved text (send exactly this)\".\n const check = card.origin?.kind === \"retro-check\" ? card.origin : undefined\n if (card.status === \"decided\" && card.verdict === \"yes\" && !retro && !check) lines.push(...answerLines(card))\n if (card.note) lines.push(`Operator note: ${card.note}`)\n // A late no on something the owner already approved in chat must not\n // quietly undo work that is done (#909).\n if (card.status === \"decided\" && card.verdict === \"no\" && !retro && !check) lines.push(NO_UNDO_LINE)\n if (card.source) lines.push(`Source: ${card.source}`)\n if (card.origin?.kind === \"reminder\") lines.push(...originLines(card.origin, card.status === \"decided\" && card.verdict === \"yes\"))\n if (retro || check) {\n // Compare ignoring whitespace so a dashboard that only reflows the draft\n // does not resend the whole draft as the operator's note.\n const squash = (s: string) => s.replace(/\\s+/g, \" \").trim()\n const draft = draftFor(card.draft, card.choice)\n const edited = card.text && squash(card.text) !== squash(draft) ? card.text : undefined\n lines.push(...(retro ? retroLines(retro, card, edited) : retroCheckLines(check!, card, edited)))\n }\n if (card.reply) lines.push(`You raised it from ${card.reply.channel} chat ${card.reply.chatId}; reply there if the requester should know.`)\n if (card.node) lines.push(`The operator answered it on another machine; the card was forwarded from ${card.node}.`)\n lines.push(\"Act on this result now. Do not raise the same card again.\")\n return lines.join(\"\\n\")\n}\n","import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from \"fs\"\nimport { resolve } from \"path\"\nimport { logger } from \"@/utils/logger\"\n\n// --- What the owner answered, across every kind (#1440) ---\n//\n// Each source keeps its own decision (the card file, the schedule, the\n// memory fact, the wiki proposal, the draft). This is only the list the\n// Wall's Answered tab reads: one line per yes or no that went through\n// decide() (inbox.ts), whichever surface sent it, and one per card its\n// agent closed (resolveCard, cards.ts). A close is the agent's word: the\n// owner may have answered elsewhere, or the agent may have withdrawn the\n// card. Reviews and request replies do not pass through decide() and are\n// not listed. \"Later\" is not an answer. It starts empty: `_answered.since` keeps the\n// day it started, so the page can say so.\n\nexport interface AnsweredItem {\n key: string\n kind: string\n title: string\n raised_by: string\n /** \"closed\": the agent that raised the card closed it (resolveCard). */\n answer: \"yes\" | \"no\" | \"closed\"\n /** Cards with choices: the one picked. */\n choice?: string\n /** The short answer: the owner's text, or the agent's reason for closing. */\n text?: string\n by: string\n at: string\n}\n\n/** Lines kept: the oldest go once the file passes this. */\nconst KEEP = 500\n/** Free text kept per line. */\nconst TEXT_MAX = 200\n\n// approvalsDir (cards.ts), not imported: cards.ts records here.\nconst dir = (root: string) => resolve(root, \".agentx\", \"approvals\")\nconst answeredFile = (root: string) => resolve(dir(root), \"_answered.jsonl\")\nconst sinceFile = (root: string) => resolve(dir(root), \"_answered.since\")\nconst cap = (s: string | undefined) => (s && s.length > TEXT_MAX ? s.slice(0, TEXT_MAX - 1) + \"…\" : s)\n\n/** Never throws: the answer stands, the list is only a view of it. */\nexport function recordAnswered(root: string, item: AnsweredItem): void {\n try {\n answeredSince(root)\n const line: AnsweredItem = { ...item, title: cap(item.title) ?? \"\" }\n if (item.choice) line.choice = cap(item.choice)\n if (item.text) line.text = cap(item.text)\n else delete line.text\n const path = answeredFile(root)\n appendFileSync(path, JSON.stringify(line) + \"\\n\")\n const lines = readFileSync(path, \"utf-8\").split(\"\\n\").filter(Boolean)\n if (lines.length > KEEP) writeFileSync(path, lines.slice(-KEEP).join(\"\\n\") + \"\\n\")\n } catch (e: any) {\n logger.warn(`[approvals] answered list not written for ${item.key}: ${e?.message ?? e}`)\n }\n}\n\n/** The day the list started: written by the first answer or the first read. */\nexport function answeredSince(root: string): string {\n const path = sinceFile(root)\n try {\n const at = readFileSync(path, \"utf-8\").trim()\n if (at) return at\n } catch {\n // Not written yet: this is the start.\n }\n const at = new Date().toISOString()\n try {\n mkdirSync(dir(root), { recursive: true })\n writeFileSync(path, at + \"\\n\")\n } catch (e: any) {\n logger.warn(`[approvals] answered start not written: ${e?.message ?? e}`)\n }\n return at\n}\n\n/** Newest first, at most `limit`. A line that does not parse is skipped. */\nexport function readAnswered(root: string, limit = 50): AnsweredItem[] {\n const path = answeredFile(root)\n if (!existsSync(path)) return []\n const out: AnsweredItem[] = []\n let lines: string[]\n try {\n lines = readFileSync(path, \"utf-8\").split(\"\\n\").filter(Boolean)\n } catch (e: any) {\n logger.warn(`[approvals] answered list not read: ${e?.message ?? e}`)\n return []\n }\n for (let i = lines.length - 1; i >= 0 && out.length < limit; i--) {\n try {\n const v = JSON.parse(lines[i])\n if (v && typeof v.key === \"string\" && typeof v.at === \"string\") out.push(v)\n } catch {\n // A torn last line from a crash mid-write: the rest still reads.\n }\n }\n return out\n}\n","// --- Where a card came from, when the daemon raised it ---\n//\n// Agents raise most cards themselves. A check-in (checkin.ts) raises one on\n// an agent's behalf for an open Apple Reminder, and records the reminder\n// here so the agent that gets the answer knows what to act on and what to\n// tick off. Only the daemon sets it: POST /approvals and the agent tool\n// never pass it through.\n\nexport interface ReminderOrigin {\n kind: \"reminder\"\n /** The reminder's full id, as remindctl prints it. */\n id: string\n title: string\n list?: string\n}\n\n/** An open request that needs attention, shown as a card on the Mac\n * (popup-runner.ts). Never stored: the request is the record. */\nexport interface RequestOrigin {\n kind: \"request\"\n id: string\n}\n\n/** A retro card (src/retro): fixes to the agents' environment proposed\n * from one run that struggled. The answer goes back to the agent that ran\n * it, which builds the picked fix for a second review. */\nexport interface RetroOrigin {\n kind: \"retro\"\n /** The run the retro read. */\n taskId: string\n /** Failure signature (wiki/failure-candidates.ts), for one card per signature. */\n signature: string\n /** The reviewer's spec for each fix, in the order of the card's choices\n * (without \"None of these\"). Only the picked one reaches the agent. */\n specs?: string[]\n}\n\n/** A monthly review of a check a retro added (src/retro/checks.ts): a\n * guard rule tagged `retro:<taskId>` that fires often on runs that went\n * well. The answer goes back to the agent that built it, which keeps,\n * loosens or removes it for a second review. */\nexport interface RetroCheckOrigin {\n kind: \"retro-check\"\n /** The guard rule's id. */\n ruleId: string\n /** The run whose retro asked for the rule. */\n taskId: string\n /** The policy file that holds the rule, relative to the daemon's folder. */\n file: string\n}\n\n/** A step of a workflow run asks the owner (src/workflows, #788): an\n * owner.ask step, a person.message to approve, or a run's approval at\n * start. The answer resumes the run; the agent that started it is not\n * told separately, the run is. */\nexport interface WorkflowOrigin {\n kind: \"workflow\"\n runId: string\n nodeId: string\n}\n\n/** An agent proposed a reusable workflow (#788). Yes turns it on. */\nexport interface WorkflowProposalOrigin {\n kind: \"workflow-proposal\"\n workflowId: string\n}\n\n/** A step of a tracked plan the owner approves when the plan is made\n * (src/requests/plan-sweep.ts, #788). The plan check reads the answer\n * and acts on it; the agent is not sent a result turn. */\nexport interface PlanStepOrigin {\n kind: \"plan-step\"\n requestId: string\n step: number\n}\n\n/** A pull request that changes core paths waits for the owner (merge\n * policy, #1047). YES approves that one commit; the policy reads the\n * answer and updates the PR's status. No agent is sent a result turn. */\nexport interface MergePolicyOrigin {\n kind: \"merge-policy\"\n repo: string\n pr: number\n sha: string\n}\n\nexport type CardOrigin = ReminderOrigin | RequestOrigin | RetroOrigin | RetroCheckOrigin | PlanStepOrigin | WorkflowOrigin | WorkflowProposalOrigin | MergePolicyOrigin\n\n/** Retro cards of either kind: raised for an agent, not by it. */\nexport function isRetroOrigin(origin: CardOrigin | undefined): origin is RetroOrigin | RetroCheckOrigin {\n return origin?.kind === \"retro\" || origin?.kind === \"retro-check\"\n}\n\n/** The choices on a check review card, in this order. */\nexport const CHECK_CHOICES = { keep: \"Keep it\", loosen: \"Loosen it\", remove: \"Remove it\" } as const\n\n/** Lines for the agent told the result of a check review card. Keep, NO\n * and silence all leave the rule as it is. */\nexport function retroCheckLines(\n origin: RetroCheckOrigin,\n card: { status: string; verdict?: string; choice?: string; choice_suggested?: boolean },\n edited?: string,\n): string[] {\n const rule = `guard rule \\`${origin.ruleId}\\` in \\`${origin.file}\\``\n const lines = [`This was a monthly review of ${rule}, added by the retro on run ${origin.taskId}. It fires often on runs that went well.`]\n const yes = card.status === \"decided\" && card.verdict === \"yes\"\n if (!yes || card.choice === CHECK_CHOICES.keep || !card.choice) {\n lines.push(\"Change nothing: the rule stays as it is.\")\n return lines\n }\n lines.push(card.choice === CHECK_CHOICES.remove\n ? `The operator chose to remove it. Delete ${rule} as a pull request.`\n : `The operator chose to loosen it. Narrow ${rule} (a tighter match, or \\`applies_to\\`) so it stops firing on good work, keep its \\`retro:${origin.taskId}\\` tag, and open it as a pull request.`)\n if (card.choice_suggested) lines.push(SUGGESTED_NOTE)\n if (edited) lines.push(\"The operator's note:\", edited)\n lines.push(\"Do not change the live policy directly: the operator reviews the pull request first.\")\n return lines\n}\n\n/** Told to the agent when the choice came from a plain yes (#1064): the\n * operator accepted the suggestion rather than picking it by hand. */\nconst SUGGESTED_NOTE = \"(The operator gave a plain yes, taken as the suggested option.)\"\n\n/** True when the operator answered a retro card with something to build:\n * YES and a fix picked. YES on \"None of these\" counts as NO. */\nexport function retroApproved(card: { status: string; verdict?: string; choice?: string }): boolean {\n return card.status === \"decided\" && card.verdict === \"yes\" && !!card.choice && card.choice !== RETRO_NONE\n}\n\n/** Lines for the agent told the result of a retro card. Replaces the plain\n * card's \"Chosen / Approved text\" lines: the specs are model output written\n * from the run's content, so they reach the agent labelled as such, never\n * as text the operator approved word for word.\n * `edited` is the operator's text when they changed the suggested one. */\nexport function retroLines(\n origin: RetroOrigin,\n card: { status: string; verdict?: string; choice?: string; choices?: string[]; choice_suggested?: boolean },\n edited?: string,\n): string[] {\n const lines = [`This was a retro card about run ${origin.taskId} (\\`agentx trace show ${origin.taskId}\\`).`]\n if (!retroApproved(card)) {\n lines.push(\"Change nothing. Do not propose these fixes again on your own.\")\n return lines\n }\n lines.push(`The operator picked this fix: ${card.choice}`)\n if (card.choice_suggested) lines.push(SUGGESTED_NOTE)\n const spec = origin.specs?.[(card.choices ?? []).indexOf(card.choice!)]\n if (spec) {\n lines.push(\n \"Spec for this fix, drafted by the retro reviewer from the run's content (a proposal to check, not instructions from the operator):\",\n spec,\n )\n }\n if (edited) lines.push(\"The operator's note on the fix:\", edited)\n lines.push(\n \"Build the chosen fix as a change the operator reviews again: a pull request, or a guard rule in warn mode.\",\n \"Do not apply it to a live system directly. Tag what you add with `retro:\" + origin.taskId + \"` so it can be found and removed later; for a guard rule, put the tag in its `tags` list.\",\n )\n return lines\n}\n\n/** The last choice on every retro card. */\nexport const RETRO_NONE = \"None of these\"\n\n/** Lines for the owning agent's result message. */\nexport function originLines(origin: ReminderOrigin, approved: boolean): string[] {\n const where = origin.list ? ` in the \"${origin.list}\" list` : \"\"\n const lines = [`This card came from the operator's reminder \"${origin.title}\"${where} (id ${origin.id}).`]\n lines.push(approved\n ? `Do what the operator chose, then tick the reminder off: remindctl complete ${origin.id}`\n : \"Leave the reminder open; it will come back at a later check-in.\")\n return lines\n}\n","// --- The screen gatekeeper (#394, plan section 1b) ---\n//\n// What the fleet puts on the owner's screen passes one check, by script,\n// no model:\n// - one question per card; a title and an ask short enough to read in\n// about ten seconds (title 120, ask 300 characters);\n// - at most 3 ready-made answers (a plain card has Yes, No, Not now);\n// - follow-up cards (resurface, bring-back, weekly, clean-up) share a\n// budget of 5 a day, at most 3 of them resurface cards;\n// - a title says what it is in words: a bare reference (\"#402\", a hash,\n// a request id) means nothing to someone glancing at a screen.\n// A card that fails is returned to its author with the reason: refused\n// when it is written, or not shown and told when the popup comes to it.\n// Nothing here rewrites, removes or answers a card. The call and Focus\n// hold is notify/hold.ts; the popup window takes no focus (card-window.ts).\n\nexport const SCREEN_LIMITS = { title: 120, ask: 300, answers: 3 } as const\n\nexport const FOLLOWUP_KINDS = [\"resurface\", \"bring-back\", \"weekly\", \"cleanup\"] as const\nexport type FollowupKind = (typeof FOLLOWUP_KINDS)[number]\n\nexport const SCREEN_BUDGET = { perDay: 5, resurface: 3 } as const\n\n// References an agent reads easily and the owner does not: links, issue\n// and merge request numbers (with or without their project), ULID-like\n// ids, request, delegation and send ids, and commit hashes. A hex run\n// needs a digit and a letter a-f, so neither a word made of a-f letters\n// nor a plain long number (a phone number, an amount) is taken for one.\nconst REFERENCES: RegExp[] = [\n /\\bhttps?:\\/\\/\\S+/gi,\n /(?:[\\w.-]+\\/)*[\\w.-]+[#!]\\d+\\b/g,\n /[#!]\\d+\\b/g,\n /\\b[0-9A-HJKMNP-TV-Z]{26}\\b/gi,\n /\\b(?:req|dlg|snd)-[\\w-]+/gi,\n /\\b(?=[0-9a-f]*\\d)(?=[0-9a-f]*[a-f])[0-9a-f]{7,}\\b/gi,\n]\n\n/** The title with every reference taken out. */\nexport function stripReferences(text: string): string {\n return REFERENCES.reduce((t, re) => t.replace(re, \" \"), text)\n}\n\n/** Why a title that is only a reference may not go on screen, or null.\n * A title with a reference must keep at least 2 words of letters once\n * the references are out; a title with none is left to the other rules. */\nexport function referenceOnlyTitle(title: string): string | null {\n const rest = stripReferences(title)\n if (rest === title) return null\n const words = rest.split(/\\s+/).filter((w) => /\\p{L}/u.test(w))\n if (words.length >= 2) return null\n return `title is only a reference (\"${title.trim()}\"); say what it is in plain words, and put the link in the body or source`\n}\n\n/** Why this card may not go on the owner's screen, or null. */\nexport function cardRuleBreak(card: { title?: string; ask?: string; choices?: string[]; origin?: { kind: string } }): string | null {\n // A card file written by hand or by an older build may miss either:\n // returned to its author, never a crash of the popup.\n const title = typeof card.title === \"string\" ? card.title : \"\"\n const ask = typeof card.ask === \"string\" ? card.ask : \"\"\n if (!title.trim()) return \"title is missing: say what it is in plain words\"\n if (title.length > SCREEN_LIMITS.title) return `title is longer than ${SCREEN_LIMITS.title} characters`\n // A request's card is held to the rule too (#1126): it is titled with\n // its headline, which its agent can write (agentx_request describe).\n const bare = referenceOnlyTitle(title)\n if (bare) return bare\n if (!ask.trim()) return \"ask is missing: one card asks one thing\"\n if (ask.length > SCREEN_LIMITS.ask) return `ask is longer than ${SCREEN_LIMITS.ask} characters`\n if ((ask.match(/\\?/g) ?? []).length > 1) return \"ask holds more than one question: one card asks one thing\"\n if ((card.choices?.length ?? 0) > SCREEN_LIMITS.answers) return `more than ${SCREEN_LIMITS.answers} choices`\n return null\n}\n\n/** Why an agent's `agentx notify` may not go on the owner's screen, or\n * null: the same ten-second rule, title 120 and message 300 (the message\n * as shown, with its \"To do:\" line), and a title in words. */\nexport function noticeRuleBreak(title: string, message: string): string | null {\n if (title.length > SCREEN_LIMITS.title) return `title is longer than ${SCREEN_LIMITS.title} characters`\n const bare = referenceOnlyTitle(title)\n if (bare) return bare\n if (message.length > SCREEN_LIMITS.ask) return `message is longer than ${SCREEN_LIMITS.ask} characters`\n return null\n}\n\n/** An agent's notice as the owner reads it: the message, then the\n * \"To do:\" line. With nothing to do, it says so, so the owner never has\n * to guess whether a notice wants something. Last, so a banner that\n * shows only the first line still shows the message. */\nexport function withTodo(message: string, todo?: string): string {\n const what = todo?.trim().replace(/\\s+/g, \" \") || \"nothing, FYI\"\n return `${message}\\nTo do: ${what}`\n}\n\n/** Local midnight before `now`: the budget's day. */\nfunction dayStart(now: number): number {\n const d = new Date(now)\n d.setHours(0, 0, 0, 0)\n return d.getTime()\n}\n\n/** Why a follow-up card of this kind cannot be raised today, or null.\n * `cards` is every card, of any status: an answered one was on screen too. */\nexport function followupBudgetRefusal(\n cards: Array<{ followup?: FollowupKind; created_at: string }>,\n kind: FollowupKind,\n now: number,\n): string | null {\n const from = dayStart(now)\n const today = cards.filter((c) => c.followup && Date.parse(c.created_at) >= from)\n if (today.length >= SCREEN_BUDGET.perDay) {\n return `the follow-up screen budget is used up today (${SCREEN_BUDGET.perDay} cards): raise it again tomorrow`\n }\n if (kind === \"resurface\" && today.filter((c) => c.followup === \"resurface\").length >= SCREEN_BUDGET.resurface) {\n return `${SCREEN_BUDGET.resurface} resurface cards were already raised today: raise it again tomorrow`\n }\n return null\n}\n\n/** What the author hears when the popup does not show its card. */\nexport function returnedText(card: { id: string; title?: string; origin?: { kind: string } }, reason: string): string {\n const title = card.title?.trim()\n if (card.origin?.kind === \"request\") {\n return [\n `[screen gate] Request ${card.id}${title ? ` (\"${title}\")` : \"\"} was not shown to the owner: ${reason}.`,\n `It is still on his list. Say what it is: agentx_request {action:\"describe\", id:\"${card.id}\", headline:\"<a few plain words>\", need:\"<what you need from him>\"}.`,\n ].join(\" \")\n }\n return [\n `[screen gate] Your card ${card.id}${title ? ` (\"${title}\")` : \"\"} was not shown to the owner: ${reason}.`,\n \"It is still in his inbox, unchanged. If it must reach him on screen, close it (agentx_approval resolve) and raise one that passes:\",\n `one question, title up to ${SCREEN_LIMITS.title} characters, ask up to ${SCREEN_LIMITS.ask}, at most ${SCREEN_LIMITS.answers} choices.`,\n ].join(\" \")\n}\n"],"mappings":"6GAAA,OAAS,cAAAA,GAAY,YAAAC,GAAU,aAAAC,EAAW,eAAAC,GAAa,gBAAAC,GAAc,cAAAC,GAAY,cAAAC,GAAY,iBAAAC,MAAqB,KAClH,OAAS,WAAAC,OAAe,OCCxBC,KAFA,OAAS,kBAAAC,GAAgB,cAAAC,GAAY,aAAAC,GAAW,gBAAAC,EAAc,iBAAAC,MAAqB,KACnF,OAAS,WAAAC,MAAe,OA+BxB,IAAMC,EAAO,IAEPC,EAAW,IAGXC,EAAOC,GAAiBJ,EAAQI,EAAM,UAAW,WAAW,EAC5DC,EAAgBD,GAAiBJ,EAAQG,EAAIC,CAAI,EAAG,i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gBA,EAAK,OAAS,OAQlE,GAPIA,EAAK,SAAW,WAAaA,EAAK,UAAY,OAAS,CAACwD,GAAS,CAAC0B,GAAOD,EAAM,KAAK,GAAGE,EAAYnF,CAAI,CAAC,EACxGA,EAAK,MAAMiF,EAAM,KAAK,kBAAkBjF,EAAK,MAAM,EAGnDA,EAAK,SAAW,WAAaA,EAAK,UAAY,MAAQ,CAACwD,GAAS,CAAC0B,GAAOD,EAAM,KAAKL,EAAY,EAC/F5E,EAAK,QAAQiF,EAAM,KAAK,WAAWjF,EAAK,QAAQ,EAChDA,EAAK,QAAQ,OAAS,YAAYiF,EAAM,KAAK,GAAGG,EAAYpF,EAAK,OAAQA,EAAK,SAAW,WAAaA,EAAK,UAAY,KAAK,CAAC,EAC7HwD,GAAS0B,EAAO,CAGlB,IAAMG,EAAUC,GAAcA,EAAE,QAAQ,OAAQ,GAAG,EAAE,KAAK,EACpDC,EAAQC,EAASxF,EAAK,MAAOA,EAAK,MAAM,EACxCyF,EAASzF,EAAK,MAAQqF,EAAOrF,EAAK,IAAI,IAAMqF,EAAOE,CAAK,EAAIvF,EAAK,KAAO,OAC9EiF,EAAM,KAAK,GAAIzB,EAAQkC,EAAWlC,EAAOxD,EAAMyF,CAAM,EAAIE,EAAgBT,EAAQlF,EAAMyF,CAAM,CAAE,EAEjG,OAAIzF,EAAK,OAAOiF,EAAM,KAAK,sBAAsBjF,EAAK,MAAM,gBAAgBA,EAAK,MAAM,mDAAmD,EACtIA,EAAK,MAAMiF,EAAM,KAAK,4EAA4EjF,EAAK,OAAO,EAClHiF,EAAM,KAAK,2DAA2D,EAC/DA,EAAM,KAAK;AAAA,CAAI,CACxB","names":["existsSync","linkSync","mkdirSync","readdirSync","readFileSync","renameSync","unlinkSync","writeFileSync","resolve","init_logger","appendFileSync","existsSync","mkdirSync","readFileSync","writeFileSync","resolve","KEEP","TEXT_MAX","dir","root","answeredFile","sinceFile","cap","s","recordAnswered","item","answeredSince","line","path","lines","e","logger","at","readAnswered","limit","out","i","v","isRetroOrigin","origin","CHECK_CHOICES","retroCheckLines","card","edited","rule","lines","SUGGESTED_NOTE","retroApproved","RETRO_NONE","retroLines","spec","originLines","approved","where","SCREEN_LIMITS","FOLLOWUP_KINDS","SCREEN_BUDGET","REFERENCES","stripReferences","text","re","referenceOnlyTitle","title","rest","w","cardRuleBreak","card","ask","bare","noticeRuleBreak","message","withTodo","todo","what","dayStart","now","d","followupBudgetRefusal","cards","kind","from","today","c","returnedText","reason","IF_SILENT_VALUES","asIfSilent","v","CARD_LIMITS","DEFAULT_CARD_SETTINGS","approvalsDir","root","resolve","CARD_ID_RE","isValidCardId","id","fileFor","newCardId","now","title","day","slug","saveCard","card","mkdirSync","path","tmp","writeFileSync","renameSync","saveNewCard","saved","linkSync","e","unlinkSync","readCard","readFileSync","legacy","listCards","status","dir","existsSync","out","f","readdirSync","c","oneLine","resolveExpiry","input","settings","max","at","raw","rel","buildCard","opts","ask","recommend","raisedBy","ifSilentRaw","ifSilent","expiry","source","extras","buildChoices","followup","FOLLOWUP_KINDS","reply","r","sameSourcePending","pending","createCard","built","broken","cardRuleBreak","full","followupBudgetRefusal","twin","isRetro","isRetroOrigin","retro","open","what","decideCard","verdict","answer","resolveAnswer","note","decided","AGENT_RESOLVABLE_ORIGINS","resolveCard","who","how","reason","resolved","recordAnswered","expireCards","expired","cardsAwaitingAgentNotice","markAgentNotified","NO_UNDO_LINE","verdictMessage","result","retroApproved","RETRO_NONE","lines","check","answerLines","originLines","squash","s","draft","draftFor","edited","retroLines","retroCheckLines"]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{a as $,b as w}from"./chunk-B6VASQHD.js";import{a as j,e as I,j as A}from"./chunk-7QW4RECS.js";import"./chunk-BYEL7KKR.js";import"./chunk-Q3A5P373.js";import{c as R}from"./chunk-JLBRNYKY.js";import"./chunk-QUFIUXMQ.js";import"./chunk-QIJLFPWE.js";var P=16e3,O=/^[A-Za-z0-9_.:@-]{1,200}$/;function v(c,e){let i=Object.keys(e.reads),f=c.metadata?.reads;if(typeof f!="string"||!f.trim())return i;let n=new Set(f.split(",").map(u=>u.trim()).filter(Boolean));return i.filter(u=>n.has(u))}function D(c,e,i,f){for(let t of Object.keys(i))if(!e.params[t])return{ok:!1,error:`unknown parameter "${t}". Allowed: ${Object.keys(e.params).join(", ")||"none"}`};let n={};for(let[t,r]of Object.entries(e.params)){let a=i[t];if((a==null||a==="")&&r.fromMetadata&&(a=f[t]),(a==null||a==="")&&r.default!==void 0&&(a=r.default),a==null||a===""){if(r.required)return{ok:!1,error:`parameter "${t}" is required: ${r.description}`};continue}let s=Array.isArray(a)?a.map(String).join(","):String(a);if(s.length>1e3)return{ok:!1,error:`parameter "${t}" is too long`};let g=r.list?s.split(",").map(m=>m.trim()).filter(Boolean):[s];for(let m of g){if(r.enum&&!r.enum.includes(m))return{ok:!1,error:`"${m}" is not allowed for "${t}". Allowed: ${r.enum.join(", ")}`};if(r.pattern&&!new RegExp(`^(?:${r.pattern.source})$`,r.pattern.flags).test(m))return{ok:!1,error:`"${m}" is not a valid value for "${t}"`}}n[t]=r.list?g.join(","):s}let u=new Set,l="",p=e.path.replace(/\{([A-Za-z0-9_]+)\}/g,(t,r)=>{let a=n[r];return a?!O.test(a)||/^\.+$/.test(a)?(l||=`"${r}" must be a plain id`,""):(u.add(r),encodeURIComponent(a)):(l||=`parameter "${r}" is required for the path`,"")});if(l)return{ok:!1,error:l};let d=new URL(c.baseUrl),o=new URL(c.baseUrl+p);if(o.origin!==d.origin)return{ok:!1,error:"the read left the provider's address"};if(p.split("/").some(t=>t==="."||t==="..")||!o.pathname.startsWith(d.pathname))return{ok:!1,error:"the read left the provider's address"};for(let[t,r]of Object.entries(n))u.has(t)||o.searchParams.set(t,r);for(let[t,r]of Object.entries(e.fixedQuery??{}))o.searchParams.set(t,r);return{ok:!0,url:o,values:n}}async function S(c,e,i={}){let f=i.providers??$,n=w(e.kind,f);if(!n)return{ok:!1,status:400,error:`no provider for kind "${e.kind}". Known: ${Object.keys(f).join(", ")||"none yet"}`};let u=j(c,e.agentId,e.kind,e.label);if(!u)return{ok:!1,status:404,error:`agent "${e.agentId}" has no enabled ${e.kind} integration${e.label?` labelled "${e.label}"`:""}`};let l=u.integration,p=Object.prototype.hasOwnProperty.call(n.reads,e.read)?n.reads[e.read]:void 0;if(!p)return{ok:!1,status:400,error:`unknown read "${e.read}". Allowed: ${v(l,n).join(", ")}`};if(!v(l,n).includes(e.read))return{ok:!1,status:403,error:`read "${e.read}" is not allowed for ${e.kind} "${l.label}" (metadata.reads)`};let d=D(n,p,e.params??{},l.metadata??{});if(!d.ok)return{ok:!1,status:400,error:d.error};let o=await A(e.agentId,l,n,i);if(o.status!=="ok")return{ok:!1,status:409,error:o.reason};let t=i.fetch??fetch,r=o.token;if(n.readToken)try{r=await n.readToken({read:e.read,values:d.values,token:o.token,fetch:t,now:(i.now??Date.now)()})}catch(k){let b=R(String(k?.message??k)).split(o.token).join("[redacted]");return{ok:!1,status:403,error:`${n.title}: ${b}`}}let a={Accept:"application/json"};(n.tokenIn??"header")==="header"?a.Authorization=`Bearer ${r}`:d.url.searchParams.set(n.tokenParam??"access_token",r);let s;try{s=await t(d.url.toString(),{method:"GET",headers:a,signal:AbortSignal.timeout(2e4),redirect:"error"})}catch(k){return{ok:!1,status:502,error:`couldn't reach ${n.title}: ${R(String(k?.message??k))}`}}let g=(await s.text().catch(()=>"")).split(o.token).join("[redacted]");if(r!==o.token&&(g=g.split(r).join("[redacted]")),!s.ok){let k=g;try{let h=JSON.parse(g);k=h?.error?.message||h?.error_description||h?.error||g}catch{}let b=s.status===401?` Connect again: ${I(e.agentId,l)}.`:s.status===403?" The account or app may lack a permission or scope this read needs.":"";return{ok:!1,status:s.status,error:`${n.title} said ${s.status}: ${R(String(k))}.${b}`}}let m=g.length>P;return{ok:!0,status:s.status,body:m?g.slice(0,P):g,truncated:m}}function x(c,e,i=$){let f=c.agents?.[e]?.integrations??[],n=[];for(let u of f){if(u.enabled===!1)continue;let l=w(u.kind,i);l&&n.push({kind:u.kind,label:u.label,title:l.title,reads:v(u,l).map(p=>{let d=l.reads[p];return{name:p,description:d.description,params:Object.fromEntries(Object.entries(d.params).map(([o,t])=>[o,{description:t.description,required:!!t.required&&!(t.fromMetadata&&u.metadata?.[o]!==void 0)&&t.default===void 0,...t.enum?{allowed:t.enum}:{}}]))}})})}return n}var y=c=>typeof c=="string"?c.trim():"";async function L(c,e,i,f,n,u={}){let l=c.toUpperCase(),p=d=>d?n.agents?.[d]?null:{status:400,body:{error:`unknown agent "${d}": it must be an agent on this node`}}:{status:400,body:{error:"agent is required: your agent id"}};if(e==="/integrations/reads"&&l==="GET"){let d=y(f.get("agent")),o=p(d);return o||{status:200,body:{integrations:x(n,d,u.providers)}}}if(e==="/integrations/read"&&l==="POST"){let d=y(i?.agent),o=p(d);if(o)return o;let t=y(i?.kind),r=y(i?.read);if(!t||!r)return{status:400,body:{error:"kind and read are required"}};let a=i?.params&&typeof i.params=="object"&&!Array.isArray(i.params)?i.params:{},s=await S(n,{agentId:d,kind:t,label:y(i?.label)||void 0,read:r,params:a},u);return s.ok?{status:200,body:{status:s.status,body:s.body,truncated:s.truncated}}:{status:s.status>=400&&s.status<600?s.status:502,body:{error:s.error}}}return e==="/integrations/read"||e==="/integrations/reads"?{status:405,body:{error:"method not allowed"}}:{status:404,body:{error:"not found"}}}export{L as handleIntegrationsApi};
|
|
2
|
-
//# sourceMappingURL=daemon-api-OVCXY4QC.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/integrations/read.ts","../src/integrations/daemon-api.ts"],"sourcesContent":["import type { DaemonConfig, Integration } from \"@/daemon/config\"\nimport { getIntegration } from \"./resolve\"\nimport { connectCommand, resolveAccessToken, type TokenDeps } from \"./resolve\"\nimport { safeProviderText } from \"./oauth\"\nimport { BUILTIN_PROVIDERS, providerFor, type ProviderRegistry } from \"./providers\"\nimport type { ProviderSpec, ReadSpec } from \"./providers/types\"\n\n// --- Named, read-only calls to an outside API (`agentx_integration_read`) ---\n//\n// An agent names an integration kind, a read from that provider's spec and\n// a few parameters. This module checks every parameter against the spec,\n// builds the URL itself and sends a GET with the integration's token. There\n// is no way to send another method, another path or a parameter the spec\n// does not list. An integration can narrow its reads further with\n// metadata.reads (\"read_a,read_b\").\n//\n// The answer is bounded (MAX_BODY characters) and never carries the token.\n\nexport const MAX_BODY = 16_000\n\nexport interface ReadDeps extends TokenDeps {\n providers?: ProviderRegistry\n}\n\nexport interface ReadRequest {\n agentId: string\n kind: string\n label?: string\n read: string\n params?: Record<string, unknown>\n}\n\nexport type ReadResult =\n | { ok: true; status: number; body: string; truncated: boolean }\n | { ok: false; status: number; error: string }\n\nconst ID_PARAM = /^[A-Za-z0-9_.:@-]{1,200}$/\n\n/** The reads an integration allows: the spec's, narrowed by metadata.reads. */\nexport function allowedReads(i: Integration, spec: ProviderSpec): string[] {\n const all = Object.keys(spec.reads)\n const only = i.metadata?.reads\n if (typeof only !== \"string\" || !only.trim()) return all\n const pick = new Set(only.split(\",\").map((s) => s.trim()).filter(Boolean))\n return all.filter((r) => pick.has(r))\n}\n\n/** Check the agent's params against a read spec. Returns the path and query\n * to send, or the first problem found. Exported for tests. */\nexport function buildReadUrl(\n spec: ProviderSpec,\n read: ReadSpec,\n params: Record<string, unknown>,\n metadata: Record<string, unknown>,\n): { ok: true; url: URL; values: Record<string, string> } | { ok: false; error: string } {\n for (const k of Object.keys(params)) {\n if (!read.params[k]) return { ok: false, error: `unknown parameter \"${k}\". Allowed: ${Object.keys(read.params).join(\", \") || \"none\"}` }\n }\n const values: Record<string, string> = {}\n for (const [name, p] of Object.entries(read.params)) {\n let raw = params[name]\n if ((raw === undefined || raw === null || raw === \"\") && p.fromMetadata) raw = metadata[name]\n if ((raw === undefined || raw === null || raw === \"\") && p.default !== undefined) raw = p.default\n if (raw === undefined || raw === null || raw === \"\") {\n if (p.required) return { ok: false, error: `parameter \"${name}\" is required: ${p.description}` }\n continue\n }\n const value = Array.isArray(raw) ? raw.map(String).join(\",\") : String(raw)\n if (value.length > 1000) return { ok: false, error: `parameter \"${name}\" is too long` }\n const items = p.list ? value.split(\",\").map((s) => s.trim()).filter(Boolean) : [value]\n for (const item of items) {\n if (p.enum && !p.enum.includes(item)) return { ok: false, error: `\"${item}\" is not allowed for \"${name}\". Allowed: ${p.enum.join(\", \")}` }\n if (p.pattern && !new RegExp(`^(?:${p.pattern.source})$`, p.pattern.flags).test(item)) return { ok: false, error: `\"${item}\" is not a valid value for \"${name}\"` }\n }\n values[name] = p.list ? items.join(\",\") : value\n }\n const used = new Set<string>()\n let pathError = \"\"\n const path = read.path.replace(/\\{([A-Za-z0-9_]+)\\}/g, (_m, name: string) => {\n const v = values[name]\n if (!v) { pathError ||= `parameter \"${name}\" is required for the path`; return \"\" }\n // \".\" and \"..\" are dot segments: the URL parser would climb out of the path.\n if (!ID_PARAM.test(v) || /^\\.+$/.test(v)) { pathError ||= `\"${name}\" must be a plain id`; return \"\" }\n used.add(name)\n return encodeURIComponent(v)\n })\n if (pathError) return { ok: false, error: pathError }\n const base = new URL(spec.baseUrl)\n const url = new URL(spec.baseUrl + path)\n if (url.origin !== base.origin) return { ok: false, error: \"the read left the provider's address\" }\n // Belt and braces: no dot segment in the read's own path, and the parsed\n // path still sits under the base path, so nothing climbed out.\n if (path.split(\"/\").some((s) => s === \".\" || s === \"..\") || !url.pathname.startsWith(base.pathname)) {\n return { ok: false, error: \"the read left the provider's address\" }\n }\n for (const [k, v] of Object.entries(values)) if (!used.has(k)) url.searchParams.set(k, v)\n for (const [k, v] of Object.entries(read.fixedQuery ?? {})) url.searchParams.set(k, v)\n return { ok: true, url, values }\n}\n\n/** Run one named read for an agent. */\nexport async function runIntegrationRead(config: DaemonConfig, req: ReadRequest, deps: ReadDeps = {}): Promise<ReadResult> {\n const providers = deps.providers ?? BUILTIN_PROVIDERS\n const spec = providerFor(req.kind, providers)\n if (!spec) return { ok: false, status: 400, error: `no provider for kind \"${req.kind}\". Known: ${Object.keys(providers).join(\", \") || \"none yet\"}` }\n const found = getIntegration(config, req.agentId, req.kind, req.label)\n if (!found) return { ok: false, status: 404, error: `agent \"${req.agentId}\" has no enabled ${req.kind} integration${req.label ? ` labelled \"${req.label}\"` : \"\"}` }\n const i = found.integration\n const read = Object.prototype.hasOwnProperty.call(spec.reads, req.read) ? spec.reads[req.read] : undefined\n if (!read) return { ok: false, status: 400, error: `unknown read \"${req.read}\". Allowed: ${allowedReads(i, spec).join(\", \")}` }\n if (!allowedReads(i, spec).includes(req.read)) return { ok: false, status: 403, error: `read \"${req.read}\" is not allowed for ${req.kind} \"${i.label}\" (metadata.reads)` }\n\n const built = buildReadUrl(spec, read, req.params ?? {}, i.metadata ?? {})\n if (!built.ok) return { ok: false, status: 400, error: built.error }\n\n const token = await resolveAccessToken(req.agentId, i, spec, deps)\n if (token.status !== \"ok\") return { ok: false, status: 409, error: token.reason }\n\n const f = deps.fetch ?? fetch\n let sendToken = token.token\n if (spec.readToken) {\n try {\n sendToken = await spec.readToken({ read: req.read, values: built.values, token: token.token, fetch: f, now: (deps.now ?? Date.now)() })\n } catch (e: any) {\n const why = safeProviderText(String(e?.message ?? e)).split(token.token).join(\"[redacted]\")\n return { ok: false, status: 403, error: `${spec.title}: ${why}` }\n }\n }\n const headers: Record<string, string> = { Accept: \"application/json\" }\n if ((spec.tokenIn ?? \"header\") === \"header\") headers.Authorization = `Bearer ${sendToken}`\n else built.url.searchParams.set(spec.tokenParam ?? \"access_token\", sendToken)\n\n let res: Response\n try {\n res = await f(built.url.toString(), { method: \"GET\", headers, signal: AbortSignal.timeout(20_000), redirect: \"error\" })\n } catch (e: any) {\n return { ok: false, status: 502, error: `couldn't reach ${spec.title}: ${safeProviderText(String(e?.message ?? e))}` }\n }\n let text = (await res.text().catch(() => \"\")).split(token.token).join(\"[redacted]\")\n if (sendToken !== token.token) text = text.split(sendToken).join(\"[redacted]\")\n if (!res.ok) {\n let why = text\n try { const j = JSON.parse(text); why = j?.error?.message || j?.error_description || j?.error || text } catch {}\n const hint = res.status === 401\n ? ` Connect again: ${connectCommand(req.agentId, i)}.`\n : res.status === 403 ? \" The account or app may lack a permission or scope this read needs.\" : \"\"\n return { ok: false, status: res.status, error: `${spec.title} said ${res.status}: ${safeProviderText(String(why))}.${hint}` }\n }\n const truncated = text.length > MAX_BODY\n return { ok: true, status: res.status, body: truncated ? text.slice(0, MAX_BODY) : text, truncated }\n}\n\nexport interface ReadCatalogEntry {\n kind: string\n label: string\n title: string\n reads: Array<{ name: string; description: string; params: Record<string, { description: string; required: boolean; allowed?: readonly string[] }> }>\n}\n\n/** The reads an agent can run, for the tool's list action. */\nexport function readCatalog(config: DaemonConfig, agentId: string, providers: ProviderRegistry = BUILTIN_PROVIDERS): ReadCatalogEntry[] {\n const list = ((config.agents?.[agentId] as any)?.integrations ?? []) as Integration[]\n const out: ReadCatalogEntry[] = []\n for (const i of list) {\n if (i.enabled === false) continue\n const spec = providerFor(i.kind, providers)\n if (!spec) continue\n out.push({\n kind: i.kind,\n label: i.label,\n title: spec.title,\n reads: allowedReads(i, spec).map((name) => {\n const r = spec.reads[name]\n return {\n name,\n description: r.description,\n params: Object.fromEntries(Object.entries(r.params).map(([k, p]) => [k, {\n description: p.description,\n required: !!p.required && !(p.fromMetadata && i.metadata?.[k] !== undefined) && p.default === undefined,\n ...(p.enum ? { allowed: p.enum } : {}),\n }])),\n }\n }),\n })\n }\n return out\n}\n","import type { DaemonConfig } from \"@/daemon/config\"\nimport { readCatalog, runIntegrationRead, type ReadDeps } from \"./read\"\n\n// --- The daemon's /integrations endpoints, for agents (#1696) ---\n//\n// GET /integrations/reads?agent= the named reads the agent can run\n// POST /integrations/read {agent, kind, label?, read, params?}\n//\n// Only reads: nothing here writes to an outside service, and no endpoint\n// returns a token. Gated by isMeshGatedPath: loopback, or a mesh token.\n\nexport interface IntegrationsApiReply {\n status: number\n body: unknown\n}\n\nconst str = (v: unknown): string => (typeof v === \"string\" ? v.trim() : \"\")\n\nexport async function handleIntegrationsApi(\n method: string,\n path: string,\n body: Record<string, unknown> | undefined,\n query: URLSearchParams,\n config: DaemonConfig,\n deps: ReadDeps = {},\n): Promise<IntegrationsApiReply> {\n const m = method.toUpperCase()\n const agentOk = (id: string): IntegrationsApiReply | null => {\n if (!id) return { status: 400, body: { error: \"agent is required: your agent id\" } }\n if (!config.agents?.[id]) return { status: 400, body: { error: `unknown agent \"${id}\": it must be an agent on this node` } }\n return null\n }\n\n if (path === \"/integrations/reads\" && m === \"GET\") {\n const agent = str(query.get(\"agent\"))\n const bad = agentOk(agent)\n if (bad) return bad\n return { status: 200, body: { integrations: readCatalog(config, agent, deps.providers) } }\n }\n\n if (path === \"/integrations/read\" && m === \"POST\") {\n const agent = str(body?.agent)\n const bad = agentOk(agent)\n if (bad) return bad\n const kind = str(body?.kind)\n const read = str(body?.read)\n if (!kind || !read) return { status: 400, body: { error: \"kind and read are required\" } }\n const params = body?.params && typeof body.params === \"object\" && !Array.isArray(body.params)\n ? (body.params as Record<string, unknown>)\n : {}\n const r = await runIntegrationRead(config, { agentId: agent, kind, label: str(body?.label) || undefined, read, params }, deps)\n if (!r.ok) return { status: r.status >= 400 && r.status < 600 ? r.status : 502, body: { error: r.error } }\n return { status: 200, body: { status: r.status, body: r.body, truncated: r.truncated } }\n }\n\n if (path === \"/integrations/read\" || path === \"/integrations/reads\") return { status: 405, body: { error: \"method not allowed\" } }\n return { status: 404, body: { error: \"not found\" } }\n}\n"],"mappings":"6PAkBO,IAAMA,EAAW,KAkBlBC,EAAW,4BAGV,SAASC,EAAaC,EAAgBC,EAA8B,CACzE,IAAMC,EAAM,OAAO,KAAKD,EAAK,KAAK,EAC5BE,EAAOH,EAAE,UAAU,MACzB,GAAI,OAAOG,GAAS,UAAY,CAACA,EAAK,KAAK,EAAG,OAAOD,EACrD,IAAME,EAAO,IAAI,IAAID,EAAK,MAAM,GAAG,EAAE,IAAKE,GAAMA,EAAE,KAAK,CAAC,EAAE,OAAO,OAAO,CAAC,EACzE,OAAOH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AAQ,IAAK,KAAM,CAAE,OAAQA,EAAE,OAAQ,KAAMA,EAAE,KAAM,UAAWA,EAAE,SAAU,CAAE,EADrE,CAAE,OAAQA,EAAE,QAAU,KAAOA,EAAE,OAAS,IAAMA,EAAE,OAAS,IAAK,KAAM,CAAE,MAAOA,EAAE,KAAM,CAAE,EAI3G,OAAId,IAAS,sBAAwBA,IAAS,sBAA8B,CAAE,OAAQ,IAAK,KAAM,CAAE,MAAO,oBAAqB,CAAE,EAC1H,CAAE,OAAQ,IAAK,KAAM,CAAE,MAAO,WAAY,CAAE,CACrD","names":["MAX_BODY","ID_PARAM","allowedReads","i","spec","all","only","pick","s","r","buildReadUrl","read","params","metadata","k","values","name","p","raw","value","items","item","used","pathError","path","_m","v","base","url","runIntegrationRead","config","req","deps","providers","BUILTIN_PROVIDERS","providerFor","found","getIntegration","built","token","resolveAccessToken","f","sendToken","e","why","safeProviderText","headers","res","text","j","hint","connectCommand","truncated","readCatalog","agentId","list","out","str","v","handleIntegrationsApi","method","path","body","query","config","deps","m","agentOk","id","agent","bad","readCatalog","kind","read","params","r","runIntegrationRead"]}
|