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,424 @@
|
|
|
1
|
+
import { BudgetDimensions, ElasticityLimits, GovernanceError, budgetTotals } from "./types.js";
|
|
2
|
+
import { canApprove } from "./perspectives.js";
|
|
3
|
+
const sumBudget = (left, right) => {
|
|
4
|
+
const added = budgetTotals(right);
|
|
5
|
+
const result = { ...left };
|
|
6
|
+
for (let index = 0; index < BudgetDimensions.length; index += 1) {
|
|
7
|
+
const dimension = BudgetDimensions[index];
|
|
8
|
+
result[dimension] = left[dimension] + added[dimension];
|
|
9
|
+
}
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
const projectedRatio = (used, cap, amount) => {
|
|
13
|
+
const added = budgetTotals(amount);
|
|
14
|
+
let ratio = 0;
|
|
15
|
+
for (let index = 0; index < BudgetDimensions.length; index += 1) {
|
|
16
|
+
const dimension = BudgetDimensions[index];
|
|
17
|
+
if (cap[dimension] <= 0) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
ratio = Math.max(ratio, (used[dimension] + added[dimension]) / cap[dimension]);
|
|
21
|
+
}
|
|
22
|
+
return ratio;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Reject negative, NaN or infinite amounts before any arithmetic. A negative
|
|
26
|
+
* charge would otherwise mint quota.
|
|
27
|
+
*/
|
|
28
|
+
const validateBudget = (budget, label) => {
|
|
29
|
+
for (let index = 0; index < BudgetDimensions.length; index += 1) {
|
|
30
|
+
const value = budget[BudgetDimensions[index]];
|
|
31
|
+
if (value === (void 0)) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (!Number.isFinite(value) || value < 0) {
|
|
35
|
+
throw new GovernanceError("budget-invalid", `${label}.${BudgetDimensions[index]} must be a finite non-negative number`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const snapshotOf = (state) => {
|
|
40
|
+
const ratio = projectedRatio(state.used, state.cap, {});
|
|
41
|
+
return {
|
|
42
|
+
scope: state.scope,
|
|
43
|
+
id: state.id,
|
|
44
|
+
cap: { ...state.cap },
|
|
45
|
+
used: { ...state.used },
|
|
46
|
+
ratio,
|
|
47
|
+
frozen: state.frozen,
|
|
48
|
+
elasticity: state.elasticity,
|
|
49
|
+
...(state.frozenReason === (void 0) ? {} : { frozenReason: state.frozenReason }),
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* The three-ledger meter.
|
|
54
|
+
*
|
|
55
|
+
* Elasticity semantics:
|
|
56
|
+
* - low: up to +20% is appended automatically; beyond that the ledger freezes;
|
|
57
|
+
* - medium: anything above the cap needs a finance `budget.top-up` approval,
|
|
58
|
+
* up to +35%;
|
|
59
|
+
* - high: up to +50% is appended automatically and settled by a post audit.
|
|
60
|
+
*/
|
|
61
|
+
export class GovernanceBudget {
|
|
62
|
+
now;
|
|
63
|
+
global;
|
|
64
|
+
reserve;
|
|
65
|
+
perspectives = new Map();
|
|
66
|
+
agents = new Map();
|
|
67
|
+
records = [];
|
|
68
|
+
audits = [];
|
|
69
|
+
transfers = [];
|
|
70
|
+
constructor(options) {
|
|
71
|
+
if (typeof (options.now) !== "function") {
|
|
72
|
+
throw new TypeError("GovernanceBudget requires a clock");
|
|
73
|
+
}
|
|
74
|
+
this.now = options.now;
|
|
75
|
+
this.global = this.state("global", "global", options.global);
|
|
76
|
+
this.reserve = this.state("reserve", "reserve", options.reserve);
|
|
77
|
+
const configured = options.perspectives ?? [];
|
|
78
|
+
for (let index = 0; index < configured.length; index += 1) {
|
|
79
|
+
const entry = configured[index];
|
|
80
|
+
this.perspectives.set(entry.perspective, this.state("perspective", entry.perspective, entry));
|
|
81
|
+
}
|
|
82
|
+
const agentLedgers = options.agents ?? [];
|
|
83
|
+
for (let index = 0; index < agentLedgers.length; index += 1) {
|
|
84
|
+
const entry = agentLedgers[index];
|
|
85
|
+
this.agents.set(entry.agent, this.state("agent", entry.agent, entry));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Open a perspective ledger. Re-opening with a different cap is rejected:
|
|
90
|
+
* a budget change is an approval, not a convenience call.
|
|
91
|
+
*/
|
|
92
|
+
openPerspective(perspective, cap, elasticity = "low") {
|
|
93
|
+
const existing = this.perspectives.get(perspective);
|
|
94
|
+
if (existing !== (void 0)) {
|
|
95
|
+
throw new GovernanceError("budget-frozen", `ledger for ${perspective} already exists`);
|
|
96
|
+
}
|
|
97
|
+
const state = this.state("perspective", perspective, { cap, elasticity });
|
|
98
|
+
this.perspectives.set(perspective, state);
|
|
99
|
+
return snapshotOf(state);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Open an agent ledger (an agent's own quota).
|
|
103
|
+
*/
|
|
104
|
+
openAgent(agent, cap, elasticity = "low") {
|
|
105
|
+
const existing = this.agents.get(agent);
|
|
106
|
+
if (existing !== (void 0)) {
|
|
107
|
+
throw new GovernanceError("budget-frozen", `ledger for agent ${agent} already exists`);
|
|
108
|
+
}
|
|
109
|
+
const state = this.state("agent", agent, { cap, elasticity });
|
|
110
|
+
this.agents.set(agent, state);
|
|
111
|
+
return snapshotOf(state);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Transfer allocation between a perspective and an agent. A sub-agent's
|
|
115
|
+
* quota is funded from its parent; the total allocation is conserved.
|
|
116
|
+
* The finance `budget.allocation` approval is mandatory.
|
|
117
|
+
*/
|
|
118
|
+
reallocate = (from, to, request) => {
|
|
119
|
+
const amount = request.amount;
|
|
120
|
+
const approval = request.approval;
|
|
121
|
+
const reason = request.reason;
|
|
122
|
+
const options = request.options ?? {};
|
|
123
|
+
validateBudget(amount, "reallocation");
|
|
124
|
+
const targetFrom = this.lookup(from.scope, from.id);
|
|
125
|
+
const existingTo = to.scope === "perspective" ? this.perspectives.get(to.id) : this.agents.get(to.id);
|
|
126
|
+
const targetTo = existingTo ?? this.state(to.scope, to.id, { cap: {}, elasticity: options.toElasticity ?? "low" });
|
|
127
|
+
if (targetFrom.frozen) {
|
|
128
|
+
return { ok: false, code: "frozen", from: snapshotOf(targetFrom), to: snapshotOf(targetTo), detail: `${from.id} is frozen` };
|
|
129
|
+
}
|
|
130
|
+
if (targetTo.frozen) {
|
|
131
|
+
return { ok: false, code: "frozen", from: snapshotOf(targetFrom), to: snapshotOf(targetTo), detail: `${to.id} is frozen` };
|
|
132
|
+
}
|
|
133
|
+
const valid = approval.granted === true &&
|
|
134
|
+
approval.subject === "budget.allocation" &&
|
|
135
|
+
canApprove(approval.by, "budget.allocation") &&
|
|
136
|
+
options.requestedBy !== (void 0) &&
|
|
137
|
+
options.requestedBy !== approval.by;
|
|
138
|
+
if (!valid) {
|
|
139
|
+
return { ok: false, code: "approval-required", from: snapshotOf(targetFrom), to: snapshotOf(targetTo), detail: "a finance budget.allocation approval is required" };
|
|
140
|
+
}
|
|
141
|
+
const moved = budgetTotals(amount);
|
|
142
|
+
for (let index = 0; index < BudgetDimensions.length; index += 1) {
|
|
143
|
+
const dimension = BudgetDimensions[index];
|
|
144
|
+
if (moved[dimension] <= 0) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
const available = targetFrom.cap[dimension] - targetFrom.used[dimension];
|
|
148
|
+
if (targetFrom.cap[dimension] <= 0 || moved[dimension] > available) {
|
|
149
|
+
return {
|
|
150
|
+
ok: false,
|
|
151
|
+
code: "insufficient",
|
|
152
|
+
from: snapshotOf(targetFrom),
|
|
153
|
+
to: snapshotOf(targetTo),
|
|
154
|
+
detail: `${dimension}: ${moved[dimension]} requested, ${Math.max(0, available)} available`,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
for (let index = 0; index < BudgetDimensions.length; index += 1) {
|
|
159
|
+
const dimension = BudgetDimensions[index];
|
|
160
|
+
targetFrom.cap[dimension] -= moved[dimension];
|
|
161
|
+
targetTo.cap[dimension] += moved[dimension];
|
|
162
|
+
}
|
|
163
|
+
if (existingTo === (void 0)) {
|
|
164
|
+
if (to.scope === "perspective") {
|
|
165
|
+
this.perspectives.set(to.id, targetTo);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
this.agents.set(to.id, targetTo);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
this.transfers.push({
|
|
172
|
+
at: this.now(),
|
|
173
|
+
fromScope: from.scope,
|
|
174
|
+
fromId: from.id,
|
|
175
|
+
toScope: to.scope,
|
|
176
|
+
toId: to.id,
|
|
177
|
+
amount: moved,
|
|
178
|
+
reason,
|
|
179
|
+
approvalId: approval.id,
|
|
180
|
+
});
|
|
181
|
+
return { ok: true, code: "reallocated", from: snapshotOf(targetFrom), to: snapshotOf(targetTo), detail: `moved ${reason}` };
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* Charge one ledger. Denials are values; a frozen ledger refuses before
|
|
185
|
+
* arithmetic so no caller can spend past a freeze.
|
|
186
|
+
*/
|
|
187
|
+
charge(request) {
|
|
188
|
+
validateBudget(request.amount, "charge");
|
|
189
|
+
const target = this.resolve(request);
|
|
190
|
+
const snapshot = snapshotOf(target);
|
|
191
|
+
if (target.frozen) {
|
|
192
|
+
return this.reject("frozen", snapshot, snapshot.ratio, target.frozenReason ?? "ledger is frozen");
|
|
193
|
+
}
|
|
194
|
+
if (request.scope === "reserve") {
|
|
195
|
+
if (request.escalation !== true) {
|
|
196
|
+
return this.reject("reserve-restricted", snapshot, snapshot.ratio, "the reserve ledger only funds escalations");
|
|
197
|
+
}
|
|
198
|
+
if (!this.approved(request, "budget.reserve")) {
|
|
199
|
+
return this.reject("approval-required", snapshot, snapshot.ratio, "a reserve charge needs a finance budget.reserve approval");
|
|
200
|
+
}
|
|
201
|
+
if (projectedRatio(target.used, target.cap, request.amount) > 0.5 && !this.boardApproved(request.boardApproval)) {
|
|
202
|
+
return this.reject("approval-required", snapshot, snapshot.ratio, "a reserve draw above 50% also needs a board approval");
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
const ratio = projectedRatio(target.used, target.cap, request.amount);
|
|
206
|
+
const limit = ElasticityLimits[target.elasticity];
|
|
207
|
+
if (ratio <= 1) {
|
|
208
|
+
this.commit(target, request, "charged", ratio);
|
|
209
|
+
return { ok: true, code: "charged", ledger: snapshotOf(target), ratio, detail: "within cap" };
|
|
210
|
+
}
|
|
211
|
+
if (ratio <= 1 + limit.autoRatio) {
|
|
212
|
+
const code = limit.postAudit ? "charged-post-audit" : "charged";
|
|
213
|
+
this.commit(target, request, code, ratio);
|
|
214
|
+
if (limit.postAudit) {
|
|
215
|
+
this.audits.push({ at: this.now(), scope: target.scope, ledgerId: target.id, amount: budgetTotals(request.amount), reason: request.reason });
|
|
216
|
+
}
|
|
217
|
+
return { ok: true, code, ledger: snapshotOf(target), ratio, detail: `within ${Math.round(limit.autoRatio * 100)}% elasticity` };
|
|
218
|
+
}
|
|
219
|
+
if (limit.requiresApproval && ratio <= 1 + limit.hardRatio) {
|
|
220
|
+
if (!this.approved(request, "budget.top-up")) {
|
|
221
|
+
return this.reject("approval-required", snapshot, ratio, "over cap; finance top-up approval required");
|
|
222
|
+
}
|
|
223
|
+
this.commit(target, request, "charged-with-approval", ratio);
|
|
224
|
+
return {
|
|
225
|
+
ok: true,
|
|
226
|
+
code: "charged-with-approval",
|
|
227
|
+
ledger: snapshotOf(target),
|
|
228
|
+
ratio,
|
|
229
|
+
detail: "over cap with finance approval",
|
|
230
|
+
...(request.approval === (void 0) ? {} : { approvalId: request.approval.id }),
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
target.frozen = true;
|
|
234
|
+
target.frozenReason = `hard ceiling at ${Math.round((1 + limit.hardRatio) * 100)}% of cap`;
|
|
235
|
+
this.records.push({
|
|
236
|
+
at: this.now(),
|
|
237
|
+
scope: target.scope,
|
|
238
|
+
ledgerId: target.id,
|
|
239
|
+
amount: budgetTotals(request.amount),
|
|
240
|
+
reason: request.reason,
|
|
241
|
+
code: "exhausted",
|
|
242
|
+
});
|
|
243
|
+
return this.reject("exhausted", snapshotOf(target), ratio, target.frozenReason);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Freeze one ledger. Finance owns this right; the reason is mandatory so a
|
|
247
|
+
* later audit can tell a policy freeze from an incident freeze.
|
|
248
|
+
*/
|
|
249
|
+
freeze(scope, id, reason, by = "finance") {
|
|
250
|
+
if (!canApprove(by, "budget.freeze")) {
|
|
251
|
+
throw new GovernanceError("approval-not-permitted", `${by} may not freeze a ledger`);
|
|
252
|
+
}
|
|
253
|
+
const target = this.lookup(scope, id);
|
|
254
|
+
target.frozen = true;
|
|
255
|
+
target.frozenReason = reason;
|
|
256
|
+
return snapshotOf(target);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Unfreeze requires a finance approval on record.
|
|
260
|
+
*/
|
|
261
|
+
unfreeze(scope, id, approval) {
|
|
262
|
+
if (approval.granted !== true || !canApprove(approval.by, "budget.freeze")) {
|
|
263
|
+
throw new GovernanceError("approval-not-permitted", "unfreeze requires a granted finance approval");
|
|
264
|
+
}
|
|
265
|
+
const target = this.lookup(scope, id);
|
|
266
|
+
target.frozen = false;
|
|
267
|
+
delete target.frozenReason;
|
|
268
|
+
return snapshotOf(target);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Draw from the escalation reserve. Every draw needs a finance approval; a
|
|
272
|
+
* draw above half the reserve also needs a board `budget.major-top-up`
|
|
273
|
+
* approval (spec section 8). The board approval is never inferred from the
|
|
274
|
+
* finance one.
|
|
275
|
+
*/
|
|
276
|
+
drawReserve(amount, approval, reason, boardApproval) {
|
|
277
|
+
validateBudget(amount, "reserve draw");
|
|
278
|
+
if (approval.granted !== true || approval.subject !== "budget.reserve" || !canApprove(approval.by, "budget.reserve")) {
|
|
279
|
+
throw new GovernanceError("approval-required", "reserve draws require a granted finance budget.reserve approval");
|
|
280
|
+
}
|
|
281
|
+
const ratio = projectedRatio(this.reserve.used, this.reserve.cap, amount);
|
|
282
|
+
if (ratio > 0.5) {
|
|
283
|
+
const boardApproved = this.boardApproved(boardApproval);
|
|
284
|
+
if (!boardApproved) {
|
|
285
|
+
throw new GovernanceError("approval-required", "a reserve draw above 50% also needs a board budget.major-top-up approval");
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return this.charge({
|
|
289
|
+
scope: "reserve",
|
|
290
|
+
amount,
|
|
291
|
+
reason,
|
|
292
|
+
escalation: true,
|
|
293
|
+
approval,
|
|
294
|
+
requestedBy: "general-manager",
|
|
295
|
+
...(boardApproval === (void 0) ? {} : { boardApproval }),
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
snapshot(scope, id) {
|
|
299
|
+
const ledgerId = id ?? (scope === "global" || scope === "reserve" ? scope : "");
|
|
300
|
+
return snapshotOf(this.lookup(scope, ledgerId));
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Remaining allocation on one ledger (cap minus used, per dimension).
|
|
304
|
+
*/
|
|
305
|
+
remaining(scope, id) {
|
|
306
|
+
const target = this.lookup(scope, id ?? (scope === "global" || scope === "reserve" ? scope : ""));
|
|
307
|
+
const result = budgetTotals({});
|
|
308
|
+
for (let index = 0; index < BudgetDimensions.length; index += 1) {
|
|
309
|
+
const dimension = BudgetDimensions[index];
|
|
310
|
+
result[dimension] = Math.max(0, target.cap[dimension] - target.used[dimension]);
|
|
311
|
+
}
|
|
312
|
+
return result;
|
|
313
|
+
}
|
|
314
|
+
snapshots() {
|
|
315
|
+
return [snapshotOf(this.global), snapshotOf(this.reserve), ...this.perspectives.values(), ...this.agents.values()].map(snapshotOf);
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* End-of-task settlement: every ledger, every transfer, every post-audit
|
|
319
|
+
* entry and the freeze list, so the archive phase can attach one object.
|
|
320
|
+
*/
|
|
321
|
+
settle() {
|
|
322
|
+
const perspectives = [...this.perspectives.values()].map(snapshotOf);
|
|
323
|
+
const agents = [...this.agents.values()].map(snapshotOf);
|
|
324
|
+
const frozen = [snapshotOf(this.global), snapshotOf(this.reserve), ...perspectives, ...agents].filter((entry) => entry.frozen);
|
|
325
|
+
return {
|
|
326
|
+
global: snapshotOf(this.global),
|
|
327
|
+
reserve: snapshotOf(this.reserve),
|
|
328
|
+
perspectives,
|
|
329
|
+
agents,
|
|
330
|
+
transfers: this.transfers.map((record) => ({ ...record, amount: { ...record.amount } })),
|
|
331
|
+
charges: this.records.length,
|
|
332
|
+
postAudit: [...this.audits],
|
|
333
|
+
frozen,
|
|
334
|
+
balanced: this.records.every((record) => record.code !== "exhausted"),
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
history() {
|
|
338
|
+
return this.records.map((record) => ({ ...record, amount: { ...record.amount } }));
|
|
339
|
+
}
|
|
340
|
+
transferHistory() {
|
|
341
|
+
return this.transfers.map((record) => ({ ...record, amount: { ...record.amount } }));
|
|
342
|
+
}
|
|
343
|
+
state(scope, id, config) {
|
|
344
|
+
validateBudget(config.cap, `ledger ${id}`);
|
|
345
|
+
return {
|
|
346
|
+
scope,
|
|
347
|
+
id,
|
|
348
|
+
cap: budgetTotals(config.cap),
|
|
349
|
+
used: budgetTotals({}),
|
|
350
|
+
elasticity: config.elasticity,
|
|
351
|
+
frozen: false,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
resolvedId(request) {
|
|
355
|
+
if (request.scope === "perspective") {
|
|
356
|
+
if (request.perspective === (void 0)) {
|
|
357
|
+
throw new GovernanceError("budget-exhausted", "a perspective charge needs a perspective id");
|
|
358
|
+
}
|
|
359
|
+
return request.perspective;
|
|
360
|
+
}
|
|
361
|
+
if (request.scope === "agent") {
|
|
362
|
+
if (request.agent === (void 0)) {
|
|
363
|
+
throw new GovernanceError("budget-exhausted", "an agent charge needs an agent id");
|
|
364
|
+
}
|
|
365
|
+
return request.agent;
|
|
366
|
+
}
|
|
367
|
+
return request.scope;
|
|
368
|
+
}
|
|
369
|
+
resolve(request) {
|
|
370
|
+
return this.lookup(request.scope, this.resolvedId(request));
|
|
371
|
+
}
|
|
372
|
+
lookup(scope, id) {
|
|
373
|
+
if (scope === "global") {
|
|
374
|
+
return this.global;
|
|
375
|
+
}
|
|
376
|
+
if (scope === "reserve") {
|
|
377
|
+
return this.reserve;
|
|
378
|
+
}
|
|
379
|
+
if (scope === "agent") {
|
|
380
|
+
const agentLedger = this.agents.get(id);
|
|
381
|
+
if (agentLedger === (void 0)) {
|
|
382
|
+
throw new GovernanceError("budget-exhausted", `no ledger for agent ${id}`);
|
|
383
|
+
}
|
|
384
|
+
return agentLedger;
|
|
385
|
+
}
|
|
386
|
+
const found = this.perspectives.get(id);
|
|
387
|
+
if (found === (void 0)) {
|
|
388
|
+
throw new GovernanceError("budget-exhausted", `no ledger for perspective ${id}`);
|
|
389
|
+
}
|
|
390
|
+
return found;
|
|
391
|
+
}
|
|
392
|
+
approved(request, subject) {
|
|
393
|
+
const approval = request.approval;
|
|
394
|
+
if (approval === (void 0) || approval.granted !== true || approval.subject !== subject) {
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
if (!canApprove(approval.by, subject)) {
|
|
398
|
+
return false;
|
|
399
|
+
}
|
|
400
|
+
return request.requestedBy !== (void 0) && request.requestedBy !== approval.by;
|
|
401
|
+
}
|
|
402
|
+
boardApproved(approval) {
|
|
403
|
+
return approval !== (void 0) && approval.granted === true && approval.subject === "budget.major-top-up" && canApprove(approval.by, "budget.major-top-up");
|
|
404
|
+
}
|
|
405
|
+
commit(target, request, code, ratio) {
|
|
406
|
+
target.used = sumBudget(target.used, request.amount);
|
|
407
|
+
this.records.push({
|
|
408
|
+
at: this.now(),
|
|
409
|
+
scope: target.scope,
|
|
410
|
+
ledgerId: target.id,
|
|
411
|
+
amount: budgetTotals(request.amount),
|
|
412
|
+
reason: request.reason,
|
|
413
|
+
code,
|
|
414
|
+
...(request.requestedBy === (void 0) ? {} : { requestedBy: request.requestedBy }),
|
|
415
|
+
...(request.approval === (void 0) ? {} : { approvalId: request.approval.id }),
|
|
416
|
+
});
|
|
417
|
+
if (ratio > 1) {
|
|
418
|
+
this.audits.push({ at: this.now(), scope: target.scope, ledgerId: target.id, amount: budgetTotals(request.amount), reason: request.reason });
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
reject(code, ledger, ratio, detail) {
|
|
422
|
+
return { ok: false, code, ledger, ratio, detail };
|
|
423
|
+
}
|
|
424
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The three-layer context (spec section 3).
|
|
3
|
+
*
|
|
4
|
+
* - global core: goal, signed capability statement, hard constraints,
|
|
5
|
+
* priorities, budget, task state, versioned board strategy, scenario and
|
|
6
|
+
* mode labels. Every perspective reads it; only the board or a human
|
|
7
|
+
* writes it.
|
|
8
|
+
* - perspective-private context: the manifest, local reasoning, tool results
|
|
9
|
+
* and private budget. Only that perspective may read it, and switching
|
|
10
|
+
* seals it.
|
|
11
|
+
* - shared receipt blackboard: conclusions, evidence refs, confidence,
|
|
12
|
+
* budget spent, manifest version, scenario/mode labels, open questions and
|
|
13
|
+
* escalation requests. Each perspective writes only its own receipts.
|
|
14
|
+
*
|
|
15
|
+
* The default inheritance is the board strategy summary, not the whole board
|
|
16
|
+
* context; `expandGlobal` opens the full record on demand.
|
|
17
|
+
*/
|
|
18
|
+
import type { Budget, Digest, Id, Ref, Timestamp } from "../types/common.js";
|
|
19
|
+
import type { ApprovalGrant, EscalationRef, ManifestRef, ModeWeights, PerspectiveId, ScenarioId } from "./types.js";
|
|
20
|
+
export interface StrategyView {
|
|
21
|
+
version: number;
|
|
22
|
+
digest: Digest;
|
|
23
|
+
/**
|
|
24
|
+
* What a perspective inherits by default.
|
|
25
|
+
*/
|
|
26
|
+
summary: string;
|
|
27
|
+
/**
|
|
28
|
+
* The full board record, expanded only on demand.
|
|
29
|
+
*/
|
|
30
|
+
detail: string;
|
|
31
|
+
}
|
|
32
|
+
export interface GlobalCore {
|
|
33
|
+
goal: string;
|
|
34
|
+
strategy: StrategyView;
|
|
35
|
+
constraints: string[];
|
|
36
|
+
priorities: string[];
|
|
37
|
+
taskState: string;
|
|
38
|
+
scenario: ScenarioId;
|
|
39
|
+
modes: ModeWeights;
|
|
40
|
+
budget: Budget;
|
|
41
|
+
version: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The read-only projection a perspective receives by default.
|
|
45
|
+
*/
|
|
46
|
+
export interface GlobalCoreView {
|
|
47
|
+
goal: string;
|
|
48
|
+
strategyVersion: number;
|
|
49
|
+
strategyDigest: Digest;
|
|
50
|
+
strategySummary: string;
|
|
51
|
+
constraints: string[];
|
|
52
|
+
priorities: string[];
|
|
53
|
+
taskState: string;
|
|
54
|
+
scenario: ScenarioId;
|
|
55
|
+
modes: ModeWeights;
|
|
56
|
+
budget: Budget;
|
|
57
|
+
version: number;
|
|
58
|
+
}
|
|
59
|
+
export interface PrivateNote {
|
|
60
|
+
at: Timestamp;
|
|
61
|
+
kind: "reasoning" | "tool-result" | "observation";
|
|
62
|
+
text: string;
|
|
63
|
+
refs?: Ref[];
|
|
64
|
+
}
|
|
65
|
+
export interface PrivateContext {
|
|
66
|
+
perspective: PerspectiveId;
|
|
67
|
+
manifest: ManifestRef;
|
|
68
|
+
notes: PrivateNote[];
|
|
69
|
+
openedAt: Timestamp;
|
|
70
|
+
sealed: boolean;
|
|
71
|
+
}
|
|
72
|
+
export interface BoardReceiptInput {
|
|
73
|
+
conclusion: string;
|
|
74
|
+
evidence: Ref[];
|
|
75
|
+
confidence: number;
|
|
76
|
+
budget: Budget;
|
|
77
|
+
manifest: ManifestRef;
|
|
78
|
+
scenario: ScenarioId;
|
|
79
|
+
modes: ModeWeights;
|
|
80
|
+
openQuestions?: string[];
|
|
81
|
+
escalation?: EscalationRef;
|
|
82
|
+
audience?: PerspectiveId[];
|
|
83
|
+
}
|
|
84
|
+
export interface BoardReceipt extends BoardReceiptInput {
|
|
85
|
+
id: Id;
|
|
86
|
+
from: PerspectiveId;
|
|
87
|
+
at: Timestamp;
|
|
88
|
+
digest: Digest;
|
|
89
|
+
openQuestions: string[];
|
|
90
|
+
}
|
|
91
|
+
export interface ContextLayersOptions {
|
|
92
|
+
core: GlobalCore;
|
|
93
|
+
now: () => Timestamp;
|
|
94
|
+
}
|
|
95
|
+
export interface ContextSnapshot {
|
|
96
|
+
core: GlobalCore;
|
|
97
|
+
privateContexts: Array<{
|
|
98
|
+
perspective: PerspectiveId;
|
|
99
|
+
notes: number;
|
|
100
|
+
sealed: boolean;
|
|
101
|
+
}>;
|
|
102
|
+
receipts: BoardReceipt[];
|
|
103
|
+
version: number;
|
|
104
|
+
}
|
|
105
|
+
export declare class ContextLayers {
|
|
106
|
+
private core;
|
|
107
|
+
private readonly now;
|
|
108
|
+
private readonly privateContexts;
|
|
109
|
+
private readonly receipts;
|
|
110
|
+
private active;
|
|
111
|
+
private counter;
|
|
112
|
+
constructor(options: ContextLayersOptions);
|
|
113
|
+
/**
|
|
114
|
+
* The default view: summary only, no full board record.
|
|
115
|
+
*/
|
|
116
|
+
global(viewer: PerspectiveId): GlobalCoreView;
|
|
117
|
+
/**
|
|
118
|
+
* Expand the full board record on demand. The access is not hidden: the
|
|
119
|
+
* caller records it in its own receipt.
|
|
120
|
+
*/
|
|
121
|
+
expandGlobal(viewer: PerspectiveId): GlobalCore;
|
|
122
|
+
/**
|
|
123
|
+
* Only the board or a human may write the global core. The change bumps
|
|
124
|
+
* the version so every perspective can detect that its assumption is stale.
|
|
125
|
+
*/
|
|
126
|
+
writeGlobal(by: PerspectiveId | "human", patch: Partial<GlobalCore>, approval?: ApprovalGrant): GlobalCore;
|
|
127
|
+
/**
|
|
128
|
+
* Open a perspective's private context and seal the previously active one.
|
|
129
|
+
* The caller cannot keep reading the old view through this object.
|
|
130
|
+
*/
|
|
131
|
+
openPerspective(id: PerspectiveId, manifest: ManifestRef): PrivateContext;
|
|
132
|
+
seal(id?: PerspectiveId): void;
|
|
133
|
+
/**
|
|
134
|
+
* Append a private note. Only the owner of an open context may write it.
|
|
135
|
+
*/
|
|
136
|
+
writePrivate(id: PerspectiveId, note: PrivateNote): PrivateContext;
|
|
137
|
+
/**
|
|
138
|
+
* Read a private context. Only the owner may read it, sealed or not.
|
|
139
|
+
*/
|
|
140
|
+
readPrivate(id: PerspectiveId, viewer: PerspectiveId): PrivateContext | undefined;
|
|
141
|
+
/**
|
|
142
|
+
* Write one receipt to the shared blackboard. The writer must be the active
|
|
143
|
+
* perspective and the receipt must match its manifest version.
|
|
144
|
+
*/
|
|
145
|
+
writeReceipt(from: PerspectiveId, input: BoardReceiptInput): BoardReceipt;
|
|
146
|
+
/**
|
|
147
|
+
* The blackboard is not public: the management and audit perspectives see
|
|
148
|
+
* everything, execution perspectives see their own receipts and receipts
|
|
149
|
+
* addressed to them.
|
|
150
|
+
*/
|
|
151
|
+
readReceipts(viewer: PerspectiveId): BoardReceipt[];
|
|
152
|
+
readReceipt(id: Id, viewer: PerspectiveId): BoardReceipt | undefined;
|
|
153
|
+
/**
|
|
154
|
+
* Receipts that requested escalation, used by the workflow's escalation
|
|
155
|
+
* phase.
|
|
156
|
+
*/
|
|
157
|
+
escalations(): BoardReceipt[];
|
|
158
|
+
snapshot(): ContextSnapshot;
|
|
159
|
+
}
|