chainlesschain 0.162.147 → 0.162.149

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 (257) hide show
  1. package/README.md +1 -1
  2. package/package.json +2 -2
  3. package/src/assets/web-panel/.build-hash +1 -1
  4. package/src/assets/web-panel/assets/{AIOps-DywJ7xTv.js → AIOps-BJif14yR.js} +1 -1
  5. package/src/assets/web-panel/assets/{ActionButton-BTlqcY-q.js → ActionButton-CXek6gJY.js} +1 -1
  6. package/src/assets/web-panel/assets/{Analytics-FdG1Mvwy.js → Analytics-BgQhdAJi.js} +3 -3
  7. package/src/assets/web-panel/assets/{AppLayout-CVsnbvN1.js → AppLayout-DTYl5NtR.js} +5 -5
  8. package/src/assets/web-panel/assets/{Audit-ITdpJ7vR.js → Audit-BzATQAeR.js} +1 -1
  9. package/src/assets/web-panel/assets/{Backup-BfXqnXo1.js → Backup-BzdPEQhL.js} +1 -1
  10. package/src/assets/web-panel/assets/{BaseInput-C09ip3_E.js → BaseInput-BM0KVh8E.js} +1 -1
  11. package/src/assets/web-panel/assets/{Chat-qdkhB42l.js → Chat-D7fHXHkz.js} +6 -6
  12. package/src/assets/web-panel/assets/{ChatBubbleRenderer-D2KfETZD.js → ChatBubbleRenderer-Wm34RR-b.js} +1 -1
  13. package/src/assets/web-panel/assets/{Checkbox-j6WZCuff.js → Checkbox-CAiSQ9vO.js} +1 -1
  14. package/src/assets/web-panel/assets/{Codegen-CGZ-K3uK.js → Codegen-Df40CrEe.js} +1 -1
  15. package/src/assets/web-panel/assets/{Col-CIlPOAu6.js → Col-DIT2fNFU.js} +1 -1
  16. package/src/assets/web-panel/assets/{Community-sY-i-hic.js → Community-CSTIbW2k.js} +1 -1
  17. package/src/assets/web-panel/assets/{Compact-DcoEfyL8.js → Compact-DtqXZZUi.js} +1 -1
  18. package/src/assets/web-panel/assets/Compliance-CUtzw6o7.js +1 -0
  19. package/src/assets/web-panel/assets/{Cowork-DLY_fkLv.js → Cowork-CezmlnmU.js} +3 -3
  20. package/src/assets/web-panel/assets/{Cron-D049pZBC.js → Cron-P4BITarg.js} +2 -2
  21. package/src/assets/web-panel/assets/{Crosschain-DCXdE8M9.js → Crosschain-BRRiYwvq.js} +1 -1
  22. package/src/assets/web-panel/assets/{DID-JCvPZtjW.js → DID-L5ijB9i4.js} +2 -2
  23. package/src/assets/web-panel/assets/{Dashboard-Cg2xu3iE.js → Dashboard-CFxro4ob.js} +2 -2
  24. package/src/assets/web-panel/assets/{Dropdown-DjJLjbLh.js → Dropdown-BmAFCQ71.js} +1 -1
  25. package/src/assets/web-panel/assets/{EmailListRenderer-DugNcSLR.js → EmailListRenderer-DJBCEuon.js} +1 -1
  26. package/src/assets/web-panel/assets/{FamilyGuardDashboard-J6Nb-E30.js → FamilyGuardDashboard-z4oLq6eT.js} +1 -1
  27. package/src/assets/web-panel/assets/{Federation-CQ3Ttpbl.js → Federation-DsVCpHMF.js} +1 -1
  28. package/src/assets/web-panel/assets/{FormItemContext-Cz0NKag4.js → FormItemContext-DP3bP5th.js} +1 -1
  29. package/src/assets/web-panel/assets/{GenericCardRenderer-NYcMP6iz.js → GenericCardRenderer-BAXP2Gc6.js} +1 -1
  30. package/src/assets/web-panel/assets/{Git-B4hYN18N.js → Git-I3g_bAw9.js} +2 -2
  31. package/src/assets/web-panel/assets/{Governance-DOQPCcC0.js → Governance-jHS5-ioS.js} +1 -1
  32. package/src/assets/web-panel/assets/{Inference-HtLF746W.js → Inference-CPL7sfx9.js} +1 -1
  33. package/src/assets/web-panel/assets/{KnowledgeGraph-BXrk8rMm.js → KnowledgeGraph-Jf236h4C.js} +1 -1
  34. package/src/assets/web-panel/assets/{Logs-DS0JnD3-.js → Logs-Cm2tcSKg.js} +2 -2
  35. package/src/assets/web-panel/assets/{Marketplace-Cqnjihrz.js → Marketplace-CZK82rhi.js} +1 -1
  36. package/src/assets/web-panel/assets/{McpTools-Cx3Psk-U.js → McpTools-CZCeji7a.js} +5 -5
  37. package/src/assets/web-panel/assets/{Memory-BjyysPtj.js → Memory-3l2KVS9k.js} +2 -2
  38. package/src/assets/web-panel/assets/MobileBridge-D3Arxfeg.css +1 -0
  39. package/src/assets/web-panel/assets/MobileBridge-VYdpoLh6.js +1 -0
  40. package/src/assets/web-panel/assets/{MobileProjects-Xwf-fdOQ.js → MobileProjects-CiB9cmm1.js} +1 -1
  41. package/src/assets/web-panel/assets/{Mtc-Djkql5m5.js → Mtc-wCFZbBuL.js} +2 -2
  42. package/src/assets/web-panel/assets/{MtcAudit-D2BAZlu0.js → MtcAudit-1a3THIyG.js} +2 -2
  43. package/src/assets/web-panel/assets/{Multisig-ByqP1ZzH.js → Multisig-DMzLB2hG.js} +3 -3
  44. package/src/assets/web-panel/assets/{NLProgramming-C_kn0nE2.js → NLProgramming-D9wZbf6l.js} +1 -1
  45. package/src/assets/web-panel/assets/{Notes-7l7eXHPq.js → Notes-hrFe2ZM-.js} +3 -3
  46. package/src/assets/web-panel/assets/{NotificationSettings-BrCDoitw.js → NotificationSettings-CHGX5Jwm.js} +1 -1
  47. package/src/assets/web-panel/assets/OrderTableRenderer-CRIFE2Tj.js +1 -0
  48. package/src/assets/web-panel/assets/{Organization-DdoNAxsM.js → Organization-By7FkhtY.js} +4 -4
  49. package/src/assets/web-panel/assets/{Overflow-Bw7R6dE3.js → Overflow--khGSzJn.js} +1 -1
  50. package/src/assets/web-panel/assets/{OverrideContext-C2r4vyBb.js → OverrideContext-BlgL9440.js} +1 -1
  51. package/src/assets/web-panel/assets/{P2P-DJNtBugA.js → P2P-CAG9dH35.js} +2 -2
  52. package/src/assets/web-panel/assets/{PdhVaultBrowser-Dwhd5_ue.js → PdhVaultBrowser-B3SQZmK9.js} +3 -3
  53. package/src/assets/web-panel/assets/{Permissions-BYoSfhPR.js → Permissions-D35ec6JA.js} +4 -4
  54. package/src/assets/web-panel/assets/{PersonalDataHub-aYCYJbnH.js → PersonalDataHub-CxBF7hW_.js} +2 -2
  55. package/src/assets/web-panel/assets/{Pipeline-DJp6CprF.js → Pipeline-s6EtOO1s.js} +1 -1
  56. package/src/assets/web-panel/assets/{Privacy-Cq9HZweR.js → Privacy-BbJYmWmO.js} +1 -1
  57. package/src/assets/web-panel/assets/{ProjectInit-CmF0HsSt.js → ProjectInit-VGQq1jMT.js} +2 -2
  58. package/src/assets/web-panel/assets/{ProjectSettings-P8V5Aea2.js → ProjectSettings-B1ew3Teh.js} +2 -2
  59. package/src/assets/web-panel/assets/Projects-CGcNIs_g.js +1 -0
  60. package/src/assets/web-panel/assets/{Providers-D589v0q2.js → Providers-mrO47FIK.js} +1 -1
  61. package/src/assets/web-panel/assets/QrScannerModal-IJF2mHyw.js +1 -0
  62. package/src/assets/web-panel/assets/{MobileBridge-zJpPuf4E.css → QrScannerModal-NwAHNfiJ.css} +1 -1
  63. package/src/assets/web-panel/assets/{QuickAsk-lvRV2osB.js → QuickAsk-CU0wN_Z0.js} +1 -1
  64. package/src/assets/web-panel/assets/{Recommend-sb84MTpY.js → Recommend-DhN37R6G.js} +1 -1
  65. package/src/assets/web-panel/assets/RemoteSession-D_xOX_hu.js +4 -0
  66. package/src/assets/web-panel/assets/{Reputation-d9Y3vy-W.js → Reputation-D_Ssv7uH.js} +1 -1
  67. package/src/assets/web-panel/assets/{Row-DMdhLUTp.js → Row-Kx5dKxX7.js} +1 -1
  68. package/src/assets/web-panel/assets/{RssFeed-OL-SMDkz.js → RssFeed-BlGwqZkY.js} +2 -2
  69. package/src/assets/web-panel/assets/{Search-BjStLKq1.js → Search-hLFQzxpb.js} +1 -1
  70. package/src/assets/web-panel/assets/{Security-MeI411qr.js → Security-DMlvsVt4.js} +2 -2
  71. package/src/assets/web-panel/assets/{Services-UajosuhT.js → Services-Bd0Qsj2m.js} +2 -2
  72. package/src/assets/web-panel/assets/{Skeleton-CGpG-QJ1.js → Skeleton-DFclq9X3.js} +1 -1
  73. package/src/assets/web-panel/assets/{Skills-C6P2RPY-.js → Skills-BNtln2qY.js} +1 -1
  74. package/src/assets/web-panel/assets/{Sla-B_fPprgw.js → Sla-Dch5H19G.js} +1 -1
  75. package/src/assets/web-panel/assets/{SpeechSettings-CqxLjSlQ.js → SpeechSettings-2UfQcU1g.js} +1 -1
  76. package/src/assets/web-panel/assets/{SyncSettings-DixSfFOQ.js → SyncSettings-CD9YQr4i.js} +2 -2
  77. package/src/assets/web-panel/assets/{Tasks-PavzPBxc.js → Tasks-BNu-7MzI.js} +1 -1
  78. package/src/assets/web-panel/assets/{Templates-BYdGRnfX.js → Templates-D1n9CaIR.js} +1 -1
  79. package/src/assets/web-panel/assets/{Tenant-BQLgnarD.js → Tenant-DenL3iBW.js} +1 -1
  80. package/src/assets/web-panel/assets/Terminal-ZzU0Io1Y.js +3 -0
  81. package/src/assets/web-panel/assets/{TimelineRenderer-Bv7uZRM7.js → TimelineRenderer-D87IfukO.js} +1 -1
  82. package/src/assets/web-panel/assets/{Tokens-DxhgszRJ.js → Tokens-BkiZc8E3.js} +1 -1
  83. package/src/assets/web-panel/assets/{Trigger-nQYHayuc.js → Trigger-BNRSytGN.js} +1 -1
  84. package/src/assets/web-panel/assets/{Trust-CvqZDuZ4.js → Trust-Bwbd4X2m.js} +1 -1
  85. package/src/assets/web-panel/assets/{UkeySign-DaR8GV2I.js → UkeySign-B8O2bs0o.js} +1 -1
  86. package/src/assets/web-panel/assets/{VideoEditing-C6Mpsokw.js → VideoEditing-C2fL8zmH.js} +1 -1
  87. package/src/assets/web-panel/assets/{Wallet-B57VRrWc.js → Wallet-BORYDdE1.js} +4 -4
  88. package/src/assets/web-panel/assets/{WebAuthn-BbtEEtpq.js → WebAuthn-C0V5S2FM.js} +4 -4
  89. package/src/assets/web-panel/assets/{WorkflowEditor-C5LwvKmH.js → WorkflowEditor-2dR0fcHL.js} +1 -1
  90. package/src/assets/web-panel/assets/{chat-MzuPR5jh.js → chat-BmuAFAn8.js} +1 -1
  91. package/src/assets/web-panel/assets/{collapseMotion-mxzzcDsg.js → collapseMotion-DVfhbsdP.js} +1 -1
  92. package/src/assets/web-panel/assets/{colors-HyW8mi_y.js → colors-CN3smMcK.js} +1 -1
  93. package/src/assets/web-panel/assets/{compact-item-DvUSzWAp.js → compact-item-DCnxb4kW.js} +1 -1
  94. package/src/assets/web-panel/assets/{createContext-4MppZl7X.js → createContext-vlR43pHn.js} +1 -1
  95. package/src/assets/web-panel/assets/devWarning-DxwmsL4j.js +1 -0
  96. package/src/assets/web-panel/assets/{echarts-jxgIOFUZ.js → echarts-CL0F2SnX.js} +1 -1
  97. package/src/assets/web-panel/assets/{hasIn-D9q3CJ-u.js → hasIn-D04tHYFd.js} +1 -1
  98. package/src/assets/web-panel/assets/{icons-DP3uiYxy.js → icons-BsDmGpcT.js} +1 -1
  99. package/src/assets/web-panel/assets/{index-C9I5MuJ0.js → index-0DnaZGkC.js} +1 -1
  100. package/src/assets/web-panel/assets/{index-Caqtu6Et.js → index-430S68MN.js} +1 -1
  101. package/src/assets/web-panel/assets/{index-eOQO6KnV.js → index-B78xL3s2.js} +1 -1
  102. package/src/assets/web-panel/assets/{index-Ci6adKh8.js → index-BTPEZTk1.js} +1 -1
  103. package/src/assets/web-panel/assets/{index-CifKUNtV.js → index-BXRg8GFQ.js} +1 -1
  104. package/src/assets/web-panel/assets/{index-D7TDMMfu.js → index-BasvsWDM.js} +1 -1
  105. package/src/assets/web-panel/assets/{index-DNYqw0MO.js → index-BeGDEXFs.js} +1 -1
  106. package/src/assets/web-panel/assets/{index-m0b6Fj9q.js → index-BqhASEL4.js} +1 -1
  107. package/src/assets/web-panel/assets/{index-BF2JsbiX.js → index-BudvKQfG.js} +1 -1
  108. package/src/assets/web-panel/assets/{index-DFqvWeGc.js → index-C-6NO5il.js} +1 -1
  109. package/src/assets/web-panel/assets/{index-SDblbKj6.js → index-C5Sxb1sE.js} +1 -1
  110. package/src/assets/web-panel/assets/{index-UUMCA2Sq.js → index-CP9m9Ggr.js} +4 -4
  111. package/src/assets/web-panel/assets/{index--Bm6OqmU.js → index-CTOCnIQ7.js} +1 -1
  112. package/src/assets/web-panel/assets/index-Cg2ldRfU.js +1 -0
  113. package/src/assets/web-panel/assets/{index-Dv7ffI2g.js → index-ClhAHDK3.js} +1 -1
  114. package/src/assets/web-panel/assets/{index-BcunsBIx.js → index-CnXebZLL.js} +1 -1
  115. package/src/assets/web-panel/assets/{index-CvAqCAo9.js → index-CngCC8hC.js} +1 -1
  116. package/src/assets/web-panel/assets/{index-DcMkjb92.js → index-Cr-A0FYJ.js} +1 -1
  117. package/src/assets/web-panel/assets/{index-BFGfC5RS.js → index-CsAsCPJ6.js} +1 -1
  118. package/src/assets/web-panel/assets/{index-DDZ6fP5Z.js → index-D28DeAAB.js} +1 -1
  119. package/src/assets/web-panel/assets/{index-CgIfXOD9.js → index-D5LZVZ0L.js} +1 -1
  120. package/src/assets/web-panel/assets/{index-DmZ6-suL.js → index-D65_XseV.js} +1 -1
  121. package/src/assets/web-panel/assets/{index-Cs-RKRUM.js → index-D8vwp4qp.js} +1 -1
  122. package/src/assets/web-panel/assets/{index-B994UQfE.js → index-DDwLgQY9.js} +1 -1
  123. package/src/assets/web-panel/assets/{index-Btz8pU68.js → index-DIpY0qM5.js} +1 -1
  124. package/src/assets/web-panel/assets/{index-B5E4DhVc.js → index-DTWg-18U.js} +1 -1
  125. package/src/assets/web-panel/assets/{index-D2jrnaq3.js → index-DTtRscUa.js} +1 -1
  126. package/src/assets/web-panel/assets/{index-BmCo2Xdp.js → index-DYAtmqiv.js} +1 -1
  127. package/src/assets/web-panel/assets/{index-Zvtru2oE.js → index-D_n8_vfI.js} +1 -1
  128. package/src/assets/web-panel/assets/{index-CLAZs1Vd.js → index-DbADHwhr.js} +1 -1
  129. package/src/assets/web-panel/assets/{index-CucRo4Vz.js → index-DbVsQBOH.js} +1 -1
  130. package/src/assets/web-panel/assets/index-Dwzo-dtJ.js +1 -0
  131. package/src/assets/web-panel/assets/{index-C0DiL97c.js → index-HhNjnCfe.js} +1 -1
  132. package/src/assets/web-panel/assets/{index-Bl-E4W4q.js → index-ToUh2b1-.js} +1 -1
  133. package/src/assets/web-panel/assets/{index-ryFLxB1p.js → index-TslMTwNy.js} +1 -1
  134. package/src/assets/web-panel/assets/{index-BGQtFso0.js → index-_FIkN3jd.js} +1 -1
  135. package/src/assets/web-panel/assets/{index-zLwYpvX0.js → index-hpvvtAZ3.js} +1 -1
  136. package/src/assets/web-panel/assets/{index-Dvg5xYuP.js → index-jzR7Ujuw.js} +1 -1
  137. package/src/assets/web-panel/assets/{index-xvUVuFnA.js → index-ljuBiQW9.js} +1 -1
  138. package/src/assets/web-panel/assets/{initDefaultProps-CC--PMsC.js → initDefaultProps-C3wUb4je.js} +1 -1
  139. package/src/assets/web-panel/assets/{motion-DdrBjRF1.js → motion-D-jYFUNA.js} +1 -1
  140. package/src/assets/web-panel/assets/{move-D712Gwl2.js → move-tqb8nwJ2.js} +1 -1
  141. package/src/assets/web-panel/assets/{mtc-parser-39y-keKO.js → mtc-parser-DSOjMJMz.js} +1 -1
  142. package/src/assets/web-panel/assets/{omit-6Y51gDB9.js → omit-CJ7VimIW.js} +1 -1
  143. package/src/assets/web-panel/assets/{pickAttrs-Cy6EHbq9.js → pickAttrs-qXiG1iT3.js} +1 -1
  144. package/src/assets/web-panel/assets/{placementArrow-BYxdAm0p.js → placementArrow-CkGBcy1Z.js} +1 -1
  145. package/src/assets/web-panel/assets/{responsiveObserve-C9R6q_cr.js → responsiveObserve-D3WvTlLO.js} +1 -1
  146. package/src/assets/web-panel/assets/{slide-CXUJlilB.js → slide-BEE2ftge.js} +1 -1
  147. package/src/assets/web-panel/assets/{statusUtils-DOtrOeql.js → statusUtils-CsfBpxiG.js} +1 -1
  148. package/src/assets/web-panel/assets/{styleChecker-D5r39o92.js → styleChecker-xPrIiJPI.js} +1 -1
  149. package/src/assets/web-panel/assets/useFlexGapSupport-C5Yd-SCR.js +1 -0
  150. package/src/assets/web-panel/assets/{useFs-BkrT-Zbc.js → useFs-D_MDS8HI.js} +1 -1
  151. package/src/assets/web-panel/assets/{useMergedState-Cl2q1fes.js → useMergedState-Dc9sO2d7.js} +1 -1
  152. package/src/assets/web-panel/assets/{usePersonalDataHub-BwnnnZjU.js → usePersonalDataHub-BqJh-usA.js} +1 -1
  153. package/src/assets/web-panel/assets/{useRefs-DD9q4mOT.js → useRefs-CAeFRzPf.js} +1 -1
  154. package/src/assets/web-panel/assets/{useState-BK4hy8Ma.js → useState-LwExUYDO.js} +1 -1
  155. package/src/assets/web-panel/assets/{vendor-BvqAck49.js → vendor-BMxUs6UX.js} +16 -16
  156. package/src/assets/web-panel/assets/{vnode-SU-N4pum.js → vnode-chm_p-gz.js} +1 -1
  157. package/src/assets/web-panel/assets/{zoom-DHScfpTP.js → zoom-3-YDNz0Z.js} +1 -1
  158. package/src/assets/web-panel/index.html +3 -3
  159. package/src/assets/web-panel/remote-session-sw.js +43 -0
  160. package/src/command-manifest.json +22 -1
  161. package/src/commands/agent.js +44 -5
  162. package/src/commands/codeintel.js +252 -0
  163. package/src/commands/eval.js +248 -0
  164. package/src/commands/plugin.js +354 -0
  165. package/src/commands/serve.js +10 -0
  166. package/src/commands/team.js +456 -0
  167. package/src/gateways/remote-session-relay.js +160 -0
  168. package/src/gateways/ws/message-dispatcher.js +77 -2
  169. package/src/gateways/ws/remote-session-protocol.js +466 -0
  170. package/src/gateways/ws/ws-server.js +299 -0
  171. package/src/harness/golden-transcript.js +65 -0
  172. package/src/harness/mcp-client.js +6 -2
  173. package/src/harness/prompt-compressor.js +27 -1
  174. package/src/harness/remote-command-ledger.js +158 -0
  175. package/src/harness/remote-session-audit-sink.js +132 -0
  176. package/src/harness/remote-session-audit.js +110 -0
  177. package/src/harness/remote-session-crypto.js +217 -0
  178. package/src/harness/remote-session-push-apns.js +246 -0
  179. package/src/harness/remote-session-push-errors.js +15 -0
  180. package/src/harness/remote-session-push-fcm.js +238 -0
  181. package/src/harness/remote-session-push-huawei.js +174 -0
  182. package/src/harness/remote-session-push-oppo.js +171 -0
  183. package/src/harness/remote-session-push-senders.js +42 -0
  184. package/src/harness/remote-session-push-vivo.js +179 -0
  185. package/src/harness/remote-session-push-web.js +299 -0
  186. package/src/harness/remote-session-push-xiaomi.js +99 -0
  187. package/src/harness/remote-session-push.js +104 -0
  188. package/src/harness/remote-session-registry.js +420 -0
  189. package/src/index.js +6 -0
  190. package/src/lib/agent-core.js +2 -0
  191. package/src/lib/agent-sandbox.js +161 -5
  192. package/src/lib/agent-team/task-lease.js +434 -0
  193. package/src/lib/agent-team/team-budget.js +165 -0
  194. package/src/lib/agent-team/team-mailbox.js +106 -0
  195. package/src/lib/agent-team/team-runner.js +266 -0
  196. package/src/lib/agent-team/team-worktree.js +204 -0
  197. package/src/lib/agents.js +18 -0
  198. package/src/lib/async-hook-supervisor.cjs +305 -0
  199. package/src/lib/did-manager.js +6 -4
  200. package/src/lib/eval/runner.js +163 -0
  201. package/src/lib/eval/tasks.js +456 -0
  202. package/src/lib/eval/trend.js +185 -0
  203. package/src/lib/lsp/__tests__/code-intelligence.integration.test.js +129 -0
  204. package/src/lib/lsp/__tests__/code-intelligence.test.js +228 -0
  205. package/src/lib/lsp/__tests__/jsonrpc-stream.test.js +104 -0
  206. package/src/lib/lsp/__tests__/lsp-client.test.js +258 -0
  207. package/src/lib/lsp/__tests__/lsp-manager.test.js +264 -0
  208. package/src/lib/lsp/__tests__/lsp-server-registry.test.js +128 -0
  209. package/src/lib/lsp/code-intelligence.js +356 -0
  210. package/src/lib/lsp/jsonrpc-stream.js +139 -0
  211. package/src/lib/lsp/lsp-client.js +318 -0
  212. package/src/lib/lsp/lsp-manager.js +323 -0
  213. package/src/lib/lsp/lsp-server-registry.js +196 -0
  214. package/src/lib/mcp-oauth.js +23 -6
  215. package/src/lib/plugin-monitor-supervisor.js +238 -0
  216. package/src/lib/plugin-runtime/agents.js +51 -0
  217. package/src/lib/plugin-runtime/bin.js +100 -0
  218. package/src/lib/plugin-runtime/hooks.js +100 -0
  219. package/src/lib/plugin-runtime/install.js +388 -0
  220. package/src/lib/plugin-runtime/lsp.js +75 -0
  221. package/src/lib/plugin-runtime/manifest.js +458 -0
  222. package/src/lib/plugin-runtime/mcp.js +89 -0
  223. package/src/lib/plugin-runtime/monitors.js +100 -0
  224. package/src/lib/plugin-runtime/policy.js +144 -0
  225. package/src/lib/plugin-runtime/reload.js +79 -0
  226. package/src/lib/plugin-runtime/scopes.js +197 -0
  227. package/src/lib/plugin-runtime/settings.js +119 -0
  228. package/src/lib/plugin-runtime/signature.js +107 -0
  229. package/src/lib/plugin-runtime/skills.js +43 -0
  230. package/src/lib/plugin-runtime/trust.js +140 -0
  231. package/src/lib/sandbox-egress-proxy.js +162 -0
  232. package/src/lib/sandbox-network-policy.js +134 -0
  233. package/src/lib/sandbox-v2.js +10 -4
  234. package/src/lib/session-manager.js +7 -3
  235. package/src/lib/settings-hook-events.cjs +78 -6
  236. package/src/lib/settings-hooks.cjs +29 -3
  237. package/src/lib/settings-loader.cjs +35 -1
  238. package/src/lib/skill-loader.js +18 -0
  239. package/src/lib/telemetry/span-recorder.js +237 -0
  240. package/src/repl/agent-repl.js +400 -4
  241. package/src/runtime/agent-core.js +546 -52
  242. package/src/runtime/agent-runtime.js +8 -13
  243. package/src/runtime/coding-agent-contract-shared.cjs +82 -8
  244. package/src/runtime/coding-agent-policy.cjs +32 -7
  245. package/src/runtime/fallback-model.js +134 -7
  246. package/src/runtime/headless-runner.js +353 -108
  247. package/src/runtime/mcp-config.js +46 -0
  248. package/src/runtime/policies/agent-policy.js +2 -0
  249. package/src/assets/web-panel/assets/Compliance-T8EtTecW.js +0 -1
  250. package/src/assets/web-panel/assets/MobileBridge-CYaITZ7w.js +0 -1
  251. package/src/assets/web-panel/assets/OrderTableRenderer-CmtqIdwr.js +0 -1
  252. package/src/assets/web-panel/assets/Projects-DPd5-lNS.js +0 -1
  253. package/src/assets/web-panel/assets/Terminal-BzOHpq-B.js +0 -3
  254. package/src/assets/web-panel/assets/devWarning-6YJJMjSH.js +0 -1
  255. package/src/assets/web-panel/assets/index-D_oeGLr6.js +0 -1
  256. package/src/assets/web-panel/assets/index-Qa57YG19.js +0 -1
  257. package/src/assets/web-panel/assets/useFlexGapSupport-DfAD5U4Z.js +0 -1
