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,245 @@
|
|
|
1
|
+
const clamp01 = (value) => (value < 0 ? 0 : value > 1 ? 1 : value);
|
|
2
|
+
/**
|
|
3
|
+
* Rounds to three decimals, so receipts and snapshots stay byte-stable.
|
|
4
|
+
*/
|
|
5
|
+
const round3 = (value) => Math.round(value * 1000) / 1000;
|
|
6
|
+
/**
|
|
7
|
+
* Named law parameters. Every entry states whether the value is measured on
|
|
8
|
+
* humans or a convention of this implementation, because a protocol may cite a
|
|
9
|
+
* direction it cannot cite a magnitude for.
|
|
10
|
+
*/
|
|
11
|
+
export const CognitiveLaws = {
|
|
12
|
+
/**
|
|
13
|
+
* Prospect theory's loss-asymmetry median estimate (Kahneman & Tversky 1992).
|
|
14
|
+
*/
|
|
15
|
+
lossAsymmetry: { value: 2.25, status: "measured", source: "λ ≈ 2.25, median across studies" },
|
|
16
|
+
/**
|
|
17
|
+
* Vigilance half-life in *cycles*, not minutes: a convention pending measurement.
|
|
18
|
+
*/
|
|
19
|
+
vigilanceTau: { value: 12, status: "convention", source: "calibrate per model from receipts" },
|
|
20
|
+
/**
|
|
21
|
+
* Inhibition-of-return kernel: distinct from novelty decay.
|
|
22
|
+
*/
|
|
23
|
+
iorTau: { value: 3, status: "convention", source: "seconds-scale effect mapped onto cycles" },
|
|
24
|
+
/**
|
|
25
|
+
* Base chunk capacity before load is applied (Cowan 2001: ~4 unrehearsed).
|
|
26
|
+
*/
|
|
27
|
+
baseCapacity: { value: 4, status: "measured", source: "Cowan 2001, BBS 24(1):87–114" },
|
|
28
|
+
/**
|
|
29
|
+
* Load may consume at most half of capacity.
|
|
30
|
+
*/
|
|
31
|
+
loadPenalty: { value: 0.5, status: "convention", source: "monotone, bounded" },
|
|
32
|
+
/**
|
|
33
|
+
* Below this load, spare capacity must not be filled with novelty (Lavie).
|
|
34
|
+
*/
|
|
35
|
+
noveltyLoadFloor: { value: 0.3, status: "convention", source: "Lavie 2005, TiCS 9(2):75–82" },
|
|
36
|
+
/**
|
|
37
|
+
* Arousal narrows breadth by raising the goal-fit exponent (Easterbrook 1959).
|
|
38
|
+
*/
|
|
39
|
+
arousalNarrowing: { value: 0.5, status: "convention", source: "Easterbrook 1959, Psych Review 66:183–201" },
|
|
40
|
+
/**
|
|
41
|
+
* Screening overhead charged per candidate scored.
|
|
42
|
+
*/
|
|
43
|
+
metaCharge: { value: 0.1, status: "convention", source: "Russell & Wefald 1991" },
|
|
44
|
+
/**
|
|
45
|
+
* How strongly a class's realised value moves its future priority.
|
|
46
|
+
*/
|
|
47
|
+
valueLearning: { value: 2, status: "convention", source: "Anderson, Laurent & Yantis 2011, PNAS 108(25); calibrate per host" },
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Estimate the state from the ledger.
|
|
51
|
+
*
|
|
52
|
+
* Two timescales of the same signal are kept apart on purpose: `arousal` is
|
|
53
|
+
* *recent* error pressure (fast, phasic) while `mastery` is the long-run success
|
|
54
|
+
* rate (slow, trait-like). Collapsing them into one number loses the fact that a
|
|
55
|
+
* competent agent can be briefly alarmed, and an incompetent one can be calm.
|
|
56
|
+
*/
|
|
57
|
+
export const estimateCognitiveState = (input) => {
|
|
58
|
+
const frames = input.frames;
|
|
59
|
+
const last = frames.length > 0 ? frames[frames.length - 1] : undefined;
|
|
60
|
+
const baseCapacity = input.baseCapacity ?? CognitiveLaws.baseCapacity.value;
|
|
61
|
+
const tau = input.tauVigilance ?? CognitiveLaws.vigilanceTau.value;
|
|
62
|
+
const window = input.window ?? 12;
|
|
63
|
+
let cyclesSinceRest = frames.length;
|
|
64
|
+
for (let index = frames.length - 1; index >= 0; index -= 1) {
|
|
65
|
+
if (frames[index].mode === "rest") {
|
|
66
|
+
cyclesSinceRest = frames.length - 1 - index;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const active = last ? last.slots.filter((slot) => slot.state === "active") : [];
|
|
71
|
+
const chunks = active.reduce((sum, slot) => sum + (typeof (slot.chunk_weight) === "number" ? slot.chunk_weight : 1), 0);
|
|
72
|
+
const deferred = (last?.ignored ?? []).filter((item) => item.reason === "deferred" || item.reason === "budget");
|
|
73
|
+
const rootCapacity = Math.max(1, baseCapacity);
|
|
74
|
+
const load = clamp01(0.6 * Math.min(1, chunks / rootCapacity) + 0.4 * Math.min(1, deferred.length / 8));
|
|
75
|
+
const recent = input.receipts.slice(Math.max(0, input.receipts.length - window));
|
|
76
|
+
const scored = recent.filter((receipt) => receipt.outcome !== (void 0));
|
|
77
|
+
const failures = scored.filter((receipt) => receipt.outcome === "blocked" || receipt.outcome === "failure").length;
|
|
78
|
+
const partials = scored.filter((receipt) => receipt.outcome === "partial").length;
|
|
79
|
+
const failureRate = scored.length > 0 ? failures / scored.length : 0;
|
|
80
|
+
const partialRate = scored.length > 0 ? partials / scored.length : 0;
|
|
81
|
+
const arousal = clamp01(0.75 * failureRate + 0.25 * partialRate);
|
|
82
|
+
const allScored = input.receipts.filter((receipt) => receipt.outcome !== (void 0));
|
|
83
|
+
const wins = allScored.filter((receipt) => receipt.outcome === "success").length;
|
|
84
|
+
const mastery = allScored.length > 0 ? clamp01(wins / allScored.length) : 0.5;
|
|
85
|
+
const vigilance = clamp01(Math.exp(-cyclesSinceRest / Math.max(1, tau)));
|
|
86
|
+
const capacityEff = Math.min(9, Math.max(1, Math.round(rootCapacity * (1 - CognitiveLaws.loadPenalty.value * load))));
|
|
87
|
+
const dominantRole = dominantRoleOf(active);
|
|
88
|
+
return {
|
|
89
|
+
load: round3(load),
|
|
90
|
+
vigilance: round3(vigilance),
|
|
91
|
+
arousal: round3(arousal),
|
|
92
|
+
mastery: round3(mastery),
|
|
93
|
+
accountability: clamp01(input.accountability ?? 0),
|
|
94
|
+
cyclesSinceRest,
|
|
95
|
+
capacityEff,
|
|
96
|
+
pLapse: round3(1 - vigilance),
|
|
97
|
+
dominantRole,
|
|
98
|
+
source: allScored.length >= 30 ? "measured" : "default",
|
|
99
|
+
samples: allScored.length,
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* The role with the most chunk weight in a focus set; ties resolve to the first seen.
|
|
104
|
+
*/
|
|
105
|
+
const dominantRoleOf = (slots) => {
|
|
106
|
+
const weight = new Map();
|
|
107
|
+
for (let index = 0; index < slots.length; index += 1) {
|
|
108
|
+
const slot = slots[index];
|
|
109
|
+
const chunks = typeof (slot.chunk_weight) === "number" ? slot.chunk_weight : 1;
|
|
110
|
+
weight.set(slot.role, (weight.get(slot.role) ?? 0) + chunks);
|
|
111
|
+
}
|
|
112
|
+
let best = undefined;
|
|
113
|
+
let bestWeight = -1;
|
|
114
|
+
const entries = [...weight];
|
|
115
|
+
for (let index = 0; index < entries.length; index += 1) {
|
|
116
|
+
const [role, total] = entries[index];
|
|
117
|
+
if (total > bestWeight) {
|
|
118
|
+
best = role;
|
|
119
|
+
bestWeight = total;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return best;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* The history multiplier: value learning minus inhibition of return.
|
|
126
|
+
*
|
|
127
|
+
* These are two mechanisms with opposite signs, not one "novelty" knob. A
|
|
128
|
+
* candidate that paid off is worth re-selecting; a candidate just rejected is
|
|
129
|
+
* worth *not* re-selecting, and both facts must survive into the next cycle.
|
|
130
|
+
*/
|
|
131
|
+
export const historyFactor = (history) => {
|
|
132
|
+
if (!history) {
|
|
133
|
+
return 1;
|
|
134
|
+
}
|
|
135
|
+
const realized = typeof (history.realized) === "number" ? history.realized : 0.5;
|
|
136
|
+
const learned = 1 + CognitiveLaws.valueLearning.value * (realized - 0.5);
|
|
137
|
+
const age = typeof (history.lastIgnoredAge) === "number" ? history.lastIgnoredAge : Number.POSITIVE_INFINITY;
|
|
138
|
+
const ior = age === Number.POSITIVE_INFINITY ? 0 : 0.5 * Math.exp(-age / CognitiveLaws.iorTau.value);
|
|
139
|
+
return Math.max(0.1, learned - ior);
|
|
140
|
+
};
|
|
141
|
+
export const salienceFromState = (candidate, state) => {
|
|
142
|
+
const gamma = 1 + CognitiveLaws.arousalNarrowing.value * state.arousal;
|
|
143
|
+
const openness = state.load >= CognitiveLaws.noveltyLoadFloor.value ? 1 : 0;
|
|
144
|
+
const value = candidate.voi * Math.pow(clamp01(candidate.goalFit), gamma) * (1 + 0.5 * clamp01(candidate.novelty) * openness) * historyFactor(candidate.history);
|
|
145
|
+
const switchTokens = candidate.switchCostTokens ?? 0;
|
|
146
|
+
const loadOnSwitch = 1 + state.load;
|
|
147
|
+
const cost = 1 +
|
|
148
|
+
2 * clamp01(candidate.costTokens / 2000) +
|
|
149
|
+
3 * clamp01(candidate.risk) +
|
|
150
|
+
0.5 * clamp01(switchTokens / 2000) * loadOnSwitch +
|
|
151
|
+
CognitiveLaws.metaCharge.value;
|
|
152
|
+
const capped = Math.min(clamp01(value / cost), clamp01(candidate.trustCap));
|
|
153
|
+
const floor = typeof (candidate.hardFloor) === "number" ? clamp01(candidate.hardFloor) : 0;
|
|
154
|
+
return round3(Math.max(capped, floor));
|
|
155
|
+
};
|
|
156
|
+
export const selectFromState = (candidates, state, options) => {
|
|
157
|
+
const threshold = options.threshold ?? 0.12;
|
|
158
|
+
const capacity = Math.max(1, options.capacity ?? state.capacityEff);
|
|
159
|
+
const switchCost = options.switchCostTokens ?? 0;
|
|
160
|
+
const scored = candidates
|
|
161
|
+
.map((candidate) => ({ candidate, score: salienceFromState(candidate, state) }))
|
|
162
|
+
.sort((left, right) => right.score - left.score);
|
|
163
|
+
const ignored = [];
|
|
164
|
+
const slots = [];
|
|
165
|
+
let usedChunks = 0;
|
|
166
|
+
let remaining = options.budgetTokens;
|
|
167
|
+
let floorConflict = false;
|
|
168
|
+
for (let index = 0; index < scored.length; index += 1) {
|
|
169
|
+
const entry = scored[index];
|
|
170
|
+
const chunks = Math.max(1, typeof (entry.candidate.chunkWeight) === "number" ? Math.floor(entry.candidate.chunkWeight) : 1);
|
|
171
|
+
const reserved = (entry.candidate.hardFloor ?? 0) > 0;
|
|
172
|
+
if (usedChunks + chunks > capacity) {
|
|
173
|
+
if (reserved) {
|
|
174
|
+
floorConflict = true;
|
|
175
|
+
}
|
|
176
|
+
ignored.push({ target: entry.candidate.target, reason: "capacity", revisit_if: "焦点释放后" });
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
const cost = entry.candidate.costTokens;
|
|
180
|
+
const withSwitch = cost + (entry.candidate.role === state.dominantRole ? 0 : switchCost);
|
|
181
|
+
if (withSwitch > remaining) {
|
|
182
|
+
ignored.push({ target: entry.candidate.target, reason: "budget", revisit_if: "预算恢复后" });
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
if (!reserved && entry.score < threshold) {
|
|
186
|
+
ignored.push({
|
|
187
|
+
target: entry.candidate.target,
|
|
188
|
+
reason: reasonForIgnore(entry.candidate, state),
|
|
189
|
+
revisit_if: entry.candidate.target.kind === "unknown" ? "VOI 上升或目标改变" : "重新评估后",
|
|
190
|
+
});
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
remaining -= withSwitch;
|
|
194
|
+
usedChunks += chunks;
|
|
195
|
+
slots.push({
|
|
196
|
+
target: entry.candidate.target,
|
|
197
|
+
role: entry.candidate.role,
|
|
198
|
+
tier: entry.candidate.tier,
|
|
199
|
+
salience: entry.score,
|
|
200
|
+
voi: entry.candidate.voi,
|
|
201
|
+
cost: { tokens: cost },
|
|
202
|
+
budget: { tokens: withSwitch },
|
|
203
|
+
why: entry.candidate.why,
|
|
204
|
+
state: "active",
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
let impasse = undefined;
|
|
208
|
+
if (floorConflict) {
|
|
209
|
+
impasse = "INFEASIBLE";
|
|
210
|
+
}
|
|
211
|
+
else if (slots.length === 0) {
|
|
212
|
+
impasse = "STUCK";
|
|
213
|
+
}
|
|
214
|
+
else if (slots.length > 1 && Math.abs(slots[0].salience - slots[1].salience) < 0.02) {
|
|
215
|
+
impasse = "TIE";
|
|
216
|
+
}
|
|
217
|
+
return { slots, ignored, impasse, capacityUsed: usedChunks };
|
|
218
|
+
};
|
|
219
|
+
const reasonForIgnore = (candidate, state) => {
|
|
220
|
+
const age = candidate.history?.lastIgnoredAge;
|
|
221
|
+
if (typeof (age) === "number" && age <= CognitiveLaws.iorTau.value) {
|
|
222
|
+
return "inhibited";
|
|
223
|
+
}
|
|
224
|
+
if (state.pLapse > 0.5 && candidate.uncertainty > 0.5) {
|
|
225
|
+
return "low_sensitivity";
|
|
226
|
+
}
|
|
227
|
+
return "low_voi";
|
|
228
|
+
};
|
|
229
|
+
export const respectsCognitiveMonotonicity = (base, state) => {
|
|
230
|
+
const at = (over = {}, stateOver = {}) => salienceFromState({ ...base, ...over }, { ...state, ...stateOver });
|
|
231
|
+
const reference = at();
|
|
232
|
+
const checks = [
|
|
233
|
+
at({ voi: Math.min(1, base.voi + 0.1) }) >= reference,
|
|
234
|
+
at({ costTokens: base.costTokens + 200 }) <= reference,
|
|
235
|
+
at({ risk: Math.min(1, base.risk + 0.1) }) <= reference,
|
|
236
|
+
at({ trustCap: Math.min(base.trustCap, 0.2) }) <= reference,
|
|
237
|
+
at({ history: { ...base.history, realized: 1 } }) >= reference,
|
|
238
|
+
at({ history: { ...base.history, lastIgnoredAge: 0, lastSelectedAge: 0 } }) <= reference,
|
|
239
|
+
at({ hardFloor: 1 }) >= reference,
|
|
240
|
+
at({ switchCostTokens: 2000 }) <= reference,
|
|
241
|
+
at({}, { arousal: 1 }) <= reference,
|
|
242
|
+
at({}, { load: 0 }) <= reference,
|
|
243
|
+
];
|
|
244
|
+
return checks.every((ok) => ok);
|
|
245
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public attention entry: one state object, one shift action.
|
|
3
|
+
*
|
|
4
|
+
* The lower-level candidate scoring, interrupt broker and resource planner are
|
|
5
|
+
* implementation details during migration. They are not part of this surface.
|
|
6
|
+
*/
|
|
7
|
+
export { Attention, toShiftAction } from "./attention.js";
|
|
8
|
+
export type { AttentionForce, AttentionForceKind, AttentionItem, AttentionOptions, AttentionShift, AttentionShiftResult, AttentionSnapshot, AttentionSubject } from "./attention.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public attention entry: one state object, one shift action.
|
|
3
|
+
*
|
|
4
|
+
* The lower-level candidate scoring, interrupt broker and resource planner are
|
|
5
|
+
* implementation details during migration. They are not part of this surface.
|
|
6
|
+
*/
|
|
7
|
+
export { Attention, toShiftAction } from "./attention.js";
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { Budget, Id, Ref, Timestamp } from "../types/common.js";
|
|
2
|
+
import type { Receipt } from "../receipt/receipt.js";
|
|
3
|
+
import type { AttentionRequest, InterruptClass } from "./socialTypes.js";
|
|
4
|
+
import { AttentionBroker, type AttentionDecision, type AttentionPolicy } from "./social.js";
|
|
5
|
+
/**
|
|
6
|
+
* The Attention Ledger's missing object: an `Interrupt`.
|
|
7
|
+
*
|
|
8
|
+
* `AttentionBroker` makes a grant/defer/deny decision, but the decision is not
|
|
9
|
+
* itself an auditable ledger row and deferred requests never expire unless a
|
|
10
|
+
* caller manually resolves them. This wrapper turns each decision into an
|
|
11
|
+
* `Interrupt` record, emits the matching receipt, and sweeps deferred requests
|
|
12
|
+
* whose response window has elapsed.
|
|
13
|
+
*
|
|
14
|
+
* It deliberately does not replace `AttentionBroker`: policy, quiet hours,
|
|
15
|
+
* cooldowns and debt stay in one place.
|
|
16
|
+
*/
|
|
17
|
+
export type InterruptStatus = "granted" | "deferred" | "denied" | "answered" | "expired" | "withdrawn";
|
|
18
|
+
export interface InterruptRecord {
|
|
19
|
+
amp: "0.1";
|
|
20
|
+
kind: "interrupt";
|
|
21
|
+
id: Id;
|
|
22
|
+
request: Id;
|
|
23
|
+
class: InterruptClass;
|
|
24
|
+
target: Ref;
|
|
25
|
+
urgency: number;
|
|
26
|
+
granted: boolean;
|
|
27
|
+
status: InterruptStatus;
|
|
28
|
+
cost: Budget;
|
|
29
|
+
at: Timestamp;
|
|
30
|
+
expires?: Timestamp;
|
|
31
|
+
debt_weight: number;
|
|
32
|
+
reason: string;
|
|
33
|
+
receipt: Id;
|
|
34
|
+
}
|
|
35
|
+
export interface AttentionLedgerOptions {
|
|
36
|
+
now: () => Timestamp;
|
|
37
|
+
policy?: Partial<AttentionPolicy>;
|
|
38
|
+
/**
|
|
39
|
+
* Response window for a deferred request that carries no `expires`.
|
|
40
|
+
*/
|
|
41
|
+
defaultExpiryMs?: number;
|
|
42
|
+
onReceipt?: (receipt: Receipt) => void;
|
|
43
|
+
}
|
|
44
|
+
export declare const MaxExternalShare: number;
|
|
45
|
+
export interface AdmissionVerdict {
|
|
46
|
+
ok: boolean;
|
|
47
|
+
reason?: string;
|
|
48
|
+
}
|
|
49
|
+
type ExternalAdmissionInput = {
|
|
50
|
+
role: string;
|
|
51
|
+
share: number;
|
|
52
|
+
goalSlot?: boolean;
|
|
53
|
+
maxShare?: number;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* A-4: external content may be present, but it cannot buy its own salience and
|
|
57
|
+
* cannot occupy the goal slot. The numeric share is the proportion of the
|
|
58
|
+
* assembled context attributable to external content.
|
|
59
|
+
*/
|
|
60
|
+
export declare const admitExternal: (input: ExternalAdmissionInput) => AdmissionVerdict;
|
|
61
|
+
/**
|
|
62
|
+
* Interrupt-producing facade over `AttentionBroker`.
|
|
63
|
+
*
|
|
64
|
+
* Every submitted request produces exactly one `InterruptRecord` and one
|
|
65
|
+
* `Receipt` (op `ask`). Deferred records own debt until resolved or expired;
|
|
66
|
+
* `sweep()` closes the bookkeeping for elapsed windows.
|
|
67
|
+
*/
|
|
68
|
+
export declare class AttentionLedger {
|
|
69
|
+
readonly broker: AttentionBroker;
|
|
70
|
+
private readonly now;
|
|
71
|
+
private readonly defaultExpiryMs;
|
|
72
|
+
private readonly onReceipt?;
|
|
73
|
+
private readonly records;
|
|
74
|
+
private readonly byRequest;
|
|
75
|
+
private seq;
|
|
76
|
+
constructor(options: AttentionLedgerOptions);
|
|
77
|
+
submit(request: AttentionRequest): {
|
|
78
|
+
interrupt: InterruptRecord;
|
|
79
|
+
decision: AttentionDecision;
|
|
80
|
+
receipt: Receipt;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Resolve a deferred request. Returns the updated record or undefined.
|
|
84
|
+
*/
|
|
85
|
+
resolve(requestId: Id, outcome?: "answered" | "expired" | "withdrawn"): InterruptRecord | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* Expire deferred requests whose response window has elapsed.
|
|
88
|
+
* Idempotent: already-resolved/expired records are skipped.
|
|
89
|
+
*/
|
|
90
|
+
sweep(at?: Timestamp): InterruptRecord[];
|
|
91
|
+
all(): readonly InterruptRecord[];
|
|
92
|
+
get(requestId: Id): InterruptRecord | undefined;
|
|
93
|
+
open(): InterruptRecord[];
|
|
94
|
+
grantedCount(): number;
|
|
95
|
+
debtScore(at?: Timestamp): number;
|
|
96
|
+
}
|
|
97
|
+
export {};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { AttentionBroker } from "./social.js";
|
|
2
|
+
export const MaxExternalShare = 0.15;
|
|
3
|
+
/**
|
|
4
|
+
* A-4: external content may be present, but it cannot buy its own salience and
|
|
5
|
+
* cannot occupy the goal slot. The numeric share is the proportion of the
|
|
6
|
+
* assembled context attributable to external content.
|
|
7
|
+
*/
|
|
8
|
+
export const admitExternal = (input) => {
|
|
9
|
+
if (input.goalSlot) {
|
|
10
|
+
return { ok: false, reason: "external content cannot occupy the goal slot" };
|
|
11
|
+
}
|
|
12
|
+
if (!Number.isFinite(input.share) || input.share < 0 || input.share > 1) {
|
|
13
|
+
return { ok: false, reason: `invalid external share: ${`${input.share}`}` };
|
|
14
|
+
}
|
|
15
|
+
const limit = input.maxShare ?? MaxExternalShare;
|
|
16
|
+
if (!Number.isFinite(limit) || limit < 0 || limit > 1) {
|
|
17
|
+
throw new RangeError("maxShare must be in [0, 1]");
|
|
18
|
+
}
|
|
19
|
+
if (input.share > limit) {
|
|
20
|
+
return { ok: false, reason: `external share ${input.share} exceeds ${limit}` };
|
|
21
|
+
}
|
|
22
|
+
return { ok: true };
|
|
23
|
+
};
|
|
24
|
+
const addTimestamps = (at, ms) => new Date(Date.parse(at) + ms).toISOString();
|
|
25
|
+
/**
|
|
26
|
+
* Interrupt-producing facade over `AttentionBroker`.
|
|
27
|
+
*
|
|
28
|
+
* Every submitted request produces exactly one `InterruptRecord` and one
|
|
29
|
+
* `Receipt` (op `ask`). Deferred records own debt until resolved or expired;
|
|
30
|
+
* `sweep()` closes the bookkeeping for elapsed windows.
|
|
31
|
+
*/
|
|
32
|
+
export class AttentionLedger {
|
|
33
|
+
broker;
|
|
34
|
+
now;
|
|
35
|
+
defaultExpiryMs;
|
|
36
|
+
onReceipt;
|
|
37
|
+
records = [];
|
|
38
|
+
byRequest = new Map();
|
|
39
|
+
seq = 0;
|
|
40
|
+
constructor(options) {
|
|
41
|
+
this.now = options.now;
|
|
42
|
+
this.defaultExpiryMs = options.defaultExpiryMs ?? 60_000;
|
|
43
|
+
this.onReceipt = options.onReceipt;
|
|
44
|
+
this.broker = new AttentionBroker({ now: options.now, policy: options.policy });
|
|
45
|
+
}
|
|
46
|
+
submit(request) {
|
|
47
|
+
if (this.byRequest.has(request.id)) {
|
|
48
|
+
throw new Error(`duplicate interrupt request: ${request.id}`);
|
|
49
|
+
}
|
|
50
|
+
const decision = this.broker.submit(request);
|
|
51
|
+
const status = statusOf(decision);
|
|
52
|
+
this.seq += 1;
|
|
53
|
+
const id = `int.${this.seq}`;
|
|
54
|
+
const expires = status === "deferred" ? (request.expires ?? addTimestamps(decision.at, this.defaultExpiryMs)) : request.expires;
|
|
55
|
+
const interrupt = {
|
|
56
|
+
amp: "0.1",
|
|
57
|
+
kind: "interrupt",
|
|
58
|
+
id,
|
|
59
|
+
request: request.id,
|
|
60
|
+
class: request.class,
|
|
61
|
+
target: request.target,
|
|
62
|
+
urgency: request.urgency,
|
|
63
|
+
granted: status === "granted",
|
|
64
|
+
status,
|
|
65
|
+
cost: request.cost,
|
|
66
|
+
at: decision.at,
|
|
67
|
+
expires,
|
|
68
|
+
debt_weight: request.urgency,
|
|
69
|
+
reason: decision.reason,
|
|
70
|
+
receipt: `rc.ask.${this.seq}`,
|
|
71
|
+
};
|
|
72
|
+
const receipt = {
|
|
73
|
+
amp: "0.1",
|
|
74
|
+
kind: "receipt",
|
|
75
|
+
id: interrupt.receipt,
|
|
76
|
+
op: "ask",
|
|
77
|
+
target: request.target,
|
|
78
|
+
at: decision.at,
|
|
79
|
+
usage: { interrupts: status === "granted" ? 1 : 0, ...request.cost },
|
|
80
|
+
outcome: status === "denied" ? "blocked" : status === "deferred" ? "partial" : "success",
|
|
81
|
+
note: `${request.class}:${status}:${decision.reason}`,
|
|
82
|
+
};
|
|
83
|
+
this.records.push(interrupt);
|
|
84
|
+
this.byRequest.set(request.id, interrupt);
|
|
85
|
+
this.onReceipt?.(receipt);
|
|
86
|
+
return { interrupt, decision, receipt };
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Resolve a deferred request. Returns the updated record or undefined.
|
|
90
|
+
*/
|
|
91
|
+
resolve(requestId, outcome = "answered") {
|
|
92
|
+
const record = this.byRequest.get(requestId);
|
|
93
|
+
if (!record || record.status !== "deferred") {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
this.broker.resolve(requestId, outcome);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
/**
|
|
101
|
+
* The broker may already have closed the debt through a prior sweep.
|
|
102
|
+
*/
|
|
103
|
+
}
|
|
104
|
+
record.status = outcome;
|
|
105
|
+
return record;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Expire deferred requests whose response window has elapsed.
|
|
109
|
+
* Idempotent: already-resolved/expired records are skipped.
|
|
110
|
+
*/
|
|
111
|
+
sweep(at = this.now()) {
|
|
112
|
+
const now = Date.parse(at);
|
|
113
|
+
const expired = [];
|
|
114
|
+
for (let index = 0; index < this.records.length; index += 1) {
|
|
115
|
+
const record = this.records[index];
|
|
116
|
+
if (record.status !== "deferred" || record.expires === (void 0)) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (Date.parse(record.expires) > now) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
this.resolve(record.request, "expired");
|
|
123
|
+
expired.push(record);
|
|
124
|
+
}
|
|
125
|
+
return expired;
|
|
126
|
+
}
|
|
127
|
+
all() {
|
|
128
|
+
return this.records;
|
|
129
|
+
}
|
|
130
|
+
get(requestId) {
|
|
131
|
+
return this.byRequest.get(requestId);
|
|
132
|
+
}
|
|
133
|
+
open() {
|
|
134
|
+
return this.records.filter((record) => record.status === "deferred");
|
|
135
|
+
}
|
|
136
|
+
grantedCount() {
|
|
137
|
+
return this.records.filter((record) => record.status === "granted").length;
|
|
138
|
+
}
|
|
139
|
+
debtScore(at = this.now()) {
|
|
140
|
+
return this.broker.debtScore(at);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const statusOf = (decision) => {
|
|
144
|
+
if (decision.decision === "grant") {
|
|
145
|
+
return "granted";
|
|
146
|
+
}
|
|
147
|
+
if (decision.decision === "defer") {
|
|
148
|
+
return "deferred";
|
|
149
|
+
}
|
|
150
|
+
return "denied";
|
|
151
|
+
};
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attention as a bounded, multi-dimensional resource.
|
|
3
|
+
*
|
|
4
|
+
* This is the resource layer above `cognition.ts`:
|
|
5
|
+
* - `ProcessAttention` is the agent-level capacity, reserve and recovery debt.
|
|
6
|
+
* - `ThreadAttention` is the per-task allocation inside that capacity.
|
|
7
|
+
*
|
|
8
|
+
* CPU analogies are structural only: a CPU can run at 100% indefinitely, a
|
|
9
|
+
* person cannot. The policy therefore caps foreground utilization below 1,
|
|
10
|
+
* keeps a safety/reserve floor, and schedules rest when recovery debt is high.
|
|
11
|
+
*/
|
|
12
|
+
import type { Pid } from "../types/common.js";
|
|
13
|
+
import type { CognitiveState } from "./cognition.js";
|
|
14
|
+
export interface AttentionResourcePolicy {
|
|
15
|
+
/**
|
|
16
|
+
* Working-memory chunks assumed when no measured capacity exists.
|
|
17
|
+
*/
|
|
18
|
+
baseSlots: number;
|
|
19
|
+
/**
|
|
20
|
+
* Fraction kept away from foreground work (background, safety, recovery).
|
|
21
|
+
*/
|
|
22
|
+
reserveRatio: number;
|
|
23
|
+
/**
|
|
24
|
+
* Hard safety floor, in slots, reserved even under pressure.
|
|
25
|
+
*/
|
|
26
|
+
safetyFloorRatio: number;
|
|
27
|
+
/**
|
|
28
|
+
* Foreground utilization ceiling; must stay below 1.0.
|
|
29
|
+
*/
|
|
30
|
+
maxForegroundUtil: number;
|
|
31
|
+
/**
|
|
32
|
+
* Minimum allocation for an admitted task, in slots.
|
|
33
|
+
*/
|
|
34
|
+
minSliceSlots: number;
|
|
35
|
+
/**
|
|
36
|
+
* Rest after this many cycles without a rest frame.
|
|
37
|
+
*/
|
|
38
|
+
restAfterCycles: number;
|
|
39
|
+
/**
|
|
40
|
+
* Rest when vigilance falls to this level.
|
|
41
|
+
*/
|
|
42
|
+
vigilanceFloor: number;
|
|
43
|
+
/**
|
|
44
|
+
* Rest when load reaches this level.
|
|
45
|
+
*/
|
|
46
|
+
loadCeiling: number;
|
|
47
|
+
/**
|
|
48
|
+
* Rest when recovery debt reaches this level.
|
|
49
|
+
*/
|
|
50
|
+
recoveryDebtThreshold: number;
|
|
51
|
+
}
|
|
52
|
+
export declare const DefaultAttentionPolicy: AttentionResourcePolicy;
|
|
53
|
+
export interface ProcessAttention {
|
|
54
|
+
pid: Pid;
|
|
55
|
+
/**
|
|
56
|
+
* Effective working-memory slots after load penalty.
|
|
57
|
+
*/
|
|
58
|
+
effectiveSlots: number;
|
|
59
|
+
/**
|
|
60
|
+
* Foreground ceiling (`floor(effective * maxForegroundUtil)`).
|
|
61
|
+
*/
|
|
62
|
+
foregroundCap: number;
|
|
63
|
+
/**
|
|
64
|
+
* Slots kept out of foreground allocation.
|
|
65
|
+
*/
|
|
66
|
+
reserveSlots: number;
|
|
67
|
+
/**
|
|
68
|
+
* Hard safety floor inside the reserve.
|
|
69
|
+
*/
|
|
70
|
+
safetySlots: number;
|
|
71
|
+
state: CognitiveState;
|
|
72
|
+
/**
|
|
73
|
+
* [0, 1] accumulated need for rest.
|
|
74
|
+
*/
|
|
75
|
+
recoveryDebt: number;
|
|
76
|
+
/**
|
|
77
|
+
* True when the policy says no foreground work should run.
|
|
78
|
+
*/
|
|
79
|
+
offline: boolean;
|
|
80
|
+
}
|
|
81
|
+
export type ThreadDeferReason = "budget" | "offline" | "low-priority" | "floor";
|
|
82
|
+
export interface ThreadAttentionCandidate {
|
|
83
|
+
tid: number;
|
|
84
|
+
pid: Pid;
|
|
85
|
+
priority: number;
|
|
86
|
+
/**
|
|
87
|
+
* Desired slots; the planner clamps to capacity.
|
|
88
|
+
*/
|
|
89
|
+
preferredSlots: number;
|
|
90
|
+
/**
|
|
91
|
+
* Minimum slots if admitted; defaults to policy.minSliceSlots.
|
|
92
|
+
*/
|
|
93
|
+
minSlots?: number;
|
|
94
|
+
/**
|
|
95
|
+
* Background tasks use the reserve and never the foreground slot.
|
|
96
|
+
*/
|
|
97
|
+
foreground?: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Extra pressure from role/context switching.
|
|
100
|
+
*/
|
|
101
|
+
switchCost?: number;
|
|
102
|
+
role?: string;
|
|
103
|
+
}
|
|
104
|
+
export interface ThreadAttention {
|
|
105
|
+
tid: number;
|
|
106
|
+
pid: Pid;
|
|
107
|
+
slots: number;
|
|
108
|
+
foreground: boolean;
|
|
109
|
+
priority: number;
|
|
110
|
+
switchCost: number;
|
|
111
|
+
role?: string;
|
|
112
|
+
}
|
|
113
|
+
export interface DeferredAttention {
|
|
114
|
+
tid: number;
|
|
115
|
+
reason: ThreadDeferReason;
|
|
116
|
+
}
|
|
117
|
+
export interface AttentionPlan {
|
|
118
|
+
process: ProcessAttention;
|
|
119
|
+
foreground?: ThreadAttention;
|
|
120
|
+
background: ThreadAttention[];
|
|
121
|
+
deferred: DeferredAttention[];
|
|
122
|
+
/**
|
|
123
|
+
* Allocated slots / effective slots.
|
|
124
|
+
*/
|
|
125
|
+
utilization: number;
|
|
126
|
+
/**
|
|
127
|
+
* Deferred pressure plus switch cost, [0, 1+].
|
|
128
|
+
*/
|
|
129
|
+
pressure: number;
|
|
130
|
+
/**
|
|
131
|
+
* True when the policy wants a rest frame.
|
|
132
|
+
*/
|
|
133
|
+
rest: boolean;
|
|
134
|
+
}
|
|
135
|
+
export declare const recoveryDebtOf: (state: CognitiveState) => number;
|
|
136
|
+
export declare const shouldRest: (state: CognitiveState, policy?: AttentionResourcePolicy) => boolean;
|
|
137
|
+
export declare const processAttention: (pid: Pid, state: CognitiveState, policy?: AttentionResourcePolicy) => ProcessAttention;
|
|
138
|
+
/**
|
|
139
|
+
* Allocate one foreground task and, from the reserve, background tasks.
|
|
140
|
+
*
|
|
141
|
+
* Floors are intentionally asymmetric: safety is always reserved, every
|
|
142
|
+
* admitted task gets `minSlots`, but a deferred task gets no floor. Guaranteeing
|
|
143
|
+
* a floor to every candidate would make admission meaningless under pressure.
|
|
144
|
+
*/
|
|
145
|
+
export declare const planAttention: (process: ProcessAttention, candidates: readonly ThreadAttentionCandidate[], policy?: AttentionResourcePolicy) => AttentionPlan;
|
|
146
|
+
/**
|
|
147
|
+
* Rest restores vigilance, reduces load and clears the rest counter.
|
|
148
|
+
*/
|
|
149
|
+
export declare const applyRest: (state: CognitiveState, cycles?: number) => CognitiveState;
|
|
150
|
+
export interface OutcomeStats {
|
|
151
|
+
successes: number;
|
|
152
|
+
attempts: number;
|
|
153
|
+
errors: number;
|
|
154
|
+
rework: number;
|
|
155
|
+
attentionSlots: number;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Efficiency is useful outcomes per unit of attention, not raw utilization.
|
|
159
|
+
* Errors and rework are subtracted so a busy-but-wrong agent cannot win.
|
|
160
|
+
*/
|
|
161
|
+
export declare const qualityAdjustedThroughput: (stats: OutcomeStats) => number;
|
|
162
|
+
export declare const attentionHealth: (plan: AttentionPlan) => {
|
|
163
|
+
utilization: number;
|
|
164
|
+
pressure: number;
|
|
165
|
+
headroom: number;
|
|
166
|
+
rest: boolean;
|
|
167
|
+
};
|