@johnhenry/mallory-cli 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/README.md +60 -2
- package/bin/mallory.mjs +51 -0
- package/package.json +51 -4
- package/src/a2a/client.js +511 -0
- package/src/a2a/demo-agent.js +396 -0
- package/src/a2a/hub.js +578 -0
- package/src/a2a/settings.js +88 -0
- package/src/a2a/task.js +358 -0
- package/src/acp/client.js +573 -0
- package/src/acp/demo-agent.js +332 -0
- package/src/acp/hub.js +632 -0
- package/src/acp/settings.js +78 -0
- package/src/actions/map.js +524 -0
- package/src/agent/cloud.js +77 -0
- package/src/agent/compact.js +84 -0
- package/src/agent/constants.js +39 -0
- package/src/agent/diff.js +101 -0
- package/src/agent/fork.js +159 -0
- package/src/agent/grounding.js +73 -0
- package/src/agent/guards.js +129 -0
- package/src/agent/local-transport.js +152 -0
- package/src/agent/loop.js +479 -0
- package/src/agent/park-store.js +77 -0
- package/src/agent/park.js +76 -0
- package/src/agent/ports.js +28 -0
- package/src/agent/providers.js +591 -0
- package/src/agent/restart.js +51 -0
- package/src/agent/router.js +380 -0
- package/src/agent/run.js +861 -0
- package/src/agent/tools.js +247 -0
- package/src/agent-library/engine.js +43 -0
- package/src/ai/bridge.js +155 -0
- package/src/ai/policy.js +131 -0
- package/src/aimatey/vendor.js +18 -0
- package/src/audio/container-duration.js +35 -0
- package/src/audio/instruments.js +776 -0
- package/src/audio/lanes.js +230 -0
- package/src/audio/patch.js +1410 -0
- package/src/audio/plan.js +276 -0
- package/src/audio/rack.js +1006 -0
- package/src/audio/sample-trim.js +293 -0
- package/src/audio/soundfont.js +243 -0
- package/src/audio/take-store.js +87 -0
- package/src/audio/takes.js +129 -0
- package/src/audio/wav.js +170 -0
- package/src/audio/zzfx.js +333 -0
- package/src/autonomy/bundle.js +207 -0
- package/src/autonomy/confine.js +61 -0
- package/src/autonomy/enforce.js +155 -0
- package/src/autonomy/file-kv.js +88 -0
- package/src/autonomy/ledger.js +203 -0
- package/src/autonomy/pins.js +50 -0
- package/src/autonomy/psl/index.js +32 -0
- package/src/autonomy/psl/suffixes.json +1 -0
- package/src/autonomy/record.js +28 -0
- package/src/autonomy/routines.js +107 -0
- package/src/autonomy/server.js +175 -0
- package/src/autonomy/signer-node.js +167 -0
- package/src/autonomy/store.js +43 -0
- package/src/autonomy/unattended.js +13 -0
- package/src/bytes/bytes.js +378 -0
- package/src/calc/syntax.js +125 -0
- package/src/calc/tex.js +28 -0
- package/src/calendar/vendor.js +2 -0
- package/src/clipboard.js +130 -0
- package/src/clsh/clsh.js +3417 -0
- package/src/codec/capnp.js +1804 -0
- package/src/codec/core.js +2043 -0
- package/src/codec/vendor/avro.js +136 -0
- package/src/codec/vendor/cbor.js +25 -0
- package/src/codec/vendor/flatbuffers.js +206 -0
- package/src/codec/vendor/msgpack.js +9 -0
- package/src/codec/vendor/protobuf.js +53 -0
- package/src/delegation/caps.js +60 -0
- package/src/delegation/config.js +32 -0
- package/src/device/model.js +246 -0
- package/src/device/recording.js +198 -0
- package/src/device/stream-model.js +151 -0
- package/src/documents/documents.js +1224 -0
- package/src/effects/catalog.js +63 -0
- package/src/effects/extras.js +133 -0
- package/src/effects/parse.js +339 -0
- package/src/embed/protocol.js +131 -0
- package/src/env/env.js +159 -0
- package/src/exact/vendor.js +45 -0
- package/src/example-meta.js +164 -0
- package/src/examples.js +94 -0
- package/src/export/canvas-image.js +217 -0
- package/src/export/expr-latex-lazy.js +8 -0
- package/src/export/formats.js +322 -0
- package/src/export/latex.js +183 -0
- package/src/export/pane.js +184 -0
- package/src/export/value.js +452 -0
- package/src/export/zip.js +214 -0
- package/src/ext/access.js +58 -0
- package/src/ext/btasks.js +225 -0
- package/src/ext/client.js +209 -0
- package/src/ext/tools.js +69 -0
- package/src/ext/view.js +105 -0
- package/src/ext/webmcp-tabs.js +299 -0
- package/src/files/archive.js +232 -0
- package/src/files/files.js +317 -0
- package/src/formats/json.js +24 -0
- package/src/formats/jupyter.js +188 -0
- package/src/formats/markdown.js +254 -0
- package/src/formats/n8n.js +276 -0
- package/src/formats/node-red.js +363 -0
- package/src/formats/registry.js +177 -0
- package/src/formats/rivet.js +259 -0
- package/src/formats/shared.js +98 -0
- package/src/formats/structure.js +182 -0
- package/src/formats/yaml.js +127 -0
- package/src/frame/frame.js +962 -0
- package/src/frame/vendor.js +1484 -0
- package/src/gate/audit.js +116 -0
- package/src/gate/gate.js +365 -0
- package/src/gate/policy.js +295 -0
- package/src/gate/scripted.js +110 -0
- package/src/gate/seams.js +32 -0
- package/src/gate/store.js +66 -0
- package/src/geometry/model.js +533 -0
- package/src/grant-key.js +149 -0
- package/src/graph/model.js +381 -0
- package/src/headless/a2a-push.js +123 -0
- package/src/headless/channels/config.js +142 -0
- package/src/headless/channels/connectors.js +283 -0
- package/src/headless/channels/index.js +257 -0
- package/src/headless/channels/mail.js +197 -0
- package/src/headless/channels/mailnet.js +223 -0
- package/src/headless/channels/platforms.js +194 -0
- package/src/headless/channels/replay.js +49 -0
- package/src/headless/cli.js +1397 -0
- package/src/headless/companion-client.js +182 -0
- package/src/headless/cost-cli.js +177 -0
- package/src/headless/deprecations-cli.js +102 -0
- package/src/headless/examples.js +48 -0
- package/src/headless/ffmpeg-exec.js +217 -0
- package/src/headless/gateways/config.js +213 -0
- package/src/headless/gateways/homeassistant.js +159 -0
- package/src/headless/gateways/index.js +121 -0
- package/src/headless/gateways/matter.js +150 -0
- package/src/headless/gateways/mqtt-client.js +177 -0
- package/src/headless/gateways/mqtt.js +70 -0
- package/src/headless/gateways/netway.js +226 -0
- package/src/headless/gateways/serverpod-worker.mjs +16 -0
- package/src/headless/gateways/serverpod.js +71 -0
- package/src/headless/gateways/util.js +27 -0
- package/src/headless/grant-cli.js +208 -0
- package/src/headless/guard.js +125 -0
- package/src/headless/guards.js +124 -0
- package/src/headless/machine-cli.js +853 -0
- package/src/headless/mcp-endpoint.js +287 -0
- package/src/headless/mcp-roots.js +38 -0
- package/src/headless/model-endpoint.js +88 -0
- package/src/headless/net.js +151 -0
- package/src/headless/node.js +263 -0
- package/src/headless/npm-tarball.js +29 -0
- package/src/headless/operator-page.js +112 -0
- package/src/headless/operator.js +242 -0
- package/src/headless/people.js +34 -0
- package/src/headless/pkg-cli.js +1103 -0
- package/src/headless/pkg-serve.js +138 -0
- package/src/headless/process-worker.js +88 -0
- package/src/headless/runner-remote.js +477 -0
- package/src/headless/sandbox-child.mjs +21 -0
- package/src/headless/scheduled.js +557 -0
- package/src/headless/serve-stream.js +97 -0
- package/src/headless/serve.js +2238 -0
- package/src/headless/short-links.js +158 -0
- package/src/headless/static-dirs.js +207 -0
- package/src/headless/trust-file.js +51 -0
- package/src/headless/watch.js +291 -0
- package/src/headless/ws-connect.js +65 -0
- package/src/headless/ws-connections.js +44 -0
- package/src/headless/ws-echo.js +150 -0
- package/src/headless/ws-proxy.js +354 -0
- package/src/headless/ws-ticket.js +48 -0
- package/src/hooks/config.js +50 -0
- package/src/hooks/engine.js +189 -0
- package/src/input/log.js +613 -0
- package/src/input/player.js +217 -0
- package/src/input/replay.js +209 -0
- package/src/jth/vendor.js +28 -0
- package/src/ledger/tx.js +94 -0
- package/src/machine/apply.js +193 -0
- package/src/machine/diff.js +168 -0
- package/src/machine/drive.js +296 -0
- package/src/machine/engine.js +478 -0
- package/src/machine/files-tool.js +76 -0
- package/src/machine/lint.js +139 -0
- package/src/machine/llmtm-trace.js +117 -0
- package/src/machine/llmtm.js +475 -0
- package/src/machine/otel.js +80 -0
- package/src/machine/pane-provider.js +51 -0
- package/src/machine/propose.js +159 -0
- package/src/machine/random.js +52 -0
- package/src/machine/risk.js +107 -0
- package/src/machine/session.js +1017 -0
- package/src/machine/shell-tool.js +45 -0
- package/src/machine/tape.js +349 -0
- package/src/machine/templates.js +104 -0
- package/src/machine/trace.js +664 -0
- package/src/machine/view.js +73 -0
- package/src/machine/vm-tool.js +47 -0
- package/src/machine/watchdog.js +46 -0
- package/src/mcp/app-args.js +51 -0
- package/src/mcp/app-run.js +56 -0
- package/src/mcp/apps.js +468 -0
- package/src/mcp/cache.js +232 -0
- package/src/mcp/client.js +507 -0
- package/src/mcp/demo-app.js +183 -0
- package/src/mcp/demo-server.js +602 -0
- package/src/mcp/elicitation.js +116 -0
- package/src/mcp/hub.js +1326 -0
- package/src/mcp/roots.js +139 -0
- package/src/mcp/sampling.js +105 -0
- package/src/mcp/settings.js +125 -0
- package/src/mcp/tape.js +292 -0
- package/src/mcp/uri-template.js +156 -0
- package/src/mcp/wsh-client.js +164 -0
- package/src/media/animated-codec.js +7 -0
- package/src/media/animated.js +623 -0
- package/src/media/compare-agent.js +70 -0
- package/src/media/compare-job.js +63 -0
- package/src/media/compare-page.js +296 -0
- package/src/media/compare-worker.js +14 -0
- package/src/media/compare.js +600 -0
- package/src/media/contract.js +62 -0
- package/src/media/decode-frame.js +57 -0
- package/src/media/decode-pool.js +188 -0
- package/src/media/ffmpeg-edit.js +344 -0
- package/src/media/ffmpeg-wasm-client.js +121 -0
- package/src/media/ffmpeg-wasm-session.js +79 -0
- package/src/media/ffmpeg-wasm.js +139 -0
- package/src/media/ffmpeg-worker.js +23 -0
- package/src/media/ffmpeg.js +903 -0
- package/src/media/helpers.js +419 -0
- package/src/media/keep.js +108 -0
- package/src/media/metadata-worker.js +16 -0
- package/src/media/metadata.js +2518 -0
- package/src/media/mime.js +102 -0
- package/src/media/page-decode.js +74 -0
- package/src/media/persist.js +114 -0
- package/src/media/png.js +226 -0
- package/src/media/sample-input.js +67 -0
- package/src/media/store.js +86 -0
- package/src/media/wav.js +109 -0
- package/src/midi/mappings.js +250 -0
- package/src/midi/message.js +125 -0
- package/src/model/action-hub.js +143 -0
- package/src/model/adapters.js +284 -0
- package/src/model/agent-runs.js +12 -0
- package/src/model/arrange.js +308 -0
- package/src/model/automation-clock.js +494 -0
- package/src/model/automation.js +653 -0
- package/src/model/batches.js +78 -0
- package/src/model/binary-view.js +195 -0
- package/src/model/breakpoints.js +392 -0
- package/src/model/calc-settings.js +65 -0
- package/src/model/calendar.js +254 -0
- package/src/model/canvas-id.js +5 -0
- package/src/model/canvas.js +5048 -0
- package/src/model/channel-names.js +29 -0
- package/src/model/channels.js +692 -0
- package/src/model/chart-clock.js +631 -0
- package/src/model/chart-code.js +69 -0
- package/src/model/codecs.js +60 -0
- package/src/model/companion-access.js +271 -0
- package/src/model/companion-pane.js +50 -0
- package/src/model/composite.js +324 -0
- package/src/model/context.js +380 -0
- package/src/model/controls.js +231 -0
- package/src/model/converter-presets.js +368 -0
- package/src/model/cost.js +580 -0
- package/src/model/curve-transform.js +122 -0
- package/src/model/cycles.js +176 -0
- package/src/model/debug-log.js +168 -0
- package/src/model/decision-clock.js +100 -0
- package/src/model/decisions.js +265 -0
- package/src/model/desk.js +87 -0
- package/src/model/device-hub.js +400 -0
- package/src/model/diff.js +445 -0
- package/src/model/emit-events.js +179 -0
- package/src/model/errors.js +238 -0
- package/src/model/event-presets.js +297 -0
- package/src/model/events.js +1303 -0
- package/src/model/explicit-setters.js +139 -0
- package/src/model/field-mapping.js +623 -0
- package/src/model/files-pane.js +263 -0
- package/src/model/flow-idle.js +89 -0
- package/src/model/foreach.js +549 -0
- package/src/model/frame-loop.js +71 -0
- package/src/model/frame-pressure.js +180 -0
- package/src/model/function-scaffold.js +1000 -0
- package/src/model/geometry-settings.js +54 -0
- package/src/model/goals.js +176 -0
- package/src/model/graph-settings.js +76 -0
- package/src/model/grid-widget.js +175 -0
- package/src/model/groups.js +332 -0
- package/src/model/hash.js +21 -0
- package/src/model/history.js +259 -0
- package/src/model/http-copy.js +88 -0
- package/src/model/http-send-companion.js +110 -0
- package/src/model/http-send.js +163 -0
- package/src/model/http-tap.js +521 -0
- package/src/model/http-tools.js +1138 -0
- package/src/model/import-lock.js +78 -0
- package/src/model/imports.js +258 -0
- package/src/model/infer-outputs.js +822 -0
- package/src/model/ink-connect.js +150 -0
- package/src/model/ink-diff.js +75 -0
- package/src/model/ink-gone.js +71 -0
- package/src/model/ink-route.js +120 -0
- package/src/model/ink-svg.js +206 -0
- package/src/model/ink.js +739 -0
- package/src/model/input-log-hub.js +456 -0
- package/src/model/input-split.js +69 -0
- package/src/model/json-schema-host.js +9 -0
- package/src/model/json-schema.js +368 -0
- package/src/model/jth.js +78 -0
- package/src/model/latex-expr.js +528 -0
- package/src/model/layout-history.js +120 -0
- package/src/model/lazy-map.js +88 -0
- package/src/model/ledger-pane.js +101 -0
- package/src/model/legacy-viaframe.js +90 -0
- package/src/model/lessons.js +448 -0
- package/src/model/links.js +981 -0
- package/src/model/live.js +411 -0
- package/src/model/math-widget.js +53 -0
- package/src/model/memory-settings.js +33 -0
- package/src/model/midi-controls.js +350 -0
- package/src/model/nl-time.js +408 -0
- package/src/model/notebook.js +137 -0
- package/src/model/pane-view-store.js +15 -0
- package/src/model/partial.js +115 -0
- package/src/model/pause-clock.js +53 -0
- package/src/model/peer-pane.js +32 -0
- package/src/model/persist-state.js +290 -0
- package/src/model/person-only.js +122 -0
- package/src/model/pin.js +209 -0
- package/src/model/plot-3d.js +213 -0
- package/src/model/plot-series.js +157 -0
- package/src/model/plot-settings.js +531 -0
- package/src/model/ports.js +312 -0
- package/src/model/presentation.js +222 -0
- package/src/model/preset-apply.js +316 -0
- package/src/model/preset-banks.js +335 -0
- package/src/model/preset-morph.js +263 -0
- package/src/model/preset-ops.js +205 -0
- package/src/model/preset-player.js +283 -0
- package/src/model/preset-states.js +172 -0
- package/src/model/profile-settings.js +109 -0
- package/src/model/promote.js +103 -0
- package/src/model/protected.js +10 -0
- package/src/model/proxy-log.js +230 -0
- package/src/model/proxy.js +367 -0
- package/src/model/quantity-widget.js +61 -0
- package/src/model/queue-book.js +359 -0
- package/src/model/quick-add.js +224 -0
- package/src/model/rate-limit.js +313 -0
- package/src/model/rate.js +95 -0
- package/src/model/recovery.js +216 -0
- package/src/model/rename-follow.js +113 -0
- package/src/model/repeater.js +1126 -0
- package/src/model/retention.js +664 -0
- package/src/model/route-edit.js +132 -0
- package/src/model/router.js +155 -0
- package/src/model/runaway.js +232 -0
- package/src/model/runlog.js +1033 -0
- package/src/model/runners/a2a.js +2 -0
- package/src/model/runners/acp.js +2 -0
- package/src/model/runners/actions.js +4 -0
- package/src/model/runners/agent.js +4 -0
- package/src/model/runners/audio.js +21 -0
- package/src/model/runners/automation.js +2 -0
- package/src/model/runners/calc.js +23 -0
- package/src/model/runners/catch.js +10 -0
- package/src/model/runners/codec.js +24 -0
- package/src/model/runners/companion-run.js +2 -0
- package/src/model/runners/device.js +7 -0
- package/src/model/runners/dom.js +13 -0
- package/src/model/runners/effects.js +2 -0
- package/src/model/runners/embed.js +11 -0
- package/src/model/runners/eval.js +2 -0
- package/src/model/runners/files.js +19 -0
- package/src/model/runners/geometry.js +23 -0
- package/src/model/runners/goals.js +18 -0
- package/src/model/runners/graph.js +23 -0
- package/src/model/runners/html.js +2 -0
- package/src/model/runners/http-proxy.js +185 -0
- package/src/model/runners/http-send.js +61 -0
- package/src/model/runners/http-static.js +83 -0
- package/src/model/runners/http-tap.js +26 -0
- package/src/model/runners/http.js +40 -0
- package/src/model/runners/import.js +2 -0
- package/src/model/runners/index.js +74 -0
- package/src/model/runners/input.js +14 -0
- package/src/model/runners/inputlog.js +7 -0
- package/src/model/runners/ledger.js +15 -0
- package/src/model/runners/machine.js +4 -0
- package/src/model/runners/mcp.js +2 -0
- package/src/model/runners/mcpapp.js +2 -0
- package/src/model/runners/media.js +18 -0
- package/src/model/runners/memory.js +28 -0
- package/src/model/runners/mesh-inspect.js +13 -0
- package/src/model/runners/peer.js +14 -0
- package/src/model/runners/plot.js +22 -0
- package/src/model/runners/render.js +14 -0
- package/src/model/runners/respond.js +2 -0
- package/src/model/runners/sample-soundfont.js +85 -0
- package/src/model/runners/sample.js +159 -0
- package/src/model/runners/scene.js +8 -0
- package/src/model/runners/score.js +24 -0
- package/src/model/runners/secret.js +10 -0
- package/src/model/runners/select.js +2 -0
- package/src/model/runners/shared.js +4 -0
- package/src/model/runners/shares.js +15 -0
- package/src/model/runners/shell.js +7 -0
- package/src/model/runners/skill.js +26 -0
- package/src/model/runners/state.js +2 -0
- package/src/model/runners/statechart.js +4 -0
- package/src/model/runners/subgraph.js +9 -0
- package/src/model/runners/tabs.js +25 -0
- package/src/model/runners/terminal.js +5 -0
- package/src/model/runners/text.js +4 -0
- package/src/model/runners/timer.js +7 -0
- package/src/model/runners/traffic.js +65 -0
- package/src/model/runners/trigger.js +2 -0
- package/src/model/runners/verdict.js +29 -0
- package/src/model/runners/vm.js +7 -0
- package/src/model/runners/wait.js +4 -0
- package/src/model/runners/ws-client.js +57 -0
- package/src/model/safe-regex.js +719 -0
- package/src/model/sample-settings.js +43 -0
- package/src/model/sample-source.js +47 -0
- package/src/model/saved-mapping.js +153 -0
- package/src/model/score-controllers.js +87 -0
- package/src/model/score-edit.js +399 -0
- package/src/model/score-instruments.js +300 -0
- package/src/model/score-library.js +407 -0
- package/src/model/score-markup.js +235 -0
- package/src/model/score-mix.js +248 -0
- package/src/model/score-patterns.js +276 -0
- package/src/model/score-selection.js +34 -0
- package/src/model/score-time.js +139 -0
- package/src/model/score-transforms.js +336 -0
- package/src/model/score-transport.js +192 -0
- package/src/model/selection.js +351 -0
- package/src/model/serial-controls.js +328 -0
- package/src/model/shares-pane.js +17 -0
- package/src/model/shell-pane.js +106 -0
- package/src/model/signature.js +1122 -0
- package/src/model/size-hints.js +106 -0
- package/src/model/size-ratio.js +12 -0
- package/src/model/skill-settings.js +23 -0
- package/src/model/snapping.js +466 -0
- package/src/model/split.js +375 -0
- package/src/model/spring-player.js +222 -0
- package/src/model/statecharts.js +1369 -0
- package/src/model/states-preset.js +208 -0
- package/src/model/static-route.js +100 -0
- package/src/model/step-words.js +45 -0
- package/src/model/subgraph.js +1042 -0
- package/src/model/switch.js +98 -0
- package/src/model/tabs-store.js +10 -0
- package/src/model/tensor-view.js +146 -0
- package/src/model/timer-clock.js +361 -0
- package/src/model/timers.js +422 -0
- package/src/model/timing.js +212 -0
- package/src/model/traffic-agent.js +111 -0
- package/src/model/traffic-store.js +20 -0
- package/src/model/traffic.js +665 -0
- package/src/model/transport.js +364 -0
- package/src/model/turns.js +86 -0
- package/src/model/types.js +425 -0
- package/src/model/value-path.js +138 -0
- package/src/model/versions.js +535 -0
- package/src/model/view-outputs.js +144 -0
- package/src/model/viewport-bookmarks.js +194 -0
- package/src/model/virtual-clock.js +85 -0
- package/src/model/vm-pane.js +258 -0
- package/src/model/wait-clock.js +715 -0
- package/src/model/wait-persist.js +248 -0
- package/src/model/waits.js +431 -0
- package/src/model/watch.js +80 -0
- package/src/model/webhook.js +496 -0
- package/src/model/when.js +48 -0
- package/src/model/widget-values.js +392 -0
- package/src/model/window-commands.js +278 -0
- package/src/model/windows.js +348 -0
- package/src/model/wire-inspect.js +343 -0
- package/src/model/wire-ops.js +324 -0
- package/src/model/wire-pipeline.js +378 -0
- package/src/model/wire-route.js +637 -0
- package/src/model/workspaces.js +122 -0
- package/src/model/ws-client.js +155 -0
- package/src/model/ws-demo.js +31 -0
- package/src/model/ws-frames.js +141 -0
- package/src/model/ws-hub.js +219 -0
- package/src/model/ws-served.js +13 -0
- package/src/model/xstate.js +374 -0
- package/src/narrative/narrative.js +1557 -0
- package/src/network/auth.js +224 -0
- package/src/network/csp-frame.js +197 -0
- package/src/network/declarative-shadow.js +27 -0
- package/src/network/frame-net-shim.js +962 -0
- package/src/network/hosts.js +157 -0
- package/src/network/policy.js +520 -0
- package/src/network/rtc-shim.js +418 -0
- package/src/network/secret-gate.js +78 -0
- package/src/network/secrets.js +261 -0
- package/src/network/sockets.js +287 -0
- package/src/network/store.js +186 -0
- package/src/network/streams.js +99 -0
- package/src/packages/asset-values.js +50 -0
- package/src/packages/assets.js +99 -0
- package/src/packages/deprecation.js +203 -0
- package/src/packages/fetch.js +152 -0
- package/src/packages/function-canvas.js +73 -0
- package/src/packages/module.js +120 -0
- package/src/packages/package.js +474 -0
- package/src/packages/published.js +27 -0
- package/src/packages/requires.js +83 -0
- package/src/packages/signing.js +145 -0
- package/src/packages/trust.js +107 -0
- package/src/panes/a2a.js +51 -0
- package/src/panes/acp.js +60 -0
- package/src/panes/actions.js +54 -0
- package/src/panes/agent.js +83 -0
- package/src/panes/audio.js +103 -0
- package/src/panes/automation.js +112 -0
- package/src/panes/calc.js +67 -0
- package/src/panes/catch.js +52 -0
- package/src/panes/codec.js +59 -0
- package/src/panes/colors.js +12 -0
- package/src/panes/companion.js +54 -0
- package/src/panes/decision.js +65 -0
- package/src/panes/device.js +56 -0
- package/src/panes/dom.js +37 -0
- package/src/panes/effects.js +118 -0
- package/src/panes/embed.js +30 -0
- package/src/panes/eval.js +186 -0
- package/src/panes/fields.js +299 -0
- package/src/panes/files.js +45 -0
- package/src/panes/gate.js +70 -0
- package/src/panes/geometry.js +64 -0
- package/src/panes/goals.js +75 -0
- package/src/panes/graph.js +66 -0
- package/src/panes/html.js +54 -0
- package/src/panes/http.js +82 -0
- package/src/panes/import.js +38 -0
- package/src/panes/input.js +124 -0
- package/src/panes/inputlog.js +66 -0
- package/src/panes/ledger.js +56 -0
- package/src/panes/machine.js +138 -0
- package/src/panes/mcp.js +85 -0
- package/src/panes/mcpapp.js +64 -0
- package/src/panes/media.js +38 -0
- package/src/panes/memory.js +46 -0
- package/src/panes/mesh-inspect.js +49 -0
- package/src/panes/note.js +38 -0
- package/src/panes/peer.js +44 -0
- package/src/panes/plot.js +196 -0
- package/src/panes/registry.js +475 -0
- package/src/panes/render.js +87 -0
- package/src/panes/respond.js +44 -0
- package/src/panes/router.js +84 -0
- package/src/panes/sample.js +75 -0
- package/src/panes/scene.js +55 -0
- package/src/panes/score.js +87 -0
- package/src/panes/secret.js +38 -0
- package/src/panes/select.js +67 -0
- package/src/panes/shader.js +166 -0
- package/src/panes/shared.js +33 -0
- package/src/panes/shares.js +43 -0
- package/src/panes/shell.js +47 -0
- package/src/panes/skill.js +44 -0
- package/src/panes/state.js +91 -0
- package/src/panes/statechart.js +63 -0
- package/src/panes/story.js +33 -0
- package/src/panes/subgraph.js +94 -0
- package/src/panes/tabs.js +52 -0
- package/src/panes/terminal.js +57 -0
- package/src/panes/text.js +36 -0
- package/src/panes/timer.js +55 -0
- package/src/panes/traffic.js +59 -0
- package/src/panes/verdict.js +62 -0
- package/src/panes/vm.js +46 -0
- package/src/panes/wait.js +61 -0
- package/src/panes/watch.js +57 -0
- package/src/panes/webhook.js +67 -0
- package/src/panes/ws-client.js +67 -0
- package/src/persist.js +281 -0
- package/src/plot/tex.js +19 -0
- package/src/plot/vendor.js +59 -0
- package/src/plot/view-vendor.js +5 -0
- package/src/privacy/levels.js +108 -0
- package/src/protocol/devtools.js +116 -0
- package/src/protocol/inspector.js +368 -0
- package/src/render/time.js +381 -0
- package/src/rooms/mesh-metrics.js +162 -0
- package/src/run/companion.js +355 -0
- package/src/run/describe.js +114 -0
- package/src/run/local-model.js +150 -0
- package/src/run/monitor.js +208 -0
- package/src/run/publish.js +360 -0
- package/src/run/respond-outcome.js +12 -0
- package/src/run/run.js +820 -0
- package/src/run/runner-pairing.js +243 -0
- package/src/run/values.js +122 -0
- package/src/runtime/compile.js +122 -0
- package/src/runtime/console-tag.js +64 -0
- package/src/runtime/frame-signals.js +126 -0
- package/src/runtime/iteration-push.js +19 -0
- package/src/runtime/keys.js +474 -0
- package/src/runtime/midi-input.js +170 -0
- package/src/runtime/person-waits.js +140 -0
- package/src/runtime/resource-timing.js +56 -0
- package/src/runtime/runtime.js +2150 -0
- package/src/runtime/sandbox-modules.js +163 -0
- package/src/runtime/spring.js +246 -0
- package/src/runtime/strict.js +215 -0
- package/src/runtime/transfer.js +75 -0
- package/src/runtime/tween.js +158 -0
- package/src/runtime/wasm-fuel.js +596 -0
- package/src/runtime/worker/00-prelude.js +88 -0
- package/src/runtime/worker/10-helpers.js +295 -0
- package/src/runtime/worker/20-io.js +645 -0
- package/src/runtime/worker/30-previews.js +210 -0
- package/src/runtime/worker/40-profile-lineage.js +278 -0
- package/src/runtime/worker/50-own-worker.js +233 -0
- package/src/runtime/worker/60-timers.js +172 -0
- package/src/runtime/worker/70-state-keyed.js +193 -0
- package/src/runtime/worker/80-each-compile-generators.js +619 -0
- package/src/runtime/worker/90-events-operators.js +655 -0
- package/src/runtime/worker/95-agents-batches.js +1820 -0
- package/src/runtime/worker/96-plot.js +47 -0
- package/src/runtime/worker/97-calc.js +28 -0
- package/src/runtime/worker/98-geometry.js +24 -0
- package/src/runtime/worker/99-graph.js +30 -0
- package/src/runtime/worker/99-shell.js +30 -0
- package/src/safety/config.js +57 -0
- package/src/safety/engine.js +324 -0
- package/src/scene/pixi-scene.js +806 -0
- package/src/scene/scene-assets.js +241 -0
- package/src/scene/scene-edit.js +319 -0
- package/src/secret/settings.js +41 -0
- package/src/security/multipart.js +257 -0
- package/src/security/redact.js +261 -0
- package/src/serial/broker.js +473 -0
- package/src/serial/config.js +185 -0
- package/src/serial/framers.js +389 -0
- package/src/serial/packets.js +64 -0
- package/src/shader/audio-texture.js +87 -0
- package/src/shader/channels.js +496 -0
- package/src/shader/common.js +90 -0
- package/src/shader/model.js +867 -0
- package/src/shader/passes.js +150 -0
- package/src/shader/shadertoy.js +198 -0
- package/src/shell/hub.js +287 -0
- package/src/sim/checkpoints.js +850 -0
- package/src/sim/compile.js +37 -0
- package/src/sim/fixed.js +377 -0
- package/src/sim/headless.js +205 -0
- package/src/sim/physics.js +399 -0
- package/src/smf-helper/vendor.js +2 -0
- package/src/sources/config.js +435 -0
- package/src/storage.js +153 -0
- package/src/table/table-geo.js +2344 -0
- package/src/table/table-lineage.js +808 -0
- package/src/table/table-quality.js +355 -0
- package/src/table/table-schema.js +392 -0
- package/src/table/table-sql.js +1650 -0
- package/src/table/table-stats.js +480 -0
- package/src/table/table.js +2102 -0
- package/src/tensor/tensor.js +1153 -0
- package/src/terminal/hub.js +715 -0
- package/src/terminal/screen.js +516 -0
- package/src/tests/capture.js +88 -0
- package/src/tests/compare.js +480 -0
- package/src/tests/dataset.js +170 -0
- package/src/tests/evaluate.js +286 -0
- package/src/tests/from-runs.js +99 -0
- package/src/tests/judge.js +134 -0
- package/src/tests/matchers.js +263 -0
- package/src/tests/matrix-spec.js +87 -0
- package/src/tests/matrix.js +397 -0
- package/src/tests/metrics.js +369 -0
- package/src/tests/no-value.js +42 -0
- package/src/tests/pane-check.js +45 -0
- package/src/tests/report.js +124 -0
- package/src/tests/reporters.js +140 -0
- package/src/tests/run.js +155 -0
- package/src/tilemap/tilemap.js +1122 -0
- package/src/units/units.js +3 -0
- package/src/util/bytes-text.js +21 -0
- package/src/util/num.js +10 -0
- package/src/util/regexp.js +2 -0
- package/src/util/text.js +38 -0
- package/src/verdict/engine.js +154 -0
- package/src/vm/guest-wsh.js +108 -0
- package/src/vm/hub.js +457 -0
- package/src/vm/image-files.js +4 -0
- package/src/vm/image.js +33 -0
- package/src/vm/image.lock.json +13 -0
- package/src/vm/link.js +266 -0
- package/src/vm/mount.js +212 -0
- package/src/vm/net.js +85 -0
- package/src/vm/pipe-ws.js +187 -0
- package/src/vm/v86-loader.js +11 -0
- package/src/webmcp/args.js +212 -0
- package/src/webmcp/hidden.js +218 -0
- package/src/webmcp/text.js +250 -0
- package/src/webmcp/tools/bookmark-tools.js +106 -0
- package/src/webmcp/tools/breakpoint-tools.js +48 -0
- package/src/webmcp/tools/canvases.js +208 -0
- package/src/webmcp/tools/context-tools.js +84 -0
- package/src/webmcp/tools/core.js +170 -0
- package/src/webmcp/tools/devices.js +41 -0
- package/src/webmcp/tools/edit.js +357 -0
- package/src/webmcp/tools/event-tools.js +145 -0
- package/src/webmcp/tools/image-tools.js +173 -0
- package/src/webmcp/tools/ink-tools.js +247 -0
- package/src/webmcp/tools/input-log-tools.js +163 -0
- package/src/webmcp/tools/live.js +166 -0
- package/src/webmcp/tools/machine-tools.js +74 -0
- package/src/webmcp/tools/media.js +161 -0
- package/src/webmcp/tools/midi-tools.js +32 -0
- package/src/webmcp/tools/preset-tools.js +184 -0
- package/src/webmcp/tools/quick-add-tools.js +95 -0
- package/src/webmcp/tools/reshape.js +152 -0
- package/src/webmcp/tools/run-tools.js +309 -0
- package/src/webmcp/tools/runs.js +101 -0
- package/src/webmcp/tools/scaffold-tools.js +161 -0
- package/src/webmcp/tools/serial-tools.js +36 -0
- package/src/webmcp/tools/shared.js +338 -0
- package/src/webmcp/tools/subgraphs.js +360 -0
- package/src/webmcp/tools/tests.js +170 -0
- package/src/webmcp/tools/traffic-tools.js +70 -0
- package/src/webmcp/tools/transport-tools.js +65 -0
- package/src/webmcp/tools/version-tools.js +126 -0
- package/src/webmcp/tools/versions.js +11 -0
- package/src/webmcp/tools/wire-tools.js +90 -0
- package/src/webmcp/tools/workspace-tools.js +93 -0
- package/src/webmcp/tools.js +1323 -0
- package/src/wsh/connect.js +347 -0
- package/src/wsh/demo-host.js +361 -0
- package/src/wsh/e2e.js +27 -0
- package/src/wsh/keys.js +154 -0
- package/src/wsh/known-hosts.js +39 -0
- package/src/wsh/private-key.js +95 -0
- package/src/wsh/reverse.js +34 -0
- package/src/wsh/settings.js +118 -0
- package/src/wsh/transfer.js +62 -0
- package/src/wsh/vendor.js +5 -0
- package/src/x402/challenge.js +171 -0
- package/src/x402/demo-server.js +127 -0
- package/src/x402/pay.js +125 -0
- package/src/x402/retry.js +95 -0
- package/src/x402/store.js +76 -0
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
// The weighted split preset: an eval pane whose code is generated from a
|
|
2
|
+
// small table of named branches and weights. Each item (a value, or each item of
|
|
3
|
+
// a for-each) goes out on exactly one branch, chosen by a seeded hash of a stable
|
|
4
|
+
// key, so the same item gets the same branch in every run, after a reload and in
|
|
5
|
+
// `mallory run`. It is the switch's mechanics (src/model/switch.js): one named
|
|
6
|
+
// output per branch, the value on the chosen one, the others skipped
|
|
7
|
+
// (docs/guide/canvas-basics.md, "Skipping"); the switch routes by conditions, this routes by chance
|
|
8
|
+
// that is reproducible. Saved with the pane:
|
|
9
|
+
//
|
|
10
|
+
// split: {
|
|
11
|
+
// branches: [{ to: "control", weight: 50 }, { to: "variant", weight: 50 }],
|
|
12
|
+
// by: "", // a property path into the value that names the item ("user.id"); "" = the value itself
|
|
13
|
+
// salt: "", // the seed: text mixed into every draw; a new salt reshuffles everyone
|
|
14
|
+
// revision: 1, // the rule's version: bump it to start a new experiment with the same salt
|
|
15
|
+
// rerandomize: false, // false: the same key always lands on the same branch; true: every entry draws again
|
|
16
|
+
// on: "", // the input routed (default: the first one)
|
|
17
|
+
// scheme: "slices", // "slices" (the default, absent when it is) or "rendezvous": how a draw becomes a branch
|
|
18
|
+
// }
|
|
19
|
+
//
|
|
20
|
+
// THE POLICY (stated in the pane and the README, tested in test/split.test.mjs):
|
|
21
|
+
// - A draw is unit(JSON [salt, revision, entry, key]) in [0, 1), the one seeded hash
|
|
22
|
+
// (src/model/hash.js, the gate's jitter uses it too). `entry` is 0 unless rerandomize is on.
|
|
23
|
+
// - The draw picks a branch by cumulative weight, in the branches' order: branch i owns the
|
|
24
|
+
// slice [Σ w(<i), Σ w(≤i)) / Σ w of the unit interval. A zero weight owns no slice, so it is
|
|
25
|
+
// never chosen; a set whose weights are all zero is refused.
|
|
26
|
+
// - Nothing is stored: every run recomputes the assignment from the settings and the key. So an
|
|
27
|
+
// existing key keeps its branch exactly while salt, revision, `by` and the weights' slices are
|
|
28
|
+
// unchanged. Editing weights recomputes: a key moves only when its draw now falls in another
|
|
29
|
+
// branch's slice (reordering branches or changing an earlier weight shifts the boundaries
|
|
30
|
+
// after it); editing the salt or revision redraws everyone. `reassignment()` says which keys
|
|
31
|
+
// move; the pane shows it for its sample cohort when a setting changes.
|
|
32
|
+
// - The "rendezvous" scheme (sticky across weight edits): instead of one draw cut into slices, every
|
|
33
|
+
// branch with weight draws for itself, unit(JSON [salt, revision, entry, key, branch name]), and the
|
|
34
|
+
// key goes to the branch with the best weighted score, ln(draw) / weight (the highest). That is
|
|
35
|
+
// weighted rendezvous hashing: P(branch) is its share, and a branch's score depends on nothing but
|
|
36
|
+
// its own name and weight, so editing one branch's weight moves a key only into or out of that
|
|
37
|
+
// branch, adding a branch moves keys only into it, removing one moves only its keys, and reordering
|
|
38
|
+
// the table moves nobody. Still nothing is stored. Salt, revision, `by` and `rerandomize` redraw
|
|
39
|
+
// everyone as before.
|
|
40
|
+
// - Arithmetic only (no Math.log, Math.pow): the same numbers in every JavaScript engine.
|
|
41
|
+
// - Counts are a random sample: a cohort of n lands near n × share on each branch, not on it
|
|
42
|
+
// (`cohortReport` gives the expected count with one standard deviation).
|
|
43
|
+
//
|
|
44
|
+
// Pure: no DOM. The code runs in the sandbox like any pane's.
|
|
45
|
+
import { outputNameProblem } from "./ports.js";
|
|
46
|
+
import { unit } from "./hash.js";
|
|
47
|
+
|
|
48
|
+
export const MAX_BRANCHES = 32;
|
|
49
|
+
export const MAX_WEIGHT = 1e6;
|
|
50
|
+
export const MAX_SALT = 64;
|
|
51
|
+
export const MAX_BY = 128;
|
|
52
|
+
export const MAX_REVISION = 1e9;
|
|
53
|
+
/** How a draw becomes a branch: "slices" (one draw cut by cumulative weight; the default, not saved) or "rendezvous" (sticky across weight edits). */
|
|
54
|
+
export const SCHEMES = ["slices", "rendezvous"];
|
|
55
|
+
/** The name of the output that carries the assignment record; no branch can have it. */
|
|
56
|
+
export const ASSIGNMENT_OUTPUT = "assignment";
|
|
57
|
+
/** What the assignment record's `rule` says: change it if the way a draw becomes a branch ever changes. */
|
|
58
|
+
export const RULE = "weighted-split/1";
|
|
59
|
+
/** The record's `rule` for the rendezvous scheme. */
|
|
60
|
+
export const RULE_RENDEZVOUS = "weighted-split/2";
|
|
61
|
+
/** Distinct keys a rerandomizing split counts entries for in one run. */
|
|
62
|
+
export const MAX_ENTRY_KEYS = 10000;
|
|
63
|
+
|
|
64
|
+
/** A new split pane's settings. */
|
|
65
|
+
export const defaultSplit = () => ({ branches: [{ to: "control", weight: 50 }, { to: "variant", weight: 50 }], by: "", salt: "", revision: 1, rerandomize: false, on: "" });
|
|
66
|
+
|
|
67
|
+
// ── the pieces the generated code carries (each standalone: no free variables but the arguments) ─────
|
|
68
|
+
|
|
69
|
+
/** The text that names an item: a string as it is, a number or boolean as `String`, anything else as JSON. */
|
|
70
|
+
export function keyText(value) {
|
|
71
|
+
if (typeof value === "string") return value;
|
|
72
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
73
|
+
return JSON.stringify(value);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The draw in [0, 1) for a key: the seeded hash (passed in, so this source can travel) of the settings that decide it. */
|
|
77
|
+
export function drawOf(hash, salt, revision, entry, key) {
|
|
78
|
+
return hash(JSON.stringify([salt, revision, entry, key]));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The branch a draw lands on: `branches` is [{ to, weight }], in order; zero weights own nothing. Null when none has weight. */
|
|
82
|
+
export function pickBranch(branches, draw) {
|
|
83
|
+
let total = 0;
|
|
84
|
+
for (const b of branches) if (b.weight > 0) total += b.weight;
|
|
85
|
+
const target = draw * total;
|
|
86
|
+
let sum = 0;
|
|
87
|
+
let last = null;
|
|
88
|
+
for (const b of branches) {
|
|
89
|
+
if (!(b.weight > 0)) continue;
|
|
90
|
+
sum += b.weight;
|
|
91
|
+
last = b.to;
|
|
92
|
+
if (target < sum) return b.to;
|
|
93
|
+
}
|
|
94
|
+
return last;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The rendezvous pick: each branch with weight draws for itself (the seeded hash of the settings, the key and the
|
|
99
|
+
* branch's name), and the key goes to the highest ln(draw) / weight, which is the shortest of the branches' waiting
|
|
100
|
+
* times at rate = weight, so a branch wins with its share. Returns `{ branch, draw }` (the winner's own draw), or a
|
|
101
|
+
* null branch when none has weight. Arithmetic only: the logarithm is a fixed series over a draw scaled by exact
|
|
102
|
+
* powers of two, so every engine gives the same number. Standalone, so its source can travel in the generated code.
|
|
103
|
+
*/
|
|
104
|
+
export function pickRendezvous(hash, salt, revision, entry, key, branches) {
|
|
105
|
+
let best = null;
|
|
106
|
+
let bestScore = 0;
|
|
107
|
+
let bestDraw = 0;
|
|
108
|
+
for (const b of branches) {
|
|
109
|
+
if (!(b.weight > 0)) continue;
|
|
110
|
+
const draw = (hash(JSON.stringify([salt, revision, entry, key, b.to])) * 4294967296 + 0.5) / 4294967296;
|
|
111
|
+
let x = draw;
|
|
112
|
+
let k = 0;
|
|
113
|
+
while (x < 0.5) {
|
|
114
|
+
x *= 2;
|
|
115
|
+
k++;
|
|
116
|
+
}
|
|
117
|
+
const t = (x - 1) / (x + 1);
|
|
118
|
+
const t2 = t * t;
|
|
119
|
+
let sum = 0;
|
|
120
|
+
let term = t;
|
|
121
|
+
for (let n = 1; n <= 41; n += 2) {
|
|
122
|
+
sum += term / n;
|
|
123
|
+
term *= t2;
|
|
124
|
+
}
|
|
125
|
+
const score = (2 * sum - k * 0.6931471805599453) / b.weight;
|
|
126
|
+
if (best === null || score > bestScore) {
|
|
127
|
+
best = b.to;
|
|
128
|
+
bestScore = score;
|
|
129
|
+
bestDraw = draw;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return { branch: best, draw: bestDraw };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// ── settings ─────────────────────────────────────────────────────────────────
|
|
136
|
+
|
|
137
|
+
/** Why these split settings can't run (an empty string when they can). Judges the settings as given, before `cleanSplit` tidies them. */
|
|
138
|
+
export function splitProblem(s) {
|
|
139
|
+
if (!s || typeof s !== "object" || Array.isArray(s)) return "split is an object: { branches, by?, salt?, revision?, rerandomize?, on?, scheme? }";
|
|
140
|
+
const branches = s.branches;
|
|
141
|
+
if (!Array.isArray(branches) || branches.length === 0) return "a split needs branches: [{ to, weight }]";
|
|
142
|
+
if (branches.length > MAX_BRANCHES) return `at most ${MAX_BRANCHES} branches`;
|
|
143
|
+
const seen = new Set();
|
|
144
|
+
let total = 0;
|
|
145
|
+
for (const b of branches) {
|
|
146
|
+
if (!b || typeof b !== "object") return "each branch is { to, weight }";
|
|
147
|
+
const named = outputNameProblem(b.to);
|
|
148
|
+
if (named) return named;
|
|
149
|
+
if (b.to === ASSIGNMENT_OUTPUT) return `"${ASSIGNMENT_OUTPUT}" is the output with the assignment record, not a branch name`;
|
|
150
|
+
if (seen.has(b.to)) return `two branches are named "${b.to}"`;
|
|
151
|
+
seen.add(b.to);
|
|
152
|
+
if (typeof b.weight !== "number" || !Number.isFinite(b.weight) || b.weight < 0) return `branch "${b.to}": the weight is a number, zero or more`;
|
|
153
|
+
if (b.weight > MAX_WEIGHT) return `branch "${b.to}": the weight is at most ${MAX_WEIGHT}`;
|
|
154
|
+
total += b.weight;
|
|
155
|
+
}
|
|
156
|
+
if (!(total > 0)) return "every weight is zero: no branch could ever be chosen, so give at least one a weight above zero";
|
|
157
|
+
if (s.by !== undefined && (typeof s.by !== "string" || (s.by.trim() !== "" && !/^[\w$-]+(\.[\w$-]+)*$/.test(s.by.trim())) || s.by.length > MAX_BY)) return `by is a property path like "user.id" (at most ${MAX_BY} characters)`;
|
|
158
|
+
if (s.salt !== undefined && (typeof s.salt !== "string" || s.salt.length > MAX_SALT)) return `salt is text of at most ${MAX_SALT} characters`;
|
|
159
|
+
if (s.revision !== undefined && (!Number.isInteger(s.revision) || s.revision < 0 || s.revision > MAX_REVISION)) return `revision is a whole number from 0 to ${MAX_REVISION}`;
|
|
160
|
+
if (s.rerandomize !== undefined && typeof s.rerandomize !== "boolean") return "rerandomize is true or false";
|
|
161
|
+
if (s.on !== undefined && typeof s.on !== "string") return "on is an input name";
|
|
162
|
+
if (s.scheme !== undefined && !SCHEMES.includes(s.scheme)) return `scheme is ${SCHEMES.map((x) => `"${x}"`).join(" or ")}`;
|
|
163
|
+
return "";
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Split settings, tidied. A saved pane that can't be read back exactly keeps what it can: a weight that
|
|
168
|
+
* isn't a finite, non-negative number becomes 0 (never chosen, and shown), a bad branch name drops the branch.
|
|
169
|
+
* `splitProblem` is what refuses; this never throws.
|
|
170
|
+
*/
|
|
171
|
+
export function cleanSplit(s) {
|
|
172
|
+
if (!s || typeof s !== "object") return undefined;
|
|
173
|
+
const seen = new Set();
|
|
174
|
+
const branches = [];
|
|
175
|
+
for (const b of Array.isArray(s.branches) ? s.branches : []) {
|
|
176
|
+
const to = typeof b?.to === "string" ? b.to.trim() : "";
|
|
177
|
+
if (outputNameProblem(to) || to === ASSIGNMENT_OUTPUT || seen.has(to) || branches.length >= MAX_BRANCHES) continue;
|
|
178
|
+
seen.add(to);
|
|
179
|
+
const w = Number(b.weight);
|
|
180
|
+
branches.push({ to, weight: Number.isFinite(w) && w >= 0 ? Math.min(w, MAX_WEIGHT) : 0 });
|
|
181
|
+
}
|
|
182
|
+
const revision = Number(s.revision);
|
|
183
|
+
return {
|
|
184
|
+
branches,
|
|
185
|
+
by: typeof s.by === "string" && /^[\w$-]+(\.[\w$-]+)*$/.test(s.by.trim()) ? s.by.trim() : "",
|
|
186
|
+
salt: typeof s.salt === "string" ? s.salt.slice(0, MAX_SALT) : "",
|
|
187
|
+
revision: Number.isInteger(revision) && revision >= 0 && revision <= MAX_REVISION ? revision : 1,
|
|
188
|
+
rerandomize: s.rerandomize === true,
|
|
189
|
+
on: typeof s.on === "string" ? s.on.trim() : "",
|
|
190
|
+
...(s.scheme === "rendezvous" ? { scheme: "rendezvous" } : {}), // the default, "slices", is not saved
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** The branches with their share of the whole, for showing the normalized weights: [{ to, weight, share }] (share 0..1). */
|
|
195
|
+
export function normalized(s) {
|
|
196
|
+
const clean = cleanSplit(s);
|
|
197
|
+
const total = clean ? clean.branches.reduce((n, b) => n + b.weight, 0) : 0;
|
|
198
|
+
return (clean?.branches ?? []).map((b) => ({ ...b, share: total > 0 ? b.weight / total : 0 }));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** The outputs a split makes: each branch's, in order, then the assignment record. */
|
|
202
|
+
export function splitOutputs(s) {
|
|
203
|
+
const clean = cleanSplit(s);
|
|
204
|
+
return clean ? [...clean.branches.map((b) => b.to), ASSIGNMENT_OUTPUT] : [];
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// ── assigning ────────────────────────────────────────────────────────────────
|
|
208
|
+
|
|
209
|
+
/** The key text of an item: the property at `by` (a dotted path) or the value itself. Throws when the path finds nothing. */
|
|
210
|
+
export function keyOf(value, by = "") {
|
|
211
|
+
let found = value;
|
|
212
|
+
if (by) for (const step of by.split(".")) found = found === null || found === undefined ? undefined : found[step];
|
|
213
|
+
if (found === undefined || found === null) throw new Error(`no key: ${by ? `"${by}" is missing from the item` : "the item is empty"}`);
|
|
214
|
+
return keyText(found);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* The assignment record for one item: `{ branch, key, draw, salt, revision, entry, rerandomize, rule, weights }`.
|
|
219
|
+
* `entry`: the nth time this key entered (only counts when rerandomize is on). Throws on settings that can't run.
|
|
220
|
+
*/
|
|
221
|
+
export function assign(split, value, entry = 0) {
|
|
222
|
+
const problem = splitProblem(split);
|
|
223
|
+
if (problem) throw new Error(problem);
|
|
224
|
+
const s = cleanSplit(split);
|
|
225
|
+
const key = keyOf(value, s.by);
|
|
226
|
+
const e = s.rerandomize ? entry : 0;
|
|
227
|
+
if (s.scheme === "rendezvous") {
|
|
228
|
+
const won = pickRendezvous(unit, s.salt, s.revision, e, key, s.branches);
|
|
229
|
+
return record(s, key, won.draw, e, won.branch);
|
|
230
|
+
}
|
|
231
|
+
const draw = drawOf(unit, s.salt, s.revision, e, key);
|
|
232
|
+
return record(s, key, draw, e, pickBranch(s.branches, draw));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function record(s, key, draw, entry, branch) {
|
|
236
|
+
return { branch, key, draw, salt: s.salt, revision: s.revision, entry, rerandomize: s.rerandomize, rule: s.scheme === "rendezvous" ? RULE_RENDEZVOUS : RULE, weights: Object.fromEntries(s.branches.map((b) => [b.to, b.weight])) };
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** A fixed cohort of `n` keys, "user-1" … "user-n": the fixture the pane's preview and the tests use. */
|
|
240
|
+
export const fixtureKeys = (n = 200) => Array.from({ length: n }, (_, i) => `user-${i + 1}`);
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* The per-branch counts for a cohort of keys (items, with `by` applied): a reproducible report. `expected` is
|
|
244
|
+
* n × share with one standard deviation, and `note` says what a small cohort can and can't show.
|
|
245
|
+
*/
|
|
246
|
+
export function cohortReport(split, items = fixtureKeys()) {
|
|
247
|
+
const s = cleanSplit(split);
|
|
248
|
+
const total = items.length;
|
|
249
|
+
const shares = normalized(s);
|
|
250
|
+
const counts = Object.fromEntries(shares.map((b) => [b.to, 0]));
|
|
251
|
+
for (const item of items) counts[assign(s, item).branch]++;
|
|
252
|
+
const expected = Object.fromEntries(shares.map((b) => [b.to, { count: total * b.share, sd: Math.sqrt(total * b.share * (1 - b.share)) }]));
|
|
253
|
+
const note =
|
|
254
|
+
total < 1000
|
|
255
|
+
? `${total} items is a sample: each branch lands near its share, not on it (about ${shares.map((b) => `${b.to} ${(total * b.share).toFixed(1)} ± ${Math.sqrt(total * b.share * (1 - b.share)).toFixed(1)}`).join(", ")}), so counts are not exact percentages`
|
|
256
|
+
: "the more items, the closer each branch gets to its share; a count is still a random sample, never exact";
|
|
257
|
+
return { total, counts, shares: Object.fromEntries(shares.map((b) => [b.to, b.share])), expected, note, rule: s.scheme === "rendezvous" ? RULE_RENDEZVOUS : RULE };
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** The most keys a report over keys given by a caller counts, and the most it lists one by one. */
|
|
261
|
+
export const MAX_REPORT_KEYS = 5000;
|
|
262
|
+
export const SHOWN_ASSIGNMENTS = 50;
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* The report for keys the caller names (items, with `by` applied, up to MAX_REPORT_KEYS): `cohortReport`'s counts, shares,
|
|
266
|
+
* expectation and note, plus `assignments` for the first few (`[{ index, key, branch }]`) and `missing`, the items that
|
|
267
|
+
* have no key at the path (counted nowhere, the first few with the reason). The draws are the model's own, so what this
|
|
268
|
+
* says is what a run does; nothing is stored. Throws when the settings can't run or there are too many keys.
|
|
269
|
+
*/
|
|
270
|
+
export function keyReport(split, items, { show = SHOWN_ASSIGNMENTS } = {}) {
|
|
271
|
+
const problem = splitProblem(split);
|
|
272
|
+
if (problem) throw new Error(problem);
|
|
273
|
+
if (!Array.isArray(items)) throw new Error("the keys are a list");
|
|
274
|
+
if (items.length > MAX_REPORT_KEYS) throw new Error(`at most ${MAX_REPORT_KEYS} keys at a time`);
|
|
275
|
+
const s = cleanSplit(split);
|
|
276
|
+
const counted = [];
|
|
277
|
+
const assignments = [];
|
|
278
|
+
const missing = [];
|
|
279
|
+
items.forEach((item, index) => {
|
|
280
|
+
try {
|
|
281
|
+
const a = assign(s, item);
|
|
282
|
+
counted.push(item);
|
|
283
|
+
if (assignments.length < show) assignments.push({ index, key: a.key, branch: a.branch });
|
|
284
|
+
} catch (error) {
|
|
285
|
+
missing.push({ index, problem: error.message });
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
const report = cohortReport(s, counted);
|
|
289
|
+
return { ...report, assignments, missing: { count: missing.length, first: missing.slice(0, 5) } };
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* What changing split settings does to existing assignments, over a cohort: the keys that keep their branch and the
|
|
294
|
+
* ones that move (`moves`: "a → b": n). `kind` says why, in words (the policy): "unchanged", "kept" (nothing moved),
|
|
295
|
+
* "recomputed" (some moved), "redrawn" (a new salt, revision or key path: everyone is drawn afresh).
|
|
296
|
+
*/
|
|
297
|
+
export function reassignment(before, after, items = fixtureKeys()) {
|
|
298
|
+
const a = cleanSplit(before);
|
|
299
|
+
const b = cleanSplit(after);
|
|
300
|
+
const redraw = a.salt !== b.salt || a.revision !== b.revision || a.by !== b.by || a.rerandomize !== b.rerandomize || (a.scheme ?? "slices") !== (b.scheme ?? "slices");
|
|
301
|
+
const moves = {};
|
|
302
|
+
let moved = 0;
|
|
303
|
+
for (const item of items) {
|
|
304
|
+
const from = assign(a, item).branch;
|
|
305
|
+
const to = assign(b, item).branch;
|
|
306
|
+
if (from !== to) {
|
|
307
|
+
moved++;
|
|
308
|
+
moves[`${from} → ${to}`] = (moves[`${from} → ${to}`] ?? 0) + 1;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
const same = JSON.stringify(a) === JSON.stringify(b);
|
|
312
|
+
const kind = same ? "unchanged" : redraw ? "redrawn" : moved ? "recomputed" : "kept";
|
|
313
|
+
const total = items.length;
|
|
314
|
+
const words = {
|
|
315
|
+
unchanged: "nothing changed: every item keeps its branch",
|
|
316
|
+
kept: `weights changed but all ${total} sample items keep their branch`,
|
|
317
|
+
recomputed: `recomputed from the same draws: ${moved} of ${total} sample items move (${Object.entries(moves).map(([k, n]) => `${k}: ${n}`).join(", ")}); the rest keep theirs${b.scheme === "rendezvous" ? " (sticky: a key moves only into or out of a branch whose weight changed, or one added or removed)" : ""}`,
|
|
318
|
+
redrawn: `drawn afresh (salt, revision, key, rerandomize or scheme changed): ${moved} of ${total} sample items move; nothing carries over`,
|
|
319
|
+
};
|
|
320
|
+
return { kind, total, moved, kept: total - moved, moves, note: words[kind] };
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// ── the preset's code ────────────────────────────────────────────────────────
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* The eval code (function mode) for split settings: it returns an object with the item under its branch's output
|
|
327
|
+
* and the assignment record under "assignment". Settings that can't run make code that throws the reason (the
|
|
328
|
+
* pane shows it). The helpers are the exported functions above, carried as source (one implementation, below).
|
|
329
|
+
*/
|
|
330
|
+
export function splitCode(s, inputNames = []) {
|
|
331
|
+
const problem = splitProblem(s);
|
|
332
|
+
if (problem) return `// Generated from the split settings (edit them in the table above).\nthrow new Error(${JSON.stringify(`split: ${problem}`)});`;
|
|
333
|
+
const clean = cleanSplit(s);
|
|
334
|
+
const source = clean.on && inputNames.includes(clean.on) ? clean.on : inputNames[0];
|
|
335
|
+
const lines = [
|
|
336
|
+
"// Generated from the split settings (edit them in the table above): the item goes out on the branch its seeded draw picks.",
|
|
337
|
+
"// Same key, salt and revision, same branch: the draw is a seeded hash, never a random number, and nothing is stored.",
|
|
338
|
+
`const hash = ${unit};`,
|
|
339
|
+
`const keyText = ${keyText};`,
|
|
340
|
+
...(clean.scheme === "rendezvous" ? [`const pickRendezvous = ${pickRendezvous};`] : [`const drawOf = ${drawOf};`, `const pickBranch = ${pickBranch};`]),
|
|
341
|
+
`const rule = ${JSON.stringify({ branches: clean.branches, by: clean.by, salt: clean.salt, revision: clean.revision, rerandomize: clean.rerandomize })};`,
|
|
342
|
+
`const value = ${source ?? "undefined"};`,
|
|
343
|
+
"let key = value;",
|
|
344
|
+
'if (rule.by) for (const step of rule.by.split(".")) key = key === null || key === undefined ? undefined : key[step];',
|
|
345
|
+
'if (key === undefined || key === null) throw new Error(`no key: ${rule.by ? `"${rule.by}" is missing from the item` : "the item is empty"}`);',
|
|
346
|
+
"key = keyText(key);",
|
|
347
|
+
];
|
|
348
|
+
if (clean.rerandomize) {
|
|
349
|
+
lines.push(
|
|
350
|
+
"// Rerandomize: every entry of a key draws again; the nth entry is reproducible for the same run of entries.",
|
|
351
|
+
"const entries = (state.splitEntries ??= new Map());",
|
|
352
|
+
`if (!entries.has(key) && entries.size >= ${MAX_ENTRY_KEYS}) throw new Error("rerandomize counts entries for at most ${MAX_ENTRY_KEYS} keys in one run");`,
|
|
353
|
+
"const entry = entries.get(key) ?? 0;",
|
|
354
|
+
"entries.set(key, entry + 1);",
|
|
355
|
+
);
|
|
356
|
+
} else lines.push("const entry = 0;");
|
|
357
|
+
if (clean.scheme === "rendezvous") lines.push("const { branch, draw } = pickRendezvous(hash, rule.salt, rule.revision, entry, key, rule.branches);");
|
|
358
|
+
else lines.push("const draw = drawOf(hash, rule.salt, rule.revision, entry, key);", "const branch = pickBranch(rule.branches, draw);");
|
|
359
|
+
lines.push(
|
|
360
|
+
`return { [branch]: value, ${ASSIGNMENT_OUTPUT}: { branch, key, draw, salt: rule.salt, revision: rule.revision, entry, rerandomize: rule.rerandomize, rule: ${JSON.stringify(clean.scheme === "rendezvous" ? RULE_RENDEZVOUS : RULE)}, weights: Object.fromEntries(rule.branches.map((b) => [b.to, b.weight])) } };`,
|
|
361
|
+
);
|
|
362
|
+
return lines.join("\n");
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/** The content patch that applies split settings to an eval pane: the settings, the generated code (function mode) and the outputs (keeping the types and descriptions of those it had). */
|
|
366
|
+
export function splitPatch(s, pane = {}) {
|
|
367
|
+
const clean = cleanSplit(s);
|
|
368
|
+
const had = new Map((pane.outputs ?? []).map((o) => [o.name, o]));
|
|
369
|
+
return {
|
|
370
|
+
split: clean,
|
|
371
|
+
code: splitCode(clean, (pane.inputs ?? []).map((i) => i.name)),
|
|
372
|
+
mode: "function",
|
|
373
|
+
outputs: splitOutputs(clean).map((name) => had.get(name) ?? { name }),
|
|
374
|
+
};
|
|
375
|
+
}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// Letting go of a control: an input pane's number, range or XY value that
|
|
2
|
+
// keeps the gesture's velocity and settles with a spring. No DOM, no timers.
|
|
3
|
+
//
|
|
4
|
+
// `canvas.springs.fling(pane, { velocity, target?, spring? })` is the whole
|
|
5
|
+
// API; a pointer release (src/ui/pane.js), mallory_set_input and a script call
|
|
6
|
+
// the same thing.
|
|
7
|
+
//
|
|
8
|
+
// - The widget's value at the call is where the spring STARTS. The spring
|
|
9
|
+
// chases `target`, which defaults to that value (the release point): the
|
|
10
|
+
// value carries on with the released velocity, overshoots, and settles
|
|
11
|
+
// back. A `target` somewhere else makes it a throw to that value.
|
|
12
|
+
// - `velocity` is in the widget's own units per second: a number for number
|
|
13
|
+
// and range, { x, y } for xy. Without it the spring starts at rest.
|
|
14
|
+
// - Flinging a pane that is already springing RETARGETS the spring it has:
|
|
15
|
+
// position and velocity carry over (no jump), a given velocity replaces
|
|
16
|
+
// the velocity, and a `spring` replaces the coefficients.
|
|
17
|
+
// - Every value written is CONSTRAINED by the widget like a morph's
|
|
18
|
+
// (src/model/preset-morph.js `constrainValue`): clamped to min and max and
|
|
19
|
+
// snapped to step, and the ends are walls (the spring stops there). The
|
|
20
|
+
// last write is the target, exactly.
|
|
21
|
+
//
|
|
22
|
+
// The widget's `spring` setting (true, or { stiffness, damping, mass }) is what
|
|
23
|
+
// a pointer release uses: without it a release is a release. Coefficients
|
|
24
|
+
// are in src/runtime/spring.js (the defaults are 170, 18, 1).
|
|
25
|
+
//
|
|
26
|
+
// THE CLOCK is the page's animation frames (`frames`, set on the root canvas's
|
|
27
|
+
// player), held by the canvas's live transport: paused, the value waits where
|
|
28
|
+
// it is; a step advances it by one frame (src/model/frame-loop.js). With
|
|
29
|
+
// reduced motion, or with no frames (headless, a hidden tab): the value jumps
|
|
30
|
+
// to the target at once. Any other write to the value (a hand on the control, a recall, an agent), undo/redo, deleting the
|
|
31
|
+
// pane or closing the canvas ends its spring (`cancel`, `dispose`).
|
|
32
|
+
//
|
|
33
|
+
// Springs write plain widget values with `canvas.update`, like the drag they
|
|
34
|
+
// continue: no undo step of their own. Tests: test/spring-player.test.mjs.
|
|
35
|
+
import { Spring, springOf, springProblem } from "../runtime/spring.js";
|
|
36
|
+
import { constrainValue, differs } from "./preset-morph.js";
|
|
37
|
+
import { axisOf } from "./widget-values.js";
|
|
38
|
+
import { FrameLoop } from "./frame-loop.js";
|
|
39
|
+
|
|
40
|
+
/** The widget kinds a spring moves. */
|
|
41
|
+
export const SPRING_WIDGETS = ["number", "range", "xy"];
|
|
42
|
+
/** The fastest a release may start (ranges per second). */
|
|
43
|
+
export const MAX_RELEASE_RANGES = 20;
|
|
44
|
+
|
|
45
|
+
const isNum = (v) => typeof v === "number" && Number.isFinite(v);
|
|
46
|
+
const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
47
|
+
|
|
48
|
+
/** Why a widget's `spring` setting is wrong (a sentence), or "". true, or { stiffness, damping, mass }. */
|
|
49
|
+
export function springSettingProblem(setting) {
|
|
50
|
+
if (setting === undefined || setting === null || setting === false || setting === true) return "";
|
|
51
|
+
const problem = springProblem(setting);
|
|
52
|
+
return problem ? `spring: ${problem}` : "";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The coefficients a widget's `spring` setting asks for, or null when it has none. */
|
|
56
|
+
export function springSetting(widget) {
|
|
57
|
+
const s = widget?.spring;
|
|
58
|
+
if (!s || springSettingProblem(s) || !SPRING_WIDGETS.includes(widget.kind)) return null;
|
|
59
|
+
return springOf(s === true ? {} : s);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** How a widget's value is a spring's position: { scalar, dims, bounds, scale, vector(value), value(vector) }. */
|
|
63
|
+
function geometry(widget) {
|
|
64
|
+
if (widget.kind === "xy") {
|
|
65
|
+
const [ax, ay] = [axisOf(widget, "x"), axisOf(widget, "y")];
|
|
66
|
+
return {
|
|
67
|
+
dims: 2,
|
|
68
|
+
bounds: [ax, ay].map(({ min, max }) => ({ min, max })),
|
|
69
|
+
scale: [ax.max - ax.min, ay.max - ay.min],
|
|
70
|
+
vector: (v) => [v.x, v.y],
|
|
71
|
+
value: ([x, y]) => ({ x, y }),
|
|
72
|
+
velocity: (v) => (isObject(v) && isNum(v.x) && isNum(v.y) ? [v.x, v.y] : null),
|
|
73
|
+
velocityShape: "{ x, y }, both numbers",
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const bounded = isNum(widget.min) && isNum(widget.max) && widget.max > widget.min;
|
|
77
|
+
const range = bounded ? widget.max - widget.min : 100;
|
|
78
|
+
return {
|
|
79
|
+
dims: 1,
|
|
80
|
+
bounds: bounded ? [{ min: widget.min, max: widget.max }] : null,
|
|
81
|
+
scale: [range],
|
|
82
|
+
vector: (v) => [v],
|
|
83
|
+
value: ([v]) => v,
|
|
84
|
+
velocity: (v) => (isNum(v) ? [v] : null),
|
|
85
|
+
velocityShape: "a number",
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export class SpringPlayer extends EventTarget {
|
|
90
|
+
/** @param {object} canvas the Canvas whose input panes it moves */
|
|
91
|
+
constructor(canvas) {
|
|
92
|
+
super();
|
|
93
|
+
this.canvas = canvas;
|
|
94
|
+
this.frames = null; // { request(cb), cancel(handle) }: the page's animation frames (root canvas only)
|
|
95
|
+
this.reduced = () => false; // does the person prefer reduced motion?
|
|
96
|
+
this.runs = new Map(); // pane id -> { spring, geo, setting, widgetKind }
|
|
97
|
+
this.loop = new FrameLoop(canvas, () => this.#root().springs.frames, (ms) => this.advance(ms));
|
|
98
|
+
this.onStructure = () => this.#prune();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
#root() {
|
|
102
|
+
return this.canvas.root;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** The ids of the panes with a spring in flight. */
|
|
106
|
+
get active() {
|
|
107
|
+
return [...this.runs.keys()];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Is pane `id` springing? */
|
|
111
|
+
springing(id) {
|
|
112
|
+
return this.runs.has(id);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** The springs in flight, for a panel or an agent: [{ pane, position, velocity, target }]. */
|
|
116
|
+
status() {
|
|
117
|
+
return [...this.runs].map(([pane, r]) => ({ pane, position: r.geo.value(r.spring.position), velocity: r.geo.value(r.spring.velocity), target: r.geo.value(r.spring.target) }));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Let go of input pane `id`'s value with `velocity`, chasing `target` (default: the value now).
|
|
122
|
+
* Returns { animating, jumped?, value, target }. Throws a sentence for a pane that isn't an input
|
|
123
|
+
* pane with a number, range or xy widget, a velocity that isn't the widget's shape, a target the
|
|
124
|
+
* widget can't hold, or coefficients that aren't a spring.
|
|
125
|
+
*/
|
|
126
|
+
fling(id, { velocity, target, spring } = {}) {
|
|
127
|
+
const pane = this.canvas.attached.has(id) ? this.canvas.panes.get(id) : undefined;
|
|
128
|
+
if (!pane) throw new Error(`No pane "${id}" to spring.`);
|
|
129
|
+
if (pane.type !== "input") throw new Error(`${pane.name || id} is a ${pane.type} pane: only an input pane's widget springs.`);
|
|
130
|
+
const w = pane.widget;
|
|
131
|
+
if (!SPRING_WIDGETS.includes(w?.kind)) throw new Error(`${pane.name || id} has a ${w?.kind} widget: a spring moves ${SPRING_WIDGETS.join(", ")} widgets.`);
|
|
132
|
+
if (pane.inputs?.length) throw new Error(`${pane.name || id} is fed by a wire, which decides its value.`);
|
|
133
|
+
const geo = geometry(w);
|
|
134
|
+
const now = constrainValue(w, w.value);
|
|
135
|
+
if (now.problem) throw new Error(`${pane.name || id}'s value ${now.problem}.`);
|
|
136
|
+
let aim = now.value;
|
|
137
|
+
if (target !== undefined) {
|
|
138
|
+
const t = constrainValue(w, target);
|
|
139
|
+
if (t.problem) throw new Error(`target ${t.problem}.`);
|
|
140
|
+
aim = t.value;
|
|
141
|
+
}
|
|
142
|
+
let speed = null;
|
|
143
|
+
if (velocity !== undefined) {
|
|
144
|
+
speed = geo.velocity(velocity);
|
|
145
|
+
if (!speed) throw new Error(`velocity is ${geo.velocityShape} (units per second).`);
|
|
146
|
+
speed = speed.map((v, i) => Math.max(-MAX_RELEASE_RANGES * geo.scale[i], Math.min(MAX_RELEASE_RANGES * geo.scale[i], v)));
|
|
147
|
+
}
|
|
148
|
+
const coefficients = spring !== undefined ? springOf(spring === true ? {} : spring) : springSetting(w) ?? springOf({});
|
|
149
|
+
const rest = { restDelta: Math.min(...geo.scale) * 0.0005, restSpeed: Math.min(...geo.scale) * 0.005 };
|
|
150
|
+
const options = { ...coefficients, ...rest, ...(geo.bounds ? { bounds: geo.bounds } : {}) };
|
|
151
|
+
const here = this.runs.get(id);
|
|
152
|
+
const s = new Spring(options, { position: here ? here.spring.position : geo.vector(now.value), target: geo.vector(aim), velocity: speed ?? (here ? here.spring.velocity : undefined) });
|
|
153
|
+
const run = { spring: s, geo, kind: w.kind, written: here ? here.written : structuredClone(w.value) };
|
|
154
|
+
const root = this.#root().springs;
|
|
155
|
+
if (root.reduced() || !root.frames || s.settled) {
|
|
156
|
+
this.runs.delete(id);
|
|
157
|
+
this.#write(id, pane, aim);
|
|
158
|
+
this.#stopIfIdle();
|
|
159
|
+
return { animating: false, ...(s.settled ? {} : { jumped: true }), value: aim, target: aim };
|
|
160
|
+
}
|
|
161
|
+
this.runs.set(id, run);
|
|
162
|
+
if (this.runs.size === 1) this.canvas.addEventListener("structure", this.onStructure);
|
|
163
|
+
this.loop.start();
|
|
164
|
+
return { animating: true, value: now.value, target: aim };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Move every spring on by `ms` (a frame's worth, or the transport's step). A settled one writes its target and ends. */
|
|
168
|
+
advance(ms) {
|
|
169
|
+
for (const [id, run] of [...this.runs]) {
|
|
170
|
+
const pane = this.canvas.attached.has(id) ? this.canvas.panes.get(id) : undefined;
|
|
171
|
+
if (!pane || pane.type !== "input" || pane.widget?.kind !== run.kind) {
|
|
172
|
+
this.runs.delete(id);
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (differs(pane.widget.value, run.written)) {
|
|
176
|
+
this.runs.delete(id); // someone else set the value (a hand on the control, a recall, an agent): the spring lets go
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
const out = run.spring.advance(ms);
|
|
180
|
+
const constrained = constrainValue(pane.widget, run.geo.value(out.position));
|
|
181
|
+
if (!constrained.problem) this.#write(id, pane, constrained.value, run);
|
|
182
|
+
if (out.settled) {
|
|
183
|
+
this.runs.delete(id);
|
|
184
|
+
this.dispatchEvent(new CustomEvent("done", { detail: { pane: id } }));
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
this.#stopIfIdle();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
#write(id, pane, value, run) {
|
|
191
|
+
if (run) run.written = structuredClone(value);
|
|
192
|
+
if (!differs(pane.widget.value, value)) return;
|
|
193
|
+
this.canvas.update(id, { widget: { ...pane.widget, value } });
|
|
194
|
+
this.canvas.presetsApplied([id]); // the pane's view draws the new value
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
#prune() {
|
|
198
|
+
for (const id of [...this.runs.keys()]) if (!this.canvas.attached.has(id) || !this.canvas.panes.has(id)) this.runs.delete(id);
|
|
199
|
+
this.#stopIfIdle();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
#stopIfIdle() {
|
|
203
|
+
if (this.runs.size) return;
|
|
204
|
+
this.loop.stop();
|
|
205
|
+
this.canvas.removeEventListener("structure", this.onStructure);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Stop the spring of pane `id` (every pane's when omitted) where it is. Returns whether there was one. */
|
|
209
|
+
cancel(id) {
|
|
210
|
+
const had = id === undefined ? this.runs.size > 0 : this.runs.delete(id);
|
|
211
|
+
if (id === undefined) this.runs.clear();
|
|
212
|
+
this.#stopIfIdle();
|
|
213
|
+
return had;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** The canvas is closing: no more frames, no more writes. */
|
|
217
|
+
dispose() {
|
|
218
|
+
this.runs.clear();
|
|
219
|
+
this.loop.stop();
|
|
220
|
+
this.canvas.removeEventListener("structure", this.onStructure);
|
|
221
|
+
}
|
|
222
|
+
}
|