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,148 @@
|
|
|
1
|
+
export const DefaultAttentionPolicy = {
|
|
2
|
+
baseSlots: 4,
|
|
3
|
+
reserveRatio: 0.25,
|
|
4
|
+
safetyFloorRatio: 0.1,
|
|
5
|
+
maxForegroundUtil: 0.75,
|
|
6
|
+
minSliceSlots: 1,
|
|
7
|
+
restAfterCycles: 8,
|
|
8
|
+
vigilanceFloor: 0.25,
|
|
9
|
+
loadCeiling: 0.9,
|
|
10
|
+
recoveryDebtThreshold: 0.7,
|
|
11
|
+
};
|
|
12
|
+
const clamp01 = (value) => Math.max(0, Math.min(1, value));
|
|
13
|
+
export const recoveryDebtOf = (state) => {
|
|
14
|
+
return clamp01(0.5 * (1 - state.vigilance) + 0.3 * state.load + 0.2 * state.pLapse);
|
|
15
|
+
};
|
|
16
|
+
export const shouldRest = (state, policy = DefaultAttentionPolicy) => {
|
|
17
|
+
return (state.cyclesSinceRest >= policy.restAfterCycles ||
|
|
18
|
+
state.vigilance <= policy.vigilanceFloor ||
|
|
19
|
+
state.load >= policy.loadCeiling ||
|
|
20
|
+
recoveryDebtOf(state) >= policy.recoveryDebtThreshold);
|
|
21
|
+
};
|
|
22
|
+
export const processAttention = (pid, state, policy = DefaultAttentionPolicy) => {
|
|
23
|
+
const effectiveSlots = Math.max(1, Math.floor(state.capacityEff));
|
|
24
|
+
const safetySlots = Math.min(effectiveSlots, Math.max(1, Math.floor(effectiveSlots * policy.safetyFloorRatio)));
|
|
25
|
+
const rawCap = Math.max(0, Math.floor(effectiveSlots * policy.maxForegroundUtil));
|
|
26
|
+
const foregroundCap = Math.max(0, Math.min(rawCap, effectiveSlots - safetySlots));
|
|
27
|
+
const reserveSlots = Math.max(safetySlots, effectiveSlots - foregroundCap);
|
|
28
|
+
return {
|
|
29
|
+
pid,
|
|
30
|
+
effectiveSlots,
|
|
31
|
+
foregroundCap,
|
|
32
|
+
reserveSlots,
|
|
33
|
+
safetySlots,
|
|
34
|
+
state,
|
|
35
|
+
recoveryDebt: recoveryDebtOf(state),
|
|
36
|
+
offline: shouldRest(state, policy),
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
const toAttention = (candidate, slots, foreground) => {
|
|
40
|
+
const attention = {
|
|
41
|
+
tid: candidate.tid,
|
|
42
|
+
pid: candidate.pid,
|
|
43
|
+
slots,
|
|
44
|
+
foreground,
|
|
45
|
+
priority: candidate.priority,
|
|
46
|
+
switchCost: Math.max(0, candidate.switchCost ?? 0),
|
|
47
|
+
};
|
|
48
|
+
if (candidate.role !== (void 0)) {
|
|
49
|
+
attention.role = candidate.role;
|
|
50
|
+
}
|
|
51
|
+
return attention;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Allocate one foreground task and, from the reserve, background tasks.
|
|
55
|
+
*
|
|
56
|
+
* Floors are intentionally asymmetric: safety is always reserved, every
|
|
57
|
+
* admitted task gets `minSlots`, but a deferred task gets no floor. Guaranteeing
|
|
58
|
+
* a floor to every candidate would make admission meaningless under pressure.
|
|
59
|
+
*/
|
|
60
|
+
export const planAttention = (process, candidates, policy = DefaultAttentionPolicy) => {
|
|
61
|
+
const deferred = [];
|
|
62
|
+
const background = [];
|
|
63
|
+
const sorted = [...candidates].sort((left, right) => right.priority - left.priority || left.tid - right.tid);
|
|
64
|
+
const foregroundCandidates = sorted.filter((candidate) => candidate.foreground !== false);
|
|
65
|
+
const backgroundCandidates = sorted.filter((candidate) => candidate.foreground === false);
|
|
66
|
+
if (process.offline) {
|
|
67
|
+
for (const candidate of foregroundCandidates) {
|
|
68
|
+
deferred.push({ tid: candidate.tid, reason: "offline" });
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
process,
|
|
72
|
+
background,
|
|
73
|
+
deferred,
|
|
74
|
+
utilization: 0,
|
|
75
|
+
pressure: 1,
|
|
76
|
+
rest: true,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
let foreground;
|
|
80
|
+
let remaining = process.foregroundCap;
|
|
81
|
+
for (let index = 0; index < foregroundCandidates.length; index += 1) {
|
|
82
|
+
const candidate = foregroundCandidates[index];
|
|
83
|
+
const minSlots = Math.max(1, candidate.minSlots ?? policy.minSliceSlots);
|
|
84
|
+
if (index === 0 && remaining >= minSlots) {
|
|
85
|
+
const slots = Math.min(remaining, Math.max(minSlots, Math.floor(candidate.preferredSlots)));
|
|
86
|
+
foreground = toAttention(candidate, slots, true);
|
|
87
|
+
remaining -= slots;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
deferred.push({ tid: candidate.tid, reason: index === 0 ? "budget" : "low-priority" });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
let reserveRemaining = Math.max(0, process.effectiveSlots - process.safetySlots - (foreground?.slots ?? 0));
|
|
94
|
+
for (const candidate of backgroundCandidates) {
|
|
95
|
+
const minSlots = Math.max(1, candidate.minSlots ?? policy.minSliceSlots);
|
|
96
|
+
if (reserveRemaining < minSlots) {
|
|
97
|
+
deferred.push({ tid: candidate.tid, reason: "budget" });
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const slots = Math.min(reserveRemaining, Math.max(minSlots, Math.floor(candidate.preferredSlots)));
|
|
101
|
+
background.push(toAttention(candidate, slots, false));
|
|
102
|
+
reserveRemaining -= slots;
|
|
103
|
+
}
|
|
104
|
+
const allocated = (foreground?.slots ?? 0) + background.reduce((sum, task) => sum + task.slots, 0);
|
|
105
|
+
const utilization = allocated / process.effectiveSlots;
|
|
106
|
+
const switchPressure = foreground === (void 0) ? 0 : Math.min(1, foreground.switchCost / Math.max(1, process.effectiveSlots));
|
|
107
|
+
const pressure = Math.min(1.5, deferred.length / Math.max(1, candidates.length) + switchPressure);
|
|
108
|
+
return {
|
|
109
|
+
process,
|
|
110
|
+
...(foreground === (void 0) ? {} : { foreground }),
|
|
111
|
+
background,
|
|
112
|
+
deferred,
|
|
113
|
+
utilization,
|
|
114
|
+
pressure,
|
|
115
|
+
rest: false,
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Rest restores vigilance, reduces load and clears the rest counter.
|
|
120
|
+
*/
|
|
121
|
+
export const applyRest = (state, cycles = 1) => {
|
|
122
|
+
const amount = Math.max(1, Math.floor(cycles));
|
|
123
|
+
const vigilance = clamp01(state.vigilance + 0.25 * amount);
|
|
124
|
+
const load = clamp01(state.load - 0.2 * amount);
|
|
125
|
+
return {
|
|
126
|
+
...state,
|
|
127
|
+
vigilance,
|
|
128
|
+
load,
|
|
129
|
+
pLapse: clamp01(1 - vigilance),
|
|
130
|
+
cyclesSinceRest: 0,
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Efficiency is useful outcomes per unit of attention, not raw utilization.
|
|
135
|
+
* Errors and rework are subtracted so a busy-but-wrong agent cannot win.
|
|
136
|
+
*/
|
|
137
|
+
export const qualityAdjustedThroughput = (stats) => {
|
|
138
|
+
const useful = Math.max(0, stats.successes - stats.errors - stats.rework);
|
|
139
|
+
return useful / Math.max(1, stats.attentionSlots);
|
|
140
|
+
};
|
|
141
|
+
export const attentionHealth = (plan) => {
|
|
142
|
+
return {
|
|
143
|
+
utilization: plan.utilization,
|
|
144
|
+
pressure: plan.pressure,
|
|
145
|
+
headroom: Math.max(0, 1 - plan.utilization),
|
|
146
|
+
rest: plan.rest,
|
|
147
|
+
};
|
|
148
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Id, Timestamp } from "../types/common.js";
|
|
2
|
+
import type { AttentionRequest, InterruptClass } from "./socialTypes.js";
|
|
3
|
+
export type Decision = "grant" | "defer" | "deny";
|
|
4
|
+
export interface AttentionPolicy {
|
|
5
|
+
/**
|
|
6
|
+
* Grants allowed per class per rolling hour. Safety is never blocked by this.
|
|
7
|
+
*/
|
|
8
|
+
budgets: Record<InterruptClass, number>;
|
|
9
|
+
quietHours?: {
|
|
10
|
+
start: number;
|
|
11
|
+
end: number;
|
|
12
|
+
};
|
|
13
|
+
cooldownMinutes?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Curiosity must clear this expected value to be granted at all.
|
|
16
|
+
*/
|
|
17
|
+
curiosityFloor?: number;
|
|
18
|
+
}
|
|
19
|
+
export declare const DefaultPolicy: AttentionPolicy;
|
|
20
|
+
export interface AttentionDecision {
|
|
21
|
+
request: Id;
|
|
22
|
+
decision: Decision;
|
|
23
|
+
reason: string;
|
|
24
|
+
at: Timestamp;
|
|
25
|
+
class: InterruptClass;
|
|
26
|
+
debtAdded: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface DebtEntry {
|
|
29
|
+
request: Id;
|
|
30
|
+
class: InterruptClass;
|
|
31
|
+
openedAt: Timestamp;
|
|
32
|
+
weight: number;
|
|
33
|
+
resolvedAt?: Timestamp;
|
|
34
|
+
}
|
|
35
|
+
type BrokerOptions = {
|
|
36
|
+
now: () => Timestamp;
|
|
37
|
+
policy?: Partial<AttentionPolicy>;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Attention broker (Profile `Social`).
|
|
41
|
+
*
|
|
42
|
+
* The human's attention is a budgeted resource, not a callable function.
|
|
43
|
+
* Safety bypasses the budget; everything else queues, cools down, or is denied.
|
|
44
|
+
*/
|
|
45
|
+
export declare class AttentionBroker {
|
|
46
|
+
private readonly policy;
|
|
47
|
+
private readonly now;
|
|
48
|
+
private readonly requests;
|
|
49
|
+
private readonly decisions;
|
|
50
|
+
private readonly grants;
|
|
51
|
+
private readonly lastTouch;
|
|
52
|
+
private readonly debt;
|
|
53
|
+
constructor(options: BrokerOptions);
|
|
54
|
+
submit(request: AttentionRequest): AttentionDecision;
|
|
55
|
+
private decide;
|
|
56
|
+
private defer;
|
|
57
|
+
private grantedThisHour;
|
|
58
|
+
private recordGrant;
|
|
59
|
+
/**
|
|
60
|
+
* Resolve a deferred request: it is answered, expired, or withdrawn.
|
|
61
|
+
*/
|
|
62
|
+
resolve(requestId: Id, outcome?: "answered" | "expired" | "withdrawn"): void;
|
|
63
|
+
/**
|
|
64
|
+
* Age-weighted debt: minutes open × urgency. Higher means more owed.
|
|
65
|
+
*/
|
|
66
|
+
debtScore(at?: Timestamp): number;
|
|
67
|
+
openDebt(): DebtEntry[];
|
|
68
|
+
/**
|
|
69
|
+
* How many requests were granted (feeds the unified ledger snapshot).
|
|
70
|
+
*/
|
|
71
|
+
grantedCount(): number;
|
|
72
|
+
decisionOf(requestId: Id): AttentionDecision | undefined;
|
|
73
|
+
}
|
|
74
|
+
export {};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
export const DefaultPolicy = {
|
|
2
|
+
budgets: { safety: 1, commitment: 3, opportunity: 2, curiosity: 1 },
|
|
3
|
+
quietHours: { start: 22, end: 7 },
|
|
4
|
+
cooldownMinutes: 10,
|
|
5
|
+
curiosityFloor: 0.7,
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Attention broker (Profile `Social`).
|
|
9
|
+
*
|
|
10
|
+
* The human's attention is a budgeted resource, not a callable function.
|
|
11
|
+
* Safety bypasses the budget; everything else queues, cools down, or is denied.
|
|
12
|
+
*/
|
|
13
|
+
export class AttentionBroker {
|
|
14
|
+
policy;
|
|
15
|
+
now;
|
|
16
|
+
requests = new Map();
|
|
17
|
+
decisions = new Map();
|
|
18
|
+
grants = new Map();
|
|
19
|
+
lastTouch = new Map();
|
|
20
|
+
debt = [];
|
|
21
|
+
constructor(options) {
|
|
22
|
+
this.now = options.now;
|
|
23
|
+
this.policy = {
|
|
24
|
+
...DefaultPolicy,
|
|
25
|
+
...options.policy,
|
|
26
|
+
budgets: { ...DefaultPolicy.budgets, ...(options.policy?.budgets ?? {}) },
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
submit(request) {
|
|
30
|
+
if (!request.why_now || !request.if_ignored) {
|
|
31
|
+
throw new Error("an attention request needs why_now and if_ignored");
|
|
32
|
+
}
|
|
33
|
+
if (this.requests.has(request.id)) {
|
|
34
|
+
throw new Error(`duplicate request: ${request.id}`);
|
|
35
|
+
}
|
|
36
|
+
this.requests.set(request.id, request);
|
|
37
|
+
const at = this.now();
|
|
38
|
+
const kind = request.class;
|
|
39
|
+
const decision = this.decide(request, at, kind);
|
|
40
|
+
this.decisions.set(request.id, decision);
|
|
41
|
+
if (decision.decision === "grant") {
|
|
42
|
+
this.recordGrant(kind, at);
|
|
43
|
+
this.lastTouch.set(request.target.id, Date.parse(at));
|
|
44
|
+
}
|
|
45
|
+
if (decision.decision !== "grant") {
|
|
46
|
+
this.lastTouch.set(request.id, Date.parse(at));
|
|
47
|
+
}
|
|
48
|
+
if (decision.debtAdded) {
|
|
49
|
+
this.debt.push({ request: request.id, class: kind, openedAt: at, weight: request.urgency });
|
|
50
|
+
}
|
|
51
|
+
return decision;
|
|
52
|
+
}
|
|
53
|
+
decide(request, at, kind) {
|
|
54
|
+
const immediate = {
|
|
55
|
+
request: request.id,
|
|
56
|
+
decision: "grant",
|
|
57
|
+
reason: "safety_bypass",
|
|
58
|
+
at,
|
|
59
|
+
class: kind,
|
|
60
|
+
debtAdded: false,
|
|
61
|
+
};
|
|
62
|
+
if (kind === "safety") {
|
|
63
|
+
return immediate;
|
|
64
|
+
}
|
|
65
|
+
const hour = new Date(at).getUTCHours();
|
|
66
|
+
const quiet = this.policy.quietHours;
|
|
67
|
+
const inQuietHours = quiet
|
|
68
|
+
? quiet.start <= quiet.end
|
|
69
|
+
? hour >= quiet.start && hour < quiet.end
|
|
70
|
+
: hour >= quiet.start || hour < quiet.end
|
|
71
|
+
: false;
|
|
72
|
+
if (inQuietHours) {
|
|
73
|
+
return this.defer(request, at, kind, "quiet_hours");
|
|
74
|
+
}
|
|
75
|
+
const cooldown = this.policy.cooldownMinutes ?? 0;
|
|
76
|
+
const touched = this.lastTouch.get(request.target.id);
|
|
77
|
+
if (touched !== (void 0) && cooldown > 0) {
|
|
78
|
+
const elapsed = (Date.parse(at) - touched) / 60_000;
|
|
79
|
+
if (elapsed < cooldown) {
|
|
80
|
+
return this.defer(request, at, kind, "cooldown");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (kind === "curiosity" && (request.expected_value ?? 0) < (this.policy.curiosityFloor ?? 0)) {
|
|
84
|
+
return { request: request.id, decision: "deny", reason: "curiosity_below_floor", at, class: kind, debtAdded: false };
|
|
85
|
+
}
|
|
86
|
+
if (this.grantedThisHour(kind, at) >= this.policy.budgets[kind]) {
|
|
87
|
+
return request.fallback === "queue"
|
|
88
|
+
? this.defer(request, at, kind, "budget_exhausted")
|
|
89
|
+
: { request: request.id, decision: "deny", reason: "budget_exhausted", at, class: kind, debtAdded: false };
|
|
90
|
+
}
|
|
91
|
+
return { request: request.id, decision: "grant", reason: "within_budget", at, class: kind, debtAdded: false };
|
|
92
|
+
}
|
|
93
|
+
defer(request, at, kind, reason) {
|
|
94
|
+
if (request.fallback === "drop") {
|
|
95
|
+
return { request: request.id, decision: "deny", reason: `${reason}:fallback_drop`, at, class: kind, debtAdded: false };
|
|
96
|
+
}
|
|
97
|
+
this.lastTouch.set(request.target.id, Date.parse(at));
|
|
98
|
+
return { request: request.id, decision: "defer", reason, at, class: kind, debtAdded: true };
|
|
99
|
+
}
|
|
100
|
+
grantedThisHour(kind, at) {
|
|
101
|
+
const now = Date.parse(at);
|
|
102
|
+
const window = (this.grants.get(kind) ?? []).filter((stamp) => now - Date.parse(stamp) < 3_600_000);
|
|
103
|
+
this.grants.set(kind, window);
|
|
104
|
+
return window.length;
|
|
105
|
+
}
|
|
106
|
+
recordGrant(kind, at) {
|
|
107
|
+
const list = this.grants.get(kind) ?? [];
|
|
108
|
+
list.push(at);
|
|
109
|
+
this.grants.set(kind, list);
|
|
110
|
+
this.lastTouch.set(kind, Date.parse(at));
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Resolve a deferred request: it is answered, expired, or withdrawn.
|
|
114
|
+
*/
|
|
115
|
+
resolve(requestId, outcome = "answered") {
|
|
116
|
+
const entry = this.debt.find((item) => item.request === requestId && !item.resolvedAt);
|
|
117
|
+
if (!entry) {
|
|
118
|
+
throw new Error(`no open debt for ${requestId}`);
|
|
119
|
+
}
|
|
120
|
+
entry.resolvedAt = this.now();
|
|
121
|
+
void outcome;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Age-weighted debt: minutes open × urgency. Higher means more owed.
|
|
125
|
+
*/
|
|
126
|
+
debtScore(at = this.now()) {
|
|
127
|
+
const now = Date.parse(at);
|
|
128
|
+
return Math.round(this.debt.reduce((sum, entry) => {
|
|
129
|
+
const end = entry.resolvedAt ? Date.parse(entry.resolvedAt) : now;
|
|
130
|
+
return sum + Math.max(0, (end - Date.parse(entry.openedAt)) / 60_000) * entry.weight;
|
|
131
|
+
}, 0));
|
|
132
|
+
}
|
|
133
|
+
openDebt() {
|
|
134
|
+
return this.debt.filter((entry) => !entry.resolvedAt);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* How many requests were granted (feeds the unified ledger snapshot).
|
|
138
|
+
*/
|
|
139
|
+
grantedCount() {
|
|
140
|
+
let count = 0;
|
|
141
|
+
const decisions = [...this.decisions.values()];
|
|
142
|
+
for (let index = 0; index < decisions.length; index += 1) {
|
|
143
|
+
const decision = decisions[index];
|
|
144
|
+
if (decision.decision === "grant") {
|
|
145
|
+
count += 1;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return count;
|
|
149
|
+
}
|
|
150
|
+
decisionOf(requestId) {
|
|
151
|
+
return this.decisions.get(requestId);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AMP v0.1 — social objects (Profile `Social`): other-model | common-ground | attention-request.
|
|
3
|
+
* Mirrors docs/schemas/social.schema.json.
|
|
4
|
+
*
|
|
5
|
+
* Everything about another mind is a hypothesis carrying confidence, not a fact (W-1, INV-11).
|
|
6
|
+
*/
|
|
7
|
+
import type { Confidence, Id, Ref, Timestamp } from "../types/common.js";
|
|
8
|
+
export interface OtherSubject {
|
|
9
|
+
kind: "human" | "agent";
|
|
10
|
+
id: Id;
|
|
11
|
+
label?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface BeliefAscription {
|
|
14
|
+
slot: Id;
|
|
15
|
+
/**
|
|
16
|
+
* 1 = "A believes P" · 2 = "A believes B believes P". Depth above 2 is computed from records, not elicited.
|
|
17
|
+
*/
|
|
18
|
+
order: 1 | 2 | 3;
|
|
19
|
+
proposition: string;
|
|
20
|
+
confidence: Confidence;
|
|
21
|
+
source: string;
|
|
22
|
+
volatility: "low" | "medium" | "high";
|
|
23
|
+
ttl: number;
|
|
24
|
+
}
|
|
25
|
+
export interface GoalAscription {
|
|
26
|
+
goal: string;
|
|
27
|
+
priority: number;
|
|
28
|
+
confidence: Confidence;
|
|
29
|
+
}
|
|
30
|
+
export interface KnowledgeState {
|
|
31
|
+
known?: Ref[];
|
|
32
|
+
unknown?: Ref[];
|
|
33
|
+
uncertain?: Ref[];
|
|
34
|
+
}
|
|
35
|
+
export interface Preference {
|
|
36
|
+
key: string;
|
|
37
|
+
value: string;
|
|
38
|
+
confidence: Confidence;
|
|
39
|
+
source?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface AttentionState {
|
|
42
|
+
state: "idle" | "busy" | "interruptible";
|
|
43
|
+
load?: Confidence;
|
|
44
|
+
last_interaction?: Timestamp;
|
|
45
|
+
}
|
|
46
|
+
export interface TrustAssessment {
|
|
47
|
+
domain?: string;
|
|
48
|
+
level: Confidence;
|
|
49
|
+
basis?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface Privacy {
|
|
52
|
+
scope: "turn" | "session" | "task" | "persistent";
|
|
53
|
+
retention_days?: number;
|
|
54
|
+
redact?: string[];
|
|
55
|
+
}
|
|
56
|
+
export interface OtherModel {
|
|
57
|
+
amp: "0.1";
|
|
58
|
+
kind: "other-model";
|
|
59
|
+
id: Id;
|
|
60
|
+
subject: OtherSubject;
|
|
61
|
+
beliefs: BeliefAscription[];
|
|
62
|
+
goals?: GoalAscription[];
|
|
63
|
+
knowledge?: KnowledgeState;
|
|
64
|
+
preferences?: Preference[];
|
|
65
|
+
attention?: AttentionState;
|
|
66
|
+
trust?: TrustAssessment;
|
|
67
|
+
common_ground?: Ref[];
|
|
68
|
+
privacy: Privacy;
|
|
69
|
+
confidence: Confidence;
|
|
70
|
+
updated: Timestamp;
|
|
71
|
+
}
|
|
72
|
+
export interface CommonGround {
|
|
73
|
+
amp: "0.1";
|
|
74
|
+
kind: "common-ground";
|
|
75
|
+
id: Id;
|
|
76
|
+
proposition: string;
|
|
77
|
+
/**
|
|
78
|
+
* Only the first four actually establish common ground.
|
|
79
|
+
*/
|
|
80
|
+
established_by: "assertion" | "confirmation" | "repair" | "shared_observation" | "assumption";
|
|
81
|
+
participants: Ref[];
|
|
82
|
+
confidence: Confidence;
|
|
83
|
+
established_at: Timestamp;
|
|
84
|
+
}
|
|
85
|
+
export type InterruptClass = "safety" | "commitment" | "opportunity" | "curiosity";
|
|
86
|
+
export interface AttentionRequest {
|
|
87
|
+
amp: "0.1";
|
|
88
|
+
kind: "attention-request";
|
|
89
|
+
id: Id;
|
|
90
|
+
from: Ref;
|
|
91
|
+
to: Ref;
|
|
92
|
+
target: Ref;
|
|
93
|
+
class: InterruptClass;
|
|
94
|
+
urgency: 1 | 2 | 3 | 4 | 5;
|
|
95
|
+
why_now: string;
|
|
96
|
+
if_ignored: string;
|
|
97
|
+
cost: import("../types/common.js").Budget;
|
|
98
|
+
expected_value?: Confidence;
|
|
99
|
+
expires?: Timestamp;
|
|
100
|
+
fallback: "queue" | "drop" | "escalate";
|
|
101
|
+
}
|
|
102
|
+
export type SocialObject = OtherModel | CommonGround | AttentionRequest;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capability-based authorization.
|
|
3
|
+
*
|
|
4
|
+
* A logical process has no MMU, so isolation is a policy decision: by default a
|
|
5
|
+
* subject may touch only its own resources, and any cross-subject access needs a
|
|
6
|
+
* live capability row. Capabilities are attenuating (rights and expiry can only
|
|
7
|
+
* shrink), recursive (revoking a parent revokes its grants) and auditable (every
|
|
8
|
+
* grant/revoke appends an event to the object chain).
|
|
9
|
+
*/
|
|
10
|
+
import type { DatabaseSync } from "node:sqlite";
|
|
11
|
+
import type { Id } from "../types/common.js";
|
|
12
|
+
export type SubjectKind = "host" | "process" | "thread";
|
|
13
|
+
export interface Subject {
|
|
14
|
+
kind: SubjectKind;
|
|
15
|
+
id: Id;
|
|
16
|
+
pid?: number;
|
|
17
|
+
tid?: number;
|
|
18
|
+
}
|
|
19
|
+
export type PermissionAction = "read" | "write" | "append" | "grant" | "revoke" | "spawn" | "kill" | "send" | "receive" | "fork" | "join";
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated Use `PermissionAction`; `Action` is reserved for the runtime's
|
|
22
|
+
* goal-directed intent (see `src/runtime/action.ts`).
|
|
23
|
+
*/
|
|
24
|
+
export type Action = PermissionAction;
|
|
25
|
+
export type ResourceKind = "object" | "process" | "thread" | "mailbox" | "budget";
|
|
26
|
+
export interface Resource {
|
|
27
|
+
kind: ResourceKind;
|
|
28
|
+
id: Id;
|
|
29
|
+
/**
|
|
30
|
+
* The process that owns the resource; omitted for kernel/global objects.
|
|
31
|
+
*/
|
|
32
|
+
ownerPid?: number;
|
|
33
|
+
}
|
|
34
|
+
export interface CapabilityRecord {
|
|
35
|
+
hid: number;
|
|
36
|
+
id: Id;
|
|
37
|
+
subject: Subject;
|
|
38
|
+
resource: Resource;
|
|
39
|
+
rights: Action[];
|
|
40
|
+
scope: "process" | "thread" | "shared";
|
|
41
|
+
parentHid?: number;
|
|
42
|
+
expiresAt?: string;
|
|
43
|
+
revokedAt?: string;
|
|
44
|
+
grantedBy?: Id;
|
|
45
|
+
createdAt: string;
|
|
46
|
+
}
|
|
47
|
+
export interface GrantInput {
|
|
48
|
+
grantor: Subject;
|
|
49
|
+
grantee: Subject;
|
|
50
|
+
resource: Resource;
|
|
51
|
+
rights: Action[];
|
|
52
|
+
scope?: "process" | "thread" | "shared";
|
|
53
|
+
expiresAt?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Rights the subject actually holds on the resource, including ownership.
|
|
57
|
+
*/
|
|
58
|
+
export declare const effectiveRights: (db: DatabaseSync, subject: Subject, resource: Resource, at: string) => Action[];
|
|
59
|
+
export declare const can: (db: DatabaseSync, subject: Subject, action: Action, resource: Resource, at: string) => boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Throws unless the subject holds `action` on `resource`.
|
|
62
|
+
*/
|
|
63
|
+
export declare const requirePermission: (db: DatabaseSync, subject: Subject, action: Action, resource: Resource, at: string) => void;
|
|
64
|
+
export declare const listCapabilities: (db: DatabaseSync, subject: Subject) => CapabilityRecord[];
|
|
65
|
+
/**
|
|
66
|
+
* Grant a subset of the grantor's rights to another subject.
|
|
67
|
+
*
|
|
68
|
+
* Amplification is rejected in both dimensions the model cares about: no new
|
|
69
|
+
* right may appear, and the new expiry may not outlive the grantor's own.
|
|
70
|
+
*/
|
|
71
|
+
export declare const grant: (db: DatabaseSync, input: GrantInput, at: string) => CapabilityRecord;
|
|
72
|
+
/**
|
|
73
|
+
* Revoke a capability and every grant derived from it.
|
|
74
|
+
*/
|
|
75
|
+
export declare const revoke: (db: DatabaseSync, subject: Subject, hid: number, at: string) => number;
|