chainlesschain 0.166.143 → 0.166.146

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 (235) hide show
  1. package/README.md +108 -10
  2. package/package.json +3 -3
  3. package/src/assets/linux-subreaper/linux-arm64/manifest.json +1 -1
  4. package/src/assets/linux-subreaper/linux-x64/manifest.json +1 -1
  5. package/src/assets/web-panel/.build-hash +1 -1
  6. package/src/assets/web-panel/assets/{AIOps-DNySV2Kf.js → AIOps-BjBY1txq.js} +1 -1
  7. package/src/assets/web-panel/assets/{ActionButton-ByFuxJsa.js → ActionButton-CS2ov4iK.js} +1 -1
  8. package/src/assets/web-panel/assets/{Analytics-ETbdywk5.js → Analytics-C9LS7ahG.js} +1 -1
  9. package/src/assets/web-panel/assets/{AppLayout-CuHekZaP.js → AppLayout-4_s9gBVg.js} +2 -2
  10. package/src/assets/web-panel/assets/{Artifacts-BJJq2BDq.js → Artifacts-CwS17ayg.js} +1 -1
  11. package/src/assets/web-panel/assets/{Audit-DXrietv8.js → Audit-D3QMRsd-.js} +1 -1
  12. package/src/assets/web-panel/assets/{BackgroundAgents-CFB1fxsr.js → BackgroundAgents-Bxau9H9Q.js} +1 -1
  13. package/src/assets/web-panel/assets/{Backup-VLtflRmp.js → Backup--YSJyAuP.js} +1 -1
  14. package/src/assets/web-panel/assets/{BaseInput-BbqBaS2r.js → BaseInput-DZolkmdu.js} +1 -1
  15. package/src/assets/web-panel/assets/{Chat-t0g7BXL8.js → Chat-DA-7fNKq.js} +1 -1
  16. package/src/assets/web-panel/assets/{ChatBubbleRenderer-JNFsjV0j.js → ChatBubbleRenderer-DniEWT5j.js} +1 -1
  17. package/src/assets/web-panel/assets/{Checkbox-BCSclHQb.js → Checkbox-B4hgbnOB.js} +1 -1
  18. package/src/assets/web-panel/assets/{Codegen-BcyINEHT.js → Codegen-BQ3HSq9S.js} +1 -1
  19. package/src/assets/web-panel/assets/{Col-C-0WNlwS.js → Col-DJwxq_Wu.js} +1 -1
  20. package/src/assets/web-panel/assets/{Community-DxZeoORX.js → Community-DZYVM_iz.js} +1 -1
  21. package/src/assets/web-panel/assets/{Compact-BNnX4jpz.js → Compact-1Yq5o53N.js} +1 -1
  22. package/src/assets/web-panel/assets/{Compliance-KnjHtn9C.js → Compliance-52Per8mR.js} +1 -1
  23. package/src/assets/web-panel/assets/{Cowork-CDyCrhbX.js → Cowork-BaCNxzo7.js} +1 -1
  24. package/src/assets/web-panel/assets/{Cron-DxpS3D1G.js → Cron-DADTMPPr.js} +1 -1
  25. package/src/assets/web-panel/assets/{Crosschain-BSzTZYyc.js → Crosschain-CS3rx96X.js} +1 -1
  26. package/src/assets/web-panel/assets/{DID-Bfj9Vdne.js → DID-B8eatIvd.js} +1 -1
  27. package/src/assets/web-panel/assets/{Dashboard-CcERVdgo.js → Dashboard-0vsurC1X.js} +2 -2
  28. package/src/assets/web-panel/assets/{Dropdown-BtYXAz6E.js → Dropdown-BULy3ccq.js} +1 -1
  29. package/src/assets/web-panel/assets/{EmailListRenderer-fdCMeGXU.js → EmailListRenderer-CcwgCUpu.js} +1 -1
  30. package/src/assets/web-panel/assets/{EvolutionSettings-LHxhcuF2.js → EvolutionSettings-DLs_6II3.js} +1 -1
  31. package/src/assets/web-panel/assets/{FamilyGuardDashboard-MIgtLsos.js → FamilyGuardDashboard-DpUpWwQP.js} +1 -1
  32. package/src/assets/web-panel/assets/{Federation-9-TOztwa.js → Federation-6hx8MMYA.js} +1 -1
  33. package/src/assets/web-panel/assets/{FormItemContext-BKcwEE6w.js → FormItemContext-CsdE-ZR5.js} +1 -1
  34. package/src/assets/web-panel/assets/{GenericCardRenderer-DJBPVUK2.js → GenericCardRenderer-DzXneQPV.js} +1 -1
  35. package/src/assets/web-panel/assets/{Git-C_XYISjG.js → Git-D_ThKL1Q.js} +1 -1
  36. package/src/assets/web-panel/assets/{Governance-DWsbPrwq.js → Governance-BFBSlr-9.js} +1 -1
  37. package/src/assets/web-panel/assets/{Inference-D0_bYket.js → Inference-BAI0b1Jl.js} +1 -1
  38. package/src/assets/web-panel/assets/{KnowledgeGraph-BoA3VQlw.js → KnowledgeGraph-CpO6Bdtr.js} +1 -1
  39. package/src/assets/web-panel/assets/{Logs-LEGItChf.js → Logs-BcRaS_HC.js} +1 -1
  40. package/src/assets/web-panel/assets/{MarkdownRenderer-DOHVc-Uw.js → MarkdownRenderer-CmZaA7Ct.js} +1 -1
  41. package/src/assets/web-panel/assets/{Marketplace-BKovl9NH.js → Marketplace-BpHBn0Nw.js} +1 -1
  42. package/src/assets/web-panel/assets/{McpTools-D61ktoGb.js → McpTools-auVxEYSE.js} +1 -1
  43. package/src/assets/web-panel/assets/{Memory-CllorS0l.js → Memory-DpCyb656.js} +1 -1
  44. package/src/assets/web-panel/assets/{MobileBridge-D-dJ78bk.js → MobileBridge-CEIGi769.js} +1 -1
  45. package/src/assets/web-panel/assets/{MobileProjects-CaxMKkd3.js → MobileProjects-pphH0a8n.js} +1 -1
  46. package/src/assets/web-panel/assets/{Mtc-qEc62Qsx.js → Mtc-CMJXBEp1.js} +1 -1
  47. package/src/assets/web-panel/assets/{MtcAudit-BY68jOZJ.js → MtcAudit-BI25yvzM.js} +1 -1
  48. package/src/assets/web-panel/assets/{Multisig-eCCR8ELt.js → Multisig-BhMDExsQ.js} +1 -1
  49. package/src/assets/web-panel/assets/{NLProgramming-VtGv8pky.js → NLProgramming-CatOR9Ez.js} +1 -1
  50. package/src/assets/web-panel/assets/{Notes-CPkYQySe.js → Notes-BHG6SBpu.js} +1 -1
  51. package/src/assets/web-panel/assets/{NotificationSettings-BuAvlHUu.js → NotificationSettings-BB-m0AbL.js} +1 -1
  52. package/src/assets/web-panel/assets/{OrderTableRenderer-CLf_HAGv.js → OrderTableRenderer-W-WReAih.js} +1 -1
  53. package/src/assets/web-panel/assets/{Organization-DjujhMbD.js → Organization-BkQCgon_.js} +1 -1
  54. package/src/assets/web-panel/assets/{Overflow-RznznTS4.js → Overflow-kCTwPrIc.js} +1 -1
  55. package/src/assets/web-panel/assets/{P2P-DSa5ot0t.js → P2P-CvOF8whc.js} +1 -1
  56. package/src/assets/web-panel/assets/{PdhVaultBrowser-oSEh6vkf.js → PdhVaultBrowser-DYkTzn6u.js} +2 -2
  57. package/src/assets/web-panel/assets/{Permissions-CdOZguX9.js → Permissions-F-UzeWVt.js} +1 -1
  58. package/src/assets/web-panel/assets/{PersonalDataHub-B4--6iEF.js → PersonalDataHub-BURpZBb6.js} +1 -1
  59. package/src/assets/web-panel/assets/{Pipeline-BnI57jE8.js → Pipeline-lZYx_7qc.js} +1 -1
  60. package/src/assets/web-panel/assets/{Privacy-C8MId3ad.js → Privacy-DdfYgt1_.js} +1 -1
  61. package/src/assets/web-panel/assets/{ProjectInit-DPGyYO8a.js → ProjectInit-DbMBCojn.js} +1 -1
  62. package/src/assets/web-panel/assets/{ProjectSettings-qBMqaJaO.js → ProjectSettings-DPGbzkyi.js} +1 -1
  63. package/src/assets/web-panel/assets/{Projects-Bq87Syce.js → Projects-B9-t2ofM.js} +1 -1
  64. package/src/assets/web-panel/assets/{Providers-CVuG9Ugf.js → Providers-q9dSBLsP.js} +1 -1
  65. package/src/assets/web-panel/assets/{QrScannerModal-C94c8m3q.js → QrScannerModal-BIth1Lij.js} +1 -1
  66. package/src/assets/web-panel/assets/{QuickAsk-BvfsXZ8s.js → QuickAsk-C928WbdK.js} +1 -1
  67. package/src/assets/web-panel/assets/{Recommend-CoezBYH9.js → Recommend-CzDNsNPZ.js} +1 -1
  68. package/src/assets/web-panel/assets/{RemoteSession-CcYC4v3u.js → RemoteSession-CedjOslI.js} +1 -1
  69. package/src/assets/web-panel/assets/{Reputation-diDbL4cO.js → Reputation-B8ggKVtj.js} +1 -1
  70. package/src/assets/web-panel/assets/{Row-5qp3_fNS.js → Row-Cx167nF6.js} +1 -1
  71. package/src/assets/web-panel/assets/{RssFeed-BCsMvpV4.js → RssFeed-Cj8hwiLP.js} +1 -1
  72. package/src/assets/web-panel/assets/{Search-Br9nVxOp.js → Search-Dsyrkogu.js} +1 -1
  73. package/src/assets/web-panel/assets/{Security-BdOUzRfA.js → Security-DfOcWFt-.js} +1 -1
  74. package/src/assets/web-panel/assets/{Services-Cp9TqzyN.js → Services-CSyv-JgS.js} +1 -1
  75. package/src/assets/web-panel/assets/{Skeleton-DSdWsUMR.js → Skeleton-B0chhFP5.js} +1 -1
  76. package/src/assets/web-panel/assets/{Skills-DRczAMTe.js → Skills-B_jrR_AF.js} +1 -1
  77. package/src/assets/web-panel/assets/{Sla-B6G_Vd8N.js → Sla-krP10aUI.js} +1 -1
  78. package/src/assets/web-panel/assets/{SpeechSettings-BCcLx5x4.js → SpeechSettings-Cm_Cjvf2.js} +1 -1
  79. package/src/assets/web-panel/assets/{SyncSettings-BFhwtxCp.js → SyncSettings-Cmb-KoqG.js} +1 -1
  80. package/src/assets/web-panel/assets/{Tasks-DGRE6VHO.js → Tasks-DUOiwTxY.js} +1 -1
  81. package/src/assets/web-panel/assets/{Templates-CJkJRFzd.js → Templates-DcEPspsP.js} +1 -1
  82. package/src/assets/web-panel/assets/{Tenant-CAOv6p00.js → Tenant-Dw93LtrE.js} +1 -1
  83. package/src/assets/web-panel/assets/{Terminal-CDrwwrKj.js → Terminal-B04i0AIG.js} +1 -1
  84. package/src/assets/web-panel/assets/{TimelineRenderer-DI0YE2SN.js → TimelineRenderer-C-aAORNK.js} +1 -1
  85. package/src/assets/web-panel/assets/{Tokens-DmqWTZSG.js → Tokens-W1RBfDKb.js} +1 -1
  86. package/src/assets/web-panel/assets/{Trigger-CkXkhmjk.js → Trigger-BuuH9sMn.js} +1 -1
  87. package/src/assets/web-panel/assets/{Trust-U8YJLcoJ.js → Trust-Bma-Vz-f.js} +1 -1
  88. package/src/assets/web-panel/assets/{UkeySign-BLTozMmr.js → UkeySign-CqWw3_ha.js} +1 -1
  89. package/src/assets/web-panel/assets/{VideoEditing-DHKyFlZa.js → VideoEditing-6NYmQRUe.js} +1 -1
  90. package/src/assets/web-panel/assets/{Wallet-DapBxIQt.js → Wallet-CTUuBxsr.js} +1 -1
  91. package/src/assets/web-panel/assets/{WebAuthn-CkvG3yOr.js → WebAuthn-D8mN5UQU.js} +1 -1
  92. package/src/assets/web-panel/assets/{WorkflowEditor-cNLsinXP.js → WorkflowEditor-DOB46XMH.js} +1 -1
  93. package/src/assets/web-panel/assets/{chat-BzgkgfMC.js → chat-BPNlNLwi.js} +1 -1
  94. package/src/assets/web-panel/assets/{colors-BPpVKQsb.js → colors-D-LNng0Q.js} +1 -1
  95. package/src/assets/web-panel/assets/{compact-item-zepznuTv.js → compact-item-Vkl3KOAb.js} +1 -1
  96. package/src/assets/web-panel/assets/{createContext-BRto-SQH.js → createContext-CFsJ9Bmp.js} +1 -1
  97. package/src/assets/web-panel/assets/{hasIn-CqsmU_n6.js → hasIn-C1v7eiIB.js} +1 -1
  98. package/src/assets/web-panel/assets/{index-DKa_jSfj.js → index-0oRhV07J.js} +1 -1
  99. package/src/assets/web-panel/assets/{index-wbvZayBb.js → index-5oK4ICcR.js} +1 -1
  100. package/src/assets/web-panel/assets/{index-CwkhrUmw.js → index-9JeeBF92.js} +1 -1
  101. package/src/assets/web-panel/assets/{index-B0Z6rfV-.js → index-BGyhWFpc.js} +1 -1
  102. package/src/assets/web-panel/assets/{index-DUclk35X.js → index-BH5PxoVq.js} +1 -1
  103. package/src/assets/web-panel/assets/{index-Z6DBe2RU.js → index-BMcTUbpz.js} +1 -1
  104. package/src/assets/web-panel/assets/{index-DXkw-nt5.js → index-BMsRfvkp.js} +1 -1
  105. package/src/assets/web-panel/assets/{index-BeBxP1M6.js → index-BObyCZ2w.js} +1 -1
  106. package/src/assets/web-panel/assets/{index-D_asIcU7.js → index-BPwv3l6X.js} +1 -1
  107. package/src/assets/web-panel/assets/{index-BeSzdB7x.js → index-BQr5mmyc.js} +1 -1
  108. package/src/assets/web-panel/assets/{index-w36TkwyO.js → index-BVHaJNpn.js} +1 -1
  109. package/src/assets/web-panel/assets/{index-D_-w4KkD.js → index-BefXafSw.js} +1 -1
  110. package/src/assets/web-panel/assets/{index-DvGttIXQ.js → index-BgvrlrtJ.js} +1 -1
  111. package/src/assets/web-panel/assets/{index-LVvzNdPa.js → index-BiPmMm38.js} +1 -1
  112. package/src/assets/web-panel/assets/{index-CdHXVSZ4.js → index-BoZnaD3Q.js} +1 -1
  113. package/src/assets/web-panel/assets/{index-Q5sAV7wp.js → index-BxJC59QT.js} +1 -1
  114. package/src/assets/web-panel/assets/{index-BGHd4D8F.js → index-CD8egQCF.js} +1 -1
  115. package/src/assets/web-panel/assets/index-CLafGdQC.js +1 -0
  116. package/src/assets/web-panel/assets/{index-JrVhUwyh.js → index-CaJvbmCw.js} +1 -1
  117. package/src/assets/web-panel/assets/{index-CTk9gY88.js → index-CfVl0Oqt.js} +1 -1
  118. package/src/assets/web-panel/assets/{index-DJSn3owP.js → index-ChGe005u.js} +1 -1
  119. package/src/assets/web-panel/assets/{index-DDPmr5Yr.js → index-Cjxxw-1P.js} +1 -1
  120. package/src/assets/web-panel/assets/{index-BEXKES7V.js → index-CmkppTkH.js} +1 -1
  121. package/src/assets/web-panel/assets/{index-CmPnDXx4.js → index-DFErisPY.js} +1 -1
  122. package/src/assets/web-panel/assets/{index-B_l6gfDh.js → index-DVfUt2bK.js} +1 -1
  123. package/src/assets/web-panel/assets/index-DYHw3Xoi.js +1 -0
  124. package/src/assets/web-panel/assets/{index-CnezE05k.js → index-DZ16Oxcu.js} +1 -1
  125. package/src/assets/web-panel/assets/{index-faHHtBKj.js → index-DbmhJVc3.js} +1 -1
  126. package/src/assets/web-panel/assets/{index-CzoKAiyT.js → index-Dd0OgZmt.js} +3 -3
  127. package/src/assets/web-panel/assets/{index-B-bNzvdU.js → index-DgYmI2pD.js} +1 -1
  128. package/src/assets/web-panel/assets/{index-B9_jRD2e.js → index-DmUZGqe2.js} +1 -1
  129. package/src/assets/web-panel/assets/{index-BuBnM6Kz.js → index-Dq9SDl82.js} +1 -1
  130. package/src/assets/web-panel/assets/{index-BLwY9y0X.js → index-DuIfomtv.js} +1 -1
  131. package/src/assets/web-panel/assets/{index-S8fkzbQ_.js → index-MGJzHAw_.js} +1 -1
  132. package/src/assets/web-panel/assets/{index-Df_CY0We.js → index-PCe8NA3J.js} +1 -1
  133. package/src/assets/web-panel/assets/{index-DEbAW3Ec.js → index-PiL6D-FC.js} +1 -1
  134. package/src/assets/web-panel/assets/{index-CBI-7Q3W.js → index-a_H30VZX.js} +1 -1
  135. package/src/assets/web-panel/assets/{index-Dnvj_XU-.js → index-hBzgHVea.js} +1 -1
  136. package/src/assets/web-panel/assets/{index-Bz7pG8z3.js → index-uDSUo2y2.js} +1 -1
  137. package/src/assets/web-panel/assets/{initDefaultProps-BlhbrsQk.js → initDefaultProps-CCYgHcTH.js} +1 -1
  138. package/src/assets/web-panel/assets/{motion-UZx12NPM.js → motion-4Yr4ZkjE.js} +1 -1
  139. package/src/assets/web-panel/assets/{move-BTby5W4q.js → move-ZP90E-ji.js} +1 -1
  140. package/src/assets/web-panel/assets/{mtc-parser-BOOaGiCg.js → mtc-parser-s0N3WyRA.js} +1 -1
  141. package/src/assets/web-panel/assets/{omit-BVylGzEr.js → omit-BZ6gx9Kf.js} +1 -1
  142. package/src/assets/web-panel/assets/{pickAttrs-Cp3Nflbr.js → pickAttrs-DxUtFOOQ.js} +1 -1
  143. package/src/assets/web-panel/assets/{placementArrow-BVXYvwH2.js → placementArrow-Btzjn1hK.js} +1 -1
  144. package/src/assets/web-panel/assets/{responsiveObserve-C67SbpBN.js → responsiveObserve-DYcoe1XJ.js} +1 -1
  145. package/src/assets/web-panel/assets/{slide-CnBvM22R.js → slide-BiBewdr4.js} +1 -1
  146. package/src/assets/web-panel/assets/{statusUtils-T8fy53tf.js → statusUtils-D9vt0dkG.js} +1 -1
  147. package/src/assets/web-panel/assets/{styleChecker-Bf7i4nlm.js → styleChecker-BXsm_vG0.js} +1 -1
  148. package/src/assets/web-panel/assets/{useFlexGapSupport-BUKk7jqw.js → useFlexGapSupport-CIG8zET4.js} +1 -1
  149. package/src/assets/web-panel/assets/{useFs-T5lg6SpD.js → useFs-ChFPF8GI.js} +1 -1
  150. package/src/assets/web-panel/assets/{usePersonalDataHub-Brvye8Tg.js → usePersonalDataHub-D4CzWJhY.js} +1 -1
  151. package/src/assets/web-panel/assets/{vnode-CK992ojP.js → vnode-6V5tphk5.js} +1 -1
  152. package/src/assets/web-panel/assets/{zoom-CcABB_97.js → zoom-B2H_VwfU.js} +1 -1
  153. package/src/assets/web-panel/index.html +1 -1
  154. package/src/command-help-index.json +4 -4
  155. package/src/commands/agent.js +64 -62
  156. package/src/commands/goal.js +79 -0
  157. package/src/commands/mcp-tasks.js +239 -0
  158. package/src/commands/mcp.js +58 -2
  159. package/src/commands/memory.js +131 -7
  160. package/src/commands/session-show.js +36 -1
  161. package/src/data/changelog.json +39 -0
  162. package/src/generated/cc-agent-protocol.schema.json +175 -69
  163. package/src/harness/jsonl-session-store.js +10 -0
  164. package/src/harness/mcp-client.js +701 -51
  165. package/src/harness/prompt-compressor.js +1 -0
  166. package/src/harness/session-index.js +8 -0
  167. package/src/harness/session-list-index.js +13 -58
  168. package/src/host/README.md +43 -0
  169. package/src/host/project-goal-graph.js +57 -0
  170. package/src/lib/agent-session-export.js +19 -0
  171. package/src/lib/app-server/context-memory-notifications.js +11 -2
  172. package/src/lib/app-server/server.js +1 -0
  173. package/src/lib/background-launch-profile.js +38 -6
  174. package/src/lib/codex-app-server-adapter.js +20 -0
  175. package/src/lib/codex-app-server-support.js +2 -2
  176. package/src/lib/context-memory-kernel/local-semantic-source.js +426 -0
  177. package/src/lib/context-memory-kernel/local-semantic-worker.py +109 -0
  178. package/src/lib/context-memory-kernel/memory-query-control.js +5 -1
  179. package/src/lib/context-memory-kernel/memory-query-index.js +37 -1
  180. package/src/lib/context-memory-kernel/memory-service.js +35 -2
  181. package/src/lib/context-memory-kernel/message-adapter.js +27 -5
  182. package/src/lib/context-memory-kernel/provider-context.js +197 -15
  183. package/src/lib/context-memory-kernel/runtime.js +40 -0
  184. package/src/lib/context-memory-kernel/segmented-memory-port.js +26 -1
  185. package/src/lib/evolution/agent-evolution-ingress.js +55 -1
  186. package/src/lib/evolution/evolution-artifact-ports.js +36 -1
  187. package/src/lib/evolution/skill-candidate-registry.js +3 -1
  188. package/src/lib/formal-budget-authority.js +56 -3
  189. package/src/lib/formal-budget-contract.js +90 -5
  190. package/src/lib/formal-budget-provider-scope.js +29 -7
  191. package/src/lib/formal-budget-transport.js +36 -5
  192. package/src/lib/goal-store.js +219 -0
  193. package/src/lib/graph-kernel/graph-runtime-surfaces.json +30 -0
  194. package/src/lib/graph-kernel/production-source-evidence.js +3 -3
  195. package/src/lib/graph-kernel/runtime-surface-manifest.js +46 -9
  196. package/src/lib/graph-kernel/runtime.js +12 -1
  197. package/src/lib/mcp-call-ledger-projection.js +1026 -0
  198. package/src/lib/mcp-call-ledger-store.js +19 -1024
  199. package/src/lib/mcp-client.js +1 -0
  200. package/src/lib/mcp-ledger-recovery-admission.js +25 -0
  201. package/src/lib/mcp-stateless-protocol.js +158 -0
  202. package/src/lib/mcp-task-continuation-contract.js +129 -0
  203. package/src/lib/mcp-task-continuation.js +147 -0
  204. package/src/lib/mcp-task-delivery-contract.js +190 -0
  205. package/src/lib/mcp-task-delivery.js +113 -0
  206. package/src/lib/mcp-task-journal-projection.js +495 -0
  207. package/src/lib/mcp-task-journal.js +57 -0
  208. package/src/lib/mcp-task-runtime.js +627 -0
  209. package/src/lib/mcp-tasks.js +217 -0
  210. package/src/lib/model-input-diagnostics.js +265 -0
  211. package/src/lib/model-input-source-mapping.js +343 -0
  212. package/src/lib/openai-responses.js +32 -9
  213. package/src/lib/provider-request-admission.js +181 -0
  214. package/src/lib/public-ide-capability-manifest.js +2 -0
  215. package/src/lib/scheduler-kernel/graph-authority-adapter.js +140 -15
  216. package/src/lib/session-generation-authority.js +58 -0
  217. package/src/lib/session-host-snapshot.js +37 -0
  218. package/src/lib/session-input-lifecycle.js +147 -0
  219. package/src/lib/session-input-receipt.js +64 -0
  220. package/src/lib/session-message-provenance.js +6 -5
  221. package/src/lib/session-model-input-diagnostics.js +262 -0
  222. package/src/lib/session-model-usage-recovery.js +115 -0
  223. package/src/lib/session-transcript-history.js +9 -0
  224. package/src/lib/session-transcript-page.js +7 -1
  225. package/src/lib/session-transcript-structure.js +45 -0
  226. package/src/lib/storage-failure-cause-codes.js +79 -0
  227. package/src/lib/sub-agent-context.js +7 -3
  228. package/src/repl/agent-repl.js +526 -253
  229. package/src/runtime/agent-core.js +296 -151
  230. package/src/runtime/headless-runner.js +58 -69
  231. package/src/runtime/headless-stream.js +40 -33
  232. package/src/runtime/mcp-config.js +5 -3
  233. package/src/runtime/policies/agent-policy.js +1 -0
  234. package/src/assets/web-panel/assets/index-DruOFzuF.js +0 -1
  235. package/src/assets/web-panel/assets/index-hhOrZ6HO.js +0 -1
