@termix-it/cryptoclaw 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1222) hide show
  1. package/CHANGELOG.md +1615 -0
  2. package/LICENSE +21 -0
  3. package/README-header.png +0 -0
  4. package/README.md +331 -0
  5. package/assets/avatar-placeholder.svg +19 -0
  6. package/assets/chrome-extension/README.md +22 -0
  7. package/assets/chrome-extension/background.js +438 -0
  8. package/assets/chrome-extension/icons/icon128.png +0 -0
  9. package/assets/chrome-extension/icons/icon16.png +0 -0
  10. package/assets/chrome-extension/icons/icon32.png +0 -0
  11. package/assets/chrome-extension/icons/icon48.png +0 -0
  12. package/assets/chrome-extension/manifest.json +25 -0
  13. package/assets/chrome-extension/options.html +196 -0
  14. package/assets/chrome-extension/options.js +59 -0
  15. package/assets/dmg-background-small.png +0 -0
  16. package/assets/dmg-background.png +0 -0
  17. package/cryptoclaw.mjs +14 -0
  18. package/dist/accounts-BPjR5SyC.js +251 -0
  19. package/dist/accounts-CIGHxE7R.js +251 -0
  20. package/dist/acp-cli-DBWmJpUJ.js +924 -0
  21. package/dist/acp-cli-DG9nygBk.js +926 -0
  22. package/dist/agent-3MZVCC-N.js +702 -0
  23. package/dist/agent-IDE9krld.js +702 -0
  24. package/dist/agent-scope-DBl1We79.js +370 -0
  25. package/dist/agent-scope-DLfFOxP6.js +370 -0
  26. package/dist/agent-scope-e_oNRhGi.js +606 -0
  27. package/dist/archive-Dy3Ezb-5.js +85 -0
  28. package/dist/archive-iT9wNsml.js +85 -0
  29. package/dist/audit-Bj_dxNaD.js +1853 -0
  30. package/dist/audit-jaTyyQX1.js +1853 -0
  31. package/dist/auth-RTEHx2eI.js +192 -0
  32. package/dist/auth-health-BlspzqyF.js +149 -0
  33. package/dist/auth-health-CCM6Z3vK.js +149 -0
  34. package/dist/auth-phxCaFNX.js +192 -0
  35. package/dist/auth-profiles-DoD7YxsD.js +2939 -0
  36. package/dist/boolean-BsqeuxE6.js +30 -0
  37. package/dist/brew-CAcErcKz.js +46 -0
  38. package/dist/brew-CqnNFIkD.js +46 -0
  39. package/dist/build-info.json +5 -0
  40. package/dist/call-D2DXG0AC.js +278 -0
  41. package/dist/call-DqxlETxE.js +278 -0
  42. package/dist/canvas-host/a2ui/.bundle.hash +1 -0
  43. package/dist/canvas-host/a2ui/a2ui.bundle.js +17765 -0
  44. package/dist/canvas-host/a2ui/index.html +307 -0
  45. package/dist/channel-options-BHpXOBuP.js +32 -0
  46. package/dist/channel-options-DUkxROTo.js +62 -0
  47. package/dist/channel-selection-BdigfMZZ.js +51 -0
  48. package/dist/channel-selection-D7jFTFec.js +51 -0
  49. package/dist/channel-summary-CobMoKN6.js +1120 -0
  50. package/dist/channel-summary-DS0kcHm2.js +1120 -0
  51. package/dist/channels-cli-D7ZNRrq7.js +1414 -0
  52. package/dist/channels-cli-DBwffwqw.js +1413 -0
  53. package/dist/channels-status-issues-C2UGSPvH.js +18 -0
  54. package/dist/channels-status-issues-Dxmd7zYk.js +18 -0
  55. package/dist/chrome-CwbWzmh4.js +1973 -0
  56. package/dist/chrome-SVqOMFxA.js +1953 -0
  57. package/dist/clack-prompter-k_egRADS.js +92 -0
  58. package/dist/clack-prompter-nSmn5cZ2.js +92 -0
  59. package/dist/cli/daemon-cli.js +2 -0
  60. package/dist/cli-C9xiWnx9.js +86 -0
  61. package/dist/cli-D6C9z94O.js +88 -0
  62. package/dist/cli-utils-B7iQwCY5.js +43 -0
  63. package/dist/cli-utils-CgOu3WAB.js +43 -0
  64. package/dist/client-BaTYzXOU.js +1617 -0
  65. package/dist/client-N6zH1neq.js +1617 -0
  66. package/dist/command-format-9IsYy-9N.js +52 -0
  67. package/dist/command-format-B0bnyrEA.js +38 -0
  68. package/dist/command-format-n_udBm8l.js +52 -0
  69. package/dist/command-options-DL1PhuUF.js +33 -0
  70. package/dist/commands-Dpeoos11.js +230 -0
  71. package/dist/completion-cli-B5nR7jt8.js +434 -0
  72. package/dist/completion-cli-CZ8zPqPs.js +773 -0
  73. package/dist/config-DSpb2aMV.js +4916 -0
  74. package/dist/config-IwiWafT3.js +5657 -0
  75. package/dist/config-dQK4rbfx.js +4916 -0
  76. package/dist/config-guard-DwIb5Y-v.js +5719 -0
  77. package/dist/configure-7M9mLC4o.js +896 -0
  78. package/dist/configure-CivCcvkA.js +896 -0
  79. package/dist/constants-C2T4hQIk.js +65 -0
  80. package/dist/constants-DBvu3LzZ.js +65 -0
  81. package/dist/control-service-BXC31sNw.js +61 -0
  82. package/dist/control-service-lVzEzp9f.js +61 -0
  83. package/dist/control-ui/apple-touch-icon.png +0 -0
  84. package/dist/control-ui/assets/index-DQ-7PWhX.js +7553 -0
  85. package/dist/control-ui/assets/index-DQ-7PWhX.js.map +1 -0
  86. package/dist/control-ui/assets/index-nlpH70Eh.css +1 -0
  87. package/dist/control-ui/favicon-32.png +0 -0
  88. package/dist/control-ui/favicon.ico +0 -0
  89. package/dist/control-ui/favicon.svg +22 -0
  90. package/dist/control-ui/index.html +17 -0
  91. package/dist/cron-cli-DS8ytfYQ.js +455 -0
  92. package/dist/cron-cli-Djb3HUdz.js +457 -0
  93. package/dist/daemon-cli-KoaJ2nJX.js +758 -0
  94. package/dist/daemon-cli-ZQIKLvAO.js +758 -0
  95. package/dist/daemon-runtime-CHWbAfKs.js +517 -0
  96. package/dist/daemon-runtime-DEjUQVjL.js +517 -0
  97. package/dist/deliver-DVRzRmNN.js +2557 -0
  98. package/dist/deliver-OfX6bSYR.js +2587 -0
  99. package/dist/deliver-sPBfRlXT.js +2587 -0
  100. package/dist/deps-BSdWD2wF.js +27 -0
  101. package/dist/deps-CZOfeWEp.js +27 -0
  102. package/dist/devices-cli-DHSpDnCS.js +207 -0
  103. package/dist/devices-cli-b9iF_uOi.js +205 -0
  104. package/dist/directory-cli-D0dTuAem.js +247 -0
  105. package/dist/directory-cli-qniSxsHo.js +245 -0
  106. package/dist/dispatcher-DA3u3CwV.js +160 -0
  107. package/dist/dns-cli-C0JUNb9O.js +201 -0
  108. package/dist/dns-cli-DwwMpMuN.js +199 -0
  109. package/dist/docs-cli-BlFHCHDz.js +161 -0
  110. package/dist/docs-cli-BpSPrY3Y.js +160 -0
  111. package/dist/doctor-Da1XgFcW.js +2584 -0
  112. package/dist/doctor-qrtookj-.js +2585 -0
  113. package/dist/entry.js +1156 -0
  114. package/dist/env-B2Cd_6IS.js +32 -0
  115. package/dist/errors--S5IAxQx.js +1952 -0
  116. package/dist/exec-CLQSz0CI.js +246 -0
  117. package/dist/exec-CW_QjkBi.js +246 -0
  118. package/dist/exec-D7I5LU33.js +1099 -0
  119. package/dist/exec-approvals-CuXem6Li.js +1043 -0
  120. package/dist/exec-approvals-P7vwSw4O.js +1043 -0
  121. package/dist/exec-approvals-cli-Csgqkksl.js +386 -0
  122. package/dist/exec-approvals-cli-Dk4yHE2L.js +388 -0
  123. package/dist/extensionAPI.js +64497 -0
  124. package/dist/format-B7OjpGnt.js +34 -0
  125. package/dist/format-Dv1wz41T.js +34 -0
  126. package/dist/gateway-cli-CJ7H2DgV.js +17352 -0
  127. package/dist/gateway-cli-CrKl-bIH.js +17352 -0
  128. package/dist/gateway-rpc--CH0NWWR.js +28 -0
  129. package/dist/gateway-rpc-BPfCU2Vi.js +28 -0
  130. package/dist/github-copilot-auth-CcPEEb3Q.js +1190 -0
  131. package/dist/github-copilot-auth-h3beCc_l.js +1190 -0
  132. package/dist/github-copilot-token-C1sArkX4.js +103 -0
  133. package/dist/github-copilot-token-DL6Pou2p.js +103 -0
  134. package/dist/github-copilot-token-hMl1wyZp.js +103 -0
  135. package/dist/gmail-setup-utils-CnVYPhaQ.js +428 -0
  136. package/dist/gmail-setup-utils-pZ9NnOvB.js +428 -0
  137. package/dist/health-format-BcsR5dtU.js +1211 -0
  138. package/dist/health-format-Pl8qK65t.js +1212 -0
  139. package/dist/help-format-BzWwbeSF.js +17 -0
  140. package/dist/help-format-CUnac_bT.js +17 -0
  141. package/dist/helpers-5yebzF4C.js +25 -0
  142. package/dist/helpers-CQI-5xS9.js +25 -0
  143. package/dist/helpers-CzQjTUbz.js +10 -0
  144. package/dist/helpers-OUt4hxkS.js +10 -0
  145. package/dist/hooks/bundled/boot-md/HOOK.md +19 -0
  146. package/dist/hooks/bundled/command-logger/HOOK.md +122 -0
  147. package/dist/hooks/bundled/session-memory/HOOK.md +109 -0
  148. package/dist/hooks/bundled/soul-evil/HOOK.md +71 -0
  149. package/dist/hooks-cli-BKHTdsn4.js +1058 -0
  150. package/dist/hooks-cli-zkLY25DX.js +1060 -0
  151. package/dist/hooks-status-BETsyuUR.js +443 -0
  152. package/dist/hooks-status-nPgxLL-x.js +443 -0
  153. package/dist/image-BFNcQzKp.js +629 -0
  154. package/dist/image-CC_YKDB-.js +1421 -0
  155. package/dist/image-DAsWVn7Q.js +629 -0
  156. package/dist/index.js +5900 -0
  157. package/dist/installs-Byb3s_8P.js +425 -0
  158. package/dist/installs-CELeuogN.js +425 -0
  159. package/dist/is-main-B6kCyqsv.js +25 -0
  160. package/dist/is-main-CBExsRNQ.js +25 -0
  161. package/dist/links-Brcj2Oc-.js +15 -0
  162. package/dist/links-cf9h8BXu.js +15 -0
  163. package/dist/loader-CU4bkeKe.js +61131 -0
  164. package/dist/logging-5MtSkLpb.js +1 -0
  165. package/dist/logging-BJRQDTME.js +15 -0
  166. package/dist/logging-CD55MXc7.js +15 -0
  167. package/dist/logging-kuFzZMsG.js +1 -0
  168. package/dist/login-qr-BCr2GKX6.js +475 -0
  169. package/dist/login-qr-BMbekoZW.js +478 -0
  170. package/dist/login-qr-HIPJAnbT.js +478 -0
  171. package/dist/logs-cli-CM7-XOcZ.js +230 -0
  172. package/dist/logs-cli-aqjT7oHu.js +228 -0
  173. package/dist/manager-C5m5qpB0.js +2871 -0
  174. package/dist/manager-CtGvmGvM.js +2872 -0
  175. package/dist/manager-DpZlm3gk.js +2870 -0
  176. package/dist/manifest-registry-BdTzIlta.js +669 -0
  177. package/dist/manifest-registry-DVQHMj0y.js +669 -0
  178. package/dist/message-channel-CfYBy4y3.js +110 -0
  179. package/dist/message-channel-CvHWS3C2.js +110 -0
  180. package/dist/model-selection-Av0fLq51.js +2940 -0
  181. package/dist/model-selection-DuI_Ue9Q.js +2691 -0
  182. package/dist/models-cli-C0JOZ5oP.js +2541 -0
  183. package/dist/models-cli-gmkzOpbq.js +2543 -0
  184. package/dist/net-D4G66Xui.js +137 -0
  185. package/dist/net-YrbuVTd2.js +137 -0
  186. package/dist/node-cli-BND9LLkM.js +1457 -0
  187. package/dist/node-cli-DNRB94ib.js +1459 -0
  188. package/dist/node-service-DTgDFo7M.js +67 -0
  189. package/dist/node-service-JEBcPQat.js +67 -0
  190. package/dist/nodes-cli-BCWlqHyR.js +1208 -0
  191. package/dist/nodes-cli-DWSo5dX7.js +1210 -0
  192. package/dist/nodes-screen-CMvShBEB.js +157 -0
  193. package/dist/nodes-screen-Cok3-EJw.js +157 -0
  194. package/dist/note-C5M2AQOP.js +73 -0
  195. package/dist/note-DEz9ZK7G.js +73 -0
  196. package/dist/onboard-channels-B75LjjVZ.js +671 -0
  197. package/dist/onboard-channels-DJz2TusQ.js +671 -0
  198. package/dist/onboard-skills-ByHkU9nx.js +3615 -0
  199. package/dist/onboard-skills-Wknr7pxR.js +3615 -0
  200. package/dist/onboarding-BejDjkx5.js +3455 -0
  201. package/dist/openclaw-root-YSGWCNem.js +84 -0
  202. package/dist/openclaw-root-_zPXSqgo.js +84 -0
  203. package/dist/pairing-cli-CFqD3IdI.js +122 -0
  204. package/dist/pairing-cli-Cn5vt4oI.js +120 -0
  205. package/dist/pairing-store-BHzy16_t.js +391 -0
  206. package/dist/pairing-store-BOhO49Bi.js +391 -0
  207. package/dist/parse-BZz5lHzQ.js +23 -0
  208. package/dist/parse-Bw0oH-rT.js +23 -0
  209. package/dist/parse-log-line-BxDgv4Uo.js +44 -0
  210. package/dist/parse-log-line-CUrpqe1w.js +44 -0
  211. package/dist/parse-timeout-D1XX_zN_.js +16 -0
  212. package/dist/parse-timeout-Du-wHHNi.js +16 -0
  213. package/dist/path-env-DQ-mM2ya.js +77 -0
  214. package/dist/path-env-eQ-HoQtS.js +77 -0
  215. package/dist/paths-C3yk0MGu.js +43 -0
  216. package/dist/paths-C90k-Dud.js +166 -0
  217. package/dist/paths-CGrNQEMk.js +201 -0
  218. package/dist/paths-D2ytuv-2.js +201 -0
  219. package/dist/paths-Dlp4VNXa.js +40 -0
  220. package/dist/paths-KUslkJRs.js +43 -0
  221. package/dist/pi-embedded-helpers-B7ARjDEK.js +1298 -0
  222. package/dist/pi-embedded-helpers-CQ9sq3Uu.js +8475 -0
  223. package/dist/pi-embedded-helpers-FPVRDeKf.js +1298 -0
  224. package/dist/pi-model-discovery-DWTTaAgY.js +20 -0
  225. package/dist/pi-model-discovery-EhM2JAQo.js +20 -0
  226. package/dist/pi-model-discovery-EwKVHlZB.js +20 -0
  227. package/dist/pi-tools.policy-Du4RZy9R.js +230 -0
  228. package/dist/plugin-auto-enable-EBxTHjFJ.js +461 -0
  229. package/dist/plugin-auto-enable-RwRwIUKC.js +461 -0
  230. package/dist/plugin-sdk/index.d.ts +8453 -0
  231. package/dist/plugin-sdk/index.js +23445 -0
  232. package/dist/plugin-sdk/pi-model-discovery-Dw3A6oXH.js +37 -0
  233. package/dist/plugins-BI-p2ba9.js +495 -0
  234. package/dist/plugins-Dk4UBZwz.js +496 -0
  235. package/dist/plugins-cli-CMg0G56J.js +441 -0
  236. package/dist/plugins-cli-CX7QeUjq.js +443 -0
  237. package/dist/ports-nXmd4Efh.js +96 -0
  238. package/dist/program-EAMJAB_2.js +191 -0
  239. package/dist/progress-D-Oc-KAH.js +133 -0
  240. package/dist/progress-DTEUicRP.js +133 -0
  241. package/dist/prompt-style-BBlJlXtd.js +9 -0
  242. package/dist/prompt-style-BntC_Eoo.js +9 -0
  243. package/dist/prompts-C2D9_VZC.js +10 -0
  244. package/dist/prompts-FbZThK8w.js +10 -0
  245. package/dist/pw-ai-D2jD_dho.js +1651 -0
  246. package/dist/pw-ai-D6JUaD41.js +1650 -0
  247. package/dist/pw-ai-ba2bHPGA.js +1649 -0
  248. package/dist/qmd-manager-B-ijyM7o.js +615 -0
  249. package/dist/qmd-manager-C_Jah5eo.js +618 -0
  250. package/dist/qmd-manager-xo4abL0u.js +618 -0
  251. package/dist/redact-1PNP01B_.js +97 -0
  252. package/dist/redact-BIMJ3ntQ.js +94 -0
  253. package/dist/redact-CVRUv382.js +97 -0
  254. package/dist/register.subclis-CJGimm3-.js +348 -0
  255. package/dist/reply-DfepuqG0.js +61133 -0
  256. package/dist/rolldown-runtime-Cbj13DAv.js +20 -0
  257. package/dist/routes-DkckwrRx.js +2410 -0
  258. package/dist/routes-Q42qtNl1.js +2410 -0
  259. package/dist/rpc-B4lvrGrD.js +95 -0
  260. package/dist/rpc-CbWcXAQK.js +95 -0
  261. package/dist/run-main-JFY3X4Xh.js +194 -0
  262. package/dist/sandbox-BGqDfFaH.js +2945 -0
  263. package/dist/sandbox-D_Tt3WRq.js +2945 -0
  264. package/dist/sandbox-cli-CaxqKiTq.js +461 -0
  265. package/dist/sandbox-cli-DA0Cbrzl.js +463 -0
  266. package/dist/security-cli-BZjA_GAD.js +508 -0
  267. package/dist/security-cli-Ct-pfF2h.js +506 -0
  268. package/dist/server-context-B9ez46MY.js +740 -0
  269. package/dist/server-context-C53lhEx_.js +740 -0
  270. package/dist/server-node-events-Cb6QOeDH.js +218 -0
  271. package/dist/server-node-events-DONmQvJg.js +216 -0
  272. package/dist/service-C0ccl5rU.js +680 -0
  273. package/dist/service-audit-AsnhO40e.js +542 -0
  274. package/dist/service-audit-BM-iyLL7.js +542 -0
  275. package/dist/service-mrQPgOXl.js +680 -0
  276. package/dist/session-cost-usage-B3HzifR9.js +692 -0
  277. package/dist/session-cost-usage-DH3c4xJA.js +692 -0
  278. package/dist/session-key-C-ig2pxJ.js +177 -0
  279. package/dist/session-key-CYpWeuht.js +177 -0
  280. package/dist/shared-CBcCIWC0.js +74 -0
  281. package/dist/shared-CtNMbLRE.js +150 -0
  282. package/dist/shared-DCh7fkR2.js +150 -0
  283. package/dist/shared-Na5zjEUc.js +74 -0
  284. package/dist/skill-scanner-AfOudYI1.js +255 -0
  285. package/dist/skill-scanner-BoGjHXUZ.js +255 -0
  286. package/dist/skills-7V483a6m.js +693 -0
  287. package/dist/skills-CsZRBUj0.js +694 -0
  288. package/dist/skills-cli-DQaq5LBX.js +290 -0
  289. package/dist/skills-cli-dVugbaAb.js +288 -0
  290. package/dist/skills-status-4_4zVBvV.js +187 -0
  291. package/dist/skills-status-cD4rfMR9.js +187 -0
  292. package/dist/sqlite-C4DljFNL.js +215 -0
  293. package/dist/sqlite-CvQzxS7q.js +197 -0
  294. package/dist/sqlite-Dnmf3LS7.js +215 -0
  295. package/dist/status-BakhDLuG.js +27 -0
  296. package/dist/status-BqtiImKF.js +21 -0
  297. package/dist/status-DHPz4Mg_.js +3364 -0
  298. package/dist/status-DSoYX3Ep.js +27 -0
  299. package/dist/status-Drziap9H.js +21 -0
  300. package/dist/subsystem-Btuh5yZj.js +834 -0
  301. package/dist/system-cli-CUQswQPX.js +83 -0
  302. package/dist/system-cli-Cz7in_Xr.js +81 -0
  303. package/dist/systemd-CFHiVC1D.js +438 -0
  304. package/dist/systemd-hints-CgQqk98i.js +19 -0
  305. package/dist/systemd-hints-DKVCFZS3.js +19 -0
  306. package/dist/systemd-kY3NnWdi.js +438 -0
  307. package/dist/systemd-linger-CFK5jDdq.js +75 -0
  308. package/dist/systemd-linger-CxBBzOjC.js +75 -0
  309. package/dist/table-DAOPkdc_.js +279 -0
  310. package/dist/table-DDQGlZSe.js +279 -0
  311. package/dist/tailnet-CZq_ZSNX.js +42 -0
  312. package/dist/tailnet-D5wOWpOX.js +42 -0
  313. package/dist/tailscale-BY0igR48.js +252 -0
  314. package/dist/tailscale-CCLcQalf.js +225 -0
  315. package/dist/tool-display-B2rS2o6B.js +795 -0
  316. package/dist/tool-display-Zbh1CRw5.js +795 -0
  317. package/dist/transcript-events-BOK6eOU8.js +17 -0
  318. package/dist/transcript-events-D2kT5WSz.js +17 -0
  319. package/dist/transcript-events-JLH5W4He.js +17 -0
  320. package/dist/tui-DFVs6pRO.js +2672 -0
  321. package/dist/tui-cli-CBKZVd1C.js +58 -0
  322. package/dist/tui-cli-DexeJOgZ.js +56 -0
  323. package/dist/tui-qPHLsB-x.js +2672 -0
  324. package/dist/update-B2q3duJD.js +317 -0
  325. package/dist/update-DNnej3C6.js +317 -0
  326. package/dist/update-cli-BPUtZjbl.js +1031 -0
  327. package/dist/update-cli-ehTYbpaU.js +1032 -0
  328. package/dist/update-runner-BfncKnU6.js +1375 -0
  329. package/dist/update-runner-DAeygRSU.js +1375 -0
  330. package/dist/usage-format-C4JfTbSp.js +36 -0
  331. package/dist/usage-format-DvowRSs-.js +36 -0
  332. package/dist/utils-7IMqr8vR.js +189 -0
  333. package/dist/utils-D7jskKIf.js +192 -0
  334. package/dist/wallet-manager-7KHKMCbT.js +264 -0
  335. package/dist/wallet-manager-CT1ykq2O.js +264 -0
  336. package/dist/webhooks-cli-C0CV-1jG.js +310 -0
  337. package/dist/webhooks-cli-DT16BygW.js +312 -0
  338. package/dist/widearea-dns-BJZTAyT3.js +127 -0
  339. package/dist/widearea-dns-Dk82I4Xa.js +127 -0
  340. package/dist/ws-6_dFpKWQ.js +13 -0
  341. package/dist/ws-D64QKPe6.js +13 -0
  342. package/dist/ws-log-BhQmGM0R.js +267 -0
  343. package/dist/ws-log-DsyLcTqD.js +267 -0
  344. package/dist/wsl-C24YfxH9.js +160 -0
  345. package/docs/.i18n/README.md +31 -0
  346. package/docs/.i18n/glossary.zh-CN.json +210 -0
  347. package/docs/.i18n/zh-CN.tm.jsonl +1329 -0
  348. package/docs/CNAME +1 -0
  349. package/docs/assets/macos-onboarding/01-macos-warning.jpeg +0 -0
  350. package/docs/assets/macos-onboarding/02-local-networks.jpeg +0 -0
  351. package/docs/assets/macos-onboarding/03-security-notice.png +0 -0
  352. package/docs/assets/macos-onboarding/04-choose-gateway.png +0 -0
  353. package/docs/assets/macos-onboarding/05-permissions.png +0 -0
  354. package/docs/assets/openclaw-logo-text-dark.png +0 -0
  355. package/docs/assets/openclaw-logo-text.png +0 -0
  356. package/docs/assets/pixel-lobster.svg +60 -0
  357. package/docs/assets/showcase/agents-ui.jpg +0 -0
  358. package/docs/assets/showcase/bambu-cli.png +0 -0
  359. package/docs/assets/showcase/codexmonitor.png +0 -0
  360. package/docs/assets/showcase/gohome-grafana.png +0 -0
  361. package/docs/assets/showcase/ios-testflight.jpg +0 -0
  362. package/docs/assets/showcase/oura-health.png +0 -0
  363. package/docs/assets/showcase/padel-cli.svg +11 -0
  364. package/docs/assets/showcase/padel-screenshot.jpg +0 -0
  365. package/docs/assets/showcase/papla-tts.jpg +0 -0
  366. package/docs/assets/showcase/pr-review-telegram.jpg +0 -0
  367. package/docs/assets/showcase/roborock-screenshot.jpg +0 -0
  368. package/docs/assets/showcase/roborock-status.svg +13 -0
  369. package/docs/assets/showcase/roof-camera-sky.jpg +0 -0
  370. package/docs/assets/showcase/snag.png +0 -0
  371. package/docs/assets/showcase/tesco-shop.jpg +0 -0
  372. package/docs/assets/showcase/wienerlinien.png +0 -0
  373. package/docs/assets/showcase/wine-cellar-skill.jpg +0 -0
  374. package/docs/assets/showcase/winix-air-purifier.jpg +0 -0
  375. package/docs/assets/showcase/xuezh-pronunciation.jpeg +0 -0
  376. package/docs/automation/auth-monitoring.md +44 -0
  377. package/docs/automation/cron-jobs.md +468 -0
  378. package/docs/automation/cron-vs-heartbeat.md +282 -0
  379. package/docs/automation/gmail-pubsub.md +256 -0
  380. package/docs/automation/poll.md +69 -0
  381. package/docs/automation/webhook.md +163 -0
  382. package/docs/bedrock.md +176 -0
  383. package/docs/brave-search.md +41 -0
  384. package/docs/broadcast-groups.md +442 -0
  385. package/docs/channels/bluebubbles.md +338 -0
  386. package/docs/channels/discord.md +476 -0
  387. package/docs/channels/feishu.md +577 -0
  388. package/docs/channels/googlechat.md +250 -0
  389. package/docs/channels/grammy.md +31 -0
  390. package/docs/channels/imessage.md +299 -0
  391. package/docs/channels/index.md +46 -0
  392. package/docs/channels/line.md +186 -0
  393. package/docs/channels/location.md +56 -0
  394. package/docs/channels/matrix.md +233 -0
  395. package/docs/channels/mattermost.md +138 -0
  396. package/docs/channels/msteams.md +768 -0
  397. package/docs/channels/nextcloud-talk.md +136 -0
  398. package/docs/channels/nostr.md +233 -0
  399. package/docs/channels/signal.md +202 -0
  400. package/docs/channels/slack.md +548 -0
  401. package/docs/channels/telegram.md +769 -0
  402. package/docs/channels/tlon.md +132 -0
  403. package/docs/channels/troubleshooting.md +29 -0
  404. package/docs/channels/twitch.md +379 -0
  405. package/docs/channels/whatsapp.md +404 -0
  406. package/docs/channels/zalo.md +189 -0
  407. package/docs/channels/zalouser.md +140 -0
  408. package/docs/cli/acp.md +170 -0
  409. package/docs/cli/agent.md +24 -0
  410. package/docs/cli/agents.md +75 -0
  411. package/docs/cli/approvals.md +50 -0
  412. package/docs/cli/browser.md +107 -0
  413. package/docs/cli/channels.md +79 -0
  414. package/docs/cli/config.md +50 -0
  415. package/docs/cli/configure.md +33 -0
  416. package/docs/cli/cron.md +42 -0
  417. package/docs/cli/dashboard.md +16 -0
  418. package/docs/cli/devices.md +70 -0
  419. package/docs/cli/directory.md +63 -0
  420. package/docs/cli/dns.md +23 -0
  421. package/docs/cli/docs.md +15 -0
  422. package/docs/cli/doctor.md +41 -0
  423. package/docs/cli/gateway.md +202 -0
  424. package/docs/cli/health.md +21 -0
  425. package/docs/cli/hooks.md +304 -0
  426. package/docs/cli/index.md +1031 -0
  427. package/docs/cli/logs.md +24 -0
  428. package/docs/cli/memory.md +45 -0
  429. package/docs/cli/message.md +239 -0
  430. package/docs/cli/models.md +79 -0
  431. package/docs/cli/node.md +112 -0
  432. package/docs/cli/nodes.md +73 -0
  433. package/docs/cli/onboard.md +43 -0
  434. package/docs/cli/pairing.md +21 -0
  435. package/docs/cli/plugins.md +62 -0
  436. package/docs/cli/reset.md +17 -0
  437. package/docs/cli/sandbox.md +152 -0
  438. package/docs/cli/security.md +26 -0
  439. package/docs/cli/sessions.md +16 -0
  440. package/docs/cli/setup.md +29 -0
  441. package/docs/cli/skills.md +26 -0
  442. package/docs/cli/status.md +26 -0
  443. package/docs/cli/system.md +60 -0
  444. package/docs/cli/tui.md +23 -0
  445. package/docs/cli/uninstall.md +17 -0
  446. package/docs/cli/update.md +98 -0
  447. package/docs/cli/voicecall.md +34 -0
  448. package/docs/cli/webhooks.md +25 -0
  449. package/docs/concepts/agent-loop.md +146 -0
  450. package/docs/concepts/agent-workspace.md +233 -0
  451. package/docs/concepts/agent.md +123 -0
  452. package/docs/concepts/architecture.md +129 -0
  453. package/docs/concepts/channel-routing.md +114 -0
  454. package/docs/concepts/compaction.md +61 -0
  455. package/docs/concepts/context.md +161 -0
  456. package/docs/concepts/features.md +53 -0
  457. package/docs/concepts/group-messages.md +84 -0
  458. package/docs/concepts/groups.md +373 -0
  459. package/docs/concepts/markdown-formatting.md +130 -0
  460. package/docs/concepts/memory.md +546 -0
  461. package/docs/concepts/messages.md +154 -0
  462. package/docs/concepts/model-failover.md +149 -0
  463. package/docs/concepts/model-providers.md +316 -0
  464. package/docs/concepts/models.md +208 -0
  465. package/docs/concepts/multi-agent.md +376 -0
  466. package/docs/concepts/oauth.md +145 -0
  467. package/docs/concepts/presence.md +102 -0
  468. package/docs/concepts/queue.md +89 -0
  469. package/docs/concepts/retry.md +69 -0
  470. package/docs/concepts/session-pruning.md +122 -0
  471. package/docs/concepts/session-tool.md +193 -0
  472. package/docs/concepts/session.md +204 -0
  473. package/docs/concepts/sessions.md +10 -0
  474. package/docs/concepts/streaming.md +135 -0
  475. package/docs/concepts/system-prompt.md +115 -0
  476. package/docs/concepts/timezone.md +91 -0
  477. package/docs/concepts/typebox.md +289 -0
  478. package/docs/concepts/typing-indicators.md +68 -0
  479. package/docs/concepts/usage-tracking.md +35 -0
  480. package/docs/date-time.md +128 -0
  481. package/docs/debug/node-issue.md +83 -0
  482. package/docs/debugging.md +162 -0
  483. package/docs/diagnostics/flags.md +91 -0
  484. package/docs/docs.json +1736 -0
  485. package/docs/environment.md +81 -0
  486. package/docs/experiments/onboarding-config-protocol.md +40 -0
  487. package/docs/experiments/plans/cron-add-hardening.md +63 -0
  488. package/docs/experiments/plans/group-policy-hardening.md +40 -0
  489. package/docs/experiments/plans/openresponses-gateway.md +123 -0
  490. package/docs/experiments/proposals/model-config.md +36 -0
  491. package/docs/experiments/research/memory.md +228 -0
  492. package/docs/gateway/authentication.md +145 -0
  493. package/docs/gateway/background-process.md +93 -0
  494. package/docs/gateway/bonjour.md +167 -0
  495. package/docs/gateway/bridge-protocol.md +89 -0
  496. package/docs/gateway/cli-backends.md +225 -0
  497. package/docs/gateway/configuration-examples.md +606 -0
  498. package/docs/gateway/configuration.md +3411 -0
  499. package/docs/gateway/discovery.md +116 -0
  500. package/docs/gateway/doctor.md +282 -0
  501. package/docs/gateway/gateway-lock.md +34 -0
  502. package/docs/gateway/health.md +35 -0
  503. package/docs/gateway/heartbeat.md +362 -0
  504. package/docs/gateway/index.md +328 -0
  505. package/docs/gateway/local-models.md +150 -0
  506. package/docs/gateway/logging.md +113 -0
  507. package/docs/gateway/multiple-gateways.md +112 -0
  508. package/docs/gateway/network-model.md +17 -0
  509. package/docs/gateway/openai-http-api.md +118 -0
  510. package/docs/gateway/openresponses-http-api.md +317 -0
  511. package/docs/gateway/pairing.md +99 -0
  512. package/docs/gateway/protocol.md +221 -0
  513. package/docs/gateway/remote-gateway-readme.md +157 -0
  514. package/docs/gateway/remote.md +129 -0
  515. package/docs/gateway/sandbox-vs-tool-policy-vs-elevated.md +128 -0
  516. package/docs/gateway/sandboxing.md +193 -0
  517. package/docs/gateway/security/formal-verification.md +164 -0
  518. package/docs/gateway/security/index.md +825 -0
  519. package/docs/gateway/tailscale.md +127 -0
  520. package/docs/gateway/tools-invoke-http-api.md +85 -0
  521. package/docs/gateway/troubleshooting.md +767 -0
  522. package/docs/help/faq.md +2829 -0
  523. package/docs/help/index.md +21 -0
  524. package/docs/help/troubleshooting.md +98 -0
  525. package/docs/hooks/soul-evil.md +69 -0
  526. package/docs/hooks.md +913 -0
  527. package/docs/images/feishu-step2-create-app.png +0 -0
  528. package/docs/images/feishu-step3-credentials.png +0 -0
  529. package/docs/images/feishu-step4-permissions.png +0 -0
  530. package/docs/images/feishu-step5-bot-capability.png +0 -0
  531. package/docs/images/feishu-step6-event-subscription.png +0 -0
  532. package/docs/images/groups-flow.svg +52 -0
  533. package/docs/images/mobile-ui-screenshot.png +0 -0
  534. package/docs/index.md +192 -0
  535. package/docs/install/ansible.md +208 -0
  536. package/docs/install/bun.md +59 -0
  537. package/docs/install/development-channels.md +75 -0
  538. package/docs/install/docker.md +567 -0
  539. package/docs/install/exe-dev.md +126 -0
  540. package/docs/install/fly.md +486 -0
  541. package/docs/install/gcp.md +503 -0
  542. package/docs/install/hetzner.md +330 -0
  543. package/docs/install/index.md +187 -0
  544. package/docs/install/installer.md +123 -0
  545. package/docs/install/macos-vm.md +281 -0
  546. package/docs/install/migrating.md +192 -0
  547. package/docs/install/nix.md +96 -0
  548. package/docs/install/node.md +78 -0
  549. package/docs/install/northflank.mdx +53 -0
  550. package/docs/install/railway.mdx +99 -0
  551. package/docs/install/render.mdx +165 -0
  552. package/docs/install/uninstall.md +128 -0
  553. package/docs/install/updating.md +228 -0
  554. package/docs/logging.md +350 -0
  555. package/docs/multi-agent-sandbox-tools.md +395 -0
  556. package/docs/network.md +54 -0
  557. package/docs/nodes/audio.md +114 -0
  558. package/docs/nodes/camera.md +156 -0
  559. package/docs/nodes/images.md +72 -0
  560. package/docs/nodes/index.md +341 -0
  561. package/docs/nodes/location-command.md +113 -0
  562. package/docs/nodes/media-understanding.md +379 -0
  563. package/docs/nodes/talk.md +90 -0
  564. package/docs/nodes/voicewake.md +65 -0
  565. package/docs/perplexity.md +80 -0
  566. package/docs/pi-dev.md +70 -0
  567. package/docs/pi.md +612 -0
  568. package/docs/platforms/android.md +148 -0
  569. package/docs/platforms/digitalocean.md +262 -0
  570. package/docs/platforms/index.md +53 -0
  571. package/docs/platforms/ios.md +107 -0
  572. package/docs/platforms/linux.md +94 -0
  573. package/docs/platforms/mac/bundled-gateway.md +73 -0
  574. package/docs/platforms/mac/canvas.md +125 -0
  575. package/docs/platforms/mac/child-process.md +69 -0
  576. package/docs/platforms/mac/dev-setup.md +102 -0
  577. package/docs/platforms/mac/health.md +34 -0
  578. package/docs/platforms/mac/icon.md +31 -0
  579. package/docs/platforms/mac/logging.md +57 -0
  580. package/docs/platforms/mac/menu-bar.md +81 -0
  581. package/docs/platforms/mac/peekaboo.md +65 -0
  582. package/docs/platforms/mac/permissions.md +44 -0
  583. package/docs/platforms/mac/release.md +85 -0
  584. package/docs/platforms/mac/remote.md +83 -0
  585. package/docs/platforms/mac/signing.md +47 -0
  586. package/docs/platforms/mac/skills.md +33 -0
  587. package/docs/platforms/mac/voice-overlay.md +60 -0
  588. package/docs/platforms/mac/voicewake.md +67 -0
  589. package/docs/platforms/mac/webchat.md +41 -0
  590. package/docs/platforms/mac/xpc.md +61 -0
  591. package/docs/platforms/macos.md +203 -0
  592. package/docs/platforms/oracle.md +303 -0
  593. package/docs/platforms/raspberry-pi.md +358 -0
  594. package/docs/platforms/windows.md +159 -0
  595. package/docs/plugin.md +664 -0
  596. package/docs/plugins/agent-tools.md +99 -0
  597. package/docs/plugins/manifest.md +71 -0
  598. package/docs/plugins/voice-call.md +284 -0
  599. package/docs/plugins/zalouser.md +81 -0
  600. package/docs/prose.md +134 -0
  601. package/docs/providers/anthropic.md +152 -0
  602. package/docs/providers/claude-max-api-proxy.md +148 -0
  603. package/docs/providers/cloudflare-ai-gateway.md +71 -0
  604. package/docs/providers/deepgram.md +93 -0
  605. package/docs/providers/github-copilot.md +72 -0
  606. package/docs/providers/glm.md +33 -0
  607. package/docs/providers/index.md +63 -0
  608. package/docs/providers/minimax.md +208 -0
  609. package/docs/providers/models.md +51 -0
  610. package/docs/providers/moonshot.md +142 -0
  611. package/docs/providers/ollama.md +277 -0
  612. package/docs/providers/openai.md +62 -0
  613. package/docs/providers/opencode.md +36 -0
  614. package/docs/providers/openrouter.md +37 -0
  615. package/docs/providers/qwen.md +53 -0
  616. package/docs/providers/synthetic.md +99 -0
  617. package/docs/providers/venice.md +267 -0
  618. package/docs/providers/vercel-ai-gateway.md +50 -0
  619. package/docs/providers/xiaomi.md +64 -0
  620. package/docs/providers/zai.md +36 -0
  621. package/docs/refactor/clawnet.md +417 -0
  622. package/docs/refactor/exec-host.md +316 -0
  623. package/docs/refactor/outbound-session-mirroring.md +85 -0
  624. package/docs/refactor/plugin-sdk.md +214 -0
  625. package/docs/refactor/strict-config.md +93 -0
  626. package/docs/reference/AGENTS.default.md +124 -0
  627. package/docs/reference/RELEASING.md +120 -0
  628. package/docs/reference/api-usage-costs.md +137 -0
  629. package/docs/reference/credits.md +27 -0
  630. package/docs/reference/device-models.md +47 -0
  631. package/docs/reference/rpc.md +43 -0
  632. package/docs/reference/session-management-compaction.md +285 -0
  633. package/docs/reference/templates/AGENTS.dev.md +83 -0
  634. package/docs/reference/templates/AGENTS.md +218 -0
  635. package/docs/reference/templates/BOOT.md +10 -0
  636. package/docs/reference/templates/BOOTSTRAP.md +61 -0
  637. package/docs/reference/templates/HEARTBEAT.md +11 -0
  638. package/docs/reference/templates/IDENTITY.dev.md +47 -0
  639. package/docs/reference/templates/IDENTITY.md +27 -0
  640. package/docs/reference/templates/SOUL.dev.md +76 -0
  641. package/docs/reference/templates/SOUL.md +42 -0
  642. package/docs/reference/templates/TOOLS.dev.md +24 -0
  643. package/docs/reference/templates/TOOLS.md +46 -0
  644. package/docs/reference/templates/USER.dev.md +18 -0
  645. package/docs/reference/templates/USER.md +22 -0
  646. package/docs/reference/test.md +50 -0
  647. package/docs/reference/transcript-hygiene.md +129 -0
  648. package/docs/reference/wizard.md +268 -0
  649. package/docs/scripts.md +28 -0
  650. package/docs/security/formal-verification.md +164 -0
  651. package/docs/start/bootstrapping.md +41 -0
  652. package/docs/start/docs-directory.md +64 -0
  653. package/docs/start/getting-started.md +120 -0
  654. package/docs/start/hubs.md +197 -0
  655. package/docs/start/lore.md +219 -0
  656. package/docs/start/onboarding.md +80 -0
  657. package/docs/start/openclaw.md +224 -0
  658. package/docs/start/pairing.md +86 -0
  659. package/docs/start/quickstart.md +22 -0
  660. package/docs/start/setup.md +162 -0
  661. package/docs/start/showcase.md +416 -0
  662. package/docs/start/wizard-cli-automation.md +141 -0
  663. package/docs/start/wizard-cli-reference.md +244 -0
  664. package/docs/start/wizard.md +108 -0
  665. package/docs/style.css +3 -0
  666. package/docs/testing.md +368 -0
  667. package/docs/token-use.md +112 -0
  668. package/docs/tools/agent-send.md +53 -0
  669. package/docs/tools/apply-patch.md +50 -0
  670. package/docs/tools/browser-linux-troubleshooting.md +139 -0
  671. package/docs/tools/browser-login.md +68 -0
  672. package/docs/tools/browser.md +576 -0
  673. package/docs/tools/chrome-extension.md +178 -0
  674. package/docs/tools/clawhub.md +257 -0
  675. package/docs/tools/creating-skills.md +54 -0
  676. package/docs/tools/elevated.md +57 -0
  677. package/docs/tools/exec-approvals.md +246 -0
  678. package/docs/tools/exec.md +179 -0
  679. package/docs/tools/firecrawl.md +61 -0
  680. package/docs/tools/index.md +512 -0
  681. package/docs/tools/llm-task.md +115 -0
  682. package/docs/tools/lobster.md +342 -0
  683. package/docs/tools/reactions.md +22 -0
  684. package/docs/tools/skills-config.md +76 -0
  685. package/docs/tools/skills.md +300 -0
  686. package/docs/tools/slash-commands.md +198 -0
  687. package/docs/tools/subagents.md +151 -0
  688. package/docs/tools/thinking.md +74 -0
  689. package/docs/tools/web.md +261 -0
  690. package/docs/tts.md +396 -0
  691. package/docs/tui.md +162 -0
  692. package/docs/vps.md +43 -0
  693. package/docs/web/control-ui.md +223 -0
  694. package/docs/web/dashboard.md +46 -0
  695. package/docs/web/index.md +116 -0
  696. package/docs/web/webchat.md +49 -0
  697. package/docs/whatsapp-openclaw-ai-zh.jpg +0 -0
  698. package/docs/whatsapp-openclaw.jpg +0 -0
  699. package/docs/zh-CN/AGENTS.md +59 -0
  700. package/docs/zh-CN/automation/auth-monitoring.md +47 -0
  701. package/docs/zh-CN/automation/cron-jobs.md +424 -0
  702. package/docs/zh-CN/automation/cron-vs-heartbeat.md +286 -0
  703. package/docs/zh-CN/automation/gmail-pubsub.md +249 -0
  704. package/docs/zh-CN/automation/poll.md +76 -0
  705. package/docs/zh-CN/automation/webhook.md +163 -0
  706. package/docs/zh-CN/bedrock.md +170 -0
  707. package/docs/zh-CN/brave-search.md +48 -0
  708. package/docs/zh-CN/broadcast-groups.md +449 -0
  709. package/docs/zh-CN/channels/bluebubbles.md +271 -0
  710. package/docs/zh-CN/channels/discord.md +468 -0
  711. package/docs/zh-CN/channels/feishu.md +629 -0
  712. package/docs/zh-CN/channels/googlechat.md +257 -0
  713. package/docs/zh-CN/channels/grammy.md +38 -0
  714. package/docs/zh-CN/channels/imessage.md +302 -0
  715. package/docs/zh-CN/channels/index.md +53 -0
  716. package/docs/zh-CN/channels/line.md +180 -0
  717. package/docs/zh-CN/channels/location.md +63 -0
  718. package/docs/zh-CN/channels/matrix.md +221 -0
  719. package/docs/zh-CN/channels/mattermost.md +144 -0
  720. package/docs/zh-CN/channels/msteams.md +775 -0
  721. package/docs/zh-CN/channels/nextcloud-talk.md +142 -0
  722. package/docs/zh-CN/channels/nostr.md +240 -0
  723. package/docs/zh-CN/channels/signal.md +209 -0
  724. package/docs/zh-CN/channels/slack.md +531 -0
  725. package/docs/zh-CN/channels/telegram.md +751 -0
  726. package/docs/zh-CN/channels/tlon.md +136 -0
  727. package/docs/zh-CN/channels/troubleshooting.md +36 -0
  728. package/docs/zh-CN/channels/twitch.md +385 -0
  729. package/docs/zh-CN/channels/whatsapp.md +411 -0
  730. package/docs/zh-CN/channels/zalo.md +196 -0
  731. package/docs/zh-CN/channels/zalouser.md +147 -0
  732. package/docs/zh-CN/cli/acp.md +173 -0
  733. package/docs/zh-CN/cli/agent.md +30 -0
  734. package/docs/zh-CN/cli/agents.md +82 -0
  735. package/docs/zh-CN/cli/approvals.md +57 -0
  736. package/docs/zh-CN/cli/browser.md +114 -0
  737. package/docs/zh-CN/cli/channels.md +86 -0
  738. package/docs/zh-CN/cli/config.md +57 -0
  739. package/docs/zh-CN/cli/configure.md +38 -0
  740. package/docs/zh-CN/cli/cron.md +43 -0
  741. package/docs/zh-CN/cli/dashboard.md +23 -0
  742. package/docs/zh-CN/cli/devices.md +74 -0
  743. package/docs/zh-CN/cli/directory.md +70 -0
  744. package/docs/zh-CN/cli/dns.md +30 -0
  745. package/docs/zh-CN/cli/docs.md +22 -0
  746. package/docs/zh-CN/cli/doctor.md +48 -0
  747. package/docs/zh-CN/cli/gateway.md +206 -0
  748. package/docs/zh-CN/cli/health.md +28 -0
  749. package/docs/zh-CN/cli/hooks.md +311 -0
  750. package/docs/zh-CN/cli/index.md +1032 -0
  751. package/docs/zh-CN/cli/logs.md +31 -0
  752. package/docs/zh-CN/cli/memory.md +52 -0
  753. package/docs/zh-CN/cli/message.md +246 -0
  754. package/docs/zh-CN/cli/models.md +85 -0
  755. package/docs/zh-CN/cli/node.md +115 -0
  756. package/docs/zh-CN/cli/nodes.md +80 -0
  757. package/docs/zh-CN/cli/onboard.md +36 -0
  758. package/docs/zh-CN/cli/pairing.md +28 -0
  759. package/docs/zh-CN/cli/plugins.md +66 -0
  760. package/docs/zh-CN/cli/reset.md +24 -0
  761. package/docs/zh-CN/cli/sandbox.md +158 -0
  762. package/docs/zh-CN/cli/security.md +33 -0
  763. package/docs/zh-CN/cli/sessions.md +23 -0
  764. package/docs/zh-CN/cli/setup.md +36 -0
  765. package/docs/zh-CN/cli/skills.md +33 -0
  766. package/docs/zh-CN/cli/status.md +33 -0
  767. package/docs/zh-CN/cli/system.md +63 -0
  768. package/docs/zh-CN/cli/tui.md +30 -0
  769. package/docs/zh-CN/cli/uninstall.md +24 -0
  770. package/docs/zh-CN/cli/update.md +101 -0
  771. package/docs/zh-CN/cli/voicecall.md +41 -0
  772. package/docs/zh-CN/cli/webhooks.md +32 -0
  773. package/docs/zh-CN/concepts/agent-loop.md +146 -0
  774. package/docs/zh-CN/concepts/agent-workspace.md +219 -0
  775. package/docs/zh-CN/concepts/agent.md +115 -0
  776. package/docs/zh-CN/concepts/architecture.md +123 -0
  777. package/docs/zh-CN/concepts/channel-routing.md +117 -0
  778. package/docs/zh-CN/concepts/compaction.md +67 -0
  779. package/docs/zh-CN/concepts/context.md +168 -0
  780. package/docs/zh-CN/concepts/features.md +59 -0
  781. package/docs/zh-CN/concepts/group-messages.md +91 -0
  782. package/docs/zh-CN/concepts/groups.md +379 -0
  783. package/docs/zh-CN/concepts/markdown-formatting.md +117 -0
  784. package/docs/zh-CN/concepts/memory.md +412 -0
  785. package/docs/zh-CN/concepts/messages.md +141 -0
  786. package/docs/zh-CN/concepts/model-failover.md +145 -0
  787. package/docs/zh-CN/concepts/model-providers.md +320 -0
  788. package/docs/zh-CN/concepts/models.md +196 -0
  789. package/docs/zh-CN/concepts/multi-agent.md +372 -0
  790. package/docs/zh-CN/concepts/oauth.md +151 -0
  791. package/docs/zh-CN/concepts/presence.md +99 -0
  792. package/docs/zh-CN/concepts/queue.md +94 -0
  793. package/docs/zh-CN/concepts/retry.md +76 -0
  794. package/docs/zh-CN/concepts/session-pruning.md +129 -0
  795. package/docs/zh-CN/concepts/session-tool.md +200 -0
  796. package/docs/zh-CN/concepts/session.md +166 -0
  797. package/docs/zh-CN/concepts/sessions.md +17 -0
  798. package/docs/zh-CN/concepts/streaming.md +133 -0
  799. package/docs/zh-CN/concepts/system-prompt.md +101 -0
  800. package/docs/zh-CN/concepts/timezone.md +96 -0
  801. package/docs/zh-CN/concepts/typebox.md +284 -0
  802. package/docs/zh-CN/concepts/typing-indicators.md +74 -0
  803. package/docs/zh-CN/concepts/usage-tracking.md +42 -0
  804. package/docs/zh-CN/date-time.md +129 -0
  805. package/docs/zh-CN/debug/node-issue.md +90 -0
  806. package/docs/zh-CN/debugging.md +160 -0
  807. package/docs/zh-CN/diagnostics/flags.md +98 -0
  808. package/docs/zh-CN/environment.md +88 -0
  809. package/docs/zh-CN/experiments/onboarding-config-protocol.md +47 -0
  810. package/docs/zh-CN/experiments/plans/cron-add-hardening.md +70 -0
  811. package/docs/zh-CN/experiments/plans/group-policy-hardening.md +45 -0
  812. package/docs/zh-CN/experiments/plans/openresponses-gateway.md +121 -0
  813. package/docs/zh-CN/experiments/proposals/model-config.md +42 -0
  814. package/docs/zh-CN/experiments/research/memory.md +235 -0
  815. package/docs/zh-CN/gateway/authentication.md +142 -0
  816. package/docs/zh-CN/gateway/background-process.md +100 -0
  817. package/docs/zh-CN/gateway/bonjour.md +174 -0
  818. package/docs/zh-CN/gateway/bridge-protocol.md +86 -0
  819. package/docs/zh-CN/gateway/cli-backends.md +213 -0
  820. package/docs/zh-CN/gateway/configuration-examples.md +587 -0
  821. package/docs/zh-CN/gateway/configuration.md +3332 -0
  822. package/docs/zh-CN/gateway/discovery.md +123 -0
  823. package/docs/zh-CN/gateway/doctor.md +238 -0
  824. package/docs/zh-CN/gateway/gateway-lock.md +41 -0
  825. package/docs/zh-CN/gateway/health.md +42 -0
  826. package/docs/zh-CN/gateway/heartbeat.md +274 -0
  827. package/docs/zh-CN/gateway/index.md +335 -0
  828. package/docs/zh-CN/gateway/local-models.md +157 -0
  829. package/docs/zh-CN/gateway/logging.md +114 -0
  830. package/docs/zh-CN/gateway/multiple-gateways.md +119 -0
  831. package/docs/zh-CN/gateway/network-model.md +23 -0
  832. package/docs/zh-CN/gateway/openai-http-api.md +125 -0
  833. package/docs/zh-CN/gateway/openresponses-http-api.md +317 -0
  834. package/docs/zh-CN/gateway/pairing.md +99 -0
  835. package/docs/zh-CN/gateway/protocol.md +220 -0
  836. package/docs/zh-CN/gateway/remote-gateway-readme.md +164 -0
  837. package/docs/zh-CN/gateway/remote.md +133 -0
  838. package/docs/zh-CN/gateway/sandbox-vs-tool-policy-vs-elevated.md +135 -0
  839. package/docs/zh-CN/gateway/sandboxing.md +188 -0
  840. package/docs/zh-CN/gateway/security/formal-verification.md +169 -0
  841. package/docs/zh-CN/gateway/security/index.md +777 -0
  842. package/docs/zh-CN/gateway/tailscale.md +124 -0
  843. package/docs/zh-CN/gateway/tools-invoke-http-api.md +92 -0
  844. package/docs/zh-CN/gateway/troubleshooting.md +771 -0
  845. package/docs/zh-CN/help/faq.md +2628 -0
  846. package/docs/zh-CN/help/index.md +28 -0
  847. package/docs/zh-CN/help/troubleshooting.md +104 -0
  848. package/docs/zh-CN/hooks/soul-evil.md +72 -0
  849. package/docs/zh-CN/hooks.md +919 -0
  850. package/docs/zh-CN/index.md +186 -0
  851. package/docs/zh-CN/install/ansible.md +215 -0
  852. package/docs/zh-CN/install/bun.md +65 -0
  853. package/docs/zh-CN/install/development-channels.md +81 -0
  854. package/docs/zh-CN/install/docker.md +532 -0
  855. package/docs/zh-CN/install/exe-dev.md +127 -0
  856. package/docs/zh-CN/install/fly.md +490 -0
  857. package/docs/zh-CN/install/gcp.md +510 -0
  858. package/docs/zh-CN/install/hetzner.md +337 -0
  859. package/docs/zh-CN/install/index.md +193 -0
  860. package/docs/zh-CN/install/installer.md +128 -0
  861. package/docs/zh-CN/install/macos-vm.md +288 -0
  862. package/docs/zh-CN/install/migrating.md +199 -0
  863. package/docs/zh-CN/install/nix.md +99 -0
  864. package/docs/zh-CN/install/node.md +85 -0
  865. package/docs/zh-CN/install/northflank.mdx +60 -0
  866. package/docs/zh-CN/install/railway.mdx +106 -0
  867. package/docs/zh-CN/install/render.mdx +169 -0
  868. package/docs/zh-CN/install/uninstall.md +135 -0
  869. package/docs/zh-CN/install/updating.md +233 -0
  870. package/docs/zh-CN/logging.md +329 -0
  871. package/docs/zh-CN/multi-agent-sandbox-tools.md +401 -0
  872. package/docs/zh-CN/network.md +59 -0
  873. package/docs/zh-CN/nodes/audio.md +120 -0
  874. package/docs/zh-CN/nodes/camera.md +162 -0
  875. package/docs/zh-CN/nodes/images.md +79 -0
  876. package/docs/zh-CN/nodes/index.md +348 -0
  877. package/docs/zh-CN/nodes/location-command.md +120 -0
  878. package/docs/zh-CN/nodes/media-understanding.md +380 -0
  879. package/docs/zh-CN/nodes/talk.md +97 -0
  880. package/docs/zh-CN/nodes/voicewake.md +72 -0
  881. package/docs/zh-CN/perplexity.md +84 -0
  882. package/docs/zh-CN/pi-dev.md +77 -0
  883. package/docs/zh-CN/pi.md +619 -0
  884. package/docs/zh-CN/platforms/android.md +155 -0
  885. package/docs/zh-CN/platforms/digitalocean.md +269 -0
  886. package/docs/zh-CN/platforms/index.md +60 -0
  887. package/docs/zh-CN/platforms/ios.md +114 -0
  888. package/docs/zh-CN/platforms/linux.md +101 -0
  889. package/docs/zh-CN/platforms/mac/bundled-gateway.md +75 -0
  890. package/docs/zh-CN/platforms/mac/canvas.md +128 -0
  891. package/docs/zh-CN/platforms/mac/child-process.md +73 -0
  892. package/docs/zh-CN/platforms/mac/dev-setup.md +109 -0
  893. package/docs/zh-CN/platforms/mac/health.md +41 -0
  894. package/docs/zh-CN/platforms/mac/icon.md +38 -0
  895. package/docs/zh-CN/platforms/mac/logging.md +64 -0
  896. package/docs/zh-CN/platforms/mac/menu-bar.md +88 -0
  897. package/docs/zh-CN/platforms/mac/peekaboo.md +62 -0
  898. package/docs/zh-CN/platforms/mac/permissions.md +46 -0
  899. package/docs/zh-CN/platforms/mac/release.md +92 -0
  900. package/docs/zh-CN/platforms/mac/remote.md +90 -0
  901. package/docs/zh-CN/platforms/mac/signing.md +54 -0
  902. package/docs/zh-CN/platforms/mac/skills.md +40 -0
  903. package/docs/zh-CN/platforms/mac/voice-overlay.md +67 -0
  904. package/docs/zh-CN/platforms/mac/voicewake.md +74 -0
  905. package/docs/zh-CN/platforms/mac/webchat.md +43 -0
  906. package/docs/zh-CN/platforms/mac/xpc.md +68 -0
  907. package/docs/zh-CN/platforms/macos.md +193 -0
  908. package/docs/zh-CN/platforms/oracle.md +310 -0
  909. package/docs/zh-CN/platforms/raspberry-pi.md +365 -0
  910. package/docs/zh-CN/platforms/windows.md +156 -0
  911. package/docs/zh-CN/plugin.md +639 -0
  912. package/docs/zh-CN/plugins/agent-tools.md +99 -0
  913. package/docs/zh-CN/plugins/manifest.md +68 -0
  914. package/docs/zh-CN/plugins/voice-call.md +250 -0
  915. package/docs/zh-CN/plugins/zalouser.md +88 -0
  916. package/docs/zh-CN/prose.md +141 -0
  917. package/docs/zh-CN/providers/anthropic.md +159 -0
  918. package/docs/zh-CN/providers/claude-max-api-proxy.md +155 -0
  919. package/docs/zh-CN/providers/deepgram.md +97 -0
  920. package/docs/zh-CN/providers/github-copilot.md +67 -0
  921. package/docs/zh-CN/providers/glm.md +39 -0
  922. package/docs/zh-CN/providers/index.md +68 -0
  923. package/docs/zh-CN/providers/minimax.md +206 -0
  924. package/docs/zh-CN/providers/models.md +55 -0
  925. package/docs/zh-CN/providers/moonshot.md +145 -0
  926. package/docs/zh-CN/providers/ollama.md +230 -0
  927. package/docs/zh-CN/providers/openai.md +68 -0
  928. package/docs/zh-CN/providers/opencode.md +41 -0
  929. package/docs/zh-CN/providers/openrouter.md +43 -0
  930. package/docs/zh-CN/providers/qwen.md +55 -0
  931. package/docs/zh-CN/providers/synthetic.md +102 -0
  932. package/docs/zh-CN/providers/venice.md +274 -0
  933. package/docs/zh-CN/providers/vercel-ai-gateway.md +57 -0
  934. package/docs/zh-CN/providers/xiaomi.md +68 -0
  935. package/docs/zh-CN/providers/zai.md +41 -0
  936. package/docs/zh-CN/refactor/clawnet.md +424 -0
  937. package/docs/zh-CN/refactor/exec-host.md +323 -0
  938. package/docs/zh-CN/refactor/outbound-session-mirroring.md +92 -0
  939. package/docs/zh-CN/refactor/plugin-sdk.md +221 -0
  940. package/docs/zh-CN/refactor/strict-config.md +100 -0
  941. package/docs/zh-CN/reference/AGENTS.default.md +131 -0
  942. package/docs/zh-CN/reference/RELEASING.md +123 -0
  943. package/docs/zh-CN/reference/api-usage-costs.md +136 -0
  944. package/docs/zh-CN/reference/credits.md +34 -0
  945. package/docs/zh-CN/reference/device-models.md +54 -0
  946. package/docs/zh-CN/reference/rpc.md +48 -0
  947. package/docs/zh-CN/reference/session-management-compaction.md +287 -0
  948. package/docs/zh-CN/reference/templates/AGENTS.dev.md +89 -0
  949. package/docs/zh-CN/reference/templates/AGENTS.md +225 -0
  950. package/docs/zh-CN/reference/templates/BOOT.md +17 -0
  951. package/docs/zh-CN/reference/templates/BOOTSTRAP.md +68 -0
  952. package/docs/zh-CN/reference/templates/HEARTBEAT.md +18 -0
  953. package/docs/zh-CN/reference/templates/IDENTITY.dev.md +54 -0
  954. package/docs/zh-CN/reference/templates/IDENTITY.md +35 -0
  955. package/docs/zh-CN/reference/templates/SOUL.dev.md +83 -0
  956. package/docs/zh-CN/reference/templates/SOUL.md +49 -0
  957. package/docs/zh-CN/reference/templates/TOOLS.dev.md +31 -0
  958. package/docs/zh-CN/reference/templates/TOOLS.md +53 -0
  959. package/docs/zh-CN/reference/templates/USER.dev.md +25 -0
  960. package/docs/zh-CN/reference/templates/USER.md +30 -0
  961. package/docs/zh-CN/reference/test.md +57 -0
  962. package/docs/zh-CN/reference/transcript-hygiene.md +109 -0
  963. package/docs/zh-CN/scripts.md +35 -0
  964. package/docs/zh-CN/security/formal-verification.md +171 -0
  965. package/docs/zh-CN/start/docs-directory.md +70 -0
  966. package/docs/zh-CN/start/getting-started.md +206 -0
  967. package/docs/zh-CN/start/hubs.md +200 -0
  968. package/docs/zh-CN/start/lore.md +226 -0
  969. package/docs/zh-CN/start/onboarding.md +105 -0
  970. package/docs/zh-CN/start/openclaw.md +248 -0
  971. package/docs/zh-CN/start/pairing.md +89 -0
  972. package/docs/zh-CN/start/quickstart.md +88 -0
  973. package/docs/zh-CN/start/setup.md +153 -0
  974. package/docs/zh-CN/start/showcase.md +423 -0
  975. package/docs/zh-CN/start/wizard.md +331 -0
  976. package/docs/zh-CN/testing.md +375 -0
  977. package/docs/zh-CN/token-use.md +119 -0
  978. package/docs/zh-CN/tools/agent-send.md +59 -0
  979. package/docs/zh-CN/tools/apply-patch.md +57 -0
  980. package/docs/zh-CN/tools/browser-linux-troubleshooting.md +144 -0
  981. package/docs/zh-CN/tools/browser-login.md +75 -0
  982. package/docs/zh-CN/tools/browser.md +553 -0
  983. package/docs/zh-CN/tools/chrome-extension.md +183 -0
  984. package/docs/zh-CN/tools/clawhub.md +209 -0
  985. package/docs/zh-CN/tools/creating-skills.md +61 -0
  986. package/docs/zh-CN/tools/elevated.md +64 -0
  987. package/docs/zh-CN/tools/exec-approvals.md +234 -0
  988. package/docs/zh-CN/tools/exec.md +169 -0
  989. package/docs/zh-CN/tools/firecrawl.md +68 -0
  990. package/docs/zh-CN/tools/index.md +515 -0
  991. package/docs/zh-CN/tools/llm-task.md +117 -0
  992. package/docs/zh-CN/tools/lobster.md +349 -0
  993. package/docs/zh-CN/tools/reactions.md +29 -0
  994. package/docs/zh-CN/tools/skills-config.md +78 -0
  995. package/docs/zh-CN/tools/skills.md +279 -0
  996. package/docs/zh-CN/tools/slash-commands.md +205 -0
  997. package/docs/zh-CN/tools/subagents.md +156 -0
  998. package/docs/zh-CN/tools/thinking.md +80 -0
  999. package/docs/zh-CN/tools/web.md +257 -0
  1000. package/docs/zh-CN/tts.md +375 -0
  1001. package/docs/zh-CN/tui.md +166 -0
  1002. package/docs/zh-CN/vps.md +47 -0
  1003. package/docs/zh-CN/web/control-ui.md +191 -0
  1004. package/docs/zh-CN/web/dashboard.md +53 -0
  1005. package/docs/zh-CN/web/index.md +118 -0
  1006. package/docs/zh-CN/web/webchat.md +56 -0
  1007. package/extensions/blockchain/cryptoclaw.plugin.json +17 -0
  1008. package/extensions/blockchain/index.ts +284 -0
  1009. package/extensions/blockchain/node_modules/.bin/cryptoclaw +21 -0
  1010. package/extensions/blockchain/node_modules/.bin/tsc +21 -0
  1011. package/extensions/blockchain/node_modules/.bin/tsserver +21 -0
  1012. package/extensions/blockchain/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -0
  1013. package/extensions/blockchain/package.json +16 -0
  1014. package/extensions/blockchain/src/evm/chains.ts +150 -0
  1015. package/extensions/blockchain/src/evm/services/abi/erc1155.ts +128 -0
  1016. package/extensions/blockchain/src/evm/services/abi/erc20.ts +96 -0
  1017. package/extensions/blockchain/src/evm/services/abi/erc721.ts +130 -0
  1018. package/extensions/blockchain/src/evm/services/abi/erc8004-identity.ts +158 -0
  1019. package/extensions/blockchain/src/evm/services/abi/erc8004-reputation.ts +120 -0
  1020. package/extensions/blockchain/src/evm/services/abi/router-v2.ts +115 -0
  1021. package/extensions/blockchain/src/evm/services/abi/router-v3.ts +81 -0
  1022. package/extensions/blockchain/src/evm/services/agent-identity-config.test.ts +117 -0
  1023. package/extensions/blockchain/src/evm/services/agent-identity-config.ts +75 -0
  1024. package/extensions/blockchain/src/evm/services/agent-identity-store.ts +37 -0
  1025. package/extensions/blockchain/src/evm/services/agent-identity.ts +262 -0
  1026. package/extensions/blockchain/src/evm/services/balance.ts +76 -0
  1027. package/extensions/blockchain/src/evm/services/blocks.ts +25 -0
  1028. package/extensions/blockchain/src/evm/services/clients.ts +48 -0
  1029. package/extensions/blockchain/src/evm/services/contracts.ts +52 -0
  1030. package/extensions/blockchain/src/evm/services/dex-config.test.ts +145 -0
  1031. package/extensions/blockchain/src/evm/services/dex-config.ts +164 -0
  1032. package/extensions/blockchain/src/evm/services/ens.ts +27 -0
  1033. package/extensions/blockchain/src/evm/services/security.test.ts +127 -0
  1034. package/extensions/blockchain/src/evm/services/security.ts +110 -0
  1035. package/extensions/blockchain/src/evm/services/swap.test.ts +204 -0
  1036. package/extensions/blockchain/src/evm/services/swap.ts +534 -0
  1037. package/extensions/blockchain/src/evm/services/tokens.ts +118 -0
  1038. package/extensions/blockchain/src/evm/services/transactions.ts +54 -0
  1039. package/extensions/blockchain/src/evm/services/transfer.ts +174 -0
  1040. package/extensions/blockchain/src/evm/services/utils.ts +18 -0
  1041. package/extensions/blockchain/src/evm/tools/block-tools.ts +34 -0
  1042. package/extensions/blockchain/src/evm/tools/contract-tools.ts +138 -0
  1043. package/extensions/blockchain/src/evm/tools/identity-tools.ts +305 -0
  1044. package/extensions/blockchain/src/evm/tools/network-tools.ts +58 -0
  1045. package/extensions/blockchain/src/evm/tools/nft-tools.ts +103 -0
  1046. package/extensions/blockchain/src/evm/tools/security-tools.ts +38 -0
  1047. package/extensions/blockchain/src/evm/tools/swap-tools.ts +314 -0
  1048. package/extensions/blockchain/src/evm/tools/token-tools.ts +167 -0
  1049. package/extensions/blockchain/src/evm/tools/tx-tools.ts +73 -0
  1050. package/extensions/blockchain/src/evm/tools/wallet-tools.ts +196 -0
  1051. package/extensions/blockchain/src/tx-gate/confirmation.ts +55 -0
  1052. package/extensions/blockchain/src/tx-gate/spending-limits.ts +94 -0
  1053. package/extensions/blockchain/src/wallet/active-wallet.ts +27 -0
  1054. package/extensions/blockchain/src/wallet/key-guard.test.ts +156 -0
  1055. package/extensions/blockchain/src/wallet/key-guard.ts +80 -0
  1056. package/extensions/blockchain/src/wallet/keystore.ts +88 -0
  1057. package/extensions/blockchain/src/wallet/wallet-manager.test.ts +215 -0
  1058. package/extensions/blockchain/src/wallet/wallet-manager.ts +212 -0
  1059. package/extensions/copilot-proxy/README.md +24 -0
  1060. package/extensions/copilot-proxy/index.ts +149 -0
  1061. package/extensions/copilot-proxy/node_modules/.bin/cryptoclaw +21 -0
  1062. package/extensions/copilot-proxy/openclaw.plugin.json +9 -0
  1063. package/extensions/copilot-proxy/package.json +14 -0
  1064. package/extensions/diagnostics-otel/index.ts +15 -0
  1065. package/extensions/diagnostics-otel/node_modules/.bin/acorn +21 -0
  1066. package/extensions/diagnostics-otel/node_modules/.bin/cryptoclaw +21 -0
  1067. package/extensions/diagnostics-otel/openclaw.plugin.json +8 -0
  1068. package/extensions/diagnostics-otel/package.json +27 -0
  1069. package/extensions/diagnostics-otel/src/service.test.ts +227 -0
  1070. package/extensions/diagnostics-otel/src/service.ts +635 -0
  1071. package/extensions/discord/index.ts +17 -0
  1072. package/extensions/discord/node_modules/.bin/cryptoclaw +21 -0
  1073. package/extensions/discord/openclaw.plugin.json +9 -0
  1074. package/extensions/discord/package.json +14 -0
  1075. package/extensions/discord/src/channel.ts +422 -0
  1076. package/extensions/discord/src/runtime.ts +14 -0
  1077. package/extensions/imessage/index.ts +17 -0
  1078. package/extensions/imessage/node_modules/.bin/cryptoclaw +21 -0
  1079. package/extensions/imessage/openclaw.plugin.json +9 -0
  1080. package/extensions/imessage/package.json +14 -0
  1081. package/extensions/imessage/src/channel.ts +294 -0
  1082. package/extensions/imessage/src/runtime.ts +14 -0
  1083. package/extensions/memory-core/index.ts +38 -0
  1084. package/extensions/memory-core/node_modules/.bin/cryptoclaw +21 -0
  1085. package/extensions/memory-core/openclaw.plugin.json +9 -0
  1086. package/extensions/memory-core/package.json +17 -0
  1087. package/extensions/memory-lancedb/config.ts +139 -0
  1088. package/extensions/memory-lancedb/index.test.ts +295 -0
  1089. package/extensions/memory-lancedb/index.ts +608 -0
  1090. package/extensions/memory-lancedb/node_modules/.bin/arrow2csv +21 -0
  1091. package/extensions/memory-lancedb/node_modules/.bin/cryptoclaw +21 -0
  1092. package/extensions/memory-lancedb/node_modules/.bin/openai +21 -0
  1093. package/extensions/memory-lancedb/openclaw.plugin.json +60 -0
  1094. package/extensions/memory-lancedb/package.json +19 -0
  1095. package/extensions/nostr/CHANGELOG.md +80 -0
  1096. package/extensions/nostr/README.md +136 -0
  1097. package/extensions/nostr/index.ts +68 -0
  1098. package/extensions/nostr/node_modules/.bin/cryptoclaw +21 -0
  1099. package/extensions/nostr/node_modules/.bin/tsc +21 -0
  1100. package/extensions/nostr/node_modules/.bin/tsserver +21 -0
  1101. package/extensions/nostr/openclaw.plugin.json +9 -0
  1102. package/extensions/nostr/package.json +34 -0
  1103. package/extensions/nostr/src/channel.test.ts +151 -0
  1104. package/extensions/nostr/src/channel.ts +353 -0
  1105. package/extensions/nostr/src/config-schema.ts +90 -0
  1106. package/extensions/nostr/src/metrics.ts +478 -0
  1107. package/extensions/nostr/src/nostr-bus.fuzz.test.ts +533 -0
  1108. package/extensions/nostr/src/nostr-bus.integration.test.ts +448 -0
  1109. package/extensions/nostr/src/nostr-bus.test.ts +199 -0
  1110. package/extensions/nostr/src/nostr-bus.ts +715 -0
  1111. package/extensions/nostr/src/nostr-profile-http.test.ts +378 -0
  1112. package/extensions/nostr/src/nostr-profile-http.ts +519 -0
  1113. package/extensions/nostr/src/nostr-profile-import.test.ts +119 -0
  1114. package/extensions/nostr/src/nostr-profile-import.ts +262 -0
  1115. package/extensions/nostr/src/nostr-profile.fuzz.test.ts +477 -0
  1116. package/extensions/nostr/src/nostr-profile.test.ts +410 -0
  1117. package/extensions/nostr/src/nostr-profile.ts +277 -0
  1118. package/extensions/nostr/src/nostr-state-store.test.ts +131 -0
  1119. package/extensions/nostr/src/nostr-state-store.ts +226 -0
  1120. package/extensions/nostr/src/runtime.ts +14 -0
  1121. package/extensions/nostr/src/seen-tracker.ts +303 -0
  1122. package/extensions/nostr/src/types.test.ts +157 -0
  1123. package/extensions/nostr/src/types.ts +101 -0
  1124. package/extensions/nostr/test/setup.ts +5 -0
  1125. package/extensions/signal/index.ts +17 -0
  1126. package/extensions/signal/node_modules/.bin/cryptoclaw +21 -0
  1127. package/extensions/signal/openclaw.plugin.json +9 -0
  1128. package/extensions/signal/package.json +14 -0
  1129. package/extensions/signal/src/channel.ts +315 -0
  1130. package/extensions/signal/src/runtime.ts +14 -0
  1131. package/extensions/slack/index.ts +17 -0
  1132. package/extensions/slack/node_modules/.bin/cryptoclaw +21 -0
  1133. package/extensions/slack/openclaw.plugin.json +9 -0
  1134. package/extensions/slack/package.json +14 -0
  1135. package/extensions/slack/src/channel.ts +604 -0
  1136. package/extensions/slack/src/runtime.ts +14 -0
  1137. package/extensions/telegram/index.ts +17 -0
  1138. package/extensions/telegram/node_modules/.bin/cryptoclaw +21 -0
  1139. package/extensions/telegram/openclaw.plugin.json +9 -0
  1140. package/extensions/telegram/package.json +14 -0
  1141. package/extensions/telegram/src/channel.ts +482 -0
  1142. package/extensions/telegram/src/runtime.ts +14 -0
  1143. package/extensions/voice-call/CHANGELOG.md +115 -0
  1144. package/extensions/voice-call/README.md +139 -0
  1145. package/extensions/voice-call/index.ts +493 -0
  1146. package/extensions/voice-call/node_modules/.bin/cryptoclaw +21 -0
  1147. package/extensions/voice-call/openclaw.plugin.json +559 -0
  1148. package/extensions/voice-call/package.json +19 -0
  1149. package/extensions/voice-call/src/allowlist.ts +19 -0
  1150. package/extensions/voice-call/src/cli.ts +279 -0
  1151. package/extensions/voice-call/src/config.test.ts +234 -0
  1152. package/extensions/voice-call/src/config.ts +523 -0
  1153. package/extensions/voice-call/src/core-bridge.ts +159 -0
  1154. package/extensions/voice-call/src/manager/context.ts +21 -0
  1155. package/extensions/voice-call/src/manager/events.ts +188 -0
  1156. package/extensions/voice-call/src/manager/lookup.ts +35 -0
  1157. package/extensions/voice-call/src/manager/outbound.ts +275 -0
  1158. package/extensions/voice-call/src/manager/state.ts +48 -0
  1159. package/extensions/voice-call/src/manager/store.ts +91 -0
  1160. package/extensions/voice-call/src/manager/timers.ts +89 -0
  1161. package/extensions/voice-call/src/manager/twiml.ts +9 -0
  1162. package/extensions/voice-call/src/manager.test.ts +224 -0
  1163. package/extensions/voice-call/src/manager.ts +887 -0
  1164. package/extensions/voice-call/src/media-stream.test.ts +96 -0
  1165. package/extensions/voice-call/src/media-stream.ts +411 -0
  1166. package/extensions/voice-call/src/providers/base.ts +67 -0
  1167. package/extensions/voice-call/src/providers/index.ts +10 -0
  1168. package/extensions/voice-call/src/providers/mock.ts +165 -0
  1169. package/extensions/voice-call/src/providers/plivo.test.ts +27 -0
  1170. package/extensions/voice-call/src/providers/plivo.ts +515 -0
  1171. package/extensions/voice-call/src/providers/stt-openai-realtime.ts +311 -0
  1172. package/extensions/voice-call/src/providers/telnyx.ts +371 -0
  1173. package/extensions/voice-call/src/providers/tts-openai.ts +259 -0
  1174. package/extensions/voice-call/src/providers/twilio/api.ts +42 -0
  1175. package/extensions/voice-call/src/providers/twilio/webhook.ts +32 -0
  1176. package/extensions/voice-call/src/providers/twilio.test.ts +60 -0
  1177. package/extensions/voice-call/src/providers/twilio.ts +626 -0
  1178. package/extensions/voice-call/src/response-generator.ts +158 -0
  1179. package/extensions/voice-call/src/runtime.ts +212 -0
  1180. package/extensions/voice-call/src/telephony-audio.ts +90 -0
  1181. package/extensions/voice-call/src/telephony-tts.ts +104 -0
  1182. package/extensions/voice-call/src/tunnel.ts +314 -0
  1183. package/extensions/voice-call/src/types.ts +272 -0
  1184. package/extensions/voice-call/src/utils.ts +14 -0
  1185. package/extensions/voice-call/src/voice-mapping.ts +67 -0
  1186. package/extensions/voice-call/src/webhook-security.test.ts +377 -0
  1187. package/extensions/voice-call/src/webhook-security.ts +689 -0
  1188. package/extensions/voice-call/src/webhook.ts +491 -0
  1189. package/extensions/whatsapp/index.ts +17 -0
  1190. package/extensions/whatsapp/node_modules/.bin/cryptoclaw +21 -0
  1191. package/extensions/whatsapp/openclaw.plugin.json +9 -0
  1192. package/extensions/whatsapp/package.json +14 -0
  1193. package/extensions/whatsapp/src/channel.ts +508 -0
  1194. package/extensions/whatsapp/src/runtime.ts +14 -0
  1195. package/package.json +242 -0
  1196. package/skills/aave-bsc/SKILL.md +55 -0
  1197. package/skills/agent-identity/SKILL.md +48 -0
  1198. package/skills/bird/SKILL.md +224 -0
  1199. package/skills/canvas/SKILL.md +204 -0
  1200. package/skills/coding-agent/SKILL.md +285 -0
  1201. package/skills/coingecko/SKILL.md +114 -0
  1202. package/skills/contract-deployer/SKILL.md +42 -0
  1203. package/skills/debank/SKILL.md +143 -0
  1204. package/skills/defi-dashboard/SKILL.md +49 -0
  1205. package/skills/defillama/SKILL.md +117 -0
  1206. package/skills/discord/SKILL.md +578 -0
  1207. package/skills/dune/SKILL.md +178 -0
  1208. package/skills/etherscan/SKILL.md +117 -0
  1209. package/skills/four-meme/SKILL.md +80 -0
  1210. package/skills/gas-tracker/SKILL.md +43 -0
  1211. package/skills/github/SKILL.md +77 -0
  1212. package/skills/macro-calendar/SKILL.md +132 -0
  1213. package/skills/market-data/SKILL.md +44 -0
  1214. package/skills/nft-manager/SKILL.md +46 -0
  1215. package/skills/portfolio-tracker/SKILL.md +55 -0
  1216. package/skills/security-check/SKILL.md +153 -0
  1217. package/skills/tmux/SKILL.md +135 -0
  1218. package/skills/tmux/scripts/find-sessions.sh +112 -0
  1219. package/skills/tmux/scripts/wait-for-text.sh +83 -0
  1220. package/skills/token-swap/SKILL.md +71 -0
  1221. package/skills/wallet-manager/SKILL.md +65 -0
  1222. package/skills/whale-watcher/SKILL.md +43 -0
