chainlesschain 0.162.189 → 0.162.197
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.
- package/README.md +84 -11
- package/bin/chainlesschain.js +7 -52
- package/completions/_cc +209 -0
- package/completions/cc.bash +18 -0
- package/completions/cc.fish +13 -0
- package/completions/cc.ps1 +226 -0
- package/package.json +10 -2
- package/src/assets/web-panel/assets/{AIOps-DbZft8w0.js → AIOps-D3Gu1a5d.js} +1 -1
- package/src/assets/web-panel/assets/{ActionButton-DoOZpwfN.js → ActionButton-DrwAoKaz.js} +1 -1
- package/src/assets/web-panel/assets/{Analytics-B0J0KLTW.js → Analytics-C7Q-gd_3.js} +3 -3
- package/src/assets/web-panel/assets/{AppLayout-D9eIR0qq.js → AppLayout-DgBtae-n.js} +4 -4
- package/src/assets/web-panel/assets/{Artifacts-BnZXEVeo.js → Artifacts-pQ6LcA-W.js} +1 -1
- package/src/assets/web-panel/assets/{Audit-X1ce4Bjn.js → Audit-DK61tocB.js} +1 -1
- package/src/assets/web-panel/assets/{BackgroundAgents-BvWR-y5v.js → BackgroundAgents-BOKgDFRh.js} +1 -1
- package/src/assets/web-panel/assets/{Backup-BublSGEd.js → Backup-Bo9G4vTP.js} +1 -1
- package/src/assets/web-panel/assets/{BaseInput-CR_77Hso.js → BaseInput-Do_dE9_v.js} +1 -1
- package/src/assets/web-panel/assets/{Chat-DixW52tq.js → Chat-COVvZzOL.js} +6 -6
- package/src/assets/web-panel/assets/ChatBubbleRenderer-BUUyJ5QO.js +1 -0
- package/src/assets/web-panel/assets/{Checkbox-CCv1C87K.js → Checkbox-Z9MJMolt.js} +1 -1
- package/src/assets/web-panel/assets/{Codegen-B03Cc3dd.js → Codegen-BVzWKVbf.js} +1 -1
- package/src/assets/web-panel/assets/{Col-CA06-6pU.js → Col-C8MnYcbT.js} +1 -1
- package/src/assets/web-panel/assets/{Community-Bj881J52.js → Community-DQxqw15l.js} +1 -1
- package/src/assets/web-panel/assets/{Compact-UZLTPoaL.js → Compact-BAUmrh3y.js} +1 -1
- package/src/assets/web-panel/assets/{Compliance-kGwzRb_0.js → Compliance-jPAkQ3zK.js} +1 -1
- package/src/assets/web-panel/assets/{Cowork-KundoYM8.js → Cowork-BBQyxbh8.js} +2 -2
- package/src/assets/web-panel/assets/{Cron-BYZyoqDe.js → Cron-W5koq8Z5.js} +2 -2
- package/src/assets/web-panel/assets/{Crosschain-BhrrppBX.js → Crosschain-BQhnu5hS.js} +1 -1
- package/src/assets/web-panel/assets/{DID-CdC6EguZ.js → DID-DD7PlI18.js} +2 -2
- package/src/assets/web-panel/assets/{Dashboard-CcQx3J4y.js → Dashboard-w_ILuwKI.js} +2 -2
- package/src/assets/web-panel/assets/{Dropdown-BpijtEzQ.js → Dropdown-qiDUAyAo.js} +1 -1
- package/src/assets/web-panel/assets/{EmailListRenderer-DfZjeZTe.js → EmailListRenderer-PDeBcI5H.js} +1 -1
- package/src/assets/web-panel/assets/{FamilyGuardDashboard-BFYSf69C.js → FamilyGuardDashboard-SuArscRM.js} +1 -1
- package/src/assets/web-panel/assets/{Federation-Okdi3pJm.js → Federation-BCovZaUn.js} +1 -1
- package/src/assets/web-panel/assets/{FormItemContext-mH-HebKW.js → FormItemContext-DjlFdVFk.js} +1 -1
- package/src/assets/web-panel/assets/{GenericCardRenderer-xivV69x7.js → GenericCardRenderer-DoEZ7fcS.js} +1 -1
- package/src/assets/web-panel/assets/{Git-1rh_YBwg.js → Git-CV0-6GPI.js} +2 -2
- package/src/assets/web-panel/assets/{Governance-eAXkNxdY.js → Governance-B_SFN50w.js} +1 -1
- package/src/assets/web-panel/assets/{Inference-CS6dMVTN.js → Inference-heI0Eo6k.js} +1 -1
- package/src/assets/web-panel/assets/{KnowledgeGraph-Bq_TnkvD.js → KnowledgeGraph-Cz5INS5p.js} +1 -1
- package/src/assets/web-panel/assets/{Logs-KchHtiHt.js → Logs-BSFxiHkg.js} +2 -2
- package/src/assets/web-panel/assets/MarkdownRenderer-1mNozZ8v.js +1 -0
- package/src/assets/web-panel/assets/{Marketplace-CsmGcX5X.js → Marketplace-0TWTpE7k.js} +1 -1
- package/src/assets/web-panel/assets/{McpTools-BaPFnnyz.js → McpTools-CV4-wBLm.js} +4 -4
- package/src/assets/web-panel/assets/{Memory-2m-sUUf7.js → Memory-x5bH5rw5.js} +2 -2
- package/src/assets/web-panel/assets/{MobileBridge-D5nVZBRu.js → MobileBridge-DaBmUu9G.js} +1 -1
- package/src/assets/web-panel/assets/{MobileProjects-Bo8MLZvT.js → MobileProjects-DqnoFPgR.js} +1 -1
- package/src/assets/web-panel/assets/{Mtc-3GDvamGa.js → Mtc-B_zKEBif.js} +4 -4
- package/src/assets/web-panel/assets/{MtcAudit-D2zGuZCH.js → MtcAudit-BCfKD2yg.js} +4 -4
- package/src/assets/web-panel/assets/{Multisig-BBVQ4t6t.js → Multisig-DgYfj6c_.js} +3 -3
- package/src/assets/web-panel/assets/{NLProgramming-BIOCyOGp.js → NLProgramming-Dz09lFUm.js} +1 -1
- package/src/assets/web-panel/assets/{Notes-DVwBGpzc.js → Notes-Cuj6ugBE.js} +3 -3
- package/src/assets/web-panel/assets/{NotificationSettings-BDnHfIfX.js → NotificationSettings-DK2WXjhg.js} +1 -1
- package/src/assets/web-panel/assets/{OrderTableRenderer-C7Ek20ag.js → OrderTableRenderer-D1IAOQoo.js} +1 -1
- package/src/assets/web-panel/assets/{Organization-D3SRKaa7.js → Organization-9fqnPvTw.js} +4 -4
- package/src/assets/web-panel/assets/{Overflow-C2B8ahyn.js → Overflow-n5xHkhow.js} +1 -1
- package/src/assets/web-panel/assets/{P2P-2iwQzG65.js → P2P-B5AUWwH-.js} +2 -2
- package/src/assets/web-panel/assets/{PdhVaultBrowser-CoPiWqMN.js → PdhVaultBrowser-CoUDV6dy.js} +4 -4
- package/src/assets/web-panel/assets/{Permissions-yV5XNXo5.js → Permissions-DPRmQf_H.js} +4 -4
- package/src/assets/web-panel/assets/{PersonalDataHub-uCDJhMUF.js → PersonalDataHub-B37bsbEN.js} +4 -4
- package/src/assets/web-panel/assets/{Pipeline-hN7ucMOA.js → Pipeline-CCAuPqu9.js} +1 -1
- package/src/assets/web-panel/assets/{Privacy-CgU0ptN4.js → Privacy-B81msZdv.js} +1 -1
- package/src/assets/web-panel/assets/{ProjectInit-CfYPiT6j.js → ProjectInit-B-Py2NbF.js} +2 -2
- package/src/assets/web-panel/assets/{ProjectSettings-B0A2C4nw.js → ProjectSettings-CYsneiRB.js} +2 -2
- package/src/assets/web-panel/assets/{Projects-BE5C0ajn.js → Projects-Y975Mh6R.js} +1 -1
- package/src/assets/web-panel/assets/{Providers-CstQPf8W.js → Providers-uO-10aP1.js} +1 -1
- package/src/assets/web-panel/assets/{QrScannerModal-Co3z_ynk.js → QrScannerModal-Bj_6gJ0l.js} +1 -1
- package/src/assets/web-panel/assets/{QuickAsk-DMTS6pQ6.js → QuickAsk-BgpBCMPE.js} +1 -1
- package/src/assets/web-panel/assets/{Recommend-ETw4odUa.js → Recommend-DhUW3YUA.js} +1 -1
- package/src/assets/web-panel/assets/RemoteSession-DdeyfbkA.js +5 -0
- package/src/assets/web-panel/assets/{Reputation-BTVqQgKq.js → Reputation-fxW421xd.js} +1 -1
- package/src/assets/web-panel/assets/{Row-CBKKwwtO.js → Row-De73w1og.js} +1 -1
- package/src/assets/web-panel/assets/{RssFeed-BHUQ438I.js → RssFeed-3US_Q_lj.js} +2 -2
- package/src/assets/web-panel/assets/{Search-B4NqeUsF.js → Search-DbZ_DU74.js} +1 -1
- package/src/assets/web-panel/assets/{Security-BRjoYG5_.js → Security-DoIU1vMF.js} +4 -4
- package/src/assets/web-panel/assets/{Services-CxQzu3p3.js → Services-DB_RGqpc.js} +2 -2
- package/src/assets/web-panel/assets/{Skeleton-BKzwwmWO.js → Skeleton-DnzLaayC.js} +1 -1
- package/src/assets/web-panel/assets/{Skills-DrsFcgth.js → Skills-VzVXHENF.js} +1 -1
- package/src/assets/web-panel/assets/{Sla-D21tmXCH.js → Sla-DMfvjCAI.js} +1 -1
- package/src/assets/web-panel/assets/{SpeechSettings-CjyjLfp8.js → SpeechSettings-DQQOYWbF.js} +1 -1
- package/src/assets/web-panel/assets/{SyncSettings-Cu45-tnx.js → SyncSettings-Bmx3FG1P.js} +2 -2
- package/src/assets/web-panel/assets/{Tasks-oMcILYOj.js → Tasks-DOQyfb-2.js} +1 -1
- package/src/assets/web-panel/assets/{Templates-Bh-Zcr5R.js → Templates-D6hTRT7c.js} +1 -1
- package/src/assets/web-panel/assets/{Tenant-68ns63aI.js → Tenant-CTPQZAzs.js} +1 -1
- package/src/assets/web-panel/assets/{Terminal-BLJkFykE.js → Terminal-B7vII3oH.js} +2 -2
- package/src/assets/web-panel/assets/{TimelineRenderer-xcrJLq-O.js → TimelineRenderer-BkiFJeXV.js} +1 -1
- package/src/assets/web-panel/assets/{Tokens-C6PpFJtf.js → Tokens-BPPdQMNo.js} +1 -1
- package/src/assets/web-panel/assets/{Trigger-BaKA7tdM.js → Trigger-BxG8JAEI.js} +1 -1
- package/src/assets/web-panel/assets/{Trust-BzhA57Jc.js → Trust-DHD7nMpM.js} +1 -1
- package/src/assets/web-panel/assets/{UkeySign-4_U3JkIR.js → UkeySign-B4BJpU47.js} +1 -1
- package/src/assets/web-panel/assets/{VideoEditing-162AANxX.js → VideoEditing-CRiGpFx2.js} +1 -1
- package/src/assets/web-panel/assets/{Wallet-B1viuql_.js → Wallet-BSDSNiem.js} +4 -4
- package/src/assets/web-panel/assets/{WebAuthn-ZVWazhCy.js → WebAuthn-DLTUh5Zv.js} +5 -5
- package/src/assets/web-panel/assets/WorkflowEditor-tW2MwjhD.js +1 -0
- package/src/assets/web-panel/assets/{chat-DmrHNuwq.js → chat-SgsLQ3FC.js} +1 -1
- package/src/assets/web-panel/assets/{colors-DAJ_M-PK.js → colors-BHjjLIKO.js} +1 -1
- package/src/assets/web-panel/assets/{compact-item-uIzmYwLs.js → compact-item-VceErdKq.js} +1 -1
- package/src/assets/web-panel/assets/{createContext-D_ZmuLwb.js → createContext-BZ332MYl.js} +1 -1
- package/src/assets/web-panel/assets/devWarning-DosMaL-k.js +1 -0
- package/src/assets/web-panel/assets/{hasIn-CDt_shTL.js → hasIn-CBTjJOjn.js} +1 -1
- package/src/assets/web-panel/assets/index-0O5ePnUq.js +1 -0
- package/src/assets/web-panel/assets/{index-rXdwUeE3.js → index-1n7xjKDU.js} +1 -1
- package/src/assets/web-panel/assets/{index-BAvSmJXW.js → index-29wVzi-k.js} +1 -1
- package/src/assets/web-panel/assets/{index-C16fYKFD.js → index-B2u26AS3.js} +1 -1
- package/src/assets/web-panel/assets/{index-C5WcdJH2.js → index-B40dQn0G.js} +3 -3
- package/src/assets/web-panel/assets/{index-CaelyMgF.js → index-B5KAGxNo.js} +1 -1
- package/src/assets/web-panel/assets/{index-OzTxFIJP.js → index-BC1xuQgX.js} +1 -1
- package/src/assets/web-panel/assets/{index-CzXqvMuP.js → index-BETEjuNr.js} +1 -1
- package/src/assets/web-panel/assets/{index-clSX4PEc.js → index-BOtvPdHt.js} +1 -1
- package/src/assets/web-panel/assets/{index-saf3VNeP.js → index-BPXFLYdW.js} +1 -1
- package/src/assets/web-panel/assets/{index-DdUMcwRB.js → index-BQSmZGgs.js} +1 -1
- package/src/assets/web-panel/assets/{index-DfSSy9uy.js → index-BRWhLbWF.js} +1 -1
- package/src/assets/web-panel/assets/{index-GcKOHD_c.js → index-BTlc-Bve.js} +1 -1
- package/src/assets/web-panel/assets/{index-BHvlm0In.js → index-BY1wexYG.js} +1 -1
- package/src/assets/web-panel/assets/{index-Cvak6Oe2.js → index-BcUenmCX.js} +1 -1
- package/src/assets/web-panel/assets/{index-CKyd472S.js → index-BeiqkxJG.js} +1 -1
- package/src/assets/web-panel/assets/{index-DvFhhe6r.js → index-BhXZEUAc.js} +1 -1
- package/src/assets/web-panel/assets/{index-DBFmcaCQ.js → index-By5jBtkV.js} +1 -1
- package/src/assets/web-panel/assets/{index-DqDSF2RW.js → index-CLc19alH.js} +1 -1
- package/src/assets/web-panel/assets/{index-DeGBoLQA.js → index-CMVvxIS8.js} +1 -1
- package/src/assets/web-panel/assets/{index-FyplHuNt.js → index-C_B9rFQE.js} +1 -1
- package/src/assets/web-panel/assets/{index-CeUpKjvi.js → index-CaIS_TNX.js} +1 -1
- package/src/assets/web-panel/assets/{index-BRa4kJ_S.js → index-CawpdGTW.js} +1 -1
- package/src/assets/web-panel/assets/index-ChAzPigF.js +1 -0
- package/src/assets/web-panel/assets/{index-QsgfSZrV.js → index-CpumS98o.js} +1 -1
- package/src/assets/web-panel/assets/{index-BDF6EQBs.js → index-Cr4rjlW5.js} +1 -1
- package/src/assets/web-panel/assets/{index-rS3gl_68.js → index-CrUgDQkf.js} +1 -1
- package/src/assets/web-panel/assets/{index-D4n1lGTB.js → index-CtjLcCNU.js} +1 -1
- package/src/assets/web-panel/assets/{index-ifxmu8SY.js → index-DUkVN794.js} +1 -1
- package/src/assets/web-panel/assets/{index-BTCXf1t-.js → index-D_SePDWj.js} +1 -1
- package/src/assets/web-panel/assets/{index-Bbxjfstq.js → index-DaCCy6lq.js} +1 -1
- package/src/assets/web-panel/assets/{index-D9OE8B3d.js → index-DdefYBSw.js} +1 -1
- package/src/assets/web-panel/assets/{index-CG0lY4h3.js → index-DePOeMDM.js} +1 -1
- package/src/assets/web-panel/assets/{index-Bx4d6c1k.js → index-DgPvuIn2.js} +1 -1
- package/src/assets/web-panel/assets/{index-Z8P4BexE.js → index-FJ3zC9LK.js} +1 -1
- package/src/assets/web-panel/assets/{index-ByzGvpR9.js → index-_PHrIO4O.js} +1 -1
- package/src/assets/web-panel/assets/{index-DwfvPe-j.js → index-fU7wNHDB.js} +1 -1
- package/src/assets/web-panel/assets/{index-CcZ9xJI9.js → index-iYQNU9za.js} +1 -1
- package/src/assets/web-panel/assets/{index-CbD_WW_6.js → index-vIXOpcjD.js} +1 -1
- package/src/assets/web-panel/assets/{initDefaultProps-pmfaD-aK.js → initDefaultProps-D1oZNz0D.js} +1 -1
- package/src/assets/web-panel/assets/{motion-CaQ2CpYF.js → motion-C8k6doMO.js} +1 -1
- package/src/assets/web-panel/assets/{move-CkKTqNbI.js → move-DJ4qSbYt.js} +1 -1
- package/src/assets/web-panel/assets/{mtc-parser-Dd4xsgRI.js → mtc-parser-CdpJD85j.js} +1 -1
- package/src/assets/web-panel/assets/{omit-BFuA5YEs.js → omit-B0V4slKA.js} +1 -1
- package/src/assets/web-panel/assets/{pickAttrs-DDfxOAJc.js → pickAttrs-Di5NiW1F.js} +1 -1
- package/src/assets/web-panel/assets/{placementArrow-Be595JCp.js → placementArrow-B5OMHgEM.js} +1 -1
- package/src/assets/web-panel/assets/{responsiveObserve-7byljUM3.js → responsiveObserve-C6U9IWql.js} +1 -1
- package/src/assets/web-panel/assets/{slide-CTWfOTaY.js → slide-BMyTH3rN.js} +1 -1
- package/src/assets/web-panel/assets/{statusUtils-CNZOuIxM.js → statusUtils-C7d6BG7Z.js} +1 -1
- package/src/assets/web-panel/assets/{styleChecker-DwOcBV78.js → styleChecker-CR50QnQy.js} +1 -1
- package/src/assets/web-panel/assets/{useFlexGapSupport-B6MNwAO9.js → useFlexGapSupport-DBEeoMb8.js} +1 -1
- package/src/assets/web-panel/assets/{useFs-CzyQjH9r.js → useFs-3r099cjv.js} +1 -1
- package/src/assets/web-panel/assets/{usePersonalDataHub-Dxh3KiVA.js → usePersonalDataHub-C5IYNdTK.js} +1 -1
- package/src/assets/web-panel/assets/{vnode-DVfZiS5N.js → vnode-DmEOLRHf.js} +1 -1
- package/src/assets/web-panel/assets/{zoom-BYme7fbY.js → zoom-DnpUiVCB.js} +1 -1
- package/src/assets/web-panel/index.html +1 -1
- package/src/cli-help.js +181 -0
- package/src/command-help-index.json +181 -0
- package/src/command-manifest.json +1271 -175
- package/src/command-surface-policy.js +312 -0
- package/src/commands/agent.js +76 -33
- package/src/commands/artifacts.js +400 -2
- package/src/commands/background-session.js +41 -3
- package/src/commands/checkpoint-restore-recovery.js +1476 -0
- package/src/commands/checkpoint.js +947 -22
- package/src/commands/compact.js +101 -25
- package/src/commands/config.js +506 -20
- package/src/commands/doctor.js +4 -1
- package/src/commands/hub.js +1 -1
- package/src/commands/mcp.js +688 -24
- package/src/commands/pack.js +16 -2
- package/src/commands/plugin.js +20 -12
- package/src/commands/session-mcp-recovery.js +218 -0
- package/src/commands/session.js +470 -110
- package/src/commands/setup.js +36 -10
- package/src/commands/skill.js +181 -110
- package/src/commands/status.js +21 -5
- package/src/commands/update.js +68 -6
- package/src/constants.js +11 -0
- package/src/data/changelog.json +14 -1
- package/src/gateways/ws/action-protocol.js +10 -0
- package/src/gateways/ws/session-protocol.js +555 -27
- package/src/gateways/ws/ws-agent-handler.js +541 -14
- package/src/gateways/ws/ws-session-gateway.js +129 -22
- package/src/gateways/ws/ws-session-state.js +431 -0
- package/src/harness/background-task-manager.js +233 -36
- package/src/harness/jsonl-session-store.js +2551 -167
- package/src/harness/mcp-client.js +802 -61
- package/src/harness/prompt-compressor.js +227 -27
- package/src/harness/session-index.js +89 -38
- package/src/harness/session-list-index.js +254 -0
- package/src/harness/structured-handoff.js +410 -0
- package/src/lazy-dispatch.js +747 -84
- package/src/lib/__tests__/logger.test.js +50 -2
- package/src/lib/advisor-runtime.js +1047 -0
- package/src/lib/agent-core.js +1 -0
- package/src/lib/agent-sandbox.js +120 -26
- package/src/lib/agent-session-export.js +20 -0
- package/src/lib/agent-team/team-runner.js +230 -8
- package/src/lib/artifact-store.js +131 -8
- package/src/lib/background-agent-supervisor.js +185 -13
- package/src/lib/background-interaction-journal.js +37 -9
- package/src/lib/background-launch-profile.js +1058 -0
- package/src/lib/checkpoint-restore-already-completed-controller.js +902 -0
- package/src/lib/checkpoint-restore-orchestrator.js +987 -0
- package/src/lib/checkpoint-restore-partial-rollback-controller.js +1953 -0
- package/src/lib/checkpoint-restore-recovery-controller.js +689 -0
- package/src/lib/checkpoint-restore-recovery.js +884 -0
- package/src/lib/checkpoint-restore-retention.js +126 -0
- package/src/lib/checkpoint-restore-saga.js +5079 -0
- package/src/lib/checkpoint-restore-session-recovery.js +1178 -0
- package/src/lib/checkpoint-restore-workspace-target-verifier.js +270 -0
- package/src/lib/checkpoint-store.js +1688 -97
- package/src/lib/checkpoint-timeline-authority.js +522 -0
- package/src/lib/checkpoint-timeline.js +642 -0
- package/src/lib/config-keys.js +18 -119
- package/src/lib/config-manager.js +446 -27
- package/src/lib/config-redaction.js +57 -0
- package/src/lib/config-schema.js +853 -0
- package/src/lib/cowork-mcp-tools.js +5 -0
- package/src/lib/cowork-task-runner.js +458 -63
- package/src/lib/delivery-coordinator.js +1234 -0
- package/src/lib/delivery-evidence.js +450 -0
- package/src/lib/doctor-checkup.js +199 -14
- package/src/lib/executable-path.js +34 -0
- package/src/lib/fatal-handler.js +16 -0
- package/src/lib/file-checkpoint.js +4909 -186
- package/src/lib/file-lines.js +125 -0
- package/src/lib/headless-config-command.js +16 -5
- package/src/lib/hook-runner.cjs +139 -38
- package/src/lib/hooks-v2-workspace-context.js +10 -0
- package/src/lib/impacted-gate-selector.js +424 -0
- package/src/lib/interaction-adapter.js +62 -0
- package/src/lib/jsonl-session-store.js +1 -35
- package/src/lib/logger.js +66 -14
- package/src/lib/mcp-call-ledger-store.js +1069 -0
- package/src/lib/mcp-call-ledger.js +747 -0
- package/src/lib/mcp-client.js +5 -0
- package/src/lib/mcp-conflict-scheduler.js +468 -0
- package/src/lib/mcp-effect-contract.js +102 -0
- package/src/lib/mcp-headers-helper-trust.js +145 -0
- package/src/lib/mcp-headers-helper.js +616 -0
- package/src/lib/mcp-host-recovery-runtime.js +131 -0
- package/src/lib/mcp-ledger-recovery-admission.js +1065 -0
- package/src/lib/mcp-recovery-adjudication.js +443 -0
- package/src/lib/output-context.js +86 -0
- package/src/lib/packer/file-identity.js +170 -0
- package/src/lib/packer/index.js +3 -0
- package/src/lib/packer/native-update-state.js +277 -0
- package/src/lib/packer/pack-update-applier.js +1983 -136
- package/src/lib/packer/pack-update-checker.js +34 -0
- package/src/lib/packer/pack-update-downloader.js +875 -86
- package/src/lib/packer/pack-update-signature.js +86 -0
- package/src/lib/packer/pkg-config-generator.js +6 -0
- package/src/lib/paths.js +65 -10
- package/src/lib/plan-mode.js +831 -14
- package/src/lib/plan-persistence.js +540 -0
- package/src/lib/plugin-runtime/hooks.js +227 -69
- package/src/lib/plugin-runtime/plugin-options.js +189 -44
- package/src/lib/pr-automation-policy.js +146 -8
- package/src/lib/process-execution-broker/credential-agent.js +7 -0
- package/src/lib/process-execution-broker/index.js +53 -8
- package/src/lib/process-execution-broker/workspace-transaction.js +976 -73
- package/src/lib/project-instructions.js +165 -29
- package/src/lib/project-mcp-trust.js +67 -0
- package/src/lib/public-ide-capability-manifest.js +278 -0
- package/src/lib/public-ide-capability-validation.js +351 -0
- package/src/lib/secret-store.js +267 -43
- package/src/lib/secure-fs.js +1089 -0
- package/src/lib/security-audit.js +58 -0
- package/src/lib/service-manager.js +34 -13
- package/src/lib/session-budget-runtime.js +1452 -0
- package/src/lib/session-host-snapshot.js +388 -0
- package/src/lib/session-message-provenance.js +429 -0
- package/src/lib/session-projection.js +804 -0
- package/src/lib/session-resource-budget.js +1495 -0
- package/src/lib/settings-hooks.cjs +138 -22
- package/src/lib/settings-loader.cjs +25 -2
- package/src/lib/side-effect-ledger-store.js +45 -23
- package/src/lib/skill-execution-identity.js +217 -0
- package/src/lib/skill-loader.js +299 -18
- package/src/lib/sub-agent-context.js +236 -28
- package/src/lib/sub-agent-registry.js +5 -0
- package/src/lib/subagent-contract.js +94 -0
- package/src/lib/todo-manager.js +185 -18
- package/src/lib/todo-persistence.js +417 -0
- package/src/lib/turn-binding-store.js +41 -23
- package/src/lib/with-file-lock.js +25 -1
- package/src/lib/ws-chat-handler.js +21 -0
- package/src/program-base.js +18 -0
- package/src/repl/advisor-command.js +103 -0
- package/src/repl/agent-repl.js +2332 -154
- package/src/repl/btw-command.js +93 -10
- package/src/repl/clipboard-image.js +119 -0
- package/src/repl/config-summary.js +64 -108
- package/src/repl/prompt-editor.js +233 -0
- package/src/repl/prompt-interactions.js +404 -0
- package/src/repl/prompt-stash.js +354 -0
- package/src/repl/prompt-suggestions.js +312 -0
- package/src/repl/repl-keybindings.js +227 -0
- package/src/repl/session-recap.js +217 -0
- package/src/repl/slash-command-registry.js +25 -4
- package/src/repl/terminal-layout.js +88 -0
- package/src/runtime/agent-core.js +1264 -325
- package/src/runtime/coding-agent-contract-shared.cjs +13 -1
- package/src/runtime/coding-agent-managed-tool-policy.cjs +7 -2
- package/src/runtime/diagnostics.js +32 -13
- package/src/runtime/headless-runner.js +298 -118
- package/src/runtime/headless-stream.js +353 -95
- package/src/runtime/mcp-config.js +148 -14
- package/src/runtime/status-diagnostics-lite.js +137 -0
- package/src/assets/web-panel/assets/ChatBubbleRenderer-DDHDpBBA.js +0 -1
- package/src/assets/web-panel/assets/MarkdownRenderer-TabqHW9B.js +0 -1
- package/src/assets/web-panel/assets/RemoteSession-B0rkE09d.js +0 -5
- package/src/assets/web-panel/assets/WorkflowEditor-tzdyUk-1.js +0 -1
- package/src/assets/web-panel/assets/devWarning-DIrncrV1.js +0 -1
- package/src/assets/web-panel/assets/index-D-Swwqld.js +0 -1
- package/src/assets/web-panel/assets/index-FMZAMKy8.js +0 -1
|
@@ -32,6 +32,38 @@ import {
|
|
|
32
32
|
runWithHostHooksV2Workspace,
|
|
33
33
|
} from "../../lib/hooks-v2-workspace-context.js";
|
|
34
34
|
import { createWsApprovalGate } from "./ws-approval-gate.js";
|
|
35
|
+
import { createSessionMcpLedgerSink } from "../../lib/mcp-call-ledger-store.js";
|
|
36
|
+
import { createMcpHostRecoveryRuntime } from "../../lib/mcp-host-recovery-runtime.js";
|
|
37
|
+
import {
|
|
38
|
+
claimWsTurnIfHead,
|
|
39
|
+
computeWsTurnInputDigest,
|
|
40
|
+
createWsTurnClaimId,
|
|
41
|
+
normalizeWsTurnRequestId,
|
|
42
|
+
readVerifiedWsTurnState,
|
|
43
|
+
settleWsTurnClaim,
|
|
44
|
+
} from "../../harness/jsonl-session-store.js";
|
|
45
|
+
|
|
46
|
+
const CANONICAL_WS_TURN_QUEUES = new Map();
|
|
47
|
+
const CANONICAL_WS_CLAIM_CAS_ATTEMPTS = 4;
|
|
48
|
+
|
|
49
|
+
function runCanonicalWsTurnExclusive(sessionId, task) {
|
|
50
|
+
const previous = CANONICAL_WS_TURN_QUEUES.get(sessionId) || Promise.resolve();
|
|
51
|
+
let release;
|
|
52
|
+
const barrier = new Promise((resolve) => {
|
|
53
|
+
release = resolve;
|
|
54
|
+
});
|
|
55
|
+
const tail = previous.catch(() => undefined).then(() => barrier);
|
|
56
|
+
CANONICAL_WS_TURN_QUEUES.set(sessionId, tail);
|
|
57
|
+
return previous
|
|
58
|
+
.catch(() => undefined)
|
|
59
|
+
.then(task)
|
|
60
|
+
.finally(() => {
|
|
61
|
+
release();
|
|
62
|
+
if (CANONICAL_WS_TURN_QUEUES.get(sessionId) === tail) {
|
|
63
|
+
CANONICAL_WS_TURN_QUEUES.delete(sessionId);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
35
67
|
|
|
36
68
|
export class WSAgentHandler {
|
|
37
69
|
/**
|
|
@@ -40,7 +72,14 @@ export class WSAgentHandler {
|
|
|
40
72
|
* @param {import("../../lib/interaction-adapter.js").WebSocketInteractionAdapter} options.interaction
|
|
41
73
|
* @param {object} [options.db]
|
|
42
74
|
*/
|
|
43
|
-
constructor({
|
|
75
|
+
constructor({
|
|
76
|
+
session,
|
|
77
|
+
interaction,
|
|
78
|
+
db,
|
|
79
|
+
approvalGate,
|
|
80
|
+
agentLoop: runAgentLoop,
|
|
81
|
+
canonicalSessionStore,
|
|
82
|
+
}) {
|
|
44
83
|
this.session = session;
|
|
45
84
|
this.interaction = interaction;
|
|
46
85
|
this.db = db || null;
|
|
@@ -58,6 +97,325 @@ export class WSAgentHandler {
|
|
|
58
97
|
// injected): approvalGate stays null and loopOptions are byte-identical.
|
|
59
98
|
this._approvalGate = approvalGate || null;
|
|
60
99
|
this._approvalGateInit = Boolean(approvalGate);
|
|
100
|
+
this._mcpRecoveryRuntime = null;
|
|
101
|
+
this._mcpRecoveryRevision = null;
|
|
102
|
+
this._mcpRecoveryClient = null;
|
|
103
|
+
this._agentLoop = runAgentLoop || agentLoop;
|
|
104
|
+
this._canonicalSessionStore = {
|
|
105
|
+
claimWsTurnIfHead,
|
|
106
|
+
computeWsTurnInputDigest,
|
|
107
|
+
createWsTurnClaimId,
|
|
108
|
+
normalizeWsTurnRequestId,
|
|
109
|
+
readVerifiedWsTurnState,
|
|
110
|
+
settleWsTurnClaim,
|
|
111
|
+
...(canonicalSessionStore || {}),
|
|
112
|
+
};
|
|
113
|
+
const explicitHostPrefix = Array.isArray(
|
|
114
|
+
session?._canonicalHostSystemPrefix,
|
|
115
|
+
)
|
|
116
|
+
? session._canonicalHostSystemPrefix
|
|
117
|
+
: null;
|
|
118
|
+
const hostSystemPrefix = explicitHostPrefix || [];
|
|
119
|
+
if (!explicitHostPrefix) {
|
|
120
|
+
for (const message of Array.isArray(session?.messages)
|
|
121
|
+
? session.messages
|
|
122
|
+
: []) {
|
|
123
|
+
if (message?.role !== "system") break;
|
|
124
|
+
hostSystemPrefix.push(Object.freeze({ ...message }));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
this._canonicalHostSystemPrefix = explicitHostPrefix
|
|
128
|
+
? explicitHostPrefix
|
|
129
|
+
: Object.freeze(hostSystemPrefix);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
_applyCanonicalMessages(messages) {
|
|
133
|
+
const canonicalMessages = Array.isArray(messages) ? messages : [];
|
|
134
|
+
this.session.messages = [
|
|
135
|
+
...this._canonicalHostSystemPrefix,
|
|
136
|
+
...canonicalMessages,
|
|
137
|
+
];
|
|
138
|
+
|
|
139
|
+
// Resume recovery notices are host-owned runtime context rather than
|
|
140
|
+
// canonical transcript content. Preserve the current notice separately,
|
|
141
|
+
// after the leading system block, on every authoritative refresh.
|
|
142
|
+
const recoveryNotice = this.session._resumeRecoveryNoticeMessage || null;
|
|
143
|
+
if (recoveryNotice) {
|
|
144
|
+
let insertionIndex = 0;
|
|
145
|
+
while (this.session.messages[insertionIndex]?.role === "system") {
|
|
146
|
+
insertionIndex += 1;
|
|
147
|
+
}
|
|
148
|
+
this.session.messages.splice(insertionIndex, 0, recoveryNotice);
|
|
149
|
+
}
|
|
150
|
+
return this.session.messages;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
_canonicalTurnFromAuthority(state, requestId, userMessage, inputDigest) {
|
|
154
|
+
const status = state?.status || (state?.turn ? "completed" : "none");
|
|
155
|
+
this._applyCanonicalMessages(state?.messages || []);
|
|
156
|
+
if (status === "completed" && state.turn) {
|
|
157
|
+
return {
|
|
158
|
+
requestId,
|
|
159
|
+
userMessage,
|
|
160
|
+
inputDigest,
|
|
161
|
+
status,
|
|
162
|
+
settled: true,
|
|
163
|
+
replayed: true,
|
|
164
|
+
response: state.turn.assistant.content,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
if (status === "failed") {
|
|
168
|
+
return {
|
|
169
|
+
requestId,
|
|
170
|
+
userMessage,
|
|
171
|
+
inputDigest,
|
|
172
|
+
status,
|
|
173
|
+
settled: true,
|
|
174
|
+
replayed: true,
|
|
175
|
+
failureCode: state.settlement?.failure?.code || "CC_WS_TURN_FAILED",
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
if (status === "pending") {
|
|
179
|
+
return {
|
|
180
|
+
requestId,
|
|
181
|
+
userMessage,
|
|
182
|
+
inputDigest,
|
|
183
|
+
status,
|
|
184
|
+
settled: false,
|
|
185
|
+
pending: true,
|
|
186
|
+
replayed: true,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
_claimCanonicalTurn(userMessage, requestId) {
|
|
193
|
+
const inputDigest =
|
|
194
|
+
this._canonicalSessionStore.computeWsTurnInputDigest(userMessage);
|
|
195
|
+
let state = this._canonicalSessionStore.readVerifiedWsTurnState(
|
|
196
|
+
this.session.id,
|
|
197
|
+
requestId,
|
|
198
|
+
{ inputDigest },
|
|
199
|
+
);
|
|
200
|
+
let terminal = this._canonicalTurnFromAuthority(
|
|
201
|
+
state,
|
|
202
|
+
requestId,
|
|
203
|
+
userMessage,
|
|
204
|
+
inputDigest,
|
|
205
|
+
);
|
|
206
|
+
if (terminal) return terminal;
|
|
207
|
+
|
|
208
|
+
const opaqueClaimId = this._canonicalSessionStore.createWsTurnClaimId();
|
|
209
|
+
let lastConflict = null;
|
|
210
|
+
for (
|
|
211
|
+
let attempt = 1;
|
|
212
|
+
attempt <= CANONICAL_WS_CLAIM_CAS_ATTEMPTS;
|
|
213
|
+
attempt++
|
|
214
|
+
) {
|
|
215
|
+
try {
|
|
216
|
+
const claimed = this._canonicalSessionStore.claimWsTurnIfHead(
|
|
217
|
+
this.session.id,
|
|
218
|
+
{ requestId, user: userMessage, inputDigest, opaqueClaimId },
|
|
219
|
+
state.headHash,
|
|
220
|
+
);
|
|
221
|
+
if (!claimed?.acquired) {
|
|
222
|
+
terminal = this._canonicalTurnFromAuthority(
|
|
223
|
+
claimed,
|
|
224
|
+
requestId,
|
|
225
|
+
userMessage,
|
|
226
|
+
inputDigest,
|
|
227
|
+
);
|
|
228
|
+
if (terminal) return terminal;
|
|
229
|
+
throw Object.assign(
|
|
230
|
+
new Error("Canonical WebSocket request claim was not acquired"),
|
|
231
|
+
{ code: "CC_WS_TURN_CLAIM_NOT_ACQUIRED" },
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
this._applyCanonicalMessages(claimed.messages);
|
|
235
|
+
const baseMessages = [...this.session.messages];
|
|
236
|
+
this.session.messages.push({ role: "user", content: userMessage });
|
|
237
|
+
return {
|
|
238
|
+
requestId,
|
|
239
|
+
userMessage,
|
|
240
|
+
inputDigest,
|
|
241
|
+
opaqueClaimId,
|
|
242
|
+
status: "pending",
|
|
243
|
+
claimAcquired: true,
|
|
244
|
+
settled: false,
|
|
245
|
+
settlementAttempted: false,
|
|
246
|
+
failureSettlementAttempted: false,
|
|
247
|
+
replayed: false,
|
|
248
|
+
response: null,
|
|
249
|
+
baseMessages,
|
|
250
|
+
};
|
|
251
|
+
} catch (error) {
|
|
252
|
+
if (error?.code !== "SESSION_REVISION_STALE") throw error;
|
|
253
|
+
lastConflict = error;
|
|
254
|
+
state = this._canonicalSessionStore.readVerifiedWsTurnState(
|
|
255
|
+
this.session.id,
|
|
256
|
+
requestId,
|
|
257
|
+
{ inputDigest },
|
|
258
|
+
);
|
|
259
|
+
terminal = this._canonicalTurnFromAuthority(
|
|
260
|
+
state,
|
|
261
|
+
requestId,
|
|
262
|
+
userMessage,
|
|
263
|
+
inputDigest,
|
|
264
|
+
);
|
|
265
|
+
if (terminal) return terminal;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
const error = new Error(
|
|
269
|
+
"Canonical WebSocket claim could not settle after revision conflicts",
|
|
270
|
+
{ cause: lastConflict },
|
|
271
|
+
);
|
|
272
|
+
error.code = "CC_WS_TURN_CLAIM_CAS_RETRY_EXHAUSTED";
|
|
273
|
+
throw error;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
_settleCanonicalSuccess(turn, assistantContent) {
|
|
277
|
+
if (typeof assistantContent !== "string" || !assistantContent.trim()) {
|
|
278
|
+
const error = new Error(
|
|
279
|
+
"Canonical WebSocket turn produced no assistant response",
|
|
280
|
+
);
|
|
281
|
+
error.code = "CC_WS_EMPTY_ASSISTANT_RESPONSE";
|
|
282
|
+
throw error;
|
|
283
|
+
}
|
|
284
|
+
turn.settlementAttempted = true;
|
|
285
|
+
const settled = this._canonicalSessionStore.settleWsTurnClaim(
|
|
286
|
+
this.session.id,
|
|
287
|
+
{
|
|
288
|
+
requestId: turn.requestId,
|
|
289
|
+
inputDigest: turn.inputDigest,
|
|
290
|
+
opaqueClaimId: turn.opaqueClaimId,
|
|
291
|
+
outcome: "completed",
|
|
292
|
+
user: turn.userMessage,
|
|
293
|
+
assistant: assistantContent,
|
|
294
|
+
},
|
|
295
|
+
);
|
|
296
|
+
if (settled?.status !== "completed" || !settled.turn) {
|
|
297
|
+
const error = new Error("Canonical WebSocket success was not settled");
|
|
298
|
+
error.code = "CC_WS_TURN_SETTLEMENT_UNKNOWN";
|
|
299
|
+
error.commitState = "unknown";
|
|
300
|
+
throw error;
|
|
301
|
+
}
|
|
302
|
+
this._applyCanonicalMessages(settled.messages);
|
|
303
|
+
turn.settled = true;
|
|
304
|
+
turn.status = "completed";
|
|
305
|
+
turn.response = settled.turn.assistant.content;
|
|
306
|
+
turn.replayed = settled.deduplicated === true;
|
|
307
|
+
return { content: turn.response, replayed: turn.replayed };
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
_settleCanonicalFailure(turn, failureCode) {
|
|
311
|
+
if (
|
|
312
|
+
!turn?.claimAcquired ||
|
|
313
|
+
turn.settled ||
|
|
314
|
+
turn.settlementAttempted ||
|
|
315
|
+
turn.failureSettlementAttempted
|
|
316
|
+
) {
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
turn.failureSettlementAttempted = true;
|
|
320
|
+
const settled = this._canonicalSessionStore.settleWsTurnClaim(
|
|
321
|
+
this.session.id,
|
|
322
|
+
{
|
|
323
|
+
requestId: turn.requestId,
|
|
324
|
+
inputDigest: turn.inputDigest,
|
|
325
|
+
opaqueClaimId: turn.opaqueClaimId,
|
|
326
|
+
outcome: "failed",
|
|
327
|
+
failureCode,
|
|
328
|
+
},
|
|
329
|
+
);
|
|
330
|
+
if (settled?.status !== "failed") {
|
|
331
|
+
const error = new Error("Canonical WebSocket failure was not settled");
|
|
332
|
+
error.code = "CC_WS_TURN_SETTLEMENT_UNKNOWN";
|
|
333
|
+
error.commitState = "unknown";
|
|
334
|
+
throw error;
|
|
335
|
+
}
|
|
336
|
+
turn.settled = true;
|
|
337
|
+
turn.status = "failed";
|
|
338
|
+
this._applyCanonicalMessages(settled.messages);
|
|
339
|
+
return true;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
_ensureMcpRecoveryRuntime() {
|
|
343
|
+
const { session } = this;
|
|
344
|
+
const revision = Number(session.mcpLedgerRecoveryRevision || 0);
|
|
345
|
+
const rawClient = session.mcpClient || null;
|
|
346
|
+
if (!this._mcpRecoveryRuntime || this._mcpRecoveryClient !== rawClient) {
|
|
347
|
+
const controller = this._mcpRecoveryRuntime?.controller || null;
|
|
348
|
+
// Only a newly verified resume revision may lower an existing runtime
|
|
349
|
+
// latch. A transport/client replacement by itself preserves settlement
|
|
350
|
+
// outcome-unknown authority across the new wrapper.
|
|
351
|
+
if (
|
|
352
|
+
controller &&
|
|
353
|
+
this._mcpRecoveryRevision !== revision &&
|
|
354
|
+
typeof controller.replaceVerifiedRecovery === "function"
|
|
355
|
+
) {
|
|
356
|
+
controller.replaceVerifiedRecovery(
|
|
357
|
+
session.mcpLedgerRecovery || {
|
|
358
|
+
incidents: [],
|
|
359
|
+
unsettled: [],
|
|
360
|
+
replayDenied: [],
|
|
361
|
+
},
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
this._mcpRecoveryRuntime = createMcpHostRecoveryRuntime({
|
|
365
|
+
bundle: {
|
|
366
|
+
mcpClient: rawClient,
|
|
367
|
+
externalToolDescriptors: session.externalToolDescriptors || {},
|
|
368
|
+
externalToolExecutors: session.externalToolExecutors || {},
|
|
369
|
+
},
|
|
370
|
+
rawClient,
|
|
371
|
+
sessionId: session.id,
|
|
372
|
+
sink: createSessionMcpLedgerSink(session.id),
|
|
373
|
+
recovery: session.mcpLedgerRecovery || null,
|
|
374
|
+
controller,
|
|
375
|
+
});
|
|
376
|
+
this._mcpRecoveryClient = rawClient;
|
|
377
|
+
this._mcpRecoveryRevision = revision;
|
|
378
|
+
} else if (this._mcpRecoveryRevision !== revision) {
|
|
379
|
+
this._mcpRecoveryRuntime.controller.replaceVerifiedRecovery(
|
|
380
|
+
session.mcpLedgerRecovery || {
|
|
381
|
+
incidents: [],
|
|
382
|
+
unsettled: [],
|
|
383
|
+
replayDenied: [],
|
|
384
|
+
},
|
|
385
|
+
);
|
|
386
|
+
this._mcpRecoveryRevision = revision;
|
|
387
|
+
}
|
|
388
|
+
return this._mcpRecoveryRuntime;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
refreshMcpRecoveryRuntime() {
|
|
392
|
+
try {
|
|
393
|
+
return this._ensureMcpRecoveryRuntime();
|
|
394
|
+
} catch (cause) {
|
|
395
|
+
const error = new Error("WS MCP recovery runtime refresh failed", {
|
|
396
|
+
cause,
|
|
397
|
+
});
|
|
398
|
+
try {
|
|
399
|
+
error.code = cause?.code || "CC_MCP_RECOVERY_REFRESH_FAILED";
|
|
400
|
+
} catch {
|
|
401
|
+
error.code = "CC_MCP_RECOVERY_REFRESH_FAILED";
|
|
402
|
+
}
|
|
403
|
+
// If an earlier runtime exists, make it unusable immediately. The
|
|
404
|
+
// session protocol also attaches an ALL-blocking projection so a future
|
|
405
|
+
// runtime cannot silently recover as clean.
|
|
406
|
+
this._mcpRecoveryRuntime?.controller?.latchAll?.(error.code);
|
|
407
|
+
throw error;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
_recordSessionState(type, payload = {}) {
|
|
412
|
+
if (typeof this.session?._recordSessionStateEvent !== "function") return;
|
|
413
|
+
try {
|
|
414
|
+
this.session._recordSessionStateEvent(type, payload);
|
|
415
|
+
} catch (_err) {
|
|
416
|
+
// Recovery persistence is best-effort for the live turn. A persisted
|
|
417
|
+
// running marker is reconciled fail-closed when the session resumes.
|
|
418
|
+
}
|
|
61
419
|
}
|
|
62
420
|
|
|
63
421
|
/** Resolve the session's approval gate (lazy, opt-in; null when disabled). */
|
|
@@ -80,6 +438,27 @@ export class WSAgentHandler {
|
|
|
80
438
|
* @param {string} [requestId] - id from ws message for response correlation
|
|
81
439
|
*/
|
|
82
440
|
async handleMessage(userMessage, requestId) {
|
|
441
|
+
if (this.session?.canonicalJsonlSession === true) {
|
|
442
|
+
let canonicalRequestId;
|
|
443
|
+
try {
|
|
444
|
+
canonicalRequestId =
|
|
445
|
+
this._canonicalSessionStore.normalizeWsTurnRequestId(requestId);
|
|
446
|
+
} catch (error) {
|
|
447
|
+
this.interaction.emit("error", {
|
|
448
|
+
requestId: null,
|
|
449
|
+
code: error?.code || "CC_WS_REQUEST_ID_INVALID",
|
|
450
|
+
message: error?.message || "WebSocket request id is invalid",
|
|
451
|
+
});
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
return runCanonicalWsTurnExclusive(this.session.id, () =>
|
|
455
|
+
this._handleMessage(userMessage, canonicalRequestId),
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
return this._handleMessage(userMessage, requestId);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
async _handleMessage(userMessage, requestId) {
|
|
83
462
|
if (this._processing) {
|
|
84
463
|
this.interaction.emit("error", {
|
|
85
464
|
requestId,
|
|
@@ -95,12 +474,48 @@ export class WSAgentHandler {
|
|
|
95
474
|
this._activeRequestId = requestId || null;
|
|
96
475
|
let sideEffectLedger = null;
|
|
97
476
|
let diffReviewFollowUps = null;
|
|
477
|
+
let runRecorded = false;
|
|
478
|
+
let canonicalTurn = null;
|
|
98
479
|
|
|
99
480
|
try {
|
|
100
481
|
const { session } = this;
|
|
101
482
|
|
|
102
|
-
|
|
103
|
-
|
|
483
|
+
if (session.canonicalJsonlSession === true) {
|
|
484
|
+
canonicalTurn = this._claimCanonicalTurn(userMessage, requestId);
|
|
485
|
+
if (canonicalTurn.status === "completed") {
|
|
486
|
+
this.interaction.emit("response-complete", {
|
|
487
|
+
requestId,
|
|
488
|
+
content: canonicalTurn.response,
|
|
489
|
+
replayed: true,
|
|
490
|
+
});
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
if (canonicalTurn.status === "failed") {
|
|
494
|
+
this.interaction.emit("error", {
|
|
495
|
+
requestId,
|
|
496
|
+
code: canonicalTurn.failureCode,
|
|
497
|
+
message: "WebSocket request previously settled as failed",
|
|
498
|
+
replayed: true,
|
|
499
|
+
});
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
if (canonicalTurn.pending) {
|
|
503
|
+
this.interaction.emit("response-pending", {
|
|
504
|
+
requestId,
|
|
505
|
+
status: "pending",
|
|
506
|
+
code: "CC_WS_TURN_PENDING",
|
|
507
|
+
remediation: "adjudicate_or_use_new_request_id",
|
|
508
|
+
});
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
} else {
|
|
512
|
+
session.messages.push({ role: "user", content: userMessage });
|
|
513
|
+
}
|
|
514
|
+
this._recordSessionState("run.started", {
|
|
515
|
+
requestId: requestId || null,
|
|
516
|
+
startedAt: new Date().toISOString(),
|
|
517
|
+
});
|
|
518
|
+
runRecorded = true;
|
|
104
519
|
|
|
105
520
|
// Auto-select model based on task type — runnable-first: never switch
|
|
106
521
|
// onto a provider with no usable key (you'd just 401). Keep the
|
|
@@ -134,6 +549,7 @@ export class WSAgentHandler {
|
|
|
134
549
|
interaction: this.interaction,
|
|
135
550
|
db: this.db,
|
|
136
551
|
});
|
|
552
|
+
const mcpRecoveryRuntime = this._ensureMcpRecoveryRuntime();
|
|
137
553
|
|
|
138
554
|
// Run agent loop
|
|
139
555
|
const loopOptions = {
|
|
@@ -152,6 +568,11 @@ export class WSAgentHandler {
|
|
|
152
568
|
externalToolDescriptors: session.externalToolDescriptors || {},
|
|
153
569
|
externalToolExecutors: session.externalToolExecutors || {},
|
|
154
570
|
mcpClient: session.mcpClient || null,
|
|
571
|
+
mcpHostClient: mcpRecoveryRuntime.client || session.mcpClient || null,
|
|
572
|
+
// MCP calls must use the same durable prewrite/settlement contract as
|
|
573
|
+
// headless and REPL sessions. For unknown/write/destructive effects a
|
|
574
|
+
// failed prewrite blocks the network call inside agent-core.
|
|
575
|
+
mcpCallLedger: mcpRecoveryRuntime.ledger,
|
|
155
576
|
shellPolicyOverrides: session.shellPolicyOverrides || null,
|
|
156
577
|
slotFiller,
|
|
157
578
|
interaction: this.interaction,
|
|
@@ -169,9 +590,13 @@ export class WSAgentHandler {
|
|
|
169
590
|
sideEffectLedger = loadSideEffectLedger(session.id);
|
|
170
591
|
diffReviewFollowUps = new DiffReviewFollowUpTracker(sideEffectLedger);
|
|
171
592
|
let currentSideEffectOpId = null;
|
|
593
|
+
let currentTodoWrite = null;
|
|
172
594
|
|
|
173
595
|
const executeAgentTurn = async () => {
|
|
174
|
-
for await (const event of
|
|
596
|
+
for await (const event of this._agentLoop(
|
|
597
|
+
session.messages,
|
|
598
|
+
loopOptions,
|
|
599
|
+
)) {
|
|
175
600
|
switch (event.type) {
|
|
176
601
|
case "slot-filling":
|
|
177
602
|
this.interaction.emit("slot-filling", {
|
|
@@ -189,6 +614,14 @@ export class WSAgentHandler {
|
|
|
189
614
|
display: formatToolArgs(event.tool, event.args),
|
|
190
615
|
});
|
|
191
616
|
currentSideEffectOpId = null;
|
|
617
|
+
currentTodoWrite =
|
|
618
|
+
event.tool === "todo_write" && Array.isArray(event.args?.todos)
|
|
619
|
+
? event.args.todos.map((todo) => ({
|
|
620
|
+
id: todo.id,
|
|
621
|
+
content: todo.content,
|
|
622
|
+
status: todo.status,
|
|
623
|
+
}))
|
|
624
|
+
: null;
|
|
192
625
|
{
|
|
193
626
|
const se = classifyToolSideEffect(event.tool, event.args);
|
|
194
627
|
if (se) {
|
|
@@ -219,6 +652,23 @@ export class WSAgentHandler {
|
|
|
219
652
|
result: event.result,
|
|
220
653
|
error: event.error,
|
|
221
654
|
});
|
|
655
|
+
if (
|
|
656
|
+
event.tool === "todo_write" &&
|
|
657
|
+
currentTodoWrite &&
|
|
658
|
+
!event.error &&
|
|
659
|
+
!event.result?.error &&
|
|
660
|
+
event.result?.success === true &&
|
|
661
|
+
Number.isSafeInteger(event.result.revision)
|
|
662
|
+
) {
|
|
663
|
+
this._recordSessionState("todo.snapshot", {
|
|
664
|
+
todo: {
|
|
665
|
+
sessionId: session.id,
|
|
666
|
+
revision: event.result.revision,
|
|
667
|
+
todos: currentTodoWrite,
|
|
668
|
+
},
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
currentTodoWrite = null;
|
|
222
672
|
if (currentSideEffectOpId) {
|
|
223
673
|
const err = event.error || event.result?.error || null;
|
|
224
674
|
if (event.result?._diffReviewAudit) {
|
|
@@ -240,16 +690,28 @@ export class WSAgentHandler {
|
|
|
240
690
|
break;
|
|
241
691
|
|
|
242
692
|
case "response-complete":
|
|
243
|
-
if (
|
|
244
|
-
|
|
245
|
-
|
|
693
|
+
if (session.canonicalJsonlSession === true) {
|
|
694
|
+
const settled = this._settleCanonicalSuccess(
|
|
695
|
+
canonicalTurn,
|
|
696
|
+
event.content,
|
|
697
|
+
);
|
|
698
|
+
this.interaction.emit("response-complete", {
|
|
699
|
+
requestId,
|
|
700
|
+
content: settled.content,
|
|
701
|
+
replayed: settled.replayed,
|
|
702
|
+
});
|
|
703
|
+
} else {
|
|
704
|
+
if (event.content) {
|
|
705
|
+
session.messages.push({
|
|
706
|
+
role: "assistant",
|
|
707
|
+
content: event.content,
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
this.interaction.emit("response-complete", {
|
|
711
|
+
requestId,
|
|
246
712
|
content: event.content,
|
|
247
713
|
});
|
|
248
714
|
}
|
|
249
|
-
this.interaction.emit("response-complete", {
|
|
250
|
-
requestId,
|
|
251
|
-
content: event.content,
|
|
252
|
-
});
|
|
253
715
|
break;
|
|
254
716
|
}
|
|
255
717
|
}
|
|
@@ -273,6 +735,13 @@ export class WSAgentHandler {
|
|
|
273
735
|
} else {
|
|
274
736
|
await runAgentTurn();
|
|
275
737
|
}
|
|
738
|
+
if (session.canonicalJsonlSession === true && !canonicalTurn?.settled) {
|
|
739
|
+
const error = new Error(
|
|
740
|
+
"Canonical WebSocket turn completed without an assistant response",
|
|
741
|
+
);
|
|
742
|
+
error.code = "CC_WS_EMPTY_ASSISTANT_RESPONSE";
|
|
743
|
+
throw error;
|
|
744
|
+
}
|
|
276
745
|
if (
|
|
277
746
|
diffReviewFollowUps.complete(sideEffectLedger, {
|
|
278
747
|
status: "completed-without-reproposal",
|
|
@@ -284,6 +753,40 @@ export class WSAgentHandler {
|
|
|
284
753
|
// Update last activity
|
|
285
754
|
session.lastActivity = new Date().toISOString();
|
|
286
755
|
} catch (err) {
|
|
756
|
+
let surfacedError = err;
|
|
757
|
+
if (
|
|
758
|
+
canonicalTurn?.claimAcquired &&
|
|
759
|
+
!canonicalTurn.settled &&
|
|
760
|
+
!canonicalTurn.settlementAttempted
|
|
761
|
+
) {
|
|
762
|
+
const failureCode = isAbortError(err)
|
|
763
|
+
? "CC_WS_TURN_INTERRUPTED"
|
|
764
|
+
: err?.code === "CC_WS_EMPTY_ASSISTANT_RESPONSE"
|
|
765
|
+
? "CC_WS_EMPTY_ASSISTANT_RESPONSE"
|
|
766
|
+
: "CC_WS_TURN_FAILED";
|
|
767
|
+
try {
|
|
768
|
+
this._settleCanonicalFailure(canonicalTurn, failureCode);
|
|
769
|
+
} catch (settlementError) {
|
|
770
|
+
surfacedError = new Error(
|
|
771
|
+
"WebSocket turn settlement is outcome-unknown; explicit adjudication or a new request id is required",
|
|
772
|
+
{ cause: settlementError },
|
|
773
|
+
);
|
|
774
|
+
surfacedError.code = "CC_WS_TURN_SETTLEMENT_UNKNOWN";
|
|
775
|
+
}
|
|
776
|
+
} else if (
|
|
777
|
+
canonicalTurn?.claimAcquired &&
|
|
778
|
+
canonicalTurn.settlementAttempted &&
|
|
779
|
+
!canonicalTurn.settled
|
|
780
|
+
) {
|
|
781
|
+
surfacedError = new Error(
|
|
782
|
+
"WebSocket turn settlement is outcome-unknown; explicit adjudication or a new request id is required",
|
|
783
|
+
{ cause: err },
|
|
784
|
+
);
|
|
785
|
+
surfacedError.code = "CC_WS_TURN_SETTLEMENT_UNKNOWN";
|
|
786
|
+
}
|
|
787
|
+
if (canonicalTurn?.baseMessages && canonicalTurn.status !== "completed") {
|
|
788
|
+
this.session.messages = [...canonicalTurn.baseMessages];
|
|
789
|
+
}
|
|
287
790
|
if (
|
|
288
791
|
sideEffectLedger &&
|
|
289
792
|
diffReviewFollowUps?.complete(sideEffectLedger, {
|
|
@@ -299,18 +802,27 @@ export class WSAgentHandler {
|
|
|
299
802
|
|
|
300
803
|
this.interaction.emit("error", {
|
|
301
804
|
requestId,
|
|
302
|
-
code: "AGENT_ERROR",
|
|
303
|
-
message:
|
|
805
|
+
code: surfacedError?.code || "AGENT_ERROR",
|
|
806
|
+
message: surfacedError.message,
|
|
304
807
|
});
|
|
305
808
|
|
|
306
809
|
// Record error in context engine
|
|
307
810
|
if (this.session.contextEngine) {
|
|
308
811
|
this.session.contextEngine.recordError({
|
|
309
812
|
step: "ws-agent-loop",
|
|
310
|
-
message:
|
|
813
|
+
message: surfacedError.message,
|
|
311
814
|
});
|
|
312
815
|
}
|
|
313
816
|
} finally {
|
|
817
|
+
if (canonicalTurn?.baseMessages && canonicalTurn.status !== "completed") {
|
|
818
|
+
this.session.messages = [...canonicalTurn.baseMessages];
|
|
819
|
+
}
|
|
820
|
+
if (runRecorded) {
|
|
821
|
+
this._recordSessionState("run.settled", {
|
|
822
|
+
requestId: requestId || null,
|
|
823
|
+
settledAt: new Date().toISOString(),
|
|
824
|
+
});
|
|
825
|
+
}
|
|
314
826
|
this._processing = false;
|
|
315
827
|
if (this._abortController === abortController) {
|
|
316
828
|
this._abortController = null;
|
|
@@ -334,6 +846,12 @@ export class WSAgentHandler {
|
|
|
334
846
|
this.interaction.rejectAllPending(reason);
|
|
335
847
|
}
|
|
336
848
|
|
|
849
|
+
this._recordSessionState("run.interrupted", {
|
|
850
|
+
requestId: interruptedRequestId,
|
|
851
|
+
interruptedAt: new Date().toISOString(),
|
|
852
|
+
reason: "client_interrupt",
|
|
853
|
+
});
|
|
854
|
+
|
|
337
855
|
return {
|
|
338
856
|
sessionId: this.session?.id || null,
|
|
339
857
|
interrupted: true,
|
|
@@ -343,6 +861,8 @@ export class WSAgentHandler {
|
|
|
343
861
|
}
|
|
344
862
|
|
|
345
863
|
destroy() {
|
|
864
|
+
const wasProcessing = this._processing;
|
|
865
|
+
const interruptedRequestId = this._activeRequestId || null;
|
|
346
866
|
const reason = createAbortError("Session closed");
|
|
347
867
|
if (this._abortController && !this._abortController.signal.aborted) {
|
|
348
868
|
this._abortController.abort(reason);
|
|
@@ -350,6 +870,13 @@ export class WSAgentHandler {
|
|
|
350
870
|
if (typeof this.interaction?.rejectAllPending === "function") {
|
|
351
871
|
this.interaction.rejectAllPending(reason);
|
|
352
872
|
}
|
|
873
|
+
if (wasProcessing) {
|
|
874
|
+
this._recordSessionState("run.interrupted", {
|
|
875
|
+
requestId: interruptedRequestId,
|
|
876
|
+
interruptedAt: new Date().toISOString(),
|
|
877
|
+
reason: "session_closed",
|
|
878
|
+
});
|
|
879
|
+
}
|
|
353
880
|
}
|
|
354
881
|
|
|
355
882
|
/**
|