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,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal, dependency-free SHA-256 (FIPS 180-4).
|
|
3
|
+
* Kept synchronous and pure so it runs identically in Node and the browser.
|
|
4
|
+
*/
|
|
5
|
+
const K = new Uint32Array([
|
|
6
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74,
|
|
7
|
+
0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d,
|
|
8
|
+
0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e,
|
|
9
|
+
0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
|
|
10
|
+
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
|
11
|
+
]);
|
|
12
|
+
const rotr = (x, n) => ((x >>> n) | (x << (32 - n))) >>> 0;
|
|
13
|
+
export const sha256Hex = (input) => {
|
|
14
|
+
const bytes = new TextEncoder().encode(input);
|
|
15
|
+
const length = bytes.length;
|
|
16
|
+
const padded = new Uint8Array(((length + 9 + 63) >> 6) << 6);
|
|
17
|
+
padded.set(bytes);
|
|
18
|
+
padded[length] = 0x80;
|
|
19
|
+
const view = new DataView(padded.buffer);
|
|
20
|
+
const bitLen = length * 8;
|
|
21
|
+
view.setUint32(padded.length - 8, Math.floor(bitLen / 0x100000000));
|
|
22
|
+
view.setUint32(padded.length - 4, bitLen >>> 0);
|
|
23
|
+
const h = new Uint32Array([0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]);
|
|
24
|
+
const w = new Uint32Array(64);
|
|
25
|
+
for (let offset = 0; offset < padded.length; offset += 64) {
|
|
26
|
+
for (let i = 0; i < 16; i++) {
|
|
27
|
+
w[i] = view.getUint32(offset + i * 4);
|
|
28
|
+
}
|
|
29
|
+
for (let i = 16; i < 64; i++) {
|
|
30
|
+
const s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ (w[i - 15] >>> 3);
|
|
31
|
+
const s1 = rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ (w[i - 2] >>> 10);
|
|
32
|
+
w[i] = (w[i - 16] + s0 + w[i - 7] + s1) >>> 0;
|
|
33
|
+
}
|
|
34
|
+
let a = h[0], b = h[1], c = h[2], d = h[3];
|
|
35
|
+
let e = h[4], f = h[5], g = h[6], k = h[7];
|
|
36
|
+
for (let i = 0; i < 64; i++) {
|
|
37
|
+
const sigma1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
|
|
38
|
+
const ch = (e & f) ^ (~e & g);
|
|
39
|
+
const t1 = (k + sigma1 + ch + K[i] + w[i]) >>> 0;
|
|
40
|
+
const sigma0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
|
|
41
|
+
const maj = (a & b) ^ (a & c) ^ (b & c);
|
|
42
|
+
const t2 = (sigma0 + maj) >>> 0;
|
|
43
|
+
k = g;
|
|
44
|
+
g = f;
|
|
45
|
+
f = e;
|
|
46
|
+
e = (d + t1) >>> 0;
|
|
47
|
+
d = c;
|
|
48
|
+
c = b;
|
|
49
|
+
b = a;
|
|
50
|
+
a = (t1 + t2) >>> 0;
|
|
51
|
+
}
|
|
52
|
+
h[0] = (h[0] + a) >>> 0;
|
|
53
|
+
h[1] = (h[1] + b) >>> 0;
|
|
54
|
+
h[2] = (h[2] + c) >>> 0;
|
|
55
|
+
h[3] = (h[3] + d) >>> 0;
|
|
56
|
+
h[4] = (h[4] + e) >>> 0;
|
|
57
|
+
h[5] = (h[5] + f) >>> 0;
|
|
58
|
+
h[6] = (h[6] + g) >>> 0;
|
|
59
|
+
h[7] = (h[7] + k) >>> 0;
|
|
60
|
+
}
|
|
61
|
+
let out = "";
|
|
62
|
+
for (let i = 0; i < 8; i++) {
|
|
63
|
+
out += h[i].toString(16).padStart(8, "0");
|
|
64
|
+
}
|
|
65
|
+
return out;
|
|
66
|
+
};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { Digest, Timestamp } from "../types/common.js";
|
|
2
|
+
import type { EntryKind } from "../ledger/persistence.js";
|
|
3
|
+
import type { KeyPair } from "../manifest/sign.js";
|
|
4
|
+
import type { CheckpointOptions, LedgerCheckpoint } from "../ledger/checkpoint.js";
|
|
5
|
+
/**
|
|
6
|
+
* Pluggable destination for JSONL lines.
|
|
7
|
+
*
|
|
8
|
+
* `append` must not resolve until the line is accepted by the storage medium;
|
|
9
|
+
* `readAll` returns the lines in write order. Each element is one complete JSON
|
|
10
|
+
* object; blank lines are treated as corruption by {@link AppendLog.open}. A
|
|
11
|
+
* host can wrap a file, a database table, or a remote log behind this
|
|
12
|
+
* interface. `AppendLog` never touches the platform filesystem itself.
|
|
13
|
+
*/
|
|
14
|
+
export interface AppendSink {
|
|
15
|
+
append(line: string): void | Promise<void>;
|
|
16
|
+
readAll(): string[] | Promise<string[]>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* In-memory sink for tests, demos, and deterministic replays.
|
|
20
|
+
*
|
|
21
|
+
* Nothing is durable: the lines live in an array and disappear with the
|
|
22
|
+
* process. Production hosts should provide a sink whose `append` resolves only
|
|
23
|
+
* after the line is safely stored. `readAll` returns a copy; {@link lines} is a
|
|
24
|
+
* live read-only view for harnesses.
|
|
25
|
+
*/
|
|
26
|
+
export declare class MemoryAppendSink implements AppendSink {
|
|
27
|
+
private readonly items;
|
|
28
|
+
constructor(lines?: readonly string[]);
|
|
29
|
+
append(line: string): void;
|
|
30
|
+
readAll(): string[];
|
|
31
|
+
/**
|
|
32
|
+
* Live view of the stored lines for test harnesses; `readAll()` returns the copy.
|
|
33
|
+
*/
|
|
34
|
+
get lines(): string[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* One entry in the append-only log.
|
|
38
|
+
*
|
|
39
|
+
* Shape-compatible with `ChainEntry` from `persistence.ts`; `at` is advisory
|
|
40
|
+
* metadata and is deliberately not covered by `hash`.
|
|
41
|
+
*/
|
|
42
|
+
export interface LogEntry {
|
|
43
|
+
seq: number;
|
|
44
|
+
kind: EntryKind;
|
|
45
|
+
payload: unknown;
|
|
46
|
+
prev: Digest;
|
|
47
|
+
hash: Digest;
|
|
48
|
+
at?: Timestamp;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Thrown when a sink contains data that fails structural or hash verification.
|
|
52
|
+
*/
|
|
53
|
+
export declare class AppendLogError extends Error {
|
|
54
|
+
/**
|
|
55
|
+
* Individual failures, in the order they were found.
|
|
56
|
+
*/
|
|
57
|
+
readonly reasons: string[];
|
|
58
|
+
constructor(message: string, reasons?: readonly string[]);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A verified, append-only hash chain over a pluggable {@link AppendSink}.
|
|
62
|
+
*
|
|
63
|
+
* Every line is one canonical entry serialized as JSON; `append` writes exactly
|
|
64
|
+
* one line and only advances the in-memory tip after the sink resolves. The
|
|
65
|
+
* hash function is identical to `persistence.ts`
|
|
66
|
+
* (`digestOf({ seq, kind, payload, prev })`), so a log can be exported as a
|
|
67
|
+
* `LedgerSnapshot` and checked by existing tooling.
|
|
68
|
+
*
|
|
69
|
+
* Durability and atomicity are properties of the sink, not of this class; there
|
|
70
|
+
* is no guarantee beyond "the sink resolved". A sink that throws after
|
|
71
|
+
* physically writing its line can leave storage and memory out of sync, so
|
|
72
|
+
* hosts should use an atomic append. A single `AppendLog` serializes its own
|
|
73
|
+
* writes, but concurrent instances sharing a sink are not coordinated.
|
|
74
|
+
*
|
|
75
|
+
* `at` is preserved but outside the hash, matching `ChainEntry`. A clean
|
|
76
|
+
* deletion of the tail produces a shorter, internally valid prefix; detecting
|
|
77
|
+
* it requires an external commitment such as a signed checkpoint.
|
|
78
|
+
*/
|
|
79
|
+
export declare class AppendLog {
|
|
80
|
+
private readonly sink;
|
|
81
|
+
private readonly items;
|
|
82
|
+
private tail;
|
|
83
|
+
/**
|
|
84
|
+
* Owner of the ledger. Needed when sealing a checkpoint, because a checkpoint
|
|
85
|
+
* binds the agent identity as well as the tip. Set it through
|
|
86
|
+
* {@link AppendLog.open} or assign it before sealing.
|
|
87
|
+
*/
|
|
88
|
+
agent: string;
|
|
89
|
+
private constructor();
|
|
90
|
+
/**
|
|
91
|
+
* Reads every line, parses it, and verifies the chain before returning.
|
|
92
|
+
*
|
|
93
|
+
* An empty sink opens as an empty log with the genesis tip. Any malformed
|
|
94
|
+
* line, gap, bad link, or hash mismatch throws {@link AppendLogError}; the
|
|
95
|
+
* log is never returned in a partially trusted state.
|
|
96
|
+
*
|
|
97
|
+
* @param sink - Storage to read (and later append to).
|
|
98
|
+
* @param agent - Ledger owner used by {@link seal}; may also be set later.
|
|
99
|
+
*/
|
|
100
|
+
static open(sink: AppendSink, agent?: string): Promise<AppendLog>;
|
|
101
|
+
/**
|
|
102
|
+
* Number of entries currently committed.
|
|
103
|
+
*/
|
|
104
|
+
get count(): number;
|
|
105
|
+
/**
|
|
106
|
+
* Hash of the last entry, or the genesis hash for an empty log.
|
|
107
|
+
*/
|
|
108
|
+
get tip(): Digest;
|
|
109
|
+
/**
|
|
110
|
+
* A shallow copy of the entries, in sequence order.
|
|
111
|
+
*/
|
|
112
|
+
entries(): readonly LogEntry[];
|
|
113
|
+
/**
|
|
114
|
+
* Rechecks the in-memory chain; a mutation since `open`/`append` fails closed.
|
|
115
|
+
*/
|
|
116
|
+
verify(): {
|
|
117
|
+
ok: boolean;
|
|
118
|
+
reasons: string[];
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Appends one entry and one JSONL line.
|
|
122
|
+
*
|
|
123
|
+
* Calls are serialized so concurrent appends get distinct, contiguous
|
|
124
|
+
* sequence numbers. In-memory `count`/`tip` advance only after
|
|
125
|
+
* `sink.append` resolves; if it rejects, this instance is unchanged and the
|
|
126
|
+
* same sequence number can be retried. Payloads are normalized through
|
|
127
|
+
* `JSON.stringify`/`JSON.parse` before hashing, so the stored line can always
|
|
128
|
+
* be reopened even when the caller passed `undefined` properties or other
|
|
129
|
+
* values JSON would rewrite.
|
|
130
|
+
*/
|
|
131
|
+
append(kind: EntryKind, payload: unknown, options?: {
|
|
132
|
+
at?: Timestamp;
|
|
133
|
+
}): Promise<LogEntry>;
|
|
134
|
+
private write;
|
|
135
|
+
/**
|
|
136
|
+
* Signs the current tip through {@link sealCheckpoint}.
|
|
137
|
+
*
|
|
138
|
+
* Refuses to sign a log whose in-memory chain no longer verifies. The agent
|
|
139
|
+
* comes from `options.agent` if present, otherwise from this log; sealing
|
|
140
|
+
* without an agent is an error rather than an anonymous checkpoint.
|
|
141
|
+
*/
|
|
142
|
+
seal(key: KeyPair, options: CheckpointOptions & {
|
|
143
|
+
agent?: string;
|
|
144
|
+
}): Promise<LedgerCheckpoint>;
|
|
145
|
+
}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { sealCheckpoint } from "../ledger/checkpoint.js";
|
|
2
|
+
import { digestOf } from "../semantic/canonical.js";
|
|
3
|
+
const GENESIS = `sha256:${"0".repeat(64)}`;
|
|
4
|
+
const DIGEST_PATTERN = /^sha256:[0-9a-f]{64}$/;
|
|
5
|
+
const ENTRY_KINDS = ["event", "frame", "receipt", "claim", "hypothesis", "unknown", "goal", "plan"];
|
|
6
|
+
const ENTRY_KIND_SET = new Set(ENTRY_KINDS);
|
|
7
|
+
/**
|
|
8
|
+
* In-memory sink for tests, demos, and deterministic replays.
|
|
9
|
+
*
|
|
10
|
+
* Nothing is durable: the lines live in an array and disappear with the
|
|
11
|
+
* process. Production hosts should provide a sink whose `append` resolves only
|
|
12
|
+
* after the line is safely stored. `readAll` returns a copy; {@link lines} is a
|
|
13
|
+
* live read-only view for harnesses.
|
|
14
|
+
*/
|
|
15
|
+
export class MemoryAppendSink {
|
|
16
|
+
items;
|
|
17
|
+
constructor(lines = []) {
|
|
18
|
+
this.items = [...lines];
|
|
19
|
+
}
|
|
20
|
+
append(line) {
|
|
21
|
+
this.items.push(line);
|
|
22
|
+
}
|
|
23
|
+
readAll() {
|
|
24
|
+
return [...this.items];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Live view of the stored lines for test harnesses; `readAll()` returns the copy.
|
|
28
|
+
*/
|
|
29
|
+
get lines() {
|
|
30
|
+
return this.items;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Thrown when a sink contains data that fails structural or hash verification.
|
|
35
|
+
*/
|
|
36
|
+
export class AppendLogError extends Error {
|
|
37
|
+
/**
|
|
38
|
+
* Individual failures, in the order they were found.
|
|
39
|
+
*/
|
|
40
|
+
reasons;
|
|
41
|
+
constructor(message, reasons = []) {
|
|
42
|
+
super(message);
|
|
43
|
+
this.name = "AppendLogError";
|
|
44
|
+
this.reasons = [...reasons];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function isDigest(value) {
|
|
48
|
+
return typeof (value) === "string" && DIGEST_PATTERN.test(value);
|
|
49
|
+
}
|
|
50
|
+
function isEntryKind(value) {
|
|
51
|
+
return typeof (value) === "string" && ENTRY_KIND_SET.has(value);
|
|
52
|
+
}
|
|
53
|
+
function isRecord(value) {
|
|
54
|
+
return typeof (value) === "object" && value !== null && !Array.isArray(value);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Must match `persistence.ts` exactly so logs and snapshots verify alike.
|
|
58
|
+
*/
|
|
59
|
+
function hashOf(seq, kind, payload, prev) {
|
|
60
|
+
return digestOf({ seq, kind, payload, prev });
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* JSONL stores JSON, not JavaScript values. Normalizing before hashing keeps
|
|
64
|
+
* the line self-consistent for `undefined` properties, `Date`, and other
|
|
65
|
+
* values that `JSON.stringify` would otherwise rewrite or drop.
|
|
66
|
+
*/
|
|
67
|
+
function jsonValue(value) {
|
|
68
|
+
const text = JSON.stringify(value);
|
|
69
|
+
return text === (void 0) ? null : JSON.parse(text);
|
|
70
|
+
}
|
|
71
|
+
function verifyEntries(entries) {
|
|
72
|
+
const reasons = [];
|
|
73
|
+
let prev = GENESIS;
|
|
74
|
+
entries.forEach((entry, index) => {
|
|
75
|
+
if (!Number.isSafeInteger(entry.seq) || entry.seq !== index) {
|
|
76
|
+
reasons.push(`entry ${index}: seq ${`${entry.seq}`} is out of order`);
|
|
77
|
+
}
|
|
78
|
+
if (!isEntryKind(entry.kind)) {
|
|
79
|
+
reasons.push(`entry ${index}: kind ${`${entry.kind}`} is not a supported entry kind`);
|
|
80
|
+
}
|
|
81
|
+
if (entry.prev !== prev) {
|
|
82
|
+
reasons.push(`entry ${index}: prev does not match the previous hash`);
|
|
83
|
+
}
|
|
84
|
+
const expected = hashOf(entry.seq, entry.kind, entry.payload, entry.prev);
|
|
85
|
+
if (entry.hash !== expected) {
|
|
86
|
+
reasons.push(`entry ${index}: hash does not cover its canonical fields`);
|
|
87
|
+
}
|
|
88
|
+
prev = entry.hash;
|
|
89
|
+
});
|
|
90
|
+
return reasons;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Parses one JSONL line without trusting its `seq`, `prev`, or `hash` fields.
|
|
94
|
+
*/
|
|
95
|
+
function entryFromLine(line, index, reasons) {
|
|
96
|
+
if (typeof (line) !== "string") {
|
|
97
|
+
reasons.push(`line ${index}: expected a string`);
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
if (line.trim().length === 0) {
|
|
101
|
+
reasons.push(`line ${index}: empty line`);
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
let value;
|
|
105
|
+
try {
|
|
106
|
+
value = JSON.parse(line);
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
reasons.push(`line ${index}: not valid JSON`);
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
if (!isRecord(value)) {
|
|
113
|
+
reasons.push(`line ${index}: expected a JSON object`);
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
const { seq, kind, prev, hash, at } = value;
|
|
117
|
+
if (typeof (seq) !== "number" || !Number.isSafeInteger(seq)) {
|
|
118
|
+
reasons.push(`line ${index}: seq is not an integer`);
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
if (!isEntryKind(kind)) {
|
|
122
|
+
reasons.push(`line ${index}: unknown entry kind ${`${kind}`}`);
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
if (!isDigest(prev)) {
|
|
126
|
+
reasons.push(`line ${index}: prev is not a sha256 digest`);
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
if (!isDigest(hash)) {
|
|
130
|
+
reasons.push(`line ${index}: hash is not a sha256 digest`);
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
if (at !== (void 0) && typeof (at) !== "string") {
|
|
134
|
+
reasons.push(`line ${index}: at is not a timestamp string`);
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
const entry = { seq, kind, payload: value.payload, prev, hash };
|
|
138
|
+
if (typeof (at) === "string") {
|
|
139
|
+
entry.at = at;
|
|
140
|
+
}
|
|
141
|
+
return entry;
|
|
142
|
+
}
|
|
143
|
+
function toChainEntry(entry) {
|
|
144
|
+
return {
|
|
145
|
+
seq: entry.seq,
|
|
146
|
+
kind: entry.kind,
|
|
147
|
+
payload: entry.payload,
|
|
148
|
+
prev: entry.prev,
|
|
149
|
+
hash: entry.hash,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* A verified, append-only hash chain over a pluggable {@link AppendSink}.
|
|
154
|
+
*
|
|
155
|
+
* Every line is one canonical entry serialized as JSON; `append` writes exactly
|
|
156
|
+
* one line and only advances the in-memory tip after the sink resolves. The
|
|
157
|
+
* hash function is identical to `persistence.ts`
|
|
158
|
+
* (`digestOf({ seq, kind, payload, prev })`), so a log can be exported as a
|
|
159
|
+
* `LedgerSnapshot` and checked by existing tooling.
|
|
160
|
+
*
|
|
161
|
+
* Durability and atomicity are properties of the sink, not of this class; there
|
|
162
|
+
* is no guarantee beyond "the sink resolved". A sink that throws after
|
|
163
|
+
* physically writing its line can leave storage and memory out of sync, so
|
|
164
|
+
* hosts should use an atomic append. A single `AppendLog` serializes its own
|
|
165
|
+
* writes, but concurrent instances sharing a sink are not coordinated.
|
|
166
|
+
*
|
|
167
|
+
* `at` is preserved but outside the hash, matching `ChainEntry`. A clean
|
|
168
|
+
* deletion of the tail produces a shorter, internally valid prefix; detecting
|
|
169
|
+
* it requires an external commitment such as a signed checkpoint.
|
|
170
|
+
*/
|
|
171
|
+
export class AppendLog {
|
|
172
|
+
sink;
|
|
173
|
+
items;
|
|
174
|
+
tail = Promise.resolve();
|
|
175
|
+
/**
|
|
176
|
+
* Owner of the ledger. Needed when sealing a checkpoint, because a checkpoint
|
|
177
|
+
* binds the agent identity as well as the tip. Set it through
|
|
178
|
+
* {@link AppendLog.open} or assign it before sealing.
|
|
179
|
+
*/
|
|
180
|
+
agent;
|
|
181
|
+
constructor(sink, entries, agent) {
|
|
182
|
+
this.sink = sink;
|
|
183
|
+
this.items = entries;
|
|
184
|
+
this.agent = agent;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Reads every line, parses it, and verifies the chain before returning.
|
|
188
|
+
*
|
|
189
|
+
* An empty sink opens as an empty log with the genesis tip. Any malformed
|
|
190
|
+
* line, gap, bad link, or hash mismatch throws {@link AppendLogError}; the
|
|
191
|
+
* log is never returned in a partially trusted state.
|
|
192
|
+
*
|
|
193
|
+
* @param sink - Storage to read (and later append to).
|
|
194
|
+
* @param agent - Ledger owner used by {@link seal}; may also be set later.
|
|
195
|
+
*/
|
|
196
|
+
static async open(sink, agent = "") {
|
|
197
|
+
const lines = await sink.readAll();
|
|
198
|
+
if (!Array.isArray(lines)) {
|
|
199
|
+
throw new AppendLogError("append sink readAll() did not return an array of lines", ["readAll() did not return an array"]);
|
|
200
|
+
}
|
|
201
|
+
const reasons = [];
|
|
202
|
+
const entries = [];
|
|
203
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
204
|
+
const entry = entryFromLine(lines[index], index, reasons);
|
|
205
|
+
if (entry === (void 0)) {
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
entries.push(entry);
|
|
209
|
+
}
|
|
210
|
+
if (reasons.length === 0) {
|
|
211
|
+
reasons.push(...verifyEntries(entries));
|
|
212
|
+
}
|
|
213
|
+
if (reasons.length > 0) {
|
|
214
|
+
throw new AppendLogError(`append log failed verification: ${reasons.join("; ")}`, reasons);
|
|
215
|
+
}
|
|
216
|
+
return new AppendLog(sink, entries, agent);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Number of entries currently committed.
|
|
220
|
+
*/
|
|
221
|
+
get count() {
|
|
222
|
+
return this.items.length;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Hash of the last entry, or the genesis hash for an empty log.
|
|
226
|
+
*/
|
|
227
|
+
get tip() {
|
|
228
|
+
return this.items.at(-1)?.hash ?? GENESIS;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* A shallow copy of the entries, in sequence order.
|
|
232
|
+
*/
|
|
233
|
+
entries() {
|
|
234
|
+
return [...this.items];
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Rechecks the in-memory chain; a mutation since `open`/`append` fails closed.
|
|
238
|
+
*/
|
|
239
|
+
verify() {
|
|
240
|
+
const reasons = verifyEntries(this.items);
|
|
241
|
+
return { ok: reasons.length === 0, reasons };
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Appends one entry and one JSONL line.
|
|
245
|
+
*
|
|
246
|
+
* Calls are serialized so concurrent appends get distinct, contiguous
|
|
247
|
+
* sequence numbers. In-memory `count`/`tip` advance only after
|
|
248
|
+
* `sink.append` resolves; if it rejects, this instance is unchanged and the
|
|
249
|
+
* same sequence number can be retried. Payloads are normalized through
|
|
250
|
+
* `JSON.stringify`/`JSON.parse` before hashing, so the stored line can always
|
|
251
|
+
* be reopened even when the caller passed `undefined` properties or other
|
|
252
|
+
* values JSON would rewrite.
|
|
253
|
+
*/
|
|
254
|
+
async append(kind, payload, options = {}) {
|
|
255
|
+
const operation = this.tail.then(() => this.write(kind, payload, options));
|
|
256
|
+
this.tail = operation.then(() => undefined, () => undefined);
|
|
257
|
+
return operation;
|
|
258
|
+
}
|
|
259
|
+
async write(kind, payload, options) {
|
|
260
|
+
const seq = this.items.length;
|
|
261
|
+
const prev = this.tip;
|
|
262
|
+
const stored = jsonValue(payload);
|
|
263
|
+
const hash = hashOf(seq, kind, stored, prev);
|
|
264
|
+
const entry = { seq, kind, payload: stored, prev, hash };
|
|
265
|
+
if (options.at !== (void 0)) {
|
|
266
|
+
entry.at = options.at;
|
|
267
|
+
}
|
|
268
|
+
await this.sink.append(JSON.stringify(entry));
|
|
269
|
+
this.items.push(entry);
|
|
270
|
+
return entry;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Signs the current tip through {@link sealCheckpoint}.
|
|
274
|
+
*
|
|
275
|
+
* Refuses to sign a log whose in-memory chain no longer verifies. The agent
|
|
276
|
+
* comes from `options.agent` if present, otherwise from this log; sealing
|
|
277
|
+
* without an agent is an error rather than an anonymous checkpoint.
|
|
278
|
+
*/
|
|
279
|
+
async seal(key, options) {
|
|
280
|
+
await this.tail;
|
|
281
|
+
const verdict = this.verify();
|
|
282
|
+
if (!verdict.ok) {
|
|
283
|
+
throw new AppendLogError("refusing to seal a broken append log", verdict.reasons);
|
|
284
|
+
}
|
|
285
|
+
const agent = options.agent ?? this.agent;
|
|
286
|
+
if (agent.trim().length === 0) {
|
|
287
|
+
throw new AppendLogError("cannot seal a checkpoint without an agent: pass one to AppendLog.open or in the seal options", ["agent is empty"]);
|
|
288
|
+
}
|
|
289
|
+
const snapshot = {
|
|
290
|
+
amp: "0.1",
|
|
291
|
+
kind: "ledger-snapshot",
|
|
292
|
+
agent,
|
|
293
|
+
tip: this.tip,
|
|
294
|
+
count: this.count,
|
|
295
|
+
entries: this.items.map(toChainEntry),
|
|
296
|
+
};
|
|
297
|
+
return sealCheckpoint(snapshot, key, options);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Durable JSONL sink for the append-only logs.
|
|
3
|
+
*
|
|
4
|
+
* This is a host adapter, not part of the domain: it uses the filesystem and
|
|
5
|
+
* therefore lives in `storage`, behind the `AppendSink` port. Each line is one
|
|
6
|
+
* complete JSON object; `readAll` drops blank lines but never rewrites a line.
|
|
7
|
+
*
|
|
8
|
+
* A production host may replace this with a database outbox or a remote log.
|
|
9
|
+
* The sink only promises that `append` returns after the bytes are handed to the
|
|
10
|
+
* OS; call `fsync` at a higher level if the durability requirement is stronger.
|
|
11
|
+
*/
|
|
12
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
13
|
+
import { dirname } from "node:path";
|
|
14
|
+
export class FileAppendSink {
|
|
15
|
+
path;
|
|
16
|
+
constructor(path) {
|
|
17
|
+
if (typeof (path) !== "string" || path.trim().length === 0) {
|
|
18
|
+
throw new TypeError("FileAppendSink requires a non-empty path");
|
|
19
|
+
}
|
|
20
|
+
this.path = path;
|
|
21
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
22
|
+
}
|
|
23
|
+
append(line) {
|
|
24
|
+
appendFileSync(this.path, `${line}\n`, { encoding: "utf8" });
|
|
25
|
+
}
|
|
26
|
+
readAll() {
|
|
27
|
+
if (!existsSync(this.path)) {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
return readFileSync(this.path, "utf8")
|
|
31
|
+
.split(/\r?\n/)
|
|
32
|
+
.filter((line) => line.length > 0);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Database } from "../database/service/database.js";
|
|
2
|
+
import { EntityCache } from "./cache.js";
|
|
3
|
+
type CacheBinder = <T>(factory: (db: Database) => EntityCache<T>) => () => EntityCache<T>;
|
|
4
|
+
/**
|
|
5
|
+
* Bind one cache to the current `Database`. When `configureStore` replaces the
|
|
6
|
+
* database, the next access rebuilds the cache instead of serving stale rows.
|
|
7
|
+
*/
|
|
8
|
+
export declare const bindCache: CacheBinder;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { database } from "./context.js";
|
|
2
|
+
import { EntityCache } from "./cache.js";
|
|
3
|
+
/**
|
|
4
|
+
* Bind one cache to the current `Database`. When `configureStore` replaces the
|
|
5
|
+
* database, the next access rebuilds the cache instead of serving stale rows.
|
|
6
|
+
*/
|
|
7
|
+
export const bindCache = (factory) => {
|
|
8
|
+
let cache;
|
|
9
|
+
let bound;
|
|
10
|
+
return () => {
|
|
11
|
+
const db = database();
|
|
12
|
+
if (cache === (void 0) || bound !== db) {
|
|
13
|
+
cache = factory(db);
|
|
14
|
+
bound = db;
|
|
15
|
+
}
|
|
16
|
+
return cache;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export interface EntityCacheOptions<T> {
|
|
2
|
+
load: (key: string) => T | undefined;
|
|
3
|
+
keyOf: (value: T) => string;
|
|
4
|
+
capacity?: number;
|
|
5
|
+
ttlMs?: number;
|
|
6
|
+
now?: () => number;
|
|
7
|
+
}
|
|
8
|
+
export interface CacheStats {
|
|
9
|
+
loads: number;
|
|
10
|
+
hits: number;
|
|
11
|
+
misses: number;
|
|
12
|
+
evictions: number;
|
|
13
|
+
size: number;
|
|
14
|
+
capacity: number;
|
|
15
|
+
}
|
|
16
|
+
export declare class EntityCache<T> {
|
|
17
|
+
readonly capacity: number;
|
|
18
|
+
readonly ttlMs: number;
|
|
19
|
+
private readonly lru;
|
|
20
|
+
private readonly loadedAt;
|
|
21
|
+
private readonly proxy;
|
|
22
|
+
private readonly load;
|
|
23
|
+
private readonly keyOf;
|
|
24
|
+
private readonly now;
|
|
25
|
+
private loads;
|
|
26
|
+
private hits;
|
|
27
|
+
private misses;
|
|
28
|
+
private evictions;
|
|
29
|
+
constructor(options: EntityCacheOptions<T>);
|
|
30
|
+
/**
|
|
31
|
+
* Read through the cache; a miss calls the service loader.
|
|
32
|
+
*/
|
|
33
|
+
get(id: string | number): T | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Look at a cached value without loading or extending its TTL.
|
|
36
|
+
*/
|
|
37
|
+
peek(id: string | number): T | undefined;
|
|
38
|
+
put(value: T): void;
|
|
39
|
+
invalidate(id?: string | number): void;
|
|
40
|
+
entries(): T[];
|
|
41
|
+
get size(): number;
|
|
42
|
+
stats(): CacheStats;
|
|
43
|
+
/**
|
|
44
|
+
* The Proxy view: `cache.entities["42"]` reads through to the service.
|
|
45
|
+
*/
|
|
46
|
+
get entities(): Record<string, T>;
|
|
47
|
+
private evictIfNeeded;
|
|
48
|
+
}
|