@@ -10,7 +10,7 @@
10
10
 
11
11
  import { executionBroker } from "../lib/process-execution-broker/index.js";
12
12
  import { AsyncLocalStorage } from "node:async_hooks";
13
- import { randomUUID } from "node:crypto";
13
+ import { createHmac, randomUUID } from "node:crypto";
14
14
  import { EventEmitter } from "events";
15
15
  import { pathToFileURL } from "url";
16
16
  import { isProxy } from "node:util/types";
@@ -29,6 +29,21 @@ import {
29
29
  isMcpToolMetadataError,
30
30
  } from "../lib/mcp-tool-metadata.js";
31
31
  import { admitMcpToolResult } from "../lib/mcp-tool-result.js";
32
+ import {
33
+ mcpTaskError,
34
+ mcpTaskId,
35
+ mcpTaskParameters,
36
+ requireMcpTaskCapability,
37
+ requireMcpToolTaskMode,
38
+ admitMcpTaskResponse,
39
+ MCP_STATELESS_PROTOCOL_VERSION,
40
+ } from "../lib/mcp-tasks.js";
41
+ import {
42
+ statelessMcpRequest,
43
+ admitStatelessMcpTask,
44
+ assertStatelessMcpAck,
45
+ } from "../lib/mcp-stateless-protocol.js";
46
+
32
47
  import { terminateOwnedProcessTree } from "../lib/process-tree-termination.js";
