chainlesschain 0.166.9 → 0.166.13

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 (232) hide show
  1. package/README.md +33 -0
  2. package/bin/chainlesschain.js +5 -0
  3. package/package.json +5 -2
  4. package/src/assets/web-panel/assets/{AIOps-DJvpifGx.js → AIOps-BN25cNOD.js} +1 -1
  5. package/src/assets/web-panel/assets/{ActionButton-D2UhuF_A.js → ActionButton-Da9IP-m5.js} +1 -1
  6. package/src/assets/web-panel/assets/{Analytics-C9ho9obu.js → Analytics-D7hkEvQm.js} +3 -3
  7. package/src/assets/web-panel/assets/{AppLayout-BvRCpFK3.js → AppLayout-CCV4Xnbc.js} +5 -5
  8. package/src/assets/web-panel/assets/{Artifacts-jxrySvpk.js → Artifacts-CVSnVJeA.js} +1 -1
  9. package/src/assets/web-panel/assets/{Audit-ovEw0ZYl.js → Audit-CuYdw5Ag.js} +1 -1
  10. package/src/assets/web-panel/assets/{BackgroundAgents-D7H5z6zS.js → BackgroundAgents-DZCnK-Tf.js} +1 -1
  11. package/src/assets/web-panel/assets/{Backup-BuXob8za.js → Backup-cV9FdpTy.js} +1 -1
  12. package/src/assets/web-panel/assets/{BaseInput-CtnszuQ2.js → BaseInput-BRnv6YSp.js} +1 -1
  13. package/src/assets/web-panel/assets/{Chat-B_mYE8fJ.js → Chat-Bw5w87P4.js} +6 -6
  14. package/src/assets/web-panel/assets/ChatBubbleRenderer-C0GjtUAw.js +1 -0
  15. package/src/assets/web-panel/assets/{Checkbox-ierdtcJD.js → Checkbox-DaoTqcdt.js} +1 -1
  16. package/src/assets/web-panel/assets/{Codegen-3VKPJD_B.js → Codegen-B4dYcEIi.js} +1 -1
  17. package/src/assets/web-panel/assets/{Col-1EdMyf5P.js → Col-mAhuOeuD.js} +1 -1
  18. package/src/assets/web-panel/assets/{Community-D6H7UA8K.js → Community-BK6KEdBk.js} +1 -1
  19. package/src/assets/web-panel/assets/{Compact-BBAZvYIm.js → Compact-CCglmNu5.js} +1 -1
  20. package/src/assets/web-panel/assets/{Compliance-CgsTrAoj.js → Compliance-Cm8S4of7.js} +1 -1
  21. package/src/assets/web-panel/assets/{Cowork-tnZgLoTE.js → Cowork-Dhs1QLMe.js} +3 -3
  22. package/src/assets/web-panel/assets/{Cron-CPpZw2Nh.js → Cron-CLlhmXWk.js} +2 -2
  23. package/src/assets/web-panel/assets/{Crosschain-BymBcp5z.js → Crosschain-BnHVbaNs.js} +1 -1
  24. package/src/assets/web-panel/assets/{DID-DKPxS_K1.js → DID-UzQP9-0O.js} +2 -2
  25. package/src/assets/web-panel/assets/{Dashboard-DvJhEmH9.js → Dashboard-CBdlPClz.js} +2 -2
  26. package/src/assets/web-panel/assets/{Dropdown-b8iQyQIZ.js → Dropdown-axIRPdq1.js} +1 -1
  27. package/src/assets/web-panel/assets/{EmailListRenderer--0-A-zKb.js → EmailListRenderer-DUalW5rx.js} +1 -1
  28. package/src/assets/web-panel/assets/{FamilyGuardDashboard-C12iDN06.js → FamilyGuardDashboard-Bl4W9luY.js} +1 -1
  29. package/src/assets/web-panel/assets/{Federation-BRhaE2Z8.js → Federation-C1yP-uEu.js} +1 -1
  30. package/src/assets/web-panel/assets/{FormItemContext-C4dnq7yf.js → FormItemContext-Xh6Ig5q8.js} +1 -1
  31. package/src/assets/web-panel/assets/{GenericCardRenderer-CGAdbR5n.js → GenericCardRenderer-C2cz3bt2.js} +1 -1
  32. package/src/assets/web-panel/assets/{Git-4eA2fYzL.js → Git-C_z63ixg.js} +2 -2
  33. package/src/assets/web-panel/assets/{Governance-BJuY9Y-9.js → Governance-BYqB33_3.js} +1 -1
  34. package/src/assets/web-panel/assets/{Inference-DZ5Dy4up.js → Inference-CEULuArm.js} +1 -1
  35. package/src/assets/web-panel/assets/{KnowledgeGraph-BMTjRs4A.js → KnowledgeGraph-fgMsu-0H.js} +1 -1
  36. package/src/assets/web-panel/assets/{Logs-BKEeQEfJ.js → Logs-DO9Hdcec.js} +2 -2
  37. package/src/assets/web-panel/assets/MarkdownRenderer-BkrK04xW.js +1 -0
  38. package/src/assets/web-panel/assets/{Marketplace-Dhho4fEg.js → Marketplace-B8zyLiFe.js} +1 -1
  39. package/src/assets/web-panel/assets/{McpTools-BW6xxSlU.js → McpTools-BLAN2mWW.js} +3 -3
  40. package/src/assets/web-panel/assets/{Memory-mPqlpSkq.js → Memory-CrQcFM7u.js} +2 -2
  41. package/src/assets/web-panel/assets/{MobileBridge-Cb9N_DQI.js → MobileBridge-DVnyiiU-.js} +1 -1
  42. package/src/assets/web-panel/assets/{MobileProjects-BNs8tah_.js → MobileProjects-qjCME5OD.js} +1 -1
  43. package/src/assets/web-panel/assets/{Mtc-CaxBt8tn.js → Mtc-4JE3C3It.js} +2 -2
  44. package/src/assets/web-panel/assets/{MtcAudit-DRPQbp3t.js → MtcAudit-CjBuak9I.js} +5 -5
  45. package/src/assets/web-panel/assets/{Multisig-CRm-d8bK.js → Multisig-BtPcYQcC.js} +3 -3
  46. package/src/assets/web-panel/assets/{NLProgramming-BCCk3LPs.js → NLProgramming-Cx653_Ba.js} +1 -1
  47. package/src/assets/web-panel/assets/{Notes-Cv8SN8gN.js → Notes-CkuD3YzS.js} +4 -4
  48. package/src/assets/web-panel/assets/{NotificationSettings-CggIvTh5.js → NotificationSettings-BgNgU7HH.js} +1 -1
  49. package/src/assets/web-panel/assets/{OrderTableRenderer-BW3_bV12.js → OrderTableRenderer-BTC8W0a-.js} +1 -1
  50. package/src/assets/web-panel/assets/{Organization-BuRE-VCO.js → Organization-Dmd4Hjxz.js} +4 -4
  51. package/src/assets/web-panel/assets/{Overflow-DBrm1gju.js → Overflow-C_5DA-G0.js} +1 -1
  52. package/src/assets/web-panel/assets/{P2P-CWVnDYgS.js → P2P-uwslV4XC.js} +2 -2
  53. package/src/assets/web-panel/assets/{PdhVaultBrowser-8RKUIpte.js → PdhVaultBrowser-CuNgwVnX.js} +5 -5
  54. package/src/assets/web-panel/assets/{Permissions-tDUAxogW.js → Permissions-CJayVX9H.js} +4 -4
  55. package/src/assets/web-panel/assets/{PersonalDataHub-Dv2-CFis.js → PersonalDataHub-Cb05H5go.js} +4 -4
  56. package/src/assets/web-panel/assets/{Pipeline-DM6kvFni.js → Pipeline-BZlGKapZ.js} +1 -1
  57. package/src/assets/web-panel/assets/{Privacy-DzK-yL0d.js → Privacy-BIzZWYzd.js} +1 -1
  58. package/src/assets/web-panel/assets/{ProjectInit-B5UrNpkj.js → ProjectInit-vEYYyQXQ.js} +2 -2
  59. package/src/assets/web-panel/assets/{ProjectSettings-CxJD43oW.js → ProjectSettings-MZqTy5CC.js} +2 -2
  60. package/src/assets/web-panel/assets/Projects-CRARUOl8.js +1 -0
  61. package/src/assets/web-panel/assets/{Providers-CYl4jRYK.js → Providers-80VAK8PX.js} +1 -1
  62. package/src/assets/web-panel/assets/{QrScannerModal-DeH2T0fH.js → QrScannerModal-CzRSoIwK.js} +1 -1
  63. package/src/assets/web-panel/assets/{QuickAsk-Bw9k_kTk.js → QuickAsk-BpwQ2n4C.js} +1 -1
  64. package/src/assets/web-panel/assets/{Recommend-Bl_jGwoi.js → Recommend-BC03TZ79.js} +1 -1
  65. package/src/assets/web-panel/assets/{RemoteSession-d6u01Kq0.js → RemoteSession-DE59-jaa.js} +2 -2
  66. package/src/assets/web-panel/assets/{Reputation-Ds_Dfr-k.js → Reputation-DOHmeWyA.js} +1 -1
  67. package/src/assets/web-panel/assets/{Row-BpQUQTNj.js → Row-hc5RZl1D.js} +1 -1
  68. package/src/assets/web-panel/assets/{RssFeed-BatpZBGt.js → RssFeed-Cv5uMP7E.js} +3 -3
  69. package/src/assets/web-panel/assets/{Search-D7hOObzi.js → Search-qohu7Ug0.js} +1 -1
  70. package/src/assets/web-panel/assets/{Security-dXQ4FKNt.js → Security-drCPFWV5.js} +4 -4
  71. package/src/assets/web-panel/assets/{Services-D8wInGPa.js → Services-BAEgUeRy.js} +2 -2
  72. package/src/assets/web-panel/assets/{Skeleton-DXQCoYpM.js → Skeleton-CkJkKBlo.js} +1 -1
  73. package/src/assets/web-panel/assets/{Skills-D3oLRIVn.js → Skills-bMuKEpez.js} +1 -1
  74. package/src/assets/web-panel/assets/{Sla-BmP4-LnJ.js → Sla-DxWQVHRC.js} +1 -1
  75. package/src/assets/web-panel/assets/{SpeechSettings-DLj-xzro.js → SpeechSettings-BpS8idmV.js} +1 -1
  76. package/src/assets/web-panel/assets/{SyncSettings-8KKaaRMr.js → SyncSettings-BPBLlW5v.js} +2 -2
  77. package/src/assets/web-panel/assets/{Tasks-GyK42I7C.js → Tasks-C4SLEeUh.js} +1 -1
  78. package/src/assets/web-panel/assets/{Templates-n1y_8UBG.js → Templates-r-wfU39U.js} +1 -1
  79. package/src/assets/web-panel/assets/{Tenant-B39nBph8.js → Tenant-C7vjRmLN.js} +1 -1
  80. package/src/assets/web-panel/assets/{Terminal-DCQoOKXe.js → Terminal-DdzeFCV2.js} +2 -2
  81. package/src/assets/web-panel/assets/{TimelineRenderer-BkhbDfXk.js → TimelineRenderer-CYyWN2KD.js} +1 -1
  82. package/src/assets/web-panel/assets/{Tokens-BeHIIU8D.js → Tokens-D8A9osUg.js} +1 -1
  83. package/src/assets/web-panel/assets/{Trigger-BHvWXVOb.js → Trigger-DBvrNlyS.js} +1 -1
  84. package/src/assets/web-panel/assets/{Trust-y2WaOSto.js → Trust-DBVAGc7o.js} +1 -1
  85. package/src/assets/web-panel/assets/{UkeySign-DBFeJBzt.js → UkeySign-C1vQUCRJ.js} +1 -1
  86. package/src/assets/web-panel/assets/{VideoEditing-BEOWitC-.js → VideoEditing-BKs4dah4.js} +1 -1
  87. package/src/assets/web-panel/assets/{Wallet-BITedTe6.js → Wallet-ByIuj3lD.js} +4 -4
  88. package/src/assets/web-panel/assets/{WebAuthn-DMwlJVin.js → WebAuthn-DYlAFCm9.js} +3 -3
  89. package/src/assets/web-panel/assets/{WorkflowEditor-CKfGFEu1.js → WorkflowEditor-Dwyadd0c.js} +1 -1
  90. package/src/assets/web-panel/assets/{chat-DR6gnBGF.js → chat-Bm2f3s08.js} +1 -1
  91. package/src/assets/web-panel/assets/{colors-C_Hw5NCn.js → colors-C8ORSh7V.js} +1 -1
  92. package/src/assets/web-panel/assets/{compact-item-B8IPwsEu.js → compact-item-1iVlnsM-.js} +1 -1
  93. package/src/assets/web-panel/assets/{createContext-D-u4JVnJ.js → createContext-CmqNyUSL.js} +1 -1
  94. package/src/assets/web-panel/assets/devWarning-B69RCDDH.js +1 -0
  95. package/src/assets/web-panel/assets/{hasIn-CZubdS4D.js → hasIn-rUMaX3Ul.js} +1 -1
  96. package/src/assets/web-panel/assets/index-9biMQ-tw.js +1 -0
  97. package/src/assets/web-panel/assets/{index-C25rOz7O.js → index-B53c3diB.js} +1 -1
  98. package/src/assets/web-panel/assets/{index-CfniPP5p.js → index-B59OWAs7.js} +1 -1
  99. package/src/assets/web-panel/assets/{index-11ASqx-A.js → index-B8BrB0Ls.js} +1 -1
  100. package/src/assets/web-panel/assets/{index-auyNYjLo.js → index-BC32_0xT.js} +1 -1
  101. package/src/assets/web-panel/assets/{index-Ctje8Vl3.js → index-BC8Wb6cy.js} +1 -1
  102. package/src/assets/web-panel/assets/{index-Cg2bCeol.js → index-BCOhTILd.js} +1 -1
  103. package/src/assets/web-panel/assets/{index-D1w96gg9.js → index-BFniLMn9.js} +1 -1
  104. package/src/assets/web-panel/assets/{index-k1Xa5iw1.js → index-BIvM-uAX.js} +1 -1
  105. package/src/assets/web-panel/assets/{index-DuOU5apg.js → index-BK-RY0-7.js} +1 -1
  106. package/src/assets/web-panel/assets/{index-D47jt8ET.js → index-BQL9r73Y.js} +1 -1
  107. package/src/assets/web-panel/assets/{index-C2VmtNaQ.js → index-BVtnizyC.js} +1 -1
  108. package/src/assets/web-panel/assets/{index-Bizm87cX.js → index-Bf1PlIHp.js} +1 -1
  109. package/src/assets/web-panel/assets/{index-Dt-w3xQ7.js → index-Bgw4Y2rU.js} +1 -1
  110. package/src/assets/web-panel/assets/{index-ffe7bvqP.js → index-BgwLNxmr.js} +1 -1
  111. package/src/assets/web-panel/assets/{index-Cl5RpreD.js → index-C-J5-pGH.js} +1 -1
  112. package/src/assets/web-panel/assets/{index-idZKyADQ.js → index-C-ZIHi42.js} +1 -1
  113. package/src/assets/web-panel/assets/{index-LvjAKDSl.js → index-C3B1S-mW.js} +1 -1
  114. package/src/assets/web-panel/assets/{index-DmRcgiYT.js → index-C5RfRciU.js} +1 -1
  115. package/src/assets/web-panel/assets/{index-rYBHSDcJ.js → index-CCEyz58d.js} +1 -1
  116. package/src/assets/web-panel/assets/index-COie87kl.js +1 -0
  117. package/src/assets/web-panel/assets/{index-DcFjRT-K.js → index-CTfEmKK0.js} +1 -1
  118. package/src/assets/web-panel/assets/{index-DjRrqooR.js → index-CfiHyVyl.js} +1 -1
  119. package/src/assets/web-panel/assets/{index-DpjHpRoq.js → index-CkFvuAex.js} +3 -3
  120. package/src/assets/web-panel/assets/{index-BzoFanEQ.js → index-D98FXb0w.js} +1 -1
  121. package/src/assets/web-panel/assets/{index-Cbm8F0M2.js → index-DDHk911Q.js} +1 -1
  122. package/src/assets/web-panel/assets/{index-BXS6wYJZ.js → index-DJxtPFOh.js} +1 -1
  123. package/src/assets/web-panel/assets/{index-DY6MHo9D.js → index-DVJ1uKf4.js} +1 -1
  124. package/src/assets/web-panel/assets/{index-CiXkhOkY.js → index-Dcck8QfW.js} +1 -1
  125. package/src/assets/web-panel/assets/{index-mYZJxGH6.js → index-DgUE51Pz.js} +1 -1
  126. package/src/assets/web-panel/assets/{index-CqmLw8cs.js → index-Dsve5Gkv.js} +1 -1
  127. package/src/assets/web-panel/assets/{index-xoNssgz_.js → index-DvedhJeM.js} +1 -1
  128. package/src/assets/web-panel/assets/{index-DfnzrUxU.js → index-DwMdWKiF.js} +1 -1
  129. package/src/assets/web-panel/assets/{index-Bi21Etg4.js → index-OcbzdRpT.js} +1 -1
  130. package/src/assets/web-panel/assets/{index-DJ6pG79m.js → index-fPK6GFEg.js} +1 -1
  131. package/src/assets/web-panel/assets/{index-_nL79NT8.js → index-geQinnns.js} +1 -1
  132. package/src/assets/web-panel/assets/{index-DTosx2Wu.js → index-pHWA7bmM.js} +1 -1
  133. package/src/assets/web-panel/assets/{index-cVqbas5C.js → index-reUHhuz8.js} +1 -1
  134. package/src/assets/web-panel/assets/{index-Bv2132PO.js → index-tqTx5wXo.js} +1 -1
  135. package/src/assets/web-panel/assets/{initDefaultProps-lcU_dT2r.js → initDefaultProps-CuA-cpkL.js} +1 -1
  136. package/src/assets/web-panel/assets/{motion-Dc7UNXZ1.js → motion-CimmE_9b.js} +1 -1
  137. package/src/assets/web-panel/assets/{move-Cll8ZXaL.js → move-DlGlrltz.js} +1 -1
  138. package/src/assets/web-panel/assets/{mtc-parser-CAb_yLIM.js → mtc-parser-CK6BJQ07.js} +1 -1
  139. package/src/assets/web-panel/assets/{omit-DurYMyTe.js → omit-BKjBfZfB.js} +1 -1
  140. package/src/assets/web-panel/assets/{pickAttrs-BITQyOlw.js → pickAttrs-B2chVYw9.js} +1 -1
  141. package/src/assets/web-panel/assets/{placementArrow-Dg1rH91i.js → placementArrow-BW8aLJJ3.js} +1 -1
  142. package/src/assets/web-panel/assets/{responsiveObserve-D_EWIeac.js → responsiveObserve-dXlPl66S.js} +1 -1
  143. package/src/assets/web-panel/assets/{slide-lK4d3zsh.js → slide-hSa89S4G.js} +1 -1
  144. package/src/assets/web-panel/assets/{statusUtils-Bflq-Git.js → statusUtils-DM6KLt-s.js} +1 -1
  145. package/src/assets/web-panel/assets/{styleChecker-Ccp0I-wt.js → styleChecker-C9MQAK15.js} +1 -1
  146. package/src/assets/web-panel/assets/{useFlexGapSupport-CYZbByYA.js → useFlexGapSupport-BpQDpP0z.js} +1 -1
  147. package/src/assets/web-panel/assets/{useFs-B_x0nxFD.js → useFs-C7rtRViA.js} +1 -1
  148. package/src/assets/web-panel/assets/{usePersonalDataHub-DW55rL85.js → usePersonalDataHub-Dm15xafq.js} +1 -1
  149. package/src/assets/web-panel/assets/{vnode-Ca6MH3W8.js → vnode-mEiEytw4.js} +1 -1
  150. package/src/assets/web-panel/assets/{zoom-NdHelOog.js → zoom-DzPxflhY.js} +1 -1
  151. package/src/assets/web-panel/index.html +1 -1
  152. package/src/command-help-index.json +5 -5
  153. package/src/commands/agent.js +51 -20
  154. package/src/commands/compact.js +349 -3
  155. package/src/commands/context.js +72 -1
  156. package/src/commands/graph.js +26 -15
  157. package/src/commands/hmemory.js +21 -0
  158. package/src/commands/hook.js +256 -28
  159. package/src/commands/memory.js +209 -42
  160. package/src/commands/promcomp.js +17 -0
  161. package/src/commands/serve.js +94 -10
  162. package/src/commands/session.js +2 -3
  163. package/src/commands/team.js +7 -1
  164. package/src/data/changelog.json +41 -2
  165. package/src/gateways/ws/session-core-protocol.js +62 -3
  166. package/src/gateways/ws/session-protocol.js +123 -15
  167. package/src/gateways/ws/ws-agent-handler.js +157 -9
  168. package/src/gateways/ws/ws-session-gateway.js +204 -30
  169. package/src/generated/cc-agent-protocol.schema.json +2094 -4
  170. package/src/harness/prompt-compressor.js +5 -55
  171. package/src/lib/agent-sandbox.js +14 -4
  172. package/src/lib/agent-team/team-distributed-graph-bridge.js +3 -3
  173. package/src/lib/app-server/context-memory-notifications.js +54 -0
  174. package/src/lib/app-server/rollout-store-factory.js +115 -0
  175. package/src/lib/app-server/rollout-store.js +310 -23
  176. package/src/lib/app-server/server.js +184 -7
  177. package/src/lib/app-server/sqlite-rollout-store.js +59 -16
  178. package/src/lib/auto-mode-config.js +26 -0
  179. package/src/lib/causal-observability.js +13 -1
  180. package/src/lib/context-memory-kernel/authority.js +95 -0
  181. package/src/lib/context-memory-kernel/durable-memory-port.js +296 -0
  182. package/src/lib/context-memory-kernel/index.js +8 -0
  183. package/src/lib/context-memory-kernel/jsonl-session-context-port.js +232 -0
  184. package/src/lib/context-memory-kernel/live-compaction.js +375 -0
  185. package/src/lib/context-memory-kernel/memory-service.js +667 -0
  186. package/src/lib/context-memory-kernel/message-adapter.js +451 -0
  187. package/src/lib/context-memory-kernel/privacy-purge-port.js +244 -0
  188. package/src/lib/context-memory-kernel/provider-context.js +192 -0
  189. package/src/lib/context-memory-kernel/runtime.js +61 -0
  190. package/src/lib/direct-model-usage.js +22 -18
  191. package/src/lib/graph-kernel/cutover-authority-resolver.js +4 -5
  192. package/src/lib/graph-kernel/cutover-ledger.js +2 -2
  193. package/src/lib/graph-kernel/event-store.js +3 -5
  194. package/src/lib/graph-kernel/index.js +2 -0
  195. package/src/lib/graph-kernel/migration-saga.js +2 -2
  196. package/src/lib/graph-kernel/production-cutover-evidence.js +976 -0
  197. package/src/lib/graph-kernel/retirement-evidence.js +12 -4
  198. package/src/lib/hierarchical-memory.js +22 -0
  199. package/src/lib/hook-audit-store.js +170 -0
  200. package/src/lib/hook-event-bus.cjs +0 -0
  201. package/src/lib/hook-manager.js +25 -83
  202. package/src/lib/hook-runtime-adapters.js +233 -0
  203. package/src/lib/hook-runtime-contract.cjs +291 -0
  204. package/src/lib/hook-runtime-contract.js +21 -0
  205. package/src/lib/hook-trust.js +210 -0
  206. package/src/lib/hooks-v2-producers.js +52 -6
  207. package/src/lib/hooks-v2-runtime.js +443 -178
  208. package/src/lib/llm-pricing.js +10 -0
  209. package/src/lib/memory-manager.js +29 -4
  210. package/src/lib/model-context-window.js +52 -0
  211. package/src/lib/permanent-memory.js +17 -0
  212. package/src/lib/plan-mode.js +8 -4
  213. package/src/lib/process-execution-broker/index.js +208 -16
  214. package/src/lib/runtime-usage-ledger.js +20 -0
  215. package/src/lib/session-consolidator.js +59 -0
  216. package/src/lib/session-core-singletons.js +17 -4
  217. package/src/lib/session-hooks.js +29 -2
  218. package/src/lib/session-transcript-migration.js +188 -0
  219. package/src/lib/settings-hook-events.cjs +37 -401
  220. package/src/lib/settings-hook-events.js +210 -8
  221. package/src/lib/settings-hooks.cjs +42 -83
  222. package/src/lib/ws-session-manager.js +4 -1
  223. package/src/repl/agent-repl.js +186 -53
  224. package/src/runtime/agent-core.js +376 -350
  225. package/src/runtime/headless-runner.js +40 -33
  226. package/src/runtime/headless-stream.js +131 -30
  227. package/src/assets/web-panel/assets/ChatBubbleRenderer-DaiA6CsX.js +0 -1
  228. package/src/assets/web-panel/assets/MarkdownRenderer-B05DgASC.js +0 -1
  229. package/src/assets/web-panel/assets/Projects-Z2Orm8Ma.js +0 -1
  230. package/src/assets/web-panel/assets/devWarning-Cq6lSd_q.js +0 -1
  231. package/src/assets/web-panel/assets/index-BQ3213fz.js +0 -1
  232. package/src/assets/web-panel/assets/index-vJagfET2.js +0 -1