@@ -0,0 +1,456 @@
1
+ /**
2
+ * `cc team` — run a declared task graph across N cooperating teammates with
3
+ * exclusive leases + dependency ordering (Phase 4, Agent Team).
4
+ *
5
+ * A task file is JSON:
6
+ * { "tasks": [ { "key": "build", "title": "...", "dependsOn": [],
7
+ * "command": "npm run build" | "prompt": "fix the bug in x" } ] }
8
+ *
9
+ * cc team plan --tasks graph.json # topological wave preview (no run)
10
+ * cc team run --tasks graph.json # dry-run: validate + schedule, no exec
11
+ * cc team run --tasks graph.json --exec # run each task's shell `command`
12
+ * cc team run --tasks graph.json --agent# hand each task's `prompt` to cc agent
13
+ *
14
+ * The lease/DAG guarantees (no double-processing, deps-before-dependents, crash
15
+ * reclaim) come from TaskLeaseRegistry; TeamRunner drives the N teammates.
16
+ */
17
+
18
+ import fs from "fs";
19
+ import path from "path";
20
+ import { fileURLToPath } from "url";
21
+ import { spawn } from "child_process";
22
+ import { TaskLeaseRegistry } from "../lib/agent-team/task-lease.js";
23
+ import { TeamRunner } from "../lib/agent-team/team-runner.js";
24
+ import { TeamWorktreeCoordinator } from "../lib/agent-team/team-worktree.js";
25
+ import { TeamBudget } from "../lib/agent-team/team-budget.js";
26
+ import { TeamMailbox } from "../lib/agent-team/team-mailbox.js";
27
+
28
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
29
+ const BIN = path.resolve(__dirname, "..", "..", "bin", "chainlesschain.js");
30
+
31
+ /** Load + validate a task-graph file into a registry (throws on bad input). */
32
+ function loadRegistry(file, { ttlMs } = {}) {
33
+ const abs = path.resolve(process.cwd(), file);
34
+ let doc;
35
+ try {
36
+ doc = JSON.parse(fs.readFileSync(abs, "utf8"));
37
+ } catch (err) {
38
+ throw new Error(`cannot read task file ${abs}: ${err.message}`);
39
+ }
40
+ const tasks = Array.isArray(doc) ? doc : doc.tasks;
41
+ if (!Array.isArray(tasks) || tasks.length === 0) {
42
+ throw new Error("task file must have a non-empty `tasks` array");
43
+ }
44
+ const reg = new TaskLeaseRegistry({ defaultTtlMs: ttlMs });
45
+ for (const t of tasks) {
46
+ const r = reg.addTask({
47
+ key: t.key,
48
+ title: t.title || t.key,
49
+ dependsOn: t.dependsOn || t.deps || [],
50
+ priority: t.priority,
51
+ metadata: { command: t.command || null, prompt: t.prompt || null },
52
+ });
53
+ if (!r.ok) {
54
+ throw new Error(
55
+ `task "${t.key || "(unnamed)"}" rejected: ${r.reason}` +
56
+ (r.cycle ? ` [${r.cycle.join(" → ")}]` : ""),
57
+ );
58
+ }
59
+ }
60
+ return reg;
61
+ }
62
+
63
+ /** Topological wave schedule (each wave = tasks whose deps are all in prior waves). */
64
+ function planWaves(reg) {
65
+ const done = new Set();
66
+ const waves = [];
67
+ const all = reg.list();
68
+ let remaining = all.map((t) => t.key);
69
+ let guard = all.length + 1;
70
+ while (remaining.length > 0 && guard-- > 0) {
71
+ const wave = remaining.filter((k) => {
72
+ const t = reg.getTask(k);
73
+ return t.dependsOn.every((d) => done.has(d));
74
+ });
75
+ if (wave.length === 0) break; // unreachable if the graph is a DAG
76
+ waves.push(wave);
77
+ wave.forEach((k) => done.add(k));
78
+ remaining = remaining.filter((k) => !wave.includes(k));
79
+ }
80
+ return waves;
81
+ }
82
+
83
+ /** Real executor: run a task's shell `command`, success = exit 0. */
84
+ function makeShellRunTask(logger) {
85
+ return function runTask({ task }) {
86
+ const command = task.metadata?.command || task?.command;
87
+ if (!command) {
88
+ throw new Error(`task "${task.key}" has no \`command\` to --exec`);
89
+ }
90
+ return new Promise((resolve, reject) => {
91
+ const child = spawn(command, {
92
+ cwd: process.cwd(),
93
+ shell: true,
94
+ env: process.env,
95
+ });
96
+ let err = "";
97
+ child.stderr?.on("data", (d) => (err += d.toString("utf8")));
98
+ child.on("error", (e) => reject(new Error(e.message)));
99
+ child.on("close", (code) => {
100
+ if (code === 0) resolve({ code });
101
+ else reject(new Error(err.trim() || `command exited ${code}`));
102
+ });
103
+ });
104
+ };
105
+ }
106
+
107
+ /** Spawn a headless `cc agent -p` for one prompt in `cwd`; resolve on exit 0. */
108
+ function spawnAgent(prompt, cwd, opts = {}) {
109
+ return new Promise((resolve, reject) => {
110
+ const args = [
111
+ BIN,
112
+ "agent",
113
+ "-p",
114
+ prompt,
115
+ "--permission-mode",
116
+ opts.permissionMode || "acceptEdits",
117
+ "--output-format",
118
+ "text",
119
+ ];
120
+ if (opts.model) args.push("--model", opts.model);
121
+ const child = spawn(process.execPath, args, {
122
+ cwd,
123
+ env: { ...process.env, CLAUDECODE: "1" },
124
+ windowsHide: true,
125
+ });
126
+ let err = "";
127
+ child.stderr?.on("data", (d) => (err += d.toString("utf8")));
128
+ child.on("error", (e) => reject(new Error(e.message)));
129
+ child.on("close", (code) =>
130
+ code === 0
131
+ ? resolve({ code })
132
+ : reject(new Error(err.trim() || `agent exited ${code}`)),
133
+ );
134
+ });
135
+ }
136
+
137
+ /** Real executor: hand a task's `prompt` to a headless `cc agent -p` in cwd. */
138
+ function makeAgentRunTask(opts = {}) {
139
+ return function runTask({ task }) {
140
+ const prompt = task.metadata?.prompt || task?.prompt;
141
+ if (!prompt) {
142
+ throw new Error(`task "${task.key}" has no \`prompt\` to --agent`);
143
+ }
144
+ return spawnAgent(prompt, process.cwd(), opts);
145
+ };
146
+ }
147
+
148
+ export function registerTeamCommand(program, { logger } = {}) {
149
+ const log = logger || console;
150
+ const team = program
151
+ .command("team")
152
+ .description(
153
+ "Run a declared task graph across N teammates (exclusive leases + dependency DAG)",
154
+ );
155
+
156
+ team
157
+ .command("plan")
158
+ .description("Show the topological wave schedule for a task graph (no run)")
159
+ .requiredOption("--tasks <file>", "Task-graph JSON file")
160
+ .option("--json", "Output the plan as JSON")
161
+ .action((options) => {
162
+ let reg;
163
+ try {
164
+ reg = loadRegistry(options.tasks);
165
+ } catch (err) {
166
+ (log.error || console.error)(err.message);
167
+ process.exitCode = 1;
168
+ return;
169
+ }
170
+ const waves = planWaves(reg);
171
+ if (options.json) {
172
+ console.log(
173
+ JSON.stringify({ waves, total: reg.list().length }, null, 2),
174
+ );
175
+ return;
176
+ }
177
+ (log.log || console.log)(
178
+ `Task graph: ${reg.list().length} task(s), ${waves.length} wave(s)`,
179
+ );
180
+ waves.forEach((w, i) => {
181
+ (log.log || console.log)(` wave ${i + 1}: ${w.join(", ")}`);
182
+ });
183
+ });
184
+
185
+ team
186
+ .command("run")
187
+ .description("Run a task graph with N cooperating teammates")
188
+ .requiredOption("--tasks <file>", "Task-graph JSON file")
189
+ .option("--teammates <n>", "Number of concurrent teammates", "2")
190
+ .option("--ttl <seconds>", "Lease TTL per task", "60")
191
+ .option("--exec", "Execute each task's shell `command` (real)")
192
+ .option(
193
+ "--agent",
194
+ "Hand each task's `prompt` to a headless cc agent (real)",
195
+ )
196
+ .option("--model <model>", "Model for --agent runs")
197
+ .option(
198
+ "--worktree",
199
+ "Run each task's `command` in its own git worktree (parallel isolation)",
200
+ )
201
+ .option(
202
+ "--merge",
203
+ "With --worktree: merge each clean branch back to base (conflicts reported, not forced)",
204
+ )
205
+ .option("--max-tasks <n>", "Budget: total task executions across the team")
206
+ .option("--max-tokens <n>", "Budget: total LLM tokens across the team")
207
+ .option(
208
+ "--max-usd <n>",
209
+ "Budget: total estimated USD spend across the team",
210
+ )
211
+ .option(
212
+ "--max-wall <seconds>",
213
+ "Budget: wall-clock seconds for the whole run",
214
+ )
215
+ .option(
216
+ "--state <file>",
217
+ "Persist team progress to a file (for --resume after a crash)",
218
+ )
219
+ .option(
220
+ "--resume",
221
+ "Restore progress from --state (completed tasks stay done; stale leases freed)",
222
+ )
223
+ .option("--json", "Emit the event stream as JSON lines")
224
+ .action(async (options) => {
225
+ const ttlMs = Math.max(1, Number(options.ttl) || 60) * 1000;
226
+ let reg;
227
+ let mailbox = new TeamMailbox();
228
+ let budget = new TeamBudget({
229
+ maxTasks: options.maxTasks,
230
+ maxTokens: options.maxTokens,
231
+ maxUsd: options.maxUsd,
232
+ maxWallMs: options.maxWall
233
+ ? Math.max(1, Number(options.maxWall)) * 1000
234
+ : null,
235
+ });
236
+ let priorMembers = [];
237
+ try {
238
+ // Resume from a prior (possibly crashed) run's state: completed tasks
239
+ // stay COMPLETED, and any lease left dangling by a crash is reclaimed so
240
+ // its task is re-run — the team-session-recovery acceptance path. The
241
+ // mailbox + budget are restored too so messages/spend stay consistent.
242
+ if (options.resume && options.state && fs.existsSync(options.state)) {
243
+ const snap = JSON.parse(fs.readFileSync(options.state, "utf8"));
244
+ const isV2 = snap && snap.version >= 2 && snap.registry;
245
+ reg = TaskLeaseRegistry.restore(isV2 ? snap.registry : snap);
246
+ if (isV2) {
247
+ if (snap.mailbox) mailbox = TeamMailbox.restore(snap.mailbox);
248
+ if (snap.budget)
249
+ budget = TeamBudget.restore(snap.budget, {
250
+ // CLI flags on the resume invocation override the prior caps;
251
+ // omitted flags keep them (never silently drop a safety cap).
252
+ overrides: {
253
+ maxTasks: options.maxTasks,
254
+ maxTokens: options.maxTokens,
255
+ maxUsd: options.maxUsd,
256
+ maxWallMs: options.maxWall
257
+ ? Math.max(1, Number(options.maxWall)) * 1000
258
+ : undefined,
259
+ },
260
+ });
261
+ priorMembers = Array.isArray(snap.members) ? snap.members : [];
262
+ }
263
+ // A teammate whose lease is still dangling here crashed last run — its
264
+ // task is about to be reclaimed, so report it LOST before the sweep.
265
+ const lostHolders = new Set();
266
+ for (const t of reg.list()) {
267
+ if (t.lease && t.lease.holder) lostHolders.add(t.lease.holder);
268
+ }
269
+ const freed = reg.reclaimExpired();
270
+ for (const h of lostHolders) {
271
+ if (options.json)
272
+ console.log(JSON.stringify({ type: "teammate:lost", holder: h }));
273
+ else (log.info || console.log)(` ⚠ teammate ${h} lost (crashed)`);
274
+ }
275
+ const s = reg.stats();
276
+ (log.info || console.log)(
277
+ `Resumed: ${s.completed}/${s.total} already done` +
278
+ (freed.length
279
+ ? `, ${freed.length} stale lease(s) reclaimed`
280
+ : ""),
281
+ );
282
+ } else {
283
+ reg = loadRegistry(options.tasks, { ttlMs });
284
+ }
285
+ } catch (err) {
286
+ (log.error || console.error)(err.message);
287
+ process.exitCode = 1;
288
+ return;
289
+ }
290
+
291
+ // Persist a snapshot after each task settles so a crash mid-run is
292
+ // resumable (persist-after-run alone would lose everything on a crash).
293
+ // v2 bundles registry + mailbox + budget + member lifecycle so a resume
294
+ // keeps the whole team state consistent, not just the task graph.
295
+ let runnerRef = null;
296
+ const persist = () => {
297
+ if (!options.state) return;
298
+ try {
299
+ fs.writeFileSync(
300
+ options.state,
301
+ JSON.stringify(
302
+ {
303
+ version: 2,
304
+ registry: reg.snapshot(),
305
+ mailbox: mailbox.snapshot(),
306
+ budget: budget.snapshot(),
307
+ members: runnerRef ? runnerRef.members() : priorMembers,
308
+ },
309
+ null,
310
+ 2,
311
+ ),
312
+ "utf8",
313
+ );
314
+ } catch (e) {
315
+ (log.error || console.error)(` state write failed: ${e.message}`);
316
+ }
317
+ };
318
+
319
+ // Pick the executor. Default is a dry-run (validate + schedule, no side
320
+ // effects) so `cc team run` is safe to explore, mirroring `cc eval --dry-run`.
321
+ let runTask;
322
+ let coord = null;
323
+ if (options.worktree) {
324
+ coord = new TeamWorktreeCoordinator(process.cwd());
325
+ if (!coord.isGitRepo()) {
326
+ (log.error || console.error)(
327
+ "--worktree requires a git repository (run inside one)",
328
+ );
329
+ process.exitCode = 1;
330
+ return;
331
+ }
332
+ if (options.agent) {
333
+ // --agent --worktree: each teammate drives an agent turn (its `prompt`)
334
+ // inside its OWN git worktree, so parallel edits never fight over the
335
+ // working tree, then integrate/merge the branches like --exec --worktree.
336
+ runTask = coord.makeRunTask({
337
+ runInWorktree: async ({ key, task, cwd }) => {
338
+ const prompt = task.metadata?.prompt || task?.prompt;
339
+ if (!prompt) {
340
+ throw new Error(`task "${key}" has no \`prompt\` to --agent`);
341
+ }
342
+ await spawnAgent(prompt, cwd, { model: options.model });
343
+ },
344
+ });
345
+ } else {
346
+ runTask = coord.makeRunTask();
347
+ }
348
+ } else if (options.exec) runTask = makeShellRunTask(log);
349
+ else if (options.agent)
350
+ runTask = makeAgentRunTask({ model: options.model });
351
+ else runTask = async () => ({ dryRun: true });
352
+
353
+ const teammates = Math.max(1, Number(options.teammates) || 2);
354
+ const runner = new TeamRunner(reg, {
355
+ teammates,
356
+ ttlMs,
357
+ runTask,
358
+ budget,
359
+ mailbox,
360
+ onEvent: (e) => {
361
+ if (options.json) console.log(JSON.stringify(e));
362
+ else if (e.type === "task:claimed")
363
+ (log.info || console.log)(` → ${e.key} [${e.holder}]`);
364
+ else if (e.type === "task:completed")
365
+ (log.info || console.log)(` ✔ ${e.key}`);
366
+ else if (e.type === "task:failed")
367
+ (log.info || console.log)(
368
+ ` ✗ ${e.key}${e.retry ? " (will retry)" : " (gave up)"}: ${e.error}`,
369
+ );
370
+ else if (e.type === "run:budget-exhausted")
371
+ (log.info || console.log)(
372
+ ` ⛔ budget reached (${e.reason || `max-tasks ${e.maxTasks}`}) — no new tasks claimed`,
373
+ );
374
+ if (e.type === "task:completed" || e.type === "task:failed")
375
+ persist();
376
+ },
377
+ });
378
+ runner.seedMembers(priorMembers);
379
+ runnerRef = runner;
380
+
381
+ const summary = await runner.run();
382
+ persist();
383
+
384
+ // Worktree integration: sequentially preview (and optionally merge) each
385
+ // committed branch back to base, then remove the worktrees. Conflicts are
386
+ // reported, never force-merged.
387
+ let integration = null;
388
+ if (coord) {
389
+ integration = coord.integrate({ merge: options.merge === true });
390
+ coord.cleanupAll();
391
+ if (!options.json) {
392
+ (log.log || console.log)("\nWorktree integration:");
393
+ for (const r of integration) {
394
+ if (!r.committed)
395
+ (log.info || console.log)(` · ${r.key}: no changes`);
396
+ else if (r.error)
397
+ (log.info || console.log)(
398
+ ` ✗ ${r.key} [${r.branch}]: ${r.error}`,
399
+ );
400
+ else if (!r.clean)
401
+ (log.info || console.log)(
402
+ ` ⚠ ${r.key} [${r.branch}]: conflicts in ${r.conflicts.length} file(s) — not merged`,
403
+ );
404
+ else
405
+ (log.info || console.log)(
406
+ ` ${r.merged ? "✔ merged" : "✔ clean"} ${r.key} [${r.branch}]`,
407
+ );
408
+ }
409
+ }
410
+ }
411
+
412
+ if (options.json && integration)
413
+ console.log(JSON.stringify({ integration }));
414
+ if (!options.json) {
415
+ const s = summary.stats;
416
+ (log.log || console.log)(
417
+ `\nTeam run: ${s.completed}/${s.total} completed` +
418
+ (s.cancelled ? `, ${s.cancelled} cancelled` : "") +
419
+ ` (${teammates} teammates, ${summary.executions} executions, peak ${summary.maxConcurrent} concurrent)`,
420
+ );
421
+ if (budget.enabled()) {
422
+ const b = budget.status();
423
+ const parts = [`${b.tasks} task(s)`, `${b.tokens} token(s)`];
424
+ if (b.maxUsd != null) parts.push(`$${b.spentUsd.toFixed(4)}`);
425
+ (log.log || console.log)(
426
+ `Budget: ${parts.join(", ")}` +
427
+ (summary.budgetStopped
428
+ ? ` — stopped early (${summary.budgetReason})`
429
+ : ""),
430
+ );
431
+ }
432
+ if (mailbox.size() > 0)
433
+ (log.log || console.log)(
434
+ `Messages: ${mailbox.size()} exchanged between teammates`,
435
+ );
436
+ } else {
437
+ console.log(
438
+ JSON.stringify({
439
+ summary: {
440
+ done: summary.done,
441
+ executions: summary.executions,
442
+ budgetStopped: summary.budgetStopped,
443
+ budgetReason: summary.budgetReason,
444
+ budget: budget.status(),
445
+ members: summary.members,
446
+ messages: mailbox.size(),
447
+ },
448
+ }),
449
+ );
450
+ }
451
+ // Non-zero exit when the graph didn't fully complete — usable as a gate.
452
+ if (!summary.done) process.exitCode = 1;
453
+ });
454
+
455
+ return program;
456
+ }
@@ -0,0 +1,160 @@
1
+ import { EventEmitter } from "events";
2
+ import WebSocket from "ws";
3
+
4
+ export class RemoteSessionRelay extends EventEmitter {
5
+ constructor({
6
+ relayUrl,
7
+ peerId,
8
+ deviceType = "remote-session",
9
+ websocketFactory,
10
+ reconnectBaseMs = 500,
11
+ reconnectMaxMs = 30_000,
12
+ maxReconnectAttempts = Infinity,
13
+ queueLimit = 100,
14
+ setTimer = setTimeout,
15
+ clearTimer = clearTimeout,
16
+ } = {}) {
17
+ super();
18
+ if (!relayUrl || !peerId)
19
+ throw new Error("relayUrl and peerId are required");
20
+ this.relayUrl = relayUrl;
21
+ this.peerId = peerId;
22
+ this.deviceType = deviceType;
23
+ this.websocketFactory = websocketFactory || ((url) => new WebSocket(url));
24
+ this.ws = null;
25
+ this.reconnectBaseMs = reconnectBaseMs;
26
+ this.reconnectMaxMs = reconnectMaxMs;
27
+ this.maxReconnectAttempts = maxReconnectAttempts;
28
+ this.queueLimit = queueLimit;
29
+ this.setTimer = setTimer;
30
+ this.clearTimer = clearTimer;
31
+ this.reconnectAttempts = 0;
32
+ this.reconnectTimer = null;
33
+ this.outbox = [];
34
+ this.closedExplicitly = false;
35
+ this.connectPromise = null;
36
+ }
37
+
38
+ connect() {
39
+ if (this.ws && this.ws.readyState === this.ws.OPEN)
40
+ return Promise.resolve();
41
+ if (this.connectPromise) return this.connectPromise;
42
+ this.closedExplicitly = false;
43
+ this.connectPromise = new Promise((resolve, reject) => {
44
+ const ws = this.websocketFactory(this.relayUrl);
45
+ this.ws = ws;
46
+ const onOpen = () => {
47
+ this._send({
48
+ type: "register",
49
+ peerId: this.peerId,
50
+ deviceType: this.deviceType,
51
+ deviceInfo: { protocol: "remote-session.e2ee.v1" },
52
+ });
53
+ this.reconnectAttempts = 0;
54
+ this.connectPromise = null;
55
+ this._flushOutbox();
56
+ this.emit("connect");
57
+ resolve();
58
+ };
59
+ ws.once("open", onOpen);
60
+ ws.once("error", (error) => {
61
+ this.connectPromise = null;
62
+ reject(error);
63
+ });
64
+ ws.on("message", (raw) => this._handleMessage(raw));
65
+ ws.on("close", () => {
66
+ if (this.ws === ws) this.ws = null;
67
+ this.connectPromise = null;
68
+ this.emit("disconnect");
69
+ this._scheduleReconnect();
70
+ });
71
+ });
72
+ return this.connectPromise;
73
+ }
74
+
75
+ sendEncrypted(targetPeerId, envelope) {
76
+ const message = {
77
+ type: "message",
78
+ to: targetPeerId,
79
+ payload: { type: "remote-session.encrypted", envelope },
80
+ };
81
+ if (!this.ws || this.ws.readyState !== this.ws.OPEN) {
82
+ if (this.outbox.length >= this.queueLimit) this.outbox.shift();
83
+ this.outbox.push(message);
84
+ this.emit("queued", { size: this.outbox.length });
85
+ return false;
86
+ }
87
+ this._send(message);
88
+ return true;
89
+ }
90
+
91
+ close() {
92
+ this.closedExplicitly = true;
93
+ if (this.reconnectTimer) {
94
+ this.clearTimer(this.reconnectTimer);
95
+ this.reconnectTimer = null;
96
+ }
97
+ this.ws?.close();
98
+ this.ws = null;
99
+ }
100
+
101
+ _scheduleReconnect() {
102
+ if (
103
+ this.closedExplicitly ||
104
+ this.reconnectTimer ||
105
+ this.reconnectAttempts >= this.maxReconnectAttempts
106
+ ) {
107
+ return;
108
+ }
109
+ const delay = Math.min(
110
+ this.reconnectBaseMs * 2 ** this.reconnectAttempts,
111
+ this.reconnectMaxMs,
112
+ );
113
+ this.reconnectAttempts += 1;
114
+ this.emit("reconnecting", { attempt: this.reconnectAttempts, delay });
115
+ this.reconnectTimer = this.setTimer(() => {
116
+ this.reconnectTimer = null;
117
+ this.connect().catch((error) => {
118
+ this.emit("reconnect-error", error);
119
+ this._scheduleReconnect();
120
+ });
121
+ }, delay);
122
+ if (typeof this.reconnectTimer?.unref === "function")
123
+ this.reconnectTimer.unref();
124
+ }
125
+
126
+ _flushOutbox() {
127
+ const pending = this.outbox.splice(0);
128
+ for (const message of pending) this._send(message);
129
+ if (pending.length) this.emit("flushed", { count: pending.length });
130
+ }
131
+
132
+ _send(message) {
133
+ if (!this.ws || this.ws.readyState !== this.ws.OPEN) {
134
+ throw new Error("Remote Session relay is not connected");
135
+ }
136
+ this.ws.send(JSON.stringify(message));
137
+ }
138
+
139
+ _handleMessage(raw) {
140
+ let message;
141
+ try {
142
+ message = JSON.parse(raw.toString("utf8"));
143
+ } catch {
144
+ this.emit("protocol-error", new Error("Invalid signaling relay JSON"));
145
+ return;
146
+ }
147
+ if (message.type === "offline-message") message = message.originalMessage;
148
+ if (
149
+ message?.type === "message" &&
150
+ message.payload?.type === "remote-session.encrypted"
151
+ ) {
152
+ this.emit("encrypted-message", {
153
+ from: message.from,
154
+ envelope: message.payload.envelope,
155
+ });
156
+ return;
157
+ }
158
+ this.emit("relay-message", message);
159
+ }
160
+ }