@@ -0,0 +1,2945 @@
1
+ import { r as STATE_DIR } from "./paths-CGrNQEMk.js";
2
+ import { c as normalizeAgentId, i as buildAgentMainSessionKey, l as normalizeMainKey, n as DEFAULT_AGENT_ID, s as normalizeAccountId$1, t as DEFAULT_ACCOUNT_ID, u as resolveAgentIdFromSessionKey } from "./session-key-CYpWeuht.js";
3
+ import { c as defaultRuntime, m as CHAT_CHANNEL_ORDER, p as CHANNEL_IDS, v as getChatChannelMeta, w as requireActivePluginRegistry } from "./subsystem-Btuh5yZj.js";
4
+ import { d as normalizeE164, h as resolveUserPath } from "./utils-D7jskKIf.js";
5
+ import { b as DEFAULT_USER_FILENAME, d as DEFAULT_AGENTS_FILENAME, f as DEFAULT_AGENT_WORKSPACE_DIR, h as DEFAULT_IDENTITY_FILENAME, l as resolveSessionAgentId, m as DEFAULT_HEARTBEAT_FILENAME, n as resolveAgentConfig, p as DEFAULT_BOOTSTRAP_FILENAME, v as DEFAULT_SOUL_FILENAME, x as ensureAgentWorkspace, y as DEFAULT_TOOLS_FILENAME } from "./agent-scope-DLfFOxP6.js";
6
+ import { t as formatCliCommand } from "./command-format-9IsYy-9N.js";
7
+ import { i as loadConfig } from "./config-dQK4rbfx.js";
8
+ import { a as normalizeWhatsAppTarget, b as normalizeChatType, c as resolveTelegramAccount, m as resolveSlackReplyToMode, p as resolveSlackAccount, r as normalizeChannelId, v as resolveDiscordAccount } from "./plugins-Dk4UBZwz.js";
9
+ import { M as DEFAULT_CRYPTOCLAW_BROWSER_COLOR, P as DEFAULT_CRYPTOCLAW_BROWSER_PROFILE_NAME, j as DEFAULT_BROWSER_EVALUATE_ENABLED } from "./chrome-CwbWzmh4.js";
10
+ import { o as syncSkillsToWorkspace } from "./skills-CsZRBUj0.js";
11
+ import { t as registerBrowserRoutes } from "./routes-DkckwrRx.js";
12
+ import { a as resolveProfile, t as createBrowserRouteContext } from "./server-context-C53lhEx_.js";
13
+ import { c as listDeliverableMessageChannels, l as normalizeMessageChannel } from "./message-channel-CvHWS3C2.js";
14
+ import { n as resolveWhatsAppAccount } from "./accounts-BPjR5SyC.js";
15
+ import { r as resolveSessionTranscriptPath, t as resolveDefaultSessionStorePath } from "./paths-C3yk0MGu.js";
16
+ import { t as emitSessionTranscriptUpdate } from "./transcript-events-D2kT5WSz.js";
17
+ import os from "node:os";
18
+ import path from "node:path";
19
+ import fs from "node:fs";
20
+ import JSON5 from "json5";
21
+ import fs$1 from "node:fs/promises";
22
+ import { spawn } from "node:child_process";
23
+ import crypto from "node:crypto";
24
+ import { CURRENT_SESSION_VERSION, SessionManager } from "@mariozechner/pi-coding-agent";
25
+ import express from "express";
26
+
27
+ //#region src/channels/conversation-label.ts
28
+ function extractConversationId(from) {
29
+ const trimmed = from?.trim();
30
+ if (!trimmed) return;
31
+ const parts = trimmed.split(":").filter(Boolean);
32
+ return parts.length > 0 ? parts[parts.length - 1] : trimmed;
33
+ }
34
+ function shouldAppendId(id) {
35
+ if (/^[0-9]+$/.test(id)) return true;
36
+ if (id.includes("@g.us")) return true;
37
+ return false;
38
+ }
39
+ function resolveConversationLabel(ctx) {
40
+ const explicit = ctx.ConversationLabel?.trim();
41
+ if (explicit) return explicit;
42
+ const threadLabel = ctx.ThreadLabel?.trim();
43
+ if (threadLabel) return threadLabel;
44
+ if (normalizeChatType(ctx.ChatType) === "direct") return ctx.SenderName?.trim() || ctx.From?.trim() || void 0;
45
+ const base = ctx.GroupChannel?.trim() || ctx.GroupSubject?.trim() || ctx.GroupSpace?.trim() || ctx.From?.trim() || "";
46
+ if (!base) return;
47
+ const id = extractConversationId(ctx.From);
48
+ if (!id) return base;
49
+ if (!shouldAppendId(id)) return base;
50
+ if (base === id) return base;
51
+ if (base.includes(id)) return base;
52
+ if (base.toLowerCase().includes(" id:")) return base;
53
+ if (base.startsWith("#") || base.startsWith("@")) return base;
54
+ return `${base} id:${id}`;
55
+ }
56
+
57
+ //#endregion
58
+ //#region src/agents/sandbox/constants.ts
59
+ const DEFAULT_SANDBOX_WORKSPACE_ROOT = path.join(os.homedir(), ".cryptoclaw", "sandboxes");
60
+ const DEFAULT_SANDBOX_IMAGE = "cryptoclaw-sandbox:bookworm-slim";
61
+ const DEFAULT_SANDBOX_CONTAINER_PREFIX = "cryptoclaw-sbx-";
62
+ const DEFAULT_SANDBOX_WORKDIR = "/workspace";
63
+ const DEFAULT_SANDBOX_IDLE_HOURS = 24;
64
+ const DEFAULT_SANDBOX_MAX_AGE_DAYS = 7;
65
+ const DEFAULT_TOOL_ALLOW = [
66
+ "exec",
67
+ "process",
68
+ "read",
69
+ "write",
70
+ "edit",
71
+ "apply_patch",
72
+ "image",
73
+ "sessions_list",
74
+ "sessions_history",
75
+ "sessions_send",
76
+ "sessions_spawn",
77
+ "session_status"
78
+ ];
79
+ const DEFAULT_TOOL_DENY = [
80
+ "browser",
81
+ "canvas",
82
+ "nodes",
83
+ "cron",
84
+ "gateway",
85
+ ...CHANNEL_IDS
86
+ ];
87
+ const DEFAULT_SANDBOX_BROWSER_IMAGE = "cryptoclaw-sandbox-browser:bookworm-slim";
88
+ const DEFAULT_SANDBOX_COMMON_IMAGE = "cryptoclaw-sandbox-common:bookworm-slim";
89
+ const DEFAULT_SANDBOX_BROWSER_PREFIX = "cryptoclaw-sbx-browser-";
90
+ const DEFAULT_SANDBOX_BROWSER_CDP_PORT = 9222;
91
+ const DEFAULT_SANDBOX_BROWSER_VNC_PORT = 5900;
92
+ const DEFAULT_SANDBOX_BROWSER_NOVNC_PORT = 6080;
93
+ const DEFAULT_SANDBOX_BROWSER_AUTOSTART_TIMEOUT_MS = 12e3;
94
+ const SANDBOX_AGENT_WORKSPACE_MOUNT = "/agent";
95
+ const resolvedSandboxStateDir = STATE_DIR ?? path.join(os.homedir(), ".cryptoclaw");
96
+ const SANDBOX_STATE_DIR = path.join(resolvedSandboxStateDir, "sandbox");
97
+ const SANDBOX_REGISTRY_PATH = path.join(SANDBOX_STATE_DIR, "containers.json");
98
+ const SANDBOX_BROWSER_REGISTRY_PATH = path.join(SANDBOX_STATE_DIR, "browsers.json");
99
+
100
+ //#endregion
101
+ //#region src/agents/tool-policy.ts
102
+ const TOOL_NAME_ALIASES = {
103
+ bash: "exec",
104
+ "apply-patch": "apply_patch"
105
+ };
106
+ const TOOL_GROUPS = {
107
+ "group:memory": ["memory_search", "memory_get"],
108
+ "group:web": ["web_search", "web_fetch"],
109
+ "group:fs": [
110
+ "read",
111
+ "write",
112
+ "edit",
113
+ "apply_patch"
114
+ ],
115
+ "group:runtime": ["exec", "process"],
116
+ "group:sessions": [
117
+ "sessions_list",
118
+ "sessions_history",
119
+ "sessions_send",
120
+ "sessions_spawn",
121
+ "session_status"
122
+ ],
123
+ "group:ui": ["browser", "canvas"],
124
+ "group:automation": ["cron", "gateway"],
125
+ "group:messaging": ["message"],
126
+ "group:nodes": ["nodes"],
127
+ "group:openclaw": [
128
+ "browser",
129
+ "canvas",
130
+ "nodes",
131
+ "cron",
132
+ "message",
133
+ "gateway",
134
+ "agents_list",
135
+ "sessions_list",
136
+ "sessions_history",
137
+ "sessions_send",
138
+ "sessions_spawn",
139
+ "session_status",
140
+ "memory_search",
141
+ "memory_get",
142
+ "web_search",
143
+ "web_fetch",
144
+ "image"
145
+ ]
146
+ };
147
+ const OWNER_ONLY_TOOL_NAMES = new Set(["whatsapp_login"]);
148
+ const TOOL_PROFILES = {
149
+ minimal: { allow: ["session_status"] },
150
+ coding: { allow: [
151
+ "group:fs",
152
+ "group:runtime",
153
+ "group:sessions",
154
+ "group:memory",
155
+ "image"
156
+ ] },
157
+ messaging: { allow: [
158
+ "group:messaging",
159
+ "sessions_list",
160
+ "sessions_history",
161
+ "sessions_send",
162
+ "session_status"
163
+ ] },
164
+ full: {}
165
+ };
166
+ function normalizeToolName(name) {
167
+ const normalized = name.trim().toLowerCase();
168
+ return TOOL_NAME_ALIASES[normalized] ?? normalized;
169
+ }
170
+ function isOwnerOnlyToolName(name) {
171
+ return OWNER_ONLY_TOOL_NAMES.has(normalizeToolName(name));
172
+ }
173
+ function applyOwnerOnlyToolPolicy(tools, senderIsOwner) {
174
+ const withGuard = tools.map((tool) => {
175
+ if (!isOwnerOnlyToolName(tool.name)) return tool;
176
+ if (senderIsOwner || !tool.execute) return tool;
177
+ return {
178
+ ...tool,
179
+ execute: async () => {
180
+ throw new Error("Tool restricted to owner senders.");
181
+ }
182
+ };
183
+ });
184
+ if (senderIsOwner) return withGuard;
185
+ return withGuard.filter((tool) => !isOwnerOnlyToolName(tool.name));
186
+ }
187
+ function normalizeToolList(list) {
188
+ if (!list) return [];
189
+ return list.map(normalizeToolName).filter(Boolean);
190
+ }
191
+ function expandToolGroups(list) {
192
+ const normalized = normalizeToolList(list);
193
+ const expanded = [];
194
+ for (const value of normalized) {
195
+ const group = TOOL_GROUPS[value];
196
+ if (group) {
197
+ expanded.push(...group);
198
+ continue;
199
+ }
200
+ expanded.push(value);
201
+ }
202
+ return Array.from(new Set(expanded));
203
+ }
204
+ function collectExplicitAllowlist(policies) {
205
+ const entries = [];
206
+ for (const policy of policies) {
207
+ if (!policy?.allow) continue;
208
+ for (const value of policy.allow) {
209
+ if (typeof value !== "string") continue;
210
+ const trimmed = value.trim();
211
+ if (trimmed) entries.push(trimmed);
212
+ }
213
+ }
214
+ return entries;
215
+ }
216
+ function buildPluginToolGroups(params) {
217
+ const all = [];
218
+ const byPlugin = /* @__PURE__ */ new Map();
219
+ for (const tool of params.tools) {
220
+ const meta = params.toolMeta(tool);
221
+ if (!meta) continue;
222
+ const name = normalizeToolName(tool.name);
223
+ all.push(name);
224
+ const pluginId = meta.pluginId.toLowerCase();
225
+ const list = byPlugin.get(pluginId) ?? [];
226
+ list.push(name);
227
+ byPlugin.set(pluginId, list);
228
+ }
229
+ return {
230
+ all,
231
+ byPlugin
232
+ };
233
+ }
234
+ function expandPluginGroups(list, groups) {
235
+ if (!list || list.length === 0) return list;
236
+ const expanded = [];
237
+ for (const entry of list) {
238
+ const normalized = normalizeToolName(entry);
239
+ if (normalized === "group:plugins") {
240
+ if (groups.all.length > 0) expanded.push(...groups.all);
241
+ else expanded.push(normalized);
242
+ continue;
243
+ }
244
+ const tools = groups.byPlugin.get(normalized);
245
+ if (tools && tools.length > 0) {
246
+ expanded.push(...tools);
247
+ continue;
248
+ }
249
+ expanded.push(normalized);
250
+ }
251
+ return Array.from(new Set(expanded));
252
+ }
253
+ function expandPolicyWithPluginGroups(policy, groups) {
254
+ if (!policy) return;
255
+ return {
256
+ allow: expandPluginGroups(policy.allow, groups),
257
+ deny: expandPluginGroups(policy.deny, groups)
258
+ };
259
+ }
260
+ function stripPluginOnlyAllowlist(policy, groups, coreTools) {
261
+ if (!policy?.allow || policy.allow.length === 0) return {
262
+ policy,
263
+ unknownAllowlist: [],
264
+ strippedAllowlist: false
265
+ };
266
+ const normalized = normalizeToolList(policy.allow);
267
+ if (normalized.length === 0) return {
268
+ policy,
269
+ unknownAllowlist: [],
270
+ strippedAllowlist: false
271
+ };
272
+ const pluginIds = new Set(groups.byPlugin.keys());
273
+ const pluginTools = new Set(groups.all);
274
+ const unknownAllowlist = [];
275
+ let hasCoreEntry = false;
276
+ for (const entry of normalized) {
277
+ if (entry === "*") {
278
+ hasCoreEntry = true;
279
+ continue;
280
+ }
281
+ const isPluginEntry = entry === "group:plugins" || pluginIds.has(entry) || pluginTools.has(entry);
282
+ const isCoreEntry = expandToolGroups([entry]).some((tool) => coreTools.has(tool));
283
+ if (isCoreEntry) hasCoreEntry = true;
284
+ if (!isCoreEntry && !isPluginEntry) unknownAllowlist.push(entry);
285
+ }
286
+ const strippedAllowlist = !hasCoreEntry;
287
+ if (strippedAllowlist) {}
288
+ return {
289
+ policy: strippedAllowlist ? {
290
+ ...policy,
291
+ allow: void 0
292
+ } : policy,
293
+ unknownAllowlist: Array.from(new Set(unknownAllowlist)),
294
+ strippedAllowlist
295
+ };
296
+ }
297
+ function resolveToolProfilePolicy(profile) {
298
+ if (!profile) return;
299
+ const resolved = TOOL_PROFILES[profile];
300
+ if (!resolved) return;
301
+ if (!resolved.allow && !resolved.deny) return;
302
+ return {
303
+ allow: resolved.allow ? [...resolved.allow] : void 0,
304
+ deny: resolved.deny ? [...resolved.deny] : void 0
305
+ };
306
+ }
307
+
308
+ //#endregion
309
+ //#region src/agents/sandbox/tool-policy.ts
310
+ function compilePattern(pattern) {
311
+ const normalized = pattern.trim().toLowerCase();
312
+ if (!normalized) return {
313
+ kind: "exact",
314
+ value: ""
315
+ };
316
+ if (normalized === "*") return { kind: "all" };
317
+ if (!normalized.includes("*")) return {
318
+ kind: "exact",
319
+ value: normalized
320
+ };
321
+ const escaped = normalized.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
322
+ return {
323
+ kind: "regex",
324
+ value: new RegExp(`^${escaped.replaceAll("\\*", ".*")}$`)
325
+ };
326
+ }
327
+ function compilePatterns(patterns) {
328
+ if (!Array.isArray(patterns)) return [];
329
+ return expandToolGroups(patterns).map(compilePattern).filter((pattern) => pattern.kind !== "exact" || pattern.value);
330
+ }
331
+ function matchesAny(name, patterns) {
332
+ for (const pattern of patterns) {
333
+ if (pattern.kind === "all") return true;
334
+ if (pattern.kind === "exact" && name === pattern.value) return true;
335
+ if (pattern.kind === "regex" && pattern.value.test(name)) return true;
336
+ }
337
+ return false;
338
+ }
339
+ function isToolAllowed(policy, name) {
340
+ const normalized = name.trim().toLowerCase();
341
+ if (matchesAny(normalized, compilePatterns(policy.deny))) return false;
342
+ const allow = compilePatterns(policy.allow);
343
+ if (allow.length === 0) return true;
344
+ return matchesAny(normalized, allow);
345
+ }
346
+ function resolveSandboxToolPolicyForAgent(cfg, agentId) {
347
+ const agentConfig = cfg && agentId ? resolveAgentConfig(cfg, agentId) : void 0;
348
+ const agentAllow = agentConfig?.tools?.sandbox?.tools?.allow;
349
+ const agentDeny = agentConfig?.tools?.sandbox?.tools?.deny;
350
+ const globalAllow = cfg?.tools?.sandbox?.tools?.allow;
351
+ const globalDeny = cfg?.tools?.sandbox?.tools?.deny;
352
+ const allowSource = Array.isArray(agentAllow) ? {
353
+ source: "agent",
354
+ key: "agents.list[].tools.sandbox.tools.allow"
355
+ } : Array.isArray(globalAllow) ? {
356
+ source: "global",
357
+ key: "tools.sandbox.tools.allow"
358
+ } : {
359
+ source: "default",
360
+ key: "tools.sandbox.tools.allow"
361
+ };
362
+ const denySource = Array.isArray(agentDeny) ? {
363
+ source: "agent",
364
+ key: "agents.list[].tools.sandbox.tools.deny"
365
+ } : Array.isArray(globalDeny) ? {
366
+ source: "global",
367
+ key: "tools.sandbox.tools.deny"
368
+ } : {
369
+ source: "default",
370
+ key: "tools.sandbox.tools.deny"
371
+ };
372
+ const deny = Array.isArray(agentDeny) ? agentDeny : Array.isArray(globalDeny) ? globalDeny : [...DEFAULT_TOOL_DENY];
373
+ const allow = Array.isArray(agentAllow) ? agentAllow : Array.isArray(globalAllow) ? globalAllow : [...DEFAULT_TOOL_ALLOW];
374
+ const expandedDeny = expandToolGroups(deny);
375
+ let expandedAllow = expandToolGroups(allow);
376
+ if (!expandedDeny.map((v) => v.toLowerCase()).includes("image") && !expandedAllow.map((v) => v.toLowerCase()).includes("image")) expandedAllow = [...expandedAllow, "image"];
377
+ return {
378
+ allow: expandedAllow,
379
+ deny: expandedDeny,
380
+ sources: {
381
+ allow: allowSource,
382
+ deny: denySource
383
+ }
384
+ };
385
+ }
386
+
387
+ //#endregion
388
+ //#region src/agents/sandbox/config.ts
389
+ function resolveSandboxScope(params) {
390
+ if (params.scope) return params.scope;
391
+ if (typeof params.perSession === "boolean") return params.perSession ? "session" : "shared";
392
+ return "agent";
393
+ }
394
+ function resolveSandboxDockerConfig(params) {
395
+ const agentDocker = params.scope === "shared" ? void 0 : params.agentDocker;
396
+ const globalDocker = params.globalDocker;
397
+ const env = agentDocker?.env ? {
398
+ ...globalDocker?.env ?? { LANG: "C.UTF-8" },
399
+ ...agentDocker.env
400
+ } : globalDocker?.env ?? { LANG: "C.UTF-8" };
401
+ const ulimits = agentDocker?.ulimits ? {
402
+ ...globalDocker?.ulimits,
403
+ ...agentDocker.ulimits
404
+ } : globalDocker?.ulimits;
405
+ const binds = [...globalDocker?.binds ?? [], ...agentDocker?.binds ?? []];
406
+ return {
407
+ image: agentDocker?.image ?? globalDocker?.image ?? DEFAULT_SANDBOX_IMAGE,
408
+ containerPrefix: agentDocker?.containerPrefix ?? globalDocker?.containerPrefix ?? DEFAULT_SANDBOX_CONTAINER_PREFIX,
409
+ workdir: agentDocker?.workdir ?? globalDocker?.workdir ?? DEFAULT_SANDBOX_WORKDIR,
410
+ readOnlyRoot: agentDocker?.readOnlyRoot ?? globalDocker?.readOnlyRoot ?? true,
411
+ tmpfs: agentDocker?.tmpfs ?? globalDocker?.tmpfs ?? [
412
+ "/tmp",
413
+ "/var/tmp",
414
+ "/run"
415
+ ],
416
+ network: agentDocker?.network ?? globalDocker?.network ?? "none",
417
+ user: agentDocker?.user ?? globalDocker?.user,
418
+ capDrop: agentDocker?.capDrop ?? globalDocker?.capDrop ?? ["ALL"],
419
+ env,
420
+ setupCommand: agentDocker?.setupCommand ?? globalDocker?.setupCommand,
421
+ pidsLimit: agentDocker?.pidsLimit ?? globalDocker?.pidsLimit,
422
+ memory: agentDocker?.memory ?? globalDocker?.memory,
423
+ memorySwap: agentDocker?.memorySwap ?? globalDocker?.memorySwap,
424
+ cpus: agentDocker?.cpus ?? globalDocker?.cpus,
425
+ ulimits,
426
+ seccompProfile: agentDocker?.seccompProfile ?? globalDocker?.seccompProfile,
427
+ apparmorProfile: agentDocker?.apparmorProfile ?? globalDocker?.apparmorProfile,
428
+ dns: agentDocker?.dns ?? globalDocker?.dns,
429
+ extraHosts: agentDocker?.extraHosts ?? globalDocker?.extraHosts,
430
+ binds: binds.length ? binds : void 0
431
+ };
432
+ }
433
+ function resolveSandboxBrowserConfig(params) {
434
+ const agentBrowser = params.scope === "shared" ? void 0 : params.agentBrowser;
435
+ const globalBrowser = params.globalBrowser;
436
+ return {
437
+ enabled: agentBrowser?.enabled ?? globalBrowser?.enabled ?? false,
438
+ image: agentBrowser?.image ?? globalBrowser?.image ?? DEFAULT_SANDBOX_BROWSER_IMAGE,
439
+ containerPrefix: agentBrowser?.containerPrefix ?? globalBrowser?.containerPrefix ?? DEFAULT_SANDBOX_BROWSER_PREFIX,
440
+ cdpPort: agentBrowser?.cdpPort ?? globalBrowser?.cdpPort ?? DEFAULT_SANDBOX_BROWSER_CDP_PORT,
441
+ vncPort: agentBrowser?.vncPort ?? globalBrowser?.vncPort ?? DEFAULT_SANDBOX_BROWSER_VNC_PORT,
442
+ noVncPort: agentBrowser?.noVncPort ?? globalBrowser?.noVncPort ?? DEFAULT_SANDBOX_BROWSER_NOVNC_PORT,
443
+ headless: agentBrowser?.headless ?? globalBrowser?.headless ?? false,
444
+ enableNoVnc: agentBrowser?.enableNoVnc ?? globalBrowser?.enableNoVnc ?? true,
445
+ allowHostControl: agentBrowser?.allowHostControl ?? globalBrowser?.allowHostControl ?? false,
446
+ autoStart: agentBrowser?.autoStart ?? globalBrowser?.autoStart ?? true,
447
+ autoStartTimeoutMs: agentBrowser?.autoStartTimeoutMs ?? globalBrowser?.autoStartTimeoutMs ?? DEFAULT_SANDBOX_BROWSER_AUTOSTART_TIMEOUT_MS
448
+ };
449
+ }
450
+ function resolveSandboxPruneConfig(params) {
451
+ const agentPrune = params.scope === "shared" ? void 0 : params.agentPrune;
452
+ const globalPrune = params.globalPrune;
453
+ return {
454
+ idleHours: agentPrune?.idleHours ?? globalPrune?.idleHours ?? DEFAULT_SANDBOX_IDLE_HOURS,
455
+ maxAgeDays: agentPrune?.maxAgeDays ?? globalPrune?.maxAgeDays ?? DEFAULT_SANDBOX_MAX_AGE_DAYS
456
+ };
457
+ }
458
+ function resolveSandboxConfigForAgent(cfg, agentId) {
459
+ const agent = cfg?.agents?.defaults?.sandbox;
460
+ let agentSandbox;
461
+ const agentConfig = cfg && agentId ? resolveAgentConfig(cfg, agentId) : void 0;
462
+ if (agentConfig?.sandbox) agentSandbox = agentConfig.sandbox;
463
+ const scope = resolveSandboxScope({
464
+ scope: agentSandbox?.scope ?? agent?.scope,
465
+ perSession: agentSandbox?.perSession ?? agent?.perSession
466
+ });
467
+ const toolPolicy = resolveSandboxToolPolicyForAgent(cfg, agentId);
468
+ return {
469
+ mode: agentSandbox?.mode ?? agent?.mode ?? "off",
470
+ scope,
471
+ workspaceAccess: agentSandbox?.workspaceAccess ?? agent?.workspaceAccess ?? "none",
472
+ workspaceRoot: agentSandbox?.workspaceRoot ?? agent?.workspaceRoot ?? DEFAULT_SANDBOX_WORKSPACE_ROOT,
473
+ docker: resolveSandboxDockerConfig({
474
+ scope,
475
+ globalDocker: agent?.docker,
476
+ agentDocker: agentSandbox?.docker
477
+ }),
478
+ browser: resolveSandboxBrowserConfig({
479
+ scope,
480
+ globalBrowser: agent?.browser,
481
+ agentBrowser: agentSandbox?.browser
482
+ }),
483
+ tools: {
484
+ allow: toolPolicy.allow,
485
+ deny: toolPolicy.deny
486
+ },
487
+ prune: resolveSandboxPruneConfig({
488
+ scope,
489
+ globalPrune: agent?.prune,
490
+ agentPrune: agentSandbox?.prune
491
+ })
492
+ };
493
+ }
494
+
495
+ //#endregion
496
+ //#region src/browser/bridge-server.ts
497
+ async function startBrowserBridgeServer(params) {
498
+ const host = params.host ?? "127.0.0.1";
499
+ const port = params.port ?? 0;
500
+ const app = express();
501
+ app.use(express.json({ limit: "1mb" }));
502
+ const authToken = params.authToken?.trim();
503
+ if (authToken) app.use((req, res, next) => {
504
+ if (String(req.headers.authorization ?? "").trim() === `Bearer ${authToken}`) return next();
505
+ res.status(401).send("Unauthorized");
506
+ });
507
+ const state = {
508
+ server: null,
509
+ port,
510
+ resolved: params.resolved,
511
+ profiles: /* @__PURE__ */ new Map()
512
+ };
513
+ registerBrowserRoutes(app, createBrowserRouteContext({
514
+ getState: () => state,
515
+ onEnsureAttachTarget: params.onEnsureAttachTarget
516
+ }));
517
+ const server = await new Promise((resolve, reject) => {
518
+ const s = app.listen(port, host, () => resolve(s));
519
+ s.once("error", reject);
520
+ });
521
+ const resolvedPort = server.address()?.port ?? port;
522
+ state.server = server;
523
+ state.port = resolvedPort;
524
+ state.resolved.controlPort = resolvedPort;
525
+ return {
526
+ server,
527
+ port: resolvedPort,
528
+ baseUrl: `http://${host}:${resolvedPort}`,
529
+ state
530
+ };
531
+ }
532
+ async function stopBrowserBridgeServer(server) {
533
+ await new Promise((resolve) => {
534
+ server.close(() => resolve());
535
+ });
536
+ }
537
+
538
+ //#endregion
539
+ //#region src/agents/sandbox/browser-bridges.ts
540
+ const BROWSER_BRIDGES = /* @__PURE__ */ new Map();
541
+
542
+ //#endregion
543
+ //#region src/agents/sandbox/config-hash.ts
544
+ function isPrimitive(value) {
545
+ return value === null || typeof value !== "object" && typeof value !== "function";
546
+ }
547
+ function normalizeForHash(value) {
548
+ if (value === void 0) return;
549
+ if (Array.isArray(value)) {
550
+ const normalized = value.map(normalizeForHash).filter((item) => item !== void 0);
551
+ const primitives = normalized.filter(isPrimitive);
552
+ if (primitives.length === normalized.length) return [...primitives].toSorted((a, b) => primitiveToString(a).localeCompare(primitiveToString(b)));
553
+ return normalized;
554
+ }
555
+ if (value && typeof value === "object") {
556
+ const entries = Object.entries(value).toSorted(([a], [b]) => a.localeCompare(b));
557
+ const normalized = {};
558
+ for (const [key, entryValue] of entries) {
559
+ const next = normalizeForHash(entryValue);
560
+ if (next !== void 0) normalized[key] = next;
561
+ }
562
+ return normalized;
563
+ }
564
+ return value;
565
+ }
566
+ function primitiveToString(value) {
567
+ if (value === null) return "null";
568
+ if (typeof value === "string") return value;
569
+ if (typeof value === "number") return String(value);
570
+ if (typeof value === "boolean") return value ? "true" : "false";
571
+ return JSON.stringify(value);
572
+ }
573
+ function computeSandboxConfigHash(input) {
574
+ const payload = normalizeForHash(input);
575
+ const raw = JSON.stringify(payload);
576
+ return crypto.createHash("sha1").update(raw).digest("hex");
577
+ }
578
+
579
+ //#endregion
580
+ //#region src/agents/sandbox/registry.ts
581
+ async function readRegistry() {
582
+ try {
583
+ const raw = await fs$1.readFile(SANDBOX_REGISTRY_PATH, "utf-8");
584
+ const parsed = JSON.parse(raw);
585
+ if (parsed && Array.isArray(parsed.entries)) return parsed;
586
+ } catch {}
587
+ return { entries: [] };
588
+ }
589
+ async function writeRegistry(registry) {
590
+ await fs$1.mkdir(SANDBOX_STATE_DIR, { recursive: true });
591
+ await fs$1.writeFile(SANDBOX_REGISTRY_PATH, `${JSON.stringify(registry, null, 2)}\n`, "utf-8");
592
+ }
593
+ async function updateRegistry(entry) {
594
+ const registry = await readRegistry();
595
+ const existing = registry.entries.find((item) => item.containerName === entry.containerName);
596
+ const next = registry.entries.filter((item) => item.containerName !== entry.containerName);
597
+ next.push({
598
+ ...entry,
599
+ createdAtMs: existing?.createdAtMs ?? entry.createdAtMs,
600
+ image: existing?.image ?? entry.image,
601
+ configHash: entry.configHash ?? existing?.configHash
602
+ });
603
+ await writeRegistry({ entries: next });
604
+ }
605
+ async function removeRegistryEntry(containerName) {
606
+ const registry = await readRegistry();
607
+ const next = registry.entries.filter((item) => item.containerName !== containerName);
608
+ if (next.length === registry.entries.length) return;
609
+ await writeRegistry({ entries: next });
610
+ }
611
+ async function readBrowserRegistry() {
612
+ try {
613
+ const raw = await fs$1.readFile(SANDBOX_BROWSER_REGISTRY_PATH, "utf-8");
614
+ const parsed = JSON.parse(raw);
615
+ if (parsed && Array.isArray(parsed.entries)) return parsed;
616
+ } catch {}
617
+ return { entries: [] };
618
+ }
619
+ async function writeBrowserRegistry(registry) {
620
+ await fs$1.mkdir(SANDBOX_STATE_DIR, { recursive: true });
621
+ await fs$1.writeFile(SANDBOX_BROWSER_REGISTRY_PATH, `${JSON.stringify(registry, null, 2)}\n`, "utf-8");
622
+ }
623
+ async function updateBrowserRegistry(entry) {
624
+ const registry = await readBrowserRegistry();
625
+ const existing = registry.entries.find((item) => item.containerName === entry.containerName);
626
+ const next = registry.entries.filter((item) => item.containerName !== entry.containerName);
627
+ next.push({
628
+ ...entry,
629
+ createdAtMs: existing?.createdAtMs ?? entry.createdAtMs,
630
+ image: existing?.image ?? entry.image
631
+ });
632
+ await writeBrowserRegistry({ entries: next });
633
+ }
634
+ async function removeBrowserRegistryEntry(containerName) {
635
+ const registry = await readBrowserRegistry();
636
+ const next = registry.entries.filter((item) => item.containerName !== containerName);
637
+ if (next.length === registry.entries.length) return;
638
+ await writeBrowserRegistry({ entries: next });
639
+ }
640
+
641
+ //#endregion
642
+ //#region src/agents/sandbox/shared.ts
643
+ function slugifySessionKey(value) {
644
+ const trimmed = value.trim() || "session";
645
+ const hash = crypto.createHash("sha1").update(trimmed).digest("hex").slice(0, 8);
646
+ return `${trimmed.toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 32) || "session"}-${hash}`;
647
+ }
648
+ function resolveSandboxWorkspaceDir(root, sessionKey) {
649
+ const resolvedRoot = resolveUserPath(root);
650
+ const slug = slugifySessionKey(sessionKey);
651
+ return path.join(resolvedRoot, slug);
652
+ }
653
+ function resolveSandboxScopeKey(scope, sessionKey) {
654
+ const trimmed = sessionKey.trim() || "main";
655
+ if (scope === "shared") return "shared";
656
+ if (scope === "session") return trimmed;
657
+ return `agent:${resolveAgentIdFromSessionKey(trimmed)}`;
658
+ }
659
+ function resolveSandboxAgentId(scopeKey) {
660
+ const trimmed = scopeKey.trim();
661
+ if (!trimmed || trimmed === "shared") return;
662
+ const parts = trimmed.split(":").filter(Boolean);
663
+ if (parts[0] === "agent" && parts[1]) return normalizeAgentId(parts[1]);
664
+ return resolveAgentIdFromSessionKey(trimmed);
665
+ }
666
+
667
+ //#endregion
668
+ //#region src/agents/sandbox/docker.ts
669
+ const HOT_CONTAINER_WINDOW_MS = 300 * 1e3;
670
+ function execDocker(args, opts) {
671
+ return new Promise((resolve, reject) => {
672
+ const child = spawn("docker", args, { stdio: [
673
+ "ignore",
674
+ "pipe",
675
+ "pipe"
676
+ ] });
677
+ let stdout = "";
678
+ let stderr = "";
679
+ child.stdout?.on("data", (chunk) => {
680
+ stdout += chunk.toString();
681
+ });
682
+ child.stderr?.on("data", (chunk) => {
683
+ stderr += chunk.toString();
684
+ });
685
+ child.on("close", (code) => {
686
+ const exitCode = code ?? 0;
687
+ if (exitCode !== 0 && !opts?.allowFailure) {
688
+ reject(new Error(stderr.trim() || `docker ${args.join(" ")} failed`));
689
+ return;
690
+ }
691
+ resolve({
692
+ stdout,
693
+ stderr,
694
+ code: exitCode
695
+ });
696
+ });
697
+ });
698
+ }
699
+ async function readDockerPort(containerName, port) {
700
+ const result = await execDocker([
701
+ "port",
702
+ containerName,
703
+ `${port}/tcp`
704
+ ], { allowFailure: true });
705
+ if (result.code !== 0) return null;
706
+ const match = (result.stdout.trim().split(/\r?\n/)[0] ?? "").match(/:(\d+)\s*$/);
707
+ if (!match) return null;
708
+ const mapped = Number.parseInt(match[1] ?? "", 10);
709
+ return Number.isFinite(mapped) ? mapped : null;
710
+ }
711
+ async function dockerImageExists(image) {
712
+ const result = await execDocker([
713
+ "image",
714
+ "inspect",
715
+ image
716
+ ], { allowFailure: true });
717
+ if (result.code === 0) return true;
718
+ const stderr = result.stderr.trim();
719
+ if (stderr.includes("No such image")) return false;
720
+ throw new Error(`Failed to inspect sandbox image: ${stderr}`);
721
+ }
722
+ async function ensureDockerImage(image) {
723
+ if (await dockerImageExists(image)) return;
724
+ if (image === DEFAULT_SANDBOX_IMAGE) {
725
+ await execDocker(["pull", "debian:bookworm-slim"]);
726
+ await execDocker([
727
+ "tag",
728
+ "debian:bookworm-slim",
729
+ DEFAULT_SANDBOX_IMAGE
730
+ ]);
731
+ return;
732
+ }
733
+ throw new Error(`Sandbox image not found: ${image}. Build or pull it first.`);
734
+ }
735
+ async function dockerContainerState(name) {
736
+ const result = await execDocker([
737
+ "inspect",
738
+ "-f",
739
+ "{{.State.Running}}",
740
+ name
741
+ ], { allowFailure: true });
742
+ if (result.code !== 0) return {
743
+ exists: false,
744
+ running: false
745
+ };
746
+ return {
747
+ exists: true,
748
+ running: result.stdout.trim() === "true"
749
+ };
750
+ }
751
+ function normalizeDockerLimit(value) {
752
+ if (value === void 0 || value === null) return;
753
+ if (typeof value === "number") return Number.isFinite(value) ? String(value) : void 0;
754
+ const trimmed = value.trim();
755
+ return trimmed ? trimmed : void 0;
756
+ }
757
+ function formatUlimitValue(name, value) {
758
+ if (!name.trim()) return null;
759
+ if (typeof value === "number" || typeof value === "string") {
760
+ const raw = String(value).trim();
761
+ return raw ? `${name}=${raw}` : null;
762
+ }
763
+ const soft = typeof value.soft === "number" ? Math.max(0, value.soft) : void 0;
764
+ const hard = typeof value.hard === "number" ? Math.max(0, value.hard) : void 0;
765
+ if (soft === void 0 && hard === void 0) return null;
766
+ if (soft === void 0) return `${name}=${hard}`;
767
+ if (hard === void 0) return `${name}=${soft}`;
768
+ return `${name}=${soft}:${hard}`;
769
+ }
770
+ function buildSandboxCreateArgs(params) {
771
+ const createdAtMs = params.createdAtMs ?? Date.now();
772
+ const args = [
773
+ "create",
774
+ "--name",
775
+ params.name
776
+ ];
777
+ args.push("--label", "cryptoclaw.sandbox=1");
778
+ args.push("--label", `cryptoclaw.sessionKey=${params.scopeKey}`);
779
+ args.push("--label", `cryptoclaw.createdAtMs=${createdAtMs}`);
780
+ if (params.configHash) args.push("--label", `cryptoclaw.configHash=${params.configHash}`);
781
+ for (const [key, value] of Object.entries(params.labels ?? {})) if (key && value) args.push("--label", `${key}=${value}`);
782
+ if (params.cfg.readOnlyRoot) args.push("--read-only");
783
+ for (const entry of params.cfg.tmpfs) args.push("--tmpfs", entry);
784
+ if (params.cfg.network) args.push("--network", params.cfg.network);
785
+ if (params.cfg.user) args.push("--user", params.cfg.user);
786
+ for (const cap of params.cfg.capDrop) args.push("--cap-drop", cap);
787
+ args.push("--security-opt", "no-new-privileges");
788
+ if (params.cfg.seccompProfile) args.push("--security-opt", `seccomp=${params.cfg.seccompProfile}`);
789
+ if (params.cfg.apparmorProfile) args.push("--security-opt", `apparmor=${params.cfg.apparmorProfile}`);
790
+ for (const entry of params.cfg.dns ?? []) if (entry.trim()) args.push("--dns", entry);
791
+ for (const entry of params.cfg.extraHosts ?? []) if (entry.trim()) args.push("--add-host", entry);
792
+ if (typeof params.cfg.pidsLimit === "number" && params.cfg.pidsLimit > 0) args.push("--pids-limit", String(params.cfg.pidsLimit));
793
+ const memory = normalizeDockerLimit(params.cfg.memory);
794
+ if (memory) args.push("--memory", memory);
795
+ const memorySwap = normalizeDockerLimit(params.cfg.memorySwap);
796
+ if (memorySwap) args.push("--memory-swap", memorySwap);
797
+ if (typeof params.cfg.cpus === "number" && params.cfg.cpus > 0) args.push("--cpus", String(params.cfg.cpus));
798
+ for (const [name, value] of Object.entries(params.cfg.ulimits ?? {})) {
799
+ const formatted = formatUlimitValue(name, value);
800
+ if (formatted) args.push("--ulimit", formatted);
801
+ }
802
+ if (params.cfg.binds?.length) for (const bind of params.cfg.binds) args.push("-v", bind);
803
+ return args;
804
+ }
805
+ async function createSandboxContainer(params) {
806
+ const { name, cfg, workspaceDir, scopeKey } = params;
807
+ await ensureDockerImage(cfg.image);
808
+ const args = buildSandboxCreateArgs({
809
+ name,
810
+ cfg,
811
+ scopeKey,
812
+ configHash: params.configHash
813
+ });
814
+ args.push("--workdir", cfg.workdir);
815
+ const mainMountSuffix = params.workspaceAccess === "ro" && workspaceDir === params.agentWorkspaceDir ? ":ro" : "";
816
+ args.push("-v", `${workspaceDir}:${cfg.workdir}${mainMountSuffix}`);
817
+ if (params.workspaceAccess !== "none" && workspaceDir !== params.agentWorkspaceDir) {
818
+ const agentMountSuffix = params.workspaceAccess === "ro" ? ":ro" : "";
819
+ args.push("-v", `${params.agentWorkspaceDir}:${SANDBOX_AGENT_WORKSPACE_MOUNT}${agentMountSuffix}`);
820
+ }
821
+ args.push(cfg.image, "sleep", "infinity");
822
+ await execDocker(args);
823
+ await execDocker(["start", name]);
824
+ if (cfg.setupCommand?.trim()) await execDocker([
825
+ "exec",
826
+ "-i",
827
+ name,
828
+ "sh",
829
+ "-lc",
830
+ cfg.setupCommand
831
+ ]);
832
+ }
833
+ async function readContainerConfigHash(containerName) {
834
+ const readLabel = async (label) => {
835
+ const result = await execDocker([
836
+ "inspect",
837
+ "-f",
838
+ `{{ index .Config.Labels "${label}" }}`,
839
+ containerName
840
+ ], { allowFailure: true });
841
+ if (result.code !== 0) return null;
842
+ const raw = result.stdout.trim();
843
+ if (!raw || raw === "<no value>") return null;
844
+ return raw;
845
+ };
846
+ return await readLabel("cryptoclaw.configHash");
847
+ }
848
+ function formatSandboxRecreateHint(params) {
849
+ if (params.scope === "session") return formatCliCommand(`cryptoclaw sandbox recreate --session ${params.sessionKey}`);
850
+ if (params.scope === "agent") return formatCliCommand(`cryptoclaw sandbox recreate --agent ${resolveSandboxAgentId(params.sessionKey) ?? "main"}`);
851
+ return formatCliCommand("cryptoclaw sandbox recreate --all");
852
+ }
853
+ async function ensureSandboxContainer(params) {
854
+ const scopeKey = resolveSandboxScopeKey(params.cfg.scope, params.sessionKey);
855
+ const slug = params.cfg.scope === "shared" ? "shared" : slugifySessionKey(scopeKey);
856
+ const containerName = `${params.cfg.docker.containerPrefix}${slug}`.slice(0, 63);
857
+ const expectedHash = computeSandboxConfigHash({
858
+ docker: params.cfg.docker,
859
+ workspaceAccess: params.cfg.workspaceAccess,
860
+ workspaceDir: params.workspaceDir,
861
+ agentWorkspaceDir: params.agentWorkspaceDir
862
+ });
863
+ const now = Date.now();
864
+ const state = await dockerContainerState(containerName);
865
+ let hasContainer = state.exists;
866
+ let running = state.running;
867
+ let currentHash = null;
868
+ let hashMismatch = false;
869
+ let registryEntry;
870
+ if (hasContainer) {
871
+ registryEntry = (await readRegistry()).entries.find((entry) => entry.containerName === containerName);
872
+ currentHash = await readContainerConfigHash(containerName);
873
+ if (!currentHash) currentHash = registryEntry?.configHash ?? null;
874
+ hashMismatch = !currentHash || currentHash !== expectedHash;
875
+ if (hashMismatch) {
876
+ const lastUsedAtMs = registryEntry?.lastUsedAtMs;
877
+ if (running && (typeof lastUsedAtMs !== "number" || now - lastUsedAtMs < HOT_CONTAINER_WINDOW_MS)) {
878
+ const hint = formatSandboxRecreateHint({
879
+ scope: params.cfg.scope,
880
+ sessionKey: scopeKey
881
+ });
882
+ defaultRuntime.log(`Sandbox config changed for ${containerName} (recently used). Recreate to apply: ${hint}`);
883
+ } else {
884
+ await execDocker([
885
+ "rm",
886
+ "-f",
887
+ containerName
888
+ ], { allowFailure: true });
889
+ hasContainer = false;
890
+ running = false;
891
+ }
892
+ }
893
+ }
894
+ if (!hasContainer) await createSandboxContainer({
895
+ name: containerName,
896
+ cfg: params.cfg.docker,
897
+ workspaceDir: params.workspaceDir,
898
+ workspaceAccess: params.cfg.workspaceAccess,
899
+ agentWorkspaceDir: params.agentWorkspaceDir,
900
+ scopeKey,
901
+ configHash: expectedHash
902
+ });
903
+ else if (!running) await execDocker(["start", containerName]);
904
+ await updateRegistry({
905
+ containerName,
906
+ sessionKey: scopeKey,
907
+ createdAtMs: now,
908
+ lastUsedAtMs: now,
909
+ image: params.cfg.docker.image,
910
+ configHash: hashMismatch && running ? currentHash ?? void 0 : expectedHash
911
+ });
912
+ return containerName;
913
+ }
914
+
915
+ //#endregion
916
+ //#region src/agents/sandbox/browser.ts
917
+ async function waitForSandboxCdp(params) {
918
+ const deadline = Date.now() + Math.max(0, params.timeoutMs);
919
+ const url = `http://127.0.0.1:${params.cdpPort}/json/version`;
920
+ while (Date.now() < deadline) {
921
+ try {
922
+ const ctrl = new AbortController();
923
+ const t = setTimeout(() => ctrl.abort(), 1e3);
924
+ try {
925
+ if ((await fetch(url, { signal: ctrl.signal })).ok) return true;
926
+ } finally {
927
+ clearTimeout(t);
928
+ }
929
+ } catch {}
930
+ await new Promise((r) => setTimeout(r, 150));
931
+ }
932
+ return false;
933
+ }
934
+ function buildSandboxBrowserResolvedConfig(params) {
935
+ return {
936
+ enabled: true,
937
+ evaluateEnabled: params.evaluateEnabled,
938
+ controlPort: params.controlPort,
939
+ cdpProtocol: "http",
940
+ cdpHost: "127.0.0.1",
941
+ cdpIsLoopback: true,
942
+ remoteCdpTimeoutMs: 1500,
943
+ remoteCdpHandshakeTimeoutMs: 3e3,
944
+ color: DEFAULT_CRYPTOCLAW_BROWSER_COLOR,
945
+ executablePath: void 0,
946
+ headless: params.headless,
947
+ noSandbox: false,
948
+ attachOnly: true,
949
+ defaultProfile: DEFAULT_CRYPTOCLAW_BROWSER_PROFILE_NAME,
950
+ profiles: { [DEFAULT_CRYPTOCLAW_BROWSER_PROFILE_NAME]: {
951
+ cdpPort: params.cdpPort,
952
+ color: DEFAULT_CRYPTOCLAW_BROWSER_COLOR
953
+ } }
954
+ };
955
+ }
956
+ async function ensureSandboxBrowserImage(image) {
957
+ if ((await execDocker([
958
+ "image",
959
+ "inspect",
960
+ image
961
+ ], { allowFailure: true })).code === 0) return;
962
+ throw new Error(`Sandbox browser image not found: ${image}. Build it with scripts/sandbox-browser-setup.sh.`);
963
+ }
964
+ async function ensureSandboxBrowser(params) {
965
+ if (!params.cfg.browser.enabled) return null;
966
+ if (!isToolAllowed(params.cfg.tools, "browser")) return null;
967
+ const slug = params.cfg.scope === "shared" ? "shared" : slugifySessionKey(params.scopeKey);
968
+ const containerName = `${params.cfg.browser.containerPrefix}${slug}`.slice(0, 63);
969
+ const state = await dockerContainerState(containerName);
970
+ if (!state.exists) {
971
+ await ensureSandboxBrowserImage(params.cfg.browser.image ?? DEFAULT_SANDBOX_BROWSER_IMAGE);
972
+ const args = buildSandboxCreateArgs({
973
+ name: containerName,
974
+ cfg: params.cfg.docker,
975
+ scopeKey: params.scopeKey,
976
+ labels: { "cryptoclaw.sandboxBrowser": "1" }
977
+ });
978
+ const mainMountSuffix = params.cfg.workspaceAccess === "ro" && params.workspaceDir === params.agentWorkspaceDir ? ":ro" : "";
979
+ args.push("-v", `${params.workspaceDir}:${params.cfg.docker.workdir}${mainMountSuffix}`);
980
+ if (params.cfg.workspaceAccess !== "none" && params.workspaceDir !== params.agentWorkspaceDir) {
981
+ const agentMountSuffix = params.cfg.workspaceAccess === "ro" ? ":ro" : "";
982
+ args.push("-v", `${params.agentWorkspaceDir}:${SANDBOX_AGENT_WORKSPACE_MOUNT}${agentMountSuffix}`);
983
+ }
984
+ args.push("-p", `127.0.0.1::${params.cfg.browser.cdpPort}`);
985
+ if (params.cfg.browser.enableNoVnc && !params.cfg.browser.headless) args.push("-p", `127.0.0.1::${params.cfg.browser.noVncPort}`);
986
+ args.push("-e", `CRYPTOCLAW_BROWSER_HEADLESS=${params.cfg.browser.headless ? "1" : "0"}`);
987
+ args.push("-e", `CRYPTOCLAW_BROWSER_ENABLE_NOVNC=${params.cfg.browser.enableNoVnc ? "1" : "0"}`);
988
+ args.push("-e", `CRYPTOCLAW_BROWSER_CDP_PORT=${params.cfg.browser.cdpPort}`);
989
+ args.push("-e", `CRYPTOCLAW_BROWSER_VNC_PORT=${params.cfg.browser.vncPort}`);
990
+ args.push("-e", `CRYPTOCLAW_BROWSER_NOVNC_PORT=${params.cfg.browser.noVncPort}`);
991
+ args.push(params.cfg.browser.image);
992
+ await execDocker(args);
993
+ await execDocker(["start", containerName]);
994
+ } else if (!state.running) await execDocker(["start", containerName]);
995
+ const mappedCdp = await readDockerPort(containerName, params.cfg.browser.cdpPort);
996
+ if (!mappedCdp) throw new Error(`Failed to resolve CDP port mapping for ${containerName}.`);
997
+ const mappedNoVnc = params.cfg.browser.enableNoVnc && !params.cfg.browser.headless ? await readDockerPort(containerName, params.cfg.browser.noVncPort) : null;
998
+ const existing = BROWSER_BRIDGES.get(params.scopeKey);
999
+ const existingProfile = existing ? resolveProfile(existing.bridge.state.resolved, DEFAULT_CRYPTOCLAW_BROWSER_PROFILE_NAME) : null;
1000
+ const shouldReuse = existing && existing.containerName === containerName && existingProfile?.cdpPort === mappedCdp;
1001
+ if (existing && !shouldReuse) {
1002
+ await stopBrowserBridgeServer(existing.bridge.server).catch(() => void 0);
1003
+ BROWSER_BRIDGES.delete(params.scopeKey);
1004
+ }
1005
+ const bridge = (() => {
1006
+ if (shouldReuse && existing) return existing.bridge;
1007
+ return null;
1008
+ })();
1009
+ const ensureBridge = async () => {
1010
+ if (bridge) return bridge;
1011
+ const onEnsureAttachTarget = params.cfg.browser.autoStart ? async () => {
1012
+ const state = await dockerContainerState(containerName);
1013
+ if (state.exists && !state.running) await execDocker(["start", containerName]);
1014
+ if (!await waitForSandboxCdp({
1015
+ cdpPort: mappedCdp,
1016
+ timeoutMs: params.cfg.browser.autoStartTimeoutMs
1017
+ })) throw new Error(`Sandbox browser CDP did not become reachable on 127.0.0.1:${mappedCdp} within ${params.cfg.browser.autoStartTimeoutMs}ms.`);
1018
+ } : void 0;
1019
+ return await startBrowserBridgeServer({
1020
+ resolved: buildSandboxBrowserResolvedConfig({
1021
+ controlPort: 0,
1022
+ cdpPort: mappedCdp,
1023
+ headless: params.cfg.browser.headless,
1024
+ evaluateEnabled: params.evaluateEnabled ?? DEFAULT_BROWSER_EVALUATE_ENABLED
1025
+ }),
1026
+ onEnsureAttachTarget
1027
+ });
1028
+ };
1029
+ const resolvedBridge = await ensureBridge();
1030
+ if (!shouldReuse) BROWSER_BRIDGES.set(params.scopeKey, {
1031
+ bridge: resolvedBridge,
1032
+ containerName
1033
+ });
1034
+ const now = Date.now();
1035
+ await updateBrowserRegistry({
1036
+ containerName,
1037
+ sessionKey: params.scopeKey,
1038
+ createdAtMs: now,
1039
+ lastUsedAtMs: now,
1040
+ image: params.cfg.browser.image,
1041
+ cdpPort: mappedCdp,
1042
+ noVncPort: mappedNoVnc ?? void 0
1043
+ });
1044
+ const noVncUrl = mappedNoVnc && params.cfg.browser.enableNoVnc && !params.cfg.browser.headless ? `http://127.0.0.1:${mappedNoVnc}/vnc.html?autoconnect=1&resize=remote` : void 0;
1045
+ return {
1046
+ bridgeUrl: resolvedBridge.baseUrl,
1047
+ noVncUrl,
1048
+ containerName
1049
+ };
1050
+ }
1051
+
1052
+ //#endregion
1053
+ //#region src/agents/sandbox/prune.ts
1054
+ let lastPruneAtMs = 0;
1055
+ async function pruneSandboxContainers(cfg) {
1056
+ const now = Date.now();
1057
+ const idleHours = cfg.prune.idleHours;
1058
+ const maxAgeDays = cfg.prune.maxAgeDays;
1059
+ if (idleHours === 0 && maxAgeDays === 0) return;
1060
+ const registry = await readRegistry();
1061
+ for (const entry of registry.entries) {
1062
+ const idleMs = now - entry.lastUsedAtMs;
1063
+ const ageMs = now - entry.createdAtMs;
1064
+ if (idleHours > 0 && idleMs > idleHours * 60 * 60 * 1e3 || maxAgeDays > 0 && ageMs > maxAgeDays * 24 * 60 * 60 * 1e3) try {
1065
+ await execDocker([
1066
+ "rm",
1067
+ "-f",
1068
+ entry.containerName
1069
+ ], { allowFailure: true });
1070
+ } catch {} finally {
1071
+ await removeRegistryEntry(entry.containerName);
1072
+ }
1073
+ }
1074
+ }
1075
+ async function pruneSandboxBrowsers(cfg) {
1076
+ const now = Date.now();
1077
+ const idleHours = cfg.prune.idleHours;
1078
+ const maxAgeDays = cfg.prune.maxAgeDays;
1079
+ if (idleHours === 0 && maxAgeDays === 0) return;
1080
+ const registry = await readBrowserRegistry();
1081
+ for (const entry of registry.entries) {
1082
+ const idleMs = now - entry.lastUsedAtMs;
1083
+ const ageMs = now - entry.createdAtMs;
1084
+ if (idleHours > 0 && idleMs > idleHours * 60 * 60 * 1e3 || maxAgeDays > 0 && ageMs > maxAgeDays * 24 * 60 * 60 * 1e3) try {
1085
+ await execDocker([
1086
+ "rm",
1087
+ "-f",
1088
+ entry.containerName
1089
+ ], { allowFailure: true });
1090
+ } catch {} finally {
1091
+ await removeBrowserRegistryEntry(entry.containerName);
1092
+ const bridge = BROWSER_BRIDGES.get(entry.sessionKey);
1093
+ if (bridge?.containerName === entry.containerName) {
1094
+ await stopBrowserBridgeServer(bridge.bridge.server).catch(() => void 0);
1095
+ BROWSER_BRIDGES.delete(entry.sessionKey);
1096
+ }
1097
+ }
1098
+ }
1099
+ }
1100
+ async function maybePruneSandboxes(cfg) {
1101
+ const now = Date.now();
1102
+ if (now - lastPruneAtMs < 300 * 1e3) return;
1103
+ lastPruneAtMs = now;
1104
+ try {
1105
+ await pruneSandboxContainers(cfg);
1106
+ await pruneSandboxBrowsers(cfg);
1107
+ } catch (error) {
1108
+ const message = error instanceof Error ? error.message : typeof error === "string" ? error : JSON.stringify(error);
1109
+ defaultRuntime.error?.(`Sandbox prune failed: ${message ?? "unknown error"}`);
1110
+ }
1111
+ }
1112
+
1113
+ //#endregion
1114
+ //#region src/config/sessions/group.ts
1115
+ const getGroupSurfaces = () => new Set([...listDeliverableMessageChannels(), "webchat"]);
1116
+ function normalizeGroupLabel(raw) {
1117
+ const trimmed = raw?.trim().toLowerCase() ?? "";
1118
+ if (!trimmed) return "";
1119
+ return trimmed.replace(/\s+/g, "-").replace(/[^a-z0-9#@._+-]+/g, "-").replace(/-{2,}/g, "-").replace(/^[-.]+|[-.]+$/g, "");
1120
+ }
1121
+ function shortenGroupId(value) {
1122
+ const trimmed = value?.trim() ?? "";
1123
+ if (!trimmed) return "";
1124
+ if (trimmed.length <= 14) return trimmed;
1125
+ return `${trimmed.slice(0, 6)}...${trimmed.slice(-4)}`;
1126
+ }
1127
+ function buildGroupDisplayName(params) {
1128
+ const providerKey = (params.provider?.trim().toLowerCase() || "group").trim();
1129
+ const groupChannel = params.groupChannel?.trim();
1130
+ const space = params.space?.trim();
1131
+ const subject = params.subject?.trim();
1132
+ const detail = (groupChannel && space ? `${space}${groupChannel.startsWith("#") ? "" : "#"}${groupChannel}` : groupChannel || subject || space || "") || "";
1133
+ const fallbackId = params.id?.trim() || params.key;
1134
+ const rawLabel = detail || fallbackId;
1135
+ let token = normalizeGroupLabel(rawLabel);
1136
+ if (!token) token = normalizeGroupLabel(shortenGroupId(rawLabel));
1137
+ if (!params.groupChannel && token.startsWith("#")) token = token.replace(/^#+/, "");
1138
+ if (token && !/^[@#]/.test(token) && !token.startsWith("g-") && !token.includes("#")) token = `g-${token}`;
1139
+ return token ? `${providerKey}:${token}` : providerKey;
1140
+ }
1141
+ function resolveGroupSessionKey(ctx) {
1142
+ const from = typeof ctx.From === "string" ? ctx.From.trim() : "";
1143
+ const chatType = ctx.ChatType?.trim().toLowerCase();
1144
+ const normalizedChatType = chatType === "channel" ? "channel" : chatType === "group" ? "group" : void 0;
1145
+ const isWhatsAppGroupId = from.toLowerCase().endsWith("@g.us");
1146
+ if (!(normalizedChatType === "group" || normalizedChatType === "channel" || from.includes(":group:") || from.includes(":channel:") || isWhatsAppGroupId)) return null;
1147
+ const providerHint = ctx.Provider?.trim().toLowerCase();
1148
+ const parts = from.split(":").filter(Boolean);
1149
+ const head = parts[0]?.trim().toLowerCase() ?? "";
1150
+ const headIsSurface = head ? getGroupSurfaces().has(head) : false;
1151
+ const provider = headIsSurface ? head : providerHint ?? (isWhatsAppGroupId ? "whatsapp" : void 0);
1152
+ if (!provider) return null;
1153
+ const second = parts[1]?.trim().toLowerCase();
1154
+ const secondIsKind = second === "group" || second === "channel";
1155
+ const kind = secondIsKind ? second : from.includes(":channel:") || normalizedChatType === "channel" ? "channel" : "group";
1156
+ const finalId = (headIsSurface ? secondIsKind ? parts.slice(2).join(":") : parts.slice(1).join(":") : from).trim().toLowerCase();
1157
+ if (!finalId) return null;
1158
+ return {
1159
+ key: `${provider}:${kind}:${finalId}`,
1160
+ channel: provider,
1161
+ id: finalId,
1162
+ chatType: kind === "channel" ? "channel" : "group"
1163
+ };
1164
+ }
1165
+
1166
+ //#endregion
1167
+ //#region src/imessage/accounts.ts
1168
+ function resolveAccountConfig$1(cfg, accountId) {
1169
+ const accounts = cfg.channels?.imessage?.accounts;
1170
+ if (!accounts || typeof accounts !== "object") return;
1171
+ return accounts[accountId];
1172
+ }
1173
+ function mergeIMessageAccountConfig(cfg, accountId) {
1174
+ const { accounts: _ignored, ...base } = cfg.channels?.imessage ?? {};
1175
+ const account = resolveAccountConfig$1(cfg, accountId) ?? {};
1176
+ return {
1177
+ ...base,
1178
+ ...account
1179
+ };
1180
+ }
1181
+ function resolveIMessageAccount(params) {
1182
+ const accountId = normalizeAccountId$1(params.accountId);
1183
+ const baseEnabled = params.cfg.channels?.imessage?.enabled !== false;
1184
+ const merged = mergeIMessageAccountConfig(params.cfg, accountId);
1185
+ const accountEnabled = merged.enabled !== false;
1186
+ const configured = Boolean(merged.cliPath?.trim() || merged.dbPath?.trim() || merged.service || merged.region?.trim() || merged.allowFrom && merged.allowFrom.length > 0 || merged.groupAllowFrom && merged.groupAllowFrom.length > 0 || merged.dmPolicy || merged.groupPolicy || typeof merged.includeAttachments === "boolean" || typeof merged.mediaMaxMb === "number" || typeof merged.textChunkLimit === "number" || merged.groups && Object.keys(merged.groups).length > 0);
1187
+ return {
1188
+ accountId,
1189
+ enabled: baseEnabled && accountEnabled,
1190
+ name: merged.name?.trim() || void 0,
1191
+ config: merged,
1192
+ configured
1193
+ };
1194
+ }
1195
+
1196
+ //#endregion
1197
+ //#region src/signal/accounts.ts
1198
+ function listConfiguredAccountIds(cfg) {
1199
+ const accounts = cfg.channels?.signal?.accounts;
1200
+ if (!accounts || typeof accounts !== "object") return [];
1201
+ return Object.keys(accounts).filter(Boolean);
1202
+ }
1203
+ function listSignalAccountIds(cfg) {
1204
+ const ids = listConfiguredAccountIds(cfg);
1205
+ if (ids.length === 0) return [DEFAULT_ACCOUNT_ID];
1206
+ return ids.toSorted((a, b) => a.localeCompare(b));
1207
+ }
1208
+ function resolveAccountConfig(cfg, accountId) {
1209
+ const accounts = cfg.channels?.signal?.accounts;
1210
+ if (!accounts || typeof accounts !== "object") return;
1211
+ return accounts[accountId];
1212
+ }
1213
+ function mergeSignalAccountConfig(cfg, accountId) {
1214
+ const { accounts: _ignored, ...base } = cfg.channels?.signal ?? {};
1215
+ const account = resolveAccountConfig(cfg, accountId) ?? {};
1216
+ return {
1217
+ ...base,
1218
+ ...account
1219
+ };
1220
+ }
1221
+ function resolveSignalAccount(params) {
1222
+ const accountId = normalizeAccountId$1(params.accountId);
1223
+ const baseEnabled = params.cfg.channels?.signal?.enabled !== false;
1224
+ const merged = mergeSignalAccountConfig(params.cfg, accountId);
1225
+ const accountEnabled = merged.enabled !== false;
1226
+ const enabled = baseEnabled && accountEnabled;
1227
+ const host = merged.httpHost?.trim() || "127.0.0.1";
1228
+ const port = merged.httpPort ?? 8080;
1229
+ const baseUrl = merged.httpUrl?.trim() || `http://${host}:${port}`;
1230
+ const configured = Boolean(merged.account?.trim() || merged.httpUrl?.trim() || merged.cliPath?.trim() || merged.httpHost?.trim() || typeof merged.httpPort === "number" || typeof merged.autoStart === "boolean");
1231
+ return {
1232
+ accountId,
1233
+ enabled,
1234
+ name: merged.name?.trim() || void 0,
1235
+ baseUrl,
1236
+ configured,
1237
+ config: merged
1238
+ };
1239
+ }
1240
+ function listEnabledSignalAccounts(cfg) {
1241
+ return listSignalAccountIds(cfg).map((accountId) => resolveSignalAccount({
1242
+ cfg,
1243
+ accountId
1244
+ })).filter((account) => account.enabled);
1245
+ }
1246
+
1247
+ //#endregion
1248
+ //#region src/slack/threading-tool-context.ts
1249
+ function buildSlackThreadingToolContext(params) {
1250
+ const configuredReplyToMode = resolveSlackReplyToMode(resolveSlackAccount({
1251
+ cfg: params.cfg,
1252
+ accountId: params.accountId
1253
+ }), params.context.ChatType);
1254
+ const effectiveReplyToMode = params.context.ThreadLabel ? "all" : configuredReplyToMode;
1255
+ const threadId = params.context.MessageThreadId ?? params.context.ReplyToId;
1256
+ return {
1257
+ currentChannelId: params.context.To?.startsWith("channel:") ? params.context.To.slice(8) : void 0,
1258
+ currentThreadTs: threadId != null ? String(threadId) : void 0,
1259
+ replyToMode: effectiveReplyToMode,
1260
+ hasRepliedRef: params.hasRepliedRef
1261
+ };
1262
+ }
1263
+
1264
+ //#endregion
1265
+ //#region src/config/group-policy.ts
1266
+ function normalizeSenderKey(value) {
1267
+ const trimmed = value.trim();
1268
+ if (!trimmed) return "";
1269
+ return (trimmed.startsWith("@") ? trimmed.slice(1) : trimmed).toLowerCase();
1270
+ }
1271
+ function resolveToolsBySender(params) {
1272
+ const toolsBySender = params.toolsBySender;
1273
+ if (!toolsBySender) return;
1274
+ const entries = Object.entries(toolsBySender);
1275
+ if (entries.length === 0) return;
1276
+ const normalized = /* @__PURE__ */ new Map();
1277
+ let wildcard;
1278
+ for (const [rawKey, policy] of entries) {
1279
+ if (!policy) continue;
1280
+ const key = normalizeSenderKey(rawKey);
1281
+ if (!key) continue;
1282
+ if (key === "*") {
1283
+ wildcard = policy;
1284
+ continue;
1285
+ }
1286
+ if (!normalized.has(key)) normalized.set(key, policy);
1287
+ }
1288
+ const candidates = [];
1289
+ const pushCandidate = (value) => {
1290
+ const trimmed = value?.trim();
1291
+ if (!trimmed) return;
1292
+ candidates.push(trimmed);
1293
+ };
1294
+ pushCandidate(params.senderId);
1295
+ pushCandidate(params.senderE164);
1296
+ pushCandidate(params.senderUsername);
1297
+ pushCandidate(params.senderName);
1298
+ for (const candidate of candidates) {
1299
+ const key = normalizeSenderKey(candidate);
1300
+ if (!key) continue;
1301
+ const match = normalized.get(key);
1302
+ if (match) return match;
1303
+ }
1304
+ return wildcard;
1305
+ }
1306
+ function resolveChannelGroups(cfg, channel, accountId) {
1307
+ const normalizedAccountId = normalizeAccountId$1(accountId);
1308
+ const channelConfig = cfg.channels?.[channel];
1309
+ if (!channelConfig) return;
1310
+ return channelConfig.accounts?.[normalizedAccountId]?.groups ?? channelConfig.accounts?.[Object.keys(channelConfig.accounts ?? {}).find((key) => key.toLowerCase() === normalizedAccountId.toLowerCase()) ?? ""]?.groups ?? channelConfig.groups;
1311
+ }
1312
+ function resolveChannelGroupPolicy(params) {
1313
+ const { cfg, channel } = params;
1314
+ const groups = resolveChannelGroups(cfg, channel, params.accountId);
1315
+ const allowlistEnabled = Boolean(groups && Object.keys(groups).length > 0);
1316
+ const normalizedId = params.groupId?.trim();
1317
+ const groupConfig = normalizedId && groups ? groups[normalizedId] : void 0;
1318
+ const defaultConfig = groups?.["*"];
1319
+ return {
1320
+ allowlistEnabled,
1321
+ allowed: !allowlistEnabled || allowlistEnabled && Boolean(groups && Object.hasOwn(groups, "*")) || (normalizedId ? Boolean(groups && Object.hasOwn(groups, normalizedId)) : false),
1322
+ groupConfig,
1323
+ defaultConfig
1324
+ };
1325
+ }
1326
+ function resolveChannelGroupRequireMention(params) {
1327
+ const { requireMentionOverride, overrideOrder = "after-config" } = params;
1328
+ const { groupConfig, defaultConfig } = resolveChannelGroupPolicy(params);
1329
+ const configMention = typeof groupConfig?.requireMention === "boolean" ? groupConfig.requireMention : typeof defaultConfig?.requireMention === "boolean" ? defaultConfig.requireMention : void 0;
1330
+ if (overrideOrder === "before-config" && typeof requireMentionOverride === "boolean") return requireMentionOverride;
1331
+ if (typeof configMention === "boolean") return configMention;
1332
+ if (overrideOrder !== "before-config" && typeof requireMentionOverride === "boolean") return requireMentionOverride;
1333
+ return true;
1334
+ }
1335
+ function resolveChannelGroupToolsPolicy(params) {
1336
+ const { groupConfig, defaultConfig } = resolveChannelGroupPolicy(params);
1337
+ const groupSenderPolicy = resolveToolsBySender({
1338
+ toolsBySender: groupConfig?.toolsBySender,
1339
+ senderId: params.senderId,
1340
+ senderName: params.senderName,
1341
+ senderUsername: params.senderUsername,
1342
+ senderE164: params.senderE164
1343
+ });
1344
+ if (groupSenderPolicy) return groupSenderPolicy;
1345
+ if (groupConfig?.tools) return groupConfig.tools;
1346
+ const defaultSenderPolicy = resolveToolsBySender({
1347
+ toolsBySender: defaultConfig?.toolsBySender,
1348
+ senderId: params.senderId,
1349
+ senderName: params.senderName,
1350
+ senderUsername: params.senderUsername,
1351
+ senderE164: params.senderE164
1352
+ });
1353
+ if (defaultSenderPolicy) return defaultSenderPolicy;
1354
+ if (defaultConfig?.tools) return defaultConfig.tools;
1355
+ }
1356
+
1357
+ //#endregion
1358
+ //#region src/channels/plugins/group-mentions.ts
1359
+ function normalizeDiscordSlug(value) {
1360
+ if (!value) return "";
1361
+ let text = value.trim().toLowerCase();
1362
+ if (!text) return "";
1363
+ text = text.replace(/^[@#]+/, "");
1364
+ text = text.replace(/[\s_]+/g, "-");
1365
+ text = text.replace(/[^a-z0-9-]+/g, "-");
1366
+ text = text.replace(/-{2,}/g, "-").replace(/^-+|-+$/g, "");
1367
+ return text;
1368
+ }
1369
+ function normalizeSlackSlug(raw) {
1370
+ const trimmed = raw?.trim().toLowerCase() ?? "";
1371
+ if (!trimmed) return "";
1372
+ return trimmed.replace(/\s+/g, "-").replace(/[^a-z0-9#@._+-]+/g, "-").replace(/-{2,}/g, "-").replace(/^[-.]+|[-.]+$/g, "");
1373
+ }
1374
+ function parseTelegramGroupId(value) {
1375
+ const raw = value?.trim() ?? "";
1376
+ if (!raw) return {
1377
+ chatId: void 0,
1378
+ topicId: void 0
1379
+ };
1380
+ const parts = raw.split(":").filter(Boolean);
1381
+ if (parts.length >= 3 && parts[1] === "topic" && /^-?\d+$/.test(parts[0]) && /^\d+$/.test(parts[2])) return {
1382
+ chatId: parts[0],
1383
+ topicId: parts[2]
1384
+ };
1385
+ if (parts.length >= 2 && /^-?\d+$/.test(parts[0]) && /^\d+$/.test(parts[1])) return {
1386
+ chatId: parts[0],
1387
+ topicId: parts[1]
1388
+ };
1389
+ return {
1390
+ chatId: raw,
1391
+ topicId: void 0
1392
+ };
1393
+ }
1394
+ function resolveTelegramRequireMention(params) {
1395
+ const { cfg, chatId, topicId } = params;
1396
+ if (!chatId) return;
1397
+ const groupConfig = cfg.channels?.telegram?.groups?.[chatId];
1398
+ const groupDefault = cfg.channels?.telegram?.groups?.["*"];
1399
+ const topicConfig = topicId && groupConfig?.topics ? groupConfig.topics[topicId] : void 0;
1400
+ const defaultTopicConfig = topicId && groupDefault?.topics ? groupDefault.topics[topicId] : void 0;
1401
+ if (typeof topicConfig?.requireMention === "boolean") return topicConfig.requireMention;
1402
+ if (typeof defaultTopicConfig?.requireMention === "boolean") return defaultTopicConfig.requireMention;
1403
+ if (typeof groupConfig?.requireMention === "boolean") return groupConfig.requireMention;
1404
+ if (typeof groupDefault?.requireMention === "boolean") return groupDefault.requireMention;
1405
+ }
1406
+ function resolveDiscordGuildEntry(guilds, groupSpace) {
1407
+ if (!guilds || Object.keys(guilds).length === 0) return null;
1408
+ const space = groupSpace?.trim() ?? "";
1409
+ if (space && guilds[space]) return guilds[space];
1410
+ const normalized = normalizeDiscordSlug(space);
1411
+ if (normalized && guilds[normalized]) return guilds[normalized];
1412
+ if (normalized) {
1413
+ const match = Object.values(guilds).find((entry) => normalizeDiscordSlug(entry?.slug ?? void 0) === normalized);
1414
+ if (match) return match;
1415
+ }
1416
+ return guilds["*"] ?? null;
1417
+ }
1418
+ function resolveTelegramGroupRequireMention(params) {
1419
+ const { chatId, topicId } = parseTelegramGroupId(params.groupId);
1420
+ const requireMention = resolveTelegramRequireMention({
1421
+ cfg: params.cfg,
1422
+ chatId,
1423
+ topicId
1424
+ });
1425
+ if (typeof requireMention === "boolean") return requireMention;
1426
+ return resolveChannelGroupRequireMention({
1427
+ cfg: params.cfg,
1428
+ channel: "telegram",
1429
+ groupId: chatId ?? params.groupId,
1430
+ accountId: params.accountId
1431
+ });
1432
+ }
1433
+ function resolveWhatsAppGroupRequireMention(params) {
1434
+ return resolveChannelGroupRequireMention({
1435
+ cfg: params.cfg,
1436
+ channel: "whatsapp",
1437
+ groupId: params.groupId,
1438
+ accountId: params.accountId
1439
+ });
1440
+ }
1441
+ function resolveIMessageGroupRequireMention(params) {
1442
+ return resolveChannelGroupRequireMention({
1443
+ cfg: params.cfg,
1444
+ channel: "imessage",
1445
+ groupId: params.groupId,
1446
+ accountId: params.accountId
1447
+ });
1448
+ }
1449
+ function resolveDiscordGroupRequireMention(params) {
1450
+ const guildEntry = resolveDiscordGuildEntry(params.cfg.channels?.discord?.guilds, params.groupSpace);
1451
+ const channelEntries = guildEntry?.channels;
1452
+ if (channelEntries && Object.keys(channelEntries).length > 0) {
1453
+ const groupChannel = params.groupChannel;
1454
+ const channelSlug = normalizeDiscordSlug(groupChannel);
1455
+ const entry = (params.groupId ? channelEntries[params.groupId] : void 0) ?? (channelSlug ? channelEntries[channelSlug] ?? channelEntries[`#${channelSlug}`] : void 0) ?? (groupChannel ? channelEntries[normalizeDiscordSlug(groupChannel)] : void 0);
1456
+ if (entry && typeof entry.requireMention === "boolean") return entry.requireMention;
1457
+ }
1458
+ if (typeof guildEntry?.requireMention === "boolean") return guildEntry.requireMention;
1459
+ return true;
1460
+ }
1461
+ function resolveGoogleChatGroupRequireMention(params) {
1462
+ return resolveChannelGroupRequireMention({
1463
+ cfg: params.cfg,
1464
+ channel: "googlechat",
1465
+ groupId: params.groupId,
1466
+ accountId: params.accountId
1467
+ });
1468
+ }
1469
+ function resolveGoogleChatGroupToolPolicy(params) {
1470
+ return resolveChannelGroupToolsPolicy({
1471
+ cfg: params.cfg,
1472
+ channel: "googlechat",
1473
+ groupId: params.groupId,
1474
+ accountId: params.accountId,
1475
+ senderId: params.senderId,
1476
+ senderName: params.senderName,
1477
+ senderUsername: params.senderUsername,
1478
+ senderE164: params.senderE164
1479
+ });
1480
+ }
1481
+ function resolveSlackGroupRequireMention(params) {
1482
+ const channels = resolveSlackAccount({
1483
+ cfg: params.cfg,
1484
+ accountId: params.accountId
1485
+ }).channels ?? {};
1486
+ if (Object.keys(channels).length === 0) return true;
1487
+ const channelId = params.groupId?.trim();
1488
+ const channelName = params.groupChannel?.replace(/^#/, "");
1489
+ const normalizedName = normalizeSlackSlug(channelName);
1490
+ const candidates = [
1491
+ channelId ?? "",
1492
+ channelName ? `#${channelName}` : "",
1493
+ channelName ?? "",
1494
+ normalizedName
1495
+ ].filter(Boolean);
1496
+ let matched;
1497
+ for (const candidate of candidates) if (candidate && channels[candidate]) {
1498
+ matched = channels[candidate];
1499
+ break;
1500
+ }
1501
+ const fallback = channels["*"];
1502
+ const resolved = matched ?? fallback;
1503
+ if (typeof resolved?.requireMention === "boolean") return resolved.requireMention;
1504
+ return true;
1505
+ }
1506
+ function resolveTelegramGroupToolPolicy(params) {
1507
+ const { chatId } = parseTelegramGroupId(params.groupId);
1508
+ return resolveChannelGroupToolsPolicy({
1509
+ cfg: params.cfg,
1510
+ channel: "telegram",
1511
+ groupId: chatId ?? params.groupId,
1512
+ accountId: params.accountId,
1513
+ senderId: params.senderId,
1514
+ senderName: params.senderName,
1515
+ senderUsername: params.senderUsername,
1516
+ senderE164: params.senderE164
1517
+ });
1518
+ }
1519
+ function resolveWhatsAppGroupToolPolicy(params) {
1520
+ return resolveChannelGroupToolsPolicy({
1521
+ cfg: params.cfg,
1522
+ channel: "whatsapp",
1523
+ groupId: params.groupId,
1524
+ accountId: params.accountId,
1525
+ senderId: params.senderId,
1526
+ senderName: params.senderName,
1527
+ senderUsername: params.senderUsername,
1528
+ senderE164: params.senderE164
1529
+ });
1530
+ }
1531
+ function resolveIMessageGroupToolPolicy(params) {
1532
+ return resolveChannelGroupToolsPolicy({
1533
+ cfg: params.cfg,
1534
+ channel: "imessage",
1535
+ groupId: params.groupId,
1536
+ accountId: params.accountId,
1537
+ senderId: params.senderId,
1538
+ senderName: params.senderName,
1539
+ senderUsername: params.senderUsername,
1540
+ senderE164: params.senderE164
1541
+ });
1542
+ }
1543
+ function resolveDiscordGroupToolPolicy(params) {
1544
+ const guildEntry = resolveDiscordGuildEntry(params.cfg.channels?.discord?.guilds, params.groupSpace);
1545
+ const channelEntries = guildEntry?.channels;
1546
+ if (channelEntries && Object.keys(channelEntries).length > 0) {
1547
+ const groupChannel = params.groupChannel;
1548
+ const channelSlug = normalizeDiscordSlug(groupChannel);
1549
+ const entry = (params.groupId ? channelEntries[params.groupId] : void 0) ?? (channelSlug ? channelEntries[channelSlug] ?? channelEntries[`#${channelSlug}`] : void 0) ?? (groupChannel ? channelEntries[normalizeDiscordSlug(groupChannel)] : void 0);
1550
+ const senderPolicy = resolveToolsBySender({
1551
+ toolsBySender: entry?.toolsBySender,
1552
+ senderId: params.senderId,
1553
+ senderName: params.senderName,
1554
+ senderUsername: params.senderUsername,
1555
+ senderE164: params.senderE164
1556
+ });
1557
+ if (senderPolicy) return senderPolicy;
1558
+ if (entry?.tools) return entry.tools;
1559
+ }
1560
+ const guildSenderPolicy = resolveToolsBySender({
1561
+ toolsBySender: guildEntry?.toolsBySender,
1562
+ senderId: params.senderId,
1563
+ senderName: params.senderName,
1564
+ senderUsername: params.senderUsername,
1565
+ senderE164: params.senderE164
1566
+ });
1567
+ if (guildSenderPolicy) return guildSenderPolicy;
1568
+ if (guildEntry?.tools) return guildEntry.tools;
1569
+ }
1570
+ function resolveSlackGroupToolPolicy(params) {
1571
+ const channels = resolveSlackAccount({
1572
+ cfg: params.cfg,
1573
+ accountId: params.accountId
1574
+ }).channels ?? {};
1575
+ if (Object.keys(channels).length === 0) return;
1576
+ const channelId = params.groupId?.trim();
1577
+ const channelName = params.groupChannel?.replace(/^#/, "");
1578
+ const normalizedName = normalizeSlackSlug(channelName);
1579
+ const candidates = [
1580
+ channelId ?? "",
1581
+ channelName ? `#${channelName}` : "",
1582
+ channelName ?? "",
1583
+ normalizedName
1584
+ ].filter(Boolean);
1585
+ let matched;
1586
+ for (const candidate of candidates) if (candidate && channels[candidate]) {
1587
+ matched = channels[candidate];
1588
+ break;
1589
+ }
1590
+ const resolved = matched ?? channels["*"];
1591
+ const senderPolicy = resolveToolsBySender({
1592
+ toolsBySender: resolved?.toolsBySender,
1593
+ senderId: params.senderId,
1594
+ senderName: params.senderName,
1595
+ senderUsername: params.senderUsername,
1596
+ senderE164: params.senderE164
1597
+ });
1598
+ if (senderPolicy) return senderPolicy;
1599
+ if (resolved?.tools) return resolved.tools;
1600
+ }
1601
+
1602
+ //#endregion
1603
+ //#region src/channels/dock.ts
1604
+ const formatLower = (allowFrom) => allowFrom.map((entry) => String(entry).trim()).filter(Boolean).map((entry) => entry.toLowerCase());
1605
+ const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1606
+ const DOCKS = {
1607
+ telegram: {
1608
+ id: "telegram",
1609
+ capabilities: {
1610
+ chatTypes: [
1611
+ "direct",
1612
+ "group",
1613
+ "channel",
1614
+ "thread"
1615
+ ],
1616
+ nativeCommands: true,
1617
+ blockStreaming: true
1618
+ },
1619
+ outbound: { textChunkLimit: 4e3 },
1620
+ config: {
1621
+ resolveAllowFrom: ({ cfg, accountId }) => (resolveTelegramAccount({
1622
+ cfg,
1623
+ accountId
1624
+ }).config.allowFrom ?? []).map((entry) => String(entry)),
1625
+ formatAllowFrom: ({ allowFrom }) => allowFrom.map((entry) => String(entry).trim()).filter(Boolean).map((entry) => entry.replace(/^(telegram|tg):/i, "")).map((entry) => entry.toLowerCase())
1626
+ },
1627
+ groups: {
1628
+ resolveRequireMention: resolveTelegramGroupRequireMention,
1629
+ resolveToolPolicy: resolveTelegramGroupToolPolicy
1630
+ },
1631
+ threading: {
1632
+ resolveReplyToMode: ({ cfg }) => cfg.channels?.telegram?.replyToMode ?? "first",
1633
+ buildToolContext: ({ context, hasRepliedRef }) => {
1634
+ const threadId = context.MessageThreadId ?? context.ReplyToId;
1635
+ return {
1636
+ currentChannelId: context.To?.trim() || void 0,
1637
+ currentThreadTs: threadId != null ? String(threadId) : void 0,
1638
+ hasRepliedRef
1639
+ };
1640
+ }
1641
+ }
1642
+ },
1643
+ whatsapp: {
1644
+ id: "whatsapp",
1645
+ capabilities: {
1646
+ chatTypes: ["direct", "group"],
1647
+ polls: true,
1648
+ reactions: true,
1649
+ media: true
1650
+ },
1651
+ commands: {
1652
+ enforceOwnerForCommands: true,
1653
+ skipWhenConfigEmpty: true
1654
+ },
1655
+ outbound: { textChunkLimit: 4e3 },
1656
+ config: {
1657
+ resolveAllowFrom: ({ cfg, accountId }) => resolveWhatsAppAccount({
1658
+ cfg,
1659
+ accountId
1660
+ }).allowFrom ?? [],
1661
+ formatAllowFrom: ({ allowFrom }) => allowFrom.map((entry) => String(entry).trim()).filter((entry) => Boolean(entry)).map((entry) => entry === "*" ? entry : normalizeWhatsAppTarget(entry)).filter((entry) => Boolean(entry))
1662
+ },
1663
+ groups: {
1664
+ resolveRequireMention: resolveWhatsAppGroupRequireMention,
1665
+ resolveToolPolicy: resolveWhatsAppGroupToolPolicy,
1666
+ resolveGroupIntroHint: () => "WhatsApp IDs: SenderId is the participant JID; [message_id: ...] is the message id for reactions (use SenderId as participant)."
1667
+ },
1668
+ mentions: { stripPatterns: ({ ctx }) => {
1669
+ const selfE164 = (ctx.To ?? "").replace(/^whatsapp:/, "");
1670
+ if (!selfE164) return [];
1671
+ const escaped = escapeRegExp(selfE164);
1672
+ return [escaped, `@${escaped}`];
1673
+ } },
1674
+ threading: { buildToolContext: ({ context, hasRepliedRef }) => {
1675
+ return {
1676
+ currentChannelId: context.From?.trim() || context.To?.trim() || void 0,
1677
+ currentThreadTs: context.ReplyToId,
1678
+ hasRepliedRef
1679
+ };
1680
+ } }
1681
+ },
1682
+ discord: {
1683
+ id: "discord",
1684
+ capabilities: {
1685
+ chatTypes: [
1686
+ "direct",
1687
+ "channel",
1688
+ "thread"
1689
+ ],
1690
+ polls: true,
1691
+ reactions: true,
1692
+ media: true,
1693
+ nativeCommands: true,
1694
+ threads: true
1695
+ },
1696
+ outbound: { textChunkLimit: 2e3 },
1697
+ streaming: { blockStreamingCoalesceDefaults: {
1698
+ minChars: 1500,
1699
+ idleMs: 1e3
1700
+ } },
1701
+ elevated: { allowFromFallback: ({ cfg }) => cfg.channels?.discord?.dm?.allowFrom },
1702
+ config: {
1703
+ resolveAllowFrom: ({ cfg, accountId }) => (resolveDiscordAccount({
1704
+ cfg,
1705
+ accountId
1706
+ }).config.dm?.allowFrom ?? []).map((entry) => String(entry)),
1707
+ formatAllowFrom: ({ allowFrom }) => formatLower(allowFrom)
1708
+ },
1709
+ groups: {
1710
+ resolveRequireMention: resolveDiscordGroupRequireMention,
1711
+ resolveToolPolicy: resolveDiscordGroupToolPolicy
1712
+ },
1713
+ mentions: { stripPatterns: () => ["<@!?\\d+>"] },
1714
+ threading: {
1715
+ resolveReplyToMode: ({ cfg }) => cfg.channels?.discord?.replyToMode ?? "off",
1716
+ buildToolContext: ({ context, hasRepliedRef }) => ({
1717
+ currentChannelId: context.To?.trim() || void 0,
1718
+ currentThreadTs: context.ReplyToId,
1719
+ hasRepliedRef
1720
+ })
1721
+ }
1722
+ },
1723
+ googlechat: {
1724
+ id: "googlechat",
1725
+ capabilities: {
1726
+ chatTypes: [
1727
+ "direct",
1728
+ "group",
1729
+ "thread"
1730
+ ],
1731
+ reactions: true,
1732
+ media: true,
1733
+ threads: true,
1734
+ blockStreaming: true
1735
+ },
1736
+ outbound: { textChunkLimit: 4e3 },
1737
+ config: {
1738
+ resolveAllowFrom: ({ cfg, accountId }) => {
1739
+ const channel = cfg.channels?.googlechat;
1740
+ const normalized = normalizeAccountId$1(accountId);
1741
+ return ((channel?.accounts?.[normalized] ?? channel?.accounts?.[Object.keys(channel?.accounts ?? {}).find((key) => key.toLowerCase() === normalized.toLowerCase()) ?? ""])?.dm?.allowFrom ?? channel?.dm?.allowFrom ?? []).map((entry) => String(entry));
1742
+ },
1743
+ formatAllowFrom: ({ allowFrom }) => allowFrom.map((entry) => String(entry).trim()).filter(Boolean).map((entry) => entry.replace(/^(googlechat|google-chat|gchat):/i, "").replace(/^user:/i, "").replace(/^users\//i, "").toLowerCase())
1744
+ },
1745
+ groups: {
1746
+ resolveRequireMention: resolveGoogleChatGroupRequireMention,
1747
+ resolveToolPolicy: resolveGoogleChatGroupToolPolicy
1748
+ },
1749
+ threading: {
1750
+ resolveReplyToMode: ({ cfg }) => cfg.channels?.googlechat?.replyToMode ?? "off",
1751
+ buildToolContext: ({ context, hasRepliedRef }) => {
1752
+ const threadId = context.MessageThreadId ?? context.ReplyToId;
1753
+ return {
1754
+ currentChannelId: context.To?.trim() || void 0,
1755
+ currentThreadTs: threadId != null ? String(threadId) : void 0,
1756
+ hasRepliedRef
1757
+ };
1758
+ }
1759
+ }
1760
+ },
1761
+ slack: {
1762
+ id: "slack",
1763
+ capabilities: {
1764
+ chatTypes: [
1765
+ "direct",
1766
+ "channel",
1767
+ "thread"
1768
+ ],
1769
+ reactions: true,
1770
+ media: true,
1771
+ nativeCommands: true,
1772
+ threads: true
1773
+ },
1774
+ outbound: { textChunkLimit: 4e3 },
1775
+ streaming: { blockStreamingCoalesceDefaults: {
1776
+ minChars: 1500,
1777
+ idleMs: 1e3
1778
+ } },
1779
+ config: {
1780
+ resolveAllowFrom: ({ cfg, accountId }) => (resolveSlackAccount({
1781
+ cfg,
1782
+ accountId
1783
+ }).dm?.allowFrom ?? []).map((entry) => String(entry)),
1784
+ formatAllowFrom: ({ allowFrom }) => formatLower(allowFrom)
1785
+ },
1786
+ groups: {
1787
+ resolveRequireMention: resolveSlackGroupRequireMention,
1788
+ resolveToolPolicy: resolveSlackGroupToolPolicy
1789
+ },
1790
+ mentions: { stripPatterns: () => ["<@[^>]+>"] },
1791
+ threading: {
1792
+ resolveReplyToMode: ({ cfg, accountId, chatType }) => resolveSlackReplyToMode(resolveSlackAccount({
1793
+ cfg,
1794
+ accountId
1795
+ }), chatType),
1796
+ allowTagsWhenOff: true,
1797
+ buildToolContext: (params) => buildSlackThreadingToolContext(params)
1798
+ }
1799
+ },
1800
+ signal: {
1801
+ id: "signal",
1802
+ capabilities: {
1803
+ chatTypes: ["direct", "group"],
1804
+ reactions: true,
1805
+ media: true
1806
+ },
1807
+ outbound: { textChunkLimit: 4e3 },
1808
+ streaming: { blockStreamingCoalesceDefaults: {
1809
+ minChars: 1500,
1810
+ idleMs: 1e3
1811
+ } },
1812
+ config: {
1813
+ resolveAllowFrom: ({ cfg, accountId }) => (resolveSignalAccount({
1814
+ cfg,
1815
+ accountId
1816
+ }).config.allowFrom ?? []).map((entry) => String(entry)),
1817
+ formatAllowFrom: ({ allowFrom }) => allowFrom.map((entry) => String(entry).trim()).filter(Boolean).map((entry) => entry === "*" ? "*" : normalizeE164(entry.replace(/^signal:/i, ""))).filter(Boolean)
1818
+ },
1819
+ threading: { buildToolContext: ({ context, hasRepliedRef }) => {
1820
+ return {
1821
+ currentChannelId: (context.ChatType?.toLowerCase() === "direct" ? context.From ?? context.To : context.To)?.trim() || void 0,
1822
+ currentThreadTs: context.ReplyToId,
1823
+ hasRepliedRef
1824
+ };
1825
+ } }
1826
+ },
1827
+ imessage: {
1828
+ id: "imessage",
1829
+ capabilities: {
1830
+ chatTypes: ["direct", "group"],
1831
+ reactions: true,
1832
+ media: true
1833
+ },
1834
+ outbound: { textChunkLimit: 4e3 },
1835
+ config: {
1836
+ resolveAllowFrom: ({ cfg, accountId }) => (resolveIMessageAccount({
1837
+ cfg,
1838
+ accountId
1839
+ }).config.allowFrom ?? []).map((entry) => String(entry)),
1840
+ formatAllowFrom: ({ allowFrom }) => allowFrom.map((entry) => String(entry).trim()).filter(Boolean)
1841
+ },
1842
+ groups: {
1843
+ resolveRequireMention: resolveIMessageGroupRequireMention,
1844
+ resolveToolPolicy: resolveIMessageGroupToolPolicy
1845
+ },
1846
+ threading: { buildToolContext: ({ context, hasRepliedRef }) => {
1847
+ return {
1848
+ currentChannelId: (context.ChatType?.toLowerCase() === "direct" ? context.From ?? context.To : context.To)?.trim() || void 0,
1849
+ currentThreadTs: context.ReplyToId,
1850
+ hasRepliedRef
1851
+ };
1852
+ } }
1853
+ }
1854
+ };
1855
+ function buildDockFromPlugin(plugin) {
1856
+ return {
1857
+ id: plugin.id,
1858
+ capabilities: plugin.capabilities,
1859
+ commands: plugin.commands,
1860
+ outbound: plugin.outbound?.textChunkLimit ? { textChunkLimit: plugin.outbound.textChunkLimit } : void 0,
1861
+ streaming: plugin.streaming ? { blockStreamingCoalesceDefaults: plugin.streaming.blockStreamingCoalesceDefaults } : void 0,
1862
+ elevated: plugin.elevated,
1863
+ config: plugin.config ? {
1864
+ resolveAllowFrom: plugin.config.resolveAllowFrom,
1865
+ formatAllowFrom: plugin.config.formatAllowFrom
1866
+ } : void 0,
1867
+ groups: plugin.groups,
1868
+ mentions: plugin.mentions,
1869
+ threading: plugin.threading,
1870
+ agentPrompt: plugin.agentPrompt
1871
+ };
1872
+ }
1873
+ function listPluginDockEntries() {
1874
+ const registry = requireActivePluginRegistry();
1875
+ const entries = [];
1876
+ const seen = /* @__PURE__ */ new Set();
1877
+ for (const entry of registry.channels) {
1878
+ const plugin = entry.plugin;
1879
+ const id = String(plugin.id).trim();
1880
+ if (!id || seen.has(id)) continue;
1881
+ seen.add(id);
1882
+ if (CHAT_CHANNEL_ORDER.includes(plugin.id)) continue;
1883
+ const dock = entry.dock ?? buildDockFromPlugin(plugin);
1884
+ entries.push({
1885
+ id: plugin.id,
1886
+ dock,
1887
+ order: plugin.meta.order
1888
+ });
1889
+ }
1890
+ return entries;
1891
+ }
1892
+ function listChannelDocks() {
1893
+ const baseEntries = CHAT_CHANNEL_ORDER.map((id) => ({
1894
+ id,
1895
+ dock: DOCKS[id],
1896
+ order: getChatChannelMeta(id).order
1897
+ }));
1898
+ const pluginEntries = listPluginDockEntries();
1899
+ const combined = [...baseEntries, ...pluginEntries];
1900
+ combined.sort((a, b) => {
1901
+ const indexA = CHAT_CHANNEL_ORDER.indexOf(a.id);
1902
+ const indexB = CHAT_CHANNEL_ORDER.indexOf(b.id);
1903
+ const orderA = a.order ?? (indexA === -1 ? 999 : indexA);
1904
+ const orderB = b.order ?? (indexB === -1 ? 999 : indexB);
1905
+ if (orderA !== orderB) return orderA - orderB;
1906
+ return String(a.id).localeCompare(String(b.id));
1907
+ });
1908
+ return combined.map((entry) => entry.dock);
1909
+ }
1910
+ function getChannelDock(id) {
1911
+ const core = DOCKS[id];
1912
+ if (core) return core;
1913
+ const pluginEntry = requireActivePluginRegistry().channels.find((entry) => entry.plugin.id === id);
1914
+ if (!pluginEntry) return;
1915
+ return pluginEntry.dock ?? buildDockFromPlugin(pluginEntry.plugin);
1916
+ }
1917
+
1918
+ //#endregion
1919
+ //#region src/config/sessions/metadata.ts
1920
+ const mergeOrigin = (existing, next) => {
1921
+ if (!existing && !next) return;
1922
+ const merged = existing ? { ...existing } : {};
1923
+ if (next?.label) merged.label = next.label;
1924
+ if (next?.provider) merged.provider = next.provider;
1925
+ if (next?.surface) merged.surface = next.surface;
1926
+ if (next?.chatType) merged.chatType = next.chatType;
1927
+ if (next?.from) merged.from = next.from;
1928
+ if (next?.to) merged.to = next.to;
1929
+ if (next?.accountId) merged.accountId = next.accountId;
1930
+ if (next?.threadId != null && next.threadId !== "") merged.threadId = next.threadId;
1931
+ return Object.keys(merged).length > 0 ? merged : void 0;
1932
+ };
1933
+ function deriveSessionOrigin(ctx) {
1934
+ const label = resolveConversationLabel(ctx)?.trim();
1935
+ const provider = normalizeMessageChannel(typeof ctx.OriginatingChannel === "string" && ctx.OriginatingChannel || ctx.Surface || ctx.Provider);
1936
+ const surface = ctx.Surface?.trim().toLowerCase();
1937
+ const chatType = normalizeChatType(ctx.ChatType) ?? void 0;
1938
+ const from = ctx.From?.trim();
1939
+ const to = (typeof ctx.OriginatingTo === "string" ? ctx.OriginatingTo : ctx.To)?.trim() ?? void 0;
1940
+ const accountId = ctx.AccountId?.trim();
1941
+ const threadId = ctx.MessageThreadId ?? void 0;
1942
+ const origin = {};
1943
+ if (label) origin.label = label;
1944
+ if (provider) origin.provider = provider;
1945
+ if (surface) origin.surface = surface;
1946
+ if (chatType) origin.chatType = chatType;
1947
+ if (from) origin.from = from;
1948
+ if (to) origin.to = to;
1949
+ if (accountId) origin.accountId = accountId;
1950
+ if (threadId != null && threadId !== "") origin.threadId = threadId;
1951
+ return Object.keys(origin).length > 0 ? origin : void 0;
1952
+ }
1953
+ function snapshotSessionOrigin(entry) {
1954
+ if (!entry?.origin) return;
1955
+ return { ...entry.origin };
1956
+ }
1957
+ function deriveGroupSessionPatch(params) {
1958
+ const resolution = params.groupResolution ?? resolveGroupSessionKey(params.ctx);
1959
+ if (!resolution?.channel) return null;
1960
+ const channel = resolution.channel;
1961
+ const subject = params.ctx.GroupSubject?.trim();
1962
+ const space = params.ctx.GroupSpace?.trim();
1963
+ const explicitChannel = params.ctx.GroupChannel?.trim();
1964
+ const normalizedChannel = normalizeChannelId(channel);
1965
+ const isChannelProvider = Boolean(normalizedChannel && getChannelDock(normalizedChannel)?.capabilities.chatTypes.includes("channel"));
1966
+ const nextGroupChannel = explicitChannel ?? ((resolution.chatType === "channel" || isChannelProvider) && subject && subject.startsWith("#") ? subject : void 0);
1967
+ const nextSubject = nextGroupChannel ? void 0 : subject;
1968
+ const patch = {
1969
+ chatType: resolution.chatType ?? "group",
1970
+ channel,
1971
+ groupId: resolution.id
1972
+ };
1973
+ if (nextSubject) patch.subject = nextSubject;
1974
+ if (nextGroupChannel) patch.groupChannel = nextGroupChannel;
1975
+ if (space) patch.space = space;
1976
+ const displayName = buildGroupDisplayName({
1977
+ provider: channel,
1978
+ subject: nextSubject ?? params.existing?.subject,
1979
+ groupChannel: nextGroupChannel ?? params.existing?.groupChannel,
1980
+ space: space ?? params.existing?.space,
1981
+ id: resolution.id,
1982
+ key: params.sessionKey
1983
+ });
1984
+ if (displayName) patch.displayName = displayName;
1985
+ return patch;
1986
+ }
1987
+ function deriveSessionMetaPatch(params) {
1988
+ const groupPatch = deriveGroupSessionPatch(params);
1989
+ const origin = deriveSessionOrigin(params.ctx);
1990
+ if (!groupPatch && !origin) return null;
1991
+ const patch = groupPatch ? { ...groupPatch } : {};
1992
+ const mergedOrigin = mergeOrigin(params.existing?.origin, origin);
1993
+ if (mergedOrigin) patch.origin = mergedOrigin;
1994
+ return Object.keys(patch).length > 0 ? patch : null;
1995
+ }
1996
+
1997
+ //#endregion
1998
+ //#region src/config/sessions/main-session.ts
1999
+ function resolveMainSessionKey(cfg) {
2000
+ if (cfg?.session?.scope === "global") return "global";
2001
+ const agents = cfg?.agents?.list ?? [];
2002
+ return buildAgentMainSessionKey({
2003
+ agentId: normalizeAgentId(agents.find((agent) => agent?.default)?.id ?? agents[0]?.id ?? DEFAULT_AGENT_ID),
2004
+ mainKey: normalizeMainKey(cfg?.session?.mainKey)
2005
+ });
2006
+ }
2007
+ function resolveMainSessionKeyFromConfig() {
2008
+ return resolveMainSessionKey(loadConfig());
2009
+ }
2010
+ function resolveAgentMainSessionKey(params) {
2011
+ const mainKey = normalizeMainKey(params.cfg?.session?.mainKey);
2012
+ return buildAgentMainSessionKey({
2013
+ agentId: params.agentId,
2014
+ mainKey
2015
+ });
2016
+ }
2017
+ function resolveExplicitAgentSessionKey(params) {
2018
+ const agentId = params.agentId?.trim();
2019
+ if (!agentId) return;
2020
+ return resolveAgentMainSessionKey({
2021
+ cfg: params.cfg,
2022
+ agentId
2023
+ });
2024
+ }
2025
+ function canonicalizeMainSessionAlias(params) {
2026
+ const raw = params.sessionKey.trim();
2027
+ if (!raw) return raw;
2028
+ const agentId = normalizeAgentId(params.agentId);
2029
+ const mainKey = normalizeMainKey(params.cfg?.session?.mainKey);
2030
+ const agentMainSessionKey = buildAgentMainSessionKey({
2031
+ agentId,
2032
+ mainKey
2033
+ });
2034
+ const agentMainAliasKey = buildAgentMainSessionKey({
2035
+ agentId,
2036
+ mainKey: "main"
2037
+ });
2038
+ const isMainAlias = raw === "main" || raw === mainKey || raw === agentMainSessionKey || raw === agentMainAliasKey;
2039
+ if (params.cfg?.session?.scope === "global" && isMainAlias) return "global";
2040
+ if (isMainAlias) return agentMainSessionKey;
2041
+ return raw;
2042
+ }
2043
+
2044
+ //#endregion
2045
+ //#region src/config/sessions/types.ts
2046
+ function mergeSessionEntry(existing, patch) {
2047
+ const sessionId = patch.sessionId ?? existing?.sessionId ?? crypto.randomUUID();
2048
+ const updatedAt = Math.max(existing?.updatedAt ?? 0, patch.updatedAt ?? 0, Date.now());
2049
+ if (!existing) return {
2050
+ ...patch,
2051
+ sessionId,
2052
+ updatedAt
2053
+ };
2054
+ return {
2055
+ ...existing,
2056
+ ...patch,
2057
+ sessionId,
2058
+ updatedAt
2059
+ };
2060
+ }
2061
+ const DEFAULT_RESET_TRIGGERS = ["/new", "/reset"];
2062
+ const DEFAULT_IDLE_MINUTES = 60;
2063
+
2064
+ //#endregion
2065
+ //#region src/config/sessions/reset.ts
2066
+ const DEFAULT_RESET_MODE = "daily";
2067
+ const DEFAULT_RESET_AT_HOUR = 4;
2068
+ const THREAD_SESSION_MARKERS = [":thread:", ":topic:"];
2069
+ const GROUP_SESSION_MARKERS = [":group:", ":channel:"];
2070
+ function isThreadSessionKey(sessionKey) {
2071
+ const normalized = (sessionKey ?? "").toLowerCase();
2072
+ if (!normalized) return false;
2073
+ return THREAD_SESSION_MARKERS.some((marker) => normalized.includes(marker));
2074
+ }
2075
+ function resolveSessionResetType(params) {
2076
+ if (params.isThread || isThreadSessionKey(params.sessionKey)) return "thread";
2077
+ if (params.isGroup) return "group";
2078
+ const normalized = (params.sessionKey ?? "").toLowerCase();
2079
+ if (GROUP_SESSION_MARKERS.some((marker) => normalized.includes(marker))) return "group";
2080
+ return "dm";
2081
+ }
2082
+ function resolveThreadFlag(params) {
2083
+ if (params.messageThreadId != null) return true;
2084
+ if (params.threadLabel?.trim()) return true;
2085
+ if (params.threadStarterBody?.trim()) return true;
2086
+ if (params.parentSessionKey?.trim()) return true;
2087
+ return isThreadSessionKey(params.sessionKey);
2088
+ }
2089
+ function resolveDailyResetAtMs(now, atHour) {
2090
+ const normalizedAtHour = normalizeResetAtHour(atHour);
2091
+ const resetAt = new Date(now);
2092
+ resetAt.setHours(normalizedAtHour, 0, 0, 0);
2093
+ if (now < resetAt.getTime()) resetAt.setDate(resetAt.getDate() - 1);
2094
+ return resetAt.getTime();
2095
+ }
2096
+ function resolveSessionResetPolicy(params) {
2097
+ const sessionCfg = params.sessionCfg;
2098
+ const baseReset = params.resetOverride ?? sessionCfg?.reset;
2099
+ const typeReset = params.resetOverride ? void 0 : sessionCfg?.resetByType?.[params.resetType];
2100
+ const hasExplicitReset = Boolean(baseReset || sessionCfg?.resetByType);
2101
+ const legacyIdleMinutes = params.resetOverride ? void 0 : sessionCfg?.idleMinutes;
2102
+ const mode = typeReset?.mode ?? baseReset?.mode ?? (!hasExplicitReset && legacyIdleMinutes != null ? "idle" : DEFAULT_RESET_MODE);
2103
+ const atHour = normalizeResetAtHour(typeReset?.atHour ?? baseReset?.atHour ?? DEFAULT_RESET_AT_HOUR);
2104
+ const idleMinutesRaw = typeReset?.idleMinutes ?? baseReset?.idleMinutes ?? legacyIdleMinutes;
2105
+ let idleMinutes;
2106
+ if (idleMinutesRaw != null) {
2107
+ const normalized = Math.floor(idleMinutesRaw);
2108
+ if (Number.isFinite(normalized)) idleMinutes = Math.max(normalized, 1);
2109
+ } else if (mode === "idle") idleMinutes = DEFAULT_IDLE_MINUTES;
2110
+ return {
2111
+ mode,
2112
+ atHour,
2113
+ idleMinutes
2114
+ };
2115
+ }
2116
+ function resolveChannelResetConfig(params) {
2117
+ const resetByChannel = params.sessionCfg?.resetByChannel;
2118
+ if (!resetByChannel) return;
2119
+ const normalized = normalizeMessageChannel(params.channel);
2120
+ const fallback = params.channel?.trim().toLowerCase();
2121
+ const key = normalized ?? fallback;
2122
+ if (!key) return;
2123
+ return resetByChannel[key] ?? resetByChannel[key.toLowerCase()];
2124
+ }
2125
+ function evaluateSessionFreshness(params) {
2126
+ const dailyResetAt = params.policy.mode === "daily" ? resolveDailyResetAtMs(params.now, params.policy.atHour) : void 0;
2127
+ const idleExpiresAt = params.policy.idleMinutes != null ? params.updatedAt + params.policy.idleMinutes * 6e4 : void 0;
2128
+ const staleDaily = dailyResetAt != null && params.updatedAt < dailyResetAt;
2129
+ const staleIdle = idleExpiresAt != null && params.now > idleExpiresAt;
2130
+ return {
2131
+ fresh: !(staleDaily || staleIdle),
2132
+ dailyResetAt,
2133
+ idleExpiresAt
2134
+ };
2135
+ }
2136
+ function normalizeResetAtHour(value) {
2137
+ if (typeof value !== "number" || !Number.isFinite(value)) return DEFAULT_RESET_AT_HOUR;
2138
+ const normalized = Math.floor(value);
2139
+ if (!Number.isFinite(normalized)) return DEFAULT_RESET_AT_HOUR;
2140
+ if (normalized < 0) return 0;
2141
+ if (normalized > 23) return 23;
2142
+ return normalized;
2143
+ }
2144
+
2145
+ //#endregion
2146
+ //#region src/config/sessions/session-key.ts
2147
+ function deriveSessionKey(scope, ctx) {
2148
+ if (scope === "global") return "global";
2149
+ const resolvedGroup = resolveGroupSessionKey(ctx);
2150
+ if (resolvedGroup) return resolvedGroup.key;
2151
+ return (ctx.From ? normalizeE164(ctx.From) : "") || "unknown";
2152
+ }
2153
+ /**
2154
+ * Resolve the session key with a canonical direct-chat bucket (default: "main").
2155
+ * All non-group direct chats collapse to this bucket; groups stay isolated.
2156
+ */
2157
+ function resolveSessionKey(scope, ctx, mainKey) {
2158
+ const explicit = ctx.SessionKey?.trim();
2159
+ if (explicit) return explicit.toLowerCase();
2160
+ const raw = deriveSessionKey(scope, ctx);
2161
+ if (scope === "global") return raw;
2162
+ const canonical = buildAgentMainSessionKey({
2163
+ agentId: DEFAULT_AGENT_ID,
2164
+ mainKey: normalizeMainKey(mainKey)
2165
+ });
2166
+ if (!(raw.includes(":group:") || raw.includes(":channel:"))) return canonical;
2167
+ return `agent:${DEFAULT_AGENT_ID}:${raw}`;
2168
+ }
2169
+
2170
+ //#endregion
2171
+ //#region src/utils/account-id.ts
2172
+ function normalizeAccountId(value) {
2173
+ if (typeof value !== "string") return;
2174
+ return value.trim() || void 0;
2175
+ }
2176
+
2177
+ //#endregion
2178
+ //#region src/utils/delivery-context.ts
2179
+ function normalizeDeliveryContext(context) {
2180
+ if (!context) return;
2181
+ const channel = typeof context.channel === "string" ? normalizeMessageChannel(context.channel) ?? context.channel.trim() : void 0;
2182
+ const to = typeof context.to === "string" ? context.to.trim() : void 0;
2183
+ const accountId = normalizeAccountId(context.accountId);
2184
+ const threadId = typeof context.threadId === "number" && Number.isFinite(context.threadId) ? Math.trunc(context.threadId) : typeof context.threadId === "string" ? context.threadId.trim() : void 0;
2185
+ const normalizedThreadId = typeof threadId === "string" ? threadId ? threadId : void 0 : threadId;
2186
+ if (!channel && !to && !accountId && normalizedThreadId == null) return;
2187
+ const normalized = {
2188
+ channel: channel || void 0,
2189
+ to: to || void 0,
2190
+ accountId
2191
+ };
2192
+ if (normalizedThreadId != null) normalized.threadId = normalizedThreadId;
2193
+ return normalized;
2194
+ }
2195
+ function normalizeSessionDeliveryFields(source) {
2196
+ if (!source) return {
2197
+ deliveryContext: void 0,
2198
+ lastChannel: void 0,
2199
+ lastTo: void 0,
2200
+ lastAccountId: void 0,
2201
+ lastThreadId: void 0
2202
+ };
2203
+ const merged = mergeDeliveryContext(normalizeDeliveryContext({
2204
+ channel: source.lastChannel ?? source.channel,
2205
+ to: source.lastTo,
2206
+ accountId: source.lastAccountId,
2207
+ threadId: source.lastThreadId
2208
+ }), normalizeDeliveryContext(source.deliveryContext));
2209
+ if (!merged) return {
2210
+ deliveryContext: void 0,
2211
+ lastChannel: void 0,
2212
+ lastTo: void 0,
2213
+ lastAccountId: void 0,
2214
+ lastThreadId: void 0
2215
+ };
2216
+ return {
2217
+ deliveryContext: merged,
2218
+ lastChannel: merged.channel,
2219
+ lastTo: merged.to,
2220
+ lastAccountId: merged.accountId,
2221
+ lastThreadId: merged.threadId
2222
+ };
2223
+ }
2224
+ function deliveryContextFromSession(entry) {
2225
+ if (!entry) return;
2226
+ return normalizeSessionDeliveryFields({
2227
+ channel: entry.channel,
2228
+ lastChannel: entry.lastChannel,
2229
+ lastTo: entry.lastTo,
2230
+ lastAccountId: entry.lastAccountId,
2231
+ lastThreadId: entry.lastThreadId ?? entry.deliveryContext?.threadId ?? entry.origin?.threadId,
2232
+ deliveryContext: entry.deliveryContext
2233
+ }).deliveryContext;
2234
+ }
2235
+ function mergeDeliveryContext(primary, fallback) {
2236
+ const normalizedPrimary = normalizeDeliveryContext(primary);
2237
+ const normalizedFallback = normalizeDeliveryContext(fallback);
2238
+ if (!normalizedPrimary && !normalizedFallback) return;
2239
+ return normalizeDeliveryContext({
2240
+ channel: normalizedPrimary?.channel ?? normalizedFallback?.channel,
2241
+ to: normalizedPrimary?.to ?? normalizedFallback?.to,
2242
+ accountId: normalizedPrimary?.accountId ?? normalizedFallback?.accountId,
2243
+ threadId: normalizedPrimary?.threadId ?? normalizedFallback?.threadId
2244
+ });
2245
+ }
2246
+ function deliveryContextKey(context) {
2247
+ const normalized = normalizeDeliveryContext(context);
2248
+ if (!normalized?.channel || !normalized?.to) return;
2249
+ const threadId = normalized.threadId != null && normalized.threadId !== "" ? String(normalized.threadId) : "";
2250
+ return `${normalized.channel}|${normalized.to}|${normalized.accountId ?? ""}|${threadId}`;
2251
+ }
2252
+
2253
+ //#endregion
2254
+ //#region src/config/cache-utils.ts
2255
+ function resolveCacheTtlMs(params) {
2256
+ const { envValue, defaultTtlMs } = params;
2257
+ if (envValue) {
2258
+ const parsed = Number.parseInt(envValue, 10);
2259
+ if (Number.isFinite(parsed) && parsed >= 0) return parsed;
2260
+ }
2261
+ return defaultTtlMs;
2262
+ }
2263
+ function isCacheEnabled(ttlMs) {
2264
+ return ttlMs > 0;
2265
+ }
2266
+ function getFileMtimeMs(filePath) {
2267
+ try {
2268
+ return fs.statSync(filePath).mtimeMs;
2269
+ } catch {
2270
+ return;
2271
+ }
2272
+ }
2273
+
2274
+ //#endregion
2275
+ //#region src/config/sessions/store.ts
2276
+ const SESSION_STORE_CACHE = /* @__PURE__ */ new Map();
2277
+ const DEFAULT_SESSION_STORE_TTL_MS = 45e3;
2278
+ function isSessionStoreRecord(value) {
2279
+ return !!value && typeof value === "object" && !Array.isArray(value);
2280
+ }
2281
+ function getSessionStoreTtl() {
2282
+ return resolveCacheTtlMs({
2283
+ envValue: process.env.CRYPTOCLAW_SESSION_CACHE_TTL_MS,
2284
+ defaultTtlMs: DEFAULT_SESSION_STORE_TTL_MS
2285
+ });
2286
+ }
2287
+ function isSessionStoreCacheEnabled() {
2288
+ return isCacheEnabled(getSessionStoreTtl());
2289
+ }
2290
+ function isSessionStoreCacheValid(entry) {
2291
+ const now = Date.now();
2292
+ const ttl = getSessionStoreTtl();
2293
+ return now - entry.loadedAt <= ttl;
2294
+ }
2295
+ function invalidateSessionStoreCache(storePath) {
2296
+ SESSION_STORE_CACHE.delete(storePath);
2297
+ }
2298
+ function normalizeSessionEntryDelivery(entry) {
2299
+ const normalized = normalizeSessionDeliveryFields({
2300
+ channel: entry.channel,
2301
+ lastChannel: entry.lastChannel,
2302
+ lastTo: entry.lastTo,
2303
+ lastAccountId: entry.lastAccountId,
2304
+ lastThreadId: entry.lastThreadId ?? entry.deliveryContext?.threadId ?? entry.origin?.threadId,
2305
+ deliveryContext: entry.deliveryContext
2306
+ });
2307
+ const nextDelivery = normalized.deliveryContext;
2308
+ const sameDelivery = (entry.deliveryContext?.channel ?? void 0) === nextDelivery?.channel && (entry.deliveryContext?.to ?? void 0) === nextDelivery?.to && (entry.deliveryContext?.accountId ?? void 0) === nextDelivery?.accountId && (entry.deliveryContext?.threadId ?? void 0) === nextDelivery?.threadId;
2309
+ const sameLast = entry.lastChannel === normalized.lastChannel && entry.lastTo === normalized.lastTo && entry.lastAccountId === normalized.lastAccountId && entry.lastThreadId === normalized.lastThreadId;
2310
+ if (sameDelivery && sameLast) return entry;
2311
+ return {
2312
+ ...entry,
2313
+ deliveryContext: nextDelivery,
2314
+ lastChannel: normalized.lastChannel,
2315
+ lastTo: normalized.lastTo,
2316
+ lastAccountId: normalized.lastAccountId,
2317
+ lastThreadId: normalized.lastThreadId
2318
+ };
2319
+ }
2320
+ function normalizeSessionStore(store) {
2321
+ for (const [key, entry] of Object.entries(store)) {
2322
+ if (!entry) continue;
2323
+ const normalized = normalizeSessionEntryDelivery(entry);
2324
+ if (normalized !== entry) store[key] = normalized;
2325
+ }
2326
+ }
2327
+ function loadSessionStore(storePath, opts = {}) {
2328
+ if (!opts.skipCache && isSessionStoreCacheEnabled()) {
2329
+ const cached = SESSION_STORE_CACHE.get(storePath);
2330
+ if (cached && isSessionStoreCacheValid(cached)) {
2331
+ if (getFileMtimeMs(storePath) === cached.mtimeMs) return structuredClone(cached.store);
2332
+ invalidateSessionStoreCache(storePath);
2333
+ }
2334
+ }
2335
+ let store = {};
2336
+ let mtimeMs = getFileMtimeMs(storePath);
2337
+ try {
2338
+ const raw = fs.readFileSync(storePath, "utf-8");
2339
+ const parsed = JSON5.parse(raw);
2340
+ if (isSessionStoreRecord(parsed)) store = parsed;
2341
+ mtimeMs = getFileMtimeMs(storePath) ?? mtimeMs;
2342
+ } catch {}
2343
+ for (const entry of Object.values(store)) {
2344
+ if (!entry || typeof entry !== "object") continue;
2345
+ const rec = entry;
2346
+ if (typeof rec.channel !== "string" && typeof rec.provider === "string") {
2347
+ rec.channel = rec.provider;
2348
+ delete rec.provider;
2349
+ }
2350
+ if (typeof rec.lastChannel !== "string" && typeof rec.lastProvider === "string") {
2351
+ rec.lastChannel = rec.lastProvider;
2352
+ delete rec.lastProvider;
2353
+ }
2354
+ if (typeof rec.groupChannel !== "string" && typeof rec.room === "string") {
2355
+ rec.groupChannel = rec.room;
2356
+ delete rec.room;
2357
+ } else if ("room" in rec) delete rec.room;
2358
+ }
2359
+ if (!opts.skipCache && isSessionStoreCacheEnabled()) SESSION_STORE_CACHE.set(storePath, {
2360
+ store: structuredClone(store),
2361
+ loadedAt: Date.now(),
2362
+ storePath,
2363
+ mtimeMs
2364
+ });
2365
+ return structuredClone(store);
2366
+ }
2367
+ function readSessionUpdatedAt(params) {
2368
+ try {
2369
+ return loadSessionStore(params.storePath)[params.sessionKey]?.updatedAt;
2370
+ } catch {
2371
+ return;
2372
+ }
2373
+ }
2374
+ async function saveSessionStoreUnlocked(storePath, store) {
2375
+ invalidateSessionStoreCache(storePath);
2376
+ normalizeSessionStore(store);
2377
+ await fs.promises.mkdir(path.dirname(storePath), { recursive: true });
2378
+ const json = JSON.stringify(store, null, 2);
2379
+ if (process.platform === "win32") {
2380
+ try {
2381
+ await fs.promises.writeFile(storePath, json, "utf-8");
2382
+ } catch (err) {
2383
+ if ((err && typeof err === "object" && "code" in err ? String(err.code) : null) === "ENOENT") return;
2384
+ throw err;
2385
+ }
2386
+ return;
2387
+ }
2388
+ const tmp = `${storePath}.${process.pid}.${crypto.randomUUID()}.tmp`;
2389
+ try {
2390
+ await fs.promises.writeFile(tmp, json, {
2391
+ mode: 384,
2392
+ encoding: "utf-8"
2393
+ });
2394
+ await fs.promises.rename(tmp, storePath);
2395
+ await fs.promises.chmod(storePath, 384);
2396
+ } catch (err) {
2397
+ if ((err && typeof err === "object" && "code" in err ? String(err.code) : null) === "ENOENT") {
2398
+ try {
2399
+ await fs.promises.mkdir(path.dirname(storePath), { recursive: true });
2400
+ await fs.promises.writeFile(storePath, json, {
2401
+ mode: 384,
2402
+ encoding: "utf-8"
2403
+ });
2404
+ await fs.promises.chmod(storePath, 384);
2405
+ } catch (err2) {
2406
+ if ((err2 && typeof err2 === "object" && "code" in err2 ? String(err2.code) : null) === "ENOENT") return;
2407
+ throw err2;
2408
+ }
2409
+ return;
2410
+ }
2411
+ throw err;
2412
+ } finally {
2413
+ await fs.promises.rm(tmp, { force: true });
2414
+ }
2415
+ }
2416
+ async function saveSessionStore(storePath, store) {
2417
+ await withSessionStoreLock(storePath, async () => {
2418
+ await saveSessionStoreUnlocked(storePath, store);
2419
+ });
2420
+ }
2421
+ async function updateSessionStore(storePath, mutator) {
2422
+ return await withSessionStoreLock(storePath, async () => {
2423
+ const store = loadSessionStore(storePath, { skipCache: true });
2424
+ const result = await mutator(store);
2425
+ await saveSessionStoreUnlocked(storePath, store);
2426
+ return result;
2427
+ });
2428
+ }
2429
+ async function withSessionStoreLock(storePath, fn, opts = {}) {
2430
+ const timeoutMs = opts.timeoutMs ?? 1e4;
2431
+ const pollIntervalMs = opts.pollIntervalMs ?? 25;
2432
+ const staleMs = opts.staleMs ?? 3e4;
2433
+ const lockPath = `${storePath}.lock`;
2434
+ const startedAt = Date.now();
2435
+ await fs.promises.mkdir(path.dirname(storePath), { recursive: true });
2436
+ while (true) try {
2437
+ const handle = await fs.promises.open(lockPath, "wx");
2438
+ try {
2439
+ await handle.writeFile(JSON.stringify({
2440
+ pid: process.pid,
2441
+ startedAt: Date.now()
2442
+ }), "utf-8");
2443
+ } catch {}
2444
+ await handle.close();
2445
+ break;
2446
+ } catch (err) {
2447
+ const code = err && typeof err === "object" && "code" in err ? String(err.code) : null;
2448
+ if (code === "ENOENT") {
2449
+ await fs.promises.mkdir(path.dirname(storePath), { recursive: true }).catch(() => void 0);
2450
+ await new Promise((r) => setTimeout(r, pollIntervalMs));
2451
+ continue;
2452
+ }
2453
+ if (code !== "EEXIST") throw err;
2454
+ const now = Date.now();
2455
+ if (now - startedAt > timeoutMs) throw new Error(`timeout acquiring session store lock: ${lockPath}`, { cause: err });
2456
+ try {
2457
+ if (now - (await fs.promises.stat(lockPath)).mtimeMs > staleMs) {
2458
+ await fs.promises.unlink(lockPath);
2459
+ continue;
2460
+ }
2461
+ } catch {}
2462
+ await new Promise((r) => setTimeout(r, pollIntervalMs));
2463
+ }
2464
+ try {
2465
+ return await fn();
2466
+ } finally {
2467
+ await fs.promises.unlink(lockPath).catch(() => void 0);
2468
+ }
2469
+ }
2470
+ async function updateSessionStoreEntry(params) {
2471
+ const { storePath, sessionKey, update } = params;
2472
+ return await withSessionStoreLock(storePath, async () => {
2473
+ const store = loadSessionStore(storePath);
2474
+ const existing = store[sessionKey];
2475
+ if (!existing) return null;
2476
+ const patch = await update(existing);
2477
+ if (!patch) return existing;
2478
+ const next = mergeSessionEntry(existing, patch);
2479
+ store[sessionKey] = next;
2480
+ await saveSessionStoreUnlocked(storePath, store);
2481
+ return next;
2482
+ });
2483
+ }
2484
+ async function recordSessionMetaFromInbound(params) {
2485
+ const { storePath, sessionKey, ctx } = params;
2486
+ const createIfMissing = params.createIfMissing ?? true;
2487
+ return await updateSessionStore(storePath, (store) => {
2488
+ const existing = store[sessionKey];
2489
+ const patch = deriveSessionMetaPatch({
2490
+ ctx,
2491
+ sessionKey,
2492
+ existing,
2493
+ groupResolution: params.groupResolution
2494
+ });
2495
+ if (!patch) return existing ?? null;
2496
+ if (!existing && !createIfMissing) return null;
2497
+ const next = mergeSessionEntry(existing, patch);
2498
+ store[sessionKey] = next;
2499
+ return next;
2500
+ });
2501
+ }
2502
+ async function updateLastRoute(params) {
2503
+ const { storePath, sessionKey, channel, to, accountId, threadId, ctx } = params;
2504
+ return await withSessionStoreLock(storePath, async () => {
2505
+ const store = loadSessionStore(storePath);
2506
+ const existing = store[sessionKey];
2507
+ const now = Date.now();
2508
+ const merged = mergeDeliveryContext(mergeDeliveryContext(normalizeDeliveryContext(params.deliveryContext), normalizeDeliveryContext({
2509
+ channel,
2510
+ to,
2511
+ accountId,
2512
+ threadId
2513
+ })), deliveryContextFromSession(existing));
2514
+ const normalized = normalizeSessionDeliveryFields({ deliveryContext: {
2515
+ channel: merged?.channel,
2516
+ to: merged?.to,
2517
+ accountId: merged?.accountId,
2518
+ threadId: merged?.threadId
2519
+ } });
2520
+ const metaPatch = ctx ? deriveSessionMetaPatch({
2521
+ ctx,
2522
+ sessionKey,
2523
+ existing,
2524
+ groupResolution: params.groupResolution
2525
+ }) : null;
2526
+ const basePatch = {
2527
+ updatedAt: Math.max(existing?.updatedAt ?? 0, now),
2528
+ deliveryContext: normalized.deliveryContext,
2529
+ lastChannel: normalized.lastChannel,
2530
+ lastTo: normalized.lastTo,
2531
+ lastAccountId: normalized.lastAccountId,
2532
+ lastThreadId: normalized.lastThreadId
2533
+ };
2534
+ const next = mergeSessionEntry(existing, metaPatch ? {
2535
+ ...basePatch,
2536
+ ...metaPatch
2537
+ } : basePatch);
2538
+ store[sessionKey] = next;
2539
+ await saveSessionStoreUnlocked(storePath, store);
2540
+ return next;
2541
+ });
2542
+ }
2543
+
2544
+ //#endregion
2545
+ //#region src/config/sessions/transcript.ts
2546
+ function stripQuery(value) {
2547
+ const noHash = value.split("#")[0] ?? value;
2548
+ return noHash.split("?")[0] ?? noHash;
2549
+ }
2550
+ function extractFileNameFromMediaUrl(value) {
2551
+ const trimmed = value.trim();
2552
+ if (!trimmed) return null;
2553
+ const cleaned = stripQuery(trimmed);
2554
+ try {
2555
+ const parsed = new URL(cleaned);
2556
+ const base = path.basename(parsed.pathname);
2557
+ if (!base) return null;
2558
+ try {
2559
+ return decodeURIComponent(base);
2560
+ } catch {
2561
+ return base;
2562
+ }
2563
+ } catch {
2564
+ const base = path.basename(cleaned);
2565
+ if (!base || base === "/" || base === ".") return null;
2566
+ return base;
2567
+ }
2568
+ }
2569
+ function resolveMirroredTranscriptText(params) {
2570
+ const mediaUrls = params.mediaUrls?.filter((url) => url && url.trim()) ?? [];
2571
+ if (mediaUrls.length > 0) {
2572
+ const names = mediaUrls.map((url) => extractFileNameFromMediaUrl(url)).filter((name) => Boolean(name && name.trim()));
2573
+ if (names.length > 0) return names.join(", ");
2574
+ return "media";
2575
+ }
2576
+ const trimmed = (params.text ?? "").trim();
2577
+ return trimmed ? trimmed : null;
2578
+ }
2579
+ async function ensureSessionHeader(params) {
2580
+ if (fs.existsSync(params.sessionFile)) return;
2581
+ await fs.promises.mkdir(path.dirname(params.sessionFile), { recursive: true });
2582
+ const header = {
2583
+ type: "session",
2584
+ version: CURRENT_SESSION_VERSION,
2585
+ id: params.sessionId,
2586
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
2587
+ cwd: process.cwd()
2588
+ };
2589
+ await fs.promises.writeFile(params.sessionFile, `${JSON.stringify(header)}\n`, "utf-8");
2590
+ }
2591
+ async function appendAssistantMessageToSessionTranscript(params) {
2592
+ const sessionKey = params.sessionKey.trim();
2593
+ if (!sessionKey) return {
2594
+ ok: false,
2595
+ reason: "missing sessionKey"
2596
+ };
2597
+ const mirrorText = resolveMirroredTranscriptText({
2598
+ text: params.text,
2599
+ mediaUrls: params.mediaUrls
2600
+ });
2601
+ if (!mirrorText) return {
2602
+ ok: false,
2603
+ reason: "empty text"
2604
+ };
2605
+ const storePath = params.storePath ?? resolveDefaultSessionStorePath(params.agentId);
2606
+ const entry = loadSessionStore(storePath, { skipCache: true })[sessionKey];
2607
+ if (!entry?.sessionId) return {
2608
+ ok: false,
2609
+ reason: `unknown sessionKey: ${sessionKey}`
2610
+ };
2611
+ const sessionFile = entry.sessionFile?.trim() || resolveSessionTranscriptPath(entry.sessionId, params.agentId);
2612
+ await ensureSessionHeader({
2613
+ sessionFile,
2614
+ sessionId: entry.sessionId
2615
+ });
2616
+ SessionManager.open(sessionFile).appendMessage({
2617
+ role: "assistant",
2618
+ content: [{
2619
+ type: "text",
2620
+ text: mirrorText
2621
+ }],
2622
+ api: "openai-responses",
2623
+ provider: "cryptoclaw",
2624
+ model: "delivery-mirror",
2625
+ usage: {
2626
+ input: 0,
2627
+ output: 0,
2628
+ cacheRead: 0,
2629
+ cacheWrite: 0,
2630
+ totalTokens: 0,
2631
+ cost: {
2632
+ input: 0,
2633
+ output: 0,
2634
+ cacheRead: 0,
2635
+ cacheWrite: 0,
2636
+ total: 0
2637
+ }
2638
+ },
2639
+ stopReason: "stop",
2640
+ timestamp: Date.now()
2641
+ });
2642
+ if (!entry.sessionFile || entry.sessionFile !== sessionFile) await updateSessionStore(storePath, (current) => {
2643
+ current[sessionKey] = {
2644
+ ...entry,
2645
+ sessionFile
2646
+ };
2647
+ });
2648
+ emitSessionTranscriptUpdate(sessionFile);
2649
+ return {
2650
+ ok: true,
2651
+ sessionFile
2652
+ };
2653
+ }
2654
+
2655
+ //#endregion
2656
+ //#region src/agents/sandbox/runtime-status.ts
2657
+ function shouldSandboxSession(cfg, sessionKey, mainSessionKey) {
2658
+ if (cfg.mode === "off") return false;
2659
+ if (cfg.mode === "all") return true;
2660
+ return sessionKey.trim() !== mainSessionKey.trim();
2661
+ }
2662
+ function resolveMainSessionKeyForSandbox(params) {
2663
+ if (params.cfg?.session?.scope === "global") return "global";
2664
+ return resolveAgentMainSessionKey({
2665
+ cfg: params.cfg,
2666
+ agentId: params.agentId
2667
+ });
2668
+ }
2669
+ function resolveComparableSessionKeyForSandbox(params) {
2670
+ return canonicalizeMainSessionAlias({
2671
+ cfg: params.cfg,
2672
+ agentId: params.agentId,
2673
+ sessionKey: params.sessionKey
2674
+ });
2675
+ }
2676
+ function resolveSandboxRuntimeStatus(params) {
2677
+ const sessionKey = params.sessionKey?.trim() ?? "";
2678
+ const agentId = resolveSessionAgentId({
2679
+ sessionKey,
2680
+ config: params.cfg
2681
+ });
2682
+ const cfg = params.cfg;
2683
+ const sandboxCfg = resolveSandboxConfigForAgent(cfg, agentId);
2684
+ const mainSessionKey = resolveMainSessionKeyForSandbox({
2685
+ cfg,
2686
+ agentId
2687
+ });
2688
+ const sandboxed = sessionKey ? shouldSandboxSession(sandboxCfg, resolveComparableSessionKeyForSandbox({
2689
+ cfg,
2690
+ agentId,
2691
+ sessionKey
2692
+ }), mainSessionKey) : false;
2693
+ return {
2694
+ agentId,
2695
+ sessionKey,
2696
+ mainSessionKey,
2697
+ mode: sandboxCfg.mode,
2698
+ sandboxed,
2699
+ toolPolicy: resolveSandboxToolPolicyForAgent(cfg, agentId)
2700
+ };
2701
+ }
2702
+ function formatSandboxToolPolicyBlockedMessage(params) {
2703
+ const tool = params.toolName.trim().toLowerCase();
2704
+ if (!tool) return;
2705
+ const runtime = resolveSandboxRuntimeStatus({
2706
+ cfg: params.cfg,
2707
+ sessionKey: params.sessionKey
2708
+ });
2709
+ if (!runtime.sandboxed) return;
2710
+ const deny = new Set(expandToolGroups(runtime.toolPolicy.deny));
2711
+ const allow = expandToolGroups(runtime.toolPolicy.allow);
2712
+ const allowSet = allow.length > 0 ? new Set(allow) : null;
2713
+ const blockedByDeny = deny.has(tool);
2714
+ const blockedByAllow = allowSet ? !allowSet.has(tool) : false;
2715
+ if (!blockedByDeny && !blockedByAllow) return;
2716
+ const reasons = [];
2717
+ const fixes = [];
2718
+ if (blockedByDeny) {
2719
+ reasons.push("deny list");
2720
+ fixes.push(`Remove "${tool}" from ${runtime.toolPolicy.sources.deny.key}.`);
2721
+ }
2722
+ if (blockedByAllow) {
2723
+ reasons.push("allow list");
2724
+ fixes.push(`Add "${tool}" to ${runtime.toolPolicy.sources.allow.key} (or set it to [] to allow all).`);
2725
+ }
2726
+ const lines = [];
2727
+ lines.push(`Tool "${tool}" blocked by sandbox tool policy (mode=${runtime.mode}).`);
2728
+ lines.push(`Session: ${runtime.sessionKey || "(unknown)"}`);
2729
+ lines.push(`Reason: ${reasons.join(" + ")}`);
2730
+ lines.push("Fix:");
2731
+ lines.push(`- agents.defaults.sandbox.mode=off (disable sandbox)`);
2732
+ for (const fix of fixes) lines.push(`- ${fix}`);
2733
+ if (runtime.mode === "non-main") lines.push(`- Use main session key (direct): ${runtime.mainSessionKey}`);
2734
+ lines.push(`- See: ${formatCliCommand(`cryptoclaw sandbox explain --session ${runtime.sessionKey}`)}`);
2735
+ return lines.join("\n");
2736
+ }
2737
+
2738
+ //#endregion
2739
+ //#region src/agents/sandbox/workspace.ts
2740
+ async function ensureSandboxWorkspace(workspaceDir, seedFrom, skipBootstrap) {
2741
+ await fs$1.mkdir(workspaceDir, { recursive: true });
2742
+ if (seedFrom) {
2743
+ const seed = resolveUserPath(seedFrom);
2744
+ const files = [
2745
+ DEFAULT_AGENTS_FILENAME,
2746
+ DEFAULT_SOUL_FILENAME,
2747
+ DEFAULT_TOOLS_FILENAME,
2748
+ DEFAULT_IDENTITY_FILENAME,
2749
+ DEFAULT_USER_FILENAME,
2750
+ DEFAULT_BOOTSTRAP_FILENAME,
2751
+ DEFAULT_HEARTBEAT_FILENAME
2752
+ ];
2753
+ for (const name of files) {
2754
+ const src = path.join(seed, name);
2755
+ const dest = path.join(workspaceDir, name);
2756
+ try {
2757
+ await fs$1.access(dest);
2758
+ } catch {
2759
+ try {
2760
+ const content = await fs$1.readFile(src, "utf-8");
2761
+ await fs$1.writeFile(dest, content, {
2762
+ encoding: "utf-8",
2763
+ flag: "wx"
2764
+ });
2765
+ } catch {}
2766
+ }
2767
+ }
2768
+ }
2769
+ await ensureAgentWorkspace({
2770
+ dir: workspaceDir,
2771
+ ensureBootstrapFiles: !skipBootstrap
2772
+ });
2773
+ }
2774
+
2775
+ //#endregion
2776
+ //#region src/agents/sandbox/context.ts
2777
+ async function resolveSandboxContext(params) {
2778
+ const rawSessionKey = params.sessionKey?.trim();
2779
+ if (!rawSessionKey) return null;
2780
+ const runtime = resolveSandboxRuntimeStatus({
2781
+ cfg: params.config,
2782
+ sessionKey: rawSessionKey
2783
+ });
2784
+ if (!runtime.sandboxed) return null;
2785
+ const cfg = resolveSandboxConfigForAgent(params.config, runtime.agentId);
2786
+ await maybePruneSandboxes(cfg);
2787
+ const agentWorkspaceDir = resolveUserPath(params.workspaceDir?.trim() || DEFAULT_AGENT_WORKSPACE_DIR);
2788
+ const workspaceRoot = resolveUserPath(cfg.workspaceRoot);
2789
+ const scopeKey = resolveSandboxScopeKey(cfg.scope, rawSessionKey);
2790
+ const sandboxWorkspaceDir = cfg.scope === "shared" ? workspaceRoot : resolveSandboxWorkspaceDir(workspaceRoot, scopeKey);
2791
+ const workspaceDir = cfg.workspaceAccess === "rw" ? agentWorkspaceDir : sandboxWorkspaceDir;
2792
+ if (workspaceDir === sandboxWorkspaceDir) {
2793
+ await ensureSandboxWorkspace(sandboxWorkspaceDir, agentWorkspaceDir, params.config?.agents?.defaults?.skipBootstrap);
2794
+ if (cfg.workspaceAccess !== "rw") try {
2795
+ await syncSkillsToWorkspace({
2796
+ sourceWorkspaceDir: agentWorkspaceDir,
2797
+ targetWorkspaceDir: sandboxWorkspaceDir,
2798
+ config: params.config
2799
+ });
2800
+ } catch (error) {
2801
+ const message = error instanceof Error ? error.message : JSON.stringify(error);
2802
+ defaultRuntime.error?.(`Sandbox skill sync failed: ${message}`);
2803
+ }
2804
+ } else await fs$1.mkdir(workspaceDir, { recursive: true });
2805
+ const containerName = await ensureSandboxContainer({
2806
+ sessionKey: rawSessionKey,
2807
+ workspaceDir,
2808
+ agentWorkspaceDir,
2809
+ cfg
2810
+ });
2811
+ const browser = await ensureSandboxBrowser({
2812
+ scopeKey,
2813
+ workspaceDir,
2814
+ agentWorkspaceDir,
2815
+ cfg,
2816
+ evaluateEnabled: params.config?.browser?.evaluateEnabled ?? DEFAULT_BROWSER_EVALUATE_ENABLED
2817
+ });
2818
+ return {
2819
+ enabled: true,
2820
+ sessionKey: rawSessionKey,
2821
+ workspaceDir,
2822
+ agentWorkspaceDir,
2823
+ workspaceAccess: cfg.workspaceAccess,
2824
+ containerName,
2825
+ containerWorkdir: cfg.docker.workdir,
2826
+ docker: cfg.docker,
2827
+ tools: cfg.tools,
2828
+ browserAllowHostControl: cfg.browser.allowHostControl,
2829
+ browser: browser ?? void 0
2830
+ };
2831
+ }
2832
+ async function ensureSandboxWorkspaceForSession(params) {
2833
+ const rawSessionKey = params.sessionKey?.trim();
2834
+ if (!rawSessionKey) return null;
2835
+ const runtime = resolveSandboxRuntimeStatus({
2836
+ cfg: params.config,
2837
+ sessionKey: rawSessionKey
2838
+ });
2839
+ if (!runtime.sandboxed) return null;
2840
+ const cfg = resolveSandboxConfigForAgent(params.config, runtime.agentId);
2841
+ const agentWorkspaceDir = resolveUserPath(params.workspaceDir?.trim() || DEFAULT_AGENT_WORKSPACE_DIR);
2842
+ const workspaceRoot = resolveUserPath(cfg.workspaceRoot);
2843
+ const scopeKey = resolveSandboxScopeKey(cfg.scope, rawSessionKey);
2844
+ const sandboxWorkspaceDir = cfg.scope === "shared" ? workspaceRoot : resolveSandboxWorkspaceDir(workspaceRoot, scopeKey);
2845
+ const workspaceDir = cfg.workspaceAccess === "rw" ? agentWorkspaceDir : sandboxWorkspaceDir;
2846
+ if (workspaceDir === sandboxWorkspaceDir) {
2847
+ await ensureSandboxWorkspace(sandboxWorkspaceDir, agentWorkspaceDir, params.config?.agents?.defaults?.skipBootstrap);
2848
+ if (cfg.workspaceAccess !== "rw") try {
2849
+ await syncSkillsToWorkspace({
2850
+ sourceWorkspaceDir: agentWorkspaceDir,
2851
+ targetWorkspaceDir: sandboxWorkspaceDir,
2852
+ config: params.config
2853
+ });
2854
+ } catch (error) {
2855
+ const message = error instanceof Error ? error.message : JSON.stringify(error);
2856
+ defaultRuntime.error?.(`Sandbox skill sync failed: ${message}`);
2857
+ }
2858
+ } else await fs$1.mkdir(workspaceDir, { recursive: true });
2859
+ return {
2860
+ workspaceDir,
2861
+ containerWorkdir: cfg.docker.workdir
2862
+ };
2863
+ }
2864
+
2865
+ //#endregion
2866
+ //#region src/agents/sandbox/manage.ts
2867
+ async function listSandboxContainers() {
2868
+ const config = loadConfig();
2869
+ const registry = await readRegistry();
2870
+ const results = [];
2871
+ for (const entry of registry.entries) {
2872
+ const state = await dockerContainerState(entry.containerName);
2873
+ let actualImage = entry.image;
2874
+ if (state.exists) try {
2875
+ const result = await execDocker([
2876
+ "inspect",
2877
+ "-f",
2878
+ "{{.Config.Image}}",
2879
+ entry.containerName
2880
+ ], { allowFailure: true });
2881
+ if (result.code === 0) actualImage = result.stdout.trim();
2882
+ } catch {}
2883
+ const configuredImage = resolveSandboxConfigForAgent(config, resolveSandboxAgentId(entry.sessionKey)).docker.image;
2884
+ results.push({
2885
+ ...entry,
2886
+ image: actualImage,
2887
+ running: state.running,
2888
+ imageMatch: actualImage === configuredImage
2889
+ });
2890
+ }
2891
+ return results;
2892
+ }
2893
+ async function listSandboxBrowsers() {
2894
+ const config = loadConfig();
2895
+ const registry = await readBrowserRegistry();
2896
+ const results = [];
2897
+ for (const entry of registry.entries) {
2898
+ const state = await dockerContainerState(entry.containerName);
2899
+ let actualImage = entry.image;
2900
+ if (state.exists) try {
2901
+ const result = await execDocker([
2902
+ "inspect",
2903
+ "-f",
2904
+ "{{.Config.Image}}",
2905
+ entry.containerName
2906
+ ], { allowFailure: true });
2907
+ if (result.code === 0) actualImage = result.stdout.trim();
2908
+ } catch {}
2909
+ const configuredImage = resolveSandboxConfigForAgent(config, resolveSandboxAgentId(entry.sessionKey)).browser.image;
2910
+ results.push({
2911
+ ...entry,
2912
+ image: actualImage,
2913
+ running: state.running,
2914
+ imageMatch: actualImage === configuredImage
2915
+ });
2916
+ }
2917
+ return results;
2918
+ }
2919
+ async function removeSandboxContainer(containerName) {
2920
+ try {
2921
+ await execDocker([
2922
+ "rm",
2923
+ "-f",
2924
+ containerName
2925
+ ], { allowFailure: true });
2926
+ } catch {}
2927
+ await removeRegistryEntry(containerName);
2928
+ }
2929
+ async function removeSandboxBrowserContainer(containerName) {
2930
+ try {
2931
+ await execDocker([
2932
+ "rm",
2933
+ "-f",
2934
+ containerName
2935
+ ], { allowFailure: true });
2936
+ } catch {}
2937
+ await removeBrowserRegistryEntry(containerName);
2938
+ for (const [sessionKey, bridge] of BROWSER_BRIDGES.entries()) if (bridge.containerName === containerName) {
2939
+ await stopBrowserBridgeServer(bridge.bridge.server).catch(() => void 0);
2940
+ BROWSER_BRIDGES.delete(sessionKey);
2941
+ }
2942
+ }
2943
+
2944
+ //#endregion
2945
+ export { resolveSandboxToolPolicyForAgent as $, resolveSessionResetPolicy as A, snapshotSessionOrigin as B, normalizeDeliveryContext as C, resolveSessionKey as D, deriveSessionKey as E, resolveAgentMainSessionKey as F, resolveChannelGroupToolsPolicy as G, listChannelDocks as H, resolveExplicitAgentSessionKey as I, resolveIMessageAccount as J, listEnabledSignalAccounts as K, resolveMainSessionKey as L, resolveThreadFlag as M, DEFAULT_RESET_TRIGGERS as N, evaluateSessionFreshness as O, canonicalizeMainSessionAlias as P, resolveSandboxScope as Q, resolveMainSessionKeyFromConfig as R, mergeDeliveryContext as S, normalizeAccountId as T, resolveChannelGroupPolicy as U, getChannelDock as V, resolveChannelGroupRequireMention as W, resolveGroupSessionKey as X, buildGroupDisplayName as Y, resolveSandboxConfigForAgent as Z, updateSessionStoreEntry as _, ensureSandboxWorkspaceForSession as a, normalizeToolName as at, deliveryContextFromSession as b, resolveSandboxRuntimeStatus as c, DEFAULT_SANDBOX_BROWSER_IMAGE as ct, loadSessionStore as d, resolveConversationLabel as dt, applyOwnerOnlyToolPolicy as et, readSessionUpdatedAt as f, updateSessionStore as g, updateLastRoute as h, removeSandboxContainer as i, expandToolGroups as it, resolveSessionResetType as j, resolveChannelResetConfig as k, appendAssistantMessageToSessionTranscript as l, DEFAULT_SANDBOX_COMMON_IMAGE as lt, saveSessionStore as m, listSandboxContainers as n, collectExplicitAllowlist as nt, resolveSandboxContext as o, resolveToolProfilePolicy as ot, recordSessionMetaFromInbound as p, resolveSignalAccount as q, removeSandboxBrowserContainer as r, expandPolicyWithPluginGroups as rt, formatSandboxToolPolicyBlockedMessage as s, stripPluginOnlyAllowlist as st, listSandboxBrowsers as t, buildPluginToolGroups as tt, resolveMirroredTranscriptText as u, DEFAULT_SANDBOX_IMAGE as ut, isCacheEnabled as v, normalizeSessionDeliveryFields as w, deliveryContextKey as x, resolveCacheTtlMs as y, deriveSessionMetaPatch as z };