@@ -1,6 +1,45 @@
1
1
  {
2
2
  "source": "CHANGELOG.md",
3
3
  "releases": [
4
+ {
5
+ "productVersion": null,
6
+ "cliVersion": "0.166.13",
7
+ "cliVersions": ["0.3.8", "0.166.12", "0.166.13"],
8
+ "date": "2026-08-30",
9
+ "title": "",
10
+ "sections": [
11
+ {
12
+ "heading": "Fixed - cc CLI 0.166.13 and Session Core 0.3.8: fail-closed P0 security closure",
13
+ "body": "> `chainlesschain` **0.166.12 -> 0.166.13** and Session Core\n> **0.3.7 -> 0.3.8** (release candidates, 2026-08-30).\n\n- **Fixed renderer IPC capabilities**: remove the environment-controlled\n generic bridge bypass and generate an exact renderer/main capability\n manifest that fails the Desktop build when it drifts.\n- **Default sandbox and approval boundary**: restore workspace-write with\n network disabled as the CLI default, deny shell execution when the approval\n gate is unavailable, and fail closed when approval policy loading or\n persistence fails.\n- **Durable process audit**: require a persistent, redacted admission record\n before high-risk process creation and retain bounded actor, session,\n authorization, policy, sandbox, and result context.\n- **Release boundary**: these versions identify the source candidates for the\n security fixes; publication still requires the exact candidate to pass the\n repository's Linux, Windows, and macOS release matrices."
14
+ }
15
+ ]
16
+ },
17
+ {
18
+ "productVersion": null,
19
+ "cliVersion": "0.166.12",
20
+ "cliVersions": ["0.166.10", "0.166.12"],
21
+ "date": "2026-08-30",
22
+ "title": "",
23
+ "sections": [
24
+ {
25
+ "heading": "Added - cc CLI 0.166.12: durable rollout storage and converged Hooks v2",
26
+ "body": "> `chainlesschain` **0.166.10 -> 0.166.12** (release candidate,\n> 2026-08-30). The immutable `0.166.11` candidate was withheld after its npm\n> workflow could not bootstrap the new scoped runtime dependency; its tag is\n> not reused. Coordinated candidates are Context/Memory Kernel `0.1.0`,\n> Session Core `0.3.7`, Agent Protocol `0.1.7`, TypeScript Agent SDK `0.2.7`,\n> Python Agent SDK `0.2.7`, VS Code `0.37.75`, and JetBrains `0.4.105`.\n\n- **Canonical context planning**: ship deterministic budget allocation,\n compaction, memory reducers, inventory validation, and cross-surface\n conformance through `@chainlesschain/context-memory-kernel`.\n- **Durable memory cutover**: route CLI context, compaction, hierarchical\n memory, App Server, WebSocket, REPL, and session flows through fail-closed\n authority stages with crash-safe persistence and privacy purge receipts;\n Session Core `0.3.7` exposes the write guard used to fence legacy writers.\n- **Protocol and SDK projections**: add bounded Context/Memory messages and App\n Server pilot clients to the generated Agent Protocol, TypeScript SDK, Python\n SDK, VS Code extension, and JetBrains plugin without granting IDE surfaces\n independent write authority.\n- **Durable rollout stores**: converge App Server, WebSocket, and CLI entry\n points on bounded memory, JSON, or SQLite rollout stores with explicit\n selection, migration, recovery, and corruption handling.\n- **Hooks v2 convergence**: route CLI, REPL, headless, settings, plugins, and\n App Server through one trust-aware event runtime with deterministic ordering,\n audit replay, timeout supervision, and fail-closed decision semantics.\n- **Release integrity**: publish the new fixed CLI runtime dependency before\n the immutable CLI tarball, then verify its registry bytes and npm provenance\n against the exact release tag and commit."
27
+ }
28
+ ]
29
+ },
30
+ {
31
+ "productVersion": null,
32
+ "cliVersion": "0.166.10",
33
+ "cliVersions": ["0.166.9", "0.166.10"],
34
+ "date": "2026-08-29",
35
+ "title": "",
36
+ "sections": [
37
+ {
38
+ "heading": "Added - cc CLI 0.166.10: governed Graph Kernel production cutover evidence",
39
+ "body": "> `chainlesschain` **0.166.9 -> 0.166.10** (release candidate,\n> 2026-08-29).\n\n- **Production evidence aggregate**: `graph:production-evidence` verifies the\n complete staged Graph Kernel cutover evidence set against the exact protected\n source commit, producer run, inventory, rollout ledger, and qualification\n artifacts before it can emit a passing receipt.\n- **Fail-closed coverage**: the verifier requires all 20 durable entries, nine\n projection classes, three rollback modes, every retired writer and mutation,\n and all three explicitly disabled Browser/Remote entries; missing, duplicate,\n stale, cross-run, or digest-mismatched evidence is rejected.\n- **Protected consumption**: the production cutover workflow is bound to\n reviewed GitHub Environments, downloads artifacts from the selected protected\n producer run, and publishes a content-free receipt only after recomputing the\n complete aggregate locally.\n- **Honest rollout boundary**: this release ships the verifier and protected\n consumer, but does not claim that a production rollout occurred; P1-12 closes\n only after the real environment supplies a valid staged-rollout artifact for\n the same exact SHA."
40
+ }
41
+ ]
42
+ },
4
43
  {
5
44
  "productVersion": null,
6
45
  "cliVersion": "0.166.9",
@@ -10,7 +49,7 @@
10
49
  "sections": [
11
50
  {
12
51
  "heading": "Added - cc CLI 0.166.9: governed UI replay and Codex compatibility gates",
13
- "body": "> `chainlesschain` **0.166.8 -> 0.166.9** (release candidate,\n> 2026-08-29). Agent Protocol and TypeScript Agent SDK candidate versions\n> remain `0.1.6` and `0.2.5`; Python Agent SDK moves to `0.2.6` after the\n> immutable `0.2.5` candidate was withheld from PyPI because its release\n> metadata named an unpublished CLI.\n\n- **Real UI driver**: reviewed Record & Replay drafts can execute the bounded\n `observe/click/type/select/assert` vocabulary in an ephemeral Playwright\n Chromium context instead of relying on a fake executor.\n- **Fail-closed isolation**: the driver denies filesystem, HTTP(S), and\n WebSocket requests, requires exact reviewed capabilities and selectors, and\n rejects ambiguous targets, environment drift, network attempts, or missing\n terminal evidence.\n- **Content-free receipts**: selectors, typed values, page text, URLs, and\n screenshots never enter reports; only domain-separated state, page,\n screenshot, target, and receipt digests plus bounded structural metadata are\n retained.\n- **Cross-platform authority**: a dedicated exact-SHA GitHub Actions matrix\n runs the positive journey and an active network-escape probe in real Chromium\n on Linux, Windows, and macOS, then refuses partial evidence in its aggregate.\n- **Exact Codex admission**: the optional experimental App Server adapter now\n admits only explicitly listed upstream patch versions; prereleases and\n unverified future patches fail closed to the stable `codex exec --json`\n fallback before turn admission.\n- **Version-bound App Server evidence**: a second exact-SHA Actions matrix\n generates each upstream version's own schema and exercises the documented\n `initialize -> initialized -> thread/list` stdio lifecycle on Linux,\n Windows, and macOS without making a model request.\n- **Removal readiness**: every compatibility job proves that production CLI\n source has no dependency on the optional adapter and that the stable Codex\n JSONL fallback still executes and projects terminal output independently.\n- **Windows strict-sandbox cleanup**: target-identity cleanup remains bound to\n the stable file object while tolerating size and timestamp metadata settling\n after the native helper closes its writer; same-path replacement is still\n rejected.\n- **JetBrains real-host gate**: plan-review document access now runs inside\n explicit IntelliJ read/write actions, and the UI journey targets the current\n one-time permission label on every supported host/version pair.\n- **Python release metadata**: the `0.2.6` patch keeps the `0.2.5` runtime API\n and generated protocol bindings while pointing install guidance at the latest\n CLI that is actually available from the public npm registry."
52
+ "body": "> `chainlesschain` **0.166.8 -> 0.166.9**, published 2026-08-29 from exact\n> commit `222396f6a8429d4b862292a2572067a5cacb1003`. Agent Protocol `0.1.6`,\n> TypeScript Agent SDK `0.2.5`, and Python Agent SDK `0.2.6` are public. The\n> immutable Python `0.2.5` candidate was withheld from PyPI because its\n> release metadata named a CLI that was not yet public.\n\n- **Real UI driver**: reviewed Record & Replay drafts can execute the bounded\n `observe/click/type/select/assert` vocabulary in an ephemeral Playwright\n Chromium context instead of relying on a fake executor.\n- **Fail-closed isolation**: the driver denies filesystem, HTTP(S), and\n WebSocket requests, requires exact reviewed capabilities and selectors, and\n rejects ambiguous targets, environment drift, network attempts, or missing\n terminal evidence.\n- **Content-free receipts**: selectors, typed values, page text, URLs, and\n screenshots never enter reports; only domain-separated state, page,\n screenshot, target, and receipt digests plus bounded structural metadata are\n retained.\n- **Cross-platform authority**: a dedicated exact-SHA GitHub Actions matrix\n runs the positive journey and an active network-escape probe in real Chromium\n on Linux, Windows, and macOS, then refuses partial evidence in its aggregate.\n- **Exact Codex admission**: the optional experimental App Server adapter now\n admits only explicitly listed upstream patch versions; prereleases and\n unverified future patches fail closed to the stable `codex exec --json`\n fallback before turn admission.\n- **Version-bound App Server evidence**: a second exact-SHA Actions matrix\n generates each upstream version's own schema and exercises the documented\n `initialize -> initialized -> thread/list` stdio lifecycle on Linux,\n Windows, and macOS without making a model request.\n- **Removal readiness**: every compatibility job proves that production CLI\n source has no dependency on the optional adapter and that the stable Codex\n JSONL fallback still executes and projects terminal output independently.\n- **Windows strict-sandbox cleanup**: target-identity cleanup remains bound to\n the stable file object while tolerating size and timestamp metadata settling\n after the native helper closes its writer; same-path replacement is still\n rejected.\n- **JetBrains real-host gate**: plan-review document access now runs inside\n explicit IntelliJ read/write actions, and the UI journey targets the current\n one-time permission label on every supported host/version pair.\n- **Python release metadata**: the `0.2.6` patch keeps the `0.2.5` runtime API\n and generated protocol bindings while pointing install guidance at the latest\n CLI that is actually available from the public npm registry.\n- **Release validation**: immutable tag `v-npm-0-166-9` resolves to the exact\n commit above. Its Linux/Windows/macOS CLI CI and Strict Sandbox matrices,\n npm Trusted Publishing/provenance/readback, Record & Replay real-browser\n matrix, Codex App Server compatibility matrix, Desktop signed-Skill\n qualification, and IDE release gate completed successfully. Open VSX\n `0.37.73` is public; JetBrains source/tag `0.4.104` remains distinct from the\n Marketplace-public `0.4.103` artifact."
14
53
  }
15
54
  ]
16
55
  },
@@ -30,7 +69,7 @@
30
69
  "sections": [
31
70
  {
32
71
  "heading": "Added - cc CLI 0.166.8 + Agent Platform and IDE patches: durable Graph review and recovery",
33
- "body": "> `chainlesschain` **0.166.7 -> 0.166.8**,\n> `@chainlesschain/agent-protocol` **0.1.5 -> 0.1.6**,\n> `@chainlesschain/agent-sdk` **0.2.4 -> 0.2.5**, and\n> `chainlesschain-agent-sdk` **0.2.4 -> 0.2.5** (release candidate,\n> 2026-08-29).\n> VS Code **0.37.72 -> 0.37.73** and JetBrains\n> **0.4.103 -> 0.4.104** carry the paired governed review surfaces.\n\n- **Durable Graph history**: fixed App Server/SDK clients expose bounded,\n metadata-only event and snapshot history for blocked-root, revision-diff,\n and time-travel debugging across CLI, Desktop, and VS Code.\n- **Recoverable HumanTask quorum**: Graph human nodes persist exact\n revision/attempt/operation bindings, release Agent capacity while waiting,\n and enforce single-winner cancel/decision CAS, quorum, and separation of\n duties through the Desktop product surface.\n- **IDE review parity**: VS Code adds bounded Graph history/diff projection;\n both IDEs enforce revision-bound approval grants and single-winner\n settlement without accepting UI-derived authority.\n- **Migration and retirement evidence**: N-1 definition backups, rollback\n digests, replay validation, replacement reachability, historical reads, and\n zero-success legacy-writer observations are bound to durable exact-SHA\n evidence rather than prose-only rollout claims.\n- **Reliability gates**: temporal message custody, dependency/scope fairness,\n cross-process DAG recovery, effect idempotency, and worktree cleanup have\n explicit bounded artifacts and fail-closed aggregate checks.\n- **Release validation**: publication requires this exact candidate to pass\n Agent Protocol and Python SDK conformance, Linux/Windows/macOS `CLI CI` and\n `CLI Strict Sandbox`, the Graph real-journey matrix, immutable package\n checks, and public-registry provenance readback."
72
+ "body": "> `chainlesschain` **0.166.7 -> 0.166.8** (source candidate fully carried into\n> public `0.166.9`; it was not published as a separate npm version),\n> `@chainlesschain/agent-protocol` **0.1.5 -> 0.1.6**,\n> `@chainlesschain/agent-sdk` **0.2.4 -> 0.2.5**, and\n> `chainlesschain-agent-sdk` **0.2.4 -> 0.2.5** (withheld Python candidate,\n> superseded by public `0.2.6`, 2026-08-29).\n> VS Code **0.37.72 -> 0.37.73** and JetBrains\n> **0.4.103 -> 0.4.104** carry the paired governed review surfaces.\n\n- **Durable Graph history**: fixed App Server/SDK clients expose bounded,\n metadata-only event and snapshot history for blocked-root, revision-diff,\n and time-travel debugging across CLI, Desktop, and VS Code.\n- **Recoverable HumanTask quorum**: Graph human nodes persist exact\n revision/attempt/operation bindings, release Agent capacity while waiting,\n and enforce single-winner cancel/decision CAS, quorum, and separation of\n duties through the Desktop product surface.\n- **IDE review parity**: VS Code adds bounded Graph history/diff projection;\n both IDEs enforce revision-bound approval grants and single-winner\n settlement without accepting UI-derived authority.\n- **Migration and retirement evidence**: N-1 definition backups, rollback\n digests, replay validation, replacement reachability, historical reads, and\n zero-success legacy-writer observations are bound to durable exact-SHA\n evidence rather than prose-only rollout claims.\n- **Reliability gates**: temporal message custody, dependency/scope fairness,\n cross-process DAG recovery, effect idempotency, and worktree cleanup have\n explicit bounded artifacts and fail-closed aggregate checks.\n- **Release validation**: publication requires this exact candidate to pass\n Agent Protocol and Python SDK conformance, Linux/Windows/macOS `CLI CI` and\n `CLI Strict Sandbox`, the Graph real-journey matrix, immutable package\n checks, and public-registry provenance readback."
34
73
  }
35
74
  ]
36
75
  },
@@ -18,6 +18,16 @@ function fail(code, message) {
18
18
  return { ok: false, error: { code, message } };
19
19
  }
20
20
 
21
+ async function canonicalMemoryService(scopeKey) {
22
+ const { resolveCliContextMemoryCutover } =
23
+ await import("../../lib/context-memory-kernel/authority.js");
24
+ const decision = resolveCliContextMemoryCutover({ scopeKey });
25
+ if (!decision.canonical) return null;
26
+ const { createCliCanonicalMemoryService } =
27
+ await import("../../lib/context-memory-kernel/memory-service.js");
28
+ return createCliCanonicalMemoryService();
29
+ }
30
+
21
31
  async function loadSingletons() {
22
32
  return import("../../lib/session-core-singletons.js");
23
33
  }
@@ -133,11 +143,11 @@ async function sessionsPolicySet(message) {
133
143
  const { getApprovalGate } = await loadSingletons();
134
144
  const gate = await getApprovalGate();
135
145
  try {
136
- gate.setSessionPolicy(message.sessionId, message.policy);
146
+ await gate.setSessionPolicy(message.sessionId, message.policy);
147
+ await gate.awaitPersistence?.();
137
148
  } catch (e) {
138
- return fail("INVALID_POLICY", e.message);
149
+ return fail(e.code || "INVALID_POLICY", e.message);
139
150
  }
140
- await new Promise((r) => setImmediate(r));
141
151
  return ok({
142
152
  sessionId: message.sessionId,
143
153
  policy: gate.getSessionPolicy(message.sessionId),
@@ -146,6 +156,24 @@ async function sessionsPolicySet(message) {
146
156
 
147
157
  async function memoryStore(message) {
148
158
  if (!message.content) return fail("BAD_REQUEST", "content required");
159
+ const canonical = await canonicalMemoryService("cli:ws:memory.store");
160
+ if (canonical) {
161
+ try {
162
+ const scope = message.scope || "global";
163
+ const entry = await canonical.addScoped(message.content, {
164
+ scope,
165
+ scopeId: scope === "global" ? null : message.scopeId || message.agentId,
166
+ category: message.category,
167
+ tags: message.tags || [],
168
+ source: "cli-ws-session-core",
169
+ evidenceStore: "cli-ws-session-core",
170
+ evidenceId: String(message.id || `memory-store-${Date.now()}`),
171
+ });
172
+ return ok({ entry });
173
+ } catch (error) {
174
+ return fail(error.code || "MEMORY_STORE_FAILED", error.message);
175
+ }
176
+ }
149
177
  const { getMemoryStore } = await loadSingletons();
150
178
  const store = getMemoryStore();
151
179
  const entry = store.add({
@@ -162,6 +190,26 @@ async function memoryStore(message) {
162
190
  }
163
191
 
164
192
  async function memoryRecall(message) {
193
+ const canonical = await canonicalMemoryService("cli:ws:memory.recall");
194
+ if (canonical) {
195
+ try {
196
+ const scope = message.scope || "global";
197
+ const result = await canonical.recallScoped(message.query || "*", {
198
+ scope,
199
+ scopeId: scope === "global" ? null : message.scopeId || message.agentId,
200
+ tags: message.tags,
201
+ category: message.category,
202
+ limit: message.limit,
203
+ sink: "cli.ws",
204
+ });
205
+ return ok({
206
+ results: result.results,
207
+ memoryRevision: result.memoryRevision,
208
+ });
209
+ } catch (error) {
210
+ return fail(error.code || "MEMORY_RECALL_FAILED", error.message);
211
+ }
212
+ }
165
213
  const { getMemoryStore } = await loadSingletons();
166
214
  const store = getMemoryStore();
167
215
  const results = store.recall({
@@ -178,6 +226,17 @@ async function memoryRecall(message) {
178
226
 
179
227
  async function memoryDelete(message) {
180
228
  if (!message.id) return fail("BAD_REQUEST", "id required");
229
+ const canonical = await canonicalMemoryService("cli:ws:memory.delete");
230
+ if (canonical) {
231
+ try {
232
+ const receipt = await canonical.delete(message.id);
233
+ return receipt
234
+ ? ok({ id: message.id, deleted: true, receipt })
235
+ : fail("NOT_FOUND", `Memory ${message.id} not found`);
236
+ } catch (error) {
237
+ return fail(error.code || "MEMORY_DELETE_FAILED", error.message);
238
+ }
239
+ }
181
240
  const { getMemoryStore } = await loadSingletons();
182
241
  const store = getMemoryStore();
183
242
  const entry = store.get(message.id);
@@ -30,6 +30,7 @@ import {
30
30
  sessionBudgetAdmissionError,
31
31
  } from "../../lib/session-budget-production-root.js";
32
32
  import { mergePricing } from "../../lib/llm-pricing.js";
33
+ import { ensureCanonicalSessionTranscript } from "../../lib/session-transcript-migration.js";
33
34
 
34
35
  const PAYLOAD_DIGEST = /^sha256:[0-9a-f]{64}$/;
35
36
  const RAW_AUTHORITY_HASH = /^[0-9a-f]{64}$/;
@@ -752,7 +753,11 @@ export async function handleSessionCreate(server, id, ws, message) {
752
753
  createdSessionId = sessionId;
753
754
 
754
755
  const session = server.sessionManager.getSession(sessionId);
755
- if (sessionBudgetRoot.enabled) {
756
+ if (
757
+ (sessionType || "agent") === "agent" &&
758
+ (sessionBudgetRoot.enabled ||
759
+ typeof server.sessionManager.markCanonicalSession === "function")
760
+ ) {
756
761
  bootstrapLease = wsBudgetDependency(
757
762
  server,
758
763
  "acquireSessionHostLease",
@@ -768,24 +773,33 @@ export async function handleSessionCreate(server, id, ws, message) {
768
773
  title: `WS agent ${new Date().toISOString().slice(0, 10)}`,
769
774
  provider: session.provider,
770
775
  model: session.model || "",
771
- sessionBudgetRoot,
776
+ ...(sessionBudgetRoot.enabled ? { sessionBudgetRoot } : {}),
772
777
  });
773
778
  canonicalSessionCreated = true;
774
779
  } catch (cause) {
775
780
  const error = new Error(
776
- "Budgeted WebSocket JSONL session could not be durably created",
781
+ "WebSocket canonical session could not be durably created",
777
782
  { cause },
778
783
  );
779
- error.code = "CC_SESSION_BUDGET_SESSION_START_FAILED";
784
+ error.code = sessionBudgetRoot.enabled
785
+ ? "CC_SESSION_BUDGET_SESSION_START_FAILED"
786
+ : "CC_WS_CANONICAL_SESSION_START_FAILED";
780
787
  throw error;
781
788
  }
782
789
  if (startedSessionId !== sessionId) {
783
790
  const error = new Error(
784
- "Budgeted WebSocket JSONL session returned a different session id",
791
+ "WebSocket canonical session returned a different session id",
785
792
  );
786
- error.code = "CC_SESSION_BUDGET_SESSION_START_FAILED";
793
+ error.code = sessionBudgetRoot.enabled
794
+ ? "CC_SESSION_BUDGET_SESSION_START_FAILED"
795
+ : "CC_WS_CANONICAL_SESSION_START_FAILED";
787
796
  throw error;
788
797
  }
798
+ if (typeof server.sessionManager.markCanonicalSession === "function") {
799
+ server.sessionManager.markCanonicalSession(sessionId);
800
+ } else {
801
+ session.canonicalJsonlSession = true;
802
+ }
789
803
  const canonicalStart = wsBudgetDependency(
790
804
  server,
791
805
  "readSessionHostResumeState",
@@ -793,17 +807,20 @@ export async function handleSessionCreate(server, id, ws, message) {
793
807
  )(sessionId);
794
808
  if (!canonicalStart?.snapshot?.verified) {
795
809
  const error = new Error(
796
- "Budgeted WebSocket JSONL session could not be verified",
810
+ "WebSocket canonical session could not be verified",
797
811
  );
798
- error.code = "CC_SESSION_BUDGET_SESSION_START_FAILED";
812
+ error.code = sessionBudgetRoot.enabled
813
+ ? "CC_SESSION_BUDGET_SESSION_START_FAILED"
814
+ : "CC_WS_CANONICAL_SESSION_START_FAILED";
799
815
  throw error;
800
816
  }
801
817
  if (
802
- !canonicalStart.sessionBudgetRoot ||
803
- !sameSessionBudgetConfig(
804
- canonicalStart.sessionBudgetRoot,
805
- sessionBudgetRoot,
806
- )
818
+ sessionBudgetRoot.enabled &&
819
+ (!canonicalStart.sessionBudgetRoot ||
820
+ !sameSessionBudgetConfig(
821
+ canonicalStart.sessionBudgetRoot,
822
+ sessionBudgetRoot,
823
+ ))
807
824
  ) {
808
825
  const error = new Error(
809
826
  "Budgeted WebSocket JSONL declaration does not match the requested root",
@@ -945,7 +962,14 @@ export async function handleSessionResume(server, id, ws, message) {
945
962
  }
946
963
 
947
964
  const { sessionId } = message;
948
- const canonicalResume = wsBudgetDependency(
965
+ // Always consult the canonical transcript before the compatibility store.
966
+ // A manager without the newer markCanonicalSession() hook may still be
967
+ // resuming a session that another host already committed to JSONL. Skipping
968
+ // this read lets stale DB/WS state replace verified history and also bypasses
969
+ // missing/tampered/rollback refusal. readSessionHostResumeState() returns
970
+ // null for a genuinely absent transcript, so legacy-only sessions retain
971
+ // their compatibility fallback without weakening canonical authority.
972
+ let canonicalResume = wsBudgetDependency(
949
973
  server,
950
974
  "readSessionHostResumeState",
951
975
  readSessionHostResumeState,
@@ -963,7 +987,20 @@ export async function handleSessionResume(server, id, ws, message) {
963
987
  );
964
988
  return;
965
989
  }
966
- const session = server.sessionManager.resumeSession(sessionId);
990
+ let session = server.sessionManager.resumeSession(sessionId);
991
+ if (
992
+ !session &&
993
+ canonicalResume?.snapshot?.verified === true &&
994
+ typeof server.sessionManager.resumeCanonicalSession === "function"
995
+ ) {
996
+ try {
997
+ session = server.sessionManager.resumeCanonicalSession(sessionId, {
998
+ type: "agent",
999
+ });
1000
+ } catch {
1001
+ session = null;
1002
+ }
1003
+ }
967
1004
 
968
1005
  if (!session) {
969
1006
  server._send(
@@ -978,6 +1015,77 @@ export async function handleSessionResume(server, id, ws, message) {
978
1015
  return;
979
1016
  }
980
1017
 
1018
+ if (
1019
+ canonicalResume?.snapshot?.verified === true &&
1020
+ session.canonicalJsonlSession !== true &&
1021
+ typeof server.sessionManager.markCanonicalSession === "function"
1022
+ ) {
1023
+ try {
1024
+ server.sessionManager.markCanonicalSession(session.id);
1025
+ canonicalResume = wsBudgetDependency(
1026
+ server,
1027
+ "readSessionHostResumeState",
1028
+ readSessionHostResumeState,
1029
+ )(session.id);
1030
+ } catch (error) {
1031
+ server._send(
1032
+ ws,
1033
+ envelopeError(
1034
+ id,
1035
+ error?.code || "CC_WS_CANONICAL_SESSION_BIND_FAILED",
1036
+ error?.message || "WebSocket canonical session binding failed",
1037
+ sessionId,
1038
+ ),
1039
+ );
1040
+ return;
1041
+ }
1042
+ }
1043
+
1044
+ if (
1045
+ !canonicalResume &&
1046
+ session.type === "agent" &&
1047
+ typeof server.sessionManager.markCanonicalSession === "function"
1048
+ ) {
1049
+ try {
1050
+ ensureCanonicalSessionTranscript({
1051
+ sessionId: session.id,
1052
+ title: `WS agent ${new Date().toISOString().slice(0, 10)}`,
1053
+ provider: session.provider,
1054
+ model: session.model || "",
1055
+ messages: session.messages,
1056
+ source: "sqlite:llm_sessions",
1057
+ stripLeadingSystem: true,
1058
+ });
1059
+ if (typeof server.sessionManager.markCanonicalSession === "function") {
1060
+ server.sessionManager.markCanonicalSession(session.id);
1061
+ } else {
1062
+ session.canonicalJsonlSession = true;
1063
+ }
1064
+ canonicalResume = wsBudgetDependency(
1065
+ server,
1066
+ "readSessionHostResumeState",
1067
+ readSessionHostResumeState,
1068
+ )(session.id);
1069
+ if (!canonicalResume?.snapshot?.verified) {
1070
+ throw Object.assign(
1071
+ new Error("Migrated WebSocket session could not be verified"),
1072
+ { code: "CC_WS_CANONICAL_SESSION_MIGRATION_FAILED" },
1073
+ );
1074
+ }
1075
+ } catch (error) {
1076
+ server._send(
1077
+ ws,
1078
+ envelopeError(
1079
+ id,
1080
+ error?.code || "CC_WS_CANONICAL_SESSION_MIGRATION_FAILED",
1081
+ error?.message || "WebSocket session migration failed",
1082
+ sessionId,
1083
+ ),
1084
+ );
1085
+ return;
1086
+ }
1087
+ }
1088
+
981
1089
  let sessionBudgetRoot;
982
1090
  let canonicalSessionBudgetRoot = null;
983
1091
  try {
@@ -42,6 +42,12 @@ import { createWsApprovalGate } from "./ws-approval-gate.js";
42
42
  import { createSessionMcpLedgerSink } from "../../lib/mcp-call-ledger-store.js";
43
43
  import { createMcpHostRecoveryRuntime } from "../../lib/mcp-host-recovery-runtime.js";
44
44
  import { compactConversationWithProvider } from "../../harness/provider-backed-compaction.js";
45
+ import {
46
+ estimateMessagesTokens,
47
+ PromptCompressor,
48
+ } from "../../harness/prompt-compressor.js";
49
+ import { resolveCliContextMemoryCutover } from "../../lib/context-memory-kernel/authority.js";
50
+ import { compactLiveMessagesCanonical } from "../../lib/context-memory-kernel/live-compaction.js";
45
51
  import { projectCanonicalResumeMessages } from "../../lib/session-message-provenance.js";
46
52
  import { feature } from "../../lib/feature-flags.js";
47
53
  import { classifyStreamRetryReason } from "../../lib/stream-retry.js";
@@ -586,6 +592,124 @@ export class WSAgentHandler {
586
592
  return block;
587
593
  }
588
594
 
595
+ _contextMemoryCutover() {
596
+ return resolveCliContextMemoryCutover({
597
+ env: this.session.contextMemoryEnv || process.env,
598
+ scopeKey: `cli:session:${this.session.id}`,
599
+ });
600
+ }
601
+
602
+ async _compactContextMemory(messages, providerOptions, trigger) {
603
+ const cutover = this._contextMemoryCutover();
604
+ if (!cutover.canonical) {
605
+ return compactConversationWithProvider(messages, providerOptions);
606
+ }
607
+ const probe = new PromptCompressor({
608
+ model: providerOptions.model,
609
+ provider: providerOptions.provider,
610
+ ...(providerOptions.maxMessages
611
+ ? { maxMessages: providerOptions.maxMessages }
612
+ : {}),
613
+ ...(providerOptions.maxTokens
614
+ ? { maxTokens: providerOptions.maxTokens }
615
+ : {}),
616
+ });
617
+ if (
618
+ providerOptions.onlyIfNeeded === true &&
619
+ !probe.shouldAutoCompact(messages)
620
+ ) {
621
+ const tokens = estimateMessagesTokens(messages);
622
+ return {
623
+ messages: [...messages],
624
+ stats: {
625
+ strategy: "none",
626
+ originalMessages: messages.length,
627
+ compressedMessages: messages.length,
628
+ originalTokens: tokens,
629
+ compressedTokens: tokens,
630
+ saved: 0,
631
+ },
632
+ degradedEvent: null,
633
+ usageEvent: null,
634
+ usageUnknownEvent: null,
635
+ };
636
+ }
637
+
638
+ let compatibilityResult = null;
639
+ const canonical = await compactLiveMessagesCanonical(messages, {
640
+ compressor: {
641
+ maxTokens: probe.maxTokens,
642
+ compress: async (dropped) => {
643
+ compatibilityResult = await compactConversationWithProvider(
644
+ dropped,
645
+ providerOptions,
646
+ );
647
+ await providerOptions.onContextMemorySummarySettled?.(
648
+ compatibilityResult,
649
+ );
650
+ return compatibilityResult;
651
+ },
652
+ },
653
+ sessionId: this.session.id,
654
+ operationId: `${trigger}-${randomUUID()}`,
655
+ provider: this.session.provider,
656
+ model: this.session.model,
657
+ env: this.session.contextMemoryEnv || process.env,
658
+ persist: this.session.canonicalJsonlSession === true,
659
+ trigger,
660
+ ...(this.session.canonicalJsonlSession === true
661
+ ? {
662
+ commit: (stats, output, settlement) => {
663
+ this._sessionHostLease?.assert?.();
664
+ const result =
665
+ this._canonicalSessionStore.appendCompactEventIfMessagesMatch(
666
+ this.session.id,
667
+ {
668
+ ...stats,
669
+ trigger,
670
+ messages: projectCanonicalResumeMessages(output, {
671
+ strict: true,
672
+ }),
673
+ },
674
+ settlement.expectedMessages,
675
+ );
676
+ if (result && typeof result.then === "function") {
677
+ void Promise.resolve(result).catch(() => {});
678
+ const error = new TypeError(
679
+ "Canonical compact settlement must be synchronous",
680
+ );
681
+ error.code = "CC_COMPACTION_SETTLEMENT_ASYNC";
682
+ throw error;
683
+ }
684
+ return result;
685
+ },
686
+ }
687
+ : {}),
688
+ });
689
+ if (canonical.receipt.status === "stale") {
690
+ const error = new Error(
691
+ "session messages changed during canonical compaction",
692
+ );
693
+ error.code = "SESSION_REVISION_STALE";
694
+ throw error;
695
+ }
696
+ if (
697
+ canonical.receipt.status === "reconciliation_required" &&
698
+ !compatibilityResult?.usageUnknownEvent
699
+ ) {
700
+ const error = new Error("canonical compaction requires reconciliation");
701
+ error.code = "CC_COMPACTION_RECONCILIATION_REQUIRED";
702
+ throw error;
703
+ }
704
+ return {
705
+ messages: canonical.messages,
706
+ stats: canonical.stats,
707
+ degradedEvent: compatibilityResult?.degradedEvent || null,
708
+ usageEvent: compatibilityResult?.usageEvent || null,
709
+ usageUnknownEvent: compatibilityResult?.usageUnknownEvent || null,
710
+ };
711
+ }
712
+
589
713
  _canonicalTurnFromAuthority(state, requestId, userMessage, inputDigest) {
590
714
  const status = state?.status || (state?.turn ? "completed" : "none");
591
715
  this._applyCanonicalMessages(state?.messages || []);
@@ -630,7 +754,8 @@ export class WSAgentHandler {
630
754
  const { session } = this;
631
755
  if (
632
756
  session.autoCompact === false ||
633
- !feature("PROMPT_COMPRESSOR") ||
757
+ (!feature("PROMPT_COMPRESSOR") &&
758
+ !this._contextMemoryCutover().canonical) ||
634
759
  this._compactionSettlementBlock?.commitState === "provider-usage-unknown"
635
760
  ) {
636
761
  return true;
@@ -647,7 +772,7 @@ export class WSAgentHandler {
647
772
  let result;
648
773
  try {
649
774
  this._sessionHostLease?.assert?.();
650
- result = await compactConversationWithProvider(session.messages, {
775
+ result = await this._compactContextMemory(session.messages, {
651
776
  provider: session.provider,
652
777
  model: session.model,
653
778
  baseUrl: session.baseUrl,
@@ -675,8 +800,17 @@ export class WSAgentHandler {
675
800
  maxTokens: session.compactionMaxTokens,
676
801
  maxOutputTokens: session.compactionMaxOutputTokens,
677
802
  summaryInputMaxChars: session.compactionInputMaxChars,
678
- });
679
- if (compactionUsageCall) {
803
+ onContextMemorySummarySettled: (summaryResult) => {
804
+ if (compactionUsageCall && !compactionUsageSettled) {
805
+ this._settleCanonicalCompactionUsage(
806
+ compactionUsageCall,
807
+ summaryResult,
808
+ );
809
+ compactionUsageSettled = true;
810
+ }
811
+ },
812
+ }, "auto");
813
+ if (compactionUsageCall && !compactionUsageSettled) {
680
814
  this._settleCanonicalCompactionUsage(compactionUsageCall, result);
681
815
  compactionUsageSettled = true;
682
816
  }
@@ -747,7 +881,11 @@ export class WSAgentHandler {
747
881
  );
748
882
  const shouldSettle = stats?.strategy !== "none" && stats?.saved > 0;
749
883
  let settlementError = null;
750
- if (!messagesChanged && shouldSettle) {
884
+ if (
885
+ !messagesChanged &&
886
+ shouldSettle &&
887
+ stats?.canonicalAlreadySettled !== true
888
+ ) {
751
889
  try {
752
890
  const settlement =
753
891
  this._canonicalSessionStore.appendCompactEventIfMessagesMatch(
@@ -1977,7 +2115,7 @@ export class WSAgentHandler {
1977
2115
  try {
1978
2116
  this.assertSessionBudgetAdmission("WebSocket compaction");
1979
2117
  this._sessionHostLease?.assert?.();
1980
- result = await compactConversationWithProvider(session.messages, {
2118
+ result = await this._compactContextMemory(session.messages, {
1981
2119
  provider: session.provider,
1982
2120
  model: session.model,
1983
2121
  baseUrl: session.baseUrl,
@@ -2002,8 +2140,17 @@ export class WSAgentHandler {
2002
2140
  : {}),
2003
2141
  maxOutputTokens: session.compactionMaxOutputTokens,
2004
2142
  summaryInputMaxChars: session.compactionInputMaxChars,
2005
- });
2006
- if (compactionUsageCall) {
2143
+ onContextMemorySummarySettled: (summaryResult) => {
2144
+ if (compactionUsageCall && !compactionUsageSettled) {
2145
+ this._settleCanonicalCompactionUsage(
2146
+ compactionUsageCall,
2147
+ summaryResult,
2148
+ );
2149
+ compactionUsageSettled = true;
2150
+ }
2151
+ },
2152
+ }, "manual");
2153
+ if (compactionUsageCall && !compactionUsageSettled) {
2007
2154
  this._settleCanonicalCompactionUsage(compactionUsageCall, result);
2008
2155
  compactionUsageSettled = true;
2009
2156
  }
@@ -2068,7 +2215,8 @@ export class WSAgentHandler {
2068
2215
  if (
2069
2216
  !commandError &&
2070
2217
  !messagesChanged &&
2071
- session.canonicalJsonlSession === true
2218
+ session.canonicalJsonlSession === true &&
2219
+ stats?.canonicalAlreadySettled !== true
2072
2220
  ) {
2073
2221
  if (stats?.strategy !== "none") {
2074
2222
  try {