dispach 0.1.2 → 0.2.0-pilot.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/README.md +196 -118
  2. package/dist/APEv2Parser-2wqk09q7.js +5 -0
  3. package/dist/APEv2Parser-2wqk09q7.js.map +9 -0
  4. package/dist/AiffParser-zw4g2bdd.js +5 -0
  5. package/dist/AiffParser-zw4g2bdd.js.map +12 -0
  6. package/dist/App-ez7ve0yp.js +11 -0
  7. package/dist/{App-b1yrwrcq.js.map → App-ez7ve0yp.js.map} +6 -7
  8. package/dist/AsfParser-2hfcf5z2.js +5 -0
  9. package/dist/AsfParser-2hfcf5z2.js.map +14 -0
  10. package/dist/ConfigEditor-aamadrx3.js +6 -0
  11. package/dist/{ConfigEditor-n8hdw6r7.js.map → ConfigEditor-aamadrx3.js.map} +2 -2
  12. package/dist/DsdiffParser-n8smktvb.js +5 -0
  13. package/dist/DsdiffParser-n8smktvb.js.map +11 -0
  14. package/dist/DsfParser-npmjp4vr.js +5 -0
  15. package/dist/DsfParser-npmjp4vr.js.map +11 -0
  16. package/dist/FlacParser-xpbs2zmb.js +5 -0
  17. package/dist/FlacParser-xpbs2zmb.js.map +9 -0
  18. package/dist/KeyProbe-4fp152yv.js +5 -0
  19. package/dist/{KeyProbe-9jjeze5r.js.map → KeyProbe-4fp152yv.js.map} +2 -2
  20. package/dist/MP4Parser-es3afcmw.js +5 -0
  21. package/dist/MP4Parser-es3afcmw.js.map +12 -0
  22. package/dist/MatroskaParser-kxysj649.js +5 -0
  23. package/dist/MatroskaParser-kxysj649.js.map +13 -0
  24. package/dist/MpegParser-b3rr7b0f.js +5 -0
  25. package/dist/MpegParser-b3rr7b0f.js.map +13 -0
  26. package/dist/MusepackParser-sgjzmq0r.js +5 -0
  27. package/dist/MusepackParser-sgjzmq0r.js.map +16 -0
  28. package/dist/OggParser-x8h54ynf.js +5 -0
  29. package/dist/OggParser-x8h54ynf.js.map +18 -0
  30. package/dist/Picker-rq015kzc.js +5 -0
  31. package/dist/{Picker-hfeh1g6m.js.map → Picker-rq015kzc.js.map} +2 -2
  32. package/dist/SessionPicker-03zyvd2f.js +5 -0
  33. package/dist/{SessionPicker-zyqkg4dn.js.map → SessionPicker-03zyvd2f.js.map} +2 -2
  34. package/dist/SkillBrowser-8s8rjv98.js +5 -0
  35. package/dist/{SkillBrowser-3qdp8080.js.map → SkillBrowser-8s8rjv98.js.map} +2 -2
  36. package/dist/WavPackParser-w515nnw2.js +5 -0
  37. package/dist/WavPackParser-w515nnw2.js.map +11 -0
  38. package/dist/WaveParser-sb0w9m20.js +5 -0
  39. package/dist/WaveParser-sb0w9m20.js.map +13 -0
  40. package/dist/WizardApp-wr1tftcr.js +5 -0
  41. package/dist/{WizardApp-vzpbydy3.js.map → WizardApp-wr1tftcr.js.map} +3 -3
  42. package/dist/agents.d.ts +19 -3
  43. package/dist/agents.d.ts.map +1 -1
  44. package/dist/channels-gx951qdp.js +31 -0
  45. package/dist/channels-gx951qdp.js.map +10 -0
  46. package/dist/channels.d.ts +26 -0
  47. package/dist/channels.d.ts.map +1 -0
  48. package/dist/client.js +11 -11
  49. package/dist/client.js.map +3 -3
  50. package/dist/config-wvjeejgd.js +24 -0
  51. package/dist/{config-g7za9x13.js.map → config-wvjeejgd.js.map} +2 -2
  52. package/dist/credential-10dn3fxj.js +19 -0
  53. package/dist/{credential-npr6z8c8.js.map → credential-10dn3fxj.js.map} +1 -1
  54. package/dist/daemon.d.ts.map +1 -1
  55. package/dist/index-10009hp8.js +11 -0
  56. package/dist/index-10009hp8.js.map +11 -0
  57. package/dist/index-1xwrkwh5.js +14 -0
  58. package/dist/index-1xwrkwh5.js.map +50 -0
  59. package/dist/index-34p39yfc.js +47 -0
  60. package/dist/index-34p39yfc.js.map +15 -0
  61. package/dist/index-3y96s740.js +6 -0
  62. package/dist/{index-hwpvhaza.js.map → index-3y96s740.js.map} +1 -1
  63. package/dist/index-4ybeefmn.js +6 -0
  64. package/dist/index-4ybeefmn.js.map +11 -0
  65. package/dist/index-59z88wrb.js +6 -0
  66. package/dist/{index-h9mw7b9d.js.map → index-59z88wrb.js.map} +2 -2
  67. package/dist/index-5fwzn21m.js +6 -0
  68. package/dist/{index-gz9x25tz.js.map → index-5fwzn21m.js.map} +2 -2
  69. package/dist/index-6dvnfk8y.js +6 -0
  70. package/dist/index-6dvnfk8y.js.map +10 -0
  71. package/dist/index-6p70fnb7.js +153 -0
  72. package/dist/index-6p70fnb7.js.map +20 -0
  73. package/dist/index-6s471ydn.js +12 -0
  74. package/dist/{index-j55s3ehk.js.map → index-6s471ydn.js.map} +2 -2
  75. package/dist/index-87wcawta.js +6 -0
  76. package/dist/{index-0d93hyfc.js.map → index-87wcawta.js.map} +2 -2
  77. package/dist/index-92gfcbw0.js +6 -0
  78. package/dist/index-92gfcbw0.js.map +9 -0
  79. package/dist/index-a0h0p20f.js +991 -0
  80. package/dist/{index-tv4yv7d2.js.map → index-a0h0p20f.js.map} +27 -23
  81. package/dist/index-bamw24xc.js +6 -0
  82. package/dist/{index-6q4wf8e3.js.map → index-bamw24xc.js.map} +1 -1
  83. package/dist/index-c8ge88a9.js +12 -0
  84. package/dist/{index-258d8bzg.js.map → index-c8ge88a9.js.map} +4 -3
  85. package/dist/index-cb2q8nae.js +6 -0
  86. package/dist/index-cb2q8nae.js.map +13 -0
  87. package/dist/index-ct6bw0a6.js +6 -0
  88. package/dist/{index-4z7axw4r.js.map → index-ct6bw0a6.js.map} +1 -1
  89. package/dist/index-cz6yjxyz.js +10 -0
  90. package/dist/index-cz6yjxyz.js.map +42 -0
  91. package/dist/index-d0c5abkw.js +6 -0
  92. package/dist/{index-vgc3y3rm.js.map → index-d0c5abkw.js.map} +3 -3
  93. package/dist/index-d0vagham.js +31 -0
  94. package/dist/index-d0vagham.js.map +188 -0
  95. package/dist/index-d0zxvr99.js +90 -0
  96. package/dist/index-d0zxvr99.js.map +13 -0
  97. package/dist/{index-s9mbq7h6.js → index-d9c97ver.js} +4 -4
  98. package/dist/{index-s9mbq7h6.js.map → index-d9c97ver.js.map} +1 -1
  99. package/dist/index-e508e0vt.js +6 -0
  100. package/dist/{index-tf71ap9v.js.map → index-e508e0vt.js.map} +1 -1
  101. package/dist/index-esq0knqx.js +6 -0
  102. package/dist/index-esq0knqx.js.map +10 -0
  103. package/dist/index-featyhps.js +6 -0
  104. package/dist/index-featyhps.js.map +10 -0
  105. package/dist/index-fnq44zdt.js +45 -0
  106. package/dist/index-fnq44zdt.js.map +74 -0
  107. package/dist/index-gmn80dwc.js +7 -0
  108. package/dist/{index-02dn6m2j.js.map → index-gmn80dwc.js.map} +2 -2
  109. package/dist/index-gwhx69qs.js +66 -0
  110. package/dist/index-gwhx69qs.js.map +12 -0
  111. package/dist/index-kjgzhf3w.js +9 -0
  112. package/dist/{index-6p999cx4.js.map → index-kjgzhf3w.js.map} +4 -6
  113. package/dist/index-m68cd91a.js +12 -0
  114. package/dist/index-m68cd91a.js.map +23 -0
  115. package/dist/{index-3g3ny01d.js → index-mhmgw54j.js} +4 -4
  116. package/dist/{index-3g3ny01d.js.map → index-mhmgw54j.js.map} +1 -1
  117. package/dist/{index-gme2egyq.js → index-qm612hwa.js} +4 -4
  118. package/dist/{index-gme2egyq.js.map → index-qm612hwa.js.map} +1 -1
  119. package/dist/{index-j7gyr5nx.js → index-qwntpbwe.js} +7 -7
  120. package/dist/{index-j7gyr5nx.js.map → index-qwntpbwe.js.map} +1 -1
  121. package/dist/index-qx3xdk4x.js +6 -0
  122. package/dist/{index-d4x6yvqh.js.map → index-qx3xdk4x.js.map} +3 -4
  123. package/dist/{index-4cf6v9nb.js → index-rh0meegk.js} +4 -4
  124. package/dist/{index-4cf6v9nb.js.map → index-rh0meegk.js.map} +1 -1
  125. package/dist/index-ryb159ff.js +9 -0
  126. package/dist/{index-ff514z3y.js.map → index-ryb159ff.js.map} +3 -5
  127. package/dist/{index-ammv5st7.js → index-s6zfpyqa.js} +6 -6
  128. package/dist/{index-ammv5st7.js.map → index-s6zfpyqa.js.map} +1 -1
  129. package/dist/index-s9va2kmc.js +429 -0
  130. package/dist/index-s9va2kmc.js.map +11 -0
  131. package/dist/index-v5dmsgpx.js +7 -0
  132. package/dist/index-v5dmsgpx.js.map +11 -0
  133. package/dist/index-vaj3mn3a.js +6 -0
  134. package/dist/index-vaj3mn3a.js.map +14 -0
  135. package/dist/index-vy0rbzws.js +6 -0
  136. package/dist/{index-fex44816.js.map → index-vy0rbzws.js.map} +2 -2
  137. package/dist/index-w0s77wfx.js +6 -0
  138. package/dist/{index-v8e92nfw.js.map → index-w0s77wfx.js.map} +1 -1
  139. package/dist/index-wx1jzjzr.js +6 -0
  140. package/dist/{index-qdbq8crg.js.map → index-wx1jzjzr.js.map} +2 -2
  141. package/dist/index-xbn26c8g.js +126 -0
  142. package/dist/index-xbn26c8g.js.map +14 -0
  143. package/dist/index-ytvwyp6k.js +6 -0
  144. package/dist/{index-9r0wyj6w.js.map → index-ytvwyp6k.js.map} +2 -2
  145. package/dist/{index-cqqb6gaq.js → index-yvnwpxbb.js} +5 -5
  146. package/dist/{index-cqqb6gaq.js.map → index-yvnwpxbb.js.map} +1 -1
  147. package/dist/index.js +379 -448
  148. package/dist/index.js.map +26 -28
  149. package/dist/init.d.ts.map +1 -1
  150. package/dist/lib/agent-secrets.d.ts +38 -0
  151. package/dist/lib/agent-secrets.d.ts.map +1 -0
  152. package/dist/lib/agent-template.d.ts +54 -0
  153. package/dist/lib/agent-template.d.ts.map +1 -0
  154. package/dist/lib/channel-actions.d.ts +103 -0
  155. package/dist/lib/channel-actions.d.ts.map +1 -0
  156. package/dist/lib/chat-frame.d.ts +12 -1
  157. package/dist/lib/chat-frame.d.ts.map +1 -1
  158. package/dist/lib/commands.d.ts +13 -0
  159. package/dist/lib/commands.d.ts.map +1 -1
  160. package/dist/lib/const.d.ts +1 -1
  161. package/dist/lib/daemon-plan.d.ts.map +1 -1
  162. package/dist/lib/help.d.ts.map +1 -1
  163. package/dist/lib/host-actions.d.ts +121 -0
  164. package/dist/lib/host-actions.d.ts.map +1 -0
  165. package/dist/lib/init-flow.d.ts +32 -0
  166. package/dist/lib/init-flow.d.ts.map +1 -1
  167. package/dist/lib/init-whatsapp.d.ts +52 -0
  168. package/dist/lib/init-whatsapp.d.ts.map +1 -0
  169. package/dist/lib/plugin-install.d.ts +120 -0
  170. package/dist/lib/plugin-install.d.ts.map +1 -0
  171. package/dist/lib/providers.d.ts.map +1 -1
  172. package/dist/lib/provision.d.ts +13 -0
  173. package/dist/lib/provision.d.ts.map +1 -1
  174. package/dist/lib/readme-table.d.ts +15 -0
  175. package/dist/lib/readme-table.d.ts.map +1 -0
  176. package/dist/lib/sandbox.d.ts +17 -0
  177. package/dist/lib/sandbox.d.ts.map +1 -1
  178. package/dist/lib/schema.d.ts +34 -1
  179. package/dist/lib/schema.d.ts.map +1 -1
  180. package/dist/lib/subcommand.d.ts.map +1 -1
  181. package/dist/lib/web-url.d.ts +15 -0
  182. package/dist/lib/web-url.d.ts.map +1 -0
  183. package/dist/lib/wizard.d.ts.map +1 -1
  184. package/dist/memory.d.ts.map +1 -1
  185. package/dist/model.d.ts.map +1 -1
  186. package/dist/plugins.d.ts +27 -8
  187. package/dist/plugins.d.ts.map +1 -1
  188. package/dist/restart.d.ts +21 -0
  189. package/dist/restart.d.ts.map +1 -0
  190. package/dist/run.d.ts.map +1 -1
  191. package/dist/schedules.d.ts.map +1 -1
  192. package/dist/serve.d.ts.map +1 -1
  193. package/dist/sessions.d.ts.map +1 -1
  194. package/dist/skills.d.ts.map +1 -1
  195. package/dist/status.d.ts +16 -0
  196. package/dist/status.d.ts.map +1 -0
  197. package/dist/tools.d.ts.map +1 -1
  198. package/dist/validate.d.ts.map +1 -1
  199. package/dist/web-61cjhpv2.js +14 -0
  200. package/dist/{web-vkb16r62.js.map → web-61cjhpv2.js.map} +3 -3
  201. package/dist/web.d.ts +2 -13
  202. package/dist/web.d.ts.map +1 -1
  203. package/dist/workspace.d.ts.map +1 -1
  204. package/dist/wrapper-9msjh1xg.js +5 -0
  205. package/dist/wrapper-9msjh1xg.js.map +9 -0
  206. package/package.json +6 -3
  207. package/dist/App-b1yrwrcq.js +0 -11
  208. package/dist/ConfigEditor-n8hdw6r7.js +0 -6
  209. package/dist/KeyProbe-9jjeze5r.js +0 -5
  210. package/dist/Picker-hfeh1g6m.js +0 -5
  211. package/dist/SessionPicker-zyqkg4dn.js +0 -5
  212. package/dist/SkillBrowser-3qdp8080.js +0 -5
  213. package/dist/WizardApp-vzpbydy3.js +0 -5
  214. package/dist/config-g7za9x13.js +0 -24
  215. package/dist/credential-npr6z8c8.js +0 -19
  216. package/dist/index-02dn6m2j.js +0 -7
  217. package/dist/index-0d93hyfc.js +0 -6
  218. package/dist/index-1c5113t4.js +0 -66
  219. package/dist/index-1c5113t4.js.map +0 -12
  220. package/dist/index-258d8bzg.js +0 -12
  221. package/dist/index-4z7axw4r.js +0 -6
  222. package/dist/index-6p999cx4.js +0 -9
  223. package/dist/index-6q4wf8e3.js +0 -6
  224. package/dist/index-9r0wyj6w.js +0 -6
  225. package/dist/index-d4x6yvqh.js +0 -6
  226. package/dist/index-fecm8xe7.js +0 -77
  227. package/dist/index-fecm8xe7.js.map +0 -12
  228. package/dist/index-fex44816.js +0 -6
  229. package/dist/index-ff514z3y.js +0 -14
  230. package/dist/index-gz9x25tz.js +0 -6
  231. package/dist/index-h9mw7b9d.js +0 -6
  232. package/dist/index-hwpvhaza.js +0 -6
  233. package/dist/index-j55s3ehk.js +0 -12
  234. package/dist/index-mtn0g9vc.js +0 -7
  235. package/dist/index-mtn0g9vc.js.map +0 -11
  236. package/dist/index-qdbq8crg.js +0 -6
  237. package/dist/index-tf71ap9v.js +0 -6
  238. package/dist/index-ttwyrdjs.js +0 -427
  239. package/dist/index-ttwyrdjs.js.map +0 -11
  240. package/dist/index-tv4yv7d2.js +0 -903
  241. package/dist/index-ty24n0jh.js +0 -167
  242. package/dist/index-ty24n0jh.js.map +0 -19
  243. package/dist/index-v8e92nfw.js +0 -6
  244. package/dist/index-vgc3y3rm.js +0 -6
  245. package/dist/index-whaw4b18.js +0 -6
  246. package/dist/index-whaw4b18.js.map +0 -10
  247. package/dist/web-vkb16r62.js +0 -14
