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,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authorization errors: a denied capability, or a grant that would amplify
|
|
3
|
+
* rights or lifetime. They share the `AmpError` shape so the kernel can turn
|
|
4
|
+
* any of them into a blocked receipt.
|
|
5
|
+
*/
|
|
6
|
+
import { AmpError } from "./ampError.js";
|
|
7
|
+
export class AuthzError extends AmpError {
|
|
8
|
+
constructor(code, problems) {
|
|
9
|
+
super("AuthzError", code, problems);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Boundary rejections: the only error a constructor in `src/boundary` may throw.
|
|
3
|
+
*
|
|
4
|
+
* The point of the boundary is that an invalid object is never returned. A
|
|
5
|
+
* constructor therefore fails as a whole, carrying every problem it found, so
|
|
6
|
+
* a caller can log one machine-readable reason and one audit receipt instead of
|
|
7
|
+
* a partially valid object that a later checker may or may not notice.
|
|
8
|
+
*/
|
|
9
|
+
import { AmpError } from "./ampError.js";
|
|
10
|
+
/**
|
|
11
|
+
* Stable machine-readable reasons; callers may switch on these.
|
|
12
|
+
*/
|
|
13
|
+
export type BoundaryCode = "invalid_frame" | "invalid_tool_args" | "unresolvable_ref" | "duplicate_ref" | "invalid_id";
|
|
14
|
+
export declare class BoundaryRejection extends AmpError<BoundaryCode> {
|
|
15
|
+
constructor(code: BoundaryCode, problems: readonly string[]);
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Boundary rejections: the only error a constructor in `src/boundary` may throw.
|
|
3
|
+
*
|
|
4
|
+
* The point of the boundary is that an invalid object is never returned. A
|
|
5
|
+
* constructor therefore fails as a whole, carrying every problem it found, so
|
|
6
|
+
* a caller can log one machine-readable reason and one audit receipt instead of
|
|
7
|
+
* a partially valid object that a later checker may or may not notice.
|
|
8
|
+
*/
|
|
9
|
+
import { AmpError } from "./ampError.js";
|
|
10
|
+
export class BoundaryRejection extends AmpError {
|
|
11
|
+
constructor(code, problems) {
|
|
12
|
+
super("BoundaryRejection", code, problems);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kernel errors: illegal process/thread transitions and exhausted resources.
|
|
3
|
+
*
|
|
4
|
+
* They share the `AmpError` shape (`code` + every problem found) so a caller can
|
|
5
|
+
* turn any of them into a blocked receipt without special-casing.
|
|
6
|
+
*/
|
|
7
|
+
import { AmpError } from "./ampError.js";
|
|
8
|
+
export type KernelCode = "invalid_process" | "invalid_thread" | "invalid_transition" | "unknown_process" | "unknown_thread" | "budget_exceeded" | "missing_receipt" | "agent_busy" | "claim_failed" | "lease_lost" | "unknown_object" | "duplicate_task";
|
|
9
|
+
export declare class KernelError extends AmpError<KernelCode> {
|
|
10
|
+
constructor(code: KernelCode, problems: readonly string[]);
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kernel errors: illegal process/thread transitions and exhausted resources.
|
|
3
|
+
*
|
|
4
|
+
* They share the `AmpError` shape (`code` + every problem found) so a caller can
|
|
5
|
+
* turn any of them into a blocked receipt without special-casing.
|
|
6
|
+
*/
|
|
7
|
+
import { AmpError } from "./ampError.js";
|
|
8
|
+
export class KernelError extends AmpError {
|
|
9
|
+
constructor(code, problems) {
|
|
10
|
+
super("KernelError", code, problems);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Window errors: the context window cannot hold a page even after eviction.
|
|
3
|
+
*/
|
|
4
|
+
import { AmpError } from "./ampError.js";
|
|
5
|
+
export type WindowCode = "window_full" | "unknown_page";
|
|
6
|
+
export declare class WindowError extends AmpError<WindowCode> {
|
|
7
|
+
constructor(code: WindowCode, problems: readonly string[]);
|
|
8
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inter-annotator agreement metrics. These are for labeled evaluation, not for
|
|
3
|
+
* model confidence; keep them separate from ECE/Brier.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Two label sequences over the same items.
|
|
7
|
+
*/
|
|
8
|
+
type LabelList = readonly string[];
|
|
9
|
+
/**
|
|
10
|
+
* A pairwise agreement statistic over two label sequences.
|
|
11
|
+
*/
|
|
12
|
+
type AgreementFn = (left: LabelList, right: LabelList) => number;
|
|
13
|
+
export declare const agreementRate: AgreementFn;
|
|
14
|
+
/**
|
|
15
|
+
* Cohen's kappa for two raters over the same categorical labels.
|
|
16
|
+
*/
|
|
17
|
+
export declare const cohenKappa: AgreementFn;
|
|
18
|
+
/**
|
|
19
|
+
* Fleiss' kappa for n items x m raters.
|
|
20
|
+
*/
|
|
21
|
+
export declare const fleissKappa: (matrix: readonly LabelList[]) => number;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inter-annotator agreement metrics. These are for labeled evaluation, not for
|
|
3
|
+
* model confidence; keep them separate from ECE/Brier.
|
|
4
|
+
*/
|
|
5
|
+
export const agreementRate = (left, right) => {
|
|
6
|
+
if (left.length !== right.length) {
|
|
7
|
+
throw new Error("label arrays must have equal length");
|
|
8
|
+
}
|
|
9
|
+
if (left.length === 0) {
|
|
10
|
+
return 1;
|
|
11
|
+
}
|
|
12
|
+
let matches = 0;
|
|
13
|
+
for (let index = 0; index < left.length; index += 1) {
|
|
14
|
+
if (left[index] === right[index]) {
|
|
15
|
+
matches += 1;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return matches / left.length;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Cohen's kappa for two raters over the same categorical labels.
|
|
22
|
+
*/
|
|
23
|
+
export const cohenKappa = (left, right) => {
|
|
24
|
+
if (left.length !== right.length) {
|
|
25
|
+
throw new Error("label arrays must have equal length");
|
|
26
|
+
}
|
|
27
|
+
if (left.length === 0) {
|
|
28
|
+
return 1;
|
|
29
|
+
}
|
|
30
|
+
const observed = agreementRate(left, right);
|
|
31
|
+
const categories = [...new Set([...left, ...right])];
|
|
32
|
+
let expected = 0;
|
|
33
|
+
for (let categoryIndex = 0; categoryIndex < categories.length; categoryIndex += 1) {
|
|
34
|
+
const category = categories[categoryIndex];
|
|
35
|
+
const leftRate = left.filter((label) => label === category).length / left.length;
|
|
36
|
+
const rightRate = right.filter((label) => label === category).length / right.length;
|
|
37
|
+
expected += leftRate * rightRate;
|
|
38
|
+
}
|
|
39
|
+
if (expected === 1) {
|
|
40
|
+
return observed === 1 ? 1 : 0;
|
|
41
|
+
}
|
|
42
|
+
return (observed - expected) / (1 - expected);
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Fleiss' kappa for n items x m raters.
|
|
46
|
+
*/
|
|
47
|
+
export const fleissKappa = (matrix) => {
|
|
48
|
+
if (matrix.length === 0) {
|
|
49
|
+
return 1;
|
|
50
|
+
}
|
|
51
|
+
const raters = matrix[0].length;
|
|
52
|
+
if (raters === 0 || matrix.some((row) => row.length !== raters)) {
|
|
53
|
+
throw new Error("ragged rating matrix");
|
|
54
|
+
}
|
|
55
|
+
const categories = [...new Set(matrix.flat())];
|
|
56
|
+
const total = matrix.length * raters;
|
|
57
|
+
const counts = new Map();
|
|
58
|
+
for (let rowIndex = 0; rowIndex < matrix.length; rowIndex += 1) {
|
|
59
|
+
const row = matrix[rowIndex];
|
|
60
|
+
for (let labelIndex = 0; labelIndex < row.length; labelIndex += 1) {
|
|
61
|
+
const label = row[labelIndex];
|
|
62
|
+
counts.set(label, (counts.get(label) ?? 0) + 1);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const observed = matrix.reduce((sum, row) => {
|
|
66
|
+
let agreements = 0;
|
|
67
|
+
for (let categoryIndex = 0; categoryIndex < categories.length; categoryIndex += 1) {
|
|
68
|
+
const category = categories[categoryIndex];
|
|
69
|
+
const count = row.filter((label) => label === category).length;
|
|
70
|
+
agreements += count * (count - 1);
|
|
71
|
+
}
|
|
72
|
+
return sum + agreements / (raters * (raters - 1));
|
|
73
|
+
}, 0) / matrix.length;
|
|
74
|
+
const expected = categories.reduce((sum, category) => {
|
|
75
|
+
const rate = (counts.get(category) ?? 0) / total;
|
|
76
|
+
return sum + rate * rate;
|
|
77
|
+
}, 0);
|
|
78
|
+
if (expected === 1) {
|
|
79
|
+
return observed === 1 ? 1 : 0;
|
|
80
|
+
}
|
|
81
|
+
return (observed - expected) / (1 - expected);
|
|
82
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export interface Annotation {
|
|
2
|
+
caseId: string;
|
|
3
|
+
annotator: string;
|
|
4
|
+
label: string;
|
|
5
|
+
note?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface LabelCandidate {
|
|
8
|
+
caseId: string;
|
|
9
|
+
predicted: number;
|
|
10
|
+
uncertainty?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* CSV header: caseId,annotator,label[,note]. Handles quoted newlines.
|
|
14
|
+
*/
|
|
15
|
+
export declare const importAnnotationsCsv: (text: string) => Annotation[];
|
|
16
|
+
/**
|
|
17
|
+
* Active learning: prefer predicted probability near 0.5 and high uncertainty.
|
|
18
|
+
*/
|
|
19
|
+
export declare const selectLabelCandidates: (candidates: readonly LabelCandidate[], budget: number) => LabelCandidate[];
|
|
20
|
+
/**
|
|
21
|
+
* Fill only unresolved ties; resolved cases keep their majority label.
|
|
22
|
+
*/
|
|
23
|
+
export declare const resolveUnresolved: (audit: LabelAudit, resolutions: Record<string, string>) => Record<string, string | null>;
|
|
24
|
+
/**
|
|
25
|
+
* Reject an annotation batch before it is used for calibration.
|
|
26
|
+
*/
|
|
27
|
+
export declare const requireLabelCoverage: (audit: LabelAudit, options?: {
|
|
28
|
+
minCoverage?: number;
|
|
29
|
+
maxDuplicates?: number;
|
|
30
|
+
}) => void;
|
|
31
|
+
export interface LabelAudit {
|
|
32
|
+
cases: number;
|
|
33
|
+
annotations: number;
|
|
34
|
+
covered: number;
|
|
35
|
+
coverage: number;
|
|
36
|
+
missing: string[];
|
|
37
|
+
duplicates: Array<{
|
|
38
|
+
caseId: string;
|
|
39
|
+
annotator: string;
|
|
40
|
+
count: number;
|
|
41
|
+
}>;
|
|
42
|
+
disagreements: Array<{
|
|
43
|
+
caseId: string;
|
|
44
|
+
labels: Record<string, number>;
|
|
45
|
+
}>;
|
|
46
|
+
annotators: string[];
|
|
47
|
+
pairwiseKappa: Array<{
|
|
48
|
+
left: string;
|
|
49
|
+
right: string;
|
|
50
|
+
kappa: number;
|
|
51
|
+
common: number;
|
|
52
|
+
}>;
|
|
53
|
+
adjudicated: Record<string, string | null>;
|
|
54
|
+
}
|
|
55
|
+
export declare const importAnnotations: (input: unknown) => Annotation[];
|
|
56
|
+
export declare const auditLabels: (caseIds: readonly string[], annotations: readonly Annotation[]) => LabelAudit;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Annotation import and adjudication.
|
|
3
|
+
*
|
|
4
|
+
* This is deliberately file-oriented: human labels may come from a spreadsheet,
|
|
5
|
+
* a CSV export or a small JSONL file. The audit reports coverage, duplicates,
|
|
6
|
+
* disagreements and pairwise Cohen's kappa before any label is trusted.
|
|
7
|
+
*/
|
|
8
|
+
import { cohenKappa } from "./agreement.js";
|
|
9
|
+
const splitCsvRecords = (text) => {
|
|
10
|
+
const records = [];
|
|
11
|
+
let record = [];
|
|
12
|
+
let cell = "";
|
|
13
|
+
let quoted = false;
|
|
14
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
15
|
+
const char = text[index];
|
|
16
|
+
if (char === '"') {
|
|
17
|
+
if (quoted && text[index + 1] === '"') {
|
|
18
|
+
cell += '"';
|
|
19
|
+
index += 1;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
quoted = !quoted;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else if (char === "," && !quoted) {
|
|
26
|
+
record.push(cell);
|
|
27
|
+
cell = "";
|
|
28
|
+
}
|
|
29
|
+
else if ((char === "\n" || char === "\r") && !quoted) {
|
|
30
|
+
if (char === "\r" && text[index + 1] === "\n") {
|
|
31
|
+
index += 1;
|
|
32
|
+
}
|
|
33
|
+
record.push(cell);
|
|
34
|
+
if (record.some((entry) => entry.trim().length > 0)) {
|
|
35
|
+
records.push(record);
|
|
36
|
+
}
|
|
37
|
+
record = [];
|
|
38
|
+
cell = "";
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
cell += char;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (cell.length > 0 || record.length > 0) {
|
|
45
|
+
record.push(cell);
|
|
46
|
+
if (record.some((entry) => entry.trim().length > 0)) {
|
|
47
|
+
records.push(record);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return records;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* CSV header: caseId,annotator,label[,note]. Handles quoted newlines.
|
|
54
|
+
*/
|
|
55
|
+
export const importAnnotationsCsv = (text) => {
|
|
56
|
+
const records = splitCsvRecords(text.replace(/^\uFEFF/, ""));
|
|
57
|
+
if (records.length === 0) {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
const header = records[0].map((cell) => cell.trim());
|
|
61
|
+
const indexOf = (name) => header.indexOf(name);
|
|
62
|
+
if (indexOf("caseId") < 0 || indexOf("annotator") < 0 || indexOf("label") < 0) {
|
|
63
|
+
throw new Error("CSV header requires caseId, annotator, label");
|
|
64
|
+
}
|
|
65
|
+
return records.slice(1).map((cells, row) => {
|
|
66
|
+
const caseId = cells[indexOf("caseId")]?.trim();
|
|
67
|
+
const annotator = cells[indexOf("annotator")]?.trim();
|
|
68
|
+
const label = cells[indexOf("label")]?.trim();
|
|
69
|
+
if (caseId === (void 0) || annotator === (void 0) || label === (void 0)) {
|
|
70
|
+
throw new Error(`CSV row ${row + 2} is incomplete`);
|
|
71
|
+
}
|
|
72
|
+
const note = indexOf("note") >= 0 ? cells[indexOf("note")]?.trim() : undefined;
|
|
73
|
+
return { caseId, annotator, label, ...(note === (void 0) || note.length === 0 ? {} : { note }) };
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Active learning: prefer predicted probability near 0.5 and high uncertainty.
|
|
78
|
+
*/
|
|
79
|
+
export const selectLabelCandidates = (candidates, budget) => {
|
|
80
|
+
return [...candidates]
|
|
81
|
+
.sort((left, right) => {
|
|
82
|
+
const leftScore = (1 - Math.abs(left.predicted - 0.5) * 2) * 0.6 + (left.uncertainty ?? 0) * 0.4;
|
|
83
|
+
const rightScore = (1 - Math.abs(right.predicted - 0.5) * 2) * 0.6 + (right.uncertainty ?? 0) * 0.4;
|
|
84
|
+
return rightScore - leftScore;
|
|
85
|
+
})
|
|
86
|
+
.slice(0, Math.max(0, budget));
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Fill only unresolved ties; resolved cases keep their majority label.
|
|
90
|
+
*/
|
|
91
|
+
export const resolveUnresolved = (audit, resolutions) => {
|
|
92
|
+
const result = { ...audit.adjudicated };
|
|
93
|
+
for (const [caseId, label] of Object.entries(resolutions)) {
|
|
94
|
+
if (result[caseId] !== null) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
result[caseId] = label;
|
|
98
|
+
}
|
|
99
|
+
return result;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Reject an annotation batch before it is used for calibration.
|
|
103
|
+
*/
|
|
104
|
+
export const requireLabelCoverage = (audit, options = {}) => {
|
|
105
|
+
const minCoverage = options.minCoverage ?? 0.9;
|
|
106
|
+
const maxDuplicates = options.maxDuplicates ?? 0;
|
|
107
|
+
if (audit.coverage < minCoverage) {
|
|
108
|
+
throw new Error(`label coverage ${audit.coverage.toFixed(3)} < ${minCoverage}`);
|
|
109
|
+
}
|
|
110
|
+
if (audit.duplicates.length > maxDuplicates) {
|
|
111
|
+
throw new Error(`duplicate annotations: ${audit.duplicates.length}`);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
export const importAnnotations = (input) => {
|
|
115
|
+
const rows = Array.isArray(input)
|
|
116
|
+
? input
|
|
117
|
+
: `${input}`
|
|
118
|
+
.split(/\r?\n/)
|
|
119
|
+
.filter((line) => line.trim().length > 0)
|
|
120
|
+
.map((line) => JSON.parse(line));
|
|
121
|
+
return rows.map((row, index) => {
|
|
122
|
+
const value = row;
|
|
123
|
+
if (typeof (value.caseId) !== "string" || typeof (value.annotator) !== "string" || typeof (value.label) !== "string") {
|
|
124
|
+
throw new Error(`annotation ${index} requires caseId, annotator and label`);
|
|
125
|
+
}
|
|
126
|
+
return { caseId: value.caseId, annotator: value.annotator, label: value.label, ...(typeof (value.note) === "string" ? { note: value.note } : {}) };
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
const pairKappa = (caseIds, annotations, left, right) => {
|
|
130
|
+
const common = [];
|
|
131
|
+
for (const caseId of caseIds) {
|
|
132
|
+
const leftLabel = annotations.find((annotation) => annotation.caseId === caseId && annotation.annotator === left)?.label;
|
|
133
|
+
const rightLabel = annotations.find((annotation) => annotation.caseId === caseId && annotation.annotator === right)?.label;
|
|
134
|
+
if (leftLabel !== (void 0) && rightLabel !== (void 0)) {
|
|
135
|
+
common.push({ caseId, left: leftLabel, right: rightLabel });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (common.length === 0) {
|
|
139
|
+
return { kappa: 1, common: 0 };
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
kappa: cohenKappa(common.map((entry) => entry.left), common.map((entry) => entry.right)),
|
|
143
|
+
common: common.length,
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
export const auditLabels = (caseIds, annotations) => {
|
|
147
|
+
const ids = new Set(caseIds);
|
|
148
|
+
const annotators = [...new Set(annotations.map((annotation) => annotation.annotator))].sort();
|
|
149
|
+
const counts = new Map();
|
|
150
|
+
for (const annotation of annotations) {
|
|
151
|
+
counts.set(`${annotation.caseId}\u0000${annotation.annotator}`, (counts.get(`${annotation.caseId}\u0000${annotation.annotator}`) ?? 0) + 1);
|
|
152
|
+
}
|
|
153
|
+
const duplicates = [...counts.entries()]
|
|
154
|
+
.filter(([, count]) => count > 1)
|
|
155
|
+
.map(([key, count]) => {
|
|
156
|
+
const [caseId, annotator] = key.split("\u0000");
|
|
157
|
+
return { caseId, annotator, count };
|
|
158
|
+
});
|
|
159
|
+
const missing = caseIds.filter((caseId) => !annotations.some((annotation) => annotation.caseId === caseId));
|
|
160
|
+
const disagreements = caseIds
|
|
161
|
+
.map((caseId) => {
|
|
162
|
+
const labels = {};
|
|
163
|
+
for (const annotation of annotations.filter((entry) => entry.caseId === caseId)) {
|
|
164
|
+
labels[annotation.label] = (labels[annotation.label] ?? 0) + 1;
|
|
165
|
+
}
|
|
166
|
+
return { caseId, labels };
|
|
167
|
+
})
|
|
168
|
+
.filter((entry) => Object.keys(entry.labels).length > 1);
|
|
169
|
+
const adjudicated = {};
|
|
170
|
+
for (const caseId of caseIds) {
|
|
171
|
+
const countsForCase = {};
|
|
172
|
+
for (const annotation of annotations.filter((entry) => entry.caseId === caseId)) {
|
|
173
|
+
countsForCase[annotation.label] = (countsForCase[annotation.label] ?? 0) + 1;
|
|
174
|
+
}
|
|
175
|
+
const ranked = Object.entries(countsForCase).sort((left, right) => right[1] - left[1]);
|
|
176
|
+
if (ranked.length === 0) {
|
|
177
|
+
adjudicated[caseId] = null;
|
|
178
|
+
}
|
|
179
|
+
else if (ranked.length > 1 && ranked[0][1] === ranked[1][1]) {
|
|
180
|
+
adjudicated[caseId] = null;
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
adjudicated[caseId] = ranked[0][0];
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const pairwiseKappa = [];
|
|
187
|
+
for (let left = 0; left < annotators.length; left += 1) {
|
|
188
|
+
for (let right = left + 1; right < annotators.length; right += 1) {
|
|
189
|
+
const result = pairKappa(caseIds, annotations, annotators[left], annotators[right]);
|
|
190
|
+
pairwiseKappa.push({ left: annotators[left], right: annotators[right], ...result });
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const covered = caseIds.filter((caseId) => annotations.some((annotation) => annotation.caseId === caseId)).length;
|
|
194
|
+
return {
|
|
195
|
+
cases: caseIds.length,
|
|
196
|
+
annotations: annotations.filter((annotation) => ids.has(annotation.caseId)).length,
|
|
197
|
+
covered,
|
|
198
|
+
coverage: caseIds.length === 0 ? 1 : covered / caseIds.length,
|
|
199
|
+
missing,
|
|
200
|
+
duplicates,
|
|
201
|
+
disagreements,
|
|
202
|
+
annotators,
|
|
203
|
+
pairwiseKappa,
|
|
204
|
+
adjudicated,
|
|
205
|
+
};
|
|
206
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export type EvidenceKind = "claim" | "evidence";
|
|
2
|
+
export interface EvidenceNode {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly kind: EvidenceKind;
|
|
5
|
+
statement: string;
|
|
6
|
+
trust?: "self" | "verified" | "trusted" | "asserted" | "inferred" | "external";
|
|
7
|
+
}
|
|
8
|
+
export interface EvidenceImpact {
|
|
9
|
+
id: string;
|
|
10
|
+
/**
|
|
11
|
+
* One shortest dependency witness; null denotes an explicitly changed root.
|
|
12
|
+
*/
|
|
13
|
+
via: string | null;
|
|
14
|
+
}
|
|
15
|
+
export declare class EvidenceGraph {
|
|
16
|
+
private readonly nodes;
|
|
17
|
+
private readonly forward;
|
|
18
|
+
private readonly reverse;
|
|
19
|
+
addClaim(id: string, statement: string): EvidenceNode;
|
|
20
|
+
addEvidence(id: string, statement: string, forClaim: string, trust?: EvidenceNode["trust"]): EvidenceNode;
|
|
21
|
+
addSource(id: string, statement: string, trust?: EvidenceNode["trust"]): EvidenceNode;
|
|
22
|
+
link(from: string, to: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* Multi-source breadth-first impact closure, including the changed roots.
|
|
25
|
+
* Visits only reachable adjacency, once per node, in container iteration order.
|
|
26
|
+
* This is a review set, not a verdict that dependent claims are false.
|
|
27
|
+
*/
|
|
28
|
+
impact(changedIds: readonly string[]): EvidenceImpact[];
|
|
29
|
+
get(id: string): EvidenceNode | undefined;
|
|
30
|
+
evidenceFor(claimId: string): string[];
|
|
31
|
+
claimsFor(evidenceId: string): string[];
|
|
32
|
+
hasCycle(): boolean;
|
|
33
|
+
get size(): number;
|
|
34
|
+
private addNode;
|
|
35
|
+
private reaches;
|
|
36
|
+
private edge;
|
|
37
|
+
}
|