worldvm 0.0.0-stage → 0.1.0
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/AUTHORING.md +833 -0
- package/README.md +154 -2
- package/bin/worldvm.mjs +3 -0
- package/dist/_internal/forma/index.d.ts +1 -0
- package/dist/_internal/forma/index.js +1 -0
- package/dist/_internal/forma/world/authoring-help.d.ts +25 -0
- package/dist/_internal/forma/world/authoring-help.js +130 -0
- package/dist/_internal/forma/world/citations.d.ts +3 -0
- package/dist/_internal/forma/world/citations.js +26 -0
- package/dist/_internal/forma/world/clock-bindings.d.ts +4 -0
- package/dist/_internal/forma/world/clock-bindings.js +45 -0
- package/dist/_internal/forma/world/compile.d.ts +13 -0
- package/dist/_internal/forma/world/compile.js +190 -0
- package/dist/_internal/forma/world/coverage.d.ts +10 -0
- package/dist/_internal/forma/world/coverage.js +242 -0
- package/dist/_internal/forma/world/digest.d.ts +1 -0
- package/dist/_internal/forma/world/digest.js +1 -0
- package/dist/_internal/forma/world/documentation.d.ts +3 -0
- package/dist/_internal/forma/world/documentation.js +38 -0
- package/dist/_internal/forma/world/homes.d.ts +4 -0
- package/dist/_internal/forma/world/homes.js +202 -0
- package/dist/_internal/forma/world/index.d.ts +6 -0
- package/dist/_internal/forma/world/index.js +5 -0
- package/dist/_internal/forma/world/lowering/accounts.d.ts +4 -0
- package/dist/_internal/forma/world/lowering/accounts.js +36 -0
- package/dist/_internal/forma/world/lowering/action-policy.d.ts +5 -0
- package/dist/_internal/forma/world/lowering/action-policy.js +16 -0
- package/dist/_internal/forma/world/lowering/agents.d.ts +6 -0
- package/dist/_internal/forma/world/lowering/agents.js +116 -0
- package/dist/_internal/forma/world/lowering/bundles.d.ts +3 -0
- package/dist/_internal/forma/world/lowering/bundles.js +13 -0
- package/dist/_internal/forma/world/lowering/child-parameters.d.ts +14 -0
- package/dist/_internal/forma/world/lowering/child-parameters.js +36 -0
- package/dist/_internal/forma/world/lowering/collects.d.ts +3 -0
- package/dist/_internal/forma/world/lowering/collects.js +51 -0
- package/dist/_internal/forma/world/lowering/component-operations.d.ts +6 -0
- package/dist/_internal/forma/world/lowering/component-operations.js +26 -0
- package/dist/_internal/forma/world/lowering/components.d.ts +7 -0
- package/dist/_internal/forma/world/lowering/components.js +236 -0
- package/dist/_internal/forma/world/lowering/connectors.d.ts +4 -0
- package/dist/_internal/forma/world/lowering/connectors.js +31 -0
- package/dist/_internal/forma/world/lowering/context.d.ts +80 -0
- package/dist/_internal/forma/world/lowering/context.js +316 -0
- package/dist/_internal/forma/world/lowering/contracts.d.ts +7 -0
- package/dist/_internal/forma/world/lowering/contracts.js +73 -0
- package/dist/_internal/forma/world/lowering/decisions.d.ts +3 -0
- package/dist/_internal/forma/world/lowering/decisions.js +164 -0
- package/dist/_internal/forma/world/lowering/derives.d.ts +3 -0
- package/dist/_internal/forma/world/lowering/derives.js +22 -0
- package/dist/_internal/forma/world/lowering/discretionary.d.ts +7 -0
- package/dist/_internal/forma/world/lowering/discretionary.js +15 -0
- package/dist/_internal/forma/world/lowering/documents.d.ts +3 -0
- package/dist/_internal/forma/world/lowering/documents.js +68 -0
- package/dist/_internal/forma/world/lowering/effective.d.ts +5 -0
- package/dist/_internal/forma/world/lowering/effective.js +26 -0
- package/dist/_internal/forma/world/lowering/entities.d.ts +3 -0
- package/dist/_internal/forma/world/lowering/entities.js +43 -0
- package/dist/_internal/forma/world/lowering/escalations.d.ts +6 -0
- package/dist/_internal/forma/world/lowering/escalations.js +31 -0
- package/dist/_internal/forma/world/lowering/evidence.d.ts +3 -0
- package/dist/_internal/forma/world/lowering/evidence.js +75 -0
- package/dist/_internal/forma/world/lowering/files.d.ts +4 -0
- package/dist/_internal/forma/world/lowering/files.js +56 -0
- package/dist/_internal/forma/world/lowering/holds.d.ts +6 -0
- package/dist/_internal/forma/world/lowering/holds.js +35 -0
- package/dist/_internal/forma/world/lowering/index.d.ts +89 -0
- package/dist/_internal/forma/world/lowering/index.js +115 -0
- package/dist/_internal/forma/world/lowering/interactions.d.ts +7 -0
- package/dist/_internal/forma/world/lowering/interactions.js +190 -0
- package/dist/_internal/forma/world/lowering/library.d.ts +5 -0
- package/dist/_internal/forma/world/lowering/library.js +41 -0
- package/dist/_internal/forma/world/lowering/milestones.d.ts +6 -0
- package/dist/_internal/forma/world/lowering/milestones.js +17 -0
- package/dist/_internal/forma/world/lowering/notices.d.ts +3 -0
- package/dist/_internal/forma/world/lowering/notices.js +33 -0
- package/dist/_internal/forma/world/lowering/param-bounds.d.ts +15 -0
- package/dist/_internal/forma/world/lowering/param-bounds.js +71 -0
- package/dist/_internal/forma/world/lowering/policies.d.ts +6 -0
- package/dist/_internal/forma/world/lowering/policies.js +95 -0
- package/dist/_internal/forma/world/lowering/principals.d.ts +62 -0
- package/dist/_internal/forma/world/lowering/principals.js +32 -0
- package/dist/_internal/forma/world/lowering/recurrences.d.ts +9 -0
- package/dist/_internal/forma/world/lowering/recurrences.js +56 -0
- package/dist/_internal/forma/world/lowering/renewal.d.ts +5 -0
- package/dist/_internal/forma/world/lowering/renewal.js +21 -0
- package/dist/_internal/forma/world/lowering/resources.d.ts +6 -0
- package/dist/_internal/forma/world/lowering/resources.js +19 -0
- package/dist/_internal/forma/world/lowering/reuse.d.ts +5 -0
- package/dist/_internal/forma/world/lowering/reuse.js +75 -0
- package/dist/_internal/forma/world/lowering/sources.d.ts +10 -0
- package/dist/_internal/forma/world/lowering/sources.js +47 -0
- package/dist/_internal/forma/world/lowering/syntax.d.ts +84 -0
- package/dist/_internal/forma/world/lowering/syntax.js +94 -0
- package/dist/_internal/forma/world/lowering/vaults.d.ts +11 -0
- package/dist/_internal/forma/world/lowering/vaults.js +148 -0
- package/dist/_internal/forma/world/prelude.generated.d.ts +1 -0
- package/dist/_internal/forma/world/prelude.generated.js +2 -0
- package/dist/_internal/forma/world/properties.d.ts +9 -0
- package/dist/_internal/forma/world/properties.js +387 -0
- package/dist/_internal/forma/world/scenarios.d.ts +10 -0
- package/dist/_internal/forma/world/scenarios.js +757 -0
- package/dist/_internal/forma/world/sensitivity.d.ts +3 -0
- package/dist/_internal/forma/world/sensitivity.js +118 -0
- package/dist/_internal/forma/world/source-syntax.d.ts +6 -0
- package/dist/_internal/forma/world/source-syntax.js +27 -0
- package/dist/_internal/forma/world/status-handling.d.ts +3 -0
- package/dist/_internal/forma/world/status-handling.js +143 -0
- package/dist/_internal/forma/world/surface.d.ts +30 -0
- package/dist/_internal/forma/world/surface.js +213 -0
- package/dist/_internal/forma/world/table-expressions.d.ts +3 -0
- package/dist/_internal/forma/world/table-expressions.js +41 -0
- package/dist/_internal/forma-tools/index.d.ts +17 -0
- package/dist/_internal/forma-tools/index.js +124 -0
- package/dist/_internal/ir-checks/advances.d.ts +7 -0
- package/dist/_internal/ir-checks/advances.js +6 -0
- package/dist/_internal/ir-checks/agent-reads.d.ts +14 -0
- package/dist/_internal/ir-checks/agent-reads.js +118 -0
- package/dist/_internal/ir-checks/amendments.d.ts +3 -0
- package/dist/_internal/ir-checks/amendments.js +21 -0
- package/dist/_internal/ir-checks/canonical-json.d.ts +3 -0
- package/dist/_internal/ir-checks/canonical-json.js +85 -0
- package/dist/_internal/ir-checks/child-parameters.d.ts +2 -0
- package/dist/_internal/ir-checks/child-parameters.js +43 -0
- package/dist/_internal/ir-checks/clock-bindings.d.ts +3 -0
- package/dist/_internal/ir-checks/clock-bindings.js +43 -0
- package/dist/_internal/ir-checks/collect-types.d.ts +14 -0
- package/dist/_internal/ir-checks/collect-types.js +34 -0
- package/dist/_internal/ir-checks/component-operations.d.ts +4 -0
- package/dist/_internal/ir-checks/component-operations.js +23 -0
- package/dist/_internal/ir-checks/content-digest.d.ts +4 -0
- package/dist/_internal/ir-checks/content-digest.js +78 -0
- package/dist/_internal/ir-checks/contract-validation.d.ts +3 -0
- package/dist/_internal/ir-checks/contract-validation.js +307 -0
- package/dist/_internal/ir-checks/contracts.d.ts +25 -0
- package/dist/_internal/ir-checks/contracts.js +80 -0
- package/dist/_internal/ir-checks/dates.d.ts +2 -0
- package/dist/_internal/ir-checks/dates.js +7 -0
- package/dist/_internal/ir-checks/documents.d.ts +3 -0
- package/dist/_internal/ir-checks/documents.js +45 -0
- package/dist/_internal/ir-checks/evidence.d.ts +20 -0
- package/dist/_internal/ir-checks/evidence.js +56 -0
- package/dist/_internal/ir-checks/files.d.ts +7 -0
- package/dist/_internal/ir-checks/files.js +47 -0
- package/dist/_internal/ir-checks/index.d.ts +59 -0
- package/dist/_internal/ir-checks/index.js +166 -0
- package/dist/_internal/ir-checks/instants.d.ts +7 -0
- package/dist/_internal/ir-checks/instants.js +61 -0
- package/dist/_internal/ir-checks/notices.d.ts +4 -0
- package/dist/_internal/ir-checks/notices.js +58 -0
- package/dist/_internal/ir-checks/policy-bounds.d.ts +5 -0
- package/dist/_internal/ir-checks/policy-bounds.js +28 -0
- package/dist/_internal/ir-checks/principals.d.ts +26 -0
- package/dist/_internal/ir-checks/principals.js +162 -0
- package/dist/_internal/ir-checks/prior-cycle.d.ts +41 -0
- package/dist/_internal/ir-checks/prior-cycle.js +21 -0
- package/dist/_internal/ir-checks/read-classification.d.ts +12 -0
- package/dist/_internal/ir-checks/read-classification.js +67 -0
- package/dist/_internal/ir-checks/read-types.d.ts +2 -0
- package/dist/_internal/ir-checks/read-types.js +40 -0
- package/dist/_internal/ir-checks/resource-proofs.d.ts +4 -0
- package/dist/_internal/ir-checks/resource-proofs.js +98 -0
- package/dist/_internal/ir-checks/resources.d.ts +3 -0
- package/dist/_internal/ir-checks/resources.js +30 -0
- package/dist/_internal/ir-checks/reuse.d.ts +10 -0
- package/dist/_internal/ir-checks/reuse.js +99 -0
- package/dist/_internal/ir-checks/sealing.d.ts +14 -0
- package/dist/_internal/ir-checks/sealing.js +123 -0
- package/dist/_internal/ir-checks/sensitive-flow.d.ts +4 -0
- package/dist/_internal/ir-checks/sensitive-flow.js +240 -0
- package/dist/_internal/ir-checks/sensitivity.d.ts +19 -0
- package/dist/_internal/ir-checks/sensitivity.js +133 -0
- package/dist/_internal/ir-checks/signatures.d.ts +4 -0
- package/dist/_internal/ir-checks/signatures.js +22 -0
- package/dist/_internal/ir-checks/vaults.d.ts +10 -0
- package/dist/_internal/ir-checks/vaults.js +140 -0
- package/dist/_internal/protocol/index.d.ts +1234 -0
- package/dist/_internal/protocol/index.js +215 -0
- package/dist/_internal/reconciler/action-intents.d.ts +17 -0
- package/dist/_internal/reconciler/action-intents.js +161 -0
- package/dist/_internal/reconciler/actions.d.ts +7 -0
- package/dist/_internal/reconciler/actions.js +134 -0
- package/dist/_internal/reconciler/amendments.d.ts +12 -0
- package/dist/_internal/reconciler/amendments.js +52 -0
- package/dist/_internal/reconciler/basis.d.ts +253 -0
- package/dist/_internal/reconciler/basis.js +16 -0
- package/dist/_internal/reconciler/bundles.d.ts +22 -0
- package/dist/_internal/reconciler/bundles.js +110 -0
- package/dist/_internal/reconciler/change-detection.d.ts +5 -0
- package/dist/_internal/reconciler/change-detection.js +82 -0
- package/dist/_internal/reconciler/collection-rules.d.ts +7 -0
- package/dist/_internal/reconciler/collection-rules.js +46 -0
- package/dist/_internal/reconciler/collection-state.d.ts +11 -0
- package/dist/_internal/reconciler/collection-state.js +62 -0
- package/dist/_internal/reconciler/collection-values.d.ts +5 -0
- package/dist/_internal/reconciler/collection-values.js +60 -0
- package/dist/_internal/reconciler/collections.d.ts +35 -0
- package/dist/_internal/reconciler/collections.js +141 -0
- package/dist/_internal/reconciler/commands.d.ts +60 -0
- package/dist/_internal/reconciler/commands.js +468 -0
- package/dist/_internal/reconciler/component-operations.d.ts +48 -0
- package/dist/_internal/reconciler/component-operations.js +256 -0
- package/dist/_internal/reconciler/context.d.ts +38 -0
- package/dist/_internal/reconciler/context.js +44 -0
- package/dist/_internal/reconciler/coverage.d.ts +31 -0
- package/dist/_internal/reconciler/coverage.js +124 -0
- package/dist/_internal/reconciler/dates.d.ts +38 -0
- package/dist/_internal/reconciler/dates.js +121 -0
- package/dist/_internal/reconciler/decide.d.ts +25 -0
- package/dist/_internal/reconciler/decide.js +263 -0
- package/dist/_internal/reconciler/decision-evaluation.d.ts +9 -0
- package/dist/_internal/reconciler/decision-evaluation.js +67 -0
- package/dist/_internal/reconciler/decision-records.d.ts +14 -0
- package/dist/_internal/reconciler/decision-records.js +77 -0
- package/dist/_internal/reconciler/decision-release.d.ts +3 -0
- package/dist/_internal/reconciler/decision-release.js +12 -0
- package/dist/_internal/reconciler/dependencies.d.ts +179 -0
- package/dist/_internal/reconciler/dependencies.js +372 -0
- package/dist/_internal/reconciler/discovery.d.ts +9 -0
- package/dist/_internal/reconciler/discovery.js +65 -0
- package/dist/_internal/reconciler/document-corrections.d.ts +18 -0
- package/dist/_internal/reconciler/document-corrections.js +59 -0
- package/dist/_internal/reconciler/documents.d.ts +26 -0
- package/dist/_internal/reconciler/documents.js +88 -0
- package/dist/_internal/reconciler/effective.d.ts +6 -0
- package/dist/_internal/reconciler/effective.js +17 -0
- package/dist/_internal/reconciler/escalations.d.ts +4 -0
- package/dist/_internal/reconciler/escalations.js +76 -0
- package/dist/_internal/reconciler/evaluation.d.ts +56 -0
- package/dist/_internal/reconciler/evaluation.js +704 -0
- package/dist/_internal/reconciler/evidence-authority.d.ts +6 -0
- package/dist/_internal/reconciler/evidence-authority.js +70 -0
- package/dist/_internal/reconciler/evidence-history.d.ts +5 -0
- package/dist/_internal/reconciler/evidence-history.js +22 -0
- package/dist/_internal/reconciler/evidence-validity.d.ts +17 -0
- package/dist/_internal/reconciler/evidence-validity.js +135 -0
- package/dist/_internal/reconciler/fact-validation.d.ts +5 -0
- package/dist/_internal/reconciler/fact-validation.js +49 -0
- package/dist/_internal/reconciler/files.d.ts +9 -0
- package/dist/_internal/reconciler/files.js +56 -0
- package/dist/_internal/reconciler/graph.d.ts +40 -0
- package/dist/_internal/reconciler/graph.js +298 -0
- package/dist/_internal/reconciler/holds.d.ts +6 -0
- package/dist/_internal/reconciler/holds.js +18 -0
- package/dist/_internal/reconciler/home-definitions.d.ts +11 -0
- package/dist/_internal/reconciler/home-definitions.js +25 -0
- package/dist/_internal/reconciler/homes.d.ts +6 -0
- package/dist/_internal/reconciler/homes.js +32 -0
- package/dist/_internal/reconciler/index.d.ts +42 -0
- package/dist/_internal/reconciler/index.js +58 -0
- package/dist/_internal/reconciler/instants.d.ts +17 -0
- package/dist/_internal/reconciler/instants.js +56 -0
- package/dist/_internal/reconciler/interaction-fields.d.ts +10 -0
- package/dist/_internal/reconciler/interaction-fields.js +30 -0
- package/dist/_internal/reconciler/invariants.d.ts +8 -0
- package/dist/_internal/reconciler/invariants.js +34 -0
- package/dist/_internal/reconciler/journal.d.ts +3 -0
- package/dist/_internal/reconciler/journal.js +4 -0
- package/dist/_internal/reconciler/linking.d.ts +10 -0
- package/dist/_internal/reconciler/linking.js +259 -0
- package/dist/_internal/reconciler/memory.d.ts +32 -0
- package/dist/_internal/reconciler/memory.js +190 -0
- package/dist/_internal/reconciler/milestones.d.ts +7 -0
- package/dist/_internal/reconciler/milestones.js +58 -0
- package/dist/_internal/reconciler/missing.d.ts +18 -0
- package/dist/_internal/reconciler/missing.js +79 -0
- package/dist/_internal/reconciler/model.d.ts +350 -0
- package/dist/_internal/reconciler/model.js +9 -0
- package/dist/_internal/reconciler/notices.d.ts +14 -0
- package/dist/_internal/reconciler/notices.js +80 -0
- package/dist/_internal/reconciler/occurrences.d.ts +3 -0
- package/dist/_internal/reconciler/occurrences.js +30 -0
- package/dist/_internal/reconciler/outputs.d.ts +12 -0
- package/dist/_internal/reconciler/outputs.js +132 -0
- package/dist/_internal/reconciler/parameters.d.ts +4 -0
- package/dist/_internal/reconciler/parameters.js +27 -0
- package/dist/_internal/reconciler/policies.d.ts +22 -0
- package/dist/_internal/reconciler/policies.js +94 -0
- package/dist/_internal/reconciler/policy-edits.d.ts +11 -0
- package/dist/_internal/reconciler/policy-edits.js +42 -0
- package/dist/_internal/reconciler/policy-linking.d.ts +4 -0
- package/dist/_internal/reconciler/policy-linking.js +104 -0
- package/dist/_internal/reconciler/principal-types.d.ts +2 -0
- package/dist/_internal/reconciler/principal-types.js +38 -0
- package/dist/_internal/reconciler/prior-decisions.d.ts +3 -0
- package/dist/_internal/reconciler/prior-decisions.js +34 -0
- package/dist/_internal/reconciler/projections.d.ts +4 -0
- package/dist/_internal/reconciler/projections.js +85 -0
- package/dist/_internal/reconciler/proofs.d.ts +9 -0
- package/dist/_internal/reconciler/proofs.js +24 -0
- package/dist/_internal/reconciler/properties.d.ts +25 -0
- package/dist/_internal/reconciler/properties.js +67 -0
- package/dist/_internal/reconciler/property-eval.d.ts +5 -0
- package/dist/_internal/reconciler/property-eval.js +101 -0
- package/dist/_internal/reconciler/property-generator.d.ts +9 -0
- package/dist/_internal/reconciler/property-generator.js +288 -0
- package/dist/_internal/reconciler/property-shrink.d.ts +14 -0
- package/dist/_internal/reconciler/property-shrink.js +183 -0
- package/dist/_internal/reconciler/provenance.d.ts +8 -0
- package/dist/_internal/reconciler/provenance.js +61 -0
- package/dist/_internal/reconciler/reconcile.d.ts +32 -0
- package/dist/_internal/reconciler/reconcile.js +164 -0
- package/dist/_internal/reconciler/recurrence.d.ts +9 -0
- package/dist/_internal/reconciler/recurrence.js +44 -0
- package/dist/_internal/reconciler/requirements.d.ts +5 -0
- package/dist/_internal/reconciler/requirements.js +331 -0
- package/dist/_internal/reconciler/resource-generation.d.ts +9 -0
- package/dist/_internal/reconciler/resource-generation.js +17 -0
- package/dist/_internal/reconciler/resource-scenarios.d.ts +26 -0
- package/dist/_internal/reconciler/resource-scenarios.js +78 -0
- package/dist/_internal/reconciler/resources.d.ts +24 -0
- package/dist/_internal/reconciler/resources.js +178 -0
- package/dist/_internal/reconciler/result-digest.d.ts +13 -0
- package/dist/_internal/reconciler/result-digest.js +66 -0
- package/dist/_internal/reconciler/reuse.d.ts +16 -0
- package/dist/_internal/reconciler/reuse.js +119 -0
- package/dist/_internal/reconciler/scenarios.d.ts +32 -0
- package/dist/_internal/reconciler/scenarios.js +442 -0
- package/dist/_internal/reconciler/scheduling.d.ts +9 -0
- package/dist/_internal/reconciler/scheduling.js +203 -0
- package/dist/_internal/reconciler/sha256.d.ts +1 -0
- package/dist/_internal/reconciler/sha256.js +1 -0
- package/dist/_internal/reconciler/signatures.d.ts +13 -0
- package/dist/_internal/reconciler/signatures.js +37 -0
- package/dist/_internal/reconciler/temporal.d.ts +10 -0
- package/dist/_internal/reconciler/temporal.js +46 -0
- package/dist/_internal/reconciler/upgrades.d.ts +6 -0
- package/dist/_internal/reconciler/upgrades.js +65 -0
- package/dist/_internal/reconciler/wire.d.ts +2 -0
- package/dist/_internal/reconciler/wire.js +5 -0
- package/dist/_internal/reconciler/work.d.ts +32 -0
- package/dist/_internal/reconciler/work.js +101 -0
- package/dist/_internal/world-ir/schema.generated.d.ts +180 -0
- package/dist/_internal/world-ir/schema.generated.js +1127 -0
- package/dist/_internal/world-ir/types.generated.d.ts +1011 -0
- package/dist/_internal/world-ir/types.generated.js +1 -0
- package/dist/authoring.d.ts +9 -0
- package/dist/authoring.js +10 -0
- package/dist/catalogue.d.ts +20 -0
- package/dist/catalogue.js +531 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +553 -0
- package/dist/codegen.d.ts +6 -0
- package/dist/codegen.js +89 -0
- package/dist/coverage.d.ts +60 -0
- package/dist/coverage.js +128 -0
- package/dist/deploy.d.ts +21 -0
- package/dist/deploy.js +72 -0
- package/dist/diagnostics.d.ts +9 -0
- package/dist/diagnostics.js +37 -0
- package/dist/diff.d.ts +17 -0
- package/dist/diff.js +19 -0
- package/dist/durable-object.d.ts +14 -0
- package/dist/durable-object.js +30 -0
- package/dist/explain.d.ts +113 -0
- package/dist/explain.js +225 -0
- package/dist/fixes.d.ts +4 -0
- package/dist/fixes.js +70 -0
- package/dist/fmt.d.ts +12 -0
- package/dist/fmt.js +39 -0
- package/dist/handle/open.d.ts +18 -0
- package/dist/handle/open.js +28 -0
- package/dist/handle/protocol.d.ts +12 -0
- package/dist/handle/protocol.js +96 -0
- package/dist/handle/store.d.ts +31 -0
- package/dist/handle/store.js +11 -0
- package/dist/handle/types.d.ts +37 -0
- package/dist/handle/types.js +1 -0
- package/dist/handle/world.d.ts +190 -0
- package/dist/handle/world.js +533 -0
- package/dist/http.d.ts +3 -0
- package/dist/http.js +72 -0
- package/dist/impact.d.ts +21 -0
- package/dist/impact.js +57 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +43 -0
- package/dist/init.d.ts +13 -0
- package/dist/init.js +99 -0
- package/dist/ir-schema.json +4213 -0
- package/dist/lints.d.ts +8 -0
- package/dist/lints.js +154 -0
- package/dist/lsp.d.ts +14 -0
- package/dist/lsp.js +380 -0
- package/dist/manual/catalog.d.ts +12 -0
- package/dist/manual/catalog.js +23 -0
- package/dist/manual/examples.d.ts +15 -0
- package/dist/manual/examples.js +39 -0
- package/dist/manual/projections.d.ts +77 -0
- package/dist/manual/projections.js +344 -0
- package/dist/manual/prose.d.ts +19 -0
- package/dist/manual/prose.js +215 -0
- package/dist/manual/render.d.ts +76 -0
- package/dist/manual/render.js +250 -0
- package/dist/manual/text.d.ts +7 -0
- package/dist/manual/text.js +15 -0
- package/dist/mcp.d.ts +32 -0
- package/dist/mcp.js +269 -0
- package/dist/mutate.d.ts +36 -0
- package/dist/mutate.js +123 -0
- package/dist/project.d.ts +26 -0
- package/dist/project.js +80 -0
- package/dist/refine.d.ts +18 -0
- package/dist/refine.js +197 -0
- package/dist/release/diff.d.ts +45 -0
- package/dist/release/diff.js +103 -0
- package/dist/release/impact.d.ts +83 -0
- package/dist/release/impact.js +214 -0
- package/dist/release/nodes.d.ts +20 -0
- package/dist/release/nodes.js +118 -0
- package/dist/render.d.ts +19 -0
- package/dist/render.js +43 -0
- package/dist/serve.d.ts +18 -0
- package/dist/serve.js +140 -0
- package/dist/snapshot.d.ts +19 -0
- package/dist/snapshot.js +45 -0
- package/dist/sqlite.d.ts +16 -0
- package/dist/sqlite.js +151 -0
- package/dist/test.d.ts +54 -0
- package/dist/test.js +131 -0
- package/dist/world.d.ts +7 -0
- package/dist/world.js +5 -0
- package/docs/authoring/vendor-risk/example.forma +11 -0
- package/docs/authoring/vendor-risk/library/vendor.forma +76 -0
- package/docs/authoring/vendor-risk/scenarios/reviews.forma +107 -0
- package/docs/protocol.md +195 -0
- package/docs/reference.md +258 -0
- package/package.json +81 -3
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
import * as K from "../_internal/reconciler/index.js";
|
|
2
|
+
import { explainReconciliation } from "../explain.js";
|
|
3
|
+
import { memory } from "./store.js";
|
|
4
|
+
import { operate } from "./protocol.js";
|
|
5
|
+
export class WorldError extends Error {
|
|
6
|
+
code;
|
|
7
|
+
details;
|
|
8
|
+
constructor(code, message, details = []) {
|
|
9
|
+
super(`${code}: ${message}`);
|
|
10
|
+
this.code = code;
|
|
11
|
+
this.details = details;
|
|
12
|
+
this.name = "WorldError";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const actor = (input) => typeof input === "string"
|
|
16
|
+
? { id: input, kind: "human", groups: [] }
|
|
17
|
+
: { id: input.id, kind: input.kind ?? "human", groups: input.groups ?? [] };
|
|
18
|
+
const newId = () => globalThis.crypto.randomUUID();
|
|
19
|
+
export const host = async (options) => {
|
|
20
|
+
// An embedder owns the release: absent a public operation declaration, expose
|
|
21
|
+
// its declared actions and decisions. Explicit operation
|
|
22
|
+
// lists and component contracts retain the kernel's narrower surface.
|
|
23
|
+
const ir = {
|
|
24
|
+
...options.ir,
|
|
25
|
+
components: options.ir.components.map((c) => c.operations !== undefined ||
|
|
26
|
+
options.ir.componentContracts?.some((x) => x.component === c.name)
|
|
27
|
+
? c
|
|
28
|
+
: {
|
|
29
|
+
...c,
|
|
30
|
+
operations: [
|
|
31
|
+
...c.actions.map((a) => a.name),
|
|
32
|
+
...(options.ir.decisions ?? []).filter((d) => d.of === c.name).map((d) => d.name),
|
|
33
|
+
],
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
36
|
+
const files = options.files ?? [], store = options.store ?? memory(), clock = options.clock ?? (() => new Date().toISOString());
|
|
37
|
+
if (!options.account && ir.accounts.length !== 1)
|
|
38
|
+
throw new WorldError("E_ACCOUNT", `This world declares ${ir.accounts.length} accounts; pass account: one of ${ir.accounts.map((a) => a.name).join(", ")}.`);
|
|
39
|
+
const account = options.account ?? ir.accounts[0].name;
|
|
40
|
+
if (!ir.accounts.some((a) => a.name === account))
|
|
41
|
+
throw new WorldError("E_ACCOUNT", `Account ${account} is not declared by this world.`);
|
|
42
|
+
const program = K.link(ir, account);
|
|
43
|
+
const entities = new Map([...program.entities.values()]
|
|
44
|
+
.filter((e) => e.ns.split(".")[0] === program.account.package.name)
|
|
45
|
+
.map((e) => [e.name, e]));
|
|
46
|
+
const loaded = await store.load();
|
|
47
|
+
if (loaded && loaded.release !== program.release && !options.activate)
|
|
48
|
+
throw new WorldError("E_RELEASE_CHANGED", `The store was written under release ${loaded.release}; this source is release ${program.release}. Preview the change with worldvm diff and impact, then open with activate: true.`);
|
|
49
|
+
let state = loaded
|
|
50
|
+
? { ...loaded, release: program.release }
|
|
51
|
+
: { release: program.release, revision: 0, records: K.emptyWorld, receipts: {}, proposals: {} };
|
|
52
|
+
if (loaded && loaded.release !== program.release)
|
|
53
|
+
await store.commit(state);
|
|
54
|
+
const listeners = new Set();
|
|
55
|
+
const seen = new Map();
|
|
56
|
+
let closed = false;
|
|
57
|
+
// Writes run one at a time, so each command sees the commit before it.
|
|
58
|
+
let queue = Promise.resolve();
|
|
59
|
+
const serial = (f) => {
|
|
60
|
+
const run = queue.then(() => {
|
|
61
|
+
if (closed)
|
|
62
|
+
throw new WorldError("E_CLOSED", "This world has been closed.");
|
|
63
|
+
return f();
|
|
64
|
+
});
|
|
65
|
+
queue = run.catch(() => { });
|
|
66
|
+
return run;
|
|
67
|
+
};
|
|
68
|
+
const evaluate = (subject, at) => K.reconcileSubject(program, K.basis(state.records, at), subject);
|
|
69
|
+
const statusOf = (subject, recon, at) => {
|
|
70
|
+
const b = K.basis(state.records, at);
|
|
71
|
+
return {
|
|
72
|
+
subject,
|
|
73
|
+
at,
|
|
74
|
+
release: program.release,
|
|
75
|
+
revision: state.revision,
|
|
76
|
+
wakeAt: recon.wakeAt,
|
|
77
|
+
wakeReason: recon.wakeReason,
|
|
78
|
+
machines: [...recon.instances.values()]
|
|
79
|
+
.sort((a, b) => a.id.localeCompare(b.id))
|
|
80
|
+
.flatMap((inst) => (program.components.get(inst.component)?.machines ?? []).map((m) => {
|
|
81
|
+
const scope = K.resourceMachineScope(program, b, inst, m.name);
|
|
82
|
+
const history = b
|
|
83
|
+
.history(inst.id, m.name)
|
|
84
|
+
.filter((r) => !scope ||
|
|
85
|
+
((r.generation ?? 1) === scope.generation &&
|
|
86
|
+
(r.account === undefined || r.account === scope.account)));
|
|
87
|
+
const current = K.machineState(b, inst.id, m.name, scope);
|
|
88
|
+
let since = null;
|
|
89
|
+
for (let i = history.length - 1; i >= 0 && history[i].state === current; i--)
|
|
90
|
+
since = history[i].at;
|
|
91
|
+
return { instance: inst.id, machine: m.name, state: current, since };
|
|
92
|
+
})),
|
|
93
|
+
instances: [...recon.results]
|
|
94
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
95
|
+
.map(([instance, r]) => ({
|
|
96
|
+
instance,
|
|
97
|
+
component: r.component,
|
|
98
|
+
digest: r.digest,
|
|
99
|
+
outputs: Object.fromEntries(r.outputs.map((o) => [o.name, o.status])),
|
|
100
|
+
requirements: r.requirements.map((q) => ({
|
|
101
|
+
name: q.name,
|
|
102
|
+
label: q.label,
|
|
103
|
+
status: q.status,
|
|
104
|
+
due: q.due,
|
|
105
|
+
blocked: r.blocked.find((b) => b.requirement === q.name)?.reason ?? null,
|
|
106
|
+
})),
|
|
107
|
+
})),
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
const workOf = (recon, subject) => [
|
|
111
|
+
...[...recon.results].flatMap(([instance, r]) => {
|
|
112
|
+
const names = new Set(K.operationsFor(recon, account, { instance }).operations.map((o) => o.name));
|
|
113
|
+
return r.actions
|
|
114
|
+
.filter((a) => names.has(a.action))
|
|
115
|
+
.map((a) => ({
|
|
116
|
+
id: K.workItems(recon).find((w) => w.members.some((m) => m.instance === instance && m.action === a.action)).key,
|
|
117
|
+
instance,
|
|
118
|
+
operation: a.action,
|
|
119
|
+
label: a.label,
|
|
120
|
+
kind: a.kind,
|
|
121
|
+
state: a.state,
|
|
122
|
+
advances: a.advancesAll ?? [a.advances],
|
|
123
|
+
assignee: { id: a.assigneeId ?? null, kind: a.assigneeKind },
|
|
124
|
+
missing: a.missing,
|
|
125
|
+
fields: (a.fields ?? []).map((f) => ({
|
|
126
|
+
field: f.field,
|
|
127
|
+
mode: f.mode,
|
|
128
|
+
value: f.value,
|
|
129
|
+
})),
|
|
130
|
+
}));
|
|
131
|
+
}),
|
|
132
|
+
...Object.values(state.proposals)
|
|
133
|
+
.filter((p) => p.subject === subject && p.state === "pending")
|
|
134
|
+
.map((p) => ({
|
|
135
|
+
id: `proposal:${p.id}`,
|
|
136
|
+
proposal: p.id,
|
|
137
|
+
instance: "",
|
|
138
|
+
operation: "accept-proposal",
|
|
139
|
+
label: p.rationale,
|
|
140
|
+
kind: "proposal",
|
|
141
|
+
state: "eligible",
|
|
142
|
+
advances: [],
|
|
143
|
+
assignee: { id: null, kind: "entity" },
|
|
144
|
+
missing: [],
|
|
145
|
+
fields: [],
|
|
146
|
+
})),
|
|
147
|
+
].sort((a, b) => a.id < b.id
|
|
148
|
+
? -1
|
|
149
|
+
: a.id > b.id
|
|
150
|
+
? 1
|
|
151
|
+
: a.instance < b.instance
|
|
152
|
+
? -1
|
|
153
|
+
: a.instance > b.instance
|
|
154
|
+
? 1
|
|
155
|
+
: 0);
|
|
156
|
+
const open = (work) => work.filter((w) => w.state === "eligible" || w.state === "dispatched");
|
|
157
|
+
const diff = (subject, before, after) => {
|
|
158
|
+
const flat = (s) => new Map((s?.instances ?? []).flatMap((i) => [
|
|
159
|
+
...i.requirements.map((q) => [JSON.stringify([i.instance, "requirement", q.name]), q.status]),
|
|
160
|
+
...Object.entries(i.outputs).map(([name, status]) => [JSON.stringify([i.instance, "output", name]), status]),
|
|
161
|
+
]));
|
|
162
|
+
const was = flat(before?.status), is = flat(after.status);
|
|
163
|
+
const transitions = [...new Set([...was.keys(), ...is.keys()])]
|
|
164
|
+
.filter((key) => was.get(key) !== is.get(key))
|
|
165
|
+
.sort()
|
|
166
|
+
.map((key) => {
|
|
167
|
+
const [instance, kind, name] = JSON.parse(key);
|
|
168
|
+
return { instance, kind, name, from: was.get(key) ?? null, to: is.get(key) ?? null };
|
|
169
|
+
});
|
|
170
|
+
const key = (w) => JSON.stringify([w.id, w.instance, w.operation]);
|
|
171
|
+
const wasOpen = new Map(open(before?.work ?? []).map((w) => [key(w), w])), isOpen = new Map(open(after.work).map((w) => [key(w), w]));
|
|
172
|
+
return {
|
|
173
|
+
subject,
|
|
174
|
+
revision: after.status.revision,
|
|
175
|
+
at: after.status.at,
|
|
176
|
+
transitions,
|
|
177
|
+
opened: [...isOpen].filter(([k]) => !wasOpen.has(k)).map(([, w]) => w),
|
|
178
|
+
closed: [...wasOpen].filter(([k]) => !isOpen.has(k)).map(([, w]) => w),
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
const view = (subject, at) => {
|
|
182
|
+
const recon = evaluate(subject, at);
|
|
183
|
+
return {
|
|
184
|
+
recon,
|
|
185
|
+
snapshot: { status: statusOf(subject, recon, at), work: workOf(recon, subject) },
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
const emit = (change) => {
|
|
189
|
+
if (!change.transitions.length && !change.opened.length && !change.closed.length)
|
|
190
|
+
return;
|
|
191
|
+
for (const listener of listeners)
|
|
192
|
+
listener(change);
|
|
193
|
+
};
|
|
194
|
+
/** Run one command: replay its receipt, or apply it, commit, and report what changed. */
|
|
195
|
+
const write = (subject, request, apply) => serial(async () => {
|
|
196
|
+
const at = clock(), id = request.id ?? newId();
|
|
197
|
+
const digest = K.sha256(K.canonicalJson({
|
|
198
|
+
release: program.release,
|
|
199
|
+
subject,
|
|
200
|
+
// Drop undefined options so an omitted option and an absent one hash alike.
|
|
201
|
+
body: JSON.parse(JSON.stringify(request.body)),
|
|
202
|
+
}));
|
|
203
|
+
const before = view(subject, at);
|
|
204
|
+
const previous = seen.get(subject) ?? before.snapshot;
|
|
205
|
+
const replay = (receipt) => {
|
|
206
|
+
seen.set(subject, before.snapshot);
|
|
207
|
+
return {
|
|
208
|
+
accepted: receipt.accepted,
|
|
209
|
+
codes: receipt.codes,
|
|
210
|
+
status: before.snapshot.status,
|
|
211
|
+
change: diff(subject, before.snapshot, before.snapshot),
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
const receipt = Object.hasOwn(state.receipts, id) ? state.receipts[id] : undefined;
|
|
215
|
+
if (receipt) {
|
|
216
|
+
if (receipt.digest !== digest)
|
|
217
|
+
return replay({ accepted: false, codes: ["command-duplicate"] });
|
|
218
|
+
return receipt.outcome;
|
|
219
|
+
}
|
|
220
|
+
const result = apply(before.recon, at, id);
|
|
221
|
+
let records = result.records;
|
|
222
|
+
if (result.accepted && records.facts.length > state.records.facts.length)
|
|
223
|
+
records = {
|
|
224
|
+
...records,
|
|
225
|
+
facts: records.facts.map((f, index) => index < state.records.facts.length ? f : { ...f, command: id }),
|
|
226
|
+
};
|
|
227
|
+
if (result.accepted)
|
|
228
|
+
records = K.recordMilestones(K.reconcileSubject(program, K.basis(records, at), subject), records);
|
|
229
|
+
const next = {
|
|
230
|
+
release: program.release,
|
|
231
|
+
revision: state.revision + 1,
|
|
232
|
+
records,
|
|
233
|
+
proposals: result.proposals ?? state.proposals,
|
|
234
|
+
receipts: state.receipts,
|
|
235
|
+
};
|
|
236
|
+
// Compute the receipt against the candidate state, then persist both atomically.
|
|
237
|
+
const prior = state;
|
|
238
|
+
let after;
|
|
239
|
+
try {
|
|
240
|
+
state = next;
|
|
241
|
+
after = view(subject, at).snapshot;
|
|
242
|
+
}
|
|
243
|
+
finally {
|
|
244
|
+
state = prior;
|
|
245
|
+
}
|
|
246
|
+
const change = diff(subject, previous, after);
|
|
247
|
+
const outcome = {
|
|
248
|
+
accepted: result.accepted,
|
|
249
|
+
codes: result.codes,
|
|
250
|
+
status: after.status,
|
|
251
|
+
change,
|
|
252
|
+
};
|
|
253
|
+
const committed = {
|
|
254
|
+
...next,
|
|
255
|
+
receipts: {
|
|
256
|
+
...next.receipts,
|
|
257
|
+
[id]: { digest, accepted: result.accepted, codes: result.codes, outcome },
|
|
258
|
+
},
|
|
259
|
+
};
|
|
260
|
+
await store.commit(committed);
|
|
261
|
+
state = committed;
|
|
262
|
+
seen.set(subject, after);
|
|
263
|
+
emit(change);
|
|
264
|
+
return outcome;
|
|
265
|
+
});
|
|
266
|
+
const subject = (type, id) => {
|
|
267
|
+
const entity = entities.get(type);
|
|
268
|
+
if (!entity)
|
|
269
|
+
throw new WorldError("E_ENTITY", `Account ${account} declares no entity ${type}. Declared: ${[...entities.keys()].join(", ")}.`);
|
|
270
|
+
if (!id.trim())
|
|
271
|
+
throw new WorldError("E_ENTITY", "A subject id must be nonempty.");
|
|
272
|
+
const target = (recon, has, wanted) => {
|
|
273
|
+
const matches = [...recon.results.keys()].filter((i) => (!wanted || i === wanted) && has(i));
|
|
274
|
+
return matches.length === 1
|
|
275
|
+
? matches[0]
|
|
276
|
+
: [matches.length ? "operation-ambiguous" : "operation-target"];
|
|
277
|
+
};
|
|
278
|
+
const refused = (...codes) => ({ accepted: false, codes, records: state.records });
|
|
279
|
+
const assertFacts = (values, options, recon, at) => {
|
|
280
|
+
const by = actor(options.by);
|
|
281
|
+
if (by.kind === "agent")
|
|
282
|
+
return refused("human-required");
|
|
283
|
+
const names = Object.keys(values);
|
|
284
|
+
if (!names.length)
|
|
285
|
+
return refused("fact-input");
|
|
286
|
+
const facts = names.map((name) => ({
|
|
287
|
+
name,
|
|
288
|
+
field: entity.fields.find((f) => f.name === name),
|
|
289
|
+
value: values[name],
|
|
290
|
+
}));
|
|
291
|
+
const invalid = facts.filter((f) => !f.field || !K.validFact(program, state.records, id, f.field.attr, f.value, at));
|
|
292
|
+
if (invalid.length)
|
|
293
|
+
return refused(...invalid.map((f) => `fact-invalid:${f.name}`));
|
|
294
|
+
const result = K.command(recon, state.records, at, {
|
|
295
|
+
kind: options.kind ?? "fact",
|
|
296
|
+
subject: id,
|
|
297
|
+
title: `Recorded ${type} ${names.join(", ")}`,
|
|
298
|
+
by: by.id,
|
|
299
|
+
facts: facts.map((f) => ({ e: id, a: f.field.attr, v: f.value })),
|
|
300
|
+
});
|
|
301
|
+
return {
|
|
302
|
+
accepted: !result.violations.length,
|
|
303
|
+
codes: result.violations.map((v) => v.invariant),
|
|
304
|
+
records: result.world,
|
|
305
|
+
};
|
|
306
|
+
};
|
|
307
|
+
const performOperation = (operation, options, recon, at, command) => {
|
|
308
|
+
const { by, id: _commandId, instance, ...input } = options;
|
|
309
|
+
if (actor(by).kind === "agent" && !input.unsigned)
|
|
310
|
+
return refused("human-required");
|
|
311
|
+
const item = workOf(recon).find((w) => w.id === operation && (!instance || w.instance === instance));
|
|
312
|
+
const name = item?.operation ?? operation;
|
|
313
|
+
const found = target(recon, (i) => K.operationsFor(recon, account, { instance: i }).operations.some((o) => o.name === name), instance ?? item?.instance);
|
|
314
|
+
if (typeof found !== "string")
|
|
315
|
+
return refused(...found);
|
|
316
|
+
const result = K.invokeOperation(recon, state.records, at, {
|
|
317
|
+
id: command,
|
|
318
|
+
account,
|
|
319
|
+
target: { instance: found },
|
|
320
|
+
operation: name,
|
|
321
|
+
actor: actor(by),
|
|
322
|
+
...input,
|
|
323
|
+
});
|
|
324
|
+
return { accepted: result.accepted, codes: result.codes, records: result.world };
|
|
325
|
+
};
|
|
326
|
+
const resolveProposal = (proposal, options, reason) => write(id, {
|
|
327
|
+
id: options.id,
|
|
328
|
+
body: [
|
|
329
|
+
reason === undefined ? "accept-proposal" : "reject-proposal",
|
|
330
|
+
type,
|
|
331
|
+
proposal,
|
|
332
|
+
reason,
|
|
333
|
+
options.signature,
|
|
334
|
+
actor(options.by),
|
|
335
|
+
],
|
|
336
|
+
}, (recon, at, command) => {
|
|
337
|
+
const by = actor(options.by);
|
|
338
|
+
if (by.kind !== "human")
|
|
339
|
+
return refused("human-required");
|
|
340
|
+
const p = Object.hasOwn(state.proposals, proposal)
|
|
341
|
+
? state.proposals[proposal]
|
|
342
|
+
: undefined;
|
|
343
|
+
if (!p || p.type !== type || p.subject !== id)
|
|
344
|
+
return refused("not-found");
|
|
345
|
+
if (p.state !== "pending")
|
|
346
|
+
return refused("proposal-resolved");
|
|
347
|
+
if (reason !== undefined && !reason.trim())
|
|
348
|
+
return refused("proposal-input");
|
|
349
|
+
const draft = p.draft;
|
|
350
|
+
const result = reason !== undefined
|
|
351
|
+
? { accepted: true, codes: [], records: state.records }
|
|
352
|
+
: draft.kind === "assert"
|
|
353
|
+
? assertFacts(draft.values, { by, ...(draft.factKind ? { kind: draft.factKind } : {}) }, recon, at)
|
|
354
|
+
: performOperation(draft.operation, {
|
|
355
|
+
by,
|
|
356
|
+
values: draft.values,
|
|
357
|
+
...(options.signature ? { signature: options.signature } : {}),
|
|
358
|
+
...(draft.instance ? { instance: draft.instance } : {}),
|
|
359
|
+
}, recon, at, command);
|
|
360
|
+
if (!result.accepted)
|
|
361
|
+
return result;
|
|
362
|
+
const resolved = {
|
|
363
|
+
...p,
|
|
364
|
+
state: reason === undefined ? "accepted" : "rejected",
|
|
365
|
+
resolution: { by, at, command, ...(reason === undefined ? {} : { reason }) },
|
|
366
|
+
};
|
|
367
|
+
// The durable proposal cites the command; the write's audit journal cites the proposal.
|
|
368
|
+
return {
|
|
369
|
+
...result,
|
|
370
|
+
records: {
|
|
371
|
+
...result.records,
|
|
372
|
+
journal: [
|
|
373
|
+
...result.records.journal,
|
|
374
|
+
{
|
|
375
|
+
id: `proposal:${command}`,
|
|
376
|
+
at,
|
|
377
|
+
actor: by.id,
|
|
378
|
+
title: `${resolved.state} proposal ${proposal}`,
|
|
379
|
+
context: proposal,
|
|
380
|
+
changes: [],
|
|
381
|
+
},
|
|
382
|
+
],
|
|
383
|
+
},
|
|
384
|
+
proposals: { ...state.proposals, [proposal]: resolved },
|
|
385
|
+
};
|
|
386
|
+
});
|
|
387
|
+
return {
|
|
388
|
+
type,
|
|
389
|
+
id,
|
|
390
|
+
proposals: () => Object.values(state.proposals).filter((p) => p.type === type && p.subject === id),
|
|
391
|
+
propose: (draft, rationale, options) => write(id, { id: options.id, body: ["propose", type, draft, rationale, actor(options.by)] }, (_recon, at, command) => {
|
|
392
|
+
const by = actor(options.by);
|
|
393
|
+
if (by.kind !== "agent")
|
|
394
|
+
return refused("forbidden");
|
|
395
|
+
if (!rationale.trim())
|
|
396
|
+
return refused("proposal-input");
|
|
397
|
+
if (draft.kind === "evidence") {
|
|
398
|
+
const recon = evaluate(id, at);
|
|
399
|
+
const item = workOf(recon).find((w) => (w.operation === draft.operation || w.id === draft.operation) &&
|
|
400
|
+
(!draft.instance || draft.instance === w.instance));
|
|
401
|
+
if (!item || item.kind !== "interaction")
|
|
402
|
+
return refused("operation-target");
|
|
403
|
+
}
|
|
404
|
+
const proposal = {
|
|
405
|
+
id: command,
|
|
406
|
+
type,
|
|
407
|
+
subject: id,
|
|
408
|
+
by,
|
|
409
|
+
at,
|
|
410
|
+
rationale,
|
|
411
|
+
draft: structuredClone(draft),
|
|
412
|
+
state: "pending",
|
|
413
|
+
};
|
|
414
|
+
return {
|
|
415
|
+
accepted: true,
|
|
416
|
+
codes: [],
|
|
417
|
+
records: state.records,
|
|
418
|
+
proposals: { ...state.proposals, [command]: proposal },
|
|
419
|
+
};
|
|
420
|
+
}),
|
|
421
|
+
acceptProposal: (proposal, options) => resolveProposal(proposal, options),
|
|
422
|
+
rejectProposal: (proposal, reason, options) => resolveProposal(proposal, options, reason),
|
|
423
|
+
assert: (values, options) => write(id, { id: options.id, body: ["assert", type, values, options.kind, actor(options.by)] }, (recon, at) => assertFacts(values, options, recon, at)),
|
|
424
|
+
perform: (operation, options) => {
|
|
425
|
+
const { by, id: commandId, instance, ...input } = options;
|
|
426
|
+
return write(id, { id: commandId, body: ["perform", type, operation, instance ?? null, input, actor(by)] }, (recon, at, command) => performOperation(operation, options, recon, at, command));
|
|
427
|
+
},
|
|
428
|
+
signal: (machine, to, options) => write(id, {
|
|
429
|
+
id: options.id,
|
|
430
|
+
body: ["signal", type, machine, to, options.instance ?? null, actor(options.by)],
|
|
431
|
+
}, (recon, at) => {
|
|
432
|
+
if (actor(options.by).kind === "agent")
|
|
433
|
+
return refused("human-required");
|
|
434
|
+
const found = target(recon, (i) => !!program.components
|
|
435
|
+
.get(recon.instances.get(i).component)
|
|
436
|
+
?.machines.some((m) => m.name === machine), options.instance);
|
|
437
|
+
if (typeof found !== "string")
|
|
438
|
+
return { accepted: false, codes: found, records: state.records };
|
|
439
|
+
const accepted = K.canTransition(program, K.basis(state.records, at), recon.instances.get(found), machine, to);
|
|
440
|
+
// A refused signal is still journaled, so the rejection itself is on the record.
|
|
441
|
+
const records = K.signal(recon, state.records, at, {
|
|
442
|
+
instance: found,
|
|
443
|
+
machine,
|
|
444
|
+
state: to,
|
|
445
|
+
by: actor(options.by).id,
|
|
446
|
+
});
|
|
447
|
+
return { accepted, codes: accepted ? [] : ["transition"], records };
|
|
448
|
+
}),
|
|
449
|
+
facts: (at = clock()) => {
|
|
450
|
+
const b = K.basis(state.records, at);
|
|
451
|
+
return entity.fields
|
|
452
|
+
.flatMap((field) => {
|
|
453
|
+
const f = b.fact(id, field.attr);
|
|
454
|
+
return f
|
|
455
|
+
? [{ fact: f.a, value: f.v, by: f.by, at: f.at, command: f.command ?? null }]
|
|
456
|
+
: [];
|
|
457
|
+
})
|
|
458
|
+
.sort((a, b) => a.fact.localeCompare(b.fact));
|
|
459
|
+
},
|
|
460
|
+
status: (at = clock()) => view(id, at).snapshot.status,
|
|
461
|
+
work: (at = clock()) => view(id, at).snapshot.work,
|
|
462
|
+
operations: (at = clock()) => {
|
|
463
|
+
const recon = evaluate(id, at);
|
|
464
|
+
return [...recon.results.keys()].sort().flatMap((instance) => K.operationsFor(recon, account, { instance }).operations.map((o) => ({
|
|
465
|
+
instance,
|
|
466
|
+
name: o.name,
|
|
467
|
+
kind: o.kind,
|
|
468
|
+
state: o.state,
|
|
469
|
+
})));
|
|
470
|
+
},
|
|
471
|
+
explain: (requirement, at = clock()) => explainReconciliation(ir, files, evaluate(id, at), null)
|
|
472
|
+
.instances.flatMap((i) => i.requirements)
|
|
473
|
+
.filter((q) => !requirement || q.name === requirement),
|
|
474
|
+
};
|
|
475
|
+
};
|
|
476
|
+
const subjects = (type) => {
|
|
477
|
+
const entity = entities.get(type);
|
|
478
|
+
if (!entity)
|
|
479
|
+
throw new WorldError("E_ENTITY", `Account ${account} declares no entity ${type}.`);
|
|
480
|
+
return [
|
|
481
|
+
...new Set(state.records.facts.filter((f) => f.a.startsWith(entity.ns + "/")).map((f) => f.e)),
|
|
482
|
+
].sort();
|
|
483
|
+
};
|
|
484
|
+
// Seed time-dependent projections before the application reads any subject.
|
|
485
|
+
const openedAt = clock();
|
|
486
|
+
for (const type of entities.keys())
|
|
487
|
+
for (const id of subjects(type))
|
|
488
|
+
seen.set(id, view(id, openedAt).snapshot);
|
|
489
|
+
const world = {
|
|
490
|
+
canRead: (actor, type, subject) => options.canRead?.({ actor, type, subject }) ?? true,
|
|
491
|
+
request: (verb, input, by) => operate(world, verb, input, by),
|
|
492
|
+
proposals: () => Object.values(state.proposals),
|
|
493
|
+
account,
|
|
494
|
+
release: program.release,
|
|
495
|
+
revision: () => state.revision,
|
|
496
|
+
now: clock,
|
|
497
|
+
types: [...entities.keys()].sort(),
|
|
498
|
+
subject,
|
|
499
|
+
subjects,
|
|
500
|
+
tick: () => serial(async () => {
|
|
501
|
+
const at = clock(), changes = [];
|
|
502
|
+
for (const type of entities.keys())
|
|
503
|
+
for (const id of subjects(type)) {
|
|
504
|
+
const after = view(id, at).snapshot, before = seen.get(id);
|
|
505
|
+
seen.set(id, after);
|
|
506
|
+
// The first sighting is a baseline; there is nothing to compare it with.
|
|
507
|
+
if (!before)
|
|
508
|
+
continue;
|
|
509
|
+
const change = diff(id, before, after);
|
|
510
|
+
if (change.transitions.length || change.opened.length || change.closed.length) {
|
|
511
|
+
changes.push(change);
|
|
512
|
+
emit(change);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return changes;
|
|
516
|
+
}),
|
|
517
|
+
nextWake: () => [...seen.values()]
|
|
518
|
+
.flatMap((s) => (s.status.wakeAt ? [s.status.wakeAt] : []))
|
|
519
|
+
.sort(K.compareTime)[0] ?? null,
|
|
520
|
+
subscribe: (listener) => {
|
|
521
|
+
listeners.add(listener);
|
|
522
|
+
return () => void listeners.delete(listener);
|
|
523
|
+
},
|
|
524
|
+
records: () => state.records,
|
|
525
|
+
close: async () => {
|
|
526
|
+
await queue;
|
|
527
|
+
closed = true;
|
|
528
|
+
listeners.clear();
|
|
529
|
+
await store.close();
|
|
530
|
+
},
|
|
531
|
+
};
|
|
532
|
+
return world;
|
|
533
|
+
};
|
package/dist/http.d.ts
ADDED
package/dist/http.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { decodeActor, verbs } from "./_internal/protocol/index.js";
|
|
2
|
+
import { failure } from "./handle/protocol.js";
|
|
3
|
+
const json = (value, status = 200) => Response.json(value, { status });
|
|
4
|
+
const httpStatus = (code) => ({
|
|
5
|
+
"invalid-request": 400,
|
|
6
|
+
unauthenticated: 401,
|
|
7
|
+
forbidden: 403,
|
|
8
|
+
"human-required": 403,
|
|
9
|
+
"not-found": 404,
|
|
10
|
+
internal: 500,
|
|
11
|
+
})[code] ?? 409;
|
|
12
|
+
/** Dev-only trusted actor header. Authenticate and replace this header at a trusted boundary. */
|
|
13
|
+
export const createHandler = (world) => async (request) => {
|
|
14
|
+
const url = new URL(request.url);
|
|
15
|
+
const name = url.pathname.match(/^\/v1\/([^/]+)$/)?.[1];
|
|
16
|
+
if (!name || !verbs.includes(name))
|
|
17
|
+
return json(failure("not-found", "Unknown protocol verb."), 404);
|
|
18
|
+
let by;
|
|
19
|
+
try {
|
|
20
|
+
by = decodeActor(JSON.parse(request.headers.get("x-worldvm-actor") ?? "null"));
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return json(failure("unauthenticated", "x-worldvm-actor must contain a trusted actor JSON object."), 401);
|
|
24
|
+
}
|
|
25
|
+
if (request.method === "GET" && name === "changes") {
|
|
26
|
+
let cleanup = () => { };
|
|
27
|
+
const body = new ReadableStream({
|
|
28
|
+
start(controller) {
|
|
29
|
+
const encoder = new TextEncoder();
|
|
30
|
+
let ended = false;
|
|
31
|
+
const unsubscribe = world.subscribe((change) => {
|
|
32
|
+
if (!ended)
|
|
33
|
+
controller.enqueue(encoder.encode(`event: change\ndata: ${JSON.stringify(change)}\n\n`));
|
|
34
|
+
});
|
|
35
|
+
const abort = () => {
|
|
36
|
+
cleanup();
|
|
37
|
+
controller.close();
|
|
38
|
+
};
|
|
39
|
+
cleanup = () => {
|
|
40
|
+
ended = true;
|
|
41
|
+
unsubscribe();
|
|
42
|
+
request.signal.removeEventListener("abort", abort);
|
|
43
|
+
};
|
|
44
|
+
controller.enqueue(encoder.encode(": worldvm changes; live events only\n\n"));
|
|
45
|
+
request.signal.addEventListener("abort", abort, { once: true });
|
|
46
|
+
if (request.signal.aborted)
|
|
47
|
+
abort();
|
|
48
|
+
},
|
|
49
|
+
cancel() {
|
|
50
|
+
cleanup();
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
return new Response(body, {
|
|
54
|
+
headers: {
|
|
55
|
+
"content-type": "text/event-stream",
|
|
56
|
+
"cache-control": "no-cache",
|
|
57
|
+
connection: "keep-alive",
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (request.method !== "POST")
|
|
62
|
+
return json(failure("invalid-request", "Use POST /v1/<verb> or GET /v1/changes."), 405);
|
|
63
|
+
let input;
|
|
64
|
+
try {
|
|
65
|
+
input = await request.json();
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return json(failure("invalid-request", "Expected a JSON request body."), 400);
|
|
69
|
+
}
|
|
70
|
+
const result = await world.request(name, input, by);
|
|
71
|
+
return json(result, result.ok ? 200 : httpStatus(result.error.code));
|
|
72
|
+
};
|
package/dist/impact.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type CliDiagnostic } from "./project.js";
|
|
2
|
+
import { type Impact } from "./release/impact.js";
|
|
3
|
+
import type { SidedDiagnostic } from "./diff.js";
|
|
4
|
+
export interface ImpactOptions {
|
|
5
|
+
/** A `worldvm/world@1` snapshot: the population to preview against. */
|
|
6
|
+
readonly world: string;
|
|
7
|
+
/** Evaluation instant; the CLI never reads the clock. */
|
|
8
|
+
readonly at: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ImpactReport {
|
|
11
|
+
readonly format: "worldvm/impact-report@1";
|
|
12
|
+
readonly command: "impact";
|
|
13
|
+
readonly old: string;
|
|
14
|
+
readonly new: string;
|
|
15
|
+
readonly snapshot: string;
|
|
16
|
+
/** False on compile, snapshot or evaluation failure, and when a change escaped the selection. */
|
|
17
|
+
readonly ok: boolean;
|
|
18
|
+
readonly diagnostics: readonly (CliDiagnostic | SidedDiagnostic)[];
|
|
19
|
+
readonly impact: Impact | null;
|
|
20
|
+
}
|
|
21
|
+
export declare const impactDirectories: (before: string, after: string, options: ImpactOptions) => Promise<ImpactReport>;
|