@@ -0,0 +1,153 @@
1
+ #!/usr/bin/env node
2
+ import{A,t,Fe,rA,L,J,ie}from"./index-a0h0p20f.js";import{Z}from"./index-34p39yfc.js";import{$o,Re}from"./index-10009hp8.js";import{ke,_e,uA,Ie,ze,_t}from"./index-wx1jzjzr.js";import{P}from"./index-kjgzhf3w.js";import{Tr}from"./index-d9c97ver.js";import{pe,G,Nn,Pt,X}from"./index-v5dmsgpx.js";import{E,p,KA,Kt,xA}from"./index-qwntpbwe.js";import{n,c,ds}from"./index-d0c5abkw.js";import{u}from"./index-92gfcbw0.js";import{closeSync as Ke,existsSync as we,mkdirSync as Xe,openSync as Je,readFileSync as Ye,readSync as Qe,statSync as be}from"node:fs";import{homedir as U}from"node:os";import{dirname as C,join as $e,resolve as qe}from"node:path";function K(e){let r=[];if(e.problem!==void 0)r.push({code:"daemon_agent_unreadable",severity:"warn",message:`Agent "${e.agentId}" could not be read: ${e.problem}`,hint:"The host skips an agent whose manifest will not load and serves the rest, so this is a warning rather than a refusal — `validate` on that agent says exactly what is wrong with it."});if(e.envFileMode!==void 0&&(e.envFileMode&63)!==0)r.push({code:"daemon_env_world_readable",severity:"warn",message:`${e.agentId}'s .env is mode ${(e.envFileMode&511).toString(8)} and holds its only secrets.`,hint:`Under a service manager that file is the *only* path credentials arrive by — a unit carries none on purpose, because its manager echoes the environment in plaintext. \`chmod 600 ${e.agentDir}/.env\`.`});return r}function Me(e){let r=[];if(e.gitRoot!==void 0)r.push({code:"daemon_binary_in_checkout",severity:"warn",message:`The binary resolves to ${e.scriptPath}, inside a git checkout at ${e.gitRoot}.`,hint:"A rebuild, a branch switch or a `git clean` changes or breaks what the service runs, and the failure arrives with no obvious connection to the change. Fine for testing; install a released build for a service you intend to leave running."});if(/[/.](nvm|fnm|volta|asdf)\//.test(e.execPath))r.push({code:"daemon_versioned_runtime",severity:"warn",message:`The interpreter is a version-managed install: ${e.execPath}`,hint:"The absolute path is baked into the service definition, so removing that runtime version later kills the service with a message only the log file sees. A system or Homebrew install is more durable."});return r}function z(e){let r=[];for(let i of e.retiring)r.push({code:"daemon_per_agent_retired",severity:"warn",message:`Retiring ${i} — one service hosts every agent now.`,hint:"It is unloaded, re-enabled and its definition removed. The re-enable is not cosmetic: a `disable` row persists across boots and no verb deletes it, so a label left disabled makes any future job with that name install cleanly and silently never start. Per-agent on/off is `stop <agent>`, which persists in the store instead."});if(e.servedElsewhere.length>0){let i=e.servedElsewhere[0];r.push({code:"daemon_agents_held_elsewhere",severity:"warn",message:`${e.servedElsewhere.length} agent(s) are held by other live processes — ${i?.agentId} by pid ${i?.pid} (${i?.mode}).`,hint:"The service will start and serve everything else, and report those as served elsewhere rather than fighting for them — one listener per bot token is the whole reason the lease exists. `stop` with no agent ends the other processes."})}return r.push(...Me(e.binary)),r}function Ce(e,r="serving on"){let i=e.lastIndexOf(r);return i===-1?e:e.slice(i)}function Y(e){let r=Ce(e),i=[],s=new Set;for(let a of r.matchAll(/denied — Sender "([^"]+)" is not in channel "([^"]+)"/g))if(a[1]!==void 0)s.add(`${a[1]}|${a[2]??""}`);for(let a of s){let[o,d]=a.split("|");i.push({code:"inbound_denied",summary:`messages from ${o} are being refused — they are not on channel "${d}"'s allowFrom list`,fix:`add ${o} to allowFrom in agent.yaml, then restart. An allowlist that is empty, or that has a typo in it, refuses silently from the sender's side: they see nothing at all.`})}if(/channel_telegram_unauthorized|telegram_token_missing/.test(r))i.push({code:"channel_unauthorized",summary:"the channel rejected its token",fix:"check the token in the .env beside the manifest, then restart."});return i}var De=3;function Q(e,r){let i=Le(r),s=[];if(r.pid!==void 0)s.push({label:"state",value:`running · pid ${r.pid}`,...r.uptimeMs===void 0?{}:{note:`up ${Kt(r.uptimeMs)}`}});else if(r.leasePid!==void 0)s.push({label:"state",value:`running · pid ${r.leasePid}`,note:"a serve process, not an installed service"});if(r.runs!==void 0&&r.runs>1)s.push({label:"starts",value:String(r.runs),...i==="restart-loop"?{note:`launchd has restarted this ${r.runs} times`}:{note:"since the service was installed"}});if(i!=="running"&&r.lastExitCode!==void 0&&r.lastExitCode!==0)s.push({label:"last exit",value:`code ${r.lastExitCode}`});if(r.stderrPath!==void 0)s.push({label:"logs",value:r.stderrPath,...r.stderrBytes===void 0?{}:{note:`(${KA(r.stderrBytes)})`}});return{verdict:i,healthy:i==="running",headline:i==="restart-loop"?`${e} — RESTART LOOP`:`${e} — ${He(i)}`,rows:s,wantsStderrTail:i==="restart-loop"||i==="failed"||i==="installed-idle"}}function Le(e){if(!e.installed)return e.leasePid===void 0?"absent":"running";if(e.pid!==void 0)return"running";if(e.disabled)return"stopped";if((e.runs??0)>=De&&(e.lastExitCode??0)!==0)return"restart-loop";if((e.lastExitCode??0)!==0)return"failed";return"installed-idle"}function He(e){switch(e){case"running":return"running";case"failed":return"STOPPED AFTER A FAILURE";case"restart-loop":return"exited · nothing is running";case"stopped":return"stopped by you";case"installed-idle":return"installed · not running";case"absent":return"not installed"}}function q(e){return`${e.headline}
3
+ ${E(e.rows)}`}function R(e){return["HOME","PATH","TMPDIR",`${e}SERVICE`,`${e}HOME`]}class D extends Error{code="daemon_secret_in_service";hint;constructor(e,r,i){super(`The service definition would carry an environment variable named ${e}.`);this.hint=`A ${i} unit is readable and its manager echoes every environment value in plaintext to any process running as this user — so a credential here is a credential published. The agent reads its own secrets from the .env beside its manifest, which is what the service is pointed at. Only these may appear: ${r.join(", ")}.`}}function O(e,r,i){let s=R(r);for(let a of Object.keys(e))if(!s.includes(a))throw new D(a,s,i)}var Ne={Crashed:!0},x=30,S=30;function lo(e,r){return`${e}.agent.${r}`}function b(e){return`${e}.server`}function w(e){return e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;").replaceAll("'","&apos;")}function _(e,r){O(e.environment,r,"launchd");let i=e.programArguments.map((o)=>` <string>${w(o)}</string>`).join(`
4
+ `),s=Object.entries(e.environment).map(([o,d])=>` <key>${w(o)}</key>
5
+ <string>${w(d)}</string>`).join(`
6
+ `);return`<?xml version="1.0" encoding="UTF-8"?>
7
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
8
+ <!--
9
+ ${e.provenance.map((o)=>` ${w(o)}`).join(`
10
+ `)}
11
+ -->
12
+ <plist version="1.0">
13
+ <dict>
14
+ <key>Label</key>
15
+ <string>${w(e.label)}</string>
16
+ <key>ProgramArguments</key>
17
+ <array>
18
+ ${i}
19
+ </array>
20
+ <key>RunAtLoad</key>
21
+ <true/>
22
+ <key>KeepAlive</key>
23
+ <dict>
24
+ <key>Crashed</key>
25
+ <${Ne.Crashed}/>
26
+ </dict>
27
+ <key>ThrottleInterval</key>
28
+ <integer>${x}</integer>
29
+ <key>ExitTimeOut</key>
30
+ <integer>${S}</integer>
31
+ <key>ProcessType</key>
32
+ <string>Adaptive</string>
33
+ <key>WorkingDirectory</key>
34
+ <string>${w(e.workingDirectory)}</string>
35
+ <key>StandardOutPath</key>
36
+ <string>${w(e.stdoutPath)}</string>
37
+ <key>StandardErrorPath</key>
38
+ <string>${w(e.stderrPath)}</string>
39
+ <key>EnvironmentVariables</key>
40
+ <dict>
41
+ ${s}
42
+ </dict>
43
+ </dict>
44
+ </plist>
45
+ `}function ee(e){let r=[];for(let i of e.split(`
46
+ `)){let s=i.split("\t");if(s.length<3)continue;let[a,o,d]=s;if(d===void 0||d==="Label"||d==="")continue;let l=Number.parseInt(o??"",10);r.push({...a===void 0||a==="-"?{}:{pid:Number.parseInt(a,10)},status:Number.isFinite(l)?l:0,label:d})}return r}function ne(e){let r={};for(let i of e.split(`
47
+ `)){let s=i.trim(),a=/^pid = (\d+)$/.exec(s);if(a?.[1]!==void 0)r.pid=Number.parseInt(a[1],10);let o=/^runs = (\d+)$/.exec(s);if(o?.[1]!==void 0)r.runs=Number.parseInt(o[1],10);let d=/^last exit code = (-?\d+)$/.exec(s);if(d?.[1]!==void 0)r.lastExitCode=Number.parseInt(d[1],10);let l=/^state = (.+)$/.exec(s);if(l?.[1]!==void 0)r.jobState=l[1];let h=/^stdout path = (.+)$/.exec(s);if(h?.[1]!==void 0)r.stdoutPath=h[1];let f=/^stderr path = (.+)$/.exec(s);if(f?.[1]!==void 0)r.stderrPath=f[1]}return r}function te(e){let r=[];for(let i of e.split(`
48
+ `)){let s=/^\s*"(.+)"\s*=>\s*(disabled|true)\s*$/.exec(i);if(s?.[1]!==void 0)r.push(s[1])}return r}function We(e,r){if(r<e)return{from:0,to:r,truncated:!0};return{from:e,to:r,truncated:!1}}async function re(e,r,i){let s=new Map(e.map((o)=>[o.path,i.offsets[o.path]??0])),a;while(!r.stopped()){for(let o of e){let d=r.sizeOf(o.path);if(d===void 0)continue;let l=We(s.get(o.path)??0,d);if(s.set(o.path,l.to),l.truncated)r.write(`
49
+ ── ${o.label} was emptied ──
50
+ `),a=o.label;if(l.to<=l.from)continue;let h=r.read(o.path,l.from,l.to);if(h==="")continue;if(e.length>1&&o.label!==a)r.write(`
51
+ ── ${o.label} ──
52
+ `),a=o.label;r.write(h)}await r.wait(i.intervalMs)}}import{existsSync as Ue,mkdirSync as H,readdirSync as le,rmSync as ue,writeFileSync as ce}from"node:fs";import{basename as je,dirname as I,join as de}from"node:path";import{join as se}from"node:path";function oe(e,r,i=process.env){let s=i.XDG_CONFIG_HOME,a=s===void 0||s===""?se(r,".config"):s;return se(a,"systemd","user",`${e}.service`)}function F(e,r){if(/[\r\n]/.test(e))throw Error(`${r} contains a newline, which systemd cannot express. hint: a unit value runs to end of line, so this would silently truncate rather than fail — rename the path.`)}function Be(e){if(!/[\s"\\]/.test(e))return e;return`"${e.replaceAll("\\","\\\\").replaceAll('"',"\\\"")}"`}function T(e,r){O(e.environment,r,"systemd");for(let o of e.programArguments)F(o,"ExecStart");F(e.workingDirectory,"WorkingDirectory");for(let[o,d]of Object.entries(e.environment))F(d,`Environment=${o}`);let i=e.programArguments.map(Be).join(" "),s=Object.entries(e.environment).map(([o,d])=>`Environment=${o}=${d}`).join(`
53
+ `);return`${e.provenance.map((o)=>`# ${o}`).join(`
54
+ `)}
55
+
56
+ [Unit]
57
+ Description=${e.label}
58
+ After=network-online.target
59
+ Wants=network-online.target
60
+
61
+ [Service]
62
+ Type=simple
63
+ ExecStart=${i}
64
+ WorkingDirectory=${e.workingDirectory}
65
+ ${s}
66
+ # A configuration fault stops the service once rather than retrying into a log nobody opens.
67
+ # Mirrors launchd's KeepAlive: {Crashed: true} — see launchd.ts for why that is structural.
68
+ Restart=on-failure
69
+ RestartSec=${x}
70
+ # Must exceed the runtime's own stop deadline, or the reaper that kills backgrounded exec
71
+ # children never finishes and they outlive the service.
72
+ TimeoutStopSec=${S}
73
+ KillMode=mixed
74
+
75
+ [Install]
76
+ WantedBy=default.target
77
+ `}function ae(e,r){return["systemctl --user daemon-reload",`systemctl --user enable --now ${e}`,`loginctl enable-linger ${r}`]}var Ge=6000,Ve=200,he=(e,r)=>{let i=Tr({command:e,args:r});return{code:i.code,stdout:i.stdout,stderr:i.stderr}};function Mt(e,r){if(e==="darwin")return new ye(r);if(e==="linux")return new fe(r);throw N(e)}function ge(e){return e==="darwin"}function N(e,r){let i=r===void 0?"":` For a systemd user unit, the line to write is:
78
+
79
+ ${r}
80
+ Restart=on-failure
81
+ RestartSec=30
82
+
83
+ Put no secrets in the unit: the agent reads the .env beside its manifest, and \`systemctl show\` echoes Environment= to anyone.`;return new t({code:"daemon_platform_unsupported",message:`daemon installs a macOS LaunchAgent or a systemd user unit, and this platform is ${e}.`,hint:`No service manager is implemented for this platform.${i} In a container, run \`serve\` in the foreground and let the container runtime supervise it; that is the deployment this runtime is designed around.`})}class fe{id="systemd";#r;#e;#i;#t;constructor(e){this.#r=e.home,this.#e=e.envPrefix,this.#i=e.exec??he,this.#t=e.env??process.env}unitPath(e){return oe(e,this.#r,this.#t)}install(e){let r=this.unitPath(e.label),i=T(e,this.#e);H(I(r),{recursive:!0}),ce(r,i,{encoding:"utf8",mode:384})}uninstall(e){ue(this.unitPath(e),{force:!0})}stop(e){throw this.#n(`systemctl --user stop ${e}`)}start(e){throw this.#n(`systemctl --user start ${e}`)}restart(e){throw this.#n(`systemctl --user restart ${e}`)}state(e){return{installed:Ue(this.unitPath(e)),disabled:!1,liveness:!1}}labels(e){try{return le(I(this.unitPath(e))).filter((r)=>r.startsWith(e)&&r.endsWith(".service")).map((r)=>r.slice(0,-8)).sort()}catch{return[]}}followUp(e){return ae(e,this.#s())}caution(){let e=this.#s(),r=this.#i("loginctl",["show-user",e,"--property=Linger"]);if(r.code===0&&/Linger=yes/i.test(r.stdout))return;return`A systemd user unit stops when your last session ends. \`loginctl enable-linger ${e}\` is what keeps it running after you log out or close an SSH connection.`}#s(){return this.#t.USER??this.#t.LOGNAME??je(this.#r)}#n(e){return new t({code:"daemon_manual_step",message:`This has to be run yourself: ${e}`,hint:`Unit files are written and read from here, and the lifecycle is not driven from here — nothing in this project's test environment can run \`systemctl --user\` (a container has no systemd, and a CI runner has no user session bus), and a command that reported success while nothing happened would be worse than this sentence. The unit is at ${this.unitPath(e.split(" ").pop()??"")}.`})}}class ye{id="launchd";#r;#e;#i;#t;constructor(e){this.#r=e.home,this.#e=`gui/${e.uid}`,this.#i=e.envPrefix,this.#t=e.exec??he}unitPath(e){return de(this.#r,"Library","LaunchAgents",`${e}.plist`)}install(e){let r=this.unitPath(e.label),i=_(e,this.#i);if(H(I(r),{recursive:!0}),H(I(e.stdoutPath),{recursive:!0}),this.#n(["bootout",`${this.#e}/${e.label}`],{tolerate:!0}),this.#s(e.label),ce(r,i,{encoding:"utf8",mode:384}),this.#n(["enable",`${this.#e}/${e.label}`],{tolerate:!0}),this.#n(["bootstrap",this.#e,r]),!this.state(e.label).installed)throw new t({code:"daemon_not_loaded",message:`${e.label} was written to ${r} but launchd did not load it.`,hint:`\`launchctl bootstrap\` returned success and \`launchctl print ${this.#e}/${e.label}\` finds nothing, which usually means an earlier copy was still unloading. Try again in a moment. Over SSH with no desktop session the ${this.#e} domain is unavailable and no LaunchAgent can load at all.`})}#s(e){let r=Date.now()+Ge;while(Date.now()<r){if(this.#t("launchctl",["print",`${this.#e}/${e}`]).code!==0)return;Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,Ve)}}uninstall(e){this.#n(["bootout",`${this.#e}/${e}`],{tolerate:!0}),this.#n(["enable",`${this.#e}/${e}`],{tolerate:!0}),ue(this.unitPath(e),{force:!0})}stop(e){this.#n(["disable",`${this.#e}/${e}`],{tolerate:!0}),this.#n(["bootout",`${this.#e}/${e}`],{tolerate:!0})}start(e){this.#n(["enable",`${this.#e}/${e}`],{tolerate:!0}),this.#n(["bootstrap",this.#e,this.unitPath(e)])}restart(e){this.#n(["kickstart","-k",`${this.#e}/${e}`])}state(e){let r=this.#t("launchctl",["print",`${this.#e}/${e}`]),i=te(this.#t("launchctl",["print-disabled",this.#e]).stdout).includes(e);if(r.code!==0)return{installed:!1,disabled:i,liveness:!0};let s=ne(r.stdout);return{installed:!0,disabled:i,liveness:!0,print:s,...s.pid===void 0?{}:{pid:s.pid}}}labels(e){let r=ee(this.#t("launchctl",["list"]).stdout).map((s)=>s.label).filter((s)=>s.startsWith(e)),i=[];try{i=le(de(this.#r,"Library","LaunchAgents")).filter((s)=>s.startsWith(e)&&s.endsWith(".plist")).map((s)=>s.slice(0,-6))}catch{}return[...new Set([...r,...i])].sort()}followUp(){return[]}caution(){return}#n(e,r={}){let i=this.#t("launchctl",e);if(i.code===0||r.tolerate===!0)return i;throw new t({code:"daemon_launchctl_failed",message:`launchctl ${e.join(" ")} failed (${i.code}): ${i.stderr.trim()||"no output"}`,hint:`Code 5 usually means the service is already loaded — try \`daemon restart\`. Code 37 means an operation is still in progress; wait a moment. Code 125 or 112 means the ${this.#e} domain is unavailable, which happens over SSH with no GUI session: a LaunchAgent needs a logged-in desktop session, and the exit timeout is ${S}s.`})}}var me=["install","uninstall","start","stop","restart","status","logs"];async function CA(e){if(!me.includes(e.action))throw new t({code:"cli_daemon_unknown_action",message:`daemon takes one of ${me.join(", ")}, not "${e.action}".`,hint:`Usage: ${A.slug} daemon <action> <agent>. Run \`${A.slug} daemon --help\` for what each one does.`});let r=e.action;if(e.manifestPath!==void 0&&r!=="status"&&r!=="logs")throw new t({code:"daemon_per_agent_retired",message:`daemon ${r} no longer takes an agent — one service hosts every agent.`,hint:`\`${A.slug} daemon ${r}\` acts on that one service. Per-agent on/off is \`${A.slug} stop <agent>\` and \`${A.slug} start <agent>\`, which persist in the store rather than as a unit — so an agent you switch off stays off across a restart without the host going down with it.`});let i=e.platform??process.platform,s=en();if(i!=="darwin"&&i!=="linux"&&r!=="status")throw N(i,tn(s,e.manifestPath??"<manifest>"));let a=i==="darwin"||i==="linux"?Mt(i,{home:U(),uid:process.getuid?.()??0,envPrefix:A.envPrefix,...e.exec===void 0?{}:{exec:e.exec},...e.env===void 0?{}:{env:e.env}}):void 0;switch(r){case"status":return await hn(e,a);case"install":return await Ze(e,s,a);case"uninstall":return on(e,a);case"start":case"stop":case"restart":return an(r,a);case"logs":return await fn(e)}}async function Ze(e,r,i){let s=b(A.slug),a=Nn(e.env),o=(i?.labels(`${A.slug}.agent.`)??[]).filter((g)=>g!==s),d=[...z({binary:r,retiring:o,servedElsewhere:(await uA(e.store)).map((g)=>({agentId:g.agentId,pid:g.pid,mode:g.mode}))}),...X(e.env).flatMap((g)=>{let y=sn(g.dir);return K({agentId:g.id??g.ref,agentDir:g.dir,...g.problem===void 0?{}:{problem:g.problem},...y===void 0?{}:{envFileMode:y}})})],l={label:s,programArguments:[r.execPath,r.scriptPath,"serve","--store",G()].filter((g)=>g!==""),workingDirectory:pe(e.env),stdoutPath:a.out,stderrPath:a.err,environment:rn(s),provenance:[`Generated by \`${A.slug} daemon install\`. One service hosts every agent.`,"Rewritten on every install — it names no agent, so there is nothing here to edit","when you add one. Switch an agent off with `stop <agent>`, which persists.","There are no secrets here and there never will be: a service manager echoes a","unit's environment in plaintext to anything running as this user. Each agent","reads its own credentials from the .env beside its manifest."]};if(e.dryRun===!0){if(process.stdout.write(i?.id==="systemd"?T(l,A.envPrefix):_(l,A.envPrefix)),d.length>0)process.stderr.write(ve(d));return n}for(let g of o)i?.uninstall(g);if(d.length>0)process.stdout.write(ve(d));Xe(C(a.out),{recursive:!0}),i?.install(l);let h=i?.followUp(s)??[];if(process.stdout.write(`${s} — ${h.length===0?"service installed":"unit written"}
84
+ ${E([{label:"runs",value:`${k(r.execPath)} … serve`},{label:"hosts",value:"every agent in the sandbox that is not stopped"},{label:"logs",value:k(a.err)},{label:"restarts",value:`on crash only, at most one per ${x}s`}])}
85
+ `),h.length>0)process.stdout.write(`
86
+ Not started yet — run these:
87
+ ${h.map((g,y)=>` ${y+1}. ${g}`).join(`
88
+ `)}
89
+ `);let f=i?.caution();if(f!==void 0)process.stdout.write(`
90
+ ${f}
91
+ `);return process.stdout.write(`
92
+ A configuration error stops it once rather than looping — \`${A.slug} daemon status\` says why.
93
+ `),n}function en(){let e=W(process.execPath),r=W(process.argv[1]??""),i=nn(C(r));return{execPath:e,scriptPath:r,...i===void 0?{}:{gitRoot:i}}}function W(e){try{return u("node:fs").realpathSync(e)}catch{return e}}function nn(e){let r=e;for(let i=0;i<40;i+=1){if(we($e(r,".git")))return r;let s=C(r);if(s===r)return;r=s}return}function tn(e,r){return`ExecStart=${e.execPath} ${e.scriptPath} serve ${r} --store ${G()}`}function rn(e){let r=U(),s=[C(W(process.execPath)),"/opt/homebrew/bin","/usr/local/bin","/usr/bin","/bin","/usr/sbin","/sbin"].filter((d,l,h)=>h.indexOf(d)===l).join(":"),a={HOME:r,PATH:s,[`${A.envPrefix}SERVICE`]:e},o=process.env[`${A.envPrefix}HOME`];if(o!==void 0&&o!=="")a[`${A.envPrefix}HOME`]=o;return a}function sn(e){try{return be($e(e,".env")).mode}catch{return}}function ve(e){return`${e.map((r)=>`${r.severity==="block"?"refused":"warning"}: ${r.message}
94
+ hint: ${r.hint}`).join(`
95
+
96
+ `)}
97
+ `}function on(e,r){let i=b(A.slug),s=Nn(e.env);for(let a of(r?.labels(`${A.slug}.agent.`)??[]).filter((o)=>o!==i))r?.uninstall(a),process.stdout.write(` also removed ${a}
98
+ `);return r?.uninstall(i),process.stdout.write(`${i} — service removed
99
+ ${E([{label:"logs kept",value:k(s.err)},{label:"agents",value:"unchanged — nothing was switched off"}])}
100
+ `),n}function an(e,r){let i=b(A.slug);if(r===void 0)return c;if(e==="start")r.start(i);if(e==="stop")r.stop(i);if(e==="restart")r.restart(i);let s=e==="stop"?" — the whole host. It stays stopped across a login until you start it again, and no"+" agent was switched off":"";return process.stdout.write(`${i} — ${e}${e==="stop"?"ped":"ed"}${s}
101
+ `),n}async function hn(e,r){let i=b(A.slug),s=await uA(e.store);if(e.manifestPath===void 0){if(r?.state(i).installed!==!0&&s.length===0)return process.stdout.write(`no server is installed and nothing is running
102
+ hint: \`${A.slug} daemon install\` keeps one running after you close the terminal. One service hosts every agent.
103
+ `),c}let a=e.manifestPath===void 0?[i]:[xe(e.manifestPath)],o=await Promise.all(a.map((h)=>pn(h,r,{...h===i?{label:i}:{},logs:h===i?Nn(e.env):Pt(h),...e.store===void 0?{}:{store:e.store},...h===i&&s[0]!==void 0?{leaseOf:s[0].agentId}:{}}))),d=e.manifestPath===void 0&&s.length>0?s.map((h)=>h.agentId).sort():[],l=(await gn()).filter((h)=>e.manifestPath===void 0||a.includes(h.agentId));if(e.json===!0)process.stdout.write(`${JSON.stringify({agents:o,hosting:d,disabled:l},null,2)}
104
+ `);else{for(let h of o){process.stdout.write(`${q(h.report)}
105
+ `);for(let f of h.attention)process.stdout.write(`
106
+ needs you ${f.summary}
107
+ ${f.fix}
108
+ `);if(h.report.wantsStderrTail&&h.tail!=="")process.stdout.write(`
109
+ last lines of stderr:
110
+ ${p(h.tail,4)}
111
+ `);if(h.report.verdict==="restart-loop"||h.report.verdict==="failed")process.stdout.write(`
112
+ fix correct the error above, then \`${A.slug} daemon restart ${h.agentId}\`
113
+ `);process.stdout.write(`
114
+ `)}if(d.length>0)process.stdout.write(` hosting ${d.length} ${d.length===1?"agent":"agents"}: ${d.join(", ")}
115
+ `);if(l.length>0){let h=`${l.length} ${l.length===1?"agent":"agents"}`;process.stdout.write(` ${h} switched off, so nothing is hosting them:
116
+ `);for(let f of l)process.stdout.write(` ${f.agentId}${f.reason===void 0?"":` — ${f.reason}`}${f.disabledAt===void 0?"":` (since ${f.disabledAt})`}
117
+ `);process.stdout.write(` \`${A.slug} start <agent>\` switches one back on — a restart alone will not.
118
+
119
+ `)}}return o.every((h)=>h.report.healthy)?n:c}async function gn(){try{let e=await ie.open({path:G()});try{return(await e.agentState.list()).filter((r)=>!r.enabled).map((r)=>({agentId:r.agentId,...r.reason===void 0?{}:{reason:r.reason},...r.disabledAt===void 0?{}:{disabledAt:r.disabledAt}}))}finally{await e.close()}}catch{return[]}}async function pn(e,r,i){let s=i.label,a=s===void 0?void 0:r?.unitPath(s),o=s===void 0?void 0:r?.state(s),d=i.logs,l;try{let v=await ie.open({path:i.store??G()});l=await v.leases.get(i.leaseOf??e),await v.close()}catch{l=void 0}if(l!==void 0&&!J(l.pid))l=void 0;let h=o?.print?.stderrPath??d.err,f=M(h),g={installed:a!==void 0&&we(a)||o?.installed===!0,disabled:o?.disabled??!1,...o?.pid===void 0?{}:{pid:o.pid},...o?.print?.runs===void 0?{}:{runs:o.print.runs},...o?.print?.lastExitCode===void 0?{}:{lastExitCode:o.print.lastExitCode},stderrPath:k(h),...f===void 0?{}:{stderrBytes:f},...l===void 0?{}:{leasePid:l.pid,leaseMode:l.mode,leaseStartedAt:l.startedAt,uptimeMs:Date.now()-Date.parse(l.startedAt)}},y=Q(e,g),m=Y(B(d.out,200));return{agentId:e,report:y,tail:y.wantsStderrTail?B(h,20):"",attention:m}}async function fn(e){let r=e.manifestPath===void 0?void 0:xe(e.manifestPath),i=r??b(A.slug),s=r===void 0?Nn(e.env):Pt(r);if(e.truncate===!0){for(let o of[s.out,s.err])try{u("node:fs").writeFileSync(o,"")}catch{}return process.stdout.write(`${i} — logs truncated
120
+ `),n}let a=B(s.err,e.lines??40);if(process.stdout.write(a===""?`${k(s.err)} is empty
121
+ `:`${a}
122
+ `),e.follow!==!0)return n;return await re([{path:s.err,label:"stderr"},{path:s.out,label:"stdout"}],yn(),{offsets:{[s.err]:M(s.err)??0,[s.out]:M(s.out)??0},intervalMs:ds}),n}function yn(){let e=!1,r,i=()=>{e=!0,r?.()};return process.on("SIGINT",i),P(()=>{process.off("SIGINT",i)}),{sizeOf:(s)=>M(s),read:(s,a,o)=>{try{let d=Je(s,"r");try{let l=Buffer.alloc(o-a),h=Qe(d,l,0,l.length,a);return l.subarray(0,h).toString("utf8")}finally{Ke(d)}}catch{return""}},write:(s)=>void process.stdout.write(s),wait:(s)=>new Promise((a)=>{if(e){a();return}let o=setTimeout(a,s);r=()=>{clearTimeout(o),a()}}),stopped:()=>e}}function xe(e){let r=L(e);if(r.id===void 0||r.id==="")throw new t({code:"cli_daemon_agent_id_missing",message:`${e} declares no id, so there is no stable name to install a service under.`,hint:"A service label is derived from the manifest id and has to survive a rename of the directory. Add `id: <name>` to the manifest."});return r.id}function k(e){return xA(qe(e),U())}function M(e){try{return be(e).size}catch{return}}function B(e,r){try{let i=Ye(e,"utf8").trimEnd();if(i==="")return"";return i.split(`
123
+ `).slice(-r).join(`
124
+ `)}catch{return""}}var vt=R(A.envPrefix);import{existsSync as mn}from"node:fs";function Xo(e=process.env){return mn("/.dockerenv")||e.container!==void 0}function vn(e){let r=e.env??process.env;if(!e.needsServer)return"command-needs-no-server";if(e.disabled===!0)return"disabled-by-flag";if(r[`${A.envPrefix}SERVICE`]!==void 0)return"is-the-service";if(r[`${A.envPrefix}NO_BOOTSTRAP`]!==void 0)return"disabled-by-env";if(Xo(r))return"in-container";if(r.CI!==void 0)return"in-ci";return}async function Eo(e){let r=vn(e);if(r!==void 0)return{kind:"skipped",reason:r};if((await uA(e.store)).length>0)return{kind:"already"};let s=e.platform??process.platform;if(!ge(s))return{kind:"manual",lines:[`${A.slug} daemon install`]};let a=e.install;if(a===void 0)return{kind:"failed",message:"no installer was supplied",hint:"This is a wiring mistake rather than a configuration one: `ensureServer` is called with an `install` callback by `index.ts`."};try{return await a()}catch(o){return{kind:"failed",message:o instanceof Error?o.message:String(o),hint:`The command ran anyway. \`${A.slug} daemon install\` reports the same failure with more detail — on macOS over SSH it is usually that a LaunchAgent needs a logged-in desktop session.`}}}function nt(e){switch(e.kind){case"started":return`started the background server · \`${A.slug} daemon uninstall\` to undo
125
+ `;case"manual":return`no server is running · ${e.lines.join(", then ")}
126
+ `;case"failed":return`could not start a background server: ${e.message}
127
+ hint: ${e.hint}
128
+ `;default:return}}async function Co(){let e=process.stdout.write.bind(process.stdout);process.stdout.write=()=>!0;try{let r=await CA({action:"install"});if(r!==n)return{kind:"failed",message:`daemon install exited ${r}`,hint:`Run \`${A.slug} daemon install\` to see what it said.`};return{kind:"started",label:`${A.slug}.server`}}finally{process.stdout.write=e}}var wn=15000,bn=250;async function cn(e={}){let r=await Eo({needsServer:!0,disabled:e.install===void 0,...e.install===void 0?{}:{install:e.install},...e.store===void 0?{}:{store:e.store},...e.env===void 0?{}:{env:e.env}}),i=Date.now()+(r.kind==="started"?e.waitMs??wn:0);for(;;){let s=await _e(e.store);if(s!==void 0||Date.now()>=i)return{outcome:r,host:s};await new Promise((a)=>setTimeout(a,bn))}}async function ot(e,r,i){let s=Ie(r),a=await ke(s,i);if(a!==void 0&&a.baseUrl!==void 0)return{ok:!0,status:200,already:!0};return await ze(e,`/v1/agents/${encodeURIComponent(s)}/start`,{},r)}async function In(e,r){let i=Ie(e),s=await ke(i,r);if(s===void 0||s.baseUrl===void 0)return{kind:"no-host"};let a=await ze(s,`/v1/agents/${encodeURIComponent(i)}/reload`,{},e);if(a.ok){let o=a.body;return{kind:"reloaded",pid:s.pid,adopted:o?.adopted??[]}}if(a.status===409)return{kind:"busy",pid:s.pid};return{kind:"failed",pid:s.pid,status:a.status,...a.detail===void 0?{}:{detail:a.detail},...a.hint===void 0?{}:{hint:a.hint}}}async function Nt(e,r){let i=Ie(e);if(i==="")return;let s=await ke(i,r);if(s===void 0||s.baseUrl===void 0)return;let a=await _t(s,"GET",`/v1/agents/${encodeURIComponent(i)}`,e);if(!a.ok)return;let o=a.body;if(o?.channels===void 0)return;return new Map(o.channels.map((d)=>[d.id,d]))}var $n=25000,xn=120000,Sn=2000;async function ln(e){let r=e.out??((o)=>process.stdout.write(o)),i=e.pollMs??Sn,s,a=Date.now()+(e.codeWaitMs??$n);while(Date.now()<a){let o=(await Nt(e.manifestPath,e.store))?.get(e.channelId);if(o?.status==="connected")return r(`Paired. ${e.channelId} is linked.
129
+ `),"paired";if(o?.input!==void 0&&o.input.payload!==s){if(s===void 0)a=Date.now()+(e.pairWaitMs??xn);s=o.input.payload;let d=s.replace(/(.{4})(?=.)/g,"$1 ");r(`
130
+ ${o.detail??"On the phone: WhatsApp › Settings › Linked devices › Link with phone number. Enter this code"}:
131
+
132
+ ${d}
133
+
134
+ Waiting — this finishes on its own, or press ctrl-c and pair later.
135
+ `)}await new Promise((d)=>setTimeout(d,i))}return s===void 0?"no-code":"timeout"}var Pn=25000,kn=120000;async function En(e){let r=e.out??((y)=>process.stdout.write(y)),i=e.factory??Z.whatsapp;if(i===void 0)return"unavailable";let s;try{s=i({id:e.channelId,agentId:"",dir:e.dir,env:{},config:{authDir:e.authDir??"./.whatsapp",pairWith:e.number}})}catch{return"unavailable"}let a,o=!1,d,l,h=()=>{l?.(),l=void 0},f={receive:()=>{},status:(y,m,v)=>{if(y==="needs_input"&&v!==void 0&&a===void 0)a=v.payload,h();if(y==="connected")o=!0,h()},error:(y)=>{let m=y?.message;if(m!==void 0&&d===void 0)d=m}},g=async(y,m)=>{let v=Date.now()+y;while(!m()&&Date.now()<v)await new Promise((V)=>{let Te=setTimeout(V,Math.min(500,v-Date.now()));l=()=>{clearTimeout(Te),V()}})};try{if(await s.start(f),r(`
136
+ Connecting to WhatsApp…
137
+ `),await g(e.codeWaitMs??Pn,()=>a!==void 0||o),a===void 0&&!o)return r(`
138
+ No pairing code arrived${d===void 0?"":` — ${d}`}
139
+ `),"no-code";if(a!==void 0&&!o)r(`
140
+ On the phone: WhatsApp › Settings › Linked devices › Link with phone number.
141
+ `+`Enter this code for +${e.number}:
142
+
143
+ ${An(a)}
144
+
145
+ `+`Waiting — this finishes on its own, or press ctrl-c and pair later.
146
+ `),await g(e.pairWaitMs??kn,()=>o);if(o)return r(`
147
+ Paired. WhatsApp is linked to +${e.number}.
148
+ `),"paired";return"code-shown"}catch{return"no-code"}finally{await s.stop().catch(()=>{})}}function An(e){return e.length===8?`${e.slice(0,4)} ${e.slice(4)}`:e}function Ar(e){return` Pair WhatsApp later: \`${A.slug} channels pair ${e} wa\` — or from the web UI.
149
+ `}import{existsSync as Se,readFileSync as Pe,rmSync as Rn}from"node:fs";import{dirname as Ee,isAbsolute as On,join as Ae,resolve as _n}from"node:path";var Oe=new Map([["telegram","tokenEnv"]]);function uo(e){let i=L(e).channels??[],s=$o(e),a=Se(s)?rA(Pe(s,"utf8")):{};return i.map((o)=>{let d=Oe.get(o.type),l=d===void 0?void 0:typeof o[d]==="string"?o[d]:void 0;return{id:o.id,type:o.type,enabled:o.enabled!==!1,...l===void 0?{}:{credentialEnv:l},...l===void 0?{}:{credentialSet:(a[l]??"")!==""},...typeof o.pairWith==="string"?{pairWith:o.pairWith}:{},...o.type==="whatsapp"?{paired:Mn(e,o)}:{},...typeof o.authDir==="string"?{authDir:o.authDir}:{},allowFrom:o.allowFrom??[]}})}async function Cn(e,r,i){let s=L(e).channels??[],a=s.find((o)=>o.id===r);if(a===void 0)throw j(r,s.map((o)=>o.id));if(a.enabled!==!1===i)return{note:`Channel "${r}" is already ${i?"connected":"disconnected"}.`,changed:!1};return await Fe({file:e,path:["channels"],value:s.map((o)=>o.id===r?{...o,enabled:i}:{...o})}),{note:i?`Channel "${r}" is connected — it starts at the agent's next start.`:`Channel "${r}" is disconnected. A disabled channel is never constructed, so it reads no credential and opens no socket.`,changed:!0}}function un(e,r,i){let s=L(e).channels??[],a=s.find((h)=>h.id===r);if(a===void 0)throw j(r,s.map((h)=>h.id));let o=Oe.get(a.type),d=o===void 0?void 0:typeof a[o]==="string"?a[o]:void 0;if(d===void 0)throw new t({code:"channel_has_no_credential",message:`Channel "${r}" (type ${a.type}) keeps no credential in the .env.`,hint:a.type==="whatsapp"?"WhatsApp is paired by scanning a QR, not by a value anybody types. Use `channels unpair` to forget the current pairing and scan a new code.":"Only a channel whose manifest entry names an environment variable has one to set. Check the entry's own fields.",field:`channels[${r}]`});return{note:`${Re(e,d,i).note}. It is read at the agent's next start.`,variable:d}}function j(e,r){return new t({code:"channel_unknown",message:`This agent declares no channel with id "${e}".`,hint:r.length===0?"It declares no channels at all. Add one with `config set <agent> channels`, or answer the channel questions in `init`.":`Declared: ${r.join(", ")}. The id is the channel's own, not its type.`,field:"channelId"})}function dn(e,r){let i=L(e).channels??[],s=i.find((o)=>o.id===r);if(s===void 0)throw j(r,i.map((o)=>o.id));let a=Tn(e,s);if(a===void 0)throw new t({code:"channel_has_no_pairing",message:`Channel "${r}" (type ${s.type}) stores no pairing.`,hint:"Only a channel linked by scanning a code has one to forget. A credential somebody typed is changed with `channels credential`, and a channel is switched off with `channels disconnect`.",field:`channels[${r}]`});return Rn(a,{recursive:!0,force:!0}),{note:`Forgot the pairing — deleted ${a}. The next start offers a new code to scan; the old device may still be listed on the phone, which is the only place it can be removed.`}}function Tn(e,r){if(r.type!=="whatsapp")return;let i=typeof r.authDir==="string"?r.authDir:"./.whatsapp";return Ae(Ee(e),i)}function Mn(e,r){let i=typeof r.authDir==="string"?r.authDir:"./.whatsapp",s=On(i)?i:_n(Ee(e),i),a=Ae(s,"creds.json");if(!Se(a))return!1;try{return JSON.parse(Pe(a,"utf8")).registered===!0}catch{return!1}}
150
+ export{lo,Mt,CA,Xo,Eo,nt,Co,cn,ot,In,Nt,ln,En,Ar,uo,Cn,un,dn};
151
+
152
+ //# debugId=230BFD1ECB20000664756E2164756E21
153
+ //# sourceMappingURL=index-6p70fnb7.js.map