attention-manifest-protocol 0.4.0 → 0.4.2
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/CHANGELOG.md +250 -226
- package/CHANGELOG.zh-CN.md +63 -39
- package/README.md +22 -1
- package/README.zh-CN.md +22 -1
- package/docs/probes/calibration-imported.json +141 -141
- package/docs/probes/eval-recorded-replay.json +597 -597
- package/docs/probes/eval-replay.json +124 -124
- package/docs/probes/eval-summary.json +42 -42
- package/docs/probes/runtime-eval.json +4230 -4230
- package/lib/attention/attention.d.ts +153 -0
- package/lib/attention/attention.js +209 -0
- package/lib/attention/budget.d.ts +31 -0
- package/lib/attention/budget.js +55 -0
- package/lib/attention/cognition.d.ts +230 -0
- package/lib/attention/cognition.js +245 -0
- package/lib/attention/index.d.ts +8 -0
- package/lib/attention/index.js +7 -0
- package/lib/attention/interrupts.d.ts +97 -0
- package/lib/attention/interrupts.js +151 -0
- package/lib/attention/resource.d.ts +167 -0
- package/lib/attention/resource.js +148 -0
- package/lib/attention/social.d.ts +74 -0
- package/lib/attention/social.js +153 -0
- package/lib/attention/socialTypes.d.ts +102 -0
- package/lib/attention/socialTypes.js +1 -0
- package/lib/authz/authz.d.ts +75 -0
- package/lib/authz/authz.js +176 -0
- package/lib/authz/index.d.ts +1 -0
- package/lib/authz/index.js +1 -0
- package/lib/bayes/calibration.d.ts +67 -0
- package/lib/bayes/calibration.js +114 -0
- package/lib/bayes/calibrationRegistry.d.ts +39 -0
- package/lib/bayes/calibrationRegistry.js +61 -0
- package/lib/bayes/calibrationSelection.d.ts +40 -0
- package/lib/bayes/calibrationSelection.js +89 -0
- package/lib/bayes/engine.d.ts +163 -0
- package/lib/bayes/engine.js +354 -0
- package/lib/bayes/index.d.ts +6 -0
- package/lib/bayes/index.js +6 -0
- package/lib/bayes/reliability.d.ts +27 -0
- package/lib/bayes/reliability.js +38 -0
- package/lib/bayes/scopedPriors.d.ts +34 -0
- package/lib/bayes/scopedPriors.js +70 -0
- package/lib/boundary/frame.d.ts +63 -0
- package/lib/boundary/frame.js +239 -0
- package/lib/boundary/ids.d.ts +8 -0
- package/lib/boundary/ids.js +12 -0
- package/lib/boundary/index.d.ts +12 -0
- package/lib/boundary/index.js +8 -0
- package/lib/boundary/refTable.d.ts +49 -0
- package/lib/boundary/refTable.js +92 -0
- package/lib/boundary/toolCall.d.ts +33 -0
- package/lib/boundary/toolCall.js +173 -0
- package/lib/concept/concept.d.ts +67 -0
- package/lib/concept/concept.js +1 -0
- package/lib/concept/conceptBudget.d.ts +56 -0
- package/lib/concept/conceptBudget.js +281 -0
- package/lib/concept/conceptBudgetTypes.d.ts +74 -0
- package/lib/concept/conceptBudgetTypes.js +1 -0
- package/lib/concept/index.d.ts +3 -0
- package/lib/concept/index.js +3 -0
- package/lib/concurrency/idempotency.d.ts +16 -0
- package/lib/concurrency/idempotency.js +21 -0
- package/lib/concurrency/index.d.ts +5 -0
- package/lib/concurrency/index.js +5 -0
- package/lib/concurrency/mutex.d.ts +13 -0
- package/lib/concurrency/mutex.js +26 -0
- package/lib/concurrency/namedLocks.d.ts +7 -0
- package/lib/concurrency/namedLocks.js +31 -0
- package/lib/concurrency/retry.d.ts +23 -0
- package/lib/concurrency/retry.js +38 -0
- package/lib/concurrency/worker.d.ts +42 -0
- package/lib/concurrency/worker.js +67 -0
- package/lib/context/agentContext.d.ts +58 -0
- package/lib/context/agentContext.js +197 -0
- package/lib/context/ast.d.ts +98 -0
- package/lib/context/ast.js +414 -0
- package/lib/context/contentStore.d.ts +16 -0
- package/lib/context/contentStore.js +61 -0
- package/lib/context/context.d.ts +15 -0
- package/lib/context/context.js +39 -0
- package/lib/context/contextIndex.d.ts +40 -0
- package/lib/context/contextIndex.js +64 -0
- package/lib/context/document.d.ts +102 -0
- package/lib/context/document.js +22 -0
- package/lib/context/fileStorePath.d.ts +1 -0
- package/lib/context/fileStorePath.js +13 -0
- package/lib/context/index.d.ts +22 -0
- package/lib/context/index.js +11 -0
- package/lib/context/lifecycle.d.ts +91 -0
- package/lib/context/lifecycle.js +163 -0
- package/lib/context/projections.d.ts +20 -0
- package/lib/context/projections.js +127 -0
- package/lib/context/workspace.d.ts +111 -0
- package/lib/context/workspace.js +318 -0
- package/lib/context/workspaceProtocol.d.ts +30 -0
- package/lib/context/workspaceProtocol.js +49 -0
- package/lib/context/workspaceService.d.ts +63 -0
- package/lib/context/workspaceService.js +352 -0
- package/lib/cooperation/board.d.ts +47 -0
- package/lib/cooperation/board.js +66 -0
- package/lib/cooperation/collaboration.d.ts +55 -0
- package/lib/cooperation/collaboration.js +1 -0
- package/lib/cooperation/index.d.ts +6 -0
- package/lib/cooperation/index.js +6 -0
- package/lib/cooperation/merge.d.ts +69 -0
- package/lib/cooperation/merge.js +109 -0
- package/lib/cooperation/metrics.d.ts +39 -0
- package/lib/cooperation/metrics.js +17 -0
- package/lib/cooperation/session.d.ts +75 -0
- package/lib/cooperation/session.js +74 -0
- package/lib/cooperation/unified.d.ts +38 -0
- package/lib/cooperation/unified.js +40 -0
- package/lib/database/adapter/adapters.d.ts +24 -0
- package/lib/database/adapter/adapters.js +31 -0
- package/lib/database/adapter/index.d.ts +4 -0
- package/lib/database/adapter/index.js +4 -0
- package/lib/database/adapter/runtimeSink.d.ts +20 -0
- package/lib/database/adapter/runtimeSink.js +50 -0
- package/lib/database/adapter/sessionStore.d.ts +11 -0
- package/lib/database/adapter/sessionStore.js +23 -0
- package/lib/database/adapter/turnStore.d.ts +10 -0
- package/lib/database/adapter/turnStore.js +15 -0
- package/lib/database/entity/agent.d.ts +133 -0
- package/lib/database/entity/agent.js +61 -0
- package/lib/database/entity/entity.d.ts +715 -0
- package/lib/database/entity/entity.js +372 -0
- package/lib/database/entity/handle.d.ts +31 -0
- package/lib/database/entity/handle.js +53 -0
- package/lib/database/entity/index.d.ts +32 -0
- package/lib/database/entity/index.js +22 -0
- package/lib/database/entity/message.d.ts +27 -0
- package/lib/database/entity/message.js +52 -0
- package/lib/database/entity/meta.d.ts +11 -0
- package/lib/database/entity/meta.js +1 -0
- package/lib/database/entity/object.d.ts +23 -0
- package/lib/database/entity/object.js +24 -0
- package/lib/database/entity/outbox.d.ts +9 -0
- package/lib/database/entity/outbox.js +5 -0
- package/lib/database/entity/process.d.ts +30 -0
- package/lib/database/entity/process.js +40 -0
- package/lib/database/entity/registry.d.ts +81 -0
- package/lib/database/entity/registry.js +91 -0
- package/lib/database/entity/runtimeApproval.d.ts +23 -0
- package/lib/database/entity/runtimeApproval.js +5 -0
- package/lib/database/entity/runtimeSession.d.ts +7 -0
- package/lib/database/entity/runtimeSession.js +5 -0
- package/lib/database/entity/runtimeTurn.d.ts +9 -0
- package/lib/database/entity/runtimeTurn.js +5 -0
- package/lib/database/entity/thread.d.ts +35 -0
- package/lib/database/entity/thread.js +55 -0
- package/lib/database/entity/window.d.ts +39 -0
- package/lib/database/entity/window.js +56 -0
- package/lib/database/entity/worker.d.ts +42 -0
- package/lib/database/entity/worker.js +58 -0
- package/lib/database/index.d.ts +6 -0
- package/lib/database/index.js +6 -0
- package/lib/database/repository/addressSpaceRepository.d.ts +18 -0
- package/lib/database/repository/addressSpaceRepository.js +40 -0
- package/lib/database/repository/agentRepository.d.ts +41 -0
- package/lib/database/repository/agentRepository.js +398 -0
- package/lib/database/repository/base.d.ts +31 -0
- package/lib/database/repository/base.js +23 -0
- package/lib/database/repository/executionRepository.d.ts +64 -0
- package/lib/database/repository/executionRepository.js +379 -0
- package/lib/database/repository/handleRepository.d.ts +35 -0
- package/lib/database/repository/handleRepository.js +57 -0
- package/lib/database/repository/index.d.ts +20 -0
- package/lib/database/repository/index.js +17 -0
- package/lib/database/repository/messageRepository.d.ts +33 -0
- package/lib/database/repository/messageRepository.js +45 -0
- package/lib/database/repository/objectRepository.d.ts +43 -0
- package/lib/database/repository/objectRepository.js +60 -0
- package/lib/database/repository/outboxRepository.d.ts +15 -0
- package/lib/database/repository/outboxRepository.js +51 -0
- package/lib/database/repository/processRepository.d.ts +31 -0
- package/lib/database/repository/processRepository.js +48 -0
- package/lib/database/repository/registryRepository.d.ts +72 -0
- package/lib/database/repository/registryRepository.js +95 -0
- package/lib/database/repository/repository.d.ts +322 -0
- package/lib/database/repository/repository.js +332 -0
- package/lib/database/repository/runtimeApprovalRepository.d.ts +14 -0
- package/lib/database/repository/runtimeApprovalRepository.js +35 -0
- package/lib/database/repository/runtimeSessionRepository.d.ts +9 -0
- package/lib/database/repository/runtimeSessionRepository.js +21 -0
- package/lib/database/repository/runtimeTurnRepository.d.ts +10 -0
- package/lib/database/repository/runtimeTurnRepository.js +32 -0
- package/lib/database/repository/socialRepository.d.ts +22 -0
- package/lib/database/repository/socialRepository.js +155 -0
- package/lib/database/repository/threadRepository.d.ts +29 -0
- package/lib/database/repository/threadRepository.js +48 -0
- package/lib/database/repository/windowRepository.d.ts +46 -0
- package/lib/database/repository/windowRepository.js +68 -0
- package/lib/database/repository/workerRepository.d.ts +38 -0
- package/lib/database/repository/workerRepository.js +61 -0
- package/lib/database/service/database.d.ts +55 -0
- package/lib/database/service/database.js +77 -0
- package/lib/database/service/handleService.d.ts +20 -0
- package/lib/database/service/handleService.js +34 -0
- package/lib/database/service/index.d.ts +16 -0
- package/lib/database/service/index.js +11 -0
- package/lib/database/service/messageService.d.ts +26 -0
- package/lib/database/service/messageService.js +40 -0
- package/lib/database/service/objectService.d.ts +32 -0
- package/lib/database/service/objectService.js +31 -0
- package/lib/database/service/processService.d.ts +22 -0
- package/lib/database/service/processService.js +45 -0
- package/lib/database/service/registryServices.d.ts +43 -0
- package/lib/database/service/registryServices.js +60 -0
- package/lib/database/service/service.d.ts +131 -0
- package/lib/database/service/service.js +153 -0
- package/lib/database/service/stepService.d.ts +23 -0
- package/lib/database/service/stepService.js +35 -0
- package/lib/database/service/threadService.d.ts +23 -0
- package/lib/database/service/threadService.js +48 -0
- package/lib/database/service/windowService.d.ts +15 -0
- package/lib/database/service/windowService.js +22 -0
- package/lib/database/service/workerService.d.ts +28 -0
- package/lib/database/service/workerService.js +34 -0
- package/lib/database/sql/index.d.ts +3 -0
- package/lib/database/sql/index.js +2 -0
- package/lib/database/sql/schema.d.ts +5 -0
- package/lib/database/sql/schema.js +416 -0
- package/lib/database/sql/sql.d.ts +290 -0
- package/lib/database/sql/sql.js +430 -0
- package/lib/database/store/database.d.ts +75 -0
- package/lib/database/store/database.js +143 -0
- package/lib/database/store/index.d.ts +3 -0
- package/lib/database/store/index.js +2 -0
- package/lib/database/store/store.d.ts +145 -0
- package/lib/database/store/store.js +192 -0
- package/lib/delegate/index.d.ts +2 -0
- package/lib/delegate/index.js +2 -0
- package/lib/delegate/team.d.ts +92 -0
- package/lib/delegate/team.js +200 -0
- package/lib/delegate/teamTypes.d.ts +43 -0
- package/lib/delegate/teamTypes.js +1 -0
- package/lib/diagnosis/checklist.d.ts +16 -0
- package/lib/diagnosis/checklist.js +61 -0
- package/lib/diagnosis/context.d.ts +19 -0
- package/lib/diagnosis/context.js +79 -0
- package/lib/diagnosis/frame.d.ts +34 -0
- package/lib/diagnosis/frame.js +230 -0
- package/lib/diagnosis/index.d.ts +5 -0
- package/lib/diagnosis/index.js +5 -0
- package/lib/diagnosis/router.d.ts +22 -0
- package/lib/diagnosis/router.js +47 -0
- package/lib/diagnosis/types.d.ts +78 -0
- package/lib/diagnosis/types.js +2 -0
- package/lib/error/agentError.d.ts +9 -0
- package/lib/error/agentError.js +13 -0
- package/lib/error/ampError.d.ts +14 -0
- package/lib/error/ampError.js +19 -0
- package/lib/error/authzError.d.ts +10 -0
- package/lib/error/authzError.js +11 -0
- package/lib/error/boundaryRejection.d.ts +16 -0
- package/lib/error/boundaryRejection.js +14 -0
- package/lib/error/index.d.ts +7 -0
- package/lib/error/index.js +7 -0
- package/lib/error/kernelError.d.ts +11 -0
- package/lib/error/kernelError.js +12 -0
- package/lib/error/mailboxError.d.ts +5 -0
- package/lib/error/mailboxError.js +6 -0
- package/lib/error/windowError.d.ts +8 -0
- package/lib/error/windowError.js +9 -0
- package/lib/evaluation/agreement.d.ts +22 -0
- package/lib/evaluation/agreement.js +82 -0
- package/lib/evaluation/index.d.ts +2 -0
- package/lib/evaluation/index.js +2 -0
- package/lib/evaluation/labels.d.ts +56 -0
- package/lib/evaluation/labels.js +206 -0
- package/lib/evidence/evidenceGraph.d.ts +37 -0
- package/lib/evidence/evidenceGraph.js +165 -0
- package/lib/evidence/index.d.ts +4 -0
- package/lib/evidence/index.js +2 -0
- package/lib/evidence/revalidation.d.ts +70 -0
- package/lib/evidence/revalidation.js +146 -0
- package/lib/execution/exec.d.ts +151 -0
- package/lib/execution/exec.js +282 -0
- package/lib/execution/handles.d.ts +25 -0
- package/lib/execution/handles.js +45 -0
- package/lib/execution/index.d.ts +3 -0
- package/lib/execution/index.js +3 -0
- package/lib/execution/pin.d.ts +60 -0
- package/lib/execution/pin.js +103 -0
- package/lib/frame/frame.d.ts +61 -0
- package/lib/frame/frame.js +1 -0
- package/lib/frame/index.d.ts +1 -0
- package/lib/frame/index.js +1 -0
- package/lib/goal/goal.d.ts +19 -0
- package/lib/goal/goal.js +21 -0
- package/lib/goal/index.d.ts +2 -0
- package/lib/goal/index.js +1 -0
- package/lib/goal/plan.d.ts +125 -0
- package/lib/goal/plan.js +60 -0
- package/lib/governance/attentionManifest.d.ts +279 -0
- package/lib/governance/attentionManifest.js +467 -0
- package/lib/governance/audit.d.ts +123 -0
- package/lib/governance/audit.js +263 -0
- package/lib/governance/budget.d.ts +219 -0
- package/lib/governance/budget.js +424 -0
- package/lib/governance/context.d.ts +159 -0
- package/lib/governance/context.js +229 -0
- package/lib/governance/control.d.ts +65 -0
- package/lib/governance/control.js +89 -0
- package/lib/governance/cooperation.d.ts +163 -0
- package/lib/governance/cooperation.js +350 -0
- package/lib/governance/credential.d.ts +117 -0
- package/lib/governance/credential.js +229 -0
- package/lib/governance/httpServer.d.ts +18 -0
- package/lib/governance/httpServer.js +74 -0
- package/lib/governance/index.d.ts +32 -0
- package/lib/governance/index.js +32 -0
- package/lib/governance/legal.d.ts +222 -0
- package/lib/governance/legal.js +371 -0
- package/lib/governance/matrix.d.ts +170 -0
- package/lib/governance/matrix.js +365 -0
- package/lib/governance/perspectives.d.ts +98 -0
- package/lib/governance/perspectives.js +340 -0
- package/lib/governance/signing.d.ts +131 -0
- package/lib/governance/signing.js +241 -0
- package/lib/governance/store.d.ts +33 -0
- package/lib/governance/store.js +89 -0
- package/lib/governance/switching.d.ts +183 -0
- package/lib/governance/switching.js +257 -0
- package/lib/governance/toolPolicy.d.ts +37 -0
- package/lib/governance/toolPolicy.js +42 -0
- package/lib/governance/transport.d.ts +76 -0
- package/lib/governance/transport.js +124 -0
- package/lib/governance/types.d.ts +218 -0
- package/lib/governance/types.js +72 -0
- package/lib/governance/workflow.d.ts +174 -0
- package/lib/governance/workflow.js +612 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +11 -0
- package/lib/interaction/index.d.ts +1 -0
- package/lib/interaction/index.js +1 -0
- package/lib/interaction/interaction.d.ts +83 -0
- package/lib/interaction/interaction.js +256 -0
- package/lib/ipc/index.d.ts +4 -0
- package/lib/ipc/index.js +3 -0
- package/lib/ipc/mailbox.d.ts +37 -0
- package/lib/ipc/mailbox.js +77 -0
- package/lib/ipc/memorySocialStore.d.ts +14 -0
- package/lib/ipc/memorySocialStore.js +83 -0
- package/lib/ipc/social.d.ts +80 -0
- package/lib/ipc/social.js +1 -0
- package/lib/kernel/index.d.ts +2 -0
- package/lib/kernel/index.js +1 -0
- package/lib/kernel/scheduler.d.ts +195 -0
- package/lib/kernel/scheduler.js +334 -0
- package/lib/ledger/checkpoint.d.ts +116 -0
- package/lib/ledger/checkpoint.js +223 -0
- package/lib/ledger/index.d.ts +4 -0
- package/lib/ledger/index.js +4 -0
- package/lib/ledger/ledger.d.ts +21 -0
- package/lib/ledger/ledger.js +23 -0
- package/lib/ledger/persistence.d.ts +46 -0
- package/lib/ledger/persistence.js +106 -0
- package/lib/ledger/share.d.ts +29 -0
- package/lib/ledger/share.js +39 -0
- package/lib/lock/index.d.ts +2 -0
- package/lib/lock/index.js +1 -0
- package/lib/lock/lease.d.ts +23 -0
- package/lib/lock/lease.js +42 -0
- package/lib/manifest/agentCard.d.ts +35 -0
- package/lib/manifest/agentCard.js +38 -0
- package/lib/manifest/cardSign.d.ts +25 -0
- package/lib/manifest/cardSign.js +70 -0
- package/lib/manifest/federation.d.ts +64 -0
- package/lib/manifest/federation.js +187 -0
- package/lib/manifest/federationTypes.d.ts +51 -0
- package/lib/manifest/federationTypes.js +1 -0
- package/lib/manifest/index.d.ts +8 -0
- package/lib/manifest/index.js +8 -0
- package/lib/manifest/keys.d.ts +221 -0
- package/lib/manifest/keys.js +484 -0
- package/lib/manifest/manifest.d.ts +102 -0
- package/lib/manifest/manifest.js +1 -0
- package/lib/manifest/sign.d.ts +38 -0
- package/lib/manifest/sign.js +90 -0
- package/lib/manifest/trust.d.ts +54 -0
- package/lib/manifest/trust.js +87 -0
- package/lib/mission/index.d.ts +2 -0
- package/lib/mission/index.js +1 -0
- package/lib/mission/missionQueue.d.ts +19 -0
- package/lib/mission/missionQueue.js +62 -0
- package/lib/module/index.d.ts +9 -0
- package/lib/module/index.js +9 -0
- package/lib/module/llm/deepseek.d.ts +43 -0
- package/lib/module/llm/deepseek.js +162 -0
- package/lib/module/llm/llm.d.ts +64 -0
- package/lib/module/llm/llm.js +16 -0
- package/lib/module/mcp/client.d.ts +32 -0
- package/lib/module/mcp/client.js +84 -0
- package/lib/module/mcp/http.d.ts +32 -0
- package/lib/module/mcp/http.js +83 -0
- package/lib/module/mcp/protocol.d.ts +62 -0
- package/lib/module/mcp/protocol.js +20 -0
- package/lib/module/mcp/server.d.ts +22 -0
- package/lib/module/mcp/server.js +138 -0
- package/lib/module/mcp/transport.d.ts +19 -0
- package/lib/module/mcp/transport.js +16 -0
- package/lib/module/mcp/workspaceServer.d.ts +20 -0
- package/lib/module/mcp/workspaceServer.js +90 -0
- package/lib/module/sandbox/sandbox.d.ts +24 -0
- package/lib/module/sandbox/sandbox.js +5 -0
- package/lib/module/tool/mcpExecutor.d.ts +18 -0
- package/lib/module/tool/mcpExecutor.js +41 -0
- package/lib/module/tool/policy.d.ts +30 -0
- package/lib/module/tool/policy.js +23 -0
- package/lib/module/tool/redact.d.ts +9 -0
- package/lib/module/tool/redact.js +19 -0
- package/lib/module/tool/tool.d.ts +26 -0
- package/lib/module/tool/tool.js +24 -0
- package/lib/module/tool/workspaceExecutor.d.ts +12 -0
- package/lib/module/tool/workspaceExecutor.js +25 -0
- package/lib/policy/guard.d.ts +115 -0
- package/lib/policy/guard.js +154 -0
- package/lib/policy/index.d.ts +2 -0
- package/lib/policy/index.js +2 -0
- package/lib/policy/policy.d.ts +249 -0
- package/lib/policy/policy.js +364 -0
- package/lib/process/agent.d.ts +295 -0
- package/lib/process/agent.js +1 -0
- package/lib/process/agentService.d.ts +87 -0
- package/lib/process/agentService.js +128 -0
- package/lib/process/agentStore.d.ts +35 -0
- package/lib/process/agentStore.js +328 -0
- package/lib/process/executionStore.d.ts +79 -0
- package/lib/process/executionStore.js +71 -0
- package/lib/process/index.d.ts +5 -0
- package/lib/process/index.js +5 -0
- package/lib/process/process.d.ts +120 -0
- package/lib/process/process.js +111 -0
- package/lib/process/transitions.d.ts +11 -0
- package/lib/process/transitions.js +8 -0
- package/lib/progress/index.d.ts +2 -0
- package/lib/progress/index.js +1 -0
- package/lib/progress/progress.d.ts +26 -0
- package/lib/progress/progress.js +42 -0
- package/lib/protocol/a2a.d.ts +51 -0
- package/lib/protocol/a2a.js +79 -0
- package/lib/protocol/channel.d.ts +25 -0
- package/lib/protocol/channel.js +27 -0
- package/lib/protocol/envelope.d.ts +180 -0
- package/lib/protocol/envelope.js +495 -0
- package/lib/protocol/httpChannel.d.ts +33 -0
- package/lib/protocol/httpChannel.js +59 -0
- package/lib/protocol/index.d.ts +6 -0
- package/lib/protocol/index.js +6 -0
- package/lib/protocol/protocol.d.ts +120 -0
- package/lib/protocol/protocol.js +1 -0
- package/lib/protocol/wire.d.ts +12 -0
- package/lib/protocol/wire.js +55 -0
- package/lib/receipt/index.d.ts +1 -0
- package/lib/receipt/index.js +1 -0
- package/lib/receipt/receipt.d.ts +43 -0
- package/lib/receipt/receipt.js +1 -0
- package/lib/registry/content.d.ts +10 -0
- package/lib/registry/content.js +58 -0
- package/lib/registry/index.d.ts +4 -0
- package/lib/registry/index.js +2 -0
- package/lib/registry/registry.d.ts +109 -0
- package/lib/registry/registry.js +299 -0
- package/lib/runtime/action.d.ts +46 -0
- package/lib/runtime/action.js +39 -0
- package/lib/runtime/behavior.d.ts +110 -0
- package/lib/runtime/behavior.js +179 -0
- package/lib/runtime/behaviorTuning.d.ts +59 -0
- package/lib/runtime/behaviorTuning.js +95 -0
- package/lib/runtime/cognitiveRuntime.d.ts +189 -0
- package/lib/runtime/cognitiveRuntime.js +490 -0
- package/lib/runtime/escalation.d.ts +22 -0
- package/lib/runtime/escalation.js +15 -0
- package/lib/runtime/governedTask.d.ts +57 -0
- package/lib/runtime/governedTask.js +150 -0
- package/lib/runtime/index.d.ts +15 -0
- package/lib/runtime/index.js +15 -0
- package/lib/runtime/kernelRuntime.d.ts +33 -0
- package/lib/runtime/kernelRuntime.js +105 -0
- package/lib/runtime/operation.d.ts +30 -0
- package/lib/runtime/operation.js +1 -0
- package/lib/runtime/replay.d.ts +24 -0
- package/lib/runtime/replay.js +38 -0
- package/lib/runtime/routing.d.ts +12 -0
- package/lib/runtime/routing.js +44 -0
- package/lib/runtime/safety.d.ts +15 -0
- package/lib/runtime/safety.js +28 -0
- package/lib/runtime/session.d.ts +147 -0
- package/lib/runtime/session.js +214 -0
- package/lib/runtime/sessionStore.d.ts +24 -0
- package/lib/runtime/sessionStore.js +20 -0
- package/lib/runtime/telemetry.d.ts +24 -0
- package/lib/runtime/telemetry.js +33 -0
- package/lib/runtime/turnStore.d.ts +16 -0
- package/lib/runtime/turnStore.js +15 -0
- package/lib/scenario/index.d.ts +1 -0
- package/lib/scenario/index.js +1 -0
- package/lib/scenario/scenario.d.ts +52 -0
- package/lib/scenario/scenario.js +210 -0
- package/lib/semantic/canonical.d.ts +6 -0
- package/lib/semantic/canonical.js +22 -0
- package/lib/semantic/index.d.ts +2 -0
- package/lib/semantic/index.js +2 -0
- package/lib/semantic/sha256.d.ts +1 -0
- package/lib/semantic/sha256.js +66 -0
- package/lib/storage/appendLog.d.ts +145 -0
- package/lib/storage/appendLog.js +299 -0
- package/lib/storage/fileAppendSink.d.ts +7 -0
- package/lib/storage/fileAppendSink.js +34 -0
- package/lib/storage/index.d.ts +2 -0
- package/lib/storage/index.js +2 -0
- package/lib/store/bindCache.d.ts +9 -0
- package/lib/store/bindCache.js +18 -0
- package/lib/store/cache.d.ts +48 -0
- package/lib/store/cache.js +162 -0
- package/lib/store/context.d.ts +10 -0
- package/lib/store/context.js +27 -0
- package/lib/store/handleStore.d.ts +9 -0
- package/lib/store/handleStore.js +25 -0
- package/lib/store/index.d.ts +9 -0
- package/lib/store/index.js +8 -0
- package/lib/store/messageStore.d.ts +9 -0
- package/lib/store/messageStore.js +25 -0
- package/lib/store/objectStore.d.ts +9 -0
- package/lib/store/objectStore.js +25 -0
- package/lib/store/processStore.d.ts +9 -0
- package/lib/store/processStore.js +25 -0
- package/lib/store/threadStore.d.ts +9 -0
- package/lib/store/threadStore.js +25 -0
- package/lib/store/windowStore.d.ts +9 -0
- package/lib/store/windowStore.js +25 -0
- package/lib/structure/abstractSyntaxTree.d.ts +181 -0
- package/lib/structure/abstractSyntaxTree.js +400 -0
- package/lib/structure/avlTree.d.ts +125 -0
- package/lib/structure/avlTree.js +369 -0
- package/lib/structure/binarySearchTree.d.ts +125 -0
- package/lib/structure/binarySearchTree.js +306 -0
- package/lib/structure/binaryTree.d.ts +174 -0
- package/lib/structure/binaryTree.js +495 -0
- package/lib/structure/bloomFilter.d.ts +126 -0
- package/lib/structure/bloomFilter.js +177 -0
- package/lib/structure/compare.d.ts +55 -0
- package/lib/structure/compare.js +96 -0
- package/lib/structure/cuckooFilter.d.ts +149 -0
- package/lib/structure/cuckooFilter.js +267 -0
- package/lib/structure/deque.d.ts +117 -0
- package/lib/structure/deque.js +205 -0
- package/lib/structure/filterKey.d.ts +19 -0
- package/lib/structure/filterKey.js +28 -0
- package/lib/structure/hash.d.ts +129 -0
- package/lib/structure/hash.js +241 -0
- package/lib/structure/heap.d.ts +152 -0
- package/lib/structure/heap.js +227 -0
- package/lib/structure/index.d.ts +20 -0
- package/lib/structure/index.js +20 -0
- package/lib/structure/iterator.d.ts +6 -0
- package/lib/structure/iterator.js +16 -0
- package/lib/structure/lru.d.ts +235 -0
- package/lib/structure/lru.js +524 -0
- package/lib/structure/ordered.d.ts +89 -0
- package/lib/structure/ordered.js +336 -0
- package/lib/structure/priority.d.ts +499 -0
- package/lib/structure/priority.js +756 -0
- package/lib/structure/queue.d.ts +90 -0
- package/lib/structure/queue.js +154 -0
- package/lib/structure/redBlackTree.d.ts +142 -0
- package/lib/structure/redBlackTree.js +644 -0
- package/lib/structure/segmentTree.d.ts +129 -0
- package/lib/structure/segmentTree.js +205 -0
- package/lib/structure/stack.d.ts +77 -0
- package/lib/structure/stack.js +107 -0
- package/lib/structure/unordered.d.ts +99 -0
- package/lib/structure/unordered.js +341 -0
- package/lib/thread/index.d.ts +2 -0
- package/lib/thread/index.js +2 -0
- package/lib/thread/thread.d.ts +107 -0
- package/lib/thread/thread.js +81 -0
- package/lib/thread/transitions.d.ts +8 -0
- package/lib/thread/transitions.js +9 -0
- package/lib/types/common.d.ts +80 -0
- package/lib/types/common.js +5 -0
- package/lib/types/index.d.ts +23 -0
- package/lib/types/index.js +1 -0
- package/lib/warrant/epistemic.d.ts +141 -0
- package/lib/warrant/epistemic.js +1 -0
- package/lib/warrant/index.d.ts +3 -0
- package/lib/warrant/index.js +3 -0
- package/lib/warrant/inquiry.d.ts +69 -0
- package/lib/warrant/inquiry.js +119 -0
- package/lib/warrant/warrant.d.ts +46 -0
- package/lib/warrant/warrant.js +153 -0
- package/lib/window/compaction.d.ts +57 -0
- package/lib/window/compaction.js +334 -0
- package/lib/window/compactionTypes.d.ts +113 -0
- package/lib/window/compactionTypes.js +1 -0
- package/lib/window/index.d.ts +7 -0
- package/lib/window/index.js +3 -0
- package/lib/window/page.d.ts +16 -0
- package/lib/window/page.js +2 -0
- package/lib/window/window.d.ts +68 -0
- package/lib/window/window.js +194 -0
- package/package.json +22 -1
- package/src/authz/index.ts +1 -0
- package/src/concept/index.ts +3 -0
- package/src/concurrency/index.ts +5 -0
- package/src/cooperation/index.ts +6 -0
- package/src/delegate/index.ts +2 -0
- package/src/error/index.ts +7 -0
- package/src/evaluation/index.ts +2 -0
- package/src/execution/index.ts +3 -0
- package/src/frame/index.ts +1 -0
- package/src/index.ts +11 -0
- package/src/ledger/index.ts +4 -0
- package/src/manifest/index.ts +8 -0
- package/src/policy/index.ts +2 -0
- package/src/protocol/index.ts +6 -0
- package/src/receipt/index.ts +1 -0
- package/src/semantic/index.ts +2 -0
- package/src/storage/index.ts +2 -0
- package/src/structure/index.ts +20 -0
- package/src/thread/index.ts +2 -0
- package/src/warrant/index.ts +3 -0
- package/src/window/index.ts +7 -4
- package/tools/rewrite-declaration-extensions.ts +98 -0
- package/tsconfig.build.json +14 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { verifySnapshot } from "./persistence.js";
|
|
2
|
+
import { canonical, digestOf } from "../semantic/canonical.js";
|
|
3
|
+
const encoder = new TextEncoder();
|
|
4
|
+
/**
|
|
5
|
+
* Domain separator mixed into every checkpoint signature. It keeps an Ed25519
|
|
6
|
+
* signature over a checkpoint body from being replayed as a signature over any
|
|
7
|
+
* other AMP object that happens to contain the same fields.
|
|
8
|
+
*/
|
|
9
|
+
export const CheckpointDomain = "amp:ledger-checkpoint:0.1";
|
|
10
|
+
const DIGEST_PATTERN = /^sha256:[0-9a-f]{64}$/;
|
|
11
|
+
const SIGNATURE_PATTERN = /^[A-Za-z0-9_-]+$/;
|
|
12
|
+
function toBase64Url(bytes) {
|
|
13
|
+
const view = new Uint8Array(bytes);
|
|
14
|
+
let binary = "";
|
|
15
|
+
for (const byte of view) {
|
|
16
|
+
binary += String.fromCharCode(byte);
|
|
17
|
+
}
|
|
18
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
19
|
+
}
|
|
20
|
+
function fromBase64Url(text) {
|
|
21
|
+
const padded = text.replace(/-/g, "+").replace(/_/g, "/");
|
|
22
|
+
const pad = padded.length % 4 ? "=".repeat(4 - (padded.length % 4)) : "";
|
|
23
|
+
const binary = atob(padded + pad);
|
|
24
|
+
return Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Selects exactly the signed fields, dropping `sig` and any runtime extras.
|
|
28
|
+
* Conditional inclusion keeps `prev` absent (rather than `null`) on the first
|
|
29
|
+
* checkpoint, so its canonical form is stable across implementations.
|
|
30
|
+
*/
|
|
31
|
+
function checkpointFields(checkpoint) {
|
|
32
|
+
const fields = {
|
|
33
|
+
amp: checkpoint.amp,
|
|
34
|
+
kind: checkpoint.kind,
|
|
35
|
+
tenant: checkpoint.tenant,
|
|
36
|
+
agent: checkpoint.agent,
|
|
37
|
+
seq: checkpoint.seq,
|
|
38
|
+
count: checkpoint.count,
|
|
39
|
+
tip: checkpoint.tip,
|
|
40
|
+
issued: checkpoint.issued,
|
|
41
|
+
kid: checkpoint.kid,
|
|
42
|
+
};
|
|
43
|
+
if (checkpoint.prev !== (void 0)) {
|
|
44
|
+
fields.prev = checkpoint.prev;
|
|
45
|
+
}
|
|
46
|
+
return fields;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Canonical JSON of the checkpoint body: every signed field, `sig` excluded,
|
|
50
|
+
* keys sorted by {@link canonical}. This is the part of the signing input that
|
|
51
|
+
* other implementations must reproduce exactly.
|
|
52
|
+
*
|
|
53
|
+
* The signature itself is over `CheckpointDomain + '\n' + checkpointBody(...)`
|
|
54
|
+
* so a valid checkpoint signature cannot be moved to another object kind.
|
|
55
|
+
*/
|
|
56
|
+
export function checkpointBody(checkpoint) {
|
|
57
|
+
return canonical(checkpointFields(checkpoint));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Digest of the signed checkpoint body (everything except `sig`).
|
|
61
|
+
*
|
|
62
|
+
* Used as the `prev` link between checkpoints and safe to log or index. It is
|
|
63
|
+
* not a ledger entry hash and must not be compared with `snapshot.tip`.
|
|
64
|
+
*/
|
|
65
|
+
export function checkpointDigest(checkpoint) {
|
|
66
|
+
return digestOf(checkpointFields(checkpoint));
|
|
67
|
+
}
|
|
68
|
+
function signingBytes(body) {
|
|
69
|
+
return encoder.encode(`${CheckpointDomain}\n${body}`);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Signs the snapshot's chain tip as a new checkpoint.
|
|
73
|
+
*
|
|
74
|
+
* `seq` is `(previous?.seq ?? -1) + 1`, and `prev` — when a previous checkpoint
|
|
75
|
+
* is supplied — is `checkpointDigest(previous)`. The seal does not verify the
|
|
76
|
+
* snapshot first: callers should pass a snapshot that has already been checked
|
|
77
|
+
* (as {@link AppendLog.seal} does). The signature is Ed25519 over the
|
|
78
|
+
* domain-separated canonical body, never over JavaScript property order.
|
|
79
|
+
*/
|
|
80
|
+
export async function sealCheckpoint(snapshot, key, options) {
|
|
81
|
+
const previous = options.previous;
|
|
82
|
+
const body = {
|
|
83
|
+
amp: "0.1",
|
|
84
|
+
kind: "ledger-checkpoint",
|
|
85
|
+
tenant: options.tenant,
|
|
86
|
+
agent: snapshot.agent,
|
|
87
|
+
seq: (previous?.seq ?? -1) + 1,
|
|
88
|
+
count: snapshot.count,
|
|
89
|
+
tip: snapshot.tip,
|
|
90
|
+
issued: options.issued ?? new Date().toISOString(),
|
|
91
|
+
kid: key.kid,
|
|
92
|
+
};
|
|
93
|
+
if (previous !== (void 0)) {
|
|
94
|
+
body.prev = checkpointDigest(previous);
|
|
95
|
+
}
|
|
96
|
+
const signature = await crypto.subtle.sign("Ed25519", key.privateKey, signingBytes(checkpointBody(body)));
|
|
97
|
+
return { ...body, sig: toBase64Url(signature) };
|
|
98
|
+
}
|
|
99
|
+
function isEmpty(value) {
|
|
100
|
+
return typeof (value) !== "string" || value.trim().length === 0;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Verifies a checkpoint without trusting any field in it.
|
|
104
|
+
*
|
|
105
|
+
* Checks the envelope (`amp`/`kind`), non-empty tenant/agent/kid/issued,
|
|
106
|
+
* non-negative integer `seq`/`count`, `sha256:<64 hex>` tip and (when present)
|
|
107
|
+
* prev format, then recomputes the canonical body and verifies the Ed25519
|
|
108
|
+
* signature. If `previous` is supplied, the checkpoint must be linked to it:
|
|
109
|
+
* `seq` must be exactly `previous.seq + 1`, `prev` must equal
|
|
110
|
+
* `checkpointDigest(previous)`, and tenant/agent must stay constant. The
|
|
111
|
+
* previous checkpoint's own signature is the caller's responsibility.
|
|
112
|
+
*/
|
|
113
|
+
export async function verifyCheckpoint(checkpoint, publicKey, previous) {
|
|
114
|
+
const reasons = [];
|
|
115
|
+
if (!checkpoint || typeof (checkpoint) !== "object") {
|
|
116
|
+
return { ok: false, reasons: ["checkpoint is not an object"] };
|
|
117
|
+
}
|
|
118
|
+
if (checkpoint.amp !== "0.1") {
|
|
119
|
+
reasons.push("unsupported checkpoint amp version");
|
|
120
|
+
}
|
|
121
|
+
if (checkpoint.kind !== "ledger-checkpoint") {
|
|
122
|
+
reasons.push("not a ledger checkpoint");
|
|
123
|
+
}
|
|
124
|
+
if (isEmpty(checkpoint.tenant)) {
|
|
125
|
+
reasons.push("tenant is empty");
|
|
126
|
+
}
|
|
127
|
+
if (isEmpty(checkpoint.agent)) {
|
|
128
|
+
reasons.push("agent is empty");
|
|
129
|
+
}
|
|
130
|
+
if (isEmpty(checkpoint.kid)) {
|
|
131
|
+
reasons.push("kid is empty");
|
|
132
|
+
}
|
|
133
|
+
if (isEmpty(checkpoint.issued)) {
|
|
134
|
+
reasons.push("issued is empty");
|
|
135
|
+
}
|
|
136
|
+
if (!Number.isSafeInteger(checkpoint.seq) || checkpoint.seq < 0) {
|
|
137
|
+
reasons.push("seq is not a non-negative integer");
|
|
138
|
+
}
|
|
139
|
+
if (!Number.isSafeInteger(checkpoint.count) || checkpoint.count < 0) {
|
|
140
|
+
reasons.push("count is not a non-negative integer");
|
|
141
|
+
}
|
|
142
|
+
if (typeof (checkpoint.tip) !== "string" || !DIGEST_PATTERN.test(checkpoint.tip)) {
|
|
143
|
+
reasons.push("tip is not a sha256 digest");
|
|
144
|
+
}
|
|
145
|
+
if (checkpoint.prev !== (void 0) && (typeof (checkpoint.prev) !== "string" || !DIGEST_PATTERN.test(checkpoint.prev))) {
|
|
146
|
+
reasons.push("prev is not a sha256 digest");
|
|
147
|
+
}
|
|
148
|
+
if (previous !== (void 0)) {
|
|
149
|
+
if (!Number.isSafeInteger(previous.seq) || previous.seq < 0) {
|
|
150
|
+
reasons.push("previous checkpoint seq is not a non-negative integer");
|
|
151
|
+
}
|
|
152
|
+
else if (checkpoint.seq !== previous.seq + 1) {
|
|
153
|
+
reasons.push(`seq ${checkpoint.seq} does not continue from ${previous.seq}`);
|
|
154
|
+
}
|
|
155
|
+
if (checkpoint.agent !== previous.agent) {
|
|
156
|
+
reasons.push("agent does not match the previous checkpoint");
|
|
157
|
+
}
|
|
158
|
+
if (checkpoint.tenant !== previous.tenant) {
|
|
159
|
+
reasons.push("tenant does not match the previous checkpoint");
|
|
160
|
+
}
|
|
161
|
+
if (checkpoint.prev === (void 0)) {
|
|
162
|
+
reasons.push("missing prev link to the previous checkpoint");
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
try {
|
|
166
|
+
if (checkpoint.prev !== checkpointDigest(previous)) {
|
|
167
|
+
reasons.push("prev does not match the previous checkpoint digest");
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
reasons.push("previous checkpoint cannot be canonicalized");
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
let body;
|
|
176
|
+
try {
|
|
177
|
+
body = checkpointBody(checkpoint);
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
reasons.push("checkpoint body cannot be canonicalized");
|
|
181
|
+
}
|
|
182
|
+
if (isEmpty(checkpoint.sig)) {
|
|
183
|
+
reasons.push("signature is empty");
|
|
184
|
+
}
|
|
185
|
+
else if (!SIGNATURE_PATTERN.test(checkpoint.sig)) {
|
|
186
|
+
reasons.push("signature is not base64url");
|
|
187
|
+
}
|
|
188
|
+
else if (body !== (void 0)) {
|
|
189
|
+
try {
|
|
190
|
+
const valid = await crypto.subtle.verify("Ed25519", publicKey, fromBase64Url(checkpoint.sig), signingBytes(body));
|
|
191
|
+
if (!valid) {
|
|
192
|
+
reasons.push("signature does not verify");
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
reasons.push("signature does not verify");
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return { ok: reasons.length === 0, reasons };
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Checks that a snapshot is the exact chain a checkpoint signed.
|
|
203
|
+
*
|
|
204
|
+
* First compares agent/count/tip with the checkpoint, then runs
|
|
205
|
+
* {@link verifySnapshot} so a rewritten middle entry cannot hide behind a
|
|
206
|
+
* matching tip declaration. This does not verify the checkpoint signature;
|
|
207
|
+
* combine it with {@link verifyCheckpoint} for end-to-end assurance.
|
|
208
|
+
*/
|
|
209
|
+
export async function verifySnapshotAgainstCheckpoint(snapshot, checkpoint) {
|
|
210
|
+
const reasons = [];
|
|
211
|
+
if (snapshot.agent !== checkpoint.agent) {
|
|
212
|
+
reasons.push(`snapshot agent ${snapshot.agent} does not match checkpoint agent ${checkpoint.agent}`);
|
|
213
|
+
}
|
|
214
|
+
if (snapshot.count !== checkpoint.count) {
|
|
215
|
+
reasons.push(`snapshot count ${snapshot.count} does not match checkpoint count ${checkpoint.count}`);
|
|
216
|
+
}
|
|
217
|
+
if (snapshot.tip !== checkpoint.tip) {
|
|
218
|
+
reasons.push("snapshot tip does not match checkpoint tip");
|
|
219
|
+
}
|
|
220
|
+
const verdict = verifySnapshot(snapshot);
|
|
221
|
+
reasons.push(...verdict.reasons);
|
|
222
|
+
return { ok: reasons.length === 0, reasons };
|
|
223
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AmpEvent, Receipt } from "../receipt/receipt.js";
|
|
2
|
+
import type { Frame } from "../frame/frame.js";
|
|
3
|
+
import type { Claim, Hypothesis, UnknownItem } from "../warrant/epistemic.js";
|
|
4
|
+
import type { Goal, Plan } from "../goal/plan.js";
|
|
5
|
+
/**
|
|
6
|
+
* Append-only ledger (X-1). Nothing is deleted or rewritten; revisions add rows.
|
|
7
|
+
* The reference store is in-memory; a host persists the same arrays as JSONL.
|
|
8
|
+
*/
|
|
9
|
+
export declare class Ledger {
|
|
10
|
+
readonly events: AmpEvent[];
|
|
11
|
+
readonly frames: Frame[];
|
|
12
|
+
readonly receipts: Receipt[];
|
|
13
|
+
readonly claims: Claim[];
|
|
14
|
+
readonly hypotheses: Hypothesis[];
|
|
15
|
+
readonly unknowns: UnknownItem[];
|
|
16
|
+
readonly goals: Goal[];
|
|
17
|
+
readonly plans: Plan[];
|
|
18
|
+
appendEvent(event: AmpEvent): void;
|
|
19
|
+
findClaim(id: string): Claim | undefined;
|
|
20
|
+
findUnknown(id: string): UnknownItem | undefined;
|
|
21
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Append-only ledger (X-1). Nothing is deleted or rewritten; revisions add rows.
|
|
3
|
+
* The reference store is in-memory; a host persists the same arrays as JSONL.
|
|
4
|
+
*/
|
|
5
|
+
export class Ledger {
|
|
6
|
+
events = [];
|
|
7
|
+
frames = [];
|
|
8
|
+
receipts = [];
|
|
9
|
+
claims = [];
|
|
10
|
+
hypotheses = [];
|
|
11
|
+
unknowns = [];
|
|
12
|
+
goals = [];
|
|
13
|
+
plans = [];
|
|
14
|
+
appendEvent(event) {
|
|
15
|
+
this.events.push(event);
|
|
16
|
+
}
|
|
17
|
+
findClaim(id) {
|
|
18
|
+
return this.claims.find((c) => c.id === id);
|
|
19
|
+
}
|
|
20
|
+
findUnknown(id) {
|
|
21
|
+
return this.unknowns.find((u) => u.id === id);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Ledger } from "./ledger.js";
|
|
2
|
+
export type EntryKind = "event" | "frame" | "receipt" | "claim" | "hypothesis" | "unknown" | "goal" | "plan";
|
|
3
|
+
export interface ChainEntry {
|
|
4
|
+
seq: number;
|
|
5
|
+
kind: EntryKind;
|
|
6
|
+
payload: unknown;
|
|
7
|
+
prev: string;
|
|
8
|
+
hash: string;
|
|
9
|
+
}
|
|
10
|
+
export interface LedgerSnapshot {
|
|
11
|
+
amp: "0.1";
|
|
12
|
+
kind: "ledger-snapshot";
|
|
13
|
+
agent: string;
|
|
14
|
+
tip: string;
|
|
15
|
+
count: number;
|
|
16
|
+
entries: ChainEntry[];
|
|
17
|
+
}
|
|
18
|
+
export interface SnapshotVerdict {
|
|
19
|
+
ok: boolean;
|
|
20
|
+
reasons: string[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Snapshot = a single chronological chain over the whole ledger.
|
|
24
|
+
*
|
|
25
|
+
* The chain is what makes "append-only" checkable after the fact: changing,
|
|
26
|
+
* reordering, or dropping any entry breaks every hash after it.
|
|
27
|
+
*/
|
|
28
|
+
export declare function exportLedger(ledger: Ledger, agent: string): LedgerSnapshot;
|
|
29
|
+
/**
|
|
30
|
+
* Structural + cryptographic verification, without trusting `count` or `tip`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function verifySnapshot(snapshot: LedgerSnapshot): SnapshotVerdict;
|
|
33
|
+
export interface RestoredLedger {
|
|
34
|
+
events: unknown[];
|
|
35
|
+
frames: unknown[];
|
|
36
|
+
receipts: unknown[];
|
|
37
|
+
claims: unknown[];
|
|
38
|
+
hypotheses: unknown[];
|
|
39
|
+
unknowns: unknown[];
|
|
40
|
+
goals: unknown[];
|
|
41
|
+
plans: unknown[];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Restores only a verified snapshot; a tampered one throws instead of loading.
|
|
45
|
+
*/
|
|
46
|
+
export declare function restoreLedger(snapshot: LedgerSnapshot): RestoredLedger;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { digestOf } from "../semantic/canonical.js";
|
|
2
|
+
const GENESIS = `sha256:${"0".repeat(64)}`;
|
|
3
|
+
const KIND_ORDER = ["event", "frame", "claim", "hypothesis", "unknown", "goal", "plan", "receipt"];
|
|
4
|
+
function hashOf(seq, kind, payload, prev) {
|
|
5
|
+
return digestOf({ seq, kind, payload, prev });
|
|
6
|
+
}
|
|
7
|
+
function timestampOf(item) {
|
|
8
|
+
const candidate = (item.at ?? item.ts ?? item.created ?? item.since);
|
|
9
|
+
return typeof (candidate) === "string" ? candidate : "";
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Snapshot = a single chronological chain over the whole ledger.
|
|
13
|
+
*
|
|
14
|
+
* The chain is what makes "append-only" checkable after the fact: changing,
|
|
15
|
+
* reordering, or dropping any entry breaks every hash after it.
|
|
16
|
+
*/
|
|
17
|
+
export function exportLedger(ledger, agent) {
|
|
18
|
+
const items = [];
|
|
19
|
+
const add = (kind, list) => {
|
|
20
|
+
for (const payload of list) {
|
|
21
|
+
const record = payload;
|
|
22
|
+
items.push({ kind, at: timestampOf(record), order: KIND_ORDER.indexOf(kind), payload });
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
add("event", ledger.events);
|
|
26
|
+
add("frame", ledger.frames);
|
|
27
|
+
add("claim", ledger.claims);
|
|
28
|
+
add("hypothesis", ledger.hypotheses);
|
|
29
|
+
add("unknown", ledger.unknowns);
|
|
30
|
+
add("goal", ledger.goals);
|
|
31
|
+
add("plan", ledger.plans);
|
|
32
|
+
add("receipt", ledger.receipts);
|
|
33
|
+
items.sort((a, b) => (a.at === b.at ? a.order - b.order : a.at < b.at ? -1 : 1));
|
|
34
|
+
const entries = [];
|
|
35
|
+
let prev = GENESIS;
|
|
36
|
+
for (const item of items) {
|
|
37
|
+
const seq = entries.length;
|
|
38
|
+
const hash = hashOf(seq, item.kind, item.payload, prev);
|
|
39
|
+
entries.push({ seq, kind: item.kind, payload: item.payload, prev, hash });
|
|
40
|
+
prev = hash;
|
|
41
|
+
}
|
|
42
|
+
return { amp: "0.1", kind: "ledger-snapshot", agent, tip: prev, count: entries.length, entries };
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Structural + cryptographic verification, without trusting `count` or `tip`.
|
|
46
|
+
*/
|
|
47
|
+
export function verifySnapshot(snapshot) {
|
|
48
|
+
const reasons = [];
|
|
49
|
+
if (snapshot.amp !== "0.1" || snapshot.kind !== "ledger-snapshot") {
|
|
50
|
+
reasons.push("not a ledger snapshot");
|
|
51
|
+
}
|
|
52
|
+
let prev = GENESIS;
|
|
53
|
+
snapshot.entries.forEach((entry, index) => {
|
|
54
|
+
if (entry.seq !== index) {
|
|
55
|
+
reasons.push(`entry ${index}: seq ${entry.seq} is out of order`);
|
|
56
|
+
}
|
|
57
|
+
if (entry.prev !== prev) {
|
|
58
|
+
reasons.push(`entry ${index}: prev does not match the previous hash`);
|
|
59
|
+
}
|
|
60
|
+
const expected = hashOf(entry.seq, entry.kind, entry.payload, entry.prev);
|
|
61
|
+
if (entry.hash !== expected) {
|
|
62
|
+
reasons.push(`entry ${index}: hash does not cover its payload`);
|
|
63
|
+
}
|
|
64
|
+
prev = entry.hash;
|
|
65
|
+
});
|
|
66
|
+
if (snapshot.count !== snapshot.entries.length) {
|
|
67
|
+
reasons.push(`count ${snapshot.count} does not match ${snapshot.entries.length} entries`);
|
|
68
|
+
}
|
|
69
|
+
if (snapshot.tip !== prev) {
|
|
70
|
+
reasons.push("tip does not match the last entry");
|
|
71
|
+
}
|
|
72
|
+
return { ok: reasons.length === 0, reasons };
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Restores only a verified snapshot; a tampered one throws instead of loading.
|
|
76
|
+
*/
|
|
77
|
+
export function restoreLedger(snapshot) {
|
|
78
|
+
const verdict = verifySnapshot(snapshot);
|
|
79
|
+
if (!verdict.ok) {
|
|
80
|
+
throw new Error(`refusing to restore a broken snapshot: ${verdict.reasons.join("; ")}`);
|
|
81
|
+
}
|
|
82
|
+
const out = {
|
|
83
|
+
events: [],
|
|
84
|
+
frames: [],
|
|
85
|
+
receipts: [],
|
|
86
|
+
claims: [],
|
|
87
|
+
hypotheses: [],
|
|
88
|
+
unknowns: [],
|
|
89
|
+
goals: [],
|
|
90
|
+
plans: [],
|
|
91
|
+
};
|
|
92
|
+
const bucket = {
|
|
93
|
+
event: out.events,
|
|
94
|
+
frame: out.frames,
|
|
95
|
+
receipt: out.receipts,
|
|
96
|
+
claim: out.claims,
|
|
97
|
+
hypothesis: out.hypotheses,
|
|
98
|
+
unknown: out.unknowns,
|
|
99
|
+
goal: out.goals,
|
|
100
|
+
plan: out.plans,
|
|
101
|
+
};
|
|
102
|
+
for (const entry of snapshot.entries) {
|
|
103
|
+
bucket[entry.kind].push(entry.payload);
|
|
104
|
+
}
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Ledger } from "./ledger.js";
|
|
2
|
+
export type ShareMode = "full" | "summary" | "reference";
|
|
3
|
+
export interface SharedView {
|
|
4
|
+
amp: "0.1";
|
|
5
|
+
kind: "shared-ledger";
|
|
6
|
+
mode: ShareMode;
|
|
7
|
+
agent: string;
|
|
8
|
+
tip: string;
|
|
9
|
+
count: number;
|
|
10
|
+
digest: string;
|
|
11
|
+
entries?: unknown[];
|
|
12
|
+
summary?: {
|
|
13
|
+
byKind: Record<string, number>;
|
|
14
|
+
claims: string[];
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Signature of the ledger sharing entry point.
|
|
19
|
+
*/
|
|
20
|
+
type ShareLedger = (ledger: Ledger, agent: string, mode: ShareMode) => SharedView;
|
|
21
|
+
/**
|
|
22
|
+
* Three sharing granularities, all integrity-checkable.
|
|
23
|
+
*
|
|
24
|
+
* full — everything; only for a trusted peer in the same domain
|
|
25
|
+
* summary — counts + claim ids; no payloads
|
|
26
|
+
* reference — tip + count + digest; the receiver must ask for more
|
|
27
|
+
*/
|
|
28
|
+
export declare const shareLedger: ShareLedger;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { digestOf } from "../semantic/canonical.js";
|
|
2
|
+
import { exportLedger } from "./persistence.js";
|
|
3
|
+
/**
|
|
4
|
+
* Three sharing granularities, all integrity-checkable.
|
|
5
|
+
*
|
|
6
|
+
* full — everything; only for a trusted peer in the same domain
|
|
7
|
+
* summary — counts + claim ids; no payloads
|
|
8
|
+
* reference — tip + count + digest; the receiver must ask for more
|
|
9
|
+
*/
|
|
10
|
+
export const shareLedger = (ledger, agent, mode) => {
|
|
11
|
+
const snapshot = exportLedger(ledger, agent);
|
|
12
|
+
const base = {
|
|
13
|
+
amp: "0.1",
|
|
14
|
+
kind: "shared-ledger",
|
|
15
|
+
mode,
|
|
16
|
+
agent,
|
|
17
|
+
tip: snapshot.tip,
|
|
18
|
+
count: snapshot.count,
|
|
19
|
+
};
|
|
20
|
+
if (mode === "full") {
|
|
21
|
+
return { ...base, digest: digestOf({ ...base, entries: snapshot.entries }), entries: snapshot.entries };
|
|
22
|
+
}
|
|
23
|
+
if (mode === "summary") {
|
|
24
|
+
const byKind = {};
|
|
25
|
+
const claims = [];
|
|
26
|
+
for (let index = 0; index < snapshot.entries.length; index += 1) {
|
|
27
|
+
const entry = snapshot.entries[index];
|
|
28
|
+
byKind[entry.kind] = (byKind[entry.kind] ?? 0) + 1;
|
|
29
|
+
if (entry.kind === "claim") {
|
|
30
|
+
const payload = entry.payload;
|
|
31
|
+
if (payload.id) {
|
|
32
|
+
claims.push(payload.id);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return { ...base, digest: digestOf({ ...base, byKind, claims }), summary: { byKind, claims } };
|
|
37
|
+
}
|
|
38
|
+
return { ...base, digest: digestOf(base) };
|
|
39
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { acquireLock, getLock, releaseLock, renewLock } from "./lease.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Named leases for cross-worker mutual exclusion.
|
|
3
|
+
*
|
|
4
|
+
* A capability answers "may this subject touch the resource"; a lease answers
|
|
5
|
+
* "who is touching it now". The fencing counter makes a stale holder's writes
|
|
6
|
+
* rejectable even after the lease has been reassigned.
|
|
7
|
+
*/
|
|
8
|
+
import type { DatabaseSync } from "node:sqlite";
|
|
9
|
+
export interface LockRecord {
|
|
10
|
+
name: string;
|
|
11
|
+
holder: string;
|
|
12
|
+
fencing: number;
|
|
13
|
+
acquiredAt: string;
|
|
14
|
+
expiresAt: string;
|
|
15
|
+
}
|
|
16
|
+
export declare const getLock: (db: DatabaseSync, name: string) => LockRecord | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Acquire a lease when it is free, expired, or already held by the same holder.
|
|
19
|
+
* Returns `undefined` when another holder owns a live lease.
|
|
20
|
+
*/
|
|
21
|
+
export declare const acquireLock: (db: DatabaseSync, name: string, holder: string, at: string, ttlMs?: number) => LockRecord | undefined;
|
|
22
|
+
export declare const renewLock: (db: DatabaseSync, name: string, holder: string, fencing: number, at: string, ttlMs?: number) => boolean;
|
|
23
|
+
export declare const releaseLock: (db: DatabaseSync, name: string, holder: string, fencing: number) => boolean;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const toRecord = (row) => ({
|
|
2
|
+
name: row.name,
|
|
3
|
+
holder: row.holder,
|
|
4
|
+
fencing: row.fencing,
|
|
5
|
+
acquiredAt: row.acquired_at,
|
|
6
|
+
expiresAt: row.expires_at,
|
|
7
|
+
});
|
|
8
|
+
const expiry = (at, ttlMs) => new Date(Date.parse(at) + ttlMs).toISOString();
|
|
9
|
+
export const getLock = (db, name) => {
|
|
10
|
+
const row = db.prepare("SELECT * FROM resource_locks WHERE name = ?").get(name);
|
|
11
|
+
return row === (void 0) ? undefined : toRecord(row);
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Acquire a lease when it is free, expired, or already held by the same holder.
|
|
15
|
+
* Returns `undefined` when another holder owns a live lease.
|
|
16
|
+
*/
|
|
17
|
+
export const acquireLock = (db, name, holder, at, ttlMs = 15_000) => {
|
|
18
|
+
const result = db
|
|
19
|
+
.prepare(`INSERT INTO resource_locks (name, holder, fencing, acquired_at, expires_at)
|
|
20
|
+
VALUES (?, ?, 1, ?, ?)
|
|
21
|
+
ON CONFLICT(name) DO UPDATE SET
|
|
22
|
+
holder = excluded.holder,
|
|
23
|
+
fencing = resource_locks.fencing + 1,
|
|
24
|
+
acquired_at = excluded.acquired_at,
|
|
25
|
+
expires_at = excluded.expires_at
|
|
26
|
+
WHERE resource_locks.expires_at <= ? OR resource_locks.holder = ?`)
|
|
27
|
+
.run(name, holder, at, expiry(at, ttlMs), at, holder);
|
|
28
|
+
if (Number(result.changes) !== 1) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
return getLock(db, name);
|
|
32
|
+
};
|
|
33
|
+
export const renewLock = (db, name, holder, fencing, at, ttlMs = 15_000) => {
|
|
34
|
+
const result = db
|
|
35
|
+
.prepare("UPDATE resource_locks SET expires_at = ? WHERE name = ? AND holder = ? AND fencing = ?")
|
|
36
|
+
.run(expiry(at, ttlMs), name, holder, fencing);
|
|
37
|
+
return Number(result.changes) === 1;
|
|
38
|
+
};
|
|
39
|
+
export const releaseLock = (db, name, holder, fencing) => {
|
|
40
|
+
const result = db.prepare("DELETE FROM resource_locks WHERE name = ? AND holder = ? AND fencing = ?").run(name, holder, fencing);
|
|
41
|
+
return Number(result.changes) === 1;
|
|
42
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A2A v1.0 Agent Card discovery.
|
|
3
|
+
*/
|
|
4
|
+
export interface AgentInterface {
|
|
5
|
+
url: string;
|
|
6
|
+
protocolBinding?: string;
|
|
7
|
+
protocolVersion?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface AgentCard {
|
|
10
|
+
name: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
version?: string;
|
|
13
|
+
url?: string;
|
|
14
|
+
supportedInterfaces?: AgentInterface[];
|
|
15
|
+
capabilities?: Record<string, unknown>;
|
|
16
|
+
skills?: Array<{
|
|
17
|
+
id: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
}>;
|
|
20
|
+
}
|
|
21
|
+
export interface CardResult {
|
|
22
|
+
ok: boolean;
|
|
23
|
+
card?: AgentCard;
|
|
24
|
+
endpoint?: string;
|
|
25
|
+
reasons: string[];
|
|
26
|
+
}
|
|
27
|
+
type CardOptions = {
|
|
28
|
+
timeoutMs?: number;
|
|
29
|
+
};
|
|
30
|
+
type FetchAgentCard = (baseUrl: string, options?: CardOptions) => Promise<CardResult>;
|
|
31
|
+
/**
|
|
32
|
+
* Fetches and minimally validates an Agent Card; the endpoint is derived from it.
|
|
33
|
+
*/
|
|
34
|
+
export declare const fetchAgentCard: FetchAgentCard;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A2A v1.0 Agent Card discovery.
|
|
3
|
+
*/
|
|
4
|
+
const WellKnown = "/.well-known/agent-card.json";
|
|
5
|
+
/**
|
|
6
|
+
* Fetches and minimally validates an Agent Card; the endpoint is derived from it.
|
|
7
|
+
*/
|
|
8
|
+
export const fetchAgentCard = async (baseUrl, options = {}) => {
|
|
9
|
+
const url = `${baseUrl.replace(/\/$/, "")}${WellKnown}`;
|
|
10
|
+
const controller = new AbortController();
|
|
11
|
+
const timer = setTimeout(() => controller.abort(), options.timeoutMs ?? 5_000);
|
|
12
|
+
try {
|
|
13
|
+
const response = await fetch(url, {
|
|
14
|
+
headers: { accept: "application/json", "a2a-version": "1.0" },
|
|
15
|
+
signal: controller.signal,
|
|
16
|
+
});
|
|
17
|
+
if (!response.ok) {
|
|
18
|
+
return { ok: false, reasons: [`HTTP ${response.status} from ${url}`] };
|
|
19
|
+
}
|
|
20
|
+
const card = (await response.json());
|
|
21
|
+
const reasons = [];
|
|
22
|
+
if (typeof (card?.name) !== "string" || card.name.length === 0) {
|
|
23
|
+
reasons.push("card has no name");
|
|
24
|
+
}
|
|
25
|
+
if (!card?.url && !(card?.supportedInterfaces?.length ?? 0)) {
|
|
26
|
+
reasons.push("card has no interface url");
|
|
27
|
+
}
|
|
28
|
+
const endpoint = card?.url ?? card?.supportedInterfaces?.[0]?.url;
|
|
29
|
+
return reasons.length === 0 && endpoint ? { ok: true, card, endpoint, reasons } : { ok: false, card, reasons };
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
const reason = error instanceof Error && error.name === "AbortError" ? "timeout" : `${error}`;
|
|
33
|
+
return { ok: false, reasons: [reason] };
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
clearTimeout(timer);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AgentCard } from "./agentCard.js";
|
|
2
|
+
import type { KeyRegistry } from "./sign.js";
|
|
3
|
+
/**
|
|
4
|
+
* JWS JSON serialization, EdDSA over the JCS-canonicalised card.
|
|
5
|
+
*/
|
|
6
|
+
export interface CardSignature {
|
|
7
|
+
protected: string;
|
|
8
|
+
signature: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function signCard(card: AgentCard, key: {
|
|
11
|
+
kid: string;
|
|
12
|
+
privateKey: CryptoKey;
|
|
13
|
+
}): Promise<CardSignature>;
|
|
14
|
+
export declare function verifyCardSignature(card: AgentCard, signature: CardSignature, publicKey: CryptoKey): Promise<{
|
|
15
|
+
ok: boolean;
|
|
16
|
+
reasons: string[];
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* Resolves the signing key from a trust registry (which Federation bundles can
|
|
20
|
+
* populate) instead of trusting a key embedded in the card itself.
|
|
21
|
+
*/
|
|
22
|
+
export declare function verifyCardWithRegistry(card: AgentCard, signature: CardSignature, registry: KeyRegistry): Promise<{
|
|
23
|
+
ok: boolean;
|
|
24
|
+
reasons: string[];
|
|
25
|
+
}>;
|