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,153 @@
|
|
|
1
|
+
import type { Ignored, ImpasseState, Slot } from "../frame/frame.js";
|
|
2
|
+
import type { Ref } from "../types/common.js";
|
|
3
|
+
import type { ActionPlan } from "../runtime/action.js";
|
|
4
|
+
/**
|
|
5
|
+
* A scored candidate before it becomes a slot. Mirrors the §5.2 inputs.
|
|
6
|
+
*/
|
|
7
|
+
export interface Candidate {
|
|
8
|
+
target: Ref;
|
|
9
|
+
role: Slot["role"];
|
|
10
|
+
tier?: Slot["tier"];
|
|
11
|
+
voi: number;
|
|
12
|
+
goalFit: number;
|
|
13
|
+
uncertainty: number;
|
|
14
|
+
novelty: number;
|
|
15
|
+
costTokens: number;
|
|
16
|
+
risk: number;
|
|
17
|
+
/**
|
|
18
|
+
* Trust cap: external content cannot buy salience, only lose it (A-4).
|
|
19
|
+
*/
|
|
20
|
+
trustCap: number;
|
|
21
|
+
why: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The reference salience function (§5.2).
|
|
25
|
+
*
|
|
26
|
+
* Only its monotonicity is normative: voi up ⇒ not down; cost/risk up ⇒ not up;
|
|
27
|
+
* trust caps the result. The absolute numbers are a starting point, calibrated
|
|
28
|
+
* over time via predicted vs realized VOI.
|
|
29
|
+
*/
|
|
30
|
+
export declare const salience: (candidate: Candidate) => number;
|
|
31
|
+
export interface SelectionOptions {
|
|
32
|
+
budgetTokens: number;
|
|
33
|
+
cap?: number;
|
|
34
|
+
threshold?: number;
|
|
35
|
+
}
|
|
36
|
+
export interface Selection {
|
|
37
|
+
slots: Slot[];
|
|
38
|
+
ignored: Ignored[];
|
|
39
|
+
impasse?: ImpasseState;
|
|
40
|
+
}
|
|
41
|
+
type SelectFocusFn = (candidates: Candidate[], options: SelectionOptions) => Selection;
|
|
42
|
+
/**
|
|
43
|
+
* Select a focus set under budget, and record deliberate exclusions (A-2).
|
|
44
|
+
* The ignored list is the part classical architectures never kept.
|
|
45
|
+
*/
|
|
46
|
+
export declare const selectFocus: SelectFocusFn;
|
|
47
|
+
export type AttentionForceKind = "attraction" | "distraction";
|
|
48
|
+
type AttentionCapacity = {
|
|
49
|
+
slots: number;
|
|
50
|
+
tokens: number;
|
|
51
|
+
};
|
|
52
|
+
export interface AttentionForce {
|
|
53
|
+
kind: AttentionForceKind;
|
|
54
|
+
from: Ref;
|
|
55
|
+
target: Ref;
|
|
56
|
+
/**
|
|
57
|
+
* Required for distraction: what the target competes with.
|
|
58
|
+
*/
|
|
59
|
+
competesWith?: Ref;
|
|
60
|
+
strength: number;
|
|
61
|
+
decay?: number;
|
|
62
|
+
ttl?: number;
|
|
63
|
+
}
|
|
64
|
+
export interface AttentionItem {
|
|
65
|
+
target: Ref;
|
|
66
|
+
/**
|
|
67
|
+
* Stable left/right order. Weight never reorders the window.
|
|
68
|
+
*/
|
|
69
|
+
order: number;
|
|
70
|
+
weight: number;
|
|
71
|
+
pinned?: boolean;
|
|
72
|
+
source?: Ref;
|
|
73
|
+
enteredAt?: string;
|
|
74
|
+
ttl?: number;
|
|
75
|
+
}
|
|
76
|
+
export interface AttentionSubject {
|
|
77
|
+
pid: number;
|
|
78
|
+
tid?: number;
|
|
79
|
+
}
|
|
80
|
+
export interface AttentionShift {
|
|
81
|
+
actionId: string;
|
|
82
|
+
direction: "left" | "right";
|
|
83
|
+
steps?: number;
|
|
84
|
+
reason: string;
|
|
85
|
+
}
|
|
86
|
+
export interface AttentionSnapshot {
|
|
87
|
+
subject: AttentionSubject;
|
|
88
|
+
status: "open" | "closed";
|
|
89
|
+
cursor: number;
|
|
90
|
+
capacity: AttentionCapacity;
|
|
91
|
+
focus: AttentionItem[];
|
|
92
|
+
ignored: AttentionItem[];
|
|
93
|
+
forces: AttentionForce[];
|
|
94
|
+
}
|
|
95
|
+
export interface AttentionShiftResult {
|
|
96
|
+
actionId: string;
|
|
97
|
+
changed: boolean;
|
|
98
|
+
blocked: boolean;
|
|
99
|
+
reason: string;
|
|
100
|
+
snapshot: AttentionSnapshot;
|
|
101
|
+
}
|
|
102
|
+
export interface AttentionOptions {
|
|
103
|
+
subject: AttentionSubject;
|
|
104
|
+
capacity: AttentionCapacity;
|
|
105
|
+
items?: readonly AttentionItem[];
|
|
106
|
+
now?: () => string;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The single attention state.
|
|
110
|
+
*
|
|
111
|
+
* It owns only the ordered focus ring, capacity and force field. It never
|
|
112
|
+
* materializes context, never mutates Frame and never executes a shift: a shift
|
|
113
|
+
* is an Action that calls `shift()` and must be settled by a Receipt.
|
|
114
|
+
*/
|
|
115
|
+
export declare class Attention {
|
|
116
|
+
readonly subject: AttentionSubject;
|
|
117
|
+
readonly capacity: AttentionCapacity;
|
|
118
|
+
status: "open" | "closed";
|
|
119
|
+
cursor: number;
|
|
120
|
+
private readonly items;
|
|
121
|
+
private readonly forces;
|
|
122
|
+
private readonly now;
|
|
123
|
+
constructor(options: AttentionOptions);
|
|
124
|
+
/**
|
|
125
|
+
* Apply an attraction/distraction force; commit decides admission.
|
|
126
|
+
*/
|
|
127
|
+
observe(force: AttentionForce): void;
|
|
128
|
+
/**
|
|
129
|
+
* Stable left/right window. Pinned items stay visible.
|
|
130
|
+
*/
|
|
131
|
+
focus(): AttentionItem[];
|
|
132
|
+
snapshot(): AttentionSnapshot;
|
|
133
|
+
/**
|
|
134
|
+
* Apply one `attention.shift` action. The caller must still record an
|
|
135
|
+
* ActionRecord and a Receipt; this method only mutates cursor.
|
|
136
|
+
*/
|
|
137
|
+
shift(action: AttentionShift): AttentionShiftResult;
|
|
138
|
+
close(): void;
|
|
139
|
+
private nextOrder;
|
|
140
|
+
private assertOpen;
|
|
141
|
+
}
|
|
142
|
+
type ShiftActionInput = Omit<AttentionShift, "actionId"> & {
|
|
143
|
+
actionId?: string;
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Convert a shift into an existing runtime ActionPlan, not a new executor.
|
|
147
|
+
*/
|
|
148
|
+
export declare const toShiftAction: (shift: ShiftActionInput) => ActionPlan;
|
|
149
|
+
/**
|
|
150
|
+
* Test helper: the contract's monotonicity constraints (§5.2).
|
|
151
|
+
*/
|
|
152
|
+
export declare const respectsMonotonicity: (base: Candidate) => boolean;
|
|
153
|
+
export {};
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
const clamp01 = (n) => Math.max(0, Math.min(1, n));
|
|
2
|
+
/**
|
|
3
|
+
* The reference salience function (§5.2).
|
|
4
|
+
*
|
|
5
|
+
* Only its monotonicity is normative: voi up ⇒ not down; cost/risk up ⇒ not up;
|
|
6
|
+
* trust caps the result. The absolute numbers are a starting point, calibrated
|
|
7
|
+
* over time via predicted vs realized VOI.
|
|
8
|
+
*/
|
|
9
|
+
export const salience = (candidate) => {
|
|
10
|
+
const value = candidate.voi * candidate.goalFit * (0.5 + candidate.uncertainty) * (1 + 0.5 * candidate.novelty);
|
|
11
|
+
const cost = 1 + 2 * clamp01(candidate.costTokens / 2000) + 3 * clamp01(candidate.risk);
|
|
12
|
+
return Math.round(Math.min(clamp01(value / cost), clamp01(candidate.trustCap)) * 1000) / 1000;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Select a focus set under budget, and record deliberate exclusions (A-2).
|
|
16
|
+
* The ignored list is the part classical architectures never kept.
|
|
17
|
+
*/
|
|
18
|
+
export const selectFocus = (candidates, options) => {
|
|
19
|
+
const threshold = options.threshold ?? 0.12;
|
|
20
|
+
const cap = options.cap ?? 7;
|
|
21
|
+
const scored = candidates.map((c) => ({ candidate: c, score: salience(c) })).sort((a, b) => b.score - a.score);
|
|
22
|
+
const ignored = [];
|
|
23
|
+
const above = [];
|
|
24
|
+
for (let i = 0; i < scored.length; i += 1) {
|
|
25
|
+
const entry = scored[i];
|
|
26
|
+
if (entry.score < threshold) {
|
|
27
|
+
ignored.push({
|
|
28
|
+
target: entry.candidate.target,
|
|
29
|
+
reason: "low_voi",
|
|
30
|
+
revisit_if: "VOI 上升或目标改变",
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
above.push(entry);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (above.length === 0) {
|
|
38
|
+
return { slots: [], ignored, impasse: "STUCK" };
|
|
39
|
+
}
|
|
40
|
+
const tie = above.length > 1 && Math.abs(above[0].score - above[1].score) < 0.02;
|
|
41
|
+
let remaining = options.budgetTokens;
|
|
42
|
+
const slots = [];
|
|
43
|
+
for (let i = 0; i < above.length; i += 1) {
|
|
44
|
+
const candidate = above[i].candidate;
|
|
45
|
+
const score = above[i].score;
|
|
46
|
+
if (slots.length >= cap) {
|
|
47
|
+
ignored.push({ target: candidate.target, reason: "deferred", revisit_if: "焦点释放后" });
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (candidate.costTokens > remaining) {
|
|
51
|
+
ignored.push({ target: candidate.target, reason: "budget", revisit_if: "预算恢复后" });
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
remaining -= candidate.costTokens;
|
|
55
|
+
slots.push({
|
|
56
|
+
target: candidate.target,
|
|
57
|
+
role: candidate.role,
|
|
58
|
+
tier: candidate.tier,
|
|
59
|
+
salience: score,
|
|
60
|
+
voi: candidate.voi,
|
|
61
|
+
cost: { tokens: candidate.costTokens },
|
|
62
|
+
budget: { tokens: candidate.costTokens },
|
|
63
|
+
why: candidate.why,
|
|
64
|
+
state: "active",
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
const impasse = slots.length === 0 ? "BUDGET" : tie ? "TIE" : undefined;
|
|
68
|
+
return { slots, ignored, impasse };
|
|
69
|
+
};
|
|
70
|
+
const clampWeight = (value) => Math.max(0, Math.min(1, value));
|
|
71
|
+
/**
|
|
72
|
+
* The single attention state.
|
|
73
|
+
*
|
|
74
|
+
* It owns only the ordered focus ring, capacity and force field. It never
|
|
75
|
+
* materializes context, never mutates Frame and never executes a shift: a shift
|
|
76
|
+
* is an Action that calls `shift()` and must be settled by a Receipt.
|
|
77
|
+
*/
|
|
78
|
+
export class Attention {
|
|
79
|
+
subject;
|
|
80
|
+
capacity;
|
|
81
|
+
status = "open";
|
|
82
|
+
cursor = 0;
|
|
83
|
+
items;
|
|
84
|
+
forces = [];
|
|
85
|
+
now;
|
|
86
|
+
constructor(options) {
|
|
87
|
+
if (!Number.isSafeInteger(options.capacity.slots) || options.capacity.slots <= 0) {
|
|
88
|
+
throw new RangeError("attention capacity.slots must be positive");
|
|
89
|
+
}
|
|
90
|
+
if (!Number.isSafeInteger(options.capacity.tokens) || options.capacity.tokens <= 0) {
|
|
91
|
+
throw new RangeError("attention capacity.tokens must be positive");
|
|
92
|
+
}
|
|
93
|
+
this.subject = { ...options.subject };
|
|
94
|
+
this.capacity = { ...options.capacity };
|
|
95
|
+
this.items = (options.items ?? []).map((item) => ({ ...item }));
|
|
96
|
+
this.items.sort((left, right) => left.order - right.order);
|
|
97
|
+
this.now = options.now ?? (() => new Date().toISOString());
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Apply an attraction/distraction force; commit decides admission.
|
|
101
|
+
*/
|
|
102
|
+
observe(force) {
|
|
103
|
+
this.assertOpen();
|
|
104
|
+
if (!Number.isFinite(force.strength) || force.strength < 0) {
|
|
105
|
+
throw new RangeError("force strength must be non-negative");
|
|
106
|
+
}
|
|
107
|
+
if (force.kind === "distraction" && force.competesWith === (void 0)) {
|
|
108
|
+
throw new Error("distraction requires competesWith");
|
|
109
|
+
}
|
|
110
|
+
const id = force.target.id;
|
|
111
|
+
const target = this.items.find((item) => item.target.id === id);
|
|
112
|
+
if (target === (void 0)) {
|
|
113
|
+
this.items.push({
|
|
114
|
+
target: { ...force.target },
|
|
115
|
+
order: this.nextOrder(),
|
|
116
|
+
weight: clampWeight(force.strength),
|
|
117
|
+
source: force.from,
|
|
118
|
+
enteredAt: this.now(),
|
|
119
|
+
...(force.ttl === (void 0) ? {} : { ttl: force.ttl }),
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
target.weight = clampWeight(target.weight + force.strength);
|
|
124
|
+
}
|
|
125
|
+
if (force.kind === "distraction" && force.competesWith !== (void 0)) {
|
|
126
|
+
const competitor = this.items.find((item) => item.target.id === force.competesWith?.id);
|
|
127
|
+
if (competitor !== (void 0)) {
|
|
128
|
+
competitor.weight = clampWeight(competitor.weight - force.strength * 0.5);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
this.forces.push({ ...force });
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Stable left/right window. Pinned items stay visible.
|
|
135
|
+
*/
|
|
136
|
+
focus() {
|
|
137
|
+
const pinned = this.items.filter((item) => item.pinned === true);
|
|
138
|
+
const unpinned = this.items.filter((item) => item.pinned !== true);
|
|
139
|
+
const needed = Math.max(0, this.capacity.slots - pinned.length);
|
|
140
|
+
const visible = unpinned.slice(this.cursor, this.cursor + needed);
|
|
141
|
+
return [...pinned, ...visible].sort((left, right) => left.order - right.order);
|
|
142
|
+
}
|
|
143
|
+
snapshot() {
|
|
144
|
+
const focus = this.focus();
|
|
145
|
+
const focusIds = new Set(focus.map((item) => item.target.id));
|
|
146
|
+
return {
|
|
147
|
+
subject: { ...this.subject },
|
|
148
|
+
status: this.status,
|
|
149
|
+
cursor: this.cursor,
|
|
150
|
+
capacity: { ...this.capacity },
|
|
151
|
+
focus,
|
|
152
|
+
ignored: this.items.filter((item) => !focusIds.has(item.target.id)),
|
|
153
|
+
forces: this.forces.map((force) => ({ ...force })),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Apply one `attention.shift` action. The caller must still record an
|
|
158
|
+
* ActionRecord and a Receipt; this method only mutates cursor.
|
|
159
|
+
*/
|
|
160
|
+
shift(action) {
|
|
161
|
+
this.assertOpen();
|
|
162
|
+
if (action.direction !== "left" && action.direction !== "right") {
|
|
163
|
+
throw new Error(`invalid shift direction ${action.direction}`);
|
|
164
|
+
}
|
|
165
|
+
const steps = Math.max(1, Math.abs(Math.trunc(action.steps ?? 1)));
|
|
166
|
+
const pinned = this.items.filter((item) => item.pinned === true).length;
|
|
167
|
+
const needed = Math.max(0, this.capacity.slots - pinned);
|
|
168
|
+
const unpinned = this.items.length - pinned;
|
|
169
|
+
const maxCursor = Math.max(0, unpinned - needed);
|
|
170
|
+
const next = Math.max(0, Math.min(maxCursor, this.cursor + (action.direction === "left" ? -steps : steps)));
|
|
171
|
+
const changed = next !== this.cursor;
|
|
172
|
+
const reason = changed ? `cursor ${this.cursor}->${next}` : `blocked at ${action.direction} boundary (${this.cursor})`;
|
|
173
|
+
this.cursor = next;
|
|
174
|
+
return { actionId: action.actionId, changed, blocked: !changed, reason, snapshot: this.snapshot() };
|
|
175
|
+
}
|
|
176
|
+
close() {
|
|
177
|
+
this.status = "closed";
|
|
178
|
+
}
|
|
179
|
+
nextOrder() {
|
|
180
|
+
return this.items.reduce((max, item) => Math.max(max, item.order), -1) + 1;
|
|
181
|
+
}
|
|
182
|
+
assertOpen() {
|
|
183
|
+
if (this.status === "closed") {
|
|
184
|
+
throw new Error("attention is closed");
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Convert a shift into an existing runtime ActionPlan, not a new executor.
|
|
190
|
+
*/
|
|
191
|
+
export const toShiftAction = (shift) => ({
|
|
192
|
+
goal: "move the attention window",
|
|
193
|
+
intent: "attention.shift",
|
|
194
|
+
expectedEffect: `attention cursor moves ${shift.direction} by ${shift.steps ?? 1}`,
|
|
195
|
+
preconditions: ["attention is open", "focus is ordered"],
|
|
196
|
+
successCriteria: ["cursor changed", "a new Frame is committed", "a Receipt is recorded"],
|
|
197
|
+
risk: "none",
|
|
198
|
+
});
|
|
199
|
+
/**
|
|
200
|
+
* Test helper: the contract's monotonicity constraints (§5.2).
|
|
201
|
+
*/
|
|
202
|
+
export const respectsMonotonicity = (base) => {
|
|
203
|
+
const at = (over) => salience({ ...base, ...over });
|
|
204
|
+
const s0 = at({});
|
|
205
|
+
return (at({ voi: Math.min(1, base.voi + 0.1) }) >= s0 &&
|
|
206
|
+
at({ costTokens: base.costTokens + 200 }) <= s0 &&
|
|
207
|
+
at({ risk: Math.min(1, base.risk + 0.1) }) <= s0 &&
|
|
208
|
+
at({ trustCap: Math.min(base.trustCap, 0.2) }) <= s0);
|
|
209
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Budget, Usage } from "../types/common.js";
|
|
2
|
+
export type BudgetDimension = "tokens" | "calls" | "ms";
|
|
3
|
+
export declare class BudgetExceeded extends Error {
|
|
4
|
+
readonly code = "budget_exceeded";
|
|
5
|
+
readonly dimension: BudgetDimension;
|
|
6
|
+
readonly limit: number;
|
|
7
|
+
readonly observed: number;
|
|
8
|
+
constructor(dimension: BudgetDimension, limit: number, observed: number);
|
|
9
|
+
}
|
|
10
|
+
export interface CallCost {
|
|
11
|
+
tokens?: number;
|
|
12
|
+
calls?: number;
|
|
13
|
+
ms?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The single metering point (A-3).
|
|
17
|
+
*
|
|
18
|
+
* The 2026 CVE-2026-114386 showed why this cannot live inside a sandbox: a
|
|
19
|
+
* nested call that bypasses the outer counter makes every quota advisory.
|
|
20
|
+
* Here, `run` charges *before* executing, so a nested orchestration that loops
|
|
21
|
+
* still hits the same counter.
|
|
22
|
+
*/
|
|
23
|
+
export declare class Dispatcher {
|
|
24
|
+
readonly lease: Budget;
|
|
25
|
+
private used;
|
|
26
|
+
constructor(lease: Budget);
|
|
27
|
+
run<T>(fn: () => T, cost?: CallCost): T;
|
|
28
|
+
private charge;
|
|
29
|
+
usage(): Usage;
|
|
30
|
+
remaining(): Required<Pick<Budget, "tokens" | "calls" | "ms">>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export class BudgetExceeded extends Error {
|
|
2
|
+
code = "budget_exceeded";
|
|
3
|
+
dimension;
|
|
4
|
+
limit;
|
|
5
|
+
observed;
|
|
6
|
+
constructor(dimension, limit, observed) {
|
|
7
|
+
super(`budget exceeded on ${dimension}: observed ${observed} > limit ${limit}`);
|
|
8
|
+
this.name = "BudgetExceeded";
|
|
9
|
+
this.dimension = dimension;
|
|
10
|
+
this.limit = limit;
|
|
11
|
+
this.observed = observed;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The single metering point (A-3).
|
|
16
|
+
*
|
|
17
|
+
* The 2026 CVE-2026-114386 showed why this cannot live inside a sandbox: a
|
|
18
|
+
* nested call that bypasses the outer counter makes every quota advisory.
|
|
19
|
+
* Here, `run` charges *before* executing, so a nested orchestration that loops
|
|
20
|
+
* still hits the same counter.
|
|
21
|
+
*/
|
|
22
|
+
export class Dispatcher {
|
|
23
|
+
lease;
|
|
24
|
+
used = { tokens: 0, calls: 0, ms: 0 };
|
|
25
|
+
constructor(lease) {
|
|
26
|
+
this.lease = lease;
|
|
27
|
+
}
|
|
28
|
+
run(fn, cost = {}) {
|
|
29
|
+
this.charge("tokens", cost.tokens ?? 0);
|
|
30
|
+
this.charge("calls", cost.calls ?? 1);
|
|
31
|
+
this.charge("ms", cost.ms ?? 0);
|
|
32
|
+
return fn();
|
|
33
|
+
}
|
|
34
|
+
charge(dimension, amount) {
|
|
35
|
+
if (amount === 0) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const limit = this.lease[dimension];
|
|
39
|
+
const next = this.used[dimension] + amount;
|
|
40
|
+
if (limit !== (void 0) && next > limit) {
|
|
41
|
+
throw new BudgetExceeded(dimension, limit, next);
|
|
42
|
+
}
|
|
43
|
+
this.used[dimension] = next;
|
|
44
|
+
}
|
|
45
|
+
usage() {
|
|
46
|
+
return { tokens: this.used.tokens, calls: this.used.calls, ms: this.used.ms };
|
|
47
|
+
}
|
|
48
|
+
remaining() {
|
|
49
|
+
return {
|
|
50
|
+
tokens: Math.max(0, (this.lease.tokens ?? 0) - this.used.tokens),
|
|
51
|
+
calls: Math.max(0, (this.lease.calls ?? 0) - this.used.calls),
|
|
52
|
+
ms: Math.max(0, (this.lease.ms ?? 0) - this.used.ms),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AMP — cognitive state model (proposal).
|
|
3
|
+
*
|
|
4
|
+
* The premise: an agent and a person face the same *control* problem — a
|
|
5
|
+
* resource-bounded decider must allocate finite cognition, monitor itself, and
|
|
6
|
+
* be observed by others. Psychology is the accumulated science of that problem,
|
|
7
|
+
* so its constraints transfer even though its phenomenology does not. This
|
|
8
|
+
* module therefore models the agent as a bounded agent, not as a mind.
|
|
9
|
+
*
|
|
10
|
+
* What is borrowed from psychology is *form*, never a magic number: every
|
|
11
|
+
* constant below is a named parameter with a citation and a stated status
|
|
12
|
+
* (`measured` on humans, or `convention`), and nothing here claims the agent
|
|
13
|
+
* has the corresponding experience.
|
|
14
|
+
*
|
|
15
|
+
* Five state variables, each estimable from the ledger alone:
|
|
16
|
+
*
|
|
17
|
+
* | state | psychological construct | what it changes |
|
|
18
|
+
* | --- | --- | --- |
|
|
19
|
+
* | `load` | working-memory occupancy + open loops | effective capacity; whether novelty may fill space |
|
|
20
|
+
* | `vigilance` | time-on-task alertness | probability of a *missed re-check*, not "energy" |
|
|
21
|
+
* | `arousal` | error pressure / urgency | breadth: it narrows what counts as on-goal |
|
|
22
|
+
* | `mastery` | self-efficacy, long-run | whether to act, ask, or delegate |
|
|
23
|
+
* | `accountability` | identifiability to an audience | effort and how many alternatives are required |
|
|
24
|
+
*
|
|
25
|
+
* The laws in `CognitiveLaws` are deliberately few, monotone and falsifiable.
|
|
26
|
+
* A state variable with no measurable signature is not modelled here at all —
|
|
27
|
+
* which is why there is no `mood`, no `fatigue`, and no `intuition`.
|
|
28
|
+
*/
|
|
29
|
+
import type { Frame, Ignored, Slot } from "../frame/frame.js";
|
|
30
|
+
import type { Receipt } from "../receipt/receipt.js";
|
|
31
|
+
import type { Confidence, Ref, Tier } from "../types/common.js";
|
|
32
|
+
type LawParameter = {
|
|
33
|
+
readonly value: number;
|
|
34
|
+
readonly status: "measured" | "convention";
|
|
35
|
+
readonly source: string;
|
|
36
|
+
};
|
|
37
|
+
type CognitiveLawSet = {
|
|
38
|
+
readonly lossAsymmetry: LawParameter;
|
|
39
|
+
readonly vigilanceTau: LawParameter;
|
|
40
|
+
readonly iorTau: LawParameter;
|
|
41
|
+
readonly baseCapacity: LawParameter;
|
|
42
|
+
readonly loadPenalty: LawParameter;
|
|
43
|
+
readonly noveltyLoadFloor: LawParameter;
|
|
44
|
+
readonly arousalNarrowing: LawParameter;
|
|
45
|
+
readonly metaCharge: LawParameter;
|
|
46
|
+
readonly valueLearning: LawParameter;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Named law parameters. Every entry states whether the value is measured on
|
|
50
|
+
* humans or a convention of this implementation, because a protocol may cite a
|
|
51
|
+
* direction it cannot cite a magnitude for.
|
|
52
|
+
*/
|
|
53
|
+
export declare const CognitiveLaws: CognitiveLawSet;
|
|
54
|
+
/**
|
|
55
|
+
* History of one target, derived from prior frames and receipts. Never stored as a weight.
|
|
56
|
+
*/
|
|
57
|
+
export interface CandidateHistory {
|
|
58
|
+
/**
|
|
59
|
+
* Mean of `realized_voi` over past selections; 0.5 only when no sample exists.
|
|
60
|
+
*/
|
|
61
|
+
realized?: number;
|
|
62
|
+
/**
|
|
63
|
+
* Cycles since this target last occupied a slot.
|
|
64
|
+
*/
|
|
65
|
+
lastSelectedAge?: number;
|
|
66
|
+
/**
|
|
67
|
+
* Cycles since this target was last explicitly excluded.
|
|
68
|
+
*/
|
|
69
|
+
lastIgnoredAge?: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A candidate plus the fields the cognitive law needs, all supplied by the host.
|
|
73
|
+
*/
|
|
74
|
+
export interface CognitiveCandidate {
|
|
75
|
+
target: Ref;
|
|
76
|
+
role: Slot["role"];
|
|
77
|
+
tier?: Tier;
|
|
78
|
+
voi: Confidence;
|
|
79
|
+
goalFit: Confidence;
|
|
80
|
+
uncertainty: Confidence;
|
|
81
|
+
novelty: Confidence;
|
|
82
|
+
costTokens: number;
|
|
83
|
+
risk: Confidence;
|
|
84
|
+
/**
|
|
85
|
+
* Trust cap: external content cannot buy salience, only lose it (A-4).
|
|
86
|
+
*/
|
|
87
|
+
trustCap: Confidence;
|
|
88
|
+
why: string;
|
|
89
|
+
/**
|
|
90
|
+
* Additive floor that the multiplicative score cannot cancel (proposed A-10).
|
|
91
|
+
*/
|
|
92
|
+
hardFloor?: Confidence;
|
|
93
|
+
/**
|
|
94
|
+
* Chunks the target occupies; two unrelated sub-goals cost two (proposed A-7).
|
|
95
|
+
*/
|
|
96
|
+
chunkWeight?: number;
|
|
97
|
+
/**
|
|
98
|
+
* Deterministic difference from the previous focus, in tokens (proposed A-12).
|
|
99
|
+
*/
|
|
100
|
+
switchCostTokens?: number;
|
|
101
|
+
history?: CandidateHistory;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Ignore reasons this law can emit. The five beyond `IgnoredReason` require a
|
|
105
|
+
* schema addition; keeping them in a wider local union means this module stays
|
|
106
|
+
* additive and changes no existing contract.
|
|
107
|
+
*/
|
|
108
|
+
export type CognitiveIgnoreReason = Ignored["reason"] | "inhibited" | "low_sensitivity" | "conservative_criterion" | "capacity" | "exhausted";
|
|
109
|
+
export interface CognitiveIgnored {
|
|
110
|
+
target: Ref;
|
|
111
|
+
reason: CognitiveIgnoreReason;
|
|
112
|
+
revisit_if: string;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The five state variables plus everything derived from them.
|
|
116
|
+
*/
|
|
117
|
+
export interface CognitiveState {
|
|
118
|
+
load: Confidence;
|
|
119
|
+
vigilance: Confidence;
|
|
120
|
+
arousal: Confidence;
|
|
121
|
+
mastery: Confidence;
|
|
122
|
+
accountability: Confidence;
|
|
123
|
+
/**
|
|
124
|
+
* Cycles since the last `rest` frame; drives `vigilance`.
|
|
125
|
+
*/
|
|
126
|
+
cyclesSinceRest: number;
|
|
127
|
+
/**
|
|
128
|
+
* `baseCapacity` after the load penalty. Capacity here is in chunks.
|
|
129
|
+
*/
|
|
130
|
+
capacityEff: number;
|
|
131
|
+
/**
|
|
132
|
+
* Probability that a fired `revisit_if` goes unchecked. This is what rest repairs.
|
|
133
|
+
*/
|
|
134
|
+
pLapse: Confidence;
|
|
135
|
+
/**
|
|
136
|
+
* Role that dominated the previous frame; switch cost is charged against it.
|
|
137
|
+
*/
|
|
138
|
+
dominantRole?: Slot["role"];
|
|
139
|
+
/**
|
|
140
|
+
* `measured` when enough receipts existed, otherwise `default`.
|
|
141
|
+
*/
|
|
142
|
+
source: "measured" | "default";
|
|
143
|
+
samples: number;
|
|
144
|
+
}
|
|
145
|
+
export interface CognitiveInputs {
|
|
146
|
+
frames: readonly Frame[];
|
|
147
|
+
receipts: readonly Receipt[];
|
|
148
|
+
/**
|
|
149
|
+
* Host-supplied when it has ground truth; otherwise derived from frames.
|
|
150
|
+
*/
|
|
151
|
+
accountability?: Confidence;
|
|
152
|
+
/**
|
|
153
|
+
* Receipts considered recent for `arousal`. Defaults to 12.
|
|
154
|
+
*/
|
|
155
|
+
window?: number;
|
|
156
|
+
baseCapacity?: number;
|
|
157
|
+
tauVigilance?: number;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Estimate the state from the ledger.
|
|
161
|
+
*
|
|
162
|
+
* Two timescales of the same signal are kept apart on purpose: `arousal` is
|
|
163
|
+
* *recent* error pressure (fast, phasic) while `mastery` is the long-run success
|
|
164
|
+
* rate (slow, trait-like). Collapsing them into one number loses the fact that a
|
|
165
|
+
* competent agent can be briefly alarmed, and an incompetent one can be calm.
|
|
166
|
+
*/
|
|
167
|
+
export declare const estimateCognitiveState: (input: CognitiveInputs) => CognitiveState;
|
|
168
|
+
/**
|
|
169
|
+
* The history multiplier: value learning minus inhibition of return.
|
|
170
|
+
*
|
|
171
|
+
* These are two mechanisms with opposite signs, not one "novelty" knob. A
|
|
172
|
+
* candidate that paid off is worth re-selecting; a candidate just rejected is
|
|
173
|
+
* worth *not* re-selecting, and both facts must survive into the next cycle.
|
|
174
|
+
*/
|
|
175
|
+
export declare const historyFactor: (history: CandidateHistory | undefined) => number;
|
|
176
|
+
/**
|
|
177
|
+
* The cognitive salience law.
|
|
178
|
+
*
|
|
179
|
+
* `S = floor ⊕ [ voi · goalFit^γ · (1 + novelty·openness) · history ]
|
|
180
|
+
* / [ 1 + c_tok + c_risk + c_switch·(1 + load) + c_meta ]`
|
|
181
|
+
*
|
|
182
|
+
* with `γ = 1 + arousalNarrowing · arousal`. Four consequences are worth naming:
|
|
183
|
+
*
|
|
184
|
+
* 1. **Arousal narrows.** As `arousal` rises, `goalFit` is raised to a power > 1,
|
|
185
|
+
* so off-goal candidates die faster and on-goal ones keep their rank. This is
|
|
186
|
+
* Easterbrook's cue-utilisation result expressed as an exponent, with no
|
|
187
|
+
* affect term anywhere.
|
|
188
|
+
* 2. **Low load does not invite capture.** Below `noveltyLoadFloor`, novelty
|
|
189
|
+
* contributes nothing, because spare capacity is exactly where irrelevant
|
|
190
|
+
* material gets in (Lavie).
|
|
191
|
+
* 3. **Hard floors bypass.** A floor is a maximum, never a multiplier, so a
|
|
192
|
+
* safety signal with `goalFit` near zero cannot be multiplied down to a
|
|
193
|
+
* `low_voi` exclusion.
|
|
194
|
+
* 4. **Deciding costs.** Every candidate pays `metaCharge`, and a candidate that
|
|
195
|
+
* differs from the previous focus pays its switch cost — twice over when
|
|
196
|
+
* `load` is high, because reconfiguration is harder under load.
|
|
197
|
+
*/
|
|
198
|
+
type SalienceLaw = (candidate: CognitiveCandidate, state: CognitiveState) => Confidence;
|
|
199
|
+
export declare const salienceFromState: SalienceLaw;
|
|
200
|
+
export interface CognitiveSelectionOptions {
|
|
201
|
+
budgetTokens: number;
|
|
202
|
+
/**
|
|
203
|
+
* Overrides `state.capacityEff` when the host has a better estimate.
|
|
204
|
+
*/
|
|
205
|
+
capacity?: number;
|
|
206
|
+
threshold?: number;
|
|
207
|
+
/**
|
|
208
|
+
* Token cost charged for changing the dominant role of the focus set.
|
|
209
|
+
*/
|
|
210
|
+
switchCostTokens?: number;
|
|
211
|
+
}
|
|
212
|
+
export interface CognitiveSelection {
|
|
213
|
+
slots: Slot[];
|
|
214
|
+
ignored: CognitiveIgnored[];
|
|
215
|
+
impasse?: "TIE" | "STUCK" | "BUDGET" | "INFEASIBLE";
|
|
216
|
+
/**
|
|
217
|
+
* Chunks consumed, so a caller can assert the capacity rule directly.
|
|
218
|
+
*/
|
|
219
|
+
capacityUsed: number;
|
|
220
|
+
}
|
|
221
|
+
type SelectionLaw = (candidates: readonly CognitiveCandidate[], state: CognitiveState, options: CognitiveSelectionOptions) => CognitiveSelection;
|
|
222
|
+
export declare const selectFromState: SelectionLaw;
|
|
223
|
+
/**
|
|
224
|
+
* The contract, as tests rather than as a formula. Ten monotonicity claims —
|
|
225
|
+
* the original five plus five that the cognitive law adds. An implementation may
|
|
226
|
+
* replace every constant above and still be conformant, provided these hold.
|
|
227
|
+
*/
|
|
228
|
+
type MonotonicityLaw = (base: CognitiveCandidate, state: CognitiveState) => boolean;
|
|
229
|
+
export declare const respectsCognitiveMonotonicity: MonotonicityLaw;
|
|
230
|
+
export {};
|