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,282 @@
|
|
|
1
|
+
import { digestOf } from "../semantic/canonical.js";
|
|
2
|
+
import { BudgetExceeded, Dispatcher } from "../attention/budget.js";
|
|
3
|
+
import { HandleStore } from "./handles.js";
|
|
4
|
+
import { PolicyEngine } from "../policy/policy.js";
|
|
5
|
+
import { digestTool, pinTools, verifyToolPins } from "./pin.js";
|
|
6
|
+
import { textOf } from "../module/mcp/protocol.js";
|
|
7
|
+
import { BoundaryRejection, parseToolCall } from "../boundary/index.js";
|
|
8
|
+
export class DriftDetected extends Error {
|
|
9
|
+
code = "security_event";
|
|
10
|
+
receipt;
|
|
11
|
+
constructor(message, receipt) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "DriftDetected";
|
|
14
|
+
this.receipt = receipt;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export class ApprovalRequired extends Error {
|
|
18
|
+
code = "approval_required";
|
|
19
|
+
receipt;
|
|
20
|
+
reason;
|
|
21
|
+
constructor(tool, receipt, reason = "action requires explicit host approval") {
|
|
22
|
+
super(`tool ${tool} is not read-only and requires explicit approval: ${reason}`);
|
|
23
|
+
this.name = "ApprovalRequired";
|
|
24
|
+
this.receipt = receipt;
|
|
25
|
+
this.reason = reason;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export class PolicyDenied extends Error {
|
|
29
|
+
code = "denied";
|
|
30
|
+
receipt;
|
|
31
|
+
constructor(message, receipt) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.name = "PolicyDenied";
|
|
34
|
+
this.receipt = receipt;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Map MCP annotations onto the policy taxonomy.
|
|
39
|
+
*/
|
|
40
|
+
const effectFor = (tool) => {
|
|
41
|
+
if (tool.annotations?.readOnlyHint === true) {
|
|
42
|
+
return "read";
|
|
43
|
+
}
|
|
44
|
+
if (tool.annotations?.destructiveHint === true) {
|
|
45
|
+
return "deploy";
|
|
46
|
+
}
|
|
47
|
+
return "write-irreversible";
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Exec profile: MCP tools behind the same budget, shaping, and receipt rules
|
|
51
|
+
* as any other action. Digest pinning makes a post-approval metadata change a
|
|
52
|
+
* security event rather than a surprise (Deadbugz / MCPoison).
|
|
53
|
+
*/
|
|
54
|
+
export class ExecProfile {
|
|
55
|
+
client;
|
|
56
|
+
dispatcher;
|
|
57
|
+
/**
|
|
58
|
+
* Host policy engine; `approveTool`/`policy.approve` are host-only APIs.
|
|
59
|
+
*/
|
|
60
|
+
policy;
|
|
61
|
+
handles;
|
|
62
|
+
now;
|
|
63
|
+
maxResultTokens;
|
|
64
|
+
onReceipt;
|
|
65
|
+
guard;
|
|
66
|
+
verifyPinsAtCall;
|
|
67
|
+
validateArgs;
|
|
68
|
+
catalog;
|
|
69
|
+
seq = 0;
|
|
70
|
+
constructor(client, options) {
|
|
71
|
+
this.client = client;
|
|
72
|
+
this.handles = options.handles;
|
|
73
|
+
this.now = options.now;
|
|
74
|
+
this.maxResultTokens = options.maxResultTokens ?? 1200;
|
|
75
|
+
this.onReceipt = options.onReceipt;
|
|
76
|
+
this.guard = options.guard;
|
|
77
|
+
this.verifyPinsAtCall = options.verifyPinsAtCall ?? true;
|
|
78
|
+
this.validateArgs = options.validateArgs ?? true;
|
|
79
|
+
this.policy =
|
|
80
|
+
options.policy ??
|
|
81
|
+
new PolicyEngine({
|
|
82
|
+
now: options.now,
|
|
83
|
+
approvalEffects: options.requireApproval === false ? new Set() : undefined,
|
|
84
|
+
});
|
|
85
|
+
this.dispatcher = new Dispatcher(options.budget);
|
|
86
|
+
}
|
|
87
|
+
async connect() {
|
|
88
|
+
await this.client.negotiate();
|
|
89
|
+
const list = await this.client.listTools();
|
|
90
|
+
const pins = pinTools(list.tools);
|
|
91
|
+
const snapshot = {
|
|
92
|
+
tools: list.tools,
|
|
93
|
+
digest: pins.catalog,
|
|
94
|
+
pins,
|
|
95
|
+
ttlMs: list.ttlMs,
|
|
96
|
+
expiresAt: Date.now() + list.ttlMs,
|
|
97
|
+
};
|
|
98
|
+
this.catalog = snapshot;
|
|
99
|
+
return snapshot;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Re-list and compare. Any changed, added or removed tool fails closed.
|
|
103
|
+
*/
|
|
104
|
+
async refresh() {
|
|
105
|
+
const list = await this.client.listTools();
|
|
106
|
+
const pins = pinTools(list.tools);
|
|
107
|
+
if (this.catalog) {
|
|
108
|
+
const verdict = verifyToolPins(this.catalog.pins, list.tools);
|
|
109
|
+
if (!verdict.ok) {
|
|
110
|
+
throw new DriftDetected(`tool catalog changed: ${verdict.reasons.join("; ")}`, this.receipt("catalog.refresh", this.dispatcher.usage(), "blocked", {
|
|
111
|
+
note: verdict.reasons.join("; "),
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const snapshot = {
|
|
116
|
+
tools: list.tools,
|
|
117
|
+
digest: pins.catalog,
|
|
118
|
+
pins,
|
|
119
|
+
ttlMs: list.ttlMs,
|
|
120
|
+
expiresAt: Date.now() + list.ttlMs,
|
|
121
|
+
};
|
|
122
|
+
this.catalog = snapshot;
|
|
123
|
+
return snapshot;
|
|
124
|
+
}
|
|
125
|
+
async ensureFresh() {
|
|
126
|
+
if (!this.catalog) {
|
|
127
|
+
await this.connect();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (Date.now() < this.catalog.expiresAt) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
await this.refresh();
|
|
134
|
+
}
|
|
135
|
+
tools() {
|
|
136
|
+
return this.catalog?.tools ?? [];
|
|
137
|
+
}
|
|
138
|
+
tool(name) {
|
|
139
|
+
return this.tools().find((tool) => tool.name === name);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Host-only convenience: issue an approval bound to the current tool schema
|
|
143
|
+
* and the exact arguments. The model must never be given this method.
|
|
144
|
+
*/
|
|
145
|
+
approveTool(name, args, approvedBy, ttlMs, scope) {
|
|
146
|
+
const tool = this.tool(name);
|
|
147
|
+
if (!tool) {
|
|
148
|
+
throw new PolicyDenied(`unknown tool: ${name}`);
|
|
149
|
+
}
|
|
150
|
+
return this.policy.approve({
|
|
151
|
+
action: name,
|
|
152
|
+
effect: effectFor(tool),
|
|
153
|
+
approvedBy,
|
|
154
|
+
ttlMs,
|
|
155
|
+
scope,
|
|
156
|
+
toolDigest: digestTool(tool),
|
|
157
|
+
argsDigest: digestOf(args),
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Non-throwing drift check for monitoring.
|
|
162
|
+
*/
|
|
163
|
+
async verify() {
|
|
164
|
+
const list = await this.client.listTools();
|
|
165
|
+
const pins = pinTools(list.tools);
|
|
166
|
+
return {
|
|
167
|
+
ok: this.catalog !== (void 0) && pins.catalog === this.catalog.digest,
|
|
168
|
+
digest: pins.catalog,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
async call(name, args, options = {}) {
|
|
172
|
+
await this.ensureFresh();
|
|
173
|
+
const tool = this.tool(name);
|
|
174
|
+
if (!tool) {
|
|
175
|
+
throw new PolicyDenied(`unknown tool: ${name}`, this.receipt(name, this.dispatcher.usage(), "blocked", { note: `unknown_tool:${name}` }));
|
|
176
|
+
}
|
|
177
|
+
if (this.verifyPinsAtCall) {
|
|
178
|
+
const fresh = await this.client.listTools();
|
|
179
|
+
const pinned = verifyToolPins(this.catalog?.pins ?? pinTools([]), fresh.tools);
|
|
180
|
+
if (!pinned.ok) {
|
|
181
|
+
const receipt = this.receipt(name, this.dispatcher.usage(), "blocked", {
|
|
182
|
+
note: pinned.reasons.join("; "),
|
|
183
|
+
});
|
|
184
|
+
throw new DriftDetected(`tool changed before call: ${pinned.reasons.join("; ")}`, receipt);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
let callArgs = args;
|
|
188
|
+
let argsDigest = digestOf(args);
|
|
189
|
+
if (this.validateArgs) {
|
|
190
|
+
try {
|
|
191
|
+
const parsed = parseToolCall({ name: tool.name, inputSchema: tool.inputSchema }, args);
|
|
192
|
+
callArgs = parsed.args;
|
|
193
|
+
argsDigest = parsed.digest;
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
if (error instanceof BoundaryRejection) {
|
|
197
|
+
const receipt = this.receipt(name, this.dispatcher.usage(), "blocked", {
|
|
198
|
+
note: `invalid_tool_args:${error.problems.join("; ")}`,
|
|
199
|
+
});
|
|
200
|
+
throw new PolicyDenied(`invalid arguments for ${name}: ${error.problems.join("; ")}`, receipt);
|
|
201
|
+
}
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
const effect = options.effect ?? effectFor(tool);
|
|
206
|
+
const verdict = this.policy.decide({
|
|
207
|
+
action: name,
|
|
208
|
+
target: { kind: "tool", id: `mcp.${name}` },
|
|
209
|
+
effect,
|
|
210
|
+
claim: options.claim,
|
|
211
|
+
toolDigest: digestTool(tool),
|
|
212
|
+
argsDigest,
|
|
213
|
+
}, options.approval);
|
|
214
|
+
if (verdict.outcome !== "allow") {
|
|
215
|
+
const receipt = this.receipt(name, this.dispatcher.usage(), "blocked", {
|
|
216
|
+
note: `${verdict.outcome}:${verdict.reason}`,
|
|
217
|
+
});
|
|
218
|
+
if (verdict.outcome === "approval_required") {
|
|
219
|
+
throw new ApprovalRequired(name, receipt, verdict.reason);
|
|
220
|
+
}
|
|
221
|
+
throw new PolicyDenied(`policy denied ${name}: ${verdict.reason}`, receipt);
|
|
222
|
+
}
|
|
223
|
+
try {
|
|
224
|
+
this.guard?.beforeDispatch({ money: options.money ?? 0 });
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
const receipt = this.receipt(name, this.dispatcher.usage(), "blocked", {
|
|
228
|
+
note: error instanceof Error ? error.message : `${error}`,
|
|
229
|
+
});
|
|
230
|
+
throw new PolicyDenied(`guard blocked ${name}: ${`${error}`}`, receipt);
|
|
231
|
+
}
|
|
232
|
+
const budgetTokens = options.budgetTokens ?? this.maxResultTokens;
|
|
233
|
+
let text;
|
|
234
|
+
try {
|
|
235
|
+
const result = await this.dispatcher.run(() => this.client.callTool(name, callArgs), {
|
|
236
|
+
calls: 1,
|
|
237
|
+
ms: 900,
|
|
238
|
+
});
|
|
239
|
+
text = textOf(result);
|
|
240
|
+
this.guard?.recordSuccess();
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
this.guard?.recordFailure();
|
|
244
|
+
this.receipt(name, this.dispatcher.usage(), "blocked", {
|
|
245
|
+
note: error instanceof BudgetExceeded ? `${error.code}:${error.dimension}` : `${error}`,
|
|
246
|
+
});
|
|
247
|
+
throw error;
|
|
248
|
+
}
|
|
249
|
+
const tokens = Math.ceil(text.length / 4);
|
|
250
|
+
if (tokens > budgetTokens) {
|
|
251
|
+
const handle = this.handles.put(text, "text", tokens);
|
|
252
|
+
const receipt = this.receipt(name, this.dispatcher.usage(), "success", {
|
|
253
|
+
handle,
|
|
254
|
+
predicted_voi: options.predictedVoi,
|
|
255
|
+
realized_voi: options.realizedVoi,
|
|
256
|
+
note: `result ${tokens} tokens > budget ${budgetTokens}; handle emitted, nothing truncated`,
|
|
257
|
+
});
|
|
258
|
+
return { receipt, handle: handle.id, tokens };
|
|
259
|
+
}
|
|
260
|
+
const receipt = this.receipt(name, this.dispatcher.usage(), "success", {
|
|
261
|
+
predicted_voi: options.predictedVoi,
|
|
262
|
+
realized_voi: options.realizedVoi,
|
|
263
|
+
});
|
|
264
|
+
return { receipt, inline: text, tokens };
|
|
265
|
+
}
|
|
266
|
+
receipt(tool, usage, outcome, extra = {}) {
|
|
267
|
+
this.seq += 1;
|
|
268
|
+
const receipt = {
|
|
269
|
+
amp: "0.1",
|
|
270
|
+
kind: "receipt",
|
|
271
|
+
id: `rc.exec.${this.seq}`,
|
|
272
|
+
op: "act",
|
|
273
|
+
target: { kind: "tool", id: `mcp.${tool}` },
|
|
274
|
+
at: this.now(),
|
|
275
|
+
usage,
|
|
276
|
+
outcome,
|
|
277
|
+
...extra,
|
|
278
|
+
};
|
|
279
|
+
this.onReceipt?.(receipt);
|
|
280
|
+
return receipt;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Handle } from "../types/common.js";
|
|
2
|
+
export interface HandlePage {
|
|
3
|
+
text: string;
|
|
4
|
+
next: number | null;
|
|
5
|
+
totalPages: number;
|
|
6
|
+
tokens: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Content-addressed handle store.
|
|
10
|
+
*
|
|
11
|
+
* Handles are opaque names, not capabilities: possession of an id must not be
|
|
12
|
+
* sufficient to read it in a real host (scope + session binding live outside
|
|
13
|
+
* this reference implementation, see architecture §11.1 T5).
|
|
14
|
+
*/
|
|
15
|
+
export declare class HandleStore {
|
|
16
|
+
private records;
|
|
17
|
+
private seq;
|
|
18
|
+
put(content: string, kind: Handle["kind"], tokens: number, scope?: Handle["scope"], ttlMs?: number): Handle;
|
|
19
|
+
has(id: string): boolean;
|
|
20
|
+
get(id: string): Handle | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Deterministic paging: same cursor always returns the same window.
|
|
23
|
+
*/
|
|
24
|
+
read(id: string, cursor: number, limitTokens?: number): HandlePage;
|
|
25
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { sha256Hex } from "../semantic/sha256.js";
|
|
2
|
+
const CharsPerToken = 4;
|
|
3
|
+
/**
|
|
4
|
+
* Content-addressed handle store.
|
|
5
|
+
*
|
|
6
|
+
* Handles are opaque names, not capabilities: possession of an id must not be
|
|
7
|
+
* sufficient to read it in a real host (scope + session binding live outside
|
|
8
|
+
* this reference implementation, see architecture §11.1 T5).
|
|
9
|
+
*/
|
|
10
|
+
export class HandleStore {
|
|
11
|
+
records = new Map();
|
|
12
|
+
seq = 0;
|
|
13
|
+
put(content, kind, tokens, scope = "session", ttlMs = 900_000) {
|
|
14
|
+
this.seq += 1;
|
|
15
|
+
const id = `h.${sha256Hex(`${kind}:${this.seq}:${content.length}`).slice(0, 10)}`;
|
|
16
|
+
const handle = { id, kind, tokens, scope, ttl_ms: ttlMs };
|
|
17
|
+
this.records.set(id, { handle, content, createdAt: Date.now() });
|
|
18
|
+
return handle;
|
|
19
|
+
}
|
|
20
|
+
has(id) {
|
|
21
|
+
return this.records.has(id);
|
|
22
|
+
}
|
|
23
|
+
get(id) {
|
|
24
|
+
return this.records.get(id)?.handle;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Deterministic paging: same cursor always returns the same window.
|
|
28
|
+
*/
|
|
29
|
+
read(id, cursor, limitTokens = 240) {
|
|
30
|
+
const record = this.records.get(id);
|
|
31
|
+
if (!record) {
|
|
32
|
+
throw new Error(`unknown handle: ${id}`);
|
|
33
|
+
}
|
|
34
|
+
const window = Math.max(1, limitTokens * CharsPerToken);
|
|
35
|
+
const start = Math.max(0, Math.min(cursor, record.content.length));
|
|
36
|
+
const end = Math.min(record.content.length, start + window);
|
|
37
|
+
const text = record.content.slice(start, end);
|
|
38
|
+
return {
|
|
39
|
+
text,
|
|
40
|
+
next: end < record.content.length ? end : null,
|
|
41
|
+
totalPages: Math.ceil(record.content.length / window),
|
|
42
|
+
tokens: Math.ceil(text.length / CharsPerToken),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Digest } from "../types/common.js";
|
|
2
|
+
import type { McpTool } from "../module/mcp/protocol.js";
|
|
3
|
+
/**
|
|
4
|
+
* Per-tool catalog pinning.
|
|
5
|
+
*
|
|
6
|
+
* The whole-catalog digest in `ExecProfile` is useful for detecting a changed
|
|
7
|
+
* list, but it is checked at connect/refresh time. The TOCTOU window remains:
|
|
8
|
+
* a server can change one tool between that check and the moment its schema is
|
|
9
|
+
* used to validate arguments. These helpers make the pin explicit per tool so
|
|
10
|
+
* a host can re-assert it immediately before a call.
|
|
11
|
+
*
|
|
12
|
+
* `digestTool` covers the fields that influence what the model sees and what
|
|
13
|
+
* arguments are validated: name, title, description, input schema and
|
|
14
|
+
* annotations. It deliberately does not cover the MCP output schema, which is
|
|
15
|
+
* not used for input validation.
|
|
16
|
+
*/
|
|
17
|
+
export interface ToolPins {
|
|
18
|
+
/**
|
|
19
|
+
* Digest of the tool set, sorted by name.
|
|
20
|
+
*
|
|
21
|
+
* MCP only SHOULD return a deterministic order and AMP must not build a
|
|
22
|
+
* signature or cache on a server-controlled order (architecture §10.6), so
|
|
23
|
+
* reordering the same tools is not drift.
|
|
24
|
+
*/
|
|
25
|
+
catalog: Digest;
|
|
26
|
+
/**
|
|
27
|
+
* Tool name to per-tool digest.
|
|
28
|
+
*/
|
|
29
|
+
tools: ReadonlyMap<string, Digest>;
|
|
30
|
+
}
|
|
31
|
+
export interface PinVerdict {
|
|
32
|
+
ok: boolean;
|
|
33
|
+
reasons: string[];
|
|
34
|
+
/**
|
|
35
|
+
* Names whose digest changed, plus added/removed names.
|
|
36
|
+
*/
|
|
37
|
+
changed: string[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Stable digest of one tool, including its description and input schema.
|
|
41
|
+
*/
|
|
42
|
+
export declare const digestTool: (tool: McpTool) => Digest;
|
|
43
|
+
/**
|
|
44
|
+
* Build a pin set from a `tools/list` result. Duplicate names fail closed.
|
|
45
|
+
*/
|
|
46
|
+
export declare const pinTools: (tools: readonly McpTool[]) => ToolPins;
|
|
47
|
+
/**
|
|
48
|
+
* Compare a fresh tool list against a previous pin set.
|
|
49
|
+
*
|
|
50
|
+
* The catalog digest catches reordering/removals; per-tool comparison catches a
|
|
51
|
+
* changed description or schema even when the list shape is unchanged.
|
|
52
|
+
*/
|
|
53
|
+
export declare const verifyToolPins: (pins: ToolPins, tools: readonly McpTool[]) => PinVerdict;
|
|
54
|
+
/**
|
|
55
|
+
* Assert that the requested tool is still exactly the pinned tool.
|
|
56
|
+
*
|
|
57
|
+
* A host can call this with the schema it is about to use for validation; an
|
|
58
|
+
* absent pin is a failure, never an implicit trust decision.
|
|
59
|
+
*/
|
|
60
|
+
export declare const assertToolPinned: (pins: ToolPins, tool: McpTool) => PinVerdict;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { digestOf } from "../semantic/canonical.js";
|
|
2
|
+
/**
|
|
3
|
+
* Stable digest of one tool, including its description and input schema.
|
|
4
|
+
*/
|
|
5
|
+
export const digestTool = (tool) => {
|
|
6
|
+
return digestOf({
|
|
7
|
+
name: tool.name,
|
|
8
|
+
title: tool.title,
|
|
9
|
+
description: tool.description,
|
|
10
|
+
inputSchema: tool.inputSchema,
|
|
11
|
+
annotations: tool.annotations ?? {},
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Build a pin set from a `tools/list` result. Duplicate names fail closed.
|
|
16
|
+
*/
|
|
17
|
+
export const pinTools = (tools) => {
|
|
18
|
+
const pinned = new Map();
|
|
19
|
+
for (let i = 0; i < tools.length; i += 1) {
|
|
20
|
+
const tool = tools[i];
|
|
21
|
+
if (pinned.has(tool.name)) {
|
|
22
|
+
throw new Error(`duplicate tool name in catalog: ${tool.name}`);
|
|
23
|
+
}
|
|
24
|
+
pinned.set(tool.name, digestTool(tool));
|
|
25
|
+
}
|
|
26
|
+
return { catalog: catalogDigest(tools), tools: pinned };
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Order-independent digest of a tool catalog.
|
|
30
|
+
*/
|
|
31
|
+
const catalogDigest = (tools) => {
|
|
32
|
+
const sorted = [...tools].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
33
|
+
return digestOf(sorted);
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Compare a fresh tool list against a previous pin set.
|
|
37
|
+
*
|
|
38
|
+
* The catalog digest catches reordering/removals; per-tool comparison catches a
|
|
39
|
+
* changed description or schema even when the list shape is unchanged.
|
|
40
|
+
*/
|
|
41
|
+
export const verifyToolPins = (pins, tools) => {
|
|
42
|
+
const reasons = [];
|
|
43
|
+
const changed = new Set();
|
|
44
|
+
const current = new Map();
|
|
45
|
+
for (let i = 0; i < tools.length; i += 1) {
|
|
46
|
+
const tool = tools[i];
|
|
47
|
+
if (current.has(tool.name)) {
|
|
48
|
+
reasons.push(`duplicate tool name: ${tool.name}`);
|
|
49
|
+
changed.add(tool.name);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
current.set(tool.name, tool);
|
|
53
|
+
}
|
|
54
|
+
const pinnedTools = [...pins.tools];
|
|
55
|
+
for (let i = 0; i < pinnedTools.length; i += 1) {
|
|
56
|
+
const name = pinnedTools[i][0];
|
|
57
|
+
const digest = pinnedTools[i][1];
|
|
58
|
+
const tool = current.get(name);
|
|
59
|
+
if (!tool) {
|
|
60
|
+
reasons.push(`tool removed: ${name}`);
|
|
61
|
+
changed.add(name);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const next = digestTool(tool);
|
|
65
|
+
if (next !== digest) {
|
|
66
|
+
reasons.push(`tool changed: ${name} ${digest} -> ${next}`);
|
|
67
|
+
changed.add(name);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const currentNames = [...current.keys()];
|
|
71
|
+
for (let i = 0; i < currentNames.length; i += 1) {
|
|
72
|
+
const name = currentNames[i];
|
|
73
|
+
if (!pins.tools.has(name)) {
|
|
74
|
+
reasons.push(`tool added: ${name}`);
|
|
75
|
+
changed.add(name);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (catalogDigest(tools) !== pins.catalog) {
|
|
79
|
+
reasons.push("catalog digest changed");
|
|
80
|
+
}
|
|
81
|
+
return { ok: reasons.length === 0, reasons, changed: [...changed].sort() };
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Assert that the requested tool is still exactly the pinned tool.
|
|
85
|
+
*
|
|
86
|
+
* A host can call this with the schema it is about to use for validation; an
|
|
87
|
+
* absent pin is a failure, never an implicit trust decision.
|
|
88
|
+
*/
|
|
89
|
+
export const assertToolPinned = (pins, tool) => {
|
|
90
|
+
const expected = pins.tools.get(tool.name);
|
|
91
|
+
if (expected === (void 0)) {
|
|
92
|
+
return { ok: false, reasons: [`tool not pinned: ${tool.name}`], changed: [tool.name] };
|
|
93
|
+
}
|
|
94
|
+
const actual = digestTool(tool);
|
|
95
|
+
if (actual !== expected) {
|
|
96
|
+
return {
|
|
97
|
+
ok: false,
|
|
98
|
+
reasons: [`tool changed: ${tool.name} ${expected} -> ${actual}`],
|
|
99
|
+
changed: [tool.name],
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return { ok: true, reasons: [], changed: [] };
|
|
103
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AMP v0.1 — Frame (注意帧): one immutable allocation snapshot.
|
|
3
|
+
* Mirrors docs/schemas/frame.schema.json.
|
|
4
|
+
*/
|
|
5
|
+
import type { Budget, Confidence, Digest, Id, Ref, Tier, Timestamp, Usage } from "../types/common.js";
|
|
6
|
+
export type FrameMode = "explore" | "exploit" | "triage" | "reflect" | "rest";
|
|
7
|
+
export type SlotRole = "goal" | "question" | "evidence" | "concept" | "process" | "tool" | "memory" | "self" | "other" | "threat" | "artifact";
|
|
8
|
+
export type IgnoredReason = "low_voi" | "out_of_scope" | "untrusted" | "budget" | "blocked" | "habituated" | "deferred";
|
|
9
|
+
export type ImpasseState = "TIE" | "STUCK" | "STALLED" | "CONFLICT" | "INFEASIBLE" | "UNKNOWN" | "UNVERIFIED" | "DRIFT" | "BUDGET";
|
|
10
|
+
/**
|
|
11
|
+
* Why something is being attended to — required, not decorative (A-1).
|
|
12
|
+
*/
|
|
13
|
+
export interface Slot {
|
|
14
|
+
target: Ref;
|
|
15
|
+
role: SlotRole;
|
|
16
|
+
tier?: Tier;
|
|
17
|
+
salience: Confidence;
|
|
18
|
+
voi?: Confidence;
|
|
19
|
+
cost: Budget;
|
|
20
|
+
budget?: Budget;
|
|
21
|
+
why: string;
|
|
22
|
+
ttl_turns?: number;
|
|
23
|
+
state: "active" | "released" | "evicted" | "done";
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Deliberate exclusion. The distinctive field: no classical architecture records this.
|
|
27
|
+
*/
|
|
28
|
+
export interface Ignored {
|
|
29
|
+
target: Ref;
|
|
30
|
+
reason: IgnoredReason;
|
|
31
|
+
revisit_if: string;
|
|
32
|
+
}
|
|
33
|
+
export interface FrameBudget {
|
|
34
|
+
allocated: Budget;
|
|
35
|
+
spent: Usage;
|
|
36
|
+
}
|
|
37
|
+
export interface Impasse {
|
|
38
|
+
state: ImpasseState;
|
|
39
|
+
detail?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface Frame {
|
|
42
|
+
amp: "0.1";
|
|
43
|
+
kind: "frame";
|
|
44
|
+
id: Id;
|
|
45
|
+
agent: Id;
|
|
46
|
+
cycle: number;
|
|
47
|
+
ts: Timestamp;
|
|
48
|
+
parent?: Ref;
|
|
49
|
+
digest: Digest;
|
|
50
|
+
mode: FrameMode;
|
|
51
|
+
goal?: Ref;
|
|
52
|
+
/**
|
|
53
|
+
* At most 9 slots. Capacity is the point, not a limitation.
|
|
54
|
+
*/
|
|
55
|
+
slots: Slot[];
|
|
56
|
+
ignored?: Ignored[];
|
|
57
|
+
budget: FrameBudget;
|
|
58
|
+
open_questions?: Ref[];
|
|
59
|
+
impasse?: Impasse;
|
|
60
|
+
note?: string;
|
|
61
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./frame.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./frame.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Goal lifecycle: the admission state machine for a `Goal`.
|
|
3
|
+
*
|
|
4
|
+
* A goal is not "active" because someone said so; it moves through explicit
|
|
5
|
+
* states, and `achieved`/`abandoned` are terminal. The plan and warrant layers
|
|
6
|
+
* read this state instead of inferring intent from prose.
|
|
7
|
+
*/
|
|
8
|
+
import type { Goal } from "./plan.js";
|
|
9
|
+
export type GoalState = "proposed" | "committed" | "active" | "achieved" | "abandoned";
|
|
10
|
+
export interface GoalLifecycle {
|
|
11
|
+
goal: Goal;
|
|
12
|
+
state: GoalState;
|
|
13
|
+
startedAt?: string;
|
|
14
|
+
achievedAt?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare const createGoalLifecycle: (goal: Goal) => GoalLifecycle;
|
|
17
|
+
type TransitionGoal = (lifecycle: GoalLifecycle, to: GoalState, at: string) => GoalLifecycle;
|
|
18
|
+
export declare const transitionGoal: TransitionGoal;
|
|
19
|
+
export {};
|
package/lib/goal/goal.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const GoalEdges = {
|
|
2
|
+
proposed: ["committed", "abandoned"],
|
|
3
|
+
committed: ["active", "abandoned"],
|
|
4
|
+
active: ["achieved", "abandoned"],
|
|
5
|
+
achieved: [],
|
|
6
|
+
abandoned: [],
|
|
7
|
+
};
|
|
8
|
+
export const createGoalLifecycle = (goal) => ({ goal, state: "proposed" });
|
|
9
|
+
export const transitionGoal = (lifecycle, to, at) => {
|
|
10
|
+
if (!GoalEdges[lifecycle.state].includes(to)) {
|
|
11
|
+
throw new Error(`goal ${lifecycle.goal.id}: ${lifecycle.state} -> ${to} is not an edge`);
|
|
12
|
+
}
|
|
13
|
+
const next = { ...lifecycle, state: to };
|
|
14
|
+
if (to === "active" && next.startedAt === (void 0)) {
|
|
15
|
+
next.startedAt = at;
|
|
16
|
+
}
|
|
17
|
+
if (to === "achieved") {
|
|
18
|
+
next.achievedAt = at;
|
|
19
|
+
}
|
|
20
|
+
return next;
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createGoalLifecycle, transitionGoal } from "./goal.js";
|