33
48
  import {
34
49
  mergeMcpHeaders,
@@ -58,6 +73,118 @@ import {
58
73
  McpLifecycleAuthority,
59
74
  } from "../lib/mcp-lifecycle-authority.js";
60
75
 
76
+ const MCP_TASK_REQUEST = Symbol("mcp.task.request");
77
+ const MCP_TASK_BINDINGS = new WeakMap();
78
+ const MCP_TASK_RESERVATIONS = new WeakMap();
79
+
80
+ function reserveTaskBinding(client) {
81
+ const pending = MCP_TASK_RESERVATIONS.get(client) || 0;
82
+ if (taskBindings(client).size + pending >= 1024) {
83
+ throw mcpTaskError(
84
+ "CC_MCP_TASK_BINDING_LIMIT",
85
+ "MCP task binding limit reached",
86
+ );
87
+ }
88
+ MCP_TASK_RESERVATIONS.set(client, pending + 1);
89
+ return () =>
90
+ MCP_TASK_RESERVATIONS.set(
91
+ client,
92
+ (MCP_TASK_RESERVATIONS.get(client) || 1) - 1,
93
+ );
94
+ }
95
+
96
+ function taskConnectionIdentity(entry) {
97
+ return JSON.stringify([
98
+ entry.httpUrl ?? null,
99
+ entry.httpSessionId ?? null,
100
+ entry.protocolVersion ?? null,
101
+ Object.entries(entry.httpHeaders || {}).sort(([a], [b]) =>
102
+ a.localeCompare(b),
103
+ ),
104
+ ]);
105
+ }
106
+
107
+ function taskBindings(client) {
108
+ let bindings = MCP_TASK_BINDINGS.get(client);
109
+ if (!bindings) {
110
+ bindings = new Map();
111
+ MCP_TASK_BINDINGS.set(client, bindings);
112
+ }
113
+ return bindings;
114
+ }
115
+
116
+ function rememberTasks(
117
+ client,
118
+ serverName,
119
+ entry,
120
+ identity,
121
+ tasks,
122
+ reservation = 0,
123
+ ) {
124
+ const bindings = taskBindings(client);
125
+ const additions = tasks.filter(
126
+ (task) => !bindings.has(JSON.stringify([serverName, task.taskId])),
127
+ );
128
+ if (
129
+ bindings.size +
130
+ additions.length +
131
+ (MCP_TASK_RESERVATIONS.get(client) || 0) -
132
+ reservation >
133
+ 1024
134
+ ) {
135
+ throw mcpTaskError(
136
+ "CC_MCP_TASK_BINDING_LIMIT",
137
+ "MCP task binding limit reached",
138
+ true,
139
+ );
140
+ }
141
+ for (const task of tasks) {
142
+ const previous = bindings.get(JSON.stringify([serverName, task.taskId]));
143
+ if (
144
+ previous &&
145
+ (previous.entry !== entry || previous.identity !== identity)
146
+ ) {
147
+ throw mcpTaskError(
148
+ "CC_MCP_TASK_BINDING_CHANGED",
149
+ "MCP task belongs to a different connection",
150
+ true,
151
+ );
152
+ }
153
+ if (
154
+ previous?.terminalObserved &&
155
+ ["working", "input_required"].includes(task.status)
156
+ ) {
157
+ throw mcpTaskError(
158
+ "CC_MCP_TASK_STATUS_REGRESSION",
159
+ "MCP task returned to a nonterminal status",
160
+ true,
161
+ );
162
+ }
163
+ if (
164
+ previous &&
165
+ ["completed", "failed", "cancelled"].includes(previous.status) &&
166
+ previous.status !== task.status
167
+ ) {
168
+ throw mcpTaskError(
169
+ "CC_MCP_TASK_STATUS_REGRESSION",
170
+ "MCP task terminal status changed",
171
+ true,
172
+ );
173
+ }
174
+ }
175
+ for (const task of tasks) {
176
+ bindings.set(JSON.stringify([serverName, task.taskId]), {
177
+ entry,
178
+ identity,
179
+ status: task.status,
180
+ terminalObserved:
181
+ ["completed", "failed", "cancelled"].includes(task.status) ||
182
+ bindings.get(JSON.stringify([serverName, task.taskId]))
183
+ ?.terminalObserved === true,
184
+ });
185
+ }
186
+ }
187
+
61
188
  /**
62
189
  * Injectable dependencies — overridable from tests.
63
190
  * `fetch` defaults to the global fetch (Node 18+).
@@ -258,6 +385,7 @@ export const SUPPORTED_MCP_PROTOCOL_VERSIONS = Object.freeze([
258
385
  "2025-03-26",
259
386
  "2025-06-18",
260
387
  MCP_PROTOCOL_VERSION,
388
+ MCP_STATELESS_PROTOCOL_VERSION,
261
389
  ]);
262
390
  const supportedMcpProtocolVersions = new Set(SUPPORTED_MCP_PROTOCOL_VERSIONS);
263
391
 
@@ -334,6 +462,7 @@ function discoveryCacheKey(name, entry) {
334
462
  entry?.httpUrl || entry?.socketUrl || config.url || null,
335
463
  config.command || null,
336
464
  Array.isArray(config.args) ? config.args : [],
465
+ entry?.protocolVersion ?? null,
337
466
  ]);
338
467
  }
339
468
 
@@ -362,6 +491,23 @@ export function assertSupportedMcpProtocolVersion(value) {
362
491
  }
363
492
  return value;
364
493
  }
494
+
495
+ export function mcpProtocolVersionField(config = {}) {
496
+ if (config.protocolVersion == null) return {};
497
+ const protocolVersion = assertSupportedMcpProtocolVersion(
498
+ config.protocolVersion,
499
+ );
500
+ if (
501
+ protocolVersion === MCP_STATELESS_PROTOCOL_VERSION &&
502
+ !["http", "https"].includes(inferTransport(config))
503
+ ) {
504
+ throw mcpTaskError(
505
+ "CC_MCP_STATELESS_TRANSPORT_UNSUPPORTED",
506
+ "MCP stateless configuration requires Streamable HTTP",
507
+ );
508
+ }
509
+ return { protocolVersion };
510
+ }
365
511
  const URL_ELICITATION_REQUIRED = -32042;
366
512
  const MCP_RPC_ERROR_CODE = "CC_MCP_RPC_ERROR";
367
513
  const mcpRpcControlData = new WeakMap();
@@ -791,7 +937,16 @@ function pendingToolFailure(error, entry, method, dispatched) {
791
937
 
792
938
  function dispatchMcpToolRequest(options, metadata, dispatch) {
793
939
  const admission = options?.dispatchAdmission ?? null;
794
- if (metadata.method !== "tools/call" || admission === null) {
940
+ if (
941
+ ![
942
+ "tools/call",
943
+ "tasks/get",
944
+ "tasks/result",
945
+ "tasks/list",
946
+ "tasks/cancel",
947
+ ].includes(metadata.method) ||
948
+ admission === null
949
+ ) {
795
950
  return dispatch();
796
951
  }
797
952
  if (typeof admission !== "function") {
@@ -961,8 +1116,8 @@ function mcpInboundBudgetError(serverName, entry, budget) {
961
1116
  function mcpJsonBudgetError(serverName, entry, budget) {
962
1117
  const dispatched = Boolean(
963
1118
  (entry?._pending instanceof Map && entry._pending.size > 0) ||
964
- (entry?._httpRequestControllers instanceof Set &&
965
- entry._httpRequestControllers.size > 0),
1119
+ (entry?._httpRequestControllers instanceof Set &&
1120
+ entry._httpRequestControllers.size > 0),
966
1121
  );
967
1122
  if (budget === "depth") {
968
1123
  const limitDepth = mcpJsonDepthLimit(entry?.config?.maxJsonDepth);
@@ -1043,7 +1198,16 @@ function safeRpcErrorText(error) {
1043
1198
  return typeof message === "string" ? message : "";
1044
1199
  }
1045
1200
 
1201
+ function unsupportedStatelessClientRequest() {
1202
+ return mcpTaskError(
1203
+ "CC_MCP_STATELESS_CLIENT_REQUEST_UNSUPPORTED",
1204
+ "MCP stateless response requires unadvertised client interaction",
1205
+ true,
1206
+ );
1207
+ }
1208
+
1046
1209
  const MCP_NON_RETRYABLE_PROTOCOL_ERROR_CODES = new Set([
1210
+ "CC_MCP_STATELESS_CLIENT_REQUEST_UNSUPPORTED",
1047
1211
  "CC_MCP_WS_PAYLOAD_TOO_LARGE",
1048
1212
  "CC_MCP_WS_BINARY_MESSAGE",
1049
1213
  "CC_MCP_WS_INVALID_MESSAGE",
@@ -1779,6 +1943,8 @@ export class MCPClient extends EventEmitter {
1779
1943
  }
1780
1944
 
1781
1945
  async _resolveElicitation(serverName, requestId, params = {}) {
1946
+ if (this.servers.get(String(serverName))?.statelessHttp)
1947
+ throw unsupportedStatelessClientRequest();
1782
1948
  if (this._activeElicitations >= this._maxConcurrentElicitations) {
1783
1949
  const request = normalizeMcpElicitationRequest(
1784
1950
  serverName,
@@ -2003,6 +2169,7 @@ export class MCPClient extends EventEmitter {
2003
2169
  }
2004
2170
 
2005
2171
  _handleElicitationComplete(serverName, params = {}) {
2172
+ if (this.servers.get(String(serverName))?.statelessHttp) return false;
2006
2173
  const elicitationId = String(params.elicitationId || "");
2007
2174
  const entry = this._urlElicitations.get(elicitationId);
2008
2175
  if (!entry || entry.server !== String(serverName)) {
@@ -2319,6 +2486,17 @@ export class MCPClient extends EventEmitter {
2319
2486
  }
2320
2487
 
2321
2488
  const transportKind = inferTransport(config);
2489
+ const requestedProtocolVersion = assertSupportedMcpProtocolVersion(
2490
+ config?.protocolVersion ?? this._protocolVersion,
2491
+ );
2492
+ const statelessHttp =
2493
+ requestedProtocolVersion === MCP_STATELESS_PROTOCOL_VERSION;
2494
+ if (statelessHttp && !["http", "https"].includes(transportKind)) {
2495
+ throw mcpTaskError(
2496
+ "CC_MCP_STATELESS_TRANSPORT_UNSUPPORTED",
2497
+ "MCP 2026-07-28 currently requires explicit Streamable HTTP configuration",
2498
+ );
2499
+ }
2322
2500
  let stdioExecutionApproval = null;
2323
2501
  let approvedStdioInvocation = null;
2324
2502
  if (transportKind === "stdio") {
@@ -2457,7 +2635,8 @@ export class MCPClient extends EventEmitter {
2457
2635
  httpUrl: null,
2458
2636
  httpHeaders: connectionHeaders,
2459
2637
  httpSessionId: null,
2460
- protocolVersion: null,
2638
+ protocolVersion: statelessHttp ? MCP_STATELESS_PROTOCOL_VERSION : null,
2639
+ statelessHttp,
2461
2640
  _httpMessageStream: null,
2462
2641
  _httpRequestControllers: new Set(),
2463
2642
  _httpDiscardControllers: new Set(),
@@ -3045,33 +3224,63 @@ export class MCPClient extends EventEmitter {
3045
3224
  this._transitionLifecycle(entry, MCP_LIFECYCLE_PHASES.INITIALIZING, {
3046
3225
  tlsIdentityDigest: entry._tlsIdentityDigest,
3047
3226
  });
3048
- const initResult = await this._requestWithRetry(name, "initialize", {
3049
- protocolVersion: this._protocolVersion,
3050
- capabilities: {
3051
- tools: {},
3052
- resources: {},
3053
- prompts: {},
3054
- elicitation: supportsUrlElicitationVersion(this._protocolVersion)
3055
- ? { form: {}, url: {} }
3056
- : { form: {} },
3057
- // Client-side roots capability: servers may request roots/list and
3058
- // subscribe to list_changed notifications (Claude-Code 2.1.203).
3059
- roots: { listChanged: true },
3060
- },
3061
- clientInfo: { name: "chainlesschain-cli", version: "0.37.9" },
3062
- });
3063
-
3064
- entry.protocolVersion = assertSupportedMcpProtocolVersion(
3065
- initResult?.protocolVersion,
3227
+ const initResult = await this._requestWithRetry(
3228
+ name,
3229
+ statelessHttp ? "server/discover" : "initialize",
3230
+ statelessHttp
3231
+ ? {}
3232
+ : {
3233
+ protocolVersion: requestedProtocolVersion,
3234
+ capabilities: {
3235
+ tools: {},
3236
+ resources: {},
3237
+ prompts: {},
3238
+ elicitation: supportsUrlElicitationVersion(
3239
+ requestedProtocolVersion,
3240
+ )
3241
+ ? { form: {}, url: {} }
3242
+ : { form: {} },
3243
+ // Client-side roots capability: servers may request roots/list and
3244
+ // subscribe to list_changed notifications (Claude-Code 2.1.203).
3245
+ roots: { listChanged: true },
3246
+ },
3247
+ clientInfo: { name: "chainlesschain-cli", version: "0.37.9" },
3248
+ },
3066
3249
  );
3250
+
3251
+ if (statelessHttp) {
3252
+ if (
3253
+ !Array.isArray(initResult?.supportedVersions) ||
3254
+ !initResult.supportedVersions.includes(MCP_STATELESS_PROTOCOL_VERSION)
3255
+ ) {
3256
+ throw mcpTaskError(
3257
+ "CC_MCP_PROTOCOL_VERSION_UNSUPPORTED",
3258
+ "MCP discovery did not confirm the requested protocol",
3259
+ );
3260
+ }
3261
+ } else {
3262
+ entry.protocolVersion = assertSupportedMcpProtocolVersion(
3263
+ initResult?.protocolVersion,
3264
+ );
3265
+ if (entry.protocolVersion === MCP_STATELESS_PROTOCOL_VERSION) {
3266
+ throw mcpTaskError(
3267
+ "CC_MCP_PROTOCOL_VERSION_UNSUPPORTED",
3268
+ "MCP stateless protocol requires explicit discovery; initialization cannot upgrade it",
3269
+ );
3270
+ }
3271
+ }
3067
3272
  this._transitionLifecycle(entry, MCP_LIFECYCLE_PHASES.DISCOVERING, {
3068
3273
  tlsIdentityDigest: entry._tlsIdentityDigest,
3069
3274
  });
3070
3275
  // Send initialized notification
3071
- this._sendNotification(name, "notifications/initialized", {});
3276
+ if (!statelessHttp)
3277
+ this._sendNotification(name, "notifications/initialized", {});
3072
3278
 
3073
3279
  entry.state = ServerState.CONNECTED;
3074
- entry.serverInfo = initResult?.serverInfo || {};
3280
+ entry.serverInfo =
3281
+ (statelessHttp
3282
+ ? initResult?._meta?.["io.modelcontextprotocol/serverInfo"]
3283
+ : initResult?.serverInfo) || {};
3075
3284
  entry.capabilities = initResult?.capabilities || {};
3076
3285
  // Optional top-level usage instructions from the server's initialize
3077
3286
  // response (previously discarded). Surfaced by tool search so a deferred
@@ -3233,6 +3442,7 @@ export class MCPClient extends EventEmitter {
3233
3442
  });
3234
3443
  if (
3235
3444
  entry.httpUrl &&
3445
+ !entry.statelessHttp &&
3236
3446
  (this._elicitationHandler || this._elicitationHandlers.size > 0)
3237
3447
  ) {
3238
3448
  this._ensureHttpMessageStream(name);
@@ -3712,6 +3922,7 @@ export class MCPClient extends EventEmitter {
3712
3922
  }
3713
3923
 
3714
3924
  async _resolveRequiredUrlElicitations(serverName, error) {
3925
+ if (this.servers.get(serverName)?.statelessHttp) return false;
3715
3926
  const requested = mcpRpcControlData.get(error)?.elicitations;
3716
3927
  if (
3717
3928
  !Array.isArray(requested) ||
@@ -3786,6 +3997,297 @@ export class MCPClient extends EventEmitter {
3786
3997
  return completed.every(Boolean);
3787
3998
  }
3788
3999
 
4000
+ /**
4001
+ * Low-level experimental Tasks requester. No automatic replay, durable
4002
+ * recovery, polling scheduler or task receiver capabilities are implied.
4003
+ * Recovery-guarded host facades deliberately deny this surface for now.
4004
+ */
4005
+ async callToolTask(serverName, toolName, args = {}, options = {}) {
4006
+ const task = mcpTaskParameters(options.ttl);
4007
+ const release = reserveTaskBinding(this);
4008
+ try {
4009
+ const entry = this.servers.get(serverName);
4010
+ if (entry?.statelessHttp && options.ttl !== undefined) {
4011
+ throw mcpTaskError(
4012
+ "CC_MCP_TASK_TTL_UNSUPPORTED",
4013
+ "Stateless task TTL is selected by the server; a client TTL cannot be requested",
4014
+ );
4015
+ }
4016
+ const identity = taskConnectionIdentity(entry || {});
4017
+ let result;
4018
+ try {
4019
+ result = await this._callToolOnce(serverName, toolName, args, {
4020
+ ...options,
4021
+ [MCP_TASK_REQUEST]: task,
4022
+ });
4023
+ } catch (error) {
4024
+ if (
4025
+ safeRpcProperty(error, "code") === "CC_MCP_HTTP_STATUS" &&
4026
+ safeRpcProperty(error, "status") === 404
4027
+ ) {
4028
+ throw mcpTaskError(
4029
+ "CC_MCP_HTTP_TOOL_OUTCOME_UNKNOWN",
4030
+ "MCP task acceptance is unknown after HTTP 404; the tool was not replayed",
4031
+ true,
4032
+ );
4033
+ }
4034
+ throw error;
4035
+ }
4036
+ if (
4037
+ this.servers.get(serverName) !== entry ||
4038
+ taskConnectionIdentity(entry) !== identity
4039
+ ) {
4040
+ throw mcpTaskError(
4041
+ "CC_MCP_TASK_BINDING_CHANGED",
4042
+ "MCP task connection identity changed",
4043
+ true,
4044
+ );
4045
+ }
4046
+ rememberTasks(this, serverName, entry, identity, [result.task], 1);
4047
+ return result;
4048
+ } finally {
4049
+ release();
4050
+ }
4051
+ }
4052
+
4053
+ /**
4054
+ * Stable, secret-keyed identity for verified journal recovery. The MCP HTTP
4055
+ * session is intentionally excluded here; the restored task is separately
4056
+ * bound to the new live entry/session by restoreTaskBinding().
4057
+ */
4058
+ getTaskRecoveryIdentity(serverName, key) {
4059
+ const entry = this.servers.get(serverName);
4060
+ if (
4061
+ !entry ||
4062
+ entry.state !== ServerState.CONNECTED ||
4063
+ entry._httpDiscardStopping
4064
+ ) {
4065
+ throw mcpTaskError(
4066
+ "CC_MCP_TASK_CONNECTION_REQUIRED",
4067
+ "MCP task requires its connected server",
4068
+ );
4069
+ }
4070
+ requireMcpTaskCapability(entry, "get");
4071
+ if (!entry.httpUrl || !["http", "https"].includes(entry.transportKind)) {
4072
+ throw mcpTaskError(
4073
+ "CC_MCP_TASK_RECOVERY_TRANSPORT_UNSUPPORTED",
4074
+ "Durable MCP task recovery currently requires HTTP",
4075
+ );
4076
+ }
4077
+ if (typeof key !== "string" || !/^[a-f0-9]{64}$/.test(key)) {
4078
+ throw mcpTaskError(
4079
+ "CC_MCP_TASK_RECOVERY_KEY_INVALID",
4080
+ "MCP task recovery key is unavailable",
4081
+ );
4082
+ }
4083
+ const identity = {
4084
+ schema: "chainlesschain.mcp-task-server-identity/v1",
4085
+ serverName,
4086
+ transport: entry.transportKind,
4087
+ endpoint: entry.httpUrl,
4088
+ protocol: entry.protocolVersion,
4089
+ headers: Object.entries(entry.httpHeaders || {})
4090
+ .map(([name, value]) => [name.toLowerCase(), value])
4091
+ .sort(([a], [b]) => a.localeCompare(b)),
4092
+ tls: entry._tlsIdentityDigest ?? null,
4093
+ tlsServerName: entry.config?.tls?.serverName ?? null,
4094
+ tlsVerify: entry.config?.tls?.rejectUnauthorized ?? true,
4095
+ configScope: entry.config?.configScope ?? null,
4096
+ headersHelper: entry.config?.headersHelper ?? null,
4097
+ };
4098
+ return (
4099
+ "hmac-sha256:" +
4100
+ createHmac("sha256", Buffer.from(key, "hex"))
4101
+ .update(JSON.stringify(identity))
4102
+ .digest("hex")
4103
+ );
4104
+ }
4105
+
4106
+ /** Low-level host primitive; callers must obtain data from verified storage. */
4107
+ restoreTaskBinding(serverName, task, { key, identityDigest } = {}) {
4108
+ if (this.getTaskRecoveryIdentity(serverName, key) !== identityDigest) {
4109
+ throw mcpTaskError(
4110
+ "CC_MCP_TASK_RECOVERY_IDENTITY_CHANGED",
4111
+ "MCP task server authorization identity changed",
4112
+ );
4113
+ }
4114
+ const entry = this.servers.get(serverName);
4115
+ const admitted = admitMcpTaskResponse(serverName, task, entry.config, {
4116
+ kind: "get",
4117
+ });
4118
+ const identity = taskConnectionIdentity(entry);
4119
+ const previous = taskBindings(this).get(
4120
+ JSON.stringify([serverName, admitted.taskId]),
4121
+ );
4122
+ if (previous) {
4123
+ if (previous.entry !== entry || previous.identity !== identity) {
4124
+ throw mcpTaskError(
4125
+ "CC_MCP_TASK_BINDING_CHANGED",
4126
+ "MCP task requires a fresh client after reconnection",
4127
+ );
4128
+ }
4129
+ // A journal snapshot must not roll back a more recent in-process status.
4130
+ return admitted.taskId;
4131
+ }
4132
+ rememberTasks(this, serverName, entry, identity, [admitted]);
4133
+ return admitted.taskId;
4134
+ }
4135
+
4136
+ async _taskRequest(serverName, method, params, options, kind) {
4137
+ const entry = this.servers.get(serverName);
4138
+ if (
4139
+ !entry ||
4140
+ entry.state !== ServerState.CONNECTED ||
4141
+ entry._httpDiscardStopping
4142
+ ) {
4143
+ throw mcpTaskError(
4144
+ "CC_MCP_TASK_CONNECTION_REQUIRED",
4145
+ "MCP task requires its connected server",
4146
+ );
4147
+ }
4148
+ requireMcpTaskCapability(entry, kind);
4149
+ const identity = taskConnectionIdentity(entry);
4150
+ if (kind !== "list") {
4151
+ const binding = taskBindings(this).get(
4152
+ JSON.stringify([serverName, params.taskId]),
4153
+ );
4154
+ if (
4155
+ !binding ||
4156
+ binding.entry !== entry ||
4157
+ binding.identity !== identity
4158
+ ) {
4159
+ throw mcpTaskError(
4160
+ "CC_MCP_TASK_BINDING_REQUIRED",
4161
+ "MCP task requires its original connection binding",
4162
+ );
4163
+ }
4164
+ }
4165
+ let value;
4166
+ try {
4167
+ value = await this._sendRequest(
4168
+ serverName,
4169
+ entry.statelessHttp && kind === "result" ? "tasks/get" : method,
4170
+ params,
4171
+ options,
4172
+ );
4173
+ } catch (error) {
4174
+ if (
4175
+ kind === "cancel" &&
4176
+ !isMcpRpcError(error) &&
4177
+ safeRpcProperty(error, "dispatched") !== false
4178
+ ) {
4179
+ throw mcpTaskError(
4180
+ "CC_MCP_TASK_CANCEL_OUTCOME_UNKNOWN",
4181
+ "MCP task cancellation outcome is unknown",
4182
+ true,
4183
+ );
4184
+ }
4185
+ throw error;
4186
+ }
4187
+ if (
4188
+ this.servers.get(serverName) !== entry ||
4189
+ entry.state !== ServerState.CONNECTED ||
4190
+ taskConnectionIdentity(entry) !== identity
4191
+ ) {
4192
+ throw mcpTaskError(
4193
+ "CC_MCP_TASK_CONNECTION_CHANGED",
4194
+ "MCP task connection changed during request",
4195
+ true,
4196
+ );
4197
+ }
4198
+ if (entry.statelessHttp) {
4199
+ if (kind === "cancel") {
4200
+ assertStatelessMcpAck(serverName, value, entry.config);
4201
+ // Acknowledgement means accepted, not cancelled. Obtain a separate
4202
+ // observation before reporting the remote terminal state.
4203
+ return this.getTask(serverName, params.taskId, options);
4204
+ }
4205
+ const modern = admitStatelessMcpTask(serverName, value, entry.config, {
4206
+ taskId: params.taskId,
4207
+ });
4208
+ rememberTasks(this, serverName, entry, identity, [modern.task]);
4209
+ if (kind === "result") {
4210
+ if (!modern.result) {
4211
+ throw mcpTaskError(
4212
+ "CC_MCP_TASK_RESULT_UNAVAILABLE",
4213
+ "MCP task has no completed result; no tool invocation was replayed",
4214
+ true,
4215
+ );
4216
+ }
4217
+ return modern.result;
4218
+ }
4219
+ return modern.task;
4220
+ }
4221
+ const admitted = admitMcpTaskResponse(serverName, value, entry.config, {
4222
+ kind,
4223
+ taskId: params.taskId,
4224
+ });
4225
+ if (kind === "result") {
4226
+ taskBindings(this).get(
4227
+ JSON.stringify([serverName, params.taskId]),
4228
+ ).terminalObserved = true;
4229
+ } else {
4230
+ rememberTasks(
4231
+ this,
4232
+ serverName,
4233
+ entry,
4234
+ identity,
4235
+ kind === "list" ? admitted.tasks : [admitted],
4236
+ );
4237
+ }
4238
+ return admitted;
4239
+ }
4240
+
4241
+ async getTask(serverName, taskId, options = {}) {
4242
+ return this._taskRequest(
4243
+ serverName,
4244
+ "tasks/get",
4245
+ { taskId: mcpTaskId(taskId) },
4246
+ options,
4247
+ "get",
4248
+ );
4249
+ }
4250
+
4251
+ async getTaskResult(serverName, taskId, options = {}) {
4252
+ return this._taskRequest(
4253
+ serverName,
4254
+ "tasks/result",
4255
+ { taskId: mcpTaskId(taskId) },
4256
+ options,
4257
+ "result",
4258
+ );
4259
+ }
4260
+
4261
+ async cancelTask(serverName, taskId, options = {}) {
4262
+ // A cancellation acknowledgement never proves remote side effects stopped.
4263
+ return this._taskRequest(
4264
+ serverName,
4265
+ "tasks/cancel",
4266
+ { taskId: mcpTaskId(taskId) },
4267
+ options,
4268
+ "cancel",
4269
+ );
4270
+ }
4271
+
4272
+ async listTasks(serverName, cursor, options = {}) {
4273
+ if (
4274
+ cursor !== undefined &&
4275
+ (typeof cursor !== "string" || cursor.length > 65536)
4276
+ ) {
4277
+ throw mcpTaskError(
4278
+ "CC_MCP_TASK_CURSOR_INVALID",
4279
+ "MCP task cursor must be a bounded opaque string",
4280
+ );
4281
+ }
4282
+ return this._taskRequest(
4283
+ serverName,
4284
+ "tasks/list",
4285
+ cursor === undefined ? {} : { cursor },
4286
+ options,
4287
+ "list",
4288
+ );
4289
+ }
4290
+
3789
4291
  async _callToolOnce(serverName, toolName, args, options = {}) {
3790
4292
  const entry = this.servers.get(serverName);
3791
4293
  if (!entry) throw new Error(`Server "${serverName}" not found`);
@@ -3813,6 +4315,9 @@ export class MCPClient extends EventEmitter {
3813
4315
  );
3814
4316
  }
3815
4317
 
4318
+ const task = options[MCP_TASK_REQUEST];
4319
+ requireMcpToolTaskMode(entry, toolName, task !== undefined);
4320
+
3816
4321
  const timeoutMs = mcpToolIdleTimeoutMs(entry.config, options);
3817
4322
  const progressToken = `cc:${randomUUID()}`;
3818
4323
  const controller = new AbortController();
@@ -3846,6 +4351,7 @@ export class MCPClient extends EventEmitter {
3846
4351
  {
3847
4352
  name: toolName,
3848
4353
  arguments: args,
4354
+ ...(task === undefined || entry.statelessHttp ? {} : { task }),
3849
4355
  _meta: { progressToken },
3850
4356
  },
3851
4357
  { ...options, signal: controller.signal },
@@ -3854,7 +4360,14 @@ export class MCPClient extends EventEmitter {
3854
4360
  // The inner transport supplies cancellation and JSON-RPC
3855
4361
  // notifications/cancelled. Preserve the idle classification at the host
3856
4362
  // boundary instead of leaking its generic AbortError/cancelled detail.
3857
- if (idleError) throw idleError;
4363
+ if (idleError) {
4364
+ if (task !== undefined) {
4365
+ idleError.dispatched = safeRpcProperty(error, "dispatched") !== false;
4366
+ idleError.outcomeUnknown = idleError.dispatched;
4367
+ idleError.retryable = false;
4368
+ }
4369
+ throw idleError;
4370
+ }
3858
4371
  throw error;
3859
4372
  } finally {
3860
4373
  if (idleTimer) clearTimeout(idleTimer);
@@ -3866,7 +4379,40 @@ export class MCPClient extends EventEmitter {
3866
4379
  this._toolProgress.delete(progressToken);
3867
4380
  }
3868
4381
 
3869
- return admitMcpToolResult(serverName, result, entry.config).result;
4382
+ if (task !== undefined) {
4383
+ if (
4384
+ this.servers.get(serverName) !== entry ||
4385
+ entry.state !== ServerState.CONNECTED
4386
+ ) {
4387
+ throw mcpTaskError(
4388
+ "CC_MCP_TASK_CONNECTION_CHANGED",
4389
+ "MCP task connection changed during request",
4390
+ true,
4391
+ );
4392
+ }
4393
+ if (entry.statelessHttp) {
4394
+ const modern = admitStatelessMcpTask(serverName, result, entry.config, {
4395
+ create: true,
4396
+ });
4397
+ return { task: modern.task };
4398
+ }
4399
+ return admitMcpTaskResponse(serverName, result, entry.config, {
4400
+ kind: "create",
4401
+ });
4402
+ }
4403
+ const admitted = admitMcpToolResult(
4404
+ serverName,
4405
+ result,
4406
+ entry.config,
4407
+ ).result;
4408
+ if (Object.hasOwn(admitted, "task") || admitted.resultType === "task") {
4409
+ throw mcpTaskError(
4410
+ "CC_MCP_TASK_UNEXPECTED",
4411
+ "MCP task acceptance cannot settle an ordinary tool call",
4412
+ true,
4413
+ );
4414
+ }
4415
+ return admitted;
3870
4416
  }
3871
4417
 
3872
4418
  /**
@@ -4476,6 +5022,7 @@ export class MCPClient extends EventEmitter {
4476
5022
  }
4477
5023
 
4478
5024
  _sendRequestCancellation(serverName, method, requestId, reason) {
5025
+ if (this.servers.get(serverName)?.statelessHttp) return;
4479
5026
  // The initialize handshake establishes the protocol/session needed for
4480
5027
  // later notifications, so it cannot itself be cancelled safely.
4481
5028
  if (method === "initialize") return;
@@ -4531,6 +5078,7 @@ export class MCPClient extends EventEmitter {
4531
5078
  */
4532
5079
  _ensureHttpMessageStream(serverName) {
4533
5080
  const entry = this.servers.get(serverName);
5081
+ if (entry?.statelessHttp) return false;
4534
5082
  if (
4535
5083
  !entry?.httpUrl ||
4536
5084
  entry.state !== ServerState.CONNECTED ||
@@ -4712,7 +5260,19 @@ export class MCPClient extends EventEmitter {
4712
5260
  }
4713
5261
 
4714
5262
  const id = this._nextId++;
4715
- const body = JSON.stringify({ jsonrpc: "2.0", id, method, params });
5263
+ const modern = entry.statelessHttp
5264
+ ? statelessMcpRequest(method, params, {
5265
+ tasks:
5266
+ options[MCP_TASK_REQUEST] !== undefined ||
5267
+ method.startsWith("tasks/"),
5268
+ })
5269
+ : null;
5270
+ const body = JSON.stringify({
5271
+ jsonrpc: "2.0",
5272
+ id,
5273
+ method,
5274
+ params: modern?.params || params,
5275
+ });
4716
5276
  this._registerLifecycleRpc(entry, id, method);
4717
5277
  let lifecycleSettled = false;
4718
5278
  const settleLifecycle = (outcome) => {
@@ -4733,6 +5293,20 @@ export class MCPClient extends EventEmitter {
4733
5293
  headers["MCP-Protocol-Version"] =
4734
5294
  entry.protocolVersion || this._protocolVersion;
4735
5295
  }
5296
+ if (modern) {
5297
+ for (const key of Object.keys(headers)) {
5298
+ if (
5299
+ [
5300
+ "mcp-session-id",
5301
+ "mcp-protocol-version",
5302
+ "mcp-method",
5303
+ "mcp-name",
5304
+ ].includes(key.toLowerCase())
5305
+ )
5306
+ delete headers[key];
5307
+ }
5308
+ Object.assign(headers, modern.headers);
5309
+ }
4736
5310
 
4737
5311
  // Every request owns a controller so caller cancellation and disconnect
4738
5312
  // remain enforceable even when its optional deadline is disabled.
@@ -4855,6 +5429,7 @@ export class MCPClient extends EventEmitter {
4855
5429
  ? response.headers.get("mcp-session-id") ||
4856
5430
  response.headers.get("Mcp-Session-Id")
4857
5431
  : null) || null;
5432
+ if (sessionId && entry.statelessHttp) throw mcpRpcInvalidResponseError();
4858
5433
  if (sessionId && !entry.httpSessionId) {
4859
5434
  entry.httpSessionId = sessionId;
4860
5435
  }
@@ -4925,7 +5500,18 @@ export class MCPClient extends EventEmitter {
4925
5500
  response,
4926
5501
  id,
4927
5502
  cap,
4928
- (message) => this._handleMessage(serverName, message, entry),
5503
+ (message) =>
5504
+ entry.statelessHttp
5505
+ ? this._handleStatelessProgress(
5506
+ serverName,
5507
+ entry,
5508
+ message,
5509
+ safeRpcProperty(
5510
+ safeRpcProperty(params, "_meta"),
5511
+ "progressToken",
5512
+ ),
5513
+ )
5514
+ : this._handleMessage(serverName, message, entry),
4929
5515
  controller?.signal,
4930
5516
  (text) => parseMcpJson(text, serverName, entry),
4931
5517
  );
@@ -4957,6 +5543,18 @@ export class MCPClient extends EventEmitter {
4957
5543
  if (wire.hasError) {
4958
5544
  throw mcpRpcError(wire.error);
4959
5545
  }
5546
+ if (
5547
+ entry.statelessHttp &&
5548
+ (!wire.result ||
5549
+ (wire.result.resultType !== "complete" &&
5550
+ !(method === "tools/call" && wire.result.resultType === "task")))
5551
+ ) {
5552
+ throw mcpTaskError(
5553
+ "CC_MCP_STATELESS_RESULT_UNSUPPORTED",
5554
+ "MCP result requires an unsupported continuation; no request was replayed",
5555
+ true,
5556
+ );
5557
+ }
4960
5558
  throwIfAborted();
4961
5559
  if (!settleLifecycle("completed")) {
4962
5560
  throw this._staleLifecycleCallbackError();
@@ -4994,7 +5592,13 @@ export class MCPClient extends EventEmitter {
4994
5592
  /** Fire-and-forget JSON-RPC notification over HTTP. Errors swallowed. */
4995
5593
  _sendHttpNotification(serverName, method, params) {
4996
5594
  const entry = this.servers.get(serverName);
4997
- if (!entry || !entry.httpUrl || entry._httpDiscardStopping) return;
5595
+ if (
5596
+ !entry ||
5597
+ !entry.httpUrl ||
5598
+ entry._httpDiscardStopping ||
5599
+ entry.statelessHttp
5600
+ )
5601
+ return;
4998
5602
  const body = JSON.stringify({ jsonrpc: "2.0", method, params });
4999
5603
  const headers = {
5000
5604
  "Content-Type": "application/json",
@@ -5206,10 +5810,55 @@ export class MCPClient extends EventEmitter {
5206
5810
  return error;
5207
5811
  }
5208
5812
 
5813
+ _handleStatelessProgress(serverName, entry, message, expectedToken) {
5814
+ if (this.servers.get(serverName) !== entry)
5815
+ throw this._staleLifecycleCallbackError();
5816
+ const wire = snapshotRpcMessage(message);
5817
+ // Stateless requests advertise no reverse-RPC or subscription authority.
5818
+ // Reject the whole response before dispatching an unexpected SSE envelope;
5819
+ // a later tool result cannot erase callbacks or data already sent to a peer.
5820
+ if (
5821
+ !wire ||
5822
+ !wire.hasJsonrpc ||
5823
+ wire.jsonrpc !== "2.0" ||
5824
+ wire.hasId ||
5825
+ wire.hasResult ||
5826
+ wire.hasError ||
5827
+ !wire.hasMethod ||
5828
+ wire.method !== "notifications/progress" ||
5829
+ typeof expectedToken !== "string" ||
5830
+ expectedToken.length === 0 ||
5831
+ safeRpcProperty(wire.params, "progressToken") !== expectedToken
5832
+ )
5833
+ throw unsupportedStatelessClientRequest();
5834
+ this._handleToolProgress(serverName, wire.params);
5835
+ }
5836
+
5837
+ _handleToolProgress(serverName, params) {
5838
+ const progressToken = safeRpcProperty(params, "progressToken");
5839
+ const resetIdle =
5840
+ typeof progressToken === "string"
5841
+ ? this._toolProgress.get(progressToken)
5842
+ : null;
5843
+ if (resetIdle) resetIdle();
5844
+ // Peer status text is tool data, not host diagnostics or interaction.
5845
+ this.emit("tool-progress", {
5846
+ server: serverName,
5847
+ ...(typeof progressToken === "string" ? { progressToken } : {}),
5848
+ ...(Number.isFinite(safeRpcProperty(params, "progress"))
5849
+ ? { progress: safeRpcProperty(params, "progress") }
5850
+ : {}),
5851
+ ...(Number.isFinite(safeRpcProperty(params, "total"))
5852
+ ? { total: safeRpcProperty(params, "total") }
5853
+ : {}),
5854
+ });
5855
+ }
5856
+
5209
5857
  _handleMessage(serverName, msg, sourceEntry = null) {
5210
5858
  const currentEntry = this.servers.get(serverName);
5211
5859
  const entry = sourceEntry || currentEntry;
5212
- if (!entry) return;
5860
+ // HTTP stateless progress has a separate request-correlated admission path.
5861
+ if (!entry || entry.statelessHttp) return;
5213
5862
  if (sourceEntry && currentEntry !== sourceEntry) {
5214
5863
  const wire = snapshotRpcMessage(msg);
5215
5864
  if (wire?.hasId && !wire.hasMethod) {
@@ -5339,24 +5988,7 @@ export class MCPClient extends EventEmitter {
5339
5988
  this._refreshServerList(serverName, "resources");
5340
5989
  this._refreshServerList(serverName, "resourceTemplates");
5341
5990
  } else if (wire.method === "notifications/progress") {
5342
- const progressToken = safeRpcProperty(wire.params, "progressToken");
5343
- const resetIdle =
5344
- typeof progressToken === "string"
5345
- ? this._toolProgress.get(progressToken)
5346
- : null;
5347
- if (resetIdle) resetIdle();
5348
- // Project only numeric progress. Server-controlled status text belongs
5349
- // to the tool result, not host diagnostics/events.
5350
- this.emit("tool-progress", {
5351
- server: serverName,
5352
- ...(typeof progressToken === "string" ? { progressToken } : {}),
5353
- ...(Number.isFinite(safeRpcProperty(wire.params, "progress"))
5354
- ? { progress: safeRpcProperty(wire.params, "progress") }
5355
- : {}),
5356
- ...(Number.isFinite(safeRpcProperty(wire.params, "total"))
5357
- ? { total: safeRpcProperty(wire.params, "total") }
5358
- : {}),
5359
- });
5991
+ this._handleToolProgress(serverName, wire.params);
5360
5992
  } else if (wire.method === "notifications/resources/updated") {
5361
5993
  this.emit("resource-updated", {
5362
5994
  server: serverName,
@@ -5487,6 +6119,7 @@ export class MCPClient extends EventEmitter {
5487
6119
  * method-not-found error instead of silence, so the server fails fast.
5488
6120
  */
5489
6121
  _handleServerRequest(serverName, msg) {
6122
+ if (this.servers.get(serverName)?.statelessHttp) return;
5490
6123
  const { id, method } = msg;
5491
6124
  if (method === "roots/list") {
5492
6125
  this._sendResponse(serverName, id, { roots: this.listRoots() });
@@ -5516,7 +6149,7 @@ export class MCPClient extends EventEmitter {
5516
6149
  /** Write a JSON-RPC response back over stdio or Streamable HTTP POST. */
5517
6150
  _sendResponse(serverName, id, result, error) {
5518
6151
  const entry = this.servers.get(serverName);
5519
- if (!entry || entry._httpDiscardStopping) return;
6152
+ if (!entry || entry._httpDiscardStopping || entry.statelessHttp) return;
5520
6153
  const envelope =
5521
6154
  error !== undefined
5522
6155
  ? { jsonrpc: "2.0", id, error }
@@ -6105,6 +6738,7 @@ export class MCPServerConfig {
6105
6738
  transport TEXT DEFAULT 'stdio',
6106
6739
  headers TEXT DEFAULT '{}',
6107
6740
  headers_helper TEXT,
6741
+ protocol_version TEXT,
6108
6742
  config_scope TEXT DEFAULT 'user',
6109
6743
  config_source TEXT,
6110
6744
  project_path TEXT,
@@ -6153,6 +6787,11 @@ export class MCPServerConfig {
6153
6787
  if (!cols.has("headers_helper")) {
6154
6788
  this.db.exec("ALTER TABLE mcp_servers ADD COLUMN headers_helper TEXT");
6155
6789
  }
6790
+ if (!cols.has("protocol_version")) {
6791
+ this.db.exec(
6792
+ "ALTER TABLE mcp_servers ADD COLUMN protocol_version TEXT",
6793
+ );
6794
+ }
6156
6795
  if (!cols.has("config_scope")) {
6157
6796
  this.db.exec(
6158
6797
  "ALTER TABLE mcp_servers ADD COLUMN config_scope TEXT DEFAULT 'user'",
@@ -6228,6 +6867,11 @@ export class MCPServerConfig {
6228
6867
  const existingRow = this.db
6229
6868
  .prepare("SELECT * FROM mcp_servers WHERE name = ?")
6230
6869
  .get(storageName);
6870
+ const protocolVersion =
6871
+ config.protocolVersion === undefined
6872
+ ? (existingRow?.protocol_version ?? null)
6873
+ : config.protocolVersion;
6874
+ mcpProtocolVersionField({ ...config, protocolVersion });
6231
6875
  const cwdUpdate = readMcpStdioCwd(config, {
6232
6876
  label: `MCP server "${name}"`,
6233
6877
  });
@@ -6250,7 +6894,7 @@ export class MCPServerConfig {
6250
6894
  }
6251
6895
  this.db
6252
6896
  .prepare(
6253
- "INSERT OR REPLACE INTO mcp_servers (name, command, args, env, runtime_kind, cwd, sandbox_policy, auto_connect, url, transport, headers, headers_helper, config_scope, config_source, project_path, display_name, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, datetime('now'))",
6897
+ "INSERT OR REPLACE INTO mcp_servers (name, command, args, env, runtime_kind, cwd, sandbox_policy, auto_connect, url, transport, headers, headers_helper, protocol_version, config_scope, config_source, project_path, display_name, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, datetime('now'))",
6254
6898
  )
6255
6899
  .run(
6256
6900
  storageName,
@@ -6265,6 +6909,7 @@ export class MCPServerConfig {
6265
6909
  transport,
6266
6910
  JSON.stringify(config.headers || {}),
6267
6911
  headersHelper,
6912
+ protocolVersion,
6268
6913
  configScope,
6269
6914
  configSource,
6270
6915
  projectPath,
@@ -6332,6 +6977,11 @@ export class MCPServerConfig {
6332
6977
  transport:
6333
6978
  row.transport || (row.url ? inferTransport({ url: row.url }) : "stdio"),
6334
6979
  headers: safeJsonParse(row.headers, {}),
6980
+ ...mcpProtocolVersionField({
6981
+ protocolVersion: row.protocol_version,
6982
+ url: row.url,
6983
+ transport: row.transport,
6984
+ }),
6335
6985
  ...(typeof row.headers_helper === "string" && row.headers_helper.trim()
6336
6986
  ? { headersHelper: row.headers_helper }
6337
6987
  : {}),