chainlesschain 0.166.17 → 0.166.18
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 +14 -7
- package/package.json +1 -1
- package/src/assets/web-panel/assets/{AIOps-CVW2n2rh.js → AIOps-CQSBl3hY.js} +1 -1
- package/src/assets/web-panel/assets/{ActionButton-DtuM163O.js → ActionButton-IQt-vRLt.js} +1 -1
- package/src/assets/web-panel/assets/{Analytics-BXvl_qHu.js → Analytics-DkHC8O7k.js} +3 -3
- package/src/assets/web-panel/assets/{AppLayout-VDBTFKOp.js → AppLayout-CSti2P2T.js} +3 -3
- package/src/assets/web-panel/assets/{Artifacts-BNz2xCiG.js → Artifacts-C57hxn3v.js} +1 -1
- package/src/assets/web-panel/assets/{Audit-DTu9Hn9P.js → Audit-DByLntcf.js} +1 -1
- package/src/assets/web-panel/assets/{BackgroundAgents-D2OCPzLe.js → BackgroundAgents-D1Bd2EOa.js} +1 -1
- package/src/assets/web-panel/assets/{Backup-C9M-vG7G.js → Backup-VstHzHng.js} +1 -1
- package/src/assets/web-panel/assets/{BaseInput-BUkCNiUQ.js → BaseInput-CLhdexIf.js} +1 -1
- package/src/assets/web-panel/assets/{Chat-OJ2ajF7l.js → Chat-BefC_JZS.js} +6 -6
- package/src/assets/web-panel/assets/{ChatBubbleRenderer-BdZt76Ab.js → ChatBubbleRenderer-DbXMvgmn.js} +1 -1
- package/src/assets/web-panel/assets/{Checkbox-C1gXKDsc.js → Checkbox-CEY982vx.js} +1 -1
- package/src/assets/web-panel/assets/{Codegen-BXbznLg7.js → Codegen-Dcm_DTvJ.js} +1 -1
- package/src/assets/web-panel/assets/{Col-CbCq5N0i.js → Col-C8SSu4KA.js} +1 -1
- package/src/assets/web-panel/assets/{Community-V8Ks6Yun.js → Community-BVV9vwRR.js} +1 -1
- package/src/assets/web-panel/assets/{Compact-DkeHQTpQ.js → Compact-B7c5Vo18.js} +1 -1
- package/src/assets/web-panel/assets/{Compliance-JeLKwn4Q.js → Compliance-Tq9jSZ5a.js} +1 -1
- package/src/assets/web-panel/assets/{Cowork-azfetcBz.js → Cowork-BJUjT09Q.js} +3 -3
- package/src/assets/web-panel/assets/{Cron-Q691i_Gp.js → Cron-CjV9PEaS.js} +2 -2
- package/src/assets/web-panel/assets/{Crosschain-BLjDRbr_.js → Crosschain-Dl7ReL8F.js} +1 -1
- package/src/assets/web-panel/assets/{DID-D8ptXplK.js → DID-CG8PjWmM.js} +2 -2
- package/src/assets/web-panel/assets/{Dashboard-Ctj2VVZL.js → Dashboard-CDBM6wmF.js} +2 -2
- package/src/assets/web-panel/assets/{Dropdown-D8VgkMJ8.js → Dropdown-8_55bXTD.js} +1 -1
- package/src/assets/web-panel/assets/{EmailListRenderer-CQPe5S6q.js → EmailListRenderer-D3qOU1Cm.js} +1 -1
- package/src/assets/web-panel/assets/{FamilyGuardDashboard-ySA-7SiN.js → FamilyGuardDashboard-Bv5oWMZF.js} +1 -1
- package/src/assets/web-panel/assets/{Federation-1PMD-fBf.js → Federation-hpZ1xkKd.js} +1 -1
- package/src/assets/web-panel/assets/{FormItemContext-C_jr6U4Q.js → FormItemContext-BN7GT191.js} +1 -1
- package/src/assets/web-panel/assets/{GenericCardRenderer-Bu3bKf2B.js → GenericCardRenderer-PCRhfA7M.js} +1 -1
- package/src/assets/web-panel/assets/{Git-Dv4Fa_T5.js → Git-CIlP2vy7.js} +2 -2
- package/src/assets/web-panel/assets/{Governance-DOEy1n1k.js → Governance-81lgm7YL.js} +1 -1
- package/src/assets/web-panel/assets/{Inference-DkvqzWcJ.js → Inference-Cs24xMOV.js} +1 -1
- package/src/assets/web-panel/assets/{KnowledgeGraph-DdUJK949.js → KnowledgeGraph-CrJLVCZo.js} +1 -1
- package/src/assets/web-panel/assets/{Logs-CRelcdUZ.js → Logs-DLyO8RKT.js} +2 -2
- package/src/assets/web-panel/assets/{MarkdownRenderer-0AHbbTA4.js → MarkdownRenderer-DBOqijrP.js} +1 -1
- package/src/assets/web-panel/assets/{Marketplace-BuuBKsev.js → Marketplace-Dz7AbQZc.js} +1 -1
- package/src/assets/web-panel/assets/{McpTools-DlgpEmA1.js → McpTools-BM0aFiWv.js} +3 -3
- package/src/assets/web-panel/assets/{Memory-DTfdqUGy.js → Memory-C9SJzENX.js} +2 -2
- package/src/assets/web-panel/assets/{MobileBridge-CXLE5ZFO.js → MobileBridge-BO2HnNRk.js} +1 -1
- package/src/assets/web-panel/assets/{MobileProjects-Dz25OB0n.js → MobileProjects-CK_jMz0l.js} +1 -1
- package/src/assets/web-panel/assets/{Mtc-kEL0fhgD.js → Mtc-CfhrJsdO.js} +2 -2
- package/src/assets/web-panel/assets/{MtcAudit-BE4UvFJU.js → MtcAudit-BE2ELxgI.js} +4 -4
- package/src/assets/web-panel/assets/{Multisig-CSApSn8c.js → Multisig-CgR_E3Jd.js} +3 -3
- package/src/assets/web-panel/assets/{NLProgramming-D11FpKWx.js → NLProgramming-Cw9445_K.js} +1 -1
- package/src/assets/web-panel/assets/{Notes-CDL-D2CS.js → Notes-DZimkTrb.js} +3 -3
- package/src/assets/web-panel/assets/{NotificationSettings-C0Q6lO-c.js → NotificationSettings-DxHVh4uT.js} +1 -1
- package/src/assets/web-panel/assets/OrderTableRenderer-Iy-pnX56.js +1 -0
- package/src/assets/web-panel/assets/{Organization-Dc-maVAq.js → Organization-pPXJtWo4.js} +4 -4
- package/src/assets/web-panel/assets/{Overflow-B5mUpSvi.js → Overflow-YamdTJwA.js} +1 -1
- package/src/assets/web-panel/assets/{P2P-TjXV53wq.js → P2P-BvqP53x7.js} +2 -2
- package/src/assets/web-panel/assets/PdhVaultBrowser-Blz1Xn2n.js +7 -0
- package/src/assets/web-panel/assets/{Permissions-DKRzQ2O6.js → Permissions-CgFRQqFJ.js} +4 -4
- package/src/assets/web-panel/assets/{PersonalDataHub-Dx2eqft8.js → PersonalDataHub-CFeo3-6O.js} +4 -4
- package/src/assets/web-panel/assets/{Pipeline-CnYZMB5p.js → Pipeline-BkaRojEK.js} +1 -1
- package/src/assets/web-panel/assets/{Privacy-BonKpPnp.js → Privacy-BNZEx2Qp.js} +1 -1
- package/src/assets/web-panel/assets/{ProjectInit-DWO0Du3J.js → ProjectInit-HUBOgEEK.js} +2 -2
- package/src/assets/web-panel/assets/{ProjectSettings-C9jqyYRv.js → ProjectSettings-CFMmhROS.js} +2 -2
- package/src/assets/web-panel/assets/{Projects-CYpKwXbz.js → Projects-Dc517BXp.js} +1 -1
- package/src/assets/web-panel/assets/{Providers-CW-fkwJq.js → Providers-DTLf8bgj.js} +1 -1
- package/src/assets/web-panel/assets/{QrScannerModal-Cw0J3Zud.js → QrScannerModal-BBNjPszk.js} +1 -1
- package/src/assets/web-panel/assets/{QuickAsk-BH4A4IpR.js → QuickAsk-DCsHvk3G.js} +1 -1
- package/src/assets/web-panel/assets/{Recommend-CDwMwJus.js → Recommend-Dpr5YSop.js} +1 -1
- package/src/assets/web-panel/assets/{RemoteSession-DKIPwzTf.js → RemoteSession-DmKnvqGg.js} +2 -2
- package/src/assets/web-panel/assets/{Reputation-CklDj7qS.js → Reputation-CSRfuurX.js} +1 -1
- package/src/assets/web-panel/assets/{Row-DJWZKsH0.js → Row-CDj3pQ_w.js} +1 -1
- package/src/assets/web-panel/assets/{RssFeed-BfSLCewo.js → RssFeed-DI0a_kNq.js} +2 -2
- package/src/assets/web-panel/assets/{Search-B0IST--x.js → Search-jAy7B2nU.js} +1 -1
- package/src/assets/web-panel/assets/{Security-h1sYNWtt.js → Security-CkHTqYhc.js} +4 -4
- package/src/assets/web-panel/assets/{Services-Gh0-oxI_.js → Services-CP-0Nzga.js} +2 -2
- package/src/assets/web-panel/assets/{Skeleton-CNDV_jOs.js → Skeleton-BkF5-p3n.js} +1 -1
- package/src/assets/web-panel/assets/{Skills-ByCLTh1n.js → Skills-BDu-utDE.js} +1 -1
- package/src/assets/web-panel/assets/{Sla-BfyrJTJz.js → Sla-CQvq_2Qb.js} +1 -1
- package/src/assets/web-panel/assets/{SpeechSettings-BQzo9kNX.js → SpeechSettings-T7Ap512g.js} +1 -1
- package/src/assets/web-panel/assets/{SyncSettings-B6fS6z_1.js → SyncSettings-Bt-PLvot.js} +2 -2
- package/src/assets/web-panel/assets/{Tasks-C-uKCP-l.js → Tasks-yLEcCogg.js} +1 -1
- package/src/assets/web-panel/assets/{Templates-D6oDy7wL.js → Templates-ByN3fmbr.js} +1 -1
- package/src/assets/web-panel/assets/{Tenant-D3LT2wNQ.js → Tenant-DBI7hITH.js} +1 -1
- package/src/assets/web-panel/assets/{Terminal-BteLcv_O.js → Terminal-B77_DlGX.js} +2 -2
- package/src/assets/web-panel/assets/{TimelineRenderer-DHHuxfqH.js → TimelineRenderer-CsLTB_QO.js} +1 -1
- package/src/assets/web-panel/assets/{Tokens-BRQeykXw.js → Tokens-BV2N6cR8.js} +1 -1
- package/src/assets/web-panel/assets/{Trigger-p2XaFWEu.js → Trigger-CjXWGH3p.js} +1 -1
- package/src/assets/web-panel/assets/{Trust-BxadBMft.js → Trust-uqXIq3WC.js} +1 -1
- package/src/assets/web-panel/assets/{UkeySign-DRBP7LDk.js → UkeySign-D-6qu4vY.js} +1 -1
- package/src/assets/web-panel/assets/{VideoEditing-CZ3NZkh7.js → VideoEditing-CxGmx_2e.js} +1 -1
- package/src/assets/web-panel/assets/{Wallet-C3NTBN7G.js → Wallet-DSq7WlAg.js} +4 -4
- package/src/assets/web-panel/assets/{WebAuthn-C7LVgMlb.js → WebAuthn-CDBiD57O.js} +2 -2
- package/src/assets/web-panel/assets/{WorkflowEditor-0_Iveog7.js → WorkflowEditor-Z8f63TSb.js} +1 -1
- package/src/assets/web-panel/assets/{chat-DzzluYo3.js → chat-B-UZFBjy.js} +1 -1
- package/src/assets/web-panel/assets/{colors-DSMYXpaj.js → colors-CFk7K-7Q.js} +1 -1
- package/src/assets/web-panel/assets/{compact-item-W76u1VSV.js → compact-item-X0IVMvgi.js} +1 -1
- package/src/assets/web-panel/assets/{createContext-otsESjb5.js → createContext-DWg4j2n6.js} +1 -1
- package/src/assets/web-panel/assets/devWarning-B2IW1J_J.js +1 -0
- package/src/assets/web-panel/assets/{hasIn-3sNLrvug.js → hasIn-CkVCwNNF.js} +1 -1
- package/src/assets/web-panel/assets/{index-BdtmEKat.js → index-5OcZHdzc.js} +1 -1
- package/src/assets/web-panel/assets/{index-DS9WYDMf.js → index-B273IY-E.js} +1 -1
- package/src/assets/web-panel/assets/{index-NaO9AE-F.js → index-B3-B3FWD.js} +1 -1
- package/src/assets/web-panel/assets/{index-BcGJtmHM.js → index-BB4KHHcv.js} +1 -1
- package/src/assets/web-panel/assets/index-BCp2ir-1.js +1 -0
- package/src/assets/web-panel/assets/{index-pVm_iUre.js → index-BG-GaZri.js} +1 -1
- package/src/assets/web-panel/assets/{index-BpcQYzP7.js → index-BPBia4b-.js} +1 -1
- package/src/assets/web-panel/assets/{index-BXLx9HfA.js → index-BipwEbTA.js} +1 -1
- package/src/assets/web-panel/assets/{index-uSCkbpZH.js → index-BoskgPt9.js} +1 -1
- package/src/assets/web-panel/assets/{index-DMmdIpLA.js → index-Btqk6zWb.js} +1 -1
- package/src/assets/web-panel/assets/index-Bw4iuzRD.js +1 -0
- package/src/assets/web-panel/assets/{index-DLDh1OW3.js → index-BzXjYUmd.js} +1 -1
- package/src/assets/web-panel/assets/{index-B9X_jqXe.js → index-C1ZAOJRW.js} +1 -1
- package/src/assets/web-panel/assets/{index-vBKPcmAP.js → index-CCLwoATF.js} +1 -1
- package/src/assets/web-panel/assets/{index-vUmYkqmu.js → index-CDfSD07S.js} +1 -1
- package/src/assets/web-panel/assets/{index-D7A5U2IH.js → index-CLlP1E4X.js} +1 -1
- package/src/assets/web-panel/assets/{index-ClOFeZ-t.js → index-CMCEXBRh.js} +1 -1
- package/src/assets/web-panel/assets/{index-Cg86EzNp.js → index-CN8HZlLH.js} +1 -1
- package/src/assets/web-panel/assets/{index-Ddd4mird.js → index-CNKFsBlz.js} +1 -1
- package/src/assets/web-panel/assets/{index-CE7tSow-.js → index-CUBkvFPH.js} +1 -1
- package/src/assets/web-panel/assets/{index-GlIOE4ja.js → index-Ca0mij1n.js} +1 -1
- package/src/assets/web-panel/assets/{index-DdU7IkKX.js → index-CbIAWbma.js} +1 -1
- package/src/assets/web-panel/assets/{index-UUHCwfNq.js → index-CbihMThv.js} +1 -1
- package/src/assets/web-panel/assets/{index-BRsD1PT2.js → index-CvOa-IFV.js} +1 -1
- package/src/assets/web-panel/assets/{index-C2aht9-M.js → index-Cvwu_rA_.js} +1 -1
- package/src/assets/web-panel/assets/{index-BJsQio5O.js → index-D-EJNxgR.js} +1 -1
- package/src/assets/web-panel/assets/{index-q7ftLqNt.js → index-D8uEL8Uw.js} +1 -1
- package/src/assets/web-panel/assets/{index-B1I1AYJs.js → index-D92g4l3n.js} +1 -1
- package/src/assets/web-panel/assets/{index-DZKAzEge.js → index-DCqpl_E_.js} +1 -1
- package/src/assets/web-panel/assets/{index-CKoFyHYQ.js → index-DLSBks8h.js} +1 -1
- package/src/assets/web-panel/assets/{index-BDlDO2px.js → index-Db_5xhrU.js} +1 -1
- package/src/assets/web-panel/assets/{index-CENWwjef.js → index-DcDggpWR.js} +1 -1
- package/src/assets/web-panel/assets/{index-DH4cl52p.js → index-DeWKPQGs.js} +1 -1
- package/src/assets/web-panel/assets/{index-DTA8Iavv.js → index-DhVHoqGL.js} +3 -3
- package/src/assets/web-panel/assets/{index-DmpaC2yk.js → index-DyWlOuak.js} +1 -1
- package/src/assets/web-panel/assets/{index-BA8mZxd-.js → index-LU54bChK.js} +1 -1
- package/src/assets/web-panel/assets/{index-CtFOt5x1.js → index-OjnAwUJo.js} +1 -1
- package/src/assets/web-panel/assets/{index-B5LOYdYm.js → index-P83LDnCz.js} +1 -1
- package/src/assets/web-panel/assets/{index-MhQQ3h8q.js → index-_-9k3Tna.js} +1 -1
- package/src/assets/web-panel/assets/{initDefaultProps-DF6llUXV.js → initDefaultProps-CFNgY8lJ.js} +1 -1
- package/src/assets/web-panel/assets/{motion-vtDV8_5K.js → motion-D-5RrDzn.js} +1 -1
- package/src/assets/web-panel/assets/{move-B6c0bdy2.js → move-DN-L0Bd-.js} +1 -1
- package/src/assets/web-panel/assets/{mtc-parser-DlLYWuBK.js → mtc-parser-6mgLSeCK.js} +1 -1
- package/src/assets/web-panel/assets/{omit-BH0zOxLN.js → omit-ClWW8eTP.js} +1 -1
- package/src/assets/web-panel/assets/{pickAttrs-D9di8_In.js → pickAttrs-Vystq3R8.js} +1 -1
- package/src/assets/web-panel/assets/{placementArrow-BDSngufM.js → placementArrow-D0H9hK4W.js} +1 -1
- package/src/assets/web-panel/assets/{responsiveObserve-C_EawMvP.js → responsiveObserve-B3iNRU-a.js} +1 -1
- package/src/assets/web-panel/assets/{slide-B_4wShxA.js → slide-CiMXe6am.js} +1 -1
- package/src/assets/web-panel/assets/{statusUtils-CbQu6qJ-.js → statusUtils-CGDZJ1uT.js} +1 -1
- package/src/assets/web-panel/assets/{styleChecker-CvXJWYXb.js → styleChecker-D2zA6NkY.js} +1 -1
- package/src/assets/web-panel/assets/{useFlexGapSupport-jjY1XknO.js → useFlexGapSupport-C1sYU6QE.js} +1 -1
- package/src/assets/web-panel/assets/{useFs-CMXBdsK_.js → useFs-BzUHSjg2.js} +1 -1
- package/src/assets/web-panel/assets/{usePersonalDataHub-YbAhhPXx.js → usePersonalDataHub-CxB5yZCq.js} +1 -1
- package/src/assets/web-panel/assets/{vnode-BFCTKc0H.js → vnode-BfUfMwtc.js} +1 -1
- package/src/assets/web-panel/assets/{zoom-CY9aBl5O.js → zoom-CFYmj1TO.js} +1 -1
- package/src/assets/web-panel/index.html +1 -1
- package/src/command-help-index.json +1 -1
- package/src/commands/agent.js +80 -2
- package/src/commands/evolution.js +33 -27
- package/src/commands/serve.js +11 -2
- package/src/data/changelog.json +5 -5
- package/src/gateways/ws/session-protocol.js +1 -0
- package/src/gateways/ws/ws-agent-handler.js +70 -2
- package/src/gateways/ws/ws-server.js +8 -0
- package/src/lib/app-server/cli-agent-kernel-adapter.js +4 -0
- package/src/lib/app-server/graph-runtime.js +115 -8
- package/src/lib/app-server/server.js +21 -2
- package/src/lib/app-server/websocket-transport.js +2 -0
- package/src/lib/evolution/agent-evolution-ingress.js +300 -0
- package/src/lib/evolution/agent-evolution-runtime-composition-brand.js +22 -0
- package/src/lib/evolution/agent-evolution-runtime-composition.js +369 -0
- package/src/lib/evolution/evidence-backed-wiki-maintainer.js +752 -0
- package/src/lib/evolution/evolution-artifact-ports.js +48 -0
- package/src/lib/evolution/evolution-eval-gate.js +11 -4
- package/src/lib/evolution/evolution-evidence-artifact-adapter.js +499 -0
- package/src/lib/evolution/evolution-evidence-projector.js +61 -1
- package/src/lib/evolution/evolution-file-witness.js +601 -0
- package/src/lib/evolution/evolution-ledger-file-backend.js +176 -0
- package/src/lib/evolution/evolution-ledger-ports.js +353 -16
- package/src/lib/evolution/evolution-ledger.js +1355 -54
- package/src/lib/evolution/evolution-run-ledger-adapter.js +409 -0
- package/src/lib/evolution/evolution-run-wiki-maintenance-source.js +300 -0
- package/src/lib/evolution/scheduled-batch-wiki-maintenance-source.js +368 -0
- package/src/lib/evolution/skill-candidate-registry.js +649 -0
- package/src/lib/evolution/skill-promotion-controller.js +109 -38
- package/src/lib/evolution/skill-promotion-review-ledger-adapter.js +451 -0
- package/src/lib/evolution/skill-promotion-review.js +793 -0
- package/src/lib/evolution/skill-registry-transition-capability.js +55 -0
- package/src/lib/evolution/skill-registry-transition-ledger-adapter.js +1280 -0
- package/src/lib/evolution/skill-registry-transition-source.js +372 -0
- package/src/lib/evolution/skill-release-registry.js +2191 -11
- package/src/lib/evolution/skill-target-matrix-eval.js +133 -10
- package/src/lib/evolution/structured-memory-agent-control-plane.js +222 -0
- package/src/lib/evolution/structured-memory-authority-ledger-adapter.js +351 -0
- package/src/lib/evolution/structured-memory-ledger-adapter.js +220 -0
- package/src/lib/evolution/structured-memory-policy-receipt-writer.js +164 -0
- package/src/lib/evolution/structured-memory-post-compact-hook.js +87 -0
- package/src/lib/evolution/structured-memory-promotion-receipt-writer.js +221 -0
- package/src/lib/evolution/structured-memory-semantic-review-pipeline.js +313 -0
- package/src/lib/evolution/wiki-maintainer-ledger-adapter.js +200 -0
- package/src/lib/evolution/wiki-maintenance-trigger-ledger-adapter.js +687 -0
- package/src/lib/evolution-system.js +65 -30
- package/src/lib/mcp-lifecycle-authority.js +21 -2
- package/src/lib/remote-approval-bridge.js +24 -0
- package/src/lib/scheduler-kernel/store.js +62 -14
- package/src/repl/agent-repl.js +45 -0
- package/src/runtime/agent-runtime.js +114 -1
- package/src/runtime/headless-runner.js +19 -0
- package/src/runtime/headless-stream.js +43 -0
- package/src/runtime/runtime-factory.js +19 -1
- package/src/assets/web-panel/assets/OrderTableRenderer-ZRE0OKbj.js +0 -1
- package/src/assets/web-panel/assets/PdhVaultBrowser-DvV2btIr.js +0 -7
- package/src/assets/web-panel/assets/devWarning-BztaXF84.js +0 -1
- package/src/assets/web-panel/assets/index-4jP_hG_4.js +0 -1
- package/src/assets/web-panel/assets/index-zxwuAXL5.js +0 -1
- package/src/lib/learning/learning-hooks.js +0 -123
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import evolutionRun from "@chainlesschain/session-core/evolution-run";
|
|
3
|
+
|
|
4
|
+
import { EvolutionEvidenceArtifactAdapter } from "./evolution-evidence-artifact-adapter.js";
|
|
5
|
+
import { EvolutionRunLedgerAdapter } from "./evolution-run-ledger-adapter.js";
|
|
6
|
+
import { captureEvolutionRunWikiMaintenanceProducer } from "./evolution-run-wiki-maintenance-source.js";
|
|
7
|
+
import { WIKI_MAINTENANCE_TRIGGER_KIND } from "./wiki-maintenance-trigger-ledger-adapter.js";
|
|
8
|
+
|
|
9
|
+
const { EVOLUTION_RUN_EVENT_SCHEMA, EVENT_TYPES } = evolutionRun;
|
|
10
|
+
|
|
11
|
+
export const AGENT_EVOLUTION_INGRESS_SCHEMA =
|
|
12
|
+
"chainlesschain.agent-evolution-ingress/v1";
|
|
13
|
+
export const AGENT_EVOLUTION_INGRESS_FAILED_CODE =
|
|
14
|
+
"CC_AGENT_EVOLUTION_INGRESS_FAILED";
|
|
15
|
+
|
|
16
|
+
const INGRESSES = new WeakSet();
|
|
17
|
+
const CORE_EVENT_KINDS = new Map([
|
|
18
|
+
["tool-executing", "tool-requested"],
|
|
19
|
+
["tool-result", "tool-completed"],
|
|
20
|
+
["tool-error", "tool-failed"],
|
|
21
|
+
["response-complete", "response-completed"],
|
|
22
|
+
["run-ended", "goal-ended"],
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
function requiredString(value, label) {
|
|
26
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
27
|
+
throw new TypeError(`${label} is required`);
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function canonical(value) {
|
|
33
|
+
if (value === null || typeof value === "boolean") {
|
|
34
|
+
return JSON.stringify(value);
|
|
35
|
+
}
|
|
36
|
+
if (typeof value === "number") {
|
|
37
|
+
if (!Number.isFinite(value)) {
|
|
38
|
+
throw new TypeError("Agent evolution evidence must be finite JSON");
|
|
39
|
+
}
|
|
40
|
+
return JSON.stringify(value);
|
|
41
|
+
}
|
|
42
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
43
|
+
if (!value || typeof value !== "object") {
|
|
44
|
+
throw new TypeError("Agent evolution evidence must be JSON-compatible");
|
|
45
|
+
}
|
|
46
|
+
if (Array.isArray(value)) {
|
|
47
|
+
return `[${value.map(canonical).join(",")}]`;
|
|
48
|
+
}
|
|
49
|
+
const prototype = Object.getPrototypeOf(value);
|
|
50
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
51
|
+
throw new TypeError("Agent evolution evidence must use plain objects");
|
|
52
|
+
}
|
|
53
|
+
return `{${Object.keys(value)
|
|
54
|
+
.sort()
|
|
55
|
+
.map((key) => `${JSON.stringify(key)}:${canonical(value[key])}`)
|
|
56
|
+
.join(",")}}`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function clone(value) {
|
|
60
|
+
return JSON.parse(canonical(value));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function digest(value) {
|
|
64
|
+
return `sha256:${crypto.createHash("sha256").update(canonical(value)).digest("hex")}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function timestamp(value, label) {
|
|
68
|
+
const date = new Date(value);
|
|
69
|
+
if (!Number.isFinite(date.getTime()) || date.toISOString() !== value) {
|
|
70
|
+
throw new TypeError(`${label} must be a canonical timestamp`);
|
|
71
|
+
}
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function normalizeId(value, label) {
|
|
76
|
+
const result = requiredString(value, label);
|
|
77
|
+
if (Buffer.byteLength(result, "utf8") > 256) {
|
|
78
|
+
throw new TypeError(`${label} is too long`);
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function guardIngress(operation) {
|
|
84
|
+
return Promise.resolve(operation).catch((cause) => {
|
|
85
|
+
if (cause?.code === AGENT_EVOLUTION_INGRESS_FAILED_CODE) throw cause;
|
|
86
|
+
const error = new Error(
|
|
87
|
+
`Agent evolution ingress failed: ${cause?.message || String(cause)}`,
|
|
88
|
+
{ cause },
|
|
89
|
+
);
|
|
90
|
+
error.code = AGENT_EVOLUTION_INGRESS_FAILED_CODE;
|
|
91
|
+
throw error;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function createAgentEvolutionIngress({
|
|
96
|
+
evidenceAdapter,
|
|
97
|
+
runAdapter,
|
|
98
|
+
sourceEnvelopeAuthority,
|
|
99
|
+
wikiMaintenanceProducer = null,
|
|
100
|
+
completionTriggerKind = WIKI_MAINTENANCE_TRIGGER_KIND.SESSION_END,
|
|
101
|
+
now = () => new Date(),
|
|
102
|
+
idGenerator = () => crypto.randomUUID(),
|
|
103
|
+
} = {}) {
|
|
104
|
+
if (!(evidenceAdapter instanceof EvolutionEvidenceArtifactAdapter)) {
|
|
105
|
+
throw new TypeError("an EvolutionEvidenceArtifactAdapter is required");
|
|
106
|
+
}
|
|
107
|
+
if (!(runAdapter instanceof EvolutionRunLedgerAdapter)) {
|
|
108
|
+
throw new TypeError("an EvolutionRunLedgerAdapter is required");
|
|
109
|
+
}
|
|
110
|
+
if (typeof sourceEnvelopeAuthority?.issue !== "function") {
|
|
111
|
+
throw new TypeError("sourceEnvelopeAuthority.issue is required");
|
|
112
|
+
}
|
|
113
|
+
if (typeof now !== "function" || typeof idGenerator !== "function") {
|
|
114
|
+
throw new TypeError("ingress clock and idGenerator must be functions");
|
|
115
|
+
}
|
|
116
|
+
const maintenanceProducer =
|
|
117
|
+
wikiMaintenanceProducer === null
|
|
118
|
+
? null
|
|
119
|
+
: captureEvolutionRunWikiMaintenanceProducer(wikiMaintenanceProducer);
|
|
120
|
+
if (
|
|
121
|
+
![
|
|
122
|
+
WIKI_MAINTENANCE_TRIGGER_KIND.SESSION_END,
|
|
123
|
+
WIKI_MAINTENANCE_TRIGGER_KIND.GOAL_END,
|
|
124
|
+
].includes(completionTriggerKind)
|
|
125
|
+
) {
|
|
126
|
+
throw new TypeError(
|
|
127
|
+
"Agent completion trigger kind must be session-end or goal-end",
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
const issueSourceEnvelope = sourceEnvelopeAuthority.issue.bind(
|
|
131
|
+
sourceEnvelopeAuthority,
|
|
132
|
+
);
|
|
133
|
+
const descriptor = runAdapter.descriptor;
|
|
134
|
+
let tail = Promise.resolve();
|
|
135
|
+
|
|
136
|
+
const serialize = (operation) => {
|
|
137
|
+
const pending = tail.then(operation, operation);
|
|
138
|
+
tail = pending.catch(() => undefined);
|
|
139
|
+
return pending;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const currentTimestamp = () => {
|
|
143
|
+
const value = now();
|
|
144
|
+
const iso = value instanceof Date ? value.toISOString() : value;
|
|
145
|
+
return timestamp(iso, "ingress timestamp");
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const appendStarted = () => {
|
|
149
|
+
const loaded = runAdapter.load();
|
|
150
|
+
if (loaded.events.length > 0) return loaded.projection;
|
|
151
|
+
const occurredAt = currentTimestamp();
|
|
152
|
+
return runAdapter.appendEvent({
|
|
153
|
+
schema: EVOLUTION_RUN_EVENT_SCHEMA,
|
|
154
|
+
tenantId: descriptor.tenantId,
|
|
155
|
+
runId: descriptor.runId,
|
|
156
|
+
eventId: `${descriptor.runId}:started`,
|
|
157
|
+
sequence: 1,
|
|
158
|
+
type: EVENT_TYPES.RUN_STARTED,
|
|
159
|
+
subjectId: descriptor.runId,
|
|
160
|
+
payloadDigest: digest({ occurredAt, runtime: "agent" }),
|
|
161
|
+
artifactRef: null,
|
|
162
|
+
keyRef: null,
|
|
163
|
+
data: { occurredAt, runtime: "agent" },
|
|
164
|
+
}).projection;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const ingest = (kind, evidence, options = {}) =>
|
|
168
|
+
guardIngress(
|
|
169
|
+
serialize(async () => {
|
|
170
|
+
const projection = appendStarted();
|
|
171
|
+
if (projection.status === "completed") {
|
|
172
|
+
throw new Error(
|
|
173
|
+
"completed EvolutionRun cannot accept Agent evidence",
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
const eventId = normalizeId(
|
|
177
|
+
options.eventId ?? `agent:${idGenerator()}`,
|
|
178
|
+
"Agent evidence eventId",
|
|
179
|
+
);
|
|
180
|
+
const occurredAt = timestamp(
|
|
181
|
+
options.occurredAt ?? currentTimestamp(),
|
|
182
|
+
"Agent evidence occurredAt",
|
|
183
|
+
);
|
|
184
|
+
const payload = clone(evidence);
|
|
185
|
+
const sourceEnvelope = await issueSourceEnvelope(
|
|
186
|
+
Object.freeze({
|
|
187
|
+
schema: AGENT_EVOLUTION_INGRESS_SCHEMA,
|
|
188
|
+
tenantId: descriptor.tenantId,
|
|
189
|
+
runId: descriptor.runId,
|
|
190
|
+
eventId,
|
|
191
|
+
kind,
|
|
192
|
+
occurredAt,
|
|
193
|
+
evidence: payload,
|
|
194
|
+
}),
|
|
195
|
+
);
|
|
196
|
+
const persisted = await evidenceAdapter.projectAndPersist({
|
|
197
|
+
sourceEnvelope,
|
|
198
|
+
payload,
|
|
199
|
+
});
|
|
200
|
+
if (
|
|
201
|
+
persisted?.tenantId !== descriptor.tenantId ||
|
|
202
|
+
persisted.evidenceId == null ||
|
|
203
|
+
persisted.manifest?.type !== "evidence" ||
|
|
204
|
+
typeof persisted.manifest.ref?.ref !== "string"
|
|
205
|
+
) {
|
|
206
|
+
throw new Error(
|
|
207
|
+
"Agent evidence persistence returned an unbound result",
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
const current = runAdapter.load();
|
|
211
|
+
return runAdapter.appendEvent({
|
|
212
|
+
schema: EVOLUTION_RUN_EVENT_SCHEMA,
|
|
213
|
+
tenantId: descriptor.tenantId,
|
|
214
|
+
runId: descriptor.runId,
|
|
215
|
+
eventId,
|
|
216
|
+
sequence: current.events.length + 1,
|
|
217
|
+
type: EVENT_TYPES.RAW_EVENT_REFERENCED,
|
|
218
|
+
subjectId: persisted.evidenceId,
|
|
219
|
+
payloadDigest: persisted.manifest.digest,
|
|
220
|
+
artifactRef: persisted.manifest.ref.ref,
|
|
221
|
+
keyRef: null,
|
|
222
|
+
data: {
|
|
223
|
+
evidenceKind: kind,
|
|
224
|
+
occurredAt,
|
|
225
|
+
derivationManifestDigest: persisted.manifest.digest,
|
|
226
|
+
},
|
|
227
|
+
});
|
|
228
|
+
}),
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
const ingress = Object.freeze({
|
|
232
|
+
schema: AGENT_EVOLUTION_INGRESS_SCHEMA,
|
|
233
|
+
tenantId: descriptor.tenantId,
|
|
234
|
+
runId: descriptor.runId,
|
|
235
|
+
start: () => guardIngress(serialize(() => appendStarted())),
|
|
236
|
+
ingestUserPrompt: (input, options) =>
|
|
237
|
+
ingest("user-prompt", { input: clone(input) }, options),
|
|
238
|
+
ingestAgentEvent: (event, options) => {
|
|
239
|
+
const baseKind = CORE_EVENT_KINDS.get(event?.type);
|
|
240
|
+
if (!baseKind) {
|
|
241
|
+
return Promise.resolve(Object.freeze({ ignored: true }));
|
|
242
|
+
}
|
|
243
|
+
const kind =
|
|
244
|
+
event.type === "tool-result" &&
|
|
245
|
+
Boolean(event.error || event.result?.error || event.result?.isError)
|
|
246
|
+
? "tool-failed"
|
|
247
|
+
: baseKind;
|
|
248
|
+
return ingest(kind, { event: clone(event) }, options);
|
|
249
|
+
},
|
|
250
|
+
complete: (options = {}) =>
|
|
251
|
+
guardIngress(
|
|
252
|
+
serialize(async () => {
|
|
253
|
+
const loaded = runAdapter.load();
|
|
254
|
+
let projection;
|
|
255
|
+
if (loaded.projection?.status === "completed") {
|
|
256
|
+
projection = loaded.projection;
|
|
257
|
+
} else {
|
|
258
|
+
if (loaded.events.length === 0) appendStarted();
|
|
259
|
+
const current = runAdapter.load();
|
|
260
|
+
const occurredAt = timestamp(
|
|
261
|
+
options.occurredAt ?? currentTimestamp(),
|
|
262
|
+
"Agent completion occurredAt",
|
|
263
|
+
);
|
|
264
|
+
projection = runAdapter.appendEvent({
|
|
265
|
+
schema: EVOLUTION_RUN_EVENT_SCHEMA,
|
|
266
|
+
tenantId: descriptor.tenantId,
|
|
267
|
+
runId: descriptor.runId,
|
|
268
|
+
eventId: `${descriptor.runId}:completed`,
|
|
269
|
+
sequence: current.events.length + 1,
|
|
270
|
+
type: EVENT_TYPES.RUN_COMPLETED,
|
|
271
|
+
subjectId: descriptor.runId,
|
|
272
|
+
payloadDigest: digest({ occurredAt, status: "completed" }),
|
|
273
|
+
artifactRef: null,
|
|
274
|
+
keyRef: null,
|
|
275
|
+
data: { occurredAt, status: "completed" },
|
|
276
|
+
}).projection;
|
|
277
|
+
}
|
|
278
|
+
if (maintenanceProducer !== null) {
|
|
279
|
+
await maintenanceProducer.enqueueCompletedRun({
|
|
280
|
+
kind: completionTriggerKind,
|
|
281
|
+
runId: descriptor.runId,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
return projection;
|
|
285
|
+
}),
|
|
286
|
+
),
|
|
287
|
+
});
|
|
288
|
+
INGRESSES.add(ingress);
|
|
289
|
+
return ingress;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export function captureAgentEvolutionIngress(value, options = {}) {
|
|
293
|
+
if (!INGRESSES.has(value)) {
|
|
294
|
+
throw new TypeError("a branded Agent evolution ingress is required");
|
|
295
|
+
}
|
|
296
|
+
if (options.tenantId != null && value.tenantId !== options.tenantId) {
|
|
297
|
+
throw new TypeError("Agent evolution ingress belongs to another tenant");
|
|
298
|
+
}
|
|
299
|
+
return value;
|
|
300
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const AGENT_EVOLUTION_RUNTIME_COMPOSITION_SCHEMA =
|
|
2
|
+
"chainlesschain.agent-evolution-runtime-composition/v1";
|
|
3
|
+
|
|
4
|
+
const COMPOSITIONS = new WeakSet();
|
|
5
|
+
|
|
6
|
+
export function sealAgentEvolutionRuntimeComposition(fields) {
|
|
7
|
+
const composition = Object.freeze({
|
|
8
|
+
schema: AGENT_EVOLUTION_RUNTIME_COMPOSITION_SCHEMA,
|
|
9
|
+
...fields,
|
|
10
|
+
});
|
|
11
|
+
COMPOSITIONS.add(composition);
|
|
12
|
+
return composition;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function captureAgentEvolutionRuntimeComposition(value) {
|
|
16
|
+
if (!COMPOSITIONS.has(value)) {
|
|
17
|
+
throw new TypeError(
|
|
18
|
+
"a branded Agent evolution runtime composition is required",
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { types as utilTypes } from "node:util";
|
|
5
|
+
|
|
6
|
+
import { ArtifactStore } from "../artifact-store.js";
|
|
7
|
+
import {
|
|
8
|
+
ArtifactStoreEncryptedRawStore,
|
|
9
|
+
EvolutionEvidenceArtifactAdapter,
|
|
10
|
+
} from "./evolution-evidence-artifact-adapter.js";
|
|
11
|
+
import {
|
|
12
|
+
EvolutionEvidenceBundleVerifier,
|
|
13
|
+
EvolutionEvidenceProjector,
|
|
14
|
+
} from "./evolution-evidence-projector.js";
|
|
15
|
+
import { EvolutionArtifactPorts } from "./evolution-artifact-ports.js";
|
|
16
|
+
import {
|
|
17
|
+
captureEvolutionLedgerFileBackend,
|
|
18
|
+
createEvolutionLedgerFileBackend,
|
|
19
|
+
} from "./evolution-ledger-file-backend.js";
|
|
20
|
+
import { EvolutionRunLedgerAdapter } from "./evolution-run-ledger-adapter.js";
|
|
21
|
+
import {
|
|
22
|
+
captureAgentEvolutionIngress,
|
|
23
|
+
createAgentEvolutionIngress,
|
|
24
|
+
} from "./agent-evolution-ingress.js";
|
|
25
|
+
import { sealAgentEvolutionRuntimeComposition } from "./agent-evolution-runtime-composition-brand.js";
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
AGENT_EVOLUTION_RUNTIME_COMPOSITION_SCHEMA,
|
|
29
|
+
captureAgentEvolutionRuntimeComposition,
|
|
30
|
+
} from "./agent-evolution-runtime-composition-brand.js";
|
|
31
|
+
const SAFE_ID = /^[A-Za-z0-9][A-Za-z0-9._:@/-]{0,255}$/u;
|
|
32
|
+
const AUTHORITY_KEYS = new Set([
|
|
33
|
+
"artifact",
|
|
34
|
+
"attestationSigner",
|
|
35
|
+
"attestationVerifier",
|
|
36
|
+
"keyedCommitter",
|
|
37
|
+
"ledger",
|
|
38
|
+
"rawEncryptor",
|
|
39
|
+
"sourceEnvelope",
|
|
40
|
+
"sourceVerifier",
|
|
41
|
+
"storagePolicy",
|
|
42
|
+
"witness",
|
|
43
|
+
]);
|
|
44
|
+
const ARTIFACT_AUTHORITY_KEYS = new Set([
|
|
45
|
+
"currentAuthorityResolver",
|
|
46
|
+
"envelopeSigner",
|
|
47
|
+
"envelopeVerifier",
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
function exactRecord(value, keys, label) {
|
|
51
|
+
if (
|
|
52
|
+
!value ||
|
|
53
|
+
typeof value !== "object" ||
|
|
54
|
+
Array.isArray(value) ||
|
|
55
|
+
utilTypes.isProxy(value) ||
|
|
56
|
+
Reflect.ownKeys(value).length !== keys.size ||
|
|
57
|
+
Reflect.ownKeys(value).some(
|
|
58
|
+
(key) => typeof key !== "string" || !keys.has(key),
|
|
59
|
+
)
|
|
60
|
+
) {
|
|
61
|
+
throw new TypeError(`${label} must contain exactly the required ports`);
|
|
62
|
+
}
|
|
63
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
64
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
65
|
+
if (!descriptor || !("value" in descriptor) || !descriptor.enumerable) {
|
|
66
|
+
throw new TypeError(`${label}.${String(key)} must be a data property`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return value;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function identifier(value, label) {
|
|
73
|
+
if (typeof value !== "string" || !SAFE_ID.test(value)) {
|
|
74
|
+
throw new TypeError(`${label} is invalid`);
|
|
75
|
+
}
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function capture(owner, method, label) {
|
|
80
|
+
if (
|
|
81
|
+
!owner ||
|
|
82
|
+
typeof owner !== "object" ||
|
|
83
|
+
utilTypes.isProxy(owner) ||
|
|
84
|
+
typeof owner[method] !== "function"
|
|
85
|
+
) {
|
|
86
|
+
throw new TypeError(`${label}.${method} port is required`);
|
|
87
|
+
}
|
|
88
|
+
const operation = owner[method];
|
|
89
|
+
return Object.freeze((...args) => Reflect.apply(operation, owner, args));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function captureAuthority(authority, method, label) {
|
|
93
|
+
return Object.freeze({ [method]: capture(authority, method, label) });
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function normalizeClock(clock) {
|
|
97
|
+
if (typeof clock !== "function" || utilTypes.isProxy(clock)) {
|
|
98
|
+
throw new TypeError("clock must be a non-proxy function");
|
|
99
|
+
}
|
|
100
|
+
return Object.freeze(() => {
|
|
101
|
+
const milliseconds = Number(clock());
|
|
102
|
+
if (!Number.isFinite(milliseconds)) {
|
|
103
|
+
throw new TypeError("clock must return epoch milliseconds");
|
|
104
|
+
}
|
|
105
|
+
return milliseconds;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function layout(stateRootDir, tenantId, runId) {
|
|
110
|
+
if (typeof stateRootDir !== "string" || stateRootDir.trim() === "") {
|
|
111
|
+
throw new TypeError("stateRootDir is required");
|
|
112
|
+
}
|
|
113
|
+
const rootDir = path.resolve(stateRootDir);
|
|
114
|
+
const scope = path.join(
|
|
115
|
+
rootDir,
|
|
116
|
+
encodeURIComponent(tenantId),
|
|
117
|
+
encodeURIComponent(runId),
|
|
118
|
+
);
|
|
119
|
+
const result = Object.freeze({
|
|
120
|
+
rootDir,
|
|
121
|
+
artifactDir: path.join(scope, "artifacts"),
|
|
122
|
+
rawDir: path.join(scope, "raw"),
|
|
123
|
+
ledgerRootDir: path.join(scope, "ledger-events"),
|
|
124
|
+
ledgerAuthorityRootDir: path.join(scope, "ledger-authority"),
|
|
125
|
+
witnessFilePath: path.join(scope, "witness", "checkpoint.json"),
|
|
126
|
+
});
|
|
127
|
+
fs.mkdirSync(path.dirname(result.witnessFilePath), {
|
|
128
|
+
recursive: true,
|
|
129
|
+
mode: 0o700,
|
|
130
|
+
});
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function defaultWitnessId(tenantId, runId) {
|
|
135
|
+
return `agent-evolution-${crypto
|
|
136
|
+
.createHash("sha256")
|
|
137
|
+
.update(`${tenantId}\0${runId}`, "utf8")
|
|
138
|
+
.digest("hex")}`;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function assertIndependentSigningAuthorities(ledger, witness) {
|
|
142
|
+
if (
|
|
143
|
+
!ledger?.trust ||
|
|
144
|
+
!witness?.trust ||
|
|
145
|
+
ledger === witness ||
|
|
146
|
+
ledger.signer === witness.signer ||
|
|
147
|
+
ledger.verifier === witness.verifier ||
|
|
148
|
+
ledger.trust === witness.trust ||
|
|
149
|
+
ledger.trust.keyId === witness.trust.keyId ||
|
|
150
|
+
ledger.trust.trustPolicyDigest === witness.trust.trustPolicyDigest
|
|
151
|
+
) {
|
|
152
|
+
throw new TypeError(
|
|
153
|
+
"ledger and witness production authorities must be independent",
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Production composition root for the CLI Agent evolution ingress.
|
|
160
|
+
*
|
|
161
|
+
* Every cryptographic, identity, policy, commitment and encryption operation
|
|
162
|
+
* is supplied by the host. This module deliberately contains no local key,
|
|
163
|
+
* permissive policy, environment fallback, or auto-enable path.
|
|
164
|
+
*/
|
|
165
|
+
export function createAgentEvolutionRuntimeComposition({
|
|
166
|
+
tenantId: tenantIdInput,
|
|
167
|
+
runId: runIdInput,
|
|
168
|
+
audience: audienceInput = "evolution-runtime",
|
|
169
|
+
stateRootDir,
|
|
170
|
+
authorities: authorityInput,
|
|
171
|
+
evidenceTtlMs,
|
|
172
|
+
witnessId: witnessIdInput,
|
|
173
|
+
clock: clockInput = Date.now,
|
|
174
|
+
evidenceIdGenerator,
|
|
175
|
+
ingressIdGenerator,
|
|
176
|
+
wikiMaintenanceProducer = null,
|
|
177
|
+
completionTriggerKind,
|
|
178
|
+
secure = true,
|
|
179
|
+
fsImpl,
|
|
180
|
+
lock,
|
|
181
|
+
random,
|
|
182
|
+
lockTimeoutMs,
|
|
183
|
+
witnessMaximumBytes,
|
|
184
|
+
} = {}) {
|
|
185
|
+
const tenantId = identifier(tenantIdInput, "tenantId");
|
|
186
|
+
const runId = identifier(runIdInput, "runId");
|
|
187
|
+
const audience = identifier(audienceInput, "audience");
|
|
188
|
+
const witnessId = identifier(
|
|
189
|
+
witnessIdInput ?? defaultWitnessId(tenantId, runId),
|
|
190
|
+
"witnessId",
|
|
191
|
+
);
|
|
192
|
+
const authorities = exactRecord(
|
|
193
|
+
authorityInput,
|
|
194
|
+
AUTHORITY_KEYS,
|
|
195
|
+
"authorities",
|
|
196
|
+
);
|
|
197
|
+
const artifactAuthority = exactRecord(
|
|
198
|
+
authorities.artifact,
|
|
199
|
+
ARTIFACT_AUTHORITY_KEYS,
|
|
200
|
+
"authorities.artifact",
|
|
201
|
+
);
|
|
202
|
+
const clock = normalizeClock(clockInput);
|
|
203
|
+
if (
|
|
204
|
+
typeof evidenceIdGenerator !== "function" ||
|
|
205
|
+
utilTypes.isProxy(evidenceIdGenerator)
|
|
206
|
+
) {
|
|
207
|
+
throw new TypeError("evidenceIdGenerator port is required");
|
|
208
|
+
}
|
|
209
|
+
if (
|
|
210
|
+
typeof ingressIdGenerator !== "function" ||
|
|
211
|
+
utilTypes.isProxy(ingressIdGenerator)
|
|
212
|
+
) {
|
|
213
|
+
throw new TypeError("ingressIdGenerator port is required");
|
|
214
|
+
}
|
|
215
|
+
const ports = Object.freeze({
|
|
216
|
+
artifactEnvelopeSigner: captureAuthority(
|
|
217
|
+
artifactAuthority.envelopeSigner,
|
|
218
|
+
"sign",
|
|
219
|
+
"artifact envelope signer",
|
|
220
|
+
),
|
|
221
|
+
artifactEnvelopeVerifier: captureAuthority(
|
|
222
|
+
artifactAuthority.envelopeVerifier,
|
|
223
|
+
"verify",
|
|
224
|
+
"artifact envelope verifier",
|
|
225
|
+
),
|
|
226
|
+
artifactCurrentAuthorityResolver: captureAuthority(
|
|
227
|
+
artifactAuthority.currentAuthorityResolver,
|
|
228
|
+
"resolve",
|
|
229
|
+
"artifact current authority resolver",
|
|
230
|
+
),
|
|
231
|
+
rawEncryptor: captureAuthority(
|
|
232
|
+
authorities.rawEncryptor,
|
|
233
|
+
"encrypt",
|
|
234
|
+
"Raw encryptor",
|
|
235
|
+
),
|
|
236
|
+
sourceEnvelope: captureAuthority(
|
|
237
|
+
authorities.sourceEnvelope,
|
|
238
|
+
"issue",
|
|
239
|
+
"source envelope authority",
|
|
240
|
+
),
|
|
241
|
+
sourceVerifier: captureAuthority(
|
|
242
|
+
authorities.sourceVerifier,
|
|
243
|
+
"verify",
|
|
244
|
+
"source verifier",
|
|
245
|
+
),
|
|
246
|
+
keyedCommitter: captureAuthority(
|
|
247
|
+
authorities.keyedCommitter,
|
|
248
|
+
"commit",
|
|
249
|
+
"keyed committer",
|
|
250
|
+
),
|
|
251
|
+
storagePolicy: captureAuthority(
|
|
252
|
+
authorities.storagePolicy,
|
|
253
|
+
"resolve",
|
|
254
|
+
"storage policy",
|
|
255
|
+
),
|
|
256
|
+
attestationSigner: captureAuthority(
|
|
257
|
+
authorities.attestationSigner,
|
|
258
|
+
"sign",
|
|
259
|
+
"attestation signer",
|
|
260
|
+
),
|
|
261
|
+
attestationVerifier: captureAuthority(
|
|
262
|
+
authorities.attestationVerifier,
|
|
263
|
+
"verify",
|
|
264
|
+
"attestation verifier",
|
|
265
|
+
),
|
|
266
|
+
});
|
|
267
|
+
capture(authorities.ledger?.signer, "sign", "ledger signer");
|
|
268
|
+
capture(authorities.ledger?.verifier, "verify", "ledger verifier");
|
|
269
|
+
capture(authorities.witness?.signer, "sign", "witness signer");
|
|
270
|
+
capture(authorities.witness?.verifier, "verify", "witness verifier");
|
|
271
|
+
assertIndependentSigningAuthorities(authorities.ledger, authorities.witness);
|
|
272
|
+
const storage = layout(stateRootDir, tenantId, runId);
|
|
273
|
+
const artifactPorts = new EvolutionArtifactPorts({
|
|
274
|
+
tenantId,
|
|
275
|
+
audience,
|
|
276
|
+
artifactStore: new ArtifactStore({
|
|
277
|
+
dir: storage.artifactDir,
|
|
278
|
+
now: clock,
|
|
279
|
+
}),
|
|
280
|
+
envelopeSigner: ports.artifactEnvelopeSigner,
|
|
281
|
+
envelopeVerifier: ports.artifactEnvelopeVerifier,
|
|
282
|
+
currentAuthorityResolver: ports.artifactCurrentAuthorityResolver,
|
|
283
|
+
now: clock,
|
|
284
|
+
});
|
|
285
|
+
const rawStore = new ArtifactStoreEncryptedRawStore({
|
|
286
|
+
tenantId,
|
|
287
|
+
artifactStore: new ArtifactStore({
|
|
288
|
+
dir: storage.rawDir,
|
|
289
|
+
now: clock,
|
|
290
|
+
}),
|
|
291
|
+
encryptor: ports.rawEncryptor,
|
|
292
|
+
});
|
|
293
|
+
const projector = new EvolutionEvidenceProjector({
|
|
294
|
+
sourceVerifier: ports.sourceVerifier,
|
|
295
|
+
keyedCommitter: ports.keyedCommitter,
|
|
296
|
+
storagePolicy: ports.storagePolicy,
|
|
297
|
+
rawStore,
|
|
298
|
+
attestationSigner: ports.attestationSigner,
|
|
299
|
+
attestationVerifier: ports.attestationVerifier,
|
|
300
|
+
idGenerator: evidenceIdGenerator,
|
|
301
|
+
now: () => new Date(clock()),
|
|
302
|
+
});
|
|
303
|
+
const bundleVerifier = new EvolutionEvidenceBundleVerifier({
|
|
304
|
+
attestationVerifier: ports.attestationVerifier,
|
|
305
|
+
now: () => new Date(clock()),
|
|
306
|
+
});
|
|
307
|
+
const evidenceAdapter = new EvolutionEvidenceArtifactAdapter({
|
|
308
|
+
tenantId,
|
|
309
|
+
audience,
|
|
310
|
+
projector,
|
|
311
|
+
bundleVerifier,
|
|
312
|
+
artifactPorts,
|
|
313
|
+
...(evidenceTtlMs === undefined ? {} : { ttlMs: evidenceTtlMs }),
|
|
314
|
+
});
|
|
315
|
+
const ledgerArtifactResolver =
|
|
316
|
+
artifactPorts.createEvolutionLedgerArtifactResolver({
|
|
317
|
+
purpose: "evolution-ledger",
|
|
318
|
+
});
|
|
319
|
+
const backend = createEvolutionLedgerFileBackend({
|
|
320
|
+
rootDir: storage.ledgerRootDir,
|
|
321
|
+
authorityRootDir: storage.ledgerAuthorityRootDir,
|
|
322
|
+
witnessFilePath: storage.witnessFilePath,
|
|
323
|
+
witnessId,
|
|
324
|
+
ledgerAuthority: authorities.ledger,
|
|
325
|
+
witnessAuthority: authorities.witness,
|
|
326
|
+
artifactResolver: ledgerArtifactResolver,
|
|
327
|
+
secure,
|
|
328
|
+
clock,
|
|
329
|
+
...(fsImpl === undefined ? {} : { fsImpl }),
|
|
330
|
+
...(lock === undefined ? {} : { lock }),
|
|
331
|
+
...(random === undefined ? {} : { random }),
|
|
332
|
+
...(lockTimeoutMs === undefined ? {} : { lockTimeoutMs }),
|
|
333
|
+
...(witnessMaximumBytes === undefined ? {} : { witnessMaximumBytes }),
|
|
334
|
+
});
|
|
335
|
+
captureEvolutionLedgerFileBackend(backend);
|
|
336
|
+
const runAdapter = new EvolutionRunLedgerAdapter({
|
|
337
|
+
descriptor: {
|
|
338
|
+
tenantId,
|
|
339
|
+
artifactTenantId: tenantId,
|
|
340
|
+
runId,
|
|
341
|
+
audience,
|
|
342
|
+
purpose: "evolution-ledger",
|
|
343
|
+
},
|
|
344
|
+
artifactPorts,
|
|
345
|
+
ledger: backend.ledger,
|
|
346
|
+
ledgerArtifactResolver,
|
|
347
|
+
now: clock,
|
|
348
|
+
});
|
|
349
|
+
const evolutionIngress = createAgentEvolutionIngress({
|
|
350
|
+
evidenceAdapter,
|
|
351
|
+
runAdapter,
|
|
352
|
+
sourceEnvelopeAuthority: ports.sourceEnvelope,
|
|
353
|
+
wikiMaintenanceProducer,
|
|
354
|
+
...(completionTriggerKind === undefined ? {} : { completionTriggerKind }),
|
|
355
|
+
now: () => new Date(clock()),
|
|
356
|
+
idGenerator: ingressIdGenerator,
|
|
357
|
+
});
|
|
358
|
+
captureAgentEvolutionIngress(evolutionIngress, { tenantId });
|
|
359
|
+
|
|
360
|
+
const composition = sealAgentEvolutionRuntimeComposition({
|
|
361
|
+
tenantId,
|
|
362
|
+
runId,
|
|
363
|
+
evolutionIngress,
|
|
364
|
+
loadRun: Object.freeze(() => runAdapter.load()),
|
|
365
|
+
ledgerDescriptor: backend.descriptor,
|
|
366
|
+
storage,
|
|
367
|
+
});
|
|
368
|
+
return composition;
|
|
369
|
+
}
|