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,400 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic, language-agnostic abstract syntax tree.
|
|
3
|
+
*
|
|
4
|
+
* This module is not a parser. It defines a plain node shape plus traversal,
|
|
5
|
+
* search, mapping, cloning, and structural comparison primitives that parsers
|
|
6
|
+
* and interpreters can build on. Node payloads are opaque values owned by the
|
|
7
|
+
* caller; the tree never inspects or clones them.
|
|
8
|
+
*
|
|
9
|
+
* Nodes and their `children` arrays are mutable by design. The class stores the
|
|
10
|
+
* supplied root by reference and performs no deep validation, so manually
|
|
11
|
+
* assembled nodes are accepted. The static {@link AbstractSyntaxTree.leaf} and
|
|
12
|
+
* {@link AbstractSyntaxTree.branch} helpers do enforce a non-empty `kind`.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Throw unless `kind` is a non-empty string.
|
|
16
|
+
*/
|
|
17
|
+
function assertKind(kind) {
|
|
18
|
+
if (typeof (kind) !== "string" || kind.length === 0) {
|
|
19
|
+
throw new TypeError("kind must be a non-empty string");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Build a plain node, omitting absent optional fields.
|
|
24
|
+
*/
|
|
25
|
+
function makeNode(kind, children, value, span) {
|
|
26
|
+
const node = { kind, children };
|
|
27
|
+
if (value !== (void 0)) {
|
|
28
|
+
node.value = value;
|
|
29
|
+
}
|
|
30
|
+
if (span !== (void 0)) {
|
|
31
|
+
node.span = span;
|
|
32
|
+
}
|
|
33
|
+
return node;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Copy a span into a fresh plain object.
|
|
37
|
+
*/
|
|
38
|
+
function copySpan(span) {
|
|
39
|
+
const copy = { start: span.start, end: span.end };
|
|
40
|
+
if ("source" in span) {
|
|
41
|
+
copy.source = span.source;
|
|
42
|
+
}
|
|
43
|
+
return copy;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Deep-copy nodes and spans, preserving value references.
|
|
47
|
+
*
|
|
48
|
+
* Iterative and memoized by node identity so tall trees do not consume the
|
|
49
|
+
* call stack and shared subtrees stay shared.
|
|
50
|
+
*/
|
|
51
|
+
function cloneNode(root) {
|
|
52
|
+
const copies = new WeakMap();
|
|
53
|
+
const originals = [];
|
|
54
|
+
const pending = [root];
|
|
55
|
+
while (pending.length > 0) {
|
|
56
|
+
const node = pending.pop();
|
|
57
|
+
if (node === (void 0) || copies.has(node)) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const copy = { kind: node.kind, children: [] };
|
|
61
|
+
if ("value" in node) {
|
|
62
|
+
copy.value = node.value;
|
|
63
|
+
}
|
|
64
|
+
if (node.span !== (void 0)) {
|
|
65
|
+
copy.span = copySpan(node.span);
|
|
66
|
+
}
|
|
67
|
+
copies.set(node, copy);
|
|
68
|
+
originals.push(node);
|
|
69
|
+
for (const child of node.children) {
|
|
70
|
+
pending.push(child);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
for (const node of originals) {
|
|
74
|
+
const copy = copies.get(node);
|
|
75
|
+
if (copy === (void 0)) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
for (const child of node.children) {
|
|
79
|
+
const childCopy = copies.get(child);
|
|
80
|
+
if (childCopy !== (void 0)) {
|
|
81
|
+
copy.children.push(childCopy);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const rootCopy = copies.get(root);
|
|
86
|
+
if (rootCopy === (void 0)) {
|
|
87
|
+
throw new Error("failed to clone the AST root");
|
|
88
|
+
}
|
|
89
|
+
return rootCopy;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Compare optional spans field by field, using SameValue semantics.
|
|
93
|
+
*/
|
|
94
|
+
function spansEqual(left, right) {
|
|
95
|
+
if (left === (void 0) || right === (void 0)) {
|
|
96
|
+
return left === right;
|
|
97
|
+
}
|
|
98
|
+
return Object.is(left.start, right.start) && Object.is(left.end, right.end) && Object.is(left.source, right.source);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* A mutable-rooted tree with non-mutating traversal and transformation helpers.
|
|
102
|
+
*
|
|
103
|
+
* The constructor accepts an arbitrary node value and stores it by reference.
|
|
104
|
+
* It does not inspect the subtree, so callers that build nodes manually are
|
|
105
|
+
* responsible for maintaining the {@link AstNode} shape.
|
|
106
|
+
*
|
|
107
|
+
* @typeParam T - Value payload stored on nodes.
|
|
108
|
+
*/
|
|
109
|
+
export class AbstractSyntaxTree {
|
|
110
|
+
rootNode;
|
|
111
|
+
/**
|
|
112
|
+
* Wrap an existing root node.
|
|
113
|
+
*
|
|
114
|
+
* @param root - Root node, stored by reference.
|
|
115
|
+
*/
|
|
116
|
+
constructor(root) {
|
|
117
|
+
this.rootNode = root;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Create a tree with one leaf node.
|
|
121
|
+
*
|
|
122
|
+
* @param kind - Non-empty node category.
|
|
123
|
+
* @param value - Optional leaf payload.
|
|
124
|
+
* @param span - Optional source extent.
|
|
125
|
+
* @throws TypeError if `kind` is not a non-empty string.
|
|
126
|
+
*/
|
|
127
|
+
static leaf(kind, value, span) {
|
|
128
|
+
assertKind(kind);
|
|
129
|
+
return new AbstractSyntaxTree(makeNode(kind, [], value, span));
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Create a tree with one branch node and the supplied children.
|
|
133
|
+
*
|
|
134
|
+
* The children iterable is copied into a new mutable array.
|
|
135
|
+
*
|
|
136
|
+
* @param kind - Non-empty node category.
|
|
137
|
+
* @param children - Direct children, in order.
|
|
138
|
+
* @param value - Optional branch payload.
|
|
139
|
+
* @param span - Optional source extent.
|
|
140
|
+
* @throws TypeError if `kind` is not a non-empty string.
|
|
141
|
+
*/
|
|
142
|
+
static branch(kind, children, value, span) {
|
|
143
|
+
assertKind(kind);
|
|
144
|
+
return new AbstractSyntaxTree(makeNode(kind, [...children], value, span));
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The stored root node, by reference.
|
|
148
|
+
*/
|
|
149
|
+
get root() {
|
|
150
|
+
return this.rootNode;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Total node count, recomputed on demand because children are mutable.
|
|
154
|
+
*/
|
|
155
|
+
get size() {
|
|
156
|
+
const iterator = this.walk();
|
|
157
|
+
let count = 0;
|
|
158
|
+
while (!iterator.next().done) {
|
|
159
|
+
count += 1;
|
|
160
|
+
}
|
|
161
|
+
return count;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Number of nodes on the longest root-to-leaf path; a leaf has height 1.
|
|
165
|
+
*/
|
|
166
|
+
get height() {
|
|
167
|
+
let maximum = 0;
|
|
168
|
+
const stack = [{ node: this.rootNode, depth: 1 }];
|
|
169
|
+
while (stack.length > 0) {
|
|
170
|
+
const frame = stack.pop();
|
|
171
|
+
if (frame === (void 0)) {
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
if (frame.depth > maximum) {
|
|
175
|
+
maximum = frame.depth;
|
|
176
|
+
}
|
|
177
|
+
for (const child of frame.node.children) {
|
|
178
|
+
stack.push({ node: child, depth: frame.depth + 1 });
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return maximum;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Number of nodes with no children.
|
|
185
|
+
*/
|
|
186
|
+
get leaves() {
|
|
187
|
+
let count = 0;
|
|
188
|
+
const stack = [this.rootNode];
|
|
189
|
+
while (stack.length > 0) {
|
|
190
|
+
const node = stack.pop();
|
|
191
|
+
if (node === (void 0)) {
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
if (node.children.length === 0) {
|
|
195
|
+
count += 1;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
for (const child of node.children) {
|
|
199
|
+
stack.push(child);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return count;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Walk the tree in the requested order.
|
|
207
|
+
*
|
|
208
|
+
* Preorder and postorder visit children left-to-right. Level order visits
|
|
209
|
+
* nodes breadth-first, also left-to-right within each level.
|
|
210
|
+
*
|
|
211
|
+
* @param order - Traversal order; defaults to `'preorder'`.
|
|
212
|
+
* @throws RangeError if `order` is not a supported traversal name.
|
|
213
|
+
*/
|
|
214
|
+
*walk(order = "preorder") {
|
|
215
|
+
switch (order) {
|
|
216
|
+
case "preorder": {
|
|
217
|
+
const stack = [this.rootNode];
|
|
218
|
+
while (stack.length > 0) {
|
|
219
|
+
const node = stack.pop();
|
|
220
|
+
if (node === (void 0)) {
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
yield node;
|
|
224
|
+
for (let index = node.children.length - 1; index >= 0; index -= 1) {
|
|
225
|
+
const child = node.children[index];
|
|
226
|
+
if (child !== (void 0)) {
|
|
227
|
+
stack.push(child);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
case "postorder": {
|
|
234
|
+
const stack = [{ node: this.rootNode, expanded: false }];
|
|
235
|
+
while (stack.length > 0) {
|
|
236
|
+
const frame = stack.pop();
|
|
237
|
+
if (frame === (void 0)) {
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
if (frame.expanded) {
|
|
241
|
+
yield frame.node;
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
stack.push({ node: frame.node, expanded: true });
|
|
245
|
+
for (let index = frame.node.children.length - 1; index >= 0; index -= 1) {
|
|
246
|
+
const child = frame.node.children[index];
|
|
247
|
+
if (child !== (void 0)) {
|
|
248
|
+
stack.push({ node: child, expanded: false });
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
case "levelorder": {
|
|
255
|
+
const queue = [this.rootNode];
|
|
256
|
+
let next = 0;
|
|
257
|
+
while (next < queue.length) {
|
|
258
|
+
const node = queue[next];
|
|
259
|
+
next += 1;
|
|
260
|
+
if (node === (void 0)) {
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
yield node;
|
|
264
|
+
for (const child of node.children) {
|
|
265
|
+
queue.push(child);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
default:
|
|
271
|
+
throw new RangeError(`unknown AST traversal order: ${`${order}`}`);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Return the first node in preorder that satisfies `predicate`.
|
|
276
|
+
*
|
|
277
|
+
* @param predicate - Test applied to each node.
|
|
278
|
+
*/
|
|
279
|
+
find(predicate) {
|
|
280
|
+
for (const node of this.walk("preorder")) {
|
|
281
|
+
if (predicate(node)) {
|
|
282
|
+
return node;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Return every node that satisfies `predicate`, in preorder.
|
|
289
|
+
*
|
|
290
|
+
* @param predicate - Test applied to each node.
|
|
291
|
+
*/
|
|
292
|
+
findAll(predicate) {
|
|
293
|
+
const matches = [];
|
|
294
|
+
for (const node of this.walk("preorder")) {
|
|
295
|
+
if (predicate(node)) {
|
|
296
|
+
matches.push(node);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return matches;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Transform every node bottom-up into a new tree.
|
|
303
|
+
*
|
|
304
|
+
* For each original node, `transform` receives that original node and its
|
|
305
|
+
* already mapped children, in order. The original tree is never modified.
|
|
306
|
+
*
|
|
307
|
+
* @param transform - Post-order mapping callback.
|
|
308
|
+
* @typeParam U - Value payload type of the mapped tree.
|
|
309
|
+
*/
|
|
310
|
+
map(transform) {
|
|
311
|
+
const mapped = new WeakMap();
|
|
312
|
+
const stack = [{ node: this.rootNode, nextChild: 0 }];
|
|
313
|
+
while (stack.length > 0) {
|
|
314
|
+
const frame = stack[stack.length - 1];
|
|
315
|
+
if (frame === (void 0)) {
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
if (frame.nextChild < frame.node.children.length) {
|
|
319
|
+
const child = frame.node.children[frame.nextChild];
|
|
320
|
+
frame.nextChild += 1;
|
|
321
|
+
stack.push({ node: child, nextChild: 0 });
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
const children = [];
|
|
325
|
+
for (const child of frame.node.children) {
|
|
326
|
+
const mappedChild = mapped.get(child);
|
|
327
|
+
if (mappedChild === (void 0)) {
|
|
328
|
+
throw new Error("cannot map an AST child before it has been visited");
|
|
329
|
+
}
|
|
330
|
+
children.push(mappedChild);
|
|
331
|
+
}
|
|
332
|
+
mapped.set(frame.node, transform(frame.node, children));
|
|
333
|
+
stack.pop();
|
|
334
|
+
}
|
|
335
|
+
const mappedRoot = mapped.get(this.rootNode);
|
|
336
|
+
if (mappedRoot === (void 0)) {
|
|
337
|
+
throw new Error("AST mapping produced no root");
|
|
338
|
+
}
|
|
339
|
+
return new AbstractSyntaxTree(mappedRoot);
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Deep-copy all nodes, child arrays, and spans.
|
|
343
|
+
*
|
|
344
|
+
* Payload values are copied by reference.
|
|
345
|
+
*/
|
|
346
|
+
clone() {
|
|
347
|
+
return new AbstractSyntaxTree(cloneNode(this.rootNode));
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Compare kinds, values (`Object.is`), spans, and ordered children.
|
|
351
|
+
*
|
|
352
|
+
* @param other - Tree to compare against.
|
|
353
|
+
*/
|
|
354
|
+
equals(other) {
|
|
355
|
+
const stack = [[this.rootNode, other.rootNode]];
|
|
356
|
+
while (stack.length > 0) {
|
|
357
|
+
const pair = stack.pop();
|
|
358
|
+
if (pair === (void 0)) {
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
const [left, right] = pair;
|
|
362
|
+
if (left.kind !== right.kind) {
|
|
363
|
+
return false;
|
|
364
|
+
}
|
|
365
|
+
if (!Object.is(left.value, right.value)) {
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
if (!spansEqual(left.span, right.span)) {
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
if (left.children.length !== right.children.length) {
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
for (let index = 0; index < left.children.length; index += 1) {
|
|
375
|
+
const leftChild = left.children[index];
|
|
376
|
+
const rightChild = right.children[index];
|
|
377
|
+
if (leftChild === (void 0) || rightChild === (void 0)) {
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
stack.push([leftChild, rightChild]);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Return a plain deep clone suitable for serialization.
|
|
387
|
+
*
|
|
388
|
+
* Node and span objects are freshly allocated and contain no class
|
|
389
|
+
* instances. Payload values are copied by reference, as with `clone()`.
|
|
390
|
+
*/
|
|
391
|
+
toJSON() {
|
|
392
|
+
return cloneNode(this.rootNode);
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Iterate in preorder; equivalent to `walk('preorder')`.
|
|
396
|
+
*/
|
|
397
|
+
[Symbol.iterator]() {
|
|
398
|
+
return this.walk("preorder");
|
|
399
|
+
}
|
|
400
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Height-balanced AVL search tree.
|
|
3
|
+
*
|
|
4
|
+
* Every node stores its subtree height, and each insertion or deletion walks
|
|
5
|
+
* back up the affected path applying LL/RR/LR/RL rotations until every balance
|
|
6
|
+
* factor is in `[-1, 1]`. The tree therefore keeps its height O(log n) even for
|
|
7
|
+
* sorted insertion sequences, and `insert`, `has`, `delete`, `min`, `max`,
|
|
8
|
+
* `floor` and `ceil` are O(log n) worst case.
|
|
9
|
+
*/
|
|
10
|
+
import type { TreeOptions } from "./binarySearchTree.js";
|
|
11
|
+
export type { TreeOptions };
|
|
12
|
+
/**
|
|
13
|
+
* A self-balancing AVL binary search tree.
|
|
14
|
+
*
|
|
15
|
+
* Duplicate values (comparator result 0) are rejected. The stored
|
|
16
|
+
* representative is never replaced by an equivalent insert; deleting with an
|
|
17
|
+
* equivalent value removes the stored representative.
|
|
18
|
+
*/
|
|
19
|
+
export declare class AVLTree<T> implements Iterable<T> {
|
|
20
|
+
private rootNode;
|
|
21
|
+
private count;
|
|
22
|
+
private readonly compare;
|
|
23
|
+
/**
|
|
24
|
+
* Create an empty AVL tree.
|
|
25
|
+
*
|
|
26
|
+
* @param options - Comparator override; defaults to natural ordering.
|
|
27
|
+
*/
|
|
28
|
+
constructor(options?: TreeOptions<T>);
|
|
29
|
+
/**
|
|
30
|
+
* Number of stored values.
|
|
31
|
+
*/
|
|
32
|
+
get size(): number;
|
|
33
|
+
/**
|
|
34
|
+
* Height of the tree in nodes: 0 when empty, 1 for a leaf.
|
|
35
|
+
*/
|
|
36
|
+
get height(): number;
|
|
37
|
+
/**
|
|
38
|
+
* Whether the tree contains no values.
|
|
39
|
+
*/
|
|
40
|
+
get isEmpty(): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Insert a value unless an equivalent one is already stored.
|
|
43
|
+
*
|
|
44
|
+
* @param value - Value to insert.
|
|
45
|
+
* @returns `true` if a node was added, `false` for an equivalent duplicate.
|
|
46
|
+
*/
|
|
47
|
+
insert(value: T): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Test whether an equivalent value is stored.
|
|
50
|
+
*
|
|
51
|
+
* @param value - Value to look up.
|
|
52
|
+
*/
|
|
53
|
+
has(value: T): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Delete the value equivalent to `value` and rebalance the path to the root.
|
|
56
|
+
*
|
|
57
|
+
* A two-child node is replaced by its in-order successor. Rotation is applied
|
|
58
|
+
* on every ancestor whose balance factor leaves `[-1, 1]`.
|
|
59
|
+
*
|
|
60
|
+
* @param value - Value to remove.
|
|
61
|
+
* @returns `true` if a value was removed, `false` when none is equivalent.
|
|
62
|
+
*/
|
|
63
|
+
delete(value: T): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Minimum stored value according to the comparator, or `undefined` when
|
|
66
|
+
* empty.
|
|
67
|
+
*/
|
|
68
|
+
min(): T | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Maximum stored value according to the comparator, or `undefined` when
|
|
71
|
+
* empty.
|
|
72
|
+
*/
|
|
73
|
+
max(): T | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Greatest stored value that is less than or equal to `value` in comparator
|
|
76
|
+
* order, or `undefined` when there is none.
|
|
77
|
+
*/
|
|
78
|
+
floor(value: T): T | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Least stored value that is greater than or equal to `value` in comparator
|
|
81
|
+
* order, or `undefined` when there is none.
|
|
82
|
+
*/
|
|
83
|
+
ceil(value: T): T | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Remove every value and reset the height to 0.
|
|
86
|
+
*/
|
|
87
|
+
clear(): void;
|
|
88
|
+
/**
|
|
89
|
+
* Collect values in ascending comparator order.
|
|
90
|
+
*/
|
|
91
|
+
toArray(): T[];
|
|
92
|
+
/**
|
|
93
|
+
* Iterate values in ascending comparator order.
|
|
94
|
+
*
|
|
95
|
+
* Mutating the tree while iterating is not supported.
|
|
96
|
+
*/
|
|
97
|
+
[Symbol.iterator](): Generator<T>;
|
|
98
|
+
/**
|
|
99
|
+
* Check the tree's invariants.
|
|
100
|
+
*
|
|
101
|
+
* Verifies strict in-order ordering, the maintained size, every node's stored
|
|
102
|
+
* height against the actual subtree height, and the AVL balance condition
|
|
103
|
+
* `|balanceFactor| <= 1`. An empty array means the tree is valid.
|
|
104
|
+
*/
|
|
105
|
+
validate(): string[];
|
|
106
|
+
private insertNode;
|
|
107
|
+
private deleteNode;
|
|
108
|
+
/**
|
|
109
|
+
* Recompute this node's height and repair its subtree with rotations.
|
|
110
|
+
*/
|
|
111
|
+
private rebalance;
|
|
112
|
+
/**
|
|
113
|
+
* Right rotation; returns the new subtree root.
|
|
114
|
+
*/
|
|
115
|
+
private rotateRight;
|
|
116
|
+
/**
|
|
117
|
+
* Left rotation; returns the new subtree root.
|
|
118
|
+
*/
|
|
119
|
+
private rotateLeft;
|
|
120
|
+
private updateHeight;
|
|
121
|
+
private balanceFactor;
|
|
122
|
+
private static heightOf;
|
|
123
|
+
private static minimumNode;
|
|
124
|
+
private inorderValues;
|
|
125
|
+
}
|