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,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iterative segment tree over an associative monoid.
|
|
3
|
+
*
|
|
4
|
+
* The class owns a power-of-two padded tree: every real leaf holds one value,
|
|
5
|
+
* padding leaves hold the identity, and every internal node combines its two
|
|
6
|
+
* children. Point updates rebuild the root path in O(log n); half-open range
|
|
7
|
+
* queries combine O(log n) canonical nodes while preserving left-to-right
|
|
8
|
+
* order, so non-commutative operations such as string concatenation work.
|
|
9
|
+
*
|
|
10
|
+
* Lazy range updates are deliberately not supported. Empty ranges return the
|
|
11
|
+
* identity, and `size: 0` is valid: the tree has no leaves but still answers
|
|
12
|
+
* empty queries and `queryAll()` with that identity.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Construction options for {@link SegmentTree}.
|
|
16
|
+
*/
|
|
17
|
+
export interface SegmentTreeOptions<T> {
|
|
18
|
+
/**
|
|
19
|
+
* Number of leaves. Must be a non-negative safe integer.
|
|
20
|
+
*/
|
|
21
|
+
size: number;
|
|
22
|
+
/**
|
|
23
|
+
* Associative operation applied left-to-right.
|
|
24
|
+
*/
|
|
25
|
+
operation: (left: T, right: T) => T;
|
|
26
|
+
/**
|
|
27
|
+
* Neutral element for {@link SegmentTreeOptions.operation}.
|
|
28
|
+
*/
|
|
29
|
+
identity: T;
|
|
30
|
+
/**
|
|
31
|
+
* Optional initial leaf values, in index order. If present, the iterable
|
|
32
|
+
* must contain exactly {@link SegmentTreeOptions.size} values.
|
|
33
|
+
*/
|
|
34
|
+
values?: Iterable<T>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A segment tree for an associative monoid.
|
|
38
|
+
*
|
|
39
|
+
* Values are stored by reference; the tree never clones them. The operation
|
|
40
|
+
* must be associative, and `identity` must be neutral for it. Commutativity is
|
|
41
|
+
* not required: range queries combine canonical nodes in index order.
|
|
42
|
+
*
|
|
43
|
+
* @typeParam T - Leaf value type.
|
|
44
|
+
*/
|
|
45
|
+
export declare class SegmentTree<T> {
|
|
46
|
+
private readonly operation;
|
|
47
|
+
private readonly identity;
|
|
48
|
+
private readonly count;
|
|
49
|
+
private readonly base;
|
|
50
|
+
private readonly tree;
|
|
51
|
+
/**
|
|
52
|
+
* Build a tree with `options.size` leaves.
|
|
53
|
+
*
|
|
54
|
+
* When `values` is omitted, every leaf starts as `identity`. When it is
|
|
55
|
+
* supplied, it is consumed once and must produce exactly `size` values.
|
|
56
|
+
*
|
|
57
|
+
* @param options - Size, operation, identity, and optional initial values.
|
|
58
|
+
* @throws RangeError if `size` is not a non-negative safe integer, or if
|
|
59
|
+
* `values` does not contain exactly `size` values.
|
|
60
|
+
* @throws TypeError if `operation` is not a function or `identity` is not
|
|
61
|
+
* supplied.
|
|
62
|
+
*/
|
|
63
|
+
constructor(options: SegmentTreeOptions<T>);
|
|
64
|
+
/**
|
|
65
|
+
* Number of real leaves.
|
|
66
|
+
*/
|
|
67
|
+
get size(): number;
|
|
68
|
+
/**
|
|
69
|
+
* Read the leaf at `index`.
|
|
70
|
+
*
|
|
71
|
+
* @throws RangeError if `index` is not a safe integer in `[0, size)`.
|
|
72
|
+
*/
|
|
73
|
+
get(index: number): T;
|
|
74
|
+
/**
|
|
75
|
+
* Replace the leaf at `index`.
|
|
76
|
+
*
|
|
77
|
+
* @throws RangeError if `index` is not a safe integer in `[0, size)`.
|
|
78
|
+
*/
|
|
79
|
+
set(index: number, value: T): void;
|
|
80
|
+
/**
|
|
81
|
+
* Transform the leaf at `index` from its current value.
|
|
82
|
+
*
|
|
83
|
+
* `update` is called once with the previous leaf value. If it throws, the
|
|
84
|
+
* tree is left unchanged.
|
|
85
|
+
*
|
|
86
|
+
* @throws RangeError if `index` is not a safe integer in `[0, size)`.
|
|
87
|
+
*/
|
|
88
|
+
update(index: number, update: (previous: T) => T): void;
|
|
89
|
+
/**
|
|
90
|
+
* Query the half-open range `[left, right)`.
|
|
91
|
+
*
|
|
92
|
+
* Canonical nodes are combined in index order, so the result is correct for
|
|
93
|
+
* non-commutative operations. An empty range returns `identity`.
|
|
94
|
+
*
|
|
95
|
+
* @throws RangeError unless `left` and `right` are safe integers satisfying
|
|
96
|
+
* `0 <= left <= right <= size`.
|
|
97
|
+
*/
|
|
98
|
+
query(left: number, right: number): T;
|
|
99
|
+
/**
|
|
100
|
+
* Query the whole stored range.
|
|
101
|
+
*
|
|
102
|
+
* This is O(1): the tree root already combines the leaves in order. It
|
|
103
|
+
* returns `identity` when the tree is empty.
|
|
104
|
+
*/
|
|
105
|
+
queryAll(): T;
|
|
106
|
+
/**
|
|
107
|
+
* Return a fresh array of leaf values in index order.
|
|
108
|
+
*/
|
|
109
|
+
toArray(): T[];
|
|
110
|
+
/**
|
|
111
|
+
* Reset every leaf to `identity`.
|
|
112
|
+
*
|
|
113
|
+
* All tree nodes are overwritten directly, so this is O(n) total rather than
|
|
114
|
+
* performing a separate rebuild path for each leaf.
|
|
115
|
+
*/
|
|
116
|
+
clear(): void;
|
|
117
|
+
/**
|
|
118
|
+
* Recombine the root path after a leaf write.
|
|
119
|
+
*/
|
|
120
|
+
private rebuild;
|
|
121
|
+
/**
|
|
122
|
+
* Validate a single-leaf index.
|
|
123
|
+
*/
|
|
124
|
+
private assertIndex;
|
|
125
|
+
/**
|
|
126
|
+
* Validate a half-open query range.
|
|
127
|
+
*/
|
|
128
|
+
private assertRange;
|
|
129
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iterative segment tree over an associative monoid.
|
|
3
|
+
*
|
|
4
|
+
* The class owns a power-of-two padded tree: every real leaf holds one value,
|
|
5
|
+
* padding leaves hold the identity, and every internal node combines its two
|
|
6
|
+
* children. Point updates rebuild the root path in O(log n); half-open range
|
|
7
|
+
* queries combine O(log n) canonical nodes while preserving left-to-right
|
|
8
|
+
* order, so non-commutative operations such as string concatenation work.
|
|
9
|
+
*
|
|
10
|
+
* Lazy range updates are deliberately not supported. Empty ranges return the
|
|
11
|
+
* identity, and `size: 0` is valid: the tree has no leaves but still answers
|
|
12
|
+
* empty queries and `queryAll()` with that identity.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* A segment tree for an associative monoid.
|
|
16
|
+
*
|
|
17
|
+
* Values are stored by reference; the tree never clones them. The operation
|
|
18
|
+
* must be associative, and `identity` must be neutral for it. Commutativity is
|
|
19
|
+
* not required: range queries combine canonical nodes in index order.
|
|
20
|
+
*
|
|
21
|
+
* @typeParam T - Leaf value type.
|
|
22
|
+
*/
|
|
23
|
+
export class SegmentTree {
|
|
24
|
+
operation;
|
|
25
|
+
identity;
|
|
26
|
+
count;
|
|
27
|
+
base;
|
|
28
|
+
tree;
|
|
29
|
+
/**
|
|
30
|
+
* Build a tree with `options.size` leaves.
|
|
31
|
+
*
|
|
32
|
+
* When `values` is omitted, every leaf starts as `identity`. When it is
|
|
33
|
+
* supplied, it is consumed once and must produce exactly `size` values.
|
|
34
|
+
*
|
|
35
|
+
* @param options - Size, operation, identity, and optional initial values.
|
|
36
|
+
* @throws RangeError if `size` is not a non-negative safe integer, or if
|
|
37
|
+
* `values` does not contain exactly `size` values.
|
|
38
|
+
* @throws TypeError if `operation` is not a function or `identity` is not
|
|
39
|
+
* supplied.
|
|
40
|
+
*/
|
|
41
|
+
constructor(options) {
|
|
42
|
+
const input = options;
|
|
43
|
+
if (input === null || typeof (input) !== "object") {
|
|
44
|
+
throw new TypeError("options must be an object");
|
|
45
|
+
}
|
|
46
|
+
if (!Number.isSafeInteger(input.size) || input.size < 0) {
|
|
47
|
+
throw new RangeError(`size must be a non-negative safe integer, received ${`${input.size}`}`);
|
|
48
|
+
}
|
|
49
|
+
if (typeof (input.operation) !== "function") {
|
|
50
|
+
throw new TypeError("operation must be a function");
|
|
51
|
+
}
|
|
52
|
+
if (!("identity" in input)) {
|
|
53
|
+
throw new TypeError("identity is required");
|
|
54
|
+
}
|
|
55
|
+
this.operation = input.operation;
|
|
56
|
+
this.identity = input.identity;
|
|
57
|
+
this.count = input.size;
|
|
58
|
+
let base = 1;
|
|
59
|
+
while (base < this.count) {
|
|
60
|
+
base *= 2;
|
|
61
|
+
}
|
|
62
|
+
this.base = base;
|
|
63
|
+
const tree = new Array(base * 2).fill(this.identity);
|
|
64
|
+
if (input.values !== (void 0)) {
|
|
65
|
+
let index = 0;
|
|
66
|
+
for (const value of input.values) {
|
|
67
|
+
if (index === this.count) {
|
|
68
|
+
throw new RangeError(`values must contain exactly ${this.count} values`);
|
|
69
|
+
}
|
|
70
|
+
tree[base + index] = value;
|
|
71
|
+
index += 1;
|
|
72
|
+
}
|
|
73
|
+
if (index !== this.count) {
|
|
74
|
+
throw new RangeError(`values must contain exactly ${this.count} values, received ${index}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
for (let node = base - 1; node >= 1; node -= 1) {
|
|
78
|
+
tree[node] = this.operation(tree[node * 2], tree[node * 2 + 1]);
|
|
79
|
+
}
|
|
80
|
+
this.tree = tree;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Number of real leaves.
|
|
84
|
+
*/
|
|
85
|
+
get size() {
|
|
86
|
+
return this.count;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Read the leaf at `index`.
|
|
90
|
+
*
|
|
91
|
+
* @throws RangeError if `index` is not a safe integer in `[0, size)`.
|
|
92
|
+
*/
|
|
93
|
+
get(index) {
|
|
94
|
+
this.assertIndex(index);
|
|
95
|
+
return this.tree[this.base + index];
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Replace the leaf at `index`.
|
|
99
|
+
*
|
|
100
|
+
* @throws RangeError if `index` is not a safe integer in `[0, size)`.
|
|
101
|
+
*/
|
|
102
|
+
set(index, value) {
|
|
103
|
+
this.assertIndex(index);
|
|
104
|
+
const leaf = this.base + index;
|
|
105
|
+
this.tree[leaf] = value;
|
|
106
|
+
this.rebuild(leaf);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Transform the leaf at `index` from its current value.
|
|
110
|
+
*
|
|
111
|
+
* `update` is called once with the previous leaf value. If it throws, the
|
|
112
|
+
* tree is left unchanged.
|
|
113
|
+
*
|
|
114
|
+
* @throws RangeError if `index` is not a safe integer in `[0, size)`.
|
|
115
|
+
*/
|
|
116
|
+
update(index, update) {
|
|
117
|
+
this.assertIndex(index);
|
|
118
|
+
const leaf = this.base + index;
|
|
119
|
+
const next = update(this.tree[leaf]);
|
|
120
|
+
this.tree[leaf] = next;
|
|
121
|
+
this.rebuild(leaf);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Query the half-open range `[left, right)`.
|
|
125
|
+
*
|
|
126
|
+
* Canonical nodes are combined in index order, so the result is correct for
|
|
127
|
+
* non-commutative operations. An empty range returns `identity`.
|
|
128
|
+
*
|
|
129
|
+
* @throws RangeError unless `left` and `right` are safe integers satisfying
|
|
130
|
+
* `0 <= left <= right <= size`.
|
|
131
|
+
*/
|
|
132
|
+
query(left, right) {
|
|
133
|
+
this.assertRange(left, right);
|
|
134
|
+
if (left === right) {
|
|
135
|
+
return this.identity;
|
|
136
|
+
}
|
|
137
|
+
let leftNode = this.base + left;
|
|
138
|
+
let rightNode = this.base + right;
|
|
139
|
+
let leftResult = this.identity;
|
|
140
|
+
let rightResult = this.identity;
|
|
141
|
+
while (leftNode < rightNode) {
|
|
142
|
+
if (leftNode % 2 === 1) {
|
|
143
|
+
leftResult = this.operation(leftResult, this.tree[leftNode]);
|
|
144
|
+
leftNode += 1;
|
|
145
|
+
}
|
|
146
|
+
if (rightNode % 2 === 1) {
|
|
147
|
+
rightNode -= 1;
|
|
148
|
+
rightResult = this.operation(this.tree[rightNode], rightResult);
|
|
149
|
+
}
|
|
150
|
+
leftNode = Math.floor(leftNode / 2);
|
|
151
|
+
rightNode = Math.floor(rightNode / 2);
|
|
152
|
+
}
|
|
153
|
+
return this.operation(leftResult, rightResult);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Query the whole stored range.
|
|
157
|
+
*
|
|
158
|
+
* This is O(1): the tree root already combines the leaves in order. It
|
|
159
|
+
* returns `identity` when the tree is empty.
|
|
160
|
+
*/
|
|
161
|
+
queryAll() {
|
|
162
|
+
return this.count === 0 ? this.identity : this.tree[1];
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Return a fresh array of leaf values in index order.
|
|
166
|
+
*/
|
|
167
|
+
toArray() {
|
|
168
|
+
return this.tree.slice(this.base, this.base + this.count);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Reset every leaf to `identity`.
|
|
172
|
+
*
|
|
173
|
+
* All tree nodes are overwritten directly, so this is O(n) total rather than
|
|
174
|
+
* performing a separate rebuild path for each leaf.
|
|
175
|
+
*/
|
|
176
|
+
clear() {
|
|
177
|
+
this.tree.fill(this.identity);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Recombine the root path after a leaf write.
|
|
181
|
+
*/
|
|
182
|
+
rebuild(leaf) {
|
|
183
|
+
let node = Math.floor(leaf / 2);
|
|
184
|
+
while (node >= 1) {
|
|
185
|
+
this.tree[node] = this.operation(this.tree[node * 2], this.tree[node * 2 + 1]);
|
|
186
|
+
node = Math.floor(node / 2);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Validate a single-leaf index.
|
|
191
|
+
*/
|
|
192
|
+
assertIndex(index) {
|
|
193
|
+
if (!Number.isSafeInteger(index) || index < 0 || index >= this.count) {
|
|
194
|
+
throw new RangeError(`index must be a safe integer in [0, ${this.count}), received ${`${index}`}`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Validate a half-open query range.
|
|
199
|
+
*/
|
|
200
|
+
assertRange(left, right) {
|
|
201
|
+
if (!Number.isSafeInteger(left) || !Number.isSafeInteger(right) || left < 0 || right > this.count || left > right) {
|
|
202
|
+
throw new RangeError(`query range must satisfy 0 <= left <= right <= ${this.count}, received [${`${left}`}, ${`${right}`})`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Array-backed last-in, first-out stack.
|
|
3
|
+
*
|
|
4
|
+
* The implementation keeps its values in a native array, so `push` and `pop`
|
|
5
|
+
* are O(1) amortized. Iteration visits the top first and works from a snapshot
|
|
6
|
+
* taken when the iterator is created, so the traversal is not disturbed by
|
|
7
|
+
* later pushes or pops.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* A last-in, first-out stack.
|
|
11
|
+
*
|
|
12
|
+
* `pop` and `peek` return `undefined` when the stack is empty rather than
|
|
13
|
+
* throwing. Since `undefined` is also a valid stored value, use {@link size} or
|
|
14
|
+
* {@link isEmpty} when presence must be distinguished from absence.
|
|
15
|
+
*
|
|
16
|
+
* Iteration is top-to-bottom.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const stack = new Stack([1, 2, 3]);
|
|
21
|
+
* stack.peek(); // 3
|
|
22
|
+
* stack.pop(); // 3
|
|
23
|
+
* [...stack]; // [2, 1]
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare class Stack<T> implements Iterable<T> {
|
|
27
|
+
private readonly items;
|
|
28
|
+
/**
|
|
29
|
+
* Create a stack, optionally seeded from `values`.
|
|
30
|
+
*
|
|
31
|
+
* Values are pushed in iteration order, so the last value becomes the top.
|
|
32
|
+
*
|
|
33
|
+
* @param values - Values to push, in order.
|
|
34
|
+
*/
|
|
35
|
+
constructor(values?: Iterable<T>);
|
|
36
|
+
/**
|
|
37
|
+
* Number of values currently on the stack.
|
|
38
|
+
*/
|
|
39
|
+
get size(): number;
|
|
40
|
+
/**
|
|
41
|
+
* Whether the stack contains no values.
|
|
42
|
+
*/
|
|
43
|
+
get isEmpty(): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Push a value onto the top.
|
|
46
|
+
*
|
|
47
|
+
* @param value - Value to push.
|
|
48
|
+
* @returns This stack, for chaining.
|
|
49
|
+
*/
|
|
50
|
+
push(value: T): this;
|
|
51
|
+
/**
|
|
52
|
+
* Remove and return the top value.
|
|
53
|
+
*
|
|
54
|
+
* @returns The former top value, or `undefined` if the stack is empty.
|
|
55
|
+
*/
|
|
56
|
+
pop(): T | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Return the top value without removing it.
|
|
59
|
+
*
|
|
60
|
+
* @returns The top value, or `undefined` if the stack is empty.
|
|
61
|
+
*/
|
|
62
|
+
peek(): T | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Remove every value.
|
|
65
|
+
*/
|
|
66
|
+
clear(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Snapshot the stack from top to bottom.
|
|
69
|
+
*
|
|
70
|
+
* @returns A new array whose first item is the top of the stack.
|
|
71
|
+
*/
|
|
72
|
+
toArray(): T[];
|
|
73
|
+
/**
|
|
74
|
+
* Iterate top to bottom over a snapshot taken when the iterator is created.
|
|
75
|
+
*/
|
|
76
|
+
[Symbol.iterator](): Generator<T, void, unknown>;
|
|
77
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Array-backed last-in, first-out stack.
|
|
3
|
+
*
|
|
4
|
+
* The implementation keeps its values in a native array, so `push` and `pop`
|
|
5
|
+
* are O(1) amortized. Iteration visits the top first and works from a snapshot
|
|
6
|
+
* taken when the iterator is created, so the traversal is not disturbed by
|
|
7
|
+
* later pushes or pops.
|
|
8
|
+
*/
|
|
9
|
+
import { generatorFrom } from "./iterator.js";
|
|
10
|
+
/**
|
|
11
|
+
* A last-in, first-out stack.
|
|
12
|
+
*
|
|
13
|
+
* `pop` and `peek` return `undefined` when the stack is empty rather than
|
|
14
|
+
* throwing. Since `undefined` is also a valid stored value, use {@link size} or
|
|
15
|
+
* {@link isEmpty} when presence must be distinguished from absence.
|
|
16
|
+
*
|
|
17
|
+
* Iteration is top-to-bottom.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const stack = new Stack([1, 2, 3]);
|
|
22
|
+
* stack.peek(); // 3
|
|
23
|
+
* stack.pop(); // 3
|
|
24
|
+
* [...stack]; // [2, 1]
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export class Stack {
|
|
28
|
+
items = [];
|
|
29
|
+
/**
|
|
30
|
+
* Create a stack, optionally seeded from `values`.
|
|
31
|
+
*
|
|
32
|
+
* Values are pushed in iteration order, so the last value becomes the top.
|
|
33
|
+
*
|
|
34
|
+
* @param values - Values to push, in order.
|
|
35
|
+
*/
|
|
36
|
+
constructor(values) {
|
|
37
|
+
if (values === (void 0)) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const initialValues = [...values];
|
|
41
|
+
for (let index = 0; index < initialValues.length; index += 1) {
|
|
42
|
+
const value = initialValues[index];
|
|
43
|
+
this.items.push(value);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Number of values currently on the stack.
|
|
48
|
+
*/
|
|
49
|
+
get size() {
|
|
50
|
+
return this.items.length;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Whether the stack contains no values.
|
|
54
|
+
*/
|
|
55
|
+
get isEmpty() {
|
|
56
|
+
return this.items.length === 0;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Push a value onto the top.
|
|
60
|
+
*
|
|
61
|
+
* @param value - Value to push.
|
|
62
|
+
* @returns This stack, for chaining.
|
|
63
|
+
*/
|
|
64
|
+
push(value) {
|
|
65
|
+
this.items.push(value);
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Remove and return the top value.
|
|
70
|
+
*
|
|
71
|
+
* @returns The former top value, or `undefined` if the stack is empty.
|
|
72
|
+
*/
|
|
73
|
+
pop() {
|
|
74
|
+
return this.items.pop();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Return the top value without removing it.
|
|
78
|
+
*
|
|
79
|
+
* @returns The top value, or `undefined` if the stack is empty.
|
|
80
|
+
*/
|
|
81
|
+
peek() {
|
|
82
|
+
if (this.items.length === 0) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
return this.items[this.items.length - 1];
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Remove every value.
|
|
89
|
+
*/
|
|
90
|
+
clear() {
|
|
91
|
+
this.items.length = 0;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Snapshot the stack from top to bottom.
|
|
95
|
+
*
|
|
96
|
+
* @returns A new array whose first item is the top of the stack.
|
|
97
|
+
*/
|
|
98
|
+
toArray() {
|
|
99
|
+
return this.items.slice().reverse();
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Iterate top to bottom over a snapshot taken when the iterator is created.
|
|
103
|
+
*/
|
|
104
|
+
[Symbol.iterator]() {
|
|
105
|
+
return generatorFrom(this.toArray());
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unordered hash set and map.
|
|
3
|
+
*
|
|
4
|
+
* Both containers are separate-chaining hash tables over a power-of-two bucket
|
|
5
|
+
* array, with a load factor of 0.75 and rehash-on-grow. The bucket index is
|
|
6
|
+
* taken from the low bits of a 64-bit hash from `./hash.ts`; collisions are
|
|
7
|
+
* walked as explicit chains and resolved with the equality strategy (never by
|
|
8
|
+
* hash equality alone). No insertion order is maintained: iteration order is
|
|
9
|
+
* unspecified bucket order and may change after a resize.
|
|
10
|
+
*
|
|
11
|
+
* Iteration is deliberately fail-fast: any structural mutation after an
|
|
12
|
+
* iterator is created (`add` of a new value, `set` of a new key, `delete`, or
|
|
13
|
+
* `clear`) makes the iterator throw on its next `next()` call, as does a
|
|
14
|
+
* rehash. Updating the value of an existing map key is not structural and does
|
|
15
|
+
* not invalidate iterators.
|
|
16
|
+
*/
|
|
17
|
+
import type { KeyStrategy } from "./hash.js";
|
|
18
|
+
/**
|
|
19
|
+
* An unordered set backed by a separate-chaining hash table.
|
|
20
|
+
*
|
|
21
|
+
* Average O(1) membership, explicit collision chains, power-of-two buckets, a
|
|
22
|
+
* 0.75 load factor, and rehash-on-grow. Iteration order is unspecified (bucket
|
|
23
|
+
* order) and may change after a resize. The public API mirrors
|
|
24
|
+
* `OrderedSet`, including custom {@link KeyStrategy} support.
|
|
25
|
+
*
|
|
26
|
+
* Iteration is fail-fast: a structural mutation (`add` of a new value,
|
|
27
|
+
* `delete`, `clear`, or an internal rehash caused by growth) after an iterator
|
|
28
|
+
* is obtained makes that iterator throw on its next step. Mutating the set
|
|
29
|
+
* during `forEach` therefore also throws once the callback returns and the
|
|
30
|
+
* loop advances.
|
|
31
|
+
*/
|
|
32
|
+
export declare class UnorderedSet<T> implements Iterable<T> {
|
|
33
|
+
private readonly table;
|
|
34
|
+
constructor(values?: Iterable<T>, options?: KeyStrategy<T>);
|
|
35
|
+
get size(): number;
|
|
36
|
+
clear(): void;
|
|
37
|
+
add(value: T): this;
|
|
38
|
+
has(value: T): boolean;
|
|
39
|
+
delete(value: T): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Alias of {@link UnorderedSet.values}.
|
|
42
|
+
*/
|
|
43
|
+
keys(): Generator<T>;
|
|
44
|
+
values(): Generator<T>;
|
|
45
|
+
entries(): Generator<[T, T]>;
|
|
46
|
+
[Symbol.iterator](): Generator<T>;
|
|
47
|
+
/**
|
|
48
|
+
* Call `callback` for each value; order is unspecified.
|
|
49
|
+
*
|
|
50
|
+
* The table generator is driven by hand so that the fail-fast version check
|
|
51
|
+
* keeps throwing between callback invocations, exactly as a `for…of` loop
|
|
52
|
+
* over `keys()` would.
|
|
53
|
+
*
|
|
54
|
+
* @param callback - Receives the value twice (matching the native `Set`
|
|
55
|
+
* shape) and the set itself.
|
|
56
|
+
* @param thisArg - Value used as `this` when invoking `callback`.
|
|
57
|
+
*/
|
|
58
|
+
forEach(callback: (value: T, value2: T, set: this) => void, thisArg?: unknown): void;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* An unordered map backed by a separate-chaining hash table.
|
|
62
|
+
*
|
|
63
|
+
* Average O(1) lookup, explicit collision chains, power-of-two buckets, a 0.75
|
|
64
|
+
* load factor, and rehash-on-grow. Iteration order is unspecified (bucket
|
|
65
|
+
* order) and may change after a resize. The public API mirrors `OrderedMap`,
|
|
66
|
+
* including custom {@link KeyStrategy} support. Membership is determined by
|
|
67
|
+
* {@link UnorderedMap.has}, so `undefined` is a perfectly valid value.
|
|
68
|
+
*
|
|
69
|
+
* Iteration is fail-fast: a structural mutation (`set` of a new key, `delete`,
|
|
70
|
+
* `clear`, or an internal rehash caused by growth) after an iterator is
|
|
71
|
+
* obtained makes that iterator throw on its next step; updating an existing
|
|
72
|
+
* key's value is allowed. Mutating the key set during `forEach` also throws
|
|
73
|
+
* once the callback returns and the loop advances.
|
|
74
|
+
*/
|
|
75
|
+
export declare class UnorderedMap<K, V> implements Iterable<[K, V]> {
|
|
76
|
+
private readonly table;
|
|
77
|
+
constructor(entries?: Iterable<readonly [K, V]>, options?: KeyStrategy<K>);
|
|
78
|
+
get size(): number;
|
|
79
|
+
clear(): void;
|
|
80
|
+
set(key: K, value: V): this;
|
|
81
|
+
get(key: K): V | undefined;
|
|
82
|
+
has(key: K): boolean;
|
|
83
|
+
delete(key: K): boolean;
|
|
84
|
+
keys(): Generator<K>;
|
|
85
|
+
values(): Generator<V>;
|
|
86
|
+
entries(): Generator<[K, V]>;
|
|
87
|
+
[Symbol.iterator](): Generator<[K, V]>;
|
|
88
|
+
/**
|
|
89
|
+
* Call `callback` for each entry; order is unspecified.
|
|
90
|
+
*
|
|
91
|
+
* The table generator is driven by hand so that the fail-fast version check
|
|
92
|
+
* keeps throwing between callback invocations, exactly as a `for…of` loop
|
|
93
|
+
* over `entries()` would.
|
|
94
|
+
*
|
|
95
|
+
* @param callback - Receives the value, the key, and the map itself.
|
|
96
|
+
* @param thisArg - Value used as `this` when invoking `callback`.
|
|
97
|
+
*/
|
|
98
|
+
forEach(callback: (value: V, key: K, map: this) => void, thisArg?: unknown): void;
|
|
99
|
+
}
|